@superdurable/dex-agents 0.1.0 → 0.3.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 +1608 -64
- 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 +254 -0
- package/dist/src/agent-context-compaction.js +287 -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 +343 -8
- package/dist/src/agent-session-codecs.js.map +1 -1
- package/dist/src/agent-session-failure.d.ts +58 -0
- package/dist/src/agent-session-failure.js +126 -0
- package/dist/src/agent-session-failure.js.map +1 -0
- package/dist/src/agent-session-flow-graph-cli.d.ts +2 -0
- package/dist/src/agent-session-flow-graph-cli.js +47 -0
- package/dist/src/agent-session-flow-graph-cli.js.map +1 -0
- package/dist/src/agent-session-flow-graph.d.ts +38 -0
- package/dist/src/agent-session-flow-graph.js +54 -0
- package/dist/src/agent-session-flow-graph.js.map +1 -0
- package/dist/src/agent-session-flow-graph.json +2187 -0
- package/dist/src/agent-session-flow.d.ts +317 -28
- package/dist/src/agent-session-flow.js +373 -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-spend-limit.d.ts +156 -0
- package/dist/src/agent-session-spend-limit.js +42 -0
- package/dist/src/agent-session-spend-limit.js.map +1 -0
- package/dist/src/agent-session-start.d.ts +49 -0
- package/dist/src/agent-session-start.js +67 -0
- package/dist/src/agent-session-start.js.map +1 -0
- package/dist/src/agent-session-step-options.d.ts +78 -0
- package/dist/src/agent-session-step-options.js +71 -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 +103 -8
- package/dist/src/agent-session-steps.js +997 -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 +200 -26
- package/dist/src/agent-session-transitions.js +732 -32
- package/dist/src/agent-session-transitions.js.map +1 -1
- package/dist/src/agent-session-values.d.ts +696 -30
- 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 +14 -3
- package/dist/src/index.js +12 -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 +166 -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 +8 -0
- package/dist/src/stepwise/index.js +13 -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 +171 -0
- package/dist/src/stepwise/stepwise-agent-runner.js +777 -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 +57 -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 +92 -22
- package/dist/src/testing/agent-session-test-client.js.map +1 -1
- package/dist/src/testing/context-window.d.ts +194 -0
- package/dist/src/testing/context-window.js +360 -0
- package/dist/src/testing/context-window.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +2 -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 +155 -0
- package/dist/src/ui-stream/agent-event-sse.js +167 -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 +74 -0
- package/dist/src/ui-stream/agent-session-record-reader.js +246 -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 +441 -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 +695 -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 +68 -0
- package/dist/src/ui-stream/agent-ui-messages.js +222 -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 +44 -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 { startAgentSession } from "../agent-session-start.js";
|
|
10
11
|
import { pollUntil } from "./polling.js";
|
|
11
12
|
const lockConflictRetryTimeoutMs = 30_000;
|
|
12
13
|
const lockConflictRetryIntervalMs = 50;
|
|
@@ -48,19 +49,79 @@ 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
|
-
await this.client
|
|
56
|
+
async startSession(sessionId, initialMessage = null, startFlowOptions = {}, sessionSettings = null) {
|
|
57
|
+
await startAgentSession(this.client, this.flow, sessionId, { initialMessage, sessionSettings }, startFlowOptions);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Calls `update_session_settings`.
|
|
61
|
+
* @param sessionId - Session Flow ID.
|
|
62
|
+
* @param sessionSettings - The complete new settings; `{}` clears them.
|
|
63
|
+
* @returns The RPC result: `false` before the session initialized or for settings over the limit.
|
|
64
|
+
*/
|
|
65
|
+
updateSessionSettings(sessionId, sessionSettings) {
|
|
66
|
+
return this.client.invokeRPC(this.flow.updateSessionSettings, sessionId, { sessionSettings });
|
|
55
67
|
}
|
|
56
68
|
/**
|
|
57
69
|
* Calls `send_user_message`.
|
|
58
70
|
* @param sessionId - Session Flow ID.
|
|
59
71
|
* @param text - Message text.
|
|
60
|
-
* @
|
|
72
|
+
* @param planMode - Whether the message starts a planning turn. Defaults to `false`.
|
|
73
|
+
* @returns The RPC result: `false` for blank text, or for a `planMode` message when plan mode is off.
|
|
74
|
+
*/
|
|
75
|
+
sendUserMessage(sessionId, text, planMode = false) {
|
|
76
|
+
return this.client.invokeRPC(this.flow.sendUserMessage, sessionId, { text, planMode });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Calls `execute_plan`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
80
|
+
* @param sessionId - Session Flow ID.
|
|
81
|
+
* @param revision - Plan revision to execute.
|
|
82
|
+
* @returns The RPC result: `false` when the revision is stale, already pending, or the session is busy.
|
|
83
|
+
*/
|
|
84
|
+
executePlan(sessionId, revision) {
|
|
85
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.executePlan, sessionId, { revision }));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Calls `steer_user_message` with new text; while no turn is active, the RPC queues it.
|
|
89
|
+
* @param sessionId - Session Flow ID.
|
|
90
|
+
* @param text - Text of the steered message.
|
|
91
|
+
* @returns The RPC result: `false` for blank text or a turn that does not accept steering.
|
|
92
|
+
*/
|
|
93
|
+
steerUserMessage(sessionId, text) {
|
|
94
|
+
return this.client.invokeRPC(this.flow.steerUserMessage, sessionId, { messageId: null, text });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Calls `steer_user_message` with a queued message's ID, which moves that message.
|
|
98
|
+
* @param sessionId - Session Flow ID.
|
|
99
|
+
* @param messageId - {@link PendingUserMessage.messageId} of a queued message.
|
|
100
|
+
* @returns The RPC result: `false` when the message is no longer queued.
|
|
101
|
+
* @throws {ChannelMessageNotFoundError} When the session consumed the message while the RPC ran.
|
|
102
|
+
*/
|
|
103
|
+
steerQueuedMessage(sessionId, messageId) {
|
|
104
|
+
return this.client.invokeRPC(this.flow.steerUserMessage, sessionId, { messageId, text: null });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Calls `delete_queued_message`.
|
|
108
|
+
* @param sessionId - Session Flow ID.
|
|
109
|
+
* @param messageId - {@link PendingUserMessage.messageId} of a queued message.
|
|
110
|
+
* @returns The RPC result: `false` when the message is no longer queued.
|
|
111
|
+
* @throws {ChannelMessageNotFoundError} When the session consumed the message while the RPC ran.
|
|
61
112
|
*/
|
|
62
|
-
|
|
63
|
-
return this.client.invokeRPC(this.flow.
|
|
113
|
+
deleteQueuedMessage(sessionId, messageId) {
|
|
114
|
+
return this.client.invokeRPC(this.flow.deleteQueuedMessage, sessionId, { messageId });
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Calls `cancel_turn`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
118
|
+
* @param sessionId - Session Flow ID.
|
|
119
|
+
* @param turnId - The turn to stop, or `null` for the active turn. Defaults to `null`.
|
|
120
|
+
* @returns The RPC result: `false` when no turn is active, `turnId` names another turn, or the turn does not
|
|
121
|
+
* accept cancellation.
|
|
122
|
+
*/
|
|
123
|
+
cancelTurn(sessionId, turnId = null) {
|
|
124
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.cancelTurn, sessionId, { turnId }));
|
|
64
125
|
}
|
|
65
126
|
/**
|
|
66
127
|
* Calls `resolve_interrupt`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
@@ -70,23 +131,18 @@ export class AgentSessionTestClient {
|
|
|
70
131
|
* @param rejectionMessage - Text shown to the model on rejection. Defaults to `null`.
|
|
71
132
|
* @returns The RPC result: `false` when the interrupt was not pending.
|
|
72
133
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
await delay(lockConflictRetryIntervalMs);
|
|
89
|
-
}
|
|
134
|
+
resolveInterrupt(sessionId, interruptId, approved, rejectionMessage = null) {
|
|
135
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.resolveInterrupt, sessionId, { interruptId, approved, rejectionMessage }));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Calls `answer_question`, retrying an `RpcLockConflictError` for up to 30 seconds.
|
|
139
|
+
* @param sessionId - Session Flow ID.
|
|
140
|
+
* @param interruptId - Pending `question` interrupt to answer.
|
|
141
|
+
* @param answer - The answer text.
|
|
142
|
+
* @returns The RPC result: `false` when the question was not pending or the answer was refused.
|
|
143
|
+
*/
|
|
144
|
+
answerQuestion(sessionId, interruptId, answer) {
|
|
145
|
+
return retryLockConflicts(() => this.client.invokeRPC(this.flow.answerQuestion, sessionId, { interruptId, answer }));
|
|
90
146
|
}
|
|
91
147
|
/**
|
|
92
148
|
* Calls `get_agent_snapshot`.
|
|
@@ -214,4 +270,18 @@ export class AgentSessionTestClient {
|
|
|
214
270
|
return newestFirst.reverse();
|
|
215
271
|
}
|
|
216
272
|
}
|
|
273
|
+
async function retryLockConflicts(invoke) {
|
|
274
|
+
const deadline = Date.now() + lockConflictRetryTimeoutMs;
|
|
275
|
+
for (;;) {
|
|
276
|
+
try {
|
|
277
|
+
return await invoke();
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (!(error instanceof RpcLockConflictError) || Date.now() >= deadline) {
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
await delay(lockConflictRetryIntervalMs);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
217
287
|
//# 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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AAC,IAAI,CAAC,WAAW,EACrB,cAAc,EACd,SAAS,CACV,CAAC;YACF,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YACnE,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;QACjC,CAAC,QAAQ,SAAS,KAAK,EAAE,EAAE;QAC3B,OAAO,WAAW,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;CACF;AAED,KAAK,UAAU,kBAAkB,CAAC,MAA8B;IAC9D,MAAM,QAAQ,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"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { type CompactionPolicy } from "../agent-context-compaction.js";
|
|
2
|
+
import type { AgentMessage, AgentSnapshot } from "../agent-session-values.js";
|
|
3
|
+
import { AgentSessionTestClient } from "./agent-session-test-client.js";
|
|
4
|
+
import { KillableWorkerProcess } from "./agent-worker-process.js";
|
|
5
|
+
/** Environment variable holding the JSON of {@link ContextWindowSettings}. */
|
|
6
|
+
export declare const contextWindowSettingsVariable = "DEX_AGENTS_CONTEXT_WINDOW_SETTINGS";
|
|
7
|
+
/** Tool that the scripted model calls once per turn. */
|
|
8
|
+
export declare const contextWindowToolName = "lookup";
|
|
9
|
+
/** Start of the error that the scripted model throws for an oversized request. */
|
|
10
|
+
export declare const contextWindowExceededError = "scripted model: input exceeds the context window";
|
|
11
|
+
/** Gate that holds a summary call of a range that names `gate-summary`. */
|
|
12
|
+
export declare const contextWindowSummaryGateName = "summary";
|
|
13
|
+
/**
|
|
14
|
+
* Sizes of the scripted model and the session of one context window test. A Worker child process reads them from
|
|
15
|
+
* {@link contextWindowSettingsVariable}.
|
|
16
|
+
*/
|
|
17
|
+
export interface ContextWindowSettings {
|
|
18
|
+
/** Context window of the scripted model, at four characters per token. */
|
|
19
|
+
readonly windowTokens: number;
|
|
20
|
+
/** Whether the session gets a compaction policy. */
|
|
21
|
+
readonly isCompactionEnabled: boolean;
|
|
22
|
+
/** Size of each tool result in characters. */
|
|
23
|
+
readonly toolOutputCharacters: number;
|
|
24
|
+
/** Size of each model answer in characters. */
|
|
25
|
+
readonly answerCharacters: number;
|
|
26
|
+
/** `AgentSessionOptions.messageWindowSize`. */
|
|
27
|
+
readonly messageWindowSize: number;
|
|
28
|
+
/** `AgentSessionOptions.messageChunkSize`. */
|
|
29
|
+
readonly messageChunkSize: number;
|
|
30
|
+
/** `AgentSessionOptions.retainedMessageLimit`; `null` keeps every message. */
|
|
31
|
+
readonly retainedMessageLimit: number | null;
|
|
32
|
+
}
|
|
33
|
+
/** The settings of a test that changes nothing. */
|
|
34
|
+
export declare const defaultContextWindowSettings: ContextWindowSettings;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the Worker environment that carries the settings.
|
|
37
|
+
* @param settings - The test's settings.
|
|
38
|
+
* @returns One entry under {@link contextWindowSettingsVariable}.
|
|
39
|
+
*/
|
|
40
|
+
export declare function contextWindowSettingsEnvironment(settings: ContextWindowSettings): Record<string, string>;
|
|
41
|
+
/**
|
|
42
|
+
* Reads the settings a test gave this Worker.
|
|
43
|
+
* @returns The test's settings, or the defaults outside a Worker child.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readContextWindowSettings(): ContextWindowSettings;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the `AgentSessionOptions` fields for the settings.
|
|
48
|
+
* @param settings - The test's settings.
|
|
49
|
+
* @returns The compaction policy and the message storage options.
|
|
50
|
+
*/
|
|
51
|
+
export declare function contextWindowSessionOptions(settings: ContextWindowSettings): {
|
|
52
|
+
readonly compaction?: CompactionPolicy;
|
|
53
|
+
readonly messageWindowSize: number;
|
|
54
|
+
readonly messageChunkSize: number;
|
|
55
|
+
readonly retainedMessageLimit: number | null;
|
|
56
|
+
};
|
|
57
|
+
/** What the scripted model does for one request: call the tool with a tag, or answer with a text. */
|
|
58
|
+
export type ContextWindowReply = {
|
|
59
|
+
readonly kind: "tool_call";
|
|
60
|
+
readonly tag: string;
|
|
61
|
+
} | {
|
|
62
|
+
readonly kind: "text";
|
|
63
|
+
readonly text: string;
|
|
64
|
+
};
|
|
65
|
+
/** One request the scripted model saw. */
|
|
66
|
+
export interface ContextWindowRequest {
|
|
67
|
+
/** `"model"` for an agent's request, `"summary"` for a summary call. */
|
|
68
|
+
readonly kind: "model" | "summary";
|
|
69
|
+
/** Characters of the request, instructions included. */
|
|
70
|
+
readonly characters: number;
|
|
71
|
+
/** The whole request as text, in the framework's format. */
|
|
72
|
+
readonly input: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Answers model requests of a framework adapter and logs every request, like a provider with a small context
|
|
76
|
+
* window. Each user message is `turn <tag>`: the model calls {@link contextWindowToolName} once with the tag, then
|
|
77
|
+
* answers {@link answerText}. It holds no state between calls, so it survives a Worker restart.
|
|
78
|
+
*/
|
|
79
|
+
export declare class ContextWindowModelScript {
|
|
80
|
+
private readonly stateDirectory;
|
|
81
|
+
private readonly settings;
|
|
82
|
+
/**
|
|
83
|
+
* @param stateDirectory - Directory shared with the test.
|
|
84
|
+
* @param settings - Sizes of the test.
|
|
85
|
+
*/
|
|
86
|
+
constructor(stateDirectory: string, settings: ContextWindowSettings);
|
|
87
|
+
/**
|
|
88
|
+
* Returns what the tool answers.
|
|
89
|
+
* @param tag - The tool call's `tag` argument.
|
|
90
|
+
* @returns Text of `toolOutputCharacters` that names the tag.
|
|
91
|
+
*/
|
|
92
|
+
toolOutput(tag: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the answer of the turn with this tag.
|
|
95
|
+
* @param tag - The tag of the user message.
|
|
96
|
+
* @returns Text of `answerCharacters` that names the tag.
|
|
97
|
+
*/
|
|
98
|
+
answerText(tag: string): string;
|
|
99
|
+
/**
|
|
100
|
+
* Answers one model request.
|
|
101
|
+
* @param request - The system prompt, the whole request as text, and whether the running turn has its result.
|
|
102
|
+
* @returns The tool call or the answer.
|
|
103
|
+
* @throws {Error} When the request exceeds the window or names no turn.
|
|
104
|
+
*/
|
|
105
|
+
reply(request: {
|
|
106
|
+
readonly instructions: string | undefined;
|
|
107
|
+
readonly inputText: string;
|
|
108
|
+
readonly hasToolResult: boolean;
|
|
109
|
+
}): Promise<ContextWindowReply>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Returns every request the scripted model saw, in order.
|
|
113
|
+
* @param stateDirectory - The test's state directory.
|
|
114
|
+
* @returns The logged requests.
|
|
115
|
+
*/
|
|
116
|
+
export declare function readContextWindowRequests(stateDirectory: string): ContextWindowRequest[];
|
|
117
|
+
/** Options of {@link ContextWindowSessionScenario}. */
|
|
118
|
+
export interface ContextWindowSessionScenarioOptions {
|
|
119
|
+
/** Dex Server address of the test's engine. */
|
|
120
|
+
readonly serverAddress: string;
|
|
121
|
+
/** Session client for the adapter's Flow. */
|
|
122
|
+
readonly sessions: AgentSessionTestClient;
|
|
123
|
+
/** Directory shared with the Worker child processes. */
|
|
124
|
+
readonly stateDirectory: string;
|
|
125
|
+
/** Sizes of the test. */
|
|
126
|
+
readonly settings: ContextWindowSettings;
|
|
127
|
+
/** Compiled module of the Worker child, which calls `runAgentWorkerProcess`. */
|
|
128
|
+
readonly workerEntryModulePath: string;
|
|
129
|
+
/** Environment that tells the Worker child where {@link stateDirectory} is. */
|
|
130
|
+
readonly workerEnvironment: Readonly<Record<string, string>>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Drives an adapter's session past a context window in Worker child processes, and checks what happened. Every
|
|
134
|
+
* adapter so proves one contract: the session keeps going, the model input shrinks, and the record stays readable.
|
|
135
|
+
*/
|
|
136
|
+
export declare class ContextWindowSessionScenario {
|
|
137
|
+
private readonly options;
|
|
138
|
+
/** The session ID of this scenario. */
|
|
139
|
+
readonly sessionId: string;
|
|
140
|
+
private readonly workers;
|
|
141
|
+
/** @param options - The engine, the session client, and the Worker child. */
|
|
142
|
+
constructor(options: ContextWindowSessionScenarioOptions);
|
|
143
|
+
/**
|
|
144
|
+
* Starts a Worker child with the scenario's settings, or with other settings.
|
|
145
|
+
* @param settings - Settings of this Worker. Defaults to the scenario's.
|
|
146
|
+
* @returns The Worker.
|
|
147
|
+
*/
|
|
148
|
+
startWorker(settings?: ContextWindowSettings): Promise<KillableWorkerProcess>;
|
|
149
|
+
/** Kills every Worker child the scenario started. */
|
|
150
|
+
close(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the logged requests of one kind.
|
|
153
|
+
* @param kind - `"model"` or `"summary"`.
|
|
154
|
+
* @returns The requests in order.
|
|
155
|
+
*/
|
|
156
|
+
requests(kind: ContextWindowRequest["kind"]): ContextWindowRequest[];
|
|
157
|
+
/**
|
|
158
|
+
* Sends one turn per tag and waits until the session finished them.
|
|
159
|
+
* @param tags - The turns' tags.
|
|
160
|
+
* @param isFirst - Whether the first tag starts the session.
|
|
161
|
+
* @returns The snapshot after the last turn.
|
|
162
|
+
*/
|
|
163
|
+
runTurns(tags: readonly string[], isFirst?: boolean): Promise<AgentSnapshot>;
|
|
164
|
+
/**
|
|
165
|
+
* Reads every message history still holds, through the public RPC.
|
|
166
|
+
* @returns The messages in sequence order.
|
|
167
|
+
*/
|
|
168
|
+
readStoredMessages(): Promise<AgentMessage[]>;
|
|
169
|
+
/**
|
|
170
|
+
* Counts the finished `CompactContext` Steps of the session.
|
|
171
|
+
* @returns The count.
|
|
172
|
+
*/
|
|
173
|
+
countCompactContextSteps(): Promise<number>;
|
|
174
|
+
/**
|
|
175
|
+
* Checks the whole contract on a session longer than the window.
|
|
176
|
+
* @param turnCount - Turns to run.
|
|
177
|
+
* @returns The final snapshot.
|
|
178
|
+
*/
|
|
179
|
+
assertOutlivesTheWindow(turnCount?: number): Promise<AgentSnapshot>;
|
|
180
|
+
/**
|
|
181
|
+
* Checks that retention deletes only chunks behind the summary. The settings need a small `retainedMessageLimit`.
|
|
182
|
+
* @param turnCount - Turns to run.
|
|
183
|
+
*/
|
|
184
|
+
assertRetentionFollowsTheSummary(turnCount?: number): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Checks that a session without a policy is unchanged and reaches the window.
|
|
187
|
+
* @param turnCount - Turns to run; the window must end the session first.
|
|
188
|
+
*/
|
|
189
|
+
assertFailsAtTheWindowWithoutAPolicy(turnCount?: number): Promise<void>;
|
|
190
|
+
/** Checks that a session started without a policy compacts once a Worker has one. */
|
|
191
|
+
assertStartsCompactingAfterAnUpgrade(): Promise<void>;
|
|
192
|
+
/** Checks SIGKILL during `CompactContext`: one more summary call, one stored summary, no repeated model call. */
|
|
193
|
+
assertWorkerKillRerunsOnlyTheSummary(): Promise<void>;
|
|
194
|
+
}
|