@agimon-ai/po-cloudflare 0.0.2-alpha.35 → 0.0.2-alpha.37

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 (267) hide show
  1. package/dist/{abort-signals-2GUraIGq.js → abort-signals-DG56Ik_S.js} +1 -1
  2. package/dist/{agent-Cz2YY3Z9.js → agent-DYy9szvi.js} +45 -3017
  3. package/dist/{anthropic-messages-opbQWUB1.js → anthropic-messages-CGsmFpbQ.js} +269 -41
  4. package/dist/apiContracts-E7V6wOHG.js +1603 -0
  5. package/dist/{approval-D3Q_syCs.js → approval-B1ULmEAh.js} +2 -2
  6. package/dist/{approvalPrompt-I2SLgQQd.js → approvalPrompt-Ce7UawQq.js} +1 -2
  7. package/dist/artifactFiles-DVzMGVFJ.js +1 -0
  8. package/dist/assets/assets/{CodeEditorView-D_2kPSBJ.js → CodeEditorView-BILAwhgB.js} +2 -2
  9. package/dist/assets/assets/{abnfDiagram-WEYOIA3C-CFGLKubd.js → abnfDiagram-WEYOIA3C-Db6cqrKC.js} +2 -2
  10. package/dist/assets/assets/{architecture-WOLXFQ4H-_wl-BvQr.js → architecture-WOLXFQ4H-7Rk6V235.js} +1 -1
  11. package/dist/assets/assets/{architectureDiagram-ZHVYKT53-CbRi1Prf.js → architectureDiagram-ZHVYKT53-cPIBXv1H.js} +2 -2
  12. package/dist/assets/assets/{blockDiagram-RJAE7QA3-DCu3FD7E.js → blockDiagram-RJAE7QA3-i8laHsc8.js} +2 -2
  13. package/dist/assets/assets/{c4Diagram-XDPPPE54-D0Mgjkkz.js → c4Diagram-XDPPPE54-OZunP8RZ.js} +2 -2
  14. package/dist/assets/assets/channel-CvxMXaY1.js +2 -0
  15. package/dist/assets/assets/{chunk-2E7WHVMD-DAA02Ed8.js → chunk-2E7WHVMD-CJ2Y2PXU.js} +2 -2
  16. package/dist/assets/assets/{chunk-4EMNKR2T-DsXBQgpA.js → chunk-4EMNKR2T-DWajFgIf.js} +2 -2
  17. package/dist/assets/assets/{chunk-55XCU76K-3VvdJXrz.js → chunk-55XCU76K-DW65zupR.js} +2 -2
  18. package/dist/assets/assets/{chunk-7S6XSTFO-BjQvUqGa.js → chunk-7S6XSTFO-BhD6Hi1W.js} +2 -2
  19. package/dist/assets/assets/{chunk-AQDTSKZB-CmjCX0p-.js → chunk-AQDTSKZB-BPGJNRYp.js} +2 -2
  20. package/dist/assets/assets/{chunk-DSNLSHJZ-C5HsO_EP.js → chunk-DSNLSHJZ-CpU36XV8.js} +2 -2
  21. package/dist/assets/assets/{chunk-HAGFOTED-CXmScNB2.js → chunk-HAGFOTED-DMeILTw3.js} +2 -2
  22. package/dist/assets/assets/{chunk-HNE4Q36P-YdNRZVWt.js → chunk-HNE4Q36P-gA49iAHT.js} +2 -2
  23. package/dist/assets/assets/{chunk-NQOKRVIF-5Xb0jAAj.js → chunk-NQOKRVIF-DeOWmx9F.js} +2 -2
  24. package/dist/assets/assets/{chunk-UHW7PFBP-Dh-2GXBT.js → chunk-UHW7PFBP-BRbNPAOv.js} +2 -2
  25. package/dist/assets/assets/{chunk-VQ5W62QI-Bhv-5lg3.js → chunk-VQ5W62QI-CIqwq4JO.js} +2 -2
  26. package/dist/assets/assets/{chunk-WQQL4CDK-RhQ4fk3O.js → chunk-WQQL4CDK-Cj8EWG06.js} +2 -2
  27. package/dist/assets/assets/chunk-XXDRQBXY-hDFq8t4z.js +2 -0
  28. package/dist/assets/assets/{chunk-YZO67HFG-CY4fGzpT.js → chunk-YZO67HFG-BEmw2nJa.js} +2 -2
  29. package/dist/assets/assets/{chunk-ZAUX2LTX-CJb2XRe6.js → chunk-ZAUX2LTX-BCFho759.js} +2 -2
  30. package/dist/assets/assets/{chunk-ZCHMQSOR-Ded5YK-R.js → chunk-ZCHMQSOR-DLzZWBoV.js} +2 -2
  31. package/dist/assets/assets/{classDiagram-v2-4MYWR3UA-Dv-YoxIh.js → classDiagram-v2-4MYWR3UA-CPpf8f8s.js} +2 -2
  32. package/dist/assets/assets/{cose-bilkent-JH36ORCC-UHMC9K1K.js → cose-bilkent-JH36ORCC-D3J0dYaE.js} +2 -2
  33. package/dist/assets/assets/{cynefin-EF2NZ3EQ-DBlGBTVy.js → cynefin-EF2NZ3EQ-7c4qKQeR.js} +1 -1
  34. package/dist/assets/assets/{cynefinDiagram-WF24UDRP-Cln1m12g.js → cynefinDiagram-WF24UDRP-rhHTynCX.js} +2 -2
  35. package/dist/assets/assets/{dagre-NK4GIZVX-CD9utwJR.js → dagre-NK4GIZVX-BGrqqTIj.js} +2 -2
  36. package/dist/assets/assets/{diagram-CBK3MWTC-CrIxXjZS.js → diagram-CBK3MWTC-1Pco0PjF.js} +2 -2
  37. package/dist/assets/assets/{diagram-I5XIIV2D-CG__zh0g.js → diagram-I5XIIV2D-EAnE24mJ.js} +2 -2
  38. package/dist/assets/assets/{diagram-ODIL2UCW-DMiPuUaL.js → diagram-ODIL2UCW-DoleQeoX.js} +2 -2
  39. package/dist/assets/assets/{diagram-PFBEJUXE-408WUhQ2.js → diagram-PFBEJUXE-B1HrTuH9.js} +2 -2
  40. package/dist/assets/assets/{diagram-RJA3I4VV-R1QXVtUH.js → diagram-RJA3I4VV-CE1gkrAQ.js} +2 -2
  41. package/dist/assets/assets/{diagram-TYUNFSNR-DU1M7Es6.js → diagram-TYUNFSNR-H93B1-Su.js} +2 -2
  42. package/dist/assets/assets/{dist-Df14c58K.js → dist-BLVZzkFm.js} +2 -2
  43. package/dist/assets/assets/{dist-Bo5Jq8lg.js → dist-BlwHZk4A.js} +2 -2
  44. package/dist/assets/assets/{dist-Co0sU-bT.js → dist-BoUQJhvf.js} +2 -2
  45. package/dist/assets/assets/{dist-MwIe8KNZ.js → dist-BrsvfkUa.js} +2 -2
  46. package/dist/assets/assets/{dist-C5Pr9_Fm.js → dist-D4JN8_Lc.js} +2 -2
  47. package/dist/assets/assets/{dist-BccTR_8r.js → dist-DApNFB-d.js} +2 -2
  48. package/dist/assets/assets/{dist-OyhC8f4N.js → dist-DHE18aHW.js} +2 -2
  49. package/dist/assets/assets/{dist-Bg94scQ_.js → dist-Mk3XGkBC.js} +2 -2
  50. package/dist/assets/assets/{dist-m7usoIfh.js → dist-kS3zF3A_.js} +2 -2
  51. package/dist/assets/assets/{ebnfDiagram-V4P3TTPT--cIVVWfB.js → ebnfDiagram-V4P3TTPT-Dkr4rBiT.js} +2 -2
  52. package/dist/assets/assets/{elk-QONTBCTQ-D0hGypwX.js → elk-QONTBCTQ-DKZCqiMW.js} +2 -2
  53. package/dist/assets/assets/{erDiagram-KYQIGQAA-BgCRh2lM.js → erDiagram-KYQIGQAA-C9qAq0Ih.js} +2 -2
  54. package/dist/assets/assets/{eventmodeling-K75KTNOO-CXRp_2WQ.js → eventmodeling-K75KTNOO-DeV0CDUk.js} +1 -1
  55. package/dist/assets/assets/flowDiagram-IUGLLWBU-OCQM79oD.js +1 -0
  56. package/dist/assets/assets/{ganttDiagram-R7GPNTJY-B2sMTF0H.js → ganttDiagram-R7GPNTJY-DJG1gbrf.js} +2 -2
  57. package/dist/assets/assets/{gitGraph-VSP46ZUC-_mjxemX0.js → gitGraph-VSP46ZUC-4wslN-77.js} +1 -1
  58. package/dist/assets/assets/{gitGraphDiagram-PDYL7XHY-Cj5xkdFl.js → gitGraphDiagram-PDYL7XHY-BPTNhIxX.js} +2 -2
  59. package/dist/assets/assets/index-CNHKCVRd.js +200 -0
  60. package/dist/assets/assets/{info-OHQRW6UA-wnI_thpb.js → info-OHQRW6UA-BTlC3z9I.js} +1 -1
  61. package/dist/assets/assets/{infoDiagram-MVDRKAX5-Cx-Q4bnF.js → infoDiagram-MVDRKAX5-DrVjd0Jn.js} +2 -2
  62. package/dist/assets/assets/{ishikawaDiagram-HPEHV2GE-BQTn2wKj.js → ishikawaDiagram-HPEHV2GE-DPY0rx3a.js} +2 -2
  63. package/dist/assets/assets/{journeyDiagram-BOSHW7O7-x-i5xuEs.js → journeyDiagram-BOSHW7O7-BSQSO9Qs.js} +2 -2
  64. package/dist/assets/assets/{kanban-definition-FNSA4HC5-wqB9Oqf2.js → kanban-definition-FNSA4HC5-BCFNn7LX.js} +2 -2
  65. package/dist/assets/assets/{line-35tFTLOz.js → line-DTCVwNS4.js} +2 -2
  66. package/dist/assets/assets/{linear-Da2WsUsk.js → linear-tXwqxGI7.js} +2 -2
  67. package/dist/assets/assets/{mermaid-parser.core-CCm9g7mk.js → mermaid-parser.core-BNRuwywy.js} +4 -4
  68. package/dist/assets/assets/{mermaid.core-CP11Nd6-.js → mermaid.core-CrZf2lec.js} +5 -5
  69. package/dist/assets/assets/{mindmap-definition-6OY57UG3-lUI1mhZA.js → mindmap-definition-6OY57UG3-G93tbgEY.js} +2 -2
  70. package/dist/assets/assets/{packet-JDAUHWVQ-BUt22sh7.js → packet-JDAUHWVQ-0xoQ5ZBS.js} +1 -1
  71. package/dist/assets/assets/{pegDiagram-ECIUJNBX-DJaRc-HG.js → pegDiagram-ECIUJNBX-Cic7zZo6.js} +2 -2
  72. package/dist/assets/assets/{pie-XZMESJXO-Duu7MVtA.js → pie-XZMESJXO-Ds-rNxTh.js} +1 -1
  73. package/dist/assets/assets/{pieDiagram-GNMPY74T-UZLGCvqe.js → pieDiagram-GNMPY74T-BM5cJDBC.js} +2 -2
  74. package/dist/assets/assets/{quadrantDiagram-D57K4MC3-DBnuAgwi.js → quadrantDiagram-D57K4MC3-BX3bw12R.js} +2 -2
  75. package/dist/assets/assets/{radar-ABXABTNO--k50TJHD.js → radar-ABXABTNO-gLSpe4Ok.js} +1 -1
  76. package/dist/assets/assets/{railroad-I3PHUGI6-XUnD8NIC.js → railroad-I3PHUGI6-q0ilJ9ab.js} +1 -1
  77. package/dist/assets/assets/{railroad-abnf-LNEFI6M7-OOlmzpkp.js → railroad-abnf-LNEFI6M7-Zb0_GWRq.js} +1 -1
  78. package/dist/assets/assets/{railroad-ebnf-DWYD2UWJ-D0RWogYc.js → railroad-ebnf-DWYD2UWJ-DnPMPunv.js} +1 -1
  79. package/dist/assets/assets/{railroad-peg-JR7BVNR7-CMtpeR3Q.js → railroad-peg-JR7BVNR7-CMA-cHsd.js} +1 -1
  80. package/dist/assets/assets/{railroadDiagram-Y72NRBL7-BlhczKMC.js → railroadDiagram-Y72NRBL7-BdzEi4y2.js} +2 -2
  81. package/dist/assets/assets/{requirementDiagram-EQYSW5RA-DHCpA3lP.js → requirementDiagram-EQYSW5RA-RMUbKBQf.js} +2 -2
  82. package/dist/assets/assets/{sankeyDiagram-SY24JHO5-DpcS8ivn.js → sankeyDiagram-SY24JHO5-CPEfqnBH.js} +2 -2
  83. package/dist/assets/assets/{sequenceDiagram-BLEHNHQU-E211wGeW.js → sequenceDiagram-BLEHNHQU-BBeElNdp.js} +2 -2
  84. package/dist/assets/assets/{src-CJ1X4tCb.js → src-Co0Is17p.js} +2 -2
  85. package/dist/assets/assets/{stateDiagram-v2-A6IESKWZ-D53eF5xB.js → stateDiagram-v2-A6IESKWZ-CvfqFFnh.js} +2 -2
  86. package/dist/assets/assets/{swimlanes-B3ENRKFQ-DEcOa7cs.js → swimlanes-B3ENRKFQ-BwRGKs3P.js} +2 -2
  87. package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-uyGVvFhD.js +9 -0
  88. package/dist/assets/assets/{timeline-definition-JXYKGLGB-QiyBGMT_.js → timeline-definition-JXYKGLGB-C3sV6KVf.js} +2 -2
  89. package/dist/assets/assets/{treeView-D4JQ5SDB-4UosJGh0.js → treeView-D4JQ5SDB-CLkzkqDW.js} +1 -1
  90. package/dist/assets/assets/{treemap-SAJKECNS-C6LWVlwK.js → treemap-SAJKECNS-BvlIiAov.js} +1 -1
  91. package/dist/assets/assets/{usecaseDiagram-WPOLBNNX-CobZD3iG.js → usecaseDiagram-WPOLBNNX-gucN60Bm.js} +2 -2
  92. package/dist/assets/assets/{vennDiagram-Q3Y3IDCW-Bm46yEJ7.js → vennDiagram-Q3Y3IDCW-DeXtbNRQ.js} +2 -2
  93. package/dist/assets/assets/{wardley-7MLQ67FV-bOBt6hOS.js → wardley-7MLQ67FV-BySGijig.js} +1 -1
  94. package/dist/assets/assets/{wardleyDiagram-IVAIDKWA-rREn3IMV.js → wardleyDiagram-IVAIDKWA-sqzxPabh.js} +2 -2
  95. package/dist/assets/assets/{webpack-YjV85Ut9.js → webpack-C8J0t4Ev.js} +2 -2
  96. package/dist/assets/assets/{xychartDiagram-4URNHDU4-CPIJN9Hg.js → xychartDiagram-4URNHDU4-DhSMAm06.js} +2 -2
  97. package/dist/assets/bundle-asset-policy.json +1 -1
  98. package/dist/assets/index.html +1 -1
  99. package/dist/assets/plugins/chunks/po-web-runtime-BhSF51GF.js +1 -0
  100. package/dist/assets/plugins/compositions.json +1 -1
  101. package/dist/assets/plugins/slots/approval.293d9a00-BSeXICbI.js +2 -0
  102. package/dist/assets/plugins/slots/artifacts.24567664-WRTyk2zV.js +1 -0
  103. package/dist/assets/plugins/slots/author.0998a880-CJMUvdJt.js +93 -0
  104. package/dist/assets/plugins/slots/{autocompact.9a92993d-COvGBX4J.js → autocompact.dd97d013-C7J2jikY.js} +1 -1
  105. package/dist/assets/plugins/slots/browse.4b5f8a0b-_ldrjFqx.js +1 -0
  106. package/dist/assets/plugins/slots/{builtin-tools.939bbfff-DAoZN5yu.js → builtin-tools.36d7400b-C4IfAXaZ.js} +3 -3
  107. package/dist/assets/plugins/slots/codemode.8eaee717-BCjLw-_j.js +11 -0
  108. package/dist/assets/plugins/slots/domain.5e95fc37-C8zAem_d.js +1 -0
  109. package/dist/assets/plugins/slots/{edit.c7c85129-BRxWodmN.js → edit.385c9aa9-BOQcLzMh.js} +3 -3
  110. package/dist/assets/plugins/slots/files.daf34ed8-ms1al6z7.js +2 -0
  111. package/dist/assets/plugins/slots/goal.77ec9930-CR483tNO.js +1 -0
  112. package/dist/assets/plugins/slots/grep.02052cdc-DikEvfp2.js +1 -0
  113. package/dist/assets/plugins/slots/help.ecd4c0f9-DL7ktrs-.js +3 -0
  114. package/dist/assets/plugins/slots/log.a86eb6d0-Bx77pvm1.js +4 -0
  115. package/dist/assets/plugins/slots/mcp.974af249-CRMSCtWu.js +109 -0
  116. package/dist/assets/plugins/slots/plan.bafb8f68-DJswVj5X.js +3 -0
  117. package/dist/assets/plugins/slots/{profile.ea55f5e1-BgWna12C.js → profile.48851a1d-y3TFtlmt.js} +1 -1
  118. package/dist/assets/plugins/slots/{prompts.9957cc84-CUpopiW4.js → prompts.723d7748-CCX8HZaI.js} +2 -2
  119. package/dist/assets/plugins/slots/read.46bf6536-DIOZjpp-.js +1 -0
  120. package/dist/assets/plugins/slots/runner.53e9bd76-CYGo3EwH.js +8 -0
  121. package/dist/assets/plugins/slots/sessions.09d5cdbb-DixP5tLq.js +1 -0
  122. package/dist/assets/plugins/slots/skill.086701a4-xzISgcpu.js +4 -0
  123. package/dist/assets/plugins/slots/subagents.8f6fa9e8-DutE7lUn.js +7 -0
  124. package/dist/assets/plugins/slots/vault.ac9935c8-DhboY0MP.js +1 -0
  125. package/dist/assets/plugins/slots/voice.e85ca7f9-NanECpYb.js +1 -0
  126. package/dist/{atomicJson-BTxm6dg3.js → atomicJson-Ct467hYH.js} +2 -2
  127. package/dist/{azure-openai-config--IsaQQgj.js → azure-openai-config-DrJddYQ4.js} +2 -2
  128. package/dist/{azure-openai-responses-DnAltsRK.js → azure-openai-responses-CcUYAmFp.js} +12 -12
  129. package/dist/{backgroundWork-ByxgPNc3.js → backgroundWork-ayFYgbbo.js} +1 -1
  130. package/dist/{classifier-shared-IhSH9hhh.js → classifier-shared-DB0OwvlW.js} +5 -5
  131. package/dist/{cloudflare-workers-ai-system-one-BNnc8MuH.js → cloudflare-workers-ai-system-one-D5kettrv.js} +3 -3
  132. package/dist/{codemode-hD8cReg-.js → codemode-BS_8gvI6.js} +1 -1
  133. package/dist/{contracts-YkHKMJHq.js → contracts-BfbG0pdB.js} +1 -1
  134. package/dist/{contracts-hsrc8TLn.js → contracts-CU5IRu-j.js} +1 -1
  135. package/dist/{diagnostics-1lYFeSJe.js → diagnostics-DT_N5BqI.js} +2 -2
  136. package/dist/{dist-Dvx5mlIR.js → dist-CLdzaXdw.js} +16 -3
  137. package/dist/{edge-Bz4xPB4W.js → edge-m-XMd0lm.js} +3 -3
  138. package/dist/{env-api-keys-Bow6MJe2.js → env-api-keys-BV3haPEf.js} +1 -1
  139. package/dist/{error-body-CJk7jMUh.js → error-body-DvA_oGc5.js} +26 -4
  140. package/dist/{exports-k-TeQGpj.js → exports-Bi83-Xc3.js} +5 -6
  141. package/dist/{exports-BALz2qXp.js → exports-Dclcf5j5.js} +9 -9
  142. package/dist/{exports-Doy9CYpT.js → exports-r0SS_cMB.js} +2 -2
  143. package/dist/{extensionFile-DxklpxjD.js → extensionFile-BILjjv_B.js} +1 -1
  144. package/dist/{github-copilot-headers-D1RedfLn.js → github-copilot-headers-CPfEKjCr.js} +1 -1
  145. package/dist/{google-generative-ai-Dv-q8r-n.js → google-generative-ai-TmoHbRui.js} +9 -9
  146. package/dist/{google-shared-D6zhMMQp.js → google-shared-BgJ0m819.js} +5 -5
  147. package/dist/{google-vertex-D70Ns0fU.js → google-vertex-DSG2Vagw.js} +10 -10
  148. package/dist/{harnessState-DFF9LydZ.js → harnessState-VHnlGUu-.js} +3 -3
  149. package/dist/{harnessStore-4dOyK89D.js → harnessStore-YpxY63su.js} +4 -4
  150. package/dist/{hash-Dt6RIbkn.js → hash-Zpy-D8On.js} +1 -1
  151. package/dist/{headers-CwtEVQvr.js → headers-FrAgcbwZ.js} +1 -1
  152. package/dist/help-CdCOHc16.js +1 -0
  153. package/dist/{help-CxfnIcrk.js → help-D2Ro7PCU.js} +1 -2
  154. package/dist/{http-C_9sqYoT.js → http-BYJqIwMF.js} +1 -1
  155. package/dist/{hubChannel-RCs6fhAi.js → hubChannel-g6w-i4vw.js} +1 -1
  156. package/dist/{identity-BgfHobJH.js → identity-XFc4sLVo.js} +3 -3
  157. package/dist/{index.edge-C724Clgs.js → index.edge-Bf6MIjYO.js} +2 -2
  158. package/dist/{index.edge-COJJ_Dv2.js → index.edge-DJhSGEtk.js} +4 -4
  159. package/dist/{index.edge-D_8ita9O.js → index.edge-DxSgTYEJ.js} +2 -2
  160. package/dist/{layeredConfig-CMuV0BBv.js → layeredConfig-D-wUS9yx.js} +3 -3
  161. package/dist/majorModes-BrBCNjAZ.js +1 -0
  162. package/dist/{majorModes-CQ4UV9zY.js → majorModes-Dl2TWW5k.js} +3 -3
  163. package/dist/{mcpProjection-Ctk4Kt9F.js → mcpProjection-CNDY4Np6.js} +1 -2
  164. package/dist/{migrations-5gbLIQIc.js → migrations-B0potTsS.js} +2 -2
  165. package/dist/{mistral-conversations-BSIAfs3U.js → mistral-conversations-B8pchf0Y.js} +12 -12
  166. package/dist/{models-Chzm15vC.js → models-DGReC_qy.js} +41 -46
  167. package/dist/{narration-B8nJ0Iaj.js → narration-D3ulb6Xd.js} +2 -3
  168. package/dist/{node-BbmYdrhA.js → node-Bf_6MHqe.js} +2 -2
  169. package/dist/{notification-DylsYBYm.js → notification-B4KLzmok.js} +1 -2
  170. package/dist/{openai-codex-responses-B14mXiVh.js → openai-codex-responses-BT4rzzPX.js} +21 -25
  171. package/dist/{openai-completions-BJm3_Ky5.js → openai-completions-CL59ZjJR.js} +25 -18
  172. package/dist/{openai-decisions-BsFjaAGw.js → openai-decisions-DH6ExlAC.js} +3 -3
  173. package/dist/{openai-responses-Du8RlS3z.js → openai-responses-Yn7OV25O.js} +16 -14
  174. package/dist/{openai-responses-shared-B7TURd1_.js → openai-responses-shared-Cvsbni4_.js} +7 -7
  175. package/dist/{openrouter-cost-CvC52g3b.js → openrouter-cost-TRj0BKPF.js} +1 -1
  176. package/dist/{openrouter-images-BYpLRSop.js → openrouter-images-CQEhYdHi.js} +6 -6
  177. package/dist/{pi-messages-Br5bk99n.js → pi-messages-COe6DyoX.js} +6 -6
  178. package/dist/{piConfig-CP3qiZkk.js → piConfig-CM-zbr9H.js} +4 -4
  179. package/dist/piSettings-DQ-OzX3B.js +1 -0
  180. package/dist/{platform-CnqcdFpd.js → platform-BpQfBhz3.js} +1 -1
  181. package/dist/{pluginProtocol-DRqZuJew.js → pluginProtocol-CKMSfrnU.js} +1 -2
  182. package/dist/{protocol-pp3q1194.js → protocol-DfghzzpH.js} +1 -2
  183. package/dist/{provider-env-C22kXiXR.js → provider-env-3chZbmsY.js} +1 -1
  184. package/dist/{provider-retry-BUoezuw8.js → provider-retry-BBTrjo8Y.js} +1 -1
  185. package/dist/{sanitize-unicode-C3Ec8oL6.js → sanitize-unicode-B91An5dg.js} +1 -1
  186. package/dist/{server-x-Afcj5B.js → server-B6v4bGo-.js} +7 -7
  187. package/dist/{server-DDyWySmJ.js → server-BfMgm6Ca.js} +8 -9
  188. package/dist/{server-BjnmG1XW.js → server-Bh--KUSf.js} +3 -3
  189. package/dist/{server-DvVQT74I.js → server-BtZ0ONdK.js} +4 -4
  190. package/dist/{server-nrto98nV.js → server-Bu7-fGOd.js} +6 -6
  191. package/dist/{server-T3wMw1mO.js → server-C-F-2lt5.js} +5 -5
  192. package/dist/{server-CA4rE4W3.js → server-C1uAR3I-.js} +3 -3
  193. package/dist/{server-DDn-Xx1l.js → server-C5LhHMxG.js} +6 -6
  194. package/dist/{server-CsBPdhbj.js → server-CCSYkeEG.js} +8 -8
  195. package/dist/{server-DfpPI1ec.js → server-CDOobSax.js} +3 -3
  196. package/dist/{server-BrV733OF.js → server-CECBjK6K.js} +11 -12
  197. package/dist/{server-Do8fR2Sb.js → server-CFDnmO7q.js} +10 -11
  198. package/dist/{server-BVcrbSi2.js → server-CNxGqKnW.js} +8 -9
  199. package/dist/{server-DjRV_5WD.js → server-COngEDna.js} +5 -5
  200. package/dist/{server-Dq5gMEjs.js → server-CPgEn98V.js} +4 -4
  201. package/dist/{server-Cp4O6TOl.js → server-CttpifFm.js} +8 -9
  202. package/dist/{server-BPUpVSmq.js → server-DRhXIgFa.js} +8 -8
  203. package/dist/{server-BSAH_I0A.js → server-D__9TXI8.js} +2 -2
  204. package/dist/{server-B0S8s0PJ.js → server-Db7vvjFE.js} +6 -6
  205. package/dist/{server-CrX9seN4.js → server-DquZAnuE.js} +4 -4
  206. package/dist/{server-Db9PgiFa.js → server-Dro3cl8P.js} +6 -6
  207. package/dist/{server-CyVWRtnS.js → server-J50zfJLS.js} +5 -5
  208. package/dist/{server-DkbF3vin.js → server-TVXlynxH.js} +9 -10
  209. package/dist/{server-IMj7c63O.js → server-dRLlM5aG.js} +3 -3
  210. package/dist/{server-Vo-JYzPi.js → server-g5BytR-E.js} +7 -7
  211. package/dist/{server-q-voTDcW.js → server-h24_XCpc.js} +5 -5
  212. package/dist/{server-CmeSdP2c.js → server-j_Y6GSDp.js} +9 -10
  213. package/dist/{server-BKnVfVIK.js → server-oeSZ338Z.js} +9 -10
  214. package/dist/{server-CECZ7J-q.js → server-uqpnYywA.js} +7 -8
  215. package/dist/{server-BhdR-Z5M.js → server-zyuY936Q.js} +9 -9
  216. package/dist/serverPlugin-DcSYreIB.js +36499 -0
  217. package/dist/session-resources-Ckd8uUQs.js +10 -0
  218. package/dist/{sessionConfig-D64L2Q-G.js → sessionConfig-DThz4-2o.js} +9 -9
  219. package/dist/{simple-options-CFzI5Pd_.js → simple-options-DvQPdbMC.js} +13 -6
  220. package/dist/{streaming-json-CDuwZdyw.js → streaming-json-CF5oj8DO.js} +1 -1
  221. package/dist/{system-one-shared-CiIrx29d.js → system-one-shared-Bg2woRPx.js} +3 -3
  222. package/dist/{transform-messages-D77af7Bx.js → transform-messages-COCl_pQj.js} +3 -16
  223. package/dist/{type-DYu4bu1B.js → type-CBeOM4Mf.js} +7 -8
  224. package/dist/{typesafe-system-one-DGxeggJh.js → typesafe-system-one-BZlYlQf5.js} +3 -3
  225. package/dist/{uuid-B0QJx6Kr.js → uuid-l3LNpywg.js} +1 -1
  226. package/dist/{validation-CLodc1-K.js → validation-Pg3lil_9.js} +2 -2
  227. package/dist/{vaultSettings-IQsCwUIl.js → vaultSettings-Dio3URba.js} +1 -1
  228. package/dist/{voiceTools-CRkvHrI6.js → voiceTools-C8cbGmIH.js} +1 -1
  229. package/dist/web-zAjwdHrc.js +3 -0
  230. package/dist/worker.js +4182 -8029
  231. package/dist/{workflow-D5tsnAHa.js → workflow-Dn4FxwDJ.js} +1 -2
  232. package/package.json +42 -42
  233. package/dist/apiContracts-CbHw014q.js +0 -4432
  234. package/dist/artifactFiles-VWppLv0Y.js +0 -1
  235. package/dist/assets/assets/channel-BaJ9GJxD.js +0 -2
  236. package/dist/assets/assets/chunk-XXDRQBXY-DMQyOR47.js +0 -2
  237. package/dist/assets/assets/flowDiagram-IUGLLWBU-DdwdXnpH.js +0 -1
  238. package/dist/assets/assets/index-Cw8VlcET.js +0 -159
  239. package/dist/assets/assets/swimlanesDiagram-AYQRV4AK-BnDQNSnk.js +0 -9
  240. package/dist/assets/plugins/chunks/po-web-runtime-g9WZFuM-.js +0 -1
  241. package/dist/assets/plugins/slots/approval.8b3f37d9-AXYyc7PO.js +0 -2
  242. package/dist/assets/plugins/slots/artifacts.47d00f81-_adb3asN.js +0 -1
  243. package/dist/assets/plugins/slots/author.a2840b8a-D4QZpt_F.js +0 -93
  244. package/dist/assets/plugins/slots/browse.6ca724d8-CTK9k6lz.js +0 -1
  245. package/dist/assets/plugins/slots/codemode.782e5bb1-DNqZxTqO.js +0 -11
  246. package/dist/assets/plugins/slots/domain.21790b66-CNEFGOh5.js +0 -1
  247. package/dist/assets/plugins/slots/files.bbcef824-B65rd6DE.js +0 -2
  248. package/dist/assets/plugins/slots/goal.9bbfc551-BS8xvxGL.js +0 -1
  249. package/dist/assets/plugins/slots/grep.3dfd3214-CyKn16fi.js +0 -1
  250. package/dist/assets/plugins/slots/help.894dfb6a-pe2i2yQ9.js +0 -3
  251. package/dist/assets/plugins/slots/log.33bc7d38-Dw8n9D_b.js +0 -4
  252. package/dist/assets/plugins/slots/mcp.59c68bcb-e2CmyiUc.js +0 -109
  253. package/dist/assets/plugins/slots/plan.4738a609-B8WYGLn_.js +0 -3
  254. package/dist/assets/plugins/slots/read.30a617e7-BL6Y4nwn.js +0 -1
  255. package/dist/assets/plugins/slots/runner.9f3559b0-Cy5Iid0v.js +0 -8
  256. package/dist/assets/plugins/slots/sessions.d6812dc8-Cxh80eCw.js +0 -1
  257. package/dist/assets/plugins/slots/skill.f506a5ea-CW969I9N.js +0 -4
  258. package/dist/assets/plugins/slots/subagents.138e4469-Bth6j8MA.js +0 -7
  259. package/dist/assets/plugins/slots/vault.01657352-BKRkXtaj.js +0 -1
  260. package/dist/assets/plugins/slots/voice.3b26e7ac-CX2B6SJP.js +0 -1
  261. package/dist/help-BtRgoabI.js +0 -1
  262. package/dist/majorModes-qeNT8IK1.js +0 -1
  263. package/dist/piSettings-4kOcXFUR.js +0 -1
  264. package/dist/serverPlugin-Bp6HbU5i.js +0 -7639
  265. package/dist/value-CSr-kBZz.js +0 -2247
  266. package/dist/web-cpsGinMd.js +0 -3
  267. package/dist/{node-CBLSc-YH.js → node-CjBe953N.js} +1 -1
@@ -1,3007 +1,5 @@
1
- import { An as addressId, Fn as documentCreate, Hn as BACKGROUND_CONTEXT, In as materializeDocument, Kn as withoutAbortSignal, Ln as materializeDocumentValue, Mn as checkRecordVersion, Nn as defineDoc, Rn as resolveAddress, Un as awaitWithContext, Vn as copyJson, jn as checkRecordScope, zn as idFromNumber } from "./serverPlugin-Bp6HbU5i.js";
2
- //#region ../../../node_modules/.pnpm/@earendil-works+chord@1.5.0_esbuild@0.28.2/node_modules/@earendil-works/chord/dist/delta/apply-immutable-trusted.js
3
- const DATA_DESCRIPTOR$1 = {
4
- value: void 0,
5
- writable: true,
6
- enumerable: true,
7
- configurable: true
8
- };
9
- /** Apply self-produced trusted operations while copying each touched container once. */
10
- function applyImmutableTrusted(target, operations) {
11
- let root = target;
12
- const owned = /* @__PURE__ */ new WeakSet();
13
- for (const operation of operations) {
14
- if (operation[0] === "r") {
15
- root = operation[1];
16
- continue;
17
- }
18
- if (operation[0] === "p" || operation[0] === "m") {
19
- const copied = copyPath(root, operation[1], operation[1].length, owned);
20
- root = copied.root;
21
- if (!Array.isArray(copied.target)) throw new TypeError("Trusted array operation target is not an array");
22
- if (operation[0] === "p") spliceTrusted(copied.target, operation[2], operation[3], operation[4]);
23
- else permuteTrusted(copied.target, operation[2]);
24
- continue;
25
- }
26
- const path = operation[1];
27
- const copied = copyPath(root, path, path.length - 1, owned);
28
- root = copied.root;
29
- const key = path[path.length - 1];
30
- switch (operation[0]) {
31
- case "s":
32
- defineData$1(copied.target, key, operation[2]);
33
- break;
34
- case "d":
35
- if (Array.isArray(copied.target)) {
36
- if (typeof key !== "number") throw new TypeError("Trusted array deletion key is not numeric");
37
- spliceTrusted(copied.target, key, 1, []);
38
- } else Reflect.deleteProperty(copied.target, key);
39
- break;
40
- case "a": {
41
- const current = read(copied.target, key);
42
- if (typeof current !== "string") throw new TypeError("Trusted append target is not a string");
43
- defineData$1(copied.target, key, `${current}${operation[2]}`);
44
- break;
45
- }
46
- case "t": {
47
- const current = read(copied.target, key);
48
- if (typeof current !== "string") throw new TypeError("Trusted truncate target is not a string");
49
- defineData$1(copied.target, key, current.slice(operation[2]));
50
- break;
51
- }
52
- }
53
- }
54
- return root;
55
- }
56
- function copyPath(root, path, length, owned) {
57
- if (!isContainer$1(root)) throw new TypeError("Trusted operation root is not a container");
58
- let copiedRoot = root;
59
- if (!owned.has(root)) {
60
- copiedRoot = shallowCopy(root);
61
- owned.add(copiedRoot);
62
- }
63
- let destination = copiedRoot;
64
- for (let index = 0; index < length; index++) {
65
- const segment = path[index];
66
- const child = read(destination, segment);
67
- if (!isContainer$1(child)) throw new TypeError("Trusted operation path is not a container");
68
- if (owned.has(child)) {
69
- destination = child;
70
- continue;
71
- }
72
- const copy = shallowCopy(child);
73
- defineData$1(destination, segment, copy);
74
- owned.add(copy);
75
- destination = copy;
76
- }
77
- return {
78
- root: copiedRoot,
79
- target: destination
80
- };
81
- }
82
- function shallowCopy(value) {
83
- if (Array.isArray(value)) return Array.from(value);
84
- return Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };
85
- }
86
- function read(target, key) {
87
- return target[key];
88
- }
89
- function defineData$1(target, key, value) {
90
- DATA_DESCRIPTOR$1.value = value;
91
- Object.defineProperty(target, key, DATA_DESCRIPTOR$1);
92
- DATA_DESCRIPTOR$1.value = void 0;
93
- }
94
- function spliceTrusted(target, start, remove, items) {
95
- const oldLength = target.length;
96
- const delta = items.length - remove;
97
- if (delta > 0) {
98
- target.length = oldLength + delta;
99
- target.copyWithin(start + items.length, start + remove, oldLength);
100
- } else if (delta < 0) {
101
- target.copyWithin(start + items.length, start + remove, oldLength);
102
- target.length = oldLength + delta;
103
- }
104
- for (let index = 0; index < items.length; index++) defineData$1(target, start + index, items[index]);
105
- }
106
- function permuteTrusted(target, permutation) {
107
- if (target.length !== permutation.length) throw new TypeError("Trusted permutation length mismatch");
108
- const previous = target.slice();
109
- for (let index = 0; index < permutation.length; index++) target[index] = previous[permutation[index]];
110
- }
111
- function isContainer$1(value) {
112
- return value !== null && typeof value === "object";
113
- }
114
- //#endregion
115
- //#region ../../../node_modules/.pnpm/@earendil-works+chord@1.5.0_esbuild@0.28.2/node_modules/@earendil-works/chord/dist/delta/tracker.js
116
- const NODE = Symbol("chord.delta.overlay.node");
117
- const PREPARED = /* @__PURE__ */ new WeakMap();
118
- const RELEASED = {};
119
- const ARRAY_MUTATORS = /* @__PURE__ */ new Set([
120
- "push",
121
- "pop",
122
- "shift",
123
- "unshift",
124
- "splice",
125
- "reverse",
126
- "sort",
127
- "fill",
128
- "copyWithin"
129
- ]);
130
- const MAX_DELTA_OPERATIONS = 4096;
131
- const MAX_SIMPLE_OBJECT_NODES = 128;
132
- const DATA_DESCRIPTOR = {
133
- value: void 0,
134
- writable: true,
135
- enumerable: true,
136
- configurable: true
137
- };
138
- var PreparedImpl = class {
139
- #context;
140
- value;
141
- base;
142
- ops;
143
- constructor(context, value, operations) {
144
- this.#context = context;
145
- this.value = value;
146
- this.base = context.baseValue;
147
- this.ops = operations;
148
- PREPARED.set(this, context);
149
- }
150
- get baseRevision() {
151
- return this.#context.baseRevision;
152
- }
153
- abort() {
154
- abortContext(this.#context);
155
- }
156
- };
157
- var ChangeImpl = class {
158
- #context;
159
- #preparedStatus;
160
- #settled = false;
161
- constructor(context) {
162
- this.#context = context;
163
- }
164
- get state() {
165
- const state = this.#context?.root?.proxy;
166
- if (state === void 0) throw new TypeError("Cannot use a settled overlay");
167
- return state;
168
- }
169
- prepare() {
170
- if (this.#settled) throw new Error("Change has already been settled");
171
- const context = this.#context;
172
- assertWritable(context);
173
- context.status.value = "prepared";
174
- try {
175
- if (!context.replacement) context.ops = context.dirty.length === 0 ? [] : emitOperations(context);
176
- const prepared = materializePrepared(context);
177
- this.#preparedStatus = context.status;
178
- this.#settled = true;
179
- return prepared;
180
- } catch (error) {
181
- context.status.value = "aborted";
182
- clearContext(context);
183
- this.#settled = true;
184
- throw error;
185
- } finally {
186
- this.#context = void 0;
187
- }
188
- }
189
- abort() {
190
- if (this.#settled) {
191
- if (this.#preparedStatus?.value === "prepared") this.#preparedStatus.value = "aborted";
192
- this.#preparedStatus = void 0;
193
- return;
194
- }
195
- this.#settled = true;
196
- abortContext(this.#context);
197
- this.#context = void 0;
198
- }
199
- };
200
- /**
201
- * Open drafts are tracked so that adopting one change makes its open competitors stale at once. Prepared contexts need
202
- * no tracking: `prepare()` releases their overlay, and `adopt()` rejects them by revision.
203
- *
204
- * The most recent open context is held strongly in `#open`: with one transaction at a time per tracker, the common case,
205
- * that is the only one, and it costs no `WeakRef` (each `WeakRef` target survives the scavenges of the current job, and
206
- * V8 then pretenures the context allocation site). A second `beginChange()` while one is open moves the older context
207
- * into `#competitors` through a `WeakRef`, so a draft the caller drops can be collected. A dropped draft that was never
208
- * settled stays held by `#open` until the tracker's next `beginChange()` or `adopt()`: at most one per tracker.
209
- */
210
- var TrackerImpl = class {
211
- #owner = {};
212
- #open;
213
- #competitors;
214
- #selfRef;
215
- #value;
216
- #revision = 0;
217
- #pruneBudget = 256;
218
- constructor(initial) {
219
- this.#value = initial;
220
- this.#selfRef = new WeakRef(this);
221
- }
222
- get value() {
223
- return this.#value;
224
- }
225
- get revision() {
226
- return this.#revision;
227
- }
228
- beginChange() {
229
- const context = createContext(this.#selfRef, this.#owner, this.#revision, this.#value, false, this.#value);
230
- if (this.#open !== void 0) this.#demote(this.#open);
231
- this.#open = context;
232
- return new ChangeImpl(context);
233
- }
234
- prepareReplace(value) {
235
- const context = createContext(this.#selfRef, this.#owner, this.#revision, value, true, this.#value);
236
- context.status.value = "prepared";
237
- try {
238
- return materializePrepared(context);
239
- } catch (error) {
240
- context.status.value = "aborted";
241
- clearContext(context);
242
- throw error;
243
- }
244
- }
245
- adopt(prepared) {
246
- const context = PREPARED.get(prepared);
247
- if (context?.owner !== this.#owner) throw new Error("Prepared change belongs to a different tracker");
248
- if (context.status.value === "consumed") throw new Error("Prepared change has already been used");
249
- if (context.status.value === "aborted") throw new Error("Prepared change has been aborted");
250
- if (context.status.value === "stale") throw new Error("Prepared change is stale");
251
- if (context.status.value !== "prepared") throw new Error("Prepared change is not ready");
252
- if (context.baseRevision !== this.#revision) {
253
- context.status.value = "stale";
254
- clearContext(context);
255
- throw new Error("Prepared change is stale");
256
- }
257
- if (this.#value !== prepared.base) {
258
- context.status.value = "stale";
259
- throw new Error("Prepared change is stale");
260
- }
261
- this.#value = prepared.value;
262
- context.status.value = "consumed";
263
- this.#revision += 1;
264
- this.#invalidate(context);
265
- }
266
- releaseContext(context) {
267
- if (this.#open === context) this.#open = void 0;
268
- else if (context.registryRef !== void 0) this.#competitors?.delete(context.registryRef);
269
- context.registryRef = void 0;
270
- }
271
- #demote(context) {
272
- const reference = new WeakRef(context);
273
- context.registryRef = reference;
274
- this.#competitors ??= /* @__PURE__ */ new Set();
275
- this.#competitors.add(reference);
276
- this.#pruneBudget -= 1;
277
- if (this.#pruneBudget === 0) {
278
- for (const entry of this.#competitors) if (entry.deref() === void 0) this.#competitors.delete(entry);
279
- this.#pruneBudget = Math.max(256, this.#competitors.size);
280
- }
281
- }
282
- #invalidate(winner) {
283
- const open = this.#open;
284
- const competitors = this.#competitors;
285
- this.#open = void 0;
286
- this.#competitors = void 0;
287
- this.#pruneBudget = 256;
288
- if (open !== void 0) staleCompetitor(open, winner);
289
- if (competitors === void 0) return;
290
- for (const reference of competitors) {
291
- const context = reference.deref();
292
- if (context !== void 0) staleCompetitor(context, winner);
293
- }
294
- }
295
- replacementBase(context) {
296
- return context.baseRevision === this.#revision ? this.#value : void 0;
297
- }
298
- };
299
- function staleCompetitor(context, winner) {
300
- if (context === winner) return;
301
- if (context.status.value === "open" || context.status.value === "prepared") context.status.value = "stale";
302
- context.registryRef = void 0;
303
- releaseOverlayReferences(context);
304
- }
305
- /** Take immutable ownership of an alias-free strict-JSON root in O(1). */
306
- function track(initial) {
307
- return new TrackerImpl(initial);
308
- }
309
- /**
310
- * Append `text` to the string at `draft[key]`, costing O(text.length). The change is recorded as one append op
311
- * (several appends to the same key in one change join into one op) without comparing the old and new strings. A plain
312
- * assignment such as `draft[key] += text` gives the same op, but `prepare()` then has to check that the new string
313
- * extends the old one, which reads the whole string: O(length) per change. A plain assignment or deletion of the key in
314
- * the same change falls back to that check.
315
- */
316
- function appendText(draft, key, text) {
317
- const node = draft[NODE];
318
- if (node === void 0) throw new TypeError("appendText() needs a draft");
319
- assertWritable(node.context);
320
- const name = String(key);
321
- const current = Array.isArray(nodeBase(node)) || !objectHas(node, name) ? void 0 : objectValue(node, name);
322
- if (typeof current !== "string") throw new TypeError(`appendText() needs a string at ${JSON.stringify(name)}`);
323
- if (text.length === 0) return;
324
- const owned = ownedSlice(text, 0);
325
- const appended = node.appends?.get(name) ?? (hasObjectWrite(node, name) ? void 0 : "");
326
- setObjectWrite(node, name, current + owned);
327
- markDirty(node);
328
- if (appended !== void 0) {
329
- node.appends ??= /* @__PURE__ */ new Map();
330
- node.appends.set(name, appended + owned);
331
- }
332
- }
333
- function materializePrepared(context) {
334
- const operations = ensureOperations(context);
335
- const base = context.baseValue;
336
- const prepared = new PreparedImpl(context, operations.length === 0 ? base : context.simpleObjectMaterialization ? cloneNode(context.root) : materializeOperations(base, operations), operations);
337
- if (context.nodes.length > 4096) releaseOverlayReferences(context);
338
- else clearContext(context);
339
- return prepared;
340
- }
341
- function materializeOperations(base, operations) {
342
- for (const operation of operations) if (operation[0] === "p" || operation[0] === "m") return applyImmutable(base, operations);
343
- return applyImmutableTrusted(base, operations);
344
- }
345
- function createContext(tracker, owner, baseRevision, root, replacement, base) {
346
- const context = {
347
- owner,
348
- tracker,
349
- baseRevision,
350
- status: { value: "open" },
351
- root: void 0,
352
- bases: [],
353
- stored: void 0,
354
- dirty: [],
355
- nodes: [],
356
- rawNodes: void 0,
357
- ops: void 0,
358
- replacement,
359
- replacementNoop: false,
360
- baseValue: base,
361
- overlayReleased: false,
362
- simpleObjectMaterialization: false,
363
- registryRef: void 0
364
- };
365
- context.root = createNode(context, root, void 0);
366
- return context;
367
- }
368
- const sharedObjectHandler = {
369
- deleteProperty(target, property) {
370
- return deleteProperty(nodeForTarget(target), property);
371
- },
372
- defineProperty(target) {
373
- assertWritable(nodeForTarget(target).context);
374
- throw new TypeError("Defining overlay properties is not supported");
375
- },
376
- get(target, property) {
377
- if (property === "then") {
378
- const node = target[NODE];
379
- if (node === void 0 || isSettledContext(node.context)) return void 0;
380
- }
381
- const node = nodeForTarget(target);
382
- if (property === NODE) return node;
383
- return getProperty(node, property);
384
- },
385
- getOwnPropertyDescriptor(target, property) {
386
- return getDescriptor(nodeForTarget(target), property);
387
- },
388
- getPrototypeOf(target) {
389
- const node = nodeForTarget(target);
390
- assertReadable(node.context);
391
- return Object.getPrototypeOf(nodeBase(node));
392
- },
393
- has(target, property) {
394
- return hasProperty(nodeForTarget(target), property);
395
- },
396
- isExtensible(target) {
397
- assertReadable(nodeForTarget(target).context);
398
- return true;
399
- },
400
- ownKeys(target) {
401
- return ownKeys(nodeForTarget(target));
402
- },
403
- preventExtensions(target) {
404
- assertWritable(nodeForTarget(target).context);
405
- throw new TypeError("Overlays cannot be made non-extensible");
406
- },
407
- set(target, property, value) {
408
- return setProperty(nodeForTarget(target), property, value);
409
- },
410
- setPrototypeOf(target) {
411
- assertWritable(nodeForTarget(target).context);
412
- throw new TypeError("Changing an overlay prototype is not supported");
413
- }
414
- };
415
- const sharedArrayHandler = sharedObjectHandler;
416
- function createNode(context, base, parent, parentKind = 0, parentKey = "", parentSource = void 0, parentPlacement = false) {
417
- const existing = context.rawNodes?.get(base);
418
- if (existing !== void 0) return existing;
419
- const target = Array.isArray(base) ? [] : {};
420
- const baseIndex = context.bases.length;
421
- const parentIndex = parent?.baseIndex ?? -1;
422
- context.bases.push(base);
423
- const node = {
424
- context,
425
- baseIndex,
426
- parentIndex,
427
- parentKind,
428
- parentKey,
429
- parentPlacement,
430
- target,
431
- proxy: target
432
- };
433
- if (parentSource !== void 0) node.parentSource = parentSource;
434
- target[NODE] = node;
435
- node.proxy = new Proxy(target, Array.isArray(base) ? sharedArrayHandler : sharedObjectHandler);
436
- if (parent !== void 0) {
437
- context.rawNodes ??= /* @__PURE__ */ new WeakMap();
438
- context.rawNodes.set(base, node);
439
- }
440
- context.nodes.push(node);
441
- return node;
442
- }
443
- function nodeBase(node) {
444
- return node.context.bases[node.baseIndex];
445
- }
446
- function nodeParent(node) {
447
- return node.parentIndex < 0 ? void 0 : node.context.nodes[node.parentIndex];
448
- }
449
- function storeValue(context, value) {
450
- if (!isContainer(value)) return value;
451
- context.stored ??= [];
452
- const index = context.stored.length;
453
- context.stored.push(value);
454
- return { index };
455
- }
456
- function storedValue(context, reference) {
457
- return typeof reference === "object" && reference !== null ? context.stored[reference.index] : reference;
458
- }
459
- function replaceStoredValue(context, reference, value) {
460
- if (isContainer(value)) {
461
- if (typeof reference === "object" && reference !== null) {
462
- context.stored[reference.index] = value;
463
- return reference;
464
- }
465
- return storeValue(context, value);
466
- }
467
- if (typeof reference === "object" && reference !== null) context.stored[reference.index] = RELEASED;
468
- return value;
469
- }
470
- function releaseStoredValue(context, reference) {
471
- if (typeof reference === "object" && reference !== null) context.stored[reference.index] = RELEASED;
472
- }
473
- function nodeForTarget(target) {
474
- const node = target[NODE];
475
- if (node === void 0) throw new TypeError("Cannot use a settled overlay");
476
- return node;
477
- }
478
- function isSettledContext(context) {
479
- return context.overlayReleased || context.status.value === "consumed" || context.status.value === "aborted" || context.status.value === "stale";
480
- }
481
- function assertReadable(context) {
482
- if (isSettledContext(context)) throw new TypeError("Cannot use a settled overlay");
483
- }
484
- function assertWritable(context) {
485
- assertReadable(context);
486
- if (context.status.value !== "open") throw new TypeError("Prepared overlays are read-only");
487
- }
488
- function getProperty(node, property) {
489
- assertReadable(node.context);
490
- if (Array.isArray(nodeBase(node))) {
491
- const overlay = arrayOverlay(node);
492
- if (property === "length") return arrayLength(overlay);
493
- if (ARRAY_MUTATORS.has(property)) return arrayMutators[property];
494
- const index = arrayIndex(property);
495
- if (index !== void 0) return getArrayIndex(node, index);
496
- return Reflect.get(Array.prototype, property, node.proxy);
497
- }
498
- if (typeof property === "symbol") return Reflect.get(nodeBase(node), property, node.proxy);
499
- const key = String(property);
500
- if (!objectHas(node, key)) {
501
- if (isObjectDeleted(node, key) || Object.hasOwn(nodeBase(node), key)) return void 0;
502
- return Reflect.get(nodeBase(node), property, node.proxy);
503
- }
504
- const value = objectValue(node, key);
505
- if (!isContainer(value)) return value;
506
- return createNode(node.context, value, node, 0, key, void 0, hasObjectWrite(node, key)).proxy;
507
- }
508
- function getArrayIndex(node, index) {
509
- const overlay = arrayOverlay(node);
510
- if (index >= arrayLength(overlay)) return void 0;
511
- const piece = locatePiece(overlay, index);
512
- const sourceIndex = piece.start + piece.step * overlay.locatedOffset;
513
- const value = entryValueAt(node, piece, sourceIndex);
514
- if (!isContainer(value)) return value;
515
- return createNode(node.context, value, node, piece.kind === "base" ? 1 : 2, sourceIndex, piece.kind === "insert" ? piece.source : void 0, piece.kind === "insert" || hasEntryOverrideAt(overlay, piece, sourceIndex)).proxy;
516
- }
517
- function setProperty(node, property, supplied) {
518
- assertWritable(node.context);
519
- if (typeof property === "symbol") throw new TypeError("Symbol writes are not supported");
520
- if (Array.isArray(nodeBase(node))) {
521
- if (property === "length") {
522
- setArrayLength(node, toArrayLength(supplied));
523
- return true;
524
- }
525
- const index = arrayIndex(property);
526
- if (index === void 0) throw new TypeError("Only array indices and length can be written");
527
- if (index > arrayLength(arrayOverlay(node))) throw new TypeError("Overlay arrays cannot contain holes");
528
- setArrayIndex(node, index, clonePlacement(supplied));
529
- return true;
530
- }
531
- const key = String(property);
532
- if (supplied === void 0) return deleteProperty(node, key);
533
- const stored = clonePlacement(supplied);
534
- const current = objectValue(node, key);
535
- const wasDeleted = isObjectDeleted(node, key);
536
- if (!wasDeleted && !isContainer(stored) && current === stored) return true;
537
- node.appends?.delete(key);
538
- setObjectWrite(node, key, stored);
539
- if (wasDeleted && Object.hasOwn(nodeBase(node), key)) {
540
- if (node.readded === void 0) node.readded = /* @__PURE__ */ new Set();
541
- node.readded.add(key);
542
- }
543
- deleteObjectDeletion(node, key);
544
- markDirty(node);
545
- return true;
546
- }
547
- function deleteProperty(node, property) {
548
- assertWritable(node.context);
549
- if (typeof property === "symbol") throw new TypeError("Symbol writes are not supported");
550
- if (Array.isArray(nodeBase(node))) throw new TypeError("Overlay arrays cannot contain holes");
551
- const key = String(property);
552
- if (!objectHas(node, key)) return true;
553
- node.appends?.delete(key);
554
- deleteObjectWrite(node, key);
555
- node.readded?.delete(key);
556
- setObjectDeletion(node, key);
557
- markDirty(node);
558
- return true;
559
- }
560
- function hasProperty(node, property) {
561
- assertReadable(node.context);
562
- if (Array.isArray(nodeBase(node))) {
563
- if (property === "length") return true;
564
- const index = arrayIndex(property);
565
- if (index !== void 0) return index < arrayLength(arrayOverlay(node));
566
- return property in Array.prototype;
567
- }
568
- return typeof property === "symbol" ? property in nodeBase(node) : objectHas(node, String(property));
569
- }
570
- function ownKeys(node) {
571
- assertReadable(node.context);
572
- if (Array.isArray(nodeBase(node))) {
573
- const length = arrayLength(arrayOverlay(node));
574
- const keys = new Array(length + 1);
575
- for (let index = 0; index < length; index++) keys[index] = String(index);
576
- keys[length] = "length";
577
- return keys;
578
- }
579
- let existingKeysOnly = node.deleteKey === void 0 && node.deletes === void 0 && node.readded === void 0 && (node.writeKey === void 0 || Object.hasOwn(nodeBase(node), node.writeKey));
580
- if (existingKeysOnly && node.writes !== void 0) {
581
- for (const key of node.writes.keys()) if (!Object.hasOwn(nodeBase(node), key)) {
582
- existingKeysOnly = false;
583
- break;
584
- }
585
- }
586
- if (existingKeysOnly) return Object.keys(nodeBase(node));
587
- const keys = Object.keys(nodeBase(node)).filter((key) => !isObjectDeleted(node, key) && !node.readded?.has(key));
588
- const seen = new Set(keys);
589
- if (node.writeKey !== void 0 && !seen.has(node.writeKey)) {
590
- keys.push(node.writeKey);
591
- seen.add(node.writeKey);
592
- }
593
- if (node.writes !== void 0) for (const key of node.writes.keys()) {
594
- if (seen.has(key)) continue;
595
- keys.push(key);
596
- seen.add(key);
597
- }
598
- const indices = [];
599
- const strings = [];
600
- for (const key of keys) {
601
- const index = arrayIndex(key);
602
- if (index === void 0) strings.push(key);
603
- else indices.push(index);
604
- }
605
- indices.sort((left, right) => left - right);
606
- return [...indices.map(String), ...strings];
607
- }
608
- function getDescriptor(node, property) {
609
- assertReadable(node.context);
610
- if (Array.isArray(nodeBase(node))) {
611
- if (property === "length") {
612
- const length = arrayLength(arrayOverlay(node));
613
- node.target.length = length;
614
- return Reflect.getOwnPropertyDescriptor(node.target, "length");
615
- }
616
- const index = arrayIndex(property);
617
- if (index === void 0 || index >= arrayLength(arrayOverlay(node))) return void 0;
618
- } else if (typeof property === "symbol" || !objectHas(node, String(property))) return void 0;
619
- return {
620
- configurable: true,
621
- enumerable: true,
622
- writable: node.context.status.value === "open",
623
- value: getProperty(node, property)
624
- };
625
- }
626
- function hasObjectWrite(node, key) {
627
- return node.writeKey === key || (node.writes?.has(key) ?? false);
628
- }
629
- function setObjectWrite(node, key, value) {
630
- if (node.writes !== void 0) {
631
- const reference = node.writes.get(key);
632
- node.writes.set(key, reference === void 0 ? storeValue(node.context, value) : replaceStoredValue(node.context, reference, value));
633
- return;
634
- }
635
- if (node.writeKey === void 0 || node.writeKey === key) {
636
- node.writeKey = key;
637
- node.writeValue = node.writeValue === void 0 ? storeValue(node.context, value) : replaceStoredValue(node.context, node.writeValue, value);
638
- return;
639
- }
640
- node.writes = /* @__PURE__ */ new Map();
641
- node.writes.set(node.writeKey, node.writeValue);
642
- node.writes.set(key, storeValue(node.context, value));
643
- node.writeKey = void 0;
644
- node.writeValue = void 0;
645
- }
646
- function deleteObjectWrite(node, key) {
647
- if (node.writeKey === key) {
648
- node.writeKey = void 0;
649
- releaseStoredValue(node.context, node.writeValue);
650
- node.writeValue = void 0;
651
- } else {
652
- const reference = node.writes?.get(key);
653
- if (reference !== void 0) releaseStoredValue(node.context, reference);
654
- node.writes?.delete(key);
655
- }
656
- }
657
- function isObjectDeleted(node, key) {
658
- return node.deleteKey === key || (node.deletes?.has(key) ?? false);
659
- }
660
- function setObjectDeletion(node, key) {
661
- if (node.deletes !== void 0) {
662
- node.deletes.add(key);
663
- return;
664
- }
665
- if (node.deleteKey === void 0 || node.deleteKey === key) {
666
- node.deleteKey = key;
667
- return;
668
- }
669
- node.deletes = /* @__PURE__ */ new Set();
670
- node.deletes.add(node.deleteKey);
671
- node.deletes.add(key);
672
- node.deleteKey = void 0;
673
- }
674
- function deleteObjectDeletion(node, key) {
675
- if (node.deleteKey === key) node.deleteKey = void 0;
676
- else node.deletes?.delete(key);
677
- }
678
- function objectHas(node, key) {
679
- if (isObjectDeleted(node, key)) return false;
680
- return hasObjectWrite(node, key) || Object.hasOwn(nodeBase(node), key);
681
- }
682
- function objectValue(node, key) {
683
- if (node.writeKey === key) return storedValue(node.context, node.writeValue);
684
- const reference = node.writes?.get(key);
685
- if (reference !== void 0) return storedValue(node.context, reference);
686
- return nodeBase(node)[key];
687
- }
688
- function markDirty(node) {
689
- if (node.dirty) return;
690
- node.dirty = true;
691
- node.context.dirty.push(node);
692
- for (let parent = nodeParent(node); parent !== void 0; parent = nodeParent(parent)) parent.subtreeDirty = true;
693
- }
694
- function arrayOverlay(node) {
695
- if (node.array !== void 0) return node.array;
696
- const base = nodeBase(node);
697
- const overlay = {
698
- root: void 0,
699
- pieces: void 0,
700
- baseOverrides: void 0,
701
- insertOverrides: void 0,
702
- structural: false,
703
- generation: 0,
704
- plan: void 0,
705
- seed: 2654435769,
706
- locatedOffset: 0,
707
- baseLocations: void 0,
708
- insertLocations: void 0
709
- };
710
- if (base.length > 0) overlay.root = createPieceNode(overlay, {
711
- kind: "base",
712
- start: 0,
713
- length: base.length,
714
- step: 1
715
- });
716
- node.array = overlay;
717
- return overlay;
718
- }
719
- function baseOverridesForWrite(overlay) {
720
- if (overlay.baseOverrides === void 0) overlay.baseOverrides = /* @__PURE__ */ new Map();
721
- return overlay.baseOverrides;
722
- }
723
- function insertOverridesForWrite(overlay) {
724
- if (overlay.insertOverrides === void 0) overlay.insertOverrides = /* @__PURE__ */ new Map();
725
- return overlay.insertOverrides;
726
- }
727
- function nextPiecePriority(overlay) {
728
- let value = overlay.seed;
729
- value ^= value << 13;
730
- value ^= value >>> 17;
731
- value ^= value << 5;
732
- overlay.seed = value >>> 0;
733
- return overlay.seed;
734
- }
735
- function treeElements(node) {
736
- return node?.elements ?? 0;
737
- }
738
- function updatePieceNode(node) {
739
- node.elements = treeElements(node.left) + node.piece.length + treeElements(node.right);
740
- }
741
- function createPieceNode(overlay, piece) {
742
- return {
743
- piece,
744
- left: void 0,
745
- right: void 0,
746
- priority: nextPiecePriority(overlay),
747
- elements: piece.length
748
- };
749
- }
750
- function mergePieceTrees(left, right) {
751
- if (left === void 0) return right;
752
- if (right === void 0) return left;
753
- if (left.priority >= right.priority) {
754
- left.right = mergePieceTrees(left.right, right);
755
- updatePieceNode(left);
756
- return left;
757
- }
758
- right.left = mergePieceTrees(left, right.left);
759
- updatePieceNode(right);
760
- return right;
761
- }
762
- function splitPieceTree(overlay, root, index) {
763
- if (root === void 0) return [void 0, void 0];
764
- const leftLength = treeElements(root.left);
765
- if (index < leftLength) {
766
- const [left, right] = splitPieceTree(overlay, root.left, index);
767
- root.left = right;
768
- updatePieceNode(root);
769
- return [left, root];
770
- }
771
- const pieceEnd = leftLength + root.piece.length;
772
- if (index > pieceEnd) {
773
- const [left, right] = splitPieceTree(overlay, root.right, index - pieceEnd);
774
- root.right = left;
775
- updatePieceNode(root);
776
- return [root, right];
777
- }
778
- if (index === leftLength) {
779
- const left = root.left;
780
- root.left = void 0;
781
- updatePieceNode(root);
782
- return [left, root];
783
- }
784
- if (index === pieceEnd) {
785
- const right = root.right;
786
- root.right = void 0;
787
- updatePieceNode(root);
788
- return [root, right];
789
- }
790
- const offset = index - leftLength;
791
- const first = {
792
- ...root.piece,
793
- length: offset
794
- };
795
- const second = {
796
- ...root.piece,
797
- start: root.piece.start + root.piece.step * offset,
798
- length: root.piece.length - offset
799
- };
800
- return [mergePieceTrees(root.left, createPieceNode(overlay, first)), mergePieceTrees(createPieceNode(overlay, second), root.right)];
801
- }
802
- function leftmostPieceNode(node) {
803
- while (node.left !== void 0) node = node.left;
804
- return node;
805
- }
806
- function rightmostPieceNode(node) {
807
- while (node.right !== void 0) node = node.right;
808
- return node;
809
- }
810
- function mergeablePieces(left, right) {
811
- if (left.kind !== right.kind) return false;
812
- if (left.kind === "insert" && left.source !== right.source) return false;
813
- if (left.length === 1 && right.length === 1) return Math.abs(right.start - left.start) === 1;
814
- return left.step === right.step && left.start + left.step * left.length === right.start;
815
- }
816
- function joinNormalized(overlay, left, right) {
817
- if (left === void 0) return right;
818
- if (right === void 0) return left;
819
- const leftPiece = rightmostPieceNode(left).piece;
820
- const rightPiece = leftmostPieceNode(right).piece;
821
- if (!mergeablePieces(leftPiece, rightPiece)) return mergePieceTrees(left, right);
822
- const [leftRest] = splitPieceTree(overlay, left, treeElements(left) - leftPiece.length);
823
- const [, rightRest] = splitPieceTree(overlay, right, rightPiece.length);
824
- const step = leftPiece.length === 1 ? rightPiece.start - leftPiece.start : leftPiece.step;
825
- return joinNormalized(overlay, joinNormalized(overlay, leftRest, createPieceNode(overlay, leftPiece.kind === "base" ? {
826
- kind: "base",
827
- start: leftPiece.start,
828
- length: leftPiece.length + rightPiece.length,
829
- step
830
- } : {
831
- kind: "insert",
832
- source: leftPiece.source,
833
- start: leftPiece.start,
834
- length: leftPiece.length + rightPiece.length,
835
- step
836
- })), rightRest);
837
- }
838
- function flattenPieceTree(node, output) {
839
- if (node === void 0) return;
840
- flattenPieceTree(node.left, output);
841
- output.push(node.piece);
842
- flattenPieceTree(node.right, output);
843
- }
844
- function piecesOf(overlay) {
845
- if (overlay.pieces === void 0) {
846
- overlay.pieces = [];
847
- flattenPieceTree(overlay.root, overlay.pieces);
848
- }
849
- return overlay.pieces;
850
- }
851
- function treeFromPieces(overlay, pieces) {
852
- mergePieces(pieces);
853
- let root;
854
- for (const piece of pieces) root = mergePieceTrees(root, createPieceNode(overlay, piece));
855
- return root;
856
- }
857
- function replaceAllPieces(overlay, pieces) {
858
- overlay.root = treeFromPieces(overlay, pieces);
859
- overlay.pieces = void 0;
860
- overlay.baseLocations = void 0;
861
- overlay.insertLocations = void 0;
862
- }
863
- function arrayLength(overlay) {
864
- return treeElements(overlay.root);
865
- }
866
- function locatePiece(overlay, index) {
867
- let node = overlay.root;
868
- while (node !== void 0) {
869
- const leftLength = treeElements(node.left);
870
- if (index < leftLength) node = node.left;
871
- else if (index >= leftLength + node.piece.length) {
872
- index -= leftLength + node.piece.length;
873
- node = node.right;
874
- } else {
875
- overlay.locatedOffset = index - leftLength;
876
- return node.piece;
877
- }
878
- }
879
- throw new RangeError("Array overlay index is out of range");
880
- }
881
- function arrayIndex(property) {
882
- if (typeof property !== "string" || property.length === 0 || property.length > 10) return void 0;
883
- if (property === "0") return 0;
884
- const first = property.charCodeAt(0);
885
- if (first < 49 || first > 57) return void 0;
886
- let index = first - 48;
887
- for (let offset = 1; offset < property.length; offset++) {
888
- const digit = property.charCodeAt(offset) - 48;
889
- if (digit < 0 || digit > 9) return void 0;
890
- index = index * 10 + digit;
891
- if (index >= 4294967295) return void 0;
892
- }
893
- return index;
894
- }
895
- function entryValueAt(node, piece, sourceIndex) {
896
- const overlay = arrayOverlay(node);
897
- if (piece.kind === "base") {
898
- const valueIndex = overlay.baseOverrides?.get(sourceIndex);
899
- return valueIndex === void 0 ? nodeBase(node)[sourceIndex] : storedValue(node.context, valueIndex);
900
- }
901
- const overrides = overlay.insertOverrides?.get(piece.source);
902
- const reference = overrides?.has(sourceIndex) ? overrides.get(sourceIndex) : piece.source.refs[sourceIndex];
903
- return storedValue(node.context, reference);
904
- }
905
- function hasEntryOverrideAt(overlay, piece, sourceIndex) {
906
- return piece.kind === "base" ? overlay.baseOverrides?.has(sourceIndex) ?? false : overlay.insertOverrides?.get(piece.source)?.has(sourceIndex) ?? false;
907
- }
908
- function extendRightmostPiece(node, amount) {
909
- if (node.right !== void 0) extendRightmostPiece(node.right, amount);
910
- else node.piece.length += amount;
911
- updatePieceNode(node);
912
- }
913
- function invalidatePieceCaches(overlay) {
914
- overlay.pieces = void 0;
915
- overlay.baseLocations = void 0;
916
- overlay.insertLocations = void 0;
917
- overlay.plan = void 0;
918
- }
919
- function replacePieceRange(node, index, remove, inserted) {
920
- if (remove === 0 && inserted.length === 0) return;
921
- const overlay = arrayOverlay(node);
922
- if (remove === 0 && index === arrayLength(overlay) && inserted.length === 1 && overlay.root !== void 0) {
923
- const addition = inserted[0];
924
- const tail = rightmostPieceNode(overlay.root).piece;
925
- if (addition.kind === "insert" && tail.kind === "insert" && tail.step === 1 && tail.start + tail.length === tail.source.refs.length) {
926
- for (let offset = 0; offset < addition.length; offset++) tail.source.refs.push(addition.source.refs[addition.start + offset]);
927
- extendRightmostPiece(overlay.root, addition.length);
928
- invalidatePieceCaches(overlay);
929
- overlay.structural = true;
930
- overlay.generation += 1;
931
- markDirty(node);
932
- return;
933
- }
934
- }
935
- const [left, rest] = splitPieceTree(overlay, overlay.root, index);
936
- const [, right] = splitPieceTree(overlay, rest, remove);
937
- overlay.root = joinNormalized(overlay, joinNormalized(overlay, left, treeFromPieces(overlay, inserted)), right);
938
- invalidatePieceCaches(overlay);
939
- overlay.structural = true;
940
- overlay.generation += 1;
941
- markDirty(node);
942
- }
943
- function mergePieces(pieces) {
944
- for (let index = 1; index < pieces.length;) {
945
- const left = pieces[index - 1];
946
- const right = pieces[index];
947
- const sameSource = left.kind === right.kind && (left.kind === "base" || left.source === right.source);
948
- if (sameSource && left.length === 1 && right.length === 1 && Math.abs(right.start - left.start) === 1) {
949
- left.step = right.start - left.start;
950
- left.length = 2;
951
- pieces.splice(index, 1);
952
- } else if (sameSource && left.step === right.step && left.start + left.step * left.length === right.start) {
953
- left.length += right.length;
954
- pieces.splice(index, 1);
955
- } else index += 1;
956
- }
957
- }
958
- function insertPiece(node, items, start = 0) {
959
- if (items.length === start) return [];
960
- const refs = [];
961
- for (let index = start; index < items.length; index++) refs.push(storeValue(node.context, items[index]));
962
- return [{
963
- kind: "insert",
964
- source: { refs },
965
- start: 0,
966
- length: refs.length,
967
- step: 1
968
- }];
969
- }
970
- function insertPlacementPiece(node, values, start = 0) {
971
- if (values.length === start) return [];
972
- const storedLength = node.context.stored?.length ?? 0;
973
- try {
974
- for (let index = start; index < values.length; index++) values[index] = storeValue(node.context, clonePlacement(values[index]));
975
- } catch (error) {
976
- if (node.context.stored !== void 0) node.context.stored.length = storedLength;
977
- throw error;
978
- }
979
- return [{
980
- kind: "insert",
981
- source: { refs: values },
982
- start,
983
- length: values.length - start,
984
- step: 1
985
- }];
986
- }
987
- function setArrayIndex(node, index, stored) {
988
- const overlay = arrayOverlay(node);
989
- const length = arrayLength(overlay);
990
- if (index === length) {
991
- replacePieceRange(node, length, 0, insertPiece(node, [stored]));
992
- return;
993
- }
994
- const piece = locatePiece(overlay, index);
995
- const sourceIndex = piece.start + piece.step * overlay.locatedOffset;
996
- const current = entryValueAt(node, piece, sourceIndex);
997
- if (!isContainer(stored) && current === stored) return;
998
- if (piece.kind === "base") {
999
- const existingIndex = overlay.baseOverrides?.get(sourceIndex);
1000
- if (!isContainer(stored) && stored === nodeBase(node)[sourceIndex]) {
1001
- if (existingIndex !== void 0) releaseStoredValue(node.context, existingIndex);
1002
- overlay.baseOverrides?.delete(sourceIndex);
1003
- } else if (existingIndex === void 0) baseOverridesForWrite(overlay).set(sourceIndex, storeValue(node.context, stored));
1004
- else overlay.baseOverrides.set(sourceIndex, replaceStoredValue(node.context, existingIndex, stored));
1005
- } else {
1006
- let overrides = overlay.insertOverrides?.get(piece.source);
1007
- const existingIndex = overrides?.get(sourceIndex);
1008
- if (!isContainer(stored) && stored === storedValue(node.context, piece.source.refs[sourceIndex])) {
1009
- if (existingIndex !== void 0) releaseStoredValue(node.context, existingIndex);
1010
- overrides?.delete(sourceIndex);
1011
- if (overrides?.size === 0) overlay.insertOverrides?.delete(piece.source);
1012
- } else {
1013
- if (overrides === void 0) {
1014
- overrides = /* @__PURE__ */ new Map();
1015
- insertOverridesForWrite(overlay).set(piece.source, overrides);
1016
- }
1017
- if (existingIndex === void 0) overrides.set(sourceIndex, storeValue(node.context, stored));
1018
- else overrides.set(sourceIndex, replaceStoredValue(node.context, existingIndex, stored));
1019
- }
1020
- }
1021
- markDirty(node);
1022
- }
1023
- function setArrayLength(node, next) {
1024
- const current = arrayLength(arrayOverlay(node));
1025
- if (next === current) return;
1026
- if (next < current) replacePieceRange(node, next, current - next, []);
1027
- else replacePieceRange(node, current, 0, insertPiece(node, Array.from({ length: next - current }, () => null)));
1028
- }
1029
- function toArrayLength(value) {
1030
- const number = Number(value);
1031
- if (!Number.isInteger(number) || number < 0 || number >= 4294967296) throw new RangeError("Invalid array length");
1032
- return number;
1033
- }
1034
- function toIntegerOrInfinity(value) {
1035
- const number = Number(value);
1036
- if (Number.isNaN(number) || number === 0) return 0;
1037
- return Number.isFinite(number) ? Math.trunc(number) : number;
1038
- }
1039
- function clampIndex(value, length) {
1040
- if (value === Number.NEGATIVE_INFINITY) return 0;
1041
- if (value < 0) return Math.max(length + value, 0);
1042
- return Math.min(value, length);
1043
- }
1044
- function mutatorNode(receiver) {
1045
- if (!isContainer(receiver)) return void 0;
1046
- const node = Reflect.get(receiver, NODE);
1047
- if (node === void 0) return void 0;
1048
- if (!Array.isArray(nodeBase(node))) throw new TypeError("Array mutator called on incompatible receiver");
1049
- assertWritable(node.context);
1050
- return node;
1051
- }
1052
- const arrayMutators = {
1053
- push(...items) {
1054
- const node = mutatorNode(this);
1055
- if (node === void 0) return Reflect.apply(Array.prototype.push, this, items);
1056
- const length = arrayLength(arrayOverlay(node));
1057
- replacePieceRange(node, length, 0, insertPlacementPiece(node, items));
1058
- return length + items.length;
1059
- },
1060
- pop() {
1061
- const node = mutatorNode(this);
1062
- if (node === void 0) return Reflect.apply(Array.prototype.pop, this, []);
1063
- const length = arrayLength(arrayOverlay(node));
1064
- if (length === 0) return void 0;
1065
- const value = getArrayIndex(node, length - 1);
1066
- replacePieceRange(node, length - 1, 1, []);
1067
- return value;
1068
- },
1069
- shift() {
1070
- const node = mutatorNode(this);
1071
- if (node === void 0) return Reflect.apply(Array.prototype.shift, this, []);
1072
- if (arrayLength(arrayOverlay(node)) === 0) return void 0;
1073
- const value = getArrayIndex(node, 0);
1074
- replacePieceRange(node, 0, 1, []);
1075
- return value;
1076
- },
1077
- unshift(...items) {
1078
- const node = mutatorNode(this);
1079
- if (node === void 0) return Reflect.apply(Array.prototype.unshift, this, items);
1080
- replacePieceRange(node, 0, 0, insertPlacementPiece(node, items));
1081
- return arrayLength(arrayOverlay(node));
1082
- },
1083
- splice(...args) {
1084
- const node = mutatorNode(this);
1085
- if (node === void 0) return Reflect.apply(Array.prototype.splice, this, args);
1086
- const length = arrayLength(arrayOverlay(node));
1087
- const start = args.length === 0 ? 0 : clampIndex(toIntegerOrInfinity(args[0]), length);
1088
- const remove = args.length === 0 ? 0 : args.length === 1 ? length - start : Math.min(Math.max(toIntegerOrInfinity(args[1]), 0), length - start);
1089
- const removed = Array.from({ length: remove }, (_, offset) => getArrayIndex(node, start + offset));
1090
- const itemStart = Math.min(2, args.length);
1091
- const itemCount = Math.max(args.length - 2, 0);
1092
- replacePieceRange(node, start, remove, insertPlacementPiece(node, args, itemStart));
1093
- setArrayLength(node, length - remove + itemCount);
1094
- return removed;
1095
- },
1096
- reverse() {
1097
- const node = mutatorNode(this);
1098
- if (node === void 0) return Reflect.apply(Array.prototype.reverse, this, []);
1099
- const overlay = arrayOverlay(node);
1100
- if (arrayLength(overlay) < 2) return node.proxy;
1101
- const pieces = [...piecesOf(overlay)].reverse();
1102
- for (const piece of pieces) {
1103
- piece.start += piece.step * (piece.length - 1);
1104
- piece.step = piece.step === 1 ? -1 : 1;
1105
- }
1106
- replaceAllPieces(overlay, pieces);
1107
- overlay.structural = true;
1108
- overlay.generation += 1;
1109
- overlay.plan = void 0;
1110
- markDirty(node);
1111
- return node.proxy;
1112
- },
1113
- sort(comparator) {
1114
- const node = mutatorNode(this);
1115
- if (node === void 0) return Reflect.apply(Array.prototype.sort, this, [comparator]);
1116
- if (comparator !== void 0 && typeof comparator !== "function") throw new TypeError("Comparator must be a function");
1117
- const overlay = arrayOverlay(node);
1118
- const insertedSources = [];
1119
- const insertedIndices = [];
1120
- const insertedValues = [];
1121
- const baseValues = new Array(nodeBase(node).length);
1122
- const order = [];
1123
- for (const piece of piecesOf(overlay)) for (let offset = 0; offset < piece.length; offset++) {
1124
- const sourceIndex = piece.start + piece.step * offset;
1125
- if (piece.kind === "base") {
1126
- order.push(sourceIndex);
1127
- baseValues[sourceIndex] = publicSortValue(node, sourceIndex, insertedSources, insertedIndices);
1128
- } else {
1129
- insertedSources.push(piece.source);
1130
- insertedIndices.push(sourceIndex);
1131
- const token = -insertedSources.length;
1132
- order.push(token);
1133
- insertedValues.push(publicSortValue(node, token, insertedSources, insertedIndices));
1134
- }
1135
- }
1136
- const baseSnapshot = /* @__PURE__ */ new Map();
1137
- for (const [index, valueIndex] of overlay.baseOverrides ?? []) baseSnapshot.set(index, storedValue(node.context, valueIndex));
1138
- const insertSnapshots = /* @__PURE__ */ new Map();
1139
- for (const [source, overrides] of overlay.insertOverrides ?? []) {
1140
- const snapshot = /* @__PURE__ */ new Map();
1141
- for (const [index, valueIndex] of overrides) snapshot.set(index, storedValue(node.context, valueIndex));
1142
- insertSnapshots.set(source, snapshot);
1143
- }
1144
- const generation = overlay.generation;
1145
- order.sort((left, right) => {
1146
- const leftValue = left < 0 ? insertedValues[-left - 1] : baseValues[left];
1147
- const rightValue = right < 0 ? insertedValues[-right - 1] : baseValues[right];
1148
- if (typeof comparator === "function") return Number(comparator(leftValue, rightValue));
1149
- const a = String(leftValue);
1150
- const b = String(rightValue);
1151
- return a < b ? -1 : a > b ? 1 : 0;
1152
- });
1153
- if (baseSnapshot.size > 0 || insertSnapshots.size > 0 || (overlay.baseOverrides?.size ?? 0) > 0 || (overlay.insertOverrides?.size ?? 0) > 0) for (const token of order) restoreSortOverride(node, token, insertedSources, insertedIndices, baseSnapshot, insertSnapshots);
1154
- const comparatorWasStructural = overlay.generation !== generation;
1155
- const currentLength = arrayLength(overlay);
1156
- if (!(currentLength >= order.length && order.every((token, index) => sameSortTokenAt(overlay, index, token, insertedSources, insertedIndices)))) replacePieceRange(node, 0, Math.min(order.length, currentLength), piecesFromSortOrder(order, insertedSources, insertedIndices));
1157
- if (comparatorWasStructural) deduplicateArrayEntries(node);
1158
- return node.proxy;
1159
- },
1160
- fill(supplied, startArg, endArg) {
1161
- const node = mutatorNode(this);
1162
- if (node === void 0) return Reflect.apply(Array.prototype.fill, this, [
1163
- supplied,
1164
- startArg,
1165
- endArg
1166
- ]);
1167
- const length = arrayLength(arrayOverlay(node));
1168
- const start = startArg === void 0 ? 0 : clampIndex(toIntegerOrInfinity(startArg), length);
1169
- const end = endArg === void 0 ? length : clampIndex(toIntegerOrInfinity(endArg), length);
1170
- if (end <= start) return node.proxy;
1171
- const items = Array.from({ length: end - start }, () => clonePlacement(supplied));
1172
- replacePieceRange(node, start, end - start, insertPiece(node, items));
1173
- return node.proxy;
1174
- },
1175
- copyWithin(targetArg, startArg, endArg) {
1176
- const node = mutatorNode(this);
1177
- if (node === void 0) return Reflect.apply(Array.prototype.copyWithin, this, [
1178
- targetArg,
1179
- startArg,
1180
- endArg
1181
- ]);
1182
- const length = arrayLength(arrayOverlay(node));
1183
- const target = clampIndex(toIntegerOrInfinity(targetArg), length);
1184
- const start = clampIndex(toIntegerOrInfinity(startArg), length);
1185
- const end = endArg === void 0 ? length : clampIndex(toIntegerOrInfinity(endArg), length);
1186
- const count = Math.min(Math.max(end - start, 0), length - target);
1187
- replacePieceRange(node, target, count, insertPiece(node, Array.from({ length: count }, (_, offset) => clonePlacement(getArrayIndex(node, start + offset)))));
1188
- return node.proxy;
1189
- }
1190
- };
1191
- function sortTokenSource(token, sources) {
1192
- return token < 0 ? sources[-token - 1] : void 0;
1193
- }
1194
- function sortTokenIndex(token, indices) {
1195
- return token < 0 ? indices[-token - 1] : token;
1196
- }
1197
- function publicSortValue(node, token, sources, indices) {
1198
- const overlay = arrayOverlay(node);
1199
- const source = sortTokenSource(token, sources);
1200
- const sourceIndex = sortTokenIndex(token, indices);
1201
- const overrideIndex = source === void 0 ? overlay.baseOverrides?.get(sourceIndex) : overlay.insertOverrides?.get(source)?.get(sourceIndex);
1202
- const value = overrideIndex !== void 0 ? storedValue(node.context, overrideIndex) : source === void 0 ? nodeBase(node)[sourceIndex] : storedValue(node.context, source.refs[sourceIndex]);
1203
- if (!isContainer(value)) return value;
1204
- return createNode(node.context, value, node, source === void 0 ? 1 : 2, sourceIndex, source, source !== void 0 || (overlay.baseOverrides?.has(sourceIndex) ?? false)).proxy;
1205
- }
1206
- function restoreSortOverride(node, token, sources, indices, baseSnapshot, insertSnapshots) {
1207
- const overlay = arrayOverlay(node);
1208
- const source = sortTokenSource(token, sources);
1209
- const sourceIndex = sortTokenIndex(token, indices);
1210
- if (source === void 0) {
1211
- const existingIndex = overlay.baseOverrides?.get(sourceIndex);
1212
- const snapshotValue = baseSnapshot.get(sourceIndex);
1213
- if (snapshotValue !== void 0) {
1214
- if (existingIndex === void 0) baseOverridesForWrite(overlay).set(sourceIndex, storeValue(node.context, snapshotValue));
1215
- else overlay.baseOverrides.set(sourceIndex, replaceStoredValue(node.context, existingIndex, snapshotValue));
1216
- } else {
1217
- if (existingIndex !== void 0) releaseStoredValue(node.context, existingIndex);
1218
- overlay.baseOverrides?.delete(sourceIndex);
1219
- }
1220
- return;
1221
- }
1222
- let overrides = overlay.insertOverrides?.get(source);
1223
- const existingIndex = overrides?.get(sourceIndex);
1224
- const snapshotValue = insertSnapshots.get(source)?.get(sourceIndex);
1225
- if (snapshotValue !== void 0) {
1226
- if (overrides === void 0) {
1227
- overrides = /* @__PURE__ */ new Map();
1228
- insertOverridesForWrite(overlay).set(source, overrides);
1229
- }
1230
- if (existingIndex === void 0) overrides.set(sourceIndex, storeValue(node.context, snapshotValue));
1231
- else overrides.set(sourceIndex, replaceStoredValue(node.context, existingIndex, snapshotValue));
1232
- } else {
1233
- if (existingIndex !== void 0) releaseStoredValue(node.context, existingIndex);
1234
- overrides?.delete(sourceIndex);
1235
- if (overrides?.size === 0) overlay.insertOverrides?.delete(source);
1236
- }
1237
- }
1238
- function sameSortTokenAt(overlay, logicalIndex, token, sources, indices) {
1239
- const piece = locatePiece(overlay, logicalIndex);
1240
- const sourceIndex = piece.start + piece.step * overlay.locatedOffset;
1241
- const tokenSource = sortTokenSource(token, sources);
1242
- return sourceIndex === sortTokenIndex(token, indices) && (piece.kind === "base" && tokenSource === void 0 || piece.kind === "insert" && piece.source === tokenSource);
1243
- }
1244
- function deduplicateArrayEntries(node) {
1245
- const overlay = arrayOverlay(node);
1246
- const seenBase = /* @__PURE__ */ new Set();
1247
- const seenInsert = /* @__PURE__ */ new Map();
1248
- const next = [];
1249
- let duplicated = false;
1250
- for (const piece of piecesOf(overlay)) for (let offset = 0; offset < piece.length; offset++) {
1251
- const sourceIndex = piece.start + piece.step * offset;
1252
- let seen;
1253
- if (piece.kind === "base") {
1254
- seen = seenBase.has(sourceIndex);
1255
- seenBase.add(sourceIndex);
1256
- } else {
1257
- let indices = seenInsert.get(piece.source);
1258
- if (indices === void 0) {
1259
- indices = /* @__PURE__ */ new Set();
1260
- seenInsert.set(piece.source, indices);
1261
- }
1262
- seen = indices.has(sourceIndex);
1263
- indices.add(sourceIndex);
1264
- }
1265
- if (seen) {
1266
- duplicated = true;
1267
- appendMergedPiece(next, insertPiece(node, [clonePlacementStored(entryValueAt(node, piece, sourceIndex), node.context)])[0]);
1268
- } else appendMergedPiece(next, singletonPiece(piece, sourceIndex));
1269
- }
1270
- if (!duplicated) return;
1271
- replaceAllPieces(overlay, next);
1272
- overlay.structural = true;
1273
- overlay.generation += 1;
1274
- overlay.plan = void 0;
1275
- markDirty(node);
1276
- }
1277
- function piecesFromSortOrder(order, sources, indices) {
1278
- const pieces = [];
1279
- for (const token of order) {
1280
- const source = token < 0 ? sources[-token - 1] : void 0;
1281
- const sourceIndex = token < 0 ? indices[-token - 1] : token;
1282
- const previous = pieces.at(-1);
1283
- const sameSource = previous !== void 0 && (source === void 0 && previous.kind === "base" || source !== void 0 && previous.kind === "insert" && previous.source === source);
1284
- if (previous !== void 0 && sameSource) {
1285
- if (previous.length === 1) {
1286
- const step = sourceIndex - previous.start;
1287
- if (step === 1 || step === -1) {
1288
- previous.step = step;
1289
- previous.length = 2;
1290
- continue;
1291
- }
1292
- } else if (previous.start + previous.step * previous.length === sourceIndex) {
1293
- previous.length += 1;
1294
- continue;
1295
- }
1296
- }
1297
- pieces.push(source === void 0 ? {
1298
- kind: "base",
1299
- start: sourceIndex,
1300
- length: 1,
1301
- step: 1
1302
- } : {
1303
- kind: "insert",
1304
- source,
1305
- start: sourceIndex,
1306
- length: 1,
1307
- step: 1
1308
- });
1309
- }
1310
- return pieces;
1311
- }
1312
- function appendMergedPiece(pieces, piece) {
1313
- const previous = pieces.at(-1);
1314
- const sameSource = previous !== void 0 && previous.kind === piece.kind && (previous.kind === "base" || previous.source === piece.source);
1315
- if (previous !== void 0 && sameSource && previous.length === 1 && piece.length === 1) {
1316
- const step = piece.start - previous.start;
1317
- if (step === 1 || step === -1) {
1318
- previous.step = step;
1319
- previous.length = 2;
1320
- return;
1321
- }
1322
- }
1323
- if (previous !== void 0 && sameSource && previous.step === piece.step && previous.start + previous.step * previous.length === piece.start) previous.length += piece.length;
1324
- else pieces.push(piece);
1325
- }
1326
- function singletonPiece(piece, sourceIndex) {
1327
- return piece.kind === "base" ? {
1328
- kind: "base",
1329
- start: sourceIndex,
1330
- length: 1,
1331
- step: 1
1332
- } : {
1333
- kind: "insert",
1334
- source: piece.source,
1335
- start: sourceIndex,
1336
- length: 1,
1337
- step: 1
1338
- };
1339
- }
1340
- function clonePlacement(value) {
1341
- const proxyNode = isContainer(value) ? Reflect.get(value, NODE) : void 0;
1342
- return proxyNode === void 0 ? copyJson(value) : clonePlacementNode(proxyNode);
1343
- }
1344
- function cloneNode(node) {
1345
- assertReadable(node.context);
1346
- if (Array.isArray(nodeBase(node))) {
1347
- const overlay = arrayOverlay(node);
1348
- const result = [];
1349
- for (const piece of piecesOf(overlay)) for (let offset = 0; offset < piece.length; offset++) {
1350
- const sourceIndex = piece.start + piece.step * offset;
1351
- result.push(cloneStored(entryValueAt(node, piece, sourceIndex), node.context));
1352
- }
1353
- return result;
1354
- }
1355
- const result = Object.create(Object.getPrototypeOf(nodeBase(node)));
1356
- for (const key of ownKeys(node)) defineData(result, key, cloneStored(objectValue(node, key), node.context));
1357
- return result;
1358
- }
1359
- function cloneStored(value, context) {
1360
- if (!isContainer(value)) return value;
1361
- const node = context.rawNodes?.get(value);
1362
- return node === void 0 || !node.dirty && !node.subtreeDirty ? value : cloneNode(node);
1363
- }
1364
- function clonePlacementNode(node) {
1365
- assertReadable(node.context);
1366
- if (Array.isArray(nodeBase(node))) {
1367
- const overlay = arrayOverlay(node);
1368
- const result = [];
1369
- for (const piece of piecesOf(overlay)) for (let offset = 0; offset < piece.length; offset++) {
1370
- const sourceIndex = piece.start + piece.step * offset;
1371
- result.push(clonePlacementStored(entryValueAt(node, piece, sourceIndex), node.context));
1372
- }
1373
- return result;
1374
- }
1375
- const result = Object.create(Object.getPrototypeOf(nodeBase(node)));
1376
- for (const key of ownKeys(node)) defineData(result, key, clonePlacementStored(objectValue(node, key), node.context));
1377
- return result;
1378
- }
1379
- function clonePlacementStored(value, context) {
1380
- if (!isContainer(value)) return copyJson(value);
1381
- const node = context.rawNodes?.get(value);
1382
- return node === void 0 ? copyJson(value) : clonePlacementNode(node);
1383
- }
1384
- function defineData(target, key, value) {
1385
- DATA_DESCRIPTOR.value = value;
1386
- Object.defineProperty(target, key, DATA_DESCRIPTOR);
1387
- DATA_DESCRIPTOR.value = void 0;
1388
- }
1389
- function emitOperations(context) {
1390
- const simple = emitSimpleObjectOperations(context);
1391
- if (simple !== void 0) return simple;
1392
- const operations = [];
1393
- const forcedFolds = /* @__PURE__ */ new Map();
1394
- const emissionPaths = /* @__PURE__ */ new Map();
1395
- const denseIndices = /* @__PURE__ */ new Map();
1396
- for (const node of context.dirty) {
1397
- recordDenseArrayPosition(node, denseIndices);
1398
- if (Array.isArray(nodeBase(node))) {
1399
- const overlay = arrayOverlay(node);
1400
- if (!overlay.structural && (overlay.baseOverrides?.size ?? 0) > 0) {
1401
- let candidates = denseIndices.get(node);
1402
- if (candidates === void 0) {
1403
- candidates = {
1404
- indices: [],
1405
- bits: void 0,
1406
- length: nodeBase(node).length
1407
- };
1408
- denseIndices.set(node, candidates);
1409
- }
1410
- for (const index of overlay.baseOverrides.keys()) addDenseCandidate(candidates, index);
1411
- }
1412
- }
1413
- }
1414
- const denseRegions = /* @__PURE__ */ new Map();
1415
- for (const [array, candidates] of denseIndices) {
1416
- const path = resolvePath(array);
1417
- if (path === void 0 || path.some((segment) => typeof segment === "string" && RESERVED_SEGMENTS.has(segment))) continue;
1418
- const regions = buildDenseRegions(candidates);
1419
- if (regions.length > 0) denseRegions.set(array, regions);
1420
- }
1421
- for (const node of context.dirty) {
1422
- const path = resolvePath(node);
1423
- if (path === void 0) continue;
1424
- if (hasCoveringDenseRegion(node, path, denseRegions)) continue;
1425
- emissionPaths.set(node, path);
1426
- if (!Array.isArray(nodeBase(node)) && hasReservedMutation(node)) forcedFolds.set(node, path);
1427
- const reservedAt = path.findIndex((segment) => typeof segment === "string" && RESERVED_SEGMENTS.has(segment));
1428
- if (reservedAt >= 0) {
1429
- let ancestor = node;
1430
- for (let depth = path.length; depth > reservedAt; depth--) ancestor = nodeParent(ancestor);
1431
- forcedFolds.set(ancestor, path.slice(0, reservedAt));
1432
- }
1433
- }
1434
- for (const [node, path] of forcedFolds) emissionPaths.set(node, path);
1435
- for (const node of denseRegions.keys()) {
1436
- const path = resolvePath(node);
1437
- if (path !== void 0 && !hasCoveringDenseRegion(node, path, denseRegions)) emissionPaths.set(node, path);
1438
- }
1439
- let maxDepth = 0;
1440
- for (const path of emissionPaths.values()) maxDepth = Math.max(maxDepth, path.length);
1441
- const buckets = Array.from({ length: maxDepth + 1 }, () => []);
1442
- for (const [node, path] of emissionPaths) buckets[path.length].push(node);
1443
- const folded = /* @__PURE__ */ new Set();
1444
- for (const bucket of buckets) for (const node of bucket) {
1445
- const path = emissionPaths.get(node);
1446
- if (hasPlacementAncestor(node) || hasFoldedAncestor(node, folded)) continue;
1447
- if (forcedFolds.has(node)) {
1448
- emitSet(operations, path, cloneNode(node));
1449
- folded.add(node);
1450
- continue;
1451
- }
1452
- if (Array.isArray(nodeBase(node))) emitArrayOperations(node, path, operations, denseRegions.get(node));
1453
- else emitObjectOperations(node, path, operations);
1454
- if (operations.length > MAX_DELTA_OPERATIONS) {
1455
- locatedDenseArray = void 0;
1456
- return [["r", cloneNode(context.root)]];
1457
- }
1458
- }
1459
- locatedDenseArray = void 0;
1460
- return operations;
1461
- }
1462
- function emitSimpleObjectOperations(context) {
1463
- const nodes = [];
1464
- for (const node of context.dirty) {
1465
- if (Array.isArray(nodeBase(node)) || hasReservedMutation(node) || hasPlacementAncestor(node)) return void 0;
1466
- for (let parent = nodeParent(node); parent !== void 0; parent = nodeParent(parent)) if (Array.isArray(nodeBase(parent))) return void 0;
1467
- const path = resolvePath(node);
1468
- if (path === void 0) continue;
1469
- for (const segment of path) if (typeof segment === "string" && RESERVED_SEGMENTS.has(segment)) return void 0;
1470
- nodes.push(node);
1471
- if (nodes.length > MAX_SIMPLE_OBJECT_NODES) return void 0;
1472
- }
1473
- for (let index = 1; index < nodes.length; index++) {
1474
- const node = nodes[index];
1475
- const depth = node.preparedPath.length;
1476
- let at = index;
1477
- while (at > 0 && nodes[at - 1].preparedPath.length > depth) {
1478
- nodes[at] = nodes[at - 1];
1479
- at -= 1;
1480
- }
1481
- nodes[at] = node;
1482
- }
1483
- const operations = [];
1484
- let canMaterializeDirectly = true;
1485
- for (const node of nodes) {
1486
- if (emitObjectOperations(node, node.preparedPath, operations)) canMaterializeDirectly = false;
1487
- if (operations.length > MAX_DELTA_OPERATIONS) return [["r", cloneNode(context.root)]];
1488
- }
1489
- context.simpleObjectMaterialization = canMaterializeDirectly;
1490
- return operations;
1491
- }
1492
- let locatedDenseArray;
1493
- let locatedDenseIndex = 0;
1494
- function locateDenseArrayPosition(node) {
1495
- let child = node;
1496
- for (let parent = nodeParent(child); parent !== void 0; parent = nodeParent(child)) {
1497
- if (Array.isArray(nodeBase(parent))) {
1498
- const overlay = arrayOverlay(parent);
1499
- if (child.parentKind !== 1 || overlay.structural) return false;
1500
- const sourceIndex = child.parentKey;
1501
- const valueIndex = overlay.baseOverrides?.get(sourceIndex);
1502
- if ((valueIndex === void 0 ? nodeBase(parent)[sourceIndex] : storedValue(parent.context, valueIndex)) !== nodeBase(child)) return false;
1503
- locatedDenseArray = parent;
1504
- locatedDenseIndex = sourceIndex;
1505
- return true;
1506
- }
1507
- child = parent;
1508
- }
1509
- return false;
1510
- }
1511
- function hasCoveringDenseRegion(node, path, denseRegions) {
1512
- for (let parent = nodeParent(node); parent !== void 0; parent = nodeParent(parent)) {
1513
- const regions = denseRegions.get(parent);
1514
- if (regions === void 0) continue;
1515
- const parentPath = resolvePath(parent);
1516
- if (parentPath === void 0 || path.length <= parentPath.length) continue;
1517
- let matches = true;
1518
- for (let index = 0; index < parentPath.length; index++) if (path[index] !== parentPath[index]) {
1519
- matches = false;
1520
- break;
1521
- }
1522
- if (!matches) continue;
1523
- const index = path[parentPath.length];
1524
- if (typeof index === "number" && regionContaining(regions, index)) return true;
1525
- }
1526
- return false;
1527
- }
1528
- function addDenseCandidate(candidates, index) {
1529
- if (candidates.bits !== void 0) {
1530
- candidates.bits[index] = 1;
1531
- return;
1532
- }
1533
- candidates.indices.push(index);
1534
- if (candidates.indices.length < 256) return;
1535
- candidates.bits = new Uint8Array(candidates.length);
1536
- for (const existing of candidates.indices) candidates.bits[existing] = 1;
1537
- candidates.indices.length = 0;
1538
- }
1539
- function recordDenseArrayPosition(node, groups) {
1540
- if (!locateDenseArrayPosition(node)) return;
1541
- let candidates = groups.get(locatedDenseArray);
1542
- if (candidates === void 0) {
1543
- candidates = {
1544
- indices: [],
1545
- bits: void 0,
1546
- length: nodeBase(locatedDenseArray).length
1547
- };
1548
- groups.set(locatedDenseArray, candidates);
1549
- }
1550
- addDenseCandidate(candidates, locatedDenseIndex);
1551
- }
1552
- function buildDenseRegions(candidates) {
1553
- if (candidates.bits === void 0) return [];
1554
- const regions = [];
1555
- const bits = candidates.bits;
1556
- for (let at = 0; at < bits.length;) {
1557
- while (at < bits.length && bits[at] === 0) at += 1;
1558
- if (at === bits.length) break;
1559
- const start = at;
1560
- let end = at;
1561
- let count = 0;
1562
- let gap = 0;
1563
- while (at < bits.length) {
1564
- if (bits[at] !== 0) {
1565
- count += 1;
1566
- end = at;
1567
- gap = 0;
1568
- } else if (++gap > 1) break;
1569
- at += 1;
1570
- }
1571
- const length = end - start + 1;
1572
- if (count >= 256 && count * 2 >= length) regions.push({
1573
- start,
1574
- length
1575
- });
1576
- }
1577
- return regions;
1578
- }
1579
- function regionContaining(regions, index) {
1580
- for (const region of regions) if (index >= region.start && index < region.start + region.length) return true;
1581
- return false;
1582
- }
1583
- function hasReservedMutation(node) {
1584
- if (node.writeKey !== void 0 && RESERVED_SEGMENTS.has(node.writeKey)) return true;
1585
- if (node.deleteKey !== void 0 && RESERVED_SEGMENTS.has(node.deleteKey)) return true;
1586
- if (node.writes !== void 0) {
1587
- for (const key of node.writes.keys()) if (RESERVED_SEGMENTS.has(key)) return true;
1588
- }
1589
- if (node.deletes !== void 0) {
1590
- for (const key of node.deletes) if (RESERVED_SEGMENTS.has(key)) return true;
1591
- }
1592
- return false;
1593
- }
1594
- function hasFoldedAncestor(node, folded) {
1595
- for (let parent = nodeParent(node); parent !== void 0; parent = nodeParent(parent)) if (folded.has(parent)) return true;
1596
- return false;
1597
- }
1598
- function hasPlacementAncestor(node) {
1599
- for (let current = node; current !== void 0; current = nodeParent(current)) if (nodeParent(current) !== void 0 && current.parentPlacement) return true;
1600
- return false;
1601
- }
1602
- function emitObjectWrite(node, path, operations, key, value) {
1603
- const nextPath = [...path, key];
1604
- const appended = node.appends?.get(key);
1605
- if (appended !== void 0) {
1606
- operations.push([
1607
- "a",
1608
- nextPath,
1609
- appended
1610
- ]);
1611
- return false;
1612
- }
1613
- const before = node.readded?.has(key) || !Object.hasOwn(nodeBase(node), key) ? void 0 : nodeBase(node)[key];
1614
- const after = cloneStored(value, node.context);
1615
- const emitted = emitChangedValue(operations, nextPath, before, after);
1616
- return isContainer(before) && isContainer(after) && !emitted;
1617
- }
1618
- function emitObjectOperations(node, path, operations) {
1619
- if (node.readded !== void 0) {
1620
- for (const key of node.readded) if (Object.hasOwn(nodeBase(node), key)) operations.push(["d", [...path, key]]);
1621
- }
1622
- let normalizedContainerWrite = false;
1623
- if (node.writeKey !== void 0) normalizedContainerWrite = emitObjectWrite(node, path, operations, node.writeKey, objectValue(node, node.writeKey));
1624
- if (node.writes !== void 0) for (const [key, valueIndex] of node.writes) {
1625
- if (operations.length > MAX_DELTA_OPERATIONS) return normalizedContainerWrite;
1626
- if (emitObjectWrite(node, path, operations, key, storedValue(node.context, valueIndex))) normalizedContainerWrite = true;
1627
- }
1628
- if (node.deleteKey !== void 0 && Object.hasOwn(nodeBase(node), node.deleteKey)) operations.push(["d", [...path, node.deleteKey]]);
1629
- if (node.deletes !== void 0) for (const key of node.deletes) {
1630
- if (operations.length > MAX_DELTA_OPERATIONS) return normalizedContainerWrite;
1631
- if (Object.hasOwn(nodeBase(node), key)) operations.push(["d", [...path, key]]);
1632
- }
1633
- return normalizedContainerWrite;
1634
- }
1635
- function buildArrayPlan(node) {
1636
- const overlay = arrayOverlay(node);
1637
- if (overlay.plan !== void 0) return overlay.plan;
1638
- const base = nodeBase(node);
1639
- const pieces = piecesOf(overlay);
1640
- overlay.plan = orderedArrayPlan(base.length, pieces) ?? elementArrayPlan(base.length, pieces);
1641
- return overlay.plan;
1642
- }
1643
- /**
1644
- * The plan when the retained base elements keep their order, the common case of inserts and removals: computed from the
1645
- * pieces alone, so appending to a long array costs no walk over its elements. `undefined` when base elements moved.
1646
- */
1647
- function orderedArrayPlan(baseLength, pieces) {
1648
- const ranges = [];
1649
- for (const piece of pieces) {
1650
- if (piece.kind !== "base" || piece.length === 0) continue;
1651
- if (piece.step !== 1 && piece.length > 1) return void 0;
1652
- if (ranges.length > 0 && piece.start <= ranges[ranges.length - 1]) return void 0;
1653
- ranges.push(piece.start, piece.start + piece.length - 1);
1654
- }
1655
- const removeRuns = [];
1656
- let end = baseLength;
1657
- for (let index = ranges.length - 2; index >= -2; index -= 2) {
1658
- const start = index >= 0 ? ranges[index + 1] + 1 : 0;
1659
- if (end > start) removeRuns.push(start, end - start);
1660
- if (index >= 0) end = ranges[index];
1661
- }
1662
- return {
1663
- removeRuns,
1664
- permutation: void 0,
1665
- insertRuns: insertRunsOf(pieces)
1666
- };
1667
- }
1668
- /** The plan from a walk over every base element, for pieces that moved base elements. */
1669
- function elementArrayPlan(baseLength, pieces) {
1670
- const retained = new Uint8Array(baseLength);
1671
- const targetBase = [];
1672
- for (const piece of pieces) {
1673
- if (piece.kind !== "base") continue;
1674
- for (let offset = 0; offset < piece.length; offset++) {
1675
- const index = piece.start + piece.step * offset;
1676
- retained[index] = 1;
1677
- targetBase.push(index);
1678
- }
1679
- }
1680
- const removeRuns = [];
1681
- for (let end = baseLength; end > 0;) {
1682
- if (retained[end - 1] !== 0) {
1683
- end -= 1;
1684
- continue;
1685
- }
1686
- let start = end - 1;
1687
- while (start > 0 && retained[start - 1] === 0) start -= 1;
1688
- removeRuns.push(start, end - start);
1689
- end = start;
1690
- }
1691
- const retainedBase = [];
1692
- for (let index = 0; index < retained.length; index++) if (retained[index] !== 0) retainedBase.push(index);
1693
- let permutation;
1694
- if (targetBase.some((value, index) => value !== retainedBase[index])) {
1695
- const positions = new Map(retainedBase.map((value, index) => [value, index]));
1696
- permutation = targetBase.map((value) => positions.get(value));
1697
- }
1698
- return {
1699
- removeRuns,
1700
- permutation,
1701
- insertRuns: insertRunsOf(pieces)
1702
- };
1703
- }
1704
- /** Runs of consecutive insert pieces as `logical index, first piece, end piece` triples. */
1705
- function insertRunsOf(pieces) {
1706
- const insertRuns = [];
1707
- let logicalIndex = 0;
1708
- for (let pieceIndex = 0; pieceIndex < pieces.length;) {
1709
- const piece = pieces[pieceIndex];
1710
- if (piece.kind === "base") {
1711
- logicalIndex += piece.length;
1712
- pieceIndex += 1;
1713
- continue;
1714
- }
1715
- const startPiece = pieceIndex;
1716
- while (pieceIndex < pieces.length && pieces[pieceIndex].kind === "insert") {
1717
- logicalIndex += pieces[pieceIndex].length;
1718
- pieceIndex += 1;
1719
- }
1720
- insertRuns.push(logicalIndex - rangeLength(pieces, startPiece, pieceIndex), startPiece, pieceIndex);
1721
- }
1722
- return insertRuns;
1723
- }
1724
- function rangeLength(pieces, start, end) {
1725
- let length = 0;
1726
- for (let index = start; index < end; index++) length += pieces[index].length;
1727
- return length;
1728
- }
1729
- function emitArrayOperations(node, path, operations, denseRegions) {
1730
- const overlay = arrayOverlay(node);
1731
- const base = nodeBase(node);
1732
- if (denseRegions !== void 0) for (const region of denseRegions) {
1733
- if (operations.length > MAX_DELTA_OPERATIONS) return;
1734
- operations.push([
1735
- "p",
1736
- path,
1737
- region.start,
1738
- region.length,
1739
- cloneArrayRegion(node, region)
1740
- ]);
1741
- }
1742
- if (overlay.structural) {
1743
- const plan = buildArrayPlan(node);
1744
- for (let index = 0; index < plan.removeRuns.length; index += 2) {
1745
- if (operations.length > MAX_DELTA_OPERATIONS) return;
1746
- operations.push([
1747
- "p",
1748
- path,
1749
- plan.removeRuns[index],
1750
- plan.removeRuns[index + 1],
1751
- []
1752
- ]);
1753
- }
1754
- if (plan.permutation !== void 0) operations.push([
1755
- "m",
1756
- path,
1757
- plan.permutation
1758
- ]);
1759
- const pieces = piecesOf(overlay);
1760
- for (let run = 0; run < plan.insertRuns.length; run += 3) {
1761
- if (operations.length > MAX_DELTA_OPERATIONS) return;
1762
- const logicalIndex = plan.insertRuns[run];
1763
- const items = [];
1764
- for (let pieceIndex = plan.insertRuns[run + 1]; pieceIndex < plan.insertRuns[run + 2]; pieceIndex++) {
1765
- const piece = pieces[pieceIndex];
1766
- for (let offset = 0; offset < piece.length; offset++) {
1767
- const sourceIndex = piece.start + piece.step * offset;
1768
- items.push(cloneStored(entryValueAt(node, piece, sourceIndex), node.context));
1769
- }
1770
- }
1771
- operations.push([
1772
- "p",
1773
- path,
1774
- logicalIndex,
1775
- 0,
1776
- items
1777
- ]);
1778
- }
1779
- }
1780
- for (const [baseIndex, valueIndex] of overlay.baseOverrides ?? []) {
1781
- if (operations.length > MAX_DELTA_OPERATIONS) return;
1782
- const index = findEntryIndex(overlay, 1, baseIndex, void 0);
1783
- if (index === void 0 || denseRegions !== void 0 && regionContaining(denseRegions, index)) continue;
1784
- emitChangedValue(operations, [...path, index], base[baseIndex], cloneStored(storedValue(node.context, valueIndex), node.context));
1785
- }
1786
- }
1787
- function cloneArrayRegion(node, region) {
1788
- const overlay = arrayOverlay(node);
1789
- const result = [];
1790
- for (let index = region.start; index < region.start + region.length; index++) {
1791
- const piece = locatePiece(overlay, index);
1792
- const sourceIndex = piece.start + piece.step * overlay.locatedOffset;
1793
- result.push(cloneStored(entryValueAt(node, piece, sourceIndex), node.context));
1794
- }
1795
- return result;
1796
- }
1797
- function emitChangedValue(operations, path, before, after) {
1798
- if (!isContainer(after) && before === after) return false;
1799
- if (isContainer(before) && isContainer(after) && equalTrustedJson(before, after)) return false;
1800
- if (typeof before === "string" && typeof after === "string") {
1801
- if (after.length > before.length && after.slice(0, before.length) === before) {
1802
- operations.push([
1803
- "a",
1804
- path,
1805
- ownedSlice(after, before.length)
1806
- ]);
1807
- return true;
1808
- }
1809
- const shared = overlap(before, after, 65536);
1810
- if (shared > 0) {
1811
- operations.push([
1812
- "t",
1813
- path,
1814
- before.length - shared
1815
- ]);
1816
- if (after.length > shared) operations.push([
1817
- "a",
1818
- path,
1819
- ownedSlice(after, shared)
1820
- ]);
1821
- return true;
1822
- }
1823
- }
1824
- operations.push([
1825
- "s",
1826
- path,
1827
- after
1828
- ]);
1829
- return true;
1830
- }
1831
- function emitSet(operations, path, value) {
1832
- if (path.length === 0) operations.push(["r", value]);
1833
- else operations.push([
1834
- "s",
1835
- path,
1836
- value
1837
- ]);
1838
- }
1839
- function resolvePath(node) {
1840
- if (node.preparedPath !== void 0) return node.preparedPath;
1841
- const parent = nodeParent(node);
1842
- if (parent === void 0) {
1843
- node.preparedPath = [];
1844
- return node.preparedPath;
1845
- }
1846
- const parentPath = resolvePath(parent);
1847
- if (parentPath === void 0) return void 0;
1848
- if (node.parentKind === 0) {
1849
- const key = node.parentKey;
1850
- if (!objectHas(parent, key) || objectValue(parent, key) !== nodeBase(node)) return void 0;
1851
- node.preparedPath = [...parentPath, key];
1852
- return node.preparedPath;
1853
- }
1854
- const overlay = arrayOverlay(parent);
1855
- const index = findEntryIndex(overlay, node.parentKind, node.parentKey, node.parentSource);
1856
- if (index === void 0) return void 0;
1857
- if (entryValueAt(parent, locatePiece(overlay, index), node.parentKey) !== nodeBase(node)) return void 0;
1858
- node.preparedPath = [...parentPath, index];
1859
- return node.preparedPath;
1860
- }
1861
- function ensurePieceLocations(overlay) {
1862
- if (overlay.baseLocations !== void 0) return;
1863
- overlay.baseLocations = [];
1864
- overlay.insertLocations = /* @__PURE__ */ new Map();
1865
- let logicalStart = 0;
1866
- for (const piece of piecesOf(overlay)) {
1867
- const last = piece.start + piece.step * (piece.length - 1);
1868
- const location = {
1869
- piece,
1870
- logicalStart,
1871
- minimum: Math.min(piece.start, last),
1872
- maximum: Math.max(piece.start, last)
1873
- };
1874
- if (piece.kind === "base") overlay.baseLocations.push(location);
1875
- else {
1876
- let locations = overlay.insertLocations.get(piece.source);
1877
- if (locations === void 0) {
1878
- locations = [];
1879
- overlay.insertLocations.set(piece.source, locations);
1880
- }
1881
- locations.push(location);
1882
- }
1883
- logicalStart += piece.length;
1884
- }
1885
- const byMinimum = (left, right) => left.minimum - right.minimum;
1886
- overlay.baseLocations.sort(byMinimum);
1887
- for (const locations of overlay.insertLocations.values()) locations.sort(byMinimum);
1888
- }
1889
- function findEntryIndex(overlay, kind, sourceIndex, source) {
1890
- if (kind === 1 && !overlay.structural) return sourceIndex;
1891
- ensurePieceLocations(overlay);
1892
- const locations = kind === 1 ? overlay.baseLocations : overlay.insertLocations.get(source);
1893
- if (locations === void 0) return void 0;
1894
- let low = 0;
1895
- let high = locations.length;
1896
- while (low < high) {
1897
- const middle = low + high >>> 1;
1898
- if (locations[middle].minimum <= sourceIndex) low = middle + 1;
1899
- else high = middle;
1900
- }
1901
- const location = locations[low - 1];
1902
- if (location === void 0 || sourceIndex > location.maximum) return void 0;
1903
- const offset = (sourceIndex - location.piece.start) / location.piece.step;
1904
- return offset >= 0 && offset < location.piece.length ? location.logicalStart + offset : void 0;
1905
- }
1906
- function ensureOperations(context) {
1907
- if (context.ops !== void 0) return context.ops;
1908
- assertReadable(context);
1909
- if (context.replacement) {
1910
- const base = context.tracker.deref()?.replacementBase(context);
1911
- context.replacementNoop = base !== void 0 && equalTrustedJson(base, nodeBase(context.root));
1912
- context.ops = context.replacementNoop ? [] : [["r", nodeBase(context.root)]];
1913
- } else context.ops = emitOperations(context);
1914
- return context.ops;
1915
- }
1916
- function equalTrustedJson(left, right) {
1917
- if (left === right) return true;
1918
- if (!isContainer(left) || !isContainer(right) || Array.isArray(left) !== Array.isArray(right)) return false;
1919
- if (Array.isArray(left)) {
1920
- const other = right;
1921
- if (left.length !== other.length) return false;
1922
- for (let index = 0; index < left.length; index++) if (!equalTrustedJson(left[index], other[index])) return false;
1923
- return true;
1924
- }
1925
- const other = right;
1926
- const keys = Object.keys(left);
1927
- if (keys.length !== Object.keys(other).length) return false;
1928
- for (const key of keys) if (!Object.hasOwn(other, key) || !equalTrustedJson(left[key], other[key])) return false;
1929
- return true;
1930
- }
1931
- function abortContext(context) {
1932
- if (context.status.value === "aborted" || context.status.value === "consumed" || context.status.value === "stale") return;
1933
- context.status.value = "aborted";
1934
- clearContext(context);
1935
- }
1936
- function releaseOverlayReferences(context) {
1937
- context.tracker.deref()?.releaseContext(context);
1938
- if (locatedDenseArray?.context === context) locatedDenseArray = void 0;
1939
- context.overlayReleased = true;
1940
- context.dirty.length = 0;
1941
- context.nodes.length = 0;
1942
- context.rawNodes = void 0;
1943
- context.ops = void 0;
1944
- context.root = void 0;
1945
- context.bases = void 0;
1946
- context.stored = void 0;
1947
- context.baseValue = void 0;
1948
- }
1949
- function clearContext(context) {
1950
- context.tracker.deref()?.releaseContext(context);
1951
- if (locatedDenseArray?.context === context) locatedDenseArray = void 0;
1952
- for (const node of context.nodes) {
1953
- if (Array.isArray(node.target)) node.target.length = 0;
1954
- Reflect.deleteProperty(node.target, NODE);
1955
- node.writes?.clear();
1956
- node.deletes?.clear();
1957
- node.readded?.clear();
1958
- if (node.array?.pieces !== void 0) node.array.pieces.length = 0;
1959
- if (node.array !== void 0) {
1960
- node.array.root = void 0;
1961
- node.array.baseLocations = void 0;
1962
- node.array.insertLocations = void 0;
1963
- }
1964
- node.array?.baseOverrides?.clear();
1965
- node.array?.insertOverrides?.clear();
1966
- node.parentSource = void 0;
1967
- node.target = RELEASED;
1968
- node.proxy = RELEASED;
1969
- node.writeKey = void 0;
1970
- node.writeValue = void 0;
1971
- node.writes = void 0;
1972
- node.deleteKey = void 0;
1973
- node.deletes = void 0;
1974
- node.readded = void 0;
1975
- node.array = void 0;
1976
- node.subtreeDirty = void 0;
1977
- node.preparedPath = void 0;
1978
- }
1979
- context.dirty.length = 0;
1980
- context.nodes.length = 0;
1981
- context.rawNodes = void 0;
1982
- context.ops = void 0;
1983
- context.root = void 0;
1984
- context.bases = void 0;
1985
- context.stored = void 0;
1986
- context.baseValue = void 0;
1987
- context.overlayReleased = true;
1988
- }
1989
- function isContainer(value) {
1990
- return value !== null && typeof value === "object";
1991
- }
1992
- const EMPTY = { kind: "empty" };
1993
- const REPLACE = { kind: "replace" };
1994
- const NO_OPS = {
1995
- kind: "ops",
1996
- ops: []
1997
- };
1998
- const REPLACE_TAKE = { kind: "replace" };
1999
- /**
2000
- * Pending ops of one state for one consumer, in order and raw (never encoded while they wait). `r` drops everything
2001
- * before it. A leaf op merges into the last pending leaf op on the same path (`a` + `a` joined, `s` replaces `s` or `a`,
2002
- * `a` after a string `s` appends into it); any other op clears the leaf index. Leaf ops on different paths commute,
2003
- * except after an ancestor primitive `s`, after which the descendant cannot be written until a structural op clears the
2004
- * index. Past `MAX_PENDING_OPS` only "replace with the current value" stays pending.
2005
- *
2006
- * Ops are only those of Delta's tracker, `diffRevisions()` and `appendText()`; received op arrays and tuples are never
2007
- * mutated (they feed other consumers too), a merge makes a new tuple.
2008
- */
2009
- var PendingOps = class {
2010
- #state = EMPTY;
2011
- /** Queue the ops of one commit. */
2012
- push(ops) {
2013
- if (ops.length === 0) return;
2014
- const state = this.#state;
2015
- if (ops[0][0] === "r") {
2016
- this.#state = {
2017
- kind: "batch",
2018
- ops
2019
- };
2020
- return;
2021
- }
2022
- switch (state.kind) {
2023
- case "empty":
2024
- this.#state = {
2025
- kind: "batch",
2026
- ops
2027
- };
2028
- return;
2029
- case "batch": {
2030
- const folding = {
2031
- kind: "folding",
2032
- ops: [],
2033
- leaves: /* @__PURE__ */ new Map()
2034
- };
2035
- this.#state = folding;
2036
- if (this.#fold(state.ops, folding)) this.#fold(ops, folding);
2037
- return;
2038
- }
2039
- case "folding":
2040
- this.#fold(ops, state);
2041
- return;
2042
- case "replace": return;
2043
- }
2044
- }
2045
- /**
2046
- * Pending ops after folding; 1 once overflowed (the replacement the owner sends). One batch is counted as received,
2047
- * so a single commit larger than `MAX_PENDING_OPS` counts in full until a second one arrives and overflows.
2048
- */
2049
- get size() {
2050
- const state = this.#state;
2051
- if (state.kind === "empty") return 0;
2052
- return state.kind === "replace" ? 1 : state.ops.length;
2053
- }
2054
- /** Hand over everything pending and start empty. */
2055
- take() {
2056
- const state = this.#state;
2057
- this.#state = EMPTY;
2058
- switch (state.kind) {
2059
- case "empty": return NO_OPS;
2060
- case "batch":
2061
- case "folding": return {
2062
- kind: "ops",
2063
- ops: state.ops
2064
- };
2065
- case "replace": return REPLACE_TAKE;
2066
- }
2067
- }
2068
- /** Fold `ops` into `folding`; false once the queue overflowed into `replace`. */
2069
- #fold(ops, folding) {
2070
- for (const op of ops) {
2071
- switch (op[0]) {
2072
- case "r":
2073
- folding.ops.length = 0;
2074
- folding.leaves.clear();
2075
- break;
2076
- case "a":
2077
- if (mergeLeaf(op, folding)) continue;
2078
- break;
2079
- case "s":
2080
- if (isPrimitive(op[2])) {
2081
- if (mergeLeaf(op, folding)) continue;
2082
- } else if (folding.leaves.size > 0) folding.leaves.clear();
2083
- break;
2084
- default: if (folding.leaves.size > 0) folding.leaves.clear();
2085
- }
2086
- folding.ops.push(op);
2087
- if (folding.ops.length > 1e4) {
2088
- this.#state = REPLACE;
2089
- return false;
2090
- }
2091
- }
2092
- return true;
2093
- }
2094
- };
2095
- const isPrimitive = (value) => value === null || typeof value !== "object";
2096
- /**
2097
- * Merge the leaf op `op` into the last pending leaf op on its path, or index it as that op at the position it is about
2098
- * to be pushed to. True when merged.
2099
- */
2100
- function mergeLeaf(op, folding) {
2101
- const key = pathKey$1(op[1]);
2102
- const at = folding.leaves.get(key);
2103
- if (at !== void 0) {
2104
- const merged = merge(folding.ops[at], op);
2105
- if (merged !== void 0) {
2106
- folding.ops[at] = merged;
2107
- return true;
2108
- }
2109
- }
2110
- folding.leaves.set(key, folding.ops.length);
2111
- return false;
2112
- }
2113
- /**
2114
- * The key of a path in the leaf index. Injective, as merging two distinct paths would lose a write: `["a.b"]` and
2115
- * `["a", "b"]` are different keys. A number and its string (`1`, `"1"`) may share one: within one index lifetime a
2116
- * parent is either an array or an object, as changing it is a structural op that clears the index.
2117
- */
2118
- function pathKey$1(path) {
2119
- return JSON.stringify(path);
2120
- }
2121
- /** `next` folded into `previous` (same path), or undefined when they do not fold. */
2122
- function merge(previous, next) {
2123
- if (next[0] === "s") return next;
2124
- if (previous[0] === "a") return [
2125
- "a",
2126
- previous[1],
2127
- previous[2] + next[2]
2128
- ];
2129
- if (typeof previous[2] === "string") return [
2130
- "s",
2131
- previous[1],
2132
- previous[2] + next[2]
2133
- ];
2134
- }
2135
- //#endregion
2136
- //#region ../../../node_modules/.pnpm/@earendil-works+chord@1.5.0_esbuild@0.28.2/node_modules/@earendil-works/chord/dist/delta/index.js
2137
- const isObj = (value) => value !== null && typeof value === "object";
2138
- /**
2139
- * Longest suffix of `a` that is a prefix of `b`. Probes with indexOf and verifies
2140
- * exact substring equality, so the hot loops are native. A hand-written KMP is
2141
- * asymptotically equivalent and much slower in practice.
2142
- *
2143
- * Always correct: the returned n satisfies a.slice(a.length - n) === b.slice(0, n).
2144
- */
2145
- function overlap(a, b, scan, probe = 64, maxCandidates = 8) {
2146
- if (a.length === 0 || b.length === 0 || scan === 0) return 0;
2147
- const tail = a.length > scan ? a.slice(a.length - scan) : a;
2148
- for (const h of [Math.min(probe, b.length), 1]) {
2149
- const head = b.slice(0, h);
2150
- let tried = 0;
2151
- for (let k = tail.indexOf(head); k !== -1; k = tail.indexOf(head, k + 1)) {
2152
- if (++tried > maxCandidates) break;
2153
- const n = tail.length - k;
2154
- if (n <= b.length && tail.slice(k) === b.slice(0, n)) return n;
2155
- }
2156
- if (h === 1) break;
2157
- }
2158
- return 0;
2159
- }
2160
- /**
2161
- * `text.slice(start, end)` as a string of its own. V8 represents a slice of 13 or more characters as a view that keeps
2162
- * all of `text` alive, so an append op cut from a long, growing string would retain that whole string for as long as
2163
- * the op lives: in a delta chain, a watch backlog, or a value built by applying the op. Appending a character and
2164
- * slicing it off again makes V8 copy just the slice.
2165
- */
2166
- function ownedSlice(text, start, end = text.length) {
2167
- return `${text.slice(start, end)} `.slice(0, -1);
2168
- }
2169
- /**
2170
- * Segments that reach the prototype chain.
2171
- *
2172
- * `JSON.parse` is safe on its own — it makes `__proto__` an own property. What is
2173
- * not safe is `parent[key] = value`, which is exactly what an applier does, and
2174
- * paths are data: `["s", ["__proto__", "isAdmin"], true]` pollutes
2175
- * `Object.prototype` for the whole process.
2176
- *
2177
- * Ops arrive from a facet, a plugin compartment, or a tool whose details may echo
2178
- * model output, so none of it is trusted input.
2179
- */
2180
- const RESERVED_SEGMENTS = /* @__PURE__ */ new Set([
2181
- "__proto__",
2182
- "constructor",
2183
- "prototype"
2184
- ]);
2185
- var UnsafePathError = class extends Error {
2186
- segment;
2187
- constructor(segment) {
2188
- super(`unsafe path segment: ${String(segment)}`);
2189
- this.segment = segment;
2190
- this.name = "UnsafePathError";
2191
- }
2192
- };
2193
- /**
2194
- * Verb, arity and payload shape for a **decoded** op: paths inline, no `#`, no
2195
- * short forms. `apply` uses this.
2196
- *
2197
- * Validating `Op` against the wire grammar would be laxer than the type: a
2198
- * two-element `["s", value]` would pass, and `apply` would then read the value as
2199
- * a path. Each vocabulary gets the validator that matches it.
2200
- */
2201
- function assertValidOp(op) {
2202
- if (!Array.isArray(op) || op.length === 0) throw new TypeError("op is not a tuple");
2203
- switch (op[0]) {
2204
- case "r":
2205
- if (op.length !== 2) throw new TypeError("r arity");
2206
- return;
2207
- case "s":
2208
- if (op.length !== 3) throw new TypeError("s arity");
2209
- assertPathArg(op[1], true);
2210
- return;
2211
- case "d":
2212
- if (op.length !== 2) throw new TypeError("d arity");
2213
- assertPathArg(op[1], true);
2214
- return;
2215
- case "a":
2216
- if (op.length !== 3 || typeof op[2] !== "string") throw new TypeError("a shape");
2217
- assertPathArg(op[1], true);
2218
- return;
2219
- case "t":
2220
- if (op.length !== 3 || !Number.isInteger(op[2]) || op[2] < 0) throw new TypeError("t shape");
2221
- assertPathArg(op[1], true);
2222
- return;
2223
- case "p":
2224
- if (op.length !== 5) throw new TypeError("p arity");
2225
- assertPathArg(op[1]);
2226
- if (!Number.isInteger(op[2]) || op[2] < 0) throw new TypeError("p index");
2227
- if (!Number.isInteger(op[3]) || op[3] < 0) throw new TypeError("p remove");
2228
- if (!Array.isArray(op[4])) throw new TypeError("p items");
2229
- return;
2230
- case "m":
2231
- if (op.length !== 3) throw new TypeError("m arity");
2232
- assertPathArg(op[1]);
2233
- assertPermutation(op[2]);
2234
- return;
2235
- default: throw new TypeError(`unknown op verb: ${String(op[0])}`);
2236
- }
2237
- }
2238
- function assertPathArg(p, nonEmpty = false) {
2239
- if (!Array.isArray(p)) throw new TypeError("path is not an array");
2240
- if (nonEmpty && p.length === 0) throw new TypeError("path is empty");
2241
- assertSafePath(p);
2242
- }
2243
- function assertPermutation(value) {
2244
- if (!Array.isArray(value)) throw new TypeError("m permutation is not an array");
2245
- const seen = new Uint8Array(value.length);
2246
- for (const index of value) {
2247
- if (!Number.isInteger(index) || index < 0 || index >= value.length || seen[index] !== 0) throw new TypeError("m permutation is not a bijection");
2248
- seen[index] = 1;
2249
- }
2250
- }
2251
- /** The same, for the wire grammar: ids and short forms are legal here. */
2252
- function assertValidWireOp(op) {
2253
- if (!Array.isArray(op) || op.length === 0) throw new TypeError("op is not a tuple");
2254
- const [verb] = op;
2255
- const okRef = (r) => {
2256
- if (typeof r === "number") {
2257
- if (!Number.isInteger(r) || r < 0) throw new TypeError("bad path id");
2258
- return;
2259
- }
2260
- if (!Array.isArray(r)) throw new TypeError("path is not an array");
2261
- assertSafePath(r);
2262
- };
2263
- switch (verb) {
2264
- case "r":
2265
- if (op.length !== 2) throw new TypeError("r arity");
2266
- return;
2267
- case "s":
2268
- if (op.length === 3) okRef(op[1]);
2269
- else if (op.length !== 2) throw new TypeError("s arity");
2270
- return;
2271
- case "d":
2272
- if (op.length === 2) okRef(op[1]);
2273
- else if (op.length !== 1) throw new TypeError("d arity");
2274
- return;
2275
- case "a":
2276
- if (op.length === 3) {
2277
- okRef(op[1]);
2278
- if (typeof op[2] !== "string") throw new TypeError("a value");
2279
- } else if (op.length === 2) {
2280
- if (typeof op[1] !== "string") throw new TypeError("a value");
2281
- } else throw new TypeError("a arity");
2282
- return;
2283
- case "t":
2284
- if (op.length === 3) {
2285
- okRef(op[1]);
2286
- if (!Number.isInteger(op[2]) || op[2] < 0) throw new TypeError("t count");
2287
- } else if (op.length === 2) {
2288
- if (!Number.isInteger(op[1]) || op[1] < 0) throw new TypeError("t count");
2289
- } else throw new TypeError("t arity");
2290
- return;
2291
- case "p": {
2292
- const [i, r, items] = op.length === 5 ? [
2293
- op[2],
2294
- op[3],
2295
- op[4]
2296
- ] : op.length === 4 ? [
2297
- op[1],
2298
- op[2],
2299
- op[3]
2300
- ] : [];
2301
- if (items === void 0) throw new TypeError("p arity");
2302
- if (op.length === 5) okRef(op[1]);
2303
- if (!Number.isInteger(i) || i < 0) throw new TypeError("p index");
2304
- if (!Number.isInteger(r) || r < 0) throw new TypeError("p remove");
2305
- if (!Array.isArray(items)) throw new TypeError("p items");
2306
- return;
2307
- }
2308
- case "m":
2309
- if (op.length === 3) okRef(op[1]);
2310
- else if (op.length !== 2) throw new TypeError("m arity");
2311
- assertPermutation(op[op.length - 1]);
2312
- return;
2313
- case "#":
2314
- if (op.length !== 3 || !Number.isInteger(op[1]) || op[1] < 0 || !Array.isArray(op[2])) throw new TypeError("# shape");
2315
- assertSafePath(op[2]);
2316
- return;
2317
- default: throw new TypeError(`unknown op verb: ${String(verb)}`);
2318
- }
2319
- }
2320
- function assertSafePath(path) {
2321
- for (const seg of path) if (typeof seg === "string") {
2322
- if (RESERVED_SEGMENTS.has(seg)) throw new UnsafePathError(seg);
2323
- } else if (!Number.isInteger(seg) || seg < 0) throw new UnsafePathError(seg);
2324
- }
2325
- /**
2326
- * An index may address an existing element or append exactly one past the end.
2327
- *
2328
- * This is not an arbitrary cap — it is what keeps the value a `JsonValue`. A
2329
- * sparse array does not survive a JSON round trip: holes serialise to `null` and
2330
- * return as real properties, so `arr[7] = x` on a length-3 array already produces
2331
- * state a replica cannot match. Rejecting the write is more honest than silently
2332
- * diverging.
2333
- *
2334
- * It also removes the denial of service it would otherwise permit:
2335
- * `["s", ["xs", 4294967290], 1]` allocates a 4.29-billion-entry array from one op.
2336
- * Growth stays possible and stays proportional — the tracker already emits
2337
- * `arr.length = n` as a splice of explicit nulls, whose op size grows with the
2338
- * gap, so a large growth costs a large op rather than a small one.
2339
- */
2340
- function assertIndexInRange(parent, index) {
2341
- if (index > parent.length) throw new UnsafePathError(index);
2342
- }
2343
- var PathError = class extends Error {
2344
- path;
2345
- constructor(path) {
2346
- super(`unresolvable path: ${JSON.stringify(path)}`);
2347
- this.path = path;
2348
- this.name = "PathError";
2349
- }
2350
- };
2351
- /**
2352
- * Apply ops to a plain mutable value. Returns the value, because `r` replaces it
2353
- * outright and cannot be done in place.
2354
- *
2355
- * Takes decoded ops. Path ids and omitted paths are a wire concern — run
2356
- * `decode` first if the ops came from a boundary.
2357
- */
2358
- function apply(target, ops) {
2359
- return applyOps(target, ops);
2360
- }
2361
- function applyOps(target, ops) {
2362
- let root = target;
2363
- for (const op of ops) {
2364
- assertValidOp(op);
2365
- if (op[0] === "r") {
2366
- root = op[1];
2367
- continue;
2368
- }
2369
- const path = op[1];
2370
- assertSafePath(path);
2371
- if (op[0] === "p") {
2372
- const target_ = path.length === 0 ? root : resolve(root, path);
2373
- if (!Array.isArray(target_)) throw new PathError(path);
2374
- target_.splice(op[2], op[3]);
2375
- const chunkSize = 1e4;
2376
- for (let offset = 0; offset < op[4].length; offset += chunkSize) target_.splice(op[2] + offset, 0, ...op[4].slice(offset, offset + chunkSize));
2377
- continue;
2378
- }
2379
- if (op[0] === "m") {
2380
- const target_ = path.length === 0 ? root : resolve(root, path);
2381
- if (!Array.isArray(target_) || target_.length !== op[2].length) throw new PathError(path);
2382
- const previous = target_.slice();
2383
- for (let index = 0; index < op[2].length; index++) target_[index] = previous[op[2][index]];
2384
- continue;
2385
- }
2386
- const parent = resolve(root, path.slice(0, -1));
2387
- const key = path[path.length - 1];
2388
- if (Array.isArray(parent)) {
2389
- if (typeof key !== "number") throw new UnsafePathError(key);
2390
- assertIndexInRange(parent, key);
2391
- }
2392
- const write = (value) => {
2393
- Object.defineProperty(parent, key, {
2394
- value,
2395
- writable: true,
2396
- enumerable: true,
2397
- configurable: true
2398
- });
2399
- };
2400
- const read = () => Object.hasOwn(parent, key) ? parent[key] : void 0;
2401
- switch (op[0]) {
2402
- case "s":
2403
- write(op[2]);
2404
- break;
2405
- case "d":
2406
- if (Array.isArray(parent)) {
2407
- if (typeof key !== "number" || key >= parent.length) throw new PathError(path);
2408
- parent.splice(key, 1);
2409
- } else delete parent[key];
2410
- break;
2411
- case "a": {
2412
- const current = read();
2413
- if (typeof current !== "string") throw new PathError(path);
2414
- write(`${current}${op[2]}`);
2415
- break;
2416
- }
2417
- case "t": {
2418
- const current = read();
2419
- if (typeof current !== "string") throw new PathError(path);
2420
- write(current.slice(op[2]));
2421
- break;
2422
- }
2423
- }
2424
- }
2425
- return root;
2426
- }
2427
- /** Apply one decoded operation batch without mutating the previous immutable value. */
2428
- function applyImmutable(target, ops) {
2429
- return applyImmutableBatches(target, [ops]);
2430
- }
2431
- /**
2432
- * Apply decoded operation batches as one final-result-only replay.
2433
- *
2434
- * Containers copied for an earlier batch may be mutated while applying a later
2435
- * batch, so this deliberately exposes no intermediate revisions.
2436
- */
2437
- function applyImmutableBatches(target, batches) {
2438
- let root = target;
2439
- const owned = /* @__PURE__ */ new WeakSet();
2440
- for (const ops of batches) for (const op of ops) {
2441
- assertValidOp(op);
2442
- if (op[0] === "r") {
2443
- root = op[1];
2444
- continue;
2445
- }
2446
- if (op[0] === "p") {
2447
- const appended = appendCopy(root, op, owned);
2448
- if (appended !== void 0) {
2449
- root = appended;
2450
- continue;
2451
- }
2452
- }
2453
- root = copyContainers(root, op[0] === "p" || op[0] === "m" ? op[1] : op[1].slice(0, -1), owned);
2454
- root = applyOps(root, [op]);
2455
- }
2456
- return root;
2457
- }
2458
- /**
2459
- * An append to an array not yet copied in this replay, built as one copy with the items (`concat`) instead of a copy that
2460
- * the insert then grows, which copies it again. `undefined` for any other splice and for any path that is not a plain
2461
- * walk over own properties, which takes the general path and so fails with its errors.
2462
- */
2463
- function appendCopy(root, op, owned) {
2464
- const [, path, index, deleteCount, items] = op;
2465
- if (deleteCount !== 0) return void 0;
2466
- let target = root;
2467
- for (const segment of path) {
2468
- if (!(typeof segment === "string" ? !RESERVED_SEGMENTS.has(segment) && isObj(target) && !Array.isArray(target) : Number.isInteger(segment) && segment >= 0 && Array.isArray(target)) || !Object.hasOwn(target, segment)) return void 0;
2469
- target = target[segment];
2470
- }
2471
- if (!Array.isArray(target) || owned.has(target) || index !== target.length) return void 0;
2472
- const appended = target.concat(items);
2473
- owned.add(appended);
2474
- if (path.length === 0) return appended;
2475
- const parentPath = path.slice(0, -1);
2476
- const copiedRoot = copyContainers(root, parentPath, owned);
2477
- Object.defineProperty(resolve(copiedRoot, parentPath), path[path.length - 1], {
2478
- value: appended,
2479
- writable: true,
2480
- enumerable: true,
2481
- configurable: true
2482
- });
2483
- return copiedRoot;
2484
- }
2485
- function copyContainers(root, path, owned) {
2486
- const copy = (value) => {
2487
- if (Array.isArray(value)) return value.slice();
2488
- if (!isObj(value)) throw new PathError(path);
2489
- return Object.getPrototypeOf(value) === null ? Object.assign(Object.create(null), value) : { ...value };
2490
- };
2491
- if (!isObj(root)) throw new PathError(path);
2492
- let copiedRoot;
2493
- if (owned.has(root)) copiedRoot = root;
2494
- else {
2495
- copiedRoot = copy(root);
2496
- owned.add(copiedRoot);
2497
- }
2498
- let destination = copiedRoot;
2499
- for (const segment of path) {
2500
- if (!Object.hasOwn(destination, segment)) throw new PathError(path);
2501
- if (Array.isArray(destination) && typeof segment !== "number") throw new UnsafePathError(segment);
2502
- const child = destination[segment];
2503
- if (!isObj(child)) throw new PathError(path);
2504
- if (owned.has(child)) {
2505
- destination = child;
2506
- continue;
2507
- }
2508
- const copiedChild = copy(child);
2509
- Object.defineProperty(destination, segment, {
2510
- value: copiedChild,
2511
- writable: true,
2512
- enumerable: true,
2513
- configurable: true
2514
- });
2515
- owned.add(copiedChild);
2516
- destination = copiedChild;
2517
- }
2518
- return copiedRoot;
2519
- }
2520
- function resolveValue(root, path) {
2521
- let node = root;
2522
- for (const seg of path) {
2523
- if (!isObj(node)) throw new PathError(path);
2524
- if (Array.isArray(node) && typeof seg !== "number") throw new UnsafePathError(seg);
2525
- if (!Object.hasOwn(node, seg)) throw new PathError(path);
2526
- node = node[seg];
2527
- }
2528
- return node;
2529
- }
2530
- function resolve(root, path) {
2531
- const node = resolveValue(root, path);
2532
- if (!isObj(node)) throw new PathError(path);
2533
- return node;
2534
- }
2535
- const pathKey = (path) => JSON.stringify(path);
2536
- /**
2537
- * Intern on SECOND use. A definition costs more than the path it replaces, so
2538
- * interning on first use loses on the many paths written exactly once.
2539
- */
2540
- function encoder() {
2541
- const seen = /* @__PURE__ */ new Set();
2542
- const ids = /* @__PURE__ */ new Map();
2543
- let nextId = 0;
2544
- let previous;
2545
- return { encode(ops) {
2546
- previous = void 0;
2547
- const out = [];
2548
- for (const op of ops) {
2549
- if (op[0] === "r") {
2550
- out.push(op);
2551
- seen.clear();
2552
- ids.clear();
2553
- nextId = 0;
2554
- previous = void 0;
2555
- continue;
2556
- }
2557
- const path = op[1];
2558
- const key = pathKey(path);
2559
- if (key === previous) {
2560
- switch (op[0]) {
2561
- case "s":
2562
- out.push(["s", op[2]]);
2563
- break;
2564
- case "d":
2565
- out.push(["d"]);
2566
- break;
2567
- case "a":
2568
- out.push(["a", op[2]]);
2569
- break;
2570
- case "t":
2571
- out.push(["t", op[2]]);
2572
- break;
2573
- case "p":
2574
- out.push([
2575
- "p",
2576
- op[2],
2577
- op[3],
2578
- op[4]
2579
- ]);
2580
- break;
2581
- case "m": out.push(["m", op[2]]);
2582
- }
2583
- continue;
2584
- }
2585
- let ref = path;
2586
- const existing = ids.get(key);
2587
- if (existing !== void 0) ref = existing;
2588
- else if (seen.has(key)) {
2589
- const id = nextId++;
2590
- ids.set(key, id);
2591
- out.push([
2592
- "#",
2593
- id,
2594
- path
2595
- ]);
2596
- ref = id;
2597
- } else seen.add(key);
2598
- switch (op[0]) {
2599
- case "s":
2600
- out.push([
2601
- "s",
2602
- ref,
2603
- op[2]
2604
- ]);
2605
- break;
2606
- case "d":
2607
- out.push(["d", ref]);
2608
- break;
2609
- case "a":
2610
- out.push([
2611
- "a",
2612
- ref,
2613
- op[2]
2614
- ]);
2615
- break;
2616
- case "t":
2617
- out.push([
2618
- "t",
2619
- ref,
2620
- op[2]
2621
- ]);
2622
- break;
2623
- case "p":
2624
- out.push([
2625
- "p",
2626
- ref,
2627
- op[2],
2628
- op[3],
2629
- op[4]
2630
- ]);
2631
- break;
2632
- case "m": out.push([
2633
- "m",
2634
- ref,
2635
- op[2]
2636
- ]);
2637
- }
2638
- previous = key;
2639
- }
2640
- return out;
2641
- } };
2642
- }
2643
- function decoder() {
2644
- const paths = /* @__PURE__ */ new Map();
2645
- return { decode(wire) {
2646
- let previous;
2647
- const out = [];
2648
- for (const op of wire) {
2649
- assertValidWireOp(op);
2650
- if (op[0] === "#") {
2651
- assertSafePath(op[2]);
2652
- paths.set(op[1], op[2]);
2653
- continue;
2654
- }
2655
- if (op[0] === "r") {
2656
- out.push(op);
2657
- paths.clear();
2658
- previous = void 0;
2659
- continue;
2660
- }
2661
- const short = op[0] === "d" && op.length === 1 || op[0] !== "d" && op[0] !== "p" && op.length === 2 || op[0] === "p" && op.length === 4;
2662
- let path;
2663
- if (short) {
2664
- if (previous === void 0) throw new PathError([]);
2665
- path = previous;
2666
- } else {
2667
- const ref = op[1];
2668
- if (typeof ref === "number") {
2669
- const resolved = paths.get(ref);
2670
- if (resolved === void 0) throw new PathError(ref);
2671
- path = resolved;
2672
- } else path = ref;
2673
- previous = path;
2674
- }
2675
- if (op[0] !== "p" && op[0] !== "m" && path.length === 0) throw new PathError(path);
2676
- switch (op[0]) {
2677
- case "s":
2678
- out.push([
2679
- "s",
2680
- path,
2681
- short ? op[1] : op[2]
2682
- ]);
2683
- break;
2684
- case "d":
2685
- out.push(["d", path]);
2686
- break;
2687
- case "a":
2688
- out.push([
2689
- "a",
2690
- path,
2691
- short ? op[1] : op[2]
2692
- ]);
2693
- break;
2694
- case "t":
2695
- out.push([
2696
- "t",
2697
- path,
2698
- short ? op[1] : op[2]
2699
- ]);
2700
- break;
2701
- case "p": {
2702
- const [i, r, items] = short ? [
2703
- op[1],
2704
- op[2],
2705
- op[3]
2706
- ] : [
2707
- op[2],
2708
- op[3],
2709
- op[4]
2710
- ];
2711
- out.push([
2712
- "p",
2713
- path,
2714
- i,
2715
- r,
2716
- items
2717
- ]);
2718
- break;
2719
- }
2720
- case "m": out.push([
2721
- "m",
2722
- path,
2723
- short ? op[1] : op[2]
2724
- ]);
2725
- }
2726
- }
2727
- return out;
2728
- } };
2729
- }
2730
- //#endregion
2731
- //#region ../../../node_modules/.pnpm/@earendil-works+chord@1.5.0_esbuild@0.28.2/node_modules/@earendil-works/chord/dist/watch.js
2732
- const STOPPED = { kind: "stopped" };
2733
- const ABORTED = { kind: "aborted" };
2734
- const ENDED$1 = { kind: "ended" };
2735
- /**
2736
- * The lifecycle both handles share: serialized delivery and termination. A source feeds it and ends it explicitly;
2737
- * termination drops every reference the watch holds into its source, so a stopped watch that is still referenced keeps
2738
- * nothing but its last value alive. Subclasses keep what is pending, each call apart from its frame's context, so the
2739
- * call a listener gets carries nothing but its data.
2740
- */
2741
- var WatchLifecycle = class {
2742
- #detach;
2743
- #report;
2744
- #closed = Promise.withResolvers();
2745
- #value;
2746
- #listener;
2747
- #started = false;
2748
- #scheduled = false;
2749
- #running = false;
2750
- /** Set by `endAfterDelivery()`: the source sends nothing more; the watch ends `ended` once it delivered the rest. */
2751
- #ending = false;
2752
- /** Set once, by `#terminate()`. */
2753
- #end;
2754
- #abortSignal;
2755
- #abortListener;
2756
- constructor(value, detach, report) {
2757
- this.#value = value;
2758
- this.#detach = detach;
2759
- this.#report = report;
2760
- }
2761
- get value() {
2762
- return this.#value;
2763
- }
2764
- get closed() {
2765
- return this.#closed.promise;
2766
- }
2767
- start(listener) {
2768
- if (this.#started) throw new Error("Watch is already started");
2769
- if (this.#end !== void 0) throw new Error("Watch is stopped");
2770
- this.#started = true;
2771
- this.#listener = listener;
2772
- this.#schedule();
2773
- }
2774
- stop() {
2775
- this.#terminate(STOPPED);
2776
- return this.#closed.promise;
2777
- }
2778
- /** End the watch `aborted` when `signal` aborts; installed once. */
2779
- observeAbort(signal) {
2780
- if (this.#abortSignal !== void 0) throw new Error("Watch abort is already installed");
2781
- if (this.#end !== void 0) return;
2782
- this.#abortSignal = signal;
2783
- this.#abortListener = () => this.abort();
2784
- signal.addEventListener("abort", this.#abortListener, { once: true });
2785
- if (signal.aborted) this.abort();
2786
- }
2787
- /** End the watch `aborted`: its acquisition context was aborted. */
2788
- abort() {
2789
- this.#terminate(ABORTED);
2790
- }
2791
- /**
2792
- * End the watch with `end` at once, dropping what is pending: the source closed (`ended`), or failed for good
2793
- * (`failed`). A failure the source may recover from is a `failed` call instead (`fail()`).
2794
- */
2795
- end(end) {
2796
- this.#terminate(end);
2797
- }
2798
- /**
2799
- * The source sends nothing more after its last frames, such as a retirement: take no more frames, deliver what is
2800
- * pending, then end `ended`, after the running call returns, if one runs. Until then the watch stays attached, so
2801
- * `end()`, `stop()`, an abort, and a throwing listener still end it first; a watch never started keeps what is
2802
- * pending until one of them or `start()`.
2803
- */
2804
- endAfterDelivery() {
2805
- if (this.#end !== void 0 || this.#ending) return;
2806
- this.#ending = true;
2807
- if (!this.#running && this.pendingContext === void 0) this.#terminate(ENDED$1);
2808
- }
2809
- /** Whether the watch still takes frames: it has not ended, and its source has not ended. */
2810
- get open() {
2811
- return this.#end === void 0 && !this.#ending;
2812
- }
2813
- /** Something became pending: deliver it once started, never inline. */
2814
- pending() {
2815
- if (this.#started) this.#schedule();
2816
- }
2817
- #schedule() {
2818
- if (this.#scheduled || this.#running || this.#end !== void 0) return;
2819
- this.#scheduled = true;
2820
- queueMicrotask(() => {
2821
- this.#scheduled = false;
2822
- this.#drain();
2823
- });
2824
- }
2825
- /**
2826
- * Deliver until nothing is pending; what arrives during a call is taken after it returns. A watch whose source ended
2827
- * ends once it delivered the rest and its last call returned.
2828
- */
2829
- async #drain() {
2830
- if (this.#running || this.#end !== void 0 || !this.#started) return;
2831
- this.#running = true;
2832
- try {
2833
- while (this.#end === void 0) {
2834
- const listener = this.#listener;
2835
- if (listener === void 0) break;
2836
- const frameContext = this.pendingContext;
2837
- if (frameContext === void 0) {
2838
- if (this.#ending) this.#terminate(ENDED$1);
2839
- break;
2840
- }
2841
- const call = this.next();
2842
- if (call.kind === "value") this.#value = call.value;
2843
- try {
2844
- await listener(call, withoutAbortSignal(frameContext));
2845
- } catch (error) {
2846
- if (this.#end === void 0) {
2847
- this.#report?.(error);
2848
- this.#terminate({
2849
- kind: "listener_error",
2850
- error: toError$1(error)
2851
- });
2852
- }
2853
- break;
2854
- }
2855
- }
2856
- } finally {
2857
- this.#running = false;
2858
- }
2859
- }
2860
- /**
2861
- * End the watch, once: detach, drop what is pending and every reference into the source, and settle `closed`. A
2862
- * callback already running keeps running.
2863
- */
2864
- #terminate(end) {
2865
- if (this.#end !== void 0) return;
2866
- this.#end = end;
2867
- const detach = this.#detach;
2868
- this.#detach = void 0;
2869
- this.#report = void 0;
2870
- this.#listener = void 0;
2871
- this.release();
2872
- if (this.#abortListener !== void 0) this.#abortSignal?.removeEventListener("abort", this.#abortListener);
2873
- this.#abortSignal = void 0;
2874
- this.#abortListener = void 0;
2875
- detach?.();
2876
- this.#closed.resolve(end);
2877
- }
2878
- };
2879
- function toError$1(error) {
2880
- if (error instanceof Error) return error;
2881
- try {
2882
- return new Error(String(error));
2883
- } catch {
2884
- return new Error(Object.prototype.toString.call(error));
2885
- }
2886
- }
2887
- /**
2888
- * The watch handle of a JSON source. Frames that arrive before `start()` or while the listener runs wait in one
2889
- * `PendingOps` queue; the next call gets the newest value, the folded ops of every frame since the previous call (or
2890
- * `[["r", newest]]` after the queue overflowed), `retired` when any of them was a retirement, and the newest frame's
2891
- * context. A frame delivered alone is passed on as the source made it. A failure (`fail()`) drops the pending frames and
2892
- * waits as one `failed` call; a value after it replaces it, and the first value call after a failure is `[["r",
2893
- * value]]`. `detach` unsubscribes it from its source on termination; `report` gets a listener's throw, which also ends
2894
- * the watch.
2895
- */
2896
- var Watch = class extends WatchLifecycle {
2897
- #ops = new PendingOps();
2898
- /**
2899
- * The source's call while it is the only frame pending: the call passes it on, with no allocation. A second frame
2900
- * drops it, so its ops stay only as long as `PendingOps` keeps them (folded, or dropped by an overflow).
2901
- */
2902
- #lone;
2903
- /** The newest frame's value and context, while a call is pending; the context also marks that one is. */
2904
- #newestValue;
2905
- #newestContext;
2906
- /** A pending frame was a retirement. */
2907
- #retired = false;
2908
- /** The newest frame was a failure: the next call is this. */
2909
- #failure;
2910
- /** A failure came after the last value call: the next value call replaces the root, and ops are not kept. */
2911
- #replace = false;
2912
- /**
2913
- * Queue the frame `call`. A value's ops turn the previous value into it, and `retired` says the document the watch
2914
- * follows was retired, which the next value call reports however many frames it folds; a failure is `fail()`.
2915
- */
2916
- advance(call, context) {
2917
- if (call.kind === "failed") {
2918
- this.#fail(call, context);
2919
- return;
2920
- }
2921
- if (!this.open) return;
2922
- if (this.#replace) this.#failure = void 0;
2923
- else {
2924
- this.#lone = this.#newestContext === void 0 ? call : void 0;
2925
- this.#ops.push(call.ops);
2926
- }
2927
- this.#newestValue = call.value;
2928
- this.#newestContext = context;
2929
- if (call.retired) this.#retired = true;
2930
- this.pending();
2931
- }
2932
- /**
2933
- * Queue a failure the source may recover from: the pending frames are dropped (`value` keeps the last delivered
2934
- * value), the listener gets `{ kind: "failed", error }`, and the next value arrives as `[["r", value]]`.
2935
- */
2936
- fail(error, context) {
2937
- this.#fail({
2938
- kind: "failed",
2939
- error
2940
- }, context);
2941
- }
2942
- #fail(call, context) {
2943
- if (!this.open) return;
2944
- this.#ops.take();
2945
- this.#lone = void 0;
2946
- this.#newestValue = void 0;
2947
- this.#failure = call;
2948
- this.#newestContext = context;
2949
- this.#replace = true;
2950
- this.pending();
2951
- }
2952
- get pendingContext() {
2953
- return this.#newestContext;
2954
- }
2955
- next() {
2956
- if (this.#replace) return this.#nextAfterFailure();
2957
- const lone = this.#lone;
2958
- const value = this.#newestValue;
2959
- const batch = this.#ops.take();
2960
- const retired = this.#retired;
2961
- this.#lone = void 0;
2962
- this.#newestValue = void 0;
2963
- this.#newestContext = void 0;
2964
- this.#retired = false;
2965
- if (lone !== void 0) return lone;
2966
- return {
2967
- kind: "value",
2968
- value,
2969
- ops: batch.kind === "ops" ? batch.ops : [["r", value]],
2970
- retired
2971
- };
2972
- }
2973
- /** The pending failure, or the value after one as a root replacement (no ops were kept since the failure). */
2974
- #nextAfterFailure() {
2975
- const failure = this.#failure;
2976
- this.#newestContext = void 0;
2977
- if (failure !== void 0) {
2978
- this.#failure = void 0;
2979
- return failure;
2980
- }
2981
- const value = this.#newestValue;
2982
- const retired = this.#retired;
2983
- this.#newestValue = void 0;
2984
- this.#retired = false;
2985
- this.#replace = false;
2986
- return {
2987
- kind: "value",
2988
- value,
2989
- ops: [["r", value]],
2990
- retired
2991
- };
2992
- }
2993
- release() {
2994
- this.#ops.take();
2995
- this.#lone = void 0;
2996
- this.#newestValue = void 0;
2997
- this.#newestContext = void 0;
2998
- this.#retired = false;
2999
- this.#failure = void 0;
3000
- this.#replace = false;
3001
- }
3002
- };
3003
- //#endregion
3004
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/errors.js
1
+ import { At as documentCreate, Dt as checkRecordVersion, Et as checkRecordScope, It as copyJson, Lt as BACKGROUND_CONTEXT, Mt as materializeDocumentValue, Nt as resolveAddress, Ot as defineDoc, Pt as idFromNumber, Rt as awaitWithContext, St as PendingOps, Tt as addressId, Vt as withoutAbortSignal, _t as Watch, jt as materializeDocument, wt as track } from "./serverPlugin-DcSYreIB.js";
2
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/errors.js
3005
3
  /**
3006
4
  * The message of a thrown value, without throwing itself: `String()` throws for values such as `Object.create(null)`,
3007
5
  * and code that formats an error must not fail for the value it formats.
@@ -3076,7 +74,7 @@ var ConversationIdle = class extends Error {
3076
74
  }
3077
75
  };
3078
76
  //#endregion
3079
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/timers.js
77
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/timers.js
3080
78
  /** Longest delay `setTimeout` supports; a longer one is waited for in several steps. */
3081
79
  const MAX_TIMER_DELAY = 2147483647;
3082
80
  /**
@@ -3141,7 +139,7 @@ function hostTimers(setTimer, report) {
3141
139
  };
3142
140
  }
3143
141
  //#endregion
3144
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/cached-storage.js
142
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/cached-storage.js
3145
143
  /**
3146
144
  * Storage that serves hot record reads from memory: conversations, tasks, and written submissions, each table bounded
3147
145
  * by a count, the least recently used record leaving first, except live tasks, which are kept until they end, and the
@@ -3396,7 +394,7 @@ function freeze$1(value) {
3396
394
  return Object.freeze(value);
3397
395
  }
3398
396
  //#endregion
3399
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/conversation-tails.js
397
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/conversation-tails.js
3400
398
  /** Conversations whose newest entry ID is kept: IDs only, so many. */
3401
399
  const LATEST_CAPACITY = 4096;
3402
400
  /** Conversations whose newest head marker is kept: whole entries (a compaction summary is one), so fewer. */
@@ -3481,7 +479,7 @@ function freeze(value) {
3481
479
  return Object.freeze(value);
3482
480
  }
3483
481
  //#endregion
3484
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/keys.js
482
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/keys.js
3485
483
  /** A task record. */
3486
484
  function taskKey(id) {
3487
485
  return `task:${id}`;
@@ -3631,7 +629,7 @@ var GatedStorage = class {
3631
629
  }
3632
630
  };
3633
631
  //#endregion
3634
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/forks.js
632
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/forks.js
3635
633
  const SCAN_PAGE_SIZE = 256;
3636
634
  /** Select every persisted conversation document copied by one fork. */
3637
635
  async function prepareForkDocumentCopies(storage, parentConversationId, at, childConversationId, context) {
@@ -3694,7 +692,7 @@ async function collectCopies(storage, scope, at, policy, childConversationId, co
3694
692
  } while (cursor !== void 0);
3695
693
  }
3696
694
  //#endregion
3697
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/transaction.js
695
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/transaction.js
3698
696
  /**
3699
697
  * Complete record after applying one change. Placement turns a queued input `placed` and a queued write `done`; a
3700
698
  * continue is never queued, so never placed. Only a placed input or continue can be answered. A settled record stays.
@@ -3798,7 +796,7 @@ var Transaction = class {
3798
796
  scanTasks(query, limit, cursor) {
3799
797
  return this.#read("scanTasks", () => this.#host.storage.scanTasks(query, limit, cursor, this.#context));
3800
798
  }
3801
- /** Internal: committed submission record. */
799
+ /** Committed submission record. */
3802
800
  submission(id) {
3803
801
  return this.#read("submission", () => this.#host.storage.submission(id, this.#context));
3804
802
  }
@@ -4121,7 +1119,8 @@ var Transaction = class {
4121
1119
  this.#assertOpen();
4122
1120
  if (stored === void 0) throw new Error(`Fork source document ${target.source.id} cannot be read`);
4123
1121
  if (stored.record.scope.kind !== "conversation" || stored.record.kind !== target.record.kind || stored.record.key !== target.record.key || stored.record.history !== target.record.history || stored.record.fork !== target.record.fork) throw new Error(`Fork source document ${target.source.id} does not match the copied record`);
4124
- const tracker = track(materializeDocumentValue(definition, target.record, stored.version, stored.value));
1122
+ const value = materializeDocumentValue(definition, target.record, stored.version, stored.value);
1123
+ const tracker = track(value);
4125
1124
  entry.definition = definition;
4126
1125
  entry.target = {
4127
1126
  kind: "created",
@@ -4711,7 +1710,7 @@ function publishes(plan) {
4711
1710
  return plan.retire || plan.change?.loaded === void 0 || plan.content !== void 0;
4712
1711
  }
4713
1712
  //#endregion
4714
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/writer.js
1713
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/writer.js
4715
1714
  const SESSION_FAILED = { kind: "failed" };
4716
1715
  /**
4717
1716
  * The writer of one Session. The line admits each commit as a part once its callback and settlement succeeded; the
@@ -5003,7 +2002,7 @@ function hop() {
5003
2002
  });
5004
2003
  }
5005
2004
  //#endregion
5006
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/session/session.js
2005
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/session/session.js
5007
2006
  const NO_HOLDS = [];
5008
2007
  const NO_OPERATIONS = [];
5009
2008
  const NO_KEYS = [];
@@ -6584,7 +3583,7 @@ var GuardedStorage = class {
6584
3583
  }
6585
3584
  };
6586
3585
  //#endregion
6587
- //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/harness/agent.js
3586
+ //#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.1_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbcc2176e814d0240ad6e785e8fba51c/node_modules/@earendil-works/pi-durable/dist/harness/agent.js
6588
3587
  const DEFAULT_RETRY_POLICY = {
6589
3588
  enabled: true,
6590
3589
  maxRetries: 3,
@@ -6703,6 +3702,34 @@ function applyChange(state, change) {
6703
3702
  const maxTurns = change.maxTurns;
6704
3703
  if (maxTurns !== void 0 && maxTurns !== null && !(Number.isSafeInteger(maxTurns) && maxTurns >= 1)) throw new RangeError(`maxTurns must be an integer 1 or more, got ${String(maxTurns)}`);
6705
3704
  set("maxTurns", maxTurns);
3705
+ const compaction = change.compaction;
3706
+ set("compaction", compaction === void 0 || compaction === null ? compaction : compactionSettings(compaction));
3707
+ }
3708
+ /** A stored copy of a conversation's compaction settings, without undefined fields. */
3709
+ function compactionSettings(settings) {
3710
+ const { modelOverrides, ...policy } = settings;
3711
+ if (modelOverrides === void 0) return compactionFields(policy);
3712
+ const overrides = Object.entries(modelOverrides).map(([key, override]) => [key, compactionFields(override)]);
3713
+ return {
3714
+ ...compactionFields(policy),
3715
+ modelOverrides: Object.fromEntries(overrides)
3716
+ };
3717
+ }
3718
+ const TOKEN_FIELDS = [
3719
+ "reserveTokens",
3720
+ "keepRecentTokens",
3721
+ "backgroundTokens"
3722
+ ];
3723
+ /** The set fields of `policy`; throws a `RangeError` for a token count that is not an integer `0` or more. */
3724
+ function compactionFields(policy) {
3725
+ const fields = policy.enabled === void 0 ? {} : { enabled: policy.enabled };
3726
+ for (const key of TOKEN_FIELDS) {
3727
+ const value = policy[key];
3728
+ if (value === void 0) continue;
3729
+ if (!(Number.isSafeInteger(value) && value >= 0)) throw new RangeError(`compaction.${key} must be an integer 0 or more, got ${String(value)}`);
3730
+ fields[key] = value;
3731
+ }
3732
+ return fields;
6706
3733
  }
6707
3734
  function isList(value) {
6708
3735
  return Array.isArray(value);
@@ -6789,7 +3816,8 @@ function resolveAgent(state, snapshot, settings, report) {
6789
3816
  sections: agentSections,
6790
3817
  ...instructions === void 0 ? {} : { instructions },
6791
3818
  ...state?.cwd === void 0 ? {} : { cwd: state.cwd },
6792
- ...state?.maxTurns === void 0 ? {} : { maxTurns: state.maxTurns }
3819
+ ...state?.maxTurns === void 0 ? {} : { maxTurns: state.maxTurns },
3820
+ ...state?.compaction === void 0 ? {} : { compaction: state.compaction }
6793
3821
  };
6794
3822
  }
6795
3823
  /** The tools offered to the model, as `AgentState.modelTools` describes. */
@@ -6847,4 +3875,4 @@ function applyWrap(items, target, wrap, nameOf, report) {
6847
3875
  }
6848
3876
  }
6849
3877
  //#endregion
6850
- export { StorageRequestError as A, appendText as B, taskKey as C, ReadAfterWrite as D, ConversationIdle as E, applyImmutable as F, decoder as I, encoder as L, Watch as M, RESERVED_SEGMENTS as N, ReadOnlySession as O, apply as P, overlap as R, ownedKey as S, ConversationBusy as T, track as V, guardObserver as _, agentHooks as a, ROOTS_KEY as b, resolveAgent as c, toolExtension as d, SessionImpl as f, createSession as g, contained as h, addTools as i, errorMessage as j, SessionFailed as k, resolveSettings as l, closeEnds as m, DEFAULT_COMPACTION_POLICY as n, configure as o, closeEndOf as p, INSTRUCTIONS_KEY as r, createAgent as s, AgentDoc as t, sectionExtension as u, observation as v, hostTimers as w, conversationKey as x, INTENT_KEY as y, ownedSlice as z };
3878
+ export { StorageRequestError as A, taskKey as C, ReadAfterWrite as D, ConversationIdle as E, ReadOnlySession as O, ownedKey as S, ConversationBusy as T, guardObserver as _, agentHooks as a, ROOTS_KEY as b, resolveAgent as c, toolExtension as d, SessionImpl as f, createSession as g, contained as h, addTools as i, errorMessage as j, SessionFailed as k, resolveSettings as l, closeEnds as m, DEFAULT_COMPACTION_POLICY as n, configure as o, closeEndOf as p, INSTRUCTIONS_KEY as r, createAgent as s, AgentDoc as t, sectionExtension as u, observation as v, hostTimers as w, conversationKey as x, INTENT_KEY as y };