@quantish/agent 0.1.23 → 0.1.25
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/index.js +61 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2348,9 +2348,13 @@ function calculateCostWithPricing(pricing, inputTokens, outputTokens, cacheCreat
|
|
|
2348
2348
|
}
|
|
2349
2349
|
function formatCost(cost) {
|
|
2350
2350
|
if (cost < 0.01) {
|
|
2351
|
-
|
|
2351
|
+
const cents = cost * 100;
|
|
2352
|
+
return `${cents.toFixed(3)}\xA2`;
|
|
2352
2353
|
}
|
|
2353
|
-
|
|
2354
|
+
if (cost < 1) {
|
|
2355
|
+
return `$${cost.toFixed(4)}`;
|
|
2356
|
+
}
|
|
2357
|
+
return `$${cost.toFixed(2)}`;
|
|
2354
2358
|
}
|
|
2355
2359
|
function listModels() {
|
|
2356
2360
|
return Object.values(MODELS);
|
|
@@ -2834,17 +2838,33 @@ var OpenRouterClient = class {
|
|
|
2834
2838
|
}
|
|
2835
2839
|
};
|
|
2836
2840
|
function calculateOpenRouterCost(modelId, inputTokens, outputTokens, cacheReadTokens = 0, cacheWriteTokens = 0) {
|
|
2837
|
-
|
|
2841
|
+
let config = getOpenRouterModelConfig(modelId);
|
|
2842
|
+
if (!config) {
|
|
2843
|
+
config = getOpenRouterModelConfig(modelId.toLowerCase());
|
|
2844
|
+
}
|
|
2845
|
+
if (!config) {
|
|
2846
|
+
const lower = modelId.toLowerCase();
|
|
2847
|
+
for (const [key, model] of Object.entries(OPENROUTER_MODELS2)) {
|
|
2848
|
+
if (key.toLowerCase() === lower || model.name.toLowerCase() === lower) {
|
|
2849
|
+
config = model;
|
|
2850
|
+
break;
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
if (!config && OPENROUTER_ALIASES[lower]) {
|
|
2854
|
+
config = OPENROUTER_MODELS2[OPENROUTER_ALIASES[lower]];
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2838
2857
|
const pricing = config?.pricing ?? {
|
|
2839
|
-
inputPerMTok:
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2858
|
+
inputPerMTok: 0.4,
|
|
2859
|
+
// GLM 4.7 pricing as fallback
|
|
2860
|
+
outputPerMTok: 1.5,
|
|
2861
|
+
cacheReadPerMTok: 0,
|
|
2862
|
+
cacheWritePerMTok: 0
|
|
2843
2863
|
};
|
|
2844
2864
|
const inputCost = inputTokens / 1e6 * pricing.inputPerMTok;
|
|
2845
2865
|
const outputCost = outputTokens / 1e6 * pricing.outputPerMTok;
|
|
2846
|
-
const cacheReadCost = cacheReadTokens / 1e6 * (pricing.cacheReadPerMTok ??
|
|
2847
|
-
const cacheWriteCost = cacheWriteTokens / 1e6 * (pricing.cacheWritePerMTok ??
|
|
2866
|
+
const cacheReadCost = cacheReadTokens / 1e6 * (pricing.cacheReadPerMTok ?? 0);
|
|
2867
|
+
const cacheWriteCost = cacheWriteTokens / 1e6 * (pricing.cacheWritePerMTok ?? 0);
|
|
2848
2868
|
return {
|
|
2849
2869
|
inputCost,
|
|
2850
2870
|
outputCost,
|
|
@@ -3613,7 +3633,7 @@ ${userMessage}`;
|
|
|
3613
3633
|
output_tokens: response.usage.outputTokens,
|
|
3614
3634
|
cache_creation_input_tokens: response.usage.cacheCreationTokens,
|
|
3615
3635
|
cache_read_input_tokens: response.usage.cacheReadTokens
|
|
3616
|
-
});
|
|
3636
|
+
}, response.cost);
|
|
3617
3637
|
const responseContent = [];
|
|
3618
3638
|
if (response.text) {
|
|
3619
3639
|
responseContent.push({ type: "text", text: response.text });
|
|
@@ -3950,15 +3970,17 @@ ${userMessage}`;
|
|
|
3950
3970
|
}
|
|
3951
3971
|
/**
|
|
3952
3972
|
* Update cumulative token usage from API response
|
|
3973
|
+
* @param usage - Token counts from the API response
|
|
3974
|
+
* @param preCalculatedCost - Optional pre-calculated cost (from OpenRouter provider)
|
|
3953
3975
|
*/
|
|
3954
|
-
updateTokenUsage(usage) {
|
|
3976
|
+
updateTokenUsage(usage, preCalculatedCost) {
|
|
3955
3977
|
const model = this.config.model ?? DEFAULT_MODEL;
|
|
3956
3978
|
this.cumulativeTokenUsage.inputTokens = usage.input_tokens;
|
|
3957
3979
|
this.cumulativeTokenUsage.outputTokens += usage.output_tokens;
|
|
3958
3980
|
this.cumulativeTokenUsage.cacheCreationInputTokens = usage.cache_creation_input_tokens || 0;
|
|
3959
3981
|
this.cumulativeTokenUsage.cacheReadInputTokens = usage.cache_read_input_tokens || 0;
|
|
3960
3982
|
this.cumulativeTokenUsage.totalTokens = this.cumulativeTokenUsage.inputTokens + this.cumulativeTokenUsage.outputTokens;
|
|
3961
|
-
const callCost = calculateCost(
|
|
3983
|
+
const callCost = preCalculatedCost ?? calculateCost(
|
|
3962
3984
|
model,
|
|
3963
3985
|
usage.input_tokens,
|
|
3964
3986
|
usage.output_tokens,
|
|
@@ -5047,16 +5069,22 @@ Use /load <id> to load a session.`
|
|
|
5047
5069
|
setIsProcessing(false);
|
|
5048
5070
|
setThinkingText(null);
|
|
5049
5071
|
abortController.current = null;
|
|
5050
|
-
if (hasQueuedMessage && queuedInput) {
|
|
5051
|
-
const nextMessage = queuedInput;
|
|
5052
|
-
setQueuedInput("");
|
|
5053
|
-
setHasQueuedMessage(false);
|
|
5054
|
-
setTimeout(() => {
|
|
5055
|
-
handleSubmit(nextMessage);
|
|
5056
|
-
}, 100);
|
|
5057
|
-
}
|
|
5058
5072
|
}
|
|
5059
|
-
}, [agent, isProcessing, isInterrupted, exit, onExit, handleSlashCommand
|
|
5073
|
+
}, [agent, isProcessing, isInterrupted, exit, onExit, handleSlashCommand]);
|
|
5074
|
+
useEffect(() => {
|
|
5075
|
+
if (!isProcessing && hasQueuedMessage && queuedInput) {
|
|
5076
|
+
const nextMessage = queuedInput;
|
|
5077
|
+
setQueuedInput("");
|
|
5078
|
+
setHasQueuedMessage(false);
|
|
5079
|
+
setMessages((prev) => prev.filter(
|
|
5080
|
+
(m) => !(m.role === "system" && m.content.startsWith("\u{1F4E5} Queued:"))
|
|
5081
|
+
));
|
|
5082
|
+
const timer = setTimeout(() => {
|
|
5083
|
+
handleSubmit(nextMessage);
|
|
5084
|
+
}, 150);
|
|
5085
|
+
return () => clearTimeout(timer);
|
|
5086
|
+
}
|
|
5087
|
+
}, [isProcessing, hasQueuedMessage, queuedInput, handleSubmit]);
|
|
5060
5088
|
useEffect(() => {
|
|
5061
5089
|
const originalConfig = agent.config;
|
|
5062
5090
|
agent.config = {
|
|
@@ -5111,6 +5139,14 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5111
5139
|
onExit?.();
|
|
5112
5140
|
exit();
|
|
5113
5141
|
}
|
|
5142
|
+
if (key.backspace && input === "" && hasQueuedMessage && queuedInput) {
|
|
5143
|
+
setInput(queuedInput);
|
|
5144
|
+
setQueuedInput("");
|
|
5145
|
+
setHasQueuedMessage(false);
|
|
5146
|
+
setMessages((prev) => prev.filter(
|
|
5147
|
+
(m) => !(m.role === "system" && m.content.startsWith("\u{1F4E5} Queued:"))
|
|
5148
|
+
));
|
|
5149
|
+
}
|
|
5114
5150
|
if (key.escape && isProcessing) {
|
|
5115
5151
|
setIsInterrupted(true);
|
|
5116
5152
|
abortController.current?.abort();
|
|
@@ -5187,9 +5223,10 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5187
5223
|
"\u274C Error: ",
|
|
5188
5224
|
error2
|
|
5189
5225
|
] }) }),
|
|
5190
|
-
isProcessing &&
|
|
5226
|
+
isProcessing && /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: "cyan", children: [
|
|
5191
5227
|
/* @__PURE__ */ jsx(Spinner, { type: "dots" }),
|
|
5192
|
-
"
|
|
5228
|
+
" ",
|
|
5229
|
+
currentToolCalls.length > 0 ? `Working... (${currentToolCalls.filter((tc) => tc.pending).length} tool${currentToolCalls.filter((tc) => tc.pending).length !== 1 ? "s" : ""} running)` : streamingText ? "Generating..." : "Thinking..."
|
|
5193
5230
|
] }) }),
|
|
5194
5231
|
input.startsWith("/") && !isProcessing && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2, children: [
|
|
5195
5232
|
/* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "Commands:" }),
|
|
@@ -5251,7 +5288,7 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5251
5288
|
}
|
|
5252
5289
|
|
|
5253
5290
|
// src/index.ts
|
|
5254
|
-
var VERSION = "0.1.
|
|
5291
|
+
var VERSION = "0.1.25";
|
|
5255
5292
|
function cleanup() {
|
|
5256
5293
|
if (processManager.hasRunning()) {
|
|
5257
5294
|
const count = processManager.runningCount();
|