Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

*.png binary
*.jpg binary
*.tgz binary

177 changes: 0 additions & 177 deletions NEW_SPEC.md

This file was deleted.

8 changes: 0 additions & 8 deletions NEW_SPEC2.md

This file was deleted.

11 changes: 6 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,21 @@
},
"dependencies": {
"@hono/standard-validator": "^0.1.3",
"cbor-x": "^1.6.0",
"@hono/zod-openapi": "^0.19.10",
"@rivetkit/fast-json-patch": "^3.1.2",
"cbor-x": "^1.6.0",
"hono": "^4.7.0",
"invariant": "^2.2.4",
"nanoevents": "^9.1.0",
"on-change": "^5.0.1",
"p-retry": "^6.2.1",
"zod": "^3.25.76",
"@hono/zod-openapi": "^0.19.10",
"hono": "^4.7.0"
"zod": "^3.25.76"
},
"devDependencies": {
"@hono/node-server": "^1.14.0",
"@hono/node-server": "^1.18.2",
"@hono/node-ws": "^1.1.1",
"@rivet-gg/actor-core": "^25.1.0",
"@rivetkit/engine-runner": "https://pkg.pr.new/rivet-gg/engine/@rivetkit/engine-runner@472",
"@types/invariant": "^2",
"@types/node": "^22.13.1",
"@types/ws": "^8",
Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/actor/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ export interface ActorDriver {
*/
getDatabase(actorId: string): Promise<unknown | undefined>;

// TODO:
//destroy(): Promise<void>;
//readState(): void;
shutdown?(immediate: boolean): Promise<void>;
}

export enum ConnectionReadyState {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/actor/router-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ export interface WebSocketOpts {
* Creates a WebSocket connection handler
*/
export async function handleWebSocketConnect(
c: HonoContext | undefined,
req: Request | undefined,
runConfig: RunConfig,
actorDriver: ActorDriver,
actorId: string,
encoding: Encoding,
parameters: unknown,
authData: unknown,
): Promise<UpgradeWebSocketArgs> {
const exposeInternalError = c ? getRequestExposeInternalError(c.req) : false;
const exposeInternalError = req ? getRequestExposeInternalError(req) : false;

// Setup promise for the init handlers since all other behavior depends on this
const {
Expand Down Expand Up @@ -157,7 +157,7 @@ export async function handleWebSocketConnect(
try {
const connId = generateConnId();
const connToken = generateConnToken();
const connState = await actor.prepareConn(parameters, c?.req.raw);
const connState = await actor.prepareConn(parameters, req);

// Save socket
const connGlobalState =
Expand Down Expand Up @@ -578,7 +578,7 @@ export async function handleConnectionMessage(
}

export async function handleRawWebSocketHandler(
c: HonoContext | undefined,
req: Request | undefined,
path: string,
actorDriver: ActorDriver,
actorId: string,
Expand All @@ -602,8 +602,8 @@ export async function handleRawWebSocketHandler(
const normalizedPath = pathname + url.search;

let newRequest: Request;
if (c) {
newRequest = new Request(`http://actor${normalizedPath}`, c.req.raw);
if (req) {
newRequest = new Request(`http://actor${normalizedPath}`, req);
} else {
newRequest = new Request(`http://actor${normalizedPath}`, {
method: "GET",
Expand Down Expand Up @@ -660,8 +660,8 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
return result.data;
}

export function getRequestExposeInternalError(req: HonoRequest): boolean {
const param = req.header(HEADER_EXPOSE_INTERNAL_ERROR);
export function getRequestExposeInternalError(req: Request): boolean {
const param = req.headers.get(HEADER_EXPOSE_INTERNAL_ERROR);
if (!param) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/actor/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function createActorRouter(
const authData = authDataRaw ? JSON.parse(authDataRaw) : undefined;

return await handleWebSocketConnect(
c as HonoContext,
c.req.raw,
runConfig,
actorDriver,
c.env.actorId,
Expand Down Expand Up @@ -220,7 +220,7 @@ export function createActorRouter(
});

return await handleRawWebSocketHandler(
c,
c.req.raw,
pathWithQuery,
actorDriver,
c.env.actorId,
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/client/actor-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,25 @@ export class ActorHandleRaw {
"getOrCreateForKey" in this.#actorQuery
) {
// TODO:
let name: string;
if ("getForKey" in this.#actorQuery) {
name = this.#actorQuery.getForKey.name;
} else if ("getOrCreateForKey" in this.#actorQuery) {
name = this.#actorQuery.getOrCreateForKey.name;
} else {
assertUnreachable(this.#actorQuery);
}

const actorId = await this.#driver.resolveActorId(
undefined,
this.#actorQuery,
this.#encodingKind,
this.#params,
signal ? { signal } : undefined,
);
this.#actorQuery = { getForId: { actorId } };

this.#actorQuery = { getForId: { actorId, name } };

return actorId;
} else if ("getForId" in this.#actorQuery) {
// SKip since it's already resolved
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,9 @@ export class ClientRaw {
params: opts?.params,
});

const actorQuery = {
const actorQuery: ActorQuery = {
getForId: {
name,
actorId,
},
};
Expand Down Expand Up @@ -400,6 +401,7 @@ export class ClientRaw {
// Create handle with actor ID
const getForIdQuery = {
getForId: {
name,
actorId,
},
} satisfies ActorQuery;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function handleRouteError(
c: HonoContext,
) {
const exposeInternalError =
opts.enableExposeInternalError && getRequestExposeInternalError(c.req);
opts.enableExposeInternalError && getRequestExposeInternalError(c.req.raw);

const { statusCode, code, message, metadata } = deconstructError(
error,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/driver-test-suite/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function createTestRuntime(
});

// Create router
const managerDriver = config.driver.manager(registry.config, config);
const managerDriver = driver.manager(registry.config, config);
const inlineDriver = createInlineClientDriver(managerDriver);
const { router } = createManagerRouter(
registry.config,
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/driver-test-suite/tests/actor-conn-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
const conn1 = handle.connect();
const conn2 = handle.connect();

// HACK: Wait for both connections to successfully connect by waiting for a round trip RPC
await conn1.getConnectionState();
await conn2.getConnectionState();

// Get state1 for reference
const state1 = await conn1.getConnectionState();

Expand All @@ -119,6 +123,10 @@ export function runActorConnStateTests(driverTestConfig: DriverTestConfig) {
const conn1 = handle.connect();
const conn2 = handle.connect();

// HACK: Wait for both connections to successfully connect by waiting for a round trip RPC
await conn1.getConnectionState();
await conn2.getConnectionState();

// Get all connection states
const allStates = await conn1.getAllConnectionStates();

Expand Down
Loading
Loading