暫無描述
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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  29. // TextPart 文本部分
  30. type TextPart struct {
  31. Type string `json:"type"`
  32. Text string `json:"text"`
  33. }
  34. // ModelInfo 模型信息
  35. type ModelInfo struct {
  36. ProviderID string `json:"providerID"`
  37. ModelID string `json:"modelID"`
  38. }
  39. // PromptResponse 对话响应
  40. type PromptResponse struct {
  41. Info AssistantMessage `json:"info"`
  42. Parts []interface{} `json:"parts"`
  43. }
  44. // AssistantMessage 助理消息
  45. type AssistantMessage struct {
  46. ID string `json:"id"`
  47. Role string `json:"role"`
  48. SessionID string `json:"sessionID"`
  49. Content string `json:"content,omitempty"`
  50. Agent string `json:"agent"`
  51. ModelID string `json:"modelID"`
  52. ProviderID string `json:"providerID"`
  53. Tokens TokenInfo `json:"tokens"`
  54. Time map[string]interface{} `json:"time"`
  55. }
  56. // TokenInfo token 信息
  57. type TokenInfo struct {
  58. Input int `json:"input"`
  59. Output int `json:"output"`
  60. }