import {z} from 'zod' export type Budget = 'low' | 'mid' | 'high'; export type TagGroupLeaf = {tags: Array, match?: ('any' | 'all' | 'any_strict' | 'all_strict' | 'exact') | undefined, resolve?: ('exact' | 'fuzzy') | undefined}; export type TagGroupNotInput = {not: TagGroupLeaf | TagGroupAndInput | TagGroupOrInput | TagGroupNotInput}; export type TagGroupOrInput = {or: Array}; export type TagGroupAndInput = {and: Array}; export type MentalModelTriggerInput = {budget?: (Budget | null) | undefined, mode?: ('full' | 'delta') | undefined, refresh_after_consolidation?: boolean | undefined, refresh_cron?: (string | null) | undefined, full_refresh_cron?: (string | null) | undefined, min_refresh_interval_seconds?: (number | null) | undefined, fact_types?: (Array<'world' | 'experience' | 'observation'> | null) | undefined, exclude_mental_models?: boolean | undefined, exclude_mental_model_ids?: (Array | null) | undefined, tags_match?: ('any' | 'all' | 'any_strict' | 'all_strict' | 'exact' | null) | undefined, tag_groups?: (Array | null) | undefined, include_chunks?: (boolean | null) | undefined, recall_max_tokens?: (number | null) | undefined, recall_chunks_max_tokens?: (number | null) | undefined, reflect_search_observations_max_tokens?: (number | null) | undefined, reflect_search_observations_include_entities?: (boolean | null) | undefined, response_schema?: ({[key: string]: unknown} | null) | undefined, keep_trace?: boolean | undefined}; export type CreateMentalModelRequest = {id?: (string | null) | undefined, name: string, source_query: string, tags?: Array | undefined, max_tokens?: number | undefined, trigger?: MentalModelTriggerInput | undefined}; export type CreateApiV1DefaultBanksBankIdMentalModelsArgs = {bank_id: string, authorization?: (string | null) | undefined, body: CreateMentalModelRequest}; export type CreateApiV1DefaultBanksBankIdMentalModelsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createMentalModelResponse = z.object({mental_model_id: z.string().nullable().optional(), operation_id: 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 }; /** * Create mental model * * POST /v1/default/banks/{bank_id}/mental-models */ export const createApiV1DefaultBanksBankIdMentalModels = async (args: CreateApiV1DefaultBanksBankIdMentalModelsArgs, options: CreateApiV1DefaultBanksBankIdMentalModelsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/default/banks/${encodeURIComponent(String(args.bank_id))}/mental-models${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(createMentalModelResponse, await res.json()) };