@desplega.ai/agent-swarm 1.119.6 → 1.121.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 (207) hide show
  1. package/README.md +2 -2
  2. package/dist/{actions-qe5zjcbr.js → actions-mwshtkf7.js} +6 -6
  3. package/dist/{anthropic-messages-qjxzsabf.js → anthropic-messages-4gn944cn.js} +29 -13
  4. package/dist/{app-31x7k3vj.js → app-skbty91x.js} +4 -4
  5. package/dist/{assistant-4crt9dve.js → assistant-tg7dhfj8.js} +13 -13
  6. package/dist/{azure-openai-responses-ntfd05zd.js → azure-openai-responses-79zc0wyy.js} +28 -13
  7. package/dist/{boot-reembed-8g69ttz4.js → boot-reembed-ntjmeyh2.js} +4 -4
  8. package/dist/{boot-reembed-q648j733.js → boot-reembed-q5x0xpcp.js} +5 -5
  9. package/dist/{boot-scrub-logs-sfmzd2hj.js → boot-scrub-logs-5gznsfbe.js} +4 -4
  10. package/dist/{claude-adapter-9n3nzt65.js → claude-adapter-vxvcym3r.js} +3 -3
  11. package/dist/{claude-managed-adapter-pv2nbqy4.js → claude-managed-adapter-g807894s.js} +2 -2
  12. package/dist/{cli-bpvgs2y6.js → cli-072t49hf.js} +2123 -1533
  13. package/dist/{cli-g6qz2kts.js → cli-0df2g86x.js} +336 -18
  14. package/dist/cli-1728qh70.js +791 -0
  15. package/dist/{cli-vg1jxfqz.js → cli-3b1ayz83.js} +5 -5
  16. package/dist/{cli-r93nz80j.js → cli-3fxqwfh3.js} +1 -1
  17. package/dist/{cli-w6rhc30s.js → cli-3jrdwnn9.js} +20 -5
  18. package/dist/{cli-pasyk3vc.js → cli-46etyprn.js} +10 -5
  19. package/dist/{cli-433c0f4b.js → cli-4pfweq4x.js} +8 -8
  20. package/dist/{cli-2r7s8jhp.js → cli-5c4327dx.js} +7 -1
  21. package/dist/{cli-4s84mw72.js → cli-5hpvd15x.js} +2 -2
  22. package/dist/{cli-branks1w.js → cli-6s3ytc5x.js} +1 -1
  23. package/dist/{cli-da3x3btq.js → cli-7pt9sc83.js} +2 -2
  24. package/dist/{cli-2gv8ygwr.js → cli-7pzae66m.js} +2 -2
  25. package/dist/{cli-qs7nb3zn.js → cli-8wrympd7.js} +27 -1
  26. package/dist/{cli-qw1ccvxm.js → cli-95rbe11h.js} +70 -51
  27. package/dist/{cli-6rvm3jkk.js → cli-agdrxyex.js} +1 -1
  28. package/dist/{cli-wr706gez.js → cli-av2s7my4.js} +167 -66
  29. package/dist/{cli-59jy217p.js → cli-avw9ev3x.js} +55 -21
  30. package/dist/{cli-fkxxh5d4.js → cli-b2mqkg1h.js} +2 -2
  31. package/dist/{cli-1arw00dp.js → cli-ccjwgarc.js} +12 -3
  32. package/dist/{cli-pscrc6tw.js → cli-ch7t5v7n.js} +5 -0
  33. package/dist/{cli-tghre7g6.js → cli-cw70hymf.js} +1 -0
  34. package/dist/{cli-n61x2aph.js → cli-dmzv0986.js} +816 -1335
  35. package/dist/{cli-d1reabed.js → cli-g9vva2qh.js} +2 -2
  36. package/dist/{cli-ner6af7m.js → cli-gdpx70nc.js} +24048 -23715
  37. package/dist/{cli-96feg24n.js → cli-ghq3v4c9.js} +2 -2
  38. package/dist/{cli-wxbnjgce.js → cli-ky8esb8t.js} +3 -3
  39. package/dist/{cli-gdqdkr3j.js → cli-nf7sadev.js} +2 -2
  40. package/dist/{cli-h6cf69x5.js → cli-p9w7kb3h.js} +1 -1
  41. package/dist/{cli-xeatwfbe.js → cli-ry656xem.js} +24 -17
  42. package/dist/{cli-q8dway4w.js → cli-s8bdcke2.js} +1 -1
  43. package/dist/cli-s8s499xy.js +81 -0
  44. package/dist/{cli-sbkwvn5e.js → cli-srjqn7fd.js} +1 -1
  45. package/dist/cli-tv7vekye.js +367 -0
  46. package/dist/{cli-gg5bd32n.js → cli-vg3zrw6h.js} +4 -4
  47. package/dist/{cli-vx0y68jv.js → cli-vp9r4ap4.js} +5 -4
  48. package/dist/{cli-mg280wsv.js → cli-we156bmz.js} +1 -1
  49. package/dist/{cli-86fdnerz.js → cli-wwsaj97q.js} +9 -4
  50. package/dist/{cli-e0y603nn.js → cli-x0e0yvnq.js} +101 -1
  51. package/dist/{cli-mw3xpgwb.js → cli-x4apc9t3.js} +4 -4
  52. package/dist/cli.js +26 -21
  53. package/dist/{codex-adapter-6j2b38tg.js → codex-adapter-mmy741zd.js} +8 -9
  54. package/dist/{codex-session-runner-vz215wgw.js → codex-session-runner-sazmx9zt.js} +8 -9
  55. package/dist/{commands-6xr20jbe.js → commands-cxxye5e4.js} +3 -3
  56. package/dist/{db-1mmvk1z4.js → db-ab1954b7.js} +5 -3
  57. package/dist/{google-generative-ai-n1d3xt4n.js → google-generative-ai-wwa2ked5.js} +14 -18
  58. package/dist/{google-vertex-mxst23gy.js → google-vertex-71xmdd7n.js} +14 -18
  59. package/dist/{handlers-xvrknk8w.js → handlers-fmfe2343.js} +13 -13
  60. package/dist/{hook-qm7he8wn.js → hook-ygnw3cvt.js} +7 -8
  61. package/dist/{http-hj08zq67.js → http-kactcc0z.js} +1128 -536
  62. package/dist/{index-688jph6a.js → index-6erq0wvk.js} +11 -11
  63. package/dist/{index-gze4fg2w.js → index-g86j2yt5.js} +9 -9
  64. package/dist/{index-etz7d8md.js → index-gmzs6a2q.js} +10 -10
  65. package/dist/{index-wj8dfpwh.js → index-hmp82wn0.js} +12 -12
  66. package/dist/{keepalive-94wn9yxw.js → keepalive-3cvt26dw.js} +18 -14
  67. package/dist/{lead-rvcqkp11.js → lead-ysf26cjr.js} +31 -32
  68. package/dist/{maintenance-qhfc4dnp.js → maintenance-9npwptbb.js} +5 -5
  69. package/dist/{mistral-conversations-ykcg66za.js → mistral-conversations-26ya4yah.js} +17 -13
  70. package/dist/{oauth-refresh-sweep-rj8wgvsw.js → oauth-refresh-sweep-0r2v76vw.js} +23 -17
  71. package/dist/{onboard-8bv8q1wc.js → onboard-ddb1674a.js} +2 -2
  72. package/dist/{openai-codex-responses-zy0907j9.js → openai-codex-responses-6rr2ye0s.js} +78 -38
  73. package/dist/{openai-completions-xk4p56n9.js → openai-completions-zfa9nkvt.js} +130 -33
  74. package/dist/{openai-responses-4gv3ca5d.js → openai-responses-9wmdks0g.js} +38 -14
  75. package/dist/{opencode-adapter-5bwzvbwj.js → opencode-adapter-h6rkxwrk.js} +2 -2
  76. package/dist/{openrouter-images-4fsrrzes.js → openrouter-images-dgq98729.js} +10 -3
  77. package/dist/{otel-impl-1kf6fr2m.js → otel-impl-b43bkq8e.js} +4 -4
  78. package/dist/{pi-messages-zb8v76wx.js → pi-messages-nzjbbz47.js} +4 -6
  79. package/dist/{pi-mono-adapter-9sg69kg3.js → pi-mono-adapter-ke789738.js} +2328 -1281
  80. package/dist/{pricing-refresh-e84tar2s.js → pricing-refresh-2rqf114z.js} +5 -5
  81. package/dist/{rbac-roles-atytq5ch.js → rbac-roles-5wkhc8xv.js} +5 -5
  82. package/dist/{rbac-roles-pg0zvnwn.js → rbac-roles-6vtafvzb.js} +4 -4
  83. package/dist/{seed-pricing-xd6nxq7k.js → seed-pricing-23wrb873.js} +4 -4
  84. package/dist/{setup-4z389yk0.js → setup-6rny4fk6.js} +2 -2
  85. package/dist/{worker-m61r0t7m.js → worker-yapewe14.js} +31 -32
  86. package/openapi.json +2671 -1811
  87. package/package.json +10 -5
  88. package/plugin/commands/swarm-chat.md +2 -0
  89. package/plugin/pi-skills/swarm-chat/SKILL.md +2 -0
  90. package/src/be/connection-bindings-blob-migration.ts +123 -0
  91. package/src/be/db-queries/mcp-oauth.ts +409 -247
  92. package/src/be/db-queries/oauth.ts +813 -131
  93. package/src/be/db.ts +97 -6
  94. package/src/be/migrations/117_unified_oauth.sql +624 -0
  95. package/src/be/migrations/119_agent_avatar.sql +7 -0
  96. package/src/be/migrations/120_task_title.sql +3 -0
  97. package/src/be/oauth-credential-bindings.ts +48 -14
  98. package/src/be/oauth-encryption-backfill.ts +84 -0
  99. package/src/be/oauth-refresh-sweep.ts +38 -23
  100. package/src/be/script-connections.ts +1130 -163
  101. package/src/be/script-credential-broker.ts +37 -27
  102. package/src/be/scripts/typecheck.ts +3 -2
  103. package/src/be/seed-capabilities.ts +62 -0
  104. package/src/be/seed-pricing.ts +1 -1
  105. package/src/be/seed-scripts/catalog/ops-catalog-audit.inline.ts +1 -1
  106. package/src/be/seed-scripts/catalog/ops-catalog-audit.ts +1 -1
  107. package/src/be/vendored-openapi.ts +98 -0
  108. package/src/commands/runner.ts +69 -6
  109. package/src/http/agents.ts +23 -5
  110. package/src/http/all-routes.ts +1 -0
  111. package/src/http/core.ts +8 -5
  112. package/src/http/index.ts +18 -5
  113. package/src/http/mcp-bridge.ts +5 -2
  114. package/src/http/mcp-oauth.ts +103 -101
  115. package/src/http/oauth-callback.ts +332 -0
  116. package/src/http/oauth-generic.ts +14 -54
  117. package/src/http/poll.ts +5 -1
  118. package/src/http/script-connections.ts +651 -170
  119. package/src/http/scripts.ts +4 -2
  120. package/src/http/sessions.ts +1 -1
  121. package/src/http/tasks.ts +35 -0
  122. package/src/http/trackers/jira.ts +22 -34
  123. package/src/http/trackers/linear.ts +21 -36
  124. package/src/http/x.ts +6 -2
  125. package/src/jira/app.ts +12 -6
  126. package/src/jira/oauth.ts +48 -48
  127. package/src/linear/app.ts +44 -2
  128. package/src/linear/oauth.ts +12 -37
  129. package/src/oauth/app-validation.ts +27 -9
  130. package/src/oauth/ensure-mcp-token.ts +1 -0
  131. package/src/oauth/ensure-token.ts +331 -108
  132. package/src/oauth/identity-capture.ts +103 -0
  133. package/src/oauth/keepalive.ts +14 -9
  134. package/src/oauth/presets.ts +242 -0
  135. package/src/oauth/wrapper.ts +197 -76
  136. package/src/prompts/base-prompt.ts +48 -4
  137. package/src/prompts/session-templates.ts +13 -1
  138. package/src/providers/claude-managed-models.ts +8 -0
  139. package/src/rbac/legacy-policy.ts +2 -1
  140. package/src/rbac/permissions.ts +7 -3
  141. package/src/scripts-runtime/credential-broker/broker.ts +51 -8
  142. package/src/scripts-runtime/credential-broker/fetch-patch.ts +30 -3
  143. package/src/scripts-runtime/credential-broker/index.ts +1 -1
  144. package/src/scripts-runtime/credential-broker/types.ts +55 -8
  145. package/src/scripts-runtime/egress-secrets.ts +6 -2
  146. package/src/scripts-runtime/eval-harness.ts +2 -2
  147. package/src/scripts-runtime/executors/types.ts +2 -1
  148. package/src/scripts-runtime/loader.ts +3 -0
  149. package/src/scripts-runtime/types/stdlib.d.ts +11 -0
  150. package/src/server.ts +230 -126
  151. package/src/tests/agent-avatar-resolution.test.ts +123 -0
  152. package/src/tests/agents-list-model-display.test.ts +10 -0
  153. package/src/tests/base-prompt.test.ts +72 -0
  154. package/src/tests/claude-managed-adapter.test.ts +6 -0
  155. package/src/tests/connection-embedded-auth.test.ts +709 -0
  156. package/src/tests/context-window.test.ts +1 -0
  157. package/src/tests/credential-broker.test.ts +123 -125
  158. package/src/tests/db-queries-oauth.test.ts +126 -1
  159. package/src/tests/ensure-token.test.ts +44 -2
  160. package/src/tests/list-endpoint-slimming.test.ts +45 -0
  161. package/src/tests/mcp-oauth-manual-client.test.ts +20 -1
  162. package/src/tests/mcp-oauth-queries.test.ts +154 -8
  163. package/src/tests/oauth-access-token-tool.test.ts +37 -1
  164. package/src/tests/oauth-callback-flow.test.ts +534 -0
  165. package/src/tests/oauth-credential-bindings.test.ts +50 -22
  166. package/src/tests/oauth-presets.test.ts +275 -0
  167. package/src/tests/oauth-refresh-failure.test.ts +263 -0
  168. package/src/tests/oauth-refresh-sweep.test.ts +83 -3
  169. package/src/tests/oauth-wrapper.test.ts +77 -55
  170. package/src/tests/prompt-template-session.test.ts +6 -5
  171. package/src/tests/rbac-charact-misc-tools.test.ts +60 -0
  172. package/src/tests/rbac-engine.test.ts +2 -1
  173. package/src/tests/script-connections-http.test.ts +356 -11
  174. package/src/tests/script-connections.test.ts +102 -0
  175. package/src/tests/sdk-allowlist.test.ts +4 -1
  176. package/src/tests/seed-capabilities.test.ts +92 -0
  177. package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
  178. package/src/tests/sessions.test.ts +46 -0
  179. package/src/tests/spec-base-url.test.ts +266 -0
  180. package/src/tests/status.test.ts +3 -4
  181. package/src/tests/swarm-config-reserved-keys.test.ts +4 -2
  182. package/src/tests/task-title-route.test.ts +106 -0
  183. package/src/tests/tool-annotations.test.ts +6 -3
  184. package/src/tests/tracker-fold.test.ts +412 -0
  185. package/src/tests/unified-oauth-migration.test.ts +455 -0
  186. package/src/tests/vendored-openapi.test.ts +263 -0
  187. package/src/tools/credential-bindings/tool.ts +232 -77
  188. package/src/tools/oauth-access-token.ts +55 -6
  189. package/src/tools/script-connections/tool.ts +73 -53
  190. package/src/tools/swarm-config/set-config.ts +24 -50
  191. package/src/tools/update-profile.ts +15 -5
  192. package/src/tracker/types.ts +12 -0
  193. package/src/types.ts +29 -0
  194. package/src/utils/context-window.ts +1 -0
  195. package/src/workflows/executors/swarm-script.ts +6 -2
  196. package/vendored-openapi/README.md +22 -0
  197. package/vendored-openapi/github.json +7759 -0
  198. package/vendored-openapi/gmail.json +393 -0
  199. package/vendored-openapi/jira.json +3396 -0
  200. package/vendored-openapi/linear.json +252 -0
  201. package/vendored-openapi/manifest.json +128 -0
  202. package/vendored-openapi/slack.json +2895 -0
  203. package/dist/cli-0pygq9r1.js +0 -429
  204. package/dist/cli-8hhms4hp.js +0 -393
  205. package/dist/cli-z9gzq07x.js +0 -27
  206. package/src/scripts-runtime/credential-broker/store.ts +0 -72
  207. package/dist/{otel-g299k41b.js → otel-63jr5v38.js} +1 -1
@@ -5,14 +5,18 @@ import {
5
5
  parseStreamingJson
6
6
  } from "./cli-zyxs93y9.js";
7
7
  import {
8
+ appendGrammarToolInputJsonDelta,
9
+ getGrammarToolInput,
10
+ resolveGrammarConstrainedSampling,
11
+ resolveJsonSchemaStrictSampling,
8
12
  transformMessages
9
- } from "./cli-e0y603nn.js";
13
+ } from "./cli-x0e0yvnq.js";
10
14
  import {
11
15
  sanitizeSurrogates
12
16
  } from "./cli-y2apkfe2.js";
13
17
  import {
14
18
  calculateCost
15
- } from "./cli-1arw00dp.js";
19
+ } from "./cli-ccjwgarc.js";
16
20
 
17
21
  // node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js
18
22
  function encodeTextSignatureV1(id, phase) {
@@ -37,6 +41,27 @@ function parseTextSignature(signature) {
37
41
  }
38
42
  return { id: signature };
39
43
  }
44
+ function convertToolResultOutput(model, content) {
45
+ const textResult = content.filter((c) => c.type === "text").map((c) => c.text).join(`
46
+ `);
47
+ const images = content.filter((c) => c.type === "image");
48
+ const hasText = textResult.length > 0;
49
+ if (images.length === 0 || !model.input.includes("image")) {
50
+ return sanitizeSurrogates(hasText ? textResult : images.length > 0 ? "(see attached image)" : "(no tool output)");
51
+ }
52
+ const output = [];
53
+ if (hasText) {
54
+ output.push({ type: "input_text", text: sanitizeSurrogates(textResult) });
55
+ }
56
+ for (const image of images) {
57
+ output.push({
58
+ type: "input_image",
59
+ detail: "auto",
60
+ image_url: `data:${image.mimeType};base64,${image.data}`
61
+ });
62
+ }
63
+ return output;
64
+ }
40
65
  function convertResponsesMessages(model, context, allowedToolCallProviders, options) {
41
66
  const messages = [];
42
67
  const loadedToolNames = new Set;
@@ -135,55 +160,49 @@ function convertResponsesMessages(model, context, allowedToolCallProviders, opti
135
160
  } else if (block.type === "toolCall") {
136
161
  const toolCall = block;
137
162
  const [callId, itemIdRaw] = toolCall.id.split("|");
163
+ const customInputProperty = options?.grammarToolInputProperties?.get(toolCall.name);
138
164
  let itemId = itemIdRaw;
139
- if (isDifferentModel && itemId?.startsWith("fc_")) {
165
+ if (isDifferentModel && itemId?.startsWith("fc_") || customInputProperty === undefined && !itemId?.startsWith("fc_")) {
140
166
  itemId = undefined;
141
167
  }
142
- output.push({
143
- type: "function_call",
144
- id: itemId,
145
- call_id: callId,
146
- name: toolCall.name,
147
- arguments: JSON.stringify(toolCall.arguments)
148
- });
168
+ if (customInputProperty !== undefined) {
169
+ output.push({
170
+ type: "custom_tool_call",
171
+ id: itemId,
172
+ call_id: callId,
173
+ name: toolCall.name,
174
+ input: sanitizeSurrogates(getGrammarToolInput(toolCall.name, toolCall.arguments, customInputProperty))
175
+ });
176
+ } else {
177
+ output.push({
178
+ type: "function_call",
179
+ id: itemId,
180
+ call_id: callId,
181
+ name: toolCall.name,
182
+ arguments: JSON.stringify(toolCall.arguments)
183
+ });
184
+ }
149
185
  }
150
186
  }
151
187
  if (output.length === 0)
152
188
  continue;
153
189
  messages.push(...output);
154
190
  } else if (msg.role === "toolResult") {
155
- const textResult = msg.content.filter((c) => c.type === "text").map((c) => c.text).join(`
156
- `);
157
- const hasImages = msg.content.some((c) => c.type === "image");
158
- const hasText = textResult.length > 0;
159
191
  const [callId] = msg.toolCallId.split("|");
160
- let output;
161
- if (hasImages && model.input.includes("image")) {
162
- const contentParts = [];
163
- if (hasText) {
164
- contentParts.push({
165
- type: "input_text",
166
- text: sanitizeSurrogates(textResult)
167
- });
168
- }
169
- for (const block of msg.content) {
170
- if (block.type === "image") {
171
- contentParts.push({
172
- type: "input_image",
173
- detail: "auto",
174
- image_url: `data:${block.mimeType};base64,${block.data}`
175
- });
176
- }
177
- }
178
- output = contentParts;
192
+ const output = convertToolResultOutput(model, msg.content);
193
+ if (options?.grammarToolInputProperties?.has(msg.toolName)) {
194
+ messages.push({
195
+ type: "custom_tool_call_output",
196
+ call_id: callId,
197
+ output
198
+ });
179
199
  } else {
180
- output = sanitizeSurrogates(hasText ? textResult : hasImages ? "(see attached image)" : "(no tool output)");
200
+ messages.push({
201
+ type: "function_call_output",
202
+ call_id: callId,
203
+ output
204
+ });
181
205
  }
182
- messages.push({
183
- type: "function_call_output",
184
- call_id: callId,
185
- output
186
- });
187
206
  const deferredTools = [];
188
207
  for (const name of msg.addedToolNames ?? []) {
189
208
  const tool = options?.deferredTools?.get(name);
@@ -207,7 +226,10 @@ function convertResponsesMessages(model, context, allowedToolCallProviders, opti
207
226
  call_id: searchCallId,
208
227
  execution: "client",
209
228
  status: "completed",
210
- tools: convertResponsesTools(deferredTools, { deferLoading: true })
229
+ tools: convertResponsesTools(deferredTools, {
230
+ ...options?.toolOptions,
231
+ deferLoading: true
232
+ })
211
233
  });
212
234
  }
213
235
  }
@@ -216,15 +238,52 @@ function convertResponsesMessages(model, context, allowedToolCallProviders, opti
216
238
  return messages;
217
239
  }
218
240
  function convertResponsesTools(tools, options) {
219
- const strict = options?.strict === undefined ? false : options.strict;
220
- return tools.map((tool) => ({
221
- type: "function",
222
- name: tool.name,
223
- description: tool.description,
224
- parameters: tool.parameters,
225
- strict,
226
- ...options?.deferLoading ? { defer_loading: true } : {}
227
- }));
241
+ const defaultStrict = options?.strict === undefined ? false : options.strict;
242
+ const supportsStrictMode = options?.supportsStrictMode ?? true;
243
+ const supportsOpenAIGrammarTools = options?.supportsOpenAIGrammarTools ?? false;
244
+ return tools.map((tool) => {
245
+ const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
246
+ if (grammar) {
247
+ return {
248
+ type: "custom",
249
+ name: tool.name,
250
+ description: tool.description,
251
+ format: {
252
+ type: "grammar",
253
+ syntax: grammar.format,
254
+ definition: grammar.definition
255
+ },
256
+ ...options?.deferLoading ? { defer_loading: true } : {}
257
+ };
258
+ }
259
+ const constrainedStrict = resolveJsonSchemaStrictSampling(tool, supportsStrictMode);
260
+ const functionTool = {
261
+ type: "function",
262
+ name: tool.name,
263
+ description: tool.description,
264
+ parameters: tool.parameters,
265
+ ...options?.deferLoading ? { defer_loading: true } : {}
266
+ };
267
+ if (supportsStrictMode) {
268
+ functionTool.strict = constrainedStrict ?? defaultStrict;
269
+ }
270
+ return functionTool;
271
+ });
272
+ }
273
+ function getCustomToolCallInput(block) {
274
+ const property = block.customInput?.property;
275
+ if (property === undefined)
276
+ return "";
277
+ const value = block.arguments[property];
278
+ return typeof value === "string" ? value : "";
279
+ }
280
+ function appendCustomToolCallInput(block, nextInput, close) {
281
+ const customInput = block.customInput;
282
+ if (!customInput)
283
+ return;
284
+ const delta = appendGrammarToolInputJsonDelta(customInput.jsonBuffer, customInput.property, nextInput, close);
285
+ block.arguments = { [customInput.property]: nextInput };
286
+ return delta;
228
287
  }
229
288
  async function processResponsesStream(openaiStream, output, stream, model, options) {
230
289
  let sawTerminalResponseEvent = false;
@@ -234,6 +293,16 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
234
293
  const slot = outputSlots.get(outputIndex);
235
294
  return slot?.type === type ? slot : undefined;
236
295
  };
296
+ const pushToolCallDelta = (slot, delta) => {
297
+ if (delta === undefined)
298
+ return;
299
+ stream.push({
300
+ type: "toolcall_delta",
301
+ contentIndex: slot.contentIndex,
302
+ delta,
303
+ partial: output
304
+ });
305
+ };
237
306
  const createSlot = (outputIndex, item) => {
238
307
  if (item.type === "reasoning") {
239
308
  const block = { type: "thinking", thinking: "" };
@@ -273,6 +342,29 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
273
342
  stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
274
343
  return slot;
275
344
  }
345
+ if (item.type === "custom_tool_call") {
346
+ const inputProperty = options?.grammarToolInputProperties?.get(item.name) ?? "input";
347
+ const input = item.input || "";
348
+ const block = {
349
+ type: "toolCall",
350
+ id: `${item.call_id}|${item.id}`,
351
+ name: item.name,
352
+ arguments: { [inputProperty]: input },
353
+ customInput: {
354
+ property: inputProperty,
355
+ jsonBuffer: { input: "", started: false, closed: false }
356
+ }
357
+ };
358
+ output.content.push(block);
359
+ const slot = {
360
+ type: "toolCall",
361
+ block,
362
+ contentIndex: output.content.length - 1
363
+ };
364
+ outputSlots.set(outputIndex, slot);
365
+ stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
366
+ return slot;
367
+ }
276
368
  return;
277
369
  };
278
370
  const getOrCreateSlot = (outputIndex, item) => {
@@ -390,34 +482,33 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
390
482
  });
391
483
  } else if (event.type === "response.function_call_arguments.delta") {
392
484
  const slot = getSlot(event.output_index, "toolCall");
393
- if (!slot)
485
+ if (!slot || slot.block.partialJson === undefined)
394
486
  continue;
395
487
  slot.block.partialJson += event.delta;
396
488
  slot.block.arguments = parseStreamingJson(slot.block.partialJson);
397
- stream.push({
398
- type: "toolcall_delta",
399
- contentIndex: slot.contentIndex,
400
- delta: event.delta,
401
- partial: output
402
- });
489
+ pushToolCallDelta(slot, event.delta);
403
490
  } else if (event.type === "response.function_call_arguments.done") {
404
491
  const slot = getSlot(event.output_index, "toolCall");
405
- if (!slot)
492
+ if (!slot || slot.block.partialJson === undefined)
406
493
  continue;
407
494
  const previousPartialJson = slot.block.partialJson;
408
495
  slot.block.partialJson = event.arguments;
409
496
  slot.block.arguments = parseStreamingJson(slot.block.partialJson);
410
497
  if (event.arguments.startsWith(previousPartialJson)) {
411
498
  const delta = event.arguments.slice(previousPartialJson.length);
412
- if (delta.length > 0) {
413
- stream.push({
414
- type: "toolcall_delta",
415
- contentIndex: slot.contentIndex,
416
- delta,
417
- partial: output
418
- });
419
- }
499
+ if (delta.length > 0)
500
+ pushToolCallDelta(slot, delta);
420
501
  }
502
+ } else if (event.type === "response.custom_tool_call_input.delta") {
503
+ const slot = getSlot(event.output_index, "toolCall");
504
+ if (!slot || !slot.block.customInput)
505
+ continue;
506
+ pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, getCustomToolCallInput(slot.block) + event.delta, false));
507
+ } else if (event.type === "response.custom_tool_call_input.done") {
508
+ const slot = getSlot(event.output_index, "toolCall");
509
+ if (!slot || !slot.block.customInput)
510
+ continue;
511
+ pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, event.input, true));
421
512
  } else if (event.type === "response.output_item.done") {
422
513
  const item = event.item;
423
514
  const slot = getOrCreateSlot(event.output_index, item);
@@ -448,7 +539,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
448
539
  partial: output
449
540
  });
450
541
  outputSlots.delete(event.output_index);
451
- } else if (item.type === "function_call" && slot?.type === "toolCall") {
542
+ } else if (item.type === "function_call" && slot?.type === "toolCall" && slot.block.partialJson !== undefined) {
452
543
  slot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || "{}");
453
544
  delete slot.block.partialJson;
454
545
  stream.push({
@@ -458,6 +549,16 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
458
549
  partial: output
459
550
  });
460
551
  outputSlots.delete(event.output_index);
552
+ } else if (item.type === "custom_tool_call" && slot?.type === "toolCall" && slot.block.customInput) {
553
+ pushToolCallDelta(slot, appendCustomToolCallInput(slot.block, item.input ?? getCustomToolCallInput(slot.block), true));
554
+ delete slot.block.customInput;
555
+ stream.push({
556
+ type: "toolcall_end",
557
+ contentIndex: slot.contentIndex,
558
+ toolCall: slot.block,
559
+ partial: output
560
+ });
561
+ outputSlots.delete(event.output_index);
461
562
  }
462
563
  } else if (event.type === "response.completed" || event.type === "response.incomplete") {
463
564
  finalizeResponse(event.response);
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  checkCodexCredentials
3
- } from "./cli-da3x3btq.js";
3
+ } from "./cli-7pt9sc83.js";
4
4
  import {
5
5
  checkClaudeManagedCredentials
6
- } from "./cli-2r7s8jhp.js";
6
+ } from "./cli-5c4327dx.js";
7
7
  import {
8
8
  checkDevinCredentials
9
9
  } from "./cli-tyfxrrdd.js";
10
10
  import {
11
11
  checkOpencodeCredentials
12
- } from "./cli-branks1w.js";
12
+ } from "./cli-6s3ytc5x.js";
13
13
  import {
14
14
  initOtel,
15
15
  injectTraceContext,
@@ -19,7 +19,7 @@ import {
19
19
  withSpan,
20
20
  withSpanContext,
21
21
  writeSkillsToFilesystem
22
- } from "./cli-ner6af7m.js";
22
+ } from "./cli-gdpx70nc.js";
23
23
  import {
24
24
  authJsonToCredentialSelection,
25
25
  credentialsToAuthJson,
@@ -27,7 +27,7 @@ import {
27
27
  } from "./cli-tk9vyqzh.js";
28
28
  import {
29
29
  checkClaudeCredentials
30
- } from "./cli-mw3xpgwb.js";
30
+ } from "./cli-x4apc9t3.js";
31
31
  import {
32
32
  MAX_RATE_LIMIT_RESET_MS,
33
33
  isCodexCreditsExhaustedMessage,
@@ -37,14 +37,14 @@ import {
37
37
  } from "./cli-psrqtw2m.js";
38
38
  import {
39
39
  getContextWindowSize
40
- } from "./cli-tghre7g6.js";
40
+ } from "./cli-cw70hymf.js";
41
41
  import {
42
42
  ensure,
43
43
  initialize
44
- } from "./cli-gg5bd32n.js";
44
+ } from "./cli-vg3zrw6h.js";
45
45
  import {
46
46
  validateJsonSchema
47
- } from "./cli-qw1ccvxm.js";
47
+ } from "./cli-95rbe11h.js";
48
48
  import {
49
49
  getApiKey
50
50
  } from "./cli-f14fvzag.js";
@@ -80,7 +80,7 @@ import {
80
80
  resolveTaskModelSelection,
81
81
  resolveTemplateAsync,
82
82
  telemetry
83
- } from "./cli-g6qz2kts.js";
83
+ } from "./cli-0df2g86x.js";
84
84
  import {
85
85
  init_credentials,
86
86
  resolveCredentialPools
@@ -137,17 +137,22 @@ var getBasePrompt = async (args) => {
137
137
  ${scriptsOnlyResult.text}`;
138
138
  }
139
139
  const slackPromptToolsEnabled = areSlackPromptToolsEnabled();
140
- if (hasMcp && slackPromptToolsEnabled && !scriptsOnlyMode) {
140
+ const serverHasCapability = (cap, whenUnknown) => args.serverCapabilities ? args.serverCapabilities.includes(cap) : whenUnknown;
141
+ if (hasMcp && slackPromptToolsEnabled && !scriptsOnlyMode && serverHasCapability("slack", true)) {
141
142
  const slackResult = await resolveTemplateAsync("system.agent.slack", {});
142
143
  prompt += slackResult.text;
143
144
  }
144
- if (role !== "lead" && args.slackContext && hasMcp && slackPromptToolsEnabled) {
145
+ if (role !== "lead" && args.slackContext && hasMcp && slackPromptToolsEnabled && (scriptsOnlyMode || serverHasCapability("slack", true))) {
145
146
  const slackResult = await resolveTemplateAsync(scriptsOnlyMode ? "system.agent.scripts_only_mode.slack" : "system.agent.worker.slack", {
146
147
  slackChannelId: args.slackContext.channelId,
147
148
  slackThreadTs: args.slackContext.threadTs ?? ""
148
149
  });
149
150
  prompt += slackResult.text;
150
151
  }
152
+ if (hasMcp && !scriptsOnlyMode && serverHasCapability("messaging", true)) {
153
+ const messagingResult = await resolveTemplateAsync("system.agent.messaging", {});
154
+ prompt += messagingResult.text;
155
+ }
151
156
  if (!hasLocalEnv) {
152
157
  prompt += `
153
158
 
@@ -311,7 +316,7 @@ Do NOT use \`--no-verify\` or any flag that bypasses git hooks.
311
316
  });
312
317
  conditionalSuffix += agentFsResult.text;
313
318
  }
314
- if (!args.capabilities || args.capabilities.includes("services")) {
319
+ if (args.serverCapabilities ? args.serverCapabilities.includes("services") : !args.capabilities || args.capabilities.includes("services")) {
315
320
  const servicesResult = await resolveTemplateAsync("system.agent.services", {
316
321
  agentId,
317
322
  swarmUrl
@@ -449,19 +454,19 @@ async function materializeCodexAuthJson(_slot, creds, deps = {}) {
449
454
  async function createProviderAdapter(provider) {
450
455
  switch (provider) {
451
456
  case "claude": {
452
- const { ClaudeAdapter } = await import("./claude-adapter-9n3nzt65.js");
457
+ const { ClaudeAdapter } = await import("./claude-adapter-vxvcym3r.js");
453
458
  return new ClaudeAdapter;
454
459
  }
455
460
  case "pi": {
456
- const { PiMonoAdapter } = await import("./pi-mono-adapter-9sg69kg3.js");
461
+ const { PiMonoAdapter } = await import("./pi-mono-adapter-ke789738.js");
457
462
  return new PiMonoAdapter;
458
463
  }
459
464
  case "codex": {
460
- const { CodexAdapter } = await import("./codex-adapter-6j2b38tg.js");
465
+ const { CodexAdapter } = await import("./codex-adapter-mmy741zd.js");
461
466
  return new CodexAdapter;
462
467
  }
463
468
  case "claude-managed": {
464
- const { ClaudeManagedAdapter } = await import("./claude-managed-adapter-pv2nbqy4.js");
469
+ const { ClaudeManagedAdapter } = await import("./claude-managed-adapter-g807894s.js");
465
470
  return new ClaudeManagedAdapter;
466
471
  }
467
472
  case "devin": {
@@ -469,7 +474,7 @@ async function createProviderAdapter(provider) {
469
474
  return new DevinAdapter;
470
475
  }
471
476
  case "opencode": {
472
- const { OpencodeAdapter } = await import("./opencode-adapter-5bwzvbwj.js");
477
+ const { OpencodeAdapter } = await import("./opencode-adapter-h6rkxwrk.js");
473
478
  return new OpencodeAdapter;
474
479
  }
475
480
  default:
@@ -1117,7 +1122,7 @@ async function checkProviderCredentials(provider, env, opts) {
1117
1122
  case "opencode":
1118
1123
  return checkOpencodeCredentials(env, opts);
1119
1124
  case "pi": {
1120
- const { checkPiMonoCredentials } = await import("./pi-mono-adapter-9sg69kg3.js");
1125
+ const { checkPiMonoCredentials } = await import("./pi-mono-adapter-ke789738.js");
1121
1126
  return checkPiMonoCredentials(env, opts);
1122
1127
  }
1123
1128
  default:
@@ -2815,6 +2820,14 @@ async function registerAgent(opts) {
2815
2820
  const error = await response.text();
2816
2821
  throw new Error(`Failed to register agent: ${response.status} ${error}`);
2817
2822
  }
2823
+ try {
2824
+ const body = await response.json();
2825
+ const caps = body.enabledCapabilities;
2826
+ if (Array.isArray(caps) && caps.every((c2) => typeof c2 === "string")) {
2827
+ return { serverCapabilities: caps };
2828
+ }
2829
+ } catch {}
2830
+ return {};
2818
2831
  }
2819
2832
  async function pollForTrigger(opts) {
2820
2833
  if (!isPollTracingEnabled()) {
@@ -4039,6 +4052,7 @@ async function runAgent(config, opts) {
4039
4052
  role
4040
4053
  });
4041
4054
  let capabilities = config.capabilities;
4055
+ let serverCapabilities;
4042
4056
  let agentSoulMd;
4043
4057
  let agentIdentityMd;
4044
4058
  let agentSetupScript;
@@ -4058,6 +4072,7 @@ async function runAgent(config, opts) {
4058
4072
  agentId,
4059
4073
  swarmUrl,
4060
4074
  capabilities,
4075
+ serverCapabilities,
4061
4076
  traits,
4062
4077
  provider: adapter.name,
4063
4078
  scriptsOnly: resolvedScriptsOnly,
@@ -4156,6 +4171,8 @@ ${additionalSystemPrompt}` : basePrompt;
4156
4171
  let cachedCredHarnessProvider = null;
4157
4172
  let lastHarnessReconcileAt = 0;
4158
4173
  const HARNESS_RECONCILE_INTERVAL_MS = 1e4;
4174
+ let lastServerCapsRefreshAt = 0;
4175
+ const SERVER_CAPS_REFRESH_INTERVAL_MS = 300000;
4159
4176
  let lastBedrockRefreshAt = 0;
4160
4177
  const BEDROCK_REFRESH_INTERVAL_MS = 5 * 60 * 1000;
4161
4178
  const apiConfig = { apiUrl, apiKey, agentId };
@@ -4208,9 +4225,22 @@ ${additionalSystemPrompt}` : basePrompt;
4208
4225
  }
4209
4226
  return { agentVisibleChanged };
4210
4227
  };
4228
+ const applyServerCapabilities = async (next) => {
4229
+ if (!next)
4230
+ return;
4231
+ const changed = !serverCapabilities || next.length !== serverCapabilities.length || next.some((c2) => !serverCapabilities?.includes(c2));
4232
+ serverCapabilities = next;
4233
+ if (changed) {
4234
+ basePrompt = await buildSystemPrompt();
4235
+ resolvedSystemPrompt = additionalSystemPrompt ? `${basePrompt}
4236
+
4237
+ ${additionalSystemPrompt}` : basePrompt;
4238
+ console.log(`[${role}] [config] Server capabilities updated (${next.length} flags) — system prompt rebuilt`);
4239
+ }
4240
+ };
4211
4241
  const reregisterAgent = async () => {
4212
4242
  try {
4213
- await registerAgent({
4243
+ const reg = await registerAgent({
4214
4244
  apiUrl,
4215
4245
  apiKey,
4216
4246
  agentId,
@@ -4221,12 +4251,14 @@ ${additionalSystemPrompt}` : basePrompt;
4221
4251
  maxTasks: state.maxConcurrent,
4222
4252
  harnessProvider: state.harnessProvider
4223
4253
  });
4254
+ lastServerCapsRefreshAt = Date.now();
4255
+ await applyServerCapabilities(reg.serverCapabilities);
4224
4256
  } catch (err) {
4225
4257
  console.warn(`[${role}] [config] Re-register failed (non-fatal): ${err}`);
4226
4258
  }
4227
4259
  };
4228
4260
  try {
4229
- await registerAgent({
4261
+ const reg = await registerAgent({
4230
4262
  apiUrl,
4231
4263
  apiKey,
4232
4264
  agentId,
@@ -4237,6 +4269,8 @@ ${additionalSystemPrompt}` : basePrompt;
4237
4269
  maxTasks: maxConcurrent,
4238
4270
  harnessProvider: bootProvider
4239
4271
  });
4272
+ lastServerCapsRefreshAt = Date.now();
4273
+ await applyServerCapabilities(reg.serverCapabilities);
4240
4274
  console.log(`[${role}] Registered as "${agentName}" (ID: ${agentId})`);
4241
4275
  } catch (error) {
4242
4276
  console.error(`[${role}] Failed to register: ${error}`);
@@ -4666,7 +4700,7 @@ ${additionalSystemPrompt}` : basePrompt;
4666
4700
  configValue: scriptsOnlyConfigValue
4667
4701
  });
4668
4702
  const { agentVisibleChanged } = await applySwarmConfigDrift(freshEnv, resolvedProvider, nextScriptsOnly);
4669
- if (agentVisibleChanged) {
4703
+ if (agentVisibleChanged || Date.now() - lastServerCapsRefreshAt > SERVER_CAPS_REFRESH_INTERVAL_MS) {
4670
4704
  await reregisterAgent();
4671
4705
  }
4672
4706
  } catch (err) {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  buildModelsDevSeedRows
3
- } from "./cli-96feg24n.js";
3
+ } from "./cli-ghq3v4c9.js";
4
4
  import {
5
5
  createLogEntry,
6
6
  getActivePricingRow,
7
7
  getDb,
8
8
  init_db,
9
9
  insertPricingRow
10
- } from "./cli-g6qz2kts.js";
10
+ } from "./cli-0df2g86x.js";
11
11
  import {
12
12
  init_secret_scrubber,
13
13
  scrubSecrets
@@ -1,6 +1,7 @@
1
1
  import {
2
- AssistantMessageEventStream
3
- } from "./cli-qs7nb3zn.js";
2
+ AssistantMessageEventStream,
3
+ formatThrownValue
4
+ } from "./cli-8wrympd7.js";
4
5
 
5
6
  // node_modules/@earendil-works/pi-ai/dist/api/lazy.js
6
7
  function createSetupErrorMessage(model, error) {
@@ -124,11 +125,19 @@ class InMemoryCredentialStore {
124
125
  class ModelsError extends Error {
125
126
  code;
126
127
  constructor(code, message, options) {
127
- super(message, options);
128
+ super(withCauseDetail(message, options?.cause), options);
128
129
  this.name = "ModelsError";
129
130
  this.code = code;
130
131
  }
131
132
  }
133
+ function withCauseDetail(message, cause) {
134
+ if (cause === undefined || cause === null)
135
+ return message;
136
+ const detail = formatThrownValue(cause).trim();
137
+ if (!detail || message.includes(detail))
138
+ return message;
139
+ return `${message}: ${detail}`;
140
+ }
132
141
  async function resolveProviderAuth(provider, credentials, authContext, overrides) {
133
142
  const requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;
134
143
  if (overrides?.apiKey !== undefined && provider.auth.apiKey) {
@@ -43,10 +43,15 @@ function pickBodyText(error) {
43
43
  const responseBody = error.$response?.body;
44
44
  if (typeof responseBody === "string")
45
45
  return responseBody;
46
+ if (isReadableStreamLike(responseBody))
47
+ return;
46
48
  if (isNonEmptyObject(responseBody))
47
49
  return safeJsonStringify(responseBody);
48
50
  return;
49
51
  }
52
+ function isReadableStreamLike(value) {
53
+ return typeof value === "object" && value !== null && "pipe" in value && typeof value.pipe === "function";
54
+ }
50
55
  function isNonEmptyObject(value) {
51
56
  return typeof value === "object" && value !== null && Object.keys(value).length > 0;
52
57
  }
@@ -1,6 +1,7 @@
1
1
  // src/utils/context-window.ts
2
2
  var CONTEXT_FORMULA = "input-cache-output";
3
3
  var CONTEXT_WINDOW_DEFAULTS = {
4
+ "claude-opus-5": 1e6,
4
5
  "claude-fable-5": 1e6,
5
6
  "claude-mythos-5": 1e6,
6
7
  "claude-sonnet-5": 1e6,