diff --git a/packages/rivetkit/src/actor/instance.ts b/packages/rivetkit/src/actor/instance.ts index 41c46dd51..043c4f7fb 100644 --- a/packages/rivetkit/src/actor/instance.ts +++ b/packages/rivetkit/src/actor/instance.ts @@ -20,12 +20,19 @@ import { promiseWithResolvers, SinglePromiseQueue, } from "@/utils"; -import type { ActionContext } from "./action"; +import { ActionContext } from "./action"; import type { ActorConfig, OnConnectOptions } from "./config"; -import { Conn, type ConnId, generateConnId, generateConnToken } from "./conn"; +import { + Conn, + type ConnId, + generateConnId, + generateConnSocketId, + generateConnToken, +} from "./conn"; import { CONN_DRIVERS, type ConnDriver, + ConnDriverKind, type ConnDriverState, getConnDriverKindFromState, } from "./conn-drivers"; @@ -225,6 +232,27 @@ export class ActorInstance { this.#persist.state = { ...(state as S) }; await this.saveState({ immediate: true }); }, + executeAction: async (name, params) => { + const socketId = generateConnSocketId(); + const conn = await this.createConn( + { + socketId, + driverState: { [ConnDriverKind.HTTP]: {} }, + }, + undefined, + undefined, + ); + + try { + return await this.executeAction( + new ActionContext(this.actorContext, conn), + name, + params || [], + ); + } finally { + this.__connDisconnected(conn, true, socketId); + } + }, }; }); diff --git a/packages/rivetkit/src/inspector/actor.ts b/packages/rivetkit/src/inspector/actor.ts index 402c472f8..7acdeb976 100644 --- a/packages/rivetkit/src/inspector/actor.ts +++ b/packages/rivetkit/src/inspector/actor.ts @@ -250,6 +250,21 @@ export function createActorInspectorRouter() { return c.json({ error: (error as Error).message }, 500); } }, + ) + .post( + "/action", + sValidator( + "json", + z.object({ name: z.string(), params: z.array(z.any()).optional() }), + ), + async (c) => { + const { name, params } = c.req.valid("json"); + const result = await c.var.inspector.accessors.executeAction( + name, + params, + ); + return c.json({ result }, 200); + }, ); } @@ -261,6 +276,7 @@ interface ActorInspectorAccessors { getDb: () => Promise>; getRpcs: () => Promise; getConnections: () => Promise; + executeAction: (name: string, params?: unknown[]) => Promise; } interface ActorInspectorEmitterEvents { diff --git a/packages/rivetkit/src/remote-manager-driver/api-endpoints.ts b/packages/rivetkit/src/remote-manager-driver/api-endpoints.ts index db99c9c4f..e23334c3c 100644 --- a/packages/rivetkit/src/remote-manager-driver/api-endpoints.ts +++ b/packages/rivetkit/src/remote-manager-driver/api-endpoints.ts @@ -15,13 +15,13 @@ import { apiCall } from "./api-utils"; // MARK: Get actor export async function getActor( config: ClientConfig, - name: string, + _: string, actorId: RivetId, ): Promise { return apiCall( config, "GET", - `/actors?name=${name}&actor_ids=${encodeURIComponent(actorId)}`, + `/actors?actor_ids=${encodeURIComponent(actorId)}`, ); }