@zvada/agent-server 0.3.26 → 0.3.27

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.
Files changed (124) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -1
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/claude-code/approvals.js +1 -1
  6. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  7. package/dist/core/agents/scripted/scripted-agent.js +30 -3
  8. package/dist/core/presets.js +4 -1
  9. package/dist/core/runtime/agent-runtime.js +15 -5
  10. package/dist/core/runtime/event-processor.js +13 -8
  11. package/dist/core/runtime/origin-line.js +42 -0
  12. package/dist/core/runtime/request-broker.js +2 -1
  13. package/dist/core/runtime/steering.js +4 -3
  14. package/dist/core/runtime/turn.js +6 -4
  15. package/dist/operator/errors.js +97 -0
  16. package/dist/operator/index.js +10 -5
  17. package/dist/operator/mcp.js +7 -12
  18. package/dist/operator/operator.js +1336 -380
  19. package/dist/operator/refs.js +59 -0
  20. package/dist/operator/render.js +171 -74
  21. package/dist/operator/session-tools.js +87 -0
  22. package/dist/operator/types.js +30 -0
  23. package/dist/operator/view.js +82 -27
  24. package/dist/protocol/config.js +12 -5
  25. package/dist/protocol/conversation.js +3 -0
  26. package/dist/protocol/history.js +2 -1
  27. package/dist/protocol/index.js +1 -0
  28. package/dist/protocol/lifecycle.js +19 -0
  29. package/dist/protocol/origin.js +39 -0
  30. package/dist/protocol/reduce.js +2 -0
  31. package/dist/protocol/wire.js +17 -0
  32. package/dist/server/routes.js +15 -5
  33. package/dist/types/client/client.d.ts.map +1 -1
  34. package/dist/types/client/connection.d.ts +14 -2
  35. package/dist/types/client/connection.d.ts.map +1 -1
  36. package/dist/types/client/turns.d.ts +2 -2
  37. package/dist/types/client/turns.d.ts.map +1 -1
  38. package/dist/types/core/agents/base.d.ts +2 -0
  39. package/dist/types/core/agents/base.d.ts.map +1 -1
  40. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  41. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  42. package/dist/types/core/presets.d.ts.map +1 -1
  43. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  44. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  45. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  46. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  47. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  48. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  49. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  50. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  51. package/dist/types/core/runtime/steering.d.ts +7 -4
  52. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  53. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  54. package/dist/types/operator/errors.d.ts +83 -0
  55. package/dist/types/operator/errors.d.ts.map +1 -0
  56. package/dist/types/operator/index.d.ts +10 -5
  57. package/dist/types/operator/index.d.ts.map +1 -1
  58. package/dist/types/operator/mcp.d.ts +1 -1
  59. package/dist/types/operator/mcp.d.ts.map +1 -1
  60. package/dist/types/operator/operator.d.ts +15 -197
  61. package/dist/types/operator/operator.d.ts.map +1 -1
  62. package/dist/types/operator/refs.d.ts +25 -0
  63. package/dist/types/operator/refs.d.ts.map +1 -0
  64. package/dist/types/operator/render.d.ts +59 -19
  65. package/dist/types/operator/render.d.ts.map +1 -1
  66. package/dist/types/operator/session-tools.d.ts +61 -0
  67. package/dist/types/operator/session-tools.d.ts.map +1 -0
  68. package/dist/types/operator/types.d.ts +441 -0
  69. package/dist/types/operator/types.d.ts.map +1 -0
  70. package/dist/types/operator/view.d.ts +19 -29
  71. package/dist/types/operator/view.d.ts.map +1 -1
  72. package/dist/types/protocol/config.d.ts +20 -5
  73. package/dist/types/protocol/config.d.ts.map +1 -1
  74. package/dist/types/protocol/conversation.d.ts +44 -3
  75. package/dist/types/protocol/conversation.d.ts.map +1 -1
  76. package/dist/types/protocol/history.d.ts +1 -1
  77. package/dist/types/protocol/history.d.ts.map +1 -1
  78. package/dist/types/protocol/index.d.ts +1 -0
  79. package/dist/types/protocol/index.d.ts.map +1 -1
  80. package/dist/types/protocol/lifecycle.d.ts +40 -2
  81. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  82. package/dist/types/protocol/origin.d.ts +49 -0
  83. package/dist/types/protocol/origin.d.ts.map +1 -0
  84. package/dist/types/protocol/reduce.d.ts.map +1 -1
  85. package/dist/types/protocol/wire-api.d.ts +39 -1
  86. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  87. package/dist/types/protocol/wire.d.ts +65 -2
  88. package/dist/types/protocol/wire.d.ts.map +1 -1
  89. package/dist/types/server/routes.d.ts.map +1 -1
  90. package/docs/consuming.md +56 -121
  91. package/docs/sync-history.md +2 -1
  92. package/package.json +1 -1
  93. package/src/client/client.ts +36 -9
  94. package/src/client/connection.ts +31 -1
  95. package/src/client/turns.ts +2 -1
  96. package/src/core/agents/base.ts +2 -0
  97. package/src/core/agents/claude-code/approvals.ts +2 -2
  98. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  99. package/src/core/agents/scripted/scripted-agent.ts +42 -3
  100. package/src/core/presets.ts +4 -1
  101. package/src/core/runtime/agent-runtime.ts +31 -7
  102. package/src/core/runtime/event-processor.ts +13 -6
  103. package/src/core/runtime/origin-line.ts +43 -0
  104. package/src/core/runtime/request-broker.ts +2 -0
  105. package/src/core/runtime/steering.ts +8 -4
  106. package/src/core/runtime/turn.ts +11 -4
  107. package/src/operator/errors.ts +218 -0
  108. package/src/operator/index.ts +18 -23
  109. package/src/operator/mcp.ts +7 -16
  110. package/src/operator/operator.ts +1583 -613
  111. package/src/operator/refs.ts +75 -0
  112. package/src/operator/render.ts +208 -98
  113. package/src/operator/session-tools.ts +126 -0
  114. package/src/operator/types.ts +505 -0
  115. package/src/operator/view.ts +93 -42
  116. package/src/protocol/config.ts +14 -6
  117. package/src/protocol/conversation.ts +3 -0
  118. package/src/protocol/history.ts +2 -1
  119. package/src/protocol/index.ts +1 -0
  120. package/src/protocol/lifecycle.ts +21 -0
  121. package/src/protocol/origin.ts +47 -0
  122. package/src/protocol/reduce.ts +4 -0
  123. package/src/protocol/wire.ts +18 -0
  124. package/src/server/routes.ts +16 -5
@@ -0,0 +1,441 @@
1
+ /**
2
+ * The operator's public types (LLP 0019): who calls, what a session is as the
3
+ * tools report it, the host the product implements, and the refusals.
4
+ * `Origin` is the protocol's (it rides `turn/start` and `turn/steer`).
5
+ */
6
+ import type { z } from "zod";
7
+ import type { ReportedPermissionMode } from "../protocol/config.ts";
8
+ import type { AgentHarness } from "../protocol/harness.ts";
9
+ import type { Origin } from "../protocol/origin.ts";
10
+ import type { ThinkingLevel } from "../protocol/thinking.ts";
11
+ import type { Answer } from "./render.ts";
12
+ import type { DecisionRequest, QuestionRequest, ViewMessage } from "./view.ts";
13
+ export type { Origin };
14
+ /**
15
+ * A session's own agent calling the tools. Filled by the engine's delivery
16
+ * of the tools to the session, never by the model.
17
+ */
18
+ export interface SessionCaller {
19
+ kind: "session";
20
+ sessionId: string;
21
+ /** The turn the call is made in: a tool call always happens inside one. */
22
+ turnId: string;
23
+ harness: AgentHarness;
24
+ /** The session's mode live at the call, not the turn's start config: `plan` may only read. */
25
+ permissionMode: ReportedPermissionMode;
26
+ /** Aborts when the agent gives the call up: a held wait answers at once. */
27
+ signal?: AbortSignal;
28
+ }
29
+ /**
30
+ * Anyone outside a session: an assistant, a paired device, the product's
31
+ * own window. `Auth` is the host's (its token, its access row): the package
32
+ * passes it through to the host and reads nothing of it.
33
+ */
34
+ export interface ExternalCaller<Auth = unknown> {
35
+ kind: "external";
36
+ /** Stable per caller; with the kind, keys repeats and rates. */
37
+ id: string;
38
+ /** Whose words its messages are: the person's own window or device, or an assistant's. */
39
+ speaksAs: "person" | "assistant";
40
+ /** How the host shows it ("ChatGPT"); an assistant's origin carries it. */
41
+ name?: string;
42
+ /** Epoch ms its connection ends: no call waits past it (less a margin). */
43
+ endsAt?: number;
44
+ /** Aborts when the caller gives the call up (its request closed): a held wait answers at once. */
45
+ signal?: AbortSignal;
46
+ auth: Auth;
47
+ }
48
+ export type Caller<Auth = unknown> = SessionCaller | ExternalCaller<Auth>;
49
+ /** `session:<id>` or `external:<id>`: every map the package keeps is keyed by it. */
50
+ export type CallerKey = `session:${string}` | `external:${string}`;
51
+ /**
52
+ * - `setting_up`: its workspace is being prepared; no turn can run yet.
53
+ * - `idle`: no turn runs; the last one finished (or none ran).
54
+ * - `working`: a turn runs.
55
+ * - `needs_input`: a turn waits on a question, a plan or a permission.
56
+ * - `stopped`: the last turn was cancelled, and nothing ran since.
57
+ * - `error`: the last turn failed, or the workspace could not be set up.
58
+ * - `archived`: put away; read only.
59
+ */
60
+ export type SessionStatus = "setting_up" | "idle" | "working" | "needs_input" | "stopped" | "error" | "archived";
61
+ /** `list_sessions`'s `started_by` filter, from the caller's side. */
62
+ export type StartedByFilter = "me" | "agents" | "person" | "any";
63
+ export interface ProjectRef {
64
+ id: string;
65
+ /** Unique among the caller's projects, case-insensitively. May hold `/` (`owner/name`). */
66
+ name: string;
67
+ }
68
+ export interface WorkspaceRef {
69
+ id: string;
70
+ /** Unique in its project, case-insensitively; holds neither `/` nor `:`. */
71
+ name: string;
72
+ }
73
+ /** One session as the host lists it. */
74
+ export interface Entry {
75
+ /**
76
+ * The engine's `sessionId`, minted when the session is asked for, before
77
+ * its workspace is set up: one identity for the session's whole life.
78
+ */
79
+ id: string;
80
+ project?: ProjectRef;
81
+ /** A host with no workspaces gives each session one of its own. */
82
+ workspace: WorkspaceRef;
83
+ /** Its number in its workspace, from 1, never reused. Absent: the tools print its id. */
84
+ chat?: number;
85
+ /** The chat a bare workspace name means. */
86
+ current: boolean;
87
+ status: SessionStatus;
88
+ title?: string;
89
+ harness?: AgentHarness;
90
+ model?: string;
91
+ /**
92
+ * Who started it: the start's origin, kept by the host. An external caller
93
+ * speaking as the person starts as the person, at account scope.
94
+ */
95
+ startedBy: Origin;
96
+ startedAt?: number;
97
+ lastActivityAt?: number;
98
+ /** Why `error`, when setup failed (a failed turn's error is the view's). */
99
+ error?: string;
100
+ /** A few words the host adds to the row (lines changed, a pull request). */
101
+ note?: string;
102
+ /** Paths in this session's tool lines are shown relative to this folder. */
103
+ root?: string;
104
+ }
105
+ /** A place in a session's conversation, minted by the host; the package never reads it. */
106
+ export type Cursor = string & {
107
+ readonly __operatorCursor: true;
108
+ };
109
+ export type TurnOutcome = "running" | "done" | "cancelled" | "failed";
110
+ export interface ViewTurn {
111
+ turnId: string;
112
+ outcome: TurnOutcome;
113
+ /** Who stopped it, when the host knows (`cancelled`). */
114
+ cancelledBy?: Origin;
115
+ /** Why it failed (`failed`). */
116
+ error?: string;
117
+ /** Each user message carries its own sender (`ViewMessage.origin`): a turn can mix them. */
118
+ messages: readonly ViewMessage[];
119
+ startedAt?: number;
120
+ endedAt?: number;
121
+ }
122
+ /**
123
+ * What a session waits on, with the kind the engine's broker said explicitly
124
+ * (`permission.requested`'s `purpose`): a plan only when it says `plan`. A
125
+ * model names one by the broker's own `requestId`.
126
+ */
127
+ export type Waiting = {
128
+ kind: "question";
129
+ request: QuestionRequest;
130
+ } | {
131
+ kind: "plan" | "permission";
132
+ request: DecisionRequest;
133
+ };
134
+ /** How a turn ended, by its id, whatever page of the transcript is read. */
135
+ export interface TurnEnded {
136
+ turnId: string;
137
+ outcome: "done" | "cancelled" | "failed";
138
+ /** Who stopped it, when the host knows. */
139
+ cancelledBy?: Origin;
140
+ }
141
+ /** One turn, looked up by id. */
142
+ export type TurnFact = {
143
+ state: "running";
144
+ } | ({
145
+ state: "ended";
146
+ } & Omit<TurnEnded, "turnId">) | {
147
+ state: "unknown";
148
+ };
149
+ export interface SessionView {
150
+ status: SessionStatus;
151
+ /** The running turn's id, if one runs: independent of `turns`' page. */
152
+ running?: string;
153
+ /** The last turn that ended, and how: independent of `turns`' page. */
154
+ lastEnded?: TurnEnded;
155
+ /** Oldest first; after `after`, only what followed it (a turn still running may repeat). */
156
+ turns: readonly ViewTurn[];
157
+ waiting: readonly Waiting[];
158
+ /** The host holds earlier turns than these. */
159
+ older?: boolean;
160
+ /** Where this read ended: the next read's `after`. Absent: the host has no cursors. */
161
+ cursor?: Cursor;
162
+ }
163
+ export interface ViewOptions {
164
+ /** The most recent messages wanted. A host may give more; the package cuts. */
165
+ last?: number;
166
+ /** Only what came after this place. A cursor the host cannot read is `stale_cursor`. */
167
+ after?: Cursor;
168
+ }
169
+ export interface ListFilter {
170
+ project?: ProjectRef;
171
+ workspace?: WorkspaceRef;
172
+ status?: readonly SessionStatus[];
173
+ /** Archived ones too: name resolution asks for the complete set. */
174
+ includeArchived?: boolean;
175
+ }
176
+ export interface StartInput {
177
+ /** The first task's turn id, minted by the package: deliver the first message as this turn. */
178
+ turnId: string;
179
+ project: ProjectRef;
180
+ /** A new chat in this workspace; absent: a new workspace. */
181
+ workspace?: WorkspaceRef;
182
+ harness?: AgentHarness;
183
+ model?: string;
184
+ thinkingLevel?: ThinkingLevel;
185
+ title?: string;
186
+ /** The first message: the host delivers it as the session's first turn, at once or once set up. */
187
+ message: string;
188
+ origin: Origin;
189
+ }
190
+ export interface SendInput {
191
+ /** Minted by the package; a retry after no answer uses it again, and the engine converges on it. */
192
+ turnId: string;
193
+ message: string;
194
+ origin: Origin;
195
+ }
196
+ /**
197
+ * What a cancel did: the turn stopped (it has ended: a host whose stop is
198
+ * asynchronous waits for the end, briefly, before saying so), there was none,
199
+ * the stop is asked and its end not yet seen (`unconfirmed`: an archive then
200
+ * archives nothing), or (a session being set up) its first task was dropped.
201
+ */
202
+ export type CancelOutcome = "stopped" | "not_running" | "unconfirmed" | "first_task_dropped";
203
+ export type ArchiveTarget = {
204
+ kind: "session";
205
+ id: string;
206
+ } | {
207
+ kind: "workspace";
208
+ id: string;
209
+ };
210
+ export interface ModelEntry {
211
+ harness: AgentHarness;
212
+ id: string;
213
+ label: string;
214
+ thinkingLevels: readonly ThinkingLevel[];
215
+ defaultThinkingLevel?: ThinkingLevel;
216
+ /** The model a new session on this harness starts on. */
217
+ default?: boolean;
218
+ /** The harness a new session starts on when none is named. */
219
+ defaultHarness?: boolean;
220
+ }
221
+ /** Every refusal the tools give, and nothing else (LLP 0019, Errors). */
222
+ export declare const OPERATOR_ERROR_CODES: readonly ["invalid_input", "not_found", "ambiguous", "archived", "self", "read_only", "access", "not_yours", "has_children", "busy", "not_waiting", "person_only", "setup_failed", "limit_depth", "limit_sessions", "limit_setting_up", "limit_rate", "limit_resources", "stale_cursor", "unsupported", "failed"];
223
+ export type OperatorErrorCode = (typeof OPERATOR_ERROR_CODES)[number];
224
+ /** A refusal as the host gives one (`authorize`, `admit`, or thrown from a method as `Refused`). */
225
+ export interface Refusal {
226
+ code: OperatorErrorCode;
227
+ /** The sessions it is about, by id (a busy member, the children not archived). */
228
+ sessions?: readonly string[];
229
+ /** The state the host saw at its commit (`busy`): the words follow it, not the preflight read. */
230
+ state?: SessionStatus;
231
+ /** The host's words, one line, trusted: said after the code's sentence. */
232
+ detail?: string;
233
+ /** Seconds after which the same call may succeed. */
234
+ retryAfter?: number;
235
+ }
236
+ /**
237
+ * What a tool does, for the rules, declared honestly: anything that changes
238
+ * something or posts outside is `write`. `read` runs in plan mode.
239
+ */
240
+ export type Effect = "read" | "write" | "destructive";
241
+ /**
242
+ * Limits, each a host may change. The defaults are LLP 0019's.
243
+ * `depth` and `sessionsPerStarter` bind session callers only. A cap across
244
+ * the host (workspaces being set up, disk, memory) is the host's, enforced
245
+ * inside its own `start`: one starter's lock cannot hold it.
246
+ */
247
+ export interface Limits {
248
+ /** A session started by a chain this long may start no more. Default 3. */
249
+ depth: number;
250
+ /** Sessions one session started that are not archived. Default 12. */
251
+ sessionsPerStarter: number;
252
+ /** Starts per caller in any 60 seconds. Default 10. */
253
+ startsPerMinute: number;
254
+ }
255
+ /** How long a held call may wait, by caller kind: a default and a cap, in seconds. */
256
+ export interface WaitCaps {
257
+ /** Default 120 and 240 (Codex cuts a tool call at 300 s unless told otherwise). */
258
+ session: {
259
+ default: number;
260
+ max: number;
261
+ };
262
+ /** Default 60 and 90; never past `endsAt` less 5 s. */
263
+ external: {
264
+ default: number;
265
+ max: number;
266
+ };
267
+ }
268
+ /** What `admit` is asked before a start: the host's resource probes. */
269
+ export interface AdmitRequest {
270
+ kind: "start";
271
+ project: ProjectRef;
272
+ /** Absent: a new workspace would be set up. */
273
+ workspace?: WorkspaceRef;
274
+ origin: Origin;
275
+ }
276
+ /**
277
+ * The facts the rules and limits rest on, authoritative, not filtered by
278
+ * what a caller may see. Required of a host that enables session callers.
279
+ */
280
+ export interface PolicyFacts {
281
+ /** The sessions this session started, not archived. */
282
+ startedBy(sessionId: string): Promise<Entry[]>;
283
+ /** Who started this session, and who started that one, nearest first. */
284
+ lineage(sessionId: string): Promise<Origin[]>;
285
+ /** Every session in the workspace with its status, archived ones excluded. */
286
+ inWorkspace(workspaceId: string): Promise<Entry[]>;
287
+ }
288
+ /**
289
+ * The product, to the package. `list`, `view`, `send` and `onChange` are
290
+ * required; every other method is a capability, and a tool that needs one
291
+ * the host lacks is not listed. The host keeps its own check at each
292
+ * mutation; the package's rules are in addition.
293
+ */
294
+ export interface OperatorHost<Auth = unknown> {
295
+ /** The sessions this caller may see, filtered as asked (the package filters again). */
296
+ list(caller: Caller<Auth>, filter: ListFilter): Promise<Entry[]>;
297
+ view(caller: Caller<Auth>, sessionId: string, options: ViewOptions): Promise<SessionView>;
298
+ /**
299
+ * Start the turn `input.turnId` now, carrying `origin` to the wire. The
300
+ * same turn id again converges on the first (the engine's rule). A host
301
+ * that finds the session busy refuses `busy` (an `OperatorError`, or
302
+ * `Refused`), any other definite refusal is one of those too, and a
303
+ * failure whose outcome is unknown throws a plain error: the package tries
304
+ * again with the same turn id.
305
+ */
306
+ send(caller: Caller<Auth>, sessionId: string, input: SendInput): Promise<void>;
307
+ /** One turn by id: running, ended (how, and by whom when stopped), or unknown. */
308
+ turn(caller: Caller<Auth>, sessionId: string, turnId: string): Promise<TurnFact>;
309
+ /**
310
+ * Call `listener` with the sessions that may have changed, for as long as
311
+ * the returned function is not called. Waits rest on it.
312
+ */
313
+ onChange(listener: (sessionIds: readonly string[]) => void): () => void;
314
+ /** One entry by session id or workspace id (its current chat), archived ones included. */
315
+ entry?(caller: Caller<Auth>, id: string): Promise<Entry | undefined>;
316
+ /** Every project this caller could start in, those with no session included. */
317
+ projects?(caller: Caller<Auth>): Promise<ProjectRef[]>;
318
+ /**
319
+ * Make the session (and its workspace, when none is named) and return its
320
+ * entry at once, its session id minted now: `idle`, or `setting_up` while
321
+ * its workspace is prepared. Keep `input.origin` as its `startedBy`. The
322
+ * host OWNS delivering `input.message` as its first turn (`input.turnId`),
323
+ * at once or once set up, and reports what became of it through the
324
+ * session's status (an `error` with why when it could not be delivered).
325
+ * The package's checks are preflight; the host enforces, atomically at
326
+ * its commit, by throwing `Refused`: no start into an archived workspace
327
+ * or by an archived starter (`archived`), and its caps across starters
328
+ * (`limit_setting_up` or `limit_resources`, with `retryAfter`). Enables
329
+ * `start_session`.
330
+ */
331
+ start?(caller: Caller<Auth>, input: StartInput): Promise<Entry>;
332
+ /**
333
+ * Stop this turn, and only it; with no turn (a session being set up), drop
334
+ * the first task the host holds for it. Enables `stop_sessions` and
335
+ * `when: interrupt`.
336
+ */
337
+ cancel?(caller: Caller<Auth>, sessionId: string, turnId?: string): Promise<CancelOutcome>;
338
+ /** Answer exactly this request; `accepted: false` when it no longer waits. Enables `answer_request`. */
339
+ respond?(caller: Caller<Auth>, sessionId: string, answer: Answer): Promise<{
340
+ accepted: boolean;
341
+ }>;
342
+ /**
343
+ * Archive one target. The package's checks are preflight; the host
344
+ * enforces eligibility atomically at its commit, throwing `Refused` with
345
+ * the sessions concerned and the state it saw: a member being set up
346
+ * (`busy`, `state: "setting_up"`), a member still working or waiting, the
347
+ * caller's own included, since a stop must be confirmed first (`busy`; a
348
+ * member the caller did not start, `not_yours`), a member that started
349
+ * sessions not archived, lineage included (`has_children`).
350
+ * Enables `archive`.
351
+ */
352
+ archive?(caller: Caller<Auth>, target: ArchiveTarget): Promise<{
353
+ note?: string;
354
+ }>;
355
+ /** The models a new session can run. Enables `list_models`. */
356
+ models?(caller: Caller<Auth>): Promise<ModelEntry[]>;
357
+ /**
358
+ * Whether this outside caller may run this tool now, read from the host's
359
+ * store at the call: asked before every tool and again just before every
360
+ * write the package makes (each send, cancel, answer, start, archive). The tool's
361
+ * name lets a host allow one write tool to a low-access caller.
362
+ */
363
+ authorize?(caller: ExternalCaller<Auth>, call: {
364
+ effect: Effect;
365
+ tool: string;
366
+ }): Refusal | undefined | Promise<Refusal | undefined>;
367
+ /** Required with session callers: the facts the rules and limits rest on. */
368
+ policy?: PolicyFacts;
369
+ /** Resource probes before a start (disk, memory): a `limit_resources` refusal, or none. */
370
+ admit?(caller: Caller<Auth>, request: AdmitRequest): Promise<Refusal | undefined>;
371
+ /** One line of host facts once a turn settles ("changes: a.ts (+4 -0)"). */
372
+ outcome?(caller: Caller<Auth>, entry: Entry): Promise<string | undefined>;
373
+ /** One line `whoami` adds for this caller ("access: read"). */
374
+ describe?(caller: Caller<Auth>): Promise<string | undefined>;
375
+ }
376
+ /**
377
+ * A tool the host adds beside the package's. It declares only its effect;
378
+ * the package applies plan mode and `authorize` (with its name) to it and
379
+ * nothing else. It may not change sessions: that is the package's tools'.
380
+ */
381
+ export interface ExtraTool<Auth = unknown> {
382
+ name: string;
383
+ title: string;
384
+ description: string;
385
+ input: z.ZodObject;
386
+ effect: Effect;
387
+ /** It reaches past this host (sends something elsewhere): MCP's `openWorldHint`. */
388
+ openWorld?: boolean;
389
+ /** `call`: the call's deadline (epoch ms) and its caller's signal, so a long run answers in time. */
390
+ run(args: never, caller: Caller<Auth>, call: CallScope): Promise<string>;
391
+ }
392
+ /**
393
+ * A call's time, as a host's own tool sees it: the deadline the package's
394
+ * waits keep (the caller's wait, capped, never past its connection) and the
395
+ * caller's signal.
396
+ */
397
+ export interface CallScope {
398
+ deadline: number;
399
+ signal?: AbortSignal;
400
+ }
401
+ /** A tool as any transport lists it. */
402
+ export interface ToolInfo {
403
+ name: string;
404
+ title: string;
405
+ description: string;
406
+ /** JSON Schema of the arguments (an object). */
407
+ inputSchema: unknown;
408
+ readOnly: boolean;
409
+ /** It reaches past this host: MCP's `openWorldHint`. */
410
+ openWorld?: boolean;
411
+ /** It may undo or lose work: MCP's `destructiveHint`. */
412
+ destructive?: boolean;
413
+ }
414
+ /** Time, for the waits and the limits. Tests pass their own; the default is the wall clock. */
415
+ export interface OperatorClock {
416
+ now(): number;
417
+ /** Resolve after `ms`, or as soon as `signal` aborts. */
418
+ pause(ms: number, signal: AbortSignal): Promise<void>;
419
+ }
420
+ export interface OperatorOptions<Auth = unknown> {
421
+ limits?: Partial<Limits>;
422
+ waits?: Partial<WaitCaps>;
423
+ extra?: ExtraTool<Auth>[];
424
+ clock?: OperatorClock;
425
+ /**
426
+ * Shown each unexpected failure a call answers without (a `refused (failed)`,
427
+ * an outcome that could not be read), once, with the tool and the caller:
428
+ * for the host's reports. Never a refusal. It cannot change the answer,
429
+ * and a throw inside it is swallowed.
430
+ */
431
+ onError?: (error: unknown, tool: string, caller: Caller<Auth>) => void;
432
+ }
433
+ export interface Operator<Auth = unknown> {
434
+ /** The same for every caller: an assistant keeps the list it got when it connected. */
435
+ tools(): ToolInfo[];
436
+ /** Run one tool and answer in text. Refusals are `OperatorError`s. */
437
+ call(name: string, args: unknown, caller: Caller<Auth>): Promise<string>;
438
+ /** The entry a reference names (LLP 0019, References). */
439
+ find(caller: Caller<Auth>, ref: string): Promise<Entry>;
440
+ }
441
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/operator/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,sBAAs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  /**
2
- * What an operator needs to know about one session, however its host keeps it.
3
- *
4
- * A host that holds a folded `ConversationState` gets this with `viewOf`. A host
5
- * that keeps its own rows (messages with their parts, a status column) builds
6
- * the same shape directly. Nothing here knows about projects, workspaces,
7
- * accounts or storage: those are the host's.
2
+ * What the operator needs to know about one session, however its host keeps
3
+ * it. A host that holds a folded `ConversationState` gets it with `viewOf`; a
4
+ * host that keeps its own rows builds the same shape. Nothing here knows about
5
+ * projects, workspaces, accounts or storage: those are the host's.
8
6
  */
9
7
  import { type ConversationElicitation, type ConversationPermission, type ConversationState } from "../protocol/conversation.ts";
8
+ import type { ReportedOrigin } from "../protocol/origin.ts";
10
9
  import type { Part, UnknownPart } from "../protocol/parts.ts";
10
+ import type { SessionStatus, SessionView, TurnFact, Waiting } from "./types.ts";
11
11
  export interface ViewMessage {
12
12
  role: "user" | "assistant";
13
13
  parts: readonly (Part | UnknownPart)[];
14
14
  /** A sub-agent's output: shown nested, never as the agent's reply. */
15
15
  nested?: boolean;
16
+ /** A user message's sender when it is not the person (LLP 0019). */
17
+ origin?: ReportedOrigin;
16
18
  }
17
19
  /** A question the agent asked, as the engine's `elicitation.requested` carries it. */
18
20
  export type QuestionRequest = Pick<ConversationElicitation, "requestId" | "mode" | "message" | "questions" | "url">;
19
21
  /** A decision the agent waits on (a tool's approval, or a plan), as `permission.requested` carries it. */
20
- export type DecisionRequest = Pick<ConversationPermission, "requestId" | "title" | "toolCall" | "options">;
21
- export type Waiting = {
22
- kind: "question";
23
- request: QuestionRequest;
24
- } | {
25
- kind: "decision";
26
- request: DecisionRequest;
27
- };
28
- export interface SessionView {
29
- /** Whether a turn is running. "Waiting on a person" is `waiting`, not a status. */
30
- status: "idle" | "working" | "error";
31
- messages: readonly ViewMessage[];
32
- waiting: readonly Waiting[];
33
- error?: string;
34
- /** The host holds earlier messages than the ones given here. */
35
- older?: boolean;
36
- }
37
- /** What a person would call the session's state. Waiting on them is not "finished". */
38
- export type Phase = "idle" | "working" | "needs_input" | "error";
39
- export declare function phaseOf(view: Pick<SessionView, "status" | "waiting">): Phase;
40
- /** A plan's approval is a decision whose options include "keep planning" (`PLAN_OPTIONS`). */
41
- export declare function isPlan(request: DecisionRequest): boolean;
42
- /** The view of a session whose events were folded with the engine's reducer. */
22
+ export type DecisionRequest = Pick<ConversationPermission, "requestId" | "title" | "toolCall" | "options" | "purpose">;
23
+ /** A decision's kind, from its `purpose`: `plan` when it says so, else a permission. */
24
+ export declare function waitingOf(request: DecisionRequest): Waiting;
25
+ /** Whether a status needs no more waiting: a wait returns it. */
26
+ export declare const settledStatus: (status: SessionStatus) => boolean;
27
+ /**
28
+ * The view of a session whose events were folded with the engine's reducer,
29
+ * with its turn facts (`running`, `lastEnded`) from every turn, not a page.
30
+ */
43
31
  export declare function viewOf(state: ConversationState): SessionView;
32
+ /** One turn of a folded state, by id: the host's `turn`, for a host that folds. */
33
+ export declare function turnOf(state: ConversationState, turnId: string): TurnFact;
44
34
  //# sourceMappingURL=view.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../../src/operator/view.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EAItB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAG9D,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC,IAAI,GAAG,WAAW,CAAC,EAAE,CAAC;IACvC,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,sFAAsF;AACtF,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,uBAAuB,EACvB,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,KAAK,CACtD,CAAC;AACF,0GAA0G;A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C;AAC9D,OAAO,KAAK,EACX,aAAa,EACb,WAAW,EACX,QAAQ,EAGR,OAAO,EACP,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,KAAK,EAAE,SAAS,CAAC,IAAI,GAAG,WAAW,CAAC,EAAE,CAAC;IACvC,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oEAAoE;IACpE,MAAM,CAAC,EAAE,cAAc,CAAC;CACxB;AAED,sFAAsF;AACtF,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,uBAAuB,EACvB,WAAW,GAAG,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,KAAK,CACtD,CAAC;AACF,0GAA0G;AAC1G,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,sBAAsB,EACtB,WAAW,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAC1D,CAAC;AAGF,wFAAwF;AACxF,wBAAgB,SAAS,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAE3D;AAED,iEAAiE;AACjE,eAAO,MAAM,aAAa,GAAI,QAAQ,aAAa,KAAG,OACN,CAAC;AAEjD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,iBAAiB,GAAG,WAAW,CAE5D;AAED,mFAAmF;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAQzE"}
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { type Origin } from "./origin.ts";
2
3
  /**
3
4
  * Permission posture for a turn. `bypass_permissions` auto-approves every
4
5
  * tool (the right default inside a sandbox); `plan` is read-only planning;
@@ -180,16 +181,30 @@ export declare const RunRequestSchema: z.ZodObject<{
180
181
  disableTools: z.ZodOptional<z.ZodBoolean>;
181
182
  includeRaw: z.ZodOptional<z.ZodBoolean>;
182
183
  }, z.core.$strip>;
184
+ origin: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
185
+ kind: z.ZodLiteral<"person">;
186
+ }, z.core.$strip>, z.ZodObject<{
187
+ kind: z.ZodLiteral<"session">;
188
+ sessionId: z.ZodString;
189
+ name: z.ZodOptional<z.ZodString>;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ kind: z.ZodLiteral<"assistant">;
192
+ id: z.ZodString;
193
+ name: z.ZodString;
194
+ }, z.core.$strip>], "kind">>;
183
195
  }, z.core.$strip>;
184
196
  export type RunRequest = z.infer<typeof RunRequestSchema>;
185
197
  /**
186
- * What makes a turn the same turn when a client sends its ids again: its input
187
- * and the config that shapes what the agent does. What a client's own restart
188
- * can change without making it another turn stays out: MCP endpoints (a fresh
189
- * per-session URL), the environment, the API key, and raw passthrough.
198
+ * What makes a turn the same turn when a client sends its ids again: its
199
+ * input, who sent it, and the config that shapes what the agent does. What a
200
+ * client's own restart can change without making it another turn stays out:
201
+ * MCP endpoints (a fresh per-session URL), the environment, the API key, and
202
+ * raw passthrough. The person's origin, said or not, adds nothing, so a
203
+ * request's identity is what it was before origins existed.
190
204
  */
191
- export declare function turnIdentity(request: Pick<RunRequest, "input" | "config">): {
205
+ export declare function turnIdentity(request: Pick<RunRequest, "input" | "config" | "origin">): {
192
206
  input: RunRequest["input"];
193
207
  config: Omit<RunConfig, "mcpServers" | "env" | "apiKey" | "includeRaw">;
208
+ origin?: Origin;
194
209
  };
195
210
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/protocol/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB;;;;;;EAM/B,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAElE;;;;GAIG;AACH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