import {z} from 'zod' export type GetApiV1ConsoleModelSquareFavoritesArgs = {showAll?: boolean | undefined, limit?: number | undefined}; export type GetApiV1ConsoleModelSquareFavoritesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const modelsquareV1FavoriteItem = z.object({callCountDisplay: z.string().optional(), contextDisplay: z.string().optional(), favoriteAt: z.string().optional(), favoriteId: z.number().int().optional(), favorited: z.boolean().optional(), iconUrl: z.string().optional(), inputPriceDisplay: z.string().optional(), jumpUrl: z.string().optional(), logoText: z.string().optional(), modelId: z.number().int().optional(), modelName: z.string().optional(), providerName: z.string().optional(), sort: z.number().int().optional(), tags: z.array(z.string()).optional(), tagsZh: z.array(z.string()).optional()}); export const modelsquareV1ListFavoritesReply = z.object({favoriteCount: z.number().int().optional(), items: z.array(modelsquareV1FavoriteItem).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 }; /** * ListFavorites 查询我的收藏列表(默认 4 个,showAll=true 返回全部)。 * * GET /v1/console/model-square/favorites */ export const getApiV1ConsoleModelSquareFavorites = async (args: GetApiV1ConsoleModelSquareFavoritesArgs, options: GetApiV1ConsoleModelSquareFavoritesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.showAll != null) query.append("showAll", String(args.showAll)) if (args.limit != null) query.append("limit", String(args.limit)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/console/model-square/favorites${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(modelsquareV1ListFavoritesReply, await res.json()) };