stitchkit 0.100.2 → 0.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +153 -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 +209 -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 +116 -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 +11 -3
- package/dist/entrypoints/telegram.d.ts.map +1 -1
- package/dist/entrypoints/telegram.js +779 -159
- 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 +224 -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-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-e05cjgtf.js +144 -0
- package/dist/{index-yw4fzmdz.js → index-e6c2spsd.js} +79 -30
- 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-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-sznqf8fx.js +20 -0
- 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/internal/secret-shapes.d.ts +21 -0
- package/dist/internal/secret-shapes.d.ts.map +1 -0
- 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/bot-api.d.ts +7 -4
- package/dist/telegram/bot-api.d.ts.map +1 -1
- 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 +3 -44
- package/dist/telegram/init-data.d.ts.map +1 -1
- package/dist/telegram/operator-channel.d.ts +19 -3
- package/dist/telegram/operator-channel.d.ts.map +1 -1
- package/dist/telegram/operator-dedupe.d.ts +44 -0
- package/dist/telegram/operator-dedupe.d.ts.map +1 -0
- 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 +25 -0
- package/dist/telegram/send-failure.d.ts.map +1 -1
- package/dist/telegram/update-intake.d.ts +82 -0
- package/dist/telegram/update-intake.d.ts.map +1 -0
- package/dist/telegram/update-store-check.d.ts +22 -0
- package/dist/telegram/update-store-check.d.ts.map +1 -0
- package/dist/telegram/update-store-postgres.d.ts +33 -0
- package/dist/telegram/update-store-postgres.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/user.d.ts +51 -0
- package/dist/telegram/user.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 +15 -2
- package/llms/react-keyboard.txt +193 -0
- package/llms/server.4.txt +16 -0
- package/llms/stitchkit.txt +10 -4
- package/llms/telegram-html.txt +35 -0
- package/llms/telegram-screens.txt +365 -0
- package/llms/telegram.txt +245 -11
- package/llms/{upgrading-0.74.0-0.100.0.txt → upgrading-0.74.0-0.101.0.txt} +39 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +889 -19
- package/llms.txt +12 -7
- 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,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
projectRuntimeTool
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-7z9ym7t8.js";
|
|
4
4
|
|
|
5
5
|
// src/tools/runtime-tool.ts
|
|
6
|
-
function
|
|
6
|
+
function defineRuntimeTool2(definition) {
|
|
7
7
|
if (definition.transports?.length === 0) {
|
|
8
8
|
throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
|
|
9
9
|
}
|
|
10
10
|
return definition;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function createRuntimeToolFactory2(config) {
|
|
13
13
|
function parseContext(context) {
|
|
14
14
|
const parsed = config.context.parse(context);
|
|
15
15
|
return {
|
|
@@ -22,18 +22,18 @@ function createRuntimeToolFactory(config) {
|
|
|
22
22
|
}
|
|
23
23
|
function define(definition) {
|
|
24
24
|
if (definition.output !== undefined) {
|
|
25
|
-
const { action
|
|
26
|
-
const
|
|
25
|
+
const { action, method, meta, handler, ...tool } = definition;
|
|
26
|
+
const identity = {
|
|
27
27
|
serviceName: config.serviceName,
|
|
28
|
-
action
|
|
29
|
-
method
|
|
28
|
+
action,
|
|
29
|
+
method,
|
|
30
30
|
...config.scope !== undefined && { scope: config.scope },
|
|
31
|
-
...(
|
|
31
|
+
...(meta ?? config.meta) !== undefined && { meta: meta ?? config.meta }
|
|
32
32
|
};
|
|
33
|
-
return
|
|
34
|
-
...
|
|
35
|
-
identity
|
|
36
|
-
handler: (context) =>
|
|
33
|
+
return defineRuntimeTool2({
|
|
34
|
+
...tool,
|
|
35
|
+
identity,
|
|
36
|
+
handler: (context) => handler(parseContext(context))
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
const { action, method, meta, handler, ...tool } = definition;
|
|
@@ -44,7 +44,7 @@ function createRuntimeToolFactory(config) {
|
|
|
44
44
|
...config.scope !== undefined && { scope: config.scope },
|
|
45
45
|
...(meta ?? config.meta) !== undefined && { meta: meta ?? config.meta }
|
|
46
46
|
};
|
|
47
|
-
return
|
|
47
|
+
return defineRuntimeTool2({
|
|
48
48
|
...tool,
|
|
49
49
|
identity,
|
|
50
50
|
handler: (context) => handler(parseContext(context))
|
|
@@ -97,4 +97,4 @@ function executableAgentRuntimeTools(tools) {
|
|
|
97
97
|
return tools;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export {
|
|
100
|
+
export { defineRuntimeTool2, createRuntimeToolFactory2, runtimeToolMountable, executableAgentRuntimeTools };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentRecordIdSchema2,
|
|
3
|
+
AgentRecordVersionSchema2,
|
|
4
|
+
AgentMessageSchema2
|
|
5
|
+
} from "./index-8kzct1d6.js";
|
|
6
|
+
|
|
7
|
+
// src/agent-runtime/conversations.ts
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var AgentConversationSummarySchema2 = z.object({
|
|
10
|
+
conversationId: AgentRecordIdSchema2,
|
|
11
|
+
version: AgentRecordVersionSchema2,
|
|
12
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
13
|
+
preview: z.string(),
|
|
14
|
+
activeRuns: z.int().nonnegative()
|
|
15
|
+
}).strict();
|
|
16
|
+
var AgentConversationPageSchema2 = z.object({
|
|
17
|
+
items: z.array(AgentConversationSummarySchema2),
|
|
18
|
+
nextCursor: z.string().min(1).optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
var AgentConversationMessagePageSchema2 = z.object({
|
|
21
|
+
items: z.array(AgentMessageSchema2),
|
|
22
|
+
compacted: z.array(z.string().min(1)),
|
|
23
|
+
nextCursor: z.string().min(1).optional()
|
|
24
|
+
}).strict();
|
|
25
|
+
|
|
26
|
+
export { AgentConversationSummarySchema2, AgentConversationPageSchema2, AgentConversationMessagePageSchema2 };
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isUnsafeKey
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-zsarb5xp.js";
|
|
4
4
|
import {
|
|
5
5
|
isRecord
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-9jfdm5tg.js";
|
|
7
7
|
|
|
8
8
|
// src/internal/request.ts
|
|
9
|
-
function
|
|
9
|
+
function generateTraceId2() {
|
|
10
10
|
return `${Date.now().toString(36)}-${crypto.randomUUID().slice(0, 8)}`;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function resolveTraceId2(req) {
|
|
13
13
|
const header = req.headers.get("x-request-id") ?? req.headers.get("x-trace-id");
|
|
14
14
|
const trimmed = header?.trim();
|
|
15
15
|
if (trimmed && trimmed.length <= 128 && /^[\w.-]+$/.test(trimmed)) {
|
|
16
16
|
return trimmed;
|
|
17
17
|
}
|
|
18
|
-
return
|
|
18
|
+
return generateTraceId2();
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function resolveSocketIp2(req, server) {
|
|
21
21
|
if (typeof server === "object" && server !== null && "requestIP" in server && typeof server.requestIP === "function") {
|
|
22
22
|
const addr = server.requestIP(req);
|
|
23
23
|
if (isRecord(addr) && typeof addr.address === "string" && addr.address) {
|
|
@@ -28,7 +28,7 @@ function resolveSocketIp(req, server) {
|
|
|
28
28
|
return req.ip;
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function extractIp2(req, options = {}) {
|
|
32
32
|
if (options.trustProxy) {
|
|
33
33
|
const forwarded = req.headers.get("x-forwarded-for");
|
|
34
34
|
if (forwarded)
|
|
@@ -39,9 +39,9 @@ function extractIp(req, options = {}) {
|
|
|
39
39
|
}
|
|
40
40
|
return (options.socketIp ?? "").replace(/^::ffff:/, "");
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function getClientInfo2(req, options = {}) {
|
|
43
43
|
return {
|
|
44
|
-
ipAddress:
|
|
44
|
+
ipAddress: extractIp2(req, options) || undefined,
|
|
45
45
|
userAgent: req.headers.get("user-agent") ?? undefined
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -145,7 +145,7 @@ function hasPrefix(bytes, prefix, bits) {
|
|
|
145
145
|
}
|
|
146
146
|
return true;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
148
|
+
function isPublicIp2(value) {
|
|
149
149
|
const address = value.trim();
|
|
150
150
|
if (!address)
|
|
151
151
|
return false;
|
|
@@ -163,7 +163,7 @@ function isPublicIp(value) {
|
|
|
163
163
|
if (!bytes)
|
|
164
164
|
return false;
|
|
165
165
|
if (hasPrefix(bytes, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255], 96)) {
|
|
166
|
-
return
|
|
166
|
+
return isPublicIp2(Array.from(bytes.slice(12)).join("."));
|
|
167
167
|
}
|
|
168
168
|
if (!hasPrefix(bytes, [32], 3))
|
|
169
169
|
return false;
|
|
@@ -174,4 +174,4 @@ function isPublicIp(value) {
|
|
|
174
174
|
return true;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
export {
|
|
177
|
+
export { generateTraceId2, resolveTraceId2, resolveSocketIp2, extractIp2, getClientInfo2, parseQueryParams, isPublicIp2 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isUnsafeKey
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-zsarb5xp.js";
|
|
4
4
|
|
|
5
5
|
// src/internal/route-pattern.ts
|
|
6
6
|
import { z } from "zod";
|
|
@@ -79,4 +79,4 @@ function parseTrailingWildcard(path) {
|
|
|
79
79
|
return wildcard ? { name: wildcard.name, segmentIndex: wildcard.segmentIndex } : null;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export { joinRoutePath, resolveRouteParamsSchema, parseTrailingWildcard };
|
|
82
|
+
export { joinRoutePath, parseRoutePattern, resolveRouteParamsSchema, parseTrailingWildcard };
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./index-dce5wxcq.js";
|
|
2
|
+
AppError2
|
|
3
|
+
} from "./index-n53mswt3.js";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
RealtimeRequestInvalidAcknowledgementError2,
|
|
6
|
+
RealtimeRequestRejectedError2
|
|
7
|
+
} from "./index-4s0fep5q.js";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
} from "./index-
|
|
9
|
+
zodIssues2
|
|
10
|
+
} from "./index-1eeqpadm.js";
|
|
11
11
|
|
|
12
12
|
// src/realtime/rejected-frame.ts
|
|
13
|
-
var
|
|
13
|
+
var REALTIME_REJECTION_KEY2 = "@stitchkit/realtime-rejected";
|
|
14
14
|
var MAX_REJECTION_ISSUES = 20;
|
|
15
15
|
function realtimeRejectionEnvelope(report) {
|
|
16
|
-
return { [
|
|
16
|
+
return { [REALTIME_REJECTION_KEY2]: report };
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function asRealtimeRejection2(value) {
|
|
19
19
|
if (typeof value !== "object" || value === null)
|
|
20
20
|
return null;
|
|
21
|
-
const report = Reflect.get(value,
|
|
21
|
+
const report = Reflect.get(value, REALTIME_REJECTION_KEY2);
|
|
22
22
|
if (typeof report !== "object" || report === null)
|
|
23
23
|
return null;
|
|
24
24
|
const event = Reflect.get(report, "event");
|
|
@@ -58,9 +58,9 @@ function parseIssues(value) {
|
|
|
58
58
|
// src/realtime/rejection.ts
|
|
59
59
|
import { z } from "zod";
|
|
60
60
|
function realtimeContractViolation(options) {
|
|
61
|
-
const issues = options.cause instanceof z.ZodError ?
|
|
61
|
+
const issues = options.cause instanceof z.ZodError ? zodIssues2(options.cause) : undefined;
|
|
62
62
|
const reason = options.reason.replaceAll("-", " ");
|
|
63
|
-
const error = new
|
|
63
|
+
const error = new AppError2("REALTIME_CONTRACT_VIOLATION", `Realtime event "${options.event}" (${options.direction}, ${options.phase}): ${reason}`, 500, {
|
|
64
64
|
event: options.event,
|
|
65
65
|
direction: options.direction,
|
|
66
66
|
phase: options.phase,
|
|
@@ -152,7 +152,7 @@ function parseRealtimeRequestArguments(registry, event, direction, args) {
|
|
|
152
152
|
return parsed.data;
|
|
153
153
|
}
|
|
154
154
|
function parseRealtimeRequestAcknowledgement(schema, event, direction, value, hook, logger) {
|
|
155
|
-
const refusal =
|
|
155
|
+
const refusal = asRealtimeRejection2(value);
|
|
156
156
|
if (refusal) {
|
|
157
157
|
reportRejected(realtimeContractViolation({
|
|
158
158
|
event,
|
|
@@ -161,7 +161,7 @@ function parseRealtimeRequestAcknowledgement(schema, event, direction, value, ho
|
|
|
161
161
|
reason: "rejected-by-peer",
|
|
162
162
|
fault: "local"
|
|
163
163
|
}), hook, logger);
|
|
164
|
-
throw new
|
|
164
|
+
throw new RealtimeRequestRejectedError2(event, refusal.reason, refusal.message, refusal.issues);
|
|
165
165
|
}
|
|
166
166
|
const parsed = schema.safeParse(value);
|
|
167
167
|
if (parsed.success)
|
|
@@ -175,7 +175,7 @@ function parseRealtimeRequestAcknowledgement(schema, event, direction, value, ho
|
|
|
175
175
|
cause: parsed.error
|
|
176
176
|
});
|
|
177
177
|
reportRejected(rejected, hook, logger);
|
|
178
|
-
throw new
|
|
178
|
+
throw new RealtimeRequestInvalidAcknowledgementError2(event, rejected.error);
|
|
179
179
|
}
|
|
180
180
|
function createValidatedRealtimeSocket({
|
|
181
181
|
target,
|
|
@@ -208,7 +208,7 @@ function createValidatedRealtimeSocket({
|
|
|
208
208
|
event,
|
|
209
209
|
reason: "invalid-arguments",
|
|
210
210
|
message: rejected.error.message,
|
|
211
|
-
issues:
|
|
211
|
+
issues: zodIssues2(parsed.error).slice(0, MAX_REJECTION_ISSUES)
|
|
212
212
|
}, logger);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
@@ -279,7 +279,7 @@ function createValidatedRealtimeSocket({
|
|
|
279
279
|
const wireArgs = [...parsed.data];
|
|
280
280
|
if (definition.ack && acknowledgement) {
|
|
281
281
|
wireArgs.push((value) => {
|
|
282
|
-
const refusal =
|
|
282
|
+
const refusal = asRealtimeRejection2(value);
|
|
283
283
|
if (refusal) {
|
|
284
284
|
reportRejected(realtimeContractViolation({
|
|
285
285
|
event,
|
|
@@ -321,4 +321,4 @@ function isModuleNotFound(error) {
|
|
|
321
321
|
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || message.includes("Cannot find module") || message.includes("Cannot find package");
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
-
export {
|
|
324
|
+
export { REALTIME_REJECTION_KEY2, asRealtimeRejection2, parseRealtimeRequestArguments, parseRealtimeRequestAcknowledgement, createValidatedRealtimeSocket, isModuleNotFound };
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./index-bm5rx7n6.js";
|
|
2
|
+
AppError2
|
|
3
|
+
} from "./index-n53mswt3.js";
|
|
5
4
|
import {
|
|
6
5
|
toolErrorFromResult
|
|
7
|
-
} from "./index-
|
|
6
|
+
} from "./index-dvwj1f43.js";
|
|
8
7
|
import {
|
|
9
8
|
assertUniqueToolName
|
|
10
|
-
} from "./index-
|
|
9
|
+
} from "./index-7z9ym7t8.js";
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
collectTools2,
|
|
12
|
+
createToolRunner
|
|
13
|
+
} from "./index-n9tyz8z3.js";
|
|
14
14
|
|
|
15
15
|
// src/tools/invoker.ts
|
|
16
|
-
function
|
|
16
|
+
function createToolInvoker2(services, config) {
|
|
17
17
|
const serviceList = Array.isArray(services) ? services : [services];
|
|
18
18
|
const tools = new Map;
|
|
19
19
|
for (const service of serviceList) {
|
|
20
|
-
for (const tool of
|
|
20
|
+
for (const tool of collectTools2(service, config.transport, {
|
|
21
21
|
extend: config.extend,
|
|
22
22
|
flattenUnionInput: config.flattenUnionInput
|
|
23
23
|
})) {
|
|
@@ -30,7 +30,7 @@ function createToolInvoker(services, config) {
|
|
|
30
30
|
const tool = tools.get(name);
|
|
31
31
|
if (tool)
|
|
32
32
|
return tool;
|
|
33
|
-
throw new
|
|
33
|
+
throw new AppError2("NOT_FOUND", `Unknown tool: ${name}`, 404, {
|
|
34
34
|
available: names
|
|
35
35
|
});
|
|
36
36
|
};
|
|
@@ -61,4 +61,4 @@ function createToolInvoker(services, config) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export {
|
|
64
|
+
export { createToolInvoker2 };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentRecordIdSchema2,
|
|
3
|
+
AgentRecordVersionSchema2,
|
|
4
|
+
AgentTimestampSchema2,
|
|
5
|
+
AgentProviderEnvelopeSchema2,
|
|
6
|
+
AgentMessageSchema2,
|
|
7
|
+
AgentAssistantPlaceholderSchema2,
|
|
8
|
+
AgentRunStateSchema2,
|
|
9
|
+
AgentRunOperationSchema2,
|
|
10
|
+
AgentTerminalReasonSchema2,
|
|
11
|
+
AgentRunSchema2,
|
|
12
|
+
AgentRunMetricsSchema2
|
|
13
|
+
} from "./index-8kzct1d6.js";
|
|
14
|
+
|
|
15
|
+
// src/agent-runtime/event-schema.ts
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
var AgentAdmissionEventSchema2 = z.object({
|
|
18
|
+
type: z.literal("admission"),
|
|
19
|
+
eventId: AgentRecordIdSchema2,
|
|
20
|
+
conversationId: AgentRecordIdSchema2,
|
|
21
|
+
runId: AgentRecordIdSchema2,
|
|
22
|
+
snapshotVersion: AgentRecordVersionSchema2,
|
|
23
|
+
input: AgentMessageSchema2,
|
|
24
|
+
run: AgentRunSchema2,
|
|
25
|
+
assistant: z.union([AgentAssistantPlaceholderSchema2, AgentMessageSchema2]),
|
|
26
|
+
emittedAt: AgentTimestampSchema2
|
|
27
|
+
});
|
|
28
|
+
var EventIdentitySchema = z.object({
|
|
29
|
+
conversationId: AgentRecordIdSchema2,
|
|
30
|
+
runId: AgentRecordIdSchema2,
|
|
31
|
+
emittedAt: AgentTimestampSchema2
|
|
32
|
+
});
|
|
33
|
+
var AgentTransientDeltaEventSchema2 = EventIdentitySchema.extend({
|
|
34
|
+
type: z.literal("assistant-delta"),
|
|
35
|
+
runtimeEpoch: z.string().min(1),
|
|
36
|
+
sequence: z.int().nonnegative(),
|
|
37
|
+
textDelta: z.string()
|
|
38
|
+
});
|
|
39
|
+
var AgentTransientReasoningIdentitySchema = EventIdentitySchema.extend({
|
|
40
|
+
runtimeEpoch: z.string().min(1),
|
|
41
|
+
sequence: z.int().nonnegative(),
|
|
42
|
+
provider: AgentProviderEnvelopeSchema2.optional()
|
|
43
|
+
});
|
|
44
|
+
var AgentReasoningStartEventSchema2 = AgentTransientReasoningIdentitySchema.extend({
|
|
45
|
+
type: z.literal("reasoning-start")
|
|
46
|
+
});
|
|
47
|
+
var AgentReasoningDeltaEventSchema2 = AgentTransientReasoningIdentitySchema.extend({
|
|
48
|
+
type: z.literal("reasoning-delta"),
|
|
49
|
+
textDelta: z.string()
|
|
50
|
+
});
|
|
51
|
+
var AgentReasoningEndEventSchema2 = AgentTransientReasoningIdentitySchema.extend({
|
|
52
|
+
type: z.literal("reasoning-end")
|
|
53
|
+
});
|
|
54
|
+
var AgentAttemptResetEventSchema2 = EventIdentitySchema.extend({
|
|
55
|
+
type: z.literal("attempt-reset"),
|
|
56
|
+
runtimeEpoch: z.string().min(1),
|
|
57
|
+
sequence: z.int().nonnegative(),
|
|
58
|
+
attempt: z.int().positive()
|
|
59
|
+
});
|
|
60
|
+
var AgentCheckpointEventSchema2 = EventIdentitySchema.extend({
|
|
61
|
+
type: z.literal("assistant-checkpoint"),
|
|
62
|
+
eventId: AgentRecordIdSchema2,
|
|
63
|
+
snapshotVersion: AgentRecordVersionSchema2,
|
|
64
|
+
message: AgentMessageSchema2,
|
|
65
|
+
metrics: AgentRunMetricsSchema2.optional()
|
|
66
|
+
});
|
|
67
|
+
var AgentRunStateEventSchema2 = EventIdentitySchema.extend({
|
|
68
|
+
type: z.literal("run-state"),
|
|
69
|
+
eventId: AgentRecordIdSchema2,
|
|
70
|
+
snapshotVersion: AgentRecordVersionSchema2,
|
|
71
|
+
state: AgentRunStateSchema2
|
|
72
|
+
});
|
|
73
|
+
var AgentRunOperationEventSchema2 = EventIdentitySchema.extend({
|
|
74
|
+
type: z.literal("run-operation"),
|
|
75
|
+
eventId: AgentRecordIdSchema2,
|
|
76
|
+
snapshotVersion: AgentRecordVersionSchema2,
|
|
77
|
+
operation: AgentRunOperationSchema2
|
|
78
|
+
});
|
|
79
|
+
var AgentToolStatusEventSchema2 = EventIdentitySchema.extend({
|
|
80
|
+
type: z.literal("tool-status"),
|
|
81
|
+
runtimeEpoch: z.string().min(1),
|
|
82
|
+
sequence: z.int().nonnegative(),
|
|
83
|
+
callId: AgentRecordIdSchema2,
|
|
84
|
+
toolName: z.string().min(1),
|
|
85
|
+
status: z.enum(["started", "completed", "failed", "interrupted"]),
|
|
86
|
+
input: z.json().optional(),
|
|
87
|
+
output: z.json().optional()
|
|
88
|
+
});
|
|
89
|
+
var AgentTerminalEventSchema2 = EventIdentitySchema.extend({
|
|
90
|
+
type: z.literal("terminal"),
|
|
91
|
+
eventId: AgentRecordIdSchema2,
|
|
92
|
+
snapshotVersion: AgentRecordVersionSchema2,
|
|
93
|
+
reason: AgentTerminalReasonSchema2,
|
|
94
|
+
policyName: z.string().min(1).optional(),
|
|
95
|
+
message: AgentMessageSchema2,
|
|
96
|
+
metrics: AgentRunMetricsSchema2.optional()
|
|
97
|
+
});
|
|
98
|
+
var AgentRuntimeEventSchema2 = z.discriminatedUnion("type", [
|
|
99
|
+
AgentAdmissionEventSchema2,
|
|
100
|
+
AgentTransientDeltaEventSchema2,
|
|
101
|
+
AgentReasoningStartEventSchema2,
|
|
102
|
+
AgentReasoningDeltaEventSchema2,
|
|
103
|
+
AgentReasoningEndEventSchema2,
|
|
104
|
+
AgentAttemptResetEventSchema2,
|
|
105
|
+
AgentCheckpointEventSchema2,
|
|
106
|
+
AgentRunStateEventSchema2,
|
|
107
|
+
AgentRunOperationEventSchema2,
|
|
108
|
+
AgentToolStatusEventSchema2,
|
|
109
|
+
AgentTerminalEventSchema2
|
|
110
|
+
]);
|
|
111
|
+
var AgentRuntimeEventCursorSchema2 = z.object({
|
|
112
|
+
snapshotVersion: AgentRecordVersionSchema2.optional(),
|
|
113
|
+
durableEventIds: z.array(AgentRecordIdSchema2).optional(),
|
|
114
|
+
runtimeEpoch: z.string().min(1).optional(),
|
|
115
|
+
sequence: z.int().nonnegative().optional()
|
|
116
|
+
});
|
|
117
|
+
function isDurableEvent(event) {
|
|
118
|
+
return event.type === "admission" || event.type === "assistant-checkpoint" || event.type === "run-state" || event.type === "run-operation" || event.type === "terminal";
|
|
119
|
+
}
|
|
120
|
+
function advanceAgentRuntimeEventCursor2(rawCursor, event) {
|
|
121
|
+
const cursor = AgentRuntimeEventCursorSchema2.parse(rawCursor);
|
|
122
|
+
if (isDurableEvent(event)) {
|
|
123
|
+
const previous = cursor.snapshotVersion;
|
|
124
|
+
const durableEventIds = previous === event.snapshotVersion ? cursor.durableEventIds ?? [] : [];
|
|
125
|
+
if (previous !== undefined && event.snapshotVersion < previous || durableEventIds.includes(event.eventId)) {
|
|
126
|
+
return { status: "duplicate", cursor };
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
status: "accepted",
|
|
130
|
+
cursor: {
|
|
131
|
+
...cursor,
|
|
132
|
+
snapshotVersion: event.snapshotVersion,
|
|
133
|
+
durableEventIds: [...durableEventIds, event.eventId]
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const previousSequence = cursor.runtimeEpoch === event.runtimeEpoch ? cursor.sequence : undefined;
|
|
138
|
+
if (previousSequence !== undefined && event.sequence <= previousSequence) {
|
|
139
|
+
return { status: "duplicate", cursor };
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
status: previousSequence !== undefined && event.sequence > previousSequence + 1 ? "gap" : "accepted",
|
|
143
|
+
cursor: { ...cursor, runtimeEpoch: event.runtimeEpoch, sequence: event.sequence }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function agentDurableEventId2(type, runId, snapshotVersion) {
|
|
147
|
+
return `${runId}:${type}:${snapshotVersion}`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { AgentAdmissionEventSchema2, AgentTransientDeltaEventSchema2, AgentReasoningStartEventSchema2, AgentReasoningDeltaEventSchema2, AgentReasoningEndEventSchema2, AgentAttemptResetEventSchema2, AgentCheckpointEventSchema2, AgentRunStateEventSchema2, AgentRunOperationEventSchema2, AgentToolStatusEventSchema2, AgentTerminalEventSchema2, AgentRuntimeEventSchema2, AgentRuntimeEventCursorSchema2, advanceAgentRuntimeEventCursor2, agentDurableEventId2 };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/contract/errors.ts
|
|
2
2
|
var APP_ERROR_BRAND = Symbol.for("stitchkit.AppError");
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class AppError2 extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
details;
|
|
@@ -33,25 +33,25 @@ class AppError extends Error {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
function
|
|
37
|
-
throw new
|
|
36
|
+
function notFound2(message = "Not found") {
|
|
37
|
+
throw new AppError2("NOT_FOUND", message, 404);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
throw new
|
|
39
|
+
function badRequest2(message, details) {
|
|
40
|
+
throw new AppError2("BAD_REQUEST", message, 400, details);
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
throw new
|
|
42
|
+
function unauthorized2(message = "Unauthorized") {
|
|
43
|
+
throw new AppError2("UNAUTHORIZED", message, 401);
|
|
44
44
|
}
|
|
45
|
-
function
|
|
46
|
-
throw new
|
|
45
|
+
function forbidden2(message = "Forbidden") {
|
|
46
|
+
throw new AppError2("FORBIDDEN", message, 403);
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
throw new
|
|
48
|
+
function conflict2(message = "Conflict", details) {
|
|
49
|
+
throw new AppError2("CONFLICT", message, 409, details);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
52
|
-
throw new
|
|
51
|
+
function rateLimited2(message = "Too many requests") {
|
|
52
|
+
throw new AppError2("RATE_LIMITED", message, 429);
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var STITCH_ERROR_STATUS2 = {
|
|
55
55
|
BAD_REQUEST: 400,
|
|
56
56
|
UNAUTHORIZED: 401,
|
|
57
57
|
FORBIDDEN: 403,
|
|
@@ -85,14 +85,14 @@ var STITCH_ERROR_STATUS = {
|
|
|
85
85
|
SPILL_REFERENCE_UNKNOWN: 404,
|
|
86
86
|
INTERNAL_SERVER_ERROR: 500
|
|
87
87
|
};
|
|
88
|
-
function
|
|
88
|
+
function isRetryableStatus2(status) {
|
|
89
89
|
return status === 408 || status === 429 || status === 502 || status === 503 || status === 504;
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return Object.hasOwn(
|
|
91
|
+
function isStitchErrorCode2(code) {
|
|
92
|
+
return Object.hasOwn(STITCH_ERROR_STATUS2, code);
|
|
93
93
|
}
|
|
94
|
-
function
|
|
95
|
-
throw new
|
|
94
|
+
function appError2(code, message, details) {
|
|
95
|
+
throw new AppError2(code, message, isStitchErrorCode2(code) ? STITCH_ERROR_STATUS2[code] : 500, details);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
export {
|
|
98
|
+
export { AppError2, notFound2, badRequest2, unauthorized2, forbidden2, conflict2, rateLimited2, STITCH_ERROR_STATUS2, isRetryableStatus2, isStitchErrorCode2, appError2 };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AgentMessagePartSchema2,
|
|
3
|
+
AgentSnapshotSchema2
|
|
4
|
+
} from "./index-8kzct1d6.js";
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from "./index-gtj3zc53.js";
|
|
6
|
+
AgentRuntimeEventSchema2
|
|
7
|
+
} from "./index-mnkk1ffz.js";
|
|
8
8
|
|
|
9
9
|
// src/agent-runtime/control-schema.ts
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
var AgentControlIdentitySchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1) }).strict();
|
|
12
|
-
var
|
|
12
|
+
var AgentControlRequestSchema2 = z.discriminatedUnion("operation", [
|
|
13
13
|
AgentControlIdentitySchema.extend({
|
|
14
14
|
operation: z.literal("attach"),
|
|
15
15
|
conversationId: z.string().min(1),
|
|
@@ -28,7 +28,7 @@ var AgentControlRequestSchema = z.discriminatedUnion("operation", [
|
|
|
28
28
|
conversationId: z.string().min(1),
|
|
29
29
|
idempotencyKey: z.string().min(1),
|
|
30
30
|
context: z.unknown(),
|
|
31
|
-
parts: z.array(
|
|
31
|
+
parts: z.array(AgentMessagePartSchema2).min(1),
|
|
32
32
|
metadata: z.unknown().optional()
|
|
33
33
|
}),
|
|
34
34
|
AgentControlIdentitySchema.extend({
|
|
@@ -50,10 +50,10 @@ var AgentControlResponseIdentitySchema = z.object({
|
|
|
50
50
|
schemaVersion: z.literal(1),
|
|
51
51
|
requestId: z.string().min(1)
|
|
52
52
|
});
|
|
53
|
-
var
|
|
53
|
+
var AgentControlResponseSchema2 = z.discriminatedUnion("outcome", [
|
|
54
54
|
AgentControlResponseIdentitySchema.extend({
|
|
55
55
|
outcome: z.literal("ok"),
|
|
56
|
-
snapshot:
|
|
56
|
+
snapshot: AgentSnapshotSchema2.optional(),
|
|
57
57
|
runId: z.string().min(1).optional()
|
|
58
58
|
}).strict(),
|
|
59
59
|
AgentControlResponseIdentitySchema.extend({
|
|
@@ -61,11 +61,11 @@ var AgentControlResponseSchema = z.discriminatedUnion("outcome", [
|
|
|
61
61
|
error: z.object({ code: z.string().min(1), message: z.string().min(1) }).strict()
|
|
62
62
|
}).strict()
|
|
63
63
|
]);
|
|
64
|
-
var
|
|
64
|
+
var AgentControlDeliverySchema2 = z.discriminatedUnion("type", [
|
|
65
65
|
z.object({
|
|
66
66
|
schemaVersion: z.literal(1),
|
|
67
67
|
type: z.literal("event"),
|
|
68
|
-
event:
|
|
68
|
+
event: AgentRuntimeEventSchema2
|
|
69
69
|
}).strict(),
|
|
70
70
|
z.object({
|
|
71
71
|
schemaVersion: z.literal(1),
|
|
@@ -74,7 +74,7 @@ var AgentControlDeliverySchema = z.discriminatedUnion("type", [
|
|
|
74
74
|
reason: z.literal("overflow")
|
|
75
75
|
}).strict()
|
|
76
76
|
]);
|
|
77
|
-
var
|
|
77
|
+
var AgentMultiSessionCursorSchema2 = z.object({
|
|
78
78
|
conversations: z.record(z.string(), z.object({
|
|
79
79
|
snapshotVersion: z.int().nonnegative().optional(),
|
|
80
80
|
durableEventIds: z.array(z.string().min(1)).optional(),
|
|
@@ -90,8 +90,8 @@ function durable(event) {
|
|
|
90
90
|
"terminal"
|
|
91
91
|
].includes(event.type);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const cursor =
|
|
93
|
+
function advanceAgentMultiSessionCursor2(raw, event) {
|
|
94
|
+
const cursor = AgentMultiSessionCursorSchema2.parse(raw);
|
|
95
95
|
const previous = cursor.conversations[event.conversationId] ?? { runs: {} };
|
|
96
96
|
if (durable(event)) {
|
|
97
97
|
const ids = previous.snapshotVersion === event.snapshotVersion ? previous.durableEventIds ?? [] : [];
|
|
@@ -133,11 +133,11 @@ function advanceAgentMultiSessionCursor(raw, event) {
|
|
|
133
133
|
}
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
|
-
function
|
|
136
|
+
function createAgentControlView2() {
|
|
137
137
|
return { cursor: { conversations: {} }, conversations: {} };
|
|
138
138
|
}
|
|
139
|
-
function
|
|
140
|
-
const snapshot =
|
|
139
|
+
function reduceAgentControlSnapshot2(view, rawSnapshot) {
|
|
140
|
+
const snapshot = AgentSnapshotSchema2.parse(rawSnapshot);
|
|
141
141
|
const previous = view.cursor.conversations[snapshot.conversationId] ?? { runs: {} };
|
|
142
142
|
return {
|
|
143
143
|
cursor: {
|
|
@@ -160,9 +160,9 @@ function reduceAgentControlSnapshot(view, rawSnapshot) {
|
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
function
|
|
164
|
-
const event =
|
|
165
|
-
const advanced =
|
|
163
|
+
function reduceAgentControlEvent2(view, rawEvent) {
|
|
164
|
+
const event = AgentRuntimeEventSchema2.parse(rawEvent);
|
|
165
|
+
const advanced = advanceAgentMultiSessionCursor2(view.cursor, event);
|
|
166
166
|
if (advanced.status === "duplicate")
|
|
167
167
|
return view;
|
|
168
168
|
const current = view.conversations[event.conversationId] ?? {
|
|
@@ -195,4 +195,4 @@ function reduceAgentControlEvent(view, rawEvent) {
|
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
export {
|
|
198
|
+
export { AgentControlRequestSchema2, AgentControlResponseSchema2, AgentControlDeliverySchema2, AgentMultiSessionCursorSchema2, advanceAgentMultiSessionCursor2, createAgentControlView2, reduceAgentControlSnapshot2, reduceAgentControlEvent2 };
|