@dudousxd/nestjs-agent-store-drizzle 0.28.3 → 0.28.5

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
@@ -6215,6 +6215,13 @@ declare class DrizzleActionProposalStore implements ActionProposalStore, ActionP
6215
6215
  admitActionProposalOutcome(command: ActionProposalOutcomeLease): ReturnType<ActionProposalOutcomeStore['admitActionProposalOutcome']>;
6216
6216
  private transactionSteps;
6217
6217
  private admissionSteps;
6218
+ /**
6219
+ * The update that settles the proposal's `proposed` tool-call record after a transition from
6220
+ * `previous` to `next` (see `toolCallUpdateForTransition`), or `undefined` when its status stays —
6221
+ * so the dashboard and run detail show `executed` / `failed` / `rejected` / `expired` instead of
6222
+ * `proposed` forever.
6223
+ */
6224
+ private toolCallSettlement;
6218
6225
  private read;
6219
6226
  private mutate;
6220
6227
  }
package/dist/index.d.ts CHANGED
@@ -6215,6 +6215,13 @@ declare class DrizzleActionProposalStore implements ActionProposalStore, ActionP
6215
6215
  admitActionProposalOutcome(command: ActionProposalOutcomeLease): ReturnType<ActionProposalOutcomeStore['admitActionProposalOutcome']>;
6216
6216
  private transactionSteps;
6217
6217
  private admissionSteps;
6218
+ /**
6219
+ * The update that settles the proposal's `proposed` tool-call record after a transition from
6220
+ * `previous` to `next` (see `toolCallUpdateForTransition`), or `undefined` when its status stays —
6221
+ * so the dashboard and run detail show `executed` / `failed` / `rejected` / `expired` instead of
6222
+ * `proposed` forever.
6223
+ */
6224
+ private toolCallSettlement;
6218
6225
  private read;
6219
6226
  private mutate;
6220
6227
  }
package/dist/index.js CHANGED
@@ -1180,7 +1180,7 @@ import { and as and2, asc as asc2, desc, eq as eq2, gte, inArray, isNotNull, isN
1180
1180
 
1181
1181
  // src/drizzle-action-proposal-store.ts
1182
1182
  import { createHash, randomUUID } from "crypto";
1183
- import { actionProposalOutcomeFenceValid, actionProposalOutcomeText, actionProposalScopeMatches, canonicalActionProposalJson as canonicalActionProposalJson3, claimActionProposalOutcome, initialActionProposal, transitionActionProposalClaim, transitionActionProposalDecision, transitionActionProposalLease, transitionActionProposalSettlement, transitionActionProposalSupersession, validateActionProposalDiscoveryIndexBatch, validateActionProposalExpiryBatch, validateActionProposalListQuery, validateActionProposalWorkerClaim } from "@dudousxd/nestjs-agent-core";
1183
+ import { actionProposalOutcomeFenceValid, actionProposalOutcomeText, actionProposalScopeMatches, canonicalActionProposalJson as canonicalActionProposalJson3, claimActionProposalOutcome, initialActionProposal, toolCallUpdateForTransition, transitionActionProposalClaim, transitionActionProposalDecision, transitionActionProposalLease, transitionActionProposalSettlement, transitionActionProposalSupersession, validateActionProposalDiscoveryIndexBatch, validateActionProposalExpiryBatch, validateActionProposalListQuery, validateActionProposalWorkerClaim } from "@dudousxd/nestjs-agent-core";
1184
1184
  import { and, asc, entityKind, eq, gt, isNull, lte, max, or, sql as sql2 } from "drizzle-orm";
1185
1185
 
1186
1186
  // src/action-proposal-transaction-mode.ts
@@ -1344,6 +1344,11 @@ var DrizzleActionProposalStore = class {
1344
1344
  })
1345
1345
  };
1346
1346
  if ((this.dialect === "mysql" ? mysqlAffectedRows(updated) : updated.length) !== 1) throw new Error("Replacement lost its locked proposal fence");
1347
+ const settled = this.toolCallSettlement(db, old.proposal, next);
1348
+ if (settled) yield {
1349
+ kind: "write",
1350
+ query: settled
1351
+ };
1347
1352
  }
1348
1353
  return {
1349
1354
  status: "created",
@@ -1596,6 +1601,38 @@ var DrizzleActionProposalStore = class {
1596
1601
  messageId
1597
1602
  };
1598
1603
  }
1604
+ /**
1605
+ * The update that settles the proposal's `proposed` tool-call record after a transition from
1606
+ * `previous` to `next` (see `toolCallUpdateForTransition`), or `undefined` when its status stays —
1607
+ * so the dashboard and run detail show `executed` / `failed` / `rejected` / `expired` instead of
1608
+ * `proposed` forever.
1609
+ */
1610
+ toolCallSettlement(db, previous, next) {
1611
+ const update = toolCallUpdateForTransition(previous, next);
1612
+ if (update === null) return void 0;
1613
+ const toolCall = agentTablesFor(this.dialect).agentToolCall;
1614
+ return db.update(toolCall).set({
1615
+ status: update.status,
1616
+ ...update.output !== void 0 ? {
1617
+ output: update.output
1618
+ } : {},
1619
+ ...update.error !== void 0 ? {
1620
+ error: update.error
1621
+ } : {},
1622
+ ...update.executedByRef !== void 0 ? {
1623
+ executedByRef: update.executedByRef
1624
+ } : {},
1625
+ ...update.decidedVia !== void 0 ? {
1626
+ decidedVia: update.decidedVia
1627
+ } : {},
1628
+ ...update.remember !== void 0 ? {
1629
+ remember: update.remember
1630
+ } : {},
1631
+ ...update.status === "executed" ? {
1632
+ executedAt: new Date(this.clock())
1633
+ } : {}
1634
+ }).where(and(eq(toolCall.id, update.toolCallId), eq(toolCall.proposalId, next.id)));
1635
+ }
1599
1636
  async read(scope, id) {
1600
1637
  const [row] = await this.db.select().from(this.table).where(and(eq(this.table.id, physicalId(id)), eq(this.table.scopeKey, scopeKey(scope)))).limit(1);
1601
1638
  return row && row.proposal.id === id && actionProposalScopeMatches(row.proposal, scope) ? row : void 0;
@@ -1614,7 +1651,10 @@ var DrizzleActionProposalStore = class {
1614
1651
  ...discoveryMetadata(result.proposal),
1615
1652
  version: row2.version + 1
1616
1653
  }).where(and(eq(this.table.id, physicalId(id)), eq(this.table.scopeKey, scopeKey(scope)), eq(this.table.version, row2.version))), this.table.id);
1617
- if (changed === 1) return result;
1654
+ if (changed === 1) {
1655
+ await this.toolCallSettlement(this.db, row2.proposal, result.proposal);
1656
+ return result;
1657
+ }
1618
1658
  }
1619
1659
  const row = await this.read(scope, id);
1620
1660
  return row ? {
@@ -2614,6 +2654,7 @@ import { and as and3, asc as asc3, count, desc as desc2, eq as eq3, gte as gte2,
2614
2654
  var UNCLASSIFIED_ERROR_CODE = "unknown";
2615
2655
  var DEFAULT_AGENT_BUCKET = "(default)";
2616
2656
  var TOOL_CALL_STATUSES = [
2657
+ "proposed",
2617
2658
  "auto_executed",
2618
2659
  "pending_approval",
2619
2660
  "executed",