Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

210 KB
Raw Blame
table acceptance_comments {
  id text [pk, not null]
  acceptance_id uuid [not null]
  author_user_id text
  author_agent_id text
  workspace_id text
  parent_comment_id text
  kind text [not null, default: 'comment']
  anchor_type text [not null, default: 'acceptance']
  context_run_id uuid
  check_item_id text
  evidence_id uuid
  anchor_rect jsonb
  content text [not null]
  editor_data jsonb
  attachments jsonb
  source jsonb
  metadata jsonb
  review_mark_id uuid
  client_id text [not null]
  resolved_at "timestamp with time zone"
  resolved_by_user_id text
  deleted_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (acceptance_id, author_user_id, client_id) [name: 'acceptance_comments_acceptance_id_author_user_id_client_id_unique', unique]
    (acceptance_id, created_at, id) [name: 'acceptance_comments_acceptance_id_created_at_id_idx']
    parent_comment_id [name: 'acceptance_comments_parent_comment_id_idx']
    evidence_id [name: 'acceptance_comments_evidence_id_idx']
    author_user_id [name: 'acceptance_comments_author_user_id_idx']
    author_agent_id [name: 'acceptance_comments_author_agent_id_idx']
    workspace_id [name: 'acceptance_comments_workspace_id_idx']
    review_mark_id [name: 'acceptance_comments_review_mark_id_idx']
  }
}

table acceptance_flow_edges {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  flow_id uuid [not null]
  source_node_id uuid [not null]
  target_node_id uuid [not null]
  trigger text [not null]
  condition text
  required boolean [not null, default: true]

  indexes {
    
    
    (flow_id, source_node_id) [name: 'acceptance_flow_edges_source_idx']
    (flow_id, target_node_id) [name: 'acceptance_flow_edges_target_idx']
  }
}

table acceptance_flow_nodes {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  flow_id uuid [not null]
  criterion_id uuid
  sub_flow_id uuid
  is_entry boolean [not null, default: false]
  overrides jsonb

  indexes {
    
    sub_flow_id [name: 'acceptance_flow_nodes_sub_flow_idx']
    (flow_id, id) [name: 'acceptance_flow_nodes_flow_id_unique', unique]
    flow_id [name: 'acceptance_flow_nodes_entry_unique', unique]
    criterion_id [name: 'acceptance_flow_nodes_criterion_idx']
  }
}

table acceptance_flows {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  acceptance_id uuid [not null]
  title 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 {
    acceptance_id [name: 'acceptance_flows_acceptance_idx']
  }
}

table acceptance_review_marks {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  review_id uuid [not null]
  seq integer [not null]
  kind text [not null]
  url text [not null]
  route_key text [not null]
  page_meta jsonb
  rect_document jsonb [not null]
  rect_viewport jsonb [not null]
  scroll jsonb [not null]
  viewport jsonb [not null]
  regions jsonb
  region_refs jsonb
  targets jsonb
  sketch jsonb
  context jsonb
  screenshot_file_id text
  content text [not null]
  client_id text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (review_id, client_id) [name: 'acceptance_review_marks_review_id_client_id_unique', unique]
    (review_id, seq) [name: 'acceptance_review_marks_review_id_seq_unique', unique]
    (route_key, review_id) [name: 'acceptance_review_marks_route_key_review_id_idx']
  }
}

table acceptance_reviews {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  site_id text [not null]
  user_id text
  workspace_id text
  project_id text
  status text [not null, default: 'draft']
  task_id text
  last_mark_seq integer [not null, default: 0]
  submitted_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (site_id, created_at) [name: 'acceptance_reviews_site_id_created_at_idx']
    task_id [name: 'acceptance_reviews_task_id_idx']
    user_id [name: 'acceptance_reviews_user_id_idx']
    workspace_id [name: 'acceptance_reviews_workspace_id_idx']
    (site_id, user_id) [name: 'acceptance_reviews_one_draft_per_user_unique', unique]
  }
}

table agents {
  id text [pk, not null]
  slug varchar(100)
  title varchar(255)
  name varchar(255)
  description varchar(1000)
  tags jsonb [default: `[]`]
  editor_data jsonb
  avatar text
  background_color text
  market_identifier text
  metadata jsonb
  profile jsonb
  society_id 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
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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]
    created_at [name: 'agents_created_at_idx']
    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, visibility, user_id) [name: 'agents_workspace_visibility_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_accounts {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  kind text [not null]
  identifier text [not null]
  display_name text
  provider text [not null]
  status text [not null, default: 'provisioning']
  capabilities jsonb [not null]
  credentials text
  credential_hint jsonb
  metadata jsonb [default: `{}`]
  settings jsonb [not null, default: `{}`]
  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 {
    (agent_id, kind, provider, identifier) [name: 'agent_accounts_agent_kind_provider_identifier_unique', unique]
    (provider, identifier) [name: 'agent_accounts_provider_identifier_unique', unique]
    agent_id [name: 'agent_accounts_agent_id_idx']
    user_id [name: 'agent_accounts_user_id_idx']
    workspace_id [name: 'agent_accounts_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]
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
  }
}

table agent_deliveries {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  subject_type text [not null]
  subject_id text [not null]
  parent_delivery_id uuid
  requester_user_id text
  project_id text
  channel_id text
  task_id text
  title text
  summary text
  category text
  outcome text [not null, default: 'unknown']
  outcome_source text
  outcome_confidence real
  shots integer
  frictions jsonb
  total_cost "numeric(20, 6)"
  total_tokens integer
  tool_calls integer
  user_messages integer
  agent_messages integer
  duration_ms integer
  started_at "timestamp with time zone"
  delivered_at "timestamp with time zone"
  settled_at "timestamp with time zone"
  distilled_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 {
    (subject_type, subject_id, agent_id) [name: 'agent_deliveries_subject_agent_unique', unique]
    (agent_id, settled_at) [name: 'agent_deliveries_agent_id_settled_at_idx']
    (user_id, settled_at) [name: 'agent_deliveries_user_id_settled_at_idx']
    (workspace_id, settled_at) [name: 'agent_deliveries_workspace_id_settled_at_idx']
    parent_delivery_id [name: 'agent_deliveries_parent_delivery_id_idx']
    project_id [name: 'agent_deliveries_project_id_idx']
    task_id [name: 'agent_deliveries_task_id_idx']
  }
}

table agent_delivery_works {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  delivery_id uuid [not null]
  work_id text [not null]
  workspace_id text
  role text [not null]
  work_version_id uuid
  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 {
    (delivery_id, work_id) [name: 'agent_delivery_works_delivery_id_work_id_unique', unique]
    work_id [name: 'agent_delivery_works_work_id_idx']
    workspace_id [name: 'agent_delivery_works_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']
    deleted_by_user_id [name: 'agent_documents_deleted_by_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_memories {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  run_id text [not null]
  topic_id text
  thread_id text
  attempt_id text [not null]
  layer text [not null]
  source text [not null]
  fixture_hash text
  title text
  summary text
  details text
  memory_category text
  memory_type text
  tags jsonb
  payload jsonb [not null]
  embedding vector(1024)
  captured_at "timestamp with time zone" [not null]
  removed_reason 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 {
    attempt_id [name: 'agent_eval_memories_attempt_id_idx']
    run_id [name: 'agent_eval_memories_run_id_idx']
    topic_id [name: 'agent_eval_memories_topic_id_idx']
    thread_id [name: 'agent_eval_memories_thread_id_idx']
    user_id [name: 'agent_eval_memories_user_id_idx']
    workspace_id [name: 'agent_eval_memories_workspace_id_idx']
  }
}

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
  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_environments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text
  workspace_id text
  identifier text
  name text [not null]
  description text
  config jsonb [not null]
  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_environments_user_id_idx']
    workspace_id [name: 'agent_eval_environments_workspace_id_idx']
    (identifier, user_id) [name: 'agent_eval_environments_identifier_user_id_unique', unique]
    (identifier, workspace_id) [name: 'agent_eval_environments_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
  workspace_id text
  dataset_id text [not null]
  environment_id uuid
  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']
    environment_id [name: 'agent_eval_test_cases_environment_id_idx']
    sort_order [name: 'agent_eval_test_cases_sort_order_idx']
    workspace_id [name: 'agent_eval_test_cases_workspace_id_idx']
  }
}

table agent_history_job_agents {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  job_id text [not null]
  agent_id text [not null]

  indexes {
    (job_id, agent_id) [name: 'agent_history_job_agents_job_id_agent_id_unique', unique]
    agent_id [name: 'agent_history_job_agents_agent_id_idx']
  }
}

table agent_history_job_groups {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  job_id text [not null]
  group_id text [not null]

  indexes {
    (job_id, group_id) [name: 'agent_history_job_groups_job_id_group_id_unique', unique]
    group_id [name: 'agent_history_job_groups_group_id_idx']
  }
}

table agent_history_job_topics {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  job_id text [not null]
  topic_id text [not null]
  priority boolean [not null, default: false]
  activity_at "timestamp with time zone" [not null]
  payload jsonb

  indexes {
    (job_id, topic_id) [name: 'agent_history_job_topics_job_id_topic_id_unique', unique]
    topic_id [name: 'agent_history_job_topics_topic_id_idx']
    (job_id, priority, activity_at) [name: 'agent_history_job_topics_pick_idx']
  }
}

table agent_history_jobs {
  id text [pk, not null]
  status text [not null, default: 'pending']
  type text [not null, default: 'transfer']
  payload jsonb
  agent_ids jsonb [not null]
  session_ids jsonb [not null]
  group_ids jsonb [not null, default: `[]`]
  source_user_id text [not null]
  source_workspace_id text
  target_user_id text [not null]
  target_workspace_id text
  total_topics integer [not null]
  completed_topics integer [not null, default: 0]
  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 {
    status [name: 'agent_history_jobs_status_idx']
    source_user_id [name: 'agent_history_jobs_source_user_id_idx']
    target_user_id [name: 'agent_history_jobs_target_user_id_idx']
    source_workspace_id [name: 'agent_history_jobs_source_workspace_id_idx']
    target_workspace_id [name: 'agent_history_jobs_target_workspace_id_idx']
  }
}

table agent_inbox_messages {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  account_id uuid
  source_type text [not null]
  source_id uuid [not null]
  sender text [not null]
  title text
  preview text
  thread_key text
  received_at "timestamp with time zone" [not null]
  read_at "timestamp with time zone"
  topic_id text
  wake_claimed_at "timestamp with time zone"
  wait_consumed_by 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 {
    (source_type, source_id) [name: 'agent_inbox_messages_source_unique', unique]
    (agent_id, received_at) [name: 'agent_inbox_messages_agent_received_at_idx']
    (agent_id, created_at) [name: 'agent_inbox_messages_agent_created_at_idx']
    (account_id, created_at) [name: 'agent_inbox_messages_account_created_at_idx']
    (account_id, sender, created_at) [name: 'agent_inbox_messages_account_sender_created_at_idx']
    (account_id, thread_key) [name: 'agent_inbox_messages_account_thread_idx']
    topic_id [name: 'agent_inbox_messages_topic_id_idx']
    user_id [name: 'agent_inbox_messages_user_id_idx']
  }
}

table agent_intervention_resolutions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  resolution_request_id uuid [not null]
  operation_id text [not null]
  batch_id text [not null]
  source text [not null]
  user_id text [not null]
  workspace_id text
  actor_id text [not null]
  scope text [not null]
  selected_intervention_ids jsonb [not null]
  expected_versions jsonb [not null]
  expected_request_revision_hashes jsonb [not null]
  expected_item_count integer [not null]
  action jsonb [not null]
  custom_execution_input_hash varchar(64)
  custom_execution_state text
  custom_execution_attempt integer
  custom_execution_lease_token uuid
  custom_execution_lease_expires_at "timestamp with time zone"
  custom_execution_result jsonb
  remember_tool_key text
  remember_effect_status text
  original_arguments text
  edited_arguments text
  original_request_revision_hash text
  edited_request_revision_hash text
  argument_effect_status text
  status text [not null, default: 'resolving']
  resolving_at "timestamp with time zone" [not null, default: `now()`]
  published_at "timestamp with time zone"
  continuation_started_at "timestamp with time zone"
  producer_ack_at "timestamp with time zone"
  terminal_at "timestamp with time zone"
  rolled_back_at "timestamp with time zone"
  version integer [not null, default: 1]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    resolution_request_id [name: 'agent_intervention_resolutions_request_unique', unique]
    (user_id, workspace_id, batch_id) [name: 'agent_intervention_resolutions_owner_batch_idx']
    (status, created_at) [name: 'agent_intervention_resolutions_status_created_idx']
    
    
    
    
    
  }
}

table agent_interventions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  operation_id text [not null]
  tool_call_id text [not null]
  tool_message_id text
  user_id text [not null]
  workspace_id text
  source text [not null]
  provider text
  interaction_kind text [not null]
  surface text [not null]
  system_action_eligibility text [not null]
  approval_mode text
  batch_id text [not null]
  activity_key text [not null]
  step_index integer [not null]
  item_index integer [not null]
  item_count integer [not null]
  sealed boolean [not null, default: false]
  canonical_tool_key text
  request_revision_hash text [not null]
  allowed_actions jsonb [not null]
  risk jsonb
  review_token_hash text [not null]
  review_context jsonb [not null]
  sanitized_request jsonb [not null]
  deadline "timestamp with time zone" [not null]
  status text [not null, default: 'pending']
  resolution_id uuid
  resolving_at "timestamp with time zone"
  published_at "timestamp with time zone"
  resolved_at "timestamp with time zone"
  producer_ack_at "timestamp with time zone"
  version integer [not null, default: 1]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (operation_id, batch_id, tool_call_id) [name: 'agent_interventions_operation_batch_tool_call_unique', unique]
    review_token_hash [name: 'agent_interventions_review_token_hash_unique', unique]
    (operation_id, batch_id, item_index) [name: 'agent_interventions_operation_batch_item_unique', unique]
    (user_id, activity_key, item_index) [name: 'agent_interventions_owner_activity_item_unique', unique]
    (user_id, workspace_id, status, deadline) [name: 'agent_interventions_owner_status_deadline_idx']
    (user_id, workspace_id, batch_id, item_index) [name: 'agent_interventions_owner_batch_idx']
    (user_id, activity_key) [name: 'agent_interventions_activity_key_idx']
    (status, deadline) [name: 'agent_interventions_status_deadline_idx']
    
    
    
    
    
  }
}

table agent_label_assignments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  label_id uuid [not null]
  agent_id text [not null]
  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 {
    (label_id, agent_id) [name: 'agent_label_assignments_label_id_agent_id_unique', unique]
    agent_id [name: 'agent_label_assignments_agent_id_idx']
    user_id [name: 'agent_label_assignments_user_id_idx']
    workspace_id [name: 'agent_label_assignments_workspace_id_idx']
  }
}

table agent_labels {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  name text [not null]
  description text
  color text
  archived boolean [not null, default: false]
  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: 'agent_labels_user_id_idx']
    workspace_id [name: 'agent_labels_workspace_id_idx']
    (user_id, name) [name: 'agent_labels_user_id_name_unique', unique]
    (workspace_id, name) [name: 'agent_labels_workspace_id_name_unique', unique]
  }
}

table agent_mails {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  account_id uuid [not null]
  signal_id uuid
  direction text [not null]
  provider text [not null]
  provider_message_id text [not null]
  message_id text
  in_reply_to text
  references jsonb [not null, default: `[]`]
  thread_key text
  from_address text [not null]
  from_name text
  to jsonb [not null, default: `[]`]
  cc jsonb [not null, default: `[]`]
  reply_to jsonb [not null, default: `[]`]
  subject text
  text text [not null, default: '']
  attachments jsonb [not null, default: `[]`]
  codes jsonb [not null, default: `[]`]
  delivered_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()`]

  indexes {
    (account_id, provider_message_id) [name: 'agent_mails_account_provider_message_unique', unique]
    (account_id, thread_key) [name: 'agent_mails_account_thread_idx']
    (agent_id, delivered_at) [name: 'agent_mails_agent_delivered_at_idx']
    signal_id [name: 'agent_mails_signal_id_idx']
    user_id [name: 'agent_mails_user_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']
    created_at [name: 'agent_operations_running_created_at_idx']
    (user_id, created_at) [name: 'agent_operations_user_id_created_at_idx']
    (workspace_id, created_at) [name: 'agent_operations_workspace_id_created_at_idx']
    metadata [name: 'agent_operations_metadata_idx']
  }
}

table agent_account_bindings {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  account_id uuid [not null]
  user_id text [not null]
  workspace_id text
  role text [not null, default: 'pool']
  priority integer [not null, default: 0]
  weight integer [not null, default: 1]
  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 {
    (agent_id, account_id) [name: 'agent_account_bindings_agent_account_unique', unique]
    agent_id [name: 'agent_account_bindings_agent_pinned_unique', unique]
    agent_id [name: 'agent_account_bindings_agent_id_idx']
    account_id [name: 'agent_account_bindings_account_id_idx']
    user_id [name: 'agent_account_bindings_user_id_idx']
    workspace_id [name: 'agent_account_bindings_workspace_id_idx']
  }
}

table agent_device_account_bindings {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  agent_id text [not null]
  user_id text [not null]
  workspace_id text
  device_id uuid [not null]
  account_id uuid [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 {
    
    (agent_id, device_id) [name: 'agent_device_account_bindings_agent_device_unique', unique]
    device_id [name: 'agent_device_account_bindings_device_id_idx']
    (account_id, device_id) [name: 'agent_device_account_bindings_account_device_idx']
    user_id [name: 'agent_device_account_bindings_user_id_idx']
    workspace_id [name: 'agent_device_account_bindings_workspace_id_idx']
  }
}

table agent_provider_account_logins {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  account_id uuid [not null]
  device_id uuid [not null]
  user_id text [not null]
  workspace_id text
  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 {
    (account_id, device_id) [name: 'agent_provider_account_logins_account_device_unique', unique]
    device_id [name: 'agent_provider_account_logins_device_id_idx']
    user_id [name: 'agent_provider_account_logins_user_id_idx']
    workspace_id [name: 'agent_provider_account_logins_workspace_id_idx']
  }
}

table agent_provider_accounts {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'public']
  provider text [not null]
  external_account_id text
  email text
  display_name text
  organization_id text
  plan_tier text
  rate_limit_tier text
  label varchar(255)
  credential_mode text [not null, default: 'referenced']
  credentials text
  credential_ref jsonb
  token_expires_at "timestamp with time zone"
  status text [not null, default: 'active']
  enabled boolean [not null, default: true]
  last_validated_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 [name: 'agent_provider_accounts_user_id_idx']
    workspace_id [name: 'agent_provider_accounts_workspace_id_idx']
    (workspace_id, visibility, user_id) [name: 'agent_provider_accounts_workspace_visibility_idx']
    token_expires_at [name: 'agent_provider_accounts_token_expires_at_idx']
    (user_id, provider, external_account_id) [name: 'agent_provider_accounts_identity_unique', unique]
    (provider, external_account_id, workspace_id) [name: 'agent_provider_accounts_identity_workspace_unique', unique]
  }
}

table agent_quota_calibrations {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  account_id uuid [not null]
  user_id text [not null]
  workspace_id text
  limit_type text [not null]
  scope_key text [not null, default: '']
  capacity_usd "numeric(20, 6)" [not null]
  capacity_tokens_equivalent bigint
  model_mix jsonb
  sample_count integer [not null]
  confidence "numeric(20, 6)"
  method text
  window_seconds integer
  calibrated_at "timestamp with time zone" [not null, default: `now()`]
  metadata jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (account_id, limit_type, scope_key, calibrated_at) [name: 'agent_quota_calibrations_account_type_scope_idx']
    workspace_id [name: 'agent_quota_calibrations_workspace_id_idx']
    user_id [name: 'agent_quota_calibrations_user_id_idx']
  }
}

table agent_quota_snapshots {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  account_id uuid [not null]
  user_id text [not null]
  workspace_id text
  device_id uuid
  limit_type text [not null]
  scope_key text [not null, default: '']
  resets_at "timestamp with time zone"
  utilization integer [not null]
  severity text
  is_active boolean
  captured_at "timestamp with time zone" [not null, default: `now()`]
  raw jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (account_id, limit_type, scope_key, captured_at) [name: 'agent_quota_snapshots_account_type_scope_idx']
    (account_id, captured_at) [name: 'agent_quota_snapshots_account_captured_idx']
    resets_at [name: 'agent_quota_snapshots_resets_at_idx']
    workspace_id [name: 'agent_quota_snapshots_workspace_id_idx']
    user_id [name: 'agent_quota_snapshots_user_id_idx']
  }
}

table agent_quota_usage_ledger {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  account_id uuid
  user_id text [not null]
  workspace_id text
  provider text [not null]
  model text
  occurred_at "timestamp with time zone" [not null]
  input_tokens integer
  output_tokens integer
  cache_read_tokens integer
  cache_write_tokens integer
  reasoning_tokens integer
  cost_usd "numeric(20, 6)"
  cost_source text
  message_id text
  operation_id text
  topic_id text
  agent_id text
  external_event_id text
  metadata jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (account_id, occurred_at) [name: 'agent_quota_usage_ledger_account_occurred_idx']
    (account_id, model, occurred_at) [name: 'agent_quota_usage_ledger_account_model_occurred_idx']
    message_id [name: 'agent_quota_usage_ledger_message_id_idx']
    operation_id [name: 'agent_quota_usage_ledger_operation_id_idx']
    workspace_id [name: 'agent_quota_usage_ledger_workspace_id_idx']
    user_id [name: 'agent_quota_usage_ledger_user_id_idx']
    external_event_id [name: 'agent_quota_usage_ledger_external_event_unique', unique]
  }
}

table agent_quota_windows {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  account_id uuid [not null]
  user_id text [not null]
  workspace_id text
  limit_type text [not null]
  scope_key text [not null, default: '']
  resets_at "timestamp with time zone" [not null]
  window_start_at "timestamp with time zone" [not null]
  window_seconds integer [not null]
  peak_utilization integer [not null, default: 0]
  last_utilization integer
  rate_limited_at "timestamp with time zone"
  observed_cost_usd "numeric(20, 6)"
  observed_tokens bigint
  estimated_capacity_usd "numeric(20, 6)"
  contaminated boolean [not null, default: false]
  first_seen_at "timestamp with time zone"
  last_seen_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 {
    (account_id, limit_type, scope_key, resets_at) [name: 'agent_quota_windows_natural_key_unique', unique]
    (account_id, resets_at) [name: 'agent_quota_windows_account_resets_idx']
    user_id [name: 'agent_quota_windows_user_id_idx']
    workspace_id [name: 'agent_quota_windows_workspace_id_idx']
  }
}

table agent_share_grants {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  share_id uuid [not null]
  user_id text [not null]
  source jsonb [not null]
  revoked_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (share_id, user_id) [name: 'agent_share_grants_share_user_unique', unique]
    user_id [name: 'agent_share_grants_user_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]
  upstream jsonb
  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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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 [pk, not null, 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 [pk, not null, 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]
  scopes jsonb
  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 artboard_boards {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  artboard_id text [not null]
  page_id text [not null]
  group_id text
  round_id uuid
  user_id text [not null]
  workspace_id text
  project_id text
  acceptance_flow_node_id uuid
  type text [not null]
  title text [not null]
  description text
  expected text
  rect jsonb [not null]
  source_path 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 {
    
    artboard_id [name: 'artboard_boards_artboard_id_idx']
    page_id [name: 'artboard_boards_page_id_idx']
    group_id [name: 'artboard_boards_group_id_idx']
    round_id [name: 'artboard_boards_round_id_idx']
    project_id [name: 'artboard_boards_project_id_idx']
    acceptance_flow_node_id [name: 'artboard_boards_acceptance_flow_node_id_unique', unique]
    user_id [name: 'artboard_boards_user_id_idx']
    workspace_id [name: 'artboard_boards_workspace_id_idx']
  }
}

table artboard_comments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  artboard_id text [not null]
  parent_comment_id uuid
  author_user_id text
  author_agent_id text
  user_id text [not null]
  workspace_id text
  page_id text
  group_id text
  board_id uuid
  content text [not null]
  client_id text [not null]
  anchor jsonb
  delivered_at "timestamp with time zone"
  resolved_at "timestamp with time zone"
  resolved_by_user_id 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 {
    (artboard_id, author_user_id, client_id) [name: 'artboard_comments_artboard_id_author_user_id_client_id_unique', unique]
    (artboard_id, created_at) [name: 'artboard_comments_artboard_id_created_at_idx']
    parent_comment_id [name: 'artboard_comments_parent_comment_id_idx']
    board_id [name: 'artboard_comments_board_id_idx']
    user_id [name: 'artboard_comments_user_id_idx']
    workspace_id [name: 'artboard_comments_workspace_id_idx']
    page_id [name: 'artboard_comments_page_id_idx']
    group_id [name: 'artboard_comments_group_id_idx']
  }
}

table artboard_edges {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  artboard_id text [not null]
  source_board_id uuid [not null]
  target_board_id uuid [not null]
  user_id text [not null]
  workspace_id text
  acceptance_flow_edge_id uuid
  label text [not null, default: '']
  condition text
  is_default boolean [not null, default: false]
  sort_order integer [not null, default: 0]
  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 {
    artboard_id [name: 'artboard_edges_artboard_id_idx']
    source_board_id [name: 'artboard_edges_source_board_id_idx']
    source_board_id [name: 'artboard_edges_source_board_id_default_unique', unique]
    target_board_id [name: 'artboard_edges_target_board_id_idx']
    acceptance_flow_edge_id [name: 'artboard_edges_acceptance_flow_edge_id_unique', unique]
    user_id [name: 'artboard_edges_user_id_idx']
    workspace_id [name: 'artboard_edges_workspace_id_idx']
  }
}

table artboard_groups {
  id text [pk, not null]
  artboard_id text [not null]
  page_id text [not null]
  user_id text [not null]
  workspace_id text
  kind text [not null]
  title text [not null]
  description text
  rect jsonb [not null]
  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 {
    artboard_id [name: 'artboard_groups_artboard_id_idx']
    page_id [name: 'artboard_groups_page_id_idx']
    user_id [name: 'artboard_groups_user_id_idx']
    workspace_id [name: 'artboard_groups_workspace_id_idx']
  }
}

table artboard_pages {
  id text [pk, not null]
  artboard_id text [not null]
  user_id text [not null]
  workspace_id text
  name text [not null]
  sort_order integer [not null, default: 0]
  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 {
    artboard_id [name: 'artboard_pages_artboard_id_idx']
    user_id [name: 'artboard_pages_user_id_idx']
    workspace_id [name: 'artboard_pages_workspace_id_idx']
  }
}

table artboard_rounds {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  artboard_id text [not null]
  page_id text [not null]
  user_id text [not null]
  workspace_id text
  title text [not null]
  status text [not null, default: 'open']
  recommended_board_id uuid
  chosen_board_id uuid
  selected_by text
  selected_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 {
    artboard_id [name: 'artboard_rounds_artboard_id_idx']
    page_id [name: 'artboard_rounds_page_id_idx']
    user_id [name: 'artboard_rounds_user_id_idx']
    workspace_id [name: 'artboard_rounds_workspace_id_idx']
    recommended_board_id [name: 'artboard_rounds_recommended_board_id_idx']
    chosen_board_id [name: 'artboard_rounds_chosen_board_id_idx']
  }
}

table artboards {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  topic_id text
  task_id text
  project_id text
  acceptance_id uuid
  title text [not null]
  description text
  content text
  phase text [not null, default: 'discuss']
  revision integer [not null, default: 1]
  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: 'artboards_user_id_idx']
    workspace_id [name: 'artboards_workspace_id_idx']
    topic_id [name: 'artboards_topic_id_idx']
    task_id [name: 'artboards_task_id_idx']
    project_id [name: 'artboards_project_id_idx']
    phase [name: 'artboards_phase_idx']
    created_at [name: 'artboards_created_at_idx']
    updated_at [name: 'artboards_updated_at_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 channel_agent_grants {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  member_id uuid [not null]
  owner_id text [not null]
  grantee_member_id uuid
  thread_id text
  requested_by_member_id uuid
  status text [not null, default: 'pending']
  decided_at "timestamp with time zone"
  revoked_at "timestamp with time zone"
  revoke_reason text
  metadata jsonb [default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (member_id, grantee_member_id, thread_id) [name: 'channel_agent_grants_live_scope_unique', unique]
    (owner_id, status) [name: 'channel_agent_grants_owner_status_idx']
    grantee_member_id [name: 'channel_agent_grants_grantee_idx']
    
    
    
    
  }
}

table channel_audit {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  event text [not null]
  target_id text [not null]
  details jsonb [not null, default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (channel_id, event, created_at) [name: 'channel_audit_channel_event_idx']
    (target_id, event, created_at) [name: 'channel_audit_target_event_idx']
  }
}

table channel_jobs {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  member_id uuid [not null]
  message_id uuid [not null]
  thread_id text
  requester_member_id uuid [not null]
  status text [not null, default: 'queued']
  blocked_reason text
  blocked_code text
  claimed_at "timestamp with time zone"
  topic_id text
  operation_id text [unique]
  wake jsonb
  manifest jsonb
  execution_config jsonb
  device_id varchar(64)
  working_directory text
  accepted_at "timestamp with time zone"
  lease_owner text
  lease_expires_at "timestamp with time zone"
  writer_held boolean [not null, default: false]
  isolated_at "timestamp with time zone"
  draft text
  ask jsonb
  publication_revoked boolean [not null, default: false]
  published_message_id uuid
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (channel_id, id) [name: 'channel_jobs_scope_unique', unique]
    (message_id, member_id) [name: 'channel_jobs_delivery_unique', unique]
    (channel_id, status) [name: 'channel_jobs_channel_status_idx']
    (member_id, requester_member_id, thread_id, claimed_at) [name: 'channel_jobs_continuation_idx']
    (topic_id, published_message_id) [name: 'channel_jobs_topic_idx']
    (member_id, status, created_at) [name: 'channel_jobs_member_queue_idx']
    lease_expires_at [name: 'channel_jobs_lease_expires_idx']
    (device_id, working_directory) [name: 'channel_jobs_active_directory_idx']
    
    
    
    
  }
}

table channel_member_grants {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  member_id uuid [not null]
  device_owner_id text [not null]
  device_id varchar(64) [not null]
  working_directory text [not null]
  requested_by_member_id uuid [not null]
  status text [not null, default: 'pending']
  decided_at "timestamp with time zone"
  revoked_at "timestamp with time zone"
  revoke_reason text
  metadata jsonb [default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    member_id [name: 'channel_member_grants_member_unique', unique]
    (device_owner_id, status) [name: 'channel_member_grants_owner_status_idx']
    
    
  }
}

table channel_members {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  actor_type text [not null]
  user_id text
  role text
  last_read_sequence integer
  section_id uuid
  pinned boolean [not null, default: false]
  hidden boolean [not null, default: false]
  pinned_at "timestamp with time zone"
  agent_id text
  name text
  description text [not null, default: '']
  config jsonb
  metadata jsonb [default: `{}`]
  status text [not null, default: 'active']
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (channel_id, id) [name: 'channel_members_scope_unique', unique]
    (channel_id, user_id) [name: 'channel_members_channel_user_unique', unique]
    user_id [name: 'channel_members_user_id_idx']
    section_id [name: 'channel_members_section_id_idx']
    agent_id [name: 'channel_members_agent_id_idx']
    
    
    
    
    
    
    
    
  }
}

table channel_message_files {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  message_id uuid [not null]
  file_id text [not null]
  sort_order integer [not null]

  indexes {
    (message_id, file_id) [name: 'channel_message_files_message_file_unique', unique]
    file_id [name: 'channel_message_files_file_idx']
  }
}

table channel_messages {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  channel_id text [not null]
  thread_id text
  sequence integer [not null]
  kind text [not null, default: 'text']
  content text [not null]
  user_id text
  agent_id text
  mentions jsonb [not null, default: `[]`]
  request_key text [not null]
  reply_to_id uuid
  routing_status text [not null]
  routing_source text
  routing_reason text
  routing_attempt integer [not null, default: 0]
  recipient_member_ids jsonb [not null, default: `[]`]
  metadata jsonb [default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (channel_id, id) [name: 'channel_messages_scope_unique', unique]
    (channel_id, sequence) [name: 'channel_messages_sequence_unique', unique]
    (channel_id, request_key) [name: 'channel_messages_request_key_unique', unique]
    (channel_id, thread_id, sequence) [name: 'channel_messages_thread_sequence_idx']
    (channel_id, thread_id, sequence) [name: 'channel_messages_request_sequence_idx']
    (channel_id, id) [name: 'channel_messages_routing_pending_idx']
    
    
    
  }
}

table channel_sections {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  name text [not null]
  sort integer
  collapsed 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, workspace_id) [name: 'channel_sections_user_id_workspace_id_idx']
  }
}

table channel_threads {
  id text [pk, not null]
  channel_id text [not null]
  root_message_id uuid [not null]
  root_sequence integer [not null]
  follower_member_ids jsonb [not null, default: `[]`]
  status text [not null, default: 'active']
  metadata jsonb [default: `{}`]
  deleted_at "timestamp with time zone"
  is_deleted boolean
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (channel_id, id) [name: 'channel_threads_scope_unique', unique]
    (channel_id, root_message_id) [name: 'channel_threads_root_unique', unique]
    
  }
}

table channels {
  id text [pk, not null]
  user_id text
  workspace_id text
  project_id text
  agent_id text
  peer_user_id text
  agent_pair_key text
  title text [not null]
  sequence integer [not null, default: 0]
  status text [not null, default: 'active']
  visibility text [not null, default: 'private']
  config jsonb
  metadata jsonb [default: `{}`]
  deleted_at "timestamp with time zone"
  is_deleted boolean
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'channels_user_id_idx']
    (agent_id, user_id, workspace_id) [name: 'channels_direct_unique', unique]
    (agent_pair_key, user_id, workspace_id) [name: 'channels_agent_pair_unique', unique]
    
    project_id [name: 'channels_project_id_idx']
    (workspace_id, visibility) [name: 'channels_workspace_visibility_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]
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (workspace_id, visibility, user_id) [name: 'chat_groups_workspace_visibility_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
  agent_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
  visibility text [not null, default: 'public']
  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_personal_identifier_idx']
    (user_id, workspace_id, identifier) [name: 'user_connectors_workspace_identifier_idx']
    (agent_id, identifier) [name: 'user_connectors_agent_identifier_idx']
    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']
    agent_id [name: 'user_connectors_agent_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 user_contact_requests {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  requester_id text [not null]
  addressee_id text [not null]
  workspace_id text
  message text
  source jsonb
  status text [not null, default: 'pending']
  responded_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 {
    (requester_id, addressee_id) [name: 'user_contact_requests_pending_unique', unique]
    (workspace_id, requester_id, addressee_id) [name: 'user_contact_requests_workspace_pending_unique', unique]
    (addressee_id, status) [name: 'user_contact_requests_addressee_status_idx']
    (requester_id, status) [name: 'user_contact_requests_requester_status_idx']
    workspace_id [name: 'user_contact_requests_workspace_id_idx']
    
  }
}

table user_contact_tag_assignments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  tag_id uuid [not null]
  contact_id uuid [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 {
    (tag_id, contact_id) [name: 'user_contact_tag_assignments_tag_id_contact_id_unique', unique]
    contact_id [name: 'user_contact_tag_assignments_contact_id_idx']
    user_id [name: 'user_contact_tag_assignments_user_id_idx']
  }
}

table user_contact_tags {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  name text [not null]
  color text
  sort_order 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 {
    (user_id, name) [name: 'user_contact_tags_user_id_name_unique', unique]
  }
}

table user_contacts {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  type text [not null]
  contact_user_id text
  agent_id text
  remark text
  description text
  phones 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, contact_user_id) [name: 'user_contacts_user_unique', unique]
    (workspace_id, user_id, contact_user_id) [name: 'user_contacts_workspace_user_unique', unique]
    (user_id, agent_id) [name: 'user_contacts_agent_unique', unique]
    (workspace_id, agent_id) [name: 'user_contacts_workspace_agent_unique', unique]
    contact_user_id [name: 'user_contacts_contact_user_id_idx']
    agent_id [name: 'user_contacts_agent_id_idx']
    workspace_id [name: 'user_contacts_workspace_id_idx']
  }
}

table dashboard_items {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  dashboard_id uuid [not null]
  widget_id uuid [not null]
  user_id text [not null]
  workspace_id text
  layout jsonb
  sort_order 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 {
    (dashboard_id, widget_id) [name: 'dashboard_items_dashboard_id_widget_id_unique', unique]
    (dashboard_id, sort_order) [name: 'dashboard_items_dashboard_id_sort_order_idx']
    widget_id [name: 'dashboard_items_widget_id_idx']
    user_id [name: 'dashboard_items_user_id_idx']
    workspace_id [name: 'dashboard_items_workspace_id_idx']
  }
}

table dashboards {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  project_id text
  agent_id text
  title text [not null]
  description text
  icon text
  sort_order integer [not null, default: 0]
  metadata jsonb
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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, sort_order) [name: 'dashboards_personal_idx']
    (workspace_id, sort_order) [name: 'dashboards_workspace_idx']
    (project_id, sort_order) [name: 'dashboards_project_idx']
    (agent_id, sort_order) [name: 'dashboards_agent_idx']
    user_id [name: 'dashboards_user_id_idx']
    workspace_id [name: 'dashboards_workspace_id_idx']
  }
}

table devices {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'private']
  shared_from_device_id varchar(64)
  device_id varchar(64) [not null]
  identity_source varchar(20) [not null]
  hostname text
  platform varchar(20)
  architecture varchar(20)
  metadata jsonb
  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]
    (workspace_id, device_id) [name: 'devices_workspace_id_device_id_unique', unique]
    user_id [name: 'devices_user_id_idx']
    workspace_id [name: 'devices_workspace_id_idx']
    (workspace_id, visibility, user_id) [name: 'devices_workspace_visibility_idx']
  }
}

table document_comment_mentions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  comment_id uuid [not null]
  mentioned_user_id text [not null]
  workspace_id text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (comment_id, mentioned_user_id) [name: 'document_comment_mentions_comment_id_mentioned_user_id_unique', unique]
    (mentioned_user_id, created_at) [name: 'document_comment_mentions_mentioned_user_id_created_at_idx']
    workspace_id [name: 'document_comment_mentions_workspace_id_idx']
  }
}

table document_comments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  document_id text [not null]
  parent_comment_id uuid
  reply_to_comment_id uuid
  author_user_id text
  workspace_id text [not null]
  content text [not null]
  editor_data jsonb
  selection_anchor jsonb
  client_id text [not null]
  deleted_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (document_id, author_user_id, client_id) [name: 'document_comments_document_id_author_user_id_client_id_unique', unique]
    (parent_comment_id, created_at, id) [name: 'document_comments_parent_comment_id_created_at_id_idx']
    reply_to_comment_id [name: 'document_comments_reply_to_comment_id_idx']
    (document_id, created_at, id) [name: 'document_comments_document_id_created_at_id_idx']
    author_user_id [name: 'document_comments_author_user_id_idx']
    workspace_id [name: 'document_comments_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]
  editor_ids text[]
  operation_id text
  agent_id text
  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']
  }
}

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

  indexes {
    (document_id, user_id) [name: 'document_likes_document_id_user_id_unique', unique]
    (document_id, created_at) [name: 'document_likes_document_id_created_at_idx']
    user_id [name: 'document_likes_user_id_idx']
    workspace_id [name: 'document_likes_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 environments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  project_id text
  name varchar(255) [not null]
  description text
  enabled boolean [not null, default: true]
  visibility text [not null, default: 'private']
  configuration 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()`]

  indexes {
    user_id [name: 'environments_user_id_idx']
    workspace_id [name: 'environments_workspace_id_idx']
    project_id [name: 'environments_project_id_unique', unique]
    (workspace_id, visibility, user_id) [name: 'environments_workspace_visibility_idx']
    (user_id, name) [name: 'environments_user_name_unique', unique]
    (workspace_id, user_id, name) [name: 'environments_workspace_user_name_unique', unique]
    
    
  }
}

table environment_instances {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  environment_id uuid [not null]
  name varchar(255) [not null]
  kind text [not null]
  device_id uuid
  provider text
  provider_scope text
  provider_resource_id text
  working_directory text [not null]
  configuration_snapshot jsonb [not null]
  configuration jsonb
  enabled boolean [not null, default: true]
  status text [not null, default: 'pending']
  build_id text
  build_error 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 {
    (environment_id, id) [name: 'environment_instances_environment_id_id_unique', unique]
    (device_id, working_directory) [name: 'environment_instances_device_path_unique', unique]
    (kind, provider, provider_scope, provider_resource_id, working_directory) [name: 'environment_instances_provider_path_unique', unique]
    environment_id [name: 'environment_instances_environment_id_idx']
    
    
    
    
    
  }
}

table expertise_bindings {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  domain_id varchar(255) [not null]
  agent_id text
  project_id text
  bound_workspace_id text
  bound_user_id text
  contribution_mode text [not null, default: 'derive']
  added_by_user_id text
  workspace_id text
  enabled boolean [not null, default: true]
  sort_order 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, domain_id) [name: 'expertise_bindings_agent_domain_unique', unique]
    (project_id, domain_id) [name: 'expertise_bindings_project_domain_unique', unique]
    (bound_workspace_id, domain_id) [name: 'expertise_bindings_workspace_domain_unique', unique]
    (bound_user_id, domain_id) [name: 'expertise_bindings_user_domain_unique', unique]
    domain_id [name: 'expertise_bindings_domain_idx']
    workspace_id [name: 'expertise_bindings_workspace_id_idx']
  }
}

table expertise_domain_snapshots {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  domain_id varchar(255) [not null]
  run_id uuid
  run_index integer [not null]
  learned_total integer [not null]
  retired_total integer [not null, default: 0]
  active_count integer [not null]
  compiled_count integer [not null, default: 0]
  layer_counts jsonb [not null, default: `{}`]
  p_inf numeric
  tau numeric
  maturity numeric
  fit_sample_size integer
  fit_r2 numeric
  fit_confidence text
  fit_computed_at "timestamp with time zone"
  tau_pinned boolean [not null, default: false]
  observed_span numeric
  plateau_kind text
  layer_coverage numeric
  canon_coverage numeric
  active_rate numeric
  captured_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    
    (domain_id, run_index) [name: 'expertise_domain_snapshots_domain_run_index_unique', unique]
    (domain_id, captured_at) [name: 'expertise_domain_snapshots_domain_captured_idx']
    domain_id [name: 'expertise_domain_snapshots_pending_fit_idx']
  }
}

table expertise_domains {
  id varchar(255) [pk, not null]
  slug varchar(255) [not null]
  title text [not null]
  description text
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'private']
  source text [not null, default: 'user']
  parent_domain_id varchar(255)
  domain_filter text [not null]
  out_of_scope text
  layers jsonb [not null, default: `[]`]
  layer_source text [not null, default: 'invented']
  canon_entries jsonb [not null, default: `[]`]
  canon_document_id varchar(255)
  flow jsonb [not null, default: `[]`]
  evidence_spec jsonb [not null, default: `[]`]
  lesson_base_document_id varchar(255)
  anchor_candidates jsonb
  anchor_chosen_at "timestamp with time zone"
  anchor_chosen_by_user_id text
  seed_state text [not null, default: 'seeding']
  seed_run_id uuid
  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: 'expertise_domains_slug_user_unique', unique]
    (workspace_id, slug) [name: 'expertise_domains_slug_workspace_unique', unique]
    user_id [name: 'expertise_domains_user_id_idx']
    (workspace_id, visibility) [name: 'expertise_domains_workspace_visibility_idx']
    parent_domain_id [name: 'expertise_domains_parent_idx']
  }
}

table expertise_hits {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  run_id uuid [not null]
  lesson_id uuid [not null]
  domain_id varchar(255) [not null]
  outcome text [not null]
  where text
  note text
  example text
  severity text
  evidence_id uuid
  operation_id text
  source_check_result_id uuid
  source_message_id text
  user_decision text
  user_decision_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    
    
    (lesson_id, created_at) [name: 'expertise_hits_lesson_created_idx']
    run_id [name: 'expertise_hits_run_idx']
    (domain_id, outcome) [name: 'expertise_hits_domain_outcome_idx']
    operation_id [name: 'expertise_hits_operation_idx']
    source_message_id [name: 'expertise_hits_source_message_idx']
  }
}

table expertise_insights {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  domain_id varchar(255)
  user_id text
  workspace_id text
  kind varchar(255) [not null]
  headline text [not null]
  body text [not null]
  action_label text
  action_target jsonb
  evidence jsonb [not null, default: `[]`]
  confidence real
  status text [not null, default: 'active']
  dismiss_reason text
  stale_after_run_index integer
  generated_by_operation_id text
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (domain_id, status) [name: 'expertise_insights_domain_status_idx']
    (user_id, status) [name: 'expertise_insights_user_status_idx']
    workspace_id [name: 'expertise_insights_workspace_idx']
  }
}

table expertise_lesson_revisions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  lesson_id uuid [not null]
  revision integer [not null]
  sections jsonb [not null]
  feedback text
  changed_by text [not null]
  kind text [not null, default: 'user-feedback']
  prev_title text
  evidence jsonb
  changed_by_user_id text
  source_run_id uuid
  operation_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (lesson_id, revision) [name: 'expertise_lesson_revisions_lesson_revision_unique', unique]
    lesson_id [name: 'expertise_lesson_revisions_lesson_idx']
  }
}

table expertise_lessons {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  domain_id varchar(255) [not null]
  created_by_user_id text
  code varchar(20) [not null]
  polarity text [not null]
  title text [not null]
  sections jsonb [not null]
  layer varchar(255)
  tags text[]
  reason_kind text
  reason_source text
  canon_anchor text
  origin_run_id uuid
  origin_hit_id uuid
  status text [not null, default: 'active']
  rejected_reason text
  salvaged_from_id uuid
  retired_at "timestamp with time zone"
  sort_order integer
  enforcement text
  direction text
  compilability text [not null, default: 'compilable']
  backtest jsonb
  compiled_criterion_id uuid
  hit_count integer [not null, default: 0]
  hit_run_count integer [not null, default: 0]
  false_positive_count integer [not null, default: 0]
  last_hit_at "timestamp with time zone"
  last_hit_run_id uuid
  generalized_from_ids jsonb
  specificity text
  example_count integer [not null, default: 0]
  current_revision integer [not null, default: 1]
  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 {
    (domain_id, code) [name: 'expertise_lessons_domain_code_unique', unique]
    (id, domain_id) [name: 'expertise_lessons_id_domain_unique', unique]
    (domain_id, status, hit_count) [name: 'expertise_lessons_domain_status_hits_idx']
    (domain_id, layer) [name: 'expertise_lessons_domain_layer_idx']
    compiled_criterion_id [name: 'expertise_lessons_compiled_criterion_idx']
  }
}

table expertise_runs {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  domain_id varchar(255) [not null]
  run_index integer [not null]
  is_seed_run boolean [not null, default: false]
  actor_type text [not null]
  actor_id text [not null]
  subject_type text [not null]
  subject_id text [not null]
  window_start "timestamp with time zone"
  window_end "timestamp with time zone"
  reflection_key varchar(255)
  had_human_in_loop boolean [not null, default: false]
  user_id text
  workspace_id text
  instance_count integer [not null, default: 0]
  refine_count integer [not null, default: 0]
  new_count integer [not null, default: 0]
  started_at "timestamp with time zone" [not null, default: `now()`]
  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 {
    (domain_id, run_index) [name: 'expertise_runs_domain_run_index_unique', unique]
    (id, domain_id) [name: 'expertise_runs_id_domain_unique', unique]
    (domain_id, reflection_key) [name: 'expertise_runs_domain_reflection_key_unique', unique]
    (domain_id, started_at) [name: 'expertise_runs_domain_started_idx']
    (actor_type, actor_id) [name: 'expertise_runs_actor_idx']
    (subject_type, subject_id) [name: 'expertise_runs_subject_idx']
  }
}

table user_favorites {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  type text [not null]
  target_id text [not null]
  path text [not null]
  title text [not null]
  icon text
  sort_order 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 {
    (user_id, type, target_id) [name: 'user_favorites_personal_target_unique', unique]
    (user_id, workspace_id, type, target_id) [name: 'user_favorites_workspace_target_unique', unique]
    user_id [name: 'user_favorites_user_id_idx']
    workspace_id [name: 'user_favorites_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
  created_by_agent_id text
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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, visibility, user_id) [name: 'documents_workspace_visibility_idx']
    (workspace_id, slug) [name: 'documents_slug_workspace_id_unique', unique]
  }
}

table file_uploads {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  pathname text [not null]
  size integer [not null]
  status text [not null, default: 'active']
  multipart_upload_id text
  multipart_part_size integer
  completed_at "timestamp with time zone"
  file_id text
  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 {
    (user_id, workspace_id, status) [name: 'file_uploads_user_scope_status_idx']
    (workspace_id, status) [name: 'file_uploads_workspace_status_idx']
    (status, expires_at) [name: 'file_uploads_status_expires_at_idx']
    (status, updated_at, id) [name: 'file_uploads_status_updated_at_id_idx']
    pathname [name: 'file_uploads_live_pathname_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
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (workspace_id, visibility, user_id) [name: 'files_workspace_visibility_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
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (workspace_id, visibility, user_id) [name: 'knowledge_bases_workspace_visibility_idx']
  }
}

table file_shares {
  id text [pk, not null]
  file_id text [not null]
  user_id text [not null]
  workspace_id text
  page_view_count integer [not null, default: 0]
  config jsonb
  metadata jsonb
  visibility text [not null, default: 'private']
  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 [name: 'file_shares_file_id_unique', unique]
    user_id [name: 'file_shares_user_id_idx']
    workspace_id [name: 'file_shares_workspace_id_idx']
  }
}

table fts_search_sync_capture_version {
  id text [pk, not null]
  version integer [not null]
}

table fts_search_sync_outbox {
  attempts integer [not null, default: 0]
  available_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]
  dead_at "timestamp with time zone"
  document_id text [not null]
  entity text [not null]
  id uuid [pk, not null, default: `gen_random_uuid()`]
  last_error text
  locked_until "timestamp with time zone"
  priority smallint [not null, default: 10]
  revision bigint [not null, default: `nextval('fts_search_sync_revision_seq')`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (entity, document_id) [name: 'fts_search_sync_outbox_entity_document_id_unique', unique]
    (priority, available_at, revision) [name: 'fts_search_sync_outbox_claim_idx']
    dead_at [name: 'fts_search_sync_outbox_dead_idx']
    locked_until [name: 'fts_search_sync_outbox_lease_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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (workspace_id, visibility, user_id) [name: 'generation_topics_workspace_visibility_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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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 goals {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  agent_id text
  project_id text
  title text [not null]
  requirement text
  config jsonb
  max_rounds integer
  max_total_cost "numeric(20, 6)"
  status text [not null, default: 'planning']
  subject_type text
  subject_id text
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  archived_at "timestamp with time zone"
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    user_id [name: 'goals_user_id_idx']
    workspace_id [name: 'goals_workspace_id_idx']
    (workspace_id, visibility, user_id) [name: 'goals_workspace_visibility_idx']
    agent_id [name: 'goals_agent_id_idx']
    project_id [name: 'goals_project_id_idx']
    status [name: 'goals_status_idx']
    (subject_type, subject_id) [name: 'goals_subject_idx']
  }
}

table goal_edges {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  goal_id text [not null]
  source_node_id uuid [not null]
  target_node_id uuid [not null]
  kind text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (source_node_id, target_node_id, kind) [name: 'goal_edges_source_target_kind_unique', unique]
    goal_id [name: 'goal_edges_goal_id_idx']
    target_node_id [name: 'goal_edges_target_node_id_idx']
    
    
    
  }
}

table goal_events {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  goal_id text [not null]
  event_type text [not null]
  entity_type text [not null]
  entity_id text [not null]
  actor_type text [not null]
  actor_id text
  task_id text
  operation_id text
  reason text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (goal_id, created_at) [name: 'goal_events_goal_id_created_at_idx']
    (entity_type, entity_id) [name: 'goal_events_entity_idx']
    task_id [name: 'goal_events_task_id_idx']
    operation_id [name: 'goal_events_operation_id_idx']
  }
}

table goal_node_decisions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  node_id uuid [not null]
  authority text [not null]
  status text [not null, default: 'pending']
  question text [not null]
  options jsonb
  recommended_option_id text
  requested_user_id text
  requested_project_role text
  resolved_option_id text
  resolution text
  resolved_by_user_id text
  resolved_by_agent_id text
  resolved_at "timestamp with time zone"
  canceled_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 {
    node_id [name: 'goal_node_decisions_node_id_unique', unique]
    status [name: 'goal_node_decisions_status_idx']
    resolved_by_user_id [name: 'goal_node_decisions_resolved_by_user_id_idx']
    (requested_user_id, status) [name: 'goal_node_decisions_requested_user_id_status_idx']
  }
}

table goal_node_work_versions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  node_id uuid [not null]
  work_version_id uuid [not null]
  relation text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (node_id, work_version_id, relation) [name: 'goal_node_work_versions_node_version_relation_unique', unique]
    work_version_id [name: 'goal_node_work_versions_work_version_id_idx']
  }
}

table goal_nodes {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  goal_id text [not null]
  kind text [not null]
  status text [not null, default: 'proposed']
  title text [not null]
  description text
  task_id text
  priority integer [not null, default: 0]
  confidence "numeric(4, 3)"
  created_by_user_id text
  created_by_agent_id text
  resolved_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 {
    (goal_id, status) [name: 'goal_nodes_goal_id_status_idx']
    created_by_user_id [name: 'goal_nodes_created_by_user_id_idx']
    (goal_id, kind) [name: 'goal_nodes_goal_id_kind_idx']
    (goal_id, id) [name: 'goal_nodes_goal_id_id_unique', unique]
    task_id [name: 'goal_nodes_task_id_unique', unique]
    
  }
}

table goal_shares {
  id text [pk, not null]
  goal_id text [not null]
  user_id text [not null]
  workspace_id text
  page_view_count integer [not null, default: 0]
  config jsonb
  metadata jsonb
  visibility text [not null, default: 'private']
  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 {
    goal_id [name: 'goal_shares_goal_id_unique', unique]
    user_id [name: 'goal_shares_user_id_idx']
    workspace_id [name: 'goal_shares_workspace_id_idx']
  }
}

table goal_subscriptions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  goal_id text [not null]
  widget_id uuid [not null]
  metric_id text
  user_id text [not null]
  workspace_id text
  enabled boolean [not null, default: false]
  confirmed_version_id uuid [not null]
  binding_revision integer [not null, default: 1]
  binding jsonb [not null]
  wake_condition jsonb [not null]
  freshness_policy jsonb [not null]
  cursor 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 {
    (goal_id, widget_id, metric_id) [name: 'goal_subscriptions_goal_widget_metric_unique', unique]
    (goal_id, widget_id) [name: 'goal_subscriptions_goal_widget_result_unique', unique]
    (widget_id, workspace_id, user_id) [name: 'goal_subscriptions_widget_enabled_idx']
    (user_id, goal_id) [name: 'goal_subscriptions_personal_idx']
    (workspace_id, goal_id) [name: 'goal_subscriptions_workspace_idx']
    metric_id [name: 'goal_subscriptions_metric_id_idx']
    confirmed_version_id [name: 'goal_subscriptions_confirmed_version_id_idx']
    (updated_at, id) [name: 'goal_subscriptions_reconcile_idx']
    
  }
}

table goal_traces {
  goal_id text [pk, not null]
  trace_s3_key text
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  final_status text
  advances_total integer
  ticks_total integer
  advances_by_trigger jsonb
  advances_by_outcome jsonb
  ticks_by_branch jsonb
  total_cost "numeric(20, 6)"
  work_operations integer
  nodes_total integer
  work_resolved integer
  work_retired integer
  findings_total integer
  gates_opened integer
  gates_resolved integer
  human_waiting_ms integer
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    started_at [name: 'goal_traces_started_at_idx']
    final_status [name: 'goal_traces_final_status_idx']
  }
}

table inbound_webhooks {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  kind text [not null]
  name text
  status text [not null, default: 'pending']
  agent_id text [not null]
  topic_id text
  instructions text
  secret text
  verification jsonb [not null]
  config jsonb [not null]
  state jsonb [not null, default: `{}`]
  connector_id uuid
  dedupe_key text
  next_maintenance_at "timestamp with time zone"
  maintenance_failures integer [not null, default: 0]
  last_delivery_at "timestamp with time zone"
  last_error text
  wake_count integer [not null, default: 0]
  wake_window_started_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, kind, dedupe_key) [name: 'inbound_webhooks_user_kind_dedupe_unique', unique]
    next_maintenance_at [name: 'inbound_webhooks_next_maintenance_idx']
    user_id [name: 'inbound_webhooks_user_idx']
    workspace_id [name: 'inbound_webhooks_workspace_idx']
    topic_id [name: 'inbound_webhooks_topic_idx']
    agent_id [name: 'inbound_webhooks_agent_idx']
    connector_id [name: 'inbound_webhooks_connector_idx']
  }
}

table linear_connections {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  organization_id varchar(255) [not null]
  organization_name varchar(255) [not null]
  organization_url_key varchar(255) [not null]
  actor_external_id varchar(255) [not null]
  actor_name varchar(255) [not null]
  credentials text
  token_expires_at "timestamp with time zone"
  revoked_at "timestamp with time zone"
  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 {
    (organization_id, user_id) [name: 'linear_connections_org_personal_unique', unique]
    (organization_id, user_id, workspace_id) [name: 'linear_connections_org_workspace_unique', unique]
    user_id [name: 'linear_connections_user_id_idx']
    workspace_id [name: 'linear_connections_workspace_id_idx']
  }
}

table linear_sync_rules {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  connection_id uuid [not null]
  user_id text [not null]
  workspace_id text
  team_id varchar(255) [not null]
  team_name varchar(255) [not null]
  linear_project_id varchar(255)
  linear_project_name varchar(255)
  state_types jsonb [not null]
  last_run_at "timestamp with time zone"
  last_result 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 {
    project_id [name: 'linear_sync_rules_project_id_idx']
    connection_id [name: 'linear_sync_rules_connection_id_idx']
    user_id [name: 'linear_sync_rules_user_id_idx']
    workspace_id [name: 'linear_sync_rules_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']
  }
}

table meeting_minutes {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  meeting_id uuid [not null]
  summary text
  chapters jsonb [not null, default: `[]`]
  decisions jsonb [not null, default: `[]`]
  action_items jsonb [not null, default: `[]`]
  keywords jsonb [not null, default: `[]`]
  document_id text
  model 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 {
    meeting_id [name: 'meeting_minutes_meeting_id_unique', unique]
    document_id [name: 'meeting_minutes_document_id_idx']
  }
}

table meeting_segments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  meeting_id uuid [not null]
  speaker_id uuid
  source text [not null]
  seq integer [not null]
  start_ms integer [not null]
  end_ms integer [not null]
  text 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 {
    (meeting_id, source, seq) [name: 'meeting_segments_meeting_id_source_seq_unique', unique]
    (meeting_id, source, start_ms) [name: 'meeting_segments_meeting_id_source_start_ms_idx']
    speaker_id [name: 'meeting_segments_speaker_id_idx']
  }
}

table meeting_speakers {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  meeting_id uuid [not null]
  label text [not null]
  display_name 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 {
    (meeting_id, label) [name: 'meeting_speakers_meeting_id_label_unique', unique]
  }
}

table meetings {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  title text [not null]
  status text [not null, default: 'recording']
  platform text [not null]
  realtime_provider text [not null]
  refine_provider text [not null]
  language text [not null, default: 'auto']
  started_at "timestamp with time zone" [not null, default: `now()`]
  ended_at "timestamp with time zone"
  duration_ms integer
  audio_file_id text
  local_audio_path text
  error jsonb
  visibility text [not null, default: 'private']
  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, workspace_id, created_at) [name: 'meetings_user_id_workspace_id_created_at_idx']
    (workspace_id, created_at) [name: 'meetings_workspace_id_created_at_idx']
    audio_file_id [name: 'meetings_audio_file_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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (topic_id, updated_at) [name: 'messages_topic_id_updated_at_idx']
    parent_id [name: 'messages_parent_id_idx']
    quota_id [name: 'messages_quota_id_idx']
    user_id [name: 'messages_user_id_idx']
    (user_id, topic_id) [name: 'messages_user_id_topic_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
  application_id varchar(255)
  credentials 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]
    (platform, tenant_id, application_id) [name: 'messenger_account_links_platform_tenant_application_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 metric_points {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  metric_id text [not null]
  user_id text [not null]
  workspace_id text
  value "numeric(20, 6)" [not null]
  observed_at "timestamp with time zone" [not null]
  actor_type text [not null]
  actor_id text
  operation_id text
  source_type text [not null]
  metadata jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (metric_id, observed_at) [name: 'metric_points_series_time_idx']
    user_id [name: 'metric_points_user_id_idx']
    workspace_id [name: 'metric_points_workspace_id_idx']
  }
}

table metrics {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  subject_type text [not null]
  subject_id text [not null]
  key text [not null]
  title text
  kind text [not null, default: 'gauge']
  unit text
  config jsonb
  metadata jsonb
  deleted_at "timestamp with time zone"
  is_deleted boolean
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (subject_type, subject_id, key) [name: 'metrics_subject_key_unique', unique]
    user_id [name: 'metrics_user_id_idx']
    workspace_id [name: 'metrics_workspace_id_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]
  workspace_id text
  category text [not null]
  type text [not null]
  title text [not null]
  content text [not null]
  context text
  metadata jsonb
  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]
    (user_id, workspace_id) [name: 'idx_notifications_user_workspace']
    workspace_id [name: 'idx_notifications_workspace_id']
    (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]
  user_id text
  workspace_id text
  enabled boolean
  last_used_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 [name: 'oidc_clients_user_id_idx']
    workspace_id [name: 'oidc_clients_workspace_id_idx']
  }
}

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 project_agents {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  agent_id text [not null]
  added_by_user_id text
  workspace_id text
  role text
  responsibility text
  enabled boolean [not null, default: true]
  sort_order 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 {
    (project_id, agent_id) [name: 'project_agents_project_id_agent_id_unique', unique]
    (project_id, sort_order) [name: 'project_agents_project_id_sort_order_idx']
    agent_id [name: 'project_agents_agent_id_idx']
    workspace_id [name: 'project_agents_workspace_id_idx']
  }
}

table project_chat_groups {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  chat_group_id text [not null]
  added_by_user_id text
  workspace_id text
  role text
  responsibility text
  enabled boolean [not null, default: true]
  sort_order 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 {
    (project_id, chat_group_id) [name: 'project_chat_groups_project_id_chat_group_id_unique', unique]
    (project_id, sort_order) [name: 'project_chat_groups_project_id_sort_order_idx']
    chat_group_id [name: 'project_chat_groups_chat_group_id_idx']
    workspace_id [name: 'project_chat_groups_workspace_id_idx']
  }
}

table project_completion_reviews {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  reviewer_user_id text
  workspace_id text
  round integer [not null]
  decision text [not null]
  comment 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 {
    (project_id, round) [name: 'project_completion_reviews_project_id_round_unique', unique]
    (project_id, created_at) [name: 'project_completion_reviews_project_id_created_at_idx']
    reviewer_user_id [name: 'project_completion_reviews_reviewer_user_id_idx']
    workspace_id [name: 'project_completion_reviews_workspace_id_idx']
    
  }
}

table project_knowledge_bases {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  knowledge_base_id text [not null]
  added_by_user_id text
  workspace_id text
  enabled boolean [not null, default: true]
  sort_order 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 {
    (project_id, knowledge_base_id) [name: 'project_knowledge_bases_project_id_knowledge_base_id_unique', unique]
    (project_id, sort_order) [name: 'project_knowledge_bases_project_id_sort_order_idx']
    knowledge_base_id [name: 'project_knowledge_bases_knowledge_base_id_idx']
    workspace_id [name: 'project_knowledge_bases_workspace_id_idx']
  }
}

table project_working_directories {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  device_id uuid
  workspace_id text
  added_by_user_id text
  path text [not null]
  name varchar(255) [not null]
  permission text [not null, default: 'readWrite']
  is_primary boolean [not null, default: false]
  sort_order 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 {
    (project_id, device_id, path) [name: 'project_working_directories_project_device_path_unique', unique]
    project_id [name: 'project_working_directories_project_primary_unique', unique]
    (project_id, sort_order) [name: 'project_working_directories_project_sort_order_idx']
    device_id [name: 'project_working_directories_device_id_idx']
    workspace_id [name: 'project_working_directories_workspace_id_idx']
    
    
  }
}

table projects {
  id text [pk, not null]
  slug varchar(100)
  identifier varchar(6)
  name varchar(255) [not null]
  description text
  avatar text
  coordinator_agent_id text
  status text [not null, default: 'backlog']
  sort_order integer
  user_id text [not null]
  workspace_id text
  visibility text [not null, default: 'public']
  completed_review_id uuid
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  archived_at "timestamp with time zone"
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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: 'projects_slug_user_id_unique', unique]
    (workspace_id, slug) [name: 'projects_slug_workspace_id_unique', unique]
    (identifier, user_id) [name: 'projects_identifier_user_id_unique', unique]
    (workspace_id, identifier) [name: 'projects_identifier_workspace_id_unique', unique]
    user_id [name: 'projects_user_id_idx']
    workspace_id [name: 'projects_workspace_id_idx']
    (user_id, sort_order) [name: 'projects_user_id_sort_order_idx']
    (workspace_id, sort_order) [name: 'projects_workspace_id_sort_order_idx']
    (workspace_id, visibility, user_id) [name: 'projects_workspace_visibility_idx']
    (status, updated_at) [name: 'projects_status_updated_at_idx']
    coordinator_agent_id [name: 'projects_coordinator_agent_id_idx']
    
  }
}

table project_environments {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  environment_id uuid [not null]
  workspace_id text
  added_by_user_id text
  default_instance_id uuid
  enabled boolean [not null, default: true]
  is_default boolean [not null, default: false]
  sort_order 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 {
    
    default_instance_id [name: 'project_environments_default_instance_id_idx']
    (project_id, environment_id) [name: 'project_environments_project_environment_unique', unique]
    project_id [name: 'project_environments_project_default_unique', unique]
    (project_id, sort_order) [name: 'project_environments_project_sort_order_idx']
    environment_id [name: 'project_environments_environment_id_idx']
    workspace_id [name: 'project_environments_workspace_id_idx']
    added_by_user_id [name: 'project_environments_added_by_user_id_idx']
    
  }
}

table project_members {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  workspace_id text [not null]
  user_id text [not null]
  added_by_user_id text
  role text [not null, default: 'member']
  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 {
    (project_id, user_id) [name: 'project_members_project_user_unique', unique]
    workspace_id [name: 'project_members_workspace_id_idx']
    user_id [name: 'project_members_user_id_idx']
  }
}

table project_sites {
  id text [pk, not null]
  project_id text [not null]
  workspace_id text
  created_by_user_id text
  name varchar(255) [not null]
  origins text[] [not null]
  acceptance_id uuid
  last_seen_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 {
    project_id [name: 'project_sites_project_id_idx']
    workspace_id [name: 'project_sites_workspace_id_idx']
    
    
  }
}

table project_works {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  project_id text [not null]
  work_id text [not null]
  added_by_user_id text
  workspace_id text
  sort_order 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 {
    (project_id, work_id) [name: 'project_works_project_id_work_id_unique', unique]
    (project_id, sort_order) [name: 'project_works_project_id_sort_order_idx']
    work_id [name: 'project_works_work_id_idx']
    workspace_id [name: 'project_works_workspace_id_idx']
  }
}

table push_live_activities {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  device_id text [not null]
  activity_key text [not null]
  operation_id text [not null]
  activity_id text [not null]
  push_token text [not null]
  apns_environment text [not null]
  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, activity_key) [name: 'idx_push_live_activities_user_device_activity', unique]
    (user_id, activity_key) [name: 'idx_push_live_activities_user_activity']
    (user_id, operation_id) [name: 'idx_push_live_activities_user_operation']
    last_seen_at [name: 'idx_push_live_activities_last_seen']
    
  }
}

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]
  apns_environment text
  app_version text
  locale text
  live_activity_push_to_start_token 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']
  }
}

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']
  }
}

table resource_permissions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  resource_type text [not null]
  resource_id text [not null]
  workspace_id text [not null]
  user_id text
  access_level text [not null]
  created_by 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, resource_type, resource_id) [name: 'resource_permissions_workspace_resource_unique', unique]
    (workspace_id, resource_type, resource_id, user_id) [name: 'resource_permissions_workspace_resource_user_id_unique', unique]
    (resource_type, resource_id) [name: 'resource_permissions_resource_idx']
    workspace_id [name: 'resource_permissions_workspace_idx']
    user_id [name: 'resource_permissions_user_id_idx']
    created_by [name: 'resource_permissions_created_by_idx']
    (workspace_id, user_id) [name: 'resource_permissions_workspace_user_idx']
  }
}

table resource_transfer_requests {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  resource_type text [not null]
  resource_id text [not null]
  workspace_id text [not null]
  initiator_id text
  recipient_id text
  previous_owner_id text
  status text [not null, default: 'pending']
  options jsonb
  expires_at "timestamp with time zone" [not null]
  resolved_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 {
    (resource_type, resource_id) [name: 'resource_transfer_requests_pending_resource_unique', unique]
    (recipient_id, status) [name: 'resource_transfer_requests_recipient_idx']
    workspace_id [name: 'resource_transfer_requests_workspace_idx']
  }
}

table scm_change_requests {
  id text [pk, not null]
  user_id text [not null]
  workspace_id text
  provider text [not null]
  repo_full_name varchar(255) [not null]
  repo_external_id varchar(255)
  number integer [not null]
  external_id varchar(255)
  url text [not null]
  title text
  author_external_id varchar(255)
  author_external_login varchar(255)
  head_ref varchar(255)
  head_sha varchar(255)
  base_ref varchar(255)
  is_draft boolean [not null, default: false]
  state text [not null]
  merged_at "timestamp with time zone"
  closed_at "timestamp with time zone"
  merged_by_external_id varchar(255)
  ci_status text
  ci_head_sha varchar(255)
  checks jsonb
  review_decision text
  merge_state_status varchar(255)
  installation_id uuid
  acceptance_id uuid
  work_id text
  topic_id text
  task_id text
  wake_count integer [not null, default: 0]
  last_wake_at "timestamp with time zone"
  last_event_at "timestamp with time zone"
  last_event_kind text
  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 {
    (provider, repo_full_name, number) [name: 'scm_change_requests_provider_repo_number_unique', unique]
    acceptance_id [name: 'scm_change_requests_acceptance_id_idx']
    topic_id [name: 'scm_change_requests_topic_id_idx']
    work_id [name: 'scm_change_requests_work_id_idx']
    installation_id [name: 'scm_change_requests_installation_id_idx']
    (user_id, updated_at) [name: 'scm_change_requests_user_updated_at_idx']
    workspace_id [name: 'scm_change_requests_workspace_id_idx']
    head_sha [name: 'scm_change_requests_head_sha_idx']
  }
}

table scm_identities {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  provider text [not null]
  external_user_id varchar(255) [not null]
  external_login varchar(255) [not null]
  credentials text
  token_expires_at "timestamp with time zone"
  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 {
    (provider, external_user_id) [name: 'scm_identities_provider_external_user_unique', unique]
    (provider, user_id) [name: 'scm_identities_provider_user_unique', unique]
    token_expires_at [name: 'scm_identities_token_expires_at_idx']
  }
}

table scm_installations {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  provider text [not null]
  installation_id varchar(255) [not null]
  account_login varchar(255) [not null]
  account_external_id varchar(255) [not null]
  account_type text [not null]
  repository_selection text [not null]
  repositories jsonb [not null, default: `[]`]
  installed_by_external_user_id varchar(255)
  installed_by_external_login varchar(255)
  suspended_at "timestamp with time zone"
  revoked_at "timestamp with time zone"
  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 {
    (provider, installation_id) [name: 'scm_installations_provider_installation_unique', unique]
    user_id [name: 'scm_installations_user_id_idx']
    workspace_id [name: 'scm_installations_workspace_id_idx']
    (provider, account_login) [name: 'scm_installations_provider_account_idx']
  }
}

table scm_webhook_deliveries {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  provider text [not null]
  delivery_id varchar(255) [not null]
  event varchar(255) [not null]
  action varchar(255)
  installation_id varchar(255)
  repo_full_name varchar(255)
  number integer
  status text [not null]
  error text
  received_at "timestamp with time zone" [not null, default: `now()`]
  processed_at "timestamp with time zone"

  indexes {
    (provider, delivery_id) [name: 'scm_webhook_deliveries_provider_delivery_unique', unique]
    received_at [name: 'scm_webhook_deliveries_received_at_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
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (workspace_id, visibility, user_id) [name: 'session_groups_workspace_visibility_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 signals {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  source text [not null]
  type text [not null]
  external_id text [not null]
  account_id uuid
  agent_id text
  scope_key text
  payload jsonb [not null, default: `{}`]
  payload_purged_at "timestamp with time zone"
  metadata jsonb [not null, default: `{}`]
  status text [not null, default: 'pending']
  attempts integer [not null, default: 0]
  error text
  occurred_at "timestamp with time zone"
  processed_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 {
    (source, external_id) [name: 'signals_source_external_id_unique', unique]
    (status, created_at) [name: 'signals_status_created_at_idx']
    (account_id, created_at) [name: 'signals_account_created_at_idx']
    user_id [name: 'signals_user_id_idx']
    (user_id, scope_key, source, created_at) [name: 'signals_user_scope_source_created_at_idx']
    created_at [name: 'signals_payload_unpurged_created_at_idx']
  }
}

table signal_decision_labels {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  decision_id uuid [not null]
  source text [not null]
  label text [not null]
  confidence real
  actor text
  metadata jsonb [not null, default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (decision_id, created_at) [name: 'signal_decision_labels_decision_created_at_idx']
  }
}

table signal_decisions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  signal_id uuid [not null]
  agent_id text
  user_id text [not null]
  workspace_id text
  scope_key text [not null]
  pipeline_version text [not null]
  outcome text [not null]
  final_reason text
  to_tag text
  verdicts jsonb [not null, default: `[]`]
  llm_tracing_ids jsonb [not null, default: `[]`]
  operation_id text
  topic_id text
  metadata jsonb [not null, default: `{}`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (signal_id, agent_id, pipeline_version) [name: 'signal_decisions_signal_agent_pipeline_unique', unique]
    signal_id [name: 'signal_decisions_signal_id_idx']
    (user_id, scope_key, created_at) [name: 'signal_decisions_user_scope_created_at_idx']
    (agent_id, created_at) [name: 'signal_decisions_agent_created_at_idx']
  }
}

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_activities {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  task_id text [not null]
  user_id text [not null]
  workspace_id text
  actor_user_id text
  actor_agent_id text
  type text [not null]
  payload jsonb
  visibility text [not null, default: 'public']
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    task_id [name: 'task_activities_task_id_idx']
    user_id [name: 'task_activities_user_id_idx']
    workspace_id [name: 'task_activities_workspace_id_idx']
    (workspace_id, visibility, user_id) [name: 'task_activities_workspace_visibility_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
  visibility text [not null, default: 'public']
  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']
    (workspace_id, visibility, user_id) [name: 'task_comments_workspace_visibility_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']
  visibility text [not null, default: 'public']
  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']
    (workspace_id, visibility, user_id) [name: 'task_deps_workspace_visibility_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']
  visibility text [not null, default: 'public']
  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']
    (workspace_id, visibility, user_id) [name: 'task_docs_workspace_visibility_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']
  trigger text
  handoff jsonb
  review_passed integer
  review_score integer
  review_scores jsonb
  review_iteration integer
  reviewed_at "timestamp with time zone"
  visibility text [not null, default: 'public']
  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']
    (workspace_id, visibility, user_id) [name: 'task_topics_workspace_visibility_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
  project_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
  visibility text [not null, default: 'public']
  started_at "timestamp with time zone"
  completed_at "timestamp with time zone"
  archived_at "timestamp with time zone"
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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']
    (project_id, status) [name: 'tasks_project_id_status_idx']
    (workspace_id, visibility, created_by_user_id) [name: 'tasks_workspace_visibility_idx']
    (workspace_id, identifier) [name: 'tasks_identifier_workspace_id_unique', unique]
  }
}

table task_external_links {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  task_id text [not null]
  user_id text [not null]
  workspace_id text
  provider text [not null]
  external_id varchar(255) [not null]
  external_identifier varchar(255) [not null]
  external_url text [not null]
  external_container_id varchar(255)
  external_updated_at "timestamp with time zone"
  synced_hash text [not null]
  last_synced_at "timestamp with time zone" [not null, default: `now()`]
  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 {
    task_id [name: 'task_external_links_task_id_unique', unique]
    (user_id, provider, external_id) [name: 'task_external_links_personal_unique', unique]
    (workspace_id, provider, external_id) [name: 'task_external_links_workspace_unique', unique]
    (provider, external_container_id) [name: 'task_external_links_container_idx']
    user_id [name: 'task_external_links_user_id_idx']
  }
}

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

  indexes {
    (task_id, label_id) [name: 'task_label_links_task_id_label_id_unique', unique]
    label_id [name: 'task_label_links_label_id_idx']
    user_id [name: 'task_label_links_user_id_idx']
    workspace_id [name: 'task_label_links_workspace_id_idx']
  }
}

table task_labels {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text
  workspace_id text
  parent_id uuid
  is_group boolean [not null, default: false]
  name text [not null]
  description text
  color text
  sort_order 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 {
    
    user_id [name: 'task_labels_user_id_idx']
    workspace_id [name: 'task_labels_workspace_id_idx']
    parent_id [name: 'task_labels_parent_id_idx']
    (user_id, name) [name: 'task_labels_user_id_name_unique', unique]
    (workspace_id, name) [name: 'task_labels_workspace_id_name_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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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
  project_id text
  project_working_directory_id uuid
  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
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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]
    created_at [name: 'topics_created_at_idx']
    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']
    project_id [name: 'topics_project_id_idx']
    project_working_directory_id [name: 'topics_project_working_directory_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 topic_analyses {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  topic_id text [not null]
  user_id text [not null]
  workspace_id text
  taxonomy_version text [not null]
  category text [not null]
  secondary_category text
  intent text
  outcome text
  labels jsonb
  metadata jsonb
  model text
  provider text
  topic_model text
  topic_provider text
  total_tokens integer
  total_input_tokens integer
  total_output_tokens integer
  total_cost "numeric(20, 6)"
  llm_calls integer
  tool_calls integer
  user_messages integer
  assistant_messages integer
  last_message_id text
  last_message_updated_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 {
    (topic_id, taxonomy_version) [name: 'topic_analyses_topic_version_unique', unique]
    (user_id, created_at) [name: 'topic_analyses_user_id_created_at_idx']
    (workspace_id, created_at) [name: 'topic_analyses_workspace_id_created_at_idx']
    (taxonomy_version, category) [name: 'topic_analyses_version_category_idx']
  }
}

table topic_comment_mentions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  comment_id text [not null]
  mentioned_user_id text [not null]
  workspace_id text [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (comment_id, mentioned_user_id) [name: 'topic_comment_mentions_comment_id_mentioned_user_id_unique', unique]
    (mentioned_user_id, created_at) [name: 'topic_comment_mentions_mentioned_user_id_created_at_idx']
    workspace_id [name: 'topic_comment_mentions_workspace_id_idx']
  }
}

table topic_comments {
  id text [pk, not null]
  topic_id text [not null]
  message_id text
  parent_comment_id text
  author_user_id text
  workspace_id text [not null]
  content text [not null]
  editor_data jsonb
  client_id text [not null]
  anchor_preview jsonb
  deleted_at "timestamp with time zone"
  moderated_at "timestamp with time zone"
  moderated_by_user_id text
  moderation_expires_at "timestamp with time zone"
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (topic_id, author_user_id, client_id) [name: 'topic_comments_topic_id_author_user_id_client_id_unique', unique]
    
    
    
    
    (parent_comment_id, created_at, id) [name: 'topic_comments_parent_comment_id_created_at_id_idx']
    (topic_id, created_at, id) [name: 'topic_comments_topic_id_created_at_id_idx']
    (topic_id, message_id) [name: 'topic_comments_topic_id_message_id_idx']
    message_id [name: 'topic_comments_message_id_idx']
    author_user_id [name: 'topic_comments_author_user_id_idx']
    moderation_expires_at [name: 'topic_comments_moderation_expires_at_idx']
    moderated_by_user_id [name: 'topic_comments_moderated_by_user_id_idx']
    workspace_id [name: 'topic_comments_workspace_id_idx']
  }
}

table trash_items {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  resource_type text [not null]
  resource_id text [not null]
  project_id text
  title text
  meta jsonb
  root_id uuid
  user_id text [not null]
  workspace_id text
  deleted_by_user_id text
  deleted_at "timestamp with time zone" [not null, default: `now()`]
  expires_at "timestamp with time zone" [not null]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (resource_type, resource_id) [name: 'trash_items_resource_unique', unique]
    (user_id, deleted_at) [name: 'trash_items_personal_listing_idx']
    (workspace_id, deleted_at) [name: 'trash_items_workspace_listing_idx']
    expires_at [name: 'trash_items_expires_at_idx']
    root_id [name: 'trash_items_root_id_idx']
    user_id [name: 'trash_items_user_id_idx']
    deleted_by_user_id [name: 'trash_items_deleted_by_user_id_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_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)
  dossier_id varchar(255)
  injectable boolean [not null, default: true]
  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']
    dossier_id [name: 'user_memories_activities_dossier_id_index']
  }
}

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)
  state text
  user_locked boolean [default: false]
  accessed_count bigint [default: 0]
  last_accessed_at "timestamp with time zone" [not null]
  captured_at "timestamp with time zone" [not null, default: `now()`]
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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_context_projects {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  context_id varchar(255) [not null]
  project_id text [not null]
  user_id text
  metadata jsonb
  source text [not null]
  evidence_count integer [not null, default: 0]
  is_primary boolean [not null, 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 {
    (context_id, project_id) [name: 'user_memories_context_projects_context_id_project_id_unique', unique]
    project_id [name: 'user_memories_context_projects_project_id_index']
    user_id [name: 'user_memories_context_projects_user_id_index']
  }
}

table user_memories_contexts {
  id varchar(255) [pk, not null]
  user_id text
  user_memory_id varchar(255)
  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]
  now text
  next_steps jsonb
  open_questions jsonb
  first_seen_at "timestamp with time zone"
  last_evidence_at "timestamp with time zone"
  synthesized_at "timestamp with time zone"
  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']
    user_memory_ids [name: 'user_memories_contexts_user_memory_ids_gin_idx']
    user_memory_id [name: 'user_memories_contexts_user_memory_id_index']
    (user_id, last_evidence_at) [name: 'user_memories_contexts_user_id_last_evidence_at_index']
  }
}

table user_memories_dossiers {
  id varchar(255) [pk, not null]
  context_id varchar(255)
  user_id text
  workspace_id text
  agent_id text
  project_id text
  user_memory_id varchar(255)
  metadata jsonb
  title text
  summary text
  summary_vector vector(1024)
  now text
  decisions jsonb
  status text [not null, default: 'active']
  first_seen_at "timestamp with time zone"
  last_evidence_at "timestamp with time zone"
  activity_count integer [not null, default: 0]
  visibility text [not null, default: 'private']
  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 [name: 'user_memories_dossiers_summary_vector_index']
    context_id [name: 'user_memories_dossiers_context_id_index']
    (user_id, last_evidence_at) [name: 'user_memories_dossiers_user_id_last_evidence_at_index']
    user_memory_id [name: 'user_memories_dossiers_user_memory_id_index']
    (workspace_id, visibility, user_id) [name: 'user_memories_dossiers_workspace_visibility_idx']
    agent_id [name: 'user_memories_dossiers_agent_id_index']
    project_id [name: 'user_memories_dossiers_project_id_index']
  }
}

table user_memories_edges {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  source_memory_id varchar(255) [not null]
  target_memory_id varchar(255) [not null]
  user_id text
  workspace_id text
  metadata jsonb
  relation text [not null]
  evidence_count integer [not null, default: 1]
  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_memory_id, target_memory_id, relation) [name: 'user_memories_edges_source_target_relation_unique', unique]
    (target_memory_id, relation) [name: 'user_memories_edges_target_memory_id_relation_index']
    (user_id, relation) [name: 'user_memories_edges_user_id_relation_index']
    (workspace_id, relation) [name: 'user_memories_edges_workspace_id_relation_index']
  }
}

table user_memories_entities {
  id varchar(255) [pk, not null]
  parent_entity_id varchar(255)
  user_id text
  workspace_id text
  agent_id text
  project_id text
  user_memory_id varchar(255)
  metadata jsonb
  name text [not null]
  type text [not null, default: 'other']
  relationship text
  role text
  description text
  description_vector vector(1024)
  is_self boolean [not null, default: false]
  visibility text [not null, default: 'private']
  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_entities_description_vector_index']
    user_id [name: 'user_memories_entities_user_id_index']
    parent_entity_id [name: 'user_memories_entities_parent_entity_id_index']
    user_memory_id [name: 'user_memories_entities_user_memory_id_index']
    user_id [name: 'user_memories_entities_user_id_self_unique', unique]
    (workspace_id, visibility, user_id) [name: 'user_memories_entities_workspace_visibility_idx']
    agent_id [name: 'user_memories_entities_agent_id_index']
    project_id [name: 'user_memories_entities_project_id_index']
  }
}

table user_memories_entity_names {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  entity_id varchar(255) [not null]
  user_id text
  workspace_id text
  metadata jsonb
  name text [not null]
  normalized text [not null]
  kind text [not null, default: 'alias']
  source_memory_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 {
    (entity_id, normalized) [name: 'user_memories_entity_names_entity_id_normalized_unique', unique]
    (user_id, normalized) [name: 'user_memories_entity_names_user_id_normalized_index']
    (workspace_id, normalized) [name: 'user_memories_entity_names_workspace_id_normalized_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
  entity_id varchar(255)
  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']
    entity_id [name: 'user_memories_identities_entity_id_index']
  }
}

table user_memories_operations {
  id varchar(255) [pk, not null]
  user_id text
  workspace_id text
  metadata jsonb
  op text [not null]
  actor text [not null]
  targets jsonb [not null]
  before jsonb
  after jsonb
  confidence real
  reason text
  gate text [not null]
  state text [not null]
  resolved_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, state, created_at) [name: 'user_memories_operations_user_id_state_created_at_index']
    (workspace_id, state, created_at) [name: 'user_memories_operations_workspace_id_state_created_at_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 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]
  holder_entity_id varchar(255)
  applies_to_entity_id varchar(255)
  scope text
  evidence_source text
  evidence_count integer [not null, default: 1]
  last_evidence_at "timestamp with time zone"
  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']
    holder_entity_id [name: 'user_memories_preferences_holder_entity_id_index']
    applies_to_entity_id [name: 'user_memories_preferences_applies_to_entity_id_index']
  }
}

table acceptances {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  project_id text
  subject_type text [not null]
  subject_id text [not null]
  status text [not null, default: 'pending']
  visibility text [not null, default: 'public']
  requirement text
  config jsonb [default: `{}`]
  visual_render jsonb
  metadata jsonb
  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 {
    user_id [name: 'acceptances_user_id_idx']
    workspace_id [name: 'acceptances_workspace_id_idx']
    project_id [name: 'acceptances_project_id_idx']
    (subject_type, subject_id) [name: 'acceptances_subject_idx']
    status [name: 'acceptances_status_idx']
    (workspace_id, visibility, user_id) [name: 'acceptances_workspace_visibility_idx']
    (user_id, subject_type, subject_id) [name: 'acceptances_personal_subject_unique', unique]
    (workspace_id, subject_type, subject_id) [name: 'acceptances_workspace_subject_unique', unique]
  }
}

table verify_check_results {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  verify_run_id uuid
  operation_id text
  user_id text [not null]
  workspace_id text
  check_item_id text [not null]
  source_criterion_id uuid
  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
  metadata jsonb
  suggestion text
  user_decision text
  user_decision_detail jsonb
  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 {
    (source_criterion_id, created_at) [name: 'verify_check_results_criterion_created_idx']
    verify_run_id [name: 'verify_check_results_verify_run_id_idx']
    operation_id [name: 'verify_check_results_operation_id_idx']
    user_id [name: 'verify_check_results_user_id_idx']
    (verify_run_id, check_item_id) [name: 'verify_check_results_verify_run_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
  definition jsonb
  tags text[] [not null, default: `[]`]
  archived_at "timestamp with time zone"
  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_evidence {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  description text
  check_result_id uuid [not null]
  type text [not null]
  content text
  document_id text
  file_id text
  metadata jsonb
  captured_by text
  captured_at "timestamp with time zone"
  user_id text [not null]
  workspace_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    check_result_id [name: 'verify_evidence_check_result_id_idx']
    document_id [name: 'verify_evidence_document_id_idx']
    file_id [name: 'verify_evidence_file_id_idx']
    user_id [name: 'verify_evidence_user_id_idx']
    workspace_id [name: 'verify_evidence_workspace_id_idx']
  }
}

table verify_reports {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  verify_run_id uuid
  operation_id text
  user_id text [not null]
  workspace_id text
  verdict text
  overall_confidence "numeric(3, 2)"
  total_checks integer
  passed_checks integer
  failed_checks integer
  uncertain_checks integer
  summary text
  content text
  reviewed_by_user boolean [default: false]
  generated_by text [default: 'system']
  generated_at "timestamp with time zone" [not null, default: `now()`]
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    verify_run_id [name: 'verify_reports_verify_run_id_unique', unique]
    operation_id [name: 'verify_reports_operation_id_idx']
    user_id [name: 'verify_reports_user_id_idx']
    workspace_id [name: 'verify_reports_workspace_id_idx']
  }
}

table verify_review_predictions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  check_result_id uuid [not null]
  user_id text [not null]
  workspace_id text
  provider text [not null]
  model text [not null]
  prompt_version text [not null]
  status text [not null]
  action text
  status_reason text
  confidence "numeric(3, 2)"
  comment text
  rationale text
  annotations jsonb
  adjudication text
  adjudication_edit text
  adjudicated_at "timestamp with time zone"
  latency_ms integer
  prompt_tokens integer
  completion_tokens integer
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    check_result_id [name: 'verify_review_predictions_check_result_id_idx']
    user_id [name: 'verify_review_predictions_user_id_idx']
    workspace_id [name: 'verify_review_predictions_workspace_id_idx']
    (provider, model) [name: 'verify_review_predictions_model_idx']
    (check_result_id, provider, model, prompt_version) [name: 'verify_review_predictions_result_model_prompt_unique', unique]
    
  }
}

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 verify_runs {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  acceptance_id uuid
  round_index integer
  operation_id text
  source text [not null, default: 'agent']
  visibility text [not null, default: 'public']
  scenario text
  title text
  goal text
  context jsonb
  metadata jsonb
  plan jsonb
  flow_snapshots jsonb
  plan_confirmed_at "timestamp with time zone"
  status text
  user_decision text
  decision_detail 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: 'verify_runs_user_id_idx']
    workspace_id [name: 'verify_runs_workspace_id_idx']
    acceptance_id [name: 'verify_runs_acceptance_id_idx']
    (acceptance_id, round_index) [name: 'verify_runs_acceptance_round_unique', unique]
    
    operation_id [name: 'verify_runs_operation_id_unique', unique]
    source [name: 'verify_runs_source_idx']
    user_decision [name: 'verify_runs_user_decision_idx']
  }
}

table widget_runs {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  widget_id uuid [not null]
  version_id uuid [not null]
  user_id text [not null]
  workspace_id text
  trigger text [not null]
  status text [not null, default: 'running']
  started_at "timestamp with time zone" [not null, default: `now()`]
  finished_at "timestamp with time zone"
  duration_ms integer
  exit_code integer
  output jsonb
  stdout text
  stderr text
  error jsonb
  sandbox_id text
  operation_id text
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (widget_id, created_at) [name: 'widget_runs_widget_id_created_at_idx']
    version_id [name: 'widget_runs_version_id_idx']
    user_id [name: 'widget_runs_user_id_idx']
    workspace_id [name: 'widget_runs_workspace_id_idx']
  }
}

table widget_versions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  widget_id uuid [not null]
  user_id text [not null]
  workspace_id text
  version integer [not null]
  runtime text [not null]
  script text [not null]
  content_hash text [not null]
  manifest jsonb
  output_type text [not null]
  view jsonb
  status text [not null, default: 'draft']
  change_note text
  published_at "timestamp with time zone"
  published_by_user_id text
  source_type text [not null]
  source_agent_id text
  source_topic_id text
  source_message_id text
  source_operation_id text
  parent_version_id uuid
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (widget_id, version) [name: 'widget_versions_widget_id_version_unique', unique]
    user_id [name: 'widget_versions_user_id_idx']
    workspace_id [name: 'widget_versions_workspace_id_idx']
    source_agent_id [name: 'widget_versions_source_agent_id_idx']
    source_topic_id [name: 'widget_versions_source_topic_id_idx']
    parent_version_id [name: 'widget_versions_parent_version_id_idx']
  }
}

table widgets {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  user_id text [not null]
  workspace_id text
  project_id text
  agent_id text
  title text [not null]
  description text
  published_version_id uuid
  draft_version_id uuid
  schedule_pattern text
  schedule_timezone text
  next_run_at "timestamp with time zone"
  last_run_id uuid
  last_run_at "timestamp with time zone"
  last_run_status text
  last_run_error jsonb
  consecutive_failures integer [not null, default: 0]
  latest_output jsonb
  latest_output_at "timestamp with time zone"
  metric_id text
  metadata jsonb
  visibility text [not null, default: 'public']
  deleted_at "timestamp with time zone"
  is_deleted boolean
  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, updated_at) [name: 'widgets_personal_idx']
    (workspace_id, updated_at) [name: 'widgets_workspace_idx']
    (project_id, updated_at) [name: 'widgets_project_idx']
    (agent_id, updated_at) [name: 'widgets_agent_idx']
    next_run_at [name: 'widgets_due_idx']
    user_id [name: 'widgets_user_id_idx']
    workspace_id [name: 'widgets_workspace_id_idx']
    published_version_id [name: 'widgets_published_version_id_idx']
    draft_version_id [name: 'widgets_draft_version_id_idx']
    metric_id [name: 'widgets_metric_id_idx']
  }
}

table work_versions {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  work_id text [not null]
  version integer [not null]
  title text
  description text
  content text
  identifier text
  status text
  url text
  change_type text [not null]
  tool_name text [not null]
  tool_identifier text [not null]
  topic_id text
  thread_id text
  message_id text
  root_operation_id text
  tool_call_id text
  agent_id text
  metadata jsonb
  cumulative_cost "numeric(20, 6)"
  cumulative_usage jsonb
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (work_id, version) [name: 'work_versions_work_id_version_unique', unique]
    (work_id, tool_call_id) [name: 'work_versions_work_id_tool_call_id_unique', unique]
    thread_id [name: 'work_versions_thread_id_idx']
    message_id [name: 'work_versions_message_id_idx']
    agent_id [name: 'work_versions_agent_id_idx']
    (root_operation_id, created_at) [name: 'work_versions_root_operation_created_at_idx']
    (topic_id, created_at) [name: 'work_versions_topic_created_at_idx']
    (topic_id, thread_id, created_at) [name: 'work_versions_topic_thread_created_at_idx']
  }
}

table works {
  id text [pk, not null]
  type text [not null]
  current_version_id uuid
  resource_type text [not null]
  resource_id text
  title text
  description text
  identifier text
  status text
  url text
  tool_name text [not null]
  tool_identifier text [not null]
  origin_topic_id text
  origin_thread_id text
  origin_agent_id text
  user_id text [not null]
  workspace_id text
  visibility text [not null]
  metadata jsonb
  deleted_at "timestamp with time zone"
  is_deleted boolean
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (resource_type, resource_id, user_id) [name: 'works_resource_user_scope_unique', unique]
    (workspace_id, resource_type, resource_id) [name: 'works_resource_workspace_scope_unique', unique]
    user_id [name: 'works_user_id_idx']
    workspace_id [name: 'works_workspace_id_idx']
    (workspace_id, visibility, user_id) [name: 'works_workspace_visibility_idx']
    (user_id, updated_at, id) [name: 'works_user_updated_at_id_idx']
    (workspace_id, updated_at, id) [name: 'works_workspace_updated_at_id_idx']
    origin_topic_id [name: 'works_origin_topic_id_idx']
    origin_thread_id [name: 'works_origin_thread_id_idx']
    origin_agent_id [name: 'works_origin_agent_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']
  reusable boolean [not null, default: false]
  expires_at "timestamp with time zone"
  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']
    inviter_id [name: 'workspace_invitations_inviter_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']
  title text
  responsibilities text
  config jsonb [not null, default: `{}`]
  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']
    workspace_id [name: 'workspace_members_unique_active_owner_idx', unique]
  }
}

table workspace_team_members {
  id uuid [pk, not null, default: `gen_random_uuid()`]
  team_id text [not null]
  workspace_id text [not null]
  user_id text [not null]
  role text [not null, default: 'member']
  created_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    
    (team_id, user_id) [name: 'workspace_team_members_team_user_unique', unique]
    (workspace_id, user_id) [name: 'workspace_team_members_workspace_user_idx']
    user_id [name: 'workspace_team_members_user_id_idx']
  }
}

table workspace_teams {
  id text [pk, not null]
  workspace_id text [not null]
  name varchar(255) [not null]
  identifier varchar(16) [not null]
  description varchar(1000)
  avatar text
  created_by text
  created_at "timestamp with time zone" [not null, default: `now()`]
  updated_at "timestamp with time zone" [not null, default: `now()`]

  indexes {
    (workspace_id, identifier) [name: 'workspace_teams_workspace_identifier_unique', unique]
    workspace_id [name: 'workspace_teams_workspace_id_idx']
    created_by [name: 'workspace_teams_created_by_idx']
    (id, workspace_id) [name: 'workspace_teams_id_workspace_unique', unique]
  }
}

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

  indexes {
    (workspace_id, user_id) [name: 'workspace_user_settings_workspace_id_user_id_unique', unique]
    user_id [name: 'workspace_user_settings_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: `{}`]
  frozen boolean [default: false]
  frozen_reason text
  frozen_at "timestamp with time zone"
  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_comment_mentions.comment_id > document_comments.id

ref: document_comment_mentions.mentioned_user_id - users.id

ref: document_comment_mentions.workspace_id - workspaces.id

ref: document_comments.author_user_id - users.id

ref: document_comments.document_id > documents.id

ref: document_comments.workspace_id - workspaces.id

ref: document_histories.document_id > documents.id

ref: document_histories.user_id - users.id

ref: document_likes.document_id > documents.id

ref: document_likes.user_id - users.id

ref: document_likes.workspace_id - workspaces.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_comment_mentions.comment_id > topic_comments.id

ref: topic_comment_mentions.mentioned_user_id - users.id

ref: topic_comments.topic_id > topics.id

ref: topic_comments.message_id - messages.id

ref: topic_comments.author_user_id - users.id

ref: topic_comments.workspace_id - workspaces.id

ref: topic_documents.document_id > documents.id

ref: topic_documents.topic_id > topics.id

ref: topics.session_id - sessions.id