Skip to content
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
13 changes: 8 additions & 5 deletions src/channels/control-plane-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
* @internal
*/

/** Matches the signed run operation routes (`execute`, `stream`, `resume`) of a control-plane run. */
/**
* Matches the signed run operation routes (`execute`, `stream`, `resume`) of a
* control-plane run. Group 1 is the run id.
*/
export const CONTROL_PLANE_RUN_OPERATION_PATH =
/^\/api\/control-plane\/runs\/[^/]+\/(?:execute|stream|resume)$/u;
/^\/api\/control-plane\/runs\/([^/]+)\/(?:execute|stream|resume)$/u;

/** Matches the bare run route, which only DELETE addresses. */
export const CONTROL_PLANE_RUN_PATH = /^\/api\/control-plane\/runs\/[^/]+$/u;
/** Matches the bare run route, which only DELETE addresses. Group 1 is the run id. */
export const CONTROL_PLANE_RUN_PATH = /^\/api\/control-plane\/runs\/([^/]+)$/u;

/**
* The run id a control-plane run route addresses, or `undefined` when the
Expand All @@ -27,5 +30,5 @@ export function controlPlaneRunIdFromPath(method: string, pathname: string): str
: normalizedMethod === "DELETE"
? CONTROL_PLANE_RUN_PATH
: undefined;
return route?.test(pathname) ? pathname.split("/")[4] : undefined;
return route?.exec(pathname)?.[1];
}
43 changes: 26 additions & 17 deletions src/server/handlers/request/project-run-execute.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,31 @@ const defaultDeps: ProjectRunExecuteHandlerDeps = {
now: () => Date.now(),
};

/** Runs the task, eval or workflow a control-plane execute request names. */
function executeProjectRun(
request: ProjectRunExecuteRequest,
ctx: HandlerContext,
req: Request,
deps: ProjectRunExecuteHandlerDeps,
): Promise<ProjectRunExecuteResponse> {
if (request.kind === "task") {
switch (request.target) {
case "task:knowledge-ingest":
return deps.executeKnowledgeIngest({ request, ctx, req });
case "task:release-asset-build":
return deps.executeReleaseAssetBuild({ request, ctx, req });
case "task:dependency-artifact-build":
return deps.executeDependencyArtifactBuild({ request, ctx, req });
case "task:style-artifact-build":
return deps.executeStyleArtifactBuild({ request, ctx, req });
default:
return executeTaskRun(request, ctx, deps);
}
}
if (request.kind === "eval") return executeEvalRun(request, ctx, req, deps);
return executeWorkflowRun(request, ctx, deps);
}

export class ProjectRunExecuteHandler extends BaseHandler {
metadata: HandlerMetadata = {
name: "ProjectRunExecuteHandler",
Expand Down Expand Up @@ -2052,19 +2077,7 @@ export class ProjectRunExecuteHandler extends BaseHandler {
async () => {
const startedAt = this.deps.now();
try {
const response = request.kind === "task" && request.target === "task:knowledge-ingest"
? await this.deps.executeKnowledgeIngest({ request, ctx, req })
: request.kind === "task" && request.target === "task:release-asset-build"
? await this.deps.executeReleaseAssetBuild({ request, ctx, req })
: request.kind === "task" && request.target === "task:dependency-artifact-build"
? await this.deps.executeDependencyArtifactBuild({ request, ctx, req })
: request.kind === "task" && request.target === "task:style-artifact-build"
? await this.deps.executeStyleArtifactBuild({ request, ctx, req })
: request.kind === "task"
? await executeTaskRun(request, ctx, this.deps)
: request.kind === "eval"
? await executeEvalRun(request, ctx, req, this.deps)
: await executeWorkflowRun(request, ctx, this.deps);
const response = await executeProjectRun(request, ctx, req, this.deps);
if (!response.success) setActiveSpanErrorStatus(new Error("Project run failed"));
return this.respond(builder.json(response, 200));
} catch (error) {
Expand Down Expand Up @@ -2095,10 +2108,6 @@ export class ProjectRunExecuteHandler extends BaseHandler {
return this.respond(builder.json({ error: error.message }, error.status));
}

if (error instanceof SyntaxError || error instanceof Error) {
return this.respond(builder.json({ error: "Invalid project run execute request" }, 400));
}

return this.respond(builder.json({ error: "Invalid project run execute request" }, 400));
}
});
Expand Down
Loading