stitchkit 0.77.0 → 0.79.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/dist/agent-runtime-browser.js +53 -581
- package/dist/agent-runtime-coding-tools.js +6 -5
- package/dist/agent-runtime-harness.js +20 -93
- package/dist/agent-runtime-openrouter.js +1 -1
- package/dist/agent-runtime.js +65 -61
- package/dist/application/decisions.d.ts +28 -25
- package/dist/application/decisions.d.ts.map +1 -1
- package/dist/application/kernel.d.ts +2 -0
- package/dist/application/kernel.d.ts.map +1 -1
- package/dist/application/keyspace.d.ts +11 -1
- package/dist/application/keyspace.d.ts.map +1 -1
- package/dist/application/schedule.d.ts.map +1 -1
- package/dist/application/schemas.d.ts +2 -0
- package/dist/application/schemas.d.ts.map +1 -1
- package/dist/application/server-resource.d.ts.map +1 -1
- package/dist/application/watch-hub.d.ts.map +1 -1
- package/dist/application-diagnostic-journal.d.ts +21 -0
- package/dist/application-diagnostic-journal.d.ts.map +1 -0
- package/dist/application-diagnostic-journal.js +632 -0
- package/dist/application-opentelemetry.js +3 -2
- package/dist/application-schemas.js +14 -98
- package/dist/application.d.ts +1 -2
- package/dist/application.d.ts.map +1 -1
- package/dist/application.js +155 -882
- package/dist/cli.js +13 -11
- package/dist/contract/index.js +15 -10
- package/dist/files/boundary.d.ts.map +1 -1
- package/dist/files.js +1 -1
- package/dist/{index-7b188kmz.js → index-2qzskm8h.js} +15 -1
- package/dist/{index-k2zczx1g.js → index-2rwwmr7v.js} +3 -3
- package/dist/{index-8eywc9zv.js → index-3gye9wzb.js} +6 -3
- package/dist/index-4fpa9dy2.js +51 -0
- package/dist/{index-7qy2ex0m.js → index-5mtc969c.js} +2 -2
- package/dist/index-5s3zajp8.js +192 -0
- package/dist/{index-3cwck0rm.js → index-6s7n2v50.js} +60 -374
- package/dist/{index-s4c8wy8m.js → index-758zx2ha.js} +11 -90
- package/dist/{index-qyrqwr4c.js → index-77fekveh.js} +4 -1
- package/dist/{index-58jzmnn4.js → index-7ag81v2f.js} +355 -34
- package/dist/index-7gnkny4z.js +326 -0
- package/dist/index-7zbps32p.js +89 -0
- package/dist/index-85vfqd7m.js +135 -0
- package/dist/{index-m668wzyc.js → index-9s6z8vgf.js} +17 -141
- package/dist/{index-bfcpjw20.js → index-actkayzn.js} +7 -3
- package/dist/index-b9aefrqd.js +20 -0
- package/dist/index-dre2ywck.js +48 -0
- package/dist/{index-nemjkxjp.js → index-dwf1f2ap.js} +16 -12
- package/dist/{index-wwst0td5.js → index-dx9xehwt.js} +1 -1
- package/dist/{index-ezmn6ac6.js → index-dxesg10d.js} +4 -4
- package/dist/{index-aczggrty.js → index-dxjjv399.js} +2 -2
- package/dist/{index-jqtsc9mj.js → index-egaabxkz.js} +3 -3
- package/dist/{index-vc1b0b1b.js → index-evcnmsc3.js} +49 -8
- package/dist/{index-nt1mp8km.js → index-fxz0v7vg.js} +84 -84
- package/dist/index-h4pj6fta.js +87 -0
- package/dist/{index-1rxswfbv.js → index-hb5pf3s4.js} +1 -1
- package/dist/{index-t8qyvrvg.js → index-k9ay6v6d.js} +21 -272
- package/dist/index-kzfs85xp.js +9 -0
- package/dist/{index-vbf2p6me.js → index-m9kzax52.js} +91 -89
- package/dist/{index-22by16v6.js → index-mgtxfe6b.js} +1 -1
- package/dist/index-p7hgdyhb.js +22 -0
- package/dist/index-pq95qkbf.js +0 -0
- package/dist/index-t0z5p5w6.js +318 -0
- package/dist/{index-s2rchahr.js → index-vwp69871.js} +13 -11
- package/dist/index-wc4x00bn.js +103 -0
- package/dist/{index-da1aqnhb.js → index-xcetq6j3.js} +8 -6
- package/dist/{index-f6n5n7nz.js → index-y01f4223.js} +33 -126
- package/dist/{index-35z5h2ty.js → index-ywd0y6m1.js} +18 -218
- package/dist/index.js +65 -1588
- package/dist/internal/deadline.d.ts +17 -0
- package/dist/internal/deadline.d.ts.map +1 -0
- package/dist/live.js +15 -89
- package/dist/node.js +17 -15
- package/dist/observability/context.d.ts.map +1 -1
- package/dist/observability/index.js +7 -6
- package/dist/primitives.js +5 -2
- package/dist/react.js +1 -1
- package/dist/remote.js +7 -6
- package/dist/server/event-bus.d.ts.map +1 -1
- package/dist/server/index.js +26 -38
- package/dist/telegram.js +1 -1
- package/dist/testing.js +86 -97
- package/dist/tool-invoker.js +11 -9
- package/dist/tools/async-operation-contract.d.ts +61 -0
- package/dist/tools/async-operation-contract.d.ts.map +1 -0
- package/dist/tools/async-operation.d.ts +2 -47
- package/dist/tools/async-operation.d.ts.map +1 -1
- package/dist/tools/view-file-contract.d.ts +98 -0
- package/dist/tools/view-file-contract.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +4 -83
- package/dist/tools/view-file.d.ts.map +1 -1
- package/dist/tools-contract.d.ts +29 -0
- package/dist/tools-contract.d.ts.map +1 -0
- package/dist/tools-contract.js +24 -0
- package/dist/tools.d.ts +3 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +59 -95
- package/llms-full.txt +146 -14
- package/package.json +14 -7
- package/dist/index-ksp6e2ye.js +0 -24
- package/dist/index-vj3vvpaa.js +0 -307
package/dist/cli.js
CHANGED
|
@@ -5,20 +5,22 @@ import {
|
|
|
5
5
|
emitResult,
|
|
6
6
|
parseCliArgs,
|
|
7
7
|
pollUntilDone
|
|
8
|
-
} from "./index-
|
|
9
|
-
import"./index-k2zczx1g.js";
|
|
10
|
-
import"./index-wwst0td5.js";
|
|
11
|
-
import"./index-7qy2ex0m.js";
|
|
12
|
-
import"./index-s4c8wy8m.js";
|
|
13
|
-
import"./index-nemjkxjp.js";
|
|
8
|
+
} from "./index-vwp69871.js";
|
|
14
9
|
import"./index-sbdmyz75.js";
|
|
15
|
-
import"./index-
|
|
10
|
+
import"./index-2rwwmr7v.js";
|
|
11
|
+
import"./index-dx9xehwt.js";
|
|
12
|
+
import"./index-5mtc969c.js";
|
|
13
|
+
import"./index-758zx2ha.js";
|
|
14
|
+
import"./index-dwf1f2ap.js";
|
|
15
|
+
import"./index-mgtxfe6b.js";
|
|
16
16
|
import"./index-cby4ar3v.js";
|
|
17
|
-
import"./index-
|
|
18
|
-
import"./index-
|
|
19
|
-
import"./index-
|
|
20
|
-
import"./index-qyrqwr4c.js";
|
|
17
|
+
import"./index-7zbps32p.js";
|
|
18
|
+
import"./index-fxz0v7vg.js";
|
|
19
|
+
import"./index-y01f4223.js";
|
|
21
20
|
import"./index-6k1937bx.js";
|
|
21
|
+
import"./index-0w9abg87.js";
|
|
22
|
+
import"./index-kzfs85xp.js";
|
|
23
|
+
import"./index-77fekveh.js";
|
|
22
24
|
export {
|
|
23
25
|
pollUntilDone,
|
|
24
26
|
parseCliArgs,
|
package/dist/contract/index.js
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ALL_TRANSPORTS,
|
|
3
|
-
AppError,
|
|
4
3
|
ContractStreamFrameSchema,
|
|
5
4
|
DEFAULT_CONTRACT_STREAM_FRAME_BYTES,
|
|
6
|
-
ManagedFilePathSchema,
|
|
7
|
-
ManagedFileRefSchema,
|
|
8
|
-
STITCH_ERROR_STATUS,
|
|
9
|
-
appError,
|
|
10
|
-
badRequest,
|
|
11
|
-
conflict,
|
|
12
5
|
createContractFactory,
|
|
13
6
|
decodeCursor,
|
|
14
7
|
defineContract,
|
|
15
8
|
defineErrors,
|
|
16
9
|
encodeCursor,
|
|
10
|
+
paginatedSchema
|
|
11
|
+
} from "../index-y01f4223.js";
|
|
12
|
+
import {
|
|
13
|
+
ManagedFilePathSchema,
|
|
14
|
+
ManagedFileRefSchema
|
|
15
|
+
} from "../index-6k1937bx.js";
|
|
16
|
+
import {
|
|
17
|
+
AppError,
|
|
18
|
+
STITCH_ERROR_STATUS,
|
|
19
|
+
appError,
|
|
20
|
+
badRequest,
|
|
21
|
+
conflict,
|
|
17
22
|
forbidden,
|
|
18
23
|
isStitchErrorCode,
|
|
19
24
|
notFound,
|
|
20
|
-
paginatedSchema,
|
|
21
25
|
rateLimited,
|
|
22
26
|
unauthorized
|
|
23
|
-
} from "../index-
|
|
24
|
-
import"../index-
|
|
27
|
+
} from "../index-0w9abg87.js";
|
|
28
|
+
import"../index-kzfs85xp.js";
|
|
29
|
+
import"../index-77fekveh.js";
|
|
25
30
|
export {
|
|
26
31
|
unauthorized,
|
|
27
32
|
rateLimited,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/files/boundary.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/files/boundary.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,sBAAsB,CAAC;AAqB9B,MAAM,MAAM,oBAAoB,GAC5B,mBAAmB,GACnB,gBAAgB,GAChB,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,GAChB,aAAa,GACb,0BAA0B,GAC1B,eAAe,CAAC;AAEpB,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,IAAI,EAAE,oBAAoB;IAD5C,YACkB,IAAI,EAAE,oBAAoB,EAC1C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY,EAIvB;CACF;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,cAAc,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC;AAE/E,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,0BAA0B,KAC9B,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAE5D,MAAM,WAAW,yBAAyB;IACxC,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjF,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,EAC/C,OAAO,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,cAAc,CAAC,CAAC;CAC5B;AAmRD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,yBAAyB,GAChC,OAAO,CAAC,mBAAmB,CAAC,CAyJ9B"}
|
package/dist/files.js
CHANGED
|
@@ -46,4 +46,18 @@ class RealtimeRequestInvalidAcknowledgementError extends Error {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
class RealtimeRequestRejectedError extends Error {
|
|
50
|
+
code = "REALTIME_REQUEST_REJECTED";
|
|
51
|
+
event;
|
|
52
|
+
reason;
|
|
53
|
+
issues;
|
|
54
|
+
constructor(event, reason, detail, issues) {
|
|
55
|
+
super(`Realtime request "${event}" was rejected by the peer (${reason}): ${detail}`);
|
|
56
|
+
this.name = "RealtimeRequestRejectedError";
|
|
57
|
+
this.event = event;
|
|
58
|
+
this.reason = reason;
|
|
59
|
+
this.issues = issues;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { RealtimeRequestPhaseSchema, RealtimeRequestPhaseEventSchema, RealtimeRequestTimeoutError, RealtimeRequestDisconnectedError, RealtimeRequestInvalidAcknowledgementError, RealtimeRequestRejectedError };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runtimeToolMountable
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-dx9xehwt.js";
|
|
4
4
|
import {
|
|
5
5
|
contractToolMountable
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-5mtc969c.js";
|
|
7
7
|
import {
|
|
8
8
|
projectToolSurface
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-mgtxfe6b.js";
|
|
10
10
|
|
|
11
11
|
// src/tools/surface.ts
|
|
12
12
|
function collectToolSurface({
|
|
@@ -44,7 +44,8 @@ var ApplicationSnapshotSchema = z.object({
|
|
|
44
44
|
capturedAt: z.string().datetime({ offset: true }),
|
|
45
45
|
changedAt: z.string().datetime({ offset: true }),
|
|
46
46
|
admission: ApplicationAdmissionSnapshotSchema,
|
|
47
|
-
resources: z.array(ManagedResourceSnapshotSchema).readonly()
|
|
47
|
+
resources: z.array(ManagedResourceSnapshotSchema).readonly(),
|
|
48
|
+
restarting: z.array(z.string()).readonly()
|
|
48
49
|
}).readonly();
|
|
49
50
|
var ApplicationStatusProjectionSchema = z.object({
|
|
50
51
|
id: ApplicationIdSchema,
|
|
@@ -57,7 +58,8 @@ var ApplicationStatusProjectionSchema = z.object({
|
|
|
57
58
|
ready: NonNegativeIntegerSchema,
|
|
58
59
|
degraded: NonNegativeIntegerSchema,
|
|
59
60
|
failed: NonNegativeIntegerSchema
|
|
60
|
-
}).readonly()
|
|
61
|
+
}).readonly(),
|
|
62
|
+
restarting: NonNegativeIntegerSchema
|
|
61
63
|
}).readonly();
|
|
62
64
|
function projectApplicationStatus(snapshot) {
|
|
63
65
|
let ready = 0;
|
|
@@ -77,7 +79,8 @@ function projectApplicationStatus(snapshot) {
|
|
|
77
79
|
health: snapshot.health,
|
|
78
80
|
ready: snapshot.ready,
|
|
79
81
|
capturedAt: snapshot.capturedAt,
|
|
80
|
-
resources: { total: snapshot.resources.length, ready, degraded, failed }
|
|
82
|
+
resources: { total: snapshot.resources.length, ready, degraded, failed },
|
|
83
|
+
restarting: snapshot.restarting.length
|
|
81
84
|
};
|
|
82
85
|
}
|
|
83
86
|
var ApplicationResourceShutdownSchema = z.object({
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/tools/async-operation-contract.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var AsyncOperationCancelResultSchema = z.discriminatedUnion("outcome", [
|
|
4
|
+
z.object({ outcome: z.literal("accepted") }),
|
|
5
|
+
z.object({ outcome: z.literal("already_terminal") }),
|
|
6
|
+
z.object({ outcome: z.literal("rejected"), reason: z.string().min(1) })
|
|
7
|
+
]);
|
|
8
|
+
function createAsyncOperationSnapshotSchema(config) {
|
|
9
|
+
const progress = config.progress ? { progress: config.progress.optional() } : {};
|
|
10
|
+
return z.discriminatedUnion("phase", [
|
|
11
|
+
z.object({ phase: z.literal("pending"), ...progress }),
|
|
12
|
+
z.object({ phase: z.literal("running"), ...progress }),
|
|
13
|
+
z.object({ phase: z.literal("succeeded"), ...progress }),
|
|
14
|
+
z.object({ phase: z.literal("failed"), failure: config.failure, ...progress }),
|
|
15
|
+
z.object({ phase: z.literal("cancelled"), ...progress })
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
// src/tools/view-file-contract.ts
|
|
19
|
+
import { z as z2 } from "zod";
|
|
20
|
+
var MAX_VIEW_FILES = 20;
|
|
21
|
+
var McpAnnotationsSchema = z2.object({
|
|
22
|
+
audience: z2.array(z2.enum(["user", "assistant"])).optional(),
|
|
23
|
+
priority: z2.number().optional()
|
|
24
|
+
});
|
|
25
|
+
var McpMediaContentSchema = z2.discriminatedUnion("type", [
|
|
26
|
+
z2.object({ type: z2.literal("text"), text: z2.string() }),
|
|
27
|
+
z2.object({
|
|
28
|
+
type: z2.literal("image"),
|
|
29
|
+
data: z2.string(),
|
|
30
|
+
mimeType: z2.string(),
|
|
31
|
+
annotations: McpAnnotationsSchema.optional()
|
|
32
|
+
}),
|
|
33
|
+
z2.object({
|
|
34
|
+
type: z2.literal("audio"),
|
|
35
|
+
data: z2.string(),
|
|
36
|
+
mimeType: z2.string(),
|
|
37
|
+
annotations: McpAnnotationsSchema.optional()
|
|
38
|
+
})
|
|
39
|
+
]);
|
|
40
|
+
var ViewFileErrorSchema = z2.object({
|
|
41
|
+
path: z2.string(),
|
|
42
|
+
message: z2.string()
|
|
43
|
+
});
|
|
44
|
+
var ViewFileOutputSchema = z2.object({
|
|
45
|
+
content: z2.array(McpMediaContentSchema),
|
|
46
|
+
errors: z2.array(ViewFileErrorSchema)
|
|
47
|
+
});
|
|
48
|
+
var ViewFileInputSchema = z2.object({
|
|
49
|
+
paths: z2.union([z2.string(), z2.array(z2.string()).max(MAX_VIEW_FILES)]).describe("Media URL(s) or file path(s) to view")
|
|
50
|
+
});
|
|
51
|
+
export { AsyncOperationCancelResultSchema, createAsyncOperationSnapshotSchema, McpAnnotationsSchema, McpMediaContentSchema, ViewFileErrorSchema, ViewFileOutputSchema, ViewFileInputSchema };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
executeToolMethod
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-758zx2ha.js";
|
|
4
4
|
import {
|
|
5
5
|
assertToolExtensionCompatible,
|
|
6
6
|
mergeSchemas,
|
|
7
7
|
projectToolSurface,
|
|
8
8
|
rebuildObject
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-mgtxfe6b.js";
|
|
10
10
|
|
|
11
11
|
// src/tools/mount.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentRuntimeEventSchema
|
|
3
|
+
} from "./index-85vfqd7m.js";
|
|
4
|
+
import {
|
|
5
|
+
AgentMessagePartSchema,
|
|
6
|
+
AgentSnapshotSchema
|
|
7
|
+
} from "./index-x1th9s8c.js";
|
|
8
|
+
|
|
9
|
+
// src/agent-runtime/control-schema.ts
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
var AgentControlIdentitySchema = z.object({ schemaVersion: z.literal(1), requestId: z.string().min(1) }).strict();
|
|
12
|
+
var AgentControlRequestSchema = z.discriminatedUnion("operation", [
|
|
13
|
+
AgentControlIdentitySchema.extend({
|
|
14
|
+
operation: z.literal("attach"),
|
|
15
|
+
conversationId: z.string().min(1),
|
|
16
|
+
access: z.enum(["observe", "control"])
|
|
17
|
+
}),
|
|
18
|
+
AgentControlIdentitySchema.extend({
|
|
19
|
+
operation: z.literal("detach"),
|
|
20
|
+
conversationId: z.string().min(1)
|
|
21
|
+
}),
|
|
22
|
+
AgentControlIdentitySchema.extend({
|
|
23
|
+
operation: z.literal("snapshot"),
|
|
24
|
+
conversationId: z.string().min(1)
|
|
25
|
+
}),
|
|
26
|
+
AgentControlIdentitySchema.extend({
|
|
27
|
+
operation: z.literal("submit"),
|
|
28
|
+
conversationId: z.string().min(1),
|
|
29
|
+
idempotencyKey: z.string().min(1),
|
|
30
|
+
context: z.unknown(),
|
|
31
|
+
parts: z.array(AgentMessagePartSchema).min(1),
|
|
32
|
+
metadata: z.unknown().optional()
|
|
33
|
+
}),
|
|
34
|
+
AgentControlIdentitySchema.extend({
|
|
35
|
+
operation: z.literal("interrupt"),
|
|
36
|
+
conversationId: z.string().min(1),
|
|
37
|
+
runId: z.string().min(1)
|
|
38
|
+
}),
|
|
39
|
+
AgentControlIdentitySchema.extend({
|
|
40
|
+
operation: z.literal("respond-approval"),
|
|
41
|
+
conversationId: z.string().min(1),
|
|
42
|
+
approvalId: z.string().min(1),
|
|
43
|
+
approved: z.boolean(),
|
|
44
|
+
reason: z.string().min(1).optional(),
|
|
45
|
+
context: z.unknown(),
|
|
46
|
+
metadata: z.unknown().optional()
|
|
47
|
+
})
|
|
48
|
+
]);
|
|
49
|
+
var AgentControlResponseIdentitySchema = z.object({
|
|
50
|
+
schemaVersion: z.literal(1),
|
|
51
|
+
requestId: z.string().min(1)
|
|
52
|
+
});
|
|
53
|
+
var AgentControlResponseSchema = z.discriminatedUnion("outcome", [
|
|
54
|
+
AgentControlResponseIdentitySchema.extend({
|
|
55
|
+
outcome: z.literal("ok"),
|
|
56
|
+
snapshot: AgentSnapshotSchema.optional(),
|
|
57
|
+
runId: z.string().min(1).optional()
|
|
58
|
+
}).strict(),
|
|
59
|
+
AgentControlResponseIdentitySchema.extend({
|
|
60
|
+
outcome: z.literal("error"),
|
|
61
|
+
error: z.object({ code: z.string().min(1), message: z.string().min(1) }).strict()
|
|
62
|
+
}).strict()
|
|
63
|
+
]);
|
|
64
|
+
var AgentControlDeliverySchema = z.discriminatedUnion("type", [
|
|
65
|
+
z.object({
|
|
66
|
+
schemaVersion: z.literal(1),
|
|
67
|
+
type: z.literal("event"),
|
|
68
|
+
event: AgentRuntimeEventSchema
|
|
69
|
+
}).strict(),
|
|
70
|
+
z.object({
|
|
71
|
+
schemaVersion: z.literal(1),
|
|
72
|
+
type: z.literal("resync-required"),
|
|
73
|
+
conversationId: z.string().min(1),
|
|
74
|
+
reason: z.literal("overflow")
|
|
75
|
+
}).strict()
|
|
76
|
+
]);
|
|
77
|
+
var AgentMultiSessionCursorSchema = z.object({
|
|
78
|
+
conversations: z.record(z.string(), z.object({
|
|
79
|
+
snapshotVersion: z.int().nonnegative().optional(),
|
|
80
|
+
durableEventIds: z.array(z.string().min(1)).optional(),
|
|
81
|
+
runs: z.record(z.string(), z.object({ runtimeEpoch: z.string().min(1), sequence: z.int().nonnegative() }).strict())
|
|
82
|
+
}).strict())
|
|
83
|
+
}).strict();
|
|
84
|
+
function durable(event) {
|
|
85
|
+
return ["admission", "assistant-checkpoint", "run-state", "terminal"].includes(event.type);
|
|
86
|
+
}
|
|
87
|
+
function advanceAgentMultiSessionCursor(raw, event) {
|
|
88
|
+
const cursor = AgentMultiSessionCursorSchema.parse(raw);
|
|
89
|
+
const previous = cursor.conversations[event.conversationId] ?? { runs: {} };
|
|
90
|
+
if (durable(event)) {
|
|
91
|
+
const ids = previous.snapshotVersion === event.snapshotVersion ? previous.durableEventIds ?? [] : [];
|
|
92
|
+
if (previous.snapshotVersion !== undefined && event.snapshotVersion < previous.snapshotVersion || ids.includes(event.eventId)) {
|
|
93
|
+
return { status: "duplicate", cursor };
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
status: "accepted",
|
|
97
|
+
cursor: {
|
|
98
|
+
conversations: {
|
|
99
|
+
...cursor.conversations,
|
|
100
|
+
[event.conversationId]: {
|
|
101
|
+
...previous,
|
|
102
|
+
snapshotVersion: event.snapshotVersion,
|
|
103
|
+
durableEventIds: [...ids, event.eventId]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const run = previous.runs[event.runId];
|
|
110
|
+
const sequence = run?.runtimeEpoch === event.runtimeEpoch ? run.sequence : undefined;
|
|
111
|
+
if (sequence !== undefined && event.sequence <= sequence)
|
|
112
|
+
return { status: "duplicate", cursor };
|
|
113
|
+
const expected = sequence === undefined ? 1 : sequence + 1;
|
|
114
|
+
return {
|
|
115
|
+
status: event.sequence === expected ? "accepted" : "gap",
|
|
116
|
+
cursor: {
|
|
117
|
+
conversations: {
|
|
118
|
+
...cursor.conversations,
|
|
119
|
+
[event.conversationId]: {
|
|
120
|
+
...previous,
|
|
121
|
+
runs: {
|
|
122
|
+
...previous.runs,
|
|
123
|
+
[event.runId]: { runtimeEpoch: event.runtimeEpoch, sequence: event.sequence }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function createAgentControlView() {
|
|
131
|
+
return { cursor: { conversations: {} }, conversations: {} };
|
|
132
|
+
}
|
|
133
|
+
function reduceAgentControlSnapshot(view, rawSnapshot) {
|
|
134
|
+
const snapshot = AgentSnapshotSchema.parse(rawSnapshot);
|
|
135
|
+
const previous = view.cursor.conversations[snapshot.conversationId] ?? { runs: {} };
|
|
136
|
+
return {
|
|
137
|
+
cursor: {
|
|
138
|
+
conversations: {
|
|
139
|
+
...view.cursor.conversations,
|
|
140
|
+
[snapshot.conversationId]: {
|
|
141
|
+
...previous,
|
|
142
|
+
snapshotVersion: snapshot.version,
|
|
143
|
+
durableEventIds: []
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
conversations: {
|
|
148
|
+
...view.conversations,
|
|
149
|
+
[snapshot.conversationId]: {
|
|
150
|
+
snapshot,
|
|
151
|
+
resyncRequired: false,
|
|
152
|
+
transientByRun: {}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function reduceAgentControlEvent(view, rawEvent) {
|
|
158
|
+
const event = AgentRuntimeEventSchema.parse(rawEvent);
|
|
159
|
+
const advanced = advanceAgentMultiSessionCursor(view.cursor, event);
|
|
160
|
+
if (advanced.status === "duplicate")
|
|
161
|
+
return view;
|
|
162
|
+
const current = view.conversations[event.conversationId] ?? {
|
|
163
|
+
resyncRequired: false,
|
|
164
|
+
transientByRun: {}
|
|
165
|
+
};
|
|
166
|
+
if (advanced.status === "gap") {
|
|
167
|
+
return {
|
|
168
|
+
cursor: advanced.cursor,
|
|
169
|
+
conversations: {
|
|
170
|
+
...view.conversations,
|
|
171
|
+
[event.conversationId]: { ...current, resyncRequired: true }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const transient = current.transientByRun[event.runId] ?? { text: "", reasoning: "" };
|
|
176
|
+
const nextTransient = event.type === "assistant-delta" ? { ...transient, text: transient.text + event.textDelta } : event.type === "reasoning-delta" ? { ...transient, reasoning: transient.reasoning + event.textDelta } : transient;
|
|
177
|
+
const snapshotStale = durable(event) && current.snapshot?.version !== event.snapshotVersion;
|
|
178
|
+
const transientByRun = event.type === "terminal" ? Object.fromEntries(Object.entries(current.transientByRun).filter(([runId]) => runId !== event.runId)) : { ...current.transientByRun, [event.runId]: nextTransient };
|
|
179
|
+
return {
|
|
180
|
+
cursor: advanced.cursor,
|
|
181
|
+
conversations: {
|
|
182
|
+
...view.conversations,
|
|
183
|
+
[event.conversationId]: {
|
|
184
|
+
...current,
|
|
185
|
+
resyncRequired: current.resyncRequired || snapshotStale,
|
|
186
|
+
transientByRun
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { AgentControlRequestSchema, AgentControlResponseSchema, AgentControlDeliverySchema, AgentMultiSessionCursorSchema, advanceAgentMultiSessionCursor, createAgentControlView, reduceAgentControlSnapshot, reduceAgentControlEvent };
|