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
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import 'server-only'
|
|
2
2
|
import { tool } from 'ai'
|
|
3
3
|
import { idempotentId } from 'experimental-a2'
|
|
4
|
-
import {
|
|
4
|
+
import { consumerContext, inputs } from 'experimental-a2/ai'
|
|
5
5
|
import { agent } from 'experimental-a2/ai/server'
|
|
6
6
|
import { vercelQueues } from 'experimental-a2/scheduler-vercel'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
consumer,
|
|
9
|
+
createServer,
|
|
10
|
+
type A2Operation,
|
|
11
|
+
} from 'experimental-a2/server'
|
|
8
12
|
import { store } from '@/lib/store'
|
|
9
13
|
import {
|
|
10
14
|
chat,
|
|
@@ -22,7 +26,7 @@ const tools = {
|
|
|
22
26
|
'Post a visible message to the multiplayer chat. Call it once for each chat bubble you want to send; this tool is the only way to speak in the room.',
|
|
23
27
|
inputSchema: chatPostInputSchema,
|
|
24
28
|
execute: async ({ message }, { toolCallId }) => {
|
|
25
|
-
const context =
|
|
29
|
+
const context = consumerContext(chatAgent)
|
|
26
30
|
context.signal.throwIfAborted()
|
|
27
31
|
const { generationId, messageId } = context.event.payload.call
|
|
28
32
|
// The agent's session shares the room's id. The explicit id makes a
|
|
@@ -114,42 +118,48 @@ Use as many post calls as the moment naturally calls for. Several short messages
|
|
|
114
118
|
},
|
|
115
119
|
})
|
|
116
120
|
|
|
117
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Each room message goes on to the agent's session, marked for whether it
|
|
123
|
+
* should answer. One lane keeps the agent's messages in the room's order.
|
|
124
|
+
*/
|
|
125
|
+
const forwardToAgent = consumer({
|
|
126
|
+
contract: chat,
|
|
127
|
+
name: 'forward-to-agent',
|
|
128
|
+
types: ['message.sent'],
|
|
129
|
+
lane: 'a2.chat.ingress',
|
|
130
|
+
}).run(async (context) => {
|
|
131
|
+
const ambient = (await context.session.state()).state.ambient.enabled
|
|
132
|
+
const { author, text } = context.event.payload
|
|
133
|
+
const mode: ChatParticipantMode = ambient
|
|
134
|
+
? 'ambient'
|
|
135
|
+
: mentionsAgent(text)
|
|
136
|
+
? 'mention'
|
|
137
|
+
: 'passive'
|
|
138
|
+
const message: ChatAgentMessage = {
|
|
139
|
+
// Event ids are unique across a store's sessions, so the forward
|
|
140
|
+
// derives its own; a retried forward converges on the same id.
|
|
141
|
+
id: await idempotentId('chat.message', context.event.id),
|
|
142
|
+
role: 'user',
|
|
143
|
+
metadata: {
|
|
144
|
+
kind: 'participant',
|
|
145
|
+
author,
|
|
146
|
+
text,
|
|
147
|
+
sentAt: context.event.createdAt.toISOString(),
|
|
148
|
+
mode,
|
|
149
|
+
},
|
|
150
|
+
parts: [{ type: 'text', text: `${author}: ${text}` }],
|
|
151
|
+
}
|
|
152
|
+
await chatAgentServer
|
|
153
|
+
.session(context.session.id)
|
|
154
|
+
.append(...inputs.message(message, { generate: mode !== 'passive' }))
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
/** The room. Its messages reach the agent through `forwardToAgent`. */
|
|
118
158
|
export const chatServer = createServer({
|
|
119
159
|
...(store ? { store } : {}),
|
|
120
160
|
...(chatScheduler ? { scheduler: chatScheduler } : {}),
|
|
121
161
|
contract: chat,
|
|
122
|
-
|
|
123
|
-
'message.sent': {
|
|
124
|
-
lane: 'a2.chat.ingress',
|
|
125
|
-
handler: async (context) => {
|
|
126
|
-
const ambient = (await context.session.state()).state.ambient.enabled
|
|
127
|
-
const { author, text } = context.event.payload
|
|
128
|
-
const mode: ChatParticipantMode = ambient
|
|
129
|
-
? 'ambient'
|
|
130
|
-
: mentionsAgent(text)
|
|
131
|
-
? 'mention'
|
|
132
|
-
: 'passive'
|
|
133
|
-
const message: ChatAgentMessage = {
|
|
134
|
-
// Event ids are unique across a store's sessions, so the forward
|
|
135
|
-
// derives its own; a retried forward converges on the same id.
|
|
136
|
-
id: await idempotentId('chat.message', context.event.id),
|
|
137
|
-
role: 'user',
|
|
138
|
-
metadata: {
|
|
139
|
-
kind: 'participant',
|
|
140
|
-
author,
|
|
141
|
-
text,
|
|
142
|
-
sentAt: context.event.createdAt.toISOString(),
|
|
143
|
-
mode,
|
|
144
|
-
},
|
|
145
|
-
parts: [{ type: 'text', text: `${author}: ${text}` }],
|
|
146
|
-
}
|
|
147
|
-
await chatAgentServer
|
|
148
|
-
.session(context.session.id)
|
|
149
|
-
.append(...inputs.message(message, { generate: mode !== 'passive' }))
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
162
|
+
consumers: [forwardToAgent],
|
|
153
163
|
})
|
|
154
164
|
|
|
155
165
|
/** Room pushes: people's messages, typing, and ambient mode. Posts are the agent's. */
|
|
@@ -1,35 +1,77 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
act,
|
|
4
|
+
cleanup,
|
|
5
|
+
fireEvent,
|
|
6
|
+
render,
|
|
7
|
+
screen,
|
|
8
|
+
waitFor,
|
|
9
|
+
} from '@testing-library/react'
|
|
10
|
+
import type { InitialSnapshot } from 'experimental-a2'
|
|
11
|
+
import { useAgent } from 'experimental-a2/ai/react'
|
|
12
|
+
import { createClient } from 'experimental-a2/client'
|
|
13
|
+
import type { ReactNode } from 'react'
|
|
14
|
+
import { afterEach, expect, it } from 'vitest'
|
|
15
|
+
import { serveAgent, type ServedAgent } from '@/test/agent'
|
|
16
|
+
import { demoAgent, type AgentState } from '../agent/model'
|
|
4
17
|
import { ActivityFeed } from './activity-feed'
|
|
5
18
|
|
|
6
|
-
|
|
19
|
+
let served: ServedAgent | undefined
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
cleanup()
|
|
23
|
+
await served?.close()
|
|
24
|
+
})
|
|
7
25
|
|
|
8
26
|
it('loads an earlier page only on request and keeps failures retryable', async () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
served = await serveAgent()
|
|
28
|
+
const { server, probe } = served
|
|
29
|
+
const client = createClient({ contract: demoAgent, api: served.url })
|
|
30
|
+
const id = crypto.randomUUID()
|
|
31
|
+
await server.session(id).append({
|
|
32
|
+
type: 'compaction.settings.updated',
|
|
33
|
+
payload: { mode: 'disabled' },
|
|
34
|
+
})
|
|
35
|
+
const operations = () => probe.operations.map(({ type }) => type)
|
|
36
|
+
|
|
37
|
+
function Feed({
|
|
38
|
+
initial,
|
|
39
|
+
}: {
|
|
40
|
+
initial: InitialSnapshot<AgentState>
|
|
41
|
+
}): ReactNode {
|
|
42
|
+
const session = useAgent({ client, id, initial })
|
|
43
|
+
return (
|
|
44
|
+
<ActivityFeed
|
|
45
|
+
events={session.events}
|
|
46
|
+
index={session.index}
|
|
47
|
+
history={session.history}
|
|
48
|
+
loadHistory={session.loadHistory}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
probe.deny(({ type }) => type === 'history')
|
|
54
|
+
render(<Feed initial={await server.session(id).state()} />)
|
|
55
|
+
await waitFor(() => expect(operations()).toContain('stream'))
|
|
56
|
+
expect(operations()).not.toContain('history')
|
|
22
57
|
await act(async () =>
|
|
23
58
|
fireEvent.click(
|
|
24
59
|
screen.getByRole('button', { name: 'Load earlier events' }),
|
|
25
60
|
),
|
|
26
61
|
)
|
|
27
|
-
expect(screen.
|
|
62
|
+
expect((await screen.findByRole('alert')).textContent).toBe(
|
|
63
|
+
'the operation is not authorized',
|
|
64
|
+
)
|
|
28
65
|
await act(async () =>
|
|
29
66
|
fireEvent.click(
|
|
30
67
|
screen.getByRole('button', { name: 'Load earlier events' }),
|
|
31
68
|
),
|
|
32
69
|
)
|
|
70
|
+
await waitFor(() =>
|
|
71
|
+
expect(screen.getByRole('list').textContent).toContain(
|
|
72
|
+
'compaction.settings.updated',
|
|
73
|
+
),
|
|
74
|
+
)
|
|
33
75
|
expect(screen.queryByRole('alert')).toBeNull()
|
|
34
|
-
expect(
|
|
76
|
+
expect(operations().filter((type) => type === 'history')).toHaveLength(2)
|
|
35
77
|
})
|
|
@@ -40,6 +40,13 @@ export const ChatIcon = (): ReactNode => (
|
|
|
40
40
|
</Glyph>
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
+
export const A2slackIcon = (): ReactNode => (
|
|
44
|
+
<Glyph>
|
|
45
|
+
<path d="M3 4h18v13H10l-4 3.5V17H3z" />
|
|
46
|
+
<path className="accent" d="M10.5 7l-1 7M14.5 7l-1 7M8 9h8M7.5 12h8" />
|
|
47
|
+
</Glyph>
|
|
48
|
+
)
|
|
49
|
+
|
|
43
50
|
export const AgentIcon = (): ReactNode => (
|
|
44
51
|
<Glyph>
|
|
45
52
|
<rect x="3" y="3" width="18" height="18" />
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
A0Icon,
|
|
4
|
+
A2slackIcon,
|
|
4
5
|
AgentIcon,
|
|
5
6
|
CanvasIcon,
|
|
6
7
|
ChatIcon,
|
|
@@ -24,6 +25,12 @@ export const demos: Demo[] = [
|
|
|
24
25
|
{ href: '/a0', name: 'A0', icon: <A0Icon />, fullWindow: true },
|
|
25
26
|
{ href: '/orders', name: 'Orders', icon: <OrdersIcon /> },
|
|
26
27
|
{ href: '/chat', name: 'Chat', icon: <ChatIcon /> },
|
|
28
|
+
{
|
|
29
|
+
href: '/a2slack',
|
|
30
|
+
name: 'a2slack',
|
|
31
|
+
icon: <A2slackIcon />,
|
|
32
|
+
fullWindow: true,
|
|
33
|
+
},
|
|
27
34
|
{ href: '/agent', name: 'Agent', icon: <AgentIcon /> },
|
|
28
35
|
{ href: '/canvas', name: 'Canvas', icon: <CanvasIcon /> },
|
|
29
36
|
{ href: '/documents', name: 'Documents', icon: <DocumentsIcon /> },
|
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
|
10
10
|
import { FastLink } from './fast-link'
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
vi.mock('next/navigation', () => ({ useRouter: () => ({ push }) }))
|
|
12
|
+
// The App Router's router only exists inside a Next.js app.
|
|
13
|
+
vi.mock('next/navigation', () => ({ useRouter: () => ({ push: () => {} }) }))
|
|
14
14
|
|
|
15
15
|
// Whether each click reached the browser's default; then stop jsdom's
|
|
16
16
|
// unimplemented navigation.
|
|
@@ -20,7 +20,6 @@ const record = (event: MouseEvent): void => {
|
|
|
20
20
|
event.preventDefault()
|
|
21
21
|
}
|
|
22
22
|
beforeEach(() => {
|
|
23
|
-
push.mockReset()
|
|
24
23
|
navigatedByClick = []
|
|
25
24
|
document.addEventListener('click', record)
|
|
26
25
|
})
|
|
@@ -40,10 +39,9 @@ const press = (): void => {
|
|
|
40
39
|
fireEvent(link(), event)
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
it('
|
|
42
|
+
it('swallows only the click that follows a press', () => {
|
|
44
43
|
render(<FastLink href="/a0">Apps</FastLink>)
|
|
45
44
|
press()
|
|
46
|
-
expect(push).toHaveBeenCalledWith('/a0')
|
|
47
45
|
fireEvent.click(link(), { detail: 1 })
|
|
48
46
|
fireEvent.click(link(), { detail: 1 })
|
|
49
47
|
expect(navigatedByClick).toEqual([false, true])
|
|
@@ -1,54 +1,95 @@
|
|
|
1
1
|
import type { ReactElement } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import { afterEach, expect, it, vi, type Mock } from 'vitest'
|
|
3
3
|
import AgentPage from './agent/[agentId]/page'
|
|
4
|
+
import { agentServer } from './agent/server'
|
|
4
5
|
import ChatPage from './chat/[chatId]/page'
|
|
6
|
+
import { chatAgentServer, chatServer } from './chat/server'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
vi.restoreAllMocks()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
type Read = (...args: never[]) => unknown
|
|
13
|
+
type Handle = { state: Read; history: Read }
|
|
14
|
+
type Reads = { state: Mock<Read>; history: Mock<Read> }
|
|
15
|
+
|
|
16
|
+
/** The reads made through each session handle `server` hands out from now on. */
|
|
17
|
+
const readsOf = <H extends Handle>(server: {
|
|
18
|
+
session(id: string): H
|
|
19
|
+
}): Reads[] => {
|
|
20
|
+
const session = server.session.bind(server)
|
|
21
|
+
const handles: Reads[] = []
|
|
22
|
+
vi.spyOn(server, 'session').mockImplementation((id) => {
|
|
23
|
+
const handle = session(id)
|
|
24
|
+
const reads: Reads = {
|
|
25
|
+
state: vi.fn<Read>(handle.state),
|
|
26
|
+
history: vi.fn<Read>(handle.history),
|
|
27
|
+
}
|
|
28
|
+
handles.push(reads)
|
|
29
|
+
return { ...handle, ...reads }
|
|
30
|
+
})
|
|
31
|
+
return handles
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const oneStateRead = (handles: Reads[]): void => {
|
|
35
|
+
expect(handles).toHaveLength(1)
|
|
36
|
+
expect(handles[0]!.state).toHaveBeenCalledExactlyOnceWith()
|
|
37
|
+
expect(handles[0]!.history).not.toHaveBeenCalled()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
it('seeds agent from one state read without fetching raw history', async () => {
|
|
41
|
+
const agentId = crypto.randomUUID()
|
|
42
|
+
const session = agentServer.session(agentId)
|
|
43
|
+
await session.append({
|
|
44
|
+
type: 'compaction.settings.updated',
|
|
45
|
+
payload: { mode: 'manual', thresholdTokens: 1234 },
|
|
29
46
|
})
|
|
47
|
+
await agentServer.drain(agentId)
|
|
48
|
+
const expected = await session.state()
|
|
49
|
+
expect(expected.state.compactionSettings).toEqual({
|
|
50
|
+
mode: 'manual',
|
|
51
|
+
thresholdTokens: 1234,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const reads = readsOf(agentServer)
|
|
55
|
+
const element = (await AgentPage({
|
|
56
|
+
params: Promise.resolve({ agentId }),
|
|
57
|
+
})) as ReactElement<{ initial: unknown; initialEvents?: unknown }>
|
|
58
|
+
oneStateRead(reads)
|
|
59
|
+
expect(element.props.initial).toEqual(expected)
|
|
60
|
+
expect(element.props.initialEvents).toBeUndefined()
|
|
30
61
|
})
|
|
31
62
|
|
|
32
|
-
it
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
expect(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
|
|
63
|
+
it('seeds chat and its agent session, each from one state read', async () => {
|
|
64
|
+
const chatId = crypto.randomUUID()
|
|
65
|
+
await chatServer.session(chatId).append({
|
|
66
|
+
type: 'message.sent',
|
|
67
|
+
payload: { author: 'alice', text: 'just chatting' },
|
|
68
|
+
})
|
|
69
|
+
// The room forwards the message to its agent in a background drain.
|
|
70
|
+
await vi.waitFor(async () => {
|
|
71
|
+
expect(
|
|
72
|
+
(await chatAgentServer.session(chatId).state()).state.messages,
|
|
73
|
+
).toHaveLength(1)
|
|
74
|
+
})
|
|
75
|
+
await chatServer.drain(chatId)
|
|
76
|
+
await chatAgentServer.drain(chatId)
|
|
77
|
+
const room = await chatServer.session(chatId).state()
|
|
78
|
+
const agent = await chatAgentServer.session(chatId).state()
|
|
79
|
+
expect(room.state.messages).toHaveLength(1)
|
|
80
|
+
|
|
81
|
+
const roomReads = readsOf(chatServer)
|
|
82
|
+
const agentReads = readsOf(chatAgentServer)
|
|
48
83
|
const element = (await ChatPage({
|
|
49
|
-
params: Promise.resolve({ chatId
|
|
50
|
-
})) as ReactElement<{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
84
|
+
params: Promise.resolve({ chatId }),
|
|
85
|
+
})) as ReactElement<{
|
|
86
|
+
initial: unknown
|
|
87
|
+
initialEvents?: unknown
|
|
88
|
+
children: ReactElement<{ agentInitial: unknown }>
|
|
89
|
+
}>
|
|
90
|
+
oneStateRead(roomReads)
|
|
91
|
+
oneStateRead(agentReads)
|
|
92
|
+
expect(element.props.initial).toEqual(room)
|
|
93
|
+
expect(element.props.initialEvents).toBeUndefined()
|
|
94
|
+
expect(element.props.children.props.agentInitial).toEqual(agent)
|
|
54
95
|
})
|
|
@@ -118,7 +118,7 @@ export function OrderClient({ sessionId }: { sessionId: string }): ReactNode {
|
|
|
118
118
|
<p className="hint">
|
|
119
119
|
The button pushes <code>shop.started</code> optimistically — the
|
|
120
120
|
badge flips before the server acks. Everything after that is
|
|
121
|
-
|
|
121
|
+
consumers appending the next fact: courier assigned, picked up,
|
|
122
122
|
delivered — watch it arrive over the stream, hands off.
|
|
123
123
|
</p>
|
|
124
124
|
</>
|
|
@@ -129,7 +129,7 @@ export function OrderClient({ sessionId }: { sessionId: string }): ReactNode {
|
|
|
129
129
|
</p>
|
|
130
130
|
) : (
|
|
131
131
|
<p className="hint">
|
|
132
|
-
Hands off from here — each status lands on its own as
|
|
132
|
+
Hands off from here — each status lands on its own as consumers append
|
|
133
133
|
the next fact.
|
|
134
134
|
</p>
|
|
135
135
|
)}
|
|
@@ -8,7 +8,7 @@ export default function OrdersPage(): ReactNode {
|
|
|
8
8
|
<p className="lede">
|
|
9
9
|
Creating an order appends a single <code>created</code> event.
|
|
10
10
|
Everything after that — the shop notification, the courier, the delivery
|
|
11
|
-
itself — is
|
|
11
|
+
itself — is consumers appending the next fact to the same log, all the
|
|
12
12
|
way to <code>delivered</code>.
|
|
13
13
|
</p>
|
|
14
14
|
<NewOrderForm />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'server-only'
|
|
2
2
|
import { vercelQueues } from 'experimental-a2/scheduler-vercel'
|
|
3
|
-
import { createServer } from 'experimental-a2/server'
|
|
3
|
+
import { consumer, createServer } from 'experimental-a2/server'
|
|
4
4
|
import { store } from '@/lib/store'
|
|
5
5
|
import { orders } from './model'
|
|
6
6
|
|
|
@@ -14,37 +14,56 @@ export const ordersScheduler =
|
|
|
14
14
|
? vercelQueues({ topic: 'a2-orders' })
|
|
15
15
|
: undefined
|
|
16
16
|
|
|
17
|
+
const notifyShop = consumer({
|
|
18
|
+
contract: orders,
|
|
19
|
+
name: 'notify-shop',
|
|
20
|
+
types: ['created'],
|
|
21
|
+
}).run(async ({ session }) => {
|
|
22
|
+
await wait(800)
|
|
23
|
+
await session.append('notify-shop', {
|
|
24
|
+
type: 'shop.notified',
|
|
25
|
+
payload: {},
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const notifyDriver = consumer({
|
|
30
|
+
contract: orders,
|
|
31
|
+
name: 'notify-driver',
|
|
32
|
+
types: ['shop.started'],
|
|
33
|
+
}).run(async ({ session }) => {
|
|
34
|
+
await wait(1200)
|
|
35
|
+
const driverId = drivers[Math.floor(Math.random() * drivers.length)]!
|
|
36
|
+
await session.append('notify-driver', {
|
|
37
|
+
type: 'driver.notified',
|
|
38
|
+
payload: { driverId },
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const pickUp = consumer({
|
|
43
|
+
contract: orders,
|
|
44
|
+
name: 'pick-up',
|
|
45
|
+
types: ['driver.notified'],
|
|
46
|
+
}).run(async ({ session }) => {
|
|
47
|
+
await wait(3000)
|
|
48
|
+
const etaMinutes = 3 + Math.floor(Math.random() * 5)
|
|
49
|
+
await session.append('courier-picked-up', {
|
|
50
|
+
type: 'courier.picked_up',
|
|
51
|
+
payload: { etaMinutes },
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const deliver = consumer({
|
|
56
|
+
contract: orders,
|
|
57
|
+
name: 'deliver',
|
|
58
|
+
types: ['courier.picked_up'],
|
|
59
|
+
}).run(async ({ session }) => {
|
|
60
|
+
await wait(3500)
|
|
61
|
+
await session.append('delivered', { type: 'delivered', payload: {} })
|
|
62
|
+
})
|
|
63
|
+
|
|
17
64
|
export const ordersServer = createServer({
|
|
18
65
|
...(store ? { store } : {}),
|
|
19
66
|
...(ordersScheduler ? { scheduler: ordersScheduler } : {}),
|
|
20
67
|
contract: orders,
|
|
21
|
-
|
|
22
|
-
created: async ({ session }) => {
|
|
23
|
-
await wait(800)
|
|
24
|
-
await session.append('notify-shop', {
|
|
25
|
-
type: 'shop.notified',
|
|
26
|
-
payload: {},
|
|
27
|
-
})
|
|
28
|
-
},
|
|
29
|
-
'shop.started': async ({ session }) => {
|
|
30
|
-
await wait(1200)
|
|
31
|
-
const driverId = drivers[Math.floor(Math.random() * drivers.length)]!
|
|
32
|
-
await session.append('notify-driver', {
|
|
33
|
-
type: 'driver.notified',
|
|
34
|
-
payload: { driverId },
|
|
35
|
-
})
|
|
36
|
-
},
|
|
37
|
-
'driver.notified': async ({ session }) => {
|
|
38
|
-
await wait(3000)
|
|
39
|
-
const etaMinutes = 3 + Math.floor(Math.random() * 5)
|
|
40
|
-
await session.append('courier-picked-up', {
|
|
41
|
-
type: 'courier.picked_up',
|
|
42
|
-
payload: { etaMinutes },
|
|
43
|
-
})
|
|
44
|
-
},
|
|
45
|
-
'courier.picked_up': async ({ session }) => {
|
|
46
|
-
await wait(3500)
|
|
47
|
-
await session.append('delivered', { type: 'delivered', payload: {} })
|
|
48
|
-
},
|
|
49
|
-
},
|
|
68
|
+
consumers: [notifyShop, notifyDriver, pickUp, deliver],
|
|
50
69
|
})
|
|
@@ -45,7 +45,7 @@ export function RecoveryClient({
|
|
|
45
45
|
return (
|
|
46
46
|
<article>
|
|
47
47
|
<header className="session-header">
|
|
48
|
-
<h1>Cross-invocation
|
|
48
|
+
<h1>Cross-invocation step chain</h1>
|
|
49
49
|
<ConnectionPill connection={connection} />
|
|
50
50
|
<span
|
|
51
51
|
className={`badge${completed ? ' done' : running ? ' waiting' : ''}`}
|
|
@@ -59,14 +59,14 @@ export function RecoveryClient({
|
|
|
59
59
|
</header>
|
|
60
60
|
|
|
61
61
|
<p className="lede">
|
|
62
|
-
Four
|
|
63
|
-
|
|
62
|
+
Four steps fit individually, but their 32-second chain does not fit in
|
|
63
|
+
one 20-second function. Every invocation has the same limit.
|
|
64
64
|
</p>
|
|
65
65
|
|
|
66
66
|
<dl className="facts">
|
|
67
67
|
<dt>Function limit</dt>
|
|
68
68
|
<dd>{FUNCTION_LIMIT_SECONDS} seconds</dd>
|
|
69
|
-
<dt>Each
|
|
69
|
+
<dt>Each step</dt>
|
|
70
70
|
<dd>{STEP_SECONDS} seconds</dd>
|
|
71
71
|
<dt>Whole chain</dt>
|
|
72
72
|
<dd>
|
|
@@ -94,15 +94,14 @@ export function RecoveryClient({
|
|
|
94
94
|
<h2>The chain is crossing function invocations</h2>
|
|
95
95
|
<p>
|
|
96
96
|
Each step waits eight seconds before appending its completion fact.
|
|
97
|
-
A2 does not predict whether the next
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
fresh function.
|
|
97
|
+
A2 does not predict whether the next step fits. The first invocation
|
|
98
|
+
completes two steps, starts the third, and is stopped by Vercel at
|
|
99
|
+
20 seconds. That event stays pending. Its claim watchdog acquires
|
|
100
|
+
the expired claim and retries the same event in a fresh function.
|
|
102
101
|
</p>
|
|
103
102
|
<p className="hint">
|
|
104
103
|
Keep this page open. Claim heartbeats keep scheduling watchdogs
|
|
105
|
-
while a
|
|
104
|
+
while a step is running. The known function deadline caps the last
|
|
106
105
|
claim window, so the scheduler arrives just after Vercel stops the
|
|
107
106
|
worker. Reloading can also trigger A2's separate
|
|
108
107
|
interaction-healing path.
|
|
@@ -112,8 +111,8 @@ export function RecoveryClient({
|
|
|
112
111
|
|
|
113
112
|
{completed ? (
|
|
114
113
|
<p className="proof">
|
|
115
|
-
All {state.completedSteps} bounded
|
|
116
|
-
|
|
114
|
+
All {state.completedSteps} bounded steps finished. The scheduler added
|
|
115
|
+
no event of its own; it only continued draining the pending
|
|
117
116
|
application events.
|
|
118
117
|
</p>
|
|
119
118
|
) : null}
|
|
@@ -127,12 +126,12 @@ export function RecoveryClient({
|
|
|
127
126
|
state.completedSteps < STEP_COUNT ? (
|
|
128
127
|
<>
|
|
129
128
|
Waiting for step {state.completedSteps + 1} of {STEP_COUNT}. The
|
|
130
|
-
event log stays quiet while its {STEP_SECONDS}-second
|
|
131
|
-
|
|
129
|
+
event log stays quiet while its {STEP_SECONDS}-second step runs;
|
|
130
|
+
the next row is the step's real completion fact.
|
|
132
131
|
</>
|
|
133
132
|
) : (
|
|
134
133
|
<>
|
|
135
|
-
All four
|
|
134
|
+
All four steps finished. Waiting for the final{' '}
|
|
136
135
|
<code>pipeline.completed</code> fact from the active drain.
|
|
137
136
|
</>
|
|
138
137
|
)
|
|
@@ -6,10 +6,10 @@ export default function RecoveryPage(): ReactNode {
|
|
|
6
6
|
<article>
|
|
7
7
|
<h1>Recovery lab</h1>
|
|
8
8
|
<p className="lede">
|
|
9
|
-
Run four 8-second
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
Run four 8-second steps in a chain. Each fits inside a 20-second Vercel
|
|
10
|
+
function, but all 32 seconds cannot. Watch Vercel stop one mid-step,
|
|
11
|
+
then let A2 retry that pending event in a fresh invocation with the same
|
|
12
|
+
limit.
|
|
13
13
|
</p>
|
|
14
14
|
<NewRecoverySession />
|
|
15
15
|
<p className="hint">
|