@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.
- package/README.md +1568 -62
- 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-framework-runner.d.ts +456 -16
- package/dist/src/agent-framework-runner.js +4 -3
- package/dist/src/agent-framework-runner.js.map +1 -1
- 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 +65 -4
- package/dist/src/agent-session-codecs.js +342 -8
- package/dist/src/agent-session-codecs.js.map +1 -1
- package/dist/src/agent-session-flow.d.ts +295 -27
- package/dist/src/agent-session-flow.js +368 -21
- package/dist/src/agent-session-flow.js.map +1 -1
- package/dist/src/agent-session-persistence.d.ts +81 -4
- package/dist/src/agent-session-persistence.js +33 -2
- package/dist/src/agent-session-persistence.js.map +1 -1
- 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 +101 -8
- package/dist/src/agent-session-steps.js +936 -197
- package/dist/src/agent-session-steps.js.map +1 -1
- 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 +189 -26
- package/dist/src/agent-session-transitions.js +680 -32
- package/dist/src/agent-session-transitions.js.map +1 -1
- package/dist/src/agent-session-values.d.ts +690 -29
- package/dist/src/agent-session-values.js +39 -4
- package/dist/src/agent-session-values.js.map +1 -1
- 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 +9 -3
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- 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 +65 -8
- package/dist/src/testing/agent-session-test-client.js +95 -22
- package/dist/src/testing/agent-session-test-client.js.map +1 -1
- package/dist/src/testing/index.d.ts +1 -0
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/private-dex-engine.d.ts +9 -0
- package/dist/src/testing/private-dex-engine.js +9 -1
- package/dist/src/testing/private-dex-engine.js.map +1 -1
- 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/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 +41 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Attribute, AttributeMap, Channel, ChannelMap, Stream } from "@superdurable/dex";
|
|
2
|
-
import type { AgentEvent, AgentInterrupt, AgentInterruptResolution, AgentMessage, AgentState,
|
|
2
|
+
import type { AgentEvent, AgentInterrupt, AgentInterruptResolution, AgentMessage, AgentMessageChunk, AgentMessageIndex, AgentPlan, AgentState, AgentToolCallRecord, AgentUsage, AgentUserMessage, PlanExecutionRequest, ContextSummary, SessionSettings, TurnReplySequence, TurnSessionSettings, ToolCallCancellation, ToolCallCompleted, TurnCancellationRequest, TurnControlRequest } from "./agent-session-values.js";
|
|
3
3
|
/** Default byte budget of the `AgentEvents` Stream: 10 MiB. */
|
|
4
4
|
export declare const defaultAgentEventsCapacityBytes: number;
|
|
5
5
|
/**
|
|
@@ -19,12 +19,25 @@ export declare const defaultAgentEventsCapacityBytes: number;
|
|
|
19
19
|
export interface AgentSessionPersistence {
|
|
20
20
|
/** The `AgentState` Attribute. It is always set after `StartAgentSession`. */
|
|
21
21
|
readonly agentState: Attribute<AgentState>;
|
|
22
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The `AgentMessages` AttributeMap: the window of the newest messages, one instance per message, keyed by
|
|
24
|
+
* {@link messageSequenceKey}. Older messages are in {@link agentMessageChunks}; see {@link agentMessageIndex}.
|
|
25
|
+
*/
|
|
23
26
|
readonly agentMessages: AttributeMap<AgentMessage>;
|
|
27
|
+
/**
|
|
28
|
+
* The `AgentMessageChunks` AttributeMap: immutable archive chunks of older messages, keyed by
|
|
29
|
+
* {@link messageSequenceKey} of each chunk's first sequence.
|
|
30
|
+
*/
|
|
31
|
+
readonly agentMessageChunks: AttributeMap<AgentMessageChunk>;
|
|
32
|
+
/**
|
|
33
|
+
* The `AgentMessageIndex` Attribute: where the window and the retained chunks start. A session that a 0.1.0
|
|
34
|
+
* Worker wrote has none until its first write on this version.
|
|
35
|
+
*/
|
|
36
|
+
readonly agentMessageIndex: Attribute<AgentMessageIndex>;
|
|
24
37
|
/** The `FrameworkRunState` Attribute: opaque framework JSON, set only while a turn is suspended. */
|
|
25
38
|
readonly frameworkRunState: Attribute<string>;
|
|
26
39
|
/** The `AgentToolCalls` AttributeMap, keyed by tool call ID; holds only the active turn's records. */
|
|
27
|
-
readonly agentToolCalls: AttributeMap<
|
|
40
|
+
readonly agentToolCalls: AttributeMap<AgentToolCallRecord>;
|
|
28
41
|
/** The `PendingInterrupts` Attribute: interrupts that `resolve_interrupt` still accepts. */
|
|
29
42
|
readonly pendingInterrupts: Attribute<readonly AgentInterrupt[]>;
|
|
30
43
|
/** The `AgentUsage` Attribute: cumulative usage of every turn. */
|
|
@@ -38,12 +51,68 @@ export interface AgentSessionPersistence {
|
|
|
38
51
|
* record becomes final, and `ResumeTurn` consumes them. Applications never publish to it.
|
|
39
52
|
*/
|
|
40
53
|
readonly toolCallResults: Channel<ToolCallCompleted>;
|
|
54
|
+
/** The `SteeredUserMessages` Channel; `steer_user_message` publishes and `ApplyTurnControl` consumes. */
|
|
55
|
+
readonly steeredUserMessages: Channel<AgentUserMessage>;
|
|
56
|
+
/**
|
|
57
|
+
* The internal `TurnControlRequests` Channel. `steer_user_message` and `cancel_turn` publish to it, and its
|
|
58
|
+
* messages only wake `ResumeTurn` or `AwaitUserMessage`.
|
|
59
|
+
*/
|
|
60
|
+
readonly turnControlRequests: Channel<TurnControlRequest>;
|
|
61
|
+
/** The `TurnCancellationRequest` Attribute: the latest `cancel_turn` request. Only `cancel_turn` writes it. */
|
|
62
|
+
readonly turnCancellationRequest: Attribute<TurnCancellationRequest>;
|
|
63
|
+
/**
|
|
64
|
+
* The internal `ToolCallCancellations` ChannelMap, keyed by tool call ID. `ResumeTurn` publishes to it to wake
|
|
65
|
+
* the Step that waits on a call of a steered or cancelled turn.
|
|
66
|
+
*/
|
|
67
|
+
readonly toolCallCancellations: ChannelMap<ToolCallCancellation>;
|
|
41
68
|
/** The best-effort `AgentEvents` Stream. Rebuild durable state with `get_agent_snapshot`. */
|
|
42
69
|
readonly agentEvents: Stream<AgentEvent>;
|
|
70
|
+
/**
|
|
71
|
+
* The `AgentTraceContext` Attribute: the W3C `traceparent` of the current activation's root span when
|
|
72
|
+
* that span has a valid context, sampled or not; an activation whose root has none, such as one without
|
|
73
|
+
* an OpenTelemetry SDK, deletes it. `RunModel` reads it to join the activation's trace.
|
|
74
|
+
*/
|
|
75
|
+
readonly agentTraceContext: Attribute<string>;
|
|
76
|
+
/** The `AgentPlan` Attribute: the session's plan, unset until `write_todos` first succeeds. */
|
|
77
|
+
readonly agentPlan: Attribute<AgentPlan>;
|
|
78
|
+
/**
|
|
79
|
+
* The `PlanExecutions` ChannelMap, keyed by {@link planExecutionKey}: approved plan executions that
|
|
80
|
+
* `execute_plan` publishes and `AwaitUserMessage` consumes.
|
|
81
|
+
*/
|
|
82
|
+
readonly planExecutions: ChannelMap<PlanExecutionRequest>;
|
|
83
|
+
/**
|
|
84
|
+
* The `PendingPlanExecution` Attribute: the execution `execute_plan` accepted and `AwaitUserMessage` has
|
|
85
|
+
* not consumed yet.
|
|
86
|
+
*/
|
|
87
|
+
readonly pendingPlanExecution: Attribute<PlanExecutionRequest>;
|
|
88
|
+
/**
|
|
89
|
+
* The `ContextSummary` Attribute: the summary that replaces the earlier messages in the model input,
|
|
90
|
+
* set once the session compacts. Only `CompactContext` writes it.
|
|
91
|
+
*/
|
|
92
|
+
readonly contextSummary: Attribute<ContextSummary>;
|
|
93
|
+
/**
|
|
94
|
+
* The `SessionSettings` Attribute: the settings the next turn starts with, from the start input and then each
|
|
95
|
+
* `update_session_settings`. Unset when the session has none.
|
|
96
|
+
*/
|
|
97
|
+
readonly sessionSettings: Attribute<SessionSettings>;
|
|
98
|
+
/**
|
|
99
|
+
* The `TurnSessionSettings` Attribute: the settings a turn started with, tagged with its turn, copied from
|
|
100
|
+
* `SessionSettings` when the turn began. A copy from an earlier turn reads as no settings.
|
|
101
|
+
*/
|
|
102
|
+
readonly turnSessionSettings: Attribute<TurnSessionSettings>;
|
|
103
|
+
/**
|
|
104
|
+
* The `TurnReplySequence` Attribute: where the latest turn's replies start, tagged with its turn. The Step
|
|
105
|
+
* that starts a turn writes it; turn events count the replies from it.
|
|
106
|
+
*/
|
|
107
|
+
readonly turnReplySequence: Attribute<TurnReplySequence>;
|
|
43
108
|
}
|
|
44
109
|
export declare function createAgentSessionPersistence(agentEventsCapacityBytes: number): AgentSessionPersistence;
|
|
45
110
|
/**
|
|
46
|
-
* Returns the `AgentMessages` map instance of a message sequence
|
|
111
|
+
* Returns the `AgentMessages` map instance of a message sequence, which is also the `AgentMessageChunks`
|
|
112
|
+
* instance of a chunk that starts at that sequence.
|
|
113
|
+
*
|
|
114
|
+
* A message stays in `AgentMessages` only while it is in the window; read older ones from their chunk, or
|
|
115
|
+
* page through all of them with `list_agent_messages`.
|
|
47
116
|
*
|
|
48
117
|
* @example
|
|
49
118
|
* ```ts
|
|
@@ -54,3 +123,11 @@ export declare function createAgentSessionPersistence(agentEventsCapacityBytes:
|
|
|
54
123
|
* @throws {RangeError} When `sequence` is not a positive safe integer.
|
|
55
124
|
*/
|
|
56
125
|
export declare function messageSequenceKey(sequence: number): string;
|
|
126
|
+
/**
|
|
127
|
+
* Returns the `PlanExecutions` map instance of a plan revision.
|
|
128
|
+
*
|
|
129
|
+
* @param revision - Positive {@link AgentPlan.revision}.
|
|
130
|
+
* @returns The revision as a decimal, such as `"3"`.
|
|
131
|
+
* @throws {RangeError} When `revision` is not a positive safe integer.
|
|
132
|
+
*/
|
|
133
|
+
export declare function planExecutionKey(revision: number): string;
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
//
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
8
|
import { Attribute, AttributeMap, Channel, ChannelMap, Stream, stringCodec } from "@superdurable/dex";
|
|
9
|
-
import { agentEventCodec, agentInterruptListCodec, agentInterruptResolutionCodec, agentMessageCodec, agentStateCodec, agentToolCallCodec, agentUsageCodec, agentUserMessageCodec, toolCallCompletedCodec, } from "./agent-session-codecs.js";
|
|
9
|
+
import { agentEventCodec, agentInterruptListCodec, agentInterruptResolutionCodec, agentMessageChunkCodec, agentMessageCodec, agentMessageIndexCodec, agentPlanCodec, agentStateCodec, agentToolCallCodec, agentUsageCodec, agentUserMessageCodec, planExecutionRequestCodec, contextSummaryCodec, sessionSettingsCodec, turnSessionSettingsCodec, turnReplySequenceCodec, toolCallCancellationCodec, toolCallCompletedCodec, turnCancellationRequestCodec, turnControlRequestCodec, } from "./agent-session-codecs.js";
|
|
10
10
|
/** Default byte budget of the `AgentEvents` Stream: 10 MiB. */
|
|
11
11
|
export const defaultAgentEventsCapacityBytes = 10 * 1024 * 1024;
|
|
12
12
|
export function createAgentSessionPersistence(agentEventsCapacityBytes) {
|
|
13
13
|
return {
|
|
14
14
|
agentState: new Attribute("AgentState", agentStateCodec),
|
|
15
15
|
agentMessages: new AttributeMap("AgentMessages", agentMessageCodec),
|
|
16
|
+
agentMessageChunks: new AttributeMap("AgentMessageChunks", agentMessageChunkCodec),
|
|
17
|
+
agentMessageIndex: new Attribute("AgentMessageIndex", agentMessageIndexCodec),
|
|
16
18
|
frameworkRunState: new Attribute("FrameworkRunState", stringCodec),
|
|
17
19
|
agentToolCalls: new AttributeMap("AgentToolCalls", agentToolCallCodec),
|
|
18
20
|
pendingInterrupts: new Attribute("PendingInterrupts", agentInterruptListCodec),
|
|
@@ -20,11 +22,27 @@ export function createAgentSessionPersistence(agentEventsCapacityBytes) {
|
|
|
20
22
|
queuedUserMessages: new Channel("QueuedUserMessages", agentUserMessageCodec),
|
|
21
23
|
interruptResolutions: new ChannelMap("InterruptResolutions", agentInterruptResolutionCodec),
|
|
22
24
|
toolCallResults: new Channel("ToolCallResults", toolCallCompletedCodec),
|
|
25
|
+
steeredUserMessages: new Channel("SteeredUserMessages", agentUserMessageCodec),
|
|
26
|
+
turnControlRequests: new Channel("TurnControlRequests", turnControlRequestCodec),
|
|
27
|
+
turnCancellationRequest: new Attribute("TurnCancellationRequest", turnCancellationRequestCodec),
|
|
28
|
+
toolCallCancellations: new ChannelMap("ToolCallCancellations", toolCallCancellationCodec),
|
|
23
29
|
agentEvents: new Stream("AgentEvents", agentEventCodec, agentEventsCapacityBytes),
|
|
30
|
+
agentTraceContext: new Attribute("AgentTraceContext", stringCodec),
|
|
31
|
+
agentPlan: new Attribute("AgentPlan", agentPlanCodec),
|
|
32
|
+
planExecutions: new ChannelMap("PlanExecutions", planExecutionRequestCodec),
|
|
33
|
+
pendingPlanExecution: new Attribute("PendingPlanExecution", planExecutionRequestCodec),
|
|
34
|
+
contextSummary: new Attribute("ContextSummary", contextSummaryCodec),
|
|
35
|
+
sessionSettings: new Attribute("SessionSettings", sessionSettingsCodec),
|
|
36
|
+
turnSessionSettings: new Attribute("TurnSessionSettings", turnSessionSettingsCodec),
|
|
37
|
+
turnReplySequence: new Attribute("TurnReplySequence", turnReplySequenceCodec),
|
|
24
38
|
};
|
|
25
39
|
}
|
|
26
40
|
/**
|
|
27
|
-
* Returns the `AgentMessages` map instance of a message sequence
|
|
41
|
+
* Returns the `AgentMessages` map instance of a message sequence, which is also the `AgentMessageChunks`
|
|
42
|
+
* instance of a chunk that starts at that sequence.
|
|
43
|
+
*
|
|
44
|
+
* A message stays in `AgentMessages` only while it is in the window; read older ones from their chunk, or
|
|
45
|
+
* page through all of them with `list_agent_messages`.
|
|
28
46
|
*
|
|
29
47
|
* @example
|
|
30
48
|
* ```ts
|
|
@@ -40,4 +58,17 @@ export function messageSequenceKey(sequence) {
|
|
|
40
58
|
}
|
|
41
59
|
return String(sequence).padStart(12, "0");
|
|
42
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns the `PlanExecutions` map instance of a plan revision.
|
|
63
|
+
*
|
|
64
|
+
* @param revision - Positive {@link AgentPlan.revision}.
|
|
65
|
+
* @returns The revision as a decimal, such as `"3"`.
|
|
66
|
+
* @throws {RangeError} When `revision` is not a positive safe integer.
|
|
67
|
+
*/
|
|
68
|
+
export function planExecutionKey(revision) {
|
|
69
|
+
if (!Number.isSafeInteger(revision) || revision <= 0) {
|
|
70
|
+
throw new RangeError(`plan revision must be a positive integer: ${revision}`);
|
|
71
|
+
}
|
|
72
|
+
return String(revision);
|
|
73
|
+
}
|
|
43
74
|
//# sourceMappingURL=agent-session-persistence.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-persistence.js","sourceRoot":"","sources":["../../src/agent-session-persistence.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEtG,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"agent-session-persistence.js","sourceRoot":"","sources":["../../src/agent-session-persistence.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEtG,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,6BAA6B,EAC7B,sBAAsB,EACtB,iBAAiB,EACjB,s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,CAAC;QACrD,MAAM,IAAI,UAAU,CAAC,6CAA6C,QAAQ,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SessionSettings } from "./agent-session-values.js";
|
|
2
|
+
/** Largest {@link SessionSettings}, as the UTF-8 bytes of their compact JSON text: 16 KiB. Same in every core. */
|
|
3
|
+
export declare const MAX_SESSION_SETTINGS_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* Extra bytes the session's own Steps and RPC accept over {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
6
|
+
*
|
|
7
|
+
* The cores write some numbers and characters differently, so settings that one core's Client accepted can
|
|
8
|
+
* measure a few bytes more in another core's Worker. The tolerance keeps that from failing a session.
|
|
9
|
+
* {@link validateSessionSettings} checks the exact limit.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SESSION_SETTINGS_SIZE_TOLERANCE_BYTES = 1024;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the size of session settings that {@link MAX_SESSION_SETTINGS_BYTES} limits.
|
|
14
|
+
*
|
|
15
|
+
* The size is the UTF-8 byte length of `JSON.stringify(sessionSettings)`: compact, with characters outside ASCII
|
|
16
|
+
* written as themselves. The Python and Go cores measure their own JSON text, which is the same for strings,
|
|
17
|
+
* integers, booleans, `null`, objects, and arrays, with two exceptions: Python writes floats in their shortest
|
|
18
|
+
* form, such as `1.0` and `1e+16`, where this core writes `1` and `10000000000000000`, and Go escapes U+2028
|
|
19
|
+
* and U+2029. So sizes can differ by a few bytes per float or per such character. The session's Steps and RPC
|
|
20
|
+
* accept {@link SESSION_SETTINGS_SIZE_TOLERANCE_BYTES} more than the limit, so settings that another core's
|
|
21
|
+
* Client accepted never fail a session.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* sessionSettingsSize({ model: "gpt-5-mini" }); // 22
|
|
26
|
+
* ```
|
|
27
|
+
* @param sessionSettings - The settings.
|
|
28
|
+
* @returns The size in bytes.
|
|
29
|
+
* @throws {TypeError} When the settings cannot be written as JSON, such as with a cycle or a `bigint`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sessionSettingsSize(sessionSettings: SessionSettings): number;
|
|
32
|
+
/**
|
|
33
|
+
* Checks that a value can be a session's settings: a JSON object whose compact JSON text fits in
|
|
34
|
+
* {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
35
|
+
*
|
|
36
|
+
* Call it before `Client.startFlow` or the `update_session_settings` RPC, such as in a form handler. A start whose
|
|
37
|
+
* settings the session refuses fails the session at once, and the RPC returns `false`.
|
|
38
|
+
* `AgentSessionTestClient.startSession` calls it.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* validateSessionSettings({ model: "gpt-5-mini" });
|
|
43
|
+
* await client.startFlow(flow, sessionId, { initialMessage: null, sessionSettings: { model: "gpt-5-mini" } });
|
|
44
|
+
* ```
|
|
45
|
+
* @param sessionSettings - The candidate settings.
|
|
46
|
+
* @throws {TypeError} When the value is not a plain JSON object or cannot be written as JSON.
|
|
47
|
+
* @throws {RangeError} When its compact JSON text is larger than {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateSessionSettings(sessionSettings: unknown): asserts sessionSettings is SessionSettings;
|
|
50
|
+
/**
|
|
51
|
+
* Checks settings as the session's Steps and RPC do: {@link validateSessionSettings} with a limit of
|
|
52
|
+
* {@link MAX_SESSION_SETTINGS_BYTES} plus {@link SESSION_SETTINGS_SIZE_TOLERANCE_BYTES}.
|
|
53
|
+
*
|
|
54
|
+
* @param sessionSettings - The candidate settings.
|
|
55
|
+
* @throws {TypeError} When the value is not a plain JSON object or cannot be written as JSON.
|
|
56
|
+
* @throws {RangeError} When its compact JSON text is larger than the session's limit.
|
|
57
|
+
*/
|
|
58
|
+
export declare function checkStoredSessionSettings(sessionSettings: unknown): asserts sessionSettings is SessionSettings;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
/** Largest {@link SessionSettings}, as the UTF-8 bytes of their compact JSON text: 16 KiB. Same in every core. */
|
|
9
|
+
export const MAX_SESSION_SETTINGS_BYTES = 16 * 1024;
|
|
10
|
+
/**
|
|
11
|
+
* Extra bytes the session's own Steps and RPC accept over {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
12
|
+
*
|
|
13
|
+
* The cores write some numbers and characters differently, so settings that one core's Client accepted can
|
|
14
|
+
* measure a few bytes more in another core's Worker. The tolerance keeps that from failing a session.
|
|
15
|
+
* {@link validateSessionSettings} checks the exact limit.
|
|
16
|
+
*/
|
|
17
|
+
export const SESSION_SETTINGS_SIZE_TOLERANCE_BYTES = 1024;
|
|
18
|
+
const utf8Encoder = new TextEncoder();
|
|
19
|
+
/**
|
|
20
|
+
* Returns the size of session settings that {@link MAX_SESSION_SETTINGS_BYTES} limits.
|
|
21
|
+
*
|
|
22
|
+
* The size is the UTF-8 byte length of `JSON.stringify(sessionSettings)`: compact, with characters outside ASCII
|
|
23
|
+
* written as themselves. The Python and Go cores measure their own JSON text, which is the same for strings,
|
|
24
|
+
* integers, booleans, `null`, objects, and arrays, with two exceptions: Python writes floats in their shortest
|
|
25
|
+
* form, such as `1.0` and `1e+16`, where this core writes `1` and `10000000000000000`, and Go escapes U+2028
|
|
26
|
+
* and U+2029. So sizes can differ by a few bytes per float or per such character. The session's Steps and RPC
|
|
27
|
+
* accept {@link SESSION_SETTINGS_SIZE_TOLERANCE_BYTES} more than the limit, so settings that another core's
|
|
28
|
+
* Client accepted never fail a session.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* sessionSettingsSize({ model: "gpt-5-mini" }); // 22
|
|
33
|
+
* ```
|
|
34
|
+
* @param sessionSettings - The settings.
|
|
35
|
+
* @returns The size in bytes.
|
|
36
|
+
* @throws {TypeError} When the settings cannot be written as JSON, such as with a cycle or a `bigint`.
|
|
37
|
+
*/
|
|
38
|
+
export function sessionSettingsSize(sessionSettings) {
|
|
39
|
+
return utf8Encoder.encode(JSON.stringify(sessionSettings)).length;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks that a value can be a session's settings: a JSON object whose compact JSON text fits in
|
|
43
|
+
* {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
44
|
+
*
|
|
45
|
+
* Call it before `Client.startFlow` or the `update_session_settings` RPC, such as in a form handler. A start whose
|
|
46
|
+
* settings the session refuses fails the session at once, and the RPC returns `false`.
|
|
47
|
+
* `AgentSessionTestClient.startSession` calls it.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* validateSessionSettings({ model: "gpt-5-mini" });
|
|
52
|
+
* await client.startFlow(flow, sessionId, { initialMessage: null, sessionSettings: { model: "gpt-5-mini" } });
|
|
53
|
+
* ```
|
|
54
|
+
* @param sessionSettings - The candidate settings.
|
|
55
|
+
* @throws {TypeError} When the value is not a plain JSON object or cannot be written as JSON.
|
|
56
|
+
* @throws {RangeError} When its compact JSON text is larger than {@link MAX_SESSION_SETTINGS_BYTES}.
|
|
57
|
+
*/
|
|
58
|
+
export function validateSessionSettings(sessionSettings) {
|
|
59
|
+
checkSessionSettings(sessionSettings, MAX_SESSION_SETTINGS_BYTES);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks settings as the session's Steps and RPC do: {@link validateSessionSettings} with a limit of
|
|
63
|
+
* {@link MAX_SESSION_SETTINGS_BYTES} plus {@link SESSION_SETTINGS_SIZE_TOLERANCE_BYTES}.
|
|
64
|
+
*
|
|
65
|
+
* @param sessionSettings - The candidate settings.
|
|
66
|
+
* @throws {TypeError} When the value is not a plain JSON object or cannot be written as JSON.
|
|
67
|
+
* @throws {RangeError} When its compact JSON text is larger than the session's limit.
|
|
68
|
+
*/
|
|
69
|
+
export function checkStoredSessionSettings(sessionSettings) {
|
|
70
|
+
checkSessionSettings(sessionSettings, MAX_SESSION_SETTINGS_BYTES + SESSION_SETTINGS_SIZE_TOLERANCE_BYTES);
|
|
71
|
+
}
|
|
72
|
+
function checkSessionSettings(sessionSettings, limitBytes) {
|
|
73
|
+
if (typeof sessionSettings !== "object" || sessionSettings === null || Array.isArray(sessionSettings)) {
|
|
74
|
+
throw new TypeError("session settings must be a JSON object");
|
|
75
|
+
}
|
|
76
|
+
const size = sessionSettingsSize(sessionSettings);
|
|
77
|
+
if (size > limitBytes) {
|
|
78
|
+
throw new RangeError(`session settings are ${size} bytes, more than the ${limitBytes} allowed`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=agent-session-settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-settings.js","sourceRoot":"","sources":["../../src/agent-session-settings.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAI1D,kHAAkH;AAClH,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,IAAI,CAAC;AAE1D,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAEtC;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAC,eAAgC;IAClE,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC;AACpE,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,uBAAuB,CAAC,eAAwB;IAC9D,oBAAoB,CAAC,eAAe,EAAE,0BAA0B,CAAC,CAAC;AACpE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,eAAwB;IACjE,oBAAoB,CAAC,eAAe,EAAE,0BAA0B,GAAG,qCAAqC,CAAC,CAAC;AAC5G,CAAC;AAED,SAAS,oBAAoB,CAAC,eAAwB,EAAE,UAAkB;IACxE,IAAI,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,IAAI,GAAG,mBAAmB,CAAC,eAAkC,CAAC,CAAC;IACrE,IAAI,IAAI,GAAG,UAAU,EAAE,CAAC;QACtB,MAAM,IAAI,UAAU,CAAC,wBAAwB,IAAI,yBAAyB,UAAU,UAAU,CAAC,CAAC;IAClG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ExecuteFailure, type AttributeMapLoad, type RetryPolicy, type StepOptions } from "@superdurable/dex";
|
|
2
|
+
import type { AgentSessionPersistence } from "./agent-session-persistence.js";
|
|
3
|
+
export declare const minuteMs = 60000;
|
|
4
|
+
export declare const modelCallStepOptions: {
|
|
5
|
+
readonly executeMethodTimeoutMs: number;
|
|
6
|
+
readonly heartbeatTimeoutMs: number;
|
|
7
|
+
readonly executeRetry: {
|
|
8
|
+
readonly maximumAttempts: 3;
|
|
9
|
+
readonly totalDurationMs: number;
|
|
10
|
+
};
|
|
11
|
+
readonly executeFailure: ExecuteFailure;
|
|
12
|
+
};
|
|
13
|
+
export declare const recoveryRetry: RetryPolicy;
|
|
14
|
+
export declare const syncDurability: {
|
|
15
|
+
readonly waitForDurability: "sync";
|
|
16
|
+
readonly executeDurability: "sync";
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The archive chunks a Step reads on top of the whole `AgentMessages` window: exact instances, or every chunk
|
|
20
|
+
* when the model input covers them all.
|
|
21
|
+
*/
|
|
22
|
+
export interface MessageChunkLoads {
|
|
23
|
+
readonly isWholeMap: boolean;
|
|
24
|
+
readonly instances: readonly AttributeMapLoad[];
|
|
25
|
+
}
|
|
26
|
+
/** Returns the options of a Step that reads model input and stores messages, with its chunk loads. */
|
|
27
|
+
export declare function messageStepOptions(persistence: AgentSessionPersistence, stepType: string, chunkLoads: MessageChunkLoads): StepOptions;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
import { ExecuteFailure, StepRef } from "@superdurable/dex";
|
|
9
|
+
import { agentSessionStepTypes } from "./agent-session-step-types.js";
|
|
10
|
+
export const minuteMs = 60_000;
|
|
11
|
+
// CompactContext makes one model call, so it shares RunModel's timeouts and retries.
|
|
12
|
+
export const modelCallStepOptions = {
|
|
13
|
+
executeMethodTimeoutMs: 15 * minuteMs,
|
|
14
|
+
heartbeatTimeoutMs: 2 * minuteMs,
|
|
15
|
+
executeRetry: { maximumAttempts: 3, totalDurationMs: 30 * minuteMs },
|
|
16
|
+
executeFailure: ExecuteFailure.proceedTo(new StepRef(agentSessionStepTypes.recordTurnFailure)),
|
|
17
|
+
};
|
|
18
|
+
// Recovery Steps must eventually run; cap their backoff so a returning Worker picks them up quickly.
|
|
19
|
+
export const recoveryRetry = { maximumIntervalMs: 5_000 };
|
|
20
|
+
// An ASYNC FlowConfig could replay a committed result after a Server failover, re-running a write.
|
|
21
|
+
export const syncDurability = { waitForDurability: "sync", executeDurability: "sync" };
|
|
22
|
+
/** Returns the options of a Step that reads model input and stores messages, with its chunk loads. */
|
|
23
|
+
export function messageStepOptions(persistence, stepType, chunkLoads) {
|
|
24
|
+
const loads = {
|
|
25
|
+
executeLoadAttributeMaps: chunkLoads.isWholeMap
|
|
26
|
+
? [persistence.agentMessages, persistence.agentToolCalls, persistence.agentMessageChunks]
|
|
27
|
+
: [persistence.agentMessages, persistence.agentToolCalls],
|
|
28
|
+
...(chunkLoads.instances.length === 0 ? {} : { executeLoadAttributeMapInstances: chunkLoads.instances }),
|
|
29
|
+
};
|
|
30
|
+
switch (stepType) {
|
|
31
|
+
case agentSessionStepTypes.runModel:
|
|
32
|
+
return { ...syncDurability, ...modelCallStepOptions, ...loads };
|
|
33
|
+
case agentSessionStepTypes.applyTurnControl:
|
|
34
|
+
return { ...syncDurability, executeRetry: recoveryRetry, ...loads };
|
|
35
|
+
default:
|
|
36
|
+
throw new TypeError(`Step type ${stepType} does not read the model input`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=agent-session-step-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-step-options.js","sourceRoot":"","sources":["../../src/agent-session-step-options.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,cAAc,EAAE,OAAO,EAA6D,MAAM,mBAAmB,CAAC;AAGvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC/B,qFAAqF;AACrF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,sBAAsB,EAAE,EAAE,GAAG,QAAQ;IACrC,kBAAkB,EAAE,CAAC,GAAG,QAAQ;IAChC,YAAY,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|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Step types of every agent session Flow, shared with the Python core. */
|
|
2
|
+
export declare const agentSessionStepTypes: {
|
|
3
|
+
readonly startAgentSession: "StartAgentSession";
|
|
4
|
+
readonly awaitUserMessage: "AwaitUserMessage";
|
|
5
|
+
readonly runModel: "RunModel";
|
|
6
|
+
readonly compactContext: "CompactContext";
|
|
7
|
+
readonly awaitToolApproval: "AwaitToolApproval";
|
|
8
|
+
readonly awaitQuestionAnswer: "AwaitQuestionAnswer";
|
|
9
|
+
readonly awaitTimer: "AwaitTimer";
|
|
10
|
+
readonly callTool: "CallTool";
|
|
11
|
+
readonly callSingleAttemptTool: "CallSingleAttemptTool";
|
|
12
|
+
readonly pollToolTask: "PollToolTask";
|
|
13
|
+
readonly recordToolFailure: "RecordToolFailure";
|
|
14
|
+
readonly recordToolOutcomeUnknown: "RecordToolOutcomeUnknown";
|
|
15
|
+
readonly resumeTurn: "ResumeTurn";
|
|
16
|
+
readonly applyTurnControl: "ApplyTurnControl";
|
|
17
|
+
readonly recordTurnFailure: "RecordTurnFailure";
|
|
18
|
+
readonly finishTurnCancellation: "FinishTurnCancellation";
|
|
19
|
+
readonly cancelToolTask: "CancelToolTask";
|
|
20
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
// You may not use this file except in compliance with the License.
|
|
5
|
+
// See the LICENSE file in the repository root.
|
|
6
|
+
//
|
|
7
|
+
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
/** Step types of every agent session Flow, shared with the Python core. */
|
|
9
|
+
export const agentSessionStepTypes = {
|
|
10
|
+
startAgentSession: "StartAgentSession",
|
|
11
|
+
awaitUserMessage: "AwaitUserMessage",
|
|
12
|
+
runModel: "RunModel",
|
|
13
|
+
compactContext: "CompactContext",
|
|
14
|
+
awaitToolApproval: "AwaitToolApproval",
|
|
15
|
+
awaitQuestionAnswer: "AwaitQuestionAnswer",
|
|
16
|
+
awaitTimer: "AwaitTimer",
|
|
17
|
+
callTool: "CallTool",
|
|
18
|
+
callSingleAttemptTool: "CallSingleAttemptTool",
|
|
19
|
+
pollToolTask: "PollToolTask",
|
|
20
|
+
recordToolFailure: "RecordToolFailure",
|
|
21
|
+
recordToolOutcomeUnknown: "RecordToolOutcomeUnknown",
|
|
22
|
+
resumeTurn: "ResumeTurn",
|
|
23
|
+
applyTurnControl: "ApplyTurnControl",
|
|
24
|
+
recordTurnFailure: "RecordTurnFailure",
|
|
25
|
+
finishTurnCancellation: "FinishTurnCancellation",
|
|
26
|
+
cancelToolTask: "CancelToolTask",
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=agent-session-step-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-step-types.js","sourceRoot":"","sources":["../../src/agent-session-step-types.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,QAAQ,EAAE,UAAU;IACpB,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;IACtC,mBAAmB,EAAE,qBAAqB;IAC1C,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,qBAAqB,EAAE,uBAAuB;IAC9C,YAAY,EAAE,cAAc;IAC5B,iBAAiB,EAAE,mBAAmB;IACtC,wBAAwB,EAAE,0BAA0B;IACpD,UAAU,EAAE,YAAY;IACxB,gBAAgB,EAAE,kBAAkB;IACpC,iBAAiB,EAAE,mBAAmB;IACtC,sBAAsB,EAAE,wBAAwB;IAChD,cAAc,EAAE,gBAAgB;CACxB,CAAC"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { Wait, type AsyncContext, type Codec, type Context, type Step, type StepDecision, type StepOptions } from "@superdurable/dex";
|
|
1
|
+
import { StepMovement, Wait, type AsyncContext, type Codec, type Context, type RecoveryErrorInfo, type Step, type StepDecision, type StepOptions } from "@superdurable/dex";
|
|
2
|
+
import { type ToolInputRequested } from "./agent-framework-runner.js";
|
|
2
3
|
import { type AgentSessionTransitions } from "./agent-session-transitions.js";
|
|
3
|
-
import { type
|
|
4
|
+
import { type AgentSessionPersistence } from "./agent-session-persistence.js";
|
|
5
|
+
import { type AgentInterruptKind, type AgentSessionStartInput, type AgentToolCallRecord, type CompactContextInput, type PlanStatus } from "./agent-session-values.js";
|
|
6
|
+
/** Start of the Flow failure reason when `StartAgentSession` refuses the start input's settings. */
|
|
7
|
+
export declare const invalidStartSessionSettingsReason = "dex-agents: the start input's session_settings are not valid session settings";
|
|
4
8
|
export declare class StartAgentSessionStep implements Step<AgentSessionStartInput> {
|
|
5
9
|
private readonly transitions;
|
|
6
10
|
readonly inputCodec: Codec<AgentSessionStartInput>;
|
|
@@ -9,15 +13,19 @@ export declare class StartAgentSessionStep implements Step<AgentSessionStartInpu
|
|
|
9
13
|
getStepOptions(): StepOptions;
|
|
10
14
|
execute(context: Context, input: AgentSessionStartInput): StepDecision;
|
|
11
15
|
}
|
|
16
|
+
/** Waits for one queued user message, or an approved plan execution, and starts its turn. */
|
|
12
17
|
export declare class AwaitUserMessageStep implements Step<void> {
|
|
13
18
|
private readonly transitions;
|
|
14
19
|
readonly inputCodec: Codec<void>;
|
|
15
20
|
constructor(transitions: AgentSessionTransitions);
|
|
16
21
|
getStepType(): string;
|
|
17
22
|
getStepOptions(): StepOptions;
|
|
18
|
-
waitFor(): Wait;
|
|
23
|
+
waitFor(context: Context): Wait;
|
|
19
24
|
execute(context: Context): StepDecision;
|
|
25
|
+
private beginUserMessageTurn;
|
|
20
26
|
}
|
|
27
|
+
/** Plan statuses that `execute_plan` accepts and `AwaitUserMessage` waits for. */
|
|
28
|
+
export declare function isExecutablePlanStatus(status: PlanStatus): boolean;
|
|
21
29
|
/** Makes the turn's next model call and fans the requested tool calls out to parallel Steps. */
|
|
22
30
|
export declare class RunModelStep implements Step<void> {
|
|
23
31
|
private readonly transitions;
|
|
@@ -26,8 +34,31 @@ export declare class RunModelStep implements Step<void> {
|
|
|
26
34
|
getStepType(): string;
|
|
27
35
|
getStepOptions(): StepOptions;
|
|
28
36
|
execute(context: AsyncContext): Promise<StepDecision>;
|
|
37
|
+
/** Returns RunModel's move instead of a model call, or `null` to call the model. */
|
|
38
|
+
private decideBeforeModelCall;
|
|
29
39
|
private completeTurn;
|
|
40
|
+
/** Returns the sequence to summarize through before this model call, or `null` to make the call. */
|
|
41
|
+
private selectCompactionBeforeModelCall;
|
|
42
|
+
private startCompaction;
|
|
30
43
|
private requestToolCalls;
|
|
44
|
+
/** A planning turn hides executable tools; a call to one never runs. */
|
|
45
|
+
private rejectPlanningTurnToolCall;
|
|
46
|
+
private deferApplicationToolCall;
|
|
47
|
+
/** Records a built-in call with its fixed policy and routes it to its wait Step; invalid arguments fail at once. */
|
|
48
|
+
private deferBuiltInToolCall;
|
|
49
|
+
/** Replaces the plan and records the call final, in this commit; no tool Step runs. */
|
|
50
|
+
private writeTodos;
|
|
51
|
+
private failBuiltInToolCall;
|
|
52
|
+
}
|
|
53
|
+
/** Summarizes the messages through a sequence for the model input, then moves back to `RunModel`. */
|
|
54
|
+
export declare class CompactContextStep implements Step<CompactContextInput | undefined> {
|
|
55
|
+
private readonly transitions;
|
|
56
|
+
readonly inputCodec: Codec<CompactContextInput | undefined>;
|
|
57
|
+
constructor(transitions: AgentSessionTransitions);
|
|
58
|
+
getStepType(): string;
|
|
59
|
+
getStepOptions(): StepOptions;
|
|
60
|
+
execute(context: AsyncContext, input: CompactContextInput | undefined): Promise<StepDecision>;
|
|
61
|
+
private summarize;
|
|
31
62
|
}
|
|
32
63
|
/** Waits for one tool call's approval or its deadline, then runs or rejects the call. */
|
|
33
64
|
export declare class AwaitToolApprovalStep implements Step<string> {
|
|
@@ -38,8 +69,8 @@ export declare class AwaitToolApprovalStep implements Step<string> {
|
|
|
38
69
|
getStepOptions(): StepOptions;
|
|
39
70
|
waitFor(context: Context, toolCallId: string): Wait;
|
|
40
71
|
execute(context: Context, toolCallId: string): StepDecision;
|
|
72
|
+
private applyResolution;
|
|
41
73
|
private rejectToolCall;
|
|
42
|
-
private writeInterruptResolved;
|
|
43
74
|
}
|
|
44
75
|
/** Runs one tool call; one class serves `CallTool` and `CallSingleAttemptTool`. */
|
|
45
76
|
export declare class ToolCallStep implements Step<string> {
|
|
@@ -50,11 +81,16 @@ export declare class ToolCallStep implements Step<string> {
|
|
|
50
81
|
getStepType(): string;
|
|
51
82
|
getStepOptions(): StepOptions;
|
|
52
83
|
execute(context: AsyncContext, toolCallId: string): Promise<StepDecision>;
|
|
84
|
+
/** Records `awaiting_answer` with the tool's question; `AwaitQuestionAnswer` raises it under the lock. */
|
|
85
|
+
private requestToolInput;
|
|
86
|
+
/** Records `waiting_for_task` and moves to `PollToolTask`, or records a task it cannot poll by effect. */
|
|
87
|
+
private startToolTask;
|
|
53
88
|
}
|
|
54
89
|
/**
|
|
55
90
|
* Failure route of a tool Step; it receives the failed Step's input, the tool call ID.
|
|
56
91
|
* `RecordToolFailure` records `failed` for a `read` call and `outcome_unknown` for a write;
|
|
57
|
-
* `RecordToolOutcomeUnknown` always records `outcome_unknown`.
|
|
92
|
+
* `RecordToolOutcomeUnknown` always records `outcome_unknown`. Either records `failed` with
|
|
93
|
+
* {@link toolCallNotRunErrorPrefix} when the tool certainly never ran.
|
|
58
94
|
*/
|
|
59
95
|
export declare class ToolCallFailureRecordingStep implements Step<string> {
|
|
60
96
|
private readonly transitions;
|
|
@@ -66,7 +102,14 @@ export declare class ToolCallFailureRecordingStep implements Step<string> {
|
|
|
66
102
|
getStepOptions(): StepOptions;
|
|
67
103
|
execute(context: Context, toolCallId: string): StepDecision;
|
|
68
104
|
}
|
|
69
|
-
/**
|
|
105
|
+
/** Returns the final record that a tool Step's failure route writes. */
|
|
106
|
+
export declare function recoveredToolCall(toolCall: AgentToolCallRecord, recoveryError: RecoveryErrorInfo | undefined, status: "failed" | "outcome_unknown"): AgentToolCallRecord;
|
|
107
|
+
/**
|
|
108
|
+
* Waits until every tool call of the batch has a final record, then makes the next model call.
|
|
109
|
+
*
|
|
110
|
+
* A steer wakes it early: it cancels the turn's pending interrupts and Timers, and waits again. After a steer or
|
|
111
|
+
* `cancel_turn`, once every result is in, it moves to `ApplyTurnControl` instead of `RunModel`.
|
|
112
|
+
*/
|
|
70
113
|
export declare class ResumeTurnStep implements Step<number> {
|
|
71
114
|
private readonly transitions;
|
|
72
115
|
readonly inputCodec: Codec<number>;
|
|
@@ -74,13 +117,63 @@ export declare class ResumeTurnStep implements Step<number> {
|
|
|
74
117
|
getStepType(): string;
|
|
75
118
|
getStepOptions(): StepOptions;
|
|
76
119
|
waitFor(_context: Context, expectedResultCount: number): Wait;
|
|
77
|
-
execute(context: Context): StepDecision;
|
|
120
|
+
execute(context: Context, expectedResultCount: number): StepDecision;
|
|
121
|
+
/** Cancels the turn's pending interrupts and wakes each Step waiting for a person or a Timer. */
|
|
122
|
+
private wakeWaitingToolCalls;
|
|
78
123
|
}
|
|
79
|
-
|
|
124
|
+
/** Ends a steered or cancelled turn, then starts a turn with the steered messages. */
|
|
125
|
+
export declare class ApplyTurnControlStep implements Step<void> {
|
|
80
126
|
private readonly transitions;
|
|
81
127
|
readonly inputCodec: Codec<void>;
|
|
82
128
|
constructor(transitions: AgentSessionTransitions);
|
|
83
129
|
getStepType(): string;
|
|
84
130
|
getStepOptions(): StepOptions;
|
|
131
|
+
waitFor(): Wait;
|
|
85
132
|
execute(context: Context): StepDecision;
|
|
86
133
|
}
|
|
134
|
+
/** Ends a failed turn; it is the failure route of `RunModel` and `CompactContext`, so it takes either's input. */
|
|
135
|
+
export declare class RecordTurnFailureStep implements Step<CompactContextInput | undefined> {
|
|
136
|
+
private readonly transitions;
|
|
137
|
+
readonly inputCodec: Codec<CompactContextInput | undefined>;
|
|
138
|
+
constructor(transitions: AgentSessionTransitions);
|
|
139
|
+
getStepType(): string;
|
|
140
|
+
getStepOptions(): StepOptions;
|
|
141
|
+
execute(context: Context): StepDecision;
|
|
142
|
+
}
|
|
143
|
+
/** `last_turn_error` of a turn whose runner stored messages incrementally without the builder. */
|
|
144
|
+
export declare const missingUnfinishedTurnMessageBuilder = "a runner that sets ToolCallsRequested.newMessages must implement buildUnfinishedTurnMessages";
|
|
145
|
+
/**
|
|
146
|
+
* Returns the full options of a tool Step type. With a tool call ID, the Step loads only that call's
|
|
147
|
+
* record; a movement's options replace the Step's static options, so every option is repeated here.
|
|
148
|
+
*/
|
|
149
|
+
export declare function toolStepOptions(persistence: AgentSessionPersistence, stepType: string, toolCallId?: string): StepOptions;
|
|
150
|
+
export declare function toolStepMovement(persistence: AgentSessionPersistence, stepType: string, toolCallId: string): StepMovement<string>;
|
|
151
|
+
/** Moves to `PollToolTask`; a poll that keeps failing leaves the task running, so the call is recorded by effect. */
|
|
152
|
+
export declare function toolTaskPollMovement(persistence: AgentSessionPersistence, toolCall: AgentToolCallRecord): StepMovement<string>;
|
|
153
|
+
/** Returns the record of a tool's question: `awaiting_answer`, or `failed` when it is blank. */
|
|
154
|
+
export declare function recordToolInputRequest(toolCall: AgentToolCallRecord, request: ToolInputRequested): AgentToolCallRecord;
|
|
155
|
+
/** Returns a final record for a task that cannot be polled: `failed` for a read, else `outcome_unknown`. */
|
|
156
|
+
export declare function recordToolTaskDefect(toolCall: AgentToolCallRecord, error: string): AgentToolCallRecord;
|
|
157
|
+
/** Returns a poll interval in whole seconds from 1 to a day, or `null` when it is not a finite number. */
|
|
158
|
+
export declare function toolTaskPollIntervalSeconds(seconds: unknown): number | null;
|
|
159
|
+
/** Record fields of a call without a pending tool question. */
|
|
160
|
+
export declare const noPendingToolQuestion: {
|
|
161
|
+
readonly inputQuestion: null;
|
|
162
|
+
readonly inputChoices: readonly [];
|
|
163
|
+
readonly inputAllowsFreeText: true;
|
|
164
|
+
};
|
|
165
|
+
/** Moves to `AwaitQuestionAnswer`, which reads the answer count to tell an unraised question from an answer. */
|
|
166
|
+
export declare function questionAnswerMovement(persistence: AgentSessionPersistence, toolCall: AgentToolCallRecord): StepMovement<string>;
|
|
167
|
+
/** An `ask_user` question uses the tool call ID; a tool's `n`-th question appends `-input-<n>`. */
|
|
168
|
+
export declare function questionInterruptId(toolCall: AgentToolCallRecord): string;
|
|
169
|
+
/** The interrupt a waiting tool call answers to: its ID and kind. */
|
|
170
|
+
export interface WaitingToolCallInterrupt {
|
|
171
|
+
readonly interruptId: string;
|
|
172
|
+
readonly kind: AgentInterruptKind;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Records a call that `ToolCallCancellations` woke as cancelled, or waits again. Pass `interrupt` `null` for a
|
|
176
|
+
* durable wait.
|
|
177
|
+
*/
|
|
178
|
+
export declare function cancelWaitingToolCall(transitions: AgentSessionTransitions, context: Context, toolCall: AgentToolCallRecord, interrupt: WaitingToolCallInterrupt | null, waitAgain: StepMovement<string>): StepDecision;
|
|
179
|
+
export declare function isToolInputRequested(outcome: unknown): outcome is ToolInputRequested;
|