@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
@@ -1,61 +1,224 @@
1
- import { type AsyncContext, type Context, type StepDecision } from "@superdurable/dex";
1
+ import { StepMovement, type AsyncContext, type Context, type RecoveryErrorInfo, type StepDecision } from "@superdurable/dex";
2
+ import type { BuiltInTool } from "./agent-built-in-tools.js";
3
+ import { type ResolvedCompactionPolicy } from "./agent-context-compaction.js";
2
4
  import { StreamAgentEventWriter } from "./agent-event-writer.js";
3
- import { type AgentFrameworkRunner, type ResolvedToolPolicy, type ToolPolicy } from "./agent-framework-runner.js";
5
+ import { type AgentFrameworkRunner, type AgentTurnContext, type DeferredToolOutcome, type ResolvedToolPolicy, type ToolPolicy } from "./agent-framework-runner.js";
4
6
  import { type AgentSessionPersistence } from "./agent-session-persistence.js";
5
- import { type AgentInterrupt, type AgentMessage, type AgentState, type AgentToolCall, type AgentUsage, type FrameworkMessage, type ToolEffect } from "./agent-session-values.js";
6
- export declare const agentSessionStepTypes: {
7
- readonly startAgentSession: "StartAgentSession";
8
- readonly awaitUserMessage: "AwaitUserMessage";
9
- readonly runModel: "RunModel";
10
- readonly awaitToolApproval: "AwaitToolApproval";
11
- readonly callTool: "CallTool";
12
- readonly callSingleAttemptTool: "CallSingleAttemptTool";
13
- readonly recordToolFailure: "RecordToolFailure";
14
- readonly recordToolOutcomeUnknown: "RecordToolOutcomeUnknown";
15
- readonly resumeTurn: "ResumeTurn";
16
- readonly recordTurnFailure: "RecordTurnFailure";
17
- };
7
+ import { type MessageChunkLoads } from "./agent-session-step-options.js";
8
+ import type { AgentSessionTracer } from "./agent-session-tracer.js";
9
+ import { type AgentInterrupt, type AgentInterruptKind, type AgentMessage, type AgentMessageChunk, type AgentMessageChunkRange, type AgentMessageIndex, type AgentPlan, type AgentState, type AgentToolCall, type AgentToolCallRecord, type AgentUsage, type AgentUserMessage, type ContextSummary, type SessionSettings, type TurnSessionSettings, type FrameworkMessage, type InteractionMode, type ToolCallCancellationReason, type ToolEffect } from "./agent-session-values.js";
10
+ import type { ResolvedAgentTracingOptions } from "./agent-tracing-options.js";
11
+ export { agentSessionStepTypes } from "./agent-session-step-types.js";
12
+ /** Most archive chunks one commit writes, so a large 0.1.0 history migrates over several commits. */
13
+ export declare const messageRolloverMaxChunksPerCommit = 4;
14
+ /**
15
+ * Most chunk bytes one commit writes, 8 MiB, which keeps a Step result far under the engine's frame limit. A
16
+ * single chunk larger than it still moves, alone.
17
+ */
18
+ export declare const messageRolloverMaxBytesPerCommit = 8388608;
19
+ /** Consumes every pending message of a Channel at once; the plan's MAX. */
20
+ export declare const allPendingMessages = 2147483647;
21
+ /** The model-visible result of a call that steering or `cancel_turn` abandoned, by reason. */
22
+ export declare const toolCallCancellationResults: Readonly<Record<ToolCallCancellationReason, string>>;
23
+ /** Fields of one `interrupt_resolved` event. */
24
+ export interface InterruptResolvedEvent {
25
+ readonly interruptId: string;
26
+ readonly kind: AgentInterruptKind;
27
+ readonly isApproved: boolean;
28
+ readonly isAnswered: boolean;
29
+ readonly rejectionMessage: string | null;
30
+ readonly cancellationReason?: ToolCallCancellationReason;
31
+ }
18
32
  export interface AgentSessionConfig {
19
33
  readonly flowType: string;
20
34
  readonly toolPolicies: Readonly<Record<string, ToolPolicy>>;
21
35
  readonly defaultToolEffect: ToolEffect;
22
36
  readonly eventStreamCapacityBytes: number;
23
37
  readonly interruptDeadlineMs: number | undefined;
38
+ readonly tracing: ResolvedAgentTracingOptions;
39
+ readonly builtInTools: ReadonlySet<BuiltInTool>;
40
+ readonly maxDurableWaitMs: number;
41
+ readonly planModeEnabled: boolean;
42
+ readonly compaction: ResolvedCompactionPolicy | undefined;
43
+ readonly messageWindowSize: number;
44
+ readonly messageChunkSize: number;
45
+ readonly messageChunkMaxBytes: number;
46
+ readonly retainedMessageLimit: number | null;
24
47
  }
25
48
  /** Shared state reads, writes, and routing used by every session Step. */
26
49
  export declare class AgentSessionTransitions {
27
50
  readonly persistence: AgentSessionPersistence;
28
- readonly runner: AgentFrameworkRunner;
51
+ readonly runner: AgentFrameworkRunner<DeferredToolOutcome>;
29
52
  readonly config: AgentSessionConfig;
30
- constructor(persistence: AgentSessionPersistence, runner: AgentFrameworkRunner, config: AgentSessionConfig);
53
+ readonly tracer: AgentSessionTracer;
54
+ constructor(persistence: AgentSessionPersistence, runner: AgentFrameworkRunner<DeferredToolOutcome>, config: AgentSessionConfig, tracer: AgentSessionTracer);
31
55
  readOptionalAgentState(context: Context): AgentState | null;
32
56
  readAgentState(context: Context): AgentState;
33
57
  writeAgentState(context: Context, state: AgentState): void;
34
58
  readPendingInterrupts(context: Context): readonly AgentInterrupt[];
59
+ readOptionalAgentPlan(context: Context): AgentPlan | null;
35
60
  readAgentUsage(context: Context): AgentUsage;
61
+ /** The settings the next turn starts with, or `null` when the session has none. */
62
+ readSessionSettings(context: Context): SessionSettings | null;
63
+ /** The settings the active turn started with; see {@link selectTurnSessionSettings}. */
64
+ readTurnSessionSettings(context: Context): SessionSettings;
65
+ readContextSummary(context: Context): ContextSummary | null;
66
+ /** The summary the runner sees; a runner without the compaction methods keeps every message instead. */
67
+ readRunnerContextSummary(context: Context): ContextSummary | null;
36
68
  readFrameworkRunState(context: Context): string | null;
37
- /** Returns messages with sequences in [start, end); requires the AgentMessages load. */
69
+ readMessageIndex(context: Context): AgentMessageIndex | null;
70
+ /** Sequence of the oldest stored message: retention deleted the earlier ones. */
71
+ readFirstStoredSequence(context: Context): number;
72
+ /**
73
+ * Returns the stored messages with sequences in [start, end), from the `AgentMessages` window and the
74
+ * `AgentMessageChunks` instances. It requires the whole window and every chunk it reads to be loaded.
75
+ */
38
76
  readMessages(context: Context, start: number, end: number): AgentMessage[];
77
+ private readWindowMessage;
78
+ /** Reads one loaded chunk and checks that it holds exactly the messages its range names. */
79
+ private readChunkMessages;
80
+ /**
81
+ * Counts the active turn's stored messages after the user messages that started it, before this Step's
82
+ * appends. A turn without its `TurnReplySequence`, such as one a 0.1.0 Worker started, is counted from its
83
+ * stored messages instead.
84
+ */
85
+ countStoredTurnReplies(context: Context, state: AgentState, turnId: string): number;
86
+ /** Returns the first sequence after the turn's user messages, from `TurnReplySequence` or the stored messages. */
87
+ private readTurnReplySequence;
88
+ /**
89
+ * Returns the turn's newest stored messages, read back until another turn's, the oldest stored message, or a
90
+ * chunk this Step did not load.
91
+ */
92
+ private readStoredTurnMessages;
93
+ /** Reads one stored message from the window or its chunk, or returns `undefined` when its chunk is not loaded. */
94
+ private readLoadedMessage;
95
+ /** First sequence of the model input: after the runner's summary, and never before the oldest stored message. */
96
+ readModelInputFirstSequence(context: Context, summary: ContextSummary | null): number;
97
+ /**
98
+ * Returns the archive chunks that hold messages in [start, end): every chunk when compaction is off, since
99
+ * the model input then covers them all, else exact instances.
100
+ */
101
+ messageChunkLoads(context: Context, start: number, end?: number): MessageChunkLoads;
102
+ /** The chunk loads of a Step that rebuilds the model input. */
103
+ modelInputChunkLoads(context: Context, summary: ContextSummary | null): MessageChunkLoads;
104
+ /** Moves to `RunModel`, loading the window and the archive chunks of the model input. */
105
+ goToRunModel(context: Context, summary?: ContextSummary | null): StepDecision;
106
+ /** Moves to `ApplyTurnControl`, which may rebuild the model input for unfinished-turn messages. */
107
+ goToApplyTurnControl(context: Context): StepDecision;
108
+ private goToModelInputStep;
39
109
  /** Returns the turn's tool call records in deferral order; requires the AgentToolCalls load. */
40
- readTurnToolCalls(context: Context, turnId: string | null): AgentToolCall[];
110
+ readTurnToolCalls(context: Context, turnId: string | null): AgentToolCallRecord[];
41
111
  /** Returns one tool call record; requires the AgentToolCalls load. */
42
- readToolCall(context: Context, toolCallId: string): AgentToolCall;
112
+ readToolCall(context: Context, toolCallId: string): AgentToolCallRecord;
43
113
  /** Tells `ResumeTurn` that one tool call of the batch has a final record. */
44
114
  publishToolCallResult(context: Context, toolCallId: string): void;
45
- writeToolCall(context: Context, toolCall: AgentToolCall): void;
46
- /** Appends messages, writes the advanced AgentState, and returns it. */
47
- appendMessages(context: Context, state: AgentState, turnId: string, frameworkMessages: readonly FrameworkMessage[]): AgentState;
48
- /** Appends the user message, opens the next turn, and moves to RunModel. */
49
- beginTurn(context: Context, state: AgentState, text: string): StepDecision;
115
+ writeToolCall(context: Context, toolCall: AgentToolCallRecord): void;
116
+ /**
117
+ * Writes a final record, its `tool_call_finished` event, and its `ToolCallResults` notice in one commit.
118
+ * Pass the Step's open events writer, if it has one, so the event keeps its order.
119
+ */
120
+ finishToolCall(context: Context, toolCall: AgentToolCallRecord, events?: StreamAgentEventWriter): void;
121
+ writeInterruptRaised(events: StreamAgentEventWriter, interrupt: AgentInterrupt): void;
122
+ writeInterruptResolved(context: Context, turnId: string, resolution: InterruptResolvedEvent): void;
123
+ /** Writes the `interrupt_resolved` event of an interrupt that steering or `cancel_turn` removed. */
124
+ writeInterruptCancelled(context: Context, turnId: string, interruptId: string, kind: AgentInterruptKind, reason: ToolCallCancellationReason): void;
125
+ /**
126
+ * Returns why the turn ends at this boundary, or `null`. It reads committed state only: a matching
127
+ * `TurnCancellationRequest`, then any pending steered message.
128
+ */
129
+ readTurnControlReason(context: Context, turnId: string | null): ToolCallCancellationReason | null;
130
+ /** Builds the runner's view of a turn; every record must be final. */
131
+ createTurnContext(context: Context, state: AgentState, turnId: string, toolCalls: readonly AgentToolCallRecord[], events: StreamAgentEventWriter, heartbeat: () => Promise<void>): AgentTurnContext;
132
+ /**
133
+ * Returns the runner's unfinished-turn messages for an ending turn, or `null` when the runner has no such
134
+ * method or it throws, so the caller stores its note instead.
135
+ */
136
+ buildUnfinishedTurnMessages(context: Context, state: AgentState, turnId: string, finalToolCalls: readonly AgentToolCallRecord[]): readonly FrameworkMessage[] | null;
137
+ isEnabledBuiltInTool(toolName: string): toolName is BuiltInTool;
138
+ /**
139
+ * Appends messages, writes the advanced AgentState, and returns it.
140
+ *
141
+ * A message goes into the `AgentMessages` window, or, when its own chunk would exceed `messageChunkMaxBytes`,
142
+ * straight into a chunk of its own, so the first store writes the largest value it ever needs. In the same
143
+ * commit it moves the oldest window messages into archive chunks while the window is over its size and
144
+ * applies retention; it writes `AgentMessageIndex` only when one of them changed it. It requires the whole
145
+ * window to be loaded. With `startsTurn`, `TurnReplySequence` records where the turn's replies begin.
146
+ */
147
+ appendMessages(context: Context, state: AgentState, turnId: string, frameworkMessages: readonly FrameworkMessage[], startsTurn?: boolean): AgentState;
148
+ /**
149
+ * Moves the oldest window messages into immutable chunks while the window holds more than its size. A chunk
150
+ * closes at `messageChunkSize` messages, at `messageChunkMaxBytes` bytes, or before a message stored in its
151
+ * own chunk. One commit writes at most {@link messageRolloverMaxChunksPerCommit} chunks and
152
+ * {@link messageRolloverMaxBytesPerCommit} bytes, so a backlog drains over several commits.
153
+ */
154
+ private rollOverMessageWindow;
155
+ /**
156
+ * Deletes the oldest archive chunk while every message in it is summarized and at least `retainedMessageLimit`
157
+ * stored messages come after it, so the newest `retainedMessageLimit` messages always stay. It runs only with
158
+ * compaction and a limit.
159
+ */
160
+ applyMessageRetention(context: Context, index: AgentMessageIndex, nextMessageSequence: number, summary: ContextSummary | null): AgentMessageIndex;
161
+ /** Appends the turn's user messages, in order, opens the next turn, and moves to RunModel. */
162
+ beginTurn(context: Context, state: AgentState, messages: readonly AgentUserMessage[], stepType: string, interactionMode?: InteractionMode, executedPlan?: AgentPlan, wasPlanDraft?: boolean, sessionSettings?: SessionSettings | null): StepDecision;
163
+ /**
164
+ * Returns the mode of a turn that these user messages start: `planning` when plan mode is enabled and a
165
+ * message has `planMode` or a `draft` plan exists, else `chat`.
166
+ */
167
+ decideInteractionMode(context: Context, messages: readonly AgentUserMessage[]): InteractionMode;
168
+ /** Ends a steered or cancelled turn with its unfinished-turn messages, or with a note; returns the new state. */
169
+ endControlledTurn(context: Context, initialState: AgentState, turnId: string, steeredMessageCount: number): AgentState;
50
170
  goToAwaitUserMessage(): StepDecision;
171
+ /** Reports whether `cancel_turn` stopped this turn; reads committed state only. */
172
+ isTurnCancelled(context: Context, turnId: string | null): boolean;
51
173
  resolveToolPolicy(toolName: string, frameworkEffect?: ToolEffect): ResolvedToolPolicy;
52
174
  recordUsage(context: Context, usage: AgentUsage, events: StreamAgentEventWriter): void;
53
175
  createEventWriter(context: Context, turnId: string | null): StreamAgentEventWriter;
54
176
  writeEvents(context: Context, turnId: string | null, write: (events: StreamAgentEventWriter) => void): void;
55
177
  /** Runs an operation while recording a heartbeat every 20 seconds. */
56
- runWithHeartbeats<Result>(context: AsyncContext, operation: () => Promise<Result>): Promise<Result>;
178
+ runWithHeartbeats<Result>(context: AsyncContext, operation: () => Promise<Result>, recordHeartbeat?: () => Promise<void>): Promise<Result>;
57
179
  recordHeartbeat(context: AsyncContext): Promise<void>;
58
180
  }
181
+ /**
182
+ * Heartbeats of one tool Step attempt. Each carries the latest checkpoint, else the Step execution ID,
183
+ * which every attempt shares and so never reads as a checkpoint.
184
+ */
185
+ export declare class ToolStepHeartbeats {
186
+ private readonly context;
187
+ readonly previousCheckpoint: string | undefined;
188
+ private checkpoint;
189
+ constructor(context: AsyncContext);
190
+ record(): Promise<void>;
191
+ saveCheckpoint(checkpoint: string): Promise<void>;
192
+ }
193
+ /** Returns a record as a runner sees it; only records that runners may see are accepted. */
194
+ export declare function toRunnerToolCall(record: AgentToolCallRecord): AgentToolCall;
195
+ /** Moves to `FinishTurnCancellation` for one turn; its locks come from the Step's own options. */
196
+ export declare function finishTurnCancellationMovement(turnId: string): StepMovement<string>;
197
+ /** Reports whether `cancel_turn` abandons this call's started task. */
198
+ export declare function isAbandonedToolTask(toolCall: AgentToolCallRecord): boolean;
199
+ /** Reports whether steering or `cancel_turn` may abandon a call that waits in a session Step. */
200
+ export declare function isCancellableByTurnControl(toolCall: AgentToolCallRecord): boolean;
201
+ /** Returns a record that steering or `cancel_turn` abandoned before the call started. */
202
+ export declare function cancelledToolCall(toolCall: AgentToolCallRecord, reason: ToolCallCancellationReason): AgentToolCallRecord;
203
+ /**
204
+ * Returns the kept chunk that holds a message, found by binary search over the index's ordered ranges, or
205
+ * `undefined` when the message is in the window.
206
+ */
207
+ export declare function findMessageChunkRange(index: AgentMessageIndex, sequence: number): AgentMessageChunkRange | undefined;
208
+ /** Whether a chunk holds exactly the messages of its range, in order. */
209
+ export declare function isMessageChunkOfRange(chunk: AgentMessageChunk, range: AgentMessageChunkRange): boolean;
210
+ /** Counts a turn's stored messages after the user messages that started it. */
211
+ export declare function countMessagesAfterUserMessages(messages: readonly AgentMessage[], turnId: string): number;
59
212
  export declare function toolStepTypeForEffect(effect: ToolEffect): string;
60
213
  /** Returns the text of the failure that selected a recovery Step. */
61
214
  export declare function readRecoveryDetail(context: Context): string;
215
+ /** Returns the text of a recovery error: its detail, else its error type, else "unknown failure". */
216
+ export declare function recoveryErrorDetail(recoveryError: RecoveryErrorInfo | undefined): string;
217
+ /** Writes `plan_updated` with the plan's revision, status, and task count. */
218
+ export declare function writePlanUpdated(events: StreamAgentEventWriter, plan: AgentPlan): void;
219
+ /**
220
+ * Returns the settings of the active turn from its stored copy: the copy's settings while it belongs to that
221
+ * turn, else `{}`. A turn that a Worker without session settings started, such as 0.1.0, leaves an earlier
222
+ * turn's copy in place, which must not apply.
223
+ */
224
+ export declare function selectTurnSessionSettings(stored: TurnSessionSettings | null, activeTurnId: string | null): SessionSettings;