config.ts
1,449 bytes
| 1 | /** |
|---|---|
| 2 | * Turn validated API input into a fully-resolved `DebateConfig`, filling |
| 3 | * defaults (like the convergence model) the orchestrator requires. |
| 4 | */ |
| 5 | import { DEFAULT_CONVERGENCE_MODEL } from './models'; |
| 6 | import { debateConfigInputSchema, type DebateConfigInput } from './schemas'; |
| 7 | import { displayNameForModel, type DebateConfig, type Participant } from './types'; |
| 8 | |
| 9 | /** |
| 10 | * Build the stable participant list for a council. The `p{index}` id scheme is |
| 11 | * shared by the orchestrator and the persistence layer so labels line up. |
| 12 | */ |
| 13 | export function participantsFor(models: string[]): Participant[] { |
| 14 | return models.map((model, i) => ({ |
| 15 | id: `p${i}`, |
| 16 | model, |
| 17 | displayName: displayNameForModel(model), |
| 18 | })); |
| 19 | } |
| 20 | |
| 21 | export function resolveDebateConfig(input: DebateConfigInput): DebateConfig { |
| 22 | return { |
| 23 | question: input.question, |
| 24 | models: input.models, |
| 25 | chairmanModel: input.chairmanModel, |
| 26 | convergenceModel: input.convergenceModel ?? DEFAULT_CONVERGENCE_MODEL, |
| 27 | maxRounds: input.maxRounds, |
| 28 | convergenceThreshold: input.convergenceThreshold, |
| 29 | temperature: input.temperature, |
| 30 | perModelTimeoutMs: input.perModelTimeoutMs, |
| 31 | ...(input.maxCostUsd !== undefined ? { maxCostUsd: input.maxCostUsd } : {}), |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | /** Parse + resolve untrusted input in one step. Throws ZodError on bad input. */ |
| 36 | export function parseDebateConfig(raw: unknown): DebateConfig { |
| 37 | return resolveDebateConfig(debateConfigInputSchema.parse(raw)); |
| 38 | } |
| 39 | |