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

Commit 433d74c

Browse files
authored
fix: get actor in remote driver (#1415)
* fix: get actor in remote driver * feat: execute actor actions through inspector (#1416)
1 parent 439cc09 commit 433d74c

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

packages/rivetkit/src/actor/instance.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ import {
2020
promiseWithResolvers,
2121
SinglePromiseQueue,
2222
} from "@/utils";
23-
import type { ActionContext } from "./action";
23+
import { ActionContext } from "./action";
2424
import type { ActorConfig, OnConnectOptions } from "./config";
25-
import { Conn, type ConnId, generateConnId, generateConnToken } from "./conn";
25+
import {
26+
Conn,
27+
type ConnId,
28+
generateConnId,
29+
generateConnSocketId,
30+
generateConnToken,
31+
} from "./conn";
2632
import {
2733
CONN_DRIVERS,
2834
type ConnDriver,
35+
ConnDriverKind,
2936
type ConnDriverState,
3037
getConnDriverKindFromState,
3138
} from "./conn-drivers";
@@ -225,6 +232,27 @@ export class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
225232
this.#persist.state = { ...(state as S) };
226233
await this.saveState({ immediate: true });
227234
},
235+
executeAction: async (name, params) => {
236+
const socketId = generateConnSocketId();
237+
const conn = await this.createConn(
238+
{
239+
socketId,
240+
driverState: { [ConnDriverKind.HTTP]: {} },
241+
},
242+
undefined,
243+
undefined,
244+
);
245+
246+
try {
247+
return await this.executeAction(
248+
new ActionContext(this.actorContext, conn),
249+
name,
250+
params || [],
251+
);
252+
} finally {
253+
this.__connDisconnected(conn, true, socketId);
254+
}
255+
},
228256
};
229257
});
230258

packages/rivetkit/src/inspector/actor.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ export function createActorInspectorRouter() {
250250
return c.json({ error: (error as Error).message }, 500);
251251
}
252252
},
253+
)
254+
.post(
255+
"/action",
256+
sValidator(
257+
"json",
258+
z.object({ name: z.string(), params: z.array(z.any()).optional() }),
259+
),
260+
async (c) => {
261+
const { name, params } = c.req.valid("json");
262+
const result = await c.var.inspector.accessors.executeAction(
263+
name,
264+
params,
265+
);
266+
return c.json({ result }, 200);
267+
},
253268
);
254269
}
255270

@@ -261,6 +276,7 @@ interface ActorInspectorAccessors {
261276
getDb: () => Promise<InferDatabaseClient<AnyDatabaseProvider>>;
262277
getRpcs: () => Promise<string[]>;
263278
getConnections: () => Promise<Connection[]>;
279+
executeAction: (name: string, params?: unknown[]) => Promise<unknown>;
264280
}
265281

266282
interface ActorInspectorEmitterEvents {

packages/rivetkit/src/remote-manager-driver/api-endpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { apiCall } from "./api-utils";
1515
// MARK: Get actor
1616
export async function getActor(
1717
config: ClientConfig,
18-
name: string,
18+
_: string,
1919
actorId: RivetId,
2020
): Promise<ActorsListResponse> {
2121
return apiCall<never, ActorsListResponse>(

0 commit comments

Comments
 (0)