@dudousxd/nestjs-agent-store-drizzle 0.30.0 → 0.32.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,
@@ -304,6 +311,12 @@ var agentRun = (0, import_sqlite_core.sqliteTable)("agent_run", {
304
311
  agentName: (0, import_sqlite_core.text)("agent_name"),
305
312
  status: (0, import_sqlite_core.text)("status").$type().notNull(),
306
313
  durationMs: (0, import_sqlite_core.integer)("duration_ms"),
314
+ /** Turn start to the first `text` frame; null for a run that streamed none or did not complete. */
315
+ ttftMs: (0, import_sqlite_core.integer)("ttft_ms"),
316
+ /** The run's known spend (the sum of its model calls with a known cost); null when none had one. */
317
+ costUsd: (0, import_sqlite_core.real)("cost_usd"),
318
+ /** The model the run's last model call resolved to. */
319
+ modelId: (0, import_sqlite_core.text)("model_id"),
307
320
  errorCode: (0, import_sqlite_core.text)("error_code"),
308
321
  errorMessage: (0, import_sqlite_core.text)("error_message"),
309
322
  retries: (0, import_sqlite_core.integer)("retries").notNull().default(0),
@@ -436,6 +449,94 @@ var agentActionProposal = (0, import_sqlite_core.sqliteTable)("agent_action_prop
436
449
  (0, import_sqlite_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
437
450
  (0, import_sqlite_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
438
451
  ]);
452
+ var agentPoppyConversation = (0, import_sqlite_core.sqliteTable)("agent_poppy_conversation", {
453
+ id: (0, import_sqlite_core.text)("id").primaryKey(),
454
+ clientId: (0, import_sqlite_core.text)("client_id").notNull(),
455
+ userId: (0, import_sqlite_core.text)("user_id").notNull(),
456
+ accountRef: (0, import_sqlite_core.text)("account_ref"),
457
+ agentName: (0, import_sqlite_core.text)("agent_name").notNull(),
458
+ threadId: (0, import_sqlite_core.text)("thread_id"),
459
+ parentId: (0, import_sqlite_core.text)("parent_id"),
460
+ openDirectId: (0, import_sqlite_core.text)("open_direct_id"),
461
+ status: (0, import_sqlite_core.text)("status").notNull(),
462
+ responder: (0, import_sqlite_core.text)("responder").notNull(),
463
+ context: (0, import_sqlite_core.text)("context"),
464
+ activeRunId: (0, import_sqlite_core.text)("active_run_id"),
465
+ turnSeq: (0, import_sqlite_core.integer)("turn_seq").notNull(),
466
+ grantInfo: (0, import_sqlite_core.text)("grant_info"),
467
+ readerHolder: (0, import_sqlite_core.text)("reader_holder"),
468
+ readerUntil: (0, import_sqlite_core.integer)("reader_until"),
469
+ prunedSeq: (0, import_sqlite_core.integer)("pruned_seq").notNull(),
470
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
471
+ updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
472
+ });
473
+ var agentPoppyEvent = (0, import_sqlite_core.sqliteTable)("agent_poppy_event", {
474
+ conversationId: (0, import_sqlite_core.text)("conversation_id").notNull(),
475
+ seq: (0, import_sqlite_core.integer)("seq").notNull(),
476
+ id: (0, import_sqlite_core.text)("id").notNull(),
477
+ type: (0, import_sqlite_core.text)("type").notNull(),
478
+ event: (0, import_sqlite_core.text)("event").notNull(),
479
+ eventKey: (0, import_sqlite_core.text)("event_key"),
480
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
481
+ }, (table) => [
482
+ (0, import_sqlite_core.primaryKey)({
483
+ columns: [
484
+ table.conversationId,
485
+ table.seq
486
+ ]
487
+ }),
488
+ (0, import_sqlite_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
489
+ (0, import_sqlite_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
490
+ ]);
491
+ var agentPoppyMessage = (0, import_sqlite_core.sqliteTable)("agent_poppy_message", {
492
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
493
+ messageId: (0, import_sqlite_core.text)("message_id").notNull(),
494
+ fingerprint: (0, import_sqlite_core.text)("fingerprint").notNull(),
495
+ conversationId: (0, import_sqlite_core.text)("conversation_id").notNull(),
496
+ response: (0, import_sqlite_core.text)("response").notNull(),
497
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
498
+ }, (table) => [
499
+ (0, import_sqlite_core.primaryKey)({
500
+ columns: [
501
+ table.owner,
502
+ table.messageId
503
+ ]
504
+ })
505
+ ]);
506
+ var agentPoppyConnection = (0, import_sqlite_core.sqliteTable)("agent_poppy_connection", {
507
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
508
+ issuer: (0, import_sqlite_core.text)("issuer").notNull(),
509
+ domain: (0, import_sqlite_core.text)("domain").notNull(),
510
+ organization: (0, import_sqlite_core.text)("organization").notNull(),
511
+ scope: (0, import_sqlite_core.text)("scope").notNull(),
512
+ status: (0, import_sqlite_core.text)("status").notNull(),
513
+ state: (0, import_sqlite_core.text)("state").notNull(),
514
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull(),
515
+ updatedAt: (0, import_sqlite_core.integer)("updated_at").notNull()
516
+ }, (table) => [
517
+ (0, import_sqlite_core.primaryKey)({
518
+ columns: [
519
+ table.owner,
520
+ table.issuer
521
+ ]
522
+ })
523
+ ]);
524
+ var agentPoppyConnect = (0, import_sqlite_core.sqliteTable)("agent_poppy_connect", {
525
+ id: (0, import_sqlite_core.text)("id").primaryKey(),
526
+ owner: (0, import_sqlite_core.text)("owner").notNull(),
527
+ domain: (0, import_sqlite_core.text)("domain").notNull(),
528
+ issuer: (0, import_sqlite_core.text)("issuer").notNull(),
529
+ organization: (0, import_sqlite_core.text)("organization").notNull(),
530
+ scope: (0, import_sqlite_core.text)("scope").notNull(),
531
+ actor: (0, import_sqlite_core.text)("actor"),
532
+ threadId: (0, import_sqlite_core.text)("thread_id"),
533
+ runId: (0, import_sqlite_core.text)("run_id"),
534
+ toolCallId: (0, import_sqlite_core.text)("tool_call_id"),
535
+ flow: (0, import_sqlite_core.text)("flow"),
536
+ status: (0, import_sqlite_core.text)("status").notNull(),
537
+ expiresAt: (0, import_sqlite_core.integer)("expires_at").notNull(),
538
+ createdAt: (0, import_sqlite_core.integer)("created_at").notNull()
539
+ });
439
540
  var agentSchema = {
440
541
  agentActionProposal,
441
542
  agentThread,
@@ -450,7 +551,12 @@ var agentSchema = {
450
551
  ragIngestionLog,
451
552
  agentConfirmToken,
452
553
  agentChannelState,
453
- agentStreamFrame
554
+ agentStreamFrame,
555
+ agentPoppyConversation,
556
+ agentPoppyEvent,
557
+ agentPoppyMessage,
558
+ agentPoppyConnection,
559
+ agentPoppyConnect
454
560
  };
455
561
 
456
562
  // src/ensure-schema.ts
@@ -643,6 +749,12 @@ var agentRun2 = (0, import_mysql_core.mysqlTable)("agent_run", {
643
749
  agentName: key("agent_name"),
644
750
  status: key("status").$type().notNull(),
645
751
  durationMs: (0, import_mysql_core.int)("duration_ms"),
752
+ /** Turn start to the first `text` frame; null for a run that streamed none or did not complete. */
753
+ ttftMs: (0, import_mysql_core.int)("ttft_ms"),
754
+ /** The run's known spend (the sum of its model calls with a known cost); null when none had one. */
755
+ costUsd: (0, import_mysql_core.double)("cost_usd"),
756
+ /** The model the run's last model call resolved to. */
757
+ modelId: key("model_id"),
646
758
  errorCode: key("error_code"),
647
759
  errorMessage: (0, import_mysql_core.longtext)("error_message"),
648
760
  retries: (0, import_mysql_core.int)("retries").notNull().default(0),
@@ -772,6 +884,124 @@ var agentActionProposal2 = (0, import_mysql_core.mysqlTable)("agent_action_propo
772
884
  (0, import_mysql_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
773
885
  (0, import_mysql_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
774
886
  ]);
887
+ var agentPoppyConversation2 = (0, import_mysql_core.mysqlTable)("agent_poppy_conversation", {
888
+ id: key("id").primaryKey(),
889
+ clientId: (0, import_mysql_core.varchar)("client_id", {
890
+ length: 2048
891
+ }).notNull(),
892
+ userId: key("user_id").notNull(),
893
+ accountRef: key("account_ref"),
894
+ agentName: key("agent_name").notNull(),
895
+ threadId: key("thread_id"),
896
+ parentId: key("parent_id"),
897
+ openDirectId: key("open_direct_id"),
898
+ status: key("status").notNull(),
899
+ responder: key("responder").notNull(),
900
+ context: (0, import_mysql_core.longtext)("context"),
901
+ activeRunId: key("active_run_id"),
902
+ turnSeq: (0, import_mysql_core.bigint)("turn_seq", {
903
+ mode: "number"
904
+ }).notNull(),
905
+ grantInfo: (0, import_mysql_core.longtext)("grant_info"),
906
+ readerHolder: key("reader_holder"),
907
+ readerUntil: (0, import_mysql_core.bigint)("reader_until", {
908
+ mode: "number"
909
+ }),
910
+ prunedSeq: (0, import_mysql_core.bigint)("pruned_seq", {
911
+ mode: "number"
912
+ }).notNull(),
913
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
914
+ mode: "number"
915
+ }).notNull(),
916
+ updatedAt: (0, import_mysql_core.bigint)("updated_at", {
917
+ mode: "number"
918
+ }).notNull()
919
+ });
920
+ var agentPoppyEvent2 = (0, import_mysql_core.mysqlTable)("agent_poppy_event", {
921
+ conversationId: key("conversation_id").notNull(),
922
+ seq: (0, import_mysql_core.bigint)("seq", {
923
+ mode: "number"
924
+ }).notNull(),
925
+ id: key("id").notNull(),
926
+ type: key("type").notNull(),
927
+ event: (0, import_mysql_core.longtext)("event").notNull(),
928
+ eventKey: key("event_key"),
929
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
930
+ mode: "number"
931
+ }).notNull()
932
+ }, (table) => [
933
+ (0, import_mysql_core.primaryKey)({
934
+ columns: [
935
+ table.conversationId,
936
+ table.seq
937
+ ]
938
+ }),
939
+ (0, import_mysql_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
940
+ (0, import_mysql_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
941
+ ]);
942
+ var agentPoppyMessage2 = (0, import_mysql_core.mysqlTable)("agent_poppy_message", {
943
+ owner: key("owner").notNull(),
944
+ messageId: key("message_id").notNull(),
945
+ fingerprint: key("fingerprint").notNull(),
946
+ conversationId: key("conversation_id").notNull(),
947
+ response: (0, import_mysql_core.longtext)("response").notNull(),
948
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
949
+ mode: "number"
950
+ }).notNull()
951
+ }, (table) => [
952
+ (0, import_mysql_core.primaryKey)({
953
+ columns: [
954
+ table.owner,
955
+ table.messageId
956
+ ]
957
+ })
958
+ ]);
959
+ var agentPoppyConnection2 = (0, import_mysql_core.mysqlTable)("agent_poppy_connection", {
960
+ owner: key("owner").notNull(),
961
+ issuer: (0, import_mysql_core.varchar)("issuer", {
962
+ length: 512
963
+ }).notNull(),
964
+ domain: key("domain").notNull(),
965
+ organization: key("organization").notNull(),
966
+ scope: (0, import_mysql_core.longtext)("scope").notNull(),
967
+ status: key("status").notNull(),
968
+ state: (0, import_mysql_core.longtext)("state").notNull(),
969
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
970
+ mode: "number"
971
+ }).notNull(),
972
+ updatedAt: (0, import_mysql_core.bigint)("updated_at", {
973
+ mode: "number"
974
+ }).notNull()
975
+ }, (table) => [
976
+ (0, import_mysql_core.primaryKey)({
977
+ columns: [
978
+ table.owner,
979
+ table.issuer
980
+ ]
981
+ })
982
+ ]);
983
+ var agentPoppyConnect2 = (0, import_mysql_core.mysqlTable)("agent_poppy_connect", {
984
+ id: key("id").primaryKey(),
985
+ owner: key("owner").notNull(),
986
+ domain: key("domain").notNull(),
987
+ issuer: (0, import_mysql_core.varchar)("issuer", {
988
+ length: 512
989
+ }).notNull(),
990
+ organization: key("organization").notNull(),
991
+ scope: (0, import_mysql_core.longtext)("scope").notNull(),
992
+ actor: (0, import_mysql_core.longtext)("actor"),
993
+ threadId: key("thread_id"),
994
+ runId: key("run_id"),
995
+ toolCallId: key("tool_call_id"),
996
+ flow: (0, import_mysql_core.longtext)("flow"),
997
+ status: key("status").notNull(),
998
+ expiresAt: (0, import_mysql_core.bigint)("expires_at", {
999
+ mode: "number"
1000
+ }).notNull(),
1001
+ createdAt: (0, import_mysql_core.bigint)("created_at", {
1002
+ mode: "number"
1003
+ }).notNull()
1004
+ });
775
1005
  var mysqlAgentSchema = {
776
1006
  agentActionProposal: agentActionProposal2,
777
1007
  agentThread: agentThread2,
@@ -786,7 +1016,12 @@ var mysqlAgentSchema = {
786
1016
  ragIngestionLog: ragIngestionLog2,
787
1017
  agentConfirmToken: agentConfirmToken2,
788
1018
  agentChannelState: agentChannelState2,
789
- agentStreamFrame: agentStreamFrame2
1019
+ agentStreamFrame: agentStreamFrame2,
1020
+ agentPoppyConversation: agentPoppyConversation2,
1021
+ agentPoppyEvent: agentPoppyEvent2,
1022
+ agentPoppyMessage: agentPoppyMessage2,
1023
+ agentPoppyConnection: agentPoppyConnection2,
1024
+ agentPoppyConnect: agentPoppyConnect2
790
1025
  };
791
1026
 
792
1027
  // src/schema-pg.ts
@@ -966,6 +1201,12 @@ var agentRun3 = (0, import_pg_core.pgTable)("agent_run", {
966
1201
  agentName: (0, import_pg_core.text)("agent_name"),
967
1202
  status: (0, import_pg_core.text)("status").$type().notNull(),
968
1203
  durationMs: (0, import_pg_core.integer)("duration_ms"),
1204
+ /** Turn start to the first `text` frame; null for a run that streamed none or did not complete. */
1205
+ ttftMs: (0, import_pg_core.integer)("ttft_ms"),
1206
+ /** The run's known spend (the sum of its model calls with a known cost); null when none had one. */
1207
+ costUsd: (0, import_pg_core.doublePrecision)("cost_usd"),
1208
+ /** The model the run's last model call resolved to. */
1209
+ modelId: (0, import_pg_core.text)("model_id"),
969
1210
  errorCode: (0, import_pg_core.text)("error_code"),
970
1211
  errorMessage: (0, import_pg_core.text)("error_message"),
971
1212
  retries: (0, import_pg_core.integer)("retries").notNull().default(0),
@@ -1093,6 +1334,118 @@ var agentActionProposal3 = (0, import_pg_core.pgTable)("agent_action_proposal",
1093
1334
  (0, import_pg_core.uniqueIndex)("agent_action_proposal_outcome_idx").on(table.outcomeIdKey),
1094
1335
  (0, import_pg_core.index)("agent_action_proposal_scope_idx").on(table.scopeKey, table.createdAt, table.id)
1095
1336
  ]);
1337
+ var agentPoppyConversation3 = (0, import_pg_core.pgTable)("agent_poppy_conversation", {
1338
+ id: (0, import_pg_core.text)("id").primaryKey(),
1339
+ clientId: (0, import_pg_core.text)("client_id").notNull(),
1340
+ userId: (0, import_pg_core.text)("user_id").notNull(),
1341
+ accountRef: (0, import_pg_core.text)("account_ref"),
1342
+ agentName: (0, import_pg_core.text)("agent_name").notNull(),
1343
+ threadId: (0, import_pg_core.text)("thread_id"),
1344
+ parentId: (0, import_pg_core.text)("parent_id"),
1345
+ openDirectId: (0, import_pg_core.text)("open_direct_id"),
1346
+ status: (0, import_pg_core.text)("status").notNull(),
1347
+ responder: (0, import_pg_core.text)("responder").notNull(),
1348
+ context: (0, import_pg_core.text)("context"),
1349
+ activeRunId: (0, import_pg_core.text)("active_run_id"),
1350
+ turnSeq: (0, import_pg_core.bigint)("turn_seq", {
1351
+ mode: "number"
1352
+ }).notNull(),
1353
+ grantInfo: (0, import_pg_core.text)("grant_info"),
1354
+ readerHolder: (0, import_pg_core.text)("reader_holder"),
1355
+ readerUntil: (0, import_pg_core.bigint)("reader_until", {
1356
+ mode: "number"
1357
+ }),
1358
+ prunedSeq: (0, import_pg_core.bigint)("pruned_seq", {
1359
+ mode: "number"
1360
+ }).notNull(),
1361
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1362
+ mode: "number"
1363
+ }).notNull(),
1364
+ updatedAt: (0, import_pg_core.bigint)("updated_at", {
1365
+ mode: "number"
1366
+ }).notNull()
1367
+ });
1368
+ var agentPoppyEvent3 = (0, import_pg_core.pgTable)("agent_poppy_event", {
1369
+ conversationId: (0, import_pg_core.text)("conversation_id").notNull(),
1370
+ seq: (0, import_pg_core.bigint)("seq", {
1371
+ mode: "number"
1372
+ }).notNull(),
1373
+ id: (0, import_pg_core.text)("id").notNull(),
1374
+ type: (0, import_pg_core.text)("type").notNull(),
1375
+ event: (0, import_pg_core.text)("event").notNull(),
1376
+ eventKey: (0, import_pg_core.text)("event_key"),
1377
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1378
+ mode: "number"
1379
+ }).notNull()
1380
+ }, (table) => [
1381
+ (0, import_pg_core.primaryKey)({
1382
+ columns: [
1383
+ table.conversationId,
1384
+ table.seq
1385
+ ]
1386
+ }),
1387
+ (0, import_pg_core.uniqueIndex)("agent_poppy_event_key_idx").on(table.conversationId, table.eventKey),
1388
+ (0, import_pg_core.index)("agent_poppy_event_id_idx").on(table.conversationId, table.id)
1389
+ ]);
1390
+ var agentPoppyMessage3 = (0, import_pg_core.pgTable)("agent_poppy_message", {
1391
+ owner: (0, import_pg_core.text)("owner").notNull(),
1392
+ messageId: (0, import_pg_core.text)("message_id").notNull(),
1393
+ fingerprint: (0, import_pg_core.text)("fingerprint").notNull(),
1394
+ conversationId: (0, import_pg_core.text)("conversation_id").notNull(),
1395
+ response: (0, import_pg_core.text)("response").notNull(),
1396
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1397
+ mode: "number"
1398
+ }).notNull()
1399
+ }, (table) => [
1400
+ (0, import_pg_core.primaryKey)({
1401
+ columns: [
1402
+ table.owner,
1403
+ table.messageId
1404
+ ]
1405
+ })
1406
+ ]);
1407
+ var agentPoppyConnection3 = (0, import_pg_core.pgTable)("agent_poppy_connection", {
1408
+ owner: (0, import_pg_core.text)("owner").notNull(),
1409
+ issuer: (0, import_pg_core.text)("issuer").notNull(),
1410
+ domain: (0, import_pg_core.text)("domain").notNull(),
1411
+ organization: (0, import_pg_core.text)("organization").notNull(),
1412
+ scope: (0, import_pg_core.text)("scope").notNull(),
1413
+ status: (0, import_pg_core.text)("status").notNull(),
1414
+ state: (0, import_pg_core.text)("state").notNull(),
1415
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1416
+ mode: "number"
1417
+ }).notNull(),
1418
+ updatedAt: (0, import_pg_core.bigint)("updated_at", {
1419
+ mode: "number"
1420
+ }).notNull()
1421
+ }, (table) => [
1422
+ (0, import_pg_core.primaryKey)({
1423
+ columns: [
1424
+ table.owner,
1425
+ table.issuer
1426
+ ]
1427
+ })
1428
+ ]);
1429
+ var agentPoppyConnect3 = (0, import_pg_core.pgTable)("agent_poppy_connect", {
1430
+ id: (0, import_pg_core.text)("id").primaryKey(),
1431
+ owner: (0, import_pg_core.text)("owner").notNull(),
1432
+ domain: (0, import_pg_core.text)("domain").notNull(),
1433
+ issuer: (0, import_pg_core.text)("issuer").notNull(),
1434
+ organization: (0, import_pg_core.text)("organization").notNull(),
1435
+ scope: (0, import_pg_core.text)("scope").notNull(),
1436
+ actor: (0, import_pg_core.text)("actor"),
1437
+ threadId: (0, import_pg_core.text)("thread_id"),
1438
+ runId: (0, import_pg_core.text)("run_id"),
1439
+ toolCallId: (0, import_pg_core.text)("tool_call_id"),
1440
+ flow: (0, import_pg_core.text)("flow"),
1441
+ status: (0, import_pg_core.text)("status").notNull(),
1442
+ expiresAt: (0, import_pg_core.bigint)("expires_at", {
1443
+ mode: "number"
1444
+ }).notNull(),
1445
+ createdAt: (0, import_pg_core.bigint)("created_at", {
1446
+ mode: "number"
1447
+ }).notNull()
1448
+ });
1096
1449
  var pgAgentSchema = {
1097
1450
  agentActionProposal: agentActionProposal3,
1098
1451
  agentThread: agentThread3,
@@ -1107,7 +1460,12 @@ var pgAgentSchema = {
1107
1460
  ragIngestionLog: ragIngestionLog3,
1108
1461
  agentConfirmToken: agentConfirmToken3,
1109
1462
  agentChannelState: agentChannelState3,
1110
- agentStreamFrame: agentStreamFrame3
1463
+ agentStreamFrame: agentStreamFrame3,
1464
+ agentPoppyConversation: agentPoppyConversation3,
1465
+ agentPoppyEvent: agentPoppyEvent3,
1466
+ agentPoppyMessage: agentPoppyMessage3,
1467
+ agentPoppyConnection: agentPoppyConnection3,
1468
+ agentPoppyConnect: agentPoppyConnect3
1111
1469
  };
1112
1470
 
1113
1471
  // src/dialect.ts
@@ -2464,6 +2822,9 @@ var DrizzleAgentStore = class {
2464
2822
  agentName: run.agentName ?? null,
2465
2823
  status: "running",
2466
2824
  durationMs: null,
2825
+ ttftMs: null,
2826
+ costUsd: null,
2827
+ modelId: null,
2467
2828
  errorCode: null,
2468
2829
  errorMessage: null,
2469
2830
  retries: 0,
@@ -2483,6 +2844,15 @@ var DrizzleAgentStore = class {
2483
2844
  if (end.durationMs !== void 0) {
2484
2845
  updates.durationMs = end.durationMs;
2485
2846
  }
2847
+ if (end.ttftMs !== void 0) {
2848
+ updates.ttftMs = end.ttftMs;
2849
+ }
2850
+ if (end.costUsd !== void 0) {
2851
+ updates.costUsd = end.costUsd;
2852
+ }
2853
+ if (end.modelId !== void 0) {
2854
+ updates.modelId = end.modelId;
2855
+ }
2486
2856
  if (end.errorCode !== void 0) {
2487
2857
  updates.errorCode = end.errorCode;
2488
2858
  }
@@ -2968,6 +3338,11 @@ function toRecentRunRow(run) {
2968
3338
  agentName: run.agentName ?? null,
2969
3339
  status: run.status,
2970
3340
  durationMs: run.durationMs ?? null,
3341
+ ttftMs: run.ttftMs ?? null,
3342
+ // MySQL's DOUBLE and Postgres' double precision come back as numbers; a driver that hands a
3343
+ // decimal back as a string is normalized here so the SPI row is always a number.
3344
+ costUsd: run.costUsd == null ? null : Number(run.costUsd),
3345
+ modelId: run.modelId ?? null,
2971
3346
  errorCode: run.errorCode ?? null,
2972
3347
  errorMessage: run.errorMessage ?? null,
2973
3348
  retries: run.retries,
@@ -3171,6 +3546,7 @@ var DrizzleGovernanceQueries = class {
3171
3546
  let failed = 0;
3172
3547
  let retries = 0;
3173
3548
  const settledDurationsMs = [];
3549
+ const ttftsMs = [];
3174
3550
  for (const run of runs) {
3175
3551
  if (run.status === "completed") {
3176
3552
  completed += 1;
@@ -3181,8 +3557,12 @@ var DrizzleGovernanceQueries = class {
3181
3557
  if ((run.status === "completed" || run.status === "failed") && run.durationMs != null) {
3182
3558
  settledDurationsMs.push(run.durationMs);
3183
3559
  }
3560
+ if (run.status === "completed" && run.parentRunId == null && run.ttftMs != null) {
3561
+ ttftsMs.push(run.ttftMs);
3562
+ }
3184
3563
  }
3185
3564
  settledDurationsMs.sort((left, right) => left - right);
3565
+ ttftsMs.sort((left, right) => left - right);
3186
3566
  return {
3187
3567
  runs: runs.length,
3188
3568
  completed,
@@ -3190,7 +3570,9 @@ var DrizzleGovernanceQueries = class {
3190
3570
  successRate: runs.length === 0 ? 0 : completed / runs.length,
3191
3571
  retries,
3192
3572
  durationP50Ms: percentileMs(settledDurationsMs, 0.5),
3193
- durationP95Ms: percentileMs(settledDurationsMs, 0.95)
3573
+ durationP95Ms: percentileMs(settledDurationsMs, 0.95),
3574
+ ttftP50Ms: percentileMs(ttftsMs, 0.5),
3575
+ ttftP95Ms: percentileMs(ttftsMs, 0.95)
3194
3576
  };
3195
3577
  }
3196
3578
  async runsByAgent(range) {
@@ -3938,14 +4320,392 @@ var DrizzleChannelStore = class {
3938
4320
  }
3939
4321
  };
3940
4322
 
4323
+ // src/drizzle-poppy-store.ts
4324
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
4325
+ var import_drizzle_orm11 = require("drizzle-orm");
4326
+ var MAX_APPEND_ATTEMPTS = 50;
4327
+ var sleep = /* @__PURE__ */ __name((ms) => new Promise((resolve) => setTimeout(resolve, ms)), "sleep");
4328
+ var nullable = /* @__PURE__ */ __name((value) => value == null ? null : String(value), "nullable");
4329
+ function toInt(value) {
4330
+ if (typeof value === "number") return value;
4331
+ if (typeof value === "bigint") return Number(value);
4332
+ if (typeof value === "string") return Number.parseInt(value, 10) || 0;
4333
+ return 0;
4334
+ }
4335
+ __name(toInt, "toInt");
4336
+ var PATCH_COLUMNS = {
4337
+ accountRef: "accountRef",
4338
+ threadId: "threadId",
4339
+ openDirectId: "openDirectId",
4340
+ status: "status",
4341
+ responder: "responder",
4342
+ context: "context",
4343
+ activeRunId: "activeRunId",
4344
+ turnSeq: "turnSeq",
4345
+ grant: "grantInfo",
4346
+ prunedSeq: "prunedSeq"
4347
+ };
4348
+ var DrizzlePoppyStore = class {
4349
+ static {
4350
+ __name(this, "DrizzlePoppyStore");
4351
+ }
4352
+ db;
4353
+ dialect;
4354
+ t;
4355
+ constructor(db) {
4356
+ this.dialect = agentDialectOf(db);
4357
+ this.t = agentTablesFor(this.dialect);
4358
+ this.db = asBuilder(db);
4359
+ }
4360
+ async createConversation(record) {
4361
+ await this.db.insert(this.t.agentPoppyConversation).values({
4362
+ id: record.id,
4363
+ clientId: record.clientId,
4364
+ userId: record.userId,
4365
+ accountRef: record.accountRef,
4366
+ agentName: record.agentName,
4367
+ threadId: record.threadId,
4368
+ parentId: record.parentId,
4369
+ openDirectId: record.openDirectId,
4370
+ status: record.status,
4371
+ responder: record.responder,
4372
+ context: JSON.stringify(record.context),
4373
+ activeRunId: record.activeRunId,
4374
+ turnSeq: record.turnSeq,
4375
+ grantInfo: record.grant === null ? null : JSON.stringify(record.grant),
4376
+ readerHolder: null,
4377
+ readerUntil: null,
4378
+ prunedSeq: record.prunedSeq,
4379
+ createdAt: record.createdAt,
4380
+ updatedAt: record.updatedAt
4381
+ });
4382
+ }
4383
+ async getConversation(id) {
4384
+ const table = this.t.agentPoppyConversation;
4385
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm11.eq)(table.id, id)).limit(1);
4386
+ if (!row) return null;
4387
+ return {
4388
+ id: row.id,
4389
+ clientId: row.clientId,
4390
+ userId: row.userId,
4391
+ accountRef: nullable(row.accountRef),
4392
+ agentName: row.agentName,
4393
+ threadId: nullable(row.threadId),
4394
+ parentId: nullable(row.parentId),
4395
+ openDirectId: nullable(row.openDirectId),
4396
+ status: row.status,
4397
+ responder: row.responder,
4398
+ context: row.context == null ? {} : JSON.parse(row.context),
4399
+ activeRunId: nullable(row.activeRunId),
4400
+ turnSeq: toInt(row.turnSeq),
4401
+ grant: row.grantInfo == null ? null : JSON.parse(row.grantInfo),
4402
+ prunedSeq: toInt(row.prunedSeq),
4403
+ createdAt: toInt(row.createdAt),
4404
+ updatedAt: toInt(row.updatedAt)
4405
+ };
4406
+ }
4407
+ async updateConversation(id, patch) {
4408
+ const table = this.t.agentPoppyConversation;
4409
+ const set = {
4410
+ updatedAt: Date.now()
4411
+ };
4412
+ for (const [key2, column] of Object.entries(PATCH_COLUMNS)) {
4413
+ const value = patch[key2];
4414
+ if (value === void 0) continue;
4415
+ set[column] = key2 === "context" || key2 === "grant" && value !== null ? JSON.stringify(value) : value;
4416
+ }
4417
+ await this.db.update(table).set(set).where((0, import_drizzle_orm11.eq)(table.id, id));
4418
+ }
4419
+ async appendEvent(conversationId, body, options = {}) {
4420
+ const table = this.t.agentPoppyEvent;
4421
+ for (let attempt = 1; ; attempt++) {
4422
+ if (options.key !== void 0) {
4423
+ const [existing] = await this.db.select({
4424
+ seq: table.seq,
4425
+ event: table.event
4426
+ }).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);
4427
+ if (existing) {
4428
+ return {
4429
+ event: {
4430
+ seq: toInt(existing.seq),
4431
+ event: JSON.parse(existing.event)
4432
+ },
4433
+ created: false
4434
+ };
4435
+ }
4436
+ }
4437
+ const seq = await this.lastSeq(conversationId) + 1;
4438
+ const now = Date.now();
4439
+ const stored = {
4440
+ seq,
4441
+ event: {
4442
+ id: (0, import_nestjs_agent_core8.newEventId)(seq),
4443
+ created_at: new Date(now).toISOString(),
4444
+ ...body
4445
+ }
4446
+ };
4447
+ let inserted = false;
4448
+ try {
4449
+ inserted = await this.insertIgnore(table, {
4450
+ conversationId,
4451
+ seq,
4452
+ id: stored.event.id,
4453
+ type: body.type,
4454
+ event: JSON.stringify(stored.event),
4455
+ eventKey: options.key ?? null,
4456
+ createdAt: now
4457
+ });
4458
+ } catch (error) {
4459
+ if (!isUniqueViolation(error)) throw error;
4460
+ }
4461
+ if (inserted) return {
4462
+ event: stored,
4463
+ created: true
4464
+ };
4465
+ if (attempt >= MAX_APPEND_ATTEMPTS) {
4466
+ throw new Error(`poppy: could not append to ${conversationId} after ${attempt} attempts`);
4467
+ }
4468
+ await sleep(Math.random() * Math.min(attempt, 10) * 2);
4469
+ }
4470
+ }
4471
+ /** The last position taken: the last event's, or — every event pruned — the pruned floor. */
4472
+ async lastSeq(conversationId) {
4473
+ const table = this.t.agentPoppyEvent;
4474
+ const [last] = await this.db.select({
4475
+ seq: table.seq
4476
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.conversationId, conversationId)).orderBy((0, import_drizzle_orm11.desc)(table.seq)).limit(1);
4477
+ if (last) return toInt(last.seq);
4478
+ const conversations = this.t.agentPoppyConversation;
4479
+ const [conversation] = await this.db.select({
4480
+ prunedSeq: conversations.prunedSeq
4481
+ }).from(conversations).where((0, import_drizzle_orm11.eq)(conversations.id, conversationId)).limit(1);
4482
+ return toInt(conversation?.prunedSeq);
4483
+ }
4484
+ async listEvents(conversationId, afterSeq, limit) {
4485
+ const table = this.t.agentPoppyEvent;
4486
+ const rows = await this.db.select({
4487
+ seq: table.seq,
4488
+ event: table.event
4489
+ }).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);
4490
+ return rows.map((row) => ({
4491
+ seq: toInt(row.seq),
4492
+ event: JSON.parse(row.event)
4493
+ }));
4494
+ }
4495
+ async findEventSeq(conversationId, eventId) {
4496
+ const table = this.t.agentPoppyEvent;
4497
+ const [row] = await this.db.select({
4498
+ seq: table.seq
4499
+ }).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);
4500
+ return row ? toInt(row.seq) : null;
4501
+ }
4502
+ async pruneEvents(conversationId, before) {
4503
+ const table = this.t.agentPoppyEvent;
4504
+ const [last] = await this.db.select({
4505
+ seq: table.seq
4506
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.conversationId, conversationId)).orderBy((0, import_drizzle_orm11.desc)(table.seq)).limit(1);
4507
+ if (!last) return;
4508
+ const [dropped] = await this.db.select({
4509
+ seq: table.seq
4510
+ }).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);
4511
+ if (!dropped) return;
4512
+ const upTo = toInt(dropped.seq);
4513
+ const conversations = this.t.agentPoppyConversation;
4514
+ await this.db.update(conversations).set({
4515
+ prunedSeq: upTo
4516
+ }).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(conversations.id, conversationId), (0, import_drizzle_orm11.lt)(conversations.prunedSeq, upTo)));
4517
+ 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)));
4518
+ }
4519
+ async claimMessage(owner, messageId, receipt) {
4520
+ const table = this.t.agentPoppyMessage;
4521
+ for (let attempt = 1; ; attempt++) {
4522
+ const inserted = await this.insertIgnore(table, {
4523
+ owner,
4524
+ messageId,
4525
+ fingerprint: receipt.fingerprint,
4526
+ conversationId: receipt.conversationId,
4527
+ response: JSON.stringify(receipt.response),
4528
+ createdAt: Date.now()
4529
+ });
4530
+ if (inserted) return {
4531
+ status: "claimed"
4532
+ };
4533
+ 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);
4534
+ if (row) {
4535
+ return {
4536
+ status: "existing",
4537
+ fingerprint: row.fingerprint,
4538
+ conversationId: row.conversationId,
4539
+ response: JSON.parse(row.response)
4540
+ };
4541
+ }
4542
+ if (attempt >= 5) throw new Error(`poppy: could not claim message ${messageId}`);
4543
+ }
4544
+ }
4545
+ async releaseMessage(owner, messageId) {
4546
+ const table = this.t.agentPoppyMessage;
4547
+ 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)));
4548
+ }
4549
+ async leaseReader(conversationId, holder, ttlMs) {
4550
+ const table = this.t.agentPoppyConversation;
4551
+ const now = Date.now();
4552
+ const taken = await affectedRows(this.dialect, this.db.update(table).set({
4553
+ readerHolder: holder,
4554
+ readerUntil: now + ttlMs
4555
+ }).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);
4556
+ if (taken === 1) return true;
4557
+ if (this.dialect !== "mysql") return false;
4558
+ const [row] = await this.db.select({
4559
+ holder: table.readerHolder
4560
+ }).from(table).where((0, import_drizzle_orm11.eq)(table.id, conversationId)).limit(1);
4561
+ return row?.holder === holder;
4562
+ }
4563
+ async releaseReader(conversationId, holder) {
4564
+ const table = this.t.agentPoppyConversation;
4565
+ await this.db.update(table).set({
4566
+ readerHolder: null,
4567
+ readerUntil: null
4568
+ }).where((0, import_drizzle_orm11.and)((0, import_drizzle_orm11.eq)(table.id, conversationId), (0, import_drizzle_orm11.eq)(table.readerHolder, holder)));
4569
+ }
4570
+ /** Insert `row`, skipping it on any duplicate key. `true` when it went in. */
4571
+ async insertIgnore(table, row) {
4572
+ if (this.dialect === "mysql") {
4573
+ const insert = this.db.insert(table);
4574
+ return mysqlAffectedRows(await insert.ignore().values(row)) === 1;
4575
+ }
4576
+ const statement = this.db.insert(table).values(row).onConflictDoNothing();
4577
+ return await affectedRows(this.dialect, statement, table.createdAt) === 1;
4578
+ }
4579
+ };
4580
+
4581
+ // src/drizzle-poppy-connection-store.ts
4582
+ var import_drizzle_orm12 = require("drizzle-orm");
4583
+ var nullable2 = /* @__PURE__ */ __name((value) => value == null ? null : String(value), "nullable");
4584
+ var toInt2 = /* @__PURE__ */ __name((value) => typeof value === "number" ? value : Number(value ?? 0), "toInt");
4585
+ var DrizzlePoppyConnectionStore = class {
4586
+ static {
4587
+ __name(this, "DrizzlePoppyConnectionStore");
4588
+ }
4589
+ db;
4590
+ dialect;
4591
+ t;
4592
+ constructor(db) {
4593
+ this.dialect = agentDialectOf(db);
4594
+ this.t = agentTablesFor(this.dialect);
4595
+ this.db = asBuilder(db);
4596
+ }
4597
+ async listConnections(owner) {
4598
+ const table = this.t.agentPoppyConnection;
4599
+ 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));
4600
+ return rows.map(toConnection);
4601
+ }
4602
+ async getConnection(owner, issuer) {
4603
+ const table = this.t.agentPoppyConnection;
4604
+ 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);
4605
+ return row ? toConnection(row) : null;
4606
+ }
4607
+ async saveConnection(record) {
4608
+ const table = this.t.agentPoppyConnection;
4609
+ const columns = {
4610
+ domain: record.domain,
4611
+ organization: record.organization,
4612
+ scope: record.scope,
4613
+ status: record.status,
4614
+ state: record.state,
4615
+ updatedAt: record.updatedAt
4616
+ };
4617
+ await upsert(this.dialect, this.db.insert(table).values({
4618
+ owner: record.owner,
4619
+ issuer: record.issuer,
4620
+ createdAt: record.createdAt,
4621
+ ...columns
4622
+ }), [
4623
+ table.owner,
4624
+ table.issuer
4625
+ ], columns);
4626
+ }
4627
+ async deleteConnection(owner, issuer) {
4628
+ const table = this.t.agentPoppyConnection;
4629
+ 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)));
4630
+ }
4631
+ async createPending(record) {
4632
+ const table = this.t.agentPoppyConnect;
4633
+ const row = {
4634
+ id: record.id,
4635
+ owner: record.owner,
4636
+ domain: record.domain,
4637
+ issuer: record.issuer,
4638
+ organization: record.organization,
4639
+ scope: record.scope,
4640
+ actor: record.actor === null ? null : JSON.stringify(record.actor),
4641
+ threadId: record.threadId,
4642
+ runId: record.runId,
4643
+ toolCallId: record.toolCallId,
4644
+ flow: record.flow,
4645
+ status: record.status,
4646
+ expiresAt: record.expiresAt,
4647
+ createdAt: record.createdAt
4648
+ };
4649
+ if (this.dialect === "mysql") {
4650
+ const insert = this.db.insert(table);
4651
+ await insert.ignore().values(row);
4652
+ return;
4653
+ }
4654
+ await this.db.insert(table).values(row).onConflictDoNothing();
4655
+ }
4656
+ async getPending(id) {
4657
+ const table = this.t.agentPoppyConnect;
4658
+ const [row] = await this.db.select().from(table).where((0, import_drizzle_orm12.eq)(table.id, id)).limit(1);
4659
+ if (!row) return null;
4660
+ return {
4661
+ id: row.id,
4662
+ owner: row.owner,
4663
+ domain: row.domain,
4664
+ issuer: row.issuer,
4665
+ organization: row.organization,
4666
+ scope: row.scope ?? "",
4667
+ actor: row.actor == null ? null : JSON.parse(row.actor),
4668
+ threadId: nullable2(row.threadId),
4669
+ runId: nullable2(row.runId),
4670
+ toolCallId: nullable2(row.toolCallId),
4671
+ flow: nullable2(row.flow),
4672
+ status: row.status,
4673
+ expiresAt: toInt2(row.expiresAt),
4674
+ createdAt: toInt2(row.createdAt)
4675
+ };
4676
+ }
4677
+ async updatePending(id, patch) {
4678
+ const set = {};
4679
+ if (patch.flow !== void 0) set.flow = patch.flow;
4680
+ if (patch.status !== void 0) set.status = patch.status;
4681
+ if (Object.keys(set).length === 0) return;
4682
+ const table = this.t.agentPoppyConnect;
4683
+ await this.db.update(table).set(set).where((0, import_drizzle_orm12.eq)(table.id, id));
4684
+ }
4685
+ };
4686
+ function toConnection(row) {
4687
+ return {
4688
+ owner: row.owner,
4689
+ issuer: row.issuer,
4690
+ domain: row.domain,
4691
+ organization: row.organization,
4692
+ scope: row.scope ?? "",
4693
+ status: row.status,
4694
+ state: row.state,
4695
+ createdAt: toInt2(row.createdAt),
4696
+ updatedAt: toInt2(row.updatedAt)
4697
+ };
4698
+ }
4699
+ __name(toConnection, "toConnection");
4700
+
3941
4701
  // src/drizzle-rag-ingestion-log.ts
3942
4702
  var import_node_diagnostics_channel = require("diagnostics_channel");
3943
4703
  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;
4704
+ var import_drizzle_orm13 = require("drizzle-orm");
4705
+ function _ts_decorate(decorators, target, key2, desc5) {
4706
+ var c = arguments.length, r = c < 3 ? target : desc5 === null ? desc5 = Object.getOwnPropertyDescriptor(target, key2) : desc5, d;
3947
4707
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3948
- r = Reflect.decorate(decorators, target, key2, desc4);
4708
+ r = Reflect.decorate(decorators, target, key2, desc5);
3949
4709
  } else {
3950
4710
  for (var i = decorators.length - 1; i >= 0; i--) {
3951
4711
  if (d = decorators[i]) {
@@ -3989,8 +4749,8 @@ function num(value) {
3989
4749
  }
3990
4750
  __name(num, "num");
3991
4751
  var RAG_INGESTION_LOG_PAGE_ORDER = [
3992
- (0, import_drizzle_orm11.desc)(ragIngestionLog.updatedAt),
3993
- (0, import_drizzle_orm11.asc)(ragIngestionLog.documentId)
4752
+ (0, import_drizzle_orm13.desc)(ragIngestionLog.updatedAt),
4753
+ (0, import_drizzle_orm13.asc)(ragIngestionLog.documentId)
3994
4754
  ];
3995
4755
  var DEFAULT_PAGE_SIZE = 200;
3996
4756
  var DEFAULT_BATCH_SIZE = 200;
@@ -4061,7 +4821,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4061
4821
  */
4062
4822
  async listPage(query = {}) {
4063
4823
  const [totalRow] = await this.db.select({
4064
- value: (0, import_drizzle_orm11.count)()
4824
+ value: (0, import_drizzle_orm13.count)()
4065
4825
  }).from(this.t.ragIngestionLog).where(this.where(query));
4066
4826
  return {
4067
4827
  rows: await this.list(query),
@@ -4140,17 +4900,17 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4140
4900
  }
4141
4901
  /** The latest recorded outcome for one document, or null if it was never attempted. */
4142
4902
  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));
4903
+ const [row] = await this.db.select().from(this.t.ragIngestionLog).where((0, import_drizzle_orm13.eq)(this.t.ragIngestionLog.documentId, documentId));
4144
4904
  return row ?? null;
4145
4905
  }
4146
4906
  /** Forget one document's record. Returns whether a row was actually removed. */
4147
4907
  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);
4908
+ 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
4909
  return removed > 0;
4150
4910
  }
4151
4911
  /** Forget every record for a collection — for when the collection itself is deleted. */
4152
4912
  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);
4913
+ 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
4914
  return removed;
4155
4915
  }
4156
4916
  /**
@@ -4180,7 +4940,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4180
4940
  }
4181
4941
  }
4182
4942
  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);
4943
+ 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
4944
  }
4185
4945
  /**
4186
4946
  * The coordinates filter AND'd with "strictly after `cursor` in
@@ -4195,7 +4955,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
4195
4955
  if (cursor === void 0) {
4196
4956
  return base;
4197
4957
  }
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))));
4958
+ 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
4959
  }
4200
4960
  /**
4201
4961
  * Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
@@ -4268,12 +5028,12 @@ DrizzleRagIngestionLog = _ts_decorate([
4268
5028
  ], DrizzleRagIngestionLog);
4269
5029
 
4270
5030
  // src/drizzle-agent-store.module.ts
4271
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
5031
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
4272
5032
  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;
5033
+ function _ts_decorate2(decorators, target, key2, desc5) {
5034
+ var c = arguments.length, r = c < 3 ? target : desc5 === null ? desc5 = Object.getOwnPropertyDescriptor(target, key2) : desc5, d;
4275
5035
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4276
- r = Reflect.decorate(decorators, target, key2, desc4);
5036
+ r = Reflect.decorate(decorators, target, key2, desc5);
4277
5037
  } else {
4278
5038
  for (var i = decorators.length - 1; i >= 0; i--) {
4279
5039
  if (d = decorators[i]) {
@@ -4305,7 +5065,7 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4305
5065
  useFactory: /* @__PURE__ */ __name(() => new DrizzleAgentStore(options.db), "useFactory")
4306
5066
  },
4307
5067
  {
4308
- provide: import_nestjs_agent_core8.AGENT_STORE,
5068
+ provide: import_nestjs_agent_core9.AGENT_STORE,
4309
5069
  useExisting: DrizzleAgentStore
4310
5070
  },
4311
5071
  // Exported, never bound to AGENT_MEMORY: that token's PRESENCE is what turns memory on, so
@@ -4322,21 +5082,21 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4322
5082
  // AGENT_PRICING_STORE: the host's own store when supplied, else the default Drizzle one.
4323
5083
  // DrizzleGovernanceQueries prices usage against whatever is bound here.
4324
5084
  options.pricingStore ? {
4325
- provide: import_nestjs_agent_core8.AGENT_PRICING_STORE,
5085
+ provide: import_nestjs_agent_core9.AGENT_PRICING_STORE,
4326
5086
  useClass: options.pricingStore
4327
5087
  } : {
4328
- provide: import_nestjs_agent_core8.AGENT_PRICING_STORE,
5088
+ provide: import_nestjs_agent_core9.AGENT_PRICING_STORE,
4329
5089
  useExisting: DrizzlePricingStore
4330
5090
  },
4331
5091
  {
4332
5092
  provide: DrizzleGovernanceQueries,
4333
5093
  useFactory: /* @__PURE__ */ __name((pricingStore) => new DrizzleGovernanceQueries(options.db, pricingStore), "useFactory"),
4334
5094
  inject: [
4335
- import_nestjs_agent_core8.AGENT_PRICING_STORE
5095
+ import_nestjs_agent_core9.AGENT_PRICING_STORE
4336
5096
  ]
4337
5097
  },
4338
5098
  {
4339
- provide: import_nestjs_agent_core8.AGENT_GOVERNANCE_QUERIES,
5099
+ provide: import_nestjs_agent_core9.AGENT_GOVERNANCE_QUERIES,
4340
5100
  useExisting: DrizzleGovernanceQueries
4341
5101
  },
4342
5102
  // What makes a `defineConfirmedTool` confirmation single use across replicas.
@@ -4345,7 +5105,7 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4345
5105
  useFactory: /* @__PURE__ */ __name(() => new DrizzleConfirmTokenStore(options.db), "useFactory")
4346
5106
  },
4347
5107
  {
4348
- provide: import_nestjs_agent_core8.AGENT_CONFIRM_TOKEN_STORE,
5108
+ provide: import_nestjs_agent_core9.AGENT_CONFIRM_TOKEN_STORE,
4349
5109
  useExisting: DrizzleConfirmTokenStore
4350
5110
  },
4351
5111
  // Text channels' state (`@dudousxd/nestjs-agent-channels`), shared by every replica.
@@ -4354,8 +5114,25 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4354
5114
  useFactory: /* @__PURE__ */ __name(() => new DrizzleChannelStore(options.db), "useFactory")
4355
5115
  },
4356
5116
  {
4357
- provide: import_nestjs_agent_core8.AGENT_CHANNEL_STORE,
5117
+ provide: import_nestjs_agent_core9.AGENT_CHANNEL_STORE,
4358
5118
  useExisting: DrizzleChannelStore
5119
+ },
5120
+ // Personal Agent Protocol (Poppy) conversations and connections, shared by every replica.
5121
+ {
5122
+ provide: DrizzlePoppyStore,
5123
+ useFactory: /* @__PURE__ */ __name(() => new DrizzlePoppyStore(options.db), "useFactory")
5124
+ },
5125
+ {
5126
+ provide: import_nestjs_agent_core9.AGENT_POPPY_STORE,
5127
+ useExisting: DrizzlePoppyStore
5128
+ },
5129
+ {
5130
+ provide: DrizzlePoppyConnectionStore,
5131
+ useFactory: /* @__PURE__ */ __name(() => new DrizzlePoppyConnectionStore(options.db), "useFactory")
5132
+ },
5133
+ {
5134
+ provide: import_nestjs_agent_core9.AGENT_POPPY_CONNECTION_STORE,
5135
+ useExisting: DrizzlePoppyConnectionStore
4359
5136
  }
4360
5137
  ],
4361
5138
  exports: [
@@ -4363,16 +5140,20 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
4363
5140
  DrizzleRagIngestionLog
4364
5141
  ],
4365
5142
  DrizzleAgentStore,
4366
- import_nestjs_agent_core8.AGENT_STORE,
5143
+ import_nestjs_agent_core9.AGENT_STORE,
4367
5144
  DrizzleMemoryProvider,
4368
5145
  DrizzleGovernanceQueries,
4369
- import_nestjs_agent_core8.AGENT_GOVERNANCE_QUERIES,
5146
+ import_nestjs_agent_core9.AGENT_GOVERNANCE_QUERIES,
4370
5147
  DrizzlePricingStore,
4371
- import_nestjs_agent_core8.AGENT_PRICING_STORE,
5148
+ import_nestjs_agent_core9.AGENT_PRICING_STORE,
4372
5149
  DrizzleConfirmTokenStore,
4373
- import_nestjs_agent_core8.AGENT_CONFIRM_TOKEN_STORE,
5150
+ import_nestjs_agent_core9.AGENT_CONFIRM_TOKEN_STORE,
4374
5151
  DrizzleChannelStore,
4375
- import_nestjs_agent_core8.AGENT_CHANNEL_STORE
5152
+ import_nestjs_agent_core9.AGENT_CHANNEL_STORE,
5153
+ DrizzlePoppyStore,
5154
+ import_nestjs_agent_core9.AGENT_POPPY_STORE,
5155
+ DrizzlePoppyConnectionStore,
5156
+ import_nestjs_agent_core9.AGENT_POPPY_CONNECTION_STORE
4376
5157
  ]
4377
5158
  };
4378
5159
  }
@@ -4389,6 +5170,8 @@ DrizzleAgentStoreModule = _ts_decorate2([
4389
5170
  DrizzleConfirmTokenStore,
4390
5171
  DrizzleGovernanceQueries,
4391
5172
  DrizzleMemoryProvider,
5173
+ DrizzlePoppyConnectionStore,
5174
+ DrizzlePoppyStore,
4392
5175
  DrizzlePricingStore,
4393
5176
  DrizzleRagIngestionLog,
4394
5177
  DrizzleStreamFrameTable,
@@ -4402,6 +5185,11 @@ DrizzleAgentStoreModule = _ts_decorate2([
4402
5185
  agentMemory,
4403
5186
  agentMessage,
4404
5187
  agentModelPricing,
5188
+ agentPoppyConnect,
5189
+ agentPoppyConnection,
5190
+ agentPoppyConversation,
5191
+ agentPoppyEvent,
5192
+ agentPoppyMessage,
4405
5193
  agentQueuedMessage,
4406
5194
  agentRun,
4407
5195
  agentSchema,