{
  "name": "Chat",
  "label": "Chat",
  "description": "Chat session table for storing chat metadata and session information",
  "tags": ["agent", "system"],
  "builtin": true,
  "readonly": true,
  "sort": 9999,
  "table": { "name": "agent_chat", "comment": "Agent chat session table" },
  "columns": [
    {
      "name": "id",
      "type": "ID",
      "label": "ID",
      "comment": "Auto-increment primary key"
    },
    {
      "name": "chat_id",
      "type": "string",
      "label": "Chat ID",
      "comment": "Unique chat identifier",
      "length": 64,
      "nullable": false,
      "unique": true
    },
    {
      "name": "title",
      "type": "string",
      "label": "Title",
      "comment": "Chat title",
      "length": 500,
      "nullable": true
    },
    {
      "name": "assistant_id",
      "type": "string",
      "label": "Assistant ID",
      "comment": "Associated assistant ID",
      "length": 200,
      "nullable": false,
      "index": true
    },
    {
      "name": "last_connector",
      "type": "string",
      "label": "Last Connector",
      "comment": "Last used connector ID (updated on each message)",
      "length": 200,
      "nullable": true,
      "index": true
    },
    {
      "name": "last_mode",
      "type": "string",
      "label": "Last Mode",
      "comment": "Last used chat mode (updated on each message)",
      "length": 50,
      "nullable": true
    },
    {
      "name": "status",
      "type": "enum",
      "label": "Status",
      "comment": "Chat status",
      "option": ["active", "archived"],
      "default": "active",
      "nullable": false,
      "index": true
    },
    {
      "name": "public",
      "type": "boolean",
      "label": "Public",
      "comment": "Whether shared across all teams",
      "default": false,
      "nullable": false
    },
    {
      "name": "share",
      "type": "enum",
      "label": "Share",
      "comment": "Sharing scope",
      "option": ["private", "team"],
      "default": "private",
      "nullable": false,
      "index": true
    },
    {
      "name": "sort",
      "type": "integer",
      "label": "Sort",
      "comment": "Sort order for display",
      "default": 9999
    },
    {
      "name": "last_message_at",
      "type": "datetime",
      "label": "Last Message At",
      "comment": "Timestamp of last message",
      "nullable": true,
      "index": true
    },
    {
      "name": "metadata",
      "type": "json",
      "label": "Metadata",
      "comment": "Additional metadata",
      "nullable": true
    }
  ],
  "relations": {
    "assistant": {
      "type": "hasOne",
      "model": "__yao.agent.assistant",
      "key": "assistant_id",
      "foreign": "assistant_id"
    },
    "messages": {
      "type": "hasMany",
      "model": "__yao.agent.message",
      "key": "chat_id",
      "foreign": "chat_id"
    },
    "resumes": {
      "type": "hasMany",
      "model": "__yao.agent.resume",
      "key": "chat_id",
      "foreign": "chat_id"
    }
  },
  "option": { "timestamps": true, "soft_deletes": true, "permission": true }
}
