diff --git a/genkit-tools/common/src/manager/manager.ts b/genkit-tools/common/src/manager/manager.ts index 094ea46bf5..6a2561c676 100644 --- a/genkit-tools/common/src/manager/manager.ts +++ b/genkit-tools/common/src/manager/manager.ts @@ -149,12 +149,17 @@ export class RuntimeManager { /** * Retrieves all runnable actions. */ - async listActions(): Promise> { - // TODO: Allow selecting a runtime by pid. - const runtime = this.getMostRecentRuntime(); + async listActions( + input?: apis.ListActionsRequest + ): Promise> { + 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 @@ -170,11 +175,14 @@ export class RuntimeManager { input: apis.RunActionRequest, streamingCallback?: StreamingCallback ): Promise { - // 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) { diff --git a/genkit-tools/common/src/server/router.ts b/genkit-tools/common/src/server/router.ts index 0a42bbad82..44bc58d306 100644 --- a/genkit-tools/common/src/server/router.ts +++ b/genkit-tools/common/src/server/router.ts @@ -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> => { - return manager.listActions(); - } - ), + listActions: loggedProcedure + .input(apis.ListActionsRequestSchema) + .query(async ({ input }): Promise> => { + return manager.listActions(input); + }), /** Runs an action. */ runAction: loggedProcedure diff --git a/genkit-tools/common/src/types/apis.ts b/genkit-tools/common/src/types/apis.ts index f0c99ec5fa..d2dd16dd79 100644 --- a/genkit-tools/common/src/types/apis.ts +++ b/genkit-tools/common/src/types/apis.ts @@ -61,7 +61,24 @@ export const GetTraceRequestSchema = z.object({ export type GetTraceRequest = z.infer; +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; + 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.'),