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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/agent-runtime/sandbox.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var AgentSandboxRestrictionSchema = z.enum([
|
|
4
|
+
"network-denied",
|
|
5
|
+
"write-contained",
|
|
6
|
+
"secrets-hidden",
|
|
7
|
+
"process-contained"
|
|
8
|
+
]);
|
|
9
|
+
var AgentSandboxGradeSchema = z.discriminatedUnion("grade", [
|
|
10
|
+
z.object({ grade: z.literal("full"), restrictions: z.array(AgentSandboxRestrictionSchema) }).strict(),
|
|
11
|
+
z.object({
|
|
12
|
+
grade: z.literal("partial"),
|
|
13
|
+
restrictions: z.array(AgentSandboxRestrictionSchema),
|
|
14
|
+
gaps: z.array(AgentSandboxRestrictionSchema)
|
|
15
|
+
}).strict(),
|
|
16
|
+
z.object({ grade: z.literal("unavailable"), reason: z.string().min(1) }).strict()
|
|
17
|
+
]);
|
|
18
|
+
var probes = new WeakMap;
|
|
19
|
+
function probeAgentProcessSandbox(sandbox, options = {}) {
|
|
20
|
+
if (options.refresh)
|
|
21
|
+
probes.delete(sandbox);
|
|
22
|
+
const present = probes.get(sandbox);
|
|
23
|
+
if (present)
|
|
24
|
+
return present;
|
|
25
|
+
const pending = Promise.resolve(sandbox.probe()).then((grade) => AgentSandboxGradeSchema.parse(grade));
|
|
26
|
+
probes.set(sandbox, pending);
|
|
27
|
+
return pending;
|
|
28
|
+
}
|
|
29
|
+
function missingSandboxRestrictions(grade, required) {
|
|
30
|
+
if (grade.grade === "unavailable")
|
|
31
|
+
return required;
|
|
32
|
+
const present = new Set(grade.restrictions);
|
|
33
|
+
return required.filter((restriction) => !present.has(restriction));
|
|
34
|
+
}
|
|
35
|
+
async function recordAgentSandboxProbe(input) {
|
|
36
|
+
const grade = await probeAgentProcessSandbox(input.sandbox);
|
|
37
|
+
const missing = missingSandboxRestrictions(grade, input.required);
|
|
38
|
+
await input.store.appendEvent({
|
|
39
|
+
conversationId: input.conversationId,
|
|
40
|
+
kind: "sandbox/probed",
|
|
41
|
+
payload: {
|
|
42
|
+
result: grade,
|
|
43
|
+
required: [...input.required],
|
|
44
|
+
missing: [...missing]
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return grade;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { AgentSandboxRestrictionSchema, AgentSandboxGradeSchema, probeAgentProcessSandbox, missingSandboxRestrictions, recordAgentSandboxProbe };
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
AgentRunStateSchema,
|
|
11
11
|
AgentTerminalReasonSchema,
|
|
12
12
|
AgentTimestampSchema
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-p1b1y93x.js";
|
|
14
14
|
|
|
15
15
|
// src/agent-runtime/event-schema.ts
|
|
16
16
|
import { z } from "zod";
|
|
@@ -51,6 +51,12 @@ var AgentReasoningDeltaEventSchema = AgentTransientReasoningIdentitySchema.exten
|
|
|
51
51
|
var AgentReasoningEndEventSchema = AgentTransientReasoningIdentitySchema.extend({
|
|
52
52
|
type: z.literal("reasoning-end")
|
|
53
53
|
});
|
|
54
|
+
var AgentAttemptResetEventSchema = 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
|
+
});
|
|
54
60
|
var AgentCheckpointEventSchema = EventIdentitySchema.extend({
|
|
55
61
|
type: z.literal("assistant-checkpoint"),
|
|
56
62
|
eventId: AgentRecordIdSchema,
|
|
@@ -95,6 +101,7 @@ var AgentRuntimeEventSchema = z.discriminatedUnion("type", [
|
|
|
95
101
|
AgentReasoningStartEventSchema,
|
|
96
102
|
AgentReasoningDeltaEventSchema,
|
|
97
103
|
AgentReasoningEndEventSchema,
|
|
104
|
+
AgentAttemptResetEventSchema,
|
|
98
105
|
AgentCheckpointEventSchema,
|
|
99
106
|
AgentRunStateEventSchema,
|
|
100
107
|
AgentRunOperationEventSchema,
|
|
@@ -140,4 +147,4 @@ function agentDurableEventId(type, runId, snapshotVersion) {
|
|
|
140
147
|
return `${runId}:${type}:${snapshotVersion}`;
|
|
141
148
|
}
|
|
142
149
|
|
|
143
|
-
export { AgentAdmissionEventSchema, AgentTransientDeltaEventSchema, AgentReasoningStartEventSchema, AgentReasoningDeltaEventSchema, AgentReasoningEndEventSchema, AgentCheckpointEventSchema, AgentRunStateEventSchema, AgentRunOperationEventSchema, AgentToolStatusEventSchema, AgentTerminalEventSchema, AgentRuntimeEventSchema, AgentRuntimeEventCursorSchema, advanceAgentRuntimeEventCursor, agentDurableEventId };
|
|
150
|
+
export { AgentAdmissionEventSchema, AgentTransientDeltaEventSchema, AgentReasoningStartEventSchema, AgentReasoningDeltaEventSchema, AgentReasoningEndEventSchema, AgentAttemptResetEventSchema, AgentCheckpointEventSchema, AgentRunStateEventSchema, AgentRunOperationEventSchema, AgentToolStatusEventSchema, AgentTerminalEventSchema, AgentRuntimeEventSchema, AgentRuntimeEventCursorSchema, advanceAgentRuntimeEventCursor, agentDurableEventId };
|
|
@@ -858,11 +858,18 @@ function assertProjectedName(name, serviceName, action, transport, derived) {
|
|
|
858
858
|
function projectToolSurface(surface, transport, config = {}) {
|
|
859
859
|
const projected = [];
|
|
860
860
|
const names = new Set;
|
|
861
|
+
const origins = new Map;
|
|
861
862
|
const append = (tool) => {
|
|
862
863
|
if (config.assertUniqueNames ?? true) {
|
|
863
|
-
|
|
864
|
+
if (names.has(tool.name)) {
|
|
865
|
+
const previous = origins.get(tool.name) ?? "unknown";
|
|
866
|
+
const current = `${tool.serviceName}.${tool.action}`;
|
|
867
|
+
throw new Error(`Duplicate ${duplicateLabel(transport)} "${tool.name}" across mounted operations: ${previous}, ${current}`);
|
|
868
|
+
}
|
|
869
|
+
assertUniqueToolName(tool.name, false, duplicateLabel(transport));
|
|
864
870
|
}
|
|
865
871
|
names.add(tool.name);
|
|
872
|
+
origins.set(tool.name, `${tool.serviceName}.${tool.action}`);
|
|
866
873
|
projected.push(tool);
|
|
867
874
|
};
|
|
868
875
|
for (const service of surface.services ?? []) {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runtimeToolMountable
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-kc6h6hg0.js";
|
|
4
4
|
import {
|
|
5
5
|
contractToolMountable
|
|
6
|
-
} from "./index-
|
|
6
|
+
} from "./index-0vfdh685.js";
|
|
7
7
|
import {
|
|
8
8
|
projectToolSurface
|
|
9
|
-
} from "./index-
|
|
9
|
+
} from "./index-r159gjwy.js";
|
|
10
10
|
|
|
11
11
|
// src/tools/surface.ts
|
|
12
12
|
function collectToolSurface({
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentMessageSchema,
|
|
3
|
+
AgentRecordIdSchema,
|
|
4
|
+
AgentRecordVersionSchema,
|
|
5
|
+
AgentRunOperationSchema,
|
|
6
|
+
AgentRunSchema,
|
|
7
|
+
AgentSnapshotSchema,
|
|
8
|
+
AgentTerminalReasonSchema,
|
|
9
|
+
AgentUsageSchema
|
|
10
|
+
} from "./index-p1b1y93x.js";
|
|
11
|
+
|
|
12
|
+
// src/agent-runtime/history-chronology.ts
|
|
13
|
+
function createToolChronology() {
|
|
14
|
+
return { calls: new Map, approvals: new Map, pending: 0, resultsStarted: false };
|
|
15
|
+
}
|
|
16
|
+
function advanceToolChronology(previous, parts) {
|
|
17
|
+
const calls = new Map(previous.calls);
|
|
18
|
+
const approvals = new Map(previous.approvals);
|
|
19
|
+
let { pending, resultsStarted } = previous;
|
|
20
|
+
for (const part of parts) {
|
|
21
|
+
if (part.type === "tool-call") {
|
|
22
|
+
if (calls.has(part.callId) || resultsStarted && pending > 0)
|
|
23
|
+
return;
|
|
24
|
+
if (pending === 0)
|
|
25
|
+
resultsStarted = false;
|
|
26
|
+
calls.set(part.callId, { toolName: part.toolName, phase: "called" });
|
|
27
|
+
pending += 1;
|
|
28
|
+
} else if (part.type === "tool-approval-request") {
|
|
29
|
+
const call = calls.get(part.callId);
|
|
30
|
+
if (call?.phase !== "called" || approvals.has(part.approvalId))
|
|
31
|
+
return;
|
|
32
|
+
approvals.set(part.approvalId, part.callId);
|
|
33
|
+
calls.set(part.callId, { ...call, phase: "requested" });
|
|
34
|
+
} else if (part.type === "tool-approval-response") {
|
|
35
|
+
const callId = approvals.get(part.approvalId);
|
|
36
|
+
const call = callId === undefined ? undefined : calls.get(callId);
|
|
37
|
+
if (callId === undefined || !call || call.phase !== "requested")
|
|
38
|
+
return;
|
|
39
|
+
calls.set(callId, { ...call, phase: part.approved ? "approved" : "denied" });
|
|
40
|
+
} else if (part.type === "tool-result") {
|
|
41
|
+
const call = calls.get(part.callId);
|
|
42
|
+
if (!call || call.toolName !== part.toolName || call.phase === "result" || call.phase === "requested" || call.phase === "denied" && part.outcome === "success")
|
|
43
|
+
return;
|
|
44
|
+
calls.set(part.callId, { ...call, phase: "result" });
|
|
45
|
+
pending -= 1;
|
|
46
|
+
resultsStarted = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return { calls, approvals, pending, resultsStarted };
|
|
50
|
+
}
|
|
51
|
+
function canProjectToolChronology(state) {
|
|
52
|
+
return [...state.calls.values()].every(({ phase }) => phase !== "called");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/agent-runtime/terminal-status.ts
|
|
56
|
+
function isSpeakableAssistantStatus(status) {
|
|
57
|
+
return status === "completed" || status === "interrupted" || status === "committed";
|
|
58
|
+
}
|
|
59
|
+
function isAssistantHistoryEvidence(status, policy) {
|
|
60
|
+
return isSpeakableAssistantStatus(status) || status === "failed" && policy?.failedAssistant === "assistant-marked";
|
|
61
|
+
}
|
|
62
|
+
function isCompleteAgentHistoryTurn(messages, policy) {
|
|
63
|
+
if (messages[0]?.role !== "user")
|
|
64
|
+
return false;
|
|
65
|
+
let chronology = createToolChronology();
|
|
66
|
+
let assistantCount = 0;
|
|
67
|
+
for (const message of messages) {
|
|
68
|
+
if (message.role === "assistant") {
|
|
69
|
+
if (!isAssistantHistoryEvidence(message.status, policy))
|
|
70
|
+
return false;
|
|
71
|
+
assistantCount += 1;
|
|
72
|
+
}
|
|
73
|
+
const next = advanceToolChronology(chronology, message.parts);
|
|
74
|
+
if (!next)
|
|
75
|
+
return false;
|
|
76
|
+
chronology = next;
|
|
77
|
+
}
|
|
78
|
+
return assistantCount > 0 && chronology.pending === 0;
|
|
79
|
+
}
|
|
80
|
+
function assistantStatus(reason) {
|
|
81
|
+
if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
|
|
82
|
+
return "completed";
|
|
83
|
+
}
|
|
84
|
+
if (reason === "superseded")
|
|
85
|
+
return "superseded";
|
|
86
|
+
if (reason === "absorbed")
|
|
87
|
+
return "superseded";
|
|
88
|
+
if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
|
|
89
|
+
return "interrupted";
|
|
90
|
+
}
|
|
91
|
+
return "failed";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/agent-runtime/store.ts
|
|
95
|
+
import { z } from "zod";
|
|
96
|
+
var AgentStoreConflictSchema = z.object({
|
|
97
|
+
outcome: z.literal("conflict"),
|
|
98
|
+
actualVersion: AgentRecordVersionSchema
|
|
99
|
+
});
|
|
100
|
+
var AgentStoreNotFoundSchema = z.object({ outcome: z.literal("not_found") });
|
|
101
|
+
var AgentStoreAppliedSchema = z.object({
|
|
102
|
+
outcome: z.literal("applied"),
|
|
103
|
+
snapshot: AgentSnapshotSchema
|
|
104
|
+
});
|
|
105
|
+
var AgentStoreDuplicateSchema = z.object({
|
|
106
|
+
outcome: z.literal("duplicate"),
|
|
107
|
+
input: AgentMessageSchema,
|
|
108
|
+
inputMessageId: AgentRecordIdSchema,
|
|
109
|
+
runId: AgentRecordIdSchema,
|
|
110
|
+
assistantMessageId: AgentRecordIdSchema,
|
|
111
|
+
run: AgentRunSchema,
|
|
112
|
+
assistant: AgentMessageSchema.optional(),
|
|
113
|
+
snapshot: AgentSnapshotSchema
|
|
114
|
+
});
|
|
115
|
+
var AgentStoreMutationResultSchema = z.discriminatedUnion("outcome", [
|
|
116
|
+
AgentStoreAppliedSchema,
|
|
117
|
+
AgentStoreDuplicateSchema,
|
|
118
|
+
AgentStoreConflictSchema,
|
|
119
|
+
AgentStoreNotFoundSchema
|
|
120
|
+
]);
|
|
121
|
+
var AgentRunViewSchema = z.object({
|
|
122
|
+
snapshotVersion: AgentRecordVersionSchema,
|
|
123
|
+
run: AgentRunSchema,
|
|
124
|
+
assistant: AgentMessageSchema.optional()
|
|
125
|
+
});
|
|
126
|
+
var AcceptInputAndAssignRunSchema = z.object({
|
|
127
|
+
idempotencyKey: z.string().min(1),
|
|
128
|
+
expectedVersion: AgentRecordVersionSchema.optional(),
|
|
129
|
+
input: AgentMessageSchema,
|
|
130
|
+
run: AgentRunSchema,
|
|
131
|
+
coalesceIntoRunId: AgentRecordIdSchema.optional()
|
|
132
|
+
});
|
|
133
|
+
var AcquireAgentRunSchema = z.object({
|
|
134
|
+
conversationId: AgentRecordIdSchema,
|
|
135
|
+
runId: AgentRecordIdSchema,
|
|
136
|
+
expectedRevision: AgentRecordVersionSchema,
|
|
137
|
+
ownerId: z.string().min(1)
|
|
138
|
+
});
|
|
139
|
+
var CheckpointRunAssistantSchema = z.object({
|
|
140
|
+
conversationId: AgentRecordIdSchema,
|
|
141
|
+
runId: AgentRecordIdSchema,
|
|
142
|
+
expectedRevision: AgentRecordVersionSchema,
|
|
143
|
+
ownerId: z.string().min(1),
|
|
144
|
+
fencingToken: AgentRecordVersionSchema.optional(),
|
|
145
|
+
assistant: AgentMessageSchema,
|
|
146
|
+
usage: AgentUsageSchema.optional()
|
|
147
|
+
});
|
|
148
|
+
var RecordRunOperationSchema = z.object({
|
|
149
|
+
conversationId: AgentRecordIdSchema,
|
|
150
|
+
runId: AgentRecordIdSchema,
|
|
151
|
+
expectedRevision: AgentRecordVersionSchema,
|
|
152
|
+
ownerId: z.string().min(1),
|
|
153
|
+
fencingToken: AgentRecordVersionSchema.optional(),
|
|
154
|
+
operation: AgentRunOperationSchema
|
|
155
|
+
});
|
|
156
|
+
var CommitRunTerminalSchema = z.object({
|
|
157
|
+
conversationId: AgentRecordIdSchema,
|
|
158
|
+
runId: AgentRecordIdSchema,
|
|
159
|
+
expectedRevision: AgentRecordVersionSchema,
|
|
160
|
+
ownerId: z.string().min(1),
|
|
161
|
+
fencingToken: AgentRecordVersionSchema.optional(),
|
|
162
|
+
assistant: AgentMessageSchema,
|
|
163
|
+
reason: AgentTerminalReasonSchema,
|
|
164
|
+
policyName: z.string().min(1).optional(),
|
|
165
|
+
usage: AgentUsageSchema.optional(),
|
|
166
|
+
absorb: z.array(z.object({
|
|
167
|
+
runId: AgentRecordIdSchema,
|
|
168
|
+
inputMessageIds: z.array(AgentRecordIdSchema).min(1)
|
|
169
|
+
})).min(1).optional()
|
|
170
|
+
});
|
|
171
|
+
var RequestRunInterruptSchema = z.object({
|
|
172
|
+
conversationId: AgentRecordIdSchema,
|
|
173
|
+
runId: AgentRecordIdSchema,
|
|
174
|
+
expectedRevision: AgentRecordVersionSchema
|
|
175
|
+
});
|
|
176
|
+
var RecoverAgentRunSchema = z.object({
|
|
177
|
+
conversationId: AgentRecordIdSchema,
|
|
178
|
+
runId: AgentRecordIdSchema,
|
|
179
|
+
expectedRevision: AgentRecordVersionSchema,
|
|
180
|
+
action: z.enum(["requeue", "abandon"]),
|
|
181
|
+
replaySafe: z.boolean().optional()
|
|
182
|
+
});
|
|
183
|
+
var ReplaceCompactedRangeSchema = z.object({
|
|
184
|
+
conversationId: AgentRecordIdSchema,
|
|
185
|
+
expectedVersion: AgentRecordVersionSchema,
|
|
186
|
+
replacedMessageIds: z.array(AgentRecordIdSchema).min(1),
|
|
187
|
+
summary: AgentMessageSchema
|
|
188
|
+
});
|
|
189
|
+
var AgentRecoverableDescriptorSchema = z.object({
|
|
190
|
+
conversationId: AgentRecordIdSchema,
|
|
191
|
+
run: AgentRunSchema
|
|
192
|
+
});
|
|
193
|
+
var AgentRecoverablePageSchema = z.object({
|
|
194
|
+
items: z.array(AgentRecoverableDescriptorSchema),
|
|
195
|
+
nextCursor: z.string().min(1).optional()
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// src/agent-runtime/store-events.ts
|
|
199
|
+
import { randomUUID } from "node:crypto";
|
|
200
|
+
import { z as z2 } from "zod";
|
|
201
|
+
var AgentStoreEventKindSchema = z2.enum([
|
|
202
|
+
"runtime/baseline",
|
|
203
|
+
"runtime/transition",
|
|
204
|
+
"provider/request",
|
|
205
|
+
"provider/message",
|
|
206
|
+
"state/set",
|
|
207
|
+
"spill/created",
|
|
208
|
+
"spill/deleted",
|
|
209
|
+
"schedule/set",
|
|
210
|
+
"schedule/fired",
|
|
211
|
+
"schedule/cancelled",
|
|
212
|
+
"schedule/late",
|
|
213
|
+
"schedule/failed",
|
|
214
|
+
"child/spawned",
|
|
215
|
+
"child/state",
|
|
216
|
+
"retry/scheduled",
|
|
217
|
+
"retry/started",
|
|
218
|
+
"sandbox/probed"
|
|
219
|
+
]);
|
|
220
|
+
var AgentStoreTransitionSchema = z2.discriminatedUnion("type", [
|
|
221
|
+
z2.object({ type: z2.literal("accept"), input: AcceptInputAndAssignRunSchema }).strict(),
|
|
222
|
+
z2.object({ type: z2.literal("acquire"), input: AcquireAgentRunSchema }).strict(),
|
|
223
|
+
z2.object({ type: z2.literal("checkpoint"), input: CheckpointRunAssistantSchema }).strict(),
|
|
224
|
+
z2.object({ type: z2.literal("operation"), input: RecordRunOperationSchema }).strict(),
|
|
225
|
+
z2.object({ type: z2.literal("interrupt"), input: RequestRunInterruptSchema }).strict(),
|
|
226
|
+
z2.object({ type: z2.literal("recover"), input: RecoverAgentRunSchema }).strict(),
|
|
227
|
+
z2.object({ type: z2.literal("terminal"), input: CommitRunTerminalSchema }).strict(),
|
|
228
|
+
z2.object({ type: z2.literal("compact"), input: ReplaceCompactedRangeSchema }).strict()
|
|
229
|
+
]);
|
|
230
|
+
var AgentStoreEventEnvelopeSchema = z2.object({
|
|
231
|
+
schemaVersion: z2.int().positive(),
|
|
232
|
+
eventId: z2.string().min(1),
|
|
233
|
+
conversationId: z2.string().min(1),
|
|
234
|
+
seq: z2.int().positive(),
|
|
235
|
+
kind: z2.string().min(1),
|
|
236
|
+
occurredAt: z2.iso.datetime({ offset: true }),
|
|
237
|
+
payload: z2.json(),
|
|
238
|
+
ignorable: z2.literal(true).optional()
|
|
239
|
+
}).strict();
|
|
240
|
+
var AppendAgentStoreEventSchema = z2.object({
|
|
241
|
+
conversationId: z2.string().min(1),
|
|
242
|
+
kind: AgentStoreEventKindSchema,
|
|
243
|
+
occurredAt: z2.iso.datetime({ offset: true }).optional(),
|
|
244
|
+
payload: z2.json(),
|
|
245
|
+
ignorable: z2.literal(true).optional()
|
|
246
|
+
}).strict();
|
|
247
|
+
var ReadAgentStoreEventsSchema = z2.object({
|
|
248
|
+
conversationId: z2.string().min(1),
|
|
249
|
+
fromSeq: z2.int().positive().optional(),
|
|
250
|
+
toSeq: z2.int().positive().optional(),
|
|
251
|
+
limit: z2.int().positive().max(1e4).default(1000)
|
|
252
|
+
}).strict().refine((input) => input.fromSeq === undefined || input.toSeq === undefined || input.fromSeq <= input.toSeq, { message: "fromSeq must not exceed toSeq" });
|
|
253
|
+
var AgentStoreEventPageSchema = z2.object({
|
|
254
|
+
items: z2.array(AgentStoreEventEnvelopeSchema),
|
|
255
|
+
nextSeq: z2.int().positive().optional()
|
|
256
|
+
}).strict();
|
|
257
|
+
var CURRENT_EVENT_SCHEMA_VERSION = 1;
|
|
258
|
+
function decodeAgentStoreEvent(value) {
|
|
259
|
+
const envelope = AgentStoreEventEnvelopeSchema.parse(value);
|
|
260
|
+
const knownVersion = envelope.schemaVersion === CURRENT_EVENT_SCHEMA_VERSION;
|
|
261
|
+
const knownKind = AgentStoreEventKindSchema.safeParse(envelope.kind).success;
|
|
262
|
+
if (knownVersion && knownKind)
|
|
263
|
+
return { outcome: "accepted", event: envelope };
|
|
264
|
+
if (!envelope.ignorable) {
|
|
265
|
+
throw new TypeError(`Unsupported agent store event at ${envelope.conversationId}:${envelope.seq} ` + `(${envelope.eventId}): schema ${envelope.schemaVersion}, kind ${envelope.kind}`);
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
outcome: "ignored",
|
|
269
|
+
eventId: envelope.eventId,
|
|
270
|
+
conversationId: envelope.conversationId,
|
|
271
|
+
seq: envelope.seq,
|
|
272
|
+
schemaVersion: envelope.schemaVersion,
|
|
273
|
+
kind: envelope.kind
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function agentStoreEventDraft(input) {
|
|
277
|
+
const parsed = AppendAgentStoreEventSchema.parse(input);
|
|
278
|
+
return {
|
|
279
|
+
schemaVersion: CURRENT_EVENT_SCHEMA_VERSION,
|
|
280
|
+
eventId: randomUUID(),
|
|
281
|
+
conversationId: parsed.conversationId,
|
|
282
|
+
kind: parsed.kind,
|
|
283
|
+
occurredAt: parsed.occurredAt ?? new Date().toISOString(),
|
|
284
|
+
payload: parsed.payload,
|
|
285
|
+
...parsed.ignorable && { ignorable: true }
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function canonicalJsonValue(value) {
|
|
289
|
+
if (value === null || typeof value === "boolean" || typeof value === "number") {
|
|
290
|
+
return JSON.stringify(value);
|
|
291
|
+
}
|
|
292
|
+
if (typeof value === "string")
|
|
293
|
+
return JSON.stringify(value);
|
|
294
|
+
if (Array.isArray(value))
|
|
295
|
+
return `[${value.map(canonicalJsonValue).join(",")}]`;
|
|
296
|
+
const record = z2.record(z2.string(), z2.json()).parse(value);
|
|
297
|
+
return `{${Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonValue(record[key])}`).join(",")}}`;
|
|
298
|
+
}
|
|
299
|
+
function canonicalAgentJson(value) {
|
|
300
|
+
return canonicalJsonValue(z2.json().parse(value));
|
|
301
|
+
}
|
|
302
|
+
var AgentConversationArchiveSchema = z2.object({
|
|
303
|
+
format: z2.literal("stitchkit.agent-conversation"),
|
|
304
|
+
formatVersion: z2.literal(1),
|
|
305
|
+
conversationId: z2.string().min(1),
|
|
306
|
+
events: z2.array(AgentStoreEventEnvelopeSchema),
|
|
307
|
+
projections: z2.array(z2.json()).default([]),
|
|
308
|
+
spills: z2.array(z2.json()).default([])
|
|
309
|
+
}).strict();
|
|
310
|
+
function encodeAgentConversationArchive(archive) {
|
|
311
|
+
const parsed = AgentConversationArchiveSchema.parse(archive);
|
|
312
|
+
return new TextEncoder().encode(canonicalAgentJson(parsed));
|
|
313
|
+
}
|
|
314
|
+
function decodeAgentConversationArchive(bytes) {
|
|
315
|
+
const value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
316
|
+
const archive = AgentConversationArchiveSchema.parse(value);
|
|
317
|
+
let previous = 0;
|
|
318
|
+
const ids = new Set;
|
|
319
|
+
for (const event of archive.events) {
|
|
320
|
+
if (event.conversationId !== archive.conversationId) {
|
|
321
|
+
throw new TypeError("Conversation archive contains an event for another conversation");
|
|
322
|
+
}
|
|
323
|
+
if (event.seq <= previous)
|
|
324
|
+
throw new TypeError("Conversation archive event sequence is not increasing");
|
|
325
|
+
if (ids.has(event.eventId))
|
|
326
|
+
throw new TypeError("Conversation archive contains a duplicate event id");
|
|
327
|
+
decodeAgentStoreEvent(event);
|
|
328
|
+
previous = event.seq;
|
|
329
|
+
ids.add(event.eventId);
|
|
330
|
+
}
|
|
331
|
+
return archive;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export { createToolChronology, advanceToolChronology, canProjectToolChronology, isAssistantHistoryEvidence, isCompleteAgentHistoryTurn, assistantStatus, AgentStoreConflictSchema, AgentStoreNotFoundSchema, AgentStoreAppliedSchema, AgentStoreDuplicateSchema, AgentStoreMutationResultSchema, AgentRunViewSchema, AcceptInputAndAssignRunSchema, AcquireAgentRunSchema, CheckpointRunAssistantSchema, RecordRunOperationSchema, CommitRunTerminalSchema, RequestRunInterruptSchema, RecoverAgentRunSchema, ReplaceCompactedRangeSchema, AgentRecoverableDescriptorSchema, AgentRecoverablePageSchema, AgentStoreEventKindSchema, AgentStoreTransitionSchema, AgentStoreEventEnvelopeSchema, AppendAgentStoreEventSchema, ReadAgentStoreEventsSchema, AgentStoreEventPageSchema, decodeAgentStoreEvent, agentStoreEventDraft, canonicalAgentJson, AgentConversationArchiveSchema, encodeAgentConversationArchive, decodeAgentConversationArchive };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentRuntimeEventSchema
|
|
3
|
-
} from "./index-
|
|
3
|
+
} from "./index-hkm6wysp.js";
|
|
4
4
|
import {
|
|
5
5
|
AgentMessagePartSchema,
|
|
6
6
|
AgentSnapshotSchema
|
|
7
|
-
} from "./index-
|
|
7
|
+
} from "./index-p1b1y93x.js";
|
|
8
8
|
|
|
9
9
|
// src/agent-runtime/control-schema.ts
|
|
10
10
|
import { z } from "zod";
|
|
@@ -179,7 +179,7 @@ function reduceAgentControlEvent(view, rawEvent) {
|
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
const transient = current.transientByRun[event.runId] ?? { text: "", reasoning: "" };
|
|
182
|
-
const nextTransient = event.type === "assistant-delta" ? { ...transient, text: transient.text + event.textDelta } : event.type === "reasoning-delta" ? { ...transient, reasoning: transient.reasoning + event.textDelta } : transient;
|
|
182
|
+
const nextTransient = event.type === "assistant-delta" ? { ...transient, text: transient.text + event.textDelta } : event.type === "reasoning-delta" ? { ...transient, reasoning: transient.reasoning + event.textDelta } : event.type === "attempt-reset" ? { text: "", reasoning: "" } : transient;
|
|
183
183
|
const snapshotStale = durable(event) && current.snapshot?.version !== event.snapshotVersion;
|
|
184
184
|
const transientByRun = event.type === "terminal" ? Object.fromEntries(Object.entries(current.transientByRun).filter(([runId]) => runId !== event.runId)) : { ...current.transientByRun, [event.runId]: nextTransient };
|
|
185
185
|
return {
|
|
@@ -15,6 +15,19 @@ export type SqliteValue = string | number | bigint | null | Uint8Array;
|
|
|
15
15
|
export interface SqliteStatement {
|
|
16
16
|
get(...parameters: SqliteValue[]): unknown;
|
|
17
17
|
all(...parameters: SqliteValue[]): readonly unknown[];
|
|
18
|
+
/**
|
|
19
|
+
* `changes` is the driver's own count and is advisory: never decide
|
|
20
|
+
* correctness by it.
|
|
21
|
+
*
|
|
22
|
+
* Because this boundary is satisfied structurally by a raw handle, the
|
|
23
|
+
* number is whatever that driver reports. `bun:sqlite` includes rows written
|
|
24
|
+
* by an AFTER INSERT trigger and by FTS5's deferred index flush during the
|
|
25
|
+
* same statement, so a statement that moved one row can report five, and one
|
|
26
|
+
* that moved none can report more than zero. A guarded `UPDATE`/upsert whose
|
|
27
|
+
* outcome is read back from `changes` is therefore not a compare-and-swap.
|
|
28
|
+
* Read the row, compare, then write unconditionally — inside the store's
|
|
29
|
+
* `BEGIN IMMEDIATE` transaction that is atomic.
|
|
30
|
+
*/
|
|
18
31
|
run(...parameters: SqliteValue[]): {
|
|
19
32
|
changes: number;
|
|
20
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/internal/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3C,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,SAAS,OAAO,EAAE,CAAC;IACtD,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IACtC,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/internal/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,UAAU,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3C,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG,SAAS,OAAO,EAAE,CAAC;IACtD;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACxD;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IACtC,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-store-conformance.d.ts","sourceRoot":"","sources":["../../src/testing/agent-store-conformance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-store-conformance.d.ts","sourceRoot":"","sources":["../../src/testing/agent-store-conformance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAIhE;;;;;;;;;GASG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,MAAM,WAAW,2BAA2B;IAC1C;;;;OAIG;IACH,WAAW,CACT,OAAO,EAAE,4BAA4B,GACpC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AAwCD,gFAAgF;AAChF,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,IAAI,CAAC,CAoCf"}
|