@polka-codes/cli-shared 0.9.91 → 0.9.92
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 +47 -4
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -35106,7 +35106,7 @@ var require_mimeScore = __commonJS((exports, module) => {
|
|
|
35106
35106
|
|
|
35107
35107
|
// ../../node_modules/sql.js/dist/sql-wasm.js
|
|
35108
35108
|
var require_sql_wasm = __commonJS((exports, module) => {
|
|
35109
|
-
var __dirname = "/
|
|
35109
|
+
var __dirname = "/home/ubuntu/polka-codes/node_modules/sql.js/dist";
|
|
35110
35110
|
var initSqlJsPromise = undefined;
|
|
35111
35111
|
var initSqlJs = function(moduleConfig) {
|
|
35112
35112
|
if (initSqlJsPromise) {
|
|
@@ -50959,12 +50959,12 @@ var toolConfigSchema = exports_external.union([
|
|
|
50959
50959
|
var memoryConfigSchema = exports_external.object({
|
|
50960
50960
|
enabled: exports_external.boolean().optional().default(true),
|
|
50961
50961
|
type: exports_external.enum(["sqlite", "memory"]).optional().default("sqlite"),
|
|
50962
|
-
path: exports_external.string().optional().default("~/.config/
|
|
50962
|
+
path: exports_external.string().optional().default("~/.config/polkacodes/memory/memory.sqlite")
|
|
50963
50963
|
}).strict().optional();
|
|
50964
50964
|
var DEFAULT_MEMORY_CONFIG = {
|
|
50965
50965
|
enabled: true,
|
|
50966
50966
|
type: "sqlite",
|
|
50967
|
-
path: "~/.config/
|
|
50967
|
+
path: "~/.config/polkacodes/memory/memory.sqlite"
|
|
50968
50968
|
};
|
|
50969
50969
|
function resolveHomePath(path) {
|
|
50970
50970
|
if (path.startsWith("~")) {
|
|
@@ -52333,6 +52333,7 @@ var writeToFile_default = {
|
|
|
52333
52333
|
// ../core/src/UsageMeter.ts
|
|
52334
52334
|
class UsageMeter {
|
|
52335
52335
|
#totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
|
|
52336
|
+
#providerMetadataEntries = [];
|
|
52336
52337
|
#modelInfos;
|
|
52337
52338
|
#maxMessages;
|
|
52338
52339
|
#maxCost;
|
|
@@ -52414,8 +52415,17 @@ class UsageMeter {
|
|
|
52414
52415
|
this.#totals.cachedRead += result.cachedRead || 0;
|
|
52415
52416
|
this.#totals.cost += result.cost || 0;
|
|
52416
52417
|
this.#totals.messageCount += 1;
|
|
52418
|
+
if (resp.providerMetadata && Object.keys(resp.providerMetadata).length > 0) {
|
|
52419
|
+
const providerKey = Object.keys(resp.providerMetadata)[0];
|
|
52420
|
+
this.#providerMetadataEntries.push({
|
|
52421
|
+
provider: providerKey || llm.provider,
|
|
52422
|
+
model: llm.modelId,
|
|
52423
|
+
metadata: resp.providerMetadata[providerKey] || resp.providerMetadata,
|
|
52424
|
+
timestamp: Date.now()
|
|
52425
|
+
});
|
|
52426
|
+
}
|
|
52417
52427
|
}
|
|
52418
|
-
setUsage(newUsage) {
|
|
52428
|
+
setUsage(newUsage, options = {}) {
|
|
52419
52429
|
if (newUsage.input != null)
|
|
52420
52430
|
this.#totals.input = newUsage.input;
|
|
52421
52431
|
if (newUsage.output != null)
|
|
@@ -52426,12 +52436,16 @@ class UsageMeter {
|
|
|
52426
52436
|
this.#totals.cost = newUsage.cost;
|
|
52427
52437
|
if (newUsage.messageCount != null)
|
|
52428
52438
|
this.#totals.messageCount = newUsage.messageCount;
|
|
52439
|
+
if (options.clearMetadata) {
|
|
52440
|
+
this.#providerMetadataEntries = [];
|
|
52441
|
+
}
|
|
52429
52442
|
}
|
|
52430
52443
|
incrementMessageCount(n = 1) {
|
|
52431
52444
|
this.#totals.messageCount += n;
|
|
52432
52445
|
}
|
|
52433
52446
|
resetUsage() {
|
|
52434
52447
|
this.#totals = { input: 0, output: 0, cachedRead: 0, cost: 0, messageCount: 0 };
|
|
52448
|
+
this.#providerMetadataEntries = [];
|
|
52435
52449
|
}
|
|
52436
52450
|
isLimitExceeded() {
|
|
52437
52451
|
const messageCount = this.#maxMessages > 0 && this.#totals.messageCount >= this.#maxMessages;
|
|
@@ -52453,6 +52467,34 @@ class UsageMeter {
|
|
|
52453
52467
|
get usage() {
|
|
52454
52468
|
return { ...this.#totals };
|
|
52455
52469
|
}
|
|
52470
|
+
get providerMetadata() {
|
|
52471
|
+
return [...this.#providerMetadataEntries];
|
|
52472
|
+
}
|
|
52473
|
+
get cacheStats() {
|
|
52474
|
+
const entries = this.#providerMetadataEntries;
|
|
52475
|
+
const totalRequests = entries.length;
|
|
52476
|
+
let totalCachedTokens = 0;
|
|
52477
|
+
let requestsWithCache = 0;
|
|
52478
|
+
for (const entry of entries) {
|
|
52479
|
+
const metadata = entry.metadata;
|
|
52480
|
+
const cachedTokens = metadata.cachedPromptTokens ?? metadata.cacheReadTokens ?? metadata.prompt_cache_hit_tokens ?? 0;
|
|
52481
|
+
if (cachedTokens > 0) {
|
|
52482
|
+
totalCachedTokens += cachedTokens;
|
|
52483
|
+
requestsWithCache++;
|
|
52484
|
+
}
|
|
52485
|
+
}
|
|
52486
|
+
const cacheHitRate = totalRequests > 0 ? requestsWithCache / totalRequests : 0;
|
|
52487
|
+
return {
|
|
52488
|
+
totalCachedTokens,
|
|
52489
|
+
totalRequests,
|
|
52490
|
+
requestsWithCache,
|
|
52491
|
+
cacheHitRate,
|
|
52492
|
+
entries: [...this.#providerMetadataEntries]
|
|
52493
|
+
};
|
|
52494
|
+
}
|
|
52495
|
+
clearProviderMetadata() {
|
|
52496
|
+
this.#providerMetadataEntries = [];
|
|
52497
|
+
}
|
|
52456
52498
|
merge(other) {
|
|
52457
52499
|
const otherUsage = other.usage;
|
|
52458
52500
|
this.#totals.input += otherUsage.input;
|
|
@@ -52460,6 +52502,7 @@ class UsageMeter {
|
|
|
52460
52502
|
this.#totals.cachedRead += otherUsage.cachedRead;
|
|
52461
52503
|
this.#totals.cost += otherUsage.cost;
|
|
52462
52504
|
this.#totals.messageCount += otherUsage.messageCount;
|
|
52505
|
+
this.#providerMetadataEntries.push(...other.providerMetadata);
|
|
52463
52506
|
}
|
|
52464
52507
|
getUsageText() {
|
|
52465
52508
|
const u = this.usage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli-shared",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.92",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "github@polka.codes",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@ai-sdk/provider": "^2.0.1",
|
|
22
22
|
"@ai-sdk/provider-utils": "^3.0.20",
|
|
23
23
|
"@inquirer/prompts": "^8.1.0",
|
|
24
|
-
"@polka-codes/core": "0.9.
|
|
24
|
+
"@polka-codes/core": "0.9.91",
|
|
25
25
|
"ai": "^5.0.117",
|
|
26
26
|
"chalk": "^5.6.2",
|
|
27
27
|
"ignore": "^7.0.5",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/lodash-es": "^4.17.12",
|
|
36
|
-
"@types/mime-types": "^3.0.1"
|
|
36
|
+
"@types/mime-types": "^3.0.1",
|
|
37
|
+
"@types/sql.js": "^1.4.9"
|
|
37
38
|
}
|
|
38
39
|
}
|