import {z} from 'zod' export type ReadFileRequest = {component?: (string | null) | undefined, line_end?: (number | null) | undefined, line_start?: (number | null) | undefined, max_chars?: number | undefined, pages?: (Array | null) | undefined, path: string}; export type CreateApiV1WorkspacesWorkspaceIdToolsReadFileArgs = {workspace_id: string, 'Idempotency-Key'?: (string | null) | undefined, body: ReadFileRequest}; export type CreateApiV1WorkspacesWorkspaceIdToolsReadFileOptions = {baseUrl?: string | undefined, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const grepTable = z.object({first_line: z.number().int(), header: z.string(), last_line: z.number().int(), rows: z.number().int().nullable().optional(), title: z.string().nullable()}); export const readFileResponse = z.object({components_omitted: z.array(z.string()), components_returned: z.array(z.string()), content: z.string(), credits: z.number().int().gte(0).nullable().optional(), file_id: z.string(), job_id: z.string().nullable().optional(), line_count: z.number().int().nullable().optional(), line_end: z.number().int().nullable().optional(), line_start: z.number().int().nullable().optional(), pages_returned: z.array(z.number().int()), path: z.string(), sql_tables: z.array(z.string()).optional(), table: grepTable.nullable().optional(), truncated: z.boolean(), waiver: z.enum(["repeat_of_job", "no_job"]).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 }; /** * read_file * * POST /v1/workspaces/{workspace_id}/tools/read-file */ export const createApiV1WorkspacesWorkspaceIdToolsReadFile = async (args: CreateApiV1WorkspacesWorkspaceIdToolsReadFileArgs, options?: CreateApiV1WorkspacesWorkspaceIdToolsReadFileOptions) => { const {baseUrl = "https://ndi-api.nace.ai", fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace_id))}/tools/read-file${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(readFileResponse, await res.json()) };