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
280 changes: 280 additions & 0 deletions packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,72 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v1/fly/execution-configurations": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* List Fly execution configurations
* @description Returns tenant-owned image, region, and VM size selections without connection credentials.
*
* Requires the integrations:read scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
get: operations["get_api_v1_fly_execution_configurations"];
put?: never;
/**
* Create a Fly execution configuration
* @description Requires a saved Fly connection and validates region and VM size against bounded provider metadata.
*
* Requires the integrations:write scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
post: operations["post_api_v1_fly_execution_configurations"];
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/fly/execution-configurations/{id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Read a Fly execution configuration
* @description Requires the integrations:read scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
get: operations["get_api_v1_fly_execution_configurations_id"];
/**
* Update a Fly execution configuration
* @description Requires the integrations:write scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
put: operations["put_api_v1_fly_execution_configurations_id"];
post?: never;
/**
* Delete a Fly execution configuration
* @description Requires the integrations:write scope.
*
* An interactive owner session is required; bearer tokens cannot call this operation.
*/
delete: operations["delete_api_v1_fly_execution_configurations_id"];
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/integrations/exe": {
parameters: {
query?: never;
Expand Down Expand Up @@ -4034,6 +4100,220 @@ export interface operations {
503: components["responses"]["Error503"];
};
};
get_api_v1_fly_execution_configurations: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Configurations */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
configurations: {
/** Format: uuid */
id: string;
name: string;
image: string;
region: string;
size: string;
createdAt: string;
updatedAt: string;
}[];
};
};
};
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"];
};
};
post_api_v1_fly_execution_configurations: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody: {
content: {
"application/json": {
name: string;
image: string;
region: string;
size: string;
};
};
};
responses: {
/** @description Created configuration */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
configuration: {
/** Format: uuid */
id: string;
name: string;
image: string;
region: string;
size: string;
createdAt: string;
updatedAt: string;
};
};
};
};
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_fly_execution_configurations_id: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Configuration */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
configuration: {
/** Format: uuid */
id: string;
name: string;
image: string;
region: string;
size: string;
createdAt: string;
updatedAt: string;
};
};
};
};
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_fly_execution_configurations_id: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
requestBody: {
content: {
"application/json": {
name: string;
image: string;
region: string;
size: string;
};
};
};
responses: {
/** @description Updated configuration */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
configuration: {
/** Format: uuid */
id: string;
name: string;
image: string;
region: string;
size: string;
createdAt: string;
updatedAt: string;
};
};
};
};
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"];
};
};
delete_api_v1_fly_execution_configurations_id: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Deletion result */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
id: string;
/** @constant */
deleted: true;
};
};
};
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_integrations_exe: {
parameters: {
query?: never;
Expand Down
12 changes: 12 additions & 0 deletions packages/api/migrations/0035_fly_execution_configurations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE app.fly_execution_configurations (
tenant_id uuid NOT NULL REFERENCES app.fly_connections(tenant_id) ON DELETE CASCADE,
id uuid NOT NULL,
name text NOT NULL CHECK (length(name) BETWEEN 1 AND 120),
image text NOT NULL CHECK (length(image) BETWEEN 1 AND 512),
region text NOT NULL CHECK (region ~ '^[a-z0-9]{3}$'),
size text NOT NULL CHECK (size ~ '^[a-z0-9-]{1,64}$'),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, id),
UNIQUE (tenant_id, name)
);
18 changes: 18 additions & 0 deletions packages/api/src/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import document from "./api-document.json";
import { authInputs, authSuccess, continuationSuccess, connectionStartInput, connectionStartSuccess, connectionResumeInput, loginSuccess, sessionResponse, type AuthAction } from "./auth-api";
import { skillInput, skillUpdateInput, skillPage, skillResponse, skillJobsResponse, previewSkillInput } from "./skills";
import { flyConnectionInput, flyConnectionMetadata } from "./fly-account-client";
import { flyExecutionConfiguration, flyExecutionConfigurationInput } from "./fly-execution-configurations";

type JsonSchema = Record<string, any>;
export interface RouteContract {
Expand Down Expand Up @@ -379,6 +380,23 @@ export const API_ROUTES: RouteContract[] = [
description: "Owner browser session only. Deletes the tenant's encrypted provisioning token.",
responses: { "200": { description: "Deletion result", content: { "application/json": { schema: jsonSchema(z.object({ deleted: z.boolean() }), "output") } } } },
}, service => service.removeFlyConnection(), { ownerSession: true }),
route("GET", "/api/v1/fly/execution-configurations", "integrations:read", {
summary: "List Fly execution configurations", description: "Returns tenant-owned image, region, and VM size selections without connection credentials.",
responses: { "200": { description: "Configurations", content: { "application/json": { schema: jsonSchema(z.object({ configurations: z.array(flyExecutionConfiguration) }), "output") } } } },
}, service => service.listFlyExecutionConfigurations(), { ownerSession: true }),
route("POST", "/api/v1/fly/execution-configurations", "integrations:write", {
summary: "Create a Fly execution configuration", description: "Requires a saved Fly connection and validates region and VM size against bounded provider metadata.",
responses: { "200": { description: "Created configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } },
}, (service, { body }) => service.saveFlyExecutionConfiguration(body), { body: flyExecutionConfigurationInput, ownerSession: true }),
route("GET", "/api/v1/fly/execution-configurations/{id}", "integrations:read", {
summary: "Read a Fly execution configuration", responses: { "200": { description: "Configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } },
}, (service, { params }) => service.getFlyExecutionConfiguration(params.id!), { ownerSession: true, parameters: z.object({ id: z.uuid() }) }),
route("PUT", "/api/v1/fly/execution-configurations/{id}", "integrations:write", {
summary: "Update a Fly execution configuration", responses: { "200": { description: "Updated configuration", content: { "application/json": { schema: jsonSchema(z.object({ configuration: flyExecutionConfiguration }), "output") } } } },
}, (service, { params, body }) => service.saveFlyExecutionConfiguration(body, params.id), { body: flyExecutionConfigurationInput, ownerSession: true, parameters: z.object({ id: z.uuid() }) }),
route("DELETE", "/api/v1/fly/execution-configurations/{id}", "integrations:write", {
summary: "Delete a Fly execution configuration", responses: { "200": { description: "Deletion result", content: { "application/json": { schema: jsonSchema(z.object({ id: z.string(), deleted: z.literal(true) }), "output") } } } },
}, (service, { params }) => service.removeFlyExecutionConfiguration(params.id!), { ownerSession: true, parameters: z.object({ id: z.uuid() }) }),
route(
"PUT",
"/api/v1/integrations/exe",
Expand Down
15 changes: 14 additions & 1 deletion packages/api/src/flow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { safeDiagnosticText } from "./harness-diagnostics";
import { skillInput, skillUpdateInput, skillPage, skillResponse, skillJobsResponse, previewSkillInput, composePrompt } from "./skills";
import { createFlyAccountClient, FlyAccountError, flyConnectionInput } from "./fly-account-client";
import { FlyConnectionRepository } from "./postgres/fly-connection-repository";
import { FlyExecutionConfigurationRepository } from "./postgres/fly-execution-configuration-repository";
import { flyExecutionConfigurationInput, getFlyExecutionMetadata, type FlyExecutionMetadataLoader } from "./fly-execution-configurations";

const PROJECT_GRAPH_LABEL_MAX_CHARS = 24;

Expand All @@ -63,7 +65,7 @@ type Scope = "projects:read" | "projects:write" | "jobs:read" | "jobs:write" | "

export class ApiService {
authorizationDuration = 0;
constructor(private env: Env, private auth: OAuthProps, private ctx?: ExecutionContext) {}
constructor(private env: Env, private auth: OAuthProps, private ctx?: ExecutionContext, private flyMetadata: FlyExecutionMetadataLoader = getFlyExecutionMetadata) {}

private jobs() { return new PostgresJobRepository(databaseFor(this.env), this.auth.tenantId, value => encrypt(value, this.env.CREDENTIAL_ENCRYPTION_KEY), value => decrypt(value, this.env.CREDENTIAL_ENCRYPTION_KEY)); }
private connections() { return new ConnectionRepository(databaseFor(this.env), this.auth.tenantId, this.env.CREDENTIAL_ENCRYPTION_KEY); }
Expand Down Expand Up @@ -187,6 +189,17 @@ export class ApiService {
} catch (error) { this.throwFlyAccountError(error); }
}
async removeFlyConnection() { await this.authorizeOwnerSession("integrations:write"); return { deleted: await this.flyConnections().remove() }; }
private flyExecutionConfigs() { return new FlyExecutionConfigurationRepository(databaseFor(this.env), this.auth.tenantId); }
async listFlyExecutionConfigurations() { await this.authorizeOwnerSession("integrations:read"); return { configurations: await this.flyExecutionConfigs().list() }; }
async getFlyExecutionConfiguration(id: string) { await this.authorizeOwnerSession("integrations:read"); const value = await this.flyExecutionConfigs().get(id); if (!value) throw new ServiceError(404, "not_found", "Fly execution configuration not found"); return { configuration: value }; }
async saveFlyExecutionConfiguration(input: unknown, id?: string) {
await this.authorizeOwnerSession("integrations:write");
if (!await this.flyConnections().get()) throw new ServiceError(409, "fly_connection_required", "Connect a Fly account before saving execution configurations.");
const parsed = flyExecutionConfigurationInput.parse(input), metadata = await this.flyMetadata();
if (!metadata.regions.includes(parsed.region) || !metadata.sizes.includes(parsed.size)) throw new ServiceError(400, "invalid_fly_configuration", "The selected Fly region or VM size is unavailable.");
return { configuration: await this.flyExecutionConfigs().save(parsed, id) };
}
async removeFlyExecutionConfiguration(id: string) { await this.authorizeOwnerSession("integrations:write"); const deleted = await this.flyExecutionConfigs().remove(id); if (!deleted) throw new ServiceError(404, "not_found", "Fly execution configuration not found"); return { id, deleted: true }; }
private throwFlyAccountError(error: unknown): never {
if (error instanceof FlyAccountError) throw new ServiceError(error.kind === "auth" ? 401 : error.kind === "organization" ? 400 : 502, error.kind === "auth" ? "fly_auth_failed" : error.kind === "organization" ? "fly_organization_unavailable" : "fly_validation_failed", error.message);
throw error;
Expand Down
Loading
Loading