@lostgradient/weft 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +47 -22
  2. package/dist/cli/generated/operation-client.generated.d.ts +28 -1
  3. package/dist/cli/generated/operation-client.generated.js +2 -0
  4. package/dist/cli-main.js +79 -79
  5. package/dist/client/handle-delegation.d.ts +4 -0
  6. package/dist/client/handle-delegation.js +6 -0
  7. package/dist/client/http-client-requests.d.ts +2 -0
  8. package/dist/client/http-client-requests.js +3 -0
  9. package/dist/client/http-client.d.ts +4 -1
  10. package/dist/client/http-client.js +9 -1
  11. package/dist/client/interface.d.ts +57 -2
  12. package/dist/client/local.d.ts +4 -1
  13. package/dist/client/local.js +7 -0
  14. package/dist/client/start-body.d.ts +7 -1
  15. package/dist/client/start-body.js +13 -4
  16. package/dist/core/codec/extension-codec.js +4 -2
  17. package/dist/core/codec/index.d.ts +1 -0
  18. package/dist/core/codec/index.js +1 -0
  19. package/dist/core/codec/serializer-registry.d.ts +122 -0
  20. package/dist/core/codec/serializer-registry.js +51 -0
  21. package/dist/core/context/index.d.ts +10 -0
  22. package/dist/core/context/index.js +3 -0
  23. package/dist/core/context/internals.d.ts +10 -0
  24. package/dist/core/context/internals.js +5 -1
  25. package/dist/core/context/run-operation.d.ts +16 -3
  26. package/dist/core/context/run-operation.js +16 -7
  27. package/dist/core/context/speculative-child.js +2 -0
  28. package/dist/core/context/types.d.ts +6 -0
  29. package/dist/core/engine/bulk-operations-purge.js +1 -0
  30. package/dist/core/engine/bulk-operations.js +1 -1
  31. package/dist/core/engine/callback-creators-bundles.js +2 -1
  32. package/dist/core/engine/callback-creators-core.js +2 -1
  33. package/dist/core/engine/construction.d.ts +1 -1
  34. package/dist/core/engine/construction.js +15 -3
  35. package/dist/core/engine/disposal.js +12 -0
  36. package/dist/core/engine/engine-create-types.d.ts +0 -14
  37. package/dist/core/engine/engine-internal-types.d.ts +17 -0
  38. package/dist/core/engine/engine-leak-warnings.d.ts +6 -0
  39. package/dist/core/engine/engine-leak-warnings.js +4 -0
  40. package/dist/core/engine/engine-runtime-helpers.d.ts +17 -0
  41. package/dist/core/engine/engine-runtime-helpers.js +26 -5
  42. package/dist/core/engine/errors.d.ts +74 -0
  43. package/dist/core/engine/errors.js +25 -1
  44. package/dist/core/engine/handle-result.js +1 -1
  45. package/dist/core/engine/handles.d.ts +89 -40
  46. package/dist/core/engine/handles.js +25 -27
  47. package/dist/core/engine/index.d.ts +122 -4
  48. package/dist/core/engine/index.js +82 -5
  49. package/dist/core/engine/inline-launch-queue.d.ts +14 -0
  50. package/dist/core/engine/inline-launch-queue.js +32 -7
  51. package/dist/core/engine/internals.d.ts +26 -10
  52. package/dist/core/engine/lifecycle/fork-helpers.js +1 -7
  53. package/dist/core/engine/lifecycle/persist.js +5 -20
  54. package/dist/core/engine/lifecycle/recovered-services.d.ts +45 -0
  55. package/dist/core/engine/lifecycle/recovered-services.js +34 -0
  56. package/dist/core/engine/lifecycle/resume.js +33 -5
  57. package/dist/core/engine/lifecycle/shared.d.ts +8 -0
  58. package/dist/core/engine/lifecycle/start-batch.js +23 -12
  59. package/dist/core/engine/lifecycle/start-commit.d.ts +47 -0
  60. package/dist/core/engine/lifecycle/start-commit.js +27 -0
  61. package/dist/core/engine/lifecycle/start-exec.d.ts +30 -2
  62. package/dist/core/engine/lifecycle/start-exec.js +38 -0
  63. package/dist/core/engine/lifecycle/start-or-signal-resolution.d.ts +79 -0
  64. package/dist/core/engine/lifecycle/start-or-signal-resolution.js +60 -0
  65. package/dist/core/engine/lifecycle/start-or-signal.d.ts +45 -0
  66. package/dist/core/engine/lifecycle/start-or-signal.js +141 -0
  67. package/dist/core/engine/lifecycle/start.d.ts +3 -3
  68. package/dist/core/engine/lifecycle/start.js +42 -37
  69. package/dist/core/engine/lifecycle.d.ts +3 -2
  70. package/dist/core/engine/lifecycle.js +9 -2
  71. package/dist/core/engine/listing.js +1 -1
  72. package/dist/core/engine/operations-data.d.ts +16 -0
  73. package/dist/core/engine/operations-data.js +6 -0
  74. package/dist/core/engine/operations-time.d.ts +3 -2
  75. package/dist/core/engine/operations-time.js +6 -1
  76. package/dist/core/engine/persisted-data-version.d.ts +5 -9
  77. package/dist/core/engine/persisted-data-version.js +4 -5
  78. package/dist/core/engine/schedule-handle.d.ts +45 -0
  79. package/dist/core/engine/schedule-handle.js +26 -0
  80. package/dist/core/engine/schedules.d.ts +1 -1
  81. package/dist/core/engine/schedules.js +7 -3
  82. package/dist/core/engine/second-instance-detector.d.ts +96 -0
  83. package/dist/core/engine/second-instance-detector.js +108 -0
  84. package/dist/core/engine/signals.d.ts +22 -0
  85. package/dist/core/engine/signals.js +15 -0
  86. package/dist/core/engine/termination/cleanup.d.ts +25 -0
  87. package/dist/core/engine/termination/cleanup.js +21 -1
  88. package/dist/core/engine/termination/complete.js +4 -3
  89. package/dist/core/engine/termination/suspend.d.ts +68 -0
  90. package/dist/core/engine/termination/suspend.js +41 -0
  91. package/dist/core/engine/termination.d.ts +4 -2
  92. package/dist/core/engine/termination.js +2 -0
  93. package/dist/core/engine/validation.js +25 -1
  94. package/dist/core/engine/workflow-feed.d.ts +5 -3
  95. package/dist/core/events/event-map.d.ts +2 -1
  96. package/dist/core/events/workflow-events.d.ts +23 -0
  97. package/dist/core/events/workflow-events.js +9 -0
  98. package/dist/core/inline-execution-strategy.d.ts +5 -0
  99. package/dist/core/inline-execution-strategy.js +2 -1
  100. package/dist/core/list-filter-validation.js +2 -1
  101. package/dist/core/start-workflow-validation.d.ts +22 -0
  102. package/dist/core/start-workflow-validation.js +11 -1
  103. package/dist/core/step-context.d.ts +10 -6
  104. package/dist/core/step-context.js +7 -15
  105. package/dist/core/types/activity.d.ts +6 -3
  106. package/dist/core/types/identity.d.ts +8 -1
  107. package/dist/core/types/launch-metadata.d.ts +33 -0
  108. package/dist/core/types/launch-metadata.js +0 -0
  109. package/dist/core/types/message-handles.d.ts +25 -0
  110. package/dist/core/types/options.d.ts +90 -7
  111. package/dist/core/types/reviews.d.ts +2 -1
  112. package/dist/core/types/services-resolution.d.ts +47 -0
  113. package/dist/core/types/services-resolution.js +0 -0
  114. package/dist/core/types/state.d.ts +11 -11
  115. package/dist/core/types/workflow-builder.d.ts +5 -4
  116. package/dist/core/types/workflow-context.d.ts +25 -0
  117. package/dist/core/types/workflow-function.d.ts +17 -0
  118. package/dist/core/types/workflow-snapshot.d.ts +29 -0
  119. package/dist/core/types/workflow-snapshot.js +0 -0
  120. package/dist/core/types.d.ts +3 -0
  121. package/dist/core/types.js +3 -0
  122. package/dist/core/weft-error.d.ts +46 -14
  123. package/dist/core/weft-error.js +12 -1
  124. package/dist/diagnostics/doctor.js +6 -3
  125. package/dist/diagnostics/format.js +2 -2
  126. package/dist/diagnostics/types.d.ts +1 -0
  127. package/dist/diagnostics/version-check.js +6 -4
  128. package/dist/index.d.ts +10 -5
  129. package/dist/index.js +11 -2
  130. package/dist/json-schema.js +3 -3
  131. package/dist/mcp/cli.js +35 -35
  132. package/dist/mcp/list-filter.js +2 -1
  133. package/dist/mcp/session.js +1 -0
  134. package/dist/observability/index.js +2 -2
  135. package/dist/server/handler.js +30 -30
  136. package/dist/server/index.js +33 -33
  137. package/dist/server/interactive-operations.js +1 -0
  138. package/dist/server/operations/resume-workflow.js +2 -2
  139. package/dist/server/operations/start-or-signal-workflow.d.ts +39 -0
  140. package/dist/server/operations/start-or-signal-workflow.js +140 -0
  141. package/dist/server/operations/start-workflow-options.d.ts +32 -0
  142. package/dist/server/operations/start-workflow-options.js +63 -0
  143. package/dist/server/operations/start-workflow.js +7 -69
  144. package/dist/server/operations/suspend-workflow.d.ts +13 -0
  145. package/dist/server/operations/suspend-workflow.js +36 -0
  146. package/dist/server/rest-binding.d.ts +18 -7
  147. package/dist/server/rest-bindings.js +12 -0
  148. package/dist/server/runtime/task-dispatch.js +5 -3
  149. package/dist/server/runtime/task-polling.d.ts +16 -2
  150. package/dist/server/runtime/task-polling.js +20 -5
  151. package/dist/server/runtime/websocket-worker.js +8 -0
  152. package/dist/server/serve-internals.d.ts +8 -0
  153. package/dist/server/serve-internals.js +4 -2
  154. package/dist/server/task-state.d.ts +8 -0
  155. package/dist/service-worker/index.js +28 -28
  156. package/dist/storage/capabilities.d.ts +10 -2
  157. package/dist/storage/capabilities.js +2 -2
  158. package/dist/storage/http.js +2 -2
  159. package/dist/storage/index.d.ts +7 -1
  160. package/dist/storage/indexeddb.js +1 -1
  161. package/dist/storage/interface.d.ts +40 -0
  162. package/dist/storage/interface.js +1 -1
  163. package/dist/storage/key-prefixes.d.ts +1 -1
  164. package/dist/storage/key-prefixes.js +3 -0
  165. package/dist/storage/lmdb.js +1 -1
  166. package/dist/storage/memory.js +1 -1
  167. package/dist/storage/neon-value-mapping.d.ts +47 -0
  168. package/dist/storage/neon-value-mapping.js +11 -0
  169. package/dist/storage/neon.d.ts +108 -0
  170. package/dist/storage/neon.js +10 -0
  171. package/dist/storage/node-sqlite-loader.d.ts +71 -0
  172. package/dist/storage/node-sqlite-loader.js +41 -0
  173. package/dist/storage/node-sqlite.d.ts +1 -19
  174. package/dist/storage/node-sqlite.js +38 -32
  175. package/dist/storage/postgres-key-value-queries.d.ts +79 -0
  176. package/dist/storage/postgres-key-value-queries.js +63 -0
  177. package/dist/storage/resolve.d.ts +2 -165
  178. package/dist/storage/resolve.js +1 -1
  179. package/dist/storage/scoped-storage.js +1 -1
  180. package/dist/storage/storage-configuration.d.ts +209 -0
  181. package/dist/storage/storage-configuration.js +0 -0
  182. package/dist/storage/text-value-store.d.ts +13 -10
  183. package/dist/storage/turso.js +2 -2
  184. package/dist/storage/typed-storage.js +1 -1
  185. package/dist/storage/web-extension.js +1 -1
  186. package/dist/testing/event-loop.d.ts +36 -2
  187. package/dist/testing/index.d.ts +31 -1
  188. package/dist/testing/index.js +33 -33
  189. package/dist/version.d.ts +1 -1
  190. package/dist/version.js +1 -1
  191. package/dist/worker/index.js +9 -5
  192. package/dist/worker/long-poll.js +4 -0
  193. package/dist/worker/protocol-messages.d.ts +20 -0
  194. package/dist/worker/protocol-schemas.d.ts +32 -0
  195. package/dist/worker/protocol-schemas.js +8 -4
  196. package/dist/worker/protocol-task-result.d.ts +28 -0
  197. package/dist/worker/protocol-task-result.js +76 -0
  198. package/dist/worker/protocol.d.ts +4 -15
  199. package/dist/worker/protocol.js +1 -1
  200. package/dist/worker/registry/fair-share.d.ts +29 -0
  201. package/dist/worker/registry/fair-share.js +30 -0
  202. package/dist/worker/registry/routing.d.ts +18 -0
  203. package/dist/worker/registry/routing.js +14 -0
  204. package/dist/worker/registry/types.d.ts +7 -0
  205. package/dist/worker/registry.d.ts +16 -1
  206. package/dist/worker/registry.js +24 -36
  207. package/package.json +17 -4
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- var wW=Object.defineProperty;var jW=(W)=>W;function hW(W,$){this[W]=jW.bind(null,$)}var b0=(W,$)=>{for(var Z in $)wW(W,Z,{get:$[Z],enumerable:!0,configurable:!0,set:hW.bind($,Z)})};var X=(W,$)=>()=>(W&&($=W(W=0)),$);function v(W,$,Z){if(!W.capabilities()[$])throw Error(`Feature "${Z}" requires storage capability "${$}", but this storage backend does not provide it.`)}function mW(W){let $=W.capabilities(),Z=[];if($.persistence!=="local")Z.push(`persistence must be "local" (got "${$.persistence}")`);if($.readAfterWrite!=="linearizable")Z.push(`readAfterWrite must be "linearizable" (got "${$.readAfterWrite}")`);if($.scanConsistency!=="snapshot")Z.push(`scanConsistency must be "snapshot" (got "${$.scanConsistency}")`);if(!$.atomicBatch)Z.push("atomicBatch must be true");if(!$.conditionalBatch)Z.push("conditionalBatch must be true");if(Z.length>0)throw Error(`Storage is not durable enough for recovery: ${Z.join("; ")}.`)}var b="default";async function r(W,$){return await W.get($)!==null}async function*z(W,$,Z){for await(let[G]of W.scan($,Z))yield G}async function s(W,$){let Z=0;for await(let G of z(W,$))Z++;return Z}async function a(W,$){let Z=[];for await(let G of z(W,$))Z.push({type:"delete",key:G});if(Z.length===0)return 0;return await W.batch(Z),Z.length}async function o(W,$,Z){let G=[];for await(let J of z(W,$,Z))G.push({type:"delete",key:J});if(G.length===0)return 0;return await W.batch(G),G.length}var gW;var t=X(()=>{gW=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","idx:","offload:","op:","review:","schedule:","schedule-due:","schedule-run:","sig:","sigres:","sigseq:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-deadline:","wf-delayed:","wf-headers:","wf-idx-","wf-terminal:"]});function i0(W){return W.length>0?W.slice(0,-1)+String.fromCharCode(W.charCodeAt(W.length-1)+1):"\xFF"}function r0(W,$={}){if($.gt!==void 0&&W<=$.gt)return!1;if($.gte!==void 0&&W<$.gte)return!1;if($.lt!==void 0&&W>=$.lt)return!1;if($.lte!==void 0&&W>$.lte)return!1;return!0}function s0(W,$){if(W===null||$===null)return W===$;if(W.byteLength!==$.byteLength)return!1;for(let Z=0;Z<W.byteLength;Z++)if(W[Z]!==$[Z])return!1;return!0}async function e(W,$){if(W.has)return W.has($);return r(W,$)}function WW(W,$,Z){if(W.keys)return W.keys($,Z);return z(W,$,Z)}async function $W(W,$){if(W.count)return W.count($);return s(W,$)}async function ZW(W,$){if(W.deletePrefix)return W.deletePrefix($);return a(W,$)}async function GW(W,$,Z){if(v(W,"conditionalBatch","storageConditionalBatch"),!W.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return W.conditionalBatch($,Z)}function q(W){return encodeURIComponent(W)}function a0(W){return decodeURIComponent(W)}function o0(W){try{return decodeURIComponent(W)}catch{return null}}var N=(W)=>String(W).padStart(16,"0"),t0;var JW=X(()=>{t();t0={workflow:(W)=>`wf:${q(W)}`,checkpoint:(W)=>`wf:${q(W)}:ckpt`,checkpointHistory:(W,$)=>`wf:${q(W)}:ckpt:${String($).padStart(10,"0")}`,timelinePrefix:(W)=>`wf:${q(W)}:timeline:`,timeline:(W,$)=>`wf:${q(W)}:timeline:${String($).padStart(10,"0")}`,schedule:(W)=>`schedule:${q(W)}`,scheduleTick:(W,$)=>`schedule-due:${String(W).padStart(16,"0")}:${q($)}`,scheduleRun:(W)=>`schedule-run:${q(W)}`,operation:(W,$,Z)=>`op:${W}:${N($)}:${Z}`,operationInflight:(W)=>`op:inflight:${W}`,operationQueued:(W)=>`op:queued:${W}`,operationResolved:(W)=>`op:resolved:${W}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(W,$,Z)=>`audit:bulk:${N(W)}:${q($)}:${q(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(W,$)=>`op:resolved-by-time:${N(W)}:${q($)}`,asyncActivity:(W,$)=>`async-act:v1:${q(W)}:${q($)}`,activityReconciliationPrefix:(W)=>`actrec:v1:${q(W)}:`,activityReconciliation:(W,$,Z)=>`actrec:v1:${q(W)}:${q($)}:${Z}`,eventPrefix:(W)=>`ev:${q(W)}:`,event:(W,$)=>`ev:${q(W)}:${String($).padStart(10,"0")}`,eventHead:(W)=>`ev:${q(W)}:head`,eventWatermark:(W)=>`ev:${q(W)}:watermark`,signal:(W,$,Z)=>`sig:${q(W)}:${$}:${q(Z)}`,signalSequence:(W)=>`sigseq:v1:${q(W)}`,signalAcceptedResponsePrefix:(W)=>`sigres:v1:${q(W)}:`,signalAcceptedResponse:(W,$,Z)=>`sigres:v1:${q(W)}:${q($)}:${q(Z)}`,deadline:(W,$)=>`wf-deadline:${N(W)}:${q($)}`,terminalCleanup:(W,$)=>`wf-cleanup:${N(W)}:${q($)}`,delayedStart:(W,$)=>`wf-delayed:${N(W)}:${q($)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(W,$)=>`wf-terminal:${N(W)}:${q($)}`,attribute:(W)=>`attr:${q(W)}`,attributeIndex:(W,$,Z)=>`idx:${W}:${$}:${q(Z)}`,tagIndex:(W,$)=>`tag:${q(W)}:${q($)}`,updatePrefix:(W)=>`upd:${q(W)}:`,update:(W,$)=>`upd:${q(W)}:${$}`,updateResponse:(W)=>`upr:${W}`,updateIdempotency:(W,$)=>`upk:${q(W)}:${$}`,budget:(W,$,Z)=>`budget:${W}:${$}:${Z}`,review:(W,$)=>`review:${q(W)}:${$}`,workflowHeaders:(W)=>`wf-headers:${q(W)}`,terminalCleanupNeeded:(W)=>`wf-cleanup-needed:${q(W)}`,offload:(W,$)=>`offload:${q(W)}:${$}`,archive:(W,$)=>`archive:${q(W)}:${$}`,stateExecution:(W,$)=>`state:execution:${q(W)}:${q($)}`,stateWorkflow:(W,$)=>`state:workflow-scope:${b}:${q(W)}:${q($)}`,streamChunkPrefix:(W,$)=>`blob:${q(W)}:${$}:chunk:`,streamChunk:(W,$,Z)=>`blob:${q(W)}:${$}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(W,$)=>`blob:${q(W)}:${$}:meta`,budgetCharged:(W)=>`budget-charged:${W}`,toolEffect:(W,$,Z)=>`tool-effect:${q(W)}:${$}:${Z}`,workflowVisibilityStatus:(W,$)=>`wf-idx-status:${q(W)}:${q($)}`,workflowVisibilityType:(W,$)=>`wf-idx-type:${q(W)}:${q($)}`,workflowVisibilityCreated:(W,$)=>`wf-idx-created:${N(W)}:${q($)}`,workflowVisibilityUpdated:(W,$)=>`wf-idx-updated:${N(W)}:${q($)}`,workflowVisibilityDeadline:(W,$)=>`wf-idx-deadline:${N(W)}:${q($)}`,workflowVisibilityManifest:(W)=>`wf-idx-manifest:${q(W)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function QW(W){let $=W.length,Z=0,G=0;while(G<$){let J=W.charCodeAt(G++);if((J&4294967168)===0){Z++;continue}else if((J&4294965248)===0)Z+=2;else{if(J>=55296&&J<=56319){if(G<$){let Q=W.charCodeAt(G);if((Q&64512)===56320)++G,J=((J&1023)<<10)+(Q&1023)+65536}}if((J&4294901760)===0)Z+=3;else Z+=4}}return Z}function vW(W,$,Z){let G=W.length,J=Z,Q=0;while(Q<G){let F=W.charCodeAt(Q++);if((F&4294967168)===0){$[J++]=F;continue}else if((F&4294965248)===0)$[J++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(Q<G){let H=W.charCodeAt(Q);if((H&64512)===56320)++Q,F=((F&1023)<<10)+(H&1023)+65536}}if((F&4294901760)===0)$[J++]=F>>12&15|224,$[J++]=F>>6&63|128;else $[J++]=F>>18&7|240,$[J++]=F>>12&63|128,$[J++]=F>>6&63|128}$[J++]=F&63|128}}function fW(W,$,Z){bW.encodeInto(W,$.subarray(Z))}function qW(W,$,Z){if(W.length>yW)fW(W,$,Z);else vW(W,$,Z)}function y(W,$,Z){let G=$,J=G+Z,Q=[],F="";while(G<J){let H=W[G++];if((H&128)===0)Q.push(H);else if((H&224)===192){let A=W[G++]&63;Q.push((H&31)<<6|A)}else if((H&240)===224){let A=W[G++]&63,g=W[G++]&63;Q.push((H&31)<<12|A<<6|g)}else if((H&248)===240){let A=W[G++]&63,g=W[G++]&63,kW=W[G++]&63,B=(H&7)<<18|A<<12|g<<6|kW;if(B>65535)B-=65536,Q.push(B>>>10&1023|55296),B=56320|B&1023;Q.push(B)}else Q.push(H);if(Q.length>=lW)F+=String.fromCharCode(...Q),Q.length=0}if(Q.length>0)F+=String.fromCharCode(...Q);return F}function cW(W,$,Z){let G=W.subarray($,$+Z);return pW.decode(G)}function FW(W,$,Z){if(Z>uW)return cW(W,$,Z);else return y(W,$,Z)}var bW,yW=50,lW=4096,pW,uW=200;var C=X(()=>{bW=new TextEncoder;pW=new TextDecoder});class K{type;data;constructor(W,$){this.type=W,this.data=$}}var V;var f=X(()=>{V=class V extends Error{constructor(W){super(W);let $=Object.create(V.prototype);Object.setPrototypeOf(this,$),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:V.name})}}});function XW(W,$,Z){let G=Z/4294967296,J=Z;W.setUint32($,G),W.setUint32($+4,J)}function x(W,$,Z){let G=Math.floor(Z/4294967296),J=Z;W.setUint32($,G),W.setUint32($+4,J)}function S(W,$){let Z=W.getInt32($),G=W.getUint32($+4);return Z*4294967296+G}function YW(W,$){let Z=W.getUint32($),G=W.getUint32($+4);return Z*4294967296+G}var O=4294967295;function rW({sec:W,nsec:$}){if(W>=0&&$>=0&&W<=iW)if($===0&&W<=nW){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,W),Z}else{let Z=W/4294967296,G=W&4294967295,J=new Uint8Array(8),Q=new DataView(J.buffer);return Q.setUint32(0,$<<2|Z&3),Q.setUint32(4,G),J}else{let Z=new Uint8Array(12),G=new DataView(Z.buffer);return G.setUint32(0,$),x(G,4,W),Z}}function sW(W){let $=W.getTime(),Z=Math.floor($/1000),G=($-Z*1000)*1e6,J=Math.floor(G/1e9);return{sec:Z+J,nsec:G-J*1e9}}function aW(W){if(W instanceof Date){let $=sW(W);return rW($)}else return null}function oW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let Z=$.getUint32(0),G=0;return{sec:Z,nsec:0}}case 8:{let Z=$.getUint32(0),G=$.getUint32(4),J=(Z&3)*4294967296+G,Q=Z>>>2;return{sec:J,nsec:Q}}case 12:{let Z=S($,4),G=$.getUint32(0);return{sec:Z,nsec:G}}default:throw new V(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function tW(W){let $=oW(W);return new Date($.sec*1000+$.nsec/1e6)}var dW=-1,nW=4294967295,iW=17179869183,HW;var VW=X(()=>{f();HW={type:dW,encode:aW,decode:tW}});var R;var E=X(()=>{VW();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(HW)}register({type:W,encode:$,decode:Z}){if(W>=0)this.encoders[W]=$,this.decoders[W]=Z;else{let G=-1-W;this.builtInEncoders[G]=$,this.builtInDecoders[G]=Z}}tryToEncode(W,$){for(let Z=0;Z<this.builtInEncoders.length;Z++){let G=this.builtInEncoders[Z];if(G!=null){let J=G(W,$);if(J!=null){let Q=-1-Z;return new K(Q,J)}}}for(let Z=0;Z<this.encoders.length;Z++){let G=this.encoders[Z];if(G!=null){let J=G(W,$);if(J!=null)return new K(Z,J)}}if(W instanceof K)return W;return null}decode(W,$,Z){let G=$<0?this.builtInDecoders[-1-$]:this.decoders[$];if(G)return G(W,$,Z);else return new K($,W)}}});function eW(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function T(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(eW(W))return new Uint8Array(W);else return Uint8Array.from(W)}class k{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??W0,this.initialBufferSize=W?.initialBufferSize??$0,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new k({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,$){if($>this.maxDepth)throw Error(`Too deep objects in depth ${$}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,$)}ensureBufferSizeToWrite(W){let $=this.pos+W;if(this.view.byteLength<$)this.resizeBuffer($*2)}resizeBuffer(W){let $=new ArrayBuffer(W),Z=new Uint8Array($),G=new DataView($);Z.set(this.bytes),this.view=G,this.bytes=Z}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let Z=QW(W);this.ensureBufferSizeToWrite(5+Z),this.writeStringHeader(Z),qW(W,this.bytes,this.pos),this.pos+=Z}encodeObject(W,$){let Z=this.extensionCodec.tryToEncode(W,this.context);if(Z!=null)this.encodeExtension(Z);else if(Array.isArray(W))this.encodeArray(W,$);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,$);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let $=W.byteLength;if($<256)this.writeU8(196),this.writeU8($);else if($<65536)this.writeU8(197),this.writeU16($);else if($<4294967296)this.writeU8(198),this.writeU32($);else throw Error(`Too large binary: ${$}`);let Z=T(W);this.writeU8a(Z)}encodeArray(W,$){let Z=W.length;if(Z<16)this.writeU8(144+Z);else if(Z<65536)this.writeU8(220),this.writeU16(Z);else if(Z<4294967296)this.writeU8(221),this.writeU32(Z);else throw Error(`Too large array: ${Z}`);for(let G of W)this.doEncode(G,$+1)}countWithoutUndefined(W,$){let Z=0;for(let G of $)if(W[G]!==void 0)Z++;return Z}encodeMap(W,$){let Z=Object.keys(W);if(this.sortKeys)Z.sort();let G=this.ignoreUndefined?this.countWithoutUndefined(W,Z):Z.length;if(G<16)this.writeU8(128+G);else if(G<65536)this.writeU8(222),this.writeU16(G);else if(G<4294967296)this.writeU8(223),this.writeU32(G);else throw Error(`Too large map object: ${G}`);for(let J of Z){let Q=W[J];if(!(this.ignoreUndefined&&Q===void 0))this.encodeString(J),this.doEncode(Q,$+1)}}encodeExtension(W){if(typeof W.data==="function"){let Z=W.data(this.pos+6),G=Z.length;if(G>=4294967296)throw Error(`Too large extension object: ${G}`);this.writeU8(201),this.writeU32(G),this.writeI8(W.type),this.writeU8a(Z);return}let $=W.data.length;if($===1)this.writeU8(212);else if($===2)this.writeU8(213);else if($===4)this.writeU8(214);else if($===8)this.writeU8(215);else if($===16)this.writeU8(216);else if($<256)this.writeU8(199),this.writeU8($);else if($<65536)this.writeU8(200),this.writeU16($);else if($<4294967296)this.writeU8(201),this.writeU32($);else throw Error(`Too large extension object: ${$}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let $=W.length;this.ensureBufferSizeToWrite($),this.bytes.set(W,this.pos),this.pos+=$}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),XW(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),x(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}var W0=100,$0=2048;var PW=X(()=>{C();E()});function M(W,$){return new k($).encodeSharedRef(W)}var NW=X(()=>{PW()});function w(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}class l{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=Z0,$=G0){this.maxKeyLength=W,this.maxLengthPerKey=$,this.caches=[];for(let Z=0;Z<this.maxKeyLength;Z++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,$,Z){let G=this.caches[Z-1];W:for(let J of G){let Q=J.bytes;for(let F=0;F<Z;F++)if(Q[F]!==W[$+F])continue W;return J.str}return null}store(W,$){let Z=this.caches[W.length-1],G={bytes:W,str:$};if(Z.length>=this.maxLengthPerKey)Z[Math.random()*Z.length|0]=G;else Z.push(G)}decode(W,$,Z){let G=this.find(W,$,Z);if(G!=null)return this.hit++,G;this.miss++;let J=y(W,$,Z),Q=Uint8Array.prototype.slice.call(W,$,$+Z);return this.store(Q,J),J}}var Z0=16,G0=16;var RW=X(()=>{C()});class _W{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let $=this.getUninitializedStateFromPool();$.type=p,$.position=0,$.size=W,$.array=Array(W)}pushMapState(W){let $=this.getUninitializedStateFromPool();$.type=L,$.readCount=0,$.size=W,$.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===p){let Z=W;Z.size=0,Z.array=void 0,Z.position=0,Z.type=void 0}if(W.type===L||W.type===UW){let Z=W;Z.size=0,Z.map=void 0,Z.readCount=0,Z.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class j{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=u;bytes=Q0;headByte=D;stack=new _W;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??R.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??O,this.maxBinLength=W?.maxBinLength??O,this.maxArrayLength=W?.maxArrayLength??O,this.maxMapLength=W?.maxMapLength??O,this.maxExtLength=W?.maxExtLength??O,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:q0,this.mapKeyConverter=W?.mapKeyConverter??J0}clone(){return new j({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=D,this.stack.reset()}setBuffer(W){let $=T(W);this.bytes=$,this.view=new DataView($.buffer,$.byteOffset,$.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer(W);else{let $=this.bytes.subarray(this.pos),Z=T(W),G=new Uint8Array($.length+Z.length);G.set($),G.set(Z,$.length),this.setBuffer(G)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:$,pos:Z}=this;return RangeError(`Extra ${$.byteLength-Z} of ${$.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let $=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return $}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let $=!1,Z;for await(let F of W){if($)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Z=this.doDecodeSync(),$=!0}catch(H){if(!(H instanceof RangeError))throw H}this.totalPos+=this.pos}if($){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Z}let{headByte:G,pos:J,totalPos:Q}=this;throw RangeError(`Insufficient data in parsing ${w(G)} at ${Q} (${J} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,$){if(this.entered){yield*this.clone().decodeMultiAsync(W,$);return}try{this.entered=!0;let Z=$,G=-1;for await(let J of W){if($&&G===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(J),Z)G=this.readArraySize(),Z=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--G===0)break}catch(Q){if(!(Q instanceof RangeError))throw Q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),$;if(W>=224)$=W-256;else if(W<192)if(W<128)$=W;else if(W<144){let G=W-128;if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W<160){let G=W-144;if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else{let G=W-160;$=this.decodeString(G,0)}else if(W===192)$=null;else if(W===194)$=!1;else if(W===195)$=!0;else if(W===202)$=this.readF32();else if(W===203)$=this.readF64();else if(W===204)$=this.readU8();else if(W===205)$=this.readU16();else if(W===206)$=this.readU32();else if(W===207)if(this.useBigInt64)$=this.readU64AsBigInt();else $=this.readU64();else if(W===208)$=this.readI8();else if(W===209)$=this.readI16();else if(W===210)$=this.readI32();else if(W===211)if(this.useBigInt64)$=this.readI64AsBigInt();else $=this.readI64();else if(W===217){let G=this.lookU8();$=this.decodeString(G,1)}else if(W===218){let G=this.lookU16();$=this.decodeString(G,2)}else if(W===219){let G=this.lookU32();$=this.decodeString(G,4)}else if(W===220){let G=this.readU16();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===221){let G=this.readU32();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===222){let G=this.readU16();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===223){let G=this.readU32();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===196){let G=this.lookU8();$=this.decodeBinary(G,1)}else if(W===197){let G=this.lookU16();$=this.decodeBinary(G,2)}else if(W===198){let G=this.lookU32();$=this.decodeBinary(G,4)}else if(W===212)$=this.decodeExtension(1,0);else if(W===213)$=this.decodeExtension(2,0);else if(W===214)$=this.decodeExtension(4,0);else if(W===215)$=this.decodeExtension(8,0);else if(W===216)$=this.decodeExtension(16,0);else if(W===199){let G=this.lookU8();$=this.decodeExtension(G,1)}else if(W===200){let G=this.lookU16();$=this.decodeExtension(G,2)}else if(W===201){let G=this.lookU32();$=this.decodeExtension(G,4)}else throw new V(`Unrecognized type byte: ${w(W)}`);this.complete();let Z=this.stack;while(Z.length>0){let G=Z.top();if(G.type===p)if(G.array[G.position]=$,G.position++,G.position===G.size)$=G.array,Z.release(G);else continue W;else if(G.type===L){if($==="__proto__")throw new V("The key __proto__ is not allowed");G.key=this.mapKeyConverter($),G.type=UW;continue W}else if(G.map[G.key]=$,G.readCount++,G.readCount===G.size)$=G.map,Z.release(G);else{G.key=null,G.type=L;continue W}}return $}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new V(`Unrecognized array type byte: ${w(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new V(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new V(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,$){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,$);return this.decodeBinary(W,$)}decodeUtf8String(W,$){if(W>this.maxStrLength)throw new V(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+$+W)throw MW;let Z=this.pos+$,G;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))G=this.keyDecoder.decode(this.bytes,Z,W);else G=FW(this.bytes,Z,W);return this.pos+=$+W,G}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary(W,$){if(W>this.maxBinLength)throw new V(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+$))throw MW;let Z=this.pos+$,G=this.bytes.subarray(Z,Z+W);return this.pos+=$+W,G}decodeExtension(W,$){if(W>this.maxExtLength)throw new V(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let Z=this.view.getInt8(this.pos+$),G=this.decodeBinary(W,$+1);return this.extensionCodec.decode(G,Z,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=YW(this.view,this.pos);return this.pos+=8,W}readI64(){let W=S(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}var p="array",L="map_key",UW="map_value",J0=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new V("The type of key must be string or number but "+typeof W)},D=-1,u,Q0,MW,q0;var BW=X(()=>{E();C();RW();f();u=new DataView(new ArrayBuffer(0)),Q0=new Uint8Array(u.buffer);try{u.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}MW=RangeError("Insufficient data"),q0=new l});function U(W,$){return new j($).decode(W)}var KW=X(()=>{BW()});var c=X(()=>{NW();KW();E()});function d(W){if(typeof W==="object"&&W!==null&&!Array.isArray(W))return W;return{}}function h(W){return Array.isArray(W)?W:[]}function OW(W){if(!(W instanceof Date))return null;let $=new ArrayBuffer(8);return new DataView($).setFloat64(0,W.getTime()),new Uint8Array($)}function AW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength).getFloat64(0);return new Date($)}function R0(W){return typeof W==="object"&&W!==null&&"__tag"in W&&W.__tag===zW}function _(W,$){if(W===void 0)return N0;if(W===null||typeof W!=="object")return W;if($.has(W))return W;$.add(W);try{return M0(W,$)}finally{$.delete(W)}}function M0(W,$){if(Array.isArray(W))return U0(W,$);if(W instanceof Map)return _0(W,$);if(W instanceof Set)return B0(W,$);if(K0(W))return W;return O0(W,$)}function U0(W,$){let Z=Array.from({length:W.length});for(let G=0;G<W.length;G++)Z[G]=_(W[G],$);return Z}function _0(W,$){let Z=new Map;for(let[G,J]of W)Z.set(_(G,$),_(J,$));return Z}function B0(W,$){let Z=new Set;for(let G of W)Z.add(_(G,$));return Z}function K0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function O0(W,$){let Z=W,G={};for(let J of Object.keys(Z))G[J]=_(Z[J],$);return G}var F0=1,X0=2,Y0=3,H0=4,V0=5,P0=6,P,zW,N0;var TW=X(()=>{c();P=new R;P.register({type:F0,encode:OW,decode:AW});P.register({type:X0,encode(W){if(W instanceof RegExp)return M({source:W.source,flags:W.flags});return null},decode(W){let $=d(U(W)),Z=typeof $.source==="string"?$.source:"",G=typeof $.flags==="string"?$.flags:"";return new RegExp(Z,G)}});P.register({type:Y0,encode(W){if(W instanceof Map){let $=[...W.entries()];return M($,{extensionCodec:P})}return null},decode(W){let Z=h(U(W,{extensionCodec:P})).map((G)=>{let J=h(G);return[J[0],J[1]]});return new Map(Z)}});P.register({type:H0,encode(W){if(W instanceof Set){let $=[...W.values()];return M($,{extensionCodec:P})}return null},decode(W){let $=h(U(W,{extensionCodec:P}));return new Set($)}});zW=Symbol("UndefinedSentinel"),N0=Object.freeze({__tag:zW});P.register({type:V0,encode(W){if(R0(W))return new Uint8Array(0);return null},decode(){return}});P.register({type:P0,encode(W){if(W instanceof Error)return M({name:W.name,message:W.message,stack:W.stack});return null},decode(W){let $=d(U(W)),Z=typeof $.name==="string"?$.name:"Error",G=typeof $.message==="string"?$.message:"",J=typeof $.stack==="string"?$.stack:void 0,Q=Error(G);if(Q.name=Z,J!==void 0)Q.stack=J;return Q}})});function n(W){let $=_(W,new Set);return M($,{extensionCodec:P})}function i(W){return U(W,{extensionCodec:P})}var DW=X(()=>{c();TW()});function m(W,$=""){let Z=[];return I(W,$,Z,new Set),{valid:Z.length===0,errors:Z}}function A0(W){let $=Object.getPrototypeOf(W);return z0($)&&!T0(W)&&D0($)}function z0(W){return W!==Object.prototype&&W!==null}function T0(W){return Array.isArray(W)||W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function D0(W){if(typeof W!=="object"||W===null)return!1;return Object.getOwnPropertyNames(W).some((Z)=>{if(Z==="constructor")return!1;let G=Object.getOwnPropertyDescriptor(W,Z);return G!==void 0&&typeof G.value==="function"})}function LW(W,$,Z,G){W.push({path:$,value:Z,reason:G.reason,suggestion:G.suggestion})}function L0(W){if(typeof W==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof W==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function I0(W,$){if(W instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if(W instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if(W instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if($.has(W))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(A0(W))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function C0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function x0(W,$,Z,G){for(let[J,Q]of W){let F=String(J);I(Q,$?`${$}.${F}`:F,Z,G)}}function S0(W,$,Z,G){let J=0;for(let Q of W){let F=$?`${$}[${J}]`:`[${J}]`;I(Q,F,Z,G),J++}}function E0(W,$,Z,G){for(let J=0;J<W.length;J++){let Q=$?`${$}[${J}]`:`[${J}]`;I(W[J],Q,Z,G)}}function k0(W,$,Z,G){for(let J of Object.keys(W)){let Q=$?`${$}.${J}`:J;I(W[J],Q,Z,G)}}function I(W,$,Z,G){if(W===null||W===void 0)return;let J=L0(W);if(J){LW(Z,$,W,J);return}if(typeof W!=="object")return;let Q=I0(W,G);if(Q){LW(Z,$,W,Q);return}G.add(W);try{if(C0(W))return;if(W instanceof Map){x0(W,$,Z,G);return}if(W instanceof Set){S0(W,$,Z,G);return}if(Array.isArray(W)){E0(W,$,Z,G);return}k0(W,$,Z,G)}finally{G.delete(W)}}var IW=X(()=>{DW()});var CW=X(()=>{IW()});function w0(W){if(W===void 0)return;if(typeof W!=="number"||!Number.isInteger(W)||W<0)throw Error("deleteRange limit must be a finite non-negative integer");return W===0?0:W}function j0(W){let $={},Z=!1;for(let J of["gt","gte","lt","lte"]){let Q=W[J];if(Q===void 0)continue;if(typeof Q!=="string")throw Error("deleteRange bounds must be strings");$[J]=Q,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let G=w0(W.limit);if(G!==void 0)$.limit=G;return $}async function xW(W,$,Z){let G=j0(Z);if(W.deleteRange)return W.deleteRange($,G);return o(W,$,G)}var SW=()=>{};CW();SW();JW();class EW{#W;#$;#Z;constructor(W,$,Z={}){this.#W=W,this.#$=$,this.#Z=Z.disposeUnderlyingStorage??!0}async get(W){let $=await this.#W.get(W);return $===null?null:this.#$.decode($)}async put(W,$){await this.#W.put(W,this.#$.encode($))}async delete(W){await this.#W.delete(W)}async*scan(W,$){for await(let[Z,G]of this.#W.scan(W,$))yield[Z,this.#$.decode(G)]}async batch(W){await this.#W.batch(this.#G(W))}#G(W){return W.map((Z)=>{if(Z.type==="put")return{type:"put",key:Z.key,value:this.#$.encode(Z.value)};return Z})}#J(W){return W.map(($)=>({key:$.key,expectedValue:$.expectedValue===null?null:this.#$.encode($.expectedValue)}))}async conditionalBatch(W,$){return GW(this.#W,this.#J(W),this.#G($))}async has(W){return e(this.#W,W)}async deletePrefix(W){return ZW(this.#W,W)}async deleteRange(W,$){return xW(this.#W,W,$)}keys(W,$){return WW(this.#W,W,$)}async count(W){return $W(this.#W,W)}[Symbol.dispose](){if(!this.#Z)return;this.#W[Symbol.dispose]()}}function z6(W,$,Z={}){return new EW(W,$,Z)}function h0(W){try{let $=JSON.stringify(W);if($===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode($)}catch($){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:$})}}function m0(W){let $=m(W);if(!$.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${$.errors[0]?.reason??""}`.trim());return n(W)}function g0(W){return JSON.parse(new TextDecoder().decode(W))}function v0(W){let $=i(W),Z=m($);if(!Z.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Z.errors[0]?.reason??""}`.trim());return $}function T6(W){return{encode($){return h0($)},decode($){let Z=g0($);return W?W(Z):Z}}}function D6(W){return{encode($){return m0($)},decode($){let Z=v0($);return W?W(Z):Z}}}export{z6 as withCodec,D6 as msgpackCodec,T6 as jsonCodec};
2
+ var gW=Object.defineProperty;var vW=(W)=>W;function bW(W,$){this[W]=vW.bind(null,$)}var c0=(W,$)=>{for(var Z in $)gW(W,Z,{get:$[Z],enumerable:!0,configurable:!0,set:bW.bind($,Z)})};var X=(W,$)=>()=>(W&&($=W(W=0)),$);function b(W,$,Z){if(!W.capabilities()[$])throw Error(`Feature "${Z}" requires storage capability "${$}", but this storage backend does not provide it.`)}function fW(W){let $=W.capabilities(),Z=[];if($.persistence!=="local"&&$.persistence!=="remote")Z.push(`persistence must be "local" or "remote" (got "${$.persistence}")`);if($.readAfterWrite!=="linearizable")Z.push(`readAfterWrite must be "linearizable" (got "${$.readAfterWrite}")`);if($.scanConsistency!=="snapshot")Z.push(`scanConsistency must be "snapshot" (got "${$.scanConsistency}")`);if(!$.atomicBatch)Z.push("atomicBatch must be true");if(!$.conditionalBatch)Z.push("conditionalBatch must be true");if(Z.length>0)throw Error(`Storage is not durable enough for recovery: ${Z.join("; ")}.`)}var f="default";async function s(W,$){return await W.get($)!==null}async function*z(W,$,Z){for await(let[G]of W.scan($,Z))yield G}async function a(W,$){let Z=0;for await(let G of z(W,$))Z++;return Z}async function o(W,$){let Z=[];for await(let G of z(W,$))Z.push({type:"delete",key:G});if(Z.length===0)return 0;return await W.batch(Z),Z.length}async function t(W,$,Z){let G=[];for await(let Q of z(W,$,Z))G.push({type:"delete",key:Q});if(G.length===0)return 0;return await W.batch(G),G.length}var yW;var e=X(()=>{yW=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","idx:","liveness:","offload:","op:","review:","schedule:","schedule-due:","schedule-run:","sig:","sigres:","sigseq:","start-idem:","state:","tag:","tool-effect:","upd:","upk:","upr:","wf:","wf-cleanup:","wf-cleanup-needed:","wf-deadline:","wf-delayed:","wf-has-services:","wf-headers:","wf-idx-","wf-terminal:"]});function e0(W){return W.length>0?W.slice(0,-1)+String.fromCharCode(W.charCodeAt(W.length-1)+1):"\xFF"}function W$(W,$={}){if($.gt!==void 0&&W<=$.gt)return!1;if($.gte!==void 0&&W<$.gte)return!1;if($.lt!==void 0&&W>=$.lt)return!1;if($.lte!==void 0&&W>$.lte)return!1;return!0}function $$(W,$){if(W===null||$===null)return W===$;if(W.byteLength!==$.byteLength)return!1;for(let Z=0;Z<W.byteLength;Z++)if(W[Z]!==$[Z])return!1;return!0}async function WW(W,$){if(W.has)return W.has($);return s(W,$)}function $W(W,$,Z){if(W.keys)return W.keys($,Z);return z(W,$,Z)}async function ZW(W,$){if(W.count)return W.count($);return a(W,$)}async function GW(W,$){if(W.deletePrefix)return W.deletePrefix($);return o(W,$)}async function QW(W,$,Z){if(b(W,"conditionalBatch","storageConditionalBatch"),!W.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return W.conditionalBatch($,Z)}function J(W){return encodeURIComponent(W)}function Z$(W){return decodeURIComponent(W)}function G$(W){try{return decodeURIComponent(W)}catch{return null}}var N=(W)=>String(W).padStart(16,"0"),Q$;var JW=X(()=>{e();Q$={workflow:(W)=>`wf:${J(W)}`,checkpoint:(W)=>`wf:${J(W)}:ckpt`,checkpointHistory:(W,$)=>`wf:${J(W)}:ckpt:${String($).padStart(10,"0")}`,timelinePrefix:(W)=>`wf:${J(W)}:timeline:`,timeline:(W,$)=>`wf:${J(W)}:timeline:${String($).padStart(10,"0")}`,schedule:(W)=>`schedule:${J(W)}`,scheduleTick:(W,$)=>`schedule-due:${String(W).padStart(16,"0")}:${J($)}`,scheduleRun:(W)=>`schedule-run:${J(W)}`,operation:(W,$,Z)=>`op:${W}:${N($)}:${Z}`,operationInflight:(W)=>`op:inflight:${W}`,operationQueued:(W)=>`op:queued:${W}`,operationResolved:(W)=>`op:resolved:${W}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(W,$,Z)=>`audit:bulk:${N(W)}:${J($)}:${J(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(W,$)=>`op:resolved-by-time:${N(W)}:${J($)}`,asyncActivity:(W,$)=>`async-act:v1:${J(W)}:${J($)}`,activityReconciliationPrefix:(W)=>`actrec:v1:${J(W)}:`,activityReconciliation:(W,$,Z)=>`actrec:v1:${J(W)}:${J($)}:${Z}`,eventPrefix:(W)=>`ev:${J(W)}:`,event:(W,$)=>`ev:${J(W)}:${String($).padStart(10,"0")}`,eventHead:(W)=>`ev:${J(W)}:head`,eventWatermark:(W)=>`ev:${J(W)}:watermark`,signal:(W,$,Z)=>`sig:${J(W)}:${$}:${J(Z)}`,signalSequence:(W)=>`sigseq:v1:${J(W)}`,signalAcceptedResponsePrefix:(W)=>`sigres:v1:${J(W)}:`,signalAcceptedResponse:(W,$,Z)=>`sigres:v1:${J(W)}:${J($)}:${J(Z)}`,deadline:(W,$)=>`wf-deadline:${N(W)}:${J($)}`,terminalCleanup:(W,$)=>`wf-cleanup:${N(W)}:${J($)}`,delayedStart:(W,$)=>`wf-delayed:${N(W)}:${J($)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(W,$)=>`wf-terminal:${N(W)}:${J($)}`,attribute:(W)=>`attr:${J(W)}`,attributeIndex:(W,$,Z)=>`idx:${W}:${$}:${J(Z)}`,tagIndex:(W,$)=>`tag:${J(W)}:${J($)}`,updatePrefix:(W)=>`upd:${J(W)}:`,update:(W,$)=>`upd:${J(W)}:${$}`,updateResponse:(W)=>`upr:${W}`,updateIdempotency:(W,$)=>`upk:${J(W)}:${$}`,startIdempotency:(W)=>`start-idem:${J(W)}`,startIdempotencySignalId:(W)=>`start-idem:${W}`,livenessPrefix:()=>"liveness:",liveness:(W)=>`liveness:${J(W)}`,budget:(W,$,Z)=>`budget:${W}:${$}:${Z}`,review:(W,$)=>`review:${J(W)}:${$}`,workflowHeaders:(W)=>`wf-headers:${J(W)}`,terminalCleanupNeeded:(W)=>`wf-cleanup-needed:${J(W)}`,workflowHasServices:(W)=>`wf-has-services:${J(W)}`,offload:(W,$)=>`offload:${J(W)}:${$}`,archive:(W,$)=>`archive:${J(W)}:${$}`,stateExecution:(W,$)=>`state:execution:${J(W)}:${J($)}`,stateWorkflow:(W,$)=>`state:workflow-scope:${f}:${J(W)}:${J($)}`,streamChunkPrefix:(W,$)=>`blob:${J(W)}:${$}:chunk:`,streamChunk:(W,$,Z)=>`blob:${J(W)}:${$}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(W,$)=>`blob:${J(W)}:${$}:meta`,budgetCharged:(W)=>`budget-charged:${W}`,toolEffect:(W,$,Z)=>`tool-effect:${J(W)}:${$}:${Z}`,workflowVisibilityStatus:(W,$)=>`wf-idx-status:${J(W)}:${J($)}`,workflowVisibilityType:(W,$)=>`wf-idx-type:${J(W)}:${J($)}`,workflowVisibilityCreated:(W,$)=>`wf-idx-created:${N(W)}:${J($)}`,workflowVisibilityUpdated:(W,$)=>`wf-idx-updated:${N(W)}:${J($)}`,workflowVisibilityDeadline:(W,$)=>`wf-idx-deadline:${N(W)}:${J($)}`,workflowVisibilityManifest:(W)=>`wf-idx-manifest:${J(W)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function qW(W){let $=W.length,Z=0,G=0;while(G<$){let Q=W.charCodeAt(G++);if((Q&4294967168)===0){Z++;continue}else if((Q&4294965248)===0)Z+=2;else{if(Q>=55296&&Q<=56319){if(G<$){let q=W.charCodeAt(G);if((q&64512)===56320)++G,Q=((Q&1023)<<10)+(q&1023)+65536}}if((Q&4294901760)===0)Z+=3;else Z+=4}}return Z}function lW(W,$,Z){let G=W.length,Q=Z,q=0;while(q<G){let F=W.charCodeAt(q++);if((F&4294967168)===0){$[Q++]=F;continue}else if((F&4294965248)===0)$[Q++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(q<G){let Y=W.charCodeAt(q);if((Y&64512)===56320)++q,F=((F&1023)<<10)+(Y&1023)+65536}}if((F&4294901760)===0)$[Q++]=F>>12&15|224,$[Q++]=F>>6&63|128;else $[Q++]=F>>18&7|240,$[Q++]=F>>12&63|128,$[Q++]=F>>6&63|128}$[Q++]=F&63|128}}function cW(W,$,Z){pW.encodeInto(W,$.subarray(Z))}function FW(W,$,Z){if(W.length>uW)cW(W,$,Z);else lW(W,$,Z)}function y(W,$,Z){let G=$,Q=G+Z,q=[],F="";while(G<Q){let Y=W[G++];if((Y&128)===0)q.push(Y);else if((Y&224)===192){let A=W[G++]&63;q.push((Y&31)<<6|A)}else if((Y&240)===224){let A=W[G++]&63,v=W[G++]&63;q.push((Y&31)<<12|A<<6|v)}else if((Y&248)===240){let A=W[G++]&63,v=W[G++]&63,mW=W[G++]&63,K=(Y&7)<<18|A<<12|v<<6|mW;if(K>65535)K-=65536,q.push(K>>>10&1023|55296),K=56320|K&1023;q.push(K)}else q.push(Y);if(q.length>=dW)F+=String.fromCharCode(...q),q.length=0}if(q.length>0)F+=String.fromCharCode(...q);return F}function rW(W,$,Z){let G=W.subarray($,$+Z);return nW.decode(G)}function XW(W,$,Z){if(Z>iW)return rW(W,$,Z);else return y(W,$,Z)}var pW,uW=50,dW=4096,nW,iW=200;var x=X(()=>{pW=new TextEncoder;nW=new TextDecoder});class O{type;data;constructor(W,$){this.type=W,this.data=$}}var V;var l=X(()=>{V=class V extends Error{constructor(W){super(W);let $=Object.create(V.prototype);Object.setPrototypeOf(this,$),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:V.name})}}});function HW(W,$,Z){let G=Z/4294967296,Q=Z;W.setUint32($,G),W.setUint32($+4,Q)}function C(W,$,Z){let G=Math.floor(Z/4294967296),Q=Z;W.setUint32($,G),W.setUint32($+4,Q)}function S(W,$){let Z=W.getInt32($),G=W.getUint32($+4);return Z*4294967296+G}function YW(W,$){let Z=W.getUint32($),G=W.getUint32($+4);return Z*4294967296+G}var B=4294967295;function tW({sec:W,nsec:$}){if(W>=0&&$>=0&&W<=oW)if($===0&&W<=aW){let Z=new Uint8Array(4);return new DataView(Z.buffer).setUint32(0,W),Z}else{let Z=W/4294967296,G=W&4294967295,Q=new Uint8Array(8),q=new DataView(Q.buffer);return q.setUint32(0,$<<2|Z&3),q.setUint32(4,G),Q}else{let Z=new Uint8Array(12),G=new DataView(Z.buffer);return G.setUint32(0,$),C(G,4,W),Z}}function eW(W){let $=W.getTime(),Z=Math.floor($/1000),G=($-Z*1000)*1e6,Q=Math.floor(G/1e9);return{sec:Z+Q,nsec:G-Q*1e9}}function W0(W){if(W instanceof Date){let $=eW(W);return tW($)}else return null}function $0(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength);switch(W.byteLength){case 4:{let Z=$.getUint32(0),G=0;return{sec:Z,nsec:0}}case 8:{let Z=$.getUint32(0),G=$.getUint32(4),Q=(Z&3)*4294967296+G,q=Z>>>2;return{sec:Q,nsec:q}}case 12:{let Z=S($,4),G=$.getUint32(0);return{sec:Z,nsec:G}}default:throw new V(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${W.length}`)}}function Z0(W){let $=$0(W);return new Date($.sec*1000+$.nsec/1e6)}var sW=-1,aW=4294967295,oW=17179869183,VW;var PW=X(()=>{l();VW={type:sW,encode:W0,decode:Z0}});var U;var E=X(()=>{PW();U=class U{static defaultCodec=new U;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(VW)}register({type:W,encode:$,decode:Z}){if(W>=0)this.encoders[W]=$,this.decoders[W]=Z;else{let G=-1-W;this.builtInEncoders[G]=$,this.builtInDecoders[G]=Z}}tryToEncode(W,$){for(let Z=0;Z<this.builtInEncoders.length;Z++){let G=this.builtInEncoders[Z];if(G!=null){let Q=G(W,$);if(Q!=null){let q=-1-Z;return new O(q,Q)}}}for(let Z=0;Z<this.encoders.length;Z++){let G=this.encoders[Z];if(G!=null){let Q=G(W,$);if(Q!=null)return new O(Z,Q)}}if(W instanceof O)return W;return null}decode(W,$,Z){let G=$<0?this.builtInDecoders[-1-$]:this.decoders[$];if(G)return G(W,$,Z);else return new O($,W)}}});function G0(W){return W instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&W instanceof SharedArrayBuffer}function D(W){if(W instanceof Uint8Array)return W;else if(ArrayBuffer.isView(W))return new Uint8Array(W.buffer,W.byteOffset,W.byteLength);else if(G0(W))return new Uint8Array(W);else return Uint8Array.from(W)}class k{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??U.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.maxDepth=W?.maxDepth??Q0,this.initialBufferSize=W?.initialBufferSize??J0,this.sortKeys=W?.sortKeys??!1,this.forceFloat32=W?.forceFloat32??!1,this.ignoreUndefined=W?.ignoreUndefined??!1,this.forceIntegerToFloat=W?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new k({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(W){if(this.entered)return this.clone().encodeSharedRef(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(W){if(this.entered)return this.clone().encode(W);try{return this.entered=!0,this.reinitializeState(),this.doEncode(W,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(W,$){if($>this.maxDepth)throw Error(`Too deep objects in depth ${$}`);if(W==null)this.encodeNil();else if(typeof W==="boolean")this.encodeBoolean(W);else if(typeof W==="number")if(!this.forceIntegerToFloat)this.encodeNumber(W);else this.encodeNumberAsFloat(W);else if(typeof W==="string")this.encodeString(W);else if(this.useBigInt64&&typeof W==="bigint")this.encodeBigInt64(W);else this.encodeObject(W,$)}ensureBufferSizeToWrite(W){let $=this.pos+W;if(this.view.byteLength<$)this.resizeBuffer($*2)}resizeBuffer(W){let $=new ArrayBuffer(W),Z=new Uint8Array($),G=new DataView($);Z.set(this.bytes),this.view=G,this.bytes=Z}encodeNil(){this.writeU8(192)}encodeBoolean(W){if(W===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber(W){if(!this.forceIntegerToFloat&&Number.isSafeInteger(W))if(W>=0)if(W<128)this.writeU8(W);else if(W<256)this.writeU8(204),this.writeU8(W);else if(W<65536)this.writeU8(205),this.writeU16(W);else if(W<4294967296)this.writeU8(206),this.writeU32(W);else if(!this.useBigInt64)this.writeU8(207),this.writeU64(W);else this.encodeNumberAsFloat(W);else if(W>=-32)this.writeU8(224|W+32);else if(W>=-128)this.writeU8(208),this.writeI8(W);else if(W>=-32768)this.writeU8(209),this.writeI16(W);else if(W>=-2147483648)this.writeU8(210),this.writeI32(W);else if(!this.useBigInt64)this.writeU8(211),this.writeI64(W);else this.encodeNumberAsFloat(W);else this.encodeNumberAsFloat(W)}encodeNumberAsFloat(W){if(this.forceFloat32)this.writeU8(202),this.writeF32(W);else this.writeU8(203),this.writeF64(W)}encodeBigInt64(W){if(W>=BigInt(0))this.writeU8(207),this.writeBigUint64(W);else this.writeU8(211),this.writeBigInt64(W)}writeStringHeader(W){if(W<32)this.writeU8(160+W);else if(W<256)this.writeU8(217),this.writeU8(W);else if(W<65536)this.writeU8(218),this.writeU16(W);else if(W<4294967296)this.writeU8(219),this.writeU32(W);else throw Error(`Too long string: ${W} bytes in UTF-8`)}encodeString(W){let Z=qW(W);this.ensureBufferSizeToWrite(5+Z),this.writeStringHeader(Z),FW(W,this.bytes,this.pos),this.pos+=Z}encodeObject(W,$){let Z=this.extensionCodec.tryToEncode(W,this.context);if(Z!=null)this.encodeExtension(Z);else if(Array.isArray(W))this.encodeArray(W,$);else if(ArrayBuffer.isView(W))this.encodeBinary(W);else if(typeof W==="object")this.encodeMap(W,$);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply(W)}`)}encodeBinary(W){let $=W.byteLength;if($<256)this.writeU8(196),this.writeU8($);else if($<65536)this.writeU8(197),this.writeU16($);else if($<4294967296)this.writeU8(198),this.writeU32($);else throw Error(`Too large binary: ${$}`);let Z=D(W);this.writeU8a(Z)}encodeArray(W,$){let Z=W.length;if(Z<16)this.writeU8(144+Z);else if(Z<65536)this.writeU8(220),this.writeU16(Z);else if(Z<4294967296)this.writeU8(221),this.writeU32(Z);else throw Error(`Too large array: ${Z}`);for(let G of W)this.doEncode(G,$+1)}countWithoutUndefined(W,$){let Z=0;for(let G of $)if(W[G]!==void 0)Z++;return Z}encodeMap(W,$){let Z=Object.keys(W);if(this.sortKeys)Z.sort();let G=this.ignoreUndefined?this.countWithoutUndefined(W,Z):Z.length;if(G<16)this.writeU8(128+G);else if(G<65536)this.writeU8(222),this.writeU16(G);else if(G<4294967296)this.writeU8(223),this.writeU32(G);else throw Error(`Too large map object: ${G}`);for(let Q of Z){let q=W[Q];if(!(this.ignoreUndefined&&q===void 0))this.encodeString(Q),this.doEncode(q,$+1)}}encodeExtension(W){if(typeof W.data==="function"){let Z=W.data(this.pos+6),G=Z.length;if(G>=4294967296)throw Error(`Too large extension object: ${G}`);this.writeU8(201),this.writeU32(G),this.writeI8(W.type),this.writeU8a(Z);return}let $=W.data.length;if($===1)this.writeU8(212);else if($===2)this.writeU8(213);else if($===4)this.writeU8(214);else if($===8)this.writeU8(215);else if($===16)this.writeU8(216);else if($<256)this.writeU8(199),this.writeU8($);else if($<65536)this.writeU8(200),this.writeU16($);else if($<4294967296)this.writeU8(201),this.writeU32($);else throw Error(`Too large extension object: ${$}`);this.writeI8(W.type),this.writeU8a(W.data)}writeU8(W){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,W),this.pos++}writeU8a(W){let $=W.length;this.ensureBufferSizeToWrite($),this.bytes.set(W,this.pos),this.pos+=$}writeI8(W){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,W),this.pos++}writeU16(W){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,W),this.pos+=2}writeI16(W){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,W),this.pos+=2}writeU32(W){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,W),this.pos+=4}writeI32(W){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,W),this.pos+=4}writeF32(W){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,W),this.pos+=4}writeF64(W){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,W),this.pos+=8}writeU64(W){this.ensureBufferSizeToWrite(8),HW(this.view,this.pos,W),this.pos+=8}writeI64(W){this.ensureBufferSizeToWrite(8),C(this.view,this.pos,W),this.pos+=8}writeBigUint64(W){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,W),this.pos+=8}writeBigInt64(W){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,W),this.pos+=8}}var Q0=100,J0=2048;var NW=X(()=>{x();E()});function R(W,$){return new k($).encodeSharedRef(W)}var RW=X(()=>{NW()});function w(W){return`${W<0?"-":""}0x${Math.abs(W).toString(16).padStart(2,"0")}`}class p{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor(W=q0,$=F0){this.maxKeyLength=W,this.maxLengthPerKey=$,this.caches=[];for(let Z=0;Z<this.maxKeyLength;Z++)this.caches.push([])}canBeCached(W){return W>0&&W<=this.maxKeyLength}find(W,$,Z){let G=this.caches[Z-1];W:for(let Q of G){let q=Q.bytes;for(let F=0;F<Z;F++)if(q[F]!==W[$+F])continue W;return Q.str}return null}store(W,$){let Z=this.caches[W.length-1],G={bytes:W,str:$};if(Z.length>=this.maxLengthPerKey)Z[Math.random()*Z.length|0]=G;else Z.push(G)}decode(W,$,Z){let G=this.find(W,$,Z);if(G!=null)return this.hit++,G;this.miss++;let Q=y(W,$,Z),q=Uint8Array.prototype.slice.call(W,$,$+Z);return this.store(q,Q),Q}}var q0=16,F0=16;var MW=X(()=>{x()});class KW{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(W){let $=this.getUninitializedStateFromPool();$.type=u,$.position=0,$.size=W,$.array=Array(W)}pushMapState(W){let $=this.getUninitializedStateFromPool();$.type=T,$.readCount=0,$.size=W,$.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let W={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(W)}return this.stack[this.stackHeadPosition]}release(W){if(this.stack[this.stackHeadPosition]!==W)throw Error("Invalid stack state. Released state is not on top of the stack.");if(W.type===u){let Z=W;Z.size=0,Z.array=void 0,Z.position=0,Z.type=void 0}if(W.type===T||W.type===_W){let Z=W;Z.size=0,Z.map=void 0,Z.readCount=0,Z.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class j{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=c;bytes=H0;headByte=L;stack=new KW;entered=!1;constructor(W){this.extensionCodec=W?.extensionCodec??U.defaultCodec,this.context=W?.context,this.useBigInt64=W?.useBigInt64??!1,this.rawStrings=W?.rawStrings??!1,this.maxStrLength=W?.maxStrLength??B,this.maxBinLength=W?.maxBinLength??B,this.maxArrayLength=W?.maxArrayLength??B,this.maxMapLength=W?.maxMapLength??B,this.maxExtLength=W?.maxExtLength??B,this.keyDecoder=W?.keyDecoder!==void 0?W.keyDecoder:Y0,this.mapKeyConverter=W?.mapKeyConverter??X0}clone(){return new j({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=L,this.stack.reset()}setBuffer(W){let $=D(W);this.bytes=$,this.view=new DataView($.buffer,$.byteOffset,$.byteLength),this.pos=0}appendBuffer(W){if(this.headByte===L&&!this.hasRemaining(1))this.setBuffer(W);else{let $=this.bytes.subarray(this.pos),Z=D(W),G=new Uint8Array($.length+Z.length);G.set($),G.set(Z,$.length),this.setBuffer(G)}}hasRemaining(W){return this.view.byteLength-this.pos>=W}createExtraByteError(W){let{view:$,pos:Z}=this;return RangeError(`Extra ${$.byteLength-Z} of ${$.byteLength} byte(s) found at buffer[${W}]`)}decode(W){if(this.entered)return this.clone().decode(W);try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);let $=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return $}finally{this.entered=!1}}*decodeMulti(W){if(this.entered){yield*this.clone().decodeMulti(W);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer(W);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(W){if(this.entered)return this.clone().decodeAsync(W);try{this.entered=!0;let $=!1,Z;for await(let F of W){if($)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Z=this.doDecodeSync(),$=!0}catch(Y){if(!(Y instanceof RangeError))throw Y}this.totalPos+=this.pos}if($){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Z}let{headByte:G,pos:Q,totalPos:q}=this;throw RangeError(`Insufficient data in parsing ${w(G)} at ${q} (${Q} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(W){return this.decodeMultiAsync(W,!0)}decodeStream(W){return this.decodeMultiAsync(W,!1)}async*decodeMultiAsync(W,$){if(this.entered){yield*this.clone().decodeMultiAsync(W,$);return}try{this.entered=!0;let Z=$,G=-1;for await(let Q of W){if($&&G===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(Q),Z)G=this.readArraySize(),Z=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--G===0)break}catch(q){if(!(q instanceof RangeError))throw q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){W:while(!0){let W=this.readHeadByte(),$;if(W>=224)$=W-256;else if(W<192)if(W<128)$=W;else if(W<144){let G=W-128;if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W<160){let G=W-144;if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else{let G=W-160;$=this.decodeString(G,0)}else if(W===192)$=null;else if(W===194)$=!1;else if(W===195)$=!0;else if(W===202)$=this.readF32();else if(W===203)$=this.readF64();else if(W===204)$=this.readU8();else if(W===205)$=this.readU16();else if(W===206)$=this.readU32();else if(W===207)if(this.useBigInt64)$=this.readU64AsBigInt();else $=this.readU64();else if(W===208)$=this.readI8();else if(W===209)$=this.readI16();else if(W===210)$=this.readI32();else if(W===211)if(this.useBigInt64)$=this.readI64AsBigInt();else $=this.readI64();else if(W===217){let G=this.lookU8();$=this.decodeString(G,1)}else if(W===218){let G=this.lookU16();$=this.decodeString(G,2)}else if(W===219){let G=this.lookU32();$=this.decodeString(G,4)}else if(W===220){let G=this.readU16();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===221){let G=this.readU32();if(G!==0){this.pushArrayState(G),this.complete();continue W}else $=[]}else if(W===222){let G=this.readU16();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===223){let G=this.readU32();if(G!==0){this.pushMapState(G),this.complete();continue W}else $={}}else if(W===196){let G=this.lookU8();$=this.decodeBinary(G,1)}else if(W===197){let G=this.lookU16();$=this.decodeBinary(G,2)}else if(W===198){let G=this.lookU32();$=this.decodeBinary(G,4)}else if(W===212)$=this.decodeExtension(1,0);else if(W===213)$=this.decodeExtension(2,0);else if(W===214)$=this.decodeExtension(4,0);else if(W===215)$=this.decodeExtension(8,0);else if(W===216)$=this.decodeExtension(16,0);else if(W===199){let G=this.lookU8();$=this.decodeExtension(G,1)}else if(W===200){let G=this.lookU16();$=this.decodeExtension(G,2)}else if(W===201){let G=this.lookU32();$=this.decodeExtension(G,4)}else throw new V(`Unrecognized type byte: ${w(W)}`);this.complete();let Z=this.stack;while(Z.length>0){let G=Z.top();if(G.type===u)if(G.array[G.position]=$,G.position++,G.position===G.size)$=G.array,Z.release(G);else continue W;else if(G.type===T){if($==="__proto__")throw new V("The key __proto__ is not allowed");G.key=this.mapKeyConverter($),G.type=_W;continue W}else if(G.map[G.key]=$,G.readCount++,G.readCount===G.size)$=G.map,Z.release(G);else{G.key=null,G.type=T;continue W}}return $}}readHeadByte(){if(this.headByte===L)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=L}readArraySize(){let W=this.readHeadByte();switch(W){case 220:return this.readU16();case 221:return this.readU32();default:if(W<160)return W-144;else throw new V(`Unrecognized array type byte: ${w(W)}`)}}pushMapState(W){if(W>this.maxMapLength)throw new V(`Max length exceeded: map length (${W}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(W)}pushArrayState(W){if(W>this.maxArrayLength)throw new V(`Max length exceeded: array length (${W}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(W)}decodeString(W,$){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String(W,$);return this.decodeBinary(W,$)}decodeUtf8String(W,$){if(W>this.maxStrLength)throw new V(`Max length exceeded: UTF-8 byte length (${W}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+$+W)throw UW;let Z=this.pos+$,G;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached(W))G=this.keyDecoder.decode(this.bytes,Z,W);else G=XW(this.bytes,Z,W);return this.pos+=$+W,G}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===T;return!1}decodeBinary(W,$){if(W>this.maxBinLength)throw new V(`Max length exceeded: bin length (${W}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(W+$))throw UW;let Z=this.pos+$,G=this.bytes.subarray(Z,Z+W);return this.pos+=$+W,G}decodeExtension(W,$){if(W>this.maxExtLength)throw new V(`Max length exceeded: ext length (${W}) > maxExtLength (${this.maxExtLength})`);let Z=this.view.getInt8(this.pos+$),G=this.decodeBinary(W,$+1);return this.extensionCodec.decode(G,Z,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let W=this.view.getUint8(this.pos);return this.pos++,W}readI8(){let W=this.view.getInt8(this.pos);return this.pos++,W}readU16(){let W=this.view.getUint16(this.pos);return this.pos+=2,W}readI16(){let W=this.view.getInt16(this.pos);return this.pos+=2,W}readU32(){let W=this.view.getUint32(this.pos);return this.pos+=4,W}readI32(){let W=this.view.getInt32(this.pos);return this.pos+=4,W}readU64(){let W=YW(this.view,this.pos);return this.pos+=8,W}readI64(){let W=S(this.view,this.pos);return this.pos+=8,W}readU64AsBigInt(){let W=this.view.getBigUint64(this.pos);return this.pos+=8,W}readI64AsBigInt(){let W=this.view.getBigInt64(this.pos);return this.pos+=8,W}readF32(){let W=this.view.getFloat32(this.pos);return this.pos+=4,W}readF64(){let W=this.view.getFloat64(this.pos);return this.pos+=8,W}}var u="array",T="map_key",_W="map_value",X0=(W)=>{if(typeof W==="string"||typeof W==="number")return W;throw new V("The type of key must be string or number but "+typeof W)},L=-1,c,H0,UW,Y0;var OW=X(()=>{E();x();MW();l();c=new DataView(new ArrayBuffer(0)),H0=new Uint8Array(c.buffer);try{c.getInt8(0)}catch(W){if(!(W instanceof RangeError))throw Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}UW=RangeError("Insufficient data"),Y0=new p});function M(W,$){return new j($).decode(W)}var BW=X(()=>{OW()});var h=X(()=>{RW();BW();E()});function d(W){if(typeof W==="object"&&W!==null&&!Array.isArray(W))return W;return{}}function m(W){return Array.isArray(W)?W:[]}function AW(W){if(!(W instanceof Date))return null;let $=new ArrayBuffer(8);return new DataView($).setFloat64(0,W.getTime()),new Uint8Array($)}function zW(W){let $=new DataView(W.buffer,W.byteOffset,W.byteLength).getFloat64(0);return new Date($)}function n(W){return DW.has(W.constructor)}function LW(W,$){W.register({type:V0,encode(Z){if(typeof Z!=="object"||Z===null)return null;let G=DW.get(Z.constructor);if(G===void 0)return null;let Q=$(G.handlers.toJSON(Z),new Set);return R({tag:G.tag,data:Q},{extensionCodec:W})},decode(Z){let G=M(Z,{extensionCodec:W});if(typeof G!=="object"||G===null||!("tag"in G))throw Error("Corrupt custom-serializer payload: missing tag.");let{tag:Q,data:q}=G;if(typeof Q!=="string")throw Error("Corrupt custom-serializer payload: tag is not a string.");let F=P0.get(Q);if(F===void 0)throw Error(`No serializer registered for tag "${Q}". Register it (with the same tag) before decoding a checkpoint that used it.`);return F.handlers.fromJSON(q)}})}var V0=100,DW,P0;var TW=X(()=>{h();DW=new Map,P0=new Map});function B0(W){return typeof W==="object"&&W!==null&&"__tag"in W&&W.__tag===IW}function _(W,$){if(W===void 0)return O0;if(W===null||typeof W!=="object")return W;if($.has(W))return W;$.add(W);try{return A0(W,$)}finally{$.delete(W)}}function A0(W,$){if(Array.isArray(W))return z0(W,$);if(W instanceof Map)return D0(W,$);if(W instanceof Set)return L0(W,$);if(T0(W))return W;return I0(W,$)}function z0(W,$){let Z=Array.from({length:W.length});for(let G=0;G<W.length;G++)Z[G]=_(W[G],$);return Z}function D0(W,$){let Z=new Map;for(let[G,Q]of W)Z.set(_(G,$),_(Q,$));return Z}function L0(W,$){let Z=new Set;for(let G of W)Z.add(_(G,$));return Z}function T0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer||n(W)}function I0(W,$){let Z=W,G={};for(let Q of Object.keys(Z))G[Q]=_(Z[Q],$);return G}var N0=1,R0=2,M0=3,U0=4,_0=5,K0=6,P,IW,O0;var xW=X(()=>{h();TW();P=new U;LW(P,_);P.register({type:N0,encode:AW,decode:zW});P.register({type:R0,encode(W){if(W instanceof RegExp)return R({source:W.source,flags:W.flags});return null},decode(W){let $=d(M(W)),Z=typeof $.source==="string"?$.source:"",G=typeof $.flags==="string"?$.flags:"";return new RegExp(Z,G)}});P.register({type:M0,encode(W){if(W instanceof Map){let $=[...W.entries()];return R($,{extensionCodec:P})}return null},decode(W){let Z=m(M(W,{extensionCodec:P})).map((G)=>{let Q=m(G);return[Q[0],Q[1]]});return new Map(Z)}});P.register({type:U0,encode(W){if(W instanceof Set){let $=[...W.values()];return R($,{extensionCodec:P})}return null},decode(W){let $=m(M(W,{extensionCodec:P}));return new Set($)}});IW=Symbol("UndefinedSentinel"),O0=Object.freeze({__tag:IW});P.register({type:_0,encode(W){if(B0(W))return new Uint8Array(0);return null},decode(){return}});P.register({type:K0,encode(W){if(W instanceof Error&&!n(W))return R({name:W.name,message:W.message,stack:W.stack});return null},decode(W){let $=d(M(W)),Z=typeof $.name==="string"?$.name:"Error",G=typeof $.message==="string"?$.message:"",Q=typeof $.stack==="string"?$.stack:void 0,q=Error(G);if(q.name=Z,Q!==void 0)q.stack=Q;return q}})});function i(W){let $=_(W,new Set);return R($,{extensionCodec:P})}function r(W){return M(W,{extensionCodec:P})}var CW=X(()=>{h();xW()});function g(W,$=""){let Z=[];return I(W,$,Z,new Set),{valid:Z.length===0,errors:Z}}function x0(W){let $=Object.getPrototypeOf(W);return C0($)&&!S0(W)&&E0($)}function C0(W){return W!==Object.prototype&&W!==null}function S0(W){return Array.isArray(W)||W instanceof Date||W instanceof RegExp||W instanceof Map||W instanceof Set||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function E0(W){if(typeof W!=="object"||W===null)return!1;return Object.getOwnPropertyNames(W).some((Z)=>{if(Z==="constructor")return!1;let G=Object.getOwnPropertyDescriptor(W,Z);return G!==void 0&&typeof G.value==="function"})}function SW(W,$,Z,G){W.push({path:$,value:Z,reason:G.reason,suggestion:G.suggestion})}function k0(W){if(typeof W==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof W==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function w0(W,$){if(W instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if(W instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if(W instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if($.has(W))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(x0(W))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function j0(W){return W instanceof Date||W instanceof RegExp||W instanceof Error||W instanceof Uint8Array||W instanceof ArrayBuffer}function h0(W,$,Z,G){for(let[Q,q]of W){let F=String(Q);I(q,$?`${$}.${F}`:F,Z,G)}}function m0(W,$,Z,G){let Q=0;for(let q of W){let F=$?`${$}[${Q}]`:`[${Q}]`;I(q,F,Z,G),Q++}}function g0(W,$,Z,G){for(let Q=0;Q<W.length;Q++){let q=$?`${$}[${Q}]`:`[${Q}]`;I(W[Q],q,Z,G)}}function v0(W,$,Z,G){for(let Q of Object.keys(W)){let q=$?`${$}.${Q}`:Q;I(W[Q],q,Z,G)}}function I(W,$,Z,G){if(W===null||W===void 0)return;let Q=k0(W);if(Q){SW(Z,$,W,Q);return}if(typeof W!=="object")return;let q=w0(W,G);if(q){SW(Z,$,W,q);return}G.add(W);try{if(j0(W))return;if(W instanceof Map){h0(W,$,Z,G);return}if(W instanceof Set){m0(W,$,Z,G);return}if(Array.isArray(W)){g0(W,$,Z,G);return}v0(W,$,Z,G)}finally{G.delete(W)}}var EW=X(()=>{CW()});var kW=X(()=>{EW()});function b0(W){if(W===void 0)return;if(typeof W!=="number"||!Number.isInteger(W)||W<0)throw Error("deleteRange limit must be a finite non-negative integer");return W===0?0:W}function f0(W){let $={},Z=!1;for(let Q of["gt","gte","lt","lte"]){let q=W[Q];if(q===void 0)continue;if(typeof q!=="string")throw Error("deleteRange bounds must be strings");$[Q]=q,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let G=b0(W.limit);if(G!==void 0)$.limit=G;return $}async function wW(W,$,Z){let G=f0(Z);if(W.deleteRange)return W.deleteRange($,G);return t(W,$,G)}var jW=()=>{};kW();jW();JW();class hW{#W;#$;#Z;constructor(W,$,Z={}){this.#W=W,this.#$=$,this.#Z=Z.disposeUnderlyingStorage??!0}async get(W){let $=await this.#W.get(W);return $===null?null:this.#$.decode($)}async put(W,$){await this.#W.put(W,this.#$.encode($))}async delete(W){await this.#W.delete(W)}async*scan(W,$){for await(let[Z,G]of this.#W.scan(W,$))yield[Z,this.#$.decode(G)]}async batch(W){await this.#W.batch(this.#G(W))}#G(W){return W.map((Z)=>{if(Z.type==="put")return{type:"put",key:Z.key,value:this.#$.encode(Z.value)};return Z})}#Q(W){return W.map(($)=>({key:$.key,expectedValue:$.expectedValue===null?null:this.#$.encode($.expectedValue)}))}async conditionalBatch(W,$){return QW(this.#W,this.#Q(W),this.#G($))}async has(W){return WW(this.#W,W)}async deletePrefix(W){return GW(this.#W,W)}async deleteRange(W,$){return wW(this.#W,W,$)}keys(W,$){return $W(this.#W,W,$)}async count(W){return ZW(this.#W,W)}[Symbol.dispose](){if(!this.#Z)return;this.#W[Symbol.dispose]()}}function w6(W,$,Z={}){return new hW(W,$,Z)}function y0(W){try{let $=JSON.stringify(W);if($===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode($)}catch($){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:$})}}function l0(W){let $=g(W);if(!$.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${$.errors[0]?.reason??""}`.trim());return i(W)}function p0(W){return JSON.parse(new TextDecoder().decode(W))}function u0(W){let $=r(W),Z=g($);if(!Z.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Z.errors[0]?.reason??""}`.trim());return $}function j6(W){return{encode($){return y0($)},decode($){let Z=p0($);return W?W(Z):Z}}}function h6(W){return{encode($){return l0($)},decode($){let Z=u0($);return W?W(Z):Z}}}export{w6 as withCodec,h6 as msgpackCodec,j6 as jsonCodec};
@@ -1 +1 @@
1
- var p=Object.defineProperty;var s=(J)=>J;function a(J,X){this[J]=s.bind(null,X)}var UJ=(J,X)=>{for(var Z in X)p(J,Z,{get:X[Z],enumerable:!0,configurable:!0,set:a.bind(X,Z)})};function K(J){let X=[];for(let Z=0;Z<J.length;Z+=512)X.push(String.fromCharCode(...J.subarray(Z,Z+512)));return btoa(X.join(""))}function b(J){let X=atob(J),Z=new Uint8Array(X.length);for(let F=0;F<X.length;F+=1)Z[F]=X.charCodeAt(F);return Z}function B(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}async function _(J,X){return await J.get(X)!==null}async function*M(J,X,Z){for await(let[F]of J.scan(X,Z))yield F}async function L(J,X){let Z=0;for await(let F of M(J,X))Z++;return Z}async function D(J,X){let Z=[];for await(let F of M(J,X))Z.push({type:"delete",key:F});if(Z.length===0)return 0;return await J.batch(Z),Z.length}async function W(J,X,Z){let F=[];for await(let V of M(J,X,Z))F.push({type:"delete",key:V});if(F.length===0)return 0;return await J.batch(F),F.length}function O(J,X,Z){if(!J.capabilities()[X])throw Error(`Feature "${Z}" requires storage capability "${X}", but this storage backend does not provide it.`)}var I="default";function S(J){return J.length>0?J.slice(0,-1)+String.fromCharCode(J.charCodeAt(J.length-1)+1):"ÿ"}function x(J,X={}){if(X.gt!==void 0&&J<=X.gt)return!1;if(X.gte!==void 0&&J<X.gte)return!1;if(X.lt!==void 0&&J>=X.lt)return!1;if(X.lte!==void 0&&J>X.lte)return!1;return!0}function WJ(J,X){if(J===null||X===null)return J===X;if(J.byteLength!==X.byteLength)return!1;for(let Z=0;Z<J.byteLength;Z++)if(J[Z]!==X[Z])return!1;return!0}async function v(J,X){if(J.has)return J.has(X);return _(J,X)}function w(J,X,Z){if(J.keys)return J.keys(X,Z);return M(J,X,Z)}async function u(J,X){if(J.count)return J.count(X);return L(J,X)}async function m(J,X){if(J.deletePrefix)return J.deletePrefix(X);return D(J,X)}async function k(J,X,Z){if(O(J,"conditionalBatch","storageConditionalBatch"),!J.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return J.conditionalBatch(X,Z)}function $(J){return encodeURIComponent(J)}function zJ(J){try{return decodeURIComponent(J)}catch{return null}}var G=(J)=>String(J).padStart(16,"0"),BJ={workflow:(J)=>`wf:${$(J)}`,checkpoint:(J)=>`wf:${$(J)}:ckpt`,checkpointHistory:(J,X)=>`wf:${$(J)}:ckpt:${String(X).padStart(10,"0")}`,timelinePrefix:(J)=>`wf:${$(J)}:timeline:`,timeline:(J,X)=>`wf:${$(J)}:timeline:${String(X).padStart(10,"0")}`,schedule:(J)=>`schedule:${$(J)}`,scheduleTick:(J,X)=>`schedule-due:${String(J).padStart(16,"0")}:${$(X)}`,scheduleRun:(J)=>`schedule-run:${$(J)}`,operation:(J,X,Z)=>`op:${J}:${G(X)}:${Z}`,operationInflight:(J)=>`op:inflight:${J}`,operationQueued:(J)=>`op:queued:${J}`,operationResolved:(J)=>`op:resolved:${J}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(J,X,Z)=>`audit:bulk:${G(J)}:${$(X)}:${$(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(J,X)=>`op:resolved-by-time:${G(J)}:${$(X)}`,asyncActivity:(J,X)=>`async-act:v1:${$(J)}:${$(X)}`,activityReconciliationPrefix:(J)=>`actrec:v1:${$(J)}:`,activityReconciliation:(J,X,Z)=>`actrec:v1:${$(J)}:${$(X)}:${Z}`,eventPrefix:(J)=>`ev:${$(J)}:`,event:(J,X)=>`ev:${$(J)}:${String(X).padStart(10,"0")}`,eventHead:(J)=>`ev:${$(J)}:head`,eventWatermark:(J)=>`ev:${$(J)}:watermark`,signal:(J,X,Z)=>`sig:${$(J)}:${X}:${$(Z)}`,signalSequence:(J)=>`sigseq:v1:${$(J)}`,signalAcceptedResponsePrefix:(J)=>`sigres:v1:${$(J)}:`,signalAcceptedResponse:(J,X,Z)=>`sigres:v1:${$(J)}:${$(X)}:${$(Z)}`,deadline:(J,X)=>`wf-deadline:${G(J)}:${$(X)}`,terminalCleanup:(J,X)=>`wf-cleanup:${G(J)}:${$(X)}`,delayedStart:(J,X)=>`wf-delayed:${G(J)}:${$(X)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(J,X)=>`wf-terminal:${G(J)}:${$(X)}`,attribute:(J)=>`attr:${$(J)}`,attributeIndex:(J,X,Z)=>`idx:${J}:${X}:${$(Z)}`,tagIndex:(J,X)=>`tag:${$(J)}:${$(X)}`,updatePrefix:(J)=>`upd:${$(J)}:`,update:(J,X)=>`upd:${$(J)}:${X}`,updateResponse:(J)=>`upr:${J}`,updateIdempotency:(J,X)=>`upk:${$(J)}:${X}`,budget:(J,X,Z)=>`budget:${J}:${X}:${Z}`,review:(J,X)=>`review:${$(J)}:${X}`,workflowHeaders:(J)=>`wf-headers:${$(J)}`,terminalCleanupNeeded:(J)=>`wf-cleanup-needed:${$(J)}`,offload:(J,X)=>`offload:${$(J)}:${X}`,archive:(J,X)=>`archive:${$(J)}:${X}`,stateExecution:(J,X)=>`state:execution:${$(J)}:${$(X)}`,stateWorkflow:(J,X)=>`state:workflow-scope:${I}:${$(J)}:${$(X)}`,streamChunkPrefix:(J,X)=>`blob:${$(J)}:${X}:chunk:`,streamChunk:(J,X,Z)=>`blob:${$(J)}:${X}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(J,X)=>`blob:${$(J)}:${X}:meta`,budgetCharged:(J)=>`budget-charged:${J}`,toolEffect:(J,X,Z)=>`tool-effect:${$(J)}:${X}:${Z}`,workflowVisibilityStatus:(J,X)=>`wf-idx-status:${$(J)}:${$(X)}`,workflowVisibilityType:(J,X)=>`wf-idx-type:${$(J)}:${$(X)}`,workflowVisibilityCreated:(J,X)=>`wf-idx-created:${G(J)}:${$(X)}`,workflowVisibilityUpdated:(J,X)=>`wf-idx-updated:${G(J)}:${$(X)}`,workflowVisibilityDeadline:(J,X)=>`wf-idx-deadline:${G(J)}:${$(X)}`,workflowVisibilityManifest:(J)=>`wf-idx-manifest:${$(J)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function i(J){if(J===void 0)return;if(typeof J!=="number"||!Number.isInteger(J)||J<0)throw Error("deleteRange limit must be a finite non-negative integer");return J===0?0:J}function N(J){let X={},Z=!1;for(let V of["gt","gte","lt","lte"]){let H=J[V];if(H===void 0)continue;if(typeof H!=="string")throw Error("deleteRange bounds must be strings");X[V]=H,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let F=i(J.limit);if(F!==void 0)X.limit=F;return X}async function f(J,X,Z){let F=N(Z);if(J.deleteRange)return J.deleteRange(X,F);return W(J,X,F)}function n(J,X){let Z={key:J,open:!1};if(X.gte!==void 0&&X.gte>Z.key)Z.key=X.gte,Z.open=!1;if(X.gt!==void 0&&X.gt>=Z.key)Z.key=X.gt,Z.open=!0;return Z}function r(J,X){let Z={key:S(J),open:!0};if(X.lt!==void 0&&X.lt<=Z.key)Z.key=X.lt,Z.open=!0;if(X.lte!==void 0&&X.lte<Z.key)Z.key=X.lte,Z.open=!1;return Z}function TJ(J,X){let Z=n(J,X),F=r(J,X);if(Z.key>F.key||Z.key===F.key&&(Z.open||F.open))return null;return{lower:Z,upper:F}}function A(J){return J.replaceAll(/:+$/g,"")}function t(J,X){let Z=A(J),F=A(X);if(Z.length===0)return F;if(F.length===0)return Z;return`${Z}:${F}`}class R{#X;#Z;constructor(J,X){this.#X=J,this.#Z=A(X)}#J(J){if(this.#Z.length===0)return J;return J.length===0?`${this.#Z}:`:`${this.#Z}:${J}`}#$(J){if(this.#Z.length===0)return J;return J.slice(this.#Z.length+1)}#F(J={}){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.reverse!==void 0)X.reverse=J.reverse;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}#H(J){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}capabilities(){return this.#X.capabilities()}scoped(J){return new R(this.#X,t(this.#Z,J))}async get(J){return this.#X.get(this.#J(J))}async put(J,X){await this.#X.put(this.#J(J),X)}async delete(J){await this.#X.delete(this.#J(J))}async*scan(J,X){for await(let[Z,F]of this.#X.scan(this.#J(J),this.#F(X)))yield[this.#$(Z),F]}async batch(J){await this.#X.batch(J.map((X)=>{if(X.type==="put")return{type:"put",key:this.#J(X.key),value:X.value};return{type:"delete",key:this.#J(X.key)}}))}async conditionalBatch(J,X){return k(this.#X,J.map((Z)=>({key:this.#J(Z.key),expectedValue:Z.expectedValue})),X.map((Z)=>{if(Z.type==="put")return{type:"put",key:this.#J(Z.key),value:Z.value};return{type:"delete",key:this.#J(Z.key)}}))}async has(J){return v(this.#X,this.#J(J))}async deletePrefix(J){return m(this.#X,this.#J(J))}async deleteRange(J,X){let Z=this.#H(N(X));return f(this.#X,this.#J(J),Z)}async*keys(J,X){for await(let Z of w(this.#X,this.#J(J),this.#F(X)))yield this.#$(Z)}async count(J){return u(this.#X,this.#J(J))}[Symbol.dispose](){this.#X[Symbol.dispose]()}}function c(J,X){return new R(J,X)}var d=1,Y="__weftStorageKeyspace",o=102400,e=8192;function JJ(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}function E(J){if(!B(J))return!1;if(J.__weftStorage!==d)return!1;return typeof J.value==="string"}function XJ(J){if(!B(J))return!1;return Object.values(J).every(E)}function z(J){if(J!==Y)return;throw Error(`WebExtensionStorage key "${Y}" is reserved for adapter metadata.`)}function ZJ(J){for(let X of J)z(X.key)}function g(J){return{__weftStorage:d,value:K(J)}}function y(J){if(!E(J))return null;return b(J.value)}function $J(J){return E(J)}function P(J){return new TextEncoder().encode(JSON.stringify(J)).byteLength}function FJ(){let J=globalThis,X=J.browser??J.chrome;if(X?.storage===void 0)throw Error("WebExtensionStorage requires globalThis.browser.storage or globalThis.chrome.storage.");return X}function HJ(J,X){let Z=J.storage?.[X];if(Z===void 0)throw Error(`WebExtensionStorage area "${X}" is not available.`);return Z}function VJ(J){if(J==="session")return"ephemeral";if(J==="sync"||J==="managed")return"remote";return"local"}function GJ(J){let X=J.runtime?.lastError?.message;return X===void 0?null:Error(X)}async function T(J,X,Z){return new Promise((F,V)=>{let H=!1,q=(U)=>{if(H)return;let C=GJ(J);if(H=!0,C!==null)V(C);else F(U)},h=(U)=>{if(H)return;H=!0,V(U)},l=(U)=>q(U),Q;try{Q=X(l)}catch{try{Q=Z()}catch(U){h(U);return}}if(JJ(Q))Q.then(q,h)})}class j{static#X=new WeakMap;#Z;#J;#$;#F;#H;constructor(J={}){this.#$=J.area??"local",this.#F=VJ(this.#$),this.#Z=FJ(),this.#J=HJ(this.#Z,this.#$),this.#H=()=>{},this.#Z.storage?.onChanged?.addListener?.(this.#H)}capabilities(){return{persistence:this.#F,readAfterWrite:"session",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!1,boundedRangeDelete:!1}}async#q(J){return T(this.#Z,(X)=>this.#J.get(J,X),()=>this.#J.get(J))}async#j(J){await T(this.#Z,(X)=>this.#J.set(J,X),()=>this.#J.set(J))}async#N(J){if(this.#J.getBytesInUse===void 0)return null;return T(this.#Z,(X)=>this.#J.getBytesInUse?.(J,X),()=>this.#J.getBytesInUse?.(J))}async#V(){let X=(await this.#q(Y))[Y];if(X===void 0)return{};if(!XJ(X))throw Error("WebExtensionStorage keyspace is not a valid storage envelope map.");return{...X}}async#U(J){let X={[Y]:J};await this.#_(X),await this.#j(X)}async#M(J){let X=j.#X.get(this.#J)??Promise.resolve(),Z={},F=new Promise((H)=>{Z.release=H}),V=X.catch(()=>{return}).then(()=>F);j.#X.set(this.#J,V),await X.catch(()=>{return});try{return await J()}finally{if(Z.release?.(),j.#X.get(this.#J)===V)j.#X.delete(this.#J)}}#G(){if(this.#$==="managed")throw Error('WebExtensionStorage area "managed" is read-only.')}#Y(J){let X=this.#J.QUOTA_BYTES_PER_ITEM??e;for(let[Z,F]of Object.entries(J)){let V=P({[Z]:F});if(V>X)throw Error(`WebExtensionStorage sync item quota exceeded for "${Z}": ${String(V)} > ${String(X)}.`)}}async#Q(J){let X=Object.keys(J),Z=await this.#N(null),F=await this.#N(X);if(Z!==null&&F!==null)return Z-F+P(J);let V=await this.#q(null);return P({...V,...J})}async#_(J){if(this.#$!=="sync")return;this.#Y(J);let X=this.#J.QUOTA_BYTES??o,Z=await this.#Q(J);if(Z>X)throw Error(`WebExtensionStorage sync total quota exceeded: ${String(Z)} > ${String(X)}.`)}async get(J){z(J);let X=await this.#V();return y(X[J])}async put(J,X){this.#G(),z(J),await this.#M(async()=>{let Z=await this.#V();Z[J]=g(X),await this.#U(Z)})}async delete(J){this.#G(),z(J),await this.#M(async()=>{let X=await this.#V();if(!(J in X))return;delete X[J],await this.#U(X)})}async*scan(J,X={}){let Z=await this.#V(),F=Object.keys(Z).filter((H)=>H.startsWith(J)).filter((H)=>x(H,X)).filter((H)=>$J(Z[H])).toSorted();if(X.reverse)F=F.toReversed();let V=0;for(let H of F){if(X.limit!==void 0&&V>=X.limit)break;let q=y(Z[H]);if(q===null)continue;yield[H,q],V+=1}}async batch(J){if(this.#G(),J.length===0)return;ZJ(J),await this.#M(async()=>{let X=await this.#V();for(let Z of J)if(Z.type==="put")X[Z.key]=g(Z.value);else delete X[Z.key];await this.#U(X)})}has(J){return _(this,J)}async*keys(J,X){yield*M(this,J,X)}count(J){return L(this,J)}async deletePrefix(J){return this.#G(),D(this,J)}async deleteRange(J,X){let Z=N(X);return this.#G(),W(this,J,Z)}scoped(J){return c(this,J)}[Symbol.dispose](){this.#Z.storage?.onChanged?.removeListener?.(this.#H)}}export{j as WebExtensionStorage};
1
+ var p=Object.defineProperty;var s=(J)=>J;function a(J,X){this[J]=s.bind(null,X)}var UJ=(J,X)=>{for(var Z in X)p(J,Z,{get:X[Z],enumerable:!0,configurable:!0,set:a.bind(X,Z)})};function b(J){let X=[];for(let Z=0;Z<J.length;Z+=512)X.push(String.fromCharCode(...J.subarray(Z,Z+512)));return btoa(X.join(""))}function K(J){let X=atob(J),Z=new Uint8Array(X.length);for(let F=0;F<X.length;F+=1)Z[F]=X.charCodeAt(F);return Z}function B(J){return typeof J==="object"&&J!==null&&!Array.isArray(J)}async function L(J,X){return await J.get(X)!==null}async function*q(J,X,Z){for await(let[F]of J.scan(X,Z))yield F}async function _(J,X){let Z=0;for await(let F of q(J,X))Z++;return Z}async function D(J,X){let Z=[];for await(let F of q(J,X))Z.push({type:"delete",key:F});if(Z.length===0)return 0;return await J.batch(Z),Z.length}async function W(J,X,Z){let F=[];for await(let V of q(J,X,Z))F.push({type:"delete",key:V});if(F.length===0)return 0;return await J.batch(F),F.length}function R(J,X,Z){if(!J.capabilities()[X])throw Error(`Feature "${Z}" requires storage capability "${X}", but this storage backend does not provide it.`)}var S="default";function v(J){return J.length>0?J.slice(0,-1)+String.fromCharCode(J.charCodeAt(J.length-1)+1):"ÿ"}function x(J,X={}){if(X.gt!==void 0&&J<=X.gt)return!1;if(X.gte!==void 0&&J<X.gte)return!1;if(X.lt!==void 0&&J>=X.lt)return!1;if(X.lte!==void 0&&J>X.lte)return!1;return!0}function WJ(J,X){if(J===null||X===null)return J===X;if(J.byteLength!==X.byteLength)return!1;for(let Z=0;Z<J.byteLength;Z++)if(J[Z]!==X[Z])return!1;return!0}async function I(J,X){if(J.has)return J.has(X);return L(J,X)}function w(J,X,Z){if(J.keys)return J.keys(X,Z);return q(J,X,Z)}async function u(J,X){if(J.count)return J.count(X);return _(J,X)}async function m(J,X){if(J.deletePrefix)return J.deletePrefix(X);return D(J,X)}async function f(J,X,Z){if(R(J,"conditionalBatch","storageConditionalBatch"),!J.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return J.conditionalBatch(X,Z)}function $(J){return encodeURIComponent(J)}function zJ(J){try{return decodeURIComponent(J)}catch{return null}}var G=(J)=>String(J).padStart(16,"0"),BJ={workflow:(J)=>`wf:${$(J)}`,checkpoint:(J)=>`wf:${$(J)}:ckpt`,checkpointHistory:(J,X)=>`wf:${$(J)}:ckpt:${String(X).padStart(10,"0")}`,timelinePrefix:(J)=>`wf:${$(J)}:timeline:`,timeline:(J,X)=>`wf:${$(J)}:timeline:${String(X).padStart(10,"0")}`,schedule:(J)=>`schedule:${$(J)}`,scheduleTick:(J,X)=>`schedule-due:${String(J).padStart(16,"0")}:${$(X)}`,scheduleRun:(J)=>`schedule-run:${$(J)}`,operation:(J,X,Z)=>`op:${J}:${G(X)}:${Z}`,operationInflight:(J)=>`op:inflight:${J}`,operationQueued:(J)=>`op:queued:${J}`,operationResolved:(J)=>`op:resolved:${J}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:(J,X,Z)=>`audit:bulk:${G(J)}:${$(X)}:${$(Z)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:(J,X)=>`op:resolved-by-time:${G(J)}:${$(X)}`,asyncActivity:(J,X)=>`async-act:v1:${$(J)}:${$(X)}`,activityReconciliationPrefix:(J)=>`actrec:v1:${$(J)}:`,activityReconciliation:(J,X,Z)=>`actrec:v1:${$(J)}:${$(X)}:${Z}`,eventPrefix:(J)=>`ev:${$(J)}:`,event:(J,X)=>`ev:${$(J)}:${String(X).padStart(10,"0")}`,eventHead:(J)=>`ev:${$(J)}:head`,eventWatermark:(J)=>`ev:${$(J)}:watermark`,signal:(J,X,Z)=>`sig:${$(J)}:${X}:${$(Z)}`,signalSequence:(J)=>`sigseq:v1:${$(J)}`,signalAcceptedResponsePrefix:(J)=>`sigres:v1:${$(J)}:`,signalAcceptedResponse:(J,X,Z)=>`sigres:v1:${$(J)}:${$(X)}:${$(Z)}`,deadline:(J,X)=>`wf-deadline:${G(J)}:${$(X)}`,terminalCleanup:(J,X)=>`wf-cleanup:${G(J)}:${$(X)}`,delayedStart:(J,X)=>`wf-delayed:${G(J)}:${$(X)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:(J,X)=>`wf-terminal:${G(J)}:${$(X)}`,attribute:(J)=>`attr:${$(J)}`,attributeIndex:(J,X,Z)=>`idx:${J}:${X}:${$(Z)}`,tagIndex:(J,X)=>`tag:${$(J)}:${$(X)}`,updatePrefix:(J)=>`upd:${$(J)}:`,update:(J,X)=>`upd:${$(J)}:${X}`,updateResponse:(J)=>`upr:${J}`,updateIdempotency:(J,X)=>`upk:${$(J)}:${X}`,startIdempotency:(J)=>`start-idem:${$(J)}`,startIdempotencySignalId:(J)=>`start-idem:${J}`,livenessPrefix:()=>"liveness:",liveness:(J)=>`liveness:${$(J)}`,budget:(J,X,Z)=>`budget:${J}:${X}:${Z}`,review:(J,X)=>`review:${$(J)}:${X}`,workflowHeaders:(J)=>`wf-headers:${$(J)}`,terminalCleanupNeeded:(J)=>`wf-cleanup-needed:${$(J)}`,workflowHasServices:(J)=>`wf-has-services:${$(J)}`,offload:(J,X)=>`offload:${$(J)}:${X}`,archive:(J,X)=>`archive:${$(J)}:${X}`,stateExecution:(J,X)=>`state:execution:${$(J)}:${$(X)}`,stateWorkflow:(J,X)=>`state:workflow-scope:${S}:${$(J)}:${$(X)}`,streamChunkPrefix:(J,X)=>`blob:${$(J)}:${X}:chunk:`,streamChunk:(J,X,Z)=>`blob:${$(J)}:${X}:chunk:${String(Z).padStart(10,"0")}`,streamMetadata:(J,X)=>`blob:${$(J)}:${X}:meta`,budgetCharged:(J)=>`budget-charged:${J}`,toolEffect:(J,X,Z)=>`tool-effect:${$(J)}:${X}:${Z}`,workflowVisibilityStatus:(J,X)=>`wf-idx-status:${$(J)}:${$(X)}`,workflowVisibilityType:(J,X)=>`wf-idx-type:${$(J)}:${$(X)}`,workflowVisibilityCreated:(J,X)=>`wf-idx-created:${G(J)}:${$(X)}`,workflowVisibilityUpdated:(J,X)=>`wf-idx-updated:${G(J)}:${$(X)}`,workflowVisibilityDeadline:(J,X)=>`wf-idx-deadline:${G(J)}:${$(X)}`,workflowVisibilityManifest:(J)=>`wf-idx-manifest:${$(J)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"};function i(J){if(J===void 0)return;if(typeof J!=="number"||!Number.isInteger(J)||J<0)throw Error("deleteRange limit must be a finite non-negative integer");return J===0?0:J}function N(J){let X={},Z=!1;for(let V of["gt","gte","lt","lte"]){let H=J[V];if(H===void 0)continue;if(typeof H!=="string")throw Error("deleteRange bounds must be strings");X[V]=H,Z=!0}if(!Z)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let F=i(J.limit);if(F!==void 0)X.limit=F;return X}async function k(J,X,Z){let F=N(Z);if(J.deleteRange)return J.deleteRange(X,F);return W(J,X,F)}function r(J,X){let Z={key:J,open:!1};if(X.gte!==void 0&&X.gte>Z.key)Z.key=X.gte,Z.open=!1;if(X.gt!==void 0&&X.gt>=Z.key)Z.key=X.gt,Z.open=!0;return Z}function n(J,X){let Z={key:v(J),open:!0};if(X.lt!==void 0&&X.lt<=Z.key)Z.key=X.lt,Z.open=!0;if(X.lte!==void 0&&X.lte<Z.key)Z.key=X.lte,Z.open=!1;return Z}function TJ(J,X){let Z=r(J,X),F=n(J,X);if(Z.key>F.key||Z.key===F.key&&(Z.open||F.open))return null;return{lower:Z,upper:F}}function A(J){return J.replaceAll(/:+$/g,"")}function t(J,X){let Z=A(J),F=A(X);if(Z.length===0)return F;if(F.length===0)return Z;return`${Z}:${F}`}class O{#X;#Z;constructor(J,X){this.#X=J,this.#Z=A(X)}#J(J){if(this.#Z.length===0)return J;return J.length===0?`${this.#Z}:`:`${this.#Z}:${J}`}#$(J){if(this.#Z.length===0)return J;return J.slice(this.#Z.length+1)}#F(J={}){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.reverse!==void 0)X.reverse=J.reverse;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}#H(J){let X={};if(J.limit!==void 0)X.limit=J.limit;if(J.gt!==void 0)X.gt=this.#J(J.gt);if(J.gte!==void 0)X.gte=this.#J(J.gte);if(J.lt!==void 0)X.lt=this.#J(J.lt);if(J.lte!==void 0)X.lte=this.#J(J.lte);return X}capabilities(){return this.#X.capabilities()}scoped(J){return new O(this.#X,t(this.#Z,J))}async get(J){return this.#X.get(this.#J(J))}async put(J,X){await this.#X.put(this.#J(J),X)}async delete(J){await this.#X.delete(this.#J(J))}async*scan(J,X){for await(let[Z,F]of this.#X.scan(this.#J(J),this.#F(X)))yield[this.#$(Z),F]}async batch(J){await this.#X.batch(J.map((X)=>{if(X.type==="put")return{type:"put",key:this.#J(X.key),value:X.value};return{type:"delete",key:this.#J(X.key)}}))}async conditionalBatch(J,X){return f(this.#X,J.map((Z)=>({key:this.#J(Z.key),expectedValue:Z.expectedValue})),X.map((Z)=>{if(Z.type==="put")return{type:"put",key:this.#J(Z.key),value:Z.value};return{type:"delete",key:this.#J(Z.key)}}))}async has(J){return I(this.#X,this.#J(J))}async deletePrefix(J){return m(this.#X,this.#J(J))}async deleteRange(J,X){let Z=this.#H(N(X));return k(this.#X,this.#J(J),Z)}async*keys(J,X){for await(let Z of w(this.#X,this.#J(J),this.#F(X)))yield this.#$(Z)}async count(J){return u(this.#X,this.#J(J))}[Symbol.dispose](){this.#X[Symbol.dispose]()}}function g(J,X){return new O(J,X)}var l=1,j="__weftStorageKeyspace",o=102400,e=8192;function JJ(J){return typeof J==="object"&&J!==null&&"then"in J&&typeof J.then==="function"}function E(J){if(!B(J))return!1;if(J.__weftStorage!==l)return!1;return typeof J.value==="string"}function XJ(J){if(!B(J))return!1;return Object.values(J).every(E)}function z(J){if(J!==j)return;throw Error(`WebExtensionStorage key "${j}" is reserved for adapter metadata.`)}function ZJ(J){for(let X of J)z(X.key)}function c(J){return{__weftStorage:l,value:b(J)}}function y(J){if(!E(J))return null;return K(J.value)}function $J(J){return E(J)}function P(J){return new TextEncoder().encode(JSON.stringify(J)).byteLength}function FJ(){let J=globalThis,X=J.browser??J.chrome;if(X?.storage===void 0)throw Error("WebExtensionStorage requires globalThis.browser.storage or globalThis.chrome.storage.");return X}function HJ(J,X){let Z=J.storage?.[X];if(Z===void 0)throw Error(`WebExtensionStorage area "${X}" is not available.`);return Z}function VJ(J){if(J==="session")return"ephemeral";if(J==="sync"||J==="managed")return"remote";return"local"}function GJ(J){let X=J.runtime?.lastError?.message;return X===void 0?null:Error(X)}async function T(J,X,Z){return new Promise((F,V)=>{let H=!1,M=(U)=>{if(H)return;let C=GJ(J);if(H=!0,C!==null)V(C);else F(U)},h=(U)=>{if(H)return;H=!0,V(U)},d=(U)=>M(U),Y;try{Y=X(d)}catch{try{Y=Z()}catch(U){h(U);return}}if(JJ(Y))Y.then(M,h)})}class Q{static#X=new WeakMap;#Z;#J;#$;#F;#H;constructor(J={}){this.#$=J.area??"local",this.#F=VJ(this.#$),this.#Z=FJ(),this.#J=HJ(this.#Z,this.#$),this.#H=()=>{},this.#Z.storage?.onChanged?.addListener?.(this.#H)}capabilities(){return{persistence:this.#F,readAfterWrite:"session",scanConsistency:"best-effort",atomicBatch:!0,conditionalBatch:!1,boundedRangeDelete:!1}}async#M(J){return T(this.#Z,(X)=>this.#J.get(J,X),()=>this.#J.get(J))}async#Q(J){await T(this.#Z,(X)=>this.#J.set(J,X),()=>this.#J.set(J))}async#N(J){if(this.#J.getBytesInUse===void 0)return null;return T(this.#Z,(X)=>this.#J.getBytesInUse?.(J,X),()=>this.#J.getBytesInUse?.(J))}async#V(){let X=(await this.#M(j))[j];if(X===void 0)return{};if(!XJ(X))throw Error("WebExtensionStorage keyspace is not a valid storage envelope map.");return{...X}}async#U(J){let X={[j]:J};await this.#L(X),await this.#Q(X)}async#q(J){let X=Q.#X.get(this.#J)??Promise.resolve(),Z={},F=new Promise((H)=>{Z.release=H}),V=X.catch(()=>{return}).then(()=>F);Q.#X.set(this.#J,V),await X.catch(()=>{return});try{return await J()}finally{if(Z.release?.(),Q.#X.get(this.#J)===V)Q.#X.delete(this.#J)}}#G(){if(this.#$==="managed")throw Error('WebExtensionStorage area "managed" is read-only.')}#j(J){let X=this.#J.QUOTA_BYTES_PER_ITEM??e;for(let[Z,F]of Object.entries(J)){let V=P({[Z]:F});if(V>X)throw Error(`WebExtensionStorage sync item quota exceeded for "${Z}": ${String(V)} > ${String(X)}.`)}}async#Y(J){let X=Object.keys(J),Z=await this.#N(null),F=await this.#N(X);if(Z!==null&&F!==null)return Z-F+P(J);let V=await this.#M(null);return P({...V,...J})}async#L(J){if(this.#$!=="sync")return;this.#j(J);let X=this.#J.QUOTA_BYTES??o,Z=await this.#Y(J);if(Z>X)throw Error(`WebExtensionStorage sync total quota exceeded: ${String(Z)} > ${String(X)}.`)}async get(J){z(J);let X=await this.#V();return y(X[J])}async put(J,X){this.#G(),z(J),await this.#q(async()=>{let Z=await this.#V();Z[J]=c(X),await this.#U(Z)})}async delete(J){this.#G(),z(J),await this.#q(async()=>{let X=await this.#V();if(!(J in X))return;delete X[J],await this.#U(X)})}async*scan(J,X={}){let Z=await this.#V(),F=Object.keys(Z).filter((H)=>H.startsWith(J)).filter((H)=>x(H,X)).filter((H)=>$J(Z[H])).toSorted();if(X.reverse)F=F.toReversed();let V=0;for(let H of F){if(X.limit!==void 0&&V>=X.limit)break;let M=y(Z[H]);if(M===null)continue;yield[H,M],V+=1}}async batch(J){if(this.#G(),J.length===0)return;ZJ(J),await this.#q(async()=>{let X=await this.#V();for(let Z of J)if(Z.type==="put")X[Z.key]=c(Z.value);else delete X[Z.key];await this.#U(X)})}has(J){return L(this,J)}async*keys(J,X){yield*q(this,J,X)}count(J){return _(this,J)}async deletePrefix(J){return this.#G(),D(this,J)}async deleteRange(J,X){let Z=N(X);return this.#G(),W(this,J,Z)}scoped(J){return g(this,J)}[Symbol.dispose](){this.#Z.storage?.onChanged?.removeListener?.(this.#H)}}export{Q as WebExtensionStorage};
@@ -1,4 +1,38 @@
1
- /** Let promise continuations and queued microtasks settle without advancing time. */
1
+ /**
2
+ * Let promise continuations and queued microtasks settle without advancing time
3
+ * or yielding a full event-loop turn. Awaits `Promise.resolve()` `turns` times,
4
+ * which is enough to drain chained `.then()` continuations. Use it when a test
5
+ * needs queued microtasks to run but does not need a macrotask boundary.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { flushPortableMicrotasks } from '@lostgradient/weft/testing';
10
+ *
11
+ * let ran = false;
12
+ * void Promise.resolve().then(() => {
13
+ * ran = true;
14
+ * });
15
+ * await flushPortableMicrotasks();
16
+ * console.log(ran); // true
17
+ * ```
18
+ */
2
19
  export declare function flushPortableMicrotasks(turns?: number): Promise<void>;
3
- /** Yield one event-loop turn without importing test-runner-only timer APIs. */
20
+ /**
21
+ * Yield one full event-loop turn without importing test-runner-only timer APIs,
22
+ * then drain microtasks. Prefers a `MessageChannel` postMessage (a macrotask)
23
+ * and falls back to `setTimeout(0)` where `MessageChannel` is unavailable.
24
+ *
25
+ * Use it in an `afterEach` to drain a prior test's deferred inline workflow
26
+ * launch: under a shared-process runner (Bun, Jest, Vitest), an engine disposed
27
+ * mid-workflow can leave a queued inline start that would otherwise starve the
28
+ * next test's timers.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { afterEach } from 'bun:test';
33
+ * import { yieldToPortableEventLoop } from '@lostgradient/weft/testing';
34
+ *
35
+ * afterEach(yieldToPortableEventLoop);
36
+ * ```
37
+ */
4
38
  export declare function yieldToPortableEventLoop(): Promise<void>;
@@ -8,6 +8,7 @@
8
8
  * @module @lostgradient/weft/testing
9
9
  */
10
10
  import { ChaosNonRetryableError, ChaosTimeoutError, ChaosTransientError, withChaos } from './chaos';
11
+ import { flushPortableMicrotasks, yieldToPortableEventLoop } from './event-loop';
11
12
  import { ActivityMockRegistry } from './mocks';
12
13
  import { killAndReboot, spawnServerSubprocess, withSubprocessServer } from './subprocess-engine';
13
14
  import { TestEngine } from './test-engine';
@@ -119,8 +120,37 @@ declare const exportedKillAndReboot: typeof killAndReboot;
119
120
  * ```
120
121
  */
121
122
  declare const exportedWithSubprocessServer: typeof withSubprocessServer;
123
+ /**
124
+ * Re-exported {@link yieldToPortableEventLoop}. See the original declaration for full docs.
125
+ *
126
+ * Yields one event-loop turn without test-runner-only timer APIs. Use it in an
127
+ * `afterEach` to drain a prior test's deferred inline workflow launch: under a
128
+ * shared-process runner (Bun, Jest, Vitest), an engine disposed mid-workflow can
129
+ * otherwise leave a queued inline start that starves the next test.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * import { yieldToPortableEventLoop } from '@lostgradient/weft/testing';
134
+ * afterEach(yieldToPortableEventLoop);
135
+ * ```
136
+ */
137
+ declare const exportedYieldToPortableEventLoop: typeof yieldToPortableEventLoop;
138
+ /**
139
+ * Re-exported {@link flushPortableMicrotasks}. See the original declaration for full docs.
140
+ *
141
+ * Lets queued microtasks settle without advancing time or yielding a full
142
+ * event-loop turn — the cheaper drain when you only need promise continuations
143
+ * to run.
144
+ *
145
+ * @example
146
+ * ```ts
147
+ * import { flushPortableMicrotasks } from '@lostgradient/weft/testing';
148
+ * await flushPortableMicrotasks();
149
+ * ```
150
+ */
151
+ declare const exportedFlushPortableMicrotasks: typeof flushPortableMicrotasks;
122
152
  export type { ChaosScenario, FaultClass } from './chaos';
123
153
  export type { MockCall, MockedActivity, MockHandle } from './mocks';
124
154
  export type { SubprocessServerHandle, SubprocessServerOptions, SubprocessServerProcess, SubprocessSignal, } from './subprocess-engine';
125
155
  export type { RunNOptions, RunNResult } from './test-engine';
126
- export { exportedActivityMockRegistry as ActivityMockRegistry, exportedChaosNonRetryableError as ChaosNonRetryableError, exportedChaosTimeoutError as ChaosTimeoutError, exportedChaosTransientError as ChaosTransientError, exportedKillAndReboot as killAndReboot, exportedSpawnServerSubprocess as spawnServerSubprocess, exportedTestEngine as TestEngine, exportedTimeControl as TimeControl, exportedWithChaos as withChaos, exportedWithSubprocessServer as withSubprocessServer, };
156
+ export { exportedActivityMockRegistry as ActivityMockRegistry, exportedChaosNonRetryableError as ChaosNonRetryableError, exportedChaosTimeoutError as ChaosTimeoutError, exportedChaosTransientError as ChaosTransientError, exportedFlushPortableMicrotasks as flushPortableMicrotasks, exportedKillAndReboot as killAndReboot, exportedSpawnServerSubprocess as spawnServerSubprocess, exportedTestEngine as TestEngine, exportedTimeControl as TimeControl, exportedWithChaos as withChaos, exportedWithSubprocessServer as withSubprocessServer, exportedYieldToPortableEventLoop as yieldToPortableEventLoop, };