chainlesschain 0.143.0 → 0.152.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 (227) hide show
  1. package/package.json +1 -1
  2. package/src/commands/a2a.js +196 -28
  3. package/src/commands/activitypub.js +364 -27
  4. package/src/commands/agent-network.js +217 -0
  5. package/src/commands/agent.js +587 -103
  6. package/src/commands/audit.js +206 -0
  7. package/src/commands/automation.js +201 -0
  8. package/src/commands/bi.js +355 -27
  9. package/src/commands/bm25.js +111 -27
  10. package/src/commands/browse.js +403 -29
  11. package/src/commands/ccron.js +128 -28
  12. package/src/commands/chat.js +207 -0
  13. package/src/commands/codegen.js +207 -0
  14. package/src/commands/collab.js +211 -0
  15. package/src/commands/compliance.js +824 -34
  16. package/src/commands/compt.js +127 -29
  17. package/src/commands/consol.js +8 -2
  18. package/src/commands/cowork.js +783 -34
  19. package/src/commands/crosschain.js +182 -28
  20. package/src/commands/dao.js +182 -28
  21. package/src/commands/dbevo.js +227 -0
  22. package/src/commands/dev.js +207 -0
  23. package/src/commands/did-v2.js +217 -0
  24. package/src/commands/did.js +221 -0
  25. package/src/commands/dlp.js +385 -27
  26. package/src/commands/economy.js +205 -50
  27. package/src/commands/evolution.js +203 -50
  28. package/src/commands/evomap.js +387 -27
  29. package/src/commands/export.js +213 -0
  30. package/src/commands/federation.js +209 -0
  31. package/src/commands/fflag.js +74 -22
  32. package/src/commands/fusion.js +205 -0
  33. package/src/commands/git.js +177 -37
  34. package/src/commands/governance.js +209 -0
  35. package/src/commands/hardening.js +209 -0
  36. package/src/commands/hmemory.js +204 -50
  37. package/src/commands/hook.js +209 -0
  38. package/src/commands/import.js +209 -0
  39. package/src/commands/incentive.js +209 -0
  40. package/src/commands/inference.js +170 -34
  41. package/src/commands/infra.js +203 -0
  42. package/src/commands/instinct.js +209 -0
  43. package/src/commands/ipfs.js +207 -0
  44. package/src/commands/itbudget.js +149 -33
  45. package/src/commands/kg.js +206 -0
  46. package/src/commands/llm.js +217 -0
  47. package/src/commands/lowcode.js +195 -38
  48. package/src/commands/marketplace.js +206 -0
  49. package/src/commands/matrix.js +386 -27
  50. package/src/commands/mcp.js +217 -0
  51. package/src/commands/mcpscaf.js +145 -33
  52. package/src/commands/meminj.js +145 -33
  53. package/src/commands/memory.js +209 -0
  54. package/src/commands/multimodal.js +203 -0
  55. package/src/commands/nlprog.js +225 -0
  56. package/src/commands/nostr.js +387 -27
  57. package/src/commands/note.js +205 -0
  58. package/src/commands/ops.js +219 -0
  59. package/src/commands/orchestrate.js +217 -0
  60. package/src/commands/orchgov.js +144 -33
  61. package/src/commands/org.js +209 -0
  62. package/src/commands/p2p.js +209 -0
  63. package/src/commands/pdfp.js +109 -27
  64. package/src/commands/perception.js +209 -0
  65. package/src/commands/perf.js +169 -32
  66. package/src/commands/perm.js +144 -33
  67. package/src/commands/permmem.js +203 -0
  68. package/src/commands/pipeline.js +207 -52
  69. package/src/commands/planmode.js +141 -32
  70. package/src/commands/plugin-ecosystem.js +209 -0
  71. package/src/commands/pqc.js +213 -0
  72. package/src/commands/privacy.js +203 -0
  73. package/src/commands/promcomp.js +111 -27
  74. package/src/commands/quantization.js +207 -0
  75. package/src/commands/rcache.js +205 -0
  76. package/src/commands/recommend.js +410 -34
  77. package/src/commands/reputation.js +208 -0
  78. package/src/commands/runtime.js +205 -0
  79. package/src/commands/sandbox.js +206 -0
  80. package/src/commands/scim.js +209 -0
  81. package/src/commands/seshhook.js +145 -33
  82. package/src/commands/seshsearch.js +141 -33
  83. package/src/commands/seshtail.js +144 -33
  84. package/src/commands/seshu.js +152 -33
  85. package/src/commands/session.js +209 -0
  86. package/src/commands/sganal.js +123 -29
  87. package/src/commands/siem.js +201 -34
  88. package/src/commands/skill.js +207 -0
  89. package/src/commands/sla.js +212 -0
  90. package/src/commands/slotfill.js +146 -33
  91. package/src/commands/social.js +358 -32
  92. package/src/commands/sso.js +209 -0
  93. package/src/commands/stress.js +206 -0
  94. package/src/commands/svccont.js +145 -33
  95. package/src/commands/sync.js +209 -0
  96. package/src/commands/tech.js +209 -0
  97. package/src/commands/tenant.js +217 -0
  98. package/src/commands/terraform.js +206 -0
  99. package/src/commands/tms.js +171 -33
  100. package/src/commands/tokens.js +209 -0
  101. package/src/commands/topiccls.js +146 -33
  102. package/src/commands/trust.js +217 -0
  103. package/src/commands/uprof.js +141 -32
  104. package/src/commands/vcheck.js +122 -28
  105. package/src/commands/wallet.js +209 -0
  106. package/src/commands/webfetch.js +141 -32
  107. package/src/commands/workflow.js +203 -0
  108. package/src/commands/zkp.js +184 -28
  109. package/src/index.js +180 -0
  110. package/src/lib/a2a-protocol.js +319 -51
  111. package/src/lib/activitypub-bridge.js +622 -50
  112. package/src/lib/agent-economy.js +304 -51
  113. package/src/lib/agent-network.js +341 -0
  114. package/src/lib/aiops.js +346 -0
  115. package/src/lib/app-builder.js +279 -46
  116. package/src/lib/audit-logger.js +321 -0
  117. package/src/lib/automation-engine.js +335 -0
  118. package/src/lib/autonomous-agent.js +284 -48
  119. package/src/lib/autonomous-developer.js +332 -0
  120. package/src/lib/bi-engine.js +616 -49
  121. package/src/lib/bm25-search.js +301 -49
  122. package/src/lib/browser-automation.js +630 -49
  123. package/src/lib/chat-core.js +336 -0
  124. package/src/lib/claude-code-bridge.js +341 -0
  125. package/src/lib/code-agent.js +339 -0
  126. package/src/lib/collaboration-governance.js +334 -0
  127. package/src/lib/community-governance.js +346 -0
  128. package/src/lib/compliance-framework-reporter.js +305 -51
  129. package/src/lib/compliance-manager.js +330 -0
  130. package/src/lib/compression-telemetry.js +301 -49
  131. package/src/lib/content-recommendation.js +351 -0
  132. package/src/lib/content-recommender.js +317 -52
  133. package/src/lib/cowork-cron.js +298 -49
  134. package/src/lib/cowork-learning.js +333 -0
  135. package/src/lib/cowork-share.js +338 -0
  136. package/src/lib/cowork-task-runner.js +308 -51
  137. package/src/lib/cowork-workflow.js +327 -0
  138. package/src/lib/cross-chain.js +311 -51
  139. package/src/lib/dao-governance.js +280 -46
  140. package/src/lib/dbevo.js +351 -0
  141. package/src/lib/decentral-infra.js +330 -0
  142. package/src/lib/did-manager.js +341 -0
  143. package/src/lib/did-v2-manager.js +341 -0
  144. package/src/lib/dlp-engine.js +626 -49
  145. package/src/lib/evolution-system.js +278 -47
  146. package/src/lib/evomap-governance.js +334 -0
  147. package/src/lib/evomap-manager.js +280 -46
  148. package/src/lib/execution-backend.js +294 -48
  149. package/src/lib/feature-flags.js +294 -49
  150. package/src/lib/federation-hardening.js +340 -0
  151. package/src/lib/git-integration.js +285 -47
  152. package/src/lib/hardening-manager.js +341 -0
  153. package/src/lib/hierarchical-memory.js +284 -48
  154. package/src/lib/hook-manager.js +341 -0
  155. package/src/lib/inference-network.js +308 -51
  156. package/src/lib/instinct-manager.js +346 -0
  157. package/src/lib/ipfs-storage.js +334 -0
  158. package/src/lib/iteration-budget.js +302 -50
  159. package/src/lib/knowledge-exporter.js +341 -0
  160. package/src/lib/knowledge-graph.js +333 -0
  161. package/src/lib/knowledge-importer.js +341 -0
  162. package/src/lib/llm-providers.js +346 -0
  163. package/src/lib/matrix-bridge.js +620 -47
  164. package/src/lib/mcp-registry.js +346 -0
  165. package/src/lib/mcp-scaffold.js +318 -54
  166. package/src/lib/memory-injection.js +288 -49
  167. package/src/lib/memory-manager.js +336 -0
  168. package/src/lib/multimodal.js +330 -0
  169. package/src/lib/nl-programming.js +341 -0
  170. package/src/lib/nostr-bridge.js +622 -49
  171. package/src/lib/note-versioning.js +339 -0
  172. package/src/lib/orchestrator.js +293 -48
  173. package/src/lib/org-manager.js +336 -0
  174. package/src/lib/p2p-manager.js +341 -0
  175. package/src/lib/pdf-parser.js +298 -49
  176. package/src/lib/perception.js +346 -0
  177. package/src/lib/perf-tuning.js +309 -50
  178. package/src/lib/permanent-memory.js +327 -0
  179. package/src/lib/permission-engine.js +287 -49
  180. package/src/lib/pipeline-orchestrator.js +289 -49
  181. package/src/lib/plan-mode.js +298 -51
  182. package/src/lib/plugin-ecosystem.js +346 -0
  183. package/src/lib/pqc-manager.js +346 -0
  184. package/src/lib/privacy-computing.js +335 -0
  185. package/src/lib/protocol-fusion.js +338 -0
  186. package/src/lib/quantization.js +337 -0
  187. package/src/lib/reputation-optimizer.js +340 -0
  188. package/src/lib/response-cache.js +333 -0
  189. package/src/lib/sandbox-v2.js +327 -0
  190. package/src/lib/scim-manager.js +346 -0
  191. package/src/lib/service-container.js +313 -52
  192. package/src/lib/session-consolidator.js +296 -49
  193. package/src/lib/session-hooks.js +312 -53
  194. package/src/lib/session-manager.js +334 -0
  195. package/src/lib/session-search.js +304 -51
  196. package/src/lib/session-tail.js +288 -49
  197. package/src/lib/session-usage.js +298 -52
  198. package/src/lib/siem-exporter.js +298 -51
  199. package/src/lib/skill-loader.js +334 -0
  200. package/src/lib/skill-marketplace.js +345 -0
  201. package/src/lib/sla-manager.js +341 -0
  202. package/src/lib/slot-filler.js +303 -51
  203. package/src/lib/social-graph-analytics.js +295 -49
  204. package/src/lib/social-graph.js +272 -49
  205. package/src/lib/social-manager.js +330 -0
  206. package/src/lib/sso-manager.js +340 -0
  207. package/src/lib/stress-tester.js +342 -0
  208. package/src/lib/sub-agent-registry.js +302 -53
  209. package/src/lib/sync-manager.js +336 -0
  210. package/src/lib/task-model-selector.js +302 -50
  211. package/src/lib/tech-learning-engine.js +341 -0
  212. package/src/lib/tenant-saas.js +341 -0
  213. package/src/lib/terraform-manager.js +333 -0
  214. package/src/lib/threat-intel.js +330 -0
  215. package/src/lib/todo-manager.js +281 -47
  216. package/src/lib/token-incentive.js +341 -0
  217. package/src/lib/token-tracker.js +336 -0
  218. package/src/lib/topic-classifier.js +297 -49
  219. package/src/lib/trust-security.js +343 -0
  220. package/src/lib/ueba.js +340 -0
  221. package/src/lib/universal-runtime.js +330 -0
  222. package/src/lib/user-profile.js +294 -50
  223. package/src/lib/version-checker.js +304 -50
  224. package/src/lib/wallet-manager.js +336 -0
  225. package/src/lib/web-fetch.js +292 -51
  226. package/src/lib/workflow-engine.js +330 -0
  227. package/src/lib/zkp-engine.js +286 -49
@@ -599,81 +599,333 @@ Keep values concise (single words or short strings).`;
599
599
 
600
600
  // ===== V2 Surface: Slot Filler governance overlay (CLI v0.142.0) =====
601
601
  export const SLOTF_PROFILE_MATURITY_V2 = Object.freeze({
602
- PENDING: "pending", ACTIVE: "active", STALE: "stale", ARCHIVED: "archived",
602
+ PENDING: "pending",
603
+ ACTIVE: "active",
604
+ STALE: "stale",
605
+ ARCHIVED: "archived",
603
606
  });
604
607
  export const SLOTF_FILL_LIFECYCLE_V2 = Object.freeze({
605
- QUEUED: "queued", FILLING: "filling", FILLED: "filled", FAILED: "failed", CANCELLED: "cancelled",
608
+ QUEUED: "queued",
609
+ FILLING: "filling",
610
+ FILLED: "filled",
611
+ FAILED: "failed",
612
+ CANCELLED: "cancelled",
606
613
  });
607
614
  const _slotfPTrans = new Map([
608
- [SLOTF_PROFILE_MATURITY_V2.PENDING, new Set([SLOTF_PROFILE_MATURITY_V2.ACTIVE, SLOTF_PROFILE_MATURITY_V2.ARCHIVED])],
609
- [SLOTF_PROFILE_MATURITY_V2.ACTIVE, new Set([SLOTF_PROFILE_MATURITY_V2.STALE, SLOTF_PROFILE_MATURITY_V2.ARCHIVED])],
610
- [SLOTF_PROFILE_MATURITY_V2.STALE, new Set([SLOTF_PROFILE_MATURITY_V2.ACTIVE, SLOTF_PROFILE_MATURITY_V2.ARCHIVED])],
615
+ [
616
+ SLOTF_PROFILE_MATURITY_V2.PENDING,
617
+ new Set([
618
+ SLOTF_PROFILE_MATURITY_V2.ACTIVE,
619
+ SLOTF_PROFILE_MATURITY_V2.ARCHIVED,
620
+ ]),
621
+ ],
622
+ [
623
+ SLOTF_PROFILE_MATURITY_V2.ACTIVE,
624
+ new Set([
625
+ SLOTF_PROFILE_MATURITY_V2.STALE,
626
+ SLOTF_PROFILE_MATURITY_V2.ARCHIVED,
627
+ ]),
628
+ ],
629
+ [
630
+ SLOTF_PROFILE_MATURITY_V2.STALE,
631
+ new Set([
632
+ SLOTF_PROFILE_MATURITY_V2.ACTIVE,
633
+ SLOTF_PROFILE_MATURITY_V2.ARCHIVED,
634
+ ]),
635
+ ],
611
636
  [SLOTF_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
612
637
  ]);
613
638
  const _slotfPTerminal = new Set([SLOTF_PROFILE_MATURITY_V2.ARCHIVED]);
614
639
  const _slotfFTrans = new Map([
615
- [SLOTF_FILL_LIFECYCLE_V2.QUEUED, new Set([SLOTF_FILL_LIFECYCLE_V2.FILLING, SLOTF_FILL_LIFECYCLE_V2.CANCELLED])],
616
- [SLOTF_FILL_LIFECYCLE_V2.FILLING, new Set([SLOTF_FILL_LIFECYCLE_V2.FILLED, SLOTF_FILL_LIFECYCLE_V2.FAILED, SLOTF_FILL_LIFECYCLE_V2.CANCELLED])],
640
+ [
641
+ SLOTF_FILL_LIFECYCLE_V2.QUEUED,
642
+ new Set([
643
+ SLOTF_FILL_LIFECYCLE_V2.FILLING,
644
+ SLOTF_FILL_LIFECYCLE_V2.CANCELLED,
645
+ ]),
646
+ ],
647
+ [
648
+ SLOTF_FILL_LIFECYCLE_V2.FILLING,
649
+ new Set([
650
+ SLOTF_FILL_LIFECYCLE_V2.FILLED,
651
+ SLOTF_FILL_LIFECYCLE_V2.FAILED,
652
+ SLOTF_FILL_LIFECYCLE_V2.CANCELLED,
653
+ ]),
654
+ ],
617
655
  [SLOTF_FILL_LIFECYCLE_V2.FILLED, new Set()],
618
656
  [SLOTF_FILL_LIFECYCLE_V2.FAILED, new Set()],
619
657
  [SLOTF_FILL_LIFECYCLE_V2.CANCELLED, new Set()],
620
658
  ]);
621
659
  const _slotfPsV2 = new Map();
622
660
  const _slotfFsV2 = new Map();
623
- let _slotfMaxActive = 10, _slotfMaxPending = 20, _slotfIdleMs = 30 * 24 * 60 * 60 * 1000, _slotfStuckMs = 30 * 1000;
624
- function _slotfPos(n, label) { const v = Math.floor(Number(n)); if (!Number.isFinite(v) || v <= 0) throw new Error(`${label} must be positive integer`); return v; }
625
- function _slotfCheckP(from, to) { const a = _slotfPTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid slotf profile transition ${from} → ${to}`); }
626
- function _slotfCheckF(from, to) { const a = _slotfFTrans.get(from); if (!a || !a.has(to)) throw new Error(`invalid slotf fill transition ${from} → ${to}`); }
627
- export function setMaxActiveSlotfTemplatesPerOwnerV2(n) { _slotfMaxActive = _slotfPos(n, "maxActiveSlotfTemplatesPerOwner"); }
628
- export function getMaxActiveSlotfTemplatesPerOwnerV2() { return _slotfMaxActive; }
629
- export function setMaxPendingSlotfFillsPerTemplateV2(n) { _slotfMaxPending = _slotfPos(n, "maxPendingSlotfFillsPerTemplate"); }
630
- export function getMaxPendingSlotfFillsPerTemplateV2() { return _slotfMaxPending; }
631
- export function setSlotfTemplateIdleMsV2(n) { _slotfIdleMs = _slotfPos(n, "slotfTemplateIdleMs"); }
632
- export function getSlotfTemplateIdleMsV2() { return _slotfIdleMs; }
633
- export function setSlotfFillStuckMsV2(n) { _slotfStuckMs = _slotfPos(n, "slotfFillStuckMs"); }
634
- export function getSlotfFillStuckMsV2() { return _slotfStuckMs; }
635
- export function _resetStateSlotFillerV2() { _slotfPsV2.clear(); _slotfFsV2.clear(); _slotfMaxActive = 10; _slotfMaxPending = 20; _slotfIdleMs = 30 * 24 * 60 * 60 * 1000; _slotfStuckMs = 30 * 1000; }
661
+ let _slotfMaxActive = 10,
662
+ _slotfMaxPending = 20,
663
+ _slotfIdleMs = 30 * 24 * 60 * 60 * 1000,
664
+ _slotfStuckMs = 30 * 1000;
665
+ function _slotfPos(n, label) {
666
+ const v = Math.floor(Number(n));
667
+ if (!Number.isFinite(v) || v <= 0)
668
+ throw new Error(`${label} must be positive integer`);
669
+ return v;
670
+ }
671
+ function _slotfCheckP(from, to) {
672
+ const a = _slotfPTrans.get(from);
673
+ if (!a || !a.has(to))
674
+ throw new Error(`invalid slotf profile transition ${from} → ${to}`);
675
+ }
676
+ function _slotfCheckF(from, to) {
677
+ const a = _slotfFTrans.get(from);
678
+ if (!a || !a.has(to))
679
+ throw new Error(`invalid slotf fill transition ${from} → ${to}`);
680
+ }
681
+ export function setMaxActiveSlotfTemplatesPerOwnerV2(n) {
682
+ _slotfMaxActive = _slotfPos(n, "maxActiveSlotfTemplatesPerOwner");
683
+ }
684
+ export function getMaxActiveSlotfTemplatesPerOwnerV2() {
685
+ return _slotfMaxActive;
686
+ }
687
+ export function setMaxPendingSlotfFillsPerTemplateV2(n) {
688
+ _slotfMaxPending = _slotfPos(n, "maxPendingSlotfFillsPerTemplate");
689
+ }
690
+ export function getMaxPendingSlotfFillsPerTemplateV2() {
691
+ return _slotfMaxPending;
692
+ }
693
+ export function setSlotfTemplateIdleMsV2(n) {
694
+ _slotfIdleMs = _slotfPos(n, "slotfTemplateIdleMs");
695
+ }
696
+ export function getSlotfTemplateIdleMsV2() {
697
+ return _slotfIdleMs;
698
+ }
699
+ export function setSlotfFillStuckMsV2(n) {
700
+ _slotfStuckMs = _slotfPos(n, "slotfFillStuckMs");
701
+ }
702
+ export function getSlotfFillStuckMsV2() {
703
+ return _slotfStuckMs;
704
+ }
705
+ export function _resetStateSlotFillerV2() {
706
+ _slotfPsV2.clear();
707
+ _slotfFsV2.clear();
708
+ _slotfMaxActive = 10;
709
+ _slotfMaxPending = 20;
710
+ _slotfIdleMs = 30 * 24 * 60 * 60 * 1000;
711
+ _slotfStuckMs = 30 * 1000;
712
+ }
636
713
  export function registerSlotfTemplateV2({ id, owner, schema, metadata } = {}) {
637
- if (!id) throw new Error("slotf template id required"); if (!owner) throw new Error("slotf template owner required");
638
- if (_slotfPsV2.has(id)) throw new Error(`slotf template ${id} already registered`);
714
+ if (!id) throw new Error("slotf template id required");
715
+ if (!owner) throw new Error("slotf template owner required");
716
+ if (_slotfPsV2.has(id))
717
+ throw new Error(`slotf template ${id} already registered`);
639
718
  const now = Date.now();
640
- const p = { id, owner, schema: schema || "{}", status: SLOTF_PROFILE_MATURITY_V2.PENDING, createdAt: now, updatedAt: now, activatedAt: null, archivedAt: null, lastTouchedAt: now, metadata: { ...(metadata || {}) } };
641
- _slotfPsV2.set(id, p); return { ...p, metadata: { ...p.metadata } };
719
+ const p = {
720
+ id,
721
+ owner,
722
+ schema: schema || "{}",
723
+ status: SLOTF_PROFILE_MATURITY_V2.PENDING,
724
+ createdAt: now,
725
+ updatedAt: now,
726
+ activatedAt: null,
727
+ archivedAt: null,
728
+ lastTouchedAt: now,
729
+ metadata: { ...(metadata || {}) },
730
+ };
731
+ _slotfPsV2.set(id, p);
732
+ return { ...p, metadata: { ...p.metadata } };
733
+ }
734
+ function _slotfCountActive(owner) {
735
+ let n = 0;
736
+ for (const p of _slotfPsV2.values())
737
+ if (p.owner === owner && p.status === SLOTF_PROFILE_MATURITY_V2.ACTIVE) n++;
738
+ return n;
642
739
  }
643
- function _slotfCountActive(owner) { let n = 0; for (const p of _slotfPsV2.values()) if (p.owner === owner && p.status === SLOTF_PROFILE_MATURITY_V2.ACTIVE) n++; return n; }
644
740
  export function activateSlotfTemplateV2(id) {
645
- const p = _slotfPsV2.get(id); if (!p) throw new Error(`slotf template ${id} not found`);
741
+ const p = _slotfPsV2.get(id);
742
+ if (!p) throw new Error(`slotf template ${id} not found`);
646
743
  _slotfCheckP(p.status, SLOTF_PROFILE_MATURITY_V2.ACTIVE);
647
744
  const recovery = p.status === SLOTF_PROFILE_MATURITY_V2.STALE;
648
- if (!recovery && _slotfCountActive(p.owner) >= _slotfMaxActive) throw new Error(`max active slotf templates for owner ${p.owner} reached`);
649
- const now = Date.now(); p.status = SLOTF_PROFILE_MATURITY_V2.ACTIVE; p.updatedAt = now; p.lastTouchedAt = now; if (!p.activatedAt) p.activatedAt = now;
745
+ if (!recovery && _slotfCountActive(p.owner) >= _slotfMaxActive)
746
+ throw new Error(`max active slotf templates for owner ${p.owner} reached`);
747
+ const now = Date.now();
748
+ p.status = SLOTF_PROFILE_MATURITY_V2.ACTIVE;
749
+ p.updatedAt = now;
750
+ p.lastTouchedAt = now;
751
+ if (!p.activatedAt) p.activatedAt = now;
752
+ return { ...p, metadata: { ...p.metadata } };
753
+ }
754
+ export function staleSlotfTemplateV2(id) {
755
+ const p = _slotfPsV2.get(id);
756
+ if (!p) throw new Error(`slotf template ${id} not found`);
757
+ _slotfCheckP(p.status, SLOTF_PROFILE_MATURITY_V2.STALE);
758
+ p.status = SLOTF_PROFILE_MATURITY_V2.STALE;
759
+ p.updatedAt = Date.now();
650
760
  return { ...p, metadata: { ...p.metadata } };
651
761
  }
652
- export function staleSlotfTemplateV2(id) { const p = _slotfPsV2.get(id); if (!p) throw new Error(`slotf template ${id} not found`); _slotfCheckP(p.status, SLOTF_PROFILE_MATURITY_V2.STALE); p.status = SLOTF_PROFILE_MATURITY_V2.STALE; p.updatedAt = Date.now(); return { ...p, metadata: { ...p.metadata } }; }
653
- export function archiveSlotfTemplateV2(id) { const p = _slotfPsV2.get(id); if (!p) throw new Error(`slotf template ${id} not found`); _slotfCheckP(p.status, SLOTF_PROFILE_MATURITY_V2.ARCHIVED); const now = Date.now(); p.status = SLOTF_PROFILE_MATURITY_V2.ARCHIVED; p.updatedAt = now; if (!p.archivedAt) p.archivedAt = now; return { ...p, metadata: { ...p.metadata } }; }
654
- export function touchSlotfTemplateV2(id) { const p = _slotfPsV2.get(id); if (!p) throw new Error(`slotf template ${id} not found`); if (_slotfPTerminal.has(p.status)) throw new Error(`cannot touch terminal slotf template ${id}`); const now = Date.now(); p.lastTouchedAt = now; p.updatedAt = now; return { ...p, metadata: { ...p.metadata } }; }
655
- export function getSlotfTemplateV2(id) { const p = _slotfPsV2.get(id); if (!p) return null; return { ...p, metadata: { ...p.metadata } }; }
656
- export function listSlotfTemplatesV2() { return [..._slotfPsV2.values()].map((p) => ({ ...p, metadata: { ...p.metadata } })); }
657
- function _slotfCountPending(templateId) { let n = 0; for (const f of _slotfFsV2.values()) if (f.templateId === templateId && (f.status === SLOTF_FILL_LIFECYCLE_V2.QUEUED || f.status === SLOTF_FILL_LIFECYCLE_V2.FILLING)) n++; return n; }
762
+ export function archiveSlotfTemplateV2(id) {
763
+ const p = _slotfPsV2.get(id);
764
+ if (!p) throw new Error(`slotf template ${id} not found`);
765
+ _slotfCheckP(p.status, SLOTF_PROFILE_MATURITY_V2.ARCHIVED);
766
+ const now = Date.now();
767
+ p.status = SLOTF_PROFILE_MATURITY_V2.ARCHIVED;
768
+ p.updatedAt = now;
769
+ if (!p.archivedAt) p.archivedAt = now;
770
+ return { ...p, metadata: { ...p.metadata } };
771
+ }
772
+ export function touchSlotfTemplateV2(id) {
773
+ const p = _slotfPsV2.get(id);
774
+ if (!p) throw new Error(`slotf template ${id} not found`);
775
+ if (_slotfPTerminal.has(p.status))
776
+ throw new Error(`cannot touch terminal slotf template ${id}`);
777
+ const now = Date.now();
778
+ p.lastTouchedAt = now;
779
+ p.updatedAt = now;
780
+ return { ...p, metadata: { ...p.metadata } };
781
+ }
782
+ export function getSlotfTemplateV2(id) {
783
+ const p = _slotfPsV2.get(id);
784
+ if (!p) return null;
785
+ return { ...p, metadata: { ...p.metadata } };
786
+ }
787
+ export function listSlotfTemplatesV2() {
788
+ return [..._slotfPsV2.values()].map((p) => ({
789
+ ...p,
790
+ metadata: { ...p.metadata },
791
+ }));
792
+ }
793
+ function _slotfCountPending(templateId) {
794
+ let n = 0;
795
+ for (const f of _slotfFsV2.values())
796
+ if (
797
+ f.templateId === templateId &&
798
+ (f.status === SLOTF_FILL_LIFECYCLE_V2.QUEUED ||
799
+ f.status === SLOTF_FILL_LIFECYCLE_V2.FILLING)
800
+ )
801
+ n++;
802
+ return n;
803
+ }
658
804
  export function createSlotfFillV2({ id, templateId, input, metadata } = {}) {
659
- if (!id) throw new Error("slotf fill id required"); if (!templateId) throw new Error("slotf fill templateId required");
805
+ if (!id) throw new Error("slotf fill id required");
806
+ if (!templateId) throw new Error("slotf fill templateId required");
660
807
  if (_slotfFsV2.has(id)) throw new Error(`slotf fill ${id} already exists`);
661
- if (!_slotfPsV2.has(templateId)) throw new Error(`slotf template ${templateId} not found`);
662
- if (_slotfCountPending(templateId) >= _slotfMaxPending) throw new Error(`max pending slotf fills for template ${templateId} reached`);
808
+ if (!_slotfPsV2.has(templateId))
809
+ throw new Error(`slotf template ${templateId} not found`);
810
+ if (_slotfCountPending(templateId) >= _slotfMaxPending)
811
+ throw new Error(
812
+ `max pending slotf fills for template ${templateId} reached`,
813
+ );
663
814
  const now = Date.now();
664
- const f = { id, templateId, input: input || "", status: SLOTF_FILL_LIFECYCLE_V2.QUEUED, createdAt: now, updatedAt: now, startedAt: null, settledAt: null, metadata: { ...(metadata || {}) } };
665
- _slotfFsV2.set(id, f); return { ...f, metadata: { ...f.metadata } };
666
- }
667
- export function fillingSlotfFillV2(id) { const f = _slotfFsV2.get(id); if (!f) throw new Error(`slotf fill ${id} not found`); _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FILLING); const now = Date.now(); f.status = SLOTF_FILL_LIFECYCLE_V2.FILLING; f.updatedAt = now; if (!f.startedAt) f.startedAt = now; return { ...f, metadata: { ...f.metadata } }; }
668
- export function fillSlotfFillV2(id) { const f = _slotfFsV2.get(id); if (!f) throw new Error(`slotf fill ${id} not found`); _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FILLED); const now = Date.now(); f.status = SLOTF_FILL_LIFECYCLE_V2.FILLED; f.updatedAt = now; if (!f.settledAt) f.settledAt = now; return { ...f, metadata: { ...f.metadata } }; }
669
- export function failSlotfFillV2(id, reason) { const f = _slotfFsV2.get(id); if (!f) throw new Error(`slotf fill ${id} not found`); _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FAILED); const now = Date.now(); f.status = SLOTF_FILL_LIFECYCLE_V2.FAILED; f.updatedAt = now; if (!f.settledAt) f.settledAt = now; if (reason) f.metadata.failReason = String(reason); return { ...f, metadata: { ...f.metadata } }; }
670
- export function cancelSlotfFillV2(id, reason) { const f = _slotfFsV2.get(id); if (!f) throw new Error(`slotf fill ${id} not found`); _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.CANCELLED); const now = Date.now(); f.status = SLOTF_FILL_LIFECYCLE_V2.CANCELLED; f.updatedAt = now; if (!f.settledAt) f.settledAt = now; if (reason) f.metadata.cancelReason = String(reason); return { ...f, metadata: { ...f.metadata } }; }
671
- export function getSlotfFillV2(id) { const f = _slotfFsV2.get(id); if (!f) return null; return { ...f, metadata: { ...f.metadata } }; }
672
- export function listSlotfFillsV2() { return [..._slotfFsV2.values()].map((f) => ({ ...f, metadata: { ...f.metadata } })); }
673
- export function autoStaleIdleSlotfTemplatesV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const p of _slotfPsV2.values()) if (p.status === SLOTF_PROFILE_MATURITY_V2.ACTIVE && (t - p.lastTouchedAt) >= _slotfIdleMs) { p.status = SLOTF_PROFILE_MATURITY_V2.STALE; p.updatedAt = t; flipped.push(p.id); } return { flipped, count: flipped.length }; }
674
- export function autoFailStuckSlotfFillsV2({ now } = {}) { const t = now ?? Date.now(); const flipped = []; for (const f of _slotfFsV2.values()) if (f.status === SLOTF_FILL_LIFECYCLE_V2.FILLING && f.startedAt != null && (t - f.startedAt) >= _slotfStuckMs) { f.status = SLOTF_FILL_LIFECYCLE_V2.FAILED; f.updatedAt = t; if (!f.settledAt) f.settledAt = t; f.metadata.failReason = "auto-fail-stuck"; flipped.push(f.id); } return { flipped, count: flipped.length }; }
815
+ const f = {
816
+ id,
817
+ templateId,
818
+ input: input || "",
819
+ status: SLOTF_FILL_LIFECYCLE_V2.QUEUED,
820
+ createdAt: now,
821
+ updatedAt: now,
822
+ startedAt: null,
823
+ settledAt: null,
824
+ metadata: { ...(metadata || {}) },
825
+ };
826
+ _slotfFsV2.set(id, f);
827
+ return { ...f, metadata: { ...f.metadata } };
828
+ }
829
+ export function fillingSlotfFillV2(id) {
830
+ const f = _slotfFsV2.get(id);
831
+ if (!f) throw new Error(`slotf fill ${id} not found`);
832
+ _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FILLING);
833
+ const now = Date.now();
834
+ f.status = SLOTF_FILL_LIFECYCLE_V2.FILLING;
835
+ f.updatedAt = now;
836
+ if (!f.startedAt) f.startedAt = now;
837
+ return { ...f, metadata: { ...f.metadata } };
838
+ }
839
+ export function fillSlotfFillV2(id) {
840
+ const f = _slotfFsV2.get(id);
841
+ if (!f) throw new Error(`slotf fill ${id} not found`);
842
+ _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FILLED);
843
+ const now = Date.now();
844
+ f.status = SLOTF_FILL_LIFECYCLE_V2.FILLED;
845
+ f.updatedAt = now;
846
+ if (!f.settledAt) f.settledAt = now;
847
+ return { ...f, metadata: { ...f.metadata } };
848
+ }
849
+ export function failSlotfFillV2(id, reason) {
850
+ const f = _slotfFsV2.get(id);
851
+ if (!f) throw new Error(`slotf fill ${id} not found`);
852
+ _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.FAILED);
853
+ const now = Date.now();
854
+ f.status = SLOTF_FILL_LIFECYCLE_V2.FAILED;
855
+ f.updatedAt = now;
856
+ if (!f.settledAt) f.settledAt = now;
857
+ if (reason) f.metadata.failReason = String(reason);
858
+ return { ...f, metadata: { ...f.metadata } };
859
+ }
860
+ export function cancelSlotfFillV2(id, reason) {
861
+ const f = _slotfFsV2.get(id);
862
+ if (!f) throw new Error(`slotf fill ${id} not found`);
863
+ _slotfCheckF(f.status, SLOTF_FILL_LIFECYCLE_V2.CANCELLED);
864
+ const now = Date.now();
865
+ f.status = SLOTF_FILL_LIFECYCLE_V2.CANCELLED;
866
+ f.updatedAt = now;
867
+ if (!f.settledAt) f.settledAt = now;
868
+ if (reason) f.metadata.cancelReason = String(reason);
869
+ return { ...f, metadata: { ...f.metadata } };
870
+ }
871
+ export function getSlotfFillV2(id) {
872
+ const f = _slotfFsV2.get(id);
873
+ if (!f) return null;
874
+ return { ...f, metadata: { ...f.metadata } };
875
+ }
876
+ export function listSlotfFillsV2() {
877
+ return [..._slotfFsV2.values()].map((f) => ({
878
+ ...f,
879
+ metadata: { ...f.metadata },
880
+ }));
881
+ }
882
+ export function autoStaleIdleSlotfTemplatesV2({ now } = {}) {
883
+ const t = now ?? Date.now();
884
+ const flipped = [];
885
+ for (const p of _slotfPsV2.values())
886
+ if (
887
+ p.status === SLOTF_PROFILE_MATURITY_V2.ACTIVE &&
888
+ t - p.lastTouchedAt >= _slotfIdleMs
889
+ ) {
890
+ p.status = SLOTF_PROFILE_MATURITY_V2.STALE;
891
+ p.updatedAt = t;
892
+ flipped.push(p.id);
893
+ }
894
+ return { flipped, count: flipped.length };
895
+ }
896
+ export function autoFailStuckSlotfFillsV2({ now } = {}) {
897
+ const t = now ?? Date.now();
898
+ const flipped = [];
899
+ for (const f of _slotfFsV2.values())
900
+ if (
901
+ f.status === SLOTF_FILL_LIFECYCLE_V2.FILLING &&
902
+ f.startedAt != null &&
903
+ t - f.startedAt >= _slotfStuckMs
904
+ ) {
905
+ f.status = SLOTF_FILL_LIFECYCLE_V2.FAILED;
906
+ f.updatedAt = t;
907
+ if (!f.settledAt) f.settledAt = t;
908
+ f.metadata.failReason = "auto-fail-stuck";
909
+ flipped.push(f.id);
910
+ }
911
+ return { flipped, count: flipped.length };
912
+ }
675
913
  export function getSlotFillerGovStatsV2() {
676
- const templatesByStatus = {}; for (const v of Object.values(SLOTF_PROFILE_MATURITY_V2)) templatesByStatus[v] = 0; for (const p of _slotfPsV2.values()) templatesByStatus[p.status]++;
677
- const fillsByStatus = {}; for (const v of Object.values(SLOTF_FILL_LIFECYCLE_V2)) fillsByStatus[v] = 0; for (const f of _slotfFsV2.values()) fillsByStatus[f.status]++;
678
- return { totalSlotfTemplatesV2: _slotfPsV2.size, totalSlotfFillsV2: _slotfFsV2.size, maxActiveSlotfTemplatesPerOwner: _slotfMaxActive, maxPendingSlotfFillsPerTemplate: _slotfMaxPending, slotfTemplateIdleMs: _slotfIdleMs, slotfFillStuckMs: _slotfStuckMs, templatesByStatus, fillsByStatus };
914
+ const templatesByStatus = {};
915
+ for (const v of Object.values(SLOTF_PROFILE_MATURITY_V2))
916
+ templatesByStatus[v] = 0;
917
+ for (const p of _slotfPsV2.values()) templatesByStatus[p.status]++;
918
+ const fillsByStatus = {};
919
+ for (const v of Object.values(SLOTF_FILL_LIFECYCLE_V2)) fillsByStatus[v] = 0;
920
+ for (const f of _slotfFsV2.values()) fillsByStatus[f.status]++;
921
+ return {
922
+ totalSlotfTemplatesV2: _slotfPsV2.size,
923
+ totalSlotfFillsV2: _slotfFsV2.size,
924
+ maxActiveSlotfTemplatesPerOwner: _slotfMaxActive,
925
+ maxPendingSlotfFillsPerTemplate: _slotfMaxPending,
926
+ slotfTemplateIdleMs: _slotfIdleMs,
927
+ slotfFillStuckMs: _slotfStuckMs,
928
+ templatesByStatus,
929
+ fillsByStatus,
930
+ };
679
931
  }