@blockrun/clawrouter 0.11.10 → 0.11.12
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/README.md +1 -1
- package/dist/cli.js +13 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/scripts/update.sh +33 -23
package/dist/index.d.ts
CHANGED
|
@@ -770,6 +770,8 @@ type UsageEntry = {
|
|
|
770
770
|
baselineCost: number;
|
|
771
771
|
savings: number;
|
|
772
772
|
latencyMs: number;
|
|
773
|
+
/** Input (prompt) tokens reported by the provider */
|
|
774
|
+
inputTokens?: number;
|
|
773
775
|
/** Partner service ID (e.g., "x_users_lookup") — only set for partner API calls */
|
|
774
776
|
partnerId?: string;
|
|
775
777
|
/** Partner service name (e.g., "AttentionVC") — only set for partner API calls */
|
package/dist/index.js
CHANGED
|
@@ -5335,6 +5335,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5335
5335
|
let maxTokens = 4096;
|
|
5336
5336
|
let routingProfile = null;
|
|
5337
5337
|
let accumulatedContent = "";
|
|
5338
|
+
let responseInputTokens;
|
|
5338
5339
|
const isChatCompletion = req.url?.includes("/chat/completions");
|
|
5339
5340
|
const sessionId = getSessionId(req.headers);
|
|
5340
5341
|
let effectiveSessionId = sessionId;
|
|
@@ -5770,7 +5771,8 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5770
5771
|
};
|
|
5771
5772
|
}
|
|
5772
5773
|
const lastAssistantMsg = [...parsedMessages].reverse().find((m) => m.role === "assistant");
|
|
5773
|
-
const
|
|
5774
|
+
const assistantToolCalls = lastAssistantMsg?.tool_calls;
|
|
5775
|
+
const toolCallNames = Array.isArray(assistantToolCalls) ? assistantToolCalls.map((tc) => tc.function?.name).filter((n) => Boolean(n)) : void 0;
|
|
5774
5776
|
const contentHash = hashRequestContent(prompt, toolCallNames);
|
|
5775
5777
|
const shouldEscalate = sessionStore.recordRequestHash(effectiveSessionId, contentHash);
|
|
5776
5778
|
if (shouldEscalate) {
|
|
@@ -6189,6 +6191,10 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6189
6191
|
const jsonStr = jsonBody.toString();
|
|
6190
6192
|
try {
|
|
6191
6193
|
const rsp = JSON.parse(jsonStr);
|
|
6194
|
+
if (rsp.usage && typeof rsp.usage === "object") {
|
|
6195
|
+
const u = rsp.usage;
|
|
6196
|
+
if (typeof u.prompt_tokens === "number") responseInputTokens = u.prompt_tokens;
|
|
6197
|
+
}
|
|
6192
6198
|
const baseChunk = {
|
|
6193
6199
|
id: rsp.id ?? `chatcmpl-${Date.now()}`,
|
|
6194
6200
|
object: "chat.completion.chunk",
|
|
@@ -6337,6 +6343,10 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6337
6343
|
if (rspJson.choices?.[0]?.message?.content) {
|
|
6338
6344
|
accumulatedContent = rspJson.choices[0].message.content;
|
|
6339
6345
|
}
|
|
6346
|
+
if (rspJson.usage && typeof rspJson.usage === "object") {
|
|
6347
|
+
if (typeof rspJson.usage.prompt_tokens === "number")
|
|
6348
|
+
responseInputTokens = rspJson.usage.prompt_tokens;
|
|
6349
|
+
}
|
|
6340
6350
|
} catch {
|
|
6341
6351
|
}
|
|
6342
6352
|
}
|
|
@@ -6385,7 +6395,8 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6385
6395
|
cost: costWithBuffer,
|
|
6386
6396
|
baselineCost: baselineWithBuffer,
|
|
6387
6397
|
savings: accurateCosts.savings,
|
|
6388
|
-
latencyMs: Date.now() - startTime
|
|
6398
|
+
latencyMs: Date.now() - startTime,
|
|
6399
|
+
...responseInputTokens !== void 0 && { inputTokens: responseInputTokens }
|
|
6389
6400
|
};
|
|
6390
6401
|
logUsage(entry).catch(() => {
|
|
6391
6402
|
});
|