@effect-agent/platform-cloudflare 0.1.0-beta.51 → 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.
- package/dist/CloudflareSubscriptions.d.mts +9 -6
- package/dist/CloudflareSubscriptions.mjs +3 -2
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/CloudflareThreadClient.d.mts +17 -17
- package/dist/{ThreadObject-sDr1JBCj.d.mts → ThreadObject-BSRVxtPI.d.mts} +3 -3
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/index.d.mts +1 -1
- package/package.json +1 -1
- package/src/CloudflareSubscriptions.ts +25 -6
|
@@ -7,7 +7,7 @@ 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, SubscriptionAlarmExtensionError, SubscriptionAlarmProtocolError, SubscriptionPartitionAlarmExtension, SubscriptionPartitionAlarmHandler, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionAlarmHandler, 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;
|
|
@@ -18,15 +18,18 @@ declare const SubscriptionAlarmExtensionError_base: Schema.Class<SubscriptionAla
|
|
|
18
18
|
}>, Cause.YieldableError>;
|
|
19
19
|
/** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */
|
|
20
20
|
declare class SubscriptionAlarmExtensionError extends SubscriptionAlarmExtensionError_base {}
|
|
21
|
-
|
|
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> {
|
|
22
24
|
readonly tag: string;
|
|
23
|
-
readonly handle: (event: DurableObjectAlarm.DurableObjectAlarmEvent) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError>;
|
|
25
|
+
readonly handle: (event: DurableObjectAlarm.DurableObjectAlarmEvent) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError, R>;
|
|
24
26
|
}
|
|
25
27
|
/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */
|
|
26
28
|
declare const SubscriptionPartitionAlarmExtension: Context.Reference<{
|
|
27
29
|
readonly handlers: ReadonlyArray<SubscriptionPartitionAlarmHandler>;
|
|
28
30
|
}>;
|
|
29
|
-
/** Capture host services once
|
|
31
|
+
/** Capture host services once, deferring native partition services to invocation.
|
|
32
|
+
* Each invocation owns its codec/handler Scope and timeout.
|
|
30
33
|
* Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.
|
|
31
34
|
* The host owns durable idempotency, prearming and external-effect uncertainty.
|
|
32
35
|
*/
|
|
@@ -37,7 +40,7 @@ declare const makeSubscriptionPartitionAlarmHandler: <Payload extends Schema.Top
|
|
|
37
40
|
readonly handle: (event: Omit<DurableObjectAlarm.DurableObjectAlarmEvent, "payload"> & {
|
|
38
41
|
readonly payload: Payload["Type"];
|
|
39
42
|
}) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;
|
|
40
|
-
}) => Effect.Effect<SubscriptionPartitionAlarmHandler, SubscriptionAlarmProtocolError, Exclude<R, Scope.Scope> | Exclude<Payload["DecodingServices"], Scope.Scope>>;
|
|
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>>;
|
|
41
44
|
declare const SubscriptionPartitionProtocolError_base: Schema.Class<SubscriptionPartitionProtocolError, Schema.TaggedStruct<"SubscriptionPartitionProtocolError", {
|
|
42
45
|
readonly message: Schema.String;
|
|
43
46
|
}>, Cause.YieldableError>;
|
|
@@ -80,5 +83,5 @@ interface SubscriptionPartitionObjectClass {
|
|
|
80
83
|
*/
|
|
81
84
|
declare const makeSubscriptionPartitionObjectClass: <E>(host: Layer.Layer<SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace, E, DurableObjectState$1.DurableObjectState | WorkerEnvironment | SubscriptionPartitionIdentity>, limits?: SubscriptionLimits) => SubscriptionPartitionObjectClass;
|
|
82
85
|
//#endregion
|
|
83
|
-
export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmExtensionError, SubscriptionAlarmProtocolError, SubscriptionPartitionAlarmExtension, SubscriptionPartitionAlarmHandler, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionAlarmHandler, 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 };
|
|
84
87
|
//# sourceMappingURL=CloudflareSubscriptions.d.mts.map
|
|
@@ -41,13 +41,14 @@ var SubscriptionAlarmProtocolError = class extends Schema.TaggedError()("Subscri
|
|
|
41
41
|
var SubscriptionAlarmExtensionError = class extends Schema.TaggedError()("SubscriptionAlarmExtensionError", { code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) }) {};
|
|
42
42
|
/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */
|
|
43
43
|
const SubscriptionPartitionAlarmExtension = Context.Reference("@effect-agent/platform-cloudflare/SubscriptionPartitionAlarmExtension", { defaultValue: () => ({ handlers: [] }) });
|
|
44
|
-
/** Capture host services once
|
|
44
|
+
/** Capture host services once, deferring native partition services to invocation.
|
|
45
|
+
* Each invocation owns its codec/handler Scope and timeout.
|
|
45
46
|
* Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.
|
|
46
47
|
* The host owns durable idempotency, prearming and external-effect uncertainty.
|
|
47
48
|
*/
|
|
48
49
|
const makeSubscriptionPartitionAlarmHandler = Effect.fn("makeSubscriptionPartitionAlarmHandler")(function* (options) {
|
|
49
50
|
if (options.tag.length === 0 || options.tag.length > 128 || options.tag.startsWith("effect-agent/") || !Number.isSafeInteger(options.timeoutMillis) || options.timeoutMillis < 1 || options.timeoutMillis > MAX_ANCILLARY_ALARM_MILLIS) return yield* SubscriptionAlarmProtocolError.make({ message: "Invalid ancillary alarm tag or timeout" });
|
|
50
|
-
const services = yield* Effect.context();
|
|
51
|
+
const services = (yield* Effect.context()).pipe(Context.omit(Subscriptions, SubscriptionIntake, SubscriptionDriver));
|
|
51
52
|
return {
|
|
52
53
|
tag: options.tag,
|
|
53
54
|
handle: (event) => Effect.gen(function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CloudflareSubscriptions.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareSubscriptions.ts"],"sourcesContent":["import {\n DoSubscriptionAlarmControl,\n DoSubscriptionTransaction,\n doSubscriptionStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoSubscriptionStore\";\nimport { type EventSources } from \"@effect-agent/thread/EventSource\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport {\n EventAcknowledgement,\n EventSourceVersion,\n SourcePartition,\n type SubscriptionAuthorizer,\n SubscriptionConfiguration,\n SubscriptionDeliverySnapshot,\n SubscriptionDeliveryKey,\n SubscriptionError,\n SubscriptionFailpointError,\n SubscriptionKey,\n SubscriptionScope,\n type SubscriptionLimits,\n SubscriptionSnapshot,\n SubscriptionSourceError,\n defaultSubscriptionLimits,\n} from \"@effect-agent/thread/Subscription\";\nimport { type SubscriptionInputBindings } from \"@effect-agent/thread/SubscriptionInput\";\nimport {\n SubscriptionDriver,\n SubscriptionIntake,\n Subscriptions,\n} from \"@effect-agent/thread/Subscriptions\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Cause, Clock, Context, DateTime, Effect, Layer, Schema, type Scope } 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 { cloudflarePreparedInputAdmissionLayer } from \"./internal/prepared-admission.ts\";\n\nconst SUBSCRIPTION_ALARM_TAG = \"effect-agent/SubscriptionPartitionWake\";\nconst SUBSCRIPTION_ALARM_ID = \"driver\";\nconst MAX_ALARM_WALL_MILLIS = 12 * 60_000;\nconst MAX_ALARMS_PER_INVOCATION = 16;\nconst MAX_ANCILLARY_ALARM_MILLIS = 30_000;\n\nconst SubscriptionAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class SubscriptionAlarmProtocolError extends Schema.TaggedError<SubscriptionAlarmProtocolError>()(\n \"SubscriptionAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\n/** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */\nexport class SubscriptionAlarmExtensionError extends Schema.TaggedError<SubscriptionAlarmExtensionError>()(\n \"SubscriptionAlarmExtensionError\",\n { code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) },\n) {}\n\nexport interface SubscriptionPartitionAlarmHandler {\n readonly tag: string;\n readonly handle: (\n event: DurableObjectAlarm.DurableObjectAlarmEvent,\n ) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError>;\n}\n\n/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */\nexport const SubscriptionPartitionAlarmExtension = Context.Reference<{\n readonly handlers: ReadonlyArray<SubscriptionPartitionAlarmHandler>;\n}>(\"@effect-agent/platform-cloudflare/SubscriptionPartitionAlarmExtension\", {\n defaultValue: () => ({ handlers: [] }),\n});\n\n/** Capture host services once; each invocation owns its codec/handler Scope and timeout.\n * Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.\n * The host owns durable idempotency, prearming and external-effect uncertainty.\n */\nexport const makeSubscriptionPartitionAlarmHandler = Effect.fn(\n \"makeSubscriptionPartitionAlarmHandler\",\n)(function* <Payload extends Schema.Top, R>(options: {\n readonly tag: string;\n readonly payload: Payload;\n readonly timeoutMillis: number;\n readonly handle: (\n event: Omit<DurableObjectAlarm.DurableObjectAlarmEvent, \"payload\"> & {\n readonly payload: Payload[\"Type\"];\n },\n ) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;\n}): Effect.fn.Return<\n SubscriptionPartitionAlarmHandler,\n SubscriptionAlarmProtocolError,\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope>\n> {\n if (\n options.tag.length === 0 ||\n options.tag.length > 128 ||\n options.tag.startsWith(\"effect-agent/\") ||\n !Number.isSafeInteger(options.timeoutMillis) ||\n options.timeoutMillis < 1 ||\n options.timeoutMillis > MAX_ANCILLARY_ALARM_MILLIS\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm tag or timeout\",\n });\n const services = yield* Effect.context<Exclude<R | Payload[\"DecodingServices\"], Scope.Scope>>();\n\n return {\n tag: options.tag,\n handle: (event) =>\n Effect.gen(function* () {\n if (event.tag !== options.tag)\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Ancillary alarm tag mismatch\",\n });\n\n const payload = yield* Schema.decodeUnknownEffect(options.payload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({ message: \"Invalid ancillary alarm payload\" }),\n ),\n );\n\n yield* options.handle({ ...event, payload });\n }).pipe(\n Effect.scoped,\n Effect.timeout(options.timeoutMillis),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n Effect.provideContext(services),\n ),\n };\n});\n\nexport class SubscriptionPartitionProtocolError extends Schema.TaggedError<SubscriptionPartitionProtocolError>()(\n \"SubscriptionPartitionProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nexport class CloudflareSubscriptionConfigError extends Schema.TaggedError<CloudflareSubscriptionConfigError>()(\n \"CloudflareSubscriptionConfigError\",\n { message: Schema.String },\n) {}\n\n/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */\nexport const validateCloudflareSubscriptionLimits = (\n limits: SubscriptionLimits,\n options: { readonly ancillaryAlarms?: boolean } = {},\n): Effect.Effect<void, CloudflareSubscriptionConfigError> => {\n const worstCaseMillis =\n 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis +\n (options.ancillaryAlarms === true ? MAX_ALARMS_PER_INVOCATION * MAX_ANCILLARY_ALARM_MILLIS : 0);\n\n return worstCaseMillis <= MAX_ALARM_WALL_MILLIS\n ? Effect.void\n : Effect.fail(\n CloudflareSubscriptionConfigError.make({\n message: \"Subscription limits can exceed the bounded Durable Object alarm wall budget\",\n }),\n );\n};\n\nconst protocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nconst SubscribeRequest = Schema.TaggedStruct(\"Subscribe\", {\n schemaVersion: Schema.Literal(1),\n scope: Schema.Struct({\n ...SubscriptionScope.fields,\n }),\n options: Schema.Struct({\n subscriptionId: SubscriptionKey.fields.subscriptionId,\n source: EventSourceVersion,\n parameters: PersistedJson,\n context: PersistedJson,\n mode: Schema.Literals([\"once\", \"continuous\"]),\n expiresAtMillis: Schema.NullOr(Schema.Number),\n destination: SubscriptionConfiguration.fields.destination,\n deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,\n admissionGroup: SubscriptionConfiguration.fields.admissionGroup,\n admissionFence: SubscriptionConfiguration.fields.admissionFence,\n agentId: SubscriptionConfiguration.fields.agentId,\n definitions: SubscriptionConfiguration.fields.definitions,\n }),\n});\n\nconst UpdateSubscriptionRequest = Schema.TaggedStruct(\"UpdateSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n options: SubscribeRequest.fields.options.mapFields(({ subscriptionId: _, ...fields }) => fields),\n});\n\nconst SubscriptionStateRequest = Schema.Struct({\n _tag: Schema.Literals([\"PauseSubscription\", \"ResumeSubscription\", \"RecoverSubscription\"]),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ListSubscriptionsRequest = Schema.TaggedStruct(\"ListSubscriptions\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n after: Schema.optionalKey(Schema.Natural),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst CancelSubscriptionRequest = Schema.TaggedStruct(\"CancelSubscription\", {\n expectedRevision: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n});\n\nconst GetSubscriptionRequest = Schema.TaggedStruct(\"GetSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscriptionScope,\n key: SubscriptionKey,\n});\n\nconst RecoverDeliveryRequest = Schema.TaggedStruct(\"RecoverDelivery\", {\n expectedGeneration: Schema.Natural,\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionDeliveryKey,\n});\n\nconst ListDeliveriesRequest = Schema.TaggedStruct(\"ListDeliveries\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n after: Schema.optionalKey(Schema.String),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst AcceptRequest = Schema.TaggedStruct(\"Accept\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n payload: PersistedJson,\n});\n\nconst StatusRequest = Schema.TaggedStruct(\"Status\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n eventId: Schema.String,\n});\n\nconst SubscriptionPartitionRequest = Schema.Union([\n SubscribeRequest,\n GetSubscriptionRequest,\n UpdateSubscriptionRequest,\n SubscriptionStateRequest,\n ListSubscriptionsRequest,\n CancelSubscriptionRequest,\n ListDeliveriesRequest,\n RecoverDeliveryRequest,\n AcceptRequest,\n StatusRequest,\n]);\n\ntype SubscriptionPartitionRequest = typeof SubscriptionPartitionRequest.Type;\n\nconst SubscriptionPage = Schema.Struct({\n items: Schema.Array(SubscriptionSnapshot),\n next: Schema.NullOr(Schema.Natural),\n});\n\nconst DeliveryPage = Schema.Struct({\n items: Schema.Array(SubscriptionDeliverySnapshot),\n next: Schema.NullOr(Schema.String),\n});\n\nconst IntakeStatus = Schema.Struct({\n ...EventAcknowledgement.fields,\n routingComplete: Schema.Boolean,\n routingFailure: Schema.NullOr(Schema.String),\n nextAttemptAtMillis: Schema.Number,\n});\n\nconst SubscriptionPartitionFailure = Schema.Union([\n SubscriptionError,\n SubscriptionSourceError,\n SubscriptionFailpointError,\n SubscriptionPartitionProtocolError,\n]);\n\ntype SubscriptionPartitionFailure = typeof SubscriptionPartitionFailure.Type;\n\nconst SubscriptionPartitionResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: SubscriptionSnapshot }),\n Schema.TaggedStruct(\"SubscriptionPage\", { value: SubscriptionPage }),\n Schema.TaggedStruct(\"DeliveryPage\", { value: DeliveryPage }),\n Schema.TaggedStruct(\"DeliverySnapshot\", { value: SubscriptionDeliverySnapshot }),\n Schema.TaggedStruct(\"Acknowledgement\", { value: EventAcknowledgement }),\n Schema.TaggedStruct(\"Status\", { value: IntakeStatus }),\n Schema.TaggedStruct(\"Failed\", { failure: SubscriptionPartitionFailure }),\n]);\n\ntype SubscriptionPartitionResponse = typeof SubscriptionPartitionResponse.Type;\n\nconst decodeRequest = Schema.decodeUnknownEffect(SubscriptionPartitionRequest);\nconst encodeRequest = Schema.encodeEffect(SubscriptionPartitionRequest);\nconst decodeResponse = Schema.decodeUnknownEffect(SubscriptionPartitionResponse);\nconst encodeResponse = Schema.encodeEffect(SubscriptionPartitionResponse);\n\nconst protocolFailure = (message: string): SubscriptionPartitionResponse => ({\n _tag: \"Failed\",\n failure: SubscriptionPartitionProtocolError.make({ message: protocolMessage(message) }),\n});\n\nexport const sourcePartitionName = (partition: SourcePartition): string =>\n JSON.stringify([partition.tenantId, partition.address]);\n\nexport interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {\n subscription(encoded: unknown): Promise<unknown>;\n}\n\nexport class SubscriptionPartitionNamespace extends Context.Service<\n SubscriptionPartitionNamespace,\n { readonly namespace: DurableObjectNamespace<SubscriptionPartitionObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace\") {}\n\nconst storageFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"storage\", code });\n\nconst corruptFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"corrupt\", code });\n\n/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */\nexport class CloudflareSubscriptionsClient {\n static layer(\n partition: SourcePartition,\n ): Layer.Layer<Subscriptions | SubscriptionIntake, never, SubscriptionPartitionNamespace> {\n return Layer.effectContext(\n Effect.gen(function* () {\n const { namespace } = yield* SubscriptionPartitionNamespace;\n\n const call = Effect.fn(\"CloudflareSubscriptionsClient.call\")(function* (\n addressedPartition: SourcePartition,\n request: SubscriptionPartitionRequest,\n ) {\n if (!samePartition(partition, addressedPartition)) {\n return yield* SubscriptionError.make({ reason: \"unauthorized\", code: \"partition\" });\n }\n\n const encoded = yield* encodeRequest(request).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () =>\n namespace\n .get(namespace.idFromName(sourcePartitionName(partition)))\n .subscription(encoded),\n catch: () => storageFailure(\"call-subscription-partition\"),\n });\n\n return yield* decodeResponse(raw).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n });\n\n const failed = (response: SubscriptionPartitionResponse): SubscriptionPartitionFailure =>\n response._tag === \"Failed\"\n ? response.failure\n : SubscriptionPartitionProtocolError.make({\n message: \"Unexpected subscription response\",\n });\n\n const asProtocolError = (): SubscriptionError =>\n corruptFailure(\"subscription-partition-protocol\");\n\n const changeState = Effect.fn(\"CloudflareSubscriptions.changeState\")(function* (\n scope: typeof SubscriptionScope.Type,\n key: typeof SubscriptionKey.Type,\n expectedRevision: number,\n _tag: \"PauseSubscription\" | \"ResumeSubscription\" | \"RecoverSubscription\",\n ) {\n const response = yield* call(scope.partition, {\n _tag,\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n });\n\n const subscriptions = Subscriptions.of({\n recoverSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"RecoverSubscription\"),\n getSubscription: (scope, key) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"GetSubscription\",\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n recoverDelivery: (scope, key, expectedGeneration) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"RecoverDelivery\",\n expectedGeneration,\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"DeliverySnapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n }),\n updateSubscription: (scope, key, expectedRevision, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"UpdateSubscription\",\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\" ||\n failure._tag === \"SubscriptionSourceError\"\n ? failure\n : asProtocolError();\n }),\n pauseSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"PauseSubscription\"),\n resumeSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"ResumeSubscription\"),\n subscribe: (scope, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"Subscribe\",\n schemaVersion: 1,\n scope,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listSubscriptions: (scope, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListSubscriptions\",\n schemaVersion: 1,\n scope,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"SubscriptionPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n cancelSubscription: (scope, key, expectedRevision) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"CancelSubscription\",\n ...(expectedRevision === undefined ? {} : { expectedRevision }),\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listDeliveries: (scope, key, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListDeliveries\",\n schemaVersion: 1,\n scope,\n key,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"DeliveryPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n const intake = SubscriptionIntake.of({\n accept: (principal, source, payload) =>\n Effect.gen(function* () {\n const request = yield* Schema.decodeUnknownEffect(AcceptRequest)({\n _tag: \"Accept\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n payload,\n }).pipe(\n Effect.mapError(() =>\n SubscriptionError.make({ reason: \"validation\", code: \"event-payload\" }),\n ),\n );\n\n const response = yield* call(request.partition, request);\n\n if (response._tag === \"Acknowledgement\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n status: (principal, source, eventId) =>\n Effect.gen(function* () {\n const response = yield* call(partition, {\n _tag: \"Status\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n eventId,\n });\n\n if (response._tag === \"Status\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n return Context.make(Subscriptions, subscriptions).pipe(\n Context.add(SubscriptionIntake, intake),\n );\n }),\n );\n }\n}\n\nexport class SubscriptionPartitionIdentity extends Context.Service<\n SubscriptionPartitionIdentity,\n { readonly partition: SourcePartition }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity\") {}\n\nconst decodePartitionName = Effect.fn(\"decodeSubscriptionPartitionName\")(function* (\n name: string | null | undefined,\n) {\n if (name === null || name === undefined) {\n return yield* SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition 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 SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition name is malformed\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(SourcePartition)({\n tenantId: tuple[0],\n address: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition identity is invalid\",\n }),\n ),\n );\n});\n\nconst samePartition = Schema.toEquivalence(SourcePartition);\n\nconst requestPartition = (request: SubscriptionPartitionRequest): SourcePartition =>\n request._tag === \"Accept\" || request._tag === \"Status\"\n ? request.partition\n : request.scope.partition;\n\nconst handleRequest = Effect.fn(\"SubscriptionPartition.handleRequest\")(function* (\n encoded: unknown,\n) {\n const decoded = yield* decodeRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeResponse(\n protocolFailure(\"The subscription request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { partition } = yield* SubscriptionPartitionIdentity;\n\n if (!samePartition(partition, requestPartition(request))) {\n return yield* encodeResponse(\n protocolFailure(\"The request partition does not match the addressed object\"),\n ).pipe(Effect.orDie);\n }\n const subscriptions = yield* Subscriptions;\n const intake = yield* SubscriptionIntake;\n\n const response = yield* Effect.gen(function* (): Effect.fn.Return<\n SubscriptionPartitionResponse,\n SubscriptionPartitionFailure\n > {\n switch (request._tag) {\n case \"GetSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.getSubscription(request.scope, request.key),\n };\n case \"Subscribe\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.subscribe(request.scope, request.options),\n };\n case \"UpdateSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.updateSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n request.options,\n ),\n };\n case \"RecoverSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.recoverSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"PauseSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.pauseSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ResumeSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.resumeSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ListSubscriptions\":\n return {\n _tag: \"SubscriptionPage\",\n value: yield* subscriptions.listSubscriptions(\n request.scope,\n request.after,\n request.limit,\n ),\n };\n case \"CancelSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.cancelSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"RecoverDelivery\":\n return {\n _tag: \"DeliverySnapshot\",\n value: yield* subscriptions.recoverDelivery(\n request.scope,\n request.key,\n request.expectedGeneration,\n ),\n };\n case \"ListDeliveries\":\n return {\n _tag: \"DeliveryPage\",\n value: yield* subscriptions.listDeliveries(\n request.scope,\n request.key,\n request.after,\n request.limit,\n ),\n };\n case \"Accept\":\n return {\n _tag: \"Acknowledgement\",\n value: yield* intake.accept(request.principal, request.source, request.payload),\n };\n case \"Status\":\n return {\n _tag: \"Status\",\n value: yield* intake.status(request.principal, request.source, request.eventId),\n };\n }\n }).pipe(\n Effect.catch((failure) =>\n Schema.is(SubscriptionPartitionFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(protocolFailure(\"The subscription operation failed outside its contract\")),\n ),\n );\n\n return yield* encodeResponse(response).pipe(Effect.orDie);\n});\n\nconst alarmStorageError = (code: string) => () => storageFailure(code);\n\nconst transactionLayer: Layer.Layer<\n DoSubscriptionTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoSubscriptionTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoSubscriptionTransaction.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: SUBSCRIPTION_ALARM_ID, tag: SUBSCRIPTION_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel-subscription-alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-alarm-deadline\")),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SUBSCRIPTION_ALARM_ID,\n tag: SUBSCRIPTION_ALARM_TAG,\n runAt,\n payload: { schemaVersion: 1, generation: replacement.generation },\n })\n .pipe(Effect.mapError(alarmStorageError(\"schedule-subscription-alarm\"))),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n storageFailure(\"commit-subscription-transaction\"),\n ),\n );\n }),\n });\n }),\n);\n\nconst alarmHandler = (limits: SubscriptionLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SUBSCRIPTION_ALARM_TAG) {\n const { handlers } = yield* SubscriptionPartitionAlarmExtension;\n const matches = handlers.filter((handler) => handler.tag === event.tag);\n const handler = matches[0];\n\n if (\n event.tag.startsWith(\"effect-agent/\") ||\n matches.length !== 1 ||\n handler === undefined\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Unknown or ambiguous ancillary alarm tag\",\n });\n\n return yield* handler.handle(event).pipe(\n Effect.scoped,\n Effect.timeout(MAX_ANCILLARY_ALARM_MILLIS),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n );\n }\n if (event.id !== SUBSCRIPTION_ALARM_ID) {\n return yield* SubscriptionAlarmProtocolError.make({\n message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({\n message: \"Unsupported subscription alarm payload\",\n }),\n ),\n );\n const driver = yield* SubscriptionDriver;\n const alarmControl = yield* DoSubscriptionAlarmControl;\n\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n\n const pass = yield* driver.runDue.pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.failCause(cause)\n : Clock.currentTimeMillis.pipe(\n Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)),\n Effect.andThen(Effect.failCause(cause)),\n ),\n ),\n );\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n {\n mode: \"isolated\",\n limit: MAX_ALARMS_PER_INVOCATION,\n retryFailedAfter: limits.retryMillis,\n onFailure: () => Effect.logWarning(\"Subscription partition alarm retained for retry\"),\n },\n ).pipe(Effect.asVoid);\n\ntype SubscriptionRuntimeServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver\n | DoSubscriptionAlarmControl\n | SubscriptionPartitionIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nexport interface SubscriptionPartitionObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, SubscriptionRuntimeServices>\n> {\n subscription(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface SubscriptionPartitionObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): SubscriptionPartitionObjectInstance;\n}\n\n/**\n * Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source\n * catalog and authority. It must not retain cleanup-scoped resources across RPC events.\n */\nexport const makeSubscriptionPartitionObjectClass = <E>(\n host: Layer.Layer<\n SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace,\n E,\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n | SubscriptionPartitionIdentity\n >,\n limits: SubscriptionLimits = defaultSubscriptionLimits,\n): SubscriptionPartitionObjectClass => {\n const cloudflareLimitsLayer = Layer.effectDiscard(validateCloudflareSubscriptionLimits(limits));\n\n const identityLayer = Layer.effect(\n SubscriptionPartitionIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return SubscriptionPartitionIdentity.of({\n partition: yield* decodePartitionName(state.raw.id.name),\n });\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 partitionStore = Layer.unwrap(\n Effect.map(SubscriptionPartitionIdentity, ({ partition }) =>\n doSubscriptionStoreLayer(partition).pipe(\n Layer.provide(transactionLayer),\n Layer.provide(sqlLayer),\n ),\n ),\n );\n\n const application = Layer.mergeAll(\n Subscriptions.layer(limits),\n SubscriptionIntake.layer(limits),\n SubscriptionDriver.layer(limits),\n cloudflareLimitsLayer,\n // Capture the host reference before its scoped input Layer is hidden from the runtime.\n Layer.effect(\n SubscriptionPartitionAlarmExtension,\n Effect.gen(function* () {\n const extension = yield* SubscriptionPartitionAlarmExtension;\n const tags = extension.handlers.map((handler) => handler.tag);\n\n if (\n tags.length > MAX_ALARMS_PER_INVOCATION ||\n new Set(tags).size !== tags.length ||\n tags.some(\n (tag) => tag.length === 0 || tag.length > 128 || tag.startsWith(\"effect-agent/\"),\n )\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm handler registry\",\n });\n\n yield* validateCloudflareSubscriptionLimits(limits, { ancillaryAlarms: tags.length > 0 });\n\n return extension;\n }),\n ),\n ).pipe(\n Layer.provideMerge(partitionStore),\n Layer.provide(\n cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer)),\n ),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(identityLayer),\n );\n\n const runtime: Layer.Layer<\n SubscriptionRuntimeServices,\n | E\n | SubscriptionError\n | SubscriptionPartitionProtocolError\n | CloudflareSubscriptionConfigError\n | SubscriptionAlarmProtocolError,\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 subscription: (encoded: unknown) => handleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<SubscriptionRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: alarmHandler(limits),\n });\n\n class SubscriptionPartitionObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return SubscriptionPartitionObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,yBAAyB;AAC/B,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;AAEnC,MAAM,2BAA2B,OAAO,OAAO;CAC7C,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CA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AAI,IAAI,CAAC,CAAC,SAAS,KAAK,UAC5B,KAAK,MACF,QAAQ,IAAI,WAAW,KAAK,IAAI,SAAS,OAAO,IAAI,WAAW,eAAe,CACjF,GAEA,OAAO,OAAO,+BAA+B,KAAK,EAChD,SAAS,2CACX,CAAC;EAEH,OAAO,qCAAqC,QAAQ,EAAE,iBAAiB,KAAK,SAAS,EAAE,CAAC;EAExF,OAAO;CACT,CAAC,CACH,CACF,CAAC,CAAC,KACA,MAAM,aAAa,cAAc,GACjC,MAAM,QACJ,sCAAsC,KAAK,MAAM,QAAQ,uBAAuB,KAAK,CAAC,CACxF,GACA,MAAM,QAAQ,cAAc,KAAK,GACjC,MAAM,aAAa,mBAAmB,mBAAmB,KAAK,GAC9D,MAAM,QAAQ,IAAI,GAClB,MAAM,aAAa,aAAa,CAClC;CAEA,MAAM,UAQF,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,eAAe,YAAqB,cAAc,OAAO,EAKvD;EACF,QAAQ,aAAa,MAAM;CAC7B,CAAC;CAED,MAAM,oCAAoC,KAAK;EAC7C,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"CloudflareSubscriptions.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/CloudflareSubscriptions.ts"],"sourcesContent":["import {\n DoSubscriptionAlarmControl,\n DoSubscriptionTransaction,\n doSubscriptionStoreLayer,\n} from \"@effect-agent/storage-cloudflare/DoSubscriptionStore\";\nimport { type EventSources } from \"@effect-agent/thread/EventSource\";\nimport { PersistedJson } from \"@effect-agent/thread/Records\";\nimport { Principal } from \"@effect-agent/thread/SubmissionLedger\";\nimport {\n EventAcknowledgement,\n EventSourceVersion,\n SourcePartition,\n type SubscriptionAuthorizer,\n SubscriptionConfiguration,\n SubscriptionDeliverySnapshot,\n SubscriptionDeliveryKey,\n SubscriptionError,\n SubscriptionFailpointError,\n SubscriptionKey,\n SubscriptionScope,\n type SubscriptionLimits,\n SubscriptionSnapshot,\n SubscriptionSourceError,\n defaultSubscriptionLimits,\n} from \"@effect-agent/thread/Subscription\";\nimport { type SubscriptionInputBindings } from \"@effect-agent/thread/SubscriptionInput\";\nimport {\n SubscriptionDriver,\n SubscriptionIntake,\n Subscriptions,\n} from \"@effect-agent/thread/Subscriptions\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Cause, Clock, Context, DateTime, Effect, Layer, Schema, type Scope } 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 { cloudflarePreparedInputAdmissionLayer } from \"./internal/prepared-admission.ts\";\n\nconst SUBSCRIPTION_ALARM_TAG = \"effect-agent/SubscriptionPartitionWake\";\nconst SUBSCRIPTION_ALARM_ID = \"driver\";\nconst MAX_ALARM_WALL_MILLIS = 12 * 60_000;\nconst MAX_ALARMS_PER_INVOCATION = 16;\nconst MAX_ANCILLARY_ALARM_MILLIS = 30_000;\n\nconst SubscriptionAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class SubscriptionAlarmProtocolError extends Schema.TaggedError<SubscriptionAlarmProtocolError>()(\n \"SubscriptionAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\n/** Bounded host diagnostic; credentials and provider responses do not belong in alarm failures. */\nexport class SubscriptionAlarmExtensionError extends Schema.TaggedError<SubscriptionAlarmExtensionError>()(\n \"SubscriptionAlarmExtensionError\",\n { code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) },\n) {}\n\n/** Native partition services supplied at alarm invocation, after the host Layer is built. */\nexport type SubscriptionPartitionAlarmServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver;\n\nexport interface SubscriptionPartitionAlarmHandler<R = SubscriptionPartitionAlarmServices> {\n readonly tag: string;\n readonly handle: (\n event: DurableObjectAlarm.DurableObjectAlarmEvent,\n ) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError, R>;\n}\n\n/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */\nexport const SubscriptionPartitionAlarmExtension = Context.Reference<{\n readonly handlers: ReadonlyArray<SubscriptionPartitionAlarmHandler>;\n}>(\"@effect-agent/platform-cloudflare/SubscriptionPartitionAlarmExtension\", {\n defaultValue: () => ({ handlers: [] }),\n});\n\n/** Capture host services once, deferring native partition services to invocation.\n * Each invocation owns its codec/handler Scope and timeout.\n * Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.\n * The host owns durable idempotency, prearming and external-effect uncertainty.\n */\nexport const makeSubscriptionPartitionAlarmHandler = Effect.fn(\n \"makeSubscriptionPartitionAlarmHandler\",\n)(function* <Payload extends Schema.Top, R>(options: {\n readonly tag: string;\n readonly payload: Payload;\n readonly timeoutMillis: number;\n readonly handle: (\n event: Omit<DurableObjectAlarm.DurableObjectAlarmEvent, \"payload\"> & {\n readonly payload: Payload[\"Type\"];\n },\n ) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;\n}): Effect.fn.Return<\n SubscriptionPartitionAlarmHandler<\n Exclude<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope>,\n Exclude<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>,\n SubscriptionPartitionAlarmServices\n >\n >\n >,\n SubscriptionAlarmProtocolError,\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>\n> {\n if (\n options.tag.length === 0 ||\n options.tag.length > 128 ||\n options.tag.startsWith(\"effect-agent/\") ||\n !Number.isSafeInteger(options.timeoutMillis) ||\n options.timeoutMillis < 1 ||\n options.timeoutMillis > MAX_ANCILLARY_ALARM_MILLIS\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm tag or timeout\",\n });\n\n // Context capture includes unrequested services too; never retain a host override of native work.\n const services = (yield* Effect.context<\n Exclude<R | Payload[\"DecodingServices\"], Scope.Scope | SubscriptionPartitionAlarmServices>\n >()).pipe(Context.omit(Subscriptions, SubscriptionIntake, SubscriptionDriver));\n\n return {\n tag: options.tag,\n handle: (event) =>\n Effect.gen(function* () {\n if (event.tag !== options.tag)\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Ancillary alarm tag mismatch\",\n });\n\n const payload = yield* Schema.decodeUnknownEffect(options.payload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({ message: \"Invalid ancillary alarm payload\" }),\n ),\n );\n\n yield* options.handle({ ...event, payload });\n }).pipe(\n Effect.scoped,\n Effect.timeout(options.timeoutMillis),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n Effect.provideContext(services),\n ),\n };\n});\n\nexport class SubscriptionPartitionProtocolError extends Schema.TaggedError<SubscriptionPartitionProtocolError>()(\n \"SubscriptionPartitionProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nexport class CloudflareSubscriptionConfigError extends Schema.TaggedError<CloudflareSubscriptionConfigError>()(\n \"CloudflareSubscriptionConfigError\",\n { message: Schema.String },\n) {}\n\n/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */\nexport const validateCloudflareSubscriptionLimits = (\n limits: SubscriptionLimits,\n options: { readonly ancillaryAlarms?: boolean } = {},\n): Effect.Effect<void, CloudflareSubscriptionConfigError> => {\n const worstCaseMillis =\n 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis +\n (options.ancillaryAlarms === true ? MAX_ALARMS_PER_INVOCATION * MAX_ANCILLARY_ALARM_MILLIS : 0);\n\n return worstCaseMillis <= MAX_ALARM_WALL_MILLIS\n ? Effect.void\n : Effect.fail(\n CloudflareSubscriptionConfigError.make({\n message: \"Subscription limits can exceed the bounded Durable Object alarm wall budget\",\n }),\n );\n};\n\nconst protocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nconst SubscribeRequest = Schema.TaggedStruct(\"Subscribe\", {\n schemaVersion: Schema.Literal(1),\n scope: Schema.Struct({\n ...SubscriptionScope.fields,\n }),\n options: Schema.Struct({\n subscriptionId: SubscriptionKey.fields.subscriptionId,\n source: EventSourceVersion,\n parameters: PersistedJson,\n context: PersistedJson,\n mode: Schema.Literals([\"once\", \"continuous\"]),\n expiresAtMillis: Schema.NullOr(Schema.Number),\n destination: SubscriptionConfiguration.fields.destination,\n deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,\n admissionGroup: SubscriptionConfiguration.fields.admissionGroup,\n admissionFence: SubscriptionConfiguration.fields.admissionFence,\n agentId: SubscriptionConfiguration.fields.agentId,\n definitions: SubscriptionConfiguration.fields.definitions,\n }),\n});\n\nconst UpdateSubscriptionRequest = Schema.TaggedStruct(\"UpdateSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n options: SubscribeRequest.fields.options.mapFields(({ subscriptionId: _, ...fields }) => fields),\n});\n\nconst SubscriptionStateRequest = Schema.Struct({\n _tag: Schema.Literals([\"PauseSubscription\", \"ResumeSubscription\", \"RecoverSubscription\"]),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ListSubscriptionsRequest = Schema.TaggedStruct(\"ListSubscriptions\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n after: Schema.optionalKey(Schema.Natural),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst CancelSubscriptionRequest = Schema.TaggedStruct(\"CancelSubscription\", {\n expectedRevision: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n});\n\nconst GetSubscriptionRequest = Schema.TaggedStruct(\"GetSubscription\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscriptionScope,\n key: SubscriptionKey,\n});\n\nconst RecoverDeliveryRequest = Schema.TaggedStruct(\"RecoverDelivery\", {\n expectedGeneration: Schema.Natural,\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionDeliveryKey,\n});\n\nconst ListDeliveriesRequest = Schema.TaggedStruct(\"ListDeliveries\", {\n schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\n after: Schema.optionalKey(Schema.String),\n limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),\n});\n\nconst AcceptRequest = Schema.TaggedStruct(\"Accept\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n payload: PersistedJson,\n});\n\nconst StatusRequest = Schema.TaggedStruct(\"Status\", {\n schemaVersion: Schema.Literal(1),\n partition: SourcePartition,\n principal: Principal,\n source: EventSourceVersion,\n eventId: Schema.String,\n});\n\nconst SubscriptionPartitionRequest = Schema.Union([\n SubscribeRequest,\n GetSubscriptionRequest,\n UpdateSubscriptionRequest,\n SubscriptionStateRequest,\n ListSubscriptionsRequest,\n CancelSubscriptionRequest,\n ListDeliveriesRequest,\n RecoverDeliveryRequest,\n AcceptRequest,\n StatusRequest,\n]);\n\ntype SubscriptionPartitionRequest = typeof SubscriptionPartitionRequest.Type;\n\nconst SubscriptionPage = Schema.Struct({\n items: Schema.Array(SubscriptionSnapshot),\n next: Schema.NullOr(Schema.Natural),\n});\n\nconst DeliveryPage = Schema.Struct({\n items: Schema.Array(SubscriptionDeliverySnapshot),\n next: Schema.NullOr(Schema.String),\n});\n\nconst IntakeStatus = Schema.Struct({\n ...EventAcknowledgement.fields,\n routingComplete: Schema.Boolean,\n routingFailure: Schema.NullOr(Schema.String),\n nextAttemptAtMillis: Schema.Number,\n});\n\nconst SubscriptionPartitionFailure = Schema.Union([\n SubscriptionError,\n SubscriptionSourceError,\n SubscriptionFailpointError,\n SubscriptionPartitionProtocolError,\n]);\n\ntype SubscriptionPartitionFailure = typeof SubscriptionPartitionFailure.Type;\n\nconst SubscriptionPartitionResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: SubscriptionSnapshot }),\n Schema.TaggedStruct(\"SubscriptionPage\", { value: SubscriptionPage }),\n Schema.TaggedStruct(\"DeliveryPage\", { value: DeliveryPage }),\n Schema.TaggedStruct(\"DeliverySnapshot\", { value: SubscriptionDeliverySnapshot }),\n Schema.TaggedStruct(\"Acknowledgement\", { value: EventAcknowledgement }),\n Schema.TaggedStruct(\"Status\", { value: IntakeStatus }),\n Schema.TaggedStruct(\"Failed\", { failure: SubscriptionPartitionFailure }),\n]);\n\ntype SubscriptionPartitionResponse = typeof SubscriptionPartitionResponse.Type;\n\nconst decodeRequest = Schema.decodeUnknownEffect(SubscriptionPartitionRequest);\nconst encodeRequest = Schema.encodeEffect(SubscriptionPartitionRequest);\nconst decodeResponse = Schema.decodeUnknownEffect(SubscriptionPartitionResponse);\nconst encodeResponse = Schema.encodeEffect(SubscriptionPartitionResponse);\n\nconst protocolFailure = (message: string): SubscriptionPartitionResponse => ({\n _tag: \"Failed\",\n failure: SubscriptionPartitionProtocolError.make({ message: protocolMessage(message) }),\n});\n\nexport const sourcePartitionName = (partition: SourcePartition): string =>\n JSON.stringify([partition.tenantId, partition.address]);\n\nexport interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {\n subscription(encoded: unknown): Promise<unknown>;\n}\n\nexport class SubscriptionPartitionNamespace extends Context.Service<\n SubscriptionPartitionNamespace,\n { readonly namespace: DurableObjectNamespace<SubscriptionPartitionObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace\") {}\n\nconst storageFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"storage\", code });\n\nconst corruptFailure = (code: string): SubscriptionError =>\n SubscriptionError.make({ reason: \"corrupt\", code });\n\n/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */\nexport class CloudflareSubscriptionsClient {\n static layer(\n partition: SourcePartition,\n ): Layer.Layer<Subscriptions | SubscriptionIntake, never, SubscriptionPartitionNamespace> {\n return Layer.effectContext(\n Effect.gen(function* () {\n const { namespace } = yield* SubscriptionPartitionNamespace;\n\n const call = Effect.fn(\"CloudflareSubscriptionsClient.call\")(function* (\n addressedPartition: SourcePartition,\n request: SubscriptionPartitionRequest,\n ) {\n if (!samePartition(partition, addressedPartition)) {\n return yield* SubscriptionError.make({ reason: \"unauthorized\", code: \"partition\" });\n }\n\n const encoded = yield* encodeRequest(request).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n\n const raw = yield* Effect.tryPromise({\n try: () =>\n namespace\n .get(namespace.idFromName(sourcePartitionName(partition)))\n .subscription(encoded),\n catch: () => storageFailure(\"call-subscription-partition\"),\n });\n\n return yield* decodeResponse(raw).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\n );\n });\n\n const failed = (response: SubscriptionPartitionResponse): SubscriptionPartitionFailure =>\n response._tag === \"Failed\"\n ? response.failure\n : SubscriptionPartitionProtocolError.make({\n message: \"Unexpected subscription response\",\n });\n\n const asProtocolError = (): SubscriptionError =>\n corruptFailure(\"subscription-partition-protocol\");\n\n const changeState = Effect.fn(\"CloudflareSubscriptions.changeState\")(function* (\n scope: typeof SubscriptionScope.Type,\n key: typeof SubscriptionKey.Type,\n expectedRevision: number,\n _tag: \"PauseSubscription\" | \"ResumeSubscription\" | \"RecoverSubscription\",\n ) {\n const response = yield* call(scope.partition, {\n _tag,\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n });\n\n const subscriptions = Subscriptions.of({\n recoverSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"RecoverSubscription\"),\n getSubscription: (scope, key) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"GetSubscription\",\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n recoverDelivery: (scope, key, expectedGeneration) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"RecoverDelivery\",\n expectedGeneration,\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"DeliverySnapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n ? failure\n : asProtocolError();\n }),\n updateSubscription: (scope, key, expectedRevision, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"UpdateSubscription\",\n schemaVersion: 1,\n scope,\n key,\n expectedRevision,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\" ||\n failure._tag === \"SubscriptionSourceError\"\n ? failure\n : asProtocolError();\n }),\n pauseSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"PauseSubscription\"),\n resumeSubscription: (scope, key, revision) =>\n changeState(scope, key, revision, \"ResumeSubscription\"),\n subscribe: (scope, options) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"Subscribe\",\n schemaVersion: 1,\n scope,\n options,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listSubscriptions: (scope, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListSubscriptions\",\n schemaVersion: 1,\n scope,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"SubscriptionPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n cancelSubscription: (scope, key, expectedRevision) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"CancelSubscription\",\n ...(expectedRevision === undefined ? {} : { expectedRevision }),\n schemaVersion: 1,\n scope,\n key,\n });\n\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n listDeliveries: (scope, key, after, limit) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"ListDeliveries\",\n schemaVersion: 1,\n scope,\n key,\n ...(after === undefined ? {} : { after }),\n ...(limit === undefined ? {} : { limit }),\n });\n\n if (response._tag === \"DeliveryPage\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n const intake = SubscriptionIntake.of({\n accept: (principal, source, payload) =>\n Effect.gen(function* () {\n const request = yield* Schema.decodeUnknownEffect(AcceptRequest)({\n _tag: \"Accept\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n payload,\n }).pipe(\n Effect.mapError(() =>\n SubscriptionError.make({ reason: \"validation\", code: \"event-payload\" }),\n ),\n );\n\n const response = yield* call(request.partition, request);\n\n if (response._tag === \"Acknowledgement\") return response.value;\n const failure = failed(response);\n\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\n\n return yield* asProtocolError();\n }),\n status: (principal, source, eventId) =>\n Effect.gen(function* () {\n const response = yield* call(partition, {\n _tag: \"Status\",\n schemaVersion: 1,\n partition,\n principal,\n source,\n eventId,\n });\n\n if (response._tag === \"Status\") return response.value;\n const failure = failed(response);\n\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n });\n\n return Context.make(Subscriptions, subscriptions).pipe(\n Context.add(SubscriptionIntake, intake),\n );\n }),\n );\n }\n}\n\nexport class SubscriptionPartitionIdentity extends Context.Service<\n SubscriptionPartitionIdentity,\n { readonly partition: SourcePartition }\n>()(\"@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity\") {}\n\nconst decodePartitionName = Effect.fn(\"decodeSubscriptionPartitionName\")(function* (\n name: string | null | undefined,\n) {\n if (name === null || name === undefined) {\n return yield* SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition 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 SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition name is malformed\",\n }),\n ),\n );\n\n return yield* Schema.decodeUnknownEffect(SourcePartition)({\n tenantId: tuple[0],\n address: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n SubscriptionPartitionProtocolError.make({\n message: \"Subscription Partition identity is invalid\",\n }),\n ),\n );\n});\n\nconst samePartition = Schema.toEquivalence(SourcePartition);\n\nconst requestPartition = (request: SubscriptionPartitionRequest): SourcePartition =>\n request._tag === \"Accept\" || request._tag === \"Status\"\n ? request.partition\n : request.scope.partition;\n\nconst handleRequest = Effect.fn(\"SubscriptionPartition.handleRequest\")(function* (\n encoded: unknown,\n) {\n const decoded = yield* decodeRequest(encoded).pipe(Effect.result);\n\n if (decoded._tag === \"Failure\") {\n return yield* encodeResponse(\n protocolFailure(\"The subscription request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { partition } = yield* SubscriptionPartitionIdentity;\n\n if (!samePartition(partition, requestPartition(request))) {\n return yield* encodeResponse(\n protocolFailure(\"The request partition does not match the addressed object\"),\n ).pipe(Effect.orDie);\n }\n const subscriptions = yield* Subscriptions;\n const intake = yield* SubscriptionIntake;\n\n const response = yield* Effect.gen(function* (): Effect.fn.Return<\n SubscriptionPartitionResponse,\n SubscriptionPartitionFailure\n > {\n switch (request._tag) {\n case \"GetSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.getSubscription(request.scope, request.key),\n };\n case \"Subscribe\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.subscribe(request.scope, request.options),\n };\n case \"UpdateSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.updateSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n request.options,\n ),\n };\n case \"RecoverSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.recoverSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"PauseSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.pauseSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ResumeSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.resumeSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"ListSubscriptions\":\n return {\n _tag: \"SubscriptionPage\",\n value: yield* subscriptions.listSubscriptions(\n request.scope,\n request.after,\n request.limit,\n ),\n };\n case \"CancelSubscription\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.cancelSubscription(\n request.scope,\n request.key,\n request.expectedRevision,\n ),\n };\n case \"RecoverDelivery\":\n return {\n _tag: \"DeliverySnapshot\",\n value: yield* subscriptions.recoverDelivery(\n request.scope,\n request.key,\n request.expectedGeneration,\n ),\n };\n case \"ListDeliveries\":\n return {\n _tag: \"DeliveryPage\",\n value: yield* subscriptions.listDeliveries(\n request.scope,\n request.key,\n request.after,\n request.limit,\n ),\n };\n case \"Accept\":\n return {\n _tag: \"Acknowledgement\",\n value: yield* intake.accept(request.principal, request.source, request.payload),\n };\n case \"Status\":\n return {\n _tag: \"Status\",\n value: yield* intake.status(request.principal, request.source, request.eventId),\n };\n }\n }).pipe(\n Effect.catch((failure) =>\n Schema.is(SubscriptionPartitionFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(protocolFailure(\"The subscription operation failed outside its contract\")),\n ),\n );\n\n return yield* encodeResponse(response).pipe(Effect.orDie);\n});\n\nconst alarmStorageError = (code: string) => () => storageFailure(code);\n\nconst transactionLayer: Layer.Layer<\n DoSubscriptionTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoSubscriptionTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n\n return DoSubscriptionTransaction.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: SUBSCRIPTION_ALARM_ID, tag: SUBSCRIPTION_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel-subscription-alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-alarm-deadline\")),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SUBSCRIPTION_ALARM_ID,\n tag: SUBSCRIPTION_ALARM_TAG,\n runAt,\n payload: { schemaVersion: 1, generation: replacement.generation },\n })\n .pipe(Effect.mapError(alarmStorageError(\"schedule-subscription-alarm\"))),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n storageFailure(\"commit-subscription-transaction\"),\n ),\n );\n }),\n });\n }),\n);\n\nconst alarmHandler = (limits: SubscriptionLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SUBSCRIPTION_ALARM_TAG) {\n const { handlers } = yield* SubscriptionPartitionAlarmExtension;\n const matches = handlers.filter((handler) => handler.tag === event.tag);\n const handler = matches[0];\n\n if (\n event.tag.startsWith(\"effect-agent/\") ||\n matches.length !== 1 ||\n handler === undefined\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Unknown or ambiguous ancillary alarm tag\",\n });\n\n return yield* handler.handle(event).pipe(\n Effect.scoped,\n Effect.timeout(MAX_ANCILLARY_ALARM_MILLIS),\n Effect.catchTag(\"TimeoutError\", () =>\n SubscriptionAlarmExtensionError.make({ code: \"timeout\" }),\n ),\n );\n }\n if (event.id !== SUBSCRIPTION_ALARM_ID) {\n return yield* SubscriptionAlarmProtocolError.make({\n message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n SubscriptionAlarmProtocolError.make({\n message: \"Unsupported subscription alarm payload\",\n }),\n ),\n );\n const driver = yield* SubscriptionDriver;\n const alarmControl = yield* DoSubscriptionAlarmControl;\n\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n\n const pass = yield* driver.runDue.pipe(\n Effect.catchCause((cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.failCause(cause)\n : Clock.currentTimeMillis.pipe(\n Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)),\n Effect.andThen(Effect.failCause(cause)),\n ),\n ),\n );\n\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n {\n mode: \"isolated\",\n limit: MAX_ALARMS_PER_INVOCATION,\n retryFailedAfter: limits.retryMillis,\n onFailure: () => Effect.logWarning(\"Subscription partition alarm retained for retry\"),\n },\n ).pipe(Effect.asVoid);\n\ntype SubscriptionRuntimeServices =\n | Subscriptions\n | SubscriptionIntake\n | SubscriptionDriver\n | DoSubscriptionAlarmControl\n | SubscriptionPartitionIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nexport interface SubscriptionPartitionObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, SubscriptionRuntimeServices>\n> {\n subscription(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface SubscriptionPartitionObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): SubscriptionPartitionObjectInstance;\n}\n\n/**\n * Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source\n * catalog and authority. It must not retain cleanup-scoped resources across RPC events.\n */\nexport const makeSubscriptionPartitionObjectClass = <E>(\n host: Layer.Layer<\n SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace,\n E,\n | EffectCfDurableObjectState.DurableObjectState\n | WorkerEnvironment\n | SubscriptionPartitionIdentity\n >,\n limits: SubscriptionLimits = defaultSubscriptionLimits,\n): SubscriptionPartitionObjectClass => {\n const cloudflareLimitsLayer = Layer.effectDiscard(validateCloudflareSubscriptionLimits(limits));\n\n const identityLayer = Layer.effect(\n SubscriptionPartitionIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n\n return SubscriptionPartitionIdentity.of({\n partition: yield* decodePartitionName(state.raw.id.name),\n });\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 partitionStore = Layer.unwrap(\n Effect.map(SubscriptionPartitionIdentity, ({ partition }) =>\n doSubscriptionStoreLayer(partition).pipe(\n Layer.provide(transactionLayer),\n Layer.provide(sqlLayer),\n ),\n ),\n );\n\n const application = Layer.mergeAll(\n Subscriptions.layer(limits),\n SubscriptionIntake.layer(limits),\n SubscriptionDriver.layer(limits),\n cloudflareLimitsLayer,\n // Capture the host reference before its scoped input Layer is hidden from the runtime.\n Layer.effect(\n SubscriptionPartitionAlarmExtension,\n Effect.gen(function* () {\n const extension = yield* SubscriptionPartitionAlarmExtension;\n const tags = extension.handlers.map((handler) => handler.tag);\n\n if (\n tags.length > MAX_ALARMS_PER_INVOCATION ||\n new Set(tags).size !== tags.length ||\n tags.some(\n (tag) => tag.length === 0 || tag.length > 128 || tag.startsWith(\"effect-agent/\"),\n )\n )\n return yield* SubscriptionAlarmProtocolError.make({\n message: \"Invalid ancillary alarm handler registry\",\n });\n\n yield* validateCloudflareSubscriptionLimits(limits, { ancillaryAlarms: tags.length > 0 });\n\n return extension;\n }),\n ),\n ).pipe(\n Layer.provideMerge(partitionStore),\n Layer.provide(\n cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer)),\n ),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(identityLayer),\n );\n\n const runtime: Layer.Layer<\n SubscriptionRuntimeServices,\n | E\n | SubscriptionError\n | SubscriptionPartitionProtocolError\n | CloudflareSubscriptionConfigError\n | SubscriptionAlarmProtocolError,\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 subscription: (encoded: unknown) => handleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<SubscriptionRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: alarmHandler(limits),\n });\n\n class SubscriptionPartitionObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n\n return SubscriptionPartitionObject;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,yBAAyB;AAC/B,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,4BAA4B;AAClC,MAAM,6BAA6B;AAEnC,MAAM,2BAA2B,OAAO,OAAO;CAC7C,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACtG,kCACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;;AAGH,IAAa,kCAAb,cAAqD,OAAO,YAA6C,CAAC,CACxG,mCACA,EAAE,MAAM,OAAO,eAAe,MAAM,OAAO,YAAY,GAAG,CAAC,EAAE,CAC/D,CAAC,CAAC,CAAC;;AAgBH,MAAa,sCAAsC,QAAQ,UAExD,yEAAyE,EAC1E,qBAAqB,EAAE,UAAU,CAAC,EAAE,GACtC,CAAC;;;;;;AAOD,MAAa,wCAAwC,OAAO,GAC1D,uCACF,CAAC,CAAC,WAA0C,SAqB1C;CACA,IACE,QAAQ,IAAI,WAAW,KACvB,QAAQ,IAAI,SAAS,OACrB,QAAQ,IAAI,WAAW,eAAe,KACtC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MAAM,QAAQ,IAAI,GAClB,MAAM,aAAa,aAAa,CAClC;CAEA,MAAM,UAQF,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,eAAe,YAAqB,cAAc,OAAO,EAKvD;EACF,QAAQ,aAAa,MAAM;CAC7B,CAAC;CAED,MAAM,oCAAoC,KAAK;EAC7C,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -182,13 +182,13 @@ declare const encodeUnknownResolutionCommand: (input: UnknownResolutionCommand,
|
|
|
182
182
|
readonly author: string;
|
|
183
183
|
readonly reason: string;
|
|
184
184
|
readonly resolution: {
|
|
185
|
+
readonly _tag: "SafeToRetry";
|
|
186
|
+
} | {
|
|
185
187
|
readonly _tag: "CompletedWithResult";
|
|
186
188
|
readonly result: Schema.Json;
|
|
187
189
|
readonly isFailure: boolean;
|
|
188
190
|
} | {
|
|
189
191
|
readonly _tag: "NeverHappened";
|
|
190
|
-
} | {
|
|
191
|
-
readonly _tag: "SafeToRetry";
|
|
192
192
|
} | {
|
|
193
193
|
readonly _tag: "AbortSubmission";
|
|
194
194
|
};
|
|
@@ -316,6 +316,14 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
316
316
|
readonly createdAt: string;
|
|
317
317
|
readonly deploymentId: string;
|
|
318
318
|
readonly payload: {
|
|
319
|
+
readonly _tag: "SubagentStarted";
|
|
320
|
+
readonly runId: string;
|
|
321
|
+
readonly toolCallId: string;
|
|
322
|
+
readonly childThreadId: string;
|
|
323
|
+
readonly childSubmissionId: string;
|
|
324
|
+
readonly childReceiptId: string;
|
|
325
|
+
readonly childRunId: string;
|
|
326
|
+
} | {
|
|
319
327
|
readonly _tag: "AbortRequested";
|
|
320
328
|
readonly submissionId: string;
|
|
321
329
|
readonly author: string;
|
|
@@ -549,14 +557,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
549
557
|
readonly resultBytes: number;
|
|
550
558
|
};
|
|
551
559
|
} | undefined;
|
|
552
|
-
} | {
|
|
553
|
-
readonly _tag: "SubagentStarted";
|
|
554
|
-
readonly runId: string;
|
|
555
|
-
readonly toolCallId: string;
|
|
556
|
-
readonly childThreadId: string;
|
|
557
|
-
readonly childSubmissionId: string;
|
|
558
|
-
readonly childReceiptId: string;
|
|
559
|
-
readonly childRunId: string;
|
|
560
560
|
} | {
|
|
561
561
|
readonly _tag: "SubagentJoined";
|
|
562
562
|
readonly runId: string;
|
|
@@ -628,13 +628,13 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
628
628
|
readonly author: string;
|
|
629
629
|
readonly reason: string;
|
|
630
630
|
readonly resolution: {
|
|
631
|
+
readonly _tag: "SafeToRetry";
|
|
632
|
+
} | {
|
|
631
633
|
readonly _tag: "CompletedWithResult";
|
|
632
634
|
readonly result: Schema.Json;
|
|
633
635
|
readonly isFailure: boolean;
|
|
634
636
|
} | {
|
|
635
637
|
readonly _tag: "NeverHappened";
|
|
636
|
-
} | {
|
|
637
|
-
readonly _tag: "SafeToRetry";
|
|
638
638
|
} | {
|
|
639
639
|
readonly _tag: "AbortSubmission";
|
|
640
640
|
};
|
|
@@ -687,6 +687,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
687
687
|
readonly threadId: string;
|
|
688
688
|
readonly actualEpoch: number;
|
|
689
689
|
readonly attemptedEpoch: number;
|
|
690
|
+
} | {
|
|
691
|
+
readonly _tag: "DurableAlarmError";
|
|
692
|
+
readonly operation: string;
|
|
693
|
+
readonly message: string;
|
|
694
|
+
readonly cause?: Schema.Json | undefined;
|
|
690
695
|
} | {
|
|
691
696
|
readonly _tag: "HostProtocolError";
|
|
692
697
|
readonly message: string;
|
|
@@ -714,11 +719,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
714
719
|
readonly limit: "database-bytes" | "input-bytes" | "queue-depth";
|
|
715
720
|
readonly actual: number;
|
|
716
721
|
readonly maximum: number;
|
|
717
|
-
} | {
|
|
718
|
-
readonly _tag: "DurableAlarmError";
|
|
719
|
-
readonly operation: string;
|
|
720
|
-
readonly message: string;
|
|
721
|
-
readonly cause?: Schema.Json | undefined;
|
|
722
722
|
} | {
|
|
723
723
|
readonly _tag: "OperationDenied";
|
|
724
724
|
readonly operation: "abort" | "awaitSettlement" | "explain" | "observe" | "resolveApproval" | "resolveUnknown" | "retry" | "scanObligations" | "verify" | "wake";
|
|
@@ -286,13 +286,13 @@ declare const encodeAdminResponse: (input: AdminFailed | ExplainedRecovery | Obl
|
|
|
286
286
|
readonly author: string;
|
|
287
287
|
readonly reason: string;
|
|
288
288
|
readonly resolution: {
|
|
289
|
-
readonly _tag: "SafeToRetry";
|
|
290
|
-
} | {
|
|
291
289
|
readonly _tag: "CompletedWithResult";
|
|
292
290
|
readonly result: Schema.Json;
|
|
293
291
|
readonly isFailure: boolean;
|
|
294
292
|
} | {
|
|
295
293
|
readonly _tag: "NeverHappened";
|
|
294
|
+
} | {
|
|
295
|
+
readonly _tag: "SafeToRetry";
|
|
296
296
|
} | {
|
|
297
297
|
readonly _tag: "AbortSubmission";
|
|
298
298
|
};
|
|
@@ -737,4 +737,4 @@ interface Class<EventServices = never> {
|
|
|
737
737
|
declare const make: <ApplicationServices, ApplicationError, EventServices = never, EventLayerError = never>(applicationLayer: Layer.Layer<CloudflareDurableRuntimeServices | ApplicationServices, ApplicationError, CloudflareBootstrapServices | DurableObjectState$1.DurableObjectState | WorkerEnvironment | DurableObjectContext | ThreadObjectNamespace>, options: Options<ApplicationServices, EventServices, EventLayerError>) => Class<ApplicationServices | EventServices>;
|
|
738
738
|
//#endregion
|
|
739
739
|
export { CloudflareDurableRuntimeOptions as C, layerConfig as E, CloudflareDurableRuntimeInitializationError as S, layer as T, decodeObligationThresholds as _, AdminVerifyRequest as a, make as b, Instance as c, RetryExecuted as d, ThreadObject_d_exports as f, decodeAdminVerifyRequest as g, decodeAdminResponse as h, AdminResponse as i, ObligationsScanned as l, decodeAdminExplainRequest as m, AdminFailed as n, Class as o, VerifiedIntegrity as p, AdminFailure as r, ExplainedRecovery as s, AdminExplainRequest as t, Options as u, decodeRetryCommand as v, CloudflareDurableRuntimeServices as w, CloudflareBootstrapServices as x, encodeAdminResponse as y };
|
|
740
|
-
//# sourceMappingURL=ThreadObject-
|
|
740
|
+
//# sourceMappingURL=ThreadObject-BSRVxtPI.d.mts.map
|
package/dist/ThreadObject.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { C as CloudflareDurableRuntimeOptions, E as layerConfig, S as CloudflareDurableRuntimeInitializationError, T as layer, _ as decodeObligationThresholds, a as AdminVerifyRequest, b as make, c as Instance, d as RetryExecuted, g as decodeAdminVerifyRequest, h as decodeAdminResponse, i as AdminResponse, l as ObligationsScanned, m as decodeAdminExplainRequest, n as AdminFailed, o as Class, p as VerifiedIntegrity, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeRetryCommand, w as CloudflareDurableRuntimeServices, x as CloudflareBootstrapServices, y as encodeAdminResponse } from "./ThreadObject-
|
|
1
|
+
import { C as CloudflareDurableRuntimeOptions, E as layerConfig, S as CloudflareDurableRuntimeInitializationError, T as layer, _ as decodeObligationThresholds, a as AdminVerifyRequest, b as make, c as Instance, d as RetryExecuted, g as decodeAdminVerifyRequest, h as decodeAdminResponse, i as AdminResponse, l as ObligationsScanned, m as decodeAdminExplainRequest, n as AdminFailed, o as Class, p as VerifiedIntegrity, r as AdminFailure, s as ExplainedRecovery, t as AdminExplainRequest, u as Options, v as decodeRetryCommand, w as CloudflareDurableRuntimeServices, x as CloudflareBootstrapServices, y as encodeAdminResponse } from "./ThreadObject-BSRVxtPI.mjs";
|
|
2
2
|
export { AdminExplainRequest, AdminFailed, AdminFailure, AdminResponse, AdminVerifyRequest, type CloudflareBootstrapServices as BootstrapServices, Class, ExplainedRecovery, type CloudflareDurableRuntimeInitializationError as InitializationError, Instance, ObligationsScanned, Options, RetryExecuted, type CloudflareDurableRuntimeOptions as RuntimeOptions, type CloudflareDurableRuntimeServices as Services, VerifiedIntegrity, decodeAdminExplainRequest, decodeAdminResponse, decodeAdminVerifyRequest, decodeObligationThresholds, decodeRetryCommand, encodeAdminResponse, layer, layerConfig, make };
|
package/dist/index.d.mts
CHANGED
|
@@ -7,6 +7,6 @@ import { t as CloudflareMemory_d_exports } from "./CloudflareMemory.mjs";
|
|
|
7
7
|
import { t as CloudflareScheduling_d_exports } from "./CloudflareScheduling.mjs";
|
|
8
8
|
import { t as CloudflareSubscriptions_d_exports } from "./CloudflareSubscriptions.mjs";
|
|
9
9
|
import { t as CloudflareThreadClient_d_exports } from "./CloudflareThreadClient.mjs";
|
|
10
|
-
import { f as ThreadObject_d_exports } from "./ThreadObject-
|
|
10
|
+
import { f as ThreadObject_d_exports } from "./ThreadObject-BSRVxtPI.mjs";
|
|
11
11
|
import { t as WakeScheduler_d_exports } from "./WakeScheduler.mjs";
|
|
12
12
|
export { Alarm_d_exports as Alarm, CloudflareBindings_d_exports as CloudflareBindings, CloudflareBrowser_d_exports as CloudflareBrowser, CloudflareCodeMode_d_exports as CloudflareCodeMode, CloudflareConfig_d_exports as CloudflareConfig, CloudflareMemory_d_exports as CloudflareMemory, CloudflareScheduling_d_exports as CloudflareScheduling, CloudflareSubscriptions_d_exports as CloudflareSubscriptions, CloudflareThreadClient_d_exports as CloudflareThreadClient, ThreadObject_d_exports as ThreadObject, WakeScheduler_d_exports as WakeScheduler };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@effect-agent/platform-cloudflare","version":"0.1.0-beta.52","dependencies":{"@effect-agent/core":"0.1.0-beta.52","@effect-agent/engine":"0.1.0-beta.52","@effect-agent/sandbox":"0.1.0-beta.52","@effect-agent/storage-cloudflare":"0.1.0-beta.52","@effect-agent/thread":"0.1.0-beta.52","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/puppeteer":"1.1.0","@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/capabilities":"0.1.0-beta.52","@effect-agent/testing":"0.1.0-beta.52","@effect/platform-node":"4.0.0-rc.112","@effect/sql-d1":"4.0.0-rc.112","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","effect-cf":"0.40.0","esbuild":"0.28.1","miniflare":"5.20260811.1-alpha","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"@cloudflare/puppeteer":"^1.1.0","effect":"^4.0.0-rc.112","effect-cf":"^0.40.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./Alarm":{"types":"./dist/Alarm.d.mts","default":"./dist/Alarm.mjs"},"./BrowserRestCapture":{"types":"./dist/BrowserRestCapture.d.mts","default":"./dist/BrowserRestCapture.mjs"},"./BrowserRestCrawl":{"types":"./dist/BrowserRestCrawl.d.mts","default":"./dist/BrowserRestCrawl.mjs"},"./CloudflareBindings":{"types":"./dist/CloudflareBindings.d.mts","default":"./dist/CloudflareBindings.mjs"},"./CloudflareBrowser":{"types":"./dist/CloudflareBrowser.d.mts","default":"./dist/CloudflareBrowser.mjs"},"./CloudflareCodeMode":{"types":"./dist/CloudflareCodeMode.d.mts","default":"./dist/CloudflareCodeMode.mjs"},"./CloudflareConfig":{"types":"./dist/CloudflareConfig.d.mts","default":"./dist/CloudflareConfig.mjs"},"./CloudflareMemory":{"types":"./dist/CloudflareMemory.d.mts","default":"./dist/CloudflareMemory.mjs"},"./CloudflareScheduling":{"types":"./dist/CloudflareScheduling.d.mts","default":"./dist/CloudflareScheduling.mjs"},"./CloudflareSubscriptions":{"types":"./dist/CloudflareSubscriptions.d.mts","default":"./dist/CloudflareSubscriptions.mjs"},"./CloudflareThreadClient":{"types":"./dist/CloudflareThreadClient.d.mts","default":"./dist/CloudflareThreadClient.mjs"},"./InteractiveBrowser":{"types":"./dist/InteractiveBrowser.d.mts","default":"./dist/InteractiveBrowser.mjs"},"./ProtectedBrowser":{"types":"./dist/ProtectedBrowser.d.mts","default":"./dist/ProtectedBrowser.mjs"},"./ThreadObject":{"types":"./dist/ThreadObject.d.mts","default":"./dist/ThreadObject.mjs"},"./WakeScheduler":{"types":"./dist/WakeScheduler.d.mts","default":"./dist/WakeScheduler.mjs"}},"description":"Cloudflare Layer assembly for Effect Agent: Durable Objects and Browser Run adapters.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/platform-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"},"peerDependenciesMeta":{"@cloudflare/puppeteer":{"optional":true}}}
|
|
@@ -65,11 +65,17 @@ export class SubscriptionAlarmExtensionError extends Schema.TaggedError<Subscrip
|
|
|
65
65
|
{ code: Schema.NonEmptyString.check(Schema.isMaxLength(128)) },
|
|
66
66
|
) {}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
/** Native partition services supplied at alarm invocation, after the host Layer is built. */
|
|
69
|
+
export type SubscriptionPartitionAlarmServices =
|
|
70
|
+
| Subscriptions
|
|
71
|
+
| SubscriptionIntake
|
|
72
|
+
| SubscriptionDriver;
|
|
73
|
+
|
|
74
|
+
export interface SubscriptionPartitionAlarmHandler<R = SubscriptionPartitionAlarmServices> {
|
|
69
75
|
readonly tag: string;
|
|
70
76
|
readonly handle: (
|
|
71
77
|
event: DurableObjectAlarm.DurableObjectAlarmEvent,
|
|
72
|
-
) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError>;
|
|
78
|
+
) => Effect.Effect<void, SubscriptionAlarmProtocolError | SubscriptionAlarmExtensionError, R>;
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
/** Host-only handlers; the framework reserves its namespace and rejects every unknown tag. */
|
|
@@ -79,7 +85,8 @@ export const SubscriptionPartitionAlarmExtension = Context.Reference<{
|
|
|
79
85
|
defaultValue: () => ({ handlers: [] }),
|
|
80
86
|
});
|
|
81
87
|
|
|
82
|
-
/** Capture host services once
|
|
88
|
+
/** Capture host services once, deferring native partition services to invocation.
|
|
89
|
+
* Each invocation owns its codec/handler Scope and timeout.
|
|
83
90
|
* Callback failures stay typed. Defects and interruption reach the native alarm multiplexer.
|
|
84
91
|
* The host owns durable idempotency, prearming and external-effect uncertainty.
|
|
85
92
|
*/
|
|
@@ -95,9 +102,17 @@ export const makeSubscriptionPartitionAlarmHandler = Effect.fn(
|
|
|
95
102
|
},
|
|
96
103
|
) => Effect.Effect<void, SubscriptionAlarmExtensionError, R>;
|
|
97
104
|
}): Effect.fn.Return<
|
|
98
|
-
SubscriptionPartitionAlarmHandler
|
|
105
|
+
SubscriptionPartitionAlarmHandler<
|
|
106
|
+
Exclude<
|
|
107
|
+
Exclude<R | Payload["DecodingServices"], Scope.Scope>,
|
|
108
|
+
Exclude<
|
|
109
|
+
Exclude<R | Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>,
|
|
110
|
+
SubscriptionPartitionAlarmServices
|
|
111
|
+
>
|
|
112
|
+
>
|
|
113
|
+
>,
|
|
99
114
|
SubscriptionAlarmProtocolError,
|
|
100
|
-
Exclude<R | Payload["DecodingServices"], Scope.Scope>
|
|
115
|
+
Exclude<R | Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>
|
|
101
116
|
> {
|
|
102
117
|
if (
|
|
103
118
|
options.tag.length === 0 ||
|
|
@@ -110,7 +125,11 @@ export const makeSubscriptionPartitionAlarmHandler = Effect.fn(
|
|
|
110
125
|
return yield* SubscriptionAlarmProtocolError.make({
|
|
111
126
|
message: "Invalid ancillary alarm tag or timeout",
|
|
112
127
|
});
|
|
113
|
-
|
|
128
|
+
|
|
129
|
+
// Context capture includes unrequested services too; never retain a host override of native work.
|
|
130
|
+
const services = (yield* Effect.context<
|
|
131
|
+
Exclude<R | Payload["DecodingServices"], Scope.Scope | SubscriptionPartitionAlarmServices>
|
|
132
|
+
>()).pipe(Context.omit(Subscriptions, SubscriptionIntake, SubscriptionDriver));
|
|
114
133
|
|
|
115
134
|
return {
|
|
116
135
|
tag: options.tag,
|