@standardagents/builder 0.24.6 → 0.24.7

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 (42) hide show
  1. package/dist/built-in-routes.js +151 -23
  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-Bd--_E_1.d.ts} +11 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +177 -35
  31. package/dist/index.js.map +1 -1
  32. package/dist/plugin.js +2 -0
  33. package/dist/plugin.js.map +1 -1
  34. package/dist/runtime.d.ts +12 -2
  35. package/dist/runtime.js +175 -35
  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/CompositionView-BvVMnyYP.js +0 -32
  40. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DHlNdv7o.js +0 -22
  41. package/dist/client/ThreadsView-BAfuNShv.js +0 -1
  42. package/dist/client/assets/index-Djjx6d3k.css +0 -1
@@ -26,14 +26,14 @@
26
26
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
27
27
  <link rel="icon" type="image/svg+xml" href="/agents/assets/img/favicon-9uH1rb2F.svg">
28
28
  <title>AgentBuilder Admin</title>
29
- <script type="module" crossorigin src="/agents/index-BVfRoUms.js"></script>
29
+ <script type="module" crossorigin src="/agents/index-0OxNDXyK.js"></script>
30
30
  <link rel="modulepreload" crossorigin href="/agents/formkit-YJ1Z7D5r.js">
31
31
  <link rel="modulepreload" crossorigin href="/agents/vendor-TPZjEwCU.js">
32
32
  <link rel="modulepreload" crossorigin href="/agents/syntax-D-ZcovVx.js">
33
33
  <link rel="modulepreload" crossorigin href="/agents/vue-BqC6IZDY.js">
34
34
  <link rel="modulepreload" crossorigin href="/agents/monaco-DI2r3M8m.js">
35
35
  <link rel="stylesheet" crossorigin href="/agents/assets/monaco-DbLkoLD4.css">
36
- <link rel="stylesheet" crossorigin href="/agents/assets/index-Djjx6d3k.css">
36
+ <link rel="stylesheet" crossorigin href="/agents/assets/index-B38KmIlM.css">
37
37
  </head>
38
38
  <body>
39
39
  <div id="app"></div>
@@ -704,6 +704,8 @@ interface LLMResponse {
704
704
  _provider?: unknown;
705
705
  /** @internal True when the request routed through the Standard Agents platform passthrough */
706
706
  _viaPlatform?: boolean;
707
+ /** @internal Router-fee percent the platform proxy reported for this request's origin (hosted routing only) */
708
+ _routerFeePercent?: number;
707
709
  /** @internal Provider response ID for async metadata fetching */
708
710
  _providerResponseId?: string;
709
711
  /** @internal Aggregate response for logging */
@@ -853,6 +855,11 @@ interface LogData {
853
855
  cost_input?: number;
854
856
  cost_cached?: number;
855
857
  cost_output?: number;
858
+ /** Standard Agents router fee (hosted routing markup on the raw provider cost); 0/absent for BYOK. */
859
+ cost_router_fee?: number;
860
+ /** Fee percent the platform reported for this request (e.g. 10 or 2.5). */
861
+ router_fee_percent?: number;
862
+ /** Total including cost_router_fee when the request routed through the platform. */
856
863
  cost_total?: number;
857
864
  message_history_length?: number;
858
865
  tools_available?: number;
@@ -1055,6 +1062,10 @@ interface LogDetails {
1055
1062
  error_type: string | null;
1056
1063
  cost_input: number | null;
1057
1064
  cost_output: number | null;
1065
+ /** Standard Agents router fee included in cost_total (hosted routing only). */
1066
+ cost_router_fee: number | null;
1067
+ /** Router-fee percent the platform reported for this request (e.g. 10 or 2.5). */
1068
+ router_fee_percent: number | null;
1058
1069
  cost_total: number | null;
1059
1070
  message_history_length: number | null;
1060
1071
  tools_available: number | null;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ModelDefinition, AgentDefinition } from './runtime.js';
2
2
  export { AgentBuilderEnv, AuthContext, AuthUser, BroadcastOptions, CodeExecutionBridge, DurableAgentBuilder, DurableThread, FlowStateSdk, FlowStateWithSdk, ImageContextConfig, InjectMessageOptions, LLMProviderInterface, NamespaceResolutionError, PromptContent, PromptDefinition, PromptIncludePart, PromptPart, PromptToolConfig, Provider, ProviderContentPart, ProviderFilePart, ProviderImagePart, ProviderRegistry, ProviderTextPart, SessionToolBinding, SessionToolConfig, SideConfig, SubagentToolConfig, SubpromptConfig, ThreadRegistryEntry, ToolConfig, UpdateThreadParams, User, authenticate, buildImageDescription, cat, createNamespaceContext, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateImageDescription, getFileStats, getMessages, getMessagesToSummarize, getShortName, getThumbnail, getUnsummarizedImageAttachments, getVisibleAgentNames, getVisibleModelNames, getVisiblePromptNames, getVisibleToolNames, grep, hasImageAttachments, head, injectMessage, isQualifiedName, linkFile, mkdir, move, optimizeImageContext, parseQualifiedName, qualifyName, queueTool, readFile, readdir, reloadHistory, rename, replaceImagesWithDescriptions, requireAdmin, requireAuth, resolveAgent, resolveHook, resolveModel, resolvePrompt, resolveTool, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage } from './runtime.js';
3
3
  export { AgentPluginOptions, agentbuilder, builder } from './plugin.js';
4
- export { A as Agent, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-D3FNNQWC.js';
4
+ export { A as Agent, m as AttachmentRef, f as BuilderThreadEndpointHandler, B as Controller, a as ControllerContext, E as Env, l as FileRecord, n as FileStats, j as FlowResult, F as FlowState, G as GrepResult, p as ImageContentPart, I as ImageMetadata, L as LLMResponse, M as Message, r as MessageContent, q as MultimodalContent, R as RequestContext, S as StorageBackend, k as TelemetryEvent, o as TextContentPart, b as ThreadEndpointContext, e as ThreadEnv, g as ThreadInstance, h as ThreadMetadata, T as ToolCall, i as ToolResult, c as createThreadEndpointHandler, d as defineController } from './index-Bd--_E_1.js';
5
5
  export { AgentType, DefinitionLoader, GlobalNamespaceContext, HookSignatures, ImageContent, ModelCapabilities, ModelProvider, NamespaceContext, PackageSignature, PackedExports, PackedMeta, PackedMetadata, PackedNamespaceContext, PromptInput, PromptTextPart, ProviderAssistantMessage, ProviderConfigSlot, ProviderConfigSlots, ProviderConfigValueSource, ProviderDefinition, ProviderError, ProviderErrorCode, ProviderFactory, ProviderFactoryConfig, ProviderFinishReason, ProviderGeneratedImage, ProviderMessage, ProviderMessageContent, ProviderMethodOverrides, ModelCapabilities as ProviderModelCapabilities, ProviderOverride, ProviderOverrideContext, ProviderReasoningDetail, ProviderRequest, ProviderResponse, ProviderStreamChunk, ProviderSyncOverride, ProviderSystemMessage, ProviderTool, ProviderToolCallPart, ProviderToolMessage, ProviderToolResultContent, ProviderUsage, ProviderUserMessage, ReasoningConfig, StructuredPrompt, TextContent, Tool, ToolArgs, ToolArgsNode, ToolArgsRawShape, ToolContent, belongsToPackage, defineAgent, defineHook, defineModel, definePrompt, defineProvider, defineTool, isPacked, isVisibleInNamespace, mapReasoningLevel, providerConst, providerEnv, providerValue } from '@standardagents/spec';
6
6
  export { C as ConstituentItem, D as DiscoveredPackage, N as NamespacedRegistry, P as PackingAnalysis, a as PackingOptions, b as PackingResult, c as UnpackOptions, d as UnpackResult } from './types-Bpe7IANZ.js';
7
7
  export { D as DiscoveryConfig, P as PackageDiscoveryService, d as discoverPackages } from './discovery-DiMJWisl.js';
package/dist/index.js CHANGED
@@ -243,6 +243,12 @@ function resolveModelPricing(modelDef, providerName) {
243
243
  }
244
244
  return null;
245
245
  }
246
+ function calculateRouterFee(rawCost, feePercent) {
247
+ if (!(rawCost > 0) || !(feePercent > 0)) {
248
+ return 0;
249
+ }
250
+ return roundCost(rawCost * feePercent / 100);
251
+ }
246
252
  function calculateUsageCost(usage, pricing) {
247
253
  if (!pricing) {
248
254
  return null;
@@ -273,6 +279,66 @@ var init_pricing = __esm({
273
279
  TOKENS_PER_MILLION = 1e6;
274
280
  }
275
281
  });
282
+
283
+ // src/agents/providers/router-fee.ts
284
+ function requestUrl(input) {
285
+ if (typeof input === "string") return input;
286
+ if (input instanceof URL) return input.toString();
287
+ if (typeof input === "object" && input !== null && typeof input.url === "string") {
288
+ return input.url;
289
+ }
290
+ return null;
291
+ }
292
+ function observeResponse(url, headers) {
293
+ if (!url) return;
294
+ for (const origin of registeredOrigins) {
295
+ if (!url.startsWith(`${origin}/v1/proxy/`)) continue;
296
+ const raw = headers.get(ROUTER_FEE_HEADER);
297
+ if (raw !== null) {
298
+ const percent = Number(raw);
299
+ if (Number.isFinite(percent) && percent >= 0) {
300
+ observedFeePercentByOrigin.set(origin, percent);
301
+ }
302
+ }
303
+ return;
304
+ }
305
+ }
306
+ function installObserver() {
307
+ if (observerInstalled) return;
308
+ const original = globalThis.fetch;
309
+ if (typeof original !== "function") return;
310
+ const bound = original.bind(globalThis);
311
+ const wrapped = async (input, init) => {
312
+ const response = await bound(input, init);
313
+ try {
314
+ observeResponse(requestUrl(input), response.headers);
315
+ } catch {
316
+ }
317
+ return response;
318
+ };
319
+ try {
320
+ globalThis.fetch = wrapped;
321
+ observerInstalled = true;
322
+ } catch {
323
+ }
324
+ }
325
+ function registerPlatformProxyOrigin(origin) {
326
+ if (!origin) return;
327
+ registeredOrigins.add(origin.replace(/\/+$/, ""));
328
+ installObserver();
329
+ }
330
+ function getObservedRouterFeePercent(origin) {
331
+ return observedFeePercentByOrigin.get(origin.replace(/\/+$/, "")) ?? null;
332
+ }
333
+ var ROUTER_FEE_HEADER, registeredOrigins, observedFeePercentByOrigin, observerInstalled;
334
+ var init_router_fee = __esm({
335
+ "src/agents/providers/router-fee.ts"() {
336
+ ROUTER_FEE_HEADER = "X-Standard-Agents-Router-Fee-Percent";
337
+ registeredOrigins = /* @__PURE__ */ new Set();
338
+ observedFeePercentByOrigin = /* @__PURE__ */ new Map();
339
+ observerInstalled = false;
340
+ }
341
+ });
276
342
  async function readCompletedArg(partialJson, argName) {
277
343
  if (!partialJson || !argName) return void 0;
278
344
  try {
@@ -823,6 +889,7 @@ var init_ProviderRegistry = __esm({
823
889
  "src/agents/providers/ProviderRegistry.ts"() {
824
890
  init_TestProvider();
825
891
  init_platform_routing();
892
+ init_router_fee();
826
893
  init_factory();
827
894
  ProviderRegistryImpl = class {
828
895
  providerCache = /* @__PURE__ */ new Map();
@@ -917,21 +984,22 @@ var init_ProviderRegistry = __esm({
917
984
  apiKey: routing.apiKey,
918
985
  baseUrl: routing.baseUrl
919
986
  };
987
+ registerPlatformProxyOrigin(routing.origin);
920
988
  const fingerprint = this.getProviderFingerprint(`platform:${providerName}`, modelDef, config);
921
989
  const cached = this.providerCache.get(modelName);
922
990
  if (cached?.fingerprint === fingerprint) {
923
- return this.buildResult(cached.provider, modelDef, true);
991
+ return this.buildResult(cached.provider, modelDef, true, routing.origin);
924
992
  }
925
- return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true);
993
+ return this.cacheAndReturn(modelName, providerFactory(config), modelDef, fingerprint, true, routing.origin);
926
994
  }
927
995
  throw new Error(`No API key found for provider: ${providerName}. Set the provider key or STANDARD_AGENTS_API_KEY.`);
928
996
  }
929
- buildResult(provider, modelDef, viaPlatform) {
930
- return { provider, modelName: modelDef.model, modelDef, viaPlatform };
997
+ buildResult(provider, modelDef, viaPlatform, platformProxyOrigin) {
998
+ return { provider, modelName: modelDef.model, modelDef, viaPlatform, platformProxyOrigin };
931
999
  }
932
- cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform) {
1000
+ cacheAndReturn(modelName, provider, modelDef, fingerprint, viaPlatform, platformProxyOrigin) {
933
1001
  this.providerCache.set(modelName, { provider, fingerprint, viaPlatform });
934
- return this.buildResult(provider, modelDef, viaPlatform);
1002
+ return this.buildResult(provider, modelDef, viaPlatform, platformProxyOrigin);
935
1003
  }
936
1004
  getProviderFingerprint(providerName, modelDef, config) {
937
1005
  return JSON.stringify({
@@ -1395,6 +1463,7 @@ var NON_VISION_PLACEHOLDER_TEXT, STREAM_FIRST_CHUNK_TIMEOUT_MS, STREAM_STALL_TIM
1395
1463
  var init_LLMRequest = __esm({
1396
1464
  "src/agents/LLMRequest.ts"() {
1397
1465
  init_pricing();
1466
+ init_router_fee();
1398
1467
  init_types();
1399
1468
  init_FlowEngine();
1400
1469
  init_toolProgress();
@@ -1658,11 +1727,7 @@ var init_LLMRequest = __esm({
1658
1727
  */
1659
1728
  static async callModel(modelId, context, state, logId) {
1660
1729
  const { ProviderRegistry: ProviderRegistry2 } = await Promise.resolve().then(() => (init_providers(), providers_exports));
1661
- const { provider, modelName, modelDef, viaPlatform } = await ProviderRegistry2.getProvider(
1662
- modelId,
1663
- state.env,
1664
- state.thread.instance
1665
- );
1730
+ const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, state.env, state.thread.instance);
1666
1731
  const streamAbort = new AbortController();
1667
1732
  const parentSignal = state.abortController?.signal;
1668
1733
  let onParentAbort;
@@ -1941,6 +2006,12 @@ var init_LLMRequest = __esm({
1941
2006
  };
1942
2007
  response._provider = provider;
1943
2008
  response._viaPlatform = viaPlatform;
2009
+ if (platformProxyOrigin) {
2010
+ const feePercent = getObservedRouterFeePercent(platformProxyOrigin);
2011
+ if (feePercent !== null) {
2012
+ response._routerFeePercent = feePercent;
2013
+ }
2014
+ }
1944
2015
  response._providerResponseId = providerResponseId;
1945
2016
  response._timing = {
1946
2017
  latencyMs: firstChunkAt > 0 ? firstChunkAt - requestSentAt : null,
@@ -2069,7 +2140,10 @@ var init_LLMRequest = __esm({
2069
2140
  const resolvedPricing = resolveModelPricing(modelDef) ?? resolveUsageReportedPricing(response.usage) ?? resolveModelPricing(modelDef, providerName);
2070
2141
  const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
2071
2142
  const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
2072
- const cost_total = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
2143
+ const rawProviderCost = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
2144
+ const routerFeePercent = standardAgentsRouterUsed && typeof response._routerFeePercent === "number" && response._routerFeePercent > 0 ? response._routerFeePercent : null;
2145
+ const costRouterFee = routerFeePercent !== null && rawProviderCost !== null ? calculateRouterFee(rawProviderCost, routerFeePercent) : null;
2146
+ const cost_total = rawProviderCost !== null && costRouterFee !== null && costRouterFee > 0 ? roundCost(rawProviderCost + costRouterFee) : rawProviderCost;
2073
2147
  const actualProvider = normalizeProviderMetadataValue(response.usage.provider) ?? null;
2074
2148
  const aggregateResponse = response._aggregate_response;
2075
2149
  const responseBody = aggregateResponse ? JSON.stringify(aggregateResponse) : JSON.stringify(response);
@@ -2135,6 +2209,8 @@ var init_LLMRequest = __esm({
2135
2209
  cost_input: calculatedCost?.costInput,
2136
2210
  cost_cached: calculatedCost?.costCached,
2137
2211
  cost_output: calculatedCost?.costOutput,
2212
+ cost_router_fee: costRouterFee ?? void 0,
2213
+ router_fee_percent: routerFeePercent ?? void 0,
2138
2214
  latency_ms: Date.now() - startTime,
2139
2215
  time_to_first_token_ms: timing?.latencyMs ?? void 0,
2140
2216
  generation_ms: timing?.generationMs ?? void 0,
@@ -2175,8 +2251,10 @@ var init_LLMRequest = __esm({
2175
2251
  actual_provider = ?17,
2176
2252
  standard_agents_router_used = ?18,
2177
2253
  time_to_first_token_ms = ?19,
2178
- generation_ms = ?20
2179
- WHERE id = ?21
2254
+ generation_ms = ?20,
2255
+ cost_router_fee = ?21,
2256
+ router_fee_percent = ?22
2257
+ WHERE id = ?23
2180
2258
  `,
2181
2259
  logData.response_body,
2182
2260
  logData.input_tokens,
@@ -2198,6 +2276,8 @@ var init_LLMRequest = __esm({
2198
2276
  standardAgentsRouterUsed ? 1 : 0,
2199
2277
  logData.time_to_first_token_ms ?? null,
2200
2278
  logData.generation_ms ?? null,
2279
+ logData.cost_router_fee ?? null,
2280
+ logData.router_fee_percent ?? null,
2201
2281
  logId
2202
2282
  );
2203
2283
  }
@@ -2536,9 +2616,24 @@ ${errorStack}` : ""}${errorDetails}`;
2536
2616
  updates.push(`actual_provider = ?${paramIndex++}`);
2537
2617
  values.push(actualProvider);
2538
2618
  }
2619
+ let updatedCostTotal;
2620
+ let updatedRouterFee;
2539
2621
  if (metadata.generation_cost !== void 0) {
2622
+ updatedCostTotal = metadata.generation_cost;
2623
+ const rawCost = typeof metadata.generation_cost === "number" ? metadata.generation_cost : Number(metadata.generation_cost);
2624
+ if (Number.isFinite(rawCost)) {
2625
+ const feePercent = await this.readRouterFeePercent(state, logId);
2626
+ if (feePercent !== null && feePercent > 0) {
2627
+ updatedRouterFee = calculateRouterFee(rawCost, feePercent);
2628
+ updatedCostTotal = roundCost(rawCost + updatedRouterFee);
2629
+ }
2630
+ }
2540
2631
  updates.push(`cost_total = ?${paramIndex++}`);
2541
- values.push(metadata.generation_cost);
2632
+ values.push(updatedCostTotal);
2633
+ if (updatedRouterFee !== void 0) {
2634
+ updates.push(`cost_router_fee = ?${paramIndex++}`);
2635
+ values.push(updatedRouterFee);
2636
+ }
2542
2637
  }
2543
2638
  if (updates.length === 0) {
2544
2639
  return;
@@ -2553,7 +2648,8 @@ ${errorStack}` : ""}${errorDetails}`;
2553
2648
  data: {
2554
2649
  id: logId,
2555
2650
  ...actualProvider !== void 0 && { actual_provider: actualProvider },
2556
- ...metadata.generation_cost !== void 0 && { cost_total: metadata.generation_cost }
2651
+ ...metadata.generation_cost !== void 0 && { cost_total: updatedCostTotal },
2652
+ ...updatedRouterFee !== void 0 && { cost_router_fee: updatedRouterFee }
2557
2653
  }
2558
2654
  });
2559
2655
  }
@@ -2561,6 +2657,23 @@ ${errorStack}` : ""}${errorDetails}`;
2561
2657
  console.error("Failed to update log with metadata (non-fatal):", error);
2562
2658
  }
2563
2659
  }
2660
+ /**
2661
+ * Router-fee percent recorded on a log row by logSuccess, or null when the
2662
+ * row has none (BYOK) or the storage shape doesn't expose it.
2663
+ */
2664
+ static async readRouterFeePercent(state, logId) {
2665
+ try {
2666
+ const cursor = await state.storage.sql.exec(
2667
+ `SELECT router_fee_percent FROM logs WHERE id = ?`,
2668
+ logId
2669
+ );
2670
+ const row = cursor?.toArray?.()[0];
2671
+ const percent = row?.router_fee_percent;
2672
+ return typeof percent === "number" && Number.isFinite(percent) ? percent : null;
2673
+ } catch {
2674
+ return null;
2675
+ }
2676
+ }
2564
2677
  };
2565
2678
  }
2566
2679
  });
@@ -13938,6 +14051,8 @@ declare module 'virtual:@standardagents/builder' {
13938
14051
  error_type: string | null;
13939
14052
  cost_input: number | null;
13940
14053
  cost_output: number | null;
14054
+ cost_router_fee: number | null;
14055
+ router_fee_percent: number | null;
13941
14056
  message_history_length: number | null;
13942
14057
  tools_available: number | null;
13943
14058
  tools_schema: string | null;
@@ -22949,8 +23064,28 @@ var migration32 = {
22949
23064
  }
22950
23065
  };
22951
23066
 
23067
+ // src/durable-objects/migrations/033_add_router_fee.ts
23068
+ var migration33 = {
23069
+ version: 33,
23070
+ name: "add_router_fee",
23071
+ async up(sql) {
23072
+ const tableInfo = sql.exec(`PRAGMA table_info(logs)`).toArray();
23073
+ const hasColumn = (name) => tableInfo.some((col) => col.name === name);
23074
+ if (!hasColumn("cost_router_fee")) {
23075
+ await sql.exec(`
23076
+ ALTER TABLE logs ADD COLUMN cost_router_fee REAL;
23077
+ `);
23078
+ }
23079
+ if (!hasColumn("router_fee_percent")) {
23080
+ await sql.exec(`
23081
+ ALTER TABLE logs ADD COLUMN router_fee_percent REAL;
23082
+ `);
23083
+ }
23084
+ }
23085
+ };
23086
+
22952
23087
  // src/durable-objects/migrations/index.ts
22953
- 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];
23088
+ 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];
22954
23089
  var LATEST_SCHEMA_VERSION = migrations.length;
22955
23090
 
22956
23091
  // src/durable-objects/DurableThread.ts
@@ -25069,9 +25204,9 @@ var DurableThread = class _DurableThread extends DurableObject {
25069
25204
  * Each migration is run in order, starting from the current version + 1.
25070
25205
  */
25071
25206
  async runMigrations(fromVersion) {
25072
- for (const migration43 of migrations) {
25073
- if (migration43.version > fromVersion) {
25074
- await migration43.up(this.ctx.storage.sql);
25207
+ for (const migration44 of migrations) {
25208
+ if (migration44.version > fromVersion) {
25209
+ await migration44.up(this.ctx.storage.sql);
25075
25210
  }
25076
25211
  }
25077
25212
  }
@@ -26558,6 +26693,7 @@ ${resultContent}${attachmentSummary}`;
26558
26693
  let inputCost = 0;
26559
26694
  let cachedCost = 0;
26560
26695
  let outputCost = 0;
26696
+ let routerFeeCost = 0;
26561
26697
  let requestCount = 0;
26562
26698
  const modelRows = await this.ctx.storage.sql.exec(
26563
26699
  `
@@ -26566,6 +26702,7 @@ ${resultContent}${attachmentSummary}`;
26566
26702
  SUM(CASE WHEN cost_cached IS NOT NULL THEN cost_input END) AS input_cost,
26567
26703
  SUM(cost_cached) AS cached_cost,
26568
26704
  SUM(cost_output) AS output_cost,
26705
+ SUM(cost_router_fee) AS router_fee_cost,
26569
26706
  COUNT(*) AS request_count
26570
26707
  FROM logs
26571
26708
  WHERE cost_total IS NOT NULL
@@ -26578,12 +26715,14 @@ ${resultContent}${attachmentSummary}`;
26578
26715
  inputCost: row.input_cost ?? 0,
26579
26716
  cachedCost: row.cached_cost ?? 0,
26580
26717
  outputCost: row.output_cost ?? 0,
26718
+ routerFeeCost: row.router_fee_cost ?? 0,
26581
26719
  count: row.request_count
26582
26720
  };
26583
26721
  totalCost += row.total_cost;
26584
26722
  inputCost += row.input_cost ?? 0;
26585
26723
  cachedCost += row.cached_cost ?? 0;
26586
26724
  outputCost += row.output_cost ?? 0;
26725
+ routerFeeCost += row.router_fee_cost ?? 0;
26587
26726
  requestCount += row.request_count;
26588
26727
  }
26589
26728
  const messageRow = await this.ctx.storage.sql.exec(
@@ -26595,6 +26734,7 @@ ${resultContent}${attachmentSummary}`;
26595
26734
  inputCost,
26596
26735
  cachedCost,
26597
26736
  outputCost,
26737
+ routerFeeCost,
26598
26738
  requestCount,
26599
26739
  messageCount,
26600
26740
  byModel
@@ -26811,7 +26951,7 @@ ${resultContent}${attachmentSummary}`;
26811
26951
  l.request_body, l.request_headers, l.response_body, l.response_headers,
26812
26952
  l.status_code, l.reasoning_content, l.input_tokens, l.cached_tokens, l.output_tokens,
26813
26953
  l.reasoning_tokens, l.total_tokens, l.latency_ms, l.time_to_first_token_ms, l.generation_ms,
26814
- l.finish_reason, l.error, l.error_type, l.cost_input, l.cost_cached, l.cost_output, l.cost_total,
26954
+ 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,
26815
26955
  l.message_history_length, l.tools_available, l.prompt_name, l.tools_called,
26816
26956
  l.queued_tools, l.provider_tools, l.parent_log_id, l.tools_schema, l.system_prompt,
26817
26957
  l.errors, l.retry_of_log_id, l.tool_results, l.is_complete, l.created_at,
@@ -26903,6 +27043,8 @@ ${resultContent}${attachmentSummary}`;
26903
27043
  cost_input: row.cost_input,
26904
27044
  cost_cached: row.cost_cached,
26905
27045
  cost_output: row.cost_output,
27046
+ cost_router_fee: row.cost_router_fee,
27047
+ router_fee_percent: row.router_fee_percent,
26906
27048
  cost_total: row.cost_total,
26907
27049
  message_history_length: row.message_history_length,
26908
27050
  tools_available: row.tools_available,
@@ -28805,7 +28947,7 @@ ${resultContent}${attachmentSummary}`;
28805
28947
  };
28806
28948
 
28807
28949
  // src/durable-objects/agentbuilder-migrations/0001_initial.ts
28808
- var migration33 = {
28950
+ var migration34 = {
28809
28951
  version: 1,
28810
28952
  async up(sql) {
28811
28953
  sql.exec(`
@@ -28904,7 +29046,7 @@ var migration33 = {
28904
29046
  };
28905
29047
 
28906
29048
  // src/durable-objects/agentbuilder-migrations/0002_add_tenvs_properties.ts
28907
- var migration34 = {
29049
+ var migration35 = {
28908
29050
  version: 2,
28909
29051
  async up(sql) {
28910
29052
  sql.exec(`ALTER TABLE threads ADD COLUMN tenvs TEXT`);
@@ -28916,7 +29058,7 @@ var migration34 = {
28916
29058
  };
28917
29059
 
28918
29060
  // src/durable-objects/agentbuilder-migrations/0003_add_parent_and_terminated.ts
28919
- var migration35 = {
29061
+ var migration36 = {
28920
29062
  version: 3,
28921
29063
  async up(sql) {
28922
29064
  sql.exec(`ALTER TABLE threads ADD COLUMN parent TEXT REFERENCES threads(id)`);
@@ -28929,7 +29071,7 @@ var migration35 = {
28929
29071
  };
28930
29072
 
28931
29073
  // src/durable-objects/agentbuilder-migrations/0004_add_env_tables.ts
28932
- var migration36 = {
29074
+ var migration37 = {
28933
29075
  version: 4,
28934
29076
  async up(sql) {
28935
29077
  sql.exec(`ALTER TABLE threads ADD COLUMN env TEXT`);
@@ -28953,7 +29095,7 @@ var migration36 = {
28953
29095
  };
28954
29096
 
28955
29097
  // src/durable-objects/agentbuilder-migrations/0005_add_pending_subagent_env_requests.ts
28956
- var migration37 = {
29098
+ var migration38 = {
28957
29099
  version: 5,
28958
29100
  async up(sql) {
28959
29101
  sql.exec(`
@@ -28979,7 +29121,7 @@ var migration37 = {
28979
29121
  };
28980
29122
 
28981
29123
  // src/durable-objects/agentbuilder-migrations/0006_add_env_value_types.ts
28982
- var migration38 = {
29124
+ var migration39 = {
28983
29125
  version: 6,
28984
29126
  async up(sql) {
28985
29127
  sql.exec(
@@ -28994,7 +29136,7 @@ var migration38 = {
28994
29136
  };
28995
29137
 
28996
29138
  // src/durable-objects/agentbuilder-migrations/0007_platform_identity_replica.ts
28997
- var migration39 = {
29139
+ var migration40 = {
28998
29140
  version: 7,
28999
29141
  async up(sql) {
29000
29142
  sql.exec(`ALTER TABLE users ADD COLUMN platform_user_id TEXT`);
@@ -29023,7 +29165,7 @@ var migration39 = {
29023
29165
  };
29024
29166
 
29025
29167
  // src/durable-objects/agentbuilder-migrations/0008_add_skills.ts
29026
- var migration40 = {
29168
+ var migration41 = {
29027
29169
  version: 8,
29028
29170
  async up(sql) {
29029
29171
  sql.exec(`
@@ -29054,7 +29196,7 @@ var migration40 = {
29054
29196
  };
29055
29197
 
29056
29198
  // src/durable-objects/agentbuilder-migrations/0009_add_user_permissions.ts
29057
- var migration41 = {
29199
+ var migration42 = {
29058
29200
  version: 9,
29059
29201
  async up(sql) {
29060
29202
  sql.exec(`ALTER TABLE users ADD COLUMN permissions TEXT`);
@@ -29065,7 +29207,7 @@ var migration41 = {
29065
29207
  };
29066
29208
 
29067
29209
  // src/durable-objects/agentbuilder-migrations/0010_add_device_logins.ts
29068
- var migration42 = {
29210
+ var migration43 = {
29069
29211
  version: 10,
29070
29212
  async up(sql) {
29071
29213
  sql.exec(`
@@ -29085,7 +29227,7 @@ var migration42 = {
29085
29227
  };
29086
29228
 
29087
29229
  // src/durable-objects/agentbuilder-migrations/index.ts
29088
- var migrations2 = [migration33, migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42];
29230
+ var migrations2 = [migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43];
29089
29231
  var LATEST_SCHEMA_VERSION2 = 10;
29090
29232
 
29091
29233
  // src/utils/crypto.ts
@@ -29848,9 +29990,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
29848
29990
  }
29849
29991
  }
29850
29992
  async runMigrations(fromVersion) {
29851
- for (const migration43 of migrations2) {
29852
- if (migration43.version > fromVersion) {
29853
- await migration43.up(this.ctx.storage.sql);
29993
+ for (const migration44 of migrations2) {
29994
+ if (migration44.version > fromVersion) {
29995
+ await migration44.up(this.ctx.storage.sql);
29854
29996
  }
29855
29997
  }
29856
29998
  }