@desplega.ai/agent-swarm 1.104.0 → 1.106.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 (142) hide show
  1. package/README.md +2 -0
  2. package/dist/{actions-2expzt47.js → actions-pk6xqa2y.js} +6 -6
  3. package/dist/{anthropic-messages-8q7p5vyq.js → anthropic-messages-8nc6r2dw.js} +10 -4
  4. package/dist/{app-dr8hwx7z.js → app-pmfvefkh.js} +3 -3
  5. package/dist/{assistant-9rhgsw7v.js → assistant-wcjpqxk6.js} +9 -9
  6. package/dist/{azure-openai-responses-0dmr2hzc.js → azure-openai-responses-6yfzw3qw.js} +10 -18
  7. package/dist/{boot-reembed-9kt97g1z.js → boot-reembed-atv4kcrh.js} +3 -3
  8. package/dist/{boot-reembed-3q1aywnz.js → boot-reembed-zanbm36c.js} +4 -4
  9. package/dist/{boot-scrub-logs-vskq108e.js → boot-scrub-logs-asq051ff.js} +2 -2
  10. package/dist/{claude-adapter-e3dhkq85.js → claude-adapter-w96mzan4.js} +2 -2
  11. package/dist/{claude-managed-adapter-z29hjgzz.js → claude-managed-adapter-vj9kzegz.js} +4 -4
  12. package/dist/{claude-managed-setup-ftbmvmvx.js → claude-managed-setup-t0wkvzgz.js} +1 -1
  13. package/dist/{cli-92fqyjcv.js → cli-07er7wrs.js} +1 -1
  14. package/dist/{cli-y9p3e94h.js → cli-08fnz4jm.js} +3 -3
  15. package/dist/{cli-yjt8a36k.js → cli-39jaysbv.js} +8 -6
  16. package/dist/{cli-5pf0b84v.js → cli-4fwzc50f.js} +2 -2
  17. package/dist/{cli-p03mawph.js → cli-50nss8e8.js} +928 -335
  18. package/dist/{cli-e7bwjntj.js → cli-6hqvenfv.js} +1 -1
  19. package/dist/{cli-0jw6j755.js → cli-6xn2xv4r.js} +24 -8
  20. package/dist/{cli-2g9jf9ek.js → cli-842gfjn1.js} +1 -1
  21. package/dist/{cli-v1syqkcb.js → cli-84gyjn6h.js} +146 -3
  22. package/dist/{cli-7b9ctyfq.js → cli-8da61htc.js} +1 -1
  23. package/dist/{cli-nzc0h54v.js → cli-8fhhmzbh.js} +1 -1
  24. package/dist/{cli-khe4x17a.js → cli-anrn8brw.js} +3 -3
  25. package/dist/{cli-2q1ct4en.js → cli-bsyka9ta.js} +104 -3
  26. package/dist/{cli-p04j6hjv.js → cli-dqhz8451.js} +1 -1
  27. package/dist/{cli-s42f54ja.js → cli-f7ypwjgh.js} +1 -1
  28. package/dist/{cli-p4cj4vhc.js → cli-hmqkes02.js} +1 -1
  29. package/dist/{cli-23zk7xqy.js → cli-j1172z85.js} +26 -18
  30. package/dist/{cli-yp2krx5r.js → cli-jk4tj5m6.js} +9 -3
  31. package/dist/{cli-q5tshxd6.js → cli-k7gt5r0p.js} +1 -1
  32. package/dist/{cli-54h5daha.js → cli-n38fcvhe.js} +6 -6
  33. package/dist/{cli-2hap19dv.js → cli-p7hff99g.js} +3 -3
  34. package/dist/cli-pscrc6tw.js +73 -0
  35. package/dist/{cli-yvektv79.js → cli-pxddwmyc.js} +1 -1
  36. package/dist/{cli-ncg70f07.js → cli-q44nxhwq.js} +1 -1
  37. package/dist/{cli-d4z1csms.js → cli-qtr61agf.js} +3 -3
  38. package/dist/{cli-zaxksbgj.js → cli-rp5kaak8.js} +5 -5
  39. package/dist/{cli-0fxvpa2q.js → cli-sdpnhajn.js} +150 -163
  40. package/dist/{cli-w1nfskkg.js → cli-sp3c9fwf.js} +2 -2
  41. package/dist/{cli-gj2n2ec1.js → cli-tfcrm7ds.js} +1 -1
  42. package/dist/{cli-0k9dc6ks.js → cli-tghre7g6.js} +1 -0
  43. package/dist/{cli-qvzgncd8.js → cli-v90vvqt8.js} +401 -125
  44. package/dist/{cli-zghef0em.js → cli-v9853xza.js} +1 -1
  45. package/dist/{cli-t9v14cnd.js → cli-wfhe4tgs.js} +1 -1
  46. package/dist/{cli-7v4y3hyd.js → cli-xgssgdqn.js} +2 -2
  47. package/dist/{cli-etvgz5x8.js → cli-xvs40j7w.js} +4 -4
  48. package/dist/{cli-jntqphs0.js → cli-ygcrdkqt.js} +15 -9
  49. package/dist/{cli-2957pqpj.js → cli-yv9dttkh.js} +32 -9
  50. package/dist/cli.js +20 -17
  51. package/dist/{codex-adapter-w0xharsg.js → codex-adapter-h9rj59tj.js} +5 -5
  52. package/dist/{codex-session-runner-kzbjcm2k.js → codex-session-runner-2ybavr0w.js} +5 -5
  53. package/dist/{commands-wfrkef57.js → commands-075ak6vf.js} +2 -2
  54. package/dist/{db-c42pxt7h.js → db-60fj8j7t.js} +2 -2
  55. package/dist/{google-generative-ai-mdn340ga.js → google-generative-ai-rf42vj2h.js} +9 -4
  56. package/dist/{google-vertex-mkdewpwe.js → google-vertex-m92pj5fb.js} +9 -4
  57. package/dist/{handlers-n36zkfvx.js → handlers-96j9z4gk.js} +9 -9
  58. package/dist/{hook-gw3vhv6s.js → hook-f58wyvmy.js} +3 -3
  59. package/dist/{http-59ygpn2h.js → http-naqhj1n0.js} +579 -52
  60. package/dist/{index-xf6fp4y1.js → index-45bqm6xc.js} +5 -5
  61. package/dist/{index-xz8vaa5c.js → index-f5e873a5.js} +10 -10
  62. package/dist/{index-jca7jdpt.js → index-jscerv2x.js} +10 -6
  63. package/dist/{index-881c1baf.js → index-v3r40ak0.js} +8 -8
  64. package/dist/{keepalive-mj4302vw.js → keepalive-8gbgeg21.js} +4 -4
  65. package/dist/{lead-qm0xjvkv.js → lead-hj6stakm.js} +26 -26
  66. package/dist/{maintenance-xppxbe4t.js → maintenance-1nvd0jva.js} +4 -4
  67. package/dist/{mistral-conversations-j380wd2q.js → mistral-conversations-26yrnbf1.js} +2 -2
  68. package/dist/{onboard-ejx6yxh8.js → onboard-8myqe0jh.js} +2 -2
  69. package/dist/{openai-codex-responses-v80z7kgx.js → openai-codex-responses-8h6kvfv8.js} +16 -25
  70. package/dist/{openai-completions-39vefwrq.js → openai-completions-x6kjnqjd.js} +11 -5
  71. package/dist/{openai-responses-dp5bkm3q.js → openai-responses-7jwyz3ds.js} +8 -16
  72. package/dist/{opencode-adapter-s8vsmzpy.js → opencode-adapter-p2w6efwc.js} +2 -2
  73. package/dist/{openrouter-images-54cva05t.js → openrouter-images-537nmn1r.js} +5 -1
  74. package/dist/{otel-impl-zs5exkpk.js → otel-impl-tddx9x81.js} +4510 -4465
  75. package/dist/{pi-mono-adapter-zf7dt1wg.js → pi-mono-adapter-y037wnp4.js} +596 -297
  76. package/dist/{pricing-refresh-nqyf8bkb.js → pricing-refresh-f6cgj5br.js} +4 -4
  77. package/dist/{seed-pricing-w3x550cj.js → seed-pricing-3tqmbe0p.js} +3 -3
  78. package/dist/{setup-7729ktfj.js → setup-tq3ept9k.js} +2 -2
  79. package/dist/{worker-4ttemwhw.js → worker-526psbtb.js} +26 -26
  80. package/openapi.json +315 -1
  81. package/package.json +8 -6
  82. package/src/be/db.ts +6 -2
  83. package/src/be/memory/access.ts +5 -0
  84. package/src/be/migrations/102_script_apis.sql +31 -0
  85. package/src/be/modelsdev-cache.json +22170 -7247
  86. package/src/be/scripts/db.ts +214 -1
  87. package/src/be/seed-pricing.ts +1 -1
  88. package/src/commands/claude-managed-setup.ts +1 -1
  89. package/src/hooks/tool-loop-detection.test.ts +81 -1
  90. package/src/hooks/tool-loop-detection.ts +53 -10
  91. package/src/http/index.ts +11 -1
  92. package/src/http/mcp.ts +49 -0
  93. package/src/http/memory.ts +21 -11
  94. package/src/http/pages-public.ts +123 -2
  95. package/src/http/scripts.ts +213 -0
  96. package/src/http/session-data.ts +16 -0
  97. package/src/http/x.ts +244 -0
  98. package/src/otel-impl.ts +73 -0
  99. package/src/otel.ts +12 -0
  100. package/src/prompts/session-templates.ts +5 -1
  101. package/src/providers/claude-managed-models.ts +9 -0
  102. package/src/server.ts +2 -0
  103. package/src/tests/agents-list-model-display.test.ts +5 -0
  104. package/src/tests/bedrock-model-groups.test.ts +3 -0
  105. package/src/tests/claude-managed-adapter.test.ts +14 -0
  106. package/src/tests/claude-managed-setup.test.ts +3 -3
  107. package/src/tests/context-window.test.ts +1 -0
  108. package/src/tests/harness-provider-resolution.test.ts +39 -0
  109. package/src/tests/http-api-integration.test.ts +1 -1
  110. package/src/tests/mcp-user-route.test.ts +70 -5
  111. package/src/tests/memory-get-tool.test.ts +132 -0
  112. package/src/tests/memory-http-recall-gating.test.ts +17 -1
  113. package/src/tests/migration-046-budgets.test.ts +32 -0
  114. package/src/tests/otel-impl-secret-scrubbing.test.ts +101 -3
  115. package/src/tests/otel-session-cost-metrics.test.ts +281 -0
  116. package/src/tests/pages-authed-mode.test.ts +50 -0
  117. package/src/tests/preload.ts +26 -0
  118. package/src/tests/register-service-security.test.ts +194 -0
  119. package/src/tests/script-apis-mcp.test.ts +308 -0
  120. package/src/tests/scripts-external-api.test.ts +449 -0
  121. package/src/tests/session-costs-model-key-normalize.test.ts +1 -0
  122. package/src/tests/update-profile-auth.test.ts +35 -1
  123. package/src/tools/memory-get.ts +17 -2
  124. package/src/tools/register-service.ts +68 -4
  125. package/src/tools/script-apis.ts +158 -0
  126. package/src/tools/script-common.ts +1 -1
  127. package/src/tools/tool-config.ts +2 -1
  128. package/src/tools/update-profile.ts +84 -1
  129. package/src/types.ts +27 -1
  130. package/src/utils/context-window.ts +1 -0
  131. package/src/utils/harness-provider.ts +35 -6
  132. package/src/utils/short-id.ts +44 -0
  133. package/templates/community/code-health-reports/run.sh +12 -6
  134. package/templates/community/dora-metrics/run.sh +10 -2
  135. package/templates/official/coder/start-up.sh +2 -2
  136. package/templates/official/content-reviewer/start-up.sh +2 -2
  137. package/templates/official/content-strategist/start-up.sh +2 -2
  138. package/templates/official/content-writer/start-up.sh +2 -2
  139. package/templates/official/discoverability-optimizer/start-up.sh +2 -2
  140. package/templates/official/ux-principles/start-up.sh +5 -5
  141. package/templates/skills/swarm-scripts/SKILL.md +4 -0
  142. package/templates/skills/swarm-scripts/content.md +4 -0
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  createSwarmEventHandler
3
- } from "./cli-92fqyjcv.js";
3
+ } from "./cli-07er7wrs.js";
4
4
  import {
5
5
  checkToolLoop
6
- } from "./cli-2957pqpj.js";
6
+ } from "./cli-yv9dttkh.js";
7
7
  import {
8
8
  readPkgVersion
9
9
  } from "./cli-d6n0thxw.js";
@@ -15,7 +15,7 @@ import {
15
15
  clampContextPercent,
16
16
  computeContextUsedUnified,
17
17
  getContextWindowSize
18
- } from "./cli-0k9dc6ks.js";
18
+ } from "./cli-tghre7g6.js";
19
19
  import {
20
20
  init_secret_scrubber,
21
21
  scrubSecrets
@@ -38,6 +38,12 @@ var CLAUDE_MANAGED_MODEL_PRICING = {
38
38
  cacheReadPerMillion: 1,
39
39
  cacheWritePerMillion: 12.5
40
40
  },
41
+ "claude-sonnet-5": {
42
+ inputPerMillion: 3,
43
+ outputPerMillion: 15,
44
+ cacheReadPerMillion: 0.3,
45
+ cacheWritePerMillion: 3.75
46
+ },
41
47
  "claude-sonnet-4-6": {
42
48
  inputPerMillion: 3,
43
49
  outputPerMillion: 15,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_package,
3
3
  package_default
4
- } from "./cli-yjt8a36k.js";
4
+ } from "./cli-39jaysbv.js";
5
5
 
6
6
  // src/commands/shared/client-config.ts
7
7
  init_package();
@@ -9,7 +9,7 @@ import {
9
9
  getScriptVersion,
10
10
  listRelationalCredentialBindings,
11
11
  validateScriptImports
12
- } from "./cli-v1syqkcb.js";
12
+ } from "./cli-84gyjn6h.js";
13
13
  import {
14
14
  checkpointStep,
15
15
  checkpointStepFailure,
@@ -19,14 +19,14 @@ import {
19
19
  interpolateNodeConfig,
20
20
  runStepValidation,
21
21
  walkGraph
22
- } from "./cli-zghef0em.js";
22
+ } from "./cli-v9853xza.js";
23
23
  import {
24
24
  getAppUrl
25
25
  } from "./cli-dh55d5fg.js";
26
26
  import {
27
27
  withSiblingAwareness,
28
28
  workflowContextKey
29
- } from "./cli-e7bwjntj.js";
29
+ } from "./cli-6hqvenfv.js";
30
30
  import {
31
31
  FollowUpConfigSchema,
32
32
  ModelTierSchema,
@@ -59,7 +59,7 @@ import {
59
59
  splitLegacyModelAlias,
60
60
  updateWorkflowRun,
61
61
  updateWorkflowRunStep
62
- } from "./cli-0jw6j755.js";
62
+ } from "./cli-6xn2xv4r.js";
63
63
  import {
64
64
  init_zod
65
65
  } from "./cli-q21d49ac.js";
@@ -1428,7 +1428,7 @@ class HumanInTheLoopExecutor extends BaseExecutor {
1428
1428
  }
1429
1429
  if (notification.channel === "slack") {
1430
1430
  try {
1431
- const { getSlackApp } = await import("./app-dr8hwx7z.js");
1431
+ const { getSlackApp } = await import("./app-pmfvefkh.js");
1432
1432
  const slackApp = getSlackApp();
1433
1433
  if (!slackApp) {
1434
1434
  console.warn("[HITL] Slack not initialized — cannot send notification");
@@ -1542,7 +1542,7 @@ class NotifyExecutor extends BaseExecutor {
1542
1542
  }
1543
1543
  }
1544
1544
  case "slack": {
1545
- const { getSlackApp } = await import("./app-dr8hwx7z.js");
1545
+ const { getSlackApp } = await import("./app-pmfvefkh.js");
1546
1546
  const app = getSlackApp();
1547
1547
  if (!app) {
1548
1548
  return {
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  recordUnmappedIdentity
3
- } from "./cli-gj2n2ec1.js";
3
+ } from "./cli-tfcrm7ds.js";
4
4
  import {
5
5
  findOrCreateUserByEmail,
6
6
  findUserByExternalId,
7
7
  linkIdentity
8
- } from "./cli-yvektv79.js";
8
+ } from "./cli-pxddwmyc.js";
9
9
  import {
10
10
  getKv,
11
11
  init_db,
12
12
  upsertKv
13
- } from "./cli-0jw6j755.js";
13
+ } from "./cli-6xn2xv4r.js";
14
14
 
15
15
  // src/slack/enrich.ts
16
16
  init_db();
@@ -0,0 +1,73 @@
1
+ // node_modules/@earendil-works/pi-ai/dist/utils/error-body.js
2
+ var MAX_PROVIDER_ERROR_BODY_CHARS = 4000;
3
+ function normalizeProviderError(error) {
4
+ if (!(error instanceof Error)) {
5
+ return { message: safeJsonStringify(error), messageCarriesBody: false };
6
+ }
7
+ const sdkError = error;
8
+ const status = extractStatus(sdkError);
9
+ const body = extractBody(sdkError);
10
+ const messageCarriesBody = body === undefined || error.message.includes(body);
11
+ return {
12
+ status,
13
+ body,
14
+ message: error.message,
15
+ messageCarriesBody
16
+ };
17
+ }
18
+ function extractStatus(error) {
19
+ if (typeof error.statusCode === "number")
20
+ return error.statusCode;
21
+ if (typeof error.status === "number")
22
+ return error.status;
23
+ if (typeof error.$metadata?.httpStatusCode === "number")
24
+ return error.$metadata.httpStatusCode;
25
+ if (typeof error.$response?.statusCode === "number")
26
+ return error.$response.statusCode;
27
+ return;
28
+ }
29
+ function extractBody(error) {
30
+ const bodyText = pickBodyText(error);
31
+ if (bodyText === undefined)
32
+ return;
33
+ const trimmed = bodyText.trim();
34
+ if (trimmed.length === 0)
35
+ return;
36
+ return truncateErrorText(trimmed, MAX_PROVIDER_ERROR_BODY_CHARS);
37
+ }
38
+ function pickBodyText(error) {
39
+ if (typeof error.body === "string")
40
+ return error.body;
41
+ if (isNonEmptyObject(error.error))
42
+ return safeJsonStringify(error.error);
43
+ const responseBody = error.$response?.body;
44
+ if (typeof responseBody === "string")
45
+ return responseBody;
46
+ if (isNonEmptyObject(responseBody))
47
+ return safeJsonStringify(responseBody);
48
+ return;
49
+ }
50
+ function isNonEmptyObject(value) {
51
+ return typeof value === "object" && value !== null && Object.keys(value).length > 0;
52
+ }
53
+ function formatProviderError(norm, prefix) {
54
+ if (norm.messageCarriesBody || norm.status === undefined || norm.body === undefined) {
55
+ return prefix !== undefined && norm.status !== undefined ? `${prefix} (${norm.status}): ${norm.message}` : norm.message;
56
+ }
57
+ return prefix !== undefined ? `${prefix} (${norm.status}): ${norm.body}` : `${norm.status}: ${norm.body}`;
58
+ }
59
+ function truncateErrorText(text, maxChars) {
60
+ if (text.length <= maxChars)
61
+ return text;
62
+ return `${text.slice(0, maxChars)}... [truncated ${text.length - maxChars} chars]`;
63
+ }
64
+ function safeJsonStringify(value) {
65
+ try {
66
+ const serialized = JSON.stringify(value);
67
+ return serialized === undefined ? String(value) : serialized;
68
+ } catch {
69
+ return String(value);
70
+ }
71
+ }
72
+
73
+ export { normalizeProviderError, formatProviderError };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getDb,
3
3
  init_db
4
- } from "./cli-0jw6j755.js";
4
+ } from "./cli-6xn2xv4r.js";
5
5
 
6
6
  // src/be/users.ts
7
7
  init_db();
@@ -17,7 +17,7 @@ import {
17
17
  CONTEXT_FORMULA,
18
18
  clampContextPercent,
19
19
  getContextWindowSize
20
- } from "./cli-0k9dc6ks.js";
20
+ } from "./cli-tghre7g6.js";
21
21
  import {
22
22
  init_credentials,
23
23
  validateOpencodeCredentials
@@ -4,11 +4,11 @@ import {
4
4
  getNextResumeGeneration,
5
5
  getResumeGeneration,
6
6
  repointTrackerSyncBySwarmId
7
- } from "./cli-s42f54ja.js";
7
+ } from "./cli-f7ypwjgh.js";
8
8
  import {
9
9
  getExecutorRegistry,
10
10
  recoverIncompleteRuns
11
- } from "./cli-54h5daha.js";
11
+ } from "./cli-n38fcvhe.js";
12
12
  import {
13
13
  assignUnassignedTaskPending,
14
14
  backfillSupersedeTaskResumeTaskId,
@@ -43,7 +43,7 @@ import {
43
43
  resolveTemplate,
44
44
  supersedeTask,
45
45
  updateAgentStatus
46
- } from "./cli-0jw6j755.js";
46
+ } from "./cli-6xn2xv4r.js";
47
47
 
48
48
  // src/heartbeat/heartbeat.ts
49
49
  init_db();
@@ -25,7 +25,7 @@ import {
25
25
  getTaskById,
26
26
  init_db,
27
27
  setSlackMessageTracking
28
- } from "./cli-0jw6j755.js";
28
+ } from "./cli-6xn2xv4r.js";
29
29
  import {
30
30
  require_receiver,
31
31
  require_sender,
@@ -54980,13 +54980,13 @@ async function initSlackApp() {
54980
54980
  socketMode: true,
54981
54981
  logLevel: import_bolt.LogLevel.DEBUG
54982
54982
  });
54983
- const { registerMessageHandler } = await import("./handlers-n36zkfvx.js");
54984
- const { registerCommandHandler } = await import("./commands-wfrkef57.js");
54985
- const { registerActionHandlers } = await import("./actions-2expzt47.js");
54983
+ const { registerMessageHandler } = await import("./handlers-96j9z4gk.js");
54984
+ const { registerCommandHandler } = await import("./commands-075ak6vf.js");
54985
+ const { registerActionHandlers } = await import("./actions-pk6xqa2y.js");
54986
54986
  registerMessageHandler(app);
54987
54987
  registerCommandHandler(app);
54988
54988
  registerActionHandlers(app);
54989
- const { createAssistant } = await import("./assistant-9rhgsw7v.js");
54989
+ const { createAssistant } = await import("./assistant-wcjpqxk6.js");
54990
54990
  app.assistant(createAssistant());
54991
54991
  return app;
54992
54992
  }
@@ -6,7 +6,7 @@ import {
6
6
  } from "./cli-zyxs93y9.js";
7
7
  import {
8
8
  transformMessages
9
- } from "./cli-2q1ct4en.js";
9
+ } from "./cli-bsyka9ta.js";
10
10
  import {
11
11
  sanitizeSurrogates
12
12
  } from "./cli-y2apkfe2.js";
@@ -199,11 +199,56 @@ function convertResponsesTools(tools, options) {
199
199
  }));
200
200
  }
201
201
  async function processResponsesStream(openaiStream, output, stream, model, options) {
202
- let currentItem = null;
203
- let currentBlock = null;
204
202
  let sawTerminalResponseEvent = false;
205
- const blocks = output.content;
206
- const blockIndex = () => blocks.length - 1;
203
+ const outputSlots = new Map;
204
+ const getSlot = (outputIndex, type) => {
205
+ const slot = outputSlots.get(outputIndex);
206
+ return slot?.type === type ? slot : undefined;
207
+ };
208
+ const createSlot = (outputIndex, item) => {
209
+ if (item.type === "reasoning") {
210
+ const block = { type: "thinking", thinking: "" };
211
+ output.content.push(block);
212
+ const slot = {
213
+ type: "thinking",
214
+ block,
215
+ contentIndex: output.content.length - 1
216
+ };
217
+ outputSlots.set(outputIndex, slot);
218
+ stream.push({ type: "thinking_start", contentIndex: slot.contentIndex, partial: output });
219
+ return slot;
220
+ }
221
+ if (item.type === "message") {
222
+ const block = { type: "text", text: "" };
223
+ output.content.push(block);
224
+ const slot = { type: "text", block, contentIndex: output.content.length - 1 };
225
+ outputSlots.set(outputIndex, slot);
226
+ stream.push({ type: "text_start", contentIndex: slot.contentIndex, partial: output });
227
+ return slot;
228
+ }
229
+ if (item.type === "function_call") {
230
+ const block = {
231
+ type: "toolCall",
232
+ id: `${item.call_id}|${item.id}`,
233
+ name: item.name,
234
+ arguments: {},
235
+ partialJson: item.arguments || ""
236
+ };
237
+ output.content.push(block);
238
+ const slot = {
239
+ type: "toolCall",
240
+ block,
241
+ contentIndex: output.content.length - 1
242
+ };
243
+ outputSlots.set(outputIndex, slot);
244
+ stream.push({ type: "toolcall_start", contentIndex: slot.contentIndex, partial: output });
245
+ return slot;
246
+ }
247
+ return;
248
+ };
249
+ const getOrCreateSlot = (outputIndex, item) => {
250
+ return outputSlots.get(outputIndex) ?? createSlot(outputIndex, item);
251
+ };
207
252
  const finalizeResponse = (response) => {
208
253
  sawTerminalResponseEvent = true;
209
254
  if (response?.id) {
@@ -216,6 +261,7 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
216
261
  output: response.usage.output_tokens || 0,
217
262
  cacheRead: cachedTokens,
218
263
  cacheWrite: 0,
264
+ reasoning: response.usage.output_tokens_details?.reasoning_tokens || 0,
219
265
  totalTokens: response.usage.total_tokens || 0,
220
266
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
221
267
  };
@@ -234,194 +280,135 @@ async function processResponsesStream(openaiStream, output, stream, model, optio
234
280
  if (event.type === "response.created") {
235
281
  output.responseId = event.response.id;
236
282
  } else if (event.type === "response.output_item.added") {
237
- const item = event.item;
238
- if (item.type === "reasoning") {
239
- currentItem = item;
240
- currentBlock = { type: "thinking", thinking: "" };
241
- output.content.push(currentBlock);
242
- stream.push({ type: "thinking_start", contentIndex: blockIndex(), partial: output });
243
- } else if (item.type === "message") {
244
- currentItem = item;
245
- currentBlock = { type: "text", text: "" };
246
- output.content.push(currentBlock);
247
- stream.push({ type: "text_start", contentIndex: blockIndex(), partial: output });
248
- } else if (item.type === "function_call") {
249
- currentItem = item;
250
- currentBlock = {
251
- type: "toolCall",
252
- id: `${item.call_id}|${item.id}`,
253
- name: item.name,
254
- arguments: {},
255
- partialJson: item.arguments || ""
256
- };
257
- output.content.push(currentBlock);
258
- stream.push({ type: "toolcall_start", contentIndex: blockIndex(), partial: output });
259
- }
260
- } else if (event.type === "response.reasoning_summary_part.added") {
261
- if (currentItem && currentItem.type === "reasoning") {
262
- currentItem.summary = currentItem.summary || [];
263
- currentItem.summary.push(event.part);
264
- }
283
+ createSlot(event.output_index, event.item);
265
284
  } else if (event.type === "response.reasoning_summary_text.delta") {
266
- if (currentItem?.type === "reasoning" && currentBlock?.type === "thinking") {
267
- currentItem.summary = currentItem.summary || [];
268
- const lastPart = currentItem.summary[currentItem.summary.length - 1];
269
- if (lastPart) {
270
- currentBlock.thinking += event.delta;
271
- lastPart.text += event.delta;
272
- stream.push({
273
- type: "thinking_delta",
274
- contentIndex: blockIndex(),
275
- delta: event.delta,
276
- partial: output
277
- });
278
- }
279
- }
285
+ const slot = getSlot(event.output_index, "thinking");
286
+ if (!slot)
287
+ continue;
288
+ slot.block.thinking += event.delta;
289
+ stream.push({
290
+ type: "thinking_delta",
291
+ contentIndex: slot.contentIndex,
292
+ delta: event.delta,
293
+ partial: output
294
+ });
280
295
  } else if (event.type === "response.reasoning_summary_part.done") {
281
- if (currentItem?.type === "reasoning" && currentBlock?.type === "thinking") {
282
- currentItem.summary = currentItem.summary || [];
283
- const lastPart = currentItem.summary[currentItem.summary.length - 1];
284
- if (lastPart) {
285
- currentBlock.thinking += `
296
+ const slot = getSlot(event.output_index, "thinking");
297
+ if (!slot)
298
+ continue;
299
+ slot.block.thinking += `
286
300
 
287
301
  `;
288
- lastPart.text += `
289
-
290
- `;
291
- stream.push({
292
- type: "thinking_delta",
293
- contentIndex: blockIndex(),
294
- delta: `
302
+ stream.push({
303
+ type: "thinking_delta",
304
+ contentIndex: slot.contentIndex,
305
+ delta: `
295
306
 
296
307
  `,
297
- partial: output
298
- });
299
- }
300
- }
308
+ partial: output
309
+ });
301
310
  } else if (event.type === "response.reasoning_text.delta") {
302
- if (currentItem?.type === "reasoning" && currentBlock?.type === "thinking") {
303
- currentBlock.thinking += event.delta;
304
- stream.push({
305
- type: "thinking_delta",
306
- contentIndex: blockIndex(),
307
- delta: event.delta,
308
- partial: output
309
- });
310
- }
311
- } else if (event.type === "response.content_part.added") {
312
- if (currentItem?.type === "message") {
313
- currentItem.content = currentItem.content || [];
314
- if (event.part.type === "output_text" || event.part.type === "refusal") {
315
- currentItem.content.push(event.part);
316
- }
317
- }
311
+ const slot = getSlot(event.output_index, "thinking");
312
+ if (!slot)
313
+ continue;
314
+ slot.block.thinking += event.delta;
315
+ stream.push({
316
+ type: "thinking_delta",
317
+ contentIndex: slot.contentIndex,
318
+ delta: event.delta,
319
+ partial: output
320
+ });
318
321
  } else if (event.type === "response.output_text.delta") {
319
- if (currentItem?.type === "message" && currentBlock?.type === "text") {
320
- if (!currentItem.content || currentItem.content.length === 0) {
321
- continue;
322
- }
323
- const lastPart = currentItem.content[currentItem.content.length - 1];
324
- if (lastPart?.type === "output_text") {
325
- currentBlock.text += event.delta;
326
- lastPart.text += event.delta;
327
- stream.push({
328
- type: "text_delta",
329
- contentIndex: blockIndex(),
330
- delta: event.delta,
331
- partial: output
332
- });
333
- }
334
- }
322
+ const slot = getSlot(event.output_index, "text");
323
+ if (!slot)
324
+ continue;
325
+ slot.block.text += event.delta;
326
+ stream.push({
327
+ type: "text_delta",
328
+ contentIndex: slot.contentIndex,
329
+ delta: event.delta,
330
+ partial: output
331
+ });
335
332
  } else if (event.type === "response.refusal.delta") {
336
- if (currentItem?.type === "message" && currentBlock?.type === "text") {
337
- if (!currentItem.content || currentItem.content.length === 0) {
338
- continue;
339
- }
340
- const lastPart = currentItem.content[currentItem.content.length - 1];
341
- if (lastPart?.type === "refusal") {
342
- currentBlock.text += event.delta;
343
- lastPart.refusal += event.delta;
333
+ const slot = getSlot(event.output_index, "text");
334
+ if (!slot)
335
+ continue;
336
+ slot.block.text += event.delta;
337
+ stream.push({
338
+ type: "text_delta",
339
+ contentIndex: slot.contentIndex,
340
+ delta: event.delta,
341
+ partial: output
342
+ });
343
+ } else if (event.type === "response.function_call_arguments.delta") {
344
+ const slot = getSlot(event.output_index, "toolCall");
345
+ if (!slot)
346
+ continue;
347
+ slot.block.partialJson += event.delta;
348
+ slot.block.arguments = parseStreamingJson(slot.block.partialJson);
349
+ stream.push({
350
+ type: "toolcall_delta",
351
+ contentIndex: slot.contentIndex,
352
+ delta: event.delta,
353
+ partial: output
354
+ });
355
+ } else if (event.type === "response.function_call_arguments.done") {
356
+ const slot = getSlot(event.output_index, "toolCall");
357
+ if (!slot)
358
+ continue;
359
+ const previousPartialJson = slot.block.partialJson;
360
+ slot.block.partialJson = event.arguments;
361
+ slot.block.arguments = parseStreamingJson(slot.block.partialJson);
362
+ if (event.arguments.startsWith(previousPartialJson)) {
363
+ const delta = event.arguments.slice(previousPartialJson.length);
364
+ if (delta.length > 0) {
344
365
  stream.push({
345
- type: "text_delta",
346
- contentIndex: blockIndex(),
347
- delta: event.delta,
366
+ type: "toolcall_delta",
367
+ contentIndex: slot.contentIndex,
368
+ delta,
348
369
  partial: output
349
370
  });
350
371
  }
351
372
  }
352
- } else if (event.type === "response.function_call_arguments.delta") {
353
- if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
354
- currentBlock.partialJson += event.delta;
355
- currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
356
- stream.push({
357
- type: "toolcall_delta",
358
- contentIndex: blockIndex(),
359
- delta: event.delta,
360
- partial: output
361
- });
362
- }
363
- } else if (event.type === "response.function_call_arguments.done") {
364
- if (currentItem?.type === "function_call" && currentBlock?.type === "toolCall") {
365
- const previousPartialJson = currentBlock.partialJson;
366
- currentBlock.partialJson = event.arguments;
367
- currentBlock.arguments = parseStreamingJson(currentBlock.partialJson);
368
- if (event.arguments.startsWith(previousPartialJson)) {
369
- const delta = event.arguments.slice(previousPartialJson.length);
370
- if (delta.length > 0) {
371
- stream.push({
372
- type: "toolcall_delta",
373
- contentIndex: blockIndex(),
374
- delta,
375
- partial: output
376
- });
377
- }
378
- }
379
- }
380
373
  } else if (event.type === "response.output_item.done") {
381
374
  const item = event.item;
382
- if (item.type === "reasoning" && currentBlock?.type === "thinking") {
375
+ const slot = getOrCreateSlot(event.output_index, item);
376
+ if (item.type === "reasoning" && slot?.type === "thinking") {
383
377
  const summaryText = item.summary?.map((s) => s.text).join(`
384
378
 
385
379
  `) || "";
386
380
  const contentText = item.content?.map((c) => c.text).join(`
387
381
 
388
382
  `) || "";
389
- currentBlock.thinking = summaryText || contentText || currentBlock.thinking;
390
- currentBlock.thinkingSignature = JSON.stringify(item);
383
+ slot.block.thinking = summaryText || contentText || slot.block.thinking;
384
+ slot.block.thinkingSignature = JSON.stringify(item);
391
385
  stream.push({
392
386
  type: "thinking_end",
393
- contentIndex: blockIndex(),
394
- content: currentBlock.thinking,
387
+ contentIndex: slot.contentIndex,
388
+ content: slot.block.thinking,
395
389
  partial: output
396
390
  });
397
- currentBlock = null;
398
- } else if (item.type === "message" && currentBlock?.type === "text") {
399
- currentBlock.text = item.content?.map((c) => c.type === "output_text" ? c.text : c.refusal).join("") || "";
400
- currentBlock.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);
391
+ outputSlots.delete(event.output_index);
392
+ } else if (item.type === "message" && slot?.type === "text") {
393
+ slot.block.text = item.content?.map((c) => c.type === "output_text" ? c.text : c.refusal).join("") || "";
394
+ slot.block.textSignature = encodeTextSignatureV1(item.id, item.phase ?? undefined);
401
395
  stream.push({
402
396
  type: "text_end",
403
- contentIndex: blockIndex(),
404
- content: currentBlock.text,
397
+ contentIndex: slot.contentIndex,
398
+ content: slot.block.text,
405
399
  partial: output
406
400
  });
407
- currentBlock = null;
408
- } else if (item.type === "function_call") {
409
- const args = currentBlock?.type === "toolCall" && currentBlock.partialJson ? parseStreamingJson(currentBlock.partialJson) : parseStreamingJson(item.arguments || "{}");
410
- let toolCall;
411
- if (currentBlock?.type === "toolCall") {
412
- currentBlock.arguments = args;
413
- delete currentBlock.partialJson;
414
- toolCall = currentBlock;
415
- } else {
416
- toolCall = {
417
- type: "toolCall",
418
- id: `${item.call_id}|${item.id}`,
419
- name: item.name,
420
- arguments: args
421
- };
422
- }
423
- currentBlock = null;
424
- stream.push({ type: "toolcall_end", contentIndex: blockIndex(), toolCall, partial: output });
401
+ outputSlots.delete(event.output_index);
402
+ } else if (item.type === "function_call" && slot?.type === "toolCall") {
403
+ slot.block.arguments = parseStreamingJson(item.arguments || slot.block.partialJson || "{}");
404
+ delete slot.block.partialJson;
405
+ stream.push({
406
+ type: "toolcall_end",
407
+ contentIndex: slot.contentIndex,
408
+ toolCall: slot.block,
409
+ partial: output
410
+ });
411
+ outputSlots.delete(event.output_index);
425
412
  }
426
413
  } else if (event.type === "response.completed" || event.type === "response.incomplete") {
427
414
  finalizeResponse(event.response);
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  buildModelsDevSeedRows
3
- } from "./cli-7v4y3hyd.js";
3
+ } from "./cli-xgssgdqn.js";
4
4
  import {
5
5
  createLogEntry,
6
6
  getActivePricingRow,
7
7
  getDb,
8
8
  init_db,
9
9
  insertPricingRow
10
- } from "./cli-0jw6j755.js";
10
+ } from "./cli-6xn2xv4r.js";
11
11
  import {
12
12
  init_secret_scrubber,
13
13
  scrubSecrets
@@ -3,7 +3,7 @@ import {
3
3
  incrKv,
4
4
  init_db,
5
5
  upsertKv
6
- } from "./cli-0jw6j755.js";
6
+ } from "./cli-6xn2xv4r.js";
7
7
 
8
8
  // src/be/unmapped-identities.ts
9
9
  init_db();
@@ -3,6 +3,7 @@ var CONTEXT_FORMULA = "input-cache-output";
3
3
  var CONTEXT_WINDOW_DEFAULTS = {
4
4
  "claude-fable-5": 1e6,
5
5
  "claude-mythos-5": 1e6,
6
+ "claude-sonnet-5": 1e6,
6
7
  "claude-opus-4-8": 1e6,
7
8
  "claude-opus-4-7": 1e6,
8
9
  "claude-opus-4-6": 1e6,