stitchkit 0.112.2 → 0.113.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 (56) 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/coding-tools.js +3 -3
  16. package/dist/entrypoints/agent-runtime/harness.js +5 -5
  17. package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
  18. package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
  19. package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
  20. package/dist/entrypoints/agent-runtime/testing.js +37 -6
  21. package/dist/entrypoints/agent-runtime.js +11 -11
  22. package/dist/entrypoints/cli.js +6 -6
  23. package/dist/entrypoints/testing.js +1 -1
  24. package/dist/entrypoints/tools/connections.js +6 -6
  25. package/dist/entrypoints/tools/invoker.js +4 -4
  26. package/dist/entrypoints/tools/mcp.js +6 -6
  27. package/dist/entrypoints/tools.js +9 -9
  28. package/dist/{index-jfk93gja.js → index-4dh3hfs7.js} +3 -3
  29. package/dist/{index-651xsm48.js → index-54q2mghq.js} +4 -4
  30. package/dist/{index-c7h371gr.js → index-5jjda9a4.js} +4 -4
  31. package/dist/{index-n0adphfg.js → index-dsxrcseb.js} +1 -1
  32. package/dist/{index-hvg9hctd.js → index-eddzs589.js} +3 -3
  33. package/dist/{index-jna0ejsa.js → index-fggxgbrk.js} +2 -1
  34. package/dist/{index-bd7spznx.js → index-gpbk7yse.js} +4 -4
  35. package/dist/{index-fh2ht88b.js → index-gz9jf461.js} +22 -3
  36. package/dist/{index-h7accrrv.js → index-jgwqc38k.js} +66 -6
  37. package/dist/{index-d4cnhfdn.js → index-k0zfcxf5.js} +19 -3
  38. package/dist/{index-ff3agzaf.js → index-nk1mh535.js} +1 -1
  39. package/dist/{index-a0vj9edp.js → index-ppf5nerp.js} +5 -5
  40. package/dist/{index-38gvr73z.js → index-yjnmac9b.js} +42 -8
  41. package/dist/{index-02h0dfpr.js → index-z4ga1fa1.js} +1 -1
  42. package/dist/{index-vqdjym30.js → index-zm1k7hhv.js} +2 -2
  43. package/dist/json-schema/dialect.d.ts +12 -10
  44. package/dist/json-schema/dialect.d.ts.map +1 -1
  45. package/dist/tools/schema/presentation.d.ts +4 -3
  46. package/dist/tools/schema/presentation.d.ts.map +1 -1
  47. package/llms/agent-runtime.2.txt +25 -0
  48. package/llms/agent-runtime.3.txt +1 -1
  49. package/llms/agent-runtime.txt +6 -0
  50. package/llms/stitchkit.txt +3 -3
  51. package/llms/{upgrading-0.103.0-0.112.0.txt → upgrading-0.103.13-0.113.0.txt} +22 -32
  52. package/llms/{upgrading-0.75.0-0.102.0.txt → upgrading-0.75.0-0.103.0.txt} +32 -3
  53. package/llms/upgrading.txt +2 -2
  54. package/llms-full.txt +54 -4
  55. package/llms.txt +3 -3
  56. package/package.json +2 -1
@@ -5,7 +5,7 @@ import {
5
5
  missingSandboxRestrictions2,
6
6
  recordAgentSandboxProbe2,
7
7
  refuseUnknownSpillReference
8
- } from "../index-n0adphfg.js";
8
+ } from "../index-dsxrcseb.js";
9
9
  import {
10
10
  AgentRecordIdSchema2,
11
11
  AgentRecordVersionSchema2,
@@ -58,7 +58,7 @@ import {
58
58
  AgentHistoryMutationSchema2,
59
59
  ACTIVE_AGENT_RUN_STATES2,
60
60
  createAgentRuntimeStore2
61
- } from "../index-38gvr73z.js";
61
+ } from "../index-yjnmac9b.js";
62
62
  import {
63
63
  AgentStoreEventKindSchema2,
64
64
  AgentStoreEventEnvelopeSchema2,
@@ -91,7 +91,7 @@ import {
91
91
  decodeAgentConversationArchive2,
92
92
  isAssistantHistoryEvidence2,
93
93
  isCompleteAgentHistoryTurn
94
- } from "../index-jna0ejsa.js";
94
+ } from "../index-fggxgbrk.js";
95
95
  import"../index-5w6t91ze.js";
96
96
  import {
97
97
  AgentRuntimeConflictError2,
@@ -123,7 +123,7 @@ import {
123
123
  agentGoalStateSlot2,
124
124
  agentTodoStateSlot2,
125
125
  createAgentRuntime2
126
- } from "../index-a0vj9edp.js";
126
+ } from "../index-ppf5nerp.js";
127
127
  import {
128
128
  AgentConversationSummarySchema2,
129
129
  AgentConversationPageSchema2,
@@ -133,13 +133,13 @@ import"../index-fynr93w4.js";
133
133
  import"../index-epmnrnth.js";
134
134
  import"../index-jy9wq8tp.js";
135
135
  import"../index-ct75c3at.js";
136
- import"../index-h7accrrv.js";
137
- import"../index-02h0dfpr.js";
138
- import"../index-vqdjym30.js";
136
+ import"../index-jgwqc38k.js";
137
+ import"../index-z4ga1fa1.js";
138
+ import"../index-zm1k7hhv.js";
139
139
  import {
140
140
  mountAgent2,
141
141
  buildToolManifest2
142
- } from "../index-c7h371gr.js";
142
+ } from "../index-5jjda9a4.js";
143
143
  import {
144
144
  createBoundedSinkManager
145
145
  } from "../index-qaet40b2.js";
@@ -191,7 +191,7 @@ import"../index-84bf5spd.js";
191
191
  import"../index-7r4knwf8.js";
192
192
  import {
193
193
  createMemoryAgentRuntimeStore2
194
- } from "../index-d4cnhfdn.js";
194
+ } from "../index-k0zfcxf5.js";
195
195
  import {
196
196
  createAgentRuntimeEventSink2
197
197
  } from "../index-616xh7f2.js";
@@ -202,11 +202,11 @@ import {
202
202
  import {
203
203
  assertPositiveSafeInteger
204
204
  } from "../index-0s4xebbg.js";
205
- import"../index-hvg9hctd.js";
205
+ import"../index-eddzs589.js";
206
206
  import {
207
207
  defineRuntimeTool2,
208
208
  executableAgentRuntimeTools
209
- } from "../index-ff3agzaf.js";
209
+ } from "../index-nk1mh535.js";
210
210
  import {
211
211
  createTraceContext2,
212
212
  childSpan2
@@ -16,12 +16,12 @@ import {
16
16
  renderCliView2,
17
17
  pollUntilDone2,
18
18
  createCli2
19
- } from "../index-bd7spznx.js";
19
+ } from "../index-gpbk7yse.js";
20
20
  import"../index-fynr93w4.js";
21
21
  import"../index-ct75c3at.js";
22
- import"../index-h7accrrv.js";
23
- import"../index-02h0dfpr.js";
24
- import"../index-vqdjym30.js";
22
+ import"../index-jgwqc38k.js";
23
+ import"../index-z4ga1fa1.js";
24
+ import"../index-zm1k7hhv.js";
25
25
  import {
26
26
  CliBuildSignatureSchema2,
27
27
  cliManifestSigningPayload2,
@@ -44,8 +44,8 @@ import {
44
44
  import {
45
45
  writeFileAtomicSync2
46
46
  } from "../index-07dcf2yn.js";
47
- import"../index-hvg9hctd.js";
48
- import"../index-ff3agzaf.js";
47
+ import"../index-eddzs589.js";
48
+ import"../index-nk1mh535.js";
49
49
  import {
50
50
  safeJsonParse
51
51
  } from "../index-zsarb5xp.js";
@@ -30,7 +30,7 @@ import {
30
30
  projectToolSurface,
31
31
  mcpProjectionCandidate,
32
32
  prepareProjectedMcpTools
33
- } from "../index-h7accrrv.js";
33
+ } from "../index-jgwqc38k.js";
34
34
  import"../index-fynr93w4.js";
35
35
  import {
36
36
  createClient2,
@@ -1,8 +1,8 @@
1
1
  import"../../index-ct75c3at.js";
2
2
  import {
3
3
  declaresDraft07,
4
- withDefsDialect
5
- } from "../../index-h7accrrv.js";
4
+ withDraft2020Keywords
5
+ } from "../../index-jgwqc38k.js";
6
6
  import"../../index-fynr93w4.js";
7
7
  import {
8
8
  markJsonSchemaObjectGuards,
@@ -26,7 +26,7 @@ import {
26
26
  } from "../../index-0s4xebbg.js";
27
27
  import {
28
28
  defineRuntimeTool2
29
- } from "../../index-ff3agzaf.js";
29
+ } from "../../index-nk1mh535.js";
30
30
  import {
31
31
  TOOL_ERROR_PROJECTION
32
32
  } from "../../index-556g5hsh.js";
@@ -844,7 +844,7 @@ async function withConnectionToken(params, body) {
844
844
  function zodObjectFromJsonSchema(schema) {
845
845
  if (!schema || Object.keys(schema).length === 0)
846
846
  return z.looseObject({});
847
- const parsed = z.fromJSONSchema(reconcileDefinitionKeyword(schema));
847
+ const parsed = z.fromJSONSchema(reconcileDialect(schema));
848
848
  if (parsed instanceof z.ZodObject) {
849
849
  markJsonSchemaObjectGuards(parsed);
850
850
  markRemoteUnionVerdict(parsed);
@@ -852,8 +852,8 @@ function zodObjectFromJsonSchema(schema) {
852
852
  }
853
853
  return z.looseObject({});
854
854
  }
855
- function reconcileDefinitionKeyword(schema) {
856
- return declaresDraft07(schema.$schema) ? schema : withDefsDialect(schema);
855
+ function reconcileDialect(schema) {
856
+ return declaresDraft07(schema.$schema) ? schema : withDraft2020Keywords(schema);
857
857
  }
858
858
  function sanitizeToolName(value) {
859
859
  return value.replace(/[^a-zA-Z0-9_-]+/g, "_").replace(/^_+|_+$/g, "") || "operation";
@@ -2,12 +2,12 @@ import"../../index-fynr93w4.js";
2
2
  import"../../index-epmnrnth.js";
3
3
  import"../../index-jy9wq8tp.js";
4
4
  import"../../index-ct75c3at.js";
5
- import"../../index-h7accrrv.js";
6
- import"../../index-02h0dfpr.js";
7
- import"../../index-vqdjym30.js";
5
+ import"../../index-jgwqc38k.js";
6
+ import"../../index-z4ga1fa1.js";
7
+ import"../../index-zm1k7hhv.js";
8
8
  import {
9
9
  createToolInvoker2
10
- } from "../../index-jfk93gja.js";
10
+ } from "../../index-4dh3hfs7.js";
11
11
  export {
12
12
  createToolInvoker2 as createToolInvoker
13
13
  };
@@ -2,9 +2,9 @@ import"../../index-ct75c3at.js";
2
2
  import"../../index-fynr93w4.js";
3
3
  import"../../index-epmnrnth.js";
4
4
  import"../../index-jy9wq8tp.js";
5
- import"../../index-h7accrrv.js";
6
- import"../../index-02h0dfpr.js";
7
- import"../../index-vqdjym30.js";
5
+ import"../../index-jgwqc38k.js";
6
+ import"../../index-z4ga1fa1.js";
7
+ import"../../index-zm1k7hhv.js";
8
8
  import {
9
9
  RESOURCE_MIME_TYPE2,
10
10
  EXT_APPS_BUNDLE_PLACEHOLDER2,
@@ -20,9 +20,9 @@ import {
20
20
  createMcpHttpRoute2,
21
21
  createStdioMcpServer2,
22
22
  bindStdioProcessSignals2
23
- } from "../../index-651xsm48.js";
24
- import"../../index-hvg9hctd.js";
25
- import"../../index-ff3agzaf.js";
23
+ } from "../../index-54q2mghq.js";
24
+ import"../../index-eddzs589.js";
25
+ import"../../index-nk1mh535.js";
26
26
  export {
27
27
  EXT_APPS_BUNDLE_PLACEHOLDER2 as EXT_APPS_BUNDLE_PLACEHOLDER,
28
28
  MCP_CATALOG_META_KEY2 as MCP_CATALOG_META_KEY,
@@ -21,19 +21,19 @@ import {
21
21
  findNonPortableFormats2,
22
22
  flattenToolJsonSchema2,
23
23
  findUntypedProperties2
24
- } from "../index-h7accrrv.js";
24
+ } from "../index-jgwqc38k.js";
25
25
  import {
26
26
  ToolExecutionControlError2,
27
27
  isToolExecutionControlError2
28
- } from "../index-02h0dfpr.js";
28
+ } from "../index-z4ga1fa1.js";
29
29
  import {
30
30
  collectTools2
31
- } from "../index-vqdjym30.js";
31
+ } from "../index-zm1k7hhv.js";
32
32
  import {
33
33
  mountAgent2,
34
34
  describeToolCatalog2,
35
35
  buildToolManifest2
36
- } from "../index-c7h371gr.js";
36
+ } from "../index-5jjda9a4.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-651xsm48.js";
63
+ } from "../index-54q2mghq.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-bd7spznx.js";
77
+ } from "../index-gpbk7yse.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-jfk93gja.js";
92
+ } from "../index-4dh3hfs7.js";
93
93
  import {
94
94
  ManagedFileError2
95
95
  } from "../index-2f9r0jgr.js";
@@ -111,14 +111,14 @@ import {
111
111
  } from "../index-yk4g8805.js";
112
112
  import {
113
113
  collectToolSurface
114
- } from "../index-hvg9hctd.js";
114
+ } from "../index-eddzs589.js";
115
115
  import {
116
116
  getTraceId2
117
117
  } from "../index-r6v4mc67.js";
118
118
  import {
119
119
  defineRuntimeTool2,
120
120
  createRuntimeToolFactory2
121
- } from "../index-ff3agzaf.js";
121
+ } from "../index-nk1mh535.js";
122
122
  import {
123
123
  formatZodError2
124
124
  } from "../index-1eeqpadm.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  assertUniqueToolName
3
- } from "./index-h7accrrv.js";
3
+ } from "./index-jgwqc38k.js";
4
4
  import {
5
5
  toolErrorFromResult
6
- } from "./index-02h0dfpr.js";
6
+ } from "./index-z4ga1fa1.js";
7
7
  import {
8
8
  collectTools2,
9
9
  createToolRunner
10
- } from "./index-vqdjym30.js";
10
+ } from "./index-zm1k7hhv.js";
11
11
  import {
12
12
  AppError2
13
13
  } from "./index-j9gxbztg.js";
@@ -8,17 +8,17 @@ import {
8
8
  validateResolvedInputRounds,
9
9
  presentationMetadata,
10
10
  prepareProjectedMcpTools
11
- } from "./index-h7accrrv.js";
11
+ } from "./index-jgwqc38k.js";
12
12
  import {
13
13
  parseToolCallArguments,
14
14
  toolResultFromError,
15
15
  observed
16
- } from "./index-02h0dfpr.js";
16
+ } from "./index-z4ga1fa1.js";
17
17
  import {
18
18
  collectTools2,
19
19
  createToolRunner,
20
20
  formatToolError
21
- } from "./index-vqdjym30.js";
21
+ } from "./index-zm1k7hhv.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-hvg9hctd.js";
34
+ } from "./index-eddzs589.js";
35
35
  import {
36
36
  runWithRequestContext2,
37
37
  getRequestContext2
@@ -2,21 +2,21 @@ import {
2
2
  toolResultFromError,
3
3
  toolCauseFromResult,
4
4
  isToolExecutionControlError2
5
- } from "./index-02h0dfpr.js";
5
+ } from "./index-z4ga1fa1.js";
6
6
  import {
7
7
  createToolRunner,
8
8
  formatToolError
9
- } from "./index-vqdjym30.js";
9
+ } from "./index-zm1k7hhv.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-hvg9hctd.js";
16
+ } from "./index-eddzs589.js";
17
17
  import {
18
18
  agentPresenterOf
19
- } from "./index-ff3agzaf.js";
19
+ } from "./index-nk1mh535.js";
20
20
  import {
21
21
  isRecord
22
22
  } from "./index-9jfdm5tg.js";
@@ -27,7 +27,7 @@ import {
27
27
  } from "./index-j4zh647a.js";
28
28
  import {
29
29
  defineRuntimeTool2
30
- } from "./index-ff3agzaf.js";
30
+ } from "./index-nk1mh535.js";
31
31
  import {
32
32
  AppError2,
33
33
  forbidden2,
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  projectToolSurface
3
- } from "./index-h7accrrv.js";
3
+ } from "./index-jgwqc38k.js";
4
4
  import {
5
5
  contractToolMountable
6
- } from "./index-vqdjym30.js";
6
+ } from "./index-zm1k7hhv.js";
7
7
  import {
8
8
  runtimeToolMountable
9
- } from "./index-ff3agzaf.js";
9
+ } from "./index-nk1mh535.js";
10
10
 
11
11
  // src/tools/surface.ts
12
12
  function collectToolSurface({
@@ -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,
@@ -14,15 +14,15 @@ import {
14
14
  objectShapeKeys,
15
15
  assertUniqueToolName,
16
16
  buildToolPresentationSchema
17
- } from "./index-h7accrrv.js";
17
+ } from "./index-jgwqc38k.js";
18
18
  import {
19
19
  toolResultFromError,
20
20
  toolErrorFromResult
21
- } from "./index-02h0dfpr.js";
21
+ } from "./index-z4ga1fa1.js";
22
22
  import {
23
23
  createToolRunner,
24
24
  formatToolError
25
- } from "./index-vqdjym30.js";
25
+ } from "./index-zm1k7hhv.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-hvg9hctd.js";
38
+ } from "./index-eddzs589.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-38gvr73z.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
@@ -763,6 +763,27 @@ import { z as z2 } from "zod";
763
763
  var DRAFT_07_MARKER = "draft-07";
764
764
  var DRAFT_07_KEYWORD = "definitions";
765
765
  var DEFS_KEYWORD = "$defs";
766
+ var SCHEMA_KEYWORDS = [
767
+ "items",
768
+ "additionalItems",
769
+ "additionalProperties",
770
+ "contains",
771
+ "propertyNames",
772
+ "not",
773
+ "if",
774
+ "then",
775
+ "else",
776
+ "unevaluatedItems",
777
+ "unevaluatedProperties"
778
+ ];
779
+ var SCHEMA_LIST_KEYWORDS = ["allOf", "anyOf", "oneOf", "prefixItems"];
780
+ var SCHEMA_MAP_KEYWORDS = [
781
+ "properties",
782
+ "patternProperties",
783
+ "dependentSchemas",
784
+ DRAFT_07_KEYWORD,
785
+ DEFS_KEYWORD
786
+ ];
766
787
  function declaresDraft07(dialect) {
767
788
  return typeof dialect === "string" && dialect.includes(DRAFT_07_MARKER);
768
789
  }
@@ -777,12 +798,51 @@ function rewriteDefinitionPointers(value) {
777
798
  }
778
799
  return rewritten;
779
800
  }
780
- function withDefsDialect(schema) {
781
- const definitions = schema[DRAFT_07_KEYWORD];
782
- if (!isRecord(definitions) || DEFS_KEYWORD in schema)
801
+ function mapValues(value, rewrite) {
802
+ if (!isRecord(value))
803
+ return value;
804
+ const rewritten = {};
805
+ for (const [name, child] of Object.entries(value))
806
+ rewritten[name] = rewrite(child);
807
+ return rewritten;
808
+ }
809
+ function withPositionalItems(schema) {
810
+ if (!isRecord(schema))
783
811
  return schema;
784
812
  const rewritten = {};
785
- for (const [key, value] of Object.entries(schema)) {
813
+ for (const [key, child] of Object.entries(schema)) {
814
+ if (SCHEMA_KEYWORDS.includes(key))
815
+ rewritten[key] = withPositionalItems(child);
816
+ else if (SCHEMA_LIST_KEYWORDS.includes(key) && Array.isArray(child)) {
817
+ rewritten[key] = child.map(withPositionalItems);
818
+ } else if (SCHEMA_MAP_KEYWORDS.includes(key)) {
819
+ rewritten[key] = mapValues(child, withPositionalItems);
820
+ } else
821
+ rewritten[key] = child;
822
+ }
823
+ const { items, additionalItems } = rewritten;
824
+ if (!Array.isArray(items))
825
+ return rewritten;
826
+ const positional = {};
827
+ for (const [key, child] of Object.entries(rewritten)) {
828
+ if (key === "items")
829
+ positional.prefixItems = items;
830
+ else if (key !== "additionalItems")
831
+ positional[key] = child;
832
+ }
833
+ if (additionalItems !== undefined)
834
+ positional.items = additionalItems;
835
+ return positional;
836
+ }
837
+ function withDraft2020Keywords(schema) {
838
+ const positional = withPositionalItems(schema);
839
+ if (!isRecord(positional))
840
+ return schema;
841
+ const definitions = positional[DRAFT_07_KEYWORD];
842
+ if (!isRecord(definitions) || DEFS_KEYWORD in positional)
843
+ return positional;
844
+ const rewritten = {};
845
+ for (const [key, value] of Object.entries(positional)) {
786
846
  if (key === DRAFT_07_KEYWORD)
787
847
  continue;
788
848
  rewritten[key] = rewriteDefinitionPointers(value);
@@ -977,7 +1037,7 @@ function isObjectPresentationSchema(schema) {
977
1037
  return schema.type === "object" && isRecord(schema.properties);
978
1038
  }
979
1039
  function presentationMetadata(schema) {
980
- return withDefsDialect(withoutDialect(schema));
1040
+ return withDraft2020Keywords(withoutDialect(schema));
981
1041
  }
982
1042
 
983
1043
  // src/tools/internal/surface-projector.ts
@@ -1244,4 +1304,4 @@ function prepareProjectedMcpTools(tools, config = {}) {
1244
1304
  return prepared;
1245
1305
  }
1246
1306
 
1247
- export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, declaresDraft07, withDefsDialect, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
1307
+ export { toolSurfaceOutputSchema, applyToolViewDefaults, projectToolView, objectShapeKeys, rebuildObject, mergeSchemas, staticInputRounds, validateMcpRoundPolicy, validateResolvedInputRounds, assertToolName, assertUniqueToolName, PORTABLE_JSON_SCHEMA_FORMATS2, findNonPortableFormats2, declaresDraft07, withDraft2020Keywords, flattenToolJsonSchema2, buildToolPresentationSchema, presentationMetadata, findUntypedProperties2, assertToolExtensionCompatible, projectRuntimeTool, projectToolSurface, mcpProjectionCandidate, prepareProjectedMcpTools };
@@ -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-38gvr73z.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;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  projectRuntimeTool
3
- } from "./index-h7accrrv.js";
3
+ } from "./index-jgwqc38k.js";
4
4
  import {
5
5
  isRecord
6
6
  } from "./index-9jfdm5tg.js";
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  ToolExecutionControlError2,
16
16
  isToolExecutionControlError2
17
- } from "./index-02h0dfpr.js";
17
+ } from "./index-z4ga1fa1.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: [],