stitchkit 0.68.11 → 0.70.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 (125) hide show
  1. package/README.md +30 -1
  2. package/dist/agent-runtime/coding-tool-contract.d.ts +156 -0
  3. package/dist/agent-runtime/coding-tool-contract.d.ts.map +1 -0
  4. package/dist/agent-runtime/coding-tool-files.d.ts +3 -0
  5. package/dist/agent-runtime/coding-tool-files.d.ts.map +1 -0
  6. package/dist/agent-runtime/coding-tool-paths.d.ts +20 -0
  7. package/dist/agent-runtime/coding-tool-paths.d.ts.map +1 -0
  8. package/dist/agent-runtime/coding-tool-search-patch.d.ts +3 -0
  9. package/dist/agent-runtime/coding-tool-search-patch.d.ts.map +1 -0
  10. package/dist/agent-runtime/coding-tool-shell.d.ts +3 -0
  11. package/dist/agent-runtime/coding-tool-shell.d.ts.map +1 -0
  12. package/dist/agent-runtime/coding-tools.d.ts +17 -0
  13. package/dist/agent-runtime/coding-tools.d.ts.map +1 -0
  14. package/dist/agent-runtime/compaction.d.ts +2 -0
  15. package/dist/agent-runtime/compaction.d.ts.map +1 -1
  16. package/dist/agent-runtime/contained-files.d.ts +56 -0
  17. package/dist/agent-runtime/contained-files.d.ts.map +1 -0
  18. package/dist/agent-runtime/control-schema.d.ts +1074 -0
  19. package/dist/agent-runtime/control-schema.d.ts.map +1 -0
  20. package/dist/agent-runtime/conversations.d.ts +128 -0
  21. package/dist/agent-runtime/conversations.d.ts.map +1 -0
  22. package/dist/agent-runtime/event-schema.d.ts +96 -0
  23. package/dist/agent-runtime/event-schema.d.ts.map +1 -1
  24. package/dist/agent-runtime/harness-contract.d.ts +169 -0
  25. package/dist/agent-runtime/harness-contract.d.ts.map +1 -0
  26. package/dist/agent-runtime/harness-control.d.ts +25 -0
  27. package/dist/agent-runtime/harness-control.d.ts.map +1 -0
  28. package/dist/agent-runtime/harness-file-resources.d.ts +33 -0
  29. package/dist/agent-runtime/harness-file-resources.d.ts.map +1 -0
  30. package/dist/agent-runtime/harness-resources.d.ts +5 -0
  31. package/dist/agent-runtime/harness-resources.d.ts.map +1 -0
  32. package/dist/agent-runtime/harness.d.ts +12 -0
  33. package/dist/agent-runtime/harness.d.ts.map +1 -0
  34. package/dist/agent-runtime/history.d.ts +2 -0
  35. package/dist/agent-runtime/history.d.ts.map +1 -1
  36. package/dist/agent-runtime/models.d.ts +199 -0
  37. package/dist/agent-runtime/models.d.ts.map +1 -1
  38. package/dist/agent-runtime/prompt.d.ts +2 -0
  39. package/dist/agent-runtime/prompt.d.ts.map +1 -1
  40. package/dist/agent-runtime/run-execution.d.ts.map +1 -1
  41. package/dist/agent-runtime/runtime.d.ts +11 -3
  42. package/dist/agent-runtime/runtime.d.ts.map +1 -1
  43. package/dist/agent-runtime/schemas.d.ts +49 -0
  44. package/dist/agent-runtime/schemas.d.ts.map +1 -1
  45. package/dist/agent-runtime/sqlite.d.ts +2 -0
  46. package/dist/agent-runtime/sqlite.d.ts.map +1 -1
  47. package/dist/agent-runtime/store-driver.d.ts +61 -212
  48. package/dist/agent-runtime/store-driver.d.ts.map +1 -1
  49. package/dist/agent-runtime/store.d.ts +368 -1
  50. package/dist/agent-runtime/store.d.ts.map +1 -1
  51. package/dist/agent-runtime/terminal-commit.d.ts +12 -1
  52. package/dist/agent-runtime/terminal-commit.d.ts.map +1 -1
  53. package/dist/agent-runtime/terminal-status.d.ts +8 -0
  54. package/dist/agent-runtime/terminal-status.d.ts.map +1 -1
  55. package/dist/agent-runtime-browser.d.ts +1 -0
  56. package/dist/agent-runtime-browser.d.ts.map +1 -1
  57. package/dist/agent-runtime-browser.js +217 -1
  58. package/dist/agent-runtime-coding-tools.d.ts +2 -0
  59. package/dist/agent-runtime-coding-tools.d.ts.map +1 -0
  60. package/dist/agent-runtime-coding-tools.js +766 -0
  61. package/dist/agent-runtime-harness.d.ts +2 -0
  62. package/dist/agent-runtime-harness.d.ts.map +1 -0
  63. package/dist/agent-runtime-harness.js +704 -0
  64. package/dist/agent-runtime-openrouter.d.ts +14 -1
  65. package/dist/agent-runtime-openrouter.d.ts.map +1 -1
  66. package/dist/agent-runtime-openrouter.js +211 -0
  67. package/dist/agent-runtime-sqlite-bun.js +4 -3
  68. package/dist/agent-runtime-sqlite-node.js +4 -3
  69. package/dist/agent-runtime.d.ts +5 -3
  70. package/dist/agent-runtime.d.ts.map +1 -1
  71. package/dist/agent-runtime.js +108 -2580
  72. package/dist/application/diagnostic-journal-contract.d.ts +164 -0
  73. package/dist/application/diagnostic-journal-contract.d.ts.map +1 -0
  74. package/dist/application/diagnostic-journal-manager.d.ts +12 -0
  75. package/dist/application/diagnostic-journal-manager.d.ts.map +1 -0
  76. package/dist/application/diagnostic-journal-storage.d.ts +29 -0
  77. package/dist/application/diagnostic-journal-storage.d.ts.map +1 -0
  78. package/dist/application/diagnostic-journal.d.ts +11 -0
  79. package/dist/application/diagnostic-journal.d.ts.map +1 -0
  80. package/dist/application.d.ts +2 -0
  81. package/dist/application.d.ts.map +1 -1
  82. package/dist/application.js +561 -17
  83. package/dist/browser/socket-io.d.ts.map +1 -1
  84. package/dist/cli.js +9 -6
  85. package/dist/{index-t23p2b68.js → index-0yphgata.js} +1 -1
  86. package/dist/{index-8vpzxg55.js → index-10gbbbaa.js} +103 -2
  87. package/dist/{index-hcx9yypn.js → index-38hs3a58.js} +13 -11
  88. package/dist/index-3xnq72rz.js +21 -0
  89. package/dist/index-7rey2b8s.js +73 -0
  90. package/dist/{index-22tjt2rk.js → index-aczggrty.js} +1 -1
  91. package/dist/index-bd17ytae.js +192 -0
  92. package/dist/{index-xyvxez9r.js → index-da1aqnhb.js} +5 -5
  93. package/dist/index-es0h4w26.js +63 -0
  94. package/dist/{index-hqza5nde.js → index-hsabxjz0.js} +78 -77
  95. package/dist/{index-f24xg2cw.js → index-ktsps64f.js} +4 -2
  96. package/dist/{index-2t6zt5cg.js → index-mjx0wt4c.js} +11 -7
  97. package/dist/{index-y2ctppmg.js → index-qzbg46b6.js} +10 -74
  98. package/dist/{index-bt5179zb.js → index-s8nt8c22.js} +16 -11
  99. package/dist/index-tg3m2ec5.js +157 -0
  100. package/dist/{index-hxh98zbm.js → index-vbf2p6me.js} +1 -1
  101. package/dist/index-vc498pst.js +51 -0
  102. package/dist/{index-pgsyp3xh.js → index-vj3vvpaa.js} +1 -192
  103. package/dist/index-vy5bjy07.js +2569 -0
  104. package/dist/{index-hb0mncmj.js → index-wc80at9n.js} +2 -2
  105. package/dist/{index-eqqyd9v8.js → index-wwst0td5.js} +2 -46
  106. package/dist/{index-ysphyxax.js → index-x1th9s8c.js} +23 -2
  107. package/dist/index-xbtcszs7.js +202 -0
  108. package/dist/{index-grgvpbch.js → index-y3w12g8d.js} +4 -2
  109. package/dist/index.js +51 -37
  110. package/dist/internal/ai-sdk-typed.d.ts +14 -0
  111. package/dist/internal/ai-sdk-typed.d.ts.map +1 -0
  112. package/dist/node.js +6 -5
  113. package/dist/observability/index.js +5 -4
  114. package/dist/realtime/request.d.ts +5 -0
  115. package/dist/realtime/request.d.ts.map +1 -1
  116. package/dist/remote.js +7 -6
  117. package/dist/server/index.js +13 -11
  118. package/dist/testing.js +6 -5
  119. package/dist/tool-invoker.js +7 -5
  120. package/dist/tools/agent-tool-error.d.ts +14 -0
  121. package/dist/tools/agent-tool-error.d.ts.map +1 -0
  122. package/dist/tools/agent.d.ts.map +1 -1
  123. package/dist/tools.js +24 -17
  124. package/llms-full.txt +386 -29
  125. package/package.json +10 -2
@@ -1,3 +1,6 @@
1
+ import {
2
+ assistantStatus
3
+ } from "./index-es0h4w26.js";
1
4
  import {
2
5
  AgentMessageSchema,
3
6
  AgentRecordIdSchema,
@@ -7,21 +10,39 @@ import {
7
10
  AgentTerminalReasonSchema,
8
11
  AgentUsageSchema,
9
12
  runStateForTerminalReason
10
- } from "./index-ysphyxax.js";
13
+ } from "./index-x1th9s8c.js";
11
14
 
12
- // src/agent-runtime/store.ts
15
+ // src/agent-runtime/conversations.ts
13
16
  import { z } from "zod";
14
- var AgentStoreConflictSchema = z.object({
15
- outcome: z.literal("conflict"),
17
+ var AgentConversationSummarySchema = z.object({
18
+ conversationId: AgentRecordIdSchema,
19
+ version: AgentRecordVersionSchema,
20
+ updatedAt: z.iso.datetime({ offset: true }),
21
+ preview: z.string(),
22
+ activeRuns: z.int().nonnegative()
23
+ }).strict();
24
+ var AgentConversationPageSchema = z.object({
25
+ items: z.array(AgentConversationSummarySchema),
26
+ nextCursor: z.string().min(1).optional()
27
+ }).strict();
28
+ var AgentConversationMessagePageSchema = z.object({
29
+ items: z.array(AgentMessageSchema),
30
+ nextCursor: z.string().min(1).optional()
31
+ }).strict();
32
+
33
+ // src/agent-runtime/store.ts
34
+ import { z as z2 } from "zod";
35
+ var AgentStoreConflictSchema = z2.object({
36
+ outcome: z2.literal("conflict"),
16
37
  actualVersion: AgentRecordVersionSchema
17
38
  });
18
- var AgentStoreNotFoundSchema = z.object({ outcome: z.literal("not_found") });
19
- var AgentStoreAppliedSchema = z.object({
20
- outcome: z.literal("applied"),
39
+ var AgentStoreNotFoundSchema = z2.object({ outcome: z2.literal("not_found") });
40
+ var AgentStoreAppliedSchema = z2.object({
41
+ outcome: z2.literal("applied"),
21
42
  snapshot: AgentSnapshotSchema
22
43
  });
23
- var AgentStoreDuplicateSchema = z.object({
24
- outcome: z.literal("duplicate"),
44
+ var AgentStoreDuplicateSchema = z2.object({
45
+ outcome: z2.literal("duplicate"),
25
46
  input: AgentMessageSchema,
26
47
  inputMessageId: AgentRecordIdSchema,
27
48
  runId: AgentRecordIdSchema,
@@ -30,136 +51,116 @@ var AgentStoreDuplicateSchema = z.object({
30
51
  assistant: AgentMessageSchema.optional(),
31
52
  snapshot: AgentSnapshotSchema
32
53
  });
33
- var AgentStoreMutationResultSchema = z.discriminatedUnion("outcome", [
54
+ var AgentStoreMutationResultSchema = z2.discriminatedUnion("outcome", [
34
55
  AgentStoreAppliedSchema,
35
56
  AgentStoreDuplicateSchema,
36
57
  AgentStoreConflictSchema,
37
58
  AgentStoreNotFoundSchema
38
59
  ]);
39
- var AgentRunViewSchema = z.object({
60
+ var AgentRunViewSchema = z2.object({
40
61
  snapshotVersion: AgentRecordVersionSchema,
41
62
  run: AgentRunSchema,
42
63
  assistant: AgentMessageSchema.optional()
43
64
  });
44
- var AcceptInputAndAssignRunSchema = z.object({
45
- idempotencyKey: z.string().min(1),
65
+ var AcceptInputAndAssignRunSchema = z2.object({
66
+ idempotencyKey: z2.string().min(1),
46
67
  expectedVersion: AgentRecordVersionSchema.optional(),
47
68
  input: AgentMessageSchema,
48
69
  run: AgentRunSchema,
49
70
  coalesceIntoRunId: AgentRecordIdSchema.optional()
50
71
  });
51
- var AcquireAgentRunSchema = z.object({
72
+ var AcquireAgentRunSchema = z2.object({
52
73
  conversationId: AgentRecordIdSchema,
53
74
  runId: AgentRecordIdSchema,
54
75
  expectedRevision: AgentRecordVersionSchema,
55
- ownerId: z.string().min(1)
76
+ ownerId: z2.string().min(1)
56
77
  });
57
- var CheckpointRunAssistantSchema = z.object({
78
+ var CheckpointRunAssistantSchema = z2.object({
58
79
  conversationId: AgentRecordIdSchema,
59
80
  runId: AgentRecordIdSchema,
60
81
  expectedRevision: AgentRecordVersionSchema,
61
- ownerId: z.string().min(1),
82
+ ownerId: z2.string().min(1),
62
83
  fencingToken: AgentRecordVersionSchema.optional(),
63
84
  assistant: AgentMessageSchema,
64
85
  usage: AgentUsageSchema.optional()
65
86
  });
66
- var CommitRunTerminalSchema = z.object({
87
+ var CommitRunTerminalSchema = z2.object({
67
88
  conversationId: AgentRecordIdSchema,
68
89
  runId: AgentRecordIdSchema,
69
90
  expectedRevision: AgentRecordVersionSchema,
70
- ownerId: z.string().min(1),
91
+ ownerId: z2.string().min(1),
71
92
  fencingToken: AgentRecordVersionSchema.optional(),
72
93
  assistant: AgentMessageSchema,
73
94
  reason: AgentTerminalReasonSchema,
74
- policyName: z.string().min(1).optional(),
95
+ policyName: z2.string().min(1).optional(),
75
96
  usage: AgentUsageSchema.optional(),
76
- absorb: z.array(z.object({
97
+ absorb: z2.array(z2.object({
77
98
  runId: AgentRecordIdSchema,
78
- inputMessageIds: z.array(AgentRecordIdSchema).min(1)
99
+ inputMessageIds: z2.array(AgentRecordIdSchema).min(1)
79
100
  })).min(1).optional()
80
101
  });
81
- var RequestRunInterruptSchema = z.object({
102
+ var RequestRunInterruptSchema = z2.object({
82
103
  conversationId: AgentRecordIdSchema,
83
104
  runId: AgentRecordIdSchema,
84
105
  expectedRevision: AgentRecordVersionSchema
85
106
  });
86
- var RecoverAgentRunSchema = z.object({
107
+ var RecoverAgentRunSchema = z2.object({
87
108
  conversationId: AgentRecordIdSchema,
88
109
  runId: AgentRecordIdSchema,
89
110
  expectedRevision: AgentRecordVersionSchema,
90
- action: z.enum(["requeue", "abandon"]),
91
- replaySafe: z.boolean().optional()
111
+ action: z2.enum(["requeue", "abandon"]),
112
+ replaySafe: z2.boolean().optional()
92
113
  });
93
- var ReplaceCompactedRangeSchema = z.object({
114
+ var ReplaceCompactedRangeSchema = z2.object({
94
115
  conversationId: AgentRecordIdSchema,
95
116
  expectedVersion: AgentRecordVersionSchema,
96
- replacedMessageIds: z.array(AgentRecordIdSchema).min(1),
117
+ replacedMessageIds: z2.array(AgentRecordIdSchema).min(1),
97
118
  summary: AgentMessageSchema
98
119
  });
120
+ var AgentRecoverableDescriptorSchema = z2.object({
121
+ conversationId: AgentRecordIdSchema,
122
+ run: AgentRunSchema
123
+ });
124
+ var AgentRecoverablePageSchema = z2.object({
125
+ items: z2.array(AgentRecoverableDescriptorSchema),
126
+ nextCursor: z2.string().min(1).optional()
127
+ });
99
128
 
100
129
  // src/agent-runtime/store-driver.ts
101
- import { z as z2 } from "zod";
102
-
103
- // src/agent-runtime/terminal-status.ts
104
- function isSpeakableAssistantStatus(status) {
105
- return status === "completed" || status === "interrupted" || status === "committed";
106
- }
107
- function assistantStatus(reason) {
108
- if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
109
- return "completed";
110
- }
111
- if (reason === "superseded")
112
- return "superseded";
113
- if (reason === "absorbed")
114
- return "superseded";
115
- if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
116
- return "interrupted";
117
- }
118
- return "failed";
119
- }
120
-
121
- // src/agent-runtime/store-driver.ts
122
- var AgentRuntimeHeadSchema = z2.object({
123
- schemaVersion: z2.literal(1),
130
+ import { z as z3 } from "zod";
131
+ var AgentRuntimeHeadSchema = z3.object({
132
+ schemaVersion: z3.literal(1),
124
133
  conversationId: AgentRecordIdSchema,
125
134
  version: AgentRecordVersionSchema
126
135
  });
127
- var AgentStoredRunSchema = z2.object({
128
- schemaVersion: z2.literal(1),
136
+ var AgentStoredRunSchema = z3.object({
137
+ schemaVersion: z3.literal(1),
129
138
  run: AgentRunSchema,
130
139
  terminalAssistant: AgentMessageSchema.optional()
131
140
  });
132
- var AgentAdmissionReceiptSchema = z2.object({
133
- schemaVersion: z2.literal(1),
141
+ var AgentAdmissionReceiptSchema = z3.object({
142
+ schemaVersion: z3.literal(1),
134
143
  conversationId: AgentRecordIdSchema,
135
- idempotencyKey: z2.string().min(1),
144
+ idempotencyKey: z3.string().min(1),
136
145
  input: AgentMessageSchema,
137
146
  runId: AgentRecordIdSchema,
138
147
  assistantMessageId: AgentRecordIdSchema
139
148
  });
140
- var AgentHistoryMutationSchema = z2.discriminatedUnion("type", [
141
- z2.object({ type: z2.literal("admit"), input: AgentMessageSchema }),
142
- z2.object({
143
- type: z2.literal("upsert-assistant"),
149
+ var AgentHistoryMutationSchema = z3.discriminatedUnion("type", [
150
+ z3.object({ type: z3.literal("admit"), input: AgentMessageSchema }),
151
+ z3.object({
152
+ type: z3.literal("upsert-assistant"),
144
153
  message: AgentMessageSchema
145
154
  }),
146
- z2.object({
147
- type: z2.literal("replace-compacted-range"),
148
- replacedMessageIds: z2.array(AgentRecordIdSchema).min(1),
155
+ z3.object({
156
+ type: z3.literal("replace-compacted-range"),
157
+ replacedMessageIds: z3.array(AgentRecordIdSchema).min(1),
149
158
  summary: AgentMessageSchema
150
159
  })
151
160
  ]);
152
- var AgentRecoverableDescriptorSchema = z2.object({
153
- conversationId: AgentRecordIdSchema,
154
- run: AgentRunSchema
155
- });
156
- var AgentRecoverablePageSchema = z2.object({
157
- items: z2.array(AgentRecoverableDescriptorSchema),
158
- nextCursor: z2.string().min(1).optional()
159
- });
160
- var AgentRecoverableScanInputSchema = z2.object({
161
- cursor: z2.string().min(1).optional(),
162
- limit: z2.number().int().min(1).max(1000)
161
+ var AgentRecoverableScanInputSchema = z3.object({
162
+ cursor: z3.string().min(1).optional(),
163
+ limit: z3.number().int().min(1).max(1000)
163
164
  });
164
165
  function emptyHead(conversationId) {
165
166
  return AgentRuntimeHeadSchema.parse({
@@ -263,7 +264,7 @@ function validateSnapshot(head, messages, records) {
263
264
  }
264
265
  }
265
266
  }
266
- var RecoverableCursorSchema = z2.tuple([AgentRecordIdSchema, AgentRecordIdSchema]);
267
+ var RecoverableCursorSchema = z3.tuple([AgentRecordIdSchema, AgentRecordIdSchema]);
267
268
  function recoverableCursor(input) {
268
269
  return JSON.stringify([input.conversationId, input.run.id]);
269
270
  }
@@ -313,7 +314,7 @@ function reduceStore(current, operation) {
313
314
  if (input.coalesceIntoRunId !== undefined && (!coalescedRun || coalescedRun.conversationId !== input.input.conversationId || coalescedRun.state !== "queued" || coalescedRun.ownerId !== undefined || coalescedRun.terminalReason !== undefined)) {
314
315
  return coalescedRun ? conflict(coalescedRun.revision) : { outcome: "not_found" };
315
316
  }
316
- if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
317
+ if (input.run.conversationId !== input.input.conversationId || input.run.inputMessageIds.length !== 1 || input.run.inputMessageIds[0] !== input.input.id || input.run.state !== "queued" || input.run.revision !== 0 || input.run.executionSequence !== undefined || input.run.ownerId !== undefined || input.run.terminalReason !== undefined || input.run.terminalPolicyName !== undefined || input.input.role !== "user" && input.input.role !== "tool" || input.input.status !== "committed" || input.input.runId !== undefined || current.messages.some((message) => message.id === input.input.id) || coalescedRun !== undefined && input.input.id === coalescedRun.assistantMessageId || !coalescedRun && (input.run.assistantMessageId === input.input.id || current.runs.some((candidate) => candidate.id === input.run.id) || current.runs.some((candidate) => candidate.assistantMessageId === input.run.assistantMessageId) || current.messages.some((message) => message.id === input.run.assistantMessageId))) {
317
318
  throw new TypeError("Input and queued run do not form one valid assignment");
318
319
  }
319
320
  const assignedRun = coalescedRun ? AgentRunSchema.parse({
@@ -911,4 +912,4 @@ function createMemoryAgentRuntimeStore() {
911
912
  return createAgentRuntimeStore(driver);
912
913
  }
913
914
 
914
- export { isSpeakableAssistantStatus, assistantStatus, AgentStoreConflictSchema, AgentStoreNotFoundSchema, AgentStoreAppliedSchema, AgentStoreDuplicateSchema, AgentStoreMutationResultSchema, AgentRunViewSchema, AcceptInputAndAssignRunSchema, AcquireAgentRunSchema, CheckpointRunAssistantSchema, CommitRunTerminalSchema, RequestRunInterruptSchema, RecoverAgentRunSchema, ReplaceCompactedRangeSchema, AgentRuntimeHeadSchema, AgentStoredRunSchema, AgentAdmissionReceiptSchema, AgentHistoryMutationSchema, AgentRecoverableDescriptorSchema, AgentRecoverablePageSchema, ACTIVE_AGENT_RUN_STATES, createAgentRuntimeStore, createMemoryAgentRuntimeStore };
915
+ export { AgentConversationSummarySchema, AgentConversationPageSchema, AgentConversationMessagePageSchema, AgentStoreConflictSchema, AgentStoreNotFoundSchema, AgentStoreAppliedSchema, AgentStoreDuplicateSchema, AgentStoreMutationResultSchema, AgentRunViewSchema, AcceptInputAndAssignRunSchema, AcquireAgentRunSchema, CheckpointRunAssistantSchema, CommitRunTerminalSchema, RequestRunInterruptSchema, RecoverAgentRunSchema, ReplaceCompactedRangeSchema, AgentRecoverableDescriptorSchema, AgentRecoverablePageSchema, AgentRuntimeHeadSchema, AgentStoredRunSchema, AgentAdmissionReceiptSchema, AgentHistoryMutationSchema, ACTIVE_AGENT_RUN_STATES, createAgentRuntimeStore, createMemoryAgentRuntimeStore };
@@ -1,7 +1,9 @@
1
1
  import {
2
- isUnsafeKey,
3
2
  resolveTraceContext
4
- } from "./index-pgsyp3xh.js";
3
+ } from "./index-bd17ytae.js";
4
+ import {
5
+ isUnsafeKey
6
+ } from "./index-vj3vvpaa.js";
5
7
  import {
6
8
  isRecord
7
9
  } from "./index-qyrqwr4c.js";
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  collectToolSurface
3
- } from "./index-eqqyd9v8.js";
3
+ } from "./index-vc498pst.js";
4
4
  import {
5
- coerceJsonArgs,
6
5
  createToolRunner,
7
- formatToolError,
6
+ formatToolError
7
+ } from "./index-7rey2b8s.js";
8
+ import {
9
+ coerceJsonArgs,
8
10
  toolResultFromError
9
- } from "./index-y2ctppmg.js";
11
+ } from "./index-qzbg46b6.js";
10
12
  import {
11
13
  isWithinDir
12
14
  } from "./index-sbdmyz75.js";
@@ -20,10 +22,12 @@ import {
20
22
  } from "./index-cby4ar3v.js";
21
23
  import {
22
24
  formatZodError,
23
- isUnsafeKey,
24
- safeJsonParse,
25
25
  validateDeclaredOutput
26
- } from "./index-pgsyp3xh.js";
26
+ } from "./index-bd17ytae.js";
27
+ import {
28
+ isUnsafeKey,
29
+ safeJsonParse
30
+ } from "./index-vj3vvpaa.js";
27
31
  import {
28
32
  isRecord
29
33
  } from "./index-qyrqwr4c.js";
@@ -1,29 +1,27 @@
1
1
  import {
2
2
  getRequestContext,
3
3
  runWithRequestContext
4
- } from "./index-f24xg2cw.js";
4
+ } from "./index-ktsps64f.js";
5
5
  import {
6
- assertToolExtensionCompatible,
7
- mergeSchemas,
8
- objectShapeKeys,
9
- projectToolSurface,
10
- rebuildObject
6
+ objectShapeKeys
11
7
  } from "./index-22by16v6.js";
12
8
  import {
13
9
  formatZodError,
14
- isUnsafeKey,
15
10
  normalizeError,
16
- safeJsonParse,
17
11
  validateDeclaredOutput
18
- } from "./index-pgsyp3xh.js";
12
+ } from "./index-bd17ytae.js";
19
13
  import {
20
- isRecord
21
- } from "./index-qyrqwr4c.js";
14
+ isUnsafeKey,
15
+ safeJsonParse
16
+ } from "./index-vj3vvpaa.js";
22
17
  import {
23
18
  AppError,
24
19
  STITCH_ERROR_STATUS,
25
20
  isStitchErrorCode
26
21
  } from "./index-0w9abg87.js";
22
+ import {
23
+ isRecord
24
+ } from "./index-qyrqwr4c.js";
27
25
 
28
26
  // src/tools/coerce.ts
29
27
  import { z } from "zod";
@@ -339,66 +337,4 @@ async function runToolMethod(method, toolName, rawArgs, context, hooks, lifecycl
339
337
  }
340
338
  }
341
339
 
342
- // src/tools/mount.ts
343
- import { z as z2 } from "zod";
344
- function applyExtend(base, extra) {
345
- if (base instanceof z2.ZodObject) {
346
- assertToolExtensionCompatible(base, extra);
347
- return rebuildObject(base, { ...extra, ...base.shape });
348
- }
349
- return z2.intersection(z2.object(extra), base);
350
- }
351
- function contractToolMountable(projected, extend) {
352
- const method = projected.source;
353
- const baseArgumentSchema = mergeSchemas(method.paramsSchema, method.inputSchema);
354
- const argumentSchema = projected.shouldExtend && extend ? applyExtend(baseArgumentSchema, extend.schema) : baseArgumentSchema;
355
- return {
356
- method,
357
- name: projected.name,
358
- argumentSchema,
359
- presentationSchema: projected.presentationSchema,
360
- shouldExtend: projected.shouldExtend
361
- };
362
- }
363
- function collectTools(service, transport, config = {}) {
364
- const { extend, flattenUnionInput = false, assertNames = true } = config;
365
- const tools = [];
366
- for (const projected of projectToolSurface({ services: [service] }, transport === "HTTP" ? "AGENT" : transport, {
367
- extend,
368
- flattenUnionInput,
369
- assertNames,
370
- assertUniqueNames: false
371
- })) {
372
- if (projected.kind !== "contract")
373
- continue;
374
- tools.push(contractToolMountable(projected, extend));
375
- }
376
- return tools;
377
- }
378
- function createToolRunner(config) {
379
- const extension = config.extend ? {
380
- schema: z2.object(config.extend.schema),
381
- resolve: config.extend.resolve
382
- } : undefined;
383
- return async function runOneToolCall(tool, rawArgs, context) {
384
- return executeToolMethod(tool.method, tool.name, rawArgs, { ...config.context, ...context, source: config.source }, config.hooks, config.lifecycle, config.coerceJsonArgs ?? true, config.onOutputStrip ? (paths) => config.onOutputStrip?.(tool.name, paths) : undefined, tool.shouldExtend ? extension : undefined);
385
- };
386
- }
387
- function formatToolError(result, toolName, errorHint) {
388
- const err = { error: result.code };
389
- if (result.details)
390
- err.details = result.details;
391
- const hints = [];
392
- if (result.hint)
393
- hints.push(result.hint);
394
- if (errorHint && toolName) {
395
- const global = errorHint(toolName, result.code);
396
- if (global)
397
- hints.push(global);
398
- }
399
- if (hints.length > 0)
400
- err._hint = hints.join(" ");
401
- return err;
402
- }
403
-
404
- export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod, contractToolMountable, collectTools, createToolRunner, formatToolError };
340
+ export { coerceJsonArgs, ToolExecutionControlError, isToolExecutionControlError, toolResultFromError, toolErrorFromResult, executeToolMethod };
@@ -1,12 +1,17 @@
1
+ import {
2
+ AgentToolError
3
+ } from "./index-3xnq72rz.js";
1
4
  import {
2
5
  collectToolSurface
3
- } from "./index-eqqyd9v8.js";
6
+ } from "./index-vc498pst.js";
4
7
  import {
5
8
  createToolRunner,
6
- formatToolError,
9
+ formatToolError
10
+ } from "./index-7rey2b8s.js";
11
+ import {
7
12
  isToolExecutionControlError,
8
13
  toolResultFromError
9
- } from "./index-y2ctppmg.js";
14
+ } from "./index-qzbg46b6.js";
10
15
  import {
11
16
  isRecord
12
17
  } from "./index-qyrqwr4c.js";
@@ -38,16 +43,16 @@ function mountAgent(services, config = {}) {
38
43
  });
39
44
  const execute = async (rawArgs, options) => {
40
45
  const args = isRecord(rawArgs) ? rawArgs : {};
41
- try {
42
- const result = await runTool(mountable, args, { signal: options.abortSignal });
43
- if (result.ok)
44
- return result.data;
45
- return formatToolError(result, mountable.name, config.errorHint);
46
- } catch (err) {
46
+ const result = await runTool(mountable, args, {
47
+ signal: options.abortSignal
48
+ }).catch((err) => {
47
49
  if (isToolExecutionControlError(err))
48
50
  throw err;
49
- return formatToolError(toolResultFromError(err), mountable.name, config.errorHint);
50
- }
51
+ throw new AgentToolError(formatToolError(toolResultFromError(err), mountable.name, config.errorHint), err);
52
+ });
53
+ if (result.ok)
54
+ return result.data;
55
+ throw new AgentToolError(formatToolError(result, mountable.name, config.errorHint));
51
56
  };
52
57
  const presenter = entry.kind === "runtime" ? entry.definition.present?.agent : undefined;
53
58
  if (entry.kind === "runtime" && presenter) {
@@ -0,0 +1,157 @@
1
+ // src/agent-runtime/models.ts
2
+ import { z } from "zod";
3
+ var AgentModelCapabilitySchema = z.enum(["tools", "vision", "reasoning", "files"]);
4
+ var AgentModelDescriptorSchema = z.object({
5
+ provider: z.string().min(1),
6
+ modelId: z.string().min(1),
7
+ contextWindow: z.int().positive(),
8
+ capabilities: z.array(AgentModelCapabilitySchema),
9
+ observedAt: z.iso.datetime({ offset: true }).optional(),
10
+ source: z.string().min(1).optional(),
11
+ availability: z.enum(["available", "unavailable"]).optional()
12
+ });
13
+ var AgentModelRegistrySnapshotSchema = z.object({
14
+ schemaVersion: z.literal(1),
15
+ source: z.string().min(1),
16
+ observedAt: z.iso.datetime({ offset: true }),
17
+ models: z.record(z.string().min(1), AgentModelDescriptorSchema)
18
+ });
19
+ var AgentModelPriceSchema = z.object({
20
+ currency: z.string().length(3),
21
+ inputPerToken: z.string().regex(/^\d+(?:\.\d+)?$/).optional(),
22
+ outputPerToken: z.string().regex(/^\d+(?:\.\d+)?$/).optional()
23
+ }).strict();
24
+ var AgentModelMetricSchema = z.object({
25
+ metric: z.string().min(1),
26
+ value: z.number(),
27
+ unit: z.enum(["index", "elo", "percent", "milliseconds"]),
28
+ source: z.string().min(1),
29
+ observedAt: z.iso.datetime({ offset: true })
30
+ }).strict();
31
+ var AgentModelPopularitySchema = z.object({
32
+ rank: z.int().positive(),
33
+ window: z.literal("week"),
34
+ source: z.string().min(1),
35
+ observedAt: z.iso.datetime({ offset: true })
36
+ }).strict();
37
+ var AgentModelCatalogEntrySchema = z.object({
38
+ id: z.string().min(1),
39
+ name: z.string().min(1),
40
+ descriptor: AgentModelDescriptorSchema,
41
+ description: z.string().optional(),
42
+ price: AgentModelPriceSchema.optional(),
43
+ popularity: AgentModelPopularitySchema.optional(),
44
+ metrics: z.array(AgentModelMetricSchema)
45
+ }).strict();
46
+ var AgentModelCatalogSchema = z.object({
47
+ schemaVersion: z.literal(1),
48
+ source: z.string().min(1),
49
+ observedAt: z.iso.datetime({ offset: true }),
50
+ completeness: z.enum(["complete", "partial"]),
51
+ models: z.array(AgentModelCatalogEntrySchema),
52
+ diagnostics: z.array(z.string())
53
+ }).strict();
54
+ var AgentModelSelectionSchema = z.object({
55
+ modelId: z.string().min(1),
56
+ selectedAt: z.iso.datetime({ offset: true })
57
+ }).strict();
58
+ var AgentModelSearchInputSchema = z.object({ query: z.string().max(256).default(""), limit: z.int().positive().max(200) }).strict();
59
+ var AgentModelSearchResultSchema = z.object({
60
+ models: z.array(AgentModelCatalogEntrySchema),
61
+ total: z.int().nonnegative(),
62
+ truncated: z.boolean()
63
+ }).strict();
64
+ function searchAgentModelCatalog(catalog, rawInput) {
65
+ const input = AgentModelSearchInputSchema.parse(rawInput);
66
+ const terms = input.query.toLocaleLowerCase().trim().split(/\s+/).filter(Boolean);
67
+ const matches = catalog.models.filter((model) => {
68
+ const searchable = `${model.id}
69
+ ${model.name}
70
+ ${model.description ?? ""}`.toLocaleLowerCase();
71
+ return terms.every((term) => searchable.includes(term));
72
+ });
73
+ return AgentModelSearchResultSchema.parse({
74
+ models: matches.slice(0, input.limit),
75
+ total: matches.length,
76
+ truncated: matches.length > input.limit
77
+ });
78
+ }
79
+ function createMemoryAgentModelSelectionStore() {
80
+ const selections = new Map;
81
+ return {
82
+ load: (conversationId) => selections.get(conversationId),
83
+ save(conversationId, rawSelection) {
84
+ selections.set(conversationId, AgentModelSelectionSchema.parse(rawSelection));
85
+ }
86
+ };
87
+ }
88
+ function defineModelRegistry(config) {
89
+ const descriptors = new Map;
90
+ for (const key in config.models) {
91
+ const declaration = config.models[key];
92
+ if (declaration)
93
+ descriptors.set(key, AgentModelDescriptorSchema.parse(declaration));
94
+ }
95
+ const descriptor = (key) => {
96
+ const found = descriptors.get(key);
97
+ if (!found)
98
+ throw new Error(`Unknown agent model: ${key}`);
99
+ return found;
100
+ };
101
+ const supports = (key, capabilities) => {
102
+ const available = new Set(descriptor(key).capabilities);
103
+ return capabilities.every((capability) => available.has(capability));
104
+ };
105
+ const preflight = (key, required = []) => {
106
+ const selected = descriptor(key);
107
+ if (selected.availability === "unavailable") {
108
+ throw new Error(`Agent model ${key} is unavailable`);
109
+ }
110
+ if (!supports(key, required)) {
111
+ throw new Error(`Agent model ${key} does not satisfy required capabilities`);
112
+ }
113
+ if (!config.providers[selected.provider]) {
114
+ throw new Error(`Unknown agent model provider: ${selected.provider}`);
115
+ }
116
+ return selected;
117
+ };
118
+ return {
119
+ keys: () => [...descriptors.keys()],
120
+ descriptor,
121
+ supports,
122
+ preflight,
123
+ resolve(key, required = []) {
124
+ const selected = preflight(key, required);
125
+ const provider = config.providers[selected.provider];
126
+ if (!provider)
127
+ throw new Error(`Unknown agent model provider: ${selected.provider}`);
128
+ return {
129
+ descriptor: selected,
130
+ model: provider.create(selected.modelId),
131
+ ...provider.normalizeUsage && { normalizeUsage: provider.normalizeUsage }
132
+ };
133
+ },
134
+ snapshot(input) {
135
+ return AgentModelRegistrySnapshotSchema.parse({
136
+ schemaVersion: 1,
137
+ source: input.source,
138
+ observedAt: input.observedAt,
139
+ models: Object.fromEntries(descriptors.entries())
140
+ });
141
+ }
142
+ };
143
+ }
144
+ function validateAgentModelSnapshot(input, policy) {
145
+ if (!Number.isSafeInteger(policy.maxAgeMs) || policy.maxAgeMs < 0) {
146
+ throw new TypeError("maxAgeMs must be a non-negative safe integer");
147
+ }
148
+ const snapshot = AgentModelRegistrySnapshotSchema.parse(input);
149
+ const now = policy.now?.() ?? new Date;
150
+ const age = now.getTime() - new Date(snapshot.observedAt).getTime();
151
+ if (age < 0 || age > policy.maxAgeMs) {
152
+ throw new Error(`Agent model snapshot from ${snapshot.source} is stale`);
153
+ }
154
+ return snapshot;
155
+ }
156
+
157
+ export { AgentModelCapabilitySchema, AgentModelDescriptorSchema, AgentModelRegistrySnapshotSchema, AgentModelPriceSchema, AgentModelMetricSchema, AgentModelPopularitySchema, AgentModelCatalogEntrySchema, AgentModelCatalogSchema, AgentModelSelectionSchema, AgentModelSearchInputSchema, AgentModelSearchResultSchema, searchAgentModelCatalog, createMemoryAgentModelSelectionStore, defineModelRegistry, validateAgentModelSnapshot };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isUnsafeKey,
3
3
  mergeMeta
4
- } from "./index-pgsyp3xh.js";
4
+ } from "./index-vj3vvpaa.js";
5
5
  import {
6
6
  callRuntimeHandler,
7
7
  isRecord,
@@ -0,0 +1,51 @@
1
+ import {
2
+ runtimeToolMountable
3
+ } from "./index-wwst0td5.js";
4
+ import {
5
+ contractToolMountable
6
+ } from "./index-7rey2b8s.js";
7
+ import {
8
+ projectToolSurface
9
+ } from "./index-22by16v6.js";
10
+
11
+ // src/tools/surface.ts
12
+ function collectToolSurface({
13
+ surface,
14
+ transport,
15
+ assertUniqueNames = true,
16
+ ...collectConfig
17
+ }) {
18
+ const entries = [];
19
+ const append = (entry) => {
20
+ entries.push(entry);
21
+ };
22
+ for (const projected of projectToolSurface(surface, transport, {
23
+ extend: collectConfig.extend,
24
+ flattenUnionInput: collectConfig.flattenUnionInput,
25
+ assertNames: collectConfig.assertNames,
26
+ assertUniqueNames
27
+ })) {
28
+ if (projected.kind === "contract") {
29
+ const mountable = contractToolMountable(projected, collectConfig.extend);
30
+ append({
31
+ kind: "contract",
32
+ service: projected.serviceName,
33
+ action: mountable.method.key,
34
+ mountable,
35
+ projection: projected
36
+ });
37
+ } else {
38
+ append({
39
+ kind: "runtime",
40
+ service: projected.serviceName,
41
+ action: projected.action,
42
+ mountable: runtimeToolMountable(projected.source, false),
43
+ definition: projected.source,
44
+ projection: projected
45
+ });
46
+ }
47
+ }
48
+ return entries;
49
+ }
50
+
51
+ export { collectToolSurface };