@effect-agent/platform-cloudflare 0.1.0-beta.50 → 0.1.0-beta.51
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/dist/CloudflareBindings.d.mts +1 -0
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/CloudflareScheduling.mjs +36 -3
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.d.mts +31 -4
- package/dist/CloudflareSubscriptions.mjs +170 -11
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/CloudflareThreadClient.d.mts +97 -22
- package/dist/CloudflareThreadClient.mjs +18 -2
- package/dist/CloudflareThreadClient.mjs.map +1 -1
- package/dist/{ThreadObject-IrGuIO4a.mjs → ThreadObject-BY8axaWT.mjs} +11 -3
- package/dist/ThreadObject-BY8axaWT.mjs.map +1 -0
- package/dist/{ThreadObject-CmeEjnBK.d.mts → ThreadObject-sDr1JBCj.d.mts} +9 -4
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/prepared-admission-9rvlHI0y.mjs +71 -0
- package/dist/prepared-admission-9rvlHI0y.mjs.map +1 -0
- package/package.json +1 -1
- package/src/CloudflareBindings.ts +1 -0
- package/src/CloudflareScheduling.ts +52 -0
- package/src/CloudflareSubscriptions.ts +321 -8
- package/src/CloudflareThreadClient.ts +40 -0
- package/src/ThreadObject.ts +27 -0
- package/src/internal/prepared-admission.ts +19 -0
- package/dist/ThreadObject-IrGuIO4a.mjs.map +0 -1
- package/dist/prepared-admission-DRBhl2Sp.mjs +0 -63
- package/dist/prepared-admission-DRBhl2Sp.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThreadObject-BY8axaWT.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/internal/progress-wait.ts","../src/internal/transport.ts","../src/internal/layers.ts","../src/ThreadObject.ts"],"sourcesContent":["import { Context, Deferred, Effect, Layer, Ref, type Scope } from \"effect\";\n\n/** Cancellation tombstones are bounded hints, never durable authority. */\nconst MAX_CANCELLATION_TOMBSTONES = 1_024;\n\ntype ActiveRegistration = ReadonlySet<Deferred.Deferred<void>>;\ntype Registration = ActiveRegistration | \"cancelled\";\ntype Registrations = ReadonlyMap<string, Registration>;\n\n/**\n * Per-incarnation cancellation registry for long-lived progress RPCs. The public runtime owns\n * the actual wake registration; this host-only registry lets an interrupted Worker Effect ask\n * the Object to interrupt its scoped wait before the Worker execution context itself ends.\n */\nexport class ProgressWaitRegistry extends Context.Service<\n ProgressWaitRegistry,\n {\n /** Register a Scope-owned cancellation signal, observing any early cancel tombstone. */\n readonly subscribe: (\n waiterId: string,\n ) => Effect.Effect<Effect.Effect<void>, never, Scope.Scope>;\n /** Cancel a registered waiter, or remember a bounded early cancellation. */\n readonly cancel: (waiterId: string) => Effect.Effect<void>;\n }\n>()(\"@effect-agent/platform-cloudflare/ProgressWaitRegistry\") {\n static readonly layer: Layer.Layer<ProgressWaitRegistry> = Layer.effect(\n ProgressWaitRegistry,\n Effect.gen(function* () {\n const registrations = yield* Ref.make<Registrations>(new Map());\n\n const remove = (waiterId: string, deferred: Deferred.Deferred<void>) =>\n Ref.update(registrations, (current) => {\n const existing = current.get(waiterId);\n\n if (existing === undefined || existing === \"cancelled\" || !existing.has(deferred)) {\n return current;\n }\n const next = new Map(current);\n const active = new Set(existing);\n\n active.delete(deferred);\n if (active.size === 0) {\n next.delete(waiterId);\n } else {\n next.set(waiterId, active);\n }\n\n return next;\n });\n\n const subscribe = Effect.fn(\"ProgressWaitRegistry.subscribe\")(\n (waiterId: string): Effect.Effect<Effect.Effect<void>, never, Scope.Scope> =>\n Effect.gen(function* () {\n const deferred = yield* Deferred.make<void>();\n\n yield* Effect.addFinalizer(() => remove(waiterId, deferred));\n\n const cancelled = yield* Ref.modify(registrations, (current) => {\n const existing = current.get(waiterId);\n const next = new Map(current);\n\n if (existing === \"cancelled\") {\n return [true, current] as const;\n }\n const active = new Set(existing ?? []);\n\n active.add(deferred);\n next.set(waiterId, active);\n\n return [false, next] as const;\n });\n\n return { cancelled, deferred };\n }).pipe(\n Effect.map(({ cancelled, deferred }) =>\n cancelled ? Effect.void : Deferred.await(deferred),\n ),\n ),\n );\n\n const cancel = Effect.fn(\"ProgressWaitRegistry.cancel\")(function* (waiterId: string) {\n const waiters = yield* Ref.modify(registrations, (current) => {\n const existing = current.get(waiterId);\n const next = new Map(current);\n\n if (existing === undefined) {\n next.set(waiterId, \"cancelled\");\n let tombstones = 0;\n\n for (const registration of next.values()) {\n if (registration === \"cancelled\") tombstones += 1;\n }\n if (tombstones > MAX_CANCELLATION_TOMBSTONES) {\n for (const [id, registration] of next) {\n if (registration !== \"cancelled\") continue;\n next.delete(id);\n break;\n }\n }\n\n return [[], next] as const;\n }\n if (existing === \"cancelled\") return [[], current] as const;\n next.delete(waiterId);\n\n return [[...existing], next] as const;\n });\n\n yield* Effect.forEach(waiters, (waiter) => Deferred.succeed(waiter, undefined), {\n discard: true,\n });\n });\n\n return ProgressWaitRegistry.of({ subscribe, cancel });\n }),\n );\n}\n","import {\n ThreadPortTransport,\n portTransportFailure,\n} from \"@effect-agent/storage-cloudflare/PortRouting\";\nimport { Effect, Layer } from \"effect\";\n\nimport { ThreadObjectNamespace } from \"../CloudflareBindings.ts\";\n\n/**\n * `ThreadPortTransport` over native Durable Object JS RPC (decision D-P6-3): one\n * `portCall(envelope)` on the stub of the Object that owns the addressed Thread\n * (`namespace.idFromName(threadId)` — the identity rule, plan §1.2). The envelopes are\n * already Schema-encoded JSON, so the RPC boundary carries only structured-cloneable values;\n * the protocol module stays transport-agnostic and fetch-with-JSON remains the documented\n * fallback carrier.\n *\n * Every delivery problem — stub construction, RPC rejection, overload, deploy-in-progress —\n * surfaces as `PortTransportError` (preserving the platform stub's own `retryable` signal\n * when present) and NEVER as a fabricated answer: on `resolveAdmission` the routing layer\n * turns exactly this error into `AdmissionIndeterminate` (SUB-031).\n */\nexport const threadPortTransportLayer: Layer.Layer<\n ThreadPortTransport,\n never,\n ThreadObjectNamespace\n> = Layer.effect(ThreadPortTransport)(\n Effect.gen(function* () {\n const { namespace } = yield* ThreadObjectNamespace;\n\n return ThreadPortTransport.of({\n call: (threadId, request) =>\n Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(threadId)).portCall(request),\n catch: (cause) => portTransportFailure(threadId, cause),\n }).pipe(\n Effect.withSpan(\"CloudflarePortTransport.call\", {\n attributes: { threadId },\n }),\n ),\n });\n }),\n);\n","import { ThreadId } from \"@effect-agent/core/Identifiers\";\nimport {\n type RunContextPreparation,\n type RunCostEstimator,\n type RunToolFailureObserver,\n} from \"@effect-agent/engine/RunOptions\";\nimport {\n CurrentToolFailureObserver,\n RunContextPreparationPassthrough,\n RunToolAuthorization,\n toolFailureObserverLayer,\n} from \"@effect-agent/engine/RunOptions\";\nimport {\n type DoStorageFailpointHandler,\n type DoStorageFailpoint,\n} from \"@effect-agent/storage-cloudflare/DoStorageFailpoint\";\nimport { submissionLedgerLayer } from \"@effect-agent/storage-cloudflare/DoSubmissionLedger\";\nimport {\n threadStoreLayer,\n storageConfigLayer,\n storageFailpointLayer,\n type DoStorageInitializationError,\n type DoStorageOptions,\n} from \"@effect-agent/storage-cloudflare/DoThreadStore\";\nimport { type PortRequest, type PortResponse } from \"@effect-agent/storage-cloudflare/PortProtocol\";\nimport {\n executePortRequest,\n routedThreadStoreLayer,\n routedSubmissionLedgerLayer,\n} from \"@effect-agent/storage-cloudflare/PortRouting\";\nimport {\n compileRegistrations,\n type AgentRegistration,\n type ResolvedBinding,\n} from \"@effect-agent/thread/AgentRegistration\";\nimport { type DigestError } from \"@effect-agent/thread/Digest\";\nimport {\n DurableAgentRuntime,\n DurableRuntimeConfig,\n} from \"@effect-agent/thread/DurableAgentRuntime\";\nimport {\n DurableRuntimeFailpoint,\n type DurableRuntimeFailpointHandler,\n} from \"@effect-agent/thread/DurableFailpoint\";\nimport {\n operationAuthorizerLayer,\n type OperationAuthorizerService,\n} from \"@effect-agent/thread/OperationAuthorizer\";\nimport { ProducerId } from \"@effect-agent/thread/Records\";\nimport { type SubmissionLedger } from \"@effect-agent/thread/SubmissionLedger\";\nimport { type ThreadStore } from \"@effect-agent/thread/ThreadStore\";\nimport { ToolReconciler } from \"@effect-agent/thread/ToolReconciler\";\nimport { type WakeScheduler } from \"@effect-agent/thread/WakeScheduler\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport type { Crypto } from \"effect\";\nimport { Context, Duration, Effect, Layer, Schema } from \"effect\";\n\nimport {\n ThreadMaintenance,\n ThreadMaintenanceFailpoint,\n DurableAlarmService,\n type ThreadMaintenanceFailpointHandler,\n} from \"../Alarm.ts\";\nimport {\n ThreadObjectIdentity,\n DurableObjectContext,\n type ThreadObjectNamespace,\n} from \"../CloudflareBindings.ts\";\nimport {\n CLOUDFLARE_RUNTIME_DEFAULTS,\n CloudflareDurableRuntimeConfig,\n CloudflareDurableRuntimeConfigValue,\n CloudflarePlatformConfigError,\n} from \"../CloudflareConfig.ts\";\nimport { cloudflareWakeSchedulerLayer } from \"../WakeScheduler.ts\";\nimport { ProgressWaitRegistry } from \"./progress-wait.ts\";\nimport { threadPortTransportLayer } from \"./transport.ts\";\n\n/**\n * Raw (unvalidated) construction options for `ThreadObject.make`, mirroring\n * `NodeDurableAgentRuntimeOptions`. Optional fields default to the documented production values\n * (`CLOUDFLARE_RUNTIME_DEFAULTS`); everything is schema-decoded into\n * `CloudflareDurableRuntimeConfigValue` before any resource opens (deployment §5 gate 1).\n */\nexport interface CloudflareDurableRuntimeOptions {\n readonly deploymentId: string;\n /** Head of the minted producer identity `{producerPrefix}:{threadId}`. */\n readonly producerPrefix: string;\n /** Milliseconds; default 30s (D5). */\n readonly ownershipLeaseDuration?: number | undefined;\n /** Milliseconds; default 100. */\n readonly alarmBackoffBase?: number | undefined;\n /** Milliseconds; default 5000. */\n readonly alarmBackoffCap?: number | undefined;\n /** Milliseconds; default 1000. Bounds every alarm re-arm delay. */\n readonly wakeScanInterval?: number | undefined;\n /** Milliseconds; default 500. */\n readonly settlementPollInterval?: number | undefined;\n /** Milliseconds; default 10000. */\n readonly leaseRenewalInterval?: number | undefined;\n /** Milliseconds; default 500. */\n readonly abortPollInterval?: number | undefined;\n /** Deployment-owned pricing authority used by durable cost budgets and settlements. */\n readonly estimateCostMicrousd?: RunCostEstimator | undefined;\n /** Closed trusted Tool failure reporting. Omission masks ambient observers at construction. */\n readonly toolFailureObserver?: RunToolFailureObserver | undefined;\n /** Milliseconds; default 25. */\n readonly observationPollInterval?: number | undefined;\n /** Bytes; default just under the 2 MB platform value limit. */\n readonly maxStoredValueBytes?: number | undefined;\n /** Default false. */\n readonly verifyOnOpen?: boolean | undefined;\n /** Nonterminal Submissions per lane before admission refuses; default 256. */\n readonly maxQueueDepthPerLane?: number | undefined;\n /** Encoded input bytes per Submission; default = the stored-value bound. */\n readonly maxInputBytes?: number | undefined;\n /** `ctx.storage.sql.databaseSize` ceiling at admission; default 9 GB (10 GB platform cap). */\n readonly maxDatabaseBytes?: number | undefined;\n /**\n * Durable Object storage fault injection (`ledger:*` / `append:*` locations). Handlers are\n * constructed per incarnation WITH the live `DurableObjectState`, so eviction harnesses can\n * map an armed hit to `ctx.abort()` — the platform's real failure mode. Default none.\n */\n readonly storageFailpoint?: ((ctx: DurableObjectState) => DoStorageFailpointHandler) | undefined;\n /** Coordinator fault injection (`submit:*` / `terminalize:*` locations); default none. */\n readonly runtimeFailpoint?:\n | ((ctx: DurableObjectState) => DurableRuntimeFailpointHandler)\n | undefined;\n /** Thread-maintenance generation/alarm fault injection; default none. */\n readonly maintenanceFailpoint?:\n | ((ctx: DurableObjectState) => ThreadMaintenanceFailpointHandler)\n | undefined;\n /** Host-supplied fail-closed authorization policy; defaults to service possession. */\n readonly operationAuthorizer?: OperationAuthorizerService | undefined;\n /**\n * Reconciliation policy consulted for open ordinary Tool Calls before an Unknown Outcome\n * is recorded (durability §10, DUR-009). Defaults to the fail-closed\n * `ToolReconciler.uncertain`.\n */\n readonly toolReconciler?: Layer.Layer<ToolReconciler> | undefined;\n}\n\n/** Services supplied before the application graph is built, including its dependencies. */\nexport type CloudflareBootstrapServices =\n | CloudflareDurableRuntimeConfig\n | ThreadObjectIdentity\n | DurableRuntimeConfig\n | Crypto.Crypto\n | DoStorageFailpoint\n | DurableRuntimeFailpoint\n | ThreadMaintenanceFailpoint\n | RunContextPreparation\n | RunToolAuthorization\n | ToolReconciler;\n\n/** Every construction failure of the assembled Cloudflare durable runtime stack. */\nexport type CloudflareDurableRuntimeInitializationError =\n | CloudflarePlatformConfigError\n | DigestError\n | DoStorageInitializationError;\n\n/** The services `ThreadObject.layer` provides. */\nexport type CloudflareDurableRuntimeServices =\n | DurableAgentRuntime\n | SubmissionLedger\n | ThreadStore\n | WakeScheduler\n | DurableAlarmService\n | ThreadMaintenance\n | ThreadObjectPorts\n | ProgressWaitRegistry;\n\n/**\n * Owner-side execution port for a `portCall` request the wire endpoint has already decoded.\n * It executes against THIS Object's LOCAL port facets — never the routed decorators, so a\n * request cannot bounce between Objects — and returns the typed response for the endpoint to\n * encode.\n */\nexport class ThreadObjectPorts extends Context.Service<\n ThreadObjectPorts,\n {\n readonly handle: (request: PortRequest) => Effect.Effect<PortResponse>;\n }\n>()(\"@effect-agent/platform-cloudflare/ThreadObjectPorts\") {}\n\nconst decodeConfigValue = Schema.decodeUnknownEffect(CloudflareDurableRuntimeConfigValue);\nconst decodeThreadId = Schema.decodeUnknownEffect(ThreadId);\nconst decodeProducerId = Schema.decodeUnknownEffect(ProducerId);\n\nconst configFromOptions = (\n options: CloudflareDurableRuntimeOptions,\n): Effect.Effect<CloudflareDurableRuntimeConfigValue, CloudflarePlatformConfigError> =>\n decodeConfigValue({\n deploymentId: options.deploymentId,\n producerPrefix: options.producerPrefix,\n ownershipLeaseDuration:\n options.ownershipLeaseDuration ?? CLOUDFLARE_RUNTIME_DEFAULTS.ownershipLeaseDuration,\n alarmBackoffBase: options.alarmBackoffBase ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffBase,\n alarmBackoffCap: options.alarmBackoffCap ?? CLOUDFLARE_RUNTIME_DEFAULTS.alarmBackoffCap,\n wakeScanInterval: options.wakeScanInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.wakeScanInterval,\n settlementPollInterval:\n options.settlementPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.settlementPollInterval,\n leaseRenewalInterval:\n options.leaseRenewalInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.leaseRenewalInterval,\n abortPollInterval: options.abortPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.abortPollInterval,\n observationPollInterval:\n options.observationPollInterval ?? CLOUDFLARE_RUNTIME_DEFAULTS.observationPollInterval,\n maxStoredValueBytes:\n options.maxStoredValueBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxStoredValueBytes,\n verifyOnOpen: options.verifyOnOpen ?? CLOUDFLARE_RUNTIME_DEFAULTS.verifyOnOpen,\n limits: {\n maxQueueDepthPerLane:\n options.maxQueueDepthPerLane ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxQueueDepthPerLane,\n maxInputBytes: Math.min(\n options.maxInputBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxInputBytes,\n options.maxStoredValueBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxStoredValueBytes,\n ),\n maxDatabaseBytes: options.maxDatabaseBytes ?? CLOUDFLARE_RUNTIME_DEFAULTS.maxDatabaseBytes,\n },\n }).pipe(\n Effect.mapError((error) =>\n CloudflarePlatformConfigError.make({\n message: `Invalid Cloudflare durable runtime configuration: ${error.message}`,\n cause: error,\n }),\n ),\n );\n\n/**\n * The Thread this Object owns, from the Object identity rule (plan §1.2): Thread\n * Objects are addressed exclusively by `idFromName(threadId)`, so `ctx.id.name` IS the\n * Thread ID. An unnamed Object (from `newUniqueId`) is a deployment error, not a lane.\n */\nconst threadIdFromState = (\n ctx: DurableObjectState,\n): Effect.Effect<ThreadId, CloudflarePlatformConfigError> =>\n ctx.id.name === undefined\n ? Effect.fail(\n CloudflarePlatformConfigError.make({\n message:\n \"This Durable Object was not created via idFromName(threadId); Thread \" +\n \"Objects must be addressed by their Thread identity (plan §1.2).\",\n }),\n )\n : decodeThreadId(ctx.id.name).pipe(\n Effect.mapError((error) =>\n CloudflarePlatformConfigError.make({\n message: `The Durable Object name is not a valid ThreadId: ${error.message}`,\n cause: error,\n }),\n ),\n );\n\n/**\n * Validate deployment settings and derive services before building application dependencies.\n * The native class factory builds this Layer inside its constructor gate. Custom Effect hosts\n * can provide it around the complete application Layer with the native context already supplied.\n */\nexport const layerConfig = (\n options: CloudflareDurableRuntimeOptions,\n): Layer.Layer<CloudflareBootstrapServices, CloudflarePlatformConfigError, DurableObjectContext> =>\n Layer.unwrap(\n Effect.gen(function* () {\n const { ctx } = yield* DurableObjectContext;\n const config = yield* configFromOptions(options);\n const threadId = yield* threadIdFromState(ctx);\n\n const producerId = yield* decodeProducerId(`${config.producerPrefix}:${threadId}`).pipe(\n Effect.mapError((error) =>\n CloudflarePlatformConfigError.make({\n message: `The minted producer identity is invalid: ${error.message}`,\n cause: error,\n }),\n ),\n );\n\n return Layer.mergeAll(\n Layer.succeed(CloudflareDurableRuntimeConfig, config),\n Layer.succeed(ThreadObjectIdentity, { threadId, producerId }),\n DurableRuntimeConfig.layer({\n deploymentId: config.deploymentId,\n producerId,\n settlementPollInterval: Duration.millis(config.settlementPollInterval),\n leaseRenewalInterval: Duration.millis(config.leaseRenewalInterval),\n abortPollInterval: Duration.millis(config.abortPollInterval),\n ...(options.estimateCostMicrousd === undefined\n ? {}\n : { estimateCostMicrousd: options.estimateCostMicrousd }),\n }),\n BrowserCrypto.layer,\n storageFailpointLayer({ storage: ctx.storage, failpoint: options.storageFailpoint?.(ctx) }),\n options.runtimeFailpoint === undefined\n ? DurableRuntimeFailpoint.layer\n : Layer.succeed(DurableRuntimeFailpoint, { hit: options.runtimeFailpoint(ctx) }),\n options.maintenanceFailpoint === undefined\n ? ThreadMaintenanceFailpoint.layer\n : Layer.succeed(ThreadMaintenanceFailpoint, {\n hit: options.maintenanceFailpoint(ctx),\n }),\n options.toolReconciler ?? ToolReconciler.uncertain,\n options.operationAuthorizer === undefined\n ? Layer.empty\n : operationAuthorizerLayer(options.operationAuthorizer),\n options.toolFailureObserver === undefined\n ? Layer.succeed(CurrentToolFailureObserver, undefined)\n : toolFailureObserverLayer(options.toolFailureObserver),\n RunContextPreparationPassthrough,\n RunToolAuthorization.allowAll,\n );\n }),\n );\n\n/**\n * Register typed Agents and version declarations. Hashing and dependency capture happen in\n * this Layer's Scope, after application Layers have been provided. Every Agent's instruction,\n * Tool, Schema, and model requirements remain visible until satisfied by Layer composition.\n * Use Layer.unwrap for registration values that need effectful application setup.\n */\nexport const layer = <const Entries extends ReadonlyArray<AgentRegistration>>(\n registrations: Entries,\n) => Layer.unwrap(Effect.map(compileRegistrations(registrations), layerFromBindings));\n\n/**\n * Assemble the durable runtime from already-resolved Agent Bindings.\n * Use `ThreadObject.layer` to compile typed Agent registrations instead.\n * Supply host services through `ThreadObject.make` or `ThreadObject.layerConfig` and\n * the Durable Object context and namespace Layers when composing a custom host.\n */\nexport const layerFromBindings = (\n bindings: ReadonlyArray<ResolvedBinding>,\n): Layer.Layer<\n CloudflareDurableRuntimeServices,\n DoStorageInitializationError,\n DurableObjectContext | ThreadObjectNamespace | CloudflareBootstrapServices\n> =>\n Layer.unwrap(\n Effect.gen(function* () {\n const { ctx } = yield* DurableObjectContext;\n const config = yield* CloudflareDurableRuntimeConfig;\n const { threadId } = yield* ThreadObjectIdentity;\n\n const storageOptions: DoStorageOptions = {\n storage: ctx.storage,\n observationPollInterval: config.observationPollInterval,\n ownershipLeaseDuration: config.ownershipLeaseDuration,\n maxStoredValueBytes: config.maxStoredValueBytes,\n verifyOnOpen: config.verifyOnOpen,\n };\n\n const infrastructure = Layer.mergeAll(\n storageConfigLayer(storageOptions),\n SqliteClient.layer({ storage: ctx.storage }),\n );\n\n // The same local ports serve routed decorators and owner-side RPC execution.\n // The RPC executor must never receive routed ports and bounce requests between Objects.\n const localPorts = Layer.mergeAll(threadStoreLayer, submissionLedgerLayer).pipe(\n Layer.provide(infrastructure),\n );\n\n const portsEndpointLayer = Layer.effect(ThreadObjectPorts)(\n Effect.gen(function* () {\n const local = yield* Effect.context<SubmissionLedger | ThreadStore>();\n\n return ThreadObjectPorts.of({\n handle: (request) => executePortRequest(request).pipe(Effect.provide(local)),\n });\n }),\n ).pipe(Layer.provide(localPorts));\n\n const routedPorts = Layer.mergeAll(\n routedSubmissionLedgerLayer({ localThreadId: threadId }),\n routedThreadStoreLayer({ localThreadId: threadId }),\n ).pipe(Layer.provide(localPorts), Layer.provide(threadPortTransportLayer));\n\n const base = Layer.mergeAll(DurableAlarmService.layer, ProgressWaitRegistry.layer);\n\n const runtimeStack = DurableAgentRuntime.layerWithBindings(bindings).pipe(\n Layer.provideMerge(routedPorts),\n Layer.provideMerge(cloudflareWakeSchedulerLayer),\n Layer.provideMerge(base),\n );\n\n return Layer.mergeAll(\n runtimeStack,\n ThreadMaintenance.layer.pipe(Layer.provide(runtimeStack)),\n portsEndpointLayer,\n );\n }),\n );\n","import { type AgentId } from \"@effect-agent/core/Identifiers\";\nimport { SubmissionId } from \"@effect-agent/core/Identifiers\";\nimport {\n decodePortRequest,\n encodePortResponse,\n type PortRequest,\n} from \"@effect-agent/storage-cloudflare/PortProtocol\";\nimport {\n IntegrityReport,\n ObligationReport,\n ObligationThresholds,\n RecoveryExplanation,\n RetryCommand,\n RetryRefused,\n} from \"@effect-agent/thread/Admin\";\nimport { DigestError } from \"@effect-agent/thread/Digest\";\nimport {\n DurableAgentRuntime,\n RecoveryReport,\n type DurableSubmitAgent,\n} from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { DurableRuntimeFailpointError } from \"@effect-agent/thread/DurableFailpoint\";\nimport {\n OperationAuthorizationRequest,\n OperationAuthorizer,\n OperationDenied,\n} from \"@effect-agent/thread/OperationAuthorizer\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport { RunJournalError } from \"@effect-agent/thread/RunJournal\";\nimport {\n AdmissionPolicyError,\n LedgerError,\n OwnershipLost,\n SettlementConflict,\n SubmissionLedger,\n SubmissionLookupByKey,\n} from \"@effect-agent/thread/SubmissionLedger\";\nimport {\n AppendConflict,\n ThreadNotMaterialized,\n ThreadRead,\n ThreadStore,\n ThreadStoreError,\n FenceRejected,\n} from \"@effect-agent/thread/ThreadStore\";\nimport { WakeScheduler } from \"@effect-agent/thread/WakeScheduler\";\nimport { Effect, Layer, Option, Schema, Stream } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectState as EffectCfDurableObjectState,\n WorkerEnvironment,\n} from \"effect-cf\";\n\nimport {\n ThreadMaintenance,\n DurableAlarmError,\n DurableAlarmService,\n type MaintenancePassFailure,\n} from \"./Alarm.ts\";\nimport {\n ThreadObjectIdentity,\n DurableObjectContext,\n ThreadObjectNamespace,\n threadNamespaceFromEnv,\n type CloudflareBindingError,\n} from \"./CloudflareBindings.ts\";\nimport { AdmissionLimitExceeded, CloudflareDurableRuntimeConfig } from \"./CloudflareConfig.ts\";\nimport {\n AbortRecorded,\n ApprovalRecorded,\n HostFailed,\n HostProtocolError,\n ObservedPage,\n ProgressObserved,\n ProgressCancelled,\n SettlementReached,\n SubmissionStatusResponse,\n SubmitSucceeded,\n UnknownResolutionRecorded,\n boundHostDiagnostic,\n decodeAbortCommand,\n decodeAwaitProgressRequest,\n decodeCancelProgressRequest,\n decodeApprovalDecisionCommand,\n decodeObservePageRequest,\n decodeReceipt,\n decodeSubmitRequest,\n decodeUnknownResolutionCommand,\n encodeHostResponse,\n type HostFailure,\n type HostResponse,\n} from \"./CloudflareThreadClient.ts\";\nimport {\n layerConfig,\n ThreadObjectPorts,\n type CloudflareDurableRuntimeInitializationError,\n type CloudflareDurableRuntimeOptions,\n type CloudflareDurableRuntimeServices,\n type CloudflareBootstrapServices,\n} from \"./internal/layers.ts\";\nimport { ProgressWaitRegistry } from \"./internal/progress-wait.ts\";\n\nexport {\n layer,\n layerConfig,\n type CloudflareDurableRuntimeOptions as RuntimeOptions,\n type CloudflareDurableRuntimeServices as Services,\n type CloudflareDurableRuntimeInitializationError as InitializationError,\n type CloudflareBootstrapServices as BootstrapServices,\n} from \"./internal/layers.ts\";\n\n/**\n * `ThreadObject.make(application, options)` — the Thread Durable Object\n * (plan §1.4,\n * D-P6-1): a factory returning a class that applications export from their Worker entry.\n * One SQLite-backed Object per Thread is the serialized owner (durability §6); the\n * Object never runs `runResolvedWorker`'s infinite loop — each ingress event or alarm runs\n * ONE bounded `runRecovery` + `processThreadHead` pass, and the persisted alarm\n * (the single multiplexed slot, D-P6-2) finishes accepted work across evictions WITHOUT any\n * incoming request.\n *\n * Constructor gate (`blockConcurrencyWhile`) is LOCAL-ONLY: schema migration and the\n * exact-version check, configuration decode, and the defensive ensure-alarm half of the\n * alarm invariant. It deliberately does NOT run the recovery pass: parent recovery can\n * require child-Object reads and vice versa, and two Objects blocked in constructor gates\n * awaiting each other's RPC would deadlock (plan §1.4). Instead every pass runs\n * `runRecovery` BEFORE any claim, so reconciliation still strictly precedes new work.\n */\n\n/** Construction options for one deployed Thread Object class. */\nexport interface Options<\n ApplicationServices = never,\n EventServices = never,\n EventLayerError = never,\n> extends CloudflareDurableRuntimeOptions {\n /** Accept transient native RPC tracing through effect-cf; disabled by default. */\n readonly rpcTracing?: boolean;\n /**\n * Name of the Worker `env` binding carrying THIS class's `DurableObjectNamespace` — the\n * Object's route back to sibling Thread Objects for the WP2 cross-Object port calls\n * and remote wakes (DEPLOY-010: the binding enters through a Layer, never ambiently).\n */\n readonly namespaceBinding: string;\n /** Acquired and finalized per native event, with access to the complete application runtime. */\n readonly eventLayer?: Layer.Layer<\n EventServices,\n EventLayerError,\n | RuntimeServices\n | ApplicationServices\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n >;\n}\n\ntype EndpointServices =\n | CloudflareDurableRuntimeServices\n | CloudflareBootstrapServices\n | DurableObjectContext;\ntype RuntimeServices = EndpointServices | ThreadObjectNamespace;\ntype ThreadObjectInitializationError =\n | CloudflareDurableRuntimeInitializationError\n | CloudflareBindingError\n | MaintenancePassFailure;\n\n/** Classify only a decoded port request so new protocol members cannot bypass pre-arming. */\nconst isMutatingPortRequest = (request: PortRequest): boolean => {\n switch (request._tag) {\n case \"LedgerAdmit\":\n case \"LedgerMarkReady\":\n case \"LedgerRequestAbort\":\n case \"LedgerRecordChildSettled\":\n case \"StoreMaterialize\":\n case \"StoreAppend\":\n return true;\n case \"LedgerLookup\":\n case \"LedgerResolveAdmission\":\n case \"StoreReadPage\":\n case \"StoreInspectTail\":\n case \"StoreExport\":\n return false;\n }\n request satisfies never;\n\n return false;\n};\n\n/** The literal encoded `PortFailed(PortProtocolError)` fallback (same shape as WP2's). */\nconst encodedPortProtocolFailure = (message: string): unknown => ({\n _tag: \"PortFailed\",\n failure: { _tag: \"PortProtocolError\", message: boundHostDiagnostic(message) },\n});\n\nconst protocolFailure = (context: string) => (error: { readonly message: string }) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`${context}: ${error.message}`),\n });\n\n/** Fold one endpoint's typed failures into the uniform `HostResponse` envelope. */\nconst respond = <Result extends HostResponse, Failure extends HostFailure>(\n effect: Effect.Effect<Result, Failure, EndpointServices>,\n): Effect.Effect<HostResponse, never, EndpointServices> =>\n effect.pipe(\n Effect.map((result): HostResponse => result),\n Effect.catch((failure) => Effect.succeed<HostResponse>(HostFailed.make({ failure }))),\n );\n\n/** Encode the response envelope; an unencodable response degrades to a protocol failure. */\nconst encodeResponse = (response: HostResponse): Effect.Effect<unknown> =>\n encodeHostResponse(response).pipe(\n Effect.catch((error) =>\n Effect.succeed<unknown>({\n _tag: \"HostFailed\",\n failure: {\n _tag: \"HostProtocolError\",\n message: boundHostDiagnostic(`The host response could not be encoded: ${error.message}`),\n },\n }),\n ),\n );\n\nconst utf8Bytes = (value: PersistedJson): number =>\n new TextEncoder().encode(JSON.stringify(value)).length;\n\n/**\n * The admission-limits gate, BEFORE `runtime.submit` touches the ledger (exit gate\n * \"resource limits are checked before admission\"; DEPLOY-007). A replayed idempotency key is\n * exempt: its accepted-work obligation already exists, and returning the original Receipt\n * consumes no new quota. Refusals are typed `AdmissionLimitExceeded` and nothing is written.\n */\nconst gateAdmissionLimits = Effect.fn(\"ThreadObject.gateAdmissionLimits\")(function* (request: {\n readonly principal: SubmissionLookupByKey[\"principal\"];\n readonly idempotencyKey: SubmissionLookupByKey[\"idempotencyKey\"];\n readonly inputPayload: PersistedJson;\n}) {\n const identity = yield* ThreadObjectIdentity;\n const config = yield* CloudflareDurableRuntimeConfig;\n const ledger = yield* SubmissionLedger;\n const { ctx } = yield* DurableObjectContext;\n\n const existing = yield* ledger.lookup(\n SubmissionLookupByKey.make({\n threadId: identity.threadId,\n principal: request.principal,\n idempotencyKey: request.idempotencyKey,\n }),\n );\n\n if (Option.isSome(existing)) return;\n\n const inputBytes = utf8Bytes(request.inputPayload);\n\n if (inputBytes > config.limits.maxInputBytes) {\n return yield* AdmissionLimitExceeded.make({\n limit: \"input-bytes\",\n actual: inputBytes,\n maximum: config.limits.maxInputBytes,\n });\n }\n\n // One Thread per Object (durability §5): the local scan IS this lane's queue.\n const nonterminal = yield* Stream.runCollect(ledger.scanNonterminal);\n\n if (nonterminal.length >= config.limits.maxQueueDepthPerLane) {\n return yield* AdmissionLimitExceeded.make({\n limit: \"queue-depth\",\n actual: nonterminal.length,\n maximum: config.limits.maxQueueDepthPerLane,\n });\n }\n\n const databaseBytes = yield* Effect.sync(() => ctx.storage.sql.databaseSize);\n\n if (databaseBytes > config.limits.maxDatabaseBytes) {\n return yield* AdmissionLimitExceeded.make({\n limit: \"database-bytes\",\n actual: databaseBytes,\n maximum: config.limits.maxDatabaseBytes,\n });\n }\n});\n\n/**\n * The submit-capable projection of an Agent Binding on the OBJECT side: the input arrived\n * already encoded through the real input schema on the Worker side (`client.ts`), so the\n * Object admits the canonical `PersistedJson` payload as-is; the resolved Binding re-derives\n * everything else from the stored `(agentId, agentDigests)` at claim time (SUB-023).\n */\nconst passthroughSubmitAgent = (agentId: AgentId): DurableSubmitAgent<typeof PersistedJson> => ({\n definition: {\n id: agentId,\n input: PersistedJson,\n },\n});\n\nconst submitEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeSubmitRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The submit request could not be decoded\")),\n Effect.flatMap((request) =>\n Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const maintenance = yield* ThreadMaintenance;\n const runtime = yield* DurableAgentRuntime;\n\n yield* gateAdmissionLimits(request);\n\n // Alarm invariant: the generation + alarm commit BEFORE the admission, and maintenance\n // cannot acknowledge that generation until this mutation leaves its public RPC seam.\n const receipt = yield* maintenance.withMutation(\n runtime.submit(passthroughSubmitAgent(request.agentId), request.inputPayload, {\n threadId: identity.threadId,\n principal: request.principal,\n idempotencyKey: request.idempotencyKey,\n ...(request.admissionGroup === undefined\n ? {}\n : { admissionGroup: request.admissionGroup }),\n ...(request.admissionFence === undefined\n ? {}\n : { admissionFence: request.admissionFence }),\n definitions: request.definitions,\n }),\n );\n\n return SubmitSucceeded.make({ receipt });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst submissionStatusEndpoint = (\n encoded: unknown,\n): Effect.Effect<unknown, never, EndpointServices> =>\n decodeReceipt(encoded).pipe(\n Effect.mapError(protocolFailure(\"The receipt could not be decoded\")),\n Effect.flatMap((receipt) =>\n Effect.gen(function* () {\n const runtime = yield* DurableAgentRuntime;\n\n return SubmissionStatusResponse.make({ status: yield* runtime.submissionStatus(receipt) });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst awaitSettlementEndpoint = (\n encoded: unknown,\n): Effect.Effect<unknown, never, EndpointServices> =>\n decodeReceipt(encoded).pipe(\n Effect.mapError(protocolFailure(\"The receipt could not be decoded\")),\n Effect.flatMap((receipt) =>\n Effect.gen(function* () {\n const runtime = yield* DurableAgentRuntime;\n const settlement = yield* runtime.awaitSettlement(receipt);\n\n return SettlementReached.make({ settlement });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst awaitProgressEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeAwaitProgressRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The progress request could not be decoded\")),\n Effect.flatMap((request) =>\n Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const runtime = yield* DurableAgentRuntime;\n const registry = yield* ProgressWaitRegistry;\n\n yield* Effect.scoped(\n Effect.gen(function* () {\n const cancelled = yield* registry.subscribe(request.waiterId);\n\n yield* Effect.raceFirst(\n runtime.awaitProgress(identity.threadId, request.afterSequence),\n cancelled,\n );\n }),\n );\n\n return ProgressObserved.make();\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst cancelProgressEndpoint = (\n encoded: unknown,\n): Effect.Effect<unknown, never, EndpointServices> =>\n decodeCancelProgressRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The progress cancellation could not be decoded\")),\n Effect.flatMap((request) =>\n Effect.gen(function* () {\n const registry = yield* ProgressWaitRegistry;\n\n yield* registry.cancel(request.waiterId);\n\n return ProgressCancelled.make();\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst observePageEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeObservePageRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The observe request could not be decoded\")),\n Effect.flatMap((request) =>\n Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const store = yield* ThreadStore;\n // The same fail-closed authorization seam the runtime's `observe` consults (P7 WP1);\n // the default reference preserves the possession behavior.\n const authorizer = yield* OperationAuthorizer;\n\n yield* authorizer.authorize(\n OperationAuthorizationRequest.make({\n operation: \"observe\",\n threadId: identity.threadId,\n }),\n );\n\n const records = yield* Stream.runCollect(\n store.read(\n ThreadRead.make({\n threadId: identity.threadId,\n ...(request.afterSequence === undefined\n ? {}\n : { afterSequence: request.afterSequence }),\n limit: request.limit,\n }),\n ),\n );\n\n return ObservedPage.make({ records: [...records] });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst abortEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeAbortCommand(encoded).pipe(\n Effect.mapError(protocolFailure(\"The abort command could not be decoded\")),\n Effect.flatMap((command) =>\n Effect.gen(function* () {\n const maintenance = yield* ThreadMaintenance;\n const runtime = yield* DurableAgentRuntime;\n const intent = yield* maintenance.withMutation(runtime.abort(command));\n\n return AbortRecorded.make({ intent });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst resolveApprovalEndpoint = (\n encoded: unknown,\n): Effect.Effect<unknown, never, EndpointServices> =>\n decodeApprovalDecisionCommand(encoded).pipe(\n Effect.mapError(protocolFailure(\"The approval command could not be decoded\")),\n Effect.flatMap((command) =>\n Effect.gen(function* () {\n const maintenance = yield* ThreadMaintenance;\n const runtime = yield* DurableAgentRuntime;\n const intent = yield* maintenance.withMutation(runtime.resolveApproval(command));\n\n return ApprovalRecorded.make({ intent });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\nconst resolveUnknownEndpoint = (\n encoded: unknown,\n): Effect.Effect<unknown, never, EndpointServices> =>\n decodeUnknownResolutionCommand(encoded).pipe(\n Effect.mapError(protocolFailure(\"The resolution command could not be decoded\")),\n Effect.flatMap((command) =>\n Effect.gen(function* () {\n const maintenance = yield* ThreadMaintenance;\n const runtime = yield* DurableAgentRuntime;\n const intent = yield* maintenance.withMutation(runtime.resolveUnknown(command));\n\n return UnknownResolutionRecorded.make({ intent });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\n// ---------------------------------------------------------------------------\n// P7 administrative entry points (plan §3): explain/verify/retry/obligations over the SAME\n// envelope discipline as the host protocol — closed request/response Schema unions, typed\n// failures that re-decode to identical tags, protocol anomalies answered typed. The envelopes\n// live here (not `client.ts`) because no Worker-side client consumption exists yet; `wake`\n// already exists as the `wake()` entry point.\n// ---------------------------------------------------------------------------\n\n/** Explain one Submission (`submissionId` present) or every nonterminal lane member. */\nexport class AdminExplainRequest extends Schema.Class<AdminExplainRequest>(\n \"@effect-agent/platform-cloudflare/AdminExplainRequest\",\n)({\n submissionId: Schema.optionalKey(SubmissionId),\n}) {}\n\n/** Verify carries no parameters — the addressed Object IS the lane. */\nexport class AdminVerifyRequest extends Schema.Class<AdminVerifyRequest>(\n \"@effect-agent/platform-cloudflare/AdminVerifyRequest\",\n)({}) {}\n\n/** Every typed failure of the four admin entry points, plus the protocol's own errors. */\nexport const AdminFailure = Schema.Union([\n AdmissionPolicyError,\n OperationDenied,\n RetryRefused,\n LedgerError,\n RunJournalError,\n DigestError,\n OwnershipLost,\n SettlementConflict,\n ThreadStoreError,\n ThreadNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n DurableAlarmError,\n HostProtocolError,\n]);\n\nexport type AdminFailure = typeof AdminFailure.Type;\n\nexport class ExplainedRecovery extends Schema.TaggedClass<ExplainedRecovery>(\n \"@effect-agent/platform-cloudflare/ExplainedRecovery\",\n)(\"ExplainedRecovery\", {\n explanations: Schema.Array(RecoveryExplanation).check(Schema.isMaxLength(1_024)),\n}) {}\n\nexport class VerifiedIntegrity extends Schema.TaggedClass<VerifiedIntegrity>(\n \"@effect-agent/platform-cloudflare/VerifiedIntegrity\",\n)(\"VerifiedIntegrity\", {\n report: IntegrityReport,\n}) {}\n\nexport class RetryExecuted extends Schema.TaggedClass<RetryExecuted>(\n \"@effect-agent/platform-cloudflare/RetryExecuted\",\n)(\"RetryExecuted\", {\n report: RecoveryReport,\n}) {}\n\nexport class ObligationsScanned extends Schema.TaggedClass<ObligationsScanned>(\n \"@effect-agent/platform-cloudflare/ObligationsScanned\",\n)(\"ObligationsScanned\", {\n report: ObligationReport,\n}) {}\n\n/** The admin entry point failed TYPED on the Object; the failure re-decodes verbatim. */\nexport class AdminFailed extends Schema.TaggedClass<AdminFailed>(\n \"@effect-agent/platform-cloudflare/AdminFailed\",\n)(\"AdminFailed\", {\n failure: AdminFailure,\n}) {}\n\n/** The uniform answer of one admin entry point. Callers narrow by the tag their call implies. */\nexport const AdminResponse = Schema.Union([\n ExplainedRecovery,\n VerifiedIntegrity,\n RetryExecuted,\n ObligationsScanned,\n AdminFailed,\n]);\n\nexport type AdminResponse = typeof AdminResponse.Type;\n\nexport const decodeAdminExplainRequest = Schema.decodeUnknownEffect(AdminExplainRequest);\nexport const decodeAdminVerifyRequest = Schema.decodeUnknownEffect(AdminVerifyRequest);\nexport const decodeRetryCommand = Schema.decodeUnknownEffect(RetryCommand);\nexport const decodeObligationThresholds = Schema.decodeUnknownEffect(ObligationThresholds);\nexport const encodeAdminResponse = Schema.encodeEffect(AdminResponse);\nexport const decodeAdminResponse = Schema.decodeUnknownEffect(AdminResponse);\n\n/** Fold one admin endpoint's typed failures into the uniform `AdminResponse` envelope. */\nconst respondAdmin = <Result extends AdminResponse, Failure extends AdminFailure>(\n effect: Effect.Effect<Result, Failure, EndpointServices>,\n): Effect.Effect<AdminResponse, never, EndpointServices> =>\n effect.pipe(\n Effect.map((result): AdminResponse => result),\n Effect.catch((failure) => Effect.succeed<AdminResponse>(AdminFailed.make({ failure }))),\n );\n\n/** Encode the admin response envelope; an unencodable response degrades to a protocol failure. */\nconst encodeAdminResponseTotal = (response: AdminResponse): Effect.Effect<unknown> =>\n encodeAdminResponse(response).pipe(\n Effect.catch((error) =>\n Effect.succeed<unknown>({\n _tag: \"AdminFailed\",\n failure: {\n _tag: \"HostProtocolError\",\n message: boundHostDiagnostic(`The admin response could not be encoded: ${error.message}`),\n },\n }),\n ),\n );\n\nconst explainEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeAdminExplainRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The explain request could not be decoded\")),\n Effect.flatMap((request) =>\n Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const runtime = yield* DurableAgentRuntime;\n\n const explanations =\n request.submissionId === undefined\n ? yield* runtime.explainThread(identity.threadId)\n : [yield* runtime.explain(request.submissionId)];\n\n return ExplainedRecovery.make({ explanations });\n }),\n ),\n respondAdmin,\n Effect.flatMap(encodeAdminResponseTotal),\n );\n\nconst verifyEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeAdminVerifyRequest(encoded).pipe(\n Effect.mapError(protocolFailure(\"The verify request could not be decoded\")),\n Effect.flatMap(() =>\n Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const runtime = yield* DurableAgentRuntime;\n const report = yield* runtime.verify(identity.threadId);\n\n return VerifiedIntegrity.make({ report });\n }),\n ),\n respondAdmin,\n Effect.flatMap(encodeAdminResponseTotal),\n );\n\nconst retryEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeRetryCommand(encoded).pipe(\n Effect.mapError(protocolFailure(\"The retry command could not be decoded\")),\n Effect.flatMap((command) =>\n Effect.gen(function* () {\n const maintenance = yield* ThreadMaintenance;\n const runtime = yield* DurableAgentRuntime;\n // Retry may repair durable state, so its generation + alarm commit before the mutation.\n const report = yield* maintenance.withMutation(runtime.retry(command));\n\n return RetryExecuted.make({ report });\n }),\n ),\n respondAdmin,\n Effect.flatMap(encodeAdminResponseTotal),\n );\n\nconst obligationsEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n decodeObligationThresholds(encoded).pipe(\n Effect.mapError(protocolFailure(\"The obligation thresholds could not be decoded\")),\n Effect.flatMap((thresholds) =>\n Effect.gen(function* () {\n const runtime = yield* DurableAgentRuntime;\n const report = yield* runtime.scanObligations(thresholds);\n\n return ObligationsScanned.make({ report });\n }),\n ),\n respondAdmin,\n Effect.flatMap(encodeAdminResponseTotal),\n );\n\n/**\n * Owner-side `portCall`: wrap a mutating envelope in the same pre-armed generation protocol as\n * public RPC (a routed mutation committed by THIS Object must already carry the alarm that will\n * finish it), execute on the LOCAL facets (never the routed decorators), then arm an immediate\n * alarm so the mutated lane is processed promptly. Protocol anomalies answer\n * `PortFailed(PortProtocolError)`.\n */\nconst portCallEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n Effect.gen(function* () {\n const ports = yield* ThreadObjectPorts;\n const maintenance = yield* ThreadMaintenance;\n const alarm = yield* DurableAlarmService;\n\n const decoded = yield* decodePortRequest(encoded).pipe(\n Effect.map((request) => ({ _tag: \"success\" as const, request })),\n Effect.catch((error) => Effect.succeed({ _tag: \"failure\" as const, message: error.message })),\n );\n\n if (decoded._tag === \"failure\") {\n return encodedPortProtocolFailure(\n `The port request could not be decoded: ${decoded.message}`,\n );\n }\n const mutating = isMutatingPortRequest(decoded.request);\n\n const handled = yield* (\n mutating\n ? maintenance.withMutation(ports.handle(decoded.request))\n : ports.handle(decoded.request)\n ).pipe(Effect.exit);\n\n if (handled._tag === \"Failure\") {\n // Without the committed generation/alarm the invariant cannot be promised; refuse before\n // the port mutation runs. `ports.handle` itself is total, so this is the maintenance error.\n return encodedPortProtocolFailure(\n \"The owner Object could not arm its maintenance alarm before the mutation.\",\n );\n }\n\n const response = yield* encodePortResponse(handled.value).pipe(\n Effect.catch((error) =>\n Effect.succeed(\n encodedPortProtocolFailure(`The port response could not be encoded: ${error.message}`),\n ),\n ),\n );\n\n if (mutating) {\n // Prompt processing hint; the pre-armed alarm already guarantees convergence.\n yield* alarm.scheduleNow.pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"ThreadObject.portCall: immediate re-arm failed\", error),\n ),\n );\n }\n\n return response;\n });\n\nconst wakeEndpoint: Effect.Effect<void, never, EndpointServices> = Effect.gen(function* () {\n const identity = yield* ThreadObjectIdentity;\n const wake = yield* WakeScheduler;\n\n // Route the remote hint through this incarnation's scheduler so scoped progress waiters and\n // the alarm receive the same hint. Delivery remains droppable; canonical storage is authority.\n yield* wake.notify(identity.threadId);\n});\n\nconst alarmEndpoint: Effect.Effect<void, MaintenancePassFailure, EndpointServices> = Effect.gen(\n function* () {\n const maintenance = yield* ThreadMaintenance;\n\n // Typed pass failures propagate: the rejected promise makes workerd retry the alarm\n // (at-least-once delivery), and the dirty generation retains a committed slot meanwhile.\n yield* maintenance.pass;\n },\n);\n\nconst gateEndpoint: Effect.Effect<void, MaintenancePassFailure, EndpointServices> = Effect.gen(\n function* () {\n // Forcing ThreadMaintenance forces the whole Layer stack: migration + exact-version\n // check + configuration decode (DEPLOY-008 fails typed here, before any mutation), then\n // the defensive local ensure-alarm half of the invariant. LOCAL-ONLY by construction.\n const maintenance = yield* ThreadMaintenance;\n\n yield* maintenance.ensureAlarm;\n },\n);\n\n/**\n * Adapter from effect-cf's native Durable Object services to Effect Agent's existing platform\n * ports. effect-cf owns the cached ManagedRuntime and supplies these values once per Object\n * incarnation; the durable runtime continues to depend only on the narrow services below.\n */\nconst effectCfPlatformLayer = (\n namespaceBinding: string,\n rpcTracing = false,\n): Layer.Layer<\n DurableObjectContext | ThreadObjectNamespace,\n CloudflareBindingError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n> => {\n const context = Layer.effect(DurableObjectContext)(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const env = yield* WorkerEnvironment;\n\n return DurableObjectContext.of({ ctx: state.raw, env });\n }),\n );\n\n const namespace = Layer.effect(ThreadObjectNamespace)(\n Effect.gen(function* () {\n const env = yield* WorkerEnvironment;\n const binding = yield* threadNamespaceFromEnv(env, namespaceBinding);\n\n return ThreadObjectNamespace.of({\n namespace: binding,\n ...(rpcTracing === true ? { rpcTracing: namespaceBinding } : {}),\n });\n }),\n );\n\n return Layer.merge(context, namespace);\n};\n\n/** The public endpoints and effect-cf invocation hook of one Thread Object instance. */\nexport interface Instance<EventServices = never> extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, RuntimeServices | EventServices>\n> {\n submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n cancelProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n observePage(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n abortEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n resolveApprovalEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n resolveUnknownEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n explainEncoded(encoded: unknown): Promise<unknown>;\n verifyEncoded(encoded: unknown): Promise<unknown>;\n retryEncoded(encoded: unknown): Promise<unknown>;\n obligationsEncoded(encoded: unknown): Promise<unknown>;\n portCall(encoded: unknown): Promise<unknown>;\n wake(): Promise<void>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\n/** The constructor shape workerd instantiates for each Thread Object. */\nexport interface Class<EventServices = never> {\n new (ctx: DurableObjectState, env: Cloudflare.Env): Instance<EventServices>;\n}\n\n/**\n * Export a composed application Layer as a native Durable Object class.\n * Bootstrap services are provided to the whole graph before it acquires, so application Layers\n * can yield effect-cf's WorkerEnvironment and DurableObjectState, derived identity, and Crypto.\n * Application dependencies remain visible until Layer.provide satisfies them. effect-cf owns the\n * cached ManagedRuntime, native RPC methods, event scopes, and telemetry flushing.\n * Initialization is local and bounded inside the constructor gate. Cloudflare eviction does not\n * guarantee finalizers; put resources requiring timely release in scoped operations or eventLayer.\n */\nexport const make = <\n ApplicationServices,\n ApplicationError,\n EventServices = never,\n EventLayerError = never,\n>(\n applicationLayer: Layer.Layer<\n CloudflareDurableRuntimeServices | ApplicationServices,\n ApplicationError,\n | CloudflareBootstrapServices\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n | DurableObjectContext\n | ThreadObjectNamespace\n >,\n options: Options<ApplicationServices, EventServices, EventLayerError>,\n): Class<ApplicationServices | EventServices> => {\n const application = applicationLayer.pipe(\n Layer.provideMerge(layerConfig(options)),\n Layer.provideMerge(effectCfPlatformLayer(options.namespaceBinding, options.rpcTracing)),\n );\n\n // The storage/config Layer must acquire inside Cloudflare's constructor gate. effect-cf owns\n // the ManagedRuntime, while this effectContext ensures its first Layer build enters the gate\n // before migration, compatibility checks, or alarm inspection touch Object storage.\n const runtime: Layer.Layer<\n RuntimeServices | ApplicationServices,\n ThreadObjectInitializationError | ApplicationError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n return yield* state.blockConcurrencyWhile(\n Effect.gen(function* () {\n const services = yield* Layer.buildWithScope(application, scope);\n\n yield* gateEndpoint.pipe(Effect.provide(services));\n\n return services;\n }),\n );\n }),\n );\n\n const rpc = {\n submitEncoded: (encoded: unknown) => submitEndpoint(encoded),\n submissionStatusEncoded: (encoded: unknown) => submissionStatusEndpoint(encoded),\n awaitSettlementEncoded: (encoded: unknown) => awaitSettlementEndpoint(encoded),\n awaitProgressEncoded: (encoded: unknown) => awaitProgressEndpoint(encoded),\n cancelProgressEncoded: (encoded: unknown) => cancelProgressEndpoint(encoded),\n observePage: (encoded: unknown) => observePageEndpoint(encoded),\n abortEncoded: (encoded: unknown) => abortEndpoint(encoded),\n resolveApprovalEncoded: (encoded: unknown) => resolveApprovalEndpoint(encoded),\n resolveUnknownEncoded: (encoded: unknown) => resolveUnknownEndpoint(encoded),\n explainEncoded: (encoded: unknown) => explainEndpoint(encoded),\n verifyEncoded: (encoded: unknown) => verifyEndpoint(encoded),\n retryEncoded: (encoded: unknown) => retryEndpoint(encoded),\n obligationsEncoded: (encoded: unknown) => obligationsEndpoint(encoded),\n portCall: (encoded: unknown) => portCallEndpoint(encoded),\n wake: () => wakeEndpoint,\n } satisfies EffectCfDurableObject.DurableObjectRpc<\n RuntimeServices | ApplicationServices | EventServices\n >;\n\n type NativeOptions = EffectCfDurableObject.DurableObjectOptions<\n RuntimeServices | ApplicationServices,\n EventServices,\n EventLayerError,\n typeof rpc\n >;\n\n const EffectCfThreadObject = EffectCfDurableObject.make<\n RuntimeServices | ApplicationServices,\n ThreadObjectInitializationError | ApplicationError,\n EventServices,\n EventLayerError,\n typeof rpc\n >(runtime, {\n ...(options.rpcTracing === true ? { rpcTracing: { service: options.namespaceBinding } } : {}),\n ...(options.eventLayer === undefined ? {} : { eventLayer: options.eventLayer }),\n // Force the gated runtime Layer when Cloudflare loads this Object incarnation. Recovery stays\n // in each bounded pass so cross-Object initialization cannot deadlock.\n initialize: Effect.void,\n rpc,\n alarm: () => alarmEndpoint,\n // This host owns the raw alarm and supplies event services through options.eventLayer.\n // Upstream's conditional alarm-registration check cannot reduce over generic application\n // services. Options and the rpc satisfies check above retain their Effect requirements.\n } as NativeOptions);\n\n // effect-cf's class type keeps `alarm` optional even when the handler option is present. This\n // concrete override reflects this factory's stronger contract while delegating execution to\n // the effect-cf runtime unchanged.\n class ThreadObject extends EffectCfThreadObject {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return ThreadObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,8BAA8B;;;;;;AAWpC,IAAa,uBAAb,MAAa,6BAA6B,QAAQ,QAUhD,CAAC,CAAC,wDAAwD,CAAC,CAAC;CAC5D,OAAgB,QAA2C,MAAM,OAC/D,sBACA,OAAO,IAAI,aAAa;EACtB,MAAM,gBAAgB,OAAO,IAAI,qBAAoB,IAAI,IAAI,CAAC;EAE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AAO;EACxD,YAAY;CACd;CAWA,MAAM,uBAAuBC,cAAsB,KAMjD,SAAS;EACT,GAAI,QAAQ,eAAe,OAAO,EAAE,YAAY,EAAE,SAAS,QAAQ,iBAAiB,EAAE,IAAI,CAAC;EAC3F,GAAI,QAAQ,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;EAG7E,YAAY,OAAO;EACnB;EACA,aAAa;CAIf,CAAkB;CAKlB,MAAM,qBAAqB,qBAAqB;EAC9C,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -4,7 +4,7 @@ import { DurableAlarmError, DurableAlarmService, ThreadMaintenance, ThreadMainte
|
|
|
4
4
|
import { HostProtocolError } from "./CloudflareThreadClient.mjs";
|
|
5
5
|
import { AgentRegistration } from "@effect-agent/thread/AgentRegistration";
|
|
6
6
|
import { DurableAgentRuntime, DurableRuntimeConfig, RecoveryReport } from "@effect-agent/thread/DurableAgentRuntime";
|
|
7
|
-
import { LedgerError, OwnershipLost, SettlementConflict, SubmissionLedger } from "@effect-agent/thread/SubmissionLedger";
|
|
7
|
+
import { AdmissionPolicyError, LedgerError, OwnershipLost, SettlementConflict, SubmissionLedger } from "@effect-agent/thread/SubmissionLedger";
|
|
8
8
|
import { Context, Crypto, Effect, Layer, Schema, Scope } from "effect";
|
|
9
9
|
import { DurableObject, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
|
|
10
10
|
import { DigestError } from "@effect-agent/thread/Digest";
|
|
@@ -192,7 +192,7 @@ declare const AdminVerifyRequest_base: Schema.Class<AdminVerifyRequest, Schema.S
|
|
|
192
192
|
/** Verify carries no parameters — the addressed Object IS the lane. */
|
|
193
193
|
declare class AdminVerifyRequest extends AdminVerifyRequest_base {}
|
|
194
194
|
/** Every typed failure of the four admin entry points, plus the protocol's own errors. */
|
|
195
|
-
declare const AdminFailure: Schema.Union<readonly [typeof OperationDenied, typeof RetryRefused, typeof LedgerError, typeof RunJournalError, typeof DigestError, typeof OwnershipLost, typeof SettlementConflict, typeof ThreadStoreError, typeof ThreadNotMaterialized, typeof AppendConflict, typeof FenceRejected, typeof DurableRuntimeFailpointError, typeof DurableAlarmError, typeof HostProtocolError]>;
|
|
195
|
+
declare const AdminFailure: Schema.Union<readonly [typeof AdmissionPolicyError, typeof OperationDenied, typeof RetryRefused, typeof LedgerError, typeof RunJournalError, typeof DigestError, typeof OwnershipLost, typeof SettlementConflict, typeof ThreadStoreError, typeof ThreadNotMaterialized, typeof AppendConflict, typeof FenceRejected, typeof DurableRuntimeFailpointError, typeof DurableAlarmError, typeof HostProtocolError]>;
|
|
196
196
|
type AdminFailure = typeof AdminFailure.Type;
|
|
197
197
|
declare const ExplainedRecovery_base: Schema.Class<ExplainedRecovery, Schema.TaggedStruct<"ExplainedRecovery", {
|
|
198
198
|
readonly explanations: Schema.$Array<typeof RecoveryExplanation>;
|
|
@@ -211,7 +211,7 @@ declare const ObligationsScanned_base: Schema.Class<ObligationsScanned, Schema.T
|
|
|
211
211
|
}>, {}>;
|
|
212
212
|
declare class ObligationsScanned extends ObligationsScanned_base {}
|
|
213
213
|
declare const AdminFailed_base: Schema.Class<AdminFailed, Schema.TaggedStruct<"AdminFailed", {
|
|
214
|
-
readonly failure: Schema.Union<readonly [typeof OperationDenied, typeof RetryRefused, typeof LedgerError, typeof RunJournalError, typeof DigestError, typeof OwnershipLost, typeof SettlementConflict, typeof ThreadStoreError, typeof ThreadNotMaterialized, typeof AppendConflict, typeof FenceRejected, typeof DurableRuntimeFailpointError, typeof DurableAlarmError, typeof HostProtocolError]>;
|
|
214
|
+
readonly failure: Schema.Union<readonly [typeof AdmissionPolicyError, typeof OperationDenied, typeof RetryRefused, typeof LedgerError, typeof RunJournalError, typeof DigestError, typeof OwnershipLost, typeof SettlementConflict, typeof ThreadStoreError, typeof ThreadNotMaterialized, typeof AppendConflict, typeof FenceRejected, typeof DurableRuntimeFailpointError, typeof DurableAlarmError, typeof HostProtocolError]>;
|
|
215
215
|
}>, {}>;
|
|
216
216
|
/** The admin entry point failed TYPED on the Object; the failure re-decodes verbatim. */
|
|
217
217
|
declare class AdminFailed extends AdminFailed_base {}
|
|
@@ -632,6 +632,10 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
632
632
|
} | {
|
|
633
633
|
readonly _tag: "AdminFailed";
|
|
634
634
|
readonly failure: {
|
|
635
|
+
readonly _tag: "AdmissionPolicyError";
|
|
636
|
+
readonly reason: "occupied" | "refused" | "unavailable";
|
|
637
|
+
readonly code: string;
|
|
638
|
+
} | {
|
|
635
639
|
readonly _tag: "SettlementConflict";
|
|
636
640
|
readonly submissionId: string;
|
|
637
641
|
readonly existingOutcome: "aborted" | "completed" | "failed";
|
|
@@ -701,6 +705,7 @@ declare const decodeAdminResponse: (input: unknown, options?: import("effect/Sch
|
|
|
701
705
|
/** The public endpoints and effect-cf invocation hook of one Thread Object instance. */
|
|
702
706
|
interface Instance<EventServices = never> extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, RuntimeServices | EventServices>> {
|
|
703
707
|
submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
708
|
+
submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
704
709
|
awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
705
710
|
awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
706
711
|
cancelProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
@@ -732,4 +737,4 @@ interface Class<EventServices = never> {
|
|
|
732
737
|
declare const make: <ApplicationServices, ApplicationError, EventServices = never, EventLayerError = never>(applicationLayer: Layer.Layer<CloudflareDurableRuntimeServices | ApplicationServices, ApplicationError, CloudflareBootstrapServices | DurableObjectState$1.DurableObjectState | WorkerEnvironment | DurableObjectContext | ThreadObjectNamespace>, options: Options<ApplicationServices, EventServices, EventLayerError>) => Class<ApplicationServices | EventServices>;
|
|
733
738
|
//#endregion
|
|
734
739
|
export { CloudflareDurableRuntimeOptions as C, layerConfig as E, CloudflareDurableRuntimeInitializationError as S, layer as T, decodeObligationThresholds as _, AdminVerifyRequest as a, make as b, Instance as c, RetryExecuted as d, ThreadObject_d_exports as f, decodeAdminVerifyRequest as g, decodeAdminResponse as h, AdminResponse as i, ObligationsScanned as l, decodeAdminExplainRequest as m, AdminFailed as n, Class as o, VerifiedIntegrity as p, AdminFailure as r, ExplainedRecovery as s, AdminExplainRequest as t, Options as u, decodeRetryCommand as v, CloudflareDurableRuntimeServices as w, CloudflareBootstrapServices as x, encodeAdminResponse as y };
|
|
735
|
-
//# sourceMappingURL=ThreadObject-
|
|
740
|
+
//# sourceMappingURL=ThreadObject-sDr1JBCj.d.mts.map
|
package/dist/ThreadObject.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as CloudflareDurableRuntimeOptions, E as layerConfig, S as CloudflareDurableRuntimeInitializationError, T as layer, _ as decodeObligationThresholds, a as AdminVerifyRequest, b as make, c as Instance, d as RetryExecuted, g as decodeAdminVerifyRequest, h as decodeAdminResponse, i as AdminResponse, l as ObligationsScanned, m as decodeAdminExplainRequest, n as AdminFailed, o as Class, p as VerifiedIntegrity, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeRetryCommand, w as CloudflareDurableRuntimeServices, x as CloudflareBootstrapServices, y as encodeAdminResponse } from "./ThreadObject-
|
|
1
|
+
import { C as CloudflareDurableRuntimeOptions, E as layerConfig, S as CloudflareDurableRuntimeInitializationError, T as layer, _ as decodeObligationThresholds, a as AdminVerifyRequest, b as make, c as Instance, d as RetryExecuted, g as decodeAdminVerifyRequest, h as decodeAdminResponse, i as AdminResponse, l as ObligationsScanned, m as decodeAdminExplainRequest, n as AdminFailed, o as Class, p as VerifiedIntegrity, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeRetryCommand, w as CloudflareDurableRuntimeServices, x as CloudflareBootstrapServices, y as encodeAdminResponse } from "./ThreadObject-sDr1JBCj.mjs";
|
|
2
2
|
export { AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, type CloudflareBootstrapServices as BootstrapServices, Class, ExplainedRecovery, type CloudflareDurableRuntimeInitializationError as InitializationError, Instance, ObligationsScanned, Options, RetryExecuted, type CloudflareDurableRuntimeOptions as RuntimeOptions, type CloudflareDurableRuntimeServices as Services, VerifiedIntegrity, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeObligationThresholds, decodeRetryCommand, encodeAdminResponse, layer, layerConfig, make };
|
package/dist/ThreadObject.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./CloudflareThreadClient.mjs";
|
|
2
|
-
import { _ as make, a as AdminVerifyRequest, c as RetryExecuted, d as decodeAdminExplainRequest, f as decodeAdminResponse, g as encodeAdminResponse, h as decodeRetryCommand, i as AdminResponse, m as decodeObligationThresholds, n as AdminFailed, o as ExplainedRecovery, p as decodeAdminVerifyRequest, r as AdminFailure, s as ObligationsScanned, t as AdminExplainRequest, u as VerifiedIntegrity, v as layer, y as layerConfig } from "./ThreadObject-
|
|
2
|
+
import { _ as make, a as AdminVerifyRequest, c as RetryExecuted, d as decodeAdminExplainRequest, f as decodeAdminResponse, g as encodeAdminResponse, h as decodeRetryCommand, i as AdminResponse, m as decodeObligationThresholds, n as AdminFailed, o as ExplainedRecovery, p as decodeAdminVerifyRequest, r as AdminFailure, s as ObligationsScanned, t as AdminExplainRequest, u as VerifiedIntegrity, v as layer, y as layerConfig } from "./ThreadObject-BY8axaWT.mjs";
|
|
3
3
|
export { AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, ExplainedRecovery, ObligationsScanned, RetryExecuted, VerifiedIntegrity, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeObligationThresholds, decodeRetryCommand, encodeAdminResponse, layer, layerConfig, make };
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { t as CloudflareMemory_d_exports } from "./CloudflareMemory.mjs";
|
|
|
7
7
|
import { t as CloudflareScheduling_d_exports } from "./CloudflareScheduling.mjs";
|
|
8
8
|
import { t as CloudflareSubscriptions_d_exports } from "./CloudflareSubscriptions.mjs";
|
|
9
9
|
import { t as CloudflareThreadClient_d_exports } from "./CloudflareThreadClient.mjs";
|
|
10
|
-
import { f as ThreadObject_d_exports } from "./ThreadObject-
|
|
10
|
+
import { f as ThreadObject_d_exports } from "./ThreadObject-sDr1JBCj.mjs";
|
|
11
11
|
import { t as WakeScheduler_d_exports } from "./WakeScheduler.mjs";
|
|
12
12
|
export { Alarm_d_exports as Alarm, CloudflareBindings_d_exports as CloudflareBindings, CloudflareBrowser_d_exports as CloudflareBrowser, CloudflareCodeMode_d_exports as CloudflareCodeMode, CloudflareConfig_d_exports as CloudflareConfig, CloudflareMemory_d_exports as CloudflareMemory, CloudflareScheduling_d_exports as CloudflareScheduling, CloudflareSubscriptions_d_exports as CloudflareSubscriptions, CloudflareThreadClient_d_exports as CloudflareThreadClient, ThreadObject_d_exports as ThreadObject, WakeScheduler_d_exports as WakeScheduler };
|
package/dist/index.mjs
CHANGED
|
@@ -8,5 +8,5 @@ import { t as CloudflareThreadClient_exports } from "./CloudflareThreadClient.mj
|
|
|
8
8
|
import { t as CloudflareScheduling_exports } from "./CloudflareScheduling.mjs";
|
|
9
9
|
import { t as CloudflareSubscriptions_exports } from "./CloudflareSubscriptions.mjs";
|
|
10
10
|
import { t as WakeScheduler_exports } from "./WakeScheduler.mjs";
|
|
11
|
-
import { l as ThreadObject_exports } from "./ThreadObject-
|
|
11
|
+
import { l as ThreadObject_exports } from "./ThreadObject-BY8axaWT.mjs";
|
|
12
12
|
export { Alarm_exports as Alarm, CloudflareBindings_exports as CloudflareBindings, CloudflareBrowser_exports as CloudflareBrowser, CloudflareCodeMode_exports as CloudflareCodeMode, CloudflareConfig_exports as CloudflareConfig, CloudflareMemory_exports as CloudflareMemory, CloudflareScheduling_exports as CloudflareScheduling, CloudflareSubscriptions_exports as CloudflareSubscriptions, CloudflareThreadClient_exports as CloudflareThreadClient, ThreadObject_exports as ThreadObject, WakeScheduler_exports as WakeScheduler };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { CloudflareThreadClient } from "./CloudflareThreadClient.mjs";
|
|
2
|
+
import "@effect-agent/thread/DurableAgentRuntime";
|
|
3
|
+
import { Effect, Layer } from "effect";
|
|
4
|
+
import "@effect-agent/core/Identifiers";
|
|
5
|
+
import { PersistedJson } from "@effect-agent/thread/Records";
|
|
6
|
+
import { ScheduleStorageError, ScheduledInputAdmission, ScheduledInputRefused, ScheduledInputRetryable } from "@effect-agent/thread/Schedule";
|
|
7
|
+
import { PreparedInputAdmission } from "@effect-agent/thread/PreparedInputAdmission";
|
|
8
|
+
import "@effect-agent/thread/Subscription";
|
|
9
|
+
//#region src/internal/prepared-admission.ts
|
|
10
|
+
const passthroughAgent = (agentId) => ({ definition: {
|
|
11
|
+
id: agentId,
|
|
12
|
+
input: PersistedJson
|
|
13
|
+
} });
|
|
14
|
+
/** Ordinary prepared admission through one freshly addressed Thread Object call. */
|
|
15
|
+
const cloudflarePreparedInputAdmissionLayer = Layer.effect(PreparedInputAdmission, Effect.gen(function* () {
|
|
16
|
+
const client = yield* CloudflareThreadClient;
|
|
17
|
+
return PreparedInputAdmission.of({
|
|
18
|
+
submissionStatus: (receipt) => client.submissionStatus(receipt).pipe(Effect.mapError(() => ScheduledInputRetryable.make({ reason: "storage" }))),
|
|
19
|
+
submit: (envelope) => client.submit(passthroughAgent(envelope.agentId), envelope.input, {
|
|
20
|
+
threadId: envelope.threadId,
|
|
21
|
+
principal: envelope.deliveryPrincipal,
|
|
22
|
+
idempotencyKey: envelope.admissionKey,
|
|
23
|
+
...envelope.admissionGroup === void 0 ? {} : { admissionGroup: envelope.admissionGroup },
|
|
24
|
+
...envelope.admissionFence === void 0 ? {} : { admissionFence: envelope.admissionFence },
|
|
25
|
+
definitions: envelope.definitions
|
|
26
|
+
}).pipe(Effect.catchTags({
|
|
27
|
+
AdmissionConflict: () => ScheduleStorageError.make({
|
|
28
|
+
operation: "prepared admission",
|
|
29
|
+
reason: "corrupt"
|
|
30
|
+
}),
|
|
31
|
+
AdmissionLimitExceeded: () => ScheduledInputRetryable.make({ reason: "capacity" }),
|
|
32
|
+
ThreadClientError: (error) => ScheduledInputRetryable.make({ reason: error.overloaded === true ? "capacity" : "transport" }),
|
|
33
|
+
HostProtocolError: () => ScheduledInputRetryable.make({ reason: "ambiguous" }),
|
|
34
|
+
AdmissionPolicyError: (error) => error.reason === "refused" ? ScheduledInputRefused.make({ code: error.code }) : ScheduledInputRetryable.make({ reason: error.reason === "occupied" ? "capacity" : "storage" }),
|
|
35
|
+
LedgerError: () => ScheduledInputRetryable.make({ reason: "storage" }),
|
|
36
|
+
ThreadStoreError: () => ScheduledInputRetryable.make({ reason: "storage" }),
|
|
37
|
+
DurableAlarmError: () => ScheduledInputRetryable.make({ reason: "storage" }),
|
|
38
|
+
AgentInputError: () => ScheduleStorageError.make({
|
|
39
|
+
operation: "prepared admission",
|
|
40
|
+
reason: "corrupt"
|
|
41
|
+
}),
|
|
42
|
+
DigestError: () => ScheduleStorageError.make({
|
|
43
|
+
operation: "prepared admission",
|
|
44
|
+
reason: "corrupt"
|
|
45
|
+
}),
|
|
46
|
+
ThreadNotMaterialized: () => ScheduledInputRetryable.make({ reason: "storage" }),
|
|
47
|
+
AppendConflict: () => ScheduledInputRetryable.make({ reason: "ambiguous" }),
|
|
48
|
+
FenceRejected: () => ScheduledInputRetryable.make({ reason: "ambiguous" }),
|
|
49
|
+
DurableRuntimeFailpointError: () => ScheduledInputRetryable.make({ reason: "ambiguous" })
|
|
50
|
+
}))
|
|
51
|
+
});
|
|
52
|
+
}));
|
|
53
|
+
const preparedFromSchedule = (envelope) => ({
|
|
54
|
+
schemaVersion: 1,
|
|
55
|
+
threadId: envelope.threadId,
|
|
56
|
+
deliveryPrincipal: envelope.deliveryPrincipal,
|
|
57
|
+
...envelope.admissionGroup === void 0 ? {} : { admissionGroup: envelope.admissionGroup },
|
|
58
|
+
...envelope.admissionFence === void 0 ? {} : { admissionFence: envelope.admissionFence },
|
|
59
|
+
agentId: envelope.agentId,
|
|
60
|
+
definitions: envelope.definitions,
|
|
61
|
+
input: envelope.input,
|
|
62
|
+
inputDigest: envelope.inputDigest,
|
|
63
|
+
admissionKey: envelope.admissionKey,
|
|
64
|
+
authorization: envelope.authorization
|
|
65
|
+
});
|
|
66
|
+
/** Compatibility adapter retaining Scheduling's public admission port. */
|
|
67
|
+
const cloudflareScheduledInputAdmissionLayer = Layer.effect(ScheduledInputAdmission, Effect.map(PreparedInputAdmission, (admission) => ScheduledInputAdmission.of({ submit: (envelope) => admission.submit(preparedFromSchedule(envelope)) })));
|
|
68
|
+
//#endregion
|
|
69
|
+
export { cloudflareScheduledInputAdmissionLayer as n, cloudflarePreparedInputAdmissionLayer as t };
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=prepared-admission-9rvlHI0y.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepared-admission-9rvlHI0y.mjs","names":[],"sources":["../src/internal/prepared-admission.ts"],"sourcesContent":["import { type AgentId } from \"@effect-agent/core/Identifiers\";\nimport { type DurableSubmitAgent } from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { PreparedInputAdmission } from \"@effect-agent/thread/PreparedInputAdmission\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport {\n type ScheduledEnvelope,\n ScheduledInputAdmission,\n ScheduledInputRetryable,\n ScheduledInputRefused,\n ScheduleStorageError,\n} from \"@effect-agent/thread/Schedule\";\nimport { type PreparedInput } from \"@effect-agent/thread/Subscription\";\nimport { Effect, Layer } from \"effect\";\n\nimport { CloudflareThreadClient, type ThreadClientError } from \"../CloudflareThreadClient.ts\";\n\nconst passthroughAgent = (agentId: AgentId): DurableSubmitAgent<typeof PersistedJson> => ({\n definition: { id: agentId, input: PersistedJson },\n});\n\n/** Ordinary prepared admission through one freshly addressed Thread Object call. */\nexport const cloudflarePreparedInputAdmissionLayer: Layer.Layer<\n PreparedInputAdmission,\n never,\n CloudflareThreadClient\n> = Layer.effect(\n PreparedInputAdmission,\n Effect.gen(function* () {\n const client = yield* CloudflareThreadClient;\n\n return PreparedInputAdmission.of({\n submissionStatus: (receipt) =>\n client\n .submissionStatus(receipt)\n .pipe(Effect.mapError(() => ScheduledInputRetryable.make({ reason: \"storage\" }))),\n submit: (envelope) =>\n client\n .submit(passthroughAgent(envelope.agentId), envelope.input, {\n threadId: envelope.threadId,\n principal: envelope.deliveryPrincipal,\n idempotencyKey: envelope.admissionKey,\n ...(envelope.admissionGroup === undefined\n ? {}\n : { admissionGroup: envelope.admissionGroup }),\n ...(envelope.admissionFence === undefined\n ? {}\n : { admissionFence: envelope.admissionFence }),\n definitions: envelope.definitions,\n })\n .pipe(\n Effect.catchTags({\n AdmissionConflict: () =>\n ScheduleStorageError.make({ operation: \"prepared admission\", reason: \"corrupt\" }),\n AdmissionLimitExceeded: () => ScheduledInputRetryable.make({ reason: \"capacity\" }),\n ThreadClientError: (error: ThreadClientError) =>\n ScheduledInputRetryable.make({\n reason: error.overloaded === true ? \"capacity\" : \"transport\",\n }),\n HostProtocolError: () => ScheduledInputRetryable.make({ reason: \"ambiguous\" }),\n AdmissionPolicyError: (error) =>\n error.reason === \"refused\"\n ? ScheduledInputRefused.make({ code: error.code })\n : ScheduledInputRetryable.make({\n reason: error.reason === \"occupied\" ? \"capacity\" : \"storage\",\n }),\n LedgerError: () => ScheduledInputRetryable.make({ reason: \"storage\" }),\n ThreadStoreError: () => ScheduledInputRetryable.make({ reason: \"storage\" }),\n DurableAlarmError: () => ScheduledInputRetryable.make({ reason: \"storage\" }),\n AgentInputError: () =>\n ScheduleStorageError.make({ operation: \"prepared admission\", reason: \"corrupt\" }),\n DigestError: () =>\n ScheduleStorageError.make({ operation: \"prepared admission\", reason: \"corrupt\" }),\n ThreadNotMaterialized: () => ScheduledInputRetryable.make({ reason: \"storage\" }),\n AppendConflict: () => ScheduledInputRetryable.make({ reason: \"ambiguous\" }),\n FenceRejected: () => ScheduledInputRetryable.make({ reason: \"ambiguous\" }),\n DurableRuntimeFailpointError: () =>\n ScheduledInputRetryable.make({ reason: \"ambiguous\" }),\n }),\n ),\n });\n }),\n);\n\nconst preparedFromSchedule = (envelope: ScheduledEnvelope): PreparedInput => ({\n schemaVersion: 1,\n threadId: envelope.threadId,\n deliveryPrincipal: envelope.deliveryPrincipal,\n ...(envelope.admissionGroup === undefined ? {} : { admissionGroup: envelope.admissionGroup }),\n ...(envelope.admissionFence === undefined ? {} : { admissionFence: envelope.admissionFence }),\n agentId: envelope.agentId,\n definitions: envelope.definitions,\n input: envelope.input,\n inputDigest: envelope.inputDigest,\n admissionKey: envelope.admissionKey,\n authorization: envelope.authorization,\n});\n\n/** Compatibility adapter retaining Scheduling's public admission port. */\nexport const cloudflareScheduledInputAdmissionLayer: Layer.Layer<\n ScheduledInputAdmission,\n never,\n PreparedInputAdmission\n> = Layer.effect(\n ScheduledInputAdmission,\n Effect.map(PreparedInputAdmission, (admission) =>\n ScheduledInputAdmission.of({\n submit: (envelope) => admission.submit(preparedFromSchedule(envelope)),\n }),\n ),\n);\n"],"mappings":";;;;;;;;;AAgBA,MAAM,oBAAoB,aAAgE,EACxF,YAAY;CAAE,IAAI;CAAS,OAAO;AAAc,EAClD;;AAGA,MAAa,wCAIT,MAAM,OACR,wBACA,OAAO,IAAI,aAAa;CACtB,MAAM,SAAS,OAAO;CAEtB,OAAO,uBAAuB,GAAG;EAC/B,mBAAmB,YACjB,OACG,iBAAiB,OAAO,CAAC,CACzB,KAAK,OAAO,eAAe,wBAAwB,KAAK,EAAE,QAAQ,UAAU,CAAC,CAAC,CAAC;EACpF,SAAS,aACP,OACG,OAAO,iBAAiB,S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C,CACH;CACN,CAAC;AACH,CAAC,CACH;AAEA,MAAM,wBAAwB,cAAgD;CAC5E,eAAe;CACf,UAAU,SAAS;CACnB,mBAAmB,SAAS;CAC5B,GAAI,SAAS,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,SAAS,eAAe;CAC3F,GAAI,SAAS,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAgB,SAAS,eAAe;CAC3F,SAAS,SAAS;CAClB,aAAa,SAAS;CACtB,OAAO,SAAS;CAChB,aAAa,SAAS;CACtB,cAAc,SAAS;CACvB,eAAe,SAAS;AAC1B;;AAGA,MAAa,yCAIT,MAAM,OACR,yBACA,OAAO,IAAI,yBAAyB,cAClC,wBAAwB,GAAG,EACzB,SAAS,aAAa,UAAU,OAAO,qBAAqB,QAAQ,CAAC,EACvE,CAAC,CACH,CACF"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.51","dependencies":{"@effect-agent/core":"0.1.0-beta.51","@effect-agent/engine":"0.1.0-beta.51","@effect-agent/sandbox":"0.1.0-beta.51","@effect-agent/storage-cloudflare":"0.1.0-beta.51","@effect-agent/thread":"0.1.0-beta.51","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/puppeteer":"1.1.0","@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/capabilities":"0.1.0-beta.51","@effect-agent/testing":"0.1.0-beta.51","@effect/platform-node":"4.0.0-rc.112","@effect/sql-d1":"4.0.0-rc.112","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","effect-cf":"0.40.0","esbuild":"0.28.1","miniflare":"5.20260811.1-alpha","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"@cloudflare/puppeteer":"^1.1.0","effect":"^4.0.0-rc.112","effect-cf":"^0.40.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./Alarm":{"types":"./dist/Alarm.d.mts","default":"./dist/Alarm.mjs"},"./BrowserRestCapture":{"types":"./dist/BrowserRestCapture.d.mts","default":"./dist/BrowserRestCapture.mjs"},"./BrowserRestCrawl":{"types":"./dist/BrowserRestCrawl.d.mts","default":"./dist/BrowserRestCrawl.mjs"},"./CloudflareBindings":{"types":"./dist/CloudflareBindings.d.mts","default":"./dist/CloudflareBindings.mjs"},"./CloudflareBrowser":{"types":"./dist/CloudflareBrowser.d.mts","default":"./dist/CloudflareBrowser.mjs"},"./CloudflareCodeMode":{"types":"./dist/CloudflareCodeMode.d.mts","default":"./dist/CloudflareCodeMode.mjs"},"./CloudflareConfig":{"types":"./dist/CloudflareConfig.d.mts","default":"./dist/CloudflareConfig.mjs"},"./CloudflareMemory":{"types":"./dist/CloudflareMemory.d.mts","default":"./dist/CloudflareMemory.mjs"},"./CloudflareScheduling":{"types":"./dist/CloudflareScheduling.d.mts","default":"./dist/CloudflareScheduling.mjs"},"./CloudflareSubscriptions":{"types":"./dist/CloudflareSubscriptions.d.mts","default":"./dist/CloudflareSubscriptions.mjs"},"./CloudflareThreadClient":{"types":"./dist/CloudflareThreadClient.d.mts","default":"./dist/CloudflareThreadClient.mjs"},"./InteractiveBrowser":{"types":"./dist/InteractiveBrowser.d.mts","default":"./dist/InteractiveBrowser.mjs"},"./ProtectedBrowser":{"types":"./dist/ProtectedBrowser.d.mts","default":"./dist/ProtectedBrowser.mjs"},"./ThreadObject":{"types":"./dist/ThreadObject.d.mts","default":"./dist/ThreadObject.mjs"},"./WakeScheduler":{"types":"./dist/WakeScheduler.d.mts","default":"./dist/WakeScheduler.mjs"}},"description":"Cloudflare Layer assembly for Effect Agent: Durable Objects and Browser Run adapters.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/platform-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"},"peerDependenciesMeta":{"@cloudflare/puppeteer":{"optional":true}}}
|
|
@@ -32,6 +32,7 @@ export interface ThreadObjectRpc extends Rpc.DurableObjectBranded {
|
|
|
32
32
|
/** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */
|
|
33
33
|
submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
34
34
|
/** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */
|
|
35
|
+
submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
35
36
|
awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
36
37
|
/** Event-driven durable progress wait; answers a `ProgressObserved` host response. */
|
|
37
38
|
awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
type ScheduleManagementFailure,
|
|
34
34
|
ScheduleWakeNoop,
|
|
35
35
|
} from "@effect-agent/thread/Scheduling";
|
|
36
|
+
import { AdmissionFence } from "@effect-agent/thread/SubmissionLedger";
|
|
36
37
|
import { BrowserCrypto } from "@effect/platform-browser";
|
|
37
38
|
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
38
39
|
import { Clock, Context, DateTime, Effect, Layer, Schema } from "effect";
|
|
@@ -81,6 +82,8 @@ const ScheduleMutationRequestFields = {
|
|
|
81
82
|
destination: ScheduleDestination,
|
|
82
83
|
deliveryPrincipal: ScheduleScopeSchema.fields.principal,
|
|
83
84
|
definitions: DefinitionDigests,
|
|
85
|
+
admissionGroup: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),
|
|
86
|
+
admissionFence: Schema.optionalKey(AdmissionFence),
|
|
84
87
|
};
|
|
85
88
|
|
|
86
89
|
const ScheduleCreateRequest = Schema.TaggedStruct("Create", ScheduleMutationRequestFields);
|
|
@@ -113,7 +116,16 @@ const ScheduleControlRequest = Schema.TaggedStruct("Control", {
|
|
|
113
116
|
expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
114
117
|
});
|
|
115
118
|
|
|
119
|
+
const ScheduleRecoverRequest = Schema.TaggedStruct("Recover", {
|
|
120
|
+
schemaVersion: Schema.Literal(1),
|
|
121
|
+
scope: ScheduleScopeSchema,
|
|
122
|
+
scheduleId: ScheduleId,
|
|
123
|
+
expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),
|
|
124
|
+
expectedGeneration: Schema.Natural,
|
|
125
|
+
});
|
|
126
|
+
|
|
116
127
|
const ScheduleOwnerRequest = Schema.Union([
|
|
128
|
+
ScheduleRecoverRequest,
|
|
117
129
|
ScheduleCreateRequest,
|
|
118
130
|
ScheduleUpdateRequest,
|
|
119
131
|
ScheduleGetRequest,
|
|
@@ -337,6 +349,24 @@ export class CloudflareSchedulingClient {
|
|
|
337
349
|
list,
|
|
338
350
|
pause: (scope, id, revision) => control("pause", scope, id, revision),
|
|
339
351
|
resume: (scope, id, revision) => control("resume", scope, id, revision),
|
|
352
|
+
recover: (scope, scheduleId, expectedRevision, expectedGeneration) =>
|
|
353
|
+
Effect.gen(function* () {
|
|
354
|
+
const response = yield* call(scope.owner, {
|
|
355
|
+
_tag: "Recover",
|
|
356
|
+
schemaVersion: 1,
|
|
357
|
+
scope,
|
|
358
|
+
scheduleId,
|
|
359
|
+
expectedRevision,
|
|
360
|
+
expectedGeneration,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
return response._tag === "Snapshot"
|
|
364
|
+
? response.value
|
|
365
|
+
: yield* ScheduleStorageError.make({
|
|
366
|
+
operation: "Schedule Owner protocol",
|
|
367
|
+
reason: "corrupt",
|
|
368
|
+
});
|
|
369
|
+
}),
|
|
340
370
|
cancel: (scope, id, revision) => control("cancel", scope, id, revision),
|
|
341
371
|
});
|
|
342
372
|
}),
|
|
@@ -489,6 +519,12 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
|
|
|
489
519
|
destination: request.destination,
|
|
490
520
|
deliveryPrincipal: request.deliveryPrincipal,
|
|
491
521
|
definitions: request.definitions,
|
|
522
|
+
...(request.admissionGroup === undefined
|
|
523
|
+
? {}
|
|
524
|
+
: { admissionGroup: request.admissionGroup }),
|
|
525
|
+
...(request.admissionFence === undefined
|
|
526
|
+
? {}
|
|
527
|
+
: { admissionFence: request.admissionFence }),
|
|
492
528
|
});
|
|
493
529
|
|
|
494
530
|
return { _tag: "Snapshot" as const, value };
|
|
@@ -501,6 +537,12 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
|
|
|
501
537
|
destination: request.destination,
|
|
502
538
|
deliveryPrincipal: request.deliveryPrincipal,
|
|
503
539
|
definitions: request.definitions,
|
|
540
|
+
...(request.admissionGroup === undefined
|
|
541
|
+
? {}
|
|
542
|
+
: { admissionGroup: request.admissionGroup }),
|
|
543
|
+
...(request.admissionFence === undefined
|
|
544
|
+
? {}
|
|
545
|
+
: { admissionFence: request.admissionFence }),
|
|
504
546
|
expectedRevision: request.expectedRevision,
|
|
505
547
|
});
|
|
506
548
|
|
|
@@ -519,6 +561,16 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
|
|
|
519
561
|
...(request.limit === undefined ? {} : { limit: request.limit }),
|
|
520
562
|
}),
|
|
521
563
|
};
|
|
564
|
+
case "Recover":
|
|
565
|
+
return {
|
|
566
|
+
_tag: "Snapshot" as const,
|
|
567
|
+
value: yield* scheduling.recover(
|
|
568
|
+
request.scope,
|
|
569
|
+
request.scheduleId,
|
|
570
|
+
request.expectedRevision,
|
|
571
|
+
request.expectedGeneration,
|
|
572
|
+
),
|
|
573
|
+
};
|
|
522
574
|
case "Control": {
|
|
523
575
|
const value =
|
|
524
576
|
request.operation === "pause"
|