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
196 changes: 193 additions & 3 deletions packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2310,8 +2310,10 @@ export interface paths {
get: operations["get_api_v1_runs"];
put?: never;
/**
* Start a project VM run with a literal prompt and optional launch skill
* @description Requires the runs:start scope.
* Start a project VM run with a prompt or script and per-run execution overrides
* @description Supply exactly one of prompt or script. Omitted execution settings use project defaults, then user defaults. Omitted integrationIds inherit this MCP client's effective integration access; explicit IDs select a subset, including an empty set. runScopes is limited to the caller's effective permissions.
*
* Requires the runs:start scope.
*
* Accepts a scoped bearer token, vendor-verified run identity, or interactive owner session.
*/
Expand Down Expand Up @@ -2344,6 +2346,34 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v1/user/run-defaults": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Get user defaults for direct VM runs
* @description Requires the projects:read scope.
*
* Accepts a scoped bearer token, vendor-verified run identity, or interactive owner session.
*/
get: operations["get_api_v1_user_run_defaults"];
/**
* Set user defaults for direct VM runs
* @description Requires the projects:write scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
put: operations["put_api_v1_user_run_defaults"];
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/search": {
parameters: {
query?: never;
Expand Down Expand Up @@ -6773,6 +6803,11 @@ export interface operations {
updatedAt: string;
runDefaults?: {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand Down Expand Up @@ -6833,6 +6868,11 @@ export interface operations {
updatedAt: string;
runDefaults?: {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand Down Expand Up @@ -6889,6 +6929,11 @@ export interface operations {
updatedAt: string;
runDefaults?: {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand Down Expand Up @@ -6951,6 +6996,11 @@ export interface operations {
updatedAt: string;
runDefaults?: {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand Down Expand Up @@ -9671,9 +9721,21 @@ export interface operations {
"application/json": {
/** Format: uuid */
projectId?: string;
prompt: string;
prompt?: string;
script?: string;
skill?: string;
name?: string;
executionConfigId?: string;
vmImage?: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
/** @description Factorize application permissions to grant. Omission inherits effective client permissions and an empty list grants none. */
runScopes?: ("projects:read" | "projects:write" | "jobs:read" | "jobs:write" | "runs:read" | "runs:invoke" | "runs:start" | "runs:cancel" | "runs:write" | "integrations:read" | "integrations:write" | "skills:read" | "skills:write")[];
integrationIds?: string[];
inputs?: {
[key: string]: unknown;
};
Expand Down Expand Up @@ -9722,6 +9784,11 @@ export interface operations {
content: {
"application/json": {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand All @@ -9748,6 +9815,11 @@ export interface operations {
content: {
"application/json": {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
Expand Down Expand Up @@ -9776,6 +9848,124 @@ export interface operations {
503: components["responses"]["Error503"];
};
};
get_api_v1_user_run_defaults: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description User run defaults */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: unknown;
tags?: string[];
/** Format: uuid */
modelAccountId?: string;
portableIntegrationIds?: string[];
githubInstallationIds?: number[];
linearConnectionId?: "linear" | null;
xConnectionIds?: string[];
/** @description Factorize API scopes for new job runs. Omission uses existing scopes on update or read/invoke defaults on create; an empty array grants no application scopes. jobs:write permits configuring jobs and their future run scopes. */
runScopes?: ("projects:read" | "projects:write" | "jobs:read" | "jobs:write" | "runs:read" | "runs:invoke" | "runs:start" | "runs:cancel" | "runs:write" | "integrations:read" | "integrations:write" | "skills:read" | "skills:write")[];
} | null;
};
};
400: components["responses"]["Error400"];
401: components["responses"]["Error401"];
403: components["responses"]["Error403"];
404: components["responses"]["Error404"];
409: components["responses"]["Error409"];
429: components["responses"]["Error429"];
500: components["responses"]["Error500"];
503: components["responses"]["Error503"];
};
};
put_api_v1_user_run_defaults: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: string;
tags?: string[];
/** Format: uuid */
modelAccountId?: string;
portableIntegrationIds?: string[];
githubInstallationIds?: number[];
linearConnectionId?: "linear" | null;
xConnectionIds?: string[];
/** @description Factorize API scopes for new job runs. Omission uses existing scopes on update or read/invoke defaults on create; an empty array grants no application scopes. jobs:write permits configuring jobs and their future run scopes. */
runScopes?: ("projects:read" | "projects:write" | "jobs:read" | "jobs:write" | "runs:read" | "runs:invoke" | "runs:start" | "runs:cancel" | "runs:write" | "integrations:read" | "integrations:write" | "skills:read" | "skills:write")[];
};
};
};
responses: {
/** @description User run defaults */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
executionConfigId: string;
/**
* @description Agent harness used for the selected model.
* @enum {string}
*/
modelProvider?: "codex" | "claude" | "pi";
model?: string;
effort?: string;
vmImage?: unknown;
tags?: string[];
/** Format: uuid */
modelAccountId?: string;
portableIntegrationIds?: string[];
githubInstallationIds?: number[];
linearConnectionId?: "linear" | null;
xConnectionIds?: string[];
/** @description Factorize API scopes for new job runs. Omission uses existing scopes on update or read/invoke defaults on create; an empty array grants no application scopes. jobs:write permits configuring jobs and their future run scopes. */
runScopes?: ("projects:read" | "projects:write" | "jobs:read" | "jobs:write" | "runs:read" | "runs:invoke" | "runs:start" | "runs:cancel" | "runs:write" | "integrations:read" | "integrations:write" | "skills:read" | "skills:write")[];
};
};
};
400: components["responses"]["Error400"];
401: components["responses"]["Error401"];
403: components["responses"]["Error403"];
404: components["responses"]["Error404"];
409: components["responses"]["Error409"];
415: components["responses"]["Error415"];
429: components["responses"]["Error429"];
500: components["responses"]["Error500"];
503: components["responses"]["Error503"];
};
};
get_api_v1_search: {
parameters: {
query?: {
Expand Down
9 changes: 9 additions & 0 deletions packages/api/migrations/0066_user_run_defaults.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE app.user_run_defaults (
tenant_id uuid NOT NULL REFERENCES app.tenants(id) ON DELETE CASCADE,
user_id uuid NOT NULL REFERENCES app.auth_users(id) ON DELETE CASCADE,
run_defaults jsonb NOT NULL,
updated_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, user_id)
);

INSERT INTO app.schema_migrations(version) VALUES ('0066_user_run_defaults') ON CONFLICT DO NOTHING;
1 change: 1 addition & 0 deletions packages/api/src/agent-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class AgentApiService {
return {id: row.id, kind, config, policy: row};
}
private selected(row: AgentIntegration, config: Record<string, any>) {
if (Array.isArray(config.agentIntegrationIds)) return config.agentIntegrationIds.includes(row.id);
switch(row.kind) {
case "bearer": return Array.isArray(config.portableIntegrationIds) && config.portableIntegrationIds.includes(row.credential_id);
case "github": return Array.isArray(config.githubInstallationIds) && config.githubInstallationIds.includes(Number(row.credential_id));
Expand Down
7 changes: 5 additions & 2 deletions packages/api/src/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { z } from "zod";
import type { ApiService } from "./flow-service";
import {
jobInputSchema,
startRunInput, startRunReceipt, projectRunDefaults, storedRunDefaults, manualInvocationSchema,
startRunInput, startRunReceipt, projectRunDefaults, storedRunDefaults, userRunDefaults, manualInvocationSchema,
renameRunSchema,
reportRunErrorSchema,
invocationPermissionsInput,
Expand Down Expand Up @@ -1001,13 +1001,16 @@ export const API_ROUTES: RouteContract[] = [
(service, { params }) => service.deleteJob(params.jobId),
),
route("POST","/api/v1/runs","runs:start",{
summary:"Start a project VM run with a literal prompt and optional launch skill",
summary:"Start a project VM run with a prompt or script and per-run execution overrides",
description:"Supply exactly one of prompt or script. Omitted execution settings use project defaults, then user defaults. Omitted integrationIds inherit this MCP client's effective integration access; explicit IDs select a subset, including an empty set. runScopes is limited to the caller's effective permissions.",
responses:{"202":{description:"Accepted run",content:{"application/json":{schema:jsonSchema(startRunReceipt,"output")}}}},
},(service,{body})=>service.startRun(body),{body:startRunInput,maxBodyBytes:256_000}),
route("PUT","/api/v1/projects/{projectId}/run-defaults","projects:write",{
summary:"Set the VM configuration, permissions and capacity for direct launches",
responses:{"200":{description:"Project run defaults",content:{"application/json":{schema:jsonSchema(storedRunDefaults,"output")}}}},
},(service,{params,body})=>service.setRunDefaults(params.projectId,body),{body:projectRunDefaults,parameters:z.object({projectId:z.guid()}),ownerSession:true}),
route("GET","/api/v1/user/run-defaults","projects:read",{summary:"Get user defaults for direct VM runs",responses:{"200":{description:"User run defaults",content:{"application/json":{schema:jsonSchema(userRunDefaults.nullable(),"output")}}}}},service=>service.getUserRunDefaults()),
route("PUT","/api/v1/user/run-defaults","projects:write",{summary:"Set user defaults for direct VM runs",responses:{"200":{description:"User run defaults",content:{"application/json":{schema:jsonSchema(userRunDefaults,"output")}}}}},(service,{body})=>service.setUserRunDefaults(body),{body:userRunDefaults,ownerSession:true}),
route(
"GET",
"/api/v1/runs",
Expand Down
18 changes: 15 additions & 3 deletions packages/api/src/flow-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,34 @@ export const jobConditionsTestSchema = z.object({
export type JobInput = z.infer<typeof jobInputSchema>;
export type ManualInvocationInput = z.infer<typeof manualInvocationSchema>;

const modelProvider = z.enum(["codex", "claude", "pi"]).optional().describe("Agent harness used for the selected model.");
export const startRunInput = z.object({
projectId: z.guid().optional(),
prompt: z.string().min(1).max(50_000).refine(value => !!value.trim()),
prompt: z.string().min(1).max(50_000).refine(value => !!value.trim()).optional(),
script: z.string().min(1).max(200_000).refine(value => !!value.trim()).optional(),
skill: z.string().min(1).max(64).optional(),
name: z.string().trim().min(1).max(120).optional(),
executionConfigId: z.string().min(1).optional(),
vmImage: jobInputSchema.shape.vmImage,
modelProvider,
model: jobInputSchema.shape.model,
runScopes: jobInputSchema.shape.runScopes.describe("Factorize application permissions to grant. Omission inherits effective client permissions and an empty list grants none."),
integrationIds: z.array(z.uuid()).max(100).refine(ids => new Set(ids).size === ids.length, "Integration IDs must be unique").optional(),
inputs: z.record(z.string(), z.unknown()).refine(value => new TextEncoder().encode(JSON.stringify(value)).length <= 200_000, "Inputs exceed 200,000 bytes").optional(),
idempotencyKey: z.string().trim().min(1).max(200).optional(),
}).strict();
}).strict().refine(value => Number(Boolean(value.prompt)) + Number(Boolean(value.script)) === 1, {
message: "Supply exactly one of prompt or script.",
path: ["prompt"],
});
export const startRunReceipt = z.object({runId:z.guid(), url:z.url(), outcomeUri:z.string(), duplicate:z.boolean()});
export const projectRunDefaults = z.object({
executionConfigId: jobInputSchema.shape.executionConfigId,
model: jobInputSchema.shape.model, effort: jobInputSchema.shape.effort, vmImage: jobInputSchema.shape.vmImage,
modelProvider, model: jobInputSchema.shape.model, effort: jobInputSchema.shape.effort, vmImage: jobInputSchema.shape.vmImage,
tags: jobInputSchema.shape.tags, modelAccountId: jobInputSchema.shape.modelAccountId,
portableIntegrationIds: jobInputSchema.shape.portableIntegrationIds, githubInstallationIds: jobInputSchema.shape.githubInstallationIds,
linearConnectionId: jobInputSchema.shape.linearConnectionId, xConnectionIds: jobInputSchema.shape.xConnectionIds,
runScopes: jobInputSchema.shape.runScopes, capacity: z.number().int().min(1).max(50).default(4),
}).strict();

export const storedRunDefaults = projectRunDefaults.extend({vmImage:z.string().optional()});
export const userRunDefaults = projectRunDefaults.omit({capacity:true});
Loading