import {z} from 'zod' export type ModelKind = 'chat' | 'embedding' | 'image' | 'video' | 'decision'; export type ModelSpecCreate = {cache_creation_input_cost_per_token?: (number | string | null) | undefined, cached_input_cost_per_token?: (number | string | null) | undefined, context_window?: (number | null) | undefined, default_context_strategy?: (string | null) | undefined, description?: (string | null) | undefined, display_name: string, input_cost_per_token?: (number | string | null) | undefined, is_active?: boolean | undefined, kind?: ModelKind | undefined, max_output_tokens?: (number | null) | undefined, model_name: string, output_cost_per_token?: (number | string | null) | undefined, provider_spec_id: string}; export type CreateApiV1WorkspacesWorkspaceModelSpecsUpsertArgs = {workspace: string, body: ModelSpecCreate}; export type CreateApiV1WorkspacesWorkspaceModelSpecsUpsertOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const modelKind = z.enum(["chat", "embedding", "image", "video", "decision"]); export const agentareaApiApiV1ModelSpecsModelSpecResponse = z.object({cache_creation_input_cost_per_token: z.string().nullable().optional(), cached_input_cost_per_token: z.string().nullable().optional(), context_window: z.number().int().nullable(), created_at: z.string(), default_context_strategy: z.string().nullable(), description: z.string().nullable(), display_name: z.string(), id: z.string(), input_cost_per_token: z.string().nullable().optional(), is_active: z.boolean(), kind: modelKind.optional(), max_output_tokens: z.number().int().nullable().optional(), model_name: z.string(), output_cost_per_token: z.string().nullable().optional(), provider_key: z.string().nullable().optional(), provider_name: z.string().nullable().optional(), provider_spec_id: z.string(), supports_function_calling: z.boolean().nullable().optional(), supports_reasoning: z.boolean().nullable().optional(), supports_vision: z.boolean().nullable().optional(), 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 }; /** * Upsert Model Spec * * POST /v1/workspaces/{workspace}/model-specs/upsert */ export const createApiV1WorkspacesWorkspaceModelSpecsUpsert = async (args: CreateApiV1WorkspacesWorkspaceModelSpecsUpsertArgs, options: CreateApiV1WorkspacesWorkspaceModelSpecsUpsertOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace))}/model-specs/upsert${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(agentareaApiApiV1ModelSpecsModelSpecResponse, await res.json()) };