@effect-agent/platform-cloudflare 0.1.0-beta.50 → 0.1.0-beta.52

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.
@@ -30,6 +30,7 @@ interface ThreadObjectRpc extends Rpc.DurableObjectBranded {
30
30
  /** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */
31
31
  submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
32
32
  /** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */
33
+ submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
33
34
  awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
34
35
  /** Event-driven durable progress wait; answers a `ProgressObserved` host response. */
35
36
  awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareBindings.mjs","names":[],"sources":["../src/CloudflareBindings.ts"],"sourcesContent":["import { type ThreadId } from \"@effect-agent/core/Identifiers\";\nimport { type ProducerId } from \"@effect-agent/thread/Records\";\nimport { Context, Effect, Layer, Predicate, 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 Thread 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 Thread Durable Object exposes to Workers and to sibling\n * Thread Objects. `ThreadObject.make` 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. The optional trailing trace context is\n * transient native RPC metadata, stripped by an opted-in effect-cf receiver before decoding\n * the host envelope. It never enters durable state.\n */\nexport interface ThreadObjectRpc extends Rpc.DurableObjectBranded {\n /** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */\n submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */\n awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Event-driven durable progress wait; answers a `ProgressObserved` host response. */\n awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Best-effort cancellation for one in-flight progress wait. */\n cancelProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** One bounded page of canonical records; answers an `ObservePageResponse`. */\n observePage(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Durable abort intent; answers an `AbortResponse`. */\n abortEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Durable approval decision (plan §2.6); answers a `ResolveApprovalResponse`. */\n resolveApprovalEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Authorized DUR-017 Unknown-Outcome resolution; answers a `ResolveUnknownResponse`. */\n resolveUnknownEncoded(encoded: unknown, traceContext?: 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 Thread Objects. The Object\n * identity rule is `namespace.idFromName(threadId)` (plan §1.2): Thread IDs are\n * globally unique, so the mapping is total and deterministic and no directory service exists.\n */\nexport class ThreadObjectNamespace extends Context.Service<\n ThreadObjectNamespace,\n {\n readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;\n /** Stable binding name for opted-in native RPC tracing; absent by default. */\n readonly rpcTracing?: string;\n }\n>()(\"@effect-agent/platform-cloudflare/ThreadObjectNamespace\") {\n static layer(\n namespace: DurableObjectNamespace<ThreadObjectRpc>,\n options: { readonly rpcTracing?: string } = {},\n ): Layer.Layer<ThreadObjectNamespace> {\n return Layer.succeed(ThreadObjectNamespace)({\n namespace,\n ...(options.rpcTracing === undefined ? {} : { rpcTracing: options.rpcTracing }),\n });\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 threadNamespaceFromEnv = Effect.fn(\"threadNamespaceFromEnv\")(function* (\n env: unknown,\n binding: string,\n): Effect.fn.Return<DurableObjectNamespace<ThreadObjectRpc>, CloudflareBindingError> {\n if (!Predicate.isObjectKeyword(env)) {\n return yield* CloudflareBindingError.make({\n binding,\n message: \"The Worker environment is not an object; no bindings are available.\",\n });\n }\n\n const candidate = yield* Effect.try({\n try: () => {\n const value: unknown = Reflect.get(env, binding);\n\n if (!Predicate.isObjectKeyword(value)) return undefined;\n const idFromName: unknown = Reflect.get(value, \"idFromName\");\n const get: unknown = Reflect.get(value, \"get\");\n\n return typeof idFromName === \"function\" && typeof get === \"function\" ? value : undefined;\n },\n catch: () =>\n CloudflareBindingError.make({\n binding,\n message: `env.${binding} could not be inspected as a DurableObjectNamespace binding.`,\n }),\n });\n\n if (candidate !== undefined) {\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 candidate as unknown as DurableObjectNamespace<ThreadObjectRpc>;\n }\n\n return yield* CloudflareBindingError.make({\n binding,\n message:\n `env.${binding} is not a DurableObjectNamespace binding; declare the Thread ` +\n \"Object class under this binding in the Worker configuration.\",\n });\n});\n\n/**\n * Build the namespace from Worker `env` (fails typed). Enable `rpcTracing` only when the\n * receiver also opts into the effect-cf native RPC trace-context contract.\n */\nexport const threadNamespaceLayer = (\n env: unknown,\n binding: string,\n options: { readonly rpcTracing?: boolean } = {},\n): Layer.Layer<ThreadObjectNamespace, CloudflareBindingError> =>\n Layer.effect(ThreadObjectNamespace)(\n Effect.map(threadNamespaceFromEnv(env, binding), (namespace) => ({\n namespace,\n ...(options.rpcTracing === true ? { rpcTracing: binding } : {}),\n })),\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 Thread identity this Object serializes and the producer identity its Attempts\n * write with (`{producerPrefix}:{threadId}`, plan §1.4). Derived once per incarnation\n * from `ctx.id.name` — the Object identity rule guarantees the name IS the Thread ID.\n */\nexport class ThreadObjectIdentity extends Context.Service<\n ThreadObjectIdentity,\n {\n readonly threadId: ThreadId;\n readonly producerId: ProducerId;\n }\n>()(\"@effect-agent/platform-cloudflare/ThreadObjectIdentity\") {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYA,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CACtF,0BACA;CACE,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;;AAwCH,IAAa,wBAAb,MAAa,8BAA8B,QAAQ,QAOjD,CAAC,CAAC,yDAAyD,CAAC,CAAC;CAC7D,OAAO,MACL,WACA,UAA4C,CAAC,GACT;EACpC,OAAO,MAAM,QAAQ,qBAAqB,CAAC,CAAC;GAC1C;GACA,GAAI,QAAQ,eA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,CAAC,wDAAwD,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"CloudflareBindings.mjs","names":[],"sources":["../src/CloudflareBindings.ts"],"sourcesContent":["import { type ThreadId } from \"@effect-agent/core/Identifiers\";\nimport { type ProducerId } from \"@effect-agent/thread/Records\";\nimport { Context, Effect, Layer, Predicate, 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 Thread 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 Thread Durable Object exposes to Workers and to sibling\n * Thread Objects. `ThreadObject.make` 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. The optional trailing trace context is\n * transient native RPC metadata, stripped by an opted-in effect-cf receiver before decoding\n * the host envelope. It never enters durable state.\n */\nexport interface ThreadObjectRpc extends Rpc.DurableObjectBranded {\n /** Admission-limits gate + `DurableAgentRuntime.submit`; answers a `SubmitResponse`. */\n submitEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Wake-hinted, poll-guaranteed settlement wait; answers an `AwaitSettlementResponse`. */\n submissionStatusEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n awaitSettlementEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Event-driven durable progress wait; answers a `ProgressObserved` host response. */\n awaitProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Best-effort cancellation for one in-flight progress wait. */\n cancelProgressEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** One bounded page of canonical records; answers an `ObservePageResponse`. */\n observePage(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Durable abort intent; answers an `AbortResponse`. */\n abortEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Durable approval decision (plan §2.6); answers a `ResolveApprovalResponse`. */\n resolveApprovalEncoded(encoded: unknown, traceContext?: unknown): Promise<unknown>;\n /** Authorized DUR-017 Unknown-Outcome resolution; answers a `ResolveUnknownResponse`. */\n resolveUnknownEncoded(encoded: unknown, traceContext?: 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 Thread Objects. The Object\n * identity rule is `namespace.idFromName(threadId)` (plan §1.2): Thread IDs are\n * globally unique, so the mapping is total and deterministic and no directory service exists.\n */\nexport class ThreadObjectNamespace extends Context.Service<\n ThreadObjectNamespace,\n {\n readonly namespace: DurableObjectNamespace<ThreadObjectRpc>;\n /** Stable binding name for opted-in native RPC tracing; absent by default. */\n readonly rpcTracing?: string;\n }\n>()(\"@effect-agent/platform-cloudflare/ThreadObjectNamespace\") {\n static layer(\n namespace: DurableObjectNamespace<ThreadObjectRpc>,\n options: { readonly rpcTracing?: string } = {},\n ): Layer.Layer<ThreadObjectNamespace> {\n return Layer.succeed(ThreadObjectNamespace)({\n namespace,\n ...(options.rpcTracing === undefined ? {} : { rpcTracing: options.rpcTracing }),\n });\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 threadNamespaceFromEnv = Effect.fn(\"threadNamespaceFromEnv\")(function* (\n env: unknown,\n binding: string,\n): Effect.fn.Return<DurableObjectNamespace<ThreadObjectRpc>, CloudflareBindingError> {\n if (!Predicate.isObjectKeyword(env)) {\n return yield* CloudflareBindingError.make({\n binding,\n message: \"The Worker environment is not an object; no bindings are available.\",\n });\n }\n\n const candidate = yield* Effect.try({\n try: () => {\n const value: unknown = Reflect.get(env, binding);\n\n if (!Predicate.isObjectKeyword(value)) return undefined;\n const idFromName: unknown = Reflect.get(value, \"idFromName\");\n const get: unknown = Reflect.get(value, \"get\");\n\n return typeof idFromName === \"function\" && typeof get === \"function\" ? value : undefined;\n },\n catch: () =>\n CloudflareBindingError.make({\n binding,\n message: `env.${binding} could not be inspected as a DurableObjectNamespace binding.`,\n }),\n });\n\n if (candidate !== undefined) {\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 candidate as unknown as DurableObjectNamespace<ThreadObjectRpc>;\n }\n\n return yield* CloudflareBindingError.make({\n binding,\n message:\n `env.${binding} is not a DurableObjectNamespace binding; declare the Thread ` +\n \"Object class under this binding in the Worker configuration.\",\n });\n});\n\n/**\n * Build the namespace from Worker `env` (fails typed). Enable `rpcTracing` only when the\n * receiver also opts into the effect-cf native RPC trace-context contract.\n */\nexport const threadNamespaceLayer = (\n env: unknown,\n binding: string,\n options: { readonly rpcTracing?: boolean } = {},\n): Layer.Layer<ThreadObjectNamespace, CloudflareBindingError> =>\n Layer.effect(ThreadObjectNamespace)(\n Effect.map(threadNamespaceFromEnv(env, binding), (namespace) => ({\n namespace,\n ...(options.rpcTracing === true ? { rpcTracing: binding } : {}),\n })),\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 Thread identity this Object serializes and the producer identity its Attempts\n * write with (`{producerPrefix}:{threadId}`, plan §1.4). Derived once per incarnation\n * from `ctx.id.name` — the Object identity rule guarantees the name IS the Thread ID.\n */\nexport class ThreadObjectIdentity extends Context.Service<\n ThreadObjectIdentity,\n {\n readonly threadId: ThreadId;\n readonly producerId: ProducerId;\n }\n>()(\"@effect-agent/platform-cloudflare/ThreadObjectIdentity\") {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAYA,IAAa,yBAAb,cAA4C,OAAO,YAAoC,CAAC,CACtF,0BACA;CACE,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;;AAyCH,IAAa,wBAAb,MAAa,8BAA8B,QAAQ,QAOjD,CAAC,CAAC,yDAAyD,CAAC,CAAC;CAC7D,OAAO,MACL,WACA,UAA4C,CAAC,GACT;EACpC,OAAO,MAAM,QAAQ,qBAAqB,CAAC,CAAC;GAC1C;GACA,GAAI,QAAQ,eAAe,KAAA,IAAY,CAAC,IAAI,EAAE,YAAY,QAAQ,WAAW;EAC/E,CAAC;CACH;AACF;;;;;;;AAQA,MAAa,yBAAyB,OAAO,GAAG,wBAAwB,CAAC,CAAC,WACxE,KACA,SACmF;CACnF,IAAI,CAAC,UAAU,gBAAgB,GAAG,GAChC,OAAO,OAAO,uBAAuB,KAAK;EACxC;EACA,SAAS;CACX,CAAC;CAGH,MAAM,YAAY,OAAO,OAAO,IAAI;EAClC,WAAW;GACT,MAAM,QAAiB,QAAQ,IAAI,KAAK,OAAO;GAE/C,IAAI,CAAC,UAAU,gBAAgB,KAAK,GAAG,OAAO,KAAA;GAC9C,MAAM,aAAsB,QAAQ,IAAI,OAAO,YAAY;GAC3D,MAAM,MAAe,QAAQ,IAAI,OAAO,KAAK;GAE7C,OAAO,OAAO,eAAe,cAAc,OAAO,QAAQ,aAAa,QAAQ,KAAA;EACjF;EACA,aACE,uBAAuB,KAAK;GAC1B;GACA,SAAS,OAAO,QAAQ;EAC1B,CAAC;CACL,CAAC;CAED,IAAI,cAAc,KAAA,GAGhB,OAAO;CAGT,OAAO,OAAO,uBAAuB,KAAK;EACxC;EACA,SACE,OAAO,QAAQ;CAEnB,CAAC;AACH,CAAC;;;;;AAMD,MAAa,wBACX,KACA,SACA,UAA6C,CAAC,MAE9C,MAAM,OAAO,qBAAqB,CAAC,CACjC,OAAO,IAAI,uBAAuB,KAAK,OAAO,IAAI,eAAe;CAC/D;CACA,GAAI,QAAQ,eAAe,OAAO,EAAE,YAAY,QAAQ,IAAI,CAAC;AAC/D,EAAE,CACJ;;;;;;AAOF,IAAa,uBAAb,MAAa,6BAA6B,QAAQ,QAMhD,CAAC,CAAC,wDAAwD,CAAC,CAAC;CAC5D,OAAO,MAAM,KAAyB,KAAiD;EACrF,OAAO,MAAM,QAAQ,oBAAoB,CAAC,CAAC;GAAE;GAAK;EAAI,CAAC;CACzD;AACF;;;;;;AAOA,IAAa,uBAAb,cAA0C,QAAQ,QAMhD,CAAC,CAAC,wDAAwD,CAAC,CAAC,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { CloudflareThreadClient } from "./CloudflareThreadClient.mjs";
3
- import { n as cloudflareScheduledInputAdmissionLayer, t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-DRBhl2Sp.mjs";
3
+ import { n as cloudflareScheduledInputAdmissionLayer, t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-9rvlHI0y.mjs";
4
4
  import "@effect-agent/thread/DurableAgentRuntime";
5
+ import { AdmissionFence } from "@effect-agent/thread/SubmissionLedger";
5
6
  import { Clock, Context, DateTime, Effect, Layer, Schema } from "effect";
6
7
  import { AgentId } from "@effect-agent/core/Identifiers";
7
8
  import { DefinitionDigests, PersistedJson } from "@effect-agent/thread/Records";
@@ -40,7 +41,9 @@ const ScheduleMutationRequestFields = {
40
41
  timing: ScheduleTimingRequest,
41
42
  destination: ScheduleDestination,
42
43
  deliveryPrincipal: ScheduleScope.fields.principal,
43
- definitions: DefinitionDigests
44
+ definitions: DefinitionDigests,
45
+ admissionGroup: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),
46
+ admissionFence: Schema.optionalKey(AdmissionFence)
44
47
  };
45
48
  const ScheduleCreateRequest = Schema.TaggedStruct("Create", ScheduleMutationRequestFields);
46
49
  const ScheduleUpdateRequest = Schema.TaggedStruct("Update", {
@@ -69,7 +72,15 @@ const ScheduleControlRequest = Schema.TaggedStruct("Control", {
69
72
  scheduleId: ScheduleId,
70
73
  expectedRevision: Schema.Int.check(Schema.isGreaterThan(0))
71
74
  });
75
+ const ScheduleRecoverRequest = Schema.TaggedStruct("Recover", {
76
+ schemaVersion: Schema.Literal(1),
77
+ scope: ScheduleScope,
78
+ scheduleId: ScheduleId,
79
+ expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),
80
+ expectedGeneration: Schema.Natural
81
+ });
72
82
  const ScheduleOwnerRequest = Schema.Union([
83
+ ScheduleRecoverRequest,
73
84
  ScheduleCreateRequest,
74
85
  ScheduleUpdateRequest,
75
86
  ScheduleGetRequest,
@@ -209,6 +220,20 @@ var CloudflareSchedulingClient = class {
209
220
  list,
210
221
  pause: (scope, id, revision) => control("pause", scope, id, revision),
211
222
  resume: (scope, id, revision) => control("resume", scope, id, revision),
223
+ recover: (scope, scheduleId, expectedRevision, expectedGeneration) => Effect.gen(function* () {
224
+ const response = yield* call(scope.owner, {
225
+ _tag: "Recover",
226
+ schemaVersion: 1,
227
+ scope,
228
+ scheduleId,
229
+ expectedRevision,
230
+ expectedGeneration
231
+ });
232
+ return response._tag === "Snapshot" ? response.value : yield* ScheduleStorageError.make({
233
+ operation: "Schedule Owner protocol",
234
+ reason: "corrupt"
235
+ });
236
+ }),
212
237
  cancel: (scope, id, revision) => control("cancel", scope, id, revision)
213
238
  });
214
239
  }));
@@ -271,7 +296,9 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
271
296
  timing: request.timing,
272
297
  destination: request.destination,
273
298
  deliveryPrincipal: request.deliveryPrincipal,
274
- definitions: request.definitions
299
+ definitions: request.definitions,
300
+ ...request.admissionGroup === void 0 ? {} : { admissionGroup: request.admissionGroup },
301
+ ...request.admissionFence === void 0 ? {} : { admissionFence: request.admissionFence }
275
302
  })
276
303
  };
277
304
  case "Update": return {
@@ -283,6 +310,8 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
283
310
  destination: request.destination,
284
311
  deliveryPrincipal: request.deliveryPrincipal,
285
312
  definitions: request.definitions,
313
+ ...request.admissionGroup === void 0 ? {} : { admissionGroup: request.admissionGroup },
314
+ ...request.admissionFence === void 0 ? {} : { admissionFence: request.admissionFence },
286
315
  expectedRevision: request.expectedRevision
287
316
  })
288
317
  };
@@ -297,6 +326,10 @@ const handleScheduleRequest = Effect.fn("ScheduleOwner.handleRequest")(function*
297
326
  ...request.limit === void 0 ? {} : { limit: request.limit }
298
327
  })
299
328
  };
329
+ case "Recover": return {
330
+ _tag: "Snapshot",
331
+ value: yield* scheduling.recover(request.scope, request.scheduleId, request.expectedRevision, request.expectedGeneration)
332
+ };
300
333
  case "Control": return {
301
334
  _tag: "Snapshot",
302
335
  value: request.operation === "pause" ? yield* scheduling.pause(request.scope, request.scheduleId, request.expectedRevision) : request.operation === "resume" ? yield* scheduling.resume(request.scope, request.scheduleId, request.expectedRevision) : yield* scheduling.cancel(request.scope, request.scheduleId, request.expectedRevision)
@@ -1 +1 @@
1
- {"version":3,"file":"CloudflareScheduling.mjs","names":["ScheduleScopeSchema","ScheduleSnapshotPageSchema","EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareScheduling.ts"],"sourcesContent":["import { AgentId } from \"@effect-agent/core/Identifiers\";\nimport {\n DoScheduleAlarmControl,\n DoScheduleTransaction,\n scheduleStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoScheduleStore\";\nimport { type DurableSubmitAgent } from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { DefinitionDigests, PersistedJson } from \"@effect-agent/thread/Records\";\nimport {\n ScheduleAuthorizationError,\n type ScheduleAuthorizer,\n ScheduleCapacityError,\n ScheduleConflict,\n ScheduleDestination,\n ScheduleFailpointError,\n ScheduleId,\n type SchedulingLimits,\n ScheduleNotFound,\n ScheduleOwner,\n type ScheduleScope,\n ScheduleScope as ScheduleScopeSchema,\n ScheduleSnapshot,\n ScheduleSnapshotPage as ScheduleSnapshotPageSchema,\n ScheduleStorageError,\n ScheduleTimingRequest,\n ScheduleValidationError,\n defaultSchedulingLimits,\n} from \"@effect-agent/thread/Schedule\";\nimport { scheduleOwnerKey } from \"@effect-agent/thread/ScheduleTransition\";\nimport {\n Scheduling,\n ScheduleDriver,\n type ScheduleManagementFailure,\n ScheduleWakeNoop,\n} from \"@effect-agent/thread/Scheduling\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Clock, Context, DateTime, Effect, Layer, Schema } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport type { ThreadObjectNamespace } from \"./CloudflareBindings.ts\";\nimport { CloudflareThreadClient } from \"./CloudflareThreadClient.ts\";\nimport {\n cloudflarePreparedInputAdmissionLayer,\n cloudflareScheduledInputAdmissionLayer,\n} from \"./internal/prepared-admission.ts\";\n\nconst SCHEDULE_ALARM_TAG = \"effect-agent/ScheduleOwnerWake\";\nconst SCHEDULE_ALARM_ID = \"driver\";\n\nconst ScheduleAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class ScheduleAlarmProtocolError extends Schema.TaggedError<ScheduleAlarmProtocolError>()(\n \"ScheduleAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\nconst boundedProtocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nexport class ScheduleOwnerProtocolError extends Schema.TaggedError<ScheduleOwnerProtocolError>()(\n \"ScheduleOwnerProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nconst ScheduleMutationRequestFields = {\n schemaVersion: Schema.Literal(1),\n agentId: AgentId,\n input: PersistedJson,\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n timing: ScheduleTimingRequest,\n destination: ScheduleDestination,\n deliveryPrincipal: ScheduleScopeSchema.fields.principal,\n definitions: DefinitionDigests,\n};\n\nconst ScheduleCreateRequest = Schema.TaggedStruct(\"Create\", ScheduleMutationRequestFields);\n\nconst ScheduleUpdateRequest = Schema.TaggedStruct(\"Update\", {\n ...ScheduleMutationRequestFields,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleGetRequest = Schema.TaggedStruct(\"Get\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n});\n\nconst ScheduleListRequest = Schema.TaggedStruct(\"List\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n after: Schema.optionalKey(ScheduleId),\n limit: Schema.optionalKey(\n Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)),\n ),\n});\n\nconst ScheduleControlRequest = Schema.TaggedStruct(\"Control\", {\n schemaVersion: Schema.Literal(1),\n operation: Schema.Literals([\"pause\", \"resume\", \"cancel\"]),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleOwnerRequest = Schema.Union([\n ScheduleCreateRequest,\n ScheduleUpdateRequest,\n ScheduleGetRequest,\n ScheduleListRequest,\n ScheduleControlRequest,\n]);\n\ntype ScheduleOwnerRequest = typeof ScheduleOwnerRequest.Type;\n\nconst ScheduleOwnerFailure = Schema.Union([\n ScheduleValidationError,\n ScheduleAuthorizationError,\n ScheduleConflict,\n ScheduleNotFound,\n ScheduleCapacityError,\n ScheduleStorageError,\n ScheduleFailpointError,\n ScheduleOwnerProtocolError,\n]);\n\ntype ScheduleOwnerFailure = typeof ScheduleOwnerFailure.Type;\n\nconst ScheduleOwnerResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: ScheduleSnapshot }),\n Schema.TaggedStruct(\"Page\", { value: ScheduleSnapshotPageSchema }),\n Schema.TaggedStruct(\"Failed\", { failure: ScheduleOwnerFailure }),\n]);\n\ntype ScheduleOwnerResponse = typeof ScheduleOwnerResponse.Type;\n\nconst decodeScheduleOwnerRequest = Schema.decodeUnknownEffect(ScheduleOwnerRequest);\nconst encodeScheduleOwnerRequest = Schema.encodeEffect(ScheduleOwnerRequest);\nconst decodeScheduleOwnerResponse = Schema.decodeUnknownEffect(ScheduleOwnerResponse);\nconst encodeScheduleOwnerResponse = Schema.encodeEffect(ScheduleOwnerResponse);\n\nconst scheduleProtocolFailure = (message: string): ScheduleOwnerResponse => ({\n _tag: \"Failed\",\n failure: ScheduleOwnerProtocolError.make({ message: boundedProtocolMessage(message) }),\n});\n\nexport interface ScheduleOwnerObjectRpc extends Rpc.DurableObjectBranded {\n schedule(encoded: unknown): Promise<unknown>;\n}\n\nexport class ScheduleOwnerNamespace extends Context.Service<\n ScheduleOwnerNamespace,\n { readonly namespace: DurableObjectNamespace<ScheduleOwnerObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerNamespace\") {}\n\nconst passthroughAgent = (agentId: AgentId): DurableSubmitAgent<typeof PersistedJson> => ({\n definition: { id: agentId, input: PersistedJson },\n});\n\nconst requestOwner = (request: ScheduleOwnerRequest): ScheduleOwner => request.scope.owner;\n\n/** Provides the same authorized management service as NodeScheduling.layer. */\nexport class CloudflareSchedulingClient {\n static readonly layer: Layer.Layer<Scheduling, never, ScheduleOwnerNamespace> = Layer.effect(\n Scheduling,\n Effect.gen(function* () {\n const { namespace } = yield* ScheduleOwnerNamespace;\n\n const call = Effect.fn(\"CloudflareSchedulingClient.call\")(function* (\n owner: ScheduleOwner,\n request: ScheduleOwnerRequest,\n ): Effect.fn.Return<ScheduleOwnerResponse, ScheduleManagementFailure> {\n const encoded = yield* encodeScheduleOwnerRequest(request).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(scheduleOwnerKey(owner))).schedule(encoded),\n catch: () =>\n ScheduleStorageError.make({\n operation: \"call Schedule Owner\",\n reason: \"unavailable\",\n }),\n });\n\n const response = yield* decodeScheduleOwnerResponse(raw).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n\n if (response._tag !== \"Failed\") return response;\n\n return yield* response.failure._tag === \"ScheduleOwnerProtocolError\"\n ? ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" })\n : response.failure;\n });\n\n const encodeInput = Effect.fn(\"CloudflareSchedulingClient.encodeInput\")(function* <\n InputSchema extends Schema.Top,\n >(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n ): Effect.fn.Return<PersistedJson, ScheduleValidationError, InputSchema[\"EncodingServices\"]> {\n const encoded = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Unable to encode Agent input\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(PersistedJson)(encoded).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n });\n\n const create: Scheduling[\"Service\"][\"create\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n\n const response = yield* call(options.scope.owner, {\n _tag: \"Create\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const update: Scheduling[\"Service\"][\"update\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n\n const response = yield* call(options.scope.owner, {\n _tag: \"Update\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const get: Scheduling[\"Service\"][\"get\"] = (scope, scheduleId) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Get\",\n schemaVersion: 1,\n scope,\n scheduleId,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const list: Scheduling[\"Service\"][\"list\"] = (scope, options = {}) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"List\",\n schemaVersion: 1,\n scope,\n ...(options.after === undefined ? {} : { after: options.after }),\n ...(options.limit === undefined ? {} : { limit: options.limit }),\n });\n\n return response._tag === \"Page\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const control = (\n operation: \"pause\" | \"resume\" | \"cancel\",\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Control\",\n schemaVersion: 1,\n operation,\n scope,\n scheduleId,\n expectedRevision,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n return Scheduling.of({\n create,\n update,\n get,\n list,\n pause: (scope, id, revision) => control(\"pause\", scope, id, revision),\n resume: (scope, id, revision) => control(\"resume\", scope, id, revision),\n cancel: (scope, id, revision) => control(\"cancel\", scope, id, revision),\n });\n }),\n );\n}\n\nexport class ScheduleOwnerIdentity extends Context.Service<\n ScheduleOwnerIdentity,\n { readonly owner: ScheduleOwner }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerIdentity\") {}\n\nconst decodeOwnerName = Effect.fn(\"decodeScheduleOwnerName\")(function* (\n name: string | null | undefined,\n): Effect.fn.Return<ScheduleOwner, ScheduleOwnerProtocolError> {\n if (name === null || name === undefined) {\n return yield* ScheduleOwnerProtocolError.make({\n message: \"Schedule Owner objects require an idFromName identity\",\n });\n }\n\n const tuple = yield* Schema.decodeUnknownEffect(\n Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])),\n )(name).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object name is malformed\" }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(ScheduleOwner)({\n tenantId: tuple[0],\n ownerId: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object identity is invalid\" }),\n ),\n );\n});\n\nconst alarmStorageError = (operation: string) => (error: { readonly _tag: string }) =>\n ScheduleStorageError.make({\n operation,\n reason: error._tag === \"StorageOperationError\" ? \"unavailable\" : \"corrupt\",\n });\n\nconst transactionLayer: Layer.Layer<\n DoScheduleTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoScheduleTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoScheduleTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\n\n return yield* alarms\n .transaction((transaction) =>\n body((replacement) =>\n replacement.deadlineAtMillis === null\n ? transaction\n .cancelAlarm({ id: SCHEDULE_ALARM_ID, tag: SCHEDULE_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel Schedule Owner alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({\n operation: \"validate Schedule Owner alarm deadline\",\n reason: \"corrupt\",\n }),\n ),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SCHEDULE_ALARM_ID,\n tag: SCHEDULE_ALARM_TAG,\n runAt,\n payload: {\n schemaVersion: 1,\n generation: replacement.generation,\n },\n })\n .pipe(\n Effect.mapError(alarmStorageError(\"schedule Schedule Owner alarm\")),\n ),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n ScheduleStorageError.make({\n operation: \"commit Schedule Owner transaction\",\n reason: \"unavailable\",\n }),\n ),\n );\n }),\n });\n }),\n);\n\ntype ScheduleRuntimeServices =\n | Scheduling\n | ScheduleDriver\n | DoScheduleAlarmControl\n | ScheduleOwnerIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nconst ensureOwner = (\n expected: ScheduleOwner,\n request: ScheduleOwnerRequest,\n): Effect.Effect<void, ScheduleOwnerProtocolError> => {\n const observed = requestOwner(request);\n\n return observed.tenantId === expected.tenantId && observed.ownerId === expected.ownerId\n ? Effect.void\n : Effect.fail(\n ScheduleOwnerProtocolError.make({\n message: \"The request owner does not match the addressed Schedule Owner object\",\n }),\n );\n};\n\nconst handleScheduleRequest = Effect.fn(\"ScheduleOwner.handleRequest\")(function* (\n encoded: unknown,\n): Effect.fn.Return<unknown, never, Scheduling | ScheduleOwnerIdentity> {\n const decoded = yield* decodeScheduleOwnerRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeScheduleOwnerResponse(\n scheduleProtocolFailure(\"The Schedule request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { owner } = yield* ScheduleOwnerIdentity;\n const scheduling = yield* Scheduling;\n\n const response = yield* Effect.gen(function* () {\n yield* ensureOwner(owner, request);\n switch (request._tag) {\n case \"Create\": {\n const value = yield* scheduling.create(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n });\n\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Update\": {\n const value = yield* scheduling.update(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n expectedRevision: request.expectedRevision,\n });\n\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Get\":\n return {\n _tag: \"Snapshot\" as const,\n value: yield* scheduling.get(request.scope, request.scheduleId),\n };\n case \"List\":\n return {\n _tag: \"Page\" as const,\n value: yield* scheduling.list(request.scope, {\n ...(request.after === undefined ? {} : { after: request.after }),\n ...(request.limit === undefined ? {} : { limit: request.limit }),\n }),\n };\n case \"Control\": {\n const value =\n request.operation === \"pause\"\n ? yield* scheduling.pause(request.scope, request.scheduleId, request.expectedRevision)\n : request.operation === \"resume\"\n ? yield* scheduling.resume(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n )\n : yield* scheduling.cancel(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n );\n\n return { _tag: \"Snapshot\" as const, value };\n }\n }\n }).pipe(\n Effect.map((value): ScheduleOwnerResponse => value),\n Effect.catch((failure) =>\n Schema.is(ScheduleOwnerFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(\n scheduleProtocolFailure(\"The Schedule operation failed outside its public contract\"),\n ),\n ),\n );\n\n return yield* encodeScheduleOwnerResponse(response).pipe(Effect.orDie);\n});\n\n/** @internal The complete native alarm operation, including its event deadline. */\nexport const scheduleAlarmHandler = (limits: SchedulingLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SCHEDULE_ALARM_TAG || event.id !== SCHEDULE_ALARM_ID) {\n return yield* ScheduleAlarmProtocolError.make({\n message: `Unsupported Schedule Owner alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(ScheduleAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n ScheduleAlarmProtocolError.make({\n message: \"Unsupported Schedule Owner alarm payload version\",\n }),\n ),\n );\n const scheduling = yield* ScheduleDriver;\n const alarmControl = yield* DoScheduleAlarmControl;\n const { owner } = yield* ScheduleOwnerIdentity;\n const nowMillis = yield* Clock.currentTimeMillis;\n\n yield* alarmControl.prearm(nowMillis + limits.recoveryPollMillis);\n const pass = yield* scheduling.runDue(owner);\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.recoveryPollMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n { mode: \"ordered\" },\n ).pipe(\n // Bound due acquisition and acknowledgement as well as admission. Prepared occurrences\n // and their replacement alarm survive interruption and retain their idempotency keys.\n Effect.timeout(\"14 minutes\"),\n Effect.asVoid,\n );\n\nexport interface ScheduleOwnerObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, ScheduleRuntimeServices>\n> {\n schedule(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface ScheduleOwnerObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): ScheduleOwnerObjectInstance;\n}\n\n/**\n * The host Layer supplies authorization and routing and is cached for the object incarnation.\n * Cloudflare eviction does not guarantee its finalizers run. Do not acquire resources requiring\n * cleanup in this Layer; acquire them inside scoped `manage` / `prepare` operations instead.\n * Native services belong to effect-cf; the database and alarm runtime remain instance-owned.\n */\nexport const makeScheduleOwnerObjectClass = <E>(\n host: Layer.Layer<\n ScheduleAuthorizer | ThreadObjectNamespace,\n E,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment | ScheduleOwnerIdentity\n >,\n limits: SchedulingLimits = defaultSchedulingLimits,\n): ScheduleOwnerObjectClass => {\n const ownerLayer = Layer.effect(\n ScheduleOwnerIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return ScheduleOwnerIdentity.of({ owner: yield* decodeOwnerName(state.raw.id.name) });\n }),\n );\n\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n\n const application = Layer.merge(Scheduling.layer(limits), ScheduleDriver.layer(limits)).pipe(\n Layer.provideMerge(\n scheduleStoreLayer.pipe(Layer.provide(transactionLayer), Layer.provide(sqlLayer)),\n ),\n Layer.provide(\n cloudflareScheduledInputAdmissionLayer.pipe(\n Layer.provide(cloudflarePreparedInputAdmissionLayer),\n Layer.provide(CloudflareThreadClient.layer),\n ),\n ),\n Layer.provide(ScheduleWakeNoop),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(ownerLayer),\n );\n\n const runtime: Layer.Layer<\n ScheduleRuntimeServices,\n E | ScheduleStorageError | ScheduleOwnerProtocolError | ScheduleValidationError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = {\n schedule: (encoded: unknown) => handleScheduleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<ScheduleRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: scheduleAlarmHandler(limits),\n });\n\n class ScheduleOwnerObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return ScheduleOwnerObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAE1B,MAAM,uBAAuB,OAAO,OAAO;CACzC,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,0BAA0B,YAC9B,QAAQ,UAAU,OAAQ,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAK,EAAE;AAEjE,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY,IAAK,CAAC,EAAE,CAC5D,CAAC,CAAC,CAAC;AAEH,MAAM,gCAAgC;CACpC,eAAe,OAAO,QAAQ,CAAC;CAC/B,SAAS;CACT,OAAO;CACP,OAAOA;CACP,YAAY;CACZ,QAAQ;CACR,aAAa;CACb,mBAAmBA,cAAoB,OAAO;CAC9C,aAAa;AACf;AAEA,MAAM,wBAAwB,OAAO,aAAa,UAAU,6BAA6B;AAEzF,MAAM,wBAAwB,OAAO,aAAa,UAAU;CAC1D,GAAG;CACH,kBAAkB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,qBAAqB,OAAO,aAAa,OAAO;CACpD,eAAe,OAAO,QAAQ,C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;EACrC,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"CloudflareScheduling.mjs","names":["ScheduleScopeSchema","ScheduleSnapshotPageSchema","EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareScheduling.ts"],"sourcesContent":["import { AgentId } from \"@effect-agent/core/Identifiers\";\nimport {\n DoScheduleAlarmControl,\n DoScheduleTransaction,\n scheduleStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoScheduleStore\";\nimport { type DurableSubmitAgent } from \"@effect-agent/thread/DurableAgentRuntime\";\nimport { DefinitionDigests, PersistedJson } from \"@effect-agent/thread/Records\";\nimport {\n ScheduleAuthorizationError,\n type ScheduleAuthorizer,\n ScheduleCapacityError,\n ScheduleConflict,\n ScheduleDestination,\n ScheduleFailpointError,\n ScheduleId,\n type SchedulingLimits,\n ScheduleNotFound,\n ScheduleOwner,\n type ScheduleScope,\n ScheduleScope as ScheduleScopeSchema,\n ScheduleSnapshot,\n ScheduleSnapshotPage as ScheduleSnapshotPageSchema,\n ScheduleStorageError,\n ScheduleTimingRequest,\n ScheduleValidationError,\n defaultSchedulingLimits,\n} from \"@effect-agent/thread/Schedule\";\nimport { scheduleOwnerKey } from \"@effect-agent/thread/ScheduleTransition\";\nimport {\n Scheduling,\n ScheduleDriver,\n type ScheduleManagementFailure,\n ScheduleWakeNoop,\n} from \"@effect-agent/thread/Scheduling\";\nimport { AdmissionFence } from \"@effect-agent/thread/SubmissionLedger\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Clock, Context, DateTime, Effect, Layer, Schema } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport type { ThreadObjectNamespace } from \"./CloudflareBindings.ts\";\nimport { CloudflareThreadClient } from \"./CloudflareThreadClient.ts\";\nimport {\n cloudflarePreparedInputAdmissionLayer,\n cloudflareScheduledInputAdmissionLayer,\n} from \"./internal/prepared-admission.ts\";\n\nconst SCHEDULE_ALARM_TAG = \"effect-agent/ScheduleOwnerWake\";\nconst SCHEDULE_ALARM_ID = \"driver\";\n\nconst ScheduleAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class ScheduleAlarmProtocolError extends Schema.TaggedError<ScheduleAlarmProtocolError>()(\n \"ScheduleAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\nconst boundedProtocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nexport class ScheduleOwnerProtocolError extends Schema.TaggedError<ScheduleOwnerProtocolError>()(\n \"ScheduleOwnerProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nconst ScheduleMutationRequestFields = {\n schemaVersion: Schema.Literal(1),\n agentId: AgentId,\n input: PersistedJson,\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n timing: ScheduleTimingRequest,\n destination: ScheduleDestination,\n deliveryPrincipal: ScheduleScopeSchema.fields.principal,\n definitions: DefinitionDigests,\n admissionGroup: Schema.optionalKey(Schema.NonEmptyString.check(Schema.isMaxLength(256))),\n admissionFence: Schema.optionalKey(AdmissionFence),\n};\n\nconst ScheduleCreateRequest = Schema.TaggedStruct(\"Create\", ScheduleMutationRequestFields);\n\nconst ScheduleUpdateRequest = Schema.TaggedStruct(\"Update\", {\n ...ScheduleMutationRequestFields,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleGetRequest = Schema.TaggedStruct(\"Get\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n});\n\nconst ScheduleListRequest = Schema.TaggedStruct(\"List\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n after: Schema.optionalKey(ScheduleId),\n limit: Schema.optionalKey(\n Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)),\n ),\n});\n\nconst ScheduleControlRequest = Schema.TaggedStruct(\"Control\", {\n schemaVersion: Schema.Literal(1),\n operation: Schema.Literals([\"pause\", \"resume\", \"cancel\"]),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleRecoverRequest = Schema.TaggedStruct(\"Recover\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n expectedGeneration: Schema.Natural,\n});\n\nconst ScheduleOwnerRequest = Schema.Union([\n ScheduleRecoverRequest,\n ScheduleCreateRequest,\n ScheduleUpdateRequest,\n ScheduleGetRequest,\n ScheduleListRequest,\n ScheduleControlRequest,\n]);\n\ntype ScheduleOwnerRequest = typeof ScheduleOwnerRequest.Type;\n\nconst ScheduleOwnerFailure = Schema.Union([\n ScheduleValidationError,\n ScheduleAuthorizationError,\n ScheduleConflict,\n ScheduleNotFound,\n ScheduleCapacityError,\n ScheduleStorageError,\n ScheduleFailpointError,\n ScheduleOwnerProtocolError,\n]);\n\ntype ScheduleOwnerFailure = typeof ScheduleOwnerFailure.Type;\n\nconst ScheduleOwnerResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: ScheduleSnapshot }),\n Schema.TaggedStruct(\"Page\", { value: ScheduleSnapshotPageSchema }),\n Schema.TaggedStruct(\"Failed\", { failure: ScheduleOwnerFailure }),\n]);\n\ntype ScheduleOwnerResponse = typeof ScheduleOwnerResponse.Type;\n\nconst decodeScheduleOwnerRequest = Schema.decodeUnknownEffect(ScheduleOwnerRequest);\nconst encodeScheduleOwnerRequest = Schema.encodeEffect(ScheduleOwnerRequest);\nconst decodeScheduleOwnerResponse = Schema.decodeUnknownEffect(ScheduleOwnerResponse);\nconst encodeScheduleOwnerResponse = Schema.encodeEffect(ScheduleOwnerResponse);\n\nconst scheduleProtocolFailure = (message: string): ScheduleOwnerResponse => ({\n _tag: \"Failed\",\n failure: ScheduleOwnerProtocolError.make({ message: boundedProtocolMessage(message) }),\n});\n\nexport interface ScheduleOwnerObjectRpc extends Rpc.DurableObjectBranded {\n schedule(encoded: unknown): Promise<unknown>;\n}\n\nexport class ScheduleOwnerNamespace extends Context.Service<\n ScheduleOwnerNamespace,\n { readonly namespace: DurableObjectNamespace<ScheduleOwnerObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerNamespace\") {}\n\nconst passthroughAgent = (agentId: AgentId): DurableSubmitAgent<typeof PersistedJson> => ({\n definition: { id: agentId, input: PersistedJson },\n});\n\nconst requestOwner = (request: ScheduleOwnerRequest): ScheduleOwner => request.scope.owner;\n\n/** Provides the same authorized management service as NodeScheduling.layer. */\nexport class CloudflareSchedulingClient {\n static readonly layer: Layer.Layer<Scheduling, never, ScheduleOwnerNamespace> = Layer.effect(\n Scheduling,\n Effect.gen(function* () {\n const { namespace } = yield* ScheduleOwnerNamespace;\n\n const call = Effect.fn(\"CloudflareSchedulingClient.call\")(function* (\n owner: ScheduleOwner,\n request: ScheduleOwnerRequest,\n ): Effect.fn.Return<ScheduleOwnerResponse, ScheduleManagementFailure> {\n const encoded = yield* encodeScheduleOwnerRequest(request).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(scheduleOwnerKey(owner))).schedule(encoded),\n catch: () =>\n ScheduleStorageError.make({\n operation: \"call Schedule Owner\",\n reason: \"unavailable\",\n }),\n });\n\n const response = yield* decodeScheduleOwnerResponse(raw).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n\n if (response._tag !== \"Failed\") return response;\n\n return yield* response.failure._tag === \"ScheduleOwnerProtocolError\"\n ? ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" })\n : response.failure;\n });\n\n const encodeInput = Effect.fn(\"CloudflareSchedulingClient.encodeInput\")(function* <\n InputSchema extends Schema.Top,\n >(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n ): Effect.fn.Return<PersistedJson, ScheduleValidationError, InputSchema[\"EncodingServices\"]> {\n const encoded = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Unable to encode Agent input\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(PersistedJson)(encoded).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n });\n\n const create: Scheduling[\"Service\"][\"create\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n\n const response = yield* call(options.scope.owner, {\n _tag: \"Create\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const update: Scheduling[\"Service\"][\"update\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n\n const response = yield* call(options.scope.owner, {\n _tag: \"Update\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const get: Scheduling[\"Service\"][\"get\"] = (scope, scheduleId) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Get\",\n schemaVersion: 1,\n scope,\n scheduleId,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const list: Scheduling[\"Service\"][\"list\"] = (scope, options = {}) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"List\",\n schemaVersion: 1,\n scope,\n ...(options.after === undefined ? {} : { after: options.after }),\n ...(options.limit === undefined ? {} : { limit: options.limit }),\n });\n\n return response._tag === \"Page\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const control = (\n operation: \"pause\" | \"resume\" | \"cancel\",\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Control\",\n schemaVersion: 1,\n operation,\n scope,\n scheduleId,\n expectedRevision,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n return Scheduling.of({\n create,\n update,\n get,\n list,\n pause: (scope, id, revision) => control(\"pause\", scope, id, revision),\n resume: (scope, id, revision) => control(\"resume\", scope, id, revision),\n recover: (scope, scheduleId, expectedRevision, expectedGeneration) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Recover\",\n schemaVersion: 1,\n scope,\n scheduleId,\n expectedRevision,\n expectedGeneration,\n });\n\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n }),\n cancel: (scope, id, revision) => control(\"cancel\", scope, id, revision),\n });\n }),\n );\n}\n\nexport class ScheduleOwnerIdentity extends Context.Service<\n ScheduleOwnerIdentity,\n { readonly owner: ScheduleOwner }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerIdentity\") {}\n\nconst decodeOwnerName = Effect.fn(\"decodeScheduleOwnerName\")(function* (\n name: string | null | undefined,\n): Effect.fn.Return<ScheduleOwner, ScheduleOwnerProtocolError> {\n if (name === null || name === undefined) {\n return yield* ScheduleOwnerProtocolError.make({\n message: \"Schedule Owner objects require an idFromName identity\",\n });\n }\n\n const tuple = yield* Schema.decodeUnknownEffect(\n Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])),\n )(name).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object name is malformed\" }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(ScheduleOwner)({\n tenantId: tuple[0],\n ownerId: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object identity is invalid\" }),\n ),\n );\n});\n\nconst alarmStorageError = (operation: string) => (error: { readonly _tag: string }) =>\n ScheduleStorageError.make({\n operation,\n reason: error._tag === \"StorageOperationError\" ? \"unavailable\" : \"corrupt\",\n });\n\nconst transactionLayer: Layer.Layer<\n DoScheduleTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoScheduleTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoScheduleTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\n\n return yield* alarms\n .transaction((transaction) =>\n body((replacement) =>\n replacement.deadlineAtMillis === null\n ? transaction\n .cancelAlarm({ id: SCHEDULE_ALARM_ID, tag: SCHEDULE_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel Schedule Owner alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({\n operation: \"validate Schedule Owner alarm deadline\",\n reason: \"corrupt\",\n }),\n ),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SCHEDULE_ALARM_ID,\n tag: SCHEDULE_ALARM_TAG,\n runAt,\n payload: {\n schemaVersion: 1,\n generation: replacement.generation,\n },\n })\n .pipe(\n Effect.mapError(alarmStorageError(\"schedule Schedule Owner alarm\")),\n ),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n ScheduleStorageError.make({\n operation: \"commit Schedule Owner transaction\",\n reason: \"unavailable\",\n }),\n ),\n );\n }),\n });\n }),\n);\n\ntype ScheduleRuntimeServices =\n | Scheduling\n | ScheduleDriver\n | DoScheduleAlarmControl\n | ScheduleOwnerIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nconst ensureOwner = (\n expected: ScheduleOwner,\n request: ScheduleOwnerRequest,\n): Effect.Effect<void, ScheduleOwnerProtocolError> => {\n const observed = requestOwner(request);\n\n return observed.tenantId === expected.tenantId && observed.ownerId === expected.ownerId\n ? Effect.void\n : Effect.fail(\n ScheduleOwnerProtocolError.make({\n message: \"The request owner does not match the addressed Schedule Owner object\",\n }),\n );\n};\n\nconst handleScheduleRequest = Effect.fn(\"ScheduleOwner.handleRequest\")(function* (\n encoded: unknown,\n): Effect.fn.Return<unknown, never, Scheduling | ScheduleOwnerIdentity> {\n const decoded = yield* decodeScheduleOwnerRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeScheduleOwnerResponse(\n scheduleProtocolFailure(\"The Schedule request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { owner } = yield* ScheduleOwnerIdentity;\n const scheduling = yield* Scheduling;\n\n const response = yield* Effect.gen(function* () {\n yield* ensureOwner(owner, request);\n switch (request._tag) {\n case \"Create\": {\n const value = yield* scheduling.create(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n ...(request.admissionGroup === undefined\n ? {}\n : { admissionGroup: request.admissionGroup }),\n ...(request.admissionFence === undefined\n ? {}\n : { admissionFence: request.admissionFence }),\n });\n\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Update\": {\n const value = yield* scheduling.update(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n ...(request.admissionGroup === undefined\n ? {}\n : { admissionGroup: request.admissionGroup }),\n ...(request.admissionFence === undefined\n ? {}\n : { admissionFence: request.admissionFence }),\n expectedRevision: request.expectedRevision,\n });\n\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Get\":\n return {\n _tag: \"Snapshot\" as const,\n value: yield* scheduling.get(request.scope, request.scheduleId),\n };\n case \"List\":\n return {\n _tag: \"Page\" as const,\n value: yield* scheduling.list(request.scope, {\n ...(request.after === undefined ? {} : { after: request.after }),\n ...(request.limit === undefined ? {} : { limit: request.limit }),\n }),\n };\n case \"Recover\":\n return {\n _tag: \"Snapshot\" as const,\n value: yield* scheduling.recover(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n request.expectedGeneration,\n ),\n };\n case \"Control\": {\n const value =\n request.operation === \"pause\"\n ? yield* scheduling.pause(request.scope, request.scheduleId, request.expectedRevision)\n : request.operation === \"resume\"\n ? yield* scheduling.resume(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n )\n : yield* scheduling.cancel(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n );\n\n return { _tag: \"Snapshot\" as const, value };\n }\n }\n }).pipe(\n Effect.map((value): ScheduleOwnerResponse => value),\n Effect.catch((failure) =>\n Schema.is(ScheduleOwnerFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(\n scheduleProtocolFailure(\"The Schedule operation failed outside its public contract\"),\n ),\n ),\n );\n\n return yield* encodeScheduleOwnerResponse(response).pipe(Effect.orDie);\n});\n\n/** @internal The complete native alarm operation, including its event deadline. */\nexport const scheduleAlarmHandler = (limits: SchedulingLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SCHEDULE_ALARM_TAG || event.id !== SCHEDULE_ALARM_ID) {\n return yield* ScheduleAlarmProtocolError.make({\n message: `Unsupported Schedule Owner alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(ScheduleAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n ScheduleAlarmProtocolError.make({\n message: \"Unsupported Schedule Owner alarm payload version\",\n }),\n ),\n );\n const scheduling = yield* ScheduleDriver;\n const alarmControl = yield* DoScheduleAlarmControl;\n const { owner } = yield* ScheduleOwnerIdentity;\n const nowMillis = yield* Clock.currentTimeMillis;\n\n yield* alarmControl.prearm(nowMillis + limits.recoveryPollMillis);\n const pass = yield* scheduling.runDue(owner);\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.recoveryPollMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n { mode: \"ordered\" },\n ).pipe(\n // Bound due acquisition and acknowledgement as well as admission. Prepared occurrences\n // and their replacement alarm survive interruption and retain their idempotency keys.\n Effect.timeout(\"14 minutes\"),\n Effect.asVoid,\n );\n\nexport interface ScheduleOwnerObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, ScheduleRuntimeServices>\n> {\n schedule(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface ScheduleOwnerObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): ScheduleOwnerObjectInstance;\n}\n\n/**\n * The host Layer supplies authorization and routing and is cached for the object incarnation.\n * Cloudflare eviction does not guarantee its finalizers run. Do not acquire resources requiring\n * cleanup in this Layer; acquire them inside scoped `manage` / `prepare` operations instead.\n * Native services belong to effect-cf; the database and alarm runtime remain instance-owned.\n */\nexport const makeScheduleOwnerObjectClass = <E>(\n host: Layer.Layer<\n ScheduleAuthorizer | ThreadObjectNamespace,\n E,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment | ScheduleOwnerIdentity\n >,\n limits: SchedulingLimits = defaultSchedulingLimits,\n): ScheduleOwnerObjectClass => {\n const ownerLayer = Layer.effect(\n ScheduleOwnerIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return ScheduleOwnerIdentity.of({ owner: yield* decodeOwnerName(state.raw.id.name) });\n }),\n );\n\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n\n const application = Layer.merge(Scheduling.layer(limits), ScheduleDriver.layer(limits)).pipe(\n Layer.provideMerge(\n scheduleStoreLayer.pipe(Layer.provide(transactionLayer), Layer.provide(sqlLayer)),\n ),\n Layer.provide(\n cloudflareScheduledInputAdmissionLayer.pipe(\n Layer.provide(cloudflarePreparedInputAdmissionLayer),\n Layer.provide(CloudflareThreadClient.layer),\n ),\n ),\n Layer.provide(ScheduleWakeNoop),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(ownerLayer),\n );\n\n const runtime: Layer.Layer<\n ScheduleRuntimeServices,\n E | ScheduleStorageError | ScheduleOwnerProtocolError | ScheduleValidationError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = {\n schedule: (encoded: unknown) => handleScheduleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<ScheduleRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: scheduleAlarmHandler(limits),\n });\n\n class ScheduleOwnerObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return ScheduleOwnerObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAE1B,MAAM,uBAAuB,OAAO,OAAO;CACzC,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,0BAA0B,YAC9B,QAAQ,UAAU,OAAQ,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAK,EAAE;AAEjE,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY,IAAK,CAAC,EAAE,CAC5D,CAAC,CAAC,CAAC;AAEH,MAAM,gCAAgC;CACpC,eAAe,OAAO,QAAQ,CAAC;CAC/B,SAAS;CACT,OAAO;CACP,OAAOA;CACP,YAAY;CACZ,QAAQ;CACR,aAAa;CACb,mBAAmBA,cAAoB,OAAO;CAC9C,aAAa;CACb,gBAAgB,OAAO,YAAY,OAAO,eAAe,MAAM,OAAO,YAAY,GAAG,CAAC,CAAC;CACvF,gBAAgB,OAAO,YAAY,cAAc;AACnD;AAEA,MAAM,wBAAwB,OAAO,aAAa,UAAU,6BAA6B;AAEzF,MAAM,wBAAwB,OAAO,aAAa,UAAU;CAC1D,GAAG;CACH,kBAAkB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,qBAAqB,OAAO,aAAa,OAAO;CACpD,eAAe,OAAO,QAAQ,CAA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IA,mBAA2B,qBAAqB,UACzD,aAAa,MAAM,EAAE,SAAS,MAAM,IAAI,QAAQ,CAAC,CACnD,CACF;CAEA,MAAM,cAAc,MAAM,MAAM,WAAW,MAAM,MAAM,GAAG,eAAe,MAAM,MAAM,CAAC,CAAC,CAAC,KACtF,MAAM,aACJ,mBAAmB,KAAK,MAAM,QAAQ,gBAAgB,GAAG,MAAM,QAAQ,QAAQ,CAAC,CAClF,GACA,MAAM,QACJ,uCAAuC,KACrC,MAAM,QAAQ,qCAAqC,GACnD,MAAM,QAAQ,uBAAuB,KAAK,CAC5C,CACF,GACA,MAAM,QAAQ,gBAAgB,GAC9B,MAAM,QAAQ,cAAc,KAAK,GACjC,MAAM,aAAa,mBAAmB,mBAAmB,KAAK,GAC9D,MAAM,QAAQ,IAAI,GAClB,MAAM,aAAa,UAAU,CAC/B;CAEA,MAAM,UAIF,MAAM,cACR,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAOA,mBAA2B;EAChD,MAAM,QAAQ,OAAO,OAAO;EAE5B,OAAO,OAAO,MAAM,sBAAsB,MAAM,eAAe,aAAa,KAAK,CAAC;CACpF,CAAC,CACH;CAMA,MAAM,OAAOC,cAAsB,KAAK,SAAS;EAC/C,YAAY,OAAO;EACnB,KAAA,EALA,WAAW,YAAqB,sBAAsB,OAAO,EAK3D;EACF,QAAQ,qBAAqB,MAAM;CACrC,CAAC;CAED,MAAM,4BAA4B,KAAK;EACrC,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
@@ -1,5 +1,5 @@
1
1
  import { ThreadObjectNamespace } from "./CloudflareBindings.mjs";
2
- import { Cause, Context, Effect, Layer, Schema } from "effect";
2
+ import { Cause, Context, Effect, Layer, Schema, Scope } from "effect";
3
3
  import { DurableObject, DurableObjectAlarm, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
4
4
  import { SourcePartition, SubscriptionAuthorizer, SubscriptionLimits } from "@effect-agent/thread/Subscription";
5
5
  import { DoSubscriptionAlarmControl } from "@effect-agent/storage-cloudflare/DoSubscriptionStore";
@@ -7,12 +7,40 @@ import { EventSources } from "@effect-agent/thread/EventSource";
7
7
  import { SubscriptionInputBindings } from "@effect-agent/thread/SubscriptionInput";
8
8
  import { SubscriptionDriver, SubscriptionIntake, Subscriptions } from "@effect-agent/thread/Subscriptions";
9
9
  declare namespace CloudflareSubscriptions_d_exports {
10
- export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits };
10
+ export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmExtensionError, SubscriptionAlarmProtocolError, SubscriptionPartitionAlarmExtension, SubscriptionPartitionAlarmHandler, SubscriptionPartitionAlarmServices, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionAlarmHandler, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits };
11
11
  }
12
12
  declare const SubscriptionAlarmProtocolError_base: Schema.Class<SubscriptionAlarmProtocolError, Schema.TaggedStruct<"SubscriptionAlarmProtocolError", {
13
13
  readonly message: Schema.String;
14
14
  }>, Cause.YieldableError>;
15
15
  declare class SubscriptionAlarmProtocolError extends SubscriptionAlarmProtocolError_base {}
16
+ declare const SubscriptionAlarmExtensionError_base: Schema.Class<SubscriptionAlarmExtensionError, Schema.TaggedStruct<"SubscriptionAlarmExtensionError", {
17
+ readonly code: Schema.NonEmptyString;
18
+ }>, Cause.YieldableError>;
19
+ /** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */
20
+ declare class SubscriptionAlarmExtensionError extends SubscriptionAlarmExtensionError_base {}
21
+ /** Native partition services supplied at alarm invocation, after the host Layer is built. */
22
+ type SubscriptionPartitionAlarmServices = Subscriptions | SubscriptionIntake | SubscriptionDriver;
23
+ interface SubscriptionPartitionAlarmHandler<R = SubscriptionPartitionAlarmServices> {
24
+ readonly tag: string;
25
+ readonly handle: (event: DurableObjectAlarm.DurableObjectAlarmEvent) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError, R>;
26
+ }
27
+ /** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */
28
+ declare const SubscriptionPartitionAlarmExtension: Context.Reference<{
29
+ readonly handlers: ReadonlyArray<SubscriptionPartitionAlarmHandler>;
30
+ }>;
31
+ /** Capture host services once, deferring native partition services to invocation.
32
+ * Each invocation owns its codec/handler Scope and timeout.
33
+ * Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.
34
+ * The host owns durable idempotency, prearming and external-effect uncertainty.
35
+ */
36
+ declare const makeSubscriptionPartitionAlarmHandler: <Payload extends Schema.Top, R>(options: {
37
+ readonly tag: string;
38
+ readonly payload: Payload;
39
+ readonly timeoutMillis: number;
40
+ readonly handle: (event: Omit<DurableObjectAlarm.DurableObjectAlarmEvent, "payload"> & {
41
+ readonly payload: Payload["Type"];
42
+ }) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;
43
+ }) => Effect.Effect<SubscriptionPartitionAlarmHandler<Exclude<Exclude<R, Scope.Scope>, Exclude<Exclude<R, Scope.Scope | SubscriptionPartitionAlarmServices>, SubscriptionPartitionAlarmServices> | Exclude<Exclude<Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>, SubscriptionPartitionAlarmServices>> | Exclude<Exclude<Payload["DecodingServices"], Scope.Scope>, Exclude<Exclude<R, Scope.Scope | SubscriptionPartitionAlarmServices>, SubscriptionPartitionAlarmServices> | Exclude<Exclude<Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>, SubscriptionPartitionAlarmServices>>>, SubscriptionAlarmProtocolError, Exclude<R, Scope.Scope | SubscriptionPartitionAlarmServices> | Exclude<Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>>;
16
44
  declare const SubscriptionPartitionProtocolError_base: Schema.Class<SubscriptionPartitionProtocolError, Schema.TaggedStruct<"SubscriptionPartitionProtocolError", {
17
45
  readonly message: Schema.String;
18
46
  }>, Cause.YieldableError>;
@@ -22,7 +50,9 @@ declare const CloudflareSubscriptionConfigError_base: Schema.Class<CloudflareSub
22
50
  }>, Cause.YieldableError>;
23
51
  declare class CloudflareSubscriptionConfigError extends CloudflareSubscriptionConfigError_base {}
24
52
  /** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */
25
- declare const validateCloudflareSubscriptionLimits: (limits: SubscriptionLimits) => Effect.Effect<void, CloudflareSubscriptionConfigError>;
53
+ declare const validateCloudflareSubscriptionLimits: (limits: SubscriptionLimits, options?: {
54
+ readonly ancillaryAlarms?: boolean;
55
+ }) => Effect.Effect<void, CloudflareSubscriptionConfigError>;
26
56
  declare const sourcePartitionName: (partition: SourcePartition) => string;
27
57
  interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {
28
58
  subscription(encoded: unknown): Promise<unknown>;
@@ -53,5 +83,5 @@ interface SubscriptionPartitionObjectClass {
53
83
  */
54
84
  declare const makeSubscriptionPartitionObjectClass: <E>(host: Layer.Layer<SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace, E, DurableObjectState$1.DurableObjectState | WorkerEnvironment | SubscriptionPartitionIdentity>, limits?: SubscriptionLimits) => SubscriptionPartitionObjectClass;
55
85
  //#endregion
56
- export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, CloudflareSubscriptions_d_exports as t, validateCloudflareSubscriptionLimits };
86
+ export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmExtensionError, SubscriptionAlarmProtocolError, SubscriptionPartitionAlarmExtension, SubscriptionPartitionAlarmHandler, SubscriptionPartitionAlarmServices, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionAlarmHandler, makeSubscriptionPartitionObjectClass, sourcePartitionName, CloudflareSubscriptions_d_exports as t, validateCloudflareSubscriptionLimits };
57
87
  //# sourceMappingURL=CloudflareSubscriptions.d.mts.map