@blockrun/clawrouter 0.12.93 → 0.12.94
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.js +76 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -924,6 +924,8 @@ type UsageEntry = {
|
|
|
924
924
|
baselineCost: number;
|
|
925
925
|
savings: number;
|
|
926
926
|
latencyMs: number;
|
|
927
|
+
/** Whether the request completed successfully or ended in an error */
|
|
928
|
+
status?: "success" | "error";
|
|
927
929
|
/** Input (prompt) tokens reported by the provider */
|
|
928
930
|
inputTokens?: number;
|
|
929
931
|
/** Output (completion) tokens reported by the provider */
|
package/dist/index.js
CHANGED
|
@@ -52959,6 +52959,7 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
52959
52959
|
let accumulatedContent = "";
|
|
52960
52960
|
let responseInputTokens;
|
|
52961
52961
|
let responseOutputTokens;
|
|
52962
|
+
let requestHadError = false;
|
|
52962
52963
|
const isChatCompletion = req.url?.includes("/chat/completions");
|
|
52963
52964
|
const sessionId = getSessionId(req.headers);
|
|
52964
52965
|
let effectiveSessionId = sessionId;
|
|
@@ -54223,6 +54224,7 @@ data: [DONE]
|
|
|
54223
54224
|
const rawErrBody = lastError?.body || structuredMessage;
|
|
54224
54225
|
const errStatus = lastError?.status || 502;
|
|
54225
54226
|
const transformedErr = transformPaymentError(rawErrBody);
|
|
54227
|
+
requestHadError = true;
|
|
54226
54228
|
if (headersSentEarly) {
|
|
54227
54229
|
let errPayload;
|
|
54228
54230
|
try {
|
|
@@ -54266,6 +54268,21 @@ data: [DONE]
|
|
|
54266
54268
|
completedAt: Date.now()
|
|
54267
54269
|
});
|
|
54268
54270
|
}
|
|
54271
|
+
const errModel = routingDecision?.model ?? modelId;
|
|
54272
|
+
if (errModel) {
|
|
54273
|
+
const errPayment = paymentStore.getStore()?.amountUsd ?? 0;
|
|
54274
|
+
logUsage({
|
|
54275
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
54276
|
+
model: errModel,
|
|
54277
|
+
tier: routingDecision?.tier ?? "DIRECT",
|
|
54278
|
+
cost: errPayment,
|
|
54279
|
+
baselineCost: errPayment,
|
|
54280
|
+
savings: 0,
|
|
54281
|
+
latencyMs: Date.now() - startTime,
|
|
54282
|
+
status: "error"
|
|
54283
|
+
}).catch(() => {
|
|
54284
|
+
});
|
|
54285
|
+
}
|
|
54269
54286
|
return;
|
|
54270
54287
|
}
|
|
54271
54288
|
const responseChunks = [];
|
|
@@ -54600,6 +54617,7 @@ data: [DONE]
|
|
|
54600
54617
|
baselineCost: logBaseline,
|
|
54601
54618
|
savings: logSavings,
|
|
54602
54619
|
latencyMs: Date.now() - startTime,
|
|
54620
|
+
status: requestHadError ? "error" : "success",
|
|
54603
54621
|
...responseInputTokens !== void 0 && { inputTokens: responseInputTokens },
|
|
54604
54622
|
...responseOutputTokens !== void 0 && { outputTokens: responseOutputTokens }
|
|
54605
54623
|
};
|