@dudousxd/nestjs-agent-store-drizzle 0.15.0 → 0.17.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/README.md CHANGED
@@ -120,6 +120,7 @@ ALTER TABLE agent_message ADD COLUMN reasoning TEXT;
120
120
  ALTER TABLE agent_message ADD COLUMN reasoning_ms INTEGER;
121
121
  ALTER TABLE agent_message ADD COLUMN ui TEXT;
122
122
  ALTER TABLE agent_message ADD COLUMN feedback TEXT;
123
+ ALTER TABLE agent_thread ADD COLUMN model TEXT;
123
124
  ALTER TABLE agent_tool_call ADD COLUMN approver TEXT;
124
125
  ALTER TABLE agent_tool_call ADD COLUMN expires_at INTEGER;
125
126
  ALTER TABLE agent_tool_call ADD COLUMN remember INTEGER;
package/dist/index.cjs CHANGED
@@ -54,6 +54,8 @@ var agentThread = (0, import_sqlite_core.sqliteTable)("agent_thread", {
54
54
  activeStreamId: (0, import_sqlite_core.text)("active_stream_id"),
55
55
  /** The agent a new turn on this thread defaults to when the caller names none. */
56
56
  defaultAgent: (0, import_sqlite_core.text)("default_agent"),
57
+ /** The model every turn on this thread runs on unless the send names one; `null` → default. */
58
+ model: (0, import_sqlite_core.text)("model"),
57
59
  createdAt: (0, import_sqlite_core.integer)("created_at", {
58
60
  mode: "timestamp_ms"
59
61
  }).notNull(),
@@ -291,6 +293,7 @@ var statements = [
291
293
  transient INTEGER NOT NULL DEFAULT 0,
292
294
  active_stream_id TEXT,
293
295
  default_agent TEXT,
296
+ model TEXT,
294
297
  created_at INTEGER NOT NULL,
295
298
  updated_at INTEGER NOT NULL,
296
299
  deleted_at INTEGER
@@ -457,6 +460,11 @@ var additiveColumns = [
457
460
  column: "feedback",
458
461
  ddl: "ALTER TABLE agent_message ADD COLUMN feedback TEXT"
459
462
  },
463
+ {
464
+ table: "agent_thread",
465
+ column: "model",
466
+ ddl: "ALTER TABLE agent_thread ADD COLUMN model TEXT"
467
+ },
460
468
  {
461
469
  table: "agent_tool_call",
462
470
  column: "approver",
@@ -522,6 +530,7 @@ var DrizzleAgentStore = class {
522
530
  transient: input.transient ?? false,
523
531
  activeStreamId: null,
524
532
  defaultAgent: null,
533
+ model: null,
525
534
  createdAt: now,
526
535
  updatedAt: now,
527
536
  deletedAt: null
@@ -627,6 +636,7 @@ var DrizzleAgentStore = class {
627
636
  transient: false,
628
637
  activeStreamId: null,
629
638
  defaultAgent: source.defaultAgent,
639
+ model: source.model,
630
640
  createdAt: now,
631
641
  updatedAt: now,
632
642
  deletedAt: null
@@ -775,6 +785,9 @@ var DrizzleAgentStore = class {
775
785
  if (patch.defaultAgent !== void 0) {
776
786
  updates.defaultAgent = patch.defaultAgent;
777
787
  }
788
+ if (patch.model !== void 0) {
789
+ updates.model = patch.model;
790
+ }
778
791
  if (Object.keys(updates).length === 0) {
779
792
  return;
780
793
  }
@@ -786,6 +799,13 @@ var DrizzleAgentStore = class {
786
799
  * agent answers the next turn, and {@link getThread} would materialize the whole transcript to
787
800
  * hand it over. `null` when the thread is unknown, soft-deleted, or has no default set.
788
801
  */
802
+ /** The thread's pinned model, projected like {@link defaultAgentForThread}. */
803
+ async modelForThread(threadId) {
804
+ const [thread] = await this.db.select({
805
+ model: agentThread.model
806
+ }).from(agentThread).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentThread.id, threadId), (0, import_drizzle_orm2.isNull)(agentThread.deletedAt)));
807
+ return thread?.model ?? null;
808
+ }
789
809
  async defaultAgentForThread(threadId) {
790
810
  const [thread] = await this.db.select({
791
811
  defaultAgent: agentThread.defaultAgent
@@ -998,8 +1018,11 @@ var DrizzleAgentStore = class {
998
1018
  });
999
1019
  }
1000
1020
  async quotaToday(actorRef, day) {
1001
- const start = /* @__PURE__ */ new Date(`${day}T00:00:00.000Z`);
1002
- const end = /* @__PURE__ */ new Date(`${day}T23:59:59.999Z`);
1021
+ return this.usageBetween(actorRef, day, day);
1022
+ }
1023
+ async usageBetween(actorRef, fromDay, toDay) {
1024
+ const start = /* @__PURE__ */ new Date(`${fromDay}T00:00:00.000Z`);
1025
+ const end = /* @__PURE__ */ new Date(`${toDay}T23:59:59.999Z`);
1003
1026
  const rows = await this.db.select().from(agentTokenUsage).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentTokenUsage.actorRef, actorRef), (0, import_drizzle_orm2.gte)(agentTokenUsage.createdAt, start), (0, import_drizzle_orm2.lte)(agentTokenUsage.createdAt, end)));
1004
1027
  const usedTokens = rows.reduce((sum2, row) => sum2 + row.inputTokens + row.outputTokens, 0);
1005
1028
  const costUsd = rows.reduce((sum2, row) => sum2 + (row.costUsd ?? 0), 0);
@@ -1016,6 +1039,9 @@ var DrizzleAgentStore = class {
1016
1039
  createdAt: thread.createdAt.toISOString(),
1017
1040
  updatedAt: thread.updatedAt.toISOString(),
1018
1041
  defaultAgent: thread.defaultAgent,
1042
+ ...thread.model != null ? {
1043
+ model: thread.model
1044
+ } : {},
1019
1045
  ...lastContent !== void 0 ? {
1020
1046
  lastMessagePreview: lastContent.slice(0, 120)
1021
1047
  } : {}