@standardagents/builder 0.24.4 → 0.24.6

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 (51) hide show
  1. package/dist/built-in-routes.js +173 -32
  2. package/dist/built-in-routes.js.map +1 -1
  3. package/dist/client/{ApiKeysView-1m7uIS8S.js → ApiKeysView-CmZKVcOR.js} +1 -1
  4. package/dist/client/CenteredContentView-DK7rPUK2.js +1 -0
  5. package/dist/client/{CompositionView-nzqzVKAg.js → CompositionView-BvVMnyYP.js} +1 -1
  6. package/dist/client/{ConfirmDialog.vue_vue_type_script_setup_true_lang-YX8WE_iB.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-h7YuRPAr.js} +1 -1
  7. package/dist/client/{CopyButton.vue_vue_type_script_setup_true_lang-BpJt6BT0.js → CopyButton.vue_vue_type_script_setup_true_lang-BpQ6CMUp.js} +1 -1
  8. package/dist/client/{DataTable.vue_vue_type_script_setup_true_lang-Dg3HMMJ0.js → DataTable.vue_vue_type_script_setup_true_lang-DCUZbvUM.js} +1 -1
  9. package/dist/client/{JsonViewer-BdNA5OCG.js → JsonViewer-CvwfQYW-.js} +1 -1
  10. package/dist/client/{LoginView-BlF_2TtB.js → LoginView-DnaG5knS.js} +1 -1
  11. package/dist/client/{MarketplaceView-DrlOb57k.js → MarketplaceView-fX_Juw54.js} +1 -1
  12. package/dist/client/{Modal.vue_vue_type_script_setup_true_lang-hkOmEwrb.js → Modal.vue_vue_type_script_setup_true_lang-CFFVfl1g.js} +1 -1
  13. package/dist/client/{ModelModal.vue_vue_type_script_setup_true_lang-p3esoV-i.js → ModelModal.vue_vue_type_script_setup_true_lang-B68s7Jo1.js} +1 -1
  14. package/dist/client/{ModelsView-CHBanMSH.js → ModelsView-lv4-IyA2.js} +1 -1
  15. package/dist/client/{PromptEditView-b5B43l4Q.js → PromptEditView-DGaxlMMx.js} +1 -1
  16. package/dist/client/{PromptModal-BF5bdmNQ.js → PromptModal-DaW1J_W6.js} +1 -1
  17. package/dist/client/{PromptsView-6TfMOScI.js → PromptsView-CdiBqZey.js} +1 -1
  18. package/dist/client/{ProvidersView-CA5Yx2Fn.js → ProvidersView-B37bgFKh.js} +1 -1
  19. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-DHlNdv7o.js +22 -0
  20. package/dist/client/ThreadsView-BAfuNShv.js +1 -0
  21. package/dist/client/{ToolsView-DE1TDnlU.js → ToolsView-BMKgNq7O.js} +1 -1
  22. package/dist/client/{UiCodeBlock.vue_vue_type_script_setup_true_lang-BawOR_eB.js → UiCodeBlock.vue_vue_type_script_setup_true_lang-BH3WC9G_.js} +1 -1
  23. package/dist/client/{UsersView-BXDHjJLB.js → UsersView-BDKchqNQ.js} +1 -1
  24. package/dist/client/{VariablesView-Bz-CbaEv.js → VariablesView-BPioaCbu.js} +1 -1
  25. package/dist/client/assets/{ThreadInspectorPane-DLSVKyBu.css → ThreadInspectorPane-lJJckks4.css} +1 -1
  26. package/dist/client/assets/index-Djjx6d3k.css +1 -0
  27. package/dist/client/{check-DKLwABgc.js → check-Dkzs1C3V.js} +1 -1
  28. package/dist/client/{chevron-right-DJJGHNE5.js → chevron-right-BGirddPg.js} +1 -1
  29. package/dist/client/{copy-CLWiDcxB.js → copy-C08OR8rY.js} +1 -1
  30. package/dist/client/{formkit-DcuuXZjC.js → formkit-YJ1Z7D5r.js} +1 -1
  31. package/dist/client/{index-TIntu1KJ.js → index-BVfRoUms.js} +3 -3
  32. package/dist/client/index.html +4 -4
  33. package/dist/client/{package-CarOhnUs.js → package-guyzMTDG.js} +1 -1
  34. package/dist/client/{plus-zGapov7j.js → plus-DG3ZN5wg.js} +1 -1
  35. package/dist/client/{timeAgo-ASgzq6bq.js → timeAgo-D7V247YG.js} +1 -1
  36. package/dist/client/{useActionFeedback-uUrfjlCo.js → useActionFeedback-byARNQjQ.js} +1 -1
  37. package/dist/client/vue-BqC6IZDY.js +1 -0
  38. package/dist/{index-jDKWlMKG.d.ts → index-D3FNNQWC.d.ts} +8 -1
  39. package/dist/index.d.ts +1 -1
  40. package/dist/index.js +102 -42
  41. package/dist/index.js.map +1 -1
  42. package/dist/runtime.d.ts +10 -2
  43. package/dist/runtime.js +102 -42
  44. package/dist/runtime.js.map +1 -1
  45. package/dist/test.d.ts +1 -1
  46. package/package.json +5 -5
  47. package/dist/client/CenteredContentView-DJzHRMGj.js +0 -1
  48. package/dist/client/ThreadInspectorPane.vue_vue_type_script_setup_true_lang-ejyFhmNy.js +0 -22
  49. package/dist/client/ThreadsView-yJpVmf42.js +0 -1
  50. package/dist/client/assets/index-V68N0r_5.css +0 -1
  51. package/dist/client/vue-2tGL2Ulx.js +0 -1
@@ -224,6 +224,18 @@ function getFallbackPricing(providerName, modelId) {
224
224
  const pricing = getProviderModelPricing(providerName, modelId);
225
225
  return pricing ? toResolvedModelPricing(pricing) : null;
226
226
  }
227
+ function resolveUsageReportedPricing(usage) {
228
+ const pricing = usage.pricing;
229
+ if (!pricing || typeof pricing.inputPerMillion !== "number" || typeof pricing.outputPerMillion !== "number") {
230
+ return null;
231
+ }
232
+ return {
233
+ inputPrice: pricing.inputPerMillion,
234
+ outputPrice: pricing.outputPerMillion,
235
+ cachedPrice: pricing.cachedInputPerMillion,
236
+ source: "provider"
237
+ };
238
+ }
227
239
  function resolveModelPricing(modelDef, providerName) {
228
240
  if (typeof modelDef.inputPrice === "number" && typeof modelDef.outputPrice === "number") {
229
241
  return {
@@ -252,14 +264,14 @@ function calculateUsageCost(usage, pricing) {
252
264
  const inputPrice = useLongContext ? pricing.longInputPrice ?? pricing.inputPrice : pricing.inputPrice;
253
265
  const outputPrice = useLongContext ? pricing.longOutputPrice ?? pricing.outputPrice : pricing.outputPrice;
254
266
  const cachedTokenPrice = useLongContext ? pricing.longCachedPrice ?? pricing.cachedPrice ?? pricing.inputPrice : pricing.cachedPrice ?? pricing.inputPrice;
255
- const costInput = roundCost(
256
- (uncachedPromptTokens * inputPrice + cachedTokens * cachedTokenPrice) / TOKENS_PER_MILLION
257
- );
267
+ const costInput = roundCost(uncachedPromptTokens * inputPrice / TOKENS_PER_MILLION);
268
+ const costCached = roundCost(cachedTokens * cachedTokenPrice / TOKENS_PER_MILLION);
258
269
  const costOutput = roundCost(billableOutputTokens * outputPrice / TOKENS_PER_MILLION);
259
270
  return {
260
271
  costInput,
272
+ costCached,
261
273
  costOutput,
262
- costTotal: roundCost(costInput + costOutput)
274
+ costTotal: roundCost(costInput + costCached + costOutput)
263
275
  };
264
276
  }
265
277
  var TOKENS_PER_MILLION;
@@ -1374,7 +1386,8 @@ function convertUsage(usage) {
1374
1386
  prompt_tokens_details: usage.cachedTokens ? { cached_tokens: usage.cachedTokens } : void 0,
1375
1387
  completion_tokens_details: usage.reasoningTokens ? { reasoning_tokens: usage.reasoningTokens } : void 0,
1376
1388
  cost: usage.cost,
1377
- provider: usage.provider
1389
+ provider: usage.provider,
1390
+ pricing: usage.pricing
1378
1391
  };
1379
1392
  }
1380
1393
  function inferProviderFromModelId(model) {
@@ -2069,7 +2082,7 @@ var init_LLMRequest = __esm({
2069
2082
  const toolsCalled = response.tool_calls ? JSON.stringify(response.tool_calls.map((tc) => tc.function.name)) : null;
2070
2083
  const providerName = response._provider?.name;
2071
2084
  const standardAgentsRouterUsed = response._viaPlatform === true || providerName === "platform";
2072
- const resolvedPricing = resolveModelPricing(modelDef, providerName);
2085
+ const resolvedPricing = resolveModelPricing(modelDef) ?? resolveUsageReportedPricing(response.usage) ?? resolveModelPricing(modelDef, providerName);
2073
2086
  const calculatedCost = calculateUsageCost(response.usage, resolvedPricing);
2074
2087
  const providerReportedCost = typeof response.usage.cost === "number" ? response.usage.cost : typeof response.usage.cost === "string" ? parseFloat(response.usage.cost) : null;
2075
2088
  const cost_total = providerReportedCost != null && !Number.isNaN(providerReportedCost) ? providerReportedCost : calculatedCost?.costTotal ?? null;
@@ -2136,6 +2149,7 @@ var init_LLMRequest = __esm({
2136
2149
  reasoning_tokens: response.usage.completion_tokens_details?.reasoning_tokens || 0,
2137
2150
  total_tokens: response.usage.total_tokens,
2138
2151
  cost_input: calculatedCost?.costInput,
2152
+ cost_cached: calculatedCost?.costCached,
2139
2153
  cost_output: calculatedCost?.costOutput,
2140
2154
  latency_ms: Date.now() - startTime,
2141
2155
  time_to_first_token_ms: timing?.latencyMs ?? void 0,
@@ -2165,19 +2179,20 @@ var init_LLMRequest = __esm({
2165
2179
  reasoning_tokens = ?5,
2166
2180
  total_tokens = ?6,
2167
2181
  cost_input = ?7,
2168
- cost_output = ?8,
2169
- latency_ms = ?9,
2170
- finish_reason = ?10,
2171
- tools_called = ?11,
2172
- cost_total = ?12,
2173
- is_complete = ?13,
2174
- reasoning_content = ?14,
2175
- provider_tools = ?15,
2176
- actual_provider = ?16,
2177
- standard_agents_router_used = ?17,
2178
- time_to_first_token_ms = ?18,
2179
- generation_ms = ?19
2180
- WHERE id = ?20
2182
+ cost_cached = ?8,
2183
+ cost_output = ?9,
2184
+ latency_ms = ?10,
2185
+ finish_reason = ?11,
2186
+ tools_called = ?12,
2187
+ cost_total = ?13,
2188
+ is_complete = ?14,
2189
+ reasoning_content = ?15,
2190
+ provider_tools = ?16,
2191
+ actual_provider = ?17,
2192
+ standard_agents_router_used = ?18,
2193
+ time_to_first_token_ms = ?19,
2194
+ generation_ms = ?20
2195
+ WHERE id = ?21
2181
2196
  `,
2182
2197
  logData.response_body,
2183
2198
  logData.input_tokens,
@@ -2186,6 +2201,7 @@ var init_LLMRequest = __esm({
2186
2201
  logData.reasoning_tokens,
2187
2202
  logData.total_tokens,
2188
2203
  logData.cost_input ?? null,
2204
+ logData.cost_cached ?? null,
2189
2205
  logData.cost_output ?? null,
2190
2206
  logData.latency_ms,
2191
2207
  logData.finish_reason,
@@ -56244,6 +56260,25 @@ function getModelIconDataUri(modelId) {
56244
56260
  }
56245
56261
  return void 0;
56246
56262
  }
56263
+ function usagePricingFromCatalogPricing(pricing) {
56264
+ if (!pricing) return void 0;
56265
+ const perMillion = (value) => {
56266
+ if (value === void 0) return void 0;
56267
+ const parsed = Number.parseFloat(value);
56268
+ if (!Number.isFinite(parsed)) return void 0;
56269
+ return Number((parsed * 1e6).toFixed(12));
56270
+ };
56271
+ const inputPerMillion = perMillion(pricing.prompt);
56272
+ const outputPerMillion = perMillion(pricing.completion);
56273
+ if (inputPerMillion === void 0 || outputPerMillion === void 0) {
56274
+ return void 0;
56275
+ }
56276
+ return {
56277
+ inputPerMillion,
56278
+ cachedInputPerMillion: perMillion(pricing.input_cache_read),
56279
+ outputPerMillion
56280
+ };
56281
+ }
56247
56282
  var OPENROUTER_SERVER_TOOL_NAMES, google_default3, meta_default4, mistralai_default3, moonshotai_default3, nvidia_default2, openai_default5, qwen_default4, zai_org_default4, ANTHROPIC_ICON2, GOOGLE_ICON3, META_ICON3, NVIDIA_ICON, ALIBABA_ICON2, DEEPSEEK_ICON2, QWEN_ICON2, MINIMAX_ICON, MOONSHOTAI_ICON, XAI_ICON, ZAI_ICON3, EXAONE_ICON, OPENROUTER_ICON, OPENAI_ICON4, MISTRAL_ICON2, COHERE_ICON, PERPLEXITY_ICON, LAB_ICONS, OPENROUTER_PROVIDER_ICON_PREFIX, OPENROUTER_PROVIDER_URL_ENTRIES, OPENROUTER_PROVIDER_URLS, OpenRouterProvider, percentileSchema, providerRoutingSchema, serverToolParametersSchema, serverToolsSchema, openrouterProviderOptions, openrouter;
56248
56283
  var init_dist6 = __esm({
56249
56284
  "../openrouter/dist/index.js"() {
@@ -56545,6 +56580,11 @@ var init_dist6 = __esm({
56545
56580
  static modelsCacheTime = 0;
56546
56581
  static CACHE_TTL = 5 * 60 * 1e3;
56547
56582
  // 5 minutes
56583
+ /** In-flight catalog download shared by concurrent callers. */
56584
+ static modelsFetchPromise = null;
56585
+ /** Timestamp of the last failed catalog fetch, for negative caching. */
56586
+ static modelsFetchFailedAt = 0;
56587
+ static FAILURE_RETRY_MS = 60 * 1e3;
56548
56588
  /**
56549
56589
  * Get capabilities for a specific model.
56550
56590
  * Fetches from OpenRouter's models API which provides rich metadata.
@@ -56562,19 +56602,73 @@ var init_dist6 = __esm({
56562
56602
  return null;
56563
56603
  }
56564
56604
  }
56605
+ /**
56606
+ * How long a streaming finish chunk may wait on the catalog pricing lookup.
56607
+ * The lookup is started when the stream starts, so by finish time it is
56608
+ * almost always resolved; the bound guarantees a slow catalog download can
56609
+ * never stall the finish chunk into the runtime's stream watchdog.
56610
+ */
56611
+ static USAGE_PRICING_FINISH_WAIT_MS = 2500;
56612
+ static async settleUsagePricing(pricingPromise) {
56613
+ let timer;
56614
+ const timeout = new Promise((resolve2) => {
56615
+ timer = setTimeout(() => resolve2(void 0), _OpenRouterProvider.USAGE_PRICING_FINISH_WAIT_MS);
56616
+ });
56617
+ try {
56618
+ return await Promise.race([pricingPromise, timeout]);
56619
+ } finally {
56620
+ if (timer !== void 0) clearTimeout(timer);
56621
+ }
56622
+ }
56623
+ /** Bounded-wait pricing attachment shared by the non-streaming paths. */
56624
+ async attachUsagePricing(result, pricingPromise) {
56625
+ const pricing = await _OpenRouterProvider.settleUsagePricing(pricingPromise);
56626
+ if (pricing) result.usage.pricing = pricing;
56627
+ return result;
56628
+ }
56629
+ /**
56630
+ * Exact unit prices for a model from OpenRouter's live catalog (cached),
56631
+ * attached to response usage so request logs can record specific prices.
56632
+ * Best-effort: any failure just leaves pricing off the usage payload.
56633
+ */
56634
+ async getUsagePricing(modelId) {
56635
+ if (!modelId) return void 0;
56636
+ try {
56637
+ const models = await this.fetchModelsWithCache();
56638
+ const model = models.find((m) => m.id === modelId);
56639
+ return usagePricingFromCatalogPricing(model?.pricing);
56640
+ } catch {
56641
+ return void 0;
56642
+ }
56643
+ }
56565
56644
  async fetchModelsWithCache() {
56566
56645
  const now = Date.now();
56567
56646
  if (_OpenRouterProvider.modelsCache && now - _OpenRouterProvider.modelsCacheTime < _OpenRouterProvider.CACHE_TTL) {
56568
56647
  return _OpenRouterProvider.modelsCache;
56569
56648
  }
56570
- const response = await fetch("https://openrouter.ai/api/v1/models");
56571
- if (!response.ok) {
56572
- throw new Error(`OpenRouter API error: ${response.status}`);
56649
+ if (now - _OpenRouterProvider.modelsFetchFailedAt < _OpenRouterProvider.FAILURE_RETRY_MS) {
56650
+ throw new Error("OpenRouter models fetch recently failed");
56573
56651
  }
56574
- const data = await response.json();
56575
- _OpenRouterProvider.modelsCache = data.data || [];
56576
- _OpenRouterProvider.modelsCacheTime = now;
56577
- return _OpenRouterProvider.modelsCache;
56652
+ if (!_OpenRouterProvider.modelsFetchPromise) {
56653
+ _OpenRouterProvider.modelsFetchPromise = (async () => {
56654
+ try {
56655
+ const response = await fetch("https://openrouter.ai/api/v1/models");
56656
+ if (!response.ok) {
56657
+ throw new Error(`OpenRouter API error: ${response.status}`);
56658
+ }
56659
+ const data = await response.json();
56660
+ _OpenRouterProvider.modelsCache = data.data || [];
56661
+ _OpenRouterProvider.modelsCacheTime = Date.now();
56662
+ return _OpenRouterProvider.modelsCache;
56663
+ } catch (error) {
56664
+ _OpenRouterProvider.modelsFetchFailedAt = Date.now();
56665
+ throw error;
56666
+ } finally {
56667
+ _OpenRouterProvider.modelsFetchPromise = null;
56668
+ }
56669
+ })();
56670
+ }
56671
+ return _OpenRouterProvider.modelsFetchPromise;
56578
56672
  }
56579
56673
  mapOpenRouterCapabilities(model) {
56580
56674
  const capabilities = {
@@ -56659,6 +56753,7 @@ var init_dist6 = __esm({
56659
56753
  if (this.config.providers && this.config.providers.length > 0) {
56660
56754
  params.provider = { only: this.config.providers };
56661
56755
  }
56756
+ const pricingPromise = this.getUsagePricing(params.model);
56662
56757
  const response = await fetch(`${baseUrl}/chat/completions`, {
56663
56758
  method: "POST",
56664
56759
  headers: {
@@ -56680,7 +56775,7 @@ var init_dist6 = __esm({
56680
56775
  throw new ProviderError(errorMessage, "invalid_request", response.status);
56681
56776
  }
56682
56777
  const data = await response.json();
56683
- return transformChatResponse3(data);
56778
+ return this.attachUsagePricing(transformChatResponse3(data), pricingPromise);
56684
56779
  } catch (error) {
56685
56780
  throw this.toProviderError(error);
56686
56781
  }
@@ -56694,6 +56789,7 @@ var init_dist6 = __esm({
56694
56789
  try {
56695
56790
  const params = buildCreateParams3(request);
56696
56791
  this.applyConfiguredProvidersToResponses(params);
56792
+ const pricingPromise = this.getUsagePricing(params.model);
56697
56793
  if (this.hasOpenRouterServerTools(params)) {
56698
56794
  const response2 = await fetch(`${baseUrl}/responses`, {
56699
56795
  method: "POST",
@@ -56711,14 +56807,14 @@ var init_dist6 = __esm({
56711
56807
  await this.throwOpenRouterFetchError(response2);
56712
56808
  }
56713
56809
  const data = await response2.json();
56714
- return transformResponse3(data);
56810
+ return this.attachUsagePricing(transformResponse3(data), pricingPromise);
56715
56811
  }
56716
56812
  const client = await this.getClient();
56717
56813
  const response = await client.beta.responses.send({
56718
56814
  ...this.toSdkResponsesRequest(params),
56719
56815
  stream: false
56720
56816
  });
56721
- return transformResponse3(response);
56817
+ return this.attachUsagePricing(transformResponse3(response), pricingPromise);
56722
56818
  } catch (error) {
56723
56819
  throw this.toProviderError(error);
56724
56820
  }
@@ -56742,6 +56838,7 @@ var init_dist6 = __esm({
56742
56838
  if (this.config.providers && this.config.providers.length > 0) {
56743
56839
  params.provider = { only: this.config.providers };
56744
56840
  }
56841
+ const pricingPromise = this.getUsagePricing(params.model);
56745
56842
  const response = await fetch(`${baseUrl}/chat/completions`, {
56746
56843
  method: "POST",
56747
56844
  headers: {
@@ -56781,6 +56878,10 @@ var init_dist6 = __esm({
56781
56878
  }
56782
56879
  }
56783
56880
  if (finishChunk) {
56881
+ if (finishChunk.type === "finish") {
56882
+ const pricing = await _OpenRouterProvider.settleUsagePricing(pricingPromise);
56883
+ if (pricing) finishChunk.usage.pricing = pricing;
56884
+ }
56784
56885
  const finishWithMeta = {
56785
56886
  ...finishChunk,
56786
56887
  _asyncMetadata: responseId ? {
@@ -56811,6 +56912,7 @@ var init_dist6 = __esm({
56811
56912
  try {
56812
56913
  const params = buildCreateParams3(request);
56813
56914
  this.applyConfiguredProvidersToResponses(params);
56915
+ const pricingPromise = this.getUsagePricing(params.model);
56814
56916
  const response = await fetch(`${baseUrl}/responses`, {
56815
56917
  method: "POST",
56816
56918
  headers: {
@@ -56849,6 +56951,10 @@ var init_dist6 = __esm({
56849
56951
  }
56850
56952
  }
56851
56953
  if (finishChunk) {
56954
+ if (finishChunk.type === "finish") {
56955
+ const pricing = await _OpenRouterProvider.settleUsagePricing(pricingPromise);
56956
+ if (pricing) finishChunk.usage.pricing = pricing;
56957
+ }
56852
56958
  const finishWithMeta = {
56853
56959
  ...finishChunk,
56854
56960
  // Include what's needed to fetch metadata later
@@ -69109,14 +69215,31 @@ var continue_post_default = defineController2(async ({ req, params, env: env2 })
69109
69215
 
69110
69216
  // src/agents/cost-summary.ts
69111
69217
  function emptyCostSummary() {
69112
- return { totalCost: 0, requestCount: 0, messageCount: 0, byModel: {} };
69218
+ return {
69219
+ totalCost: 0,
69220
+ inputCost: 0,
69221
+ cachedCost: 0,
69222
+ outputCost: 0,
69223
+ requestCount: 0,
69224
+ messageCount: 0,
69225
+ byModel: {}
69226
+ };
69113
69227
  }
69114
69228
  function mergeByModel(summaries) {
69115
69229
  const merged = {};
69116
69230
  for (const summary of summaries) {
69117
69231
  for (const [modelName, acc] of Object.entries(summary.byModel)) {
69118
- const entry = merged[modelName] ?? { totalCost: 0, count: 0 };
69232
+ const entry = merged[modelName] ?? {
69233
+ totalCost: 0,
69234
+ inputCost: 0,
69235
+ cachedCost: 0,
69236
+ outputCost: 0,
69237
+ count: 0
69238
+ };
69119
69239
  entry.totalCost += acc.totalCost;
69240
+ entry.inputCost = (entry.inputCost ?? 0) + (acc.inputCost ?? 0);
69241
+ entry.cachedCost = (entry.cachedCost ?? 0) + (acc.cachedCost ?? 0);
69242
+ entry.outputCost = (entry.outputCost ?? 0) + (acc.outputCost ?? 0);
69120
69243
  entry.count += acc.count;
69121
69244
  merged[modelName] = entry;
69122
69245
  }
@@ -69125,19 +69248,28 @@ function mergeByModel(summaries) {
69125
69248
  }
69126
69249
  function sumSummaries(summaries) {
69127
69250
  let totalCost = 0;
69251
+ let inputCost = 0;
69252
+ let cachedCost = 0;
69253
+ let outputCost = 0;
69128
69254
  let requestCount = 0;
69129
69255
  let messageCount = 0;
69130
69256
  for (const summary of summaries) {
69131
69257
  totalCost += summary.totalCost;
69258
+ inputCost += summary.inputCost ?? 0;
69259
+ cachedCost += summary.cachedCost ?? 0;
69260
+ outputCost += summary.outputCost ?? 0;
69132
69261
  requestCount += summary.requestCount;
69133
69262
  messageCount += summary.messageCount;
69134
69263
  }
69135
- return { totalCost, requestCount, messageCount };
69264
+ return { totalCost, inputCost, cachedCost, outputCost, requestCount, messageCount };
69136
69265
  }
69137
69266
  function buildModelBreakdown(byModel) {
69138
69267
  return Object.entries(byModel).map(([modelName, acc]) => ({
69139
69268
  modelName,
69140
69269
  totalCost: acc.totalCost,
69270
+ inputCost: acc.inputCost ?? 0,
69271
+ cachedCost: acc.cachedCost ?? 0,
69272
+ outputCost: acc.outputCost ?? 0,
69141
69273
  requestCount: acc.count,
69142
69274
  avgCostPerRequest: acc.count > 0 ? acc.totalCost / acc.count : 0
69143
69275
  })).sort((a, b) => b.totalCost - a.totalCost);
@@ -69212,6 +69344,9 @@ var cost_get_default = defineController2(async ({ req, params, env: env2 }) => {
69212
69344
  parent: null,
69213
69345
  isRoot: true,
69214
69346
  totalCost: ownSummary.totalCost,
69347
+ inputCost: ownSummary.inputCost ?? 0,
69348
+ cachedCost: ownSummary.cachedCost ?? 0,
69349
+ outputCost: ownSummary.outputCost ?? 0,
69215
69350
  requestCount: ownSummary.requestCount
69216
69351
  },
69217
69352
  ...descendants.map((child, index) => ({
@@ -69221,11 +69356,17 @@ var cost_get_default = defineController2(async ({ req, params, env: env2 }) => {
69221
69356
  parent: child.parent,
69222
69357
  isRoot: false,
69223
69358
  totalCost: descendantSummaries[index]?.totalCost ?? 0,
69359
+ inputCost: descendantSummaries[index]?.inputCost ?? 0,
69360
+ cachedCost: descendantSummaries[index]?.cachedCost ?? 0,
69361
+ outputCost: descendantSummaries[index]?.outputCost ?? 0,
69224
69362
  requestCount: descendantSummaries[index]?.requestCount ?? 0
69225
69363
  })).filter((row) => row.requestCount > 0)
69226
69364
  ];
69227
69365
  return Response.json({
69228
69366
  totalCost: totals.totalCost,
69367
+ inputCost: totals.inputCost,
69368
+ cachedCost: totals.cachedCost,
69369
+ outputCost: totals.outputCost,
69229
69370
  ownCost: ownSummary.totalCost,
69230
69371
  requestCount: totals.requestCount,
69231
69372
  messageCount: totals.messageCount,