import {z} from 'zod' export type NavigateDateQuery = string; export type GetApiConnectorsNavigateArgs = {nodeId?: string | undefined, page?: number | undefined, limit?: number | undefined, depth?: number | undefined, nodeTypes?: Array | undefined, createdAfter?: NavigateDateQuery | undefined, createdBefore?: NavigateDateQuery | undefined, modifiedAfter?: NavigateDateQuery | undefined, modifiedBefore?: NavigateDateQuery | undefined}; export type GetApiConnectorsNavigateOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const knowledgeGraphNodeRefSchema = z.object({id: z.string(), name: z.string(), node_type: z.string(), sub_type: z.string().nullable(), is_record: z.boolean()}); export const knowledgeGraphNodeRowSchema = z.object({id: z.string(), name: z.string(), node_type: z.string(), sub_type: z.string().nullable(), is_record: z.boolean(), has_children: z.boolean(), detail: z.string().nullable(), web_url: z.string().nullable().optional(), indexing_status: z.string().nullable().optional(), source_created_at: z.number().int().nullable().optional(), source_modified_at: z.number().int().nullable().optional(), level: z.number().int().optional(), context_summary: z.string().nullable().optional()}); export const knowledgeGraphPaginationSchema = z.object({page: z.number().int(), limit: z.number().int(), total: z.number().int(), has_next: z.boolean(), has_prev: z.boolean()}); export const navigateKnowledgeGraphResponseSchema = z.object({current: knowledgeGraphNodeRefSchema.nullable(), breadcrumbs: z.array(knowledgeGraphNodeRefSchema), rows: z.array(knowledgeGraphNodeRowSchema), related: z.array(knowledgeGraphNodeRowSchema), pagination: knowledgeGraphPaginationSchema.nullable(), web_url: z.string().nullable(), indexing_status: z.string().nullable(), connector: z.string().nullable(), context_block: z.string().nullable().optional(), text: z.string()}); 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 }; /** * Browse the knowledge graph from a node * * GET /connectors/navigate * * Also accepts auth: oauth2 */ export const getApiConnectorsNavigate = async (args: GetApiConnectorsNavigateArgs, options?: GetApiConnectorsNavigateOptions) => { const {baseUrl = "https://app.pipeshub.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.nodeId != null) query.append("nodeId", String(args.nodeId)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.depth != null) query.append("depth", String(args.depth)) for (const item of args.nodeTypes ?? []) query.append("nodeTypes", String(item)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) if (args.modifiedAfter != null) query.append("modifiedAfter", String(args.modifiedAfter)) if (args.modifiedBefore != null) query.append("modifiedBefore", String(args.modifiedBefore)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/connectors/navigate${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(navigateKnowledgeGraphResponseSchema, await res.json()) };