stitchkit 0.87.1 → 0.89.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/dist/agent-runtime/child-blocking.d.ts +17 -0
  3. package/dist/agent-runtime/child-blocking.d.ts.map +1 -0
  4. package/dist/agent-runtime/child-budget-policy.d.ts +23 -0
  5. package/dist/agent-runtime/child-budget-policy.d.ts.map +1 -0
  6. package/dist/agent-runtime/children-contract.d.ts +155 -0
  7. package/dist/agent-runtime/children-contract.d.ts.map +1 -0
  8. package/dist/agent-runtime/children.d.ts +4 -99
  9. package/dist/agent-runtime/children.d.ts.map +1 -1
  10. package/dist/agent-runtime/coding-shell-process.d.ts +33 -0
  11. package/dist/agent-runtime/coding-shell-process.d.ts.map +1 -0
  12. package/dist/agent-runtime/coding-tool-contract.d.ts +18 -0
  13. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -1
  14. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -1
  15. package/dist/agent-runtime/coding-tool-listing.d.ts.map +1 -1
  16. package/dist/agent-runtime/coding-tool-paths.d.ts +1 -1
  17. package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -1
  18. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -1
  19. package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -1
  20. package/dist/agent-runtime/coding-tool-utf8.d.ts +28 -0
  21. package/dist/agent-runtime/coding-tool-utf8.d.ts.map +1 -0
  22. package/dist/agent-runtime/contained-files.d.ts +20 -0
  23. package/dist/agent-runtime/contained-files.d.ts.map +1 -1
  24. package/dist/agent-runtime/durability-contract.d.ts +176 -0
  25. package/dist/agent-runtime/durability-contract.d.ts.map +1 -0
  26. package/dist/agent-runtime/durability-json.d.ts +3 -0
  27. package/dist/agent-runtime/durability-json.d.ts.map +1 -0
  28. package/dist/agent-runtime/durability-ledger.d.ts +16 -0
  29. package/dist/agent-runtime/durability-ledger.d.ts.map +1 -0
  30. package/dist/agent-runtime/durability-scheduler.d.ts +29 -0
  31. package/dist/agent-runtime/durability-scheduler.d.ts.map +1 -0
  32. package/dist/agent-runtime/durability.d.ts +14 -0
  33. package/dist/agent-runtime/durability.d.ts.map +1 -0
  34. package/dist/agent-runtime/event-search.d.ts.map +1 -1
  35. package/dist/agent-runtime/harness-contract.d.ts +37 -0
  36. package/dist/agent-runtime/harness-contract.d.ts.map +1 -1
  37. package/dist/agent-runtime/harness.d.ts +8 -0
  38. package/dist/agent-runtime/harness.d.ts.map +1 -1
  39. package/dist/agent-runtime/models.d.ts +14 -0
  40. package/dist/agent-runtime/models.d.ts.map +1 -1
  41. package/dist/agent-runtime/observability.d.ts +8 -0
  42. package/dist/agent-runtime/observability.d.ts.map +1 -1
  43. package/dist/agent-runtime/owned-provider-stream.d.ts +16 -0
  44. package/dist/agent-runtime/owned-provider-stream.d.ts.map +1 -0
  45. package/dist/agent-runtime/prompt.d.ts +23 -0
  46. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  47. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  48. package/dist/agent-runtime/runtime-internals.d.ts +16 -0
  49. package/dist/agent-runtime/runtime-internals.d.ts.map +1 -1
  50. package/dist/agent-runtime/runtime.d.ts +25 -0
  51. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  52. package/dist/agent-runtime/sandbox-broker.d.ts +7 -0
  53. package/dist/agent-runtime/sandbox-broker.d.ts.map +1 -0
  54. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts +9 -0
  55. package/dist/agent-runtime/sandbox-bubblewrap-args.d.ts.map +1 -0
  56. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts +22 -0
  57. package/dist/agent-runtime/sandbox-bubblewrap-storage.d.ts.map +1 -0
  58. package/dist/agent-runtime/sandbox-bubblewrap.d.ts +14 -0
  59. package/dist/agent-runtime/sandbox-bubblewrap.d.ts.map +1 -0
  60. package/dist/agent-runtime/sandbox-coding-adapter.d.ts +15 -0
  61. package/dist/agent-runtime/sandbox-coding-adapter.d.ts.map +1 -0
  62. package/dist/agent-runtime/sandbox-coding.d.ts +15 -0
  63. package/dist/agent-runtime/sandbox-coding.d.ts.map +1 -0
  64. package/dist/agent-runtime/sandbox-contract.d.ts +93 -0
  65. package/dist/agent-runtime/sandbox-contract.d.ts.map +1 -0
  66. package/dist/agent-runtime/sandbox-process-owner.d.ts +11 -0
  67. package/dist/agent-runtime/sandbox-process-owner.d.ts.map +1 -0
  68. package/dist/agent-runtime/sandbox-process.d.ts +8 -0
  69. package/dist/agent-runtime/sandbox-process.d.ts.map +1 -0
  70. package/dist/agent-runtime/sandbox-session.d.ts +5 -0
  71. package/dist/agent-runtime/sandbox-session.d.ts.map +1 -0
  72. package/dist/agent-runtime/sandbox.d.ts +19 -0
  73. package/dist/agent-runtime/sandbox.d.ts.map +1 -1
  74. package/dist/agent-runtime/schemas.d.ts +6 -0
  75. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  76. package/dist/agent-runtime/sqlite-purge.d.ts.map +1 -1
  77. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  78. package/dist/agent-runtime/store-driver.d.ts +127 -0
  79. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  80. package/dist/agent-runtime/store-events.d.ts +106 -0
  81. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  82. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts +14 -0
  83. package/dist/agent-runtime/store-migrations/v2-to-v3.d.ts.map +1 -0
  84. package/dist/agent-runtime/store.d.ts +115 -0
  85. package/dist/agent-runtime/store.d.ts.map +1 -1
  86. package/dist/agent-runtime-browser.js +5 -3
  87. package/dist/agent-runtime-coding-tools.js +11 -1236
  88. package/dist/agent-runtime-harness.d.ts +1 -1
  89. package/dist/agent-runtime-harness.d.ts.map +1 -1
  90. package/dist/agent-runtime-harness.js +69 -19
  91. package/dist/agent-runtime-openrouter.d.ts +3 -12
  92. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  93. package/dist/agent-runtime-openrouter.js +22 -9
  94. package/dist/agent-runtime-sandbox.d.ts +5 -0
  95. package/dist/agent-runtime-sandbox.d.ts.map +1 -0
  96. package/dist/agent-runtime-sandbox.js +797 -0
  97. package/dist/agent-runtime-sqlite-bun.js +5 -5
  98. package/dist/agent-runtime-sqlite-node.js +5 -5
  99. package/dist/agent-runtime.d.ts +6 -5
  100. package/dist/agent-runtime.d.ts.map +1 -1
  101. package/dist/agent-runtime.js +266 -69
  102. package/dist/application.js +26 -26
  103. package/dist/cli.js +8 -8
  104. package/dist/{index-rcgsnrr6.js → index-31jw8fjq.js} +3 -3
  105. package/dist/{index-9hw9eq48.js → index-7601qfg1.js} +14 -14
  106. package/dist/{index-3xnq72rz.js → index-7rkhw9ec.js} +14 -1
  107. package/dist/{index-0vfdh685.js → index-8c3a7m4g.js} +1 -1
  108. package/dist/{index-t7gh5w3v.js → index-bn2cjajt.js} +27 -6
  109. package/dist/{index-z2452tsw.js → index-bt14acb5.js} +2 -2
  110. package/dist/index-cp20z0n6.js +1351 -0
  111. package/dist/{index-9553432s.js → index-crykmqkr.js} +1 -1
  112. package/dist/{index-6g273pqx.js → index-fadnxwna.js} +89 -7
  113. package/dist/{index-p1b1y93x.js → index-gtj3zc53.js} +5 -1
  114. package/dist/{index-5wezxcxx.js → index-hrbajay7.js} +107 -5
  115. package/dist/{index-35aefxby.js → index-hw2chdvy.js} +768 -49
  116. package/dist/{index-0ydchz76.js → index-mnm4qp0p.js} +5 -5
  117. package/dist/{index-tg3m2ec5.js → index-mqv3b5rh.js} +4 -1
  118. package/dist/{index-1szetq6f.js → index-q3ve2d1k.js} +30 -8
  119. package/dist/{index-hkm6wysp.js → index-y64k3s0h.js} +1 -1
  120. package/dist/{index-z1m86vc8.js → index-zwkgfq1s.js} +97 -86
  121. package/dist/{index-wn9cb82y.js → index-zyvby92n.js} +12 -9
  122. package/dist/index.js +13 -13
  123. package/dist/server/index.js +9 -9
  124. package/dist/testing/agent-store-conformance.d.ts.map +1 -1
  125. package/dist/testing.js +69 -24
  126. package/dist/tool-invoker.js +6 -6
  127. package/dist/tools/agent.d.ts +6 -0
  128. package/dist/tools/agent.d.ts.map +1 -1
  129. package/dist/tools/connections/define.d.ts +6 -0
  130. package/dist/tools/connections/define.d.ts.map +1 -0
  131. package/dist/tools/connections/errors.d.ts +50 -0
  132. package/dist/tools/connections/errors.d.ts.map +1 -0
  133. package/dist/tools/connections/http.d.ts +3 -0
  134. package/dist/tools/connections/http.d.ts.map +1 -0
  135. package/dist/tools/connections/index.d.ts +19 -0
  136. package/dist/tools/connections/index.d.ts.map +1 -0
  137. package/dist/tools/connections/index.js +1047 -0
  138. package/dist/tools/connections/instance.d.ts +3 -0
  139. package/dist/tools/connections/instance.d.ts.map +1 -0
  140. package/dist/tools/connections/json-rpc.d.ts +8 -0
  141. package/dist/tools/connections/json-rpc.d.ts.map +1 -0
  142. package/dist/tools/connections/limits.d.ts +36 -0
  143. package/dist/tools/connections/limits.d.ts.map +1 -0
  144. package/dist/tools/connections/mcp-client.d.ts +44 -0
  145. package/dist/tools/connections/mcp-client.d.ts.map +1 -0
  146. package/dist/tools/connections/mcp.d.ts +5 -0
  147. package/dist/tools/connections/mcp.d.ts.map +1 -0
  148. package/dist/tools/connections/mount.d.ts +12 -0
  149. package/dist/tools/connections/mount.d.ts.map +1 -0
  150. package/dist/tools/connections/openapi-document.d.ts +4 -0
  151. package/dist/tools/connections/openapi-document.d.ts.map +1 -0
  152. package/dist/tools/connections/openapi.d.ts +5 -0
  153. package/dist/tools/connections/openapi.d.ts.map +1 -0
  154. package/dist/tools/connections/runtime.d.ts +29 -0
  155. package/dist/tools/connections/runtime.d.ts.map +1 -0
  156. package/dist/tools/connections/schema-budget.d.ts +8 -0
  157. package/dist/tools/connections/schema-budget.d.ts.map +1 -0
  158. package/dist/tools/connections/sse-frames.d.ts +7 -0
  159. package/dist/tools/connections/sse-frames.d.ts.map +1 -0
  160. package/dist/tools/connections/sse-session.d.ts +26 -0
  161. package/dist/tools/connections/sse-session.d.ts.map +1 -0
  162. package/dist/tools/connections/ssrf.d.ts +15 -0
  163. package/dist/tools/connections/ssrf.d.ts.map +1 -0
  164. package/dist/tools/connections/types.d.ts +60 -0
  165. package/dist/tools/connections/types.d.ts.map +1 -0
  166. package/dist/tools/durability-context.d.ts +7 -0
  167. package/dist/tools/durability-context.d.ts.map +1 -0
  168. package/dist/tools/execute.d.ts +2 -0
  169. package/dist/tools/execute.d.ts.map +1 -1
  170. package/dist/tools/registry.d.ts +38 -0
  171. package/dist/tools/registry.d.ts.map +1 -0
  172. package/dist/tools/runtime-tool.d.ts +4 -0
  173. package/dist/tools/runtime-tool.d.ts.map +1 -1
  174. package/dist/tools.d.ts +1 -0
  175. package/dist/tools.d.ts.map +1 -1
  176. package/dist/tools.js +83 -26
  177. package/llms-full.txt +329 -14
  178. package/llms.txt +1 -0
  179. package/package.json +9 -1
  180. package/dist/{index-evcnmsc3.js → index-t7fkyxcr.js} +3 -3
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  collectTools,
3
3
  createToolRunner
4
- } from "./index-0vfdh685.js";
4
+ } from "./index-8c3a7m4g.js";
5
5
  import {
6
6
  toolErrorFromResult
7
- } from "./index-wn9cb82y.js";
8
- import {
9
- assertUniqueToolName
10
- } from "./index-r159gjwy.js";
7
+ } from "./index-zyvby92n.js";
11
8
  import {
12
9
  AppError
13
10
  } from "./index-0w9abg87.js";
11
+ import {
12
+ assertUniqueToolName
13
+ } from "./index-r159gjwy.js";
14
14
 
15
15
  // src/tools/invoker.ts
16
16
  function createToolInvoker(services, config) {
@@ -128,7 +128,10 @@ function defineModelRegistry(config) {
128
128
  return {
129
129
  descriptor: selected,
130
130
  model: provider.create(selected.modelId),
131
- ...provider.normalizeUsage && { normalizeUsage: provider.normalizeUsage }
131
+ ...provider.normalizeUsage && { normalizeUsage: provider.normalizeUsage },
132
+ ...provider.resolveResponseProvider && {
133
+ resolveResponseProvider: provider.resolveResponseProvider
134
+ }
132
135
  };
133
136
  },
134
137
  snapshot(input) {
@@ -1,17 +1,19 @@
1
1
  import {
2
- AgentToolError
3
- } from "./index-3xnq72rz.js";
2
+ AgentToolError,
3
+ resolveToolDurability
4
+ } from "./index-7rkhw9ec.js";
4
5
  import {
5
6
  collectToolSurface
6
- } from "./index-rcgsnrr6.js";
7
+ } from "./index-31jw8fjq.js";
7
8
  import {
8
9
  createToolRunner,
9
10
  formatToolError
10
- } from "./index-0vfdh685.js";
11
+ } from "./index-8c3a7m4g.js";
11
12
  import {
12
13
  isToolExecutionControlError,
14
+ toolCauseFromResult,
13
15
  toolResultFromError
14
- } from "./index-wn9cb82y.js";
16
+ } from "./index-zyvby92n.js";
15
17
  import {
16
18
  isRecord
17
19
  } from "./index-77fekveh.js";
@@ -20,6 +22,10 @@ import {
20
22
  import { jsonSchema, tool } from "ai";
21
23
  function mountAgent(services, config = {}) {
22
24
  const serviceList = Array.isArray(services) ? services : [services];
25
+ if (config.registry && config.runtimeTools) {
26
+ throw new Error("mountAgent accepts either runtimeTools or a registry, not both");
27
+ }
28
+ const runtimeTools = config.registry ? config.registry.tools : config.runtimeTools;
23
29
  const tools = {};
24
30
  const runTool = createToolRunner({
25
31
  source: "agent",
@@ -32,7 +38,7 @@ function mountAgent(services, config = {}) {
32
38
  onOutputStrip: config.onOutputStrip
33
39
  });
34
40
  for (const entry of collectToolSurface({
35
- surface: { services: serviceList, runtimeTools: config.runtimeTools },
41
+ surface: { services: serviceList, runtimeTools },
36
42
  transport: "AGENT",
37
43
  extend: config.extend,
38
44
  flattenUnionInput: config.flattenUnionInput
@@ -43,7 +49,23 @@ function mountAgent(services, config = {}) {
43
49
  });
44
50
  const execute = async (rawArgs, options) => {
45
51
  const args = isRecord(rawArgs) ? rawArgs : {};
46
- const result = await runTool(mountable, args, {
52
+ const durability = resolveToolDurability(options.context, options.toolCallId, options.abortSignal);
53
+ const executeTool = durability ? createToolRunner({
54
+ source: "agent",
55
+ extend: config.extend,
56
+ context: {
57
+ ...config.context,
58
+ step: durability.step,
59
+ sleep: durability.sleep,
60
+ waitFor: durability.waitFor
61
+ },
62
+ hooks: config.hooks,
63
+ lifecycle: config.lifecycle,
64
+ errorHint: config.errorHint,
65
+ coerceJsonArgs: config.coerceJsonArgs,
66
+ onOutputStrip: config.onOutputStrip
67
+ }) : runTool;
68
+ const result = await executeTool(mountable, args, {
47
69
  signal: options.abortSignal
48
70
  }).catch((err) => {
49
71
  if (isToolExecutionControlError(err))
@@ -52,7 +74,7 @@ function mountAgent(services, config = {}) {
52
74
  });
53
75
  if (result.ok)
54
76
  return result.data;
55
- throw new AgentToolError(formatToolError(result, mountable.name, config.errorHint));
77
+ throw new AgentToolError(formatToolError(result, mountable.name, config.errorHint), toolCauseFromResult(result));
56
78
  };
57
79
  const presenter = entry.kind === "runtime" ? entry.definition.present?.agent : undefined;
58
80
  if (entry.kind === "runtime" && presenter) {
@@ -10,7 +10,7 @@ import {
10
10
  AgentRunStateSchema,
11
11
  AgentTerminalReasonSchema,
12
12
  AgentTimestampSchema
13
- } from "./index-p1b1y93x.js";
13
+ } from "./index-gtj3zc53.js";
14
14
 
15
15
  // src/agent-runtime/event-schema.ts
16
16
  import { z } from "zod";
@@ -7,89 +7,7 @@ import {
7
7
  AgentSnapshotSchema,
8
8
  AgentTerminalReasonSchema,
9
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
- }
10
+ } from "./index-gtj3zc53.js";
93
11
 
94
12
  // src/agent-runtime/store.ts
95
13
  import { z } from "zod";
@@ -186,6 +104,11 @@ var ReplaceCompactedRangeSchema = z.object({
186
104
  replacedMessageIds: z.array(AgentRecordIdSchema).min(1),
187
105
  summary: AgentMessageSchema
188
106
  });
107
+ var SeedConversationInputSchema = z.object({
108
+ conversationId: AgentRecordIdSchema,
109
+ seedKey: z.string().min(1),
110
+ inputs: z.array(AgentMessageSchema).min(1)
111
+ });
189
112
  var AgentRecoverableDescriptorSchema = z.object({
190
113
  conversationId: AgentRecordIdSchema,
191
114
  run: AgentRunSchema
@@ -202,6 +125,7 @@ var AgentStoreEventKindSchema = z2.enum([
202
125
  "runtime/baseline",
203
126
  "runtime/transition",
204
127
  "provider/request",
128
+ "provider/response",
205
129
  "provider/message",
206
130
  "state/set",
207
131
  "spill/created",
@@ -215,7 +139,11 @@ var AgentStoreEventKindSchema = z2.enum([
215
139
  "child/state",
216
140
  "retry/scheduled",
217
141
  "retry/started",
218
- "sandbox/probed"
142
+ "sandbox/probed",
143
+ "approval/response-rejected",
144
+ "durability/step",
145
+ "durability/park",
146
+ "durability/event"
219
147
  ]);
220
148
  var AgentStoreTransitionSchema = z2.discriminatedUnion("type", [
221
149
  z2.object({ type: z2.literal("accept"), input: AcceptInputAndAssignRunSchema }).strict(),
@@ -225,7 +153,8 @@ var AgentStoreTransitionSchema = z2.discriminatedUnion("type", [
225
153
  z2.object({ type: z2.literal("interrupt"), input: RequestRunInterruptSchema }).strict(),
226
154
  z2.object({ type: z2.literal("recover"), input: RecoverAgentRunSchema }).strict(),
227
155
  z2.object({ type: z2.literal("terminal"), input: CommitRunTerminalSchema }).strict(),
228
- z2.object({ type: z2.literal("compact"), input: ReplaceCompactedRangeSchema }).strict()
156
+ z2.object({ type: z2.literal("compact"), input: ReplaceCompactedRangeSchema }).strict(),
157
+ z2.object({ type: z2.literal("seed"), input: SeedConversationInputSchema }).strict()
229
158
  ]);
230
159
  var AgentStoreEventEnvelopeSchema = z2.object({
231
160
  schemaVersion: z2.int().positive(),
@@ -331,4 +260,86 @@ function decodeAgentConversationArchive(bytes) {
331
260
  return archive;
332
261
  }
333
262
 
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 };
263
+ // src/agent-runtime/history-chronology.ts
264
+ function createToolChronology() {
265
+ return { calls: new Map, approvals: new Map, pending: 0, resultsStarted: false };
266
+ }
267
+ function advanceToolChronology(previous, parts) {
268
+ const calls = new Map(previous.calls);
269
+ const approvals = new Map(previous.approvals);
270
+ let { pending, resultsStarted } = previous;
271
+ for (const part of parts) {
272
+ if (part.type === "tool-call") {
273
+ if (calls.has(part.callId) || resultsStarted && pending > 0)
274
+ return;
275
+ if (pending === 0)
276
+ resultsStarted = false;
277
+ calls.set(part.callId, { toolName: part.toolName, phase: "called" });
278
+ pending += 1;
279
+ } else if (part.type === "tool-approval-request") {
280
+ const call = calls.get(part.callId);
281
+ if (call?.phase !== "called" || approvals.has(part.approvalId))
282
+ return;
283
+ approvals.set(part.approvalId, part.callId);
284
+ calls.set(part.callId, { ...call, phase: "requested" });
285
+ } else if (part.type === "tool-approval-response") {
286
+ const callId = approvals.get(part.approvalId);
287
+ const call = callId === undefined ? undefined : calls.get(callId);
288
+ if (callId === undefined || !call || call.phase !== "requested")
289
+ return;
290
+ calls.set(callId, { ...call, phase: part.approved ? "approved" : "denied" });
291
+ } else if (part.type === "tool-result") {
292
+ const call = calls.get(part.callId);
293
+ if (!call || call.toolName !== part.toolName || call.phase === "result" || call.phase === "requested" || call.phase === "denied" && part.outcome === "success")
294
+ return;
295
+ calls.set(part.callId, { ...call, phase: "result" });
296
+ pending -= 1;
297
+ resultsStarted = true;
298
+ }
299
+ }
300
+ return { calls, approvals, pending, resultsStarted };
301
+ }
302
+ function canProjectToolChronology(state) {
303
+ return [...state.calls.values()].every(({ phase }) => phase !== "called");
304
+ }
305
+
306
+ // src/agent-runtime/terminal-status.ts
307
+ function isSpeakableAssistantStatus(status) {
308
+ return status === "completed" || status === "interrupted" || status === "committed";
309
+ }
310
+ function isAssistantHistoryEvidence(status, policy) {
311
+ return isSpeakableAssistantStatus(status) || status === "failed" && policy?.failedAssistant === "assistant-marked";
312
+ }
313
+ function isCompleteAgentHistoryTurn(messages, policy) {
314
+ if (messages[0]?.role !== "user")
315
+ return false;
316
+ let chronology = createToolChronology();
317
+ let assistantCount = 0;
318
+ for (const message of messages) {
319
+ if (message.role === "assistant") {
320
+ if (!isAssistantHistoryEvidence(message.status, policy))
321
+ return false;
322
+ assistantCount += 1;
323
+ }
324
+ const next = advanceToolChronology(chronology, message.parts);
325
+ if (!next)
326
+ return false;
327
+ chronology = next;
328
+ }
329
+ return assistantCount > 0 && chronology.pending === 0;
330
+ }
331
+ function assistantStatus(reason) {
332
+ if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
333
+ return "completed";
334
+ }
335
+ if (reason === "superseded")
336
+ return "superseded";
337
+ if (reason === "absorbed")
338
+ return "superseded";
339
+ if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
340
+ return "interrupted";
341
+ }
342
+ return "failed";
343
+ }
344
+
345
+ export { AgentStoreConflictSchema, AgentStoreNotFoundSchema, AgentStoreAppliedSchema, AgentStoreDuplicateSchema, AgentStoreMutationResultSchema, AgentRunViewSchema, AcceptInputAndAssignRunSchema, AcquireAgentRunSchema, CheckpointRunAssistantSchema, RecordRunOperationSchema, CommitRunTerminalSchema, RequestRunInterruptSchema, RecoverAgentRunSchema, ReplaceCompactedRangeSchema, SeedConversationInputSchema, AgentRecoverableDescriptorSchema, AgentRecoverablePageSchema, AgentStoreEventKindSchema, AgentStoreTransitionSchema, AgentStoreEventEnvelopeSchema, AppendAgentStoreEventSchema, ReadAgentStoreEventsSchema, AgentStoreEventPageSchema, decodeAgentStoreEvent, agentStoreEventDraft, canonicalAgentJson, AgentConversationArchiveSchema, encodeAgentConversationArchive, decodeAgentConversationArchive, createToolChronology, advanceToolChronology, canProjectToolChronology, isAssistantHistoryEvidence, isCompleteAgentHistoryTurn, assistantStatus };
@@ -2,12 +2,6 @@ import {
2
2
  getRequestContext,
3
3
  runWithRequestContext
4
4
  } from "./index-vsbzgd7b.js";
5
- import {
6
- objectShapeKeys
7
- } from "./index-r159gjwy.js";
8
- import {
9
- coerceJsonArgs
10
- } from "./index-7zbps32p.js";
11
5
  import {
12
6
  formatZodError,
13
7
  normalizeError,
@@ -18,9 +12,15 @@ import {
18
12
  STITCH_ERROR_STATUS,
19
13
  isStitchErrorCode
20
14
  } from "./index-0w9abg87.js";
15
+ import {
16
+ coerceJsonArgs
17
+ } from "./index-7zbps32p.js";
21
18
  import {
22
19
  isUnsafeKey
23
20
  } from "./index-kzfs85xp.js";
21
+ import {
22
+ objectShapeKeys
23
+ } from "./index-r159gjwy.js";
24
24
  import {
25
25
  isRecord
26
26
  } from "./index-77fekveh.js";
@@ -46,18 +46,21 @@ function toolResultFromError(err) {
46
46
  details: appErr.details ?? { message: appErr.message },
47
47
  ...appErr.hint && { hint: appErr.hint }
48
48
  };
49
- normalizedToolErrors.set(result, appErr);
49
+ normalizedToolErrors.set(result, { normalized: appErr, cause: err });
50
50
  return result;
51
51
  }
52
52
  function toolErrorFromResult(result) {
53
53
  const retained = normalizedToolErrors.get(result);
54
54
  if (retained)
55
- return retained;
55
+ return retained.normalized;
56
56
  const details = isRecord(result.details) ? result.details : undefined;
57
57
  const message = typeof details?.message === "string" ? details.message : result.code;
58
58
  const status = isStitchErrorCode(result.code) ? STITCH_ERROR_STATUS[result.code] : 500;
59
59
  return new AppError(result.code, message, status, details, result.hint);
60
60
  }
61
+ function toolCauseFromResult(result) {
62
+ return normalizedToolErrors.get(result)?.cause;
63
+ }
61
64
  async function executeToolMethod(method, toolName, rawArgs, context, hooks, lifecycle, coerceJson = false, onOutputStrip, extension, finalizeOutput) {
62
65
  return inToolCallContext({ source: context.source, toolName, method }, () => runToolMethod(method, toolName, rawArgs, context, hooks, lifecycle, coerceJson, onOutputStrip, extension, finalizeOutput));
63
66
  }
@@ -258,4 +261,4 @@ async function runToolMethod(method, toolName, rawArgs, context, hooks, lifecycl
258
261
  }
259
262
  }
260
263
 
261
- export { ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
264
+ export { ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, toolCauseFromResult, executeToolMethod };
package/dist/index.js CHANGED
@@ -6,6 +6,16 @@ import {
6
6
  createBackoff,
7
7
  resumableIterator
8
8
  } from "./index-s8cnx02s.js";
9
+ import {
10
+ contractEndpointMatchers,
11
+ createClient,
12
+ createClients,
13
+ createScopedClients,
14
+ createScopedUrlBuilders,
15
+ createUrlBuilder,
16
+ createUrlBuilders,
17
+ parseNDJSON
18
+ } from "./index-27gm3d6g.js";
9
19
  import {
10
20
  REALTIME_REJECTION_KEY,
11
21
  asRealtimeRejection,
@@ -22,6 +32,9 @@ import {
22
32
  RealtimeRequestRejectedError,
23
33
  RealtimeRequestTimeoutError
24
34
  } from "./index-2qzskm8h.js";
35
+ import {
36
+ parseSSE
37
+ } from "./index-qmgs7y68.js";
25
38
  import {
26
39
  LiveStateControllerStatusSchema,
27
40
  LiveStatePhaseSchema,
@@ -29,19 +42,6 @@ import {
29
42
  createLiveStateController
30
43
  } from "./index-ywd0y6m1.js";
31
44
  import"./index-7gnkny4z.js";
32
- import {
33
- contractEndpointMatchers,
34
- createClient,
35
- createClients,
36
- createScopedClients,
37
- createScopedUrlBuilders,
38
- createUrlBuilder,
39
- createUrlBuilders,
40
- parseNDJSON
41
- } from "./index-27gm3d6g.js";
42
- import {
43
- parseSSE
44
- } from "./index-qmgs7y68.js";
45
45
  import {
46
46
  ApiError,
47
47
  createHttpClient
@@ -27,6 +27,11 @@ import {
27
27
  } from "../index-3z73fh2c.js";
28
28
  import"../index-apn8repm.js";
29
29
  import"../index-2qzskm8h.js";
30
+ import {
31
+ inputIsQuery,
32
+ parseSSE,
33
+ streamSSE
34
+ } from "../index-qmgs7y68.js";
30
35
  import {
31
36
  composeAuthHooks,
32
37
  createAuthHook,
@@ -70,15 +75,6 @@ import {
70
75
  resolveSocketIp,
71
76
  resolveTraceId
72
77
  } from "../index-f9mb610r.js";
73
- import {
74
- jsonSchemaFields,
75
- toJsonSchema
76
- } from "../index-cby4ar3v.js";
77
- import {
78
- inputIsQuery,
79
- parseSSE,
80
- streamSSE
81
- } from "../index-qmgs7y68.js";
82
78
  import {
83
79
  errorCode,
84
80
  formatZodError,
@@ -105,6 +101,10 @@ import {
105
101
  } from "../index-0w9abg87.js";
106
102
  import"../index-zcgf3gqf.js";
107
103
  import"../index-kzfs85xp.js";
104
+ import {
105
+ jsonSchemaFields,
106
+ toJsonSchema
107
+ } from "../index-cby4ar3v.js";
108
108
  import {
109
109
  isRecord
110
110
  } from "../index-77fekveh.js";
@@ -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;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"}
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,CAqCf"}
package/dist/testing.js CHANGED
@@ -1,47 +1,39 @@
1
1
  import {
2
2
  createApplication
3
- } from "./index-evcnmsc3.js";
4
- import"./index-2k4yrqkc.js";
3
+ } from "./index-t7fkyxcr.js";
5
4
  import"./index-3gye9wzb.js";
5
+ import"./index-2k4yrqkc.js";
6
6
  import"./index-3z73fh2c.js";
7
7
  import {
8
8
  createMemoryAgentRuntimeStore
9
- } from "./index-5wezxcxx.js";
10
- import {
11
- createAgentRaceBarrier,
12
- createAgentRaceDriver,
13
- createAgentRaceTrace
14
- } from "./index-cnyk6te3.js";
9
+ } from "./index-hrbajay7.js";
15
10
  import {
16
11
  decodeAgentConversationArchive
17
- } from "./index-z1m86vc8.js";
12
+ } from "./index-zwkgfq1s.js";
18
13
  import {
19
14
  AgentMessageSchema,
20
15
  AgentRunSchema
21
- } from "./index-p1b1y93x.js";
16
+ } from "./index-gtj3zc53.js";
17
+ import {
18
+ createAgentRaceBarrier,
19
+ createAgentRaceDriver,
20
+ createAgentRaceTrace
21
+ } from "./index-cnyk6te3.js";
22
22
  import {
23
23
  RealtimeRejectDirectionSchema,
24
24
  RealtimeRejectFaultSchema,
25
25
  RealtimeRejectPhaseSchema,
26
26
  RealtimeRejectReasonSchema
27
27
  } from "./index-p7hgdyhb.js";
28
+ import {
29
+ createClient,
30
+ createClients
31
+ } from "./index-27gm3d6g.js";
28
32
  import {
29
33
  RealtimeRequestDisconnectedError,
30
34
  RealtimeRequestInvalidAcknowledgementError,
31
35
  RealtimeRequestTimeoutError
32
36
  } from "./index-2qzskm8h.js";
33
- import {
34
- mcpProjectionCandidate,
35
- prepareProjectedMcpTools,
36
- projectToolSurface
37
- } from "./index-r159gjwy.js";
38
- import {
39
- toJsonSchema
40
- } from "./index-cby4ar3v.js";
41
- import {
42
- createClient,
43
- createClients
44
- } from "./index-27gm3d6g.js";
45
37
  import"./index-qmgs7y68.js";
46
38
  import"./index-3xwxfj4z.js";
47
39
  import"./index-7evdsyez.js";
@@ -52,6 +44,14 @@ import"./index-6k1937bx.js";
52
44
  import"./index-0w9abg87.js";
53
45
  import"./index-zcgf3gqf.js";
54
46
  import"./index-kzfs85xp.js";
47
+ import {
48
+ mcpProjectionCandidate,
49
+ prepareProjectedMcpTools,
50
+ projectToolSurface
51
+ } from "./index-r159gjwy.js";
52
+ import {
53
+ toJsonSchema
54
+ } from "./index-cby4ar3v.js";
55
55
  import {
56
56
  isRecord
57
57
  } from "./index-77fekveh.js";
@@ -97,7 +97,8 @@ async function runAgentStoreConformance(config) {
97
97
  `${run}-causal-active`,
98
98
  `${run}-interrupt-priority`,
99
99
  `${run}-ledger`,
100
- `${run}-archive`
100
+ `${run}-archive`,
101
+ `${run}-seed`
101
102
  ]
102
103
  };
103
104
  const store = await config.createStore(context);
@@ -117,6 +118,36 @@ async function runAgentStoreConformance(config) {
117
118
  if (failure !== undefined)
118
119
  throw failure;
119
120
  }
121
+ async function seedScenario(store, conversationId) {
122
+ const input = {
123
+ conversationId,
124
+ seedKey: "brief",
125
+ inputs: [userMessage(conversationId, "seed-a"), userMessage(conversationId, "seed-b")]
126
+ };
127
+ const first = await store.seedConversationInput(input);
128
+ requireOutcome(first, "applied");
129
+ const before = await store.loadSnapshot(conversationId);
130
+ if (before.messages.map((message) => message.id).join(",") !== "seed-a,seed-b")
131
+ throw new Error("Seed conformance: complete ordered seed missing");
132
+ await Promise.all([store.seedConversationInput(input), store.seedConversationInput(input)]);
133
+ const repeated = await store.loadSnapshot(conversationId);
134
+ if (repeated.version !== before.version || repeated.messages.length !== 2)
135
+ throw new Error("Seed conformance: replay changed history");
136
+ const compacted = await store.replaceCompactedRange({
137
+ conversationId,
138
+ expectedVersion: repeated.version,
139
+ replacedMessageIds: ["seed-a", "seed-b"],
140
+ summary: AgentMessageSchema.parse({
141
+ ...userMessage(conversationId, "seed-summary"),
142
+ role: "summary"
143
+ })
144
+ });
145
+ requireOutcome(compacted, "applied");
146
+ await store.seedConversationInput(input);
147
+ const after = await store.loadSnapshot(conversationId);
148
+ if (after.messages.some((message) => message.id === "seed-a" || message.id === "seed-b"))
149
+ throw new Error("Seed conformance: compacted instructions resurrected");
150
+ }
120
151
  async function conformanceScenario(store, conversationIds) {
121
152
  const [
122
153
  conversationId,
@@ -126,8 +157,11 @@ async function conformanceScenario(store, conversationIds) {
126
157
  causalActiveConversationId,
127
158
  interruptPriorityConversationId,
128
159
  ledgerConversationId,
129
- archiveConversationId
160
+ archiveConversationId,
161
+ seedConversationId
130
162
  ] = conversationIds;
163
+ if (seedConversationId)
164
+ await seedScenario(store, seedConversationId);
131
165
  if (ledgerConversationId)
132
166
  await ledgerScenario(store, ledgerConversationId);
133
167
  if (archiveConversationId)
@@ -541,6 +575,17 @@ async function conformanceScenario(store, conversationIds) {
541
575
  if (terminalRun?.state !== "abandoned" || terminalMessage?.status !== "failed") {
542
576
  throw new Error("Abandon recovery did not atomically terminalize its assistant record");
543
577
  }
578
+ const abandonedView = await store.loadRun({
579
+ conversationId: recoveryConversationId,
580
+ runId: abandonedRun.id
581
+ });
582
+ if (abandonedView?.run.state !== "abandoned" || abandonedView.run.terminalReason !== "abandoned" || abandonedView.assistant?.status !== "failed") {
583
+ throw new Error("The canonical run record disagrees with its abandoned index projection");
584
+ }
585
+ const afterAbandon = await store.scanRecoverable({ limit: 100 });
586
+ if (afterAbandon.items.some((item) => item.run.id === abandonedRun.id)) {
587
+ throw new Error("The recoverable index still exposes a canonically abandoned run");
588
+ }
544
589
  await assertCausalHistoryOrder(store, causalHistoryConversationId);
545
590
  await assertActiveRunCausalOrder(store, causalActiveConversationId);
546
591
  await assertInterruptPriorityOrder(store, interruptPriorityConversationId);
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  createToolInvoker
3
- } from "./index-0ydchz76.js";
4
- import"./index-0vfdh685.js";
5
- import"./index-wn9cb82y.js";
3
+ } from "./index-mnm4qp0p.js";
4
+ import"./index-8c3a7m4g.js";
5
+ import"./index-zyvby92n.js";
6
6
  import"./index-vsbzgd7b.js";
7
7
  import"./index-f9mb610r.js";
8
- import"./index-r159gjwy.js";
9
- import"./index-cby4ar3v.js";
10
- import"./index-7zbps32p.js";
11
8
  import"./index-7evdsyez.js";
12
9
  import"./index-2bxcmqkb.js";
13
10
  import"./index-6k1937bx.js";
14
11
  import"./index-0w9abg87.js";
15
12
  import"./index-zcgf3gqf.js";
13
+ import"./index-7zbps32p.js";
16
14
  import"./index-kzfs85xp.js";
15
+ import"./index-r159gjwy.js";
16
+ import"./index-cby4ar3v.js";
17
17
  import"./index-77fekveh.js";
18
18
  export {
19
19
  createToolInvoker