@dudousxd/nestjs-agent-store-drizzle 0.35.0 → 0.36.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 +12 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -2
- package/dist/index.d.ts +70 -2
- package/dist/index.js +23 -14
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -271,6 +271,10 @@ var agentTokenUsage = (0, import_sqlite_core.sqliteTable)("agent_token_usage", {
|
|
|
271
271
|
metadata: (0, import_sqlite_core.text)("metadata", {
|
|
272
272
|
mode: "json"
|
|
273
273
|
}).$type(),
|
|
274
|
+
/** `false` keeps the row out of the agent's quota windows (`recordUsage({ countsTowardsQuota: false })`). */
|
|
275
|
+
countsTowardsQuota: (0, import_sqlite_core.integer)("counts_towards_quota", {
|
|
276
|
+
mode: "boolean"
|
|
277
|
+
}).notNull().default(true),
|
|
274
278
|
createdAt: (0, import_sqlite_core.integer)("created_at", {
|
|
275
279
|
mode: "timestamp_ms"
|
|
276
280
|
}).notNull()
|
|
@@ -744,6 +748,8 @@ var agentTokenUsage2 = (0, import_mysql_core.mysqlTable)("agent_token_usage", {
|
|
|
744
748
|
requests: (0, import_mysql_core.int)("requests"),
|
|
745
749
|
/** The caller's own JSON, never read by the library. */
|
|
746
750
|
metadata: (0, import_mysql_core.json)("metadata").$type(),
|
|
751
|
+
/** `false` keeps the row out of the agent's quota windows (`recordUsage({ countsTowardsQuota: false })`). */
|
|
752
|
+
countsTowardsQuota: (0, import_mysql_core.boolean)("counts_towards_quota").notNull().default(true),
|
|
747
753
|
createdAt: ts("created_at").notNull()
|
|
748
754
|
}, (table) => [
|
|
749
755
|
(0, import_mysql_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt),
|
|
@@ -1229,6 +1235,8 @@ var agentTokenUsage3 = (0, import_pg_core.pgTable)("agent_token_usage", {
|
|
|
1229
1235
|
requests: (0, import_pg_core.integer)("requests"),
|
|
1230
1236
|
/** The caller's own JSON, never read by the library. */
|
|
1231
1237
|
metadata: (0, import_pg_core.jsonb)("metadata").$type(),
|
|
1238
|
+
/** `false` keeps the row out of the agent's quota windows (`recordUsage({ countsTowardsQuota: false })`). */
|
|
1239
|
+
countsTowardsQuota: (0, import_pg_core.boolean)("counts_towards_quota").notNull().default(true),
|
|
1232
1240
|
createdAt: ts2("created_at").notNull()
|
|
1233
1241
|
}, (table) => [
|
|
1234
1242
|
(0, import_pg_core.index)("agent_token_usage_actor_created_idx").on(table.actorRef, table.createdAt),
|
|
@@ -3299,6 +3307,7 @@ var DrizzleAgentStore = class {
|
|
|
3299
3307
|
characters: input.characters ?? null,
|
|
3300
3308
|
requests: input.requests ?? null,
|
|
3301
3309
|
metadata: input.metadata ?? null,
|
|
3310
|
+
countsTowardsQuota: input.countsTowardsQuota !== false,
|
|
3302
3311
|
modelId: input.modelId,
|
|
3303
3312
|
purpose: input.purpose,
|
|
3304
3313
|
inputTokens: input.usage.inputTokens,
|
|
@@ -3383,7 +3392,7 @@ var DrizzleAgentStore = class {
|
|
|
3383
3392
|
});
|
|
3384
3393
|
const from = new Date(Math.min(...bounds.map(({ start }) => start.getTime())));
|
|
3385
3394
|
const to = new Date(Math.max(...bounds.map(({ end }) => end.getTime())));
|
|
3386
|
-
const [row] = await this.db.select(columns).from(usage).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(usage.actorRef, actorRef), within(from, to)));
|
|
3395
|
+
const [row] = await this.db.select(columns).from(usage).where((0, import_drizzle_orm4.and)((0, import_drizzle_orm4.eq)(usage.actorRef, actorRef), within(from, to), (0, import_drizzle_orm4.eq)(usage.countsTowardsQuota, true)));
|
|
3387
3396
|
return bounds.map((_, index4) => ({
|
|
3388
3397
|
usedTokens: Number(row?.[`tokens${index4}`] ?? 0),
|
|
3389
3398
|
costUsd: Number(row?.[`cost${index4}`] ?? 0),
|
|
@@ -3710,7 +3719,7 @@ var DrizzleGovernanceQueries = class {
|
|
|
3710
3719
|
* per-feature reads that group by them.
|
|
3711
3720
|
*/
|
|
3712
3721
|
async usageInRange(range, withFeature = false) {
|
|
3713
|
-
const { start, end } = (0, import_nestjs_agent_core5.
|
|
3722
|
+
const { start, end } = (0, import_nestjs_agent_core5.usageRangeBounds)(range);
|
|
3714
3723
|
const usage = this.t.agentTokenUsage;
|
|
3715
3724
|
const rows = await this.db.select({
|
|
3716
3725
|
modelId: usage.modelId,
|
|
@@ -3730,7 +3739,7 @@ var DrizzleGovernanceQueries = class {
|
|
|
3730
3739
|
audioSeconds: usage.audioSeconds,
|
|
3731
3740
|
characters: usage.characters
|
|
3732
3741
|
} : {}
|
|
3733
|
-
}).from(usage).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.gte)(this.t.agentTokenUsage.createdAt, start), (0, import_drizzle_orm5.
|
|
3742
|
+
}).from(usage).where((0, import_drizzle_orm5.and)((0, import_drizzle_orm5.gte)(this.t.agentTokenUsage.createdAt, start), (0, import_drizzle_orm5.lt)(this.t.agentTokenUsage.createdAt, end)));
|
|
3734
3743
|
return rows.map(toUsageInput);
|
|
3735
3744
|
}
|
|
3736
3745
|
async spendByModel(range) {
|