@dudousxd/nestjs-agent-core 0.40.0 → 0.41.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.
Files changed (36) hide show
  1. package/README.md +7 -0
  2. package/dist/ag-ui/index.cjs +46 -10
  3. package/dist/ag-ui/index.cjs.map +1 -1
  4. package/dist/ag-ui/index.d.cts +9 -3
  5. package/dist/ag-ui/index.d.ts +9 -3
  6. package/dist/ag-ui/index.js +46 -10
  7. package/dist/ag-ui/index.js.map +1 -1
  8. package/dist/{catalog-CrzetM3_.d.cts → catalog-BKS3Yxo6.d.cts} +2 -0
  9. package/dist/{catalog-CrzetM3_.d.ts → catalog-BKS3Yxo6.d.ts} +2 -0
  10. package/dist/genui/builtins.cjs.map +1 -1
  11. package/dist/genui/builtins.d.cts +1 -1
  12. package/dist/genui/builtins.d.ts +1 -1
  13. package/dist/genui/builtins.js.map +1 -1
  14. package/dist/genui/index.cjs +660 -68
  15. package/dist/genui/index.cjs.map +1 -1
  16. package/dist/genui/index.d.cts +5 -5
  17. package/dist/genui/index.d.ts +5 -5
  18. package/dist/genui/index.js +654 -68
  19. package/dist/genui/index.js.map +1 -1
  20. package/dist/guardrails/index.cjs +3 -1
  21. package/dist/guardrails/index.cjs.map +1 -1
  22. package/dist/guardrails/index.d.cts +5 -4
  23. package/dist/guardrails/index.d.ts +5 -4
  24. package/dist/guardrails/index.js +3 -1
  25. package/dist/guardrails/index.js.map +1 -1
  26. package/dist/index.cjs +1161 -421
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +118 -13
  29. package/dist/index.d.ts +118 -13
  30. package/dist/index.js +1153 -421
  31. package/dist/index.js.map +1 -1
  32. package/dist/{processors-B7nfbU6E.d.cts → processors-BXM-MNga.d.cts} +1 -1
  33. package/dist/{processors-BR3nICcp.d.ts → processors-ByDr5POu.d.ts} +1 -1
  34. package/dist/{stream-events-DAmes2Of.d.ts → stream-events-BGKLD6RX.d.ts} +73 -4
  35. package/dist/{stream-events-M0jc7lSW.d.cts → stream-events-CF-6-Y6L.d.cts} +73 -4
  36. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -528,37 +528,37 @@ async function mayDecideApproval(policy, actor, decision) {
528
528
  return defaultCanDecide(actor, decision);
529
529
  }
530
530
  __name(mayDecideApproval, "mayDecideApproval");
531
- function toolCallApprovalFromRow(row) {
532
- if (row.approver === null || row.approver === void 0) {
531
+ function toolCallApprovalFromRow(row2) {
532
+ if (row2.approver === null || row2.approver === void 0) {
533
533
  return null;
534
534
  }
535
- const status = row.status === "pending_approval" || row.status === "proposed" ? "pending" : row.status === "rejected" ? "rejected" : row.status === "expired" ? "expired" : "approved";
536
- const expiresAt = row.expiresAt instanceof Date ? row.expiresAt.toISOString() : typeof row.expiresAt === "string" ? row.expiresAt : void 0;
535
+ const status = row2.status === "pending_approval" || row2.status === "proposed" ? "pending" : row2.status === "rejected" ? "rejected" : row2.status === "expired" ? "expired" : "approved";
536
+ const expiresAt = row2.expiresAt instanceof Date ? row2.expiresAt.toISOString() : typeof row2.expiresAt === "string" ? row2.expiresAt : void 0;
537
537
  const decided = status === "approved" || status === "rejected";
538
538
  return {
539
- toolCallId: row.toolCallId,
540
- ...row.proposalId != null ? {
541
- proposalId: row.proposalId
539
+ toolCallId: row2.toolCallId,
540
+ ...row2.proposalId != null ? {
541
+ proposalId: row2.proposalId
542
542
  } : {},
543
- approver: row.approver,
544
- ...row.confirmation != null ? {
545
- confirmation: row.confirmation
543
+ approver: row2.approver,
544
+ ...row2.confirmation != null ? {
545
+ confirmation: row2.confirmation
546
546
  } : {},
547
547
  status,
548
548
  ...expiresAt !== void 0 ? {
549
549
  expiresAt
550
550
  } : {},
551
- ...row.remember === true ? {
551
+ ...row2.remember === true ? {
552
552
  remember: true
553
553
  } : {},
554
- ...decided && typeof row.executedByRef === "string" ? {
555
- decidedBy: row.executedByRef
554
+ ...decided && typeof row2.executedByRef === "string" ? {
555
+ decidedBy: row2.executedByRef
556
556
  } : {},
557
- ...decided && typeof row.decidedVia === "string" ? {
558
- decidedVia: row.decidedVia
557
+ ...decided && typeof row2.decidedVia === "string" ? {
558
+ decidedVia: row2.decidedVia
559
559
  } : {},
560
- ...status === "rejected" && typeof row.error === "string" ? {
561
- reason: row.error
560
+ ...status === "rejected" && typeof row2.error === "string" ? {
561
+ reason: row2.error
562
562
  } : {}
563
563
  };
564
564
  }
@@ -575,24 +575,24 @@ function estimateCost(usage, price) {
575
575
  return uncachedInputTokens / 1e6 * price.inputPricePer1m + cacheWriteTokens / 1e6 * (price.cacheWritePricePer1m ?? price.inputPricePer1m) + cacheReadTokens / 1e6 * (price.cacheReadPricePer1m ?? price.inputPricePer1m) + usage.outputTokens / 1e6 * price.outputPricePer1m;
576
576
  }
577
577
  __name(estimateCost, "estimateCost");
578
- function rowCost(row, prices) {
579
- return row.costUsd ?? estimateCost(row, prices.get(row.modelId));
578
+ function rowCost(row2, prices) {
579
+ return row2.costUsd ?? estimateCost(row2, prices.get(row2.modelId));
580
580
  }
581
581
  __name(rowCost, "rowCost");
582
582
  function bucketByModel(rows, prices) {
583
583
  const byModel = /* @__PURE__ */ new Map();
584
- for (const row of rows) {
585
- const bucket = byModel.get(row.modelId) ?? {
584
+ for (const row2 of rows) {
585
+ const bucket = byModel.get(row2.modelId) ?? {
586
586
  requests: 0,
587
587
  inputTokens: 0,
588
588
  outputTokens: 0,
589
589
  costUsd: 0
590
590
  };
591
591
  bucket.requests += 1;
592
- bucket.inputTokens += row.inputTokens;
593
- bucket.outputTokens += row.outputTokens;
594
- bucket.costUsd += rowCost(row, prices);
595
- byModel.set(row.modelId, bucket);
592
+ bucket.inputTokens += row2.inputTokens;
593
+ bucket.outputTokens += row2.outputTokens;
594
+ bucket.costUsd += rowCost(row2, prices);
595
+ byModel.set(row2.modelId, bucket);
596
596
  }
597
597
  const result2 = [];
598
598
  for (const [modelId, bucket] of byModel) {
@@ -610,18 +610,18 @@ function bucketByModel(rows, prices) {
610
610
  __name(bucketByModel, "bucketByModel");
611
611
  function bucketByActor(rows, prices) {
612
612
  const byActor = /* @__PURE__ */ new Map();
613
- for (const row of rows) {
614
- const bucket = byActor.get(row.actorRef) ?? {
613
+ for (const row2 of rows) {
614
+ const bucket = byActor.get(row2.actorRef) ?? {
615
615
  requests: 0,
616
616
  totalTokens: 0,
617
617
  costUsd: 0,
618
618
  threadIds: /* @__PURE__ */ new Set()
619
619
  };
620
620
  bucket.requests += 1;
621
- bucket.totalTokens += row.inputTokens + row.outputTokens;
622
- bucket.costUsd += rowCost(row, prices);
623
- bucket.threadIds.add(row.threadId);
624
- byActor.set(row.actorRef, bucket);
621
+ bucket.totalTokens += row2.inputTokens + row2.outputTokens;
622
+ bucket.costUsd += rowCost(row2, prices);
623
+ bucket.threadIds.add(row2.threadId);
624
+ byActor.set(row2.actorRef, bucket);
625
625
  }
626
626
  const result2 = [];
627
627
  for (const [actorRef, bucket] of byActor) {
@@ -639,16 +639,16 @@ function bucketByActor(rows, prices) {
639
639
  __name(bucketByActor, "bucketByActor");
640
640
  function bucketByThread(rows, prices, threads, options) {
641
641
  const byThread = /* @__PURE__ */ new Map();
642
- for (const row of rows) {
643
- const bucket = byThread.get(row.threadId) ?? {
642
+ for (const row2 of rows) {
643
+ const bucket = byThread.get(row2.threadId) ?? {
644
644
  requests: 0,
645
645
  totalTokens: 0,
646
646
  costUsd: 0
647
647
  };
648
648
  bucket.requests += 1;
649
- bucket.totalTokens += row.inputTokens + row.outputTokens;
650
- bucket.costUsd += rowCost(row, prices);
651
- byThread.set(row.threadId, bucket);
649
+ bucket.totalTokens += row2.inputTokens + row2.outputTokens;
650
+ bucket.costUsd += rowCost(row2, prices);
651
+ byThread.set(row2.threadId, bucket);
652
652
  }
653
653
  const result2 = [];
654
654
  for (const [threadId, bucket] of byThread) {
@@ -677,26 +677,26 @@ function rollupThreadUsage(rows, prices) {
677
677
  totalTokens: 0,
678
678
  costUsd: 0
679
679
  };
680
- for (const row of rows) {
680
+ for (const row2 of rows) {
681
681
  rollup.requests += 1;
682
- rollup.inputTokens += row.inputTokens;
683
- rollup.outputTokens += row.outputTokens;
684
- rollup.totalTokens += row.inputTokens + row.outputTokens;
685
- rollup.costUsd += rowCost(row, prices);
682
+ rollup.inputTokens += row2.inputTokens;
683
+ rollup.outputTokens += row2.outputTokens;
684
+ rollup.totalTokens += row2.inputTokens + row2.outputTokens;
685
+ rollup.costUsd += rowCost(row2, prices);
686
686
  }
687
687
  return rollup;
688
688
  }
689
689
  __name(rollupThreadUsage, "rollupThreadUsage");
690
690
  function bucketUsageTrend(rows, prices) {
691
691
  const byDay = /* @__PURE__ */ new Map();
692
- for (const row of rows) {
693
- const bucket = byDay.get(row.day) ?? {
692
+ for (const row2 of rows) {
693
+ const bucket = byDay.get(row2.day) ?? {
694
694
  totalTokens: 0,
695
695
  costUsd: 0
696
696
  };
697
- bucket.totalTokens += row.inputTokens + row.outputTokens;
698
- bucket.costUsd += rowCost(row, prices);
699
- byDay.set(row.day, bucket);
697
+ bucket.totalTokens += row2.inputTokens + row2.outputTokens;
698
+ bucket.costUsd += rowCost(row2, prices);
699
+ byDay.set(row2.day, bucket);
700
700
  }
701
701
  const result2 = [];
702
702
  for (const [day, bucket] of byDay) {
@@ -732,7 +732,7 @@ async function filterToolsByEnabled(entries) {
732
732
  entry,
733
733
  enabled: await isToolEnabled(entry.spec, entry.handler)
734
734
  })));
735
- return checked.filter((row) => row.enabled).map((row) => row.entry);
735
+ return checked.filter((row2) => row2.enabled).map((row2) => row2.entry);
736
736
  }
737
737
  __name(filterToolsByEnabled, "filterToolsByEnabled");
738
738
  async function canActorUseTool(actor, handler) {
@@ -744,7 +744,7 @@ async function filterToolsByCanUse(entries, actor) {
744
744
  entry,
745
745
  allowed: await canActorUseTool(actor, entry.handler)
746
746
  })));
747
- return checked.filter((row) => row.allowed).map((row) => row.entry);
747
+ return checked.filter((row2) => row2.allowed).map((row2) => row2.entry);
748
748
  }
749
749
  __name(filterToolsByCanUse, "filterToolsByCanUse");
750
750
  async function filterToolsByRole(tools, actor, policy) {
@@ -2644,20 +2644,20 @@ function validateActionProposalDiscoveryIndexBatch(command) {
2644
2644
  __name(validateActionProposalDiscoveryIndexBatch, "validateActionProposalDiscoveryIndexBatch");
2645
2645
 
2646
2646
  // src/action-proposal-outcome.ts
2647
- function attachActionProposalOutcome(row, now, ui = [], text) {
2648
- if (row.outcome) return row;
2649
- const execution = row.execution;
2647
+ function attachActionProposalOutcome(row2, now, ui = [], text) {
2648
+ if (row2.outcome) return row2;
2649
+ const execution = row2.execution;
2650
2650
  const outcome = {
2651
- id: `${row.id}:outcome:1`,
2652
- proposalId: row.id,
2651
+ id: `${row2.id}:outcome:1`,
2652
+ proposalId: row2.id,
2653
2653
  outcomeVersion: 1,
2654
- tenantRef: row.tenantRef,
2655
- actorRef: row.actorRef,
2656
- threadId: row.threadId,
2657
- originRunId: row.originRunId,
2658
- originToolCallId: row.originToolCallId,
2659
- toolName: row.toolName,
2660
- decision: row.decision,
2654
+ tenantRef: row2.tenantRef,
2655
+ actorRef: row2.actorRef,
2656
+ threadId: row2.threadId,
2657
+ originRunId: row2.originRunId,
2658
+ originToolCallId: row2.originToolCallId,
2659
+ toolName: row2.toolName,
2660
+ decision: row2.decision,
2661
2661
  ui,
2662
2662
  createdAt: now,
2663
2663
  ...text !== void 0 ? {
@@ -2671,12 +2671,12 @@ function attachActionProposalOutcome(row, now, ui = [], text) {
2671
2671
  } : {},
2672
2672
  ...execution?.error !== void 0 ? {
2673
2673
  error: execution.error
2674
- } : row.decisionAudit?.reason !== void 0 ? {
2675
- error: row.decisionAudit.reason
2674
+ } : row2.decisionAudit?.reason !== void 0 ? {
2675
+ error: row2.decisionAudit.reason
2676
2676
  } : {}
2677
2677
  };
2678
2678
  return snapshotActionProposal({
2679
- ...row,
2679
+ ...row2,
2680
2680
  outcome,
2681
2681
  outcomeDelivery: {
2682
2682
  status: "pending",
@@ -2686,13 +2686,13 @@ function attachActionProposalOutcome(row, now, ui = [], text) {
2686
2686
  });
2687
2687
  }
2688
2688
  __name(attachActionProposalOutcome, "attachActionProposalOutcome");
2689
- function claimActionProposalOutcome(row, command, now, token) {
2689
+ function claimActionProposalOutcome(row2, command, now, token) {
2690
2690
  validateActionProposalWorkerClaim(command, now);
2691
- const delivery = row.outcomeDelivery;
2692
- if (!row.outcome || !delivery || delivery.status !== "pending" || delivery.lease && now < delivery.lease.expiresAt) return null;
2691
+ const delivery = row2.outcomeDelivery;
2692
+ if (!row2.outcome || !delivery || delivery.status !== "pending" || delivery.lease && now < delivery.lease.expiresAt) return null;
2693
2693
  const generation = delivery.generation + 1;
2694
2694
  return snapshotActionProposal({
2695
- ...row,
2695
+ ...row2,
2696
2696
  outcomeDelivery: {
2697
2697
  ...delivery,
2698
2698
  generation,
@@ -2706,11 +2706,11 @@ function claimActionProposalOutcome(row, command, now, token) {
2706
2706
  });
2707
2707
  }
2708
2708
  __name(claimActionProposalOutcome, "claimActionProposalOutcome");
2709
- function actionProposalOutcomeFenceValid(row, command, now) {
2709
+ function actionProposalOutcomeFenceValid(row2, command, now) {
2710
2710
  if (!Number.isSafeInteger(now)) throw new RangeError("Invalid server clock");
2711
2711
  if (typeof command.token !== "string" || !command.token || !Number.isSafeInteger(command.generation) || command.generation < 1 || typeof command.outcomeId !== "string" || !command.outcomeId) throw new TypeError("Invalid outcome fence");
2712
- const delivery = row.outcomeDelivery;
2713
- return row.outcome?.id === command.outcomeId && delivery?.status === "pending" && delivery.generation === command.generation && delivery.lease?.token === command.token && delivery.lease.generation === command.generation && now < delivery.lease.expiresAt;
2712
+ const delivery = row2.outcomeDelivery;
2713
+ return row2.outcome?.id === command.outcomeId && delivery?.status === "pending" && delivery.generation === command.generation && delivery.lease?.token === command.token && delivery.lease.generation === command.generation && now < delivery.lease.expiresAt;
2714
2714
  }
2715
2715
  __name(actionProposalOutcomeFenceValid, "actionProposalOutcomeFenceValid");
2716
2716
  function outcomeSummary(outcome) {
@@ -2885,21 +2885,21 @@ function check(schema, value, path, root, issues, depth) {
2885
2885
  });
2886
2886
  return;
2887
2887
  }
2888
- const s = schema;
2889
- if (typeof s.$ref === "string") {
2890
- const target = resolveRef(root, s.$ref);
2888
+ const s2 = schema;
2889
+ if (typeof s2.$ref === "string") {
2890
+ const target = resolveRef(root, s2.$ref);
2891
2891
  if (target === void 0) {
2892
2892
  issues.push({
2893
2893
  path,
2894
- message: `references unknown schema ${s.$ref}`
2894
+ message: `references unknown schema ${s2.$ref}`
2895
2895
  });
2896
2896
  return;
2897
2897
  }
2898
2898
  check(target, value, path, root, issues, depth + 1);
2899
2899
  }
2900
- if (s.type !== void 0) {
2901
- const types = Array.isArray(s.type) ? s.type : [
2902
- s.type
2900
+ if (s2.type !== void 0) {
2901
+ const types = Array.isArray(s2.type) ? s2.type : [
2902
+ s2.type
2903
2903
  ];
2904
2904
  if (!types.some((type) => matchesType(type, value))) {
2905
2905
  issues.push({
@@ -2909,76 +2909,76 @@ function check(schema, value, path, root, issues, depth) {
2909
2909
  return;
2910
2910
  }
2911
2911
  }
2912
- if (Array.isArray(s.enum) && !s.enum.some((option) => deepEqual(option, value))) {
2912
+ if (Array.isArray(s2.enum) && !s2.enum.some((option) => deepEqual(option, value))) {
2913
2913
  issues.push({
2914
2914
  path,
2915
- message: `must be one of ${s.enum.map((option) => JSON.stringify(option)).join(", ")}`
2915
+ message: `must be one of ${s2.enum.map((option) => JSON.stringify(option)).join(", ")}`
2916
2916
  });
2917
2917
  }
2918
- if ("const" in s && !deepEqual(s.const, value)) {
2918
+ if ("const" in s2 && !deepEqual(s2.const, value)) {
2919
2919
  issues.push({
2920
2920
  path,
2921
- message: `must be ${JSON.stringify(s.const)}`
2921
+ message: `must be ${JSON.stringify(s2.const)}`
2922
2922
  });
2923
2923
  }
2924
2924
  if (typeof value === "string") {
2925
- if (typeof s.minLength === "number" && value.length < s.minLength) {
2925
+ if (typeof s2.minLength === "number" && value.length < s2.minLength) {
2926
2926
  issues.push({
2927
2927
  path,
2928
- message: `must be at least ${s.minLength} characters`
2928
+ message: `must be at least ${s2.minLength} characters`
2929
2929
  });
2930
2930
  }
2931
- if (typeof s.maxLength === "number" && value.length > s.maxLength) {
2931
+ if (typeof s2.maxLength === "number" && value.length > s2.maxLength) {
2932
2932
  issues.push({
2933
2933
  path,
2934
- message: `must be at most ${s.maxLength} characters`
2934
+ message: `must be at most ${s2.maxLength} characters`
2935
2935
  });
2936
2936
  }
2937
- if (typeof s.pattern === "string") {
2937
+ if (typeof s2.pattern === "string") {
2938
2938
  let pattern;
2939
2939
  try {
2940
- pattern = new RegExp(s.pattern, "u");
2940
+ pattern = new RegExp(s2.pattern, "u");
2941
2941
  } catch {
2942
2942
  pattern = void 0;
2943
2943
  }
2944
2944
  if (pattern !== void 0 && !pattern.test(value)) {
2945
2945
  issues.push({
2946
2946
  path,
2947
- message: `must match ${s.pattern}`
2947
+ message: `must match ${s2.pattern}`
2948
2948
  });
2949
2949
  }
2950
2950
  }
2951
2951
  }
2952
2952
  if (typeof value === "number") {
2953
- if (typeof s.minimum === "number" && value < s.minimum) {
2953
+ if (typeof s2.minimum === "number" && value < s2.minimum) {
2954
2954
  issues.push({
2955
2955
  path,
2956
- message: `must be >= ${s.minimum}`
2956
+ message: `must be >= ${s2.minimum}`
2957
2957
  });
2958
2958
  }
2959
- if (typeof s.maximum === "number" && value > s.maximum) {
2959
+ if (typeof s2.maximum === "number" && value > s2.maximum) {
2960
2960
  issues.push({
2961
2961
  path,
2962
- message: `must be <= ${s.maximum}`
2962
+ message: `must be <= ${s2.maximum}`
2963
2963
  });
2964
2964
  }
2965
2965
  }
2966
2966
  if (Array.isArray(value)) {
2967
- if (typeof s.minItems === "number" && value.length < s.minItems) {
2967
+ if (typeof s2.minItems === "number" && value.length < s2.minItems) {
2968
2968
  issues.push({
2969
2969
  path,
2970
- message: `must have at least ${s.minItems} items`
2970
+ message: `must have at least ${s2.minItems} items`
2971
2971
  });
2972
2972
  }
2973
- if (typeof s.maxItems === "number" && value.length > s.maxItems) {
2973
+ if (typeof s2.maxItems === "number" && value.length > s2.maxItems) {
2974
2974
  issues.push({
2975
2975
  path,
2976
- message: `must have at most ${s.maxItems} items`
2976
+ message: `must have at most ${s2.maxItems} items`
2977
2977
  });
2978
2978
  }
2979
- if (s.items !== void 0 && !Array.isArray(s.items)) {
2979
+ if (s2.items !== void 0 && !Array.isArray(s2.items)) {
2980
2980
  value.forEach((item, index) => {
2981
- check(s.items, item, [
2981
+ check(s2.items, item, [
2982
2982
  ...path,
2983
2983
  index
2984
2984
  ], root, issues, depth + 1);
@@ -2987,9 +2987,9 @@ function check(schema, value, path, root, issues, depth) {
2987
2987
  }
2988
2988
  if (matchesType("object", value)) {
2989
2989
  const record2 = value;
2990
- const properties = typeof s.properties === "object" && s.properties !== null ? s.properties : {};
2991
- if (Array.isArray(s.required)) {
2992
- for (const key of s.required) {
2990
+ const properties = typeof s2.properties === "object" && s2.properties !== null ? s2.properties : {};
2991
+ if (Array.isArray(s2.required)) {
2992
+ for (const key of s2.required) {
2993
2993
  if (record2[key] === void 0) {
2994
2994
  issues.push({
2995
2995
  path: [
@@ -3009,7 +3009,7 @@ function check(schema, value, path, root, issues, depth) {
3009
3009
  key
3010
3010
  ], root, issues, depth + 1);
3011
3011
  }
3012
- } else if (s.additionalProperties === false) {
3012
+ } else if (s2.additionalProperties === false) {
3013
3013
  issues.push({
3014
3014
  path: [
3015
3015
  ...path,
@@ -3017,34 +3017,34 @@ function check(schema, value, path, root, issues, depth) {
3017
3017
  ],
3018
3018
  message: "is not a known property"
3019
3019
  });
3020
- } else if (typeof s.additionalProperties === "object" && s.additionalProperties !== null) {
3021
- check(s.additionalProperties, entry, [
3020
+ } else if (typeof s2.additionalProperties === "object" && s2.additionalProperties !== null) {
3021
+ check(s2.additionalProperties, entry, [
3022
3022
  ...path,
3023
3023
  key
3024
3024
  ], root, issues, depth + 1);
3025
3025
  }
3026
3026
  }
3027
3027
  }
3028
- if (Array.isArray(s.allOf)) {
3029
- for (const sub of s.allOf) check(sub, value, path, root, issues, depth + 1);
3028
+ if (Array.isArray(s2.allOf)) {
3029
+ for (const sub of s2.allOf) check(sub, value, path, root, issues, depth + 1);
3030
3030
  }
3031
- if (Array.isArray(s.anyOf) || Array.isArray(s.oneOf)) {
3032
- const options = Array.isArray(s.anyOf) ? s.anyOf : s.oneOf;
3031
+ if (Array.isArray(s2.anyOf) || Array.isArray(s2.oneOf)) {
3032
+ const options = Array.isArray(s2.anyOf) ? s2.anyOf : s2.oneOf;
3033
3033
  const passing = options.filter((sub) => {
3034
3034
  const nested = [];
3035
3035
  check(sub, value, path, root, nested, depth + 1);
3036
3036
  return nested.length === 0;
3037
3037
  }).length;
3038
- if (Array.isArray(s.anyOf) ? passing === 0 : passing !== 1) {
3038
+ if (Array.isArray(s2.anyOf) ? passing === 0 : passing !== 1) {
3039
3039
  issues.push({
3040
3040
  path,
3041
- message: Array.isArray(s.anyOf) ? "does not match any allowed shape" : "must match exactly one allowed shape"
3041
+ message: Array.isArray(s2.anyOf) ? "does not match any allowed shape" : "must match exactly one allowed shape"
3042
3042
  });
3043
3043
  }
3044
3044
  }
3045
- if (s.not !== void 0) {
3045
+ if (s2.not !== void 0) {
3046
3046
  const nested = [];
3047
- check(s.not, value, path, root, nested, depth + 1);
3047
+ check(s2.not, value, path, root, nested, depth + 1);
3048
3048
  if (nested.length === 0) {
3049
3049
  issues.push({
3050
3050
  path,
@@ -3101,7 +3101,7 @@ function buildCatalog(byName, validator) {
3101
3101
  ]
3102
3102
  };
3103
3103
  }
3104
- const result2 = await validateProps(definition.props, props, validator);
3104
+ const result2 = await validateProps(definition.outputProps ?? definition.props, props, validator);
3105
3105
  return result2;
3106
3106
  },
3107
3107
  validateSync(component, props) {
@@ -3117,11 +3117,11 @@ function buildCatalog(byName, validator) {
3117
3117
  ]
3118
3118
  };
3119
3119
  }
3120
- return validatePropsSync(definition.props, props, validator);
3120
+ return validatePropsSync(definition.outputProps ?? definition.props, props, validator);
3121
3121
  },
3122
3122
  jsonSchemaFor(component) {
3123
3123
  const definition = byName.get(component);
3124
- return definition === void 0 ? void 0 : toJsonSchema(definition.props);
3124
+ return definition === void 0 ? void 0 : toJsonSchema(definition.outputProps ?? definition.props);
3125
3125
  },
3126
3126
  extend(more) {
3127
3127
  const next = new Map(byName);
@@ -3137,7 +3137,7 @@ __name(buildCatalog, "buildCatalog");
3137
3137
 
3138
3138
  // src/genui/tree.ts
3139
3139
  var GENUI_TREE_COMPONENT = "genui:tree";
3140
- async function validateTree(catalog, tree, limits = {}) {
3140
+ async function validateTree(catalog, tree, limits = {}, phase = "output") {
3141
3141
  const maxDepth = limits.maxDepth ?? 12;
3142
3142
  const maxNodes = limits.maxNodes ?? 200;
3143
3143
  const issues = [];
@@ -3189,7 +3189,7 @@ async function validateTree(catalog, tree, limits = {}) {
3189
3189
  });
3190
3190
  return void 0;
3191
3191
  }
3192
- const validated = await catalog.validate(element.type, element.props ?? {});
3192
+ const validated = phase === "input" ? await validateProps(definition.props, element.props ?? {}, catalog.validator) : await catalog.validate(element.type, element.props ?? {});
3193
3193
  let props = {};
3194
3194
  if (!validated.ok) {
3195
3195
  for (const issue4 of validated.issues) {
@@ -3549,8 +3549,8 @@ function snapshotActionProposal(value) {
3549
3549
  return JSON.parse(canonicalActionProposalJson(value));
3550
3550
  }
3551
3551
  __name(snapshotActionProposal, "snapshotActionProposal");
3552
- function actionProposalScopeMatches(row, scope) {
3553
- return row.tenantRef === scope.tenantRef && row.actorRef === scope.actorRef && row.threadId === scope.threadId;
3552
+ function actionProposalScopeMatches(row2, scope) {
3553
+ return row2.tenantRef === scope.tenantRef && row2.actorRef === scope.actorRef && row2.threadId === scope.threadId;
3554
3554
  }
3555
3555
  __name(actionProposalScopeMatches, "actionProposalScopeMatches");
3556
3556
  function initialActionProposal(input, now) {
@@ -3566,9 +3566,9 @@ function initialActionProposal(input, now) {
3566
3566
  });
3567
3567
  }
3568
3568
  __name(initialActionProposal, "initialActionProposal");
3569
- function actionProposalCreationMatches(row, input) {
3569
+ function actionProposalCreationMatches(row2, input) {
3570
3570
  validateActionProposalCreation(input);
3571
- const { decision: _decision, decisionAudit: _audit, execution: _execution, createdAt: _created, updatedAt: _updated, supersededBy: _supersededBy, outcome: _outcome, outcomeDelivery: _delivery, ...original } = row;
3571
+ const { decision: _decision, decisionAudit: _audit, execution: _execution, createdAt: _created, updatedAt: _updated, supersededBy: _supersededBy, outcome: _outcome, outcomeDelivery: _delivery, ...original } = row2;
3572
3572
  return canonicalActionProposalJson(original) === canonicalActionProposalJson(input);
3573
3573
  }
3574
3574
  __name(actionProposalCreationMatches, "actionProposalCreationMatches");
@@ -3579,7 +3579,7 @@ function result(status, proposal) {
3579
3579
  };
3580
3580
  }
3581
3581
  __name(result, "result");
3582
- function transitionActionProposalDecision(row, command, now) {
3582
+ function transitionActionProposalDecision(row2, command, now) {
3583
3583
  checkTime(now);
3584
3584
  if (![
3585
3585
  "approved",
@@ -3590,11 +3590,11 @@ function transitionActionProposalDecision(row, command, now) {
3590
3590
  checkString(command.via);
3591
3591
  if (command.reason !== void 0 && typeof command.reason !== "string") throw new TypeError("reason must be a string");
3592
3592
  if (command.remember !== void 0 && typeof command.remember !== "boolean") throw new TypeError("remember must be a boolean");
3593
- if (row.decision !== "pending") {
3594
- return result(row.decision === command.decision ? "unchanged" : row.decision === "expired" ? "expired" : "conflict", row);
3593
+ if (row2.decision !== "pending") {
3594
+ return result(row2.decision === command.decision ? "unchanged" : row2.decision === "expired" ? "expired" : "conflict", row2);
3595
3595
  }
3596
- const next = snapshotActionProposal(row);
3597
- if (row.expiresAt !== null && now >= row.expiresAt) {
3596
+ const next = snapshotActionProposal(row2);
3597
+ if (row2.expiresAt !== null && now >= row2.expiresAt) {
3598
3598
  next.decision = "expired";
3599
3599
  next.decisionAudit = {
3600
3600
  actorRef: "system",
@@ -3604,7 +3604,7 @@ function transitionActionProposalDecision(row, command, now) {
3604
3604
  next.updatedAt = now;
3605
3605
  return result(command.decision === "expired" ? "applied" : "expired", attachActionProposalOutcome(next, now));
3606
3606
  }
3607
- if (command.decision === "expired") return result("conflict", row);
3607
+ if (command.decision === "expired") return result("conflict", row2);
3608
3608
  const { decision, ...audit } = command;
3609
3609
  next.decision = decision;
3610
3610
  next.decisionAudit = {
@@ -3632,13 +3632,13 @@ function checkLeaseMs(leaseMs, now) {
3632
3632
  if (!Number.isSafeInteger(leaseMs) || leaseMs <= 0 || !Number.isSafeInteger(now + leaseMs)) throw new RangeError("leaseMs must be finite and positive");
3633
3633
  }
3634
3634
  __name(checkLeaseMs, "checkLeaseMs");
3635
- function transitionActionProposalClaim(row, command, now, token) {
3635
+ function transitionActionProposalClaim(row2, command, now, token) {
3636
3636
  checkLeaseMs(command.leaseMs, now);
3637
3637
  checkString(command.workerId);
3638
3638
  checkString(token);
3639
- const execution = row.execution;
3640
- if (row.decision !== "approved" || !execution || execution.status !== "queued" && !(execution.status === "executing" && execution.lease && now >= execution.lease.expiresAt)) return result("conflict", row);
3641
- const next = snapshotActionProposal(row);
3639
+ const execution = row2.execution;
3640
+ if (row2.decision !== "approved" || !execution || execution.status !== "queued" && !(execution.status === "executing" && execution.lease && now >= execution.lease.expiresAt)) return result("conflict", row2);
3641
+ const next = snapshotActionProposal(row2);
3642
3642
  const generation = execution.generation + 1;
3643
3643
  next.execution = {
3644
3644
  status: "executing",
@@ -3654,32 +3654,32 @@ function transitionActionProposalClaim(row, command, now, token) {
3654
3654
  return result("applied", next);
3655
3655
  }
3656
3656
  __name(transitionActionProposalClaim, "transitionActionProposalClaim");
3657
- function leaseStatus(row, command, now) {
3657
+ function leaseStatus(row2, command, now) {
3658
3658
  checkTime(now);
3659
3659
  checkString(command.token);
3660
3660
  if (!Number.isSafeInteger(command.generation) || command.generation < 1) throw new RangeError("Invalid lease generation");
3661
- const work = row.execution;
3662
- if (row.decision !== "approved" || work?.status !== "executing" || !work.lease || work.generation !== command.generation || work.lease.generation !== command.generation || work.lease.token !== command.token) return "conflict";
3661
+ const work = row2.execution;
3662
+ if (row2.decision !== "approved" || work?.status !== "executing" || !work.lease || work.generation !== command.generation || work.lease.generation !== command.generation || work.lease.token !== command.token) return "conflict";
3663
3663
  return now >= work.lease.expiresAt ? "expired" : "valid";
3664
3664
  }
3665
3665
  __name(leaseStatus, "leaseStatus");
3666
- function transitionActionProposalLease(row, command, now) {
3666
+ function transitionActionProposalLease(row2, command, now) {
3667
3667
  checkLeaseMs(command.leaseMs, now);
3668
- const status = leaseStatus(row, command, now);
3669
- if (status !== "valid") return result(status, row);
3670
- const next = snapshotActionProposal(row);
3668
+ const status = leaseStatus(row2, command, now);
3669
+ if (status !== "valid") return result(status, row2);
3670
+ const next = snapshotActionProposal(row2);
3671
3671
  if (next.execution?.lease) next.execution.lease.expiresAt = Math.max(next.execution.lease.expiresAt, now + command.leaseMs);
3672
3672
  next.updatedAt = now;
3673
3673
  return result("applied", next);
3674
3674
  }
3675
3675
  __name(transitionActionProposalLease, "transitionActionProposalLease");
3676
- function transitionActionProposalSettlement(row, command, now) {
3676
+ function transitionActionProposalSettlement(row2, command, now) {
3677
3677
  checkTime(now);
3678
3678
  if (command.status !== "succeeded" && command.status !== "failed") throw new TypeError("Unsupported settlement status");
3679
3679
  if (command.status === "succeeded" && command.error !== void 0 || command.status === "failed" && (typeof command.error !== "string" || command.result !== void 0)) throw new TypeError("Ambiguous action proposal settlement");
3680
- const status = leaseStatus(row, command, now);
3681
- if (status !== "valid") return result(status, row);
3682
- const next = snapshotActionProposal(row);
3680
+ const status = leaseStatus(row2, command, now);
3681
+ if (status !== "valid") return result(status, row2);
3682
+ const next = snapshotActionProposal(row2);
3683
3683
  next.execution = command.status === "succeeded" ? {
3684
3684
  status: "succeeded",
3685
3685
  generation: command.generation,
@@ -3699,16 +3699,16 @@ function transitionActionProposalSettlement(row, command, now) {
3699
3699
  return result("applied", attachActionProposalOutcome(next, now, command.ui, command.text));
3700
3700
  }
3701
3701
  __name(transitionActionProposalSettlement, "transitionActionProposalSettlement");
3702
- function transitionActionProposalSupersession(row, replacement, command, now) {
3702
+ function transitionActionProposalSupersession(row2, replacement, command, now) {
3703
3703
  checkTime(now);
3704
3704
  checkString(command.replacementProposalId);
3705
3705
  checkString(command.actorRef);
3706
3706
  checkString(command.via);
3707
- if (replacement.id !== command.replacementProposalId || row.id === replacement.id || !actionProposalScopeMatches(row, replacement) || row.toolName !== replacement.toolName || !row.replacementKey || row.replacementKey !== replacement.replacementKey) return result("conflict", row);
3708
- if (row.decision === "superseded") return result(row.supersededBy === replacement.id ? "unchanged" : "conflict", row);
3709
- if (row.decision !== "pending") return result("conflict", row);
3710
- if (row.expiresAt !== null && now >= row.expiresAt) return {
3711
- ...transitionActionProposalDecision(row, {
3707
+ if (replacement.id !== command.replacementProposalId || row2.id === replacement.id || !actionProposalScopeMatches(row2, replacement) || row2.toolName !== replacement.toolName || !row2.replacementKey || row2.replacementKey !== replacement.replacementKey) return result("conflict", row2);
3708
+ if (row2.decision === "superseded") return result(row2.supersededBy === replacement.id ? "unchanged" : "conflict", row2);
3709
+ if (row2.decision !== "pending") return result("conflict", row2);
3710
+ if (row2.expiresAt !== null && now >= row2.expiresAt) return {
3711
+ ...transitionActionProposalDecision(row2, {
3712
3712
  decision: "expired",
3713
3713
  actorRef: "system",
3714
3714
  via: "expiry"
@@ -3716,7 +3716,7 @@ function transitionActionProposalSupersession(row, replacement, command, now) {
3716
3716
  status: "expired"
3717
3717
  };
3718
3718
  const next = snapshotActionProposal({
3719
- ...row,
3719
+ ...row2,
3720
3720
  decision: "superseded",
3721
3721
  supersededBy: replacement.id,
3722
3722
  decisionAudit: {
@@ -3731,6 +3731,560 @@ function transitionActionProposalSupersession(row, replacement, command, now) {
3731
3731
  }
3732
3732
  __name(transitionActionProposalSupersession, "transitionActionProposalSupersession");
3733
3733
 
3734
+ // src/genui/builtins.ts
3735
+ var str = /* @__PURE__ */ __name((description, extra = {}) => ({
3736
+ type: "string",
3737
+ ...description !== void 0 ? {
3738
+ description
3739
+ } : {},
3740
+ ...extra
3741
+ }), "str");
3742
+ var obj = /* @__PURE__ */ __name((properties, required = []) => ({
3743
+ type: "object",
3744
+ properties,
3745
+ required,
3746
+ additionalProperties: false
3747
+ }), "obj");
3748
+ var arr = /* @__PURE__ */ __name((items, extra = {}) => ({
3749
+ type: "array",
3750
+ items,
3751
+ ...extra
3752
+ }), "arr");
3753
+ var cell = {
3754
+ type: [
3755
+ "string",
3756
+ "number",
3757
+ "boolean",
3758
+ "null"
3759
+ ]
3760
+ };
3761
+ var row = {
3762
+ type: "object",
3763
+ additionalProperties: cell
3764
+ };
3765
+ var s = /* @__PURE__ */ __name((value) => value === null || value === void 0 ? "" : String(value), "s");
3766
+ var heading = /* @__PURE__ */ __name((props) => props.title ? `*${s(props.title)}*
3767
+ ` : "", "heading");
3768
+ function textTable(columns, rows, max = 15) {
3769
+ const shown = rows.slice(0, max);
3770
+ const widths = columns.map((column) => Math.min(28, Math.max(column.label.length, ...shown.map((r) => s(r[column.key]).length))));
3771
+ const format = /* @__PURE__ */ __name((values) => values.map((value, index) => value.slice(0, widths[index]).padEnd(widths[index] ?? 0)).join(" "), "format");
3772
+ const lines = [
3773
+ format(columns.map((column) => column.label)),
3774
+ widths.map((width) => "-".repeat(width)).join(" "),
3775
+ ...shown.map((r) => format(columns.map((column) => s(r[column.key]))))
3776
+ ];
3777
+ if (rows.length > max) lines.push(`\u2026 ${rows.length - max} more rows`);
3778
+ return `\`\`\`
3779
+ ${lines.join("\n")}
3780
+ \`\`\``;
3781
+ }
3782
+ __name(textTable, "textTable");
3783
+ function lineDiff(before, after) {
3784
+ const a = before.split("\n");
3785
+ const b = after.split("\n");
3786
+ if (a.length * b.length > 25e4) {
3787
+ return [
3788
+ ...a.map((text) => ({
3789
+ op: "del",
3790
+ text
3791
+ })),
3792
+ ...b.map((text) => ({
3793
+ op: "add",
3794
+ text
3795
+ }))
3796
+ ];
3797
+ }
3798
+ const dp = Array.from({
3799
+ length: a.length + 1
3800
+ }, () => new Array(b.length + 1).fill(0));
3801
+ const at = /* @__PURE__ */ __name((i2, j2) => dp[i2]?.[j2] ?? 0, "at");
3802
+ for (let i2 = a.length - 1; i2 >= 0; i2--) {
3803
+ for (let j2 = b.length - 1; j2 >= 0; j2--) {
3804
+ dp[i2][j2] = a[i2] === b[j2] ? at(i2 + 1, j2 + 1) + 1 : Math.max(at(i2 + 1, j2), at(i2, j2 + 1));
3805
+ }
3806
+ }
3807
+ const out = [];
3808
+ let i = 0;
3809
+ let j = 0;
3810
+ while (i < a.length && j < b.length) {
3811
+ if (a[i] === b[j]) {
3812
+ out.push({
3813
+ op: "same",
3814
+ text: a[i]
3815
+ });
3816
+ i++;
3817
+ j++;
3818
+ } else if (at(i + 1, j) >= at(i, j + 1)) {
3819
+ out.push({
3820
+ op: "del",
3821
+ text: a[i++]
3822
+ });
3823
+ } else {
3824
+ out.push({
3825
+ op: "add",
3826
+ text: b[j++]
3827
+ });
3828
+ }
3829
+ }
3830
+ while (i < a.length) out.push({
3831
+ op: "del",
3832
+ text: a[i++]
3833
+ });
3834
+ while (j < b.length) out.push({
3835
+ op: "add",
3836
+ text: b[j++]
3837
+ });
3838
+ return out;
3839
+ }
3840
+ __name(lineDiff, "lineDiff");
3841
+ function bar(value, max, width = 20) {
3842
+ const n = max > 0 ? Math.round(Math.abs(value) / max * width) : 0;
3843
+ return "\u2588".repeat(n) || "\u258F";
3844
+ }
3845
+ __name(bar, "bar");
3846
+ var DataTable = defineComponent({
3847
+ name: "DataTable",
3848
+ title: "Data table",
3849
+ description: "Tabular data (records with the same fields) as a sortable table. Prefer it over markdown tables for more than 3 rows.",
3850
+ props: obj({
3851
+ title: str("Short caption"),
3852
+ columns: arr(obj({
3853
+ key: str("Field name in each row"),
3854
+ label: str("Column header"),
3855
+ align: str(void 0, {
3856
+ enum: [
3857
+ "left",
3858
+ "right",
3859
+ "center"
3860
+ ]
3861
+ }),
3862
+ format: str("How to format values", {
3863
+ enum: [
3864
+ "text",
3865
+ "number",
3866
+ "currency",
3867
+ "percent",
3868
+ "date",
3869
+ "link"
3870
+ ]
3871
+ })
3872
+ }, [
3873
+ "key",
3874
+ "label"
3875
+ ]), {
3876
+ minItems: 1,
3877
+ maxItems: 12
3878
+ }),
3879
+ rows: arr(row, {
3880
+ maxItems: 500
3881
+ })
3882
+ }, [
3883
+ "columns",
3884
+ "rows"
3885
+ ]),
3886
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}${textTable(props.columns ?? [], props.rows ?? [])}`, "fallbackText")
3887
+ });
3888
+ var Chart = defineComponent({
3889
+ name: "Chart",
3890
+ title: "Chart",
3891
+ description: "`bar` to compare categories, `line` for a trend over time. `data` is a list of points; `xKey` names the category/time field and each series names a numeric field.",
3892
+ props: obj({
3893
+ type: str("Chart type", {
3894
+ enum: [
3895
+ "bar",
3896
+ "line"
3897
+ ]
3898
+ }),
3899
+ title: str(),
3900
+ xKey: str("Field of each point used for the x axis"),
3901
+ series: arr(obj({
3902
+ key: str("Numeric field"),
3903
+ label: str()
3904
+ }, [
3905
+ "key"
3906
+ ]), {
3907
+ minItems: 1,
3908
+ maxItems: 6
3909
+ }),
3910
+ data: arr(row, {
3911
+ minItems: 1,
3912
+ maxItems: 200
3913
+ }),
3914
+ unit: str("Unit shown after values, e.g. `KB` or `%`")
3915
+ }, [
3916
+ "type",
3917
+ "xKey",
3918
+ "series",
3919
+ "data"
3920
+ ]),
3921
+ fallbackText: /* @__PURE__ */ __name((props) => {
3922
+ const series = props.series ?? [];
3923
+ const data = props.data ?? [];
3924
+ const first = series[0]?.key ?? "";
3925
+ const max = Math.max(0, ...data.map((point) => Math.abs(Number(point[first]) || 0)));
3926
+ const unit = props.unit ? ` ${s(props.unit)}` : "";
3927
+ const lines = data.slice(0, 20).map((point) => `${s(point[props.xKey]).slice(0, 18).padEnd(18)} ${bar(Number(point[first]) || 0, max)} ${s(point[first])}${unit}`);
3928
+ return `${heading(props)}\`\`\`
3929
+ ${lines.join("\n")}
3930
+ \`\`\``;
3931
+ }, "fallbackText")
3932
+ });
3933
+ var KpiCards = defineComponent({
3934
+ name: "KpiCards",
3935
+ title: "KPI cards",
3936
+ description: "A few key numbers (metrics, totals, counts) as cards.",
3937
+ props: obj({
3938
+ title: str(),
3939
+ items: arr(obj({
3940
+ label: str(),
3941
+ value: {
3942
+ type: [
3943
+ "string",
3944
+ "number"
3945
+ ]
3946
+ },
3947
+ delta: str("Change, e.g. `+12%`"),
3948
+ trend: str(void 0, {
3949
+ enum: [
3950
+ "up",
3951
+ "down",
3952
+ "flat"
3953
+ ]
3954
+ }),
3955
+ hint: str()
3956
+ }, [
3957
+ "label",
3958
+ "value"
3959
+ ]), {
3960
+ minItems: 1,
3961
+ maxItems: 8
3962
+ })
3963
+ }, [
3964
+ "items"
3965
+ ]),
3966
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}${(props.items ?? []).map((item) => `\u2022 *${s(item.label)}:* ${s(item.value)}${item.delta ? ` (${s(item.delta)})` : ""}`).join("\n")}`, "fallbackText")
3967
+ });
3968
+ var SourceCards = defineComponent({
3969
+ name: "SourceCards",
3970
+ title: "Sources",
3971
+ description: "The documents, pages or links an answer is based on, as cards.",
3972
+ props: obj({
3973
+ title: str(),
3974
+ items: arr(obj({
3975
+ title: str(),
3976
+ url: str(),
3977
+ snippet: str(),
3978
+ source: str("e.g. Wiki, GitHub")
3979
+ }, [
3980
+ "title"
3981
+ ]), {
3982
+ minItems: 1,
3983
+ maxItems: 12
3984
+ })
3985
+ }, [
3986
+ "items"
3987
+ ]),
3988
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}${(props.items ?? []).map((item) => `\u2022 ${item.url ? `<${s(item.url)}|${s(item.title)}>` : s(item.title)}${item.source ? ` \u2014 ${s(item.source)}` : ""}`).join("\n")}`, "fallbackText")
3989
+ });
3990
+ var Checklist = defineComponent({
3991
+ name: "Checklist",
3992
+ title: "Checklist",
3993
+ description: "Steps or a to-do list with done/not-done state.",
3994
+ props: obj({
3995
+ title: str(),
3996
+ items: arr(obj({
3997
+ label: str(),
3998
+ done: {
3999
+ type: "boolean"
4000
+ },
4001
+ note: str()
4002
+ }, [
4003
+ "label"
4004
+ ]), {
4005
+ minItems: 1,
4006
+ maxItems: 50
4007
+ })
4008
+ }, [
4009
+ "items"
4010
+ ]),
4011
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}${(props.items ?? []).map((item) => `${item.done ? "\u2611" : "\u2610"} ${s(item.label)}${item.note ? ` \u2014 _${s(item.note)}_` : ""}`).join("\n")}`, "fallbackText")
4012
+ });
4013
+ var Timeline = defineComponent({
4014
+ name: "Timeline",
4015
+ title: "Timeline",
4016
+ description: "Events in chronological order (the history of a project, an incident, a deal).",
4017
+ props: obj({
4018
+ title: str(),
4019
+ events: arr(obj({
4020
+ date: str(),
4021
+ title: str(),
4022
+ description: str()
4023
+ }, [
4024
+ "title"
4025
+ ]), {
4026
+ minItems: 1,
4027
+ maxItems: 50
4028
+ })
4029
+ }, [
4030
+ "events"
4031
+ ]),
4032
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}${(props.events ?? []).map((event) => `\u2022 ${event.date ? `*${s(event.date)}* ` : ""}${s(event.title)}${event.description ? ` \u2014 ${s(event.description)}` : ""}`).join("\n")}`, "fallbackText")
4033
+ });
4034
+ var CodeBlock = defineComponent({
4035
+ name: "CodeBlock",
4036
+ title: "Code",
4037
+ description: "A code snippet or file excerpt with syntax highlighting.",
4038
+ props: obj({
4039
+ title: str(),
4040
+ language: str(),
4041
+ code: str()
4042
+ }, [
4043
+ "code"
4044
+ ]),
4045
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}\`\`\`
4046
+ ${s(props.code)}
4047
+ \`\`\``, "fallbackText")
4048
+ });
4049
+ var Diff = defineComponent({
4050
+ name: "Diff",
4051
+ title: "Diff",
4052
+ description: "A before/after change to a text or code file, as a line diff.",
4053
+ props: obj({
4054
+ title: str(),
4055
+ language: str(),
4056
+ before: str(),
4057
+ after: str()
4058
+ }, [
4059
+ "before",
4060
+ "after"
4061
+ ]),
4062
+ fallbackText: /* @__PURE__ */ __name((props) => `${heading(props)}\`\`\`
4063
+ ${lineDiff(s(props.before), s(props.after)).map((line) => `${line.op === "add" ? "+" : line.op === "del" ? "-" : " "} ${line.text}`).join("\n")}
4064
+ \`\`\``, "fallbackText")
4065
+ });
4066
+ var Callout = defineComponent({
4067
+ name: "Callout",
4068
+ title: "Callout",
4069
+ description: "A short note, warning or success message, emphasized.",
4070
+ props: obj({
4071
+ tone: str(void 0, {
4072
+ enum: [
4073
+ "info",
4074
+ "success",
4075
+ "warning",
4076
+ "danger"
4077
+ ]
4078
+ }),
4079
+ title: str(),
4080
+ text: str()
4081
+ }, [
4082
+ "text"
4083
+ ]),
4084
+ fallbackText: /* @__PURE__ */ __name((props) => `${props.tone === "warning" || props.tone === "danger" ? ":warning: " : ":information_source: "}${heading(props)}${s(props.text)}`, "fallbackText")
4085
+ });
4086
+ var Stack = defineComponent({
4087
+ name: "Stack",
4088
+ title: "Stack",
4089
+ description: "Lays its children out vertically (or horizontally with direction=row).",
4090
+ props: obj({
4091
+ direction: str(void 0, {
4092
+ enum: [
4093
+ "column",
4094
+ "row"
4095
+ ]
4096
+ }),
4097
+ gap: {
4098
+ type: "number"
4099
+ }
4100
+ }),
4101
+ children: true,
4102
+ fallbackText: /* @__PURE__ */ __name(() => "", "fallbackText")
4103
+ });
4104
+ var Card = defineComponent({
4105
+ name: "Card",
4106
+ title: "Card",
4107
+ description: "A box with an optional title around its children.",
4108
+ props: obj({
4109
+ title: str(),
4110
+ subtitle: str()
4111
+ }),
4112
+ children: true,
4113
+ fallbackText: /* @__PURE__ */ __name((props) => props.title ? `*${s(props.title)}*${props.subtitle ? ` \u2014 ${s(props.subtitle)}` : ""}` : "", "fallbackText")
4114
+ });
4115
+ var Heading = defineComponent({
4116
+ name: "Heading",
4117
+ title: "Heading",
4118
+ description: "A heading.",
4119
+ props: obj({
4120
+ text: str()
4121
+ }, [
4122
+ "text"
4123
+ ]),
4124
+ fallbackText: /* @__PURE__ */ __name((props) => `*${s(props.text)}*`, "fallbackText")
4125
+ });
4126
+ var Text = defineComponent({
4127
+ name: "Text",
4128
+ title: "Text",
4129
+ description: "A paragraph of plain text (no markdown).",
4130
+ props: obj({
4131
+ text: str(),
4132
+ muted: {
4133
+ type: "boolean"
4134
+ }
4135
+ }, [
4136
+ "text"
4137
+ ]),
4138
+ fallbackText: /* @__PURE__ */ __name((props) => s(props.text), "fallbackText")
4139
+ });
4140
+ var Badge = defineComponent({
4141
+ name: "Badge",
4142
+ title: "Badge",
4143
+ description: "A small label.",
4144
+ props: obj({
4145
+ text: str(),
4146
+ tone: str(void 0, {
4147
+ enum: [
4148
+ "neutral",
4149
+ "brand",
4150
+ "success",
4151
+ "warning",
4152
+ "danger"
4153
+ ]
4154
+ })
4155
+ }, [
4156
+ "text"
4157
+ ]),
4158
+ fallbackText: /* @__PURE__ */ __name((props) => `[${s(props.text)}]`, "fallbackText")
4159
+ });
4160
+ var Link = defineComponent({
4161
+ name: "Link",
4162
+ title: "Link",
4163
+ description: "A link to an http(s) URL.",
4164
+ props: obj({
4165
+ text: str(),
4166
+ url: str(void 0, {
4167
+ pattern: "^https?://"
4168
+ })
4169
+ }, [
4170
+ "text",
4171
+ "url"
4172
+ ]),
4173
+ fallbackText: /* @__PURE__ */ __name((props) => `<${s(props.url)}|${s(props.text || props.url)}>`, "fallbackText")
4174
+ });
4175
+ var Image = defineComponent({
4176
+ name: "Image",
4177
+ title: "Image",
4178
+ description: "An image from an https URL.",
4179
+ props: obj({
4180
+ url: str(void 0, {
4181
+ pattern: "^https://"
4182
+ }),
4183
+ alt: str()
4184
+ }, [
4185
+ "url"
4186
+ ]),
4187
+ fallbackText: /* @__PURE__ */ __name((props) => s(props.url), "fallbackText")
4188
+ });
4189
+
4190
+ // src/genui/registry.ts
4191
+ function snapshotComponentPresentation(value) {
4192
+ const seen = /* @__PURE__ */ new Set();
4193
+ const check2 = /* @__PURE__ */ __name((entry) => {
4194
+ if (entry === null || typeof entry === "string" || typeof entry === "boolean") return;
4195
+ if (typeof entry === "number" && Number.isFinite(entry)) return;
4196
+ if (typeof entry !== "object" || entry === null) throw new TypeError("genui: presentation must contain only JSON values");
4197
+ if (seen.has(entry)) throw new TypeError("genui: presentation must contain acyclic JSON values");
4198
+ if (!Array.isArray(entry) && Object.getPrototypeOf(entry) !== Object.prototype && Object.getPrototypeOf(entry) !== null) throw new TypeError("genui: presentation must contain plain JSON objects");
4199
+ seen.add(entry);
4200
+ for (const item of Object.values(entry)) check2(item);
4201
+ seen.delete(entry);
4202
+ }, "check");
4203
+ check2(value);
4204
+ return JSON.parse(JSON.stringify(value));
4205
+ }
4206
+ __name(snapshotComponentPresentation, "snapshotComponentPresentation");
4207
+ function createComponent(definition, options = {}) {
4208
+ defineComponent(definition);
4209
+ const catalog = defineCatalog([
4210
+ definition
4211
+ ], options);
4212
+ const factory = /* @__PURE__ */ __name(async (props) => {
4213
+ const result2 = await validateProps(definition.props, props, catalog.validator);
4214
+ if (!result2.ok) throw new Error(`genui: invalid ${definition.name} props: ${formatIssues(result2.issues)}`);
4215
+ const normalized = snapshotComponentPresentation(result2.value);
4216
+ if (typeof normalized !== "object" || normalized === null || Array.isArray(normalized)) throw new TypeError("genui: component props must be a JSON object");
4217
+ const portable = await catalog.validate(definition.name, normalized);
4218
+ if (!portable.ok || canonicalJson(snapshotComponentPresentation(portable.value)) !== canonicalJson(normalized)) {
4219
+ throw new Error(`genui: ${definition.name} requires outputProps accepting stable normalized JSON props`);
4220
+ }
4221
+ return {
4222
+ component: definition.name,
4223
+ props: normalized,
4224
+ version: definition.version ?? 1,
4225
+ fallbackText: componentToText(catalog, definition.name, normalized)
4226
+ };
4227
+ }, "factory");
4228
+ return Object.assign(factory, {
4229
+ definition
4230
+ });
4231
+ }
4232
+ __name(createComponent, "createComponent");
4233
+ var table = createComponent(DataTable);
4234
+ var chart = createComponent(Chart);
4235
+ function validatePresentationBatch(presentations) {
4236
+ const batch = Array.isArray(presentations) ? presentations : [
4237
+ presentations
4238
+ ];
4239
+ return batch.map((item) => {
4240
+ const presentation = snapshotComponentPresentation(item);
4241
+ if (typeof presentation !== "object" || presentation === null || typeof presentation.component !== "string" || !/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(presentation.component) || !Number.isSafeInteger(presentation.version) || presentation.version <= 0 || typeof presentation.fallbackText !== "string" || typeof presentation.props !== "object" || presentation.props === null || Array.isArray(presentation.props)) {
4242
+ throw new TypeError("genui: invalid component presentation");
4243
+ }
4244
+ return presentation;
4245
+ });
4246
+ }
4247
+ __name(validatePresentationBatch, "validatePresentationBatch");
4248
+ function canonicalJson(value) {
4249
+ if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
4250
+ if (typeof value === "object" && value !== null) {
4251
+ const record2 = value;
4252
+ return `{${Object.keys(record2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(record2[key])}`).join(",")}}`;
4253
+ }
4254
+ return JSON.stringify(value);
4255
+ }
4256
+ __name(canonicalJson, "canonicalJson");
4257
+
4258
+ // src/tool-presentations.ts
4259
+ async function emitToolPresentations(handler, output, ctx, toolName) {
4260
+ if (handler.present === void 0) return;
4261
+ try {
4262
+ const result2 = await handler.present(output, ctx);
4263
+ if (result2 === void 0) return;
4264
+ const batch = validatePresentationBatch(result2);
4265
+ for (const presentation of batch) {
4266
+ await ctx.emitUi(presentation.component, presentation.props, {
4267
+ version: presentation.version,
4268
+ fallbackText: presentation.fallbackText
4269
+ });
4270
+ }
4271
+ } catch (error) {
4272
+ if (ctx.onPresentationError !== void 0) {
4273
+ try {
4274
+ await ctx.onPresentationError(error, {
4275
+ toolName
4276
+ });
4277
+ return;
4278
+ } catch (reportError) {
4279
+ console.warn(`Tool "${toolName}" presentation error reporter failed`, reportError);
4280
+ }
4281
+ } else {
4282
+ console.warn(`Tool "${toolName}" presentation failed after successful execution`, error);
4283
+ }
4284
+ }
4285
+ }
4286
+ __name(emitToolPresentations, "emitToolPresentations");
4287
+
3734
4288
  // src/tool-registry.ts
3735
4289
  var ToolForbiddenError = class extends Error {
3736
4290
  static {
@@ -3813,6 +4367,15 @@ var ToolRegistry = class {
3813
4367
  handler
3814
4368
  });
3815
4369
  }
4370
+ /** Whether a successful preflight shortcut has UI to journal. */
4371
+ hasPresentation(name) {
4372
+ return typeof this.entries.get(name)?.handler.present === "function";
4373
+ }
4374
+ /** Present an already authorized successful domain result without executing its action again. */
4375
+ async presentOutput(name, output, ctx) {
4376
+ const entry = this.entries.get(name);
4377
+ if (entry !== void 0) await emitToolPresentations(entry.handler, output, ctx, name);
4378
+ }
3816
4379
  has(name) {
3817
4380
  return this.entries.has(name);
3818
4381
  }
@@ -3898,8 +4461,9 @@ var ToolRegistry = class {
3898
4461
  }) : void 0;
3899
4462
  if (trusted) assertTrustedInput(name, hookInput, executionInput);
3900
4463
  if (result2?.status === "denied") throw new ToolPreflightDeniedError(name, result2.reason);
3901
- if (result2?.status === "completed") return result2.output;
3902
- return entry.handler.execute(executionInput, withEmit);
4464
+ const output = result2?.status === "completed" ? result2.output : await entry.handler.execute(executionInput, withEmit);
4465
+ await emitToolPresentations(entry.handler, output, withEmit, name);
4466
+ return output;
3903
4467
  }
3904
4468
  /** Authorize and validate without executing. The caller journals this result before approval. */
3905
4469
  async prepare(name, input, ctx, policy, options = {}) {
@@ -3965,6 +4529,7 @@ var DefaultRolesPolicy = class {
3965
4529
  this.emptyRoles = options.emptyRoles ?? "allow";
3966
4530
  }
3967
4531
  can(actor, tool) {
4532
+ if (tool.ability !== void 0 && tool.roles === void 0) return false;
3968
4533
  const allowed = tool.roles ?? this.defaultRoles;
3969
4534
  if (allowed.length === 0) return this.emptyRoles === "allow";
3970
4535
  return (actor.roles ?? []).some((role) => allowed.includes(role));
@@ -4114,7 +4679,8 @@ var AGENT_SPAN_EVENTS = [
4114
4679
  "llm.turn",
4115
4680
  "tool.execution",
4116
4681
  "retrieval",
4117
- "follow-ups"
4682
+ "follow-ups",
4683
+ "structured-output"
4118
4684
  ];
4119
4685
  var AGENT_DIAGNOSTIC_EVENTS = [
4120
4686
  "run.started",
@@ -4152,8 +4718,19 @@ function createNegotiatedUiCollector(toolCallId, scope, resolveCatalog, write) {
4152
4718
  }, "restart"),
4153
4719
  emit: /* @__PURE__ */ __name(async (component, props, options = {}) => {
4154
4720
  if (!resolveCatalog) {
4155
- if (scope.uiCapabilities !== void 0) throw new Error("UI capabilities require an authorized server catalog");
4156
- return collector.emit(component, props, options);
4721
+ const declared = scope.uiCapabilities === void 0 || scope.uiCapabilities.components.some((entry) => entry.name === component && entry.version === (options.version ?? 1));
4722
+ if (declared) return collector.emit(component, props, options);
4723
+ const id2 = options.id ?? `${toolCallId}:ui:${next++}`;
4724
+ if (options.fallbackText !== void 0 && options.fallbackText.length > 0) {
4725
+ texts.set(id2, options.fallbackText);
4726
+ await write?.({
4727
+ kind: "text",
4728
+ text: options.fallbackText
4729
+ });
4730
+ }
4731
+ return {
4732
+ id: id2
4733
+ };
4157
4734
  }
4158
4735
  const capturedProps = snapshotActionProposal(props);
4159
4736
  const capturedOptions = {
@@ -5240,6 +5817,10 @@ async function claimToolCall(turn, call) {
5240
5817
  ...spec?.terminal === true ? {
5241
5818
  terminal: true
5242
5819
  } : {},
5820
+ // Journal this extra checkpoint's opt-in; historical claims without it keep their sequence.
5821
+ ...preflight?.status === "completed" && deps.registry.hasPresentation(call.name) ? {
5822
+ presentCompletedPreflight: true
5823
+ } : {},
5243
5824
  ...approval !== void 0 ? {
5244
5825
  approval
5245
5826
  } : {},
@@ -5270,6 +5851,9 @@ async function claimToolCall(turn, call) {
5270
5851
  ...persisted?.terminal === true ? {
5271
5852
  terminal: true
5272
5853
  } : {},
5854
+ ...persisted?.presentCompletedPreflight === true ? {
5855
+ presentCompletedPreflight: true
5856
+ } : {},
5273
5857
  ...toolType === "action" && persisted?.approval !== void 0 ? {
5274
5858
  approval: persisted.approval
5275
5859
  } : {},
@@ -5796,6 +6380,19 @@ async function runClaimedToolCall(turn, claimed) {
5796
6380
  }
5797
6381
  if (claimed.preflight !== void 0 && claimed.preflight.status !== "ready") {
5798
6382
  const result2 = claimed.preflight;
6383
+ if (result2.status === "completed" && claimed.presentCompletedPreflight === true) {
6384
+ const raw = await hooks.step(`present:${call.id}`, async () => {
6385
+ const ui = createNegotiatedUiCollector(call.id, ctx, deps.resolveUiCatalog, (event) => turn.writer.write(encodeStreamEvent(event)));
6386
+ await deps.registry.presentOutput(call.name, result2.output, {
6387
+ ...toolCallContext(ctx, call.id),
6388
+ emitUi: ui.emit
6389
+ });
6390
+ return wrapToolStepOutput(result2.output, ui.components(), ui.text());
6391
+ });
6392
+ const presented = unwrapToolStepOutput(raw);
6393
+ if (presented.ui.length > 0) turn.toolUi.set(call.id, presented.ui);
6394
+ if (presented.text) turn.toolText.set(call.id, presented.text);
6395
+ }
5799
6396
  if (result2.status === "completed" && claimed.terminal === true) turn.halt.terminal = true;
5800
6397
  const outcome = result2.status === "completed" ? {
5801
6398
  status: "executed",
@@ -6687,14 +7284,14 @@ var InMemoryActionProposalStore = class {
6687
7284
  }
6688
7285
  async createActionProposal(input) {
6689
7286
  validateActionProposalCreation(input);
6690
- const row = this.rows.get(input.id);
6691
- if (row) {
6692
- if (!actionProposalScopeMatches(row, input)) return {
7287
+ const row2 = this.rows.get(input.id);
7288
+ if (row2) {
7289
+ if (!actionProposalScopeMatches(row2, input)) return {
6693
7290
  status: "conflict"
6694
7291
  };
6695
7292
  return {
6696
- status: actionProposalCreationMatches(row, input) ? "unchanged" : "conflict",
6697
- proposal: snapshotActionProposal(row)
7293
+ status: actionProposalCreationMatches(row2, input) ? "unchanged" : "conflict",
7294
+ proposal: snapshotActionProposal(row2)
6698
7295
  };
6699
7296
  }
6700
7297
  const proposal = initialActionProposal(input, this.clock());
@@ -6705,42 +7302,42 @@ var InMemoryActionProposalStore = class {
6705
7302
  };
6706
7303
  }
6707
7304
  async getActionProposal(scope, id) {
6708
- const row = this.rows.get(id);
6709
- return row && actionProposalScopeMatches(row, scope) ? snapshotActionProposal(row) : null;
7305
+ const row2 = this.rows.get(id);
7306
+ return row2 && actionProposalScopeMatches(row2, scope) ? snapshotActionProposal(row2) : null;
6710
7307
  }
6711
7308
  async listActionProposals(scope, query = {}) {
6712
7309
  const limit = validateActionProposalListQuery(query);
6713
7310
  return [
6714
7311
  ...this.rows.values()
6715
- ].filter((row) => actionProposalScopeMatches(row, scope) && (query.decision === void 0 || row.decision === query.decision) && (query.after === void 0 || row.createdAt > query.after.createdAt || row.createdAt === query.after.createdAt && row.id > query.after.id)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, limit).map(snapshotActionProposal);
7312
+ ].filter((row2) => actionProposalScopeMatches(row2, scope) && (query.decision === void 0 || row2.decision === query.decision) && (query.after === void 0 || row2.createdAt > query.after.createdAt || row2.createdAt === query.after.createdAt && row2.id > query.after.id)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, limit).map(snapshotActionProposal);
6716
7313
  }
6717
7314
  mutate(scope, id, transition) {
6718
- const row = this.rows.get(id);
6719
- if (!row || !actionProposalScopeMatches(row, scope)) return {
7315
+ const row2 = this.rows.get(id);
7316
+ if (!row2 || !actionProposalScopeMatches(row2, scope)) return {
6720
7317
  status: "not_found"
6721
7318
  };
6722
- const result2 = transition(row, this.clock());
7319
+ const result2 = transition(row2, this.clock());
6723
7320
  if (result2.proposal) this.rows.set(id, snapshotActionProposal(result2.proposal));
6724
7321
  return result2;
6725
7322
  }
6726
7323
  async decideActionProposal(scope, id, command) {
6727
- return this.mutate(scope, id, (row, now) => transitionActionProposalDecision(row, command, now));
7324
+ return this.mutate(scope, id, (row2, now) => transitionActionProposalDecision(row2, command, now));
6728
7325
  }
6729
7326
  async claimActionProposal(scope, id, command) {
6730
- return this.mutate(scope, id, (row, now) => transitionActionProposalClaim(row, command, now, randomUUID()));
7327
+ return this.mutate(scope, id, (row2, now) => transitionActionProposalClaim(row2, command, now, randomUUID()));
6731
7328
  }
6732
7329
  async extendActionProposalLease(scope, id, command) {
6733
- return this.mutate(scope, id, (row, now) => transitionActionProposalLease(row, command, now));
7330
+ return this.mutate(scope, id, (row2, now) => transitionActionProposalLease(row2, command, now));
6734
7331
  }
6735
7332
  async settleActionProposal(scope, id, command) {
6736
- return this.mutate(scope, id, (row, now) => transitionActionProposalSettlement(row, command, now));
7333
+ return this.mutate(scope, id, (row2, now) => transitionActionProposalSettlement(row2, command, now));
6737
7334
  }
6738
7335
  async claimNextActionProposal(command) {
6739
7336
  const now = this.clock();
6740
7337
  validateActionProposalWorkerClaim(command, now);
6741
7338
  const candidates = [
6742
7339
  ...this.rows.values()
6743
- ].filter((row) => row.decision === "approved" && (row.execution?.status === "queued" || row.execution?.status === "executing" && row.execution.lease !== null && now >= row.execution.lease.expiresAt)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, 32);
7340
+ ].filter((row2) => row2.decision === "approved" && (row2.execution?.status === "queued" || row2.execution?.status === "executing" && row2.execution.lease !== null && now >= row2.execution.lease.expiresAt)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, 32);
6744
7341
  for (const candidate of candidates) {
6745
7342
  const claimed = await this.claimActionProposal(candidate, candidate.id, command);
6746
7343
  if (claimed.status === "applied" && claimed.proposal) return claimed.proposal;
@@ -6752,7 +7349,7 @@ var InMemoryActionProposalStore = class {
6752
7349
  validateActionProposalExpiryBatch(command, now);
6753
7350
  const candidates = [
6754
7351
  ...this.rows.values()
6755
- ].filter((row) => row.decision === "pending" && row.expiresAt !== null && now >= row.expiresAt).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, command.limit);
7352
+ ].filter((row2) => row2.decision === "pending" && row2.expiresAt !== null && now >= row2.expiresAt).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, command.limit);
6756
7353
  let expired = 0;
6757
7354
  for (const candidate of candidates) {
6758
7355
  const result2 = await this.decideActionProposal(candidate, candidate.id, {
@@ -6769,11 +7366,11 @@ var InMemoryActionProposalStore = class {
6769
7366
  validateActionProposalWorkerClaim(command, now);
6770
7367
  const candidates = [
6771
7368
  ...this.rows.values()
6772
- ].filter((row) => row.outcomeDelivery?.status === "pending" && (!row.outcomeDelivery.lease || now >= row.outcomeDelivery.lease.expiresAt)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, 32);
7369
+ ].filter((row2) => row2.outcomeDelivery?.status === "pending" && (!row2.outcomeDelivery.lease || now >= row2.outcomeDelivery.lease.expiresAt)).sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).slice(0, 32);
6773
7370
  for (const candidate of candidates) {
6774
- const row = this.rows.get(candidate.id);
6775
- if (!row) continue;
6776
- const next = claimActionProposalOutcome(row, command, this.clock(), randomUUID());
7371
+ const row2 = this.rows.get(candidate.id);
7372
+ if (!row2) continue;
7373
+ const next = claimActionProposalOutcome(row2, command, this.clock(), randomUUID());
6777
7374
  if (!next?.outcome || !next.outcomeDelivery?.lease) continue;
6778
7375
  this.rows.set(next.id, next);
6779
7376
  return {
@@ -6793,9 +7390,9 @@ var InMemoryActionProposalStore = class {
6793
7390
  if (existing) return this.createActionProposal(input);
6794
7391
  const proposal = initialActionProposal(input, this.clock());
6795
7392
  const replacements = [];
6796
- if (input.replacementKey) for (const row of this.rows.values()) {
6797
- if (row.decision !== "pending" || !actionProposalScopeMatches(row, input) || row.toolName !== input.toolName || row.replacementKey !== input.replacementKey) continue;
6798
- const result2 = transitionActionProposalSupersession(row, proposal, {
7393
+ if (input.replacementKey) for (const row2 of this.rows.values()) {
7394
+ if (row2.decision !== "pending" || !actionProposalScopeMatches(row2, input) || row2.toolName !== input.toolName || row2.replacementKey !== input.replacementKey) continue;
7395
+ const result2 = transitionActionProposalSupersession(row2, proposal, {
6799
7396
  replacementProposalId: proposal.id,
6800
7397
  actorRef: input.actorRef,
6801
7398
  via: "supersession"
@@ -6803,7 +7400,7 @@ var InMemoryActionProposalStore = class {
6803
7400
  if (result2.proposal) replacements.push(result2.proposal);
6804
7401
  }
6805
7402
  this.rows.set(proposal.id, proposal);
6806
- for (const row of replacements) this.rows.set(row.id, row);
7403
+ for (const row2 of replacements) this.rows.set(row2.id, row2);
6807
7404
  return {
6808
7405
  status: "created",
6809
7406
  proposal: snapshotActionProposal(proposal)
@@ -6814,7 +7411,7 @@ var InMemoryActionProposalStore = class {
6814
7411
  if (!replacement || !actionProposalScopeMatches(replacement, scope)) return {
6815
7412
  status: "not_found"
6816
7413
  };
6817
- return this.mutate(scope, id, (row, now) => transitionActionProposalSupersession(row, replacement, command, now));
7414
+ return this.mutate(scope, id, (row2, now) => transitionActionProposalSupersession(row2, replacement, command, now));
6818
7415
  }
6819
7416
  };
6820
7417
 
@@ -6839,7 +7436,7 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6839
7436
  throw new Error(`thread ${id} already exists`);
6840
7437
  }
6841
7438
  const ts = this.now();
6842
- const row = {
7439
+ const row2 = {
6843
7440
  id,
6844
7441
  actorRef: input.actor.id,
6845
7442
  tenantRef: input.actor.tenantRef ?? null,
@@ -6852,20 +7449,20 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6852
7449
  persona: input.persona
6853
7450
  } : {}
6854
7451
  };
6855
- this.threads.set(id, row);
6856
- return this.toSummary(row);
7452
+ this.threads.set(id, row2);
7453
+ return this.toSummary(row2);
6857
7454
  }
6858
7455
  async getThread(threadId) {
6859
- const row = this.threads.get(threadId);
6860
- if (row === void 0) {
7456
+ const row2 = this.threads.get(threadId);
7457
+ if (row2 === void 0) {
6861
7458
  return null;
6862
7459
  }
6863
7460
  return {
6864
- ...this.toSummary(row),
6865
- messages: row.messages.map((message) => this.withApprovals(message)),
7461
+ ...this.toSummary(row2),
7462
+ messages: row2.messages.map((message) => this.withApprovals(message)),
6866
7463
  // The run streaming right now — the one field the read-model reports it under.
6867
- ...row.activeStreamId !== void 0 ? {
6868
- activeRunId: row.activeStreamId
7464
+ ...row2.activeStreamId !== void 0 ? {
7465
+ activeRunId: row2.activeStreamId
6869
7466
  } : {}
6870
7467
  };
6871
7468
  }
@@ -6931,7 +7528,7 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6931
7528
  async listThreads(actorRef, limit = 50) {
6932
7529
  return [
6933
7530
  ...this.threads.values()
6934
- ].filter((row) => row.actorRef === actorRef && !row.transient).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)).slice(0, limit).map((row) => this.toSummary(row));
7531
+ ].filter((row2) => row2.actorRef === actorRef && !row2.transient).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt)).slice(0, limit).map((row2) => this.toSummary(row2));
6935
7532
  }
6936
7533
  async softDeleteThread(threadId) {
6937
7534
  this.threads.delete(threadId);
@@ -6947,7 +7544,7 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6947
7544
  ];
6948
7545
  const id = crypto.randomUUID();
6949
7546
  const ts = this.now();
6950
- const row = {
7547
+ const row2 = {
6951
7548
  id,
6952
7549
  actorRef: source.actorRef,
6953
7550
  tenantRef: source.tenantRef,
@@ -6969,8 +7566,8 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6969
7566
  persona: source.persona
6970
7567
  } : {}
6971
7568
  };
6972
- this.threads.set(id, row);
6973
- return this.toSummary(row);
7569
+ this.threads.set(id, row2);
7570
+ return this.toSummary(row2);
6974
7571
  }
6975
7572
  async ownerOfThread(threadId) {
6976
7573
  return this.threads.get(threadId)?.actorRef ?? null;
@@ -6990,38 +7587,38 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
6990
7587
  return call.runId ?? this.threads.get(call.threadId)?.activeStreamId ?? null;
6991
7588
  }
6992
7589
  async ownerOfActiveStream(runId) {
6993
- for (const row of this.threads.values()) {
6994
- if (row.activeStreamId === runId) {
6995
- return row.actorRef;
7590
+ for (const row2 of this.threads.values()) {
7591
+ if (row2.activeStreamId === runId) {
7592
+ return row2.actorRef;
6996
7593
  }
6997
7594
  }
6998
7595
  return null;
6999
7596
  }
7000
7597
  async setTitle(threadId, title) {
7001
- const row = this.threads.get(threadId);
7002
- if (row !== void 0) {
7003
- row.title = title;
7004
- row.updatedAt = this.now();
7598
+ const row2 = this.threads.get(threadId);
7599
+ if (row2 !== void 0) {
7600
+ row2.title = title;
7601
+ row2.updatedAt = this.now();
7005
7602
  }
7006
7603
  }
7007
7604
  async updateThread(threadId, patch) {
7008
- const row = this.threads.get(threadId);
7009
- if (row === void 0) {
7605
+ const row2 = this.threads.get(threadId);
7606
+ if (row2 === void 0) {
7010
7607
  return;
7011
7608
  }
7012
7609
  if (patch.title !== void 0) {
7013
- row.title = patch.title;
7610
+ row2.title = patch.title;
7014
7611
  }
7015
7612
  if (patch.defaultAgent !== void 0) {
7016
- row.defaultAgent = patch.defaultAgent;
7613
+ row2.defaultAgent = patch.defaultAgent;
7017
7614
  }
7018
7615
  if (patch.model !== void 0) {
7019
- row.model = patch.model;
7616
+ row2.model = patch.model;
7020
7617
  }
7021
7618
  if (patch.persona !== void 0) {
7022
- row.persona = patch.persona;
7619
+ row2.persona = patch.persona;
7023
7620
  }
7024
- row.updatedAt = this.now();
7621
+ row2.updatedAt = this.now();
7025
7622
  }
7026
7623
  async activeRunForThread(threadId) {
7027
7624
  return this.threads.get(threadId)?.activeStreamId ?? null;
@@ -7069,64 +7666,64 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7069
7666
  }
7070
7667
  /** Settle a run's outcome. A no-op when the run is unknown (mirrors `setTitle`/`updateThread`). */
7071
7668
  async recordRunEnd(end) {
7072
- const row = this.runs.get(end.runId);
7073
- if (row === void 0) {
7669
+ const row2 = this.runs.get(end.runId);
7670
+ if (row2 === void 0) {
7074
7671
  return;
7075
7672
  }
7076
- row.status = end.status;
7077
- row.settledAt = this.now();
7673
+ row2.status = end.status;
7674
+ row2.settledAt = this.now();
7078
7675
  if (end.durationMs !== void 0) {
7079
- row.durationMs = end.durationMs;
7676
+ row2.durationMs = end.durationMs;
7080
7677
  }
7081
7678
  if (end.errorCode !== void 0) {
7082
- row.errorCode = end.errorCode;
7679
+ row2.errorCode = end.errorCode;
7083
7680
  }
7084
7681
  if (end.errorMessage !== void 0) {
7085
- row.errorMessage = end.errorMessage;
7682
+ row2.errorMessage = end.errorMessage;
7086
7683
  }
7087
7684
  }
7088
7685
  /** Bump the run's llm-step retry counter. */
7089
7686
  async bumpRunRetries(runId) {
7090
- const row = this.runs.get(runId);
7091
- if (row !== void 0) {
7092
- row.retries += 1;
7687
+ const row2 = this.runs.get(runId);
7688
+ if (row2 !== void 0) {
7689
+ row2.retries += 1;
7093
7690
  }
7094
7691
  }
7095
7692
  async promoteThread(threadId) {
7096
- const row = this.threads.get(threadId);
7097
- if (row?.transient) {
7098
- row.transient = false;
7099
- row.updatedAt = this.now();
7693
+ const row2 = this.threads.get(threadId);
7694
+ if (row2?.transient) {
7695
+ row2.transient = false;
7696
+ row2.updatedAt = this.now();
7100
7697
  }
7101
7698
  }
7102
7699
  async setActiveStream(threadId, runId) {
7103
- const row = this.threads.get(threadId);
7104
- if (row !== void 0) {
7700
+ const row2 = this.threads.get(threadId);
7701
+ if (row2 !== void 0) {
7105
7702
  if (runId === null) {
7106
- delete row.activeStreamId;
7703
+ delete row2.activeStreamId;
7107
7704
  } else {
7108
- row.activeStreamId = runId;
7705
+ row2.activeStreamId = runId;
7109
7706
  }
7110
7707
  }
7111
7708
  }
7112
7709
  async claimActiveStream(threadId, runId, options = {}) {
7113
- const row = this.threads.get(threadId);
7114
- if (row === void 0) {
7710
+ const row2 = this.threads.get(threadId);
7711
+ if (row2 === void 0) {
7115
7712
  return false;
7116
7713
  }
7117
- const holder = row.activeStreamId;
7714
+ const holder = row2.activeStreamId;
7118
7715
  if (holder !== void 0 && holder !== runId && holder !== options.replacing) {
7119
7716
  return false;
7120
7717
  }
7121
- row.activeStreamId = runId;
7718
+ row2.activeStreamId = runId;
7122
7719
  return true;
7123
7720
  }
7124
7721
  async releaseActiveStream(threadId, runId) {
7125
- const row = this.threads.get(threadId);
7126
- if (row?.activeStreamId !== runId) {
7722
+ const row2 = this.threads.get(threadId);
7723
+ if (row2?.activeStreamId !== runId) {
7127
7724
  return false;
7128
7725
  }
7129
- delete row.activeStreamId;
7726
+ delete row2.activeStreamId;
7130
7727
  return true;
7131
7728
  }
7132
7729
  async enqueueMessage(input) {
@@ -7259,38 +7856,38 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7259
7856
  return void 0;
7260
7857
  }
7261
7858
  async getThreadActionProposalScope(threadId) {
7262
- const row = this.threads.get(threadId);
7263
- return row ? {
7859
+ const row2 = this.threads.get(threadId);
7860
+ return row2 ? {
7264
7861
  threadId,
7265
- actorRef: row.actorRef,
7266
- tenantRef: row.tenantRef
7862
+ actorRef: row2.actorRef,
7863
+ tenantRef: row2.tenantRef
7267
7864
  } : null;
7268
7865
  }
7269
7866
  async admitActionProposalOutcome(command) {
7270
- const row = [
7867
+ const row2 = [
7271
7868
  ...this.rows.values()
7272
- ].find((row2) => row2.outcome?.id === command.outcomeId);
7273
- if (!row?.outcome || !row.outcomeDelivery) return {
7869
+ ].find((row3) => row3.outcome?.id === command.outcomeId);
7870
+ if (!row2?.outcome || !row2.outcomeDelivery) return {
7274
7871
  status: "not_found"
7275
7872
  };
7276
- if (row.outcomeDelivery.status === "admitted") return {
7873
+ if (row2.outcomeDelivery.status === "admitted") return {
7277
7874
  status: "unchanged",
7278
- ...row.outcomeDelivery.messageId !== void 0 ? {
7279
- messageId: row.outcomeDelivery.messageId
7875
+ ...row2.outcomeDelivery.messageId !== void 0 ? {
7876
+ messageId: row2.outcomeDelivery.messageId
7280
7877
  } : {}
7281
7878
  };
7282
- if (row.outcomeDelivery.status === "discarded") return {
7879
+ if (row2.outcomeDelivery.status === "discarded") return {
7283
7880
  status: "discarded"
7284
7881
  };
7285
- if (!actionProposalOutcomeFenceValid(row, command, this.clock())) return {
7882
+ if (!actionProposalOutcomeFenceValid(row2, command, this.clock())) return {
7286
7883
  status: "conflict"
7287
7884
  };
7288
- const thread = this.threads.get(row.threadId);
7885
+ const thread = this.threads.get(row2.threadId);
7289
7886
  if (!thread) {
7290
- this.rows.set(row.id, snapshotActionProposal({
7291
- ...row,
7887
+ this.rows.set(row2.id, snapshotActionProposal({
7888
+ ...row2,
7292
7889
  outcomeDelivery: {
7293
- ...row.outcomeDelivery,
7890
+ ...row2.outcomeDelivery,
7294
7891
  status: "discarded",
7295
7892
  lease: null
7296
7893
  }
@@ -7299,7 +7896,7 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7299
7896
  status: "discarded"
7300
7897
  };
7301
7898
  }
7302
- if (thread.actorRef !== row.actorRef || thread.tenantRef !== row.tenantRef) return {
7899
+ if (thread.actorRef !== row2.actorRef || thread.tenantRef !== row2.tenantRef) return {
7303
7900
  status: "conflict"
7304
7901
  };
7305
7902
  if (thread.activeStreamId) return {
@@ -7308,15 +7905,15 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7308
7905
  const message = {
7309
7906
  id: crypto.randomUUID(),
7310
7907
  role: "assistant",
7311
- content: actionProposalOutcomeText(row.outcome),
7908
+ content: actionProposalOutcomeText(row2.outcome),
7312
7909
  createdAt: this.now(),
7313
- actionProposalOutcome: snapshotActionProposal(row.outcome),
7314
- ui: snapshotActionProposal(row.outcome.ui)
7910
+ actionProposalOutcome: snapshotActionProposal(row2.outcome),
7911
+ ui: snapshotActionProposal(row2.outcome.ui)
7315
7912
  };
7316
7913
  const next = snapshotActionProposal({
7317
- ...row,
7914
+ ...row2,
7318
7915
  outcomeDelivery: {
7319
- ...row.outcomeDelivery,
7916
+ ...row2.outcomeDelivery,
7320
7917
  status: "admitted",
7321
7918
  lease: null,
7322
7919
  messageId: message.id
@@ -7324,15 +7921,15 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7324
7921
  });
7325
7922
  thread.messages.push(message);
7326
7923
  thread.updatedAt = message.createdAt;
7327
- this.rows.set(row.id, next);
7924
+ this.rows.set(row2.id, next);
7328
7925
  return {
7329
7926
  status: "applied",
7330
7927
  messageId: message.id
7331
7928
  };
7332
7929
  }
7333
7930
  async appendMessage(input) {
7334
- const row = this.threads.get(input.threadId);
7335
- if (row === void 0) {
7931
+ const row2 = this.threads.get(input.threadId);
7932
+ if (row2 === void 0) {
7336
7933
  throw new Error(`thread ${input.threadId} not found`);
7337
7934
  }
7338
7935
  const message = {
@@ -7377,13 +7974,13 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7377
7974
  actionProposalOutcome: input.actionProposalOutcome
7378
7975
  } : {}
7379
7976
  };
7380
- row.messages.push(message);
7381
- row.updatedAt = message.createdAt;
7977
+ row2.messages.push(message);
7978
+ row2.updatedAt = message.createdAt;
7382
7979
  return message;
7383
7980
  }
7384
7981
  async setMessageToolResults(messageId, results) {
7385
- for (const row of this.threads.values()) {
7386
- const message = row.messages.find((candidate) => candidate.id === messageId);
7982
+ for (const row2 of this.threads.values()) {
7983
+ const message = row2.messages.find((candidate) => candidate.id === messageId);
7387
7984
  if (message !== void 0) {
7388
7985
  message.toolResults = results;
7389
7986
  return;
@@ -7391,12 +7988,12 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7391
7988
  }
7392
7989
  }
7393
7990
  async setMessageUi(messageId, ui) {
7394
- for (const row of this.threads.values()) {
7395
- const index = row.messages.findIndex((candidate) => candidate.id === messageId);
7396
- const message = row.messages[index];
7991
+ for (const row2 of this.threads.values()) {
7992
+ const index = row2.messages.findIndex((candidate) => candidate.id === messageId);
7993
+ const message = row2.messages[index];
7397
7994
  if (message !== void 0) {
7398
7995
  const { ui: _previous, ...rest } = message;
7399
- row.messages[index] = ui.length > 0 ? {
7996
+ row2.messages[index] = ui.length > 0 ? {
7400
7997
  ...rest,
7401
7998
  ui
7402
7999
  } : rest;
@@ -7408,12 +8005,12 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7408
8005
  return this.threadIdForMessage(messageId) ?? null;
7409
8006
  }
7410
8007
  async setMessageFeedback(messageId, feedback) {
7411
- for (const row of this.threads.values()) {
7412
- const index = row.messages.findIndex((candidate) => candidate.id === messageId);
7413
- const message = row.messages[index];
8008
+ for (const row2 of this.threads.values()) {
8009
+ const index = row2.messages.findIndex((candidate) => candidate.id === messageId);
8010
+ const message = row2.messages[index];
7414
8011
  if (message !== void 0) {
7415
8012
  const { feedback: _previous, ...rest } = message;
7416
- row.messages[index] = feedback !== null ? {
8013
+ row2.messages[index] = feedback !== null ? {
7417
8014
  ...rest,
7418
8015
  feedback
7419
8016
  } : rest;
@@ -7422,13 +8019,13 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7422
8019
  }
7423
8020
  }
7424
8021
  async truncateFrom(threadId, messageId) {
7425
- const row = this.threads.get(threadId);
7426
- if (row === void 0) {
8022
+ const row2 = this.threads.get(threadId);
8023
+ if (row2 === void 0) {
7427
8024
  return;
7428
8025
  }
7429
- const cutoff = row.messages.findIndex((message) => message.id === messageId);
8026
+ const cutoff = row2.messages.findIndex((message) => message.id === messageId);
7430
8027
  if (cutoff >= 0) {
7431
- row.messages = row.messages.slice(0, cutoff);
8028
+ row2.messages = row2.messages.slice(0, cutoff);
7432
8029
  }
7433
8030
  }
7434
8031
  /**
@@ -7493,16 +8090,16 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7493
8090
  async toolCallOutcomes(toolCallIds) {
7494
8091
  const outcomes = [];
7495
8092
  for (const id of toolCallIds) {
7496
- const row = this.toolCalls.get(id);
7497
- if (row !== void 0) {
8093
+ const row2 = this.toolCalls.get(id);
8094
+ if (row2 !== void 0) {
7498
8095
  outcomes.push({
7499
8096
  id,
7500
- status: row.status,
7501
- ...row.output !== void 0 ? {
7502
- output: row.output
8097
+ status: row2.status,
8098
+ ...row2.output !== void 0 ? {
8099
+ output: row2.output
7503
8100
  } : {},
7504
- ...row.error !== void 0 ? {
7505
- error: row.error
8101
+ ...row2.error !== void 0 ? {
8102
+ error: row2.error
7506
8103
  } : {}
7507
8104
  });
7508
8105
  }
@@ -7511,38 +8108,38 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7511
8108
  }
7512
8109
  async failUnsettledToolCalls(runId, error) {
7513
8110
  let settled = 0;
7514
- for (const row of this.toolCalls.values()) {
7515
- if (row.runId === runId && row.status === "pending_approval") {
7516
- row.status = "failed";
7517
- row.error = error;
8111
+ for (const row2 of this.toolCalls.values()) {
8112
+ if (row2.runId === runId && row2.status === "pending_approval") {
8113
+ row2.status = "failed";
8114
+ row2.error = error;
7518
8115
  settled += 1;
7519
8116
  }
7520
8117
  }
7521
8118
  return settled;
7522
8119
  }
7523
8120
  async updateToolCall(input) {
7524
- const row = this.toolCalls.get(input.toolCallId);
7525
- if (row === void 0) {
8121
+ const row2 = this.toolCalls.get(input.toolCallId);
8122
+ if (row2 === void 0) {
7526
8123
  return;
7527
8124
  }
7528
- row.status = input.status;
8125
+ row2.status = input.status;
7529
8126
  if (input.output !== void 0) {
7530
- row.output = input.output;
8127
+ row2.output = input.output;
7531
8128
  }
7532
8129
  if (input.error !== void 0) {
7533
- row.error = input.error;
8130
+ row2.error = input.error;
7534
8131
  }
7535
8132
  if (input.executionMs !== void 0) {
7536
- row.executionMs = input.executionMs;
8133
+ row2.executionMs = input.executionMs;
7537
8134
  }
7538
8135
  if (input.executedByRef !== void 0) {
7539
- row.executedByRef = input.executedByRef;
8136
+ row2.executedByRef = input.executedByRef;
7540
8137
  }
7541
8138
  if (input.remember !== void 0) {
7542
- row.remember = input.remember;
8139
+ row2.remember = input.remember;
7543
8140
  }
7544
8141
  if (input.decidedVia !== void 0) {
7545
- row.decidedVia = input.decidedVia;
8142
+ row2.decidedVia = input.decidedVia;
7546
8143
  }
7547
8144
  }
7548
8145
  async recordUsage(input) {
@@ -7570,9 +8167,9 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7570
8167
  return this.usageBetween(actorRef, day, day);
7571
8168
  }
7572
8169
  async usageBetween(actorRef, fromDay, toDay) {
7573
- const rows = this.usage.filter((row) => row.actorRef === actorRef && row.day >= fromDay && row.day <= toDay);
7574
- const usedTokens = rows.reduce((sum, row) => sum + row.inputTokens + row.outputTokens, 0);
7575
- const costUsd = rows.reduce((sum, row) => sum + (row.costUsd ?? 0), 0);
8170
+ const rows = this.usage.filter((row2) => row2.actorRef === actorRef && row2.day >= fromDay && row2.day <= toDay);
8171
+ const usedTokens = rows.reduce((sum, row2) => sum + row2.inputTokens + row2.outputTokens, 0);
8172
+ const costUsd = rows.reduce((sum, row2) => sum + (row2.costUsd ?? 0), 0);
7576
8173
  return {
7577
8174
  usedTokens,
7578
8175
  costUsd
@@ -7580,30 +8177,30 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7580
8177
  }
7581
8178
  /** Test helper: read the recorded usage rows (modelId + token totals). */
7582
8179
  usageRows() {
7583
- return this.usage.map((row) => ({
7584
- actorRef: row.actorRef,
7585
- tokens: row.inputTokens + row.outputTokens,
7586
- modelId: row.modelId
8180
+ return this.usage.map((row2) => ({
8181
+ actorRef: row2.actorRef,
8182
+ tokens: row2.inputTokens + row2.outputTokens,
8183
+ modelId: row2.modelId
7587
8184
  }));
7588
8185
  }
7589
8186
  /** Governance read-model feed: recorded usage rows with the input/output split + thread/day. */
7590
8187
  governanceUsage() {
7591
- return this.usage.map((row) => ({
7592
- actorRef: row.actorRef,
7593
- threadId: row.threadId,
7594
- modelId: row.modelId,
7595
- inputTokens: row.inputTokens,
7596
- outputTokens: row.outputTokens,
7597
- day: row.day,
7598
- createdAt: row.createdAt,
7599
- ...row.cacheWriteTokens !== void 0 ? {
7600
- cacheWriteTokens: row.cacheWriteTokens
8188
+ return this.usage.map((row2) => ({
8189
+ actorRef: row2.actorRef,
8190
+ threadId: row2.threadId,
8191
+ modelId: row2.modelId,
8192
+ inputTokens: row2.inputTokens,
8193
+ outputTokens: row2.outputTokens,
8194
+ day: row2.day,
8195
+ createdAt: row2.createdAt,
8196
+ ...row2.cacheWriteTokens !== void 0 ? {
8197
+ cacheWriteTokens: row2.cacheWriteTokens
7601
8198
  } : {},
7602
- ...row.cacheReadTokens !== void 0 ? {
7603
- cacheReadTokens: row.cacheReadTokens
8199
+ ...row2.cacheReadTokens !== void 0 ? {
8200
+ cacheReadTokens: row2.cacheReadTokens
7604
8201
  } : {},
7605
- ...row.costUsd !== void 0 ? {
7606
- costUsd: row.costUsd
8202
+ ...row2.costUsd !== void 0 ? {
8203
+ costUsd: row2.costUsd
7607
8204
  } : {}
7608
8205
  }));
7609
8206
  }
@@ -7611,22 +8208,22 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7611
8208
  governanceToolCalls() {
7612
8209
  return [
7613
8210
  ...this.toolCalls.values()
7614
- ].map((row) => ({
7615
- toolCallId: row.toolCallId,
7616
- toolName: row.toolName,
7617
- toolType: row.toolType,
7618
- status: row.status,
7619
- threadId: row.threadId,
7620
- messageId: row.messageId,
7621
- createdAt: row.createdAt,
7622
- ...row.executionMs !== void 0 ? {
7623
- executionMs: row.executionMs
8211
+ ].map((row2) => ({
8212
+ toolCallId: row2.toolCallId,
8213
+ toolName: row2.toolName,
8214
+ toolType: row2.toolType,
8215
+ status: row2.status,
8216
+ threadId: row2.threadId,
8217
+ messageId: row2.messageId,
8218
+ createdAt: row2.createdAt,
8219
+ ...row2.executionMs !== void 0 ? {
8220
+ executionMs: row2.executionMs
7624
8221
  } : {},
7625
- ...row.error !== void 0 ? {
7626
- error: row.error
8222
+ ...row2.error !== void 0 ? {
8223
+ error: row2.error
7627
8224
  } : {},
7628
- ...row.runId !== void 0 ? {
7629
- runId: row.runId
8225
+ ...row2.runId !== void 0 ? {
8226
+ runId: row2.runId
7630
8227
  } : {}
7631
8228
  }));
7632
8229
  }
@@ -7686,51 +8283,51 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7686
8283
  governanceThreads() {
7687
8284
  return [
7688
8285
  ...this.threads.values()
7689
- ].map((row) => ({
7690
- threadId: row.id,
7691
- title: row.title,
7692
- actorRef: row.actorRef,
7693
- messageCount: row.messages.length,
7694
- updatedAt: row.updatedAt
8286
+ ].map((row2) => ({
8287
+ threadId: row2.id,
8288
+ title: row2.title,
8289
+ actorRef: row2.actorRef,
8290
+ messageCount: row2.messages.length,
8291
+ updatedAt: row2.updatedAt
7695
8292
  }));
7696
8293
  }
7697
8294
  /** Governance read-model feed: recorded run outcomes (the reliability surfaces). */
7698
8295
  governanceRuns() {
7699
8296
  return [
7700
8297
  ...this.runs.values()
7701
- ].map((row) => ({
7702
- runId: row.runId,
7703
- threadId: row.threadId,
7704
- actorRef: row.actorRef,
7705
- status: row.status,
7706
- retries: row.retries,
7707
- startedAt: row.startedAt,
7708
- ...row.agentName !== void 0 ? {
7709
- agentName: row.agentName
8298
+ ].map((row2) => ({
8299
+ runId: row2.runId,
8300
+ threadId: row2.threadId,
8301
+ actorRef: row2.actorRef,
8302
+ status: row2.status,
8303
+ retries: row2.retries,
8304
+ startedAt: row2.startedAt,
8305
+ ...row2.agentName !== void 0 ? {
8306
+ agentName: row2.agentName
7710
8307
  } : {},
7711
- ...row.parentRunId !== void 0 ? {
7712
- parentRunId: row.parentRunId
8308
+ ...row2.parentRunId !== void 0 ? {
8309
+ parentRunId: row2.parentRunId
7713
8310
  } : {},
7714
- ...row.durationMs !== void 0 ? {
7715
- durationMs: row.durationMs
8311
+ ...row2.durationMs !== void 0 ? {
8312
+ durationMs: row2.durationMs
7716
8313
  } : {},
7717
- ...row.errorCode !== void 0 ? {
7718
- errorCode: row.errorCode
8314
+ ...row2.errorCode !== void 0 ? {
8315
+ errorCode: row2.errorCode
7719
8316
  } : {},
7720
- ...row.errorMessage !== void 0 ? {
7721
- errorMessage: row.errorMessage
8317
+ ...row2.errorMessage !== void 0 ? {
8318
+ errorMessage: row2.errorMessage
7722
8319
  } : {},
7723
- ...row.settledAt !== void 0 ? {
7724
- settledAt: row.settledAt
8320
+ ...row2.settledAt !== void 0 ? {
8321
+ settledAt: row2.settledAt
7725
8322
  } : {},
7726
- ...row.promptHash !== void 0 ? {
7727
- promptHash: row.promptHash
8323
+ ...row2.promptHash !== void 0 ? {
8324
+ promptHash: row2.promptHash
7728
8325
  } : {}
7729
8326
  }));
7730
8327
  }
7731
8328
  threadIdForMessage(messageId) {
7732
- for (const [threadId, row] of this.threads) {
7733
- if (row.messages.some((message) => message.id === messageId)) {
8329
+ for (const [threadId, row2] of this.threads) {
8330
+ if (row2.messages.some((message) => message.id === messageId)) {
7734
8331
  return threadId;
7735
8332
  }
7736
8333
  }
@@ -7740,54 +8337,54 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7740
8337
  toolCallRows() {
7741
8338
  return [
7742
8339
  ...this.toolCalls.values()
7743
- ].map((row) => ({
7744
- toolCallId: row.toolCallId,
7745
- toolName: row.toolName,
7746
- toolType: row.toolType,
7747
- status: row.status,
7748
- input: row.input,
7749
- ...row.output !== void 0 ? {
7750
- output: row.output
8340
+ ].map((row2) => ({
8341
+ toolCallId: row2.toolCallId,
8342
+ toolName: row2.toolName,
8343
+ toolType: row2.toolType,
8344
+ status: row2.status,
8345
+ input: row2.input,
8346
+ ...row2.output !== void 0 ? {
8347
+ output: row2.output
7751
8348
  } : {},
7752
- ...row.error !== void 0 ? {
7753
- error: row.error
8349
+ ...row2.error !== void 0 ? {
8350
+ error: row2.error
7754
8351
  } : {},
7755
- ...row.runId !== void 0 ? {
7756
- runId: row.runId
8352
+ ...row2.runId !== void 0 ? {
8353
+ runId: row2.runId
7757
8354
  } : {},
7758
- ...row.executedByRef !== void 0 ? {
7759
- executedByRef: row.executedByRef
8355
+ ...row2.executedByRef !== void 0 ? {
8356
+ executedByRef: row2.executedByRef
7760
8357
  } : {},
7761
- ...row.approver !== void 0 ? {
7762
- approver: row.approver
8358
+ ...row2.approver !== void 0 ? {
8359
+ approver: row2.approver
7763
8360
  } : {},
7764
- ...row.expiresAt !== void 0 ? {
7765
- expiresAt: row.expiresAt
8361
+ ...row2.expiresAt !== void 0 ? {
8362
+ expiresAt: row2.expiresAt
7766
8363
  } : {},
7767
- ...row.remember !== void 0 ? {
7768
- remember: row.remember
8364
+ ...row2.remember !== void 0 ? {
8365
+ remember: row2.remember
7769
8366
  } : {},
7770
- ...row.decidedVia !== void 0 ? {
7771
- decidedVia: row.decidedVia
8367
+ ...row2.decidedVia !== void 0 ? {
8368
+ decidedVia: row2.decidedVia
7772
8369
  } : {}
7773
8370
  }));
7774
8371
  }
7775
- toSummary(row) {
7776
- const last = row.messages[row.messages.length - 1];
8372
+ toSummary(row2) {
8373
+ const last = row2.messages[row2.messages.length - 1];
7777
8374
  return {
7778
- id: row.id,
7779
- title: row.title,
7780
- transient: row.transient,
7781
- createdAt: row.createdAt,
7782
- updatedAt: row.updatedAt,
8375
+ id: row2.id,
8376
+ title: row2.title,
8377
+ transient: row2.transient,
8378
+ createdAt: row2.createdAt,
8379
+ updatedAt: row2.updatedAt,
7783
8380
  ...last !== void 0 ? {
7784
8381
  lastMessagePreview: last.content.slice(0, 120)
7785
8382
  } : {},
7786
- defaultAgent: row.defaultAgent ?? null,
7787
- ...row.model != null ? {
7788
- model: row.model
8383
+ defaultAgent: row2.defaultAgent ?? null,
8384
+ ...row2.model != null ? {
8385
+ model: row2.model
7789
8386
  } : {},
7790
- persona: row.persona ?? null
8387
+ persona: row2.persona ?? null
7791
8388
  };
7792
8389
  }
7793
8390
  };
@@ -7795,22 +8392,22 @@ var InMemoryAgentStore = class extends InMemoryActionProposalStore {
7795
8392
  // src/confirm-token.ts
7796
8393
  import { createHash as createHash2, createHmac, timingSafeEqual } from "crypto";
7797
8394
  var DEFAULT_CONFIRM_TTL_MS = 15 * 60 * 1e3;
7798
- function canonicalJson(value) {
8395
+ function canonicalJson2(value) {
7799
8396
  if (value === void 0) return "null";
7800
8397
  if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
7801
- if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
8398
+ if (Array.isArray(value)) return `[${value.map(canonicalJson2).join(",")}]`;
7802
8399
  if (typeof value.toJSON === "function") {
7803
- return canonicalJson(value.toJSON());
8400
+ return canonicalJson2(value.toJSON());
7804
8401
  }
7805
8402
  const entries = Object.entries(value).filter(([, entry]) => entry !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
7806
- return `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`).join(",")}}`;
8403
+ return `{${entries.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson2(entry)}`).join(",")}}`;
7807
8404
  }
7808
- __name(canonicalJson, "canonicalJson");
8405
+ __name(canonicalJson2, "canonicalJson");
7809
8406
  function signature(subject, expiresAt, secret) {
7810
8407
  if (secret === "") {
7811
8408
  throw new Error("confirm token: the secret is empty");
7812
8409
  }
7813
- return createHmac("sha256", secret).update(canonicalJson([
8410
+ return createHmac("sha256", secret).update(canonicalJson2([
7814
8411
  "agent-confirm",
7815
8412
  subject.tool,
7816
8413
  subject.actorId,
@@ -8138,8 +8735,8 @@ var SqlTokenStreamSink = class {
8138
8735
  autoPurge;
8139
8736
  writes = /* @__PURE__ */ new Map();
8140
8737
  lastAutoPurge = 0;
8141
- constructor(table, options = {}) {
8142
- this.table = table;
8738
+ constructor(table2, options = {}) {
8739
+ this.table = table2;
8143
8740
  this.pollIntervalMs = Math.max(1, options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
8144
8741
  this.idlePollIntervalMs = Math.max(this.pollIntervalMs, options.idlePollIntervalMs ?? DEFAULT_IDLE_POLL_INTERVAL_MS);
8145
8742
  this.flushMs = Math.max(0, options.flushMs ?? DEFAULT_FLUSH_MS);
@@ -8281,15 +8878,15 @@ var SqlTokenStreamSink = class {
8281
8878
  let quietSince = Date.now();
8282
8879
  while (true) {
8283
8880
  const rows = await this.table.read(runId, cursor, READ_PAGE);
8284
- for (const row of rows) {
8285
- cursor = row.seq;
8286
- if (row.frame === null) {
8287
- if (row.error !== null) {
8288
- throw new AgentStreamError(JSON.parse(row.error));
8881
+ for (const row2 of rows) {
8882
+ cursor = row2.seq;
8883
+ if (row2.frame === null) {
8884
+ if (row2.error !== null) {
8885
+ throw new AgentStreamError(JSON.parse(row2.error));
8289
8886
  }
8290
8887
  return;
8291
8888
  }
8292
- yield encoder2.encode(row.frame);
8889
+ yield encoder2.encode(row2.frame);
8293
8890
  }
8294
8891
  if (rows.length > 0) {
8295
8892
  quietSince = Date.now();
@@ -8341,8 +8938,8 @@ var SqlTokenStreamSink = class {
8341
8938
  };
8342
8939
 
8343
8940
  // src/action-proposal-text.ts
8344
- function resolveTextActionProposalDecision(text, proposals) {
8345
- const command = parseTextActionProposalCommand(text);
8941
+ function resolveTextActionProposalDecision(text, proposals, vocabulary) {
8942
+ const command = parseTextActionProposalCommand(text, vocabulary);
8346
8943
  if (command.status === "unmatched") return command;
8347
8944
  const { decision, remember } = command;
8348
8945
  const pending = proposals.filter((proposal) => proposal.decision === "pending");
@@ -8377,40 +8974,136 @@ function resolveTextActionProposalDecision(text, proposals) {
8377
8974
  };
8378
8975
  }
8379
8976
  __name(resolveTextActionProposalDecision, "resolveTextActionProposalDecision");
8380
- function parseTextActionProposalCommand(text) {
8977
+ var DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY = {
8978
+ approve: [
8979
+ "yes",
8980
+ "confirm",
8981
+ "approve",
8982
+ "approved",
8983
+ "ok"
8984
+ ],
8985
+ reject: [
8986
+ "no",
8987
+ "cancel",
8988
+ "reject",
8989
+ "deny"
8990
+ ],
8991
+ remember: [
8992
+ "always in this conversation"
8993
+ ]
8994
+ };
8995
+ var DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES = {
8996
+ approved: "Proposal approved and queued to run.",
8997
+ rejected: "Proposal rejected; nothing was run.",
8998
+ expired: "The proposal expired; nothing was run.",
8999
+ unchanged: "This proposal could not be changed; refresh the list to see where it stands.",
9000
+ ambiguous: /* @__PURE__ */ __name((ids) => `Which proposal? Reply confirm #ID or cancel #ID: ${ids.join(", ")}`, "ambiguous"),
9001
+ tooMany: "There are several proposals. Confirm or reject one with an explicit #ID."
9002
+ };
9003
+ function textActionProposalReply(result2, decision, replies = DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES) {
9004
+ return result2.status === "expired" || result2.proposal?.decision === "expired" ? replies.expired : result2.status === "applied" || result2.status === "unchanged" ? decision === "approved" ? replies.approved : replies.rejected : replies.unchanged;
9005
+ }
9006
+ __name(textActionProposalReply, "textActionProposalReply");
9007
+ var escapeRegExp = /* @__PURE__ */ __name((word) => word.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "escapeRegExp");
9008
+ var alternatives = /* @__PURE__ */ __name((words) => words.map((word) => word.trim()).filter((word) => word.length > 0).map((word) => escapeRegExp(word).replace(/\s+/g, "\\s+")).join("|"), "alternatives");
9009
+ var fold = /* @__PURE__ */ __name((word) => word.trim().toLowerCase(), "fold");
9010
+ function parseTextActionProposalCommand(text, vocabulary = DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY) {
8381
9011
  if (/[\r\n]/u.test(text)) return {
8382
9012
  status: "unmatched"
8383
9013
  };
8384
- const normalized = text.trim();
8385
- const match = /^(sim|confirmo|confirmar|aprovar|aprovo|cancelar|rejeitar|rejeito|não|nao)(?: (sempre nesta conversa))?(?: #([^\s]+?))?[.!]?$/iu.exec(normalized);
9014
+ const verbs = alternatives([
9015
+ ...vocabulary.approve,
9016
+ ...vocabulary.reject
9017
+ ]);
9018
+ if (verbs.length === 0) return {
9019
+ status: "unmatched"
9020
+ };
9021
+ const remember = alternatives(vocabulary.remember);
9022
+ const match = new RegExp(`^(${verbs})${remember.length > 0 ? `(?: (${remember}))?` : "()"}(?: #([^\\s]+?))?[.!]?$`, "iu").exec(text.trim());
8386
9023
  if (!match) return {
8387
9024
  status: "unmatched"
8388
9025
  };
8389
- const verb = match[1]?.toLocaleLowerCase("pt-BR");
9026
+ const verb = match[1] === void 0 ? void 0 : fold(match[1]);
8390
9027
  if (verb === void 0) return {
8391
9028
  status: "unmatched"
8392
9029
  };
8393
- const decision = [
8394
- "cancelar",
8395
- "rejeitar",
8396
- "rejeito",
8397
- "n\xE3o",
8398
- "nao"
8399
- ].includes(verb) ? "rejected" : "approved";
8400
- const remember = match[2] !== void 0;
8401
- if (remember && decision !== "approved") return {
9030
+ const decision = vocabulary.reject.some((word) => fold(word) === verb) ? "rejected" : "approved";
9031
+ const remembers = match[2] !== void 0 && match[2] !== "";
9032
+ if (remembers && decision !== "approved") return {
8402
9033
  status: "unmatched"
8403
9034
  };
8404
9035
  return {
8405
9036
  status: "command",
8406
9037
  decision,
8407
- remember,
9038
+ remember: remembers,
8408
9039
  ...match[3] !== void 0 ? {
8409
9040
  proposalId: match[3]
8410
9041
  } : {}
8411
9042
  };
8412
9043
  }
8413
9044
  __name(parseTextActionProposalCommand, "parseTextActionProposalCommand");
9045
+ var ptBrActionProposalText = {
9046
+ vocabulary: {
9047
+ approve: [
9048
+ "sim",
9049
+ "confirmo",
9050
+ "confirmar",
9051
+ "aprovar",
9052
+ "aprovo",
9053
+ "pode",
9054
+ ...DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY.approve
9055
+ ],
9056
+ reject: [
9057
+ "n\xE3o",
9058
+ "nao",
9059
+ "cancelar",
9060
+ "cancela",
9061
+ "rejeitar",
9062
+ "rejeito",
9063
+ ...DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY.reject
9064
+ ],
9065
+ remember: [
9066
+ "sempre nesta conversa",
9067
+ ...DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY.remember
9068
+ ]
9069
+ },
9070
+ replies: {
9071
+ approved: "Proposta aprovada e enfileirada para execu\xE7\xE3o.",
9072
+ rejected: "Proposta rejeitada; nenhuma a\xE7\xE3o foi executada.",
9073
+ expired: "A proposta expirou; nenhuma a\xE7\xE3o foi executada.",
9074
+ unchanged: "N\xE3o foi poss\xEDvel alterar esta proposta; atualize a lista para consultar seu estado.",
9075
+ ambiguous: /* @__PURE__ */ __name((ids) => `Qual proposta? Responda confirmar #ID ou cancelar #ID: ${ids.join(", ")}`, "ambiguous"),
9076
+ tooMany: "H\xE1 v\xE1rias propostas. Confirme ou rejeite usando #ID expl\xEDcito."
9077
+ }
9078
+ };
9079
+
9080
+ // src/action-proposal-view.ts
9081
+ function toActionProposalView(proposal) {
9082
+ const { execution, outcomeDelivery, idempotencyKey: _idempotencyKey, preparationInput: _preparationInput, executionContext: _executionContext, ...rest } = proposal;
9083
+ return {
9084
+ ...rest,
9085
+ execution: execution === null ? null : withoutLease(execution),
9086
+ ...outcomeDelivery !== void 0 ? {
9087
+ outcomeDelivery: withoutLease(outcomeDelivery)
9088
+ } : {}
9089
+ };
9090
+ }
9091
+ __name(toActionProposalView, "toActionProposalView");
9092
+ function toActionProposalMutationView(result2) {
9093
+ const { proposal, ...rest } = result2;
9094
+ return {
9095
+ ...rest,
9096
+ ...proposal !== void 0 ? {
9097
+ proposal: toActionProposalView(proposal)
9098
+ } : {}
9099
+ };
9100
+ }
9101
+ __name(toActionProposalMutationView, "toActionProposalMutationView");
9102
+ function withoutLease(value) {
9103
+ const { lease: _lease, ...rest } = value;
9104
+ return rest;
9105
+ }
9106
+ __name(withoutLease, "withoutLease");
8414
9107
 
8415
9108
  // src/action-proposal-executor.ts
8416
9109
  var ActionProposalExecutor = class {
@@ -8642,6 +9335,37 @@ function assertIndependentActionCapabilities(store, resolver) {
8642
9335
  if (required.some((method) => typeof candidate[method] !== "function")) throw new Error("Independent action mode requires proposal, worker, outcome and admission capabilities on the conversation store");
8643
9336
  }
8644
9337
  __name(assertIndependentActionCapabilities, "assertIndependentActionCapabilities");
9338
+
9339
+ // src/functional-tool.ts
9340
+ function createFunctionalTool(definition) {
9341
+ const { input, execute, present, preflight, isEnabled, canUse, describe, kind, ...metadata } = definition;
9342
+ return {
9343
+ spec: {
9344
+ ...metadata,
9345
+ kind: kind ?? "read",
9346
+ inputSchema: input
9347
+ },
9348
+ handler: {
9349
+ execute: execute.bind(definition),
9350
+ ...present === void 0 ? {} : {
9351
+ present: present.bind(definition)
9352
+ },
9353
+ ...preflight === void 0 ? {} : {
9354
+ preflight: preflight.bind(definition)
9355
+ },
9356
+ ...isEnabled === void 0 ? {} : {
9357
+ isEnabled: isEnabled.bind(definition)
9358
+ },
9359
+ ...canUse === void 0 ? {} : {
9360
+ canUse: canUse.bind(definition)
9361
+ },
9362
+ ...describe === void 0 ? {} : {
9363
+ describe: describe.bind(definition)
9364
+ }
9365
+ }
9366
+ };
9367
+ }
9368
+ __name(createFunctionalTool, "createFunctionalTool");
8645
9369
  export {
8646
9370
  AGENT_ACTOR_DIRECTORY,
8647
9371
  AGENT_ACTOR_RESOLVER,
@@ -8691,6 +9415,8 @@ export {
8691
9415
  DEFAULT_MAX_SKILLS,
8692
9416
  DEFAULT_REFUSAL_REASON,
8693
9417
  DEFAULT_STRUCTURED_OUTPUT_INSTRUCTION,
9418
+ DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES,
9419
+ DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
8694
9420
  DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS,
8695
9421
  DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS,
8696
9422
  DefaultApprovalPolicy,
@@ -8748,12 +9474,13 @@ export {
8748
9474
  buildSkillsBlock,
8749
9475
  canActorUseTool,
8750
9476
  canonicalActionProposalJson,
8751
- canonicalJson,
9477
+ canonicalJson2 as canonicalJson,
8752
9478
  claimActionProposalOutcome,
8753
9479
  closeEmptyRoles,
8754
9480
  compositeSkillProvider,
8755
9481
  confirmTokenExpiry,
8756
9482
  createFrameBuffer,
9483
+ createFunctionalTool,
8757
9484
  createIncrementalGate,
8758
9485
  createNegotiatedUiCollector,
8759
9486
  createNoopEmitUi,
@@ -8767,6 +9494,7 @@ export {
8767
9494
  detachedDelivered,
8768
9495
  detachedStarted,
8769
9496
  detachedUnsettled,
9497
+ emitToolPresentations,
8770
9498
  encodeStreamEvent,
8771
9499
  escapeUnsafeToolUiText,
8772
9500
  estimateCost,
@@ -8805,6 +9533,7 @@ export {
8805
9533
  parseTextActionProposalCommand,
8806
9534
  personaCatalogEntry,
8807
9535
  prepareActionProposal,
9536
+ ptBrActionProposalText,
8808
9537
  publishAgentDelegated,
8809
9538
  publishAgentMemoryResolved,
8810
9539
  publishAgentMemoryWritten,
@@ -8861,6 +9590,9 @@ export {
8861
9590
  streamFailure,
8862
9591
  summarizeWithModel,
8863
9592
  tenantScope,
9593
+ textActionProposalReply,
9594
+ toActionProposalMutationView,
9595
+ toActionProposalView,
8864
9596
  toolCallApprovalFromRow,
8865
9597
  toolCallContext,
8866
9598
  traceLlmTurn,