table agents {
  id text [pk, not null]
  slug varchar(100)
  title varchar(255)
  description varchar(1000)
  tags jsonb [default: `[]`]
  editor_data jsonb
  avatar text
  background_color text
  market_identifier text
  plugins jsonb
  client_id text
  user_id text [not null]
  workspace_id text
  agency_config jsonb
  chat_config jsonb
  few_shots jsonb
  model text
  params jsonb [default: `{}`]
  provider text
  system_role text
  tts jsonb
  virtual boolean [default: false]
  pinned boolean
  opening_message text
  opening_questions text[] [default: `[]`]
  session_group_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'client_id_user_id_unique', unique]
    (slug, user_id) [name: 'agents_slug_user_id_unique', unique]
    user_id [name: 'agents_user_id_idx']
    title [name: 'agents_title_idx']
    description [name: 'agents_description_idx']
    session_group_id [name: 'agents_session_group_id_idx']
    workspace_id [name: 'agents_workspace_id_idx']
    (workspace_id, slug) [name: 'agents_slug_workspace_id_unique', unique]
  }
}

table agents_files {
  file_id text [not null]
  agent_id text [not null]
  enabled boolean [default: true]
  user_id text [not null]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (file_id, agent_id, user_id) [pk]
    agent_id [name: 'agents_files_agent_id_idx']
    file_id [name: 'agents_files_file_id_idx']
    user_id [name: 'agents_files_user_id_idx']
    workspace_id [name: 'agents_files_workspace_id_idx']
  }
}

table agents_knowledge_bases {
  agent_id text [not null]
  knowledge_base_id text [not null]
  user_id text [not null]
  workspace_id text
  enabled boolean [default: true]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (agent_id, knowledge_base_id) [pk]
    agent_id [name: 'agents_knowledge_bases_agent_id_idx']
    knowledge_base_id [name: 'agents_knowledge_bases_knowledge_base_id_idx']
    user_id [name: 'agents_knowledge_bases_user_id_idx']
    workspace_id [name: 'agents_knowledge_bases_workspace_id_idx']
  }
}

table agent_bot_providers {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  platform varchar(50) [not null]
  application_id varchar(255) [not null]
  credentials text
  settings jsonb [default: `{}`]
  enabled boolean [not null, default: true]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (platform, application_id) [name: 'agent_bot_providers_platform_app_id_unique', unique]
    platform [name: 'agent_bot_providers_platform_idx']
    agent_id [name: 'agent_bot_providers_agent_id_idx']
    user_id [name: 'agent_bot_providers_user_id_idx']
    workspace_id [name: 'agent_bot_providers_workspace_id_idx']
  }
}

table agent_cron_jobs {
  id text [pk, not null]
  agent_id text [not null]
  group_id text
  user_id text [not null]
  workspace_id text
  name text
  description text
  enabled boolean [default: true]
  cron_pattern text [not null]
  timezone text [default: 'UTC']
  content text [not null]
  edit_data jsonb
  max_executions integer
  remaining_executions integer
  execution_conditions jsonb
  last_executed_at timestamp
  total_executions integer [default: 0]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    agent_id [name: 'agent_cron_jobs_agent_id_idx']
    group_id [name: 'agent_cron_jobs_group_id_idx']
    user_id [name: 'agent_cron_jobs_user_id_idx']
    workspace_id [name: 'agent_cron_jobs_workspace_id_idx']
    enabled [name: 'agent_cron_jobs_enabled_idx']
    remaining_executions [name: 'agent_cron_jobs_remaining_executions_idx']
    last_executed_at [name: 'agent_cron_jobs_last_executed_at_idx']
    workspace_id [name: 'agent_cron_jobs_workspace_id_idx']
  }
}

table agent_documents {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  agent_id text [not null]
  document_id varchar(255) [not null]
  template_id varchar(100)
  access_self integer [not null, default: 31]
  access_shared integer [not null, default: 0]
  access_public integer [not null, default: 0]
  policy_load varchar(30) [not null, default: 'always']
  policy jsonb
  policy_load_position varchar(50) [not null, default: 'before-first-user']
  policy_load_format varchar(20) [not null, default: 'raw']
  policy_load_rule varchar(50) [not null, default: 'always']
  deleted_at "timestamp with time zone"
  deleted_by_user_id text
  deleted_by_agent_id text
  delete_reason text
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    workspace_id [name: 'agent_documents_workspace_id_idx']
    user_id [name: 'agent_documents_user_id_idx']
    agent_id [name: 'agent_documents_agent_id_idx']
    access_self [name: 'agent_documents_access_self_idx']
    access_shared [name: 'agent_documents_access_shared_idx']
    access_public [name: 'agent_documents_access_public_idx']
    policy_load [name: 'agent_documents_policy_load_idx']
    template_id [name: 'agent_documents_template_id_idx']
    policy_load_position [name: 'agent_documents_policy_load_position_idx']
    policy_load_format [name: 'agent_documents_policy_load_format_idx']
    policy_load_rule [name: 'agent_documents_policy_load_rule_idx']
    (agent_id, policy_load_position) [name: 'agent_documents_agent_load_position_idx']
    deleted_at [name: 'agent_documents_deleted_at_idx']
    (agent_id, deleted_at, policy_load) [name: 'agent_documents_agent_autoload_deleted_idx']
    document_id [name: 'agent_documents_document_id_idx']
    (agent_id, document_id, user_id) [name: 'agent_documents_agent_document_user_unique', unique]
  }
}

table agent_eval_benchmarks {
  id text [pk, not null]
  identifier text [not null]
  name text [not null]
  description text
  rubrics jsonb [not null]
  reference_url text
  metadata jsonb
  user_id text
  workspace_id text
  is_system boolean [not null, default: true]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (identifier, user_id) [name: 'agent_eval_benchmarks_identifier_user_id_unique', unique]
    is_system [name: 'agent_eval_benchmarks_is_system_idx']
    user_id [name: 'agent_eval_benchmarks_user_id_idx']
    workspace_id [name: 'agent_eval_benchmarks_workspace_id_idx']
    (workspace_id, identifier) [name: 'agent_eval_benchmarks_identifier_workspace_id_unique', unique]
  }
}

table agent_eval_datasets {
  id text [pk, not null]
  benchmark_id text [not null]
  source_experiment_id text
  identifier text [not null]
  user_id text
  workspace_id text
  name text [not null]
  description text
  eval_mode text
  eval_config jsonb
  metadata jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (identifier, user_id) [name: 'agent_eval_datasets_identifier_user_id_unique', unique]
    benchmark_id [name: 'agent_eval_datasets_benchmark_id_idx']
    source_experiment_id [name: 'agent_eval_datasets_source_experiment_id_idx']
    user_id [name: 'agent_eval_datasets_user_id_idx']
    workspace_id [name: 'agent_eval_datasets_workspace_id_idx']
    (workspace_id, identifier) [name: 'agent_eval_datasets_identifier_workspace_id_unique', unique]
  }
}

table agent_eval_experiment_benchmarks {
  experiment_id text [not null]
  benchmark_id text [not null]
  user_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (experiment_id, benchmark_id) [pk]
    benchmark_id [name: 'agent_eval_experiment_benchmarks_benchmark_id_idx']
    user_id [name: 'agent_eval_experiment_benchmarks_user_id_idx']
    workspace_id [name: 'agent_eval_experiment_benchmarks_workspace_id_idx']
  }
}

table agent_eval_experiments {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  name text [not null]
  description text
  metadata jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'agent_eval_experiments_user_id_idx']
    workspace_id [name: 'agent_eval_experiments_workspace_id_idx']
  }
}

table agent_eval_run_topics {
  user_id text [not null]
  workspace_id text
  run_id text [not null]
  topic_id text [not null]
  test_case_id text [not null]
  status text
  score real
  passed boolean
  eval_result jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (run_id, topic_id) [pk]
    user_id [name: 'agent_eval_run_topics_user_id_idx']
    run_id [name: 'agent_eval_run_topics_run_id_idx']
    test_case_id [name: 'agent_eval_run_topics_test_case_id_idx']
    workspace_id [name: 'agent_eval_run_topics_workspace_id_idx']
  }
}

table agent_eval_runs {
  id text [pk, not null]
  dataset_id text [not null]
  experiment_id text
  parent_run_id text
  target_agent_id text
  user_id text [not null]
  workspace_id text
  name text
  status text [not null, default: 'idle']
  config jsonb
  metrics jsonb
  started_at "timestamp with time zone"
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    
    dataset_id [name: 'agent_eval_runs_dataset_id_idx']
    experiment_id [name: 'agent_eval_runs_experiment_id_idx']
    parent_run_id [name: 'agent_eval_runs_parent_run_id_idx']
    user_id [name: 'agent_eval_runs_user_id_idx']
    status [name: 'agent_eval_runs_status_idx']
    target_agent_id [name: 'agent_eval_runs_target_agent_id_idx']
    workspace_id [name: 'agent_eval_runs_workspace_id_idx']
  }
}

table agent_eval_test_cases {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  dataset_id text [not null]
  content jsonb [not null]
  eval_mode text
  eval_config jsonb
  metadata jsonb
  sort_order integer
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'agent_eval_test_cases_user_id_idx']
    dataset_id [name: 'agent_eval_test_cases_dataset_id_idx']
    sort_order [name: 'agent_eval_test_cases_sort_order_idx']
    workspace_id [name: 'agent_eval_test_cases_workspace_id_idx']
  }
}

table agent_operations {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  agent_id text
  topic_id text
  thread_id text
  task_id text
  chat_group_id text
  parent_operation_id text
  status text [not null]
  completion_reason text
  verify_status text
  verify_plan jsonb
  verify_plan_confirmed_at "timestamp with time zone"
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  step_count integer
  max_steps integer
  force_finish boolean
  interruption jsonb
  error jsonb
  total_cost "numeric(20, 6)"
  currency text [not null, default: 'USD']
  total_input_tokens integer
  total_output_tokens integer
  total_tokens integer
  llm_calls integer
  tool_calls integer
  human_interventions integer
  processing_time_ms integer
  human_waiting_time_ms integer
  cost jsonb
  usage jsonb
  cost_limit jsonb
  model text
  provider text
  model_runtime_config jsonb
  trigger text
  app_context jsonb
  trace_s3_key text
  metadata jsonb [default: `{}`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'agent_operations_user_id_idx']
    workspace_id [name: 'agent_operations_workspace_id_idx']
    agent_id [name: 'agent_operations_agent_id_idx']
    topic_id [name: 'agent_operations_topic_id_idx']
    thread_id [name: 'agent_operations_thread_id_idx']
    task_id [name: 'agent_operations_task_id_idx']
    chat_group_id [name: 'agent_operations_chat_group_id_idx']
    parent_operation_id [name: 'agent_operations_parent_operation_id_idx']
    status [name: 'agent_operations_status_idx']
    (user_id, created_at) [name: 'agent_operations_user_id_created_at_idx']
    metadata [name: 'agent_operations_metadata_idx']
    workspace_id [name: 'agent_operations_workspace_id_idx']
  }
}

table agent_shares {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  visibility text [not null, default: 'private']
  share_config jsonb
  user_view_count integer [not null, default: 0]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    agent_id [name: 'agent_shares_agent_id_unique', unique]
    visibility [name: 'agent_shares_visibility_idx']
  }
}

table agent_skills {
  id text [pk, not null]
  name text [not null]
  description text [not null]
  identifier text [not null]
  source text [not null]
  manifest jsonb [not null, default: `{}`]
  content text
  editor_data jsonb
  resources jsonb [default: `{}`]
  zip_file_hash varchar(64)
  user_id text [not null]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, name) [name: 'agent_skills_user_name_idx', unique]
    identifier [name: 'agent_skills_identifier_idx']
    user_id [name: 'agent_skills_user_id_idx']
    source [name: 'agent_skills_source_idx']
    zip_file_hash [name: 'agent_skills_zip_hash_idx']
    workspace_id [name: 'agent_skills_workspace_id_idx']
    (workspace_id, name) [name: 'agent_skills_name_workspace_id_unique', unique]
  }
}

table ai_models {
  id varchar(150) [not null]
  "_id" uuid [default: `gen_random_uuid()`]
  display_name varchar(200)
  description text
  organization varchar(100)
  enabled boolean
  provider_id varchar(64) [not null]
  type varchar(20) [not null, default: 'chat']
  sort integer
  user_id text [not null]
  pricing jsonb
  parameters jsonb [default: `{}`]
  config jsonb
  abilities jsonb [default: `{}`]
  context_window_tokens integer
  source varchar(20)
  released_at varchar(10)
  settings jsonb [default: `{}`]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (id, provider_id, user_id) [name: 'ai_models_id_provider_id_user_id_unique', unique]
    (id, provider_id, user_id, workspace_id) [name: 'ai_models_id_provider_id_user_id_workspace_id_unique', unique]
    user_id [name: 'ai_models_user_id_idx']
    workspace_id [name: 'ai_models_workspace_id_idx']
  }
}

table ai_providers {
  id varchar(64) [not null]
  name text
  "_id" uuid [default: `gen_random_uuid()`]
  user_id text [not null]
  sort integer
  enabled boolean
  fetch_on_client boolean
  check_model text
  logo text
  description text
  key_vaults text
  source varchar(20)
  settings jsonb
  config jsonb
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (id, user_id) [name: 'ai_providers_id_user_id_unique', unique]
    (id, user_id, workspace_id) [name: 'ai_providers_id_user_id_workspace_id_unique', unique]
    user_id [name: 'ai_providers_user_id_idx']
    workspace_id [name: 'ai_providers_workspace_id_idx']
  }
}

table api_keys {
  id text [pk, not null]
  name varchar(256) [not null]
  key varchar(256) [not null, unique]
  key_hash varchar(128) [unique]
  enabled boolean [default: true]
  expires_at "timestamp with time zone"
  last_used_at "timestamp with time zone"
  user_id text [not null]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'api_keys_user_id_idx']
    workspace_id [name: 'api_keys_workspace_id_idx']
  }
}

table async_tasks {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  type text
  status text
  error jsonb
  inference_id text
  user_id text [not null]
  workspace_id text
  duration integer
  parent_id uuid
  metadata jsonb [not null, default: '{}']
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'async_tasks_user_id_idx']
    parent_id [name: 'async_tasks_parent_id_idx']
    (type, status) [name: 'async_tasks_type_status_idx']
    inference_id [name: 'async_tasks_inference_id_idx']
    metadata [name: 'async_tasks_metadata_idx']
    workspace_id [name: 'async_tasks_workspace_id_idx']
  }
}

table accounts {
  access_token text
  access_token_expires_at timestamp
  account_id text [not null]
  created_at timestamp [not null, default: `now()`]
  id text [pk, not null]
  id_token text
  password text
  provider_id text [not null]
  refresh_token text
  refresh_token_expires_at timestamp
  scope text
  updated_at timestamp [not null]
  user_id text [not null]

  indexes {
    user_id [name: 'account_userId_idx']
  }
}

table passkey {
  aaguid text
  backedUp boolean
  counter integer
  createdAt timestamp [default: `now()`]
  credentialID text [not null]
  deviceType text
  id text [pk, not null]
  name text
  publicKey text [not null]
  transports text
  userId text [not null]

  indexes {
    credentialID [name: 'passkey_credential_id_unique', unique]
    userId [name: 'passkey_user_id_idx']
  }
}

table auth_sessions {
  created_at timestamp [not null, default: `now()`]
  expires_at timestamp [not null]
  id text [pk, not null]
  impersonated_by text
  ip_address text
  token text [not null, unique]
  updated_at timestamp [not null]
  user_agent text
  user_id text [not null]

  indexes {
    user_id [name: 'auth_session_userId_idx']
  }
}

table two_factor {
  backup_codes text [not null]
  id text [pk, not null]
  secret text [not null]
  user_id text [not null]

  indexes {
    secret [name: 'two_factor_secret_idx']
    user_id [name: 'two_factor_user_id_idx']
  }
}

table verifications {
  created_at timestamp [not null, default: `now()`]
  expires_at timestamp [not null]
  id text [pk, not null]
  identifier text [not null]
  updated_at timestamp [not null, default: `now()`]
  value text [not null]

  indexes {
    identifier [name: 'verification_identifier_idx']
  }
}

table chat_groups {
  id text [pk, not null]
  title text
  description text
  avatar text
  background_color text
  market_identifier text
  content text
  editor_data jsonb
  config jsonb
  client_id text
  user_id text [not null]
  workspace_id text
  group_id text
  pinned boolean [default: false]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'chat_groups_client_id_user_id_unique', unique]
    user_id [name: 'chat_groups_user_id_idx']
    group_id [name: 'chat_groups_group_id_idx']
    workspace_id [name: 'chat_groups_workspace_id_idx']
  }
}

table chat_groups_agents {
  chat_group_id text [not null]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  enabled boolean [default: true]
  order integer [default: 0]
  role text [default: 'participant']
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (chat_group_id, agent_id) [pk]
    user_id [name: 'chat_groups_agents_user_id_idx']
    workspace_id [name: 'chat_groups_agents_workspace_id_idx']
  }
}

table user_connector_tools {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_connector_id uuid [not null]
  user_id text [not null]
  workspace_id text
  tool_name varchar(255) [not null]
  display_name varchar(255)
  description text
  input_schema jsonb
  output_schema jsonb
  crud_type text [not null]
  render_config jsonb
  permission text [not null]
  is_work_artifact boolean [not null, default: false]
  work_artifact_config jsonb
  limit_config jsonb
  metadata jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_connector_id, tool_name) [name: 'user_connector_tools_connector_tool_unique', unique]
    user_id [name: 'user_connector_tools_user_id_idx']
    user_connector_id [name: 'user_connector_tools_connector_id_idx']
    workspace_id [name: 'user_connector_tools_workspace_id_idx']
  }
}

table user_connectors {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  identifier varchar(255) [not null]
  name varchar(255) [not null]
  source_type text [not null]
  mcp_server_url text
  mcp_connection_type text
  mcp_stdio_config jsonb
  status text [not null]
  is_enabled boolean [not null, default: true]
  oidc_config jsonb
  credentials text
  token_expires_at "timestamp with time zone"
  metadata jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, identifier) [name: 'user_connectors_user_identifier_unique', unique]
    user_id [name: 'user_connectors_user_id_idx']
    token_expires_at [name: 'user_connectors_token_expires_at_idx']
    workspace_id [name: 'user_connectors_workspace_id_idx']
  }
}

table user_installed_plugins {
  user_id text [not null]
  workspace_id text
  identifier text [not null]
  type text [not null]
  manifest jsonb
  settings jsonb
  custom_params jsonb
  source varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, identifier) [pk]
    workspace_id [name: 'user_installed_plugins_workspace_id_idx']
  }
}

table devices {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  device_id varchar(64) [not null]
  identity_source varchar(20) [not null]
  hostname text
  platform varchar(20)
  friendly_name text
  default_cwd text
  recent_cwds text[] [not null, default: `[]`]
  working_dirs jsonb [default: `[]`]
  first_seen_at "timestamp with time zone" [not null, default: `now()`]
  last_seen_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, device_id) [name: 'devices_user_id_device_id_unique', unique]
    user_id [name: 'devices_user_id_idx']
    workspace_id [name: 'devices_workspace_id_idx']
  }
}

table document_histories {
  id varchar(255) [pk, not null]
  document_id varchar(255) [not null]
  user_id text [not null]
  workspace_id text
  editor_data jsonb [not null]
  save_source text [not null]
  saved_at "timestamp with time zone" [not null]

  indexes {
    document_id [name: 'document_histories_document_id_idx']
    user_id [name: 'document_histories_user_id_idx']
    workspace_id [name: 'document_histories_workspace_id_idx']
    saved_at [name: 'document_histories_saved_at_idx']
    workspace_id [name: 'document_histories_workspace_id_idx']
  }
}

table document_shares {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  document_id varchar(255) [not null]
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'private']
  permission text [not null, default: 'read']
  page_view_count integer [not null, default: 0]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    document_id [name: 'document_shares_document_id_unique', unique]
    user_id [name: 'document_shares_user_id_idx']
    workspace_id [name: 'document_shares_workspace_id_idx']
  }
}

table documents {
  id varchar(255) [pk, not null]
  title text
  description text
  content text
  file_type varchar(255) [not null]
  filename text
  total_char_count integer [not null]
  total_line_count integer [not null]
  metadata jsonb
  pages jsonb
  source_type text [not null]
  source text [not null]
  file_id text
  knowledge_base_id text
  parent_id varchar(255)
  user_id text [not null]
  client_id text
  editor_data jsonb
  slug varchar(255)
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    source [name: 'documents_source_idx']
    file_type [name: 'documents_file_type_idx']
    source_type [name: 'documents_source_type_idx']
    user_id [name: 'documents_user_id_idx']
    file_id [name: 'documents_file_id_idx']
    parent_id [name: 'documents_parent_id_idx']
    knowledge_base_id [name: 'documents_knowledge_base_id_idx']
    (client_id, user_id) [name: 'documents_client_id_user_id_unique', unique]
    (slug, user_id) [name: 'documents_slug_user_id_unique', unique]
    workspace_id [name: 'documents_workspace_id_idx']
    (workspace_id, slug) [name: 'documents_slug_workspace_id_unique', unique]
  }
}

table files {
  id text [pk, not null]
  user_id text [not null]
  file_type varchar(255) [not null]
  file_hash varchar(64)
  name text [not null]
  size integer [not null]
  url text [not null]
  source text
  parent_id varchar(255)
  client_id text
  metadata jsonb
  chunk_task_id uuid
  embedding_task_id uuid
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    file_hash [name: 'file_hash_idx']
    user_id [name: 'files_user_id_idx']
    parent_id [name: 'files_parent_id_idx']
    chunk_task_id [name: 'files_chunk_task_id_idx']
    embedding_task_id [name: 'files_embedding_task_id_idx']
    (client_id, user_id) [name: 'files_client_id_user_id_unique', unique]
    workspace_id [name: 'files_workspace_id_idx']
  }
}

table global_files {
  hash_id varchar(64) [pk, not null]
  file_type varchar(255) [not null]
  size integer [not null]
  url text [not null]
  metadata jsonb
  creator text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    creator [name: 'global_files_creator_idx']
  }
}

table knowledge_base_files {
  knowledge_base_id text [not null]
  file_id text [not null]
  user_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (knowledge_base_id, file_id) [pk]
    knowledge_base_id [name: 'knowledge_base_files_kb_id_idx']
    user_id [name: 'knowledge_base_files_user_id_idx']
    file_id [name: 'knowledge_base_files_file_id_idx']
    workspace_id [name: 'knowledge_base_files_workspace_id_idx']
  }
}

table knowledge_bases {
  id text [pk, not null]
  name text [not null]
  description text
  avatar text
  type text
  user_id text [not null]
  client_id text
  is_public boolean [default: false]
  settings jsonb
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'knowledge_bases_client_id_user_id_unique', unique]
    user_id [name: 'knowledge_bases_user_id_idx']
    workspace_id [name: 'knowledge_bases_workspace_id_idx']
  }
}

table generation_batches {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  generation_topic_id text [not null]
  provider text [not null]
  model text [not null]
  prompt text [not null]
  width integer
  height integer
  ratio varchar(64)
  config jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'generation_batches_user_id_idx']
    generation_topic_id [name: 'generation_batches_topic_id_idx']
    workspace_id [name: 'generation_batches_workspace_id_idx']
  }
}

table generation_topics {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  title text
  cover_url text
  type varchar(32) [not null, default: 'image']
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'generation_topics_user_id_idx']
    workspace_id [name: 'generation_topics_workspace_id_idx']
  }
}

table generations {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  generation_batch_id varchar(64) [not null]
  async_task_id uuid
  file_id text
  seed integer
  asset jsonb
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'generations_user_id_idx']
    generation_batch_id [name: 'generations_batch_id_idx']
    file_id [name: 'generations_file_id_idx']
    workspace_id [name: 'generations_workspace_id_idx']
  }
}

table llm_generation_tracing {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  scenario text [not null]
  prompt_version text [not null]
  prompt_hash text [not null]
  schema_name text
  user_id text [not null]
  agent_id text
  topic_id text
  workspace_id text
  trigger text
  parent_tracing_id uuid
  provider text
  model text
  success boolean [not null]
  error_code text
  error_detail text
  validation_failed boolean [not null, default: false]
  input_hash text
  input_hint text
  latency_ms integer
  input_tokens integer
  output_tokens integer
  cost_usd "numeric(12, 8)"
  storage_key text
  feedback_signal text
  feedback_score "numeric(3, 2)"
  feedback_source text
  feedback_data jsonb
  feedback_updated_at "timestamp with time zone"
  trace_id text
  span_id text
  metadata jsonb [default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    scenario [name: 'llm_generation_tracing_scenario_idx']
    prompt_version [name: 'llm_generation_tracing_prompt_version_idx']
    user_id [name: 'llm_generation_tracing_user_id_idx']
    agent_id [name: 'llm_generation_tracing_agent_id_idx']
    topic_id [name: 'llm_generation_tracing_topic_id_idx']
    workspace_id [name: 'llm_generation_tracing_workspace_id_idx']
    provider [name: 'llm_generation_tracing_provider_idx']
    model [name: 'llm_generation_tracing_model_idx']
    success [name: 'llm_generation_tracing_success_idx']
    error_code [name: 'llm_generation_tracing_error_code_idx']
    validation_failed [name: 'llm_generation_tracing_validation_failed_idx']
    feedback_signal [name: 'llm_generation_tracing_feedback_signal_idx']
    created_at [name: 'llm_generation_tracing_created_at_idx']
    workspace_id [name: 'llm_generation_tracing_workspace_id_idx']
  }
}

table message_chunks {
  message_id text
  chunk_id uuid
  user_id text [not null]
  workspace_id text

  indexes {
    (chunk_id, message_id) [pk]
    user_id [name: 'message_chunks_user_id_idx']
    message_id [name: 'message_chunks_message_id_idx']
    workspace_id [name: 'message_chunks_workspace_id_idx']
  }
}

table message_groups {
  id varchar(255) [pk, not null]
  topic_id text
  user_id text [not null]
  workspace_id text
  parent_group_id varchar(255)
  parent_message_id text
  title varchar(255)
  description text
  type text
  content text
  editor_data jsonb
  metadata jsonb
  client_id varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'message_groups_client_id_user_id_unique', unique]
    user_id [name: 'message_groups_user_id_idx']
    topic_id [name: 'message_groups_topic_id_idx']
    type [name: 'message_groups_type_idx']
    parent_group_id [name: 'message_groups_parent_group_id_idx']
    parent_message_id [name: 'message_groups_parent_message_id_idx']
    workspace_id [name: 'message_groups_workspace_id_idx']
  }
}

table message_plugins {
  id text [pk, not null]
  tool_call_id text
  type text [default: 'default']
  intervention jsonb
  api_name text
  arguments text
  identifier text
  state jsonb
  error jsonb
  client_id text
  user_id text [not null]
  workspace_id text

  indexes {
    (client_id, user_id) [name: 'message_plugins_client_id_user_id_unique', unique]
    user_id [name: 'message_plugins_user_id_idx']
    tool_call_id [name: 'message_plugins_tool_call_id_idx']
    workspace_id [name: 'message_plugins_workspace_id_idx']
  }
}

table message_queries {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  message_id text [not null]
  rewrite_query text
  user_query text
  client_id text
  user_id text [not null]
  workspace_id text
  embeddings_id uuid

  indexes {
    (client_id, user_id) [name: 'message_queries_client_id_user_id_unique', unique]
    user_id [name: 'message_queries_user_id_idx']
    message_id [name: 'message_queries_message_id_idx']
    embeddings_id [name: 'message_queries_embeddings_id_idx']
    workspace_id [name: 'message_queries_workspace_id_idx']
  }
}

table message_query_chunks {
  id text
  query_id uuid
  chunk_id uuid
  similarity "numeric(6, 5)"
  user_id text [not null]
  workspace_id text

  indexes {
    (chunk_id, id, query_id) [pk]
    user_id [name: 'message_query_chunks_user_id_idx']
    id [name: 'message_query_chunks_message_id_idx']
    query_id [name: 'message_query_chunks_query_id_idx']
    workspace_id [name: 'message_query_chunks_workspace_id_idx']
  }
}

table message_tts {
  id text [pk, not null]
  content_md5 text
  file_id text
  voice text
  client_id text
  user_id text [not null]
  workspace_id text

  indexes {
    (client_id, user_id) [name: 'message_tts_client_id_user_id_unique', unique]
    user_id [name: 'message_tts_user_id_idx']
    workspace_id [name: 'message_tts_workspace_id_idx']
  }
}

table message_translates {
  id text [pk, not null]
  content text
  from text
  to text
  client_id text
  user_id text [not null]
  workspace_id text

  indexes {
    (client_id, user_id) [name: 'message_translates_client_id_user_id_unique', unique]
    user_id [name: 'message_translates_user_id_idx']
    workspace_id [name: 'message_translates_workspace_id_idx']
  }
}

table messages {
  id text [pk, not null]
  role varchar(255) [not null]
  content text
  editor_data jsonb
  summary text
  reasoning jsonb
  search jsonb
  metadata jsonb
  usage jsonb
  model text
  provider text
  favorite boolean [default: false]
  error jsonb
  tools jsonb
  trace_id text
  observation_id text
  client_id text
  user_id text [not null]
  session_id text
  topic_id text
  thread_id text
  parent_id text
  quota_id text
  agent_id text
  group_id text
  target_id text
  message_group_id varchar(255)
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    created_at [name: 'messages_created_at_idx']
    (client_id, user_id) [name: 'message_client_id_user_unique', unique]
    topic_id [name: 'messages_topic_id_idx']
    parent_id [name: 'messages_parent_id_idx']
    quota_id [name: 'messages_quota_id_idx']
    user_id [name: 'messages_user_id_idx']
    session_id [name: 'messages_session_id_idx']
    thread_id [name: 'messages_thread_id_idx']
    agent_id [name: 'messages_agent_id_idx']
    group_id [name: 'messages_group_id_idx']
    message_group_id [name: 'messages_message_group_id_idx']
    () [name: 'messages_usage_cost_idx']
    () [name: 'messages_usage_total_tokens_idx']
    workspace_id [name: 'messages_workspace_id_idx']
  }
}

table messages_files {
  file_id text [not null]
  message_id text [not null]
  user_id text [not null]
  workspace_id text

  indexes {
    (file_id, message_id) [pk]
    user_id [name: 'messages_files_user_id_idx']
    message_id [name: 'messages_files_message_id_idx']
    workspace_id [name: 'messages_files_workspace_id_idx']
  }
}

table messenger_account_links {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  platform varchar(50) [not null]
  tenant_id varchar(255) [not null, default: '']
  platform_user_id varchar(255) [not null]
  platform_username text
  active_agent_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (platform, tenant_id, platform_user_id) [name: 'messenger_account_links_platform_tenant_user_unique', unique]
    (user_id, platform, tenant_id) [name: 'messenger_account_links_user_platform_tenant_unique', unique]
    active_agent_id [name: 'messenger_account_links_active_agent_idx']
    workspace_id [name: 'messenger_account_links_workspace_id_idx']
  }
}

table messenger_installations {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  platform varchar(50) [not null]
  tenant_id varchar(255) [not null]
  application_id varchar(255) [not null]
  account_id varchar(255)
  credentials text [not null]
  metadata jsonb [not null, default: `{}`]
  token_expires_at "timestamp with time zone"
  installed_by_user_id text
  installed_by_platform_user_id varchar(255)
  revoked_at "timestamp with time zone"
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (platform, application_id, tenant_id) [name: 'messenger_installations_platform_app_tenant_unique', unique]
    (platform, tenant_id) [name: 'messenger_installations_platform_tenant_idx']
    token_expires_at [name: 'messenger_installations_token_expires_at_idx']
  }
}

table nextauth_accounts {
  access_token text
  expires_at integer
  id_token text
  provider text [not null]
  providerAccountId text [not null]
  refresh_token text
  scope text
  session_state text
  token_type text
  type text [not null]
  user_id text [not null]

  indexes {
    (provider, providerAccountId) [pk]
    user_id [name: 'nextauth_accounts_user_id_idx']
  }
}

table nextauth_authenticators {
  counter integer [not null]
  credentialBackedUp boolean [not null]
  credentialDeviceType text [not null]
  credentialID text [not null, unique]
  credentialPublicKey text [not null]
  providerAccountId text [not null]
  transports text
  user_id text [not null]

  indexes {
    (user_id, credentialID) [pk]
  }
}

table nextauth_sessions {
  expires timestamp [not null]
  sessionToken text [pk, not null]
  user_id text [not null]

  indexes {
    user_id [name: 'nextauth_sessions_user_id_idx']
  }
}

table nextauth_verificationtokens {
  expires timestamp [not null]
  identifier text [not null]
  token text [not null]

  indexes {
    (identifier, token) [pk]
  }
}

table notification_deliveries {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  notification_id uuid [not null]
  channel text [not null]
  status text [not null]
  provider_message_id text
  failed_reason text
  sent_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    notification_id [name: 'idx_deliveries_notification']
    channel [name: 'idx_deliveries_channel']
    status [name: 'idx_deliveries_status']
  }
}

table notifications {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  category text [not null]
  type text [not null]
  title text [not null]
  content text [not null]
  dedupe_key text
  action_url text
  is_read boolean [not null, default: false]
  is_archived boolean [not null, default: false]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'idx_notifications_user']
    (user_id, created_at) [name: 'idx_notifications_user_active']
    user_id [name: 'idx_notifications_user_unread']
    (user_id, dedupe_key) [name: 'idx_notifications_dedupe', unique]
    (updated_at, created_at, id) [name: 'idx_notifications_archived_cleanup']
  }
}

table oauth_handoffs {
  id text [pk, not null]
  client varchar(50) [not null]
  payload jsonb [not null]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
}

table oidc_access_tokens {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  consumed_at "timestamp with time zone"
  user_id text [not null]
  client_id varchar(255) [not null]
  grant_id varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_access_tokens_user_id_idx']
  }
}

table oidc_authorization_codes {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  consumed_at "timestamp with time zone"
  user_id text [not null]
  client_id varchar(255) [not null]
  grant_id varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_authorization_codes_user_id_idx']
  }
}

table oidc_clients {
  id varchar(255) [pk, not null]
  name text [not null]
  description text
  client_secret varchar(255)
  redirect_uris text[] [not null]
  grants text[] [not null]
  response_types text[] [not null]
  scopes text[] [not null]
  token_endpoint_auth_method varchar(20)
  application_type varchar(20)
  client_uri text
  logo_uri text
  policy_uri text
  tos_uri text
  is_first_party boolean [default: false]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
}

table oidc_consents {
  user_id text [not null]
  client_id varchar(255) [not null]
  scopes text[] [not null]
  expires_at "timestamp with time zone"
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, client_id) [pk]
  }
}

table oidc_device_codes {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  consumed_at "timestamp with time zone"
  user_id text
  client_id varchar(255) [not null]
  grant_id varchar(255)
  user_code varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_device_codes_user_id_idx']
  }
}

table oidc_grants {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  consumed_at "timestamp with time zone"
  user_id text [not null]
  client_id varchar(255) [not null]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_grants_user_id_idx']
  }
}

table oidc_interactions {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
}

table oidc_refresh_tokens {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  consumed_at "timestamp with time zone"
  user_id text [not null]
  client_id varchar(255) [not null]
  grant_id varchar(255)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_refresh_tokens_user_id_idx']
  }
}

table oidc_sessions {
  id varchar(255) [pk, not null]
  data jsonb [not null]
  expires_at "timestamp with time zone" [not null]
  user_id text [not null]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'oidc_sessions_user_id_idx']
  }
}

table push_tokens {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  expo_token text [not null]
  device_id text [not null]
  platform text [not null]
  app_version text
  locale text
  created_at "timestamp with time zone" [not null, default: `now()`]
  last_seen_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, device_id) [name: 'idx_push_tokens_user_device', unique]
    user_id [name: 'idx_push_tokens_user']
    last_seen_at [name: 'idx_push_tokens_last_seen']
  }
}

table chunks {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  text text
  abstract text
  metadata jsonb
  index integer
  type varchar
  client_id text
  user_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'chunks_client_id_user_id_unique', unique]
    user_id [name: 'chunks_user_id_idx']
    workspace_id [name: 'chunks_workspace_id_idx']
  }
}

table document_chunks {
  document_id varchar(30) [not null]
  chunk_id uuid [not null]
  page_index integer
  user_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (document_id, chunk_id) [pk]
    document_id [name: 'document_chunks_document_id_idx']
    chunk_id [name: 'document_chunks_chunk_id_idx']
    user_id [name: 'document_chunks_user_id_idx']
    workspace_id [name: 'document_chunks_workspace_id_idx']
  }
}

table embeddings {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  chunk_id uuid [unique]
  embeddings vector(1024)
  model text
  client_id text
  user_id text
  workspace_id text

  indexes {
    (client_id, user_id) [name: 'embeddings_client_id_user_id_unique', unique]
    chunk_id [name: 'embeddings_chunk_id_idx']
    user_id [name: 'embeddings_user_id_idx']
    workspace_id [name: 'embeddings_workspace_id_idx']
  }
}

table unstructured_chunks {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  text text
  metadata jsonb
  index integer
  type varchar
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
  parent_id varchar
  composite_id uuid
  client_id text
  user_id text
  workspace_id text
  file_id varchar

  indexes {
    (client_id, user_id) [name: 'unstructured_chunks_client_id_user_id_unique', unique]
    user_id [name: 'unstructured_chunks_user_id_idx']
    composite_id [name: 'unstructured_chunks_composite_id_idx']
    file_id [name: 'unstructured_chunks_file_id_idx']
    workspace_id [name: 'unstructured_chunks_workspace_id_idx']
  }
}

table rag_eval_dataset_records {
  id text [pk, not null]
  dataset_id text [not null]
  ideal text
  question text
  reference_files text[]
  metadata jsonb
  user_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'rag_eval_dataset_records_user_id_idx']
    workspace_id [name: 'rag_eval_dataset_records_workspace_id_idx']
  }
}

table rag_eval_datasets {
  id text [pk, not null]
  description text
  name text [not null]
  knowledge_base_id text
  user_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'rag_eval_datasets_user_id_idx']
    workspace_id [name: 'rag_eval_datasets_workspace_id_idx']
  }
}

table rag_eval_evaluations {
  id text [pk, not null]
  name text [not null]
  description text
  eval_records_url text
  status text
  error jsonb
  dataset_id text [not null]
  knowledge_base_id text
  language_model text
  embedding_model text
  user_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'rag_eval_evaluations_user_id_idx']
    workspace_id [name: 'rag_eval_evaluations_workspace_id_idx']
  }
}

table rag_eval_evaluation_records {
  id text [pk, not null]
  question text [not null]
  answer text
  context text[]
  ideal text
  status text
  error jsonb
  language_model text
  embedding_model text
  question_embedding_id uuid
  duration integer
  dataset_record_id text [not null]
  evaluation_id text [not null]
  user_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'rag_eval_evaluation_records_user_id_idx']
    workspace_id [name: 'rag_eval_evaluation_records_workspace_id_idx']
  }
}

table rbac_permissions {
  id text [pk, not null]
  code text [not null, unique]
  name text [not null]
  description text
  category text [not null]
  is_active boolean [not null, default: true]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
}

table rbac_role_permissions {
  role_id text [not null]
  permission_id text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (role_id, permission_id) [pk]
    role_id [name: 'rbac_role_permissions_role_id_idx']
    permission_id [name: 'rbac_role_permissions_permission_id_idx']
  }
}

table rbac_roles {
  id text [pk, not null]
  name text [not null]
  display_name text [not null]
  description text
  is_system boolean [not null, default: false]
  is_active boolean [not null, default: true]
  metadata jsonb [default: `{}`]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    workspace_id [name: 'rbac_roles_workspace_id_idx']
    (name, workspace_id) [name: 'rbac_roles_name_workspace_unique', unique]
  }
}

table rbac_user_roles {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  role_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]
  expires_at "timestamp with time zone"

  indexes {
    (user_id, role_id, workspace_id) [name: 'rbac_user_roles_user_role_scope_unique', unique]
    user_id [name: 'rbac_user_roles_user_id_idx']
    role_id [name: 'rbac_user_roles_role_id_idx']
    workspace_id [name: 'rbac_user_roles_workspace_id_idx']
  }
}

table agents_to_sessions {
  agent_id text [not null]
  session_id text [not null]
  user_id text [not null]
  workspace_id text

  indexes {
    (agent_id, session_id) [pk]
    session_id [name: 'agents_to_sessions_session_id_idx']
    agent_id [name: 'agents_to_sessions_agent_id_idx']
    user_id [name: 'agents_to_sessions_user_id_idx']
    workspace_id [name: 'agents_to_sessions_workspace_id_idx']
  }
}

table file_chunks {
  file_id varchar
  chunk_id uuid
  created_at "timestamp with time zone" [not null, default: `now()`]
  user_id text [not null]
  workspace_id text

  indexes {
    (file_id, chunk_id) [pk]
    user_id [name: 'file_chunks_user_id_idx']
    workspace_id [name: 'file_chunks_workspace_id_idx']
    file_id [name: 'file_chunks_file_id_idx']
    chunk_id [name: 'file_chunks_chunk_id_idx']
    workspace_id [name: 'file_chunks_workspace_id_idx']
  }
}

table files_to_sessions {
  file_id text [not null]
  session_id text [not null]
  user_id text [not null]
  workspace_id text

  indexes {
    (file_id, session_id) [pk]
    user_id [name: 'files_to_sessions_user_id_idx']
    workspace_id [name: 'files_to_sessions_workspace_id_idx']
    file_id [name: 'files_to_sessions_file_id_idx']
    session_id [name: 'files_to_sessions_session_id_idx']
    workspace_id [name: 'files_to_sessions_workspace_id_idx']
  }
}

table session_groups {
  id text [pk, not null]
  name text [not null]
  sort integer
  user_id text [not null]
  client_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'session_groups_client_id_user_id_unique', unique]
    user_id [name: 'session_groups_user_id_idx']
    workspace_id [name: 'session_groups_workspace_id_idx']
  }
}

table sessions {
  id text [pk, not null]
  slug varchar(100) [not null]
  title text
  description text
  avatar text
  background_color text
  type text [default: 'agent']
  user_id text [not null]
  group_id text
  client_id text
  pinned boolean [default: false]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (slug, user_id) [name: 'slug_user_id_unique', unique]
    (client_id, user_id) [name: 'sessions_client_id_user_id_unique', unique]
    user_id [name: 'sessions_user_id_idx']
    (id, user_id) [name: 'sessions_id_user_id_idx']
    (user_id, updated_at) [name: 'sessions_user_id_updated_at_idx']
    group_id [name: 'sessions_group_id_idx']
    workspace_id [name: 'sessions_workspace_id_idx']
    (workspace_id, slug) [name: 'sessions_slug_workspace_id_unique', unique]
  }
}

table system_bot_providers {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  platform varchar(50) [not null]
  enabled boolean [not null, default: true]
  credentials text [not null]
  application_id varchar(255)
  settings jsonb [not null, default: `{}`]
  connection_mode varchar(20)
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    platform [name: 'system_bot_providers_platform_unique', unique]
  }
}

table briefs {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  task_id text
  cron_job_id text
  topic_id text
  agent_id text
  type text [not null]
  priority text [default: 'info']
  title text [not null]
  summary text [not null]
  artifacts jsonb
  actions jsonb
  resolved_action text
  resolved_comment text
  read_at "timestamp with time zone"
  resolved_at "timestamp with time zone"
  trigger varchar(255)
  metadata jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'briefs_user_id_idx']
    task_id [name: 'briefs_task_id_idx']
    cron_job_id [name: 'briefs_cron_job_id_idx']
    agent_id [name: 'briefs_agent_id_idx']
    type [name: 'briefs_type_idx']
    priority [name: 'briefs_priority_idx']
    (user_id, resolved_at) [name: 'briefs_unresolved_idx']
    trigger [name: 'briefs_trigger_idx']
    workspace_id [name: 'briefs_workspace_id_idx']
  }
}

table task_comments {
  id text [pk, not null]
  task_id text [not null]
  user_id text [not null]
  workspace_id text
  author_user_id text
  author_agent_id text
  content text [not null]
  editor_data jsonb
  brief_id text
  topic_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    task_id [name: 'task_comments_task_id_idx']
    user_id [name: 'task_comments_user_id_idx']
    author_user_id [name: 'task_comments_author_user_id_idx']
    author_agent_id [name: 'task_comments_agent_id_idx']
    brief_id [name: 'task_comments_brief_id_idx']
    topic_id [name: 'task_comments_topic_id_idx']
    workspace_id [name: 'task_comments_workspace_id_idx']
  }
}

table task_dependencies {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  task_id text [not null]
  depends_on_id text [not null]
  user_id text [not null]
  workspace_id text
  type text [not null, default: 'blocks']
  condition jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (task_id, depends_on_id) [name: 'task_deps_unique_idx', unique]
    task_id [name: 'task_deps_task_id_idx']
    depends_on_id [name: 'task_deps_depends_on_id_idx']
    user_id [name: 'task_deps_user_id_idx']
    workspace_id [name: 'task_dependencies_workspace_id_idx']
  }
}

table task_documents {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  task_id text [not null]
  document_id text [not null]
  user_id text [not null]
  workspace_id text
  pinned_by text [not null, default: 'agent']
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (task_id, document_id) [name: 'task_docs_unique_idx', unique]
    task_id [name: 'task_docs_task_id_idx']
    document_id [name: 'task_docs_document_id_idx']
    user_id [name: 'task_docs_user_id_idx']
    workspace_id [name: 'task_documents_workspace_id_idx']
  }
}

table task_topics {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  task_id text [not null]
  topic_id text
  user_id text [not null]
  workspace_id text
  seq integer [not null]
  operation_id text
  status text [not null, default: 'running']
  handoff jsonb
  review_passed integer
  review_score integer
  review_scores jsonb
  review_iteration integer
  reviewed_at "timestamp with time zone"
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (task_id, topic_id) [name: 'task_topics_unique_idx', unique]
    task_id [name: 'task_topics_task_id_idx']
    topic_id [name: 'task_topics_topic_id_idx']
    user_id [name: 'task_topics_user_id_idx']
    (task_id, status) [name: 'task_topics_status_idx']
    workspace_id [name: 'task_topics_workspace_id_idx']
  }
}

table tasks {
  id text [pk, not null]
  identifier text [not null]
  seq integer [not null]
  created_by_user_id text [not null]
  workspace_id text
  created_by_agent_id text
  assignee_user_id text
  assignee_agent_id text
  parent_task_id text
  name text
  description varchar(255)
  instruction text [not null]
  editor_data jsonb
  status text [not null, default: 'backlog']
  priority integer [default: 0]
  sort_order integer [default: 0]
  automation_mode text
  heartbeat_interval integer
  heartbeat_timeout integer
  last_heartbeat_at "timestamp with time zone"
  schedule_pattern text
  schedule_timezone text [default: 'UTC']
  total_topics integer [default: 0]
  max_topics integer
  current_topic_id text
  context jsonb [default: `{}`]
  config jsonb [default: `{}`]
  error text
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    
    (identifier, created_by_user_id) [name: 'tasks_identifier_idx', unique]
    created_by_user_id [name: 'tasks_created_by_user_id_idx']
    created_by_agent_id [name: 'tasks_created_by_agent_id_idx']
    assignee_user_id [name: 'tasks_assignee_user_id_idx']
    assignee_agent_id [name: 'tasks_assignee_agent_id_idx']
    parent_task_id [name: 'tasks_parent_task_id_idx']
    status [name: 'tasks_status_idx']
    priority [name: 'tasks_priority_idx']
    automation_mode [name: 'tasks_automation_mode_idx']
    (status, last_heartbeat_at) [name: 'tasks_heartbeat_idx']
    workspace_id [name: 'tasks_workspace_id_idx']
    (workspace_id, identifier) [name: 'tasks_identifier_workspace_id_unique', unique]
  }
}

table threads {
  id text [pk, not null]
  title text
  content text
  editor_data jsonb
  type text [not null]
  status text
  topic_id text [not null]
  source_message_id text
  parent_thread_id text
  client_id text
  agent_id text
  group_id text
  metadata jsonb
  user_id text [not null]
  last_active_at "timestamp with time zone" [default: `now()`]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'threads_client_id_user_id_unique', unique]
    user_id [name: 'threads_user_id_idx']
    topic_id [name: 'threads_topic_id_idx']
    type [name: 'threads_type_idx']
    agent_id [name: 'threads_agent_id_idx']
    group_id [name: 'threads_group_id_idx']
    parent_thread_id [name: 'threads_parent_thread_id_idx']
    workspace_id [name: 'threads_workspace_id_idx']
  }
}

table topic_documents {
  document_id text [not null]
  topic_id text [not null]
  user_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (document_id, topic_id) [pk]
    user_id [name: 'topic_documents_user_id_idx']
    topic_id [name: 'topic_documents_topic_id_idx']
    document_id [name: 'topic_documents_document_id_idx']
    workspace_id [name: 'topic_documents_workspace_id_idx']
  }
}

table topic_shares {
  id text [pk, not null]
  topic_id text [not null]
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'private']
  page_view_count integer [not null, default: 0]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    topic_id [name: 'topic_shares_topic_id_unique', unique]
    user_id [name: 'topic_shares_user_id_idx']
    workspace_id [name: 'topic_shares_workspace_id_idx']
  }
}

table topics {
  id text [pk, not null]
  title text
  favorite boolean [default: false]
  session_id text
  content text
  editor_data jsonb
  agent_id text
  group_id text
  user_id text [not null]
  client_id text
  description text
  history_summary text
  metadata jsonb
  trigger text
  mode text
  status text
  completed_at "timestamp with time zone"
  total_cost "numeric(20, 6)"
  total_input_tokens integer
  total_output_tokens integer
  total_tokens integer
  cost jsonb
  usage jsonb
  model text
  provider text
  sender_id text
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (client_id, user_id) [name: 'topics_client_id_user_id_unique', unique]
    user_id [name: 'topics_user_id_idx']
    (id, user_id) [name: 'topics_id_user_id_idx']
    session_id [name: 'topics_session_id_idx']
    group_id [name: 'topics_group_id_idx']
    agent_id [name: 'topics_agent_id_idx']
    trigger [name: 'topics_trigger_idx']
    status [name: 'topics_status_idx']
    model [name: 'topics_model_idx']
    provider [name: 'topics_provider_idx']
    (user_id, completed_at) [name: 'topics_user_id_completed_at_idx']
    sender_id [name: 'topics_sender_id_idx']
    workspace_id [name: 'topics_workspace_id_idx']
    () [name: 'topics_extract_status_gin_idx']
  }
}

table user_settings {
  id text [pk, not null]
  tts jsonb
  hotkey jsonb
  key_vaults text
  general jsonb
  language_model jsonb
  system_agent jsonb
  default_agent jsonb
  market jsonb
  memory jsonb
  tool jsonb
  image jsonb
  notification jsonb
}

table users {
  id text [pk, not null]
  username text [unique]
  email text [unique]
  normalized_email text [unique]
  avatar text
  phone text [unique]
  first_name text
  last_name text
  full_name text
  interests "varchar(64)[]"
  is_onboarded boolean [default: false]
  agent_onboarding jsonb
  onboarding jsonb
  clerk_created_at "timestamp with time zone"
  email_verified boolean [not null, default: false]
  email_verified_at "timestamp with time zone"
  preference jsonb
  role text
  banned boolean [default: false]
  ban_reason text
  ban_expires "timestamp with time zone"
  two_factor_enabled boolean [default: false]
  phone_number_verified boolean
  last_active_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    email [name: 'users_email_idx']
    username [name: 'users_username_idx']
    created_at [name: 'users_created_at_idx']
    created_at [name: 'users_banned_true_created_at_idx']
  }
}

table user_memories {
  id varchar(255) [pk, not null]
  user_id text
  memory_category varchar(255)
  memory_layer varchar(255)
  memory_type varchar(255)
  metadata jsonb
  tags text[]
  title varchar(255)
  summary text
  summary_vector_1024 vector(1024)
  details text
  details_vector_1024 vector(1024)
  status varchar(255)
  accessed_count bigint [default: 0]
  last_accessed_at "timestamp with time zone" [not null]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    summary_vector_1024 [name: 'user_memories_summary_vector_1024_index']
    details_vector_1024 [name: 'user_memories_details_vector_1024_index']
    user_id [name: 'user_memories_user_id_index']
  }
}

table user_memories_activities {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_id varchar(255)
  metadata jsonb
  tags text[]
  type varchar(255) [not null]
  status varchar(255) [not null, default: 'pending']
  timezone varchar(255)
  starts_at "timestamp with time zone"
  ends_at "timestamp with time zone"
  associated_objects jsonb
  associated_subjects jsonb
  associated_locations jsonb
  notes text
  narrative text
  narrative_vector vector(1024)
  feedback text
  feedback_vector vector(1024)
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    narrative_vector [name: 'user_memories_activities_narrative_vector_index']
    feedback_vector [name: 'user_memories_activities_feedback_vector_index']
    type [name: 'user_memories_activities_type_index']
    user_id [name: 'user_memories_activities_user_id_index']
    user_memory_id [name: 'user_memories_activities_user_memory_id_index']
    status [name: 'user_memories_activities_status_index']
  }
}

table user_memories_contexts {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_ids jsonb
  metadata jsonb
  tags text[]
  associated_objects jsonb
  associated_subjects jsonb
  title text
  description text
  description_vector vector(1024)
  type varchar(255)
  current_status text
  score_impact numeric [default: 0]
  score_urgency numeric [default: 0]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    description_vector [name: 'user_memories_contexts_description_vector_index']
    type [name: 'user_memories_contexts_type_index']
    user_id [name: 'user_memories_contexts_user_id_index']
  }
}

table user_memories_experiences {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_id varchar(255)
  metadata jsonb
  tags text[]
  type varchar(255)
  situation text
  situation_vector vector(1024)
  reasoning text
  possible_outcome text
  action text
  action_vector vector(1024)
  key_learning text
  key_learning_vector vector(1024)
  score_confidence real [default: 0]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    situation_vector [name: 'user_memories_experiences_situation_vector_index']
    action_vector [name: 'user_memories_experiences_action_vector_index']
    key_learning_vector [name: 'user_memories_experiences_key_learning_vector_index']
    type [name: 'user_memories_experiences_type_index']
    user_id [name: 'user_memories_experiences_user_id_index']
    user_memory_id [name: 'user_memories_experiences_user_memory_id_index']
  }
}

table user_memories_identities {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_id varchar(255)
  metadata jsonb
  tags text[]
  type varchar(255)
  description text
  description_vector vector(1024)
  episodic_date "timestamp with time zone"
  relationship varchar(255)
  role text
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    description_vector [name: 'user_memories_identities_description_vector_index']
    type [name: 'user_memories_identities_type_index']
    user_id [name: 'user_memories_identities_user_id_index']
    user_memory_id [name: 'user_memories_identities_user_memory_id_index']
  }
}

table user_memories_preferences {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_id varchar(255)
  metadata jsonb
  tags text[]
  conclusion_directives text
  conclusion_directives_vector vector(1024)
  type varchar(255)
  suggestions text
  score_priority numeric [default: 0]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    conclusion_directives_vector [name: 'user_memories_preferences_conclusion_directives_vector_index']
    user_id [name: 'user_memories_preferences_user_id_index']
    user_memory_id [name: 'user_memories_preferences_user_memory_id_index']
  }
}

table user_memory_persona_document_histories {
  id varchar(255) [pk, not null]
  user_id text
  persona_id varchar(255)
  profile varchar(255) [not null, default: 'default']
  snapshot_persona text
  snapshot_tagline text
  reasoning text
  diff_persona text
  diff_tagline text
  snapshot text
  summary text
  edited_by varchar(255) [default: 'agent']
  memory_ids jsonb
  source_ids jsonb
  metadata jsonb
  previous_version integer
  next_version integer
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    persona_id [name: 'user_persona_document_histories_persona_id_index']
    user_id [name: 'user_persona_document_histories_user_id_index']
    profile [name: 'user_persona_document_histories_profile_index']
  }
}

table user_memory_persona_documents {
  id varchar(255) [pk, not null]
  user_id text
  profile varchar(255) [not null, default: 'default']
  tagline text
  persona text
  memory_ids jsonb
  source_ids jsonb
  metadata jsonb
  version integer [not null, default: 1]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (user_id, profile) [name: 'user_persona_documents_user_id_profile_unique', unique]
    user_id [name: 'user_persona_documents_user_id_index']
  }
}

table verify_check_results {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  operation_id text [not null]
  user_id text [not null]
  workspace_id text
  check_item_id text [not null]
  check_item_title text
  required boolean [not null, default: true]
  check_item_index integer
  verifier_type text [not null]
  verifier_config_hash text
  verifier_operation_id text
  verifier_tracing_id uuid
  status text [not null, default: 'pending']
  verdict text
  confidence "numeric(3, 2)"
  toulmin jsonb
  suggestion text
  user_decision text
  is_false_positive boolean
  is_false_negative boolean
  repair_operation_id text
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    operation_id [name: 'verify_check_results_operation_id_idx']
    user_id [name: 'verify_check_results_user_id_idx']
    (operation_id, check_item_id) [name: 'verify_check_results_operation_id_check_item_id_unique', unique]
    verifier_type [name: 'verify_check_results_verifier_type_idx']
    verifier_operation_id [name: 'verify_check_results_verifier_operation_id_idx']
    verifier_tracing_id [name: 'verify_check_results_verifier_tracing_id_idx']
    status [name: 'verify_check_results_status_idx']
    verdict [name: 'verify_check_results_verdict_idx']
    repair_operation_id [name: 'verify_check_results_repair_operation_id_idx']
    workspace_id [name: 'verify_check_results_workspace_id_idx']
  }
}

table verify_criteria {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  title text [not null]
  description text
  required boolean [not null, default: true]
  verifier_type text [not null]
  verifier_config jsonb [default: `{}`]
  on_fail text [not null, default: 'manual']
  document_id varchar(255)
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'verify_criteria_user_id_idx']
    verifier_type [name: 'verify_criteria_verifier_type_idx']
    document_id [name: 'verify_criteria_document_id_idx']
    workspace_id [name: 'verify_criteria_workspace_id_idx']
  }
}

table verify_rubric_criteria {
  rubric_id uuid [not null]
  criterion_id uuid [not null]
  user_id text [not null]
  workspace_id text
  sort_order integer
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (rubric_id, criterion_id) [pk]
    criterion_id [name: 'verify_rubric_criteria_criterion_id_idx']
    user_id [name: 'verify_rubric_criteria_user_id_idx']
    workspace_id [name: 'verify_rubric_criteria_workspace_id_idx']
  }
}

table verify_rubrics {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  title text [not null]
  description text
  config jsonb [default: `{}`]
  workspace_id text
  accessed_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'verify_rubrics_user_id_idx']
    workspace_id [name: 'verify_rubrics_workspace_id_idx']
  }
}

table workspace_audit_logs {
  id text [pk, not null]
  workspace_id text [not null]
  user_id text
  action text [not null]
  resource_type text
  resource_id text
  metadata jsonb [default: `{}`]
  ip_address text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    workspace_id [name: 'workspace_audit_logs_workspace_id_idx']
    action [name: 'workspace_audit_logs_action_idx']
    created_at [name: 'workspace_audit_logs_created_at_idx']
  }
}

table workspace_invitations {
  id text [pk, not null]
  workspace_id text [not null]
  inviter_id text [not null]
  email text
  role text [not null, default: 'member']
  token text [not null, unique]
  status text [not null, default: 'pending']
  expires_at "timestamp with time zone" [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    workspace_id [name: 'workspace_invitations_workspace_id_idx']
    email [name: 'workspace_invitations_email_idx']
    token [name: 'workspace_invitations_token_idx']
  }
}

table workspace_members {
  workspace_id text [not null]
  user_id text [not null]
  role text [not null, default: 'member']
  joined_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]
  deleted_at "timestamp with time zone"

  indexes {
    (workspace_id, user_id) [pk]
    user_id [name: 'workspace_members_user_id_idx']
  }
}

table workspaces {
  id text [pk, not null]
  slug varchar(100) [not null]
  name varchar(255) [not null]
  description varchar(1000)
  avatar text
  primary_owner_id text [not null]
  settings jsonb [default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    slug [name: 'workspaces_slug_idx', unique]
    primary_owner_id [name: 'workspaces_primary_owner_id_idx']
  }
}

ref: agent_skills.user_id - users.id

ref: agent_skills.zip_file_hash - global_files.hash_id

ref: accounts.user_id > users.id

ref: passkey.userId > users.id

ref: auth_sessions.user_id > users.id

ref: two_factor.user_id > users.id

ref: agent_eval_datasets.benchmark_id > agent_eval_benchmarks.id

ref: agent_eval_datasets.user_id - users.id

ref: agent_eval_run_topics.run_id > agent_eval_runs.id

ref: agent_eval_run_topics.topic_id - topics.id

ref: agent_eval_run_topics.test_case_id > agent_eval_test_cases.id

ref: agent_eval_runs.dataset_id > agent_eval_datasets.id

ref: agent_eval_runs.target_agent_id - agents.id

ref: agent_eval_runs.user_id - users.id

ref: agent_eval_test_cases.dataset_id > agent_eval_datasets.id

ref: agents_files.file_id > files.id

ref: agents_files.agent_id > agents.id

ref: agents_knowledge_bases.knowledge_base_id - knowledge_bases.id

ref: agents_knowledge_bases.agent_id > agents.id

ref: agents.id - agent_shares.agent_id

ref: agents_to_sessions.session_id > sessions.id

ref: agents_to_sessions.agent_id > agents.id

ref: chat_groups_agents.chat_group_id > chat_groups.id

ref: chat_groups_agents.agent_id > agents.id

ref: chat_groups_agents.user_id - users.id

ref: chat_groups.user_id - users.id

ref: unstructured_chunks.file_id - files.id

ref: document_chunks.document_id > documents.id

ref: document_histories.document_id > documents.id

ref: document_histories.user_id - users.id

ref: documents.file_id > files.id

ref: file_chunks.file_id - files.id

ref: file_chunks.chunk_id - chunks.id

ref: generations.file_id - files.id

ref: files.embedding_task_id - async_tasks.id

ref: files_to_sessions.file_id > files.id

ref: files_to_sessions.session_id > sessions.id

ref: generation_batches.user_id - users.id

ref: generation_batches.generation_topic_id > generation_topics.id

ref: generation_topics.user_id - users.id

ref: generations.user_id - users.id

ref: generations.generation_batch_id > generation_batches.id

ref: generations.async_task_id - async_tasks.id

ref: message_groups.user_id - users.id

ref: message_groups.topic_id - topics.id

ref: message_groups.parent_group_id > message_groups.id

ref: messages_files.file_id > files.id

ref: messages_files.message_id > messages.id

ref: messages.id - message_translates.id

ref: messages.session_id - sessions.id

ref: messages.parent_id - messages.id

ref: messages.topic_id - topics.id

ref: threads.source_message_id - messages.id

ref: messages.message_group_id > message_groups.id

ref: sessions.group_id - session_groups.id

ref: topic_documents.document_id > documents.id

ref: topic_documents.topic_id > topics.id

ref: topics.session_id - sessions.id