@keystrokehq/keystroke 0.1.39 → 0.1.40

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.
package/dist/agent.cjs CHANGED
@@ -10,7 +10,7 @@ let node_path = require("node:path");
10
10
  let node_os = require("node:os");
11
11
  let node_fs_promises = require("node:fs/promises");
12
12
  let node_sqlite = require("node:sqlite");
13
- //#region ../agent/dist/schemas-C8sAmmrl.mjs
13
+ //#region ../agent/dist/schemas-4m3ayl5o.mjs
14
14
  function capabilitiesFromGatewayTags(tags) {
15
15
  const set = new Set(tags ?? []);
16
16
  return {
@@ -68,7 +68,8 @@ const AgentModelIdSchema = zod.z.custom((value) => typeof value === "string" &&
68
68
  const GatewayModelPricingSchema = zod.z.object({
69
69
  input: zod.z.string().optional(),
70
70
  output: zod.z.string().optional(),
71
- input_cache_read: zod.z.string().optional()
71
+ input_cache_read: zod.z.string().optional(),
72
+ input_cache_write: zod.z.string().optional()
72
73
  });
73
74
  const GatewayModelResponseSchema = zod.z.object({
74
75
  id: zod.z.string().min(1),
@@ -156,7 +157,8 @@ async function fetchGatewayModelMetadata(modelId) {
156
157
  const pricing = {
157
158
  inputPerMillion: pricePerMillion(raw.pricing?.input),
158
159
  outputPerMillion: pricePerMillion(raw.pricing?.output),
159
- cacheReadPerMillion: pricePerMillion(raw.pricing?.input_cache_read)
160
+ cacheReadPerMillion: pricePerMillion(raw.pricing?.input_cache_read),
161
+ cacheWritePerMillion: pricePerMillion(raw.pricing?.input_cache_write)
160
162
  };
161
163
  gatewayModelCache.set(cacheKey, {
162
164
  status: "found",
@@ -1138,12 +1140,14 @@ function llmUsageFromLanguageModelUsage(usage, resolved, options) {
1138
1140
  const reasoning = usage.outputTokenDetails.reasoningTokens ?? 0;
1139
1141
  const cacheRead = usage.inputTokenDetails.cacheReadTokens ?? 0;
1140
1142
  const cacheWrite = usage.inputTokenDetails.cacheWriteTokens ?? 0;
1143
+ const noCache = usage.inputTokenDetails.noCacheTokens ?? Math.max(0, input - cacheRead - cacheWrite);
1141
1144
  const totalTokens = usage.totalTokens ?? input + output;
1142
1145
  const pricing = resolved.pricing;
1143
- const inputCost = pricing ? input / 1e6 * pricing.inputPerMillion : 0;
1146
+ const inputCost = pricing ? noCache / 1e6 * pricing.inputPerMillion : 0;
1144
1147
  const outputCost = pricing ? output / 1e6 * pricing.outputPerMillion : 0;
1145
1148
  const cacheReadCost = pricing ? cacheRead / 1e6 * pricing.cacheReadPerMillion : 0;
1146
- const total = inputCost + outputCost + cacheReadCost;
1149
+ const cacheWriteCost = pricing ? cacheWrite / 1e6 * pricing.cacheWritePerMillion : 0;
1150
+ const total = inputCost + outputCost + cacheReadCost + cacheWriteCost;
1147
1151
  const { directId } = splitAgentModelId(resolved.modelId);
1148
1152
  return {
1149
1153
  label: resolved.modelId,
@@ -1157,15 +1161,16 @@ function llmUsageFromLanguageModelUsage(usage, resolved, options) {
1157
1161
  ...options?.byok !== void 0 ? { keySource: options.byok ? "byok" : "platform" } : {},
1158
1162
  responseModel: resolved.modelId,
1159
1163
  input,
1164
+ noCache,
1160
1165
  output,
1161
1166
  reasoning,
1162
1167
  cacheRead,
1163
1168
  cacheWrite,
1164
1169
  cost: {
1165
- input: inputCost,
1170
+ noCache: inputCost,
1166
1171
  output: outputCost,
1167
1172
  cacheRead: cacheReadCost,
1168
- cacheWrite: 0,
1173
+ cacheWrite: cacheWriteCost,
1169
1174
  total
1170
1175
  }
1171
1176
  }