| 1 | package personapi |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "time" |
| 7 | |
| 8 | "amadan.net/oficina/equipo/internal/equipo/conversation" |
| 9 | "amadan.net/oficina/equipo/internal/equipo/kernel" |
| 10 | "amadan.net/oficina/equipo/internal/equipo/planning" |
| 11 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 12 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 13 | "amadan.net/oficina/equipo/internal/taskplan" |
| 14 | ) |
| 15 | |
| 16 | type PersonPrincipal struct { |
| 17 | Pending bool |
| 18 | Address, CredentialID string |
| 19 | SessionHash string |
| 20 | SessionEpoch int64 |
| 21 | } |
| 22 | type VerifyPersonBearer func(context.Context, string) (PersonPrincipal, error) |
| 23 | type Page[T any] struct { |
| 24 | Items []T `json:"items"` |
| 25 | NextCursor string `json:"next_cursor"` |
| 26 | Revision int64 `json:"revision"` |
| 27 | } |
| 28 | type Error struct { |
| 29 | Code string `json:"code"` |
| 30 | CopyKey string `json:"copy_key"` |
| 31 | RequestID string `json:"request_id"` |
| 32 | CurrentRevision *int64 `json:"current_revision,omitempty"` |
| 33 | } |
| 34 | type Result struct { |
| 35 | Value any |
| 36 | Revision int64 |
| 37 | } |
| 38 | type Person struct { |
| 39 | Address string `json:"address"` |
| 40 | DisplayIdentity string `json:"display_identity"` |
| 41 | Active bool `json:"active"` |
| 42 | Role string `json:"role"` |
| 43 | } |
| 44 | type Me struct { |
| 45 | ID string `json:"id"` |
| 46 | Address string `json:"address"` |
| 47 | Role string `json:"role"` |
| 48 | Person Person `json:"person"` |
| 49 | TeamID string `json:"team_id"` |
| 50 | TeamName string `json:"team_name"` |
| 51 | Revision int64 `json:"revision"` |
| 52 | } |
| 53 | type Settings struct { |
| 54 | Landing string `json:"landing"` |
| 55 | Revision int64 `json:"revision"` |
| 56 | } |
| 57 | type Message struct { |
| 58 | ID string `json:"id"` |
| 59 | ConversationID string `json:"conversation_id"` |
| 60 | ThreadID string `json:"thread_id"` |
| 61 | AuthorKind string `json:"author_kind"` |
| 62 | AuthorID string `json:"author_id"` |
| 63 | Body string `json:"body"` |
| 64 | Sequence int64 `json:"sequence"` |
| 65 | Revision int64 `json:"revision"` |
| 66 | CreatedAt time.Time `json:"created_at"` |
| 67 | Sources []team.SourceRef `json:"sources"` |
| 68 | } |
| 69 | type Card struct { |
| 70 | ID string `json:"id"` |
| 71 | Kind string `json:"kind"` |
| 72 | ResourceID string `json:"resource_id"` |
| 73 | TaskID string `json:"task_id"` |
| 74 | Revision int64 `json:"revision"` |
| 75 | CopyKey string `json:"copy_key"` |
| 76 | Actions []string `json:"actions"` |
| 77 | WaitingTaskID string `json:"waiting_task_id"` |
| 78 | } |
| 79 | type ConversationPage struct { |
| 80 | Messages []Message `json:"messages"` |
| 81 | Cards []Card `json:"cards"` |
| 82 | NextCursor string `json:"next_cursor"` |
| 83 | Revision int64 `json:"revision"` |
| 84 | } |
| 85 | type Preference struct { |
| 86 | ID string `json:"id"` |
| 87 | Text string `json:"text"` |
| 88 | Status string `json:"status"` |
| 89 | SourceMessageID string `json:"source_message_id"` |
| 90 | Revision int64 `json:"revision"` |
| 91 | } |
| 92 | type Task struct { |
| 93 | ID string `json:"id"` |
| 94 | ProjectID int64 `json:"project_id"` |
| 95 | Requester string `json:"requester"` |
| 96 | Description string `json:"description"` |
| 97 | Kind taskplan.Kind `json:"kind"` |
| 98 | State string `json:"state"` |
| 99 | Revision int64 `json:"revision"` |
| 100 | PlanRevision int64 `json:"plan_revision"` |
| 101 | ReplacementID string `json:"replacement_id"` |
| 102 | CanCancel bool `json:"can_cancel"` |
| 103 | CanMerge bool `json:"can_merge"` |
| 104 | NeedsYou bool `json:"needs_you"` |
| 105 | Steps []Step `json:"steps"` |
| 106 | Usage *Usage `json:"usage"` |
| 107 | } |
| 108 | type Usage struct { |
| 109 | Calls int64 `json:"calls"` |
| 110 | InputTokens int64 `json:"input_tokens"` |
| 111 | OutputTokens int64 `json:"output_tokens"` |
| 112 | } |
| 113 | type Step struct { |
| 114 | Key string `json:"key"` |
| 115 | Category string `json:"category"` |
| 116 | Action string `json:"action"` |
| 117 | State string `json:"state"` |
| 118 | Model string `json:"model"` |
| 119 | Account string `json:"account"` |
| 120 | Actual string `json:"actual"` |
| 121 | Reason string `json:"reason"` |
| 122 | Usage *Usage `json:"usage"` |
| 123 | AllowanceRemaining *int64 `json:"allowance_remaining"` |
| 124 | } |
| 125 | type Coordinator struct { |
| 126 | ID string `json:"id"` |
| 127 | RunnerID string `json:"runner_id"` |
| 128 | ConnectionID string `json:"connection_id"` |
| 129 | Generation int64 `json:"generation"` |
| 130 | Revision int64 `json:"revision"` |
| 131 | WaitingTaskID string `json:"waiting_task_id"` |
| 132 | Turns []Turn `json:"turns"` |
| 133 | Limits *Limits `json:"limits"` |
| 134 | LimitsRevision int64 `json:"limits_revision"` |
| 135 | } |
| 136 | type Turn struct { |
| 137 | ID string `json:"id"` |
| 138 | State string `json:"state"` |
| 139 | Revision int64 `json:"revision"` |
| 140 | } |
| 141 | type Question struct { |
| 142 | ID string `json:"id"` |
| 143 | Kind string `json:"kind"` |
| 144 | TaskID string `json:"task_id"` |
| 145 | Text string `json:"text"` |
| 146 | State string `json:"state"` |
| 147 | Revision int64 `json:"revision"` |
| 148 | CanAnswer bool `json:"can_answer"` |
| 149 | CanAllow bool `json:"can_allow"` |
| 150 | Options []Option `json:"options"` |
| 151 | Fields []Field `json:"fields"` |
| 152 | AllowText bool `json:"allow_text"` |
| 153 | ExpiresAt *time.Time `json:"expires_at"` |
| 154 | } |
| 155 | type Option struct { |
| 156 | ID string `json:"id"` |
| 157 | Label string `json:"label"` |
| 158 | } |
| 159 | type Field struct { |
| 160 | Key string `json:"key"` |
| 161 | Prompt string `json:"prompt"` |
| 162 | } |
| 163 | type Ack struct { |
| 164 | Revision int64 `json:"revision"` |
| 165 | } |
| 166 | |
| 167 | type MessageInput struct { |
| 168 | Body string `json:"body"` |
| 169 | } |
| 170 | type SettingsInput struct { |
| 171 | Landing string `json:"landing"` |
| 172 | } |
| 173 | type RouteInput struct { |
| 174 | TaskID string `json:"task_id"` |
| 175 | } |
| 176 | type ProjectInput struct { |
| 177 | ProjectID int64 `json:"project_id"` |
| 178 | } |
| 179 | type PreferenceInput struct { |
| 180 | Text string `json:"text"` |
| 181 | SourceMessageID string `json:"source_message_id,omitempty"` |
| 182 | } |
| 183 | type BindingInput struct { |
| 184 | RunnerID string `json:"runner_id"` |
| 185 | ConnectionID string `json:"connection_id"` |
| 186 | } |
| 187 | type RetryInput struct { |
| 188 | TurnID string `json:"turn_id"` |
| 189 | } |
| 190 | type Limits struct { |
| 191 | Calls int64 `json:"calls"` |
| 192 | InputTokens int64 `json:"input_tokens"` |
| 193 | OutputTokens int64 `json:"output_tokens"` |
| 194 | Seconds int64 `json:"seconds"` |
| 195 | } |
| 196 | type LimitsInput struct { |
| 197 | Person string `json:"person"` |
| 198 | Limits Limits `json:"limits"` |
| 199 | } |
| 200 | type RenderedInput struct { |
| 201 | CandidateHash string `json:"candidate_hash"` |
| 202 | DiffHash string `json:"diff_hash"` |
| 203 | RenderHash string `json:"render_hash"` |
| 204 | Decision string `json:"decision"` |
| 205 | } |
| 206 | type MergeInput struct { |
| 207 | Reference string `json:"reference"` |
| 208 | } |
| 209 | type AnswerInput struct { |
| 210 | Kind string `json:"kind"` |
| 211 | OptionID string `json:"option_id,omitempty"` |
| 212 | Text string `json:"text,omitempty"` |
| 213 | Behavior string `json:"behavior,omitempty"` |
| 214 | UpdatedInput json.RawMessage `json:"updated_input,omitempty"` |
| 215 | } |
| 216 | type PlanInput struct { |
| 217 | Kind taskplan.Kind `json:"kind"` |
| 218 | ProjectID int64 `json:"project_id"` |
| 219 | Steps []PlanStep `json:"steps"` |
| 220 | PlaybookID string `json:"playbook_id"` |
| 221 | PlaybookRevision int64 `json:"playbook_revision"` |
| 222 | } |
| 223 | type PlanStep struct { |
| 224 | DependsOn []string `json:"depends_on,omitempty"` |
| 225 | Key string `json:"key"` |
| 226 | Specialist string `json:"specialist"` |
| 227 | Action string `json:"action"` |
| 228 | Instructions string `json:"instructions"` |
| 229 | ConnectionID string `json:"connection_id"` |
| 230 | Model string `json:"model"` |
| 231 | SelectionReason string `json:"selection_reason"` |
| 232 | } |
| 233 | type Plan struct { |
| 234 | PlanInput |
| 235 | TaskID string `json:"task_id"` |
| 236 | Revision int64 `json:"revision"` |
| 237 | RequiredSteps []string `json:"required_steps"` |
| 238 | } |
| 239 | |
| 240 | type Application interface { |
| 241 | NotificationOperations |
| 242 | PersonAPIExtendedMutation(context.Context, kernel.Actor, string, string, any, kernel.Mutation) (Result, error) |
| 243 | Conversation(context.Context, kernel.Actor, string, int) (conversation.ConversationPage, error) |
| 244 | SendMessage(context.Context, kernel.Actor, string, string, kernel.Mutation) (conversation.Message, error) |
| 245 | TaskThread(context.Context, kernel.Actor, string, string, int) (conversation.ConversationPage, error) |
| 246 | RouteMessage(context.Context, kernel.Actor, string, string, kernel.Mutation) (conversation.Message, error) |
| 247 | PersonalSettings(context.Context, kernel.Actor) (conversation.PersonalSettings, error) |
| 248 | SavePersonalSettings(context.Context, kernel.Actor, conversation.PersonalSettings, kernel.Mutation) (conversation.PersonalSettings, error) |
| 249 | Preferences(context.Context, kernel.Actor) ([]conversation.Preference, error) |
| 250 | SetPreference(context.Context, kernel.Actor, conversation.Preference, kernel.Mutation) (conversation.Preference, error) |
| 251 | DeletePreference(context.Context, kernel.Actor, string, kernel.Mutation) error |
| 252 | TaskPlan(context.Context, kernel.Actor, string) (taskplan.Plan, error) |
| 253 | ProposePlan(context.Context, kernel.Actor, taskplan.Plan, kernel.Mutation) (taskplan.Plan, error) |
| 254 | EditPlan(context.Context, kernel.Actor, taskplan.Plan, kernel.Mutation) (taskplan.Plan, error) |
| 255 | ApprovePlan(context.Context, kernel.Actor, string, kernel.Mutation) (planning.Task, error) |
| 256 | CorrectTaskProject(context.Context, kernel.Actor, string, int64, kernel.Mutation) (planning.Task, error) |
| 257 | SaveCoordinatorBinding(context.Context, kernel.Actor, string, string, kernel.Mutation) (runnerproto.CoordinatorBinding, error) |
| 258 | ResetCoordinator(context.Context, kernel.Actor, kernel.Mutation) (runnerproto.CoordinatorBinding, error) |
| 259 | RetryCoordinatorTurn(context.Context, kernel.Actor, string, kernel.Mutation) (runnerproto.CoordinatorTurn, error) |
| 260 | SetCoordinatorLimits(context.Context, kernel.Actor, string, team.Limits, kernel.Mutation) error |
| 261 | AnswerClarification(context.Context, kernel.Actor, string, string, string, kernel.Mutation) error |
| 262 | AnswerQuestion(context.Context, kernel.Actor, string, int64, runnerproto.QuestionAnswer) error |
| 263 | ApproveRenderedChange(context.Context, kernel.Actor, string, string, string, string, string, kernel.Mutation) error |
| 264 | AcknowledgeMerge(context.Context, kernel.Actor, string, int64, string) error |
| 265 | PersonAPIRead(context.Context, kernel.Actor, string, string, string, int) (Result, error) |
| 266 | PersonAPICancel(context.Context, kernel.Actor, string, kernel.Mutation) (Ack, error) |
| 267 | } |
| 268 | |