import {z} from 'zod' export type GetApiV1DefaultBanksBankIdGraphArgs = {bank_id: string, type?: (string | null) | undefined, limit?: number | undefined, q?: (string | null) | undefined, tags?: (Array | null) | undefined, tags_match?: ('any' | 'all' | 'any_strict' | 'all_strict' | 'exact') | undefined, document_id?: (string | null) | undefined, chunk_id?: (string | null) | undefined, authorization?: (string | null) | undefined}; export type GetApiV1DefaultBanksBankIdGraphOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const memoryGraphNodeData = z.object({id: z.string(), label: z.string().optional(), text: z.string().optional(), date: z.string().optional(), context: z.string().optional(), entities: z.string().optional(), color: z.string().nullable().optional()}); export const memoryGraphNode = z.object({data: memoryGraphNodeData}); export const memoryGraphEdgeData = z.object({id: z.string(), source: z.string(), target: z.string(), linkType: z.string().optional(), weight: z.number().optional(), entityName: z.string().optional(), color: z.string().nullable().optional(), lineStyle: z.string().nullable().optional()}); export const memoryGraphEdge = z.object({data: memoryGraphEdgeData}); export const memoryGraphTableRow = z.object({id: z.string(), text: z.string().optional(), context: z.string().optional(), occurred_start: z.string().nullable().optional(), occurred_end: z.string().nullable().optional(), mentioned_at: z.string().nullable().optional(), date: z.string().nullable().optional(), entities: z.string().optional(), document_id: z.string().nullable().optional(), chunk_id: z.string().nullable().optional(), fact_type: z.string().nullable().optional(), tags: z.array(z.string()).optional(), created_at: z.string().nullable().optional(), proof_count: z.number().int().nullable().optional()}); export const graphDataResponse = z.object({nodes: z.array(memoryGraphNode), edges: z.array(memoryGraphEdge), table_rows: z.array(memoryGraphTableRow), total_units: z.number().int(), limit: z.number().int()}); 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 }; /** * Get memory graph data * * GET /v1/default/banks/{bank_id}/graph */ export const getApiV1DefaultBanksBankIdGraph = async (args: GetApiV1DefaultBanksBankIdGraphArgs, options: GetApiV1DefaultBanksBankIdGraphOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.type != null) query.append("type", String(args.type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.q != null) query.append("q", String(args.q)) for (const item of args.tags ?? []) query.append("tags", String(item)) if (args.tags_match != null) query.append("tags_match", String(args.tags_match)) if (args.document_id != null) query.append("document_id", String(args.document_id)) if (args.chunk_id != null) query.append("chunk_id", String(args.chunk_id)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/default/banks/${encodeURIComponent(String(args.bank_id))}/graph${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(graphDataResponse, await res.json()) };