@dudousxd/nestjs-agent-store-drizzle 0.11.0 → 0.12.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.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
2
2
  import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
3
- import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, RecordUsageInput, 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 } from '@dudousxd/nestjs-agent-core';
3
+ import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, RecordUsageInput, 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 } from '@dudousxd/nestjs-agent-core';
4
4
  export { ThreadTurnPage, ThreadTurnQuery } from '@dudousxd/nestjs-agent-core';
5
5
  import { TablesRelationalConfig, SQL } from 'drizzle-orm';
6
6
  import { OnModuleInit, OnModuleDestroy, Type, DynamicModule } from '@nestjs/common';
@@ -751,6 +751,78 @@ declare const agentToolCall: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
751
751
  }, {}, {
752
752
  length: number | undefined;
753
753
  }>;
754
+ approver: drizzle_orm_sqlite_core.SQLiteColumn<{
755
+ name: "approver";
756
+ tableName: "agent_tool_call";
757
+ dataType: "string";
758
+ columnType: "SQLiteText";
759
+ data: string;
760
+ driverParam: string;
761
+ notNull: false;
762
+ hasDefault: false;
763
+ isPrimaryKey: false;
764
+ isAutoincrement: false;
765
+ hasRuntimeDefault: false;
766
+ enumValues: [string, ...string[]];
767
+ baseColumn: never;
768
+ identity: undefined;
769
+ generated: undefined;
770
+ }, {}, {
771
+ length: number | undefined;
772
+ }>;
773
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
774
+ name: "expires_at";
775
+ tableName: "agent_tool_call";
776
+ dataType: "date";
777
+ columnType: "SQLiteTimestamp";
778
+ data: Date;
779
+ driverParam: number;
780
+ notNull: false;
781
+ hasDefault: false;
782
+ isPrimaryKey: false;
783
+ isAutoincrement: false;
784
+ hasRuntimeDefault: false;
785
+ enumValues: undefined;
786
+ baseColumn: never;
787
+ identity: undefined;
788
+ generated: undefined;
789
+ }, {}, {}>;
790
+ remember: drizzle_orm_sqlite_core.SQLiteColumn<{
791
+ name: "remember";
792
+ tableName: "agent_tool_call";
793
+ dataType: "boolean";
794
+ columnType: "SQLiteBoolean";
795
+ data: boolean;
796
+ driverParam: number;
797
+ notNull: false;
798
+ hasDefault: false;
799
+ isPrimaryKey: false;
800
+ isAutoincrement: false;
801
+ hasRuntimeDefault: false;
802
+ enumValues: undefined;
803
+ baseColumn: never;
804
+ identity: undefined;
805
+ generated: undefined;
806
+ }, {}, {}>;
807
+ decidedVia: drizzle_orm_sqlite_core.SQLiteColumn<{
808
+ name: "decided_via";
809
+ tableName: "agent_tool_call";
810
+ dataType: "string";
811
+ columnType: "SQLiteText";
812
+ data: string;
813
+ driverParam: string;
814
+ notNull: false;
815
+ hasDefault: false;
816
+ isPrimaryKey: false;
817
+ isAutoincrement: false;
818
+ hasRuntimeDefault: false;
819
+ enumValues: [string, ...string[]];
820
+ baseColumn: never;
821
+ identity: undefined;
822
+ generated: undefined;
823
+ }, {}, {
824
+ length: number | undefined;
825
+ }>;
754
826
  };
755
827
  dialect: "sqlite";
756
828
  }>;
@@ -2604,6 +2676,78 @@ declare const agentSchema: {
2604
2676
  }, {}, {
2605
2677
  length: number | undefined;
2606
2678
  }>;
2679
+ approver: drizzle_orm_sqlite_core.SQLiteColumn<{
2680
+ name: "approver";
2681
+ tableName: "agent_tool_call";
2682
+ dataType: "string";
2683
+ columnType: "SQLiteText";
2684
+ data: string;
2685
+ driverParam: string;
2686
+ notNull: false;
2687
+ hasDefault: false;
2688
+ isPrimaryKey: false;
2689
+ isAutoincrement: false;
2690
+ hasRuntimeDefault: false;
2691
+ enumValues: [string, ...string[]];
2692
+ baseColumn: never;
2693
+ identity: undefined;
2694
+ generated: undefined;
2695
+ }, {}, {
2696
+ length: number | undefined;
2697
+ }>;
2698
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2699
+ name: "expires_at";
2700
+ tableName: "agent_tool_call";
2701
+ dataType: "date";
2702
+ columnType: "SQLiteTimestamp";
2703
+ data: Date;
2704
+ driverParam: number;
2705
+ notNull: false;
2706
+ hasDefault: false;
2707
+ isPrimaryKey: false;
2708
+ isAutoincrement: false;
2709
+ hasRuntimeDefault: false;
2710
+ enumValues: undefined;
2711
+ baseColumn: never;
2712
+ identity: undefined;
2713
+ generated: undefined;
2714
+ }, {}, {}>;
2715
+ remember: drizzle_orm_sqlite_core.SQLiteColumn<{
2716
+ name: "remember";
2717
+ tableName: "agent_tool_call";
2718
+ dataType: "boolean";
2719
+ columnType: "SQLiteBoolean";
2720
+ data: boolean;
2721
+ driverParam: number;
2722
+ notNull: false;
2723
+ hasDefault: false;
2724
+ isPrimaryKey: false;
2725
+ isAutoincrement: false;
2726
+ hasRuntimeDefault: false;
2727
+ enumValues: undefined;
2728
+ baseColumn: never;
2729
+ identity: undefined;
2730
+ generated: undefined;
2731
+ }, {}, {}>;
2732
+ decidedVia: drizzle_orm_sqlite_core.SQLiteColumn<{
2733
+ name: "decided_via";
2734
+ tableName: "agent_tool_call";
2735
+ dataType: "string";
2736
+ columnType: "SQLiteText";
2737
+ data: string;
2738
+ driverParam: string;
2739
+ notNull: false;
2740
+ hasDefault: false;
2741
+ isPrimaryKey: false;
2742
+ isAutoincrement: false;
2743
+ hasRuntimeDefault: false;
2744
+ enumValues: [string, ...string[]];
2745
+ baseColumn: never;
2746
+ identity: undefined;
2747
+ generated: undefined;
2748
+ }, {}, {
2749
+ length: number | undefined;
2750
+ }>;
2607
2751
  };
2608
2752
  dialect: "sqlite";
2609
2753
  }>;
@@ -3743,6 +3887,15 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3743
3887
  ownerOfThread(threadId: string): Promise<string | null>;
3744
3888
  ownerOfToolCall(toolCallId: string): Promise<string | null>;
3745
3889
  runForToolCall(toolCallId: string): Promise<string | null>;
3890
+ /**
3891
+ * The approval record of every call on `messageIds` that a policy put to a person, grouped by
3892
+ * message. One query over the calls that carry an approver — a thread whose calls never asked
3893
+ * anyone reads nothing back.
3894
+ */
3895
+ private approvalsFor;
3896
+ /** Tools whose approval someone asked to remember in this thread. */
3897
+ rememberedApprovals(threadId: string): Promise<string[]>;
3898
+ toolCallApproval(toolCallId: string): Promise<ToolCallApprovalState | null>;
3746
3899
  ownerOfActiveStream(runId: string): Promise<string | null>;
3747
3900
  setTitle(threadId: string, title: string): Promise<void>;
3748
3901
  promoteThread(threadId: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as drizzle_orm_sqlite_core from 'drizzle-orm/sqlite-core';
2
2
  import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
3
- import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, RecordUsageInput, 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 } from '@dudousxd/nestjs-agent-core';
3
+ import { MessageRole, ToolCallRequest, ToolResult, MessageAttachment, MessageUsage, AgentUiComponent, ToolKind, ToolCallStatus, UsagePurpose, AgentStore, ThreadTurnReader, CreateThreadInput, ThreadSummary, ThreadDetail, ThreadTurnQuery, ThreadTurnPage, ToolCallApprovalState, UpdateThreadInput, RecordRunStartInput, AppendMessageInput, StoredMessage, RecordToolCallInput, UpdateToolCallInput, RecordUsageInput, 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 } from '@dudousxd/nestjs-agent-core';
4
4
  export { ThreadTurnPage, ThreadTurnQuery } from '@dudousxd/nestjs-agent-core';
5
5
  import { TablesRelationalConfig, SQL } from 'drizzle-orm';
6
6
  import { OnModuleInit, OnModuleDestroy, Type, DynamicModule } from '@nestjs/common';
@@ -751,6 +751,78 @@ declare const agentToolCall: drizzle_orm_sqlite_core.SQLiteTableWithColumns<{
751
751
  }, {}, {
752
752
  length: number | undefined;
753
753
  }>;
754
+ approver: drizzle_orm_sqlite_core.SQLiteColumn<{
755
+ name: "approver";
756
+ tableName: "agent_tool_call";
757
+ dataType: "string";
758
+ columnType: "SQLiteText";
759
+ data: string;
760
+ driverParam: string;
761
+ notNull: false;
762
+ hasDefault: false;
763
+ isPrimaryKey: false;
764
+ isAutoincrement: false;
765
+ hasRuntimeDefault: false;
766
+ enumValues: [string, ...string[]];
767
+ baseColumn: never;
768
+ identity: undefined;
769
+ generated: undefined;
770
+ }, {}, {
771
+ length: number | undefined;
772
+ }>;
773
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
774
+ name: "expires_at";
775
+ tableName: "agent_tool_call";
776
+ dataType: "date";
777
+ columnType: "SQLiteTimestamp";
778
+ data: Date;
779
+ driverParam: number;
780
+ notNull: false;
781
+ hasDefault: false;
782
+ isPrimaryKey: false;
783
+ isAutoincrement: false;
784
+ hasRuntimeDefault: false;
785
+ enumValues: undefined;
786
+ baseColumn: never;
787
+ identity: undefined;
788
+ generated: undefined;
789
+ }, {}, {}>;
790
+ remember: drizzle_orm_sqlite_core.SQLiteColumn<{
791
+ name: "remember";
792
+ tableName: "agent_tool_call";
793
+ dataType: "boolean";
794
+ columnType: "SQLiteBoolean";
795
+ data: boolean;
796
+ driverParam: number;
797
+ notNull: false;
798
+ hasDefault: false;
799
+ isPrimaryKey: false;
800
+ isAutoincrement: false;
801
+ hasRuntimeDefault: false;
802
+ enumValues: undefined;
803
+ baseColumn: never;
804
+ identity: undefined;
805
+ generated: undefined;
806
+ }, {}, {}>;
807
+ decidedVia: drizzle_orm_sqlite_core.SQLiteColumn<{
808
+ name: "decided_via";
809
+ tableName: "agent_tool_call";
810
+ dataType: "string";
811
+ columnType: "SQLiteText";
812
+ data: string;
813
+ driverParam: string;
814
+ notNull: false;
815
+ hasDefault: false;
816
+ isPrimaryKey: false;
817
+ isAutoincrement: false;
818
+ hasRuntimeDefault: false;
819
+ enumValues: [string, ...string[]];
820
+ baseColumn: never;
821
+ identity: undefined;
822
+ generated: undefined;
823
+ }, {}, {
824
+ length: number | undefined;
825
+ }>;
754
826
  };
755
827
  dialect: "sqlite";
756
828
  }>;
@@ -2604,6 +2676,78 @@ declare const agentSchema: {
2604
2676
  }, {}, {
2605
2677
  length: number | undefined;
2606
2678
  }>;
2679
+ approver: drizzle_orm_sqlite_core.SQLiteColumn<{
2680
+ name: "approver";
2681
+ tableName: "agent_tool_call";
2682
+ dataType: "string";
2683
+ columnType: "SQLiteText";
2684
+ data: string;
2685
+ driverParam: string;
2686
+ notNull: false;
2687
+ hasDefault: false;
2688
+ isPrimaryKey: false;
2689
+ isAutoincrement: false;
2690
+ hasRuntimeDefault: false;
2691
+ enumValues: [string, ...string[]];
2692
+ baseColumn: never;
2693
+ identity: undefined;
2694
+ generated: undefined;
2695
+ }, {}, {
2696
+ length: number | undefined;
2697
+ }>;
2698
+ expiresAt: drizzle_orm_sqlite_core.SQLiteColumn<{
2699
+ name: "expires_at";
2700
+ tableName: "agent_tool_call";
2701
+ dataType: "date";
2702
+ columnType: "SQLiteTimestamp";
2703
+ data: Date;
2704
+ driverParam: number;
2705
+ notNull: false;
2706
+ hasDefault: false;
2707
+ isPrimaryKey: false;
2708
+ isAutoincrement: false;
2709
+ hasRuntimeDefault: false;
2710
+ enumValues: undefined;
2711
+ baseColumn: never;
2712
+ identity: undefined;
2713
+ generated: undefined;
2714
+ }, {}, {}>;
2715
+ remember: drizzle_orm_sqlite_core.SQLiteColumn<{
2716
+ name: "remember";
2717
+ tableName: "agent_tool_call";
2718
+ dataType: "boolean";
2719
+ columnType: "SQLiteBoolean";
2720
+ data: boolean;
2721
+ driverParam: number;
2722
+ notNull: false;
2723
+ hasDefault: false;
2724
+ isPrimaryKey: false;
2725
+ isAutoincrement: false;
2726
+ hasRuntimeDefault: false;
2727
+ enumValues: undefined;
2728
+ baseColumn: never;
2729
+ identity: undefined;
2730
+ generated: undefined;
2731
+ }, {}, {}>;
2732
+ decidedVia: drizzle_orm_sqlite_core.SQLiteColumn<{
2733
+ name: "decided_via";
2734
+ tableName: "agent_tool_call";
2735
+ dataType: "string";
2736
+ columnType: "SQLiteText";
2737
+ data: string;
2738
+ driverParam: string;
2739
+ notNull: false;
2740
+ hasDefault: false;
2741
+ isPrimaryKey: false;
2742
+ isAutoincrement: false;
2743
+ hasRuntimeDefault: false;
2744
+ enumValues: [string, ...string[]];
2745
+ baseColumn: never;
2746
+ identity: undefined;
2747
+ generated: undefined;
2748
+ }, {}, {
2749
+ length: number | undefined;
2750
+ }>;
2607
2751
  };
2608
2752
  dialect: "sqlite";
2609
2753
  }>;
@@ -3743,6 +3887,15 @@ declare class DrizzleAgentStore implements AgentStore, ThreadTurnReader {
3743
3887
  ownerOfThread(threadId: string): Promise<string | null>;
3744
3888
  ownerOfToolCall(toolCallId: string): Promise<string | null>;
3745
3889
  runForToolCall(toolCallId: string): Promise<string | null>;
3890
+ /**
3891
+ * The approval record of every call on `messageIds` that a policy put to a person, grouped by
3892
+ * message. One query over the calls that carry an approver — a thread whose calls never asked
3893
+ * anyone reads nothing back.
3894
+ */
3895
+ private approvalsFor;
3896
+ /** Tools whose approval someone asked to remember in this thread. */
3897
+ rememberedApprovals(threadId: string): Promise<string[]>;
3898
+ toolCallApproval(toolCallId: string): Promise<ToolCallApprovalState | null>;
3746
3899
  ownerOfActiveStream(runId: string): Promise<string | null>;
3747
3900
  setTitle(threadId: string, title: string): Promise<void>;
3748
3901
  promoteThread(threadId: string): Promise<void>;
package/dist/index.js CHANGED
@@ -87,7 +87,19 @@ var agentToolCall = sqliteTable("agent_tool_call", {
87
87
  mode: "timestamp_ms"
88
88
  }),
89
89
  /** The run (turn) this call belongs to, for a trace deep-link; null for a pre-rollout row. */
90
- runId: text("run_id")
90
+ runId: text("run_id"),
91
+ /** Who had to approve it (`requester` or a role); null for a call no policy put to anyone. */
92
+ approver: text("approver"),
93
+ /** When the approval request lapses; null → never. */
94
+ expiresAt: integer("expires_at", {
95
+ mode: "timestamp_ms"
96
+ }),
97
+ /** The approval covers later calls of this tool in this thread. */
98
+ remember: integer("remember", {
99
+ mode: "boolean"
100
+ }),
101
+ /** The surface the decision came through (`web`, `slack`, `remembered`, …). */
102
+ decidedVia: text("decided_via")
91
103
  }, (table) => [
92
104
  index("agent_tool_call_message_idx").on(table.messageId)
93
105
  ]);
@@ -273,7 +285,11 @@ var statements = [
273
285
  error TEXT,
274
286
  created_at INTEGER NOT NULL,
275
287
  executed_at INTEGER,
276
- run_id TEXT
288
+ run_id TEXT,
289
+ approver TEXT,
290
+ expires_at INTEGER,
291
+ remember INTEGER,
292
+ decided_via TEXT
277
293
  )`,
278
294
  `CREATE INDEX IF NOT EXISTS agent_tool_call_message_idx
279
295
  ON agent_tool_call (message_id)`,
@@ -390,6 +406,26 @@ var additiveColumns = [
390
406
  table: "agent_message",
391
407
  column: "ui",
392
408
  ddl: "ALTER TABLE agent_message ADD COLUMN ui TEXT"
409
+ },
410
+ {
411
+ table: "agent_tool_call",
412
+ column: "approver",
413
+ ddl: "ALTER TABLE agent_tool_call ADD COLUMN approver TEXT"
414
+ },
415
+ {
416
+ table: "agent_tool_call",
417
+ column: "expires_at",
418
+ ddl: "ALTER TABLE agent_tool_call ADD COLUMN expires_at INTEGER"
419
+ },
420
+ {
421
+ table: "agent_tool_call",
422
+ column: "remember",
423
+ ddl: "ALTER TABLE agent_tool_call ADD COLUMN remember INTEGER"
424
+ },
425
+ {
426
+ table: "agent_tool_call",
427
+ column: "decided_via",
428
+ ddl: "ALTER TABLE agent_tool_call ADD COLUMN decided_via TEXT"
393
429
  }
394
430
  ];
395
431
  async function ensureAgentSchema(db) {
@@ -406,6 +442,7 @@ async function ensureAgentSchema(db) {
406
442
  __name(ensureAgentSchema, "ensureAgentSchema");
407
443
 
408
444
  // src/drizzle-agent-store.ts
445
+ import { toolCallApprovalFromRow } from "@dudousxd/nestjs-agent-core";
409
446
  import { and, asc, desc, eq, gte, inArray, isNotNull, isNull, lte, sql as sql2 } from "drizzle-orm";
410
447
  var TURN_MESSAGE_COLUMNS = {
411
448
  id: agentMessage.id,
@@ -449,9 +486,17 @@ var DrizzleAgentStore = class {
449
486
  }
450
487
  const messages = await this.db.select().from(agentMessage).where(eq(agentMessage.threadId, threadId)).orderBy(asc(agentMessage.createdAt), asc(agentMessage.id));
451
488
  const last = messages[messages.length - 1];
489
+ const approvals = await this.approvalsFor(messages.map((message) => message.id));
452
490
  return {
453
491
  ...this.toSummary(thread, last?.content),
454
- messages: messages.map((message) => this.toStoredMessage(message)),
492
+ messages: messages.map((message) => {
493
+ const stored = this.toStoredMessage(message);
494
+ const onMessage = approvals.get(message.id);
495
+ return onMessage !== void 0 ? {
496
+ ...stored,
497
+ approvals: onMessage
498
+ } : stored;
499
+ }),
455
500
  ...thread.activeStreamId != null ? {
456
501
  activeStreamId: thread.activeStreamId
457
502
  } : {}
@@ -580,6 +625,63 @@ var DrizzleAgentStore = class {
580
625
  }).from(agentToolCall).innerJoin(agentMessage, eq(agentToolCall.messageId, agentMessage.id)).innerJoin(agentThread, eq(agentMessage.threadId, agentThread.id)).where(eq(agentToolCall.id, toolCallId));
581
626
  return row?.runId ?? row?.activeStreamId ?? null;
582
627
  }
628
+ /**
629
+ * The approval record of every call on `messageIds` that a policy put to a person, grouped by
630
+ * message. One query over the calls that carry an approver — a thread whose calls never asked
631
+ * anyone reads nothing back.
632
+ */
633
+ async approvalsFor(messageIds) {
634
+ const byMessage = /* @__PURE__ */ new Map();
635
+ if (messageIds.length === 0) {
636
+ return byMessage;
637
+ }
638
+ const rows = await this.db.select({
639
+ id: agentToolCall.id,
640
+ messageId: agentToolCall.messageId,
641
+ status: agentToolCall.status,
642
+ approver: agentToolCall.approver,
643
+ expiresAt: agentToolCall.expiresAt,
644
+ remember: agentToolCall.remember,
645
+ executedByRef: agentToolCall.executedByRef,
646
+ decidedVia: agentToolCall.decidedVia,
647
+ error: agentToolCall.error
648
+ }).from(agentToolCall).where(and(inArray(agentToolCall.messageId, messageIds), isNotNull(agentToolCall.approver))).orderBy(asc(agentToolCall.createdAt), asc(agentToolCall.id));
649
+ for (const row of rows) {
650
+ const approval = toolCallApprovalFromRow({
651
+ ...row,
652
+ toolCallId: row.id
653
+ });
654
+ if (approval === null) {
655
+ continue;
656
+ }
657
+ const list = byMessage.get(row.messageId) ?? [];
658
+ list.push(approval);
659
+ byMessage.set(row.messageId, list);
660
+ }
661
+ return byMessage;
662
+ }
663
+ /** Tools whose approval someone asked to remember in this thread. */
664
+ async rememberedApprovals(threadId) {
665
+ const rows = await this.db.selectDistinct({
666
+ toolName: agentToolCall.toolName
667
+ }).from(agentToolCall).innerJoin(agentMessage, eq(agentToolCall.messageId, agentMessage.id)).where(and(eq(agentMessage.threadId, threadId), eq(agentToolCall.remember, true)));
668
+ return rows.map((row) => row.toolName);
669
+ }
670
+ async toolCallApproval(toolCallId) {
671
+ const [row] = await this.db.select({
672
+ status: agentToolCall.status,
673
+ approver: agentToolCall.approver,
674
+ expiresAt: agentToolCall.expiresAt
675
+ }).from(agentToolCall).where(eq(agentToolCall.id, toolCallId));
676
+ if (row === void 0) {
677
+ return null;
678
+ }
679
+ return {
680
+ status: row.status,
681
+ approver: row.approver,
682
+ expiresAt: row.expiresAt?.toISOString() ?? null
683
+ };
684
+ }
583
685
  async ownerOfActiveStream(runId) {
584
686
  const [thread] = await this.db.select({
585
687
  actorRef: agentThread.actorRef
@@ -739,7 +841,11 @@ var DrizzleAgentStore = class {
739
841
  error: null,
740
842
  createdAt: /* @__PURE__ */ new Date(),
741
843
  executedAt: null,
742
- runId: input.runId ?? null
844
+ runId: input.runId ?? null,
845
+ approver: input.approver ?? null,
846
+ expiresAt: input.expiresAt !== void 0 ? new Date(input.expiresAt) : null,
847
+ remember: null,
848
+ decidedVia: null
743
849
  });
744
850
  }
745
851
  async updateToolCall(input) {
@@ -758,6 +864,12 @@ var DrizzleAgentStore = class {
758
864
  if (input.executedByRef !== void 0) {
759
865
  updates.executedByRef = input.executedByRef;
760
866
  }
867
+ if (input.remember !== void 0) {
868
+ updates.remember = input.remember;
869
+ }
870
+ if (input.decidedVia !== void 0) {
871
+ updates.decidedVia = input.decidedVia;
872
+ }
761
873
  if (input.status === "executed" || input.status === "auto_executed") {
762
874
  updates.executedAt = /* @__PURE__ */ new Date();
763
875
  }
@@ -886,7 +998,8 @@ var TOOL_CALL_STATUSES = [
886
998
  "pending_approval",
887
999
  "executed",
888
1000
  "rejected",
889
- "failed"
1001
+ "failed",
1002
+ "expired"
890
1003
  ];
891
1004
  function isToolCallStatus(value) {
892
1005
  return TOOL_CALL_STATUSES.includes(value);