import {z} from 'zod' export type LabelValue = {value: string, description?: string | undefined}; export type MapFieldOutput = {type?: ('text' | 'multi-text' | 'value' | 'multi-values' | 'map') | undefined, description?: string | undefined, values?: Array | undefined, fields?: {[key: string]: MapFieldOutput} | undefined}; export type LabelGroupOutput = {key: string, description?: string | undefined, type?: ('value' | 'multi-values' | 'text' | 'multi-text' | 'map') | undefined, optional?: boolean | undefined, tag?: boolean | undefined, values?: Array | undefined, fields?: {[key: string]: MapFieldOutput} | undefined}; export type ConsolidationScopePattern = {tags?: Array | undefined, tags_match?: (string | null) | undefined}; export type ConsolidationStrategySpec = {scopes?: Array | undefined, observations_mission?: (string | null) | undefined, max_observations_per_scope?: (number | null) | undefined, consolidation_source_facts_max_tokens?: (number | null) | undefined, consolidation_source_facts_max_tokens_per_observation?: (number | null) | undefined}; export type BankTemplateConfig = {reflect_mission?: (string | null) | undefined, retain_mission?: (string | null) | undefined, retain_extraction_mode?: (string | null) | undefined, retain_custom_instructions?: (string | null) | undefined, retain_chunk_size?: (number | null) | undefined, retain_structured_chunk_size?: (number | null) | undefined, enable_observations?: (boolean | null) | undefined, observations_mission?: (string | null) | undefined, enable_text_search?: (boolean | null) | undefined, enable_temporal_retrieval?: (boolean | null) | undefined, enable_graph_retrieval?: (boolean | null) | undefined, enable_reranking?: (boolean | null) | undefined, reflect_use_decision_model?: (boolean | null) | undefined, mental_model_refresh_use_decision_model?: (boolean | null) | undefined, mental_model_delta_use_decision_model?: (boolean | null) | undefined, disposition_skepticism?: (number | null) | undefined, disposition_literalism?: (number | null) | undefined, disposition_empathy?: (number | null) | undefined, entity_labels?: (Array | null) | undefined, entities_allow_free_form?: (boolean | null) | undefined, retain_default_strategy?: (string | null) | undefined, retain_strategies?: ({[key: string]: unknown} | null) | undefined, retain_chunk_batch_size?: (number | null) | undefined, retain_max_attachments_per_chunk?: (number | null) | undefined, mcp_enabled_tools?: (Array | null) | undefined, consolidation_llm_batch_size?: (number | null) | undefined, consolidation_source_facts_max_tokens?: (number | null) | undefined, consolidation_source_facts_max_tokens_per_observation?: (number | null) | undefined, max_observations_per_scope?: (number | null) | undefined, observation_scope_limits?: (Array<{[key: string]: unknown}> | null) | undefined, default_observation_scopes?: ('per_tag' | 'combined' | 'all_combinations' | 'shared' | Array> | null) | undefined, consolidation_strategies?: (Array | null) | undefined, reflect_source_facts_max_tokens?: (number | null) | undefined, knowledge_page_default_trigger?: ({[key: string]: unknown} | null) | undefined, reflect_default_options?: ({[key: string]: unknown} | null) | undefined, mental_model_min_refresh_interval_seconds?: (number | null) | undefined, llm_gemini_safety_settings?: (Array | null) | undefined, recall_budget_function?: (string | null) | undefined, recall_budget_fixed_low?: (number | null) | undefined, recall_budget_fixed_mid?: (number | null) | undefined, recall_budget_fixed_high?: (number | null) | undefined, recall_budget_adaptive_low?: (number | null) | undefined, recall_budget_adaptive_mid?: (number | null) | undefined, recall_budget_adaptive_high?: (number | null) | undefined, recall_budget_min?: (number | null) | undefined, recall_budget_max?: (number | null) | undefined, audit_log_enabled?: (boolean | null) | undefined, store_document_text?: (boolean | null) | undefined, default_timezone?: (string | null) | undefined, enable_auto_consolidation?: (boolean | null) | undefined, consolidation_use_decision_model?: (boolean | null) | undefined, consolidation_max_memories_per_round?: (number | null) | undefined, consolidation_llm_parallelism?: (number | null) | undefined, recall_include_chunks?: (boolean | null) | undefined, recall_prefer_observations?: (boolean | null) | undefined, recall_decision_model_prune?: (boolean | null) | undefined, recall_decision_model_dedup?: (boolean | null) | undefined, recall_max_tokens?: (number | null) | undefined, recall_chunks_max_tokens?: (number | null) | undefined, memory_defense?: ({[key: string]: unknown} | null) | undefined}; 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 TagGroupNotOutput = {not: TagGroupLeaf | TagGroupAndOutput | TagGroupOrOutput | TagGroupNotOutput}; export type TagGroupOrOutput = {or: Array}; export type TagGroupAndOutput = {and: Array}; export type MentalModelTriggerOutput = {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 BankTemplateMentalModel = {id: string, name: string, source_query: string, tags?: Array | undefined, max_tokens?: number | undefined, trigger?: MentalModelTriggerOutput | undefined}; export type BankTemplateDirective = {name: string, content: string, priority?: number | undefined, is_active?: boolean | undefined, tags?: Array | undefined}; export type BankTemplateManifest = {version: string, bank?: (BankTemplateConfig | null) | undefined, mental_models?: (Array | null) | undefined, directives?: (Array | null) | undefined}; export type CreateApiV1DefaultBanksBankIdImportArgs = {bank_id: string, dry_run?: boolean | undefined, authorization?: (string | null) | undefined, body: BankTemplateManifest}; export type CreateApiV1DefaultBanksBankIdImportOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const bankTemplateImportResponse = z.object({bank_id: z.string(), config_applied: z.boolean(), mental_models_created: z.array(z.string()).optional(), mental_models_updated: z.array(z.string()).optional(), directives_created: z.array(z.string()).optional(), directives_updated: z.array(z.string()).optional(), operation_ids: z.array(z.string()).optional(), dry_run: z.boolean().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 }; /** * Import bank template * * POST /v1/default/banks/{bank_id}/import */ export const createApiV1DefaultBanksBankIdImport = async (args: CreateApiV1DefaultBanksBankIdImportArgs, options: CreateApiV1DefaultBanksBankIdImportOptions) => { 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.dry_run != null) query.append("dry_run", String(args.dry_run)) if (args.authorization != null) headers.set("authorization", String(args.authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/default/banks/${encodeURIComponent(String(args.bank_id))}/import${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(bankTemplateImportResponse, await res.json()) };