Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.1.1/schema.json",

Check notice on line 2 in biome.json

View workflow job for this annotation

GitHub Actions / quality

deserialize

The configuration schema version does not match the CLI version 2.3.5
"files": {
"includes": [
"**/*.js",
Expand Down Expand Up @@ -43,5 +43,56 @@
"noExplicitAny": "off"
}
}
}
},
"overrides": [
{
"includes": [
"rivetkit-typescript/packages/rivetkit/src/**/*",
"!rivetkit-typescript/packages/rivetkit/src/test/**/*"
],
"linter": {
"rules": {
"style": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"node:crypto": "Use '@/utils/node' getNodeCrypto() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:fs": "Use '@/utils/node' getNodeFsSync() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:fs/promises": "Use '@/utils/node' getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:path": "Use '@/utils/node' getNodePath() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:os": "Use '@/utils/node' getNodeOs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:child_process": "Use '@/utils/node' getNodeChildProcess() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:stream": "Use '@/utils/node' getNodeStream() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:net": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"node:url": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"crypto": "Use '@/utils/node' getNodeCrypto() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"fs": "Use '@/utils/node' getNodeFsSync() or getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"fs/promises": "Use '@/utils/node' getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"path": "Use '@/utils/node' getNodePath() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"os": "Use '@/utils/node' getNodeOs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"child_process": "Use '@/utils/node' getNodeChildProcess() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"stream": "Use '@/utils/node' getNodeStream() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"net": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
"url": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts"
}
}
}
}
}
}
},
{
"includes": [
"rivetkit-typescript/packages/rivetkit/src/utils/node.ts"
],
"linter": {
"rules": {
"style": {
"noRestrictedImports": "off"
}
}
}
}
]
}
2 changes: 1 addition & 1 deletion engine/artifacts/openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 5 additions & 22 deletions engine/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
{
"name": "@rivetkit/engine",
"private": true,
"version": "1.0.0",
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.13.1",
"scripts": {
"start": "npx turbo watch build",
"build": "npx turbo build",
"test": "npx turbo test",
"test:watch": "npx turbo watch test",
"check-types": "npx turbo check-types",
"fmt": "pnpm biome check --write --diagnostic-level=error ."
},
"devDependencies": {
"@bare-ts/tools": "0.15.0",
"@biomejs/biome": "^2.2.3",
"lefthook": "^1.12.4",
"tsup": "^8.5.0",
"turbo": "^2.5.6",
"typescript": "^5.9.2"
},
"dependencies": {
"@sentry/vite-plugin": "^2.23.1"
},
"resolutions": {
"rivetkit": "workspace:*",
"@clerk/shared": "3.27.1"
"@vbare/compiler": "^0.0.3"
}
}
8 changes: 7 additions & 1 deletion engine/sdks/typescript/runner-protocol/src/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
packages:
- engine
- engine/docker/template
- engine/sdks/typescript/api-full
- engine/sdks/typescript/runner
Expand Down
5 changes: 5 additions & 0 deletions rivetkit-typescript/packages/rivetkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts",
"build:schema": "./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v2.bare -o dist/schemas/client-protocol/v2.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v2.bare -o dist/schemas/file-system-driver/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v3.bare -o dist/schemas/actor-persist/v3.ts",
"check-types": "tsc --noEmit",
"lint": "biome check .",
"lint:fix": "biome check --write .",
"format": "biome format .",
"format:write": "biome format --write .",
"test": "vitest run",
"test:watch": "vitest",
"dump-openapi": "tsx scripts/dump-openapi.ts",
Expand All @@ -178,6 +182,7 @@
},
"devDependencies": {
"@bare-ts/tools": "^0.13.0",
"@biomejs/biome": "^2.2.3",
"@hono/node-server": "^1.18.2",
"@hono/node-ws": "^1.1.1",
"@types/invariant": "^2",
Expand Down
146 changes: 5 additions & 141 deletions rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "node:fs/promises";
import { resolve } from "node:path";
import { zodToJsonSchema } from "zod-to-json-schema";
import { ClientConfigSchema } from "@/client/config";
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
import type { ManagerDriver } from "@/manager/driver";
Expand All @@ -12,20 +11,16 @@ import {
setup,
} from "@/mod";
import { type RunnerConfig, RunnerConfigSchema } from "@/registry/run-config";
import {
HttpActionRequestSchema,
HttpActionResponseSchema,
} from "@/schemas/client-protocol-zod/mod";
import { VERSION } from "@/utils";

function main() {
async function main() {
const registryConfig: RegistryConfig = RegistryConfigSchema.parse({
use: {},
});
const registry = setup(registryConfig);

const driverConfig: RunnerConfig = RunnerConfigSchema.parse({
driver: createFileSystemOrMemoryDriver(false),
driver: await createFileSystemOrMemoryDriver(false),
getUpgradeWebSocket: () => () => unimplemented(),
inspector: {
enabled: false,
Expand All @@ -37,7 +32,6 @@ function main() {
getWithKey: unimplemented,
getOrCreateWithKey: unimplemented,
createActor: unimplemented,
listActors: unimplemented,
sendRequest: unimplemented,
openWebSocket: unimplemented,
proxyRequest: unimplemented,
Expand All @@ -51,26 +45,22 @@ function main() {
ClientConfigSchema.parse({}),
);

const { openapi: managerOpenapi } = createManagerRouter(
const { openapi } = createManagerRouter(
registryConfig,
driverConfig,
managerDriver,
driverConfig.driver!,
client,
);

// Get OpenAPI document
const managerOpenApiDoc = managerOpenapi.getOpenAPIDocument({
const openApiDoc = openapi.getOpenAPIDocument({
openapi: "3.0.0",
info: {
version: VERSION,
title: "RivetKit API",
},
});

// Inject actor router paths
injectActorRouter(managerOpenApiDoc);

const outputPath = resolve(
import.meta.dirname,
"..",
Expand All @@ -80,136 +70,10 @@ function main() {
"rivetkit-openapi",
"openapi.json",
);
fs.writeFile(outputPath, JSON.stringify(managerOpenApiDoc, null, 2));
await fs.writeFile(outputPath, JSON.stringify(openApiDoc, null, 2));
console.log("Dumped OpenAPI to", outputPath);
}

/**
* Manually inject actor router paths into the OpenAPI spec.
*
* We do this manually instead of extracting from the actual router since the
* actor routes support multiple encodings (JSON, CBOR, bare), but OpenAPI
* specs are JSON-focused and don't cleanly represent multi-encoding routes.
*/
function injectActorRouter(openApiDoc: any) {
if (!openApiDoc.paths) {
openApiDoc.paths = {};
}

// Convert Zod schemas to JSON Schema and remove $schema property
const actionRequestSchema = zodToJsonSchema(HttpActionRequestSchema, {
$refStrategy: "none",
});
delete (actionRequestSchema as any).$schema;

const actionResponseSchema = zodToJsonSchema(HttpActionResponseSchema, {
$refStrategy: "none",
});
delete (actionResponseSchema as any).$schema;

// Common actorId parameter
const actorIdParam = {
name: "actorId",
in: "path" as const,
required: true,
schema: {
type: "string",
},
description: "The ID of the actor to target",
};

// GET /gateway/{actorId}/health
openApiDoc.paths["/gateway/{actorId}/health"] = {
get: {
parameters: [actorIdParam],
responses: {
200: {
description: "Health check",
content: {
"text/plain": {
schema: {
type: "string",
},
},
},
},
},
},
};

// POST /gateway/{actorId}/action/{action}
openApiDoc.paths["/gateway/{actorId}/action/{action}"] = {
post: {
parameters: [
actorIdParam,
{
name: "action",
in: "path" as const,
required: true,
schema: {
type: "string",
},
description: "The name of the action to execute",
},
],
requestBody: {
content: {
"application/json": {
schema: actionRequestSchema,
},
},
},
responses: {
200: {
description: "Action executed successfully",
content: {
"application/json": {
schema: actionResponseSchema,
},
},
},
400: {
description: "Invalid action",
},
500: {
description: "Internal error",
},
},
},
};

// ALL /gateway/{actorId}/request/{path}
const requestPath = {
parameters: [
actorIdParam,
{
name: "path",
in: "path" as const,
required: true,
schema: {
type: "string",
},
description: "The HTTP path to forward to the actor",
},
],
responses: {
200: {
description: "Response from actor's raw HTTP handler",
},
},
};

openApiDoc.paths["/gateway/{actorId}/request/{path}"] = {
get: requestPath,
post: requestPath,
put: requestPath,
delete: requestPath,
patch: requestPath,
head: requestPath,
options: requestPath,
};
}

function unimplemented(): never {
throw new Error("UNIMPLEMENTED");
}
Expand Down
6 changes: 4 additions & 2 deletions rivetkit-typescript/packages/rivetkit/src/drivers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import type { DriverConfig, RunnerConfig } from "@/registry/run-config";
/**
* Chooses the appropriate driver based on the run configuration.
*/
export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
export async function chooseDefaultDriver(
runConfig: RunnerConfig,
): Promise<DriverConfig> {
if (runConfig.endpoint && runConfig.driver) {
throw new UserError(
"Cannot specify both 'endpoint' and 'driver' in configuration",
Expand All @@ -31,5 +33,5 @@ export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
}

loggerWithoutContext().debug({ msg: "using default file system driver" });
return createFileSystemOrMemoryDriver(true);
return await createFileSystemOrMemoryDriver(true);
}
Loading
Loading