import {z} from 'zod' export type CreateApiApiPublicV2TablesTableIdSheetsArgs = {table_id: string, body: {title?: (string | null) | undefined, index?: (number | null) | undefined, operation_id?: (string | null) | undefined, source?: ({type: 'file', file_name: string, file_content_base64: string} | {type: 'request_logs', request_log_ids?: (Array | null) | undefined, prompt_id?: (number | null) | undefined, prompt_version_id?: (number | null) | undefined, prompt_label_id?: (number | null) | undefined, start_time?: (string | null) | undefined, end_time?: (string | null) | undefined}) | undefined}}; export type CreateApiApiPublicV2TablesTableIdSheetsOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sheet = z.object({id: z.string().optional(), table_id: z.string().optional(), workspace_id: z.number().int().optional(), title: z.string().optional(), index: z.number().int().optional(), row_count: z.number().int().optional(), version_count: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const createApiApiPublicV2TablesTableIdSheetsResponse = z.object({success: z.boolean().optional(), sheet: sheet.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 }; /** * Create Sheet * * POST /api/public/v2/tables/{table_id}/sheets */ export const createApiApiPublicV2TablesTableIdSheets = async (args: CreateApiApiPublicV2TablesTableIdSheetsArgs, options: CreateApiApiPublicV2TablesTableIdSheetsOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/tables/${encodeURIComponent(String(args.table_id))}/sheets${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(createApiApiPublicV2TablesTableIdSheetsResponse, await res.json()) };