experimental-a2 0.19.0 → 0.21.1
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 +50 -0
- package/README.md +1 -1
- package/dist/{actor-C7b-1arn.d.ts → actor-HnGmrOZZ.d.ts} +5 -5
- package/dist/{actor-C7b-1arn.d.ts.map → actor-HnGmrOZZ.d.ts.map} +1 -1
- package/dist/actor-client.d.ts +1 -1
- package/dist/actor-client.js +2 -2
- package/dist/actor-react.d.ts +3 -3
- package/dist/actor-react.js +5 -5
- package/dist/{actor-shared-t7w8xIKP.js → actor-shared-DFET5q16.js} +3 -3
- package/dist/{actor-shared-t7w8xIKP.js.map → actor-shared-DFET5q16.js.map} +1 -1
- package/dist/actor.d.ts +1 -1
- package/dist/actor.js +54 -43
- package/dist/actor.js.map +1 -1
- package/dist/{ai-Cz3hqVhk.d.ts → ai-CvEnqVfo.d.ts} +8 -8
- package/dist/{ai-Cz3hqVhk.d.ts.map → ai-CvEnqVfo.d.ts.map} +1 -1
- package/dist/{ai-mMiWul1T.js → ai-CzE672Q3.js} +9 -9
- package/dist/ai-CzE672Q3.js.map +1 -0
- package/dist/ai-client.d.ts +2 -2
- package/dist/ai-client.js +2 -2
- package/dist/ai-fx.d.ts +1 -1
- package/dist/ai-fx.d.ts.map +1 -1
- package/dist/ai-fx.js +36 -9
- package/dist/ai-fx.js.map +1 -1
- package/dist/{ai-harness-CV6rXbB3.d.ts → ai-harness-Bfk-Lycn.d.ts} +2 -2
- package/dist/ai-harness-Bfk-Lycn.d.ts.map +1 -0
- package/dist/{ai-harness-BuuC-gJ3.js → ai-harness-dQeJaR1t.js} +17 -4
- package/dist/ai-harness-dQeJaR1t.js.map +1 -0
- package/dist/ai-pi.d.ts +1 -1
- package/dist/ai-pi.js +4 -4
- package/dist/ai-pi.js.map +1 -1
- package/dist/ai-react.d.ts +5 -5
- package/dist/ai-react.js +2 -2
- package/dist/ai-server.d.ts +14 -17
- package/dist/ai-server.d.ts.map +1 -1
- package/dist/ai-server.js +84 -75
- package/dist/ai-server.js.map +1 -1
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +2 -2
- package/dist/{client-BhHLoNKF.js → client-9IeTsiAs.js} +5 -5
- package/dist/{client-BhHLoNKF.js.map → client-9IeTsiAs.js.map} +1 -1
- package/dist/{client-h_DKFAjj.d.ts → client-CUMbS_38.d.ts} +3 -3
- package/dist/{client-h_DKFAjj.d.ts.map → client-CUMbS_38.d.ts.map} +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/{contract-BYKASlCV.js → contract-CWukt01d.js} +2 -2
- package/dist/contract-CWukt01d.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/{initial-snapshot-Bx-c0pDP.d.ts → initial-snapshot-D3Lve43o.d.ts} +4 -4
- package/dist/initial-snapshot-D3Lve43o.d.ts.map +1 -0
- package/dist/{internal-CscSY7K_.js → internal-Bc4PvfHk.js} +10 -3
- package/dist/internal-Bc4PvfHk.js.map +1 -0
- package/dist/otel.d.ts +1 -1
- package/dist/otel.js +1 -1
- package/dist/otel.js.map +1 -1
- package/dist/{react-BBXgHWFc.d.ts → react-BoHvC3v9.d.ts} +4 -4
- package/dist/{react-BBXgHWFc.d.ts.map → react-BoHvC3v9.d.ts.map} +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/{reducer-CqA59Q6U.d.ts → reducer-CYPHsSmd.d.ts} +2 -2
- package/dist/{reducer-CqA59Q6U.d.ts.map → reducer-CYPHsSmd.d.ts.map} +1 -1
- package/dist/{reducer-BAXc8JyF.js → reducer-CjmvZSAb.js} +2 -2
- package/dist/{reducer-BAXc8JyF.js.map → reducer-CjmvZSAb.js.map} +1 -1
- package/dist/runtime-consumer-BWmht60z.js +12 -0
- package/dist/runtime-consumer-BWmht60z.js.map +1 -0
- package/dist/scheduler-qstash.d.ts +2 -2
- package/dist/scheduler-qstash.d.ts.map +1 -1
- package/dist/scheduler-qstash.js +7 -7
- package/dist/scheduler-qstash.js.map +1 -1
- package/dist/scheduler-task-X1SToDjP.js.map +1 -1
- package/dist/scheduler-vercel.d.ts +2 -2
- package/dist/scheduler-vercel.d.ts.map +1 -1
- package/dist/scheduler-vercel.js +5 -4
- package/dist/scheduler-vercel.js.map +1 -1
- package/dist/{server-DYAATFuT.d.ts → server-BshFZ0eL.d.ts} +108 -41
- package/dist/server-BshFZ0eL.d.ts.map +1 -0
- package/dist/{server-D-Y4pqwu.js → server-DvIB8kj5.js} +423 -135
- package/dist/server-DvIB8kj5.js.map +1 -0
- package/dist/server.browser.js +1 -1
- package/dist/server.browser.js.map +1 -1
- package/dist/server.d.ts +4 -4
- package/dist/server.js +2 -2
- package/dist/{session-clear-C-QwTXV1.d.ts → session-clear-Bk_29eEw.d.ts} +2 -2
- package/dist/session-clear-Bk_29eEw.d.ts.map +1 -0
- package/dist/{session-clear-DGI4jTQ5.js → session-clear-wHd5GCpZ.js} +5 -4
- package/dist/session-clear-wHd5GCpZ.js.map +1 -0
- package/dist/store-N8PXxDAS.js.map +1 -1
- package/dist/store-Z2qjw50n.d.ts +523 -0
- package/dist/store-Z2qjw50n.d.ts.map +1 -0
- package/dist/store-codec-DwrWlgQx.js +65 -0
- package/dist/store-codec-DwrWlgQx.js.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 +393 -210
- package/dist/store-memory.js.map +1 -1
- package/dist/{store-polling-7WJV0YWP.js → store-polling-DYNyxCev.js} +2 -2
- package/dist/{store-polling-7WJV0YWP.js.map → store-polling-DYNyxCev.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 +1595 -673
- package/dist/store-postgres.js.map +1 -1
- package/dist/{store-presence-polling-B1ixeqIS.js → store-presence-polling-CzQ0wdtM.js} +3 -3
- package/dist/{store-presence-polling-B1ixeqIS.js.map → store-presence-polling-CzQ0wdtM.js.map} +1 -1
- package/dist/store-redis-http.d.ts +1 -1
- package/dist/store-redis-http.js +4 -4
- package/dist/store-redis-notify-IiVdlYHc.js +2919 -0
- package/dist/store-redis-notify-IiVdlYHc.js.map +1 -0
- package/dist/store-redis.d.ts +1 -1
- package/dist/store-redis.js +2 -2
- package/dist/store-sqlite.d.ts +1 -1
- package/dist/store-sqlite.d.ts.map +1 -1
- package/dist/store-sqlite.js +517 -287
- package/dist/store-sqlite.js.map +1 -1
- package/dist/{telemetry-Cyfqo6Qt.d.ts → telemetry-CWwsh-Gx.d.ts} +3 -3
- package/dist/telemetry-CWwsh-Gx.d.ts.map +1 -0
- package/dist/{wire-BKxH1vbP.js → wire-CZGqNZRx.js} +5 -4
- package/dist/wire-CZGqNZRx.js.map +1 -0
- package/docs/01-quickstart.mdx +28 -19
- package/docs/02-examples.mdx +1 -1
- package/docs/actors/01-introduction.mdx +9 -1
- package/docs/actors/02-concurrency.mdx +1 -1
- package/docs/actors/meta.ts +1 -1
- package/docs/agents/01-introduction.mdx +1 -1
- package/docs/agents/02-tools.mdx +13 -12
- package/docs/agents/03-conversations.mdx +31 -21
- package/docs/agents/04-harnesses.mdx +7 -3
- package/docs/agents/meta.ts +1 -1
- package/docs/client/03-presence.mdx +18 -14
- package/docs/client/meta.ts +1 -1
- package/docs/contract/01-events.mdx +2 -2
- package/docs/contract/02-state.mdx +18 -14
- package/docs/contract/03-sessions.mdx +32 -25
- package/docs/index.mdx +31 -26
- package/docs/reference/01-core.mdx +12 -12
- package/docs/reference/02-server.mdx +247 -192
- package/docs/reference/04-ai.mdx +29 -20
- package/docs/reference/05-telemetry.mdx +146 -0
- package/docs/reference/06-errors.mdx +24 -18
- package/docs/reference/meta.ts +1 -1
- package/docs/schedulers/01-overview.mdx +112 -0
- package/docs/schedulers/02-vercel-queues.mdx +87 -0
- package/docs/schedulers/03-qstash.mdx +123 -0
- package/docs/schedulers/meta.ts +1 -0
- package/docs/server/01-consumers.mdx +415 -0
- package/docs/server/02-timers.mdx +33 -23
- package/docs/server/03-cancellation.mdx +52 -44
- package/docs/server/04-routes.mdx +4 -1
- package/docs/server/05-sql-projections.mdx +391 -0
- package/docs/server/06-guarantees.mdx +60 -50
- package/docs/stores/01-overview.mdx +37 -0
- package/docs/stores/02-redis.mdx +57 -0
- package/docs/stores/03-redis-http.mdx +56 -0
- package/docs/stores/04-postgres.mdx +172 -0
- package/docs/stores/05-sqlite.mdx +36 -0
- package/docs/stores/06-memory.mdx +22 -0
- package/docs/stores/meta.ts +1 -0
- package/docs/upgrades/01-overview.mdx +30 -0
- package/docs/upgrades/79-0-21.mdx +165 -0
- package/docs/upgrades/80-0-20.mdx +43 -0
- package/docs/upgrades/81-0-19.mdx +33 -0
- package/docs/upgrades/82-0-18.mdx +33 -0
- package/docs/upgrades/83-0-17.mdx +69 -0
- package/docs/upgrades/meta.ts +3 -0
- package/examples/playground/DEPLOY.md +48 -11
- package/examples/playground/app/a0/apps/[appId]/route.ts +6 -10
- package/examples/playground/app/a0/chat.test.tsx +421 -330
- package/examples/playground/app/a0/sandbox-log.ts +17 -15
- package/examples/playground/app/a0/server.ts +4 -4
- package/examples/playground/app/a0/shell.tsx +1 -1
- package/examples/playground/app/a0/uploads/route.test.ts +59 -0
- package/examples/playground/app/a2slack/a2slack.css +1067 -0
- package/examples/playground/app/a2slack/c/[channel]/page.tsx +20 -0
- package/examples/playground/app/a2slack/consumers/agent.ts +63 -0
- package/examples/playground/app/a2slack/consumers/feed.ts +164 -0
- package/examples/playground/app/a2slack/consumers/notify.ts +116 -0
- package/examples/playground/app/a2slack/consumers/search.ts +37 -0
- package/examples/playground/app/a2slack/consumers/triage.ts +31 -0
- package/examples/playground/app/a2slack/consumers/welcome.ts +25 -0
- package/examples/playground/app/a2slack/db/a2.ts +206 -0
- package/examples/playground/app/a2slack/db/index.ts +73 -0
- package/examples/playground/app/a2slack/db/migrations/0000_extensions.sql +4 -0
- package/examples/playground/app/a2slack/db/migrations/0001_workspace.sql +74 -0
- package/examples/playground/app/a2slack/db/migrations/0002_a2.sql +215 -0
- package/examples/playground/app/a2slack/db/migrations/0003_a2_batch.sql +67 -0
- package/examples/playground/app/a2slack/db/migrations/meta/0000_snapshot.json +18 -0
- package/examples/playground/app/a2slack/db/migrations/meta/0001_snapshot.json +500 -0
- package/examples/playground/app/a2slack/db/migrations/meta/0002_snapshot.json +1159 -0
- package/examples/playground/app/a2slack/db/migrations/meta/0003_snapshot.json +1159 -0
- package/examples/playground/app/a2slack/db/migrations/meta/_journal.json +34 -0
- package/examples/playground/app/a2slack/db/queries.ts +263 -0
- package/examples/playground/app/a2slack/db/schema.ts +145 -0
- package/examples/playground/app/a2slack/drills/a2slack.drill.ts +708 -0
- package/examples/playground/app/a2slack/drills/harness.ts +244 -0
- package/examples/playground/app/a2slack/events/route.ts +36 -0
- package/examples/playground/app/a2slack/identity.ts +44 -0
- package/examples/playground/app/a2slack/inbox/route.ts +8 -0
- package/examples/playground/app/a2slack/lag/data/route.ts +8 -0
- package/examples/playground/app/a2slack/lag/page.tsx +101 -0
- package/examples/playground/app/a2slack/lag.ts +73 -0
- package/examples/playground/app/a2slack/layout.tsx +43 -0
- package/examples/playground/app/a2slack/messages/route.ts +17 -0
- package/examples/playground/app/a2slack/model.test.ts +208 -0
- package/examples/playground/app/a2slack/model.ts +369 -0
- package/examples/playground/app/a2slack/models.test.ts +72 -0
- package/examples/playground/app/a2slack/page.tsx +10 -0
- package/examples/playground/app/a2slack/scheduler/route.ts +5 -0
- package/examples/playground/app/a2slack/search/route.ts +40 -0
- package/examples/playground/app/a2slack/search-index.ts +108 -0
- package/examples/playground/app/a2slack/server.test.ts +315 -0
- package/examples/playground/app/a2slack/server.ts +55 -0
- package/examples/playground/app/a2slack/sessions.ts +50 -0
- package/examples/playground/app/a2slack/thread/route.ts +8 -0
- package/examples/playground/app/a2slack/ui/ChannelView.tsx +87 -0
- package/examples/playground/app/a2slack/ui/Composer.tsx +117 -0
- package/examples/playground/app/a2slack/ui/DotsShadow.tsx +42 -0
- package/examples/playground/app/a2slack/ui/Feed.tsx +157 -0
- package/examples/playground/app/a2slack/ui/InboxContext.tsx +63 -0
- package/examples/playground/app/a2slack/ui/InboxView.tsx +82 -0
- package/examples/playground/app/a2slack/ui/Menu.tsx +128 -0
- package/examples/playground/app/a2slack/ui/MessageRow.tsx +314 -0
- package/examples/playground/app/a2slack/ui/NameGate.tsx +35 -0
- package/examples/playground/app/a2slack/ui/SearchContext.tsx +146 -0
- package/examples/playground/app/a2slack/ui/SearchResults.tsx +97 -0
- package/examples/playground/app/a2slack/ui/Shell.tsx +34 -0
- package/examples/playground/app/a2slack/ui/Sidebar.tsx +199 -0
- package/examples/playground/app/a2slack/ui/ThreadPanel.tsx +134 -0
- package/examples/playground/app/a2slack/ui/useInbox.ts +71 -0
- package/examples/playground/app/agent/[agentId]/agent-queue.test.tsx +116 -90
- package/examples/playground/app/agent/[agentId]/compaction-panel.test.tsx +107 -76
- package/examples/playground/app/agent/ingress.test.ts +41 -17
- package/examples/playground/app/agent/model-input.test.tsx +92 -43
- package/examples/playground/app/agent/server.ts +3 -3
- package/examples/playground/app/chat/[chatId]/agent-stream-drawer.test.tsx +2 -2
- package/examples/playground/app/chat/[chatId]/chat-client.tsx +1 -1
- package/examples/playground/app/chat/server.test.ts +38 -65
- package/examples/playground/app/chat/server.ts +45 -35
- package/examples/playground/app/components/activity-history.test.tsx +60 -18
- package/examples/playground/app/components/demo-icons.tsx +7 -0
- package/examples/playground/app/components/demos.tsx +7 -0
- package/examples/playground/app/components/fast-link.test.tsx +3 -5
- package/examples/playground/app/initial-state.test.tsx +86 -45
- package/examples/playground/app/orders/[orderId]/order-client.tsx +2 -2
- package/examples/playground/app/orders/page.tsx +1 -1
- package/examples/playground/app/orders/server.ts +49 -30
- package/examples/playground/app/recovery/[recoveryId]/recovery-client.tsx +14 -15
- package/examples/playground/app/recovery/page.tsx +4 -4
- package/examples/playground/app/recovery/server.ts +23 -32
- package/examples/playground/drizzle.config.ts +14 -0
- package/examples/playground/next.config.ts +6 -1
- package/examples/playground/package.json +13 -1
- package/examples/playground/scripts/migrate.mjs +31 -0
- package/examples/playground/test/agent.ts +35 -0
- package/examples/playground/test/model.ts +149 -0
- package/examples/playground/test/serve.ts +184 -0
- package/examples/playground/test/server-only.ts +1 -0
- package/examples/playground/vercel.json +9 -0
- package/examples/playground/vitest.config.ts +27 -0
- package/examples/playground/vitest.drills.config.ts +32 -0
- package/package.json +7 -2
- package/sql/postgres/drizzle-schema.ts +206 -0
- package/sql/postgres/notifications.sql +24 -0
- package/sql/postgres/schema.sql +276 -0
- package/src/actor.ts +101 -71
- package/src/ai-agent.ts +154 -115
- package/src/ai-control-server.ts +8 -8
- package/src/ai-fx.ts +41 -9
- package/src/ai-harness.ts +28 -2
- package/src/ai-pi.ts +2 -2
- package/src/ai-server.ts +2 -2
- package/src/ai.ts +7 -7
- package/src/contract.ts +1 -1
- package/src/deterministic-id.ts +26 -3
- package/src/errors.ts +9 -6
- package/src/idempotent-replay.ts +0 -1
- package/src/index.ts +1 -1
- package/src/internal.ts +17 -6
- package/src/otel.ts +1 -1
- package/src/postgres-notifications.ts +0 -22
- package/src/postgres-resources.ts +6 -9
- package/src/postgres-schema.ts +121 -0
- package/src/push-envelope.ts +20 -0
- package/src/runtime-consumer.ts +10 -0
- package/src/scheduler-qstash.ts +12 -5
- package/src/scheduler-task.ts +2 -2
- package/src/scheduler-vercel.ts +10 -4
- package/src/server.browser.ts +1 -1
- package/src/server.ts +839 -238
- package/src/session-socket.ts +1 -1
- package/src/store-codec.ts +66 -0
- package/src/store-memory.ts +581 -255
- package/src/store-postgres.ts +1984 -943
- package/src/store-redis-core.ts +1624 -1152
- package/src/store-redis-notify.ts +2 -0
- package/src/store-sqlite.ts +891 -486
- package/src/store.ts +227 -97
- package/src/telemetry.ts +2 -1
- package/src/wire.ts +1 -0
- package/dist/ai-harness-BuuC-gJ3.js.map +0 -1
- package/dist/ai-harness-CV6rXbB3.d.ts.map +0 -1
- package/dist/ai-mMiWul1T.js.map +0 -1
- package/dist/contract-BYKASlCV.js.map +0 -1
- package/dist/idempotent-replay-JdgMQRRm.js +0 -21
- package/dist/idempotent-replay-JdgMQRRm.js.map +0 -1
- package/dist/initial-snapshot-Bx-c0pDP.d.ts.map +0 -1
- package/dist/internal-CscSY7K_.js.map +0 -1
- package/dist/server-D-Y4pqwu.js.map +0 -1
- package/dist/server-DYAATFuT.d.ts.map +0 -1
- package/dist/session-clear-C-QwTXV1.d.ts.map +0 -1
- package/dist/session-clear-DGI4jTQ5.js.map +0 -1
- package/dist/store-CyLUy86v.d.ts +0 -404
- package/dist/store-CyLUy86v.d.ts.map +0 -1
- package/dist/store-codec-DTG0Ftek.js +0 -10
- package/dist/store-codec-DTG0Ftek.js.map +0 -1
- package/dist/store-redis-notify-CM0AfLY0.js +0 -2544
- package/dist/store-redis-notify-CM0AfLY0.js.map +0 -1
- package/dist/telemetry-Cyfqo6Qt.d.ts.map +0 -1
- package/dist/wire-BKxH1vbP.js.map +0 -1
- package/docs/reference/05-adapters.mdx +0 -351
- package/docs/server/01-handlers.mdx +0 -200
- package/docs/server/05-production.mdx +0 -323
package/dist/ai-server.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { i as A2Error } from "./session-clear-
|
|
2
|
-
import { a as reducer, s as validateSync } from "./reducer-
|
|
3
|
-
import { h as installAmbientToolScopeStorage, m as failedPreviousAttempt, p as consumeSchedulerSendFailure } from "./internal-
|
|
1
|
+
import { i as A2Error } from "./session-clear-wHd5GCpZ.js";
|
|
2
|
+
import { a as reducer, s as validateSync } from "./reducer-CjmvZSAb.js";
|
|
3
|
+
import { h as installAmbientToolScopeStorage, m as failedPreviousAttempt, p as consumeSchedulerSendFailure } from "./internal-Bc4PvfHk.js";
|
|
4
4
|
import { t as boundedCache } from "./bounded-cache-CPHWF-8h.js";
|
|
5
|
-
import { a as CONSOLE_TELEMETRY,
|
|
5
|
+
import { a as CONSOLE_TELEMETRY, n as createServer, o as setServerFetchHooks } from "./server-DvIB8kj5.js";
|
|
6
6
|
import { a as unexplainedAdmission, i as steersOn, n as initialControlState, r as steeringEnd, t as STEERED_REASON } from "./ai-control-CvLbW10B.js";
|
|
7
|
-
import { A as interruptUIMessage, C as reduceToolActivity, D as flattenProgressBatches, E as upsertResponse, M as assertMessageBase, N as restoreMessageBase, O as progressBatches, S as projectedMessage, T as upsertMessage, _ as applyControlChanges,
|
|
8
|
-
import { a as
|
|
7
|
+
import { A as interruptUIMessage, C as reduceToolActivity, D as flattenProgressBatches, E as upsertResponse, M as assertMessageBase, N as restoreMessageBase, O as progressBatches, S as projectedMessage, T as upsertMessage, _ as applyControlChanges, b as findMessage, d as appSlice, f as isAgentContract, g as isUIMessage, h as aiEventId, j as pauseUIMessage, k as progressOwnedBy, m as AI_EVENT_ID_PREFIX, n as agentContract, o as events, p as withAIStorage, u as appReducerOf, v as controlCommit, w as retainMessageBase, y as advanceProjection } from "./ai-CzE672Q3.js";
|
|
8
|
+
import { a as gatewaySessionAffinity, c as harnessLog, f as registerHarnessStates, l as harnessStates, o as harnessDriver } from "./ai-harness-dQeJaR1t.js";
|
|
9
|
+
import { t as runtimeConsumer } from "./runtime-consumer-BWmht60z.js";
|
|
9
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
11
|
import { asSchema, convertToModelMessages, isToolUIPart, stepCountIs, streamText, toUIMessageStream } from "ai";
|
|
12
12
|
import { Buffer } from "node:buffer";
|
|
13
13
|
//#region src/ai-coordinator.ts
|
|
@@ -1607,8 +1607,8 @@ const measuredInputTokens = (options) => {
|
|
|
1607
1607
|
//#endregion
|
|
1608
1608
|
//#region src/ai-agent.ts
|
|
1609
1609
|
/**
|
|
1610
|
-
* The server-only implementation of the experimental-a2/ai protocol:
|
|
1611
|
-
*
|
|
1610
|
+
* The server-only implementation of the experimental-a2/ai protocol: its
|
|
1611
|
+
* consumers and `agent()`, its assembly as an ordinary A2 server.
|
|
1612
1612
|
*/
|
|
1613
1613
|
const isAgentIngressEvent = (event) => {
|
|
1614
1614
|
if (event.type !== "ai.control.requested") return false;
|
|
@@ -1659,8 +1659,8 @@ const withModelSettings = (options) => {
|
|
|
1659
1659
|
const instructionTexts = (instructions) => instructions === void 0 ? [] : typeof instructions === "string" ? [instructions] : (Array.isArray(instructions) ? instructions : [instructions]).map((message) => message.content);
|
|
1660
1660
|
const errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
1661
1661
|
const toolScopeStorage = installAmbientToolScopeStorage(() => new AsyncLocalStorage());
|
|
1662
|
-
/** Run `fn` with `ctx` as the ambient tool
|
|
1663
|
-
function
|
|
1662
|
+
/** Run `fn` with `ctx` as the ambient tool consumer context, for direct tool tests. */
|
|
1663
|
+
function runWithConsumerContext(ctx, fn) {
|
|
1664
1664
|
return toolScopeStorage.run({ context: ctx }, fn);
|
|
1665
1665
|
}
|
|
1666
1666
|
/** Sessions whose latest step prompt one process keeps for that step's tools. */
|
|
@@ -1736,7 +1736,10 @@ async function generateWithAISDK(options) {
|
|
|
1736
1736
|
...context.generation,
|
|
1737
1737
|
headers: Object.keys(headers).some((key) => key.toLowerCase() === "x-session-affinity") ? headers : {
|
|
1738
1738
|
...headers,
|
|
1739
|
-
"x-session-affinity":
|
|
1739
|
+
"x-session-affinity": gatewaySessionAffinity({
|
|
1740
|
+
agentName,
|
|
1741
|
+
sessionId: context.event.sessionId
|
|
1742
|
+
})
|
|
1740
1743
|
},
|
|
1741
1744
|
providerOptions: {
|
|
1742
1745
|
...context.generation.providerOptions,
|
|
@@ -2116,7 +2119,7 @@ const assertNoLoopOptions = (options) => {
|
|
|
2116
2119
|
throw new TypeError(harness === "ai-sdk" ? `${key} belongs to the harness: agent({ harness: { type: 'ai-sdk', ${key} } })` : `${key} is an option of the AI SDK harness; ${harness}() runs its own loop`);
|
|
2117
2120
|
}
|
|
2118
2121
|
};
|
|
2119
|
-
function
|
|
2122
|
+
function createConsumers(options) {
|
|
2120
2123
|
if (options.model === void 0) throw new TypeError("agent requires model");
|
|
2121
2124
|
if (options.progress?.maxChunks !== void 0 && (!Number.isInteger(options.progress.maxChunks) || options.progress.maxChunks < 1)) throw new TypeError("progress.maxChunks must be a positive integer");
|
|
2122
2125
|
if (options.progress?.maxDelayMs !== void 0 && (!Number.isFinite(options.progress.maxDelayMs) || options.progress.maxDelayMs < 0)) throw new TypeError("progress.maxDelayMs must be a non-negative number");
|
|
@@ -2740,8 +2743,14 @@ function createHandlers(options) {
|
|
|
2740
2743
|
};
|
|
2741
2744
|
}
|
|
2742
2745
|
};
|
|
2743
|
-
|
|
2744
|
-
|
|
2746
|
+
const contract = options.contract;
|
|
2747
|
+
const { toolLane } = options;
|
|
2748
|
+
return [
|
|
2749
|
+
runtimeConsumer({
|
|
2750
|
+
contract,
|
|
2751
|
+
name: "a2.ai.metadata",
|
|
2752
|
+
types: ["ai.model.metadata.requested"]
|
|
2753
|
+
}).run(async (ctx) => {
|
|
2745
2754
|
const limits = await readModelLimits({
|
|
2746
2755
|
modelId: ctx.event.payload.modelId,
|
|
2747
2756
|
signal: ctx.signal
|
|
@@ -2755,27 +2764,29 @@ function createHandlers(options) {
|
|
|
2755
2764
|
limits
|
|
2756
2765
|
}
|
|
2757
2766
|
};
|
|
2758
|
-
}
|
|
2759
|
-
|
|
2767
|
+
}),
|
|
2768
|
+
runtimeConsumer({
|
|
2769
|
+
contract,
|
|
2770
|
+
name: "a2.ai.control",
|
|
2771
|
+
types: [
|
|
2772
|
+
"ai.control.requested",
|
|
2773
|
+
"ai.work.reported",
|
|
2774
|
+
"ai.session.closed"
|
|
2775
|
+
],
|
|
2760
2776
|
lane: ({ event }) => {
|
|
2777
|
+
if (event.type !== "ai.control.requested") return "a2.ai.control";
|
|
2761
2778
|
const command = event.payload;
|
|
2762
2779
|
if (event.id === "") throw new A2Error("INVALID_PAYLOAD", "AI command IDs must be nonempty");
|
|
2763
2780
|
if (event.id?.startsWith("a2.ai:")) throw new A2Error("INVALID_PAYLOAD", `AI command IDs cannot use the reserved '${AI_EVENT_ID_PREFIX}' prefix`);
|
|
2764
2781
|
if ((command.action === "send" || command.action === "steer") && event.id !== command.message.id) throw new A2Error("INVALID_PAYLOAD", "AI input event ID must equal message.id");
|
|
2765
2782
|
return "a2.ai.control";
|
|
2766
|
-
}
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
"ai.session.closed": {
|
|
2774
|
-
lane: "a2.ai.control",
|
|
2775
|
-
handler: controlHandler
|
|
2776
|
-
},
|
|
2777
|
-
"ai.generation.requested": {
|
|
2778
|
-
lane: "a2.ai.model",
|
|
2783
|
+
}
|
|
2784
|
+
}).run(controlHandler),
|
|
2785
|
+
runtimeConsumer({
|
|
2786
|
+
contract,
|
|
2787
|
+
name: "a2.ai.model",
|
|
2788
|
+
types: ["ai.generation.requested"],
|
|
2789
|
+
lane: () => "a2.ai.model",
|
|
2779
2790
|
abortOn: {
|
|
2780
2791
|
"ai.control.requested": (event, trigger) => event.payload.action === "stop" && event.payload.turnId === trigger.payload.control?.turnId,
|
|
2781
2792
|
"ai.control.committed": (event, trigger) => {
|
|
@@ -2783,32 +2794,34 @@ function createHandlers(options) {
|
|
|
2783
2794
|
return active?.turnId !== trigger.payload.control?.turnId || active?.version !== trigger.payload.control?.version;
|
|
2784
2795
|
},
|
|
2785
2796
|
"ai.session.closed": true
|
|
2786
|
-
}
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2797
|
+
}
|
|
2798
|
+
}).run((ctx) => telemetry.span("a2.ai.generate", {
|
|
2799
|
+
"a2.contract": options.contract.name,
|
|
2800
|
+
"a2.session_id": ctx.event.sessionId,
|
|
2801
|
+
"a2.ai.generate.request_id": ctx.event.id,
|
|
2802
|
+
"a2.ai.generate.attempt": ctx.attempt
|
|
2803
|
+
}, async () => {
|
|
2804
|
+
try {
|
|
2805
|
+
return control.settled({
|
|
2806
|
+
ctx,
|
|
2807
|
+
events: await generationHandler(ctx)
|
|
2808
|
+
});
|
|
2809
|
+
} catch (error) {
|
|
2810
|
+
if (control.cancelled({
|
|
2811
|
+
error,
|
|
2812
|
+
signal: ctx.signal
|
|
2813
|
+
})) return control.settled({
|
|
2814
|
+
ctx,
|
|
2815
|
+
events: void 0
|
|
2816
|
+
});
|
|
2817
|
+
throw error;
|
|
2818
|
+
}
|
|
2819
|
+
})),
|
|
2820
|
+
runtimeConsumer({
|
|
2821
|
+
contract,
|
|
2822
|
+
name: "a2.ai.tools",
|
|
2823
|
+
types: ["ai.tool.execution.requested"],
|
|
2824
|
+
...toolLane === void 0 ? {} : { lane: () => toolLane },
|
|
2812
2825
|
abortOn: {
|
|
2813
2826
|
"ai.control.requested": (event, trigger) => event.payload.action === "stop" && event.payload.turnId === trigger.payload.turnId,
|
|
2814
2827
|
"ai.generation.failed": (event, trigger) => event.payload.generationId === trigger.payload.call.generationId,
|
|
@@ -2817,21 +2830,21 @@ function createHandlers(options) {
|
|
|
2817
2830
|
return active?.turnId !== trigger.payload.turnId || active?.version !== trigger.payload.version;
|
|
2818
2831
|
},
|
|
2819
2832
|
"ai.session.closed": true
|
|
2820
|
-
}
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
};
|
|
2833
|
+
}
|
|
2834
|
+
}).run((ctx) => telemetry.span("a2.ai.tool", {
|
|
2835
|
+
"a2.contract": options.contract.name,
|
|
2836
|
+
"a2.session_id": ctx.event.sessionId,
|
|
2837
|
+
"a2.ai.tool.request_id": ctx.event.payload.call.requestId,
|
|
2838
|
+
"a2.ai.tool.call_id": ctx.event.payload.call.toolCallId,
|
|
2839
|
+
"a2.ai.tool.name": ctx.event.payload.call.toolName,
|
|
2840
|
+
"a2.ai.tool.attempt": ctx.attempt
|
|
2841
|
+
}, () => handleToolExecution(ctx)))
|
|
2842
|
+
];
|
|
2831
2843
|
}
|
|
2832
2844
|
function agent(options) {
|
|
2833
2845
|
assertNoLoopOptions(options);
|
|
2834
|
-
|
|
2846
|
+
if (options.toolLane !== void 0 && (typeof options.toolLane !== "string" || options.toolLane.length === 0)) throw new TypeError("toolLane must be a non-empty string");
|
|
2847
|
+
const { model, tools, instructions, maxSteps, harness, toolRecovery, progress, toolLane, ...rest } = options;
|
|
2835
2848
|
let contract;
|
|
2836
2849
|
let serverOptions;
|
|
2837
2850
|
if ("contract" in rest) {
|
|
@@ -2850,7 +2863,7 @@ function agent(options) {
|
|
|
2850
2863
|
serverOptions = remaining;
|
|
2851
2864
|
}
|
|
2852
2865
|
const states = harnessStates();
|
|
2853
|
-
const builtIns =
|
|
2866
|
+
const builtIns = createConsumers({
|
|
2854
2867
|
contract,
|
|
2855
2868
|
model,
|
|
2856
2869
|
harnessStates: states,
|
|
@@ -2863,14 +2876,10 @@ function agent(options) {
|
|
|
2863
2876
|
...progress === void 0 ? {} : { progress },
|
|
2864
2877
|
...toolLane === void 0 ? {} : { toolLane }
|
|
2865
2878
|
});
|
|
2866
|
-
for (const type of Object.keys(handlers ?? {})) if (Object.hasOwn(builtIns, type)) throw new TypeError(`agent handles '${type}' itself`);
|
|
2867
2879
|
const server = createServer({
|
|
2868
2880
|
...serverOptions,
|
|
2869
2881
|
contract,
|
|
2870
|
-
|
|
2871
|
-
...builtIns,
|
|
2872
|
-
...handlers
|
|
2873
|
-
}
|
|
2882
|
+
consumers: [...builtIns, ...serverOptions.consumers ?? []]
|
|
2874
2883
|
});
|
|
2875
2884
|
registerHarnessStates(server, states);
|
|
2876
2885
|
const applicationEvents = "contract" in rest;
|
|
@@ -2881,6 +2890,6 @@ function agent(options) {
|
|
|
2881
2890
|
return server;
|
|
2882
2891
|
}
|
|
2883
2892
|
//#endregion
|
|
2884
|
-
export { agent,
|
|
2893
|
+
export { agent, runWithConsumerContext };
|
|
2885
2894
|
|
|
2886
2895
|
//# sourceMappingURL=ai-server.js.map
|