experimental-a2 0.6.0 → 0.8.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/CHANGELOG.md +41 -0
- package/dist/ai-server.d.ts +4 -5
- package/dist/ai-server.d.ts.map +1 -1
- package/dist/ai-server.js +20 -17
- package/dist/ai-server.js.map +1 -1
- package/dist/ai.d.ts +334 -2
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +1 -1
- package/dist/client.d.ts +202 -2
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1025 -1
- package/dist/client.js.map +1 -0
- package/dist/errors-BQuJpe82.js.map +1 -1
- package/dist/index.d.ts +22 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/{internal-DstsI6Re.js → internal-DRXJ56EI.js} +5 -28
- package/dist/internal-DRXJ56EI.js.map +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/scheduler-qstash.d.ts +3 -3
- package/dist/scheduler-qstash.js +4 -5
- package/dist/scheduler-qstash.js.map +1 -1
- package/dist/scheduler-vercel.d.ts +2 -2
- package/dist/scheduler-vercel.js +4 -4
- package/dist/scheduler-vercel.js.map +1 -1
- package/dist/{server-Duw6MVlB.js → server-B2XNevQA.js} +830 -131
- package/dist/server-B2XNevQA.js.map +1 -0
- package/dist/{server-DpvjhdoE.d.ts → server-DjPhHnbI.d.ts} +71 -50
- package/dist/server-DjPhHnbI.d.ts.map +1 -0
- package/dist/server.d.ts +3 -3
- package/dist/server.js +1 -1
- package/dist/store-N8PXxDAS.js.map +1 -1
- package/dist/{store-DysUkTH3.d.ts → store-RJO35BMj.d.ts} +24 -62
- package/dist/store-RJO35BMj.d.ts.map +1 -0
- package/dist/store-memory.d.ts +1 -1
- package/dist/store-memory.d.ts.map +1 -1
- package/dist/store-memory.js +80 -78
- package/dist/store-memory.js.map +1 -1
- package/dist/{store-polling-dSeLxzfb.js → store-polling-6DW7F1DT.js} +2 -2
- package/dist/{store-polling-dSeLxzfb.js.map → store-polling-6DW7F1DT.js.map} +1 -1
- package/dist/store-postgres.d.ts +1 -1
- package/dist/store-postgres.d.ts.map +1 -1
- package/dist/store-postgres.js +231 -182
- package/dist/store-postgres.js.map +1 -1
- package/dist/{store-redis-core-BFLwz0Wj.js → store-redis-core-DT01r4GZ.js} +213 -161
- package/dist/store-redis-core-DT01r4GZ.js.map +1 -0
- package/dist/store-redis-http.d.ts +1 -1
- package/dist/store-redis-http.js +3 -4
- package/dist/store-redis-http.js.map +1 -1
- package/dist/store-redis.d.ts +1 -1
- package/dist/store-redis.js +4 -5
- package/dist/store-redis.js.map +1 -1
- package/dist/store-sqlite.d.ts +1 -1
- package/dist/store-sqlite.d.ts.map +1 -1
- package/dist/store-sqlite.js +104 -91
- package/dist/store-sqlite.js.map +1 -1
- package/dist/{wire-BFQmSJ-9.js → wire-B6te_wns.js} +4 -3
- package/dist/wire-B6te_wns.js.map +1 -0
- package/docs/concepts/02-handlers.mdx +4 -0
- package/docs/concepts/04-state.mdx +57 -9
- package/docs/guides/03-react.mdx +20 -28
- package/docs/guides/05-production.mdx +9 -11
- package/docs/guides/06-ai-agents.mdx +10 -15
- package/docs/guides/09-presence.mdx +14 -19
- package/docs/guides/10-transports.mdx +104 -86
- package/docs/reference/01-api.mdx +182 -293
- package/docs/reference/02-errors.mdx +5 -7
- package/package.json +1 -14
- package/src/ai-server.ts +36 -15
- package/src/client.ts +2 -2
- package/src/errors.ts +1 -0
- package/src/internal.ts +3 -62
- package/src/push-envelope.ts +24 -21
- package/src/scheduler-qstash.ts +3 -3
- package/src/scheduler-vercel.ts +2 -2
- package/src/server-fetch.ts +344 -0
- package/src/server.ts +315 -312
- package/src/session-socket.ts +36 -20
- package/src/sse.ts +2 -2
- package/src/store-memory.ts +138 -101
- package/src/store-postgres.ts +355 -238
- package/src/store-redis-core.ts +247 -237
- package/src/store-redis-http.ts +1 -2
- package/src/store-redis.ts +1 -2
- package/src/store-sqlite.ts +191 -153
- package/src/store.ts +24 -66
- package/src/wire.ts +2 -1
- package/dist/ai-D_PGS-JR.d.ts +0 -334
- package/dist/ai-D_PGS-JR.d.ts.map +0 -1
- package/dist/cli-B3VuxoDe.js +0 -599
- package/dist/cli-B3VuxoDe.js.map +0 -1
- package/dist/cli-bin.d.ts +0 -1
- package/dist/cli-bin.js +0 -7
- package/dist/cli-bin.js.map +0 -1
- package/dist/cli.d.ts +0 -20
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -2
- package/dist/client-CdMqi7mC.d.ts +0 -202
- package/dist/client-CdMqi7mC.d.ts.map +0 -1
- package/dist/client-Dj5d3SP_.js +0 -1026
- package/dist/client-Dj5d3SP_.js.map +0 -1
- package/dist/devtools-J_jZ2vQf.d.ts +0 -152
- package/dist/devtools-J_jZ2vQf.d.ts.map +0 -1
- package/dist/devtools-kJJaORn-.js +0 -340
- package/dist/devtools-kJJaORn-.js.map +0 -1
- package/dist/devtools-server.browser.d.ts +0 -1
- package/dist/devtools-server.browser.js +0 -6
- package/dist/devtools-server.browser.js.map +0 -1
- package/dist/devtools-server.d.ts +0 -23
- package/dist/devtools-server.d.ts.map +0 -1
- package/dist/devtools-server.js +0 -1270
- package/dist/devtools-server.js.map +0 -1
- package/dist/devtools.d.ts +0 -2
- package/dist/devtools.js +0 -2
- package/dist/errors-W6nwJ-fm.d.ts +0 -21
- package/dist/errors-W6nwJ-fm.d.ts.map +0 -1
- package/dist/http.d.ts +0 -151
- package/dist/http.d.ts.map +0 -1
- package/dist/http.js +0 -706
- package/dist/http.js.map +0 -1
- package/dist/inspection-DaxB5jM2.js +0 -13
- package/dist/inspection-DaxB5jM2.js.map +0 -1
- package/dist/internal-DstsI6Re.js.map +0 -1
- package/dist/platform-B4TnJtWu.js +0 -34
- package/dist/platform-B4TnJtWu.js.map +0 -1
- package/dist/server-DpvjhdoE.d.ts.map +0 -1
- package/dist/server-Duw6MVlB.js.map +0 -1
- package/dist/store-DysUkTH3.d.ts.map +0 -1
- package/dist/store-redis-core-BFLwz0Wj.js.map +0 -1
- package/dist/testing.browser.d.ts +0 -1
- package/dist/testing.browser.js +0 -6
- package/dist/testing.browser.js.map +0 -1
- package/dist/testing.d.ts +0 -32
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -103
- package/dist/testing.js.map +0 -1
- package/dist/wire-BFQmSJ-9.js.map +0 -1
- package/docs/guides/07-devtools.mdx +0 -229
- package/src/cli-bin.ts +0 -5
- package/src/cli.ts +0 -1046
- package/src/devtools-app.ts +0 -989
- package/src/devtools-server.browser.ts +0 -5
- package/src/devtools-server.ts +0 -604
- package/src/devtools.ts +0 -716
- package/src/http.ts +0 -394
- package/src/inspection.ts +0 -39
- package/src/testing.browser.ts +0 -5
- package/src/testing.ts +0 -185
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d8f2793: Make handler state reads event-relative. `ctx.session.state(reducer)` now folds
|
|
8
|
+
through the triggering event, so concurrent appends do not change what retries
|
|
9
|
+
observe. Pass `{ through: 'latest' }` for an intentional live read, or a numeric
|
|
10
|
+
`through` for an inclusive boundary.
|
|
11
|
+
|
|
12
|
+
A2 now keeps one reducer snapshot head plus only the historical checkpoints
|
|
13
|
+
currently referenced by unfinished handler events. Completion and
|
|
14
|
+
dead-lettering release those references and collect orphan history atomically.
|
|
15
|
+
Root reads and handler latest reads do not retain historical checkpoints. There
|
|
16
|
+
are no retention knobs.
|
|
17
|
+
|
|
18
|
+
AI handlers now recheck cancellation immediately before invoking a tool or
|
|
19
|
+
model, so work canceled during asynchronous prompt or instruction resolution
|
|
20
|
+
does not cross an external execution boundary.
|
|
21
|
+
|
|
22
|
+
## 0.7.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- eaf38cd: Replace the `experimental-a2/http` adapter and `handle(server, options)` with a
|
|
27
|
+
bound `server.fetch(request, options?)` method. Unprotected framework routes can
|
|
28
|
+
now export `server.fetch` directly, while protected routes pass a request-scoped
|
|
29
|
+
`authorize` callback over typed stream, history, and push operations.
|
|
30
|
+
|
|
31
|
+
WebSocket upgrades are supplied through the per-request `upgradeWebSocket`
|
|
32
|
+
capability. Each socket subscription and push is authorized independently;
|
|
33
|
+
physical upgrade authentication remains the application's responsibility.
|
|
34
|
+
Invocation deadlines and `waitUntil` remain ambient platform capabilities.
|
|
35
|
+
|
|
36
|
+
Remove the `experimental-a2/http` entry point, its before/after hooks, public
|
|
37
|
+
transport helpers, and legacy push validation surface. Scheduler callbacks now
|
|
38
|
+
use the configured scheduler's `handler(...servers)` method directly.
|
|
39
|
+
|
|
40
|
+
Remove the Devtools dashboard, protocol, capture format, CLI, testing helpers,
|
|
41
|
+
and store inspection capability. Redis no longer maintains the global session
|
|
42
|
+
index that existed only for Devtools discovery.
|
|
43
|
+
|
|
3
44
|
## 0.6.0
|
|
4
45
|
|
|
5
46
|
### Minor Changes
|
package/dist/ai-server.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as EventDefs, r as ContractEvent } from "./contract-jIfaR085.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { n as A2Server, p as ServerOptions } from "./server-DjPhHnbI.js";
|
|
3
|
+
import { AIEventDefs, AIState, AgentDefinition, AgentToolContext, AgentToolEventDefs } from "./ai.js";
|
|
4
4
|
import { Instructions, LanguageModel, TextStreamPart, ToolSet, ToolSet as ToolSet$1, UIMessage, UIMessageChunk, streamText } from "ai";
|
|
5
5
|
//#region src/ai-sdk-step.d.ts
|
|
6
6
|
type StreamTextOptions<T extends ToolSet$1> = Parameters<typeof streamText<T>>[0];
|
|
@@ -38,7 +38,6 @@ type AISDKStepSettings<T extends ToolSet$1> = Partial<Omit<StreamTextOptions<T>,
|
|
|
38
38
|
};
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/ai-server.d.ts
|
|
41
|
-
declare function validateAgentPush(context: PushValidationContext): void;
|
|
42
41
|
type AgentGenerateContext<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet> = {
|
|
43
42
|
request: ContractEvent<D, "ai.generation.requested">;
|
|
44
43
|
requestId: string;
|
|
@@ -100,7 +99,7 @@ type CreateHandlersOptions<M extends UIMessage, D extends AIEventDefs<M> & Event
|
|
|
100
99
|
maxDelayMs?: number;
|
|
101
100
|
};
|
|
102
101
|
};
|
|
103
|
-
type CreateAgentServerOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet> = CreateHandlersOptions<M, D, T> & Omit<ServerOptions<D>, "contract" | "handlers"
|
|
102
|
+
type CreateAgentServerOptions<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet> = CreateHandlersOptions<M, D, T> & Omit<ServerOptions<D>, "contract" | "handlers"> & {
|
|
104
103
|
handlers?: ServerOptions<D>["handlers"];
|
|
105
104
|
};
|
|
106
105
|
/** Run `fn` with `ctx` as the ambient tool handler context, for direct tool tests. */
|
|
@@ -113,5 +112,5 @@ declare function createHandlers<M extends UIMessage, D extends AIEventDefs<M> &
|
|
|
113
112
|
/** Assemble an A2 server with the built-in agent handlers and app extensions. */
|
|
114
113
|
declare function createAgentServer<M extends UIMessage, D extends AIEventDefs<M> & EventDefs, T extends ToolSet = ToolSet>(options: CreateAgentServerOptions<M, D, T>): A2Server<D>;
|
|
115
114
|
//#endregion
|
|
116
|
-
export { AgentGenerate, AgentGenerateContext, AgentGenerationSettings, AgentMessageMetadata, AgentResolverContext, CompactionPolicy, CreateAgentServerOptions, CreateHandlersOptions, type Instructions, type LanguageModel, Resolvable, type ToolSet, createAgentServer, createHandlers, runWithHandlerContext
|
|
115
|
+
export { AgentGenerate, AgentGenerateContext, AgentGenerationSettings, AgentMessageMetadata, AgentResolverContext, CompactionPolicy, CreateAgentServerOptions, CreateHandlersOptions, type Instructions, type LanguageModel, Resolvable, type ToolSet, createAgentServer, createHandlers, runWithHandlerContext };
|
|
117
116
|
//# sourceMappingURL=ai-server.d.ts.map
|
package/dist/ai-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-server.d.ts","names":[],"sources":["../src/ai-sdk-step.ts","../src/ai-server.ts"],"mappings":";;;;;KAiBK,kBAAkB,UAAU,aAAW,kBAAkB,WAAW;KAKpE,iBAAiB,UAAU,sBAE5B,KACE,QAAQ,kBAAkB;KAI3B;KAmBA;KASA,iBAAiB,UAAU,yBACpB,WAAW,IAAI,KAAK,EAAE;KAG7B,aAAa,UAAU,WAAS,gBAAgB,kBAAkB,MACrE,YAAY,kBAAkB,GAAG,cAAa,aAAa,qBACvD;KAGD,qBAAqB,UAAU,aAAW,KAC7C,aAAa;WAGJ,OAAO,iBAAiB;;KAG9B,yBAAyB,UAAU,aAAW,KACjD,aAAa;WAGJ,OAAO,iBAAiB;;KAG9B,mBAAmB,UAAU,OAAO,iBAAiB;KAErD,yBAAyB,UAAU,aAAW,YACjD,kBAAkB;KAGf,yBAAyB,UAAU,cACtC,SAAS,KAAK,WAAW,yBAAyB;EAChD,OAAO,iBAAiB;MAEvB,WAAW,yBAAyB;KAEpC,2BAA2B,UAAU,aAAW,YACnD,kBAAkB;KAGf,oBAAoB,UAAU,aAAW,QAC5C,2BAA2B,QACvB;KAGD,oBAAoB,UAAU,cACjC,SAAS,KAAK,WAAW,oBAAoB;EAC3C,OAAO,iBAAiB;MAEvB,WAAW,oBAAoB;;KAGxB,kBAAkB,UAAU,aAAW,QACjD,KACE,kBAAkB,IAClB,8BAA8B;EAGhC,UAAU,iBAAiB;EAC3B,UAAU,mBAAmB,qBAAqB;EAClD,uBAAuB,mBAAmB,qBAAqB;EAC/D,cAAc,mBAAmB,yBAAyB;EAC1D,2BAA2B,mBAAmB,yBAAyB;EACvE,iBAAiB,yBAAyB;EAC1C,8BAA8B,yBAAyB;EACvD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,cAAc;;;iBA2Bb,sBAAsB,UAAU,oBAAoB,GAClE,KAAK,iBAAiB,IACtB,UAAU,IACT;;;;;iBA2hBa,eACd,UAAU,WACV,UAAU,YAAY,KAAK,WAC3B,UAAU,UAAU,SAEpB,SAAS,sBAAsB,GAAG,GAAG,KACpC,YAAY,cAAc;;iBAm5Bb,kBACd,UAAU,WACV,UAAU,YAAY,KAAK,WAC3B,UAAU,UAAU,SACpB,SAAS,yBAAyB,GAAG,GAAG,KAAK,SAAS"}
|
package/dist/ai-server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as A2Error } from "./errors-BQuJpe82.js";
|
|
2
|
-
import {
|
|
3
|
-
import { t as createServer } from "./server-
|
|
2
|
+
import { f as consumeSchedulerSendFailure, p as installAmbientToolScopeStorage } from "./internal-DRXJ56EI.js";
|
|
3
|
+
import { r as setServerFetchHooks, t as createServer } from "./server-B2XNevQA.js";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
import { convertToModelMessages, stepCountIs, streamText, toUIMessageStream } from "ai";
|
|
6
6
|
//#region src/ai-sdk-step.ts
|
|
@@ -278,7 +278,7 @@ const continuationReady = (state) => {
|
|
|
278
278
|
* `createHandlers()` exposes the ordinary A2 handler table;
|
|
279
279
|
* `createAgentServer()` is its batteries-included assembly with createServer.
|
|
280
280
|
*/
|
|
281
|
-
function
|
|
281
|
+
function validateAgentIngress(context) {
|
|
282
282
|
const rejected = context.events.find((event) => {
|
|
283
283
|
if (event.type !== "ai.message.created") return !(event.type === "ai.approval.responded" || event.type === "ai.input.responded" || event.type === "ai.message.interrupted" || event.type === "ai.retry.requested");
|
|
284
284
|
const payload = event.payload;
|
|
@@ -674,9 +674,9 @@ function createHandlers(options) {
|
|
|
674
674
|
}
|
|
675
675
|
};
|
|
676
676
|
};
|
|
677
|
-
const scheduleNext = async (ctx) => requestForNextMessage((await ctx.session.state(coordinator)).state);
|
|
677
|
+
const scheduleNext = async (ctx) => requestForNextMessage((await ctx.session.state(coordinator, { through: "latest" })).state);
|
|
678
678
|
const continueIfReady = async (ctx, generationId) => {
|
|
679
|
-
const state = (await ctx.session.state(coordinator)).state;
|
|
679
|
+
const state = (await ctx.session.state(coordinator, { through: "latest" })).state;
|
|
680
680
|
const response = state.response;
|
|
681
681
|
if (response?.generation?.generationId !== generationId) return;
|
|
682
682
|
const input = response.inputResponse;
|
|
@@ -805,6 +805,7 @@ function createHandlers(options) {
|
|
|
805
805
|
const execute = tools[call.toolName]?.execute;
|
|
806
806
|
if (execute === void 0) return resultEvent(call, "execution:error", { error: `Tool '${call.toolName}' has no server executor` });
|
|
807
807
|
const messages = await promptMessages(ctx.event.sessionId, call, ctx.session.history);
|
|
808
|
+
if (ctx.signal.aborted) return;
|
|
808
809
|
const scope = {
|
|
809
810
|
contract: options.agent.contract,
|
|
810
811
|
context: ctx
|
|
@@ -812,7 +813,7 @@ function createHandlers(options) {
|
|
|
812
813
|
return toolScopeStorage.run(scope, () => runToolExecution(ctx, call, execute, messages));
|
|
813
814
|
};
|
|
814
815
|
const handleToolCall = async (ctx) => {
|
|
815
|
-
const response = (await ctx.session.state(coordinator)).state.response;
|
|
816
|
+
const response = (await ctx.session.state(coordinator, { through: "latest" })).state.response;
|
|
816
817
|
const current = response?.calls.find((candidate) => candidate.index === ctx.event.index);
|
|
817
818
|
if (current === void 0 || response?.generation?.generationId !== ctx.event.payload.generationId || response.failure !== void 0 || current.terminal || current.approval !== void 0) return;
|
|
818
819
|
if (current.call.providerExecuted === true) {
|
|
@@ -822,7 +823,7 @@ function createHandlers(options) {
|
|
|
822
823
|
return executeTool(ctx, current.call);
|
|
823
824
|
};
|
|
824
825
|
const handleApproval = async (ctx) => {
|
|
825
|
-
const response = (await ctx.session.state(coordinator)).state.response;
|
|
826
|
+
const response = (await ctx.session.state(coordinator, { through: "latest" })).state.response;
|
|
826
827
|
const current = response?.calls.find((candidate) => candidate.approval?.approvalId === ctx.event.payload.approvalId && candidate.approval.messageId === ctx.event.payload.messageId && candidate.approval.generationId === ctx.event.payload.generationId && candidate.responseIndex === ctx.event.index);
|
|
827
828
|
if (current === void 0 || response?.generation?.generationId !== current.call.generationId || response.failure !== void 0 || current.terminal) return;
|
|
828
829
|
if (current.call.providerExecuted === true) {
|
|
@@ -836,7 +837,7 @@ function createHandlers(options) {
|
|
|
836
837
|
const history = await ctx.session.history();
|
|
837
838
|
const requestId = ctx.event.id;
|
|
838
839
|
const request = ctx.event.payload;
|
|
839
|
-
const coordinatorState = (await ctx.session.state(coordinator)).state;
|
|
840
|
+
const coordinatorState = (await ctx.session.state(coordinator, { through: "latest" })).state;
|
|
840
841
|
if (coordinatorState.closed || coordinatorState.response?.activeRequestId !== requestId) return;
|
|
841
842
|
if (history.some((event) => {
|
|
842
843
|
if (event.type === "ai.generation.completed") return event.payload.requestId === requestId;
|
|
@@ -919,7 +920,7 @@ function createHandlers(options) {
|
|
|
919
920
|
payload: started
|
|
920
921
|
});
|
|
921
922
|
await ctx.session.append("generation-start", ...startEvents);
|
|
922
|
-
const startedCoordinatorState = (await ctx.session.state(coordinator)).state;
|
|
923
|
+
const startedCoordinatorState = (await ctx.session.state(coordinator, { through: "latest" })).state;
|
|
923
924
|
if (startedCoordinatorState.response?.activeRequestId !== requestId || startedCoordinatorState.response.generation?.generationId !== generationId) return;
|
|
924
925
|
const promptCoordinatorState = {
|
|
925
926
|
...coordinatorStateAt(history),
|
|
@@ -962,13 +963,14 @@ function createHandlers(options) {
|
|
|
962
963
|
};
|
|
963
964
|
}
|
|
964
965
|
}
|
|
965
|
-
const currentState = (await ctx.session.state(options.agent.reducer)).state;
|
|
966
|
-
const currentCoordinatorState = (await ctx.session.state(coordinator)).state;
|
|
966
|
+
const currentState = (await ctx.session.state(options.agent.reducer, { through: "latest" })).state;
|
|
967
|
+
const currentCoordinatorState = (await ctx.session.state(coordinator, { through: "latest" })).state;
|
|
967
968
|
const generationMessages = activeContextMessages(currentState, currentCoordinatorState);
|
|
968
969
|
promptCache.set(promptCacheKey(ctx.event.sessionId, generationId), convertToModelMessages(generationMessages, { tools }));
|
|
969
970
|
let pendingToolCalls = [];
|
|
970
971
|
try {
|
|
971
972
|
const resolvedInstructions = options.instructions === void 0 ? void 0 : await resolve(options.instructions, resolverContext);
|
|
973
|
+
if (ctx.signal.aborted) return;
|
|
972
974
|
const generateContext = {
|
|
973
975
|
request: ctx.event,
|
|
974
976
|
requestId,
|
|
@@ -1083,7 +1085,7 @@ function createHandlers(options) {
|
|
|
1083
1085
|
return scheduleNext(ctx);
|
|
1084
1086
|
};
|
|
1085
1087
|
const handleRetry = async (ctx) => {
|
|
1086
|
-
const response = (await ctx.session.state(coordinator)).state.response;
|
|
1088
|
+
const response = (await ctx.session.state(coordinator, { through: "latest" })).state.response;
|
|
1087
1089
|
if (response?.status !== "failed" || response.rootMessageId !== ctx.event.payload.messageId || response.responseMessageId !== ctx.event.payload.responseMessageId) return;
|
|
1088
1090
|
return {
|
|
1089
1091
|
type: "ai.generation.requested",
|
|
@@ -1096,7 +1098,7 @@ function createHandlers(options) {
|
|
|
1096
1098
|
};
|
|
1097
1099
|
};
|
|
1098
1100
|
const handleInputResponse = async (ctx) => {
|
|
1099
|
-
const response = (await ctx.session.state(coordinator)).state.response;
|
|
1101
|
+
const response = (await ctx.session.state(coordinator, { through: "latest" })).state.response;
|
|
1100
1102
|
if (response?.responseMessageId !== ctx.event.payload.messageId || response.inputResponse?.index !== ctx.event.index || response.inputResponse.generationId !== ctx.event.payload.generationId || response.inputResponse.inputId !== ctx.event.payload.inputId) return;
|
|
1101
1103
|
await continueIfReady(ctx, ctx.event.payload.generationId);
|
|
1102
1104
|
};
|
|
@@ -1186,17 +1188,18 @@ function createAgentServer(options) {
|
|
|
1186
1188
|
...compaction === void 0 ? {} : { compaction },
|
|
1187
1189
|
...progress === void 0 ? {} : { progress }
|
|
1188
1190
|
});
|
|
1189
|
-
|
|
1191
|
+
const server = createServer({
|
|
1190
1192
|
...serverOptions,
|
|
1191
1193
|
contract: definition.contract,
|
|
1192
1194
|
handlers: {
|
|
1193
1195
|
...builtIns,
|
|
1194
1196
|
...handlers
|
|
1195
|
-
}
|
|
1196
|
-
validatePush: validateAgentPush
|
|
1197
|
+
}
|
|
1197
1198
|
});
|
|
1199
|
+
setServerFetchHooks(server, { validateIngress: validateAgentIngress });
|
|
1200
|
+
return server;
|
|
1198
1201
|
}
|
|
1199
1202
|
//#endregion
|
|
1200
|
-
export { createAgentServer, createHandlers, runWithHandlerContext
|
|
1203
|
+
export { createAgentServer, createHandlers, runWithHandlerContext };
|
|
1201
1204
|
|
|
1202
1205
|
//# sourceMappingURL=ai-server.js.map
|