@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
@@ -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;
@@ -885,6 +892,7 @@ interface Env extends ThreadEnv {
885
892
  ANTHROPIC_API_KEY?: string;
886
893
  OPENROUTER_API_KEY?: string;
887
894
  GOOGLE_API_KEY?: string;
895
+ NOVITA_API_KEY?: string;
888
896
  XAI_API_KEY?: string;
889
897
  UI_DEV_SERVER?: string;
890
898
  ASSETS?: {
@@ -1055,6 +1063,10 @@ interface LogDetails {
1055
1063
  error_type: string | null;
1056
1064
  cost_input: number | null;
1057
1065
  cost_output: number | null;
1066
+ /** Standard Agents router fee included in cost_total (hosted routing only). */
1067
+ cost_router_fee: number | null;
1068
+ /** Router-fee percent the platform reported for this request (e.g. 10 or 2.5). */
1069
+ router_fee_percent: number | null;
1058
1070
  cost_total: number | null;
1059
1071
  message_history_length: number | null;
1060
1072
  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-BsS0cHzL.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({
@@ -950,6 +1018,7 @@ var init_ProviderRegistry = __esm({
950
1018
  cerebras: "CEREBRAS_API_KEY",
951
1019
  google: "GOOGLE_API_KEY",
952
1020
  groq: "GROQ_API_KEY",
1021
+ novita: "NOVITA_API_KEY",
953
1022
  openai: "OPENAI_API_KEY",
954
1023
  openrouter: "OPENROUTER_API_KEY",
955
1024
  anthropic: "ANTHROPIC_API_KEY",
@@ -1395,6 +1464,7 @@ var NON_VISION_PLACEHOLDER_TEXT, STREAM_FIRST_CHUNK_TIMEOUT_MS, STREAM_STALL_TIM
1395
1464
  var init_LLMRequest = __esm({
1396
1465
  "src/agents/LLMRequest.ts"() {
1397
1466
  init_pricing();
1467
+ init_router_fee();
1398
1468
  init_types();
1399
1469
  init_FlowEngine();
1400
1470
  init_toolProgress();
@@ -1658,11 +1728,7 @@ var init_LLMRequest = __esm({
1658
1728
  */
1659
1729
  static async callModel(modelId, context, state, logId) {
1660
1730
  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
- );
1731
+ const { provider, modelName, modelDef, viaPlatform, platformProxyOrigin } = await ProviderRegistry2.getProvider(modelId, state.env, state.thread.instance);
1666
1732
  const streamAbort = new AbortController();
1667
1733
  const parentSignal = state.abortController?.signal;
1668
1734
  let onParentAbort;
@@ -1941,6 +2007,12 @@ var init_LLMRequest = __esm({
1941
2007
  };
1942
2008
  response._provider = provider;
1943
2009
  response._viaPlatform = viaPlatform;
2010
+ if (platformProxyOrigin) {
2011
+ const feePercent = getObservedRouterFeePercent(platformProxyOrigin);
2012
+ if (feePercent !== null) {
2013
+ response._routerFeePercent = feePercent;
2014
+ }
2015
+ }
1944
2016
  response._providerResponseId = providerResponseId;
1945
2017
  response._timing = {
1946
2018
  latencyMs: firstChunkAt > 0 ? firstChunkAt - requestSentAt : null,
@@ -2069,7 +2141,10 @@ var init_LLMRequest = __esm({
2069
2141
  const resolvedPricing = resolveModelPricing(modelDef) ?? resolveUsageReportedPricing(response.usage) ?? resolveModelPricing(modelDef, providerName);
2070
2142
  const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
2071
2143
  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;
2144
+ const rawProviderCost = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
2145
+ const routerFeePercent = standardAgentsRouterUsed && typeof response._routerFeePercent === "number" && response._routerFeePercent > 0 ? response._routerFeePercent : null;
2146
+ const costRouterFee = routerFeePercent !== null && rawProviderCost !== null ? calculateRouterFee(rawProviderCost, routerFeePercent) : null;
2147
+ const cost_total = rawProviderCost !== null && costRouterFee !== null && costRouterFee > 0 ? roundCost(rawProviderCost + costRouterFee) : rawProviderCost;
2073
2148
  const actualProvider = normalizeProviderMetadataValue(response.usage.provider) ?? null;
2074
2149
  const aggregateResponse = response._aggregate_response;
2075
2150
  const responseBody = aggregateResponse ? JSON.stringify(aggregateResponse) : JSON.stringify(response);
@@ -2135,6 +2210,8 @@ var init_LLMRequest = __esm({
2135
2210
  cost_input: calculatedCost?.costInput,
2136
2211
  cost_cached: calculatedCost?.costCached,
2137
2212
  cost_output: calculatedCost?.costOutput,
2213
+ cost_router_fee: costRouterFee ?? void 0,
2214
+ router_fee_percent: routerFeePercent ?? void 0,
2138
2215
  latency_ms: Date.now() - startTime,
2139
2216
  time_to_first_token_ms: timing?.latencyMs ?? void 0,
2140
2217
  generation_ms: timing?.generationMs ?? void 0,
@@ -2175,8 +2252,10 @@ var init_LLMRequest = __esm({
2175
2252
  actual_provider = ?17,
2176
2253
  standard_agents_router_used = ?18,
2177
2254
  time_to_first_token_ms = ?19,
2178
- generation_ms = ?20
2179
- WHERE id = ?21
2255
+ generation_ms = ?20,
2256
+ cost_router_fee = ?21,
2257
+ router_fee_percent = ?22
2258
+ WHERE id = ?23
2180
2259
  `,
2181
2260
  logData.response_body,
2182
2261
  logData.input_tokens,
@@ -2198,6 +2277,8 @@ var init_LLMRequest = __esm({
2198
2277
  standardAgentsRouterUsed ? 1 : 0,
2199
2278
  logData.time_to_first_token_ms ?? null,
2200
2279
  logData.generation_ms ?? null,
2280
+ logData.cost_router_fee ?? null,
2281
+ logData.router_fee_percent ?? null,
2201
2282
  logId
2202
2283
  );
2203
2284
  }
@@ -2536,9 +2617,24 @@ ${errorStack}` : ""}${errorDetails}`;
2536
2617
  updates.push(`actual_provider = ?${paramIndex++}`);
2537
2618
  values.push(actualProvider);
2538
2619
  }
2620
+ let updatedCostTotal;
2621
+ let updatedRouterFee;
2539
2622
  if (metadata.generation_cost !== void 0) {
2623
+ updatedCostTotal = metadata.generation_cost;
2624
+ const rawCost = typeof metadata.generation_cost === "number" ? metadata.generation_cost : Number(metadata.generation_cost);
2625
+ if (Number.isFinite(rawCost)) {
2626
+ const feePercent = await this.readRouterFeePercent(state, logId);
2627
+ if (feePercent !== null && feePercent > 0) {
2628
+ updatedRouterFee = calculateRouterFee(rawCost, feePercent);
2629
+ updatedCostTotal = roundCost(rawCost + updatedRouterFee);
2630
+ }
2631
+ }
2540
2632
  updates.push(`cost_total = ?${paramIndex++}`);
2541
- values.push(metadata.generation_cost);
2633
+ values.push(updatedCostTotal);
2634
+ if (updatedRouterFee !== void 0) {
2635
+ updates.push(`cost_router_fee = ?${paramIndex++}`);
2636
+ values.push(updatedRouterFee);
2637
+ }
2542
2638
  }
2543
2639
  if (updates.length === 0) {
2544
2640
  return;
@@ -2553,7 +2649,8 @@ ${errorStack}` : ""}${errorDetails}`;
2553
2649
  data: {
2554
2650
  id: logId,
2555
2651
  ...actualProvider !== void 0 && { actual_provider: actualProvider },
2556
- ...metadata.generation_cost !== void 0 && { cost_total: metadata.generation_cost }
2652
+ ...metadata.generation_cost !== void 0 && { cost_total: updatedCostTotal },
2653
+ ...updatedRouterFee !== void 0 && { cost_router_fee: updatedRouterFee }
2557
2654
  }
2558
2655
  });
2559
2656
  }
@@ -2561,6 +2658,23 @@ ${errorStack}` : ""}${errorDetails}`;
2561
2658
  console.error("Failed to update log with metadata (non-fatal):", error);
2562
2659
  }
2563
2660
  }
2661
+ /**
2662
+ * Router-fee percent recorded on a log row by logSuccess, or null when the
2663
+ * row has none (BYOK) or the storage shape doesn't expose it.
2664
+ */
2665
+ static async readRouterFeePercent(state, logId) {
2666
+ try {
2667
+ const cursor = await state.storage.sql.exec(
2668
+ `SELECT router_fee_percent FROM logs WHERE id = ?`,
2669
+ logId
2670
+ );
2671
+ const row = cursor?.toArray?.()[0];
2672
+ const percent = row?.router_fee_percent;
2673
+ return typeof percent === "number" && Number.isFinite(percent) ? percent : null;
2674
+ } catch {
2675
+ return null;
2676
+ }
2677
+ }
2564
2678
  };
2565
2679
  }
2566
2680
  });
@@ -13938,6 +14052,8 @@ declare module 'virtual:@standardagents/builder' {
13938
14052
  error_type: string | null;
13939
14053
  cost_input: number | null;
13940
14054
  cost_output: number | null;
14055
+ cost_router_fee: number | null;
14056
+ router_fee_percent: number | null;
13941
14057
  message_history_length: number | null;
13942
14058
  tools_available: number | null;
13943
14059
  tools_schema: string | null;
@@ -14460,6 +14576,12 @@ var FIRST_PARTY_PROVIDERS = [
14460
14576
  label: "Groq",
14461
14577
  envKeys: ["GROQ_API_KEY"]
14462
14578
  },
14579
+ {
14580
+ name: "novita",
14581
+ package: "@standardagents/novita",
14582
+ label: "Novita AI",
14583
+ envKeys: ["NOVITA_API_KEY"]
14584
+ },
14463
14585
  {
14464
14586
  name: "openai",
14465
14587
  package: "@standardagents/openai",
@@ -22949,8 +23071,28 @@ var migration32 = {
22949
23071
  }
22950
23072
  };
22951
23073
 
23074
+ // src/durable-objects/migrations/033_add_router_fee.ts
23075
+ var migration33 = {
23076
+ version: 33,
23077
+ name: "add_router_fee",
23078
+ async up(sql) {
23079
+ const tableInfo = sql.exec(`PRAGMA table_info(logs)`).toArray();
23080
+ const hasColumn = (name) => tableInfo.some((col) => col.name === name);
23081
+ if (!hasColumn("cost_router_fee")) {
23082
+ await sql.exec(`
23083
+ ALTER TABLE logs ADD COLUMN cost_router_fee REAL;
23084
+ `);
23085
+ }
23086
+ if (!hasColumn("router_fee_percent")) {
23087
+ await sql.exec(`
23088
+ ALTER TABLE logs ADD COLUMN router_fee_percent REAL;
23089
+ `);
23090
+ }
23091
+ }
23092
+ };
23093
+
22952
23094
  // 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];
23095
+ 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
23096
  var LATEST_SCHEMA_VERSION = migrations.length;
22955
23097
 
22956
23098
  // src/durable-objects/DurableThread.ts
@@ -25069,9 +25211,9 @@ var DurableThread = class _DurableThread extends DurableObject {
25069
25211
  * Each migration is run in order, starting from the current version + 1.
25070
25212
  */
25071
25213
  async runMigrations(fromVersion) {
25072
- for (const migration43 of migrations) {
25073
- if (migration43.version > fromVersion) {
25074
- await migration43.up(this.ctx.storage.sql);
25214
+ for (const migration44 of migrations) {
25215
+ if (migration44.version > fromVersion) {
25216
+ await migration44.up(this.ctx.storage.sql);
25075
25217
  }
25076
25218
  }
25077
25219
  }
@@ -26558,6 +26700,7 @@ ${resultContent}${attachmentSummary}`;
26558
26700
  let inputCost = 0;
26559
26701
  let cachedCost = 0;
26560
26702
  let outputCost = 0;
26703
+ let routerFeeCost = 0;
26561
26704
  let requestCount = 0;
26562
26705
  const modelRows = await this.ctx.storage.sql.exec(
26563
26706
  `
@@ -26566,6 +26709,7 @@ ${resultContent}${attachmentSummary}`;
26566
26709
  SUM(CASE WHEN cost_cached IS NOT NULL THEN cost_input END) AS input_cost,
26567
26710
  SUM(cost_cached) AS cached_cost,
26568
26711
  SUM(cost_output) AS output_cost,
26712
+ SUM(cost_router_fee) AS router_fee_cost,
26569
26713
  COUNT(*) AS request_count
26570
26714
  FROM logs
26571
26715
  WHERE cost_total IS NOT NULL
@@ -26578,12 +26722,14 @@ ${resultContent}${attachmentSummary}`;
26578
26722
  inputCost: row.input_cost ?? 0,
26579
26723
  cachedCost: row.cached_cost ?? 0,
26580
26724
  outputCost: row.output_cost ?? 0,
26725
+ routerFeeCost: row.router_fee_cost ?? 0,
26581
26726
  count: row.request_count
26582
26727
  };
26583
26728
  totalCost += row.total_cost;
26584
26729
  inputCost += row.input_cost ?? 0;
26585
26730
  cachedCost += row.cached_cost ?? 0;
26586
26731
  outputCost += row.output_cost ?? 0;
26732
+ routerFeeCost += row.router_fee_cost ?? 0;
26587
26733
  requestCount += row.request_count;
26588
26734
  }
26589
26735
  const messageRow = await this.ctx.storage.sql.exec(
@@ -26595,6 +26741,7 @@ ${resultContent}${attachmentSummary}`;
26595
26741
  inputCost,
26596
26742
  cachedCost,
26597
26743
  outputCost,
26744
+ routerFeeCost,
26598
26745
  requestCount,
26599
26746
  messageCount,
26600
26747
  byModel
@@ -26811,7 +26958,7 @@ ${resultContent}${attachmentSummary}`;
26811
26958
  l.request_body, l.request_headers, l.response_body, l.response_headers,
26812
26959
  l.status_code, l.reasoning_content, l.input_tokens, l.cached_tokens, l.output_tokens,
26813
26960
  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,
26961
+ 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
26962
  l.message_history_length, l.tools_available, l.prompt_name, l.tools_called,
26816
26963
  l.queued_tools, l.provider_tools, l.parent_log_id, l.tools_schema, l.system_prompt,
26817
26964
  l.errors, l.retry_of_log_id, l.tool_results, l.is_complete, l.created_at,
@@ -26903,6 +27050,8 @@ ${resultContent}${attachmentSummary}`;
26903
27050
  cost_input: row.cost_input,
26904
27051
  cost_cached: row.cost_cached,
26905
27052
  cost_output: row.cost_output,
27053
+ cost_router_fee: row.cost_router_fee,
27054
+ router_fee_percent: row.router_fee_percent,
26906
27055
  cost_total: row.cost_total,
26907
27056
  message_history_length: row.message_history_length,
26908
27057
  tools_available: row.tools_available,
@@ -28805,7 +28954,7 @@ ${resultContent}${attachmentSummary}`;
28805
28954
  };
28806
28955
 
28807
28956
  // src/durable-objects/agentbuilder-migrations/0001_initial.ts
28808
- var migration33 = {
28957
+ var migration34 = {
28809
28958
  version: 1,
28810
28959
  async up(sql) {
28811
28960
  sql.exec(`
@@ -28904,7 +29053,7 @@ var migration33 = {
28904
29053
  };
28905
29054
 
28906
29055
  // src/durable-objects/agentbuilder-migrations/0002_add_tenvs_properties.ts
28907
- var migration34 = {
29056
+ var migration35 = {
28908
29057
  version: 2,
28909
29058
  async up(sql) {
28910
29059
  sql.exec(`ALTER TABLE threads ADD COLUMN tenvs TEXT`);
@@ -28916,7 +29065,7 @@ var migration34 = {
28916
29065
  };
28917
29066
 
28918
29067
  // src/durable-objects/agentbuilder-migrations/0003_add_parent_and_terminated.ts
28919
- var migration35 = {
29068
+ var migration36 = {
28920
29069
  version: 3,
28921
29070
  async up(sql) {
28922
29071
  sql.exec(`ALTER TABLE threads ADD COLUMN parent TEXT REFERENCES threads(id)`);
@@ -28929,7 +29078,7 @@ var migration35 = {
28929
29078
  };
28930
29079
 
28931
29080
  // src/durable-objects/agentbuilder-migrations/0004_add_env_tables.ts
28932
- var migration36 = {
29081
+ var migration37 = {
28933
29082
  version: 4,
28934
29083
  async up(sql) {
28935
29084
  sql.exec(`ALTER TABLE threads ADD COLUMN env TEXT`);
@@ -28953,7 +29102,7 @@ var migration36 = {
28953
29102
  };
28954
29103
 
28955
29104
  // src/durable-objects/agentbuilder-migrations/0005_add_pending_subagent_env_requests.ts
28956
- var migration37 = {
29105
+ var migration38 = {
28957
29106
  version: 5,
28958
29107
  async up(sql) {
28959
29108
  sql.exec(`
@@ -28979,7 +29128,7 @@ var migration37 = {
28979
29128
  };
28980
29129
 
28981
29130
  // src/durable-objects/agentbuilder-migrations/0006_add_env_value_types.ts
28982
- var migration38 = {
29131
+ var migration39 = {
28983
29132
  version: 6,
28984
29133
  async up(sql) {
28985
29134
  sql.exec(
@@ -28994,7 +29143,7 @@ var migration38 = {
28994
29143
  };
28995
29144
 
28996
29145
  // src/durable-objects/agentbuilder-migrations/0007_platform_identity_replica.ts
28997
- var migration39 = {
29146
+ var migration40 = {
28998
29147
  version: 7,
28999
29148
  async up(sql) {
29000
29149
  sql.exec(`ALTER TABLE users ADD COLUMN platform_user_id TEXT`);
@@ -29023,7 +29172,7 @@ var migration39 = {
29023
29172
  };
29024
29173
 
29025
29174
  // src/durable-objects/agentbuilder-migrations/0008_add_skills.ts
29026
- var migration40 = {
29175
+ var migration41 = {
29027
29176
  version: 8,
29028
29177
  async up(sql) {
29029
29178
  sql.exec(`
@@ -29054,7 +29203,7 @@ var migration40 = {
29054
29203
  };
29055
29204
 
29056
29205
  // src/durable-objects/agentbuilder-migrations/0009_add_user_permissions.ts
29057
- var migration41 = {
29206
+ var migration42 = {
29058
29207
  version: 9,
29059
29208
  async up(sql) {
29060
29209
  sql.exec(`ALTER TABLE users ADD COLUMN permissions TEXT`);
@@ -29065,7 +29214,7 @@ var migration41 = {
29065
29214
  };
29066
29215
 
29067
29216
  // src/durable-objects/agentbuilder-migrations/0010_add_device_logins.ts
29068
- var migration42 = {
29217
+ var migration43 = {
29069
29218
  version: 10,
29070
29219
  async up(sql) {
29071
29220
  sql.exec(`
@@ -29085,7 +29234,7 @@ var migration42 = {
29085
29234
  };
29086
29235
 
29087
29236
  // src/durable-objects/agentbuilder-migrations/index.ts
29088
- var migrations2 = [migration33, migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42];
29237
+ var migrations2 = [migration34, migration35, migration36, migration37, migration38, migration39, migration40, migration41, migration42, migration43];
29089
29238
  var LATEST_SCHEMA_VERSION2 = 10;
29090
29239
 
29091
29240
  // src/utils/crypto.ts
@@ -29848,9 +29997,9 @@ ${result ?? error ?? "No result content."}${attachmentSummary}`;
29848
29997
  }
29849
29998
  }
29850
29999
  async runMigrations(fromVersion) {
29851
- for (const migration43 of migrations2) {
29852
- if (migration43.version > fromVersion) {
29853
- await migration43.up(this.ctx.storage.sql);
30000
+ for (const migration44 of migrations2) {
30001
+ if (migration44.version > fromVersion) {
30002
+ await migration44.up(this.ctx.storage.sql);
29854
30003
  }
29855
30004
  }
29856
30005
  }