import {z} from 'zod' export type GetApiApiPublicV2FoldersEntitiesArgs = {workspace_id: number, folder_id?: number | undefined, filter_type?: ('FOLDER' | 'PROMPT' | 'SNIPPET' | 'WORKFLOW' | 'DATASET' | 'REPORT' | 'AB_TEST' | 'INPUT_VARIABLE_SET' | Array<'FOLDER' | 'PROMPT' | 'SNIPPET' | 'WORKFLOW' | 'DATASET' | 'REPORT' | 'AB_TEST' | 'INPUT_VARIABLE_SET'>) | undefined, search_query?: string | undefined, flatten?: boolean | undefined, include_metadata?: boolean | undefined, created_by_email?: string | undefined, created_after?: string | undefined, created_before?: string | undefined, updated_after?: string | undefined, updated_before?: string | undefined, external_source?: string | undefined, external_id?: string | undefined, sort_by?: ('created_at' | 'updated_at' | 'name' | 'id') | undefined, sort_order?: ('asc' | 'desc') | undefined, tags?: (string | Array) | undefined, semantic_search?: boolean | undefined, semantic_search_top_k?: number | undefined, semantic_search_threshold?: number | undefined}; export type GetApiApiPublicV2FoldersEntitiesOptions = {baseUrl: string, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const entityType = z.enum(["FOLDER", "PROMPT", "SNIPPET", "WORKFLOW", "DATASET", "REPORT", "AB_TEST", "INPUT_VARIABLE_SET"]); export const promptEntityMetadata = z.object({type: z.enum(["chat", "completion"]).nullable().optional(), latest_version_number: z.number().int().nullable().optional()}); export const workflowEntityMetadata = z.object({latest_version_number: z.number().int().nullable().optional()}); export const datasetEntityMetadata = z.object({isDraft: z.boolean().optional(), latest_version_number: z.number().int().nullable().optional()}); export const externalId = z.object({source: z.string().min(1).max(128), external_id: z.string().min(1).max(512)}); export const folderEntity = z.object({id: z.number().int(), name: z.string(), type: entityType, created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), folder_id: z.number().int().nullable().optional(), path: z.array(z.string()), metadata: z.union([promptEntityMetadata, workflowEntityMetadata, datasetEntityMetadata, z.object({})]).nullable().optional(), external_ids: z.array(externalId).optional()}); export const listFolderEntitiesResponse = z.object({entities: z.array(folderEntity).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 }; /** * List Folder Entities * * GET /api/public/v2/folders/entities */ export const getApiApiPublicV2FoldersEntities = async (args: GetApiApiPublicV2FoldersEntitiesArgs, options: GetApiApiPublicV2FoldersEntitiesOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args.folder_id != null) query.append("folder_id", String(args.folder_id)) if (args.filter_type != null) query.append("filter_type", String(args.filter_type)) if (args.search_query != null) query.append("search_query", String(args.search_query)) if (args.flatten != null) query.append("flatten", String(args.flatten)) if (args.include_metadata != null) query.append("include_metadata", String(args.include_metadata)) if (args.created_by_email != null) query.append("created_by_email", String(args.created_by_email)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.updated_before != null) query.append("updated_before", String(args.updated_before)) if (args.external_source != null) query.append("external_source", String(args.external_source)) if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.tags != null) query.append("tags", String(args.tags)) if (args.semantic_search != null) query.append("semantic_search", String(args.semantic_search)) if (args.semantic_search_top_k != null) query.append("semantic_search_top_k", String(args.semantic_search_top_k)) if (args.semantic_search_threshold != null) query.append("semantic_search_threshold", String(args.semantic_search_threshold)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v2/folders/entities${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(listFolderEntitiesResponse, await res.json()) };