Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.go 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package opencode
  2. import (
  3. "context"
  4. )
  5. // OpenCodeClient opencode 客户端接口
  6. type OpenCodeClient interface {
  7. CreateSession(ctx context.Context, title string) (*Session, error)
  8. SendPrompt(ctx context.Context, sessionID string, prompt *PromptRequest) (*PromptResponse, error)
  9. SendPromptStream(ctx context.Context, sessionID string, prompt *PromptRequest) (<-chan string, error)
  10. GetSession(ctx context.Context, sessionID string) (*Session, error)
  11. ListSessions(ctx context.Context) ([]Session, error)
  12. GetBaseURL() string
  13. GetPort() int
  14. }
  15. // Session 会话信息
  16. type Session struct {
  17. ID string `json:"id"`
  18. Title string `json:"title"`
  19. ParentID string `json:"parentID,omitempty"`
  20. Path map[string]string `json:"path,omitempty"`
  21. CreatedAt string `json:"createdAt,omitempty"`
  22. }
  23. // PromptRequest 对话请求
  24. type PromptRequest struct {
  25. Parts []TextPart `json:"parts"`
  26. Agent string `json:"agent,omitempty"`
  27. Model *ModelInfo `json:"model,omitempty"`
  28. // Experimental 实验性配置
  29. Experimental *struct {
  30. DisablePasteSummary *bool `json:"disable_paste_summary,omitempty"`
  31. } `json:"experimental,omitempty"`
  32. }
  33. // TextPart 文本部分
  34. type TextPart struct {
  35. Type string `json:"type"`
  36. Text string `json:"text"`
  37. }
  38. // ModelInfo 模型信息
  39. type ModelInfo struct {
  40. ProviderID string `json:"providerID"`
  41. ModelID string `json:"modelID"`
  42. }
  43. // PromptResponse 对话响应
  44. type PromptResponse struct {
  45. Info AssistantMessage `json:"info"`
  46. Parts []interface{} `json:"parts"`
  47. }
  48. // AssistantMessage 助理消息
  49. type AssistantMessage struct {
  50. ID string `json:"id"`
  51. Role string `json:"role"`
  52. SessionID string `json:"sessionID"`
  53. Content string `json:"content,omitempty"`
  54. Agent string `json:"agent"`
  55. ModelID string `json:"modelID"`
  56. ProviderID string `json:"providerID"`
  57. Tokens TokenInfo `json:"tokens"`
  58. Time map[string]interface{} `json:"time"`
  59. }
  60. // TokenInfo token 信息
  61. type TokenInfo struct {
  62. Input int `json:"input"`
  63. Output int `json:"output"`
  64. }