@superdurable/dex-agents 0.3.0 → 0.5.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 +598 -45
- package/dist/src/agent-context-compaction.d.ts +1 -1
- package/dist/src/agent-framework-runner.d.ts +210 -10
- package/dist/src/agent-framework-runner.js +30 -0
- package/dist/src/agent-framework-runner.js.map +1 -1
- package/dist/src/agent-local-directory-media-store.d.ts +111 -0
- package/dist/src/agent-local-directory-media-store.js +417 -0
- package/dist/src/agent-local-directory-media-store.js.map +1 -0
- package/dist/src/agent-media.d.ts +279 -0
- package/dist/src/agent-media.js +457 -0
- package/dist/src/agent-media.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +3 -1
- package/dist/src/agent-session-codecs.js +53 -4
- package/dist/src/agent-session-codecs.js.map +1 -1
- package/dist/src/agent-session-failure.d.ts +4 -2
- package/dist/src/agent-session-failure.js +6 -2
- package/dist/src/agent-session-failure.js.map +1 -1
- package/dist/src/agent-session-flow-graph.d.ts +46 -0
- package/dist/src/agent-session-flow-graph.js +51 -0
- package/dist/src/agent-session-flow-graph.js.map +1 -1
- package/dist/src/agent-session-flow-graph.json +98 -81
- package/dist/src/agent-session-flow.d.ts +5 -3
- package/dist/src/agent-session-flow.js +10 -1
- package/dist/src/agent-session-flow.js.map +1 -1
- package/dist/src/agent-session-start.d.ts +1 -1
- package/dist/src/agent-session-start.js +2 -2
- package/dist/src/agent-session-start.js.map +1 -1
- package/dist/src/agent-session-steps.d.ts +9 -0
- package/dist/src/agent-session-steps.js +219 -34
- package/dist/src/agent-session-steps.js.map +1 -1
- package/dist/src/agent-session-tracer.js +1 -1
- package/dist/src/agent-session-tracer.js.map +1 -1
- package/dist/src/agent-session-transitions.d.ts +4 -0
- package/dist/src/agent-session-transitions.js +29 -1
- package/dist/src/agent-session-transitions.js.map +1 -1
- package/dist/src/agent-session-values.d.ts +112 -1
- package/dist/src/agent-session-values.js +6 -0
- package/dist/src/agent-session-values.js.map +1 -1
- package/dist/src/agent-session-wait-steps.js +17 -5
- package/dist/src/agent-session-wait-steps.js.map +1 -1
- package/dist/src/ai-sdk/ai-sdk-model-client.d.ts +15 -3
- package/dist/src/ai-sdk/ai-sdk-model-client.js +36 -7
- package/dist/src/ai-sdk/ai-sdk-model-client.js.map +1 -1
- package/dist/src/ai-sdk/index.d.ts +1 -1
- package/dist/src/ai-sdk/index.js +1 -1
- package/dist/src/ai-sdk/index.js.map +1 -1
- package/dist/src/{stepwise → builtin-loop}/agent-definition.d.ts +120 -5
- package/dist/src/builtin-loop/agent-definition.js.map +1 -0
- package/dist/src/builtin-loop/builtin-agent-session-flow.d.ts +69 -0
- package/dist/src/{stepwise/stepwise-agent-session-flow.js → builtin-loop/builtin-agent-session-flow.js} +15 -9
- package/dist/src/builtin-loop/builtin-agent-session-flow.js.map +1 -0
- package/dist/src/{stepwise/stepwise-agent-runner.d.ts → builtin-loop/builtin-loop-agent-runner.d.ts} +85 -26
- package/dist/src/{stepwise/stepwise-agent-runner.js → builtin-loop/builtin-loop-agent-runner.js} +320 -213
- package/dist/src/builtin-loop/builtin-loop-agent-runner.js.map +1 -0
- package/dist/src/{stepwise/stepwise-input-items.d.ts → builtin-loop/builtin-loop-input-items.d.ts} +7 -3
- package/dist/src/{stepwise/stepwise-input-items.js → builtin-loop/builtin-loop-input-items.js} +57 -10
- package/dist/src/builtin-loop/builtin-loop-input-items.js.map +1 -0
- package/dist/src/builtin-loop/function-tool.d.ts +282 -0
- package/dist/src/{stepwise → builtin-loop}/function-tool.js +63 -3
- package/dist/src/builtin-loop/function-tool.js.map +1 -0
- package/dist/src/builtin-loop/index.d.ts +8 -0
- package/dist/src/builtin-loop/index.js +13 -0
- package/dist/src/builtin-loop/index.js.map +1 -0
- package/dist/src/builtin-loop/json-schema-validation.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/model-client.d.ts +36 -7
- package/dist/src/builtin-loop/model-client.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/scripted-model-client.d.ts +8 -5
- package/dist/src/{stepwise → builtin-loop}/scripted-model-client.js +8 -5
- package/dist/src/builtin-loop/scripted-model-client.js.map +1 -0
- package/dist/src/{stepwise → builtin-loop}/tool-source.d.ts +13 -3
- package/dist/src/builtin-loop/tool-source.js.map +1 -0
- package/dist/src/connectors/connector-input-schema.d.ts +19 -0
- package/dist/src/connectors/connector-input-schema.js +228 -0
- package/dist/src/connectors/connector-input-schema.js.map +1 -0
- package/dist/src/connectors/connector-step-context.d.ts +94 -0
- package/dist/src/connectors/connector-step-context.js +180 -0
- package/dist/src/connectors/connector-step-context.js.map +1 -0
- package/dist/src/connectors/connector-tool-source.d.ts +401 -0
- package/dist/src/connectors/connector-tool-source.js +628 -0
- package/dist/src/connectors/connector-tool-source.js.map +1 -0
- package/dist/src/connectors/index.d.ts +3 -0
- package/dist/src/connectors/index.js +11 -0
- package/dist/src/connectors/index.js.map +1 -0
- package/dist/src/index.d.ts +7 -3
- package/dist/src/index.js +6 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/index.d.ts +1 -0
- package/dist/src/mcp/index.js +1 -0
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/mcp-dex-conventions.d.ts +57 -0
- package/dist/src/mcp/mcp-dex-conventions.js +90 -0
- package/dist/src/mcp/mcp-dex-conventions.js.map +1 -0
- package/dist/src/mcp/mcp-image-content.d.ts +20 -0
- package/dist/src/mcp/mcp-image-content.js +82 -0
- package/dist/src/mcp/mcp-image-content.js.map +1 -0
- package/dist/src/mcp/mcp-tool-source.d.ts +178 -17
- package/dist/src/mcp/mcp-tool-source.js +237 -34
- package/dist/src/mcp/mcp-tool-source.js.map +1 -1
- package/dist/src/s3/index.d.ts +1 -0
- package/dist/src/s3/index.js +9 -0
- package/dist/src/s3/index.js.map +1 -0
- package/dist/src/s3/s3-media-store.d.ts +138 -0
- package/dist/src/s3/s3-media-store.js +255 -0
- package/dist/src/s3/s3-media-store.js.map +1 -0
- package/dist/src/stepwise/index.d.ts +41 -8
- package/dist/src/stepwise/index.js +35 -5
- package/dist/src/stepwise/index.js.map +1 -1
- package/dist/src/testing/agent-session-test-client.d.ts +6 -3
- package/dist/src/testing/agent-session-test-client.js +10 -3
- package/dist/src/testing/agent-session-test-client.js.map +1 -1
- package/dist/src/testing/scripted-model-client.d.ts +1 -1
- package/dist/src/testing/scripted-model-client.js +2 -2
- package/dist/src/testing/scripted-model-client.js.map +1 -1
- package/dist/src/tool-source-router.d.ts +211 -0
- package/dist/src/tool-source-router.js +380 -0
- package/dist/src/tool-source-router.js.map +1 -0
- package/dist/src/ui-stream/agent-event-json.d.ts +2 -1
- package/dist/src/ui-stream/agent-event-json.js +3 -1
- package/dist/src/ui-stream/agent-event-json.js.map +1 -1
- package/dist/src/ui-stream/agent-ui-messages.d.ts +11 -3
- package/dist/src/ui-stream/agent-ui-messages.js +29 -5
- package/dist/src/ui-stream/agent-ui-messages.js.map +1 -1
- package/package.json +25 -3
- package/dist/src/stepwise/agent-definition.js.map +0 -1
- package/dist/src/stepwise/function-tool.d.ts +0 -130
- package/dist/src/stepwise/function-tool.js.map +0 -1
- package/dist/src/stepwise/json-schema-validation.js.map +0 -1
- package/dist/src/stepwise/model-client.js.map +0 -1
- package/dist/src/stepwise/scripted-model-client.js.map +0 -1
- package/dist/src/stepwise/stepwise-agent-runner.js.map +0 -1
- package/dist/src/stepwise/stepwise-agent-session-flow.d.ts +0 -35
- package/dist/src/stepwise/stepwise-agent-session-flow.js.map +0 -1
- package/dist/src/stepwise/stepwise-input-items.js.map +0 -1
- package/dist/src/stepwise/tool-source.js.map +0 -1
- /package/dist/src/{stepwise → builtin-loop}/agent-definition.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/json-schema-validation.d.ts +0 -0
- /package/dist/src/{stepwise → builtin-loop}/json-schema-validation.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/model-client.js +0 -0
- /package/dist/src/{stepwise → builtin-loop}/tool-source.js +0 -0
|
@@ -0,0 +1,380 @@
|
|
|
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 { ToolExecutionError, } from "./agent-framework-runner.js";
|
|
9
|
+
/**
|
|
10
|
+
* Default `AgentDefinition.toolSourceListingTimeoutMs`: 10 seconds. It is also the default time one model call of a
|
|
11
|
+
* framework adapter waits for each tool source's listing. Exported from the package root since 0.4.0.
|
|
12
|
+
*/
|
|
13
|
+
export const defaultToolSourceListingTimeoutMs = 10_000;
|
|
14
|
+
const toolSourceMethods = ["listTools", "deferredToolCall", "executeDeferredToolCall", "pollToolTask"];
|
|
15
|
+
const toolSourceReferenceKey = "reference";
|
|
16
|
+
/**
|
|
17
|
+
* Serves {@link ToolSource}s from a framework runner, so their calls run in tool Steps as the built-in loop runner runs
|
|
18
|
+
* them.
|
|
19
|
+
*
|
|
20
|
+
* A framework adapter that implements {@link AgentFrameworkRunner} builds one router from its `toolSources`. In each
|
|
21
|
+
* `RunModel` it awaits {@link listSourceTools} and offers every listed tool to its framework as a native tool that
|
|
22
|
+
* never runs inside the model call. When the model calls one, the adapter returns {@link buildDeferredToolCall}, so
|
|
23
|
+
* the source picks the effect, the approval, and whether the call is an ordered write, and the router stores the
|
|
24
|
+
* source's name with the source's own `toolSourceReference`. The tool Step then reaches that source through
|
|
25
|
+
* {@link executeDeferredToolCall} on any Worker, with the full execution: the Step context, the heartbeat
|
|
26
|
+
* checkpoint, and the attempt. {@link toolCallStepOptions}, {@link pollToolTask}, and {@link cancelToolTask} route
|
|
27
|
+
* the same way. A runner whose `executeDeferredToolCall` returns only results, and so polls no tool tasks, uses
|
|
28
|
+
* {@link executeDeferredToolCallForResult} instead. `BuiltinLoopAgentRunner` uses a router too.
|
|
29
|
+
*
|
|
30
|
+
* Construction refuses a source without a {@link ToolSource} method or a non-blank, unique `sourceName`, and a
|
|
31
|
+
* name that a source declares through `declaredToolNames` when it repeats a local tool, a built-in tool, or another
|
|
32
|
+
* source's tool. Each listing refuses the same collisions among the listed names.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const toolSources = new ToolSourceRouter([new ConnectorToolSource([refund])], {
|
|
37
|
+
* sourceNameKey: "my_framework_tool_source",
|
|
38
|
+
* localToolNames: new Set(Object.keys(frameworkTools)),
|
|
39
|
+
* });
|
|
40
|
+
* const listed = await toolSources.listSourceTools();
|
|
41
|
+
* const call = toolSources.buildDeferredToolCall(turn, listed.get("refund")!, modelCall);
|
|
42
|
+
* ```
|
|
43
|
+
* @since 0.4.0
|
|
44
|
+
*/
|
|
45
|
+
export class ToolSourceRouter {
|
|
46
|
+
toolSources;
|
|
47
|
+
toolSourcesByName;
|
|
48
|
+
sourceNameKey;
|
|
49
|
+
localToolNames;
|
|
50
|
+
localToolDescription;
|
|
51
|
+
listingTimeoutMs;
|
|
52
|
+
/** The last listing of each source, so estimates count its tools without listing again. */
|
|
53
|
+
lastListings = new Map();
|
|
54
|
+
/**
|
|
55
|
+
* Creates the router and checks the sources.
|
|
56
|
+
* @param toolSources - The sources, in the order the model sees their tools.
|
|
57
|
+
* @param options - The envelope key, the names source tools must not repeat, and the listing timeout.
|
|
58
|
+
* @throws {TypeError} When a source lacks a {@link ToolSource} method or a non-blank `sourceName`, two sources
|
|
59
|
+
* share a `sourceName`, `sourceNameKey` is blank, or a declared tool name repeats a local tool, a built-in tool, or
|
|
60
|
+
* another source's tool.
|
|
61
|
+
* @throws {RangeError} When `listingTimeoutMs` is not positive.
|
|
62
|
+
*/
|
|
63
|
+
constructor(toolSources, options) {
|
|
64
|
+
if (typeof options.sourceNameKey !== "string" || options.sourceNameKey.trim() === "") {
|
|
65
|
+
throw new TypeError("ToolSourceRouterOptions.sourceNameKey must be a non-blank string");
|
|
66
|
+
}
|
|
67
|
+
for (const source of toolSources) {
|
|
68
|
+
const missing = toolSourceMethods.find((method) => typeof source?.[method] !== "function");
|
|
69
|
+
if (missing !== undefined) {
|
|
70
|
+
throw new TypeError(`tool source ${String(source)} has no ${missing} method`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const toolSourcesByName = new Map();
|
|
74
|
+
for (const source of toolSources) {
|
|
75
|
+
if (typeof source.sourceName !== "string" || source.sourceName.trim() === "") {
|
|
76
|
+
throw new TypeError(`tool source ${String(source)} needs a non-blank sourceName`);
|
|
77
|
+
}
|
|
78
|
+
if (toolSourcesByName.has(source.sourceName)) {
|
|
79
|
+
throw new TypeError(`two tool sources are named ${source.sourceName}`);
|
|
80
|
+
}
|
|
81
|
+
toolSourcesByName.set(source.sourceName, source);
|
|
82
|
+
}
|
|
83
|
+
const listingTimeoutMs = options.listingTimeoutMs ?? defaultToolSourceListingTimeoutMs;
|
|
84
|
+
if (!(listingTimeoutMs > 0)) {
|
|
85
|
+
throw new RangeError("toolSourceListingTimeoutMs must be positive");
|
|
86
|
+
}
|
|
87
|
+
this.toolSources = [...toolSources];
|
|
88
|
+
this.toolSourcesByName = toolSourcesByName;
|
|
89
|
+
this.sourceNameKey = options.sourceNameKey;
|
|
90
|
+
this.localToolNames = new Set(options.localToolNames ?? []);
|
|
91
|
+
this.localToolDescription = options.localToolDescription ?? "a tool of the agent";
|
|
92
|
+
this.listingTimeoutMs = listingTimeoutMs;
|
|
93
|
+
this.refuseDeclaredToolNameCollisions(options.builtInToolNames ?? new Set());
|
|
94
|
+
}
|
|
95
|
+
/** Whether the router has at least one source. */
|
|
96
|
+
get hasToolSources() {
|
|
97
|
+
return this.toolSources.length > 0;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns the names the sources always list, from their optional `declaredToolNames`.
|
|
101
|
+
* @returns The names.
|
|
102
|
+
*/
|
|
103
|
+
declaredToolNames() {
|
|
104
|
+
const names = new Set();
|
|
105
|
+
for (const source of this.toolSources) {
|
|
106
|
+
for (const toolName of source.declaredToolNames?.() ?? []) {
|
|
107
|
+
names.add(toolName);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return names;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Lists every source's tools for one model call, in source order.
|
|
114
|
+
*
|
|
115
|
+
* A source whose listing throws or takes longer than the listing timeout offers no tools in this call, with a
|
|
116
|
+
* warning, so a down server never fails a turn.
|
|
117
|
+
* @param builtInToolNames - The built-in tools enabled for this turn. Defaults to none.
|
|
118
|
+
* @returns The listed tools by name.
|
|
119
|
+
* @throws {TypeError} When a listed name repeats a local tool, an enabled built-in tool, or another source's tool.
|
|
120
|
+
*/
|
|
121
|
+
async listSourceTools(builtInToolNames = new Set()) {
|
|
122
|
+
const listed = new Map();
|
|
123
|
+
for (const [index, source] of this.toolSources.entries()) {
|
|
124
|
+
for (const tool of await this.listOneSource(index, source)) {
|
|
125
|
+
this.refuseSourceToolName(tool.name, builtInToolNames, listed);
|
|
126
|
+
listed.set(tool.name, { source, tool });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return listed;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Returns each source's tools without I/O: its `cachedTools` when it has them, else this router's last listing.
|
|
133
|
+
* A name listed twice keeps its first source. Use it to estimate the model input.
|
|
134
|
+
* @returns The cached tools by name.
|
|
135
|
+
*/
|
|
136
|
+
readCachedSourceTools() {
|
|
137
|
+
const cached = new Map();
|
|
138
|
+
for (const [index, source] of this.toolSources.entries()) {
|
|
139
|
+
const tools = source.cachedTools?.() ?? this.lastListings.get(index) ?? [];
|
|
140
|
+
for (const tool of tools) {
|
|
141
|
+
if (!cached.has(tool.name)) {
|
|
142
|
+
cached.set(tool.name, { source, tool });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return cached;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Builds the deferred call for one model call of a listed source tool.
|
|
150
|
+
*
|
|
151
|
+
* The source's `deferredToolCall` decides the policy, the `ordered` flag, and its own reference. The router
|
|
152
|
+
* keeps all of it and wraps the reference with the source's name.
|
|
153
|
+
* @param turn - The `RunModel` context.
|
|
154
|
+
* @param listedTool - The listed tool the model called, from {@link listSourceTools} of this model call.
|
|
155
|
+
* @param modelCall - The model's tool call ID and its arguments as JSON text.
|
|
156
|
+
* @returns The deferred call to return in `ToolCallsRequested`.
|
|
157
|
+
*/
|
|
158
|
+
buildDeferredToolCall(turn, listedTool, modelCall) {
|
|
159
|
+
const built = listedTool.source.deferredToolCall(turn, {
|
|
160
|
+
toolCallId: modelCall.toolCallId,
|
|
161
|
+
toolName: listedTool.tool.name,
|
|
162
|
+
arguments: modelCall.arguments,
|
|
163
|
+
listedTool: listedTool.tool,
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
...built,
|
|
167
|
+
toolSourceReference: writeToolSourceEnvelope(this.sourceNameKey, listedTool.source.sourceName, built.toolSourceReference),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Whether a source built this call, so its tool Step and polls go to a source. It reads only the record, so it
|
|
172
|
+
* answers even when that source is not configured on this Worker; {@link executeDeferredToolCall} then throws.
|
|
173
|
+
* @param toolCall - The call's record.
|
|
174
|
+
* @returns `true` when the record holds this router's envelope, or a reference while the router has sources.
|
|
175
|
+
*/
|
|
176
|
+
isSourceToolCall(toolCall) {
|
|
177
|
+
if (readToolSourceEnvelope(this.sourceNameKey, toolCall.toolSourceReference) !== undefined) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return (toolCall.toolSourceReference ?? undefined) !== undefined && this.hasToolSources;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Runs one call in its tool Step through the source that built it, with the source's own reference and every
|
|
184
|
+
* other field of `call` unchanged, such as the Step context, the heartbeat checkpoint, and the attempt.
|
|
185
|
+
* @param call - The deferred execution from the tool Step.
|
|
186
|
+
* @returns The source's outcome.
|
|
187
|
+
* @throws {RangeError} When no source built the call, or its source is not configured on this Worker, so the
|
|
188
|
+
* effect decides the outcome.
|
|
189
|
+
* @throws Any error of the source, such as `ToolExecutionError` or `ToolOutcomeUnknownError`.
|
|
190
|
+
*/
|
|
191
|
+
async executeDeferredToolCall(call) {
|
|
192
|
+
const routed = this.requireToolSource(call.toolCall);
|
|
193
|
+
return routed.source.executeDeferredToolCall({
|
|
194
|
+
...call,
|
|
195
|
+
toolCall: withToolSourceReference(call.toolCall, routed.reference),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Runs one call as {@link executeDeferredToolCall} does, for a runner that polls no tool tasks and asks no tool
|
|
200
|
+
* questions, so its `executeDeferredToolCall` returns only a `ToolExecutionResult`. Such a runner has no
|
|
201
|
+
* `pollToolTask`, so the session tells the source that it cannot start tasks. `ConnectorToolSource` returns only
|
|
202
|
+
* results.
|
|
203
|
+
* @param call - The deferred execution from the tool Step.
|
|
204
|
+
* @returns The source's result.
|
|
205
|
+
* @throws {ToolExecutionError} When the source asked the user a question. A question comes before any effect, so
|
|
206
|
+
* the call records `failed` and the model reads why.
|
|
207
|
+
* @throws {Error} When the source started a tool task anyway. The task may run, so the effect decides the outcome.
|
|
208
|
+
* @throws Any error of {@link executeDeferredToolCall}.
|
|
209
|
+
*/
|
|
210
|
+
async executeDeferredToolCallForResult(call) {
|
|
211
|
+
const outcome = await this.executeDeferredToolCall(call);
|
|
212
|
+
if (!("kind" in outcome)) {
|
|
213
|
+
return outcome;
|
|
214
|
+
}
|
|
215
|
+
const toolName = call.toolCall.toolName;
|
|
216
|
+
if (outcome.kind === "tool_input_requested") {
|
|
217
|
+
throw new ToolExecutionError(`tool ${toolName} asked a question, which this agent cannot ask the user`);
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`tool ${toolName} started a tool task, which this agent cannot poll`);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Polls a source's tool task once, through the source that built the call.
|
|
223
|
+
* @param poll - The call's record from `PollToolTask`.
|
|
224
|
+
* @returns The source's outcome.
|
|
225
|
+
* @throws {RangeError} When no source built the call. The task may still run, so `PollToolTask` retries and then
|
|
226
|
+
* records the call by its effect.
|
|
227
|
+
* @throws Any error of the source.
|
|
228
|
+
*/
|
|
229
|
+
async pollToolTask(poll) {
|
|
230
|
+
const routed = this.requireToolSource(poll.toolCall);
|
|
231
|
+
return routed.source.pollToolTask({ ...poll, toolCall: withToolSourceReference(poll.toolCall, routed.reference) });
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Cancels a source's task through the source that built the call; a source without `cancelToolTask` leaves its
|
|
235
|
+
* task running.
|
|
236
|
+
* @param cancellation - The abandoned call's record from `CancelToolTask`.
|
|
237
|
+
* @returns A Promise that resolves once the source took the cancellation.
|
|
238
|
+
* @throws {RangeError} When no source built the call.
|
|
239
|
+
* @throws Any error of the source.
|
|
240
|
+
*/
|
|
241
|
+
async cancelToolTask(cancellation) {
|
|
242
|
+
const routed = this.requireToolSource(cancellation.toolCall);
|
|
243
|
+
await routed.source.cancelToolTask?.({
|
|
244
|
+
...cancellation,
|
|
245
|
+
toolCall: withToolSourceReference(cancellation.toolCall, routed.reference),
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Returns the source's options for one call's tool Step.
|
|
250
|
+
* @param toolCall - The record whose tool Step starts.
|
|
251
|
+
* @returns The source's options, or `undefined` when no source built the call or its source defines none.
|
|
252
|
+
* @throws {RangeError} When a source built the call but it is not configured on this Worker; the session then
|
|
253
|
+
* uses the defaults.
|
|
254
|
+
*/
|
|
255
|
+
toolCallStepOptions(toolCall) {
|
|
256
|
+
const routed = this.routeToToolSource(toolCall);
|
|
257
|
+
return routed?.source.toolCallStepOptions?.(withToolSourceReference(toolCall, routed.reference));
|
|
258
|
+
}
|
|
259
|
+
refuseDeclaredToolNameCollisions(builtInToolNames) {
|
|
260
|
+
const declared = new Map();
|
|
261
|
+
for (const source of this.toolSources) {
|
|
262
|
+
const names = [...(source.declaredToolNames?.() ?? [])].sort();
|
|
263
|
+
for (const toolName of names) {
|
|
264
|
+
this.refuseSourceToolName(toolName, builtInToolNames, declared);
|
|
265
|
+
}
|
|
266
|
+
for (const toolName of names) {
|
|
267
|
+
declared.set(toolName, source);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
refuseSourceToolName(toolName, builtInToolNames, otherSourceTools) {
|
|
272
|
+
if (builtInToolNames.has(toolName)) {
|
|
273
|
+
throw new TypeError(`tool ${toolName} uses the name of an enabled built-in tool`);
|
|
274
|
+
}
|
|
275
|
+
if (this.localToolNames.has(toolName)) {
|
|
276
|
+
throw new TypeError(`tool ${toolName} of a tool source uses the name of ${this.localToolDescription}`);
|
|
277
|
+
}
|
|
278
|
+
if (otherSourceTools.has(toolName)) {
|
|
279
|
+
throw new TypeError(`two tool sources list a tool named ${toolName}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async listOneSource(index, source) {
|
|
283
|
+
const listing = source.listTools();
|
|
284
|
+
// A listing that outlives this call keeps running; nobody else reads its error.
|
|
285
|
+
listing.catch(() => undefined);
|
|
286
|
+
let timer;
|
|
287
|
+
const timedOut = new Promise((resolve) => {
|
|
288
|
+
timer = setTimeout(() => resolve("timed_out"), this.listingTimeoutMs);
|
|
289
|
+
});
|
|
290
|
+
try {
|
|
291
|
+
const tools = await Promise.race([listing, timedOut]);
|
|
292
|
+
if (tools === "timed_out") {
|
|
293
|
+
console.warn(`tool source ${index} listed nothing within ${this.listingTimeoutMs} ms`);
|
|
294
|
+
return [];
|
|
295
|
+
}
|
|
296
|
+
this.lastListings.set(index, tools);
|
|
297
|
+
return tools;
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
console.warn(`tool source ${index} could not list its tools: ${error instanceof Error ? error.message : String(error)}`);
|
|
301
|
+
return [];
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
clearTimeout(timer);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
requireToolSource(toolCall) {
|
|
308
|
+
const routed = this.routeToToolSource(toolCall);
|
|
309
|
+
if (routed === undefined) {
|
|
310
|
+
throw new RangeError(`no tool source built the call of tool ${toolCall.toolName}`);
|
|
311
|
+
}
|
|
312
|
+
return routed;
|
|
313
|
+
}
|
|
314
|
+
routeToToolSource(toolCall) {
|
|
315
|
+
const envelope = readToolSourceEnvelope(this.sourceNameKey, toolCall.toolSourceReference);
|
|
316
|
+
if (envelope !== undefined) {
|
|
317
|
+
const source = this.toolSourcesByName.get(envelope.sourceName);
|
|
318
|
+
if (source === undefined) {
|
|
319
|
+
throw new RangeError(`tool source ${envelope.sourceName}, which built the call of tool ${toolCall.toolName}, is not configured on this Worker`);
|
|
320
|
+
}
|
|
321
|
+
return { source, reference: envelope.reference };
|
|
322
|
+
}
|
|
323
|
+
const reference = toolCall.toolSourceReference ?? undefined;
|
|
324
|
+
if (reference === undefined || this.toolSources.length === 0) {
|
|
325
|
+
return undefined;
|
|
326
|
+
}
|
|
327
|
+
const onlySource = this.toolSources.length === 1 ? this.toolSources[0] : undefined;
|
|
328
|
+
if (onlySource !== undefined) {
|
|
329
|
+
// A reference the source built itself, such as in a runner subclass.
|
|
330
|
+
return { source: onlySource, reference };
|
|
331
|
+
}
|
|
332
|
+
throw new RangeError(`cannot tell which tool source built the call of ${toolCall.toolName}`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The router's `toolSourceReference`: the source's name under `sourceNameKey` and its own reference, as JSON text.
|
|
337
|
+
* @param sourceNameKey - The envelope key of the runner.
|
|
338
|
+
* @param sourceName - The building source's name.
|
|
339
|
+
* @param reference - The source's own reference, or `undefined`.
|
|
340
|
+
* @returns The envelope text.
|
|
341
|
+
*/
|
|
342
|
+
export function writeToolSourceEnvelope(sourceNameKey, sourceName, reference) {
|
|
343
|
+
return JSON.stringify({ [sourceNameKey]: sourceName, [toolSourceReferenceKey]: reference ?? null });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Reads an envelope that {@link writeToolSourceEnvelope} wrote with the same key.
|
|
347
|
+
* @param sourceNameKey - The envelope key of the runner.
|
|
348
|
+
* @param toolSourceReference - A record's `toolSourceReference`.
|
|
349
|
+
* @returns The source's name and its own reference, or `undefined` when the text is no such envelope.
|
|
350
|
+
*/
|
|
351
|
+
export function readToolSourceEnvelope(sourceNameKey, toolSourceReference) {
|
|
352
|
+
if (toolSourceReference === undefined || toolSourceReference === null) {
|
|
353
|
+
return undefined;
|
|
354
|
+
}
|
|
355
|
+
let envelope;
|
|
356
|
+
try {
|
|
357
|
+
envelope = JSON.parse(toolSourceReference);
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
if (typeof envelope !== "object" || envelope === null || Array.isArray(envelope)) {
|
|
363
|
+
return undefined;
|
|
364
|
+
}
|
|
365
|
+
const sourceName = envelope[sourceNameKey];
|
|
366
|
+
const reference = envelope[toolSourceReferenceKey];
|
|
367
|
+
if (typeof sourceName !== "string") {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
if (reference !== null && reference !== undefined && typeof reference !== "string") {
|
|
371
|
+
return undefined;
|
|
372
|
+
}
|
|
373
|
+
return { sourceName, reference: reference ?? undefined };
|
|
374
|
+
}
|
|
375
|
+
/** The record as the source built it: its own reference instead of the router's envelope. */
|
|
376
|
+
function withToolSourceReference(toolCall, reference) {
|
|
377
|
+
const { toolSourceReference: _envelope, ...rest } = toolCall;
|
|
378
|
+
return (reference === undefined ? rest : { ...rest, toolSourceReference: reference });
|
|
379
|
+
}
|
|
380
|
+
//# sourceMappingURL=tool-source-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-source-router.js","sourceRoot":"","sources":["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AS,KAAK,QAAQ,EAAE,CAAC;QACnF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,IAAI,SAAS,EAAE,CAAC;AAC3D,CAAC;AAED,6FAA6F;AAC7F,SAAS,uBAAuB,CAAoC,QAAc,EAAE,SAA6B;IAC/G,MAAM,EAAE,mBAAmB,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC7D,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,mBAAmB,EAAE,SAAS,EAAE,CAAS,CAAC;AAChG,CAAC"}
|
|
@@ -18,7 +18,8 @@ export declare function convertAgentEventToJson(event: AgentEvent): AgentEventJs
|
|
|
18
18
|
* Use it when a browser shared with Python backends reads the snapshot. It is the `get_agent_snapshot` wire
|
|
19
19
|
* format without the fields only the session's Steps use. Messages leave out `framework_item`, the
|
|
20
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`,
|
|
21
|
+
* `tool_source_reference`, `trace_context`, `input_continuation`, `input_answers`, `task_answer_pending`, and
|
|
22
|
+
* `runner_tool_state`.
|
|
22
23
|
*
|
|
23
24
|
* `session_settings` is included as stored, so the browser sees the settings the next turn starts with. Keep
|
|
24
25
|
* anything a browser must not see out of session settings, or remove the key before serving the JSON.
|
|
@@ -34,6 +34,7 @@ const workerOnlyToolCallFieldNames = new Set([
|
|
|
34
34
|
"input_continuation",
|
|
35
35
|
"input_answers",
|
|
36
36
|
"task_answer_pending",
|
|
37
|
+
"runner_tool_state",
|
|
37
38
|
]);
|
|
38
39
|
/**
|
|
39
40
|
* Converts an `AgentSnapshot` to the snake_case JSON a browser reads, the same JSON the Python core produces.
|
|
@@ -41,7 +42,8 @@ const workerOnlyToolCallFieldNames = new Set([
|
|
|
41
42
|
* Use it when a browser shared with Python backends reads the snapshot. It is the `get_agent_snapshot` wire
|
|
42
43
|
* format without the fields only the session's Steps use. Messages leave out `framework_item`, the
|
|
43
44
|
* 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`,
|
|
45
|
+
* `tool_source_reference`, `trace_context`, `input_continuation`, `input_answers`, `task_answer_pending`, and
|
|
46
|
+
* `runner_tool_state`.
|
|
45
47
|
*
|
|
46
48
|
* `session_settings` is included as stored, so the browser sees the settings the next turn starts with. Keep
|
|
47
49
|
* anything a browser must not see out of session settings, or remove the key before serving the JSON.
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"agent-event-json.js","sourceRoot":"","sources":["../../../src/ui-stream/agent-event-json.ts"],"names":[],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AK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AACvG,CAAC"}
|
|
@@ -23,11 +23,19 @@ export interface AgentSessionUIMessages {
|
|
|
23
23
|
* assistant and tool messages of one turn become one assistant message with ID
|
|
24
24
|
* {@link agentAssistantUIMessageId}: a `step-start` part before each model call, a text part per model
|
|
25
25
|
* text, and a dynamic tool part per tool call. A stored tool result shows the text the model saw, so a
|
|
26
|
-
* failed or rejected call appears as `output-available` with that text. A turn-failure
|
|
27
|
-
* user message and appears as
|
|
26
|
+
* failed or rejected call appears as `output-available` with that text. A turn-failure, steered, or cancelled
|
|
27
|
+
* note is the last stored user message of a turn that has ended, and it appears as a user message. Any other user
|
|
28
|
+
* message after the turn's first model output, such as the message of a built-in loop continuation, is not shown;
|
|
29
|
+
* it starts the step of the next model call, also while that call is still running, as the UI stream does.
|
|
30
|
+
* Changed in 0.5.0: such a message no longer appears as a user message that splits the turn.
|
|
31
|
+
*
|
|
32
|
+
* The UI stream starts a step for every `RunModel` Step, and this function one for every model call. They differ
|
|
33
|
+
* only where a `RunModel` makes no model call, such as when `decideTurnContinuation` ends a turn after its tools:
|
|
34
|
+
* the stream then sends one more `start-step` and `finish-step` with no visible part, which leaves no part in the
|
|
35
|
+
* AI SDK message, so the message still matches the converted snapshot.
|
|
28
36
|
*
|
|
29
37
|
* The session stores a turn's messages when the turn ends, or after each model call for a runner such as
|
|
30
|
-
* the
|
|
38
|
+
* the built-in loop runner. For the active turn the function shows each tool call of `snapshot.toolCalls` once in
|
|
31
39
|
* the turn's assistant message: a stored call without a result takes the record's state, and a call not
|
|
32
40
|
* stored yet is added. Approvals waiting for `resolve_interrupt` are `approval-requested`, running calls
|
|
33
41
|
* are `input-available` or `approval-responded`, and finished calls show their result. The active turn's
|
|
@@ -17,11 +17,19 @@ import { encodeAgentUIStreamCursor } from "./agent-ui-stream-cursor.js";
|
|
|
17
17
|
* assistant and tool messages of one turn become one assistant message with ID
|
|
18
18
|
* {@link agentAssistantUIMessageId}: a `step-start` part before each model call, a text part per model
|
|
19
19
|
* text, and a dynamic tool part per tool call. A stored tool result shows the text the model saw, so a
|
|
20
|
-
* failed or rejected call appears as `output-available` with that text. A turn-failure
|
|
21
|
-
* user message and appears as
|
|
20
|
+
* failed or rejected call appears as `output-available` with that text. A turn-failure, steered, or cancelled
|
|
21
|
+
* note is the last stored user message of a turn that has ended, and it appears as a user message. Any other user
|
|
22
|
+
* message after the turn's first model output, such as the message of a built-in loop continuation, is not shown;
|
|
23
|
+
* it starts the step of the next model call, also while that call is still running, as the UI stream does.
|
|
24
|
+
* Changed in 0.5.0: such a message no longer appears as a user message that splits the turn.
|
|
25
|
+
*
|
|
26
|
+
* The UI stream starts a step for every `RunModel` Step, and this function one for every model call. They differ
|
|
27
|
+
* only where a `RunModel` makes no model call, such as when `decideTurnContinuation` ends a turn after its tools:
|
|
28
|
+
* the stream then sends one more `start-step` and `finish-step` with no visible part, which leaves no part in the
|
|
29
|
+
* AI SDK message, so the message still matches the converted snapshot.
|
|
22
30
|
*
|
|
23
31
|
* The session stores a turn's messages when the turn ends, or after each model call for a runner such as
|
|
24
|
-
* the
|
|
32
|
+
* the built-in loop runner. For the active turn the function shows each tool call of `snapshot.toolCalls` once in
|
|
25
33
|
* the turn's assistant message: a stored call without a result takes the record's state, and a call not
|
|
26
34
|
* stored yet is added. Approvals waiting for `resolve_interrupt` are `approval-requested`, running calls
|
|
27
35
|
* are `input-available` or `approval-responded`, and finished calls show their result. The active turn's
|
|
@@ -38,9 +46,14 @@ import { encodeAgentUIStreamCursor } from "./agent-ui-stream-cursor.js";
|
|
|
38
46
|
*/
|
|
39
47
|
export function convertAgentSnapshotToUIMessages(snapshot) {
|
|
40
48
|
const uiMessages = [];
|
|
49
|
+
const activeTurnId = snapshot.state?.activeTurnId ?? null;
|
|
41
50
|
let assistantMessage;
|
|
42
|
-
for (const message of snapshot.messages) {
|
|
51
|
+
for (const [index, message] of snapshot.messages.entries()) {
|
|
43
52
|
if (message.role === "user") {
|
|
53
|
+
if (assistantMessage?.turnId === message.turnId && !isTurnEndingNote(snapshot, index, activeTurnId)) {
|
|
54
|
+
assistantMessage.startModelCall();
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
44
57
|
assistantMessage = undefined;
|
|
45
58
|
uiMessages.push({
|
|
46
59
|
id: agentUserUIMessageId(message.sequence),
|
|
@@ -55,7 +68,6 @@ export function convertAgentSnapshotToUIMessages(snapshot) {
|
|
|
55
68
|
}
|
|
56
69
|
assistantMessage.appendStoredMessage(message);
|
|
57
70
|
}
|
|
58
|
-
const activeTurnId = snapshot.state?.activeTurnId ?? null;
|
|
59
71
|
if (activeTurnId !== null && snapshot.toolCalls.length > 0) {
|
|
60
72
|
if (assistantMessage?.turnId !== activeTurnId) {
|
|
61
73
|
assistantMessage = new AgentAssistantUIMessageBuilder(activeTurnId);
|
|
@@ -65,6 +77,13 @@ export function convertAgentSnapshotToUIMessages(snapshot) {
|
|
|
65
77
|
}
|
|
66
78
|
return uiMessages;
|
|
67
79
|
}
|
|
80
|
+
/** Whether a user message after the turn's model output is a note: the last stored message of an ended turn. */
|
|
81
|
+
function isTurnEndingNote(snapshot, index, activeTurnId) {
|
|
82
|
+
const message = snapshot.messages[index];
|
|
83
|
+
const following = snapshot.messages[index + 1];
|
|
84
|
+
const isLastOfTurn = following === undefined || following.turnId !== message.turnId;
|
|
85
|
+
return isLastOfTurn && message.turnId !== activeTurnId;
|
|
86
|
+
}
|
|
68
87
|
/**
|
|
69
88
|
* Reads an agent session as AI SDK messages and the UI stream resume token of its active turn.
|
|
70
89
|
*
|
|
@@ -108,6 +127,11 @@ class AgentAssistantUIMessageBuilder {
|
|
|
108
127
|
parts: [{ type: "step-start" }],
|
|
109
128
|
};
|
|
110
129
|
}
|
|
130
|
+
/** Starts the step of a model call that follows a user message within the turn. */
|
|
131
|
+
startModelCall() {
|
|
132
|
+
this.message.parts.push({ type: "step-start" });
|
|
133
|
+
this.isAfterToolResult = false;
|
|
134
|
+
}
|
|
111
135
|
appendStoredMessage(message) {
|
|
112
136
|
if (message.role === "tool") {
|
|
113
137
|
this.appendToolResult(message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-ui-messages.js","sourceRoot":"","sources":["../../../src/ui-stream/agent-ui-messages.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAK1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EACL,uBAAuB,GAIxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GAGrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAgBxE
|
|
1
|
+
{"version":3,"file":"agent-ui-messages.js","sourceRoot":"","sources":["../../../src/ui-stream/agent-ui-messages.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;AAK1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,EACL,uBAAuB,GAIxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EACL,yBAAyB,EACzB,oBAAoB,GAGrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAgBxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,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H;YACtH,OAAO,QAAQ,CAAC,gBAAgB;gBAC9B,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;gBAC5F,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;QAChD,KAAK,WAAW;YACd,OAAO,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,EAAE,EAAE,GAAG,eAAe,EAAE,CAAC;QACvG,KAAK,QAAQ,CAAC;QACd,KAAK,iBAAiB;YACpB,OAAO;gBACL,GAAG,QAAQ;gBACX,KAAK,EAAE,cAAc;gBACrB,SAAS,EAAE,uBAAuB,CAAC,QAAQ,CAAC;gBAC5C,GAAG,eAAe;aACnB,CAAC;QACJ,KAAK,UAAU;YACb,OAAO;gBACL,GAAG,QAAQ;gBACX,KAAK,EAAE,eAAe;gBACtB,QAAQ,EAAE;oBACR,EAAE,EAAE,UAAU;oBACd,QAAQ,EAAE,KAAK;oBACf,GAAG,CAAC,QAAQ,CAAC,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,gBAAgB,EAAE,CAAC;iBACrF;aACF,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/dex-agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Durable agent sessions for Dex, shared by the Dex TypeScript agent framework adapters",
|
|
5
5
|
"license": "LicenseRef-Sustainable-Use-1.0",
|
|
6
6
|
"repository": {
|
|
@@ -38,10 +38,18 @@
|
|
|
38
38
|
"types": "./dist/src/mcp/index.d.ts",
|
|
39
39
|
"import": "./dist/src/mcp/index.js"
|
|
40
40
|
},
|
|
41
|
+
"./connectors": {
|
|
42
|
+
"types": "./dist/src/connectors/index.d.ts",
|
|
43
|
+
"import": "./dist/src/connectors/index.js"
|
|
44
|
+
},
|
|
41
45
|
"./ui-stream": {
|
|
42
46
|
"types": "./dist/src/ui-stream/index.d.ts",
|
|
43
47
|
"import": "./dist/src/ui-stream/index.js"
|
|
44
48
|
},
|
|
49
|
+
"./builtin-loop": {
|
|
50
|
+
"types": "./dist/src/builtin-loop/index.d.ts",
|
|
51
|
+
"import": "./dist/src/builtin-loop/index.js"
|
|
52
|
+
},
|
|
45
53
|
"./stepwise": {
|
|
46
54
|
"types": "./dist/src/stepwise/index.d.ts",
|
|
47
55
|
"import": "./dist/src/stepwise/index.js"
|
|
@@ -49,6 +57,10 @@
|
|
|
49
57
|
"./ai-sdk": {
|
|
50
58
|
"types": "./dist/src/ai-sdk/index.d.ts",
|
|
51
59
|
"import": "./dist/src/ai-sdk/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./s3": {
|
|
62
|
+
"types": "./dist/src/s3/index.d.ts",
|
|
63
|
+
"import": "./dist/src/s3/index.js"
|
|
52
64
|
}
|
|
53
65
|
},
|
|
54
66
|
"scripts": {
|
|
@@ -58,27 +70,37 @@
|
|
|
58
70
|
"test:long": "npm run build && node --test --test-concurrency=1 --test-timeout=1800000 'dist/test/long/*.integration.test.js'"
|
|
59
71
|
},
|
|
60
72
|
"peerDependencies": {
|
|
73
|
+
"@aws-sdk/client-s3": "^3.700.0",
|
|
61
74
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
62
75
|
"@opentelemetry/api": "^1.3.0",
|
|
63
|
-
"@superdurable/
|
|
76
|
+
"@superdurable/connectors-sdk": "0.9.0",
|
|
77
|
+
"@superdurable/dex": "1.45.0",
|
|
64
78
|
"ai": "^7.0.159"
|
|
65
79
|
},
|
|
66
80
|
"peerDependenciesMeta": {
|
|
81
|
+
"@aws-sdk/client-s3": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
67
84
|
"@modelcontextprotocol/sdk": {
|
|
68
85
|
"optional": true
|
|
69
86
|
},
|
|
70
87
|
"@opentelemetry/api": {
|
|
71
88
|
"optional": true
|
|
72
89
|
},
|
|
90
|
+
"@superdurable/connectors-sdk": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
73
93
|
"ai": {
|
|
74
94
|
"optional": true
|
|
75
95
|
}
|
|
76
96
|
},
|
|
77
97
|
"devDependencies": {
|
|
98
|
+
"@aws-sdk/client-s3": "3.1155.0",
|
|
78
99
|
"@modelcontextprotocol/sdk": "1.32.2",
|
|
79
100
|
"@opentelemetry/api": "1.9.1",
|
|
80
101
|
"@opentelemetry/sdk-trace-base": "2.12.0",
|
|
81
|
-
"@superdurable/
|
|
102
|
+
"@superdurable/connectors-sdk": "0.9.0",
|
|
103
|
+
"@superdurable/dex": "1.45.0",
|
|
82
104
|
"@types/node": "22.20.5",
|
|
83
105
|
"ai": "7.0.159",
|
|
84
106
|
"typescript": "5.9.3",
|