@effect-agent/platform-cloudflare 0.1.0-beta.38 → 0.1.0-beta.40
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/bindings-BrVEOkfe.d.mts +102 -0
- package/dist/browser-quick-action.d.mts +18 -1
- package/dist/browser-quick-action.mjs +14 -1
- package/dist/browser-quick-action.mjs.map +1 -1
- package/dist/browser-rest-capture.d.mts +17 -2
- package/dist/browser-rest-capture.mjs +12 -1
- package/dist/browser-rest-capture.mjs.map +1 -1
- package/dist/browser-rest-crawl.mjs +2 -2
- package/dist/browser-rest-crawl.mjs.map +1 -1
- package/dist/index.d.mts +245 -237
- package/dist/index.mjs +168 -164
- package/dist/index.mjs.map +1 -1
- package/dist/interactive-browser.d.mts +160 -2
- package/dist/interactive-browser.mjs +1166 -2
- package/dist/interactive-browser.mjs.map +1 -0
- package/dist/{scheduling-B-OFqoS9.mjs → prepared-admission-BKp_Upw2.mjs} +134 -433
- package/dist/prepared-admission-BKp_Upw2.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/scheduling.d.mts +47 -2
- package/dist/scheduling.mjs +339 -1
- package/dist/scheduling.mjs.map +1 -0
- package/dist/subscriptions.d.mts +52 -0
- package/dist/subscriptions.mjs +346 -0
- package/dist/subscriptions.mjs.map +1 -0
- package/package.json +20 -13
- package/src/alarm.ts +264 -265
- package/src/bindings.ts +34 -30
- package/src/browser-quick-action.ts +31 -0
- package/src/browser-rest-capture.ts +27 -0
- package/src/client.ts +111 -105
- package/src/code-mode-executor.ts +19 -0
- package/src/config.ts +7 -7
- package/src/index.ts +10 -11
- package/src/interactive-browser.ts +29 -1
- package/src/layers.ts +178 -257
- package/src/prepared-admission.ts +90 -0
- package/src/scheduling.ts +19 -55
- package/src/subscriptions.ts +661 -0
- package/src/{conversation-object.ts → thread-object.ts} +167 -136
- package/src/transport.ts +15 -15
- package/src/wake-scheduler.ts +17 -22
- package/dist/interactive-browser-BRo-Bfvb.d.mts +0 -144
- package/dist/interactive-browser-Cy5q-ldl.mjs +0 -1154
- package/dist/interactive-browser-Cy5q-ldl.mjs.map +0 -1
- package/dist/scheduling-B-OFqoS9.mjs.map +0 -1
- package/dist/scheduling-BJs_kHTx.d.mts +0 -142
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduling.mjs","names":["ScheduleScopeSchema","ScheduleSnapshotPageSchema","EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/scheduling.ts"],"sourcesContent":["import { AgentId } from \"@effect-agent/core\";\nimport {\n DoScheduleAlarmControl,\n DoScheduleTransaction,\n scheduleStoreLayer,\n} from \"@effect-agent/storage-cloudflare\";\nimport {\n DefinitionDigests,\n PersistedJson,\n type DurableSubmitAgent,\n ScheduleAuthorizationError,\n type ScheduleAuthorizer,\n ScheduleCapacityError,\n ScheduleConflict,\n ScheduleDestination,\n ScheduleFailpointError,\n ScheduleId,\n type SchedulingLimits,\n ScheduleNotFound,\n ScheduleOwner,\n type ScheduleScope,\n ScheduleScope as ScheduleScopeSchema,\n ScheduleSnapshot,\n ScheduleSnapshotPage as ScheduleSnapshotPageSchema,\n ScheduleStorageError,\n ScheduleTimingRequest,\n ScheduleValidationError,\n Scheduling,\n ScheduleDriver,\n type ScheduleManagementFailure,\n defaultSchedulingLimits,\n scheduleOwnerKey,\n ScheduleWakeNoop,\n} from \"@effect-agent/thread\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Clock, Context, DateTime, Effect, Layer, Schema } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport type { ThreadObjectNamespace } from \"./bindings.ts\";\nimport { CloudflareThreadClient } from \"./client.ts\";\nimport {\n cloudflarePreparedInputAdmissionLayer,\n cloudflareScheduledInputAdmissionLayer,\n} from \"./prepared-admission.ts\";\n\nconst SCHEDULE_ALARM_TAG = \"effect-agent/ScheduleOwnerWake\";\nconst SCHEDULE_ALARM_ID = \"driver\";\n\nconst ScheduleAlarmPayload = Schema.Struct({\n schemaVersion: Schema.Literal(1),\n generation: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nexport class ScheduleAlarmProtocolError extends Schema.TaggedError<ScheduleAlarmProtocolError>()(\n \"ScheduleAlarmProtocolError\",\n { message: Schema.String },\n) {}\n\nconst boundedProtocolMessage = (message: string): string =>\n message.length <= 4_096 ? message : `${message.slice(0, 4_093)}...`;\n\nexport class ScheduleOwnerProtocolError extends Schema.TaggedError<ScheduleOwnerProtocolError>()(\n \"ScheduleOwnerProtocolError\",\n { message: Schema.String.check(Schema.isMaxLength(4_096)) },\n) {}\n\nconst ScheduleMutationRequestFields = {\n schemaVersion: Schema.Literal(1),\n agentId: AgentId,\n input: PersistedJson,\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n timing: ScheduleTimingRequest,\n destination: ScheduleDestination,\n deliveryPrincipal: ScheduleScopeSchema.fields.principal,\n definitions: DefinitionDigests,\n};\n\nconst ScheduleCreateRequest = Schema.TaggedStruct(\"Create\", ScheduleMutationRequestFields);\n\nconst ScheduleUpdateRequest = Schema.TaggedStruct(\"Update\", {\n ...ScheduleMutationRequestFields,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleGetRequest = Schema.TaggedStruct(\"Get\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n});\n\nconst ScheduleListRequest = Schema.TaggedStruct(\"List\", {\n schemaVersion: Schema.Literal(1),\n scope: ScheduleScopeSchema,\n after: Schema.optionalKey(ScheduleId),\n limit: Schema.optionalKey(\n Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(100)),\n ),\n});\n\nconst ScheduleControlRequest = Schema.TaggedStruct(\"Control\", {\n schemaVersion: Schema.Literal(1),\n operation: Schema.Literals([\"pause\", \"resume\", \"cancel\"]),\n scope: ScheduleScopeSchema,\n scheduleId: ScheduleId,\n expectedRevision: Schema.Int.check(Schema.isGreaterThan(0)),\n});\n\nconst ScheduleOwnerRequest = Schema.Union([\n ScheduleCreateRequest,\n ScheduleUpdateRequest,\n ScheduleGetRequest,\n ScheduleListRequest,\n ScheduleControlRequest,\n]);\ntype ScheduleOwnerRequest = typeof ScheduleOwnerRequest.Type;\n\nconst ScheduleOwnerFailure = Schema.Union([\n ScheduleValidationError,\n ScheduleAuthorizationError,\n ScheduleConflict,\n ScheduleNotFound,\n ScheduleCapacityError,\n ScheduleStorageError,\n ScheduleFailpointError,\n ScheduleOwnerProtocolError,\n]);\ntype ScheduleOwnerFailure = typeof ScheduleOwnerFailure.Type;\n\nconst ScheduleOwnerResponse = Schema.Union([\n Schema.TaggedStruct(\"Snapshot\", { value: ScheduleSnapshot }),\n Schema.TaggedStruct(\"Page\", { value: ScheduleSnapshotPageSchema }),\n Schema.TaggedStruct(\"Failed\", { failure: ScheduleOwnerFailure }),\n]);\ntype ScheduleOwnerResponse = typeof ScheduleOwnerResponse.Type;\n\nconst decodeScheduleOwnerRequest = Schema.decodeUnknownEffect(ScheduleOwnerRequest);\nconst encodeScheduleOwnerRequest = Schema.encodeEffect(ScheduleOwnerRequest);\nconst decodeScheduleOwnerResponse = Schema.decodeUnknownEffect(ScheduleOwnerResponse);\nconst encodeScheduleOwnerResponse = Schema.encodeEffect(ScheduleOwnerResponse);\n\nconst scheduleProtocolFailure = (message: string): ScheduleOwnerResponse => ({\n _tag: \"Failed\",\n failure: ScheduleOwnerProtocolError.make({ message: boundedProtocolMessage(message) }),\n});\n\nexport interface ScheduleOwnerObjectRpc extends Rpc.DurableObjectBranded {\n schedule(encoded: unknown): Promise<unknown>;\n}\n\nexport class ScheduleOwnerNamespace extends Context.Service<\n ScheduleOwnerNamespace,\n { readonly namespace: DurableObjectNamespace<ScheduleOwnerObjectRpc> }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerNamespace\") {}\n\nconst passthroughAgent = (agentId: AgentId): DurableSubmitAgent<typeof PersistedJson> => ({\n definition: { id: agentId, input: PersistedJson },\n});\n\nconst requestOwner = (request: ScheduleOwnerRequest): ScheduleOwner => request.scope.owner;\n\n/** Provides the same authorized management service as NodeScheduling.layer. */\nexport class CloudflareSchedulingClient {\n static readonly layer: Layer.Layer<Scheduling, never, ScheduleOwnerNamespace> = Layer.effect(\n Scheduling,\n Effect.gen(function* () {\n const { namespace } = yield* ScheduleOwnerNamespace;\n\n const call = Effect.fn(\"CloudflareSchedulingClient.call\")(function* (\n owner: ScheduleOwner,\n request: ScheduleOwnerRequest,\n ): Effect.fn.Return<ScheduleOwnerResponse, ScheduleManagementFailure> {\n const encoded = yield* encodeScheduleOwnerRequest(request).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n const raw = yield* Effect.tryPromise({\n try: () => namespace.get(namespace.idFromName(scheduleOwnerKey(owner))).schedule(encoded),\n catch: () =>\n ScheduleStorageError.make({\n operation: \"call Schedule Owner\",\n reason: \"unavailable\",\n }),\n });\n const response = yield* decodeScheduleOwnerResponse(raw).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" }),\n ),\n );\n if (response._tag !== \"Failed\") return response;\n return yield* response.failure._tag === \"ScheduleOwnerProtocolError\"\n ? ScheduleStorageError.make({ operation: \"Schedule Owner protocol\", reason: \"corrupt\" })\n : response.failure;\n });\n\n const encodeInput = Effect.fn(\"CloudflareSchedulingClient.encodeInput\")(function* <\n InputSchema extends Schema.Top,\n >(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n ): Effect.fn.Return<PersistedJson, ScheduleValidationError, InputSchema[\"EncodingServices\"]> {\n const encoded = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Unable to encode Agent input\",\n }),\n ),\n );\n return yield* Schema.decodeUnknownEffect(PersistedJson)(encoded).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n });\n\n const create: Scheduling[\"Service\"][\"create\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n const response = yield* call(options.scope.owner, {\n _tag: \"Create\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const update: Scheduling[\"Service\"][\"update\"] = (agent, input, options) =>\n Effect.gen(function* () {\n const payload = yield* encodeInput(agent, input);\n const response = yield* call(options.scope.owner, {\n _tag: \"Update\",\n schemaVersion: 1,\n agentId: agent.definition.id,\n input: payload,\n ...options,\n });\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const get: Scheduling[\"Service\"][\"get\"] = (scope, scheduleId) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Get\",\n schemaVersion: 1,\n scope,\n scheduleId,\n });\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const list: Scheduling[\"Service\"][\"list\"] = (scope, options = {}) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"List\",\n schemaVersion: 1,\n scope,\n ...(options.after === undefined ? {} : { after: options.after }),\n ...(options.limit === undefined ? {} : { limit: options.limit }),\n });\n return response._tag === \"Page\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n const control = (\n operation: \"pause\" | \"resume\" | \"cancel\",\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) =>\n Effect.gen(function* () {\n const response = yield* call(scope.owner, {\n _tag: \"Control\",\n schemaVersion: 1,\n operation,\n scope,\n scheduleId,\n expectedRevision,\n });\n return response._tag === \"Snapshot\"\n ? response.value\n : yield* ScheduleStorageError.make({\n operation: \"Schedule Owner protocol\",\n reason: \"corrupt\",\n });\n });\n\n return Scheduling.of({\n create,\n update,\n get,\n list,\n pause: (scope, id, revision) => control(\"pause\", scope, id, revision),\n resume: (scope, id, revision) => control(\"resume\", scope, id, revision),\n cancel: (scope, id, revision) => control(\"cancel\", scope, id, revision),\n });\n }),\n );\n}\n\nexport class ScheduleOwnerIdentity extends Context.Service<\n ScheduleOwnerIdentity,\n { readonly owner: ScheduleOwner }\n>()(\"@effect-agent/platform-cloudflare/ScheduleOwnerIdentity\") {}\n\nconst decodeOwnerName = Effect.fn(\"decodeScheduleOwnerName\")(function* (\n name: string | null | undefined,\n): Effect.fn.Return<ScheduleOwner, ScheduleOwnerProtocolError> {\n if (name === null || name === undefined) {\n return yield* ScheduleOwnerProtocolError.make({\n message: \"Schedule Owner objects require an idFromName identity\",\n });\n }\n const tuple = yield* Schema.decodeUnknownEffect(\n Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])),\n )(name).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object name is malformed\" }),\n ),\n );\n return yield* Schema.decodeUnknownEffect(ScheduleOwner)({\n tenantId: tuple[0],\n ownerId: tuple[1],\n }).pipe(\n Effect.mapError(() =>\n ScheduleOwnerProtocolError.make({ message: \"Schedule Owner object identity is invalid\" }),\n ),\n );\n});\n\nconst alarmStorageError = (operation: string) => (error: { readonly _tag: string }) =>\n ScheduleStorageError.make({\n operation,\n reason: error._tag === \"StorageOperationError\" ? \"unavailable\" : \"corrupt\",\n });\n\nconst transactionLayer: Layer.Layer<\n DoScheduleTransaction,\n never,\n DurableObjectAlarm.DurableObjectAlarm\n> = Layer.effect(\n DoScheduleTransaction,\n Effect.gen(function* () {\n const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;\n return DoScheduleTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\n return yield* alarms\n .transaction((transaction) =>\n body((replacement) =>\n replacement.deadlineAtMillis === null\n ? transaction\n .cancelAlarm({ id: SCHEDULE_ALARM_ID, tag: SCHEDULE_ALARM_TAG })\n .pipe(Effect.mapError(alarmStorageError(\"cancel Schedule Owner alarm\")))\n : Effect.fromOption(\n DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1)),\n ).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({\n operation: \"validate Schedule Owner alarm deadline\",\n reason: \"corrupt\",\n }),\n ),\n Effect.flatMap((runAt) =>\n transaction\n .scheduleAlarm({\n id: SCHEDULE_ALARM_ID,\n tag: SCHEDULE_ALARM_TAG,\n runAt,\n payload: {\n schemaVersion: 1,\n generation: replacement.generation,\n },\n })\n .pipe(\n Effect.mapError(alarmStorageError(\"schedule Schedule Owner alarm\")),\n ),\n ),\n ),\n ),\n )\n .pipe(\n Effect.catchTag(\"StorageOperationError\", () =>\n ScheduleStorageError.make({\n operation: \"commit Schedule Owner transaction\",\n reason: \"unavailable\",\n }),\n ),\n );\n }),\n });\n }),\n);\n\ntype ScheduleRuntimeServices =\n | Scheduling\n | ScheduleDriver\n | DoScheduleAlarmControl\n | ScheduleOwnerIdentity\n | DurableObjectAlarm.DurableObjectAlarm;\n\nconst ensureOwner = (\n expected: ScheduleOwner,\n request: ScheduleOwnerRequest,\n): Effect.Effect<void, ScheduleOwnerProtocolError> => {\n const observed = requestOwner(request);\n return observed.tenantId === expected.tenantId && observed.ownerId === expected.ownerId\n ? Effect.void\n : Effect.fail(\n ScheduleOwnerProtocolError.make({\n message: \"The request owner does not match the addressed Schedule Owner object\",\n }),\n );\n};\n\nconst handleScheduleRequest = Effect.fn(\"ScheduleOwner.handleRequest\")(function* (\n encoded: unknown,\n): Effect.fn.Return<unknown, never, Scheduling | ScheduleOwnerIdentity> {\n const decoded = yield* decodeScheduleOwnerRequest(encoded).pipe(Effect.result);\n if (decoded._tag === \"Failure\") {\n return yield* encodeScheduleOwnerResponse(\n scheduleProtocolFailure(\"The Schedule request could not be decoded\"),\n ).pipe(Effect.orDie);\n }\n const request = decoded.success;\n const { owner } = yield* ScheduleOwnerIdentity;\n const scheduling = yield* Scheduling;\n const response = yield* Effect.gen(function* () {\n yield* ensureOwner(owner, request);\n switch (request._tag) {\n case \"Create\": {\n const value = yield* scheduling.create(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n });\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Update\": {\n const value = yield* scheduling.update(passthroughAgent(request.agentId), request.input, {\n scope: request.scope,\n scheduleId: request.scheduleId,\n timing: request.timing,\n destination: request.destination,\n deliveryPrincipal: request.deliveryPrincipal,\n definitions: request.definitions,\n expectedRevision: request.expectedRevision,\n });\n return { _tag: \"Snapshot\" as const, value };\n }\n case \"Get\":\n return {\n _tag: \"Snapshot\" as const,\n value: yield* scheduling.get(request.scope, request.scheduleId),\n };\n case \"List\":\n return {\n _tag: \"Page\" as const,\n value: yield* scheduling.list(request.scope, {\n ...(request.after === undefined ? {} : { after: request.after }),\n ...(request.limit === undefined ? {} : { limit: request.limit }),\n }),\n };\n case \"Control\": {\n const value =\n request.operation === \"pause\"\n ? yield* scheduling.pause(request.scope, request.scheduleId, request.expectedRevision)\n : request.operation === \"resume\"\n ? yield* scheduling.resume(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n )\n : yield* scheduling.cancel(\n request.scope,\n request.scheduleId,\n request.expectedRevision,\n );\n return { _tag: \"Snapshot\" as const, value };\n }\n }\n }).pipe(\n Effect.map((value): ScheduleOwnerResponse => value),\n Effect.catch((failure) =>\n Schema.is(ScheduleOwnerFailure)(failure)\n ? Effect.succeed({ _tag: \"Failed\" as const, failure })\n : Effect.succeed(\n scheduleProtocolFailure(\"The Schedule operation failed outside its public contract\"),\n ),\n ),\n );\n return yield* encodeScheduleOwnerResponse(response).pipe(Effect.orDie);\n});\n\nconst scheduleAlarmHandler = (limits: SchedulingLimits) =>\n DurableObjectAlarm.processDue(\n (event) =>\n Effect.gen(function* () {\n if (event.tag !== SCHEDULE_ALARM_TAG || event.id !== SCHEDULE_ALARM_ID) {\n return yield* ScheduleAlarmProtocolError.make({\n message: `Unsupported Schedule Owner alarm ${event.tag}/${event.id}`,\n });\n }\n yield* Schema.decodeUnknownEffect(ScheduleAlarmPayload)(event.payload).pipe(\n Effect.mapError(() =>\n ScheduleAlarmProtocolError.make({\n message: \"Unsupported Schedule Owner alarm payload version\",\n }),\n ),\n );\n const scheduling = yield* ScheduleDriver;\n const alarmControl = yield* DoScheduleAlarmControl;\n const { owner } = yield* ScheduleOwnerIdentity;\n const nowMillis = yield* Clock.currentTimeMillis;\n yield* alarmControl.prearm(nowMillis + limits.recoveryPollMillis);\n const pass = yield* scheduling.runDue(owner);\n if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.recoveryPollMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n { mode: \"ordered\" },\n ).pipe(Effect.asVoid);\n\nexport interface ScheduleOwnerObjectInstance extends InstanceType<\n EffectCfDurableObject.DurableObjectClass<Record<never, never>, ScheduleRuntimeServices>\n> {\n schedule(encoded: unknown): Promise<unknown>;\n alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;\n}\n\nexport interface ScheduleOwnerObjectClass {\n new (ctx: DurableObjectState, env: Cloudflare.Env): ScheduleOwnerObjectInstance;\n}\n\n/**\n * The host Layer supplies authorization and routing and is cached for the object incarnation.\n * Cloudflare eviction does not guarantee its finalizers run. Do not acquire resources requiring\n * cleanup in this Layer; acquire them inside scoped `manage` / `prepare` operations instead.\n * Native services belong to effect-cf; the database and alarm runtime remain instance-owned.\n */\nexport const makeScheduleOwnerObjectClass = <E>(\n host: Layer.Layer<\n ScheduleAuthorizer | ThreadObjectNamespace,\n E,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment | ScheduleOwnerIdentity\n >,\n limits: SchedulingLimits = defaultSchedulingLimits,\n): ScheduleOwnerObjectClass => {\n const ownerLayer = Layer.effect(\n ScheduleOwnerIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n return ScheduleOwnerIdentity.of({ owner: yield* decodeOwnerName(state.raw.id.name) });\n }),\n );\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n const application = Layer.merge(Scheduling.layer(limits), ScheduleDriver.layer(limits)).pipe(\n Layer.provideMerge(\n scheduleStoreLayer.pipe(Layer.provide(transactionLayer), Layer.provide(sqlLayer)),\n ),\n Layer.provide(\n cloudflareScheduledInputAdmissionLayer.pipe(\n Layer.provide(cloudflarePreparedInputAdmissionLayer),\n Layer.provide(CloudflareThreadClient.layer),\n ),\n ),\n Layer.provide(ScheduleWakeNoop),\n Layer.provide(BrowserCrypto.layer),\n Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer),\n Layer.provide(host),\n Layer.provideMerge(ownerLayer),\n );\n const runtime: Layer.Layer<\n ScheduleRuntimeServices,\n E | ScheduleStorageError | ScheduleOwnerProtocolError | ScheduleValidationError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n\n const rpc = {\n schedule: (encoded: unknown) => handleScheduleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<ScheduleRuntimeServices>;\n\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: scheduleAlarmHandler(limits),\n });\n\n class ScheduleOwnerObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n return ScheduleOwnerObject;\n};\n"],"mappings":";;;;;;;;;AAmDA,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAE1B,MAAM,uBAAuB,OAAO,OAAO;CACzC,eAAe,OAAO,QAAQ,CAAC;CAC/B,YAAY,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AACtD,CAAC;AAED,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,CAC3B,CAAC,CAAC,CAAC;AAEH,MAAM,0BAA0B,YAC9B,QAAQ,UAAU,OAAQ,UAAU,GAAG,QAAQ,MAAM,GAAG,IAAK,EAAE;AAEjE,IAAa,6BAAb,cAAgD,OAAO,YAAwC,CAAC,CAC9F,8BACA,EAAE,SAAS,OAAO,OAAO,MAAM,OAAO,YAAY,IAAK,CAAC,EAAE,CAC5D,CAAC,CAAC,CAAC;AAEH,MAAM,gCAAgC;CACpC,eAAe,OAAO,QAAQ,CAAC;CAC/B,SAAS;CACT,OAAO;CACP,OAAOA;CACP,YAAY;CACZ,QAAQ;CACR,aAAa;CACb,mBAAmBA,cAAoB,OAAO;CAC9C,aAAa;AACf;AAEA,MAAM,wBAAwB,OAAO,aAAa,UAAU,6BAA6B;AAEzF,MAAM,wBAAwB,OAAO,aAAa,UAAU;CAC1D,GAAG;CACH,kBAAkB,OAAO,IAAI,MAAM,OAAO,cAAc,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,qBAAqB,OAAO,aAAa,OAAO;CACpD,eAAe,OAAO,QAAQ,CAAC;CAC/B,OAAOA;CACP,YAAY;AACd,CA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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { i as ThreadObjectNamespace } from "./bindings-BrVEOkfe.mjs";
|
|
2
|
+
import { Cause, Context, Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { DoSubscriptionAlarmControl } from "@effect-agent/storage-cloudflare";
|
|
4
|
+
import { EventSources, SourcePartition, SubscriptionAuthorizer, SubscriptionDriver, SubscriptionInputBindings, SubscriptionIntake, SubscriptionLimits, Subscriptions } from "@effect-agent/thread";
|
|
5
|
+
import { DurableObject, DurableObjectAlarm, DurableObjectState as DurableObjectState$1, WorkerEnvironment } from "effect-cf";
|
|
6
|
+
//#region src/subscriptions.d.ts
|
|
7
|
+
declare const SubscriptionAlarmProtocolError_base: Schema.Class<SubscriptionAlarmProtocolError, Schema.TaggedStruct<"SubscriptionAlarmProtocolError", {
|
|
8
|
+
readonly message: Schema.String;
|
|
9
|
+
}>, Cause.YieldableError>;
|
|
10
|
+
declare class SubscriptionAlarmProtocolError extends SubscriptionAlarmProtocolError_base {}
|
|
11
|
+
declare const SubscriptionPartitionProtocolError_base: Schema.Class<SubscriptionPartitionProtocolError, Schema.TaggedStruct<"SubscriptionPartitionProtocolError", {
|
|
12
|
+
readonly message: Schema.String;
|
|
13
|
+
}>, Cause.YieldableError>;
|
|
14
|
+
declare class SubscriptionPartitionProtocolError extends SubscriptionPartitionProtocolError_base {}
|
|
15
|
+
declare const CloudflareSubscriptionConfigError_base: Schema.Class<CloudflareSubscriptionConfigError, Schema.TaggedStruct<"CloudflareSubscriptionConfigError", {
|
|
16
|
+
readonly message: Schema.String;
|
|
17
|
+
}>, Cause.YieldableError>;
|
|
18
|
+
declare class CloudflareSubscriptionConfigError extends CloudflareSubscriptionConfigError_base {}
|
|
19
|
+
/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */
|
|
20
|
+
declare const validateCloudflareSubscriptionLimits: (limits: SubscriptionLimits) => Effect.Effect<void, CloudflareSubscriptionConfigError>;
|
|
21
|
+
declare const sourcePartitionName: (partition: SourcePartition) => string;
|
|
22
|
+
interface SubscriptionPartitionObjectRpc extends Rpc.DurableObjectBranded {
|
|
23
|
+
subscription(encoded: unknown): Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
declare const SubscriptionPartitionNamespace_base: Context.ServiceClass<SubscriptionPartitionNamespace, "@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace", {
|
|
26
|
+
readonly namespace: DurableObjectNamespace<SubscriptionPartitionObjectRpc>;
|
|
27
|
+
}>;
|
|
28
|
+
declare class SubscriptionPartitionNamespace extends SubscriptionPartitionNamespace_base {}
|
|
29
|
+
/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */
|
|
30
|
+
declare class CloudflareSubscriptionsClient {
|
|
31
|
+
static layer(partition: SourcePartition): Layer.Layer<Subscriptions | SubscriptionIntake, never, SubscriptionPartitionNamespace>;
|
|
32
|
+
}
|
|
33
|
+
declare const SubscriptionPartitionIdentity_base: Context.ServiceClass<SubscriptionPartitionIdentity, "@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity", {
|
|
34
|
+
readonly partition: SourcePartition;
|
|
35
|
+
}>;
|
|
36
|
+
declare class SubscriptionPartitionIdentity extends SubscriptionPartitionIdentity_base {}
|
|
37
|
+
type SubscriptionRuntimeServices = Subscriptions | SubscriptionIntake | SubscriptionDriver | DoSubscriptionAlarmControl | SubscriptionPartitionIdentity | DurableObjectAlarm.DurableObjectAlarm;
|
|
38
|
+
interface SubscriptionPartitionObjectInstance extends InstanceType<DurableObject.DurableObjectClass<Record<never, never>, SubscriptionRuntimeServices>> {
|
|
39
|
+
subscription(encoded: unknown): Promise<unknown>;
|
|
40
|
+
alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void;
|
|
41
|
+
}
|
|
42
|
+
interface SubscriptionPartitionObjectClass {
|
|
43
|
+
new (ctx: DurableObjectState, env: Cloudflare.Env): SubscriptionPartitionObjectInstance;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source
|
|
47
|
+
* catalog and authority. It must not retain cleanup-scoped resources across RPC events.
|
|
48
|
+
*/
|
|
49
|
+
declare const makeSubscriptionPartitionObjectClass: <E>(host: Layer.Layer<SubscriptionAuthorizer | EventSources | SubscriptionInputBindings | ThreadObjectNamespace, E, DurableObjectState$1.DurableObjectState | WorkerEnvironment | SubscriptionPartitionIdentity>, limits?: SubscriptionLimits) => SubscriptionPartitionObjectClass;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionObjectClass, SubscriptionPartitionObjectInstance, SubscriptionPartitionObjectRpc, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits };
|
|
52
|
+
//# sourceMappingURL=subscriptions.d.mts.map
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { s as CloudflareThreadClient, t as cloudflarePreparedInputAdmissionLayer } from "./prepared-admission-BKp_Upw2.mjs";
|
|
2
|
+
import { Cause, Clock, Context, DateTime, Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { DoSubscriptionAlarmControl, DoSubscriptionTransaction, doSubscriptionStoreLayer } from "@effect-agent/storage-cloudflare";
|
|
4
|
+
import { EventAcknowledgement, EventSourceVersion, PersistedJson, Principal, SourcePartition, SubscriptionConfiguration, SubscriptionDeliverySnapshot, SubscriptionDriver, SubscriptionError, SubscriptionFailpointError, SubscriptionIntake, SubscriptionKey, SubscriptionScope, SubscriptionSnapshot, SubscriptionSourceError, Subscriptions, defaultSubscriptionLimits } from "@effect-agent/thread";
|
|
5
|
+
import { BrowserCrypto } from "@effect/platform-browser";
|
|
6
|
+
import { SqliteClient } from "@effect/sql-sqlite-do";
|
|
7
|
+
import { DurableObject, DurableObjectAlarm, DurableObjectState } from "effect-cf";
|
|
8
|
+
//#region src/subscriptions.ts
|
|
9
|
+
const SUBSCRIPTION_ALARM_TAG = "effect-agent/SubscriptionPartitionWake";
|
|
10
|
+
const SUBSCRIPTION_ALARM_ID = "driver";
|
|
11
|
+
const MAX_ALARM_WALL_MILLIS = 72e4;
|
|
12
|
+
const SubscriptionAlarmPayload = Schema.Struct({
|
|
13
|
+
schemaVersion: Schema.Literal(1),
|
|
14
|
+
generation: Schema.Int.check(Schema.isGreaterThan(0))
|
|
15
|
+
});
|
|
16
|
+
var SubscriptionAlarmProtocolError = class extends Schema.TaggedError()("SubscriptionAlarmProtocolError", { message: Schema.String }) {};
|
|
17
|
+
var SubscriptionPartitionProtocolError = class extends Schema.TaggedError()("SubscriptionPartitionProtocolError", { message: Schema.String.check(Schema.isMaxLength(4096)) }) {};
|
|
18
|
+
var CloudflareSubscriptionConfigError = class extends Schema.TaggedError()("CloudflareSubscriptionConfigError", { message: Schema.String }) {};
|
|
19
|
+
/** Reject limits whose four bounded phases could exceed the safe Durable Object alarm budget. */
|
|
20
|
+
const validateCloudflareSubscriptionLimits = (limits) => {
|
|
21
|
+
return 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis <= MAX_ALARM_WALL_MILLIS ? Effect.void : Effect.fail(CloudflareSubscriptionConfigError.make({ message: "Subscription limits can exceed the bounded Durable Object alarm wall budget" }));
|
|
22
|
+
};
|
|
23
|
+
const protocolMessage = (message) => message.length <= 4096 ? message : `${message.slice(0, 4093)}...`;
|
|
24
|
+
const SubscribeRequest = Schema.TaggedStruct("Subscribe", {
|
|
25
|
+
schemaVersion: Schema.Literal(1),
|
|
26
|
+
scope: Schema.Struct({ ...SubscriptionScope.fields }),
|
|
27
|
+
options: Schema.Struct({
|
|
28
|
+
subscriptionId: SubscriptionKey.fields.subscriptionId,
|
|
29
|
+
source: EventSourceVersion,
|
|
30
|
+
parameters: PersistedJson,
|
|
31
|
+
context: PersistedJson,
|
|
32
|
+
mode: Schema.Literals(["once", "continuous"]),
|
|
33
|
+
expiresAtMillis: Schema.Number,
|
|
34
|
+
destination: SubscriptionConfiguration.fields.destination,
|
|
35
|
+
deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,
|
|
36
|
+
agentId: SubscriptionConfiguration.fields.agentId,
|
|
37
|
+
definitions: SubscriptionConfiguration.fields.definitions
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
const ListSubscriptionsRequest = Schema.TaggedStruct("ListSubscriptions", {
|
|
41
|
+
schemaVersion: Schema.Literal(1),
|
|
42
|
+
scope: SubscribeRequest.fields.scope,
|
|
43
|
+
after: Schema.optionalKey(Schema.Natural),
|
|
44
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
|
|
45
|
+
});
|
|
46
|
+
const CancelSubscriptionRequest = Schema.TaggedStruct("CancelSubscription", {
|
|
47
|
+
schemaVersion: Schema.Literal(1),
|
|
48
|
+
scope: SubscribeRequest.fields.scope,
|
|
49
|
+
key: SubscriptionKey
|
|
50
|
+
});
|
|
51
|
+
const ListDeliveriesRequest = Schema.TaggedStruct("ListDeliveries", {
|
|
52
|
+
schemaVersion: Schema.Literal(1),
|
|
53
|
+
scope: SubscribeRequest.fields.scope,
|
|
54
|
+
key: SubscriptionKey,
|
|
55
|
+
after: Schema.optionalKey(Schema.String),
|
|
56
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)))
|
|
57
|
+
});
|
|
58
|
+
const AcceptRequest = Schema.TaggedStruct("Accept", {
|
|
59
|
+
schemaVersion: Schema.Literal(1),
|
|
60
|
+
partition: SourcePartition,
|
|
61
|
+
principal: Principal,
|
|
62
|
+
source: EventSourceVersion,
|
|
63
|
+
payload: PersistedJson
|
|
64
|
+
});
|
|
65
|
+
const StatusRequest = Schema.TaggedStruct("Status", {
|
|
66
|
+
schemaVersion: Schema.Literal(1),
|
|
67
|
+
partition: SourcePartition,
|
|
68
|
+
principal: Principal,
|
|
69
|
+
source: EventSourceVersion,
|
|
70
|
+
eventId: Schema.String
|
|
71
|
+
});
|
|
72
|
+
const SubscriptionPartitionRequest = Schema.Union([
|
|
73
|
+
SubscribeRequest,
|
|
74
|
+
ListSubscriptionsRequest,
|
|
75
|
+
CancelSubscriptionRequest,
|
|
76
|
+
ListDeliveriesRequest,
|
|
77
|
+
AcceptRequest,
|
|
78
|
+
StatusRequest
|
|
79
|
+
]);
|
|
80
|
+
const SubscriptionPage = Schema.Struct({
|
|
81
|
+
items: Schema.Array(SubscriptionSnapshot),
|
|
82
|
+
next: Schema.NullOr(Schema.Natural)
|
|
83
|
+
});
|
|
84
|
+
const DeliveryPage = Schema.Struct({
|
|
85
|
+
items: Schema.Array(SubscriptionDeliverySnapshot),
|
|
86
|
+
next: Schema.NullOr(Schema.String)
|
|
87
|
+
});
|
|
88
|
+
const IntakeStatus = Schema.Struct({
|
|
89
|
+
...EventAcknowledgement.fields,
|
|
90
|
+
routingComplete: Schema.Boolean,
|
|
91
|
+
routingFailure: Schema.NullOr(Schema.String),
|
|
92
|
+
nextAttemptAtMillis: Schema.Number
|
|
93
|
+
});
|
|
94
|
+
const SubscriptionPartitionFailure = Schema.Union([
|
|
95
|
+
SubscriptionError,
|
|
96
|
+
SubscriptionSourceError,
|
|
97
|
+
SubscriptionFailpointError,
|
|
98
|
+
SubscriptionPartitionProtocolError
|
|
99
|
+
]);
|
|
100
|
+
const SubscriptionPartitionResponse = Schema.Union([
|
|
101
|
+
Schema.TaggedStruct("Snapshot", { value: SubscriptionSnapshot }),
|
|
102
|
+
Schema.TaggedStruct("SubscriptionPage", { value: SubscriptionPage }),
|
|
103
|
+
Schema.TaggedStruct("DeliveryPage", { value: DeliveryPage }),
|
|
104
|
+
Schema.TaggedStruct("Acknowledgement", { value: EventAcknowledgement }),
|
|
105
|
+
Schema.TaggedStruct("Status", { value: IntakeStatus }),
|
|
106
|
+
Schema.TaggedStruct("Failed", { failure: SubscriptionPartitionFailure })
|
|
107
|
+
]);
|
|
108
|
+
const decodeRequest = Schema.decodeUnknownEffect(SubscriptionPartitionRequest);
|
|
109
|
+
const encodeRequest = Schema.encodeEffect(SubscriptionPartitionRequest);
|
|
110
|
+
const decodeResponse = Schema.decodeUnknownEffect(SubscriptionPartitionResponse);
|
|
111
|
+
const encodeResponse = Schema.encodeEffect(SubscriptionPartitionResponse);
|
|
112
|
+
const protocolFailure = (message) => ({
|
|
113
|
+
_tag: "Failed",
|
|
114
|
+
failure: SubscriptionPartitionProtocolError.make({ message: protocolMessage(message) })
|
|
115
|
+
});
|
|
116
|
+
const sourcePartitionName = (partition) => JSON.stringify([partition.tenantId, partition.address]);
|
|
117
|
+
var SubscriptionPartitionNamespace = class extends Context.Service()("@effect-agent/platform-cloudflare/SubscriptionPartitionNamespace") {};
|
|
118
|
+
const storageFailure = (code) => SubscriptionError.make({
|
|
119
|
+
reason: "storage",
|
|
120
|
+
code
|
|
121
|
+
});
|
|
122
|
+
const corruptFailure = (code) => SubscriptionError.make({
|
|
123
|
+
reason: "corrupt",
|
|
124
|
+
code
|
|
125
|
+
});
|
|
126
|
+
/** Worker-side management and trusted intake, routed to one fresh partition stub per call. */
|
|
127
|
+
var CloudflareSubscriptionsClient = class {
|
|
128
|
+
static layer(partition) {
|
|
129
|
+
return Layer.effectContext(Effect.gen(function* () {
|
|
130
|
+
const { namespace } = yield* SubscriptionPartitionNamespace;
|
|
131
|
+
const call = Effect.fn("CloudflareSubscriptionsClient.call")(function* (addressedPartition, request) {
|
|
132
|
+
if (!samePartition(partition, addressedPartition)) return yield* SubscriptionError.make({
|
|
133
|
+
reason: "unauthorized",
|
|
134
|
+
code: "partition"
|
|
135
|
+
});
|
|
136
|
+
const encoded = yield* encodeRequest(request).pipe(Effect.mapError(() => corruptFailure("subscription-partition-protocol")));
|
|
137
|
+
const raw = yield* Effect.tryPromise({
|
|
138
|
+
try: () => namespace.get(namespace.idFromName(sourcePartitionName(partition))).subscription(encoded),
|
|
139
|
+
catch: () => storageFailure("call-subscription-partition")
|
|
140
|
+
});
|
|
141
|
+
return yield* decodeResponse(raw).pipe(Effect.mapError(() => corruptFailure("subscription-partition-protocol")));
|
|
142
|
+
});
|
|
143
|
+
const failed = (response) => response._tag === "Failed" ? response.failure : SubscriptionPartitionProtocolError.make({ message: "Unexpected subscription response" });
|
|
144
|
+
const asProtocolError = () => corruptFailure("subscription-partition-protocol");
|
|
145
|
+
const subscriptions = Subscriptions.of({
|
|
146
|
+
subscribe: (scope, options) => Effect.gen(function* () {
|
|
147
|
+
const response = yield* call(scope.partition, {
|
|
148
|
+
_tag: "Subscribe",
|
|
149
|
+
schemaVersion: 1,
|
|
150
|
+
scope,
|
|
151
|
+
options
|
|
152
|
+
});
|
|
153
|
+
if (response._tag === "Snapshot") return response.value;
|
|
154
|
+
const failure = failed(response);
|
|
155
|
+
if (failure._tag === "SubscriptionError" || failure._tag === "SubscriptionSourceError" || failure._tag === "SubscriptionFailpointError") return yield* failure;
|
|
156
|
+
return yield* asProtocolError();
|
|
157
|
+
}),
|
|
158
|
+
listSubscriptions: (scope, after, limit) => Effect.gen(function* () {
|
|
159
|
+
const response = yield* call(scope.partition, {
|
|
160
|
+
_tag: "ListSubscriptions",
|
|
161
|
+
schemaVersion: 1,
|
|
162
|
+
scope,
|
|
163
|
+
...after === void 0 ? {} : { after },
|
|
164
|
+
...limit === void 0 ? {} : { limit }
|
|
165
|
+
});
|
|
166
|
+
if (response._tag === "SubscriptionPage") return response.value;
|
|
167
|
+
const failure = failed(response);
|
|
168
|
+
return yield* failure._tag === "SubscriptionError" ? failure : asProtocolError();
|
|
169
|
+
}),
|
|
170
|
+
cancelSubscription: (scope, key) => Effect.gen(function* () {
|
|
171
|
+
const response = yield* call(scope.partition, {
|
|
172
|
+
_tag: "CancelSubscription",
|
|
173
|
+
schemaVersion: 1,
|
|
174
|
+
scope,
|
|
175
|
+
key
|
|
176
|
+
});
|
|
177
|
+
if (response._tag === "Snapshot") return response.value;
|
|
178
|
+
const failure = failed(response);
|
|
179
|
+
if (failure._tag === "SubscriptionError" || failure._tag === "SubscriptionFailpointError") return yield* failure;
|
|
180
|
+
return yield* asProtocolError();
|
|
181
|
+
}),
|
|
182
|
+
listDeliveries: (scope, key, after, limit) => Effect.gen(function* () {
|
|
183
|
+
const response = yield* call(scope.partition, {
|
|
184
|
+
_tag: "ListDeliveries",
|
|
185
|
+
schemaVersion: 1,
|
|
186
|
+
scope,
|
|
187
|
+
key,
|
|
188
|
+
...after === void 0 ? {} : { after },
|
|
189
|
+
...limit === void 0 ? {} : { limit }
|
|
190
|
+
});
|
|
191
|
+
if (response._tag === "DeliveryPage") return response.value;
|
|
192
|
+
const failure = failed(response);
|
|
193
|
+
return yield* failure._tag === "SubscriptionError" ? failure : asProtocolError();
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
const intake = SubscriptionIntake.of({
|
|
197
|
+
accept: (principal, source, payload) => Effect.gen(function* () {
|
|
198
|
+
const request = yield* Schema.decodeUnknownEffect(AcceptRequest)({
|
|
199
|
+
_tag: "Accept",
|
|
200
|
+
schemaVersion: 1,
|
|
201
|
+
partition,
|
|
202
|
+
principal,
|
|
203
|
+
source,
|
|
204
|
+
payload
|
|
205
|
+
}).pipe(Effect.mapError(() => SubscriptionError.make({
|
|
206
|
+
reason: "validation",
|
|
207
|
+
code: "event-payload"
|
|
208
|
+
})));
|
|
209
|
+
const response = yield* call(request.partition, request);
|
|
210
|
+
if (response._tag === "Acknowledgement") return response.value;
|
|
211
|
+
const failure = failed(response);
|
|
212
|
+
if (failure._tag === "SubscriptionError" || failure._tag === "SubscriptionSourceError" || failure._tag === "SubscriptionFailpointError") return yield* failure;
|
|
213
|
+
return yield* asProtocolError();
|
|
214
|
+
}),
|
|
215
|
+
status: (principal, source, eventId) => Effect.gen(function* () {
|
|
216
|
+
const response = yield* call(partition, {
|
|
217
|
+
_tag: "Status",
|
|
218
|
+
schemaVersion: 1,
|
|
219
|
+
partition,
|
|
220
|
+
principal,
|
|
221
|
+
source,
|
|
222
|
+
eventId
|
|
223
|
+
});
|
|
224
|
+
if (response._tag === "Status") return response.value;
|
|
225
|
+
const failure = failed(response);
|
|
226
|
+
return yield* failure._tag === "SubscriptionError" ? failure : asProtocolError();
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
return Context.make(Subscriptions, subscriptions).pipe(Context.add(SubscriptionIntake, intake));
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var SubscriptionPartitionIdentity = class extends Context.Service()("@effect-agent/platform-cloudflare/SubscriptionPartitionIdentity") {};
|
|
234
|
+
const decodePartitionName = Effect.fn("decodeSubscriptionPartitionName")(function* (name) {
|
|
235
|
+
if (name === null || name === void 0) return yield* SubscriptionPartitionProtocolError.make({ message: "Subscription Partition objects require an idFromName identity" });
|
|
236
|
+
const tuple = yield* Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Tuple([Schema.String, Schema.String])))(name).pipe(Effect.mapError(() => SubscriptionPartitionProtocolError.make({ message: "Subscription Partition name is malformed" })));
|
|
237
|
+
return yield* Schema.decodeUnknownEffect(SourcePartition)({
|
|
238
|
+
tenantId: tuple[0],
|
|
239
|
+
address: tuple[1]
|
|
240
|
+
}).pipe(Effect.mapError(() => SubscriptionPartitionProtocolError.make({ message: "Subscription Partition identity is invalid" })));
|
|
241
|
+
});
|
|
242
|
+
const samePartition = Schema.toEquivalence(SourcePartition);
|
|
243
|
+
const requestPartition = (request) => request._tag === "Accept" || request._tag === "Status" ? request.partition : request.scope.partition;
|
|
244
|
+
const handleRequest = Effect.fn("SubscriptionPartition.handleRequest")(function* (encoded) {
|
|
245
|
+
const decoded = yield* decodeRequest(encoded).pipe(Effect.result);
|
|
246
|
+
if (decoded._tag === "Failure") return yield* encodeResponse(protocolFailure("The subscription request could not be decoded")).pipe(Effect.orDie);
|
|
247
|
+
const request = decoded.success;
|
|
248
|
+
const { partition } = yield* SubscriptionPartitionIdentity;
|
|
249
|
+
if (!samePartition(partition, requestPartition(request))) return yield* encodeResponse(protocolFailure("The request partition does not match the addressed object")).pipe(Effect.orDie);
|
|
250
|
+
const subscriptions = yield* Subscriptions;
|
|
251
|
+
const intake = yield* SubscriptionIntake;
|
|
252
|
+
const response = yield* Effect.gen(function* () {
|
|
253
|
+
switch (request._tag) {
|
|
254
|
+
case "Subscribe": return {
|
|
255
|
+
_tag: "Snapshot",
|
|
256
|
+
value: yield* subscriptions.subscribe(request.scope, request.options)
|
|
257
|
+
};
|
|
258
|
+
case "ListSubscriptions": return {
|
|
259
|
+
_tag: "SubscriptionPage",
|
|
260
|
+
value: yield* subscriptions.listSubscriptions(request.scope, request.after, request.limit)
|
|
261
|
+
};
|
|
262
|
+
case "CancelSubscription": return {
|
|
263
|
+
_tag: "Snapshot",
|
|
264
|
+
value: yield* subscriptions.cancelSubscription(request.scope, request.key)
|
|
265
|
+
};
|
|
266
|
+
case "ListDeliveries": return {
|
|
267
|
+
_tag: "DeliveryPage",
|
|
268
|
+
value: yield* subscriptions.listDeliveries(request.scope, request.key, request.after, request.limit)
|
|
269
|
+
};
|
|
270
|
+
case "Accept": return {
|
|
271
|
+
_tag: "Acknowledgement",
|
|
272
|
+
value: yield* intake.accept(request.principal, request.source, request.payload)
|
|
273
|
+
};
|
|
274
|
+
case "Status": return {
|
|
275
|
+
_tag: "Status",
|
|
276
|
+
value: yield* intake.status(request.principal, request.source, request.eventId)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}).pipe(Effect.catch((failure) => Schema.is(SubscriptionPartitionFailure)(failure) ? Effect.succeed({
|
|
280
|
+
_tag: "Failed",
|
|
281
|
+
failure
|
|
282
|
+
}) : Effect.succeed(protocolFailure("The subscription operation failed outside its contract"))));
|
|
283
|
+
return yield* encodeResponse(response).pipe(Effect.orDie);
|
|
284
|
+
});
|
|
285
|
+
const alarmStorageError = (code) => () => storageFailure(code);
|
|
286
|
+
const transactionLayer = Layer.effect(DoSubscriptionTransaction, Effect.gen(function* () {
|
|
287
|
+
const alarms = yield* DurableObjectAlarm.DurableObjectAlarm;
|
|
288
|
+
return DoSubscriptionTransaction.of({ run: (body) => Effect.gen(function* () {
|
|
289
|
+
const nowMillis = yield* Clock.currentTimeMillis;
|
|
290
|
+
return yield* alarms.transaction((transaction) => body((replacement) => replacement.deadlineAtMillis === null ? transaction.cancelAlarm({
|
|
291
|
+
id: SUBSCRIPTION_ALARM_ID,
|
|
292
|
+
tag: SUBSCRIPTION_ALARM_TAG
|
|
293
|
+
}).pipe(Effect.mapError(alarmStorageError("cancel-subscription-alarm"))) : Effect.fromOption(DateTime.make(Math.max(replacement.deadlineAtMillis, nowMillis + 1))).pipe(Effect.mapError(() => corruptFailure("subscription-alarm-deadline")), Effect.flatMap((runAt) => transaction.scheduleAlarm({
|
|
294
|
+
id: SUBSCRIPTION_ALARM_ID,
|
|
295
|
+
tag: SUBSCRIPTION_ALARM_TAG,
|
|
296
|
+
runAt,
|
|
297
|
+
payload: {
|
|
298
|
+
schemaVersion: 1,
|
|
299
|
+
generation: replacement.generation
|
|
300
|
+
}
|
|
301
|
+
}).pipe(Effect.mapError(alarmStorageError("schedule-subscription-alarm"))))))).pipe(Effect.catchTag("StorageOperationError", () => storageFailure("commit-subscription-transaction")));
|
|
302
|
+
}) });
|
|
303
|
+
}));
|
|
304
|
+
const alarmHandler = (limits) => DurableObjectAlarm.processDue((event) => Effect.gen(function* () {
|
|
305
|
+
if (event.tag !== SUBSCRIPTION_ALARM_TAG || event.id !== SUBSCRIPTION_ALARM_ID) return yield* SubscriptionAlarmProtocolError.make({ message: `Unsupported Subscription Partition alarm ${event.tag}/${event.id}` });
|
|
306
|
+
yield* Schema.decodeUnknownEffect(SubscriptionAlarmPayload)(event.payload).pipe(Effect.mapError(() => SubscriptionAlarmProtocolError.make({ message: "Unsupported subscription alarm payload" })));
|
|
307
|
+
const driver = yield* SubscriptionDriver;
|
|
308
|
+
const alarmControl = yield* DoSubscriptionAlarmControl;
|
|
309
|
+
yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);
|
|
310
|
+
if ((yield* driver.runDue.pipe(Effect.catchCause((cause) => Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Clock.currentTimeMillis.pipe(Effect.flatMap((time) => alarmControl.prearm(time + limits.retryMillis)), Effect.andThen(Effect.failCause(cause)))))).failed > 0) yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);
|
|
311
|
+
else yield* alarmControl.reconcile;
|
|
312
|
+
}), { mode: "ordered" }).pipe(Effect.asVoid);
|
|
313
|
+
/**
|
|
314
|
+
* Build one source-addressed SQLite Durable Object. The host Layer binds the permitted source
|
|
315
|
+
* catalog and authority. It must not retain cleanup-scoped resources across RPC events.
|
|
316
|
+
*/
|
|
317
|
+
const makeSubscriptionPartitionObjectClass = (host, limits = defaultSubscriptionLimits) => {
|
|
318
|
+
const cloudflareLimitsLayer = Layer.effectDiscard(validateCloudflareSubscriptionLimits(limits));
|
|
319
|
+
const identityLayer = Layer.effect(SubscriptionPartitionIdentity, Effect.gen(function* () {
|
|
320
|
+
const state = yield* DurableObjectState.DurableObjectState;
|
|
321
|
+
return SubscriptionPartitionIdentity.of({ partition: yield* decodePartitionName(state.raw.id.name) });
|
|
322
|
+
}));
|
|
323
|
+
const sqlLayer = Layer.unwrap(Effect.map(DurableObjectState.DurableObjectState, (state) => SqliteClient.layer({ storage: state.raw.storage })));
|
|
324
|
+
const partitionStore = Layer.unwrap(Effect.map(SubscriptionPartitionIdentity, ({ partition }) => doSubscriptionStoreLayer(partition).pipe(Layer.provide(transactionLayer), Layer.provide(sqlLayer))));
|
|
325
|
+
const application = Layer.mergeAll(Subscriptions.layer(limits), SubscriptionIntake.layer(limits), SubscriptionDriver.layer(limits), cloudflareLimitsLayer).pipe(Layer.provideMerge(partitionStore), Layer.provide(cloudflarePreparedInputAdmissionLayer.pipe(Layer.provide(CloudflareThreadClient.layer))), Layer.provide(BrowserCrypto.layer), Layer.provideMerge(DurableObjectAlarm.DurableObjectAlarm.layer), Layer.provide(host), Layer.provideMerge(identityLayer));
|
|
326
|
+
const runtime = Layer.effectContext(Effect.gen(function* () {
|
|
327
|
+
const state = yield* DurableObjectState.DurableObjectState;
|
|
328
|
+
const scope = yield* Effect.scope;
|
|
329
|
+
return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));
|
|
330
|
+
}));
|
|
331
|
+
const Base = DurableObject.make(runtime, {
|
|
332
|
+
initialize: Effect.void,
|
|
333
|
+
rpc: { subscription: (encoded) => handleRequest(encoded) },
|
|
334
|
+
alarms: alarmHandler(limits)
|
|
335
|
+
});
|
|
336
|
+
class SubscriptionPartitionObject extends Base {
|
|
337
|
+
alarm(alarmInfo) {
|
|
338
|
+
return super.alarm?.(alarmInfo);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return SubscriptionPartitionObject;
|
|
342
|
+
};
|
|
343
|
+
//#endregion
|
|
344
|
+
export { CloudflareSubscriptionConfigError, CloudflareSubscriptionsClient, SubscriptionAlarmProtocolError, SubscriptionPartitionIdentity, SubscriptionPartitionNamespace, SubscriptionPartitionProtocolError, makeSubscriptionPartitionObjectClass, sourcePartitionName, validateCloudflareSubscriptionLimits };
|
|
345
|
+
|
|
346
|
+
//# sourceMappingURL=subscriptions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.mjs","names":["EffectCfDurableObjectState","EffectCfDurableObject"],"sources":["../src/subscriptions.ts"],"sourcesContent":["import {\n DoSubscriptionAlarmControl,\n DoSubscriptionTransaction,\n doSubscriptionStoreLayer,\n} from \"@effect-agent/storage-cloudflare\";\nimport {\n EventAcknowledgement,\n EventSourceVersion,\n type EventSources,\n type SubscriptionInputBindings,\n PersistedJson,\n Principal,\n SourcePartition,\n type SubscriptionAuthorizer,\n SubscriptionConfiguration,\n SubscriptionDriver,\n SubscriptionDeliverySnapshot,\n SubscriptionError,\n SubscriptionFailpointError,\n SubscriptionIntake,\n SubscriptionKey,\n SubscriptionScope,\n type SubscriptionLimits,\n SubscriptionSnapshot,\n SubscriptionSourceError,\n Subscriptions,\n defaultSubscriptionLimits,\n} from \"@effect-agent/thread\";\nimport { BrowserCrypto } from \"@effect/platform-browser\";\nimport { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { Cause, Clock, Context, DateTime, Effect, Layer, Schema } from \"effect\";\nimport {\n DurableObject as EffectCfDurableObject,\n DurableObjectAlarm,\n DurableObjectState as EffectCfDurableObjectState,\n type WorkerEnvironment,\n} from \"effect-cf\";\n\nimport { type ThreadObjectNamespace } from \"./bindings.ts\";\nimport { CloudflareThreadClient } from \"./client.ts\";\nimport { cloudflarePreparedInputAdmissionLayer } from \"./prepared-admission.ts\";\n\nconst SUBSCRIPTION_ALARM_TAG = \"effect-agent/SubscriptionPartitionWake\";\nconst SUBSCRIPTION_ALARM_ID = \"driver\";\nconst MAX_ALARM_WALL_MILLIS = 12 * 60_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\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): Effect.Effect<void, CloudflareSubscriptionConfigError> => {\n const worstCaseMillis =\n 4 * Math.ceil(limits.batchSize / limits.concurrency) * limits.operationTimeoutMillis;\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.Number,\n destination: SubscriptionConfiguration.fields.destination,\n deliveryPrincipal: SubscriptionConfiguration.fields.deliveryPrincipal,\n agentId: SubscriptionConfiguration.fields.agentId,\n definitions: SubscriptionConfiguration.fields.definitions,\n }),\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 schemaVersion: Schema.Literal(1),\n scope: SubscribeRequest.fields.scope,\n key: SubscriptionKey,\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 ListSubscriptionsRequest,\n CancelSubscriptionRequest,\n ListDeliveriesRequest,\n AcceptRequest,\n StatusRequest,\n]);\ntype SubscriptionPartitionRequest = typeof SubscriptionPartitionRequest.Type;\n\nconst SubscriptionPage = Schema.Struct({\n items: Schema.Array(SubscriptionSnapshot),\n next: Schema.NullOr(Schema.Natural),\n});\nconst DeliveryPage = Schema.Struct({\n items: Schema.Array(SubscriptionDeliverySnapshot),\n next: Schema.NullOr(Schema.String),\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]);\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(\"Acknowledgement\", { value: EventAcknowledgement }),\n Schema.TaggedStruct(\"Status\", { value: IntakeStatus }),\n Schema.TaggedStruct(\"Failed\", { failure: SubscriptionPartitionFailure }),\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 });\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 const encoded = yield* encodeRequest(request).pipe(\n Effect.mapError(() => corruptFailure(\"subscription-partition-protocol\")),\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 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 const asProtocolError = (): SubscriptionError =>\n corruptFailure(\"subscription-partition-protocol\");\n\n const subscriptions = Subscriptions.of({\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 if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\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 if (response._tag === \"SubscriptionPage\") return response.value;\n const failure = failed(response);\n return yield* failure._tag === \"SubscriptionError\" ? failure : asProtocolError();\n }),\n cancelSubscription: (scope, key) =>\n Effect.gen(function* () {\n const response = yield* call(scope.partition, {\n _tag: \"CancelSubscription\",\n schemaVersion: 1,\n scope,\n key,\n });\n if (response._tag === \"Snapshot\") return response.value;\n const failure = failed(response);\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\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 if (response._tag === \"DeliveryPage\") return response.value;\n const failure = failed(response);\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 const response = yield* call(request.partition, request);\n if (response._tag === \"Acknowledgement\") return response.value;\n const failure = failed(response);\n if (\n failure._tag === \"SubscriptionError\" ||\n failure._tag === \"SubscriptionSourceError\" ||\n failure._tag === \"SubscriptionFailpointError\"\n )\n return yield* failure;\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 if (response._tag === \"Status\") return response.value;\n const failure = failed(response);\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 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 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);\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 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 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 const response = yield* Effect.gen(function* (): Effect.fn.Return<\n SubscriptionPartitionResponse,\n SubscriptionPartitionFailure\n > {\n switch (request._tag) {\n case \"Subscribe\":\n return {\n _tag: \"Snapshot\",\n value: yield* subscriptions.subscribe(request.scope, request.options),\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(request.scope, request.key),\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 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 return DoSubscriptionTransaction.of({\n run: (body) =>\n Effect.gen(function* () {\n const nowMillis = yield* Clock.currentTimeMillis;\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 || 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 yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\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 if (pass.failed > 0) {\n yield* alarmControl.prearm((yield* Clock.currentTimeMillis) + limits.retryMillis);\n } else {\n yield* alarmControl.reconcile;\n }\n }),\n { mode: \"ordered\" },\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 const identityLayer = Layer.effect(\n SubscriptionPartitionIdentity,\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n return SubscriptionPartitionIdentity.of({\n partition: yield* decodePartitionName(state.raw.id.name),\n });\n }),\n );\n const sqlLayer = Layer.unwrap(\n Effect.map(EffectCfDurableObjectState.DurableObjectState, (state) =>\n SqliteClient.layer({ storage: state.raw.storage }),\n ),\n );\n 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 const application = Layer.mergeAll(\n Subscriptions.layer(limits),\n SubscriptionIntake.layer(limits),\n SubscriptionDriver.layer(limits),\n cloudflareLimitsLayer,\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 const runtime: Layer.Layer<\n SubscriptionRuntimeServices,\n E | SubscriptionError | SubscriptionPartitionProtocolError | CloudflareSubscriptionConfigError,\n EffectCfDurableObjectState.DurableObjectState | WorkerEnvironment\n > = Layer.effectContext(\n Effect.gen(function* () {\n const state = yield* EffectCfDurableObjectState.DurableObjectState;\n const scope = yield* Effect.scope;\n return yield* state.blockConcurrencyWhile(Layer.buildWithScope(application, scope));\n }),\n );\n const rpc = {\n subscription: (encoded: unknown) => handleRequest(encoded),\n } satisfies EffectCfDurableObject.DurableObjectRpc<SubscriptionRuntimeServices>;\n const Base = EffectCfDurableObject.make(runtime, {\n initialize: Effect.void,\n rpc,\n alarms: alarmHandler(limits),\n });\n class SubscriptionPartitionObject extends Base {\n override alarm(alarmInfo?: AlarmInvocationInfo): Promise<void> | void {\n return super.alarm?.(alarmInfo);\n }\n }\n return SubscriptionPartitionObject;\n};\n"],"mappings":";;;;;;;;AA0CA,MAAM,yBAAyB;AAC/B,MAAM,wBAAwB;AAC9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AAM,cAAc,MAAM,SACxB,cAAc,MAAM,MAAM,GAC1B,mBAAmB,MAAM,MAAM,GAC/B,mBAAmB,MAAM,MAAM,GAC/B,qBACF,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;CACA,MAAM,UAIF,MAAM,cACR,OAAO,IAAI,aAAa;EACtB,MAAM,QAAQ,OAAOA,mBAA2B;EAChD,MAAM,QAAQ,OAAO,OAAO;EAC5B,OAAO,OAAO,MAAM,sBAAsB,MAAM,eAAe,aAAa,KAAK,CAAC;CACpF,CAAC,CACH;CAIA,MAAM,OAAOC,cAAsB,KAAK,SAAS;EAC/C,YAAY,OAAO;EACnB,KAAA,EAJA,eAAe,YAAqB,cAAc,OAAO,EAIvD;EACF,QAAQ,aAAa,MAAM;CAC7B,CAAC;CACD,MAAM,oCAAoC,KAAK;EAC7C,MAAe,WAAuD;GACpE,OAAO,MAAM,QAAQ,SAAS;EAChC;CACF;CACA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-agent/platform-cloudflare",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.40",
|
|
4
4
|
"exports": {
|
|
5
5
|
".": {
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -24,17 +24,17 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@
|
|
28
|
-
"@effect-agent/
|
|
29
|
-
"@effect-agent/
|
|
30
|
-
"@effect-agent/
|
|
31
|
-
"@effect-agent/
|
|
32
|
-
"@effect-agent/storage-cloudflare": "0.1.0-beta.38",
|
|
27
|
+
"@effect-agent/core": "0.1.0-beta.40",
|
|
28
|
+
"@effect-agent/engine": "0.1.0-beta.40",
|
|
29
|
+
"@effect-agent/sandbox": "0.1.0-beta.40",
|
|
30
|
+
"@effect-agent/storage-cloudflare": "0.1.0-beta.40",
|
|
31
|
+
"@effect-agent/thread": "0.1.0-beta.40",
|
|
33
32
|
"@effect/platform-browser": "4.0.0-rc.111",
|
|
34
|
-
"@effect/sql-sqlite-do": "4.0.0-rc.111"
|
|
35
|
-
"effect": "4.0.0-rc.111"
|
|
33
|
+
"@effect/sql-sqlite-do": "4.0.0-rc.111"
|
|
36
34
|
},
|
|
37
35
|
"peerDependencies": {
|
|
36
|
+
"@cloudflare/puppeteer": "^1.1.0",
|
|
37
|
+
"effect": "^4.0.0-rc.111",
|
|
38
38
|
"effect-cf": "^0.37.0"
|
|
39
39
|
},
|
|
40
40
|
"description": "Cloudflare Layer assembly for Effect Agent: Durable Objects and Browser Run adapters.",
|
|
@@ -57,18 +57,25 @@
|
|
|
57
57
|
"check": "tsc --noEmit -p tsconfig.json"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
+
"@cloudflare/puppeteer": "1.1.0",
|
|
60
61
|
"@cloudflare/vitest-pool-workers": "0.21.3",
|
|
61
62
|
"@cloudflare/workers-types": "5.20260825.1",
|
|
62
|
-
"@effect-agent/capabilities": "0.1.0-beta.
|
|
63
|
-
"@effect-agent/testing": "0.1.0-beta.
|
|
63
|
+
"@effect-agent/capabilities": "0.1.0-beta.39",
|
|
64
|
+
"@effect-agent/testing": "0.1.0-beta.39",
|
|
64
65
|
"@effect/platform-node": "4.0.0-rc.111",
|
|
65
66
|
"@effect/sql-d1": "4.0.0-rc.111",
|
|
66
67
|
"@effect/vitest": "4.0.0-rc.111",
|
|
68
|
+
"effect": "4.0.0-rc.111",
|
|
67
69
|
"effect-cf": "0.37.0",
|
|
68
70
|
"esbuild": "0.28.1",
|
|
69
71
|
"miniflare": "5.20260811.1-alpha",
|
|
70
72
|
"typescript": "7.0.2",
|
|
71
|
-
"vite-plus": "0.
|
|
72
|
-
"vitest": "4.1.
|
|
73
|
+
"vite-plus": "0.3.0",
|
|
74
|
+
"vitest": "4.1.11"
|
|
75
|
+
},
|
|
76
|
+
"peerDependenciesMeta": {
|
|
77
|
+
"@cloudflare/puppeteer": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
73
80
|
}
|
|
74
81
|
}
|