@standardagents/builder 0.41.22 → 0.41.26

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 (39) hide show
  1. package/dist/built-in-routes.js +387 -134
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-D4g6ZNWG.js → ApiKeysView-CJYLO_ua.js} +1 -1
  4. package/dist/client/{CenteredContentView-B3WUhJPU.js → CenteredContentView-V1sCsISI.js} +1 -1
  5. package/dist/client/{CompositionView-pL0H07yI.js → CompositionView-hqbZ8f7d.js} +1 -1
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-uehuZFVv.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-CYrgsA6b.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-vwNMv4kh.js → CopyButton.vue_vue_type_script_setup_true_lang-DFIJfKuD.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-lgIAQ4Oz.js → DataTable.vue_vue_type_script_setup_true_lang-IvRbPHup.js} +1 -1
  9. package/dist/client/{JsonViewer-BsC-w_01.js → JsonViewer-C6FsqOlJ.js} +1 -1
  10. package/dist/client/{LoginView-DriOurmS.js → LoginView-san5UrfX.js} +1 -1
  11. package/dist/client/{MarketplaceView-7pl01VFg.js → MarketplaceView-B89Shmm7.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-CQE6ME9a.js → Modal.vue_vue_type_script_setup_true_lang-BLzEXJtn.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-Dv-GVzNy.js → ModelModal.vue_vue_type_script_setup_true_lang-DTd4Jp3K.js} +1 -1
  14. package/dist/client/{ModelsView-BDxyu8pj.js → ModelsView-DWLrrwGf.js} +1 -1
  15. package/dist/client/{PromptEditView-Brn_lMum.js → PromptEditView-PHQ8rLZn.js} +1 -1
  16. package/dist/client/{PromptModal-BeqgBmpj.js → PromptModal-Bk5rLNB7.js} +1 -1
  17. package/dist/client/{PromptsView-Dgu1UMES.js → PromptsView-gugjlK3M.js} +1 -1
  18. package/dist/client/{ProvidersView-B3SPkaxt.js → ProvidersView-DVV8Q1Sw.js} +1 -1
  19. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-BvsyovVV.js +22 -0
  20. package/dist/client/{ThreadsView-D0hT0NXg.js → ThreadsView-Doxz0NfK.js} +1 -1
  21. package/dist/client/{ToolsView-BitH87Mf.js → ToolsView-BZfq0wpk.js} +1 -1
  22. package/dist/client/{UsersView-BArKqDfJ.js → UsersView-D5sXzAHz.js} +1 -1
  23. package/dist/client/{VariablesView-BJtT_XLQ.js → VariablesView-BlEY-E07.js} +1 -1
  24. package/dist/client/assets/{ThreadInspectorPane-C9Lp8kxl.css → ThreadInspectorPane-DczJCBBm.css} +1 -1
  25. package/dist/client/{index-CAiyJVjz.js → index-CdsRfG1j.js} +2 -2
  26. package/dist/client/index.html +1 -1
  27. package/dist/{index-BhIiPl8o.d.ts → index-Dn0rBA1H.d.ts} +4 -2
  28. package/dist/index.d.ts +3 -3
  29. package/dist/index.js +196 -35
  30. package/dist/index.js.map +1 -1
  31. package/dist/plugin.js +1 -1
  32. package/dist/plugin.js.map +1 -1
  33. package/dist/{resolver-D30lNT4L.d.ts → resolver-C6zKX6kw.d.ts} +11 -5
  34. package/dist/runtime.d.ts +2 -2
  35. package/dist/runtime.js +195 -34
  36. package/dist/runtime.js.map +1 -1
  37. package/dist/test.d.ts +1 -1
  38. package/package.json +5 -5
  39. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DaArzwIz.js +0 -22
@@ -3414,6 +3414,153 @@ var init_remoteAttachment = __esm({
3414
3414
  }
3415
3415
  });
3416
3416
 
3417
+ // src/agents/strictToolSchema.ts
3418
+ function isRecord(value) {
3419
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3420
+ }
3421
+ function isObjectSchema(schema) {
3422
+ const type = schema.type;
3423
+ return type === "object" || Array.isArray(type) && type.includes("object") || type === void 0 && isRecord(schema.properties);
3424
+ }
3425
+ function acceptsNull(schema) {
3426
+ if (schema.type === "null") return true;
3427
+ if (Array.isArray(schema.type) && schema.type.includes("null")) return true;
3428
+ return Array.isArray(schema.anyOf) && schema.anyOf.some((v) => isRecord(v) && acceptsNull(v));
3429
+ }
3430
+ function nullableStrictSchema(schema) {
3431
+ if (acceptsNull(schema)) return schema;
3432
+ const { description, title, ...rest } = schema;
3433
+ const variants = Array.isArray(rest.anyOf) && Object.keys(rest).length === 1 ? [...rest.anyOf] : [rest];
3434
+ return {
3435
+ anyOf: [...variants, { type: "null" }],
3436
+ ...description !== void 0 ? { description } : {},
3437
+ ...title !== void 0 ? { title } : {}
3438
+ };
3439
+ }
3440
+ function toStrictSchema(value) {
3441
+ if (!isRecord(value)) return {};
3442
+ if (Array.isArray(value.anyOf)) {
3443
+ const node2 = { anyOf: value.anyOf.map((v) => toStrictSchema(v)) };
3444
+ if (typeof value.description === "string") node2.description = value.description;
3445
+ if (typeof value.title === "string") node2.title = value.title;
3446
+ return node2;
3447
+ }
3448
+ const node = {};
3449
+ for (const [key, child] of Object.entries(value)) {
3450
+ if (!SUPPORTED_KEYWORDS.has(key)) continue;
3451
+ if (key === "properties" || key === "required" || key === "additionalProperties") continue;
3452
+ if (key === "items") node.items = toStrictSchema(child);
3453
+ else if (key === "$defs" && isRecord(child)) {
3454
+ node.$defs = Object.fromEntries(
3455
+ Object.entries(child).map(([name15, def]) => [name15, toStrictSchema(def)])
3456
+ );
3457
+ } else node[key] = child;
3458
+ }
3459
+ if (isObjectSchema(value)) {
3460
+ const properties = isRecord(value.properties) ? value.properties : {};
3461
+ const required = new Set(
3462
+ Array.isArray(value.required) ? value.required.filter((item) => typeof item === "string") : []
3463
+ );
3464
+ node.type = "object";
3465
+ node.properties = Object.fromEntries(
3466
+ Object.entries(properties).map(([name15, child]) => {
3467
+ const strict = toStrictSchema(child);
3468
+ return [name15, required.has(name15) ? strict : nullableStrictSchema(strict)];
3469
+ })
3470
+ );
3471
+ node.required = Object.keys(properties);
3472
+ node.additionalProperties = false;
3473
+ }
3474
+ return node;
3475
+ }
3476
+ function stripNullArguments(value) {
3477
+ if (Array.isArray(value)) {
3478
+ return value.map((item) => isRecord(item) ? stripNullArguments(item) : item);
3479
+ }
3480
+ if (!isRecord(value)) return value;
3481
+ const out = {};
3482
+ for (const [key, child] of Object.entries(value)) {
3483
+ if (child === null) continue;
3484
+ out[key] = stripNullArguments(child);
3485
+ }
3486
+ return out;
3487
+ }
3488
+ function buildSubagentArgumentsSchema(sources) {
3489
+ const merged = /* @__PURE__ */ new Map();
3490
+ for (const source of sources) {
3491
+ const schema = isRecord(source.argumentSchema) ? source.argumentSchema : {};
3492
+ const properties2 = isRecord(schema.properties) ? schema.properties : {};
3493
+ const required = new Set(
3494
+ Array.isArray(schema.required) ? schema.required.filter((item) => typeof item === "string") : []
3495
+ );
3496
+ for (const [prop, child] of Object.entries(properties2)) {
3497
+ const entry = merged.get(prop) ?? {
3498
+ variants: /* @__PURE__ */ new Map(),
3499
+ declaredBy: [],
3500
+ requiredBy: []
3501
+ };
3502
+ const strict = toStrictSchema(child);
3503
+ entry.variants.set(JSON.stringify(strict), strict);
3504
+ entry.declaredBy.push(source.name);
3505
+ if (required.has(prop)) entry.requiredBy.push(source.name);
3506
+ merged.set(prop, entry);
3507
+ }
3508
+ }
3509
+ const multiple = sources.length > 1;
3510
+ const properties = {};
3511
+ for (const [prop, entry] of merged) {
3512
+ const variants = [...entry.variants.values()];
3513
+ let schema = variants.length === 1 ? variants[0] : { anyOf: variants };
3514
+ if (multiple) {
3515
+ const usage = [`Used by: ${entry.declaredBy.join(", ")}.`];
3516
+ usage.push(
3517
+ entry.requiredBy.length === sources.length ? "Required." : entry.requiredBy.length > 0 ? `Required for: ${entry.requiredBy.join(", ")}; pass null for other agents.` : "Optional; pass null to omit."
3518
+ );
3519
+ const own = typeof schema.description === "string" ? `${schema.description} ` : "";
3520
+ schema = { ...schema, description: `${own}${usage.join(" ")}` };
3521
+ }
3522
+ const alwaysRequired = entry.variants.size === 1 && sources.every((source) => entry.requiredBy.includes(source.name));
3523
+ properties[prop] = alwaysRequired ? schema : nullableStrictSchema(schema);
3524
+ }
3525
+ return {
3526
+ type: "object",
3527
+ description: multiple ? "Initial arguments for the selected agent; they persist for the child thread lifetime. Fill the properties the selected agent uses and pass null for the rest." : `Initial arguments for ${sources[0]?.name ?? "the subagent"}; they persist for the child thread lifetime.`,
3528
+ properties,
3529
+ required: Object.keys(properties),
3530
+ additionalProperties: false
3531
+ };
3532
+ }
3533
+ var SUPPORTED_KEYWORDS;
3534
+ var init_strictToolSchema = __esm({
3535
+ "src/agents/strictToolSchema.ts"() {
3536
+ SUPPORTED_KEYWORDS = /* @__PURE__ */ new Set([
3537
+ "type",
3538
+ "properties",
3539
+ "required",
3540
+ "additionalProperties",
3541
+ "items",
3542
+ "enum",
3543
+ "const",
3544
+ "anyOf",
3545
+ "description",
3546
+ "title",
3547
+ "pattern",
3548
+ "format",
3549
+ "minLength",
3550
+ "maxLength",
3551
+ "minimum",
3552
+ "maximum",
3553
+ "exclusiveMinimum",
3554
+ "exclusiveMaximum",
3555
+ "multipleOf",
3556
+ "minItems",
3557
+ "maxItems",
3558
+ "$ref",
3559
+ "$defs"
3560
+ ]);
3561
+ }
3562
+ });
3563
+
3417
3564
  // src/durable-objects/files.ts
3418
3565
  var files_exports = {};
3419
3566
  __export(files_exports, {
@@ -4152,6 +4299,7 @@ var init_ToolExecutor = __esm({
4152
4299
  init_ThreadStateImpl();
4153
4300
  init_sessionTools();
4154
4301
  init_remoteAttachment();
4302
+ init_strictToolSchema();
4155
4303
  SUBAGENT_CREATE_TOOL = "subagent_create";
4156
4304
  SUBAGENT_MESSAGE_TOOL = "subagent_message";
4157
4305
  SUBAGENTS_LIST_TOOL = "subagents";
@@ -5072,16 +5220,26 @@ Message one with subagent_message(referenceId, message).`
5072
5220
  args,
5073
5221
  initAttachmentsProperty
5074
5222
  );
5075
- const initialArguments = builtinSubagentAction === "create" ? builtinCreateInitialArguments : args;
5076
- const argumentValidationError = await this.validateSubagentArguments(
5223
+ const validationOptions = { agentName, packageId };
5224
+ let initialArguments = builtinSubagentAction === "create" ? stripNullArguments(builtinCreateInitialArguments) : args;
5225
+ let argumentValidationError = await this.validateSubagentArguments(
5077
5226
  state,
5078
5227
  agentDef,
5079
5228
  initialArguments,
5080
- {
5081
- agentName,
5082
- packageId
5083
- }
5229
+ validationOptions
5084
5230
  );
5231
+ if (argumentValidationError && builtinSubagentAction === "create") {
5232
+ const rawError = await this.validateSubagentArguments(
5233
+ state,
5234
+ agentDef,
5235
+ builtinCreateInitialArguments,
5236
+ validationOptions
5237
+ );
5238
+ if (!rawError) {
5239
+ argumentValidationError = null;
5240
+ initialArguments = builtinCreateInitialArguments;
5241
+ }
5242
+ }
5085
5243
  if (argumentValidationError) {
5086
5244
  return argumentValidationError;
5087
5245
  }
@@ -5391,7 +5549,7 @@ Message one with subagent_message(referenceId, message).`
5391
5549
  error: `${SUBAGENT_CREATE_TOOL} requires agent.`
5392
5550
  };
5393
5551
  }
5394
- if (rawArguments !== void 0 && (typeof rawArguments !== "object" || rawArguments === null || Array.isArray(rawArguments))) {
5552
+ if (rawArguments !== void 0 && rawArguments !== null && (typeof rawArguments !== "object" || rawArguments === null || Array.isArray(rawArguments))) {
5395
5553
  return {
5396
5554
  agent,
5397
5555
  message,
@@ -15750,10 +15908,15 @@ ${resultContent}${attachmentSummary}`;
15750
15908
  }
15751
15909
  }
15752
15910
  /**
15753
- * This thread's OWN request-log cost summary (no descendants), aggregated
15754
- * in SQL so subtree cost reporting doesn't page full log rows out of every
15755
- * thread in the tree. Used by GET /api/threads/:id/cost, which merges these
15756
- * across the thread and all of its subagent descendants.
15911
+ * This thread's OWN cost summary (no descendants), aggregated in SQL so
15912
+ * subtree cost reporting doesn't page full log rows out of every thread in
15913
+ * the tree. Used by GET /api/threads/:id/cost, which merges these across
15914
+ * the thread and all of its subagent descendants.
15915
+ *
15916
+ * `totalCost` is everything the thread cost: LLM request rows (`cost_total`)
15917
+ * plus application log rows (`kind = 'app'`, ThreadState.log() `cost`,
15918
+ * stored as `app_cost`). `appCost` reports the application share apart;
15919
+ * the per-model breakdown, component sums and `requestCount` stay LLM-only.
15757
15920
  */
15758
15921
  async getCostSummary() {
15759
15922
  await this.ensureMigrated();
@@ -15774,7 +15937,7 @@ ${resultContent}${attachmentSummary}`;
15774
15937
  SUM(cost_router_fee) AS router_fee_cost,
15775
15938
  COUNT(*) AS request_count
15776
15939
  FROM logs
15777
- WHERE cost_total IS NOT NULL
15940
+ WHERE cost_total IS NOT NULL AND (kind IS NULL OR kind != '${APP_LOG_KIND}')
15778
15941
  GROUP BY model_key
15779
15942
  `
15780
15943
  );
@@ -15794,12 +15957,21 @@ ${resultContent}${attachmentSummary}`;
15794
15957
  routerFeeCost += row.router_fee_cost ?? 0;
15795
15958
  requestCount += row.request_count;
15796
15959
  }
15960
+ const appRow = await this.ctx.storage.sql.exec(
15961
+ `SELECT SUM(app_cost) AS app_cost FROM logs WHERE kind = ? AND app_cost IS NOT NULL`,
15962
+ APP_LOG_KIND
15963
+ );
15964
+ const appCost = appRow.one().app_cost ?? 0;
15965
+ totalCost += appCost;
15797
15966
  const messageRow = await this.ctx.storage.sql.exec(
15798
- `SELECT COUNT(DISTINCT message_id) AS message_count FROM logs WHERE cost_total IS NOT NULL`
15967
+ `SELECT COUNT(DISTINCT message_id) AS message_count FROM logs
15968
+ WHERE cost_total IS NOT NULL OR (kind = ? AND app_cost IS NOT NULL)`,
15969
+ APP_LOG_KIND
15799
15970
  );
15800
15971
  const messageCount = messageRow.one().message_count || 0;
15801
15972
  return {
15802
15973
  totalCost,
15974
+ appCost,
15803
15975
  inputCost,
15804
15976
  cachedCost,
15805
15977
  outputCost,
@@ -19557,6 +19729,7 @@ var init_FlowEngine = __esm({
19557
19729
  init_sessionTools();
19558
19730
  init_ThreadStateImpl();
19559
19731
  init_ParentHookResolver();
19732
+ init_strictToolSchema();
19560
19733
  IMMEDIATE_BOOTSTRAP_TOOL_NAME = "bootstrap_immediate_subagent";
19561
19734
  HookBlockedExecutionError = class extends Error {
19562
19735
  constructor(message) {
@@ -22329,22 +22502,6 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
22329
22502
  }
22330
22503
  return parts.length > 0 ? parts.join("; ") : "no extra initial arguments";
22331
22504
  }
22332
- static buildSubagentArgumentsSchema(sideSubagentDescriptors) {
22333
- const variants = sideSubagentDescriptors.map((entry) => ({
22334
- ...this.normalizeSubagentArgumentSchema(entry.argumentSchema),
22335
- title: `${entry.name} initial arguments`,
22336
- description: `Initial arguments for ${entry.name}. These values persist for the child thread lifetime.`
22337
- }));
22338
- if (variants.length === 1) {
22339
- return variants[0];
22340
- }
22341
- return {
22342
- type: "object",
22343
- description: "Agent-specific initial arguments for the selected subagent. Use the schema matching the selected agent.",
22344
- additionalProperties: false,
22345
- anyOf: variants
22346
- };
22347
- }
22348
22505
  static buildSubagentCreateTool(sideSubagentDescriptors) {
22349
22506
  const agentNames = sideSubagentDescriptors.map((entry) => entry.name);
22350
22507
  const descriptionLines = sideSubagentDescriptors.map((entry) => {
@@ -22361,7 +22518,7 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
22361
22518
  "Create and run a configured subagent. Every instance is a persistent, addressable thread.",
22362
22519
  "Available subagents:",
22363
22520
  ...descriptionLines,
22364
- "Provide any required invocation arguments via `arguments`; they persist for the life of the subagent thread.",
22521
+ "Provide the selected agent's invocation arguments via `arguments` (null for properties it does not use); they persist for the life of the subagent thread.",
22365
22522
  "Before creating a new instance, call `subagents` to check the status of instances you already have \u2014 an existing one may already cover the work, and instance caps count live children.",
22366
22523
  "Use subagent_message for follow-up communication with existing instances."
22367
22524
  ].join("\n"),
@@ -22388,10 +22545,14 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
22388
22545
  type: "string",
22389
22546
  description: "Required human-readable instance name for the spawned subagent thread. Use a concise stable label that identifies this child instance."
22390
22547
  },
22391
- arguments: this.buildSubagentArgumentsSchema(sideSubagentDescriptors)
22548
+ // One strict object (union of every relationship's arguments,
22549
+ // optional ones nullable) — see strictToolSchema.ts for the
22550
+ // provider rules this satisfies. Required like every property
22551
+ // under strict mode; the model passes {} when there are none.
22552
+ arguments: buildSubagentArgumentsSchema(sideSubagentDescriptors)
22392
22553
  },
22393
22554
  additionalProperties: false,
22394
- required: ["agent", "message", "attachments", "name"]
22555
+ required: ["agent", "message", "attachments", "name", "arguments"]
22395
22556
  }
22396
22557
  }
22397
22558
  };
@@ -22415,8 +22576,8 @@ ${msg.content}` : `${imageDescriptions}${nonImageList}`;
22415
22576
  sanitized[key] = this.sanitizeToolJsonSchema(child);
22416
22577
  }
22417
22578
  const type = sanitized.type;
22418
- const isObjectSchema = type === "object" || Array.isArray(type) && type.includes("object");
22419
- if (isObjectSchema) {
22579
+ const isObjectSchema2 = type === "object" || Array.isArray(type) && type.includes("object");
22580
+ if (isObjectSchema2) {
22420
22581
  sanitized.additionalProperties = false;
22421
22582
  }
22422
22583
  return sanitized;
@@ -30167,11 +30328,11 @@ ${msg.content}` : msg.content;
30167
30328
  flushToolResults();
30168
30329
  return { anthropicMessages, system };
30169
30330
  }
30170
- function isRecord(value) {
30331
+ function isRecord2(value) {
30171
30332
  return typeof value === "object" && value !== null && !Array.isArray(value);
30172
30333
  }
30173
30334
  function transformTool(tool3) {
30174
- const parameters = isRecord(tool3.function.parameters) ? tool3.function.parameters : { type: "object", properties: {} };
30335
+ const parameters = isRecord2(tool3.function.parameters) ? tool3.function.parameters : { type: "object", properties: {} };
30175
30336
  return {
30176
30337
  name: tool3.function.name,
30177
30338
  ...tool3.function.description ? { description: tool3.function.description } : {},
@@ -30271,23 +30432,23 @@ function extractToolCalls(content) {
30271
30432
  toolCalls.push({
30272
30433
  id: block.id,
30273
30434
  name: block.name,
30274
- arguments: isRecord(block.input) ? block.input : {}
30435
+ arguments: isRecord2(block.input) ? block.input : {}
30275
30436
  });
30276
30437
  }
30277
30438
  }
30278
30439
  return toolCalls.length > 0 ? toolCalls : void 0;
30279
30440
  }
30280
30441
  function webSearchToolResult(id, input, resultContent) {
30281
- const query = isRecord(input) && typeof input.query === "string" ? input.query : void 0;
30442
+ const query = isRecord2(input) && typeof input.query === "string" ? input.query : void 0;
30282
30443
  let status = "completed";
30283
30444
  let sources;
30284
30445
  if (Array.isArray(resultContent)) {
30285
- sources = resultContent.filter(isRecord).filter((item) => item.type === "web_search_result" && typeof item.url === "string").map((item) => ({
30446
+ sources = resultContent.filter(isRecord2).filter((item) => item.type === "web_search_result" && typeof item.url === "string").map((item) => ({
30286
30447
  type: "url",
30287
30448
  url: item.url,
30288
30449
  ...typeof item.title === "string" ? { title: item.title } : {}
30289
30450
  }));
30290
- } else if (isRecord(resultContent) && resultContent.type === "web_search_tool_result_error") {
30451
+ } else if (isRecord2(resultContent) && resultContent.type === "web_search_tool_result_error") {
30291
30452
  status = "failed";
30292
30453
  }
30293
30454
  return {
@@ -30366,7 +30527,7 @@ function transformResponse(message) {
30366
30527
  };
30367
30528
  }
30368
30529
  function resolveThinkingOverride(value) {
30369
- if (!isRecord(value)) return void 0;
30530
+ if (!isRecord2(value)) return void 0;
30370
30531
  const display = value.display === "summarized" || value.display === "omitted" ? value.display : void 0;
30371
30532
  if (value.type === "adaptive") {
30372
30533
  return { type: "adaptive", ...display ? { display } : {} };
@@ -30399,7 +30560,7 @@ function buildCreateParams(request, reasoningLevels = DEFAULT_REASONING_LEVELS,
30399
30560
  max_tokens: maxTokens,
30400
30561
  messages: anthropicMessages
30401
30562
  };
30402
- const providerOptions = isRecord(request.providerOptions) ? request.providerOptions : {};
30563
+ const providerOptions = isRecord2(request.providerOptions) ? request.providerOptions : {};
30403
30564
  const {
30404
30565
  cacheSystemPrompt,
30405
30566
  thinking: thinkingOverride,
@@ -30507,7 +30668,7 @@ function createStreamState() {
30507
30668
  function parseToolCallArguments(argumentsJson) {
30508
30669
  try {
30509
30670
  const parsed = argumentsJson ? JSON.parse(argumentsJson) : {};
30510
- return isRecord(parsed) ? parsed : {};
30671
+ return isRecord2(parsed) ? parsed : {};
30511
30672
  } catch {
30512
30673
  return {};
30513
30674
  }
@@ -31466,20 +31627,20 @@ function transformChatMessages2(messages) {
31466
31627
  }
31467
31628
  return result;
31468
31629
  }
31469
- function isRecord2(value) {
31630
+ function isRecord3(value) {
31470
31631
  return !!value && typeof value === "object" && !Array.isArray(value);
31471
31632
  }
31472
31633
  function normalizeStrictJsonSchema(schema) {
31473
31634
  if (Array.isArray(schema)) {
31474
31635
  return schema.map((item) => normalizeStrictJsonSchema(item));
31475
31636
  }
31476
- if (!isRecord2(schema)) {
31637
+ if (!isRecord3(schema)) {
31477
31638
  return schema;
31478
31639
  }
31479
31640
  const normalized = {};
31480
31641
  for (const [key, value] of Object.entries(schema)) {
31481
31642
  if (STRICT_UNSUPPORTED_KEYWORDS.has(key)) continue;
31482
- if (key === "properties" && isRecord2(value)) {
31643
+ if (key === "properties" && isRecord3(value)) {
31483
31644
  const props = {};
31484
31645
  for (const [propName, propSchema] of Object.entries(value)) {
31485
31646
  props[propName] = normalizeStrictJsonSchema(propSchema);
@@ -31491,10 +31652,10 @@ function normalizeStrictJsonSchema(schema) {
31491
31652
  normalized[key] = normalizeStrictJsonSchema(value);
31492
31653
  }
31493
31654
  }
31494
- const properties = isRecord2(normalized.properties) ? normalized.properties : void 0;
31655
+ const properties = isRecord3(normalized.properties) ? normalized.properties : void 0;
31495
31656
  const type = normalized.type;
31496
- const isObjectSchema = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
31497
- if (isObjectSchema) {
31657
+ const isObjectSchema2 = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
31658
+ if (isObjectSchema2) {
31498
31659
  if (normalized.type === void 0) {
31499
31660
  normalized.type = "object";
31500
31661
  }
@@ -31505,7 +31666,7 @@ function normalizeStrictJsonSchema(schema) {
31505
31666
  return normalized;
31506
31667
  }
31507
31668
  function normalizeStrictToolParameters(parameters) {
31508
- const base = isRecord2(parameters) ? { ...parameters } : {};
31669
+ const base = isRecord3(parameters) ? { ...parameters } : {};
31509
31670
  if (base.type === void 0) base.type = "object";
31510
31671
  if (base.properties === void 0) base.properties = {};
31511
31672
  return normalizeStrictJsonSchema(base);
@@ -32415,20 +32576,20 @@ function transformChatMessages3(messages) {
32415
32576
  }
32416
32577
  return result;
32417
32578
  }
32418
- function isRecord3(value) {
32579
+ function isRecord4(value) {
32419
32580
  return !!value && typeof value === "object" && !Array.isArray(value);
32420
32581
  }
32421
32582
  function normalizeStrictJsonSchema2(schema) {
32422
32583
  if (Array.isArray(schema)) {
32423
32584
  return schema.map((item) => normalizeStrictJsonSchema2(item));
32424
32585
  }
32425
- if (!isRecord3(schema)) {
32586
+ if (!isRecord4(schema)) {
32426
32587
  return schema;
32427
32588
  }
32428
32589
  const normalized = {};
32429
32590
  for (const [key, value] of Object.entries(schema)) {
32430
32591
  if (STRICT_UNSUPPORTED_KEYWORDS2.has(key)) continue;
32431
- if (key === "properties" && isRecord3(value)) {
32592
+ if (key === "properties" && isRecord4(value)) {
32432
32593
  const props = {};
32433
32594
  for (const [propName, propSchema] of Object.entries(value)) {
32434
32595
  props[propName] = normalizeStrictJsonSchema2(propSchema);
@@ -32440,10 +32601,10 @@ function normalizeStrictJsonSchema2(schema) {
32440
32601
  normalized[key] = normalizeStrictJsonSchema2(value);
32441
32602
  }
32442
32603
  }
32443
- const properties = isRecord3(normalized.properties) ? normalized.properties : void 0;
32604
+ const properties = isRecord4(normalized.properties) ? normalized.properties : void 0;
32444
32605
  const type = normalized.type;
32445
- const isObjectSchema = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
32446
- if (isObjectSchema) {
32606
+ const isObjectSchema2 = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
32607
+ if (isObjectSchema2) {
32447
32608
  if (normalized.type === void 0) {
32448
32609
  normalized.type = "object";
32449
32610
  }
@@ -32454,7 +32615,7 @@ function normalizeStrictJsonSchema2(schema) {
32454
32615
  return normalized;
32455
32616
  }
32456
32617
  function normalizeStrictToolParameters2(parameters) {
32457
- const base = isRecord3(parameters) ? { ...parameters } : {};
32618
+ const base = isRecord4(parameters) ? { ...parameters } : {};
32458
32619
  if (base.type === void 0) base.type = "object";
32459
32620
  if (base.properties === void 0) base.properties = {};
32460
32621
  return normalizeStrictJsonSchema2(base);
@@ -55032,20 +55193,20 @@ function transformChatMessages4(messages) {
55032
55193
  }
55033
55194
  return result;
55034
55195
  }
55035
- function isRecord4(value) {
55196
+ function isRecord5(value) {
55036
55197
  return !!value && typeof value === "object" && !Array.isArray(value);
55037
55198
  }
55038
55199
  function normalizeStrictJsonSchema3(schema) {
55039
55200
  if (Array.isArray(schema)) {
55040
55201
  return schema.map((item) => normalizeStrictJsonSchema3(item));
55041
55202
  }
55042
- if (!isRecord4(schema)) {
55203
+ if (!isRecord5(schema)) {
55043
55204
  return schema;
55044
55205
  }
55045
55206
  const normalized = {};
55046
55207
  for (const [key, value] of Object.entries(schema)) {
55047
55208
  if (STRICT_UNSUPPORTED_KEYWORDS3.has(key)) continue;
55048
- if (key === "properties" && isRecord4(value)) {
55209
+ if (key === "properties" && isRecord5(value)) {
55049
55210
  const props = {};
55050
55211
  for (const [propName, propSchema] of Object.entries(value)) {
55051
55212
  props[propName] = normalizeStrictJsonSchema3(propSchema);
@@ -55057,10 +55218,10 @@ function normalizeStrictJsonSchema3(schema) {
55057
55218
  normalized[key] = normalizeStrictJsonSchema3(value);
55058
55219
  }
55059
55220
  }
55060
- const properties = isRecord4(normalized.properties) ? normalized.properties : void 0;
55221
+ const properties = isRecord5(normalized.properties) ? normalized.properties : void 0;
55061
55222
  const type = normalized.type;
55062
- const isObjectSchema = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
55063
- if (isObjectSchema) {
55223
+ const isObjectSchema2 = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
55224
+ if (isObjectSchema2) {
55064
55225
  if (normalized.type === void 0) {
55065
55226
  normalized.type = "object";
55066
55227
  }
@@ -55071,7 +55232,7 @@ function normalizeStrictJsonSchema3(schema) {
55071
55232
  return normalized;
55072
55233
  }
55073
55234
  function normalizeStrictToolParameters3(parameters) {
55074
- const base = isRecord4(parameters) ? { ...parameters } : {};
55235
+ const base = isRecord5(parameters) ? { ...parameters } : {};
55075
55236
  if (base.type === void 0) base.type = "object";
55076
55237
  if (base.properties === void 0) base.properties = {};
55077
55238
  return normalizeStrictJsonSchema3(base);
@@ -56169,7 +56330,7 @@ ${msg.content}` : msg.content;
56169
56330
  }
56170
56331
  return { input, instructions };
56171
56332
  }
56172
- function isRecord5(value) {
56333
+ function isRecord6(value) {
56173
56334
  return typeof value === "object" && value !== null && !Array.isArray(value);
56174
56335
  }
56175
56336
  function isObjectJsonSchema(schema) {
@@ -56180,15 +56341,24 @@ function normalizeStrictFunctionSchema(value) {
56180
56341
  if (Array.isArray(value)) {
56181
56342
  return value.map((item) => normalizeStrictFunctionSchema(item));
56182
56343
  }
56183
- if (!isRecord5(value)) {
56344
+ if (!isRecord6(value)) {
56184
56345
  return value;
56185
56346
  }
56347
+ if (Array.isArray(value.anyOf)) {
56348
+ const normalized2 = {
56349
+ anyOf: value.anyOf.map((item) => normalizeStrictFunctionSchema(item))
56350
+ };
56351
+ for (const key of ANY_OF_ANNOTATION_KEYS) {
56352
+ if (key in value) normalized2[key] = value[key];
56353
+ }
56354
+ return normalized2;
56355
+ }
56186
56356
  const normalized = {};
56187
56357
  for (const [key, child] of Object.entries(value)) {
56188
56358
  normalized[key] = normalizeStrictFunctionSchema(child);
56189
56359
  }
56190
56360
  if (isObjectJsonSchema(normalized)) {
56191
- const properties = isRecord5(normalized.properties) ? normalized.properties : {};
56361
+ const properties = isRecord6(normalized.properties) ? normalized.properties : {};
56192
56362
  normalized.properties = properties;
56193
56363
  normalized.required = Object.keys(properties);
56194
56364
  normalized.additionalProperties = false;
@@ -56196,12 +56366,12 @@ function normalizeStrictFunctionSchema(value) {
56196
56366
  return normalized;
56197
56367
  }
56198
56368
  function normalizeStrictFunctionParameters(inputParams) {
56199
- const schema = isRecord5(inputParams) ? inputParams : {
56369
+ const schema = isRecord6(inputParams) ? inputParams : {
56200
56370
  type: "object",
56201
56371
  properties: {}
56202
56372
  };
56203
56373
  const normalized = normalizeStrictFunctionSchema(schema);
56204
- return isRecord5(normalized) ? normalized : { type: "object", properties: {}, required: [], additionalProperties: false };
56374
+ return isRecord6(normalized) ? normalized : { type: "object", properties: {}, required: [], additionalProperties: false };
56205
56375
  }
56206
56376
  function transformTool2(tool3) {
56207
56377
  const inputParams = tool3.function.parameters;
@@ -56262,6 +56432,24 @@ function mapFinishReason5(response) {
56262
56432
  }
56263
56433
  return "stop";
56264
56434
  }
56435
+ function unusableResponseError(response) {
56436
+ if (response.status === "failed") {
56437
+ return {
56438
+ message: response.error?.message || "Response generation failed",
56439
+ code: response.error?.code || "server_error"
56440
+ };
56441
+ }
56442
+ if (response.status !== "incomplete") return null;
56443
+ const output = Array.isArray(response.output) ? response.output : [];
56444
+ const hasToolCalls = output.some((item) => item.type === "function_call");
56445
+ const text2 = extractTextContent2(output);
56446
+ if (hasToolCalls || text2 !== null && text2.length > 0) return null;
56447
+ const reason = response.incomplete_details?.reason ?? "unknown";
56448
+ return {
56449
+ message: `OpenAI returned an incomplete response with no output (reason: ${reason})` + (response.error?.message ? `: ${response.error.message}` : ""),
56450
+ code: response.error?.code || "invalid_request"
56451
+ };
56452
+ }
56265
56453
  function extractTextContent2(output) {
56266
56454
  const textParts = [];
56267
56455
  for (const item of output) {
@@ -56340,15 +56528,15 @@ function getStringValue(record24, key) {
56340
56528
  return typeof value === "string" ? value : void 0;
56341
56529
  }
56342
56530
  function extractOpenAIWebSearchActions(item) {
56343
- if (!isRecord5(item)) return void 0;
56531
+ if (!isRecord6(item)) return void 0;
56344
56532
  const action = item.action;
56345
- if (!isRecord5(action)) return void 0;
56533
+ if (!isRecord6(action)) return void 0;
56346
56534
  const type = getStringValue(action, "type") ?? "search";
56347
56535
  const query = getStringValue(action, "query");
56348
56536
  const url = getStringValue(action, "url");
56349
56537
  const pattern = getStringValue(action, "pattern");
56350
56538
  const rawSources = action.sources;
56351
- const sources = Array.isArray(rawSources) ? rawSources.filter(isRecord5).map((source) => ({
56539
+ const sources = Array.isArray(rawSources) ? rawSources.filter(isRecord6).map((source) => ({
56352
56540
  type: getStringValue(source, "type"),
56353
56541
  url: getStringValue(source, "url") ?? "",
56354
56542
  title: getStringValue(source, "title")
@@ -56364,7 +56552,7 @@ function extractOpenAIWebSearchActions(item) {
56364
56552
  };
56365
56553
  }
56366
56554
  function extractOpenAIFileSearchResult(item) {
56367
- if (!isRecord5(item)) return void 0;
56555
+ if (!isRecord6(item)) return void 0;
56368
56556
  const queries = item.queries;
56369
56557
  const results = item.results;
56370
56558
  return {
@@ -56373,11 +56561,11 @@ function extractOpenAIFileSearchResult(item) {
56373
56561
  };
56374
56562
  }
56375
56563
  function extractOpenAICodeInterpreterResult(item) {
56376
- if (!isRecord5(item)) return void 0;
56564
+ if (!isRecord6(item)) return void 0;
56377
56565
  const code = getStringValue(item, "code");
56378
56566
  const containerId = getStringValue(item, "container_id");
56379
56567
  const outputs = item.outputs;
56380
- const logs = Array.isArray(outputs) ? outputs.filter(isRecord5).map((output) => getStringValue(output, "logs")).filter((value) => typeof value === "string").join("\n") : "";
56568
+ const logs = Array.isArray(outputs) ? outputs.filter(isRecord6).map((output) => getStringValue(output, "logs")).filter((value) => typeof value === "string").join("\n") : "";
56381
56569
  return {
56382
56570
  ...code || containerId ? { input: { ...code ? { code } : {}, ...containerId ? { containerId } : {} } } : {},
56383
56571
  ...logs ? { output: logs } : {},
@@ -56397,7 +56585,7 @@ function providerToolResult(name15, id, status, result) {
56397
56585
  function extractProviderToolResults2(output) {
56398
56586
  const providerTools = [];
56399
56587
  for (const item of output) {
56400
- if (!isRecord5(item)) continue;
56588
+ if (!isRecord6(item)) continue;
56401
56589
  const type = getStringValue(item, "type");
56402
56590
  const id = getStringValue(item, "id");
56403
56591
  if (!type || !id) continue;
@@ -56463,6 +56651,12 @@ function transformUsage5(usage, modelId) {
56463
56651
  return transformed;
56464
56652
  }
56465
56653
  function transformResponse2(response) {
56654
+ const unusable = unusableResponseError(response);
56655
+ if (unusable) {
56656
+ throw new ProviderError(unusable.message, toProviderErrorCode(unusable.code), void 0, void 0, {
56657
+ cause: response
56658
+ });
56659
+ }
56466
56660
  const content = extractTextContent2(response.output);
56467
56661
  const { reasoning, reasoningDetails } = extractReasoningContent2(response.output);
56468
56662
  const toolCalls = extractToolCalls4(response.output);
@@ -56585,11 +56779,12 @@ function createStreamState2() {
56585
56779
  hasContent: false,
56586
56780
  hasReasoning: false,
56587
56781
  currentItemId: null,
56588
- imageIndex: 0
56782
+ imageIndex: 0,
56783
+ terminal: false
56589
56784
  };
56590
56785
  }
56591
56786
  function isCurrentReasoningDeltaEvent(event) {
56592
- return isRecord5(event) && event.type === "response.reasoning.delta" && typeof event.delta === "string";
56787
+ return isRecord6(event) && event.type === "response.reasoning.delta" && typeof event.delta === "string";
56593
56788
  }
56594
56789
  function resolveToolCallId(state, itemId) {
56595
56790
  return state.toolCallIdsByItemId.get(itemId) ?? itemId;
@@ -56600,13 +56795,13 @@ function getToolCallForItem(state, itemId) {
56600
56795
  function parseToolCallArguments2(argumentsJson) {
56601
56796
  try {
56602
56797
  const parsed = argumentsJson ? JSON.parse(argumentsJson) : {};
56603
- return isRecord5(parsed) ? parsed : {};
56798
+ return isRecord6(parsed) ? parsed : {};
56604
56799
  } catch {
56605
56800
  return {};
56606
56801
  }
56607
56802
  }
56608
56803
  function getFunctionCallItemField(event, field) {
56609
- if (!isRecord5(event) || !isRecord5(event.item)) {
56804
+ if (!isRecord6(event) || !isRecord6(event.item)) {
56610
56805
  return void 0;
56611
56806
  }
56612
56807
  const value = event.item[field];
@@ -56632,7 +56827,7 @@ function processStreamEvent2(event, state) {
56632
56827
  // Reasoning streaming
56633
56828
  case "response.reasoning_text.delta":
56634
56829
  state.hasReasoning = true;
56635
- if (isRecord5(event) && typeof event.delta === "string") {
56830
+ if (isRecord6(event) && typeof event.delta === "string") {
56636
56831
  state.reasoningContent += event.delta;
56637
56832
  chunks.push({ type: "reasoning-delta", delta: event.delta });
56638
56833
  }
@@ -56772,6 +56967,7 @@ function processStreamEvent2(event, state) {
56772
56967
  }
56773
56968
  // Response completion
56774
56969
  case "response.completed": {
56970
+ state.terminal = true;
56775
56971
  if (state.hasContent) {
56776
56972
  chunks.push({ type: "content-done" });
56777
56973
  }
@@ -56788,13 +56984,21 @@ function processStreamEvent2(event, state) {
56788
56984
  break;
56789
56985
  }
56790
56986
  case "response.failed":
56791
- chunks.push({
56792
- type: "error",
56793
- error: event.response.error?.message || "Response generation failed",
56794
- code: event.response.error?.code
56795
- });
56987
+ state.terminal = true;
56988
+ chunks.push(
56989
+ upstreamErrorChunk(
56990
+ event.response.error?.message || "Response generation failed",
56991
+ event.response.error?.code
56992
+ )
56993
+ );
56796
56994
  break;
56797
56995
  case "response.incomplete": {
56996
+ state.terminal = true;
56997
+ const unusable = state.hasContent || state.toolCalls.size > 0 ? null : unusableResponseError(event.response);
56998
+ if (unusable) {
56999
+ chunks.push(upstreamErrorChunk(unusable.message, unusable.code));
57000
+ break;
57001
+ }
56798
57002
  if (state.hasContent) {
56799
57003
  chunks.push({ type: "content-done" });
56800
57004
  }
@@ -56810,9 +57014,51 @@ function processStreamEvent2(event, state) {
56810
57014
  });
56811
57015
  break;
56812
57016
  }
57017
+ // Stream-level error event (`{ type: "error", code, message }`): the
57018
+ // upstream aborted the response. Previously ignored, which let the stream
57019
+ // end silently and read as an empty successful completion.
57020
+ case "error": {
57021
+ state.terminal = true;
57022
+ const errorEvent = event;
57023
+ chunks.push(upstreamErrorChunk(errorEvent.message || "OpenAI stream error", errorEvent.code));
57024
+ break;
57025
+ }
56813
57026
  }
56814
57027
  return chunks;
56815
57028
  }
57029
+ function upstreamErrorChunk(message, rawCode) {
57030
+ const code = toProviderErrorCode(rawCode);
57031
+ const error = rawCode && rawCode !== code ? `${message} (${rawCode})` : message;
57032
+ return { type: "error", error, code };
57033
+ }
57034
+ function unterminatedStreamError(state) {
57035
+ if (state.terminal) return null;
57036
+ return {
57037
+ type: "error",
57038
+ error: "OpenAI stream ended without a terminal response event",
57039
+ code: "server_error"
57040
+ };
57041
+ }
57042
+ function toProviderErrorCode(code) {
57043
+ switch (code) {
57044
+ case "rate_limit":
57045
+ case "rate_limit_exceeded":
57046
+ return "rate_limit";
57047
+ case "server_error":
57048
+ case "server_is_overloaded":
57049
+ case "internal_error":
57050
+ return "server_error";
57051
+ case "timeout":
57052
+ return "timeout";
57053
+ case "auth_error":
57054
+ case "invalid_api_key":
57055
+ return "auth_error";
57056
+ case "unknown":
57057
+ return "unknown";
57058
+ default:
57059
+ return "invalid_request";
57060
+ }
57061
+ }
56816
57062
  function createErrorChunk2(error, code) {
56817
57063
  return { type: "error", error, code };
56818
57064
  }
@@ -56864,7 +57110,7 @@ function normalizeIcon6(icon) {
56864
57110
  function getOpenAIIconDataUri() {
56865
57111
  return normalizeIcon6(OPENAI_ICON3);
56866
57112
  }
56867
- var DEFAULT_REASONING_LEVELS2, OPENAI_NATIVE_TOOLS, openai_default6, OPENAI_ICON3, OpenAIProvider, openaiProviderOptions, openai;
57113
+ var DEFAULT_REASONING_LEVELS2, OPENAI_NATIVE_TOOLS, ANY_OF_ANNOTATION_KEYS, openai_default6, OPENAI_ICON3, OpenAIProvider, openaiProviderOptions, openai;
56868
57114
  var init_dist7 = __esm({
56869
57115
  "../openai/dist/index.js"() {
56870
57116
  init_chunk_ESFAYEBL();
@@ -56880,6 +57126,7 @@ var init_dist7 = __esm({
56880
57126
  "code_interpreter",
56881
57127
  "file_search"
56882
57128
  ]);
57129
+ ANY_OF_ANNOTATION_KEYS = ["description", "title"];
56883
57130
  openai_default6 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" fill="none" viewBox="0 0 128 128"><g clip-path="url(%23clip0_2138_504)"><g clip-path="url(%23clip1_2138_504)"><path fill="%23000" d="M118.824 52.388a31.9 31.9 0 0 0-2.74-26.192 32.25 32.25 0 0 0-34.736-15.472A31.9 31.9 0 0 0 57.296 0C43.28-.032 30.844 8.992 26.532 22.328A31.9 31.9 0 0 0 5.208 37.796C-1.828 49.924-.224 65.212 9.176 75.612a31.9 31.9 0 0 0 2.74 26.192 32.25 32.25 0 0 0 34.736 15.472 31.88 31.88 0 0 0 24.052 10.72c14.024.036 26.464-8.996 30.776-22.344a31.9 31.9 0 0 0 21.324-15.468 32.26 32.26 0 0 0-3.976-37.804zm-48.112 67.244a23.9 23.9 0 0 1-15.356-5.552c.196-.104.536-.292.756-.428L81.6 98.932a4.14 4.14 0 0 0 2.096-3.628V59.372l10.772 6.22a.38.38 0 0 1 .208.296v29.756c-.016 13.232-10.732 23.96-23.964 23.988M19.176 97.62a23.88 23.88 0 0 1-2.86-16.072c.188.112.52.316.756.452L42.56 96.72a4.15 4.15 0 0 0 4.188 0l31.116-17.968v12.44a.4.4 0 0 1-.152.332L51.948 106.4c-11.476 6.608-26.132 2.68-32.768-8.78zm-6.708-55.636a23.9 23.9 0 0 1 12.484-10.516c0 .22-.012.608-.012.88v29.444a4.15 4.15 0 0 0 2.092 3.624L58.148 83.38 47.376 89.6a.38.38 0 0 1-.364.032L21.244 74.744c-11.452-6.632-15.38-21.284-8.78-32.756zm88.504 20.596L69.856 44.612l10.772-6.216a.38.38 0 0 1 .364-.032L106.76 53.24c11.472 6.628 15.404 21.304 8.776 32.776a23.98 23.98 0 0 1-12.48 10.512V66.204a4.14 4.14 0 0 0-2.08-3.624zm10.72-16.136c-.188-.116-.52-.316-.756-.452l-25.488-14.72a4.15 4.15 0 0 0-4.188 0L50.144 49.24V36.8a.4.4 0 0 1 .152-.332L76.06 21.604c11.476-6.62 26.148-2.68 32.764 8.8a23.98 23.98 0 0 1 2.86 16.04zM44.288 68.616l-10.776-6.22a.38.38 0 0 1-.208-.296V32.344C33.312 19.096 44.06 8.36 57.308 8.368a23.98 23.98 0 0 1 15.336 5.552c-.196.104-.532.292-.756.428L46.4 29.068a4.14 4.14 0 0 0-2.096 3.624l-.016 35.916zM50.14 56 64 47.996l13.86 8V72L64 80l-13.86-8z"/></g></g><defs><clipPath id="clip0_2138_504"><path fill="%23fff" d="M0 0h128v128H0z"/></clipPath><clipPath id="clip1_2138_504"><path fill="%23fff" d="M0 0h128v128H0z"/></clipPath></defs></svg>';
56884
57131
  OPENAI_ICON3 = openai_default6;
56885
57132
  OpenAIProvider = class _OpenAIProvider {
@@ -57343,6 +57590,8 @@ var init_dist7 = __esm({
57343
57590
  yield chunk;
57344
57591
  }
57345
57592
  }
57593
+ const unterminated = request.signal?.aborted ? null : unterminatedStreamError(state);
57594
+ if (unterminated) yield unterminated;
57346
57595
  } catch (error) {
57347
57596
  const providerError = self.toProviderError(error);
57348
57597
  yield createErrorChunk2(providerError.message, providerError.code);
@@ -58735,24 +58984,24 @@ var init_claude_constants = __esm({
58735
58984
  });
58736
58985
 
58737
58986
  // ../../node_modules/.pnpm/@openrouter+sdk@0.3.12/node_modules/@openrouter/sdk/esm/lib/claude-type-guards.js
58738
- function isRecord6(value) {
58987
+ function isRecord7(value) {
58739
58988
  return value !== null && typeof value === "object" && !Array.isArray(value);
58740
58989
  }
58741
58990
  function isNonClaudeRole(role) {
58742
58991
  return role === NonClaudeMessageRole.System || role === NonClaudeMessageRole.Developer || role === NonClaudeMessageRole.Tool;
58743
58992
  }
58744
58993
  function isClaudeToolResultBlock(block) {
58745
- if (!isRecord6(block))
58994
+ if (!isRecord7(block))
58746
58995
  return false;
58747
58996
  return block["type"] === ClaudeContentBlockType.ToolResult;
58748
58997
  }
58749
58998
  function isClaudeImageBlockWithSource(block) {
58750
- if (!isRecord6(block))
58999
+ if (!isRecord7(block))
58751
59000
  return false;
58752
- return block["type"] === ClaudeContentBlockType.Image && "source" in block && isRecord6(block["source"]);
59001
+ return block["type"] === ClaudeContentBlockType.Image && "source" in block && isRecord7(block["source"]);
58753
59002
  }
58754
59003
  function isClaudeToolUseBlockWithId(block) {
58755
- if (!isRecord6(block))
59004
+ if (!isRecord7(block))
58756
59005
  return false;
58757
59006
  return block["type"] === ClaudeContentBlockType.ToolUse && "id" in block && typeof block["id"] === "string";
58758
59007
  }
@@ -58772,7 +59021,7 @@ function isClaudeStyleMessages(input) {
58772
59021
  return false;
58773
59022
  }
58774
59023
  for (const msg of input) {
58775
- if (!isRecord6(msg))
59024
+ if (!isRecord7(msg))
58776
59025
  continue;
58777
59026
  if (!("role" in msg))
58778
59027
  continue;
@@ -59085,7 +59334,7 @@ var init_http = __esm({
59085
59334
  });
59086
59335
 
59087
59336
  // ../../node_modules/.pnpm/@openrouter+sdk@0.3.12/node_modules/@openrouter/sdk/esm/lib/next-turn-params.js
59088
- function isRecord7(value) {
59337
+ function isRecord8(value) {
59089
59338
  return typeof value === "object" && value !== null && !Array.isArray(value);
59090
59339
  }
59091
59340
  function buildNextTurnParamsContext(request) {
@@ -59111,7 +59360,7 @@ async function executeNextTurnParamsFunctions(toolCalls, tools, currentRequest)
59111
59360
  const callsForTool = toolCalls.filter((tc) => tc.name === tool3.function.name);
59112
59361
  for (const call of callsForTool) {
59113
59362
  const nextParams = tool3.function.nextTurnParams;
59114
- if (!isRecord7(call.arguments)) {
59363
+ if (!isRecord8(call.arguments)) {
59115
59364
  const typeStr = Array.isArray(call.arguments) ? "array" : typeof call.arguments;
59116
59365
  throw new Error(`Tool call arguments for ${tool3.function.name} must be an object, got ${typeStr}`);
59117
59366
  }
@@ -69730,7 +69979,7 @@ function isOpenRouterServerTool(value) {
69730
69979
  function isOpenRouterProviderTool(tool3) {
69731
69980
  return tool3.executionMode === "provider" && tool3.executionProvider === "openrouter" && isOpenRouterServerToolName(tool3.function.name);
69732
69981
  }
69733
- function isRecord8(value) {
69982
+ function isRecord9(value) {
69734
69983
  return !!value && typeof value === "object" && !Array.isArray(value);
69735
69984
  }
69736
69985
  function readNumber(value) {
@@ -69738,9 +69987,9 @@ function readNumber(value) {
69738
69987
  }
69739
69988
  function getServerToolParameters(providerOptions, toolName) {
69740
69989
  const rawConfig = providerOptions?.serverTools ?? providerOptions?.server_tools;
69741
- if (!isRecord8(rawConfig)) return void 0;
69990
+ if (!isRecord9(rawConfig)) return void 0;
69742
69991
  const rawParameters = rawConfig[toolName];
69743
- if (!isRecord8(rawParameters) || Object.keys(rawParameters).length === 0) {
69992
+ if (!isRecord9(rawParameters) || Object.keys(rawParameters).length === 0) {
69744
69993
  return void 0;
69745
69994
  }
69746
69995
  return rawParameters;
@@ -69767,9 +70016,9 @@ function serverToolNameFromUsageKey(key) {
69767
70016
  return isOpenRouterServerToolName(name15) ? name15 : void 0;
69768
70017
  }
69769
70018
  function extractServerToolUse(usage) {
69770
- if (!isRecord8(usage)) return void 0;
70019
+ if (!isRecord9(usage)) return void 0;
69771
70020
  const raw = usage.server_tool_use ?? usage.serverToolUse;
69772
- return isRecord8(raw) ? raw : void 0;
70021
+ return isRecord9(raw) ? raw : void 0;
69773
70022
  }
69774
70023
  function providerToolResultsFromServerToolUse(usage) {
69775
70024
  const serverToolUse = extractServerToolUse(usage);
@@ -69800,9 +70049,9 @@ function extractWebSearchCitations(value) {
69800
70049
  if (!Array.isArray(value)) return [];
69801
70050
  const citations = [];
69802
70051
  for (const annotation of value) {
69803
- if (!isRecord8(annotation)) continue;
70052
+ if (!isRecord9(annotation)) continue;
69804
70053
  const rawCitation = annotation.url_citation ?? annotation.urlCitation;
69805
- if (!isRecord8(rawCitation)) continue;
70054
+ if (!isRecord9(rawCitation)) continue;
69806
70055
  const url = rawCitation.url;
69807
70056
  if (typeof url !== "string" || url.length === 0) continue;
69808
70057
  citations.push({
@@ -70063,8 +70312,8 @@ function normalizeStrictJsonSchema4(schema) {
70063
70312
  }
70064
70313
  const properties = isRecord22(normalized.properties) ? normalized.properties : void 0;
70065
70314
  const type = normalized.type;
70066
- const isObjectSchema = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
70067
- if (isObjectSchema) {
70315
+ const isObjectSchema2 = type === "object" || Array.isArray(type) && type.includes("object") || !!properties;
70316
+ if (isObjectSchema2) {
70068
70317
  if (normalized.type === void 0) {
70069
70318
  normalized.type = "object";
70070
70319
  }
@@ -80197,7 +80446,7 @@ var config_get_default = defineController2(async ({ config, env: env2, req }) =>
80197
80446
  });
80198
80447
 
80199
80448
  // src/version.ts
80200
- var BUILDER_VERSION = "0.41.22".length > 0 ? "0.41.22" : "dev";
80449
+ var BUILDER_VERSION = "0.41.26".length > 0 ? "0.41.26" : "dev";
80201
80450
 
80202
80451
  // src/api/diagnostics.get.ts
80203
80452
  init_LLMRequest();
@@ -85313,6 +85562,7 @@ var continue_post_default = defineController2(async ({ req, params, env: env2 })
85313
85562
  function emptyCostSummary() {
85314
85563
  return {
85315
85564
  totalCost: 0,
85565
+ appCost: 0,
85316
85566
  inputCost: 0,
85317
85567
  cachedCost: 0,
85318
85568
  outputCost: 0,
@@ -85347,6 +85597,7 @@ function mergeByModel(summaries) {
85347
85597
  }
85348
85598
  function sumSummaries(summaries) {
85349
85599
  let totalCost = 0;
85600
+ let appCost = 0;
85350
85601
  let inputCost = 0;
85351
85602
  let cachedCost = 0;
85352
85603
  let outputCost = 0;
@@ -85355,6 +85606,7 @@ function sumSummaries(summaries) {
85355
85606
  let messageCount = 0;
85356
85607
  for (const summary of summaries) {
85357
85608
  totalCost += summary.totalCost;
85609
+ appCost += summary.appCost ?? 0;
85358
85610
  inputCost += summary.inputCost ?? 0;
85359
85611
  cachedCost += summary.cachedCost ?? 0;
85360
85612
  outputCost += summary.outputCost ?? 0;
@@ -85362,7 +85614,7 @@ function sumSummaries(summaries) {
85362
85614
  requestCount += summary.requestCount;
85363
85615
  messageCount += summary.messageCount;
85364
85616
  }
85365
- return { totalCost, inputCost, cachedCost, outputCost, routerFeeCost, requestCount, messageCount };
85617
+ return { totalCost, appCost, inputCost, cachedCost, outputCost, routerFeeCost, requestCount, messageCount };
85366
85618
  }
85367
85619
  function buildModelBreakdown(byModel) {
85368
85620
  return Object.entries(byModel).map(([modelName, acc]) => ({
@@ -85376,6 +85628,28 @@ function buildModelBreakdown(byModel) {
85376
85628
  avgCostPerRequest: acc.count > 0 ? acc.totalCost / acc.count : 0
85377
85629
  })).sort((a, b) => b.totalCost - a.totalCost);
85378
85630
  }
85631
+ function threadCostRow(thread, summary, isRoot) {
85632
+ return {
85633
+ threadId: thread.id,
85634
+ agentName: thread.agent_name ?? null,
85635
+ threadName: threadNameFromTags(thread.tags),
85636
+ parent: isRoot ? null : thread.parent,
85637
+ isRoot,
85638
+ totalCost: summary?.totalCost ?? 0,
85639
+ appCost: summary?.appCost ?? 0,
85640
+ inputCost: summary?.inputCost ?? 0,
85641
+ cachedCost: summary?.cachedCost ?? 0,
85642
+ outputCost: summary?.outputCost ?? 0,
85643
+ routerFeeCost: summary?.routerFeeCost ?? 0,
85644
+ requestCount: summary?.requestCount ?? 0
85645
+ };
85646
+ }
85647
+ function buildThreadCostRows(root, rootSummary, descendants, descendantSummaries) {
85648
+ return [
85649
+ threadCostRow(root, rootSummary, true),
85650
+ ...descendants.map((child, index) => threadCostRow(child, descendantSummaries[index], false)).filter((row) => row.requestCount > 0 || row.totalCost > 0)
85651
+ ];
85652
+ }
85379
85653
  function threadNameFromTags(tags) {
85380
85654
  for (const tag of tags ?? []) {
85381
85655
  if (typeof tag === "string" && tag.startsWith("name:")) {
@@ -85438,36 +85712,15 @@ var cost_get_default = defineController2(async ({ req, params, env: env2 }) => {
85438
85712
  messageCount: entry.requestCount
85439
85713
  };
85440
85714
  }
85441
- const threads = [
85442
- {
85443
- threadId,
85444
- agentName: thread.agent_name ?? null,
85445
- threadName: threadNameFromTags(thread.tags),
85446
- parent: null,
85447
- isRoot: true,
85448
- totalCost: ownSummary.totalCost,
85449
- inputCost: ownSummary.inputCost ?? 0,
85450
- cachedCost: ownSummary.cachedCost ?? 0,
85451
- outputCost: ownSummary.outputCost ?? 0,
85452
- routerFeeCost: ownSummary.routerFeeCost ?? 0,
85453
- requestCount: ownSummary.requestCount
85454
- },
85455
- ...descendants.map((child, index) => ({
85456
- threadId: child.id,
85457
- agentName: child.agent_name ?? null,
85458
- threadName: threadNameFromTags(child.tags),
85459
- parent: child.parent,
85460
- isRoot: false,
85461
- totalCost: descendantSummaries[index]?.totalCost ?? 0,
85462
- inputCost: descendantSummaries[index]?.inputCost ?? 0,
85463
- cachedCost: descendantSummaries[index]?.cachedCost ?? 0,
85464
- outputCost: descendantSummaries[index]?.outputCost ?? 0,
85465
- routerFeeCost: descendantSummaries[index]?.routerFeeCost ?? 0,
85466
- requestCount: descendantSummaries[index]?.requestCount ?? 0
85467
- })).filter((row) => row.requestCount > 0)
85468
- ];
85715
+ const threads = buildThreadCostRows(
85716
+ { id: threadId, agent_name: thread.agent_name, parent: null, tags: thread.tags },
85717
+ ownSummary,
85718
+ descendants,
85719
+ descendantSummaries
85720
+ );
85469
85721
  return Response.json({
85470
85722
  totalCost: totals.totalCost,
85723
+ appCost: totals.appCost,
85471
85724
  inputCost: totals.inputCost,
85472
85725
  cachedCost: totals.cachedCost,
85473
85726
  outputCost: totals.outputCost,