@standardagents/builder 0.24.6 → 0.25.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 (43) hide show
  1. package/dist/built-in-routes.js +3220 -1984
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-CmZKVcOR.js → ApiKeysView-C_QyBNy2.js} +1 -1
  4. package/dist/client/{CenteredContentView-DK7rPUK2.js → CenteredContentView-c7OLhxvd.js} +1 -1
  5. package/dist/client/CompositionView-DqKI6dJ9.js +32 -0
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-h7YuRPAr.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-DQIo2wlE.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-BpQ6CMUp.js → CopyButton.vue_vue_type_script_setup_true_lang-q-A7DQTq.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-DCUZbvUM.js → DataTable.vue_vue_type_script_setup_true_lang-B0UNyBiO.js} +1 -1
  9. package/dist/client/{JsonViewer-CvwfQYW-.js → JsonViewer-DrA7M9_g.js} +1 -1
  10. package/dist/client/{LoginView-DnaG5knS.js → LoginView-BxbNgfzz.js} +1 -1
  11. package/dist/client/{MarketplaceView-fX_Juw54.js → MarketplaceView-DXrtN6-0.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-CFFVfl1g.js → Modal.vue_vue_type_script_setup_true_lang-CLZzFYMW.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-B68s7Jo1.js → ModelModal.vue_vue_type_script_setup_true_lang-BaLZApRs.js} +1 -1
  14. package/dist/client/{ModelsView-lv4-IyA2.js → ModelsView-CVtPgAVZ.js} +1 -1
  15. package/dist/client/{PromptEditView-DGaxlMMx.js → PromptEditView-Dhc0rBHD.js} +1 -1
  16. package/dist/client/{PromptModal-DaW1J_W6.js → PromptModal-DXt6M359.js} +1 -1
  17. package/dist/client/{PromptsView-CdiBqZey.js → PromptsView-y3yvzkjM.js} +1 -1
  18. package/dist/client/{ProvidersView-B37bgFKh.js → ProvidersView-DN-SmDPF.js} +1 -1
  19. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-lIW3rtYB.js +22 -0
  20. package/dist/client/ThreadsView-B1Xo2bP0.js +1 -0
  21. package/dist/client/{ToolsView-BMKgNq7O.js → ToolsView-DYj_Mk9L.js} +1 -1
  22. package/dist/client/{UsersView-BDKchqNQ.js → UsersView-BLNNFDUM.js} +1 -1
  23. package/dist/client/{VariablesView-BPioaCbu.js → VariablesView-D4-5tNwt.js} +1 -1
  24. package/dist/client/assets/{ThreadInspectorPane-lJJckks4.css → ThreadInspectorPane-CGrBd6US.css} +1 -1
  25. package/dist/client/assets/index-B38KmIlM.css +1 -0
  26. package/dist/client/{index-BVfRoUms.js → index-0OxNDXyK.js} +2 -2
  27. package/dist/client/index.html +2 -2
  28. package/dist/{index-D3FNNQWC.d.ts → index-BsS0cHzL.d.ts} +12 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +184 -35
  31. package/dist/index.js.map +1 -1
  32. package/dist/plugin.d.ts +1 -1
  33. package/dist/plugin.js +8 -0
  34. package/dist/plugin.js.map +1 -1
  35. package/dist/runtime.d.ts +12 -2
  36. package/dist/runtime.js +176 -35
  37. package/dist/runtime.js.map +1 -1
  38. package/dist/test.d.ts +1 -1
  39. package/package.json +5 -5
  40. package/dist/client/CompositionView-BvVMnyYP.js +0 -32
  41. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DHlNdv7o.js +0 -22
  42. package/dist/client/ThreadsView-BAfuNShv.js +0 -1
  43. package/dist/client/assets/index-Djjx6d3k.css +0 -1
package/dist/runtime.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-D3FNNQWC.js';
2
- export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-D3FNNQWC.js';
1
+ import { e as ThreadEnv, A as Agent, h as ThreadMetadata, i as ToolResult, M as Message, l as FileRecord, F as FlowState, n as FileStats, G as GrepResult, m as AttachmentRef, r as MessageContent, E as Env, g as ThreadInstance } from './index-BsS0cHzL.js';
2
+ export { f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, j as FlowResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, T as ToolCall, c as createThreadEndpointHandler, d as defineController } from './index-BsS0cHzL.js';
3
3
  import { CodeExecutionOptions, CodeExecutionResult, SubagentRegistryEntry, InjectMessageInput, QueueMessageInput, ClientToolRequest, ClientToolResponse, SkillMetadata, SkillFileInput, ModelDefinition as ModelDefinition$1, ToolArgs, PromptTextPart, PromptEnvPart, VariableDefinition, SubpromptConfig as SubpromptConfig$1, PromptToolConfig as PromptToolConfig$1, SubagentToolConfig as SubagentToolConfig$1, ReasoningConfig, SideConfig as SideConfig$1, LLMProviderInterface, ContentPart, TextPart, ImagePart, FilePart, NamespaceContext, DefinitionLoader } from '@standardagents/spec';
4
4
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ModelCapabilities as ProviderModelCapabilities, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel } from '@standardagents/spec';
5
5
  import { DurableObject, WorkerEntrypoint } from 'cloudflare:workers';
@@ -759,6 +759,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
759
759
  inputCost: number;
760
760
  cachedCost: number;
761
761
  outputCost: number;
762
+ routerFeeCost: number;
762
763
  requestCount: number;
763
764
  messageCount: number;
764
765
  byModel: Record<string, {
@@ -766,6 +767,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
766
767
  inputCost: number;
767
768
  cachedCost: number;
768
769
  outputCost: number;
770
+ routerFeeCost: number;
769
771
  count: number;
770
772
  }>;
771
773
  }>;
@@ -855,6 +857,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
855
857
  cost_input: number | null;
856
858
  cost_cached: number | null;
857
859
  cost_output: number | null;
860
+ cost_router_fee: number | null;
861
+ router_fee_percent: number | null;
858
862
  cost_total: number | null;
859
863
  message_history_length: number | null;
860
864
  tools_available: number | null;
@@ -3312,6 +3316,12 @@ interface ProviderLookupResult {
3312
3316
  modelDef: ModelDefinition$1<string>;
3313
3317
  /** True when requests route through the Standard Agents platform (hosted routing or a registered override). */
3314
3318
  viaPlatform: boolean;
3319
+ /**
3320
+ * Platform origin serving the passthrough proxy when built-in hosted routing
3321
+ * is active. Lets request logging look up the router-fee percent observed on
3322
+ * this origin's proxied responses.
3323
+ */
3324
+ platformProxyOrigin?: string;
3315
3325
  }
3316
3326
  /**
3317
3327
  * Provider registry implementation
package/dist/runtime.js CHANGED
@@ -234,6 +234,12 @@ function resolveModelPricing(modelDef, providerName) {
234
234
  }
235
235
  return null;
236
236
  }
237
+ function calculateRouterFee(rawCost, feePercent) {
238
+ if (!(rawCost > 0) || !(feePercent > 0)) {
239
+ return 0;
240
+ }
241
+ return roundCost(rawCost * feePercent / 100);
242
+ }
237
243
  function calculateUsageCost(usage, pricing) {
238
244
  if (!pricing) {
239
245
  return null;
@@ -264,6 +270,66 @@ var init_pricing = __esm({
264
270
  TOKENS_PER_MILLION = 1e6;
265
271
  }
266
272
  });
273
+
274
+ // src/agents/providers/router-fee.ts
275
+ function requestUrl(input) {
276
+ if (typeof input === "string") return input;
277
+ if (input instanceof URL) return input.toString();
278
+ if (typeof input === "object" && input !== null && typeof input.url === "string") {
279
+ return input.url;
280
+ }
281
+ return null;
282
+ }
283
+ function observeResponse(url, headers) {
284
+ if (!url) return;
285
+ for (const origin of registeredOrigins) {
286
+ if (!url.startsWith(`${origin}/v1/proxy/`)) continue;
287
+ const raw = headers.get(ROUTER_FEE_HEADER);
288
+ if (raw !== null) {
289
+ const percent = Number(raw);
290
+ if (Number.isFinite(percent) && percent >= 0) {
291
+ observedFeePercentByOrigin.set(origin, percent);
292
+ }
293
+ }
294
+ return;
295
+ }
296
+ }
297
+ function installObserver() {
298
+ if (observerInstalled) return;
299
+ const original = globalThis.fetch;
300
+ if (typeof original !== "function") return;
301
+ const bound = original.bind(globalThis);
302
+ const wrapped = async (input, init) => {
303
+ const response = await bound(input, init);
304
+ try {
305
+ observeResponse(requestUrl(input), response.headers);
306
+ } catch {
307
+ }
308
+ return response;
309
+ };
310
+ try {
311
+ globalThis.fetch = wrapped;
312
+ observerInstalled = true;
313
+ } catch {
314
+ }
315
+ }
316
+ function registerPlatformProxyOrigin(origin) {
317
+ if (!origin) return;
318
+ registeredOrigins.add(origin.replace(/\/+$/, ""));
319
+ installObserver();
320
+ }
321
+ function getObservedRouterFeePercent(origin) {
322
+ return observedFeePercentByOrigin.get(origin.replace(/\/+$/, "")) ?? null;
323
+ }
324
+ var ROUTER_FEE_HEADER, registeredOrigins, observedFeePercentByOrigin, observerInstalled;
325
+ var init_router_fee = __esm({
326
+ "src/agents/providers/router-fee.ts"() {
327
+ ROUTER_FEE_HEADER = "X-Standard-Agents-Router-Fee-Percent";
328
+ registeredOrigins = /* @__PURE__ */ new Set();
329
+ observedFeePercentByOrigin = /* @__PURE__ */ new Map();
330
+ observerInstalled = false;
331
+ }
332
+ });
267
333
  async function readCompletedArg(partialJson, argName) {
268
334
  if (!partialJson || !argName) return void 0;
269
335
  try {
@@ -814,6 +880,7 @@ var init_ProviderRegistry = __esm({
814
880
  "src/agents/providers/ProviderRegistry.ts"() {
815
881
  init_TestProvider();
816
882
  init_platform_routing();
883
+ init_router_fee();
817
884
  init_factory();
818
885
  ProviderRegistryImpl = class {
819
886
  providerCache = /* @__PURE__ */ new Map();
@@ -908,21 +975,22 @@ var init_ProviderRegistry = __esm({
908
975
  apiKey: routing.apiKey,
909
976
  baseUrl: routing.baseUrl
910
977
  };
978
+ registerPlatformProxyOrigin(routing.origin);
911
979
  const fingerprint = this.getProviderFingerprint(`platform:${providerName}`, modelDef, config);
912
980
  const cached = this.providerCache.get(modelName);
913
981
  if (cached?.fingerprint === fingerprint) {
914
- return this.buildResult(cached.provider, modelDef, true);
982
+ return this.buildResult(cached.provider, modelDef, true, routing.origin);
915
983
  }
916
- return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true);
984
+ return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true, routing.origin);
917
985
  }
918
986
  throw new Error(`No API key found for provider: ${providerName}. Set the provider key or STANDARD_AGENTS_API_KEY.`);
919
987
  }
920
- buildResult(provider, modelDef, viaPlatform) {
921
- return { provider, modelName: modelDef.model, modelDef, viaPlatform };
988
+ buildResult(provider, modelDef, viaPlatform, platformProxyOrigin) {
989
+ return { provider, modelName: modelDef.model, modelDef, viaPlatform, platformProxyOrigin };
922
990
  }
923
- cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform) {
991
+ cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform, platformProxyOrigin) {
924
992
  this.providerCache.set(modelName, { provider, fingerprint, viaPlatform });
925
- return this.buildResult(provider, modelDef, viaPlatform);
993
+ return this.buildResult(provider, modelDef, viaPlatform, platformProxyOrigin);
926
994
  }
927
995
  getProviderFingerprint(providerName, modelDef, config) {
928
996
  return JSON.stringify({
@@ -941,6 +1009,7 @@ var init_ProviderRegistry = __esm({
941
1009
  cerebras: "CEREBRAS_API_KEY",
942
1010
  google: "GOOGLE_API_KEY",
943
1011
  groq: "GROQ_API_KEY",
1012
+ novita: "NOVITA_API_KEY",
944
1013
  openai: "OPENAI_API_KEY",
945
1014
  openrouter: "OPENROUTER_API_KEY",
946
1015
  anthropic: "ANTHROPIC_API_KEY",
@@ -1386,6 +1455,7 @@ var NON_VISION_PLACEHOLDER_TEXT, STREAM_FIRST_CHUNK_TIMEOUT_MS, STREAM_STALL_TIM
1386
1455
  var init_LLMRequest = __esm({
1387
1456
  "src/agents/LLMRequest.ts"() {
1388
1457
  init_pricing();
1458
+ init_router_fee();
1389
1459
  init_types();
1390
1460
  init_FlowEngine();
1391
1461
  init_toolProgress();
@@ -1649,11 +1719,7 @@ var init_LLMRequest = __esm({
1649
1719
  */
1650
1720
  static async callModel(modelId, context, state, logId) {
1651
1721
  const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
1652
- const { provider, modelName, modelDef, viaPlatform } = await ProviderRegistry2.getProvider(
1653
- modelId,
1654
- state.env,
1655
- state.thread.instance
1656
- );
1722
+ const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, state.env, state.thread.instance);
1657
1723
  const streamAbort = new AbortController();
1658
1724
  const parentSignal = state.abortController?.signal;
1659
1725
  let onParentAbort;
@@ -1932,6 +1998,12 @@ var init_LLMRequest = __esm({
1932
1998
  };
1933
1999
  response._provider = provider;
1934
2000
  response._viaPlatform = viaPlatform;
2001
+ if (platformProxyOrigin) {
2002
+ const feePercent = getObservedRouterFeePercent(platformProxyOrigin);
2003
+ if (feePercent !== null) {
2004
+ response._routerFeePercent = feePercent;
2005
+ }
2006
+ }
1935
2007
  response._providerResponseId = providerResponseId;
1936
2008
  response._timing = {
1937
2009
  latencyMs: firstChunkAt > 0 ? firstChunkAt - requestSentAt : null,
@@ -2060,7 +2132,10 @@ var init_LLMRequest = __esm({
2060
2132
  const resolvedPricing = resolveModelPricing(modelDef) ?? resolveUsageReportedPricing(response.usage) ?? resolveModelPricing(modelDef, providerName);
2061
2133
  const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
2062
2134
  const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
2063
- const cost_total = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
2135
+ const rawProviderCost = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
2136
+ const routerFeePercent = standardAgentsRouterUsed && typeof response._routerFeePercent === "number" && response._routerFeePercent > 0 ? response._routerFeePercent : null;
2137
+ const costRouterFee = routerFeePercent !== null && rawProviderCost !== null ? calculateRouterFee(rawProviderCost, routerFeePercent) : null;
2138
+ const cost_total = rawProviderCost !== null && costRouterFee !== null && costRouterFee > 0 ? roundCost(rawProviderCost + costRouterFee) : rawProviderCost;
2064
2139
  const actualProvider = normalizeProviderMetadataValue(response.usage.provider) ?? null;
2065
2140
  const aggregateResponse = response._aggregate_response;
2066
2141
  const responseBody = aggregateResponse ? JSON.stringify(aggregateResponse) : JSON.stringify(response);
@@ -2126,6 +2201,8 @@ var init_LLMRequest = __esm({
2126
2201
  cost_input: calculatedCost?.costInput,
2127
2202
  cost_cached: calculatedCost?.costCached,
2128
2203
  cost_output: calculatedCost?.costOutput,
2204
+ cost_router_fee: costRouterFee ?? void 0,
2205
+ router_fee_percent: routerFeePercent ?? void 0,
2129
2206
  latency_ms: Date.now() - startTime,
2130
2207
  time_to_first_token_ms: timing?.latencyMs ?? void 0,
2131
2208
  generation_ms: timing?.generationMs ?? void 0,
@@ -2166,8 +2243,10 @@ var init_LLMRequest = __esm({
2166
2243
  actual_provider = ?17,
2167
2244
  standard_agents_router_used = ?18,
2168
2245
  time_to_first_token_ms = ?19,
2169
- generation_ms = ?20
2170
- WHERE id = ?21
2246
+ generation_ms = ?20,
2247
+ cost_router_fee = ?21,
2248
+ router_fee_percent = ?22
2249
+ WHERE id = ?23
2171
2250
  `,
2172
2251
  logData.response_body,
2173
2252
  logData.input_tokens,
@@ -2189,6 +2268,8 @@ var init_LLMRequest = __esm({
2189
2268
  standardAgentsRouterUsed ? 1 : 0,
2190
2269
  logData.time_to_first_token_ms ?? null,
2191
2270
  logData.generation_ms ?? null,
2271
+ logData.cost_router_fee ?? null,
2272
+ logData.router_fee_percent ?? null,
2192
2273
  logId
2193
2274
  );
2194
2275
  }
@@ -2527,9 +2608,24 @@ ${errorStack}` : ""}${errorDetails}`;
2527
2608
  updates.push(`actual_provider = ?${paramIndex++}`);
2528
2609
  values.push(actualProvider);
2529
2610
  }
2611
+ let updatedCostTotal;
2612
+ let updatedRouterFee;
2530
2613
  if (metadata.generation_cost !== void 0) {
2614
+ updatedCostTotal = metadata.generation_cost;
2615
+ const rawCost = typeof metadata.generation_cost === "number" ? metadata.generation_cost : Number(metadata.generation_cost);
2616
+ if (Number.isFinite(rawCost)) {
2617
+ const feePercent = await this.readRouterFeePercent(state, logId);
2618
+ if (feePercent !== null && feePercent > 0) {
2619
+ updatedRouterFee = calculateRouterFee(rawCost, feePercent);
2620
+ updatedCostTotal = roundCost(rawCost + updatedRouterFee);
2621
+ }
2622
+ }
2531
2623
  updates.push(`cost_total = ?${paramIndex++}`);
2532
- values.push(metadata.generation_cost);
2624
+ values.push(updatedCostTotal);
2625
+ if (updatedRouterFee !== void 0) {
2626
+ updates.push(`cost_router_fee = ?${paramIndex++}`);
2627
+ values.push(updatedRouterFee);
2628
+ }
2533
2629
  }
2534
2630
  if (updates.length === 0) {
2535
2631
  return;
@@ -2544,7 +2640,8 @@ ${errorStack}` : ""}${errorDetails}`;
2544
2640
  data: {
2545
2641
  id: logId,
2546
2642
  ...actualProvider !== void 0 && { actual_provider: actualProvider },
2547
- ...metadata.generation_cost !== void 0 && { cost_total: metadata.generation_cost }
2643
+ ...metadata.generation_cost !== void 0 && { cost_total: updatedCostTotal },
2644
+ ...updatedRouterFee !== void 0 && { cost_router_fee: updatedRouterFee }
2548
2645
  }
2549
2646
  });
2550
2647
  }
@@ -2552,6 +2649,23 @@ ${errorStack}` : ""}${errorDetails}`;
2552
2649
  console.error("Failed to update log with metadata (non-fatal):", error);
2553
2650
  }
2554
2651
  }
2652
+ /**
2653
+ * Router-fee percent recorded on a log row by logSuccess, or null when the
2654
+ * row has none (BYOK) or the storage shape doesn't expose it.
2655
+ */
2656
+ static async readRouterFeePercent(state, logId) {
2657
+ try {
2658
+ const cursor = await state.storage.sql.exec(
2659
+ `SELECT router_fee_percent FROM logs WHERE id = ?`,
2660
+ logId
2661
+ );
2662
+ const row = cursor?.toArray?.()[0];
2663
+ const percent = row?.router_fee_percent;
2664
+ return typeof percent === "number" && Number.isFinite(percent) ? percent : null;
2665
+ } catch {
2666
+ return null;
2667
+ }
2668
+ }
2555
2669
  };
2556
2670
  }
2557
2671
  });
@@ -14702,8 +14816,28 @@ var migration32 = {
14702
14816
  }
14703
14817
  };
14704
14818
 
14819
+ // src/durable-objects/migrations/033_add_router_fee.ts
14820
+ var migration33 = {
14821
+ version: 33,
14822
+ name: "add_router_fee",
14823
+ async up(sql) {
14824
+ const tableInfo = sql.exec(`PRAGMA table_info(logs)`).toArray();
14825
+ const hasColumn = (name) => tableInfo.some((col) => col.name === name);
14826
+ if (!hasColumn("cost_router_fee")) {
14827
+ await sql.exec(`
14828
+ ALTER TABLE logs ADD COLUMN cost_router_fee REAL;
14829
+ `);
14830
+ }
14831
+ if (!hasColumn("router_fee_percent")) {
14832
+ await sql.exec(`
14833
+ ALTER TABLE logs ADD COLUMN router_fee_percent REAL;
14834
+ `);
14835
+ }
14836
+ }
14837
+ };
14838
+
14705
14839
  // src/durable-objects/migrations/index.ts
14706
- var migrations = [migration, migration2, migration3, migration4, migration5, migration6, migration7, migration8, migration9, migration10, migration11, migration12, migration13, migration14, migration15, migration16, migration17, migration18, migration19, migration20, migration21, migration22, migration23, migration24, migration25, migration26, migration27, migration28, migration29, migration30, migration31, migration32];
14840
+ var migrations = [migration, migration2, migration3, migration4, migration5, migration6, migration7, migration8, migration9, migration10, migration11, migration12, migration13, migration14, migration15, migration16, migration17, migration18, migration19, migration20, migration21, migration22, migration23, migration24, migration25, migration26, migration27, migration28, migration29, migration30, migration31, migration32, migration33];
14707
14841
  var LATEST_SCHEMA_VERSION = migrations.length;
14708
14842
 
14709
14843
  // src/durable-objects/DurableThread.ts
@@ -16822,9 +16956,9 @@ var DurableThread = class _DurableThread extends DurableObject {
16822
16956
  * Each migration is run in order, starting from the current version + 1.
16823
16957
  */
16824
16958
  async runMigrations(fromVersion) {
16825
- for (const migration43 of migrations) {
16826
- if (migration43.version > fromVersion) {
16827
- await migration43.up(this.ctx.storage.sql);
16959
+ for (const migration44 of migrations) {
16960
+ if (migration44.version > fromVersion) {
16961
+ await migration44.up(this.ctx.storage.sql);
16828
16962
  }
16829
16963
  }
16830
16964
  }
@@ -18311,6 +18445,7 @@ ${resultContent}${attachmentSummary}`;
18311
18445
  let inputCost = 0;
18312
18446
  let cachedCost = 0;
18313
18447
  let outputCost = 0;
18448
+ let routerFeeCost = 0;
18314
18449
  let requestCount = 0;
18315
18450
  const modelRows = await this.ctx.storage.sql.exec(
18316
18451
  `
@@ -18319,6 +18454,7 @@ ${resultContent}${attachmentSummary}`;
18319
18454
  SUM(CASE WHEN cost_cached IS NOT NULL THEN cost_input END) AS input_cost,
18320
18455
  SUM(cost_cached) AS cached_cost,
18321
18456
  SUM(cost_output) AS output_cost,
18457
+ SUM(cost_router_fee) AS router_fee_cost,
18322
18458
  COUNT(*) AS request_count
18323
18459
  FROM logs
18324
18460
  WHERE cost_total IS NOT NULL
@@ -18331,12 +18467,14 @@ ${resultContent}${attachmentSummary}`;
18331
18467
  inputCost: row.input_cost ?? 0,
18332
18468
  cachedCost: row.cached_cost ?? 0,
18333
18469
  outputCost: row.output_cost ?? 0,
18470
+ routerFeeCost: row.router_fee_cost ?? 0,
18334
18471
  count: row.request_count
18335
18472
  };
18336
18473
  totalCost += row.total_cost;
18337
18474
  inputCost += row.input_cost ?? 0;
18338
18475
  cachedCost += row.cached_cost ?? 0;
18339
18476
  outputCost += row.output_cost ?? 0;
18477
+ routerFeeCost += row.router_fee_cost ?? 0;
18340
18478
  requestCount += row.request_count;
18341
18479
  }
18342
18480
  const messageRow = await this.ctx.storage.sql.exec(
@@ -18348,6 +18486,7 @@ ${resultContent}${attachmentSummary}`;
18348
18486
  inputCost,
18349
18487
  cachedCost,
18350
18488
  outputCost,
18489
+ routerFeeCost,
18351
18490
  requestCount,
18352
18491
  messageCount,
18353
18492
  byModel
@@ -18564,7 +18703,7 @@ ${resultContent}${attachmentSummary}`;
18564
18703
  l.request_body, l.request_headers, l.response_body, l.response_headers,
18565
18704
  l.status_code, l.reasoning_content, l.input_tokens, l.cached_tokens, l.output_tokens,
18566
18705
  l.reasoning_tokens, l.total_tokens, l.latency_ms, l.time_to_first_token_ms, l.generation_ms,
18567
- l.finish_reason, l.error, l.error_type, l.cost_input, l.cost_cached, l.cost_output, l.cost_total,
18706
+ l.finish_reason, l.error, l.error_type, l.cost_input, l.cost_cached, l.cost_output, l.cost_router_fee, l.router_fee_percent, l.cost_total,
18568
18707
  l.message_history_length, l.tools_available, l.prompt_name, l.tools_called,
18569
18708
  l.queued_tools, l.provider_tools, l.parent_log_id, l.tools_schema, l.system_prompt,
18570
18709
  l.errors, l.retry_of_log_id, l.tool_results, l.is_complete, l.created_at,
@@ -18656,6 +18795,8 @@ ${resultContent}${attachmentSummary}`;
18656
18795
  cost_input: row.cost_input,
18657
18796
  cost_cached: row.cost_cached,
18658
18797
  cost_output: row.cost_output,
18798
+ cost_router_fee: row.cost_router_fee,
18799
+ router_fee_percent: row.router_fee_percent,
18659
18800
  cost_total: row.cost_total,
18660
18801
  message_history_length: row.message_history_length,
18661
18802
  tools_available: row.tools_available,
@@ -20558,7 +20699,7 @@ ${resultContent}${attachmentSummary}`;
20558
20699
  };
20559
20700
 
20560
20701
  // src/durable-objects/agentbuilder-migrations/0001_initial.ts
20561
- var migration33 = {
20702
+ var migration34 = {
20562
20703
  version: 1,
20563
20704
  async up(sql) {
20564
20705
  sql.exec(`
@@ -20657,7 +20798,7 @@ var migration33 = {
20657
20798
  };
20658
20799
 
20659
20800
  // src/durable-objects/agentbuilder-migrations/0002_add_tenvs_properties.ts
20660
- var migration34 = {
20801
+ var migration35 = {
20661
20802
  version: 2,
20662
20803
  async up(sql) {
20663
20804
  sql.exec(`ALTER TABLE threads ADD COLUMN tenvs TEXT`);
@@ -20669,7 +20810,7 @@ var migration34 = {
20669
20810
  };
20670
20811
 
20671
20812
  // src/durable-objects/agentbuilder-migrations/0003_add_parent_and_terminated.ts
20672
- var migration35 = {
20813
+ var migration36 = {
20673
20814
  version: 3,
20674
20815
  async up(sql) {
20675
20816
  sql.exec(`ALTER TABLE threads ADD COLUMN parent TEXT REFERENCES threads(id)`);
@@ -20682,7 +20823,7 @@ var migration35 = {
20682
20823
  };
20683
20824
 
20684
20825
  // src/durable-objects/agentbuilder-migrations/0004_add_env_tables.ts
20685
- var migration36 = {
20826
+ var migration37 = {
20686
20827
  version: 4,
20687
20828
  async up(sql) {
20688
20829
  sql.exec(`ALTER TABLE threads ADD COLUMN env TEXT`);
@@ -20706,7 +20847,7 @@ var migration36 = {
20706
20847
  };
20707
20848
 
20708
20849
  // src/durable-objects/agentbuilder-migrations/0005_add_pending_subagent_env_requests.ts
20709
- var migration37 = {
20850
+ var migration38 = {
20710
20851
  version: 5,
20711
20852
  async up(sql) {
20712
20853
  sql.exec(`
@@ -20732,7 +20873,7 @@ var migration37 = {
20732
20873
  };
20733
20874
 
20734
20875
  // src/durable-objects/agentbuilder-migrations/0006_add_env_value_types.ts
20735
- var migration38 = {
20876
+ var migration39 = {
20736
20877
  version: 6,
20737
20878
  async up(sql) {
20738
20879
  sql.exec(
@@ -20747,7 +20888,7 @@ var migration38 = {
20747
20888
  };
20748
20889
 
20749
20890
  // src/durable-objects/agentbuilder-migrations/0007_platform_identity_replica.ts
20750
- var migration39 = {
20891
+ var migration40 = {
20751
20892
  version: 7,
20752
20893
  async up(sql) {
20753
20894
  sql.exec(`ALTER TABLE users ADD COLUMN platform_user_id TEXT`);
@@ -20776,7 +20917,7 @@ var migration39 = {
20776
20917
  };
20777
20918
 
20778
20919
  // src/durable-objects/agentbuilder-migrations/0008_add_skills.ts
20779
- var migration40 = {
20920
+ var migration41 = {
20780
20921
  version: 8,
20781
20922
  async up(sql) {
20782
20923
  sql.exec(`
@@ -20807,7 +20948,7 @@ var migration40 = {
20807
20948
  };
20808
20949
 
20809
20950
  // src/durable-objects/agentbuilder-migrations/0009_add_user_permissions.ts
20810
- var migration41 = {
20951
+ var migration42 = {
20811
20952
  version: 9,
20812
20953
  async up(sql) {
20813
20954
  sql.exec(`ALTER TABLE users ADD COLUMN permissions TEXT`);
@@ -20818,7 +20959,7 @@ var migration41 = {
20818
20959
  };
20819
20960
 
20820
20961
  // src/durable-objects/agentbuilder-migrations/0010_add_device_logins.ts
20821
- var migration42 = {
20962
+ var migration43 = {
20822
20963
  version: 10,
20823
20964
  async up(sql) {
20824
20965
  sql.exec(`
@@ -20838,7 +20979,7 @@ var migration42 = {
20838
20979
  };
20839
20980
 
20840
20981
  // src/durable-objects/agentbuilder-migrations/index.ts
20841
- var migrations2 = [migration33, migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42];
20982
+ var migrations2 = [migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43];
20842
20983
  var LATEST_SCHEMA_VERSION2 = 10;
20843
20984
 
20844
20985
  // src/utils/crypto.ts
@@ -21601,9 +21742,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
21601
21742
  }
21602
21743
  }
21603
21744
  async runMigrations(fromVersion) {
21604
- for (const migration43 of migrations2) {
21605
- if (migration43.version > fromVersion) {
21606
- await migration43.up(this.ctx.storage.sql);
21745
+ for (const migration44 of migrations2) {
21746
+ if (migration44.version > fromVersion) {
21747
+ await migration44.up(this.ctx.storage.sql);
21607
21748
  }
21608
21749
  }
21609
21750
  }