types.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Package agentserver 新 AI 助手对接 AgentServer 的客户端与代理。
  2. // 接口与事件结构以 AgentServer 仓库 packages/shared/src/api.ts、events.ts 为准,这里只声明用到的字段。
  3. package agentserver
  4. import "encoding/json"
  5. // SessionDto AgentServer 会话(POST/PATCH /v1/sessions 的返回)
  6. type SessionDto struct {
  7. Id string `json:"id"`
  8. Title string `json:"title"`
  9. Model string `json:"model"`
  10. ProfileId *string `json:"profileId"`
  11. CreatedAt string `json:"createdAt"`
  12. UpdatedAt string `json:"updatedAt"`
  13. }
  14. // SessionDetailDto GET /v1/sessions/:id 的返回(只取索引子资源需要的字段)
  15. type SessionDetailDto struct {
  16. Id string `json:"id"`
  17. ActiveRunId *string `json:"activeRunId"`
  18. PendingInteractions []InteractionRefDto `json:"pendingInteractions"`
  19. }
  20. // RunDto Run 状态(POST /messages、GET /runs/:id 的返回)
  21. type RunDto struct {
  22. Id string `json:"id"`
  23. SessionId string `json:"sessionId"`
  24. }
  25. // FileDto 工作区文件(POST/GET /sessions/:id/files 的返回元素)
  26. type FileDto struct {
  27. Id string `json:"id"`
  28. SessionId string `json:"sessionId"`
  29. Path string `json:"path"`
  30. }
  31. // InteractionRefDto 交互请求(只取 ID)
  32. type InteractionRefDto struct {
  33. InteractionId string `json:"interactionId"`
  34. }
  35. // AgentEvent 事件信封(SSE data 与 /events items 的元素)
  36. type AgentEvent struct {
  37. Seq int64 `json:"seq"`
  38. Type string `json:"type"`
  39. SessionId string `json:"sessionId"`
  40. RunId *string `json:"runId"`
  41. Payload json.RawMessage `json:"payload"`
  42. }
  43. // EventsPage GET /v1/sessions/:id/events 的返回
  44. type EventsPage struct {
  45. Items []AgentEvent `json:"items"`
  46. }
  47. // ErrorBody AgentServer 的错误格式:{ "error": { "code", "message" } }
  48. type ErrorBody struct {
  49. Error struct {
  50. Code string `json:"code"`
  51. Message string `json:"message"`
  52. } `json:"error"`
  53. }
  54. // 子资源 ID 前缀(AgentServer 使用带前缀的 ULID)
  55. const (
  56. PrefixSession = "ses_"
  57. PrefixRun = "run_"
  58. PrefixInteraction = "itx_"
  59. PrefixFile = "file_"
  60. )