stitchkit 0.85.2 → 0.87.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 +243 -0
- package/README.md +3 -0
- package/dist/agent-runtime/agent-tool.d.ts +25 -0
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -0
- package/dist/agent-runtime/child-tools.d.ts +69 -0
- package/dist/agent-runtime/child-tools.d.ts.map +1 -0
- package/dist/agent-runtime/children.d.ts +113 -0
- package/dist/agent-runtime/children.d.ts.map +1 -0
- package/dist/agent-runtime/coding-tool-contract.d.ts +29 -0
- package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-refusals.d.ts +2 -0
- package/dist/agent-runtime/coding-tool-refusals.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
- package/dist/agent-runtime/coding-tools.d.ts +1 -0
- package/dist/agent-runtime/coding-tools.d.ts.map +1 -1
- package/dist/agent-runtime/control-schema.d.ts +17 -0
- package/dist/agent-runtime/control-schema.d.ts.map +1 -1
- package/dist/agent-runtime/conversations.d.ts +11 -0
- package/dist/agent-runtime/conversations.d.ts.map +1 -1
- package/dist/agent-runtime/event-schema.d.ts +34 -0
- package/dist/agent-runtime/event-schema.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-tools.d.ts +53 -0
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -0
- package/dist/agent-runtime/event-search.d.ts +23 -0
- package/dist/agent-runtime/event-search.d.ts.map +1 -0
- package/dist/agent-runtime/fault-bench.d.ts +45 -0
- package/dist/agent-runtime/fault-bench.d.ts.map +1 -0
- package/dist/agent-runtime/observability.d.ts +6 -0
- package/dist/agent-runtime/observability.d.ts.map +1 -1
- package/dist/agent-runtime/projections.d.ts +69 -0
- package/dist/agent-runtime/projections.d.ts.map +1 -0
- package/dist/agent-runtime/provider-failure.d.ts +5 -1
- package/dist/agent-runtime/provider-failure.d.ts.map +1 -1
- package/dist/agent-runtime/provider-origin.d.ts +12 -0
- package/dist/agent-runtime/provider-origin.d.ts.map +1 -0
- package/dist/agent-runtime/retry-policy.d.ts +27 -0
- package/dist/agent-runtime/retry-policy.d.ts.map +1 -0
- package/dist/agent-runtime/run-execution.d.ts +0 -9
- package/dist/agent-runtime/run-execution.d.ts.map +1 -1
- package/dist/agent-runtime/run-operation-lifecycle.d.ts.map +1 -1
- package/dist/agent-runtime/runtime.d.ts +15 -0
- package/dist/agent-runtime/runtime.d.ts.map +1 -1
- package/dist/agent-runtime/sandbox.d.ts +66 -0
- package/dist/agent-runtime/sandbox.d.ts.map +1 -0
- package/dist/agent-runtime/schedule-tools.d.ts +35 -0
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -0
- package/dist/agent-runtime/schedules.d.ts +63 -0
- package/dist/agent-runtime/schedules.d.ts.map +1 -0
- package/dist/agent-runtime/schemas.d.ts +9 -0
- package/dist/agent-runtime/schemas.d.ts.map +1 -1
- package/dist/agent-runtime/spill.d.ts +24 -0
- package/dist/agent-runtime/spill.d.ts.map +1 -0
- package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite.d.ts +26 -0
- package/dist/agent-runtime/sqlite.d.ts.map +1 -1
- package/dist/agent-runtime/state-slots.d.ts +48 -0
- package/dist/agent-runtime/state-slots.d.ts.map +1 -0
- package/dist/agent-runtime/state-tools.d.ts +58 -0
- package/dist/agent-runtime/state-tools.d.ts.map +1 -0
- package/dist/agent-runtime/store-driver.d.ts +13 -0
- package/dist/agent-runtime/store-driver.d.ts.map +1 -1
- package/dist/agent-runtime/store-events.d.ts +829 -0
- package/dist/agent-runtime/store-events.d.ts.map +1 -0
- package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts +6 -0
- package/dist/agent-runtime/store-migrations/v1-to-v2.d.ts.map +1 -0
- package/dist/agent-runtime/store.d.ts +45 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +1 -1
- package/dist/agent-runtime-browser.js +5 -3
- package/dist/agent-runtime-coding-tools.js +144 -15
- package/dist/agent-runtime-harness.js +12 -11
- package/dist/agent-runtime-sqlite-bun.d.ts +1 -1
- package/dist/agent-runtime-sqlite-bun.d.ts.map +1 -1
- package/dist/agent-runtime-sqlite-bun.js +5 -4
- package/dist/agent-runtime-sqlite-node.d.ts +1 -1
- package/dist/agent-runtime-sqlite-node.d.ts.map +1 -1
- package/dist/agent-runtime-sqlite-node.js +5 -4
- package/dist/agent-runtime-testing.d.ts +3 -0
- package/dist/agent-runtime-testing.d.ts.map +1 -0
- package/dist/agent-runtime-testing.js +156 -0
- package/dist/agent-runtime.d.ts +16 -2
- package/dist/agent-runtime.d.ts.map +1 -1
- package/dist/agent-runtime.js +1632 -156
- package/dist/application.js +14 -14
- package/dist/cli.js +6 -6
- package/dist/{index-fwbkp2jn.js → index-0vfdh685.js} +2 -2
- package/dist/{index-5z8tezpx.js → index-0ydchz76.js} +3 -3
- package/dist/{index-3ds42w1w.js → index-1szetq6f.js} +33 -4
- package/dist/{index-2jg7b11j.js → index-35aefxby.js} +879 -424
- package/dist/index-3yrqvza8.js +964 -0
- package/dist/{index-fq492hg0.js → index-5wezxcxx.js} +238 -161
- package/dist/index-9553432s.js +26 -0
- package/dist/{index-27487ay5.js → index-9hw9eq48.js} +4 -4
- package/dist/index-cnyk6te3.js +77 -0
- package/dist/index-gskm1k5a.js +50 -0
- package/dist/{index-4hk633vz.js → index-hkm6wysp.js} +9 -2
- package/dist/{index-dx9xehwt.js → index-kc6h6hg0.js} +1 -1
- package/dist/{index-x15ss2dx.js → index-p1b1y93x.js} +3 -0
- package/dist/{index-mgtxfe6b.js → index-r159gjwy.js} +8 -1
- package/dist/{index-s4ckmrac.js → index-rcgsnrr6.js} +3 -3
- package/dist/{index-dggwnnjv.js → index-wn9cb82y.js} +1 -1
- package/dist/index-z1m86vc8.js +334 -0
- package/dist/{index-ff0kcqvp.js → index-z2452tsw.js} +3 -3
- package/dist/internal/sqlite.d.ts +13 -0
- package/dist/internal/sqlite.d.ts.map +1 -1
- package/dist/testing/agent-store-conformance.d.ts.map +1 -1
- package/dist/testing.js +89 -80
- package/dist/tool-invoker.js +4 -4
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +16 -0
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +10 -8
- package/llms-full.txt +373 -16
- package/package.json +6 -1
- package/dist/index-66nxrgy0.js +0 -554
- package/dist/index-y2s6h5bf.js +0 -83
|
@@ -1,51 +1,49 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AcceptInputAndAssignRunSchema,
|
|
3
|
+
AcquireAgentRunSchema,
|
|
4
|
+
AgentRecoverablePageSchema,
|
|
5
|
+
AgentRunViewSchema,
|
|
6
|
+
AgentStoreEventEnvelopeSchema,
|
|
7
|
+
AgentStoreEventPageSchema,
|
|
8
|
+
AgentStoreTransitionSchema,
|
|
9
|
+
AppendAgentStoreEventSchema,
|
|
10
|
+
CheckpointRunAssistantSchema,
|
|
11
|
+
CommitRunTerminalSchema,
|
|
12
|
+
ReadAgentStoreEventsSchema,
|
|
13
|
+
RecordRunOperationSchema,
|
|
14
|
+
RecoverAgentRunSchema,
|
|
15
|
+
ReplaceCompactedRangeSchema,
|
|
16
|
+
RequestRunInterruptSchema,
|
|
17
|
+
agentStoreEventDraft,
|
|
18
|
+
assistantStatus,
|
|
19
|
+
canonicalAgentJson,
|
|
20
|
+
decodeAgentConversationArchive,
|
|
21
|
+
encodeAgentConversationArchive
|
|
22
|
+
} from "./index-z1m86vc8.js";
|
|
4
23
|
import {
|
|
5
24
|
AgentMessageSchema,
|
|
6
25
|
AgentRecordIdSchema,
|
|
7
26
|
AgentRecordVersionSchema,
|
|
8
|
-
AgentRunOperationSchema,
|
|
9
27
|
AgentRunSchema,
|
|
10
28
|
AgentSnapshotSchema,
|
|
11
|
-
AgentTerminalReasonSchema,
|
|
12
|
-
AgentUsageSchema,
|
|
13
29
|
runStateForTerminalReason
|
|
14
|
-
} from "./index-
|
|
15
|
-
|
|
16
|
-
// src/agent-runtime/conversations.ts
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
var AgentConversationSummarySchema = z.object({
|
|
19
|
-
conversationId: AgentRecordIdSchema,
|
|
20
|
-
version: AgentRecordVersionSchema,
|
|
21
|
-
updatedAt: z.iso.datetime({ offset: true }),
|
|
22
|
-
preview: z.string(),
|
|
23
|
-
activeRuns: z.int().nonnegative()
|
|
24
|
-
}).strict();
|
|
25
|
-
var AgentConversationPageSchema = z.object({
|
|
26
|
-
items: z.array(AgentConversationSummarySchema),
|
|
27
|
-
nextCursor: z.string().min(1).optional()
|
|
28
|
-
}).strict();
|
|
29
|
-
var AgentConversationMessagePageSchema = z.object({
|
|
30
|
-
items: z.array(AgentMessageSchema),
|
|
31
|
-
nextCursor: z.string().min(1).optional()
|
|
32
|
-
}).strict();
|
|
30
|
+
} from "./index-p1b1y93x.js";
|
|
33
31
|
|
|
34
32
|
// src/agent-runtime/purge.ts
|
|
35
|
-
import { z
|
|
36
|
-
var AgentConversationPurgeInputSchema =
|
|
33
|
+
import { z } from "zod";
|
|
34
|
+
var AgentConversationPurgeInputSchema = z.strictObject({
|
|
37
35
|
conversationId: AgentRecordIdSchema,
|
|
38
36
|
expectedVersion: AgentRecordVersionSchema.optional()
|
|
39
37
|
});
|
|
40
|
-
var AgentConversationPurgeResultSchema =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
outcome:
|
|
46
|
-
runIds:
|
|
38
|
+
var AgentConversationPurgeResultSchema = z.discriminatedUnion("outcome", [
|
|
39
|
+
z.strictObject({ outcome: z.literal("purged") }),
|
|
40
|
+
z.strictObject({ outcome: z.literal("already_purged") }),
|
|
41
|
+
z.strictObject({ outcome: z.literal("unsupported") }),
|
|
42
|
+
z.strictObject({
|
|
43
|
+
outcome: z.literal("active"),
|
|
44
|
+
runIds: z.array(AgentRecordIdSchema).min(1)
|
|
47
45
|
}),
|
|
48
|
-
|
|
46
|
+
z.strictObject({ outcome: z.literal("conflict"), actualVersion: AgentRecordVersionSchema })
|
|
49
47
|
]);
|
|
50
48
|
|
|
51
49
|
class AgentConversationPurgedError extends Error {
|
|
@@ -61,112 +59,9 @@ async function purgeAgentConversation(store, input) {
|
|
|
61
59
|
return AgentConversationPurgeResultSchema.parse(await store.purgeConversation(parsed));
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
// src/agent-runtime/store.ts
|
|
65
|
-
import { z as z3 } from "zod";
|
|
66
|
-
var AgentStoreConflictSchema = z3.object({
|
|
67
|
-
outcome: z3.literal("conflict"),
|
|
68
|
-
actualVersion: AgentRecordVersionSchema
|
|
69
|
-
});
|
|
70
|
-
var AgentStoreNotFoundSchema = z3.object({ outcome: z3.literal("not_found") });
|
|
71
|
-
var AgentStoreAppliedSchema = z3.object({
|
|
72
|
-
outcome: z3.literal("applied"),
|
|
73
|
-
snapshot: AgentSnapshotSchema
|
|
74
|
-
});
|
|
75
|
-
var AgentStoreDuplicateSchema = z3.object({
|
|
76
|
-
outcome: z3.literal("duplicate"),
|
|
77
|
-
input: AgentMessageSchema,
|
|
78
|
-
inputMessageId: AgentRecordIdSchema,
|
|
79
|
-
runId: AgentRecordIdSchema,
|
|
80
|
-
assistantMessageId: AgentRecordIdSchema,
|
|
81
|
-
run: AgentRunSchema,
|
|
82
|
-
assistant: AgentMessageSchema.optional(),
|
|
83
|
-
snapshot: AgentSnapshotSchema
|
|
84
|
-
});
|
|
85
|
-
var AgentStoreMutationResultSchema = z3.discriminatedUnion("outcome", [
|
|
86
|
-
AgentStoreAppliedSchema,
|
|
87
|
-
AgentStoreDuplicateSchema,
|
|
88
|
-
AgentStoreConflictSchema,
|
|
89
|
-
AgentStoreNotFoundSchema
|
|
90
|
-
]);
|
|
91
|
-
var AgentRunViewSchema = z3.object({
|
|
92
|
-
snapshotVersion: AgentRecordVersionSchema,
|
|
93
|
-
run: AgentRunSchema,
|
|
94
|
-
assistant: AgentMessageSchema.optional()
|
|
95
|
-
});
|
|
96
|
-
var AcceptInputAndAssignRunSchema = z3.object({
|
|
97
|
-
idempotencyKey: z3.string().min(1),
|
|
98
|
-
expectedVersion: AgentRecordVersionSchema.optional(),
|
|
99
|
-
input: AgentMessageSchema,
|
|
100
|
-
run: AgentRunSchema,
|
|
101
|
-
coalesceIntoRunId: AgentRecordIdSchema.optional()
|
|
102
|
-
});
|
|
103
|
-
var AcquireAgentRunSchema = z3.object({
|
|
104
|
-
conversationId: AgentRecordIdSchema,
|
|
105
|
-
runId: AgentRecordIdSchema,
|
|
106
|
-
expectedRevision: AgentRecordVersionSchema,
|
|
107
|
-
ownerId: z3.string().min(1)
|
|
108
|
-
});
|
|
109
|
-
var CheckpointRunAssistantSchema = z3.object({
|
|
110
|
-
conversationId: AgentRecordIdSchema,
|
|
111
|
-
runId: AgentRecordIdSchema,
|
|
112
|
-
expectedRevision: AgentRecordVersionSchema,
|
|
113
|
-
ownerId: z3.string().min(1),
|
|
114
|
-
fencingToken: AgentRecordVersionSchema.optional(),
|
|
115
|
-
assistant: AgentMessageSchema,
|
|
116
|
-
usage: AgentUsageSchema.optional()
|
|
117
|
-
});
|
|
118
|
-
var RecordRunOperationSchema = z3.object({
|
|
119
|
-
conversationId: AgentRecordIdSchema,
|
|
120
|
-
runId: AgentRecordIdSchema,
|
|
121
|
-
expectedRevision: AgentRecordVersionSchema,
|
|
122
|
-
ownerId: z3.string().min(1),
|
|
123
|
-
fencingToken: AgentRecordVersionSchema.optional(),
|
|
124
|
-
operation: AgentRunOperationSchema
|
|
125
|
-
});
|
|
126
|
-
var CommitRunTerminalSchema = z3.object({
|
|
127
|
-
conversationId: AgentRecordIdSchema,
|
|
128
|
-
runId: AgentRecordIdSchema,
|
|
129
|
-
expectedRevision: AgentRecordVersionSchema,
|
|
130
|
-
ownerId: z3.string().min(1),
|
|
131
|
-
fencingToken: AgentRecordVersionSchema.optional(),
|
|
132
|
-
assistant: AgentMessageSchema,
|
|
133
|
-
reason: AgentTerminalReasonSchema,
|
|
134
|
-
policyName: z3.string().min(1).optional(),
|
|
135
|
-
usage: AgentUsageSchema.optional(),
|
|
136
|
-
absorb: z3.array(z3.object({
|
|
137
|
-
runId: AgentRecordIdSchema,
|
|
138
|
-
inputMessageIds: z3.array(AgentRecordIdSchema).min(1)
|
|
139
|
-
})).min(1).optional()
|
|
140
|
-
});
|
|
141
|
-
var RequestRunInterruptSchema = z3.object({
|
|
142
|
-
conversationId: AgentRecordIdSchema,
|
|
143
|
-
runId: AgentRecordIdSchema,
|
|
144
|
-
expectedRevision: AgentRecordVersionSchema
|
|
145
|
-
});
|
|
146
|
-
var RecoverAgentRunSchema = z3.object({
|
|
147
|
-
conversationId: AgentRecordIdSchema,
|
|
148
|
-
runId: AgentRecordIdSchema,
|
|
149
|
-
expectedRevision: AgentRecordVersionSchema,
|
|
150
|
-
action: z3.enum(["requeue", "abandon"]),
|
|
151
|
-
replaySafe: z3.boolean().optional()
|
|
152
|
-
});
|
|
153
|
-
var ReplaceCompactedRangeSchema = z3.object({
|
|
154
|
-
conversationId: AgentRecordIdSchema,
|
|
155
|
-
expectedVersion: AgentRecordVersionSchema,
|
|
156
|
-
replacedMessageIds: z3.array(AgentRecordIdSchema).min(1),
|
|
157
|
-
summary: AgentMessageSchema
|
|
158
|
-
});
|
|
159
|
-
var AgentRecoverableDescriptorSchema = z3.object({
|
|
160
|
-
conversationId: AgentRecordIdSchema,
|
|
161
|
-
run: AgentRunSchema
|
|
162
|
-
});
|
|
163
|
-
var AgentRecoverablePageSchema = z3.object({
|
|
164
|
-
items: z3.array(AgentRecoverableDescriptorSchema),
|
|
165
|
-
nextCursor: z3.string().min(1).optional()
|
|
166
|
-
});
|
|
167
|
-
|
|
168
62
|
// src/agent-runtime/store-driver.ts
|
|
169
|
-
import {
|
|
63
|
+
import { createHash } from "node:crypto";
|
|
64
|
+
import { z as z2 } from "zod";
|
|
170
65
|
|
|
171
66
|
// src/agent-runtime/store-purge.ts
|
|
172
67
|
function createStoreConversationPurge(driver, conversations) {
|
|
@@ -192,40 +87,59 @@ function createStoreConversationPurge(driver, conversations) {
|
|
|
192
87
|
}
|
|
193
88
|
|
|
194
89
|
// src/agent-runtime/store-driver.ts
|
|
195
|
-
var AgentRuntimeHeadSchema =
|
|
196
|
-
schemaVersion:
|
|
90
|
+
var AgentRuntimeHeadSchema = z2.object({
|
|
91
|
+
schemaVersion: z2.literal(1),
|
|
197
92
|
conversationId: AgentRecordIdSchema,
|
|
198
93
|
version: AgentRecordVersionSchema
|
|
199
94
|
});
|
|
200
|
-
var AgentStoredRunSchema =
|
|
201
|
-
schemaVersion:
|
|
95
|
+
var AgentStoredRunSchema = z2.object({
|
|
96
|
+
schemaVersion: z2.literal(1),
|
|
202
97
|
run: AgentRunSchema,
|
|
203
98
|
terminalAssistant: AgentMessageSchema.optional()
|
|
204
99
|
});
|
|
205
|
-
var AgentAdmissionReceiptSchema =
|
|
206
|
-
schemaVersion:
|
|
100
|
+
var AgentAdmissionReceiptSchema = z2.object({
|
|
101
|
+
schemaVersion: z2.literal(1),
|
|
207
102
|
conversationId: AgentRecordIdSchema,
|
|
208
|
-
idempotencyKey:
|
|
103
|
+
idempotencyKey: z2.string().min(1),
|
|
209
104
|
input: AgentMessageSchema,
|
|
210
105
|
runId: AgentRecordIdSchema,
|
|
211
106
|
assistantMessageId: AgentRecordIdSchema
|
|
212
107
|
});
|
|
213
|
-
var AgentHistoryMutationSchema =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
type:
|
|
108
|
+
var AgentHistoryMutationSchema = z2.discriminatedUnion("type", [
|
|
109
|
+
z2.object({ type: z2.literal("admit"), input: AgentMessageSchema }),
|
|
110
|
+
z2.object({
|
|
111
|
+
type: z2.literal("upsert-assistant"),
|
|
217
112
|
message: AgentMessageSchema
|
|
218
113
|
}),
|
|
219
|
-
|
|
220
|
-
type:
|
|
221
|
-
replacedMessageIds:
|
|
114
|
+
z2.object({
|
|
115
|
+
type: z2.literal("replace-compacted-range"),
|
|
116
|
+
replacedMessageIds: z2.array(AgentRecordIdSchema).min(1),
|
|
222
117
|
summary: AgentMessageSchema
|
|
223
118
|
})
|
|
224
119
|
]);
|
|
225
|
-
var AgentRecoverableScanInputSchema =
|
|
226
|
-
cursor:
|
|
227
|
-
limit:
|
|
120
|
+
var AgentRecoverableScanInputSchema = z2.object({
|
|
121
|
+
cursor: z2.string().min(1).optional(),
|
|
122
|
+
limit: z2.number().int().min(1).max(1000)
|
|
228
123
|
});
|
|
124
|
+
function transitionRecord(operation) {
|
|
125
|
+
if (operation.type !== "checkpoint")
|
|
126
|
+
return operation;
|
|
127
|
+
const { assistant, ...rest } = operation.input;
|
|
128
|
+
const body = canonicalAgentJson(assistant);
|
|
129
|
+
return {
|
|
130
|
+
type: operation.type,
|
|
131
|
+
input: {
|
|
132
|
+
...rest,
|
|
133
|
+
assistant: {
|
|
134
|
+
id: assistant.id,
|
|
135
|
+
status: assistant.status,
|
|
136
|
+
sha256: createHash("sha256").update(body).digest("hex"),
|
|
137
|
+
parts: assistant.parts.length,
|
|
138
|
+
bytes: Buffer.byteLength(body)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
229
143
|
function emptyHead(conversationId) {
|
|
230
144
|
return AgentRuntimeHeadSchema.parse({
|
|
231
145
|
schemaVersion: 1,
|
|
@@ -328,7 +242,7 @@ function validateSnapshot(head, messages, records) {
|
|
|
328
242
|
}
|
|
329
243
|
}
|
|
330
244
|
}
|
|
331
|
-
var RecoverableCursorSchema =
|
|
245
|
+
var RecoverableCursorSchema = z2.tuple([AgentRecordIdSchema, AgentRecordIdSchema]);
|
|
332
246
|
function recoverableCursor(input) {
|
|
333
247
|
return JSON.stringify([input.conversationId, input.run.id]);
|
|
334
248
|
}
|
|
@@ -650,7 +564,7 @@ function validateAdmissionReceipt(receipt, record, conversationId) {
|
|
|
650
564
|
}
|
|
651
565
|
}
|
|
652
566
|
function createAgentRuntimeStore(driver) {
|
|
653
|
-
const
|
|
567
|
+
const snapshotIn = async (transaction, conversationId) => {
|
|
654
568
|
const [stored, messages, activeRecords] = await Promise.all([
|
|
655
569
|
driver.head.load(transaction, conversationId),
|
|
656
570
|
driver.history.load(transaction, conversationId),
|
|
@@ -662,7 +576,10 @@ function createAgentRuntimeStore(driver) {
|
|
|
662
576
|
runIds: referencedRunIds(messages)
|
|
663
577
|
});
|
|
664
578
|
return snapshotOf(head, messages, mergeRunRecords(activeRecords, referencedRecords));
|
|
665
|
-
}
|
|
579
|
+
};
|
|
580
|
+
const loadSnapshot = (conversationId) => driver.transaction((transaction) => snapshotIn(transaction, conversationId), {
|
|
581
|
+
access: "read"
|
|
582
|
+
});
|
|
666
583
|
const loadRun = (input) => driver.transaction(async (transaction) => {
|
|
667
584
|
const [stored, record] = await Promise.all([
|
|
668
585
|
driver.head.load(transaction, input.conversationId),
|
|
@@ -798,12 +715,142 @@ function createAgentRuntimeStore(driver) {
|
|
|
798
715
|
for (const mutation of reduced.historyMutations ?? []) {
|
|
799
716
|
await driver.history.apply(transaction, mutation);
|
|
800
717
|
}
|
|
718
|
+
await driver.events.append(transaction, agentStoreEventDraft({
|
|
719
|
+
conversationId,
|
|
720
|
+
kind: "runtime/transition",
|
|
721
|
+
payload: z2.json().parse(transitionRecord(operation))
|
|
722
|
+
}));
|
|
801
723
|
return { outcome: "applied", snapshot: reduced.snapshot };
|
|
802
724
|
});
|
|
725
|
+
const appendEvent = (input) => {
|
|
726
|
+
const parsed = AppendAgentStoreEventSchema.parse(input);
|
|
727
|
+
return driver.transaction(async (transaction) => {
|
|
728
|
+
if (await driver.conversations?.isPurged(transaction, parsed.conversationId)) {
|
|
729
|
+
throw new AgentConversationPurgedError;
|
|
730
|
+
}
|
|
731
|
+
return driver.events.append(transaction, agentStoreEventDraft(parsed));
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
const readEvents = (input) => {
|
|
735
|
+
const parsed = ReadAgentStoreEventsSchema.parse(input);
|
|
736
|
+
return driver.transaction(async (transaction) => AgentStoreEventPageSchema.parse(await driver.events.list(transaction, parsed)), { access: "read" });
|
|
737
|
+
};
|
|
738
|
+
const exportConversation = (conversationId) => driver.transaction(async (transaction) => {
|
|
739
|
+
const events = [];
|
|
740
|
+
let fromSeq;
|
|
741
|
+
do {
|
|
742
|
+
const page = AgentStoreEventPageSchema.parse(await driver.events.list(transaction, ReadAgentStoreEventsSchema.parse({
|
|
743
|
+
conversationId,
|
|
744
|
+
...fromSeq && { fromSeq },
|
|
745
|
+
limit: 1e4
|
|
746
|
+
})));
|
|
747
|
+
events.push(...page.items);
|
|
748
|
+
fromSeq = page.nextSeq;
|
|
749
|
+
} while (fromSeq !== undefined);
|
|
750
|
+
const durable = await driver.archive?.export(transaction, conversationId) ?? {
|
|
751
|
+
projections: [],
|
|
752
|
+
spills: []
|
|
753
|
+
};
|
|
754
|
+
const snapshot = await snapshotIn(transaction, conversationId);
|
|
755
|
+
return encodeAgentConversationArchive({
|
|
756
|
+
format: "stitchkit.agent-conversation",
|
|
757
|
+
formatVersion: 1,
|
|
758
|
+
conversationId,
|
|
759
|
+
events,
|
|
760
|
+
projections: [
|
|
761
|
+
{ archiveType: "runtime-snapshot", snapshot: z2.json().parse(snapshot) },
|
|
762
|
+
...durable.projections
|
|
763
|
+
],
|
|
764
|
+
spills: durable.spills
|
|
765
|
+
});
|
|
766
|
+
}, { access: "read" });
|
|
767
|
+
const importConversation = async (bytes) => {
|
|
768
|
+
const archive = decodeAgentConversationArchive(bytes);
|
|
769
|
+
return driver.transaction(async (transaction) => {
|
|
770
|
+
const existing = await driver.events.list(transaction, {
|
|
771
|
+
conversationId: archive.conversationId,
|
|
772
|
+
limit: 1
|
|
773
|
+
});
|
|
774
|
+
if (existing.items.length > 0) {
|
|
775
|
+
throw new TypeError("Conversation event log must be empty before import");
|
|
776
|
+
}
|
|
777
|
+
for (const event of archive.events) {
|
|
778
|
+
const appended = await driver.events.append(transaction, {
|
|
779
|
+
schemaVersion: event.schemaVersion,
|
|
780
|
+
eventId: event.eventId,
|
|
781
|
+
conversationId: event.conversationId,
|
|
782
|
+
kind: event.kind,
|
|
783
|
+
occurredAt: event.occurredAt,
|
|
784
|
+
payload: event.payload,
|
|
785
|
+
...event.ignorable && { ignorable: true }
|
|
786
|
+
});
|
|
787
|
+
if (appended.seq !== event.seq) {
|
|
788
|
+
throw new TypeError("Conversation archive event sequence is not contiguous");
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
const snapshotEntry = archive.projections.find((entry) => typeof entry === "object" && entry !== null && !Array.isArray(entry) && entry.archiveType === "runtime-snapshot");
|
|
792
|
+
if (snapshotEntry && typeof snapshotEntry === "object" && !Array.isArray(snapshotEntry)) {
|
|
793
|
+
const snapshot = AgentSnapshotSchema.parse(snapshotEntry.snapshot);
|
|
794
|
+
if (snapshot.conversationId !== archive.conversationId) {
|
|
795
|
+
throw new TypeError("Conversation archive snapshot belongs to another conversation");
|
|
796
|
+
}
|
|
797
|
+
if (snapshot.version > 0 || snapshot.messages.length > 0 || snapshot.runs.length > 0) {
|
|
798
|
+
const outcome = await driver.head.compareAndSwap(transaction, {
|
|
799
|
+
conversationId: snapshot.conversationId,
|
|
800
|
+
expectedVersion: 0,
|
|
801
|
+
next: AgentRuntimeHeadSchema.parse({
|
|
802
|
+
schemaVersion: 1,
|
|
803
|
+
conversationId: snapshot.conversationId,
|
|
804
|
+
version: snapshot.version
|
|
805
|
+
})
|
|
806
|
+
});
|
|
807
|
+
if (outcome.outcome !== "applied") {
|
|
808
|
+
throw new TypeError("Conversation archive snapshot target is not empty");
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
for (const run of snapshot.runs) {
|
|
812
|
+
const terminalAssistant = snapshot.messages.find((message) => message.id === run.assistantMessageId);
|
|
813
|
+
await driver.runs.save(transaction, AgentStoredRunSchema.parse({
|
|
814
|
+
schemaVersion: 1,
|
|
815
|
+
run,
|
|
816
|
+
...terminalAssistant && { terminalAssistant }
|
|
817
|
+
}));
|
|
818
|
+
}
|
|
819
|
+
for (const message of snapshot.messages) {
|
|
820
|
+
await driver.history.apply(transaction, { type: "admit", input: message });
|
|
821
|
+
}
|
|
822
|
+
for (const event of archive.events) {
|
|
823
|
+
if (event.kind !== "runtime/transition")
|
|
824
|
+
continue;
|
|
825
|
+
const transition = AgentStoreTransitionSchema.parse(event.payload);
|
|
826
|
+
if (transition.type !== "accept")
|
|
827
|
+
continue;
|
|
828
|
+
const assigned = snapshot.runs.find((run) => run.inputMessageIds.includes(transition.input.input.id));
|
|
829
|
+
if (!assigned) {
|
|
830
|
+
throw new TypeError("Conversation archive admission has no assigned run");
|
|
831
|
+
}
|
|
832
|
+
await driver.admissions.create(transaction, AgentAdmissionReceiptSchema.parse({
|
|
833
|
+
schemaVersion: 1,
|
|
834
|
+
conversationId: archive.conversationId,
|
|
835
|
+
idempotencyKey: transition.input.idempotencyKey,
|
|
836
|
+
input: transition.input.input,
|
|
837
|
+
runId: assigned.id,
|
|
838
|
+
assistantMessageId: assigned.assistantMessageId
|
|
839
|
+
}));
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
await driver.archive?.import(transaction, archive);
|
|
843
|
+
return { conversationId: archive.conversationId, events: archive.events.length };
|
|
844
|
+
});
|
|
845
|
+
};
|
|
803
846
|
return {
|
|
804
847
|
loadSnapshot,
|
|
805
848
|
loadRun,
|
|
806
849
|
listActiveRuns,
|
|
850
|
+
appendEvent,
|
|
851
|
+
readEvents,
|
|
852
|
+
exportConversation,
|
|
853
|
+
importConversation,
|
|
807
854
|
...driver.conversations && {
|
|
808
855
|
purgeConversation: createStoreConversationPurge(driver, driver.conversations)
|
|
809
856
|
},
|
|
@@ -860,6 +907,7 @@ function createMemoryAgentRuntimeStore() {
|
|
|
860
907
|
let runs = new Map;
|
|
861
908
|
let admissions = new Map;
|
|
862
909
|
let histories = new Map;
|
|
910
|
+
let events = new Map;
|
|
863
911
|
let transactionTail = Promise.resolve();
|
|
864
912
|
const driver = {
|
|
865
913
|
async transaction(work) {
|
|
@@ -876,7 +924,11 @@ function createMemoryAgentRuntimeStore() {
|
|
|
876
924
|
heads: cloneHeadMap(heads),
|
|
877
925
|
runs: cloneNestedMap(runs, (record) => AgentStoredRunSchema.parse(structuredClone(record))),
|
|
878
926
|
admissions: cloneNestedMap(admissions, (receipt) => AgentAdmissionReceiptSchema.parse(structuredClone(receipt))),
|
|
879
|
-
histories: cloneHistoryMap(histories)
|
|
927
|
+
histories: cloneHistoryMap(histories),
|
|
928
|
+
events: new Map([...events].map(([conversationId, stored]) => [
|
|
929
|
+
conversationId,
|
|
930
|
+
stored.map((event) => AgentStoreEventEnvelopeSchema.parse(structuredClone(event)))
|
|
931
|
+
]))
|
|
880
932
|
};
|
|
881
933
|
try {
|
|
882
934
|
const result = await work(transaction);
|
|
@@ -885,6 +937,7 @@ function createMemoryAgentRuntimeStore() {
|
|
|
885
937
|
runs = transaction.runs;
|
|
886
938
|
admissions = transaction.admissions;
|
|
887
939
|
histories = transaction.histories;
|
|
940
|
+
events = transaction.events;
|
|
888
941
|
return result;
|
|
889
942
|
} finally {
|
|
890
943
|
release.resolve();
|
|
@@ -900,6 +953,7 @@ function createMemoryAgentRuntimeStore() {
|
|
|
900
953
|
transaction.runs.delete(conversationId);
|
|
901
954
|
transaction.admissions.delete(conversationId);
|
|
902
955
|
transaction.histories.delete(conversationId);
|
|
956
|
+
transaction.events.delete(conversationId);
|
|
903
957
|
}
|
|
904
958
|
},
|
|
905
959
|
head: {
|
|
@@ -995,6 +1049,29 @@ function createMemoryAgentRuntimeStore() {
|
|
|
995
1049
|
]);
|
|
996
1050
|
}
|
|
997
1051
|
},
|
|
1052
|
+
events: {
|
|
1053
|
+
async append(transaction, draft) {
|
|
1054
|
+
const current = transaction.events.get(draft.conversationId) ?? [];
|
|
1055
|
+
const event = AgentStoreEventEnvelopeSchema.parse({
|
|
1056
|
+
...draft,
|
|
1057
|
+
seq: (current.at(-1)?.seq ?? 0) + 1
|
|
1058
|
+
});
|
|
1059
|
+
if (current.some((candidate) => candidate.eventId === event.eventId)) {
|
|
1060
|
+
throw new TypeError("Agent store event identity is already present");
|
|
1061
|
+
}
|
|
1062
|
+
transaction.events.set(draft.conversationId, [...current, event]);
|
|
1063
|
+
return event;
|
|
1064
|
+
},
|
|
1065
|
+
async list(transaction, input) {
|
|
1066
|
+
const selected = (transaction.events.get(input.conversationId) ?? []).filter((event) => (input.fromSeq === undefined || event.seq >= input.fromSeq) && (input.toSeq === undefined || event.seq <= input.toSeq));
|
|
1067
|
+
const items = selected.slice(0, input.limit);
|
|
1068
|
+
const last = items.at(-1);
|
|
1069
|
+
return AgentStoreEventPageSchema.parse({
|
|
1070
|
+
items,
|
|
1071
|
+
...selected.length > items.length && last ? { nextSeq: last.seq + 1 } : {}
|
|
1072
|
+
});
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
998
1075
|
async scanRecoverable(input) {
|
|
999
1076
|
const descriptors = [...runs].flatMap(([conversationId, conversationRuns]) => [...conversationRuns.values()].filter((record) => isActiveRunState(record.run.state)).map((record) => ({ conversationId, run: record.run }))).sort((left, right) => left.conversationId.localeCompare(right.conversationId) || left.run.id.localeCompare(right.run.id));
|
|
1000
1077
|
const cursorTuple = input.cursor ? parseRecoverableCursor(input.cursor) : undefined;
|
|
@@ -1014,4 +1091,4 @@ function createMemoryAgentRuntimeStore() {
|
|
|
1014
1091
|
return createAgentRuntimeStore(driver);
|
|
1015
1092
|
}
|
|
1016
1093
|
|
|
1017
|
-
export {
|
|
1094
|
+
export { AgentConversationPurgeInputSchema, AgentConversationPurgeResultSchema, AgentConversationPurgedError, purgeAgentConversation, AgentRuntimeHeadSchema, AgentStoredRunSchema, AgentAdmissionReceiptSchema, AgentHistoryMutationSchema, ACTIVE_AGENT_RUN_STATES, createAgentRuntimeStore, createMemoryAgentRuntimeStore };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentMessageSchema,
|
|
3
|
+
AgentRecordIdSchema,
|
|
4
|
+
AgentRecordVersionSchema
|
|
5
|
+
} from "./index-p1b1y93x.js";
|
|
6
|
+
|
|
7
|
+
// src/agent-runtime/conversations.ts
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
var AgentConversationSummarySchema = z.object({
|
|
10
|
+
conversationId: AgentRecordIdSchema,
|
|
11
|
+
version: AgentRecordVersionSchema,
|
|
12
|
+
updatedAt: z.iso.datetime({ offset: true }),
|
|
13
|
+
preview: z.string(),
|
|
14
|
+
activeRuns: z.int().nonnegative()
|
|
15
|
+
}).strict();
|
|
16
|
+
var AgentConversationPageSchema = z.object({
|
|
17
|
+
items: z.array(AgentConversationSummarySchema),
|
|
18
|
+
nextCursor: z.string().min(1).optional()
|
|
19
|
+
}).strict();
|
|
20
|
+
var AgentConversationMessagePageSchema = z.object({
|
|
21
|
+
items: z.array(AgentMessageSchema),
|
|
22
|
+
compacted: z.array(z.string().min(1)),
|
|
23
|
+
nextCursor: z.string().min(1).optional()
|
|
24
|
+
}).strict();
|
|
25
|
+
|
|
26
|
+
export { AgentConversationSummarySchema, AgentConversationPageSchema, AgentConversationMessagePageSchema };
|
|
@@ -3,19 +3,19 @@ import {
|
|
|
3
3
|
} from "./index-sbdmyz75.js";
|
|
4
4
|
import {
|
|
5
5
|
collectToolSurface
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-rcgsnrr6.js";
|
|
7
7
|
import {
|
|
8
8
|
createToolRunner,
|
|
9
9
|
formatToolError
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-0vfdh685.js";
|
|
11
11
|
import {
|
|
12
12
|
toolResultFromError
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-wn9cb82y.js";
|
|
14
14
|
import {
|
|
15
15
|
assertUniqueToolName,
|
|
16
16
|
buildToolPresentationSchema,
|
|
17
17
|
objectShapeKeys
|
|
18
|
-
} from "./index-
|
|
18
|
+
} from "./index-r159gjwy.js";
|
|
19
19
|
import {
|
|
20
20
|
jsonSchemaFields
|
|
21
21
|
} from "./index-cby4ar3v.js";
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/agent-runtime/testing.ts
|
|
2
|
+
function createAgentRaceBarrier(timeoutMs = 5000) {
|
|
3
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1) {
|
|
4
|
+
throw new TypeError("Agent race barrier timeoutMs must be a positive safe integer");
|
|
5
|
+
}
|
|
6
|
+
const reached = Promise.withResolvers();
|
|
7
|
+
const released = Promise.withResolvers();
|
|
8
|
+
let announced = false;
|
|
9
|
+
return {
|
|
10
|
+
reached: reached.promise,
|
|
11
|
+
async wait() {
|
|
12
|
+
if (!announced) {
|
|
13
|
+
announced = true;
|
|
14
|
+
reached.resolve();
|
|
15
|
+
}
|
|
16
|
+
let timer;
|
|
17
|
+
try {
|
|
18
|
+
await Promise.race([
|
|
19
|
+
released.promise,
|
|
20
|
+
new Promise((_resolve, reject) => {
|
|
21
|
+
timer = setTimeout(() => reject(new Error(`Agent race barrier exceeded ${timeoutMs}ms teardown bound`)), timeoutMs);
|
|
22
|
+
})
|
|
23
|
+
]);
|
|
24
|
+
} finally {
|
|
25
|
+
if (timer !== undefined)
|
|
26
|
+
clearTimeout(timer);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
release: released.resolve
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function createAgentRaceTrace() {
|
|
33
|
+
const recorded = [];
|
|
34
|
+
return {
|
|
35
|
+
record(name) {
|
|
36
|
+
const entry = { name, sequence: recorded.length };
|
|
37
|
+
recorded.push(entry);
|
|
38
|
+
return entry;
|
|
39
|
+
},
|
|
40
|
+
entries: () => recorded.map((entry) => ({ ...entry })),
|
|
41
|
+
assertBefore(first, second) {
|
|
42
|
+
const firstEntry = recorded.find((entry) => entry.name === first);
|
|
43
|
+
const secondEntry = recorded.find((entry) => entry.name === second);
|
|
44
|
+
if (!firstEntry || !secondEntry || firstEntry.sequence >= secondEntry.sequence) {
|
|
45
|
+
throw new Error(`Expected ${first} before ${second}`);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
assertSequence(names) {
|
|
49
|
+
const actual = recorded.map((entry) => entry.name);
|
|
50
|
+
if (actual.length !== names.length || actual.some((name, index) => name !== names[index])) {
|
|
51
|
+
throw new Error(`Expected trace ${names.join(" -> ")}, received ${actual.join(" -> ")}`);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
count: (name) => recorded.filter((entry) => entry.name === name).length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createAgentRaceDriver(timeoutMs = 5000) {
|
|
58
|
+
const trace = createAgentRaceTrace();
|
|
59
|
+
const barriers = new Map;
|
|
60
|
+
return {
|
|
61
|
+
trace,
|
|
62
|
+
barrier(name) {
|
|
63
|
+
const existing = barriers.get(name);
|
|
64
|
+
if (existing)
|
|
65
|
+
return existing;
|
|
66
|
+
const created = createAgentRaceBarrier(timeoutMs);
|
|
67
|
+
barriers.set(name, created);
|
|
68
|
+
return created;
|
|
69
|
+
},
|
|
70
|
+
releaseAll() {
|
|
71
|
+
for (const barrier of barriers.values())
|
|
72
|
+
barrier.release();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { createAgentRaceBarrier, createAgentRaceTrace, createAgentRaceDriver };
|