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 @@
-
+
@@ -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 @@
-