@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.cjs CHANGED
@@ -1398,6 +1398,11 @@ var DrizzleActionProposalStore = class {
1398
1398
  })
1399
1399
  };
1400
1400
  if ((this.dialect === "mysql" ? mysqlAffectedRows(updated) : updated.length) !== 1) throw new Error("Replacement lost its locked proposal fence");
1401
+ const settled = this.toolCallSettlement(db, old.proposal, next);
1402
+ if (settled) yield {
1403
+ kind: "write",
1404
+ query: settled
1405
+ };
1401
1406
  }
1402
1407
  return {
1403
1408
  status: "created",
@@ -1650,6 +1655,38 @@ var DrizzleActionProposalStore = class {
1650
1655
  messageId
1651
1656
  };
1652
1657
  }
1658
+ /**
1659
+ * The update that settles the proposal's `proposed` tool-call record after a transition from
1660
+ * `previous` to `next` (see `toolCallUpdateForTransition`), or `undefined` when its status stays —
1661
+ * so the dashboard and run detail show `executed` / `failed` / `rejected` / `expired` instead of
1662
+ * `proposed` forever.
1663
+ */
1664
+ toolCallSettlement(db, previous, next) {
1665
+ const update = (0, import_nestjs_agent_core3.toolCallUpdateForTransition)(previous, next);
1666
+ if (update === null) return void 0;
1667
+ const toolCall = agentTablesFor(this.dialect).agentToolCall;
1668
+ return db.update(toolCall).set({
1669
+ status: update.status,
1670
+ ...update.output !== void 0 ? {
1671
+ output: update.output
1672
+ } : {},
1673
+ ...update.error !== void 0 ? {
1674
+ error: update.error
1675
+ } : {},
1676
+ ...update.executedByRef !== void 0 ? {
1677
+ executedByRef: update.executedByRef
1678
+ } : {},
1679
+ ...update.decidedVia !== void 0 ? {
1680
+ decidedVia: update.decidedVia
1681
+ } : {},
1682
+ ...update.remember !== void 0 ? {
1683
+ remember: update.remember
1684
+ } : {},
1685
+ ...update.status === "executed" ? {
1686
+ executedAt: new Date(this.clock())
1687
+ } : {}
1688
+ }).where((0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(toolCall.id, update.toolCallId), (0, import_drizzle_orm3.eq)(toolCall.proposalId, next.id)));
1689
+ }
1653
1690
  async read(scope, id) {
1654
1691
  const [row] = await this.db.select().from(this.table).where((0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(this.table.id, physicalId(id)), (0, import_drizzle_orm3.eq)(this.table.scopeKey, scopeKey(scope)))).limit(1);
1655
1692
  return row && row.proposal.id === id && (0, import_nestjs_agent_core3.actionProposalScopeMatches)(row.proposal, scope) ? row : void 0;
@@ -1668,7 +1705,10 @@ var DrizzleActionProposalStore = class {
1668
1705
  ...discoveryMetadata(result.proposal),
1669
1706
  version: row2.version + 1
1670
1707
  }).where((0, import_drizzle_orm3.and)((0, import_drizzle_orm3.eq)(this.table.id, physicalId(id)), (0, import_drizzle_orm3.eq)(this.table.scopeKey, scopeKey(scope)), (0, import_drizzle_orm3.eq)(this.table.version, row2.version))), this.table.id);
1671
- if (changed === 1) return result;
1708
+ if (changed === 1) {
1709
+ await this.toolCallSettlement(this.db, row2.proposal, result.proposal);
1710
+ return result;
1711
+ }
1672
1712
  }
1673
1713
  const row = await this.read(scope, id);
1674
1714
  return row ? {
@@ -2668,6 +2708,7 @@ var import_drizzle_orm5 = require("drizzle-orm");
2668
2708
  var UNCLASSIFIED_ERROR_CODE = "unknown";
2669
2709
  var DEFAULT_AGENT_BUCKET = "(default)";
2670
2710
  var TOOL_CALL_STATUSES = [
2711
+ "proposed",
2671
2712
  "auto_executed",
2672
2713
  "pending_approval",
2673
2714
  "executed",