Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 8585e6a

Browse files
committed
chore(core): add token support
1 parent 35b80aa commit 8585e6a

File tree

18 files changed

+108
-63
lines changed

18 files changed

+108
-63
lines changed

examples/next-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"@types/react": "^19",
2222
"@types/react-dom": "^19"
2323
}
24-
}
24+
}

packages/next-js/src/mod.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ export const toNextHandler = (
1010

1111
const { fetch } = registry.startServerless(inputConfig);
1212

13-
const fetchWrapper = async (request: Request, { params }: { params: Promise<{ all: string[] }> }) => {
13+
const fetchWrapper = async (
14+
request: Request,
15+
{ params }: { params: Promise<{ all: string[] }> },
16+
) => {
1417
const { all } = await params;
1518

1619
const newUrl = new URL(request.url);
17-
newUrl.pathname = all.join('/');
20+
newUrl.pathname = all.join("/");
1821
const newReq = new Request(newUrl, request);
1922

2023
return await fetch(newReq);

packages/rivetkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"@bare-ts/lib": "~0.3.0",
164164
"@hono/standard-validator": "^0.1.3",
165165
"@hono/zod-openapi": "^0.19.10",
166-
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@a0639d0",
166+
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-dev/engine/@rivetkit/engine-runner@0cfcf3d",
167167
"@rivetkit/fast-json-patch": "^3.1.2",
168168
"cbor-x": "^1.6.0",
169169
"hono": "^4.7.0",

packages/rivetkit/src/actor/driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Hono, MiddlewareHandler } from "hono";
12
import type { CachedSerializer } from "@/actor/protocol/serde";
23
import type { AnyClient } from "@/client/client";
34
import type { ManagerDriver } from "@/manager/driver";
@@ -7,7 +8,6 @@ import type * as protocol from "@/schemas/client-protocol/mod";
78
import type { AnyConn, ConnectionDriver } from "./connection";
89
import type { GenericConnGlobalState } from "./generic-conn-driver";
910
import type { AnyActorInstance } from "./instance";
10-
import { Hono, MiddlewareHandler } from "hono";
1111

1212
export type ConnectionDriversMap = Record<ConnectionDriver, ConnDriver>;
1313

packages/rivetkit/src/client/actor-conn.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,9 @@ enc
396396
logger().trace(
397397
getEnvUniversal("_RIVETKIT_LOG_MESSAGE")
398398
? {
399-
msg: "parsed message",
400-
message: jsonStringifyCompat(response).substring(0, 100) + "...",
401-
}
399+
msg: "parsed message",
400+
message: jsonStringifyCompat(response).substring(0, 100) + "...",
401+
}
402402
: { msg: "parsed message" },
403403
);
404404

@@ -722,9 +722,9 @@ enc
722722
logger().trace(
723723
getEnvUniversal("_RIVETKIT_LOG_MESSAGE")
724724
? {
725-
msg: "sent http message",
726-
message: `${jsonStringifyCompat(message).substring(0, 100)}...`,
727-
}
725+
msg: "sent http message",
726+
message: `${jsonStringifyCompat(message).substring(0, 100)}...`,
727+
}
728728
: { msg: "sent http message" },
729729
);
730730

packages/rivetkit/src/client/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const ClientConfigSchema = z.object({
1616

1717
token: z
1818
.string()
19-
.nullable()
20-
.default(() => getEnvUniversal("RIVET_TOKEN") ?? null),
19+
.optional()
20+
.transform((x) => x ?? getEnvUniversal("RIVET_TOKEN")),
2121

2222
headers: z.record(z.string()).optional().default({}),
2323

packages/rivetkit/src/common/versioned-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface VersionedDataConfig<T> {
1313
}
1414

1515
export class VersionedDataHandler<T> {
16-
constructor(private config: VersionedDataConfig<T>) { }
16+
constructor(private config: VersionedDataConfig<T>) {}
1717

1818
serializeWithEmbeddedVersion(data: T): Uint8Array {
1919
const versioned: VersionedData<Uint8Array> = {

packages/rivetkit/src/driver-test-suite/mod.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { runRequestAccessTests } from "./tests/request-access";
3333
export interface SkipTests {
3434
schedule?: boolean;
3535
sleep?: boolean;
36+
sse?: boolean;
3637
}
3738

3839
export interface DriverTestConfig {
@@ -87,7 +88,10 @@ export function runDriverTests(
8788
runActorDriverTests(driverTestConfig);
8889
runManagerDriverTests(driverTestConfig);
8990

90-
for (const transport of ["websocket", "sse"] as Transport[]) {
91+
const transports: Transport[] = driverTestConfig.skip?.sse
92+
? ["websocket"]
93+
: ["websocket", "sse"];
94+
for (const transport of transports) {
9195
describe(`transport (${transport})`, () => {
9296
runActorConnTests({
9397
...driverTestConfig,

packages/rivetkit/src/drivers/default.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ import { loggerWithoutContext } from "@/actor/log";
33
import { createEngineDriver } from "@/drivers/engine/mod";
44
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
55
import type { DriverConfig, RunConfig } from "@/registry/run-config";
6-
import { getEnvUniversal } from "@/utils";
76

87
/**
98
* Chooses the appropriate driver based on the run configuration.
109
*/
1110
export function chooseDefaultDriver(runConfig: RunConfig): DriverConfig {
12-
const engineEndpoint = runConfig.endpoint ?? getEnvUniversal("RIVET_ENGINE");
13-
14-
if (engineEndpoint && runConfig.driver) {
11+
if (runConfig.endpoint && runConfig.driver) {
1512
throw new UserError(
1613
"Cannot specify both 'engine' and 'driver' in configuration",
1714
);
@@ -21,12 +18,16 @@ export function chooseDefaultDriver(runConfig: RunConfig): DriverConfig {
2118
return runConfig.driver;
2219
}
2320

24-
if (engineEndpoint) {
21+
if (runConfig.endpoint) {
2522
loggerWithoutContext().debug({
2623
msg: "using rivet engine driver",
27-
endpoint: engineEndpoint,
24+
endpoint: runConfig.endpoint,
25+
});
26+
// TODO: Add all properties from config
27+
return createEngineDriver({
28+
endpoint: runConfig.endpoint,
29+
token: runConfig.token,
2830
});
29-
return createEngineDriver({ endpoint: engineEndpoint });
3031
}
3132

3233
loggerWithoutContext().debug({ msg: "using default file system driver" });

packages/rivetkit/src/drivers/engine/actor-driver.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import type {
44
} from "@rivetkit/engine-runner";
55
import { Runner } from "@rivetkit/engine-runner";
66
import * as cbor from "cbor-x";
7+
import { Hono, MiddlewareHandler } from "hono";
8+
import { streamSSE } from "hono/streaming";
79
import { WSContext } from "hono/ws";
810
import invariant from "invariant";
911
import { lookupInRegistry } from "@/actor/definition";
@@ -41,8 +43,6 @@ import { promiseWithResolvers } from "@/utils";
4143
import type { Config } from "./config";
4244
import { KEYS } from "./kv";
4345
import { logger } from "./log";
44-
import { Hono, MiddlewareHandler } from "hono";
45-
import { streamSSE } from "hono/streaming";
4646

4747
interface ActorHandler {
4848
actor?: AnyActorInstance;
@@ -86,12 +86,12 @@ export class EngineActorDriver implements ActorDriver {
8686
const runnerConfig: RunnerConfig = {
8787
version: this.#version,
8888
endpoint: config.endpoint,
89+
token: config.token,
8990
pegboardEndpoint: config.pegboardEndpoint,
9091
namespace: config.namespace,
9192
totalSlots: config.totalSlots,
9293
runnerName: config.runnerName,
9394
runnerKey: config.runnerKey,
94-
token: config.token,
9595
metadata: {
9696
inspectorToken: this.#runConfig.inspector.token(),
9797
},
@@ -304,15 +304,13 @@ export class EngineActorDriver implements ActorDriver {
304304

305305
const url = new URL(request.url);
306306

307+
// Parse configuration from Sec-WebSocket-Protocol header
307308
const protocols = request.headers.get("sec-websocket-protocol");
308309
if (protocols === null)
309310
throw new Error(`Missing sec-websocket-protocol header`);
310311

311-
// Parse configuration from Sec-WebSocket-Protocol header
312-
const protocols = request.headers.get("sec-websocket-protocol");
313312
let encodingRaw: string | undefined;
314313
let connParamsRaw: string | undefined;
315-
let token: string | undefined;
316314

317315
if (protocols) {
318316
const protocolList = protocols.split(",").map((p) => p.trim());
@@ -323,8 +321,6 @@ export class EngineActorDriver implements ActorDriver {
323321
connParamsRaw = decodeURIComponent(
324322
protocol.substring(WS_PROTOCOL_CONN_PARAMS.length),
325323
);
326-
} else if (protocol.startsWith(WS_PROTOCOL_TOKEN)) {
327-
token = protocol.substring(WS_PROTOCOL_TOKEN.length);
328324
}
329325
}
330326
}

0 commit comments

Comments
 (0)