@superdurable/dex-agents 0.1.0 → 0.2.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.
Files changed (149) hide show
  1. package/README.md +1568 -62
  2. package/dist/src/agent-built-in-tools.d.ts +81 -0
  3. package/dist/src/agent-built-in-tools.js +246 -0
  4. package/dist/src/agent-built-in-tools.js.map +1 -0
  5. package/dist/src/agent-context-compaction.d.ts +108 -0
  6. package/dist/src/agent-context-compaction.js +39 -0
  7. package/dist/src/agent-context-compaction.js.map +1 -0
  8. package/dist/src/agent-framework-runner.d.ts +456 -16
  9. package/dist/src/agent-framework-runner.js +4 -3
  10. package/dist/src/agent-framework-runner.js.map +1 -1
  11. package/dist/src/agent-plans.d.ts +48 -0
  12. package/dist/src/agent-plans.js +86 -0
  13. package/dist/src/agent-plans.js.map +1 -0
  14. package/dist/src/agent-session-cancellation-steps.d.ts +28 -0
  15. package/dist/src/agent-session-cancellation-steps.js +154 -0
  16. package/dist/src/agent-session-cancellation-steps.js.map +1 -0
  17. package/dist/src/agent-session-codecs.d.ts +65 -4
  18. package/dist/src/agent-session-codecs.js +342 -8
  19. package/dist/src/agent-session-codecs.js.map +1 -1
  20. package/dist/src/agent-session-flow.d.ts +295 -27
  21. package/dist/src/agent-session-flow.js +368 -21
  22. package/dist/src/agent-session-flow.js.map +1 -1
  23. package/dist/src/agent-session-persistence.d.ts +81 -4
  24. package/dist/src/agent-session-persistence.js +33 -2
  25. package/dist/src/agent-session-persistence.js.map +1 -1
  26. package/dist/src/agent-session-settings.d.ts +58 -0
  27. package/dist/src/agent-session-settings.js +81 -0
  28. package/dist/src/agent-session-settings.js.map +1 -0
  29. package/dist/src/agent-session-step-options.d.ts +27 -0
  30. package/dist/src/agent-session-step-options.js +39 -0
  31. package/dist/src/agent-session-step-options.js.map +1 -0
  32. package/dist/src/agent-session-step-types.d.ts +20 -0
  33. package/dist/src/agent-session-step-types.js +28 -0
  34. package/dist/src/agent-session-step-types.js.map +1 -0
  35. package/dist/src/agent-session-steps.d.ts +101 -8
  36. package/dist/src/agent-session-steps.js +936 -197
  37. package/dist/src/agent-session-steps.js.map +1 -1
  38. package/dist/src/agent-session-tracer.d.ts +61 -0
  39. package/dist/src/agent-session-tracer.js +608 -0
  40. package/dist/src/agent-session-tracer.js.map +1 -0
  41. package/dist/src/agent-session-transitions.d.ts +189 -26
  42. package/dist/src/agent-session-transitions.js +680 -32
  43. package/dist/src/agent-session-transitions.js.map +1 -1
  44. package/dist/src/agent-session-values.d.ts +690 -29
  45. package/dist/src/agent-session-values.js +39 -4
  46. package/dist/src/agent-session-values.js.map +1 -1
  47. package/dist/src/agent-session-wait-steps.d.ts +53 -0
  48. package/dist/src/agent-session-wait-steps.js +389 -0
  49. package/dist/src/agent-session-wait-steps.js.map +1 -0
  50. package/dist/src/agent-tracing-options.d.ts +107 -0
  51. package/dist/src/agent-tracing-options.js +20 -0
  52. package/dist/src/agent-tracing-options.js.map +1 -0
  53. package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +40 -0
  54. package/dist/src/ai-sdk/ai-sdk-model-client.js +235 -0
  55. package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -0
  56. package/dist/src/ai-sdk/index.d.ts +1 -0
  57. package/dist/src/ai-sdk/index.js +9 -0
  58. package/dist/src/ai-sdk/index.js.map +1 -0
  59. package/dist/src/index.d.ts +9 -3
  60. package/dist/src/index.js +7 -2
  61. package/dist/src/index.js.map +1 -1
  62. package/dist/src/mcp/index.d.ts +3 -0
  63. package/dist/src/mcp/index.js +10 -0
  64. package/dist/src/mcp/index.js.map +1 -0
  65. package/dist/src/mcp/mcp-resource-and-prompt-tools.d.ts +29 -0
  66. package/dist/src/mcp/mcp-resource-and-prompt-tools.js +185 -0
  67. package/dist/src/mcp/mcp-resource-and-prompt-tools.js.map +1 -0
  68. package/dist/src/mcp/mcp-server-config.d.ts +86 -0
  69. package/dist/src/mcp/mcp-server-config.js +38 -0
  70. package/dist/src/mcp/mcp-server-config.js.map +1 -0
  71. package/dist/src/mcp/mcp-tool-source.d.ts +470 -0
  72. package/dist/src/mcp/mcp-tool-source.js +1204 -0
  73. package/dist/src/mcp/mcp-tool-source.js.map +1 -0
  74. package/dist/src/stepwise/agent-definition.d.ts +158 -0
  75. package/dist/src/stepwise/agent-definition.js +9 -0
  76. package/dist/src/stepwise/agent-definition.js.map +1 -0
  77. package/dist/src/stepwise/function-tool.d.ts +130 -0
  78. package/dist/src/stepwise/function-tool.js +75 -0
  79. package/dist/src/stepwise/function-tool.js.map +1 -0
  80. package/dist/src/stepwise/index.d.ts +7 -0
  81. package/dist/src/stepwise/index.js +12 -0
  82. package/dist/src/stepwise/index.js.map +1 -0
  83. package/dist/src/stepwise/json-schema-validation.d.ts +9 -0
  84. package/dist/src/stepwise/json-schema-validation.js +141 -0
  85. package/dist/src/stepwise/json-schema-validation.js.map +1 -0
  86. package/dist/src/stepwise/model-client.d.ts +194 -0
  87. package/dist/src/stepwise/model-client.js +9 -0
  88. package/dist/src/stepwise/model-client.js.map +1 -0
  89. package/dist/src/stepwise/scripted-model-client.d.ts +99 -0
  90. package/dist/src/stepwise/scripted-model-client.js +156 -0
  91. package/dist/src/stepwise/scripted-model-client.js.map +1 -0
  92. package/dist/src/stepwise/stepwise-agent-runner.d.ts +189 -0
  93. package/dist/src/stepwise/stepwise-agent-runner.js +804 -0
  94. package/dist/src/stepwise/stepwise-agent-runner.js.map +1 -0
  95. package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +35 -0
  96. package/dist/src/stepwise/stepwise-agent-session-flow.js +56 -0
  97. package/dist/src/stepwise/stepwise-agent-session-flow.js.map +1 -0
  98. package/dist/src/stepwise/stepwise-input-items.d.ts +12 -0
  99. package/dist/src/stepwise/stepwise-input-items.js +172 -0
  100. package/dist/src/stepwise/stepwise-input-items.js.map +1 -0
  101. package/dist/src/stepwise/tool-source.d.ts +103 -0
  102. package/dist/src/stepwise/tool-source.js +9 -0
  103. package/dist/src/stepwise/tool-source.js.map +1 -0
  104. package/dist/src/testing/agent-session-test-client.d.ts +65 -8
  105. package/dist/src/testing/agent-session-test-client.js +95 -22
  106. package/dist/src/testing/agent-session-test-client.js.map +1 -1
  107. package/dist/src/testing/index.d.ts +1 -0
  108. package/dist/src/testing/index.js +1 -0
  109. package/dist/src/testing/index.js.map +1 -1
  110. package/dist/src/testing/private-dex-engine.d.ts +9 -0
  111. package/dist/src/testing/private-dex-engine.js +9 -1
  112. package/dist/src/testing/private-dex-engine.js.map +1 -1
  113. package/dist/src/testing/scripted-model-client.d.ts +1 -0
  114. package/dist/src/testing/scripted-model-client.js +10 -0
  115. package/dist/src/testing/scripted-model-client.js.map +1 -0
  116. package/dist/src/ui-stream/agent-event-json.d.ts +30 -0
  117. package/dist/src/ui-stream/agent-event-json.js +64 -0
  118. package/dist/src/ui-stream/agent-event-json.js.map +1 -0
  119. package/dist/src/ui-stream/agent-event-sse.d.ts +154 -0
  120. package/dist/src/ui-stream/agent-event-sse.js +159 -0
  121. package/dist/src/ui-stream/agent-event-sse.js.map +1 -0
  122. package/dist/src/ui-stream/agent-event-stream-positions.d.ts +42 -0
  123. package/dist/src/ui-stream/agent-event-stream-positions.js +153 -0
  124. package/dist/src/ui-stream/agent-event-stream-positions.js.map +1 -0
  125. package/dist/src/ui-stream/agent-session-record-reader.d.ts +72 -0
  126. package/dist/src/ui-stream/agent-session-record-reader.js +241 -0
  127. package/dist/src/ui-stream/agent-session-record-reader.js.map +1 -0
  128. package/dist/src/ui-stream/agent-ui-message-stream-responses.d.ts +219 -0
  129. package/dist/src/ui-stream/agent-ui-message-stream-responses.js +440 -0
  130. package/dist/src/ui-stream/agent-ui-message-stream-responses.js.map +1 -0
  131. package/dist/src/ui-stream/agent-ui-message-stream.d.ts +138 -0
  132. package/dist/src/ui-stream/agent-ui-message-stream.js +681 -0
  133. package/dist/src/ui-stream/agent-ui-message-stream.js.map +1 -0
  134. package/dist/src/ui-stream/agent-ui-message-types.d.ts +238 -0
  135. package/dist/src/ui-stream/agent-ui-message-types.js +57 -0
  136. package/dist/src/ui-stream/agent-ui-message-types.js.map +1 -0
  137. package/dist/src/ui-stream/agent-ui-messages.d.ts +66 -0
  138. package/dist/src/ui-stream/agent-ui-messages.js +220 -0
  139. package/dist/src/ui-stream/agent-ui-messages.js.map +1 -0
  140. package/dist/src/ui-stream/agent-ui-stream-cursor.d.ts +64 -0
  141. package/dist/src/ui-stream/agent-ui-stream-cursor.js +186 -0
  142. package/dist/src/ui-stream/agent-ui-stream-cursor.js.map +1 -0
  143. package/dist/src/ui-stream/index.d.ts +14 -0
  144. package/dist/src/ui-stream/index.js +22 -0
  145. package/dist/src/ui-stream/index.js.map +1 -0
  146. package/dist/src/ui-stream/server-sent-event-responses.d.ts +6 -0
  147. package/dist/src/ui-stream/server-sent-event-responses.js +34 -0
  148. package/dist/src/ui-stream/server-sent-event-responses.js.map +1 -0
  149. package/package.json +41 -5
@@ -5,14 +5,106 @@
5
5
  * - `running_model`: `RunModel` makes the turn's next model call.
6
6
  * - `running_tools`: the requested tool calls run in parallel Steps, some possibly waiting for
7
7
  * approval, and `ResumeTurn` waits for their results.
8
+ * - `compacting_context`: `CompactContext` summarizes earlier messages before the turn's next model
9
+ * call. Only a session with {@link AgentSessionOptions.compaction} reaches it.
8
10
  */
9
- export type AgentSessionStatus = "waiting_for_user_message" | "running_model" | "running_tools";
11
+ export type AgentSessionStatus = "waiting_for_user_message" | "running_model" | "running_tools" | "compacting_context";
12
+ /**
13
+ * Kind of a turn, stored in {@link AgentState.interactionMode} when the turn starts, for the runner to choose
14
+ * the tools it offers. Plan mode needs {@link AgentSessionOptions.planModeEnabled}; without it every turn is
15
+ * `chat`.
16
+ *
17
+ * - `chat`: an ordinary turn. The runner offers every tool.
18
+ * - `planning`: a turn that only plans. A message of the turn has `planMode`, or a `draft` plan waits for
19
+ * review. The runner offers only `write_todos`, and `RunModel` rejects any other call.
20
+ * - `executing`: a turn that `execute_plan` started. The runner offers every tool.
21
+ */
22
+ export type InteractionMode = "chat" | "planning" | "executing";
23
+ /**
24
+ * Where an {@link AgentPlan} stands.
25
+ *
26
+ * - `draft`: a planning turn wrote the plan, and it waits for `execute_plan`.
27
+ * - `active`: the plan runs, or `write_todos` wrote it outside a planning turn with a task not completed.
28
+ * - `completed`: every task is completed.
29
+ * - `cleared`: `write_todos` replaced the plan with no tasks.
30
+ */
31
+ export type PlanStatus = "draft" | "active" | "completed" | "cleared";
32
+ /** Where one task of an {@link AgentPlan} stands: `pending`, `in_progress`, or `completed`. */
33
+ export type PlanTaskStatus = "pending" | "in_progress" | "completed";
34
+ /** One task of an {@link AgentPlan}. */
35
+ export interface AgentPlanTask {
36
+ /** What the task does, as the model wrote it; never blank. Wire field: `content`. */
37
+ readonly content: string;
38
+ /** Where the task stands. Wire field: `status`. */
39
+ readonly status: PlanTaskStatus;
40
+ }
41
+ /**
42
+ * The session's plan, stored in the `AgentPlan` Attribute: a short task list the model replaces as a whole.
43
+ *
44
+ * `write_todos` replaces it with the next revision, and `execute_plan` names the revision the user approves.
45
+ * Compaction never summarizes it.
46
+ */
47
+ export interface AgentPlan {
48
+ /**
49
+ * Revision of the plan, starting at 1. Every `write_todos` call that succeeds adds 1, an empty list
50
+ * included. Wire field: `revision`.
51
+ */
52
+ readonly revision: number;
53
+ /** Where the plan stands. Wire field: `status`. */
54
+ readonly status: PlanStatus;
55
+ /** Every task in order; empty when `cleared`. Wire field: `tasks`. */
56
+ readonly tasks: readonly AgentPlanTask[];
57
+ /** RFC 3339 time of the last change. Wire field: `updated_at`. */
58
+ readonly updatedAt: string;
59
+ }
60
+ /**
61
+ * Input of the `execute_plan` RPC.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const snapshot = await client.invokeRPC(flow.getAgentSnapshot, sessionId);
66
+ * if (snapshot.plan?.status === "draft") {
67
+ * await client.invokeRPC(flow.executePlan, sessionId, { revision: snapshot.plan.revision });
68
+ * }
69
+ * ```
70
+ */
71
+ export interface ExecutePlanRequest {
72
+ /**
73
+ * {@link AgentPlan.revision} the user reviewed. A stale revision is refused, so the session never runs a
74
+ * plan the user did not see. Wire field: `revision`.
75
+ */
76
+ readonly revision: number;
77
+ }
78
+ /**
79
+ * One approved plan execution, published to the `PlanExecutions` ChannelMap instance named by the revision
80
+ * and held in the `PendingPlanExecution` Attribute until `AwaitUserMessage` starts its `executing` turn.
81
+ */
82
+ export interface PlanExecutionRequest {
83
+ /** The approved {@link AgentPlan.revision}. Wire field: `revision`. */
84
+ readonly revision: number;
85
+ }
86
+ /**
87
+ * A session's settings: one JSON object that the application chooses, such as `{ model: "gpt-5-mini" }`.
88
+ *
89
+ * Set them in {@link AgentSessionStartInput.sessionSettings} and replace them with the
90
+ * `update_session_settings` RPC. A runner reads the settings of the running turn from
91
+ * `AgentTurnContext.sessionSettings`; a Stepwise agent maps them to a model client with
92
+ * `AgentDefinition.resolveModel`. Keys keep their spelling on the wire; nothing is converted to snake_case.
93
+ *
94
+ * Settings are stored in the session and returned by `get_agent_snapshot`, so never put a secret in them. Put a
95
+ * reference, such as a credential name, that the Worker resolves. Their compact JSON text must fit in
96
+ * `MAX_SESSION_SETTINGS_BYTES`; see `validateSessionSettings`.
97
+ */
98
+ export type SessionSettings = Readonly<Record<string, unknown>>;
10
99
  /**
11
100
  * Input of the `StartAgentSession` Step, passed to `Client.startFlow`.
12
101
  *
13
102
  * @example
14
103
  * ```ts
15
- * await client.startFlow(flow, "session-42", { initialMessage: "Summarize my inbox" });
104
+ * await client.startFlow(flow, "session-42", {
105
+ * initialMessage: "Summarize my inbox",
106
+ * sessionSettings: { model: "gpt-5-mini" },
107
+ * });
16
108
  * ```
17
109
  */
18
110
  export interface AgentSessionStartInput {
@@ -21,6 +113,15 @@ export interface AgentSessionStartInput {
21
113
  * Blank text is treated as `null`. Wire field: `initial_message`.
22
114
  */
23
115
  readonly initialMessage: string | null;
116
+ /**
117
+ * The session's {@link SessionSettings}, which every turn's `AgentTurnContext.sessionSettings` carries until
118
+ * `update_session_settings` replaces them. Absent or `null` starts without settings. Settings that the session
119
+ * refuses, because they are not a JSON object or are too large, fail the session at once with no retry; check
120
+ * them first with `validateSessionSettings`. Never put a secret in them: `get_agent_snapshot` and the browser
121
+ * snapshot JSON return them. Start sessions with settings only after every Worker of the Flow type runs
122
+ * dex-agents 0.2.0, because a 0.1.0 Worker drops them. Wire field: `session_settings`.
123
+ */
124
+ readonly sessionSettings?: SessionSettings | null;
24
125
  }
25
126
  /** Small durable summary of an agent session, stored in the `AgentState` Attribute. */
26
127
  export interface AgentState {
@@ -34,6 +135,23 @@ export interface AgentState {
34
135
  readonly nextMessageSequence: number;
35
136
  /** Error text of the most recent failed turn, or `null`. Wire field: `last_turn_error`. */
36
137
  readonly lastTurnError: string | null;
138
+ /**
139
+ * Kind of the active turn, or of the last turn between turns; the session sets it when a turn starts.
140
+ * Wire field: `interaction_mode`, `chat` by default.
141
+ *
142
+ * Like every field plans added, a decoded value omits it at its default, so a value of a session that
143
+ * uses no plans has its 0.1.0 shape, and code that compares whole values keeps working; the wire always
144
+ * carries it. Treat `undefined` as `chat`.
145
+ */
146
+ readonly interactionMode?: InteractionMode;
147
+ /**
148
+ * Whether `steer_user_message` and `cancel_turn` may end the active turn. A Worker that applies them sets it
149
+ * when a turn starts and clears it when the turn ends. An earlier Worker drops it whenever it writes
150
+ * `AgentState`, so the RPCs refuse a turn that such a Worker started or advanced. Wire field:
151
+ * `accepts_turn_control`. The decoder sets it only when it is `true`, so `undefined` means `false` and an idle
152
+ * state keeps its 0.1.0 shape.
153
+ */
154
+ readonly acceptsTurnControl?: boolean;
37
155
  }
38
156
  /** Author of one stored agent message. */
39
157
  export type AgentMessageRole = "user" | "assistant" | "tool";
@@ -79,16 +197,75 @@ export interface AgentMessage extends FrameworkMessage {
79
197
  */
80
198
  export type ToolEffect = "read" | "idempotent_write" | "non_idempotent_write" | "unclassified";
81
199
  /**
82
- * Status of one deferred tool call record.
200
+ * Status of one deferred tool call record, as a runner sees it.
83
201
  *
84
202
  * `awaiting_approval` and `approved` are open. The other statuses are final: the session
85
203
  * never runs a call whose record is final, and the runner reports the result to the model.
86
- * `failed` means the tool threw {@link ToolExecutionError}, or a `read` call ended without a result after
87
- * its attempts ran out. `outcome_unknown` means a write's tool Step ended without a result, through a
88
- * Worker crash, a timeout, or another error after its attempts ran out.
204
+ * `failed` means the tool threw {@link ToolExecutionError}, a `read` call ended without a result after
205
+ * its attempts ran out, or the tool did not run (its error starts with {@link toolCallNotRunErrorPrefix}).
206
+ * `outcome_unknown` means a write's tool Step ended without a result, through a Worker crash, a timeout,
207
+ * or another error after its attempts ran out.
208
+ *
209
+ * The set of final statuses never grows, so an exhaustive mapping of final statuses stays complete.
210
+ * A stored record can also hold an {@link AgentToolCallWaitingStatus}; runners never see one.
89
211
  */
90
212
  export type AgentToolCallStatus = "awaiting_approval" | "approved" | "rejected" | "succeeded" | "failed" | "outcome_unknown";
91
- /** Durable record of one deferred tool call, stored in `AgentToolCalls` under its tool call ID. */
213
+ /**
214
+ * Non-final status of a stored record while a session Step waits on the call's behalf.
215
+ *
216
+ * - `awaiting_answer`: `AwaitQuestionAnswer` waits for `answer_question`. The call is an `ask_user`
217
+ * call, or a tool call whose tool returned {@link ToolInputRequested}.
218
+ * - `waiting_for_timer`: `AwaitTimer` waits until {@link AgentToolCallRecord.waitUntil} for a
219
+ * `durable_wait` call.
220
+ * - `waiting_for_task`: the tool returned {@link ToolTaskStarted}, and `PollToolTask` polls the task in
221
+ * {@link AgentToolCallRecord.taskId} every {@link AgentToolCallRecord.taskPollIntervalSeconds}.
222
+ *
223
+ * These statuses appear in {@link AgentSnapshot.toolCalls} and in records read with
224
+ * `Client.getAttributes`. A runner never receives a record with one of them: `RunModel` runs only after
225
+ * every record of the turn is final, and a tool Step runs only an `approved` record.
226
+ */
227
+ export type AgentToolCallWaitingStatus = "awaiting_answer" | "waiting_for_timer" | "waiting_for_task";
228
+ /** Status of a stored tool call record: an {@link AgentToolCallStatus} or an {@link AgentToolCallWaitingStatus}. */
229
+ export type AgentToolCallRecordStatus = AgentToolCallStatus | AgentToolCallWaitingStatus;
230
+ /**
231
+ * How a question that a tool or its task asked was resolved.
232
+ *
233
+ * - `answered`: the user answered with `answer_question`.
234
+ * - `declined`: the user declined with `resolve_interrupt` and `approved` `false`.
235
+ * - `deadline_passed`: `interruptDeadlineMs` passed first.
236
+ *
237
+ * A tool's own question is only ever answered: a decline or a passed deadline ends the call with
238
+ * `rejected`. A question that a started task asked through {@link AgentFrameworkRunner.pollToolTask}
239
+ * goes back to the task in every case, so the task, not the session, decides what a decline means.
240
+ */
241
+ export type QuestionResolution = "answered" | "declined" | "deadline_passed";
242
+ /**
243
+ * How one question that a tool asked by returning {@link ToolInputRequested} was resolved.
244
+ *
245
+ * `AwaitQuestionAnswer` appends one to the call's `inputAnswers` when the user answers. The tool then
246
+ * runs again and receives every answer in {@link DeferredToolExecution.inputAnswers}. For a question that
247
+ * a started task asked, it also appends one when the user declines or the deadline passes, and
248
+ * `PollToolTask` hands it to the task as {@link ToolTaskPoll.pendingAnswer}.
249
+ */
250
+ export interface QuestionAnswer {
251
+ /** Interrupt ID of the resolved question, `<toolCallId>-input-<n>`. Wire field: `interrupt_id`. */
252
+ readonly interruptId: string;
253
+ /** Question text the tool asked. Wire field: `question`. */
254
+ readonly question: string;
255
+ /**
256
+ * The user's answer, exactly as sent to `answer_question`. For a declined question, the user's rejection
257
+ * message or {@link defaultQuestionDeclinedToolResult}; for a passed deadline, {@link questionDeadlinePassed}.
258
+ * Wire field: `answer`.
259
+ */
260
+ readonly answer: string;
261
+ /**
262
+ * How the question was resolved; `answered` when absent, the only resolution of a tool's own question.
263
+ * Answers the session reads always carry it; it is optional so that code that builds answers by hand keeps
264
+ * compiling. Wire field: `resolution`.
265
+ */
266
+ readonly resolution?: QuestionResolution;
267
+ }
268
+ /** Durable record of one deferred tool call, as a runner sees it; stored in `AgentToolCalls` under its tool call ID. */
92
269
  export interface AgentToolCall {
93
270
  /** Framework tool call ID; non-empty and slash-free. Wire field: `tool_call_id`. */
94
271
  readonly toolCallId: string;
@@ -108,7 +285,8 @@ export interface AgentToolCall {
108
285
  readonly output: string | null;
109
286
  /**
110
287
  * The `ToolExecutionError` message, or the failed Step's recovery detail, after `failed` or
111
- * `outcome_unknown`; otherwise `null`. Wire field: `error`.
288
+ * `outcome_unknown`; otherwise `null`. Wire field: `error`. A tool Step that failed before the tool
289
+ * ran records `failed` with {@link toolCallNotRunErrorPrefix}, `": "`, and the recovery detail.
112
290
  */
113
291
  readonly error: string | null;
114
292
  /** Rejection text after `rejected`, otherwise `null`. Wire field: `rejection_message`. */
@@ -118,30 +296,195 @@ export interface AgentToolCall {
118
296
  * It extends the planned contract, as in the Python core. Wire field: `deferral_order`.
119
297
  */
120
298
  readonly deferralOrder: number;
299
+ /**
300
+ * {@link DeferredToolCall.toolSourceReference}: opaque text the tool's source stored with the call,
301
+ * absent when it stored none. Wire field: `tool_source_reference`, `null` when absent.
302
+ */
303
+ readonly toolSourceReference?: string;
304
+ /**
305
+ * W3C `traceparent` of the activation root that the call's `execute_tool` spans join; absent when
306
+ * none recorded. The session sets it when `RunModel` defers the call and again when an approval
307
+ * starts a new activation, so parallel activations never swap tool spans. Wire field:
308
+ * `trace_context`, `null` when absent.
309
+ */
310
+ readonly traceContext?: string;
311
+ /**
312
+ * RFC 3339 time at which a `durable_wait` call's Timer ends, otherwise `null`. Wire field: `wait_until`.
313
+ *
314
+ * Records the session reads always carry this field. It is optional only so that code that builds
315
+ * records by hand, such as a unit test, keeps compiling.
316
+ */
317
+ readonly waitUntil?: string | null;
318
+ /**
319
+ * Opaque text from the tool's last {@link ToolInputRequested}, returned to the tool when it runs
320
+ * again after the answer. For a call waiting for a task, the continuation of the task's last question
321
+ * until the next poll, and then what the last {@link ToolTaskPending} returned. `null` when there is none.
322
+ * Wire field: `input_continuation`. Optional for the same reason as {@link waitUntil}.
323
+ */
324
+ readonly inputContinuation?: string | null;
325
+ /**
326
+ * Answers to the questions the tool asked through {@link ToolInputRequested}, oldest first; empty
327
+ * for other calls. Wire field: `input_answers`. Optional for the same reason as {@link waitUntil}.
328
+ */
329
+ readonly inputAnswers?: readonly QuestionAnswer[];
330
+ /**
331
+ * Question text of the tool's pending {@link ToolInputRequested} while the record is
332
+ * `awaiting_answer`, otherwise `null`. It is `null` for an `ask_user` call, whose question is in
333
+ * {@link arguments}. `AwaitQuestionAnswer` raises the question interrupt from it under the
334
+ * `PendingInterrupts` lock. Wire field: `input_question`. Optional for the same reason as
335
+ * {@link waitUntil}.
336
+ */
337
+ readonly inputQuestion?: string | null;
338
+ /**
339
+ * Choices of that pending {@link ToolInputRequested}; empty for a free-text question or when no tool
340
+ * question is pending. Wire field: `input_choices`. Optional for the same reason as {@link waitUntil}.
341
+ */
342
+ readonly inputChoices?: readonly string[];
343
+ /**
344
+ * Whether that pending {@link ToolInputRequested} accepts free text; `true` when no tool question is
345
+ * pending. Wire field: `input_allows_free_text`. Optional for the same reason as {@link waitUntil}.
346
+ */
347
+ readonly inputAllowsFreeText?: boolean;
348
+ /**
349
+ * Why steering or `cancel_turn` abandoned the call before it started, on a `rejected` record;
350
+ * otherwise `null`. Wire field: `cancellation_reason`. Optional for the same reason as
351
+ * {@link waitUntil}.
352
+ */
353
+ readonly cancellationReason?: ToolCallCancellationReason | null;
354
+ /**
355
+ * The remote task ID from the tool's {@link ToolTaskStarted}, or `null` for a call that started no
356
+ * task. It stays on the record after the task finishes. Wire field: `task_id`. Optional for the same
357
+ * reason as {@link waitUntil}.
358
+ */
359
+ readonly taskId?: string | null;
360
+ /**
361
+ * Whole seconds `PollToolTask` waits before the next poll, at least 1, from {@link ToolTaskStarted} or
362
+ * the last {@link ToolTaskPending}; `null` for a call that started no task. Wire field:
363
+ * `task_poll_interval_seconds`. Optional for the same reason as {@link waitUntil}.
364
+ */
365
+ readonly taskPollIntervalSeconds?: number | null;
366
+ /**
367
+ * Whether the last entry of {@link inputAnswers}, the resolution of the task's last question, has not
368
+ * reached the task yet. `AwaitQuestionAnswer` sets it, `PollToolTask` then polls at once and hands that
369
+ * entry to the runner, and the poll's commit clears it. Wire field: `task_answer_pending`. Optional for
370
+ * the same reason as {@link waitUntil}.
371
+ */
372
+ readonly taskAnswerPending?: boolean;
121
373
  }
122
- /** One pending approval request, stored in the `PendingInterrupts` Attribute. */
374
+ /**
375
+ * Why steering or cancellation abandoned a tool call before it started.
376
+ *
377
+ * - `steered`: `steer_user_message` superseded the turn.
378
+ * - `turn_cancelled`: `cancel_turn` stopped the turn.
379
+ *
380
+ * A `rejected` record carries one in {@link AgentToolCall.cancellationReason}; its `rejectionMessage` is
381
+ * {@link toolCallCancelledBySteeringResult} or {@link toolCallCancelledByTurnCancellationResult}.
382
+ */
383
+ export type ToolCallCancellationReason = "steered" | "turn_cancelled";
384
+ /**
385
+ * A stored tool call record, as `get_agent_snapshot` and `Client.getAttributes` return it.
386
+ *
387
+ * It is an {@link AgentToolCall} whose status may also be an {@link AgentToolCallWaitingStatus}, and
388
+ * whose fields added in 0.2.0 are always present.
389
+ */
390
+ export interface AgentToolCallRecord extends Omit<AgentToolCall, "status" | "waitUntil" | "inputContinuation" | "inputAnswers" | "inputQuestion" | "inputChoices" | "inputAllowsFreeText" | "cancellationReason" | "taskId" | "taskPollIntervalSeconds" | "taskAnswerPending"> {
391
+ /** Current status. Wire field: `status`. */
392
+ readonly status: AgentToolCallRecordStatus;
393
+ /** See {@link AgentToolCall.waitUntil}. Wire field: `wait_until`. */
394
+ readonly waitUntil: string | null;
395
+ /** See {@link AgentToolCall.inputContinuation}. Wire field: `input_continuation`. */
396
+ readonly inputContinuation: string | null;
397
+ /** See {@link AgentToolCall.inputAnswers}. Wire field: `input_answers`. */
398
+ readonly inputAnswers: readonly QuestionAnswer[];
399
+ /** See {@link AgentToolCall.inputQuestion}. Wire field: `input_question`. */
400
+ readonly inputQuestion: string | null;
401
+ /** See {@link AgentToolCall.inputChoices}. Wire field: `input_choices`. */
402
+ readonly inputChoices: readonly string[];
403
+ /** See {@link AgentToolCall.inputAllowsFreeText}. Wire field: `input_allows_free_text`. */
404
+ readonly inputAllowsFreeText: boolean;
405
+ /**
406
+ * See {@link AgentToolCall.cancellationReason}. Wire field: `cancellation_reason`. Records the session reads
407
+ * always carry it; it is optional so that code that builds records by hand keeps compiling.
408
+ */
409
+ readonly cancellationReason?: ToolCallCancellationReason | null;
410
+ /**
411
+ * See {@link AgentToolCall.taskId}. Wire field: `task_id`. Records the session reads always carry it; it is
412
+ * optional so that code that builds records by hand keeps compiling, and a missing value means `null`.
413
+ */
414
+ readonly taskId?: string | null;
415
+ /**
416
+ * See {@link AgentToolCall.taskPollIntervalSeconds}. Wire field: `task_poll_interval_seconds`. Optional for
417
+ * the same reason as {@link taskId}; a missing value means `null`.
418
+ */
419
+ readonly taskPollIntervalSeconds?: number | null;
420
+ /**
421
+ * See {@link AgentToolCall.taskAnswerPending}. Wire field: `task_answer_pending`. Optional for the same
422
+ * reason as {@link taskId}; a missing value means `false`.
423
+ */
424
+ readonly taskAnswerPending?: boolean;
425
+ }
426
+ /**
427
+ * Kind of one {@link AgentInterrupt}.
428
+ *
429
+ * - `tool_approval`: a tool call waits for approval. Answer it with `resolve_interrupt`.
430
+ * - `question`: the model, through `ask_user`, or a tool, through {@link ToolInputRequested}, asked the
431
+ * user a question. Answer it with `answer_question`, or decline it with `resolve_interrupt` and
432
+ * `approved` `false`.
433
+ */
434
+ export type AgentInterruptKind = "tool_approval" | "question";
435
+ /** One pending approval or question, stored in the `PendingInterrupts` Attribute. */
123
436
  export interface AgentInterrupt {
124
- /** Interrupt ID; equals the tool call ID for tool approvals. Wire field: `interrupt_id`. */
437
+ /**
438
+ * Interrupt ID passed to `resolve_interrupt` or `answer_question`. It equals the tool call ID for a
439
+ * tool approval and an `ask_user` question, and is `<toolCallId>-input-<n>` for the `n`-th question a
440
+ * tool asked through {@link ToolInputRequested}. Wire field: `interrupt_id`.
441
+ */
125
442
  readonly interruptId: string;
126
443
  /** Interrupt kind. Wire field: `kind`. */
127
- readonly kind: "tool_approval";
128
- /** Tool call awaiting approval. Wire field: `tool_call_id`. */
444
+ readonly kind: AgentInterruptKind;
445
+ /** Tool call that waits. Wire field: `tool_call_id`. */
129
446
  readonly toolCallId: string;
130
- /** Tool name. Wire field: `tool_name`. */
447
+ /** Tool name; `ask_user` for an `ask_user` question. Wire field: `tool_name`. */
131
448
  readonly toolName: string;
132
449
  /** Tool arguments as JSON text. Wire field: `arguments`. */
133
450
  readonly arguments: string;
134
451
  /** RFC 3339 time at which the interrupt was raised. Wire field: `created_at`. */
135
452
  readonly createdAt: string;
136
- /** RFC 3339 approval deadline, or `null` for no deadline. Wire field: `deadline`. */
453
+ /**
454
+ * RFC 3339 deadline, or `null` for no deadline. After it, the session rejects the call with
455
+ * {@link approvalDeadlinePassed} or {@link questionDeadlinePassed}. Wire field: `deadline`.
456
+ */
137
457
  readonly deadline: string | null;
458
+ /**
459
+ * Question text of a `question` interrupt, otherwise `null`. Wire field: `question`.
460
+ *
461
+ * Interrupts the session reads always carry this field and the two below. They are optional only so
462
+ * that code written against 0.1.0, which builds interrupts by hand, keeps compiling; treat `undefined`
463
+ * as `null`, an empty list, and `true`.
464
+ */
465
+ readonly question?: string | null;
466
+ /** Answers to offer for a `question` interrupt; empty for a free-text question. Wire field: `choices`. */
467
+ readonly choices?: readonly string[];
468
+ /**
469
+ * Whether `answer_question` accepts an answer that is not one of {@link choices}. Always `true` when
470
+ * `choices` is empty and for a tool approval. Wire field: `allows_free_text`.
471
+ */
472
+ readonly allowsFreeText?: boolean;
138
473
  }
139
474
  /** Resolution of one interrupt, published to the `InterruptResolutions` ChannelMap. */
140
475
  export interface AgentInterruptResolution {
141
- /** Whether the tool call may run. Wire field: `approved`. */
476
+ /**
477
+ * Whether the tool call may run, or, for a question, whether the user answered it. Wire field:
478
+ * `approved`.
479
+ */
142
480
  readonly approved: boolean;
143
- /** Text shown to the model when rejected, or `null`. Wire field: `rejection_message`. */
481
+ /** Text shown to the model when rejected or declined, or `null`. Wire field: `rejection_message`. */
144
482
  readonly rejectionMessage: string | null;
483
+ /**
484
+ * The answer to a `question` interrupt, otherwise `null`. Wire field: `answer`. Resolutions the
485
+ * session reads always carry it; it is optional so that 0.1.0 code keeps compiling.
486
+ */
487
+ readonly answer?: string | null;
145
488
  }
146
489
  /**
147
490
  * Model usage counters, stored cumulatively in the `AgentUsage` Attribute.
@@ -170,10 +513,120 @@ export interface ToolCallCompleted {
170
513
  /** Tool call whose record is final. Wire field: `tool_call_id`. */
171
514
  readonly toolCallId: string;
172
515
  }
173
- /** One user message, the input of the `send_user_message` RPC and the `QueuedUserMessages` Channel value. */
516
+ /**
517
+ * One user message, the input of the `send_user_message` RPC and the value of the `QueuedUserMessages` and
518
+ * `SteeredUserMessages` Channels.
519
+ */
174
520
  export interface AgentUserMessage {
175
521
  /** Message text. Blank text is rejected. Wire field: `text`. */
176
522
  readonly text: string;
523
+ /**
524
+ * Whether the message starts a `planning` turn, which drafts a plan for review instead of doing the work.
525
+ * `send_user_message` rejects it unless {@link AgentSessionOptions.planModeEnabled} is set. Wire field:
526
+ * `plan_mode`, `false` by default; a decoded message omits it when `false`, and `null` reads as `false`.
527
+ */
528
+ readonly planMode?: boolean;
529
+ }
530
+ /**
531
+ * One user message that waits in `QueuedUserMessages` or `SteeredUserMessages`, as `get_agent_snapshot` lists it,
532
+ * so a UI can delete or steer a queued message by its ID.
533
+ */
534
+ export interface PendingUserMessage {
535
+ /** Channel message ID that Dex assigned when the message was published. Wire field: `message_id`. */
536
+ readonly messageId: string;
537
+ /** The user message. Wire field: `message`. */
538
+ readonly message: AgentUserMessage;
539
+ }
540
+ /**
541
+ * Input of the `steer_user_message` RPC. Set exactly one field: `messageId` moves a queued message, and `text`
542
+ * sends a new one.
543
+ *
544
+ * @example
545
+ * ```ts
546
+ * await client.invokeRPC(flow.steerUserMessage, sessionId, { messageId: null, text: "Use staging instead" });
547
+ * const [queued] = (await client.invokeRPC(flow.getAgentSnapshot, sessionId)).queuedMessages ?? [];
548
+ * if (queued !== undefined) {
549
+ * await client.invokeRPC(flow.steerUserMessage, sessionId, { messageId: queued.messageId, text: null });
550
+ * }
551
+ * ```
552
+ */
553
+ export interface SteerUserMessageRequest {
554
+ /** {@link PendingUserMessage.messageId} of a queued message, or `null`. Wire field: `message_id`. */
555
+ readonly messageId: string | null;
556
+ /** Text of a new steered message, or `null`. Wire field: `text`. */
557
+ readonly text: string | null;
558
+ }
559
+ /** Input of the `delete_queued_message` RPC. */
560
+ export interface DeleteQueuedMessageRequest {
561
+ /** {@link PendingUserMessage.messageId} of a queued message. Wire field: `message_id`. */
562
+ readonly messageId: string;
563
+ }
564
+ /** Input of the `cancel_turn` RPC. */
565
+ export interface CancelTurnRequest {
566
+ /**
567
+ * The turn to stop, or `null` for whichever turn is active. A turn ID that is not the active turn makes the
568
+ * RPC return `false`. Wire field: `turn_id`.
569
+ */
570
+ readonly turnId: string | null;
571
+ }
572
+ /**
573
+ * Input of the `update_session_settings` RPC, which replaces the session's settings from the next turn on.
574
+ *
575
+ * @example
576
+ * ```ts
577
+ * await client.invokeRpc(flow.updateSessionSettings, "session-42", { sessionSettings: { model: "gpt-5" } });
578
+ * ```
579
+ */
580
+ export interface UpdateSessionSettingsRequest {
581
+ /**
582
+ * The complete new {@link SessionSettings}. They replace the old settings; nothing is merged, and `{}` clears
583
+ * them. Never put a secret in them. `null`, which a missing field also decodes to, makes the RPC return
584
+ * `false` and change nothing. Wire field: `session_settings`.
585
+ */
586
+ readonly sessionSettings: SessionSettings | null;
587
+ }
588
+ /**
589
+ * The settings one turn started with, stored in the `TurnSessionSettings` Attribute.
590
+ *
591
+ * The Step that starts a turn writes it in the commit that starts the turn. The session reads it only while
592
+ * {@link turnId} is `AgentState.activeTurnId`, so a copy an earlier turn left, such as when a Worker without
593
+ * session settings started the current turn, reads as no settings.
594
+ */
595
+ export interface TurnSessionSettings {
596
+ /** Turn ID of the turn that started with these settings. Wire field: `turn_id`. */
597
+ readonly turnId: string;
598
+ /** The settings, a non-empty JSON object. Wire field: `session_settings`. */
599
+ readonly sessionSettings: SessionSettings;
600
+ }
601
+ /** Name of the RPC that published one {@link TurnControlRequest}. */
602
+ export type TurnControlKind = "steer" | "cancel_turn";
603
+ /**
604
+ * Wake-up of a waiting session Step, published to the internal `TurnControlRequests` Channel by
605
+ * `steer_user_message` and `cancel_turn`. The session decides from `SteeredUserMessages` and
606
+ * `TurnCancellationRequest`, not from this message.
607
+ */
608
+ export interface TurnControlRequest {
609
+ /** The RPC that published it. Wire field: `kind`. */
610
+ readonly kind: TurnControlKind;
611
+ }
612
+ /**
613
+ * The latest `cancel_turn` request, stored in the `TurnCancellationRequest` Attribute. A turn is cancelled while
614
+ * `turnId` equals `AgentState.activeTurnId`. Turn IDs never repeat, so a request for an earlier turn never matches.
615
+ */
616
+ export interface TurnCancellationRequest {
617
+ /** The turn to stop. Wire field: `turn_id`. */
618
+ readonly turnId: string;
619
+ /** RFC 3339 time of the request. Wire field: `requested_at`. */
620
+ readonly requestedAt: string;
621
+ }
622
+ /**
623
+ * Wake-up of the Step that waits on one tool call, published by `ResumeTurn` to the internal
624
+ * `ToolCallCancellations` ChannelMap instance named by the tool call ID. The waiting Step decides from the
625
+ * session's flags, not from this message.
626
+ */
627
+ export interface ToolCallCancellation {
628
+ /** Why the turn ends. Wire field: `reason`. */
629
+ readonly reason: ToolCallCancellationReason;
177
630
  }
178
631
  /**
179
632
  * Standard type of one {@link AgentEvent}. Adapters may write other types with an adapter prefix.
@@ -182,18 +635,37 @@ export interface AgentUserMessage {
182
635
  * - `turn_started`: `{"sequence"}`, the sequence of the user message that started the turn.
183
636
  * - `turn_completed`: `{"message_count"}`, the number of messages the turn appended.
184
637
  * - `turn_failed`: `{"error"}`.
638
+ * - `turn_steered`: `{"steered_message_count","message_count"}`, when steering ended the turn before its final
639
+ * answer: the steered messages that start the next turn, and the messages the ended turn appended. Treat it
640
+ * like `turn_completed`.
641
+ * - `turn_cancelled`: `{"message_count"}`, when `cancel_turn` ended the turn before its final answer. Treat it
642
+ * like `turn_completed`.
185
643
  * - `text_delta` and `reasoning_delta`: `{"text"}`.
186
644
  * - `tool_call_started`: `{"tool_call_id","tool_name"}`.
187
645
  * - `tool_call_finished`: `{"tool_call_id","tool_name","status"}`, when a record becomes final,
188
646
  * including a rejection.
189
647
  * - `tool_call_deferred`: `{"tool_call_id","tool_name","effect","requires_approval"}`, when the model
190
- * asks for a call, which then runs in its own Step.
191
- * - `interrupt_raised`: `{"interrupt_id","tool_call_id","tool_name","deadline"}`.
192
- * - `interrupt_resolved`: `{"interrupt_id","approved","rejection_message"}`.
648
+ * asks for a call, which then runs in its own Step or, for a built-in tool, waits in the session.
649
+ * - `interrupt_raised`: `{"interrupt_id","kind","tool_call_id","tool_name","deadline","question",
650
+ * "choices","allows_free_text"}`. For a tool approval, `question` is `null`, `choices` is empty, and
651
+ * `allows_free_text` is `true`.
652
+ * - `interrupt_resolved`: `{"interrupt_id","kind","approved","answered","rejection_message",
653
+ * "cancellation_reason"}`. `answered` is `true` only for an answered question. `cancellation_reason`
654
+ * is `"steered"` or `"turn_cancelled"` when steering or `cancel_turn` abandoned the call, otherwise `null`.
655
+ * - `timer_started`: `{"tool_call_id","wait_until","reason"}`, when a `durable_wait` call starts its Timer.
656
+ * - `plan_updated`: `{"revision","status","task_count"}`, when `write_todos` replaced the plan or an
657
+ * approval marked a draft `active`.
658
+ * - `plan_execution_started`: `{"revision"}`, after the `turn_started` of an `executing` turn.
659
+ * - `tool_task_started`: `{"tool_call_id","tool_name","task_id"}`, when a tool starts remote work that
660
+ * `PollToolTask` polls.
193
661
  * - `usage_recorded`: `{"recorded","session"}`: one model call's and the cumulative usage, each with
194
662
  * {@link AgentUsage} wire fields.
663
+ * - `compaction_started`: `{"through_sequence"}`, when `CompactContext` starts summarizing the messages
664
+ * through that sequence. A retried attempt writes it again.
665
+ * - `compaction_finished`: `{"generation","through_sequence"}`, when `CompactContext` wrote a
666
+ * {@link ContextSummary}.
195
667
  */
196
- export type AgentEventType = "turn_started" | "turn_completed" | "turn_failed" | "text_delta" | "reasoning_delta" | "tool_call_started" | "tool_call_finished" | "tool_call_deferred" | "interrupt_raised" | "interrupt_resolved" | "usage_recorded";
668
+ export type AgentEventType = "turn_started" | "turn_completed" | "turn_failed" | "turn_steered" | "turn_cancelled" | "text_delta" | "reasoning_delta" | "tool_call_started" | "tool_call_finished" | "tool_call_deferred" | "interrupt_raised" | "interrupt_resolved" | "timer_started" | "plan_updated" | "plan_execution_started" | "tool_task_started" | "usage_recorded" | "compaction_started" | "compaction_finished";
197
669
  /** One best-effort live event, written to the `AgentEvents` Stream. */
198
670
  export interface AgentEvent {
199
671
  /** An {@link AgentEventType} or an adapter-specific type such as `"vercel_ai.step"`. Wire field: `type`. */
@@ -209,8 +681,8 @@ export interface AgentEvent {
209
681
  * Group live text by `(turnId, stepExecutionId, attempt)`. Within one `stepExecutionId`, keep only the
210
682
  * events of the highest `attempt` seen and drop the partial text of lower attempts. Different
211
683
  * `stepExecutionId` values of one turn are its model calls and tool Steps, and each keeps its
212
- * own events. After `turn_completed` or `turn_failed`, replace the turn's live text with the stored
213
- * messages.
684
+ * own events. After `turn_completed`, `turn_failed`, `turn_steered`, or `turn_cancelled`, replace the
685
+ * turn's live text with the stored messages.
214
686
  */
215
687
  readonly stepExecutionId: string;
216
688
  /** Event payload as JSON text. Wire field: `payload`. */
@@ -225,6 +697,134 @@ export interface ResolveInterruptInput {
225
697
  /** Text shown to the model when rejected, or `null`. Wire field: `rejection_message`. */
226
698
  readonly rejectionMessage: string | null;
227
699
  }
700
+ /**
701
+ * Input of the `answer_question` RPC.
702
+ *
703
+ * @example
704
+ * ```ts
705
+ * const question = snapshot.pendingInterrupts.find((interrupt) => interrupt.kind === "question");
706
+ * if (question !== undefined) {
707
+ * await client.invokeRPC(flow.answerQuestion, sessionId, {
708
+ * interruptId: question.interruptId, answer: question.choices[0] ?? "yes" });
709
+ * }
710
+ * ```
711
+ */
712
+ export interface AnswerQuestionRequest {
713
+ /** {@link AgentInterrupt.interruptId} of a pending `question` interrupt. Wire field: `interrupt_id`. */
714
+ readonly interruptId: string;
715
+ /**
716
+ * The answer. It must not be blank. When the interrupt has `choices` and `allowsFreeText` is `false`,
717
+ * it must equal one of the choices exactly. Wire field: `answer`.
718
+ */
719
+ readonly answer: string;
720
+ }
721
+ /**
722
+ * The summary that replaces a session's earlier messages in the model input, stored in the
723
+ * `ContextSummary` Attribute.
724
+ *
725
+ * Only `CompactContext` writes it, in a session with {@link AgentSessionOptions.compaction}. Each new
726
+ * summary folds in the previous one, so it always covers the messages from {@link firstSequence}
727
+ * through {@link lastSequence}. The summarized messages stay stored, and `list_agent_messages` and
728
+ * `get_agent_snapshot` return them, until retention deletes whole archive chunks of them; see
729
+ * `AgentSessionOptions.retainedMessageLimit`. Only the model input changes.
730
+ *
731
+ * @example
732
+ * ```ts
733
+ * const snapshot = await client.invokeRPC(flow.getAgentSnapshot, sessionId);
734
+ * const summarizedThrough = snapshot.contextSummary?.lastSequence ?? 0;
735
+ * ```
736
+ */
737
+ export interface ContextSummary {
738
+ /** Count of summaries the session has written, starting at 1. Wire field: `generation`. */
739
+ readonly generation: number;
740
+ /** Sequence of the first summarized message; always 1. Wire field: `first_sequence`. */
741
+ readonly firstSequence: number;
742
+ /**
743
+ * Sequence of the last summarized message. A runner with the compaction capability receives only the
744
+ * messages after it. Wire field: `last_sequence`.
745
+ */
746
+ readonly lastSequence: number;
747
+ /** Summary text from the runner's `summarizeContext`. Wire field: `text`. */
748
+ readonly text: string;
749
+ /** RFC 3339 time at which `CompactContext` wrote the summary. Wire field: `created_at`. */
750
+ readonly createdAt: string;
751
+ }
752
+ /**
753
+ * One immutable archive chunk of the `AgentMessageChunks` AttributeMap.
754
+ *
755
+ * When the `AgentMessages` window grows past `AgentSessionOptions.messageWindowSize`, its oldest messages
756
+ * move into chunks of at most `messageChunkSize` messages and `messageChunkMaxBytes` bytes, each keyed by
757
+ * `messageSequenceKey` of its first sequence. A chunk is never rewritten. Retention deletes a whole chunk.
758
+ */
759
+ export interface AgentMessageChunk {
760
+ /**
761
+ * The chunk's messages with consecutive sequences, oldest first: the range its
762
+ * {@link AgentMessageChunkRange} names. Wire field: `messages`.
763
+ */
764
+ readonly messages: readonly AgentMessage[];
765
+ }
766
+ /** The sequences one `AgentMessageChunks` instance holds, as {@link AgentMessageIndex.chunks} lists it. */
767
+ export interface AgentMessageChunkRange {
768
+ /** Sequence of the chunk's first message; the instance key is `messageSequenceKey` of it. Wire field: `first_sequence`. */
769
+ readonly firstSequence: number;
770
+ /** Sequence of the chunk's last message. Wire field: `last_sequence`. */
771
+ readonly lastSequence: number;
772
+ }
773
+ /**
774
+ * Where a session's messages are stored, held in the `AgentMessageIndex` Attribute.
775
+ *
776
+ * Messages from {@link windowFirstSequence} on are in the `AgentMessages` window, one instance per message.
777
+ * Earlier ones, from {@link firstSequence}, are in the `AgentMessageChunks` instances that {@link chunks}
778
+ * lists. A chunk holds at most `messageChunkSize` messages and at most `messageChunkMaxBytes` bytes, except
779
+ * that a larger message gets a chunk of its own. A session that a 0.1.0 Worker wrote has no index: every
780
+ * message is in `AgentMessages` until the session's writes on this version move them, a few chunks per
781
+ * commit.
782
+ *
783
+ * @example
784
+ * ```ts
785
+ * const [index] = await client.getAttributes(sessionId, flow.agentMessageIndex);
786
+ * const oldestStored = index?.firstSequence ?? 1;
787
+ * const chunk = index?.chunks.find((range) => range.firstSequence <= 7 && 7 <= range.lastSequence);
788
+ * ```
789
+ */
790
+ export interface AgentMessageIndex {
791
+ /**
792
+ * Every kept chunk, oldest first, without overlaps. The archived ones, before `windowFirstSequence`, are
793
+ * contiguous from `firstSequence`. A chunk at or after `windowFirstSequence` holds one message that was too
794
+ * large for the window, stored straight into its own chunk. Wire field: `chunks`.
795
+ */
796
+ readonly chunks: readonly AgentMessageChunkRange[];
797
+ /**
798
+ * Sequence of the oldest stored message: the first archived chunk's first sequence, or `windowFirstSequence`
799
+ * when no archived chunk is kept. Retention deleted every earlier message. Wire field: `first_sequence`.
800
+ */
801
+ readonly firstSequence: number;
802
+ /** Sequence of the first message in the `AgentMessages` window. Wire field: `window_first_sequence`. */
803
+ readonly windowFirstSequence: number;
804
+ }
805
+ /**
806
+ * Where the replies of a turn start: the value of the `TurnReplySequence` Attribute.
807
+ *
808
+ * The Step that starts a turn writes it, so the turn's `turn_completed`, `turn_steered`, and `turn_cancelled`
809
+ * events count the turn's messages after its user messages without reading them. A value for another turn,
810
+ * such as one a 0.1.0 Worker started, is ignored.
811
+ */
812
+ export interface TurnReplySequence {
813
+ /** `"turn-<n>"` of the turn. Wire field: `turn_id`. */
814
+ readonly turnId: string;
815
+ /** First sequence after the user messages that started the turn. Wire field: `sequence`. */
816
+ readonly sequence: number;
817
+ }
818
+ /**
819
+ * Input of the `CompactContext` Step: the last message to summarize.
820
+ *
821
+ * `RunModel` moves to `CompactContext` with it when the next model input would cross the compaction
822
+ * threshold.
823
+ */
824
+ export interface CompactContextInput {
825
+ /** Sequence of the last message to summarize, after the current summary's. Wire field: `through_sequence`. */
826
+ readonly throughSequence: number;
827
+ }
228
828
  /** Output of the `get_agent_snapshot` RPC, enough for a UI to rebuild its view. */
229
829
  export interface AgentSnapshot {
230
830
  /** Current session state, or `null` before `StartAgentSession` committed. Wire field: `state`. */
@@ -234,11 +834,36 @@ export interface AgentSnapshot {
234
834
  /** Interrupts that `resolve_interrupt` still accepts. Wire field: `pending_interrupts`. */
235
835
  readonly pendingInterrupts: readonly AgentInterrupt[];
236
836
  /** Deferred tool call records of the active turn, in deferral order. Wire field: `tool_calls`. */
237
- readonly toolCalls: readonly AgentToolCall[];
837
+ readonly toolCalls: readonly AgentToolCallRecord[];
238
838
  /** Cumulative usage. Wire field: `usage`. */
239
839
  readonly usage: AgentUsage;
240
840
  /** User messages queued and not yet consumed. Wire field: `queued_message_count`. */
241
841
  readonly queuedMessageCount: number;
842
+ /**
843
+ * The {@link AgentPlan}, or absent before `write_todos` first succeeded. Wire field: `plan`, `null` while
844
+ * there is none; a decoded snapshot omits it then, like the other fields plans added.
845
+ */
846
+ readonly plan?: AgentPlan | null;
847
+ /**
848
+ * Those queued messages with their Channel message IDs, oldest first; pass an ID to `delete_queued_message` or
849
+ * `steer_user_message`. Wire field: `queued_messages`. Snapshots the session returns always carry it and the
850
+ * field below; they are optional so that 0.1.0 code that builds snapshots keeps compiling.
851
+ */
852
+ readonly queuedMessages?: readonly PendingUserMessage[];
853
+ /** Steered messages the session has not applied yet, oldest first. Wire field: `steered_messages`. */
854
+ readonly steeredMessages?: readonly PendingUserMessage[];
855
+ /**
856
+ * The current {@link ContextSummary}, or `null` when the session never compacted; {@link messages}
857
+ * still holds the summarized messages. Wire field: `context_summary`. The RPC always sets it; it is
858
+ * optional so that 0.1.0 code that builds a snapshot keeps compiling.
859
+ */
860
+ readonly contextSummary?: ContextSummary | null;
861
+ /**
862
+ * The `SessionSettings` Attribute: the settings the next turn starts with, or `null` when the session has
863
+ * none. The active turn may still run with the settings it started with. Wire field: `session_settings`. The
864
+ * RPC always sets it; it is optional so that 0.1.0 code that builds a snapshot keeps compiling.
865
+ */
866
+ readonly sessionSettings?: SessionSettings | null;
242
867
  }
243
868
  /** Input of the `list_agent_messages` RPC. */
244
869
  export interface ListAgentMessagesInput {
@@ -256,6 +881,12 @@ export interface AgentMessagesPage {
256
881
  * Wire field: `next_before_sequence`.
257
882
  */
258
883
  readonly nextBeforeSequence: number | null;
884
+ /**
885
+ * The oldest stored sequence when retention deleted every earlier message, or `null` when none was deleted.
886
+ * A page whose `nextBeforeSequence` is `null` reaches the start of the conversation only when this is
887
+ * `null` too. Absent in a page a 0.1.0 Worker returned. Wire field: `deleted_before_sequence`.
888
+ */
889
+ readonly deletedBeforeSequence?: number | null;
259
890
  }
260
891
  /**
261
892
  * Returns usage with every counter at zero.
@@ -281,9 +912,9 @@ export declare function addAgentUsage(left: AgentUsage, right: AgentUsage): Agen
281
912
  *
282
913
  * @param status - Status to classify.
283
914
  * @returns `true` for `rejected`, `succeeded`, `failed`, and `outcome_unknown`; `false` for
284
- * `awaiting_approval` and `approved`.
915
+ * `awaiting_approval`, `approved`, and every {@link AgentToolCallWaitingStatus}.
285
916
  */
286
- export declare function isFinalToolCallStatus(status: AgentToolCallStatus): boolean;
917
+ export declare function isFinalToolCallStatus(status: AgentToolCallRecordStatus): boolean;
287
918
  /** Tool result text the model sees for an `outcome_unknown` call; the same text as the Python core. */
288
919
  export declare const outcomeUnknownToolResult: string;
289
920
  /** First line of the note `RecordTurnFailure` stores after a failed turn ran tools. */
@@ -294,6 +925,34 @@ export declare const turnFailureNoteFooter = "Do not repeat these tool calls unl
294
925
  export declare const defaultRejectionToolResult = "The user rejected this tool call.";
295
926
  /** Rejection message recorded when an approval deadline passes. */
296
927
  export declare const approvalDeadlinePassed = "approval deadline passed";
928
+ /** Rejection message recorded when a question's deadline passes. */
929
+ export declare const questionDeadlinePassed = "question deadline passed";
930
+ /** Tool result text the model sees when the user declines a question without a message, or with an empty one. */
931
+ export declare const defaultQuestionDeclinedToolResult = "The user declined to answer.";
932
+ /** First line of the note `ApplyTurnControl` stores after a steered turn ran tools. */
933
+ export declare const turnSteeredNoteHeader = "[Dex] The user steered the conversation after these tool calls ran:";
934
+ /** First line of the note `ApplyTurnControl` stores after a cancelled turn ran tools. */
935
+ export declare const turnCancelledNoteHeader = "[Dex] The user stopped the previous turn after these tool calls ran:";
936
+ /** Model-visible result of a tool call that steering abandoned before it started; the same text as the Python core. */
937
+ export declare const toolCallCancelledBySteeringResult = "{\"status\":\"cancelled\",\"reason\":\"superseded_by_steered_user_message\"}";
938
+ /** Model-visible result of a tool call that `cancel_turn` abandoned before it started. */
939
+ export declare const toolCallCancelledByTurnCancellationResult = "{\"status\":\"cancelled\",\"reason\":\"turn_cancelled_by_user\"}";
940
+ /**
941
+ * Error recorded when a tool returns {@link ToolTaskStarted} to a runner without
942
+ * {@link AgentFrameworkRunner.pollToolTask}. The Python core names its method `poll_tool_task`.
943
+ */
944
+ export declare const missingToolTaskPoller = "the tool started a task, but the runner does not implement pollToolTask";
945
+ /** Error recorded when a {@link ToolTaskStarted} has a blank `taskId`; the same text as the Python core. */
946
+ export declare const blankToolTaskId = "the tool started a task without a task ID";
947
+ /** Error recorded when a task's poll interval is not a number; the same text as the Python core. */
948
+ export declare const invalidToolTaskPollInterval = "the tool task's poll interval is not a number";
949
+ /** Error of an `outcome_unknown` record whose task `cancel_turn` abandoned; the same text as the Python core. */
950
+ export declare const toolTaskAbandonedError = "the turn was cancelled while the tool's task was running; the task may have taken effect";
951
+ /**
952
+ * Start of the `error` of a `failed` record whose tool Step certainly never ran the tool; the same text as the
953
+ * Python core.
954
+ */
955
+ export declare const toolCallNotRunErrorPrefix = "the tool did not run, so it is safe to call again";
297
956
  /**
298
957
  * Returns the note text that tells the model what a failed turn already did.
299
958
  *
@@ -313,7 +972,9 @@ export declare const approvalDeadlinePassed = "approval deadline passed";
313
972
  * joined with newlines.
314
973
  * @throws {TypeError} When a record is not final.
315
974
  */
316
- export declare function buildTurnFailureNote(toolCalls: readonly AgentToolCall[]): string;
975
+ export declare function buildTurnFailureNote(toolCalls: readonly (AgentToolCall | AgentToolCallRecord)[]): string;
976
+ /** Returns a note in the turn-failure note's line format with another first line. */
977
+ export declare function buildToolCallNote(header: string, toolCalls: readonly (AgentToolCall | AgentToolCallRecord)[]): string;
317
978
  /**
318
979
  * Returns the tool result text a runner shows the model for a final tool call record.
319
980
  *
@@ -332,6 +993,6 @@ export declare function buildTurnFailureNote(toolCalls: readonly AgentToolCall[]
332
993
  * @returns The output for `succeeded`; `The tool call failed: <error>` for `failed`; the rejection
333
994
  * message, or {@link defaultRejectionToolResult}, for `rejected`; {@link outcomeUnknownToolResult}
334
995
  * for `outcome_unknown`.
335
- * @throws {TypeError} When the record status is `awaiting_approval` or `approved`.
996
+ * @throws {TypeError} When the record status is not final.
336
997
  */
337
- export declare function describeToolCallOutcome(toolCall: AgentToolCall): string;
998
+ export declare function describeToolCallOutcome(toolCall: AgentToolCall | AgentToolCallRecord): string;