stitchkit 0.100.2 → 0.100.3
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 +86 -0
- package/README.md +2 -1
- package/dist/entrypoints/agent-runtime/browser.js +119 -119
- package/dist/entrypoints/agent-runtime/coding-tools.js +15 -20
- package/dist/entrypoints/agent-runtime/harness.js +55 -63
- package/dist/entrypoints/agent-runtime/openrouter.js +6 -6
- package/dist/entrypoints/agent-runtime/sandbox.js +20 -25
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +11 -13
- package/dist/entrypoints/agent-runtime/sqlite/node.js +11 -13
- package/dist/entrypoints/agent-runtime/testing.js +32 -34
- package/dist/entrypoints/agent-runtime.js +395 -402
- package/dist/entrypoints/application/diagnostic-journal.js +26 -27
- package/dist/entrypoints/application/directory-inbox.js +16 -17
- package/dist/entrypoints/application/grammy.js +13 -13
- package/dist/entrypoints/application/opentelemetry.js +13 -13
- package/dist/entrypoints/application/schemas.js +24 -24
- package/dist/entrypoints/application.js +208 -210
- package/dist/entrypoints/bin/upgrade-cli.js +2 -2
- package/dist/entrypoints/cli.js +81 -84
- package/dist/entrypoints/contract.js +54 -57
- package/dist/entrypoints/declaration.js +22 -22
- package/dist/entrypoints/files.js +18 -21
- package/dist/entrypoints/geo.js +7 -8
- package/dist/entrypoints/google.js +2 -2
- package/dist/entrypoints/index.js +150 -154
- package/dist/entrypoints/live.js +45 -47
- package/dist/entrypoints/node.js +68 -74
- package/dist/entrypoints/oauth.js +6 -6
- package/dist/entrypoints/observability.d.ts +1 -0
- package/dist/entrypoints/observability.d.ts.map +1 -1
- package/dist/entrypoints/observability.js +115 -87
- package/dist/entrypoints/primitives.js +35 -35
- package/dist/entrypoints/react/keyboard.d.ts +4 -0
- package/dist/entrypoints/react/keyboard.d.ts.map +1 -0
- package/dist/entrypoints/react/keyboard.js +397 -0
- package/dist/entrypoints/react.js +10 -10
- package/dist/entrypoints/release.js +7 -7
- package/dist/entrypoints/remote.js +15 -17
- package/dist/entrypoints/server.js +198 -200
- package/dist/entrypoints/telegram/html.d.ts +5 -0
- package/dist/entrypoints/telegram/html.d.ts.map +1 -0
- package/dist/entrypoints/telegram/html.js +26 -0
- package/dist/entrypoints/telegram/screens.d.ts +14 -0
- package/dist/entrypoints/telegram/screens.d.ts.map +1 -0
- package/dist/entrypoints/telegram/screens.js +2028 -0
- package/dist/entrypoints/telegram.d.ts +5 -1
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +548 -156
- package/dist/entrypoints/testing.js +75 -79
- package/dist/entrypoints/tools/connections.js +30 -32
- package/dist/entrypoints/tools/contract.js +18 -20
- package/dist/entrypoints/tools/invoker.js +12 -17
- package/dist/entrypoints/tools.js +223 -229
- package/dist/entrypoints/tracking/server.js +6 -6
- package/dist/entrypoints/tracking.js +40 -42
- package/dist/entrypoints/voice.js +3 -3
- package/dist/{index-eaysmdtq.js → index-0ndk4555.js} +56 -56
- package/dist/{index-2bxbyab0.js → index-1bx1xv1k.js} +1 -1
- package/dist/{index-p5r7qpdd.js → index-1eeqpadm.js} +4 -4
- package/dist/{index-hadmp193.js → index-3ct7hhq6.js} +210 -210
- package/dist/{index-e01r054k.js → index-45tdvqa3.js} +26 -26
- package/dist/{index-dce5wxcq.js → index-4s0fep5q.js} +8 -8
- package/dist/index-50ejfz75.js +9 -0
- package/dist/{index-m9zn6cpq.js → index-5107q189.js} +12 -12
- package/dist/{index-sbdmyz75.js → index-5cc6r990.js} +3 -3
- package/dist/index-6k1svmjh.js +141 -0
- package/dist/{index-c6bxbsnc.js → index-7kxw1awn.js} +2 -2
- package/dist/{index-0r0fbk7z.js → index-7z9ym7t8.js} +28 -28
- package/dist/{index-p7hgdyhb.js → index-814xpr6d.js} +2 -2
- package/dist/{index-gtj3zc53.js → index-8kzct1d6.js} +99 -99
- package/dist/{index-1zbbzgfh.js → index-9pw0a51a.js} +4 -4
- package/dist/{index-79z7m7dt.js → index-a9pd417t.js} +35 -35
- package/dist/{index-ham5sz8m.js → index-aaj97r4y.js} +45 -45
- package/dist/{index-s812ycat.js → index-aan6hqb9.js} +3 -3
- package/dist/{index-10x2hbx0.js → index-adhgd4pe.js} +44 -44
- package/dist/{index-2gxzjvyr.js → index-afjvjyck.js} +23 -23
- package/dist/{index-qmy6zq75.js → index-ahvsksw5.js} +16 -16
- package/dist/{index-hr4tzbwq.js → index-ap3gqe56.js} +3 -3
- package/dist/{index-znfs20ss.js → index-b2bz0kdm.js} +16 -16
- package/dist/{index-r066jx76.js → index-c6aagrbd.js} +148 -120
- package/dist/{index-k30h66yd.js → index-ck71tbcf.js} +9 -9
- package/dist/{index-eqqvgdb3.js → index-ct75c3at.js} +2 -2
- package/dist/{index-gw8bmyaj.js → index-djjhhgjk.js} +41 -41
- package/dist/{index-8qt2m66q.js → index-dvwj1f43.js} +43 -43
- package/dist/{index-fhwqwxe0.js → index-ej331hah.js} +1 -1
- package/dist/{index-9t3dffv2.js → index-ewbaywk5.js} +5 -5
- package/dist/{index-7p1f0vp2.js → index-fyphpknh.js} +25 -25
- package/dist/{index-83bdg97s.js → index-g149e9pk.js} +1 -1
- package/dist/{index-ngfhvfpd.js → index-g6a3na27.js} +4 -4
- package/dist/{index-qwhynv6x.js → index-h124epcf.js} +20 -20
- package/dist/{index-h6eeys1v.js → index-h97tqqp1.js} +9 -9
- package/dist/{index-zcgf3gqf.js → index-hby4qhax.js} +10 -10
- package/dist/{index-5jrd0yng.js → index-j8aw2c0e.js} +4 -4
- package/dist/{index-d8m8zpd8.js → index-jzczzcsb.js} +14 -14
- package/dist/index-kqnd6a85.js +26 -0
- package/dist/{index-35mh5bhj.js → index-kw1ws0cs.js} +12 -12
- package/dist/{index-yw4fzmdz.js → index-kzz6rq0w.js} +28 -17
- package/dist/{index-4gcnakhx.js → index-m38ej7e5.js} +2 -2
- package/dist/{index-ndddxtyx.js → index-m79yr938.js} +19 -19
- package/dist/{index-5p2m7we1.js → index-m9fndta6.js} +11 -11
- package/dist/index-mnkk1ffz.js +150 -0
- package/dist/index-n15jny5b.js +4 -0
- package/dist/{index-2vtcmrj9.js → index-n53mswt3.js} +20 -20
- package/dist/{index-bt14acb5.js → index-n5yqxd3d.js} +21 -21
- package/dist/{index-bm5rx7n6.js → index-n9tyz8z3.js} +12 -12
- package/dist/index-nmaqxdx7.js +463 -0
- package/dist/{index-mqv3b5rh.js → index-nx6eazt0.js} +30 -30
- package/dist/{index-3z73fh2c.js → index-q0th8q0z.js} +9 -9
- package/dist/{index-v260df89.js → index-qjeggp8w.js} +20 -20
- package/dist/{index-zfrhfn82.js → index-r1z0rd9c.js} +20 -20
- package/dist/{index-wqgjfstn.js → index-r5c4fedv.js} +3 -3
- package/dist/{index-cyktc4bp.js → index-r5hsgkz5.js} +118 -118
- package/dist/{index-0b1ess5e.js → index-r7a7r7ha.js} +1 -1
- package/dist/{index-1j8pm5t0.js → index-rfkh44ss.js} +15 -15
- package/dist/index-rz3z13e9.js +47 -0
- package/dist/{index-k6gpggb9.js → index-s80awwsw.js} +35 -35
- package/dist/{index-vqr7f7v8.js → index-ssmd41kh.js} +124 -124
- package/dist/{index-ensd0r74.js → index-v14qqmys.js} +41 -41
- package/dist/{index-paz6sgdp.js → index-v4a2fjtk.js} +36 -36
- package/dist/{index-d9pk3td4.js → index-w0eqdhyd.js} +14 -14
- package/dist/{index-5qn1kx34.js → index-w575evhq.js} +29 -29
- package/dist/{index-3gye9wzb.js → index-w5s3xftz.js} +26 -26
- package/dist/{index-tm88avnj.js → index-wykebpn9.js} +3 -3
- package/dist/{index-sh3s86na.js → index-xkhk5d6g.js} +17 -17
- package/dist/{index-6k1937bx.js → index-xqhede6x.js} +4 -4
- package/dist/{index-f4fx2tza.js → index-zs4ms3th.js} +181 -181
- package/dist/{index-k5hsfc3j.js → index-zsvzhjtk.js} +1 -1
- package/dist/observability/bounded-logger.d.ts +2 -0
- package/dist/observability/bounded-logger.d.ts.map +1 -1
- package/dist/observability/sanitize.d.ts +6 -0
- package/dist/observability/sanitize.d.ts.map +1 -1
- package/dist/observability/secret-values.d.ts +25 -0
- package/dist/observability/secret-values.d.ts.map +1 -0
- package/dist/react/keyboard/hooks.d.ts +71 -0
- package/dist/react/keyboard/hooks.d.ts.map +1 -0
- package/dist/react/keyboard/layers.d.ts +98 -0
- package/dist/react/keyboard/layers.d.ts.map +1 -0
- package/dist/react/keyboard/zone.d.ts +139 -0
- package/dist/react/keyboard/zone.d.ts.map +1 -0
- package/dist/telegram/crypto.d.ts +16 -0
- package/dist/telegram/crypto.d.ts.map +1 -0
- package/dist/telegram/html/check.d.ts +26 -0
- package/dist/telegram/html/check.d.ts.map +1 -0
- package/dist/telegram/html/nodes.d.ts +70 -0
- package/dist/telegram/html/nodes.d.ts.map +1 -0
- package/dist/telegram/html/parse.d.ts +35 -0
- package/dist/telegram/html/parse.d.ts.map +1 -0
- package/dist/telegram/html/render.d.ts +39 -0
- package/dist/telegram/html/render.d.ts.map +1 -0
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/operator-channel.d.ts +36 -3
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/screens/callback-codec.d.ts +34 -0
- package/dist/telegram/screens/callback-codec.d.ts.map +1 -0
- package/dist/telegram/screens/dispatch.d.ts +22 -0
- package/dist/telegram/screens/dispatch.d.ts.map +1 -0
- package/dist/telegram/screens/display.d.ts +70 -0
- package/dist/telegram/screens/display.d.ts.map +1 -0
- package/dist/telegram/screens/execute.d.ts +57 -0
- package/dist/telegram/screens/execute.d.ts.map +1 -0
- package/dist/telegram/screens/html.d.ts +36 -0
- package/dist/telegram/screens/html.d.ts.map +1 -0
- package/dist/telegram/screens/outcome.d.ts +74 -0
- package/dist/telegram/screens/outcome.d.ts.map +1 -0
- package/dist/telegram/screens/path.d.ts +29 -0
- package/dist/telegram/screens/path.d.ts.map +1 -0
- package/dist/telegram/screens/reconcile.d.ts +67 -0
- package/dist/telegram/screens/reconcile.d.ts.map +1 -0
- package/dist/telegram/screens/registry.d.ts +23 -0
- package/dist/telegram/screens/registry.d.ts.map +1 -0
- package/dist/telegram/screens/render.d.ts +70 -0
- package/dist/telegram/screens/render.d.ts.map +1 -0
- package/dist/telegram/screens/runtime.d.ts +133 -0
- package/dist/telegram/screens/runtime.d.ts.map +1 -0
- package/dist/telegram/screens/screen-types.d.ts +130 -0
- package/dist/telegram/screens/screen-types.d.ts.map +1 -0
- package/dist/telegram/screens/screen.d.ts +138 -0
- package/dist/telegram/screens/screen.d.ts.map +1 -0
- package/dist/telegram/screens/state.d.ts +115 -0
- package/dist/telegram/screens/state.d.ts.map +1 -0
- package/dist/telegram/screens/telegram-screens.d.ts +18 -0
- package/dist/telegram/screens/telegram-screens.d.ts.map +1 -0
- package/dist/telegram/screens/test-chat-telegram.d.ts +47 -0
- package/dist/telegram/screens/test-chat-telegram.d.ts.map +1 -0
- package/dist/telegram/screens/test-chat.d.ts +66 -0
- package/dist/telegram/screens/test-chat.d.ts.map +1 -0
- package/dist/telegram/screens/view.d.ts +89 -0
- package/dist/telegram/screens/view.d.ts.map +1 -0
- package/dist/telegram/send-failure.d.ts +19 -0
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/update-intake.d.ts +78 -0
- package/dist/telegram/update-intake.d.ts.map +1 -0
- package/dist/telegram/update-store-sqlite.d.ts +26 -0
- package/dist/telegram/update-store-sqlite.d.ts.map +1 -0
- package/dist/telegram/update-store.d.ts +67 -0
- package/dist/telegram/update-store.d.ts.map +1 -0
- package/dist/telegram/webhook.d.ts +105 -0
- package/dist/telegram/webhook.d.ts.map +1 -0
- package/dist/tools/cli/args-fields.d.ts +8 -0
- package/dist/tools/cli/args-fields.d.ts.map +1 -1
- package/dist/tools/cli/args-route.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/help.d.ts.map +1 -1
- package/llms/cli.txt +8 -2
- package/llms/observability.txt +2 -1
- package/llms/react-keyboard.txt +193 -0
- package/llms/stitchkit.txt +7 -1
- package/llms/telegram-html.txt +35 -0
- package/llms/telegram-screens.txt +365 -0
- package/llms/telegram.txt +160 -4
- package/llms-full.txt +736 -8
- package/llms.txt +10 -5
- package/package.json +17 -2
- package/dist/index-2k4yrqkc.js +0 -9
- package/dist/index-crykmqkr.js +0 -26
- package/dist/index-y64k3s0h.js +0 -150
- package/dist/index-y91ry9h2.js +0 -4
- /package/dist/{index-hffjpmq9.js → index-9jfdm5tg.js} +0 -0
- /package/dist/{index-zjjyynm3.js → index-d4pa2bgs.js} +0 -0
- /package/dist/{index-rxfy4cq7.js → index-dwfv9a85.js} +0 -0
- /package/dist/{index-5jm36zv1.js → index-gfk7nrht.js} +0 -0
- /package/dist/{index-b9aefrqd.js → index-n1dqr7gf.js} +0 -0
- /package/dist/{index-q3pyb9n0.js → index-sykb5ag7.js} +0 -0
- /package/dist/{index-48ffdxgk.js → index-xhzq2qvj.js} +0 -0
- /package/dist/{index-kzfs85xp.js → index-zsarb5xp.js} +0 -0
|
@@ -1,116 +1,116 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
CheckpointRunAssistantSchema,
|
|
10
|
-
CommitRunTerminalSchema,
|
|
11
|
-
ReadAgentStoreEventsSchema,
|
|
12
|
-
RecordRunOperationSchema,
|
|
13
|
-
RecoverAgentRunSchema,
|
|
14
|
-
ReplaceCompactedRangeSchema,
|
|
15
|
-
RequestRunInterruptSchema,
|
|
16
|
-
SeedConversationInputSchema,
|
|
17
|
-
agentStoreEventDraft,
|
|
18
|
-
assistantStatus,
|
|
19
|
-
canonicalAgentJson,
|
|
20
|
-
decodeAgentConversationArchive,
|
|
21
|
-
encodeAgentConversationArchive
|
|
22
|
-
} from "./index-cyktc4bp.js";
|
|
2
|
+
AgentRecordIdSchema2,
|
|
3
|
+
AgentRecordVersionSchema2,
|
|
4
|
+
AgentMessageSchema2,
|
|
5
|
+
runStateForTerminalReason2,
|
|
6
|
+
AgentRunSchema2,
|
|
7
|
+
AgentSnapshotSchema2
|
|
8
|
+
} from "./index-8kzct1d6.js";
|
|
23
9
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
AppendAgentStoreEventSchema2,
|
|
11
|
+
ReadAgentStoreEventsSchema2,
|
|
12
|
+
AgentStoreEventPageSchema2,
|
|
13
|
+
AgentRunViewSchema2,
|
|
14
|
+
AcceptInputAndAssignRunSchema2,
|
|
15
|
+
AcquireAgentRunSchema2,
|
|
16
|
+
CheckpointRunAssistantSchema2,
|
|
17
|
+
RecordRunOperationSchema2,
|
|
18
|
+
CommitRunTerminalSchema2,
|
|
19
|
+
RequestRunInterruptSchema2,
|
|
20
|
+
RecoverAgentRunSchema2,
|
|
21
|
+
ReplaceCompactedRangeSchema2,
|
|
22
|
+
SeedConversationInputSchema2,
|
|
23
|
+
AgentRecoverablePageSchema2,
|
|
24
|
+
AgentStoreTransitionSchema2,
|
|
25
|
+
agentStoreEventDraft,
|
|
26
|
+
canonicalAgentJson2,
|
|
27
|
+
encodeAgentConversationArchive2,
|
|
28
|
+
decodeAgentConversationArchive2,
|
|
29
|
+
assistantStatus
|
|
30
|
+
} from "./index-r5hsgkz5.js";
|
|
31
31
|
|
|
32
32
|
// src/agent-runtime/purge.ts
|
|
33
33
|
import { z } from "zod";
|
|
34
|
-
var
|
|
35
|
-
conversationId:
|
|
36
|
-
expectedVersion:
|
|
34
|
+
var AgentConversationPurgeInputSchema2 = z.strictObject({
|
|
35
|
+
conversationId: AgentRecordIdSchema2,
|
|
36
|
+
expectedVersion: AgentRecordVersionSchema2.optional()
|
|
37
37
|
});
|
|
38
|
-
var
|
|
38
|
+
var AgentConversationPurgeResultSchema2 = z.discriminatedUnion("outcome", [
|
|
39
39
|
z.strictObject({ outcome: z.literal("purged") }),
|
|
40
40
|
z.strictObject({ outcome: z.literal("already_purged") }),
|
|
41
41
|
z.strictObject({ outcome: z.literal("unsupported") }),
|
|
42
42
|
z.strictObject({
|
|
43
43
|
outcome: z.literal("active"),
|
|
44
|
-
runIds: z.array(
|
|
44
|
+
runIds: z.array(AgentRecordIdSchema2).min(1)
|
|
45
45
|
}),
|
|
46
|
-
z.strictObject({ outcome: z.literal("conflict"), actualVersion:
|
|
46
|
+
z.strictObject({ outcome: z.literal("conflict"), actualVersion: AgentRecordVersionSchema2 })
|
|
47
47
|
]);
|
|
48
48
|
|
|
49
|
-
class
|
|
49
|
+
class AgentConversationPurgedError2 extends Error {
|
|
50
50
|
constructor() {
|
|
51
51
|
super("Agent conversation has been purged; use a new conversation ID");
|
|
52
52
|
this.name = "AgentConversationPurgedError";
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
async function
|
|
56
|
-
const parsed =
|
|
55
|
+
async function purgeAgentConversation2(store, input) {
|
|
56
|
+
const parsed = AgentConversationPurgeInputSchema2.parse(input);
|
|
57
57
|
if (!store.purgeConversation)
|
|
58
58
|
return { outcome: "unsupported" };
|
|
59
|
-
return
|
|
59
|
+
return AgentConversationPurgeResultSchema2.parse(await store.purgeConversation(parsed));
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// src/agent-runtime/store-driver-contract.ts
|
|
63
63
|
import { z as z2 } from "zod";
|
|
64
|
-
var
|
|
64
|
+
var AgentRuntimeHeadSchema2 = z2.object({
|
|
65
65
|
schemaVersion: z2.literal(1),
|
|
66
|
-
conversationId:
|
|
67
|
-
version:
|
|
66
|
+
conversationId: AgentRecordIdSchema2,
|
|
67
|
+
version: AgentRecordVersionSchema2
|
|
68
68
|
});
|
|
69
|
-
var
|
|
69
|
+
var AgentStoredRunSchema2 = z2.object({
|
|
70
70
|
schemaVersion: z2.literal(1),
|
|
71
|
-
run:
|
|
72
|
-
terminalAssistant:
|
|
71
|
+
run: AgentRunSchema2,
|
|
72
|
+
terminalAssistant: AgentMessageSchema2.optional()
|
|
73
73
|
});
|
|
74
|
-
var
|
|
74
|
+
var AgentAdmissionReceiptSchema2 = z2.object({
|
|
75
75
|
schemaVersion: z2.literal(1),
|
|
76
|
-
conversationId:
|
|
76
|
+
conversationId: AgentRecordIdSchema2,
|
|
77
77
|
idempotencyKey: z2.string().min(1),
|
|
78
|
-
input:
|
|
79
|
-
runId:
|
|
80
|
-
assistantMessageId:
|
|
78
|
+
input: AgentMessageSchema2,
|
|
79
|
+
runId: AgentRecordIdSchema2,
|
|
80
|
+
assistantMessageId: AgentRecordIdSchema2
|
|
81
81
|
});
|
|
82
|
-
var
|
|
82
|
+
var AgentSeedReceiptSchema2 = z2.object({
|
|
83
83
|
schemaVersion: z2.literal(1),
|
|
84
|
-
conversationId:
|
|
84
|
+
conversationId: AgentRecordIdSchema2,
|
|
85
85
|
seedKey: z2.string().min(1),
|
|
86
|
-
messageIds: z2.array(
|
|
86
|
+
messageIds: z2.array(AgentRecordIdSchema2).min(1)
|
|
87
87
|
});
|
|
88
|
-
var
|
|
89
|
-
z2.object({ type: z2.literal("admit"), input:
|
|
88
|
+
var AgentHistoryMutationSchema2 = z2.discriminatedUnion("type", [
|
|
89
|
+
z2.object({ type: z2.literal("admit"), input: AgentMessageSchema2 }),
|
|
90
90
|
z2.object({
|
|
91
91
|
type: z2.literal("upsert-assistant"),
|
|
92
|
-
message:
|
|
92
|
+
message: AgentMessageSchema2
|
|
93
93
|
}),
|
|
94
94
|
z2.object({
|
|
95
95
|
type: z2.literal("replace-compacted-range"),
|
|
96
|
-
replacedMessageIds: z2.array(
|
|
97
|
-
summary:
|
|
96
|
+
replacedMessageIds: z2.array(AgentRecordIdSchema2).min(1),
|
|
97
|
+
summary: AgentMessageSchema2
|
|
98
98
|
}),
|
|
99
99
|
z2.object({
|
|
100
100
|
type: z2.literal("seed"),
|
|
101
|
-
message:
|
|
101
|
+
message: AgentMessageSchema2
|
|
102
102
|
})
|
|
103
103
|
]);
|
|
104
|
-
var
|
|
104
|
+
var ACTIVE_AGENT_RUN_STATES2 = [
|
|
105
105
|
"queued",
|
|
106
106
|
"running",
|
|
107
107
|
"interrupt_requested"
|
|
108
108
|
];
|
|
109
109
|
function isActiveRunState(state) {
|
|
110
|
-
return
|
|
110
|
+
return ACTIVE_AGENT_RUN_STATES2.includes(state);
|
|
111
111
|
}
|
|
112
112
|
function emptyHead(conversationId) {
|
|
113
|
-
return
|
|
113
|
+
return AgentRuntimeHeadSchema2.parse({
|
|
114
114
|
schemaVersion: 1,
|
|
115
115
|
conversationId,
|
|
116
116
|
version: 0
|
|
@@ -180,7 +180,7 @@ function orderRunMessages(messages, runs) {
|
|
|
180
180
|
function snapshotOf(head, messages, records) {
|
|
181
181
|
validateSnapshot(head, messages, records);
|
|
182
182
|
const runs = orderRuns(messages, records.map((record) => record.run));
|
|
183
|
-
return
|
|
183
|
+
return AgentSnapshotSchema2.parse({
|
|
184
184
|
schemaVersion: 1,
|
|
185
185
|
conversationId: head.conversationId,
|
|
186
186
|
version: head.version,
|
|
@@ -229,7 +229,7 @@ function mergeRunRecords(...groups) {
|
|
|
229
229
|
const records = new Map;
|
|
230
230
|
for (const group of groups) {
|
|
231
231
|
for (const rawRecord of group) {
|
|
232
|
-
const record =
|
|
232
|
+
const record = AgentStoredRunSchema2.parse(rawRecord);
|
|
233
233
|
const previous = records.get(record.run.id);
|
|
234
234
|
if (previous && previous.run.assistantMessageId !== record.run.assistantMessageId) {
|
|
235
235
|
throw new TypeError("Stored agent run identity changed across normalized records");
|
|
@@ -250,7 +250,7 @@ async function snapshotIn(driver, transaction, conversationId) {
|
|
|
250
250
|
driver.history.load(transaction, conversationId),
|
|
251
251
|
driver.runs.listActive(transaction, conversationId)
|
|
252
252
|
]);
|
|
253
|
-
const head =
|
|
253
|
+
const head = AgentRuntimeHeadSchema2.parse(stored ?? emptyHead(conversationId));
|
|
254
254
|
const referencedRecords = await driver.runs.loadMany(transaction, {
|
|
255
255
|
conversationId,
|
|
256
256
|
runIds: referencedRunIds(messages)
|
|
@@ -270,12 +270,12 @@ function loadRun(driver, input) {
|
|
|
270
270
|
]);
|
|
271
271
|
if (!record)
|
|
272
272
|
return;
|
|
273
|
-
const parsed =
|
|
273
|
+
const parsed = AgentStoredRunSchema2.parse(record);
|
|
274
274
|
if (parsed.run.conversationId !== input.conversationId || parsed.run.id !== input.runId) {
|
|
275
275
|
throw new TypeError("Stored run does not match the identity it was loaded by");
|
|
276
276
|
}
|
|
277
|
-
const head =
|
|
278
|
-
return
|
|
277
|
+
const head = AgentRuntimeHeadSchema2.parse(stored ?? emptyHead(input.conversationId));
|
|
278
|
+
return AgentRunViewSchema2.parse({
|
|
279
279
|
snapshotVersion: head.version,
|
|
280
280
|
run: parsed.run,
|
|
281
281
|
...parsed.terminalAssistant && { assistant: parsed.terminalAssistant }
|
|
@@ -288,7 +288,7 @@ function listActiveRuns(driver, conversationId) {
|
|
|
288
288
|
driver.runs.listActive(transaction, conversationId),
|
|
289
289
|
driver.history.load(transaction, conversationId)
|
|
290
290
|
]);
|
|
291
|
-
const runs = records.map((record) =>
|
|
291
|
+
const runs = records.map((record) => AgentStoredRunSchema2.parse(record).run);
|
|
292
292
|
for (const run of runs) {
|
|
293
293
|
if (run.conversationId !== conversationId) {
|
|
294
294
|
throw new TypeError("Active run belongs to another conversation");
|
|
@@ -301,18 +301,18 @@ function listActiveRuns(driver, conversationId) {
|
|
|
301
301
|
}, { access: "read" });
|
|
302
302
|
}
|
|
303
303
|
function appendEvent(driver, input) {
|
|
304
|
-
const parsed =
|
|
304
|
+
const parsed = AppendAgentStoreEventSchema2.parse(input);
|
|
305
305
|
return driver.transaction((transaction) => appendEventIn(driver, transaction, parsed));
|
|
306
306
|
}
|
|
307
307
|
async function appendEventIn(driver, transaction, parsed) {
|
|
308
308
|
if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
|
|
309
|
-
throw new
|
|
309
|
+
throw new AgentConversationPurgedError2;
|
|
310
310
|
}
|
|
311
311
|
return driver.events.append(transaction, agentStoreEventDraft(parsed));
|
|
312
312
|
}
|
|
313
313
|
function readEvents(driver, input) {
|
|
314
|
-
const parsed =
|
|
315
|
-
return driver.transaction(async (transaction) =>
|
|
314
|
+
const parsed = ReadAgentStoreEventsSchema2.parse(input);
|
|
315
|
+
return driver.transaction(async (transaction) => AgentStoreEventPageSchema2.parse(await driver.events.list(transaction, parsed)), { access: "read" });
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
// src/agent-runtime/store-archive.ts
|
|
@@ -321,7 +321,7 @@ function exportConversation(driver, conversationId) {
|
|
|
321
321
|
const events = [];
|
|
322
322
|
let fromSeq;
|
|
323
323
|
do {
|
|
324
|
-
const page =
|
|
324
|
+
const page = AgentStoreEventPageSchema2.parse(await driver.events.list(transaction, ReadAgentStoreEventsSchema2.parse({
|
|
325
325
|
conversationId,
|
|
326
326
|
...fromSeq && { fromSeq },
|
|
327
327
|
limit: 1e4
|
|
@@ -334,7 +334,7 @@ function exportConversation(driver, conversationId) {
|
|
|
334
334
|
spills: []
|
|
335
335
|
};
|
|
336
336
|
const snapshot = await snapshotIn(driver, transaction, conversationId);
|
|
337
|
-
return
|
|
337
|
+
return encodeAgentConversationArchive2({
|
|
338
338
|
format: "stitchkit.agent-conversation",
|
|
339
339
|
formatVersion: 1,
|
|
340
340
|
conversationId,
|
|
@@ -348,7 +348,7 @@ function exportConversation(driver, conversationId) {
|
|
|
348
348
|
}, { access: "read" });
|
|
349
349
|
}
|
|
350
350
|
async function importConversation(driver, bytes) {
|
|
351
|
-
const archive =
|
|
351
|
+
const archive = decodeAgentConversationArchive2(bytes);
|
|
352
352
|
return driver.transaction(async (transaction) => {
|
|
353
353
|
const existing = await driver.events.list(transaction, {
|
|
354
354
|
conversationId: archive.conversationId,
|
|
@@ -373,7 +373,7 @@ async function importConversation(driver, bytes) {
|
|
|
373
373
|
}
|
|
374
374
|
const snapshotEntry = archive.projections.find((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry) && entry.archiveType === "runtime-snapshot");
|
|
375
375
|
if (snapshotEntry && typeof snapshotEntry === "object" && !Array.isArray(snapshotEntry)) {
|
|
376
|
-
const snapshot =
|
|
376
|
+
const snapshot = AgentSnapshotSchema2.parse(snapshotEntry.snapshot);
|
|
377
377
|
if (snapshot.conversationId !== archive.conversationId) {
|
|
378
378
|
throw new TypeError("Conversation archive snapshot belongs to another conversation");
|
|
379
379
|
}
|
|
@@ -381,7 +381,7 @@ async function importConversation(driver, bytes) {
|
|
|
381
381
|
const outcome = await driver.head.compareAndSwap(transaction, {
|
|
382
382
|
conversationId: snapshot.conversationId,
|
|
383
383
|
expectedVersion: 0,
|
|
384
|
-
next:
|
|
384
|
+
next: AgentRuntimeHeadSchema2.parse({
|
|
385
385
|
schemaVersion: 1,
|
|
386
386
|
conversationId: snapshot.conversationId,
|
|
387
387
|
version: snapshot.version
|
|
@@ -393,7 +393,7 @@ async function importConversation(driver, bytes) {
|
|
|
393
393
|
}
|
|
394
394
|
for (const run of snapshot.runs) {
|
|
395
395
|
const terminalAssistant = snapshot.messages.find((message) => message.id === run.assistantMessageId);
|
|
396
|
-
await driver.runs.save(transaction,
|
|
396
|
+
await driver.runs.save(transaction, AgentStoredRunSchema2.parse({
|
|
397
397
|
schemaVersion: 1,
|
|
398
398
|
run,
|
|
399
399
|
...terminalAssistant && { terminalAssistant }
|
|
@@ -405,14 +405,14 @@ async function importConversation(driver, bytes) {
|
|
|
405
405
|
for (const event of archive.events) {
|
|
406
406
|
if (event.kind !== "runtime/transition")
|
|
407
407
|
continue;
|
|
408
|
-
const transition =
|
|
408
|
+
const transition = AgentStoreTransitionSchema2.parse(event.payload);
|
|
409
409
|
if (transition.type !== "accept")
|
|
410
410
|
continue;
|
|
411
411
|
const assigned = snapshot.runs.find((run) => run.inputMessageIds.includes(transition.input.input.id));
|
|
412
412
|
if (!assigned) {
|
|
413
413
|
throw new TypeError("Conversation archive admission has no assigned run");
|
|
414
414
|
}
|
|
415
|
-
await driver.admissions.create(transaction,
|
|
415
|
+
await driver.admissions.create(transaction, AgentAdmissionReceiptSchema2.parse({
|
|
416
416
|
schemaVersion: 1,
|
|
417
417
|
conversationId: archive.conversationId,
|
|
418
418
|
idempotencyKey: transition.input.idempotencyKey,
|
|
@@ -452,11 +452,11 @@ async function findEvent(driver, transaction, conversationId, eventId) {
|
|
|
452
452
|
return;
|
|
453
453
|
}
|
|
454
454
|
function appendEventOnce(driver, input, key) {
|
|
455
|
-
const parsed =
|
|
455
|
+
const parsed = AppendAgentStoreEventSchema2.parse(input);
|
|
456
456
|
const eventId = eventOnceId(parsed.conversationId, parsed.kind, key);
|
|
457
457
|
return driver.transaction(async (transaction) => {
|
|
458
458
|
if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
|
|
459
|
-
throw new
|
|
459
|
+
throw new AgentConversationPurgedError2;
|
|
460
460
|
}
|
|
461
461
|
const previous = await findEvent(driver, transaction, parsed.conversationId, eventId);
|
|
462
462
|
if (previous)
|
|
@@ -485,7 +485,7 @@ function applied(current, input, effects) {
|
|
|
485
485
|
const messages = input.messages ?? current.messages;
|
|
486
486
|
return {
|
|
487
487
|
outcome: "applied",
|
|
488
|
-
snapshot:
|
|
488
|
+
snapshot: AgentSnapshotSchema2.parse({
|
|
489
489
|
...current,
|
|
490
490
|
version: current.version + 1,
|
|
491
491
|
runs,
|
|
@@ -513,13 +513,13 @@ function reduceAccept(current, input) {
|
|
|
513
513
|
if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" && input.input.role !== "tool" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
|
|
514
514
|
throw new TypeError("Input and queued run do not form one valid assignment");
|
|
515
515
|
}
|
|
516
|
-
const assignedRun = coalescedRun ?
|
|
516
|
+
const assignedRun = coalescedRun ? AgentRunSchema2.parse({
|
|
517
517
|
...coalescedRun,
|
|
518
518
|
inputMessageIds: [...coalescedRun.inputMessageIds, input.input.id],
|
|
519
519
|
revision: coalescedRun.revision + 1,
|
|
520
520
|
updatedAt: new Date().toISOString()
|
|
521
521
|
}) : input.run;
|
|
522
|
-
const admissionReceipt =
|
|
522
|
+
const admissionReceipt = AgentAdmissionReceiptSchema2.parse({
|
|
523
523
|
schemaVersion: 1,
|
|
524
524
|
conversationId: input.input.conversationId,
|
|
525
525
|
idempotencyKey: input.idempotencyKey,
|
|
@@ -531,7 +531,7 @@ function reduceAccept(current, input) {
|
|
|
531
531
|
messages: [...current.messages, input.input],
|
|
532
532
|
runs: coalescedRun ? replaceRun(current.runs, assignedRun) : [...current.runs, assignedRun]
|
|
533
533
|
}, {
|
|
534
|
-
runRecords: [
|
|
534
|
+
runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: assignedRun })],
|
|
535
535
|
admissionReceipt,
|
|
536
536
|
historyMutations: [{ type: "admit", input: input.input }]
|
|
537
537
|
});
|
|
@@ -546,7 +546,7 @@ function reduceSeed(current, input) {
|
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
548
|
return applied(current, { messages: [...input.inputs, ...current.messages] }, {
|
|
549
|
-
seedReceipt:
|
|
549
|
+
seedReceipt: AgentSeedReceiptSchema2.parse({
|
|
550
550
|
schemaVersion: 1,
|
|
551
551
|
conversationId,
|
|
552
552
|
seedKey: input.seedKey,
|
|
@@ -599,7 +599,7 @@ function reduceAcquire(current, run, input) {
|
|
|
599
599
|
if (run.revision !== input.expectedRevision || run.state !== "queued" || acquisitionBlocked) {
|
|
600
600
|
return conflict(run.revision);
|
|
601
601
|
}
|
|
602
|
-
const next =
|
|
602
|
+
const next = AgentRunSchema2.parse({
|
|
603
603
|
...run,
|
|
604
604
|
state: "running",
|
|
605
605
|
executionSequence: run.executionSequence ?? current.version + 1,
|
|
@@ -609,14 +609,14 @@ function reduceAcquire(current, run, input) {
|
|
|
609
609
|
updatedAt: new Date().toISOString()
|
|
610
610
|
});
|
|
611
611
|
return applied(current, { runs: replaceRun(current.runs, next) }, {
|
|
612
|
-
runRecords: [
|
|
612
|
+
runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: next })]
|
|
613
613
|
});
|
|
614
614
|
}
|
|
615
615
|
function reduceCheckpoint(current, run, input) {
|
|
616
616
|
if (run.revision !== input.expectedRevision || run.state !== "running" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken || input.assistant.runId !== run.id || input.assistant.id !== run.assistantMessageId || input.assistant.conversationId !== run.conversationId || input.assistant.role !== "assistant" || input.assistant.status !== "streaming") {
|
|
617
617
|
return conflict(run.revision);
|
|
618
618
|
}
|
|
619
|
-
const next =
|
|
619
|
+
const next = AgentRunSchema2.parse({
|
|
620
620
|
...run,
|
|
621
621
|
...input.usage && { usage: input.usage },
|
|
622
622
|
revision: run.revision + 1,
|
|
@@ -626,7 +626,7 @@ function reduceCheckpoint(current, run, input) {
|
|
|
626
626
|
runs: replaceRun(current.runs, next),
|
|
627
627
|
messages: replaceMessage(current.messages, input.assistant)
|
|
628
628
|
}, {
|
|
629
|
-
runRecords: [
|
|
629
|
+
runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: next })],
|
|
630
630
|
historyMutations: [{ type: "upsert-assistant", message: input.assistant }]
|
|
631
631
|
});
|
|
632
632
|
}
|
|
@@ -634,26 +634,26 @@ function reduceOperation(current, run, input) {
|
|
|
634
634
|
if (run.revision !== input.expectedRevision || run.state !== "running" && run.state !== "interrupt_requested" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken) {
|
|
635
635
|
return conflict(run.revision);
|
|
636
636
|
}
|
|
637
|
-
const next =
|
|
637
|
+
const next = AgentRunSchema2.parse({
|
|
638
638
|
...run,
|
|
639
639
|
lastOperation: input.operation,
|
|
640
640
|
revision: run.revision + 1,
|
|
641
641
|
updatedAt: new Date().toISOString()
|
|
642
642
|
});
|
|
643
|
-
return applied(current, { runs: replaceRun(current.runs, next) }, { runRecords: [
|
|
643
|
+
return applied(current, { runs: replaceRun(current.runs, next) }, { runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: next })] });
|
|
644
644
|
}
|
|
645
645
|
function reduceInterrupt(current, run, input) {
|
|
646
646
|
if (run.revision !== input.expectedRevision || run.state !== "running") {
|
|
647
647
|
return conflict(run.revision);
|
|
648
648
|
}
|
|
649
|
-
const next =
|
|
649
|
+
const next = AgentRunSchema2.parse({
|
|
650
650
|
...run,
|
|
651
651
|
state: "interrupt_requested",
|
|
652
652
|
revision: run.revision + 1,
|
|
653
653
|
updatedAt: new Date().toISOString()
|
|
654
654
|
});
|
|
655
655
|
return applied(current, { runs: replaceRun(current.runs, next) }, {
|
|
656
|
-
runRecords: [
|
|
656
|
+
runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: next })]
|
|
657
657
|
});
|
|
658
658
|
}
|
|
659
659
|
function reduceRecover(current, run, input) {
|
|
@@ -664,7 +664,7 @@ function reduceRecover(current, run, input) {
|
|
|
664
664
|
throw new TypeError("Recovering an acquired run requires explicit replaySafe evidence");
|
|
665
665
|
}
|
|
666
666
|
const { ownerId: _released, ...carried } = run;
|
|
667
|
-
const next =
|
|
667
|
+
const next = AgentRunSchema2.parse({
|
|
668
668
|
...carried,
|
|
669
669
|
state: input.action === "requeue" ? "queued" : "abandoned",
|
|
670
670
|
revision: run.revision + 1,
|
|
@@ -673,7 +673,7 @@ function reduceRecover(current, run, input) {
|
|
|
673
673
|
});
|
|
674
674
|
if (input.action === "abandon") {
|
|
675
675
|
const existingAssistant = current.messages.find((message) => message.id === run.assistantMessageId);
|
|
676
|
-
const assistant =
|
|
676
|
+
const assistant = AgentMessageSchema2.parse({
|
|
677
677
|
...existingAssistant ?? {
|
|
678
678
|
schemaVersion: 1,
|
|
679
679
|
id: run.assistantMessageId,
|
|
@@ -691,7 +691,7 @@ function reduceRecover(current, run, input) {
|
|
|
691
691
|
messages: replaceMessage(current.messages, assistant)
|
|
692
692
|
}, {
|
|
693
693
|
runRecords: [
|
|
694
|
-
|
|
694
|
+
AgentStoredRunSchema2.parse({
|
|
695
695
|
schemaVersion: 1,
|
|
696
696
|
run: next,
|
|
697
697
|
terminalAssistant: assistant
|
|
@@ -701,7 +701,7 @@ function reduceRecover(current, run, input) {
|
|
|
701
701
|
});
|
|
702
702
|
}
|
|
703
703
|
return applied(current, { runs: replaceRun(current.runs, next) }, {
|
|
704
|
-
runRecords: [
|
|
704
|
+
runRecords: [AgentStoredRunSchema2.parse({ schemaVersion: 1, run: next })]
|
|
705
705
|
});
|
|
706
706
|
}
|
|
707
707
|
|
|
@@ -713,7 +713,7 @@ function reduceTerminal(current, run, input) {
|
|
|
713
713
|
if (run.revision !== input.expectedRevision || run.state !== "running" && run.state !== "interrupt_requested" || run.ownerId !== input.ownerId || input.fencingToken !== undefined && run.fencingToken !== input.fencingToken || input.assistant.runId !== run.id || input.assistant.id !== run.assistantMessageId || input.assistant.conversationId !== run.conversationId || input.assistant.role !== "assistant" || input.assistant.status !== assistantStatus(input.reason)) {
|
|
714
714
|
return conflict(run.revision);
|
|
715
715
|
}
|
|
716
|
-
if (input.absorb &&
|
|
716
|
+
if (input.absorb && runStateForTerminalReason2(input.reason) !== "completed") {
|
|
717
717
|
throw new TypeError("Only a completing run may absorb a queued successor");
|
|
718
718
|
}
|
|
719
719
|
const named = new Set((input.absorb ?? []).map((entry) => entry.runId));
|
|
@@ -725,9 +725,9 @@ function reduceTerminal(current, run, input) {
|
|
|
725
725
|
return candidate !== undefined && candidate.id !== run.id && candidate.state === "queued" && candidate.conversationId === run.conversationId && candidate.inputMessageIds.length === entry.inputMessageIds.length && candidate.inputMessageIds.every((id, index) => id === entry.inputMessageIds[index]);
|
|
726
726
|
});
|
|
727
727
|
const absorbedIds = new Set(absorbable.flatMap((entry) => entry.inputMessageIds));
|
|
728
|
-
const next =
|
|
728
|
+
const next = AgentRunSchema2.parse({
|
|
729
729
|
...run,
|
|
730
|
-
state:
|
|
730
|
+
state: runStateForTerminalReason2(input.reason),
|
|
731
731
|
terminalReason: input.reason,
|
|
732
732
|
...input.policyName && { terminalPolicyName: input.policyName },
|
|
733
733
|
...input.usage && { usage: input.usage },
|
|
@@ -744,9 +744,9 @@ function reduceTerminal(current, run, input) {
|
|
|
744
744
|
const candidate = current.runs.find((item) => item.id === entry.runId);
|
|
745
745
|
if (!candidate)
|
|
746
746
|
throw new TypeError("Absorbed run disappeared inside the reducer");
|
|
747
|
-
return
|
|
747
|
+
return AgentRunSchema2.parse({
|
|
748
748
|
...candidate,
|
|
749
|
-
state:
|
|
749
|
+
state: runStateForTerminalReason2("absorbed"),
|
|
750
750
|
terminalReason: "absorbed",
|
|
751
751
|
absorbedIntoRunId: next.id,
|
|
752
752
|
revision: candidate.revision + 1,
|
|
@@ -759,12 +759,12 @@ function reduceTerminal(current, run, input) {
|
|
|
759
759
|
messages: replaceMessage(current.messages, input.assistant)
|
|
760
760
|
}, {
|
|
761
761
|
runRecords: [
|
|
762
|
-
|
|
762
|
+
AgentStoredRunSchema2.parse({
|
|
763
763
|
schemaVersion: 1,
|
|
764
764
|
run: next,
|
|
765
765
|
terminalAssistant: input.assistant
|
|
766
766
|
}),
|
|
767
|
-
...absorbedRuns.map((absorbed) =>
|
|
767
|
+
...absorbedRuns.map((absorbed) => AgentStoredRunSchema2.parse({ schemaVersion: 1, run: absorbed }))
|
|
768
768
|
],
|
|
769
769
|
historyMutations: [{ type: "upsert-assistant", message: input.assistant }]
|
|
770
770
|
});
|
|
@@ -775,7 +775,7 @@ function transitionRecord(operation) {
|
|
|
775
775
|
if (operation.type !== "checkpoint")
|
|
776
776
|
return operation;
|
|
777
777
|
const { assistant, ...rest } = operation.input;
|
|
778
|
-
const body =
|
|
778
|
+
const body = canonicalAgentJson2(assistant);
|
|
779
779
|
return {
|
|
780
780
|
type: operation.type,
|
|
781
781
|
input: {
|
|
@@ -830,7 +830,7 @@ function validateAdmissionReceipt(receipt, record, conversationId) {
|
|
|
830
830
|
async function readForMutation(driver, transaction, operation) {
|
|
831
831
|
const conversationId = operationConversationId(operation);
|
|
832
832
|
if (await driver.conversations?.isPurged(transaction, conversationId)) {
|
|
833
|
-
throw new
|
|
833
|
+
throw new AgentConversationPurgedError2;
|
|
834
834
|
}
|
|
835
835
|
const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" || operation.type === "seed" ? undefined : operation.input.runId;
|
|
836
836
|
const [stored, messages, activeRecords, operationRecord, duplicateReceipt] = await Promise.all([
|
|
@@ -843,7 +843,7 @@ async function readForMutation(driver, transaction, operation) {
|
|
|
843
843
|
idempotencyKey: operation.input.idempotencyKey
|
|
844
844
|
}) : undefined
|
|
845
845
|
]);
|
|
846
|
-
const head =
|
|
846
|
+
const head = AgentRuntimeHeadSchema2.parse(stored ?? emptyHead(conversationId));
|
|
847
847
|
const referencedRecords = await driver.runs.loadMany(transaction, {
|
|
848
848
|
conversationId,
|
|
849
849
|
runIds: referencedRunIds(messages)
|
|
@@ -872,7 +872,7 @@ async function settledSeed(driver, transaction, read, input) {
|
|
|
872
872
|
throw new TypeError("Partial instruction seed collision: restore the complete seed before retrying");
|
|
873
873
|
}
|
|
874
874
|
if (collisions > 0) {
|
|
875
|
-
await driver.seeds.create(transaction,
|
|
875
|
+
await driver.seeds.create(transaction, AgentSeedReceiptSchema2.parse({
|
|
876
876
|
schemaVersion: 1,
|
|
877
877
|
conversationId,
|
|
878
878
|
seedKey: input.seedKey,
|
|
@@ -939,7 +939,7 @@ async function assertAdmissionIdentitiesFree(driver, transaction, conversationId
|
|
|
939
939
|
}
|
|
940
940
|
async function persistApplied(driver, transaction, read, operation, reduced) {
|
|
941
941
|
const { conversationId, current } = read;
|
|
942
|
-
const nextHead =
|
|
942
|
+
const nextHead = AgentRuntimeHeadSchema2.parse({
|
|
943
943
|
schemaVersion: 1,
|
|
944
944
|
conversationId,
|
|
945
945
|
version: reduced.snapshot.version
|
|
@@ -994,7 +994,7 @@ function mutateStore(driver, operation) {
|
|
|
994
994
|
// src/agent-runtime/store-purge.ts
|
|
995
995
|
function createStoreConversationPurge(driver, conversations) {
|
|
996
996
|
return async (input) => {
|
|
997
|
-
const { conversationId, expectedVersion } =
|
|
997
|
+
const { conversationId, expectedVersion } = AgentConversationPurgeInputSchema2.parse(input);
|
|
998
998
|
return driver.transaction(async (transaction) => {
|
|
999
999
|
if (await conversations.isPurged(transaction, conversationId)) {
|
|
1000
1000
|
return { outcome: "already_purged" };
|
|
@@ -1019,7 +1019,7 @@ var AgentRecoverableScanInputSchema = z5.object({
|
|
|
1019
1019
|
cursor: z5.string().min(1).optional(),
|
|
1020
1020
|
limit: z5.number().int().min(1).max(1000)
|
|
1021
1021
|
});
|
|
1022
|
-
function
|
|
1022
|
+
function createAgentRuntimeStore2(driver) {
|
|
1023
1023
|
const mutate = (operation) => mutateStore(driver, operation);
|
|
1024
1024
|
return {
|
|
1025
1025
|
loadSnapshot: (conversationId) => loadSnapshot(driver, conversationId),
|
|
@@ -1036,36 +1036,36 @@ function createAgentRuntimeStore(driver) {
|
|
|
1036
1036
|
},
|
|
1037
1037
|
acceptInputAndAssignRun: (input) => mutate({
|
|
1038
1038
|
type: "accept",
|
|
1039
|
-
input:
|
|
1039
|
+
input: AcceptInputAndAssignRunSchema2.parse(input)
|
|
1040
1040
|
}),
|
|
1041
|
-
acquireRun: (input) => mutate({ type: "acquire", input:
|
|
1041
|
+
acquireRun: (input) => mutate({ type: "acquire", input: AcquireAgentRunSchema2.parse(input) }),
|
|
1042
1042
|
checkpointRunAssistant: (input) => mutate({
|
|
1043
1043
|
type: "checkpoint",
|
|
1044
|
-
input:
|
|
1044
|
+
input: CheckpointRunAssistantSchema2.parse(input)
|
|
1045
1045
|
}),
|
|
1046
1046
|
recordRunOperation: (input) => mutate({
|
|
1047
1047
|
type: "operation",
|
|
1048
|
-
input:
|
|
1048
|
+
input: RecordRunOperationSchema2.parse(input)
|
|
1049
1049
|
}),
|
|
1050
1050
|
requestRunInterrupt: (input) => mutate({
|
|
1051
1051
|
type: "interrupt",
|
|
1052
|
-
input:
|
|
1052
|
+
input: RequestRunInterruptSchema2.parse(input)
|
|
1053
1053
|
}),
|
|
1054
|
-
recoverRun: (input) => mutate({ type: "recover", input:
|
|
1055
|
-
commitRunTerminal: (input) => mutate({ type: "terminal", input:
|
|
1054
|
+
recoverRun: (input) => mutate({ type: "recover", input: RecoverAgentRunSchema2.parse(input) }),
|
|
1055
|
+
commitRunTerminal: (input) => mutate({ type: "terminal", input: CommitRunTerminalSchema2.parse(input) }),
|
|
1056
1056
|
replaceCompactedRange: (input) => mutate({
|
|
1057
1057
|
type: "compact",
|
|
1058
|
-
input:
|
|
1058
|
+
input: ReplaceCompactedRangeSchema2.parse(input)
|
|
1059
1059
|
}),
|
|
1060
1060
|
seedConversationInput: (input) => mutate({
|
|
1061
1061
|
type: "seed",
|
|
1062
|
-
input:
|
|
1062
|
+
input: SeedConversationInputSchema2.parse(input)
|
|
1063
1063
|
}),
|
|
1064
1064
|
async scanRecoverable(input) {
|
|
1065
1065
|
const parsed = AgentRecoverableScanInputSchema.parse(input);
|
|
1066
|
-
return
|
|
1066
|
+
return AgentRecoverablePageSchema2.parse(await driver.scanRecoverable(parsed));
|
|
1067
1067
|
}
|
|
1068
1068
|
};
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
1071
|
-
export {
|
|
1071
|
+
export { AgentConversationPurgeInputSchema2, AgentConversationPurgeResultSchema2, AgentConversationPurgedError2, purgeAgentConversation2, AgentRuntimeHeadSchema2, AgentStoredRunSchema2, AgentAdmissionReceiptSchema2, AgentSeedReceiptSchema2, AgentHistoryMutationSchema2, ACTIVE_AGENT_RUN_STATES2, isActiveRunState, replaceMessage, appendEventIn, createAgentRuntimeStore2 };
|