@polka-codes/cli-shared 0.9.90 → 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.
Files changed (2) hide show
  1. package/dist/index.js +66 -5
  2. 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 = "/Users/xiliangchen/projects/polka-codes/node_modules/sql.js/dist";
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/polka-codes/memory.sqlite")
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/polka-codes/memory.sqlite"
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;
@@ -67433,6 +67476,7 @@ import { randomUUID } from "node:crypto";
67433
67476
  import { existsSync as existsSync3 } from "node:fs";
67434
67477
  import { mkdir as mkdir2, readFile as readFile3, rename as rename2, writeFile as writeFile2 } from "node:fs/promises";
67435
67478
  import { dirname as dirname3, resolve as resolve5 } from "node:path";
67479
+ import { fileURLToPath } from "node:url";
67436
67480
  var import_sql = __toESM(require_sql_wasm(), 1);
67437
67481
 
67438
67482
  class FileLock {
@@ -67542,7 +67586,24 @@ async function getSqlJs() {
67542
67586
  if (SqlJsInitPromise) {
67543
67587
  return SqlJsInitPromise;
67544
67588
  }
67545
- SqlJsInitPromise = import_sql.default({});
67589
+ const moduleDir = dirname3(fileURLToPath(import.meta.url));
67590
+ const candidates = [
67591
+ resolve5(moduleDir, "sql-wasm.wasm"),
67592
+ resolve5(moduleDir, "..", "dist", "sql-wasm.wasm"),
67593
+ resolve5(moduleDir, "..", "node_modules", "sql.js", "dist", "sql-wasm.wasm"),
67594
+ resolve5(moduleDir, "..", "..", "..", "node_modules", "sql.js", "dist", "sql-wasm.wasm"),
67595
+ resolve5(process.cwd(), "node_modules", "sql.js", "dist", "sql-wasm.wasm")
67596
+ ];
67597
+ SqlJsInitPromise = import_sql.default({
67598
+ locateFile: (file2) => {
67599
+ for (const candidate of candidates) {
67600
+ if (existsSync3(candidate)) {
67601
+ return candidate;
67602
+ }
67603
+ }
67604
+ return file2;
67605
+ }
67606
+ });
67546
67607
  SqlJs = await SqlJsInitPromise;
67547
67608
  return SqlJs;
67548
67609
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli-shared",
3
- "version": "0.9.90",
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.89",
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
  }