@superdurable/dex-agents 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/README.md +475 -2
- package/dist/src/agent-event-writer.d.ts +26 -0
- package/dist/src/agent-event-writer.js +110 -0
- package/dist/src/agent-event-writer.js.map +1 -0
- package/dist/src/agent-framework-runner.d.ts +368 -0
- package/dist/src/agent-framework-runner.js +81 -0
- package/dist/src/agent-framework-runner.js.map +1 -0
- package/dist/src/agent-session-codecs.d.ts +44 -0
- package/dist/src/agent-session-codecs.js +355 -0
- package/dist/src/agent-session-codecs.js.map +1 -0
- package/dist/src/agent-session-flow.d.ts +148 -0
- package/dist/src/agent-session-flow.js +276 -0
- package/dist/src/agent-session-flow.js.map +1 -0
- package/dist/src/agent-session-persistence.d.ts +56 -0
- package/dist/src/agent-session-persistence.js +43 -0
- package/dist/src/agent-session-persistence.js.map +1 -0
- package/dist/src/agent-session-steps.d.ts +86 -0
- package/dist/src/agent-session-steps.js +533 -0
- package/dist/src/agent-session-steps.js.map +1 -0
- package/dist/src/agent-session-transitions.d.ts +61 -0
- package/dist/src/agent-session-transitions.js +202 -0
- package/dist/src/agent-session-transitions.js.map +1 -0
- package/dist/src/agent-session-values.d.ts +337 -0
- package/dist/src/agent-session-values.js +127 -0
- package/dist/src/agent-session-values.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +12 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/testing/agent-session-test-client.d.ts +148 -0
- package/dist/src/testing/agent-session-test-client.js +217 -0
- package/dist/src/testing/agent-session-test-client.js.map +1 -0
- package/dist/src/testing/agent-test-environment.d.ts +52 -0
- package/dist/src/testing/agent-test-environment.js +86 -0
- package/dist/src/testing/agent-test-environment.js.map +1 -0
- package/dist/src/testing/agent-worker-process.d.ts +91 -0
- package/dist/src/testing/agent-worker-process.js +150 -0
- package/dist/src/testing/agent-worker-process.js.map +1 -0
- package/dist/src/testing/child-process-group.d.ts +33 -0
- package/dist/src/testing/child-process-group.js +164 -0
- package/dist/src/testing/child-process-group.js.map +1 -0
- package/dist/src/testing/coordination.d.ts +99 -0
- package/dist/src/testing/coordination.js +155 -0
- package/dist/src/testing/coordination.js.map +1 -0
- package/dist/src/testing/index.d.ts +7 -0
- package/dist/src/testing/index.js +15 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/testing/polling.d.ts +31 -0
- package/dist/src/testing/polling.js +51 -0
- package/dist/src/testing/polling.js.map +1 -0
- package/dist/src/testing/private-dex-engine.d.ts +92 -0
- package/dist/src/testing/private-dex-engine.js +215 -0
- package/dist/src/testing/private-dex-engine.js.map +1 -0
- package/dist/src/testing/step-history.d.ts +40 -0
- package/dist/src/testing/step-history.js +59 -0
- package/dist/src/testing/step-history.js.map +1 -0
- package/package.json +50 -4
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
9
|
+
var useValue = arguments.length > 2;
|
|
10
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
11
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
12
|
+
}
|
|
13
|
+
return useValue ? value : void 0;
|
|
14
|
+
};
|
|
15
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
16
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
17
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
18
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
19
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
20
|
+
var _, done = false;
|
|
21
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
22
|
+
var context = {};
|
|
23
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
24
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
25
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
26
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
27
|
+
if (kind === "accessor") {
|
|
28
|
+
if (result === void 0) continue;
|
|
29
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
30
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
31
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
32
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
33
|
+
}
|
|
34
|
+
else if (_ = accept(result)) {
|
|
35
|
+
if (kind === "field") initializers.unshift(_);
|
|
36
|
+
else descriptor[key] = _;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
40
|
+
done = true;
|
|
41
|
+
};
|
|
42
|
+
import { StepList, booleanCodec, rpc, } from "@superdurable/dex";
|
|
43
|
+
import { agentMessagesPageCodec, agentSnapshotCodec, agentUserMessageCodec, listAgentMessagesInputCodec, resolveInterruptInputCodec, } from "./agent-session-codecs.js";
|
|
44
|
+
import { createAgentSessionPersistence, defaultAgentEventsCapacityBytes, } from "./agent-session-persistence.js";
|
|
45
|
+
import { AwaitToolApprovalStep, AwaitUserMessageStep, RecordTurnFailureStep, ResumeTurnStep, RunModelStep, StartAgentSessionStep, ToolCallFailureRecordingStep, ToolCallStep, } from "./agent-session-steps.js";
|
|
46
|
+
import { AgentSessionTransitions, agentSessionStepTypes, } from "./agent-session-transitions.js";
|
|
47
|
+
const snapshotMessageLimit = 200;
|
|
48
|
+
const messagePageLimit = 200;
|
|
49
|
+
const toolEffects = [
|
|
50
|
+
"read",
|
|
51
|
+
"idempotent_write",
|
|
52
|
+
"non_idempotent_write",
|
|
53
|
+
"unclassified",
|
|
54
|
+
];
|
|
55
|
+
/**
|
|
56
|
+
* Creates the shared agent session Flow for one agent and its framework runner.
|
|
57
|
+
*
|
|
58
|
+
* Construct it once per agent at application startup and pass the same object to the Registry and
|
|
59
|
+
* every Client call. Each call creates a distinct Flow with its own Step instances, persistence
|
|
60
|
+
* definitions, and RPC methods, so one Registry can hold several agents under different Flow types.
|
|
61
|
+
* Adapter packages wrap this function; applications usually call the adapter's factory instead.
|
|
62
|
+
*
|
|
63
|
+
* It is a function rather than a class because the Dex Client identifies an RPC by its method
|
|
64
|
+
* function, and two Flows of one class would share their RPC methods.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const triage = createAgentSessionFlow(triageRunner, "TriageAgent", {
|
|
69
|
+
* toolPolicies: { lookup_customer: { effect: "read" } },
|
|
70
|
+
* interruptDeadlineMs: 24 * 60 * 60 * 1000,
|
|
71
|
+
* });
|
|
72
|
+
* const billing = createAgentSessionFlow(billingRunner, "BillingAgent");
|
|
73
|
+
* const registry = new Registry([triage, billing]);
|
|
74
|
+
* ```
|
|
75
|
+
* @param runner - Framework runner; the Flow owns no other dependency.
|
|
76
|
+
* @param flowType - Flow type, unique within the Registry, such as `"TriageAgent"`. Keep it stable:
|
|
77
|
+
* running sessions resume by it.
|
|
78
|
+
* @param options - Tool policies, Stream capacity, and approval deadline. Defaults to all defaults.
|
|
79
|
+
* @returns A new Flow to register in one Registry.
|
|
80
|
+
* @throws {TypeError} When `flowType` is blank, the runner is incomplete, or an effect is unknown.
|
|
81
|
+
* @throws {RangeError} When `eventStreamCapacityBytes` or `interruptDeadlineMs` is not positive.
|
|
82
|
+
*/
|
|
83
|
+
export function createAgentSessionFlow(runner, flowType, options = {}) {
|
|
84
|
+
const config = resolveAgentSessionConfig(runner, flowType, options);
|
|
85
|
+
const persistence = createAgentSessionPersistence(config.eventStreamCapacityBytes);
|
|
86
|
+
const transitions = new AgentSessionTransitions(persistence, runner, config);
|
|
87
|
+
const resolvedOptions = Object.freeze({
|
|
88
|
+
toolPolicies: config.toolPolicies,
|
|
89
|
+
defaultToolEffect: config.defaultToolEffect,
|
|
90
|
+
eventStreamCapacityBytes: config.eventStreamCapacityBytes,
|
|
91
|
+
interruptDeadlineMs: config.interruptDeadlineMs,
|
|
92
|
+
});
|
|
93
|
+
// A class per Flow gives each Flow its own RPC methods, which the Dex Client identifies by function.
|
|
94
|
+
let AgentSessionFlowDefinition = (() => {
|
|
95
|
+
let _instanceExtraInitializers = [];
|
|
96
|
+
let _sendUserMessage_decorators;
|
|
97
|
+
let _resolveInterrupt_decorators;
|
|
98
|
+
let _getAgentSnapshot_decorators;
|
|
99
|
+
let _listAgentMessages_decorators;
|
|
100
|
+
return class AgentSessionFlowDefinition {
|
|
101
|
+
static {
|
|
102
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
103
|
+
_sendUserMessage_decorators = [rpc({
|
|
104
|
+
name: "send_user_message",
|
|
105
|
+
inputCodec: agentUserMessageCodec,
|
|
106
|
+
outputCodec: booleanCodec,
|
|
107
|
+
})];
|
|
108
|
+
_resolveInterrupt_decorators = [rpc({
|
|
109
|
+
name: "resolve_interrupt",
|
|
110
|
+
inputCodec: resolveInterruptInputCodec,
|
|
111
|
+
outputCodec: booleanCodec,
|
|
112
|
+
lockAttributes: [persistence.pendingInterrupts.lock()],
|
|
113
|
+
})];
|
|
114
|
+
_getAgentSnapshot_decorators = [rpc({
|
|
115
|
+
name: "get_agent_snapshot",
|
|
116
|
+
outputCodec: agentSnapshotCodec,
|
|
117
|
+
loadAttributeMaps: [persistence.agentMessages, persistence.agentToolCalls],
|
|
118
|
+
})];
|
|
119
|
+
_listAgentMessages_decorators = [rpc({
|
|
120
|
+
name: "list_agent_messages",
|
|
121
|
+
inputCodec: listAgentMessagesInputCodec,
|
|
122
|
+
outputCodec: agentMessagesPageCodec,
|
|
123
|
+
loadAttributeMaps: [persistence.agentMessages],
|
|
124
|
+
})];
|
|
125
|
+
__esDecorate(this, null, _sendUserMessage_decorators, { kind: "method", name: "sendUserMessage", static: false, private: false, access: { has: obj => "sendUserMessage" in obj, get: obj => obj.sendUserMessage }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
126
|
+
__esDecorate(this, null, _resolveInterrupt_decorators, { kind: "method", name: "resolveInterrupt", static: false, private: false, access: { has: obj => "resolveInterrupt" in obj, get: obj => obj.resolveInterrupt }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
127
|
+
__esDecorate(this, null, _getAgentSnapshot_decorators, { kind: "method", name: "getAgentSnapshot", static: false, private: false, access: { has: obj => "getAgentSnapshot" in obj, get: obj => obj.getAgentSnapshot }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
128
|
+
__esDecorate(this, null, _listAgentMessages_decorators, { kind: "method", name: "listAgentMessages", static: false, private: false, access: { has: obj => "listAgentMessages" in obj, get: obj => obj.listAgentMessages }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
129
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
130
|
+
}
|
|
131
|
+
runner = (__runInitializers(this, _instanceExtraInitializers), runner);
|
|
132
|
+
options = resolvedOptions;
|
|
133
|
+
agentState = persistence.agentState;
|
|
134
|
+
agentMessages = persistence.agentMessages;
|
|
135
|
+
frameworkRunState = persistence.frameworkRunState;
|
|
136
|
+
agentToolCalls = persistence.agentToolCalls;
|
|
137
|
+
pendingInterrupts = persistence.pendingInterrupts;
|
|
138
|
+
agentUsage = persistence.agentUsage;
|
|
139
|
+
queuedUserMessages = persistence.queuedUserMessages;
|
|
140
|
+
interruptResolutions = persistence.interruptResolutions;
|
|
141
|
+
toolCallResults = persistence.toolCallResults;
|
|
142
|
+
agentEvents = persistence.agentEvents;
|
|
143
|
+
steps = StepList.startStep(new StartAgentSessionStep(transitions)).otherSteps(new AwaitUserMessageStep(transitions), new RunModelStep(transitions), new AwaitToolApprovalStep(transitions), new ToolCallStep(transitions, agentSessionStepTypes.callTool), new ToolCallStep(transitions, agentSessionStepTypes.callSingleAttemptTool), new ToolCallFailureRecordingStep(transitions, agentSessionStepTypes.recordToolFailure, true), new ToolCallFailureRecordingStep(transitions, agentSessionStepTypes.recordToolOutcomeUnknown, false), new ResumeTurnStep(transitions), new RecordTurnFailureStep(transitions));
|
|
144
|
+
getFlowType() {
|
|
145
|
+
return config.flowType;
|
|
146
|
+
}
|
|
147
|
+
getSteps() {
|
|
148
|
+
return this.steps;
|
|
149
|
+
}
|
|
150
|
+
getPersistenceSchema() {
|
|
151
|
+
return {
|
|
152
|
+
attributes: [
|
|
153
|
+
persistence.agentState,
|
|
154
|
+
persistence.agentMessages,
|
|
155
|
+
persistence.frameworkRunState,
|
|
156
|
+
persistence.agentToolCalls,
|
|
157
|
+
persistence.pendingInterrupts,
|
|
158
|
+
persistence.agentUsage,
|
|
159
|
+
],
|
|
160
|
+
channels: [
|
|
161
|
+
persistence.queuedUserMessages,
|
|
162
|
+
persistence.interruptResolutions,
|
|
163
|
+
persistence.toolCallResults,
|
|
164
|
+
],
|
|
165
|
+
streams: [persistence.agentEvents],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
sendUserMessage(context, message) {
|
|
169
|
+
if (message.text.trim() === "") {
|
|
170
|
+
return { output: false };
|
|
171
|
+
}
|
|
172
|
+
persistence.queuedUserMessages.publish(context, { text: message.text });
|
|
173
|
+
return { output: true };
|
|
174
|
+
}
|
|
175
|
+
resolveInterrupt(context, input) {
|
|
176
|
+
const pendingInterrupts = transitions.readPendingInterrupts(context);
|
|
177
|
+
const interrupt = pendingInterrupts.find((pending) => pending.interruptId === input.interruptId);
|
|
178
|
+
// After the deadline, AwaitToolApproval rejects the call; a late answer must not win.
|
|
179
|
+
if (interrupt === undefined ||
|
|
180
|
+
(interrupt.deadline !== null && Date.parse(interrupt.deadline) <= Date.now())) {
|
|
181
|
+
return { output: false };
|
|
182
|
+
}
|
|
183
|
+
persistence.pendingInterrupts.set(context, pendingInterrupts.filter((interrupt) => interrupt.interruptId !== input.interruptId));
|
|
184
|
+
persistence.interruptResolutions.publish(context, input.interruptId, {
|
|
185
|
+
approved: input.approved,
|
|
186
|
+
rejectionMessage: input.approved ? null : input.rejectionMessage,
|
|
187
|
+
});
|
|
188
|
+
return { output: true };
|
|
189
|
+
}
|
|
190
|
+
getAgentSnapshot(context) {
|
|
191
|
+
const state = transitions.readOptionalAgentState(context);
|
|
192
|
+
if (state === null) {
|
|
193
|
+
return {
|
|
194
|
+
output: {
|
|
195
|
+
state: null,
|
|
196
|
+
messages: [],
|
|
197
|
+
pendingInterrupts: [],
|
|
198
|
+
toolCalls: [],
|
|
199
|
+
usage: transitions.readAgentUsage(context),
|
|
200
|
+
queuedMessageCount: 0,
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const end = state.nextMessageSequence;
|
|
205
|
+
return {
|
|
206
|
+
output: {
|
|
207
|
+
state,
|
|
208
|
+
messages: transitions.readMessages(context, end - snapshotMessageLimit, end),
|
|
209
|
+
pendingInterrupts: transitions.readPendingInterrupts(context),
|
|
210
|
+
toolCalls: transitions.readTurnToolCalls(context, state.activeTurnId),
|
|
211
|
+
usage: transitions.readAgentUsage(context),
|
|
212
|
+
queuedMessageCount: context.channelSize(persistence.queuedUserMessages),
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
listAgentMessages(context, input) {
|
|
217
|
+
const state = transitions.readOptionalAgentState(context);
|
|
218
|
+
if (state === null) {
|
|
219
|
+
return { output: { messages: [], nextBeforeSequence: null } };
|
|
220
|
+
}
|
|
221
|
+
const limit = Math.max(1, Math.min(input.limit, messagePageLimit));
|
|
222
|
+
let end = state.nextMessageSequence;
|
|
223
|
+
if (input.beforeSequence !== null) {
|
|
224
|
+
end = Math.max(1, Math.min(input.beforeSequence, end));
|
|
225
|
+
}
|
|
226
|
+
const start = Math.max(1, end - limit);
|
|
227
|
+
return {
|
|
228
|
+
output: {
|
|
229
|
+
messages: transitions.readMessages(context, start, end),
|
|
230
|
+
nextBeforeSequence: start > 1 ? start : null,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
})();
|
|
236
|
+
return new AgentSessionFlowDefinition();
|
|
237
|
+
}
|
|
238
|
+
function resolveAgentSessionConfig(runner, flowType, options) {
|
|
239
|
+
if (typeof runner?.buildUserMessage !== "function" ||
|
|
240
|
+
typeof runner.runModelStep !== "function" ||
|
|
241
|
+
typeof runner.executeDeferredToolCall !== "function") {
|
|
242
|
+
throw new TypeError("createAgentSessionFlow requires an AgentFrameworkRunner");
|
|
243
|
+
}
|
|
244
|
+
if (typeof flowType !== "string" || flowType.trim() === "") {
|
|
245
|
+
throw new TypeError("flowType must be a non-blank string");
|
|
246
|
+
}
|
|
247
|
+
const defaultToolEffect = options.defaultToolEffect ?? "unclassified";
|
|
248
|
+
requireToolEffect(defaultToolEffect, "defaultToolEffect");
|
|
249
|
+
const toolPolicies = {};
|
|
250
|
+
for (const [toolName, policy] of Object.entries(options.toolPolicies ?? {})) {
|
|
251
|
+
requireToolEffect(policy.effect, `tool policy ${toolName}`);
|
|
252
|
+
toolPolicies[toolName] = Object.freeze({ ...policy });
|
|
253
|
+
}
|
|
254
|
+
const eventStreamCapacityBytes = options.eventStreamCapacityBytes ?? defaultAgentEventsCapacityBytes;
|
|
255
|
+
if (!Number.isSafeInteger(eventStreamCapacityBytes) || eventStreamCapacityBytes <= 0) {
|
|
256
|
+
throw new RangeError("eventStreamCapacityBytes must be a positive integer");
|
|
257
|
+
}
|
|
258
|
+
const interruptDeadlineMs = options.interruptDeadlineMs;
|
|
259
|
+
if (interruptDeadlineMs !== undefined &&
|
|
260
|
+
(!Number.isFinite(interruptDeadlineMs) || interruptDeadlineMs <= 0)) {
|
|
261
|
+
throw new RangeError("interruptDeadlineMs must be positive");
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
flowType,
|
|
265
|
+
toolPolicies: Object.freeze(toolPolicies),
|
|
266
|
+
defaultToolEffect,
|
|
267
|
+
eventStreamCapacityBytes,
|
|
268
|
+
interruptDeadlineMs,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function requireToolEffect(effect, description) {
|
|
272
|
+
if (!toolEffects.includes(effect)) {
|
|
273
|
+
throw new TypeError(`${description} has unknown tool effect ${String(effect)}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=agent-session-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-session-flow.js","sourceRoot":"","sources":["../../src/agent-session-flow.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,kDAAkD;AAClD,mEAAmE;AACnE,+CAA+C;AAC/C,EAAE;AACF,0DAA0D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1D,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,GAAG,GAKJ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,6BAA6B,EAC7B,+BAA+B,GAEhC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,YAAY,GACb,MAAM,0B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GAAG,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,wBAAwB,GAC5B,OAAO,CAAC,wBAAwB,IAAI,+BAA+B,CAAC;IACtE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,wBAAwB,CAAC,IAAI,wBAAwB,IAAI,CAAC,EAAE,CAAC;QACrF,MAAM,IAAI,UAAU,CAAC,qDAAqD,CAAC,CAAC;IAC9E,CAAC;IACD,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACxD,IACE,mBAAmB,KAAK,SAAS;QACjC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,mBAAmB,IAAI,CAAC,CAAC,EACnE,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO;QACL,QAAQ;QACR,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;QACzC,iBAAiB;QACjB,wBAAwB;QACxB,mBAAmB;KACpB,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,MAAkB,EAAE,WAAmB;IAChE,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,SAAS,CAAC,GAAG,WAAW,4BAA4B,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Attribute, AttributeMap, Channel, ChannelMap, Stream } from "@superdurable/dex";
|
|
2
|
+
import type { AgentEvent, AgentInterrupt, AgentInterruptResolution, AgentMessage, AgentState, AgentToolCall, AgentUsage, AgentUserMessage, ToolCallCompleted } from "./agent-session-values.js";
|
|
3
|
+
/** Default byte budget of the `AgentEvents` Stream: 10 MiB. */
|
|
4
|
+
export declare const defaultAgentEventsCapacityBytes: number;
|
|
5
|
+
/**
|
|
6
|
+
* Persistence definitions registered by one agent session Flow.
|
|
7
|
+
*
|
|
8
|
+
* Every Flow returned by {@link createAgentSessionFlow} owns its own definition objects, available as
|
|
9
|
+
* properties of the Flow. Pass them to `Client.getAttributes`, `Client.readStream`, or
|
|
10
|
+
* `Client.listStreamMessages` to read a session from outside the Flow. The persisted names are wire
|
|
11
|
+
* contracts shared with the Python core.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const [state, usage] = await client.getAttributes(sessionId, flow.agentState, flow.agentUsage);
|
|
16
|
+
* const page = await client.listStreamMessages(sessionId, flow.agentEvents, 50);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export interface AgentSessionPersistence {
|
|
20
|
+
/** The `AgentState` Attribute. It is always set after `StartAgentSession`. */
|
|
21
|
+
readonly agentState: Attribute<AgentState>;
|
|
22
|
+
/** The `AgentMessages` AttributeMap, keyed by sequence as 12-digit zero-padded decimal. */
|
|
23
|
+
readonly agentMessages: AttributeMap<AgentMessage>;
|
|
24
|
+
/** The `FrameworkRunState` Attribute: opaque framework JSON, set only while a turn is suspended. */
|
|
25
|
+
readonly frameworkRunState: Attribute<string>;
|
|
26
|
+
/** The `AgentToolCalls` AttributeMap, keyed by tool call ID; holds only the active turn's records. */
|
|
27
|
+
readonly agentToolCalls: AttributeMap<AgentToolCall>;
|
|
28
|
+
/** The `PendingInterrupts` Attribute: interrupts that `resolve_interrupt` still accepts. */
|
|
29
|
+
readonly pendingInterrupts: Attribute<readonly AgentInterrupt[]>;
|
|
30
|
+
/** The `AgentUsage` Attribute: cumulative usage of every turn. */
|
|
31
|
+
readonly agentUsage: Attribute<AgentUsage>;
|
|
32
|
+
/** The `QueuedUserMessages` Channel; `send_user_message` publishes and `AwaitUserMessage` consumes. */
|
|
33
|
+
readonly queuedUserMessages: Channel<AgentUserMessage>;
|
|
34
|
+
/** The `InterruptResolutions` ChannelMap, keyed by interrupt ID. */
|
|
35
|
+
readonly interruptResolutions: ChannelMap<AgentInterruptResolution>;
|
|
36
|
+
/**
|
|
37
|
+
* The internal `ToolCallResults` Channel. Every tool call of a batch publishes one message when its
|
|
38
|
+
* record becomes final, and `ResumeTurn` consumes them. Applications never publish to it.
|
|
39
|
+
*/
|
|
40
|
+
readonly toolCallResults: Channel<ToolCallCompleted>;
|
|
41
|
+
/** The best-effort `AgentEvents` Stream. Rebuild durable state with `get_agent_snapshot`. */
|
|
42
|
+
readonly agentEvents: Stream<AgentEvent>;
|
|
43
|
+
}
|
|
44
|
+
export declare function createAgentSessionPersistence(agentEventsCapacityBytes: number): AgentSessionPersistence;
|
|
45
|
+
/**
|
|
46
|
+
* Returns the `AgentMessages` map instance of a message sequence.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const [message] = await client.getAttributes(sessionId, flow.agentMessages.instance(messageSequenceKey(7)));
|
|
51
|
+
* ```
|
|
52
|
+
* @param sequence - Positive message sequence.
|
|
53
|
+
* @returns The sequence as a 12-digit zero-padded decimal, such as `"000000000007"`.
|
|
54
|
+
* @throws {RangeError} When `sequence` is not a positive safe integer.
|
|
55
|
+
*/
|
|
56
|
+
export declare function messageSequenceKey(sequence: number): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { 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";
|
|
10
|
+
/** Default byte budget of the `AgentEvents` Stream: 10 MiB. */
|
|
11
|
+
export const defaultAgentEventsCapacityBytes = 10 * 1024 * 1024;
|
|
12
|
+
export function createAgentSessionPersistence(agentEventsCapacityBytes) {
|
|
13
|
+
return {
|
|
14
|
+
agentState: new Attribute("AgentState", agentStateCodec),
|
|
15
|
+
agentMessages: new AttributeMap("AgentMessages", agentMessageCodec),
|
|
16
|
+
frameworkRunState: new Attribute("FrameworkRunState", stringCodec),
|
|
17
|
+
agentToolCalls: new AttributeMap("AgentToolCalls", agentToolCallCodec),
|
|
18
|
+
pendingInterrupts: new Attribute("PendingInterrupts", agentInterruptListCodec),
|
|
19
|
+
agentUsage: new Attribute("AgentUsage", agentUsageCodec),
|
|
20
|
+
queuedUserMessages: new Channel("QueuedUserMessages", agentUserMessageCodec),
|
|
21
|
+
interruptResolutions: new ChannelMap("InterruptResolutions", agentInterruptResolutionCodec),
|
|
22
|
+
toolCallResults: new Channel("ToolCallResults", toolCallCompletedCodec),
|
|
23
|
+
agentEvents: new Stream("AgentEvents", agentEventCodec, agentEventsCapacityBytes),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the `AgentMessages` map instance of a message sequence.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const [message] = await client.getAttributes(sessionId, flow.agentMessages.instance(messageSequenceKey(7)));
|
|
32
|
+
* ```
|
|
33
|
+
* @param sequence - Positive message sequence.
|
|
34
|
+
* @returns The sequence as a 12-digit zero-padded decimal, such as `"000000000007"`.
|
|
35
|
+
* @throws {RangeError} When `sequence` is not a positive safe integer.
|
|
36
|
+
*/
|
|
37
|
+
export function messageSequenceKey(sequence) {
|
|
38
|
+
if (!Number.isSafeInteger(sequence) || sequence <= 0) {
|
|
39
|
+
throw new RangeError(`message sequence must be a positive integer: ${sequence}`);
|
|
40
|
+
}
|
|
41
|
+
return String(sequence).padStart(12, "0");
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=agent-session-persistence.js.map
|
|
@@ -0,0 +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,GACvB,MAAM,2BAA2B,CAAC;AAanC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AA0ChE,MAAM,UAAU,6BAA6B,CAC3C,wBAAgC;IAEhC,OAAO;QACL,UAAU,EAAE,IAAI,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC;QACxD,aAAa,EAAE,IAAI,YAAY,CAAC,eAAe,EAAE,iBAAiB,CAAC;QACnE,iBAAiB,EAAE,IAAI,SAAS,CAAC,mBAAmB,EAAE,WAAW,CAAC;QAClE,cAAc,EAAE,IAAI,YAAY,CAAC,gBAAgB,EAAE,kBAAkB,CAAC;QACtE,iBAAiB,EAAE,IAAI,SAAS,CAAC,mBAAmB,EAAE,uBAAuB,CAAC;QAC9E,UAAU,EAAE,IAAI,SAAS,CAAC,YAAY,EAAE,eAAe,CAAC;QACxD,kBAAkB,EAAE,IAAI,OAAO,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;QAC5E,oBAAoB,EAAE,IAAI,UAAU,CAAC,sBAAsB,EAAE,6BAA6B,CAAC;QAC3F,eAAe,EAAE,IAAI,OAAO,CAAC,iBAAiB,EAAE,sBAAsB,CAAC;QACvE,WAAW,EAAE,IAAI,MAAM,CAAC,aAAa,EAAE,eAAe,EAAE,wBAAwB,CAAC;KAClF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,UAAU,CAAC,gDAAgD,QAAQ,EAAE,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Wait, type AsyncContext, type Codec, type Context, type Step, type StepDecision, type StepOptions } from "@superdurable/dex";
|
|
2
|
+
import { type AgentSessionTransitions } from "./agent-session-transitions.js";
|
|
3
|
+
import { type AgentSessionStartInput } from "./agent-session-values.js";
|
|
4
|
+
export declare class StartAgentSessionStep implements Step<AgentSessionStartInput> {
|
|
5
|
+
private readonly transitions;
|
|
6
|
+
readonly inputCodec: Codec<AgentSessionStartInput>;
|
|
7
|
+
constructor(transitions: AgentSessionTransitions);
|
|
8
|
+
getStepType(): string;
|
|
9
|
+
getStepOptions(): StepOptions;
|
|
10
|
+
execute(context: Context, input: AgentSessionStartInput): StepDecision;
|
|
11
|
+
}
|
|
12
|
+
export declare class AwaitUserMessageStep implements Step<void> {
|
|
13
|
+
private readonly transitions;
|
|
14
|
+
readonly inputCodec: Codec<void>;
|
|
15
|
+
constructor(transitions: AgentSessionTransitions);
|
|
16
|
+
getStepType(): string;
|
|
17
|
+
getStepOptions(): StepOptions;
|
|
18
|
+
waitFor(): Wait;
|
|
19
|
+
execute(context: Context): StepDecision;
|
|
20
|
+
}
|
|
21
|
+
/** Makes the turn's next model call and fans the requested tool calls out to parallel Steps. */
|
|
22
|
+
export declare class RunModelStep implements Step<void> {
|
|
23
|
+
private readonly transitions;
|
|
24
|
+
readonly inputCodec: Codec<void>;
|
|
25
|
+
constructor(transitions: AgentSessionTransitions);
|
|
26
|
+
getStepType(): string;
|
|
27
|
+
getStepOptions(): StepOptions;
|
|
28
|
+
execute(context: AsyncContext): Promise<StepDecision>;
|
|
29
|
+
private completeTurn;
|
|
30
|
+
private requestToolCalls;
|
|
31
|
+
}
|
|
32
|
+
/** Waits for one tool call's approval or its deadline, then runs or rejects the call. */
|
|
33
|
+
export declare class AwaitToolApprovalStep implements Step<string> {
|
|
34
|
+
private readonly transitions;
|
|
35
|
+
readonly inputCodec: Codec<string>;
|
|
36
|
+
constructor(transitions: AgentSessionTransitions);
|
|
37
|
+
getStepType(): string;
|
|
38
|
+
getStepOptions(): StepOptions;
|
|
39
|
+
waitFor(context: Context, toolCallId: string): Wait;
|
|
40
|
+
execute(context: Context, toolCallId: string): StepDecision;
|
|
41
|
+
private rejectToolCall;
|
|
42
|
+
private writeInterruptResolved;
|
|
43
|
+
}
|
|
44
|
+
/** Runs one tool call; one class serves `CallTool` and `CallSingleAttemptTool`. */
|
|
45
|
+
export declare class ToolCallStep implements Step<string> {
|
|
46
|
+
private readonly transitions;
|
|
47
|
+
private readonly stepType;
|
|
48
|
+
readonly inputCodec: Codec<string>;
|
|
49
|
+
constructor(transitions: AgentSessionTransitions, stepType: string);
|
|
50
|
+
getStepType(): string;
|
|
51
|
+
getStepOptions(): StepOptions;
|
|
52
|
+
execute(context: AsyncContext, toolCallId: string): Promise<StepDecision>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Failure route of a tool Step; it receives the failed Step's input, the tool call ID.
|
|
56
|
+
* `RecordToolFailure` records `failed` for a `read` call and `outcome_unknown` for a write;
|
|
57
|
+
* `RecordToolOutcomeUnknown` always records `outcome_unknown`.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ToolCallFailureRecordingStep implements Step<string> {
|
|
60
|
+
private readonly transitions;
|
|
61
|
+
private readonly stepType;
|
|
62
|
+
private readonly isReadFailureRecorded;
|
|
63
|
+
readonly inputCodec: Codec<string>;
|
|
64
|
+
constructor(transitions: AgentSessionTransitions, stepType: string, isReadFailureRecorded: boolean);
|
|
65
|
+
getStepType(): string;
|
|
66
|
+
getStepOptions(): StepOptions;
|
|
67
|
+
execute(context: Context, toolCallId: string): StepDecision;
|
|
68
|
+
}
|
|
69
|
+
/** Waits until every tool call of the batch has a final record, then makes the next model call. */
|
|
70
|
+
export declare class ResumeTurnStep implements Step<number> {
|
|
71
|
+
private readonly transitions;
|
|
72
|
+
readonly inputCodec: Codec<number>;
|
|
73
|
+
constructor(transitions: AgentSessionTransitions);
|
|
74
|
+
getStepType(): string;
|
|
75
|
+
getStepOptions(): StepOptions;
|
|
76
|
+
waitFor(_context: Context, expectedResultCount: number): Wait;
|
|
77
|
+
execute(context: Context): StepDecision;
|
|
78
|
+
}
|
|
79
|
+
export declare class RecordTurnFailureStep implements Step<void> {
|
|
80
|
+
private readonly transitions;
|
|
81
|
+
readonly inputCodec: Codec<void>;
|
|
82
|
+
constructor(transitions: AgentSessionTransitions);
|
|
83
|
+
getStepType(): string;
|
|
84
|
+
getStepOptions(): StepOptions;
|
|
85
|
+
execute(context: Context): StepDecision;
|
|
86
|
+
}
|