import {z} from 'zod' export type IDSEnum = 'pdf' | 'doc' | 'http' | 'tool' | 'text_blob' | 'image' | 'text_image'; export type CreateApiApiV1DatasourceDatasourceIdTextBlobArgs = {datasource_id: string, ds_type: IDSEnum | null, name?: (string | null) | undefined, description?: (string | null) | undefined, org_id?: (string | null) | undefined, body: {[key: string]: unknown}}; export type CreateApiApiV1DatasourceDatasourceIdTextBlobOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iDSEnum = z.enum(["pdf", "doc", "http", "tool", "text_blob", "image", "text_image"]); export const iDataSourceFileRead = z.object({ds_type: iDSEnum.nullable(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), attributes: z.record(z.string(), z.unknown()).optional(), org_id: z.string().nullable().optional(), id: z.string()}); export const iPostResponseBaseIDataSourceFileRead = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iDataSourceFileRead.nullable().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 }; /** * Add Datasourcefile Text Blob * * POST /api/v1/datasource/{datasource_id}/text_blob * * Also accepts auth: HTTPBearer */ export const createApiApiV1DatasourceDatasourceIdTextBlob = async (args: CreateApiApiV1DatasourceDatasourceIdTextBlobArgs, options: CreateApiApiV1DatasourceDatasourceIdTextBlobOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.ds_type != null) query.append("ds_type", String(args.ds_type)) if (args.name != null) query.append("name", String(args.name)) if (args.description != null) query.append("description", String(args.description)) if (args.org_id != null) query.append("org_id", String(args.org_id)) if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/datasource/${encodeURIComponent(String(args.datasource_id))}/text_blob${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(iPostResponseBaseIDataSourceFileRead, await res.json()) };