bridge.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package app
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/sst/opencode/pkg/client"
  6. )
  7. // AgentServiceBridge provides a minimal agent service that sends messages to the API
  8. type AgentServiceBridge struct {
  9. client *client.ClientWithResponses
  10. }
  11. // NewAgentServiceBridge creates a new agent service bridge
  12. func NewAgentServiceBridge(client *client.ClientWithResponses) *AgentServiceBridge {
  13. return &AgentServiceBridge{client: client}
  14. }
  15. // Run sends a message to the chat API
  16. func (a *AgentServiceBridge) Run(ctx context.Context, sessionID string, text string, attachments ...Attachment) (string, error) {
  17. // TODO: Handle attachments when API supports them
  18. if len(attachments) > 0 {
  19. // For now, ignore attachments
  20. // return "", fmt.Errorf("attachments not supported yet")
  21. }
  22. part := client.MessagePart{}
  23. part.FromMessagePartText(client.MessagePartText{
  24. Type: "text",
  25. Text: text,
  26. })
  27. parts := []client.MessagePart{part}
  28. go a.client.PostSessionChatWithResponse(ctx, client.PostSessionChatJSONRequestBody{
  29. SessionID: sessionID,
  30. Parts: parts,
  31. ProviderID: "anthropic",
  32. ModelID: "claude-sonnet-4-20250514",
  33. })
  34. // The actual response will come through SSE
  35. // For now, just return success
  36. return "", nil
  37. }
  38. // Cancel cancels the current generation - NOT IMPLEMENTED IN API YET
  39. func (a *AgentServiceBridge) Cancel(sessionID string) error {
  40. // TODO: Not implemented in TypeScript API yet
  41. return nil
  42. }
  43. // IsBusy checks if the agent is busy - NOT IMPLEMENTED IN API YET
  44. func (a *AgentServiceBridge) IsBusy() bool {
  45. // TODO: Not implemented in TypeScript API yet
  46. return false
  47. }
  48. // IsSessionBusy checks if the agent is busy for a specific session - NOT IMPLEMENTED IN API YET
  49. func (a *AgentServiceBridge) IsSessionBusy(sessionID string) bool {
  50. // TODO: Not implemented in TypeScript API yet
  51. return false
  52. }
  53. // CompactSession compacts a session - NOT IMPLEMENTED IN API YET
  54. func (a *AgentServiceBridge) CompactSession(ctx context.Context, sessionID string, force bool) error {
  55. // TODO: Not implemented in TypeScript API yet
  56. return fmt.Errorf("session compaction not implemented in API")
  57. }