@dudousxd/nestjs-agent-store-drizzle 0.22.0 → 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/README.md CHANGED
@@ -150,7 +150,7 @@ reader's `IN (…)` and `truncateFrom`'s delete) filter on it.
150
150
  ## Attachment housekeeping
151
151
 
152
152
  `referencedMediaIds(actorRef, mediaIds)` answers which of a set of media ids a message that still
153
- exists carries, for one actor — the inverse of the host's own staged-media inventory, and the half a
153
+ exists — or one still waiting in a thread's queue (`agent_queued_message`) — carries, for one actor — the inverse of the host's own staged-media inventory, and the half a
154
154
  sweep cannot work out for itself. It needs **no schema change**: it reads the `attachments` JSON
155
155
  column messages have carried since attachments shipped, so an existing database answers correctly
156
156
  the moment you upgrade, with nothing to backfill.
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,
@@ -1235,7 +1274,8 @@ var DrizzleAgentStore = class {
1235
1274
  return rows.length;
1236
1275
  }
1237
1276
  /**
1238
- * Of `mediaIds`, the ones a surviving message in one of this actor's threads still carries.
1277
+ * Of `mediaIds`, the ones a surviving message — or a message waiting in the queue — in one of
1278
+ * this actor's threads still carries.
1239
1279
  *
1240
1280
  * Reads the `attachments` JSON back out and matches in memory rather than pushing the match into
1241
1281
  * SQL: the column holds an array of objects, and every dialect this adapter's sibling targets
@@ -1254,9 +1294,15 @@ var DrizzleAgentStore = class {
1254
1294
  const rows = await this.db.select({
1255
1295
  attachments: agentMessage.attachments
1256
1296
  }).from(agentMessage).innerJoin(agentThread, (0, import_drizzle_orm2.eq)(agentMessage.threadId, agentThread.id)).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentThread.actorRef, actorRef), (0, import_drizzle_orm2.isNotNull)(agentMessage.attachments)));
1297
+ const queued = await this.db.select({
1298
+ attachments: agentQueuedMessage.attachments
1299
+ }).from(agentQueuedMessage).innerJoin(agentThread, (0, import_drizzle_orm2.eq)(agentQueuedMessage.threadId, agentThread.id)).where((0, import_drizzle_orm2.and)((0, import_drizzle_orm2.eq)(agentThread.actorRef, actorRef), (0, import_drizzle_orm2.isNotNull)(agentQueuedMessage.attachments)));
1257
1300
  const wanted = new Set(mediaIds);
1258
1301
  const found = /* @__PURE__ */ new Set();
1259
- for (const row of rows) {
1302
+ for (const row of [
1303
+ ...rows,
1304
+ ...queued
1305
+ ]) {
1260
1306
  for (const attachment of row.attachments ?? []) {
1261
1307
  if (wanted.has(attachment.mediaId)) {
1262
1308
  found.add(attachment.mediaId);
@@ -1308,6 +1354,7 @@ var DrizzleAgentStore = class {
1308
1354
  ...thread.model != null ? {
1309
1355
  model: thread.model
1310
1356
  } : {},
1357
+ persona: thread.persona ?? null,
1311
1358
  ...lastContent !== void 0 ? {
1312
1359
  lastMessagePreview: lastContent.slice(0, 120)
1313
1360
  } : {}
@@ -1337,6 +1384,9 @@ var DrizzleAgentStore = class {
1337
1384
  ...message.agentName != null ? {
1338
1385
  agentName: message.agentName
1339
1386
  } : {},
1387
+ ...message.persona != null ? {
1388
+ persona: message.persona
1389
+ } : {},
1340
1390
  ...message.runId != null ? {
1341
1391
  runId: message.runId
1342
1392
  } : {},
@@ -1367,6 +1417,9 @@ function toQueuedMessage(row) {
1367
1417
  ...row.agentName !== null ? {
1368
1418
  agentName: row.agentName
1369
1419
  } : {},
1420
+ ...row.persona !== null ? {
1421
+ persona: row.persona
1422
+ } : {},
1370
1423
  ...row.model !== null ? {
1371
1424
  model: row.model
1372
1425
  } : {},