@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
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
8
|
import { setTimeout as delay } from "node:timers/promises";
|
|
9
9
|
import { RpcLockConflictError } from "@superdurable/dex";
|
|
10
|
+
import { validateSessionSettings } from "../agent-session-settings.js";
|
|
10
11
|
import { pollUntil } from "./polling.js";
|
|
11
12
|
const lockConflictRetryTimeoutMs = 30_000;
|
|
12
13
|
const lockConflictRetryIntervalMs = 50;
|
|
@@ -48,19 +49,82 @@ export class AgentSessionTestClient {
|
|
|
48
49
|
* @param sessionId - Flow ID of the new session.
|
|
49
50
|
* @param initialMessage - First user message, or `null` to start idle. Defaults to `null`.
|
|
50
51
|
* @param startFlowOptions - Start options, such as a `configOverride` with `stepDurability`.
|
|
52
|
+
* @param sessionSettings - The session's settings, or `null` to start without settings. Defaults to `null`.
|
|
51
53
|
* @returns A Promise that resolves after Dex accepted the start.
|
|
54
|
+
* @throws {TypeError | RangeError} From `validateSessionSettings`, before anything is sent.
|
|
52
55
|
*/
|
|
53
|
-
async startSession(sessionId, initialMessage = null, startFlowOptions = {}) {
|
|
54
|
-
|
|
56
|
+
async startSession(sessionId, initialMessage = null, startFlowOptions = {}, sessionSettings = null) {
|
|
57
|
+
if (sessionSettings !== null) {
|
|
58
|
+
validateSessionSettings(sessionSettings);
|
|
59
|
+
}
|
|
60
|
+
await this.client.startFlow(this.flow, sessionId, { initialMessage, sessionSettings }, startFlowOptions);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Calls `update_session_settings`.
|
|
64
|
+
* @param sessionId - Session Flow ID.
|
|
65
|
+
* @param sessionSettings - The complete new settings; `{}` clears them.
|
|
66
|
+
* @returns The RPC result: `false` before the session initialized or for settings over the limit.
|
|
67
|
+
*/
|
|
68
|
+
updateSessionSettings(sessionId, sessionSettings) {
|
|
69
|
+
return this.client.invokeRPC(this.flow.updateSessionSettings, sessionId, { sessionSettings });
|
|
55
70
|
}
|
|
56
71
|
/**
|
|
57
72
|
* Calls `send_user_message`.
|
|
58
73
|
* @param sessionId - Session Flow ID.
|
|
59
74
|
* @param text - Message text.
|
|
60
|
-
* @
|
|
75
|
+
* @param planMode - Whether the message starts a planning turn. Defaults to `false`.
|
|
76
|
+
* @returns The RPC result: `false` for blank text, or for a `planMode` message when plan mode is off.
|
|
61
77
|
*/
|
|
62
|
-
sendUserMessage(sessionId, text) {
|
|
63
|
-
return this.client.invokeRPC(this.flow.sendUserMessage, sessionId, { text });
|
|
78
|
+
sendUserMessage(sessionId, text, planMode = false) {
|
|
79
|
+
return this.client.invokeRPC(this.flow.sendUserMessage, sessionId, { text, planMode });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Calls `execute_plan`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
83
|
+
* @param sessionId - Session Flow ID.
|
|
84
|
+
* @param revision - Plan revision to execute.
|
|
85
|
+
* @returns The RPC result: `false` when the revision is stale, already pending, or the session is busy.
|
|
86
|
+
*/
|
|
87
|
+
executePlan(sessionId, revision) {
|
|
88
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.executePlan, sessionId, { revision }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Calls `steer_user_message` with new text; while no turn is active, the RPC queues it.
|
|
92
|
+
* @param sessionId - Session Flow ID.
|
|
93
|
+
* @param text - Text of the steered message.
|
|
94
|
+
* @returns The RPC result: `false` for blank text or a turn that does not accept steering.
|
|
95
|
+
*/
|
|
96
|
+
steerUserMessage(sessionId, text) {
|
|
97
|
+
return this.client.invokeRPC(this.flow.steerUserMessage, sessionId, { messageId: null, text });
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Calls `steer_user_message` with a queued message's ID, which moves that message.
|
|
101
|
+
* @param sessionId - Session Flow ID.
|
|
102
|
+
* @param messageId - {@link PendingUserMessage.messageId} of a queued message.
|
|
103
|
+
* @returns The RPC result: `false` when the message is no longer queued.
|
|
104
|
+
* @throws {ChannelMessageNotFoundError} When the session consumed the message while the RPC ran.
|
|
105
|
+
*/
|
|
106
|
+
steerQueuedMessage(sessionId, messageId) {
|
|
107
|
+
return this.client.invokeRPC(this.flow.steerUserMessage, sessionId, { messageId, text: null });
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Calls `delete_queued_message`.
|
|
111
|
+
* @param sessionId - Session Flow ID.
|
|
112
|
+
* @param messageId - {@link PendingUserMessage.messageId} of a queued message.
|
|
113
|
+
* @returns The RPC result: `false` when the message is no longer queued.
|
|
114
|
+
* @throws {ChannelMessageNotFoundError} When the session consumed the message while the RPC ran.
|
|
115
|
+
*/
|
|
116
|
+
deleteQueuedMessage(sessionId, messageId) {
|
|
117
|
+
return this.client.invokeRPC(this.flow.deleteQueuedMessage, sessionId, { messageId });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Calls `cancel_turn`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
121
|
+
* @param sessionId - Session Flow ID.
|
|
122
|
+
* @param turnId - The turn to stop, or `null` for the active turn. Defaults to `null`.
|
|
123
|
+
* @returns The RPC result: `false` when no turn is active, `turnId` names another turn, or the turn does not
|
|
124
|
+
* accept cancellation.
|
|
125
|
+
*/
|
|
126
|
+
cancelTurn(sessionId, turnId = null) {
|
|
127
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.cancelTurn, sessionId, { turnId }));
|
|
64
128
|
}
|
|
65
129
|
/**
|
|
66
130
|
* Calls `resolve_interrupt`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
@@ -70,23 +134,18 @@ export class AgentSessionTestClient {
|
|
|
70
134
|
* @param rejectionMessage - Text shown to the model on rejection. Defaults to `null`.
|
|
71
135
|
* @returns The RPC result: `false` when the interrupt was not pending.
|
|
72
136
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
await delay(lockConflictRetryIntervalMs);
|
|
89
|
-
}
|
|
137
|
+
resolveInterrupt(sessionId, interruptId, approved, rejectionMessage = null) {
|
|
138
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.resolveInterrupt, sessionId, { interruptId, approved, rejectionMessage }));
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Calls `answer_question`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
142
|
+
* @param sessionId - Session Flow ID.
|
|
143
|
+
* @param interruptId - Pending `question` interrupt to answer.
|
|
144
|
+
* @param answer - The answer text.
|
|
145
|
+
* @returns The RPC result: `false` when the question was not pending or the answer was refused.
|
|
146
|
+
*/
|
|
147
|
+
answerQuestion(sessionId, interruptId, answer) {
|
|
148
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.answerQuestion, sessionId, { interruptId, answer }));
|
|
90
149
|
}
|
|
91
150
|
/**
|
|
92
151
|
* Calls `get_agent_snapshot`.
|
|
@@ -214,4 +273,18 @@ export class AgentSessionTestClient {
|
|
|
214
273
|
return newestFirst.reverse();
|
|
215
274
|
}
|
|
216
275
|
}
|
|
276
|
+
async function retryLockConflicts(invoke) {
|
|
277
|
+
const deadline = Date.now() + lockConflictRetryTimeoutMs;
|
|
278
|
+
for (;;) {
|
|
279
|
+
try {
|
|
280
|
+
return await invoke();
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
if (!(error instanceof RpcLockConflictError) || Date.now() >= deadline) {
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
await delay(lockConflictRetryIntervalMs);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
217
290
|
//# sourceMappingURL=agent-session-test-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-test-client.js","sourceRoot":"","sources":["../../../src/testing/agent-session-test-client.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAsC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-session-test-client.js","sourceRoot":"","sources":["../../../src/testing/agent-session-test-client.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,oBAAoB,EAAsC,MAAM,mBAAmB,CAAC;AAc7F,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,cAAc,GAAG,GAAG,CAAC;AAQ3B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,sBAAsB;IAQf;IAEA;IATlB;;;;OAIG;IACH;IACE,kCAAkC;IAClB,MAAc;IAC9B,8CAA8C;IAC9B,IAAiE;QAFjE,WAAM,GAAN,MAAM,CAAQ;QAEd,SAAI,GAAJ,IAAI,CAA6D;IAChF,CAAC;IAEJ;;;;;;;;OAQG;IAC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GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,0BAA0B,CAAC;IACzD,SAAS,CAAC;QACR,IAAI,CAAC;YACH,OAAO,MAAM,MAAM,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,IAAI,CAAC,CAAC,KAAK,YAAY,oBAAoB,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;gBACvE,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,MAAM,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -3,5 +3,6 @@ export { AgentTestEnvironment, type AgentTestEnvironmentOptions, } from "./agent
|
|
|
3
3
|
export { KillableWorkerProcess, agentWorkerBlobCacheDirectoryVariable, agentWorkerReadyLine, agentWorkerServerAddressVariable, runAgentWorkerProcess, type KillableWorkerProcessOptions, } from "./agent-worker-process.js";
|
|
4
4
|
export { FileGate, InvocationLog } from "./coordination.js";
|
|
5
5
|
export { pollUntil, type PollOptions } from "./polling.js";
|
|
6
|
+
export { ScriptedModelClient, scriptedModelApi, scriptedModelProvider, type ScriptedModelReply, type ScriptedModelResponder, type ScriptedToolCall, } from "./scripted-model-client.js";
|
|
6
7
|
export { executeCompletedEvent, readStepHistory, waitForCompletedEvent, type ReadStepHistoryOptions, type StepHistoryEntry, } from "./step-history.js";
|
|
7
8
|
export { PrivateDexEngine, findFreeLoopbackPort, findFreeLoopbackPorts, type PrivateDexEngineOptions, } from "./private-dex-engine.js";
|
|
@@ -10,6 +10,7 @@ export { AgentTestEnvironment, } from "./agent-test-environment.js";
|
|
|
10
10
|
export { KillableWorkerProcess, agentWorkerBlobCacheDirectoryVariable, agentWorkerReadyLine, agentWorkerServerAddressVariable, runAgentWorkerProcess, } from "./agent-worker-process.js";
|
|
11
11
|
export { FileGate, InvocationLog } from "./coordination.js";
|
|
12
12
|
export { pollUntil } from "./polling.js";
|
|
13
|
+
export { ScriptedModelClient, scriptedModelApi, scriptedModelProvider, } from "./scripted-model-client.js";
|
|
13
14
|
export { executeCompletedEvent, readStepHistory, waitForCompletedEvent, } from "./step-history.js";
|
|
14
15
|
export { PrivateDexEngine, findFreeLoopbackPort, findFreeLoopbackPorts, } from "./private-dex-engine.js";
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,sBAAsB,GAEvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,qBAAqB,EACrB,qCAAqC,EACrC,oBAAoB,EACpB,gCAAgC,EAChC,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GAGtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EACL,sBAAsB,GAEvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,oBAAoB,GAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,qBAAqB,EACrB,qCAAqC,EACrC,oBAAoB,EACpB,gCAAgC,EAChC,qBAAqB,GAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GAItB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,qBAAqB,GAGtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC"}
|
|
@@ -17,6 +17,15 @@ export interface PrivateDexEngineOptions {
|
|
|
17
17
|
readonly stateDirectory?: string;
|
|
18
18
|
/** Milliseconds to wait for the engine to report readiness. Defaults to 60,000. */
|
|
19
19
|
readonly readyTimeoutMs?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Path of a `dex-server-zd` YAML file with configuration overrides, passed as `dexcli dev -zd-config`.
|
|
22
|
+
* Use it to test server settings, such as `streamStore: { backend: disabled }`, which drops
|
|
23
|
+
* Step Stream writes. When omitted, the engine gets a file that sets only
|
|
24
|
+
* `dev.durabilityMode: processCrashSafe`, which skips fsync and survives a process kill but not a host
|
|
25
|
+
* crash. A file of your own replaces it, so set `dev.durabilityMode` there too, or the engine uses the
|
|
26
|
+
* slower `strict` default of `dex-server-zd` 0.1.18 and later.
|
|
27
|
+
*/
|
|
28
|
+
readonly serverZdConfigPath?: string;
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
31
|
* A private `dexcli dev --engine zd` instance on free loopback ports, owned by one test process.
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
// See the LICENSE file in the repository root.
|
|
6
6
|
//
|
|
7
7
|
// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
-
import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
8
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
9
9
|
import { createServer } from "node:net";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
12
|
import { ChildProcessGroup } from "./child-process-group.js";
|
|
13
13
|
const engineReadyLine = "Dex development environment is ready";
|
|
14
14
|
const startAttempts = 3;
|
|
15
|
+
// A config file also works with dexcli releases that predate --durability.
|
|
16
|
+
const processCrashSafeServerZdConfig = "dev:\n durabilityMode: processCrashSafe\n";
|
|
15
17
|
/**
|
|
16
18
|
* A private `dexcli dev --engine zd` instance on free loopback ports, owned by one test process.
|
|
17
19
|
*
|
|
@@ -69,6 +71,11 @@ export class PrivateDexEngine {
|
|
|
69
71
|
const stateDirectory = options.stateDirectory ?? mkdtempSync(join(tmpdir(), "dex-agents-engine-"));
|
|
70
72
|
mkdirSync(stateDirectory, { recursive: true });
|
|
71
73
|
const logPath = join(stateDirectory, "dexcli.log");
|
|
74
|
+
let configPath = options.serverZdConfigPath;
|
|
75
|
+
if (configPath === undefined) {
|
|
76
|
+
configPath = join(stateDirectory, "zd-overrides.yaml");
|
|
77
|
+
writeFileSync(configPath, processCrashSafeServerZdConfig);
|
|
78
|
+
}
|
|
72
79
|
let lastFailure;
|
|
73
80
|
for (let attempt = 1; attempt <= startAttempts; attempt += 1) {
|
|
74
81
|
const [dexPort, webPort] = await findFreeLoopbackPorts(2);
|
|
@@ -94,6 +101,7 @@ export class PrivateDexEngine {
|
|
|
94
101
|
if (serverZdPath !== undefined) {
|
|
95
102
|
commandArguments.push("-zd-binary", serverZdPath);
|
|
96
103
|
}
|
|
104
|
+
commandArguments.push("-zd-config", configPath);
|
|
97
105
|
try {
|
|
98
106
|
const processGroup = await ChildProcessGroup.start({
|
|
99
107
|
description: "dexcli dev",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"private-dex-engine.js","sourceRoot":"","sources":["../../../src/testing/private-dex-engine.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"private-dex-engine.js","sourceRoot":"","sources":["../../../src/testing/private-dex-engine.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACpF,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,MAAM,eAAe,GAAG,sCAAsC,CAAC;AAC/D,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,2EAA2E;AAC3E,MAAM,8BAA8B,GAAG,4CAA4C,CAAC;AAgCpF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,gBAAgB;IAGT;IAEA;IAEA;IAEA;IACC;IACA;IAVnB;IACE,0FAA0F;IAC1E,aAAqB;IACrC,wEAAwE;IACxD,MAAc;IAC9B,yEAAyE;IACzD,cAAsB;IACtC,6DAA6D;IAC7C,OAAe,EACd,YAA+B,EAC/B,qBAA8B;QAR/B,kBAAa,GAAb,aAAa,CAAQ;QAErB,WAAM,GAAN,MAAM,CAAQ;QAEd,mBAAc,GAAd,cAAc,CAAQ;QAEtB,YAAO,GAAP,OAAO,CAAQ;QACd,iBAAY,GAAZ,YAAY,CAAmB;QAC/B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AAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC,CAAC;IAC3D,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ScriptedModelClient, scriptedModelApi, scriptedModelProvider, type ScriptedModelReply, type ScriptedModelResponder, type ScriptedToolCall, } from "../stepwise/scripted-model-client.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
// The scripted model client lives in the stepwise entry point; this path keeps the 0.1.0 module.
|
|
9
|
+
export { ScriptedModelClient, scriptedModelApi, scriptedModelProvider, } from "../stepwise/scripted-model-client.js";
|
|
10
|
+
//# sourceMappingURL=scripted-model-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripted-model-client.js","sourceRoot":"","sources":["../../../src/testing/scripted-model-client.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAG1D,iGAAiG;AACjG,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,GAItB,MAAM,sCAAsC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentEvent, AgentSnapshot } from "../agent-session-values.js";
|
|
2
|
+
import type { AgentEventJson } from "./agent-ui-message-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts an `AgentEvent` to its snake_case wire JSON, the format of the plain Server-Sent Events stream.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const message = await client.readStream(sessionId, flow.agentEvents, resumeToken);
|
|
9
|
+
* response.write(`data: ${JSON.stringify(convertAgentEventToJson(message.value))}\n\n`);
|
|
10
|
+
* ```
|
|
11
|
+
* @param event - Event read from the `AgentEvents` Stream.
|
|
12
|
+
* @returns A new object with `type`, `turn_id`, `attempt`, `step_execution_id`, and `payload` text.
|
|
13
|
+
*/
|
|
14
|
+
export declare function convertAgentEventToJson(event: AgentEvent): AgentEventJson;
|
|
15
|
+
/**
|
|
16
|
+
* Converts an `AgentSnapshot` to the snake_case JSON a browser reads, the same JSON the Python core produces.
|
|
17
|
+
*
|
|
18
|
+
* Use it when a browser shared with Python backends reads the snapshot. It is the `get_agent_snapshot` wire
|
|
19
|
+
* format without the fields only the session's Steps use. Messages leave out `framework_item`, the
|
|
20
|
+
* framework's replay data, which can hold the agent's instructions. Tool calls leave out
|
|
21
|
+
* `tool_source_reference`, `trace_context`, `input_continuation`, `input_answers`, and `task_answer_pending`.
|
|
22
|
+
*
|
|
23
|
+
* `session_settings` is included as stored, so the browser sees the settings the next turn starts with. Keep
|
|
24
|
+
* anything a browser must not see out of session settings, or remove the key before serving the JSON.
|
|
25
|
+
*
|
|
26
|
+
* @param snapshot - Output of the `get_agent_snapshot` RPC.
|
|
27
|
+
* @returns A new JSON object with `state`, `messages`, `pending_interrupts`, `tool_calls`, `usage`, and
|
|
28
|
+
* `queued_message_count`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function convertAgentSnapshotToJson(snapshot: AgentSnapshot): Readonly<Record<string, unknown>>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 { encodeAgentSnapshot } from "../agent-session-codecs.js";
|
|
9
|
+
/**
|
|
10
|
+
* Converts an `AgentEvent` to its snake_case wire JSON, the format of the plain Server-Sent Events stream.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const message = await client.readStream(sessionId, flow.agentEvents, resumeToken);
|
|
15
|
+
* response.write(`data: ${JSON.stringify(convertAgentEventToJson(message.value))}\n\n`);
|
|
16
|
+
* ```
|
|
17
|
+
* @param event - Event read from the `AgentEvents` Stream.
|
|
18
|
+
* @returns A new object with `type`, `turn_id`, `attempt`, `step_execution_id`, and `payload` text.
|
|
19
|
+
*/
|
|
20
|
+
export function convertAgentEventToJson(event) {
|
|
21
|
+
return {
|
|
22
|
+
type: event.type,
|
|
23
|
+
turn_id: event.turnId,
|
|
24
|
+
attempt: event.attempt,
|
|
25
|
+
step_execution_id: event.stepExecutionId,
|
|
26
|
+
payload: event.payload,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
// Replay, routing, tracing, and tool resume state that only the session's Steps read.
|
|
30
|
+
const workerOnlyMessageFieldNames = new Set(["framework_item"]);
|
|
31
|
+
const workerOnlyToolCallFieldNames = new Set([
|
|
32
|
+
"tool_source_reference",
|
|
33
|
+
"trace_context",
|
|
34
|
+
"input_continuation",
|
|
35
|
+
"input_answers",
|
|
36
|
+
"task_answer_pending",
|
|
37
|
+
]);
|
|
38
|
+
/**
|
|
39
|
+
* Converts an `AgentSnapshot` to the snake_case JSON a browser reads, the same JSON the Python core produces.
|
|
40
|
+
*
|
|
41
|
+
* Use it when a browser shared with Python backends reads the snapshot. It is the `get_agent_snapshot` wire
|
|
42
|
+
* format without the fields only the session's Steps use. Messages leave out `framework_item`, the
|
|
43
|
+
* framework's replay data, which can hold the agent's instructions. Tool calls leave out
|
|
44
|
+
* `tool_source_reference`, `trace_context`, `input_continuation`, `input_answers`, and `task_answer_pending`.
|
|
45
|
+
*
|
|
46
|
+
* `session_settings` is included as stored, so the browser sees the settings the next turn starts with. Keep
|
|
47
|
+
* anything a browser must not see out of session settings, or remove the key before serving the JSON.
|
|
48
|
+
*
|
|
49
|
+
* @param snapshot - Output of the `get_agent_snapshot` RPC.
|
|
50
|
+
* @returns A new JSON object with `state`, `messages`, `pending_interrupts`, `tool_calls`, `usage`, and
|
|
51
|
+
* `queued_message_count`.
|
|
52
|
+
*/
|
|
53
|
+
export function convertAgentSnapshotToJson(snapshot) {
|
|
54
|
+
const snapshotJson = encodeAgentSnapshot(snapshot);
|
|
55
|
+
return {
|
|
56
|
+
...snapshotJson,
|
|
57
|
+
messages: snapshotJson["messages"].map((message) => omitJsonFields(message, workerOnlyMessageFieldNames)),
|
|
58
|
+
tool_calls: snapshotJson["tool_calls"].map((toolCall) => omitJsonFields(toolCall, workerOnlyToolCallFieldNames)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function omitJsonFields(value, fieldNames) {
|
|
62
|
+
return Object.fromEntries(Object.entries(value).filter(([fieldName]) => !fieldNames.has(fieldName)));
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=agent-event-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-event-json.js","sourceRoot":"","sources":["../../../src/ui-stream/agent-event-json.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAE1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAIjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAiB;IACvD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,MAAM;QACrB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,iBAAiB,EAAE,KAAK,CAAC,eAAe;QACxC,OAAO,EAAE,KAAK,CAAC,OAAO;KACvB,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,MAAM,2BAA2B,GAAwB,IAAI,GAAG,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACrF,MAAM,4BAA4B,GAAwB,IAAI,GAAG,CAAC;IAChE,uBAAuB;IACvB,eAAe;IACf,oBAAoB;IACpB,eAAe;IACf,qBAAqB;CACtB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,0BAA0B,CAAC,QAAuB;IAChE,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,CAA4B,CAAC;IAC9E,OAAO;QACL,GAAG,YAAY;QACf,QAAQ,EAAG,YAAY,CAAC,UAAU,CAA+B,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAChF,cAAc,CAAC,OAAO,EAAE,2BAA2B,CAAC,CACrD;QACD,UAAU,EAAG,YAAY,CAAC,YAAY,CAA+B,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CACrF,cAAc,CAAC,QAAQ,EAAE,4BAA4B,CAAC,CACvD;KACF,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CACrB,KAA8B,EAC9B,UAA+B;IAE/B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACvG,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Client, StreamMessage } from "@superdurable/dex";
|
|
2
|
+
import type { AgentFrameworkRunner, DeferredToolOutcome } from "../agent-framework-runner.js";
|
|
3
|
+
import type { AgentSessionFlow } from "../agent-session-flow.js";
|
|
4
|
+
import type { AgentEvent, AgentSnapshot } from "../agent-session-values.js";
|
|
5
|
+
/** HTTP headers of the plain `AgentEvents` Server-Sent Events response. */
|
|
6
|
+
export declare const agentEventStreamHeaders: Readonly<Record<string, string>>;
|
|
7
|
+
/**
|
|
8
|
+
* Selects the agent session and Stream position of a plain `AgentEvents` Server-Sent Events stream.
|
|
9
|
+
*
|
|
10
|
+
* Pass it to {@link streamAgentEventSseFrames} or {@link createAgentEventSseResponse}.
|
|
11
|
+
*/
|
|
12
|
+
export interface AgentEventSseOptions {
|
|
13
|
+
/** Client used for every Stream read. The caller keeps ownership. */
|
|
14
|
+
readonly client: Client;
|
|
15
|
+
/** The agent session Flow, the same object the Worker registered. */
|
|
16
|
+
readonly flow: AgentSessionFlow<AgentFrameworkRunner<DeferredToolOutcome>>;
|
|
17
|
+
/** Session ID: the Flow ID of the agent session. */
|
|
18
|
+
readonly flowId: string;
|
|
19
|
+
/**
|
|
20
|
+
* Dex resume token of the last event the browser received: the `Last-Event-ID` request header, or the
|
|
21
|
+
* `resumeToken` of {@link readAgentEventStreamSnapshot} on the first connection. Omit it, or pass `""`,
|
|
22
|
+
* to start at the oldest retained event.
|
|
23
|
+
*/
|
|
24
|
+
readonly resumeToken?: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Long-poll duration of one Stream read, in milliseconds. It must be a whole number of seconds. The
|
|
27
|
+
* stream sends a keep-alive comment after each empty poll. Defaults to 10,000.
|
|
28
|
+
*/
|
|
29
|
+
readonly pollTimeoutMs?: number;
|
|
30
|
+
/** Ends the stream before its next Stream read once aborted, such as the request's `signal`. */
|
|
31
|
+
readonly signal?: AbortSignal | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** A session snapshot and the Dex resume token that a plain event stream opened with it starts from. */
|
|
34
|
+
export interface AgentEventStreamSnapshot {
|
|
35
|
+
/** Output of the `get_agent_snapshot` RPC. */
|
|
36
|
+
readonly snapshot: AgentSnapshot;
|
|
37
|
+
/**
|
|
38
|
+
* Dex resume token to open the event stream with. While a turn is active it replays that turn's events
|
|
39
|
+
* from its first retained event; otherwise it starts after the newest event read before the snapshot.
|
|
40
|
+
*/
|
|
41
|
+
readonly resumeToken: string;
|
|
42
|
+
}
|
|
43
|
+
/** Snake_case wire JSON of an {@link AgentEventStreamSnapshot}, the same JSON as the Python core. */
|
|
44
|
+
export interface AgentEventStreamSnapshotJson {
|
|
45
|
+
/** The `AgentSnapshot` wire JSON. */
|
|
46
|
+
readonly snapshot: Readonly<Record<string, unknown>>;
|
|
47
|
+
/** Dex resume token to open the event stream with. */
|
|
48
|
+
readonly resume_token: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Formats one `AgentEvents` message as a Server-Sent Event whose `id` is its Dex resume token.
|
|
52
|
+
*
|
|
53
|
+
* An `EventSource` sends the `id` back as the `Last-Event-ID` header when it reconnects. The event has no
|
|
54
|
+
* `event:` field, so `EventSource.onmessage` receives every event; switch on `type` in the data.
|
|
55
|
+
*
|
|
56
|
+
* @param message - Message read from the `AgentEvents` Stream.
|
|
57
|
+
* @returns `id: <resume token>`, then `data: <AgentEvent wire JSON>`, then a blank line.
|
|
58
|
+
*/
|
|
59
|
+
export declare function formatAgentEventSseFrame(message: StreamMessage<AgentEvent>): string;
|
|
60
|
+
/**
|
|
61
|
+
* Yields an agent session's `AgentEvents` as Server-Sent Event frames, resuming after a Dex resume token.
|
|
62
|
+
*
|
|
63
|
+
* Each event becomes one frame whose `id` is its Dex resume token and whose data is the `AgentEvent` wire
|
|
64
|
+
* JSON: `type`, `turn_id`, `attempt`, `step_execution_id`, and `payload` text. Reconnecting with the last
|
|
65
|
+
* `id` continues with the next event, with no repeated or missing event while the Stream retains them.
|
|
66
|
+
* After each empty long poll it yields a keep-alive comment. The stream never ends on its own; stop
|
|
67
|
+
* iterating, or abort `signal`, when the browser goes away.
|
|
68
|
+
*
|
|
69
|
+
* The browser applies the event rules of the session contract. Within one `step_execution_id` it keeps
|
|
70
|
+
* only the highest `attempt` and drops the partial text of lower attempts. After `turn_completed`,
|
|
71
|
+
* `turn_failed`, `turn_steered`, or `turn_cancelled` it replaces the turn's live text with the stored
|
|
72
|
+
* messages. On every connection, load
|
|
73
|
+
* {@link readAgentEventStreamSnapshot} first and open the stream from its `resumeToken`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* for await (const frame of streamAgentEventSseFrames({
|
|
78
|
+
* client, flow, flowId: sessionId, resumeToken: request.headers["last-event-id"] })) {
|
|
79
|
+
* response.write(frame);
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
* @param options - Session, start position, and polling.
|
|
83
|
+
* @returns An async generator of SSE frames and keep-alive comments.
|
|
84
|
+
* @throws {RangeError} When `pollTimeoutMs` is not a positive whole number of seconds.
|
|
85
|
+
* @throws {DexServiceError} When a Stream read fails.
|
|
86
|
+
*/
|
|
87
|
+
export declare function streamAgentEventSseFrames(options: AgentEventSseOptions): AsyncGenerator<string, void, undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a streaming `text/event-stream` Response of an agent session's `AgentEvents`.
|
|
90
|
+
*
|
|
91
|
+
* It writes {@link streamAgentEventSseFrames} and stops reading when the browser closes the response.
|
|
92
|
+
* Mount it in any server that returns a Fetch API `Response`. The session ID usually comes from the
|
|
93
|
+
* browser, so the route must check that the caller may read that session.
|
|
94
|
+
*
|
|
95
|
+
* Before it answers 200, it reads once, with a long poll of up to 1 second, to check the resume token.
|
|
96
|
+
* When Dex rejects the token, such as one of another session, it answers 400, which stops an
|
|
97
|
+
* `EventSource` from reconnecting with it; the browser then loads the snapshot again. A token from
|
|
98
|
+
* before a Stream Store restart is accepted and continues at the oldest retained event.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* // GET /sessions/:id/events
|
|
103
|
+
* export async function GET(request: Request, sessionId: string): Promise<Response> {
|
|
104
|
+
* const url = new URL(request.url);
|
|
105
|
+
* return createAgentEventSseResponse({
|
|
106
|
+
* client, flow, flowId: sessionId,
|
|
107
|
+
* resumeToken: request.headers.get("last-event-id") ?? url.searchParams.get("resumeToken") ?? "",
|
|
108
|
+
* signal: request.signal,
|
|
109
|
+
* });
|
|
110
|
+
* }
|
|
111
|
+
* // In the browser:
|
|
112
|
+
* const { resumeToken } = await (await fetch(`/sessions/${sessionId}/snapshot`)).json();
|
|
113
|
+
* const events = new EventSource(`/sessions/${sessionId}/events?resumeToken=${encodeURIComponent(resumeToken)}`);
|
|
114
|
+
* events.onmessage = (message) => render(JSON.parse(message.data));
|
|
115
|
+
* ```
|
|
116
|
+
* @param options - Session, start position, polling, and extra response headers.
|
|
117
|
+
* @returns A 200 Response with {@link agentEventStreamHeaders} and the application's `headers`; 400 with
|
|
118
|
+
* a text body when Dex rejects the resume token.
|
|
119
|
+
* @throws {RangeError} When `pollTimeoutMs` is not a positive whole number of seconds.
|
|
120
|
+
* @throws {DexServiceError} When the first Stream read fails for another reason.
|
|
121
|
+
*/
|
|
122
|
+
export declare function createAgentEventSseResponse(options: AgentEventSseOptions & {
|
|
123
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
124
|
+
}): Promise<Response>;
|
|
125
|
+
/**
|
|
126
|
+
* Reads the session snapshot together with the Dex resume token to open the plain event stream from.
|
|
127
|
+
*
|
|
128
|
+
* Call it whenever the browser connects or reconnects after a gap. It reads the newest event first and
|
|
129
|
+
* the snapshot second, so events after the token may repeat what the snapshot shows but none is missing.
|
|
130
|
+
* While a turn is active the token replays that turn's events, so the browser can rebuild its live text.
|
|
131
|
+
* The `get_agent_snapshot` RPC needs a running Worker.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* // GET /sessions/:id/snapshot
|
|
136
|
+
* const value = await readAgentEventStreamSnapshot({ client, flow, flowId: sessionId });
|
|
137
|
+
* return Response.json(convertAgentEventStreamSnapshotToJson(value));
|
|
138
|
+
* ```
|
|
139
|
+
* @param options - Client, Flow, and session ID.
|
|
140
|
+
* @returns The snapshot and the resume token.
|
|
141
|
+
* @throws {DexServiceError} When the Stream read or the RPC fails.
|
|
142
|
+
*/
|
|
143
|
+
export declare function readAgentEventStreamSnapshot(options: {
|
|
144
|
+
readonly client: Client;
|
|
145
|
+
readonly flow: AgentSessionFlow<AgentFrameworkRunner<DeferredToolOutcome>>;
|
|
146
|
+
readonly flowId: string;
|
|
147
|
+
}): Promise<AgentEventStreamSnapshot>;
|
|
148
|
+
/**
|
|
149
|
+
* Converts an {@link AgentEventStreamSnapshot} to snake_case wire JSON for an HTTP response.
|
|
150
|
+
*
|
|
151
|
+
* @param value - Snapshot and resume token.
|
|
152
|
+
* @returns `{ snapshot, resume_token }`, with the snapshot in its `AgentSnapshot` wire format.
|
|
153
|
+
*/
|
|
154
|
+
export declare function convertAgentEventStreamSnapshotToJson(value: AgentEventStreamSnapshot): AgentEventStreamSnapshotJson;
|