From c1816fe6d610461581f07207735908ddf5fea5cf Mon Sep 17 00:00:00 2001 From: Windfarer Date: Mon, 30 Mar 2026 11:13:44 +0800 Subject: [PATCH] add oidc --- .env.example | 23 + CHANGELOG.md | 53 ++ README.md | 75 +- README_CN.md | 187 ++--- README_JA.md | 75 +- README_KO.md | 73 +- VERSION | 2 +- .../prompt_templates/agent_system_prompt.yaml | 5 +- docker-compose.dev.yml | 13 + docker-compose.yml | 12 + docs/IM集成开发文档.md | 123 ++- docs/OIDC认证调用流程.md | 642 ++++++++++++++ docs/QA.md | 18 + frontend/package-lock.json | 36 +- frontend/src/App.vue | 98 ++- frontend/src/api/agent/index.ts | 2 +- frontend/src/api/auth/index.ts | 45 + frontend/src/components/IMChannelPanel.vue | 97 ++- frontend/src/components/doc-content.vue | 4 +- frontend/src/components/document-preview.vue | 2 +- frontend/src/i18n/locales/en-US.ts | 14 +- frontend/src/i18n/locales/ko-KR.ts | 8 +- frontend/src/i18n/locales/ru-RU.ts | 14 +- frontend/src/i18n/locales/zh-CN.ts | 14 +- frontend/src/utils/mermaidShared.ts | 3 +- frontend/src/views/auth/Login.vue | 780 ++++++------------ .../chat/components/AgentStreamDisplay.vue | 5 +- frontend/src/views/chat/components/botmsg.vue | 4 +- frontend/vite.config.ts | 4 +- helm/Chart.yaml | 2 +- internal/agent/const.go | 7 + internal/agent/engine.go | 23 + internal/agent/engine_test.go | 221 +++++ internal/agent/observe.go | 14 +- internal/agent/think.go | 21 +- internal/application/repository/knowledge.go | 46 +- internal/application/service/user.go | 417 ++++++++++ internal/config/config.go | 133 ++- internal/container/container.go | 56 ++ internal/handler/auth.go | 157 ++++ internal/handler/im.go | 19 +- internal/im/adapter.go | 11 +- internal/im/mattermost/adapter.go | 341 ++++++++ internal/im/mattermost/client.go | 182 ++++ internal/im/mattermost/form_parse.go | 27 + internal/im/types.go | 10 +- internal/middleware/auth.go | 11 +- internal/models/chat/remote_api.go | 20 + internal/router/router.go | 3 + internal/types/chat.go | 1 + internal/types/interfaces/user.go | 4 + internal/types/user.go | 30 + misc/dex-config.yaml | 20 + scripts/dev.sh | 12 +- 54 files changed, 3412 insertions(+), 807 deletions(-) create mode 100644 docs/OIDC认证调用流程.md create mode 100644 internal/agent/engine_test.go create mode 100644 internal/im/mattermost/adapter.go create mode 100644 internal/im/mattermost/client.go create mode 100644 internal/im/mattermost/form_parse.go create mode 100644 misc/dex-config.yaml diff --git a/.env.example b/.env.example index 4b9255dc..e5236ac4 100644 --- a/.env.example +++ b/.env.example @@ -309,3 +309,26 @@ DOCREADER_TRANSPORT=grpc # Weaviate 数据库名称(可选) #WEAVIATE_COLLECTION=your_weaviate_db_name + +# ----- OIDC Auth ----- +# 如果需要启用OIDC登录,设为true并填写后续字段 +# OIDC_AUTH_ENABLE=false + +# (Optional) 用于OIDC自动发现端点配置 +# OIDC_AUTH_ISSUER_URL=http://127.0.0.1:5556/dex +# OIDC_AUTH_DISCOVERY_URL=http://127.0.0.1:5556/dex/.well-known/openid-configuration + +# OIDC_AUTH_PROVIDER_DISPLAY_NAME=OIDC +# OIDC_AUTH_CLIENT_ID=client_id_for_oidc_client +# OIDC_AUTH_CLIENT_SECRET=secret_for_oidc_client + +# (Optional) OIDC 端点配置, 如果上面的OIDC_AUTH_DISCOVERY_URL填过了,下面的这些可以留空 +# OIDC_AUTH_AUTHORIZATION_ENDPOINT=http://127.0.0.1:5556/dex/auth +# OIDC_AUTH_TOKEN_ENDPOINT=http://127.0.0.1:5556/dex/token +# OIDC_AUTH_USER_INFO_ENDPOINT=http://127.0.0.1:5556/dex/userinfo + +# OIDC_AUTH_SCOPES="openid profile email" + +# 用于OIDC用于信息中提取用户数据 +# OIDC_USER_INFO_MAPPING_USER_NAME=name +# OIDC_USER_INFO_MAPPING_EMAIL=email \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index e0b6b445..82f4caaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,58 @@ All notable changes to this project will be documented in this file. +## [0.3.5] - 2026-03-27 + +### 🚀 New Features +- **NEW**: Telegram IM Integration — Telegram bot adapter with webhook and long-polling modes, streaming replies via editMessageText, file download via getFile API, and timing-safe secret token verification +- **NEW**: DingTalk IM Integration — DingTalk bot supporting webhook (HmacSHA256 signature verification) and Stream mode (via dingtalk-stream-sdk-go), with AI Card streaming via OpenAPI and AccessToken caching +- **NEW**: Mattermost IM Channel — Mattermost IM channel adapter support +- **NEW**: IM Slash Command System — pluggable command framework with five built-in commands: /help, /info, /search, /stop, /clear; wired into all IM channel message dispatch +- **NEW**: IM Distributed Coordination — Redis-based multi-instance coordination: per-user queue limits, global concurrency gate, message dedup, WebSocket leader election, /stop cancellation for queued and in-flight requests +- **NEW**: Suggested Questions — agent-specific suggested questions API based on knowledge bases, with frontend display in chat and create-chat views; image knowledge auto-enqueues question generation tasks +- **NEW**: VLM Auto-Describe MCP Tool Images — when MCP tools return image content, the agent automatically generates text descriptions via the configured VLM model, making image data accessible to text-only LLMs +- **NEW**: Novita AI Provider — new LLM provider with OpenAI-compatible API supporting chat, embedding, and VLLM model types +- **NEW**: Channel Tracking — channel field added to knowledge entries and messages to track source (web/api/im/browser_extension) with frontend labels and DB migrations +- **NEW**: Expose Built-in Parser Engine in Settings — built-in parser engine now visible and selectable in the settings UI + +### ⚡ Improvements +- MCP tool names now derived from service.Name (stable across server reconnections) instead of UUID; added collision detection and unique (tenant_id, name) DB index +- Frontend formats MCP tool names from snake_case (e.g. mcp_my_server_search_docs) to human-readable form (My Server Search Docs) +- Enhanced intent classification and context templates: runtime metadata (current time, weekday) injected into context, critical instructions added to rewrite template for entity/keyword preservation +- Knowledge search: added SQL LIKE wildcard escaping, title-based filtering, URL and HTML file type support; FindByMetadataKey method added +- Chunk search returns total chunk counts per knowledge ID for improved agent context awareness +- MiniMax models upgraded from M2.1/M2.1-lightning to M2.7/M2.7-highspeed; Novita AI MiniMax reference updated to M2.7 +- DingTalk AI Card streaming: create/deliver/update via OpenAPI; shared think-block rendering via im.TransformThinkBlocks applied to all IM reply paths (DingTalk, Telegram, Feishu) +- IM stream orphan reaper and edit throttling added for DingTalk and Telegram; Feishu stream reaper fixes memory leak +- WeCom group chat replies fixed via appchat API with user fallback; empty-stream fallback when no visible content is produced +- Improved LLM call log summarization: limits output to last few messages to reduce verbosity +- ParallelToolCalls option added to ChatOptions + +### 🐛 Bug Fixes +- Fixed agent producing empty response when no knowledge base is configured: retry (max 2), nudge message, and fallback response added +- Fixed UTF-8 byte-based truncation in summary fallback causing PostgreSQL invalid byte sequence errors for Chinese/emoji content; changed to rune-based truncation +- Fixed marked.js usage errors; upgraded marked dependency to v17.0.5 for correct code block rendering +- Fixed vLLM streaming: reasoning content now parsed and propagated through streaming pipeline alongside standard response +- Fixed frontend page counter not resetting to 1 after knowledge file operations (tag, upload, move, edit, delete), causing pagination skips +- Fixed image markdown being stripped during message sanitization +- Fixed MCP tool naming to use service.Name instead of UUID, preventing tool call failures after server reconnection +- Fixed global default storage engine not respected when creating a new knowledge base (was hardcoded to "local") +- Fixed API key encryption loss when updating tenant settings via PUT /tenants/kv/{key}: AfterFind-decrypted plaintext no longer written back to DB +- Fixed empty passage filtering in rerank to prevent Aliyun and Baidu Qianfan 400 errors +- Fixed markdown table rows being passed raw to rerank; now converted to plain text (col1, col2) before reranking +- Fixed OpenRouter embedding provider missing support +- Fixed Milvus vector metric type now configurable via MILVUS_METRIC_TYPE environment variable +- Fixed temperature validation to accept zero as a valid value (was previously defaulting) +- Fixed pg_search update guarded with skip_embedding to prevent unnecessary re-embedding +- Fixed thinking block content being indexed into chat history knowledge base, degrading RAG retrieval quality + +### 📚 Documentation +- Added Telegram and DingTalk IM platform setup guides (WebSocket/Webhook modes, streaming, architecture diagrams) +- Updated IM integration docs with Slack, slash commands, QA queue, rate limiting, and streaming output sections + +### 🔒 Security Enhancements +- Enhanced SSRF protection in RemoteAPIChat: replaced default DialContext with SSRFSafeDialContext; added SSRF URL validation for BaseURL and endpoint in NewRemoteAPIChat and chat methods + ## [0.3.4] - 2026-03-19 ### 🚀 New Features @@ -740,6 +792,7 @@ All notable changes to this project will be documented in this file. - Docker Compose for quick startup and service orchestration. - MCP server support for integrating with MCP-compatible clients. +[0.3.5]: https://github.com/Tencent/WeKnora/tree/v0.3.5 [0.3.4]: https://github.com/Tencent/WeKnora/tree/v0.3.4 [0.3.3]: https://github.com/Tencent/WeKnora/tree/v0.3.3 [0.3.2]: https://github.com/Tencent/WeKnora/tree/v0.3.2 diff --git a/README.md b/README.md index b64c3fdf..95aaea3e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ License - Version + Version

@@ -50,6 +50,17 @@ It adopts a modular architecture that combines multimodal preprocessing, semanti ## ✨ Latest Updates +**v0.3.5 Highlights:** + +- **Telegram, DingTalk & Mattermost IM Integration**: Added Telegram bot (webhook/long-polling, streaming via editMessageText), DingTalk bot (webhook/Stream mode, AI Card streaming), and Mattermost adapter; IM channel coverage now includes WeCom, Feishu, Slack, Telegram, DingTalk, and Mattermost +- **IM Slash Commands & QA Queue**: Pluggable slash-command system (/help, /info, /search, /stop, /clear) with a bounded QA worker pool, per-user rate limiting, and Redis-based multi-instance coordination +- **Suggested Questions**: Agents surface context-aware suggested questions based on configured knowledge bases; image knowledge automatically enqueues question generation +- **VLM Auto-Describe MCP Tool Images**: When MCP tools return images, the agent generates text descriptions via the configured VLM model, enabling image content to be used by text-only LLMs +- **Novita AI Provider**: New LLM provider with OpenAI-compatible API supporting chat, embedding, and VLLM model types +- **MCP Tool Name Stability**: Tool names now based on service name (stable across reconnections) instead of UUID; unique name constraint added; frontend formats names into human-readable form +- **Channel Tracking**: Knowledge entries and messages record source channel (web/api/im/browser_extension) for traceability +- **Bug Fixes**: Fixed agent empty response when no knowledge base is configured, UTF-8 truncation in summaries for Chinese/emoji documents, API key encryption loss on tenant settings update, vLLM streaming reasoning content propagation, and rerank empty passage errors + **v0.3.4 Highlights:** - **IM Bot Integration**: WeCom, Feishu, and Slack IM channel support with WebSocket/Webhook modes, streaming, and knowledge base integration @@ -60,25 +71,21 @@ It adopts a modular architecture that combines multimodal preprocessing, semanti - **AWS S3 Storage**: Integrated AWS S3 storage adapter with configuration UI and database migrations - **AES-256-GCM Encryption**: API keys encrypted at rest with AES-256-GCM for enhanced security - **Built-in MCP Service**: Built-in MCP service support for extending agent capabilities -- **Agent Streaming Panel**: Optimized AgentStreamDisplay with auto-scrolling, improved styling, and loading indicators - **Hybrid Search Optimization**: Grouped targets and reused query embeddings for better retrieval performance - **Final Answer Tool**: New final_answer tool with agent duration tracking for improved agent workflows -**v0.3.3 Highlights:** - -- 🧩 **Parent-Child Chunking**: Hierarchical parent-child chunking strategy for enhanced context management and more accurate retrieval -- 📌 **Knowledge Base Pinning**: Pin frequently-used knowledge bases for quick access -- 🔄 **Fallback Response**: Fallback response handling with UI indicators when no relevant results are found -- 🖼️ **Image Icon Detection**: Automatic image icon detection and filtering in document processing -- 🧹 **Passage Cleaning for Rerank**: Passage cleaning for rerank model to improve relevance scoring accuracy -- 🐳 **Docker & Skill Management**: Enhanced Docker setup with entrypoint script and skill management -- 🗄️ **Storage Auto-Creation**: Storage engine connectivity check with auto-creation of buckets -- 🎨 **UI Consistency**: Standardized border styles, updated theme and component styles across the application -- ⚡ **Chunk Size Tuning**: Updated chunk size configurations for knowledge base processing -
Earlier Releases +**v0.3.3 Highlights:** + +- **Parent-Child Chunking**: Hierarchical parent-child chunking strategy for enhanced context management and more accurate retrieval +- **Knowledge Base Pinning**: Pin frequently-used knowledge bases for quick access +- **Fallback Response**: Fallback response handling with UI indicators when no relevant results are found +- **Passage Cleaning for Rerank**: Passage cleaning for rerank model to improve relevance scoring accuracy +- **Storage Auto-Creation**: Storage engine connectivity check with auto-creation of buckets +- **Milvus Vector DB**: Added Milvus as a new vector database backend for knowledge retrieval + **v0.3.2 Highlights:** - 🔍 **Knowledge Search**: New "Knowledge Search" entry point with semantic retrieval, supporting bringing search results directly into the conversation window @@ -163,24 +170,28 @@ WeKnora employs a modern modular design to build a complete document understandi ## 🧩 Feature Matrix -| Module | Support | Description | -|---------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Agent Mode | ✅ ReACT Agent Mode | Support for using built-in tools to retrieve knowledge bases, MCP tools, and web search, with cross-knowledge base retrieval and multiple iterations | -| Knowledge Base Types | ✅ FAQ / Document | Support for creating FAQ and document knowledge base types, with folder import, URL import, tag management, and online entry | -| Document Formats | ✅ PDF / Word / Txt / Markdown / Images (with OCR / Caption) | Support for structured and unstructured documents with text extraction from images | -| Model Management | ✅ Centralized configuration, built-in model sharing | Centralized model configuration with model selection in knowledge base settings, support for multi-tenant shared built-in models | -| Embedding Models | ✅ Local models, BGE / GTE APIs, etc. | Customizable embedding models, compatible with local deployment and cloud vector generation APIs | -| Vector DB Integration | ✅ PostgreSQL (pgvector), Elasticsearch | Support for mainstream vector index backends, flexible switching for different retrieval scenarios | -| Retrieval Strategies | ✅ BM25 / Dense Retrieval / GraphRAG | Support for sparse/dense recall and knowledge graph-enhanced retrieval with customizable retrieve-rerank-generate pipelines | -| LLM Integration | ✅ Support for Qwen, DeepSeek, etc., with thinking/non-thinking mode switching | Compatible with local models (e.g., via Ollama) or external API services with flexible inference configuration | -| Conversation Strategy | ✅ Agent models, normal mode models, retrieval thresholds, Prompt configuration | Support for configuring Agent models, normal mode models, retrieval thresholds, online Prompt configuration, precise control over multi-turn conversation behavior | -| Web Search | ✅ Extensible search engines, DuckDuckGo / Google | Support for extensible web search engines with built-in DuckDuckGo search engine | -| MCP Tools | ✅ uvx, npx launchers, Stdio/HTTP Streamable/SSE | Support for extending Agent capabilities through MCP, with built-in uvx and npx launchers, supporting three transport methods | -| QA Capabilities | ✅ Context-aware, multi-turn dialogue, prompt templates | Support for complex semantic modeling, instruction control and chain-of-thought Q&A with configurable prompts and context windows | -| E2E Testing | ✅ Retrieval+generation process visualization and metric evaluation | End-to-end testing tools for evaluating recall hit rates, answer coverage, BLEU/ROUGE and other metrics | -| Deployment Modes | ✅ Support for local deployment / Docker images | Meets private, offline deployment and flexible operation requirements, with fast development mode support | -| User Interfaces | ✅ Web UI + RESTful API | Interactive interface and standard API endpoints, with Agent mode/normal mode switching and tool call process display | -| Task Management | ✅ MQ async tasks, automatic database migration | MQ-based async task state maintenance, support for automatic database schema and data migration during version upgrades | +| Module | Support | Description | +|---------|---------|-------------| +| Agent Mode | ✅ ReACT Agent Mode | Built-in tools for knowledge base retrieval, MCP tool calls, and web search; cross-knowledge base retrieval with multi-step iteration | +| Knowledge Base Types | ✅ FAQ / Document | FAQ and document knowledge bases with folder import, URL import, tag management, online entry, and knowledge move | +| Document Formats | ✅ PDF / Word / Txt / Markdown / HTML / Images (OCR + Caption) | Structured and unstructured document parsing; image text extraction via OCR; image caption generation via VLM | +| IM Channel Integration | ✅ WeCom / Feishu / Slack / Telegram / DingTalk / Mattermost | WebSocket and Webhook modes; streaming replies; slash commands (/help, /info, /search, /stop, /clear); per-user rate limiting; Redis-based multi-instance coordination | +| Model Management | ✅ Centralized configuration, built-in model sharing | Centralized model config with per-knowledge-base model selection; multi-tenant shared built-in model support | +| Embedding Models | ✅ Local models (Ollama), BGE / GTE / OpenAI-compatible APIs | Customizable embedding models compatible with local deployment and cloud vector generation APIs | +| Vector DB Integration | ✅ PostgreSQL (pgvector) / Elasticsearch / Milvus / Weaviate / Qdrant | Five vector index backends with flexible switching to match retrieval scenario requirements | +| Object Storage | ✅ Local / MinIO / AWS S3 / Volcengine TOS | Pluggable storage adapters for file and image assets; bucket auto-creation on startup | +| Retrieval Strategies | ✅ BM25 / Dense Retrieval / GraphRAG | Sparse/dense recall and knowledge graph-enhanced retrieval; customizable retrieve-rerank-generate pipeline | +| LLM Integration | ✅ Qwen / DeepSeek / MiniMax / NVIDIA / Novita AI / OpenAI-compatible | Local models via Ollama or external API services; thinking/non-thinking mode switching; vLLM streaming reasoning content support | +| Conversation Strategy | ✅ Agent model, normal model, retrieval threshold, Prompt configuration | Online Prompt editing; retrieval threshold tuning; precise multi-turn conversation behavior control | +| Web Search | ✅ DuckDuckGo / Bing / Google (extensible) | Pluggable search engine providers; web search toggle per conversation | +| MCP Tools | ✅ uvx / npx launchers, Stdio / HTTP Streamable / SSE | Extend agent capabilities via MCP; stable tool naming with collision protection; VLM auto-description for tool-returned images | +| Suggested Questions | ✅ Knowledge-base-driven question suggestions | Agent surfaces context-aware suggested questions in chat interface; image knowledge auto-generates questions | +| QA Capabilities | ✅ Context-aware, multi-turn dialogue, prompt templates | Complex semantic modeling, instruction control, chain-of-thought Q&A with configurable prompts and context windows | +| Security | ✅ AES-256-GCM at-rest encryption, SSRF protection | API keys encrypted at rest; SSRF-safe HTTP client for remote API calls; sandbox execution for agent skills | +| E2E Testing | ✅ Retrieval + generation visualization and metric evaluation | End-to-end test tools for evaluating recall hit rates, answer coverage, BLEU/ROUGE metrics | +| Deployment Modes | ✅ Local / Docker / Kubernetes (Helm) | Private and offline deployment; fast development mode with hot-reload; Helm chart for Kubernetes | +| User Interfaces | ✅ Web UI + RESTful API | Interactive web interface and standard API; Agent/normal mode switching; tool call process display | +| Task Management | ✅ MQ async tasks, automatic database migration | MQ-based async task state; automatic schema and data migration on version upgrade | ## 🚀 Getting Started diff --git a/README_CN.md b/README_CN.md index 547cdbc2..47a7a961 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,55 +1,42 @@ -

- - WeKnora Logo - -

-

- - - Tencent%2FWeKnora | Trendshift - - -

-

- - 官方网站 - - - 微信对话开放平台 - - - License - - - 版本 - -

-

-| English | 简体中文 | 日本語 | -

-

-

+ + + +| **[English](./README.md)** | **简体中文** | **[日本語](./README_JA.md)** | + + + + [项目介绍](#-项目介绍) • [架构设计](#-架构设计) • [核心特性](#-核心特性) • [快速开始](#-快速开始) • [文档](#-文档) • [开发指南](#-开发指南) -

-

+ # 💡 WeKnora - 基于大模型的文档理解检索框架 ## 📌 项目介绍 -[**WeKnora(维娜拉)**](https://weknora.weixin.qq.com) 是一款基于大语言模型(LLM)的文档理解与语义检索框架,专为结构复杂、内容异构的文档场景而打造。 +**[WeKnora(维娜拉)](https://weknora.weixin.qq.com)** 是一款基于大语言模型(LLM)的文档理解与语义检索框架,专为结构复杂、内容异构的文档场景而打造。 框架采用模块化架构,融合多模态预处理、语义向量索引、智能召回与大模型生成推理,构建起高效、可控的文档问答流程。核心检索流程基于 **RAG(Retrieval-Augmented Generation)** 机制,将上下文相关片段与语言模型结合,实现更高质量的语义回答。 -**官网:** https://weknora.weixin.qq.com +**官网:** [https://weknora.weixin.qq.com](https://weknora.weixin.qq.com) ## ✨ 最新更新 +**v0.3.5 版本亮点:** + +- **Telegram、ding'ding & Mattermost IM集成**:新增Telegram机器人(webhook/长轮询,流式editMessageText回复)、钉钉机器人(webhook/Stream模式,AI卡片流式输出)和Mattermost适配器;IM频道现已覆盖企业微信、飞书、Slack、Telegram、钉钉、Mattermost共6个平台 +- **IM斜杠命令与QA队列**:可插拔斜杠命令框架(/help、/info、/search、/stop、/clear),配合有界QA工作池、用户级限流和基于Redis的多实例分布式协调 +- **推荐问题**:Agent基于关联知识库自动生成上下文相关的推荐问题,在对话界面开场前展示;图片知识自动触发问题生成任务 +- **VLM自动描述MCP工具返回图片**:当MCP工具返回图片时,Agent通过配置的VLM模型自动生成文字描述,使不支持图片输入的LLM也能理解图片内容 +- **Novita AI提供商**:新增Novita AI,通过OpenAI兼容接口支持Chat、Embedding和VLLM模型类型 +- **MCP工具名称稳定性**:工具名称改为基于service.Name(跨重连保持稳定),新增唯一名称约束和碰撞防护;前端将snake_case工具名格式化为可读形式 +- **来源频道标记**:知识条目和消息新增channel字段,记录来源(web/api/im/browser_extension),便于追溯 +- **重要修复**:修复无知识库时Agent空响应、中文/emoji文档摘要UTF-8截断、租户设置更新时API密钥加密丢失、vLLM流式推理内容缺失、Rerank空段落过滤等问题 + **v0.3.4 版本亮点:** - **IM机器人集成**:支持企业微信、飞书、Slack IM频道,WebSocket/Webhook双模式,流式回复与知识库集成 @@ -60,24 +47,19 @@ - **AWS S3存储**:集成AWS S3存储适配器,配置界面及数据库迁移 - **AES-256-GCM加密**:API密钥静态加密,采用AES-256-GCM增强安全性 - **内置MCP服务**:支持内置MCP服务,扩展Agent能力 -- **Agent流式交互面板**:优化AgentStreamDisplay组件,自动滚动、样式增强与加载指示器 - **混合检索优化**:按目标分组并复用查询向量,提升检索性能 - **Final Answer工具**:新增final_answer工具及Agent耗时跟踪,优化Agent工作流 +**更早版本** + **v0.3.3 版本亮点:** -- 🧩 **父子分块策略**:层级化的父子分块策略,增强上下文管理和检索精度 -- 📌 **知识库置顶**:支持置顶常用知识库,快速访问 -- 🔄 **兜底回复**:无相关结果时的兜底回复处理及UI指示 -- 🖼️ **图片图标检测**:文档处理中的图片图标自动检测与过滤 -- 🧹 **Rerank段落清洗**:Rerank模型段落清洗功能,提升相关性评分准确度 -- 🐳 **Docker与技能管理**:增强Docker设置,新增入口脚本和技能管理 -- 🗄️ **存储桶自动创建**:存储引擎连通性检查增强,支持自动创建存储桶 -- 🎨 **UI一致性优化**:统一边框样式、更新主题和组件样式,全面提升视觉一致性 -- ⚡ **分块尺寸调优**:更新知识库处理中的分块大小配置 - -
-更早版本 +- **父子分块策略**:层级化的父子分块策略,增强上下文管理和检索精度 +- **知识库置顶**:支持置顶常用知识库,快速访问 +- **兜底回复**:无相关结果时的兜底回复处理及UI指示 +- **Rerank段落清洗**:Rerank模型段落清洗功能,提升相关性评分准确度 +- **存储桶自动创建**:存储引擎连通性检查增强,支持自动创建存储桶 +- **Milvus向量数据库**:新增Milvus向量数据库后端,用于知识检索 **v0.3.2 版本亮点:** @@ -120,7 +102,7 @@ - 🎨 **全新UI**:优化对话界面,支持Agent模式/普通模式切换,展示工具调用过程,知识库管理界面全面升级 - ⚡ **底层升级**:引入MQ异步任务管理,支持数据库自动迁移,提供快速开发模式 -
+ ## 🔒 安全声明 @@ -133,7 +115,7 @@ ## 🏗️ 架构设计 -![weknora-pipelone.png](./docs/images/architecture.png) +weknora-pipelone.png WeKnora 采用现代化模块化设计,构建了一条完整的文档理解与检索流水线。系统主要包括文档解析、向量化处理、检索引擎和大模型推理等核心模块,每个组件均可灵活配置与扩展。 @@ -153,34 +135,42 @@ WeKnora 采用现代化模块化设计,构建了一条完整的文档理解与 ## 📊 适用场景 -| 应用场景 | 具体应用 | 核心价值 | -|---------|----------|----------| -| **企业知识管理** | 内部文档检索、规章制度问答、操作手册查询 | 提升知识查找效率,降低培训成本 | -| **科研文献分析** | 论文检索、研究报告分析、学术资料整理 | 加速文献调研,辅助研究决策 | -| **产品技术支持** | 产品手册问答、技术文档检索、故障排查 | 提升客户服务质量,减少技术支持负担 | -| **法律合规审查** | 合同条款检索、法规政策查询、案例分析 | 提高合规效率,降低法律风险 | -| **医疗知识辅助** | 医学文献检索、诊疗指南查询、病例分析 | 辅助临床决策,提升诊疗质量 | + +| 应用场景 | 具体应用 | 核心价值 | +| ---------- | -------------------- | ----------------- | +| **企业知识管理** | 内部文档检索、规章制度问答、操作手册查询 | 提升知识查找效率,降低培训成本 | +| **科研文献分析** | 论文检索、研究报告分析、学术资料整理 | 加速文献调研,辅助研究决策 | +| **产品技术支持** | 产品手册问答、技术文档检索、故障排查 | 提升客户服务质量,减少技术支持负担 | +| **法律合规审查** | 合同条款检索、法规政策查询、案例分析 | 提高合规效率,降低法律风险 | +| **医疗知识辅助** | 医学文献检索、诊疗指南查询、病例分析 | 辅助临床决策,提升诊疗质量 | + ## 🧩 功能模块能力 -| 功能模块 | 支持情况 | 说明 | -|---------|-----------------------------------------------------|------| -| Agent模式 | ✅ ReACT Agent模式 | 支持使用内置工具检索知识库、MCP工具和网络搜索,跨知识库检索,多次迭代和反思 | -| 知识库类型 | ✅ FAQ / 文档 | 支持创建FAQ和文档两种类型知识库,支持文件夹导入、URL导入、标签管理和在线录入 | -| 文档格式支持 | ✅ PDF / Word / Txt / Markdown / 图片(含 OCR / Caption) | 支持多种结构化与非结构化文档内容解析,支持图文混排与图像文字提取 | -| 模型管理 | ✅ 集中配置、内置模型共享 | 模型集中配置,知识库设置页增加模型选择,支持多租户共享内置模型 | -| 嵌入模型支持 | ✅ 本地模型、BGE / GTE API 等 | 支持自定义 embedding 模型,兼容本地部署与云端向量生成接口 | -| 向量数据库接入 | ✅ PostgreSQL(pgvector)、Elasticsearch | 支持主流向量索引后端,可灵活切换与扩展,适配不同检索场景 | -| 检索机制 | ✅ BM25 / Dense Retrieve / GraphRAG | 支持稠密/稀疏召回、知识图谱增强检索等多种策略,可自由组合召回-重排-生成流程 | -| 大模型集成 | ✅ 支持 Qwen、DeepSeek 等,思考/非思考模式切换 | 可接入本地大模型(如 Ollama 启动)或调用外部 API 服务,支持推理模式灵活配置 | -| 对话策略 | ✅ Agent模型、普通模式模型、检索阈值、Prompt配置 | 支持配置Agent模型、普通模式所需的模型、检索阈值,在线配置Prompt,精确控制多轮对话行为 | -| 网络搜索 | ✅ 可扩展搜索引擎、DuckDuckGo / Google | 支持可扩展的网络搜索引擎,内置DuckDuckGo搜索引擎 | -| MCP工具 | ✅ uvx、npx启动工具,Stdio/HTTP Streamable/SSE | 支持通过MCP扩展Agent能力,内置uvx、npx两种MCP启动工具,支持三种传输方式 | -| 问答能力 | ✅ 上下文感知、多轮对话、提示词模板 | 支持复杂语义建模、指令控制与链式问答,可配置提示词与上下文窗口 | -| 端到端测试支持 | ✅ 检索+生成过程可视化与指标评估 | 提供一体化链路测试工具,支持评估召回命中率、回答覆盖度、BLEU / ROUGE 等主流指标 | -| 部署模式 | ✅ 支持本地部署 / Docker 镜像 | 满足私有化、离线部署与灵活运维的需求,支持快速开发模式 | -| 用户界面 | ✅ Web UI + RESTful API | 提供交互式界面与标准 API 接口,支持Agent模式/普通模式切换,展示工具调用过程 | -| 任务管理 | ✅ MQ异步任务、数据库自动迁移 | 引入MQ对异步任务进行状态维护,支持版本升级时的数据库表结构和数据自动迁移 | + +| 功能模块 | 支持情况 | 说明 | +| ------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------- | +| Agent模式 | ✅ ReACT Agent模式 | 内置工具检索知识库、调用MCP工具和网络搜索;支持跨知识库检索与多轮迭代推理 | +| 知识库类型 | ✅ FAQ / 文档 | FAQ和文档两种类型,支持文件夹导入、URL导入、标签管理、在线录入和知识迁移 | +| 文档格式支持 | ✅ PDF / Word / Txt / Markdown / HTML / 图片(OCR + Caption) | 结构化与非结构化文档解析;图片OCR文字提取;VLM图片描述生成 | +| IM频道集成 | ✅ 企业微信 / 飞书 / Slack / Telegram / 钉钉 / Mattermost | WebSocket和Webhook双模式;流式回复;斜杠命令(/help、/info、/search、/stop、/clear);用户级限流;基于Redis的多实例分布式协调 | +| 模型管理 | ✅ 集中配置、内置模型共享 | 模型集中配置,知识库级别模型选择,支持多租户共享内置模型 | +| 嵌入模型支持 | ✅ 本地模型(Ollama)、BGE / GTE / OpenAI兼容接口 | 支持自定义embedding模型,兼容本地部署与云端向量生成接口 | +| 向量数据库接入 | ✅ PostgreSQL(pgvector)/ Elasticsearch / Milvus / Weaviate / Qdrant | 五种向量索引后端,可灵活切换,适配不同检索场景 | +| 对象存储 | ✅ 本地 / MinIO / AWS S3 / 火山引擎TOS | 可插拔存储适配器;启动时自动创建存储桶 | +| 检索机制 | ✅ BM25 / Dense Retrieve / GraphRAG | 稠密/稀疏召回、知识图谱增强检索;可自由组合召回-重排-生成流程 | +| 大模型集成 | ✅ Qwen / DeepSeek / MiniMax / NVIDIA / Novita AI / OpenAI兼容 | 接入本地大模型(Ollama)或外部API服务;思考/非思考模式切换;vLLM流式推理内容支持 | +| 对话策略 | ✅ Agent模型、普通模式模型、检索阈值、Prompt配置 | 在线Prompt编辑;检索阈值调节;精确控制多轮对话行为 | +| 网络搜索 | ✅ DuckDuckGo / Bing / Google(可扩展) | 可插拔搜索引擎;按对话开关网络搜索 | +| MCP工具 | ✅ uvx / npx启动工具,Stdio / HTTP Streamable / SSE | 通过MCP扩展Agent能力;工具名称稳定(跨重连保持一致);VLM自动描述工具返回图片 | +| 推荐问题 | ✅ 基于知识库的问题推荐 | Agent在对话前展示推荐问题;图片知识自动触发问题生成 | +| 问答能力 | ✅ 上下文感知、多轮对话、提示词模板 | 复杂语义建模、指令控制与链式问答,可配置提示词与上下文窗口 | +| 安全机制 | ✅ AES-256-GCM静态加密、SSRF防护 | API密钥静态加密;远程API调用的SSRF安全校验;Agent技能沙盒执行 | +| 端到端测试支持 | ✅ 检索+生成过程可视化与指标评估 | 一体化链路测试,支持评估召回命中率、回答覆盖度、BLEU/ROUGE等指标 | +| 部署模式 | ✅ 本地 / Docker / Kubernetes(Helm) | 私有化和离线部署;热重载快速开发模式;Helm Chart支持Kubernetes部署 | +| 用户界面 | ✅ Web UI + RESTful API | 交互式界面与标准API;Agent/普通模式切换;工具调用过程可视化 | +| 任务管理 | ✅ MQ异步任务、数据库自动迁移 | MQ异步任务状态维护;版本升级时自动执行数据库表结构和数据迁移 | + ## 🚀 快速开始 @@ -188,9 +178,9 @@ WeKnora 采用现代化模块化设计,构建了一条完整的文档理解与 确保本地已安装以下工具: -* [Docker](https://www.docker.com/) -* [Docker Compose](https://docs.docker.com/compose/) -* [Git](https://git-scm.com/) +- [Docker](https://www.docker.com/) +- [Docker Compose](https://docs.docker.com/compose/) +- [Git](https://git-scm.com/) ### 📦 安装步骤 @@ -235,31 +225,37 @@ ollama serve > /dev/null 2>&1 & #### ③.1 激活不同组合的功能 - 启动最小功能 + ```bash docker compose up -d ``` - 启动全部功能 + ```bash docker-compose --profile full up -d ``` - 需要 tracing 日志 + ```bash docker-compose --profile jaeger up -d ``` - 需要 neo4j 知识图谱 + ```bash docker-compose --profile neo4j up -d ``` - 需要 minio 文件存储服务 + ```bash docker-compose --profile minio up -d ``` - 多选项组合 + ```bash docker-compose --profile neo4j --profile minio up -d ``` @@ -276,9 +272,9 @@ make stop-all 启动成功后,可访问以下地址: -* Web UI:`http://localhost` -* 后端 API:`http://localhost:8080` -* 链路追踪(Jaeger):`http://localhost:16686` +- Web UI:`http://localhost` +- 后端 API:`http://localhost:8080` +- 链路追踪(Jaeger):`http://localhost:16686` ### 🔌 使用微信对话开放平台 @@ -301,6 +297,7 @@ git clone https://github.com/Tencent/WeKnora > 推荐直接参考 [MCP配置说明](./mcp-server/MCP_CONFIG.md) 进行配置。 mcp客户端配置服务器 + ```json { "mcpServers": { @@ -319,6 +316,7 @@ mcp客户端配置服务器 ``` 使用stdio命令直接运行 + ``` pip install weknora-mcp-server python -m weknora-mcp-server @@ -349,7 +347,7 @@ make clean-db ### ④ 访问Web UI -http://localhost +[http://localhost](http://localhost) 首次访问会自动跳转到注册登录页面,完成注册后,请创建一个新的知识库,并在该知识库的设置页面完成相关设置。 @@ -357,15 +355,12 @@ http://localhost ### Web UI 界面 - - - - - - - - -
知识库管理
知识库管理
对话设置
对话设置
Agent模式工具调用过程
Agent模式工具调用过程
+ +| | | +| ----------------- | -------- | +| **知识库管理** | **对话设置** | +| **Agent模式工具调用过程** | | + **知识库管理:** 支持创建FAQ和文档两种类型知识库,支持拖拽上传、文件夹导入、URL导入等多种方式,自动识别文档结构并提取核心知识,建立索引。支持标签管理和在线录入,系统清晰展示处理进度和文档状态,实现高效的知识库管理。 @@ -413,6 +408,7 @@ make dev-frontend # 启动前端(新终端) ``` **开发优势:** + - ✅ 前端修改自动热重载(无需重启) - ✅ 后端修改快速重启(5-10秒,支持 Air 热重载) - ✅ 无需重新构建 Docker 镜像 @@ -480,7 +476,7 @@ refactor: 重构文档解析模块 感谢以下优秀的贡献者们: -[![Contributors](https://contrib.rocks/image?repo=Tencent/WeKnora)](https://github.com/Tencent/WeKnora/graphs/contributors) +[Contributors](https://github.com/Tencent/WeKnora/graphs/contributors) ## 📄 许可证 @@ -489,10 +485,3 @@ refactor: 重构文档解析模块 ## 📈 项目统计 - - - - - Star History Chart - - diff --git a/README_JA.md b/README_JA.md index da5c8977..a906c4a0 100644 --- a/README_JA.md +++ b/README_JA.md @@ -22,7 +22,7 @@ License - バージョン + バージョン

@@ -50,6 +50,17 @@ ## ✨ 最新アップデート +**v0.3.5 バージョンのハイライト:** + +- **Telegram、DingTalk & Mattermost IM統合**:Telegramボット(webhook/ロングポーリング、editMessageTextストリーミング)、DingTalkボット(webhook/Streamモード、AIカードストリーミング)、Mattermost アダプターを新規追加。IMチャネルはWeChat Work、Feishu、Slack、Telegram、DingTalk、Mattermost の6プラットフォームをカバー +- **IMスラッシュコマンドとQAキュー**:プラグイン式スラッシュコマンドフレームワーク(/help、/info、/search、/stop、/clear)、有界QAワーカープール、ユーザー単位レート制限、RedisベースのマルチインスタンスDistributed Coordination +- **推奨質問**:Agentが関連ナレッジベースに基づいてコンテキスト対応の推奨質問を自動生成し、チャットインターフェースに表示。画像ナレッジは質問生成タスクを自動キュー登録 +- **VLMによるMCPツール画像自動説明**:MCPツールが画像を返した場合、設定されたVLMモデルを使用してテキスト説明を自動生成し、テキストのみのLLMでも画像内容を利用可能に +- **Novita AIプロバイダー**:OpenAI互換APIでchat、embedding、VLLMモデルタイプをサポートする新しいLLMプロバイダー +- **MCPツール名の安定性**:ツール名をUUIDではなくservice.Nameから生成(再接続後も安定)。衝突防止制約を追加。フロントエンドでsnake_caseを人間が読みやすい形式に整形 +- **チャネルトラッキング**:ナレッジエントリとメッセージにchannelフィールド追加(web/api/im/browser_extension) +- **重要バグ修正**:ナレッジベース未設定時のAgent空レスポンス、中国語/絵文字ドキュメントのUTF-8切り詰め、テナント設定更新時のAPIキー暗号化消失、vLLMストリーミング推論コンテンツ欠落、Rerankの空パッセージエラーを修正 + **v0.3.4 バージョンのハイライト:** - **IMボット統合**:企業WeChat、Feishu、SlackのIMチャネルをサポート、WebSocket/Webhookモード、ストリーミング対応、ナレッジベース統合 @@ -60,25 +71,21 @@ - **AWS S3ストレージ**:AWS S3ストレージアダプターを統合、設定UIとデータベースマイグレーション - **AES-256-GCM暗号化**:APIキーをAES-256-GCMで静的暗号化、セキュリティ強化 - **組み込みMCPサービス**:組み込みMCPサービスサポートでAgent機能を拡張 -- **Agentストリーミングパネル**:AgentStreamDisplayコンポーネントの最適化、自動スクロール、スタイル改善、読み込みインジケーター - **ハイブリッド検索最適化**:ターゲットのグループ化とクエリ埋め込みの再利用で検索性能を向上 - **Final Answerツール**:新しいfinal_answerツールとAgentの所要時間追跡でワークフローを改善 -**v0.3.3 バージョンのハイライト:** - -- 🧩 **親子チャンキング**:階層型の親子チャンキング戦略により、コンテキスト管理と検索精度を強化 -- 📌 **ナレッジベースのピン留め**:よく使うナレッジベースをピン留めして素早くアクセス -- 🔄 **フォールバックレスポンス**:関連する結果がない場合のフォールバックレスポンス処理とUIインジケーター -- 🖼️ **画像アイコン検出**:ドキュメント処理における画像アイコンの自動検出とフィルタリング -- 🧹 **Rerankパッセージクリーニング**:Rerankモデルのパッセージクリーニング機能で関連性スコアの精度を向上 -- 🐳 **Docker・スキル管理**:エントリポイントスクリプトとスキル管理によるDocker環境の強化 -- 🗄️ **バケット自動作成**:ストレージエンジン接続チェックの強化、バケットの自動作成をサポート -- 🎨 **UI一貫性**:ボーダースタイルの統一、テーマとコンポーネントスタイルの更新で視覚的一貫性を向上 -- ⚡ **チャンクサイズ最適化**:ナレッジベース処理のチャンクサイズ設定を更新 -
過去のリリース +**v0.3.3 バージョンのハイライト:** + +- **親子チャンキング**:階層型の親子チャンキング戦略により、コンテキスト管理と検索精度を強化 +- **ナレッジベースのピン留め**:よく使うナレッジベースをピン留めして素早くアクセス +- **フォールバックレスポンス**:関連する結果がない場合のフォールバックレスポンス処理とUIインジケーター +- **Rerankパッセージクリーニング**:Rerankモデルのパッセージクリーニング機能で関連性スコアの精度を向上 +- **バケット自動作成**:ストレージエンジン接続チェックの強化、バケットの自動作成をサポート +- **Milvusベクトルデータベース**:ナレッジ検索用にMilvusベクトルデータベースバックエンドを追加 + **v0.3.0 バージョンのハイライト:** - 🏢 **共有スペース**:共有スペース管理、メンバー招待、メンバー間でのナレッジベースとAgentの共有、テナント分離検索 @@ -148,24 +155,28 @@ WeKnoraは現代的なモジュラー設計を採用し、完全な文書理解 ## 🧩 機能モジュール能力 -| 機能モジュール | サポート状況 | 説明 | -|---------|-----------------------------------------------------|------| -| Agentモード | ✅ ReACT Agentモード | 組み込みツールでナレッジベースを検索、MCPツールとWeb検索を使用、クロスナレッジベース検索、複数回の反復とリフレクションをサポート | -| ナレッジベースタイプ | ✅ FAQ / ドキュメント | FAQとドキュメントの2種類のナレッジベースの作成をサポート、フォルダーインポート、URLインポート、タグ管理、オンライン入力機能 | -| 文書フォーマットサポート | ✅ PDF / Word / Txt / Markdown / 画像(OCR / Caption含む) | 様々な構造化・非構造化文書コンテンツの解析をサポート、図文混在と画像文字抽出をサポート | -| モデル管理 | ✅ 集中設定、組み込みモデル共有 | モデルの集中設定、ナレッジベース設定ページにモデル選択を追加、マルチテナント間での組み込みモデル共有をサポート | -| 埋め込みモデルサポート | ✅ ローカルモデル、BGE / GTE API等 | カスタムembeddingモデルをサポート、ローカルデプロイとクラウドベクトル生成インターフェースに対応 | -| ベクトルデータベース接続 | ✅ PostgreSQL(pgvector)、Elasticsearch | 主流のベクトルインデックスバックエンドをサポート、柔軟な切り替えと拡張が可能、異なる検索シナリオに適応 | -| 検索メカニズム | ✅ BM25 / Dense Retrieve / GraphRAG | 密・疎検索、ナレッジグラフ強化検索など複数の戦略をサポート、検索-再ランキング-生成プロセスを自由に組み合わせ可能 | -| 大規模モデル統合 | ✅ Qwen、DeepSeek等をサポート、思考/非思考モード切り替え | ローカル大規模モデル(Ollama起動など)に接続可能、または外部APIサービスを呼び出し、推論モードの柔軟な設定をサポート | -| 対話戦略 | ✅ Agentモデル、通常モードモデル、検索閾値、Prompt設定 | Agentモデル、通常モードに必要なモデル、検索閾値の設定をサポート、オンラインPrompt設定、マルチターン対話の動作を精密に制御 | -| Web検索 | ✅ 拡張可能な検索エンジン、DuckDuckGo / Google | 拡張可能なWeb検索エンジンをサポート、DuckDuckGo検索エンジンを組み込み | -| MCPツール | ✅ uvx、npx起動ツール、Stdio/HTTP Streamable/SSE | MCPを通じてAgent機能を拡張、uvx、npxの2種類のMCP起動ツールを組み込み、3種類の転送方式をサポート | -| Q&A能力 | ✅ コンテキスト認識、マルチターン対話、プロンプトテンプレート | 複雑な意味モデリング、指示制御、チェーンQ&Aをサポート、プロンプトとコンテキストウィンドウを設定可能 | -| エンドツーエンドテストサポート | ✅ 検索+生成プロセスの可視化と指標評価 | 一体化されたリンクテストツールを提供、リコール的中率、回答カバレッジ、BLEU / ROUGE等の主流指標の評価をサポート | -| デプロイメントモード | ✅ ローカルデプロイメント / Dockerイメージ | プライベート化、オフラインデプロイメント、柔軟な運用保守のニーズに対応、高速開発モードをサポート | -| ユーザーインターフェース | ✅ Web UI + RESTful API | インタラクティブインターフェースと標準APIインターフェースを提供、Agentモード/通常モードの切り替え、ツール呼び出しプロセスの表示をサポート | -| タスク管理 | ✅ MQ非同期タスク、データベース自動マイグレーション | MQによる非同期タスクの状態維持を導入、バージョンアップ時のデータベーステーブル構造とデータの自動マイグレーションをサポート | +| 機能モジュール | サポート状況 | 説明 | +|---------|------------|------| +| Agentモード | ✅ ReACT Agentモード | 組み込みツールでナレッジベースを検索、MCPツールとWeb検索を呼び出し、クロスナレッジベース検索と複数回の反復推論をサポート | +| ナレッジベースタイプ | ✅ FAQ / ドキュメント | FAQとドキュメントの2種類のナレッジベース、フォルダーインポート、URLインポート、タグ管理、オンライン入力、ナレッジ移動をサポート | +| 文書フォーマットサポート | ✅ PDF / Word / Txt / Markdown / HTML / 画像(OCR + Caption) | 構造化・非構造化文書の解析、OCRによる画像文字抽出、VLMによる画像キャプション生成 | +| IMチャネル統合 | ✅ WeChat Work / Feishu / Slack / Telegram / DingTalk / Mattermost | WebSocket・Webhookモード、ストリーミング返信、スラッシュコマンド(/help、/info、/search、/stop、/clear)、ユーザー単位レート制限、RedisベースのマルチインスタンスDistributed Coordination | +| モデル管理 | ✅ 集中設定、組み込みモデル共有 | モデルの集中設定、ナレッジベース単位のモデル選択、マルチテナント間での組み込みモデル共有 | +| 埋め込みモデルサポート | ✅ ローカルモデル(Ollama)、BGE / GTE / OpenAI互換API | カスタムembeddingモデル対応、ローカルデプロイとクラウドベクトル生成インターフェースに対応 | +| ベクトルデータベース接続 | ✅ PostgreSQL(pgvector)/ Elasticsearch / Milvus / Weaviate / Qdrant | 5種類のベクトルインデックスバックエンドを柔軟に切り替え可能 | +| オブジェクトストレージ | ✅ ローカル / MinIO / AWS S3 / 火山引擎TOS | プラグイン式ストレージアダプター、起動時にバケットを自動作成 | +| 検索メカニズム | ✅ BM25 / Dense Retrieve / GraphRAG | 密・疎検索、ナレッジグラフ強化検索、検索-再ランキング-生成を自由に組み合わせ | +| 大規模モデル統合 | ✅ Qwen / DeepSeek / MiniMax / NVIDIA / Novita AI / OpenAI互換 | ローカルモデル(Ollama)または外部APIサービスに接続、思考/非思考モード切り替え、vLLMストリーミング推論コンテンツ対応 | +| 対話戦略 | ✅ Agentモデル、通常モードモデル、検索閾値、Prompt設定 | オンラインPrompt編集、検索閾値チューニング、マルチターン対話の精密制御 | +| Web検索 | ✅ DuckDuckGo / Bing / Google(拡張可能) | プラグイン式検索エンジン、対話ごとにWeb検索を切り替え可能 | +| MCPツール | ✅ uvx / npx起動ツール、Stdio / HTTP Streamable / SSE | MCPでAgent機能を拡張、安定したツール名管理(衝突防止付き)、ツール返却画像のVLM自動説明 | +| 推奨質問 | ✅ ナレッジベース連動の質問推奨 | Agentがチャット前に推奨質問を提示、画像ナレッジが質問生成を自動トリガー | +| Q&A能力 | ✅ コンテキスト認識、マルチターン対話、プロンプトテンプレート | 複雑な意味モデリング、指示制御、チェーンQ&A、プロンプトとコンテキストウィンドウを設定可能 | +| セキュリティ | ✅ AES-256-GCM静的暗号化、SSRF防護 | APIキーの静的暗号化、リモートAPI呼び出しのSSRFセーフ検証、Agentスキルのサンドボックス実行 | +| エンドツーエンドテストサポート | ✅ 検索+生成プロセスの可視化と指標評価 | 一体化テストツール、リコール的中率・回答カバレッジ・BLEU/ROUGE等の指標評価 | +| デプロイメントモード | ✅ ローカル / Docker / Kubernetes(Helm) | プライベート化・オフラインデプロイ、ホットリロード高速開発モード、Kubernetes用Helm Chart | +| ユーザーインターフェース | ✅ Web UI + RESTful API | インタラクティブインターフェースと標準API、Agentモード/通常モード切り替え、ツール呼び出しプロセス表示 | +| タスク管理 | ✅ MQ非同期タスク、データベース自動マイグレーション | MQによる非同期タスク状態維持、バージョンアップ時のDB自動マイグレーション | ## 🚀 クイックスタート diff --git a/README_KO.md b/README_KO.md index 8c54326d..483429c4 100644 --- a/README_KO.md +++ b/README_KO.md @@ -22,7 +22,7 @@ License - 버전 + 버전

@@ -50,6 +50,17 @@ ## ✨ 최신 업데이트 +**v0.3.5 하이라이트:** + +- **Telegram, DingTalk & Mattermost IM 통합**: Telegram 봇(webhook/롱폴링, editMessageText 스트리밍), DingTalk 봇(webhook/Stream 모드, AI 카드 스트리밍), Mattermost 어댑터를 신규 추가. IM 채널이 기업WeChat, Feishu, Slack, Telegram, DingTalk, Mattermost 6개 플랫폼으로 확대 +- **IM 슬래시 커맨드 및 QA 큐**: 플러그인 방식 슬래시 커맨드 프레임워크(/help, /info, /search, /stop, /clear), 유계 QA 워커 풀, 사용자별 레이트 리밋, Redis 기반 멀티 인스턴스 분산 조정 +- **추천 질문**: Agent가 연결된 지식베이스를 기반으로 컨텍스트 맞춤 추천 질문을 자동 생성해 채팅 화면에 표시; 이미지 지식은 질문 생성 작업을 자동 큐 등록 +- **VLM을 통한 MCP 도구 이미지 자동 설명**: MCP 도구가 이미지를 반환하면 설정된 VLM 모델로 텍스트 설명을 자동 생성해 텍스트 전용 LLM에서도 이미지 내용 활용 가능 +- **Novita AI 프로바이더**: OpenAI 호환 API로 chat, embedding, VLLM 모델 타입을 지원하는 신규 LLM 프로바이더 +- **MCP 도구명 안정성**: UUID 대신 service.Name 기반 도구명(재연결 후에도 안정), 고유명 제약 및 충돌 방지 추가; 프론트엔드에서 snake_case를 사람이 읽기 쉬운 형태로 변환 +- **채널 추적**: 지식 항목과 메시지에 channel 필드 추가(web/api/im/browser_extension)로 출처 추적 가능 +- **주요 버그 수정**: 지식베이스 미설정 시 Agent 빈 응답, 한국어/이모지 문서 요약의 UTF-8 잘림, 테넌트 설정 업데이트 시 API 키 암호화 손실, vLLM 스트리밍 추론 콘텐츠 누락, Rerank 빈 패시지 오류 수정 + **v0.3.4 하이라이트:** - **IM 봇 통합**: 기업WeChat, Feishu, Slack IM 채널 지원, WebSocket/Webhook 모드, 스트리밍 및 지식베이스 통합 @@ -60,25 +71,21 @@ - **AWS S3 스토리지**: AWS S3 스토리지 어댑터 통합, 설정 UI 및 데이터베이스 마이그레이션 - **AES-256-GCM 암호화**: API 키를 AES-256-GCM으로 정적 암호화하여 보안 강화 - **내장 MCP 서비스**: 내장 MCP 서비스 지원으로 Agent 기능 확장 -- **Agent 스트리밍 패널**: AgentStreamDisplay 컴포넌트 최적화, 자동 스크롤, 스타일 개선 및 로딩 인디케이터 - **하이브리드 검색 최적화**: 타겟 그룹화 및 쿼리 임베딩 재사용으로 검색 성능 향상 - **Final Answer 도구**: 새로운 final_answer 도구 및 Agent 소요 시간 추적으로 워크플로우 개선 -**v0.3.3 하이라이트:** - -- 🧩 **부모-자식 청킹**: 계층적 부모-자식 청킹 전략으로 컨텍스트 관리 및 검색 정확도 강화 -- 📌 **지식베이스 고정**: 자주 사용하는 지식베이스를 고정하여 빠른 접근 지원 -- 🔄 **폴백 응답**: 관련 결과가 없을 때 폴백 응답 처리 및 UI 표시기 -- 🖼️ **이미지 아이콘 감지**: 문서 처리 시 이미지 아이콘 자동 감지 및 필터링 -- 🧹 **Rerank 패시지 클리닝**: Rerank 모델의 패시지 클리닝 기능으로 관련성 점수 정확도 향상 -- 🐳 **Docker 및 스킬 관리**: 엔트리포인트 스크립트와 스킬 관리로 Docker 설정 강화 -- 🗄️ **버킷 자동 생성**: 스토리지 엔진 연결 확인 강화, 버킷 자동 생성 지원 -- 🎨 **UI 일관성**: 테두리 스타일 통일, 테마 및 컴포넌트 스타일 업데이트로 시각적 일관성 향상 -- ⚡ **청크 크기 최적화**: 지식베이스 처리를 위한 청크 크기 구성 업데이트 -
이전 릴리스 +**v0.3.3 하이라이트:** + +- **부모-자식 청킹**: 계층적 부모-자식 청킹 전략으로 컨텍스트 관리 및 검색 정확도 강화 +- **지식베이스 고정**: 자주 사용하는 지식베이스를 고정하여 빠른 접근 지원 +- **폴백 응답**: 관련 결과가 없을 때 폴백 응답 처리 및 UI 표시기 +- **Rerank 패시지 클리닝**: Rerank 모델의 패시지 클리닝 기능으로 관련성 점수 정확도 향상 +- **버킷 자동 생성**: 스토리지 엔진 연결 확인 강화, 버킷 자동 생성 지원 +- **Milvus 벡터 데이터베이스**: 지식 검색을 위한 Milvus 벡터 데이터베이스 백엔드 추가 + **v0.3.0 하이라이트:** - 🏢 **공유 공간**: 멤버 초대, 멤버 간 지식베이스/에이전트 공유, 테넌트 격리 검색을 지원하는 공유 공간 @@ -143,23 +150,27 @@ WeKnora는 완전한 문서 이해 및 검색 파이프라인을 구축하기 ## 🧩 기능 매트릭스 | 모듈 | 지원 범위 | 설명 | -|---------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Agent 모드 | ✅ ReACT Agent Mode | 내장 도구/지식베이스 검색, MCP 도구, 웹 검색 지원. 교차 지식베이스 검색 및 다중 반복 지원 | -| 지식베이스 타입 | ✅ FAQ / Document | FAQ/문서 지식베이스 생성 지원. 폴더 임포트, URL 임포트, 태그 관리, 온라인 입력 지원 | -| 문서 포맷 | ✅ PDF / Word / Txt / Markdown / Images (OCR / Caption 포함) | 구조화/비구조화 문서 처리 및 이미지 텍스트 추출 지원 | -| 모델 관리 | ✅ 중앙 설정, 내장 모델 공유 | 지식베이스 설정에서 모델 선택을 포함한 중앙 모델 관리 및 멀티테넌트 내장 모델 공유 지원 | -| 임베딩 모델 | ✅ 로컬 모델, BGE / GTE API 등 | 커스터마이징 가능한 임베딩 모델. 로컬 배포 및 클라우드 벡터 생성 API와 호환 | -| 벡터 DB 연동 | ✅ PostgreSQL (pgvector), Elasticsearch | 주요 벡터 인덱스 백엔드 지원, 검색 시나리오별 유연한 전환 | -| 검색 전략 | ✅ BM25 / Dense Retrieval / GraphRAG | 희소/밀집 검색 및 지식 그래프 강화 검색 지원. 검색-리랭크-생성 파이프라인 커스터마이징 가능 | -| LLM 연동 | ✅ Qwen, DeepSeek 등 지원, 사고/비사고 모드 전환 | 로컬 모델(예: Ollama) 또는 외부 API 서비스와 연동 가능한 유연한 추론 설정 | -| 대화 전략 | ✅ Agent 모델, 일반 모드 모델, 검색 임계값, 프롬프트 설정 | Agent/일반 모델, 검색 임계값, 온라인 프롬프트 설정 지원. 멀티턴 대화 동작 정밀 제어 | -| 웹 검색 | ✅ 확장 가능한 검색 엔진, DuckDuckGo / Google | 확장 가능한 웹 검색 엔진 지원, DuckDuckGo 기본 제공 | -| MCP 도구 | ✅ uvx, npx 런처, Stdio/HTTP Streamable/SSE | MCP를 통한 Agent 기능 확장. uvx/npx 런처 내장, 세 가지 전송 방식 지원 | -| QA 역량 | ✅ 문맥 인식, 멀티턴 대화, 프롬프트 템플릿 | 복잡한 시맨틱 모델링, 지시 제어, 체인형 Q&A 지원. 프롬프트/컨텍스트 윈도우 설정 가능 | -| E2E 테스트 | ✅ 검색+생성 과정 시각화 및 지표 평가 | 리콜 적중률, 답변 커버리지, BLEU/ROUGE 등 지표를 평가하는 종단간 테스트 도구 제공 | -| 배포 모드 | ✅ 로컬 배포 / Docker 이미지 | 프라이빗/오프라인 배포 및 유연한 운영 요구 충족. 고속 개발 모드 지원 | -| 사용자 인터페이스 | ✅ Web UI + RESTful API | 상호작용 UI와 표준 API 제공. Agent/일반 모드 전환 및 도구 호출 과정 표시 | -| 작업 관리 | ✅ MQ 비동기 작업, 자동 DB 마이그레이션 | MQ 기반 비동기 작업 상태 유지 및 버전 업그레이드 시 스키마/데이터 자동 마이그레이션 지원 | +|---------|---------|------| +| Agent 모드 | ✅ ReACT Agent Mode | 내장 도구로 지식베이스 검색, MCP 도구 및 웹 검색 호출; 교차 지식베이스 검색 및 다중 반복 추론 | +| 지식베이스 타입 | ✅ FAQ / Document | FAQ/문서 지식베이스, 폴더 임포트, URL 임포트, 태그 관리, 온라인 입력, 지식 이동 지원 | +| 문서 포맷 | ✅ PDF / Word / Txt / Markdown / HTML / 이미지 (OCR + Caption) | 구조화/비구조화 문서 파싱; OCR 이미지 텍스트 추출; VLM 이미지 캡션 생성 | +| IM 채널 통합 | ✅ WeChat Work / Feishu / Slack / Telegram / DingTalk / Mattermost | WebSocket·Webhook 모드, 스트리밍 답변, 슬래시 커맨드(/help, /info, /search, /stop, /clear), 사용자별 레이트 리밋, Redis 기반 멀티 인스턴스 분산 조정 | +| 모델 관리 | ✅ 중앙 설정, 내장 모델 공유 | 지식베이스별 모델 선택 포함 중앙 모델 관리; 멀티테넌트 내장 모델 공유 | +| 임베딩 모델 | ✅ 로컬 모델(Ollama), BGE / GTE / OpenAI 호환 API | 커스텀 임베딩 모델, 로컬 배포 및 클라우드 벡터 생성 API 호환 | +| 벡터 DB 연동 | ✅ PostgreSQL (pgvector) / Elasticsearch / Milvus / Weaviate / Qdrant | 5종 벡터 인덱스 백엔드, 검색 시나리오별 유연한 전환 | +| 오브젝트 스토리지 | ✅ 로컬 / MinIO / AWS S3 / Volcengine TOS | 플러그인 방식 스토리지 어댑터; 시작 시 버킷 자동 생성 | +| 검색 전략 | ✅ BM25 / Dense Retrieval / GraphRAG | 희소/밀집 검색, 지식 그래프 강화 검색; 검색-리랭크-생성 파이프라인 조합 가능 | +| LLM 연동 | ✅ Qwen / DeepSeek / MiniMax / NVIDIA / Novita AI / OpenAI 호환 | 로컬 모델(Ollama) 또는 외부 API, 사고/비사고 모드 전환, vLLM 스트리밍 추론 콘텐츠 지원 | +| 대화 전략 | ✅ Agent 모델, 일반 모드 모델, 검색 임계값, 프롬프트 설정 | 온라인 프롬프트 편집, 검색 임계값 조정, 멀티턴 대화 동작 정밀 제어 | +| 웹 검색 | ✅ DuckDuckGo / Bing / Google (확장 가능) | 플러그인 방식 검색 엔진; 대화별 웹 검색 켜기/끄기 | +| MCP 도구 | ✅ uvx / npx 런처, Stdio / HTTP Streamable / SSE | MCP로 Agent 기능 확장; 안정적인 도구명 관리(충돌 방지); 도구 반환 이미지 VLM 자동 설명 | +| 추천 질문 | ✅ 지식베이스 기반 질문 추천 | Agent가 채팅 전 추천 질문 표시; 이미지 지식이 질문 생성 자동 트리거 | +| QA 역량 | ✅ 문맥 인식, 멀티턴 대화, 프롬프트 템플릿 | 복잡한 시맨틱 모델링, 지시 제어, 체인형 Q&A; 프롬프트/컨텍스트 윈도우 설정 | +| 보안 | ✅ AES-256-GCM 정적 암호화, SSRF 방어 | API 키 정적 암호화; 원격 API 호출 SSRF 안전 검증; Agent 스킬 샌드박스 실행 | +| E2E 테스트 | ✅ 검색+생성 과정 시각화 및 지표 평가 | 리콜 적중률, 답변 커버리지, BLEU/ROUGE 지표 평가 종단간 테스트 도구 | +| 배포 모드 | ✅ 로컬 / Docker / Kubernetes (Helm) | 프라이빗/오프라인 배포; 핫 리로드 고속 개발 모드; Kubernetes용 Helm Chart | +| 사용자 인터페이스 | ✅ Web UI + RESTful API | 상호작용 UI와 표준 API; Agent/일반 모드 전환; 도구 호출 과정 표시 | +| 작업 관리 | ✅ MQ 비동기 작업, 자동 DB 마이그레이션 | MQ 기반 비동기 작업 상태 유지; 버전 업그레이드 시 스키마/데이터 자동 마이그레이션 | ## 🚀 시작하기 diff --git a/VERSION b/VERSION index 42045aca..c2c0004f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.4 +0.3.5 diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index 4fd28689..fadc2757 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -25,14 +25,17 @@ templates: ### Workflow 1. **Analyze:** Understand the user's request. 2. **Plan:** If the task is complex, use todo_write to create a plan. - 3. **Execute:** Use available tools to gather information or perform actions. + 3. **Execute:** Use available tools (including any connected MCP tools) to gather information or perform actions. + After receiving tool results, analyze them and incorporate the findings into your answer. 4. **Synthesize:** Call the final_answer tool with your comprehensive answer. You MUST always end by calling final_answer. ### Tool Guidelines + * **MCP Tools:** If external MCP tools are available, use them to fulfill the user's request. Analyze and incorporate their results into your final answer. * **web_search / web_fetch:** Use these if enabled to find information from the internet. * **todo_write:** Use for managing multi-step tasks. * **thinking:** Use to plan and reflect. * **final_answer:** MANDATORY as your final action. Always submit your complete answer through this tool. NEVER end your turn without calling it. + If you cannot fully answer, explain what you tried and why. If the question is outside your capabilities, say so politely. ### User-Friendly Communication In ALL outputs visible to users (including your thinking/reasoning), you MUST: diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 21bf1369..84cb6712 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -186,6 +186,19 @@ services: - jaeger - full + dex: + image: dexidp/dex:latest + container_name: WeKnora-dex-dev + ports: + - "5556:5556" + volumes: + - ./misc/dex-config.yaml:/etc/dex/config.yaml + command: ["dex", "serve", "/etc/dex/config.yaml"] + profiles: + - dex + - full + + networks: WeKnora-network-dev: driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml index 3d3f65f1..00a859f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -340,6 +340,18 @@ services: profiles: - weaviate + dex: + image: dexidp/dex:latest + container_name: dex + ports: + - "5556:5556" + volumes: + - ./misc/dex-config.yaml:/etc/dex/config.yaml + command: ["dex", "serve", "/etc/dex/config.yaml"] + profiles: + - dex + - full + networks: WeKnora-network: driver: bridge diff --git a/docs/IM集成开发文档.md b/docs/IM集成开发文档.md index 7d907f9e..1632e8ca 100644 --- a/docs/IM集成开发文档.md +++ b/docs/IM集成开发文档.md @@ -1,6 +1,6 @@ # IM 集成开发文档 -WeKnora 的 IM 集成模块将企业即时通讯平台(企业微信、飞书、Slack、Telegram、钉钉)接入 WeKnora 知识问答管道,支持在 IM 中直接向 AI 提问并获得实时流式回答。 +WeKnora 的 IM 集成模块将企业即时通讯平台(企业微信、飞书、Slack、Telegram、钉钉、Mattermost)接入 WeKnora 知识问答管道,支持在 IM 中直接向 AI 提问并获得实时流式回答。 IM 渠道绑定到 Agent,一个 Agent 可接入多个 IM 渠道,所有配置通过前端 Agent 编辑器管理,存储在数据库中。 @@ -12,6 +12,7 @@ IM 渠道绑定到 Agent,一个 Agent 可接入多个 IM 渠道,所有配置 - [Slack 接入](#slack-接入) - [Telegram 接入](#telegram-接入) - [钉钉接入](#钉钉接入) + - [Mattermost 接入](#mattermost-接入) - [前端管理](#前端管理) - [架构总览](#架构总览) - [数据模型](#数据模型) @@ -25,6 +26,7 @@ IM 渠道绑定到 Agent,一个 Agent 可接入多个 IM 渠道,所有配置 - [Slack](#slack) - [Telegram](#telegram) - [钉钉 (DingTalk)](#钉钉-dingtalk) + - [Mattermost](#mattermost) - [斜杠指令系统](#斜杠指令系统) - [QA 队列与限流](#qa-队列与限流) - [流式输出机制](#流式输出机制) @@ -466,6 +468,49 @@ curl -X POST "https://api.telegram.org/bot/setWebhook" \ 2. **消息接收地址**:粘贴从 WeKnora 复制的回调地址 3. 钉钉会通过 HmacSHA256 签名验证回调请求 +--- + +### Mattermost 接入 + +Mattermost 为**自建部署**,当前仅支持 **Webhook** 模式:**出站 Webhook(Outgoing Webhook)** 将用户消息 POST 到 WeKnora,Bot 通过 **REST API v4** 发回频道/线程回复。与 Slack Events API 类似,回调需快速返回 `200`,实际回答由 Bot Token 异步调用接口完成。 + +> 需要公网或内网可达的回调 URL(Mattermost 服务器能访问 WeKnora 的 `/api/v1/im/callback/{channel_id}`)。若 WeKnora 在内网,请在 Mattermost 中配置 [Trusted Internal Connections](https://docs.mattermost.com/configure/environment-configuration-settings.html) 或将回调地址加入允许列表。 + +#### 第一步:创建 Bot 账户并获取 Token + +1. 在 Mattermost 中创建专用 Bot 账户(或使用个人账户的 **Personal Access Token**,不推荐生产环境)。 +2. 为 Bot 授予在目标频道/团队发消息、读取文件等所需权限(若需将用户上传的文件写入知识库,需能下载附件)。 +3. 在 **Profile → Security → Personal Access Tokens**(或 Bot 设置)生成 Token,复制保存为 **Bot Token**。 + +#### 第二步:创建 Outgoing Webhook + +1. 打开 **产品菜单 → 集成 → 出站 Webhook**(若不可见,需系统管理员在 **系统控制台 → 集成** 中启用出站 Webhook)。 +2. 点击 **Add Outgoing Webhook**,填写标题与描述。 +3. **Content Type** 建议选择 **application/json**(也支持 `application/x-www-form-urlencoded`,WeKnora 两种均可解析)。 +4. 选择触发频道,或配置**触发词**(与频道组合规则以 Mattermost 说明为准)。 +5. **Callback URLs** 先留空或填占位;保存后在 WeKnora 创建渠道后会得到正式地址。 +6. 保存后复制页面上的 **Token**(出站 Webhook 密钥),即 **Outgoing Webhook Token**。 + +#### 第三步:在 WeKnora 中添加 IM 渠道 + +1. 进入 Agent 编辑器 → **IM 集成** → **添加渠道**。 +2. 填写配置: + - **平台**:选择「Mattermost」 + - **接入模式**:固定为 **Webhook**(选择 Mattermost 后界面会禁用 WebSocket) + - **输出模式**:流式输出 / 完整输出(流式通过编辑帖子实现) + - **Site URL**:Mattermost 站点根地址,如 `https://mattermost.example.com`(无尾部 `/`) + - **Bot Token**:上一步生成的 Token + - **Outgoing Webhook Token**:出站 Webhook 页面复制的 Token(用于校验回调,且参与 `bot_identity` 去重) + - **Bot User ID**(可选):Bot 在 Mattermost 中的用户 ID;填写后可忽略 Bot 自身触发的回调,避免自回复循环 +3. 保存后,复制渠道卡片上的 **回调地址**,回到 Mattermost 出站 Webhook 配置,将 **Callback URLs** 设为该地址并保存。 + +#### 第四步:验证 + +在绑定频道发送触发出站 Webhook 的消息,应收到 WeKnora 的回复;回复默认出现在**触发帖所在线程**(使用 Mattermost 的 `root_id` 与触发 `post_id` 对齐)。 + +**参考文档:** [Outgoing webhooks](https://developers.mattermost.com/integrate/webhooks/outgoing/) + + --- ## 前端管理 @@ -475,7 +520,7 @@ IM 渠道在 Agent 编辑器的 **IM 集成** 标签页中管理(仅编辑模 ### 渠道列表 每个渠道以卡片形式展示,包含: -- **平台标识**:企业微信(绿色)/ 飞书(蓝色)/ Slack(紫色)/ Telegram(蓝色)/ 钉钉(蓝色) +- **平台标识**:企业微信(绿色)/ 飞书(蓝色)/ Slack(紫色)/ Telegram(蓝色)/ 钉钉(蓝色)/ Mattermost(蓝色) - **渠道名称**:用户自定义 - **接入模式**:WebSocket / Webhook - **输出模式**:流式输出 / 完整输出 @@ -511,6 +556,17 @@ IM 渠道在 Agent 编辑器的 **IM 集成** 标签页中管理(仅编辑模 │ │ │ │ │ │ │ │ ─────┼─────────────┼─────────────┼──────────────┼─────────────┼──────── │ │ └─────────────┼─────────────┼──────────────┘─────────────┘ │ +│ │ │ +│ ┌────┴────────────┐ │ +│ │ Mattermost │ Webhook-only │ +│ └────────┬────────┘ │ +│ ▼ │ +│ ┌────────────────┐ │ +│ │ Mattermost │ │ +│ │ Adapter │ │ +│ └────────┬────────┘ │ +│ │ │ +│ ──────────────────┴────────────────────────────────────────────────────│ │ ▼ │ │ ┌──────────────────────────────────┐ │ │ │ im.Service │ 服务编排层 │ @@ -559,7 +615,7 @@ CREATE TABLE im_channels ( id VARCHAR(36) PRIMARY KEY, tenant_id BIGINT NOT NULL, agent_id VARCHAR(36) NOT NULL, -- 绑定的 Agent ID - platform VARCHAR(20) NOT NULL, -- 'wecom' | 'feishu' | 'slack' | 'telegram' | 'dingtalk' + platform VARCHAR(20) NOT NULL, -- 'wecom' | 'feishu' | 'slack' | 'telegram' | 'dingtalk' | 'mattermost' name VARCHAR(255) NOT NULL DEFAULT '', enabled BOOLEAN NOT NULL DEFAULT true, mode VARCHAR(20) NOT NULL DEFAULT 'websocket', -- 'webhook' | 'websocket' @@ -587,6 +643,9 @@ CREATE TABLE im_channels ( | Telegram | Webhook | `bot_token`, `secret_token`(可选) | | 钉钉 | WebSocket | `client_id`, `client_secret`, `card_template_id`(可选) | | 钉钉 | Webhook | `client_id`, `client_secret`, `card_template_id`(可选) | +| Mattermost | Webhook(唯一支持) | `site_url`, `bot_token`, `outgoing_token`(必填);`bot_user_id`(可选,过滤机器人自身消息) | + +`mattermost` 渠道的 `mode` 在数据库中固定为 `webhook`(创建时若未指定,服务端与模型钩子会默认 `webhook`)。`bot_identity` 形如 `mattermost:wh:{outgoing_token}`,用于防止同一出站 Webhook 重复绑定多个渠道。 ### im_channel_sessions 表 @@ -626,7 +685,7 @@ CREATE TABLE im_channels ( ### IMChannel — IM 渠道 -每个 IM 渠道代表一个 IM 平台机器人与 WeKnora Agent 的绑定关系。一个 Agent 可以绑定多个渠道(如同时接入企业微信、飞书和 Slack),同一平台也可以创建多个渠道(如不同的企业微信机器人)。 +每个 IM 渠道代表一个 IM 平台机器人与 WeKnora Agent 的绑定关系。一个 Agent 可以绑定多个渠道(如同时接入企业微信、飞书、Slack 与 Mattermost),同一平台也可以创建多个渠道(如不同的企业微信机器人)。 渠道有一个计算字段 `BotIdentity`,由平台类型、模式和核心凭证推导,用于防止同一机器人被重复创建。 @@ -638,7 +697,7 @@ CREATE TABLE im_channels ( ```go type IncomingMessage struct { - Platform Platform // "wecom" | "feishu" | "slack" | "telegram" | "dingtalk" + Platform Platform // "wecom" | "feishu" | "slack" | "telegram" | "dingtalk" | "mattermost" MessageType MessageType // "text" | "file" | "image" UserID string // 平台用户标识 UserName string // 显示名 (可选) @@ -1127,6 +1186,59 @@ EndStream: --- +### Mattermost + +仅支持 **Webhook** 模式:Mattermost **Outgoing Webhook** 将请求体 POST 到 WeKnora 统一回调地址;适配器实现 `Adapter`、`StreamSender`、`FileDownloader`(标准库 HTTP 调用 REST API,无第三方 SDK)。 + +#### Webhook 模式(Outgoing Webhook) + +``` +Mattermost 服务器 ──HTTP POST──▶ /api/v1/im/callback/{channel_id} + │ + 校验 body 中 token = outgoing_token + 解析 JSON 或 x-www-form-urlencoded + │ + 通过 REST API v4 回复(Bearer Bot Token) +``` + +- **安全校验:** 请求体中的 `token` 必须与渠道凭证中的 `outgoing_token` 一致(创建渠道时工厂会校验 `outgoing_token` 非空)。 +- **载荷格式:** 支持 `application/json` 与 `application/x-www-form-urlencoded`(与 [官方文档](https://developers.mattermost.com/integrate/webhooks/outgoing/) 一致)。 +- **机器人过滤:** 若配置了 `bot_user_id`,且 `user_id` 与之相同,则返回 `nil` 消息,避免自激。 +- **线程回复:** `IncomingMessage.Extra` 中保存 `thread_root_id`(有 `root_id` 时用其值,否则用触发帖 `post_id`);`SendReply` / `CreatePost` 时设置 `root_id`,使回复出现在同一线程。 +- **消息去重:** `MessageID` 使用触发帖的 `post_id`。 +- **文件消息:** 若载荷含 `file_ids`,取首个文件 ID 作为 `FileKey`;`DownloadFile` 先 `GET /api/v4/files/{id}/info` 再 `GET /api/v4/files/{id}` 下载内容。 + +#### 流式回复 + +与 Slack 类似,通过**编辑同一条帖子**展示累积全文: + +``` +StartStream: + 1. POST /api/v4/posts → 创建占位帖(如「正在思考...」),得到 post id + +SendStreamChunk: + 2. PUT /api/v4/posts/{post_id}/patch → Patch message 字段(累积全文) + +EndStream: + 3. 最后一次 Patch,与 SendStreamChunk 相同逻辑 +``` + +流式刷新间隔由 Service 侧 `streamFlushInterval`(300ms)批量合并,以降低编辑频率、减轻 API 压力。 + +#### URL 验证 + +Mattermost 出站 Webhook 无 Slack/Feishu 类 challenge 流程,`HandleURLVerification` 恒为 `false`。 + +#### 源码文件 + +| 文件 | 职责 | +|------|------| +| `internal/im/mattermost/adapter.go` | 出站 Webhook 解析、Token 校验、发帖/补丁流式、文件下载 | +| `internal/im/mattermost/client.go` | REST v4:`CreatePost`、`PatchPostMessage`、文件 info/下载 | +| `internal/im/mattermost/form_parse.go` | 表单编码 body 与 `file_ids` 辅助解析 | + +--- + ## 斜杠指令系统 IM 渠道支持斜杠指令(Slash Commands),用户在聊天中输入 `/指令名` 即可触发,无需经过 QA 管道,且不受限流约束。 @@ -1300,6 +1412,7 @@ QA 管道 ──chunk──chunk──chunk──▶ EventBus | 企业微信 Webhook | PicUrl 直接下载 或 MediaId 临时素材 API | | 企业微信 WebSocket | 加密附件 URL + per-message AES 密钥解密 | | Telegram | getFile API 获取文件路径 + HTTPS 下载(支持文档和图片) | +| Mattermost | `GET /api/v4/files/{file_id}/info` + `GET /api/v4/files/{file_id}`(Bearer Bot Token) | --- diff --git a/docs/OIDC认证调用流程.md b/docs/OIDC认证调用流程.md new file mode 100644 index 00000000..f26aaaa1 --- /dev/null +++ b/docs/OIDC认证调用流程.md @@ -0,0 +1,642 @@ +# WeKnora OIDC 认证调用流程 + +本文档说明 WeKnora 当前 OIDC 登录能力的实际调用过程,覆盖: + +- 前端如何判断是否展示 OIDC 登录入口 +- 用户点击 OIDC 登录后的前后端调用链路 +- 后端如何与 OIDC Provider 交互 +- 登录成功后前端如何接收结果并落盘本地登录态 +- 关键配置项与本地联调方式 + +本文内容基于当前项目实现,相关代码主要位于: + +- 后端路由:`internal/router/router.go` +- 认证处理:`internal/handler/auth.go` +- 认证服务:`internal/application/service/user.go` +- 配置定义:`internal/config/config.go` +- 前端登录页:`frontend/src/views/auth/Login.vue` +- 前端全局回调处理:`frontend/src/App.vue` +- 前端认证 API:`frontend/src/api/auth/index.ts` +- 本地 Dex 示例:`misc/dex-config.yaml` + +--- + +## 1. 整体设计说明 + +本项目的 OIDC 登录采用的是 **后端发起授权参数生成、后端接收回调并完成 code 换 token、前端通过 URL hash 接收最终登录结果** 的模式。 + +和常见的纯前端 OIDC SDK 不同,WeKnora 的特点是: + +1. **前端只负责发起跳转**,不直接和 OIDC Provider 交换 token。 +2. **后端负责用授权码 `code` 向 OIDC Provider 换取 token**。 +3. 后端拿到 OIDC 用户信息后,会: + - 查找本地用户; + - 若用户不存在,则自动创建本地账号和默认租户; + - 最终签发 WeKnora 自己的本地 JWT(`token` / `refresh_token`)。 +4. 后端不会直接把登录结果放在 query string 中,而是: + - 将结果 JSON 序列化后再做 base64url 编码; + - 以 `#oidc_result=...` 的形式重定向回前端; + - 前端在 `App.vue` 中统一解析 hash,完成登录态持久化。 + +因此,**OIDC Provider 的 token 只用于后端换取用户身份,本项目真正的业务访问凭证仍然是 WeKnora 自己签发的 JWT**。 + +--- + +## 2. 相关接口 + +当前 OIDC 相关接口均注册在 `internal/router/router.go` 中: + +- `GET /api/v1/auth/oidc/config` + - 获取 OIDC 是否启用,以及 Provider 展示名称 +- `GET /api/v1/auth/oidc/url` + - 生成第三方登录跳转地址 +- `GET /api/v1/auth/oidc/callback` + - OIDC Provider 回调地址 + +其中,前端常规登录仍然使用: + +- `POST /api/v1/auth/login` +- `POST /api/v1/auth/refresh` +- `POST /api/v1/auth/logout` +- `GET /api/v1/auth/me` + +--- + +## 3. 调用流程图 + +### 3.1 总体时序图 + +```mermaid +sequenceDiagram + autonumber + participant U as 用户浏览器 + participant FE as 前端(Login/App) + participant BE as WeKnora 后端 + participant OP as OIDC Provider + + FE->>BE: GET /api/v1/auth/oidc/config + BE-->>FE: { enabled, provider_display_name } + + U->>FE: 点击“OIDC 登录” + FE->>BE: GET /api/v1/auth/oidc/url?redirect_uri=... + BE-->>FE: { success, authorization_url, state } + FE->>OP: 浏览器跳转到 authorization_url + + OP-->>BE: GET /api/v1/auth/oidc/callback?code=...&state=... + BE->>OP: POST token endpoint (code 换 token) + OP-->>BE: access_token / id_token + BE->>OP: GET userinfo endpoint(可选) + OP-->>BE: 用户信息 claims + + BE->>BE: 查找/自动创建本地用户 + BE->>BE: 签发本地 token、refresh_token + BE-->>FE: 302 到 /#oidc_result=... + + FE->>FE: App.vue 解析 hash + FE->>FE: 写入 authStore/token/tenant + FE-->>U: 跳转 /platform/knowledge-bases +``` + +### 3.2 后端回调处理分支图 + +```mermaid +flowchart TD + A[OIDC Provider 回调到 /api/v1/auth/oidc/callback] --> B{query 中是否有 error} + B -- 是 --> C[拼接 #oidc_error 和 error_description] + C --> D[302 重定向到前端登录页] + + B -- 否 --> E[解析 state] + E --> F{state 是否合法且包含 redirect_uri} + F -- 否 --> G[302 到前端并带 #oidc_error=invalid_state] + + F -- 是 --> H{是否有 code} + H -- 否 --> I[302 到前端并带 #oidc_error=missing_code] + + H -- 是 --> J[调用 LoginWithOIDC,传入 code 和 redirect_uri] + J --> K[向 OIDC token endpoint 换 token] + K --> L[解析 id_token / 调用 userinfo] + L --> M{本地用户是否存在} + M -- 否 --> N[自动注册新用户并创建默认租户] + M -- 是 --> O[使用现有用户] + N --> P[签发 WeKnora JWT] + O --> P + P --> Q[编码为 oidc_result] + Q --> R[302 重定向到前端首页 hash] +``` + +--- + +## 4. 前端调用流程 + +## 4.1 登录页初始化:决定是否展示 OIDC 登录按钮 + +登录页组件位于 `frontend/src/views/auth/Login.vue`。 + +页面加载时会执行: + +```ts +loadOIDCConfig() +``` + +该函数调用: + +```ts +getOIDCConfig() -> GET /api/v1/auth/oidc/config +``` + +后端 `GetOIDCConfig` 会读取 `configInfo.OIDCAuth`: + +- `enabled`: 是否启用 OIDC +- `provider_display_name`: 登录按钮上展示的供应商名称 + +前端据此决定: + +- 是否显示 OIDC 登录按钮; +- 按钮文案是否显示为“使用 XXX 登录”。 + +--- + +## 4.2 用户点击 OIDC 登录按钮 + +用户点击按钮后,`Login.vue` 中会执行 `handleOIDCLogin()`。 + +核心逻辑: + +1. 前端先构造后端回调地址: + +```ts +const getBackendOIDCRedirectURI = () => `${window.location.origin}/api/v1/auth/oidc/callback` +``` + +其中: + +- `redirect_uri`:提供给 OIDC Provider 的回调地址,必须是后端地址。 + +登录成功后,后端固定回跳前端首页 `/`,并通过 hash 传递 OIDC 结果。 + +2. 前端调用: + +```ts +GET /api/v1/auth/oidc/url?redirect_uri=... +``` + +3. 后端返回 `authorization_url` 后,前端直接执行: + +```ts +window.location.href = authorizationURL +``` + +浏览器随后离开 WeKnora 页面,跳转到 OIDC Provider 的授权页。 + +--- + +## 5. 后端生成授权地址 + +对应处理器:`AuthHandler.GetOIDCAuthorizationURL` + +对应服务:`userService.GetOIDCAuthorizationURL` + +### 5.1 参数校验 + +后端要求以下参数必须存在: + +- `redirect_uri` + +否则直接返回校验错误。 + +### 5.2 读取 OIDC 配置 + +`getOIDCConfig()` 会执行以下逻辑: + +1. 检查 `OIDCAuth.Enable` 是否为 `true`; +2. 设置默认值: + - `ProviderDisplayName` 默认是 `OIDC` + - `Scopes` 默认是 `openid profile email` + - `UserInfoMapping.Username` 默认是 `name` + - `UserInfoMapping.Email` 默认是 `email` +3. 若未显式配置授权/令牌端点,则通过 `discovery_url` 拉取 OIDC Discovery 文档; +4. 自动补齐: + - `authorization_endpoint` + - `token_endpoint` + - `userinfo_endpoint` + +### 5.3 生成 state + +后端不会把 state 只当成随机串,而是编码了一个 JSON 结构: + +```json +{ + "nonce": "随机字符串", + "redirect_uri": "后端回调地址" +} +``` + +然后再做 base64url 编码,作为 `state` 传给 Provider。 + +这样在 OIDC Provider 回调时,后端就可以从 `state` 里还原: + +- 本次使用的后端 `redirect_uri` + +### 5.4 拼接授权地址 + +后端最终拼接的参数包含: + +- `response_type=code` +- `client_id` +- `redirect_uri` +- `scope` +- `state` + +然后返回给前端: + +```json +{ + "success": true, + "provider_display_name": "Dex", + "authorization_url": "...", + "state": "..." +} +``` + +--- + +## 6. OIDC Provider 回调到后端 + +OIDC Provider 完成认证后,会回调: + +```text +GET /api/v1/auth/oidc/callback +``` + +处理器为 `AuthHandler.OIDCRedirectCallback`。 + +### 6.1 Provider 返回错误时 + +如果 query 中带有: + +- `error` +- `error_description` + +后端不会返回 JSON,而是直接 302 到前端首页 `/`,并带上 hash: + +```text +#oidc_error=...&oidc_error_description=... +``` + +### 6.2 解析 state + +后端会把 `state` 做 base64url 解码并解析为结构体。 + +如果出现以下情况,将判定失败: + +- `state` 无法解码 +- JSON 结构非法 +- `state.redirect_uri` 为空 + +失败时会重定向到前端首页: + +```text +#oidc_error=invalid_state +``` + +### 6.3 校验 code + +如果没有收到 `code`,则重定向: + +```text +#oidc_error=missing_code +``` + +### 6.4 正式执行 OIDC 登录 + +若 `state` 与 `code` 都合法,则调用: + +```go +LoginWithOIDC(ctx, code, decodedState.RedirectURI) +``` + +注意这里传入的是 **state 中保存的 redirect_uri**,而不是重新拼接的地址,这样保证了 code 交换时使用的 `redirect_uri` 和授权时完全一致。 + +--- + +## 7. 后端用 code 换 token 并解析用户身份 + +核心逻辑位于 `internal/application/service/user.go`。 + +## 7.1 换取 OIDC token + +`exchangeOIDCCode()` 会向 OIDC Provider 的 `token_endpoint` 发起: + +```text +POST application/x-www-form-urlencoded +``` + +表单参数包括: + +- `grant_type=authorization_code` +- `code` +- `redirect_uri` +- `client_id` +- `client_secret` + +期望返回字段: + +- `access_token` +- `id_token` +- `token_type` + +如果 `access_token` 和 `id_token` 都缺失,则认为失败。 + +## 7.2 解析用户信息 + +`resolveOIDCUserInfo()` 的处理顺序是: + +1. 如果有 `id_token`,先本地解码 JWT payload,提取 claims; +2. 如果配置了 `userinfo_endpoint` 且有 `access_token`,再调用 userinfo 接口; +3. 将两部分 claims 合并,userinfo 的字段可覆盖前面已取到的字段; +4. 根据配置的 `user_info_mapping` 提取: + - 用户名字段 + - 邮箱字段 + +默认映射: + +- `username -> name` +- `email -> email` + +另外还有回退逻辑: + +1. 若 username 为空,尝试 `preferred_username` +2. 再尝试 `name` +3. 再尝试从邮箱前缀生成用户名 + +如果最终没有拿到邮箱,则直接报错,因为本地用户是按 email 关联的。 + +--- + +## 8. 本地用户关联与自动开通 + +### 8.1 通过邮箱查找用户 + +后端使用 OIDC 返回的邮箱执行: + +```go +userRepo.GetUserByEmail(ctx, userInfo.Email) +``` + +### 8.2 用户不存在时自动注册 + +若本地不存在该邮箱用户,则调用 `provisionOIDCUser()` 自动创建账号。 + +自动创建逻辑包括: + +1. 根据 OIDC 用户名/邮箱生成本地用户名; +2. 若用户名冲突,则自动追加 `-1`、`-2` 等后缀; +3. 生成随机密码; +4. 调用现有 `Register()` 流程创建用户; +5. `Register()` 内部还会自动创建默认租户。 + +因此,**首次使用 OIDC 登录的用户,不需要提前在 WeKnora 中手工建号**。 + +### 8.3 用户禁用处理 + +如果找到的本地用户 `IsActive=false`,则登录失败,回调给前端的错误信息为: + +```text +Account is disabled +``` + +--- + +## 9. 生成 WeKnora 本地登录态 + +OIDC 登录成功后,后端不会直接把 OIDC token 交给前端使用,而是继续执行: + +```go +GenerateTokens(ctx, user) +``` + +生成两类 JWT: + +- `token`:访问令牌,默认 24 小时 +- `refresh_token`:刷新令牌,默认 7 天 + +并写入本地 `auth_tokens` 存储(通过 `tokenRepo.CreateToken`)。 + +最终后端还会查询当前用户所属租户,并返回: + +- `user` +- `tenant` +- `token` +- `refresh_token` +- `is_new_user` + +这一步意味着: + +> OIDC 只负责“确认你是谁”,WeKnora 自己负责“签发系统内可用的业务令牌”。 + +--- + +## 10. 后端如何把结果传回前端 + +`OIDCRedirectCallback` 在拿到 `OIDCCallbackResponse` 后,会执行: + +1. 将响应对象 JSON 序列化; +2. 用 base64url 编码; +3. 302 重定向到: + +```text +/#oidc_result=ENCODED_PAYLOAD +``` + +失败时则返回: + +```text +/#oidc_error=...&oidc_error_description=... +``` + +这里使用 hash 的好处是: + +- 不会把结果作为 query 参数再次发送给服务端; +- 前端可以在浏览器本地直接读取并清理; +- 避免刷新时重复向后端暴露这些参数。 + +--- + +## 11. 前端如何消费 OIDC 回调结果 + +前端不是在 `Login.vue` 中处理回调,而是在 `frontend/src/App.vue` 中统一处理。 + +这样即使后端把用户重定向到 `/`,应用根组件也能接住这次 OIDC 登录结果。 + +## 11.1 App.vue 解析 hash + +应用挂载时执行: + +```ts +handleGlobalOIDCCallback() +``` + +它会读取: + +```ts +window.location.hash +``` + +并解析以下字段: + +- `oidc_error` +- `oidc_error_description` +- `oidc_result` + +## 11.2 错误分支 + +如果存在 `oidc_error`: + +1. 调用 `clearOIDCCallbackState('/login')` 清理 URL; +2. 跳转到 `/login`; +3. 弹出错误消息。 + +## 11.3 成功分支 + +如果存在 `oidc_result`: + +1. base64url 解码并反序列化; +2. 如果 `response.success=true`: + - 写入 `authStore.setUser(...)` + - 写入 `authStore.setToken(...)` + - 写入 `authStore.setRefreshToken(...)` + - 写入 `authStore.setTenant(...)` +3. 最终跳转到: + +```text +/platform/knowledge-bases +``` + +这与普通账号密码登录成功后的持久化逻辑保持一致。 + +--- + +## 12. 关键配置项 + +OIDC 配置定义位于 `internal/config/config.go`,环境变量示例见 `.env.example`。 + +### 12.1 主要配置项 + +| 配置项 | 说明 | +|---|---| +| `OIDC_AUTH_ENABLE` | 是否启用 OIDC 登录 | +| `OIDC_AUTH_ISSUER_URL` | Issuer 地址,可用于自动拼 discovery URL | +| `OIDC_AUTH_DISCOVERY_URL` | OIDC Discovery 地址 | +| `OIDC_AUTH_PROVIDER_DISPLAY_NAME` | 前端按钮显示名称 | +| `OIDC_AUTH_CLIENT_ID` | OIDC Client ID | +| `OIDC_AUTH_CLIENT_SECRET` | OIDC Client Secret | +| `OIDC_AUTH_AUTHORIZATION_ENDPOINT` | 授权端点,可选 | +| `OIDC_AUTH_TOKEN_ENDPOINT` | Token 端点,可选 | +| `OIDC_AUTH_USER_INFO_ENDPOINT` | UserInfo 端点,可选 | +| `OIDC_AUTH_SCOPES` | Scope 列表,默认 `openid profile email` | +| `OIDC_USER_INFO_MAPPING_USER_NAME` | claims 中映射到用户名的字段名 | +| `OIDC_USER_INFO_MAPPING_EMAIL` | claims 中映射到邮箱的字段名 | + +### 12.2 启用时的最小要求 + +当 `OIDC_AUTH_ENABLE=true` 时,后端校验要求: + +1. 必须有 `client_id` +2. 必须有 `client_secret` +3. 必须满足以下二选一: + - 配置 `discovery_url` + - 或同时配置 `authorization_endpoint + token_endpoint` + +--- + +## 13. 本地联调示例(Dex) +[Dex](https://dexidp.io/) 是一个简单易用的OIDC Provider,您可以通过它对接多种第三方认证系统(如OAuth2.0,Google,GitHub,LDAP等)。除了Dex之外,您也可以选择[KeyCloak](https://www.keycloak.org/)等其他符合OpenID Connect协议的Provider进行接入。 + +项目中已提供 Dex 示例配置:`misc/dex-config.yaml`。 + +其中静态客户端配置示例: + +```yaml +staticClients: + - id: weknora + redirectURIs: + - 'http://127.0.0.1:5173/api/v1/auth/oidc/callback' + - 'http://127.0.0.1/api/v1/auth/oidc/callback' + name: 'WeKnora' + # secret: +``` + +这说明本地调试时,需要确保 **Provider 注册的 redirect URI 与前端实际传给后端的 `redirect_uri` 完全一致**。 + +前端当前实现中使用的是: + +```ts +${window.location.origin}/api/v1/auth/oidc/callback +``` + +所以: + +- 若前端从 `http://127.0.0.1:5173` 访问,则 redirect URI 为 + `http://127.0.0.1:5173/api/v1/auth/oidc/callback` +- 若通过 Nginx 统一入口访问,则可能是 + `http://127.0.0.1/api/v1/auth/oidc/callback` + +Provider 必须提前把这些地址加入白名单。 + +--- + +## 14. 调用链路总结 + +可以把当前 OIDC 登录理解为以下 4 个阶段: + +### 阶段一:前端发现能力 + +前端调用 `/auth/oidc/config`,决定是否展示第三方登录入口。 + +### 阶段二:浏览器跳转授权 + +前端调用 `/auth/oidc/url` 获取授权地址,然后跳转到 OIDC Provider。 + +### 阶段三:后端完成身份兑换 + +Provider 回调后端 `/auth/oidc/callback`,后端用 `code` 换 token、拉取用户信息、关联或创建本地用户,并签发 WeKnora JWT。 + +### 阶段四:前端接收最终结果 + +后端 302 回前端,并通过 `#oidc_result` 传递登录结果;前端在 `App.vue` 中统一解析,写入本地登录态并进入业务页面。 + +--- + +## 15. 注意事项 + +1. **`redirect_uri` 必须严格匹配** Provider 客户端配置。 +2. **前端首页不是 OIDC Provider 回调地址**。 + - Provider 回调的是后端 `/api/v1/auth/oidc/callback` + - 后端再固定重定向到前端首页 `/` +3. **邮箱是本地账号关联主键**。 + - 若 Provider 没返回 email,将无法完成登录。 +4. **首次 OIDC 登录会自动创建用户和默认租户**。 +5. **真正用于访问 WeKnora API 的仍是本地 JWT**,不是 OIDC access token。 +6. 当前实现对 `state` 做了编码封装,但 **没有服务端持久化 state/nonce 校验**;它主要用于传递上下文和基本防错,而不是完整的防重放机制。 + +--- + +## 16. 相关源码定位 + +- 前端是否展示 OIDC 登录按钮: + - `frontend/src/views/auth/Login.vue` +- 前端获取授权地址: + - `frontend/src/api/auth/index.ts` + - `frontend/src/views/auth/Login.vue` +- 前端解析回调 hash: + - `frontend/src/App.vue` +- OIDC 接口路由注册: + - `internal/router/router.go` +- OIDC HTTP 处理: + - `internal/handler/auth.go` +- OIDC 业务逻辑: + - `internal/application/service/user.go` +- OIDC 配置结构与环境变量覆盖: + - `internal/config/config.go` +- Dex 本地示例: + - `misc/dex-config.yaml` diff --git a/docs/QA.md b/docs/QA.md index 0589b4c6..581629e1 100644 --- a/docs/QA.md +++ b/docs/QA.md @@ -142,6 +142,24 @@ environment: - 仅支持 **只读查询**,包括 `SELECT`, `SHOW`, `DESCRIBE`, `EXPLAIN`, `PRAGMA` 等语句。 - 禁止执行任何修改数据的操作,如 `INSERT`, `UPDATE`, `DELETE`, `CREATE`, `DROP` 等。 +## 7. 页面里刚保存的配置几秒后又消失了? + +这类问题通常不是配置真的被系统清掉了,而是浏览器代理、缓存或插件干扰导致前端读到了异常响应,页面随后又被旧状态覆盖。 + +建议按下面顺序排查: + +1. 先关闭浏览器代理、抓包工具、自动改写请求的插件,再重新打开页面。 +2. 确认浏览器没有把 `localhost` 或当前访问域名走代理;如果配置了 PAC,请将 `localhost`、`127.0.0.1` 和实际部署域名加入直连名单。 +3. 强制刷新页面,或直接使用无痕窗口重新登录后再保存一次配置。 +4. 打开浏览器开发者工具的 `Network` 面板,确认保存配置相关请求返回的是最新内容,且没有被代理改写、缓存命中或重定向到其他环境。 +5. 如果是调试模式部署,可尝试重启 `app` 服务后再验证一次: + +```bash +docker compose restart app +``` + +如果重启后短时间恢复正常,但再次访问又出现相同现象,仍应优先检查浏览器代理、缓存和多环境串连问题,而不是直接判断为后端配置丢失。 + ## P.S. 如果以上方式未解决问题,请在issue中描述您的问题,并提供必要的日志信息辅助我们进行问题排查 diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c0c5adba..7b782e78 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "knowledage-base", - "version": "0.1.3", + "version": "0.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "knowledage-base", - "version": "0.1.3", + "version": "0.3.4", "dependencies": { "@microsoft/fetch-event-source": "^2.0.1", "@types/dompurify": "^3.0.5", @@ -16,7 +16,7 @@ "docx-preview": "^0.3.7", "dompurify": "^3.2.6", "highlight.js": "^11.11.1", - "marked": "^5.1.2", + "marked": "^17.0.5", "mermaid": "^11.4.1", "pagefind": "^1.1.1", "papaparse": "^5.5.3", @@ -33,7 +33,6 @@ }, "devDependencies": { "@tsconfig/node22": "^22.0.1", - "@types/marked": "^5.0.2", "@types/node": "^22.14.0", "@vitejs/plugin-vue": "6.0.0", "@vitejs/plugin-vue-jsx": "5.0.1", @@ -1806,13 +1805,6 @@ "@types/lodash": "*" } }, - "node_modules/@types/marked": { - "version": "5.0.2", - "resolved": "https://mirrors.tencent.com/npm/@types/marked/-/marked-5.0.2.tgz", - "integrity": "sha512-OucS4KMHhFzhz27KxmWg7J+kIYqyqoW5kdIEI319hqARQQUTqhao3M/F+uFnDXD0Rg72iDDZxZNxq5gvctmLlg==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/node": { "version": "22.16.3", "resolved": "https://mirrors.tencent.com/npm/@types/node/-/node-22.16.3.tgz", @@ -3190,10 +3182,9 @@ } }, "node_modules/dompurify": { - "version": "3.2.6", - "resolved": "https://mirrors.tencent.com/npm/dompurify/-/dompurify-3.2.6.tgz", - "integrity": "sha512-/2GogDQlohXPZe6D6NOgQvXLPSYBqIWMnZ8zzOhn09REE4eyAzb+Hed3jhoM9OkuaJ8P6ZGTTVWQKAi8ieIzfQ==", - "license": "(MPL-2.0 OR Apache-2.0)", + "version": "3.3.3", + "resolved": "https://mirrors.tencent.com/npm/dompurify/-/dompurify-3.3.3.tgz", + "integrity": "sha512-Oj6pzI2+RqBfFG+qOaOLbFXLQ90ARpcGG6UePL82bJLtdsa6CYJD7nmiU8MW9nQNOtCHV3lZ/Bzq1X0QYbBZCA==", "optionalDependencies": { "@types/trusted-types": "^2.0.7" } @@ -3956,15 +3947,14 @@ } }, "node_modules/marked": { - "version": "5.1.2", - "resolved": "https://mirrors.tencent.com/npm/marked/-/marked-5.1.2.tgz", - "integrity": "sha512-ahRPGXJpjMjwSOlBoTMZAK7ATXkli5qCPxZ21TG44rx1KEo44bii4ekgTDQPNRQ4Kh7JMb9Ub1PVk1NxRSsorg==", - "license": "MIT", + "version": "17.0.5", + "resolved": "https://mirrors.tencent.com/npm/marked/-/marked-17.0.5.tgz", + "integrity": "sha512-6hLvc0/JEbRjRgzI6wnT2P1XuM1/RrrDEX0kPt0N7jGm1133g6X7DlxFasUIx+72aKAr904GTxhSLDrd5DIlZg==", "bin": { "marked": "bin/marked.js" }, "engines": { - "node": ">= 16" + "node": ">= 20" } }, "node_modules/math-intrinsics": { @@ -4260,9 +4250,9 @@ "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==" }, "node_modules/picomatch": { - "version": "4.0.3", - "resolved": "https://mirrors.tencent.com/npm/picomatch/-/picomatch-4.0.3.tgz", - "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "version": "4.0.4", + "resolved": "https://mirrors.tencent.com/npm/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "dev": true, "license": "MIT", "engines": { diff --git a/frontend/src/App.vue b/frontend/src/App.vue index fd517905..9421b1c9 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,7 +1,10 @@ + + + @@ -726,187 +701,60 @@ onMounted(() => { } } -/* Global Animated Background - Knowledge Graph */ .animated-bg { position: absolute; top: 0; left: 0; right: 0; bottom: 0; - width: 100%; - height: 100%; pointer-events: none; z-index: 1; overflow: hidden; + contain: strict; } -/* Knowledge Nodes */ .knowledge-node { position: absolute; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); - backdrop-filter: blur(4px); border: 2px solid rgba(255, 255, 255, 0.3); - box-shadow: - 0 0 15px rgba(255, 255, 255, 0.4), - 0 0 30px rgba(16, 185, 129, 0.3), - inset 0 0 15px rgba(255, 255, 255, 0.1); + box-shadow: + 0 0 15px rgba(255, 255, 255, 0.35), + 0 0 30px rgba(16, 185, 129, 0.2), + inset 0 0 8px rgba(255, 255, 255, 0.1); display: flex; align-items: center; justify-content: center; - animation: nodePulse 4s infinite ease-in-out; - transition: all 0.3s ease; -} - -.knowledge-node:hover { - transform: scale(1.2); - box-shadow: - 0 0 20px rgba(255, 255, 255, 0.6), - 0 0 40px rgba(16, 185, 129, 0.5), - inset 0 0 20px rgba(255, 255, 255, 0.2); + animation: nodePulse 5s infinite ease-in-out; + will-change: transform, opacity; } .node-icon { width: 20px; height: 20px; color: rgba(255, 255, 255, 0.9); - filter: drop-shadow(0 0 3px rgba(16, 185, 129, 0.5)); } -.node-1 { - top: 15%; - left: 20%; - animation-delay: 0s; -} - -.node-2 { - top: 25%; - left: 35%; - animation-delay: 0.5s; -} - -.node-3 { - top: 20%; - left: 55%; - animation-delay: 1s; -} - -.node-4 { - top: 30%; - left: 75%; - animation-delay: 1.5s; -} - -.node-5 { - top: 45%; - left: 25%; - animation-delay: 2s; -} - -.node-6 { - top: 50%; - left: 45%; - animation-delay: 2.5s; -} - -.node-7 { - top: 48%; - left: 65%; - animation-delay: 3s; -} - -.node-8 { - top: 60%; - left: 20%; - animation-delay: 0.3s; -} - -.node-9 { - top: 70%; - left: 40%; - animation-delay: 0.8s; -} - -.node-10 { - top: 65%; - left: 80%; - animation-delay: 1.3s; -} - -.node-11 { - top: 12%; - right: 15%; - animation-delay: 1.8s; -} - -.node-12 { - top: 38%; - right: 10%; - animation-delay: 2.3s; -} - -.node-13 { - top: 55%; - left: 10%; - animation-delay: 1.1s; -} - -.node-14 { - top: 35%; - left: 8%; - animation-delay: 2.8s; -} - -.node-15 { - top: 75%; - left: 60%; - animation-delay: 1.6s; -} - -.node-16 { - top: 80%; - right: 25%; - animation-delay: 3.2s; -} - -.node-17 { - top: 15%; - right: 35%; - animation-delay: 2.1s; -} - -.node-18 { - top: 42%; - right: 28%; - animation-delay: 0.6s; -} - -.node-19 { - top: 68%; - left: 12%; - animation-delay: 1.9s; -} - -.node-20 { - top: 52%; - right: 18%; - animation-delay: 2.6s; -} +.node-1 { top: 15%; left: 20%; animation-delay: 0s; } +.node-2 { top: 25%; left: 35%; animation-delay: 0.5s; } +.node-3 { top: 20%; left: 55%; animation-delay: 1s; } +.node-4 { top: 30%; left: 75%; animation-delay: 1.5s; } +.node-5 { top: 45%; left: 25%; animation-delay: 2s; } +.node-6 { top: 50%; left: 45%; animation-delay: 2.5s; } +.node-7 { top: 48%; left: 65%; animation-delay: 3s; } +.node-8 { top: 60%; left: 20%; animation-delay: 0.3s; } +.node-9 { top: 12%; right: 15%; animation-delay: 1.8s; } +.node-10 { top: 38%; right: 10%; animation-delay: 2.3s; } +.node-11 { top: 70%; left: 40%; animation-delay: 0.8s; } +.node-12 { top: 65%; left: 80%; animation-delay: 1.3s; } @keyframes nodePulse { - 0%, 100% { - transform: scale(1); - opacity: 0.7; - } - 50% { - transform: scale(1.08); - opacity: 0.9; - } + 0%, 100% { transform: scale(1); opacity: 0.65; } + 50% { transform: scale(1.08); opacity: 0.9; } } -/* Connection Lines */ .knowledge-lines { position: absolute; top: 0; @@ -922,37 +770,30 @@ onMounted(() => { stroke-dasharray: 6, 3; stroke-linecap: round; animation: lineFlow 10s infinite linear; - filter: drop-shadow(0 0 3px rgba(16, 185, 129, 0.4)); + will-change: stroke-dashoffset; } -.line-1 { animation-delay: 0s; } -.line-2 { animation-delay: 0.5s; } -.line-3 { animation-delay: 1s; } -.line-4 { animation-delay: 0.3s; } -.line-5 { animation-delay: 0.8s; } -.line-6 { animation-delay: 1.3s; } -.line-7 { animation-delay: 1.8s; } -.line-8 { animation-delay: 2.3s; } -.line-9 { animation-delay: 0.2s; } +.line-1 { animation-delay: 0s; } +.line-2 { animation-delay: 0.5s; } +.line-3 { animation-delay: 1s; } +.line-4 { animation-delay: 0.3s; } +.line-5 { animation-delay: 0.8s; } +.line-6 { animation-delay: 1.3s; } +.line-7 { animation-delay: 1.8s; } +.line-8 { animation-delay: 2.3s; } +.line-9 { animation-delay: 0.2s; } .line-10 { animation-delay: 0.7s; } -.line-11 { animation-delay: 1.2s; } -.line-12 { animation-delay: 0.6s; } -.line-13 { animation-delay: 0.4s; } -.line-14 { animation-delay: 1.1s; } -.line-15 { animation-delay: 0.9s; } -.line-16 { animation-delay: 1.5s; } -.line-17 { animation-delay: 2.1s; } -.line-18 { animation-delay: 1.7s; } -.line-19 { animation-delay: 0.35s; } -.line-20 { animation-delay: 1.4s; } +.line-11 { animation-delay: 0.9s; } +.line-12 { animation-delay: 1.5s; } @keyframes lineFlow { - 0% { - stroke-dashoffset: 0; - } - 100% { - stroke-dashoffset: 18; - } + 0% { stroke-dashoffset: 0; } + 100% { stroke-dashoffset: 18; } +} + +@media (prefers-reduced-motion: reduce) { + .knowledge-node { animation: none; opacity: 0.65; } + .connection-line { animation: none; } } /* Left Showcase Section */ @@ -1004,7 +845,6 @@ onMounted(() => { display: inline-block; padding: 8px 20px; background: rgba(255, 255, 255, 0.2); - backdrop-filter: blur(10px); border-radius: 20px; color: var(--td-text-color-anti); font-size: 14px; @@ -1092,22 +932,11 @@ onMounted(() => { top: 32px; left: 50px; z-index: 100; - transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; - &:hover { - transform: translateY(-2px); - } - .logo-image { width: 120px; - height: auto; - filter: brightness(1.1) contrast(1.05) drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25)); - transition: all 0.3s ease; - } - - &:hover .logo-image { - filter: brightness(1.15) contrast(1.08) drop-shadow(0 6px 16px rgba(0, 0, 0, 0.3)); + height: auto; } } @@ -1128,45 +957,23 @@ onMounted(() => { padding: 9px 15px; border-radius: 20px; background: rgba(255, 255, 255, 0.2); - backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, 0.25); color: var(--td-text-color-anti); text-decoration: none; font-size: 13px; - font-weight: 600; + font-weight: 600; font-family: "PingFang SC", sans-serif; letter-spacing: 0.2px; - transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; position: relative; - box-shadow: var(--td-shadow-2); - svg { - flex-shrink: 0; - transition: transform 0.25s ease; - } - - .link-text { - line-height: 1; - } + svg { flex-shrink: 0; } + .link-text { line-height: 1; } &:hover { background: rgba(255, 255, 255, 0.3); border-color: rgba(255, 255, 255, 0.4); color: var(--td-text-color-anti); - transform: translateY(-2px); - box-shadow: - 0 4px 16px rgba(0, 0, 0, 0.15), - 0 0 0 1px rgba(255, 255, 255, 0.2); - - svg { - transform: scale(1.08); - } - } - - &:active { - transform: translateY(-1px); - box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); } } @@ -1176,11 +983,10 @@ onMounted(() => { button { background: rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 255, 255, 0.25); - backdrop-filter: blur(8px); color: var(--td-text-color-anti); .lang-flag-icon { - font-size: 16px; + font-size: 16px; line-height: 1; flex-shrink: 0; } @@ -1188,20 +994,11 @@ onMounted(() => { &:hover { background: rgba(255, 255, 255, 0.3); border-color: rgba(255, 255, 255, 0.4); - color: var(--td-text-color-anti); - box-shadow: - 0 4px 16px rgba(0, 0, 0, 0.15), - 0 0 0 1px rgba(255, 255, 255, 0.2); } svg:last-child { margin-left: 2px; flex-shrink: 0; - transition: transform 0.25s ease; - } - - &:hover svg:last-child { - transform: translateY(2px); } } } @@ -1211,14 +1008,12 @@ onMounted(() => { top: calc(100% + 8px); right: 0; min-width: 160px; - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(14px); + background: rgba(255, 255, 255, 0.97); border: 1px solid var(--td-component-stroke); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12); overflow: hidden; z-index: 1000; - animation: dropdownFadeIn 0.2s ease-out; } .language-option { @@ -1227,19 +1022,12 @@ onMounted(() => { gap: 10px; padding: 10px 14px; cursor: pointer; - transition: all 0.2s; font-size: 13px; font-family: "PingFang SC", sans-serif; color: var(--td-text-color-primary); - .lang-flag { - font-size: 16px; - flex-shrink: 0; - } - - .lang-label { - flex: 1; - } + .lang-flag { font-size: 16px; flex-shrink: 0; } + .lang-label { flex: 1; } .check-icon { color: var(--td-success-color); @@ -1248,35 +1036,16 @@ onMounted(() => { flex-shrink: 0; } - &:hover { - background: var(--td-bg-color-secondarycontainer); - } - - &.active { - background: var(--td-success-color-light); - color: var(--td-brand-color-active); - } -} - -@keyframes dropdownFadeIn { - from { - opacity: 0; - transform: translateY(-8px); - } - to { - opacity: 1; - transform: translateY(0); - } + &:hover { background: var(--td-bg-color-secondarycontainer); } + &.active { background: var(--td-success-color-light); color: var(--td-brand-color-active); } } .form-card { - background: rgba(255, 255, 255, 0.95); - backdrop-filter: blur(20px); + background: rgba(255, 255, 255, 0.97); border-radius: 16px; padding: 40px; - box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.3); + box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15); box-sizing: border-box; - animation: slideInRight 0.4s ease-out; border: none; width: 100%; } @@ -1375,23 +1144,37 @@ onMounted(() => { font-weight: 500; font-family: "PingFang SC", sans-serif; margin: 20px 0 16px 0; - transition: all 0.3s; +} - :deep(.t-button) { - background-color: var(--td-brand-color); - border-color: var(--td-brand-color); +.oidc-divider { + position: relative; + margin: 4px 0 6px; + text-align: center; + color: var(--td-text-color-placeholder); + font-size: 12px; - &:hover { - background-color: var(--td-brand-color); - border-color: var(--td-brand-color); - transform: translateY(-1px); - box-shadow: 0 4px 12px rgba(7, 192, 95, 0.3); - } - - &:active { - transform: translateY(0); - } + span { + position: relative; + z-index: 1; + padding: 0 12px; + background: rgba(255, 255, 255, 0.95); } + + &::before { + content: ''; + position: absolute; + left: 0; + right: 0; + top: 50%; + border-top: 1px solid var(--td-component-stroke); + } +} + +.oidc-button { + height: 46px; + border-radius: 8px; + font-size: 15px; + font-weight: 500; } .form-footer { @@ -1417,6 +1200,12 @@ onMounted(() => { } } +.login-form-footer { + border-bottom: none; + padding-bottom: 8px; + margin-top: 12px; +} + .login-features { margin-top: 20px; padding: 0; @@ -1454,20 +1243,16 @@ onMounted(() => { } } -/* Animations */ -@keyframes slideInRight { - from { - opacity: 0; - transform: translateX(20px); - } - to { - opacity: 1; - transform: translateX(0); - } -} - /* Responsive Design */ @media (max-width: 1024px) { + .knowledge-node:nth-of-type(n + 13) { + display: none; + } + + .connection-line:nth-of-type(n + 13) { + display: none; + } + .showcase-subtitle { font-size: 18px; } @@ -1502,6 +1287,14 @@ onMounted(() => { flex-direction: column; } + .knowledge-node:nth-of-type(n + 9) { + display: none; + } + + .connection-line:nth-of-type(n + 9) { + display: none; + } + .showcase-section { flex: 0 0 auto; min-height: 50vh; @@ -1564,6 +1357,10 @@ onMounted(() => { } @media (max-width: 480px) { + .animated-bg { + display: none; + } + .showcase-section { padding: 32px 20px; } @@ -1610,109 +1407,76 @@ onMounted(() => { margin-bottom: 24px; } } + +@media (prefers-reduced-motion: reduce) { + .knowledge-node, + .connection-line { + animation: none !important; + transition: none !important; + } + + .animated-bg { + display: none; + } +}