From bb23444e39371ec10982c9d77b9f0ff667dd8605 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 4 Aug 2026 20:30:43 +0800 Subject: [PATCH] fix(knowledge): sync folder APIs and address review follow-ups Document folder tree/move/rename endpoints in docs/api, Swagger, and the Go client; align frontend path normalization with server caps; guard rename no-ops and duplicate folder creation; enforce KB ownership on folder rename. --- client/knowledge.go | 111 +++++++- docs/api/knowledge.md | 90 +++++++ docs/docs.go | 255 ++++++++++++++++-- docs/swagger.json | 255 ++++++++++++++++-- docs/swagger.yaml | 181 ++++++++++++- frontend/src/i18n/locales/en-US.ts | 1 + frontend/src/i18n/locales/ko-KR.ts | 1 + frontend/src/i18n/locales/ru-RU.ts | 1 + frontend/src/i18n/locales/zh-CN.ts | 1 + .../src/views/knowledge/KnowledgeBase.vue | 8 +- .../knowledge/components/FolderPickerMenu.vue | 6 +- .../src/views/knowledge/folderTree.test.ts | 15 ++ frontend/src/views/knowledge/folderTree.ts | 30 ++- internal/handler/knowledge.go | 4 + 14 files changed, 907 insertions(+), 52 deletions(-) diff --git a/client/knowledge.go b/client/knowledge.go index 7ab8d7de..8a96ce46 100644 --- a/client/knowledge.go +++ b/client/knowledge.go @@ -321,7 +321,9 @@ func (c *Client) ListKnowledge(ctx context.Context, // KnowledgeListFilter mirrors the server-side filters accepted by GET // /api/v1/knowledge-bases/{id}/knowledge. Empty / zero fields are omitted from -// the request. +// the request. FolderPath, when non-nil, selects a folder scope; the empty +// string means the knowledge base root. Omit FolderPath entirely for a flat +// listing across every folder. type KnowledgeListFilter struct { TagID string Keyword string @@ -332,6 +334,8 @@ type KnowledgeListFilter struct { // They are serialized in RFC3339 format. StartTime time.Time EndTime time.Time + FolderPath *string + FolderRecursive bool } // ListKnowledgeWithFilter lists knowledge entries with the full filter surface. @@ -367,6 +371,12 @@ func (c *Client) ListKnowledgeWithFilter(ctx context.Context, if !filter.EndTime.IsZero() { queryParams.Add("end_time", filter.EndTime.Format(time.RFC3339)) } + if filter.FolderPath != nil { + queryParams.Add("folder_path", *filter.FolderPath) + if filter.FolderRecursive { + queryParams.Add("folder_recursive", "true") + } + } resp, err := c.doRequest(ctx, http.MethodGet, path, nil, queryParams) if err != nil { @@ -381,6 +391,105 @@ func (c *Client) ListKnowledgeWithFilter(ctx context.Context, return response.Data, response.Total, nil } +// KnowledgeFolderNode is one node of the knowledge base folder tree. +type KnowledgeFolderNode struct { + Path string `json:"path"` + Name string `json:"name"` + DocumentCount int64 `json:"document_count"` + TotalCount int64 `json:"total_count"` + Children []*KnowledgeFolderNode `json:"children,omitempty"` +} + +// KnowledgeFolderTree is returned by ListKnowledgeFolders. +type KnowledgeFolderTree struct { + RootDocumentCount int64 `json:"root_document_count"` + TotalDocumentCount int64 `json:"total_document_count"` + Folders []*KnowledgeFolderNode `json:"folders"` +} + +// ListKnowledgeFolders returns the folder hierarchy of a knowledge base. +func (c *Client) ListKnowledgeFolders(ctx context.Context, knowledgeBaseID string) (*KnowledgeFolderTree, error) { + path := fmt.Sprintf("/api/v1/knowledge-bases/%s/knowledge/folders", knowledgeBaseID) + resp, err := c.doRequest(ctx, http.MethodGet, path, nil, nil) + if err != nil { + return nil, err + } + + var response struct { + Success bool `json:"success"` + Data *KnowledgeFolderTree `json:"data"` + } + if err := parseResponse(resp, &response); err != nil { + return nil, err + } + return response.Data, nil +} + +// MoveKnowledgeToFolderRequest re-files knowledge entries under a folder path. +type MoveKnowledgeToFolderRequest struct { + KBID string `json:"kb_id"` + IDs []string `json:"knowledge_ids"` + FolderPath string `json:"folder_path"` +} + +// MoveKnowledgeToFolderResponse is the payload of POST /knowledge/folder. +type MoveKnowledgeToFolderResponse struct { + MovedCount int64 `json:"moved_count"` + FolderPath string `json:"folder_path"` +} + +// MoveKnowledgeToFolder updates folder_path for the given knowledge entries. +// An empty FolderPath moves documents back to the knowledge base root. +func (c *Client) MoveKnowledgeToFolder(ctx context.Context, req *MoveKnowledgeToFolderRequest) (*MoveKnowledgeToFolderResponse, error) { + resp, err := c.doRequest(ctx, http.MethodPost, "/api/v1/knowledge/folder", req, nil) + if err != nil { + return nil, err + } + + var response struct { + Success bool `json:"success"` + Data *MoveKnowledgeToFolderResponse `json:"data"` + } + if err := parseResponse(resp, &response); err != nil { + return nil, err + } + return response.Data, nil +} + +// RenameKnowledgeFolderRequest moves a folder and its subtree to a new path. +type RenameKnowledgeFolderRequest struct { + From string `json:"from"` + To string `json:"to"` +} + +// RenameKnowledgeFolderResponse is the payload of PUT .../knowledge/folders. +type RenameKnowledgeFolderResponse struct { + MovedCount int64 `json:"moved_count"` + FolderPath string `json:"folder_path"` +} + +// RenameKnowledgeFolder rewrites folder_path for a folder and every descendant. +func (c *Client) RenameKnowledgeFolder( + ctx context.Context, + knowledgeBaseID string, + req *RenameKnowledgeFolderRequest, +) (*RenameKnowledgeFolderResponse, error) { + path := fmt.Sprintf("/api/v1/knowledge-bases/%s/knowledge/folders", knowledgeBaseID) + resp, err := c.doRequest(ctx, http.MethodPut, path, req, nil) + if err != nil { + return nil, err + } + + var response struct { + Success bool `json:"success"` + Data *RenameKnowledgeFolderResponse `json:"data"` + } + if err := parseResponse(resp, &response); err != nil { + return nil, err + } + return response.Data, nil +} + // DeleteKnowledge enqueues an asynchronous delete for the given knowledge entry. // The server returns 200 once the task has been submitted; the actual deletion is // performed by a background worker (same pipeline as BatchDeleteKnowledge). diff --git a/docs/api/knowledge.md b/docs/api/knowledge.md index d4c632e3..94dc51c7 100644 --- a/docs/api/knowledge.md +++ b/docs/api/knowledge.md @@ -10,6 +10,8 @@ | POST | `/knowledge-bases/:id/knowledge/url` | 从 URL 创建知识(网页抓取或文件下载) | | POST | `/knowledge-bases/:id/knowledge/manual` | 创建手工 Markdown 知识 | | GET | `/knowledge-bases/:id/knowledge` | 列出知识库下的知识(支持分页/筛选) | +| GET | `/knowledge-bases/:id/knowledge/folders` | 获取知识库文件夹目录树 | +| PUT | `/knowledge-bases/:id/knowledge/folders` | 重命名或移动文件夹(含子目录) | | DELETE | `/knowledge-bases/:id/knowledge` | 清空知识库下的所有知识(异步任务) | | GET | `/knowledge/batch` | 按 ID 列表批量获取知识 | | GET | `/knowledge/:id` | 获取知识详情 | @@ -25,6 +27,7 @@ | GET | `/knowledge/search` | 跨知识库搜索/过滤知识 | | POST | `/knowledge/batch-reparse` | 同一知识库内批量重新解析知识(异步任务) | | POST | `/knowledge/batch-delete` | 同一知识库内批量删除知识(异步任务) | +| POST | `/knowledge/folder` | 批量移动知识到指定文件夹(仅改归类) | | POST | `/knowledge/move` | 迁移知识到另一知识库(异步任务) | | GET | `/knowledge/move/progress/:task_id` | 查询知识迁移任务进度 | @@ -276,6 +279,10 @@ curl --location 'http://localhost:8080/api/v1/knowledge-bases/kb-00000001/knowle | `source` | string | - | 按来源/渠道过滤:`web` / `api` / `browser_extension` / `feishu` / `notion` / `yuque` / `wechat` 等; 特殊值 `manual` / `url` 命中 `type` 列 | | `start_time` | string | - | 更新时间起点,接受 RFC3339 (`2024-05-01T00:00:00+08:00`) 或 `YYYY-MM-DD HH:MM:SS` / `YYYY-MM-DD` | | `end_time` | string | - | 更新时间终点,格式同 `start_time` | +| `folder_path` | string | - | 按文件夹路径筛选;**仅当传入该参数时启用文件夹维度**。空字符串表示知识库根目录(不含子文件夹中的文档);不传则列出全部文件夹下的文档(扁平视图) | +| `folder_recursive` | bool | false | 为 `true` 时同时返回 `folder_path` 子目录内的文档;仅在传入 `folder_path` 时生效 | + +> **文件夹筛选语义**:`folder_path` 是否出现在 query 中决定列表模式,不能仅凭空字符串区分「根目录」与「不按文件夹过滤」。集成方若需要浏览某一文件夹,应显式传 `folder_path`(根目录传 `folder_path=`);若需要全库扁平列表,则省略该参数。 **请求**: @@ -304,6 +311,7 @@ curl --location 'http://localhost:8080/api/v1/knowledge-bases/kb-00000001/knowle "enable_status": "disabled", "embedding_model_id": "dff7bc94-7885-4dd1-bfd5-bd96e4df2fc3", "file_name": "", + "folder_path": "", "file_type": "", "file_size": 0, "file_hash": "", @@ -324,6 +332,88 @@ curl --location 'http://localhost:8080/api/v1/knowledge-bases/kb-00000001/knowle } ``` +## GET `/knowledge-bases/:id/knowledge/folders` - 获取文件夹目录树 + +返回由 `folder_path` 聚合而成的目录树,包含每个文件夹的直接文档数与含子目录的总数。只读,权限与列出知识相同(Viewer+ 且对 KB 有 read 权限)。 + +**响应**: + +```json +{ + "success": true, + "data": { + "root_document_count": 2, + "total_document_count": 10, + "folders": [ + { + "path": "docs", + "name": "docs", + "document_count": 0, + "total_count": 4, + "children": [ + { + "path": "docs/spec", + "name": "spec", + "document_count": 3, + "total_count": 4, + "children": [] + } + ] + } + ] + } +} +``` + +## PUT `/knowledge-bases/:id/knowledge/folders` - 重命名或移动文件夹 + +把一个文件夹及其所有子目录改到新路径。目标路径已存在时两个文件夹合并;不能移动到自身子目录下。需要 KB **创建者**或 Admin+,且对 KB 有 write 权限。 + +**请求体**: + +| 字段 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ---------------------------- | +| `from` | string | 是 | 源文件夹路径(不能为空) | +| `to` | string | 是 | 目标文件夹路径(不能为空) | + +**响应**: + +```json +{ + "success": true, + "data": { + "moved_count": 3, + "folder_path": "handbook" + } +} +``` + +`moved_count` 为 0 表示源文件夹不存在或已是 no-op。 + +## POST `/knowledge/folder` - 批量移动知识到文件夹 + +批量修改知识条目的 `folder_path`,仅调整归类,**不会**重新解析、分块或向量化。目标路径不存在时会自动创建;空路径表示移回知识库根目录。需要 editor/admin 且为 KB 创建者或 Admin+。 + +**请求体**: + +| 字段 | 类型 | 必填 | 说明 | +| --------------- | -------- | ---- | ----------------------------------------- | +| `kb_id` | string | 是 | 知识库 ID | +| `knowledge_ids` | string[] | 是 | 知识 ID 列表(最多 200 条) | +| `folder_path` | string | 否 | 目标文件夹路径;省略或空字符串表示根目录 | + +**响应**: + +```json +{ + "success": true, + "data": { + "moved_count": 2, + "folder_path": "archive/2026" + } +} +``` + ## DELETE `/knowledge-bases/:id/knowledge` - 清空知识库下的所有知识 异步提交"清空任务",删除该知识库下的全部知识条目;知识库本身保留。**仅 KB 所有者(admin 且空间匹配)可操作**。 diff --git a/docs/docs.go b/docs/docs.go index 15643bd3..55b08cdf 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -5002,6 +5002,18 @@ const docTemplate = `{ "description": "更新时间终点,RFC3339 格式", "name": "end_time", "in": "query" + }, + { + "type": "string", + "description": "文件夹路径筛选,空字符串表示知识库根目录;不传该参数则不按文件夹过滤", + "name": "folder_path", + "in": "query" + }, + { + "type": "boolean", + "description": "为 true 时同时返回子文件夹内的文档", + "name": "folder_recursive", + "in": "query" } ], "responses": { @@ -5163,6 +5175,113 @@ const docTemplate = `{ } } }, + "/knowledge-bases/{id}/knowledge/folders": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "返回知识库内由文件夹上传形成的目录树,包含每个文件夹的直接文档数与含子目录的总数", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "获取知识库文件夹目录树", + "parameters": [ + { + "type": "string", + "description": "知识库ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "目录树", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "把一个文件夹及其所有子目录改到新路径。目标路径已存在时两个文件夹合并;不能移动到自身子目录下", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "重命名或移动文件夹", + "parameters": [ + { + "type": "string", + "description": "知识库ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "重命名请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.RenameKnowledgeFolderRequest" + } + } + ], + "responses": { + "200": { + "description": "重命名成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "403": { + "description": "权限不足", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge-bases/{id}/knowledge/manual": { "post": { "security": [ @@ -6028,6 +6147,61 @@ const docTemplate = `{ } } }, + "/knowledge/folder": { + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "批量修改知识条目所属文件夹。文件夹由路径推导而来,因此目标路径不存在时会自动创建;空路径表示知识库顶层。仅调整归类,不会重新解析文档", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "移动知识到文件夹", + "parameters": [ + { + "description": "移动请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.MoveKnowledgeToFolderRequest" + } + } + ], + "responses": { + "200": { + "description": "移动成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "403": { + "description": "权限不足", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge/image/{id}/{chunk_id}": { "put": { "security": [ @@ -16369,6 +16543,13 @@ const docTemplate = `{ "description": "Creation time of the knowledge", "type": "string" }, + "custom_metadata": { + "description": "CustomMetadata is user-authored descriptive metadata. It is deliberately\nseparate from Metadata, which contains internal ingestion state and IDs.", + "type": "array", + "items": { + "type": "integer" + } + }, "deleted_at": { "description": "Deletion time of the knowledge", "allOf": [ @@ -16413,6 +16594,10 @@ const docTemplate = `{ "description": "File type of the knowledge", "type": "string" }, + "folder_path": { + "description": "FolderPath is the canonical relative directory this entry belongs to\ninside the knowledge base, e.g. \"docs/spec\" for a folder upload of\n\"docs/spec/design.md\". Empty means the knowledge base root. It is a\ndisplay/navigation concern only: it never affects where the file is\nphysically stored (see FilePath).", + "type": "string" + }, "id": { "description": "Unique identifier of the knowledge", "type": "string" @@ -17926,6 +18111,7 @@ const docTemplate = `{ "type": "boolean" }, "mineru_enable_ocr": { + "description": "MinerUEnableOCR is retained for compatibility with configurations saved\nbefore parse_method supported auto/ocr/txt.", "type": "boolean" }, "mineru_enable_table": { @@ -17942,6 +18128,9 @@ const docTemplate = `{ "description": "MinerU 自建解析参数", "type": "string" }, + "mineru_parse_method": { + "type": "string" + }, "mineru_vlm_server_url": { "description": "vLLM 服务器地址 (vlm-http-client / hybrid-http-client)", "type": "string" @@ -18001,6 +18190,10 @@ const docTemplate = `{ "items": { "type": "string" } + }, + "xlsx_first_row_as_header": { + "description": "XLSXFirstRowAsHeader restores row-1 column context for flat XLSX tables.\nnil preserves the parser default; an explicit false disables the mode.", + "type": "boolean" } } }, @@ -18617,6 +18810,10 @@ const docTemplate = `{ "description": "KnowledgeChannel indicates through which channel the knowledge was ingested (web, api, wechat, etc.)", "type": "string" }, + "knowledge_custom_metadata": { + "description": "KnowledgeCustomMetadata is user-authored context safe to expose to models.", + "type": "string" + }, "knowledge_description": { "description": "KnowledgeDescription is the description of the knowledge document", "type": "string" @@ -21169,6 +21366,28 @@ const docTemplate = `{ } } }, + "internal_handler.MoveKnowledgeToFolderRequest": { + "type": "object", + "required": [ + "kb_id", + "knowledge_ids" + ], + "properties": { + "folder_path": { + "description": "FolderPath is the destination folder; the empty string is the knowledge\nbase top level. It is deliberately not ` + "`" + `binding:\"required\"` + "`" + ` so documents\ncan be moved back out of every folder.", + "type": "string" + }, + "kb_id": { + "type": "string" + }, + "knowledge_ids": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "internal_handler.PreviewChunkResult": { "type": "object", "properties": { @@ -21355,6 +21574,21 @@ const docTemplate = `{ } } }, + "internal_handler.RenameKnowledgeFolderRequest": { + "type": "object", + "required": [ + "from", + "to" + ], + "properties": { + "from": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, "internal_handler.ResetUserPasswordRequest": { "type": "object", "required": [ @@ -21659,29 +21893,14 @@ const docTemplate = `{ "internal_handler.UpdateChunkRequest": { "type": "object", "properties": { - "chunk_index": { - "type": "integer" - }, "content": { "type": "string" }, - "embedding": { - "type": "array", - "items": { - "type": "number" - } - }, - "end_at": { + "expected_revision": { "type": "integer" }, - "image_info": { - "type": "string" - }, "is_enabled": { "type": "boolean" - }, - "start_at": { - "type": "integer" } } }, @@ -22076,6 +22295,10 @@ const docTemplate = `{ "description": "Selected custom agent ID (backend resolves shared agent and its workspace from share relation)", "type": "string" }, + "agent_source_tenant_id": { + "description": "Optional disambiguator; backend still verifies the share relation", + "type": "integer" + }, "attachment_ids": { "description": "Pre-uploaded session-scoped document IDs", "type": "array", diff --git a/docs/swagger.json b/docs/swagger.json index faadf1ad..60049511 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -4995,6 +4995,18 @@ "description": "更新时间终点,RFC3339 格式", "name": "end_time", "in": "query" + }, + { + "type": "string", + "description": "文件夹路径筛选,空字符串表示知识库根目录;不传该参数则不按文件夹过滤", + "name": "folder_path", + "in": "query" + }, + { + "type": "boolean", + "description": "为 true 时同时返回子文件夹内的文档", + "name": "folder_recursive", + "in": "query" } ], "responses": { @@ -5156,6 +5168,113 @@ } } }, + "/knowledge-bases/{id}/knowledge/folders": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "返回知识库内由文件夹上传形成的目录树,包含每个文件夹的直接文档数与含子目录的总数", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "获取知识库文件夹目录树", + "parameters": [ + { + "type": "string", + "description": "知识库ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "目录树", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "把一个文件夹及其所有子目录改到新路径。目标路径已存在时两个文件夹合并;不能移动到自身子目录下", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "重命名或移动文件夹", + "parameters": [ + { + "type": "string", + "description": "知识库ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "重命名请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.RenameKnowledgeFolderRequest" + } + } + ], + "responses": { + "200": { + "description": "重命名成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "403": { + "description": "权限不足", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge-bases/{id}/knowledge/manual": { "post": { "security": [ @@ -6021,6 +6140,61 @@ } } }, + "/knowledge/folder": { + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "批量修改知识条目所属文件夹。文件夹由路径推导而来,因此目标路径不存在时会自动创建;空路径表示知识库顶层。仅调整归类,不会重新解析文档", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "知识管理" + ], + "summary": "移动知识到文件夹", + "parameters": [ + { + "description": "移动请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.MoveKnowledgeToFolderRequest" + } + } + ], + "responses": { + "200": { + "description": "移动成功", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "403": { + "description": "权限不足", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge/image/{id}/{chunk_id}": { "put": { "security": [ @@ -16362,6 +16536,13 @@ "description": "Creation time of the knowledge", "type": "string" }, + "custom_metadata": { + "description": "CustomMetadata is user-authored descriptive metadata. It is deliberately\nseparate from Metadata, which contains internal ingestion state and IDs.", + "type": "array", + "items": { + "type": "integer" + } + }, "deleted_at": { "description": "Deletion time of the knowledge", "allOf": [ @@ -16406,6 +16587,10 @@ "description": "File type of the knowledge", "type": "string" }, + "folder_path": { + "description": "FolderPath is the canonical relative directory this entry belongs to\ninside the knowledge base, e.g. \"docs/spec\" for a folder upload of\n\"docs/spec/design.md\". Empty means the knowledge base root. It is a\ndisplay/navigation concern only: it never affects where the file is\nphysically stored (see FilePath).", + "type": "string" + }, "id": { "description": "Unique identifier of the knowledge", "type": "string" @@ -17919,6 +18104,7 @@ "type": "boolean" }, "mineru_enable_ocr": { + "description": "MinerUEnableOCR is retained for compatibility with configurations saved\nbefore parse_method supported auto/ocr/txt.", "type": "boolean" }, "mineru_enable_table": { @@ -17935,6 +18121,9 @@ "description": "MinerU 自建解析参数", "type": "string" }, + "mineru_parse_method": { + "type": "string" + }, "mineru_vlm_server_url": { "description": "vLLM 服务器地址 (vlm-http-client / hybrid-http-client)", "type": "string" @@ -17994,6 +18183,10 @@ "items": { "type": "string" } + }, + "xlsx_first_row_as_header": { + "description": "XLSXFirstRowAsHeader restores row-1 column context for flat XLSX tables.\nnil preserves the parser default; an explicit false disables the mode.", + "type": "boolean" } } }, @@ -18610,6 +18803,10 @@ "description": "KnowledgeChannel indicates through which channel the knowledge was ingested (web, api, wechat, etc.)", "type": "string" }, + "knowledge_custom_metadata": { + "description": "KnowledgeCustomMetadata is user-authored context safe to expose to models.", + "type": "string" + }, "knowledge_description": { "description": "KnowledgeDescription is the description of the knowledge document", "type": "string" @@ -21162,6 +21359,28 @@ } } }, + "internal_handler.MoveKnowledgeToFolderRequest": { + "type": "object", + "required": [ + "kb_id", + "knowledge_ids" + ], + "properties": { + "folder_path": { + "description": "FolderPath is the destination folder; the empty string is the knowledge\nbase top level. It is deliberately not `binding:\"required\"` so documents\ncan be moved back out of every folder.", + "type": "string" + }, + "kb_id": { + "type": "string" + }, + "knowledge_ids": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "internal_handler.PreviewChunkResult": { "type": "object", "properties": { @@ -21348,6 +21567,21 @@ } } }, + "internal_handler.RenameKnowledgeFolderRequest": { + "type": "object", + "required": [ + "from", + "to" + ], + "properties": { + "from": { + "type": "string" + }, + "to": { + "type": "string" + } + } + }, "internal_handler.ResetUserPasswordRequest": { "type": "object", "required": [ @@ -21652,29 +21886,14 @@ "internal_handler.UpdateChunkRequest": { "type": "object", "properties": { - "chunk_index": { - "type": "integer" - }, "content": { "type": "string" }, - "embedding": { - "type": "array", - "items": { - "type": "number" - } - }, - "end_at": { + "expected_revision": { "type": "integer" }, - "image_info": { - "type": "string" - }, "is_enabled": { "type": "boolean" - }, - "start_at": { - "type": "integer" } } }, @@ -22069,6 +22288,10 @@ "description": "Selected custom agent ID (backend resolves shared agent and its workspace from share relation)", "type": "string" }, + "agent_source_tenant_id": { + "description": "Optional disambiguator; backend still verifies the share relation", + "type": "integer" + }, "attachment_ids": { "description": "Pre-uploaded session-scoped document IDs", "type": "array", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 7c37ab15..598bb603 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1391,6 +1391,13 @@ definitions: created_at: description: Creation time of the knowledge type: string + custom_metadata: + description: |- + CustomMetadata is user-authored descriptive metadata. It is deliberately + separate from Metadata, which contains internal ingestion state and IDs. + items: + type: integer + type: array deleted_at: allOf: - $ref: '#/definitions/gorm.DeletedAt' @@ -1422,6 +1429,14 @@ definitions: file_type: description: File type of the knowledge type: string + folder_path: + description: |- + FolderPath is the canonical relative directory this entry belongs to + inside the knowledge base, e.g. "docs/spec" for a folder upload of + "docs/spec/design.md". Empty means the knowledge base root. It is a + display/navigation concern only: it never affects where the file is + physically stored (see FilePath). + type: string id: description: Unique identifier of the knowledge type: string @@ -2574,6 +2589,9 @@ definitions: mineru_enable_formula: type: boolean mineru_enable_ocr: + description: |- + MinerUEnableOCR is retained for compatibility with configurations saved + before parse_method supported auto/ocr/txt. type: boolean mineru_enable_table: type: boolean @@ -2585,6 +2603,8 @@ definitions: mineru_model: description: MinerU 自建解析参数 type: string + mineru_parse_method: + type: string mineru_vlm_server_url: description: vLLM 服务器地址 (vlm-http-client / hybrid-http-client) type: string @@ -2629,6 +2649,11 @@ definitions: items: type: string type: array + xlsx_first_row_as_header: + description: |- + XLSXFirstRowAsHeader restores row-1 column context for flat XLSX tables. + nil preserves the parser default; an explicit false disables the mode. + type: boolean type: object github_com_Tencent_WeKnora_internal_types.QuestionGenerationConfig: properties: @@ -3086,6 +3111,10 @@ definitions: description: KnowledgeChannel indicates through which channel the knowledge was ingested (web, api, wechat, etc.) type: string + knowledge_custom_metadata: + description: KnowledgeCustomMetadata is user-authored context safe to expose + to models. + type: string knowledge_description: description: KnowledgeDescription is the description of the knowledge document type: string @@ -4979,6 +5008,24 @@ definitions: task_id: type: string type: object + internal_handler.MoveKnowledgeToFolderRequest: + properties: + folder_path: + description: |- + FolderPath is the destination folder; the empty string is the knowledge + base top level. It is deliberately not `binding:"required"` so documents + can be moved back out of every folder. + type: string + kb_id: + type: string + knowledge_ids: + items: + type: string + type: array + required: + - kb_id + - knowledge_ids + type: object internal_handler.PreviewChunkResult: properties: content: @@ -5112,6 +5159,16 @@ definitions: required: - modelName type: object + internal_handler.RenameKnowledgeFolderRequest: + properties: + from: + type: string + to: + type: string + required: + - from + - to + type: object internal_handler.ResetUserPasswordRequest: properties: email: @@ -5318,22 +5375,12 @@ definitions: type: object internal_handler.UpdateChunkRequest: properties: - chunk_index: - type: integer content: type: string - embedding: - items: - type: number - type: array - end_at: + expected_revision: type: integer - image_info: - type: string is_enabled: type: boolean - start_at: - type: integer type: object internal_handler.UpdateKnowledgeBaseRequest: properties: @@ -5601,6 +5648,9 @@ definitions: description: Selected custom agent ID (backend resolves shared agent and its workspace from share relation) type: string + agent_source_tenant_id: + description: Optional disambiguator; backend still verifies the share relation + type: integer attachment_ids: description: Pre-uploaded session-scoped document IDs items: @@ -8927,6 +8977,14 @@ paths: in: query name: end_time type: string + - description: 文件夹路径筛选,空字符串表示知识库根目录;不传该参数则不按文件夹过滤 + in: query + name: folder_path + type: string + - description: 为 true 时同时返回子文件夹内的文档 + in: query + name: folder_recursive + type: boolean produces: - application/json responses: @@ -9004,6 +9062,73 @@ paths: summary: 从文件创建知识 tags: - 知识管理 + /knowledge-bases/{id}/knowledge/folders: + get: + consumes: + - application/json + description: 返回知识库内由文件夹上传形成的目录树,包含每个文件夹的直接文档数与含子目录的总数 + parameters: + - description: 知识库ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 目录树 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: 获取知识库文件夹目录树 + tags: + - 知识管理 + put: + consumes: + - application/json + description: 把一个文件夹及其所有子目录改到新路径。目标路径已存在时两个文件夹合并;不能移动到自身子目录下 + parameters: + - description: 知识库ID + in: path + name: id + required: true + type: string + - description: 重命名请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler.RenameKnowledgeFolderRequest' + produces: + - application/json + responses: + "200": + description: 重命名成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + "403": + description: 权限不足 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: 重命名或移动文件夹 + tags: + - 知识管理 /knowledge-bases/{id}/knowledge/manual: post: consumes: @@ -9842,6 +9967,40 @@ paths: summary: 批量重新解析知识 tags: - 知识管理 + /knowledge/folder: + post: + consumes: + - application/json + description: 批量修改知识条目所属文件夹。文件夹由路径推导而来,因此目标路径不存在时会自动创建;空路径表示知识库顶层。仅调整归类,不会重新解析文档 + parameters: + - description: 移动请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler.MoveKnowledgeToFolderRequest' + produces: + - application/json + responses: + "200": + description: 移动成功 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + "403": + description: 权限不足 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: 移动知识到文件夹 + tags: + - 知识管理 /knowledge/image/{id}/{chunk_id}: put: consumes: diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 087407c8..9d00d996 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -399,6 +399,7 @@ export default { newFolderHintUnder: 'Will be created under “{folder}”', success: 'Moved {count} documents', failed: 'Could not move the documents', + duplicate: 'That folder already exists', }, tagFilterTitle: 'Filter by tag', tagFilterPlaceholder: 'Tags', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 73344617..446b5c30 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5158,6 +5158,7 @@ export default { newFolderHintUnder: '「{folder}」 아래에 생성됩니다', success: '문서 {count}개를 이동했습니다', failed: '문서를 이동할 수 없습니다', + duplicate: '이미 존재하는 폴더입니다', }, tagFilterTitle: '태그로 필터', tagFilterPlaceholder: '태그', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 94d4a740..486101cb 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5158,6 +5158,7 @@ export default { newFolderHintUnder: 'Будет создана внутри «{folder}»', success: 'Перемещено документов: {count}', failed: 'Не удалось переместить документы', + duplicate: 'Такая папка уже существует', }, tagFilterTitle: 'Фильтр по тегу', tagFilterPlaceholder: 'Теги', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 2723e224..bad4dcde 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5158,6 +5158,7 @@ export default { newFolderHintUnder: '将在「{folder}」下创建', success: '已移动 {count} 个文档', failed: '移动失败', + duplicate: '该目录已存在', }, tagFilterTitle: '按标签筛选', tagFilterPlaceholder: '标签', diff --git a/frontend/src/views/knowledge/KnowledgeBase.vue b/frontend/src/views/knowledge/KnowledgeBase.vue index d806c8d5..0a61a69b 100644 --- a/frontend/src/views/knowledge/KnowledgeBase.vue +++ b/frontend/src/views/knowledge/KnowledgeBase.vue @@ -842,7 +842,13 @@ const handleFolderRename = async ({ from, to }: { from: string; to: string }) => return; } try { - await renameKnowledgeFolder(kbId.value, from, to); + const res: any = await renameKnowledgeFolder(kbId.value, from, to); + const movedCount = res?.data?.moved_count ?? 0; + if (movedCount === 0) { + MessagePlugin.warning(t('knowledgeBase.folderTree.renameFailed')); + await loadFolderTree(kbId.value); + return; + } MessagePlugin.success(t('knowledgeBase.folderTree.renameSuccess')); // Follow the folder to its new path so the user stays where they were. if (selectedFolderPath.value === from) { diff --git a/frontend/src/views/knowledge/components/FolderPickerMenu.vue b/frontend/src/views/knowledge/components/FolderPickerMenu.vue index 570a1fb6..ecc3a74e 100644 --- a/frontend/src/views/knowledge/components/FolderPickerMenu.vue +++ b/frontend/src/views/knowledge/components/FolderPickerMenu.vue @@ -57,6 +57,7 @@