@finalai/agent-definition 0.1.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.

Potentially problematic release.


This version of @finalai/agent-definition might be problematic. Click here for more details.

Files changed (206) hide show
  1. package/README.md +16 -0
  2. package/THIRD_PARTY_NOTICES.md +303 -0
  3. package/dist/compiler-assets/chunk-2CZRHOLL.ts +10 -0
  4. package/dist/compiler-assets/chunk-32O3ODZE.ts +39 -0
  5. package/dist/compiler-assets/chunk-5BK6FVRE.ts +75 -0
  6. package/dist/compiler-assets/chunk-6WR3PGNF.ts +0 -0
  7. package/dist/compiler-assets/chunk-7QP2CKPI.ts +30 -0
  8. package/dist/compiler-assets/chunk-7VSSVZM4.ts +55 -0
  9. package/dist/compiler-assets/chunk-7WGYG73V.ts +42 -0
  10. package/dist/compiler-assets/chunk-BLB6JGLO.ts +481 -0
  11. package/dist/compiler-assets/chunk-CWWRTRWW.ts +76 -0
  12. package/dist/compiler-assets/chunk-EVQIK62B.ts +188 -0
  13. package/dist/compiler-assets/chunk-GNR7XBPN.ts +3364 -0
  14. package/dist/compiler-assets/chunk-GTUZOATD.ts +10 -0
  15. package/dist/compiler-assets/chunk-HFS4KLEL.ts +10 -0
  16. package/dist/compiler-assets/chunk-HGW4YHAY.ts +6865 -0
  17. package/dist/compiler-assets/chunk-HNPUTP35.ts +172 -0
  18. package/dist/compiler-assets/chunk-JIPNTA56.ts +59 -0
  19. package/dist/compiler-assets/chunk-JNJE72EH.ts +10 -0
  20. package/dist/compiler-assets/chunk-JPY4L2UJ.ts +349 -0
  21. package/dist/compiler-assets/chunk-JTGTLYDT.ts +0 -0
  22. package/dist/compiler-assets/chunk-LUSAAV4L.ts +33 -0
  23. package/dist/compiler-assets/chunk-MZMSKIKU.ts +472 -0
  24. package/dist/compiler-assets/chunk-NMYHO2QN.ts +25 -0
  25. package/dist/compiler-assets/chunk-NYTOYKKF.ts +28 -0
  26. package/dist/compiler-assets/chunk-OWC6SFFF.ts +295 -0
  27. package/dist/compiler-assets/chunk-QMKWAFVZ.ts +59 -0
  28. package/dist/compiler-assets/chunk-QMWTDPNT.ts +79 -0
  29. package/dist/compiler-assets/chunk-RWUIMTBI.ts +13 -0
  30. package/dist/compiler-assets/chunk-SKTNMUO7.ts +64 -0
  31. package/dist/compiler-assets/chunk-T6WG4L4M.ts +19 -0
  32. package/dist/compiler-assets/chunk-TATN3PYK.ts +81 -0
  33. package/dist/compiler-assets/chunk-VHXHUU7L.ts +16 -0
  34. package/dist/compiler-assets/chunk-WMXMVFHM.ts +121 -0
  35. package/dist/compiler-assets/chunk-XHKPWT3G.ts +55 -0
  36. package/dist/compiler-assets/chunk-ZDLVA6XF.ts +476 -0
  37. package/dist/compiler-assets/src/authoring/agent.ts +10 -0
  38. package/dist/compiler-assets/src/authoring/approval.ts +19 -0
  39. package/dist/compiler-assets/src/authoring/brand.ts +23 -0
  40. package/dist/compiler-assets/src/authoring/channels.ts +26 -0
  41. package/dist/compiler-assets/src/authoring/connections.ts +10 -0
  42. package/dist/compiler-assets/src/authoring/context.ts +7 -0
  43. package/dist/compiler-assets/src/authoring/credentials.ts +21 -0
  44. package/dist/compiler-assets/src/authoring/dynamic.ts +10 -0
  45. package/dist/compiler-assets/src/authoring/harness.ts +17 -0
  46. package/dist/compiler-assets/src/authoring/hooks.ts +28 -0
  47. package/dist/compiler-assets/src/authoring/index.ts +110 -0
  48. package/dist/compiler-assets/src/authoring/instructions.ts +14 -0
  49. package/dist/compiler-assets/src/authoring/sandbox.ts +25 -0
  50. package/dist/compiler-assets/src/authoring/schedules.ts +10 -0
  51. package/dist/compiler-assets/src/authoring/skills.ts +10 -0
  52. package/dist/compiler-assets/src/authoring/tools.ts +23 -0
  53. package/dist/compiler-assets/src/compatibility.ts +14810 -0
  54. package/dist/compiler-assets/src/compiler/evaluate-child.mjs +77 -0
  55. package/dist/compiler-assets/src/index.ts +195 -0
  56. package/dist/compiler-assets/src/manifest.ts +72 -0
  57. package/dist/compiler-assets/src/resolve.ts +19 -0
  58. package/dist/compiler-assets/src/runtime/bundle.ts +72 -0
  59. package/dist/compiler-assets/src/runtime/describe.ts +31 -0
  60. package/dist/compiler-assets/src/runtime/described.ts +142 -0
  61. package/dist/compiler-assets/src/runtime/isolate.ts +28 -0
  62. package/dist/compiler-assets/src/runtime/layout.ts +15 -0
  63. package/dist/compiler-assets/src/runtime/lower.ts +52 -0
  64. package/dist/compiler-assets/src/runtime/schema-validation.ts +21 -0
  65. package/dist/compiler-assets/src/runtime/values.ts +38 -0
  66. package/dist/modules/authoring/agent.d.mts +22 -0
  67. package/dist/modules/authoring/agent.mjs +6 -0
  68. package/dist/modules/authoring/agent.mjs.map +7 -0
  69. package/dist/modules/authoring/approval.d.mts +17 -0
  70. package/dist/modules/authoring/approval.mjs +42 -0
  71. package/dist/modules/authoring/approval.mjs.map +7 -0
  72. package/dist/modules/authoring/brand.d.mts +27 -0
  73. package/dist/modules/authoring/brand.mjs +51 -0
  74. package/dist/modules/authoring/brand.mjs.map +7 -0
  75. package/dist/modules/authoring/channels.d.mts +41 -0
  76. package/dist/modules/authoring/channels.mjs +65 -0
  77. package/dist/modules/authoring/channels.mjs.map +7 -0
  78. package/dist/modules/authoring/connections.d.mts +23 -0
  79. package/dist/modules/authoring/connections.mjs +6 -0
  80. package/dist/modules/authoring/connections.mjs.map +7 -0
  81. package/dist/modules/authoring/context.d.mts +83 -0
  82. package/dist/modules/authoring/context.mjs +12 -0
  83. package/dist/modules/authoring/context.mjs.map +7 -0
  84. package/dist/modules/authoring/credentials.d.mts +10 -0
  85. package/dist/modules/authoring/credentials.mjs +31 -0
  86. package/dist/modules/authoring/credentials.mjs.map +7 -0
  87. package/dist/modules/authoring/dynamic.d.mts +30 -0
  88. package/dist/modules/authoring/dynamic.mjs +15 -0
  89. package/dist/modules/authoring/dynamic.mjs.map +7 -0
  90. package/dist/modules/authoring/harness.d.mts +85 -0
  91. package/dist/modules/authoring/harness.mjs +55 -0
  92. package/dist/modules/authoring/harness.mjs.map +7 -0
  93. package/dist/modules/authoring/hooks.d.mts +120 -0
  94. package/dist/modules/authoring/hooks.mjs +72 -0
  95. package/dist/modules/authoring/hooks.mjs.map +7 -0
  96. package/dist/modules/authoring/index.d.mts +27 -0
  97. package/dist/modules/authoring/index.mjs +63 -0
  98. package/dist/modules/authoring/index.mjs.map +7 -0
  99. package/dist/modules/authoring/instructions.d.mts +13 -0
  100. package/dist/modules/authoring/instructions.mjs +15 -0
  101. package/dist/modules/authoring/instructions.mjs.map +7 -0
  102. package/dist/modules/authoring/sandbox.d.mts +21 -0
  103. package/dist/modules/authoring/sandbox.mjs +13 -0
  104. package/dist/modules/authoring/sandbox.mjs.map +7 -0
  105. package/dist/modules/authoring/schedules.d.mts +8 -0
  106. package/dist/modules/authoring/schedules.mjs +6 -0
  107. package/dist/modules/authoring/schedules.mjs.map +7 -0
  108. package/dist/modules/authoring/skills.d.mts +8 -0
  109. package/dist/modules/authoring/skills.mjs +6 -0
  110. package/dist/modules/authoring/skills.mjs.map +7 -0
  111. package/dist/modules/authoring/tools.d.mts +80 -0
  112. package/dist/modules/authoring/tools.mjs +70 -0
  113. package/dist/modules/authoring/tools.mjs.map +7 -0
  114. package/dist/modules/compatibility.d.mts +36 -0
  115. package/dist/modules/compatibility.mjs +536 -0
  116. package/dist/modules/compatibility.mjs.map +7 -0
  117. package/dist/modules/compiler/assemble.d.mts +30 -0
  118. package/dist/modules/compiler/assemble.mjs +923 -0
  119. package/dist/modules/compiler/assemble.mjs.map +7 -0
  120. package/dist/modules/compiler/bundle.d.mts +22 -0
  121. package/dist/modules/compiler/bundle.mjs +385 -0
  122. package/dist/modules/compiler/bundle.mjs.map +7 -0
  123. package/dist/modules/compiler/diagnostics.d.mts +40 -0
  124. package/dist/modules/compiler/diagnostics.mjs +38 -0
  125. package/dist/modules/compiler/diagnostics.mjs.map +7 -0
  126. package/dist/modules/compiler/discovery.d.mts +36 -0
  127. package/dist/modules/compiler/discovery.mjs +158 -0
  128. package/dist/modules/compiler/discovery.mjs.map +7 -0
  129. package/dist/modules/compiler/evaluate.d.mts +13 -0
  130. package/dist/modules/compiler/evaluate.mjs +194 -0
  131. package/dist/modules/compiler/evaluate.mjs.map +7 -0
  132. package/dist/modules/compiler/files.d.mts +19 -0
  133. package/dist/modules/compiler/files.mjs +90 -0
  134. package/dist/modules/compiler/files.mjs.map +7 -0
  135. package/dist/modules/compiler/frontmatter.d.mts +9 -0
  136. package/dist/modules/compiler/frontmatter.mjs +34 -0
  137. package/dist/modules/compiler/frontmatter.mjs.map +7 -0
  138. package/dist/modules/compiler/index.d.mts +49 -0
  139. package/dist/modules/compiler/index.mjs +244 -0
  140. package/dist/modules/compiler/index.mjs.map +7 -0
  141. package/dist/modules/compiler/load.d.mts +8 -0
  142. package/dist/modules/compiler/load.mjs +45 -0
  143. package/dist/modules/compiler/load.mjs.map +7 -0
  144. package/dist/modules/compiler/local-isolate.d.mts +20 -0
  145. package/dist/modules/compiler/local-isolate.mjs +93 -0
  146. package/dist/modules/compiler/local-isolate.mjs.map +7 -0
  147. package/dist/modules/compiler/packages.d.mts +66 -0
  148. package/dist/modules/compiler/packages.mjs +307 -0
  149. package/dist/modules/compiler/packages.mjs.map +7 -0
  150. package/dist/modules/index.d.mts +7 -0
  151. package/dist/modules/index.mjs +25 -0
  152. package/dist/modules/index.mjs.map +7 -0
  153. package/dist/modules/manifest.d.mts +2 -0
  154. package/dist/modules/manifest.mjs +67 -0
  155. package/dist/modules/manifest.mjs.map +7 -0
  156. package/dist/modules/resolve.d.mts +24 -0
  157. package/dist/modules/resolve.mjs +176 -0
  158. package/dist/modules/resolve.mjs.map +7 -0
  159. package/dist/modules/runtime/bundle.d.mts +12 -0
  160. package/dist/modules/runtime/bundle.mjs +48 -0
  161. package/dist/modules/runtime/bundle.mjs.map +7 -0
  162. package/dist/modules/runtime/describe.d.mts +19 -0
  163. package/dist/modules/runtime/describe.mjs +471 -0
  164. package/dist/modules/runtime/describe.mjs.map +7 -0
  165. package/dist/modules/runtime/described.d.mts +376 -0
  166. package/dist/modules/runtime/described.mjs +116 -0
  167. package/dist/modules/runtime/described.mjs.map +7 -0
  168. package/dist/modules/runtime/isolate.d.mts +70 -0
  169. package/dist/modules/runtime/isolate.mjs +454 -0
  170. package/dist/modules/runtime/isolate.mjs.map +7 -0
  171. package/dist/modules/runtime/layout.d.mts +21 -0
  172. package/dist/modules/runtime/layout.mjs +24 -0
  173. package/dist/modules/runtime/layout.mjs.map +7 -0
  174. package/dist/modules/runtime/lower.d.mts +73 -0
  175. package/dist/modules/runtime/lower.mjs +463 -0
  176. package/dist/modules/runtime/lower.mjs.map +7 -0
  177. package/dist/modules/runtime/schema-validation.d.mts +21 -0
  178. package/dist/modules/runtime/schema-validation.mjs +238 -0
  179. package/dist/modules/runtime/schema-validation.mjs.map +7 -0
  180. package/dist/modules/runtime/values.d.mts +20 -0
  181. package/dist/modules/runtime/values.mjs +48 -0
  182. package/dist/modules/runtime/values.mjs.map +7 -0
  183. package/fixtures/acme-fleet/agent/agent.ts +74 -0
  184. package/fixtures/acme-fleet/agent/instructions.md +1 -0
  185. package/fixtures/assistant/agent/agent.ts +16 -0
  186. package/fixtures/assistant/agent/instructions.md +1 -0
  187. package/fixtures/assistant/agent/tools/current_time.ts +9 -0
  188. package/fixtures/assistant-with-tools/agent/agent.ts +16 -0
  189. package/fixtures/assistant-with-tools/agent/instructions.md +1 -0
  190. package/fixtures/assistant-with-tools/agent/tools/current_time.ts +9 -0
  191. package/fixtures/final-connection/agent/agent.ts +15 -0
  192. package/fixtures/final-connection/agent/connections/final.ts +9 -0
  193. package/fixtures/release-scout/agent/agent.ts +22 -0
  194. package/fixtures/release-scout/agent/channels/github-signature.ts +27 -0
  195. package/fixtures/release-scout/agent/channels/github.ts +38 -0
  196. package/fixtures/release-scout/agent/connections/linear.ts +9 -0
  197. package/fixtures/release-scout/agent/hooks/audit.ts +24 -0
  198. package/fixtures/release-scout/agent/instructions/org-context.ts +26 -0
  199. package/fixtures/release-scout/agent/instructions.md +2 -0
  200. package/fixtures/release-scout/agent/sandbox.ts +20 -0
  201. package/fixtures/release-scout/agent/schedules/daily-digest.md +7 -0
  202. package/fixtures/release-scout/agent/skills/triage/SKILL.md +8 -0
  203. package/fixtures/release-scout/agent/skills/triage/checklist.md +3 -0
  204. package/fixtures/release-scout/agent/tools/lookup_release_notes.ts +24 -0
  205. package/fixtures/tsconfig.json +5 -0
  206. package/package.json +94 -0
@@ -0,0 +1,481 @@
1
+ import {
2
+ isDynamicSentinel,
3
+ isEnvironmentLike,
4
+ isOpenRequestLike,
5
+ lowerConnection,
6
+ lowerEnvironment,
7
+ lowerInstructions,
8
+ lowerSkill,
9
+ lowerTool,
10
+ toJson
11
+ } from "./chunk-ZDLVA6XF.ts";
12
+ import {
13
+ AUTHORED_SERVER_KEY
14
+ } from "./chunk-NMYHO2QN.ts";
15
+ import {
16
+ hookHandlersFor
17
+ } from "./chunk-QMWTDPNT.ts";
18
+ import {
19
+ unopenedRequestOf
20
+ } from "./chunk-CWWRTRWW.ts";
21
+ import {
22
+ registerToolName,
23
+ toolLabelSchema
24
+ } from "./chunk-TATN3PYK.ts";
25
+ import {
26
+ validateSchemaValue
27
+ } from "./chunk-GNR7XBPN.ts";
28
+ import {
29
+ lowerApproval
30
+ } from "./chunk-7VSSVZM4.ts";
31
+ import {
32
+ mcpServerBindingSchema,
33
+ providerRefSchema
34
+ } from "./chunk-OWC6SFFF.ts";
35
+ import {
36
+ ConversationKind,
37
+ ParticipantKind
38
+ } from "./chunk-5BK6FVRE.ts";
39
+ import {
40
+ jsonObjectSchema,
41
+ jsonValueSchema
42
+ } from "./chunk-7QP2CKPI.ts";
43
+ import {
44
+ TranscriptRole
45
+ } from "./chunk-RWUIMTBI.ts";
46
+ import {
47
+ DynamicEvent
48
+ } from "./chunk-SKTNMUO7.ts";
49
+ import {
50
+ authoredKindOf,
51
+ stamp
52
+ } from "./chunk-XHKPWT3G.ts";
53
+ import {
54
+ authoredRecordSchema,
55
+ callableSchema,
56
+ entriesOf,
57
+ fieldOf,
58
+ isAsyncIterable,
59
+ isCallable,
60
+ isObjectLike,
61
+ isPlainObject,
62
+ messageOf,
63
+ optionalValueSchema
64
+ } from "./chunk-JIPNTA56.ts";
65
+ import {
66
+ array,
67
+ boolean,
68
+ looseObject,
69
+ nativeEnum,
70
+ number,
71
+ object,
72
+ string
73
+ } from "./chunk-HGW4YHAY.ts";
74
+
75
+ // src/runtime/isolate.ts
76
+ var jsonOf = (value, path) => {
77
+ const issues = [];
78
+ const json = toJson(value, { path, issues });
79
+ const failure = issues.find((issue) => issue.severity === "error");
80
+ if (failure != null) throw new Error(failure.message);
81
+ return json;
82
+ };
83
+ var lastSegment = (exportName) => {
84
+ const base = exportName.split("#")[0] ?? exportName;
85
+ return base.split("/").at(-1) ?? base;
86
+ };
87
+ var lowerResolvedValue = (value, key) => {
88
+ if (value == null) return null;
89
+ const kind = authoredKindOf(value);
90
+ if (kind === "instructions" /* Instructions */)
91
+ return jsonOf(lowerInstructions(value, null), "instructions");
92
+ if (kind === "skill" /* Skill */) {
93
+ const lowered = lowerSkill({ key, value });
94
+ const failure = lowered.issues.find((issue) => issue.severity === "error");
95
+ if (failure != null) throw new Error(failure.message);
96
+ return jsonOf(lowered.skill, "skill");
97
+ }
98
+ if (isEnvironmentLike(value) || isOpenRequestLike(value)) {
99
+ const issues = [];
100
+ const environment = lowerEnvironment(value, "environment", issues);
101
+ return jsonOf(environment, "environment");
102
+ }
103
+ if (isPlainObject(value)) {
104
+ const entries = entriesOf(value);
105
+ if (entries.length > 0 && entries.every(([, item]) => authoredKindOf(item) === "skill" /* Skill */)) {
106
+ return entries.map(
107
+ ([entryKey, item]) => jsonOf(lowerSkill({ key: entryKey, value: item }).skill, "skill")
108
+ );
109
+ }
110
+ }
111
+ return jsonOf(value, "resolved value");
112
+ };
113
+ var throwOnErrors = (issues) => {
114
+ const failure = issues.find((issue) => issue.severity === "error");
115
+ if (failure != null) throw new Error(failure.message);
116
+ };
117
+ var combineMcpServers = (entries) => {
118
+ const handler = (event) => async (payload, ctx) => {
119
+ const previous = array(mcpServerBindingSchema).safeParse(ctx.previousValue).data ?? [];
120
+ const tools = [];
121
+ const approvals = {};
122
+ const connections = [];
123
+ const addTool = (name, exportName, value, resolver) => {
124
+ const lowered = lowerTool({ name, exportName, value });
125
+ throwOnErrors(lowered.issues);
126
+ registerToolName(value, name);
127
+ if (resolver != null) {
128
+ const snapshot = jsonObjectSchema.parse(
129
+ jsonOf(
130
+ {
131
+ resolver,
132
+ name,
133
+ event,
134
+ payload,
135
+ session: ctx.session,
136
+ messages: ctx.messages,
137
+ channel: ctx.channel
138
+ },
139
+ "dynamic tool boundary"
140
+ )
141
+ );
142
+ lowered.descriptor.dynamic = snapshot;
143
+ if (lowered.descriptor.inputApproval != null)
144
+ lowered.descriptor.inputApproval = {
145
+ ...lowered.descriptor.inputApproval,
146
+ dynamic: snapshot
147
+ };
148
+ }
149
+ tools.push(lowered.descriptor);
150
+ approvals[name] = lowered.approval;
151
+ };
152
+ const addConnection = (key, exportName, value, resolver) => {
153
+ const lowered = lowerConnection({ key, exportName, value });
154
+ throwOnErrors(lowered.issues);
155
+ if (resolver != null && lowered.binding.inputApprovals != null) {
156
+ const snapshot = jsonObjectSchema.parse(
157
+ jsonOf(
158
+ {
159
+ resolver,
160
+ name: key,
161
+ event,
162
+ payload,
163
+ session: ctx.session,
164
+ messages: ctx.messages,
165
+ channel: ctx.channel
166
+ },
167
+ "dynamic connection boundary"
168
+ )
169
+ );
170
+ lowered.binding.inputApprovals = Object.fromEntries(
171
+ Object.entries(lowered.binding.inputApprovals).map(([name, reference]) => [
172
+ name,
173
+ { ...reference, dynamic: snapshot }
174
+ ])
175
+ );
176
+ }
177
+ connections.push(
178
+ resolver == null ? lowered.binding : { ...lowered.binding, dynamicResolver: resolver }
179
+ );
180
+ };
181
+ for (const entry of entries) {
182
+ const add = entry.kind === "tool" ? addTool : (name, exportName, value) => addConnection(name, exportName, value);
183
+ if (!isDynamicSentinel(entry.value)) {
184
+ add(entry.key, entry.exportName, entry.value);
185
+ continue;
186
+ }
187
+ const resolve = fieldOf(fieldOf(entry.value, "events"), event);
188
+ if (!isCallable(resolve)) {
189
+ for (const server of previous) {
190
+ if (entry.kind === "connection" && server.kind === "http" /* Http */ && server.dynamicResolver === entry.exportName) {
191
+ connections.push(server);
192
+ } else if (entry.kind === "tool" && server.kind === "worker" /* Worker */) {
193
+ for (const tool of server.tools) {
194
+ if (tool.dynamic?.["resolver"] !== entry.exportName) continue;
195
+ tools.push(tool);
196
+ approvals[tool.name] = Object.hasOwn(server.approvals ?? {}, tool.name) ? server.approvals?.[tool.name] ?? "allow" /* Allow */ : "allow" /* Allow */;
197
+ }
198
+ }
199
+ }
200
+ continue;
201
+ }
202
+ const result = await resolve(payload, ctx);
203
+ if (result == null) continue;
204
+ const kind = authoredKindOf(result);
205
+ if (kind === "tool" /* Tool */ || kind === "connection" /* Connection */) {
206
+ if (entry.kind === "tool") addTool(entry.key, entry.exportName, result, entry.exportName);
207
+ else addConnection(entry.key, entry.exportName, result, entry.exportName);
208
+ } else if (isPlainObject(result)) {
209
+ for (const [name, item] of entriesOf(result)) {
210
+ if (entry.kind === "tool")
211
+ addTool(name, `${entry.exportName}#${name}`, item, entry.exportName);
212
+ else addConnection(name, `${entry.exportName}#${name}`, item, entry.exportName);
213
+ }
214
+ }
215
+ }
216
+ const servers = [];
217
+ if (tools.length > 0) {
218
+ servers.push({
219
+ key: AUTHORED_SERVER_KEY,
220
+ kind: "worker" /* Worker */,
221
+ tools,
222
+ approvals
223
+ });
224
+ }
225
+ return jsonOf([...servers, ...connections], "mcpServers");
226
+ };
227
+ return stamp(
228
+ {
229
+ kind: "final:dynamic",
230
+ events: {
231
+ ["session.started" /* SessionStarted */]: handler("session.started" /* SessionStarted */),
232
+ ["turn.started" /* TurnStarted */]: handler("turn.started" /* TurnStarted */)
233
+ }
234
+ },
235
+ "dynamic" /* Dynamic */
236
+ );
237
+ };
238
+ var matchRoute = (pattern, path) => {
239
+ const patternParts = pattern.split("/").filter((part) => part.length > 0);
240
+ const pathParts = path.split("/").filter((part) => part.length > 0);
241
+ if (patternParts.length !== pathParts.length) return false;
242
+ return patternParts.every((part, index) => part.startsWith(":") || part === pathParts[index]);
243
+ };
244
+ var toolModuleSchema = looseObject({
245
+ execute: callableSchema,
246
+ inputSchema: optionalValueSchema,
247
+ outputSchema: optionalValueSchema,
248
+ toModelOutput: callableSchema.optional(),
249
+ label: toolLabelSchema.nullish()
250
+ });
251
+ var sentinelSchema = looseObject({ events: authoredRecordSchema });
252
+ var channelModuleSchema = looseObject({
253
+ configure: callableSchema.optional(),
254
+ routes: array(looseObject({ method: string(), path: string(), handler: callableSchema }))
255
+ });
256
+ var dynamicToolBoundarySchema = object({
257
+ resolver: string(),
258
+ name: string(),
259
+ event: nativeEnum(DynamicEvent),
260
+ payload: object({
261
+ type: nativeEnum(DynamicEvent),
262
+ prompt: array(jsonValueSchema).nullable()
263
+ }),
264
+ session: object({
265
+ id: string(),
266
+ organizationId: string(),
267
+ definitionId: string(),
268
+ revisionId: string(),
269
+ conversation: object({
270
+ id: string(),
271
+ kind: nativeEnum(ConversationKind),
272
+ title: string().nullable(),
273
+ metadata: jsonObjectSchema,
274
+ participants: array(
275
+ object({
276
+ id: string(),
277
+ kind: nativeEnum(ParticipantKind),
278
+ displayName: string(),
279
+ userId: string().nullable()
280
+ })
281
+ )
282
+ }).nullable(),
283
+ author: object({
284
+ participantId: string().nullable(),
285
+ userId: string().nullable(),
286
+ displayName: string()
287
+ }).nullable(),
288
+ turn: object({ id: string() }).nullable(),
289
+ harness: providerRefSchema
290
+ }),
291
+ messages: array(
292
+ object({
293
+ role: nativeEnum(TranscriptRole),
294
+ content: array(jsonValueSchema),
295
+ toolCallId: string().nullable(),
296
+ seq: number()
297
+ })
298
+ ),
299
+ channel: object({ kind: string().nullable() })
300
+ });
301
+ var createIsolateRuntime = (modules) => {
302
+ const lookup = (name) => {
303
+ if (!(name in modules)) throw new Error(`bundle has no export ${name}`);
304
+ return modules[name];
305
+ };
306
+ const resolveAuthored = async (args) => {
307
+ if (args.dynamic == null) return lookup(args.exportName);
308
+ const boundary = dynamicToolBoundarySchema.parse(args.dynamic);
309
+ if (args.exportName !== boundary.resolver && args.exportName !== `${boundary.resolver}#${boundary.name}`)
310
+ throw new Error("dynamic export does not match its boundary");
311
+ const sentinel = lookup(boundary.resolver);
312
+ if (!isDynamicSentinel(sentinel)) throw new Error("dynamic resolver is not a defineDynamic");
313
+ const resolve = fieldOf(fieldOf(sentinel, "events"), boundary.event);
314
+ if (!isCallable(resolve)) throw new Error("dynamic resolver has no boundary handler");
315
+ const result = await resolve(boundary.payload, {
316
+ session: boundary.session,
317
+ messages: boundary.messages,
318
+ channel: boundary.channel,
319
+ secrets: args.secrets
320
+ });
321
+ const expected = args.kind === "tool" /* Tool */ ? "tool" /* Tool */ : "connection" /* Connection */;
322
+ return authoredKindOf(result) === expected ? result : fieldOf(result, boundary.name);
323
+ };
324
+ return {
325
+ evaluateApproval: async ({ reference, input, secrets }) => {
326
+ const value = await resolveAuthored({
327
+ exportName: reference.export,
328
+ dynamic: reference.dynamic,
329
+ kind: reference.kind,
330
+ secrets
331
+ });
332
+ let policy;
333
+ let validated = input;
334
+ if (reference.kind === "tool" /* Tool */) {
335
+ const tool = toolModuleSchema.parse(value);
336
+ validated = await validateSchemaValue({
337
+ schema: tool.inputSchema,
338
+ value: input,
339
+ what: "approval input"
340
+ });
341
+ policy = fieldOf(value, "approval");
342
+ } else {
343
+ if (authoredKindOf(value) !== "connection" /* Connection */)
344
+ throw new Error("approval export is not a connection");
345
+ policy = reference.policyKey == null ? fieldOf(value, "approval") : fieldOf(fieldOf(fieldOf(value, "tools"), "approval"), reference.policyKey);
346
+ }
347
+ const lowered = lowerApproval(policy);
348
+ const predicate = fieldOf(policy, "predicate");
349
+ if (lowered.error != null || !lowered.inputDependent || !isCallable(predicate))
350
+ throw new Error("approval reference has no valid input predicate");
351
+ return boolean().parse(await predicate(validated)) ? "ask" /* Ask */ : "allow" /* Allow */;
352
+ },
353
+ runTool: async (args) => {
354
+ const value = await resolveAuthored({
355
+ exportName: args.export,
356
+ dynamic: args.dynamic,
357
+ kind: "tool" /* Tool */,
358
+ secrets: args.ctx.secrets
359
+ });
360
+ if (args.dynamic != null)
361
+ registerToolName(value, dynamicToolBoundarySchema.parse(args.dynamic).name);
362
+ const parsed = toolModuleSchema.safeParse(value);
363
+ if (!parsed.success) throw new Error(`${args.export} is not a tool`);
364
+ const tool = parsed.data;
365
+ const input = await validateSchemaValue({
366
+ schema: tool.inputSchema,
367
+ value: args.input,
368
+ what: "tool input"
369
+ });
370
+ const label = isObjectLike(tool.label) ? tool.label : null;
371
+ const statusLabel = async (callback, values) => {
372
+ if (callback == null) return void 0;
373
+ try {
374
+ const text = string().safeParse(await callback(...values));
375
+ return text.success ? text.data : void 0;
376
+ } catch {
377
+ return void 0;
378
+ }
379
+ };
380
+ const started = await statusLabel(label?.start, [input]);
381
+ if (started != null) args.onProgress?.(null, started);
382
+ const result = await tool.execute(input, args.ctx);
383
+ let output = result;
384
+ if (isAsyncIterable(result)) {
385
+ for await (const item of result) {
386
+ output = item;
387
+ args.onProgress?.(
388
+ jsonOf(item, "tool progress"),
389
+ await statusLabel(label?.delta, [input, item])
390
+ );
391
+ }
392
+ }
393
+ const validated = await validateSchemaValue({
394
+ schema: tool.outputSchema,
395
+ value: output,
396
+ what: "tool output"
397
+ });
398
+ const modelOutput = tool.toModelOutput == null ? null : await tool.toModelOutput(validated);
399
+ const completed = await statusLabel(label?.complete, [input, validated]);
400
+ if (completed != null) args.onProgress?.(null, completed);
401
+ return {
402
+ output: jsonOf(validated ?? null, "tool output"),
403
+ modelOutput: modelOutput == null ? null : jsonOf(modelOutput, "tool model output")
404
+ };
405
+ },
406
+ resolveDynamic: async (args) => {
407
+ const sentinel = lookup(args.export);
408
+ const parsed = sentinelSchema.safeParse(sentinel);
409
+ if (!isDynamicSentinel(sentinel) || !parsed.success) {
410
+ throw new Error(`${args.export} is not a defineDynamic resolver`);
411
+ }
412
+ const resolve = parsed.data.events[args.event];
413
+ if (!isCallable(resolve)) return null;
414
+ let result;
415
+ try {
416
+ result = await resolve(args.payload, args.ctx);
417
+ } catch (cause) {
418
+ const request = unopenedRequestOf(cause);
419
+ if (request == null) throw cause;
420
+ result = request;
421
+ }
422
+ return lowerResolvedValue(result, args.key ?? lastSegment(args.export));
423
+ },
424
+ dispatchHook: async (args) => {
425
+ const handlers = hookHandlersFor(lookup(args.export), args.event);
426
+ const failures = [];
427
+ for (const invoke of handlers) {
428
+ try {
429
+ await invoke(args.event, args.ctx);
430
+ } catch (cause) {
431
+ failures.push({ message: messageOf(cause) });
432
+ }
433
+ }
434
+ return { handled: handlers.length, failures };
435
+ },
436
+ handleChannelSocket: async (args) => {
437
+ const original = channelModuleSchema.safeParse(lookup(args.export));
438
+ if (!original.success) return null;
439
+ const parsed = original.data.configure == null ? original : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));
440
+ if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);
441
+ const route = parsed.data.routes.find(
442
+ (candidate) => candidate.method === "WS" && matchRoute(candidate.path, args.path)
443
+ );
444
+ if (route == null) return null;
445
+ const response = await route.handler({
446
+ request: args.request,
447
+ secrets: args.secrets,
448
+ receive: args.receive,
449
+ socket: args.socket
450
+ });
451
+ if (response != null && !(response instanceof Response))
452
+ throw new Error(`${args.export} socket route returned an invalid response`);
453
+ return response;
454
+ },
455
+ handleChannelRoute: async (args) => {
456
+ const original = channelModuleSchema.safeParse(lookup(args.export));
457
+ if (!original.success) return null;
458
+ const parsed = original.data.configure == null ? original : channelModuleSchema.safeParse(await original.data.configure(args.configuration ?? {}));
459
+ if (!parsed.success) throw new Error(`${args.export} configured channel is invalid`);
460
+ const route = parsed.data.routes.find(
461
+ (candidate) => candidate.method === args.request.method && matchRoute(candidate.path, args.path)
462
+ );
463
+ if (route == null) return null;
464
+ const response = await route.handler({
465
+ request: args.request,
466
+ secrets: args.secrets,
467
+ receive: args.receive
468
+ });
469
+ if (!(response instanceof Response)) {
470
+ throw new Error(`${args.export} route ${args.path} did not return a Response`);
471
+ }
472
+ return response;
473
+ }
474
+ };
475
+ };
476
+
477
+ export {
478
+ lowerResolvedValue,
479
+ combineMcpServers,
480
+ createIsolateRuntime
481
+ };
@@ -0,0 +1,76 @@
1
+ import {
2
+ _function,
3
+ array,
4
+ custom,
5
+ looseObject,
6
+ number,
7
+ object,
8
+ string,
9
+ unknown
10
+ } from "./chunk-HGW4YHAY.ts";
11
+
12
+ // ../agent-provider/src/sandbox/open-scope.ts
13
+ var openRequestFieldsSchema = looseObject({
14
+ providerName: string(),
15
+ environmentOptions: unknown(),
16
+ openOptions: unknown()
17
+ });
18
+ var unopenedSchema = object({
19
+ unopenedRequest: openRequestFieldsSchema
20
+ });
21
+ var unopenedRequestOf = (cause) => {
22
+ const parsed = unopenedSchema.safeParse(cause);
23
+ return parsed.success ? parsed.data.unopenedRequest : null;
24
+ };
25
+ var scopeMethodsSchema = looseObject({ current: _function() });
26
+ var sandboxOpenScopeSchema = custom(
27
+ (value) => scopeMethodsSchema.safeParse(value).success
28
+ );
29
+ var awaitableOpenRequest = (request) => {
30
+ const then = (onFulfilled, onRejected) => {
31
+ const scope = sandboxOpenScopeSchema.safeParse(globalThis.__finalSandboxOpenScope).data;
32
+ const opener = scope?.current() ?? null;
33
+ const opened = opener == null ? Promise.reject(
34
+ Object.assign(
35
+ new Error(
36
+ `awaiting ${request.providerName}.open() opens a sandbox only inside a defineSandbox selector`
37
+ ),
38
+ { unopenedRequest: { ...request } }
39
+ )
40
+ ) : opener(request);
41
+ return opened.then(onFulfilled, onRejected);
42
+ };
43
+ const awaitable = Object.assign(request, { then });
44
+ Object.defineProperty(awaitable, "then", { enumerable: false });
45
+ return awaitable;
46
+ };
47
+ var sessionMethodsSchema = looseObject({
48
+ id: string(),
49
+ description: string(),
50
+ defaultWorkingDirectory: string(),
51
+ ports: array(number()),
52
+ readFile: _function(),
53
+ readBinaryFile: _function(),
54
+ readTextFile: _function(),
55
+ writeFile: _function(),
56
+ writeBinaryFile: _function(),
57
+ writeTextFile: _function(),
58
+ spawn: _function(),
59
+ run: _function(),
60
+ stat: _function(),
61
+ readDir: _function(),
62
+ resolvePath: _function(),
63
+ removePath: _function(),
64
+ getPortEndpoint: _function(),
65
+ getPortUrl: _function(),
66
+ stop: _function(),
67
+ destroy: _function()
68
+ });
69
+ var sandboxSessionSchema = custom(
70
+ (value) => sessionMethodsSchema.safeParse(value).success
71
+ );
72
+
73
+ export {
74
+ unopenedRequestOf,
75
+ awaitableOpenRequest
76
+ };