@effect-agent/platform-cloudflare 0.1.0-beta.8 → 0.1.0-beta.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/dist/Alarm.d.mts +184 -0
  2. package/dist/Alarm.mjs +451 -0
  3. package/dist/Alarm.mjs.map +1 -0
  4. package/dist/BrowserRestCapture.d.mts +35 -0
  5. package/dist/BrowserRestCapture.mjs +238 -0
  6. package/dist/BrowserRestCapture.mjs.map +1 -0
  7. package/dist/BrowserRestCrawl.d.mts +17 -0
  8. package/dist/BrowserRestCrawl.mjs +244 -0
  9. package/dist/BrowserRestCrawl.mjs.map +1 -0
  10. package/dist/CloudflareAiGateway.d.mts +64 -0
  11. package/dist/CloudflareAiGateway.mjs +70 -0
  12. package/dist/CloudflareAiGateway.mjs.map +1 -0
  13. package/dist/CloudflareBindings.d.mts +112 -0
  14. package/dist/CloudflareBindings.mjs +101 -0
  15. package/dist/CloudflareBindings.mjs.map +1 -0
  16. package/dist/CloudflareBrowser-D4YqaTAl.mjs +495 -0
  17. package/dist/CloudflareBrowser-D4YqaTAl.mjs.map +1 -0
  18. package/dist/CloudflareBrowser-DJq53niJ.d.mts +80 -0
  19. package/dist/CloudflareBrowser.d.mts +2 -0
  20. package/dist/CloudflareBrowser.mjs +2 -0
  21. package/dist/CloudflareCodeMode.d.mts +44 -0
  22. package/dist/CloudflareCodeMode.mjs +616 -0
  23. package/dist/CloudflareCodeMode.mjs.map +1 -0
  24. package/dist/CloudflareConfig-f3CqTel1.d.mts +101 -0
  25. package/dist/CloudflareConfig.d.mts +2 -0
  26. package/dist/CloudflareConfig.mjs +122 -0
  27. package/dist/CloudflareConfig.mjs.map +1 -0
  28. package/dist/CloudflareMemory.d.mts +142 -0
  29. package/dist/CloudflareMemory.mjs +195 -0
  30. package/dist/CloudflareMemory.mjs.map +1 -0
  31. package/dist/CloudflareScheduling.d.mts +52 -0
  32. package/dist/CloudflareScheduling.mjs +389 -0
  33. package/dist/CloudflareScheduling.mjs.map +1 -0
  34. package/dist/CloudflareSubscriptions.d.mts +87 -0
  35. package/dist/CloudflareSubscriptions.mjs +524 -0
  36. package/dist/CloudflareSubscriptions.mjs.map +1 -0
  37. package/dist/CloudflareThreadClient.d.mts +1286 -0
  38. package/dist/CloudflareThreadClient.mjs +386 -0
  39. package/dist/CloudflareThreadClient.mjs.map +1 -0
  40. package/dist/InteractiveBrowser.d.mts +144 -0
  41. package/dist/InteractiveBrowser.mjs +1090 -0
  42. package/dist/InteractiveBrowser.mjs.map +1 -0
  43. package/dist/ProtectedBrowser.d.mts +65 -0
  44. package/dist/ProtectedBrowser.mjs +859 -0
  45. package/dist/ProtectedBrowser.mjs.map +1 -0
  46. package/dist/ThreadObject-BpwkEc5E.mjs +836 -0
  47. package/dist/ThreadObject-BpwkEc5E.mjs.map +1 -0
  48. package/dist/ThreadObject-NbFOWK1I.d.mts +816 -0
  49. package/dist/ThreadObject.d.mts +2 -0
  50. package/dist/ThreadObject.mjs +3 -0
  51. package/dist/WakeScheduler.d.mts +23 -0
  52. package/dist/WakeScheduler.mjs +60 -0
  53. package/dist/WakeScheduler.mjs.map +1 -0
  54. package/dist/boundary-BguazVkh.mjs +42 -0
  55. package/dist/boundary-BguazVkh.mjs.map +1 -0
  56. package/dist/browser-session-lifecycle-CUbVfEgP.mjs +84 -0
  57. package/dist/browser-session-lifecycle-CUbVfEgP.mjs.map +1 -0
  58. package/dist/browser-session-lifecycle-DJpqLXy_.d.mts +21 -0
  59. package/dist/index.d.mts +13 -1547
  60. package/dist/index.mjs +13 -1636
  61. package/dist/prepared-admission-DSi55W-7.mjs +73 -0
  62. package/dist/prepared-admission-DSi55W-7.mjs.map +1 -0
  63. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  64. package/package.json +1 -53
  65. package/src/Alarm.ts +967 -0
  66. package/src/BrowserRestCapture.ts +477 -0
  67. package/src/BrowserRestCrawl.ts +540 -0
  68. package/src/CloudflareAiGateway.ts +170 -0
  69. package/src/CloudflareBindings.ts +180 -0
  70. package/src/CloudflareBrowser.ts +15 -0
  71. package/src/{code-mode-executor.ts → CloudflareCodeMode.ts} +372 -204
  72. package/src/{config.ts → CloudflareConfig.ts} +9 -8
  73. package/src/CloudflareMemory.ts +406 -0
  74. package/src/CloudflareScheduling.ts +733 -0
  75. package/src/CloudflareSubscriptions.ts +1045 -0
  76. package/src/CloudflareThreadClient.ts +807 -0
  77. package/src/InteractiveBrowser.ts +2357 -0
  78. package/src/ProtectedBrowser.ts +2 -0
  79. package/src/ThreadObject.ts +1179 -0
  80. package/src/{wake-scheduler.ts → WakeScheduler.ts} +23 -23
  81. package/src/index.ts +12 -23
  82. package/src/internal/boundary.ts +55 -0
  83. package/src/internal/browser-quick-action.ts +857 -0
  84. package/src/internal/browser-session-lifecycle.ts +160 -0
  85. package/src/internal/layers.ts +751 -0
  86. package/src/internal/message-delivery.ts +148 -0
  87. package/src/internal/prepared-admission.ts +116 -0
  88. package/src/internal/progress-wait.ts +121 -0
  89. package/src/internal/transport.ts +42 -0
  90. package/src/protected-browser/binding.ts +187 -0
  91. package/src/protected-browser/inspect-frame.ts +125 -0
  92. package/src/protected-browser/native.ts +429 -0
  93. package/src/protected-browser/policy.ts +719 -0
  94. package/dist/index.mjs.map +0 -1
  95. package/src/alarm.ts +0 -334
  96. package/src/bindings.ts +0 -145
  97. package/src/client.ts +0 -646
  98. package/src/conversation-object.ts +0 -768
  99. package/src/layers.ts +0 -376
  100. package/src/transport.ts +0 -38
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/bindings.ts","../src/config.ts","../src/alarm.ts","../src/wake-scheduler.ts","../src/transport.ts","../src/layers.ts","../src/client.ts","../src/conversation-object.ts","../src/code-mode-executor.ts"],"sourcesContent":["import type { ConversationId } from \"@effect-agent/core\";\nimport type { ProducerId } from \"@effect-agent/session\";\nimport { Context, Effect, Layer, Schema } from \"effect\";\n\n/**\n * Cloudflare platform bindings as Effect services (DEPLOY-010: \"Cloudflare platform bindings\n * are supplied as Effect services/Layers\"). Application code never reads `env` or touches a\n * `DurableObjectState` directly — the Conversation Object class constructs these Layers once\n * per incarnation and everything downstream consumes the services.\n */\n\n/** A Cloudflare platform binding was missing or carried the wrong shape (DEPLOY-003/010). */\nexport class CloudflareBindingError extends Schema.TaggedError<CloudflareBindingError>()(\n \"CloudflareBindingError\",\n {\n binding: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/**\n * The RPC surface one Conversation Durable Object exposes to Workers and to sibling\n * Conversation Objects. `makeConversationObjectClass` implements it; the Worker-side client\n * and the cross-Object transport call it through `DurableObjectNamespace` stubs. Every\n * `encoded` value is a Schema-encoded envelope (`client.ts` wire schemas for host entry\n * points, `@effect-agent/storage-cloudflare` port envelopes for `portCall`), so the RPC\n * boundary carries only structured-cloneable JSON.\n */\nexport interface ConversationObjectRpc extends Rpc.DurableObjectBranded {\n /** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */\n submitEncoded(encoded: unknown): Promise<unknown>;\n /** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */\n awaitSettlementEncoded(encoded: unknown): Promise<unknown>;\n /** One bounded page of canonical records; answers an `ObservePageResponse`. */\n observePage(encoded: unknown): Promise<unknown>;\n /** Durable abort intent; answers an `AbortResponse`. */\n abortEncoded(encoded: unknown): Promise<unknown>;\n /** Durable approval decision (plan §2.6); answers a `ResolveApprovalResponse`. */\n resolveApprovalEncoded(encoded: unknown): Promise<unknown>;\n /** Authorized DUR-017 Unknown-Outcome resolution; answers a `ResolveUnknownResponse`. */\n resolveUnknownEncoded(encoded: unknown): Promise<unknown>;\n /** Owner-side cross-Object port endpoint (WP2 envelopes, executed on LOCAL facets). */\n portCall(encoded: unknown): Promise<unknown>;\n /** Droppable liveness hint from another Object: arms an immediate alarm. */\n wake(): Promise<void>;\n}\n\n/**\n * The `DurableObjectNamespace` binding that addresses Conversation Objects. The Object\n * identity rule is `namespace.idFromName(conversationId)` (plan §1.2): Conversation IDs are\n * globally unique, so the mapping is total and deterministic and no directory service exists.\n */\nexport class ConversationObjectNamespace extends Context.Service<\n ConversationObjectNamespace,\n {\n readonly namespace: DurableObjectNamespace<ConversationObjectRpc>;\n }\n>()(\"@effect-agent/platform-cloudflare/ConversationObjectNamespace\") {\n static layer(\n namespace: DurableObjectNamespace<ConversationObjectRpc>,\n ): Layer.Layer<ConversationObjectNamespace> {\n return Layer.succeed(ConversationObjectNamespace)({ namespace });\n }\n}\n\n/**\n * Narrow one `env` member to a `DurableObjectNamespace`. `env` is an untyped platform value,\n * and a namespace binding is a host object no Schema can decode, so this is the documented\n * narrowest-boundary check (structural probe for the namespace surface the transport uses);\n * a missing or misshaped binding fails typed before any Layer is built.\n */\nexport const conversationNamespaceFromEnv = (\n env: unknown,\n binding: string,\n): Effect.Effect<DurableObjectNamespace<ConversationObjectRpc>, CloudflareBindingError> =>\n Effect.suspend(() => {\n if (typeof env !== \"object\" || env === null) {\n return Effect.fail(\n CloudflareBindingError.make({\n binding,\n message: \"The Worker environment is not an object; no bindings are available.\",\n }),\n );\n }\n const candidate: unknown = (env as Record<string, unknown>)[binding];\n if (\n typeof candidate === \"object\" &&\n candidate !== null &&\n \"idFromName\" in candidate &&\n typeof candidate.idFromName === \"function\" &&\n \"get\" in candidate &&\n typeof candidate.get === \"function\"\n ) {\n // The structural probe above is the entire runtime contract this package relies on;\n // the assertion records that `idFromName`/`get` name a DurableObjectNamespace.\n return Effect.succeed(candidate as DurableObjectNamespace<ConversationObjectRpc>);\n }\n return Effect.fail(\n CloudflareBindingError.make({\n binding,\n message:\n `env.${binding} is not a DurableObjectNamespace binding; declare the Conversation ` +\n \"Object class under this binding in the Worker configuration.\",\n }),\n );\n });\n\n/** `ConversationObjectNamespace` built from the untyped Worker `env` (fails typed). */\nexport const conversationNamespaceLayer = (\n env: unknown,\n binding: string,\n): Layer.Layer<ConversationObjectNamespace, CloudflareBindingError> =>\n Layer.effect(ConversationObjectNamespace)(\n Effect.map(conversationNamespaceFromEnv(env, binding), (namespace) => ({ namespace })),\n );\n\n/**\n * The live Durable Object execution context of THIS incarnation. Only Layer construction and\n * the alarm service consume it; important state never lives on it (`ctx.storage` is truth,\n * everything in memory is a cache — deployment spec §11).\n */\nexport class DurableObjectContext extends Context.Service<\n DurableObjectContext,\n {\n readonly ctx: DurableObjectState;\n readonly env: unknown;\n }\n>()(\"@effect-agent/platform-cloudflare/DurableObjectContext\") {\n static layer(ctx: DurableObjectState, env: unknown): Layer.Layer<DurableObjectContext> {\n return Layer.succeed(DurableObjectContext)({ ctx, env });\n }\n}\n\n/**\n * The Conversation identity this Object serializes and the producer identity its Attempts\n * write with (`{producerPrefix}:{conversationId}`, plan §1.4). Derived once per incarnation\n * from `ctx.id.name` — the Object identity rule guarantees the name IS the Conversation ID.\n */\nexport class ConversationObjectIdentity extends Context.Service<\n ConversationObjectIdentity,\n {\n readonly conversationId: ConversationId;\n readonly producerId: ProducerId;\n }\n>()(\"@effect-agent/platform-cloudflare/ConversationObjectIdentity\") {}\n","import { DEFAULT_OWNERSHIP_LEASE_DURATION, DeploymentId } from \"@effect-agent/session\";\nimport { DEFAULT_MAX_STORED_VALUE_BYTES } from \"@effect-agent/storage-cloudflare\";\nimport { Context, Duration, Schema } from \"effect\";\n\n/**\n * Schema-validated configuration for the Cloudflare durable runtime (deployment spec §4:\n * decoded once during Layer construction, exposed as a typed service; DEPLOY-003). Every\n * cadence is in milliseconds; every bound is finite and checked before any resource opens.\n */\n\nconst PositiveMillis = Schema.Int.check(Schema.isGreaterThan(0));\nconst NonNegativeMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));\n\n/** The supplied Cloudflare durable runtime configuration failed validation (DEPLOY-003). */\nexport class CloudflarePlatformConfigError extends Schema.TaggedError<CloudflarePlatformConfigError>()(\n \"CloudflarePlatformConfigError\",\n {\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\n/**\n * An admission was refused by a host resource limit BEFORE any ledger row existed\n * (deployment spec §8, DEPLOY-007: \"Admission has explicit bounded quota and overload\n * behavior... a typed rejection\"). This is the DC analogue of `NodeDurableHost`'s\n * `AdmissionClosed` host gate: the port surface stays untouched, the refusal happens in the\n * Conversation Object's submit entry point before `DurableAgentRuntime.submit` runs, and\n * nothing was admitted or written.\n */\nexport class AdmissionLimitExceeded extends Schema.TaggedError<AdmissionLimitExceeded>()(\n \"AdmissionLimitExceeded\",\n {\n limit: Schema.Literals([\"queue-depth\", \"input-bytes\", \"database-bytes\"]),\n actual: Schema.Int,\n maximum: Schema.Int,\n },\n) {\n override get message() {\n return (\n `Admission refused before any ledger row existed: ${this.limit} ${this.actual} exceeds ` +\n `the configured maximum ${this.maximum}. Accepted work is unaffected; retry after the ` +\n \"lane drains or raise the limit (DEPLOY-007).\"\n );\n }\n}\n\n/** The platform's hard per-Object database cap (10 GB, developers.cloudflare.com limits). */\nexport const CLOUDFLARE_DATABASE_CAP_BYTES = 10_000_000_000;\n\n/** Default database-size admission ceiling: a 1 GB safety margin under the platform cap. */\nexport const DEFAULT_MAX_DATABASE_BYTES = 9_000_000_000;\n\n/**\n * Explicit bounded admission quotas checked by the Conversation Object BEFORE admission\n * (exit gate \"resource limits are checked before admission\").\n */\nexport class CloudflareAdmissionLimitsValue extends Schema.Class<CloudflareAdmissionLimitsValue>(\n \"@effect-agent/platform-cloudflare/CloudflareAdmissionLimitsValue\",\n)({\n /** Maximum nonterminal Submissions per Conversation lane before new admissions refuse. */\n maxQueueDepthPerLane: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(100_000),\n ),\n /** Maximum encoded input bytes; never above the storage per-value bound. */\n maxInputBytes: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(2_000_000)),\n /** Maximum `ctx.storage.sql.databaseSize` at admission; stays under the 10 GB platform cap. */\n maxDatabaseBytes: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(CLOUDFLARE_DATABASE_CAP_BYTES),\n ),\n}) {}\n\n/**\n * Validated Cloudflare durable runtime configuration. The producer identity of one\n * Conversation Object is `{producerPrefix}:{conversationId}` — stable across incarnations of\n * the same deployment, distinct across deployments — and producer-epoch fencing (not the\n * producer name) remains the correctness authority (DUR-006).\n */\nexport class CloudflareDurableRuntimeConfigValue extends Schema.Class<CloudflareDurableRuntimeConfigValue>(\n \"@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfigValue\",\n)({\n deploymentId: DeploymentId,\n /** Head of the minted producer identity `{producerPrefix}:{conversationId}`. */\n producerPrefix: Schema.NonEmptyString.check(Schema.isMaxLength(256)),\n /** Submission ownership lease duration (D5); fences work across Object incarnations. */\n ownershipLeaseDuration: PositiveMillis,\n /** Base delay of the alarm re-arm backoff when a pass makes no progress. */\n alarmBackoffBase: PositiveMillis,\n /** Ceiling of the alarm re-arm backoff. */\n alarmBackoffCap: PositiveMillis,\n /**\n * The maintenance-pass scan cadence and the ceiling of every re-arm delay: nonterminal\n * work is revisited at least this often (wake/scan pairing, persistence §14).\n */\n wakeScanInterval: PositiveMillis,\n /** `awaitSettlement` ledger re-check cadence when no wake arrives. */\n settlementPollInterval: PositiveMillis,\n /** Worker ownership-lease renewal cadence during an active Attempt. */\n leaseRenewalInterval: PositiveMillis,\n /** Active-Run abort-intent poll cadence. */\n abortPollInterval: PositiveMillis,\n /** Canonical observation poll cadence of the Durable Object store. */\n observationPollInterval: NonNegativeMillis,\n /** Per-value byte bound; must stay under the platform's 2 MB SQLite value limit. */\n maxStoredValueBytes: Schema.Int.check(\n Schema.isGreaterThan(0),\n Schema.isLessThanOrEqualTo(2_000_000),\n ),\n /** Opt-in full payload/digest-chain audit while opening the store. */\n verifyOnOpen: Schema.Boolean,\n limits: CloudflareAdmissionLimitsValue,\n}) {}\n\n/** Explicit configuration authority for the assembled Cloudflare durable runtime. */\nexport class CloudflareDurableRuntimeConfig extends Context.Service<\n CloudflareDurableRuntimeConfig,\n CloudflareDurableRuntimeConfigValue\n>()(\"@effect-agent/platform-cloudflare/CloudflareDurableRuntimeConfig\") {}\n\n/** Documented production defaults applied by `CloudflareDurableRuntime.layer`. */\nexport const CLOUDFLARE_RUNTIME_DEFAULTS = {\n ownershipLeaseDuration: Duration.toMillis(DEFAULT_OWNERSHIP_LEASE_DURATION),\n alarmBackoffBase: 100,\n alarmBackoffCap: 5_000,\n wakeScanInterval: 1_000,\n settlementPollInterval: 500,\n leaseRenewalInterval: 10_000,\n abortPollInterval: 500,\n observationPollInterval: 25,\n maxStoredValueBytes: DEFAULT_MAX_STORED_VALUE_BYTES,\n verifyOnOpen: false,\n maxQueueDepthPerLane: 256,\n maxInputBytes: DEFAULT_MAX_STORED_VALUE_BYTES,\n maxDatabaseBytes: DEFAULT_MAX_DATABASE_BYTES,\n} as const;\n","import {\n AgentBindingResolver,\n DurableAgentRuntime,\n SubmissionLedger,\n type DurableBindingFailure,\n type DurableWorkerFailure,\n type RecoveryReport,\n} from \"@effect-agent/session\";\nimport { Clock, Context, Effect, Layer, Option, Random, Ref, Schema, Stream } from \"effect\";\n\nimport { ConversationObjectIdentity, DurableObjectContext } from \"./bindings.ts\";\nimport { CloudflareDurableRuntimeConfig } from \"./config.ts\";\n\n/**\n * The single multiplexed Durable Object alarm (decision D-P6-2). A Durable Object has ONE\n * alarm slot; every cadence the Node host ran on fibers (wake scan, lease expiry, settlement\n * and abort re-checks, retry backoff) multiplexes into one idempotent maintenance pass, and\n * the slot always holds the EARLIEST deadline any caller asked for.\n *\n * The alarm invariant (plan §1.4): committed nonterminal work implies a committed alarm.\n * It is established by pre-arming — every mutating entry point and every pass arms the alarm\n * BEFORE its durable mutations — so an eviction at any failpoint leaves a persisted alarm\n * that workerd re-delivers to a fresh incarnation WITHOUT any incoming request. Spurious\n * alarms are harmless by design: a pass over an all-settled lane simply deletes the slot.\n */\n\n/** The Durable Object alarm API failed; surfaces on host entry points as a typed refusal. */\nexport class DurableAlarmError extends Schema.TaggedError<DurableAlarmError>()(\n \"DurableAlarmError\",\n {\n operation: Schema.String,\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\nconst alarmFailure =\n (operation: string) =>\n (cause: unknown): DurableAlarmError =>\n DurableAlarmError.make({\n operation,\n message: cause instanceof Error ? cause.message : String(cause),\n cause,\n });\n\n/** `ctx.storage` alarm slot as an Effect service; storage is truth, never a memory field. */\nexport class DurableAlarmService extends Context.Service<\n DurableAlarmService,\n {\n /** The scheduled deadline in epoch milliseconds, if any. */\n readonly scheduled: Effect.Effect<Option.Option<number>, DurableAlarmError>;\n /** Replace the slot with this deadline. */\n readonly scheduleAt: (epochMillis: number) => Effect.Effect<void, DurableAlarmError>;\n /** Keep the EARLIER of the existing deadline and this one (the multiplexing rule). */\n readonly ensureScheduledBy: (epochMillis: number) => Effect.Effect<void, DurableAlarmError>;\n /**\n * Arm an immediate alarm (the durable, coalescing local wake) — DEFERRED while a\n * maintenance pass is executing. Workerd cancels an in-flight alarm handler when a new\n * EARLIER deadline is written during its execution (`requestScheduledAlarm`), and the\n * maintenance pass runs INSIDE the alarm handler: an immediate wake landing mid-pass\n * (a routed port mutation, a sibling's `wake()`, the coordinator's own local notify)\n * would kill the running Attempt — manufacturing an ownership loss no real eviction\n * caused, and routing open uncertain-class Tool Calls into spurious Unknown Outcomes.\n * Deferral is contract-safe: wakes are droppable hints, every mutating entry point\n * pre-arms BEFORE its first durable mutation (the alarm invariant never rests on this\n * call), and the deferred wake is flushed when the pass completes.\n */\n readonly scheduleNow: Effect.Effect<void, DurableAlarmError>;\n /**\n * Run one maintenance pass with wake deferral (see `scheduleNow`): `scheduleNow` calls\n * while `body` executes coalesce into one flag, flushed as an immediate re-arm after the\n * pass — failures of the flush are logged and swallowed (hints are droppable; the pass's\n * own re-arm policy already bounded the next delivery).\n */\n readonly withWakesDeferred: <A, E, R>(body: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;\n /** Clear the slot; only the maintenance pass does this, and only when all work settled. */\n readonly cancel: Effect.Effect<void, DurableAlarmError>;\n }\n>()(\"@effect-agent/platform-cloudflare/DurableAlarmService\") {\n static readonly layer: Layer.Layer<DurableAlarmService, never, DurableObjectContext> =\n Layer.effect(DurableAlarmService)(\n Effect.gen(function* () {\n const { ctx } = yield* DurableObjectContext;\n /**\n * In-memory pass bookkeeping — a pure CACHE, never state: a fresh incarnation has no\n * running pass, and a deferred wake lost to eviction was only ever a promptness hint\n * on top of the already-committed pre-armed alarm.\n */\n const runningPasses = yield* Ref.make(0);\n const wakeDeferred = yield* Ref.make(false);\n const scheduled = Effect.tryPromise({\n try: () => ctx.storage.getAlarm(),\n catch: alarmFailure(\"get alarm\"),\n }).pipe(\n Effect.map((deadline) =>\n deadline === null ? Option.none<number>() : Option.some(deadline),\n ),\n );\n const scheduleAt = (epochMillis: number) =>\n Effect.tryPromise({\n try: () => ctx.storage.setAlarm(epochMillis),\n catch: alarmFailure(\"set alarm\"),\n });\n const ensureScheduledBy = (epochMillis: number) =>\n scheduled.pipe(\n Effect.flatMap((existing) =>\n Option.isSome(existing) && existing.value <= epochMillis\n ? Effect.void\n : scheduleAt(epochMillis),\n ),\n );\n const armNow = Clock.currentTimeMillis.pipe(\n Effect.flatMap((now) => ensureScheduledBy(now)),\n );\n const scheduleNow = Ref.get(runningPasses).pipe(\n Effect.flatMap((passes) => (passes > 0 ? Ref.set(wakeDeferred, true) : armNow)),\n );\n /**\n * Flush after the LAST concurrent pass: the re-arm lands at the very end of the alarm\n * handler, where a superseding cancellation only re-delivers to the already-idempotent\n * pass. Runs inside `Effect.ensuring`, so flush failures are logged, never raised.\n */\n const flushDeferredWake = Ref.get(runningPasses).pipe(\n Effect.flatMap((passes) =>\n passes > 0\n ? Effect.void\n : Ref.getAndSet(wakeDeferred, false).pipe(\n Effect.flatMap((wanted) => (wanted ? armNow : Effect.void)),\n ),\n ),\n Effect.catch((error) =>\n Effect.logWarning(\"DurableAlarmService: deferred wake flush failed\", error),\n ),\n );\n const withWakesDeferred = <A, E, R>(body: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n Ref.update(runningPasses, (passes) => passes + 1).pipe(\n Effect.andThen(body),\n Effect.ensuring(\n Ref.update(runningPasses, (passes) => passes - 1).pipe(\n Effect.andThen(flushDeferredWake),\n ),\n ),\n );\n const cancel = Effect.tryPromise({\n try: () => ctx.storage.deleteAlarm(),\n catch: alarmFailure(\"delete alarm\"),\n });\n return DurableAlarmService.of({\n scheduled,\n scheduleAt,\n ensureScheduledBy,\n scheduleNow,\n withWakesDeferred,\n cancel,\n });\n }),\n );\n}\n\n/** What one maintenance pass did — auditable evidence mirroring `NodeDurableHost`'s report. */\nexport class MaintenancePassReport extends Schema.Class<MaintenancePassReport>(\n \"@effect-agent/platform-cloudflare/MaintenancePassReport\",\n)({\n /** Recovery decisions executed (or deferred) BEFORE any new claim in this pass. */\n recovered: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n /** Settlements the drain pass finalized. */\n settled: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n /** Submissions still nonterminal after the pass (suspended/unknown lanes stay honest). */\n nonterminal: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),\n /** `rearmed` while nonterminal work remains, `cleared` once everything settled. */\n alarm: Schema.Literals([\"rearmed\", \"cleared\"]),\n}) {}\n\nexport type MaintenancePassFailure =\n | DurableWorkerFailure\n | DurableBindingFailure\n | DurableAlarmError;\n\n/**\n * The idempotent maintenance pass and the alarm-invariant helpers (plan §1.4, D-P6-1/2).\n *\n * `pass` = pre-arm → `runRecovery` → `processConversationResolved` → re-arm-or-clear:\n *\n * 1. **Pre-arm**: the alarm is re-armed at `now + wakeScanInterval` BEFORE any work, so an\n * eviction (or thrown failure → workerd alarm retry) at any point of the pass leaves a\n * committed alarm and the fresh incarnation converges without an incoming request.\n * 2. **Reconcile before new work** (exit gate): every pass classifies and repairs every\n * nonterminal Submission before the drain claims anything; the pure classifier and the\n * repair executors are idempotent, so at-least-once alarm delivery re-runs them safely.\n * 3. **Drain**: one bounded `processConversationResolved` pass over this Object's lane — the\n * D-P6-1 shape; no infinite `runResolvedWorker` loop ever pins the Object.\n * 4. **Re-arm policy**: nonterminal work re-arms at `now + min(backoff-with-jitter,\n * wakeScanInterval)` — the scan interval bounds every wait (lease expiry of a dead\n * incarnation included, since claims retry each pass) and the backoff (reset on progress,\n * grown otherwise) keeps stuck lanes from busy-spinning; all settled clears the slot.\n *\n * Every step is a durability-protocol step that already tolerates re-execution, which is\n * what makes double-fired alarms harmless (the alarm.test.ts gate).\n */\nexport class ConversationMaintenance extends Context.Service<\n ConversationMaintenance,\n {\n /** One idempotent maintenance pass; failures propagate so workerd retries the alarm. */\n readonly pass: Effect.Effect<MaintenancePassReport, MaintenancePassFailure>;\n /**\n * Defensive half of the alarm invariant, run by the constructor gate: if any local\n * Submission is nonterminal and no alarm is scheduled, arm one within the scan interval.\n * Local-only (one ledger scan + the alarm slot) — never a recovery pass, never transport.\n */\n readonly ensureAlarm: Effect.Effect<void, MaintenancePassFailure>;\n /**\n * The pre-arm every mutating entry point runs BEFORE its first durable mutation: with\n * the alarm committed first, a committed admission (or any other committed nonterminal\n * transition) can never be observed without the alarm that will finish it.\n */\n readonly preArm: Effect.Effect<void, DurableAlarmError>;\n }\n>()(\"@effect-agent/platform-cloudflare/ConversationMaintenance\") {\n static readonly layer: Layer.Layer<\n ConversationMaintenance,\n never,\n | DurableAgentRuntime\n | AgentBindingResolver\n | SubmissionLedger\n | DurableAlarmService\n | CloudflareDurableRuntimeConfig\n | ConversationObjectIdentity\n > = Layer.effect(ConversationMaintenance)(\n Effect.gen(function* () {\n const runtime = yield* DurableAgentRuntime;\n const resolver = yield* AgentBindingResolver;\n const ledger = yield* SubmissionLedger;\n const alarm = yield* DurableAlarmService;\n const config = yield* CloudflareDurableRuntimeConfig;\n const identity = yield* ConversationObjectIdentity;\n\n /**\n * Consecutive no-progress passes — an in-memory CACHE, not state: a fresh incarnation\n * restarts at zero and merely re-arms sooner than a long-lived one would have.\n */\n const stalls = yield* Ref.make(0);\n\n const preArm = Clock.currentTimeMillis.pipe(\n Effect.flatMap((now) => alarm.ensureScheduledBy(now + config.wakeScanInterval)),\n );\n\n const countNonterminal = Stream.runCollect(ledger.scanNonterminal).pipe(\n Effect.map((snapshots) => snapshots.length),\n );\n\n const rearmDelay = Effect.fn(\"ConversationMaintenance.rearmDelay\")(function* (\n progressed: boolean,\n ) {\n const priorStalls = yield* Ref.getAndUpdate(stalls, (count) =>\n progressed ? 0 : count + 1,\n );\n if (progressed) return config.alarmBackoffBase;\n const exponent = Math.min(priorStalls, 30);\n const backoff = Math.min(config.alarmBackoffCap, config.alarmBackoffBase * 2 ** exponent);\n const jitter = yield* Random.next;\n // Full jitter over [backoff/2, backoff]: desynchronizes retry storms without ever\n // waiting longer than the deterministic bound.\n const jittered = Math.ceil(backoff / 2 + (backoff / 2) * jitter);\n return Math.min(jittered, config.wakeScanInterval);\n });\n\n const pass = Effect.fn(\"ConversationMaintenance.pass\")(function* (): Effect.fn.Return<\n MaintenancePassReport,\n MaintenancePassFailure\n > {\n // Step 1 — pre-arm: an abort or throw anywhere below leaves a committed alarm.\n yield* preArm;\n // Step 2 — reconciliation strictly precedes new work in this pass (exit gate).\n const recovered: ReadonlyArray<RecoveryReport> = yield* runtime.runRecovery;\n // Step 3 — one bounded drain pass over this Object's own lane.\n const settlements = yield* runtime\n .processConversationResolved(identity.conversationId)\n .pipe(Effect.provideService(AgentBindingResolver, resolver));\n // Step 4 — re-arm or clear.\n const nonterminal = yield* countNonterminal;\n if (nonterminal === 0) {\n yield* alarm.cancel;\n yield* Ref.set(stalls, 0);\n // Close the cancel/admission interleaving window: a submission committing between\n // the count and the cancel (Durable Object events interleave at storage-operation\n // boundaries) must not be left without its alarm. The recount re-arms if anything\n // appeared; the submit entry's own `scheduleNow` covers commits after the recount.\n const appeared = yield* countNonterminal;\n if (appeared > 0) {\n yield* preArm;\n return MaintenancePassReport.make({\n recovered: recovered.length,\n settled: settlements.length,\n nonterminal: appeared,\n alarm: \"rearmed\",\n });\n }\n return MaintenancePassReport.make({\n recovered: recovered.length,\n settled: settlements.length,\n nonterminal,\n alarm: \"cleared\",\n });\n }\n const progressed =\n settlements.length > 0 || recovered.some((report) => report.disposition === \"repaired\");\n const delay = yield* rearmDelay(progressed);\n const now = yield* Clock.currentTimeMillis;\n yield* alarm.ensureScheduledBy(now + delay);\n return MaintenancePassReport.make({\n recovered: recovered.length,\n settled: settlements.length,\n nonterminal,\n alarm: \"rearmed\",\n });\n });\n\n const ensureAlarm = Effect.fn(\"ConversationMaintenance.ensureAlarm\")(function* () {\n const nonterminal = yield* countNonterminal;\n if (nonterminal === 0) return;\n yield* preArm;\n });\n\n return ConversationMaintenance.of({\n // Wake deferral (see `DurableAlarmService.scheduleNow`): an immediate wake written\n // while THIS handler runs would make workerd cancel it mid-Attempt; deferring keeps\n // the running pass alive and flushes the hint as the pass's final re-arm.\n pass: alarm.withWakesDeferred(pass()),\n ensureAlarm: ensureAlarm(),\n preArm,\n });\n }),\n );\n}\n","import type { ConversationId } from \"@effect-agent/core\";\nimport { WakeScheduler } from \"@effect-agent/session\";\nimport { Effect, Layer, PubSub, Schema, Stream } from \"effect\";\n\nimport { DurableAlarmService } from \"./alarm.ts\";\nimport { ConversationObjectIdentity, ConversationObjectNamespace } from \"./bindings.ts\";\n\n/**\n * Bounded in-memory wake buffer for same-incarnation `awaitSettlement` subscribers. Wake\n * hints are droppable by contract (consumers pair every subscription with ledger polls), so\n * a full buffer slides out the oldest hint and an eviction simply loses the buffer — the\n * poll interval and the persisted alarm keep liveness (persistence §14).\n */\nconst WAKE_BUFFER_CAPACITY = 1_024;\n\n/** A remote wake stub call failed; always swallowed and logged (hints are droppable). */\nclass RemoteWakeDropped extends Schema.TaggedError<RemoteWakeDropped>()(\"RemoteWakeDropped\", {\n conversationId: Schema.String,\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n}) {}\n\n/**\n * The DC `WakeScheduler` (plan §1.4):\n *\n * - `notify(local)` → `setAlarm(now)` — durable, cheap, coalescing (the alarm slot keeps the\n * earliest deadline) — plus a same-incarnation PubSub hint for `awaitSettlement` waiters.\n * - `notify(remote)` → fire-and-forget `wake()` on the owning Object's stub with every error\n * swallowed and logged: hints are droppable, and the target's own alarm/scan pairing (the\n * maintenance pass re-polls unsettled children) guarantees liveness without this call.\n * - `wakes` → the bounded sliding PubSub only. No important state lives in memory: the\n * subscription accelerates waiters within one incarnation and the settlement poll interval\n * is the correctness path.\n */\nexport const cloudflareWakeSchedulerLayer: Layer.Layer<\n WakeScheduler,\n never,\n DurableAlarmService | ConversationObjectIdentity | ConversationObjectNamespace\n> = Layer.effect(WakeScheduler)(\n Effect.gen(function* () {\n const alarm = yield* DurableAlarmService;\n const identity = yield* ConversationObjectIdentity;\n const { namespace } = yield* ConversationObjectNamespace;\n const hints = yield* PubSub.sliding<ConversationId>(WAKE_BUFFER_CAPACITY);\n yield* Effect.addFinalizer(() => PubSub.shutdown(hints));\n\n const notifyLocal = (conversationId: ConversationId) =>\n PubSub.publish(hints, conversationId).pipe(\n Effect.andThen(alarm.scheduleNow),\n Effect.catch((error) =>\n // `notify` never fails by contract; a failed alarm write degrades to \"hint lost\"\n // and the pass re-arm (or the next entry point's pre-arm) restores the invariant.\n Effect.logWarning(\"CloudflareWakeScheduler: local alarm wake failed\", error),\n ),\n Effect.asVoid,\n );\n\n const notifyRemote = (conversationId: ConversationId) =>\n Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(conversationId)).wake(),\n catch: (cause) =>\n RemoteWakeDropped.make({\n conversationId,\n message: cause instanceof Error ? cause.message : String(cause),\n cause,\n }),\n }).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\n `CloudflareWakeScheduler: remote wake of ${conversationId} dropped`,\n error,\n ),\n ),\n Effect.asVoid,\n );\n\n return WakeScheduler.of({\n notify: (conversationId) =>\n conversationId === identity.conversationId\n ? notifyLocal(conversationId)\n : notifyRemote(conversationId),\n wakes: Stream.fromPubSub(hints),\n });\n }),\n);\n","import { ConversationPortTransport, portTransportFailure } from \"@effect-agent/storage-cloudflare\";\nimport { Effect, Layer } from \"effect\";\n\nimport { ConversationObjectNamespace } from \"./bindings.ts\";\n\n/**\n * `ConversationPortTransport` over native Durable Object JS RPC (decision D-P6-3): one\n * `portCall(envelope)` on the stub of the Object that owns the addressed Conversation\n * (`namespace.idFromName(conversationId)` — 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 conversationPortTransportLayer: Layer.Layer<\n ConversationPortTransport,\n never,\n ConversationObjectNamespace\n> = Layer.effect(ConversationPortTransport)(\n Effect.gen(function* () {\n const { namespace } = yield* ConversationObjectNamespace;\n return ConversationPortTransport.of({\n call: (conversationId, request) =>\n Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(conversationId)).portCall(request),\n catch: (cause) => portTransportFailure(conversationId, cause),\n }).pipe(\n Effect.withSpan(\"CloudflarePortTransport.call\", {\n attributes: { conversationId },\n }),\n ),\n });\n }),\n);\n","import { ConversationId } from \"@effect-agent/core\";\nimport {\n AgentBindingResolver,\n ConversationStore,\n DurableAgentRuntime,\n DurableRuntimeConfig,\n DurableRuntimeFailpoint,\n ProducerId,\n SubmissionLedger,\n ToolReconciler,\n WakeScheduler,\n type DurableRuntimeFailpointHandler,\n type ResolvedBinding,\n} from \"@effect-agent/session\";\nimport {\n conversationStoreLayer,\n handleEncodedPortRequest,\n routedConversationStoreLayer,\n routedSubmissionLedgerLayer,\n storageConfigLayer,\n storageFailpointLayer,\n submissionLedgerLayer,\n type DoStorageFailpointHandler,\n type DoStorageInitializationError,\n type DoStorageOptions,\n} from \"@effect-agent/storage-cloudflare\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Context, Duration, Effect, Layer, Schema } from \"effect\";\n\nimport { ConversationMaintenance, DurableAlarmService } from \"./alarm.ts\";\nimport {\n ConversationObjectIdentity,\n ConversationObjectNamespace,\n DurableObjectContext,\n} from \"./bindings.ts\";\nimport {\n CLOUDFLARE_RUNTIME_DEFAULTS,\n CloudflareDurableRuntimeConfig,\n CloudflareDurableRuntimeConfigValue,\n CloudflarePlatformConfigError,\n} from \"./config.ts\";\nimport { conversationPortTransportLayer } from \"./transport.ts\";\nimport { cloudflareWakeSchedulerLayer } from \"./wake-scheduler.ts\";\n\n/**\n * Raw (unvalidated) construction options for `CloudflareDurableRuntime.layer`, mirroring\n * `NodeDurableRuntimeOptions`. 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}:{conversationId}`. */\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 /** 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 /**\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 * Registered worker Bindings resolved at durable claim time (S2, spec/subagents.md §11):\n * build each with `DurableWorkerBinding.make(binding, digests)`. An Effect or callback form is\n * accepted because capture can be effectful. The callback receives the live Object context and\n * derived identities and is evaluated once per incarnation during Layer construction. Defaults\n * to the empty registration (every resolved claim fails closed).\n */\n readonly bindings?: CloudflareBindingSource | undefined;\n}\n\n/** Per-incarnation host values available while registered worker Bindings are captured. */\nexport interface CloudflareBindingSourceContext {\n readonly ctx: DurableObjectState;\n readonly env: unknown;\n readonly conversationId: ConversationId;\n readonly producerId: ProducerId;\n}\n\n/**\n * Registered worker Bindings, or a closed Effect/callback that captures them once for each\n * Durable Object incarnation. Callback Effects cannot require services or fail typed.\n */\nexport type CloudflareBindingSource =\n | ReadonlyArray<ResolvedBinding>\n | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>\n | ((\n context: CloudflareBindingSourceContext,\n ) =>\n | ReadonlyArray<ResolvedBinding>\n | Effect.Effect<ReadonlyArray<ResolvedBinding>, never, never>);\n\n/** Every construction failure of the assembled Cloudflare durable runtime stack. */\nexport type CloudflareDurableRuntimeInitializationError =\n | CloudflarePlatformConfigError\n | DoStorageInitializationError;\n\n/** The services `CloudflareDurableRuntime.layer` provides. */\nexport type CloudflareDurableRuntimeServices =\n | DurableAgentRuntime\n | SubmissionLedger\n | ConversationStore\n | WakeScheduler\n | DurableRuntimeConfig\n | AgentBindingResolver\n | CloudflareDurableRuntimeConfig\n | ConversationObjectIdentity\n | DurableAlarmService\n | ConversationMaintenance\n | ConversationObjectPorts;\n\n/**\n * Owner-side endpoint body for the Conversation Object's `portCall` (plan §1.3): decode,\n * execute against THIS Object's LOCAL port facets — never the routed decorators, so a\n * request cannot bounce between Objects — and answer the encoded response envelope. Total by\n * construction (protocol anomalies answer `PortFailed(PortProtocolError)`).\n */\nexport class ConversationObjectPorts extends Context.Service<\n ConversationObjectPorts,\n {\n readonly handle: (encoded: unknown) => Effect.Effect<unknown>;\n }\n>()(\"@effect-agent/platform-cloudflare/ConversationObjectPorts\") {}\n\nconst decodeConfigValue = Schema.decodeUnknownEffect(CloudflareDurableRuntimeConfigValue);\nconst decodeConversationId = Schema.decodeUnknownEffect(ConversationId);\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 Conversation this Object owns, from the Object identity rule (plan §1.2): Conversation\n * Objects are addressed exclusively by `idFromName(conversationId)`, so `ctx.id.name` IS the\n * Conversation ID. An unnamed Object (from `newUniqueId`) is a deployment error, not a lane.\n */\nconst conversationIdFromState = (\n ctx: DurableObjectState,\n): Effect.Effect<ConversationId, CloudflarePlatformConfigError> =>\n ctx.id.name === undefined\n ? Effect.fail(\n CloudflarePlatformConfigError.make({\n message:\n \"This Durable Object was not created via idFromName(conversationId); Conversation \" +\n \"Objects must be addressed by their Conversation identity (plan §1.2).\",\n }),\n )\n : decodeConversationId(ctx.id.name).pipe(\n Effect.mapError((error) =>\n CloudflarePlatformConfigError.make({\n message: `The Durable Object name is not a valid ConversationId: ${error.message}`,\n cause: error,\n }),\n ),\n );\n\nconst resolveBindings = (\n source: CloudflareDurableRuntimeOptions[\"bindings\"],\n context: CloudflareBindingSourceContext,\n): Effect.Effect<ReadonlyArray<ResolvedBinding>> =>\n source === undefined\n ? Effect.succeed([])\n : Effect.isEffect(source)\n ? source\n : typeof source === \"function\"\n ? Effect.suspend(() => {\n const bindings = source(context);\n return Effect.isEffect(bindings) ? bindings : Effect.succeed(bindings);\n })\n : Effect.succeed(source);\n\n/**\n * The DC Layer assembly (deployment §12: a Layer-assembly library, not an app entrypoint;\n * plan §1.4). `layer(options)` decodes the configuration, derives this Object's Conversation\n * and producer identities, opens the Object's private SQLite database through\n * `@effect/sql-sqlite-do` for BOTH the Conversation Log and the Submission Ledger (so claims\n * fence the same producer epochs — ADR-0011 D7 transposed), wraps the local port facets with\n * the WP2 cross-Object routing decorators over the Durable Object RPC transport, wires the\n * alarm-backed wake scheduler and the maintenance pass, defaults reconciliation to the\n * fail-closed `ToolReconciler.uncertain`, and provides a ready `DurableAgentRuntime` on top.\n *\n * Storage compatibility is verified during construction: an incompatible database fails the\n * Layer typed (`DoStorageCompatibilityError`) before anything is mutated (DEPLOY-008).\n *\n * Requires only the two binding services (`DurableObjectContext`,\n * `ConversationObjectNamespace`) — platform values enter exclusively through Layers\n * (DEPLOY-010).\n */\nexport class CloudflareDurableRuntime {\n static layer(\n options: CloudflareDurableRuntimeOptions,\n ): Layer.Layer<\n CloudflareDurableRuntimeServices,\n CloudflareDurableRuntimeInitializationError,\n DurableObjectContext | ConversationObjectNamespace\n > {\n return Layer.unwrap(\n Effect.gen(function* () {\n const { ctx, env } = yield* DurableObjectContext;\n const config = yield* configFromOptions(options);\n const conversationId = yield* conversationIdFromState(ctx);\n const producerId = yield* decodeProducerId(\n `${config.producerPrefix}:${conversationId}`,\n ).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 const identityLayer = Layer.succeed(ConversationObjectIdentity)({\n conversationId,\n producerId,\n });\n const cloudflareConfigLayer = Layer.succeed(CloudflareDurableRuntimeConfig)(config);\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 failpoint: options.storageFailpoint?.(ctx),\n };\n const infrastructure = Layer.mergeAll(\n storageConfigLayer(storageOptions),\n storageFailpointLayer(storageOptions),\n SqliteClient.layer({ storage: ctx.storage }),\n BrowserCrypto.layer,\n );\n\n /**\n * ONE local-facet instance (a shared Layer value) serves both the routed decorators\n * and the owner-side `portCall` executor — the executor must never see the routed\n * ports (plan §1.3: re-routing could bounce a request between Objects).\n */\n const localPorts = Layer.mergeAll(conversationStoreLayer, submissionLedgerLayer).pipe(\n Layer.provide(infrastructure),\n );\n\n const portsEndpointLayer = Layer.effect(ConversationObjectPorts)(\n Effect.gen(function* () {\n const local = yield* Effect.context<SubmissionLedger | ConversationStore>();\n return ConversationObjectPorts.of({\n handle: (encoded) => handleEncodedPortRequest(encoded).pipe(Effect.provide(local)),\n });\n }),\n ).pipe(Layer.provide(localPorts));\n\n const routedPorts = Layer.mergeAll(\n routedSubmissionLedgerLayer({ localConversationId: conversationId }),\n routedConversationStoreLayer({ localConversationId: conversationId }),\n ).pipe(Layer.provide(localPorts), Layer.provide(conversationPortTransportLayer));\n\n const runtimeConfigLayer = Layer.succeed(DurableRuntimeConfig)(\n DurableRuntimeConfig.make({\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 }),\n );\n\n const runtimeFailpointLayer =\n options.runtimeFailpoint === undefined\n ? DurableRuntimeFailpoint.layer\n : Layer.succeed(DurableRuntimeFailpoint)({ hit: options.runtimeFailpoint(ctx) });\n const reconcilerLayer = options.toolReconciler ?? ToolReconciler.uncertain;\n const bindingResolverLayer = Layer.effect(AgentBindingResolver)(\n Effect.map(\n resolveBindings(options.bindings, { ctx, env, conversationId, producerId }),\n (bindings) => AgentBindingResolver.fromBindings(bindings),\n ),\n );\n\n const base = Layer.mergeAll(\n identityLayer,\n cloudflareConfigLayer,\n DurableAlarmService.layer,\n );\n\n const runtimeStack = DurableAgentRuntime.layer.pipe(\n Layer.provideMerge(routedPorts),\n Layer.provideMerge(cloudflareWakeSchedulerLayer),\n Layer.provideMerge(runtimeConfigLayer),\n Layer.provideMerge(bindingResolverLayer),\n Layer.provide(\n Layer.mergeAll(runtimeFailpointLayer, reconcilerLayer, BrowserCrypto.layer),\n ),\n Layer.provideMerge(base),\n );\n\n return Layer.mergeAll(\n runtimeStack,\n ConversationMaintenance.layer.pipe(Layer.provide(runtimeStack)),\n portsEndpointLayer,\n );\n }),\n );\n }\n}\n","import { AgentId, AgentInputError, type ConversationId } from \"@effect-agent/core\";\nimport {\n AbortCommand,\n AbortIntent,\n AdmissionConflict,\n AppendConflict,\n ApprovalConflict,\n ApprovalDecisionCommand,\n ApprovalDecisionIntent,\n CanonicalRecordEnvelope,\n CanonicalSequence,\n ConversationNotMaterialized,\n ConversationStoreError,\n DefinitionDigests,\n DigestError,\n DurableRuntimeFailpointError,\n FenceRejected,\n IdempotencyKey,\n JoinedToHost,\n LedgerError,\n PersistedJson,\n Principal,\n Receipt,\n Settlement,\n SettlementConflict,\n UnknownResolutionCommand,\n UnknownResolutionConflict,\n UnknownResolutionIntent,\n type DurableSubmitAgent,\n type DurableSubmitOptions,\n} from \"@effect-agent/session\";\nimport { Context, Effect, Layer, Schema } from \"effect\";\n\nimport { DurableAlarmError } from \"./alarm.ts\";\nimport { ConversationObjectNamespace, type ConversationObjectRpc } from \"./bindings.ts\";\nimport { AdmissionLimitExceeded } from \"./config.ts\";\n\n/**\n * The Worker↔Conversation-Object host protocol (plan §1.4): Schema envelopes for the host\n * entry points (`submitEncoded`, `awaitSettlementEncoded`, `observePage`, `abortEncoded`,\n * `resolveApprovalEncoded`, `resolveUnknownEncoded`) plus the Worker-side client that speaks\n * it. Mirrors the WP2 port protocol: requests and responses are closed Schema unions, typed\n * failures travel as their own tagged classes and RE-DECODE to identical tags on the caller\n * (error-tag fidelity), and protocol anomalies are answered typed instead of thrown.\n */\n\n/** Ceiling for host protocol diagnostic strings. */\nconst MAX_HOST_DIAGNOSTIC_LENGTH = 4_096;\n\nconst BoundedDiagnostic = Schema.String.check(Schema.isMaxLength(MAX_HOST_DIAGNOSTIC_LENGTH));\n\n/** Truncate a diagnostic string to the host protocol's bounded length. */\nexport const boundHostDiagnostic = (value: string): string =>\n value.length > MAX_HOST_DIAGNOSTIC_LENGTH\n ? `${value.slice(0, MAX_HOST_DIAGNOSTIC_LENGTH - 3)}...`\n : value;\n\n/**\n * The envelope itself could not be honored: the Object could not decode the request, or a\n * response could not be encoded/decoded. Never carries operation semantics.\n */\nexport class HostProtocolError extends Schema.TaggedError<HostProtocolError>()(\n \"HostProtocolError\",\n {\n message: BoundedDiagnostic,\n },\n) {}\n\n/** The Worker-side stub call itself failed (RPC rejection, overload, eviction mid-call). */\nexport class ConversationClientError extends Schema.TaggedError<ConversationClientError>()(\n \"ConversationClientError\",\n {\n conversationId: Schema.String,\n message: Schema.String,\n cause: Schema.optionalKey(Schema.Defect()),\n },\n) {}\n\n// ---------------------------------------------------------------------------\n// Requests\n// ---------------------------------------------------------------------------\n\n/**\n * One durable submission, input ALREADY encoded by the caller through the Agent Binding's\n * input schema (the Worker bundles the same Agent definitions as the Object, so schema\n * validation happens client-side; the resolved Binding re-validates at claim time). The\n * Conversation identity is deliberately absent — the addressed Object IS the lane.\n */\nexport class SubmitRequest extends Schema.Class<SubmitRequest>(\n \"@effect-agent/platform-cloudflare/SubmitRequest\",\n)({\n agentId: AgentId,\n principal: Principal,\n idempotencyKey: IdempotencyKey,\n definitions: DefinitionDigests,\n inputPayload: PersistedJson,\n}) {}\n\n/** One bounded page of canonical records after an optional sequence. */\nexport class ObservePageRequest extends Schema.Class<ObservePageRequest>(\n \"@effect-agent/platform-cloudflare/ObservePageRequest\",\n)({\n afterSequence: Schema.optionalKey(CanonicalSequence),\n limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1_024)),\n}) {}\n\n// ---------------------------------------------------------------------------\n// Responses\n// ---------------------------------------------------------------------------\n\n/**\n * Every typed failure a host entry point can produce, plus the protocol's own errors. Same\n * closed-union discipline as the WP2 `PortFailure`: members re-decode to the SAME tagged\n * classes on the Worker side; `cause` chains travel as Schema defects without instance\n * fidelity (plan §2.8).\n */\nexport const HostFailure = Schema.Union([\n AgentInputError,\n DigestError,\n AdmissionConflict,\n SettlementConflict,\n ApprovalConflict,\n UnknownResolutionConflict,\n JoinedToHost,\n LedgerError,\n ConversationStoreError,\n ConversationNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n AdmissionLimitExceeded,\n DurableAlarmError,\n HostProtocolError,\n]);\nexport type HostFailure = typeof HostFailure.Type;\n\nexport class SubmitSucceeded extends Schema.TaggedClass<SubmitSucceeded>(\n \"@effect-agent/platform-cloudflare/SubmitSucceeded\",\n)(\"SubmitSucceeded\", {\n receipt: Receipt,\n}) {}\n\nexport class SettlementReached extends Schema.TaggedClass<SettlementReached>(\n \"@effect-agent/platform-cloudflare/SettlementReached\",\n)(\"SettlementReached\", {\n settlement: Settlement,\n}) {}\n\nexport class ObservedPage extends Schema.TaggedClass<ObservedPage>(\n \"@effect-agent/platform-cloudflare/ObservedPage\",\n)(\"ObservedPage\", {\n records: Schema.Array(CanonicalRecordEnvelope).check(Schema.isMaxLength(1_024)),\n}) {}\n\nexport class AbortRecorded extends Schema.TaggedClass<AbortRecorded>(\n \"@effect-agent/platform-cloudflare/AbortRecorded\",\n)(\"AbortRecorded\", {\n intent: AbortIntent,\n}) {}\n\nexport class ApprovalRecorded extends Schema.TaggedClass<ApprovalRecorded>(\n \"@effect-agent/platform-cloudflare/ApprovalRecorded\",\n)(\"ApprovalRecorded\", {\n intent: ApprovalDecisionIntent,\n}) {}\n\nexport class UnknownResolutionRecorded extends Schema.TaggedClass<UnknownResolutionRecorded>(\n \"@effect-agent/platform-cloudflare/UnknownResolutionRecorded\",\n)(\"UnknownResolutionRecorded\", {\n intent: UnknownResolutionIntent,\n}) {}\n\n/** The entry point failed TYPED on the Object; the failure re-decodes verbatim. */\nexport class HostFailed extends Schema.TaggedClass<HostFailed>(\n \"@effect-agent/platform-cloudflare/HostFailed\",\n)(\"HostFailed\", {\n failure: HostFailure,\n}) {}\n\n/** The uniform answer of one host entry point. Callers narrow by the tag their call implies. */\nexport const HostResponse = Schema.Union([\n SubmitSucceeded,\n SettlementReached,\n ObservedPage,\n AbortRecorded,\n ApprovalRecorded,\n UnknownResolutionRecorded,\n HostFailed,\n]);\nexport type HostResponse = typeof HostResponse.Type;\n\n// ---------------------------------------------------------------------------\n// Codecs (shared by the Object endpoints and the Worker client)\n// ---------------------------------------------------------------------------\n\nexport const decodeSubmitRequest = Schema.decodeUnknownEffect(SubmitRequest);\nexport const encodeSubmitRequest = Schema.encodeEffect(SubmitRequest);\nexport const decodeReceipt = Schema.decodeUnknownEffect(Receipt);\nexport const encodeReceipt = Schema.encodeEffect(Receipt);\nexport const decodeObservePageRequest = Schema.decodeUnknownEffect(ObservePageRequest);\nexport const encodeObservePageRequest = Schema.encodeEffect(ObservePageRequest);\nexport const decodeAbortCommand = Schema.decodeUnknownEffect(AbortCommand);\nexport const encodeAbortCommand = Schema.encodeEffect(AbortCommand);\nexport const decodeApprovalDecisionCommand = Schema.decodeUnknownEffect(ApprovalDecisionCommand);\nexport const encodeApprovalDecisionCommand = Schema.encodeEffect(ApprovalDecisionCommand);\nexport const decodeUnknownResolutionCommand = Schema.decodeUnknownEffect(UnknownResolutionCommand);\nexport const encodeUnknownResolutionCommand = Schema.encodeEffect(UnknownResolutionCommand);\nexport const encodeHostResponse = Schema.encodeEffect(HostResponse);\nexport const decodeHostResponse = Schema.decodeUnknownEffect(HostResponse);\n\n// ---------------------------------------------------------------------------\n// Worker-side client\n// ---------------------------------------------------------------------------\n\n/** Failure surface of `CloudflareConversationClient.submit`. */\nexport type ClientSubmitFailure =\n | AgentInputError\n | DigestError\n | AdmissionConflict\n | LedgerError\n | ConversationStoreError\n | ConversationNotMaterialized\n | AppendConflict\n | FenceRejected\n | DurableRuntimeFailpointError\n | AdmissionLimitExceeded\n | DurableAlarmError\n | HostProtocolError\n | ConversationClientError;\n\nexport type ClientAwaitFailure =\n | LedgerError\n | SettlementConflict\n | HostProtocolError\n | ConversationClientError;\n\nexport type ClientObserveFailure =\n | ConversationStoreError\n | ConversationNotMaterialized\n | HostProtocolError\n | ConversationClientError;\n\nexport type ClientAbortFailure =\n | LedgerError\n | SettlementConflict\n | JoinedToHost\n | DurableRuntimeFailpointError\n | DurableAlarmError\n | HostProtocolError\n | ConversationClientError;\n\nexport type ClientApprovalFailure =\n | LedgerError\n | SettlementConflict\n | ApprovalConflict\n | DurableAlarmError\n | HostProtocolError\n | ConversationClientError;\n\nexport type ClientUnknownFailure =\n | LedgerError\n | SettlementConflict\n | UnknownResolutionConflict\n | JoinedToHost\n | DurableRuntimeFailpointError\n | DurableAlarmError\n | HostProtocolError\n | ConversationClientError;\n\nconst SUBMIT_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"AgentInputError\",\n \"DigestError\",\n \"AdmissionConflict\",\n \"LedgerError\",\n \"ConversationStoreError\",\n \"ConversationNotMaterialized\",\n \"AppendConflict\",\n \"FenceRejected\",\n \"DurableRuntimeFailpointError\",\n \"AdmissionLimitExceeded\",\n \"DurableAlarmError\",\n \"HostProtocolError\",\n]);\nconst AWAIT_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"LedgerError\",\n \"SettlementConflict\",\n \"HostProtocolError\",\n]);\nconst OBSERVE_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"ConversationStoreError\",\n \"ConversationNotMaterialized\",\n \"HostProtocolError\",\n]);\nconst ABORT_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"LedgerError\",\n \"SettlementConflict\",\n \"JoinedToHost\",\n \"DurableRuntimeFailpointError\",\n \"DurableAlarmError\",\n \"HostProtocolError\",\n]);\nconst APPROVAL_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"LedgerError\",\n \"SettlementConflict\",\n \"ApprovalConflict\",\n \"DurableAlarmError\",\n \"HostProtocolError\",\n]);\nconst UNKNOWN_FAILURE_TAGS: ReadonlySet<string> = new Set([\n \"LedgerError\",\n \"SettlementConflict\",\n \"UnknownResolutionConflict\",\n \"JoinedToHost\",\n \"DurableRuntimeFailpointError\",\n \"DurableAlarmError\",\n \"HostProtocolError\",\n]);\n\nconst outOfContract = (\n conversationId: string,\n operation: string,\n observed: string,\n): ConversationClientError =>\n ConversationClientError.make({\n conversationId,\n message: boundHostDiagnostic(\n `The Conversation Object answered ${operation} with the out-of-contract ${observed}.`,\n ),\n });\n\n/**\n * Narrow one decoded `HostFailed.failure` to the operation's declared failure family; an\n * out-of-contract tag folds into `ConversationClientError` instead of being erased or\n * re-thrown raw (the WP2 discipline). The predicate is the single documented narrowing over\n * the closed `HostFailure` union.\n */\nconst narrowFailure =\n <Failure extends HostFailure>(tags: ReadonlySet<string>) =>\n (failure: HostFailure): failure is Failure =>\n tags.has(failure._tag);\n\n/** Worker-side client over the Conversation Object namespace (DEPLOY-010). */\nexport class CloudflareConversationClient extends Context.Service<\n CloudflareConversationClient,\n {\n /** Encode the input client-side, then durably submit to the owning Object. */\n readonly submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) => Effect.Effect<Receipt, ClientSubmitFailure, InputSchema[\"EncodingServices\"]>;\n /** Wake-hinted, poll-guaranteed settlement wait executed inside the owning Object. */\n readonly awaitSettlement: (receipt: Receipt) => Effect.Effect<Settlement, ClientAwaitFailure>;\n /** One bounded page of canonical records. */\n readonly readPage: (\n conversationId: ConversationId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Every canonical record up to the CURRENT committed tail, via repeated pages. A\n * snapshot read, not a live observation — callers wanting liveness re-read after\n * `awaitSettlement`.\n */\n readonly readAll: (\n conversationId: ConversationId,\n ) => Effect.Effect<ReadonlyArray<CanonicalRecordEnvelope>, ClientObserveFailure>;\n /**\n * Submission-addressed operations take the owning Conversation explicitly (from the\n * Receipt): minted Submission identities stay OPAQUE outside the storage adapter that\n * minted them (D-P6-5), so the client never parses one to find the lane.\n */\n readonly abort: (\n conversationId: ConversationId,\n command: AbortCommand,\n ) => Effect.Effect<AbortIntent, ClientAbortFailure>;\n readonly resolveApproval: (\n conversationId: ConversationId,\n command: ApprovalDecisionCommand,\n ) => Effect.Effect<ApprovalDecisionIntent, ClientApprovalFailure>;\n readonly resolveUnknown: (\n conversationId: ConversationId,\n command: UnknownResolutionCommand,\n ) => Effect.Effect<UnknownResolutionIntent, ClientUnknownFailure>;\n }\n>()(\"@effect-agent/platform-cloudflare/CloudflareConversationClient\") {\n static readonly layer: Layer.Layer<\n CloudflareConversationClient,\n never,\n ConversationObjectNamespace\n > = Layer.effect(CloudflareConversationClient)(\n Effect.gen(function* () {\n const { namespace } = yield* ConversationObjectNamespace;\n\n const call = (\n conversationId: string,\n operation: string,\n invoke: (stub: DurableObjectStub<ConversationObjectRpc>) => Promise<unknown>,\n ): Effect.Effect<HostResponse, ConversationClientError | HostProtocolError> =>\n Effect.tryPromise({\n try: () => invoke(namespace.get(namespace.idFromName(conversationId))),\n catch: (cause) =>\n ConversationClientError.make({\n conversationId,\n message: boundHostDiagnostic(\n `${operation} did not reach the Conversation Object: ${\n cause instanceof Error ? cause.message : String(cause)\n }`,\n ),\n cause,\n }),\n }).pipe(\n Effect.flatMap((raw) =>\n decodeHostResponse(raw).pipe(\n Effect.mapError(\n (error): HostProtocolError =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `The ${operation} answer could not be decoded: ${error.message}`,\n ),\n }),\n ),\n ),\n ),\n Effect.withSpan(\"CloudflareConversationClient.call\", {\n attributes: { conversationId, operation },\n }),\n );\n\n const expect = <\n Result extends Exclude<HostResponse, HostFailed>,\n Failure extends HostFailure,\n >(\n conversationId: string,\n operation: string,\n resultTag: Result[\"_tag\"],\n tags: ReadonlySet<string>,\n ) => {\n const isExpected = narrowFailure<Failure>(tags);\n return (\n response: HostResponse,\n ): Effect.Effect<Result, Failure | ConversationClientError> => {\n if (response._tag === \"HostFailed\") {\n const failure = response.failure;\n return isExpected(failure)\n ? Effect.fail(failure)\n : Effect.fail(outOfContract(conversationId, operation, `failure ${failure._tag}`));\n }\n if (response._tag !== resultTag) {\n return Effect.fail(outOfContract(conversationId, operation, `result ${response._tag}`));\n }\n return Effect.succeed(response as Result);\n };\n };\n\n const readPage = (\n conversationId: ConversationId,\n options?: {\n readonly afterSequence?: CanonicalSequence | undefined;\n readonly limit?: number | undefined;\n },\n ) =>\n Effect.gen(function* () {\n const request = ObservePageRequest.make({\n ...(options?.afterSequence === undefined\n ? {}\n : { afterSequence: options.afterSequence }),\n limit: options?.limit ?? 256,\n });\n const encoded = yield* encodeObservePageRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`observePage request encode failed: ${error.message}`),\n }),\n ),\n );\n const response = yield* call(conversationId, \"observePage\", (stub) =>\n stub.observePage(encoded),\n );\n const page = yield* expect<ObservedPage, ClientObserveFailure & HostFailure>(\n conversationId,\n \"observePage\",\n \"ObservedPage\",\n OBSERVE_FAILURE_TAGS,\n )(response);\n return page.records;\n });\n\n return CloudflareConversationClient.of({\n submit: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: DurableSubmitOptions,\n ) =>\n Effect.gen(function* () {\n // Client-side half of `DurableAgentRuntime.submit`'s input boundary: encode\n // through the Agent's input schema and prove the canonical persistence bounds.\n const encodedInput = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError((cause) =>\n AgentInputError.make({ message: `Unable to encode Agent input: ${cause.message}` }),\n ),\n );\n const inputPayload = yield* Schema.decodeUnknownEffect(PersistedJson)(\n encodedInput,\n ).pipe(\n Effect.mapError(() =>\n AgentInputError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n const request = SubmitRequest.make({\n agentId: agent.definition.id,\n principal: options.principal,\n idempotencyKey: options.idempotencyKey,\n definitions: options.definitions,\n inputPayload,\n });\n const encoded = yield* encodeSubmitRequest(request).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`submit request encode failed: ${error.message}`),\n }),\n ),\n );\n const response = yield* call(options.conversationId, \"submit\", (stub) =>\n stub.submitEncoded(encoded),\n );\n const succeeded = yield* expect<SubmitSucceeded, ClientSubmitFailure & HostFailure>(\n options.conversationId,\n \"submit\",\n \"SubmitSucceeded\",\n SUBMIT_FAILURE_TAGS,\n )(response);\n return succeeded.receipt;\n }),\n\n awaitSettlement: (receipt) =>\n Effect.gen(function* () {\n const encoded = yield* encodeReceipt(receipt).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`receipt encode failed: ${error.message}`),\n }),\n ),\n );\n const response = yield* call(receipt.conversationId, \"awaitSettlement\", (stub) =>\n stub.awaitSettlementEncoded(encoded),\n );\n const settled = yield* expect<SettlementReached, ClientAwaitFailure & HostFailure>(\n receipt.conversationId,\n \"awaitSettlement\",\n \"SettlementReached\",\n AWAIT_FAILURE_TAGS,\n )(response);\n return settled.settlement;\n }),\n\n readPage,\n\n readAll: (conversationId) =>\n Effect.gen(function* () {\n const all: Array<CanonicalRecordEnvelope> = [];\n let after: CanonicalSequence | undefined;\n for (;;) {\n const page = yield* readPage(conversationId, { afterSequence: after, limit: 1_024 });\n all.push(...page);\n const last = page.at(-1);\n if (page.length < 1_024 || last === undefined) return all;\n after = last.sequence;\n }\n }),\n\n abort: (conversationId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeAbortCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`abort command encode failed: ${error.message}`),\n }),\n ),\n );\n const response = yield* call(conversationId, \"abort\", (stub) =>\n stub.abortEncoded(encoded),\n );\n const recorded = yield* expect<AbortRecorded, ClientAbortFailure & HostFailure>(\n conversationId,\n \"abort\",\n \"AbortRecorded\",\n ABORT_FAILURE_TAGS,\n )(response);\n return recorded.intent;\n }),\n\n resolveApproval: (conversationId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeApprovalDecisionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(`approval command encode failed: ${error.message}`),\n }),\n ),\n );\n const response = yield* call(conversationId, \"resolveApproval\", (stub) =>\n stub.resolveApprovalEncoded(encoded),\n );\n const recorded = yield* expect<ApprovalRecorded, ClientApprovalFailure & HostFailure>(\n conversationId,\n \"resolveApproval\",\n \"ApprovalRecorded\",\n APPROVAL_FAILURE_TAGS,\n )(response);\n return recorded.intent;\n }),\n\n resolveUnknown: (conversationId, command) =>\n Effect.gen(function* () {\n const encoded = yield* encodeUnknownResolutionCommand(command).pipe(\n Effect.mapError((error) =>\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `resolution command encode failed: ${error.message}`,\n ),\n }),\n ),\n );\n const response = yield* call(conversationId, \"resolveUnknown\", (stub) =>\n stub.resolveUnknownEncoded(encoded),\n );\n const recorded = yield* expect<\n UnknownResolutionRecorded,\n ClientUnknownFailure & HostFailure\n >(\n conversationId,\n \"resolveUnknown\",\n \"UnknownResolutionRecorded\",\n UNKNOWN_FAILURE_TAGS,\n )(response);\n return recorded.intent;\n }),\n });\n }),\n );\n}\n","import type { AgentId } from \"@effect-agent/core\";\nimport { SubmissionId } from \"@effect-agent/core\";\nimport {\n AppendConflict,\n ConversationNotMaterialized,\n ConversationRead,\n ConversationStore,\n ConversationStoreError,\n DigestError,\n DurableAgentRuntime,\n DurableRuntimeFailpointError,\n FenceRejected,\n IntegrityReport,\n LedgerError,\n ObligationReport,\n ObligationThresholds,\n OperationAuthorizationRequest,\n OperationAuthorizer,\n OperationDenied,\n OwnershipLost,\n PersistedJson,\n RecoveryExplanation,\n RecoveryReport,\n RetryCommand,\n RetryRefused,\n RunJournalError,\n SettlementConflict,\n SubmissionLedger,\n SubmissionLookupByKey,\n type DurableSubmitAgent,\n} from \"@effect-agent/session\";\nimport type { DurableObject as CloudflareDurableObject } from \"cloudflare:workers\";\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 ConversationMaintenance,\n DurableAlarmError,\n DurableAlarmService,\n type MaintenancePassFailure,\n} from \"./alarm.ts\";\nimport {\n ConversationObjectIdentity,\n DurableObjectContext,\n ConversationObjectNamespace,\n conversationNamespaceFromEnv,\n type CloudflareBindingError,\n} from \"./bindings.ts\";\nimport {\n AbortRecorded,\n ApprovalRecorded,\n HostFailed,\n HostProtocolError,\n ObservedPage,\n SettlementReached,\n SubmitSucceeded,\n UnknownResolutionRecorded,\n boundHostDiagnostic,\n decodeAbortCommand,\n decodeApprovalDecisionCommand,\n decodeObservePageRequest,\n decodeReceipt,\n decodeSubmitRequest,\n decodeUnknownResolutionCommand,\n encodeHostResponse,\n type HostFailure,\n type HostResponse,\n} from \"./client.ts\";\nimport { AdmissionLimitExceeded, CloudflareDurableRuntimeConfig } from \"./config.ts\";\nimport {\n CloudflareDurableRuntime,\n ConversationObjectPorts,\n type CloudflareDurableRuntimeInitializationError,\n type CloudflareDurableRuntimeOptions,\n type CloudflareDurableRuntimeServices,\n} from \"./layers.ts\";\n\n/**\n * `makeConversationObjectClass(options, observability?)` — the Conversation 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 Conversation 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` + `processConversationResolved` 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 Conversation Object class. */\nexport interface ConversationObjectOptions extends CloudflareDurableRuntimeOptions {\n /**\n * Name of the Worker `env` binding carrying THIS class's `DurableObjectNamespace` — the\n * Object's route back to sibling Conversation 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}\n\ntype EndpointServices = CloudflareDurableRuntimeServices | DurableObjectContext;\ntype RuntimeServices = EndpointServices | ConversationObjectNamespace;\ntype ConversationObjectInitializationError =\n | CloudflareDurableRuntimeInitializationError\n | CloudflareBindingError\n | MaintenancePassFailure;\n\n/** Port envelope tags whose owner-side execution durably mutates this Object's lane. */\nconst MUTATING_PORT_TAGS: ReadonlySet<string> = new Set([\n \"LedgerAdmit\",\n \"LedgerMarkReady\",\n \"LedgerRequestAbort\",\n \"LedgerRecordChildSettled\",\n \"StoreMaterialize\",\n \"StoreAppend\",\n]);\n\nconst isMutatingPortRequest = (encoded: unknown): boolean =>\n typeof encoded === \"object\" &&\n encoded !== null &&\n \"_tag\" in encoded &&\n typeof encoded._tag === \"string\" &&\n MUTATING_PORT_TAGS.has(encoded._tag);\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: unknown): 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(\"ConversationObject.gateAdmissionLimits\")(\n function* (request: {\n readonly principal: SubmissionLookupByKey[\"principal\"];\n readonly idempotencyKey: SubmissionLookupByKey[\"idempotencyKey\"];\n readonly inputPayload: PersistedJson;\n }) {\n const identity = yield* ConversationObjectIdentity;\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 conversationId: identity.conversationId,\n principal: request.principal,\n idempotencyKey: request.idempotencyKey,\n }),\n );\n if (Option.isSome(existing)) return;\n\n const inputBytes = utf8Bytes(request.inputPayload);\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 Conversation per Object (durability §5): the local scan IS this lane's queue.\n const nonterminal = yield* Stream.runCollect(ledger.scanNonterminal);\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 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/**\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* ConversationObjectIdentity;\n const maintenance = yield* ConversationMaintenance;\n const runtime = yield* DurableAgentRuntime;\n yield* gateAdmissionLimits(request);\n // Alarm invariant: the alarm commits BEFORE the admission it will finish (D-P6-2).\n yield* maintenance.preArm;\n const receipt = yield* runtime.submit(\n passthroughSubmitAgent(request.agentId),\n request.inputPayload,\n {\n conversationId: identity.conversationId,\n principal: request.principal,\n idempotencyKey: request.idempotencyKey,\n definitions: request.definitions,\n },\n );\n return SubmitSucceeded.make({ 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 return SettlementReached.make({ settlement });\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* ConversationObjectIdentity;\n const store = yield* ConversationStore;\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 yield* authorizer\n .authorize(\n OperationAuthorizationRequest.make({\n operation: \"observe\",\n conversationId: identity.conversationId,\n }),\n )\n .pipe(Effect.catchTag(\"OperationDenied\", deniedToProtocolFailure));\n const records = yield* Stream.runCollect(\n store.read(\n ConversationRead.make({\n conversationId: identity.conversationId,\n ...(request.afterSequence === undefined\n ? {}\n : { afterSequence: request.afterSequence }),\n limit: request.limit,\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* ConversationMaintenance;\n const runtime = yield* DurableAgentRuntime;\n yield* maintenance.preArm;\n const intent = yield* runtime.abort(command);\n return AbortRecorded.make({ intent });\n }),\n ),\n respond,\n Effect.flatMap(encodeResponse),\n );\n\n/**\n * The pre-P7 host protocol's failure union does not carry `OperationDenied` (the Worker client\n * predates the authorizer). This assembly always runs the default possession authorizer — no\n * `CloudflareDurableRuntimeOptions` authorizer lever exists yet — so a denial here is\n * unreachable today; if one ever surfaces it degrades to the protocol failure instead of an\n * out-of-contract throw. The four P7 admin entry points below carry `OperationDenied` typed.\n */\nconst deniedToProtocolFailure = (\n denied: OperationDenied,\n): Effect.Effect<never, HostProtocolError> =>\n Effect.fail(\n HostProtocolError.make({\n message: boundHostDiagnostic(\n `The ${denied.operation} operation was denied: ${denied.reason}`,\n ),\n }),\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* ConversationMaintenance;\n const runtime = yield* DurableAgentRuntime;\n yield* maintenance.preArm;\n const intent = yield* runtime\n .resolveApproval(command)\n .pipe(Effect.catchTag(\"OperationDenied\", deniedToProtocolFailure));\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* ConversationMaintenance;\n const runtime = yield* DurableAgentRuntime;\n yield* maintenance.preArm;\n const intent = yield* runtime\n .resolveUnknown(command)\n .pipe(Effect.catchTag(\"OperationDenied\", deniedToProtocolFailure));\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 OperationDenied,\n RetryRefused,\n LedgerError,\n RunJournalError,\n DigestError,\n OwnershipLost,\n SettlementConflict,\n ConversationStoreError,\n ConversationNotMaterialized,\n AppendConflict,\n FenceRejected,\n DurableRuntimeFailpointError,\n DurableAlarmError,\n HostProtocolError,\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]);\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* ConversationObjectIdentity;\n const runtime = yield* DurableAgentRuntime;\n const explanations =\n request.submissionId === undefined\n ? yield* runtime.explainConversation(identity.conversationId)\n : [yield* runtime.explain(request.submissionId)];\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* ConversationObjectIdentity;\n const runtime = yield* DurableAgentRuntime;\n const report = yield* runtime.verify(identity.conversationId);\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* ConversationMaintenance;\n const runtime = yield* DurableAgentRuntime;\n // Alarm invariant: retry may repair durable state, so the alarm that will finish the\n // lane commits BEFORE the mutation (D-P6-2), exactly like abort.\n yield* maintenance.preArm;\n const report = yield* runtime.retry(command);\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 return ObligationsScanned.make({ report });\n }),\n ),\n respondAdmin,\n Effect.flatMap(encodeAdminResponseTotal),\n );\n\n/**\n * Owner-side `portCall`: pre-arm before a mutating envelope (a routed admission committed by\n * THIS Object must already carry the alarm that will finish it), execute on the LOCAL facets\n * (never the routed decorators), then arm an immediate alarm so the mutated lane is\n * processed promptly. Protocol anomalies answer `PortFailed(PortProtocolError)`.\n */\nconst portCallEndpoint = (encoded: unknown): Effect.Effect<unknown, never, EndpointServices> =>\n Effect.gen(function* () {\n const ports = yield* ConversationObjectPorts;\n const maintenance = yield* ConversationMaintenance;\n const alarm = yield* DurableAlarmService;\n const mutating = isMutatingPortRequest(encoded);\n if (mutating) {\n const preArmed = yield* maintenance.preArm.pipe(Effect.exit);\n if (preArmed._tag === \"Failure\") {\n // Without the committed alarm the invariant cannot be promised; refuse the mutation.\n return encodedPortProtocolFailure(\n \"The owner Object could not arm its maintenance alarm before the mutation.\",\n );\n }\n }\n const response = yield* ports.handle(encoded);\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(\"ConversationObject.portCall: immediate re-arm failed\", error),\n ),\n );\n }\n return response;\n });\n\nconst wakeEndpoint: Effect.Effect<void, never, EndpointServices> = Effect.gen(function* () {\n const alarm = yield* DurableAlarmService;\n // Wake hints are droppable by contract: a failed alarm write is logged and swallowed; the\n // sender's own alarm/scan pairing (or this Object's next entry point) restores liveness.\n yield* alarm.scheduleNow.pipe(\n Effect.catch((error) => Effect.logWarning(\"ConversationObject.wake dropped\", error)),\n );\n});\n\nconst alarmEndpoint: Effect.Effect<void, MaintenancePassFailure, EndpointServices> = Effect.gen(\n function* () {\n const maintenance = yield* ConversationMaintenance;\n // Typed pass failures propagate: the rejected promise makes workerd retry the alarm\n // (at-least-once delivery), and the pass's own pre-arm keeps the slot committed meanwhile.\n yield* maintenance.pass;\n },\n);\n\nconst gateEndpoint: Effect.Effect<void, MaintenancePassFailure, EndpointServices> = Effect.gen(\n function* () {\n // Forcing ConversationMaintenance 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* ConversationMaintenance;\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): Layer.Layer<\n DurableObjectContext | ConversationObjectNamespace,\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 return DurableObjectContext.of({ ctx: state.raw, env });\n }),\n );\n const namespace = Layer.effect(ConversationObjectNamespace)(\n Effect.gen(function* () {\n const env = yield* WorkerEnvironment;\n const binding = yield* conversationNamespaceFromEnv(env, namespaceBinding);\n return ConversationObjectNamespace.of({ namespace: binding });\n }),\n );\n return Layer.merge(context, namespace);\n};\n\n/** The public endpoint surface of one Conversation Object instance. */\nexport interface ConversationObjectInstance extends CloudflareDurableObject {\n submitEncoded(encoded: unknown): Promise<unknown>;\n awaitSettlementEncoded(encoded: unknown): Promise<unknown>;\n observePage(encoded: unknown): Promise<unknown>;\n abortEncoded(encoded: unknown): Promise<unknown>;\n resolveApprovalEncoded(encoded: unknown): Promise<unknown>;\n resolveUnknownEncoded(encoded: 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 Conversation Object. */\nexport interface ConversationObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): ConversationObjectInstance;\n}\n\n/**\n * Build the application's Conversation Object class (export it from the Worker entry).\n * effect-cf owns the cached ManagedRuntime, native RPC methods, event scopes, and post-handler\n * OTLP flush scheduling for RPC and alarm events. The optional outer Layer is built per native\n * event, so a host can install Tracer/Logger/Metric services and `OtlpExporter.Flusher` without\n * Effect Agent owning exporter lifecycle machinery.\n */\nexport const makeConversationObjectClass = <EventLayerError = never, EventServices = never>(\n options: ConversationObjectOptions,\n observability?: Layer.Layer<\n EventServices,\n EventLayerError,\n | DurableObjectContext\n | ConversationObjectNamespace\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n >,\n): ConversationObjectClass => {\n const application: Layer.Layer<\n RuntimeServices,\n CloudflareDurableRuntimeInitializationError | CloudflareBindingError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = CloudflareDurableRuntime.layer(options).pipe(\n Layer.provideMerge(effectCfPlatformLayer(options.namespaceBinding)),\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,\n ConversationObjectInitializationError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n return yield* state.blockConcurrencyWhile(\n Effect.gen(function* () {\n const services = yield* Layer.buildWithScope(application, scope);\n yield* gateEndpoint.pipe(Effect.provide(services));\n return services;\n }),\n );\n }),\n );\n\n const rpc = {\n submitEncoded: (encoded: unknown) => submitEndpoint(encoded),\n awaitSettlementEncoded: (encoded: unknown) => awaitSettlementEndpoint(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<RuntimeServices | EventServices>;\n\n const EffectCfConversationObject = EffectCfDurableObject.make<\n RuntimeServices,\n ConversationObjectInitializationError,\n EventServices,\n EventLayerError,\n typeof rpc\n >(runtime, {\n ...(observability === undefined ? {} : { eventLayer: observability }),\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 });\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 ConversationObject extends EffectCfConversationObject {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return ConversationObject;\n};\n","import {\n CodeExecutionHost,\n CodeExecutionRequest,\n CodeExecutionResourceUse,\n CodeExecutionResult,\n CodeExecutionTimeoutError,\n CodeExecutor,\n CodeExecutorStartError,\n CodeExecutorTerminatedError,\n CodeExecutorUnsupportedError,\n CodeExecutionProtocolError,\n CodeHostCall,\n CodeHostCallLimitError,\n CodeHostCallResult,\n CodeOutputLimitError,\n CodeProgramFailedError,\n CodeSourceError,\n SandboxImplementation,\n type CodeExecutorExecute,\n} from \"@effect-agent/sandbox\";\nimport { WorkerEntrypoint } from \"cloudflare:workers\";\nimport { Clock, Duration, Effect, Fiber, Layer, Option, Schema } from \"effect\";\n\n/**\n * The Cloudflare Dynamic Worker `CodeExecutor` adapter (C4 of ADR-0017;\n * DEPLOY-011). Each pass loads one fresh Worker through the Worker Loader\n * with `globalOutbound: null`, so generated code has no ambient network,\n * bindings, or secrets; its only authority is the pass-scoped host stub that\n * routes back to `CodeModeHostEntrypoint` and, from there, into the pass's\n * `CodeExecutionHost` service. Platform CPU limits stop synchronous runaway\n * programs; the executor-owned wall-clock deadline interrupts asynchronously\n * suspended passes. Deployment class `E` only: the adapter records no\n * persistent state and a later pass may run in a completely different\n * isolate.\n */\nexport const dynamicWorkerImplementation = SandboxImplementation.make({\n isolation: \"isolated\",\n identity: \"cloudflare-dynamic-worker\",\n});\n\n/** The narrow host stub the dynamic worker receives (Workers RPC). */\nexport interface CodeModeHostStub {\n readonly call: (passId: string, hostCall: unknown) => Promise<unknown>;\n}\n\ninterface RegisteredPass {\n readonly dispatch: (hostCall: unknown) => Promise<unknown>;\n}\n\n/**\n * Live passes by identity. Entries are Scope-managed: registered when a pass\n * opens and removed by its finalizer, so a stale harness (or a forged\n * `passId`) cannot reach any host authority.\n */\nconst passRegistry = new Map<string, RegisteredPass>();\n\n/**\n * The host-side RPC target for dynamic workers. The application exposes it\n * from its Worker entry (`export { CodeModeHostEntrypoint }`) and hands the\n * adapter a same-instance stub — `ctx.exports.CodeModeHostEntrypoint()` in\n * production (a self service binding may reach a different instance and must\n * not be used there); tests bind it through Miniflare's `kCurrentWorker`.\n */\nexport class CodeModeHostEntrypoint extends WorkerEntrypoint {\n async call(passId: unknown, hostCall: unknown): Promise<unknown> {\n const pass = passRegistry.get(String(passId));\n if (pass === undefined) {\n throw new Error(\"Unknown Code Mode pass\");\n }\n return pass.dispatch(hostCall);\n }\n}\n\n/**\n * The fixed harness loaded as the dynamic worker's main module. The generated\n * source becomes `program.mjs` (`export default (<expression>);`) — a module,\n * never `eval`. The harness installs namespace globals and a bounded console,\n * imports the program, invokes it exactly once, and returns one envelope the\n * host validates through Effect Schema.\n */\nconst HARNESS_MODULE = String.raw`\nimport { WorkerEntrypoint } from \"cloudflare:workers\";\nimport programDefault from \"./program.js\";\n\nconst encoder = new TextEncoder();\nconst utf8 = (text) => encoder.encode(text).byteLength;\nconst safeText = (value) => {\n try {\n if (value instanceof Error) return (value.name + \": \" + value.message).slice(0, 4000);\n if (typeof value === \"string\") return value.slice(0, 4000);\n const encoded = JSON.stringify(value);\n return (encoded === undefined ? String(value) : encoded).slice(0, 4000);\n } catch {\n return \"[unserializable value]\";\n }\n};\nconst safeJson = (value) => {\n try {\n const encoded = JSON.stringify(value);\n if (encoded !== undefined && encoded.length <= 4000) return JSON.parse(encoded);\n } catch {}\n return safeText(value);\n};\n\nexport default class CodeModeHarness extends WorkerEntrypoint {\n async run() {\n const config = JSON.parse(this.env.CODE_MODE_PASS);\n const host = this.env.CODE_MODE_HOST;\n const limits = config.limits;\n const logs = [];\n let logBytes = 0;\n let fatal;\n const boundedLogs = () => logs.slice(0, 4096);\n const write = (...values) => {\n const joined = values.map(safeText).join(\" \");\n const line = joined.length > 16000 ? joined.slice(0, 15999) + \"…\" : joined;\n const bytes = utf8(line);\n if (logs.length >= 4096 || logBytes + bytes > limits.maxLogBytes) {\n fatal = fatal ?? { _tag: \"log-limit\", observed: logBytes + bytes, logs: boundedLogs() };\n throw new Error(\"code-mode log limit exceeded\");\n }\n logs.push(line);\n logBytes += bytes;\n };\n globalThis.console = { log: write, info: write, warn: write, error: write, debug: write };\n\n let hostCalls = 0;\n const makeMethod = (namespace, method) => async (argument) => {\n hostCalls += 1;\n if (hostCalls > limits.maxHostCalls) {\n fatal = fatal ?? { _tag: \"host-call-limit\", logs: boundedLogs() };\n throw new Error(\"code-mode host-call limit exceeded\");\n }\n let argText;\n try {\n argText = JSON.stringify(argument);\n } catch {}\n if (argText === undefined || utf8(argText) > limits.maxHostCallArgumentBytes) {\n fatal = fatal ?? {\n _tag: \"argument-limit\",\n observed: argText === undefined ? 0 : utf8(argText),\n logs: boundedLogs(),\n };\n throw new Error(\"code-mode host-call argument limit exceeded\");\n }\n const outcome = await host.call(config.passId, {\n namespace,\n method,\n argument: JSON.parse(argText),\n });\n if (outcome !== null && typeof outcome === \"object\" && outcome._tag === \"CodeHostCallSuccess\") {\n return outcome.value;\n }\n if (outcome !== null && typeof outcome === \"object\" && outcome._tag === \"CodeHostCallFailure\") {\n throw outcome.error;\n }\n fatal = fatal ?? { _tag: \"protocol\", message: \"host returned an unrecognized outcome\" };\n throw new Error(\"code-mode host protocol violation\");\n };\n for (const namespace of config.namespaces) {\n const methods = {};\n for (const method of namespace.methods) {\n methods[method] = makeMethod(namespace.name, method);\n }\n globalThis[namespace.name] = methods;\n }\n\n // program.js is imported statically at the top of this module, so a\n // syntactically invalid program fails the whole harness at load (mapped\n // to a source error by the host). Using a static import keeps this module\n // free of dynamic-import expressions, which single-script Miniflare hosts\n // reject. The isolation boundary does NOT depend on the ordering of this\n // import versus the console/namespace shims installed below: the loaded\n // Worker has globalOutbound: null and no bindings, secrets, or env from\n // the Worker Loader config BEFORE any module in the graph evaluates, so\n // module-level program code has no ambient authority regardless. The\n // shims below are usability wrappers (bounded console, namespace globals),\n // and the accepted program is a single async-function expression whose\n // body runs only when invoked here — after the shims exist.\n const program = programDefault;\n if (typeof program !== \"function\") {\n return { _tag: \"source-not-a-function\", actual: typeof program };\n }\n try {\n const value = await program();\n if (fatal !== undefined) return fatal;\n let text;\n try {\n text = JSON.stringify(value);\n } catch {}\n if (text === undefined) {\n return {\n _tag: \"program-failed\",\n reason: \"non-json-result\",\n thrown: null,\n message: \"The program must return a JSON value\",\n logs: boundedLogs(),\n };\n }\n const resultBytes = utf8(text);\n if (resultBytes > limits.maxResultBytes) {\n return { _tag: \"result-limit\", observed: resultBytes, logs: boundedLogs() };\n }\n return {\n _tag: \"completed\",\n value: JSON.parse(text),\n logs: boundedLogs(),\n hostCalls,\n logBytes,\n resultBytes,\n };\n } catch (cause) {\n if (fatal !== undefined) return fatal;\n return {\n _tag: \"program-failed\",\n reason: cause instanceof Error ? \"threw\" : \"rejected\",\n thrown: safeJson(cause),\n message: safeText(cause),\n logs: boundedLogs(),\n };\n }\n }\n}\n`;\n\nconst BoundedLogs = Schema.Array(Schema.String.check(Schema.isMaxLength(16 * 1024))).check(\n Schema.isMaxLength(4_096),\n);\n\nconst HarnessCompleted = Schema.Struct({\n _tag: Schema.Literal(\"completed\"),\n value: Schema.Json,\n logs: BoundedLogs,\n hostCalls: Schema.Natural,\n logBytes: Schema.Natural,\n resultBytes: Schema.Natural,\n});\nconst HarnessSourceInvalid = Schema.Struct({\n _tag: Schema.Literal(\"source-invalid\"),\n message: Schema.String,\n});\nconst HarnessNotAFunction = Schema.Struct({\n _tag: Schema.Literal(\"source-not-a-function\"),\n actual: Schema.String,\n});\nconst HarnessProgramFailed = Schema.Struct({\n _tag: Schema.Literal(\"program-failed\"),\n reason: Schema.Literals([\"threw\", \"rejected\", \"non-json-result\"]),\n thrown: Schema.Json,\n message: Schema.String,\n logs: BoundedLogs,\n});\nconst HarnessLogLimit = Schema.Struct({\n _tag: Schema.Literal(\"log-limit\"),\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\nconst HarnessArgumentLimit = Schema.Struct({\n _tag: Schema.Literal(\"argument-limit\"),\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\nconst HarnessResultLimit = Schema.Struct({\n _tag: Schema.Literal(\"result-limit\"),\n observed: Schema.Natural,\n logs: BoundedLogs,\n});\nconst HarnessHostCallLimit = Schema.Struct({\n _tag: Schema.Literal(\"host-call-limit\"),\n logs: BoundedLogs,\n});\nconst HarnessProtocol = Schema.Struct({\n _tag: Schema.Literal(\"protocol\"),\n message: Schema.String,\n});\nconst HarnessOutcome = Schema.Union([\n HarnessCompleted,\n HarnessSourceInvalid,\n HarnessNotAFunction,\n HarnessProgramFailed,\n HarnessLogLimit,\n HarnessArgumentLimit,\n HarnessResultLimit,\n HarnessHostCallLimit,\n HarnessProtocol,\n]);\n\nconst decodeHarnessOutcome = (value: unknown) => {\n try {\n return Schema.decodeUnknownOption(HarnessOutcome)(value);\n } catch {\n return Option.none<typeof HarnessOutcome.Type>();\n }\n};\n\nconst decodeHostCall = (value: unknown) => {\n try {\n return Schema.decodeUnknownOption(CodeHostCall)(value);\n } catch {\n return Option.none<CodeHostCall>();\n }\n};\n\n/**\n * Project a host outcome to the plain JSON envelope the harness reads. A\n * `CodeExecutionHost` may return either real `CodeHostCallResult` instances\n * (the substitute and conformance kit) or plain-object equivalents (the Code\n * Mode capability's broker route), so this reads the shared fields rather than\n * `Schema.encodeSync`, which would reject a plain object.\n */\nconst hostResultEnvelope = (outcome: CodeHostCallResult): Record<string, unknown> =>\n outcome._tag === \"CodeHostCallSuccess\"\n ? { _tag: \"CodeHostCallSuccess\", value: outcome.value }\n : { _tag: \"CodeHostCallFailure\", error: outcome.error };\n\nconst utf8ByteLength = (value: string): number => {\n let total = 0;\n for (const character of value) {\n const codePoint = character.codePointAt(0) ?? 0;\n total += codePoint <= 0x7f ? 1 : codePoint <= 0x7ff ? 2 : codePoint <= 0xffff ? 3 : 4;\n }\n return total;\n};\n\nconst encodedJsonByteLength = (value: unknown): number | undefined => {\n try {\n const encoded = JSON.stringify(value);\n return encoded === undefined ? undefined : utf8ByteLength(encoded);\n } catch {\n return undefined;\n }\n};\n\ninterface PendingHostCall {\n readonly hostCall: unknown;\n readonly resolve: (value: unknown) => void;\n readonly reject: (reason: unknown) => void;\n}\n\n/** Reserved global names the harness owns inside the dynamic worker. */\nconst reservedHarnessGlobals = new Set([\"console\"]);\n\nexport interface DynamicWorkerCodeExecutorOptions {\n /** The `worker_loader` binding. */\n readonly loader: WorkerLoader;\n /**\n * A SAME-INSTANCE stub of `CodeModeHostEntrypoint`. In production create it\n * with `ctx.exports.CodeModeHostEntrypoint()`; a cross-instance stub would\n * dispatch host calls into an isolate without this pass's registry entry.\n */\n readonly hostStub: CodeModeHostStub;\n /** Compatibility date for dynamic workers; defaults to `2025-05-01`. */\n readonly compatibilityDate?: string | undefined;\n}\n\nconst passCounterState = { next: 0 };\n\nconst makeExecute = (options: DynamicWorkerCodeExecutorOptions): CodeExecutorExecute =>\n Effect.fn(\"DynamicWorkerCodeExecutor.execute\")(function* (request: CodeExecutionRequest) {\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: dynamicWorkerImplementation,\n feature: \"network\",\n message:\n \"The Dynamic Worker executor denies all egress with globalOutbound: null; an allowlist is not supported in the first slice\",\n });\n }\n const sourceBytes = utf8ByteLength(request.source);\n if (sourceBytes > request.limits.maxSourceBytes) {\n return yield* CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"oversized\",\n message: `Source is ${sourceBytes} bytes; the request allows ${request.limits.maxSourceBytes}`,\n });\n }\n for (const namespace of request.namespaces) {\n if (reservedHarnessGlobals.has(namespace.name)) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: dynamicWorkerImplementation,\n feature: \"namespaces\",\n message: `Namespace ${namespace.name} collides with a harness binding`,\n });\n }\n }\n\n const host = yield* CodeExecutionHost;\n passCounterState.next += 1;\n // The pass id is the only credential a loaded program presents to reach\n // its host authority, so it must be unguessable: a program cannot forge\n // another pass's id even if two passes were ever concurrent (the broker\n // keeps them sequential, but the id must not rely on that). The counter\n // prefix keeps ids debuggable; the random suffix makes them unforgeable.\n const passId = `code-mode-pass-${passCounterState.next}-${crypto.randomUUID()}`;\n\n // Promise-side host calls bridge into the Effect world through a pending\n // list served by a scoped fiber, exactly like the deterministic\n // substitute: interruption reaches in-flight host calls, and pass-fatal\n // conditions fail the pass by failing the server.\n const pending: Array<PendingHostCall> = [];\n let wake: (() => void) | undefined;\n let issuedHostCalls = 0;\n const dispatch = (hostCall: unknown): Promise<unknown> =>\n new Promise((resolve, reject) => {\n issuedHostCalls += 1;\n if (issuedHostCalls > request.limits.maxHostCalls + 1) {\n reject(new Error(\"host-call limit exceeded\"));\n return;\n }\n pending.push({ hostCall, resolve, reject });\n wake?.();\n });\n\n yield* Effect.acquireRelease(\n Effect.sync(() => {\n passRegistry.set(passId, { dispatch });\n }),\n () =>\n Effect.sync(() => {\n passRegistry.delete(passId);\n }),\n );\n\n const nextPending = Effect.suspend(() => {\n const item = pending.shift();\n if (item !== undefined) {\n return Effect.succeed(item);\n }\n return Effect.callback<PendingHostCall>((resume) => {\n wake = () => {\n wake = undefined;\n const next = pending.shift();\n if (next !== undefined) {\n resume(Effect.succeed(next));\n }\n };\n });\n });\n\n const serveHostCalls = Effect.gen(function* () {\n let served = 0;\n while (true) {\n const item = yield* nextPending;\n served += 1;\n if (served > request.limits.maxHostCalls) {\n return yield* CodeHostCallLimitError.make({\n implementation: dynamicWorkerImplementation,\n limit: request.limits.maxHostCalls,\n logs: [],\n });\n }\n const decoded = decodeHostCall(item.hostCall);\n if (Option.isNone(decoded)) {\n item.reject(new TypeError(\"host calls must match the CodeHostCall schema\"));\n continue;\n }\n const outcome = yield* host.call(decoded.value);\n if (outcome._tag === \"CodeHostCallSuccess\") {\n const bytes = encodedJsonByteLength(outcome.value);\n if (bytes === undefined || bytes > request.limits.maxHostCallResultBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"host-call-result\",\n limit: request.limits.maxHostCallResultBytes,\n observed: bytes ?? 0,\n logs: [],\n });\n }\n }\n item.resolve(hostResultEnvelope(outcome));\n }\n });\n\n const workerCode = {\n compatibilityDate: options.compatibilityDate ?? \"2025-05-01\",\n allowExperimental: true,\n mainModule: \"harness.js\",\n modules: {\n \"harness.js\": HARNESS_MODULE,\n \"program.js\": `export default (\\n${request.source}\\n);`,\n },\n env: {\n CODE_MODE_HOST: options.hostStub,\n CODE_MODE_PASS: JSON.stringify({\n passId,\n namespaces: request.namespaces.map((namespace) => ({\n name: namespace.name,\n methods: namespace.methods,\n })),\n limits: {\n maxLogBytes: request.limits.maxLogBytes,\n maxResultBytes: request.limits.maxResultBytes,\n maxHostCalls: request.limits.maxHostCalls,\n maxHostCallArgumentBytes: request.limits.maxHostCallArgumentBytes,\n },\n }),\n },\n globalOutbound: null,\n ...(request.limits.cpuMillis === undefined\n ? {}\n : {\n limits: {\n cpuMs: request.limits.cpuMillis,\n subRequests: request.limits.maxHostCalls + 8,\n },\n }),\n };\n\n const startedAt = yield* Clock.currentTimeMillis;\n const worker = yield* Effect.acquireRelease(\n Effect.try({\n try: () => options.loader.load(workerCode as never),\n catch: (cause) => {\n const text = cause instanceof Error ? cause.message : String(cause);\n // Blame the program's source ONLY on a genuine compile diagnostic;\n // any other load rejection is an infrastructure start failure, not\n // the model's fault (see classifyWorkerFailure for the same split).\n if (/syntaxerror|failed to (compile|parse)/i.test(text)) {\n return CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"invalid\",\n message: text.slice(0, 8_000),\n });\n }\n return CodeExecutorStartError.make({\n implementation: dynamicWorkerImplementation,\n message: `The Worker Loader rejected the pass: ${text}`.slice(0, 8_000),\n cause,\n });\n },\n }),\n (stub) =>\n Effect.sync(() => {\n (stub as Partial<Record<typeof Symbol.dispose, () => void>>)[Symbol.dispose]?.();\n }),\n );\n\n const server = yield* serveHostCalls.pipe(Effect.forkScoped);\n\n const rpc = Effect.tryPromise({\n try: async () => {\n const entrypoint = worker.getEntrypoint() as unknown as {\n run(): Promise<unknown>;\n };\n return await entrypoint.run();\n },\n catch: (cause) => classifyWorkerFailure(cause, request.limits.maxWallTime),\n });\n\n const raw = yield* Effect.raceFirst(rpc, Fiber.join(server)).pipe(\n Effect.timeoutOrElse({\n duration: request.limits.maxWallTime,\n orElse: () =>\n CodeExecutionTimeoutError.make({\n implementation: dynamicWorkerImplementation,\n kind: \"wall-clock\",\n maxWallTime: request.limits.maxWallTime,\n logs: [],\n }),\n }),\n Effect.ensuring(Fiber.interrupt(server)),\n );\n const finishedAt = yield* Clock.currentTimeMillis;\n\n const outcome = decodeHarnessOutcome(raw);\n if (Option.isNone(outcome)) {\n return yield* CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: \"The dynamic worker returned a value outside the harness envelope schema\",\n });\n }\n switch (outcome.value._tag) {\n case \"completed\": {\n return CodeExecutionResult.make({\n implementation: dynamicWorkerImplementation,\n value: outcome.value.value,\n logs: outcome.value.logs,\n resourceUse: CodeExecutionResourceUse.make({\n wallTime: Duration.millis(Math.max(0, finishedAt - startedAt)),\n hostCalls: outcome.value.hostCalls,\n logBytes: outcome.value.logBytes,\n resultBytes: outcome.value.resultBytes,\n }),\n });\n }\n case \"source-invalid\": {\n return yield* CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"invalid\",\n message: outcome.value.message.slice(0, 8_000),\n });\n }\n case \"source-not-a-function\": {\n return yield* CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"not-a-function\",\n message: `The source expression evaluated to ${outcome.value.actual}; it must evaluate to one async function`,\n });\n }\n case \"program-failed\": {\n return yield* CodeProgramFailedError.make({\n implementation: dynamicWorkerImplementation,\n reason: outcome.value.reason,\n thrown: outcome.value.thrown,\n message: outcome.value.message.slice(0, 8_000),\n logs: outcome.value.logs,\n });\n }\n case \"log-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"logs\",\n limit: request.limits.maxLogBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"argument-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"host-call-argument\",\n limit: request.limits.maxHostCallArgumentBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"result-limit\": {\n return yield* CodeOutputLimitError.make({\n implementation: dynamicWorkerImplementation,\n surface: \"result\",\n limit: request.limits.maxResultBytes,\n observed: outcome.value.observed,\n logs: outcome.value.logs,\n });\n }\n case \"host-call-limit\": {\n return yield* CodeHostCallLimitError.make({\n implementation: dynamicWorkerImplementation,\n limit: request.limits.maxHostCalls,\n logs: outcome.value.logs,\n });\n }\n case \"protocol\": {\n return yield* CodeExecutionProtocolError.make({\n implementation: dynamicWorkerImplementation,\n message: outcome.value.message.slice(0, 8_000),\n });\n }\n }\n });\n\n/**\n * Expected worker-level failures map into the typed union with bounded\n * diagnostics; anything unrecognized stays a start/termination error rather\n * than a fabricated program result.\n */\nconst classifyWorkerFailure = (\n cause: unknown,\n maxWallTime: Duration.Duration,\n):\n | CodeExecutionTimeoutError\n | CodeExecutorTerminatedError\n | CodeExecutorStartError\n | CodeSourceError => {\n const text = (() => {\n try {\n return cause instanceof Error ? `${cause.name}: ${cause.message}` : String(cause);\n } catch {\n return \"[unserializable worker failure]\";\n }\n })();\n // `WorkerLoader.load()` is lazy, so a module-compile error in the generated\n // program surfaces here at first use. Blame the program's source ONLY on a\n // genuine compile diagnostic (a `SyntaxError` or an explicit compile\n // failure) — the fixed harness is valid, so the fault is in program.js. A\n // bare \"failed to start Worker\" without a compile diagnostic is an\n // infrastructure start failure, not the model's fault, so it must NOT be\n // misclassified as a source error.\n if (/syntaxerror|failed to (compile|parse)/i.test(text)) {\n return CodeSourceError.make({\n implementation: dynamicWorkerImplementation,\n reason: \"invalid\",\n message: text.slice(0, 8_000),\n });\n }\n if (/cpu/i.test(text)) {\n return CodeExecutionTimeoutError.make({\n implementation: dynamicWorkerImplementation,\n kind: \"cpu\",\n maxWallTime,\n logs: [],\n });\n }\n if (/failed to start worker/i.test(text)) {\n return CodeExecutorStartError.make({\n implementation: dynamicWorkerImplementation,\n message: text.slice(0, 8_000),\n cause,\n });\n }\n return CodeExecutorTerminatedError.make({\n implementation: dynamicWorkerImplementation,\n message: text.slice(0, 8_000),\n });\n};\n\n/** Layer building the Dynamic Worker `CodeExecutor` from resolved bindings. */\nexport const dynamicWorkerCodeExecutorLayer = (\n options: DynamicWorkerCodeExecutorOptions,\n): Layer.Layer<CodeExecutor> =>\n Layer.succeed(CodeExecutor)(CodeExecutor.of({ execute: makeExecute(options) }));\n"],"mappings":";;;;;;;;;;;;;;;;;AAYA,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CACtF,0BACA;CACE,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;;AAkCH,IAAa,8BAAb,MAAa,oCAAoC,QAAQ,QAKvD,CAAC,CAAC,+DAA+D,CAAC,CAAC;CACnE,OAAO,MACL,WAC0C;EAC1C,OAAO,MAAM,QAAQ,2BAA2B,CAAC,CAAC,EAAE,UAAU,CAAC;CACjE;AACF;;;;;;;AAQA,MAAa,gCACX,KACA,YAEA,OAAO,cAAc;CACnB,IAAI,OAAO,QAAQ,YAAY,QAAQ,MACrC,OAAO,OAAO,KACZ,uBAAuB,KAAK;EAC1B;EACA,SAAS;CACX,CAAC,CACH;CAEF,MAAM,YAAsB,IAAgC;CAC5D,IACE,OAAO,cAAc,YACrB,cAAc,QACd,gBAAgB,aAChB,OAAO,UAAU,eAAe,cAChC,SAAS,aACT,OAAO,UAAU,QAAQ,YAIzB,OAAO,OAAO,QAAQ,SAA0D;CAElF,OAAO,OAAO,KACZ,uBAAuB,KAAK;EAC1B;EACA,SACE,OAAO,QAAQ;CAEnB,CAAC,CACH;AACF,CAAC;;AAGH,MAAa,8BACX,KACA,YAEA,MAAM,OAAO,2BAA2B,CAAC,CACvC,OAAO,IAAI,6BAA6B,KAAK,OAAO,IAAI,eAAe,EAAE,UAAU,EAAE,CACvF;;;;;;AAOF,IAAa,uBAAb,MAAa,6BAA6B,QAAQ,QAMhD,CAAC,CAAC,wDAAwD,CAAC,CAAC;CAC5D,OAAO,MAA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