import {z} from 'zod' export type GetApiV1AdminApiSpecTemplatesTemplateIdBindableModelsArgs = {templateId: string, keyword?: string | undefined}; export type GetApiV1AdminApiSpecTemplatesTemplateIdBindableModelsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const adminV1BindableModel = z.object({bound: z.boolean().optional(), modelId: z.string().optional(), modelName: z.string().optional()}); export const adminV1ListBindableModelsReply = z.object({items: z.array(adminV1BindableModel).optional()}); 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 }; /** * ListBindableModels 列出全部启用模型并标注是否已绑定该模板(端点行由绑定自动派生,不做资格过滤) * * GET /v1/admin/api-spec-templates/{templateId}/bindable-models */ export const getApiV1AdminApiSpecTemplatesTemplateIdBindableModels = async (args: GetApiV1AdminApiSpecTemplatesTemplateIdBindableModelsArgs, options: GetApiV1AdminApiSpecTemplatesTemplateIdBindableModelsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.keyword != null) query.append("keyword", String(args.keyword)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/api-spec-templates/${encodeURIComponent(String(args.templateId))}/bindable-models${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(adminV1ListBindableModelsReply, await res.json()) };