stitchkit 0.112.3 → 0.113.1

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 (54) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/agent-runtime/run-model-attempts.d.ts.map +1 -1
  3. package/dist/agent-runtime/runtime.d.ts +8 -3
  4. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  5. package/dist/agent-runtime/sqlite-history.d.ts.map +1 -1
  6. package/dist/agent-runtime/store-driver-contract.d.ts +94 -1
  7. package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
  8. package/dist/agent-runtime/store-events.d.ts +8 -0
  9. package/dist/agent-runtime/store-events.d.ts.map +1 -1
  10. package/dist/agent-runtime/store-memory.d.ts.map +1 -1
  11. package/dist/agent-runtime/store-reduce-history.d.ts +1 -1
  12. package/dist/agent-runtime/store-reduce-history.d.ts.map +1 -1
  13. package/dist/agent-runtime/store.d.ts +8 -2
  14. package/dist/agent-runtime/store.d.ts.map +1 -1
  15. package/dist/entrypoints/agent-runtime/harness.js +5 -5
  16. package/dist/entrypoints/agent-runtime/sqlite/bun.js +3 -3
  17. package/dist/entrypoints/agent-runtime/sqlite/node.js +3 -3
  18. package/dist/entrypoints/agent-runtime/testing.js +34 -3
  19. package/dist/entrypoints/agent-runtime.js +10 -10
  20. package/dist/entrypoints/cli.js +6 -6
  21. package/dist/entrypoints/tools/connections.js +3 -3
  22. package/dist/entrypoints/tools/contract.js +2 -2
  23. package/dist/entrypoints/tools/invoker.js +5 -5
  24. package/dist/entrypoints/tools/mcp.js +6 -6
  25. package/dist/entrypoints/tools.js +9 -9
  26. package/dist/{index-54q2mghq.js → index-8jjzfts8.js} +3 -3
  27. package/dist/{index-epmnrnth.js → index-dsa676h8.js} +24 -7
  28. package/dist/{index-eddzs589.js → index-emrmgq3s.js} +1 -1
  29. package/dist/{index-jna0ejsa.js → index-fggxgbrk.js} +2 -1
  30. package/dist/{index-gpbk7yse.js → index-fytsnhzj.js} +5 -5
  31. package/dist/{index-c9vpsxw4.js → index-gz9jf461.js} +22 -3
  32. package/dist/{index-kenvdagc.js → index-k0zfcxf5.js} +19 -3
  33. package/dist/{index-b9yqb9e7.js → index-mhrtwttb.js} +5 -5
  34. package/dist/{index-4dh3hfs7.js → index-nn6607y3.js} +2 -2
  35. package/dist/{index-jy9wq8tp.js → index-rbzq0q16.js} +1 -1
  36. package/dist/{index-5jjda9a4.js → index-sjww6myv.js} +3 -3
  37. package/dist/{index-z4ga1fa1.js → index-tg2q89ps.js} +2 -2
  38. package/dist/{index-zm1k7hhv.js → index-v6mzw27b.js} +1 -1
  39. package/dist/{index-f2p949ax.js → index-yjnmac9b.js} +41 -7
  40. package/dist/tools/connections/runtime.d.ts +1 -1
  41. package/dist/tools/schema/json-schema-origin.d.ts +6 -5
  42. package/dist/tools/schema/json-schema-origin.d.ts.map +1 -1
  43. package/llms/agent-runtime.2.txt +25 -0
  44. package/llms/agent-runtime.3.txt +1 -1
  45. package/llms/agent-runtime.txt +6 -0
  46. package/llms/cli.2.txt +14 -3
  47. package/llms/stitchkit.txt +3 -3
  48. package/llms/tools-connections.txt +1 -1
  49. package/llms/{upgrading-0.103.0-0.112.0.txt → upgrading-0.103.13-0.113.0.txt} +22 -32
  50. package/llms/{upgrading-0.75.0-0.102.0.txt → upgrading-0.75.0-0.103.0.txt} +32 -3
  51. package/llms/upgrading.txt +2 -2
  52. package/llms-full.txt +69 -8
  53. package/llms.txt +5 -5
  54. package/package.json +1 -1
@@ -1,13 +1,13 @@
1
1
  import"../../index-fynr93w4.js";
2
- import"../../index-epmnrnth.js";
3
- import"../../index-jy9wq8tp.js";
2
+ import"../../index-dsa676h8.js";
3
+ import"../../index-rbzq0q16.js";
4
4
  import"../../index-ct75c3at.js";
5
5
  import"../../index-jgwqc38k.js";
6
- import"../../index-z4ga1fa1.js";
7
- import"../../index-zm1k7hhv.js";
6
+ import"../../index-tg2q89ps.js";
7
+ import"../../index-v6mzw27b.js";
8
8
  import {
9
9
  createToolInvoker2
10
- } from "../../index-4dh3hfs7.js";
10
+ } from "../../index-nn6607y3.js";
11
11
  export {
12
12
  createToolInvoker2 as createToolInvoker
13
13
  };
@@ -1,10 +1,10 @@
1
1
  import"../../index-ct75c3at.js";
2
2
  import"../../index-fynr93w4.js";
3
- import"../../index-epmnrnth.js";
4
- import"../../index-jy9wq8tp.js";
3
+ import"../../index-dsa676h8.js";
4
+ import"../../index-rbzq0q16.js";
5
5
  import"../../index-jgwqc38k.js";
6
- import"../../index-z4ga1fa1.js";
7
- import"../../index-zm1k7hhv.js";
6
+ import"../../index-tg2q89ps.js";
7
+ import"../../index-v6mzw27b.js";
8
8
  import {
9
9
  RESOURCE_MIME_TYPE2,
10
10
  EXT_APPS_BUNDLE_PLACEHOLDER2,
@@ -20,8 +20,8 @@ import {
20
20
  createMcpHttpRoute2,
21
21
  createStdioMcpServer2,
22
22
  bindStdioProcessSignals2
23
- } from "../../index-54q2mghq.js";
24
- import"../../index-eddzs589.js";
23
+ } from "../../index-8jjzfts8.js";
24
+ import"../../index-emrmgq3s.js";
25
25
  import"../../index-nk1mh535.js";
26
26
  export {
27
27
  EXT_APPS_BUNDLE_PLACEHOLDER2 as EXT_APPS_BUNDLE_PLACEHOLDER,
@@ -9,10 +9,10 @@ import {
9
9
  import {
10
10
  normalizeError2
11
11
  } from "../index-fynr93w4.js";
12
- import"../index-epmnrnth.js";
12
+ import"../index-dsa676h8.js";
13
13
  import {
14
14
  coerceJsonArgs2
15
- } from "../index-jy9wq8tp.js";
15
+ } from "../index-rbzq0q16.js";
16
16
  import"../index-ct75c3at.js";
17
17
  import {
18
18
  assertToolName,
@@ -25,15 +25,15 @@ import {
25
25
  import {
26
26
  ToolExecutionControlError2,
27
27
  isToolExecutionControlError2
28
- } from "../index-z4ga1fa1.js";
28
+ } from "../index-tg2q89ps.js";
29
29
  import {
30
30
  collectTools2
31
- } from "../index-zm1k7hhv.js";
31
+ } from "../index-v6mzw27b.js";
32
32
  import {
33
33
  mountAgent2,
34
34
  describeToolCatalog2,
35
35
  buildToolManifest2
36
- } from "../index-5jjda9a4.js";
36
+ } from "../index-sjww6myv.js";
37
37
  import"../index-m38ej7e5.js";
38
38
  import {
39
39
  ALL_TRANSPORTS2,
@@ -60,7 +60,7 @@ import {
60
60
  createMcpHttpRoute2,
61
61
  createStdioMcpServer2,
62
62
  bindStdioProcessSignals2
63
- } from "../index-54q2mghq.js";
63
+ } from "../index-8jjzfts8.js";
64
64
  import {
65
65
  AsyncOperationCancelResultSchema2,
66
66
  createAsyncOperationSnapshotSchema2,
@@ -74,7 +74,7 @@ import {
74
74
  WaitTimeoutError,
75
75
  runWaitOperation,
76
76
  createCli2
77
- } from "../index-gpbk7yse.js";
77
+ } from "../index-fytsnhzj.js";
78
78
  import {
79
79
  ManagedFilePathSchema2,
80
80
  ManagedFileRefSchema2
@@ -89,7 +89,7 @@ import {
89
89
  } from "../index-pzw0fpek.js";
90
90
  import {
91
91
  createToolInvoker2
92
- } from "../index-4dh3hfs7.js";
92
+ } from "../index-nn6607y3.js";
93
93
  import {
94
94
  ManagedFileError2
95
95
  } from "../index-2f9r0jgr.js";
@@ -111,7 +111,7 @@ import {
111
111
  } from "../index-yk4g8805.js";
112
112
  import {
113
113
  collectToolSurface
114
- } from "../index-eddzs589.js";
114
+ } from "../index-emrmgq3s.js";
115
115
  import {
116
116
  getTraceId2
117
117
  } from "../index-r6v4mc67.js";
@@ -13,12 +13,12 @@ import {
13
13
  parseToolCallArguments,
14
14
  toolResultFromError,
15
15
  observed
16
- } from "./index-z4ga1fa1.js";
16
+ } from "./index-tg2q89ps.js";
17
17
  import {
18
18
  collectTools2,
19
19
  createToolRunner,
20
20
  formatToolError
21
- } from "./index-zm1k7hhv.js";
21
+ } from "./index-v6mzw27b.js";
22
22
  import {
23
23
  DEFAULT_CORS_ALLOW_HEADERS2,
24
24
  DEFAULT_PROCESS_SIGNALS,
@@ -31,7 +31,7 @@ import {
31
31
  } from "./index-e6c2spsd.js";
32
32
  import {
33
33
  collectToolSurface
34
- } from "./index-eddzs589.js";
34
+ } from "./index-emrmgq3s.js";
35
35
  import {
36
36
  runWithRequestContext2,
37
37
  getRequestContext2
@@ -82,9 +82,9 @@ function markJsonSchemaObjectGuards(schema) {
82
82
  };
83
83
  visit(schema);
84
84
  }
85
- var REMOTE_UNION_VERDICT = Symbol.for("stitchkit.tools.json-schema-remote-union-verdict.v1");
86
- function markRemoteUnionVerdict(schema) {
87
- Reflect.defineProperty(schema, REMOTE_UNION_VERDICT, {
85
+ var REMOTE_SCHEMA_VERDICT = Symbol.for("stitchkit.tools.json-schema-remote-verdict.v1");
86
+ function markRemoteSchemaVerdict(schema) {
87
+ Reflect.defineProperty(schema, REMOTE_SCHEMA_VERDICT, {
88
88
  configurable: false,
89
89
  enumerable: false,
90
90
  value: true,
@@ -92,12 +92,29 @@ function markRemoteUnionVerdict(schema) {
92
92
  });
93
93
  }
94
94
  function localVerdict(schema, error) {
95
- if (Reflect.get(schema, REMOTE_UNION_VERDICT) !== true)
95
+ if (Reflect.get(schema, REMOTE_SCHEMA_VERDICT) !== true)
96
96
  return error;
97
- const local = error.issues.filter((issue) => issue.code !== "invalid_union");
97
+ const local = localIssues(error.issues);
98
98
  if (local.length === 0)
99
99
  return null;
100
- return local.length === error.issues.length ? error : new z.ZodError(local);
100
+ return sameIssues(local, error.issues) ? error : new z.ZodError(local);
101
+ }
102
+ function sameIssues(left, right) {
103
+ return left.length === right.length && left.every((issue, index) => issue === right[index]);
104
+ }
105
+ function localIssues(issues) {
106
+ return issues.flatMap((issue) => {
107
+ if (issue.code === "invalid_union" || issue.code === "invalid_format")
108
+ return [];
109
+ if (issue.code === "invalid_key") {
110
+ const children = localIssues(issue.issues);
111
+ if (children.length === 0)
112
+ return [];
113
+ if (!sameIssues(children, issue.issues))
114
+ return [{ ...issue, issues: children }];
115
+ }
116
+ return [issue];
117
+ });
101
118
  }
102
119
  function jsonSchemaObjectCoercionMembers(schema) {
103
120
  if (Reflect.get(schema, JSON_SCHEMA_OBJECT_GUARD) !== true)
@@ -114,4 +131,4 @@ function jsonSchemaObjectCoercionMembers(schema) {
114
131
  return;
115
132
  }
116
133
 
117
- export { markJsonSchemaObjectGuards, markRemoteUnionVerdict, localVerdict, jsonSchemaObjectCoercionMembers };
134
+ export { markJsonSchemaObjectGuards, markRemoteSchemaVerdict, localVerdict, jsonSchemaObjectCoercionMembers };
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-jgwqc38k.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-zm1k7hhv.js";
6
+ } from "./index-v6mzw27b.js";
7
7
  import {
8
8
  runtimeToolMountable
9
9
  } from "./index-nk1mh535.js";
@@ -170,7 +170,8 @@ var ReplaceCompactedRangeSchema2 = z2.object({
170
170
  var SeedConversationInputSchema2 = z2.object({
171
171
  conversationId: AgentRecordIdSchema2,
172
172
  seedKey: z2.string().min(1),
173
- inputs: z2.array(AgentMessageSchema2).min(1)
173
+ inputs: z2.array(AgentMessageSchema2).min(1),
174
+ placement: z2.enum(["lead", "after-settled"]).optional()
174
175
  });
175
176
  var AgentRecoverableDescriptorSchema2 = z2.object({
176
177
  conversationId: AgentRecordIdSchema2,
@@ -3,10 +3,10 @@ import {
3
3
  } from "./index-fynr93w4.js";
4
4
  import {
5
5
  jsonSchemaObjectCoercionMembers
6
- } from "./index-epmnrnth.js";
6
+ } from "./index-dsa676h8.js";
7
7
  import {
8
8
  coerceJsonArgs2
9
- } from "./index-jy9wq8tp.js";
9
+ } from "./index-rbzq0q16.js";
10
10
  import {
11
11
  jsonSchemaFields
12
12
  } from "./index-ct75c3at.js";
@@ -18,11 +18,11 @@ import {
18
18
  import {
19
19
  toolResultFromError,
20
20
  toolErrorFromResult
21
- } from "./index-z4ga1fa1.js";
21
+ } from "./index-tg2q89ps.js";
22
22
  import {
23
23
  createToolRunner,
24
24
  formatToolError
25
- } from "./index-zm1k7hhv.js";
25
+ } from "./index-v6mzw27b.js";
26
26
  import {
27
27
  fetchGuarded,
28
28
  readCapped
@@ -35,7 +35,7 @@ import {
35
35
  } from "./index-eemvahkc.js";
36
36
  import {
37
37
  collectToolSurface
38
- } from "./index-eddzs589.js";
38
+ } from "./index-emrmgq3s.js";
39
39
  import {
40
40
  isUnsafeKey,
41
41
  safeJsonParse
@@ -5,7 +5,7 @@ import {
5
5
  AgentRecoverableDescriptorSchema2,
6
6
  AgentRecoverablePageSchema2,
7
7
  canonicalAgentJson2
8
- } from "./index-jna0ejsa.js";
8
+ } from "./index-fggxgbrk.js";
9
9
  import {
10
10
  AgentMessageSchema2,
11
11
  AgentRunSchema2
@@ -19,7 +19,7 @@ import {
19
19
  appendEventIn,
20
20
  ArchiveProjectionSchema,
21
21
  createAgentRuntimeStore2
22
- } from "./index-f2p949ax.js";
22
+ } from "./index-yjnmac9b.js";
23
23
  import {
24
24
  AgentConversationPageSchema2,
25
25
  AgentConversationMessagePageSchema2
@@ -656,7 +656,7 @@ var sqliteHistory = {
656
656
  },
657
657
  async apply(transaction, rawMutation) {
658
658
  const mutation = AgentHistoryMutationSchema2.parse(rawMutation);
659
- const message = mutation.type === "admit" ? mutation.input : mutation.type === "upsert-assistant" ? mutation.message : mutation.type === "seed" ? mutation.message : mutation.summary;
659
+ const message = mutation.type === "admit" ? mutation.input : mutation.type === "upsert-assistant" ? mutation.message : mutation.type === "seed" || mutation.type === "insert" ? mutation.message : mutation.summary;
660
660
  if (mutation.type === "seed") {
661
661
  transaction.prepare(`
662
662
  UPDATE stitchkit_agent_runtime_messages SET position = position + 1
@@ -700,6 +700,25 @@ var sqliteHistory = {
700
700
  SELECT position FROM stitchkit_agent_runtime_messages
701
701
  WHERE conversation_id = ? AND id = ?
702
702
  `).get(message.conversationId, message.id);
703
+ if (mutation.type === "insert" && missing(existing) && mutation.beforeMessageId) {
704
+ const anchor = transaction.prepare(`
705
+ SELECT position FROM stitchkit_agent_runtime_messages
706
+ WHERE conversation_id = ? AND id = ? AND active = 1
707
+ `).get(message.conversationId, mutation.beforeMessageId);
708
+ if (missing(anchor))
709
+ throw new Error("Insert anchor is not in the active history");
710
+ const { position } = PositionedMessageRowSchema.parse(anchor);
711
+ transaction.prepare(`
712
+ UPDATE stitchkit_agent_runtime_messages SET position = position + 1
713
+ WHERE conversation_id = ? AND position >= ?
714
+ `).run(message.conversationId, position);
715
+ transaction.prepare(`
716
+ INSERT INTO stitchkit_agent_runtime_messages
717
+ (conversation_id, id, position, active, payload)
718
+ VALUES (?, ?, ?, 1, ?)
719
+ `).run(message.conversationId, message.id, position, encodeJson(message));
720
+ return;
721
+ }
703
722
  if (!missing(existing)) {
704
723
  transaction.prepare(`
705
724
  UPDATE stitchkit_agent_runtime_messages SET payload = ?, active = 1
@@ -2,7 +2,7 @@ import {
2
2
  AgentStoreEventEnvelopeSchema2,
3
3
  AgentStoreEventPageSchema2,
4
4
  AgentRecoverablePageSchema2
5
- } from "./index-jna0ejsa.js";
5
+ } from "./index-fggxgbrk.js";
6
6
  import {
7
7
  AgentRecordIdSchema2,
8
8
  AgentMessageSchema2
@@ -17,7 +17,7 @@ import {
17
17
  replaceMessage,
18
18
  ArchiveSpillSchema,
19
19
  createAgentRuntimeStore2
20
- } from "./index-f2p949ax.js";
20
+ } from "./index-yjnmac9b.js";
21
21
 
22
22
  // src/agent-runtime/store-memory.ts
23
23
  import { z as z2 } from "zod";
@@ -208,8 +208,24 @@ var memoryHistory = {
208
208
  },
209
209
  async apply(transaction, rawMutation) {
210
210
  const mutation = AgentHistoryMutationSchema2.parse(rawMutation);
211
- const conversationId = mutation.type === "admit" ? mutation.input.conversationId : mutation.type === "upsert-assistant" ? mutation.message.conversationId : mutation.type === "seed" ? mutation.message.conversationId : mutation.summary.conversationId;
211
+ const conversationId = mutation.type === "admit" ? mutation.input.conversationId : mutation.type === "upsert-assistant" ? mutation.message.conversationId : mutation.type === "seed" || mutation.type === "insert" ? mutation.message.conversationId : mutation.summary.conversationId;
212
212
  const current = transaction.histories.get(conversationId) ?? [];
213
+ if (mutation.type === "insert") {
214
+ const existingIndex = current.findIndex((message) => message.id === mutation.message.id);
215
+ if (existingIndex !== -1) {
216
+ transaction.histories.set(conversationId, replaceMessage(current, mutation.message));
217
+ return;
218
+ }
219
+ const anchorIndex = mutation.beforeMessageId === undefined ? current.length : current.findIndex((message) => message.id === mutation.beforeMessageId);
220
+ if (anchorIndex === -1)
221
+ throw new Error("Insert anchor is not in the active history");
222
+ transaction.histories.set(conversationId, [
223
+ ...current.slice(0, anchorIndex),
224
+ mutation.message,
225
+ ...current.slice(anchorIndex)
226
+ ]);
227
+ return;
228
+ }
213
229
  if (mutation.type === "admit") {
214
230
  transaction.histories.set(conversationId, [...current, mutation.input]);
215
231
  return;
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  ToolExecutionControlError2,
16
16
  isToolExecutionControlError2
17
- } from "./index-z4ga1fa1.js";
17
+ } from "./index-tg2q89ps.js";
18
18
  import {
19
19
  agentDurableEventId2
20
20
  } from "./index-mnkk1ffz.js";
@@ -34,7 +34,7 @@ import {
34
34
  ProviderJournalMessageSchema,
35
35
  ProviderJournalRequestSchema,
36
36
  ProviderJournalResponseSchema
37
- } from "./index-jna0ejsa.js";
37
+ } from "./index-fggxgbrk.js";
38
38
  import {
39
39
  messageOf
40
40
  } from "./index-g149e9pk.js";
@@ -3214,7 +3214,7 @@ async function applyStreamPart(execution, scope, part) {
3214
3214
  }
3215
3215
 
3216
3216
  // src/agent-runtime/run-model-attempts.ts
3217
- function createStopConditions(execution) {
3217
+ function createStopConditions(execution, turn) {
3218
3218
  const { config, maxSteps } = execution.dependencies;
3219
3219
  const { state } = execution;
3220
3220
  const maxStepCondition = stepCountIs(maxSteps);
@@ -3228,7 +3228,7 @@ function createStopConditions(execution) {
3228
3228
  ];
3229
3229
  for (const policy of config.loop?.stopPolicies ?? []) {
3230
3230
  stopConditions.push(async (options) => {
3231
- const stopped = await policy.when(options);
3231
+ const stopped = await policy.when({ ...options, ...turn.runtimeContext });
3232
3232
  if (stopped && state.terminalPolicyName === undefined)
3233
3233
  state.terminalPolicyName = policy.name;
3234
3234
  return stopped;
@@ -3452,7 +3452,7 @@ async function consumeAttempt(context, attempt, stream) {
3452
3452
  async function runModelAttempts(execution, turn) {
3453
3453
  const { config, publish, now } = execution.dependencies;
3454
3454
  const { state } = execution;
3455
- const stopConditions = createStopConditions(execution);
3455
+ const stopConditions = createStopConditions(execution, turn);
3456
3456
  const loop = {
3457
3457
  retryAttempt: 1,
3458
3458
  takenThisAttempt: [],
@@ -3,11 +3,11 @@ import {
3
3
  } from "./index-jgwqc38k.js";
4
4
  import {
5
5
  toolErrorFromResult
6
- } from "./index-z4ga1fa1.js";
6
+ } from "./index-tg2q89ps.js";
7
7
  import {
8
8
  collectTools2,
9
9
  createToolRunner
10
- } from "./index-zm1k7hhv.js";
10
+ } from "./index-v6mzw27b.js";
11
11
  import {
12
12
  AppError2
13
13
  } from "./index-j9gxbztg.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  jsonSchemaObjectCoercionMembers
3
- } from "./index-epmnrnth.js";
3
+ } from "./index-dsa676h8.js";
4
4
  import {
5
5
  safeJsonParse
6
6
  } from "./index-zsarb5xp.js";
@@ -2,18 +2,18 @@ import {
2
2
  toolResultFromError,
3
3
  toolCauseFromResult,
4
4
  isToolExecutionControlError2
5
- } from "./index-z4ga1fa1.js";
5
+ } from "./index-tg2q89ps.js";
6
6
  import {
7
7
  createToolRunner,
8
8
  formatToolError
9
- } from "./index-zm1k7hhv.js";
9
+ } from "./index-v6mzw27b.js";
10
10
  import {
11
11
  AgentToolError2,
12
12
  resolveToolDurability
13
13
  } from "./index-56yx8dxp.js";
14
14
  import {
15
15
  collectToolSurface
16
- } from "./index-eddzs589.js";
16
+ } from "./index-emrmgq3s.js";
17
17
  import {
18
18
  agentPresenterOf
19
19
  } from "./index-nk1mh535.js";
@@ -4,10 +4,10 @@ import {
4
4
  } from "./index-fynr93w4.js";
5
5
  import {
6
6
  localVerdict
7
- } from "./index-epmnrnth.js";
7
+ } from "./index-dsa676h8.js";
8
8
  import {
9
9
  coerceJsonArgs2
10
- } from "./index-jy9wq8tp.js";
10
+ } from "./index-rbzq0q16.js";
11
11
  import {
12
12
  applyToolViewDefaults,
13
13
  projectToolView,
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  toolErrorFromResult,
9
9
  executeToolMethod
10
- } from "./index-z4ga1fa1.js";
10
+ } from "./index-tg2q89ps.js";
11
11
  import {
12
12
  isRetryableStatus2
13
13
  } from "./index-j9gxbztg.js";
@@ -39,7 +39,7 @@ import {
39
39
  ProviderJournalMessageSchema,
40
40
  ProviderJournalRequestSchema,
41
41
  ProviderJournalResponseSchema
42
- } from "./index-jna0ejsa.js";
42
+ } from "./index-fggxgbrk.js";
43
43
  import {
44
44
  StepEventPayloadSchema,
45
45
  ParkEventPayloadSchema,
@@ -154,6 +154,11 @@ var AgentHistoryMutationSchema2 = z3.discriminatedUnion("type", [
154
154
  z3.object({
155
155
  type: z3.literal("seed"),
156
156
  message: AgentMessageSchema2
157
+ }),
158
+ z3.object({
159
+ type: z3.literal("insert"),
160
+ message: AgentMessageSchema2,
161
+ beforeMessageId: AgentRecordIdSchema2.optional()
157
162
  })
158
163
  ]);
159
164
  var ACTIVE_AGENT_RUN_STATES2 = [
@@ -362,22 +367,51 @@ function reduceAccept(current, input) {
362
367
  historyMutations: [{ type: "admit", input: input.input }]
363
368
  });
364
369
  }
370
+ function seedReceipt(input) {
371
+ return AgentSeedReceiptSchema2.parse({
372
+ schemaVersion: 1,
373
+ conversationId: input.conversationId,
374
+ seedKey: input.seedKey,
375
+ messageIds: input.inputs.map((message) => message.id)
376
+ });
377
+ }
378
+ function reduceSettledSeed(current, input) {
379
+ for (const message of input.inputs) {
380
+ if (message.conversationId !== input.conversationId || message.runId !== undefined || !(message.role === "user" && message.status === "committed" || message.role === "assistant" && message.status === "completed")) {
381
+ throw new TypeError("A settled exchange must be committed user and completed assistant messages no run owns");
382
+ }
383
+ }
384
+ const activeMessageIds = new Set(current.runs.filter((run) => isActiveRunState(run.state)).flatMap((run) => [...run.inputMessageIds, run.assistantMessageId]));
385
+ const anchor = current.messages.find((message) => activeMessageIds.has(message.id));
386
+ const at = anchor ? current.messages.indexOf(anchor) : current.messages.length;
387
+ return applied(current, {
388
+ messages: [
389
+ ...current.messages.slice(0, at),
390
+ ...input.inputs,
391
+ ...current.messages.slice(at)
392
+ ]
393
+ }, {
394
+ seedReceipt: seedReceipt(input),
395
+ historyMutations: input.inputs.map((message) => ({
396
+ type: "insert",
397
+ message,
398
+ ...anchor && { beforeMessageId: anchor.id }
399
+ }))
400
+ });
401
+ }
365
402
  function reduceSeed(current, input) {
366
403
  const conversationId = input.conversationId;
367
404
  if (current.conversationId !== conversationId)
368
405
  return { outcome: "not_found" };
406
+ if (input.placement === "after-settled")
407
+ return reduceSettledSeed(current, input);
369
408
  for (const message of input.inputs) {
370
409
  if (message.conversationId !== conversationId || message.role !== "user" || message.status !== "committed" || message.runId !== undefined) {
371
410
  throw new TypeError("Seeded conversation input must be committed unowned user messages");
372
411
  }
373
412
  }
374
413
  return applied(current, { messages: [...input.inputs, ...current.messages] }, {
375
- seedReceipt: AgentSeedReceiptSchema2.parse({
376
- schemaVersion: 1,
377
- conversationId,
378
- seedKey: input.seedKey,
379
- messageIds: input.inputs.map((message) => message.id)
380
- }),
414
+ seedReceipt: seedReceipt(input),
381
415
  historyMutations: [...input.inputs].reverse().map((message) => ({
382
416
  type: "seed",
383
417
  message
@@ -21,7 +21,7 @@ export declare function withConnectionToken<T>(params: {
21
21
  * Turn a discovered JSON Schema into a `ZodObject`, falling back to a permissive
22
22
  * object when the external schema is absent or not an object. This is the typed
23
23
  * boundary: the schema crosses from an untrusted foreign document into Zod here
24
- * and nowhere else. Its unions are left to the remote that owns the schema.
24
+ * and nowhere else. Unions and string formats are left to the remote that owns the schema.
25
25
  */
26
26
  export declare function zodObjectFromJsonSchema(schema: Record<string, unknown> | undefined): ZodObject;
27
27
  /** Normalise a tool name into the characters every provider accepts. */
@@ -6,19 +6,20 @@ import { z } from 'zod';
6
6
  */
7
7
  export declare function markJsonSchemaObjectGuards(schema: z.core.$ZodType): void;
8
8
  /**
9
- * Record that a schema restored from a foreign document leaves its unions to the remote.
9
+ * Record that a foreign schema leaves unions and string formats to its remote owner.
10
10
  *
11
11
  * A foreign tool schema is the remote's presentation, and a presentation may join a
12
12
  * discriminated union into one object whose shared field is an unlabelled `anyOf` (a stitchkit
13
13
  * server with `flattenUnionInput` does, ADR 0205). Every value the remote accepts still passes
14
14
  * such a union; which branch a value was meant for does not survive. Judged here, a wrong value
15
15
  * can only be refused with every branch listed, while the remote, which holds the original
16
- * schema, names the one field that is wrong.
16
+ * schema, names the one field that is wrong. JSON Schema also carries string formats and
17
+ * patterns without the author's error messages; only the remote can report those faithfully.
17
18
  */
18
- export declare function markRemoteUnionVerdict(schema: z.ZodObject): void;
19
+ export declare function markRemoteSchemaVerdict(schema: z.ZodObject): void;
19
20
  /**
20
- * What a local parse refuses of a value the remote judges: everything but its unions. `null` when
21
- * every refusal was a union's — the value goes to the remote, whose refusal is the answer.
21
+ * Retain every reported issue except foreign unions and string formats. `null` means that
22
+ * every refusal belongs to the remote, whose answer carries the original schema's wording.
22
23
  * A schema that is not a restored foreign one keeps its own verdict whole.
23
24
  */
24
25
  export declare function localVerdict(schema: z.core.$ZodType, error: z.ZodError): z.ZodError | null;
@@ -1 +1 @@
1
- {"version":3,"file":"json-schema-origin.d.ts","sourceRoot":"","sources":["../../../src/tools/schema/json-schema-origin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAiExE;AAID;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAOhE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,CAK1F;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GACtB,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,SAAS,CAsBxC"}
1
+ {"version":3,"file":"json-schema-origin.d.ts","sourceRoot":"","sources":["../../../src/tools/schema/json-schema-origin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgCxB;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAiExE;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAOjE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,GAAG,IAAI,CAK1F;AAuBD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,GACtB,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,SAAS,CAsBxC"}
@@ -256,6 +256,31 @@ implement the smaller `AgentRuntimeStoreDriver` rather than these eleven members
256
256
  calls this and nothing else, so an adapter that implements the interface has
257
257
  everything recovery needs
258
258
 
259
+ ### Writing history no run owns
260
+
261
+ `seedConversationInput` writes messages no run owns, exactly once per `seedKey`; the key is
262
+ recorded beside the history, so compaction or replacement of the messages never brings them
263
+ back. It places them by `placement`:
264
+
265
+ - absent or `'lead'` — committed user instructions ahead of the whole conversation;
266
+ - `'after-settled'` — an exchange that already happened without a model (a confirmed voice
267
+ command and its receipt): committed `user` and completed `assistant` messages. They land after
268
+ the settled history and ahead of the first message of any run still active, so an active run's
269
+ input and answer stay adjacent and the next run reads the exchange before the input queued
270
+ behind it. With no active run they are the tail.
271
+
272
+ ```ts
273
+ await store.seedConversationInput({
274
+ conversationId,
275
+ seedKey: `voice:${commandId}`,
276
+ placement: 'after-settled',
277
+ inputs: [ownerMessage, receiptMessage],
278
+ })
279
+ ```
280
+
281
+ The pair is ordinary history: it is in `loadSnapshot`, compaction may summarize it, and the next
282
+ provider request carries it. No model is called and no run is created.
283
+
259
284
  ### Reading a conversation
260
285
 
261
286
  Two shapes of read, and the difference matters as a conversation grows.
@@ -181,7 +181,7 @@ Server-only optional application runtime. See the
181
181
  | `selectCompactableHistory` | function | which oldest whole complete turns may be summarised away — the half of compaction that needs no store (→ ADR 0142) |
182
182
  | `SelectCompactableHistoryOptions` / `CompactableHistory` | _type_ | message list, retained-turn count and evidence policy in; `leadingSummary`, `compactable` and `retained` out |
183
183
  | `createAgentSessionCoordinator` | function | strict process-local queue/interrupt/supersede lifecycle |
184
- | `AgentRuntimeStopPolicy` | _type_ | named custom AI SDK stop condition persisted and published on policy stop |
184
+ | `AgentRuntimeStopPolicy` | _type_ | named stop rule persisted and published on policy stop; `when` receives the AI SDK `steps` plus the run context `prepareStep` gets (`context`, `run`, `signal`, `toolFenceLifecycle`, `contextUsage`) |
185
185
  | `AgentRuntimePrepareStep` | _type_ | per-run controlled step callback with typed domain context and managed run signal/fence |
186
186
  | `AgentContextOverflowError` | class | deliberate application budget refusal thrown from `loop.prepareStep`; terminalizes as `context_overflow` without classifying arbitrary error text |
187
187
  | `AgentRuntimeRecordIds` | _type_ | optional caller-provided input, run and assistant IDs for stable application records |
@@ -165,6 +165,12 @@ await ticket.accepted
165
165
  const terminal = await ticket.result
166
166
  ```
167
167
 
168
+ A stop policy's `when` receives the steps so far together with the same run context
169
+ `prepareStep` gets — `context`, `run`, `signal`, `toolFenceLifecycle` and `contextUsage` —
170
+ typed by the runtime's `CONTEXT`. A rule that depends on its own run (a receipt bound to the
171
+ run's request, a per-tenant limit) reads it there; it needs no map of its own keyed by `runId`.
172
+ The first policy to return `true` ends the run as `policy_stop` with its `name` as `policyName`.
173
+
168
174
  ## Bounded deferred tool catalogs
169
175
 
170
176
  Use `createDeferredAgentToolSurface` when a measured large catalog makes