@quantish/agent 0.1.23 → 0.1.24
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 +55 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2834,17 +2834,33 @@ var OpenRouterClient = class {
|
|
|
2834
2834
|
}
|
|
2835
2835
|
};
|
|
2836
2836
|
function calculateOpenRouterCost(modelId, inputTokens, outputTokens, cacheReadTokens = 0, cacheWriteTokens = 0) {
|
|
2837
|
-
|
|
2837
|
+
let config = getOpenRouterModelConfig(modelId);
|
|
2838
|
+
if (!config) {
|
|
2839
|
+
config = getOpenRouterModelConfig(modelId.toLowerCase());
|
|
2840
|
+
}
|
|
2841
|
+
if (!config) {
|
|
2842
|
+
const lower = modelId.toLowerCase();
|
|
2843
|
+
for (const [key, model] of Object.entries(OPENROUTER_MODELS2)) {
|
|
2844
|
+
if (key.toLowerCase() === lower || model.name.toLowerCase() === lower) {
|
|
2845
|
+
config = model;
|
|
2846
|
+
break;
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
if (!config && OPENROUTER_ALIASES[lower]) {
|
|
2850
|
+
config = OPENROUTER_MODELS2[OPENROUTER_ALIASES[lower]];
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2838
2853
|
const pricing = config?.pricing ?? {
|
|
2839
|
-
inputPerMTok:
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2854
|
+
inputPerMTok: 0.4,
|
|
2855
|
+
// GLM 4.7 pricing as fallback
|
|
2856
|
+
outputPerMTok: 1.5,
|
|
2857
|
+
cacheReadPerMTok: 0,
|
|
2858
|
+
cacheWritePerMTok: 0
|
|
2843
2859
|
};
|
|
2844
2860
|
const inputCost = inputTokens / 1e6 * pricing.inputPerMTok;
|
|
2845
2861
|
const outputCost = outputTokens / 1e6 * pricing.outputPerMTok;
|
|
2846
|
-
const cacheReadCost = cacheReadTokens / 1e6 * (pricing.cacheReadPerMTok ??
|
|
2847
|
-
const cacheWriteCost = cacheWriteTokens / 1e6 * (pricing.cacheWritePerMTok ??
|
|
2862
|
+
const cacheReadCost = cacheReadTokens / 1e6 * (pricing.cacheReadPerMTok ?? 0);
|
|
2863
|
+
const cacheWriteCost = cacheWriteTokens / 1e6 * (pricing.cacheWritePerMTok ?? 0);
|
|
2848
2864
|
return {
|
|
2849
2865
|
inputCost,
|
|
2850
2866
|
outputCost,
|
|
@@ -3613,7 +3629,7 @@ ${userMessage}`;
|
|
|
3613
3629
|
output_tokens: response.usage.outputTokens,
|
|
3614
3630
|
cache_creation_input_tokens: response.usage.cacheCreationTokens,
|
|
3615
3631
|
cache_read_input_tokens: response.usage.cacheReadTokens
|
|
3616
|
-
});
|
|
3632
|
+
}, response.cost);
|
|
3617
3633
|
const responseContent = [];
|
|
3618
3634
|
if (response.text) {
|
|
3619
3635
|
responseContent.push({ type: "text", text: response.text });
|
|
@@ -3950,15 +3966,17 @@ ${userMessage}`;
|
|
|
3950
3966
|
}
|
|
3951
3967
|
/**
|
|
3952
3968
|
* Update cumulative token usage from API response
|
|
3969
|
+
* @param usage - Token counts from the API response
|
|
3970
|
+
* @param preCalculatedCost - Optional pre-calculated cost (from OpenRouter provider)
|
|
3953
3971
|
*/
|
|
3954
|
-
updateTokenUsage(usage) {
|
|
3972
|
+
updateTokenUsage(usage, preCalculatedCost) {
|
|
3955
3973
|
const model = this.config.model ?? DEFAULT_MODEL;
|
|
3956
3974
|
this.cumulativeTokenUsage.inputTokens = usage.input_tokens;
|
|
3957
3975
|
this.cumulativeTokenUsage.outputTokens += usage.output_tokens;
|
|
3958
3976
|
this.cumulativeTokenUsage.cacheCreationInputTokens = usage.cache_creation_input_tokens || 0;
|
|
3959
3977
|
this.cumulativeTokenUsage.cacheReadInputTokens = usage.cache_read_input_tokens || 0;
|
|
3960
3978
|
this.cumulativeTokenUsage.totalTokens = this.cumulativeTokenUsage.inputTokens + this.cumulativeTokenUsage.outputTokens;
|
|
3961
|
-
const callCost = calculateCost(
|
|
3979
|
+
const callCost = preCalculatedCost ?? calculateCost(
|
|
3962
3980
|
model,
|
|
3963
3981
|
usage.input_tokens,
|
|
3964
3982
|
usage.output_tokens,
|
|
@@ -5047,16 +5065,22 @@ Use /load <id> to load a session.`
|
|
|
5047
5065
|
setIsProcessing(false);
|
|
5048
5066
|
setThinkingText(null);
|
|
5049
5067
|
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
5068
|
}
|
|
5059
|
-
}, [agent, isProcessing, isInterrupted, exit, onExit, handleSlashCommand
|
|
5069
|
+
}, [agent, isProcessing, isInterrupted, exit, onExit, handleSlashCommand]);
|
|
5070
|
+
useEffect(() => {
|
|
5071
|
+
if (!isProcessing && hasQueuedMessage && queuedInput) {
|
|
5072
|
+
const nextMessage = queuedInput;
|
|
5073
|
+
setQueuedInput("");
|
|
5074
|
+
setHasQueuedMessage(false);
|
|
5075
|
+
setMessages((prev) => prev.filter(
|
|
5076
|
+
(m) => !(m.role === "system" && m.content.startsWith("\u{1F4E5} Queued:"))
|
|
5077
|
+
));
|
|
5078
|
+
const timer = setTimeout(() => {
|
|
5079
|
+
handleSubmit(nextMessage);
|
|
5080
|
+
}, 150);
|
|
5081
|
+
return () => clearTimeout(timer);
|
|
5082
|
+
}
|
|
5083
|
+
}, [isProcessing, hasQueuedMessage, queuedInput, handleSubmit]);
|
|
5060
5084
|
useEffect(() => {
|
|
5061
5085
|
const originalConfig = agent.config;
|
|
5062
5086
|
agent.config = {
|
|
@@ -5111,6 +5135,14 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5111
5135
|
onExit?.();
|
|
5112
5136
|
exit();
|
|
5113
5137
|
}
|
|
5138
|
+
if (key.backspace && input === "" && hasQueuedMessage && queuedInput) {
|
|
5139
|
+
setInput(queuedInput);
|
|
5140
|
+
setQueuedInput("");
|
|
5141
|
+
setHasQueuedMessage(false);
|
|
5142
|
+
setMessages((prev) => prev.filter(
|
|
5143
|
+
(m) => !(m.role === "system" && m.content.startsWith("\u{1F4E5} Queued:"))
|
|
5144
|
+
));
|
|
5145
|
+
}
|
|
5114
5146
|
if (key.escape && isProcessing) {
|
|
5115
5147
|
setIsInterrupted(true);
|
|
5116
5148
|
abortController.current?.abort();
|
|
@@ -5187,9 +5219,10 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5187
5219
|
"\u274C Error: ",
|
|
5188
5220
|
error2
|
|
5189
5221
|
] }) }),
|
|
5190
|
-
isProcessing &&
|
|
5222
|
+
isProcessing && /* @__PURE__ */ jsx(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: "cyan", children: [
|
|
5191
5223
|
/* @__PURE__ */ jsx(Spinner, { type: "dots" }),
|
|
5192
|
-
"
|
|
5224
|
+
" ",
|
|
5225
|
+
currentToolCalls.length > 0 ? `Working... (${currentToolCalls.filter((tc) => tc.pending).length} tool${currentToolCalls.filter((tc) => tc.pending).length !== 1 ? "s" : ""} running)` : streamingText ? "Generating..." : "Thinking..."
|
|
5193
5226
|
] }) }),
|
|
5194
5227
|
input.startsWith("/") && !isProcessing && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, paddingLeft: 2, children: [
|
|
5195
5228
|
/* @__PURE__ */ jsx(Text, { color: "gray", dimColor: true, children: "Commands:" }),
|
|
@@ -5251,7 +5284,7 @@ Stopped ${count} background process${count > 1 ? "es" : ""}.`);
|
|
|
5251
5284
|
}
|
|
5252
5285
|
|
|
5253
5286
|
// src/index.ts
|
|
5254
|
-
var VERSION = "0.1.
|
|
5287
|
+
var VERSION = "0.1.24";
|
|
5255
5288
|
function cleanup() {
|
|
5256
5289
|
if (processManager.hasRunning()) {
|
|
5257
5290
|
const count = processManager.runningCount();
|