Phase 7 Task 7: 插件与集成系统
- 创建 plugin_manager.py 模块
- PluginManager: 插件管理主类
- ChromeExtensionHandler: Chrome 插件处理
- BotHandler: 飞书/钉钉/Slack 机器人处理
- WebhookIntegration: Zapier/Make Webhook 集成
- WebDAVSync: WebDAV 同步管理
- 创建完整的 Chrome 扩展代码
- manifest.json, background.js, content.js, content.css
- popup.html/js: 弹出窗口界面
- options.html/js: 设置页面
- 支持网页剪藏、选中文本保存、项目选择
- 更新 schema.sql 添加插件相关数据库表
- plugins: 插件配置表
- bot_sessions: 机器人会话表
- webhook_endpoints: Webhook 端点表
- webdav_syncs: WebDAV 同步配置表
- plugin_activity_logs: 插件活动日志表
- 更新 main.py 添加插件相关 API 端点
- GET/POST /api/v1/plugins - 插件管理
- POST /api/v1/plugins/chrome/clip - Chrome 插件保存网页
- POST /api/v1/bots/webhook/{platform} - 接收机器人消息
- GET /api/v1/bots/sessions - 机器人会话列表
- POST /api/v1/webhook-endpoints - 创建 Webhook 端点
- POST /webhook/{type}/{token} - 接收外部 Webhook
- POST /api/v1/webdav-syncs - WebDAV 同步配置
- POST /api/v1/webdav-syncs/{id}/test - 测试 WebDAV 连接
- POST /api/v1/webdav-syncs/{id}/sync - 触发 WebDAV 同步
- 更新 requirements.txt 添加插件依赖
- beautifulsoup4: HTML 解析
- webdavclient3: WebDAV 客户端
- 更新 STATUS.md 和 README.md 开发进度
This commit is contained in:
@@ -222,3 +222,320 @@ CREATE INDEX IF NOT EXISTS idx_workflow_logs_workflow ON workflow_logs(workflow_
|
||||
CREATE INDEX IF NOT EXISTS idx_workflow_logs_task ON workflow_logs(task_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_workflow_logs_status ON workflow_logs(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_workflow_logs_created ON workflow_logs(created_at);
|
||||
|
||||
-- Phase 7: 多模态支持相关表
|
||||
|
||||
-- 视频表
|
||||
CREATE TABLE IF NOT EXISTS videos (
|
||||
id TEXT PRIMARY KEY,
|
||||
project_id TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
duration REAL, -- 视频时长(秒)
|
||||
fps REAL, -- 帧率
|
||||
resolution TEXT, -- JSON: {"width": int, "height": int}
|
||||
audio_transcript_id TEXT, -- 关联的音频转录ID
|
||||
full_ocr_text TEXT, -- 所有帧OCR文本合并
|
||||
extracted_entities TEXT, -- JSON: 提取的实体列表
|
||||
extracted_relations TEXT, -- JSON: 提取的关系列表
|
||||
status TEXT DEFAULT 'processing', -- processing, completed, failed
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||
FOREIGN KEY (audio_transcript_id) REFERENCES transcripts(id)
|
||||
);
|
||||
|
||||
-- 视频关键帧表
|
||||
CREATE TABLE IF NOT EXISTS video_frames (
|
||||
id TEXT PRIMARY KEY,
|
||||
video_id TEXT NOT NULL,
|
||||
frame_number INTEGER,
|
||||
timestamp REAL, -- 时间戳(秒)
|
||||
image_data BLOB, -- 帧图片数据(可选,可存储在OSS)
|
||||
image_url TEXT, -- 图片URL(如果存储在OSS)
|
||||
ocr_text TEXT, -- OCR识别文本
|
||||
extracted_entities TEXT, -- JSON: 该帧提取的实体
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (video_id) REFERENCES videos(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 图片表
|
||||
CREATE TABLE IF NOT EXISTS images (
|
||||
id TEXT PRIMARY KEY,
|
||||
project_id TEXT NOT NULL,
|
||||
filename TEXT NOT NULL,
|
||||
image_data BLOB, -- 图片数据(可选)
|
||||
image_url TEXT, -- 图片URL
|
||||
ocr_text TEXT, -- OCR识别文本
|
||||
description TEXT, -- 图片描述(LLM生成)
|
||||
extracted_entities TEXT, -- JSON: 提取的实体列表
|
||||
extracted_relations TEXT, -- JSON: 提取的关系列表
|
||||
status TEXT DEFAULT 'processing',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- 多模态实体提及表
|
||||
CREATE TABLE IF NOT EXISTS multimodal_mentions (
|
||||
id TEXT PRIMARY KEY,
|
||||
project_id TEXT NOT NULL,
|
||||
entity_id TEXT NOT NULL,
|
||||
modality TEXT NOT NULL, -- audio, video, image, document
|
||||
source_id TEXT NOT NULL, -- transcript_id, video_id, image_id
|
||||
source_type TEXT NOT NULL, -- 来源类型
|
||||
position TEXT, -- JSON: 位置信息
|
||||
text_snippet TEXT, -- 提及的文本片段
|
||||
confidence REAL DEFAULT 1.0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 多模态实体关联表
|
||||
CREATE TABLE IF NOT EXISTS multimodal_entity_links (
|
||||
id TEXT PRIMARY KEY,
|
||||
entity_id TEXT NOT NULL,
|
||||
linked_entity_id TEXT NOT NULL, -- 关联的实体ID
|
||||
link_type TEXT NOT NULL, -- same_as, related_to, part_of
|
||||
confidence REAL DEFAULT 1.0,
|
||||
evidence TEXT, -- 关联证据
|
||||
modalities TEXT, -- JSON: 涉及的模态列表
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (entity_id) REFERENCES entities(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (linked_entity_id) REFERENCES entities(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 多模态相关索引
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_project ON videos(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_videos_status ON videos(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_video_frames_video ON video_frames(video_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_images_project ON images(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_images_status ON images(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_mentions_project ON multimodal_mentions(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_mentions_entity ON multimodal_mentions(entity_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_mentions_modality ON multimodal_mentions(modality);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_mentions_source ON multimodal_mentions(source_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_links_entity ON multimodal_entity_links(entity_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_multimodal_links_linked ON multimodal_entity_links(linked_entity_id);
|
||||
|
||||
-- Phase 7 Task 7: 插件与集成相关表
|
||||
|
||||
-- 插件配置表
|
||||
CREATE TABLE IF NOT EXISTS plugins (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
plugin_type TEXT NOT NULL, -- chrome_extension, feishu_bot, dingtalk_bot, zapier, make, webdav, custom
|
||||
project_id TEXT,
|
||||
status TEXT DEFAULT 'active', -- active, inactive, error, pending
|
||||
config TEXT, -- JSON: plugin specific configuration
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_used_at TIMESTAMP,
|
||||
use_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- 插件详细配置表
|
||||
CREATE TABLE IF NOT EXISTS plugin_configs (
|
||||
id TEXT PRIMARY KEY,
|
||||
plugin_id TEXT NOT NULL,
|
||||
config_key TEXT NOT NULL,
|
||||
config_value TEXT,
|
||||
is_encrypted BOOLEAN DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE,
|
||||
UNIQUE(plugin_id, config_key)
|
||||
);
|
||||
|
||||
-- 机器人会话表
|
||||
CREATE TABLE IF NOT EXISTS bot_sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
bot_type TEXT NOT NULL, -- feishu, dingtalk
|
||||
session_id TEXT NOT NULL, -- 群ID或会话ID
|
||||
session_name TEXT NOT NULL,
|
||||
project_id TEXT,
|
||||
webhook_url TEXT,
|
||||
secret TEXT, -- 签名密钥
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_message_at TIMESTAMP,
|
||||
message_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- Webhook 端点表(Zapier/Make集成)
|
||||
CREATE TABLE IF NOT EXISTS webhook_endpoints (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
endpoint_type TEXT NOT NULL, -- zapier, make, custom
|
||||
endpoint_url TEXT NOT NULL,
|
||||
project_id TEXT,
|
||||
auth_type TEXT DEFAULT 'none', -- none, api_key, oauth, custom
|
||||
auth_config TEXT, -- JSON: authentication configuration
|
||||
trigger_events TEXT, -- JSON array: events that trigger this webhook
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_triggered_at TIMESTAMP,
|
||||
trigger_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- WebDAV 同步配置表
|
||||
CREATE TABLE IF NOT EXISTS webdav_syncs (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL,
|
||||
server_url TEXT NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL, -- 建议加密存储
|
||||
remote_path TEXT DEFAULT '/insightflow',
|
||||
sync_mode TEXT DEFAULT 'bidirectional', -- bidirectional, upload_only, download_only
|
||||
sync_interval INTEGER DEFAULT 3600, -- 秒
|
||||
last_sync_at TIMESTAMP,
|
||||
last_sync_status TEXT DEFAULT 'pending', -- pending, success, failed
|
||||
last_sync_error TEXT,
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
sync_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- Chrome 扩展令牌表
|
||||
CREATE TABLE IF NOT EXISTS chrome_extension_tokens (
|
||||
id TEXT PRIMARY KEY,
|
||||
token_hash TEXT NOT NULL UNIQUE, -- SHA256 hash of the token
|
||||
user_id TEXT,
|
||||
project_id TEXT,
|
||||
name TEXT,
|
||||
permissions TEXT, -- JSON array: read, write, delete
|
||||
expires_at TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_used_at TIMESTAMP,
|
||||
use_count INTEGER DEFAULT 0,
|
||||
is_revoked BOOLEAN DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- 插件相关索引
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_project ON plugins(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_type ON plugins(plugin_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_status ON plugins(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugin_configs_plugin ON plugin_configs(plugin_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bot_sessions_project ON bot_sessions(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bot_sessions_type ON bot_sessions(bot_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_webhook_endpoints_project ON webhook_endpoints(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_webhook_endpoints_type ON webhook_endpoints(endpoint_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_webdav_syncs_project ON webdav_syncs(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chrome_tokens_project ON chrome_extension_tokens(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_chrome_tokens_hash ON chrome_extension_tokens(token_hash);
|
||||
|
||||
-- Phase 7: 插件与集成相关表
|
||||
|
||||
-- 插件表
|
||||
CREATE TABLE IF NOT EXISTS plugins (
|
||||
id TEXT PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
plugin_type TEXT NOT NULL, -- chrome_extension, feishu_bot, dingtalk_bot, slack_bot, webhook, webdav, custom
|
||||
project_id TEXT,
|
||||
status TEXT DEFAULT 'active', -- active, inactive, error, pending
|
||||
config TEXT, -- JSON: 插件配置
|
||||
api_key TEXT UNIQUE, -- 用于认证的 API Key
|
||||
api_secret TEXT, -- 用于签名验证的 Secret
|
||||
webhook_url TEXT, -- 机器人 Webhook URL
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_used_at TIMESTAMP,
|
||||
use_count INTEGER DEFAULT 0,
|
||||
success_count INTEGER DEFAULT 0,
|
||||
fail_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- 机器人会话表
|
||||
CREATE TABLE IF NOT EXISTS bot_sessions (
|
||||
id TEXT PRIMARY KEY,
|
||||
plugin_id TEXT NOT NULL,
|
||||
platform TEXT NOT NULL, -- feishu, dingtalk, slack, wechat
|
||||
session_id TEXT NOT NULL, -- 平台特定的会话ID
|
||||
user_id TEXT,
|
||||
user_name TEXT,
|
||||
project_id TEXT, -- 关联的项目ID
|
||||
context TEXT, -- JSON: 会话上下文
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_message_at TIMESTAMP,
|
||||
message_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||
UNIQUE(plugin_id, session_id)
|
||||
);
|
||||
|
||||
-- Webhook 端点表(用于 Zapier/Make 集成)
|
||||
CREATE TABLE IF NOT EXISTS webhook_endpoints (
|
||||
id TEXT PRIMARY KEY,
|
||||
plugin_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
endpoint_path TEXT NOT NULL UNIQUE, -- 如 /webhook/zapier/abc123
|
||||
endpoint_type TEXT NOT NULL, -- zapier, make, custom
|
||||
secret TEXT, -- 用于签名验证
|
||||
allowed_events TEXT, -- JSON: 允许的事件列表
|
||||
target_project_id TEXT, -- 数据导入的目标项目
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
last_triggered_at TIMESTAMP,
|
||||
trigger_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (target_project_id) REFERENCES projects(id)
|
||||
);
|
||||
|
||||
-- WebDAV 同步配置表
|
||||
CREATE TABLE IF NOT EXISTS webdav_syncs (
|
||||
id TEXT PRIMARY KEY,
|
||||
plugin_id TEXT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
server_url TEXT NOT NULL,
|
||||
username TEXT NOT NULL,
|
||||
password TEXT NOT NULL, -- 建议加密存储
|
||||
remote_path TEXT DEFAULT '/',
|
||||
local_path TEXT DEFAULT './sync',
|
||||
sync_direction TEXT DEFAULT 'bidirectional', -- upload, download, bidirectional
|
||||
sync_mode TEXT DEFAULT 'manual', -- manual, realtime, scheduled
|
||||
sync_schedule TEXT, -- cron expression
|
||||
file_patterns TEXT, -- JSON: 文件匹配模式列表
|
||||
auto_analyze BOOLEAN DEFAULT 1, -- 同步后自动分析
|
||||
last_sync_at TIMESTAMP,
|
||||
last_sync_status TEXT,
|
||||
is_active BOOLEAN DEFAULT 1,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
sync_count INTEGER DEFAULT 0,
|
||||
FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 插件活动日志表
|
||||
CREATE TABLE IF NOT EXISTS plugin_activity_logs (
|
||||
id TEXT PRIMARY KEY,
|
||||
plugin_id TEXT NOT NULL,
|
||||
activity_type TEXT NOT NULL, -- message, webhook, sync, error
|
||||
source TEXT NOT NULL, -- 来源标识
|
||||
details TEXT, -- JSON: 详细信息
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (plugin_id) REFERENCES plugins(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-- 插件相关索引
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_project ON plugins(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_type ON plugins(plugin_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugins_api_key ON plugins(api_key);
|
||||
CREATE INDEX IF NOT EXISTS idx_bot_sessions_plugin ON bot_sessions(plugin_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_bot_sessions_project ON bot_sessions(project_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_webhook_endpoints_plugin ON webhook_endpoints(plugin_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_webdav_syncs_plugin ON webdav_syncs(plugin_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugin_logs_plugin ON plugin_activity_logs(plugin_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugin_logs_type ON plugin_activity_logs(activity_type);
|
||||
CREATE INDEX IF NOT EXISTS idx_plugin_logs_created ON plugin_activity_logs(created_at);
|
||||
|
||||
Reference in New Issue
Block a user