@polka-codes/cli 0.7.1 → 0.7.2
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 +17 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24629,7 +24629,7 @@ var {
|
|
|
24629
24629
|
Help
|
|
24630
24630
|
} = import__.default;
|
|
24631
24631
|
// package.json
|
|
24632
|
-
var version = "0.7.
|
|
24632
|
+
var version = "0.7.2";
|
|
24633
24633
|
|
|
24634
24634
|
// ../../node_modules/@anthropic-ai/sdk/version.mjs
|
|
24635
24635
|
var VERSION = "0.36.2";
|
|
@@ -32915,6 +32915,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
32915
32915
|
#client;
|
|
32916
32916
|
#apiKey;
|
|
32917
32917
|
#options;
|
|
32918
|
+
#modelProviderInfo;
|
|
32918
32919
|
model;
|
|
32919
32920
|
constructor(options) {
|
|
32920
32921
|
super(options.usageMeter);
|
|
@@ -32939,6 +32940,9 @@ class OpenRouterService extends AiServiceBase {
|
|
|
32939
32940
|
id: options.model,
|
|
32940
32941
|
info: {}
|
|
32941
32942
|
};
|
|
32943
|
+
fetch(`https://openrouter.ai/api/v1/models/${this.model.id}/endpoints`).then((res) => res.json()).then((data) => {
|
|
32944
|
+
this.#modelProviderInfo = data.data;
|
|
32945
|
+
});
|
|
32942
32946
|
}
|
|
32943
32947
|
async* sendImpl(systemPrompt, messages) {
|
|
32944
32948
|
const openAiMessages = [
|
|
@@ -33059,12 +33063,20 @@ class OpenRouterService extends AiServiceBase {
|
|
|
33059
33063
|
signal: controller.signal
|
|
33060
33064
|
});
|
|
33061
33065
|
const responseBody = await response.json();
|
|
33062
|
-
const generation = responseBody.data;
|
|
33066
|
+
const generation = responseBody.data ?? {};
|
|
33067
|
+
let totalCost = generation.total_cost || 0;
|
|
33068
|
+
if (generation.is_byok && this.#modelProviderInfo) {
|
|
33069
|
+
const price = this.#modelProviderInfo.endpoints.find((e2) => e2.provider_name === generation.provider_name)?.pricing;
|
|
33070
|
+
if (price) {
|
|
33071
|
+
totalCost += (generation.native_tokens_prompt || 0) * price.request;
|
|
33072
|
+
totalCost += (generation.native_tokens_completion || 0) * price.completion;
|
|
33073
|
+
}
|
|
33074
|
+
}
|
|
33063
33075
|
yield {
|
|
33064
33076
|
type: "usage",
|
|
33065
|
-
inputTokens: generation
|
|
33066
|
-
outputTokens: generation
|
|
33067
|
-
totalCost
|
|
33077
|
+
inputTokens: generation.native_tokens_prompt || 0,
|
|
33078
|
+
outputTokens: generation.native_tokens_completion || 0,
|
|
33079
|
+
totalCost
|
|
33068
33080
|
};
|
|
33069
33081
|
} catch (error) {
|
|
33070
33082
|
console.error("Error fetching OpenRouter generation details:", error);
|