@dudousxd/nestjs-agent-store-drizzle 0.30.0 → 0.31.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
@@ -8,11 +8,11 @@ var __export = (target, all) => {
8
8
  for (var name in all)
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
- var __copyProps = (to, from, except, desc4) => {
11
+ var __copyProps = (to, from, except, desc5) => {
12
12
  if (from && typeof from === "object" || typeof from === "function") {
13
13
  for (let key2 of __getOwnPropNames(from))
14
14
  if (!__hasOwnProp.call(to, key2) && key2 !== except)
15
- __defProp(to, key2, { get: () => from[key2], enumerable: !(desc4 = __getOwnPropDesc(from, key2)) || desc4.enumerable });
15
+ __defProp(to, key2, { get: () => from[key2], enumerable: !(desc5 = __getOwnPropDesc(from, key2)) || desc5.enumerable });
16
16
  }
17
17
  return to;
18
18
  };
@@ -28,6 +28,8 @@ __export(index_exports, {
28
28
  DrizzleConfirmTokenStore: () => DrizzleConfirmTokenStore,
29
29
  DrizzleGovernanceQueries: () => DrizzleGovernanceQueries,
30
30
  DrizzleMemoryProvider: () => DrizzleMemoryProvider,
31
+ DrizzlePoppyConnectionStore: () => DrizzlePoppyConnectionStore,
32
+ DrizzlePoppyStore: () => DrizzlePoppyStore,
31
33
  DrizzlePricingStore: () => DrizzlePricingStore,
32
34
  DrizzleRagIngestionLog: () => DrizzleRagIngestionLog,
33
35
  DrizzleStreamFrameTable: () => DrizzleStreamFrameTable,
@@ -41,6 +43,11 @@ __export(index_exports, {
41
43
  agentMemory: () => agentMemory,
42
44
  agentMessage: () => agentMessage,
43
45
  agentModelPricing: () => agentModelPricing,
46
+ agentPoppyConnect: () => agentPoppyConnect,
47
+ agentPoppyConnection: () => agentPoppyConnection,
48
+ agentPoppyConversation: () => agentPoppyConversation,
49
+ agentPoppyEvent: () => agentPoppyEvent,
50
+ agentPoppyMessage: () => agentPoppyMessage,
44
51
  agentQueuedMessage: () => agentQueuedMessage,
45
52
  agentRun: () => agentRun,
46
53
  agentSchema: () => agentSchema,
@@ -436,6 +443,94 @@ var agentActionProposal = (0, import_sqlite_core.sqliteTable)("agent_action_prop
436
443
  (0, import_sqlite_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
437
444
  (0, import_sqlite_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
438
445
  ]);
446
+ var agentPoppyConversation = (0, import_sqlite_core.sqliteTable)("agent_poppy_conversation", {
447
+ id: (0, import_sqlite_core.text)("id").primaryKey(),
448
+ clientId: (0, import_sqlite_core.text)("client_id").notNull(),
449
+ userId: (0, import_sqlite_core.text)("user_id").notNull(),
450
+ accountRef: (0, import_sqlite_core.text)("account_ref"),
451
+ agentName: (0, import_sqlite_core.text)("agent_name").notNull(),
452
+ threadId: (0, import_sqlite_core.text)("thread_id"),
453
+ parentId: (0, import_sqlite_core.text)("parent_id"),
454
+ openDirectId: (0, import_sqlite_core.text)("open_direct_id"),
455
+ status: (0, import_sqlite_core.text)("status").notNull(),
456
+ responder: (0, import_sqlite_core.text)("responder").notNull(),
457
+ context: (0, import_sqlite_core.text)("context"),
458
+ activeRunId: (0, import_sqlite_core.text)("active_run_id"),
459
+ turnSeq: (0, import_sqlite_core.integer)("turn_seq").notNull(),
460
+ grantInfo: (0, import_sqlite_core.text)("grant_info"),
461
+ readerHolder: (0, import_sqlite_core.text)("reader_holder"),
462
+ readerUntil: (0, import_sqlite_core.integer)("reader_until"),
463
+ prunedSeq: (0, import_sqlite_core.integer)("pruned_seq").notNull(),
464
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
465
+ updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
466
+ });
467
+ var agentPoppyEvent = (0, import_sqlite_core.sqliteTable)("agent_poppy_event", {
468
+ conversationId: (0, import_sqlite_core.text)("conversation_id").notNull(),
469
+ seq: (0, import_sqlite_core.integer)("seq").notNull(),
470
+ id: (0, import_sqlite_core.text)("id").notNull(),
471
+ type: (0, import_sqlite_core.text)("type").notNull(),
472
+ event: (0, import_sqlite_core.text)("event").notNull(),
473
+ eventKey: (0, import_sqlite_core.text)("event_key"),
474
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
475
+ }, (table) => [
476
+ (0, import_sqlite_core.primaryKey)({
477
+ columns: [
478
+ table.conversationId,
479
+ table.seq
480
+ ]
481
+ }),
482
+ (0, import_sqlite_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
483
+ (0, import_sqlite_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
484
+ ]);
485
+ var agentPoppyMessage = (0, import_sqlite_core.sqliteTable)("agent_poppy_message", {
486
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
487
+ messageId: (0, import_sqlite_core.text)("message_id").notNull(),
488
+ fingerprint: (0, import_sqlite_core.text)("fingerprint").notNull(),
489
+ conversationId: (0, import_sqlite_core.text)("conversation_id").notNull(),
490
+ response: (0, import_sqlite_core.text)("response").notNull(),
491
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
492
+ }, (table) => [
493
+ (0, import_sqlite_core.primaryKey)({
494
+ columns: [
495
+ table.owner,
496
+ table.messageId
497
+ ]
498
+ })
499
+ ]);
500
+ var agentPoppyConnection = (0, import_sqlite_core.sqliteTable)("agent_poppy_connection", {
501
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
502
+ issuer: (0, import_sqlite_core.text)("issuer").notNull(),
503
+ domain: (0, import_sqlite_core.text)("domain").notNull(),
504
+ organization: (0, import_sqlite_core.text)("organization").notNull(),
505
+ scope: (0, import_sqlite_core.text)("scope").notNull(),
506
+ status: (0, import_sqlite_core.text)("status").notNull(),
507
+ state: (0, import_sqlite_core.text)("state").notNull(),
508
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
509
+ updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
510
+ }, (table) => [
511
+ (0, import_sqlite_core.primaryKey)({
512
+ columns: [
513
+ table.owner,
514
+ table.issuer
515
+ ]
516
+ })
517
+ ]);
518
+ var agentPoppyConnect = (0, import_sqlite_core.sqliteTable)("agent_poppy_connect", {
519
+ id: (0, import_sqlite_core.text)("id").primaryKey(),
520
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
521
+ domain: (0, import_sqlite_core.text)("domain").notNull(),
522
+ issuer: (0, import_sqlite_core.text)("issuer").notNull(),
523
+ organization: (0, import_sqlite_core.text)("organization").notNull(),
524
+ scope: (0, import_sqlite_core.text)("scope").notNull(),
525
+ actor: (0, import_sqlite_core.text)("actor"),
526
+ threadId: (0, import_sqlite_core.text)("thread_id"),
527
+ runId: (0, import_sqlite_core.text)("run_id"),
528
+ toolCallId: (0, import_sqlite_core.text)("tool_call_id"),
529
+ flow: (0, import_sqlite_core.text)("flow"),
530
+ status: (0, import_sqlite_core.text)("status").notNull(),
531
+ expiresAt: (0, import_sqlite_core.integer)("expires_at").notNull(),
532
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
533
+ });
439
534
  var agentSchema = {
440
535
  agentActionProposal,
441
536
  agentThread,
@@ -450,7 +545,12 @@ var agentSchema = {
450
545
  ragIngestionLog,
451
546
  agentConfirmToken,
452
547
  agentChannelState,
453
- agentStreamFrame
548
+ agentStreamFrame,
549
+ agentPoppyConversation,
550
+ agentPoppyEvent,
551
+ agentPoppyMessage,
552
+ agentPoppyConnection,
553
+ agentPoppyConnect
454
554
  };
455
555
 
456
556
  // src/ensure-schema.ts
@@ -772,6 +872,124 @@ var agentActionProposal2 = (0, import_mysql_core.mysqlTable)("agent_action_propo
772
872
  (0, import_mysql_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
773
873
  (0, import_mysql_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
774
874
  ]);
875
+ var agentPoppyConversation2 = (0, import_mysql_core.mysqlTable)("agent_poppy_conversation", {
876
+ id: key("id").primaryKey(),
877
+ clientId: (0, import_mysql_core.varchar)("client_id", {
878
+ length: 2048
879
+ }).notNull(),
880
+ userId: key("user_id").notNull(),
881
+ accountRef: key("account_ref"),
882
+ agentName: key("agent_name").notNull(),
883
+ threadId: key("thread_id"),
884
+ parentId: key("parent_id"),
885
+ openDirectId: key("open_direct_id"),
886
+ status: key("status").notNull(),
887
+ responder: key("responder").notNull(),
888
+ context: (0, import_mysql_core.longtext)("context"),
889
+ activeRunId: key("active_run_id"),
890
+ turnSeq: (0, import_mysql_core.bigint)("turn_seq", {
891
+ mode: "number"
892
+ }).notNull(),
893
+ grantInfo: (0, import_mysql_core.longtext)("grant_info"),
894
+ readerHolder: key("reader_holder"),
895
+ readerUntil: (0, import_mysql_core.bigint)("reader_until", {
896
+ mode: "number"
897
+ }),
898
+ prunedSeq: (0, import_mysql_core.bigint)("pruned_seq", {
899
+ mode: "number"
900
+ }).notNull(),
901
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
902
+ mode: "number"
903
+ }).notNull(),
904
+ updatedAt: (0, import_mysql_core.bigint)("updated_at", {
905
+ mode: "number"
906
+ }).notNull()
907
+ });
908
+ var agentPoppyEvent2 = (0, import_mysql_core.mysqlTable)("agent_poppy_event", {
909
+ conversationId: key("conversation_id").notNull(),
910
+ seq: (0, import_mysql_core.bigint)("seq", {
911
+ mode: "number"
912
+ }).notNull(),
913
+ id: key("id").notNull(),
914
+ type: key("type").notNull(),
915
+ event: (0, import_mysql_core.longtext)("event").notNull(),
916
+ eventKey: key("event_key"),
917
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
918
+ mode: "number"
919
+ }).notNull()
920
+ }, (table) => [
921
+ (0, import_mysql_core.primaryKey)({
922
+ columns: [
923
+ table.conversationId,
924
+ table.seq
925
+ ]
926
+ }),
927
+ (0, import_mysql_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
928
+ (0, import_mysql_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
929
+ ]);
930
+ var agentPoppyMessage2 = (0, import_mysql_core.mysqlTable)("agent_poppy_message", {
931
+ owner: key("owner").notNull(),
932
+ messageId: key("message_id").notNull(),
933
+ fingerprint: key("fingerprint").notNull(),
934
+ conversationId: key("conversation_id").notNull(),
935
+ response: (0, import_mysql_core.longtext)("response").notNull(),
936
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
937
+ mode: "number"
938
+ }).notNull()
939
+ }, (table) => [
940
+ (0, import_mysql_core.primaryKey)({
941
+ columns: [
942
+ table.owner,
943
+ table.messageId
944
+ ]
945
+ })
946
+ ]);
947
+ var agentPoppyConnection2 = (0, import_mysql_core.mysqlTable)("agent_poppy_connection", {
948
+ owner: key("owner").notNull(),
949
+ issuer: (0, import_mysql_core.varchar)("issuer", {
950
+ length: 512
951
+ }).notNull(),
952
+ domain: key("domain").notNull(),
953
+ organization: key("organization").notNull(),
954
+ scope: (0, import_mysql_core.longtext)("scope").notNull(),
955
+ status: key("status").notNull(),
956
+ state: (0, import_mysql_core.longtext)("state").notNull(),
957
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
958
+ mode: "number"
959
+ }).notNull(),
960
+ updatedAt: (0, import_mysql_core.bigint)("updated_at", {
961
+ mode: "number"
962
+ }).notNull()
963
+ }, (table) => [
964
+ (0, import_mysql_core.primaryKey)({
965
+ columns: [
966
+ table.owner,
967
+ table.issuer
968
+ ]
969
+ })
970
+ ]);
971
+ var agentPoppyConnect2 = (0, import_mysql_core.mysqlTable)("agent_poppy_connect", {
972
+ id: key("id").primaryKey(),
973
+ owner: key("owner").notNull(),
974
+ domain: key("domain").notNull(),
975
+ issuer: (0, import_mysql_core.varchar)("issuer", {
976
+ length: 512
977
+ }).notNull(),
978
+ organization: key("organization").notNull(),
979
+ scope: (0, import_mysql_core.longtext)("scope").notNull(),
980
+ actor: (0, import_mysql_core.longtext)("actor"),
981
+ threadId: key("thread_id"),
982
+ runId: key("run_id"),
983
+ toolCallId: key("tool_call_id"),
984
+ flow: (0, import_mysql_core.longtext)("flow"),
985
+ status: key("status").notNull(),
986
+ expiresAt: (0, import_mysql_core.bigint)("expires_at", {
987
+ mode: "number"
988
+ }).notNull(),
989
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
990
+ mode: "number"
991
+ }).notNull()
992
+ });
775
993
  var mysqlAgentSchema = {
776
994
  agentActionProposal: agentActionProposal2,
777
995
  agentThread: agentThread2,
@@ -786,7 +1004,12 @@ var mysqlAgentSchema = {
786
1004
  ragIngestionLog: ragIngestionLog2,
787
1005
  agentConfirmToken: agentConfirmToken2,
788
1006
  agentChannelState: agentChannelState2,
789
- agentStreamFrame: agentStreamFrame2
1007
+ agentStreamFrame: agentStreamFrame2,
1008
+ agentPoppyConversation: agentPoppyConversation2,
1009
+ agentPoppyEvent: agentPoppyEvent2,
1010
+ agentPoppyMessage: agentPoppyMessage2,
1011
+ agentPoppyConnection: agentPoppyConnection2,
1012
+ agentPoppyConnect: agentPoppyConnect2
790
1013
  };
791
1014
 
792
1015
  // src/schema-pg.ts
@@ -1093,6 +1316,118 @@ var agentActionProposal3 = (0, import_pg_core.pgTable)("agent_action_proposal",
1093
1316
  (0, import_pg_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
1094
1317
  (0, import_pg_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
1095
1318
  ]);
1319
+ var agentPoppyConversation3 = (0, import_pg_core.pgTable)("agent_poppy_conversation", {
1320
+ id: (0, import_pg_core.text)("id").primaryKey(),
1321
+ clientId: (0, import_pg_core.text)("client_id").notNull(),
1322
+ userId: (0, import_pg_core.text)("user_id").notNull(),
1323
+ accountRef: (0, import_pg_core.text)("account_ref"),
1324
+ agentName: (0, import_pg_core.text)("agent_name").notNull(),
1325
+ threadId: (0, import_pg_core.text)("thread_id"),
1326
+ parentId: (0, import_pg_core.text)("parent_id"),
1327
+ openDirectId: (0, import_pg_core.text)("open_direct_id"),
1328
+ status: (0, import_pg_core.text)("status").notNull(),
1329
+ responder: (0, import_pg_core.text)("responder").notNull(),
1330
+ context: (0, import_pg_core.text)("context"),
1331
+ activeRunId: (0, import_pg_core.text)("active_run_id"),
1332
+ turnSeq: (0, import_pg_core.bigint)("turn_seq", {
1333
+ mode: "number"
1334
+ }).notNull(),
1335
+ grantInfo: (0, import_pg_core.text)("grant_info"),
1336
+ readerHolder: (0, import_pg_core.text)("reader_holder"),
1337
+ readerUntil: (0, import_pg_core.bigint)("reader_until", {
1338
+ mode: "number"
1339
+ }),
1340
+ prunedSeq: (0, import_pg_core.bigint)("pruned_seq", {
1341
+ mode: "number"
1342
+ }).notNull(),
1343
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1344
+ mode: "number"
1345
+ }).notNull(),
1346
+ updatedAt: (0, import_pg_core.bigint)("updated_at", {
1347
+ mode: "number"
1348
+ }).notNull()
1349
+ });
1350
+ var agentPoppyEvent3 = (0, import_pg_core.pgTable)("agent_poppy_event", {
1351
+ conversationId: (0, import_pg_core.text)("conversation_id").notNull(),
1352
+ seq: (0, import_pg_core.bigint)("seq", {
1353
+ mode: "number"
1354
+ }).notNull(),
1355
+ id: (0, import_pg_core.text)("id").notNull(),
1356
+ type: (0, import_pg_core.text)("type").notNull(),
1357
+ event: (0, import_pg_core.text)("event").notNull(),
1358
+ eventKey: (0, import_pg_core.text)("event_key"),
1359
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1360
+ mode: "number"
1361
+ }).notNull()
1362
+ }, (table) => [
1363
+ (0, import_pg_core.primaryKey)({
1364
+ columns: [
1365
+ table.conversationId,
1366
+ table.seq
1367
+ ]
1368
+ }),
1369
+ (0, import_pg_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
1370
+ (0, import_pg_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
1371
+ ]);
1372
+ var agentPoppyMessage3 = (0, import_pg_core.pgTable)("agent_poppy_message", {
1373
+ owner: (0, import_pg_core.text)("owner").notNull(),
1374
+ messageId: (0, import_pg_core.text)("message_id").notNull(),
1375
+ fingerprint: (0, import_pg_core.text)("fingerprint").notNull(),
1376
+ conversationId: (0, import_pg_core.text)("conversation_id").notNull(),
1377
+ response: (0, import_pg_core.text)("response").notNull(),
1378
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1379
+ mode: "number"
1380
+ }).notNull()
1381
+ }, (table) => [
1382
+ (0, import_pg_core.primaryKey)({
1383
+ columns: [
1384
+ table.owner,
1385
+ table.messageId
1386
+ ]
1387
+ })
1388
+ ]);
1389
+ var agentPoppyConnection3 = (0, import_pg_core.pgTable)("agent_poppy_connection", {
1390
+ owner: (0, import_pg_core.text)("owner").notNull(),
1391
+ issuer: (0, import_pg_core.text)("issuer").notNull(),
1392
+ domain: (0, import_pg_core.text)("domain").notNull(),
1393
+ organization: (0, import_pg_core.text)("organization").notNull(),
1394
+ scope: (0, import_pg_core.text)("scope").notNull(),
1395
+ status: (0, import_pg_core.text)("status").notNull(),
1396
+ state: (0, import_pg_core.text)("state").notNull(),
1397
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1398
+ mode: "number"
1399
+ }).notNull(),
1400
+ updatedAt: (0, import_pg_core.bigint)("updated_at", {
1401
+ mode: "number"
1402
+ }).notNull()
1403
+ }, (table) => [
1404
+ (0, import_pg_core.primaryKey)({
1405
+ columns: [
1406
+ table.owner,
1407
+ table.issuer
1408
+ ]
1409
+ })
1410
+ ]);
1411
+ var agentPoppyConnect3 = (0, import_pg_core.pgTable)("agent_poppy_connect", {
1412
+ id: (0, import_pg_core.text)("id").primaryKey(),
1413
+ owner: (0, import_pg_core.text)("owner").notNull(),
1414
+ domain: (0, import_pg_core.text)("domain").notNull(),
1415
+ issuer: (0, import_pg_core.text)("issuer").notNull(),
1416
+ organization: (0, import_pg_core.text)("organization").notNull(),
1417
+ scope: (0, import_pg_core.text)("scope").notNull(),
1418
+ actor: (0, import_pg_core.text)("actor"),
1419
+ threadId: (0, import_pg_core.text)("thread_id"),
1420
+ runId: (0, import_pg_core.text)("run_id"),
1421
+ toolCallId: (0, import_pg_core.text)("tool_call_id"),
1422
+ flow: (0, import_pg_core.text)("flow"),
1423
+ status: (0, import_pg_core.text)("status").notNull(),
1424
+ expiresAt: (0, import_pg_core.bigint)("expires_at", {
1425
+ mode: "number"
1426
+ }).notNull(),
1427
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1428
+ mode: "number"
1429
+ }).notNull()
1430
+ });
1096
1431
  var pgAgentSchema = {
1097
1432
  agentActionProposal: agentActionProposal3,
1098
1433
  agentThread: agentThread3,
@@ -1107,7 +1442,12 @@ var pgAgentSchema = {
1107
1442
  ragIngestionLog: ragIngestionLog3,
1108
1443
  agentConfirmToken: agentConfirmToken3,
1109
1444
  agentChannelState: agentChannelState3,
1110
- agentStreamFrame: agentStreamFrame3
1445
+ agentStreamFrame: agentStreamFrame3,
1446
+ agentPoppyConversation: agentPoppyConversation3,
1447
+ agentPoppyEvent: agentPoppyEvent3,
1448
+ agentPoppyMessage: agentPoppyMessage3,
1449
+ agentPoppyConnection: agentPoppyConnection3,
1450
+ agentPoppyConnect: agentPoppyConnect3
1111
1451
  };
1112
1452
 
1113
1453
  // src/dialect.ts
@@ -3938,14 +4278,392 @@ var DrizzleChannelStore = class {
3938
4278
  }
3939
4279
  };
3940
4280
 
4281
+ // src/drizzle-poppy-store.ts
4282
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
4283
+ var import_drizzle_orm11 = require("drizzle-orm");
4284
+ var MAX_APPEND_ATTEMPTS = 50;
4285
+ var sleep = /* @__PURE__ */ __name((ms) => new Promise((resolve) => setTimeout(resolve, ms)), "sleep");
4286
+ var nullable = /* @__PURE__ */ __name((value) => value == null ? null : String(value), "nullable");
4287
+ function toInt(value) {
4288
+ if (typeof value === "number") return value;
4289
+ if (typeof value === "bigint") return Number(value);
4290
+ if (typeof value === "string") return Number.parseInt(value, 10) || 0;
4291
+ return 0;
4292
+ }
4293
+ __name(toInt, "toInt");
4294
+ var PATCH_COLUMNS = {
4295
+ accountRef: "accountRef",
4296
+ threadId: "threadId",
4297
+ openDirectId: "openDirectId",
4298
+ status: "status",
4299
+ responder: "responder",
4300
+ context: "context",
4301
+ activeRunId: "activeRunId",
4302
+ turnSeq: "turnSeq",
4303
+ grant: "grantInfo",
4304
+ prunedSeq: "prunedSeq"
4305
+ };
4306
+ var DrizzlePoppyStore = class {
4307
+ static {
4308
+ __name(this, "DrizzlePoppyStore");
4309
+ }
4310
+ db;
4311
+ dialect;
4312
+ t;
4313
+ constructor(db) {
4314
+ this.dialect = agentDialectOf(db);
4315
+ this.t = agentTablesFor(this.dialect);
4316
+ this.db = asBuilder(db);
4317
+ }
4318
+ async createConversation(record) {
4319
+ await this.db.insert(this.t.agentPoppyConversation).values({
4320
+ id: record.id,
4321
+ clientId: record.clientId,
4322
+ userId: record.userId,
4323
+ accountRef: record.accountRef,
4324
+ agentName: record.agentName,
4325
+ threadId: record.threadId,
4326
+ parentId: record.parentId,
4327
+ openDirectId: record.openDirectId,
4328
+ status: record.status,
4329
+ responder: record.responder,
4330
+ context: JSON.stringify(record.context),
4331
+ activeRunId: record.activeRunId,
4332
+ turnSeq: record.turnSeq,
4333
+ grantInfo: record.grant === null ? null : JSON.stringify(record.grant),
4334
+ readerHolder: null,
4335
+ readerUntil: null,
4336
+ prunedSeq: record.prunedSeq,
4337
+ createdAt: record.createdAt,
4338
+ updatedAt: record.updatedAt
4339
+ });
4340
+ }
4341
+ async getConversation(id) {
4342
+ const table = this.t.agentPoppyConversation;
4343
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm11.eq)(table.id, id)).limit(1);
4344
+ if (!row) return null;
4345
+ return {
4346
+ id: row.id,
4347
+ clientId: row.clientId,
4348
+ userId: row.userId,
4349
+ accountRef: nullable(row.accountRef),
4350
+ agentName: row.agentName,
4351
+ threadId: nullable(row.threadId),
4352
+ parentId: nullable(row.parentId),
4353
+ openDirectId: nullable(row.openDirectId),
4354
+ status: row.status,
4355
+ responder: row.responder,
4356
+ context: row.context == null ? {} : JSON.parse(row.context),
4357
+ activeRunId: nullable(row.activeRunId),
4358
+ turnSeq: toInt(row.turnSeq),
4359
+ grant: row.grantInfo == null ? null : JSON.parse(row.grantInfo),
4360
+ prunedSeq: toInt(row.prunedSeq),
4361
+ createdAt: toInt(row.createdAt),
4362
+ updatedAt: toInt(row.updatedAt)
4363
+ };
4364
+ }
4365
+ async updateConversation(id, patch) {
4366
+ const table = this.t.agentPoppyConversation;
4367
+ const set = {
4368
+ updatedAt: Date.now()
4369
+ };
4370
+ for (const [key2, column] of Object.entries(PATCH_COLUMNS)) {
4371
+ const value = patch[key2];
4372
+ if (value === void 0) continue;
4373
+ set[column] = key2 === "context" || key2 === "grant" && value !== null ? JSON.stringify(value) : value;
4374
+ }
4375
+ await this.db.update(table).set(set).where((0, import_drizzle_orm11.eq)(table.id, id));
4376
+ }
4377
+ async appendEvent(conversationId, body, options = {}) {
4378
+ const table = this.t.agentPoppyEvent;
4379
+ for (let attempt = 1; ; attempt++) {
4380
+ if (options.key !== void 0) {
4381
+ const [existing] = await this.db.select({
4382
+ seq: table.seq,
4383
+ event: table.event
4384
+ }).from(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.conversationId, conversationId), (0, import_drizzle_orm11.eq)(table.eventKey, options.key))).limit(1);
4385
+ if (existing) {
4386
+ return {
4387
+ event: {
4388
+ seq: toInt(existing.seq),
4389
+ event: JSON.parse(existing.event)
4390
+ },
4391
+ created: false
4392
+ };
4393
+ }
4394
+ }
4395
+ const seq = await this.lastSeq(conversationId) + 1;
4396
+ const now = Date.now();
4397
+ const stored = {
4398
+ seq,
4399
+ event: {
4400
+ id: (0, import_nestjs_agent_core8.newEventId)(seq),
4401
+ created_at: new Date(now).toISOString(),
4402
+ ...body
4403
+ }
4404
+ };
4405
+ let inserted = false;
4406
+ try {
4407
+ inserted = await this.insertIgnore(table, {
4408
+ conversationId,
4409
+ seq,
4410
+ id: stored.event.id,
4411
+ type: body.type,
4412
+ event: JSON.stringify(stored.event),
4413
+ eventKey: options.key ?? null,
4414
+ createdAt: now
4415
+ });
4416
+ } catch (error) {
4417
+ if (!isUniqueViolation(error)) throw error;
4418
+ }
4419
+ if (inserted) return {
4420
+ event: stored,
4421
+ created: true
4422
+ };
4423
+ if (attempt >= MAX_APPEND_ATTEMPTS) {
4424
+ throw new Error(`poppy: could not append to ${conversationId} after ${attempt} attempts`);
4425
+ }
4426
+ await sleep(Math.random() * Math.min(attempt, 10) * 2);
4427
+ }
4428
+ }
4429
+ /** The last position taken: the last event's, or — every event pruned — the pruned floor. */
4430
+ async lastSeq(conversationId) {
4431
+ const table = this.t.agentPoppyEvent;
4432
+ const [last] = await this.db.select({
4433
+ seq: table.seq
4434
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.conversationId, conversationId)).orderBy((0, import_drizzle_orm11.desc)(table.seq)).limit(1);
4435
+ if (last) return toInt(last.seq);
4436
+ const conversations = this.t.agentPoppyConversation;
4437
+ const [conversation] = await this.db.select({
4438
+ prunedSeq: conversations.prunedSeq
4439
+ }).from(conversations).where((0, import_drizzle_orm11.eq)(conversations.id, conversationId)).limit(1);
4440
+ return toInt(conversation?.prunedSeq);
4441
+ }
4442
+ async listEvents(conversationId, afterSeq, limit) {
4443
+ const table = this.t.agentPoppyEvent;
4444
+ const rows = await this.db.select({
4445
+ seq: table.seq,
4446
+ event: table.event
4447
+ }).from(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.conversationId, conversationId), (0, import_drizzle_orm11.gt)(table.seq, afterSeq))).orderBy(table.seq).limit(limit);
4448
+ return rows.map((row) => ({
4449
+ seq: toInt(row.seq),
4450
+ event: JSON.parse(row.event)
4451
+ }));
4452
+ }
4453
+ async findEventSeq(conversationId, eventId) {
4454
+ const table = this.t.agentPoppyEvent;
4455
+ const [row] = await this.db.select({
4456
+ seq: table.seq
4457
+ }).from(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.conversationId, conversationId), (0, import_drizzle_orm11.eq)(table.id, eventId))).limit(1);
4458
+ return row ? toInt(row.seq) : null;
4459
+ }
4460
+ async pruneEvents(conversationId, before) {
4461
+ const table = this.t.agentPoppyEvent;
4462
+ const [last] = await this.db.select({
4463
+ seq: table.seq
4464
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.conversationId, conversationId)).orderBy((0, import_drizzle_orm11.desc)(table.seq)).limit(1);
4465
+ if (!last) return;
4466
+ const [dropped] = await this.db.select({
4467
+ seq: table.seq
4468
+ }).from(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.conversationId, conversationId), (0, import_drizzle_orm11.lt)(table.createdAt, before), (0, import_drizzle_orm11.lt)(table.seq, toInt(last.seq)))).orderBy((0, import_drizzle_orm11.desc)(table.seq)).limit(1);
4469
+ if (!dropped) return;
4470
+ const upTo = toInt(dropped.seq);
4471
+ const conversations = this.t.agentPoppyConversation;
4472
+ await this.db.update(conversations).set({
4473
+ prunedSeq: upTo
4474
+ }).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(conversations.id, conversationId), (0, import_drizzle_orm11.lt)(conversations.prunedSeq, upTo)));
4475
+ await this.db.delete(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.conversationId, conversationId), (0, import_drizzle_orm11.lte)(table.seq, upTo)));
4476
+ }
4477
+ async claimMessage(owner, messageId, receipt) {
4478
+ const table = this.t.agentPoppyMessage;
4479
+ for (let attempt = 1; ; attempt++) {
4480
+ const inserted = await this.insertIgnore(table, {
4481
+ owner,
4482
+ messageId,
4483
+ fingerprint: receipt.fingerprint,
4484
+ conversationId: receipt.conversationId,
4485
+ response: JSON.stringify(receipt.response),
4486
+ createdAt: Date.now()
4487
+ });
4488
+ if (inserted) return {
4489
+ status: "claimed"
4490
+ };
4491
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.owner, owner), (0, import_drizzle_orm11.eq)(table.messageId, messageId))).limit(1);
4492
+ if (row) {
4493
+ return {
4494
+ status: "existing",
4495
+ fingerprint: row.fingerprint,
4496
+ conversationId: row.conversationId,
4497
+ response: JSON.parse(row.response)
4498
+ };
4499
+ }
4500
+ if (attempt >= 5) throw new Error(`poppy: could not claim message ${messageId}`);
4501
+ }
4502
+ }
4503
+ async releaseMessage(owner, messageId) {
4504
+ const table = this.t.agentPoppyMessage;
4505
+ await this.db.delete(table).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.owner, owner), (0, import_drizzle_orm11.eq)(table.messageId, messageId)));
4506
+ }
4507
+ async leaseReader(conversationId, holder, ttlMs) {
4508
+ const table = this.t.agentPoppyConversation;
4509
+ const now = Date.now();
4510
+ const taken = await affectedRows(this.dialect, this.db.update(table).set({
4511
+ readerHolder: holder,
4512
+ readerUntil: now + ttlMs
4513
+ }).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.id, conversationId), (0, import_drizzle_orm11.or)((0, import_drizzle_orm11.isNull)(table.readerHolder), (0, import_drizzle_orm11.eq)(table.readerHolder, holder), (0, import_drizzle_orm11.lte)(table.readerUntil, now)))), table.id);
4514
+ if (taken === 1) return true;
4515
+ if (this.dialect !== "mysql") return false;
4516
+ const [row] = await this.db.select({
4517
+ holder: table.readerHolder
4518
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.id, conversationId)).limit(1);
4519
+ return row?.holder === holder;
4520
+ }
4521
+ async releaseReader(conversationId, holder) {
4522
+ const table = this.t.agentPoppyConversation;
4523
+ await this.db.update(table).set({
4524
+ readerHolder: null,
4525
+ readerUntil: null
4526
+ }).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.id, conversationId), (0, import_drizzle_orm11.eq)(table.readerHolder, holder)));
4527
+ }
4528
+ /** Insert `row`, skipping it on any duplicate key. `true` when it went in. */
4529
+ async insertIgnore(table, row) {
4530
+ if (this.dialect === "mysql") {
4531
+ const insert = this.db.insert(table);
4532
+ return mysqlAffectedRows(await insert.ignore().values(row)) === 1;
4533
+ }
4534
+ const statement = this.db.insert(table).values(row).onConflictDoNothing();
4535
+ return await affectedRows(this.dialect, statement, table.createdAt) === 1;
4536
+ }
4537
+ };
4538
+
4539
+ // src/drizzle-poppy-connection-store.ts
4540
+ var import_drizzle_orm12 = require("drizzle-orm");
4541
+ var nullable2 = /* @__PURE__ */ __name((value) => value == null ? null : String(value), "nullable");
4542
+ var toInt2 = /* @__PURE__ */ __name((value) => typeof value === "number" ? value : Number(value ?? 0), "toInt");
4543
+ var DrizzlePoppyConnectionStore = class {
4544
+ static {
4545
+ __name(this, "DrizzlePoppyConnectionStore");
4546
+ }
4547
+ db;
4548
+ dialect;
4549
+ t;
4550
+ constructor(db) {
4551
+ this.dialect = agentDialectOf(db);
4552
+ this.t = agentTablesFor(this.dialect);
4553
+ this.db = asBuilder(db);
4554
+ }
4555
+ async listConnections(owner) {
4556
+ const table = this.t.agentPoppyConnection;
4557
+ const rows = await this.db.select().from(table).where((0, import_drizzle_orm12.eq)(table.owner, owner)).orderBy((0, import_drizzle_orm12.asc)(table.domain), (0, import_drizzle_orm12.asc)(table.issuer));
4558
+ return rows.map(toConnection);
4559
+ }
4560
+ async getConnection(owner, issuer) {
4561
+ const table = this.t.agentPoppyConnection;
4562
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(table.owner, owner), (0, import_drizzle_orm12.eq)(table.issuer, issuer))).limit(1);
4563
+ return row ? toConnection(row) : null;
4564
+ }
4565
+ async saveConnection(record) {
4566
+ const table = this.t.agentPoppyConnection;
4567
+ const columns = {
4568
+ domain: record.domain,
4569
+ organization: record.organization,
4570
+ scope: record.scope,
4571
+ status: record.status,
4572
+ state: record.state,
4573
+ updatedAt: record.updatedAt
4574
+ };
4575
+ await upsert(this.dialect, this.db.insert(table).values({
4576
+ owner: record.owner,
4577
+ issuer: record.issuer,
4578
+ createdAt: record.createdAt,
4579
+ ...columns
4580
+ }), [
4581
+ table.owner,
4582
+ table.issuer
4583
+ ], columns);
4584
+ }
4585
+ async deleteConnection(owner, issuer) {
4586
+ const table = this.t.agentPoppyConnection;
4587
+ await this.db.delete(table).where((0, import_drizzle_orm12.and)((0, import_drizzle_orm12.eq)(table.owner, owner), (0, import_drizzle_orm12.eq)(table.issuer, issuer)));
4588
+ }
4589
+ async createPending(record) {
4590
+ const table = this.t.agentPoppyConnect;
4591
+ const row = {
4592
+ id: record.id,
4593
+ owner: record.owner,
4594
+ domain: record.domain,
4595
+ issuer: record.issuer,
4596
+ organization: record.organization,
4597
+ scope: record.scope,
4598
+ actor: record.actor === null ? null : JSON.stringify(record.actor),
4599
+ threadId: record.threadId,
4600
+ runId: record.runId,
4601
+ toolCallId: record.toolCallId,
4602
+ flow: record.flow,
4603
+ status: record.status,
4604
+ expiresAt: record.expiresAt,
4605
+ createdAt: record.createdAt
4606
+ };
4607
+ if (this.dialect === "mysql") {
4608
+ const insert = this.db.insert(table);
4609
+ await insert.ignore().values(row);
4610
+ return;
4611
+ }
4612
+ await this.db.insert(table).values(row).onConflictDoNothing();
4613
+ }
4614
+ async getPending(id) {
4615
+ const table = this.t.agentPoppyConnect;
4616
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm12.eq)(table.id, id)).limit(1);
4617
+ if (!row) return null;
4618
+ return {
4619
+ id: row.id,
4620
+ owner: row.owner,
4621
+ domain: row.domain,
4622
+ issuer: row.issuer,
4623
+ organization: row.organization,
4624
+ scope: row.scope ?? "",
4625
+ actor: row.actor == null ? null : JSON.parse(row.actor),
4626
+ threadId: nullable2(row.threadId),
4627
+ runId: nullable2(row.runId),
4628
+ toolCallId: nullable2(row.toolCallId),
4629
+ flow: nullable2(row.flow),
4630
+ status: row.status,
4631
+ expiresAt: toInt2(row.expiresAt),
4632
+ createdAt: toInt2(row.createdAt)
4633
+ };
4634
+ }
4635
+ async updatePending(id, patch) {
4636
+ const set = {};
4637
+ if (patch.flow !== void 0) set.flow = patch.flow;
4638
+ if (patch.status !== void 0) set.status = patch.status;
4639
+ if (Object.keys(set).length === 0) return;
4640
+ const table = this.t.agentPoppyConnect;
4641
+ await this.db.update(table).set(set).where((0, import_drizzle_orm12.eq)(table.id, id));
4642
+ }
4643
+ };
4644
+ function toConnection(row) {
4645
+ return {
4646
+ owner: row.owner,
4647
+ issuer: row.issuer,
4648
+ domain: row.domain,
4649
+ organization: row.organization,
4650
+ scope: row.scope ?? "",
4651
+ status: row.status,
4652
+ state: row.state,
4653
+ createdAt: toInt2(row.createdAt),
4654
+ updatedAt: toInt2(row.updatedAt)
4655
+ };
4656
+ }
4657
+ __name(toConnection, "toConnection");
4658
+
3941
4659
  // src/drizzle-rag-ingestion-log.ts
3942
4660
  var import_node_diagnostics_channel = require("diagnostics_channel");
3943
4661
  var import_common = require("@nestjs/common");
3944
- var import_drizzle_orm11 = require("drizzle-orm");
3945
- function _ts_decorate(decorators, target, key2, desc4) {
3946
- var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key2) : desc4, d;
4662
+ var import_drizzle_orm13 = require("drizzle-orm");
4663
+ function _ts_decorate(decorators, target, key2, desc5) {
4664
+ var c = arguments.length, r = c < 3 ? target : desc5 === null ? desc5 = Object.getOwnPropertyDescriptor(target, key2) : desc5, d;
3947
4665
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3948
- r = Reflect.decorate(decorators, target, key2, desc4);
4666
+ r = Reflect.decorate(decorators, target, key2, desc5);
3949
4667
  } else {
3950
4668
  for (var i = decorators.length - 1; i >= 0; i--) {
3951
4669
  if (d = decorators[i]) {
@@ -3989,8 +4707,8 @@ function num(value) {
3989
4707
  }
3990
4708
  __name(num, "num");
3991
4709
  var RAG_INGESTION_LOG_PAGE_ORDER = [
3992
- (0, import_drizzle_orm11.desc)(ragIngestionLog.updatedAt),
3993
- (0, import_drizzle_orm11.asc)(ragIngestionLog.documentId)
4710
+ (0, import_drizzle_orm13.desc)(ragIngestionLog.updatedAt),
4711
+ (0, import_drizzle_orm13.asc)(ragIngestionLog.documentId)
3994
4712
  ];
3995
4713
  var DEFAULT_PAGE_SIZE = 200;
3996
4714
  var DEFAULT_BATCH_SIZE = 200;
@@ -4061,7 +4779,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4061
4779
  */
4062
4780
  async listPage(query = {}) {
4063
4781
  const [totalRow] = await this.db.select({
4064
- value: (0, import_drizzle_orm11.count)()
4782
+ value: (0, import_drizzle_orm13.count)()
4065
4783
  }).from(this.t.ragIngestionLog).where(this.where(query));
4066
4784
  return {
4067
4785
  rows: await this.list(query),
@@ -4140,17 +4858,17 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4140
4858
  }
4141
4859
  /** The latest recorded outcome for one document, or null if it was never attempted. */
4142
4860
  async get(documentId) {
4143
- const [row] = await this.db.select().from(this.t.ragIngestionLog).where((0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.documentId, documentId));
4861
+ const [row] = await this.db.select().from(this.t.ragIngestionLog).where((0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.documentId, documentId));
4144
4862
  return row ?? null;
4145
4863
  }
4146
4864
  /** Forget one document's record. Returns whether a row was actually removed. */
4147
4865
  async remove(documentId) {
4148
- const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where((0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.documentId, documentId)), this.t.ragIngestionLog.documentId);
4866
+ const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where((0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.documentId, documentId)), this.t.ragIngestionLog.documentId);
4149
4867
  return removed > 0;
4150
4868
  }
4151
4869
  /** Forget every record for a collection — for when the collection itself is deleted. */
4152
4870
  async removeByCollection(collection) {
4153
- const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where((0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.collection, collection)), this.t.ragIngestionLog.documentId);
4871
+ const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where((0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.collection, collection)), this.t.ragIngestionLog.documentId);
4154
4872
  return removed;
4155
4873
  }
4156
4874
  /**
@@ -4180,7 +4898,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4180
4898
  }
4181
4899
  }
4182
4900
  where(query) {
4183
- return (0, import_drizzle_orm11.and)(query.collection !== void 0 ? (0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? (0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.status, query.status) : void 0);
4901
+ return (0, import_drizzle_orm13.and)(query.collection !== void 0 ? (0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? (0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.status, query.status) : void 0);
4184
4902
  }
4185
4903
  /**
4186
4904
  * The coordinates filter AND'd with "strictly after `cursor` in
@@ -4195,7 +4913,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4195
4913
  if (cursor === void 0) {
4196
4914
  return base;
4197
4915
  }
4198
- return (0, import_drizzle_orm11.and)(base, (0, import_drizzle_orm11.or)((0, import_drizzle_orm11.lt)(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm11.gt)(this.t.ragIngestionLog.documentId, cursor.documentId))));
4916
+ return (0, import_drizzle_orm13.and)(base, (0, import_drizzle_orm13.or)((0, import_drizzle_orm13.lt)(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm13.and)((0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), (0, import_drizzle_orm13.gt)(this.t.ragIngestionLog.documentId, cursor.documentId))));
4199
4917
  }
4200
4918
  /**
4201
4919
  * Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
@@ -4268,12 +4986,12 @@ DrizzleRagIngestionLog = _ts_decorate([
4268
4986
  ], DrizzleRagIngestionLog);
4269
4987
 
4270
4988
  // src/drizzle-agent-store.module.ts
4271
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
4989
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
4272
4990
  var import_common2 = require("@nestjs/common");
4273
- function _ts_decorate2(decorators, target, key2, desc4) {
4274
- var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key2) : desc4, d;
4991
+ function _ts_decorate2(decorators, target, key2, desc5) {
4992
+ var c = arguments.length, r = c < 3 ? target : desc5 === null ? desc5 = Object.getOwnPropertyDescriptor(target, key2) : desc5, d;
4275
4993
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4276
- r = Reflect.decorate(decorators, target, key2, desc4);
4994
+ r = Reflect.decorate(decorators, target, key2, desc5);
4277
4995
  } else {
4278
4996
  for (var i = decorators.length - 1; i >= 0; i--) {
4279
4997
  if (d = decorators[i]) {
@@ -4305,7 +5023,7 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4305
5023
  useFactory: /* @__PURE__ */ __name(() => new DrizzleAgentStore(options.db), "useFactory")
4306
5024
  },
4307
5025
  {
4308
- provide: import_nestjs_agent_core8.AGENT_STORE,
5026
+ provide: import_nestjs_agent_core9.AGENT_STORE,
4309
5027
  useExisting: DrizzleAgentStore
4310
5028
  },
4311
5029
  // Exported, never bound to AGENT_MEMORY: that token's PRESENCE is what turns memory on, so
@@ -4322,21 +5040,21 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4322
5040
  // AGENT_PRICING_STORE: the host's own store when supplied, else the default Drizzle one.
4323
5041
  // DrizzleGovernanceQueries prices usage against whatever is bound here.
4324
5042
  options.pricingStore ? {
4325
- provide: import_nestjs_agent_core8.AGENT_PRICING_STORE,
5043
+ provide: import_nestjs_agent_core9.AGENT_PRICING_STORE,
4326
5044
  useClass: options.pricingStore
4327
5045
  } : {
4328
- provide: import_nestjs_agent_core8.AGENT_PRICING_STORE,
5046
+ provide: import_nestjs_agent_core9.AGENT_PRICING_STORE,
4329
5047
  useExisting: DrizzlePricingStore
4330
5048
  },
4331
5049
  {
4332
5050
  provide: DrizzleGovernanceQueries,
4333
5051
  useFactory: /* @__PURE__ */ __name((pricingStore) => new DrizzleGovernanceQueries(options.db, pricingStore), "useFactory"),
4334
5052
  inject: [
4335
- import_nestjs_agent_core8.AGENT_PRICING_STORE
5053
+ import_nestjs_agent_core9.AGENT_PRICING_STORE
4336
5054
  ]
4337
5055
  },
4338
5056
  {
4339
- provide: import_nestjs_agent_core8.AGENT_GOVERNANCE_QUERIES,
5057
+ provide: import_nestjs_agent_core9.AGENT_GOVERNANCE_QUERIES,
4340
5058
  useExisting: DrizzleGovernanceQueries
4341
5059
  },
4342
5060
  // What makes a `defineConfirmedTool` confirmation single use across replicas.
@@ -4345,7 +5063,7 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4345
5063
  useFactory: /* @__PURE__ */ __name(() => new DrizzleConfirmTokenStore(options.db), "useFactory")
4346
5064
  },
4347
5065
  {
4348
- provide: import_nestjs_agent_core8.AGENT_CONFIRM_TOKEN_STORE,
5066
+ provide: import_nestjs_agent_core9.AGENT_CONFIRM_TOKEN_STORE,
4349
5067
  useExisting: DrizzleConfirmTokenStore
4350
5068
  },
4351
5069
  // Text channels' state (`@dudousxd/nestjs-agent-channels`), shared by every replica.
@@ -4354,8 +5072,25 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4354
5072
  useFactory: /* @__PURE__ */ __name(() => new DrizzleChannelStore(options.db), "useFactory")
4355
5073
  },
4356
5074
  {
4357
- provide: import_nestjs_agent_core8.AGENT_CHANNEL_STORE,
5075
+ provide: import_nestjs_agent_core9.AGENT_CHANNEL_STORE,
4358
5076
  useExisting: DrizzleChannelStore
5077
+ },
5078
+ // Personal Agent Protocol (Poppy) conversations and connections, shared by every replica.
5079
+ {
5080
+ provide: DrizzlePoppyStore,
5081
+ useFactory: /* @__PURE__ */ __name(() => new DrizzlePoppyStore(options.db), "useFactory")
5082
+ },
5083
+ {
5084
+ provide: import_nestjs_agent_core9.AGENT_POPPY_STORE,
5085
+ useExisting: DrizzlePoppyStore
5086
+ },
5087
+ {
5088
+ provide: DrizzlePoppyConnectionStore,
5089
+ useFactory: /* @__PURE__ */ __name(() => new DrizzlePoppyConnectionStore(options.db), "useFactory")
5090
+ },
5091
+ {
5092
+ provide: import_nestjs_agent_core9.AGENT_POPPY_CONNECTION_STORE,
5093
+ useExisting: DrizzlePoppyConnectionStore
4359
5094
  }
4360
5095
  ],
4361
5096
  exports: [
@@ -4363,16 +5098,20 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4363
5098
  DrizzleRagIngestionLog
4364
5099
  ],
4365
5100
  DrizzleAgentStore,
4366
- import_nestjs_agent_core8.AGENT_STORE,
5101
+ import_nestjs_agent_core9.AGENT_STORE,
4367
5102
  DrizzleMemoryProvider,
4368
5103
  DrizzleGovernanceQueries,
4369
- import_nestjs_agent_core8.AGENT_GOVERNANCE_QUERIES,
5104
+ import_nestjs_agent_core9.AGENT_GOVERNANCE_QUERIES,
4370
5105
  DrizzlePricingStore,
4371
- import_nestjs_agent_core8.AGENT_PRICING_STORE,
5106
+ import_nestjs_agent_core9.AGENT_PRICING_STORE,
4372
5107
  DrizzleConfirmTokenStore,
4373
- import_nestjs_agent_core8.AGENT_CONFIRM_TOKEN_STORE,
5108
+ import_nestjs_agent_core9.AGENT_CONFIRM_TOKEN_STORE,
4374
5109
  DrizzleChannelStore,
4375
- import_nestjs_agent_core8.AGENT_CHANNEL_STORE
5110
+ import_nestjs_agent_core9.AGENT_CHANNEL_STORE,
5111
+ DrizzlePoppyStore,
5112
+ import_nestjs_agent_core9.AGENT_POPPY_STORE,
5113
+ DrizzlePoppyConnectionStore,
5114
+ import_nestjs_agent_core9.AGENT_POPPY_CONNECTION_STORE
4376
5115
  ]
4377
5116
  };
4378
5117
  }
@@ -4389,6 +5128,8 @@ DrizzleAgentStoreModule = _ts_decorate2([
4389
5128
  DrizzleConfirmTokenStore,
4390
5129
  DrizzleGovernanceQueries,
4391
5130
  DrizzleMemoryProvider,
5131
+ DrizzlePoppyConnectionStore,
5132
+ DrizzlePoppyStore,
4392
5133
  DrizzlePricingStore,
4393
5134
  DrizzleRagIngestionLog,
4394
5135
  DrizzleStreamFrameTable,
@@ -4402,6 +5143,11 @@ DrizzleAgentStoreModule = _ts_decorate2([
4402
5143
  agentMemory,
4403
5144
  agentMessage,
4404
5145
  agentModelPricing,
5146
+ agentPoppyConnect,
5147
+ agentPoppyConnection,
5148
+ agentPoppyConversation,
5149
+ agentPoppyEvent,
5150
+ agentPoppyMessage,
4405
5151
  agentQueuedMessage,
4406
5152
  agentRun,
4407
5153
  agentSchema,