@rivetkit/cloudflare-workers 2.0.4 → 2.0.5
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 +25 -23
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.d.cts +26 -15
- package/dist/mod.d.ts +26 -15
- package/dist/mod.js +24 -22
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +7 -2
- package/src/handler.ts +26 -34
- package/src/mod.ts +2 -1
package/dist/mod.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _class;// src/handler.ts
|
|
2
2
|
var _cloudflareworkers = require('cloudflare:workers');
|
|
3
|
-
var _hono = require('hono');
|
|
4
3
|
|
|
5
4
|
// src/actor-handler-do.ts
|
|
6
5
|
|
|
@@ -241,7 +240,9 @@ function createActorDurableObject(registry, rootRunConfig) {
|
|
|
241
240
|
|
|
242
241
|
var _zod = require('zod');
|
|
243
242
|
var ConfigSchema = _driverhelpers.RunConfigSchema.removeDefault().omit({ driver: true, getUpgradeWebSocket: true }).extend({
|
|
244
|
-
|
|
243
|
+
/** Path that the Rivet manager API will be mounted. */
|
|
244
|
+
managerPath: _zod.z.string().optional().default("/rivet"),
|
|
245
|
+
fetch: _zod.z.custom().optional()
|
|
245
246
|
}).default({});
|
|
246
247
|
|
|
247
248
|
// src/manager-driver.ts
|
|
@@ -577,11 +578,7 @@ var upgradeWebSocket = _ws.defineWebSocketHelper.call(void 0, async (c, events)
|
|
|
577
578
|
function getCloudflareAmbientEnv() {
|
|
578
579
|
return _cloudflareworkers.env;
|
|
579
580
|
}
|
|
580
|
-
function
|
|
581
|
-
const { createHandler } = createServer(registry, inputConfig);
|
|
582
|
-
return createHandler();
|
|
583
|
-
}
|
|
584
|
-
function createServer(registry, inputConfig) {
|
|
581
|
+
function createHandler(registry, inputConfig) {
|
|
585
582
|
const config = ConfigSchema.parse(inputConfig);
|
|
586
583
|
const runConfig = {
|
|
587
584
|
...config,
|
|
@@ -594,25 +591,30 @@ function createServer(registry, inputConfig) {
|
|
|
594
591
|
getUpgradeWebSocket: () => upgradeWebSocket
|
|
595
592
|
};
|
|
596
593
|
const ActorHandler2 = createActorDurableObject(registry, runConfig);
|
|
597
|
-
const serverOutput = registry.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
594
|
+
const serverOutput = registry.start(runConfig);
|
|
595
|
+
const handler = {
|
|
596
|
+
fetch: (request, cfEnv, ctx) => {
|
|
597
|
+
const url = new URL(request.url);
|
|
598
|
+
const env3 = Object.assign({ RIVET: serverOutput.client }, cfEnv);
|
|
599
|
+
if (url.pathname.startsWith(config.managerPath)) {
|
|
600
|
+
const strippedPath = url.pathname.substring(config.managerPath.length);
|
|
601
|
+
url.pathname = strippedPath;
|
|
602
|
+
const modifiedRequest = new Request(url.toString(), request);
|
|
603
|
+
return serverOutput.fetch(modifiedRequest, env3, ctx);
|
|
604
|
+
}
|
|
605
|
+
if (config.fetch) {
|
|
606
|
+
return config.fetch(request, env3, ctx);
|
|
607
|
+
} else {
|
|
608
|
+
return new Response(
|
|
609
|
+
"This is a RivetKit server.\n\nLearn more at https://rivetkit.org\n",
|
|
610
|
+
{ status: 200 }
|
|
611
|
+
);
|
|
604
612
|
}
|
|
605
|
-
const handler = {
|
|
606
|
-
fetch: (request, env3, ctx) => {
|
|
607
|
-
return app.fetch(request, env3, ctx);
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
return { handler, ActorHandler: ActorHandler2 };
|
|
611
613
|
}
|
|
612
614
|
};
|
|
615
|
+
return { handler, ActorHandler: ActorHandler2 };
|
|
613
616
|
}
|
|
614
617
|
|
|
615
618
|
|
|
616
|
-
|
|
617
|
-
exports.createServer = createServer; exports.createServerHandler = createServerHandler;
|
|
619
|
+
exports.createHandler = createHandler;
|
|
618
620
|
//# sourceMappingURL=mod.cjs.map
|
package/dist/mod.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/nathan/rivetkit/packages/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":["invariant","env","_a","ActorHandler"],"mappings":"AAAA;ACAA,uDAAoB;AACpB,4BAAqB;ADErB;AACA;AEJA;AAEA,4FAAsB;AAEtB,oCAA0D;AAC1D,wDAA0C;AFI1C;AACA;AGVA;AAMA;AACC;AACA;AACA;AAAA;AAoBM,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;AAOA,IAAM,aAAA,YAAN,MAAmB;AAAA,EAClB;AAAA,iBACA,aAAA,EAA4C,OAAA,CAAQ,aAAA,CAAc,EAAA;AAAA,kBAClE,uBAAA,EAAyB,IAAI,qCAAA,CAAuB,EAAA;AACrD,UAAA;AAEO,IAAM,4BAAA,EAAN,MAAyD;AAAA,EA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I,IAAA;AAAiB,MAAA;AAAU,MAAA;AArCpCC,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;ARyfW;AACA;ACviBI;AACRD,EAAAA;AACR;AAYgB;AAIP,EAAA;AACD,EAAA;AACR;AAEgB;AAIT,EAAA;AAGA,EAAA;AACF,IAAA;AACK,IAAA;AACD,MAAA;AACN,MAAA;AAAiD;AAEjD,MAAA;AACD,IAAA;AACA,IAAA;AACD,EAAA;AAGME,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;AD0gBY;AACA;AACA;AACA","file":"/Users/nathan/rivetkit/packages/cloudflare-workers/dist/mod.cjs","sourcesContent":[null,"import { env } from \"cloudflare:workers\";\nimport { Hono } from \"hono\";\nimport type { Registry, RunConfig } from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\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 function getCloudflareAmbientEnv(): Bindings {\n\treturn env as unknown as Bindings;\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\t...config,\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} 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 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, env } from \"cloudflare:workers\";\nimport type { ExecutionContext } from \"hono\";\nimport invariant from \"invariant\";\nimport type { ActorKey, ActorRouter, Registry, RunConfig } from \"rivetkit\";\nimport { createActorRouter, createClientWithDriver } from \"rivetkit\";\nimport { serializeEmptyPersistData } from \"rivetkit/driver-helpers\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport type { Bindings } 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\trootRunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t// Configure to use the runner role instead of server role\n\tconst runConfig = Object.assign({}, rootRunConfig, { role: \"runner\" });\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// 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({ msg: \"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: env });\n\n\t\t\t// Configure actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.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(managerDriver);\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\tawait this.ctx.storage.put({\n\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t});\n\t\t\tthis.#initialized = {\n\t\t\t\tname: req.name,\n\t\t\t\tkey: req.key,\n\t\t\t};\n\n\t\t\tlogger().debug({ msg: \"initialized actor\", key: req.key });\n\n\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\tawait this.#loadActor();\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\tactorId,\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\tawait this.#loadActor();\n\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t// Get the actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.driver\");\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\t\t\tconst inlineClient = createClientWithDriver(managerDriver);\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// Load the actor instance and trigger alarm\n\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\tawait actor._onAlarm();\n\t\t}\n\t};\n}\n","import invariant from \"invariant\";\nimport type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"rivetkit\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"rivetkit/driver-helpers\";\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 DriverContext {\n\tstate: DurableObjectState;\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): DriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { state: state.ctx };\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/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-cloudflare-workers\");\n}\n","import type { Hono } from \"hono\";\nimport { RunConfigSchema } from \"rivetkit/driver-helpers\";\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 { Context as HonoContext } from \"hono\";\nimport type { Encoding, UniversalWebSocket } from \"rivetkit\";\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\ttype ManagerDisplayInformation,\n\ttype ManagerDriver,\n} from \"rivetkit/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"rivetkit/errors\";\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\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({\n\t\t\tmsg: \"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<UniversalWebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug({\n\t\t\tmsg: \"opening websocket to durable object\",\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\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_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({ msg: \"rewriting websocket url\", from: path, to: url });\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({\n\t\t\tmsg: \"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 UniversalWebSocket;\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({\n\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug({\n\t\t\tmsg: \"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_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({ msg: \"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({\n\t\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tdisplayInformation(): ManagerDisplayInformation {\n\t\treturn {\n\t\t\tname: \"Cloudflare Workers\",\n\t\t\tproperties: {},\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":["/Users/nathan/rivetkit/packages/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":["invariant","env","_a","ActorHandler"],"mappings":"AAAA;ACAA,uDAAoB;ADEpB;AACA;AEHA;AAEA,4FAAsB;AAEtB,oCAA0D;AAC1D,wDAA0C;AFG1C;AACA;AGTA;AAMA;AACC;AACA;AACA;AAAA;AAoBM,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;AAOA,IAAM,aAAA,YAAN,MAAmB;AAAA,EAClB;AAAA,iBACA,aAAA,EAA4C,OAAA,CAAQ,aAAA,CAAc,EAAA;AAAA,kBAClE,uBAAA,EAAyB,IAAI,qCAAA,CAAuB,EAAA;AACrD,UAAA;AAEO,IAAM,4BAAA,EAAN,MAAyD;AAAA,EAC/D,CAAA,cAAA;AAAA,EACA,CAAA,SAAA;AAAA,EACA,CAAA,aAAA;AAAA,EACA,CAAA,YAAA;AAAA,EACA,CAAA,WAAA;AAAA,EACA,CAAA,OAAA,kBAAqC,IAAI,GAAA,CAA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pCC,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;AC1iBI;AACRD,EAAAA;AACR;AAOgB;AAIT,EAAA;AAGA,EAAA;AACF,IAAA;AACK,IAAA;AACD,MAAA;AACN,MAAA;AAAiD;AAEjD,MAAA;AACD,IAAA;AACA,IAAA;AACD,EAAA;AAGME,EAAAA;AAGA,EAAA;AAGA,EAAA;AACG,IAAA;AACD,MAAA;AAGAF,MAAAA;AAGF,MAAA;AACH,QAAA;AACI,QAAA;AACJ,QAAA;AACA,QAAA;AACD,MAAA;AAEI,MAAA;AACH,QAAA;AACD,MAAA;AACC,QAAA;AACC,UAAA;AACE,UAAA;AACH,QAAA;AACD,MAAA;AACD,IAAA;AACD,EAAA;AAES,EAAA;AACV;ADqhBY;AACA;AACA","file":"/Users/nathan/rivetkit/packages/cloudflare-workers/dist/mod.cjs","sourcesContent":[null,"import { env } from \"cloudflare:workers\";\nimport type { Registry, RunConfig } from \"rivetkit\";\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 function getCloudflareAmbientEnv(): Bindings {\n\treturn env as unknown as Bindings;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\nexport function createHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\t...config,\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} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.start(runConfig);\n\n\t// Create Cloudflare handler\n\tconst handler = {\n\t\tfetch: (request, cfEnv, ctx) => {\n\t\t\tconst url = new URL(request.url);\n\n\t\t\t// Inject Rivet env\n\t\t\tconst env = Object.assign({ RIVET: serverOutput.client }, cfEnv);\n\n\t\t\t// Mount Rivet manager API\n\t\t\tif (url.pathname.startsWith(config.managerPath)) {\n\t\t\t\tconst strippedPath = url.pathname.substring(config.managerPath.length);\n\t\t\t\turl.pathname = strippedPath;\n\t\t\t\tconst modifiedRequest = new Request(url.toString(), request);\n\t\t\t\treturn serverOutput.fetch(modifiedRequest, env, ctx);\n\t\t\t}\n\n\t\t\tif (config.fetch) {\n\t\t\t\treturn config.fetch(request, env, ctx);\n\t\t\t} else {\n\t\t\t\treturn new Response(\n\t\t\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivetkit.org\\n\",\n\t\t\t\t\t{ status: 200 },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t} satisfies ExportedHandler<Bindings>;\n\n\treturn { handler, ActorHandler };\n}\n","import { DurableObject, env } from \"cloudflare:workers\";\nimport type { ExecutionContext } from \"hono\";\nimport invariant from \"invariant\";\nimport type { ActorKey, ActorRouter, Registry, RunConfig } from \"rivetkit\";\nimport { createActorRouter, createClientWithDriver } from \"rivetkit\";\nimport { serializeEmptyPersistData } from \"rivetkit/driver-helpers\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport type { Bindings } 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\trootRunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t// Configure to use the runner role instead of server role\n\tconst runConfig = Object.assign({}, rootRunConfig, { role: \"runner\" });\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// 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({ msg: \"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: env });\n\n\t\t\t// Configure actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.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(managerDriver);\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\tawait this.ctx.storage.put({\n\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t});\n\t\t\tthis.#initialized = {\n\t\t\t\tname: req.name,\n\t\t\t\tkey: req.key,\n\t\t\t};\n\n\t\t\tlogger().debug({ msg: \"initialized actor\", key: req.key });\n\n\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\tawait this.#loadActor();\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\tactorId,\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\tawait this.#loadActor();\n\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t// Get the actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.driver\");\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\t\t\tconst inlineClient = createClientWithDriver(managerDriver);\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// Load the actor instance and trigger alarm\n\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\tawait actor._onAlarm();\n\t\t}\n\t};\n}\n","import invariant from \"invariant\";\nimport type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"rivetkit\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"rivetkit/driver-helpers\";\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 DriverContext {\n\tstate: DurableObjectState;\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): DriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { state: state.ctx };\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/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-cloudflare-workers\");\n}\n","import type { Client } from \"rivetkit\";\nimport { RunConfigSchema } from \"rivetkit/driver-helpers\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\t/** Path that the Rivet manager API will be mounted. */\n\t\tmanagerPath: z.string().optional().default(\"/rivet\"),\n\n\t\tfetch: z\n\t\t\t.custom<ExportedHandlerFetchHandler<{ RIVET: Client<any> }, unknown>>()\n\t\t\t.optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Context as HonoContext } from \"hono\";\nimport type { Encoding, UniversalWebSocket } from \"rivetkit\";\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\ttype ManagerDisplayInformation,\n\ttype ManagerDriver,\n} from \"rivetkit/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"rivetkit/errors\";\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\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({\n\t\t\tmsg: \"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<UniversalWebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug({\n\t\t\tmsg: \"opening websocket to durable object\",\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\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_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({ msg: \"rewriting websocket url\", from: path, to: url });\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({\n\t\t\tmsg: \"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 UniversalWebSocket;\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({\n\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug({\n\t\t\tmsg: \"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_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({ msg: \"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({\n\t\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tdisplayInformation(): ManagerDisplayInformation {\n\t\treturn {\n\t\t\tname: \"Cloudflare Workers\",\n\t\t\tproperties: {},\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
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as rivetkit from 'rivetkit';
|
|
2
|
+
import { Client, ActorKey, Registry } from 'rivetkit';
|
|
3
|
+
export { Client } from 'rivetkit';
|
|
2
4
|
import * as rivetkit_log from 'rivetkit/log';
|
|
3
5
|
import * as hono from 'hono';
|
|
4
|
-
import { Hono } from 'hono';
|
|
5
6
|
import * as rivetkit_driver_helpers from 'rivetkit/driver-helpers';
|
|
6
|
-
import * as rivetkit from 'rivetkit';
|
|
7
|
-
import { ActorKey, Registry } from 'rivetkit';
|
|
8
7
|
import * as rivetkit_utils from 'rivetkit/utils';
|
|
9
8
|
import { z } from 'zod';
|
|
10
|
-
import { Client } from 'rivetkit/client';
|
|
11
9
|
import { DurableObject } from 'cloudflare:workers';
|
|
12
10
|
|
|
13
11
|
interface DriverContext {
|
|
@@ -105,6 +103,8 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
105
103
|
token?: ((...args: unknown[]) => string) | undefined;
|
|
106
104
|
defaultEndpoint?: string | undefined;
|
|
107
105
|
}>>>;
|
|
106
|
+
disableServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
107
|
+
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
108
108
|
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
109
109
|
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
110
110
|
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
@@ -118,7 +118,13 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
118
118
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
119
119
|
}>>>;
|
|
120
120
|
}, "getUpgradeWebSocket" | "driver"> & {
|
|
121
|
-
|
|
121
|
+
/** Path that the Rivet manager API will be mounted. */
|
|
122
|
+
managerPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
123
|
+
fetch: z.ZodOptional<z.ZodType<ExportedHandlerFetchHandler<{
|
|
124
|
+
RIVET: Client<any>;
|
|
125
|
+
}, unknown>, z.ZodTypeDef, ExportedHandlerFetchHandler<{
|
|
126
|
+
RIVET: Client<any>;
|
|
127
|
+
}, unknown>>>;
|
|
122
128
|
}, "strip", z.ZodTypeAny, {
|
|
123
129
|
api: {
|
|
124
130
|
host: string;
|
|
@@ -143,12 +149,15 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
143
149
|
token: (...args: unknown[]) => string;
|
|
144
150
|
defaultEndpoint?: string | undefined;
|
|
145
151
|
};
|
|
152
|
+
disableServer: boolean;
|
|
153
|
+
disableActorDriver: boolean;
|
|
146
154
|
basePath: string;
|
|
147
155
|
noWelcome: boolean;
|
|
148
156
|
logging: {
|
|
149
157
|
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
150
158
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
151
159
|
};
|
|
160
|
+
managerPath: string;
|
|
152
161
|
cors?: {
|
|
153
162
|
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
154
163
|
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
@@ -157,7 +166,9 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
157
166
|
credentials?: boolean;
|
|
158
167
|
exposeHeaders?: string[];
|
|
159
168
|
} | undefined;
|
|
160
|
-
|
|
169
|
+
fetch?: ExportedHandlerFetchHandler<{
|
|
170
|
+
RIVET: Client<any>;
|
|
171
|
+
}, unknown> | undefined;
|
|
161
172
|
}, {
|
|
162
173
|
api?: {
|
|
163
174
|
host?: string | undefined;
|
|
@@ -190,13 +201,18 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
190
201
|
token?: ((...args: unknown[]) => string) | undefined;
|
|
191
202
|
defaultEndpoint?: string | undefined;
|
|
192
203
|
} | undefined;
|
|
204
|
+
disableServer?: boolean | undefined;
|
|
205
|
+
disableActorDriver?: boolean | undefined;
|
|
193
206
|
basePath?: string | undefined;
|
|
194
207
|
noWelcome?: boolean | undefined;
|
|
195
208
|
logging?: {
|
|
196
209
|
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
197
210
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
198
211
|
} | undefined;
|
|
199
|
-
|
|
212
|
+
managerPath?: string | undefined;
|
|
213
|
+
fetch?: ExportedHandlerFetchHandler<{
|
|
214
|
+
RIVET: Client<any>;
|
|
215
|
+
}, unknown> | undefined;
|
|
200
216
|
}>>;
|
|
201
217
|
type InputConfig = z.input<typeof ConfigSchema>;
|
|
202
218
|
|
|
@@ -219,11 +235,6 @@ interface Handler {
|
|
|
219
235
|
handler: ExportedHandler<Bindings>;
|
|
220
236
|
ActorHandler: DurableObjectConstructor;
|
|
221
237
|
}
|
|
222
|
-
|
|
223
|
-
client: Client<A>;
|
|
224
|
-
createHandler: (hono?: Hono) => Handler;
|
|
225
|
-
}
|
|
226
|
-
declare function createServerHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): Handler;
|
|
227
|
-
declare function createServer<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): SetupOutput<R>;
|
|
238
|
+
declare function createHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): Handler;
|
|
228
239
|
|
|
229
|
-
export { type Bindings, type InputConfig as Config, type DriverContext,
|
|
240
|
+
export { type Bindings, type InputConfig as Config, type DriverContext, createHandler };
|
package/dist/mod.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as rivetkit from 'rivetkit';
|
|
2
|
+
import { Client, ActorKey, Registry } from 'rivetkit';
|
|
3
|
+
export { Client } from 'rivetkit';
|
|
2
4
|
import * as rivetkit_log from 'rivetkit/log';
|
|
3
5
|
import * as hono from 'hono';
|
|
4
|
-
import { Hono } from 'hono';
|
|
5
6
|
import * as rivetkit_driver_helpers from 'rivetkit/driver-helpers';
|
|
6
|
-
import * as rivetkit from 'rivetkit';
|
|
7
|
-
import { ActorKey, Registry } from 'rivetkit';
|
|
8
7
|
import * as rivetkit_utils from 'rivetkit/utils';
|
|
9
8
|
import { z } from 'zod';
|
|
10
|
-
import { Client } from 'rivetkit/client';
|
|
11
9
|
import { DurableObject } from 'cloudflare:workers';
|
|
12
10
|
|
|
13
11
|
interface DriverContext {
|
|
@@ -105,6 +103,8 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
105
103
|
token?: ((...args: unknown[]) => string) | undefined;
|
|
106
104
|
defaultEndpoint?: string | undefined;
|
|
107
105
|
}>>>;
|
|
106
|
+
disableServer: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
107
|
+
disableActorDriver: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
108
108
|
basePath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
109
109
|
noWelcome: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
110
110
|
logging: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
@@ -118,7 +118,13 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
118
118
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
119
119
|
}>>>;
|
|
120
120
|
}, "getUpgradeWebSocket" | "driver"> & {
|
|
121
|
-
|
|
121
|
+
/** Path that the Rivet manager API will be mounted. */
|
|
122
|
+
managerPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
123
|
+
fetch: z.ZodOptional<z.ZodType<ExportedHandlerFetchHandler<{
|
|
124
|
+
RIVET: Client<any>;
|
|
125
|
+
}, unknown>, z.ZodTypeDef, ExportedHandlerFetchHandler<{
|
|
126
|
+
RIVET: Client<any>;
|
|
127
|
+
}, unknown>>>;
|
|
122
128
|
}, "strip", z.ZodTypeAny, {
|
|
123
129
|
api: {
|
|
124
130
|
host: string;
|
|
@@ -143,12 +149,15 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
143
149
|
token: (...args: unknown[]) => string;
|
|
144
150
|
defaultEndpoint?: string | undefined;
|
|
145
151
|
};
|
|
152
|
+
disableServer: boolean;
|
|
153
|
+
disableActorDriver: boolean;
|
|
146
154
|
basePath: string;
|
|
147
155
|
noWelcome: boolean;
|
|
148
156
|
logging: {
|
|
149
157
|
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
150
158
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
151
159
|
};
|
|
160
|
+
managerPath: string;
|
|
152
161
|
cors?: {
|
|
153
162
|
origin: string | string[] | ((origin: string, c: hono.Context) => string | undefined | null);
|
|
154
163
|
allowMethods?: string[] | ((origin: string, c: hono.Context) => string[]);
|
|
@@ -157,7 +166,9 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
157
166
|
credentials?: boolean;
|
|
158
167
|
exposeHeaders?: string[];
|
|
159
168
|
} | undefined;
|
|
160
|
-
|
|
169
|
+
fetch?: ExportedHandlerFetchHandler<{
|
|
170
|
+
RIVET: Client<any>;
|
|
171
|
+
}, unknown> | undefined;
|
|
161
172
|
}, {
|
|
162
173
|
api?: {
|
|
163
174
|
host?: string | undefined;
|
|
@@ -190,13 +201,18 @@ declare const ConfigSchema: z.ZodDefault<z.ZodObject<Omit<{
|
|
|
190
201
|
token?: ((...args: unknown[]) => string) | undefined;
|
|
191
202
|
defaultEndpoint?: string | undefined;
|
|
192
203
|
} | undefined;
|
|
204
|
+
disableServer?: boolean | undefined;
|
|
205
|
+
disableActorDriver?: boolean | undefined;
|
|
193
206
|
basePath?: string | undefined;
|
|
194
207
|
noWelcome?: boolean | undefined;
|
|
195
208
|
logging?: {
|
|
196
209
|
level?: "error" | "trace" | "fatal" | "warn" | "info" | "debug" | "silent" | undefined;
|
|
197
210
|
baseLogger?: rivetkit_log.Logger | undefined;
|
|
198
211
|
} | undefined;
|
|
199
|
-
|
|
212
|
+
managerPath?: string | undefined;
|
|
213
|
+
fetch?: ExportedHandlerFetchHandler<{
|
|
214
|
+
RIVET: Client<any>;
|
|
215
|
+
}, unknown> | undefined;
|
|
200
216
|
}>>;
|
|
201
217
|
type InputConfig = z.input<typeof ConfigSchema>;
|
|
202
218
|
|
|
@@ -219,11 +235,6 @@ interface Handler {
|
|
|
219
235
|
handler: ExportedHandler<Bindings>;
|
|
220
236
|
ActorHandler: DurableObjectConstructor;
|
|
221
237
|
}
|
|
222
|
-
|
|
223
|
-
client: Client<A>;
|
|
224
|
-
createHandler: (hono?: Hono) => Handler;
|
|
225
|
-
}
|
|
226
|
-
declare function createServerHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): Handler;
|
|
227
|
-
declare function createServer<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): SetupOutput<R>;
|
|
238
|
+
declare function createHandler<R extends Registry<any>>(registry: R, inputConfig?: InputConfig): Handler;
|
|
228
239
|
|
|
229
|
-
export { type Bindings, type InputConfig as Config, type DriverContext,
|
|
240
|
+
export { type Bindings, type InputConfig as Config, type DriverContext, createHandler };
|
package/dist/mod.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/handler.ts
|
|
2
2
|
import { env as env2 } from "cloudflare:workers";
|
|
3
|
-
import { Hono } from "hono";
|
|
4
3
|
|
|
5
4
|
// src/actor-handler-do.ts
|
|
6
5
|
import { DurableObject, env } from "cloudflare:workers";
|
|
@@ -241,7 +240,9 @@ function createActorDurableObject(registry, rootRunConfig) {
|
|
|
241
240
|
import { RunConfigSchema } from "rivetkit/driver-helpers";
|
|
242
241
|
import { z } from "zod";
|
|
243
242
|
var ConfigSchema = RunConfigSchema.removeDefault().omit({ driver: true, getUpgradeWebSocket: true }).extend({
|
|
244
|
-
|
|
243
|
+
/** Path that the Rivet manager API will be mounted. */
|
|
244
|
+
managerPath: z.string().optional().default("/rivet"),
|
|
245
|
+
fetch: z.custom().optional()
|
|
245
246
|
}).default({});
|
|
246
247
|
|
|
247
248
|
// src/manager-driver.ts
|
|
@@ -577,11 +578,7 @@ var upgradeWebSocket = defineWebSocketHelper(async (c, events) => {
|
|
|
577
578
|
function getCloudflareAmbientEnv() {
|
|
578
579
|
return env2;
|
|
579
580
|
}
|
|
580
|
-
function
|
|
581
|
-
const { createHandler } = createServer(registry, inputConfig);
|
|
582
|
-
return createHandler();
|
|
583
|
-
}
|
|
584
|
-
function createServer(registry, inputConfig) {
|
|
581
|
+
function createHandler(registry, inputConfig) {
|
|
585
582
|
const config = ConfigSchema.parse(inputConfig);
|
|
586
583
|
const runConfig = {
|
|
587
584
|
...config,
|
|
@@ -594,25 +591,30 @@ function createServer(registry, inputConfig) {
|
|
|
594
591
|
getUpgradeWebSocket: () => upgradeWebSocket
|
|
595
592
|
};
|
|
596
593
|
const ActorHandler2 = createActorDurableObject(registry, runConfig);
|
|
597
|
-
const serverOutput = registry.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
if (
|
|
603
|
-
|
|
594
|
+
const serverOutput = registry.start(runConfig);
|
|
595
|
+
const handler = {
|
|
596
|
+
fetch: (request, cfEnv, ctx) => {
|
|
597
|
+
const url = new URL(request.url);
|
|
598
|
+
const env3 = Object.assign({ RIVET: serverOutput.client }, cfEnv);
|
|
599
|
+
if (url.pathname.startsWith(config.managerPath)) {
|
|
600
|
+
const strippedPath = url.pathname.substring(config.managerPath.length);
|
|
601
|
+
url.pathname = strippedPath;
|
|
602
|
+
const modifiedRequest = new Request(url.toString(), request);
|
|
603
|
+
return serverOutput.fetch(modifiedRequest, env3, ctx);
|
|
604
|
+
}
|
|
605
|
+
if (config.fetch) {
|
|
606
|
+
return config.fetch(request, env3, ctx);
|
|
607
|
+
} else {
|
|
608
|
+
return new Response(
|
|
609
|
+
"This is a RivetKit server.\n\nLearn more at https://rivetkit.org\n",
|
|
610
|
+
{ status: 200 }
|
|
611
|
+
);
|
|
604
612
|
}
|
|
605
|
-
const handler = {
|
|
606
|
-
fetch: (request, env3, ctx) => {
|
|
607
|
-
return app.fetch(request, env3, ctx);
|
|
608
|
-
}
|
|
609
|
-
};
|
|
610
|
-
return { handler, ActorHandler: ActorHandler2 };
|
|
611
613
|
}
|
|
612
614
|
};
|
|
615
|
+
return { handler, ActorHandler: ActorHandler2 };
|
|
613
616
|
}
|
|
614
617
|
export {
|
|
615
|
-
|
|
616
|
-
createServerHandler
|
|
618
|
+
createHandler
|
|
617
619
|
};
|
|
618
620
|
//# sourceMappingURL=mod.js.map
|
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 { env } from \"cloudflare:workers\";\nimport { Hono } from \"hono\";\nimport type { Registry, RunConfig } from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\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 function getCloudflareAmbientEnv(): Bindings {\n\treturn env as unknown as Bindings;\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\t...config,\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} 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 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, env } from \"cloudflare:workers\";\nimport type { ExecutionContext } from \"hono\";\nimport invariant from \"invariant\";\nimport type { ActorKey, ActorRouter, Registry, RunConfig } from \"rivetkit\";\nimport { createActorRouter, createClientWithDriver } from \"rivetkit\";\nimport { serializeEmptyPersistData } from \"rivetkit/driver-helpers\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport type { Bindings } 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\trootRunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t// Configure to use the runner role instead of server role\n\tconst runConfig = Object.assign({}, rootRunConfig, { role: \"runner\" });\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// 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({ msg: \"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: env });\n\n\t\t\t// Configure actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.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(managerDriver);\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\tawait this.ctx.storage.put({\n\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t});\n\t\t\tthis.#initialized = {\n\t\t\t\tname: req.name,\n\t\t\t\tkey: req.key,\n\t\t\t};\n\n\t\t\tlogger().debug({ msg: \"initialized actor\", key: req.key });\n\n\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\tawait this.#loadActor();\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\tactorId,\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\tawait this.#loadActor();\n\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t// Get the actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.driver\");\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\t\t\tconst inlineClient = createClientWithDriver(managerDriver);\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// Load the actor instance and trigger alarm\n\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\tawait actor._onAlarm();\n\t\t}\n\t};\n}\n","import invariant from \"invariant\";\nimport type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"rivetkit\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"rivetkit/driver-helpers\";\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 DriverContext {\n\tstate: DurableObjectState;\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): DriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { state: state.ctx };\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/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-cloudflare-workers\");\n}\n","import type { Hono } from \"hono\";\nimport { RunConfigSchema } from \"rivetkit/driver-helpers\";\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 { Context as HonoContext } from \"hono\";\nimport type { Encoding, UniversalWebSocket } from \"rivetkit\";\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\ttype ManagerDisplayInformation,\n\ttype ManagerDriver,\n} from \"rivetkit/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"rivetkit/errors\";\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\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({\n\t\t\tmsg: \"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<UniversalWebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug({\n\t\t\tmsg: \"opening websocket to durable object\",\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\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_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({ msg: \"rewriting websocket url\", from: path, to: url });\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({\n\t\t\tmsg: \"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 UniversalWebSocket;\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({\n\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug({\n\t\t\tmsg: \"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_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({ msg: \"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({\n\t\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tdisplayInformation(): ManagerDisplayInformation {\n\t\treturn {\n\t\t\tname: \"Cloudflare Workers\",\n\t\t\tproperties: {},\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,OAAAA,YAAW;AACpB,SAAS,YAAY;;;ACDrB,SAAS,eAAe,WAAW;AAE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AAA;AAAA,MAEjD,OAAO;AAAA,IACR;AAAA,IACA,qBAAqB,MAAM;AAAA,EAC5B;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,SAASD,MAAK,QAAQ;AAC7B,iBAAO,IAAI,MAAM,SAASA,MAAK,GAAG;AAAA,QACnC;AAAA,MACD;AAEA,aAAO,EAAE,SAAS,cAAAC,cAAa;AAAA,IAChC;AAAA,EACD;AACD;","names":["env","invariant","invariant","KEYS","env","_a","env","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 { env } from \"cloudflare:workers\";\nimport type { Registry, RunConfig } from \"rivetkit\";\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 function getCloudflareAmbientEnv(): Bindings {\n\treturn env as unknown as Bindings;\n}\n\ninterface Handler {\n\thandler: ExportedHandler<Bindings>;\n\tActorHandler: DurableObjectConstructor;\n}\n\nexport function createHandler<R extends Registry<any>>(\n\tregistry: R,\n\tinputConfig?: InputConfig,\n): Handler {\n\tconst config = ConfigSchema.parse(inputConfig);\n\n\t// Create config\n\tconst runConfig = {\n\t\t...config,\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} satisfies RunConfig;\n\n\t// Create Durable Object\n\tconst ActorHandler = createActorDurableObject(registry, runConfig);\n\n\t// Create server\n\tconst serverOutput = registry.start(runConfig);\n\n\t// Create Cloudflare handler\n\tconst handler = {\n\t\tfetch: (request, cfEnv, ctx) => {\n\t\t\tconst url = new URL(request.url);\n\n\t\t\t// Inject Rivet env\n\t\t\tconst env = Object.assign({ RIVET: serverOutput.client }, cfEnv);\n\n\t\t\t// Mount Rivet manager API\n\t\t\tif (url.pathname.startsWith(config.managerPath)) {\n\t\t\t\tconst strippedPath = url.pathname.substring(config.managerPath.length);\n\t\t\t\turl.pathname = strippedPath;\n\t\t\t\tconst modifiedRequest = new Request(url.toString(), request);\n\t\t\t\treturn serverOutput.fetch(modifiedRequest, env, ctx);\n\t\t\t}\n\n\t\t\tif (config.fetch) {\n\t\t\t\treturn config.fetch(request, env, ctx);\n\t\t\t} else {\n\t\t\t\treturn new Response(\n\t\t\t\t\t\"This is a RivetKit server.\\n\\nLearn more at https://rivetkit.org\\n\",\n\t\t\t\t\t{ status: 200 },\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t} satisfies ExportedHandler<Bindings>;\n\n\treturn { handler, ActorHandler };\n}\n","import { DurableObject, env } from \"cloudflare:workers\";\nimport type { ExecutionContext } from \"hono\";\nimport invariant from \"invariant\";\nimport type { ActorKey, ActorRouter, Registry, RunConfig } from \"rivetkit\";\nimport { createActorRouter, createClientWithDriver } from \"rivetkit\";\nimport { serializeEmptyPersistData } from \"rivetkit/driver-helpers\";\nimport {\n\tCloudflareDurableObjectGlobalState,\n\tcreateCloudflareActorsActorDriverBuilder,\n} from \"./actor-driver\";\nimport type { Bindings } 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\trootRunConfig: RunConfig,\n): DurableObjectConstructor {\n\tconst globalState = new CloudflareDurableObjectGlobalState();\n\n\t// Configure to use the runner role instead of server role\n\tconst runConfig = Object.assign({}, rootRunConfig, { role: \"runner\" });\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// 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({ msg: \"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: env });\n\n\t\t\t// Configure actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.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(managerDriver);\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\tawait this.ctx.storage.put({\n\t\t\t\t[KEYS.NAME]: req.name,\n\t\t\t\t[KEYS.KEY]: req.key,\n\t\t\t\t[KEYS.PERSIST_DATA]: serializeEmptyPersistData(req.input),\n\t\t\t});\n\t\t\tthis.#initialized = {\n\t\t\t\tname: req.name,\n\t\t\t\tkey: req.key,\n\t\t\t};\n\n\t\t\tlogger().debug({ msg: \"initialized actor\", key: req.key });\n\n\t\t\t// Preemptively actor so the lifecycle hooks are called\n\t\t\tawait this.#loadActor();\n\t\t}\n\n\t\tasync fetch(request: Request): Promise<Response> {\n\t\t\tconst { actorRouter } = await this.#loadActor();\n\n\t\t\tconst actorId = this.ctx.id.toString();\n\t\t\treturn await actorRouter.fetch(request, {\n\t\t\t\tactorId,\n\t\t\t});\n\t\t}\n\n\t\tasync alarm(): Promise<void> {\n\t\t\tawait this.#loadActor();\n\t\t\tconst actorId = this.ctx.id.toString();\n\n\t\t\t// Get the actor driver\n\t\t\tinvariant(runConfig.driver, \"runConfig.driver\");\n\t\t\tconst managerDriver = runConfig.driver.manager(\n\t\t\t\tregistry.config,\n\t\t\t\trunConfig,\n\t\t\t);\n\t\t\tconst inlineClient = createClientWithDriver(managerDriver);\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// Load the actor instance and trigger alarm\n\t\t\tconst actor = await actorDriver.loadActor(actorId);\n\t\t\tawait actor._onAlarm();\n\t\t}\n\t};\n}\n","import invariant from \"invariant\";\nimport type {\n\tAnyActorInstance as CoreAnyActorInstance,\n\tRegistryConfig,\n\tRunConfig,\n} from \"rivetkit\";\nimport {\n\tcreateGenericConnDrivers,\n\tGenericConnGlobalState,\n\tlookupInRegistry,\n} from \"rivetkit\";\nimport type { Client } from \"rivetkit/client\";\nimport type {\n\tActorDriver,\n\tAnyActorInstance,\n\tManagerDriver,\n} from \"rivetkit/driver-helpers\";\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 DriverContext {\n\tstate: DurableObjectState;\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): DriverContext {\n\t\tconst state = this.#globalState.getDOState(actorId);\n\t\treturn { state: state.ctx };\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/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-cloudflare-workers\");\n}\n","import type { Client } from \"rivetkit\";\nimport { RunConfigSchema } from \"rivetkit/driver-helpers\";\nimport { z } from \"zod\";\n\nexport const ConfigSchema = RunConfigSchema.removeDefault()\n\t.omit({ driver: true, getUpgradeWebSocket: true })\n\t.extend({\n\t\t/** Path that the Rivet manager API will be mounted. */\n\t\tmanagerPath: z.string().optional().default(\"/rivet\"),\n\n\t\tfetch: z\n\t\t\t.custom<ExportedHandlerFetchHandler<{ RIVET: Client<any> }, unknown>>()\n\t\t\t.optional(),\n\t})\n\t.default({});\nexport type InputConfig = z.input<typeof ConfigSchema>;\nexport type Config = z.infer<typeof ConfigSchema>;\n","import type { Context as HonoContext } from \"hono\";\nimport type { Encoding, UniversalWebSocket } from \"rivetkit\";\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\ttype ManagerDisplayInformation,\n\ttype ManagerDriver,\n} from \"rivetkit/driver-helpers\";\nimport { ActorAlreadyExists, InternalError } from \"rivetkit/errors\";\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\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({\n\t\t\tmsg: \"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<UniversalWebSocket> {\n\t\tconst env = getCloudflareAmbientEnv();\n\n\t\tlogger().debug({\n\t\t\tmsg: \"opening websocket to durable object\",\n\t\t\tactorId,\n\t\t\tpath,\n\t\t});\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_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({ msg: \"rewriting websocket url\", from: path, to: url });\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({\n\t\t\tmsg: \"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 UniversalWebSocket;\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({\n\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tconst newUrl = new URL(`http://actor${path}`);\n\t\tconst actorRequest = new Request(newUrl, c.req.raw);\n\n\t\tlogger().debug({\n\t\t\tmsg: \"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_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({ msg: \"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({\n\t\t\t\tmsg: \"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({\n\t\t\tmsg: \"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\tdisplayInformation(): ManagerDisplayInformation {\n\t\treturn {\n\t\t\tname: \"Cloudflare Workers\",\n\t\t\tproperties: {},\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,OAAAA,YAAW;;;ACApB,SA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AEjD,OAAO;AAAA,IACR;AAAA,IACA,qBAAqB,MAAM;AAAA,EAC5B;AAGA,QAAMC,gBAAe,yBAAyB,UAAU,SAAS;AAGjE,QAAM,eAAe,SAAS,MAAM,SAAS;AAG7C,QAAM,UAAU;AAAA,IACf,OAAO,CAAC,SAAS,OAAO,QAAQ;AAC/B,YAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAG/B,YAAMD,OAAM,OAAO,OAAO,EAAE,OAAO,aAAa,OAAO,GAAG,KAAK;AAG/D,UAAI,IAAI,SAAS,WAAW,OAAO,WAAW,GAAG;AAChD,cAAM,eAAe,IAAI,SAAS,UAAU,OAAO,YAAY,MAAM;AACrE,YAAI,WAAW;AACf,cAAM,kBAAkB,IAAI,QAAQ,IAAI,SAAS,GAAG,OAAO;AAC3D,eAAO,aAAa,MAAM,iBAAiBA,MAAK,GAAG;AAAA,MACpD;AAEA,UAAI,OAAO,OAAO;AACjB,eAAO,OAAO,MAAM,SAASA,MAAK,GAAG;AAAA,MACtC,OAAO;AACN,eAAO,IAAI;AAAA,UACV;AAAA,UACA,EAAE,QAAQ,IAAI;AAAA,QACf;AAAA,MACD;AAAA,IACD;AAAA,EACD;AAEA,SAAO,EAAE,SAAS,cAAAC,cAAa;AAChC;","names":["env","invariant","invariant","KEYS","env","_a","env","ActorHandler"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivetkit/cloudflare-workers",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Cloudflare Workers adapter for RivetKit actors",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rivetkit",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"invariant": "^2.2.4",
|
|
44
44
|
"zod": "^3.25.76",
|
|
45
45
|
"hono": "4.8.3",
|
|
46
|
-
"rivetkit": "2.0.
|
|
46
|
+
"rivetkit": "2.0.5"
|
|
47
47
|
},
|
|
48
48
|
"stableVersion": "0.8.0",
|
|
49
49
|
"scripts": {
|
package/src/config.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Client } from "rivetkit";
|
|
2
2
|
import { RunConfigSchema } from "rivetkit/driver-helpers";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
export const ConfigSchema = RunConfigSchema.removeDefault()
|
|
6
6
|
.omit({ driver: true, getUpgradeWebSocket: true })
|
|
7
7
|
.extend({
|
|
8
|
-
|
|
8
|
+
/** Path that the Rivet manager API will be mounted. */
|
|
9
|
+
managerPath: z.string().optional().default("/rivet"),
|
|
10
|
+
|
|
11
|
+
fetch: z
|
|
12
|
+
.custom<ExportedHandlerFetchHandler<{ RIVET: Client<any> }, unknown>>()
|
|
13
|
+
.optional(),
|
|
9
14
|
})
|
|
10
15
|
.default({});
|
|
11
16
|
export type InputConfig = z.input<typeof ConfigSchema>;
|
package/src/handler.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { env } from "cloudflare:workers";
|
|
2
|
-
import { Hono } from "hono";
|
|
3
2
|
import type { Registry, RunConfig } from "rivetkit";
|
|
4
|
-
import type { Client } from "rivetkit/client";
|
|
5
3
|
import {
|
|
6
4
|
type ActorHandlerInterface,
|
|
7
5
|
createActorDurableObject,
|
|
@@ -31,23 +29,10 @@ interface Handler {
|
|
|
31
29
|
ActorHandler: DurableObjectConstructor;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
client: Client<A>;
|
|
36
|
-
createHandler: (hono?: Hono) => Handler;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function createServerHandler<R extends Registry<any>>(
|
|
32
|
+
export function createHandler<R extends Registry<any>>(
|
|
40
33
|
registry: R,
|
|
41
34
|
inputConfig?: InputConfig,
|
|
42
35
|
): Handler {
|
|
43
|
-
const { createHandler } = createServer(registry, inputConfig);
|
|
44
|
-
return createHandler();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function createServer<R extends Registry<any>>(
|
|
48
|
-
registry: R,
|
|
49
|
-
inputConfig?: InputConfig,
|
|
50
|
-
): SetupOutput<R> {
|
|
51
36
|
const config = ConfigSchema.parse(inputConfig);
|
|
52
37
|
|
|
53
38
|
// Create config
|
|
@@ -66,27 +51,34 @@ export function createServer<R extends Registry<any>>(
|
|
|
66
51
|
const ActorHandler = createActorDurableObject(registry, runConfig);
|
|
67
52
|
|
|
68
53
|
// Create server
|
|
69
|
-
const serverOutput = registry.
|
|
54
|
+
const serverOutput = registry.start(runConfig);
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const app = hono ?? new Hono();
|
|
56
|
+
// Create Cloudflare handler
|
|
57
|
+
const handler = {
|
|
58
|
+
fetch: (request, cfEnv, ctx) => {
|
|
59
|
+
const url = new URL(request.url);
|
|
76
60
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
app.route("/registry", serverOutput.hono);
|
|
80
|
-
}
|
|
61
|
+
// Inject Rivet env
|
|
62
|
+
const env = Object.assign({ RIVET: serverOutput.client }, cfEnv);
|
|
81
63
|
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
64
|
+
// Mount Rivet manager API
|
|
65
|
+
if (url.pathname.startsWith(config.managerPath)) {
|
|
66
|
+
const strippedPath = url.pathname.substring(config.managerPath.length);
|
|
67
|
+
url.pathname = strippedPath;
|
|
68
|
+
const modifiedRequest = new Request(url.toString(), request);
|
|
69
|
+
return serverOutput.fetch(modifiedRequest, env, ctx);
|
|
70
|
+
}
|
|
88
71
|
|
|
89
|
-
|
|
72
|
+
if (config.fetch) {
|
|
73
|
+
return config.fetch(request, env, ctx);
|
|
74
|
+
} else {
|
|
75
|
+
return new Response(
|
|
76
|
+
"This is a RivetKit server.\n\nLearn more at https://rivetkit.org\n",
|
|
77
|
+
{ status: 200 },
|
|
78
|
+
);
|
|
79
|
+
}
|
|
90
80
|
},
|
|
91
|
-
}
|
|
81
|
+
} satisfies ExportedHandler<Bindings>;
|
|
82
|
+
|
|
83
|
+
return { handler, ActorHandler };
|
|
92
84
|
}
|
package/src/mod.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type { Client } from "rivetkit";
|
|
1
2
|
export type { DriverContext } from "./actor-driver";
|
|
2
3
|
export type { InputConfig as Config } from "./config";
|
|
3
|
-
export { type Bindings,
|
|
4
|
+
export { type Bindings, createHandler } from "./handler";
|