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
199 changes: 167 additions & 32 deletions packages/api-client/src/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,28 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/v1/runs/{runId}/artifacts/{artifactId}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
/**
* Download a retained run artifact
* @description Requires the runs:read scope.
*
* Accepts a scoped bearer token or interactive owner session.
*/
get: operations["get_api_v1_runs_runId_artifacts_artifactId"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/v1/runs/{runId}/trace-pages": {
parameters: {
query?: never;
Expand Down Expand Up @@ -1918,21 +1940,85 @@ export interface components {
};
RunDetail: {
id: string;
state: string;
/** @description Live file generation; clients reset trace pagination when it changes. */
trace_generation?: string | null;
trace_projection?: components["schemas"]["TraceProjection"];
trace_sources?: components["schemas"]["TraceSources"];
execution_diagnostics: components["schemas"]["ExecutionDiagnostics"];
harness_log: components["schemas"]["HarnessLog"];
/** @description Secondary artifact or cleanup error; does not replace execution_diagnostics */
artifact_error?: string | null;
/** @description Current job name, included so run content does not require a separate job request. */
job_id: string;
project_id?: string;
project_name?: string;
job_name: string;
issue_id: string;
issue_url: string | null;
issue_title: string;
run_name: string;
agent_name: string;
workspace_name: string;
agent_kind: string;
/** @enum {string} */
state: "queued" | "reserved" | "starting" | "running" | "blocked" | "stopping" | "succeeded" | "failed" | "stopped" | "done" | "ignored";
provider: string;
backend_kind: string;
capabilities: string[];
destination_url: string | null;
/** @enum {string} */
artifact_state: "pending" | "collecting" | "stored" | "partial" | "failed";
artifact_error: string | null;
created_at: string;
updated_at: string;
started_at: string | null;
failure_source: ("system" | "agent") | null;
agent_error: {
reason: string;
reported_at: string;
reporter: {
user_id: string;
/** @enum {string} */
kind: "api_key" | "oauth" | "session";
id: string;
};
} | null;
elapsed_time?: ({
duration: number;
} | {
low: number;
high: number;
}) | null;
job_result: {
/** @enum {string} */
status: "succeeded" | "failed";
summary?: string;
reason?: string;
outputs?: {
[key: string]: unknown;
};
} | null;
run_artifacts: {
id: string;
kind: string;
provider: string;
format: string;
byte_size: number;
sha256: string;
state: string;
media_type: string | null;
created_at: string;
}[];
tenant_id: string;
invocation_id: string;
execution_handle: {
backendKind: string;
id: string;
} | null;
execution_backend_kind: string;
execution_capabilities: string[];
claim_released: boolean;
vm_cleanup_attempt: number;
cleanup_next_at: string | null;
vm_cleanup_complete: boolean;
prompt: string;
context: {
[key: string]: unknown;
};
occurrence: {
[key: string]: unknown;
} | null;
invocation: {
id: string;
source: string;
Expand All @@ -1946,33 +2032,54 @@ export interface components {
} | null;
created_at: string;
};
invocation_source: string;
invocation_claim_key: string;
invocation_trigger_id: string | null;
invocation_created_at: string;
activity: {
action: string;
detail: string;
created_at: string;
}[];
tenant_id?: string;
invocation_id?: string;
execution_handle?: {
backendKind: string;
id: string;
execution_diagnostics: {
[key: string]: unknown;
} | null;
execution_backend_kind?: string;
execution_capabilities?: string[];
claim_released?: boolean;
vm_cleanup_attempt?: number;
vm_cleanup_complete?: boolean;
/** Format: date-time */
cleanup_next_at?: string | null;
occurrence?: {
trace_sources: {
primary: {
/** @enum {string} */
kind: "execution_stream" | "native_session";
path: string;
/** @constant */
mediaType: "application/x-ndjson";
/** @enum {string} */
provider: "codex" | "claude" | "pi";
formatVersion?: string;
cliVersion?: string;
harnessVersion?: string;
discoverCommand?: string;
};
nativeSession?: {
/** @enum {string} */
kind: "execution_stream" | "native_session";
path: string;
/** @constant */
mediaType: "application/x-ndjson";
/** @enum {string} */
provider: "codex" | "claude" | "pi";
formatVersion?: string;
cliVersion?: string;
harnessVersion?: string;
discoverCommand?: string;
};
} | null;
trace_projection: {
[key: string]: unknown;
} | null;
invocation_source?: string;
invocation_claim_key?: string;
invocation_trigger_id?: string | null;
/** Format: date-time */
invocation_created_at?: string;
} & WithRequired<components["schemas"]["Run"], "id" | "state" | "job_name">;
trace_generation: string | null;
harness_log: {
[key: string]: unknown;
} | null;
};
RunDiagnostics: {
runId: string;
jobId: string;
Expand Down Expand Up @@ -6276,6 +6383,37 @@ export interface operations {
503: components["responses"]["Error503"];
};
};
get_api_v1_runs_runId_artifacts_artifactId: {
parameters: {
query?: never;
header?: never;
path: {
runId: string;
artifactId: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Authorized artifact bytes */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/octet-stream": 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"];
};
};
get_api_v1_runs_runId_trace_pages: {
parameters: {
query?: {
Expand Down Expand Up @@ -6618,6 +6756,3 @@ export interface operations {
};
};
}
type WithRequired<T, K extends keyof T> = T & {
[P in K]-?: T[P];
};
6 changes: 6 additions & 0 deletions packages/api/migrations/0026_structured_job_results.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE app.runs ADD COLUMN result_protocol_version integer NOT NULL DEFAULT 0;
ALTER TABLE app.runs ADD COLUMN job_result jsonb;
ALTER TABLE app.runs ADD CONSTRAINT runs_result_protocol_version_check CHECK (result_protocol_version IN (0,1));
ALTER TABLE app.run_artifacts DROP CONSTRAINT IF EXISTS run_artifacts_kind_check;
ALTER TABLE app.run_artifacts ADD CONSTRAINT run_artifacts_kind_check CHECK (kind IN ('execution_stream','native_session','related_session','terminal_log','manifest','job_file'));
INSERT INTO app.schema_migrations(version) VALUES ('0026_structured_job_results') ON CONFLICT DO NOTHING;
3 changes: 2 additions & 1 deletion packages/api/src/agent-driver.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CLAUDE_STREAM_HARNESS } from "./claude-stream";
import { PI_CLI_VERSION, PI_SESSION_VERSION } from "./pi-trace";
import type { TraceSources } from "./trace-source";
import { JOB_RESULT_PATH } from "./job-result";
export type AgentKind = "codex" | "claude" | "pi";

export interface AgentConfiguration { model?: string; effort?: string; }
Expand Down Expand Up @@ -70,7 +71,7 @@ class PiDriver implements AgentDriver {
const drivers: Record<AgentKind, AgentDriver> = { codex: new CodexDriver(), claude: new ClaudeDriver(), pi: new PiDriver() };
export function agentDriver(kind: AgentKind): AgentDriver {
const driver = drivers[kind];
return { kind, launch(runId, config) { const spec = driver.launch(runId, config); return { ...spec, traceSources: driverTraceSources(kind, spec) }; } };
return { kind, launch(runId, config) { const spec = driver.launch(runId, config); return { ...spec, env: { ...spec.env, FACTORIZE_RESULT_PATH: JOB_RESULT_PATH }, traceSources: driverTraceSources(kind, spec) }; } };
}

/** Compatibility for drivers and historical runs that only declare native sessions. */
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/api-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { searchResponse } from "./search-contracts";
import { consentPreviewInput, consentPreviewResponse, consentDecisionInput, consentDecisionResponse } from "./consent-api";
import { exeConnection, integrationStatus, authorizedClient, accessToken, createdAccessToken, savedExe, testedExe, savedAmp, savedTail, okResult } from "./settings-contracts";
import { triggerAvailabilityResponse, namedOption, providerOptions, githubInstallation, githubRepository, tailIntegration } from "./editor-contracts";
import { runSummaryResponse, runPageResponse, runStatusResponse, revisionTracePage, revisionTraceQuery } from "./run-read-contracts";
import { runSummaryResponse, runPageResponse, runStatusResponse, fullRunResponse, revisionTracePage, revisionTraceQuery } from "./run-read-contracts";
import { jobPageQuery, jobSummaryPage, jobSelectorPage, jobResponse, jobUpdateInput } from "./job-contracts";
import { projectInput, projectListQuery, projectResponse } from "./project-contracts";
import { z } from "zod";
Expand Down Expand Up @@ -867,6 +867,10 @@ export const API_ROUTES: RouteContract[] = [
description: "No prompt decryption, invocation context, artifacts, activity or diagnostics assembly. Continue polling terminal runs while finalizing is true. trace_revision changes on generation transition or canonical projection/replay; live appends retain the revision. Full detail remains available at GET /runs/{runId}.",
responses: { "200": { description: "Status", content: { "application/json": { schema: jsonSchema(runStatusResponse, "output") } } } },
}, (service, { params }) => service.getRunStatus(params.runId), { parameters: z.object({ runId: z.guid() }) }),
route("GET", "/api/v1/runs/{runId}/artifacts/{artifactId}", "runs:read", {
summary: "Download a retained run artifact",
responses: { "200": { description: "Authorized artifact bytes", content: { "application/octet-stream": { schema: { type: "string", format: "binary" } } } } },
}, (service, { params }) => service.downloadRunArtifact(params.runId, params.artifactId), { parameters: z.object({ runId: z.guid(), artifactId: z.guid() }) }),
route("GET", "/api/v1/runs/{runId}/trace-pages", "runs:read", {
summary: "Get revision-bound trace page",
description: "First request omits revision and uses after=0. Subsequent requests supply the returned revision. A changed generation or canonical projection returns reset=true and events from zero in the new revision, from one database snapshot. Discard all cached old pages before merging the response. nextCursor=null means caught up, not finalized; poll after the last sequence while active/finalizing. Legacy GET /trace remains unchanged.",
Expand Down Expand Up @@ -1099,6 +1103,7 @@ export function generateOpenApi() {
...document.components.schemas,
Run: { ...jsonSchema(runSummaryResponse, "output"), additionalProperties: true },
RunPage: jsonSchema(runPageResponse, "output"),
RunDetail: jsonSchema(fullRunResponse, "output"),
...Object.fromEntries(
Object.entries(namedBodies).map(([name, schema]) => [
name,
Expand Down
Loading
Loading