import {z} from 'zod' export type ModelConfig = {temperature?: (number | null) | undefined, max_tokens?: (number | null) | undefined, top_p?: (number | null) | undefined, stop_sequences?: (Array | null) | undefined, reasoning_effort?: ('none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null) | undefined, request_timeout_ms?: (number | null) | undefined, thinking_budget?: (number | null) | undefined}; export type ModelChainEntry = {model: string, config?: ModelConfig | undefined}; export type TeamMemberCreate = {assistant_id: string, assistant_revision_id?: (string | null) | undefined, router_name?: (string | null) | undefined, router_description?: (string | null) | undefined, examples?: (Array | null) | undefined, model_settings?: (ModelChainEntry | null) | undefined, position?: number | undefined, enabled?: boolean | undefined}; export type TeamRevisionCreate = {name: string, description?: (string | null) | undefined, based_on_revision_id?: (string | null) | undefined, purpose?: (string | null) | undefined, mode?: ('supervisor' | 'swarm') | undefined, fallback_member_id: string, initial_member_id?: (string | null) | undefined, swarm_domain_hint?: (string | null) | undefined, swarm_max_hops?: (number | null) | undefined, router_config_id?: (string | null) | undefined, router_model_settings?: (ModelChainEntry | null) | undefined, members?: (Array | null) | undefined}; export type CreateApiV1TeamsTeamIdRevisionsArgs = {team_id: string, body: TeamRevisionCreate}; export type CreateApiV1TeamsTeamIdRevisionsOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const modelConfig = z.object({temperature: z.number().gte(0).lte(2).nullable().optional(), max_tokens: z.number().int().gte(1).nullable().optional(), top_p: z.number().gte(0).lte(1).nullable().optional(), stop_sequences: z.array(z.string()).nullable().optional(), reasoning_effort: z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).nullable().optional(), request_timeout_ms: z.number().int().gte(1000).lte(20000).nullable().optional(), thinking_budget: z.number().int().gte(1).nullable().optional()}); export const modelChainEntry = z.object({model: z.string(), config: modelConfig.optional()}); export const teamMemberResponse = z.object({id: z.string(), assistant_id: z.string(), assistant_name: z.string(), assistant_revision_id: z.string().nullable().optional(), router_name: z.string().nullable().optional(), router_description: z.string().nullable().optional(), examples: z.array(z.string()).optional(), model_settings: modelChainEntry.nullable().optional(), position: z.number().int(), enabled: z.boolean(), created_at: z.string()}); export const teamRevisionResponse = z.object({id: z.string(), team_id: z.string(), name: z.string(), description: z.string().nullable().optional(), purpose: z.string().nullable().optional(), mode: z.string(), fallback_member_id: z.string(), initial_member_id: z.string().nullable().optional(), swarm_domain_hint: z.string().nullable().optional(), swarm_max_hops: z.number().int(), router_config_id: z.string().nullable().optional(), router_model_settings: modelChainEntry.nullable().optional(), members: z.array(teamMemberResponse).optional(), created_by: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create a team revision * * POST /v1/teams/{team_id}/revisions */ export const createApiV1TeamsTeamIdRevisions = async (args: CreateApiV1TeamsTeamIdRevisionsArgs, options: CreateApiV1TeamsTeamIdRevisionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.team_id))}/revisions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(teamRevisionResponse, await res.json()) };