@rivetkit/cloudflare-workers 0.9.3 → 0.9.6

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/mod.cjs CHANGED
@@ -589,6 +589,7 @@ function createServer(registry, inputConfig) {
589
589
  const config = ConfigSchema.parse(inputConfig);
590
590
  const runConfig = {
591
591
  driver: {
592
+ name: "cloudflare-workers",
592
593
  manager: () => new CloudflareActorsManagerDriver(),
593
594
  // HACK: We can't build the actor driver until we're inside the Durable Object
594
595
  actor: void 0
package/dist/mod.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/nathan/rivetkit/packages/drivers/cloudflare-workers/dist/mod.cjs","../src/handler.ts","../src/actor-handler-do.ts","../src/actor-driver.ts","../src/log.ts","../src/config.ts","../src/manager-driver.ts","../src/util.ts","../src/websocket.ts"],"names":["_a","invariant","ActorHandler"],"mappings":"AAAA;ACAA,0CAAkC;AAGlC,4BAAqB;AACrB,4FAAsB;ADAtB;AACA;AELA,uDAA8B;AAO9B;AACC;AACA;AACA;AAAA,sCACM;AACP,8DAA0C;AFC1C;AACA;AGTA;AACC;AACA;AACA;AAAA;AAQD;AAaO,IAAM,mCAAA,EAAN,MAAyC;AAAA;AAAA,EAE/C,CAAA,IAAA,kBAA8C,IAAI,GAAA,CAAI,CAAA;AAAA,EAEtD,UAAA,CAAW,OAAA,EAA2C;AACrD,IAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,CAAA,GAAA,CAAK,GAAA,CAAI,OAAO,CAAA;AACnC,IAAA,iCAAA,MAAU,IAAU,KAAA,CAAA,EAAW,0CAA0C,CAAA;AACzE,IAAA,OAAO,KAAA;AAAA,EACR;AAAA,EAEA,UAAA,CAAW,OAAA,EAAiB,KAAA,EAAiC;AAC5D,IAAA,IAAA,CAAK,CAAA,GAAA,CAAK,GAAA,CAAI,OAAA,EAAS,KAAK,CAAA;AAAA,EAC7B;AACD,CAAA;AAQA,IAAM,aAAA,Y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AACN,IAAA;AACD,EAAA;AACD;AN0KY;AACA;AQ3fH;AAGI;AARb,EAAA;AAcO,EAAA;AACF,EAAA;AACH,IAAA;AACD,EAAA;AAEM,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACG,IAAA;AACJ,IAAA;AACH,MAAA;AACD,IAAA;AACK,IAAA;AACD,IAAA;AACH,MAAA;AACD,IAAA;AACK,IAAA;AACE,IAAA;AACP,EAAA;AAEG,EAAA;AACI,IAAA;AAAiB,MAAA;AAAU,MAAA;AArCpCA,QAAAA;AAsCG,QAAA;AAAsB,MAAA;AACvB,IAAA;AACD,EAAA;AACI,EAAA;AACI,IAAA;AAAiB,MAAA;AAAY,MAAA;AA1CtCA,QAAAA;AA2CG,QAAA;AAAwB,MAAA;AACzB,IAAA;AACD,EAAA;AACI,EAAA;AACI,IAAA;AAAiB,MAAA;AAAU,MAAA;AA/CpCA,QAAAA;AAgDG,QAAA;AAAsB,MAAA;AACvB,IAAA;AACD,EAAA;AAEA,EAAA;AAKA,EAAA;AAEO,EAAA;AACE,IAAA;AACR,IAAA;AAAS;AAAA;AAAA;AAIR,MAAA;AACD,IAAA;AACA,IAAA;AACA,EAAA;AACD;AR0fW;AACA;ACviBC;AAEG;AACT,EAAA;AACNC,EAAAA;AACO,EAAA;AACR;AAYgB;AAIP,EAAA;AACD,EAAA;AACR;AAEgB;AAIT,EAAA;AAGA,EAAA;AACG,IAAA;AACP,MAAA;AAAiD;AAEjD,MAAA;AACD,IAAA;AACA,IAAA;AACG,IAAA;AACJ,EAAA;AAGMC,EAAAA;AAGA,EAAA;AAEC,EAAA;AACE,IAAA;AACR,IAAA;AAEO,MAAA;AAGD,MAAA;AACA,QAAA;AACL,MAAA;AAGM,MAAA;AACL,QAAA;AACC,UAAA;AACD,QAAA;AACD,MAAA;AAEA,MAAA;AACD,IAAA;AACD,EAAA;AACD;ADygBY;AACA;AACA;AACA","file":"/home/nathan/rivetkit/packages/drivers/cloudflare-workers/dist/mod.cjs","sourcesContent":[null,"import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Registry, RunConfig } from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport { Hono } from \"hono\";\nimport invariant from \"invariant\";\nimport {\n\ttype ActorHandlerInterface,\n\tcreateActorDurableObject,\n\ttype DurableObjectConstructor,\n} from \"./actor-handler-do\";\nimport { ConfigSchema, type InputConfig } from \"./config\";\nimport { CloudflareActorsManagerDriver } from \"./manager-driver\";\nimport { upgradeWebSocket } from \"./websocket\";\n\n/** Cloudflare Workers env */\nexport interface Bindings {\n\tACTOR_KV: KVNamespace;\n\tACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>;\n}\n\n/**\n * Stores the env for the current request. Required since some contexts like the inline client driver does not have access to the Hono context.\n *\n * Use getCloudflareAmbientEnv unless using CF_AMBIENT_ENV.run.\n */\nexport const CF_AMBIENT_ENV = new AsyncLocalStorage<Bindings>();\n\nexport function getCloudflareAmbientEnv(): Bindings {\n\tconst env = CF_AMBIENT_ENV.getStore();\n\tinvariant(env, \"missing CF_AMBIENT_ENV\");\n\treturn env;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\ninterface SetupOutput<A extends Registry<any>> {\n\tclient: Client<A>;\n\tcreateHandler: (hono?: Hono) => Handler;\n}\n\nexport function createServerHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst { createHandler } = createServer(registry, inputConfig);\n\treturn createHandler();\n}\n\nexport function createServer<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): SetupOutput<R> {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\tdriver: {\n\t\t\tmanager: () => new CloudflareActorsManagerDriver(),\n\t\t\t// HACK: We can't build the actor driver until we're inside the Durable Object\n\t\t\tactor: undefined as any,\n\t\t},\n\t\tgetUpgradeWebSocket: () => upgradeWebSocket,\n\t\t...config,\n\t} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.createServer(runConfig);\n\n\treturn {\n\t\tclient: serverOutput.client as Client<R>,\n\t\tcreateHandler: (hono) => {\n\t\t\t// Build base router\n\t\t\tconst app = hono ?? new Hono();\n\n\t\t\t// Mount registry router at /registry\n\t\t\tif (!hono) {\n\t\t\t\tapp.route(\"/registry\", serverOutput.hono);\n\t\t\t}\n\n\t\t\t// Create Cloudflare handler\n\t\t\tconst handler = {\n\t\t\t\tfetch: (request, env, ctx) => {\n\t\t\t\t\treturn CF_AMBIENT_ENV.run(env, () => app.fetch(request, env, ctx));\n\t\t\t\t},\n\t\t\t} satisfies ExportedHandler<Bindings>;\n\n\t\t\treturn { handler, ActorHandler };\n\t\t},\n\t};\n}\n","import { DurableObject } from \"cloudflare:workers\";\nimport type {\n\tActorKey,\n\tActorRouter,\n\tRegistry,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateActorRouter,\n\tcreateClientWithDriver,\n\tcreateInlineClientDriver,\n} from \"@rivetkit/core\";\nimport { serializeEmptyPersistData } from \"@rivetkit/core/driver-helpers\";\nimport type { ExecutionContext } from \"hono\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport { type Bindings, CF_AMBIENT_ENV } from \"./handler\";\nimport { logger } from \"./log\";\n\nexport const KEYS = {\n\tNAME: \"rivetkit:name\",\n\tKEY: \"rivetkit:key\",\n\tPERSIST_DATA: \"rivetkit:data\",\n};\n\nexport interface ActorHandlerInterface extends DurableObject {\n\tinitialize(req: ActorInitRequest): Promise<void>;\n}\n\nexport interface ActorInitRequest {\n\tname: string;\n\tkey: ActorKey;\n\tinput?: unknown;\n}\n\ninterface InitializedData {\n\tname: string;\n\tkey: ActorKey;\n}\n\nexport type DurableObjectConstructor = new (\n\t...args: ConstructorParameters<typeof DurableObject<Bindings>>\n) => DurableObject<Bindings>;\n\ninterface LoadedActor {\n\tactorRouter: ActorRouter;\n}\n\nexport function createActorDurableObject(\n\tregistry: Registry<any>,\n\trunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t/**\n\t * Startup steps:\n\t * 1. If not already created call `initialize`, otherwise check KV to ensure it's initialized\n\t * 2. Load actor\n\t * 3. Start service requests\n\t */\n\treturn class ActorHandler\n\t\textends DurableObject<Bindings>\n\t\timplements ActorHandlerInterface\n\t{\n\t\t#initialized?: InitializedData;\n\t\t#initializedPromise?: PromiseWithResolvers<void>;\n\n\t\t#actor?: LoadedActor;\n\n\t\tasync #loadActor(): Promise<LoadedActor> {\n\t\t\t// This is always called from another context using CF_AMBIENT_ENV\n\n\t\t\t// Wait for init\n\t\t\tif (!this.#initialized) {\n\t\t\t\t// Wait for init\n\t\t\t\tif (this.#initializedPromise) {\n\t\t\t\t\tawait this.#initializedPromise.promise;\n\t\t\t\t} else {\n\t\t\t\t\tthis.#initializedPromise = Promise.withResolvers();\n\t\t\t\t\tconst res = await this.ctx.storage.get([\n\t\t\t\t\t\tKEYS.NAME,\n\t\t\t\t\t\tKEYS.KEY,\n\t\t\t\t\t\tKEYS.PERSIST_DATA,\n\t\t\t\t\t]);\n\t\t\t\t\tif (res.get(KEYS.PERSIST_DATA)) {\n\t\t\t\t\t\tconst name = res.get(KEYS.NAME) as string;\n\t\t\t\t\t\tif (!name) throw new Error(\"missing actor name\");\n\t\t\t\t\t\tconst key = res.get(KEYS.KEY) as ActorKey;\n\t\t\t\t\t\tif (!key) throw new Error(\"missing actor key\");\n\n\t\t\t\t\t\tlogger().debug(\"already initialized\", { name, key });\n\n\t\t\t\t\t\tthis.#initialized = { name, key };\n\t\t\t\t\t\tthis.#initializedPromise.resolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger().debug(\"waiting to initialize\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check if already loaded\n\t\t\tif (this.#actor) {\n\t\t\t\treturn this.#actor;\n\t\t\t}\n\n\t\t\tif (!this.#initialized) throw new Error(\"Not initialized\");\n\n\t\t\t// Register DO with global state first\n\t\t\t// HACK: This leaks the DO context, but DO does not provide a native way\n\t\t\t// of knowing when the DO shuts down. We're making a broad assumption\n\t\t\t// that DO will boot a new isolate frequenlty enough that this is not an issue.\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\tglobalState.setDOState(actorId, { ctx: this.ctx, env: this.env });\n\n\t\t\t// Configure actor driver\n\t\t\trunConfig.driver.actor =\n\t\t\t\tcreateCloudflareActorsActorDriverBuilder(globalState);\n\n\t\t\t// Create manager driver (we need this for the actor router)\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\n\t\t\t// Create inline client\n\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t);\n\n\t\t\t// Create actor driver\n\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t\tmanagerDriver,\n\t\t\t\tinlineClient,\n\t\t\t);\n\n\t\t\t// Create actor router\n\t\t\tconst actorRouter = createActorRouter(runConfig, actorDriver);\n\n\t\t\t// Save actor\n\t\t\tthis.#actor = {\n\t\t\t\tactorRouter,\n\t\t\t};\n\n\t\t\t// Initialize the actor instance with proper metadata\n\t\t\t// This ensures the actor driver knows about this actor\n\t\t\tawait actorDriver.loadActor(actorId);\n\n\t\t\treturn this.#actor;\n\t\t}\n\n\t\t/** RPC called by the service that creates the DO to initialize it. */\n\t\tasync initialize(req: ActorInitRequest) {\n\t\t\t// TODO: Need to add this to a core promise that needs to be resolved before start\n\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.ctx.storage.put({\n\t\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t\t});\n\t\t\t\tthis.#initialized = {\n\t\t\t\t\tname: req.name,\n\t\t\t\t\tkey: req.key,\n\t\t\t\t};\n\n\t\t\t\tlogger().debug(\"initialized actor\", { key: req.key });\n\n\t\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\t\tawait this.#loadActor();\n\t\t\t});\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\t\tactorId,\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.#loadActor();\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t\t// Get the actor driver\n\t\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t);\n\t\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t\t);\n\t\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t\tmanagerDriver,\n\t\t\t\t\tinlineClient,\n\t\t\t\t);\n\n\t\t\t\t// Load the actor instance and trigger alarm\n\t\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\t\tawait actor.onAlarm();\n\t\t\t});\n\t\t}\n\t};\n}\n","import type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport invariant from \"invariant\";\nimport { KEYS } from \"./actor-handler-do\";\n\ninterface DurableObjectGlobalState {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n/**\n * Cloudflare DO can have multiple DO running within the same global scope.\n *\n * This allows for storing the actor context globally and looking it up by ID in `CloudflareActorsActorDriver`.\n */\nexport class CloudflareDurableObjectGlobalState {\n\t// Single map for all actor state\n\t#dos: Map<string, DurableObjectGlobalState> = new Map();\n\n\tgetDOState(actorId: string): DurableObjectGlobalState {\n\t\tconst state = this.#dos.get(actorId);\n\t\tinvariant(state !== undefined, \"durable object state not in global state\");\n\t\treturn state;\n\t}\n\n\tsetDOState(actorId: string, state: DurableObjectGlobalState) {\n\t\tthis.#dos.set(actorId, state);\n\t}\n}\n\nexport interface ActorDriverContext {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n// Actor handler to track running instances\nclass ActorHandler {\n\tactor?: AnyActorInstance;\n\tactorPromise?: PromiseWithResolvers<void> = Promise.withResolvers();\n\tgenericConnGlobalState = new GenericConnGlobalState();\n}\n\nexport class CloudflareActorsActorDriver implements ActorDriver {\n\t#registryConfig: RegistryConfig;\n\t#runConfig: RunConfig;\n\t#managerDriver: ManagerDriver;\n\t#inlineClient: Client<any>;\n\t#globalState: CloudflareDurableObjectGlobalState;\n\t#actors: Map<string, ActorHandler> = new Map();\n\n\tconstructor(\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t\tglobalState: CloudflareDurableObjectGlobalState,\n\t) {\n\t\tthis.#registryConfig = registryConfig;\n\t\tthis.#runConfig = runConfig;\n\t\tthis.#managerDriver = managerDriver;\n\t\tthis.#inlineClient = inlineClient;\n\t\tthis.#globalState = globalState;\n\t}\n\n\t#getDOCtx(actorId: string) {\n\t\treturn this.#globalState.getDOState(actorId).ctx;\n\t}\n\n\tasync loadActor(actorId: string): Promise<AnyActorInstance> {\n\t\t// Check if actor is already loaded\n\t\tlet handler = this.#actors.get(actorId);\n\t\tif (handler) {\n\t\t\tif (handler.actorPromise) await handler.actorPromise.promise;\n\t\t\tif (!handler.actor) throw new Error(\"Actor should be loaded\");\n\t\t\treturn handler.actor;\n\t\t}\n\n\t\t// Create new actor handler\n\t\thandler = new ActorHandler();\n\t\tthis.#actors.set(actorId, handler);\n\n\t\t// Get the actor metadata from Durable Object storage\n\t\tconst doState = this.#globalState.getDOState(actorId);\n\t\tconst storage = doState.ctx.storage;\n\n\t\t// Load actor metadata\n\t\tconst [name, key] = await Promise.all([\n\t\t\tstorage.get<string>(KEYS.NAME),\n\t\t\tstorage.get<string[]>(KEYS.KEY),\n\t\t]);\n\n\t\tif (!name) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing name`);\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing key`);\n\t\t}\n\n\t\t// Create actor instance\n\t\tconst definition = lookupInRegistry(this.#registryConfig, name);\n\t\thandler.actor = definition.instantiate();\n\n\t\t// Start actor\n\t\tconst connDrivers = createGenericConnDrivers(\n\t\t\thandler.genericConnGlobalState,\n\t\t);\n\t\tawait handler.actor.start(\n\t\t\tconnDrivers,\n\t\t\tthis,\n\t\t\tthis.#inlineClient,\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t\t\"unknown\", // TODO: Support regions in Cloudflare\n\t\t);\n\n\t\t// Finish\n\t\thandler.actorPromise?.resolve();\n\t\thandler.actorPromise = undefined;\n\n\t\treturn handler.actor;\n\t}\n\n\tgetGenericConnGlobalState(actorId: string): GenericConnGlobalState {\n\t\tconst handler = this.#actors.get(actorId);\n\t\tif (!handler) {\n\t\t\tthrow new Error(`Actor ${actorId} not loaded`);\n\t\t}\n\t\treturn handler.genericConnGlobalState;\n\t}\n\n\tgetContext(actorId: string): ActorDriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { ctx: state.ctx, env: state.env };\n\t}\n\n\tasync readPersistedData(actorId: string): Promise<Uint8Array | undefined> {\n\t\treturn await this.#getDOCtx(actorId).storage.get(KEYS.PERSIST_DATA);\n\t}\n\n\tasync writePersistedData(actorId: string, data: Uint8Array): Promise<void> {\n\t\tawait this.#getDOCtx(actorId).storage.put(KEYS.PERSIST_DATA, data);\n\t}\n\n\tasync setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {\n\t\tawait this.#getDOCtx(actor.id).storage.setAlarm(timestamp);\n\t}\n\n\tasync getDatabase(actorId: string): Promise<unknown | undefined> {\n\t\treturn this.#getDOCtx(actorId).storage.sql;\n\t}\n}\n\nexport function createCloudflareActorsActorDriverBuilder(\n\tglobalState: CloudflareDurableObjectGlobalState,\n) {\n\treturn (\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t) => {\n\t\treturn new CloudflareActorsActorDriver(\n\t\t\tregistryConfig,\n\t\t\trunConfig,\n\t\t\tmanagerDriver,\n\t\t\tinlineClient,\n\t\t\tglobalState,\n\t\t);\n\t};\n}\n","import { getLogger } from \"@rivetkit/core/log\";\n\nexport const LOGGER_NAME = \"driver-cloudflare-workers\";\n\nexport function logger() {\n\treturn getLogger(LOGGER_NAME);\n}\n","import { RunConfigSchema } from \"@rivetkit/core/driver-helpers\";\nimport type { Hono } from \"hono\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\tapp: z.custom<Hono>().optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Encoding } from \"@rivetkit/core\";\nimport {\n\ttype ActorOutput,\n\ttype CreateInput,\n\ttype GetForIdInput,\n\ttype GetOrCreateWithKeyInput,\n\ttype GetWithKeyInput,\n\tHEADER_AUTH_DATA,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ENCODING,\n\tHEADER_EXPOSE_INTERNAL_ERROR,\n\ttype ManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"@rivetkit/core/errors\";\nimport type { Context as HonoContext } from \"hono\";\nimport { getCloudflareAmbientEnv } from \"./handler\";\nimport { logger } from \"./log\";\nimport type { Bindings } from \"./mod\";\nimport { serializeKey, serializeNameAndKey } from \"./util\";\n\n// Actor metadata structure\ninterface ActorData {\n\tname: string;\n\tkey: string[];\n}\n\n// Key constants similar to Redis implementation\nconst KEYS = {\n\tACTOR: {\n\t\t// Combined key for actor metadata (name and key)\n\t\tmetadata: (actorId: string) => `actor:${actorId}:metadata`,\n\n\t\t// Key index function for actor lookup\n\t\tkeyIndex: (name: string, key: string[] = []) => {\n\t\t\t// Use serializeKey for consistent handling of all keys\n\t\t\treturn `actor_key:${serializeKey(key)}`;\n\t\t},\n\t},\n};\n\nconst STANDARD_WEBSOCKET_HEADERS = [\n\t\"connection\",\n\t\"upgrade\",\n\t\"sec-websocket-key\",\n\t\"sec-websocket-version\",\n\t\"sec-websocket-protocol\",\n\t\"sec-websocket-extensions\",\n];\n\nexport class CloudflareActorsManagerDriver implements ManagerDriver {\n\tasync sendRequest(actorId: string, actorRequest: Request): Promise<Response> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"sending request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync openWebSocket(\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t): Promise<WebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"opening websocket to durable object\", { actorId, path });\n\n\t\t// Make a fetch request to the Durable Object with WebSocket upgrade\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\tconst headers: Record<string, string> = {\n\t\t\tUpgrade: \"websocket\",\n\t\t\tConnection: \"Upgrade\",\n\t\t\t[HEADER_EXPOSE_INTERNAL_ERROR]: \"true\",\n\t\t\t[HEADER_ENCODING]: encoding,\n\t\t};\n\t\tif (params) {\n\t\t\theaders[HEADER_CONN_PARAMS] = JSON.stringify(params);\n\t\t}\n\t\t// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts\n\t\theaders[\"sec-websocket-protocol\"] = \"rivetkit\";\n\n\t\t// Use the path parameter to determine the URL\n\t\tconst url = `http://actor${path}`;\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: path,\n\t\t\tto: url,\n\t\t});\n\n\t\tconst response = await stub.fetch(url, {\n\t\t\theaders,\n\t\t});\n\t\tconst webSocket = response.webSocket;\n\n\t\tif (!webSocket) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"missing websocket connection in response from DO\",\n\t\t\t);\n\t\t}\n\n\t\tlogger().debug(\"durable object websocket connection open\", {\n\t\t\tactorId,\n\t\t});\n\n\t\twebSocket.accept();\n\n\t\t// TODO: Is this still needed?\n\t\t// HACK: Cloudflare does not call onopen automatically, so we need\n\t\t// to call this on the next tick\n\t\tsetTimeout(() => {\n\t\t\tconst event = new Event(\"open\");\n\t\t\t(webSocket as any).onopen?.(event);\n\t\t\t(webSocket as any).dispatchEvent(event);\n\t\t}, 0);\n\n\t\treturn webSocket as unknown as WebSocket;\n\t}\n\n\tasync proxyRequest(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tactorRequest: Request,\n\t\tactorId: string,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync proxyWebSocket(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t\tauthData: unknown,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding websocket to durable object\", {\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\n\n\t\t// Validate upgrade\n\t\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\t\tif (!upgradeHeader || upgradeHeader !== \"websocket\") {\n\t\t\treturn new Response(\"Expected Upgrade: websocket\", {\n\t\t\t\tstatus: 426,\n\t\t\t});\n\t\t}\n\n\t\t// TODO: strip headers\n\t\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: c.req.url,\n\t\t\tto: actorRequest.url,\n\t\t});\n\n\t\t// Always build fresh request to prevent forwarding unwanted headers\n\t\t// HACK: Since we can't build a new request, we need to remove\n\t\t// non-standard headers manually\n\t\tconst headerKeys: string[] = [];\n\t\tactorRequest.headers.forEach((v, k) => headerKeys.push(k));\n\t\tfor (const k of headerKeys) {\n\t\t\tif (!STANDARD_WEBSOCKET_HEADERS.includes(k)) {\n\t\t\t\tactorRequest.headers.delete(k);\n\t\t\t}\n\t\t}\n\n\t\t// Add RivetKit headers\n\t\tactorRequest.headers.set(HEADER_EXPOSE_INTERNAL_ERROR, \"true\");\n\t\tactorRequest.headers.set(HEADER_ENCODING, encoding);\n\t\tif (params) {\n\t\t\tactorRequest.headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));\n\t\t}\n\t\tif (authData) {\n\t\t\tactorRequest.headers.set(HEADER_AUTH_DATA, JSON.stringify(authData));\n\t\t}\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync getForId({\n\t\tc,\n\t\tactorId,\n\t}: GetForIdInput<{ Bindings: Bindings }>): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Get actor metadata from KV (combined name and key)\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\t// If the actor doesn't exist, return undefined\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n\n\tasync getWithKey({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t}: GetWithKeyInput<{ Bindings: Bindings }>): Promise<\n\t\tActorOutput | undefined\n\t> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"getWithKey: searching for actor\", { name, key });\n\n\t\t// Generate deterministic ID from the name and key\n\t\t// This is aligned with how createActor generates IDs\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst actorId = env.ACTOR_DO.idFromName(nameKeyString).toString();\n\n\t\t// Check if the actor metadata exists\n\t\tconst actorData = await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t});\n\n\t\tif (!actorData) {\n\t\t\tlogger().debug(\"getWithKey: no actor found with matching name and key\", {\n\t\t\t\tname,\n\t\t\t\tkey,\n\t\t\t\tactorId,\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlogger().debug(\"getWithKey: found actor with matching name and key\", {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t});\n\t\treturn this.#buildActorOutput(c, actorId);\n\t}\n\n\tasync getOrCreateWithKey(\n\t\tinput: GetOrCreateWithKeyInput,\n\t): Promise<ActorOutput> {\n\t\t// TODO: Prevent race condition here\n\t\tconst getOutput = await this.getWithKey(input);\n\t\tif (getOutput) {\n\t\t\treturn getOutput;\n\t\t} else {\n\t\t\treturn await this.createActor(input);\n\t\t}\n\t}\n\n\tasync createActor({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t\tinput,\n\t}: CreateInput<{ Bindings: Bindings }>): Promise<ActorOutput> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Check if actor with the same name and key already exists\n\t\tconst existingActor = await this.getWithKey({ c, name, key });\n\t\tif (existingActor) {\n\t\t\tthrow new ActorAlreadyExists(name, key);\n\t\t}\n\n\t\t// Create a deterministic ID from the actor name and key\n\t\t// This ensures that actors with the same name and key will have the same ID\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst doId = env.ACTOR_DO.idFromName(nameKeyString);\n\t\tconst actorId = doId.toString();\n\n\t\t// Init actor\n\t\tconst actor = env.ACTOR_DO.get(doId);\n\t\tawait actor.initialize({\n\t\t\tname,\n\t\t\tkey,\n\t\t\tinput,\n\t\t});\n\n\t\t// Store combined actor metadata (name and key)\n\t\tconst actorData: ActorData = { name, key };\n\t\tawait env.ACTOR_KV.put(\n\t\t\tKEYS.ACTOR.metadata(actorId),\n\t\t\tJSON.stringify(actorData),\n\t\t);\n\n\t\t// Add to key index for lookups by name and key\n\t\tawait env.ACTOR_KV.put(KEYS.ACTOR.keyIndex(name, key), actorId);\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t};\n\t}\n\n\t// Helper method to build actor output from an ID\n\tasync #buildActorOutput(\n\t\tc: any,\n\t\tactorId: string,\n\t): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n}\n","// Constants for key handling\nexport const EMPTY_KEY = \"(none)\";\nexport const KEY_SEPARATOR = \",\";\n\n/**\n * Serializes an array of key strings into a single string for use with idFromName\n *\n * @param name The actor name\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized name and key\n */\nexport function serializeNameAndKey(name: string, key: string[]): string {\n\t// Escape colons in the name\n\tconst escapedName = name.replace(/:/g, \"\\\\:\");\n\n\t// For empty keys, just return the name and a marker\n\tif (key.length === 0) {\n\t\treturn `${escapedName}:${EMPTY_KEY}`;\n\t}\n\n\t// Serialize the key array\n\tconst serializedKey = serializeKey(key);\n\n\t// Combine name and serialized key\n\treturn `${escapedName}:${serializedKey}`;\n}\n\n/**\n * Serializes an array of key strings into a single string\n *\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized key\n */\nexport function serializeKey(key: string[]): string {\n\t// Use a special marker for empty key arrays\n\tif (key.length === 0) {\n\t\treturn EMPTY_KEY;\n\t}\n\n\t// Escape each key part to handle the separator and the empty key marker\n\tconst escapedParts = key.map((part) => {\n\t\t// First check if it matches our empty key marker\n\t\tif (part === EMPTY_KEY) {\n\t\t\treturn `\\\\${EMPTY_KEY}`;\n\t\t}\n\n\t\t// Escape backslashes first, then commas\n\t\tlet escaped = part.replace(/\\\\/g, \"\\\\\\\\\");\n\t\tescaped = escaped.replace(/,/g, \"\\\\,\");\n\t\treturn escaped;\n\t});\n\n\treturn escapedParts.join(KEY_SEPARATOR);\n}\n\n/**\n * Deserializes a key string back into an array of key strings\n *\n * @param keyString The serialized key string\n * @returns Array of key strings\n */\nexport function deserializeKey(keyString: string): string[] {\n\t// Handle empty values\n\tif (!keyString) {\n\t\treturn [];\n\t}\n\n\t// Check for special empty key marker\n\tif (keyString === EMPTY_KEY) {\n\t\treturn [];\n\t}\n\n\t// Split by unescaped commas and unescape the escaped characters\n\tconst parts: string[] = [];\n\tlet currentPart = \"\";\n\tlet escaping = false;\n\n\tfor (let i = 0; i < keyString.length; i++) {\n\t\tconst char = keyString[i];\n\n\t\tif (escaping) {\n\t\t\t// This is an escaped character, add it directly\n\t\t\tcurrentPart += char;\n\t\t\tescaping = false;\n\t\t} else if (char === \"\\\\\") {\n\t\t\t// Start of an escape sequence\n\t\t\tescaping = true;\n\t\t} else if (char === KEY_SEPARATOR) {\n\t\t\t// This is a separator\n\t\t\tparts.push(currentPart);\n\t\t\tcurrentPart = \"\";\n\t\t} else {\n\t\t\t// Regular character\n\t\t\tcurrentPart += char;\n\t\t}\n\t}\n\n\t// Add the last part if it exists\n\tif (currentPart || parts.length > 0) {\n\t\tparts.push(currentPart);\n\t}\n\n\treturn parts;\n}\n","// Modified from https://github.com/honojs/hono/blob/40ea0eee58e39b31053a0246c595434f1094ad31/src/adapter/cloudflare-workers/websocket.ts#L17\n//\n// This version calls the open event by default\n\nimport type { UpgradeWebSocket, WSEvents, WSReadyState } from \"hono/ws\";\nimport { defineWebSocketHelper, WSContext } from \"hono/ws\";\n\n// Based on https://github.com/honojs/hono/issues/1153#issuecomment-1767321332\nexport const upgradeWebSocket: UpgradeWebSocket<\n\tWebSocket,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tWSEvents<WebSocket>\n> = defineWebSocketHelper(async (c, events) => {\n\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\tif (upgradeHeader !== \"websocket\") {\n\t\treturn;\n\t}\n\n\tconst webSocketPair = new WebSocketPair();\n\tconst client: WebSocket = webSocketPair[0];\n\tconst server: WebSocket = webSocketPair[1];\n\n\tconst wsContext = new WSContext<WebSocket>({\n\t\tclose: (code, reason) => server.close(code, reason),\n\t\tget protocol() {\n\t\t\treturn server.protocol;\n\t\t},\n\t\traw: server,\n\t\tget readyState() {\n\t\t\treturn server.readyState as WSReadyState;\n\t\t},\n\t\turl: server.url ? new URL(server.url) : null,\n\t\tsend: (source) => server.send(source),\n\t});\n\n\tif (events.onClose) {\n\t\tserver.addEventListener(\"close\", (evt: CloseEvent) =>\n\t\t\tevents.onClose?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onMessage) {\n\t\tserver.addEventListener(\"message\", (evt: MessageEvent) =>\n\t\t\tevents.onMessage?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onError) {\n\t\tserver.addEventListener(\"error\", (evt: Event) =>\n\t\t\tevents.onError?.(evt, wsContext),\n\t\t);\n\t}\n\n\tserver.accept?.();\n\n\t// note: cloudflare actors doesn't support 'open' event, so we call it immediately with a fake event\n\t//\n\t// we have to do this after `server.accept() is called`\n\tevents.onOpen?.(new Event(\"open\"), wsContext);\n\n\treturn new Response(null, {\n\t\tstatus: 101,\n\t\theaders: {\n\t\t\t// HACK: Required in order for Cloudflare to not error with \"Network connection lost\"\n\t\t\t//\n\t\t\t// This bug undocumented. Cannot easily reproduce outside of RivetKit.\n\t\t\t\"Sec-WebSocket-Protocol\": \"rivetkit\",\n\t\t},\n\t\twebSocket: client,\n\t});\n});\n"]}
1
+ {"version":3,"sources":["/home/nathan/rivetkit/packages/drivers/cloudflare-workers/dist/mod.cjs","../src/handler.ts","../src/actor-handler-do.ts","../src/actor-driver.ts","../src/log.ts","../src/config.ts","../src/manager-driver.ts","../src/util.ts","../src/websocket.ts"],"names":["_a","invariant","ActorHandler"],"mappings":"AAAA;ACAA,0CAAkC;AAGlC,4BAAqB;AACrB,4FAAsB;ADAtB;AACA;AELA,uDAA8B;AAO9B;AACC;AACA;AACA;AAAA,sCACM;AACP,8DAA0C;AFC1C;AACA;AGTA;AACC;AACA;AACA;AAAA;AAQD;AAaO,IAAM,mCAAA,EAAN,MAAyC;AAAA;AAAA,EAE/C,CAAA,IAAA,kBAA8C,IAAI,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AAA;AACD,EAAA;AACR;AAEgB;AAIT,EAAA;AAGA,EAAA;AACG,IAAA;AACD,MAAA;AACN,MAAA;AAAiD;AAEjD,MAAA;AACD,IAAA;AACA,IAAA;AACG,IAAA;AACJ,EAAA;AAGMC,EAAAA;AAGA,EAAA;AAEC,EAAA;AACE,IAAA;AACR,IAAA;AAEO,MAAA;AAGD,MAAA;AACA,QAAA;AACL,MAAA;AAGM,MAAA;AACL,QAAA;AACC,UAAA;AACD,QAAA;AACD,MAAA;AAEA,MAAA;AACD,IAAA;AACD,EAAA;AACD;ADygBY;AACA;AACA;AACA","file":"/home/nathan/rivetkit/packages/drivers/cloudflare-workers/dist/mod.cjs","sourcesContent":[null,"import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Registry, RunConfig } from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport { Hono } from \"hono\";\nimport invariant from \"invariant\";\nimport {\n\ttype ActorHandlerInterface,\n\tcreateActorDurableObject,\n\ttype DurableObjectConstructor,\n} from \"./actor-handler-do\";\nimport { ConfigSchema, type InputConfig } from \"./config\";\nimport { CloudflareActorsManagerDriver } from \"./manager-driver\";\nimport { upgradeWebSocket } from \"./websocket\";\n\n/** Cloudflare Workers env */\nexport interface Bindings {\n\tACTOR_KV: KVNamespace;\n\tACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>;\n}\n\n/**\n * Stores the env for the current request. Required since some contexts like the inline client driver does not have access to the Hono context.\n *\n * Use getCloudflareAmbientEnv unless using CF_AMBIENT_ENV.run.\n */\nexport const CF_AMBIENT_ENV = new AsyncLocalStorage<Bindings>();\n\nexport function getCloudflareAmbientEnv(): Bindings {\n\tconst env = CF_AMBIENT_ENV.getStore();\n\tinvariant(env, \"missing CF_AMBIENT_ENV\");\n\treturn env;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\ninterface SetupOutput<A extends Registry<any>> {\n\tclient: Client<A>;\n\tcreateHandler: (hono?: Hono) => Handler;\n}\n\nexport function createServerHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst { createHandler } = createServer(registry, inputConfig);\n\treturn createHandler();\n}\n\nexport function createServer<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): SetupOutput<R> {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\tdriver: {\n\t\t\tname: \"cloudflare-workers\",\n\t\t\tmanager: () => new CloudflareActorsManagerDriver(),\n\t\t\t// HACK: We can't build the actor driver until we're inside the Durable Object\n\t\t\tactor: undefined as any,\n\t\t},\n\t\tgetUpgradeWebSocket: () => upgradeWebSocket,\n\t\t...config,\n\t} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.createServer(runConfig);\n\n\treturn {\n\t\tclient: serverOutput.client as Client<R>,\n\t\tcreateHandler: (hono) => {\n\t\t\t// Build base router\n\t\t\tconst app = hono ?? new Hono();\n\n\t\t\t// Mount registry router at /registry\n\t\t\tif (!hono) {\n\t\t\t\tapp.route(\"/registry\", serverOutput.hono);\n\t\t\t}\n\n\t\t\t// Create Cloudflare handler\n\t\t\tconst handler = {\n\t\t\t\tfetch: (request, env, ctx) => {\n\t\t\t\t\treturn CF_AMBIENT_ENV.run(env, () => app.fetch(request, env, ctx));\n\t\t\t\t},\n\t\t\t} satisfies ExportedHandler<Bindings>;\n\n\t\t\treturn { handler, ActorHandler };\n\t\t},\n\t};\n}\n","import { DurableObject } from \"cloudflare:workers\";\nimport type {\n\tActorKey,\n\tActorRouter,\n\tRegistry,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateActorRouter,\n\tcreateClientWithDriver,\n\tcreateInlineClientDriver,\n} from \"@rivetkit/core\";\nimport { serializeEmptyPersistData } from \"@rivetkit/core/driver-helpers\";\nimport type { ExecutionContext } from \"hono\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport { type Bindings, CF_AMBIENT_ENV } from \"./handler\";\nimport { logger } from \"./log\";\n\nexport const KEYS = {\n\tNAME: \"rivetkit:name\",\n\tKEY: \"rivetkit:key\",\n\tPERSIST_DATA: \"rivetkit:data\",\n};\n\nexport interface ActorHandlerInterface extends DurableObject {\n\tinitialize(req: ActorInitRequest): Promise<void>;\n}\n\nexport interface ActorInitRequest {\n\tname: string;\n\tkey: ActorKey;\n\tinput?: unknown;\n}\n\ninterface InitializedData {\n\tname: string;\n\tkey: ActorKey;\n}\n\nexport type DurableObjectConstructor = new (\n\t...args: ConstructorParameters<typeof DurableObject<Bindings>>\n) => DurableObject<Bindings>;\n\ninterface LoadedActor {\n\tactorRouter: ActorRouter;\n}\n\nexport function createActorDurableObject(\n\tregistry: Registry<any>,\n\trunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t/**\n\t * Startup steps:\n\t * 1. If not already created call `initialize`, otherwise check KV to ensure it's initialized\n\t * 2. Load actor\n\t * 3. Start service requests\n\t */\n\treturn class ActorHandler\n\t\textends DurableObject<Bindings>\n\t\timplements ActorHandlerInterface\n\t{\n\t\t#initialized?: InitializedData;\n\t\t#initializedPromise?: PromiseWithResolvers<void>;\n\n\t\t#actor?: LoadedActor;\n\n\t\tasync #loadActor(): Promise<LoadedActor> {\n\t\t\t// This is always called from another context using CF_AMBIENT_ENV\n\n\t\t\t// Wait for init\n\t\t\tif (!this.#initialized) {\n\t\t\t\t// Wait for init\n\t\t\t\tif (this.#initializedPromise) {\n\t\t\t\t\tawait this.#initializedPromise.promise;\n\t\t\t\t} else {\n\t\t\t\t\tthis.#initializedPromise = Promise.withResolvers();\n\t\t\t\t\tconst res = await this.ctx.storage.get([\n\t\t\t\t\t\tKEYS.NAME,\n\t\t\t\t\t\tKEYS.KEY,\n\t\t\t\t\t\tKEYS.PERSIST_DATA,\n\t\t\t\t\t]);\n\t\t\t\t\tif (res.get(KEYS.PERSIST_DATA)) {\n\t\t\t\t\t\tconst name = res.get(KEYS.NAME) as string;\n\t\t\t\t\t\tif (!name) throw new Error(\"missing actor name\");\n\t\t\t\t\t\tconst key = res.get(KEYS.KEY) as ActorKey;\n\t\t\t\t\t\tif (!key) throw new Error(\"missing actor key\");\n\n\t\t\t\t\t\tlogger().debug(\"already initialized\", { name, key });\n\n\t\t\t\t\t\tthis.#initialized = { name, key };\n\t\t\t\t\t\tthis.#initializedPromise.resolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger().debug(\"waiting to initialize\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check if already loaded\n\t\t\tif (this.#actor) {\n\t\t\t\treturn this.#actor;\n\t\t\t}\n\n\t\t\tif (!this.#initialized) throw new Error(\"Not initialized\");\n\n\t\t\t// Register DO with global state first\n\t\t\t// HACK: This leaks the DO context, but DO does not provide a native way\n\t\t\t// of knowing when the DO shuts down. We're making a broad assumption\n\t\t\t// that DO will boot a new isolate frequenlty enough that this is not an issue.\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\tglobalState.setDOState(actorId, { ctx: this.ctx, env: this.env });\n\n\t\t\t// Configure actor driver\n\t\t\trunConfig.driver.actor =\n\t\t\t\tcreateCloudflareActorsActorDriverBuilder(globalState);\n\n\t\t\t// Create manager driver (we need this for the actor router)\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\n\t\t\t// Create inline client\n\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t);\n\n\t\t\t// Create actor driver\n\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t\tmanagerDriver,\n\t\t\t\tinlineClient,\n\t\t\t);\n\n\t\t\t// Create actor router\n\t\t\tconst actorRouter = createActorRouter(runConfig, actorDriver);\n\n\t\t\t// Save actor\n\t\t\tthis.#actor = {\n\t\t\t\tactorRouter,\n\t\t\t};\n\n\t\t\t// Initialize the actor instance with proper metadata\n\t\t\t// This ensures the actor driver knows about this actor\n\t\t\tawait actorDriver.loadActor(actorId);\n\n\t\t\treturn this.#actor;\n\t\t}\n\n\t\t/** RPC called by the service that creates the DO to initialize it. */\n\t\tasync initialize(req: ActorInitRequest) {\n\t\t\t// TODO: Need to add this to a core promise that needs to be resolved before start\n\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.ctx.storage.put({\n\t\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t\t});\n\t\t\t\tthis.#initialized = {\n\t\t\t\t\tname: req.name,\n\t\t\t\t\tkey: req.key,\n\t\t\t\t};\n\n\t\t\t\tlogger().debug(\"initialized actor\", { key: req.key });\n\n\t\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\t\tawait this.#loadActor();\n\t\t\t});\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\t\tactorId,\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.#loadActor();\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t\t// Get the actor driver\n\t\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t);\n\t\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t\t);\n\t\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t\tmanagerDriver,\n\t\t\t\t\tinlineClient,\n\t\t\t\t);\n\n\t\t\t\t// Load the actor instance and trigger alarm\n\t\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\t\tawait actor.onAlarm();\n\t\t\t});\n\t\t}\n\t};\n}\n","import type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport invariant from \"invariant\";\nimport { KEYS } from \"./actor-handler-do\";\n\ninterface DurableObjectGlobalState {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n/**\n * Cloudflare DO can have multiple DO running within the same global scope.\n *\n * This allows for storing the actor context globally and looking it up by ID in `CloudflareActorsActorDriver`.\n */\nexport class CloudflareDurableObjectGlobalState {\n\t// Single map for all actor state\n\t#dos: Map<string, DurableObjectGlobalState> = new Map();\n\n\tgetDOState(actorId: string): DurableObjectGlobalState {\n\t\tconst state = this.#dos.get(actorId);\n\t\tinvariant(state !== undefined, \"durable object state not in global state\");\n\t\treturn state;\n\t}\n\n\tsetDOState(actorId: string, state: DurableObjectGlobalState) {\n\t\tthis.#dos.set(actorId, state);\n\t}\n}\n\nexport interface ActorDriverContext {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n// Actor handler to track running instances\nclass ActorHandler {\n\tactor?: AnyActorInstance;\n\tactorPromise?: PromiseWithResolvers<void> = Promise.withResolvers();\n\tgenericConnGlobalState = new GenericConnGlobalState();\n}\n\nexport class CloudflareActorsActorDriver implements ActorDriver {\n\t#registryConfig: RegistryConfig;\n\t#runConfig: RunConfig;\n\t#managerDriver: ManagerDriver;\n\t#inlineClient: Client<any>;\n\t#globalState: CloudflareDurableObjectGlobalState;\n\t#actors: Map<string, ActorHandler> = new Map();\n\n\tconstructor(\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t\tglobalState: CloudflareDurableObjectGlobalState,\n\t) {\n\t\tthis.#registryConfig = registryConfig;\n\t\tthis.#runConfig = runConfig;\n\t\tthis.#managerDriver = managerDriver;\n\t\tthis.#inlineClient = inlineClient;\n\t\tthis.#globalState = globalState;\n\t}\n\n\t#getDOCtx(actorId: string) {\n\t\treturn this.#globalState.getDOState(actorId).ctx;\n\t}\n\n\tasync loadActor(actorId: string): Promise<AnyActorInstance> {\n\t\t// Check if actor is already loaded\n\t\tlet handler = this.#actors.get(actorId);\n\t\tif (handler) {\n\t\t\tif (handler.actorPromise) await handler.actorPromise.promise;\n\t\t\tif (!handler.actor) throw new Error(\"Actor should be loaded\");\n\t\t\treturn handler.actor;\n\t\t}\n\n\t\t// Create new actor handler\n\t\thandler = new ActorHandler();\n\t\tthis.#actors.set(actorId, handler);\n\n\t\t// Get the actor metadata from Durable Object storage\n\t\tconst doState = this.#globalState.getDOState(actorId);\n\t\tconst storage = doState.ctx.storage;\n\n\t\t// Load actor metadata\n\t\tconst [name, key] = await Promise.all([\n\t\t\tstorage.get<string>(KEYS.NAME),\n\t\t\tstorage.get<string[]>(KEYS.KEY),\n\t\t]);\n\n\t\tif (!name) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing name`);\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing key`);\n\t\t}\n\n\t\t// Create actor instance\n\t\tconst definition = lookupInRegistry(this.#registryConfig, name);\n\t\thandler.actor = definition.instantiate();\n\n\t\t// Start actor\n\t\tconst connDrivers = createGenericConnDrivers(\n\t\t\thandler.genericConnGlobalState,\n\t\t);\n\t\tawait handler.actor.start(\n\t\t\tconnDrivers,\n\t\t\tthis,\n\t\t\tthis.#inlineClient,\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t\t\"unknown\", // TODO: Support regions in Cloudflare\n\t\t);\n\n\t\t// Finish\n\t\thandler.actorPromise?.resolve();\n\t\thandler.actorPromise = undefined;\n\n\t\treturn handler.actor;\n\t}\n\n\tgetGenericConnGlobalState(actorId: string): GenericConnGlobalState {\n\t\tconst handler = this.#actors.get(actorId);\n\t\tif (!handler) {\n\t\t\tthrow new Error(`Actor ${actorId} not loaded`);\n\t\t}\n\t\treturn handler.genericConnGlobalState;\n\t}\n\n\tgetContext(actorId: string): ActorDriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { ctx: state.ctx, env: state.env };\n\t}\n\n\tasync readPersistedData(actorId: string): Promise<Uint8Array | undefined> {\n\t\treturn await this.#getDOCtx(actorId).storage.get(KEYS.PERSIST_DATA);\n\t}\n\n\tasync writePersistedData(actorId: string, data: Uint8Array): Promise<void> {\n\t\tawait this.#getDOCtx(actorId).storage.put(KEYS.PERSIST_DATA, data);\n\t}\n\n\tasync setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {\n\t\tawait this.#getDOCtx(actor.id).storage.setAlarm(timestamp);\n\t}\n\n\tasync getDatabase(actorId: string): Promise<unknown | undefined> {\n\t\treturn this.#getDOCtx(actorId).storage.sql;\n\t}\n}\n\nexport function createCloudflareActorsActorDriverBuilder(\n\tglobalState: CloudflareDurableObjectGlobalState,\n) {\n\treturn (\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t) => {\n\t\treturn new CloudflareActorsActorDriver(\n\t\t\tregistryConfig,\n\t\t\trunConfig,\n\t\t\tmanagerDriver,\n\t\t\tinlineClient,\n\t\t\tglobalState,\n\t\t);\n\t};\n}\n","import { getLogger } from \"@rivetkit/core/log\";\n\nexport const LOGGER_NAME = \"driver-cloudflare-workers\";\n\nexport function logger() {\n\treturn getLogger(LOGGER_NAME);\n}\n","import { RunConfigSchema } from \"@rivetkit/core/driver-helpers\";\nimport type { Hono } from \"hono\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\tapp: z.custom<Hono>().optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Encoding } from \"@rivetkit/core\";\nimport {\n\ttype ActorOutput,\n\ttype CreateInput,\n\ttype GetForIdInput,\n\ttype GetOrCreateWithKeyInput,\n\ttype GetWithKeyInput,\n\tHEADER_AUTH_DATA,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ENCODING,\n\tHEADER_EXPOSE_INTERNAL_ERROR,\n\ttype ManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"@rivetkit/core/errors\";\nimport type { Context as HonoContext } from \"hono\";\nimport { getCloudflareAmbientEnv } from \"./handler\";\nimport { logger } from \"./log\";\nimport type { Bindings } from \"./mod\";\nimport { serializeKey, serializeNameAndKey } from \"./util\";\n\n// Actor metadata structure\ninterface ActorData {\n\tname: string;\n\tkey: string[];\n}\n\n// Key constants similar to Redis implementation\nconst KEYS = {\n\tACTOR: {\n\t\t// Combined key for actor metadata (name and key)\n\t\tmetadata: (actorId: string) => `actor:${actorId}:metadata`,\n\n\t\t// Key index function for actor lookup\n\t\tkeyIndex: (name: string, key: string[] = []) => {\n\t\t\t// Use serializeKey for consistent handling of all keys\n\t\t\treturn `actor_key:${serializeKey(key)}`;\n\t\t},\n\t},\n};\n\nconst STANDARD_WEBSOCKET_HEADERS = [\n\t\"connection\",\n\t\"upgrade\",\n\t\"sec-websocket-key\",\n\t\"sec-websocket-version\",\n\t\"sec-websocket-protocol\",\n\t\"sec-websocket-extensions\",\n];\n\nexport class CloudflareActorsManagerDriver implements ManagerDriver {\n\tasync sendRequest(actorId: string, actorRequest: Request): Promise<Response> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"sending request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync openWebSocket(\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t): Promise<WebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"opening websocket to durable object\", { actorId, path });\n\n\t\t// Make a fetch request to the Durable Object with WebSocket upgrade\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\tconst headers: Record<string, string> = {\n\t\t\tUpgrade: \"websocket\",\n\t\t\tConnection: \"Upgrade\",\n\t\t\t[HEADER_EXPOSE_INTERNAL_ERROR]: \"true\",\n\t\t\t[HEADER_ENCODING]: encoding,\n\t\t};\n\t\tif (params) {\n\t\t\theaders[HEADER_CONN_PARAMS] = JSON.stringify(params);\n\t\t}\n\t\t// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts\n\t\theaders[\"sec-websocket-protocol\"] = \"rivetkit\";\n\n\t\t// Use the path parameter to determine the URL\n\t\tconst url = `http://actor${path}`;\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: path,\n\t\t\tto: url,\n\t\t});\n\n\t\tconst response = await stub.fetch(url, {\n\t\t\theaders,\n\t\t});\n\t\tconst webSocket = response.webSocket;\n\n\t\tif (!webSocket) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"missing websocket connection in response from DO\",\n\t\t\t);\n\t\t}\n\n\t\tlogger().debug(\"durable object websocket connection open\", {\n\t\t\tactorId,\n\t\t});\n\n\t\twebSocket.accept();\n\n\t\t// TODO: Is this still needed?\n\t\t// HACK: Cloudflare does not call onopen automatically, so we need\n\t\t// to call this on the next tick\n\t\tsetTimeout(() => {\n\t\t\tconst event = new Event(\"open\");\n\t\t\t(webSocket as any).onopen?.(event);\n\t\t\t(webSocket as any).dispatchEvent(event);\n\t\t}, 0);\n\n\t\treturn webSocket as unknown as WebSocket;\n\t}\n\n\tasync proxyRequest(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tactorRequest: Request,\n\t\tactorId: string,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync proxyWebSocket(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t\tauthData: unknown,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding websocket to durable object\", {\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\n\n\t\t// Validate upgrade\n\t\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\t\tif (!upgradeHeader || upgradeHeader !== \"websocket\") {\n\t\t\treturn new Response(\"Expected Upgrade: websocket\", {\n\t\t\t\tstatus: 426,\n\t\t\t});\n\t\t}\n\n\t\t// TODO: strip headers\n\t\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: c.req.url,\n\t\t\tto: actorRequest.url,\n\t\t});\n\n\t\t// Always build fresh request to prevent forwarding unwanted headers\n\t\t// HACK: Since we can't build a new request, we need to remove\n\t\t// non-standard headers manually\n\t\tconst headerKeys: string[] = [];\n\t\tactorRequest.headers.forEach((v, k) => headerKeys.push(k));\n\t\tfor (const k of headerKeys) {\n\t\t\tif (!STANDARD_WEBSOCKET_HEADERS.includes(k)) {\n\t\t\t\tactorRequest.headers.delete(k);\n\t\t\t}\n\t\t}\n\n\t\t// Add RivetKit headers\n\t\tactorRequest.headers.set(HEADER_EXPOSE_INTERNAL_ERROR, \"true\");\n\t\tactorRequest.headers.set(HEADER_ENCODING, encoding);\n\t\tif (params) {\n\t\t\tactorRequest.headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));\n\t\t}\n\t\tif (authData) {\n\t\t\tactorRequest.headers.set(HEADER_AUTH_DATA, JSON.stringify(authData));\n\t\t}\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync getForId({\n\t\tc,\n\t\tactorId,\n\t}: GetForIdInput<{ Bindings: Bindings }>): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Get actor metadata from KV (combined name and key)\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\t// If the actor doesn't exist, return undefined\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n\n\tasync getWithKey({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t}: GetWithKeyInput<{ Bindings: Bindings }>): Promise<\n\t\tActorOutput | undefined\n\t> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"getWithKey: searching for actor\", { name, key });\n\n\t\t// Generate deterministic ID from the name and key\n\t\t// This is aligned with how createActor generates IDs\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst actorId = env.ACTOR_DO.idFromName(nameKeyString).toString();\n\n\t\t// Check if the actor metadata exists\n\t\tconst actorData = await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t});\n\n\t\tif (!actorData) {\n\t\t\tlogger().debug(\"getWithKey: no actor found with matching name and key\", {\n\t\t\t\tname,\n\t\t\t\tkey,\n\t\t\t\tactorId,\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlogger().debug(\"getWithKey: found actor with matching name and key\", {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t});\n\t\treturn this.#buildActorOutput(c, actorId);\n\t}\n\n\tasync getOrCreateWithKey(\n\t\tinput: GetOrCreateWithKeyInput,\n\t): Promise<ActorOutput> {\n\t\t// TODO: Prevent race condition here\n\t\tconst getOutput = await this.getWithKey(input);\n\t\tif (getOutput) {\n\t\t\treturn getOutput;\n\t\t} else {\n\t\t\treturn await this.createActor(input);\n\t\t}\n\t}\n\n\tasync createActor({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t\tinput,\n\t}: CreateInput<{ Bindings: Bindings }>): Promise<ActorOutput> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Check if actor with the same name and key already exists\n\t\tconst existingActor = await this.getWithKey({ c, name, key });\n\t\tif (existingActor) {\n\t\t\tthrow new ActorAlreadyExists(name, key);\n\t\t}\n\n\t\t// Create a deterministic ID from the actor name and key\n\t\t// This ensures that actors with the same name and key will have the same ID\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst doId = env.ACTOR_DO.idFromName(nameKeyString);\n\t\tconst actorId = doId.toString();\n\n\t\t// Init actor\n\t\tconst actor = env.ACTOR_DO.get(doId);\n\t\tawait actor.initialize({\n\t\t\tname,\n\t\t\tkey,\n\t\t\tinput,\n\t\t});\n\n\t\t// Store combined actor metadata (name and key)\n\t\tconst actorData: ActorData = { name, key };\n\t\tawait env.ACTOR_KV.put(\n\t\t\tKEYS.ACTOR.metadata(actorId),\n\t\t\tJSON.stringify(actorData),\n\t\t);\n\n\t\t// Add to key index for lookups by name and key\n\t\tawait env.ACTOR_KV.put(KEYS.ACTOR.keyIndex(name, key), actorId);\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t};\n\t}\n\n\t// Helper method to build actor output from an ID\n\tasync #buildActorOutput(\n\t\tc: any,\n\t\tactorId: string,\n\t): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n}\n","// Constants for key handling\nexport const EMPTY_KEY = \"(none)\";\nexport const KEY_SEPARATOR = \",\";\n\n/**\n * Serializes an array of key strings into a single string for use with idFromName\n *\n * @param name The actor name\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized name and key\n */\nexport function serializeNameAndKey(name: string, key: string[]): string {\n\t// Escape colons in the name\n\tconst escapedName = name.replace(/:/g, \"\\\\:\");\n\n\t// For empty keys, just return the name and a marker\n\tif (key.length === 0) {\n\t\treturn `${escapedName}:${EMPTY_KEY}`;\n\t}\n\n\t// Serialize the key array\n\tconst serializedKey = serializeKey(key);\n\n\t// Combine name and serialized key\n\treturn `${escapedName}:${serializedKey}`;\n}\n\n/**\n * Serializes an array of key strings into a single string\n *\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized key\n */\nexport function serializeKey(key: string[]): string {\n\t// Use a special marker for empty key arrays\n\tif (key.length === 0) {\n\t\treturn EMPTY_KEY;\n\t}\n\n\t// Escape each key part to handle the separator and the empty key marker\n\tconst escapedParts = key.map((part) => {\n\t\t// First check if it matches our empty key marker\n\t\tif (part === EMPTY_KEY) {\n\t\t\treturn `\\\\${EMPTY_KEY}`;\n\t\t}\n\n\t\t// Escape backslashes first, then commas\n\t\tlet escaped = part.replace(/\\\\/g, \"\\\\\\\\\");\n\t\tescaped = escaped.replace(/,/g, \"\\\\,\");\n\t\treturn escaped;\n\t});\n\n\treturn escapedParts.join(KEY_SEPARATOR);\n}\n\n/**\n * Deserializes a key string back into an array of key strings\n *\n * @param keyString The serialized key string\n * @returns Array of key strings\n */\nexport function deserializeKey(keyString: string): string[] {\n\t// Handle empty values\n\tif (!keyString) {\n\t\treturn [];\n\t}\n\n\t// Check for special empty key marker\n\tif (keyString === EMPTY_KEY) {\n\t\treturn [];\n\t}\n\n\t// Split by unescaped commas and unescape the escaped characters\n\tconst parts: string[] = [];\n\tlet currentPart = \"\";\n\tlet escaping = false;\n\n\tfor (let i = 0; i < keyString.length; i++) {\n\t\tconst char = keyString[i];\n\n\t\tif (escaping) {\n\t\t\t// This is an escaped character, add it directly\n\t\t\tcurrentPart += char;\n\t\t\tescaping = false;\n\t\t} else if (char === \"\\\\\") {\n\t\t\t// Start of an escape sequence\n\t\t\tescaping = true;\n\t\t} else if (char === KEY_SEPARATOR) {\n\t\t\t// This is a separator\n\t\t\tparts.push(currentPart);\n\t\t\tcurrentPart = \"\";\n\t\t} else {\n\t\t\t// Regular character\n\t\t\tcurrentPart += char;\n\t\t}\n\t}\n\n\t// Add the last part if it exists\n\tif (currentPart || parts.length > 0) {\n\t\tparts.push(currentPart);\n\t}\n\n\treturn parts;\n}\n","// Modified from https://github.com/honojs/hono/blob/40ea0eee58e39b31053a0246c595434f1094ad31/src/adapter/cloudflare-workers/websocket.ts#L17\n//\n// This version calls the open event by default\n\nimport type { UpgradeWebSocket, WSEvents, WSReadyState } from \"hono/ws\";\nimport { defineWebSocketHelper, WSContext } from \"hono/ws\";\n\n// Based on https://github.com/honojs/hono/issues/1153#issuecomment-1767321332\nexport const upgradeWebSocket: UpgradeWebSocket<\n\tWebSocket,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tWSEvents<WebSocket>\n> = defineWebSocketHelper(async (c, events) => {\n\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\tif (upgradeHeader !== \"websocket\") {\n\t\treturn;\n\t}\n\n\tconst webSocketPair = new WebSocketPair();\n\tconst client: WebSocket = webSocketPair[0];\n\tconst server: WebSocket = webSocketPair[1];\n\n\tconst wsContext = new WSContext<WebSocket>({\n\t\tclose: (code, reason) => server.close(code, reason),\n\t\tget protocol() {\n\t\t\treturn server.protocol;\n\t\t},\n\t\traw: server,\n\t\tget readyState() {\n\t\t\treturn server.readyState as WSReadyState;\n\t\t},\n\t\turl: server.url ? new URL(server.url) : null,\n\t\tsend: (source) => server.send(source),\n\t});\n\n\tif (events.onClose) {\n\t\tserver.addEventListener(\"close\", (evt: CloseEvent) =>\n\t\t\tevents.onClose?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onMessage) {\n\t\tserver.addEventListener(\"message\", (evt: MessageEvent) =>\n\t\t\tevents.onMessage?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onError) {\n\t\tserver.addEventListener(\"error\", (evt: Event) =>\n\t\t\tevents.onError?.(evt, wsContext),\n\t\t);\n\t}\n\n\tserver.accept?.();\n\n\t// note: cloudflare actors doesn't support 'open' event, so we call it immediately with a fake event\n\t//\n\t// we have to do this after `server.accept() is called`\n\tevents.onOpen?.(new Event(\"open\"), wsContext);\n\n\treturn new Response(null, {\n\t\tstatus: 101,\n\t\theaders: {\n\t\t\t// HACK: Required in order for Cloudflare to not error with \"Network connection lost\"\n\t\t\t//\n\t\t\t// This bug undocumented. Cannot easily reproduce outside of RivetKit.\n\t\t\t\"Sec-WebSocket-Protocol\": \"rivetkit\",\n\t\t},\n\t\twebSocket: client,\n\t});\n});\n"]}
package/dist/mod.d.cts CHANGED
@@ -11,12 +11,15 @@ import { DurableObject } from 'cloudflare:workers';
11
11
 
12
12
  declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
13
13
  driver: z.ZodDefault<z.ZodOptional<z.ZodObject<{
14
+ name: z.ZodString;
14
15
  manager: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver>;
15
16
  actor: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver>;
16
17
  }, "strip", z.ZodTypeAny, {
18
+ name: string;
17
19
  actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver;
18
20
  manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver;
19
21
  }, {
22
+ name: string;
20
23
  actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver;
21
24
  manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver;
22
25
  }>>>;
@@ -37,10 +40,67 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
37
40
  exposeHeaders?: string[];
38
41
  }>>;
39
42
  maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
43
+ studio: z.ZodDefault<z.ZodOptional<z.ZodObject<{
44
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
45
+ cors: z.ZodDefault<z.ZodOptional<z.ZodType<{
46
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
47
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
48
+ allowHeaders?: string[];
49
+ maxAge?: number;
50
+ credentials?: boolean;
51
+ exposeHeaders?: string[];
52
+ }, z.ZodTypeDef, {
53
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
54
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
55
+ allowHeaders?: string[];
56
+ maxAge?: number;
57
+ credentials?: boolean;
58
+ exposeHeaders?: string[];
59
+ }>>>;
60
+ token: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>>>;
61
+ defaultEndpoint: z.ZodOptional<z.ZodString>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ enabled: boolean;
64
+ cors: {
65
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
66
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
67
+ allowHeaders?: string[];
68
+ maxAge?: number;
69
+ credentials?: boolean;
70
+ exposeHeaders?: string[];
71
+ };
72
+ token: (...args: unknown[]) => string;
73
+ defaultEndpoint?: string | undefined;
74
+ }, {
75
+ enabled?: boolean | undefined;
76
+ cors?: {
77
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
78
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
79
+ allowHeaders?: string[];
80
+ maxAge?: number;
81
+ credentials?: boolean;
82
+ exposeHeaders?: string[];
83
+ } | undefined;
84
+ token?: ((...args: unknown[]) => string) | undefined;
85
+ defaultEndpoint?: string | undefined;
86
+ }>>>;
40
87
  }, "driver" | "getUpgradeWebSocket"> & {
41
88
  app: z.ZodOptional<z.ZodType<Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">, z.ZodTypeDef, Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">>>;
42
89
  }, "strip", z.ZodTypeAny, {
43
90
  maxIncomingMessageSize: number;
91
+ studio: {
92
+ enabled: boolean;
93
+ cors: {
94
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
95
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
96
+ allowHeaders?: string[];
97
+ maxAge?: number;
98
+ credentials?: boolean;
99
+ exposeHeaders?: string[];
100
+ };
101
+ token: (...args: unknown[]) => string;
102
+ defaultEndpoint?: string | undefined;
103
+ };
44
104
  cors?: {
45
105
  origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
46
106
  allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
@@ -60,6 +120,19 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
60
120
  exposeHeaders?: string[];
61
121
  } | undefined;
62
122
  maxIncomingMessageSize?: number | undefined;
123
+ studio?: {
124
+ enabled?: boolean | undefined;
125
+ cors?: {
126
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
127
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
128
+ allowHeaders?: string[];
129
+ maxAge?: number;
130
+ credentials?: boolean;
131
+ exposeHeaders?: string[];
132
+ } | undefined;
133
+ token?: ((...args: unknown[]) => string) | undefined;
134
+ defaultEndpoint?: string | undefined;
135
+ } | undefined;
63
136
  app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined;
64
137
  }>>;
65
138
  type InputConfig = z.input<typeof ConfigSchema>;
package/dist/mod.d.ts CHANGED
@@ -11,12 +11,15 @@ import { DurableObject } from 'cloudflare:workers';
11
11
 
12
12
  declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
13
13
  driver: z.ZodDefault<z.ZodOptional<z.ZodObject<{
14
+ name: z.ZodString;
14
15
  manager: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver>;
15
16
  actor: z.ZodType<(registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver, z.ZodTypeDef, (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver>;
16
17
  }, "strip", z.ZodTypeAny, {
18
+ name: string;
17
19
  actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver;
18
20
  manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver;
19
21
  }, {
22
+ name: string;
20
23
  actor: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig, managerDriver: _rivetkit_core_driver_helpers.ManagerDriver, inlineClient: _rivetkit_core.AnyClient) => _rivetkit_core_driver_helpers.ActorDriver;
21
24
  manager: (registryConfig: _rivetkit_core.RegistryConfig, runConfig: _rivetkit_core.RunConfig) => _rivetkit_core_driver_helpers.ManagerDriver;
22
25
  }>>>;
@@ -37,10 +40,67 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
37
40
  exposeHeaders?: string[];
38
41
  }>>;
39
42
  maxIncomingMessageSize: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
43
+ studio: z.ZodDefault<z.ZodOptional<z.ZodObject<{
44
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
45
+ cors: z.ZodDefault<z.ZodOptional<z.ZodType<{
46
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
47
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
48
+ allowHeaders?: string[];
49
+ maxAge?: number;
50
+ credentials?: boolean;
51
+ exposeHeaders?: string[];
52
+ }, z.ZodTypeDef, {
53
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
54
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
55
+ allowHeaders?: string[];
56
+ maxAge?: number;
57
+ credentials?: boolean;
58
+ exposeHeaders?: string[];
59
+ }>>>;
60
+ token: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodString>>>;
61
+ defaultEndpoint: z.ZodOptional<z.ZodString>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ enabled: boolean;
64
+ cors: {
65
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
66
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
67
+ allowHeaders?: string[];
68
+ maxAge?: number;
69
+ credentials?: boolean;
70
+ exposeHeaders?: string[];
71
+ };
72
+ token: (...args: unknown[]) => string;
73
+ defaultEndpoint?: string | undefined;
74
+ }, {
75
+ enabled?: boolean | undefined;
76
+ cors?: {
77
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
78
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
79
+ allowHeaders?: string[];
80
+ maxAge?: number;
81
+ credentials?: boolean;
82
+ exposeHeaders?: string[];
83
+ } | undefined;
84
+ token?: ((...args: unknown[]) => string) | undefined;
85
+ defaultEndpoint?: string | undefined;
86
+ }>>>;
40
87
  }, "driver" | "getUpgradeWebSocket"> & {
41
88
  app: z.ZodOptional<z.ZodType<Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">, z.ZodTypeDef, Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/">>>;
42
89
  }, "strip", z.ZodTypeAny, {
43
90
  maxIncomingMessageSize: number;
91
+ studio: {
92
+ enabled: boolean;
93
+ cors: {
94
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
95
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
96
+ allowHeaders?: string[];
97
+ maxAge?: number;
98
+ credentials?: boolean;
99
+ exposeHeaders?: string[];
100
+ };
101
+ token: (...args: unknown[]) => string;
102
+ defaultEndpoint?: string | undefined;
103
+ };
44
104
  cors?: {
45
105
  origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
46
106
  allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
@@ -60,6 +120,19 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
60
120
  exposeHeaders?: string[];
61
121
  } | undefined;
62
122
  maxIncomingMessageSize?: number | undefined;
123
+ studio?: {
124
+ enabled?: boolean | undefined;
125
+ cors?: {
126
+ origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
127
+ allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
128
+ allowHeaders?: string[];
129
+ maxAge?: number;
130
+ credentials?: boolean;
131
+ exposeHeaders?: string[];
132
+ } | undefined;
133
+ token?: ((...args: unknown[]) => string) | undefined;
134
+ defaultEndpoint?: string | undefined;
135
+ } | undefined;
63
136
  app?: Hono<hono_types.BlankEnv, hono_types.BlankSchema, "/"> | undefined;
64
137
  }>>;
65
138
  type InputConfig = z.input<typeof ConfigSchema>;
package/dist/mod.js CHANGED
@@ -589,6 +589,7 @@ function createServer(registry, inputConfig) {
589
589
  const config = ConfigSchema.parse(inputConfig);
590
590
  const runConfig = {
591
591
  driver: {
592
+ name: "cloudflare-workers",
592
593
  manager: () => new CloudflareActorsManagerDriver(),
593
594
  // HACK: We can't build the actor driver until we're inside the Durable Object
594
595
  actor: void 0
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/handler.ts","../src/actor-handler-do.ts","../src/actor-driver.ts","../src/log.ts","../src/config.ts","../src/manager-driver.ts","../src/util.ts","../src/websocket.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Registry, RunConfig } from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport { Hono } from \"hono\";\nimport invariant from \"invariant\";\nimport {\n\ttype ActorHandlerInterface,\n\tcreateActorDurableObject,\n\ttype DurableObjectConstructor,\n} from \"./actor-handler-do\";\nimport { ConfigSchema, type InputConfig } from \"./config\";\nimport { CloudflareActorsManagerDriver } from \"./manager-driver\";\nimport { upgradeWebSocket } from \"./websocket\";\n\n/** Cloudflare Workers env */\nexport interface Bindings {\n\tACTOR_KV: KVNamespace;\n\tACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>;\n}\n\n/**\n * Stores the env for the current request. Required since some contexts like the inline client driver does not have access to the Hono context.\n *\n * Use getCloudflareAmbientEnv unless using CF_AMBIENT_ENV.run.\n */\nexport const CF_AMBIENT_ENV = new AsyncLocalStorage<Bindings>();\n\nexport function getCloudflareAmbientEnv(): Bindings {\n\tconst env = CF_AMBIENT_ENV.getStore();\n\tinvariant(env, \"missing CF_AMBIENT_ENV\");\n\treturn env;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\ninterface SetupOutput<A extends Registry<any>> {\n\tclient: Client<A>;\n\tcreateHandler: (hono?: Hono) => Handler;\n}\n\nexport function createServerHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst { createHandler } = createServer(registry, inputConfig);\n\treturn createHandler();\n}\n\nexport function createServer<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): SetupOutput<R> {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\tdriver: {\n\t\t\tmanager: () => new CloudflareActorsManagerDriver(),\n\t\t\t// HACK: We can't build the actor driver until we're inside the Durable Object\n\t\t\tactor: undefined as any,\n\t\t},\n\t\tgetUpgradeWebSocket: () => upgradeWebSocket,\n\t\t...config,\n\t} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.createServer(runConfig);\n\n\treturn {\n\t\tclient: serverOutput.client as Client<R>,\n\t\tcreateHandler: (hono) => {\n\t\t\t// Build base router\n\t\t\tconst app = hono ?? new Hono();\n\n\t\t\t// Mount registry router at /registry\n\t\t\tif (!hono) {\n\t\t\t\tapp.route(\"/registry\", serverOutput.hono);\n\t\t\t}\n\n\t\t\t// Create Cloudflare handler\n\t\t\tconst handler = {\n\t\t\t\tfetch: (request, env, ctx) => {\n\t\t\t\t\treturn CF_AMBIENT_ENV.run(env, () => app.fetch(request, env, ctx));\n\t\t\t\t},\n\t\t\t} satisfies ExportedHandler<Bindings>;\n\n\t\t\treturn { handler, ActorHandler };\n\t\t},\n\t};\n}\n","import { DurableObject } from \"cloudflare:workers\";\nimport type {\n\tActorKey,\n\tActorRouter,\n\tRegistry,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateActorRouter,\n\tcreateClientWithDriver,\n\tcreateInlineClientDriver,\n} from \"@rivetkit/core\";\nimport { serializeEmptyPersistData } from \"@rivetkit/core/driver-helpers\";\nimport type { ExecutionContext } from \"hono\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport { type Bindings, CF_AMBIENT_ENV } from \"./handler\";\nimport { logger } from \"./log\";\n\nexport const KEYS = {\n\tNAME: \"rivetkit:name\",\n\tKEY: \"rivetkit:key\",\n\tPERSIST_DATA: \"rivetkit:data\",\n};\n\nexport interface ActorHandlerInterface extends DurableObject {\n\tinitialize(req: ActorInitRequest): Promise<void>;\n}\n\nexport interface ActorInitRequest {\n\tname: string;\n\tkey: ActorKey;\n\tinput?: unknown;\n}\n\ninterface InitializedData {\n\tname: string;\n\tkey: ActorKey;\n}\n\nexport type DurableObjectConstructor = new (\n\t...args: ConstructorParameters<typeof DurableObject<Bindings>>\n) => DurableObject<Bindings>;\n\ninterface LoadedActor {\n\tactorRouter: ActorRouter;\n}\n\nexport function createActorDurableObject(\n\tregistry: Registry<any>,\n\trunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t/**\n\t * Startup steps:\n\t * 1. If not already created call `initialize`, otherwise check KV to ensure it's initialized\n\t * 2. Load actor\n\t * 3. Start service requests\n\t */\n\treturn class ActorHandler\n\t\textends DurableObject<Bindings>\n\t\timplements ActorHandlerInterface\n\t{\n\t\t#initialized?: InitializedData;\n\t\t#initializedPromise?: PromiseWithResolvers<void>;\n\n\t\t#actor?: LoadedActor;\n\n\t\tasync #loadActor(): Promise<LoadedActor> {\n\t\t\t// This is always called from another context using CF_AMBIENT_ENV\n\n\t\t\t// Wait for init\n\t\t\tif (!this.#initialized) {\n\t\t\t\t// Wait for init\n\t\t\t\tif (this.#initializedPromise) {\n\t\t\t\t\tawait this.#initializedPromise.promise;\n\t\t\t\t} else {\n\t\t\t\t\tthis.#initializedPromise = Promise.withResolvers();\n\t\t\t\t\tconst res = await this.ctx.storage.get([\n\t\t\t\t\t\tKEYS.NAME,\n\t\t\t\t\t\tKEYS.KEY,\n\t\t\t\t\t\tKEYS.PERSIST_DATA,\n\t\t\t\t\t]);\n\t\t\t\t\tif (res.get(KEYS.PERSIST_DATA)) {\n\t\t\t\t\t\tconst name = res.get(KEYS.NAME) as string;\n\t\t\t\t\t\tif (!name) throw new Error(\"missing actor name\");\n\t\t\t\t\t\tconst key = res.get(KEYS.KEY) as ActorKey;\n\t\t\t\t\t\tif (!key) throw new Error(\"missing actor key\");\n\n\t\t\t\t\t\tlogger().debug(\"already initialized\", { name, key });\n\n\t\t\t\t\t\tthis.#initialized = { name, key };\n\t\t\t\t\t\tthis.#initializedPromise.resolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger().debug(\"waiting to initialize\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check if already loaded\n\t\t\tif (this.#actor) {\n\t\t\t\treturn this.#actor;\n\t\t\t}\n\n\t\t\tif (!this.#initialized) throw new Error(\"Not initialized\");\n\n\t\t\t// Register DO with global state first\n\t\t\t// HACK: This leaks the DO context, but DO does not provide a native way\n\t\t\t// of knowing when the DO shuts down. We're making a broad assumption\n\t\t\t// that DO will boot a new isolate frequenlty enough that this is not an issue.\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\tglobalState.setDOState(actorId, { ctx: this.ctx, env: this.env });\n\n\t\t\t// Configure actor driver\n\t\t\trunConfig.driver.actor =\n\t\t\t\tcreateCloudflareActorsActorDriverBuilder(globalState);\n\n\t\t\t// Create manager driver (we need this for the actor router)\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\n\t\t\t// Create inline client\n\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t);\n\n\t\t\t// Create actor driver\n\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t\tmanagerDriver,\n\t\t\t\tinlineClient,\n\t\t\t);\n\n\t\t\t// Create actor router\n\t\t\tconst actorRouter = createActorRouter(runConfig, actorDriver);\n\n\t\t\t// Save actor\n\t\t\tthis.#actor = {\n\t\t\t\tactorRouter,\n\t\t\t};\n\n\t\t\t// Initialize the actor instance with proper metadata\n\t\t\t// This ensures the actor driver knows about this actor\n\t\t\tawait actorDriver.loadActor(actorId);\n\n\t\t\treturn this.#actor;\n\t\t}\n\n\t\t/** RPC called by the service that creates the DO to initialize it. */\n\t\tasync initialize(req: ActorInitRequest) {\n\t\t\t// TODO: Need to add this to a core promise that needs to be resolved before start\n\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.ctx.storage.put({\n\t\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t\t});\n\t\t\t\tthis.#initialized = {\n\t\t\t\t\tname: req.name,\n\t\t\t\t\tkey: req.key,\n\t\t\t\t};\n\n\t\t\t\tlogger().debug(\"initialized actor\", { key: req.key });\n\n\t\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\t\tawait this.#loadActor();\n\t\t\t});\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\t\tactorId,\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.#loadActor();\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t\t// Get the actor driver\n\t\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t);\n\t\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t\t);\n\t\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t\tmanagerDriver,\n\t\t\t\t\tinlineClient,\n\t\t\t\t);\n\n\t\t\t\t// Load the actor instance and trigger alarm\n\t\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\t\tawait actor.onAlarm();\n\t\t\t});\n\t\t}\n\t};\n}\n","import type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport invariant from \"invariant\";\nimport { KEYS } from \"./actor-handler-do\";\n\ninterface DurableObjectGlobalState {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n/**\n * Cloudflare DO can have multiple DO running within the same global scope.\n *\n * This allows for storing the actor context globally and looking it up by ID in `CloudflareActorsActorDriver`.\n */\nexport class CloudflareDurableObjectGlobalState {\n\t// Single map for all actor state\n\t#dos: Map<string, DurableObjectGlobalState> = new Map();\n\n\tgetDOState(actorId: string): DurableObjectGlobalState {\n\t\tconst state = this.#dos.get(actorId);\n\t\tinvariant(state !== undefined, \"durable object state not in global state\");\n\t\treturn state;\n\t}\n\n\tsetDOState(actorId: string, state: DurableObjectGlobalState) {\n\t\tthis.#dos.set(actorId, state);\n\t}\n}\n\nexport interface ActorDriverContext {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n// Actor handler to track running instances\nclass ActorHandler {\n\tactor?: AnyActorInstance;\n\tactorPromise?: PromiseWithResolvers<void> = Promise.withResolvers();\n\tgenericConnGlobalState = new GenericConnGlobalState();\n}\n\nexport class CloudflareActorsActorDriver implements ActorDriver {\n\t#registryConfig: RegistryConfig;\n\t#runConfig: RunConfig;\n\t#managerDriver: ManagerDriver;\n\t#inlineClient: Client<any>;\n\t#globalState: CloudflareDurableObjectGlobalState;\n\t#actors: Map<string, ActorHandler> = new Map();\n\n\tconstructor(\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t\tglobalState: CloudflareDurableObjectGlobalState,\n\t) {\n\t\tthis.#registryConfig = registryConfig;\n\t\tthis.#runConfig = runConfig;\n\t\tthis.#managerDriver = managerDriver;\n\t\tthis.#inlineClient = inlineClient;\n\t\tthis.#globalState = globalState;\n\t}\n\n\t#getDOCtx(actorId: string) {\n\t\treturn this.#globalState.getDOState(actorId).ctx;\n\t}\n\n\tasync loadActor(actorId: string): Promise<AnyActorInstance> {\n\t\t// Check if actor is already loaded\n\t\tlet handler = this.#actors.get(actorId);\n\t\tif (handler) {\n\t\t\tif (handler.actorPromise) await handler.actorPromise.promise;\n\t\t\tif (!handler.actor) throw new Error(\"Actor should be loaded\");\n\t\t\treturn handler.actor;\n\t\t}\n\n\t\t// Create new actor handler\n\t\thandler = new ActorHandler();\n\t\tthis.#actors.set(actorId, handler);\n\n\t\t// Get the actor metadata from Durable Object storage\n\t\tconst doState = this.#globalState.getDOState(actorId);\n\t\tconst storage = doState.ctx.storage;\n\n\t\t// Load actor metadata\n\t\tconst [name, key] = await Promise.all([\n\t\t\tstorage.get<string>(KEYS.NAME),\n\t\t\tstorage.get<string[]>(KEYS.KEY),\n\t\t]);\n\n\t\tif (!name) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing name`);\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing key`);\n\t\t}\n\n\t\t// Create actor instance\n\t\tconst definition = lookupInRegistry(this.#registryConfig, name);\n\t\thandler.actor = definition.instantiate();\n\n\t\t// Start actor\n\t\tconst connDrivers = createGenericConnDrivers(\n\t\t\thandler.genericConnGlobalState,\n\t\t);\n\t\tawait handler.actor.start(\n\t\t\tconnDrivers,\n\t\t\tthis,\n\t\t\tthis.#inlineClient,\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t\t\"unknown\", // TODO: Support regions in Cloudflare\n\t\t);\n\n\t\t// Finish\n\t\thandler.actorPromise?.resolve();\n\t\thandler.actorPromise = undefined;\n\n\t\treturn handler.actor;\n\t}\n\n\tgetGenericConnGlobalState(actorId: string): GenericConnGlobalState {\n\t\tconst handler = this.#actors.get(actorId);\n\t\tif (!handler) {\n\t\t\tthrow new Error(`Actor ${actorId} not loaded`);\n\t\t}\n\t\treturn handler.genericConnGlobalState;\n\t}\n\n\tgetContext(actorId: string): ActorDriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { ctx: state.ctx, env: state.env };\n\t}\n\n\tasync readPersistedData(actorId: string): Promise<Uint8Array | undefined> {\n\t\treturn await this.#getDOCtx(actorId).storage.get(KEYS.PERSIST_DATA);\n\t}\n\n\tasync writePersistedData(actorId: string, data: Uint8Array): Promise<void> {\n\t\tawait this.#getDOCtx(actorId).storage.put(KEYS.PERSIST_DATA, data);\n\t}\n\n\tasync setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {\n\t\tawait this.#getDOCtx(actor.id).storage.setAlarm(timestamp);\n\t}\n\n\tasync getDatabase(actorId: string): Promise<unknown | undefined> {\n\t\treturn this.#getDOCtx(actorId).storage.sql;\n\t}\n}\n\nexport function createCloudflareActorsActorDriverBuilder(\n\tglobalState: CloudflareDurableObjectGlobalState,\n) {\n\treturn (\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t) => {\n\t\treturn new CloudflareActorsActorDriver(\n\t\t\tregistryConfig,\n\t\t\trunConfig,\n\t\t\tmanagerDriver,\n\t\t\tinlineClient,\n\t\t\tglobalState,\n\t\t);\n\t};\n}\n","import { getLogger } from \"@rivetkit/core/log\";\n\nexport const LOGGER_NAME = \"driver-cloudflare-workers\";\n\nexport function logger() {\n\treturn getLogger(LOGGER_NAME);\n}\n","import { RunConfigSchema } from \"@rivetkit/core/driver-helpers\";\nimport type { Hono } from \"hono\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\tapp: z.custom<Hono>().optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Encoding } from \"@rivetkit/core\";\nimport {\n\ttype ActorOutput,\n\ttype CreateInput,\n\ttype GetForIdInput,\n\ttype GetOrCreateWithKeyInput,\n\ttype GetWithKeyInput,\n\tHEADER_AUTH_DATA,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ENCODING,\n\tHEADER_EXPOSE_INTERNAL_ERROR,\n\ttype ManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"@rivetkit/core/errors\";\nimport type { Context as HonoContext } from \"hono\";\nimport { getCloudflareAmbientEnv } from \"./handler\";\nimport { logger } from \"./log\";\nimport type { Bindings } from \"./mod\";\nimport { serializeKey, serializeNameAndKey } from \"./util\";\n\n// Actor metadata structure\ninterface ActorData {\n\tname: string;\n\tkey: string[];\n}\n\n// Key constants similar to Redis implementation\nconst KEYS = {\n\tACTOR: {\n\t\t// Combined key for actor metadata (name and key)\n\t\tmetadata: (actorId: string) => `actor:${actorId}:metadata`,\n\n\t\t// Key index function for actor lookup\n\t\tkeyIndex: (name: string, key: string[] = []) => {\n\t\t\t// Use serializeKey for consistent handling of all keys\n\t\t\treturn `actor_key:${serializeKey(key)}`;\n\t\t},\n\t},\n};\n\nconst STANDARD_WEBSOCKET_HEADERS = [\n\t\"connection\",\n\t\"upgrade\",\n\t\"sec-websocket-key\",\n\t\"sec-websocket-version\",\n\t\"sec-websocket-protocol\",\n\t\"sec-websocket-extensions\",\n];\n\nexport class CloudflareActorsManagerDriver implements ManagerDriver {\n\tasync sendRequest(actorId: string, actorRequest: Request): Promise<Response> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"sending request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync openWebSocket(\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t): Promise<WebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"opening websocket to durable object\", { actorId, path });\n\n\t\t// Make a fetch request to the Durable Object with WebSocket upgrade\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\tconst headers: Record<string, string> = {\n\t\t\tUpgrade: \"websocket\",\n\t\t\tConnection: \"Upgrade\",\n\t\t\t[HEADER_EXPOSE_INTERNAL_ERROR]: \"true\",\n\t\t\t[HEADER_ENCODING]: encoding,\n\t\t};\n\t\tif (params) {\n\t\t\theaders[HEADER_CONN_PARAMS] = JSON.stringify(params);\n\t\t}\n\t\t// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts\n\t\theaders[\"sec-websocket-protocol\"] = \"rivetkit\";\n\n\t\t// Use the path parameter to determine the URL\n\t\tconst url = `http://actor${path}`;\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: path,\n\t\t\tto: url,\n\t\t});\n\n\t\tconst response = await stub.fetch(url, {\n\t\t\theaders,\n\t\t});\n\t\tconst webSocket = response.webSocket;\n\n\t\tif (!webSocket) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"missing websocket connection in response from DO\",\n\t\t\t);\n\t\t}\n\n\t\tlogger().debug(\"durable object websocket connection open\", {\n\t\t\tactorId,\n\t\t});\n\n\t\twebSocket.accept();\n\n\t\t// TODO: Is this still needed?\n\t\t// HACK: Cloudflare does not call onopen automatically, so we need\n\t\t// to call this on the next tick\n\t\tsetTimeout(() => {\n\t\t\tconst event = new Event(\"open\");\n\t\t\t(webSocket as any).onopen?.(event);\n\t\t\t(webSocket as any).dispatchEvent(event);\n\t\t}, 0);\n\n\t\treturn webSocket as unknown as WebSocket;\n\t}\n\n\tasync proxyRequest(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tactorRequest: Request,\n\t\tactorId: string,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync proxyWebSocket(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t\tauthData: unknown,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding websocket to durable object\", {\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\n\n\t\t// Validate upgrade\n\t\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\t\tif (!upgradeHeader || upgradeHeader !== \"websocket\") {\n\t\t\treturn new Response(\"Expected Upgrade: websocket\", {\n\t\t\t\tstatus: 426,\n\t\t\t});\n\t\t}\n\n\t\t// TODO: strip headers\n\t\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: c.req.url,\n\t\t\tto: actorRequest.url,\n\t\t});\n\n\t\t// Always build fresh request to prevent forwarding unwanted headers\n\t\t// HACK: Since we can't build a new request, we need to remove\n\t\t// non-standard headers manually\n\t\tconst headerKeys: string[] = [];\n\t\tactorRequest.headers.forEach((v, k) => headerKeys.push(k));\n\t\tfor (const k of headerKeys) {\n\t\t\tif (!STANDARD_WEBSOCKET_HEADERS.includes(k)) {\n\t\t\t\tactorRequest.headers.delete(k);\n\t\t\t}\n\t\t}\n\n\t\t// Add RivetKit headers\n\t\tactorRequest.headers.set(HEADER_EXPOSE_INTERNAL_ERROR, \"true\");\n\t\tactorRequest.headers.set(HEADER_ENCODING, encoding);\n\t\tif (params) {\n\t\t\tactorRequest.headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));\n\t\t}\n\t\tif (authData) {\n\t\t\tactorRequest.headers.set(HEADER_AUTH_DATA, JSON.stringify(authData));\n\t\t}\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync getForId({\n\t\tc,\n\t\tactorId,\n\t}: GetForIdInput<{ Bindings: Bindings }>): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Get actor metadata from KV (combined name and key)\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\t// If the actor doesn't exist, return undefined\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n\n\tasync getWithKey({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t}: GetWithKeyInput<{ Bindings: Bindings }>): Promise<\n\t\tActorOutput | undefined\n\t> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"getWithKey: searching for actor\", { name, key });\n\n\t\t// Generate deterministic ID from the name and key\n\t\t// This is aligned with how createActor generates IDs\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst actorId = env.ACTOR_DO.idFromName(nameKeyString).toString();\n\n\t\t// Check if the actor metadata exists\n\t\tconst actorData = await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t});\n\n\t\tif (!actorData) {\n\t\t\tlogger().debug(\"getWithKey: no actor found with matching name and key\", {\n\t\t\t\tname,\n\t\t\t\tkey,\n\t\t\t\tactorId,\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlogger().debug(\"getWithKey: found actor with matching name and key\", {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t});\n\t\treturn this.#buildActorOutput(c, actorId);\n\t}\n\n\tasync getOrCreateWithKey(\n\t\tinput: GetOrCreateWithKeyInput,\n\t): Promise<ActorOutput> {\n\t\t// TODO: Prevent race condition here\n\t\tconst getOutput = await this.getWithKey(input);\n\t\tif (getOutput) {\n\t\t\treturn getOutput;\n\t\t} else {\n\t\t\treturn await this.createActor(input);\n\t\t}\n\t}\n\n\tasync createActor({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t\tinput,\n\t}: CreateInput<{ Bindings: Bindings }>): Promise<ActorOutput> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Check if actor with the same name and key already exists\n\t\tconst existingActor = await this.getWithKey({ c, name, key });\n\t\tif (existingActor) {\n\t\t\tthrow new ActorAlreadyExists(name, key);\n\t\t}\n\n\t\t// Create a deterministic ID from the actor name and key\n\t\t// This ensures that actors with the same name and key will have the same ID\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst doId = env.ACTOR_DO.idFromName(nameKeyString);\n\t\tconst actorId = doId.toString();\n\n\t\t// Init actor\n\t\tconst actor = env.ACTOR_DO.get(doId);\n\t\tawait actor.initialize({\n\t\t\tname,\n\t\t\tkey,\n\t\t\tinput,\n\t\t});\n\n\t\t// Store combined actor metadata (name and key)\n\t\tconst actorData: ActorData = { name, key };\n\t\tawait env.ACTOR_KV.put(\n\t\t\tKEYS.ACTOR.metadata(actorId),\n\t\t\tJSON.stringify(actorData),\n\t\t);\n\n\t\t// Add to key index for lookups by name and key\n\t\tawait env.ACTOR_KV.put(KEYS.ACTOR.keyIndex(name, key), actorId);\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t};\n\t}\n\n\t// Helper method to build actor output from an ID\n\tasync #buildActorOutput(\n\t\tc: any,\n\t\tactorId: string,\n\t): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n}\n","// Constants for key handling\nexport const EMPTY_KEY = \"(none)\";\nexport const KEY_SEPARATOR = \",\";\n\n/**\n * Serializes an array of key strings into a single string for use with idFromName\n *\n * @param name The actor name\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized name and key\n */\nexport function serializeNameAndKey(name: string, key: string[]): string {\n\t// Escape colons in the name\n\tconst escapedName = name.replace(/:/g, \"\\\\:\");\n\n\t// For empty keys, just return the name and a marker\n\tif (key.length === 0) {\n\t\treturn `${escapedName}:${EMPTY_KEY}`;\n\t}\n\n\t// Serialize the key array\n\tconst serializedKey = serializeKey(key);\n\n\t// Combine name and serialized key\n\treturn `${escapedName}:${serializedKey}`;\n}\n\n/**\n * Serializes an array of key strings into a single string\n *\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized key\n */\nexport function serializeKey(key: string[]): string {\n\t// Use a special marker for empty key arrays\n\tif (key.length === 0) {\n\t\treturn EMPTY_KEY;\n\t}\n\n\t// Escape each key part to handle the separator and the empty key marker\n\tconst escapedParts = key.map((part) => {\n\t\t// First check if it matches our empty key marker\n\t\tif (part === EMPTY_KEY) {\n\t\t\treturn `\\\\${EMPTY_KEY}`;\n\t\t}\n\n\t\t// Escape backslashes first, then commas\n\t\tlet escaped = part.replace(/\\\\/g, \"\\\\\\\\\");\n\t\tescaped = escaped.replace(/,/g, \"\\\\,\");\n\t\treturn escaped;\n\t});\n\n\treturn escapedParts.join(KEY_SEPARATOR);\n}\n\n/**\n * Deserializes a key string back into an array of key strings\n *\n * @param keyString The serialized key string\n * @returns Array of key strings\n */\nexport function deserializeKey(keyString: string): string[] {\n\t// Handle empty values\n\tif (!keyString) {\n\t\treturn [];\n\t}\n\n\t// Check for special empty key marker\n\tif (keyString === EMPTY_KEY) {\n\t\treturn [];\n\t}\n\n\t// Split by unescaped commas and unescape the escaped characters\n\tconst parts: string[] = [];\n\tlet currentPart = \"\";\n\tlet escaping = false;\n\n\tfor (let i = 0; i < keyString.length; i++) {\n\t\tconst char = keyString[i];\n\n\t\tif (escaping) {\n\t\t\t// This is an escaped character, add it directly\n\t\t\tcurrentPart += char;\n\t\t\tescaping = false;\n\t\t} else if (char === \"\\\\\") {\n\t\t\t// Start of an escape sequence\n\t\t\tescaping = true;\n\t\t} else if (char === KEY_SEPARATOR) {\n\t\t\t// This is a separator\n\t\t\tparts.push(currentPart);\n\t\t\tcurrentPart = \"\";\n\t\t} else {\n\t\t\t// Regular character\n\t\t\tcurrentPart += char;\n\t\t}\n\t}\n\n\t// Add the last part if it exists\n\tif (currentPart || parts.length > 0) {\n\t\tparts.push(currentPart);\n\t}\n\n\treturn parts;\n}\n","// Modified from https://github.com/honojs/hono/blob/40ea0eee58e39b31053a0246c595434f1094ad31/src/adapter/cloudflare-workers/websocket.ts#L17\n//\n// This version calls the open event by default\n\nimport type { UpgradeWebSocket, WSEvents, WSReadyState } from \"hono/ws\";\nimport { defineWebSocketHelper, WSContext } from \"hono/ws\";\n\n// Based on https://github.com/honojs/hono/issues/1153#issuecomment-1767321332\nexport const upgradeWebSocket: UpgradeWebSocket<\n\tWebSocket,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tWSEvents<WebSocket>\n> = defineWebSocketHelper(async (c, events) => {\n\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\tif (upgradeHeader !== \"websocket\") {\n\t\treturn;\n\t}\n\n\tconst webSocketPair = new WebSocketPair();\n\tconst client: WebSocket = webSocketPair[0];\n\tconst server: WebSocket = webSocketPair[1];\n\n\tconst wsContext = new WSContext<WebSocket>({\n\t\tclose: (code, reason) => server.close(code, reason),\n\t\tget protocol() {\n\t\t\treturn server.protocol;\n\t\t},\n\t\traw: server,\n\t\tget readyState() {\n\t\t\treturn server.readyState as WSReadyState;\n\t\t},\n\t\turl: server.url ? new URL(server.url) : null,\n\t\tsend: (source) => server.send(source),\n\t});\n\n\tif (events.onClose) {\n\t\tserver.addEventListener(\"close\", (evt: CloseEvent) =>\n\t\t\tevents.onClose?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onMessage) {\n\t\tserver.addEventListener(\"message\", (evt: MessageEvent) =>\n\t\t\tevents.onMessage?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onError) {\n\t\tserver.addEventListener(\"error\", (evt: Event) =>\n\t\t\tevents.onError?.(evt, wsContext),\n\t\t);\n\t}\n\n\tserver.accept?.();\n\n\t// note: cloudflare actors doesn't support 'open' event, so we call it immediately with a fake event\n\t//\n\t// we have to do this after `server.accept() is called`\n\tevents.onOpen?.(new Event(\"open\"), wsContext);\n\n\treturn new Response(null, {\n\t\tstatus: 101,\n\t\theaders: {\n\t\t\t// HACK: Required in order for Cloudflare to not error with \"Network connection lost\"\n\t\t\t//\n\t\t\t// This bug undocumented. Cannot easily reproduce outside of RivetKit.\n\t\t\t\"Sec-WebSocket-Protocol\": \"rivetkit\",\n\t\t},\n\t\twebSocket: client,\n\t});\n});\n"],"mappings":";AAAA,SAAS,yBAAyB;AAGlC,SAAS,YAAY;AACrB,OAAOA,gBAAe;;;ACJtB,SAAS,qBAA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Aa,MAAM,WAAW;AAG7C,QAAM,YAAY;AAAA,IACjB,QAAQ;AAAA,MACP,SAAS,MAAM,IAAI,8BAA8B;AAAA;AAAA,MAEjD,OAAO;AAAA,IACR;AAAA,IACA,qBAAqB,MAAM;AAAA,IAC3B,GAAG;AAAA,EACJ;AAGA,QAAMC,gBAAe,yBAAyB,UAAU,SAAS;AAGjE,QAAM,eAAe,SAAS,aAAa,SAAS;AAEpD,SAAO;AAAA,IACN,QAAQ,aAAa;AAAA,IACrB,eAAe,CAAC,SAAS;AAExB,YAAM,MAAM,QAAQ,IAAI,KAAK;AAG7B,UAAI,CAAC,MAAM;AACV,YAAI,MAAM,aAAa,aAAa,IAAI;AAAA,MACzC;AAGA,YAAM,UAAU;AAAA,QACf,OAAO,CAAC,SAAS,KAAK,QAAQ;AAC7B,iBAAO,eAAe,IAAI,KAAK,MAAM,IAAI,MAAM,SAAS,KAAK,GAAG,CAAC;AAAA,QAClE;AAAA,MACD;AAEA,aAAO,EAAE,SAAS,cAAAA,cAAa;AAAA,IAChC;AAAA,EACD;AACD;","names":["invariant","KEYS","_a","invariant","ActorHandler"]}
1
+ {"version":3,"sources":["../src/handler.ts","../src/actor-handler-do.ts","../src/actor-driver.ts","../src/log.ts","../src/config.ts","../src/manager-driver.ts","../src/util.ts","../src/websocket.ts"],"sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { Registry, RunConfig } from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport { Hono } from \"hono\";\nimport invariant from \"invariant\";\nimport {\n\ttype ActorHandlerInterface,\n\tcreateActorDurableObject,\n\ttype DurableObjectConstructor,\n} from \"./actor-handler-do\";\nimport { ConfigSchema, type InputConfig } from \"./config\";\nimport { CloudflareActorsManagerDriver } from \"./manager-driver\";\nimport { upgradeWebSocket } from \"./websocket\";\n\n/** Cloudflare Workers env */\nexport interface Bindings {\n\tACTOR_KV: KVNamespace;\n\tACTOR_DO: DurableObjectNamespace<ActorHandlerInterface>;\n}\n\n/**\n * Stores the env for the current request. Required since some contexts like the inline client driver does not have access to the Hono context.\n *\n * Use getCloudflareAmbientEnv unless using CF_AMBIENT_ENV.run.\n */\nexport const CF_AMBIENT_ENV = new AsyncLocalStorage<Bindings>();\n\nexport function getCloudflareAmbientEnv(): Bindings {\n\tconst env = CF_AMBIENT_ENV.getStore();\n\tinvariant(env, \"missing CF_AMBIENT_ENV\");\n\treturn env;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\ninterface SetupOutput<A extends Registry<any>> {\n\tclient: Client<A>;\n\tcreateHandler: (hono?: Hono) => Handler;\n}\n\nexport function createServerHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst { createHandler } = createServer(registry, inputConfig);\n\treturn createHandler();\n}\n\nexport function createServer<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): SetupOutput<R> {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\tdriver: {\n\t\t\tname: \"cloudflare-workers\",\n\t\t\tmanager: () => new CloudflareActorsManagerDriver(),\n\t\t\t// HACK: We can't build the actor driver until we're inside the Durable Object\n\t\t\tactor: undefined as any,\n\t\t},\n\t\tgetUpgradeWebSocket: () => upgradeWebSocket,\n\t\t...config,\n\t} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.createServer(runConfig);\n\n\treturn {\n\t\tclient: serverOutput.client as Client<R>,\n\t\tcreateHandler: (hono) => {\n\t\t\t// Build base router\n\t\t\tconst app = hono ?? new Hono();\n\n\t\t\t// Mount registry router at /registry\n\t\t\tif (!hono) {\n\t\t\t\tapp.route(\"/registry\", serverOutput.hono);\n\t\t\t}\n\n\t\t\t// Create Cloudflare handler\n\t\t\tconst handler = {\n\t\t\t\tfetch: (request, env, ctx) => {\n\t\t\t\t\treturn CF_AMBIENT_ENV.run(env, () => app.fetch(request, env, ctx));\n\t\t\t\t},\n\t\t\t} satisfies ExportedHandler<Bindings>;\n\n\t\t\treturn { handler, ActorHandler };\n\t\t},\n\t};\n}\n","import { DurableObject } from \"cloudflare:workers\";\nimport type {\n\tActorKey,\n\tActorRouter,\n\tRegistry,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateActorRouter,\n\tcreateClientWithDriver,\n\tcreateInlineClientDriver,\n} from \"@rivetkit/core\";\nimport { serializeEmptyPersistData } from \"@rivetkit/core/driver-helpers\";\nimport type { ExecutionContext } from \"hono\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport { type Bindings, CF_AMBIENT_ENV } from \"./handler\";\nimport { logger } from \"./log\";\n\nexport const KEYS = {\n\tNAME: \"rivetkit:name\",\n\tKEY: \"rivetkit:key\",\n\tPERSIST_DATA: \"rivetkit:data\",\n};\n\nexport interface ActorHandlerInterface extends DurableObject {\n\tinitialize(req: ActorInitRequest): Promise<void>;\n}\n\nexport interface ActorInitRequest {\n\tname: string;\n\tkey: ActorKey;\n\tinput?: unknown;\n}\n\ninterface InitializedData {\n\tname: string;\n\tkey: ActorKey;\n}\n\nexport type DurableObjectConstructor = new (\n\t...args: ConstructorParameters<typeof DurableObject<Bindings>>\n) => DurableObject<Bindings>;\n\ninterface LoadedActor {\n\tactorRouter: ActorRouter;\n}\n\nexport function createActorDurableObject(\n\tregistry: Registry<any>,\n\trunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t/**\n\t * Startup steps:\n\t * 1. If not already created call `initialize`, otherwise check KV to ensure it's initialized\n\t * 2. Load actor\n\t * 3. Start service requests\n\t */\n\treturn class ActorHandler\n\t\textends DurableObject<Bindings>\n\t\timplements ActorHandlerInterface\n\t{\n\t\t#initialized?: InitializedData;\n\t\t#initializedPromise?: PromiseWithResolvers<void>;\n\n\t\t#actor?: LoadedActor;\n\n\t\tasync #loadActor(): Promise<LoadedActor> {\n\t\t\t// This is always called from another context using CF_AMBIENT_ENV\n\n\t\t\t// Wait for init\n\t\t\tif (!this.#initialized) {\n\t\t\t\t// Wait for init\n\t\t\t\tif (this.#initializedPromise) {\n\t\t\t\t\tawait this.#initializedPromise.promise;\n\t\t\t\t} else {\n\t\t\t\t\tthis.#initializedPromise = Promise.withResolvers();\n\t\t\t\t\tconst res = await this.ctx.storage.get([\n\t\t\t\t\t\tKEYS.NAME,\n\t\t\t\t\t\tKEYS.KEY,\n\t\t\t\t\t\tKEYS.PERSIST_DATA,\n\t\t\t\t\t]);\n\t\t\t\t\tif (res.get(KEYS.PERSIST_DATA)) {\n\t\t\t\t\t\tconst name = res.get(KEYS.NAME) as string;\n\t\t\t\t\t\tif (!name) throw new Error(\"missing actor name\");\n\t\t\t\t\t\tconst key = res.get(KEYS.KEY) as ActorKey;\n\t\t\t\t\t\tif (!key) throw new Error(\"missing actor key\");\n\n\t\t\t\t\t\tlogger().debug(\"already initialized\", { name, key });\n\n\t\t\t\t\t\tthis.#initialized = { name, key };\n\t\t\t\t\t\tthis.#initializedPromise.resolve();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger().debug(\"waiting to initialize\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Check if already loaded\n\t\t\tif (this.#actor) {\n\t\t\t\treturn this.#actor;\n\t\t\t}\n\n\t\t\tif (!this.#initialized) throw new Error(\"Not initialized\");\n\n\t\t\t// Register DO with global state first\n\t\t\t// HACK: This leaks the DO context, but DO does not provide a native way\n\t\t\t// of knowing when the DO shuts down. We're making a broad assumption\n\t\t\t// that DO will boot a new isolate frequenlty enough that this is not an issue.\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\tglobalState.setDOState(actorId, { ctx: this.ctx, env: this.env });\n\n\t\t\t// Configure actor driver\n\t\t\trunConfig.driver.actor =\n\t\t\t\tcreateCloudflareActorsActorDriverBuilder(globalState);\n\n\t\t\t// Create manager driver (we need this for the actor router)\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\n\t\t\t// Create inline client\n\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t);\n\n\t\t\t// Create actor driver\n\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t\tmanagerDriver,\n\t\t\t\tinlineClient,\n\t\t\t);\n\n\t\t\t// Create actor router\n\t\t\tconst actorRouter = createActorRouter(runConfig, actorDriver);\n\n\t\t\t// Save actor\n\t\t\tthis.#actor = {\n\t\t\t\tactorRouter,\n\t\t\t};\n\n\t\t\t// Initialize the actor instance with proper metadata\n\t\t\t// This ensures the actor driver knows about this actor\n\t\t\tawait actorDriver.loadActor(actorId);\n\n\t\t\treturn this.#actor;\n\t\t}\n\n\t\t/** RPC called by the service that creates the DO to initialize it. */\n\t\tasync initialize(req: ActorInitRequest) {\n\t\t\t// TODO: Need to add this to a core promise that needs to be resolved before start\n\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.ctx.storage.put({\n\t\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t\t});\n\t\t\t\tthis.#initialized = {\n\t\t\t\t\tname: req.name,\n\t\t\t\t\tkey: req.key,\n\t\t\t\t};\n\n\t\t\t\tlogger().debug(\"initialized actor\", { key: req.key });\n\n\t\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\t\tawait this.#loadActor();\n\t\t\t});\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\t\tactorId,\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\treturn await CF_AMBIENT_ENV.run(this.env, async () => {\n\t\t\t\tawait this.#loadActor();\n\t\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t\t// Get the actor driver\n\t\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t);\n\t\t\t\tconst inlineClient = createClientWithDriver(\n\t\t\t\t\tcreateInlineClientDriver(managerDriver),\n\t\t\t\t);\n\t\t\t\tconst actorDriver = runConfig.driver.actor(\n\t\t\t\t\tregistry.config,\n\t\t\t\t\trunConfig,\n\t\t\t\t\tmanagerDriver,\n\t\t\t\t\tinlineClient,\n\t\t\t\t);\n\n\t\t\t\t// Load the actor instance and trigger alarm\n\t\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\t\tawait actor.onAlarm();\n\t\t\t});\n\t\t}\n\t};\n}\n","import type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"@rivetkit/core\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"@rivetkit/core\";\nimport type { Client } from \"@rivetkit/core/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport invariant from \"invariant\";\nimport { KEYS } from \"./actor-handler-do\";\n\ninterface DurableObjectGlobalState {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n/**\n * Cloudflare DO can have multiple DO running within the same global scope.\n *\n * This allows for storing the actor context globally and looking it up by ID in `CloudflareActorsActorDriver`.\n */\nexport class CloudflareDurableObjectGlobalState {\n\t// Single map for all actor state\n\t#dos: Map<string, DurableObjectGlobalState> = new Map();\n\n\tgetDOState(actorId: string): DurableObjectGlobalState {\n\t\tconst state = this.#dos.get(actorId);\n\t\tinvariant(state !== undefined, \"durable object state not in global state\");\n\t\treturn state;\n\t}\n\n\tsetDOState(actorId: string, state: DurableObjectGlobalState) {\n\t\tthis.#dos.set(actorId, state);\n\t}\n}\n\nexport interface ActorDriverContext {\n\tctx: DurableObjectState;\n\tenv: unknown;\n}\n\n// Actor handler to track running instances\nclass ActorHandler {\n\tactor?: AnyActorInstance;\n\tactorPromise?: PromiseWithResolvers<void> = Promise.withResolvers();\n\tgenericConnGlobalState = new GenericConnGlobalState();\n}\n\nexport class CloudflareActorsActorDriver implements ActorDriver {\n\t#registryConfig: RegistryConfig;\n\t#runConfig: RunConfig;\n\t#managerDriver: ManagerDriver;\n\t#inlineClient: Client<any>;\n\t#globalState: CloudflareDurableObjectGlobalState;\n\t#actors: Map<string, ActorHandler> = new Map();\n\n\tconstructor(\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t\tglobalState: CloudflareDurableObjectGlobalState,\n\t) {\n\t\tthis.#registryConfig = registryConfig;\n\t\tthis.#runConfig = runConfig;\n\t\tthis.#managerDriver = managerDriver;\n\t\tthis.#inlineClient = inlineClient;\n\t\tthis.#globalState = globalState;\n\t}\n\n\t#getDOCtx(actorId: string) {\n\t\treturn this.#globalState.getDOState(actorId).ctx;\n\t}\n\n\tasync loadActor(actorId: string): Promise<AnyActorInstance> {\n\t\t// Check if actor is already loaded\n\t\tlet handler = this.#actors.get(actorId);\n\t\tif (handler) {\n\t\t\tif (handler.actorPromise) await handler.actorPromise.promise;\n\t\t\tif (!handler.actor) throw new Error(\"Actor should be loaded\");\n\t\t\treturn handler.actor;\n\t\t}\n\n\t\t// Create new actor handler\n\t\thandler = new ActorHandler();\n\t\tthis.#actors.set(actorId, handler);\n\n\t\t// Get the actor metadata from Durable Object storage\n\t\tconst doState = this.#globalState.getDOState(actorId);\n\t\tconst storage = doState.ctx.storage;\n\n\t\t// Load actor metadata\n\t\tconst [name, key] = await Promise.all([\n\t\t\tstorage.get<string>(KEYS.NAME),\n\t\t\tstorage.get<string[]>(KEYS.KEY),\n\t\t]);\n\n\t\tif (!name) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing name`);\n\t\t}\n\t\tif (!key) {\n\t\t\tthrow new Error(`Actor ${actorId} is not initialized - missing key`);\n\t\t}\n\n\t\t// Create actor instance\n\t\tconst definition = lookupInRegistry(this.#registryConfig, name);\n\t\thandler.actor = definition.instantiate();\n\n\t\t// Start actor\n\t\tconst connDrivers = createGenericConnDrivers(\n\t\t\thandler.genericConnGlobalState,\n\t\t);\n\t\tawait handler.actor.start(\n\t\t\tconnDrivers,\n\t\t\tthis,\n\t\t\tthis.#inlineClient,\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t\t\"unknown\", // TODO: Support regions in Cloudflare\n\t\t);\n\n\t\t// Finish\n\t\thandler.actorPromise?.resolve();\n\t\thandler.actorPromise = undefined;\n\n\t\treturn handler.actor;\n\t}\n\n\tgetGenericConnGlobalState(actorId: string): GenericConnGlobalState {\n\t\tconst handler = this.#actors.get(actorId);\n\t\tif (!handler) {\n\t\t\tthrow new Error(`Actor ${actorId} not loaded`);\n\t\t}\n\t\treturn handler.genericConnGlobalState;\n\t}\n\n\tgetContext(actorId: string): ActorDriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { ctx: state.ctx, env: state.env };\n\t}\n\n\tasync readPersistedData(actorId: string): Promise<Uint8Array | undefined> {\n\t\treturn await this.#getDOCtx(actorId).storage.get(KEYS.PERSIST_DATA);\n\t}\n\n\tasync writePersistedData(actorId: string, data: Uint8Array): Promise<void> {\n\t\tawait this.#getDOCtx(actorId).storage.put(KEYS.PERSIST_DATA, data);\n\t}\n\n\tasync setAlarm(actor: AnyActorInstance, timestamp: number): Promise<void> {\n\t\tawait this.#getDOCtx(actor.id).storage.setAlarm(timestamp);\n\t}\n\n\tasync getDatabase(actorId: string): Promise<unknown | undefined> {\n\t\treturn this.#getDOCtx(actorId).storage.sql;\n\t}\n}\n\nexport function createCloudflareActorsActorDriverBuilder(\n\tglobalState: CloudflareDurableObjectGlobalState,\n) {\n\treturn (\n\t\tregistryConfig: RegistryConfig,\n\t\trunConfig: RunConfig,\n\t\tmanagerDriver: ManagerDriver,\n\t\tinlineClient: Client<any>,\n\t) => {\n\t\treturn new CloudflareActorsActorDriver(\n\t\t\tregistryConfig,\n\t\t\trunConfig,\n\t\t\tmanagerDriver,\n\t\t\tinlineClient,\n\t\t\tglobalState,\n\t\t);\n\t};\n}\n","import { getLogger } from \"@rivetkit/core/log\";\n\nexport const LOGGER_NAME = \"driver-cloudflare-workers\";\n\nexport function logger() {\n\treturn getLogger(LOGGER_NAME);\n}\n","import { RunConfigSchema } from \"@rivetkit/core/driver-helpers\";\nimport type { Hono } from \"hono\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\tapp: z.custom<Hono>().optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Encoding } from \"@rivetkit/core\";\nimport {\n\ttype ActorOutput,\n\ttype CreateInput,\n\ttype GetForIdInput,\n\ttype GetOrCreateWithKeyInput,\n\ttype GetWithKeyInput,\n\tHEADER_AUTH_DATA,\n\tHEADER_CONN_PARAMS,\n\tHEADER_ENCODING,\n\tHEADER_EXPOSE_INTERNAL_ERROR,\n\ttype ManagerDriver,\n} from \"@rivetkit/core/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"@rivetkit/core/errors\";\nimport type { Context as HonoContext } from \"hono\";\nimport { getCloudflareAmbientEnv } from \"./handler\";\nimport { logger } from \"./log\";\nimport type { Bindings } from \"./mod\";\nimport { serializeKey, serializeNameAndKey } from \"./util\";\n\n// Actor metadata structure\ninterface ActorData {\n\tname: string;\n\tkey: string[];\n}\n\n// Key constants similar to Redis implementation\nconst KEYS = {\n\tACTOR: {\n\t\t// Combined key for actor metadata (name and key)\n\t\tmetadata: (actorId: string) => `actor:${actorId}:metadata`,\n\n\t\t// Key index function for actor lookup\n\t\tkeyIndex: (name: string, key: string[] = []) => {\n\t\t\t// Use serializeKey for consistent handling of all keys\n\t\t\treturn `actor_key:${serializeKey(key)}`;\n\t\t},\n\t},\n};\n\nconst STANDARD_WEBSOCKET_HEADERS = [\n\t\"connection\",\n\t\"upgrade\",\n\t\"sec-websocket-key\",\n\t\"sec-websocket-version\",\n\t\"sec-websocket-protocol\",\n\t\"sec-websocket-extensions\",\n];\n\nexport class CloudflareActorsManagerDriver implements ManagerDriver {\n\tasync sendRequest(actorId: string, actorRequest: Request): Promise<Response> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"sending request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync openWebSocket(\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t): Promise<WebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"opening websocket to durable object\", { actorId, path });\n\n\t\t// Make a fetch request to the Durable Object with WebSocket upgrade\n\t\tconst id = env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = env.ACTOR_DO.get(id);\n\n\t\tconst headers: Record<string, string> = {\n\t\t\tUpgrade: \"websocket\",\n\t\t\tConnection: \"Upgrade\",\n\t\t\t[HEADER_EXPOSE_INTERNAL_ERROR]: \"true\",\n\t\t\t[HEADER_ENCODING]: encoding,\n\t\t};\n\t\tif (params) {\n\t\t\theaders[HEADER_CONN_PARAMS] = JSON.stringify(params);\n\t\t}\n\t\t// HACK: See packages/drivers/cloudflare-workers/src/websocket.ts\n\t\theaders[\"sec-websocket-protocol\"] = \"rivetkit\";\n\n\t\t// Use the path parameter to determine the URL\n\t\tconst url = `http://actor${path}`;\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: path,\n\t\t\tto: url,\n\t\t});\n\n\t\tconst response = await stub.fetch(url, {\n\t\t\theaders,\n\t\t});\n\t\tconst webSocket = response.webSocket;\n\n\t\tif (!webSocket) {\n\t\t\tthrow new InternalError(\n\t\t\t\t\"missing websocket connection in response from DO\",\n\t\t\t);\n\t\t}\n\n\t\tlogger().debug(\"durable object websocket connection open\", {\n\t\t\tactorId,\n\t\t});\n\n\t\twebSocket.accept();\n\n\t\t// TODO: Is this still needed?\n\t\t// HACK: Cloudflare does not call onopen automatically, so we need\n\t\t// to call this on the next tick\n\t\tsetTimeout(() => {\n\t\t\tconst event = new Event(\"open\");\n\t\t\t(webSocket as any).onopen?.(event);\n\t\t\t(webSocket as any).dispatchEvent(event);\n\t\t}, 0);\n\n\t\treturn webSocket as unknown as WebSocket;\n\t}\n\n\tasync proxyRequest(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tactorRequest: Request,\n\t\tactorId: string,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding request to durable object\", {\n\t\t\tactorId,\n\t\t\tmethod: actorRequest.method,\n\t\t\turl: actorRequest.url,\n\t\t});\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync proxyWebSocket(\n\t\tc: HonoContext<{ Bindings: Bindings }>,\n\t\tpath: string,\n\t\tactorId: string,\n\t\tencoding: Encoding,\n\t\tparams: unknown,\n\t\tauthData: unknown,\n\t): Promise<Response> {\n\t\tlogger().debug(\"forwarding websocket to durable object\", {\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\n\n\t\t// Validate upgrade\n\t\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\t\tif (!upgradeHeader || upgradeHeader !== \"websocket\") {\n\t\t\treturn new Response(\"Expected Upgrade: websocket\", {\n\t\t\t\tstatus: 426,\n\t\t\t});\n\t\t}\n\n\t\t// TODO: strip headers\n\t\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug(\"rewriting websocket url\", {\n\t\t\tfrom: c.req.url,\n\t\t\tto: actorRequest.url,\n\t\t});\n\n\t\t// Always build fresh request to prevent forwarding unwanted headers\n\t\t// HACK: Since we can't build a new request, we need to remove\n\t\t// non-standard headers manually\n\t\tconst headerKeys: string[] = [];\n\t\tactorRequest.headers.forEach((v, k) => headerKeys.push(k));\n\t\tfor (const k of headerKeys) {\n\t\t\tif (!STANDARD_WEBSOCKET_HEADERS.includes(k)) {\n\t\t\t\tactorRequest.headers.delete(k);\n\t\t\t}\n\t\t}\n\n\t\t// Add RivetKit headers\n\t\tactorRequest.headers.set(HEADER_EXPOSE_INTERNAL_ERROR, \"true\");\n\t\tactorRequest.headers.set(HEADER_ENCODING, encoding);\n\t\tif (params) {\n\t\t\tactorRequest.headers.set(HEADER_CONN_PARAMS, JSON.stringify(params));\n\t\t}\n\t\tif (authData) {\n\t\t\tactorRequest.headers.set(HEADER_AUTH_DATA, JSON.stringify(authData));\n\t\t}\n\n\t\tconst id = c.env.ACTOR_DO.idFromString(actorId);\n\t\tconst stub = c.env.ACTOR_DO.get(id);\n\n\t\treturn await stub.fetch(actorRequest);\n\t}\n\n\tasync getForId({\n\t\tc,\n\t\tactorId,\n\t}: GetForIdInput<{ Bindings: Bindings }>): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Get actor metadata from KV (combined name and key)\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\t// If the actor doesn't exist, return undefined\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n\n\tasync getWithKey({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t}: GetWithKeyInput<{ Bindings: Bindings }>): Promise<\n\t\tActorOutput | undefined\n\t> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug(\"getWithKey: searching for actor\", { name, key });\n\n\t\t// Generate deterministic ID from the name and key\n\t\t// This is aligned with how createActor generates IDs\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst actorId = env.ACTOR_DO.idFromName(nameKeyString).toString();\n\n\t\t// Check if the actor metadata exists\n\t\tconst actorData = await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t});\n\n\t\tif (!actorData) {\n\t\t\tlogger().debug(\"getWithKey: no actor found with matching name and key\", {\n\t\t\t\tname,\n\t\t\t\tkey,\n\t\t\t\tactorId,\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\n\t\tlogger().debug(\"getWithKey: found actor with matching name and key\", {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t});\n\t\treturn this.#buildActorOutput(c, actorId);\n\t}\n\n\tasync getOrCreateWithKey(\n\t\tinput: GetOrCreateWithKeyInput,\n\t): Promise<ActorOutput> {\n\t\t// TODO: Prevent race condition here\n\t\tconst getOutput = await this.getWithKey(input);\n\t\tif (getOutput) {\n\t\t\treturn getOutput;\n\t\t} else {\n\t\t\treturn await this.createActor(input);\n\t\t}\n\t}\n\n\tasync createActor({\n\t\tc,\n\t\tname,\n\t\tkey,\n\t\tinput,\n\t}: CreateInput<{ Bindings: Bindings }>): Promise<ActorOutput> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\t// Check if actor with the same name and key already exists\n\t\tconst existingActor = await this.getWithKey({ c, name, key });\n\t\tif (existingActor) {\n\t\t\tthrow new ActorAlreadyExists(name, key);\n\t\t}\n\n\t\t// Create a deterministic ID from the actor name and key\n\t\t// This ensures that actors with the same name and key will have the same ID\n\t\tconst nameKeyString = serializeNameAndKey(name, key);\n\t\tconst doId = env.ACTOR_DO.idFromName(nameKeyString);\n\t\tconst actorId = doId.toString();\n\n\t\t// Init actor\n\t\tconst actor = env.ACTOR_DO.get(doId);\n\t\tawait actor.initialize({\n\t\t\tname,\n\t\t\tkey,\n\t\t\tinput,\n\t\t});\n\n\t\t// Store combined actor metadata (name and key)\n\t\tconst actorData: ActorData = { name, key };\n\t\tawait env.ACTOR_KV.put(\n\t\t\tKEYS.ACTOR.metadata(actorId),\n\t\t\tJSON.stringify(actorData),\n\t\t);\n\n\t\t// Add to key index for lookups by name and key\n\t\tawait env.ACTOR_KV.put(KEYS.ACTOR.keyIndex(name, key), actorId);\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname,\n\t\t\tkey,\n\t\t};\n\t}\n\n\t// Helper method to build actor output from an ID\n\tasync #buildActorOutput(\n\t\tc: any,\n\t\tactorId: string,\n\t): Promise<ActorOutput | undefined> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tconst actorData = (await env.ACTOR_KV.get(KEYS.ACTOR.metadata(actorId), {\n\t\t\ttype: \"json\",\n\t\t})) as ActorData | null;\n\n\t\tif (!actorData) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn {\n\t\t\tactorId,\n\t\t\tname: actorData.name,\n\t\t\tkey: actorData.key,\n\t\t};\n\t}\n}\n","// Constants for key handling\nexport const EMPTY_KEY = \"(none)\";\nexport const KEY_SEPARATOR = \",\";\n\n/**\n * Serializes an array of key strings into a single string for use with idFromName\n *\n * @param name The actor name\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized name and key\n */\nexport function serializeNameAndKey(name: string, key: string[]): string {\n\t// Escape colons in the name\n\tconst escapedName = name.replace(/:/g, \"\\\\:\");\n\n\t// For empty keys, just return the name and a marker\n\tif (key.length === 0) {\n\t\treturn `${escapedName}:${EMPTY_KEY}`;\n\t}\n\n\t// Serialize the key array\n\tconst serializedKey = serializeKey(key);\n\n\t// Combine name and serialized key\n\treturn `${escapedName}:${serializedKey}`;\n}\n\n/**\n * Serializes an array of key strings into a single string\n *\n * @param key Array of key strings to serialize\n * @returns A single string containing the serialized key\n */\nexport function serializeKey(key: string[]): string {\n\t// Use a special marker for empty key arrays\n\tif (key.length === 0) {\n\t\treturn EMPTY_KEY;\n\t}\n\n\t// Escape each key part to handle the separator and the empty key marker\n\tconst escapedParts = key.map((part) => {\n\t\t// First check if it matches our empty key marker\n\t\tif (part === EMPTY_KEY) {\n\t\t\treturn `\\\\${EMPTY_KEY}`;\n\t\t}\n\n\t\t// Escape backslashes first, then commas\n\t\tlet escaped = part.replace(/\\\\/g, \"\\\\\\\\\");\n\t\tescaped = escaped.replace(/,/g, \"\\\\,\");\n\t\treturn escaped;\n\t});\n\n\treturn escapedParts.join(KEY_SEPARATOR);\n}\n\n/**\n * Deserializes a key string back into an array of key strings\n *\n * @param keyString The serialized key string\n * @returns Array of key strings\n */\nexport function deserializeKey(keyString: string): string[] {\n\t// Handle empty values\n\tif (!keyString) {\n\t\treturn [];\n\t}\n\n\t// Check for special empty key marker\n\tif (keyString === EMPTY_KEY) {\n\t\treturn [];\n\t}\n\n\t// Split by unescaped commas and unescape the escaped characters\n\tconst parts: string[] = [];\n\tlet currentPart = \"\";\n\tlet escaping = false;\n\n\tfor (let i = 0; i < keyString.length; i++) {\n\t\tconst char = keyString[i];\n\n\t\tif (escaping) {\n\t\t\t// This is an escaped character, add it directly\n\t\t\tcurrentPart += char;\n\t\t\tescaping = false;\n\t\t} else if (char === \"\\\\\") {\n\t\t\t// Start of an escape sequence\n\t\t\tescaping = true;\n\t\t} else if (char === KEY_SEPARATOR) {\n\t\t\t// This is a separator\n\t\t\tparts.push(currentPart);\n\t\t\tcurrentPart = \"\";\n\t\t} else {\n\t\t\t// Regular character\n\t\t\tcurrentPart += char;\n\t\t}\n\t}\n\n\t// Add the last part if it exists\n\tif (currentPart || parts.length > 0) {\n\t\tparts.push(currentPart);\n\t}\n\n\treturn parts;\n}\n","// Modified from https://github.com/honojs/hono/blob/40ea0eee58e39b31053a0246c595434f1094ad31/src/adapter/cloudflare-workers/websocket.ts#L17\n//\n// This version calls the open event by default\n\nimport type { UpgradeWebSocket, WSEvents, WSReadyState } from \"hono/ws\";\nimport { defineWebSocketHelper, WSContext } from \"hono/ws\";\n\n// Based on https://github.com/honojs/hono/issues/1153#issuecomment-1767321332\nexport const upgradeWebSocket: UpgradeWebSocket<\n\tWebSocket,\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tany,\n\tWSEvents<WebSocket>\n> = defineWebSocketHelper(async (c, events) => {\n\tconst upgradeHeader = c.req.header(\"Upgrade\");\n\tif (upgradeHeader !== \"websocket\") {\n\t\treturn;\n\t}\n\n\tconst webSocketPair = new WebSocketPair();\n\tconst client: WebSocket = webSocketPair[0];\n\tconst server: WebSocket = webSocketPair[1];\n\n\tconst wsContext = new WSContext<WebSocket>({\n\t\tclose: (code, reason) => server.close(code, reason),\n\t\tget protocol() {\n\t\t\treturn server.protocol;\n\t\t},\n\t\traw: server,\n\t\tget readyState() {\n\t\t\treturn server.readyState as WSReadyState;\n\t\t},\n\t\turl: server.url ? new URL(server.url) : null,\n\t\tsend: (source) => server.send(source),\n\t});\n\n\tif (events.onClose) {\n\t\tserver.addEventListener(\"close\", (evt: CloseEvent) =>\n\t\t\tevents.onClose?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onMessage) {\n\t\tserver.addEventListener(\"message\", (evt: MessageEvent) =>\n\t\t\tevents.onMessage?.(evt, wsContext),\n\t\t);\n\t}\n\tif (events.onError) {\n\t\tserver.addEventListener(\"error\", (evt: Event) =>\n\t\t\tevents.onError?.(evt, wsContext),\n\t\t);\n\t}\n\n\tserver.accept?.();\n\n\t// note: cloudflare actors doesn't support 'open' event, so we call it immediately with a fake event\n\t//\n\t// we have to do this after `server.accept() is called`\n\tevents.onOpen?.(new Event(\"open\"), wsContext);\n\n\treturn new Response(null, {\n\t\tstatus: 101,\n\t\theaders: {\n\t\t\t// HACK: Required in order for Cloudflare to not error with \"Network connection lost\"\n\t\t\t//\n\t\t\t// This bug undocumented. Cannot easily reproduce outside of RivetKit.\n\t\t\t\"Sec-WebSocket-Protocol\": \"rivetkit\",\n\t\t},\n\t\twebSocket: client,\n\t});\n});\n"],"mappings":";AAAA,SAAS,yBAAyB;AAGlC,SAAS,YAAY;AACrB,OAAOA,gBAAe;;;ACJtB,SAAS,qBAAqB;AAO9B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,iCAAiC;;;ACP1C;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAOP,OAAO,eAAe;AAaf,IAAM,qCAAN,MAAyC;AAAA;AAAA,EAE/C,OAA8C,oBAAI,IAAI;AAAA,EAEtD,WAAW,SAA2C;AACrD,UAAM,QAAQ,KAAK,KAAK,IAAI,OAAO;AACnC,cAAU,UAAU,QAAW,0CAA0C;AACzE,WAAO;AAAA,EACR;AAAA,EAEA,WAAW,SAAiB,OAAiC;AAC5D,SAAK,KAAK,IAAI,SAAS,KAAK;AAAA,EAC7B;AACD;AAQA,IAAM,eAAN,MAAmB;AAAA,EAClB;AAAA,EACA,eAA4C,QAAQ,cAAc;AAAA,EAClE,yBAAyB,IAAI,uBAAuB;AACrD;AAEO,IAAM,8BAAN,MAAyD;AAAA,EAC/D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAqC,oBAAI,IAAI;AAAA,EAE7C,YACC,gBACA,WACA,eACA,cACA,aACC;AACD,SAAK,kBAAkB;AACvB,SAAK,aAAa;AAClB,SAAK,iBA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@@
1
1
  {
2
2
  "name": "@rivetkit/cloudflare-workers",
3
- "version": "0.9.3",
3
+ "version": "0.9.6",
4
4
  "keywords": [
5
5
  "rivetkit",
6
6
  "cloudflare",
@@ -42,7 +42,7 @@
42
42
  "invariant": "^2.2.4",
43
43
  "zod": "^3.25.76",
44
44
  "hono": "4.8.3",
45
- "@rivetkit/core": "0.9.3"
45
+ "@rivetkit/core": "0.9.6"
46
46
  },
47
47
  "stableVersion": "0.8.0",
48
48
  "scripts": {
package/src/handler.ts CHANGED
@@ -58,6 +58,7 @@ export function createServer<R extends Registry<any>>(
58
58
  // Create config
59
59
  const runConfig = {
60
60
  driver: {
61
+ name: "cloudflare-workers",
61
62
  manager: () => new CloudflareActorsManagerDriver(),
62
63
  // HACK: We can't build the actor driver until we're inside the Durable Object
63
64
  actor: undefined as any,