@dudousxd/nestjs-agent-store-drizzle 0.14.0 → 0.16.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
@@ -119,6 +119,8 @@ ALTER TABLE agent_run ADD COLUMN parent_run_id TEXT;
119
119
  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
+ ALTER TABLE agent_message ADD COLUMN feedback TEXT;
123
+ ALTER TABLE agent_thread ADD COLUMN model TEXT;
122
124
  ALTER TABLE agent_tool_call ADD COLUMN approver TEXT;
123
125
  ALTER TABLE agent_tool_call ADD COLUMN expires_at INTEGER;
124
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(),
@@ -97,6 +99,10 @@ var agentMessage = (0, import_sqlite_core.sqliteTable)("agent_message", {
97
99
  ui: (0, import_sqlite_core.text)("ui", {
98
100
  mode: "json"
99
101
  }).$type(),
102
+ /** The thread owner's thumbs-up/down (+ comment); `null` when unrated. Not copied on fork. */
103
+ feedback: (0, import_sqlite_core.text)("feedback", {
104
+ mode: "json"
105
+ }).$type(),
100
106
  createdAt: (0, import_sqlite_core.integer)("created_at", {
101
107
  mode: "timestamp_ms"
102
108
  }).notNull()
@@ -287,6 +293,7 @@ var statements = [
287
293
  transient INTEGER NOT NULL DEFAULT 0,
288
294
  active_stream_id TEXT,
289
295
  default_agent TEXT,
296
+ model TEXT,
290
297
  created_at INTEGER NOT NULL,
291
298
  updated_at INTEGER NOT NULL,
292
299
  deleted_at INTEGER
@@ -308,6 +315,7 @@ var statements = [
308
315
  reasoning TEXT,
309
316
  reasoning_ms INTEGER,
310
317
  ui TEXT,
318
+ feedback TEXT,
311
319
  created_at INTEGER NOT NULL
312
320
  )`,
313
321
  `CREATE INDEX IF NOT EXISTS agent_message_thread_created_idx
@@ -447,6 +455,16 @@ var additiveColumns = [
447
455
  column: "ui",
448
456
  ddl: "ALTER TABLE agent_message ADD COLUMN ui TEXT"
449
457
  },
458
+ {
459
+ table: "agent_message",
460
+ column: "feedback",
461
+ ddl: "ALTER TABLE agent_message ADD COLUMN feedback TEXT"
462
+ },
463
+ {
464
+ table: "agent_thread",
465
+ column: "model",
466
+ ddl: "ALTER TABLE agent_thread ADD COLUMN model TEXT"
467
+ },
450
468
  {
451
469
  table: "agent_tool_call",
452
470
  column: "approver",
@@ -512,6 +530,7 @@ var DrizzleAgentStore = class {
512
530
  transient: input.transient ?? false,
513
531
  activeStreamId: null,
514
532
  defaultAgent: null,
533
+ model: null,
515
534
  createdAt: now,
516
535
  updatedAt: now,
517
536
  deletedAt: null
@@ -617,6 +636,7 @@ var DrizzleAgentStore = class {
617
636
  transient: false,
618
637
  activeStreamId: null,
619
638
  defaultAgent: source.defaultAgent,
639
+ model: source.model,
620
640
  createdAt: now,
621
641
  updatedAt: now,
622
642
  deletedAt: null
@@ -765,6 +785,9 @@ var DrizzleAgentStore = class {
765
785
  if (patch.defaultAgent !== void 0) {
766
786
  updates.defaultAgent = patch.defaultAgent;
767
787
  }
788
+ if (patch.model !== void 0) {
789
+ updates.model = patch.model;
790
+ }
768
791
  if (Object.keys(updates).length === 0) {
769
792
  return;
770
793
  }
@@ -776,6 +799,13 @@ var DrizzleAgentStore = class {
776
799
  * agent answers the next turn, and {@link getThread} would materialize the whole transcript to
777
800
  * hand it over. `null` when the thread is unknown, soft-deleted, or has no default set.
778
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
+ }
779
809
  async defaultAgentForThread(threadId) {
780
810
  const [thread] = await this.db.select({
781
811
  defaultAgent: agentThread.defaultAgent
@@ -850,6 +880,7 @@ var DrizzleAgentStore = class {
850
880
  reasoning: input.reasoning ?? null,
851
881
  reasoningMs: input.reasoningMs ?? null,
852
882
  ui: input.ui ?? null,
883
+ feedback: null,
853
884
  createdAt: now
854
885
  };
855
886
  await this.db.insert(agentMessage).values(message);
@@ -868,6 +899,17 @@ var DrizzleAgentStore = class {
868
899
  ui: ui.length > 0 ? ui : null
869
900
  }).where((0, import_drizzle_orm2.eq)(agentMessage.id, messageId));
870
901
  }
902
+ async threadOfMessage(messageId) {
903
+ const [row] = await this.db.select({
904
+ threadId: agentMessage.threadId
905
+ }).from(agentMessage).where((0, import_drizzle_orm2.eq)(agentMessage.id, messageId)).limit(1);
906
+ return row?.threadId ?? null;
907
+ }
908
+ async setMessageFeedback(messageId, feedback) {
909
+ await this.db.update(agentMessage).set({
910
+ feedback
911
+ }).where((0, import_drizzle_orm2.eq)(agentMessage.id, messageId));
912
+ }
871
913
  async truncateFrom(threadId, messageId) {
872
914
  const messages = await this.db.select().from(agentMessage).where((0, import_drizzle_orm2.eq)(agentMessage.threadId, threadId)).orderBy((0, import_drizzle_orm2.asc)(agentMessage.createdAt), (0, import_drizzle_orm2.asc)(agentMessage.id));
873
915
  const cutoff = messages.findIndex((message) => message.id === messageId);
@@ -994,6 +1036,9 @@ var DrizzleAgentStore = class {
994
1036
  createdAt: thread.createdAt.toISOString(),
995
1037
  updatedAt: thread.updatedAt.toISOString(),
996
1038
  defaultAgent: thread.defaultAgent,
1039
+ ...thread.model != null ? {
1040
+ model: thread.model
1041
+ } : {},
997
1042
  ...lastContent !== void 0 ? {
998
1043
  lastMessagePreview: lastContent.slice(0, 120)
999
1044
  } : {}
@@ -1034,6 +1079,9 @@ var DrizzleAgentStore = class {
1034
1079
  } : {},
1035
1080
  ...message.ui != null ? {
1036
1081
  ui: message.ui
1082
+ } : {},
1083
+ ...message.feedback != null ? {
1084
+ feedback: message.feedback
1037
1085
  } : {}
1038
1086
  };
1039
1087
  }