@livx.cc/agentx 0.99.131 → 0.99.133

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/cli.d.ts CHANGED
@@ -266,11 +266,14 @@ declare function cacheMultipliers(model?: string): {
266
266
  write: number;
267
267
  };
268
268
  /** USD cost from a model's per-1K pricing (ai.libx.js ModelPricing) + token usage. 0 if unpriced.
269
- * Cache-aware: promptTokens includes cache reads/writes — priced at the provider's real multipliers
270
- * (via `model`) so cached runs aren't overstated. Omitting `model` falls back to Anthropic's rates. */
269
+ * Cache-aware: promptTokens includes cache reads/writes. The catalog's own cache prices
270
+ * (`cacheCostPer1K` / `cacheWriteCostPer1K`) win; otherwise the provider's multipliers (via `model`)
271
+ * apply. Omitting `model` falls back to Anthropic's rates. */
271
272
  declare function costOf(pricing: {
272
273
  inputCostPer1K: number;
273
274
  outputCostPer1K: number;
275
+ cacheCostPer1K?: number;
276
+ cacheWriteCostPer1K?: number;
274
277
  } | undefined, promptTokens?: number, completionTokens?: number, cacheCreationTokens?: number, cacheReadTokens?: number, model?: string): number;
275
278
  /** Cost of one turn at `model`'s rate (looks up ai.libx.js pricing). Subscription `claude-code/<alias>` models
276
279
  * are priced at their API-equivalent Anthropic rate so auto-vs-pinned comparisons stay meaningful. */
package/dist/cli.js CHANGED
@@ -6232,7 +6232,7 @@ ${out}`;
6232
6232
  o.host?.notify?.({ kind: "compaction", message: `context full \u2014 auto-trimmed ${dropped} oldest message(s) to fit ~${Math.round(o.maxContextTokens / 1e3)}k tokens` });
6233
6233
  }
6234
6234
  }
6235
- out = dropOrphanToolResults(out);
6235
+ out = answerOpenToolCalls(dropOrphanToolResults(out));
6236
6236
  if (/^google\//.test(o.model ?? "")) out = hoistToolImages(out);
6237
6237
  return scrubBase64(out);
6238
6238
  }
@@ -6408,6 +6408,20 @@ var callIdSet = (msgs) => {
6408
6408
  for (const m of msgs) if (m.role === "assistant") for (const tc of m.tool_calls ?? []) ids.add(tc.id);
6409
6409
  return ids;
6410
6410
  };
6411
+ function answerOpenToolCalls(messages) {
6412
+ const answered = new Set(messages.filter((m) => m.role === "tool").map((m) => m.tool_call_id ?? ""));
6413
+ if (messages.every((m) => m.role !== "assistant" || (m.tool_calls ?? []).every((tc) => answered.has(tc.id)))) return messages;
6414
+ const out = [];
6415
+ for (let i = 0; i < messages.length; i++) {
6416
+ const m = messages[i];
6417
+ out.push(m);
6418
+ const open = m.role === "assistant" ? (m.tool_calls ?? []).filter((tc) => !answered.has(tc.id)) : [];
6419
+ if (!open.length) continue;
6420
+ while (i + 1 < messages.length && messages[i + 1].role === "tool") out.push(messages[++i]);
6421
+ for (const tc of open) out.push({ role: "tool", tool_call_id: tc.id, name: tc.function?.name, content: "not run \u2014 the turn stopped before this call (a limit or an interruption); run it again if it is still needed" });
6422
+ }
6423
+ return out;
6424
+ }
6411
6425
  function dropOrphanToolResults(messages) {
6412
6426
  const ids = callIdSet(messages);
6413
6427
  const ok = (m) => m.role !== "tool" || ids.has(m.tool_call_id ?? "");
@@ -20247,7 +20261,7 @@ function costOf(pricing, promptTokens = 0, completionTokens = 0, cacheCreationTo
20247
20261
  if (!pricing) return 0;
20248
20262
  const mult = model ? cacheMultipliers(model) : { read: 0.1, write: 1.25 };
20249
20263
  const fresh = Math.max(0, promptTokens - cacheCreationTokens - cacheReadTokens);
20250
- return fresh / 1e3 * pricing.inputCostPer1K + cacheCreationTokens / 1e3 * pricing.inputCostPer1K * mult.write + cacheReadTokens / 1e3 * pricing.inputCostPer1K * mult.read + completionTokens / 1e3 * pricing.outputCostPer1K;
20264
+ return fresh / 1e3 * pricing.inputCostPer1K + cacheCreationTokens / 1e3 * (pricing.cacheWriteCostPer1K ?? pricing.inputCostPer1K * mult.write) + cacheReadTokens / 1e3 * (pricing.cacheCostPer1K ?? pricing.inputCostPer1K * mult.read) + completionTokens / 1e3 * pricing.outputCostPer1K;
20251
20265
  }
20252
20266
  var autoModels = () => ({ ...new ModelRouterOptions().models, ...JSON.parse(process.env.AGENTX_AUTO_MODELS || "{}") });
20253
20267
  function autoRouteSend(args, agent, session, pof) {