@dudousxd/nestjs-agent-store-drizzle 0.22.1 → 0.23.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 CHANGED
@@ -62,6 +62,8 @@ var agentThread = (0, import_sqlite_core.sqliteTable)("agent_thread", {
62
62
  defaultAgent: (0, import_sqlite_core.text)("default_agent"),
63
63
  /** The model every turn on this thread runs on unless the send names one; `null` → default. */
64
64
  model: (0, import_sqlite_core.text)("model"),
65
+ /** The persona a send on this thread runs under when it names none; `null` → the agent's default. */
66
+ persona: (0, import_sqlite_core.text)("persona"),
65
67
  /** Why the thread's message queue stopped draining; `null` → it drains. */
66
68
  queuePause: (0, import_sqlite_core.text)("queue_pause", {
67
69
  mode: "json"
@@ -101,6 +103,8 @@ var agentMessage = (0, import_sqlite_core.sqliteTable)("agent_message", {
101
103
  mode: "json"
102
104
  }).$type(),
103
105
  agentName: (0, import_sqlite_core.text)("agent_name"),
106
+ /** The persona the turn that wrote this message ran under; `null` → none. */
107
+ persona: (0, import_sqlite_core.text)("persona"),
104
108
  runId: (0, import_sqlite_core.text)("run_id"),
105
109
  /** The step's streamed thinking; `null` when the model produced none. */
106
110
  reasoning: (0, import_sqlite_core.text)("reasoning"),
@@ -173,6 +177,8 @@ var agentQueuedMessage = (0, import_sqlite_core.sqliteTable)("agent_queued_messa
173
177
  mode: "json"
174
178
  }).$type(),
175
179
  agentName: (0, import_sqlite_core.text)("agent_name"),
180
+ /** The persona the send resolved — what the message starts under. */
181
+ persona: (0, import_sqlite_core.text)("persona"),
176
182
  model: (0, import_sqlite_core.text)("model"),
177
183
  pageContext: (0, import_sqlite_core.text)("page_context", {
178
184
  mode: "json"
@@ -360,6 +366,7 @@ var statements = [
360
366
  active_stream_id TEXT,
361
367
  default_agent TEXT,
362
368
  model TEXT,
369
+ persona TEXT,
363
370
  queue_pause TEXT,
364
371
  created_at INTEGER NOT NULL,
365
372
  updated_at INTEGER NOT NULL,
@@ -378,6 +385,7 @@ var statements = [
378
385
  follow_ups TEXT,
379
386
  usage TEXT,
380
387
  agent_name TEXT,
388
+ persona TEXT,
381
389
  run_id TEXT,
382
390
  reasoning TEXT,
383
391
  reasoning_ms INTEGER,
@@ -394,6 +402,7 @@ var statements = [
394
402
  content TEXT NOT NULL,
395
403
  attachments TEXT,
396
404
  agent_name TEXT,
405
+ persona TEXT,
397
406
  model TEXT,
398
407
  page_context TEXT,
399
408
  interrupt INTEGER NOT NULL DEFAULT 0,
@@ -589,6 +598,21 @@ var additiveColumns = [
589
598
  table: "agent_tool_call",
590
599
  column: "decided_via",
591
600
  ddl: "ALTER TABLE agent_tool_call ADD COLUMN decided_via TEXT"
601
+ },
602
+ {
603
+ table: "agent_thread",
604
+ column: "persona",
605
+ ddl: "ALTER TABLE agent_thread ADD COLUMN persona TEXT"
606
+ },
607
+ {
608
+ table: "agent_message",
609
+ column: "persona",
610
+ ddl: "ALTER TABLE agent_message ADD COLUMN persona TEXT"
611
+ },
612
+ {
613
+ table: "agent_queued_message",
614
+ column: "persona",
615
+ ddl: "ALTER TABLE agent_queued_message ADD COLUMN persona TEXT"
592
616
  }
593
617
  ];
594
618
  async function ensureAgentSchema(db) {
@@ -636,6 +660,7 @@ var DrizzleAgentStore = class {
636
660
  activeStreamId: null,
637
661
  defaultAgent: null,
638
662
  model: null,
663
+ persona: input.persona ?? null,
639
664
  queuePause: null,
640
665
  createdAt: now,
641
666
  updatedAt: now,
@@ -743,6 +768,7 @@ var DrizzleAgentStore = class {
743
768
  activeStreamId: null,
744
769
  defaultAgent: source.defaultAgent,
745
770
  model: source.model,
771
+ persona: source.persona,
746
772
  // A fork is a new conversation: nothing is waiting on it, and nothing is paused.
747
773
  queuePause: null,
748
774
  createdAt: now,
@@ -762,6 +788,7 @@ var DrizzleAgentStore = class {
762
788
  followUps: message.followUps,
763
789
  usage: message.usage,
764
790
  agentName: message.agentName,
791
+ persona: message.persona,
765
792
  // The copy is the same message, so it keeps the run that wrote it. A reader asking which
766
793
  // turn produced this text gets the truthful answer; the run's own thread is still the
767
794
  // original, so a run-scoped read never picks the fork's rows up.
@@ -922,6 +949,7 @@ var DrizzleAgentStore = class {
922
949
  content: input.content,
923
950
  attachments: input.attachments !== void 0 && input.attachments.length > 0 ? input.attachments : null,
924
951
  agentName: input.agentName ?? null,
952
+ persona: input.persona ?? null,
925
953
  model: input.model ?? null,
926
954
  pageContext: input.pageContext ?? null,
927
955
  interrupt: input.interrupt === true,
@@ -1017,6 +1045,9 @@ var DrizzleAgentStore = class {
1017
1045
  if (patch.model !== void 0) {
1018
1046
  updates.model = patch.model;
1019
1047
  }
1048
+ if (patch.persona !== void 0) {
1049
+ updates.persona = patch.persona;
1050
+ }
1020
1051
  if (Object.keys(updates).length === 0) {
1021
1052
  return;
1022
1053
  }
@@ -1035,6 +1066,13 @@ var DrizzleAgentStore = class {
1035
1066
  }).from(agentThread).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentThread.id, threadId), (0, import_drizzle_orm2.isNull)(agentThread.deletedAt)));
1036
1067
  return thread?.model ?? null;
1037
1068
  }
1069
+ /** The thread's pinned persona, projected like {@link defaultAgentForThread}. */
1070
+ async personaForThread(threadId) {
1071
+ const [thread] = await this.db.select({
1072
+ persona: agentThread.persona
1073
+ }).from(agentThread).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentThread.id, threadId), (0, import_drizzle_orm2.isNull)(agentThread.deletedAt)));
1074
+ return thread?.persona ?? null;
1075
+ }
1038
1076
  async defaultAgentForThread(threadId) {
1039
1077
  const [thread] = await this.db.select({
1040
1078
  defaultAgent: agentThread.defaultAgent
@@ -1105,6 +1143,7 @@ var DrizzleAgentStore = class {
1105
1143
  followUps: input.followUps ?? null,
1106
1144
  usage: input.usage ?? null,
1107
1145
  agentName: input.agentName ?? null,
1146
+ persona: input.persona ?? null,
1108
1147
  runId: input.runId ?? null,
1109
1148
  reasoning: input.reasoning ?? null,
1110
1149
  reasoningMs: input.reasoningMs ?? null,
@@ -1315,6 +1354,7 @@ var DrizzleAgentStore = class {
1315
1354
  ...thread.model != null ? {
1316
1355
  model: thread.model
1317
1356
  } : {},
1357
+ persona: thread.persona ?? null,
1318
1358
  ...lastContent !== void 0 ? {
1319
1359
  lastMessagePreview: lastContent.slice(0, 120)
1320
1360
  } : {}
@@ -1344,6 +1384,9 @@ var DrizzleAgentStore = class {
1344
1384
  ...message.agentName != null ? {
1345
1385
  agentName: message.agentName
1346
1386
  } : {},
1387
+ ...message.persona != null ? {
1388
+ persona: message.persona
1389
+ } : {},
1347
1390
  ...message.runId != null ? {
1348
1391
  runId: message.runId
1349
1392
  } : {},
@@ -1374,6 +1417,9 @@ function toQueuedMessage(row) {
1374
1417
  ...row.agentName !== null ? {
1375
1418
  agentName: row.agentName
1376
1419
  } : {},
1420
+ ...row.persona !== null ? {
1421
+ persona: row.persona
1422
+ } : {},
1377
1423
  ...row.model !== null ? {
1378
1424
  model: row.model
1379
1425
  } : {},