feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

164
docker/.env.example Normal file
View File

@@ -0,0 +1,164 @@
# Server
export LISTEN_ADDR=":8888"
export LOG_LEVEL="debug"
export MAX_REQUEST_BODY_SIZE=1073741824
export SERVER_HOST="localhost${LISTEN_ADDR}"
export MINIO_PROXY_ENDPOINT=":8889"
# MySQL
export MYSQL_ROOT_PASSWORD=root
export MYSQL_DATABASE=opencoze
export MYSQL_USER=coze
export MYSQL_PASSWORD=coze123
export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_DSN="${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(${MYSQL_HOST}:${MYSQL_PORT})/${MYSQL_DATABASE}?charset=utf8mb4&parseTime=True"
export ATLAS_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@${MYSQL_HOST}:${MYSQL_PORT}/${MYSQL_DATABASE}?charset=utf8mb4&parseTime=True"
# Redis
export REDIS_AOF_ENABLED=no
export REDIS_IO_THREADS=4
export ALLOW_EMPTY_PASSWORD=yes
export REDIS_ADDR="localhost:6379"
# This Upload component used in Agent / workflow File/Image With LLM , support the component of imagex / storage
# default: storage, use the settings of storage component
# if imagex, you must finish the configuration of <VolcEngine ImageX>
export FILE_UPLOAD_COMPONENT_TYPE="storage"
# VolcEngine ImageX
export VE_IMAGEX_AK=""
export VE_IMAGEX_SK=""
export VE_IMAGEX_SERVER_ID=""
export VE_IMAGEX_DOMAIN=""
export VE_IMAGEX_TEMPLATE=""
export VE_IMAGEX_UPLOAD_HOST="https://imagex.volcengineapi.com"
# Storage component
export STORAGE_TYPE="minio" # minio / tos
export STORAGE_BUCKET="opencoze"
# MiniIO
export MINIO_ROOT_USER=minioadmin
export MINIO_ROOT_PASSWORD=minioadmin123
export MINIO_DEFAULT_BUCKETS=milvus
export MINIO_AK=$MINIO_ROOT_USER
export MINIO_SK=$MINIO_ROOT_PASSWORD
export MINIO_ENDPOINT="localhost:9000"
export MINIO_API_HOST="http://${MINIO_ENDPOINT}"
# TOS
export TOS_ACCESS_KEY=
export TOS_SECRET_KEY=
export TOS_ENDPOINT=https://tos-cn-beijing.volces.com
export TOS_REGION=cn-beijing
# Elasticsearch
export ES_ADDR="http://localhost:9200"
export ES_VERSION="v8"
export ES_USERNAME=""
export ES_PASSWORD=""
export COZE_MQ_TYPE="nsq" # nsq / kafka / rmq
export MQ_NAME_SERVER="127.0.0.1:4150"
# RocketMQ
export RMQ_ACCESS_KEY=""
export RMQ_SECRET_KEY=""
# Settings for VectorStore
# VectorStore type: milvus / vikingdb
# If you want to use vikingdb, you need to set up the vikingdb configuration.
export VECTOR_STORE_TYPE="milvus"
# milvus vector store
export MILVUS_ADDR="localhost:19530"
# vikingdb vector store for Volcengine
export VIKING_DB_HOST=""
export VIKING_DB_REGION=""
export VIKING_DB_AK=""
export VIKING_DB_SK=""
export VIKING_DB_SCHEME=""
export VIKING_DB_MODEL_NAME="" # if vikingdb model name is not set, you need to set Embedding settings
# Settings for Embedding
# The Embedding model relied on by knowledge base vectorization does not need to be configured
# if the vector database comes with built-in Embedding functionality (such as VikingDB). Currently,
# Coze Studio supports three access methods: openai, ark, and custom http. Users can simply choose one of them when using
# embedding type: openai / ark / http
export EMBEDDING_TYPE="ark"
# openai embedding
export OPENAI_EMBEDDING_BASE_URL="" # (string) OpenAI base_url
export OPENAI_EMBEDDING_MODEL="" # (string) OpenAI embedding model
export OPENAI_EMBEDDING_API_KEY="" # (string) OpenAI api_key
export OPENAI_EMBEDDING_BY_AZURE=true # (bool) OpenAI by_azure
export OPENAI_EMBEDDING_API_VERSION="" # OpenAI azure api version
export OPENAI_EMBEDDING_DIMS=1024 # (int) 向量维度
export OPENAI_EMBEDDING_REQUEST_DIMS=0
# ark embedding
export ARK_EMBEDDING_MODEL=""
export ARK_EMBEDDING_AK=""
export ARK_EMBEDDING_DIMS="2048"
export ARK_EMBEDDING_BASE_URL=""
# http embedding
export HTTP_EMBEDDING_ADDR="http://127.0.0.1:6543"
# Settings for OCR
# If you want to use the OCR-related functions in the knowledge base featureYou need to set up the OCR configuration.
# Currently, Coze Studio has built-in Volcano OCR.
# ocr_type: default type `ve`
export OCR_TYPE="ve"
# ve ocr
export VE_OCR_AK=""
export VE_OCR_SK=""
# Settings for Model
# Model for agent & workflow
# add suffix number to add different models
export MODEL_PROTOCOL_0="ark" # protocol
export MODEL_OPENCOZE_ID_0="100001" # id for record
export MODEL_NAME_0="" # model name for show
export MODEL_ID_0="" # model name for connection
export MODEL_API_KEY_0="" # model api key
export MODEL_BASE_URL_0="" # model base url
# Model for knowledge nl2sql, messages2query (rewrite), image annotation
# add prefix to assign specific model, downgrade to default config when prefix is not configured:
# 1. nl2sql: NL2SQL_ (e.g. NL2SQL_BUILTIN_CM_TYPE)
# 2. messages2query: M2Q_ (e.g. M2Q_BUILTIN_CM_TYPE)
# 3. image annotation: IA_ (e.g. IA_BUILTIN_CM_TYPE)
# supported chat model type: openai / ark / deepseek / ollama / qwen / gemini
export BUILTIN_CM_TYPE="ark"
# type openai
export BUILTIN_CM_OPENAI_BASE_URL=""
export BUILTIN_CM_OPENAI_API_KEY=""
export BUILTIN_CM_OPENAI_BY_AZURE=true
export BUILTIN_CM_OPENAI_MODEL=""
# type ark
export BUILTIN_CM_ARK_API_KEY=""
export BUILTIN_CM_ARK_MODEL=""
export BUILTIN_CM_ARK_BASE_URL=""
# type deepseek
export BUILTIN_CM_DEEPSEEK_BASE_URL=""
export BUILTIN_CM_DEEPSEEK_API_KEY=""
export BUILTIN_CM_DEEPSEEK_MODEL=""
# type ollama
export BUILTIN_CM_OLLAMA_BASE_URL=""
export BUILTIN_CM_OLLAMA_MODEL=""
# type qwen
export BUILTIN_CM_QWEN_BASE_URL=""
export BUILTIN_CM_QWEN_API_KEY=""
export BUILTIN_CM_QWEN_MODEL=""
# type gemini
export BUILTIN_CM_GEMINI_BACKEND=""
export BUILTIN_CM_GEMINI_API_KEY=""
export BUILTIN_CM_GEMINI_PROJECT=""
export BUILTIN_CM_GEMINI_LOCATION=""
export BUILTIN_CM_GEMINI_BASE_URL=""
export BUILTIN_CM_GEMINI_MODEL=""

71
docker/atlas/README.md Executable file
View File

@@ -0,0 +1,71 @@
## 0. setup environment
On Mac :
brew install ariga/tap/atlas
On Linux :
curl -sSf https://atlasgo.sh | sh -s -- --community
Setup to you database url :
export ATLAS_URL="mysql://coze:coze123@localhost:3306/opencoze?charset=utf8mb4&parseTime=True"
## 2. init baseline
# cd ./docker/atlas
atlas migrate diff initial --env local --to $ATLAS_URL
# The following command is the same as the one above.
atlas migrate diff initial \
--dir "file://migrations" \
--to $ATLAS_URL \
--dev-url "docker://mysql/8/"
## 3. update database table
On developer machineI want add/update table for my business
# First, add or update your table as needed.
# Second, autogenerate diff sql
# cd ./docker/atlas
atlas migrate diff update --env local --to $ATLAS_URL # step 1
# The following command is the same as the one above.
atlas migrate diff update \
--dir "file://migrations" \
--to $ATLAS_URL \
--dev-url "docker://mysql/8/"
# will autogenerate some xxxxx_update.sql in margrations
# Third, Check whether the contents of the new xxxx_update.sql file are correct.
# If any changes are needed, please modify it manually.
# If you manually modified margrations file, you need to run the following command to update its hash value.
# If you did not manually modify margrations file, do not run the following command.
atlas migrate hash # step 2 if need
atlas migrate status --url $ATLAS_URL --dir "file://migrations" # check status
# Last, dump the lastest database schema for other developer
atlas schema inspect -u $ATLAS_URL --exclude "atlas_schema_revisions,table_*" > opencoze_latest_schema.hcl # step 3
## 4. apply migration
On developer machineI want to update my local database with the changes that others developer have made
# cd ./docker/atlas
atlas schema apply -u $ATLAS_URL --to file://opencoze_latest_schema.hcl # step 1 for developer on mac, this command will execute in start_debug.sh
On Server machine
atlas migrate apply --url $ATLAS_URL --dir "file://migrations" --baseline "20250703095335" # step 1 for dev server

12
docker/atlas/atlas.hcl Executable file
View File

@@ -0,0 +1,12 @@
env "local" {
url = "mysql://coze:coze123@localhost:3306/opencoze?charset=utf8mb4&parseTime=True"
dev = "docker://mysql/8"
migration {
dir = "file://migrations"
exclude = ["atlas_schema_revisions", "table_*"]
baseline = "20250703095335"
}
}

View File

@@ -0,0 +1,90 @@
-- Add new schema named "opencoze"
CREATE DATABASE IF NOT EXISTS `opencoze` COLLATE utf8mb4_unicode_ci;
-- Create "agent_to_database" table
CREATE TABLE `opencoze`.`agent_to_database` (`id` bigint unsigned NOT NULL COMMENT "ID", `agent_id` bigint unsigned NOT NULL COMMENT "Agent ID", `database_id` bigint unsigned NOT NULL COMMENT "ID of database_info", `is_draft` bool NOT NULL COMMENT "Is draft", `prompt_disable` bool NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported", PRIMARY KEY (`id`), UNIQUE INDEX `uniq_agent_db_draft` (`agent_id`, `database_id`, `is_draft`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "agent_to_database info";
-- Create "agent_tool_draft" table
CREATE TABLE `opencoze`.`agent_tool_draft` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Agent ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path", `method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method", `tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Name", `tool_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0", `operation` json NULL COMMENT "Tool Openapi Operation Schema", PRIMARY KEY (`id`), INDEX `idx_agent_plugin_tool` (`agent_id`, `plugin_id`, `tool_id`), INDEX `idx_agent_tool_bind` (`agent_id`, `created_at`), UNIQUE INDEX `uniq_idx_agent_tool_id` (`agent_id`, `tool_id`), UNIQUE INDEX `uniq_idx_agent_tool_name` (`agent_id`, `tool_name`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Agent Tool";
-- Create "agent_tool_version" table
CREATE TABLE `opencoze`.`agent_tool_version` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Agent ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID", `agent_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Tool Version", `tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Name", `tool_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0", `sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path", `method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method", `operation` json NULL COMMENT "Tool Openapi Operation Schema", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", PRIMARY KEY (`id`), INDEX `idx_agent_tool_id_created_at` (`agent_id`, `tool_id`, `created_at`), INDEX `idx_agent_tool_name_created_at` (`agent_id`, `tool_name`, `created_at`), UNIQUE INDEX `uniq_idx_agent_tool_id_agent_version` (`agent_id`, `tool_id`, `agent_version`), UNIQUE INDEX `uniq_idx_agent_tool_name_agent_version` (`agent_id`, `tool_name`, `agent_version`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Agent Tool Version";
-- Create "api_key" table
CREATE TABLE `opencoze`.`api_key` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", `key` varchar(255) NOT NULL DEFAULT "" COMMENT "API Key hash", `name` varchar(255) NOT NULL DEFAULT "" COMMENT "API Key Name", `status` tinyint NOT NULL DEFAULT 0 COMMENT "0 normal, 1 deleted", `user_id` bigint NOT NULL DEFAULT 0 COMMENT "API Key Owner", `expired_at` bigint NOT NULL DEFAULT 0 COMMENT "API Key Expired Time", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `last_used_at` bigint NOT NULL DEFAULT 0 COMMENT "Used Time in Milliseconds", PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "api key table";
-- Create "app_connector_release_ref" table
CREATE TABLE `opencoze`.`app_connector_release_ref` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key", `record_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Record ID", `connector_id` bigint unsigned NULL COMMENT "Publish Connector ID", `publish_config` json NULL COMMENT "Publish Configuration", `publish_status` tinyint NOT NULL DEFAULT 0 COMMENT "Publish Status", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", PRIMARY KEY (`id`), UNIQUE INDEX `idx_record_connector` (`record_id`, `connector_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Connector Release Record Reference";
-- Create "app_draft" table
CREATE TABLE `opencoze`.`app_draft` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "APP ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI", `Name` varchar(255) NOT NULL DEFAULT "" COMMENT "Application Name", `desc` text NULL COMMENT "Application Description", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Application";
-- Create "app_release_record" table
CREATE TABLE `opencoze`.`app_release_record` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Record ID", `app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI", `Name` varchar(255) NOT NULL DEFAULT "" COMMENT "Application Name", `desc` text NULL COMMENT "Application Description", `connector_ids` json NULL COMMENT "Publish Connector IDs", `extra_info` json NULL COMMENT "Publish Extra Info", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Release Version", `version_desc` text NULL COMMENT "Version Description", `publish_status` tinyint NOT NULL DEFAULT 0 COMMENT "Publish Status", `publish_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Time in Milliseconds", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", PRIMARY KEY (`id`), INDEX `idx_app_publish_at` (`app_id`, `publish_at`), UNIQUE INDEX `uniq_idx_app_version_connector` (`app_id`, `version`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Application Release Record";
-- Create "conversation" table
CREATE TABLE `opencoze`.`conversation` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID", `connector_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "业务线 ID", `agent_id` bigint NOT NULL DEFAULT 0 COMMENT "agent_id", `scene` tinyint NOT NULL DEFAULT 0 COMMENT "会话场景", `section_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "最新section_id", `creator_id` bigint unsigned NULL DEFAULT 0 COMMENT "创建者id", `ext` text NULL COMMENT "扩展字段", `status` tinyint NOT NULL DEFAULT 1 COMMENT "status: 1-normal 2-deleted", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间", PRIMARY KEY (`id`), INDEX `idx_connector_bot_status` (`connector_id`, `agent_id`, `creator_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "会话信息表";
-- Create "data_copy_task" table
CREATE TABLE `opencoze`.`data_copy_task` (`master_task_id` varchar(128) NOT NULL DEFAULT "" COMMENT "复制任务ID", `origin_data_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源id", `target_data_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标id", `origin_space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源团队空间", `target_space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标团队空间", `origin_user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源用户ID", `target_user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标用户ID", `origin_app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源AppID", `target_app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标AppID", `data_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "数据类型 1:knowledge, 2:database", `ext_info` varchar(255) NOT NULL DEFAULT "" COMMENT "存储额外信息", `start_time` bigint NOT NULL DEFAULT 0 COMMENT "任务开始时间", `finish_time` bigint NULL COMMENT "任务结束时间", `status` tinyint NOT NULL DEFAULT 1 COMMENT "1:创建 2:执行中 3:成功 4:失败", `error_msg` varchar(128) NULL COMMENT "错误信息", PRIMARY KEY (`master_task_id`, `origin_data_id`, `data_type`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "data方向复制任务记录表";
-- Create "draft_database_info" table
CREATE TABLE `opencoze`.`draft_database_info` (`id` bigint unsigned NOT NULL COMMENT "ID", `app_id` bigint unsigned NULL COMMENT "App ID", `space_id` bigint unsigned NOT NULL COMMENT "Space ID", `related_online_id` bigint unsigned NOT NULL COMMENT "The primary key ID of online_database_info table", `is_visible` tinyint NOT NULL DEFAULT 1 COMMENT "Visibility: 0 invisible, 1 visible", `prompt_disabled` tinyint NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported", `table_name` varchar(255) NOT NULL COMMENT "Table name", `table_desc` varchar(256) NULL COMMENT "Table description", `table_field` text NULL COMMENT "Table field info", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID", `icon_uri` varchar(255) NOT NULL COMMENT "Icon Uri", `physical_table_name` varchar(255) NULL COMMENT "The name of the real physical table", `rw_mode` bigint NOT NULL DEFAULT 1 COMMENT "Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", PRIMARY KEY (`id`), INDEX `idx_space_app_creator_deleted` (`space_id`, `app_id`, `creator_id`, `deleted_at`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "draft database info";
-- Create "knowledge" table
CREATE TABLE `opencoze`.`knowledge` (`id` bigint unsigned NOT NULL COMMENT "主键ID", `name` varchar(150) NOT NULL DEFAULT "" COMMENT "名称", `app_id` bigint NOT NULL DEFAULT 0 COMMENT "项目ID标识该资源是否是项目独有", `creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "空间ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds", `status` tinyint NOT NULL DEFAULT 1 COMMENT "0 初始化, 1 生效 2 失效", `description` text NULL COMMENT "描述", `icon_uri` varchar(150) NULL COMMENT "头像uri", `format_type` tinyint NOT NULL DEFAULT 0 COMMENT "0:文本 1:表格 2:图片", PRIMARY KEY (`id`), INDEX `idx_app_id` (`app_id`), INDEX `idx_creator_id` (`creator_id`), INDEX `idx_space_id_deleted_at_updated_at` (`space_id`, `deleted_at`, `updated_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库表";
-- Create "knowledge_document" table
CREATE TABLE `opencoze`.`knowledge_document` (`id` bigint unsigned NOT NULL COMMENT "主键ID", `knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "所属knowledge的ID", `name` varchar(150) NOT NULL DEFAULT "" COMMENT "文档名称", `file_extension` varchar(20) NOT NULL DEFAULT "0" COMMENT "文档类型, txt/pdf/csv/...", `document_type` int NOT NULL DEFAULT 0 COMMENT "文档类型: 0:文本 1:表格 2:图片", `uri` text NULL COMMENT "资源uri", `size` bigint unsigned NOT NULL DEFAULT 0 COMMENT "文档大小", `slice_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT "分片数量", `char_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT "字符数", `creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建者ID", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间id", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds", `source_type` int NOT NULL DEFAULT 0 COMMENT "0:本地文件上传, 2:自定义文本", `status` int NOT NULL DEFAULT 0 COMMENT "状态", `fail_reason` TEXT NULL COMMENT "失败原因", `parse_rule` json NULL COMMENT "解析+切片规则", `table_info` json NULL COMMENT "表格信息", PRIMARY KEY (`id`), INDEX `idx_creator_id` (`creator_id`), INDEX `idx_knowledge_id_deleted_at_updated_at` (`knowledge_id`, `deleted_at`, `updated_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库文档表";
-- Create "knowledge_document_review" table
CREATE TABLE `opencoze`.`knowledge_document_review` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID", `knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "knowledge id", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间id", `name` varchar(150) NOT NULL DEFAULT "" COMMENT "文档名称", `type` varchar(10) NOT NULL DEFAULT "0" COMMENT "文档类型", `uri` text NULL COMMENT "资源标识", `format_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0 文本, 1 表格, 2 图片", `status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0 处理中1 已完成2 失败3 失效", `chunk_resp_uri` text NULL COMMENT "预切片tos资源标识", `deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者ID", PRIMARY KEY (`id`), INDEX `idx_dataset_id` (`knowledge_id`, `status`, `updated_at`), INDEX `idx_uri` (`uri` (100))) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "文档审阅表";
-- Create "knowledge_document_slice" table
CREATE TABLE `opencoze`.`knowledge_document_slice` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID", `knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "knowledge id", `document_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "document id", `content` text NULL COMMENT "切片内容", `sequence` double NOT NULL COMMENT "切片顺序号, 从1开始", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者ID", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间ID", `status` int NOT NULL DEFAULT 0 COMMENT "状态", `fail_reason` TEXT NULL COMMENT "失败原因", `hit` bigint unsigned NOT NULL DEFAULT 0 COMMENT "命中次数", PRIMARY KEY (`id`), INDEX `idx_document_id_deleted_at_sequence` (`document_id`, `deleted_at`, `sequence`), INDEX `idx_knowledge_id_document_id` (`knowledge_id`, `document_id`), INDEX `idx_sequence` (`sequence`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库文件切片表";
-- Create "message" table
CREATE TABLE `opencoze`.`message` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID", `run_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "对应的run_id", `conversation_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "conversation id", `user_id` varchar(60) NOT NULL DEFAULT "" COMMENT "user id", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id", `role` varchar(100) NOT NULL DEFAULT "" COMMENT "角色: user、assistant、system", `content_type` varchar(100) NOT NULL DEFAULT "" COMMENT "内容类型 1 text", `content` mediumtext NULL COMMENT "内容", `message_type` varchar(100) NOT NULL DEFAULT "" COMMENT "消息类型:", `display_content` text NULL COMMENT "展示内容", `ext` text NULL COMMENT "message 扩展字段" COLLATE utf8mb4_general_ci, `section_id` bigint unsigned NULL COMMENT "段落id", `broken_position` int NULL DEFAULT -1 COMMENT "打断位置", `status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "消息状态 1 Available 2 Deleted 3 Replaced 4 Broken 5 Failed 6 Streaming 7 Pending", `model_content` mediumtext NULL COMMENT "模型输入内容", `meta_info` text NULL COMMENT "引用、高亮等文本标记信息", `reasoning_content` text NULL COMMENT "思考内容" COLLATE utf8mb4_general_ci, `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间", PRIMARY KEY (`id`), INDEX `idx_conversation_id` (`conversation_id`), INDEX `idx_run_id` (`run_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "消息表";
-- Create "model_entity" table
CREATE TABLE `opencoze`.`model_entity` (`id` bigint unsigned NOT NULL COMMENT "主键ID", `meta_id` bigint unsigned NOT NULL COMMENT "模型元信息 id", `name` varchar(128) NOT NULL COMMENT "名称", `description` text NULL COMMENT "描述", `default_params` json NOT NULL COMMENT "默认参数", `scenario` bigint unsigned NOT NULL COMMENT "模型应用场景", `status` int NOT NULL DEFAULT 1 COMMENT "模型状态", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` bigint unsigned NULL COMMENT "Delete Time in Milliseconds", PRIMARY KEY (`id`), INDEX `idx_scenario` (`scenario`), INDEX `idx_status` (`status`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "模型信息";
-- Create "model_meta" table
CREATE TABLE `opencoze`.`model_meta` (`id` bigint unsigned NOT NULL COMMENT "主键ID", `model_name` varchar(128) NOT NULL COMMENT "模型名称", `protocol` varchar(128) NOT NULL COMMENT "模型协议", `icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI", `capability` json NULL COMMENT "模型能力", `conn_config` json NULL COMMENT "模型连接配置", `status` int NOT NULL DEFAULT 1 COMMENT "模型状态", `description` varchar(2048) NOT NULL DEFAULT "" COMMENT "模型描述", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` bigint unsigned NULL COMMENT "Delete Time in Milliseconds", `icon_url` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URL", PRIMARY KEY (`id`), INDEX `idx_status` (`status`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "模型元信息";
-- Create "node_execution" table
CREATE TABLE `opencoze`.`node_execution` (`id` bigint unsigned NOT NULL COMMENT "node execution id", `execute_id` bigint unsigned NOT NULL COMMENT "the workflow execute id this node execution belongs to", `node_id` varchar(128) NOT NULL COMMENT "node key", `node_name` varchar(128) NOT NULL COMMENT "name of the node", `node_type` varchar(128) NOT NULL COMMENT "the type of the node, in string", `created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond", `status` tinyint unsigned NOT NULL COMMENT "1=waiting 2=running 3=success 4=fail", `duration` bigint unsigned NULL COMMENT "execution duration in millisecond", `input` mediumtext NULL COMMENT "actual input of the node", `output` mediumtext NULL COMMENT "actual output of the node", `raw_output` mediumtext NULL COMMENT "the original output of the node", `error_info` mediumtext NULL COMMENT "error info", `error_level` varchar(32) NULL COMMENT "level of the error", `input_tokens` bigint unsigned NULL COMMENT "number of input tokens", `output_tokens` bigint unsigned NULL COMMENT "number of output tokens", `updated_at` bigint unsigned NULL COMMENT "update time in millisecond", `composite_node_index` bigint unsigned NULL COMMENT "loop or batch's execution index", `composite_node_items` mediumtext NULL COMMENT "the items extracted from parent composite node for this index", `parent_node_id` varchar(128) NULL COMMENT "when as inner node for loop or batch, this is the parent node's key", `sub_execute_id` bigint unsigned NULL COMMENT "if this node is sub_workflow, the exe id of the sub workflow", `extra` mediumtext NULL COMMENT "extra info", PRIMARY KEY (`id`), INDEX `idx_execute_id_node_id` (`execute_id`, `node_id`), INDEX `idx_execute_id_parent_node_id` (`execute_id`, `parent_node_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "online_database_info" table
CREATE TABLE `opencoze`.`online_database_info` (`id` bigint unsigned NOT NULL COMMENT "ID", `app_id` bigint unsigned NULL COMMENT "App ID", `space_id` bigint unsigned NOT NULL COMMENT "Space ID", `related_draft_id` bigint unsigned NOT NULL COMMENT "The primary key ID of draft_database_info table", `is_visible` tinyint NOT NULL DEFAULT 1 COMMENT "Visibility: 0 invisible, 1 visible", `prompt_disabled` tinyint NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported", `table_name` varchar(255) NOT NULL COMMENT "Table name", `table_desc` varchar(256) NULL COMMENT "Table description", `table_field` text NULL COMMENT "Table field info", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID", `icon_uri` varchar(255) NOT NULL COMMENT "Icon Uri", `physical_table_name` varchar(255) NULL COMMENT "The name of the real physical table", `rw_mode` bigint NOT NULL DEFAULT 1 COMMENT "Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", PRIMARY KEY (`id`), INDEX `idx_space_app_creator_deleted` (`space_id`, `app_id`, `creator_id`, `deleted_at`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "online database info";
-- Create "plugin" table
CREATE TABLE `opencoze`.`plugin` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID", `app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI", `server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL", `plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Plugin Version, e.g. v1.0.0", `version_desc` text NULL COMMENT "Plugin Version Description", `manifest` json NULL COMMENT "Plugin Manifest", `openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root", PRIMARY KEY (`id`), INDEX `idx_space_created_at` (`space_id`, `created_at`), INDEX `idx_space_updated_at` (`space_id`, `updated_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Latest Plugin";
-- Create "plugin_draft" table
CREATE TABLE `opencoze`.`plugin_draft` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID", `app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI", `server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL", `plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", `manifest` json NULL COMMENT "Plugin Manifest", `openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root", PRIMARY KEY (`id`), INDEX `idx_app_id` (`app_id`, `id`), INDEX `idx_space_app_created_at` (`space_id`, `app_id`, `created_at`), INDEX `idx_space_app_updated_at` (`space_id`, `app_id`, `updated_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Plugin";
-- Create "plugin_oauth_auth" table
CREATE TABLE `opencoze`.`plugin_oauth_auth` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key", `user_id` varchar(255) NOT NULL DEFAULT "" COMMENT "User ID", `plugin_id` bigint NOT NULL DEFAULT 0 COMMENT "Plugin ID", `is_draft` bool NOT NULL DEFAULT 0 COMMENT "Is Draft Plugin", `oauth_config` json NULL COMMENT "Authorization Code OAuth Config", `access_token` varchar(1024) NOT NULL DEFAULT "" COMMENT "Access Token", `refresh_token` varchar(1024) NOT NULL DEFAULT "" COMMENT "Refresh Token", `token_expired_at` bigint NULL COMMENT "Token Expired in Milliseconds", `next_token_refresh_at` bigint NULL COMMENT "Next Token Refresh Time in Milliseconds", `last_active_at` bigint NULL COMMENT "Last active time in Milliseconds", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", PRIMARY KEY (`id`), INDEX `idx_last_active_at` (`last_active_at`), INDEX `idx_last_token_expired_at` (`token_expired_at`), INDEX `idx_next_token_refresh_at` (`next_token_refresh_at`), UNIQUE INDEX `uniq_idx_user_plugin_is_draft` (`user_id`, `plugin_id`, `is_draft`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Plugin OAuth Authorization Code Info";
-- Create "plugin_version" table
CREATE TABLE `opencoze`.`plugin_version` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI", `server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL", `plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Plugin Version, e.g. v1.0.0", `version_desc` text NULL COMMENT "Plugin Version Description", `manifest` json NULL COMMENT "Plugin Manifest", `openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", PRIMARY KEY (`id`), UNIQUE INDEX `uniq_idx_plugin_version` (`plugin_id`, `version`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Plugin Version";
-- Create "prompt_resource" table
CREATE TABLE `opencoze`.`prompt_resource` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "主键ID", `space_id` bigint NOT NULL COMMENT "空间ID", `name` varchar(255) NOT NULL COMMENT "名称", `description` varchar(255) NOT NULL COMMENT "描述", `prompt_text` mediumtext NULL COMMENT "prompt正文", `status` int NOT NULL COMMENT "状态,0无效,1有效", `creator_id` bigint NOT NULL COMMENT "创建者ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间", PRIMARY KEY (`id`), INDEX `idx_creator_id` (`creator_id`)) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "prompt_resource";
-- Create "run_record" table
CREATE TABLE `opencoze`.`run_record` (`id` bigint unsigned NOT NULL COMMENT "主键ID", `conversation_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "会话 ID", `section_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "section ID", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id", `user_id` varchar(255) NOT NULL DEFAULT "" COMMENT "user id", `source` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "执行来源 0 API,", `token_count` int NOT NULL DEFAULT 0 COMMENT "token 消耗", `output_tokens` int NOT NULL DEFAULT 0 COMMENT "消耗的 output token 数", `input_tokens` int NOT NULL DEFAULT 0 COMMENT "消耗的 input token 数", `status` varchar(255) NOT NULL DEFAULT "" COMMENT "状态,0 Unknown, 1-Created,2-InProgress,3-Completed,4-Failed,5-Expired,6-Cancelled,7-RequiresAction", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者标识", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间", `failed_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "失败时间", `last_error` text NULL COMMENT "error message" COLLATE utf8mb4_general_ci, `completed_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "结束时间", `chat_request` text NULL COMMENT "保存原始请求的部分字段" COLLATE utf8mb4_general_ci, `ext` text NULL COMMENT "扩展字段" COLLATE utf8mb4_general_ci, PRIMARY KEY (`id`), INDEX `idx_c_s` (`conversation_id`, `section_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "执行记录表";
-- Create "shortcut_command" table
CREATE TABLE `opencoze`.`shortcut_command` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID", `object_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "实体ID,该实体可用这个指令", `command_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "命令ID", `command_name` varchar(255) NOT NULL DEFAULT "" COMMENT "命令名称", `shortcut_command` varchar(255) NOT NULL DEFAULT "" COMMENT "快捷指令", `description` varchar(2000) NOT NULL DEFAULT "" COMMENT "命令描述", `send_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "发送类型 0:query 1:panel", `tool_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "使用工具的type 1:workFlow 2:插件", `work_flow_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "使用workFlow的id", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "使用插件的id", `plugin_tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "使用插件的api_name", `template_query` text NULL COMMENT "query模板", `components` json NULL COMMENT "panel参数", `card_schema` text NULL COMMENT "卡片schema", `tool_info` json NULL COMMENT "工具信息 包含name+变量列表", `status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "状态,0无效,1有效", `creator_id` bigint unsigned NULL DEFAULT 0 COMMENT "创建者ID", `is_online` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "是否为线上信息 0草稿 1线上", `created_at` bigint NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint NOT NULL DEFAULT 0 COMMENT "更新时间", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "multi的指令时该指令由哪个节点执行", `shortcut_icon` json NULL COMMENT "快捷指令图标", `plugin_tool_id` bigint NOT NULL DEFAULT 0 COMMENT "tool_id", PRIMARY KEY (`id`), UNIQUE INDEX `uniq_object_command_id_type` (`object_id`, `command_id`, `is_online`)) CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "bot快捷指令表";
-- Create "single_agent_draft" table
CREATE TABLE `opencoze`.`single_agent_draft` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", `agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID", `name` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Name", `desc` text NOT NULL COMMENT "Agent Description", `icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime(3) NULL COMMENT "delete time in millisecond", `variables_meta_id` bigint NULL COMMENT "variables meta 表 ID", `model_info` json NULL COMMENT "Model Configuration Information", `onboarding_info` json NULL COMMENT "Onboarding Information", `prompt` json NULL COMMENT "Agent Prompt Configuration", `plugin` json NULL COMMENT "Agent Plugin Base Configuration", `knowledge` json NULL COMMENT "Agent Knowledge Base Configuration", `workflow` json NULL COMMENT "Agent Workflow Configuration", `suggest_reply` json NULL COMMENT "Suggested Replies", `jump_config` json NULL COMMENT "Jump Configuration", `background_image_info_list` json NULL COMMENT "Background image", `database` json NULL COMMENT "Agent Database Base Configuration", `shortcut_command` json NULL COMMENT "shortcut command", PRIMARY KEY (`id`), UNIQUE INDEX `idx_agent_id` (`agent_id`), INDEX `idx_creator_id` (`creator_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Single Agent Draft Copy Table";
-- Create "single_agent_publish" table
CREATE TABLE `opencoze`.`single_agent_publish` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键id", `agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id", `publish_id` varchar(50) NOT NULL DEFAULT "" COMMENT "发布 id" COLLATE utf8mb4_general_ci, `connector_ids` json NULL COMMENT "发布的 connector_ids", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Version", `publish_info` text NULL COMMENT "发布信息" COLLATE utf8mb4_general_ci, `publish_time` bigint unsigned NOT NULL DEFAULT 0 COMMENT "发布时间", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "发布人 user_id", `status` tinyint NOT NULL DEFAULT 0 COMMENT "状态 0:使用中 1:删除 3:禁用", `extra` json NULL COMMENT "扩展字段", PRIMARY KEY (`id`), INDEX `idx_agent_id_version` (`agent_id`, `version`), INDEX `idx_creator_id` (`creator_id`), INDEX `idx_publish_id` (`publish_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "bot 渠道和发布版本流水表";
-- Create "single_agent_version" table
CREATE TABLE `opencoze`.`single_agent_version` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", `agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID", `creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID", `name` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Name", `desc` text NOT NULL COMMENT "Agent Description", `icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `deleted_at` datetime(3) NULL COMMENT "delete time in millisecond", `variables_meta_id` bigint NULL COMMENT "variables meta 表 ID", `model_info` json NULL COMMENT "Model Configuration Information", `onboarding_info` json NULL COMMENT "Onboarding Information", `prompt` json NULL COMMENT "Agent Prompt Configuration", `plugin` json NULL COMMENT "Agent Plugin Base Configuration", `knowledge` json NULL COMMENT "Agent Knowledge Base Configuration", `workflow` json NULL COMMENT "Agent Workflow Configuration", `suggest_reply` json NULL COMMENT "Suggested Replies", `jump_config` json NULL COMMENT "Jump Configuration", `connector_id` bigint unsigned NOT NULL COMMENT "Connector ID", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Version", `background_image_info_list` json NULL COMMENT "Background image", `database` json NULL COMMENT "Agent Database Base Configuration", `shortcut_command` json NULL COMMENT "shortcut command", PRIMARY KEY (`id`), UNIQUE INDEX `idx_agent_id_and_version_connector_id` (`agent_id`, `version`, `connector_id`), INDEX `idx_creator_id` (`creator_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Single Agent Version Copy Table";
-- Create "space" table
CREATE TABLE `opencoze`.`space` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID, Space ID", `owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID", `name` varchar(200) NOT NULL DEFAULT "" COMMENT "Space Name", `description` varchar(2000) NOT NULL DEFAULT "" COMMENT "Space Description", `icon_uri` varchar(200) NOT NULL DEFAULT "" COMMENT "Icon URI", `creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creator ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)", `deleted_at` bigint unsigned NULL COMMENT "Deletion Time (Milliseconds)", PRIMARY KEY (`id`), INDEX `idx_creator_id` (`creator_id`), INDEX `idx_owner_id` (`owner_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Space Table" AUTO_INCREMENT 666;
-- Create "space_user" table
CREATE TABLE `opencoze`.`space_user` (`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID, Auto Increment", `space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID", `user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "User ID", `role_type` int NOT NULL DEFAULT 3 COMMENT "Role Type: 1.owner 2.admin 3.member", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)", PRIMARY KEY (`id`), INDEX `idx_user_id` (`user_id`), UNIQUE INDEX `uk_space_user` (`space_id`, `user_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Space Member Table";
-- Create "template" table
CREATE TABLE `opencoze`.`template` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", `agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID", `workflow_id` bigint NOT NULL DEFAULT 0 COMMENT "Workflow ID", `space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `heat` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Heat", `product_entity_type` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Product Entity Type", `meta_info` json NULL COMMENT "Meta Info", `agent_extra` json NULL COMMENT "Agent Extra Info", `workflow_extra` json NULL COMMENT "Workflow Extra Info", `project_extra` json NULL COMMENT "Project Extra Info", PRIMARY KEY (`id`), UNIQUE INDEX `idx_agent_id` (`agent_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Template Info Table";
-- Create "tool" table
CREATE TABLE `opencoze`.`tool` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0", `sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path", `method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method", `operation` json NULL COMMENT "Tool Openapi Operation Schema", `activated_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:activated; 1:deactivated", PRIMARY KEY (`id`), INDEX `idx_plugin_activated_status` (`plugin_id`, `activated_status`), UNIQUE INDEX `uniq_idx_plugin_sub_url_method` (`plugin_id`, `sub_url`, `method`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Latest Tool";
-- Create "tool_draft" table
CREATE TABLE `opencoze`.`tool_draft` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds", `sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path", `method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method", `operation` json NULL COMMENT "Tool Openapi Operation Schema", `debug_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:not pass; 1:pass", `activated_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:activated; 1:deactivated", PRIMARY KEY (`id`), INDEX `idx_plugin_created_at_id` (`plugin_id`, `created_at`, `id`), UNIQUE INDEX `uniq_idx_plugin_sub_url_method` (`plugin_id`, `sub_url`, `method`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Tool";
-- Create "tool_version" table
CREATE TABLE `opencoze`.`tool_version` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID", `tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID", `plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID", `version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0", `sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path", `method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method", `operation` json NULL COMMENT "Tool Openapi Operation Schema", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds", `deleted_at` datetime NULL COMMENT "Delete Time", PRIMARY KEY (`id`), UNIQUE INDEX `uniq_idx_tool_version` (`tool_id`, `version`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Tool Version";
-- Create "user" table
CREATE TABLE `opencoze`.`user` (`id` bigint NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", `name` varchar(128) NOT NULL DEFAULT "" COMMENT "User Nickname", `unique_name` varchar(128) NOT NULL DEFAULT "" COMMENT "User Unique Name", `email` varchar(128) NOT NULL DEFAULT "" COMMENT "Email", `password` varchar(128) NOT NULL DEFAULT "" COMMENT "Password (Encrypted)", `description` varchar(512) NOT NULL DEFAULT "" COMMENT "User Description", `icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Avatar URI", `user_verified` bool NOT NULL DEFAULT 0 COMMENT "User Verification Status", `locale` varchar(128) NOT NULL DEFAULT "" COMMENT "Locale", `session_key` varchar(256) NOT NULL DEFAULT "" COMMENT "Session Key", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)", `deleted_at` bigint unsigned NULL COMMENT "Deletion Time (Milliseconds)", PRIMARY KEY (`id`), UNIQUE INDEX `idx_email` (`email`), INDEX `idx_session_key` (`session_key`), UNIQUE INDEX `idx_unique_name` (`unique_name`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "User Table";
-- Create "variable_instance" table
CREATE TABLE `opencoze`.`variable_instance` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID", `biz_type` tinyint unsigned NOT NULL COMMENT "1 for agent2 for app", `biz_id` varchar(128) NOT NULL DEFAULT "" COMMENT "1 for agent_id2 for app_id", `version` varchar(255) NOT NULL COMMENT "agent or project 版本,为空代表草稿态", `keyword` varchar(255) NOT NULL COMMENT "记忆的KEY", `type` tinyint NOT NULL COMMENT "记忆类型 1 KV 2 list", `content` text NULL COMMENT "记忆内容", `connector_uid` varchar(255) NOT NULL COMMENT "二方用户ID", `connector_id` bigint NOT NULL COMMENT "二方id, e.g. coze = 10000010", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间", PRIMARY KEY (`id`), INDEX `idx_connector_key` (`biz_id`, `biz_type`, `version`, `connector_uid`, `connector_id`)) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "KV Memory";
-- Create "variables_meta" table
CREATE TABLE `opencoze`.`variables_meta` (`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID", `creator_id` bigint unsigned NOT NULL COMMENT "创建者ID", `biz_type` tinyint unsigned NOT NULL COMMENT "1 for agent2 for app", `biz_id` varchar(128) NOT NULL DEFAULT "" COMMENT "1 for agent_id2 for app_id", `variable_list` json NULL COMMENT "变量配置的json数据", `created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "create time", `updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "update time", `version` varchar(255) NOT NULL COMMENT "project版本,为空代表草稿态", PRIMARY KEY (`id`), UNIQUE INDEX `idx_project_key` (`biz_id`, `biz_type`, `version`), INDEX `idx_user_key` (`creator_id`)) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "KV Memory meta";
-- Create "workflow_draft" table
CREATE TABLE `opencoze`.`workflow_draft` (`id` bigint unsigned NOT NULL COMMENT "workflow ID", `canvas` mediumtext NOT NULL COMMENT "前端 schema", `input_params` mediumtext NULL COMMENT " 入参 schema", `output_params` mediumtext NULL COMMENT " 出参 schema", `test_run_success` bool NOT NULL DEFAULT 0 COMMENT "0 未运行, 1 运行成功", `modified` bool NOT NULL DEFAULT 0 COMMENT "0 未被修改, 1 已被修改", `updated_at` bigint unsigned NULL, `deleted_at` datetime(3) NULL, `commit_id` varchar(255) NOT NULL COMMENT "used to uniquely identify a draft snapshot", PRIMARY KEY (`id`), INDEX `idx_updated_at` (`updated_at` DESC)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "workflow_execution" table
CREATE TABLE `opencoze`.`workflow_execution` (`id` bigint unsigned NOT NULL COMMENT "execute id", `workflow_id` bigint unsigned NOT NULL COMMENT "workflow_id", `version` varchar(50) NULL COMMENT "workflow version. empty if is draft", `space_id` bigint unsigned NOT NULL COMMENT "the space id the workflow belongs to", `mode` tinyint unsigned NOT NULL COMMENT "the execution mode: 1. debug run 2. release run 3. node debug", `operator_id` bigint unsigned NOT NULL COMMENT "the user id that runs this workflow", `connector_id` bigint unsigned NULL COMMENT "the connector on which this execution happened", `connector_uid` varchar(64) NULL COMMENT "user id of the connector", `created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond", `log_id` varchar(128) NULL COMMENT "log id", `status` tinyint unsigned NULL COMMENT "1=running 2=success 3=fail 4=interrupted", `duration` bigint unsigned NULL COMMENT "execution duration in millisecond", `input` mediumtext NULL COMMENT "actual input of this execution", `output` mediumtext NULL COMMENT "the actual output of this execution", `error_code` varchar(255) NULL COMMENT "error code if any", `fail_reason` mediumtext NULL COMMENT "the reason for failure", `input_tokens` bigint unsigned NULL COMMENT "number of input tokens", `output_tokens` bigint unsigned NULL COMMENT "number of output tokens", `updated_at` bigint unsigned NULL COMMENT "update time in millisecond", `root_execution_id` bigint unsigned NULL COMMENT "the top level execution id. Null if this is the root", `parent_node_id` varchar(128) NULL COMMENT "the node key for the sub_workflow node that executes this workflow", `app_id` bigint unsigned NULL COMMENT "app id this workflow execution belongs to", `node_count` mediumint unsigned NULL COMMENT "the total node count of the workflow", `resume_event_id` bigint unsigned NULL COMMENT "the current event ID which is resuming", `agent_id` bigint unsigned NULL COMMENT "the agent that this execution binds to", `sync_pattern` tinyint unsigned NULL COMMENT "the sync pattern 1. sync 2. async 3. stream", `commit_id` varchar(255) NULL COMMENT "draft commit id this execution belongs to", PRIMARY KEY (`id`), INDEX `idx_workflow_id_version_mode_created_at` (`workflow_id`, `version`, `mode`, `created_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "workflow_meta" table
CREATE TABLE `opencoze`.`workflow_meta` (`id` bigint unsigned NOT NULL COMMENT "workflow id", `name` varchar(256) NOT NULL COMMENT "workflow name", `description` varchar(2000) NOT NULL COMMENT "workflow description", `icon_uri` varchar(256) NOT NULL COMMENT "icon uri", `status` tinyint unsigned NOT NULL COMMENT "0:未发布过, 1:已发布过", `content_type` tinyint unsigned NOT NULL COMMENT "0用户 1官方", `mode` tinyint unsigned NOT NULL COMMENT "0:workflow, 3:chat_flow", `created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond", `updated_at` bigint unsigned NULL COMMENT "update time in millisecond", `deleted_at` datetime(3) NULL COMMENT "delete time in millisecond", `creator_id` bigint unsigned NOT NULL COMMENT "user id for creator", `tag` tinyint unsigned NULL COMMENT "template tag: Tag: 1=All, 2=Hot, 3=Information, 4=Music, 5=Picture, 6=UtilityTool, 7=Life, 8=Traval, 9=Network, 10=System, 11=Movie, 12=Office, 13=Shopping, 14=Education, 15=Health, 16=Social, 17=Entertainment, 18=Finance, 100=Hidden", `author_id` bigint unsigned NOT NULL COMMENT "原作者用户 ID", `space_id` bigint unsigned NOT NULL COMMENT " 空间 ID", `updater_id` bigint unsigned NULL COMMENT " 更新元信息的用户 ID", `source_id` bigint unsigned NULL COMMENT " 复制来源的 workflow ID", `app_id` bigint unsigned NULL COMMENT "应用 ID", `latest_version` varchar(50) NULL COMMENT "the version of the most recent publish", `latest_version_ts` bigint unsigned NULL COMMENT "create time of latest version", PRIMARY KEY (`id`), INDEX `idx_app_id` (`app_id`), INDEX `idx_latest_version_ts` (`latest_version_ts` DESC), INDEX `idx_space_id_app_id_status_latest_version_ts` (`space_id`, `app_id`, `status`, `latest_version_ts`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "workflow_reference" table
CREATE TABLE `opencoze`.`workflow_reference` (`id` bigint unsigned NOT NULL COMMENT "workflow id", `referred_id` bigint unsigned NOT NULL COMMENT "the id of the workflow that is referred by other entities", `referring_id` bigint unsigned NOT NULL COMMENT "the entity id that refers this workflow", `refer_type` tinyint unsigned NOT NULL COMMENT "1 subworkflow 2 tool", `referring_biz_type` tinyint unsigned NOT NULL COMMENT "the biz type the referring entity belongs to: 1. workflow 2. agent", `created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond", `status` tinyint unsigned NOT NULL COMMENT "whether this reference currently takes effect. 0: disabled 1: enabled", `deleted_at` datetime(3) NULL, PRIMARY KEY (`id`), INDEX `idx_referred_id_referring_biz_type_status` (`referred_id`, `referring_biz_type`, `status`), INDEX `idx_referring_id_status` (`referring_id`, `status`), UNIQUE INDEX `uniq_referred_id_referring_id_refer_type` (`referred_id`, `referring_id`, `refer_type`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "workflow_snapshot" table
CREATE TABLE `opencoze`.`workflow_snapshot` (`workflow_id` bigint unsigned NOT NULL COMMENT "workflow id this snapshot belongs to", `commit_id` varchar(255) NOT NULL COMMENT "the commit id of the workflow draft", `canvas` mediumtext NOT NULL COMMENT "frontend schema for this snapshot", `input_params` mediumtext NULL COMMENT "input parameter info", `output_params` mediumtext NULL COMMENT "output parameter info", `created_at` bigint unsigned NOT NULL, PRIMARY KEY (`workflow_id`, `commit_id`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "snapshot for executed workflow draft";
-- Create "workflow_version" table
CREATE TABLE `opencoze`.`workflow_version` (`id` bigint unsigned NOT NULL COMMENT "workflow id", `version` varchar(50) NOT NULL COMMENT "发布版本", `version_description` varchar(2000) NOT NULL COMMENT "版本描述", `canvas` mediumtext NOT NULL COMMENT "前端 schema", `input_params` mediumtext NULL, `output_params` mediumtext NULL, `creator_id` bigint unsigned NOT NULL COMMENT "发布用户 ID", `created_at` bigint unsigned NOT NULL COMMENT "创建时间毫秒时间戳", `deleted_at` datetime(3) NULL COMMENT "删除毫秒时间戳", `commit_id` varchar(255) NOT NULL COMMENT "the commit id corresponding to this version", PRIMARY KEY (`id`, `version`), INDEX `idx_id_created_at` (`id`, `created_at`)) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@@ -0,0 +1,2 @@
-- Modify "run_record" table
ALTER TABLE `opencoze`.`run_record` DROP COLUMN `token_count`, DROP COLUMN `output_tokens`, DROP COLUMN `input_tokens`, ADD COLUMN `usage` json NULL COMMENT "usage";

View File

@@ -0,0 +1,2 @@
-- Modify "plugin_oauth_auth" table
ALTER TABLE `opencoze`.`plugin_oauth_auth` MODIFY COLUMN `access_token` text NOT NULL COMMENT "Access Token", MODIFY COLUMN `refresh_token` text NOT NULL COMMENT "Refresh Token";

View File

@@ -0,0 +1,10 @@
-- Modify "api_key" table
ALTER TABLE `opencoze`.`api_key` RENAME COLUMN `key` TO `api_key`;
-- Modify "app_draft" table
ALTER TABLE `opencoze`.`app_draft` RENAME COLUMN `desc` TO `description`;
-- Modify "app_release_record" table
ALTER TABLE `opencoze`.`app_release_record` RENAME COLUMN `desc` TO `description`;
-- Modify "single_agent_draft" table
ALTER TABLE `opencoze`.`single_agent_draft` RENAME COLUMN `desc` TO `description`, RENAME COLUMN `database` TO `database_config`;
-- Modify "single_agent_version" table
ALTER TABLE `opencoze`.`single_agent_version` RENAME COLUMN `desc` TO `description`, RENAME COLUMN `database` TO `database_config`;

View File

@@ -0,0 +1,38 @@
-- Modify "api_key" table
ALTER TABLE `opencoze`.`api_key` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID";
-- Modify "app_connector_release_ref" table
ALTER TABLE `opencoze`.`app_connector_release_ref` RENAME INDEX `idx_record_connector` TO `uniq_record_connector`;
-- Modify "app_draft" table
ALTER TABLE `opencoze`.`app_draft` RENAME COLUMN `Name` TO `name`;
-- Modify "app_release_record" table
ALTER TABLE `opencoze`.`app_release_record` RENAME COLUMN `Name` TO `name`;
-- Modify "knowledge_document_slice" table
ALTER TABLE `opencoze`.`knowledge_document_slice` MODIFY COLUMN `sequence` decimal(20,5) NOT NULL COMMENT "切片顺序号, 从1开始";
-- Modify "model_entity" table
ALTER TABLE `opencoze`.`model_entity` MODIFY COLUMN `default_params` json NULL COMMENT "默认参数";
-- Modify "node_execution" table
ALTER TABLE `opencoze`.`node_execution` COMMENT "node 节点运行记录用于记录每次workflow执行时每个节点的状态信息", COLLATE utf8mb4_0900_ai_ci;
-- Modify "prompt_resource" table
ALTER TABLE `opencoze`.`prompt_resource` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID";
-- Modify "single_agent_draft" table
ALTER TABLE `opencoze`.`single_agent_draft` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", RENAME INDEX `idx_agent_id` TO `uniq_agent_id`;
-- Modify "single_agent_version" table
ALTER TABLE `opencoze`.`single_agent_version` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", RENAME INDEX `idx_agent_id_and_version_connector_id` TO `uniq_agent_id_and_version_connector_id`;
-- Modify "space_user" table
ALTER TABLE `opencoze`.`space_user` RENAME INDEX `uk_space_user` TO `uniq_space_user`;
-- Modify "template" table
ALTER TABLE `opencoze`.`template` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", RENAME INDEX `idx_agent_id` TO `uniq_agent_id`;
-- Modify "user" table
ALTER TABLE `opencoze`.`user` AUTO_INCREMENT 888, MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID", RENAME INDEX `idx_email` TO `uniq_email`, RENAME INDEX `idx_unique_name` TO `uniq_unique_name`;
-- Modify "variables_meta" table
ALTER TABLE `opencoze`.`variables_meta` RENAME INDEX `idx_project_key` TO `uniq_project_key`;
-- Modify "workflow_draft" table
ALTER TABLE `opencoze`.`workflow_draft` COMMENT "workflow 画布草稿表用于记录workflow最新的草稿画布信息";
-- Modify "workflow_execution" table
ALTER TABLE `opencoze`.`workflow_execution` COMMENT "workflow 执行记录表用于记录每次workflow执行时的状态";
-- Modify "workflow_meta" table
ALTER TABLE `opencoze`.`workflow_meta` COMMENT "workflow 元信息表用于记录workflow基本的元信息";
-- Modify "workflow_reference" table
ALTER TABLE `opencoze`.`workflow_reference` COMMENT "workflow 关联关系表用于记录workflow 直接互相引用关系";
-- Modify "workflow_version" table
ALTER TABLE `opencoze`.`workflow_version` COMMENT "workflow 画布版本信息表,用于记录不同版本的画布信息";

View File

@@ -0,0 +1,8 @@
-- Modify "data_copy_task" table
ALTER TABLE `opencoze`.`data_copy_task` ADD COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID", DROP PRIMARY KEY, ADD PRIMARY KEY (`id`), ADD UNIQUE INDEX `uniq_master_task_id_origin_data_id_data_type` (`master_task_id`, `origin_data_id`, `data_type`);
-- Modify "workflow_snapshot" table
ALTER TABLE `opencoze`.`workflow_snapshot` ADD COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID", DROP PRIMARY KEY, ADD PRIMARY KEY (`id`), ADD UNIQUE INDEX `uniq_workflow_id_commit_id` (`workflow_id`, `commit_id`);
-- Modify "workflow_version" table
ALTER TABLE `opencoze`.`workflow_version` DROP INDEX `idx_id_created_at`;
-- Modify "workflow_version" table
ALTER TABLE `opencoze`.`workflow_version` MODIFY COLUMN `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID", ADD COLUMN `workflow_id` bigint unsigned NOT NULL COMMENT "workflow id", DROP PRIMARY KEY, ADD PRIMARY KEY (`id`), ADD INDEX `idx_id_created_at` (`workflow_id`, `created_at`), ADD UNIQUE INDEX `uniq_workflow_id_version` (`workflow_id`, `version`);

View File

@@ -0,0 +1,12 @@
-- Create "connector_workflow_version" table
CREATE TABLE `opencoze`.`connector_workflow_version` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "id",
`app_id` bigint unsigned NOT NULL COMMENT "app id",
`connector_id` bigint unsigned NOT NULL COMMENT "connector id",
`workflow_id` bigint unsigned NOT NULL COMMENT "workflow id",
`version` varchar(256) NOT NULL COMMENT "version",
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
PRIMARY KEY (`id`),
INDEX `idx_connector_id_workflow_id_create_at` (`connector_id`, `workflow_id`, `created_at`),
UNIQUE INDEX `idx_connector_id_workflow_id_version` (`connector_id`, `workflow_id`, `version`)
) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@@ -0,0 +1,8 @@
h1:6MVlbZNblz3Fs7fkT8xJhLsjCBfs8+PpnALEU+5WANo=
20250703095335_initial.sql h1:/joaeUTMhXqAEc0KwsSve5+bYM0qPOp+9OizJtsRc+U=
20250703115304_update.sql h1:cbYo6Q6Lh96hB4hu5KW2Nn/Mr0VDpg7a1WPgpIb1SOc=
20250704040445_update.sql h1:QWmoPY//oQ+GFZwET9w/oAWa8mM0KVaD5G8Yiu9bMqY=
20250708075302_update.sql h1:QGyaDOKhpdgSrb2CsqsiqL+FKMvXaLjxdMtwt+QsuRA=
20250710100212_update.sql h1:mN/3iKQDoIw2BTkMwWp3I/qOAcVGrQJ5tOJ0OqH4ZWU=
20250711034533_update.sql h1:EWeK//5urS9hJIRCeD3lwQYWNH9AIKEWG9pMLdw7KPc=
20250717125913_update.sql h1:WtPR99RlWZn0rXZsB19qp1hq0FwO5qmFhcTcV6EnFYs=

File diff suppressed because it is too large Load Diff

564
docker/docker-compose.yml Executable file
View File

@@ -0,0 +1,564 @@
x-env-file: &env_file
- .env
services:
mysql:
image: mysql:8.4.5
container_name: coze-mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
MYSQL_DATABASE: ${MYSQL_DATABASE:-opencoze}
MYSQL_USER: ${MYSQL_USER:-coze}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:-coze123}
profiles: ['middleware', 'mysql-setup', 'mysql']
env_file: *env_file
ports:
- '3306:3306'
volumes:
- ./data/mysql:/var/lib/mysql
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
healthcheck:
test:
[
'CMD',
'mysqladmin',
'ping',
'-h',
'localhost',
'-u$${MYSQL_USER}',
'-p$${MYSQL_PASSWORD}',
]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
networks:
- coze-network
redis:
image: bitnami/redis:8.0
container_name: coze-redis
user: root
privileged: true
profiles: ['middleware']
env_file: *env_file
environment:
- REDIS_AOF_ENABLED=${REDIS_AOF_ENABLED:-no}
- REDIS_PORT_NUMBER=${REDIS_PORT_NUMBER:-6379}
- REDIS_IO_THREADS=${REDIS_IO_THREADS:-4}
- ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD:-yes}
ports:
- '6379:6379'
volumes:
- ./data/bitnami/redis:/bitnami/redis/data:rw,Z
command: >
bash -c "
/opt/bitnami/scripts/redis/setup.sh
# Set proper permissions for data directories
chown -R redis:redis /bitnami/redis/data
chmod g+s /bitnami/redis/data
exec /opt/bitnami/scripts/redis/entrypoint.sh /opt/bitnami/scripts/redis/run.sh
"
depends_on:
minio-setup:
condition: service_completed_successfully
elasticsearch-setup:
condition: service_completed_successfully
mysql-setup-schema:
condition: service_completed_successfully
mysql-setup-init-sql:
condition: service_completed_successfully
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
networks:
- coze-network
# rocketmq-namesrv:
# image: apache/rocketmq:5.3.2
# container_name: coze-rocketmq-namesrv
# privileged: true
# user: root
# profiles: ['middleware']
# env_file: *env_file
# ports:
# - '9876:9876'
# volumes:
# - ./data/rocketmq/namesrv/logs:/home/rocketmq/logs:rw,Z
# - ./data/rocketmq/namesrv/store:/home/rocketmq/store:rw,Z
# environment:
# - ALLOW_ANONYMOUS_LOGIN=yes
# command: >
# bash -c "
# # Set proper permissions for data directories
# mkdir -p /home/rocketmq/logs /home/rocketmq/store
# mkdir -p /home/rocketmq/logs/rocketmqlogs
# touch /home/rocketmq/logs/rocketmqlogs/tools.log
# touch /home/rocketmq/logs/rocketmqlogs/tools_default.log
# chown -R rocketmq:rocketmq /home/rocketmq/logs /home/rocketmq/store
# chmod g+s /home/rocketmq/logs /home/rocketmq/store
# echo 'Starting RocketMQ NameServer...'
# sh mqnamesrv
# "
# healthcheck:
# test: ['CMD', 'sh', 'mqadmin', 'clusterList', '-n', 'localhost:9876']
# interval: 5s
# timeout: 10s
# retries: 10
# start_period: 10s
# networks:
# - coze-network
# rocketmq-broker:
# image: apache/rocketmq:5.3.2
# container_name: coze-rocketmq-broker
# privileged: true
# user: root
# profiles: ['middleware']
# env_file: *env_file
# ports:
# - '10909:10909'
# - '10911:10911'
# - '10912:10912'
# volumes:
# - ./data/rocketmq/broker/logs:/home/rocketmq/logs:rw,Z
# - ./data/rocketmq/broker/store:/home/rocketmq/store:rw,Z
# - ./volumes/rocketmq/broker.conf:/home/rocketmq/conf/broker.conf:rw,Z
# networks:
# - coze-network
# command: >
# bash -c '
# # Set proper permissions
# mkdir -p /home/rocketmq/logs/rocketmqlogs /home/rocketmq/store
# touch /home/rocketmq/logs/rocketmqlogs/tools.log \
# /home/rocketmq/logs/rocketmqlogs/tools_default.log
# chown -R rocketmq:rocketmq /home/rocketmq/logs /home/rocketmq/store
# chmod g+s /home/rocketmq/logs /home/rocketmq/store
# echo "Starting RocketMQ Broker..."
# sh mqbroker -n rocketmq-namesrv:9876 -c /home/rocketmq/conf/broker.conf &
# echo "Waiting for Broker registration..."
# broker_ready=false
# for i in {1..60}; do
# if sh mqadmin clusterList -n rocketmq-namesrv:9876 \
# | grep -q "DefaultCluster.*broker-a"; then
# echo "Registered."
# broker_ready=true
# break
# fi
# echo "Not ready, retry $$i/60..."
# sleep 1
# done
# if [ "$$broker_ready" = false ]; then
# echo "ERROR: registration timed out."
# exit 1
# fi
# echo "Creating topics..."
# for t in opencoze_knowledge opencoze_search_app opencoze_search_resource \
# %RETRY%cg_knowledge %RETRY%cg_search_app %RETRY%cg_search_resource; do
# sh mqadmin updateTopic -n rocketmq-namesrv:9876 \
# -c DefaultCluster -t "$$t"
# done
# touch /tmp/rocketmq_ready
# echo "Broker started successfully."
# wait
# '
# depends_on:
# - rocketmq-namesrv
# healthcheck:
# test: ['CMD-SHELL', '[ -f /tmp/rocketmq_ready ]']
# interval: 10s
# timeout: 10s
# retries: 10
# start_period: 10s
elasticsearch:
image: bitnami/elasticsearch:8.18.0
container_name: coze-elasticsearch
user: root
privileged: true
profiles: ['middleware']
env_file: *env_file
environment:
- TEST=1
# Add Java certificate trust configuration
# - ES_JAVA_OPTS=-Djdk.tls.client.protocols=TLSv1.2 -Dhttps.protocols=TLSv1.2 -Djavax.net.ssl.trustAll=true -Xms4096m -Xmx4096m
ports:
- '9200:9200'
volumes:
- ./data/bitnami/elasticsearch:/bitnami/elasticsearch/data
- ./volumes/elasticsearch/elasticsearch.yml:/opt/bitnami/elasticsearch/config/my_elasticsearch.yml
- ./volumes/elasticsearch/analysis-smartcn.zip:/opt/bitnami/elasticsearch/analysis-smartcn.zip:rw,Z
healthcheck:
test:
[
'CMD-SHELL',
'curl -f http://localhost:9200 && [ -f /tmp/es_plugins_ready ]',
]
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
networks:
- coze-network
# Install smartcn analyzer plugin
command: >
bash -c "
/opt/bitnami/scripts/elasticsearch/setup.sh
# Set proper permissions for data directories
chown -R elasticsearch:elasticsearch /bitnami/elasticsearch/data
chmod g+s /bitnami/elasticsearch/data
# Create plugin directory
mkdir -p /bitnami/elasticsearch/plugins;
# Unzip plugin to plugin directory and set correct permissions
echo 'Installing smartcn plugin...';
if [ ! -d /opt/bitnami/elasticsearch/plugins/analysis-smartcn ]; then
# Download plugin package locally
echo 'Copying smartcn plugin...';
cp /opt/bitnami/elasticsearch/analysis-smartcn.zip /tmp/analysis-smartcn.zip
elasticsearch-plugin install file:///tmp/analysis-smartcn.zip
if [[ "$?" != "0" ]]; then
echo 'Plugin installation failed, exiting operation';
rm -rf /opt/bitnami/elasticsearch/plugins/analysis-smartcn
exit 1;
fi;
rm -f /tmp/analysis-smartcn.zip;
fi;
# Create marker file indicating plugin installation success
touch /tmp/es_plugins_ready;
echo 'Plugin installation successful, marker file created';
# Start Elasticsearch
exec /opt/bitnami/scripts/elasticsearch/entrypoint.sh /opt/bitnami/scripts/elasticsearch/run.sh
echo -e "⏳ Adjusting Elasticsearch disk watermark settings..."
"
minio:
image: minio/minio:RELEASE.2025-06-13T11-33-47Z-cpuv1
container_name: coze-minio
user: root
privileged: true
profiles: ['middleware']
env_file: *env_file
ports:
- '9000:9000'
- '9001:9001'
volumes:
- ./data/minio:/data
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-minioadmin}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-minioadmin123}
MINIO_DEFAULT_BUCKETS: ${MINIO_BUCKET:-opencoze},${MINIO_DEFAULT_BUCKETS:-milvus}
command: server /data --console-address ":9001"
healthcheck:
test:
[
'CMD-SHELL',
'/usr/bin/mc alias set health_check http://localhost:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD} && /usr/bin/mc ready health_check',
]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
networks:
- coze-network
etcd:
image: bitnami/etcd:3.5
container_name: coze-etcd
user: root
privileged: true
profiles: ['middleware']
env_file: *env_file
environment:
- ETCD_AUTO_COMPACTION_MODE=revision
- ETCD_AUTO_COMPACTION_RETENTION=1000
- ETCD_QUOTA_BACKEND_BYTES=4294967296
- ALLOW_NONE_AUTHENTICATION=yes
ports:
- 2379:2379
- 2380:2380
volumes:
- ./data/bitnami/etcd:/bitnami/etcd:rw,Z
- ./volumes/etcd/etcd.conf.yml:/opt/bitnami/etcd/conf/etcd.conf.yml:ro,Z
command: >
bash -c "
/opt/bitnami/scripts/etcd/setup.sh
# Set proper permissions for data and config directories
chown -R etcd:etcd /bitnami/etcd
chmod g+s /bitnami/etcd
exec /opt/bitnami/scripts/etcd/entrypoint.sh /opt/bitnami/scripts/etcd/run.sh
"
healthcheck:
test: ['CMD', 'etcdctl', 'endpoint', 'health']
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
networks:
- coze-network
milvus:
container_name: coze-milvus
image: milvusdb/milvus:v2.5.10
user: root
privileged: true
profiles: ['middleware']
env_file: *env_file
command: >
bash -c "
# Set proper permissions for data directories
chown -R root:root /var/lib/milvus
chmod g+s /var/lib/milvus
exec milvus run standalone
"
security_opt:
- seccomp:unconfined
environment:
ETCD_ENDPOINTS: coze-etcd:2379
MINIO_ADDRESS: coze-minio:9000
MINIO_BUCKET_NAME: ${MINIO_BUCKET:-milvus}
MINIO_ACCESS_KEY_ID: ${MINIO_ROOT_USER:-minioadmin}
MINIO_SECRET_ACCESS_KEY: ${MINIO_ROOT_PASSWORD:-minioadmin123}
MINIO_USE_SSL: false
LOG_LEVEL: debug
volumes:
- ./data/milvus:/var/lib/milvus:rw,Z
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:9091/healthz']
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
ports:
- '19530:19530'
- '9091:9091'
depends_on:
etcd:
condition: service_healthy
minio:
condition: service_healthy
networks:
- coze-network
nsqlookupd:
image: nsqio/nsq:v1.2.1
container_name: coze-nsqlookupd
command: /nsqlookupd
profiles: ['middleware']
ports:
- '4160:4160'
- '4161:4161'
networks:
- coze-network
healthcheck:
test: ['CMD-SHELL', 'nsqlookupd --version']
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
nsqd:
image: nsqio/nsq:v1.2.1
container_name: coze-nsqd
command: /nsqd --lookupd-tcp-address=coze-nsqlookupd:4160 --broadcast-address=coze-nsqd
profiles: ['middleware']
ports:
- '4150:4150'
- '4151:4151'
depends_on:
nsqlookupd:
condition: service_healthy
networks:
- coze-network
healthcheck:
test: ['CMD-SHELL', '/nsqd --version']
interval: 5s
timeout: 10s
retries: 10
start_period: 10s
nsqadmin:
image: nsqio/nsq:v1.2.1
container_name: coze-nsqadmin
command: /nsqadmin --lookupd-http-address=coze-nsqlookupd:4161
profiles: ['middleware']
ports:
- '4171:4171'
depends_on:
nsqlookupd:
condition: service_healthy
networks:
- coze-network
elasticsearch-setup:
image: alpine/curl:8.12.1
container_name: coze-elasticsearch-setup
profiles: ['middleware', 'volcano-setup']
env_file: *env_file
volumes:
- ./volumes/elasticsearch/setup_es.sh:/setup_es.sh
- ./volumes/elasticsearch/es_index_schema:/es_index_schema
command:
- /bin/sh
- -c
- |
set -ex
/setup_es.sh
echo 'Elasticsearch setup complete.'
networks:
- coze-network
restart: 'no'
minio-setup:
image: minio/mc:RELEASE.2025-05-21T01-59-54Z-cpuv1
container_name: coze-minio-setup
profiles: ['middleware']
env_file: *env_file
depends_on:
minio:
condition: service_healthy
volumes:
- ./volumes/minio/default_icon/:/default_icon
- ./volumes/minio/official_plugin_icon/:/official_plugin_icon
entrypoint: >
/bin/sh -c "
(/usr/bin/mc alias set localminio http://coze-minio:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD} && \
/usr/bin/mc mb --ignore-existing localminio/${STORAGE_BUCKET} && \
/usr/bin/mc cp --recursive /default_icon/ localminio/${STORAGE_BUCKET}/default_icon/ && \
/usr/bin/mc cp --recursive /official_plugin_icon/ localminio/${STORAGE_BUCKET}/official_plugin_icon/ && \
echo 'upload files to minio complete: Files uploaded to ${STORAGE_BUCKET} bucket.') || exit 1; \
"
networks:
- coze-network
restart: 'no'
mysql-setup-schema:
image: arigaio/atlas:0.35.0-community-alpine
container_name: coze-mysql-setup-schema
profiles: ['middleware', 'mysql-setup', 'run-server']
env_file: *env_file
volumes:
- ./atlas/opencoze_latest_schema.hcl:/opencoze_latest_schema.hcl
entrypoint:
- /bin/sh
- -c
- |
set -ex
TMP_ATLAS_URL="${ATLAS_URL}"
if [ "${MYSQL_HOST}" = "localhost" ] || [ "${MYSQL_HOST}" = "127.0.0.1" ]; then
echo "MYSQL_HOST is localhost or 127.0.0.1, replacing with docker network address"
TMP_ATLAS_URL="mysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:${MYSQL_PORT}/${MYSQL_DATABASE}?charset=utf8mb4&parseTime=True"
fi
echo "final atlas url: $${TMP_ATLAS_URL}"
for i in `seq 1 60`; do
if atlas schema apply \
-u "$${TMP_ATLAS_URL}" \
--to file:///opencoze_latest_schema.hcl \
--exclude "atlas_schema_revisions,table_*" \
--auto-approve; then
echo "MySQL setup complete."
exit 0
fi
echo "atlas schema apply failed, retrying...($$i/60)"
sleep 1
done
echo "MySQL setup failed after 60 retries."
exit 1
networks:
- coze-network
mysql-setup-init-sql:
image: mysql:8.4.5
container_name: coze-mysql-setup-init-sql
profiles: ['middleware', 'mysql-setup', 'run-server', 'volcano-setup']
env_file: *env_file
command:
- /bin/sh
- -c
- |
set -ex
for i in $(seq 1 60); do
DB_HOST="$${MYSQL_HOST}"
if [ "$${MYSQL_HOST}" = "localhost" ] || [ "$${MYSQL_HOST}" = "127.0.0.1" ]; then
DB_HOST="mysql"
fi
if mysql -h "$${DB_HOST}" -P"$${MYSQL_PORT}" -u"$${MYSQL_USER}" -p"$${MYSQL_PASSWORD}" "$${MYSQL_DATABASE}" < /schema.sql && \
mysql -h "$${DB_HOST}" -P"$${MYSQL_PORT}" -u"$${MYSQL_USER}" -p"$${MYSQL_PASSWORD}" "$${MYSQL_DATABASE}" < /sql_init.sql; then
echo 'MySQL init success.'
exit 0
fi
echo "Retrying to connect to mysql... ($$i/60)"
sleep 1
done
echo 'Failed to init mysql db.'
exit 1
volumes:
- ./volumes/mysql/sql_init.sql:/sql_init.sql
- ./volumes/mysql/schema.sql:/schema.sql
networks:
- coze-network
restart: 'no'
coze-server:
# build:
# context: ../
# dockerfile: backend/Dockerfile
image: opencoze/opencoze:latest
container_name: coze-server
profiles: ['run-server']
env_file: *env_file
environment:
LISTEN_ADDR: 0.0.0.0:8888
networks:
- coze-network
ports:
- '8888:8888'
- '8889:8889'
volumes:
- .env:/app/.env
# - ../backend/conf:/app/resources/conf
# - ../backend/static:/app/resources/static
depends_on:
mysql:
condition: service_healthy
redis:
condition: service_healthy
# rocketmq-namesrv:
# condition: service_healthy
# rocketmq-broker:
# condition: service_healthy
elasticsearch:
condition: service_healthy
minio:
condition: service_healthy
milvus:
condition: service_healthy
minio-setup:
condition: service_completed_successfully
elasticsearch-setup:
condition: service_completed_successfully
mysql-setup-init-sql:
condition: service_completed_successfully
command: ['/app/bootstrap.sh']
networks:
coze-network:
driver: bridge

3
docker/proxy/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/coze-dev/coze-studio/docker/proxy
go 1.24.1

100
docker/proxy/proxy.go Normal file
View File

@@ -0,0 +1,100 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"fmt"
"io"
"log"
"net"
"os"
"strings"
)
func main() {
proxyURLListString := os.Getenv("COZE_SERVER_PROXY_URL_LIST")
if proxyURLListString == "" {
proxyURLListString = "mysql:3306,redis:6379,elasticsearch:9200,milvus:19530,minio:9000,nsqd:4150"
}
proxyURLList := strings.Split(proxyURLListString, ",")
for _, serverAddInDockerNet := range proxyURLList {
err := listen(serverAddInDockerNet)
if err != nil {
fmt.Printf("listen %s failed: %v\n", serverAddInDockerNet, err)
}
}
// 阻塞主程序,防止退出
select {}
}
func listen(serverAddInDockerNet string) error {
tcpAddr, err := net.ResolveTCPAddr("tcp", serverAddInDockerNet)
if err != nil {
fmt.Printf("解析失败: %v\n", err)
return err
}
fmt.Printf("host %s : %s:%d\n", serverAddInDockerNet, tcpAddr.IP, tcpAddr.Port)
localAddr := fmt.Sprintf(":%d", tcpAddr.Port)
addr := fmt.Sprintf("%s:%d", tcpAddr.IP, tcpAddr.Port)
go startListener(localAddr, addr)
return nil
}
func startListener(localAddr, targetAddr string) {
// 监听本地端口
listener, err := net.Listen("tcp", localAddr)
if err != nil {
log.Printf("无法监听端口 %s: %v", localAddr, err)
return
}
defer listener.Close()
log.Printf("TCP 服务器已启动,监听端口 %s\n", localAddr)
for {
// 接受客户端连接
clientConn, err := listener.Accept()
if err != nil {
log.Printf("接受连接失败: %v", err)
continue
}
// 处理客户端连接
go handleConnection(clientConn, targetAddr)
}
}
func handleConnection(clientConn net.Conn, targetAddr string) {
defer clientConn.Close()
// 连接到目标服务器
targetConn, err := net.Dial("tcp", targetAddr)
if err != nil {
log.Printf("无法连接到目标服务器 %s: %v", targetAddr, err)
return
}
defer targetConn.Close()
// 启动两个协程进行双向数据转发
go io.Copy(targetConn, clientConn)
io.Copy(clientConn, targetConn)
}

Binary file not shown.

View File

@@ -0,0 +1,14 @@
cluster:
name: "docker-cluster"
routing:
allocation:
disk:
watermark:
low: "99%"
high: "99%"
flood_stage: "99%"
discovery:
type: single-node
xpack:
security:
enabled: false

View File

@@ -0,0 +1,74 @@
{
"index_patterns": ["coze_resource*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"text_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "stop", "snowball"]
},
"smartcn": {
"type": "smartcn"
}
}
}
},
"mappings": {
"dynamic": false,
"properties": {
"res_type": {
"type": "keyword"
},
"app_id": {
"type": "keyword",
"null_value": "NULL"
},
"res_id": {
"type": "keyword"
},
"res_sub_type": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "smartcn",
"search_analyzer": "smartcn",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"owner_id": {
"type": "keyword"
},
"space_id": {
"type": "keyword"
},
"biz_status": {
"type": "keyword"
},
"publish_status": {
"type": "keyword"
},
"create_time": {
"type": "long"
},
"update_time": {
"type": "long"
},
"publish_time": {
"type": "long"
}
}
}
},
"priority": 200,
"_meta": {
"description": "resource library's index template"
}
}

View File

@@ -0,0 +1,79 @@
{
"index_patterns": ["project_draft*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"text_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "stop", "snowball"]
},
"smartcn": {
"type": "smartcn"
}
}
}
},
"mappings": {
"dynamic": false,
"properties": {
"create_time": {
"type": "long"
},
"has_published": {
"type": "keyword"
},
"id": {
"type": "keyword"
},
"name": {
"type": "text",
"analyzer": "smartcn",
"search_analyzer": "smartcn",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"owner_id": {
"type": "keyword"
},
"publish_time": {
"type": "long"
},
"space_id": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"type": {
"type": "keyword"
},
"update_time": {
"type": "long"
},
"fav_time": {
"type": "long"
},
"recently_open_time": {
"type": "long"
},
"is_fav": {
"type": "keyword"
},
"is_recently_open": {
"type": "keyword"
}
}
}
},
"priority": 200,
"_meta": {
"description": "Project draft index template"
}
}

View File

@@ -0,0 +1,93 @@
#!/bin/sh
set -e
if [[ "$ES_ADDR" == *"localhost"* || "$ES_ADDR" == *"127.0.0.1"* ]]; then
echo "ES_ADDR is localhost, using docker address: http://elasticsearch:9200"
ES_ADDR="http://elasticsearch:9200"
fi
# ES_ADDR=http://localhost:31160
INDEX_DIR=/es_index_schema
echo "ES_ADDR: $ES_ADDR"
AUTH_PARAM=""
if [ -n "$ES_USERNAME" ]; then
AUTH_PARAM="-k -u $ES_USERNAME:$ES_PASSWORD"
fi
for i in $(seq 1 60); do
echo "Checking Elasticsearch availability... (attempt $i)"
if curl -s -f $AUTH_PARAM "${ES_ADDR}/_cat/health"; then
echo "Elasticsearch is up and running!"
break
fi
echo "Elasticsearch not available, retrying in 1 seconds..."
sleep 1
done
echo -e "🔍 Checking smartcn plugin status..."
if ! curl -s $AUTH_PARAM "${ES_ADDR}/_cat/plugins" | grep -q "analysis-smartcn"; then
echo -e "❌ smartcn plugin not loaded correctly, please ensure the plugin is installed and Elasticsearch is restarted"
exit 1
fi
echo -e "🔍 Initializing Elasticsearch index templates..."
ES_TEMPLATES=$(find "$INDEX_DIR" -type f -name "*.index-template.json" | sort)
if [ -z "$ES_TEMPLATES" ]; then
echo -e " No Elasticsearch index templates found in $INDEX_DIR"
exit 1
else
# Add index creation logic
echo -e "🔄 Creating Elasticsearch indexes..."
for template_file in $ES_TEMPLATES; do
template_name=$(basename "$template_file" | sed 's/\.index-template\.json$//')
echo -e "➡️ Registering template: $template_name"
# Attempt to register index template
response=$(curl -s $AUTH_PARAM -X PUT "${ES_ADDR}/_index_template/$template_name" \
-H "Content-Type: application/json" \
-d @"$template_file" 2>&1)
# Check if successful
if echo "$response" | grep -q '"acknowledged":true'; then
echo -e "✅ Template $template_name registered successfully"
else
echo -e "❌ Failed to register template $template_name. Response: $response"
exit 1
fi
index_name=$(basename "$template_file" | sed 's/\.index-template\.json$//')
echo -e "➡️ Creating index: $index_name"
# Check if index exists
if ! curl -s -f $AUTH_PARAM "${ES_ADDR}/_cat/indices/$index_name" >/dev/null; then
# Create index (matching template's index_patterns)
curl $AUTH_PARAM -X PUT "${ES_ADDR}/$index_name" -H "Content-Type: application/json"
echo ""
# Set refresh interval if index was just created
echo -e "🔄 Setting refresh_interval for index: $index_name..."
CURL_OUTPUT=$(curl -s $AUTH_PARAM -w "\nHTTP_STATUS_CODE:%{http_code}" -X PUT "${ES_ADDR}/${index_name}/_settings" -H 'Content-Type: application/json' -d'
{
"index": {
"refresh_interval": "10ms"
}
}')
echo -e "📄 Curl command output for $index_name:\n$CURL_OUTPUT"
# Extract the JSON body from the output, excluding the HTTP_STATUS_CODE line
JSON_BODY=$(echo "$CURL_OUTPUT" | sed '$d')
if ! echo "$JSON_BODY" | grep -q '"acknowledged":true'; then
echo -e "⚠️ Warning: Failed to set refresh interval for $index_name index. Response Body: $JSON_BODY. Please check and set manually."
exit 1
else
echo -e "✅ Successfully set refresh_interval for $index_name."
fi
else
echo -e " Index $index_name already exists"
fi
done
fi
echo "Elasticsearch setup completed."
exit 0

View File

View File

@@ -0,0 +1 @@
{}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 814 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 831 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
docker/volumes/minio/tosutil Executable file

Binary file not shown.

View File

@@ -0,0 +1,836 @@
SET NAMES utf8mb4;
CREATE DATABASE IF NOT EXISTS opencoze COLLATE utf8mb4_unicode_ci;
-- Create "agent_to_database" table
CREATE TABLE IF NOT EXISTS `agent_to_database` (
`id` bigint unsigned NOT NULL COMMENT "ID",
`agent_id` bigint unsigned NOT NULL COMMENT "Agent ID",
`database_id` bigint unsigned NOT NULL COMMENT "ID of database_info",
`is_draft` bool NOT NULL COMMENT "Is draft",
`prompt_disable` bool NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_agent_db_draft` (`agent_id`, `database_id`, `is_draft`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "agent_to_database info";
-- Create "agent_tool_draft" table
CREATE TABLE IF NOT EXISTS `agent_tool_draft` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Agent ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path",
`method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method",
`tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Name",
`tool_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0",
`operation` json NULL COMMENT "Tool Openapi Operation Schema",
PRIMARY KEY (`id`),
INDEX `idx_agent_plugin_tool` (`agent_id`, `plugin_id`, `tool_id`),
INDEX `idx_agent_tool_bind` (`agent_id`, `created_at`),
UNIQUE INDEX `uniq_idx_agent_tool_id` (`agent_id`, `tool_id`),
UNIQUE INDEX `uniq_idx_agent_tool_name` (`agent_id`, `tool_name`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Agent Tool";
-- Create "agent_tool_version" table
CREATE TABLE IF NOT EXISTS `agent_tool_version` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Agent ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID",
`agent_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Tool Version",
`tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Name",
`tool_version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0",
`sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path",
`method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method",
`operation` json NULL COMMENT "Tool Openapi Operation Schema",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
PRIMARY KEY (`id`),
INDEX `idx_agent_tool_id_created_at` (`agent_id`, `tool_id`, `created_at`),
INDEX `idx_agent_tool_name_created_at` (`agent_id`, `tool_name`, `created_at`),
UNIQUE INDEX `uniq_idx_agent_tool_id_agent_version` (`agent_id`, `tool_id`, `agent_version`),
UNIQUE INDEX `uniq_idx_agent_tool_name_agent_version` (`agent_id`, `tool_name`, `agent_version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Agent Tool Version";
-- Create "api_key" table
CREATE TABLE IF NOT EXISTS `api_key` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID",
`api_key` varchar(255) NOT NULL DEFAULT "" COMMENT "API Key hash",
`name` varchar(255) NOT NULL DEFAULT "" COMMENT "API Key Name",
`status` tinyint NOT NULL DEFAULT 0 COMMENT "0 normal, 1 deleted",
`user_id` bigint NOT NULL DEFAULT 0 COMMENT "API Key Owner",
`expired_at` bigint NOT NULL DEFAULT 0 COMMENT "API Key Expired Time",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`last_used_at` bigint NOT NULL DEFAULT 0 COMMENT "Used Time in Milliseconds",
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "api key table";
-- Create "app_connector_release_ref" table
CREATE TABLE IF NOT EXISTS `app_connector_release_ref` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key",
`record_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Record ID",
`connector_id` bigint unsigned NULL COMMENT "Publish Connector ID",
`publish_config` json NULL COMMENT "Publish Configuration",
`publish_status` tinyint NOT NULL DEFAULT 0 COMMENT "Publish Status",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_record_connector` (`record_id`, `connector_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Connector Release Record Reference";
-- Create "app_draft" table
CREATE TABLE IF NOT EXISTS `app_draft` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "APP ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI",
`name` varchar(255) NOT NULL DEFAULT "" COMMENT "Application Name",
`description` text NULL COMMENT "Application Description",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Application";
-- Create "app_release_record" table
CREATE TABLE IF NOT EXISTS `app_release_record` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Record ID",
`app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI",
`name` varchar(255) NOT NULL DEFAULT "" COMMENT "Application Name",
`description` text NULL COMMENT "Application Description",
`connector_ids` json NULL COMMENT "Publish Connector IDs",
`extra_info` json NULL COMMENT "Publish Extra Info",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Release Version",
`version_desc` text NULL COMMENT "Version Description",
`publish_status` tinyint NOT NULL DEFAULT 0 COMMENT "Publish Status",
`publish_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Publish Time in Milliseconds",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
PRIMARY KEY (`id`),
INDEX `idx_app_publish_at` (`app_id`, `publish_at`),
UNIQUE INDEX `uniq_idx_app_version_connector` (`app_id`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Application Release Record";
-- Create "connector_workflow_version" table
CREATE TABLE IF NOT EXISTS `connector_workflow_version` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "id",
`app_id` bigint unsigned NOT NULL COMMENT "app id",
`connector_id` bigint unsigned NOT NULL COMMENT "connector id",
`workflow_id` bigint unsigned NOT NULL COMMENT "workflow id",
`version` varchar(256) NOT NULL COMMENT "version",
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
PRIMARY KEY (`id`),
INDEX `idx_connector_id_workflow_id_create_at` (`connector_id`, `workflow_id`, `created_at`),
UNIQUE INDEX `idx_connector_id_workflow_id_version` (`connector_id`, `workflow_id`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create "conversation" table
CREATE TABLE IF NOT EXISTS `conversation` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID",
`connector_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "业务线 ID",
`agent_id` bigint NOT NULL DEFAULT 0 COMMENT "agent_id",
`scene` tinyint NOT NULL DEFAULT 0 COMMENT "会话场景",
`section_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "最新section_id",
`creator_id` bigint unsigned NULL DEFAULT 0 COMMENT "创建者id",
`ext` text NULL COMMENT "扩展字段",
`status` tinyint NOT NULL DEFAULT 1 COMMENT "status: 1-normal 2-deleted",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间",
PRIMARY KEY (`id`),
INDEX `idx_connector_bot_status` (`connector_id`, `agent_id`, `creator_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "会话信息表";
-- Create "data_copy_task" table
CREATE TABLE IF NOT EXISTS `data_copy_task` (
`master_task_id` varchar(128) NOT NULL DEFAULT "" COMMENT "复制任务ID",
`origin_data_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源id",
`target_data_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标id",
`origin_space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源团队空间",
`target_space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标团队空间",
`origin_user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源用户ID",
`target_user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标用户ID",
`origin_app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "源AppID",
`target_app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "目标AppID",
`data_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "数据类型 1:knowledge, 2:database",
`ext_info` varchar(255) NOT NULL DEFAULT "" COMMENT "存储额外信息",
`start_time` bigint NOT NULL DEFAULT 0 COMMENT "任务开始时间",
`finish_time` bigint NULL COMMENT "任务结束时间",
`status` tinyint NOT NULL DEFAULT 1 COMMENT "1:创建 2:执行中 3:成功 4:失败",
`error_msg` varchar(128) NULL COMMENT "错误信息",
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_master_task_id_origin_data_id_data_type` (`master_task_id`, `origin_data_id`, `data_type`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "data方向复制任务记录表";
-- Create "draft_database_info" table
CREATE TABLE IF NOT EXISTS `draft_database_info` (
`id` bigint unsigned NOT NULL COMMENT "ID",
`app_id` bigint unsigned NULL COMMENT "App ID",
`space_id` bigint unsigned NOT NULL COMMENT "Space ID",
`related_online_id` bigint unsigned NOT NULL COMMENT "The primary key ID of online_database_info table",
`is_visible` tinyint NOT NULL DEFAULT 1 COMMENT "Visibility: 0 invisible, 1 visible",
`prompt_disabled` tinyint NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported",
`table_name` varchar(255) NOT NULL COMMENT "Table name",
`table_desc` varchar(256) NULL COMMENT "Table description",
`table_field` text NULL COMMENT "Table field info",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID",
`icon_uri` varchar(255) NOT NULL COMMENT "Icon Uri",
`physical_table_name` varchar(255) NULL COMMENT "The name of the real physical table",
`rw_mode` bigint NOT NULL DEFAULT 1 COMMENT "Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
PRIMARY KEY (`id`),
INDEX `idx_space_app_creator_deleted` (`space_id`, `app_id`, `creator_id`, `deleted_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "draft database info";
-- Create "knowledge" table
CREATE TABLE IF NOT EXISTS `knowledge` (
`id` bigint unsigned NOT NULL COMMENT "主键ID",
`name` varchar(150) NOT NULL DEFAULT "" COMMENT "名称",
`app_id` bigint NOT NULL DEFAULT 0 COMMENT "项目ID标识该资源是否是项目独有",
`creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "空间ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds",
`status` tinyint NOT NULL DEFAULT 1 COMMENT "0 初始化, 1 生效 2 失效",
`description` text NULL COMMENT "描述",
`icon_uri` varchar(150) NULL COMMENT "头像uri",
`format_type` tinyint NOT NULL DEFAULT 0 COMMENT "0:文本 1:表格 2:图片",
PRIMARY KEY (`id`),
INDEX `idx_app_id` (`app_id`),
INDEX `idx_creator_id` (`creator_id`),
INDEX `idx_space_id_deleted_at_updated_at` (`space_id`, `deleted_at`, `updated_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库表";
-- Create "knowledge_document" table
CREATE TABLE IF NOT EXISTS `knowledge_document` (
`id` bigint unsigned NOT NULL COMMENT "主键ID",
`knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "所属knowledge的ID",
`name` varchar(150) NOT NULL DEFAULT "" COMMENT "文档名称",
`file_extension` varchar(20) NOT NULL DEFAULT "0" COMMENT "文档类型, txt/pdf/csv/...",
`document_type` int NOT NULL DEFAULT 0 COMMENT "文档类型: 0:文本 1:表格 2:图片",
`uri` text NULL COMMENT "资源uri",
`size` bigint unsigned NOT NULL DEFAULT 0 COMMENT "文档大小",
`slice_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT "分片数量",
`char_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT "字符数",
`creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建者ID",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间id",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds",
`source_type` int NOT NULL DEFAULT 0 COMMENT "0:本地文件上传, 2:自定义文本",
`status` int NOT NULL DEFAULT 0 COMMENT "状态",
`fail_reason` text NULL COMMENT "失败原因",
`parse_rule` json NULL COMMENT "解析+切片规则",
`table_info` json NULL COMMENT "表格信息",
PRIMARY KEY (`id`),
INDEX `idx_creator_id` (`creator_id`),
INDEX `idx_knowledge_id_deleted_at_updated_at` (`knowledge_id`, `deleted_at`, `updated_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库文档表";
-- Create "knowledge_document_review" table
CREATE TABLE IF NOT EXISTS `knowledge_document_review` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID",
`knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "knowledge id",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间id",
`name` varchar(150) NOT NULL DEFAULT "" COMMENT "文档名称",
`type` varchar(10) NOT NULL DEFAULT "0" COMMENT "文档类型",
`uri` text NULL COMMENT "资源标识",
`format_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0 文本, 1 表格, 2 图片",
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0 处理中1 已完成2 失败3 失效",
`chunk_resp_uri` text NULL COMMENT "预切片tos资源标识",
`deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者ID",
PRIMARY KEY (`id`),
INDEX `idx_dataset_id` (`knowledge_id`, `status`, `updated_at`),
INDEX `idx_uri` (`uri` (100))
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "文档审阅表";
-- Create "knowledge_document_slice" table
CREATE TABLE IF NOT EXISTS `knowledge_document_slice` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID",
`knowledge_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "knowledge id",
`document_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "document id",
`content` text NULL COMMENT "切片内容",
`sequence` decimal(20,5) NOT NULL COMMENT "切片顺序号, 从1开始",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime(3) NULL COMMENT "Delete Time in Milliseconds",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者ID",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "空间ID",
`status` int NOT NULL DEFAULT 0 COMMENT "状态",
`fail_reason` text NULL COMMENT "失败原因",
`hit` bigint unsigned NOT NULL DEFAULT 0 COMMENT "命中次数",
PRIMARY KEY (`id`),
INDEX `idx_document_id_deleted_at_sequence` (`document_id`, `deleted_at`, `sequence`),
INDEX `idx_knowledge_id_document_id` (`knowledge_id`, `document_id`),
INDEX `idx_sequence` (`sequence`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "知识库文件切片表";
-- Create "message" table
CREATE TABLE IF NOT EXISTS `message` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID",
`run_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "对应的run_id",
`conversation_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "conversation id",
`user_id` varchar(60) NOT NULL DEFAULT "" COMMENT "user id",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id",
`role` varchar(100) NOT NULL DEFAULT "" COMMENT "角色: user、assistant、system",
`content_type` varchar(100) NOT NULL DEFAULT "" COMMENT "内容类型 1 text",
`content` mediumtext NULL COMMENT "内容",
`message_type` varchar(100) NOT NULL DEFAULT "" COMMENT "消息类型:",
`display_content` text NULL COMMENT "展示内容",
`ext` text NULL COMMENT "message 扩展字段" COLLATE utf8mb4_general_ci,
`section_id` bigint unsigned NULL COMMENT "段落id",
`broken_position` int NULL DEFAULT -1 COMMENT "打断位置",
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "消息状态 1 Available 2 Deleted 3 Replaced 4 Broken 5 Failed 6 Streaming 7 Pending",
`model_content` mediumtext NULL COMMENT "模型输入内容",
`meta_info` text NULL COMMENT "引用、高亮等文本标记信息",
`reasoning_content` text NULL COMMENT "思考内容" COLLATE utf8mb4_general_ci,
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间",
PRIMARY KEY (`id`),
INDEX `idx_conversation_id` (`conversation_id`),
INDEX `idx_run_id` (`run_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "消息表";
-- Create "model_entity" table
CREATE TABLE IF NOT EXISTS `model_entity` (
`id` bigint unsigned NOT NULL COMMENT "主键ID",
`meta_id` bigint unsigned NOT NULL COMMENT "模型元信息 id",
`name` varchar(128) NOT NULL COMMENT "名称",
`description` text NULL COMMENT "描述",
`default_params` json NULL COMMENT "默认参数",
`scenario` bigint unsigned NOT NULL COMMENT "模型应用场景",
`status` int NOT NULL DEFAULT 1 COMMENT "模型状态",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` bigint unsigned NULL COMMENT "Delete Time in Milliseconds",
PRIMARY KEY (`id`),
INDEX `idx_scenario` (`scenario`),
INDEX `idx_status` (`status`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "模型信息";
-- Create "model_meta" table
CREATE TABLE IF NOT EXISTS `model_meta` (
`id` bigint unsigned NOT NULL COMMENT "主键ID",
`model_name` varchar(128) NOT NULL COMMENT "模型名称",
`protocol` varchar(128) NOT NULL COMMENT "模型协议",
`icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI",
`capability` json NULL COMMENT "模型能力",
`conn_config` json NULL COMMENT "模型连接配置",
`status` int NOT NULL DEFAULT 1 COMMENT "模型状态",
`description` varchar(2048) NOT NULL DEFAULT "" COMMENT "模型描述",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` bigint unsigned NULL COMMENT "Delete Time in Milliseconds",
`icon_url` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URL",
PRIMARY KEY (`id`),
INDEX `idx_status` (`status`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "模型元信息";
-- Create "node_execution" table
CREATE TABLE IF NOT EXISTS `node_execution` (
`id` bigint unsigned NOT NULL COMMENT "node execution id",
`execute_id` bigint unsigned NOT NULL COMMENT "the workflow execute id this node execution belongs to",
`node_id` varchar(128) NOT NULL COMMENT "node key" COLLATE utf8mb4_unicode_ci,
`node_name` varchar(128) NOT NULL COMMENT "name of the node" COLLATE utf8mb4_unicode_ci,
`node_type` varchar(128) NOT NULL COMMENT "the type of the node, in string" COLLATE utf8mb4_unicode_ci,
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
`status` tinyint unsigned NOT NULL COMMENT "1=waiting 2=running 3=success 4=fail",
`duration` bigint unsigned NULL COMMENT "execution duration in millisecond",
`input` mediumtext NULL COMMENT "actual input of the node" COLLATE utf8mb4_unicode_ci,
`output` mediumtext NULL COMMENT "actual output of the node" COLLATE utf8mb4_unicode_ci,
`raw_output` mediumtext NULL COMMENT "the original output of the node" COLLATE utf8mb4_unicode_ci,
`error_info` mediumtext NULL COMMENT "error info" COLLATE utf8mb4_unicode_ci,
`error_level` varchar(32) NULL COMMENT "level of the error" COLLATE utf8mb4_unicode_ci,
`input_tokens` bigint unsigned NULL COMMENT "number of input tokens",
`output_tokens` bigint unsigned NULL COMMENT "number of output tokens",
`updated_at` bigint unsigned NULL COMMENT "update time in millisecond",
`composite_node_index` bigint unsigned NULL COMMENT "loop or batch's execution index",
`composite_node_items` mediumtext NULL COMMENT "the items extracted from parent composite node for this index" COLLATE utf8mb4_unicode_ci,
`parent_node_id` varchar(128) NULL COMMENT "when as inner node for loop or batch, this is the parent node's key" COLLATE utf8mb4_unicode_ci,
`sub_execute_id` bigint unsigned NULL COMMENT "if this node is sub_workflow, the exe id of the sub workflow",
`extra` mediumtext NULL COMMENT "extra info" COLLATE utf8mb4_unicode_ci,
PRIMARY KEY (`id`),
INDEX `idx_execute_id_node_id` (`execute_id`, `node_id`),
INDEX `idx_execute_id_parent_node_id` (`execute_id`, `parent_node_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "node 节点运行记录用于记录每次workflow执行时每个节点的状态信息";
-- Create "online_database_info" table
CREATE TABLE IF NOT EXISTS `online_database_info` (
`id` bigint unsigned NOT NULL COMMENT "ID",
`app_id` bigint unsigned NULL COMMENT "App ID",
`space_id` bigint unsigned NOT NULL COMMENT "Space ID",
`related_draft_id` bigint unsigned NOT NULL COMMENT "The primary key ID of draft_database_info table",
`is_visible` tinyint NOT NULL DEFAULT 1 COMMENT "Visibility: 0 invisible, 1 visible",
`prompt_disabled` tinyint NOT NULL DEFAULT 0 COMMENT "Support prompt calls: 1 not supported, 0 supported",
`table_name` varchar(255) NOT NULL COMMENT "Table name",
`table_desc` varchar(256) NULL COMMENT "Table description",
`table_field` text NULL COMMENT "Table field info",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID",
`icon_uri` varchar(255) NOT NULL COMMENT "Icon Uri",
`physical_table_name` varchar(255) NULL COMMENT "The name of the real physical table",
`rw_mode` bigint NOT NULL DEFAULT 1 COMMENT "Read and write permission modes: 1. Limited read and write mode 2. Read-only mode 3. Full read and write mode",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
PRIMARY KEY (`id`),
INDEX `idx_space_app_creator_deleted` (`space_id`, `app_id`, `creator_id`, `deleted_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "online database info";
-- Create "plugin" table
CREATE TABLE IF NOT EXISTS `plugin` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID",
`app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI",
`server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL",
`plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Plugin Version, e.g. v1.0.0",
`version_desc` text NULL COMMENT "Plugin Version Description",
`manifest` json NULL COMMENT "Plugin Manifest",
`openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root",
PRIMARY KEY (`id`),
INDEX `idx_space_created_at` (`space_id`, `created_at`),
INDEX `idx_space_updated_at` (`space_id`, `updated_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Latest Plugin";
-- Create "plugin_draft" table
CREATE TABLE IF NOT EXISTS `plugin_draft` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID",
`app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI",
`server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL",
`plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
`manifest` json NULL COMMENT "Plugin Manifest",
`openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root",
PRIMARY KEY (`id`),
INDEX `idx_app_id` (`app_id`, `id`),
INDEX `idx_space_app_created_at` (`space_id`, `app_id`, `created_at`),
INDEX `idx_space_app_updated_at` (`space_id`, `app_id`, `updated_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Plugin";
-- Create "plugin_oauth_auth" table
CREATE TABLE IF NOT EXISTS `plugin_oauth_auth` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key",
`user_id` varchar(255) NOT NULL DEFAULT "" COMMENT "User ID",
`plugin_id` bigint NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`is_draft` bool NOT NULL DEFAULT 0 COMMENT "Is Draft Plugin",
`oauth_config` json NULL COMMENT "Authorization Code OAuth Config",
`access_token` text NOT NULL COMMENT "Access Token",
`refresh_token` text NOT NULL COMMENT "Refresh Token",
`token_expired_at` bigint NULL COMMENT "Token Expired in Milliseconds",
`next_token_refresh_at` bigint NULL COMMENT "Next Token Refresh Time in Milliseconds",
`last_active_at` bigint NULL COMMENT "Last active time in Milliseconds",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
PRIMARY KEY (`id`),
INDEX `idx_last_active_at` (`last_active_at`),
INDEX `idx_last_token_expired_at` (`token_expired_at`),
INDEX `idx_next_token_refresh_at` (`next_token_refresh_at`),
UNIQUE INDEX `uniq_idx_user_plugin_is_draft` (`user_id`, `plugin_id`, `is_draft`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Plugin OAuth Authorization Code Info";
-- Create "plugin_version" table
CREATE TABLE IF NOT EXISTS `plugin_version` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`developer_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Developer ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`app_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Application ID",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Icon URI",
`server_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Server URL",
`plugin_type` tinyint NOT NULL DEFAULT 0 COMMENT "Plugin Type, 1:http, 6:local",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Plugin Version, e.g. v1.0.0",
`version_desc` text NULL COMMENT "Plugin Version Description",
`manifest` json NULL COMMENT "Plugin Manifest",
`openapi_doc` json NULL COMMENT "OpenAPI Document, only stores the root",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_idx_plugin_version` (`plugin_id`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Plugin Version";
-- Create "prompt_resource" table
CREATE TABLE IF NOT EXISTS `prompt_resource` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID",
`space_id` bigint NOT NULL COMMENT "空间ID",
`name` varchar(255) NOT NULL COMMENT "名称",
`description` varchar(255) NOT NULL COMMENT "描述",
`prompt_text` mediumtext NULL COMMENT "prompt正文",
`status` int NOT NULL COMMENT "状态,0无效,1有效",
`creator_id` bigint NOT NULL COMMENT "创建者ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间",
PRIMARY KEY (`id`),
INDEX `idx_creator_id` (`creator_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "prompt_resource";
-- Create "run_record" table
CREATE TABLE IF NOT EXISTS `run_record` (
`id` bigint unsigned NOT NULL COMMENT "主键ID",
`conversation_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "会话 ID",
`section_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "section ID",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id",
`user_id` varchar(255) NOT NULL DEFAULT "" COMMENT "user id",
`source` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "执行来源 0 API,",
`status` varchar(255) NOT NULL DEFAULT "" COMMENT "状态,0 Unknown, 1-Created,2-InProgress,3-Completed,4-Failed,5-Expired,6-Cancelled,7-RequiresAction",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "创建者标识",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间",
`failed_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "失败时间",
`last_error` text NULL COMMENT "error message" COLLATE utf8mb4_general_ci,
`completed_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "结束时间",
`chat_request` text NULL COMMENT "保存原始请求的部分字段" COLLATE utf8mb4_general_ci,
`ext` text NULL COMMENT "扩展字段" COLLATE utf8mb4_general_ci,
`usage` json NULL COMMENT "usage",
PRIMARY KEY (`id`),
INDEX `idx_c_s` (`conversation_id`, `section_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "执行记录表";
-- Create "shortcut_command" table
CREATE TABLE IF NOT EXISTS `shortcut_command` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键ID",
`object_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "实体ID,该实体可用这个指令",
`command_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "命令ID",
`command_name` varchar(255) NOT NULL DEFAULT "" COMMENT "命令名称",
`shortcut_command` varchar(255) NOT NULL DEFAULT "" COMMENT "快捷指令",
`description` varchar(2000) NOT NULL DEFAULT "" COMMENT "命令描述",
`send_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "发送类型 0:query 1:panel",
`tool_type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "使用工具的type 1:workFlow 2:插件",
`work_flow_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "使用workFlow的id",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "使用插件的id",
`plugin_tool_name` varchar(255) NOT NULL DEFAULT "" COMMENT "使用插件的api_name",
`template_query` text NULL COMMENT "query模板",
`components` json NULL COMMENT "panel参数",
`card_schema` text NULL COMMENT "卡片schema",
`tool_info` json NULL COMMENT "工具信息 包含name+变量列表",
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "状态,0无效,1有效",
`creator_id` bigint unsigned NULL DEFAULT 0 COMMENT "创建者ID",
`is_online` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "是否为线上信息 0草稿 1线上",
`created_at` bigint NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint NOT NULL DEFAULT 0 COMMENT "更新时间",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "multi的指令时该指令由哪个节点执行",
`shortcut_icon` json NULL COMMENT "快捷指令图标",
`plugin_tool_id` bigint NOT NULL DEFAULT 0 COMMENT "tool_id",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_object_command_id_type` (`object_id`, `command_id`, `is_online`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_general_ci COMMENT "bot快捷指令表";
-- Create "single_agent_draft" table
CREATE TABLE IF NOT EXISTS `single_agent_draft` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID",
`agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID",
`name` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Name",
`description` text NOT NULL COMMENT "Agent Description",
`icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime(3) NULL COMMENT "delete time in millisecond",
`variables_meta_id` bigint NULL COMMENT "variables meta 表 ID",
`model_info` json NULL COMMENT "Model Configuration Information",
`onboarding_info` json NULL COMMENT "Onboarding Information",
`prompt` json NULL COMMENT "Agent Prompt Configuration",
`plugin` json NULL COMMENT "Agent Plugin Base Configuration",
`knowledge` json NULL COMMENT "Agent Knowledge Base Configuration",
`workflow` json NULL COMMENT "Agent Workflow Configuration",
`suggest_reply` json NULL COMMENT "Suggested Replies",
`jump_config` json NULL COMMENT "Jump Configuration",
`background_image_info_list` json NULL COMMENT "Background image",
`database_config` json NULL COMMENT "Agent Database Base Configuration",
`shortcut_command` json NULL COMMENT "shortcut command",
PRIMARY KEY (`id`),
INDEX `idx_creator_id` (`creator_id`),
UNIQUE INDEX `uniq_agent_id` (`agent_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Single Agent Draft Copy Table";
-- Create "single_agent_publish" table
CREATE TABLE IF NOT EXISTS `single_agent_publish` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "主键id",
`agent_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "agent_id",
`publish_id` varchar(50) NOT NULL DEFAULT "" COMMENT "发布 id" COLLATE utf8mb4_general_ci,
`connector_ids` json NULL COMMENT "发布的 connector_ids",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Version",
`publish_info` text NULL COMMENT "发布信息" COLLATE utf8mb4_general_ci,
`publish_time` bigint unsigned NOT NULL DEFAULT 0 COMMENT "发布时间",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "发布人 user_id",
`status` tinyint NOT NULL DEFAULT 0 COMMENT "状态 0:使用中 1:删除 3:禁用",
`extra` json NULL COMMENT "扩展字段",
PRIMARY KEY (`id`),
INDEX `idx_agent_id_version` (`agent_id`, `version`),
INDEX `idx_creator_id` (`creator_id`),
INDEX `idx_publish_id` (`publish_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "bot 渠道和发布版本流水表";
-- Create "single_agent_version" table
CREATE TABLE IF NOT EXISTS `single_agent_version` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID",
`agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID",
`creator_id` bigint NOT NULL DEFAULT 0 COMMENT "Creator ID",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID",
`name` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Name",
`description` text NOT NULL COMMENT "Agent Description",
`icon_uri` varchar(255) NOT NULL DEFAULT "" COMMENT "Icon URI",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`deleted_at` datetime(3) NULL COMMENT "delete time in millisecond",
`variables_meta_id` bigint NULL COMMENT "variables meta 表 ID",
`model_info` json NULL COMMENT "Model Configuration Information",
`onboarding_info` json NULL COMMENT "Onboarding Information",
`prompt` json NULL COMMENT "Agent Prompt Configuration",
`plugin` json NULL COMMENT "Agent Plugin Base Configuration",
`knowledge` json NULL COMMENT "Agent Knowledge Base Configuration",
`workflow` json NULL COMMENT "Agent Workflow Configuration",
`suggest_reply` json NULL COMMENT "Suggested Replies",
`jump_config` json NULL COMMENT "Jump Configuration",
`connector_id` bigint unsigned NOT NULL COMMENT "Connector ID",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Agent Version",
`background_image_info_list` json NULL COMMENT "Background image",
`database_config` json NULL COMMENT "Agent Database Base Configuration",
`shortcut_command` json NULL COMMENT "shortcut command",
PRIMARY KEY (`id`),
INDEX `idx_creator_id` (`creator_id`),
UNIQUE INDEX `uniq_agent_id_and_version_connector_id` (`agent_id`, `version`, `connector_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Single Agent Version Copy Table";
-- Create "space" table
CREATE TABLE IF NOT EXISTS `space` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID, Space ID",
`owner_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Owner ID",
`name` varchar(200) NOT NULL DEFAULT "" COMMENT "Space Name",
`description` varchar(2000) NOT NULL DEFAULT "" COMMENT "Space Description",
`icon_uri` varchar(200) NOT NULL DEFAULT "" COMMENT "Icon URI",
`creator_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creator ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)",
`deleted_at` bigint unsigned NULL COMMENT "Deletion Time (Milliseconds)",
PRIMARY KEY (`id`),
INDEX `idx_creator_id` (`creator_id`),
INDEX `idx_owner_id` (`owner_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Space Table";
-- Create "space_user" table
CREATE TABLE IF NOT EXISTS `space_user` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID, Auto Increment",
`space_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Space ID",
`user_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "User ID",
`role_type` int NOT NULL DEFAULT 3 COMMENT "Role Type: 1.owner 2.admin 3.member",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)",
PRIMARY KEY (`id`),
INDEX `idx_user_id` (`user_id`),
UNIQUE INDEX `uniq_space_user` (`space_id`, `user_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Space Member Table";
-- Create "template" table
CREATE TABLE IF NOT EXISTS `template` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID",
`agent_id` bigint NOT NULL DEFAULT 0 COMMENT "Agent ID",
`workflow_id` bigint NOT NULL DEFAULT 0 COMMENT "Workflow ID",
`space_id` bigint NOT NULL DEFAULT 0 COMMENT "Space ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`heat` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Heat",
`product_entity_type` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Product Entity Type",
`meta_info` json NULL COMMENT "Meta Info",
`agent_extra` json NULL COMMENT "Agent Extra Info",
`workflow_extra` json NULL COMMENT "Workflow Extra Info",
`project_extra` json NULL COMMENT "Project Extra Info",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_agent_id` (`agent_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Template Info Table";
-- Create "tool" table
CREATE TABLE IF NOT EXISTS `tool` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0",
`sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path",
`method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method",
`operation` json NULL COMMENT "Tool Openapi Operation Schema",
`activated_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:activated; 1:deactivated",
PRIMARY KEY (`id`),
INDEX `idx_plugin_activated_status` (`plugin_id`, `activated_status`),
UNIQUE INDEX `uniq_idx_plugin_sub_url_method` (`plugin_id`, `sub_url`, `method`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Latest Tool";
-- Create "tool_draft" table
CREATE TABLE IF NOT EXISTS `tool_draft` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time in Milliseconds",
`sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path",
`method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method",
`operation` json NULL COMMENT "Tool Openapi Operation Schema",
`debug_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:not pass; 1:pass",
`activated_status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT "0:activated; 1:deactivated",
PRIMARY KEY (`id`),
INDEX `idx_plugin_created_at_id` (`plugin_id`, `created_at`, `id`),
UNIQUE INDEX `uniq_idx_plugin_sub_url_method` (`plugin_id`, `sub_url`, `method`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Draft Tool";
-- Create "tool_version" table
CREATE TABLE IF NOT EXISTS `tool_version` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Primary Key ID",
`tool_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Tool ID",
`plugin_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Plugin ID",
`version` varchar(255) NOT NULL DEFAULT "" COMMENT "Tool Version, e.g. v1.0.0",
`sub_url` varchar(512) NOT NULL DEFAULT "" COMMENT "Sub URL Path",
`method` varchar(64) NOT NULL DEFAULT "" COMMENT "HTTP Request Method",
`operation` json NULL COMMENT "Tool Openapi Operation Schema",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Create Time in Milliseconds",
`deleted_at` datetime NULL COMMENT "Delete Time",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_idx_tool_version` (`tool_id`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "Tool Version";
-- Create "user" table
CREATE TABLE IF NOT EXISTS `user` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "Primary Key ID",
`name` varchar(128) NOT NULL DEFAULT "" COMMENT "User Nickname",
`unique_name` varchar(128) NOT NULL DEFAULT "" COMMENT "User Unique Name",
`email` varchar(128) NOT NULL DEFAULT "" COMMENT "Email",
`password` varchar(128) NOT NULL DEFAULT "" COMMENT "Password (Encrypted)",
`description` varchar(512) NOT NULL DEFAULT "" COMMENT "User Description",
`icon_uri` varchar(512) NOT NULL DEFAULT "" COMMENT "Avatar URI",
`user_verified` bool NOT NULL DEFAULT 0 COMMENT "User Verification Status",
`locale` varchar(128) NOT NULL DEFAULT "" COMMENT "Locale",
`session_key` varchar(256) NOT NULL DEFAULT "" COMMENT "Session Key",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Creation Time (Milliseconds)",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "Update Time (Milliseconds)",
`deleted_at` bigint unsigned NULL COMMENT "Deletion Time (Milliseconds)",
PRIMARY KEY (`id`),
INDEX `idx_session_key` (`session_key`),
UNIQUE INDEX `uniq_email` (`email`),
UNIQUE INDEX `uniq_unique_name` (`unique_name`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "User Table";
-- Create "variable_instance" table
CREATE TABLE IF NOT EXISTS `variable_instance` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID",
`biz_type` tinyint unsigned NOT NULL COMMENT "1 for agent2 for app",
`biz_id` varchar(128) NOT NULL DEFAULT "" COMMENT "1 for agent_id2 for app_id",
`version` varchar(255) NOT NULL COMMENT "agent or project 版本,为空代表草稿态",
`keyword` varchar(255) NOT NULL COMMENT "记忆的KEY",
`type` tinyint NOT NULL COMMENT "记忆类型 1 KV 2 list",
`content` text NULL COMMENT "记忆内容",
`connector_uid` varchar(255) NOT NULL COMMENT "二方用户ID",
`connector_id` bigint NOT NULL COMMENT "二方id, e.g. coze = 10000010",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "创建时间",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "更新时间",
PRIMARY KEY (`id`),
INDEX `idx_connector_key` (`biz_id`, `biz_type`, `version`, `connector_uid`, `connector_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "KV Memory";
-- Create "variables_meta" table
CREATE TABLE IF NOT EXISTS `variables_meta` (
`id` bigint unsigned NOT NULL DEFAULT 0 COMMENT "主键ID",
`creator_id` bigint unsigned NOT NULL COMMENT "创建者ID",
`biz_type` tinyint unsigned NOT NULL COMMENT "1 for agent2 for app",
`biz_id` varchar(128) NOT NULL DEFAULT "" COMMENT "1 for agent_id2 for app_id",
`variable_list` json NULL COMMENT "变量配置的json数据",
`created_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "create time",
`updated_at` bigint unsigned NOT NULL DEFAULT 0 COMMENT "update time",
`version` varchar(255) NOT NULL COMMENT "project版本,为空代表草稿态",
PRIMARY KEY (`id`),
INDEX `idx_user_key` (`creator_id`),
UNIQUE INDEX `uniq_project_key` (`biz_id`, `biz_type`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT "KV Memory meta";
-- Create "workflow_draft" table
CREATE TABLE IF NOT EXISTS `workflow_draft` (
`id` bigint unsigned NOT NULL COMMENT "workflow ID",
`canvas` mediumtext NOT NULL COMMENT "前端 schema",
`input_params` mediumtext NULL COMMENT " 入参 schema",
`output_params` mediumtext NULL COMMENT " 出参 schema",
`test_run_success` bool NOT NULL DEFAULT 0 COMMENT "0 未运行, 1 运行成功",
`modified` bool NOT NULL DEFAULT 0 COMMENT "0 未被修改, 1 已被修改",
`updated_at` bigint unsigned NULL,
`deleted_at` datetime(3) NULL,
`commit_id` varchar(255) NOT NULL COMMENT "used to uniquely identify a draft snapshot",
PRIMARY KEY (`id`),
INDEX `idx_updated_at` (`updated_at` DESC)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "workflow 画布草稿表用于记录workflow最新的草稿画布信息";
-- Create "workflow_execution" table
CREATE TABLE IF NOT EXISTS `workflow_execution` (
`id` bigint unsigned NOT NULL COMMENT "execute id",
`workflow_id` bigint unsigned NOT NULL COMMENT "workflow_id",
`version` varchar(50) NULL COMMENT "workflow version. empty if is draft",
`space_id` bigint unsigned NOT NULL COMMENT "the space id the workflow belongs to",
`mode` tinyint unsigned NOT NULL COMMENT "the execution mode: 1. debug run 2. release run 3. node debug",
`operator_id` bigint unsigned NOT NULL COMMENT "the user id that runs this workflow",
`connector_id` bigint unsigned NULL COMMENT "the connector on which this execution happened",
`connector_uid` varchar(64) NULL COMMENT "user id of the connector",
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
`log_id` varchar(128) NULL COMMENT "log id",
`status` tinyint unsigned NULL COMMENT "1=running 2=success 3=fail 4=interrupted",
`duration` bigint unsigned NULL COMMENT "execution duration in millisecond",
`input` mediumtext NULL COMMENT "actual input of this execution",
`output` mediumtext NULL COMMENT "the actual output of this execution",
`error_code` varchar(255) NULL COMMENT "error code if any",
`fail_reason` mediumtext NULL COMMENT "the reason for failure",
`input_tokens` bigint unsigned NULL COMMENT "number of input tokens",
`output_tokens` bigint unsigned NULL COMMENT "number of output tokens",
`updated_at` bigint unsigned NULL COMMENT "update time in millisecond",
`root_execution_id` bigint unsigned NULL COMMENT "the top level execution id. Null if this is the root",
`parent_node_id` varchar(128) NULL COMMENT "the node key for the sub_workflow node that executes this workflow",
`app_id` bigint unsigned NULL COMMENT "app id this workflow execution belongs to",
`node_count` mediumint unsigned NULL COMMENT "the total node count of the workflow",
`resume_event_id` bigint unsigned NULL COMMENT "the current event ID which is resuming",
`agent_id` bigint unsigned NULL COMMENT "the agent that this execution binds to",
`sync_pattern` tinyint unsigned NULL COMMENT "the sync pattern 1. sync 2. async 3. stream",
`commit_id` varchar(255) NULL COMMENT "draft commit id this execution belongs to",
PRIMARY KEY (`id`),
INDEX `idx_workflow_id_version_mode_created_at` (`workflow_id`, `version`, `mode`, `created_at`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "workflow 执行记录表用于记录每次workflow执行时的状态";
-- Create "workflow_meta" table
CREATE TABLE IF NOT EXISTS `workflow_meta` (
`id` bigint unsigned NOT NULL COMMENT "workflow id",
`name` varchar(256) NOT NULL COMMENT "workflow name",
`description` varchar(2000) NOT NULL COMMENT "workflow description",
`icon_uri` varchar(256) NOT NULL COMMENT "icon uri",
`status` tinyint unsigned NOT NULL COMMENT "0:未发布过, 1:已发布过",
`content_type` tinyint unsigned NOT NULL COMMENT "0用户 1官方",
`mode` tinyint unsigned NOT NULL COMMENT "0:workflow, 3:chat_flow",
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
`updated_at` bigint unsigned NULL COMMENT "update time in millisecond",
`deleted_at` datetime(3) NULL COMMENT "delete time in millisecond",
`creator_id` bigint unsigned NOT NULL COMMENT "user id for creator",
`tag` tinyint unsigned NULL COMMENT "template tag: Tag: 1=All, 2=Hot, 3=Information, 4=Music, 5=Picture, 6=UtilityTool, 7=Life, 8=Traval, 9=Network, 10=System, 11=Movie, 12=Office, 13=Shopping, 14=Education, 15=Health, 16=Social, 17=Entertainment, 18=Finance, 100=Hidden",
`author_id` bigint unsigned NOT NULL COMMENT "原作者用户 ID",
`space_id` bigint unsigned NOT NULL COMMENT " 空间 ID",
`updater_id` bigint unsigned NULL COMMENT " 更新元信息的用户 ID",
`source_id` bigint unsigned NULL COMMENT " 复制来源的 workflow ID",
`app_id` bigint unsigned NULL COMMENT "应用 ID",
`latest_version` varchar(50) NULL COMMENT "the version of the most recent publish",
`latest_version_ts` bigint unsigned NULL COMMENT "create time of latest version",
PRIMARY KEY (`id`),
INDEX `idx_app_id` (`app_id`),
INDEX `idx_latest_version_ts` (`latest_version_ts` DESC),
INDEX `idx_space_id_app_id_status_latest_version_ts` (`space_id`, `app_id`, `status`, `latest_version_ts`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "workflow 元信息表用于记录workflow基本的元信息";
-- Create "workflow_reference" table
CREATE TABLE IF NOT EXISTS `workflow_reference` (
`id` bigint unsigned NOT NULL COMMENT "workflow id",
`referred_id` bigint unsigned NOT NULL COMMENT "the id of the workflow that is referred by other entities",
`referring_id` bigint unsigned NOT NULL COMMENT "the entity id that refers this workflow",
`refer_type` tinyint unsigned NOT NULL COMMENT "1 subworkflow 2 tool",
`referring_biz_type` tinyint unsigned NOT NULL COMMENT "the biz type the referring entity belongs to: 1. workflow 2. agent",
`created_at` bigint unsigned NOT NULL COMMENT "create time in millisecond",
`status` tinyint unsigned NOT NULL COMMENT "whether this reference currently takes effect. 0: disabled 1: enabled",
`deleted_at` datetime(3) NULL,
PRIMARY KEY (`id`),
INDEX `idx_referred_id_referring_biz_type_status` (`referred_id`, `referring_biz_type`, `status`),
INDEX `idx_referring_id_status` (`referring_id`, `status`),
UNIQUE INDEX `uniq_referred_id_referring_id_refer_type` (`referred_id`, `referring_id`, `refer_type`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "workflow 关联关系表用于记录workflow 直接互相引用关系";
-- Create "workflow_snapshot" table
CREATE TABLE IF NOT EXISTS `workflow_snapshot` (
`workflow_id` bigint unsigned NOT NULL COMMENT "workflow id this snapshot belongs to",
`commit_id` varchar(255) NOT NULL COMMENT "the commit id of the workflow draft",
`canvas` mediumtext NOT NULL COMMENT "frontend schema for this snapshot",
`input_params` mediumtext NULL COMMENT "input parameter info",
`output_params` mediumtext NULL COMMENT "output parameter info",
`created_at` bigint unsigned NOT NULL,
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID",
PRIMARY KEY (`id`),
UNIQUE INDEX `uniq_workflow_id_commit_id` (`workflow_id`, `commit_id`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "snapshot for executed workflow draft";
-- Create "workflow_version" table
CREATE TABLE IF NOT EXISTS `workflow_version` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT "ID",
`workflow_id` bigint unsigned NOT NULL COMMENT "workflow id",
`version` varchar(50) NOT NULL COMMENT "发布版本",
`version_description` varchar(2000) NOT NULL COMMENT "版本描述",
`canvas` mediumtext NOT NULL COMMENT "前端 schema",
`input_params` mediumtext NULL,
`output_params` mediumtext NULL,
`creator_id` bigint unsigned NOT NULL COMMENT "发布用户 ID",
`created_at` bigint unsigned NOT NULL COMMENT "创建时间毫秒时间戳",
`deleted_at` datetime(3) NULL COMMENT "删除毫秒时间戳",
`commit_id` varchar(255) NOT NULL COMMENT "the commit id corresponding to this version",
PRIMARY KEY (`id`),
INDEX `idx_id_created_at` (`workflow_id`, `created_at`),
UNIQUE INDEX `uniq_workflow_id_version` (`workflow_id`, `version`)
) ENGINE=InnoDB CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT "workflow 画布版本信息表,用于记录不同版本的画布信息";

688
docker/volumes/mysql/sql_init.sql Executable file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,28 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
brokerClusterName = DefaultCluster
# 禁用磁盘使用率告警
# min:1, max:95
diskMaxUsedSpaceRatio=95.0
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 使用宿主机IP地址确保客户端可以直接访问
brokerIP1 = 127.0.0.1