| 1 | // Package wire is the thin v1 contract: person API v1 resources and events, |
| 2 | // and the runner stream frames. The instance, the runner, the headless suite |
| 3 | // and the native apps all build against these types and the recorded |
| 4 | // fixtures in testdata. |
| 5 | package wire |
| 6 | |
| 7 | import ( |
| 8 | "bytes" |
| 9 | "encoding/json" |
| 10 | "errors" |
| 11 | "io" |
| 12 | "time" |
| 13 | ) |
| 14 | |
| 15 | // Turn states. A turn ends in exactly one of replied, failed or cancelled. |
| 16 | const ( |
| 17 | TurnQueued = "queued" |
| 18 | TurnRunning = "running" |
| 19 | // TurnWaiting is a dispatched turn held by its runner because nothing |
| 20 | // the person connected can answer now (reason no_connection). It is |
| 21 | // not an ending: the turn goes on its own when a connection returns, |
| 22 | // and the person may cancel it. |
| 23 | TurnWaiting = "waiting" |
| 24 | TurnReplied = "replied" |
| 25 | TurnFailed = "failed" |
| 26 | TurnCancelled = "cancelled" |
| 27 | ) |
| 28 | |
| 29 | // Message roles. |
| 30 | const ( |
| 31 | RolePerson = "person" |
| 32 | RoleCoordinator = "coordinator" |
| 33 | ) |
| 34 | |
| 35 | // Event types on GET /api/v1/events. |
| 36 | const ( |
| 37 | EventMessage = "message" |
| 38 | EventTurn = "turn" |
| 39 | EventDelta = "delta" |
| 40 | EventRunner = "runner" |
| 41 | EventPing = "ping" |
| 42 | EventCard = "card" |
| 43 | EventProject = "project" |
| 44 | EventActivity = "activity" |
| 45 | // EventGlance carries the Assistant's instant first line for a turn |
| 46 | // (Glance), on the Assistant's stream only. Like a delta it has |
| 47 | // revision 0 and nothing stores it. |
| 48 | EventGlance = "glance" |
| 49 | // EventCoordinator carries the person's Coordinator resource. |
| 50 | EventCoordinator = "coordinator" |
| 51 | ) |
| 52 | |
| 53 | // Turn kinds. A person turn answers the person's messages; the runner |
| 54 | // starts the others itself: move_in when the coordinator's desk is empty |
| 55 | // (it looks around and introduces itself once) and explore when the |
| 56 | // reachable namespaces changed (it looks at the difference only). |
| 57 | const ( |
| 58 | TurnPerson = "" |
| 59 | TurnMoveIn = "move_in" |
| 60 | TurnExplore = "explore" |
| 61 | // TurnHousekeeping is a housekeeping judgement turn (spec |
| 62 | // 2026-11-08-equipo-housekeeping.md, slice 3): queued after the |
| 63 | // person's own turns and after move-in and explore. |
| 64 | TurnHousekeeping = "housekeeping" |
| 65 | // TurnSpecialistAdded is the coordinator's continuation after an |
| 66 | // owner's Add on a specialist card for one project (spec |
| 67 | // 2026-11-28-dynamic-specialists.md, section 1, Routing): queued by |
| 68 | // the instance in the Add's transaction, once per card, in the |
| 69 | // proposing turn's lane. It may only record the card's task in the |
| 70 | // card's project and start it with the card's specialist. |
| 71 | TurnSpecialistAdded = "specialist_added" |
| 72 | // ReasonYielded ends a move_in or explore turn that gave way to a |
| 73 | // person's message; it continues in a new turn after the answer. |
| 74 | ReasonYielded = "yielded" |
| 75 | ) |
| 76 | |
| 77 | // Coordinator states: new (has not moved in), moving_in, ready. |
| 78 | const ( |
| 79 | CoordinatorNew = "new" |
| 80 | CoordinatorMovingIn = "moving_in" |
| 81 | CoordinatorReady = "ready" |
| 82 | ) |
| 83 | |
| 84 | // Notebook is GET /api/v1/notebook: the person's coordinator's notebook |
| 85 | // as its runner last reported it, each entry with where it came from. ID |
| 86 | // is the person. POST /api/v1/notebook/reset clears it and starts the |
| 87 | // coordinator afresh (202 with the Coordinator, 409 while a turn runs). |
| 88 | type Notebook struct { |
| 89 | ID string `json:"id"` |
| 90 | Revision int64 `json:"revision"` |
| 91 | Entries []NotebookEntry `json:"entries"` |
| 92 | UpdatedAt *time.Time `json:"updated_at"` |
| 93 | } |
| 94 | |
| 95 | // Coordinator is the person's coordinator as the person sees it: whether |
| 96 | // it has moved in, and the move-in turn while one runs. ID is the person. |
| 97 | type Coordinator struct { |
| 98 | ID string `json:"id"` |
| 99 | Revision int64 `json:"revision"` |
| 100 | State string `json:"state"` |
| 101 | TurnID string `json:"turn_id"` |
| 102 | MovedInAt *time.Time `json:"moved_in_at"` |
| 103 | } |
| 104 | |
| 105 | // Project states. |
| 106 | const ( |
| 107 | ProjectActive = "active" |
| 108 | ProjectRemoved = "removed" |
| 109 | ) |
| 110 | |
| 111 | // Card kinds and states. A project card says what the coordinator added |
| 112 | // and offers Remove; a question card waits for one answer. |
| 113 | const ( |
| 114 | CardProject = "project" |
| 115 | CardQuestion = "question" |
| 116 | CardAccess = "access" |
| 117 | CardAdded = "added" |
| 118 | CardWorking = "working" |
| 119 | CardCreated = "created" |
| 120 | CardChanged = "changed" |
| 121 | CardRemoved = "removed" |
| 122 | CardOpen = "open" |
| 123 | CardAnswered = "answered" |
| 124 | // CardHome reports a change of where new projects go (Name is the |
| 125 | // namespace, empty when cleared) and offers Undo while CardHomeSet. |
| 126 | CardHome = "home" |
| 127 | CardHomeSet = "set" |
| 128 | CardUndone = "undone" |
| 129 | // CardHomeAsk asks the owner to confirm a change the coordinator was |
| 130 | // not sure the person asked for; ChoiceConfirm applies it. |
| 131 | CardHomeAsk = "ask" |
| 132 | // ChoiceUndo is the answer that undoes a home card. |
| 133 | ChoiceUndo = "undo" |
| 134 | ChoiceConfirm = "confirm" |
| 135 | ActivityThink = "thinking" |
| 136 | ActivityTool = "tool" |
| 137 | MaxQuestion = 500 |
| 138 | MaxOptions = 6 |
| 139 | MaxOption = 80 |
| 140 | MaxProjectCards = 50 |
| 141 | ) |
| 142 | |
| 143 | // Terminal reports whether a turn state is final. |
| 144 | // InFlight are the states of a turn that has not ended. |
| 145 | var InFlight = []string{TurnQueued, TurnRunning, TurnWaiting} |
| 146 | |
| 147 | func Terminal(state string) bool { |
| 148 | return state == TurnReplied || state == TurnFailed || state == TurnCancelled |
| 149 | } |
| 150 | |
| 151 | // Me is GET /api/v1/me. Person repeats the identity in the shape the |
| 152 | // earlier person API used. |
| 153 | type Me struct { |
| 154 | ID string `json:"id"` |
| 155 | Address string `json:"address"` |
| 156 | Role string `json:"role"` |
| 157 | Person Person `json:"person"` |
| 158 | TeamID string `json:"team_id"` |
| 159 | TeamName string `json:"team_name"` |
| 160 | Revision int64 `json:"revision"` |
| 161 | } |
| 162 | |
| 163 | // Person is a team member. |
| 164 | type Person struct { |
| 165 | Address string `json:"address"` |
| 166 | DisplayIdentity string `json:"display_identity"` |
| 167 | Active bool `json:"active"` |
| 168 | Role string `json:"role"` |
| 169 | } |
| 170 | |
| 171 | // Message is one line of the person's conversation. |
| 172 | type Message struct { |
| 173 | ProjectID string `json:"project_id,omitempty"` |
| 174 | ID string `json:"id"` |
| 175 | Revision int64 `json:"revision"` |
| 176 | Role string `json:"role"` |
| 177 | Text string `json:"text"` |
| 178 | TurnID string `json:"turn_id"` |
| 179 | CreatedAt time.Time `json:"created_at"` |
| 180 | // Switched is the quiet line under a reply that moved to another |
| 181 | // connection; clients render it with the reset in the person's zone. |
| 182 | Switched *Switched `json:"switched"` |
| 183 | // Attachments are the images and files sent with a person's message, |
| 184 | // in the order they were attached; omitted when there are none. |
| 185 | Attachments []MessageAttachment `json:"attachments,omitempty"` |
| 186 | // Lookups are the answers and sources shown under an Assistant reply, |
| 187 | // in call order, at most MaxLookupsPerReply; omitted when there are |
| 188 | // none (spec 2026-11-26-assistant-abilities §4.6). |
| 189 | Lookups []AssistantLookup `json:"lookups,omitempty"` |
| 190 | } |
| 191 | |
| 192 | // MessageAttachment is an image or file the person uploaded (POST |
| 193 | // /api/v1/attachments) and then sent with a message. Kind is image or |
| 194 | // file; MediaType was sniffed from the bytes. Width and Height are an |
| 195 | // image's upright size, 0 for a file. MessageID is empty until sent. The |
| 196 | // bytes are GET /api/v1/attachments/{id}; an image's thumbnail (at most |
| 197 | // 1024 px) is GET /api/v1/attachments/{id}/preview. |
| 198 | type MessageAttachment struct { |
| 199 | ID string `json:"id"` |
| 200 | Revision int64 `json:"revision"` |
| 201 | Kind string `json:"kind"` |
| 202 | Name string `json:"name"` |
| 203 | MediaType string `json:"media_type"` |
| 204 | Size int64 `json:"size"` |
| 205 | SHA256 string `json:"sha256"` |
| 206 | Width int `json:"width"` |
| 207 | Height int `json:"height"` |
| 208 | MessageID string `json:"message_id"` |
| 209 | CreatedAt time.Time `json:"created_at"` |
| 210 | } |
| 211 | |
| 212 | // Message attachment kinds. |
| 213 | const ( |
| 214 | AttachmentImage = "image" |
| 215 | AttachmentFile = "file" |
| 216 | ) |
| 217 | |
| 218 | // Turn is one coordinator answer to one or more queued person messages, |
| 219 | // or a turn the coordinator takes on its own (Kind move_in or explore). |
| 220 | type Turn struct { |
| 221 | ID string `json:"id"` |
| 222 | Revision int64 `json:"revision"` |
| 223 | Kind string `json:"kind"` |
| 224 | State string `json:"state"` |
| 225 | Reason string `json:"reason"` |
| 226 | Attempt int64 `json:"attempt"` |
| 227 | MessageIDs []string `json:"message_ids"` |
| 228 | ReplyID string `json:"reply_id"` |
| 229 | // Connection is the runner's connection (LocalID) that answered. |
| 230 | Connection string `json:"connection"` |
| 231 | CreatedAt time.Time `json:"created_at"` |
| 232 | UpdatedAt time.Time `json:"updated_at"` |
| 233 | // Timing is where a replied turn's time went, for diagnosis only. |
| 234 | Timing *TurnTiming `json:"timing"` |
| 235 | } |
| 236 | |
| 237 | // TurnTiming splits one turn's wall time. Each side measures on its own |
| 238 | // clock: the instance from the message commit to the runner's ack, the |
| 239 | // runner from receiving the frame. Milliseconds; zero means not seen. |
| 240 | type TurnTiming struct { |
| 241 | // QueuedMs is message commit to the runner's ack of the command. |
| 242 | QueuedMs int64 `json:"queued_ms"` |
| 243 | // StartMs is the runner receiving the frame to the user frame on the |
| 244 | // provider's stdin: lease check, process start or copy rotation. |
| 245 | StartMs int64 `json:"start_ms"` |
| 246 | // The rest count from the user frame on stdin. |
| 247 | FirstEventMs int64 `json:"first_event_ms"` |
| 248 | FirstThinkingMs int64 `json:"first_thinking_ms"` |
| 249 | FirstToolMs int64 `json:"first_tool_ms"` |
| 250 | FirstTextMs int64 `json:"first_text_ms"` |
| 251 | LastTextMs int64 `json:"last_text_ms"` |
| 252 | ResultMs int64 `json:"result_ms"` |
| 253 | // Cold is true when the provider process started for this turn. |
| 254 | Cold bool `json:"cold"` |
| 255 | } |
| 256 | |
| 257 | // Runner is the person's own runner as the person sees it. |
| 258 | type Runner struct { |
| 259 | ID string `json:"id"` |
| 260 | Revision int64 `json:"revision"` |
| 261 | Online bool `json:"online"` |
| 262 | // Label is the machine's name ("Tito Studio"); Role primary or worker; |
| 263 | // Since when it last came online or went offline; Platform and |
| 264 | // Capabilities what it reported (null until it has). |
| 265 | Label string `json:"label"` |
| 266 | Role string `json:"role"` |
| 267 | Since *time.Time `json:"since"` |
| 268 | Platform *Platform `json:"platform"` |
| 269 | Capabilities *Capabilities `json:"capabilities"` |
| 270 | // Removing: the person removed it and it is stopping the work it may |
| 271 | // have started; it is revoked once that work's end is proven. |
| 272 | Removing bool `json:"removing"` |
| 273 | // SealKey is the runner's X25519 public key (base64), derived from its |
| 274 | // enrolment ed25519 key: secrets are sealed to it (spec §2.4). |
| 275 | SealKey string `json:"seal_key"` |
| 276 | } |
| 277 | |
| 278 | // RunnerList is GET /api/v1/runners: the person's runners, primary first. |
| 279 | type RunnerList struct { |
| 280 | Items []Runner `json:"items"` |
| 281 | } |
| 282 | |
| 283 | // Delta appends streamed text to the draft of a running turn. |
| 284 | type Delta struct { |
| 285 | TurnID string `json:"turn_id"` |
| 286 | Offset int64 `json:"offset"` |
| 287 | Text string `json:"text"` |
| 288 | } |
| 289 | |
| 290 | // Glance is a glance event's data: the line to show for the turn until |
| 291 | // its reply arrives. |
| 292 | type Glance struct { |
| 293 | TurnID string `json:"turn_id"` |
| 294 | Text string `json:"text"` |
| 295 | } |
| 296 | |
| 297 | // Activity is what the coordinator is doing before or between its text: |
| 298 | // thinking, or using one of its tools. Label is the line to show; it never |
| 299 | // carries tool input. Activity events have revision 0, like deltas. |
| 300 | type Activity struct { |
| 301 | TurnID string `json:"turn_id"` |
| 302 | Attempt int64 `json:"attempt"` |
| 303 | Kind string `json:"kind"` |
| 304 | Tool string `json:"tool"` |
| 305 | // Repo is the repository named by the activity, when known (a name |
| 306 | // from the person's catalog, never a path or query). |
| 307 | Repo string `json:"repo"` |
| 308 | Label string `json:"label"` |
| 309 | } |
| 310 | |
| 311 | // Project is a repository the team works on. Repo is the forge key, for |
| 312 | // example amadan.net/oficina/sample; Name drops the host. |
| 313 | type Project struct { |
| 314 | Starred bool `json:"starred,omitempty"` |
| 315 | Names []string `json:"names,omitempty"` |
| 316 | PersonalNames []string `json:"personal_names,omitempty"` |
| 317 | TitleSource string `json:"title_source,omitempty"` |
| 318 | DescriptionSource string `json:"description_source,omitempty"` |
| 319 | Forge string `json:"forge,omitempty"` |
| 320 | ConnectionID string `json:"connection_id,omitempty"` |
| 321 | Autonomy ProjectAutonomy `json:"autonomy,omitzero"` |
| 322 | CopyOwner string `json:"copy_owner,omitempty"` |
| 323 | CopyRevision int64 `json:"copy_revision,omitempty"` |
| 324 | ID string `json:"id"` |
| 325 | Revision int64 `json:"revision"` |
| 326 | Repo string `json:"repo"` |
| 327 | Name string `json:"name"` |
| 328 | // Title is the product's name (Woodstar); Attachments are what the |
| 329 | // project is made of, its repositories first. |
| 330 | Title string `json:"title"` |
| 331 | Attachments []Attachment `json:"attachments"` |
| 332 | State string `json:"state"` |
| 333 | AddedBy string `json:"added_by"` |
| 334 | CreatedAt time.Time `json:"created_at"` |
| 335 | UpdatedAt time.Time `json:"updated_at"` |
| 336 | // Description is one line about the product (its README's first |
| 337 | // paragraph until the coordinator writes one); Stack the languages |
| 338 | // and platforms found in its repositories (go, swift, swiftui...); |
| 339 | // Checks whether its checks run on the team's runner. People are the |
| 340 | // person who added it and everyone who filed a task in it. |
| 341 | Description string `json:"description"` |
| 342 | Stack []string `json:"stack"` |
| 343 | Checks *ProjectChecks `json:"checks"` |
| 344 | People []PersonRef `json:"people"` |
| 345 | } |
| 346 | |
| 347 | // ProjectList is GET /api/v1/projects. Allowed is the person's |
| 348 | // runner-advertised allowlist: the repositories add may take. |
| 349 | type ProjectList struct { |
| 350 | Cursor int64 `json:"cursor"` |
| 351 | Connections []ProjectConnection `json:"connections,omitempty"` |
| 352 | CanAdd []ReachableProject `json:"can_add,omitempty"` |
| 353 | Items []Project `json:"items"` |
| 354 | Allowed []string `json:"allowed"` |
| 355 | // Home is the team's namespace for new projects; empty means the |
| 356 | // coordinator uses the best-fitting existing repository (never set |
| 357 | // falls back to the runner's own home; an explicit clear does not). |
| 358 | Home string `json:"home"` |
| 359 | } |
| 360 | |
| 361 | // AddProject is the body of POST /api/v1/projects. |
| 362 | type AddProject struct { |
| 363 | Repo string `json:"repo"` |
| 364 | } |
| 365 | |
| 366 | // Card is something in the conversation the person can act on: a project |
| 367 | // the coordinator added (Remove) or a question (answer). |
| 368 | type Card struct { |
| 369 | PlacementByName bool `json:"placement_by_name,omitempty"` |
| 370 | // PlacementQuestion marks every placement question, with options or |
| 371 | // by name: it is answered in the app, never from a notification. |
| 372 | PlacementQuestion bool `json:"placement_question,omitempty"` |
| 373 | RememberName string `json:"remember_name,omitempty"` |
| 374 | Access *AccessRequest `json:"access,omitempty"` |
| 375 | ID string `json:"id"` |
| 376 | Revision int64 `json:"revision"` |
| 377 | Kind string `json:"kind"` |
| 378 | State string `json:"state"` |
| 379 | TurnID string `json:"turn_id"` |
| 380 | ProjectID string `json:"project_id"` |
| 381 | Name string `json:"name"` |
| 382 | Question string `json:"question"` |
| 383 | Options []string `json:"options"` |
| 384 | Choice string `json:"choice"` |
| 385 | // TaskID names the task a task card reports. |
| 386 | TaskID string `json:"task_id"` |
| 387 | CreatedAt time.Time `json:"created_at"` |
| 388 | UpdatedAt time.Time `json:"updated_at"` |
| 389 | // ActionID is the housekeeping action a receipt reports (the combined |
| 390 | // card); VisibleAt is when it shows in the conversation, after quiet |
| 391 | // hours. Both are absent on every other card. |
| 392 | ActionID string `json:"action_id,omitempty"` |
| 393 | VisibleAt *time.Time `json:"visible_at,omitempty"` |
| 394 | // Specialist is a specialist card's proposal; absent on every other |
| 395 | // card. |
| 396 | Specialist *CardSpecialistView `json:"specialist,omitempty"` |
| 397 | // Research is a sources card's step and URLs; absent on every other |
| 398 | // card. |
| 399 | Research *CardResearchView `json:"research,omitempty"` |
| 400 | // Inventory is a research_inventory card's primary and the addresses |
| 401 | // it lists; absent on every other card. |
| 402 | Inventory *CardInventoryView `json:"inventory,omitempty"` |
| 403 | // PreviewURL is a merge card's candidate preview, once it is up; |
| 404 | // absent otherwise. |
| 405 | PreviewURL string `json:"preview_url,omitempty"` |
| 406 | // Site is a publish card's site; absent on every other card. |
| 407 | Site *CardSite `json:"site,omitempty"` |
| 408 | // Place is a place card's proposal; absent on every other card. |
| 409 | Place *CardPlaceView `json:"place,omitempty"` |
| 410 | // Advice is an advice card's advice; absent on every other card. |
| 411 | Advice *Advice `json:"advice,omitempty"` |
| 412 | // Aside: the person set the card aside (POST /cards/{id}/visibility). |
| 413 | // It still waits on them and stays in Needs you; absent when not. |
| 414 | Aside bool `json:"aside,omitempty"` |
| 415 | } |
| 416 | |
| 417 | // AnswerCard is the body of POST /api/v1/cards/{id}/answer. Revision must |
| 418 | // be the card's current revision. |
| 419 | type AnswerCard struct { |
| 420 | IdempotencyKey string `json:"idempotency_key,omitempty"` |
| 421 | RememberName *string `json:"remember_name,omitempty"` |
| 422 | Choice string `json:"choice"` |
| 423 | Revision int64 `json:"revision"` |
| 424 | // Note is the person's words with an answer that takes them (a |
| 425 | // direction card's Try again, and its Build this naming the option |
| 426 | // they want), at most MaxDirectionNote bytes. |
| 427 | Note string `json:"note,omitempty"` |
| 428 | } |
| 429 | |
| 430 | // Answered is the response: the answered card, and the answer as the |
| 431 | // person's message with the turn that carries it to the coordinator. |
| 432 | type Answered struct { |
| 433 | Card Card `json:"card"` |
| 434 | Message Message `json:"message"` |
| 435 | Turn Turn `json:"turn"` |
| 436 | } |
| 437 | |
| 438 | // CardConflict is the 409 body for a stale or repeated answer. |
| 439 | type CardConflict struct { |
| 440 | Code string `json:"code"` |
| 441 | CopyKey string `json:"copy_key"` |
| 442 | RequestID string `json:"request_id"` |
| 443 | Card Card `json:"card"` |
| 444 | } |
| 445 | |
| 446 | // Event is the data of one Server-Sent Event. Cursor is also the SSE id. |
| 447 | // Clients apply an event only if Revision is newer than what they hold; |
| 448 | // deltas apply only when Offset equals the draft length. |
| 449 | type Event struct { |
| 450 | Cursor int64 `json:"cursor"` |
| 451 | Type string `json:"type"` |
| 452 | Resource string `json:"resource"` |
| 453 | ID string `json:"id"` |
| 454 | Revision int64 `json:"revision"` |
| 455 | TurnID string `json:"turn_id,omitempty"` |
| 456 | MessageID string `json:"message_id,omitempty"` |
| 457 | Attempt int64 `json:"attempt,omitempty"` |
| 458 | Data json.RawMessage `json:"data"` |
| 459 | } |
| 460 | |
| 461 | // Snapshot is everything a client shows, read in one transaction. |
| 462 | type Snapshot struct { |
| 463 | Me Me `json:"me"` |
| 464 | Messages []Message `json:"messages"` |
| 465 | Turns []Turn `json:"turns"` |
| 466 | Runner Runner `json:"runner"` |
| 467 | Projects []Project `json:"projects"` |
| 468 | Cards []Card `json:"cards"` |
| 469 | // Tasks are the team's tasks the cards and the Tasks page show. |
| 470 | Tasks []Task `json:"tasks"` |
| 471 | // Coordinator says whether the coordinator has moved in. |
| 472 | Coordinator Coordinator `json:"coordinator"` |
| 473 | // Connections are the person's own, every runner. |
| 474 | Connections []Connection `json:"connections"` |
| 475 | // HousekeepingSummary is the person's tidying loop at a glance. |
| 476 | HousekeepingSummary HousekeepingSummary `json:"housekeeping_summary"` |
| 477 | Cursor int64 `json:"cursor"` |
| 478 | // Runners are all the person's runners (Runner stays, the primary, |
| 479 | // for one release). |
| 480 | Runners []Runner `json:"runners"` |
| 481 | } |
| 482 | |
| 483 | // SendMessage is the body of POST /api/v1/messages. |
| 484 | type SendMessage struct { |
| 485 | ProjectID string `json:"project_id,omitempty"` |
| 486 | Text string `json:"text"` |
| 487 | IdempotencyKey string `json:"idempotency_key"` |
| 488 | // Attachments are ids from POST /api/v1/attachments, the sender's own |
| 489 | // and on no other message, at most five. Text may then be empty. |
| 490 | Attachments []string `json:"attachments,omitempty"` |
| 491 | } |
| 492 | |
| 493 | // Sent is the response to POST /api/v1/messages. |
| 494 | type Sent struct { |
| 495 | Message Message `json:"message"` |
| 496 | Turn Turn `json:"turn"` |
| 497 | } |
| 498 | |
| 499 | // MessagePage is GET /api/v1/messages, oldest first. Before is the cursor |
| 500 | // for the previous page, empty at the start of the conversation. |
| 501 | type MessagePage struct { |
| 502 | Items []Message `json:"items"` |
| 503 | Before string `json:"before"` |
| 504 | } |
| 505 | |
| 506 | // CancelAccepted is the 202 body of POST /api/v1/turns/{id}/cancel. |
| 507 | type CancelAccepted struct { |
| 508 | Attempt int64 `json:"attempt"` |
| 509 | } |
| 510 | |
| 511 | // Error is every non-2xx JSON body. It matches personapi.Error. |
| 512 | type Error struct { |
| 513 | Code string `json:"code"` |
| 514 | CopyKey string `json:"copy_key"` |
| 515 | RequestID string `json:"request_id"` |
| 516 | CurrentRevision *int64 `json:"current_revision,omitempty"` |
| 517 | } |
| 518 | |
| 519 | // Limits shared by both ends. |
| 520 | const ( |
| 521 | MaxMessageBytes = 16 << 10 |
| 522 | MaxFrameBytes = 256 << 10 |
| 523 | MaxTailMessages = 50 |
| 524 | PingInterval = 20 * time.Second |
| 525 | EventRetention = 24 * time.Hour |
| 526 | ) |
| 527 | |
| 528 | var ErrStrict = errors.New("wire: invalid document") |
| 529 | |
| 530 | // Strict decodes exactly one JSON value with no unknown fields. |
| 531 | func Strict(raw []byte, v any) error { |
| 532 | d := json.NewDecoder(bytes.NewReader(raw)) |
| 533 | d.DisallowUnknownFields() |
| 534 | if err := d.Decode(v); err != nil { |
| 535 | return err |
| 536 | } |
| 537 | if d.Decode(new(json.RawMessage)) != io.EOF { |
| 538 | return ErrStrict |
| 539 | } |
| 540 | return nil |
| 541 | } |
| 542 | |