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
7 changes: 5 additions & 2 deletions pi/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ export type Config = z.infer<typeof ConfigSchema>;
export const RuntimeConfigSchema = ConfigSchema.omit({ engine_url: true });
export type RuntimeConfig = z.infer<typeof RuntimeConfigSchema>;

/** JSON Schema published to the configuration worker. */
/** JSON Schema published to the configuration worker. The registry validator
* has no `$schema` meta-schema, so strip the draft-2020-12 `$schema` key. */
export function runtimeJsonSchema(): Record<string, unknown> {
return z.toJSONSchema(RuntimeConfigSchema) as Record<string, unknown>;
const out = z.toJSONSchema(RuntimeConfigSchema) as Record<string, unknown>;
delete out.$schema;
return out;
}

/** The runtime slice of a full config, for use as `initial_value`. */
Expand Down
29 changes: 19 additions & 10 deletions pi/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ const SteerPayloadSchema = z.object({
prompt: z.string().describe('Instruction to inject into the live run'),
});

const RUN_REQUEST_FORMAT = z.toJSONSchema(RunPayloadSchema);
const SESSION_ID_FORMAT = z.toJSONSchema(SessionIdSchema);
const STEER_REQUEST_FORMAT = z.toJSONSchema(SteerPayloadSchema);
// The registry's publish validator has no `$schema` meta-schema registered, so
// the draft-2020-12 `$schema` key z.toJSONSchema stamps at the root fails
// publish. Strip it; the schema body is what the engine + registry consume.
function jsonSchema(schema: z.ZodType): Record<string, unknown> {
const out = z.toJSONSchema(schema) as Record<string, unknown>;
delete out.$schema;
return out;
}

const RUN_REQUEST_FORMAT = jsonSchema(RunPayloadSchema);
const SESSION_ID_FORMAT = jsonSchema(SessionIdSchema);
const STEER_REQUEST_FORMAT = jsonSchema(SteerPayloadSchema);

const UsageSchema = z.object({
input_tokens: z.number(),
Expand Down Expand Up @@ -149,13 +158,13 @@ const SessionsResultSchema = z.object({
sessions: z.array(SessionRecordSchema),
});

const RUN_RESPONSE_FORMAT = z.toJSONSchema(RunResultSchema);
const START_RESPONSE_FORMAT = z.toJSONSchema(StartResultSchema);
const STEER_RESPONSE_FORMAT = z.toJSONSchema(SteerResultSchema);
const FOLLOWUP_RESPONSE_FORMAT = z.toJSONSchema(FollowUpResultSchema);
const STOP_RESPONSE_FORMAT = z.toJSONSchema(StopResultSchema);
const STATUS_RESPONSE_FORMAT = z.toJSONSchema(StatusResultSchema);
const SESSIONS_RESPONSE_FORMAT = z.toJSONSchema(SessionsResultSchema);
const RUN_RESPONSE_FORMAT = jsonSchema(RunResultSchema);
const START_RESPONSE_FORMAT = jsonSchema(StartResultSchema);
const STEER_RESPONSE_FORMAT = jsonSchema(SteerResultSchema);
const FOLLOWUP_RESPONSE_FORMAT = jsonSchema(FollowUpResultSchema);
const STOP_RESPONSE_FORMAT = jsonSchema(StopResultSchema);
const STATUS_RESPONSE_FORMAT = jsonSchema(StatusResultSchema);
const SESSIONS_RESPONSE_FORMAT = jsonSchema(SessionsResultSchema);

type LiveRun = { session: AgentSession };
const live = new Map<string, LiveRun>();
Expand Down
Loading