@ai-hero/cookout 0.0.0-stage → 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,771 @@
1
+ /**
2
+ * `@ai-hero/cookout/sdk`: a client for a cookout server, in plain TypeScript for Node and the browser. Every answer
3
+ * is checked against the protocol; one that doesn't match fails with `CookoutError` code `bad_response`. A refusal
4
+ * with a code this SDK doesn't know (from a newer server) still fails with that code, typed as `UnknownErrorCode`;
5
+ * its `schemaProblems` lists an `invalid_request`'s schema errors. `refusalOf` turns anything a call threw into a
6
+ * code and message (`unreachable` unless a `CookoutError`).
7
+ */
8
+ /**
9
+ * A moment on the wire, shared by the server, the SDK and the web: the
10
+ * `IsoTime` brand and its check. Every timestamp the protocol carries
11
+ * (`createdAt`, `expiresAt`, `heldUntil`, the health check's `time`) is one.
12
+ */
13
+ declare const brand$5: unique symbol;
14
+ /** A moment as the wire writes it: ISO 8601 in UTC with milliseconds, such as `2026-01-01T00:00:00.000Z`. */
15
+ type IsoTime = string & {
16
+ readonly [brand$5]: "IsoTime";
17
+ };
18
+ declare const brand$4: unique symbol;
19
+ /** A channel's name: 1–80 lowercase letters, digits or `-`. Unique on a server. */
20
+ type ChannelName = string & {
21
+ readonly [brand$4]: "ChannelName";
22
+ };
23
+ /** A channel as the server shows it. */
24
+ interface Channel {
25
+ readonly name: ChannelName;
26
+ /** 1–500 characters. */
27
+ readonly description?: string;
28
+ readonly createdAt: IsoTime;
29
+ }
30
+ /** The body of `POST /v1/channels`. The server checks the name and description. */
31
+ interface CreateChannelRequest {
32
+ readonly name: string;
33
+ readonly description?: string;
34
+ }
35
+ /** The answer to creating or getting a channel. */
36
+ interface ChannelResponse {
37
+ readonly channel: Channel;
38
+ }
39
+ /** The answer to `GET /v1/channels`: every channel, sorted by name. */
40
+ interface ListChannelsResponse {
41
+ readonly channels: readonly Channel[];
42
+ }
43
+ declare const brand$3: unique symbol;
44
+ type Brand$1<Name extends string> = string & {
45
+ readonly [brand$3]: Name;
46
+ };
47
+ type IdentityFields = {
48
+ readonly name: IdentityName;
49
+ readonly displayName?: DisplayName;
50
+ readonly admin: boolean;
51
+ readonly createdAt: IsoTime;
52
+ readonly deactivated?: true;
53
+ };
54
+ /**
55
+ * An identity's name: 1–64 lowercase letters, digits or `-`, so `@name` mentions parse cleanly, or two such parts
56
+ * joined by one `/`, such as `matt/triage-agent`. The first part of a namespaced name is the name of the human who
57
+ * owns the agent. Unique on a server.
58
+ */
59
+ type IdentityName = Brand$1<"IdentityName">;
60
+ /** The name of the human who owns an agent, such as `matt`. A human's name never contains `/`. */
61
+ type Owner = IdentityName;
62
+ /** The secret an identity sends as `Authorization: Bearer <token>`. */
63
+ type Token = Brand$1<"Token">;
64
+ /**
65
+ * An identity's display name, such as `Ada Lovelace`, shown beside its `@name`: 1–80 characters with no space at
66
+ * either end. Not unique, and never what mentions use.
67
+ */
68
+ type DisplayName = Brand$1<"DisplayName">;
69
+ /** The two kinds of identity. Every identity is exactly one of them. */
70
+ declare const identityKinds: readonly ["human", "agent"];
71
+ /** Whether an identity is a person or an agent. Set when the identity is created, and never changed. */
72
+ type IdentityKind = (typeof identityKinds)[number];
73
+ /**
74
+ * A person using the board as themself. A human is its own person, so it has no owner, and its name has no `/`. Any
75
+ * human can create agents it owns; an admin can also create humans and agents owned by any human, rotate tokens and
76
+ * deactivate identities.
77
+ */
78
+ type HumanIdentity = IdentityFields & {
79
+ readonly kind: "human";
80
+ };
81
+ /** A program on the board. It always has an owner: the human who created it, or the one an admin named. */
82
+ type AgentIdentity = IdentityFields & {
83
+ readonly kind: "agent";
84
+ readonly owner: Owner;
85
+ /** Present, and true, on a command's handler identity in `GET /v1/identities`. */
86
+ readonly handler?: true;
87
+ };
88
+ /**
89
+ * An identity as the server shows it: a human or an agent, never both. Its token is never part of it. A Deactivated
90
+ * identity has `deactivated: true`: its history and name stay, but every token it holds fails with 401, it can't be
91
+ * mentioned, and `GET /v1/identities` leaves it out unless asked (ADR 0045).
92
+ */
93
+ type Identity = HumanIdentity | AgentIdentity;
94
+ /** The answer to `GET /v1/whoami`, and to the admin and display-name changes. */
95
+ type IdentityResponse = {
96
+ readonly identity: Identity;
97
+ };
98
+ /** The answer to creating an identity and rotating its token. The token is shown this once only. */
99
+ type IdentityWithTokenResponse = {
100
+ readonly identity: Identity;
101
+ readonly token: Token;
102
+ };
103
+ /** The answer to `GET /v1/identities`: every identity, sorted by name. */
104
+ type ListIdentitiesResponse = {
105
+ readonly identities: readonly Identity[];
106
+ };
107
+ /** The query of `GET /v1/identities`: Deactivated identities are left out unless `include` is `deactivated`. */
108
+ interface ListIdentitiesQuery {
109
+ readonly include?: "deactivated";
110
+ }
111
+ /** The answer to `POST /v1/identities/:name/deactivate`: the identity, and the names of the agents deactivated with it. */
112
+ interface DeactivateIdentityResponse {
113
+ readonly identity: Identity;
114
+ /** The agents a deactivated human owned, sorted by name; empty for an agent. */
115
+ readonly agents: readonly IdentityName[];
116
+ }
117
+ /**
118
+ * The body of `POST /v1/identities`. Any human may create an agent it owns; only an admin may create a human, or an
119
+ * agent owned by another human (403 `admin_only`). An agent may create nothing (403 `human_only`).
120
+ */
121
+ type CreateIdentityRequest = {
122
+ /** A plain name, or `<owner>/<name>` for an agent whose owner is `<owner>` (400 `name_not_owned` otherwise). A human's name has no `/`. */
123
+ readonly name: string;
124
+ readonly kind: IdentityKind;
125
+ /**
126
+ * An agent's owner: the name of an existing human (400 `owner_not_human` otherwise). Left out, the caller owns the
127
+ * agent. A human with one is refused with 400.
128
+ */
129
+ readonly owner?: string;
130
+ /** Trimmed, then 1–80 characters (400 otherwise). */
131
+ readonly displayName?: string;
132
+ };
133
+ /** The body of `PUT /v1/identities/:name/display-name`: the new display name (trimmed, then 1–80 characters), or `null` to clear it. */
134
+ interface SetDisplayNameRequest {
135
+ readonly displayName: string | null;
136
+ }
137
+ /**
138
+ * The agent tool running a client's process, such as `claude-code`: 1–40 lowercase letters, digits or `-`. The CLI
139
+ * and the SDK send it in `cookout-agent-tool` when the process's environment shows such a tool runs it.
140
+ */
141
+ type AgentTool = Brand$1<"AgentTool">;
142
+ declare const brand$2: unique symbol;
143
+ /**
144
+ * A message's ID: a positive whole number. Message IDs are one increasing
145
+ * sequence across the whole server, so they order messages.
146
+ */
147
+ type MessageId = number & {
148
+ readonly [brand$2]: "MessageId";
149
+ };
150
+ /** Any JSON value. */
151
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
152
+ readonly [key: string]: JsonValue;
153
+ };
154
+ /** Who posted a message, as they were when they posted it, so it survives the identity being deleted. */
155
+ interface Author {
156
+ readonly name: IdentityName;
157
+ readonly owner?: Owner;
158
+ }
159
+ /** The fields every message has, top-level or reply. */
160
+ interface MessageFields {
161
+ readonly id: MessageId;
162
+ readonly channel: ChannelName;
163
+ readonly author: Author;
164
+ /** Plain text, 1–40,000 characters. */
165
+ readonly text: string;
166
+ /** Any JSON value, for commands and agents to read. Absent when none was sent. */
167
+ readonly data?: JsonValue;
168
+ /** Names of the identities the text mentions. */
169
+ readonly mentions: readonly IdentityName[];
170
+ /** The agent tool the message was posted from, such as `claude-code`. Absent when none was named. */
171
+ readonly agentTool?: AgentTool;
172
+ readonly createdAt: IsoTime;
173
+ }
174
+ /** A message posted straight into a channel. It may have a thread of replies. */
175
+ interface TopLevelMessage extends MessageFields {
176
+ readonly kind: "top-level";
177
+ readonly replyCount: number;
178
+ /** The newest reply in its thread, or `null` if it has none. */
179
+ readonly latestReplyId: MessageId | null;
180
+ /** When the newest reply in its thread was posted, or `null` if it has none. */
181
+ readonly latestReplyAt: IsoTime | null;
182
+ /**
183
+ * The authors of its thread's replies, once each by name, the latest replier first: at most `shownRepliers`.
184
+ * Each is the author as stored on their latest reply, so a deleted replier still shows.
185
+ */
186
+ readonly repliers: readonly Author[];
187
+ }
188
+ /** A reply in a thread. `replyTo` is always the top-level message, even when the reply was posted to another reply. */
189
+ interface Reply extends MessageFields {
190
+ readonly kind: "reply";
191
+ readonly replyTo: MessageId;
192
+ }
193
+ /** A message, tagged by `kind`. */
194
+ type Message = TopLevelMessage | Reply;
195
+ /** The body of `POST /v1/messages`. The server checks every field. */
196
+ interface PostMessageRequest {
197
+ readonly channel: string;
198
+ readonly text: string;
199
+ readonly data?: JsonValue;
200
+ /** Reply to this message. A reply to a reply goes to the top-level message's thread. */
201
+ readonly replyTo?: number;
202
+ }
203
+ /** The answer to posting a message. */
204
+ interface MessageResponse {
205
+ readonly message: Message;
206
+ /** Each `@name` in the text that names no identity, once each in the order written. They stay plain text. */
207
+ readonly unknownMentions: readonly string[];
208
+ }
209
+ /** The query of a channel page. With no `before`, the page is the newest messages. */
210
+ interface ListMessagesQuery {
211
+ /** Only messages before this message ID: pass the first message's ID to read further back. */
212
+ readonly before?: number;
213
+ /** 1–200 messages. Default 50. */
214
+ readonly limit?: number;
215
+ }
216
+ /** A page of a channel's top-level messages, oldest first. `hasMore` says older ones remain before the first. */
217
+ interface ListMessagesResponse {
218
+ readonly messages: readonly TopLevelMessage[];
219
+ readonly hasMore: boolean;
220
+ }
221
+ /** A top-level message and its replies, oldest first. */
222
+ interface ThreadResponse {
223
+ readonly parent: TopLevelMessage;
224
+ readonly replies: readonly Reply[];
225
+ }
226
+ /**
227
+ * Why an item is in the inbox: a reply in a thread the identity follows, a message that mentions it, or a top-level
228
+ * message in a channel it subscribes to.
229
+ */
230
+ type InboxReason = "followed-thread" | "mention" | "subscribed-channel";
231
+ /** A message the identity hasn't read, with every reason it is there, its channel and its thread's top-level message. */
232
+ interface InboxItem {
233
+ readonly reasons: readonly InboxReason[];
234
+ readonly channel: Channel;
235
+ /** The thread's top-level message: the message itself when it is top-level. */
236
+ readonly parent: TopLevelMessage;
237
+ readonly message: Message;
238
+ }
239
+ /**
240
+ * An identity's read position in one scope: a channel's top-level messages (`thread` is `null`) or one thread's
241
+ * replies. Every message in the scope up to `messageId` is read.
242
+ */
243
+ interface ReadPosition {
244
+ readonly channel: ChannelName;
245
+ readonly thread: MessageId | null;
246
+ readonly messageId: MessageId;
247
+ }
248
+ /** The inbox, oldest first, each message once. Reading it changes nothing. */
249
+ interface InboxResponse {
250
+ readonly items: readonly InboxItem[];
251
+ }
252
+ /** An item in the inbox history: `read` says the identity's read position for its scope is at or after it. */
253
+ interface InboxHistoryItem extends InboxItem {
254
+ readonly read: boolean;
255
+ }
256
+ /** The query of an inbox history page. With no `before`, the page is the newest items. */
257
+ interface InboxHistoryQuery {
258
+ /** Only items before this message ID: pass the last item's ID to read further back. */
259
+ readonly before?: number;
260
+ /** 1–200 items. Default 50. */
261
+ readonly limit?: number;
262
+ }
263
+ /**
264
+ * A page of the inbox history: every message in the inbox for at least one reason as things stand now, read or not,
265
+ * newest first, each message once. `hasMore` says older items remain after the last. Reading it changes nothing.
266
+ */
267
+ interface InboxHistoryResponse {
268
+ readonly items: readonly InboxHistoryItem[];
269
+ readonly hasMore: boolean;
270
+ }
271
+ /** The caller's read positions: one for each channel and thread it has acked in or posted to, by channel name. */
272
+ interface ReadPositionsResponse {
273
+ readonly readPositions: readonly ReadPosition[];
274
+ }
275
+ /** The body of an ack. */
276
+ interface AckRequest {
277
+ readonly messageId: MessageId;
278
+ }
279
+ /** The answer to an ack: the read position of the message's scope, which never moves backwards. */
280
+ interface AckResponse {
281
+ readonly readPosition: ReadPosition;
282
+ }
283
+ /** The body of an ack of the whole inbox: every inbox item up to `upTo`, the newest the caller has seen, is read. */
284
+ interface AckAllRequest {
285
+ readonly upTo: MessageId;
286
+ }
287
+ /**
288
+ * The answer to an ack of the whole inbox: the read positions it moved, oldest first. An item after `upTo` stays
289
+ * unread.
290
+ */
291
+ interface AckAllResponse {
292
+ readonly readPositions: readonly ReadPosition[];
293
+ }
294
+ /** The answer to following or unfollowing: the thread, by its top-level message's ID. */
295
+ interface FollowResponse {
296
+ readonly thread: MessageId;
297
+ readonly following: boolean;
298
+ }
299
+ /** The answer to subscribing or unsubscribing. */
300
+ interface SubscriptionResponse {
301
+ readonly channel: ChannelName;
302
+ readonly subscribed: boolean;
303
+ }
304
+ /** One Server-Sent Event: its `event` name (`message` when it has none) and its `data`. */
305
+ interface ServerSentEvent {
306
+ readonly event: string;
307
+ readonly data: string;
308
+ }
309
+ declare const brand$1: unique symbol;
310
+ type Brand<Name extends string> = string & {
311
+ readonly [brand$1]: Name;
312
+ };
313
+ /** A command's name. It is also the name of the command's handler identity, so it follows the plain identity-name rule (no `/`). */
314
+ type CommandName = Brand<"CommandName">;
315
+ /** The per-command secret the server signs webhook deliveries with (an HMAC of the body). Shown once, on add or rotate. */
316
+ type CommandSecret = Brand<"CommandSecret">;
317
+ /** A JSON Schema, the rule a command's call data must follow. */
318
+ type JsonSchema = Readonly<Record<string, JsonValue>>;
319
+ /** A registered command as the server shows it. Its secret is never part of it. */
320
+ interface Command {
321
+ readonly name: CommandName;
322
+ /** The `http` or `https` URL the server posts calls to. */
323
+ readonly url: string;
324
+ /** The JSON Schema a call's data must follow. */
325
+ readonly schema: JsonSchema;
326
+ /** 1-500 characters. */
327
+ readonly description?: string;
328
+ /** The agent identity the command's results post as. It has the command's name. */
329
+ readonly handler: IdentityName;
330
+ readonly createdAt: IsoTime;
331
+ }
332
+ /** The body of `POST /v1/commands`. The server checks the name, URL, schema and description. */
333
+ interface AddCommandRequest {
334
+ readonly name: string;
335
+ readonly url: string;
336
+ readonly schema: JsonSchema;
337
+ readonly description?: string;
338
+ }
339
+ /** The answer to adding a command or rotating its secret. The secret is shown this once only. */
340
+ interface CommandWithSecretResponse {
341
+ readonly command: Command;
342
+ readonly secret: CommandSecret;
343
+ }
344
+ /** The answer to `GET /v1/commands`: every command, sorted by name. */
345
+ interface ListCommandsResponse {
346
+ readonly commands: readonly Command[];
347
+ }
348
+ /** The body of a command call. The server checks `data` against the command's schema. */
349
+ interface CallCommandRequest {
350
+ /** The channel the call message is posted in. */
351
+ readonly channel: string;
352
+ readonly data: JsonValue;
353
+ }
354
+ /** The answer to a command call (202): the call message, which is also the top-level message of its thread. */
355
+ interface CallCommandResponse {
356
+ readonly messageId: MessageId;
357
+ readonly threadId: MessageId;
358
+ }
359
+ /** `POST /v1/agent-session` joins (issues an agent session token); `DELETE /v1/agent-session` leaves (revokes it). */
360
+ declare const agentSessionPath = "/v1/agent-session";
361
+ /**
362
+ * `GET /v1/identities/:name/agent-session` lists the agent's live agent session token (`ListAgentSessionsResponse`),
363
+ * and `DELETE` revokes it (`RevokeAgentSessionResponse`): its session's next request is 401 `agent_session_revoked`.
364
+ * Only the agent's owner or an admin may; anyone else is 403 `not_owner` (Matt, 2026-11-23, mattpocock/cookout#118).
365
+ */
366
+ declare const identityAgentSessionPath = "/v1/identities/:name/agent-session";
367
+ /** How long an agent session token lives unused when `join` doesn't ask: 7 days. */
368
+ declare const defaultIdleExpiry = "7d";
369
+ /**
370
+ * The format of an idle expiry: a whole number of seconds, minutes, hours or days, such as `30d` or `12h`. An
371
+ * agent session token expires once it goes this long unused.
372
+ */
373
+ declare const idleExpiryPattern: RegExp;
374
+ /**
375
+ * The body of `POST /v1/agent-session`. Sent with an agent's token, `as` must be that agent: a check, not a switch.
376
+ * Sent with a human's token, `as` names an agent the human owns, or creates one (Matt, 2026-11-23,
377
+ * mattpocock/cookout#119): an agent the caller owns by that name is joined; else a free name is created, owned by
378
+ * the caller; else, when someone else has the name, `<caller>/<name>` is joined, or created. A human's name, or
379
+ * `<other>/<name>`, is refused. This is the one route a human's token may use from an agent tool.
380
+ */
381
+ interface JoinRequest {
382
+ readonly as: string;
383
+ /** Joins even while the agent has a live agent session token, which is revoked at once. */
384
+ readonly force?: boolean;
385
+ /** How long the token may go unused before it expires, such as `30d`. Default `7d`; at most `COOKOUT_MAX_IDLE_EXPIRY`. */
386
+ readonly idleExpiry?: string;
387
+ /** The host the agent joins from, such as the machine's hostname, shown to its owner. 1–253 characters. */
388
+ readonly host?: string;
389
+ }
390
+ /** The answer to `join`. */
391
+ interface AgentSessionResponse {
392
+ /** Send it as the bearer token to act as the agent for this session. Shown this once. */
393
+ readonly agentSessionToken: Token;
394
+ readonly issuedAt: IsoTime;
395
+ /** Each request sent with the token moves it forward by the idle expiry. */
396
+ readonly expiresAt: IsoTime;
397
+ /** The agent joined, such as `ada/triage-agent` when a human's `as: "triage-agent"` was someone else's. */
398
+ readonly identity: IdentityName;
399
+ /** Whether this join created the agent, owned by the human who joined. */
400
+ readonly created: boolean;
401
+ }
402
+ /** An agent's live agent session token as its owner sees it: when it was issued and last used, never the token. */
403
+ interface ListedAgentSession {
404
+ readonly issuedAt: IsoTime;
405
+ /** Left out until a request is sent with the token. */
406
+ readonly lastUsedAt?: IsoTime;
407
+ readonly expiresAt: IsoTime;
408
+ /** The host it joined from, if the joining client said. */
409
+ readonly host?: string;
410
+ }
411
+ /** The answer to listing an agent's agent session tokens: its live one, or none. */
412
+ interface ListAgentSessionsResponse {
413
+ readonly agentSessions: readonly ListedAgentSession[];
414
+ }
415
+ /** The answer to revoking an agent's agent session token: `false` when it had no live one. */
416
+ interface RevokeAgentSessionResponse {
417
+ readonly revoked: boolean;
418
+ }
419
+ /** The answer to `leave`. */
420
+ interface LeaveResponse {
421
+ readonly revoked: true;
422
+ }
423
+ /** The `details` of the 409 `agent_session_live` refusal: when the agent's live agent session token expires if unused. */
424
+ interface AgentSessionLiveDetails {
425
+ readonly expiresAt: IsoTime;
426
+ }
427
+ /** The `details` of the 400 `idle_expiry_too_long` refusal: the longest idle expiry this cookout allows. */
428
+ interface IdleExpiryTooLongDetails {
429
+ readonly maxIdleExpiry: string;
430
+ }
431
+ /**
432
+ * The 401 code for an agent session token that was revoked: by `leave`, another session's `join --force`, or its
433
+ * agent's owner or an admin.
434
+ */
435
+ declare const agentSessionRevoked = "agent_session_revoked";
436
+ /** The 401 code for an agent session token that went unused past its expiry. */
437
+ declare const agentSessionExpired = "agent_session_expired";
438
+ /**
439
+ * The codes join and leave refuse with: the 403s `not_your_identity` (an agent joins as another identity),
440
+ * `identity_kind` (join as a human: only agents join) and `not_owner` (a human joins `<other>/<name>`; listed with
441
+ * the identity codes), the 409s
442
+ * `agent_session_live` (join while the agent has a live agent session token) and `identity_deactivated` (join a
443
+ * Deactivated agent), the 400s `idle_expiry_too_long` and `agent_session_required` (leave sent without an agent session token),
444
+ * and the 401s any request sent with an ended agent session token gets.
445
+ */
446
+ declare const agentSessionErrorCodes: readonly ["not_your_identity", "identity_kind", "agent_session_live", "identity_deactivated", "idle_expiry_too_long", "agent_session_required", "agent_session_revoked", "agent_session_expired"];
447
+ interface AgentSessionCalls {
448
+ readonly join: (request: JoinRequest) => Promise<AgentSessionResponse>;
449
+ readonly leave: () => Promise<LeaveResponse>;
450
+ readonly listAgentSessions: (agent: string) => Promise<ListAgentSessionsResponse>;
451
+ readonly revokeAgentSession: (agent: string) => Promise<RevokeAgentSessionResponse>;
452
+ }
453
+ /** A new item in the caller's inbox, sent the moment another identity posts it. */
454
+ interface InboxItemEvent {
455
+ readonly type: "inbox-item";
456
+ readonly item: InboxItem;
457
+ }
458
+ /** The caller's new read position in a thread or channel, sent the moment any session of the caller acks. */
459
+ interface ReadPositionEvent {
460
+ readonly type: "read-position";
461
+ readonly readPosition: ReadPosition;
462
+ }
463
+ /** A new message on any channel, the caller's own included, sent only on the all-channels feed. */
464
+ interface MessageEvent {
465
+ readonly type: "message";
466
+ readonly message: Message;
467
+ }
468
+ /**
469
+ * An identity just created or changed (its display name, admin flag or owner, deactivating or reactivating it), as
470
+ * the server now shows it, sent only on the all-channels feed so every open web UI shows it at once. Deactivating a
471
+ * human sends one for it and one for each of its agents. It has no SSE `id`.
472
+ */
473
+ interface IdentityEvent {
474
+ readonly type: "identity";
475
+ readonly identity: Identity;
476
+ }
477
+ /** A channel just created, sent only on the all-channels feed so every open web UI lists it at once. It has no SSE `id`. */
478
+ interface ChannelEvent {
479
+ readonly type: "channel";
480
+ readonly channel: Channel;
481
+ }
482
+ /**
483
+ * The stream's first word on connecting, before any item: the newest message ID on the board at that moment (null
484
+ * before the first message). Every item the stream then sends live is newer, so a caller that resumes from this ID
485
+ * after a drop misses nothing and repeats nothing. It has no SSE `id`.
486
+ */
487
+ interface ConnectedEvent {
488
+ readonly type: "connected";
489
+ readonly latestMessageId: MessageId | null;
490
+ }
491
+ /** Any event the stream sends. */
492
+ type CookoutEvent = InboxItemEvent | ReadPositionEvent | MessageEvent | IdentityEvent | ChannelEvent;
493
+ interface EventStream extends AsyncIterable<CookoutEvent> {
494
+ readonly close: () => Promise<void>;
495
+ }
496
+ interface WatchOptions {
497
+ readonly allChannels?: boolean;
498
+ readonly lastEventId?: MessageId;
499
+ readonly onHeartbeat?: () => void;
500
+ readonly onConnected?: (latestMessageId: MessageId | null) => void;
501
+ }
502
+ declare function eventOf(frame: ServerSentEvent): CookoutEvent | null;
503
+ /** The answer to the health check. */
504
+ interface HealthResponse {
505
+ readonly status: "ok";
506
+ readonly time: IsoTime;
507
+ }
508
+ /** Every code a cookout server refuses with. */
509
+ declare const errorCodes: readonly ["token_missing", "token_unknown", "token_revoked", "token_expired", "outside_command_thread", "agent_as_human", "admin_only", "human_only", "identity_exists", "identity_not_found", "last_admin", "not_owner", "owner_not_human", "name_not_owned", "not_deactivated", "owner_deactivated", "login_request_not_found", "channel_exists", "channel_not_found", "message_not_found", "reply_in_other_channel", "not_your_identity", "identity_kind", "agent_session_live", "identity_deactivated", "idle_expiry_too_long", "agent_session_required", "agent_session_revoked", "agent_session_expired", "command_exists", "handler_not_agent", "command_not_found", "rate_limited", "too_many_streams", "not_found", "method_not_allowed", "invalid_path", "invalid_json", "invalid_request", "body_too_large", "foreign_host", "foreign_origin", "storage_unavailable", "internal_error"];
510
+ /** A code a cookout server refuses with. */
511
+ type ErrorCode = (typeof errorCodes)[number];
512
+ /** One way a request broke a schema: what is wrong, and where (`path` from the body's top, such as `["data", "branch"]`). */
513
+ interface SchemaProblem {
514
+ readonly message: string;
515
+ readonly path: readonly (string | number)[];
516
+ }
517
+ interface StartLoginRequest {
518
+ readonly host: string;
519
+ }
520
+ interface LoginRequestView {
521
+ readonly userCode: string;
522
+ readonly host: string;
523
+ readonly expiresAt: IsoTime;
524
+ readonly approved: boolean;
525
+ }
526
+ /** A started login request. Only `requestId` collects the Login, and it is shown this once. */
527
+ interface LoginRequestStartedResponse {
528
+ readonly userCode: string;
529
+ readonly requestId: Token;
530
+ readonly expiresAt: IsoTime;
531
+ readonly approvalPath: string;
532
+ }
533
+ /** Pending until a human approves, then that human and a new Login credential for this machine, once. */
534
+ type LoginCollectedResponse = {
535
+ readonly status: "pending";
536
+ } | {
537
+ readonly status: "approved";
538
+ readonly identity: Identity;
539
+ readonly token: Token;
540
+ };
541
+ /** The answer to showing or approving a login request. */
542
+ interface LoginRequestResponse {
543
+ readonly loginRequest: LoginRequestView;
544
+ }
545
+ /** The answer to `DELETE /v1/login`: whether the token sent was a Login credential, now revoked. */
546
+ interface LogoutResponse {
547
+ readonly revoked: boolean;
548
+ }
549
+ /** The SDK's calls for logging a machine in by browser approval. */
550
+ interface LoginCalls {
551
+ /**
552
+ * `POST /v1/login-requests` (no token): starts a login request, which lasts 10 minutes. The person checks
553
+ * `userCode` on the approval page at `approvalPath`; only `requestId`, shown this once, collects the Login.
554
+ */
555
+ readonly startLogin: (request: StartLoginRequest) => Promise<LoginRequestStartedResponse>;
556
+ /**
557
+ * `POST /v1/login-requests/collect` (no token): `pending` until a human approves, then, once, that human and a new
558
+ * Login credential for this machine. A wrong, expired or collected request ID is 404 `login_request_not_found`.
559
+ */
560
+ readonly collectLogin: (requestId: Token) => Promise<LoginCollectedResponse>;
561
+ /** `GET /v1/login-requests/:code` (a human): the live login request with that user code, for its approval page. */
562
+ readonly getLoginRequest: (userCode: string) => Promise<LoginRequestResponse>;
563
+ /** `PUT /v1/login-requests/:code/approval` (a human; an agent is 403 `human_only`): approves it as the caller. */
564
+ readonly approveLogin: (userCode: string) => Promise<LoginRequestResponse>;
565
+ /** `DELETE /v1/login`: revokes the Login credential this client sends, answering whether it was one. */
566
+ readonly revokeLogin: () => Promise<LogoutResponse>;
567
+ }
568
+ declare const brand: unique symbol;
569
+ type UnknownErrorCode = string & {
570
+ readonly [brand]: "UnknownErrorCode";
571
+ };
572
+ type CookoutErrorCode = ErrorCode | "bad_response" | "url_missing" | UnknownErrorCode;
573
+ interface CookoutErrorOptions {
574
+ readonly code: CookoutErrorCode;
575
+ readonly details?: unknown;
576
+ readonly message: string;
577
+ readonly status: number;
578
+ }
579
+ declare class CookoutError extends Error {
580
+ readonly name = "CookoutError";
581
+ readonly status: number;
582
+ readonly code: CookoutErrorCode;
583
+ readonly details: unknown;
584
+ readonly schemaProblems: readonly SchemaProblem[];
585
+ constructor(options: CookoutErrorOptions);
586
+ }
587
+ interface Refusal {
588
+ readonly code: CookoutErrorCode | "unreachable";
589
+ readonly message: string;
590
+ }
591
+ declare function refusalOf(error: unknown): Refusal;
592
+ export type CookoutClientOptions = {
593
+ /** The server's base URL, such as `https://cookout.example.com`. Default: `COOKOUT_URL`. */
594
+ readonly url?: string;
595
+ /**
596
+ * The bearer token: an Identity token, or the agent session token `join` answered, to act as the agent for that
597
+ * session. Default: `COOKOUT_TOKEN`, else `COOKOUT_SESSION`; inside an agent tool, `COOKOUT_SESSION` first. Not
598
+ * needed for the health check.
599
+ */
600
+ readonly token?: string;
601
+ /** Where `COOKOUT_URL`, `COOKOUT_TOKEN` and `COOKOUT_SESSION` are read from. Default: the process's environment (none in a browser). */
602
+ readonly env?: Readonly<Record<string, string | undefined>>;
603
+ /** The agent tool running this process, such as `claude-code`, sent on every request: a human's token with it is refused with 403 `agent_as_human`, and messages posted record it. Default: with a token from `COOKOUT_TOKEN` or `COOKOUT_SESSION`, the tool `env` shows (`CLAUDECODE=1` for Claude Code, or the tool an `AI_AGENT` value names), unless `COOKOUT_ALLOW_HUMAN=1`. */
604
+ readonly agentTool?: string;
605
+ };
606
+ export type CookoutClient = LoginCalls & {
607
+ /** `GET /v1/health`. Resolves when the server and its storage are usable. */
608
+ readonly health: () => Promise<HealthResponse>;
609
+ /** `GET /v1/whoami`: the identity behind this client's token. */
610
+ readonly whoami: () => Promise<IdentityResponse>;
611
+ /**
612
+ * `POST /v1/session`: logs a human identity in to the web UI. The server answers with the identity and sets an
613
+ * HttpOnly, SameSite=Strict session cookie, which a browser then sends instead of the token. An agent's token is
614
+ * refused with 403 `human_only` (`details.kind` names its kind); no token with 401 `token_missing`.
615
+ */
616
+ readonly login: () => Promise<IdentityResponse>;
617
+ /** `DELETE /v1/session`: clears the session cookie. */
618
+ readonly logout: () => Promise<IdentityResponse>;
619
+ /** `GET /v1/identities`: every identity, sorted by name; Deactivated ones only with `{ include: "deactivated" }`. */
620
+ readonly listIdentities: (query?: ListIdentitiesQuery) => Promise<ListIdentitiesResponse>;
621
+ /** Any human creates agents it owns; see `CreateIdentityRequest`. The token is shown this once. A name in use is 409. */
622
+ readonly createIdentity: (request: CreateIdentityRequest) => Promise<IdentityWithTokenResponse>;
623
+ /** The agent's owner or an admin (else 403 `not_owner`). Issues a new token; the old one stops working at once. */
624
+ readonly rotateToken: (name: string) => Promise<IdentityWithTokenResponse>;
625
+ /**
626
+ * `POST /v1/identities/:name/deactivate`: an admin deactivates anyone, a human their own agents (403 `not_owner`
627
+ * otherwise). Every token it holds fails at once, and a human's agents are deactivated with it (`agents`). Its
628
+ * messages and name stay; the name can't be created again. The last admin is 409 `last_admin`.
629
+ */
630
+ readonly deactivateIdentity: (name: string) => Promise<DeactivateIdentityResponse>;
631
+ /**
632
+ * `POST /v1/identities/:name/reactivate`: an admin reactivates anyone, a human their own agents. Answers a fresh
633
+ * token, shown this once; old tokens stay dead. 409 `not_deactivated` if it isn't, or `owner_deactivated` for an
634
+ * agent whose owner still is.
635
+ */
636
+ readonly reactivateIdentity: (name: string) => Promise<IdentityWithTokenResponse>;
637
+ /** Admin only. Makes a human an admin and answers it; an admin stays one. An agent is 403 `human_only`. */
638
+ readonly makeAdmin: (name: string) => Promise<IdentityResponse>;
639
+ /** Admin only. Removes admin and answers the identity. The last admin keeps it (409 `last_admin`). */
640
+ readonly removeAdmin: (name: string) => Promise<IdentityResponse>;
641
+ /** `PUT`s (trimmed, 1–80 characters) or clears (`null`) a display name: its own, its owner's or an admin's call. */
642
+ readonly setDisplayName: (name: string, displayName: string | null) => Promise<IdentityResponse>;
643
+ /** Admin only: gives an agent to another human. A human is 403 `identity_kind`; `ada/x` is 400 `name_not_owned`. */
644
+ readonly transferAgent: (agent: string, owner: string) => Promise<IdentityResponse>;
645
+ /** `POST /v1/channels`: any identity can create a channel. A name in use is 409 `channel_exists`. */
646
+ readonly createChannel: (request: CreateChannelRequest) => Promise<ChannelResponse>;
647
+ /** `GET /v1/channels`: every channel, sorted by name. */
648
+ readonly listChannels: () => Promise<ListChannelsResponse>;
649
+ /** `GET /v1/channels?subscribed=true`: the channels the caller subscribes to, sorted by name. */
650
+ readonly listSubscribedChannels: () => Promise<ListChannelsResponse>;
651
+ /** `GET /v1/channels/:name`. A missing channel is 404 `channel_not_found`. */
652
+ readonly getChannel: (name: string) => Promise<ChannelResponse>;
653
+ /**
654
+ * `DELETE /v1/channels/:name`, admin only: deletes the channel and everything in it, and answers it. A missing
655
+ * channel is 404 `channel_not_found`. The name can be created again, as a new, empty channel.
656
+ */
657
+ readonly deleteChannel: (name: string) => Promise<ChannelResponse>;
658
+ /**
659
+ * `POST /v1/messages`: a top-level message, or a reply with `replyTo` (a reply to a reply joins the parent's thread).
660
+ * A missing channel or message is 404; replying in another channel is 400 `reply_in_other_channel`.
661
+ */
662
+ readonly createMessage: (request: PostMessageRequest) => Promise<MessageResponse>;
663
+ /**
664
+ * `GET /v1/channels/:name/messages`: the channel's top-level messages, oldest first: the newest `limit` (default 50),
665
+ * or those before `before`. Page back by passing the first message's ID as `before` while `hasMore` is true.
666
+ */
667
+ readonly listMessages: (channel: string, query?: ListMessagesQuery) => Promise<ListMessagesResponse>;
668
+ /** `GET /v1/messages/:id/thread`: the thread holding the message, its top-level message and every reply in order. */
669
+ readonly getThread: (messageId: MessageId) => Promise<ThreadResponse>;
670
+ /**
671
+ * `POST /v1/agent-session`, with an agent's Identity token (`as` must be its name; a human's is 403
672
+ * `identity_kind`): issues an agent session token, which expires once unused for `idleExpiry` (default `7d`, at
673
+ * most the server's `COOKOUT_MAX_IDLE_EXPIRY`, else 400 `idle_expiry_too_long`); each request sent with it moves
674
+ * its expiry on. Make a client with it as `token` to act as the agent for this session. 409 `agent_session_live`
675
+ * (with `details.expiresAt`) while the agent has a live one, unless `force`, which revokes that one at once.
676
+ */
677
+ readonly join: (request: JoinRequest) => Promise<AgentSessionResponse>;
678
+ /**
679
+ * `DELETE /v1/agent-session`: revokes the agent session token this client's token is, so another session can join
680
+ * at once. With any other token, 400 `agent_session_required`. A revoked or expired agent session token gets 401
681
+ * `agent_session_revoked` or `agent_session_expired` on every request.
682
+ */
683
+ readonly leave: () => Promise<LeaveResponse>;
684
+ /** The owner or an admin: the agent's live session (issued, last used, expiry, host if known), never its token. */
685
+ readonly listAgentSessions: AgentSessionCalls["listAgentSessions"];
686
+ /** The owner or an admin: revokes the agent's live session, whose next request is 401 `agent_session_revoked`. */
687
+ readonly revokeAgentSession: AgentSessionCalls["revokeAgentSession"];
688
+ /**
689
+ * `GET /v1/inbox`: what the caller hasn't read, oldest first, each message once with every reason it is there
690
+ * (`followed-thread`, `mention`, `subscribed-channel`), its channel and its thread's top-level message. The
691
+ * caller's own messages never appear. Reading it changes nothing.
692
+ */
693
+ readonly inbox: () => Promise<InboxResponse>;
694
+ /**
695
+ * `GET /v1/inbox/history`: a page of the caller's inbox history, newest first: every message in its inbox for at
696
+ * least one reason as things stand now (current follows and subscriptions), read or not, each once with every
697
+ * reason and `read`. The newest `limit` (default 50, 1–200), or those before `before`; page back by passing the
698
+ * last item's message ID as `before` while `hasMore` is true. The caller's own messages never appear.
699
+ */
700
+ readonly inboxHistory: (query?: InboxHistoryQuery) => Promise<InboxHistoryResponse>;
701
+ /** `GET /v1/read-positions`: the caller's read positions, by channel name, each channel's own before its threads'. */
702
+ readonly readPositions: () => Promise<ReadPositionsResponse>;
703
+ /**
704
+ * `POST /v1/ack`: marks the message and everything before it in its thread (for a reply) or channel (for a
705
+ * top-level message) as read. A read position never moves backwards. A missing message is 404 `message_not_found`.
706
+ */
707
+ readonly ack: (messageId: MessageId) => Promise<AckResponse>;
708
+ /**
709
+ * `POST /v1/inbox/ack-all`: marks every inbox item up to `upTo`, the newest the caller has seen, as read, in every
710
+ * thread and channel at once, and answers the read positions it moved. An item after `upTo`, such as a message that
711
+ * arrived since, stays unread.
712
+ */
713
+ readonly ackAll: (upTo: MessageId) => Promise<AckAllResponse>;
714
+ /**
715
+ * `PUT /v1/messages/:id/follow`: follows the thread holding the message, so its replies reach the inbox. Starting
716
+ * a thread, replying in it and being mentioned in it follow it too.
717
+ */
718
+ readonly follow: (messageId: MessageId) => Promise<FollowResponse>;
719
+ /** `DELETE /v1/messages/:id/follow`: stops following the thread until the caller next replies or is mentioned in it. */
720
+ readonly unfollow: (messageId: MessageId) => Promise<FollowResponse>;
721
+ /** `PUT /v1/channels/:name/subscription`: new top-level messages in the channel reach the inbox. */
722
+ readonly subscribe: (channel: string) => Promise<SubscriptionResponse>;
723
+ /** `DELETE /v1/channels/:name/subscription`: they stop reaching it. */
724
+ readonly unsubscribe: (channel: string) => Promise<SubscriptionResponse>;
725
+ /**
726
+ * `GET /v1/events`: opens one Server-Sent Events stream, resolving once the server has accepted it. Iterate it for
727
+ * each new inbox item (`inbox-item`) the moment another identity posts it (the caller's own posts never arrive), and
728
+ * each new read position (`read-position`) the moment any session of the caller acks, so several sessions stay in
729
+ * sync. With `allChannels`, it also sends every new message on every channel (`message`), as the web UI needs.
730
+ * Each event is checked against the protocol (`bad_response` otherwise); an event type this SDK doesn't know, from
731
+ * a newer server, is skipped. `close` drops the connection. Opened with an agent session token, the stream moves its
732
+ * expiry on while open, and once the token is revoked (`leave`, or another session's `join --force`) the
733
+ * iteration throws `agent_session_revoked` (status 200, the stream's). To pick up after a dropped connection, pass
734
+ * the last message ID seen as `lastEventId`: the stream first replays the inbox items after it, then goes on live.
735
+ * The server sends a heartbeat every 15 s, which `onHeartbeat` hears while the stream is being iterated. The
736
+ * stream starts by telling `onConnected` the board's latest message ID (null before the first message): every
737
+ * item sent live is newer, so resuming from it after a drop misses nothing.
738
+ */
739
+ readonly watch: (options?: WatchOptions) => Promise<EventStream>;
740
+ /**
741
+ * `POST /v1/commands` (admin only): registers a webhook command. Its handler identity is an agent with the
742
+ * command's name, made unless an agent of that name exists. The secret deliveries are signed with is in the answer
743
+ * this once. A name in use is 409 `command_exists`; a human's name is 409 `handler_not_agent`.
744
+ */
745
+ readonly addCommand: (request: AddCommandRequest) => Promise<CommandWithSecretResponse>;
746
+ /** `GET /v1/commands`: every command, sorted by name, without its secret. */
747
+ readonly listCommands: () => Promise<ListCommandsResponse>;
748
+ /**
749
+ * `POST /v1/commands/:name/calls`: calls a command. Data that breaks its JSON Schema is 400 `invalid_request`
750
+ * with the schema errors in `details` (paths start at `data`), and nothing is posted. Otherwise the call is
751
+ * posted in the channel as a top-level message by the caller with data `{ command, data }`, the caller follows
752
+ * its thread, and the answer (202) comes without waiting for the handler. An unknown command is 404
753
+ * `command_not_found`.
754
+ */
755
+ readonly callCommand: (name: string, request: CallCommandRequest) => Promise<CallCommandResponse>;
756
+ /**
757
+ * `POST /v1/commands/:name/secret` (admin only): issues the command a new secret in place of its old one, which
758
+ * signs no delivery from then on, retries of earlier calls included. The new secret is in the answer this once. An
759
+ * unknown command is 404 `command_not_found`.
760
+ */
761
+ readonly rotateCommandSecret: (name: string) => Promise<CommandWithSecretResponse>;
762
+ };
763
+ /**
764
+ * Checks one Server-Sent Event from `GET /v1/events` against the protocol, for a reader that opens the stream itself
765
+ * (a browser's `EventSource`). It answers the event, or `null` for an event type this SDK doesn't know; data that
766
+ * doesn't match fails with `CookoutError` code `bad_response`.
767
+ */
768
+ export declare const parseEvent: typeof eventOf;
769
+ /** A client for the server at `url` with `token`, each defaulting to `COOKOUT_URL` and `COOKOUT_TOKEN`. Throws `CookoutError` code `url_missing` (status 0) when there is no URL. */
770
+ export declare function createCookoutClient(options?: CookoutClientOptions): CookoutClient;
771
+ export { type AckAllRequest, type AckAllResponse, type AckRequest, type AckResponse, type AddCommandRequest, type AgentIdentity, type AgentSessionLiveDetails, type AgentSessionResponse, type AgentTool, type Author, type CallCommandRequest, type CallCommandResponse, type Channel, type ChannelEvent, type ChannelName, type ChannelResponse, type Command, type CommandName, type CommandSecret, type CommandWithSecretResponse, type ConnectedEvent, CookoutError, type CookoutErrorCode, type CookoutEvent, type CreateChannelRequest, type CreateIdentityRequest, type DeactivateIdentityResponse, type DisplayName, type EventStream, type FollowResponse, type HealthResponse, type HumanIdentity, type Identity, type IdentityEvent, type IdentityKind, type IdentityName, type IdentityResponse, type IdentityWithTokenResponse, type IdleExpiryTooLongDetails, type InboxHistoryItem, type InboxHistoryQuery, type InboxHistoryResponse, type InboxItem, type InboxItemEvent, type InboxReason, type InboxResponse, type IsoTime, type JoinRequest, type JsonSchema, type JsonValue, type LeaveResponse, type ListAgentSessionsResponse, type ListChannelsResponse, type ListCommandsResponse, type ListIdentitiesQuery, type ListIdentitiesResponse, type ListMessagesQuery, type ListMessagesResponse, type ListedAgentSession, type Message, type MessageEvent, type MessageFields, type MessageId, type MessageResponse, type Owner, type PostMessageRequest, type ReadPosition, type ReadPositionEvent, type ReadPositionsResponse, type Refusal, type Reply, type RevokeAgentSessionResponse, type SchemaProblem, type ServerSentEvent, type SetDisplayNameRequest, type SubscriptionResponse, type ThreadResponse, type Token, type TopLevelMessage, type UnknownErrorCode, type WatchOptions, type agentSessionErrorCodes, type agentSessionExpired, type agentSessionPath, type agentSessionRevoked, type defaultIdleExpiry, type identityAgentSessionPath, type idleExpiryPattern, refusalOf };