|
| 1 | +/* |
| 2 | +Copyright 2026 The Faros Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package api |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "encoding/json" |
| 22 | + "time" |
| 23 | + |
| 24 | + aiv1alpha1 "github.com/faroshq/provider-app-studio/apis/ai/v1alpha1" |
| 25 | + asclient "github.com/faroshq/provider-app-studio/client" |
| 26 | + "github.com/faroshq/provider-app-studio/store" |
| 27 | + "github.com/faroshq/provider-app-studio/workspace" |
| 28 | +) |
| 29 | + |
| 30 | +// projectAssistantEngine is App Studio's private boundary around assistant |
| 31 | +// execution. Eino implementations plug in behind this contract; REST payloads, |
| 32 | +// project APIs, and portal state stay App Studio-owned. |
| 33 | +type projectAssistantEngine interface { |
| 34 | + StreamProjectAssistant( |
| 35 | + context.Context, |
| 36 | + projectAssistantRunRequest, |
| 37 | + projectAssistantEventSink, |
| 38 | + ) (projectAssistantRunResult, error) |
| 39 | +} |
| 40 | + |
| 41 | +type projectAssistantRunRequest struct { |
| 42 | + Identity identity |
| 43 | + Client *asclient.Client |
| 44 | + Project *aiv1alpha1.Project |
| 45 | + Repository *ProjectRepositoryView |
| 46 | + WorkspaceScope workspace.Scope |
| 47 | + Workspace *workspace.FileStore |
| 48 | + MessageScope store.Scope |
| 49 | + LLM projectLLMSettings |
| 50 | + History []store.Message |
| 51 | + MCPBaseURL string |
| 52 | + MCPInsecureSkipTLSVerify bool |
| 53 | +} |
| 54 | + |
| 55 | +type projectAssistantRunResult struct { |
| 56 | + Content string |
| 57 | + Events []projectAssistantEvent |
| 58 | + ToolCalls []projectAssistantToolCall |
| 59 | +} |
| 60 | + |
| 61 | +type projectAssistantEventSink interface { |
| 62 | + EmitProjectAssistantEvent(context.Context, projectAssistantEvent) error |
| 63 | +} |
| 64 | + |
| 65 | +type projectAssistantEvent struct { |
| 66 | + Type projectAssistantEventType `json:"type"` |
| 67 | + ID string `json:"id,omitempty"` |
| 68 | + MessageID string `json:"messageID,omitempty"` |
| 69 | + ToolCall *projectAssistantToolCall `json:"toolCall,omitempty"` |
| 70 | + Permission *projectAssistantPermission `json:"permission,omitempty"` |
| 71 | + Checkpoint *projectAssistantCheckpoint `json:"checkpoint,omitempty"` |
| 72 | + Delta string `json:"delta,omitempty"` |
| 73 | + Status string `json:"status,omitempty"` |
| 74 | + Error string `json:"error,omitempty"` |
| 75 | + Metadata json.RawMessage `json:"metadata,omitempty"` |
| 76 | + CreatedAt *time.Time `json:"createdAt,omitempty"` |
| 77 | +} |
| 78 | + |
| 79 | +type projectAssistantEventType string |
| 80 | + |
| 81 | +const ( |
| 82 | + projectAssistantEventRunStarted projectAssistantEventType = "run_started" |
| 83 | + projectAssistantEventMessageDelta projectAssistantEventType = "message_delta" |
| 84 | + projectAssistantEventStatus projectAssistantEventType = "status" |
| 85 | + projectAssistantEventToolCallStarted projectAssistantEventType = "tool_call_started" |
| 86 | + projectAssistantEventToolCallFinished projectAssistantEventType = "tool_call_finished" |
| 87 | + projectAssistantEventPermissionNeeded projectAssistantEventType = "permission_required" |
| 88 | + projectAssistantEventCheckpointSaved projectAssistantEventType = "checkpoint_saved" |
| 89 | + projectAssistantEventRunFailed projectAssistantEventType = "run_failed" |
| 90 | + projectAssistantEventRunFinished projectAssistantEventType = "run_finished" |
| 91 | +) |
| 92 | + |
| 93 | +type projectAssistantToolCall struct { |
| 94 | + ID string `json:"id"` |
| 95 | + Name string `json:"name"` |
| 96 | + Status string `json:"status,omitempty"` |
| 97 | + Summary string `json:"summary,omitempty"` |
| 98 | + Input json.RawMessage `json:"input,omitempty"` |
| 99 | + Result json.RawMessage `json:"result,omitempty"` |
| 100 | +} |
| 101 | + |
| 102 | +type projectAssistantPermission struct { |
| 103 | + ID string `json:"id"` |
| 104 | + ToolCallID string `json:"toolCallID,omitempty"` |
| 105 | + ToolName string `json:"toolName,omitempty"` |
| 106 | + Reason string `json:"reason,omitempty"` |
| 107 | + Input json.RawMessage `json:"input,omitempty"` |
| 108 | +} |
| 109 | + |
| 110 | +type projectAssistantCheckpoint struct { |
| 111 | + ID string `json:"id"` |
| 112 | + Reason string `json:"reason,omitempty"` |
| 113 | + CreatedAt *time.Time `json:"createdAt,omitempty"` |
| 114 | +} |
0 commit comments