Skip to content

feat:(genkit-tools) support passing runtimeId to tools apis #3252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
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
22 changes: 15 additions & 7 deletions genkit-tools/common/src/manager/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ export class RuntimeManager {
/**
* Retrieves all runnable actions.
*/
async listActions(): Promise<Record<string, Action>> {
// TODO: Allow selecting a runtime by pid.
const runtime = this.getMostRecentRuntime();
async listActions(
input?: apis.ListActionsRequest
): Promise<Record<string, Action>> {
const runtime = input?.runtimeId
? this.getRuntimeById(input.runtimeId)
: this.getMostRecentRuntime();
if (!runtime) {
throw new Error(
'No runtimes found. Make sure your app is running using `genkit start -- ...`. See getting started documentation.'
input?.runtimeId
? `No runtime found with ID ${input.runtimeId}.`
: 'No runtimes found. Make sure your app is running using `genkit start -- ...`. See getting started documentation.'
);
}
const response = await axios
Expand All @@ -170,11 +175,14 @@ export class RuntimeManager {
input: apis.RunActionRequest,
streamingCallback?: StreamingCallback<any>
): Promise<RunActionResponse> {
// TODO: Allow selecting a runtime by pid.
const runtime = this.getMostRecentRuntime();
const runtime = input.runtimeId
? this.getRuntimeById(input.runtimeId)
: this.getMostRecentRuntime();
if (!runtime) {
throw new Error(
'No runtimes found. Make sure your app is running using `genkit start -- ...`. See getting started documentation.'
input.runtimeId
? `No runtime found with ID ${input.runtimeId}.`
: 'No runtimes found. Make sure your app is running using `genkit start -- ...`. See getting started documentation.'
);
}
if (streamingCallback) {
Expand Down
10 changes: 5 additions & 5 deletions genkit-tools/common/src/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ const loggedProcedure = t.procedure.use(async (opts) => {
export const TOOLS_SERVER_ROUTER = (manager: RuntimeManager) =>
t.router({
/** Retrieves all runnable actions. */
listActions: loggedProcedure.query(
async (): Promise<Record<string, Action>> => {
return manager.listActions();
}
),
listActions: loggedProcedure
.input(apis.ListActionsRequestSchema)
.query(async ({ input }): Promise<Record<string, Action>> => {
return manager.listActions(input);
}),

/** Runs an action. */
runAction: loggedProcedure
Expand Down
17 changes: 17 additions & 0 deletions genkit-tools/common/src/types/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,24 @@ export const GetTraceRequestSchema = z.object({

export type GetTraceRequest = z.infer<typeof GetTraceRequestSchema>;

export const ListActionsRequestSchema = z.object({
runtimeId: z
.string()
.optional()
.describe(
'ID of the Genkit runtime to run the action on. Typically $pid-$port.'
),
});

export type ListActionsRequest = z.infer<typeof ListActionsRequestSchema>;

export const RunActionRequestSchema = z.object({
runtimeId: z
.string()
.optional()
.describe(
'ID of the Genkit runtime to run the action on. Typically $pid-$port.'
),
key: z
.string()
.describe('Action key that consists of the action type and ID.'),
Expand Down
Loading