@lostgradient/weft 0.7.0 → 0.8.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.
- package/README.md +4 -2
- package/dist/cli-main.js +63 -63
- package/dist/core/context/activity-retry-state.d.ts +6 -5
- package/dist/core/context/activity-retry-state.js +31 -21
- package/dist/core/context/durable-activity.d.ts +117 -0
- package/dist/core/context/durable-activity.js +79 -0
- package/dist/core/context/operation-request.d.ts +15 -0
- package/dist/core/context/parallel-operations.js +1 -0
- package/dist/core/context/run-operation-cached-request.d.ts +8 -0
- package/dist/core/context/run-operation-cached-request.js +59 -0
- package/dist/core/context/run-operation.d.ts +23 -5
- package/dist/core/context/run-operation.js +62 -47
- package/dist/core/engine/activity-heartbeat-tracking.d.ts +8 -17
- package/dist/core/engine/activity-heartbeat-tracking.js +7 -1
- package/dist/core/engine/activity-reconciliation.d.ts +1 -0
- package/dist/core/engine/activity-reconciliation.js +7 -2
- package/dist/core/engine/anonymous-signal-sequence.js +6 -4
- package/dist/core/engine/async-activity-completion.d.ts +5 -7
- package/dist/core/engine/async-activity-completion.js +13 -9
- package/dist/core/engine/bulk-operations-purge.js +2 -1
- package/dist/core/engine/bulk-operations.js +8 -7
- package/dist/core/engine/callback-checkpoint-persistence.d.ts +3 -0
- package/dist/core/engine/callback-checkpoint-persistence.js +25 -0
- package/dist/core/engine/callback-creators-bundles.js +4 -1
- package/dist/core/engine/checkpoint-io.d.ts +4 -1
- package/dist/core/engine/checkpoint-io.js +19 -10
- package/dist/core/engine/completed-review-storage.d.ts +2 -1
- package/dist/core/engine/completed-review-storage.js +4 -3
- package/dist/core/engine/index.d.ts +31 -0
- package/dist/core/engine/index.js +6 -1
- package/dist/core/engine/internals.d.ts +2 -1
- package/dist/core/engine/lease-manager.js +2 -2
- package/dist/core/engine/memo-durable-activity.d.ts +11 -0
- package/dist/core/engine/memo-durable-activity.js +282 -0
- package/dist/core/engine/operations-activity.d.ts +5 -1
- package/dist/core/engine/operations-activity.js +19 -7
- package/dist/core/engine/operations-data.d.ts +4 -1
- package/dist/core/engine/operations-data.js +3 -3
- package/dist/core/engine/reviews.js +7 -4
- package/dist/core/engine/schedule-timer.js +2 -0
- package/dist/core/engine/storage-io.js +1 -1
- package/dist/core/json.js +1 -1
- package/dist/core/weft-error.d.ts +1 -1
- package/dist/core/weft-error.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +6 -0
- package/dist/json-schema.js +1 -1
- package/dist/mcp/cli.js +26 -26
- package/dist/server/handler.js +21 -21
- package/dist/server/index.js +17 -17
- package/dist/server/runtime/websocket-worker.js +7 -2
- package/dist/server/serve-internals.d.ts +28 -0
- package/dist/server/serve-internals.js +4 -2
- package/dist/service-worker/index.js +22 -22
- package/dist/service-worker/setup.d.ts +18 -1
- package/dist/service-worker/setup.js +7 -4
- package/dist/storage/typed-storage.d.ts +1 -1
- package/dist/storage/typed-storage.js +1 -1
- package/dist/testing/index.js +27 -27
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -60,6 +60,23 @@ export interface SetupServiceWorkerOptions {
|
|
|
60
60
|
* fetch/periodic-sync handlers to fail-fast with explicit errors.
|
|
61
61
|
*/
|
|
62
62
|
register?: (engine: Engine) => void | Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* When `true`, calls `engine.recoverAll()` (with no arguments) after
|
|
65
|
+
* `options.register` completes and before the `ready` promise settles.
|
|
66
|
+
* Fetch and periodic-sync handlers therefore block on both workflow
|
|
67
|
+
* registration AND recovery before serving any traffic.
|
|
68
|
+
*
|
|
69
|
+
* This is the zero-boilerplate replacement for the common pattern of
|
|
70
|
+
* calling `await engine.recoverAll()` at the end of your `register`
|
|
71
|
+
* callback. It does NOT forward `RecoverAllOptions`: if you need
|
|
72
|
+
* `acknowledgeUnknownWorkflowTypes` or any other recovery option, call
|
|
73
|
+
* `engine.recoverAll(opts)` yourself inside `register` and leave `recover`
|
|
74
|
+
* unset — do not set both, or recovery runs twice (the helper has no guard
|
|
75
|
+
* against a second, no-argument pass).
|
|
76
|
+
*
|
|
77
|
+
* Defaults to `false` — no behavior change for callers that omit this option.
|
|
78
|
+
*/
|
|
79
|
+
recover?: boolean;
|
|
63
80
|
}
|
|
64
81
|
/**
|
|
65
82
|
* Result returned by {@link setupServiceWorker} once registration completes.
|
|
@@ -83,7 +100,7 @@ export interface SetupServiceWorkerResult {
|
|
|
83
100
|
engine: Engine;
|
|
84
101
|
storage: WeftStorage;
|
|
85
102
|
scheduler: ServiceWorkerScheduler;
|
|
86
|
-
/** Resolves when `
|
|
103
|
+
/** Resolves when registration (and recovery, if `recover: true`) completes. Rejects if either threw. */
|
|
87
104
|
ready: Promise<void>;
|
|
88
105
|
}
|
|
89
106
|
/**
|
|
@@ -96,11 +96,14 @@ export function setupServiceWorker(options = {}) {
|
|
|
96
96
|
storage,
|
|
97
97
|
onTimerFired: (entry) => engine.fireTimer(entry),
|
|
98
98
|
periodicSyncTag
|
|
99
|
-
}), registrationReady = Promise.resolve().then(() => {
|
|
100
|
-
if (options.register === void 0)
|
|
101
|
-
return;
|
|
102
|
-
return options.register(engine);
|
|
103
99
|
});
|
|
100
|
+
async function runRegistrationAndRecovery() {
|
|
101
|
+
if (options.register !== void 0)
|
|
102
|
+
await options.register(engine);
|
|
103
|
+
if (options.recover === !0)
|
|
104
|
+
await engine.recoverAll();
|
|
105
|
+
}
|
|
106
|
+
const registrationReady = Promise.resolve().then(runRegistrationAndRecovery);
|
|
104
107
|
attachListeners(scope, pathPrefix, periodicSyncTag, engine, scheduler, registrationReady);
|
|
105
108
|
const result = {
|
|
106
109
|
engine,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var r0=Object.defineProperty;var s0=($)=>$;function a0($,Z){this[$]=s0.bind(null,Z)}var Y1=($,Z)=>{for(var Q in Z)r0($,Q,{get:Z[Q],enumerable:!0,configurable:!0,set:a0.bind(Z,Q)})};var H=($,Z)=>()=>($&&(Z=$($=0)),Z);var V1=($,Z,Q)=>{if(Z!=null){if(typeof Z!=="object"&&typeof Z!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let J;if(Q)J=Z[Symbol.asyncDispose];if(J===void 0)J=Z[Symbol.dispose];if(typeof J!=="function")throw TypeError("Object not disposable");$.push([Q,J,Z])}else if(Q)$.push([Q]);return Z},P1=($,Z,Q)=>{let J=(q)=>Z=Q?new SuppressedError(q,Z,"An error was suppressed during disposal"):(Q=!0,q),W=(q)=>{while(q=$.pop())try{var F=q[1]&&q[1].call(q[2]);if(q[0])return Promise.resolve(F).then(W,(K)=>(J(K),W()))}catch(K){J(K)}if(Q)throw Z};return W()};function v($,Z,Q){if(!$.capabilities()[Z])throw Error(`Feature "${Q}" requires storage capability "${Z}", but this storage backend does not provide it.`)}function o0($){let Z=$.capabilities(),Q=[];if(Z.persistence!=="local"&&Z.persistence!=="remote")Q.push(`persistence must be "local" or "remote" (got "${Z.persistence}")`);if(Z.readAfterWrite!=="linearizable")Q.push(`readAfterWrite must be "linearizable" (got "${Z.readAfterWrite}")`);if(Z.scanConsistency!=="snapshot")Q.push(`scanConsistency must be "snapshot" (got "${Z.scanConsistency}")`);if(!Z.atomicBatch)Q.push("atomicBatch must be true");if(!Z.conditionalBatch)Q.push("conditionalBatch must be true");if(Q.length>0)throw Error(`Storage is not durable enough for recovery: ${Q.join("; ")}.`)}var p="default";async function Q0($,Z){return await $.get(Z)!==null}async function*A($,Z,Q){for await(let[J]of $.scan(Z,Q))yield J}async function J0($,Z){let Q=0;for await(let J of A($,Z))Q++;return Q}async function W0($,Z){let Q=[];for await(let J of A($,Z))Q.push({type:"delete",key:J});if(Q.length===0)return 0;return await $.batch(Q),Q.length}async function G0($,Z,Q){let J=[];for await(let W of A($,Z,Q))J.push({type:"delete",key:W});if(J.length===0)return 0;return await $.batch(J),J.length}var t0;var q0=H(()=>{t0=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","idx:","lease:","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-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-terminal:"]});function z($,Z){if(Z>c)throw new K0($,Z)}function A1($){return $.length>0?$.slice(0,-1)+String.fromCharCode($.charCodeAt($.length-1)+1):"\xFF"}function z1($,Z={}){if(Z.gt!==void 0&&$<=Z.gt)return!1;if(Z.gte!==void 0&&$<Z.gte)return!1;if(Z.lt!==void 0&&$>=Z.lt)return!1;if(Z.lte!==void 0&&$>Z.lte)return!1;return!0}function T1($,Z){if($===null||Z===null)return $===Z;if($.byteLength!==Z.byteLength)return!1;for(let Q=0;Q<$.byteLength;Q++)if($[Q]!==Z[Q])return!1;return!0}async function H0($,Z){if($.has)return $.has(Z);return Q0($,Z)}function X0($,Z,Q){if($.keys)return $.keys(Z,Q);return A($,Z,Q)}async function Y0($,Z){if($.count)return $.count(Z);return J0($,Z)}async function V0($,Z){if($.deletePrefix)return $.deletePrefix(Z);return W0($,Z)}async function D1($,Z){z("batch operations",Z.length),await $.batch(Z)}async function P0($,Z,Q){if(z("conditionalBatch conditions",Z.length),z("conditionalBatch operations",Q.length),v($,"conditionalBatch","storageConditionalBatch"),!$.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return $.conditionalBatch(Z,Q)}function G($){return encodeURIComponent($)}function L1($){return decodeURIComponent($)}function x1($){try{return decodeURIComponent($)}catch{return null}}var c=1e4,B1=1e4,K0,P=($)=>String($).padStart(16,"0"),e0="0",$$="1",F0=($,Z,Q,J)=>`sig:${G($)}:${G(Z)}:${J}:${G(Q)}`,I1;var N0=H(()=>{q0();K0=class K0 extends Error{code="StorageBatchOperationLimitExceededError";cap=c;count;target;constructor($,Z){super(`${$} count ${Z} exceeds MAX_BATCH_OPERATIONS (${c}).`);this.name="StorageBatchOperationLimitExceededError",this.target=$,this.count=Z}};I1={workflow:($)=>`wf:${G($)}`,checkpoint:($)=>`wf:${G($)}:ckpt`,checkpointHistory:($,Z)=>`wf:${G($)}:ckpt:${String(Z).padStart(10,"0")}`,timelinePrefix:($)=>`wf:${G($)}:timeline:`,timeline:($,Z)=>`wf:${G($)}:timeline:${String(Z).padStart(10,"0")}`,schedule:($)=>`schedule:${G($)}`,scheduleTick:($,Z)=>`schedule-due:${String($).padStart(16,"0")}:${G(Z)}`,scheduleRun:($)=>`schedule-run:${G($)}`,operation:($,Z,Q)=>`op:${$}:${P(Z)}:${Q}`,operationInflight:($)=>`op:inflight:${$}`,operationQueued:($)=>`op:queued:${$}`,operationResolved:($)=>`op:resolved:${$}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:($)=>`op:dead-letter:${$}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:($,Z,Q)=>`audit:bulk:${P($)}:${G(Z)}:${G(Q)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:($,Z)=>`op:resolved-by-time:${P($)}:${G(Z)}`,asyncActivity:($,Z)=>`async-act:v1:${G($)}:${G(Z)}`,activityReconciliationPrefix:($)=>`actrec:v1:${G($)}:`,activityReconciliation:($,Z,Q)=>`actrec:v1:${G($)}:${G(Z)}:${Q}`,eventPrefix:($)=>`ev:${G($)}:`,event:($,Z)=>`ev:${G($)}:${String(Z).padStart(10,"0")}`,eventHead:($)=>`ev:${G($)}:head`,eventWatermark:($)=>`ev:${G($)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:($)=>`fleet-event:${String($).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:($)=>`fleet-event-by-workflow:${G($)}:`,fleetEventByWorkflow:($,Z)=>`fleet-event-by-workflow:${G($)}:${String(Z).padStart(10,"0")}`,signal:($,Z,Q)=>F0($,Z,Q,$$),startSignal:($,Z,Q)=>F0($,Z,Q,e0),signalSequence:($)=>`sigseq:v1:${G($)}`,signalAcceptedResponsePrefix:($)=>`sigres:v1:${G($)}:`,signalAcceptedResponse:($,Z,Q)=>`sigres:v1:${G($)}:${G(Z)}:${G(Q)}`,deadline:($,Z)=>`wf-deadline:${P($)}:${G(Z)}`,terminalCleanup:($,Z)=>`wf-cleanup:${P($)}:${G(Z)}`,teardownTimer:($,Z)=>`wf-teardown:${P($)}:${G(Z)}`,delayedStart:($,Z)=>`wf-delayed:${P($)}:${G(Z)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:($,Z)=>`wf-terminal:${P($)}:${G(Z)}`,attribute:($)=>`attr:${G($)}`,attributeIndex:($,Z,Q)=>`idx:${$}:${Z}:${G(Q)}`,tagIndex:($,Z)=>`tag:${G($)}:${G(Z)}`,updatePrefix:($)=>`upd:${G($)}:`,update:($,Z)=>`upd:${G($)}:${Z}`,updateResponse:($)=>`upr:${$}`,updateIdempotency:($,Z)=>`upk:${G($)}:${Z}`,startIdempotency:($)=>`start-idem:${G($)}`,startIdempotencySignalId:($)=>`start-idem:${$}`,livenessPrefix:()=>"liveness:",liveness:($)=>`liveness:${G($)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",budget:($,Z,Q)=>`budget:${$}:${Z}:${Q}`,review:($,Z)=>`review:${G($)}:${Z}`,workflowHeaders:($)=>`wf-headers:${G($)}`,childCancellationPrefix:($)=>`child-cancel:${G($)}:`,childCancellation:($,Z)=>`child-cancel:${G($)}:${G(Z)}`,terminalCleanupNeeded:($)=>`wf-cleanup-needed:${G($)}`,workflowConcurrency:($,Z)=>`wf-concurrency:${G($)}:${G(Z)}`,workflowConcurrencyHolder:($)=>`wf-concurrency-holder:${G($)}`,workflowHasServices:($)=>`wf-has-services:${G($)}`,finalizerState:($)=>`wf-finalizer-state:${G($)}`,teardownOwed:($)=>`wf-teardown-needed:${G($)}`,teardownDeadLetter:($)=>`wf-teardown-deadletter:${G($)}`,offload:($,Z)=>`offload:${G($)}:${Z}`,archive:($,Z)=>`archive:${G($)}:${Z}`,stateExecution:($,Z)=>`state:execution:${G($)}:${G(Z)}`,stateWorkflow:($,Z)=>`state:workflow-scope:${p}:${G($)}:${G(Z)}`,streamChunkPrefix:($,Z)=>`blob:${G($)}:${Z}:chunk:`,streamChunk:($,Z,Q)=>`blob:${G($)}:${Z}:chunk:${String(Q).padStart(10,"0")}`,streamTail:($,Z)=>`blob:${G($)}:${Z}:tail`,streamMetadata:($,Z)=>`blob:${G($)}:${Z}:meta`,budgetCharged:($)=>`budget-charged:${$}`,toolEffect:($,Z,Q)=>`tool-effect:${G($)}:${Z}:${Q}`,workflowVisibilityStatus:($,Z)=>`wf-idx-status:${G($)}:${G(Z)}`,workflowVisibilityType:($,Z)=>`wf-idx-type:${G($)}:${G(Z)}`,workflowVisibilityCreated:($,Z)=>`wf-idx-created:${P($)}:${G(Z)}`,workflowVisibilityUpdated:($,Z)=>`wf-idx-updated:${P($)}:${G(Z)}`,workflowVisibilityDeadline:($,Z)=>`wf-idx-deadline:${P($)}:${G(Z)}`,workflowVisibilityManifest:($)=>`wf-idx-manifest:${G($)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function M0($){let Z=$.length,Q=0,J=0;while(J<Z){let W=$.charCodeAt(J++);if((W&4294967168)===0){Q++;continue}else if((W&4294965248)===0)Q+=2;else{if(W>=55296&&W<=56319){if(J<Z){let q=$.charCodeAt(J);if((q&64512)===56320)++J,W=((W&1023)<<10)+(q&1023)+65536}}if((W&4294901760)===0)Q+=3;else Q+=4}}return Q}function Z$($,Z,Q){let J=$.length,W=Q,q=0;while(q<J){let F=$.charCodeAt(q++);if((F&4294967168)===0){Z[W++]=F;continue}else if((F&4294965248)===0)Z[W++]=F>>6&31|192;else{if(F>=55296&&F<=56319){if(q<J){let K=$.charCodeAt(q);if((K&64512)===56320)++q,F=((F&1023)<<10)+(K&1023)+65536}}if((F&4294901760)===0)Z[W++]=F>>12&15|224,Z[W++]=F>>6&63|128;else Z[W++]=F>>18&7|240,Z[W++]=F>>12&63|128,Z[W++]=F>>6&63|128}Z[W++]=F&63|128}}function W$($,Z,Q){Q$.encodeInto($,Z.subarray(Q))}function R0($,Z,Q){if($.length>J$)W$($,Z,Q);else Z$($,Z,Q)}function l($,Z,Q){let J=Z,W=J+Q,q=[],F="";while(J<W){let K=$[J++];if((K&128)===0)q.push(K);else if((K&224)===192){let B=$[J++]&63;q.push((K&31)<<6|B)}else if((K&240)===224){let B=$[J++]&63,f=$[J++]&63;q.push((K&31)<<12|B<<6|f)}else if((K&248)===240){let B=$[J++]&63,f=$[J++]&63,i0=$[J++]&63,U=(K&7)<<18|B<<12|f<<6|i0;if(U>65535)U-=65536,q.push(U>>>10&1023|55296),U=56320|U&1023;q.push(U)}else q.push(K);if(q.length>=G$)F+=String.fromCharCode(...q),q.length=0}if(q.length>0)F+=String.fromCharCode(...q);return F}function K$($,Z,Q){let J=$.subarray(Z,Z+Q);return q$.decode(J)}function U0($,Z,Q){if(Q>F$)return K$($,Z,Q);else return l($,Z,Q)}var Q$,J$=50,G$=4096,q$,F$=200;var I=H(()=>{Q$=new TextEncoder;q$=new TextDecoder});class S{type;data;constructor($,Z){this.type=$,this.data=Z}}var Y;var u=H(()=>{Y=class Y extends Error{constructor($){super($);let Z=Object.create(Y.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:Y.name})}}});function S0($,Z,Q){let J=Q/4294967296,W=Q;$.setUint32(Z,J),$.setUint32(Z+4,W)}function k($,Z,Q){let J=Math.floor(Q/4294967296),W=Q;$.setUint32(Z,J),$.setUint32(Z+4,W)}function m($,Z){let Q=$.getInt32(Z),J=$.getUint32(Z+4);return Q*4294967296+J}function _0($,Z){let Q=$.getUint32(Z),J=$.getUint32(Z+4);return Q*4294967296+J}var _=4294967295;function V$({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=Y$)if(Z===0&&$<=X$){let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,$),Q}else{let Q=$/4294967296,J=$&4294967295,W=new Uint8Array(8),q=new DataView(W.buffer);return q.setUint32(0,Z<<2|Q&3),q.setUint32(4,J),W}else{let Q=new Uint8Array(12),J=new DataView(Q.buffer);return J.setUint32(0,Z),k(J,4,$),Q}}function P$($){let Z=$.getTime(),Q=Math.floor(Z/1000),J=(Z-Q*1000)*1e6,W=Math.floor(J/1e9);return{sec:Q+W,nsec:J-W*1e9}}function N$($){if($ instanceof Date){let Z=P$($);return V$(Z)}else return null}function M$($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let Q=Z.getUint32(0),J=0;return{sec:Q,nsec:0}}case 8:{let Q=Z.getUint32(0),J=Z.getUint32(4),W=(Q&3)*4294967296+J,q=Q>>>2;return{sec:W,nsec:q}}case 12:{let Q=m(Z,4),J=Z.getUint32(0);return{sec:Q,nsec:J}}default:throw new Y(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function R$($){let Z=M$($);return new Date(Z.sec*1000+Z.nsec/1e6)}var H$=-1,X$=4294967295,Y$=17179869183,C0;var O0=H(()=>{u();C0={type:H$,encode:N$,decode:R$}});var R;var E=H(()=>{O0();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(C0)}register({type:$,encode:Z,decode:Q}){if($>=0)this.encoders[$]=Z,this.decoders[$]=Q;else{let J=-1-$;this.builtInEncoders[J]=Z,this.builtInDecoders[J]=Q}}tryToEncode($,Z){for(let Q=0;Q<this.builtInEncoders.length;Q++){let J=this.builtInEncoders[Q];if(J!=null){let W=J($,Z);if(W!=null){let q=-1-Q;return new S(q,W)}}}for(let Q=0;Q<this.encoders.length;Q++){let J=this.encoders[Q];if(J!=null){let W=J($,Z);if(W!=null)return new S(Q,W)}}if($ instanceof S)return $;return null}decode($,Z,Q){let J=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(J)return J($,Z,Q);else return new S(Z,$)}}});function U$($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function T($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(U$($))return new Uint8Array($);else return Uint8Array.from($)}class w{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??R.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??S$,this.initialBufferSize=$?.initialBufferSize??_$,this.sortKeys=$?.sortKeys??!1,this.forceFloat32=$?.forceFloat32??!1,this.ignoreUndefined=$?.ignoreUndefined??!1,this.forceIntegerToFloat=$?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new w({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($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),Q=new Uint8Array(Z),J=new DataView(Z);Q.set(this.bytes),this.view=J,this.bytes=Q}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let Q=M0($);this.ensureBufferSizeToWrite(5+Q),this.writeStringHeader(Q),R0($,this.bytes,this.pos),this.pos+=Q}encodeObject($,Z){let Q=this.extensionCodec.tryToEncode($,this.context);if(Q!=null)this.encodeExtension(Q);else if(Array.isArray($))this.encodeArray($,Z);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,Z);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let Z=$.byteLength;if(Z<256)this.writeU8(196),this.writeU8(Z);else if(Z<65536)this.writeU8(197),this.writeU16(Z);else if(Z<4294967296)this.writeU8(198),this.writeU32(Z);else throw Error(`Too large binary: ${Z}`);let Q=T($);this.writeU8a(Q)}encodeArray($,Z){let Q=$.length;if(Q<16)this.writeU8(144+Q);else if(Q<65536)this.writeU8(220),this.writeU16(Q);else if(Q<4294967296)this.writeU8(221),this.writeU32(Q);else throw Error(`Too large array: ${Q}`);for(let J of $)this.doEncode(J,Z+1)}countWithoutUndefined($,Z){let Q=0;for(let J of Z)if($[J]!==void 0)Q++;return Q}encodeMap($,Z){let Q=Object.keys($);if(this.sortKeys)Q.sort();let J=this.ignoreUndefined?this.countWithoutUndefined($,Q):Q.length;if(J<16)this.writeU8(128+J);else if(J<65536)this.writeU8(222),this.writeU16(J);else if(J<4294967296)this.writeU8(223),this.writeU32(J);else throw Error(`Too large map object: ${J}`);for(let W of Q){let q=$[W];if(!(this.ignoreUndefined&&q===void 0))this.encodeString(W),this.doEncode(q,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let Q=$.data(this.pos+6),J=Q.length;if(J>=4294967296)throw Error(`Too large extension object: ${J}`);this.writeU8(201),this.writeU32(J),this.writeI8($.type),this.writeU8a(Q);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),S0(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),k(this.view,this.pos,$),this.pos+=8}writeBigUint64($){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,$),this.pos+=8}writeBigInt64($){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,$),this.pos+=8}}var S$=100,_$=2048;var B0=H(()=>{I();E()});function N($,Z){return new w(Z).encodeSharedRef($)}var A0=H(()=>{B0()});function j($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}class n{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=C$,Z=O$){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let Q=0;Q<this.maxKeyLength;Q++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,Q){let J=this.caches[Q-1];$:for(let W of J){let q=W.bytes;for(let F=0;F<Q;F++)if(q[F]!==$[Z+F])continue $;return W.str}return null}store($,Z){let Q=this.caches[$.length-1],J={bytes:$,str:Z};if(Q.length>=this.maxLengthPerKey)Q[Math.random()*Q.length|0]=J;else Q.push(J)}decode($,Z,Q){let J=this.find($,Z,Q);if(J!=null)return this.hit++,J;this.miss++;let W=l($,Z,Q),q=Uint8Array.prototype.slice.call($,Z,Z+Q);return this.store(q,W),W}}var C$=16,O$=16;var z0=H(()=>{I()});class L0{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=d,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=L,Z.readCount=0,Z.size=$,Z.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let $={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push($)}return this.stack[this.stackHeadPosition]}release($){if(this.stack[this.stackHeadPosition]!==$)throw Error("Invalid stack state. Released state is not on top of the stack.");if($.type===d){let Q=$;Q.size=0,Q.array=void 0,Q.position=0,Q.type=void 0}if($.type===L||$.type===D0){let Q=$;Q.size=0,Q.map=void 0,Q.readCount=0,Q.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class h{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=i;bytes=A$;headByte=D;stack=new L0;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??R.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??_,this.maxBinLength=$?.maxBinLength??_,this.maxArrayLength=$?.maxArrayLength??_,this.maxMapLength=$?.maxMapLength??_,this.maxExtLength=$?.maxExtLength??_,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:z$,this.mapKeyConverter=$?.mapKeyConverter??B$}clone(){return new h({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($){let Z=T($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),Q=T($),J=new Uint8Array(Z.length+Q.length);J.set(Z),J.set(Q,Z.length),this.setBuffer(J)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:Q}=this;return RangeError(`Extra ${Z.byteLength-Q} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,Q;for await(let F of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(F);try{Q=this.doDecodeSync(),Z=!0}catch(K){if(!(K instanceof RangeError))throw K}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Q}let{headByte:J,pos:W,totalPos:q}=this;throw RangeError(`Insufficient data in parsing ${j(J)} at ${q} (${W} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let Q=Z,J=-1;for await(let W of $){if(Z&&J===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(W),Q)J=this.readArraySize(),Q=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--J===0)break}catch(q){if(!(q instanceof RangeError))throw q}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let J=$-128;if(J!==0){this.pushMapState(J),this.complete();continue $}else Z={}}else if($<160){let J=$-144;if(J!==0){this.pushArrayState(J),this.complete();continue $}else Z=[]}else{let J=$-160;Z=this.decodeString(J,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let J=this.lookU8();Z=this.decodeString(J,1)}else if($===218){let J=this.lookU16();Z=this.decodeString(J,2)}else if($===219){let J=this.lookU32();Z=this.decodeString(J,4)}else if($===220){let J=this.readU16();if(J!==0){this.pushArrayState(J),this.complete();continue $}else Z=[]}else if($===221){let J=this.readU32();if(J!==0){this.pushArrayState(J),this.complete();continue $}else Z=[]}else if($===222){let J=this.readU16();if(J!==0){this.pushMapState(J),this.complete();continue $}else Z={}}else if($===223){let J=this.readU32();if(J!==0){this.pushMapState(J),this.complete();continue $}else Z={}}else if($===196){let J=this.lookU8();Z=this.decodeBinary(J,1)}else if($===197){let J=this.lookU16();Z=this.decodeBinary(J,2)}else if($===198){let J=this.lookU32();Z=this.decodeBinary(J,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let J=this.lookU8();Z=this.decodeExtension(J,1)}else if($===200){let J=this.lookU16();Z=this.decodeExtension(J,2)}else if($===201){let J=this.lookU32();Z=this.decodeExtension(J,4)}else throw new Y(`Unrecognized type byte: ${j($)}`);this.complete();let Q=this.stack;while(Q.length>0){let J=Q.top();if(J.type===d)if(J.array[J.position]=Z,J.position++,J.position===J.size)Z=J.array,Q.release(J);else continue $;else if(J.type===L){if(Z==="__proto__")throw new Y("The key __proto__ is not allowed");J.key=this.mapKeyConverter(Z),J.type=D0;continue $}else if(J.map[J.key]=Z,J.readCount++,J.readCount===J.size)Z=J.map,Q.release(J);else{J.key=null,J.type=L;continue $}}return Z}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new Y(`Unrecognized array type byte: ${j($)}`)}}pushMapState($){if($>this.maxMapLength)throw new Y(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new Y(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,Z){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,Z);return this.decodeBinary($,Z)}decodeUtf8String($,Z){if($>this.maxStrLength)throw new Y(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw T0;let Q=this.pos+Z,J;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))J=this.keyDecoder.decode(this.bytes,Q,$);else J=U0(this.bytes,Q,$);return this.pos+=Z+$,J}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new Y(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw T0;let Q=this.pos+Z,J=this.bytes.subarray(Q,Q+$);return this.pos+=Z+$,J}decodeExtension($,Z){if($>this.maxExtLength)throw new Y(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let Q=this.view.getInt8(this.pos+Z),J=this.decodeBinary($,Z+1);return this.extensionCodec.decode(J,Q,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 $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=_0(this.view,this.pos);return this.pos+=8,$}readI64(){let $=m(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}var d="array",L="map_key",D0="map_value",B$=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new Y("The type of key must be string or number but "+typeof $)},D=-1,i,A$,T0,z$;var x0=H(()=>{E();I();z0();u();i=new DataView(new ArrayBuffer(0)),A$=new Uint8Array(i.buffer);try{i.getInt8(0)}catch($){if(!($ 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")}T0=RangeError("Insufficient data"),z$=new n});function M($,Z){return new h(Z).decode($)}var I0=H(()=>{x0()});var g=H(()=>{A0();I0();E()});function r($){if(typeof $==="object"&&$!==null&&!Array.isArray($))return $;return{}}function b($){return Array.isArray($)?$:[]}function k0($){if(!($ instanceof Date))return null;let Z=new ArrayBuffer(8);return new DataView(Z).setFloat64(0,$.getTime()),new Uint8Array(Z)}function m0($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength).getFloat64(0);return new Date(Z)}function g6($){return typeof $==="string"&&D$.has($)}var s,T$,D$;var E0=H(()=>{s=class s extends Error{code;constructor($,Z,Q){super(Z,Q);this.code=$,this.name=$}};T$={WorkflowAlreadyExistsError:!0,BulkDeleteRequiresTerminalWorkflowsError:!0,BulkOperationConfirmationError:!0,WorkflowTypeNotRegisteredForRecoveryError:!0,EngineCreateNameMismatchError:!0,EngineDisposedError:!0,WorkflowNotFoundError:!0,WorkflowNotRegisteredError:!0,WorkflowConcurrencyLimitExceededError:!0,WorkflowSuspendNotSupportedError:!0,ActivityResolutionError:!0,BranchTopologyChangedError:!0,PersistedDataIncompatibleError:!0,WorkflowTimeoutError:!0,HttpClientError:!0,WorkerProtocolIncompatibleError:!0,UpdateTimeoutError:!0,UpdateValidationError:!0,WorkflowTerminalError:!0,WorkflowBuilderError:!0,VersionMismatchError:!0,EffectReplayConflictError:!0,ReviewTimeoutError:!0,AtomicStateConflictError:!0,StandardSchemaValidationError:!0,ActivityReconciliationCapabilityError:!0,ActivityReconciliationConflictError:!0,ActivityReconciliationIndeterminateError:!0,AsyncActivityTokenNotFoundError:!0,ActivityScheduleToCloseTimeoutError:!0,ActivityPerAttemptTimeoutError:!0,PayloadSizeExceededError:!0,StartOrSignalConflictError:!0,WorkflowTeardownPendingError:!0,IdempotencyKeyPurgedError:!0},D$=new Set(Object.keys(T$))});function a($){return w0.has($.constructor)}function j0($,Z){$.register({type:L$,encode(Q){if(typeof Q!=="object"||Q===null)return null;let J=w0.get(Q.constructor);if(J===void 0)return null;let W=Z(J.handlers.toJSON(Q),new Set);return N({tag:J.tag,data:W},{extensionCodec:$})},decode(Q){let J=M(Q,{extensionCodec:$});if(typeof J!=="object"||J===null||!("tag"in J))throw Error("Corrupt custom-serializer payload: missing tag.");let{tag:W,data:q}=J;if(typeof W!=="string")throw Error("Corrupt custom-serializer payload: tag is not a string.");let F=x$.get(W);if(F===void 0)throw Error(`No serializer registered for tag "${W}". Register it (with the same tag) before decoding a checkpoint that used it.`);return F.handlers.fromJSON(q)}})}var L$=100,w0,x$;var h0=H(()=>{g();w0=new Map,x$=new Map});function h$($,Z){if(Z<=200)return JSON.stringify($);return`${Z}-byte string starting ${JSON.stringify($.slice(0,120))}`}function g$($,Z){let Q=j$.encode($).byteLength;if(Q>g0)throw new t({source:$,flags:Z,sourceByteLength:Q,reason:`because source exceeds the ${g0}-byte limit.`});try{return new RegExp($,Z)}catch(J){let W=J instanceof Error?J.message:String(J);throw new t({source:$,flags:Z,sourceByteLength:Q,reason:`because ${W}`,cause:J})}}function y$($){return typeof $==="object"&&$!==null&&"__tag"in $&&$.__tag===b0}function e($,Z){if(!O($,Z))return $;return C($,new Set)}function C($,Z){if($===void 0)return b$;if($===null||typeof $!=="object")return $;if(Z.has($))return $;Z.add($);try{return f$($,Z)}finally{Z.delete($)}}function f$($,Z){if(Array.isArray($))return v$($,Z);if($ instanceof Map)return p$($,Z);if($ instanceof Set)return c$($,Z);if(y0($))return $;return l$($,Z)}function v$($,Z){let Q=Array.from({length:$.length});for(let J=0;J<$.length;J++)Q[J]=C($[J],Z);return Q}function p$($,Z){let Q=new Map;for(let[J,W]of $)Q.set(C(J,Z),C(W,Z));return Q}function c$($,Z){let Q=new Set;for(let J of $)Q.add(C(J,Z));return Q}function y0($){return $ instanceof Date||$ instanceof RegExp||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer||a($)}function l$($,Z){let Q=$,J={};for(let W of Object.keys(Q))J[W]=C(Q[W],Z);return J}function O($,Z){if($===void 0)return!0;if($===null||typeof $!=="object")return!1;if(Z.has($))return!1;if(y0($))return!1;Z.add($);try{if(Array.isArray($))return u$($,Z);if($ instanceof Map)return n$($,Z);if($ instanceof Set)return d$($,Z);return i$($,Z)}finally{Z.delete($)}}function u$($,Z){for(let Q=0;Q<$.length;Q++)if(O($[Q],Z))return!0;return!1}function n$($,Z){for(let[Q,J]of $)if(O(Q,Z)||O(J,Z))return!0;return!1}function d$($,Z){for(let Q of $)if(O(Q,Z))return!0;return!1}function i$($,Z){let Q=$;for(let J of Object.keys(Q))if(O(Q[J],Z))return!0;return!1}var I$=1,o=2,k$=3,m$=4,E$=5,w$=6,g0=65535,j$,t,V,b0,b$;var f0=H(()=>{g();E0();h0();j$=new TextEncoder;t=class t extends s{extensionType;source;flags;sourceByteLength;constructor($){super("RegExpExtensionDecodeError",`RegExp extension type ${o} could not be decoded: source=${h$($.source,$.sourceByteLength)} flags=${JSON.stringify($.flags)} ${$.reason}`,$.cause===void 0?void 0:{cause:$.cause});this.extensionType=o,this.source=$.source,this.flags=$.flags,this.sourceByteLength=$.sourceByteLength}};V=new R;j0(V,e);V.register({type:I$,encode:k0,decode:m0});V.register({type:o,encode($){if($ instanceof RegExp)return N({source:$.source,flags:$.flags});return null},decode($){let Z=r(M($)),Q=typeof Z.source==="string"?Z.source:"",J=typeof Z.flags==="string"?Z.flags:"";return g$(Q,J)}});V.register({type:k$,encode($){if($ instanceof Map){let Z=[...$.entries()];return N(Z,{extensionCodec:V})}return null},decode($){let Q=b(M($,{extensionCodec:V})).map((J)=>{let W=b(J);return[W[0],W[1]]});return new Map(Q)}});V.register({type:m$,encode($){if($ instanceof Set){let Z=[...$.values()];return N(Z,{extensionCodec:V})}return null},decode($){let Z=b(M($,{extensionCodec:V}));return new Set(Z)}});b0=Symbol("UndefinedSentinel"),b$=Object.freeze({__tag:b0});V.register({type:E$,encode($){if(y$($))return new Uint8Array(0);return null},decode(){return}});V.register({type:w$,encode($){if($ instanceof Error&&!a($))return N({name:$.name,message:$.message,stack:$.stack});return null},decode($){let Z=r(M($)),Q=typeof Z.name==="string"?Z.name:"Error",J=typeof Z.message==="string"?Z.message:"",W=typeof Z.stack==="string"?Z.stack:void 0,q=Error(J);if(q.name=Q,W!==void 0)q.stack=W;return q}})});function $0($){let Z=e($,new Set);return N(Z,{extensionCodec:V})}function Z0($){return M($,{extensionCodec:V})}var v0=H(()=>{g();f0()});function y($,Z=""){let Q=[];return x($,Z,Q,new Set),{valid:Q.length===0,errors:Q}}function r$($){let Z=Object.getPrototypeOf($);return s$(Z)&&!a$($)&&o$(Z)}function s$($){return $!==Object.prototype&&$!==null}function a$($){return Array.isArray($)||$ instanceof Date||$ instanceof RegExp||$ instanceof Map||$ instanceof Set||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer}function o$($){if(typeof $!=="object"||$===null)return!1;return Object.getOwnPropertyNames($).some((Q)=>{if(Q==="constructor")return!1;let J=Object.getOwnPropertyDescriptor($,Q);return J!==void 0&&typeof J.value==="function"})}function p0($,Z,Q,J){$.push({path:Z,value:Q,reason:J.reason,suggestion:J.suggestion})}function t$($){if(typeof $==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof $==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function e$($,Z){if($ instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if($ instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if($ instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if(Z.has($))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(r$($))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function $1($){return $ instanceof Date||$ instanceof RegExp||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer}function Z1($,Z,Q,J){for(let[W,q]of $){let F=String(W);x(q,Z?`${Z}.${F}`:F,Q,J)}}function Q1($,Z,Q,J){let W=0;for(let q of $){let F=Z?`${Z}[${W}]`:`[${W}]`;x(q,F,Q,J),W++}}function J1($,Z,Q,J){for(let W=0;W<$.length;W++){let q=Z?`${Z}[${W}]`:`[${W}]`;x($[W],q,Q,J)}}function W1($,Z,Q,J){for(let W of Object.keys($)){let q=Z?`${Z}.${W}`:W;x($[W],q,Q,J)}}function x($,Z,Q,J){if($===null||$===void 0)return;let W=t$($);if(W){p0(Q,Z,$,W);return}if(typeof $!=="object")return;let q=e$($,J);if(q){p0(Q,Z,$,q);return}J.add($);try{if($1($))return;if($ instanceof Map){Z1($,Z,Q,J);return}if($ instanceof Set){Q1($,Z,Q,J);return}if(Array.isArray($)){J1($,Z,Q,J);return}W1($,Z,Q,J)}finally{J.delete($)}}var c0=H(()=>{v0()});var l0=H(()=>{c0()});function G1($){if($===void 0)return;if(typeof $!=="number"||!Number.isInteger($)||$<0)throw Error("deleteRange limit must be a finite non-negative integer");return $===0?0:$}function q1($){let Z={},Q=!1;for(let W of["gt","gte","lt","lte"]){let q=$[W];if(q===void 0)continue;if(typeof q!=="string")throw Error("deleteRange bounds must be strings");Z[W]=q,Q=!0}if(!Q)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let J=G1($.limit);if(J!==void 0)Z.limit=J;return Z}async function u0($,Z,Q){let J=q1(Q);if($.deleteRange)return $.deleteRange(Z,J);return G0($,Z,J)}var n0=()=>{};l0();n0();N0();class d0{#$;#Z;#Q;constructor($,Z,Q={}){this.#$=$,this.#Z=Z,this.#Q=Q.disposeUnderlyingStorage??!0}async get($){let Z=await this.#$.get($);return Z===null?null:this.#Z.decode(Z)}async put($,Z){await this.#$.put($,this.#Z.encode(Z))}async delete($){await this.#$.delete($)}async*scan($,Z){for await(let[Q,J]of this.#$.scan($,Z))yield[Q,this.#Z.decode(J)]}async batch($){z("batch operations",$.length),await this.#$.batch(this.#J($))}#J($){return $.map((Q)=>{if(Q.type==="put")return{type:"put",key:Q.key,value:this.#Z.encode(Q.value)};return Q})}#W($){return $.map((Z)=>({key:Z.key,expectedValue:Z.expectedValue===null?null:this.#Z.encode(Z.expectedValue)}))}async conditionalBatch($,Z){return P0(this.#$,this.#W($),this.#J(Z))}async has($){return H0(this.#$,$)}async deletePrefix($){return V0(this.#$,$)}async deleteRange($,Z){return u0(this.#$,$,Z)}keys($,Z){return X0(this.#$,$,Z)}async count($){return Y0(this.#$,$)}[Symbol.dispose](){if(!this.#Q)return;this.#$[Symbol.dispose]()}}function q8($,Z,Q={}){return new d0($,Z,Q)}function F1($){try{let Z=JSON.stringify($);if(Z===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode(Z)}catch(Z){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:Z})}}function K1($){let Z=y($);if(!Z.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${Z.errors[0]?.reason??""}`.trim());return $0($)}function H1($){return JSON.parse(new TextDecoder().decode($))}function X1($){let Z=Z0($),Q=y(Z);if(!Q.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Q.errors[0]?.reason??""}`.trim());return Z}function F8($){return{encode(Z){return F1(Z)},decode(Z){let Q=H1(Z);return $?$(Q):Q}}}function K8($){return{encode(Z){return K1(Z)},decode(Z){let Q=X1(Z);return $?$(Q):Q}}}export{q8 as withCodec,K8 as msgpackCodec,F8 as jsonCodec};
|
|
2
|
+
var a0=Object.defineProperty;var o0=($)=>$;function t0($,Z){this[$]=o0.bind(null,Z)}var _6=($,Z)=>{for(var Q in Z)a0($,Q,{get:Z[Q],enumerable:!0,configurable:!0,set:t0.bind(Z,Q)})};var J=($,Z)=>()=>($&&(Z=$($=0)),Z);var C6=($,Z,Q)=>{if(Z!=null){if(typeof Z!=="object"&&typeof Z!=="function")throw TypeError('Object expected to be assigned to "using" declaration');let W;if(Q)W=Z[Symbol.asyncDispose];if(W===void 0)W=Z[Symbol.dispose];if(typeof W!=="function")throw TypeError("Object not disposable");$.push([Q,W,Z])}else if(Q)$.push([Q]);return Z},S6=($,Z,Q)=>{let W=(F)=>Z=Q?new SuppressedError(F,Z,"An error was suppressed during disposal"):(Q=!0,F),G=(F)=>{while(F=$.pop())try{var K=F[1]&&F[1].call(F[2]);if(F[0])return Promise.resolve(K).then(G,(H)=>(W(H),G()))}catch(H){W(H)}if(Q)throw Z};return G()};function p($,Z,Q){if(!$.capabilities()[Z])throw Error(`Feature "${Q}" requires storage capability "${Z}", but this storage backend does not provide it.`)}function e0($){let Z=$.capabilities(),Q=[];if(Z.persistence!=="local"&&Z.persistence!=="remote")Q.push(`persistence must be "local" or "remote" (got "${Z.persistence}")`);if(Z.readAfterWrite!=="linearizable")Q.push(`readAfterWrite must be "linearizable" (got "${Z.readAfterWrite}")`);if(Z.scanConsistency!=="snapshot")Q.push(`scanConsistency must be "snapshot" (got "${Z.scanConsistency}")`);if(!Z.atomicBatch)Q.push("atomicBatch must be true");if(!Z.conditionalBatch)Q.push("conditionalBatch must be true");if(Q.length>0)throw Error(`Storage is not durable enough for recovery: ${Q.join("; ")}.`)}var c="default";async function G0($,Z){return await $.get(Z)!==null}async function*O($,Z,Q){for await(let[W]of $.scan(Z,Q))yield W}async function q0($,Z){let Q=0;for await(let W of O($,Z))Q++;return Q}async function F0($,Z){let Q=[];for await(let W of O($,Z))Q.push({type:"delete",key:W});if(Q.length===0)return 0;return await $.batch(Q),Q.length}async function K0($,Z,Q){let W=[];for await(let G of O($,Z,Q))W.push({type:"delete",key:G});if(W.length===0)return 0;return await $.batch(W),W.length}var $$;var H0=J(()=>{$$=["actrec:","archive:","async-act:","attr:","audit:bulk:","blob:","budget:","budget-charged:","ev:","fleet-event-by-workflow:","fleet-event:","fleet-event-tail","idx:","lease:","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-concurrency:","wf-concurrency-holder:","wf-deadline:","wf-delayed:","wf-finalizer-state:","wf-has-services:","wf-headers:","wf-idx-","wf-teardown:","wf-teardown-deadletter:","wf-teardown-needed:","wf-terminal:"]});function z($,Z){if(Z>l)throw new X0($,Z)}function E6($){return $.length>0?$.slice(0,-1)+String.fromCharCode($.charCodeAt($.length-1)+1):"\xFF"}function k6($,Z={}){if(Z.gt!==void 0&&$<=Z.gt)return!1;if(Z.gte!==void 0&&$<Z.gte)return!1;if(Z.lt!==void 0&&$>=Z.lt)return!1;if(Z.lte!==void 0&&$>Z.lte)return!1;return!0}function m6($,Z){if($===null||Z===null)return $===Z;if($.byteLength!==Z.byteLength)return!1;for(let Q=0;Q<$.byteLength;Q++)if($[Q]!==Z[Q])return!1;return!0}async function Y0($,Z){if($.has)return $.has(Z);return G0($,Z)}function V0($,Z,Q){if($.keys)return $.keys(Z,Q);return O($,Z,Q)}async function P0($,Z){if($.count)return $.count(Z);return q0($,Z)}async function M0($,Z){if($.deletePrefix)return $.deletePrefix(Z);return F0($,Z)}async function w6($,Z){z("batch operations",Z.length),await $.batch(Z)}async function N0($,Z,Q){if(z("conditionalBatch conditions",Z.length),z("conditionalBatch operations",Q.length),p($,"conditionalBatch","storageConditionalBatch"),!$.conditionalBatch)throw Error("This storage backend reports conditionalBatch capability but does not implement the conditionalBatch() method.");return $.conditionalBatch(Z,Q)}function q($){return encodeURIComponent($)}function j6($){return decodeURIComponent($)}function h6($){try{return decodeURIComponent($)}catch{return null}}var l=1e4,I6=1e4,X0,P=($)=>String($).padStart(16,"0"),Z$="0",Q$="1",J0=($,Z,Q,W)=>`sig:${q($)}:${q(Z)}:${W}:${q(Q)}`,g6;var R0=J(()=>{H0();X0=class X0 extends Error{code="StorageBatchOperationLimitExceededError";cap=l;count;target;constructor($,Z){super(`${$} count ${Z} exceeds MAX_BATCH_OPERATIONS (${l}).`);this.name="StorageBatchOperationLimitExceededError",this.target=$,this.count=Z}};g6={workflow:($)=>`wf:${q($)}`,checkpoint:($)=>`wf:${q($)}:ckpt`,checkpointHistory:($,Z)=>`wf:${q($)}:ckpt:${String(Z).padStart(10,"0")}`,timelinePrefix:($)=>`wf:${q($)}:timeline:`,timeline:($,Z)=>`wf:${q($)}:timeline:${String(Z).padStart(10,"0")}`,schedule:($)=>`schedule:${q($)}`,scheduleTick:($,Z)=>`schedule-due:${String($).padStart(16,"0")}:${q(Z)}`,scheduleRun:($)=>`schedule-run:${q($)}`,operation:($,Z,Q)=>`op:${$}:${P(Z)}:${Q}`,operationInflight:($)=>`op:inflight:${$}`,operationQueued:($)=>`op:queued:${$}`,operationResolved:($)=>`op:resolved:${$}`,operationDeadLetterPrefix:()=>"op:dead-letter:",operationDeadLetter:($)=>`op:dead-letter:${$}`,bulkOperationAuditPrefix:()=>"audit:bulk:",bulkOperationAudit:($,Z,Q)=>`audit:bulk:${P($)}:${q(Z)}:${q(Q)}`,operationResolvedByTimePrefix:()=>"op:resolved-by-time:",operationResolvedByTime:($,Z)=>`op:resolved-by-time:${P($)}:${q(Z)}`,asyncActivity:($,Z)=>`async-act:v1:${q($)}:${q(Z)}`,activityReconciliationPrefix:($)=>`actrec:v1:${q($)}:`,activityReconciliation:($,Z,Q)=>`actrec:v1:${q($)}:${q(Z)}:${Q}`,eventPrefix:($)=>`ev:${q($)}:`,event:($,Z)=>`ev:${q($)}:${String(Z).padStart(10,"0")}`,eventHead:($)=>`ev:${q($)}:head`,eventWatermark:($)=>`ev:${q($)}:watermark`,fleetEventPrefix:()=>"fleet-event:",fleetEvent:($)=>`fleet-event:${String($).padStart(10,"0")}`,fleetEventTail:()=>"fleet-event-tail",fleetEventByWorkflowPrefix:($)=>`fleet-event-by-workflow:${q($)}:`,fleetEventByWorkflow:($,Z)=>`fleet-event-by-workflow:${q($)}:${String(Z).padStart(10,"0")}`,signal:($,Z,Q)=>J0($,Z,Q,Q$),startSignal:($,Z,Q)=>J0($,Z,Q,Z$),signalSequence:($)=>`sigseq:v1:${q($)}`,signalAcceptedResponsePrefix:($)=>`sigres:v1:${q($)}:`,signalAcceptedResponse:($,Z,Q)=>`sigres:v1:${q($)}:${q(Z)}:${q(Q)}`,deadline:($,Z)=>`wf-deadline:${P($)}:${q(Z)}`,terminalCleanup:($,Z)=>`wf-cleanup:${P($)}:${q(Z)}`,teardownTimer:($,Z)=>`wf-teardown:${P($)}:${q(Z)}`,delayedStart:($,Z)=>`wf-delayed:${P($)}:${q(Z)}`,terminalWorkflowPrefix:()=>"wf-terminal:",terminalWorkflow:($,Z)=>`wf-terminal:${P($)}:${q(Z)}`,attribute:($)=>`attr:${q($)}`,attributeIndex:($,Z,Q)=>`idx:${$}:${Z}:${q(Q)}`,tagIndex:($,Z)=>`tag:${q($)}:${q(Z)}`,updatePrefix:($)=>`upd:${q($)}:`,update:($,Z)=>`upd:${q($)}:${Z}`,updateResponse:($)=>`upr:${$}`,updateIdempotency:($,Z)=>`upk:${q($)}:${Z}`,startIdempotency:($)=>`start-idem:${q($)}`,startIdempotencySignalId:($)=>`start-idem:${$}`,livenessPrefix:()=>"liveness:",liveness:($)=>`liveness:${q($)}`,leasePrefix:()=>"lease:",leaseEpoch:()=>"lease:epoch",leaseHolder:()=>"lease:holder",budget:($,Z,Q)=>`budget:${$}:${Z}:${Q}`,review:($,Z)=>`review:${q($)}:${Z}`,workflowHeaders:($)=>`wf-headers:${q($)}`,childCancellationPrefix:($)=>`child-cancel:${q($)}:`,childCancellation:($,Z)=>`child-cancel:${q($)}:${q(Z)}`,terminalCleanupNeeded:($)=>`wf-cleanup-needed:${q($)}`,workflowConcurrency:($,Z)=>`wf-concurrency:${q($)}:${q(Z)}`,workflowConcurrencyHolder:($)=>`wf-concurrency-holder:${q($)}`,workflowHasServices:($)=>`wf-has-services:${q($)}`,finalizerState:($)=>`wf-finalizer-state:${q($)}`,teardownOwed:($)=>`wf-teardown-needed:${q($)}`,teardownDeadLetter:($)=>`wf-teardown-deadletter:${q($)}`,offload:($,Z)=>`offload:${q($)}:${Z}`,archive:($,Z)=>`archive:${q($)}:${Z}`,stateExecution:($,Z)=>`state:execution:${q($)}:${q(Z)}`,stateWorkflow:($,Z)=>`state:workflow-scope:${c}:${q($)}:${q(Z)}`,streamChunkPrefix:($,Z)=>`blob:${q($)}:${Z}:chunk:`,streamChunk:($,Z,Q)=>`blob:${q($)}:${Z}:chunk:${String(Q).padStart(10,"0")}`,streamTail:($,Z)=>`blob:${q($)}:${Z}:tail`,streamMetadata:($,Z)=>`blob:${q($)}:${Z}:meta`,budgetCharged:($)=>`budget-charged:${$}`,toolEffect:($,Z,Q)=>`tool-effect:${q($)}:${Z}:${Q}`,workflowVisibilityStatus:($,Z)=>`wf-idx-status:${q($)}:${q(Z)}`,workflowVisibilityType:($,Z)=>`wf-idx-type:${q($)}:${q(Z)}`,workflowVisibilityCreated:($,Z)=>`wf-idx-created:${P($)}:${q(Z)}`,workflowVisibilityUpdated:($,Z)=>`wf-idx-updated:${P($)}:${q(Z)}`,workflowVisibilityDeadline:($,Z)=>`wf-idx-deadline:${P($)}:${q(Z)}`,workflowVisibilityManifest:($)=>`wf-idx-manifest:${q($)}`,workflowVisibilityMetaVersion:()=>"wf-idx-meta:version",workflowVisibilityMetaBuiltAt:()=>"wf-idx-meta:built-at",workflowVisibilityMetaCursor:()=>"wf-idx-meta:cursor"}});function U0($){let Z=$.length,Q=0,W=0;while(W<Z){let G=$.charCodeAt(W++);if((G&4294967168)===0){Q++;continue}else if((G&4294965248)===0)Q+=2;else{if(G>=55296&&G<=56319){if(W<Z){let F=$.charCodeAt(W);if((F&64512)===56320)++W,G=((G&1023)<<10)+(F&1023)+65536}}if((G&4294901760)===0)Q+=3;else Q+=4}}return Q}function W$($,Z,Q){let W=$.length,G=Q,F=0;while(F<W){let K=$.charCodeAt(F++);if((K&4294967168)===0){Z[G++]=K;continue}else if((K&4294965248)===0)Z[G++]=K>>6&31|192;else{if(K>=55296&&K<=56319){if(F<W){let H=$.charCodeAt(F);if((H&64512)===56320)++F,K=((K&1023)<<10)+(H&1023)+65536}}if((K&4294901760)===0)Z[G++]=K>>12&15|224,Z[G++]=K>>6&63|128;else Z[G++]=K>>18&7|240,Z[G++]=K>>12&63|128,Z[G++]=K>>6&63|128}Z[G++]=K&63|128}}function F$($,Z,Q){G$.encodeInto($,Z.subarray(Q))}function _0($,Z,Q){if($.length>q$)F$($,Z,Q);else W$($,Z,Q)}function n($,Z,Q){let W=Z,G=W+Q,F=[],K="";while(W<G){let H=$[W++];if((H&128)===0)F.push(H);else if((H&224)===192){let A=$[W++]&63;F.push((H&31)<<6|A)}else if((H&240)===224){let A=$[W++]&63,v=$[W++]&63;F.push((H&31)<<12|A<<6|v)}else if((H&248)===240){let A=$[W++]&63,v=$[W++]&63,s0=$[W++]&63,U=(H&7)<<18|A<<12|v<<6|s0;if(U>65535)U-=65536,F.push(U>>>10&1023|55296),U=56320|U&1023;F.push(U)}else F.push(H);if(F.length>=K$)K+=String.fromCharCode(...F),F.length=0}if(F.length>0)K+=String.fromCharCode(...F);return K}function X$($,Z,Q){let W=$.subarray(Z,Z+Q);return H$.decode(W)}function C0($,Z,Q){if(Q>J$)return X$($,Z,Q);else return n($,Z,Q)}var G$,q$=50,K$=4096,H$,J$=200;var I=J(()=>{G$=new TextEncoder;H$=new TextDecoder});class _{type;data;constructor($,Z){this.type=$,this.data=Z}}var Y;var d=J(()=>{Y=class Y extends Error{constructor($){super($);let Z=Object.create(Y.prototype);Object.setPrototypeOf(this,Z),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:Y.name})}}});function S0($,Z,Q){let W=Q/4294967296,G=Q;$.setUint32(Z,W),$.setUint32(Z+4,G)}function E($,Z,Q){let W=Math.floor(Q/4294967296),G=Q;$.setUint32(Z,W),$.setUint32(Z+4,G)}function k($,Z){let Q=$.getInt32(Z),W=$.getUint32(Z+4);return Q*4294967296+W}function B0($,Z){let Q=$.getUint32(Z),W=$.getUint32(Z+4);return Q*4294967296+W}var C=4294967295;function M$({sec:$,nsec:Z}){if($>=0&&Z>=0&&$<=P$)if(Z===0&&$<=V$){let Q=new Uint8Array(4);return new DataView(Q.buffer).setUint32(0,$),Q}else{let Q=$/4294967296,W=$&4294967295,G=new Uint8Array(8),F=new DataView(G.buffer);return F.setUint32(0,Z<<2|Q&3),F.setUint32(4,W),G}else{let Q=new Uint8Array(12),W=new DataView(Q.buffer);return W.setUint32(0,Z),E(W,4,$),Q}}function N$($){let Z=$.getTime(),Q=Math.floor(Z/1000),W=(Z-Q*1000)*1e6,G=Math.floor(W/1e9);return{sec:Q+G,nsec:W-G*1e9}}function R$($){if($ instanceof Date){let Z=N$($);return M$(Z)}else return null}function U$($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength);switch($.byteLength){case 4:{let Q=Z.getUint32(0),W=0;return{sec:Q,nsec:0}}case 8:{let Q=Z.getUint32(0),W=Z.getUint32(4),G=(Q&3)*4294967296+W,F=Q>>>2;return{sec:G,nsec:F}}case 12:{let Q=k(Z,4),W=Z.getUint32(0);return{sec:Q,nsec:W}}default:throw new Y(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${$.length}`)}}function _$($){let Z=U$($);return new Date(Z.sec*1000+Z.nsec/1e6)}var Y$=-1,V$=4294967295,P$=17179869183,A0;var O0=J(()=>{d();A0={type:Y$,encode:R$,decode:_$}});var R;var m=J(()=>{O0();R=class R{static defaultCodec=new R;__brand;builtInEncoders=[];builtInDecoders=[];encoders=[];decoders=[];constructor(){this.register(A0)}register({type:$,encode:Z,decode:Q}){if($>=0)this.encoders[$]=Z,this.decoders[$]=Q;else{let W=-1-$;this.builtInEncoders[W]=Z,this.builtInDecoders[W]=Q}}tryToEncode($,Z){for(let Q=0;Q<this.builtInEncoders.length;Q++){let W=this.builtInEncoders[Q];if(W!=null){let G=W($,Z);if(G!=null){let F=-1-Q;return new _(F,G)}}}for(let Q=0;Q<this.encoders.length;Q++){let W=this.encoders[Q];if(W!=null){let G=W($,Z);if(G!=null)return new _(Q,G)}}if($ instanceof _)return $;return null}decode($,Z,Q){let W=Z<0?this.builtInDecoders[-1-Z]:this.decoders[Z];if(W)return W($,Z,Q);else return new _(Z,$)}}});function C$($){return $ instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&$ instanceof SharedArrayBuffer}function T($){if($ instanceof Uint8Array)return $;else if(ArrayBuffer.isView($))return new Uint8Array($.buffer,$.byteOffset,$.byteLength);else if(C$($))return new Uint8Array($);else return Uint8Array.from($)}class w{extensionCodec;context;useBigInt64;maxDepth;initialBufferSize;sortKeys;forceFloat32;ignoreUndefined;forceIntegerToFloat;pos;view;bytes;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??R.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.maxDepth=$?.maxDepth??S$,this.initialBufferSize=$?.initialBufferSize??B$,this.sortKeys=$?.sortKeys??!1,this.forceFloat32=$?.forceFloat32??!1,this.ignoreUndefined=$?.ignoreUndefined??!1,this.forceIntegerToFloat=$?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new w({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($){if(this.entered)return this.clone().encodeSharedRef($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode($){if(this.entered)return this.clone().encode($);try{return this.entered=!0,this.reinitializeState(),this.doEncode($,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode($,Z){if(Z>this.maxDepth)throw Error(`Too deep objects in depth ${Z}`);if($==null)this.encodeNil();else if(typeof $==="boolean")this.encodeBoolean($);else if(typeof $==="number")if(!this.forceIntegerToFloat)this.encodeNumber($);else this.encodeNumberAsFloat($);else if(typeof $==="string")this.encodeString($);else if(this.useBigInt64&&typeof $==="bigint")this.encodeBigInt64($);else this.encodeObject($,Z)}ensureBufferSizeToWrite($){let Z=this.pos+$;if(this.view.byteLength<Z)this.resizeBuffer(Z*2)}resizeBuffer($){let Z=new ArrayBuffer($),Q=new Uint8Array(Z),W=new DataView(Z);Q.set(this.bytes),this.view=W,this.bytes=Q}encodeNil(){this.writeU8(192)}encodeBoolean($){if($===!1)this.writeU8(194);else this.writeU8(195)}encodeNumber($){if(!this.forceIntegerToFloat&&Number.isSafeInteger($))if($>=0)if($<128)this.writeU8($);else if($<256)this.writeU8(204),this.writeU8($);else if($<65536)this.writeU8(205),this.writeU16($);else if($<4294967296)this.writeU8(206),this.writeU32($);else if(!this.useBigInt64)this.writeU8(207),this.writeU64($);else this.encodeNumberAsFloat($);else if($>=-32)this.writeU8(224|$+32);else if($>=-128)this.writeU8(208),this.writeI8($);else if($>=-32768)this.writeU8(209),this.writeI16($);else if($>=-2147483648)this.writeU8(210),this.writeI32($);else if(!this.useBigInt64)this.writeU8(211),this.writeI64($);else this.encodeNumberAsFloat($);else this.encodeNumberAsFloat($)}encodeNumberAsFloat($){if(this.forceFloat32)this.writeU8(202),this.writeF32($);else this.writeU8(203),this.writeF64($)}encodeBigInt64($){if($>=BigInt(0))this.writeU8(207),this.writeBigUint64($);else this.writeU8(211),this.writeBigInt64($)}writeStringHeader($){if($<32)this.writeU8(160+$);else if($<256)this.writeU8(217),this.writeU8($);else if($<65536)this.writeU8(218),this.writeU16($);else if($<4294967296)this.writeU8(219),this.writeU32($);else throw Error(`Too long string: ${$} bytes in UTF-8`)}encodeString($){let Q=U0($);this.ensureBufferSizeToWrite(5+Q),this.writeStringHeader(Q),_0($,this.bytes,this.pos),this.pos+=Q}encodeObject($,Z){let Q=this.extensionCodec.tryToEncode($,this.context);if(Q!=null)this.encodeExtension(Q);else if(Array.isArray($))this.encodeArray($,Z);else if(ArrayBuffer.isView($))this.encodeBinary($);else if(typeof $==="object")this.encodeMap($,Z);else throw Error(`Unrecognized object: ${Object.prototype.toString.apply($)}`)}encodeBinary($){let Z=$.byteLength;if(Z<256)this.writeU8(196),this.writeU8(Z);else if(Z<65536)this.writeU8(197),this.writeU16(Z);else if(Z<4294967296)this.writeU8(198),this.writeU32(Z);else throw Error(`Too large binary: ${Z}`);let Q=T($);this.writeU8a(Q)}encodeArray($,Z){let Q=$.length;if(Q<16)this.writeU8(144+Q);else if(Q<65536)this.writeU8(220),this.writeU16(Q);else if(Q<4294967296)this.writeU8(221),this.writeU32(Q);else throw Error(`Too large array: ${Q}`);for(let W of $)this.doEncode(W,Z+1)}countWithoutUndefined($,Z){let Q=0;for(let W of Z)if($[W]!==void 0)Q++;return Q}encodeMap($,Z){let Q=Object.keys($);if(this.sortKeys)Q.sort();let W=this.ignoreUndefined?this.countWithoutUndefined($,Q):Q.length;if(W<16)this.writeU8(128+W);else if(W<65536)this.writeU8(222),this.writeU16(W);else if(W<4294967296)this.writeU8(223),this.writeU32(W);else throw Error(`Too large map object: ${W}`);for(let G of Q){let F=$[G];if(!(this.ignoreUndefined&&F===void 0))this.encodeString(G),this.doEncode(F,Z+1)}}encodeExtension($){if(typeof $.data==="function"){let Q=$.data(this.pos+6),W=Q.length;if(W>=4294967296)throw Error(`Too large extension object: ${W}`);this.writeU8(201),this.writeU32(W),this.writeI8($.type),this.writeU8a(Q);return}let Z=$.data.length;if(Z===1)this.writeU8(212);else if(Z===2)this.writeU8(213);else if(Z===4)this.writeU8(214);else if(Z===8)this.writeU8(215);else if(Z===16)this.writeU8(216);else if(Z<256)this.writeU8(199),this.writeU8(Z);else if(Z<65536)this.writeU8(200),this.writeU16(Z);else if(Z<4294967296)this.writeU8(201),this.writeU32(Z);else throw Error(`Too large extension object: ${Z}`);this.writeI8($.type),this.writeU8a($.data)}writeU8($){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,$),this.pos++}writeU8a($){let Z=$.length;this.ensureBufferSizeToWrite(Z),this.bytes.set($,this.pos),this.pos+=Z}writeI8($){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,$),this.pos++}writeU16($){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,$),this.pos+=2}writeI16($){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,$),this.pos+=2}writeU32($){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,$),this.pos+=4}writeI32($){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,$),this.pos+=4}writeF32($){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,$),this.pos+=4}writeF64($){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,$),this.pos+=8}writeU64($){this.ensureBufferSizeToWrite(8),S0(this.view,this.pos,$),this.pos+=8}writeI64($){this.ensureBufferSizeToWrite(8),E(this.view,this.pos,$),this.pos+=8}writeBigUint64($){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,$),this.pos+=8}writeBigInt64($){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,$),this.pos+=8}}var S$=100,B$=2048;var z0=J(()=>{I();m()});function M($,Z){return new w(Z).encodeSharedRef($)}var T0=J(()=>{z0()});function j($){return`${$<0?"-":""}0x${Math.abs($).toString(16).padStart(2,"0")}`}class u{hit=0;miss=0;caches;maxKeyLength;maxLengthPerKey;constructor($=A$,Z=O$){this.maxKeyLength=$,this.maxLengthPerKey=Z,this.caches=[];for(let Q=0;Q<this.maxKeyLength;Q++)this.caches.push([])}canBeCached($){return $>0&&$<=this.maxKeyLength}find($,Z,Q){let W=this.caches[Q-1];$:for(let G of W){let F=G.bytes;for(let K=0;K<Q;K++)if(F[K]!==$[Z+K])continue $;return G.str}return null}store($,Z){let Q=this.caches[$.length-1],W={bytes:$,str:Z};if(Q.length>=this.maxLengthPerKey)Q[Math.random()*Q.length|0]=W;else Q.push(W)}decode($,Z,Q){let W=this.find($,Z,Q);if(W!=null)return this.hit++,W;this.miss++;let G=n($,Z,Q),F=Uint8Array.prototype.slice.call($,Z,Z+Q);return this.store(F,G),G}}var A$=16,O$=16;var D0=J(()=>{I()});class I0{stack=[];stackHeadPosition=-1;get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState($){let Z=this.getUninitializedStateFromPool();Z.type=i,Z.position=0,Z.size=$,Z.array=Array($)}pushMapState($){let Z=this.getUninitializedStateFromPool();Z.type=L,Z.readCount=0,Z.size=$,Z.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let $={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push($)}return this.stack[this.stackHeadPosition]}release($){if(this.stack[this.stackHeadPosition]!==$)throw Error("Invalid stack state. Released state is not on top of the stack.");if($.type===i){let Q=$;Q.size=0,Q.array=void 0,Q.position=0,Q.type=void 0}if($.type===L||$.type===x0){let Q=$;Q.size=0,Q.map=void 0,Q.readCount=0,Q.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}class h{extensionCodec;context;useBigInt64;rawStrings;maxStrLength;maxBinLength;maxArrayLength;maxMapLength;maxExtLength;keyDecoder;mapKeyConverter;totalPos=0;pos=0;view=r;bytes=T$;headByte=D;stack=new I0;entered=!1;constructor($){this.extensionCodec=$?.extensionCodec??R.defaultCodec,this.context=$?.context,this.useBigInt64=$?.useBigInt64??!1,this.rawStrings=$?.rawStrings??!1,this.maxStrLength=$?.maxStrLength??C,this.maxBinLength=$?.maxBinLength??C,this.maxArrayLength=$?.maxArrayLength??C,this.maxMapLength=$?.maxMapLength??C,this.maxExtLength=$?.maxExtLength??C,this.keyDecoder=$?.keyDecoder!==void 0?$.keyDecoder:D$,this.mapKeyConverter=$?.mapKeyConverter??z$}clone(){return new h({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($){let Z=T($);this.bytes=Z,this.view=new DataView(Z.buffer,Z.byteOffset,Z.byteLength),this.pos=0}appendBuffer($){if(this.headByte===D&&!this.hasRemaining(1))this.setBuffer($);else{let Z=this.bytes.subarray(this.pos),Q=T($),W=new Uint8Array(Z.length+Q.length);W.set(Z),W.set(Q,Z.length),this.setBuffer(W)}}hasRemaining($){return this.view.byteLength-this.pos>=$}createExtraByteError($){let{view:Z,pos:Q}=this;return RangeError(`Extra ${Z.byteLength-Q} of ${Z.byteLength} byte(s) found at buffer[${$}]`)}decode($){if(this.entered)return this.clone().decode($);try{this.entered=!0,this.reinitializeState(),this.setBuffer($);let Z=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return Z}finally{this.entered=!1}}*decodeMulti($){if(this.entered){yield*this.clone().decodeMulti($);return}try{this.entered=!0,this.reinitializeState(),this.setBuffer($);while(this.hasRemaining(1))yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync($){if(this.entered)return this.clone().decodeAsync($);try{this.entered=!0;let Z=!1,Q;for await(let K of $){if(Z)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(K);try{Q=this.doDecodeSync(),Z=!0}catch(H){if(!(H instanceof RangeError))throw H}this.totalPos+=this.pos}if(Z){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return Q}let{headByte:W,pos:G,totalPos:F}=this;throw RangeError(`Insufficient data in parsing ${j(W)} at ${F} (${G} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream($){return this.decodeMultiAsync($,!0)}decodeStream($){return this.decodeMultiAsync($,!1)}async*decodeMultiAsync($,Z){if(this.entered){yield*this.clone().decodeMultiAsync($,Z);return}try{this.entered=!0;let Q=Z,W=-1;for await(let G of $){if(Z&&W===0)throw this.createExtraByteError(this.totalPos);if(this.appendBuffer(G),Q)W=this.readArraySize(),Q=!1,this.complete();try{while(!0)if(yield this.doDecodeSync(),--W===0)break}catch(F){if(!(F instanceof RangeError))throw F}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){$:while(!0){let $=this.readHeadByte(),Z;if($>=224)Z=$-256;else if($<192)if($<128)Z=$;else if($<144){let W=$-128;if(W!==0){this.pushMapState(W),this.complete();continue $}else Z={}}else if($<160){let W=$-144;if(W!==0){this.pushArrayState(W),this.complete();continue $}else Z=[]}else{let W=$-160;Z=this.decodeString(W,0)}else if($===192)Z=null;else if($===194)Z=!1;else if($===195)Z=!0;else if($===202)Z=this.readF32();else if($===203)Z=this.readF64();else if($===204)Z=this.readU8();else if($===205)Z=this.readU16();else if($===206)Z=this.readU32();else if($===207)if(this.useBigInt64)Z=this.readU64AsBigInt();else Z=this.readU64();else if($===208)Z=this.readI8();else if($===209)Z=this.readI16();else if($===210)Z=this.readI32();else if($===211)if(this.useBigInt64)Z=this.readI64AsBigInt();else Z=this.readI64();else if($===217){let W=this.lookU8();Z=this.decodeString(W,1)}else if($===218){let W=this.lookU16();Z=this.decodeString(W,2)}else if($===219){let W=this.lookU32();Z=this.decodeString(W,4)}else if($===220){let W=this.readU16();if(W!==0){this.pushArrayState(W),this.complete();continue $}else Z=[]}else if($===221){let W=this.readU32();if(W!==0){this.pushArrayState(W),this.complete();continue $}else Z=[]}else if($===222){let W=this.readU16();if(W!==0){this.pushMapState(W),this.complete();continue $}else Z={}}else if($===223){let W=this.readU32();if(W!==0){this.pushMapState(W),this.complete();continue $}else Z={}}else if($===196){let W=this.lookU8();Z=this.decodeBinary(W,1)}else if($===197){let W=this.lookU16();Z=this.decodeBinary(W,2)}else if($===198){let W=this.lookU32();Z=this.decodeBinary(W,4)}else if($===212)Z=this.decodeExtension(1,0);else if($===213)Z=this.decodeExtension(2,0);else if($===214)Z=this.decodeExtension(4,0);else if($===215)Z=this.decodeExtension(8,0);else if($===216)Z=this.decodeExtension(16,0);else if($===199){let W=this.lookU8();Z=this.decodeExtension(W,1)}else if($===200){let W=this.lookU16();Z=this.decodeExtension(W,2)}else if($===201){let W=this.lookU32();Z=this.decodeExtension(W,4)}else throw new Y(`Unrecognized type byte: ${j($)}`);this.complete();let Q=this.stack;while(Q.length>0){let W=Q.top();if(W.type===i)if(W.array[W.position]=Z,W.position++,W.position===W.size)Z=W.array,Q.release(W);else continue $;else if(W.type===L){if(Z==="__proto__")throw new Y("The key __proto__ is not allowed");W.key=this.mapKeyConverter(Z),W.type=x0;continue $}else if(W.map[W.key]=Z,W.readCount++,W.readCount===W.size)Z=W.map,Q.release(W);else{W.key=null,W.type=L;continue $}}return Z}}readHeadByte(){if(this.headByte===D)this.headByte=this.readU8();return this.headByte}complete(){this.headByte=D}readArraySize(){let $=this.readHeadByte();switch($){case 220:return this.readU16();case 221:return this.readU32();default:if($<160)return $-144;else throw new Y(`Unrecognized array type byte: ${j($)}`)}}pushMapState($){if($>this.maxMapLength)throw new Y(`Max length exceeded: map length (${$}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState($)}pushArrayState($){if($>this.maxArrayLength)throw new Y(`Max length exceeded: array length (${$}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState($)}decodeString($,Z){if(!this.rawStrings||this.stateIsMapKey())return this.decodeUtf8String($,Z);return this.decodeBinary($,Z)}decodeUtf8String($,Z){if($>this.maxStrLength)throw new Y(`Max length exceeded: UTF-8 byte length (${$}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+Z+$)throw L0;let Q=this.pos+Z,W;if(this.stateIsMapKey()&&this.keyDecoder?.canBeCached($))W=this.keyDecoder.decode(this.bytes,Q,$);else W=C0(this.bytes,Q,$);return this.pos+=Z+$,W}stateIsMapKey(){if(this.stack.length>0)return this.stack.top().type===L;return!1}decodeBinary($,Z){if($>this.maxBinLength)throw new Y(`Max length exceeded: bin length (${$}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining($+Z))throw L0;let Q=this.pos+Z,W=this.bytes.subarray(Q,Q+$);return this.pos+=Z+$,W}decodeExtension($,Z){if($>this.maxExtLength)throw new Y(`Max length exceeded: ext length (${$}) > maxExtLength (${this.maxExtLength})`);let Q=this.view.getInt8(this.pos+Z),W=this.decodeBinary($,Z+1);return this.extensionCodec.decode(W,Q,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 $=this.view.getUint8(this.pos);return this.pos++,$}readI8(){let $=this.view.getInt8(this.pos);return this.pos++,$}readU16(){let $=this.view.getUint16(this.pos);return this.pos+=2,$}readI16(){let $=this.view.getInt16(this.pos);return this.pos+=2,$}readU32(){let $=this.view.getUint32(this.pos);return this.pos+=4,$}readI32(){let $=this.view.getInt32(this.pos);return this.pos+=4,$}readU64(){let $=B0(this.view,this.pos);return this.pos+=8,$}readI64(){let $=k(this.view,this.pos);return this.pos+=8,$}readU64AsBigInt(){let $=this.view.getBigUint64(this.pos);return this.pos+=8,$}readI64AsBigInt(){let $=this.view.getBigInt64(this.pos);return this.pos+=8,$}readF32(){let $=this.view.getFloat32(this.pos);return this.pos+=4,$}readF64(){let $=this.view.getFloat64(this.pos);return this.pos+=8,$}}var i="array",L="map_key",x0="map_value",z$=($)=>{if(typeof $==="string"||typeof $==="number")return $;throw new Y("The type of key must be string or number but "+typeof $)},D=-1,r,T$,L0,D$;var E0=J(()=>{m();I();D0();d();r=new DataView(new ArrayBuffer(0)),T$=new Uint8Array(r.buffer);try{r.getInt8(0)}catch($){if(!($ 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")}L0=RangeError("Insufficient data"),D$=new u});function N($,Z){return new h(Z).decode($)}var k0=J(()=>{E0()});var g=J(()=>{T0();k0();m()});function s($){if(typeof $==="object"&&$!==null&&!Array.isArray($))return $;return{}}function b($){return Array.isArray($)?$:[]}function m0($){if(!($ instanceof Date))return null;let Z=new ArrayBuffer(8);return new DataView(Z).setFloat64(0,$.getTime()),new Uint8Array(Z)}function w0($){let Z=new DataView($.buffer,$.byteOffset,$.byteLength).getFloat64(0);return new Date(Z)}function l8($){return typeof $==="string"&&x$.has($)}var a,L$,x$;var j0=J(()=>{a=class a extends Error{code;constructor($,Z,Q){super(Z,Q);this.code=$,this.name=$}};L$={WorkflowAlreadyExistsError:!0,BulkDeleteRequiresTerminalWorkflowsError:!0,BulkOperationConfirmationError:!0,WorkflowTypeNotRegisteredForRecoveryError:!0,EngineCreateNameMismatchError:!0,EngineDisposedError:!0,WorkflowNotFoundError:!0,WorkflowNotRegisteredError:!0,WorkflowConcurrencyLimitExceededError:!0,WorkflowSuspendNotSupportedError:!0,ActivityResolutionError:!0,BranchTopologyChangedError:!0,PersistedDataIncompatibleError:!0,WorkflowTimeoutError:!0,HttpClientError:!0,WorkerProtocolIncompatibleError:!0,UpdateTimeoutError:!0,UpdateValidationError:!0,WorkflowTerminalError:!0,WorkflowBuilderError:!0,VersionMismatchError:!0,EffectReplayConflictError:!0,ReviewTimeoutError:!0,AtomicStateConflictError:!0,StandardSchemaValidationError:!0,ActivityReconciliationCapabilityError:!0,ActivityReconciliationConflictError:!0,ActivityReconciliationIndeterminateError:!0,DurableActivityScopeError:!0,DurableActivityUnsupportedError:!0,AsyncActivityTokenNotFoundError:!0,ActivityScheduleToCloseTimeoutError:!0,ActivityPerAttemptTimeoutError:!0,PayloadSizeExceededError:!0,StartOrSignalConflictError:!0,WorkflowTeardownPendingError:!0,IdempotencyKeyPurgedError:!0},x$=new Set(Object.keys(L$))});function o($){return h0.has($.constructor)}function g0($,Z){$.register({type:I$,encode(Q){if(typeof Q!=="object"||Q===null)return null;let W=h0.get(Q.constructor);if(W===void 0)return null;let G=Z(W.handlers.toJSON(Q),new Set);return M({tag:W.tag,data:G},{extensionCodec:$})},decode(Q){let W=N(Q,{extensionCodec:$});if(typeof W!=="object"||W===null||!("tag"in W))throw Error("Corrupt custom-serializer payload: missing tag.");let{tag:G,data:F}=W;if(typeof G!=="string")throw Error("Corrupt custom-serializer payload: tag is not a string.");let K=E$.get(G);if(K===void 0)throw Error(`No serializer registered for tag "${G}". Register it (with the same tag) before decoding a checkpoint that used it.`);return K.handlers.fromJSON(F)}})}var I$=100,h0,E$;var b0=J(()=>{g();h0=new Map,E$=new Map});function b$($,Z){if(Z<=200)return JSON.stringify($);return`${Z}-byte string starting ${JSON.stringify($.slice(0,120))}`}function y$($,Z){let Q=g$.encode($).byteLength;if(Q>y0)throw new e({source:$,flags:Z,sourceByteLength:Q,reason:`because source exceeds the ${y0}-byte limit.`});try{return new RegExp($,Z)}catch(W){let G=W instanceof Error?W.message:String(W);throw new e({source:$,flags:Z,sourceByteLength:Q,reason:`because ${G}`,cause:W})}}function v$($){return typeof $==="object"&&$!==null&&"__tag"in $&&$.__tag===f0}function $0($,Z){if(!B($,Z))return $;return S($,new Set)}function S($,Z){if($===void 0)return f$;if($===null||typeof $!=="object")return $;if(Z.has($))return $;Z.add($);try{return p$($,Z)}finally{Z.delete($)}}function p$($,Z){if(Array.isArray($))return c$($,Z);if($ instanceof Map)return l$($,Z);if($ instanceof Set)return n$($,Z);if(v0($))return $;return d$($,Z)}function c$($,Z){let Q=Array.from({length:$.length});for(let W=0;W<$.length;W++)Q[W]=S($[W],Z);return Q}function l$($,Z){let Q=new Map;for(let[W,G]of $)Q.set(S(W,Z),S(G,Z));return Q}function n$($,Z){let Q=new Set;for(let W of $)Q.add(S(W,Z));return Q}function v0($){return $ instanceof Date||$ instanceof RegExp||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer||o($)}function d$($,Z){let Q=$,W={};for(let G of Object.keys(Q))W[G]=S(Q[G],Z);return W}function B($,Z){if($===void 0)return!0;if($===null||typeof $!=="object")return!1;if(Z.has($))return!1;if(v0($))return!1;Z.add($);try{if(Array.isArray($))return u$($,Z);if($ instanceof Map)return i$($,Z);if($ instanceof Set)return r$($,Z);return s$($,Z)}finally{Z.delete($)}}function u$($,Z){for(let Q=0;Q<$.length;Q++)if(B($[Q],Z))return!0;return!1}function i$($,Z){for(let[Q,W]of $)if(B(Q,Z)||B(W,Z))return!0;return!1}function r$($,Z){for(let Q of $)if(B(Q,Z))return!0;return!1}function s$($,Z){let Q=$;for(let W of Object.keys(Q))if(B(Q[W],Z))return!0;return!1}var k$=1,t=2,m$=3,w$=4,j$=5,h$=6,y0=65535,g$,e,V,f0,f$;var p0=J(()=>{g();j0();b0();g$=new TextEncoder;e=class e extends a{extensionType;source;flags;sourceByteLength;constructor($){super("RegExpExtensionDecodeError",`RegExp extension type ${t} could not be decoded: source=${b$($.source,$.sourceByteLength)} flags=${JSON.stringify($.flags)} ${$.reason}`,$.cause===void 0?void 0:{cause:$.cause});this.extensionType=t,this.source=$.source,this.flags=$.flags,this.sourceByteLength=$.sourceByteLength}};V=new R;g0(V,$0);V.register({type:k$,encode:m0,decode:w0});V.register({type:t,encode($){if($ instanceof RegExp)return M({source:$.source,flags:$.flags});return null},decode($){let Z=s(N($)),Q=typeof Z.source==="string"?Z.source:"",W=typeof Z.flags==="string"?Z.flags:"";return y$(Q,W)}});V.register({type:m$,encode($){if($ instanceof Map){let Z=[...$.entries()];return M(Z,{extensionCodec:V})}return null},decode($){let Q=b(N($,{extensionCodec:V})).map((W)=>{let G=b(W);return[G[0],G[1]]});return new Map(Q)}});V.register({type:w$,encode($){if($ instanceof Set){let Z=[...$.values()];return M(Z,{extensionCodec:V})}return null},decode($){let Z=b(N($,{extensionCodec:V}));return new Set(Z)}});f0=Symbol("UndefinedSentinel"),f$=Object.freeze({__tag:f0});V.register({type:j$,encode($){if(v$($))return new Uint8Array(0);return null},decode(){return}});V.register({type:h$,encode($){if($ instanceof Error&&!o($))return M({name:$.name,message:$.message,stack:$.stack});return null},decode($){let Z=s(N($)),Q=typeof Z.name==="string"?Z.name:"Error",W=typeof Z.message==="string"?Z.message:"",G=typeof Z.stack==="string"?Z.stack:void 0,F=Error(W);if(F.name=Q,G!==void 0)F.stack=G;return F}})});function Z0($){let Z=$0($,new Set);return M(Z,{extensionCodec:V})}function Q0($){return N($,{extensionCodec:V})}var c0=J(()=>{g();p0()});function y($,Z=""){let Q=[];return x($,Z,Q,new Set),{valid:Q.length===0,errors:Q}}function a$($){let Z=Object.getPrototypeOf($);return o$(Z)&&!t$($)&&e$(Z)}function o$($){return $!==Object.prototype&&$!==null}function t$($){return Array.isArray($)||$ instanceof Date||$ instanceof RegExp||$ instanceof Map||$ instanceof Set||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer}function e$($){if(typeof $!=="object"||$===null)return!1;return Object.getOwnPropertyNames($).some((Q)=>{if(Q==="constructor")return!1;let W=Object.getOwnPropertyDescriptor($,Q);return W!==void 0&&typeof W.value==="function"})}function l0($,Z,Q,W){$.push({path:Z,value:Q,reason:W.reason,suggestion:W.suggestion})}function $6($){if(typeof $==="function")return{reason:"Functions cannot be serialized.",suggestion:"Move this into ctx.run() or reconstruct it on resume."};if(typeof $==="symbol")return{reason:"Symbols cannot be serialized.",suggestion:"Use a string identifier instead of a Symbol."};return null}function Z6($,Z){if($ instanceof WeakRef)return{reason:"WeakRef cannot be serialized.",suggestion:"Store the referenced value directly instead of using a WeakRef."};if($ instanceof WeakMap)return{reason:"WeakMap cannot be serialized.",suggestion:"Use a Map instead of a WeakMap."};if($ instanceof WeakSet)return{reason:"WeakSet cannot be serialized.",suggestion:"Use a Set instead of a WeakSet."};if(Z.has($))return{reason:"Circular reference detected.",suggestion:"Remove the circular reference or restructure the data."};if(a$($))return{reason:"Class instances with methods cannot be serialized.",suggestion:"Store only the data and reconstruct the instance."};return null}function Q6($){return $ instanceof Date||$ instanceof RegExp||$ instanceof Error||$ instanceof Uint8Array||$ instanceof ArrayBuffer}function W6($,Z,Q,W){for(let[G,F]of $){let K=String(G);x(F,Z?`${Z}.${K}`:K,Q,W)}}function G6($,Z,Q,W){let G=0;for(let F of $){let K=Z?`${Z}[${G}]`:`[${G}]`;x(F,K,Q,W),G++}}function q6($,Z,Q,W){for(let G=0;G<$.length;G++){let F=Z?`${Z}[${G}]`:`[${G}]`;x($[G],F,Q,W)}}function F6($,Z,Q,W){for(let G of Object.keys($)){let F=Z?`${Z}.${G}`:G;x($[G],F,Q,W)}}function x($,Z,Q,W){if($===null||$===void 0)return;let G=$6($);if(G){l0(Q,Z,$,G);return}if(typeof $!=="object")return;let F=Z6($,W);if(F){l0(Q,Z,$,F);return}W.add($);try{if(Q6($))return;if($ instanceof Map){W6($,Z,Q,W);return}if($ instanceof Set){G6($,Z,Q,W);return}if(Array.isArray($)){q6($,Z,Q,W);return}F6($,Z,Q,W)}finally{W.delete($)}}var n0=J(()=>{c0()});var d0=J(()=>{n0()});function f($){let Z=new WeakSet,Q=(W)=>{if(K6(W))return!0;if(H6(W))return!1;if(Array.isArray(W))return J6(W,Z,Q);if(typeof W==="object")return X6(W,Z,Q);return!1};return Q($)}function HZ($){if($===void 0)return null;if($ instanceof Error)return{name:$.name,message:$.message};if(f($))return $;try{let Z=JSON.stringify($);if(Z===void 0)return W0($);let Q=JSON.parse(Z);return f(Q)?Q:W0($)}catch{return W0($)}}function K6($){if($===null)return!0;if(typeof $==="number")return Number.isFinite($)&&!Object.is($,-0);return typeof $==="string"||typeof $==="boolean"}function H6($){let Z=typeof $;return Z==="undefined"||Z==="bigint"||Z==="function"||Z==="symbol"}function J6($,Z,Q){if(Z.has($))return!1;Z.add($);for(let W of $)if(!Q(W))return!1;return Z.delete($),!0}function X6($,Z,Q){if(!Y6($))return!1;if(Z.has($))return!1;Z.add($);for(let W of Object.values($))if(!Q(W))return!1;return Z.delete($),!0}function W0($){if(typeof $==="bigint")return $.toString();if(typeof $==="symbol")return $.description??null;return null}function Y6($){if(!$||typeof $!=="object")return!1;let Z=Reflect.getPrototypeOf($);return Z===Object.prototype||Z===null}function V6($){if($===void 0)return;if(typeof $!=="number"||!Number.isInteger($)||$<0)throw Error("deleteRange limit must be a finite non-negative integer");return $===0?0:$}function P6($){let Z={},Q=!1;for(let G of["gt","gte","lt","lte"]){let F=$[G];if(F===void 0)continue;if(typeof F!=="string")throw Error("deleteRange bounds must be strings");Z[G]=F,Q=!0}if(!Q)throw Error("deleteRange requires at least one of gt/gte/lt/lte; use deletePrefix to delete a whole prefix");let W=V6($.limit);if(W!==void 0)Z.limit=W;return Z}async function u0($,Z,Q){let W=P6(Q);if($.deleteRange)return $.deleteRange(Z,W);return K0($,Z,W)}var i0=()=>{};d0();i0();R0();class r0{#$;#Z;#Q;constructor($,Z,Q={}){this.#$=$,this.#Z=Z,this.#Q=Q.disposeUnderlyingStorage??!0}async get($){let Z=await this.#$.get($);return Z===null?null:this.#Z.decode(Z)}async put($,Z){await this.#$.put($,this.#Z.encode(Z))}async delete($){await this.#$.delete($)}async*scan($,Z){for await(let[Q,W]of this.#$.scan($,Z))yield[Q,this.#Z.decode(W)]}async batch($){z("batch operations",$.length),await this.#$.batch(this.#W($))}#W($){return $.map((Q)=>{if(Q.type==="put")return{type:"put",key:Q.key,value:this.#Z.encode(Q.value)};return Q})}#G($){return $.map((Z)=>({key:Z.key,expectedValue:Z.expectedValue===null?null:this.#Z.encode(Z.expectedValue)}))}async conditionalBatch($,Z){return N0(this.#$,this.#G($),this.#W(Z))}async has($){return Y0(this.#$,$)}async deletePrefix($){return M0(this.#$,$)}async deleteRange($,Z){return u0(this.#$,$,Z)}keys($,Z){return V0(this.#$,$,Z)}async count($){return P0(this.#$,$)}[Symbol.dispose](){if(!this.#Q)return;this.#$[Symbol.dispose]()}}function RZ($,Z,Q={}){return new r0($,Z,Q)}function M6($){try{if(!f($))throw TypeError("jsonCodec only supports JSON-serializable values.");let Z=JSON.stringify($);if(Z===void 0)throw TypeError("jsonCodec only supports JSON-serializable values.");return new TextEncoder().encode(Z)}catch(Z){throw TypeError("jsonCodec only supports JSON-serializable values.",{cause:Z})}}function N6($){let Z=y($);if(!Z.valid)throw TypeError(`msgpackCodec only supports structuredClone-compatible values. ${Z.errors[0]?.reason??""}`.trim());return Z0($)}function R6($){return JSON.parse(new TextDecoder().decode($))}function U6($){let Z=Q0($),Q=y(Z);if(!Q.valid)throw TypeError(`msgpackCodec decoded a non-cloneable value. ${Q.errors[0]?.reason??""}`.trim());return Z}function UZ($){return{encode(Z){return M6(Z)},decode(Z){let Q=R6(Z);return $?$(Q):Q}}}function _Z($){return{encode(Z){return N6(Z)},decode(Z){let Q=U6(Z);return $?$(Q):Q}}}export{RZ as withCodec,_Z as msgpackCodec,UZ as jsonCodec};
|