| 1 | package runnerproto |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 5 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 6 | "encoding/json" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | type RunnerPrincipal struct{ RunnerID, Person, CredentialID string } |
| 11 | |
| 12 | const CoordinatorCapability = "coordinator.v1" |
| 13 | |
| 14 | type CoordinatorBinding struct { |
| 15 | WaitingTaskID string `gorm:"-" json:",omitempty"` |
| 16 | WaitingTaskURL string `gorm:"-" json:",omitempty"` |
| 17 | ID, Person, RunnerID, ConnectionID string |
| 18 | Revision, Generation int64 |
| 19 | } |
| 20 | type CoordinatorTurn struct { |
| 21 | ID, MessageID, RequestID, ProviderSessionID, ContextHash string |
| 22 | Generation, Revision int64 |
| 23 | State string |
| 24 | } |
| 25 | type CoordinatorMessage struct { |
| 26 | ID, AuthorKind, AuthorID, Body string |
| 27 | Sequence, Revision int64 |
| 28 | } |
| 29 | type CoordinatorProject struct { |
| 30 | ID int64 |
| 31 | Label string |
| 32 | Revision int64 |
| 33 | } |
| 34 | type CoordinatorContext struct { |
| 35 | Pending []string `json:",omitempty"` |
| 36 | Hash string `json:",omitempty"` |
| 37 | Recent []MessageRef `json:",omitempty"` |
| 38 | Instructions, ConfirmedDecisions, Retrieved []ContextRef `json:",omitempty"` |
| 39 | ConversationID string |
| 40 | Revision int64 |
| 41 | Messages []CoordinatorMessage |
| 42 | Projects []CoordinatorProject |
| 43 | Sources []SourceSnapshot |
| 44 | ConfirmedPreferences []ContextRef |
| 45 | } |
| 46 | type MessageRef struct { |
| 47 | ID, AuthorKind, Body string |
| 48 | Sequence, Revision int64 |
| 49 | } |
| 50 | type SourceRef = team.SourceRef |
| 51 | |
| 52 | type ContextRef struct { |
| 53 | Source SourceRef |
| 54 | Text string |
| 55 | } |
| 56 | type CoordinatorToolCopy struct { |
| 57 | Accepted, Rejected string |
| 58 | Descriptions map[string]string |
| 59 | } |
| 60 | type CoordinatorClaim struct { |
| 61 | ToolCopy CoordinatorToolCopy |
| 62 | Binding CoordinatorBinding |
| 63 | Turn CoordinatorTurn |
| 64 | Scope team.Scope |
| 65 | Handle team.Handle |
| 66 | Brief RunnerBrief |
| 67 | Context CoordinatorContext |
| 68 | Admission team.AdmissionTicket |
| 69 | LeaseDeadline, AttemptDeadline time.Time |
| 70 | } |
| 71 | type CoordinatorRequest struct { |
| 72 | ToolCall *CoordinatorToolCall `json:"tool_call,omitempty"` |
| 73 | Version int `json:"version"` |
| 74 | Capabilities []string `json:"capabilities"` |
| 75 | TurnID string `json:"turn_id,omitempty"` |
| 76 | Revision int64 `json:"revision,omitempty"` |
| 77 | Claim *CoordinatorClaim `json:"claim,omitempty"` |
| 78 | Event *Event `json:"event,omitempty"` |
| 79 | Proof *ContainmentProof `json:"proof,omitempty"` |
| 80 | } |
| 81 | |
| 82 | type CoordinatorToolCall struct { |
| 83 | RequestID string `json:"request_id"` |
| 84 | Name string `json:"name"` |
| 85 | Arguments json.RawMessage `json:"arguments"` |
| 86 | } |
| 87 | type CoordinatorToolResult struct { |
| 88 | ResourceID string `json:"resource_id"` |
| 89 | Revision int64 `json:"revision"` |
| 90 | Value json.RawMessage `json:"value"` |
| 91 | } |
| 92 | type ClarificationQuestion struct { |
| 93 | ID, MessageID, TurnID, Prompt, State string |
| 94 | Options []QuestionOption |
| 95 | Revision, Generation int64 |
| 96 | ExpiresAt time.Time |
| 97 | } |
| 98 | type QuestionOption struct { |
| 99 | ID string `json:"id"` |
| 100 | Label string `json:"label"` |
| 101 | } |
| 102 | |
| 103 | func CoordinatorCopy(copy map[string]string, accepted, rejected string) CoordinatorToolCopy { |
| 104 | out := CoordinatorToolCopy{Accepted: accepted, Rejected: rejected, Descriptions: map[string]string{}} |
| 105 | for _, name := range provider.CoordinatorTools() { |
| 106 | out.Descriptions[name] = copy["coordinator.tool."+name] |
| 107 | } |
| 108 | return out |
| 109 | } |
| 110 | |
| 111 | func NewCoordinatorRequest(c CoordinatorClaim) CoordinatorRequest { |
| 112 | return CoordinatorRequest{Version: 2, Capabilities: []string{CoordinatorCapability}, Claim: &c} |
| 113 | } |
| 114 | |
| 115 | func CoordinatorContextRef(kind, id string, rev int64, text string) ContextRef { |
| 116 | return ContextRef{Source: team.SourceRef{Kind: kind, ID: id, Revision: rev, Hash: team.ContentDigest([]byte(text))}, Text: text} |
| 117 | } |
| 118 | |