@effect-agent/platform-cloudflare 0.1.0-beta.51 → 0.1.0-beta.53
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/Alarm.d.mts +45 -6
- package/dist/Alarm.mjs +111 -47
- package/dist/Alarm.mjs.map +1 -1
- 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 +24 -24
- package/dist/ProtectedBrowser.d.mts +5 -3
- package/dist/ProtectedBrowser.mjs +180 -36
- package/dist/ProtectedBrowser.mjs.map +1 -1
- package/dist/{ThreadObject-BY8axaWT.mjs → ThreadObject-OuKI0mBU.mjs} +33 -6
- package/dist/ThreadObject-OuKI0mBU.mjs.map +1 -0
- package/dist/{ThreadObject-sDr1JBCj.d.mts → ThreadObject-d-ui3RZ-.d.mts} +26 -15
- package/dist/ThreadObject.d.mts +2 -2
- package/dist/ThreadObject.mjs +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/Alarm.ts +242 -72
- package/src/CloudflareSubscriptions.ts +25 -6
- package/src/ThreadObject.ts +1 -0
- package/src/internal/layers.ts +93 -9
- package/src/protected-browser/binding.ts +2 -1
- package/src/protected-browser/inspect-frame.ts +62 -19
- package/src/protected-browser/native.ts +50 -5
- package/src/protected-browser/policy.ts +138 -13
- package/dist/ThreadObject-BY8axaWT.mjs.map +0 -1
|
@@ -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);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C;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,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,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"}
|
|
@@ -316,11 +316,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
316
316
|
readonly createdAt: string;
|
|
317
317
|
readonly deploymentId: string;
|
|
318
318
|
readonly payload: {
|
|
319
|
-
readonly _tag: "AbortRequested";
|
|
320
|
-
readonly submissionId: string;
|
|
321
|
-
readonly author: string;
|
|
322
|
-
readonly reason: string;
|
|
323
|
-
} | {
|
|
324
319
|
readonly _tag: "ThreadCreated";
|
|
325
320
|
readonly agentId: string;
|
|
326
321
|
readonly definitions: {
|
|
@@ -458,6 +453,11 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
458
453
|
readonly runDisposition?: Schema.Json | undefined;
|
|
459
454
|
readonly finishReason?: "budget-exhausted" | undefined;
|
|
460
455
|
readonly exhausted?: "tokens" | "tool-calls" | "turns" | undefined;
|
|
456
|
+
} | {
|
|
457
|
+
readonly _tag: "AbortRequested";
|
|
458
|
+
readonly submissionId: string;
|
|
459
|
+
readonly author: string;
|
|
460
|
+
readonly reason: string;
|
|
461
461
|
} | {
|
|
462
462
|
readonly _tag: "SubmissionSettled";
|
|
463
463
|
readonly submissionId: string;
|
|
@@ -644,6 +644,16 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
644
644
|
} | {
|
|
645
645
|
readonly _tag: "HostFailed";
|
|
646
646
|
readonly failure: {
|
|
647
|
+
readonly _tag: "HostProtocolError";
|
|
648
|
+
readonly message: string;
|
|
649
|
+
} | {
|
|
650
|
+
readonly _tag: "AgentInputError";
|
|
651
|
+
readonly message: string;
|
|
652
|
+
} | {
|
|
653
|
+
readonly _tag: "DigestError";
|
|
654
|
+
readonly message: string;
|
|
655
|
+
readonly cause?: Schema.Json | undefined;
|
|
656
|
+
} | {
|
|
647
657
|
readonly _tag: "AdmissionConflict";
|
|
648
658
|
readonly threadId: string;
|
|
649
659
|
readonly principal: string;
|
|
@@ -658,6 +668,15 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
658
668
|
readonly _tag: "SettlementConflict";
|
|
659
669
|
readonly submissionId: string;
|
|
660
670
|
readonly existingOutcome: "aborted" | "completed" | "failed";
|
|
671
|
+
} | {
|
|
672
|
+
readonly _tag: "ApprovalConflict";
|
|
673
|
+
readonly submissionId: string;
|
|
674
|
+
readonly toolCallId: string;
|
|
675
|
+
readonly existingDecision: "approved" | "denied";
|
|
676
|
+
} | {
|
|
677
|
+
readonly _tag: "UnknownResolutionConflict";
|
|
678
|
+
readonly submissionId: string;
|
|
679
|
+
readonly toolCallId: string;
|
|
661
680
|
} | {
|
|
662
681
|
readonly _tag: "JoinedToHost";
|
|
663
682
|
readonly submissionId: string;
|
|
@@ -687,25 +706,6 @@ declare const encodeHostResponse: (input: AbortRecorded | ApprovalRecorded | Hos
|
|
|
687
706
|
readonly threadId: string;
|
|
688
707
|
readonly actualEpoch: number;
|
|
689
708
|
readonly attemptedEpoch: number;
|
|
690
|
-
} | {
|
|
691
|
-
readonly _tag: "HostProtocolError";
|
|
692
|
-
readonly message: string;
|
|
693
|
-
} | {
|
|
694
|
-
readonly _tag: "AgentInputError";
|
|
695
|
-
readonly message: string;
|
|
696
|
-
} | {
|
|
697
|
-
readonly _tag: "DigestError";
|
|
698
|
-
readonly message: string;
|
|
699
|
-
readonly cause?: Schema.Json | undefined;
|
|
700
|
-
} | {
|
|
701
|
-
readonly _tag: "ApprovalConflict";
|
|
702
|
-
readonly submissionId: string;
|
|
703
|
-
readonly toolCallId: string;
|
|
704
|
-
readonly existingDecision: "approved" | "denied";
|
|
705
|
-
} | {
|
|
706
|
-
readonly _tag: "UnknownResolutionConflict";
|
|
707
|
-
readonly submissionId: string;
|
|
708
|
-
readonly toolCallId: string;
|
|
709
709
|
} | {
|
|
710
710
|
readonly _tag: "DurableRuntimeFailpointError";
|
|
711
711
|
readonly location: "abort:after-intent" | "approval:after-request-append" | "approval:after-suspend" | "claim:after-claim" | "compaction:after-canonical-append" | "compaction:before-canonical-append" | "input:after-canonical-append" | "join:after-canonical-append" | "join:after-claim" | "policy:after-reservation-append" | "policy:before-reservation-append" | "resolve:after-intent" | "run:after-start-append" | "run:before-start-append" | "step:after-step-append" | "subagent:after-admit" | "subagent:after-child-abort-intent" | "subagent:after-child-ready" | "subagent:after-join-append" | "subagent:after-release" | "subagent:after-release-pending" | "subagent:after-request-append" | "subagent:after-reserve" | "subagent:after-sibling-settle" | "subagent:after-start-append" | "subagent:after-suspend" | "submit:after-admit" | "submit:after-materialize" | "terminalize:after-canonical-append" | "terminalize:after-reserve" | "tools:after-prepared-append" | "tools:before-prepared-append" | "turn:after-canonical-append" | "turn:after-response-append" | "turn:after-results-append";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as BrowserRunSessionLifecycle } from "./browser-session-lifecycle-DJpqLXy_.mjs";
|
|
2
2
|
import { Context, Crypto, Effect, Layer, Redacted, Schema, Scope } from "effect";
|
|
3
3
|
import { InteractiveBrowserPolicy } from "@effect-agent/sandbox/InteractiveBrowser";
|
|
4
|
-
import { CredentialFieldRole, ProtectedBrowser, ProtectedBrowserControl, ProtectedBrowserError, ProtectedCleanup } from "@effect-agent/sandbox/ProtectedBrowser";
|
|
4
|
+
import { CredentialFieldRole, CredentialOrigin, ProtectedBrowser, ProtectedBrowserControl, ProtectedBrowserError, ProtectedCleanup } from "@effect-agent/sandbox/ProtectedBrowser";
|
|
5
5
|
//#region src/protected-browser/policy.d.ts
|
|
6
6
|
declare const ProtectedTransportError_base: Schema.Class<ProtectedTransportError, Schema.TaggedStruct<"ProtectedTransportError", {
|
|
7
7
|
readonly reason: Schema.Literals<readonly ["stale-reference", "needs-attention", "unsupported", "provider"]>;
|
|
@@ -14,12 +14,14 @@ declare const ProtectedBrowserDispatch_base: Context.ServiceClass<ProtectedBrows
|
|
|
14
14
|
declare class ProtectedBrowserDispatch extends ProtectedBrowserDispatch_base {}
|
|
15
15
|
/** Decoded adapter boundary. SDK exceptions and page diagnostics never cross this port. */
|
|
16
16
|
interface ProtectedBrowserTransport {
|
|
17
|
+
/** Select observation/target origins; undefined restores all network-permitted HTTPS frames. */
|
|
18
|
+
readonly restrictObservation: (origins: ReadonlyArray<typeof CredentialOrigin.Type> | undefined) => Effect.Effect<void, ProtectedTransportError>;
|
|
17
19
|
readonly context: Effect.Effect<typeof ProtectedPageContext.Type, ProtectedTransportError>;
|
|
18
20
|
readonly discover: Effect.Effect<typeof ProtectedDiscovery.Type, ProtectedTransportError>;
|
|
19
21
|
readonly target: (ref: string) => Effect.Effect<ProtectedBrowserControl, ProtectedTransportError>;
|
|
20
22
|
readonly navigate: (url: string) => Effect.Effect<void, ProtectedTransportError>;
|
|
21
23
|
readonly click: (ref: string) => Effect.Effect<void, ProtectedTransportError>;
|
|
22
|
-
readonly fill: (ref: string, role: typeof CredentialFieldRole.Type, value: Redacted.Redacted<string>) => Effect.Effect<void, ProtectedTransportError, ProtectedBrowserDispatch>;
|
|
24
|
+
readonly fill: (ref: string, role: typeof CredentialFieldRole.Type | "text" | "select", value: Redacted.Redacted<string>) => Effect.Effect<void, ProtectedTransportError, ProtectedBrowserDispatch>;
|
|
23
25
|
/** Invalidates local references synchronously before bounded exact-session cleanup. */
|
|
24
26
|
readonly invalidate: () => void;
|
|
25
27
|
readonly close: Effect.Effect<typeof ProtectedCleanup.Type>;
|
|
@@ -44,7 +46,7 @@ declare const ProtectedDiscovery: Schema.Struct<{
|
|
|
44
46
|
}>;
|
|
45
47
|
/**
|
|
46
48
|
* Fresh private passes only. Account administrators and Browser Rendering token holders are
|
|
47
|
-
* trusted operators. No viewer, handoff, raw JavaScript, screenshot or plaintext
|
|
49
|
+
* trusted operators. No viewer, handoff, raw JavaScript, screenshot or plaintext credential API exists.
|
|
48
50
|
* Hosts explicitly authorize post-exposure observations for recipients they trust not to echo.
|
|
49
51
|
*/
|
|
50
52
|
declare const browserRunProtectedLayer: () => Layer.Layer<ProtectedBrowser, never, BrowserRunProtectedTransport | Crypto.Crypto>;
|