@superdurable/dex-agents 0.0.0-stage → 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.
- package/LICENSE +105 -0
- package/README.md +1981 -2
- package/dist/src/agent-built-in-tools.d.ts +81 -0
- package/dist/src/agent-built-in-tools.js +246 -0
- package/dist/src/agent-built-in-tools.js.map +1 -0
- package/dist/src/agent-context-compaction.d.ts +108 -0
- package/dist/src/agent-context-compaction.js +39 -0
- package/dist/src/agent-context-compaction.js.map +1 -0
- package/dist/src/agent-event-writer.d.ts +26 -0
- package/dist/src/agent-event-writer.js +110 -0
- package/dist/src/agent-event-writer.js.map +1 -0
- package/dist/src/agent-framework-runner.d.ts +808 -0
- package/dist/src/agent-framework-runner.js +82 -0
- package/dist/src/agent-framework-runner.js.map +1 -0
- package/dist/src/agent-plans.d.ts +48 -0
- package/dist/src/agent-plans.js +86 -0
- package/dist/src/agent-plans.js.map +1 -0
- package/dist/src/agent-session-cancellation-steps.d.ts +28 -0
- package/dist/src/agent-session-cancellation-steps.js +154 -0
- package/dist/src/agent-session-cancellation-steps.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +105 -0
- package/dist/src/agent-session-codecs.js +689 -0
- package/dist/src/agent-session-codecs.js.map +1 -0
- package/dist/src/agent-session-flow.d.ts +416 -0
- package/dist/src/agent-session-flow.js +623 -0
- package/dist/src/agent-session-flow.js.map +1 -0
- package/dist/src/agent-session-persistence.d.ts +133 -0
- package/dist/src/agent-session-persistence.js +74 -0
- package/dist/src/agent-session-persistence.js.map +1 -0
- package/dist/src/agent-session-settings.d.ts +58 -0
- package/dist/src/agent-session-settings.js +81 -0
- package/dist/src/agent-session-settings.js.map +1 -0
- package/dist/src/agent-session-step-options.d.ts +27 -0
- package/dist/src/agent-session-step-options.js +39 -0
- package/dist/src/agent-session-step-options.js.map +1 -0
- package/dist/src/agent-session-step-types.d.ts +20 -0
- package/dist/src/agent-session-step-types.js +28 -0
- package/dist/src/agent-session-step-types.js.map +1 -0
- package/dist/src/agent-session-steps.d.ts +179 -0
- package/dist/src/agent-session-steps.js +1272 -0
- package/dist/src/agent-session-steps.js.map +1 -0
- package/dist/src/agent-session-tracer.d.ts +61 -0
- package/dist/src/agent-session-tracer.js +608 -0
- package/dist/src/agent-session-tracer.js.map +1 -0
- package/dist/src/agent-session-transitions.d.ts +224 -0
- package/dist/src/agent-session-transitions.js +850 -0
- package/dist/src/agent-session-transitions.js.map +1 -0
- package/dist/src/agent-session-values.d.ts +998 -0
- package/dist/src/agent-session-values.js +162 -0
- package/dist/src/agent-session-values.js.map +1 -0
- package/dist/src/agent-session-wait-steps.d.ts +53 -0
- package/dist/src/agent-session-wait-steps.js +389 -0
- package/dist/src/agent-session-wait-steps.js.map +1 -0
- package/dist/src/agent-tracing-options.d.ts +107 -0
- package/dist/src/agent-tracing-options.js +20 -0
- package/dist/src/agent-tracing-options.js.map +1 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +40 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js +235 -0
- package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -0
- package/dist/src/ai-sdk/index.d.ts +1 -0
- package/dist/src/ai-sdk/index.js +9 -0
- package/dist/src/ai-sdk/index.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +17 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/index.d.ts +3 -0
- package/dist/src/mcp/index.js +10 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.d.ts +29 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js +185 -0
- package/dist/src/mcp/mcp-resource-and-prompt-tools.js.map +1 -0
- package/dist/src/mcp/mcp-server-config.d.ts +86 -0
- package/dist/src/mcp/mcp-server-config.js +38 -0
- package/dist/src/mcp/mcp-server-config.js.map +1 -0
- package/dist/src/mcp/mcp-tool-source.d.ts +470 -0
- package/dist/src/mcp/mcp-tool-source.js +1204 -0
- package/dist/src/mcp/mcp-tool-source.js.map +1 -0
- package/dist/src/stepwise/agent-definition.d.ts +158 -0
- package/dist/src/stepwise/agent-definition.js +9 -0
- package/dist/src/stepwise/agent-definition.js.map +1 -0
- package/dist/src/stepwise/function-tool.d.ts +130 -0
- package/dist/src/stepwise/function-tool.js +75 -0
- package/dist/src/stepwise/function-tool.js.map +1 -0
- package/dist/src/stepwise/index.d.ts +7 -0
- package/dist/src/stepwise/index.js +12 -0
- package/dist/src/stepwise/index.js.map +1 -0
- package/dist/src/stepwise/json-schema-validation.d.ts +9 -0
- package/dist/src/stepwise/json-schema-validation.js +141 -0
- package/dist/src/stepwise/json-schema-validation.js.map +1 -0
- package/dist/src/stepwise/model-client.d.ts +194 -0
- package/dist/src/stepwise/model-client.js +9 -0
- package/dist/src/stepwise/model-client.js.map +1 -0
- package/dist/src/stepwise/scripted-model-client.d.ts +99 -0
- package/dist/src/stepwise/scripted-model-client.js +156 -0
- package/dist/src/stepwise/scripted-model-client.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-runner.d.ts +189 -0
- package/dist/src/stepwise/stepwise-agent-runner.js +804 -0
- package/dist/src/stepwise/stepwise-agent-runner.js.map +1 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +35 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js +56 -0
- package/dist/src/stepwise/stepwise-agent-session-flow.js.map +1 -0
- package/dist/src/stepwise/stepwise-input-items.d.ts +12 -0
- package/dist/src/stepwise/stepwise-input-items.js +172 -0
- package/dist/src/stepwise/stepwise-input-items.js.map +1 -0
- package/dist/src/stepwise/tool-source.d.ts +103 -0
- package/dist/src/stepwise/tool-source.js +9 -0
- package/dist/src/stepwise/tool-source.js.map +1 -0
- package/dist/src/testing/agent-session-test-client.d.ts +205 -0
- package/dist/src/testing/agent-session-test-client.js +290 -0
- package/dist/src/testing/agent-session-test-client.js.map +1 -0
- package/dist/src/testing/agent-test-environment.d.ts +52 -0
- package/dist/src/testing/agent-test-environment.js +86 -0
- package/dist/src/testing/agent-test-environment.js.map +1 -0
- package/dist/src/testing/agent-worker-process.d.ts +91 -0
- package/dist/src/testing/agent-worker-process.js +150 -0
- package/dist/src/testing/agent-worker-process.js.map +1 -0
- package/dist/src/testing/child-process-group.d.ts +33 -0
- package/dist/src/testing/child-process-group.js +164 -0
- package/dist/src/testing/child-process-group.js.map +1 -0
- package/dist/src/testing/coordination.d.ts +99 -0
- package/dist/src/testing/coordination.js +155 -0
- package/dist/src/testing/coordination.js.map +1 -0
- package/dist/src/testing/index.d.ts +8 -0
- package/dist/src/testing/index.js +16 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/polling.d.ts +31 -0
- package/dist/src/testing/polling.js +51 -0
- package/dist/src/testing/polling.js.map +1 -0
- package/dist/src/testing/private-dex-engine.d.ts +101 -0
- package/dist/src/testing/private-dex-engine.js +223 -0
- package/dist/src/testing/private-dex-engine.js.map +1 -0
- package/dist/src/testing/scripted-model-client.d.ts +1 -0
- package/dist/src/testing/scripted-model-client.js +10 -0
- package/dist/src/testing/scripted-model-client.js.map +1 -0
- package/dist/src/testing/step-history.d.ts +40 -0
- package/dist/src/testing/step-history.js +59 -0
- package/dist/src/testing/step-history.js.map +1 -0
- package/dist/src/ui-stream/agent-event-json.d.ts +30 -0
- package/dist/src/ui-stream/agent-event-json.js +64 -0
- package/dist/src/ui-stream/agent-event-json.js.map +1 -0
- package/dist/src/ui-stream/agent-event-sse.d.ts +154 -0
- package/dist/src/ui-stream/agent-event-sse.js +159 -0
- package/dist/src/ui-stream/agent-event-sse.js.map +1 -0
- package/dist/src/ui-stream/agent-event-stream-positions.d.ts +42 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js +153 -0
- package/dist/src/ui-stream/agent-event-stream-positions.js.map +1 -0
- package/dist/src/ui-stream/agent-session-record-reader.d.ts +72 -0
- package/dist/src/ui-stream/agent-session-record-reader.js +241 -0
- package/dist/src/ui-stream/agent-session-record-reader.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.d.ts +219 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js +440 -0
- package/dist/src/ui-stream/agent-ui-message-stream-responses.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-stream.d.ts +138 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js +681 -0
- package/dist/src/ui-stream/agent-ui-message-stream.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-message-types.d.ts +238 -0
- package/dist/src/ui-stream/agent-ui-message-types.js +57 -0
- package/dist/src/ui-stream/agent-ui-message-types.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-messages.d.ts +66 -0
- package/dist/src/ui-stream/agent-ui-messages.js +220 -0
- package/dist/src/ui-stream/agent-ui-messages.js.map +1 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.d.ts +64 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js +186 -0
- package/dist/src/ui-stream/agent-ui-stream-cursor.js.map +1 -0
- package/dist/src/ui-stream/index.d.ts +14 -0
- package/dist/src/ui-stream/index.js +22 -0
- package/dist/src/ui-stream/index.js.map +1 -0
- package/dist/src/ui-stream/server-sent-event-responses.d.ts +6 -0
- package/dist/src/ui-stream/server-sent-event-responses.js +34 -0
- package/dist/src/ui-stream/server-sent-event-responses.js.map +1 -0
- package/package.json +86 -4
|
@@ -0,0 +1,998 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status of an agent session, stored in the `status` field of {@link AgentState}.
|
|
3
|
+
*
|
|
4
|
+
* - `waiting_for_user_message`: the session is idle in `AwaitUserMessage`.
|
|
5
|
+
* - `running_model`: `RunModel` makes the turn's next model call.
|
|
6
|
+
* - `running_tools`: the requested tool calls run in parallel Steps, some possibly waiting for
|
|
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.
|
|
10
|
+
*/
|
|
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>>;
|
|
99
|
+
/**
|
|
100
|
+
* Input of the `StartAgentSession` Step, passed to `Client.startFlow`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* await client.startFlow(flow, "session-42", {
|
|
105
|
+
* initialMessage: "Summarize my inbox",
|
|
106
|
+
* sessionSettings: { model: "gpt-5-mini" },
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export interface AgentSessionStartInput {
|
|
111
|
+
/**
|
|
112
|
+
* First user message, or `null` to start idle in `AwaitUserMessage`.
|
|
113
|
+
* Blank text is treated as `null`. Wire field: `initial_message`.
|
|
114
|
+
*/
|
|
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;
|
|
125
|
+
}
|
|
126
|
+
/** Small durable summary of an agent session, stored in the `AgentState` Attribute. */
|
|
127
|
+
export interface AgentState {
|
|
128
|
+
/** Current session status. Wire field: `status`. */
|
|
129
|
+
readonly status: AgentSessionStatus;
|
|
130
|
+
/** Number of completed or failed turns. Wire field: `turn_count`. */
|
|
131
|
+
readonly turnCount: number;
|
|
132
|
+
/** ID of the running turn, `turn-<n>`, or `null` when idle. Wire field: `active_turn_id`. */
|
|
133
|
+
readonly activeTurnId: string | null;
|
|
134
|
+
/** Sequence assigned to the next stored message; starts at 1. Wire field: `next_message_sequence`. */
|
|
135
|
+
readonly nextMessageSequence: number;
|
|
136
|
+
/** Error text of the most recent failed turn, or `null`. Wire field: `last_turn_error`. */
|
|
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;
|
|
155
|
+
}
|
|
156
|
+
/** Author of one stored agent message. */
|
|
157
|
+
export type AgentMessageRole = "user" | "assistant" | "tool";
|
|
158
|
+
/**
|
|
159
|
+
* Framework-neutral projection of one framework message, produced by an {@link AgentFrameworkRunner}.
|
|
160
|
+
*
|
|
161
|
+
* The session stores it as an {@link AgentMessage} after adding a sequence, turn ID, and time.
|
|
162
|
+
* Only `frameworkItem` is replayed to the framework; the other fields are display projections.
|
|
163
|
+
*/
|
|
164
|
+
export interface FrameworkMessage {
|
|
165
|
+
/** Author of the message. */
|
|
166
|
+
readonly role: AgentMessageRole;
|
|
167
|
+
/** Display text, or `null` for a message without text, such as a bare tool call. */
|
|
168
|
+
readonly text: string | null;
|
|
169
|
+
/** Tool call ID for a tool call or tool result message, otherwise `null`. */
|
|
170
|
+
readonly toolCallId: string | null;
|
|
171
|
+
/** Tool name for a tool call or tool result message, otherwise `null`. */
|
|
172
|
+
readonly toolName: string | null;
|
|
173
|
+
/** Tool call arguments as JSON text, otherwise `null`. */
|
|
174
|
+
readonly toolArguments: string | null;
|
|
175
|
+
/** Tool result text, otherwise `null`. */
|
|
176
|
+
readonly toolOutput: string | null;
|
|
177
|
+
/** Framework-native JSON for this message; the session replays it to the framework unchanged. */
|
|
178
|
+
readonly frameworkItem: string;
|
|
179
|
+
}
|
|
180
|
+
/** One message stored in the `AgentMessages` AttributeMap under its zero-padded sequence. */
|
|
181
|
+
export interface AgentMessage extends FrameworkMessage {
|
|
182
|
+
/** Monotonic session-wide sequence, starting at 1. Wire field: `sequence`. */
|
|
183
|
+
readonly sequence: number;
|
|
184
|
+
/** Turn that produced the message. Wire field: `turn_id`. */
|
|
185
|
+
readonly turnId: string;
|
|
186
|
+
/** RFC 3339 time at which the session stored the message. Wire field: `created_at`. */
|
|
187
|
+
readonly createdAt: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Side-effect class of a tool, which decides where and how often the session runs it.
|
|
191
|
+
*
|
|
192
|
+
* - `read`: runs in `CallTool`, up to 3 attempts; no approval by default.
|
|
193
|
+
* - `idempotent_write`: runs in `CallTool`, up to 3 attempts with one idempotency key; when they run
|
|
194
|
+
* out, the session records `outcome_unknown`.
|
|
195
|
+
* - `non_idempotent_write`: runs once in `CallSingleAttemptTool`; a crash records `outcome_unknown`.
|
|
196
|
+
* - `unclassified`: treated like `non_idempotent_write`; the default for tools without a policy.
|
|
197
|
+
*/
|
|
198
|
+
export type ToolEffect = "read" | "idempotent_write" | "non_idempotent_write" | "unclassified";
|
|
199
|
+
/**
|
|
200
|
+
* Status of one deferred tool call record, as a runner sees it.
|
|
201
|
+
*
|
|
202
|
+
* `awaiting_approval` and `approved` are open. The other statuses are final: the session
|
|
203
|
+
* never runs a call whose record is final, and the runner reports the result to the model.
|
|
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.
|
|
211
|
+
*/
|
|
212
|
+
export type AgentToolCallStatus = "awaiting_approval" | "approved" | "rejected" | "succeeded" | "failed" | "outcome_unknown";
|
|
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. */
|
|
269
|
+
export interface AgentToolCall {
|
|
270
|
+
/** Framework tool call ID; non-empty and slash-free. Wire field: `tool_call_id`. */
|
|
271
|
+
readonly toolCallId: string;
|
|
272
|
+
/** Turn that deferred the call. Wire field: `turn_id`. */
|
|
273
|
+
readonly turnId: string;
|
|
274
|
+
/** Tool name. Wire field: `tool_name`. */
|
|
275
|
+
readonly toolName: string;
|
|
276
|
+
/** Tool arguments as JSON text. Wire field: `arguments`. */
|
|
277
|
+
readonly arguments: string;
|
|
278
|
+
/** Effect that selected the tool Step. Wire field: `effect`. */
|
|
279
|
+
readonly effect: ToolEffect;
|
|
280
|
+
/** Whether the call waited for `resolve_interrupt`. Wire field: `requires_approval`. */
|
|
281
|
+
readonly requiresApproval: boolean;
|
|
282
|
+
/** Current status. Wire field: `status`. */
|
|
283
|
+
readonly status: AgentToolCallStatus;
|
|
284
|
+
/** Tool output text after `succeeded`, otherwise `null`. Wire field: `output`. */
|
|
285
|
+
readonly output: string | null;
|
|
286
|
+
/**
|
|
287
|
+
* The `ToolExecutionError` message, or the failed Step's recovery detail, after `failed` or
|
|
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.
|
|
290
|
+
*/
|
|
291
|
+
readonly error: string | null;
|
|
292
|
+
/** Rejection text after `rejected`, otherwise `null`. Wire field: `rejection_message`. */
|
|
293
|
+
readonly rejectionMessage: string | null;
|
|
294
|
+
/**
|
|
295
|
+
* Zero-based order in which the turn deferred the call; approved calls run in this order.
|
|
296
|
+
* It extends the planned contract, as in the Python core. Wire field: `deferral_order`.
|
|
297
|
+
*/
|
|
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;
|
|
373
|
+
}
|
|
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. */
|
|
436
|
+
export interface AgentInterrupt {
|
|
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
|
+
*/
|
|
442
|
+
readonly interruptId: string;
|
|
443
|
+
/** Interrupt kind. Wire field: `kind`. */
|
|
444
|
+
readonly kind: AgentInterruptKind;
|
|
445
|
+
/** Tool call that waits. Wire field: `tool_call_id`. */
|
|
446
|
+
readonly toolCallId: string;
|
|
447
|
+
/** Tool name; `ask_user` for an `ask_user` question. Wire field: `tool_name`. */
|
|
448
|
+
readonly toolName: string;
|
|
449
|
+
/** Tool arguments as JSON text. Wire field: `arguments`. */
|
|
450
|
+
readonly arguments: string;
|
|
451
|
+
/** RFC 3339 time at which the interrupt was raised. Wire field: `created_at`. */
|
|
452
|
+
readonly createdAt: string;
|
|
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
|
+
*/
|
|
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;
|
|
473
|
+
}
|
|
474
|
+
/** Resolution of one interrupt, published to the `InterruptResolutions` ChannelMap. */
|
|
475
|
+
export interface AgentInterruptResolution {
|
|
476
|
+
/**
|
|
477
|
+
* Whether the tool call may run, or, for a question, whether the user answered it. Wire field:
|
|
478
|
+
* `approved`.
|
|
479
|
+
*/
|
|
480
|
+
readonly approved: boolean;
|
|
481
|
+
/** Text shown to the model when rejected or declined, or `null`. Wire field: `rejection_message`. */
|
|
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;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Model usage counters, stored cumulatively in the `AgentUsage` Attribute.
|
|
491
|
+
*
|
|
492
|
+
* Runners report the usage of one model call in an {@link AgentTurnOutcome}; the session adds it.
|
|
493
|
+
* Use {@link emptyAgentUsage} and {@link addAgentUsage} to accumulate per-model-call usage.
|
|
494
|
+
*/
|
|
495
|
+
export interface AgentUsage {
|
|
496
|
+
/** Number of model calls. Wire field: `model_calls`. */
|
|
497
|
+
readonly modelCalls: number;
|
|
498
|
+
/** Input tokens, including cached input tokens. Wire field: `input_tokens`. */
|
|
499
|
+
readonly inputTokens: number;
|
|
500
|
+
/** Output tokens, including reasoning tokens when the provider counts them so. Wire field: `output_tokens`. */
|
|
501
|
+
readonly outputTokens: number;
|
|
502
|
+
/** Input tokens served from a provider cache. Wire field: `cached_input_tokens`. */
|
|
503
|
+
readonly cachedInputTokens: number;
|
|
504
|
+
/** Reasoning tokens reported by the provider. Wire field: `reasoning_tokens`. */
|
|
505
|
+
readonly reasoningTokens: number;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Notice that one tool call of the current batch reached a final record, published to the internal
|
|
509
|
+
* `ToolCallResults` Channel. `ResumeTurn` waits for one per requested tool call; the result itself is
|
|
510
|
+
* in the call's `AgentToolCalls` record.
|
|
511
|
+
*/
|
|
512
|
+
export interface ToolCallCompleted {
|
|
513
|
+
/** Tool call whose record is final. Wire field: `tool_call_id`. */
|
|
514
|
+
readonly toolCallId: string;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* One user message, the input of the `send_user_message` RPC and the value of the `QueuedUserMessages` and
|
|
518
|
+
* `SteeredUserMessages` Channels.
|
|
519
|
+
*/
|
|
520
|
+
export interface AgentUserMessage {
|
|
521
|
+
/** Message text. Blank text is rejected. Wire field: `text`. */
|
|
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;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Standard type of one {@link AgentEvent}. Adapters may write other types with an adapter prefix.
|
|
633
|
+
*
|
|
634
|
+
* Payloads are JSON objects with snake_case keys, serialized with sorted keys:
|
|
635
|
+
* - `turn_started`: `{"sequence"}`, the sequence of the user message that started the turn.
|
|
636
|
+
* - `turn_completed`: `{"message_count"}`, the number of messages the turn appended.
|
|
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`.
|
|
643
|
+
* - `text_delta` and `reasoning_delta`: `{"text"}`.
|
|
644
|
+
* - `tool_call_started`: `{"tool_call_id","tool_name"}`.
|
|
645
|
+
* - `tool_call_finished`: `{"tool_call_id","tool_name","status"}`, when a record becomes final,
|
|
646
|
+
* including a rejection.
|
|
647
|
+
* - `tool_call_deferred`: `{"tool_call_id","tool_name","effect","requires_approval"}`, when the model
|
|
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.
|
|
661
|
+
* - `usage_recorded`: `{"recorded","session"}`: one model call's and the cumulative usage, each with
|
|
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}.
|
|
667
|
+
*/
|
|
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";
|
|
669
|
+
/** One best-effort live event, written to the `AgentEvents` Stream. */
|
|
670
|
+
export interface AgentEvent {
|
|
671
|
+
/** An {@link AgentEventType} or an adapter-specific type such as `"vercel_ai.step"`. Wire field: `type`. */
|
|
672
|
+
readonly type: string;
|
|
673
|
+
/** Turn the event belongs to, or `null`. Wire field: `turn_id`. */
|
|
674
|
+
readonly turnId: string | null;
|
|
675
|
+
/** One-based attempt of the Step that wrote the event. Wire field: `attempt`. */
|
|
676
|
+
readonly attempt: number;
|
|
677
|
+
/**
|
|
678
|
+
* Dex Step execution ID of the Step that wrote the event; all attempts of one Step execution share
|
|
679
|
+
* it. Events written before this field existed decode with `""`. Wire field: `step_execution_id`.
|
|
680
|
+
*
|
|
681
|
+
* Group live text by `(turnId, stepExecutionId, attempt)`. Within one `stepExecutionId`, keep only the
|
|
682
|
+
* events of the highest `attempt` seen and drop the partial text of lower attempts. Different
|
|
683
|
+
* `stepExecutionId` values of one turn are its model calls and tool Steps, and each keeps its
|
|
684
|
+
* own events. After `turn_completed`, `turn_failed`, `turn_steered`, or `turn_cancelled`, replace the
|
|
685
|
+
* turn's live text with the stored messages.
|
|
686
|
+
*/
|
|
687
|
+
readonly stepExecutionId: string;
|
|
688
|
+
/** Event payload as JSON text. Wire field: `payload`. */
|
|
689
|
+
readonly payload: string;
|
|
690
|
+
}
|
|
691
|
+
/** Input of the `resolve_interrupt` RPC. */
|
|
692
|
+
export interface ResolveInterruptInput {
|
|
693
|
+
/** Pending interrupt to resolve. Wire field: `interrupt_id`. */
|
|
694
|
+
readonly interruptId: string;
|
|
695
|
+
/** Whether the tool call may run. Wire field: `approved`. */
|
|
696
|
+
readonly approved: boolean;
|
|
697
|
+
/** Text shown to the model when rejected, or `null`. Wire field: `rejection_message`. */
|
|
698
|
+
readonly rejectionMessage: string | null;
|
|
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
|
+
}
|
|
828
|
+
/** Output of the `get_agent_snapshot` RPC, enough for a UI to rebuild its view. */
|
|
829
|
+
export interface AgentSnapshot {
|
|
830
|
+
/** Current session state, or `null` before `StartAgentSession` committed. Wire field: `state`. */
|
|
831
|
+
readonly state: AgentState | null;
|
|
832
|
+
/** Up to the last 200 messages in ascending sequence order. Wire field: `messages`. */
|
|
833
|
+
readonly messages: readonly AgentMessage[];
|
|
834
|
+
/** Interrupts that `resolve_interrupt` still accepts. Wire field: `pending_interrupts`. */
|
|
835
|
+
readonly pendingInterrupts: readonly AgentInterrupt[];
|
|
836
|
+
/** Deferred tool call records of the active turn, in deferral order. Wire field: `tool_calls`. */
|
|
837
|
+
readonly toolCalls: readonly AgentToolCallRecord[];
|
|
838
|
+
/** Cumulative usage. Wire field: `usage`. */
|
|
839
|
+
readonly usage: AgentUsage;
|
|
840
|
+
/** User messages queued and not yet consumed. Wire field: `queued_message_count`. */
|
|
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;
|
|
867
|
+
}
|
|
868
|
+
/** Input of the `list_agent_messages` RPC. */
|
|
869
|
+
export interface ListAgentMessagesInput {
|
|
870
|
+
/** Return messages with a smaller sequence, or `null` for the newest. Wire field: `before_sequence`. */
|
|
871
|
+
readonly beforeSequence: number | null;
|
|
872
|
+
/** Page size; the session clamps it to 1..200. A missing wire value means 50. Wire field: `limit`. */
|
|
873
|
+
readonly limit: number;
|
|
874
|
+
}
|
|
875
|
+
/** Output of the `list_agent_messages` RPC. */
|
|
876
|
+
export interface AgentMessagesPage {
|
|
877
|
+
/** Messages in ascending sequence order. Wire field: `messages`. */
|
|
878
|
+
readonly messages: readonly AgentMessage[];
|
|
879
|
+
/**
|
|
880
|
+
* Value to pass as `beforeSequence` for the next older page, or `null` when no older message exists.
|
|
881
|
+
* Wire field: `next_before_sequence`.
|
|
882
|
+
*/
|
|
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;
|
|
890
|
+
}
|
|
891
|
+
/**
|
|
892
|
+
* Returns usage with every counter at zero.
|
|
893
|
+
*
|
|
894
|
+
* @returns A new {@link AgentUsage} whose counters are all `0`.
|
|
895
|
+
*/
|
|
896
|
+
export declare function emptyAgentUsage(): AgentUsage;
|
|
897
|
+
/**
|
|
898
|
+
* Adds two usage values counter by counter.
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```ts
|
|
902
|
+
* let usage = emptyAgentUsage();
|
|
903
|
+
* usage = addAgentUsage(usage, { ...emptyAgentUsage(), modelCalls: 1, inputTokens: 120, outputTokens: 30 });
|
|
904
|
+
* ```
|
|
905
|
+
* @param left - First usage value.
|
|
906
|
+
* @param right - Second usage value.
|
|
907
|
+
* @returns A new {@link AgentUsage} holding the sums; neither input is changed.
|
|
908
|
+
*/
|
|
909
|
+
export declare function addAgentUsage(left: AgentUsage, right: AgentUsage): AgentUsage;
|
|
910
|
+
/**
|
|
911
|
+
* Reports whether a tool call status is final.
|
|
912
|
+
*
|
|
913
|
+
* @param status - Status to classify.
|
|
914
|
+
* @returns `true` for `rejected`, `succeeded`, `failed`, and `outcome_unknown`; `false` for
|
|
915
|
+
* `awaiting_approval`, `approved`, and every {@link AgentToolCallWaitingStatus}.
|
|
916
|
+
*/
|
|
917
|
+
export declare function isFinalToolCallStatus(status: AgentToolCallRecordStatus): boolean;
|
|
918
|
+
/** Tool result text the model sees for an `outcome_unknown` call; the same text as the Python core. */
|
|
919
|
+
export declare const outcomeUnknownToolResult: string;
|
|
920
|
+
/** First line of the note `RecordTurnFailure` stores after a failed turn ran tools. */
|
|
921
|
+
export declare const turnFailureNoteHeader = "[Dex] The previous turn failed after these tool calls ran:";
|
|
922
|
+
/** Last line of that note. */
|
|
923
|
+
export declare const turnFailureNoteFooter = "Do not repeat these tool calls unless the user asks again.";
|
|
924
|
+
/** Tool result text the model sees for a rejection without a message; the same text as the Python core. */
|
|
925
|
+
export declare const defaultRejectionToolResult = "The user rejected this tool call.";
|
|
926
|
+
/** Rejection message recorded when an approval deadline passes. */
|
|
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";
|
|
956
|
+
/**
|
|
957
|
+
* Returns the note text that tells the model what a failed turn already did.
|
|
958
|
+
*
|
|
959
|
+
* `RecordTurnFailure` stores this note through {@link AgentFrameworkRunner.buildUserMessage} when a
|
|
960
|
+
* failed turn has final tool call records, as the failed turn's last message, so the next turn's model
|
|
961
|
+
* does not repeat a write. The text matches the Python core's `build_turn_failure_note`:
|
|
962
|
+
*
|
|
963
|
+
* ```text
|
|
964
|
+
* [Dex] The previous turn failed after these tool calls ran:
|
|
965
|
+
* - charge {"amount": 5} -> succeeded: charged 5
|
|
966
|
+
* Do not repeat these tool calls unless the user asks again.
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @param toolCalls - Final records of the failed turn; they are listed in `deferralOrder`.
|
|
970
|
+
* @returns {@link turnFailureNoteHeader}, one `- <toolName> <arguments> -> <status>: <outcome>` line
|
|
971
|
+
* per record, with the outcome from {@link describeToolCallOutcome}, and {@link turnFailureNoteFooter},
|
|
972
|
+
* joined with newlines.
|
|
973
|
+
* @throws {TypeError} When a record is not final.
|
|
974
|
+
*/
|
|
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;
|
|
978
|
+
/**
|
|
979
|
+
* Returns the tool result text a runner shows the model for a final tool call record.
|
|
980
|
+
*
|
|
981
|
+
* Use it when resuming a framework whose tool result must be text. A runner whose framework has a
|
|
982
|
+
* native rejection, such as a rejection message argument, may pass `rejectionMessage` there instead.
|
|
983
|
+
* The texts match the Python core's `describe_tool_call_outcome`.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```ts
|
|
987
|
+
* const record = turn.recordedToolCall(pendingCallId);
|
|
988
|
+
* if (record !== undefined && isFinalToolCallStatus(record.status)) {
|
|
989
|
+
* frameworkToolResult = describeToolCallOutcome(record);
|
|
990
|
+
* }
|
|
991
|
+
* ```
|
|
992
|
+
* @param toolCall - Record whose status is final.
|
|
993
|
+
* @returns The output for `succeeded`; `The tool call failed: <error>` for `failed`; the rejection
|
|
994
|
+
* message, or {@link defaultRejectionToolResult}, for `rejected`; {@link outcomeUnknownToolResult}
|
|
995
|
+
* for `outcome_unknown`.
|
|
996
|
+
* @throws {TypeError} When the record status is not final.
|
|
997
|
+
*/
|
|
998
|
+
export declare function describeToolCallOutcome(toolCall: AgentToolCall | AgentToolCallRecord): string;
|