@dudousxd/nestjs-agent-store-drizzle 0.28.6 → 0.29.0
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.cjs +9 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -9
- package/dist/index.d.ts +81 -9
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -237,8 +237,10 @@ var agentTokenUsage = (0, import_sqlite_core.sqliteTable)("agent_token_usage", {
|
|
|
237
237
|
cacheWriteTokens: (0, import_sqlite_core.integer)("cache_write_tokens"),
|
|
238
238
|
/** Subset of `inputTokens` served from the prompt cache this turn; null when not reported. */
|
|
239
239
|
cacheReadTokens: (0, import_sqlite_core.integer)("cache_read_tokens"),
|
|
240
|
-
/**
|
|
240
|
+
/** The turn's USD cost: provider-reported, or estimated from the price row (see `costSource`); null when unpriced. */
|
|
241
241
|
costUsd: (0, import_sqlite_core.real)("cost_usd"),
|
|
242
|
+
/** Where `cost_usd` came from: `'provider'` (reported) or `'estimate'` (tokens × the price row); null on rows from before it existed (reported). */
|
|
243
|
+
costSource: (0, import_sqlite_core.text)("cost_source").$type(),
|
|
242
244
|
createdAt: (0, import_sqlite_core.integer)("created_at", {
|
|
243
245
|
mode: "timestamp_ms"
|
|
244
246
|
}).notNull()
|
|
@@ -544,6 +546,8 @@ var agentTokenUsage2 = (0, import_mysql_core.mysqlTable)("agent_token_usage", {
|
|
|
544
546
|
cacheWriteTokens: (0, import_mysql_core.int)("cache_write_tokens"),
|
|
545
547
|
cacheReadTokens: (0, import_mysql_core.int)("cache_read_tokens"),
|
|
546
548
|
costUsd: (0, import_mysql_core.double)("cost_usd"),
|
|
549
|
+
/** Where `cost_usd` came from: `'provider'` (reported) or `'estimate'` (tokens × the price row); null on rows from before it existed (reported). */
|
|
550
|
+
costSource: key("cost_source").$type(),
|
|
547
551
|
createdAt: ts("created_at").notNull()
|
|
548
552
|
}, (table) => [
|
|
549
553
|
(0, import_mysql_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt)
|
|
@@ -825,6 +829,8 @@ var agentTokenUsage3 = (0, import_pg_core.pgTable)("agent_token_usage", {
|
|
|
825
829
|
cacheWriteTokens: (0, import_pg_core.integer)("cache_write_tokens"),
|
|
826
830
|
cacheReadTokens: (0, import_pg_core.integer)("cache_read_tokens"),
|
|
827
831
|
costUsd: (0, import_pg_core.doublePrecision)("cost_usd"),
|
|
832
|
+
/** Where `cost_usd` came from: `'provider'` (reported) or `'estimate'` (tokens × the price row); null on rows from before it existed (reported). */
|
|
833
|
+
costSource: (0, import_pg_core.text)("cost_source").$type(),
|
|
828
834
|
createdAt: ts2("created_at").notNull()
|
|
829
835
|
}, (table) => [
|
|
830
836
|
(0, import_pg_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt)
|
|
@@ -2582,6 +2588,7 @@ var DrizzleAgentStore = class {
|
|
|
2582
2588
|
cacheWriteTokens: input.usage.cacheWriteTokens ?? null,
|
|
2583
2589
|
cacheReadTokens: input.usage.cacheReadTokens ?? null,
|
|
2584
2590
|
costUsd: input.costUsd ?? null,
|
|
2591
|
+
costSource: input.costUsd !== void 0 ? input.costSource ?? "provider" : null,
|
|
2585
2592
|
createdAt: /* @__PURE__ */ new Date()
|
|
2586
2593
|
});
|
|
2587
2594
|
}
|
|
@@ -2592,12 +2599,7 @@ var DrizzleAgentStore = class {
|
|
|
2592
2599
|
const start = /* @__PURE__ */ new Date(`${fromDay}T00:00:00.000Z`);
|
|
2593
2600
|
const end = /* @__PURE__ */ new Date(`${toDay}T23:59:59.999Z`);
|
|
2594
2601
|
const rows = await this.db.select().from(this.t.agentTokenUsage).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(this.t.agentTokenUsage.actorRef, actorRef), (0, import_drizzle_orm4.gte)(this.t.agentTokenUsage.createdAt, start), (0, import_drizzle_orm4.lte)(this.t.agentTokenUsage.createdAt, end)));
|
|
2595
|
-
|
|
2596
|
-
const costUsd = rows.reduce((sum2, row) => sum2 + (row.costUsd ?? 0), 0);
|
|
2597
|
-
return {
|
|
2598
|
-
usedTokens,
|
|
2599
|
-
costUsd
|
|
2600
|
-
};
|
|
2602
|
+
return (0, import_nestjs_agent_core4.sumUsage)(rows);
|
|
2601
2603
|
}
|
|
2602
2604
|
toSummary(thread, lastContent) {
|
|
2603
2605
|
return {
|