Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
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
32 changes: 30 additions & 2 deletions packages/rivetkit/src/actor/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -225,6 +232,27 @@ export class ActorInstance<S, CP, CS, V, I, DB extends AnyDatabaseProvider> {
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);
}
},
};
});

Expand Down
16 changes: 16 additions & 0 deletions packages/rivetkit/src/inspector/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
}

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

interface ActorInspectorEmitterEvents {
Expand Down
4 changes: 2 additions & 2 deletions packages/rivetkit/src/remote-manager-driver/api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import { apiCall } from "./api-utils";
// MARK: Get actor
export async function getActor(
config: ClientConfig,
name: string,
_: string,
actorId: RivetId,
): Promise<ActorsListResponse> {
return apiCall<never, ActorsListResponse>(
config,
"GET",
`/actors?name=${name}&actor_ids=${encodeURIComponent(actorId)}`,
`/actors?actor_ids=${encodeURIComponent(actorId)}`,
);
}

Expand Down
Loading