@dudousxd/nestjs-agent-store-drizzle 0.27.0 → 0.28.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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
2
- import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, AgentHostContext, Actor, PageContext, QueuePause, ActionProposal, ToolKind, ToolCallStatus, ToolConfirmation, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, ActionProposalStore, ActionProposalWorkerStore, ActionProposalDiscoveryIndexStore, ActionProposalOutcomeStore, ActionProposalStoreOptions, ActionProposalSupersessionStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, CreateActionProposal, CreateActionProposalResult, ActionProposalScope, ActionProposalMutationResult, ListActionProposals, ActionProposalDecisionCommand, ClaimActionProposal, ExtendActionProposalLease, SettleActionProposal, ActionProposalOutcomeLease, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, StreamFrameTable, StreamFrameRow, SqlTokenStreamSink, SqlTokenStreamSinkOptions, ConfirmTokenStore, ConfirmTokenClaim } from '@dudousxd/nestjs-agent-core';
2
+ import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, MessageFeedback, AgentHostContext, Actor, PageContext, QueuePause, ActionProposal, ToolKind, ToolCallStatus, ToolConfirmation, UsagePurpose, AgentStore, ThreadTurnReader, ChatQueueStore, ActionProposalStore, ActionProposalWorkerStore, ActionProposalDiscoveryIndexStore, ActionProposalOutcomeStore, ActionProposalStoreOptions, ActionProposalSupersessionStore, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, EnqueueMessageInput, QueuedMessage, QueuedMessagePatch, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, ToolCallOutcome, RecordUsageInput, CreateActionProposal, CreateActionProposalResult, ActionProposalScope, ActionProposalMutationResult, ListActionProposals, ActionProposalDecisionCommand, ClaimActionProposal, ExtendActionProposalLease, SettleActionProposal, ActionProposalOutcomeLease, AgentGovernanceQueries, AgentPricingStore, GovernanceRange, ModelSpendRow, ActorSpendRow, ThreadSpendRow, UsageTrendPoint, ToolCallActivityRow, ThreadActivityRow, RunMetrics, RunAgentBreakdownRow, RunErrorBreakdownRow, RunTrendPoint, RecentRunRow, PendingApprovalRow, ToolStatRow, GovernancePageQuery, ToolCallWhere, GovernancePage, ThreadWhere, RunWhere, ApprovalWhere, GovernanceRunDetail, GovernanceThreadDetailQuery, GovernanceThreadDetail, MemoryProvider, ListMemoriesInput, MemoryRecord, ForgetMemoryInput, StoreMemoryInput, ModelPriceInput, CurrentModelPrice, StreamFrameTable, StreamFrameRow, SqlTokenStreamSink, SqlTokenStreamSinkOptions, ConfirmTokenStore, ConfirmTokenClaim, ChannelStore } from '@dudousxd/nestjs-agent-core';
3
3
  export { ThreadTurnPage, ThreadTurnQuery } from '@dudousxd/nestjs-agent-core';
4
4
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
5
5
  import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
@@ -2436,6 +2436,92 @@ declare const ragIngestionLog: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
2436
2436
  };
2437
2437
  dialect: "sqlite";
2438
2438
  }>;
2439
+ /**
2440
+ * Text channels' short-lived state (`@dudousxd/nestjs-agent-channels`), one row per key: the provider
2441
+ * message ids already answered, a question waiting for the person's answer, an outcome already
2442
+ * relayed. The primary key is the lock a claim takes; `expires_at` is epoch-ms, and past it the row
2443
+ * is free again and dead weight for `DrizzleChannelStore.purgeExpired`. Keys longer than 255
2444
+ * characters are stored by their SHA-256.
2445
+ */
2446
+ declare const agentChannelState: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
2447
+ name: "agent_channel_state";
2448
+ schema: undefined;
2449
+ columns: {
2450
+ key: drizzle_orm_sqlite_core.SQLiteColumn<{
2451
+ name: "key";
2452
+ tableName: "agent_channel_state";
2453
+ dataType: "string";
2454
+ columnType: "SQLiteText";
2455
+ data: string;
2456
+ driverParam: string;
2457
+ notNull: true;
2458
+ hasDefault: false;
2459
+ isPrimaryKey: true;
2460
+ isAutoincrement: false;
2461
+ hasRuntimeDefault: false;
2462
+ enumValues: [string, ...string[]];
2463
+ baseColumn: never;
2464
+ identity: undefined;
2465
+ generated: undefined;
2466
+ }, {}, {
2467
+ length: number | undefined;
2468
+ }>;
2469
+ value: drizzle_orm_sqlite_core.SQLiteColumn<{
2470
+ name: "value";
2471
+ tableName: "agent_channel_state";
2472
+ dataType: "string";
2473
+ columnType: "SQLiteText";
2474
+ data: string;
2475
+ driverParam: string;
2476
+ notNull: false;
2477
+ hasDefault: false;
2478
+ isPrimaryKey: false;
2479
+ isAutoincrement: false;
2480
+ hasRuntimeDefault: false;
2481
+ enumValues: [string, ...string[]];
2482
+ baseColumn: never;
2483
+ identity: undefined;
2484
+ generated: undefined;
2485
+ }, {}, {
2486
+ length: number | undefined;
2487
+ }>;
2488
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2489
+ name: "expires_at";
2490
+ tableName: "agent_channel_state";
2491
+ dataType: "number";
2492
+ columnType: "SQLiteInteger";
2493
+ data: number;
2494
+ driverParam: number;
2495
+ notNull: true;
2496
+ hasDefault: false;
2497
+ isPrimaryKey: false;
2498
+ isAutoincrement: false;
2499
+ hasRuntimeDefault: false;
2500
+ enumValues: undefined;
2501
+ baseColumn: never;
2502
+ identity: undefined;
2503
+ generated: undefined;
2504
+ }, {}, {}>;
2505
+ createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2506
+ name: "created_at";
2507
+ tableName: "agent_channel_state";
2508
+ dataType: "number";
2509
+ columnType: "SQLiteInteger";
2510
+ data: number;
2511
+ driverParam: number;
2512
+ notNull: true;
2513
+ hasDefault: false;
2514
+ isPrimaryKey: false;
2515
+ isAutoincrement: false;
2516
+ hasRuntimeDefault: false;
2517
+ enumValues: undefined;
2518
+ baseColumn: never;
2519
+ identity: undefined;
2520
+ generated: undefined;
2521
+ }, {}, {}>;
2522
+ };
2523
+ dialect: "sqlite";
2524
+ }>;
2439
2525
  /**
2440
2526
  * Spent confirm tokens (`defineConfirmedTool`), one row per token, keyed by its SHA-256 — the
2441
2527
  * primary key is the lock that makes a confirmation single use across replicas. Only the hash, the
@@ -5671,6 +5757,85 @@ declare const agentSchema: {
5671
5757
  };
5672
5758
  dialect: "sqlite";
5673
5759
  }>;
5760
+ agentChannelState: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
5761
+ name: "agent_channel_state";
5762
+ schema: undefined;
5763
+ columns: {
5764
+ key: drizzle_orm_sqlite_core.SQLiteColumn<{
5765
+ name: "key";
5766
+ tableName: "agent_channel_state";
5767
+ dataType: "string";
5768
+ columnType: "SQLiteText";
5769
+ data: string;
5770
+ driverParam: string;
5771
+ notNull: true;
5772
+ hasDefault: false;
5773
+ isPrimaryKey: true;
5774
+ isAutoincrement: false;
5775
+ hasRuntimeDefault: false;
5776
+ enumValues: [string, ...string[]];
5777
+ baseColumn: never;
5778
+ identity: undefined;
5779
+ generated: undefined;
5780
+ }, {}, {
5781
+ length: number | undefined;
5782
+ }>;
5783
+ value: drizzle_orm_sqlite_core.SQLiteColumn<{
5784
+ name: "value";
5785
+ tableName: "agent_channel_state";
5786
+ dataType: "string";
5787
+ columnType: "SQLiteText";
5788
+ data: string;
5789
+ driverParam: string;
5790
+ notNull: false;
5791
+ hasDefault: false;
5792
+ isPrimaryKey: false;
5793
+ isAutoincrement: false;
5794
+ hasRuntimeDefault: false;
5795
+ enumValues: [string, ...string[]];
5796
+ baseColumn: never;
5797
+ identity: undefined;
5798
+ generated: undefined;
5799
+ }, {}, {
5800
+ length: number | undefined;
5801
+ }>;
5802
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
5803
+ name: "expires_at";
5804
+ tableName: "agent_channel_state";
5805
+ dataType: "number";
5806
+ columnType: "SQLiteInteger";
5807
+ data: number;
5808
+ driverParam: number;
5809
+ notNull: true;
5810
+ hasDefault: false;
5811
+ isPrimaryKey: false;
5812
+ isAutoincrement: false;
5813
+ hasRuntimeDefault: false;
5814
+ enumValues: undefined;
5815
+ baseColumn: never;
5816
+ identity: undefined;
5817
+ generated: undefined;
5818
+ }, {}, {}>;
5819
+ createdAt: drizzle_orm_sqlite_core.SQLiteColumn<{
5820
+ name: "created_at";
5821
+ tableName: "agent_channel_state";
5822
+ dataType: "number";
5823
+ columnType: "SQLiteInteger";
5824
+ data: number;
5825
+ driverParam: number;
5826
+ notNull: true;
5827
+ hasDefault: false;
5828
+ isPrimaryKey: false;
5829
+ isAutoincrement: false;
5830
+ hasRuntimeDefault: false;
5831
+ enumValues: undefined;
5832
+ baseColumn: never;
5833
+ identity: undefined;
5834
+ generated: undefined;
5835
+ }, {}, {}>;
5836
+ };
5837
+ dialect: "sqlite";
5838
+ }>;
5674
5839
  agentStreamFrame: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
5675
5840
  name: "agent_stream_frame";
5676
5841
  schema: undefined;
@@ -6291,6 +6456,34 @@ declare class DrizzleConfirmTokenStore implements ConfirmTokenStore {
6291
6456
  purgeExpired(now?: number): Promise<number>;
6292
6457
  }
6293
6458
 
6459
+ interface DrizzleChannelStoreOptions {
6460
+ /** How often a claim also deletes expired rows. Default 10 minutes; `0` → never (purge yourself). */
6461
+ purgeEveryMs?: number;
6462
+ }
6463
+ /**
6464
+ * A `ChannelStore` (text channels, `@dudousxd/nestjs-agent-channels`) over the `agent_channel_state`
6465
+ * table — shared by every replica, no Redis needed.
6466
+ *
6467
+ * A claim deletes the key's row when it expired, then inserts it skipping a duplicate key —
6468
+ * `ON CONFLICT DO NOTHING` on SQLite and Postgres, `INSERT IGNORE` on MySQL — so the primary key is
6469
+ * the lock: of two concurrent claims one inserts and the other touches no row. Expired rows are
6470
+ * deleted as claims arrive (`purgeEveryMs`), or by {@link purgeExpired} from a job. The table comes
6471
+ * from `ensureAgentSchema` (or your own migration).
6472
+ */
6473
+ declare class DrizzleChannelStore implements ChannelStore {
6474
+ private readonly db;
6475
+ private readonly dialect;
6476
+ private readonly t;
6477
+ private readonly purgeEveryMs;
6478
+ private lastPurge;
6479
+ constructor(db: AgentDrizzleDb, options?: DrizzleChannelStoreOptions);
6480
+ claim(key: string, ttlMs: number): Promise<boolean>;
6481
+ get(key: string): Promise<string | null>;
6482
+ set(key: string, value: string, ttlMs: number): Promise<void>;
6483
+ delete(key: string): Promise<void>;
6484
+ purgeExpired(now?: number): Promise<number>;
6485
+ }
6486
+
6294
6487
  /**
6295
6488
  * The paging order: newest first, tiebroken on the primary key.
6296
6489
  *
@@ -6508,7 +6701,8 @@ interface DrizzleAgentStoreModuleOptions {
6508
6701
  * `@dudousxd/nestjs-agent`, plus {@link DrizzleGovernanceQueries} to
6509
6702
  * {@link AGENT_GOVERNANCE_QUERIES} (the read-model the dashboard/telescope surfaces consume) and
6510
6703
  * {@link DrizzlePricingStore} to {@link AGENT_PRICING_STORE} (the write side of that pricing table),
6511
- * and {@link DrizzleConfirmTokenStore} to {@link AGENT_CONFIRM_TOKEN_STORE} (confirmed writes).
6704
+ * {@link DrizzleConfirmTokenStore} to {@link AGENT_CONFIRM_TOKEN_STORE} (confirmed writes), and
6705
+ * {@link DrizzleChannelStore} to {@link AGENT_CHANNEL_STORE} (text channels' state).
6512
6706
  * The host app supplies an already-opened Drizzle db — this module never opens a connection itself.
6513
6707
  *
6514
6708
  * The returned module is global, so {@link AGENT_STORE}, {@link AGENT_GOVERNANCE_QUERIES} and
@@ -9100,6 +9294,81 @@ declare const pgAgentSchema: {
9100
9294
  };
9101
9295
  dialect: "pg";
9102
9296
  }>;
9297
+ agentChannelState: drizzle_orm_pg_core.PgTableWithColumns<{
9298
+ name: "agent_channel_state";
9299
+ schema: undefined;
9300
+ columns: {
9301
+ key: drizzle_orm_pg_core.PgColumn<{
9302
+ name: "key";
9303
+ tableName: "agent_channel_state";
9304
+ dataType: "string";
9305
+ columnType: "PgText";
9306
+ data: string;
9307
+ driverParam: string;
9308
+ notNull: true;
9309
+ hasDefault: false;
9310
+ isPrimaryKey: true;
9311
+ isAutoincrement: false;
9312
+ hasRuntimeDefault: false;
9313
+ enumValues: [string, ...string[]];
9314
+ baseColumn: never;
9315
+ identity: undefined;
9316
+ generated: undefined;
9317
+ }, {}, {}>;
9318
+ value: drizzle_orm_pg_core.PgColumn<{
9319
+ name: "value";
9320
+ tableName: "agent_channel_state";
9321
+ dataType: "string";
9322
+ columnType: "PgText";
9323
+ data: string;
9324
+ driverParam: string;
9325
+ notNull: false;
9326
+ hasDefault: false;
9327
+ isPrimaryKey: false;
9328
+ isAutoincrement: false;
9329
+ hasRuntimeDefault: false;
9330
+ enumValues: [string, ...string[]];
9331
+ baseColumn: never;
9332
+ identity: undefined;
9333
+ generated: undefined;
9334
+ }, {}, {}>;
9335
+ expiresAt: drizzle_orm_pg_core.PgColumn<{
9336
+ name: "expires_at";
9337
+ tableName: "agent_channel_state";
9338
+ dataType: "number";
9339
+ columnType: "PgBigInt53";
9340
+ data: number;
9341
+ driverParam: string | number;
9342
+ notNull: true;
9343
+ hasDefault: false;
9344
+ isPrimaryKey: false;
9345
+ isAutoincrement: false;
9346
+ hasRuntimeDefault: false;
9347
+ enumValues: undefined;
9348
+ baseColumn: never;
9349
+ identity: undefined;
9350
+ generated: undefined;
9351
+ }, {}, {}>;
9352
+ createdAt: drizzle_orm_pg_core.PgColumn<{
9353
+ name: "created_at";
9354
+ tableName: "agent_channel_state";
9355
+ dataType: "number";
9356
+ columnType: "PgBigInt53";
9357
+ data: number;
9358
+ driverParam: string | number;
9359
+ notNull: true;
9360
+ hasDefault: false;
9361
+ isPrimaryKey: false;
9362
+ isAutoincrement: false;
9363
+ hasRuntimeDefault: false;
9364
+ enumValues: undefined;
9365
+ baseColumn: never;
9366
+ identity: undefined;
9367
+ generated: undefined;
9368
+ }, {}, {}>;
9369
+ };
9370
+ dialect: "pg";
9371
+ }>;
9103
9372
  agentStreamFrame: drizzle_orm_pg_core.PgTableWithColumns<{
9104
9373
  name: "agent_stream_frame";
9105
9374
  schema: undefined;
@@ -11767,6 +12036,81 @@ declare const mysqlAgentSchema: {
11767
12036
  };
11768
12037
  dialect: "mysql";
11769
12038
  }>;
12039
+ agentChannelState: drizzle_orm_mysql_core.MySqlTableWithColumns<{
12040
+ name: "agent_channel_state";
12041
+ schema: undefined;
12042
+ columns: {
12043
+ key: drizzle_orm_mysql_core.MySqlColumn<{
12044
+ name: string;
12045
+ tableName: "agent_channel_state";
12046
+ dataType: "string";
12047
+ columnType: "MySqlVarChar";
12048
+ data: string;
12049
+ driverParam: string | number;
12050
+ notNull: true;
12051
+ hasDefault: false;
12052
+ isPrimaryKey: true;
12053
+ isAutoincrement: false;
12054
+ hasRuntimeDefault: false;
12055
+ enumValues: [string, ...string[]];
12056
+ baseColumn: never;
12057
+ identity: undefined;
12058
+ generated: undefined;
12059
+ }, {}, {}>;
12060
+ value: drizzle_orm_mysql_core.MySqlColumn<{
12061
+ name: "value";
12062
+ tableName: "agent_channel_state";
12063
+ dataType: "string";
12064
+ columnType: "MySqlText";
12065
+ data: string;
12066
+ driverParam: string;
12067
+ notNull: false;
12068
+ hasDefault: false;
12069
+ isPrimaryKey: false;
12070
+ isAutoincrement: false;
12071
+ hasRuntimeDefault: false;
12072
+ enumValues: [string, ...string[]];
12073
+ baseColumn: never;
12074
+ identity: undefined;
12075
+ generated: undefined;
12076
+ }, {}, {}>;
12077
+ expiresAt: drizzle_orm_mysql_core.MySqlColumn<{
12078
+ name: "expires_at";
12079
+ tableName: "agent_channel_state";
12080
+ dataType: "number";
12081
+ columnType: "MySqlBigInt53";
12082
+ data: number;
12083
+ driverParam: string | number;
12084
+ notNull: true;
12085
+ hasDefault: false;
12086
+ isPrimaryKey: false;
12087
+ isAutoincrement: false;
12088
+ hasRuntimeDefault: false;
12089
+ enumValues: undefined;
12090
+ baseColumn: never;
12091
+ identity: undefined;
12092
+ generated: undefined;
12093
+ }, {}, {}>;
12094
+ createdAt: drizzle_orm_mysql_core.MySqlColumn<{
12095
+ name: "created_at";
12096
+ tableName: "agent_channel_state";
12097
+ dataType: "number";
12098
+ columnType: "MySqlBigInt53";
12099
+ data: number;
12100
+ driverParam: string | number;
12101
+ notNull: true;
12102
+ hasDefault: false;
12103
+ isPrimaryKey: false;
12104
+ isAutoincrement: false;
12105
+ hasRuntimeDefault: false;
12106
+ enumValues: undefined;
12107
+ baseColumn: never;
12108
+ identity: undefined;
12109
+ generated: undefined;
12110
+ }, {}, {}>;
12111
+ };
12112
+ dialect: "mysql";
12113
+ }>;
11770
12114
  agentStreamFrame: drizzle_orm_mysql_core.MySqlTableWithColumns<{
11771
12115
  name: "agent_stream_frame";
11772
12116
  schema: undefined;
@@ -11861,4 +12205,4 @@ declare const mysqlAgentSchema: {
11861
12205
  }>;
11862
12206
  };
11863
12207
 
11864
- export { type AgentDialect, type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentMySqlDb, type AgentPgDb, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentSqliteDb, type AgentThreadRow, DrizzleActionProposalStore, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, DrizzleStreamFrameTable, DrizzleTokenStreamSink, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentActionProposal, agentConfirmToken, agentDialectOf, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentSchemaDdl, agentStreamFrame, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, mysqlAgentSchema, pgAgentSchema, ragIngestionLog };
12208
+ export { type AgentDialect, type AgentDrizzleDb, type AgentMemoryRow, type AgentMessageRow, type AgentMySqlDb, type AgentPgDb, type AgentQueuedMessageRow, type AgentRunRow, type AgentRunStatus, type AgentSqliteDb, type AgentThreadRow, DrizzleActionProposalStore, DrizzleAgentStore, DrizzleAgentStoreModule, type DrizzleAgentStoreModuleOptions, DrizzleChannelStore, type DrizzleChannelStoreOptions, DrizzleConfirmTokenStore, DrizzleGovernanceQueries, DrizzleMemoryProvider, DrizzlePricingStore, DrizzleRagIngestionLog, DrizzleStreamFrameTable, DrizzleTokenStreamSink, RAG_INGESTION_LOG_PAGE_ORDER, type RagIngestionLogCursor, type RagIngestionLogIterateOptions, type RagIngestionLogQuery, type RagIngestionLogRow, type RagIngestionLogWhere, type RagIngestionStatus, agentActionProposal, agentChannelState, agentConfirmToken, agentDialectOf, agentMemory, agentMessage, agentModelPricing, agentQueuedMessage, agentRun, agentSchema, agentSchemaDdl, agentStreamFrame, agentThread, agentTokenUsage, agentToolCall, ensureAgentSchema, mysqlAgentSchema, pgAgentSchema, ragIngestionLog };
package/dist/index.js CHANGED
@@ -290,6 +290,14 @@ var ragIngestionLog = sqliteTable("rag_ingestion_log", {
290
290
  }, (table) => [
291
291
  index("rag_ingestion_log_collection_idx").on(table.collection, table.updatedAt)
292
292
  ]);
293
+ var agentChannelState = sqliteTable("agent_channel_state", {
294
+ key: text("key").primaryKey(),
295
+ value: text("value"),
296
+ expiresAt: integer("expires_at").notNull(),
297
+ createdAt: integer("created_at").notNull()
298
+ }, (table) => [
299
+ index("agent_channel_state_expires_idx").on(table.expiresAt)
300
+ ]);
293
301
  var agentConfirmToken = sqliteTable("agent_confirm_token", {
294
302
  hash: text("hash").primaryKey(),
295
303
  actorRef: text("actor_ref").notNull(),
@@ -352,6 +360,7 @@ var agentSchema = {
352
360
  agentMemory,
353
361
  ragIngestionLog,
354
362
  agentConfirmToken,
363
+ agentChannelState,
355
364
  agentStreamFrame
356
365
  };
357
366
 
@@ -548,6 +557,18 @@ var ragIngestionLog2 = mysqlTable("rag_ingestion_log", {
548
557
  }, (table) => [
549
558
  index2("rag_ingestion_log_collection_idx").on(table.collection, table.updatedAt)
550
559
  ]);
560
+ var agentChannelState2 = mysqlTable("agent_channel_state", {
561
+ key: key("key").primaryKey(),
562
+ value: longtext("value"),
563
+ expiresAt: bigint("expires_at", {
564
+ mode: "number"
565
+ }).notNull(),
566
+ createdAt: bigint("created_at", {
567
+ mode: "number"
568
+ }).notNull()
569
+ }, (table) => [
570
+ index2("agent_channel_state_expires_idx").on(table.expiresAt)
571
+ ]);
551
572
  var agentConfirmToken2 = mysqlTable("agent_confirm_token", {
552
573
  hash: key("hash").primaryKey(),
553
574
  actorRef: key("actor_ref").notNull(),
@@ -633,6 +654,7 @@ var mysqlAgentSchema = {
633
654
  agentMemory: agentMemory2,
634
655
  ragIngestionLog: ragIngestionLog2,
635
656
  agentConfirmToken: agentConfirmToken2,
657
+ agentChannelState: agentChannelState2,
636
658
  agentStreamFrame: agentStreamFrame2
637
659
  };
638
660
 
@@ -816,6 +838,18 @@ var ragIngestionLog3 = pgTable("rag_ingestion_log", {
816
838
  }, (table) => [
817
839
  index3("rag_ingestion_log_collection_idx").on(table.collection, table.updatedAt)
818
840
  ]);
841
+ var agentChannelState3 = pgTable("agent_channel_state", {
842
+ key: text2("key").primaryKey(),
843
+ value: text2("value"),
844
+ expiresAt: bigint2("expires_at", {
845
+ mode: "number"
846
+ }).notNull(),
847
+ createdAt: bigint2("created_at", {
848
+ mode: "number"
849
+ }).notNull()
850
+ }, (table) => [
851
+ index3("agent_channel_state_expires_idx").on(table.expiresAt)
852
+ ]);
819
853
  var agentConfirmToken3 = pgTable("agent_confirm_token", {
820
854
  hash: text2("hash").primaryKey(),
821
855
  actorRef: text2("actor_ref").notNull(),
@@ -899,6 +933,7 @@ var pgAgentSchema = {
899
933
  agentMemory: agentMemory3,
900
934
  ragIngestionLog: ragIngestionLog3,
901
935
  agentConfirmToken: agentConfirmToken3,
936
+ agentChannelState: agentChannelState3,
902
937
  agentStreamFrame: agentStreamFrame3
903
938
  };
904
939
 
@@ -3531,10 +3566,82 @@ var DrizzleConfirmTokenStore = class {
3531
3566
  }
3532
3567
  };
3533
3568
 
3569
+ // src/drizzle-channel-store.ts
3570
+ import { createHash as createHash2 } from "crypto";
3571
+ import { and as and7, eq as eq8, gt as gt3, lte as lte4 } from "drizzle-orm";
3572
+ var channelStateKey = /* @__PURE__ */ __name((key2) => key2.length <= 255 ? key2 : `sha256:${createHash2("sha256").update(key2).digest("hex")}`, "channelStateKey");
3573
+ var DrizzleChannelStore = class {
3574
+ static {
3575
+ __name(this, "DrizzleChannelStore");
3576
+ }
3577
+ db;
3578
+ dialect;
3579
+ t;
3580
+ purgeEveryMs;
3581
+ lastPurge = 0;
3582
+ constructor(db, options = {}) {
3583
+ this.dialect = agentDialectOf(db);
3584
+ this.t = agentTablesFor(this.dialect);
3585
+ this.db = asBuilder(db);
3586
+ this.purgeEveryMs = options.purgeEveryMs ?? 10 * 60 * 1e3;
3587
+ }
3588
+ async claim(key2, ttlMs) {
3589
+ const table = this.t.agentChannelState;
3590
+ const now = Date.now();
3591
+ if (this.purgeEveryMs > 0 && now - this.lastPurge >= this.purgeEveryMs) {
3592
+ this.lastPurge = now;
3593
+ await this.purgeExpired(now);
3594
+ }
3595
+ const id = channelStateKey(key2);
3596
+ await this.db.delete(table).where(and7(eq8(table.key, id), lte4(table.expiresAt, now)));
3597
+ const row = {
3598
+ key: id,
3599
+ value: null,
3600
+ expiresAt: now + ttlMs,
3601
+ createdAt: now
3602
+ };
3603
+ if (this.dialect === "mysql") {
3604
+ const insert = this.db.insert(table);
3605
+ return mysqlAffectedRows(await insert.ignore().values(row)) === 1;
3606
+ }
3607
+ const inserted = await affectedRows(this.dialect, this.db.insert(table).values(row).onConflictDoNothing(), table.key);
3608
+ return inserted === 1;
3609
+ }
3610
+ async get(key2) {
3611
+ const table = this.t.agentChannelState;
3612
+ const rows = await this.db.select({
3613
+ value: table.value
3614
+ }).from(table).where(and7(eq8(table.key, channelStateKey(key2)), gt3(table.expiresAt, Date.now())));
3615
+ const value = rows[0]?.value;
3616
+ return typeof value === "string" ? value : null;
3617
+ }
3618
+ async set(key2, value, ttlMs) {
3619
+ const table = this.t.agentChannelState;
3620
+ const now = Date.now();
3621
+ await upsert(this.dialect, this.db.insert(table).values({
3622
+ key: channelStateKey(key2),
3623
+ value,
3624
+ expiresAt: now + ttlMs,
3625
+ createdAt: now
3626
+ }), table.key, {
3627
+ value,
3628
+ expiresAt: now + ttlMs
3629
+ });
3630
+ }
3631
+ async delete(key2) {
3632
+ const table = this.t.agentChannelState;
3633
+ await this.db.delete(table).where(eq8(table.key, channelStateKey(key2)));
3634
+ }
3635
+ async purgeExpired(now = Date.now()) {
3636
+ const table = this.t.agentChannelState;
3637
+ return affectedRows(this.dialect, this.db.delete(table).where(lte4(table.expiresAt, now)), table.key);
3638
+ }
3639
+ };
3640
+
3534
3641
  // src/drizzle-rag-ingestion-log.ts
3535
3642
  import { subscribe, unsubscribe } from "diagnostics_channel";
3536
3643
  import { Injectable, Logger } from "@nestjs/common";
3537
- import { and as and7, asc as asc5, count as count2, desc as desc3, eq as eq8, gt as gt3, lt as lt3, or as or3 } from "drizzle-orm";
3644
+ import { and as and8, asc as asc5, count as count2, desc as desc3, eq as eq9, gt as gt4, lt as lt3, or as or3 } from "drizzle-orm";
3538
3645
  function _ts_decorate(decorators, target, key2, desc4) {
3539
3646
  var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key2) : desc4, d;
3540
3647
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -3733,17 +3840,17 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
3733
3840
  }
3734
3841
  /** The latest recorded outcome for one document, or null if it was never attempted. */
3735
3842
  async get(documentId) {
3736
- const [row] = await this.db.select().from(this.t.ragIngestionLog).where(eq8(this.t.ragIngestionLog.documentId, documentId));
3843
+ const [row] = await this.db.select().from(this.t.ragIngestionLog).where(eq9(this.t.ragIngestionLog.documentId, documentId));
3737
3844
  return row ?? null;
3738
3845
  }
3739
3846
  /** Forget one document's record. Returns whether a row was actually removed. */
3740
3847
  async remove(documentId) {
3741
- const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where(eq8(this.t.ragIngestionLog.documentId, documentId)), this.t.ragIngestionLog.documentId);
3848
+ const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where(eq9(this.t.ragIngestionLog.documentId, documentId)), this.t.ragIngestionLog.documentId);
3742
3849
  return removed > 0;
3743
3850
  }
3744
3851
  /** Forget every record for a collection — for when the collection itself is deleted. */
3745
3852
  async removeByCollection(collection) {
3746
- const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where(eq8(this.t.ragIngestionLog.collection, collection)), this.t.ragIngestionLog.documentId);
3853
+ const removed = await affectedRows(this.dialect, this.db.delete(this.t.ragIngestionLog).where(eq9(this.t.ragIngestionLog.collection, collection)), this.t.ragIngestionLog.documentId);
3747
3854
  return removed;
3748
3855
  }
3749
3856
  /**
@@ -3773,7 +3880,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
3773
3880
  }
3774
3881
  }
3775
3882
  where(query) {
3776
- return and7(query.collection !== void 0 ? eq8(this.t.ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? eq8(this.t.ragIngestionLog.status, query.status) : void 0);
3883
+ return and8(query.collection !== void 0 ? eq9(this.t.ragIngestionLog.collection, query.collection) : void 0, query.status !== void 0 ? eq9(this.t.ragIngestionLog.status, query.status) : void 0);
3777
3884
  }
3778
3885
  /**
3779
3886
  * The coordinates filter AND'd with "strictly after `cursor` in
@@ -3788,7 +3895,7 @@ var DrizzleRagIngestionLog = class _DrizzleRagIngestionLog {
3788
3895
  if (cursor === void 0) {
3789
3896
  return base;
3790
3897
  }
3791
- return and7(base, or3(lt3(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), and7(eq8(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), gt3(this.t.ragIngestionLog.documentId, cursor.documentId))));
3898
+ return and8(base, or3(lt3(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), and8(eq9(this.t.ragIngestionLog.updatedAt, cursor.updatedAt), gt4(this.t.ragIngestionLog.documentId, cursor.documentId))));
3792
3899
  }
3793
3900
  /**
3794
3901
  * Upsert one outcome. Keyed by document id so the row always reflects the *current* state — a
@@ -3861,7 +3968,7 @@ DrizzleRagIngestionLog = _ts_decorate([
3861
3968
  ], DrizzleRagIngestionLog);
3862
3969
 
3863
3970
  // src/drizzle-agent-store.module.ts
3864
- import { AGENT_CONFIRM_TOKEN_STORE, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, AGENT_STORE } from "@dudousxd/nestjs-agent-core";
3971
+ import { AGENT_CHANNEL_STORE, AGENT_CONFIRM_TOKEN_STORE, AGENT_GOVERNANCE_QUERIES, AGENT_PRICING_STORE, AGENT_STORE } from "@dudousxd/nestjs-agent-core";
3865
3972
  import { Module } from "@nestjs/common";
3866
3973
  function _ts_decorate2(decorators, target, key2, desc4) {
3867
3974
  var c = arguments.length, r = c < 3 ? target : desc4 === null ? desc4 = Object.getOwnPropertyDescriptor(target, key2) : desc4, d;
@@ -3940,6 +4047,15 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
3940
4047
  {
3941
4048
  provide: AGENT_CONFIRM_TOKEN_STORE,
3942
4049
  useExisting: DrizzleConfirmTokenStore
4050
+ },
4051
+ // Text channels' state (`@dudousxd/nestjs-agent-channels`), shared by every replica.
4052
+ {
4053
+ provide: DrizzleChannelStore,
4054
+ useFactory: /* @__PURE__ */ __name(() => new DrizzleChannelStore(options.db), "useFactory")
4055
+ },
4056
+ {
4057
+ provide: AGENT_CHANNEL_STORE,
4058
+ useExisting: DrizzleChannelStore
3943
4059
  }
3944
4060
  ],
3945
4061
  exports: [
@@ -3954,7 +4070,9 @@ var DrizzleAgentStoreModule = class _DrizzleAgentStoreModule {
3954
4070
  DrizzlePricingStore,
3955
4071
  AGENT_PRICING_STORE,
3956
4072
  DrizzleConfirmTokenStore,
3957
- AGENT_CONFIRM_TOKEN_STORE
4073
+ AGENT_CONFIRM_TOKEN_STORE,
4074
+ DrizzleChannelStore,
4075
+ AGENT_CHANNEL_STORE
3958
4076
  ]
3959
4077
  };
3960
4078
  }
@@ -3966,6 +4084,7 @@ export {
3966
4084
  DrizzleActionProposalStore,
3967
4085
  DrizzleAgentStore,
3968
4086
  DrizzleAgentStoreModule,
4087
+ DrizzleChannelStore,
3969
4088
  DrizzleConfirmTokenStore,
3970
4089
  DrizzleGovernanceQueries,
3971
4090
  DrizzleMemoryProvider,
@@ -3975,6 +4094,7 @@ export {
3975
4094
  DrizzleTokenStreamSink,
3976
4095
  RAG_INGESTION_LOG_PAGE_ORDER,
3977
4096
  agentActionProposal,
4097
+ agentChannelState,
3978
4098
  agentConfirmToken,
3979
4099
  agentDialectOf,
3980
4100
  agentMemory,