// This file is auto-generated by @hey-api/openapi-ts

import {
  type Client,
  formDataBodySerializer,
  type Options as Options2,
  type TDataShape,
} from "./client";
import { client } from "./client.gen";
import type {
  AddBankBackgroundData,
  AddBankBackgroundErrors,
  AddBankBackgroundResponses,
  AuditLogStatsData,
  AuditLogStatsErrors,
  AuditLogStatsResponses,
  CancelOperationData,
  CancelOperationErrors,
  CancelOperationResponses,
  ClearBankMemoriesData,
  ClearBankMemoriesErrors,
  ClearBankMemoriesResponses,
  ClearMemoryObservationsData,
  ClearMemoryObservationsErrors,
  ClearMemoryObservationsResponses,
  ClearObservationsData,
  ClearObservationsErrors,
  ClearObservationsResponses,
  CreateDirectiveData,
  CreateDirectiveErrors,
  CreateDirectiveResponses,
  CreateMentalModelData,
  CreateMentalModelErrors,
  CreateMentalModelResponses,
  CreateOrUpdateBankData,
  CreateOrUpdateBankErrors,
  CreateOrUpdateBankResponses,
  CreateWebhookData,
  CreateWebhookErrors,
  CreateWebhookResponses,
  DeleteBankData,
  DeleteBankErrors,
  DeleteBankResponses,
  DeleteDirectiveData,
  DeleteDirectiveErrors,
  DeleteDirectiveResponses,
  DeleteDocumentData,
  DeleteDocumentErrors,
  DeleteDocumentResponses,
  DeleteMentalModelData,
  DeleteMentalModelErrors,
  DeleteMentalModelResponses,
  DeleteWebhookData,
  DeleteWebhookErrors,
  DeleteWebhookResponses,
  ExportBankTemplateData,
  ExportBankTemplateErrors,
  ExportBankTemplateResponses,
  FileRetainData,
  FileRetainErrors,
  FileRetainResponses,
  GetAgentStatsData,
  GetAgentStatsErrors,
  GetAgentStatsResponses,
  GetBankConfigData,
  GetBankConfigErrors,
  GetBankConfigResponses,
  GetBankProfileData,
  GetBankProfileErrors,
  GetBankProfileResponses,
  GetBankTemplateSchemaData,
  GetBankTemplateSchemaResponses,
  GetChunkData,
  GetChunkErrors,
  GetChunkResponses,
  GetDirectiveData,
  GetDirectiveErrors,
  GetDirectiveResponses,
  GetDocumentData,
  GetDocumentErrors,
  GetDocumentResponses,
  GetEntityData,
  GetEntityErrors,
  GetEntityGraphData,
  GetEntityGraphErrors,
  GetEntityGraphResponses,
  GetEntityResponses,
  GetGraphData,
  GetGraphErrors,
  GetGraphResponses,
  GetMemoriesTimeseriesData,
  GetMemoriesTimeseriesErrors,
  GetMemoriesTimeseriesResponses,
  GetMemoryData,
  GetMemoryErrors,
  GetMemoryResponses,
  GetMentalModelData,
  GetMentalModelErrors,
  GetMentalModelHistoryData,
  GetMentalModelHistoryErrors,
  GetMentalModelHistoryResponses,
  GetMentalModelResponses,
  GetObservationHistoryData,
  GetObservationHistoryErrors,
  GetObservationHistoryResponses,
  GetOperationStatusData,
  GetOperationStatusErrors,
  GetOperationStatusResponses,
  GetVersionData,
  GetVersionResponses,
  HealthEndpointHealthGetData,
  HealthEndpointHealthGetResponses,
  ImportBankTemplateData,
  ImportBankTemplateErrors,
  ImportBankTemplateResponses,
  ListAuditLogsData,
  ListAuditLogsErrors,
  ListAuditLogsResponses,
  ListBanksData,
  ListBanksErrors,
  ListBanksResponses,
  ListDirectivesData,
  ListDirectivesErrors,
  ListDirectivesResponses,
  ListDocumentsData,
  ListDocumentsErrors,
  ListDocumentsResponses,
  ListEntitiesData,
  ListEntitiesErrors,
  ListEntitiesResponses,
  ListMemoriesData,
  ListMemoriesErrors,
  ListMemoriesResponses,
  ListMentalModelsData,
  ListMentalModelsErrors,
  ListMentalModelsResponses,
  ListOperationsData,
  ListOperationsErrors,
  ListOperationsResponses,
  ListTagsData,
  ListTagsErrors,
  ListTagsResponses,
  ListWebhookDeliveriesData,
  ListWebhookDeliveriesErrors,
  ListWebhookDeliveriesResponses,
  ListWebhooksData,
  ListWebhooksErrors,
  ListWebhooksResponses,
  MetricsEndpointMetricsGetData,
  MetricsEndpointMetricsGetResponses,
  RecallMemoriesData,
  RecallMemoriesErrors,
  RecallMemoriesResponses,
  RecoverConsolidationData,
  RecoverConsolidationErrors,
  RecoverConsolidationResponses,
  ReflectData,
  ReflectErrors,
  ReflectResponses,
  RefreshMentalModelData,
  RefreshMentalModelErrors,
  RefreshMentalModelResponses,
  RegenerateEntityObservationsData,
  RegenerateEntityObservationsErrors,
  RegenerateEntityObservationsResponses,
  ResetBankConfigData,
  ResetBankConfigErrors,
  ResetBankConfigResponses,
  RetainMemoriesData,
  RetainMemoriesErrors,
  RetainMemoriesResponses,
  RetryOperationData,
  RetryOperationErrors,
  RetryOperationResponses,
  TriggerConsolidationData,
  TriggerConsolidationErrors,
  TriggerConsolidationResponses,
  UpdateBankConfigData,
  UpdateBankConfigErrors,
  UpdateBankConfigResponses,
  UpdateBankData,
  UpdateBankDispositionData,
  UpdateBankDispositionErrors,
  UpdateBankDispositionResponses,
  UpdateBankErrors,
  UpdateBankResponses,
  UpdateDirectiveData,
  UpdateDirectiveErrors,
  UpdateDirectiveResponses,
  UpdateDocumentData,
  UpdateDocumentErrors,
  UpdateDocumentResponses,
  UpdateMentalModelData,
  UpdateMentalModelErrors,
  UpdateMentalModelResponses,
  UpdateWebhookData,
  UpdateWebhookErrors,
  UpdateWebhookResponses,
} from "./types.gen";

export type Options<
  TData extends TDataShape = TDataShape,
  ThrowOnError extends boolean = boolean,
> = Options2<TData, ThrowOnError> & {
  /**
   * You can provide a client instance returned by `createClient()` instead of
   * individual options. This might be also useful if you want to implement a
   * custom client.
   */
  client?: Client;
  /**
   * You can pass arbitrary values through the `meta` object. This can be
   * used to access values that aren't defined as part of the SDK function.
   */
  meta?: Record<string, unknown>;
};

/**
 * Health check endpoint
 *
 * Checks the health of the API and database connection
 */
export const healthEndpointHealthGet = <ThrowOnError extends boolean = false>(
  options?: Options<HealthEndpointHealthGetData, ThrowOnError>,
) =>
  (options?.client ?? client).get<
    HealthEndpointHealthGetResponses,
    unknown,
    ThrowOnError
  >({ url: "/health", ...options });

/**
 * Get API version and feature flags
 *
 * Returns API version information and enabled feature flags. Use this to check which capabilities are available in this deployment.
 */
export const getVersion = <ThrowOnError extends boolean = false>(
  options?: Options<GetVersionData, ThrowOnError>,
) =>
  (options?.client ?? client).get<GetVersionResponses, unknown, ThrowOnError>({
    url: "/version",
    ...options,
  });

/**
 * Prometheus metrics endpoint
 *
 * Exports metrics in Prometheus format for scraping
 */
export const metricsEndpointMetricsGet = <ThrowOnError extends boolean = false>(
  options?: Options<MetricsEndpointMetricsGetData, ThrowOnError>,
) =>
  (options?.client ?? client).get<
    MetricsEndpointMetricsGetResponses,
    unknown,
    ThrowOnError
  >({ url: "/metrics", ...options });

/**
 * Get memory graph data
 *
 * Retrieve graph data for visualization, optionally filtered by type (world/experience/opinion).
 */
export const getGraph = <ThrowOnError extends boolean = false>(
  options: Options<GetGraphData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetGraphResponses,
    GetGraphErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/graph", ...options });

/**
 * List memory units
 *
 * List memory units with pagination and optional full-text search. Supports filtering by type. Results are sorted by most recent first (mentioned_at DESC, then created_at DESC).
 */
export const listMemories = <ThrowOnError extends boolean = false>(
  options: Options<ListMemoriesData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListMemoriesResponses,
    ListMemoriesErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/memories/list", ...options });

/**
 * Get memory unit
 *
 * Get a single memory unit by ID with all its metadata including entities and tags. Note: the 'history' field is deprecated and always returns an empty list - use GET /memories/{memory_id}/history instead.
 */
export const getMemory = <ThrowOnError extends boolean = false>(
  options: Options<GetMemoryData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetMemoryResponses,
    GetMemoryErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/memories/{memory_id}", ...options });

/**
 * Get observation history
 *
 * Get the full history of an observation, with each change's source facts resolved to their text.
 */
export const getObservationHistory = <ThrowOnError extends boolean = false>(
  options: Options<GetObservationHistoryData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetObservationHistoryResponses,
    GetObservationHistoryErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/memories/{memory_id}/history",
    ...options,
  });

/**
 * Recall memory
 *
 * Recall memory using semantic similarity and spreading activation.
 *
 * The type parameter is optional and must be one of:
 * - `world`: General knowledge about people, places, events, and things that happen
 * - `experience`: Memories about experience, conversations, actions taken, and tasks performed
 */
export const recallMemories = <ThrowOnError extends boolean = false>(
  options: Options<RecallMemoriesData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RecallMemoriesResponses,
    RecallMemoriesErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/memories/recall",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Reflect and generate answer
 *
 * Reflect and formulate an answer using bank identity, world facts, and opinions.
 *
 * This endpoint:
 * 1. Retrieves experience (conversations and events)
 * 2. Retrieves world facts relevant to the query
 * 3. Retrieves existing opinions (bank's perspectives)
 * 4. Uses LLM to formulate a contextual answer
 * 5. Returns plain text answer and the facts used
 */
export const reflect = <ThrowOnError extends boolean = false>(
  options: Options<ReflectData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    ReflectResponses,
    ReflectErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/reflect",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * List all memory banks
 *
 * Get a list of all agents with their profiles
 */
export const listBanks = <ThrowOnError extends boolean = false>(
  options?: Options<ListBanksData, ThrowOnError>,
) =>
  (options?.client ?? client).get<
    ListBanksResponses,
    ListBanksErrors,
    ThrowOnError
  >({ url: "/v1/default/banks", ...options });

/**
 * Get statistics for memory bank
 *
 * Get statistics about nodes and links for a specific agent
 */
export const getAgentStats = <ThrowOnError extends boolean = false>(
  options: Options<GetAgentStatsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetAgentStatsResponses,
    GetAgentStatsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/stats", ...options });

/**
 * Memory ingestion time-series
 *
 * Memories ingested over a period, bucketed by time and broken down by fact type.
 */
export const getMemoriesTimeseries = <ThrowOnError extends boolean = false>(
  options: Options<GetMemoriesTimeseriesData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetMemoriesTimeseriesResponses,
    GetMemoriesTimeseriesErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/stats/memories-timeseries",
    ...options,
  });

/**
 * List entities
 *
 * List all entities (people, organizations, etc.) known by the bank, ordered by mention count. Supports pagination.
 */
export const listEntities = <ThrowOnError extends boolean = false>(
  options: Options<ListEntitiesData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListEntitiesResponses,
    ListEntitiesErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/entities", ...options });

/**
 * Get entity co-occurrence graph
 *
 * Return a graph of entities (nodes) and their co-occurrences (edges) for visualization.
 */
export const getEntityGraph = <ThrowOnError extends boolean = false>(
  options: Options<GetEntityGraphData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetEntityGraphResponses,
    GetEntityGraphErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/entities/graph", ...options });

/**
 * Get entity details
 *
 * Get detailed information about an entity including observations (mental model).
 */
export const getEntity = <ThrowOnError extends boolean = false>(
  options: Options<GetEntityData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetEntityResponses,
    GetEntityErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/entities/{entity_id}", ...options });

/**
 * Regenerate entity observations (deprecated)
 *
 * This endpoint is deprecated. Entity observations have been replaced by mental models.
 *
 * @deprecated
 */
export const regenerateEntityObservations = <
  ThrowOnError extends boolean = false,
>(
  options: Options<RegenerateEntityObservationsData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RegenerateEntityObservationsResponses,
    RegenerateEntityObservationsErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/entities/{entity_id}/regenerate",
    ...options,
  });

/**
 * List mental models
 *
 * List user-curated living documents that stay current.
 */
export const listMentalModels = <ThrowOnError extends boolean = false>(
  options: Options<ListMentalModelsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListMentalModelsResponses,
    ListMentalModelsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/mental-models", ...options });

/**
 * Create mental model
 *
 * Create a mental model by running reflect with the source query in the background. Returns an operation ID to track progress. The content is auto-generated by the reflect endpoint. Use the operations endpoint to check completion status.
 */
export const createMentalModel = <ThrowOnError extends boolean = false>(
  options: Options<CreateMentalModelData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    CreateMentalModelResponses,
    CreateMentalModelErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Delete mental model
 *
 * Delete a mental model.
 */
export const deleteMentalModel = <ThrowOnError extends boolean = false>(
  options: Options<DeleteMentalModelData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    DeleteMentalModelResponses,
    DeleteMentalModelErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
    ...options,
  });

/**
 * Get mental model
 *
 * Get a specific mental model by ID.
 */
export const getMentalModel = <ThrowOnError extends boolean = false>(
  options: Options<GetMentalModelData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetMentalModelResponses,
    GetMentalModelErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
    ...options,
  });

/**
 * Update mental model
 *
 * Update a mental model's name and/or source query.
 */
export const updateMentalModel = <ThrowOnError extends boolean = false>(
  options: Options<UpdateMentalModelData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateMentalModelResponses,
    UpdateMentalModelErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Get mental model history
 *
 * Get the refresh history of a mental model, showing content changes over time.
 */
export const getMentalModelHistory = <ThrowOnError extends boolean = false>(
  options: Options<GetMentalModelHistoryData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetMentalModelHistoryResponses,
    GetMentalModelHistoryErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}/history",
    ...options,
  });

/**
 * Refresh mental model
 *
 * Submit an async task to re-run the source query through reflect and update the content.
 */
export const refreshMentalModel = <ThrowOnError extends boolean = false>(
  options: Options<RefreshMentalModelData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RefreshMentalModelResponses,
    RefreshMentalModelErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/mental-models/{mental_model_id}/refresh",
    ...options,
  });

/**
 * List directives
 *
 * List hard rules that are injected into prompts.
 */
export const listDirectives = <ThrowOnError extends boolean = false>(
  options: Options<ListDirectivesData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListDirectivesResponses,
    ListDirectivesErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/directives", ...options });

/**
 * Create directive
 *
 * Create a hard rule that will be injected into prompts.
 */
export const createDirective = <ThrowOnError extends boolean = false>(
  options: Options<CreateDirectiveData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    CreateDirectiveResponses,
    CreateDirectiveErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/directives",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Delete directive
 *
 * Delete a directive.
 */
export const deleteDirective = <ThrowOnError extends boolean = false>(
  options: Options<DeleteDirectiveData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    DeleteDirectiveResponses,
    DeleteDirectiveErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
    ...options,
  });

/**
 * Get directive
 *
 * Get a specific directive by ID.
 */
export const getDirective = <ThrowOnError extends boolean = false>(
  options: Options<GetDirectiveData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetDirectiveResponses,
    GetDirectiveErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
    ...options,
  });

/**
 * Update directive
 *
 * Update a directive's properties.
 */
export const updateDirective = <ThrowOnError extends boolean = false>(
  options: Options<UpdateDirectiveData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateDirectiveResponses,
    UpdateDirectiveErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/directives/{directive_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * List documents
 *
 * List documents with pagination and optional search. Documents are the source content from which memory units are extracted.
 */
export const listDocuments = <ThrowOnError extends boolean = false>(
  options: Options<ListDocumentsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListDocumentsResponses,
    ListDocumentsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/documents", ...options });

/**
 * Delete a document
 *
 * Delete a document and all its associated memory units and links.
 *
 * This will cascade delete:
 * - The document itself
 * - All memory units extracted from this document
 * - All links (temporal, semantic, entity) associated with those memory units
 *
 * This operation cannot be undone.
 */
export const deleteDocument = <ThrowOnError extends boolean = false>(
  options: Options<DeleteDocumentData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    DeleteDocumentResponses,
    DeleteDocumentErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/documents/{document_id}", ...options });

/**
 * Get document details
 *
 * Get a specific document including its original text
 */
export const getDocument = <ThrowOnError extends boolean = false>(
  options: Options<GetDocumentData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetDocumentResponses,
    GetDocumentErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/documents/{document_id}", ...options });

/**
 * Update document
 *
 * Update mutable fields on a document without re-processing its content.
 *
 * **Tags** (`tags`): Propagated to all associated memory units. Observations derived from those units are invalidated and queued for re-consolidation under the new tags. Co-source memories from other documents that shared those observations are also reset.
 *
 * At least one field must be provided.
 */
export const updateDocument = <ThrowOnError extends boolean = false>(
  options: Options<UpdateDocumentData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateDocumentResponses,
    UpdateDocumentErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/documents/{document_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * List tags
 *
 * List all unique tags in a memory bank with usage counts. Supports wildcard search using '*' (e.g., 'user:*', '*-fred', 'tag*-2'). Case-insensitive.
 */
export const listTags = <ThrowOnError extends boolean = false>(
  options: Options<ListTagsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListTagsResponses,
    ListTagsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/tags", ...options });

/**
 * Get chunk details
 *
 * Get a specific chunk by its ID
 */
export const getChunk = <ThrowOnError extends boolean = false>(
  options: Options<GetChunkData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetChunkResponses,
    GetChunkErrors,
    ThrowOnError
  >({ url: "/v1/default/chunks/{chunk_id}", ...options });

/**
 * List async operations
 *
 * Get a list of async operations for a specific agent, with optional filtering by status and operation type. Results are sorted by most recent first.
 */
export const listOperations = <ThrowOnError extends boolean = false>(
  options: Options<ListOperationsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListOperationsResponses,
    ListOperationsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/operations", ...options });

/**
 * Cancel a pending async operation
 *
 * Cancel a pending async operation by removing it from the queue
 */
export const cancelOperation = <ThrowOnError extends boolean = false>(
  options: Options<CancelOperationData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    CancelOperationResponses,
    CancelOperationErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/operations/{operation_id}",
    ...options,
  });

/**
 * Get operation status
 *
 * Get the status of a specific async operation. Returns 'pending', 'completed', or 'failed'. Completed operations are removed from storage, so 'completed' means the operation finished successfully.
 */
export const getOperationStatus = <ThrowOnError extends boolean = false>(
  options: Options<GetOperationStatusData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetOperationStatusResponses,
    GetOperationStatusErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/operations/{operation_id}",
    ...options,
  });

/**
 * Retry a failed async operation
 *
 * Re-queue a failed async operation so the worker picks it up again
 */
export const retryOperation = <ThrowOnError extends boolean = false>(
  options: Options<RetryOperationData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RetryOperationResponses,
    RetryOperationErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/operations/{operation_id}/retry",
    ...options,
  });

/**
 * Get memory bank profile
 *
 * Get disposition traits and mission for a memory bank. Auto-creates agent with defaults if not exists.
 *
 * @deprecated
 */
export const getBankProfile = <ThrowOnError extends boolean = false>(
  options: Options<GetBankProfileData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetBankProfileResponses,
    GetBankProfileErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/profile", ...options });

/**
 * Update memory bank disposition
 *
 * Update bank's disposition traits (skepticism, literalism, empathy)
 *
 * @deprecated
 */
export const updateBankDisposition = <ThrowOnError extends boolean = false>(
  options: Options<UpdateBankDispositionData, ThrowOnError>,
) =>
  (options.client ?? client).put<
    UpdateBankDispositionResponses,
    UpdateBankDispositionErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/profile",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Add/merge memory bank background (deprecated)
 *
 * Deprecated: Use PUT /mission instead. This endpoint now updates the mission field.
 *
 * @deprecated
 */
export const addBankBackground = <ThrowOnError extends boolean = false>(
  options: Options<AddBankBackgroundData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    AddBankBackgroundResponses,
    AddBankBackgroundErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/background",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Delete memory bank
 *
 * Delete an entire memory bank including all memories, entities, documents, and the bank profile itself. This is a destructive operation that cannot be undone.
 */
export const deleteBank = <ThrowOnError extends boolean = false>(
  options: Options<DeleteBankData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    DeleteBankResponses,
    DeleteBankErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}", ...options });

/**
 * Partial update memory bank
 *
 * Partially update an agent's profile. Only provided fields will be updated.
 */
export const updateBank = <ThrowOnError extends boolean = false>(
  options: Options<UpdateBankData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateBankResponses,
    UpdateBankErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Create or update memory bank
 *
 * Create a new agent or update existing agent with disposition and mission. Auto-fills missing fields with defaults.
 */
export const createOrUpdateBank = <ThrowOnError extends boolean = false>(
  options: Options<CreateOrUpdateBankData, ThrowOnError>,
) =>
  (options.client ?? client).put<
    CreateOrUpdateBankResponses,
    CreateOrUpdateBankErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Import bank template
 *
 * Import a bank template manifest to create or update a bank's configuration, mental models, and directives. If the bank does not exist it is created. Config fields are applied as per-bank overrides. Mental models are matched by id, directives by name — existing ones are updated, new ones are created. Use dry_run=true to validate the manifest without applying changes.
 */
export const importBankTemplate = <ThrowOnError extends boolean = false>(
  options: Options<ImportBankTemplateData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    ImportBankTemplateResponses,
    ImportBankTemplateErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/import", ...options });

/**
 * Export bank template
 *
 * Export a bank's current configuration, mental models, and directives as a template manifest. The exported manifest can be imported into another bank to replicate the setup.
 */
export const exportBankTemplate = <ThrowOnError extends boolean = false>(
  options: Options<ExportBankTemplateData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ExportBankTemplateResponses,
    ExportBankTemplateErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/export", ...options });

/**
 * Get bank template JSON Schema
 *
 * Returns the JSON Schema for the bank template manifest format. Use this to validate template manifests before importing.
 */
export const getBankTemplateSchema = <ThrowOnError extends boolean = false>(
  options?: Options<GetBankTemplateSchemaData, ThrowOnError>,
) =>
  (options?.client ?? client).get<
    GetBankTemplateSchemaResponses,
    unknown,
    ThrowOnError
  >({ url: "/v1/bank-template-schema", ...options });

/**
 * Clear all observations
 *
 * Delete all observations for a memory bank. This is useful for resetting the consolidated knowledge.
 */
export const clearObservations = <ThrowOnError extends boolean = false>(
  options: Options<ClearObservationsData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    ClearObservationsResponses,
    ClearObservationsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/observations", ...options });

/**
 * Recover failed consolidation
 *
 * Reset all memories that were permanently marked as failed during consolidation (after exhausting all LLM retries and adaptive batch splitting) so they are picked up again on the next consolidation run. Does not delete any observations.
 */
export const recoverConsolidation = <ThrowOnError extends boolean = false>(
  options: Options<RecoverConsolidationData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RecoverConsolidationResponses,
    RecoverConsolidationErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/consolidation/recover", ...options });

/**
 * Clear observations for a memory
 *
 * Delete all observations derived from a specific memory and reset it for re-consolidation. The memory itself is not deleted. A consolidation job is triggered automatically so the memory will produce fresh observations on the next consolidation run.
 */
export const clearMemoryObservations = <ThrowOnError extends boolean = false>(
  options: Options<ClearMemoryObservationsData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    ClearMemoryObservationsResponses,
    ClearMemoryObservationsErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/memories/{memory_id}/observations",
    ...options,
  });

/**
 * Reset bank configuration
 *
 * Reset bank configuration to defaults by removing all bank-specific overrides. The bank will then use global and tenant-level configuration only.
 */
export const resetBankConfig = <ThrowOnError extends boolean = false>(
  options: Options<ResetBankConfigData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    ResetBankConfigResponses,
    ResetBankConfigErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/config", ...options });

/**
 * Get bank configuration
 *
 * Get fully resolved configuration for a bank including all hierarchical overrides (global → tenant → bank). The 'config' field contains all resolved config values. The 'overrides' field shows only bank-specific overrides.
 */
export const getBankConfig = <ThrowOnError extends boolean = false>(
  options: Options<GetBankConfigData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    GetBankConfigResponses,
    GetBankConfigErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/config", ...options });

/**
 * Update bank configuration
 *
 * Update configuration overrides for a bank. Only hierarchical fields can be overridden (LLM settings, retention parameters, etc.). Keys can be provided in Python field format (llm_provider) or environment variable format (HINDSIGHT_API_LLM_PROVIDER).
 */
export const updateBankConfig = <ThrowOnError extends boolean = false>(
  options: Options<UpdateBankConfigData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateBankConfigResponses,
    UpdateBankConfigErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/config",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Trigger consolidation
 *
 * Run memory consolidation to create/update observations from recent memories.
 */
export const triggerConsolidation = <ThrowOnError extends boolean = false>(
  options: Options<TriggerConsolidationData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    TriggerConsolidationResponses,
    TriggerConsolidationErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/consolidate", ...options });

/**
 * List webhooks
 *
 * List all webhooks registered for a bank.
 */
export const listWebhooks = <ThrowOnError extends boolean = false>(
  options: Options<ListWebhooksData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListWebhooksResponses,
    ListWebhooksErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/webhooks", ...options });

/**
 * Register webhook
 *
 * Register a webhook endpoint to receive event notifications for this bank.
 */
export const createWebhook = <ThrowOnError extends boolean = false>(
  options: Options<CreateWebhookData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    CreateWebhookResponses,
    CreateWebhookErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/webhooks",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Delete webhook
 *
 * Remove a registered webhook.
 */
export const deleteWebhook = <ThrowOnError extends boolean = false>(
  options: Options<DeleteWebhookData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    DeleteWebhookResponses,
    DeleteWebhookErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}", ...options });

/**
 * Update webhook
 *
 * Update one or more fields of a registered webhook. Only provided fields are changed.
 */
export const updateWebhook = <ThrowOnError extends boolean = false>(
  options: Options<UpdateWebhookData, ThrowOnError>,
) =>
  (options.client ?? client).patch<
    UpdateWebhookResponses,
    UpdateWebhookErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * List webhook deliveries
 *
 * Inspect delivery history for a webhook (useful for debugging).
 */
export const listWebhookDeliveries = <ThrowOnError extends boolean = false>(
  options: Options<ListWebhookDeliveriesData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListWebhookDeliveriesResponses,
    ListWebhookDeliveriesErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/webhooks/{webhook_id}/deliveries",
    ...options,
  });

/**
 * Clear memory bank memories
 *
 * Delete memory units for a memory bank. Optionally filter by type (world, experience, opinion) to delete only specific types. This is a destructive operation that cannot be undone. The bank profile (disposition and background) will be preserved.
 */
export const clearBankMemories = <ThrowOnError extends boolean = false>(
  options: Options<ClearBankMemoriesData, ThrowOnError>,
) =>
  (options.client ?? client).delete<
    ClearBankMemoriesResponses,
    ClearBankMemoriesErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/memories", ...options });

/**
 * Retain memories
 *
 * Retain memory items with automatic fact extraction.
 *
 * This is the main endpoint for storing memories. It supports both synchronous and asynchronous processing via the `async` parameter.
 *
 * **Features:**
 * - Efficient batch processing
 * - Automatic fact extraction from natural language
 * - Entity recognition and linking
 * - Document tracking with automatic upsert (when document_id is provided)
 * - Temporal and semantic linking
 * - Optional asynchronous processing
 *
 * **The system automatically:**
 * 1. Extracts semantic facts from the content
 * 2. Generates embeddings
 * 3. Deduplicates similar facts
 * 4. Creates temporal, semantic, and entity links
 * 5. Tracks document metadata
 *
 * **When `async=true`:** Returns immediately after queuing. Use the operations endpoint to monitor progress.
 *
 * **When `async=false` (default):** Waits for processing to complete.
 *
 * **Note:** If a memory item has a `document_id` that already exists, the old document and its memory units will be deleted before creating new ones (upsert behavior).
 */
export const retainMemories = <ThrowOnError extends boolean = false>(
  options: Options<RetainMemoriesData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    RetainMemoriesResponses,
    RetainMemoriesErrors,
    ThrowOnError
  >({
    url: "/v1/default/banks/{bank_id}/memories",
    ...options,
    headers: {
      "Content-Type": "application/json",
      ...options.headers,
    },
  });

/**
 * Convert files to memories
 *
 * Upload files (PDF, DOCX, etc.), convert them to markdown, and retain as memories.
 *
 * This endpoint handles file upload, conversion, and memory creation in a single operation.
 *
 * **Features:**
 * - Supports PDF, DOCX, PPTX, XLSX, images (with OCR), audio (with transcription)
 * - Automatic file-to-markdown conversion using pluggable parsers
 * - Files stored in object storage (PostgreSQL by default, S3 for production)
 * - Each file becomes a separate document with optional metadata/tags
 * - Always processes asynchronously — returns operation IDs immediately
 *
 * **The system automatically:**
 * 1. Stores uploaded files in object storage
 * 2. Converts files to markdown
 * 3. Creates document records with file metadata
 * 4. Extracts facts and creates memory units (same as regular retain)
 *
 * Use the operations endpoint to monitor progress.
 *
 * **Request format:** multipart/form-data with:
 * - `files`: One or more files to upload
 * - `request`: JSON string with FileRetainRequest model
 *
 * **Parser selection:**
 * - Set `parser` in the request body to override the server default for all files.
 * - Set `parser` inside a `files_metadata` entry for per-file control.
 * - Pass a list (e.g. `['iris', 'markitdown']`) to define an ordered fallback chain — each parser is tried in sequence until one succeeds.
 * - Falls back to the server default (`HINDSIGHT_API_FILE_PARSER`) if not specified.
 * - Only parsers enabled on the server may be requested; others return HTTP 400.
 */
export const fileRetain = <ThrowOnError extends boolean = false>(
  options: Options<FileRetainData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    FileRetainResponses,
    FileRetainErrors,
    ThrowOnError
  >({
    ...formDataBodySerializer,
    url: "/v1/default/banks/{bank_id}/files/retain",
    ...options,
    headers: {
      "Content-Type": null,
      ...options.headers,
    },
  });

/**
 * List audit logs
 *
 * List audit log entries for a bank, ordered by most recent first.
 */
export const listAuditLogs = <ThrowOnError extends boolean = false>(
  options: Options<ListAuditLogsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    ListAuditLogsResponses,
    ListAuditLogsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/audit-logs", ...options });

/**
 * Audit log statistics
 *
 * Get audit log counts grouped by time bucket for charting.
 */
export const auditLogStats = <ThrowOnError extends boolean = false>(
  options: Options<AuditLogStatsData, ThrowOnError>,
) =>
  (options.client ?? client).get<
    AuditLogStatsResponses,
    AuditLogStatsErrors,
    ThrowOnError
  >({ url: "/v1/default/banks/{bank_id}/audit-logs/stats", ...options });
