package opencode import ( "context" ) // OpenCodeClient opencode 客户端接口 type OpenCodeClient interface { CreateSession(ctx context.Context, title string) (*Session, error) SendPrompt(ctx context.Context, sessionID string, prompt *PromptRequest) (*PromptResponse, error) SendPromptStream(ctx context.Context, sessionID string, prompt *PromptRequest) (<-chan string, error) GetSession(ctx context.Context, sessionID string) (*Session, error) ListSessions(ctx context.Context) ([]Session, error) GetBaseURL() string GetPort() int } // Session 会话信息 type Session struct { ID string `json:"id"` Title string `json:"title"` ParentID string `json:"parentID,omitempty"` Path map[string]string `json:"path,omitempty"` CreatedAt string `json:"createdAt,omitempty"` } // PromptRequest 对话请求 type PromptRequest struct { Parts []TextPart `json:"parts"` Agent string `json:"agent,omitempty"` Model *ModelInfo `json:"model,omitempty"` } // TextPart 文本部分 type TextPart struct { Type string `json:"type"` Text string `json:"text"` } // ModelInfo 模型信息 type ModelInfo struct { ProviderID string `json:"providerID"` ModelID string `json:"modelID"` } // PromptResponse 对话响应 type PromptResponse struct { Info AssistantMessage `json:"info"` Parts []interface{} `json:"parts"` } // AssistantMessage 助理消息 type AssistantMessage struct { ID string `json:"id"` Role string `json:"role"` SessionID string `json:"sessionID"` Content string `json:"content,omitempty"` Agent string `json:"agent"` ModelID string `json:"modelID"` ProviderID string `json:"providerID"` Tokens TokenInfo `json:"tokens"` Time map[string]interface{} `json:"time"` } // TokenInfo token 信息 type TokenInfo struct { Input int `json:"input"` Output int `json:"output"` }