From 92fd75f54a82d1e92f4b2a647cc25fc944709a4a Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 25 Aug 2026 15:13:20 +0800 Subject: [PATCH] refactor(sandbox): remove token requirement for skill installation from source Updated the skill installation process to eliminate the need for a token when installing skills from ClawHub, SkillHub, or Git URLs. The source must now be readable anonymously, ensuring that no credentials are sent during the fetch process. Adjusted related documentation and UI components to reflect this change, enhancing the user experience by simplifying the installation workflow. --- client/README.md | 2 +- client/README_EN.md | 2 +- client/skill.go | 8 +- docs/agent-skills.md | 2 +- docs/api/skill.md | 2 +- docs/docs.go | 1683 +++++++++++++--- docs/swagger.json | 1685 ++++++++++++++--- docs/swagger.yaml | 1247 ++++++++++-- frontend/src/api/system/index.ts | 2 +- .../src/components/SandboxSkillsPanel.vue | 89 +- frontend/src/i18n/locales/en-US.ts | 3 - frontend/src/i18n/locales/ko-KR.ts | 3 - frontend/src/i18n/locales/ru-RU.ts | 3 - frontend/src/i18n/locales/zh-CN.ts | 3 - .../service/tenant_skill_source.go | 145 +- .../service/tenant_skill_source_test.go | 136 +- internal/handler/sandbox_skill.go | 17 +- internal/handler/sandbox_skill_test.go | 8 +- internal/handler/skill_handler.go | 1 - 19 files changed, 4148 insertions(+), 893 deletions(-) diff --git a/client/README.md b/client/README.md index d832a35a..cd9ac297 100644 --- a/client/README.md +++ b/client/README.md @@ -391,7 +391,7 @@ if err != nil { ```go skillID, err := apiClient.InstallSandboxSkillFromSource( - context.Background(), sandboxConfigID, "@owner/slug", "") + context.Background(), sandboxConfigID, "@owner/slug") if err != nil { // 处理错误 } diff --git a/client/README_EN.md b/client/README_EN.md index 63700654..6c676018 100644 --- a/client/README_EN.md +++ b/client/README_EN.md @@ -204,7 +204,7 @@ if err != nil { ```go skillID, err := apiClient.InstallSandboxSkillFromSource( - context.Background(), sandboxConfigID, "@owner/slug", "") + context.Background(), sandboxConfigID, "@owner/slug") if err != nil { // Handle error } diff --git a/client/skill.go b/client/skill.go index 2d180bdf..d2f93e5a 100644 --- a/client/skill.go +++ b/client/skill.go @@ -53,17 +53,15 @@ func (c *Client) ListSkills(ctx context.Context, sandboxConfigID string) ([]Skil // InstallSandboxSkillFromSource installs a skill onto a sandbox config from a // ClawHub / SkillHub / skills.sh / GitHub / GitLab locator or a direct archive -// URL. The call is accepted asynchronously; follow progress on the skill ID. +// URL. The source must be readable anonymously. The call is accepted +// asynchronously; follow progress on the skill ID. func (c *Client) InstallSandboxSkillFromSource( - ctx context.Context, configID, source, token string, + ctx context.Context, configID, source string, ) (string, error) { if configID == "" { return "", fmt.Errorf("sandbox config ID is required") } body := map[string]string{"source": source} - if token != "" { - body["token"] = token - } path := "/api/v1/sandbox-configs/" + url.PathEscape(configID) + "/skills" resp, err := c.doRequest(ctx, http.MethodPost, path, body, nil) if err != nil { diff --git a/docs/agent-skills.md b/docs/agent-skills.md index 52e6722c..8ba484bb 100644 --- a/docs/agent-skills.md +++ b/docs/agent-skills.md @@ -164,7 +164,7 @@ Docker、Local、CubeSandbox、E2B 均通过同一套空间配置 CRUD、连接 - skills.sh、GitHub、GitLab 仓库或目录链接 - 直接的 zip / `SKILL.md` URL -私有 SkillHub 可在同一次请求里带 Token,仅用于下载、不会落库。安装仍走原有镜像快照流程。 +来源必须可匿名读取,服务端下载时不携带任何凭据;私有仓库请先导出 zip 再上传。安装仍走原有镜像快照流程。 **有沙箱在跑时改不了身份字段。** 身份字段分两组,成因不同但后果都足够严重: diff --git a/docs/api/skill.md b/docs/api/skill.md index 3e172e34..8d83f491 100644 --- a/docs/api/skill.md +++ b/docs/api/skill.md @@ -75,7 +75,7 @@ curl --location 'http://localhost:8080/api/v1/sandbox-configs/{id}/skills' \ - skills.sh / GitHub / GitLab 仓库或目录链接 - 直接的 zip / `SKILL.md` URL -私有 SkillHub 可带 `token`,仅用于本次下载,服务端不保存。 +来源必须可匿名读取:服务端不会为这次下载附带任何凭据,因此私有仓库/私有 registry 需要先自行导出 zip 再上传。 ```curl curl --location 'http://localhost:8080/api/v1/sandbox-configs/{id}/skills' \ diff --git a/docs/docs.go b/docs/docs.go index de2725d1..e51e472b 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -6122,6 +6122,66 @@ const docTemplate = `{ } } }, + "/knowledge-search": { + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "在知识库中搜索(不使用LLM总结)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "问答" + ], + "summary": "知识搜索", + "parameters": [ + { + "description": "搜索请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler_session.SearchKnowledgeRequest" + } + }, + { + "enum": [ + "handle", + "public" + ], + "type": "string", + "default": "handle", + "description": "文件引用形式,public 返回可加载直链", + "name": "resource_urls", + "in": "query" + } + ], + "responses": { + "200": { + "description": "搜索结果", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge/batch": { "get": { "security": [ @@ -6594,14 +6654,17 @@ const docTemplate = `{ "in": "query" }, { + "minimum": 0, "type": "integer", - "description": "Offset for pagination", + "description": "Offset for pagination (minimum 0)", "name": "offset", "in": "query" }, { + "maximum": 100, + "minimum": 1, "type": "integer", - "description": "Limit for pagination (default 20)", + "description": "Limit for pagination (default 20, maximum 100)", "name": "limit", "in": "query" }, @@ -6751,7 +6814,7 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "更新知识条目信息", + "description": "部分更新知识条目(标题/描述/自定义元数据);未传字段保持不变,显式传空 description 可清空摘要", "consumes": [ "application/json" ], @@ -6771,12 +6834,12 @@ const docTemplate = `{ "required": true }, { - "description": "知识信息", + "description": "更新字段(均可选)", "name": "request", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Knowledge" + "$ref": "#/definitions/internal_handler.UpdateKnowledgeRequest" } } ], @@ -9051,6 +9114,574 @@ const docTemplate = `{ } } }, + "/memory/consolidate": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "合并意思接近的条目、归档到期事项,不等待每日后台整理", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "立刻整理我的记忆", + "responses": { + "200": { + "description": "整理结果", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/documents": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回当前用户回答里反复引用的文档,次数未达习惯门槛的不展示", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出常用资料", + "parameters": [ + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "文档列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/documents/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除一条文档亲和度计数,之后检索不再因为这份文档而加权", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "停止用某份文档做个性化检索", + "parameters": [ + { + "type": "string", + "description": "亲和度 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/export": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "以 JSON 导出当前用户的全部记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "导出我的记忆", + "responses": { + "200": { + "description": "记忆导出", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "分页返回当前用户的记忆条目,可按状态过滤", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出我的记忆", + "parameters": [ + { + "enum": [ + "active", + "superseded", + "archived", + "pending" + ], + "type": "string", + "description": "状态过滤", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "记忆列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "手动添加一条长期记忆", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "新增一条记忆", + "parameters": [ + { + "description": "记忆内容", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "新增的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "永久删除当前用户的全部记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "清空我的记忆", + "responses": { + "200": { + "description": "清空成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "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": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "更新后的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "永久删除一条记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "删除一条记忆", + "parameters": [ + { + "type": "string", + "description": "记忆ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}/confirm": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "接受系统推断的记忆,使其开始生效", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "确认一条推断出的记忆", + "parameters": [ + { + "type": "string", + "description": "记忆 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "确认成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}/reject": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "拒绝系统推断的记忆,并记住这次拒绝", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "否决一条推断出的记忆", + "parameters": [ + { + "type": "string", + "description": "记忆 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "否决成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/settings": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回合并后的记忆开关状态(空间级 + 个人级)与记忆条数", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "获取我的记忆设置", + "responses": { + "200": { + "description": "记忆设置", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "开启或关闭当前用户自己的长期记忆", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "更新我的记忆设置", + "parameters": [ + { + "description": "设置", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "更新后的设置", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回已计数、尚未提升为长期关注的主题,以及距离阈值还差几次", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出正在观察的主题", + "parameters": [ + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "主题列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除尚未提升的主题计数,并记住这次拒绝,之后不会再自动记为长期关注", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "停止跟踪一个主题", + "parameters": [ + { + "type": "string", + "description": "主题 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics/{id}/promote": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "不等待剩余次数,把正在观察的主题提升为一条长期关注记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "立即记为长期关注", + "parameters": [ + { + "type": "string", + "description": "主题 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "新增的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/messages/chat-history-stats": { "get": { "security": [ @@ -10942,6 +11573,432 @@ const docTemplate = `{ } } }, + "/sandbox-configs/{id}/skills": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "List the agent skills installed onto one sandbox config's image.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "List installed skills", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Installed skills", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Sandbox config not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Install a skill onto this sandbox config's image. Send a zip\nas multipart form field \"file\", or JSON {\"source\":\"...\"} to\npull from ClawHub, SkillHub, skills.sh, GitHub, GitLab, or a\ndirect archive URL. The source must be readable anonymously.\nThe install boots a sandbox and runs for minutes, so the\nrequest is only accepted; follow it via the install-events\nstream.", + "consumes": [ + "application/json", + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Install a skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "Skill bundle (zip)", + "name": "file", + "in": "formData" + }, + { + "description": "Install from a registry, git host, or archive URL", + "name": "request", + "in": "body", + "schema": { + "$ref": "#/definitions/internal_handler.skillSourceRequest" + } + } + ], + "responses": { + "202": { + "description": "Install accepted", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Missing, oversized or invalid bundle or source", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Sandbox config not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Retrieve one installed skill of a sandbox config.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Get an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Installed skill", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Remove a skill from the config's image. The removal rebuilds\nthe image and runs for minutes, so it is only accepted; follow\nit via the install-events stream.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Remove an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "202": { + "description": "Removal accepted", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "patch": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Show or hide an installed skill. The files stay in the image either way; removal is a separate flow.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Update an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + }, + { + "description": "Fields to update", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.skillPatchRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated skill", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Invalid request", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}/install-events": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Server-sent progress for one install or removal. The stream\nalways terminates: with the run's own terminal event, with one\nderived from the durable status, or with a \"detached\" frame\nwhen it stops following a run that is still going.", + "produces": [ + "text/event-stream" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Follow an install or removal", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "SSE stream of progress events", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}/transcript": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Server-sent replay of everything the installer agent did — the\nprompt it was given, its thinking, the commands it ran and\ntheir output — followed live while the install is still\nrunning. Frames are the same shape the chat stream uses, so a\nconsole renders an install with the components it renders a\nchat turn with. 404 once the event log has expired; the\ndurable message history is the fallback.", + "produces": [ + "text/event-stream" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Follow an install's agent transcript", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "SSE stream of transcript events", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill or transcript not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/sessions": { "get": { "security": [ @@ -11173,66 +12230,6 @@ const docTemplate = `{ } } }, - "/knowledge-search": { - "post": { - "security": [ - { - "Bearer": [] - }, - { - "ApiKeyAuth": [] - } - ], - "description": "在知识库中搜索(不使用LLM总结)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "问答" - ], - "summary": "知识搜索", - "parameters": [ - { - "description": "搜索请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/internal_handler_session.SearchKnowledgeRequest" - } - }, - { - "enum": [ - "handle", - "public" - ], - "type": "string", - "default": "handle", - "description": "文件引用形式,public 返回可加载直链", - "name": "resource_urls", - "in": "query" - } - ], - "responses": { - "200": { - "description": "搜索结果", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" - } - } - } - } - }, "/sessions/{id}": { "get": { "security": [ @@ -11902,7 +12899,7 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "获取所有预装的Agent Skills元数据", + "description": "返回指定沙盒配置镜像内、智能体实际能调用的已安装技能(ready 且启用)。不传 sandbox_config_id 时列表为空。", "consumes": [ "application/json" ], @@ -11912,7 +12909,15 @@ const docTemplate = `{ "tags": [ "Skills" ], - "summary": "获取预装Skills列表", + "summary": "获取当前沙盒配置上可执行的 Skills", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "sandbox_config_id", + "in": "query" + } + ], "responses": { "200": { "description": "Skills列表", @@ -11920,12 +12925,6 @@ const docTemplate = `{ "type": "object", "additionalProperties": true } - }, - "500": { - "description": "服务器错误", - "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" - } } } } @@ -13028,6 +14027,74 @@ const docTemplate = `{ } } }, + "/system/admin/users/create": { + "post": { + "description": "Provision a new local user account (SystemAdmin only).\nWhen ` + "`" + `password` + "`" + ` is omitted or null, a cryptographically random\npassword is generated (OIDC-style crypto/rand + base64url)\nand returned once in the response body. Any provided value,\nincluding empty string, is policy-checked. Tenant provisioning\nfollows the shared auth.default_tenant_mode policy.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "System Admin" + ], + "summary": "Create a new user (SystemAdmin)", + "parameters": [ + { + "description": "User creation request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest" + } + } + ], + "responses": { + "200": { + "description": "Identity already exists, returns the existing user", + "schema": { + "$ref": "#/definitions/internal_handler.CreateSystemUserResponse" + } + }, + "201": { + "description": "User created successfully", + "schema": { + "$ref": "#/definitions/internal_handler.CreateSystemUserResponse" + } + }, + "400": { + "description": "Invalid request or weak password", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "403": { + "description": "Forbidden: not a system admin", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "409": { + "description": "Email and username refer to conflicting identities", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal error", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/system/admin/users/reset-password": { "post": { "description": "Replace another user's local password and revoke all of their existing sessions (SystemAdmin only).\nA system administrator cannot reset their own password through this endpoint; self-service password change still requires the old password.", @@ -15713,6 +16780,26 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest": { + "type": "object", + "required": [ + "email", + "username" + ], + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + }, + "username": { + "type": "string", + "maxLength": 50, + "minLength": 2 + } + } + }, "github_com_Tencent_WeKnora_internal_types.AgentStep": { "type": "object", "properties": { @@ -15775,6 +16862,7 @@ const docTemplate = `{ "system.admin_promoted", "system.admin_revoked", "system.user_password_reset", + "system.user_created", "system.api_key_created", "system.api_key_revoked", "system.queue_task_retried", @@ -15838,6 +16926,7 @@ const docTemplate = `{ "AuditActionSystemAdminPromoted", "AuditActionSystemAdminRevoked", "AuditActionSystemUserPasswordReset", + "AuditActionSystemUserCreated", "AuditActionSystemAPIKeyCreated", "AuditActionSystemAPIKeyRevoked", "AuditActionSystemQueueTaskRetried", @@ -16392,6 +17481,10 @@ const docTemplate = `{ "type": "string" } }, + "memory_enabled": { + "description": "Whether this agent may read the user's long-term memory. Nil inherits\nthe workspace setting; false opts a single agent out of memory even when\nthe workspace has it on. There is no \"on\" that overrides the workspace.", + "type": "boolean" + }, "model_id": { "description": "===== Model Settings =====\nModel ID to use for conversations", "type": "string" @@ -16617,8 +17710,44 @@ const docTemplate = `{ "github_com_Tencent_WeKnora_internal_types.DockerSandboxConfig": { "type": "object", "properties": { + "cpu_limit": { + "description": "CPULimit is the number of CPU cores one sandbox may use. 0 uses the\nbuilt-in default.", + "type": "number" + }, + "host": { + "description": "Host is the daemon endpoint in DOCKER_HOST form. Empty means the local\nunix socket.", + "type": "string" + }, + "http_timeout_sec": { + "description": "HTTPTimeoutSec bounds each Engine API call. 0 uses the built-in default.", + "type": "integer" + }, + "idle_ttl_seconds": { + "description": "IdleTTLSeconds is how long a session container may go unused before it\nis reclaimed. The daemon has no idle timeout of its own, so this is what\nstops an abandoned session from pinning host memory indefinitely.", + "type": "integer" + }, "image": { "type": "string" + }, + "memory_limit_mb": { + "description": "MemoryLimitMB caps one sandbox's memory. 0 uses the built-in default.", + "type": "integer" + }, + "network_mode": { + "description": "NetworkMode is the Docker network sandboxes join: \"bridge\" (default) or\n\"none\" for no egress. Nothing else is accepted — host and container:\nmodes share another namespace outright, and a named network is usually\nthe deployment's own compose network, which would put the sandbox next\nto Postgres and Redis.", + "type": "string" + }, + "pids_limit": { + "description": "PidsLimit caps how many processes one sandbox may run. 0 uses the\nbuilt-in default.", + "type": "integer" + }, + "runtime": { + "description": "Runtime selects an alternative OCI runtime such as \"runsc\" (gVisor).\nEmpty uses the daemon default.", + "type": "string" + }, + "tls_cert_path": { + "description": "TLSCertPath is a directory on the WeKnora host containing ca.pem,\ncert.pem and key.pem. Required when Host is a TCP endpoint.", + "type": "string" } } }, @@ -17163,147 +18292,6 @@ const docTemplate = `{ } } }, - "github_com_Tencent_WeKnora_internal_types.Knowledge": { - "type": "object", - "properties": { - "channel": { - "description": "Channel indicates through which channel the knowledge was ingested (web, api, browser_extension, wechat, etc.)", - "type": "string" - }, - "created_at": { - "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": [ - { - "$ref": "#/definitions/gorm.DeletedAt" - } - ] - }, - "description": { - "description": "Description of the knowledge", - "type": "string" - }, - "embedding_model_id": { - "description": "ID of the embedding model", - "type": "string" - }, - "enable_status": { - "description": "Enable status of the knowledge", - "type": "string" - }, - "error_message": { - "description": "Error message of the knowledge", - "type": "string" - }, - "file_hash": { - "description": "File hash of the knowledge", - "type": "string" - }, - "file_name": { - "description": "File name of the knowledge", - "type": "string" - }, - "file_path": { - "description": "File path of the knowledge", - "type": "string" - }, - "file_size": { - "description": "File size of the knowledge", - "type": "integer" - }, - "file_type": { - "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" - }, - "knowledge_base_id": { - "description": "ID of the knowledge base", - "type": "string" - }, - "knowledge_base_name": { - "description": "Knowledge base name (not stored in database, populated on query)", - "type": "string" - }, - "last_faq_import_result": { - "description": "Last FAQ import result (for FAQ type knowledge only)", - "type": "array", - "items": { - "type": "integer" - } - }, - "metadata": { - "description": "Metadata of the knowledge", - "type": "array", - "items": { - "type": "integer" - } - }, - "parse_status": { - "description": "Parse status of the knowledge", - "type": "string" - }, - "pending_subtasks_count": { - "description": "PendingSubtasksCount is the outstanding enrichment subtask count\n(summary + question + graph chunks). Only meaningful while\nParseStatus == \"finalizing\"; defaults to 0 in any terminal state.", - "type": "integer" - }, - "processed_at": { - "description": "Processed time of the knowledge", - "type": "string" - }, - "source": { - "description": "Source of the knowledge (e.g. URL address for url type, \"manual\" for manual type)", - "type": "string" - }, - "storage_size": { - "description": "Storage size of the knowledge", - "type": "integer" - }, - "summary_status": { - "description": "Summary status for async summary generation", - "type": "string" - }, - "tags": { - "description": "Tags holds the tags associated with this knowledge (populated on query, not persisted directly).", - "type": "array", - "items": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.KnowledgeTag" - } - }, - "tenant_id": { - "description": "Workspace ID", - "type": "integer" - }, - "title": { - "description": "Title of the knowledge", - "type": "string" - }, - "type": { - "description": "Type of the knowledge", - "type": "string" - }, - "updated_at": { - "description": "Last updated time of the knowledge", - "type": "string" - } - } - }, "github_com_Tencent_WeKnora_internal_types.KnowledgeBase": { "type": "object", "properties": { @@ -17694,47 +18682,6 @@ const docTemplate = `{ } } }, - "github_com_Tencent_WeKnora_internal_types.KnowledgeTag": { - "type": "object", - "properties": { - "color": { - "description": "Optional display color", - "type": "string" - }, - "created_at": { - "description": "Creation time", - "type": "string" - }, - "id": { - "description": "Unique identifier of the tag (UUID)", - "type": "string" - }, - "knowledge_base_id": { - "description": "Knowledge base ID that this tag belongs to", - "type": "string" - }, - "name": { - "description": "Tag name, unique within the same knowledge base", - "type": "string" - }, - "seq_id": { - "description": "SeqID is an auto-increment integer ID for external API usage", - "type": "integer" - }, - "sort_order": { - "description": "Sort order within the same knowledge base", - "type": "integer" - }, - "tenant_id": { - "description": "Workspace ID", - "type": "integer" - }, - "updated_at": { - "description": "Last updated time", - "type": "string" - } - } - }, "github_com_Tencent_WeKnora_internal_types.ListMembersResponse": { "type": "object", "properties": { @@ -18118,6 +19065,55 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.MemoryConfig": { + "type": "object", + "properties": { + "embedding_model_id": { + "description": "EmbeddingModelID is the single model used to score memory against a\nquestion. It is pinned per workspace: knowledge bases each have their\nown embedding model, and grabbing whichever one happens to be listed\nfirst would mix incomparable vector spaces. Blank means semantic recall\nis off and matching stays lexical.", + "type": "string" + }, + "enabled": { + "description": "Enabled defaults to false. Memory retains user statements across\nsessions, so a workspace admin has to turn it on deliberately.", + "type": "boolean" + }, + "extract_delay_seconds": { + "description": "ExtractDelaySeconds is how long a finished turn waits before\ndistillation runs. Waiting lets one model call cover the several\nmessages a user usually sends in a row. 0 means the default.", + "type": "integer" + }, + "extract_instructions": { + "description": "ExtractInstructions are workspace-specific rules appended to the\ndistillation prompt, for policies the product cannot guess (\"never record\ncustomer names\", \"always note the environment a question is about\").", + "type": "string" + }, + "extract_min_interval_seconds": { + "description": "ExtractMinIntervalSeconds is the floor between two distillation runs for\nthe same person, and exists purely to bound cost. It never drops a turn:\na turn arriving inside the interval is queued and picked up by the next\nrun. 0 means the default.", + "type": "integer" + }, + "extract_model_id": { + "description": "ExtractModelID is the model used by the background extraction task.\nEmpty means \"use the model the conversation itself used\", which is what\nthe settings UI promises, so the extraction task must never fail merely\nbecause this is blank.", + "type": "string" + }, + "interest_threshold": { + "description": "InterestThreshold is how many separate conversations must touch a topic\nbefore it becomes a stored interest. 0 means the default. Setting it to 1\nrecords every topic on first sight, which is usually too noisy.", + "type": "integer" + }, + "max_items": { + "description": "MaxItems caps active items per subject. 0 means DefaultMemoryMaxItems.", + "type": "integer" + }, + "retrieval_conditioning": { + "description": "RetrievalConditioning lets memory shape retrieval — query rewriting and\nper-document ranking — rather than only being appended to the answer\nprompt. This is where memory earns its keep in a knowledge-base product.", + "type": "boolean" + }, + "vector_recall": { + "description": "VectorRecall adds semantic similarity to memory recall. Nil means on\nwhen an embedding model is reachable.\n\nLexical matching alone cannot find a memory the user has re-worded, which\nis most of them: \"回答直接给结论\" and \"别铺垫那么多\" share no tokens. The\ncost is one embedding call per turn, bounded and degraded to lexical on\nfailure, so the feature never becomes a reason a chat is slow.", + "type": "boolean" + }, + "write_mode": { + "description": "WriteMode is MemoryWriteExplicitOnly or MemoryWriteAuto.", + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.MentionedItem": { "type": "object", "properties": { @@ -18261,6 +19257,21 @@ const docTemplate = `{ "updated_at": { "description": "Last update timestamp", "type": "string" + }, + "usage": { + "description": "LLM token usage aggregated across every round of the turn that produced this\nassistant message. Persisted so history reads can attribute cost after the\nlive stream is gone; NULL (nil) for user messages and pre-feature rows.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.TokenUsage" + } + ] + }, + "used_memories": { + "description": "UsedMemories records which long-term memories were injected into this\nanswer, so the chat UI can show them and let the user delete one on the\nspot. Persisted rather than only streamed so reopening a conversation\nstill explains what the answer saw.", + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UsedMemory" + } } } }, @@ -18884,6 +19895,21 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.PromptCacheStatus": { + "type": "string", + "enum": [ + "unsupported", + "unreported", + "miss", + "hit" + ], + "x-enum-varnames": [ + "PromptCacheStatusUnsupported", + "PromptCacheStatusUnreported", + "PromptCacheStatusMiss", + "PromptCacheStatusHit" + ] + }, "github_com_Tencent_WeKnora_internal_types.QuestionGenerationConfig": { "type": "object", "properties": { @@ -19691,6 +20717,31 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.SkillImageConfig": { + "type": "object", + "properties": { + "base_template_id": { + "description": "BaseTemplateID is the template this chain was originally built from;\nthe rebuild path starts over from it.", + "type": "string" + }, + "built_at": { + "description": "BuiltAt records when this generation was produced.", + "type": "string" + }, + "generation": { + "description": "Generation increments on every successful install/remove, for naming\nand troubleshooting.", + "type": "integer" + }, + "owner_fingerprint": { + "description": "OwnerFingerprint identifies the provider account that owns the snapshot.\nSnapshots are invisible across accounts, so a mismatch means \"fall back\nto the base template\" rather than \"fail\".", + "type": "string" + }, + "snapshot_id": { + "description": "SnapshotID is the currently effective snapshot; empty = base template.", + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.StarterSuggestionConfig": { "type": "object", "properties": { @@ -20090,6 +21141,14 @@ const docTemplate = `{ "description": "ID", "type": "integer" }, + "memory_config": { + "description": "Memory config: workspace switch for cross-session long-term memory", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.MemoryConfig" + } + ] + }, "name": { "description": "Name", "type": "string" @@ -20198,6 +21257,18 @@ const docTemplate = `{ "description": "SandboxType selects the sandbox backend. Named configs may use \"cube\",\n\"e2b\", \"docker\", or \"local\". \"disabled\" is reserved for the hidden\nworkspace policy row.", "type": "string" }, + "skill_image": { + "description": "SkillImage points at the snapshot that carries this config's installed\nskills. Empty means \"use the base template\". Written only by the skill\ninstall/remove path: MergeSandboxConfigForUpdate ignores client values\nso a settings-form save cannot wipe or plant the pointer.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.SkillImageConfig" + } + ] + }, + "skill_rollout": { + "description": "SkillRollout decides whether sessions that already hold a sandbox of\nthis config rebuild after a skill install or removal. Empty and\nSkillRolloutNextTurn rebuild on the next chat turn. SkillRolloutNewSession\nleaves those sandboxes on the previous image; only sessions that start\nafterwards boot the new snapshot.", + "type": "string" + }, "volume_mount": { "description": "VolumeMount configures an optional shared volume mounted into every\nsandbox created for this tenant. Currently used for tenant-installed\nskills, but the configuration itself is skill-agnostic and can serve\nany volume-mount use case (shared datasets, pre-installed toolchains,\netc.).", "allOf": [ @@ -20208,6 +21279,39 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.TokenUsage": { + "type": "object", + "properties": { + "cache_miss_tokens": { + "type": "integer" + }, + "cache_read_tokens": { + "type": "integer" + }, + "cache_reported": { + "type": "boolean" + }, + "cache_status": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PromptCacheStatus" + }, + "cache_write_tokens": { + "type": "integer" + }, + "cached_tokens": { + "description": "CachedTokens is the legacy alias for CacheReadTokens. It remains on the\nwire for compatibility with existing API consumers.", + "type": "integer" + }, + "completion_tokens": { + "type": "integer" + }, + "prompt_tokens": { + "type": "integer" + }, + "total_tokens": { + "type": "integer" + } + } + }, "github_com_Tencent_WeKnora_internal_types.ToolCall": { "type": "object", "properties": { @@ -20344,6 +21448,20 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.UsedMemory": { + "type": "object", + "properties": { + "content": { + "type": "string" + }, + "id": { + "type": "string" + }, + "kind": { + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.User": { "type": "object", "properties": { @@ -20922,6 +22040,10 @@ const docTemplate = `{ "description": "populated in ego mode", "type": "integer" }, + "familiar_count": { + "description": "FamiliarCount is how many returned nodes are lit up for this person.", + "type": "integer" + }, "mode": { "type": "string" }, @@ -20942,6 +22064,10 @@ const docTemplate = `{ "github_com_Tencent_WeKnora_internal_types.WikiGraphNode": { "type": "object", "properties": { + "familiar": { + "description": "Familiar is true when this page was built from a document this person\nkeeps citing in answers. It is a personal overlay, not a property of\nthe page: two people looking at the same wiki see different highlights.", + "type": "boolean" + }, "link_count": { "description": "Number of inbound + outbound links", "type": "integer" @@ -21535,6 +22661,18 @@ const docTemplate = `{ } } }, + "internal_handler.CreateSystemUserResponse": { + "type": "object", + "properties": { + "generated_password": { + "description": "GeneratedPassword is the plaintext password when the server\nauto-generated one. Absent when the caller supplied the password.", + "type": "string" + }, + "user": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo" + } + } + }, "internal_handler.DeleteTagRequest": { "type": "object", "properties": { @@ -22760,6 +23898,23 @@ const docTemplate = `{ } } }, + "internal_handler.UpdateKnowledgeRequest": { + "type": "object", + "properties": { + "custom_metadata": { + "type": "array", + "items": { + "type": "integer" + } + }, + "description": { + "type": "string" + }, + "title": { + "type": "string" + } + } + }, "internal_handler.UpdateModelRequest": { "type": "object", "properties": { @@ -23075,6 +24230,24 @@ const docTemplate = `{ } } }, + "internal_handler.skillPatchRequest": { + "type": "object", + "properties": { + "enabled": { + "description": "Enabled is a pointer because its absence is a bad request rather than a\nrequest to disable the skill.", + "type": "boolean" + } + } + }, + "internal_handler.skillSourceRequest": { + "type": "object", + "properties": { + "source": { + "description": "Source is a ClawHub/SkillHub slug or page URL, a skills.sh / GitHub /\nGitLab locator, or a direct zip/SKILL.md URL. It must be readable\nanonymously: the fetch carries no credential of any kind.", + "type": "string" + } + } + }, "internal_handler.storageBackendRequest": { "type": "object", "required": [ diff --git a/docs/swagger.json b/docs/swagger.json index 7e83a153..fd115ee3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -6115,6 +6115,66 @@ } } }, + "/knowledge-search": { + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "在知识库中搜索(不使用LLM总结)", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "问答" + ], + "summary": "知识搜索", + "parameters": [ + { + "description": "搜索请求", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler_session.SearchKnowledgeRequest" + } + }, + { + "enum": [ + "handle", + "public" + ], + "type": "string", + "default": "handle", + "description": "文件引用形式,public 返回可加载直链", + "name": "resource_urls", + "in": "query" + } + ], + "responses": { + "200": { + "description": "搜索结果", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/knowledge/batch": { "get": { "security": [ @@ -6587,14 +6647,17 @@ "in": "query" }, { + "minimum": 0, "type": "integer", - "description": "Offset for pagination", + "description": "Offset for pagination (minimum 0)", "name": "offset", "in": "query" }, { + "maximum": 100, + "minimum": 1, "type": "integer", - "description": "Limit for pagination (default 20)", + "description": "Limit for pagination (default 20, maximum 100)", "name": "limit", "in": "query" }, @@ -6744,7 +6807,7 @@ "ApiKeyAuth": [] } ], - "description": "更新知识条目信息", + "description": "部分更新知识条目(标题/描述/自定义元数据);未传字段保持不变,显式传空 description 可清空摘要", "consumes": [ "application/json" ], @@ -6764,12 +6827,12 @@ "required": true }, { - "description": "知识信息", + "description": "更新字段(均可选)", "name": "request", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Knowledge" + "$ref": "#/definitions/internal_handler.UpdateKnowledgeRequest" } } ], @@ -9044,6 +9107,574 @@ } } }, + "/memory/consolidate": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "合并意思接近的条目、归档到期事项,不等待每日后台整理", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "立刻整理我的记忆", + "responses": { + "200": { + "description": "整理结果", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/documents": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回当前用户回答里反复引用的文档,次数未达习惯门槛的不展示", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出常用资料", + "parameters": [ + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "文档列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/documents/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除一条文档亲和度计数,之后检索不再因为这份文档而加权", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "停止用某份文档做个性化检索", + "parameters": [ + { + "type": "string", + "description": "亲和度 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/export": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "以 JSON 导出当前用户的全部记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "导出我的记忆", + "responses": { + "200": { + "description": "记忆导出", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "分页返回当前用户的记忆条目,可按状态过滤", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出我的记忆", + "parameters": [ + { + "enum": [ + "active", + "superseded", + "archived", + "pending" + ], + "type": "string", + "description": "状态过滤", + "name": "status", + "in": "query" + }, + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "记忆列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "手动添加一条长期记忆", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "新增一条记忆", + "parameters": [ + { + "description": "记忆内容", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "新增的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "永久删除当前用户的全部记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "清空我的记忆", + "responses": { + "200": { + "description": "清空成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}": { + "put": { + "security": [ + { + "Bearer": [] + } + ], + "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": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "更新后的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "永久删除一条记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "删除一条记忆", + "parameters": [ + { + "type": "string", + "description": "记忆ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}/confirm": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "接受系统推断的记忆,使其开始生效", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "确认一条推断出的记忆", + "parameters": [ + { + "type": "string", + "description": "记忆 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "确认成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/items/{id}/reject": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "拒绝系统推断的记忆,并记住这次拒绝", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "否决一条推断出的记忆", + "parameters": [ + { + "type": "string", + "description": "记忆 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "否决成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/settings": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回合并后的记忆开关状态(空间级 + 个人级)与记忆条数", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "获取我的记忆设置", + "responses": { + "200": { + "description": "记忆设置", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "开启或关闭当前用户自己的长期记忆", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "更新我的记忆设置", + "parameters": [ + { + "description": "设置", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "更新后的设置", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "返回已计数、尚未提升为长期关注的主题,以及距离阈值还差几次", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "列出正在观察的主题", + "parameters": [ + { + "type": "integer", + "default": 50, + "description": "每页条数", + "name": "limit", + "in": "query" + }, + { + "type": "integer", + "description": "偏移量", + "name": "offset", + "in": "query" + } + ], + "responses": { + "200": { + "description": "主题列表", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "删除尚未提升的主题计数,并记住这次拒绝,之后不会再自动记为长期关注", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "停止跟踪一个主题", + "parameters": [ + { + "type": "string", + "description": "主题 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/memory/topics/{id}/promote": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "不等待剩余次数,把正在观察的主题提升为一条长期关注记忆", + "produces": [ + "application/json" + ], + "tags": [ + "长期记忆" + ], + "summary": "立即记为长期关注", + "parameters": [ + { + "type": "string", + "description": "主题 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "新增的记忆", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/messages/chat-history-stats": { "get": { "security": [ @@ -10935,6 +11566,432 @@ } } }, + "/sandbox-configs/{id}/skills": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "List the agent skills installed onto one sandbox config's image.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "List installed skills", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Installed skills", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Sandbox config not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Install a skill onto this sandbox config's image. Send a zip\nas multipart form field \"file\", or JSON {\"source\":\"...\"} to\npull from ClawHub, SkillHub, skills.sh, GitHub, GitLab, or a\ndirect archive URL. The source must be readable anonymously.\nThe install boots a sandbox and runs for minutes, so the\nrequest is only accepted; follow it via the install-events\nstream.", + "consumes": [ + "application/json", + "multipart/form-data" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Install a skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "file", + "description": "Skill bundle (zip)", + "name": "file", + "in": "formData" + }, + { + "description": "Install from a registry, git host, or archive URL", + "name": "request", + "in": "body", + "schema": { + "$ref": "#/definitions/internal_handler.skillSourceRequest" + } + } + ], + "responses": { + "202": { + "description": "Install accepted", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Missing, oversized or invalid bundle or source", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Sandbox config not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Retrieve one installed skill of a sandbox config.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Get an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Installed skill", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "delete": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Remove a skill from the config's image. The removal rebuilds\nthe image and runs for minutes, so it is only accepted; follow\nit via the install-events stream.", + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Remove an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "202": { + "description": "Removal accepted", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + }, + "patch": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Show or hide an installed skill. The files stay in the image either way; removal is a separate flow.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Update an installed skill", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + }, + { + "description": "Fields to update", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.skillPatchRequest" + } + } + ], + "responses": { + "200": { + "description": "Updated skill", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "Invalid request", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}/install-events": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Server-sent progress for one install or removal. The stream\nalways terminates: with the run's own terminal event, with one\nderived from the durable status, or with a \"detached\" frame\nwhen it stops following a run that is still going.", + "produces": [ + "text/event-stream" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Follow an install or removal", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "SSE stream of progress events", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/sandbox-configs/{id}/skills/{skillId}/transcript": { + "get": { + "security": [ + { + "Bearer": [] + }, + { + "ApiKeyAuth": [] + } + ], + "description": "Server-sent replay of everything the installer agent did — the\nprompt it was given, its thinking, the commands it ran and\ntheir output — followed live while the install is still\nrunning. Frames are the same shape the chat stream uses, so a\nconsole renders an install with the components it renders a\nchat turn with. 404 once the event log has expired; the\ndurable message history is the fallback.", + "produces": [ + "text/event-stream" + ], + "tags": [ + "SandboxConfig" + ], + "summary": "Follow an install's agent transcript", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Skill ID", + "name": "skillId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "SSE stream of transcript events", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "Skill or transcript not found", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/sessions": { "get": { "security": [ @@ -11166,66 +12223,6 @@ } } }, - "/knowledge-search": { - "post": { - "security": [ - { - "Bearer": [] - }, - { - "ApiKeyAuth": [] - } - ], - "description": "在知识库中搜索(不使用LLM总结)", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "问答" - ], - "summary": "知识搜索", - "parameters": [ - { - "description": "搜索请求", - "name": "request", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/internal_handler_session.SearchKnowledgeRequest" - } - }, - { - "enum": [ - "handle", - "public" - ], - "type": "string", - "default": "handle", - "description": "文件引用形式,public 返回可加载直链", - "name": "resource_urls", - "in": "query" - } - ], - "responses": { - "200": { - "description": "搜索结果", - "schema": { - "type": "object", - "additionalProperties": true - } - }, - "400": { - "description": "请求参数错误", - "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" - } - } - } - } - }, "/sessions/{id}": { "get": { "security": [ @@ -11895,7 +12892,7 @@ "ApiKeyAuth": [] } ], - "description": "获取所有预装的Agent Skills元数据", + "description": "返回指定沙盒配置镜像内、智能体实际能调用的已安装技能(ready 且启用)。不传 sandbox_config_id 时列表为空。", "consumes": [ "application/json" ], @@ -11905,7 +12902,15 @@ "tags": [ "Skills" ], - "summary": "获取预装Skills列表", + "summary": "获取当前沙盒配置上可执行的 Skills", + "parameters": [ + { + "type": "string", + "description": "Sandbox config ID", + "name": "sandbox_config_id", + "in": "query" + } + ], "responses": { "200": { "description": "Skills列表", @@ -11913,12 +12918,6 @@ "type": "object", "additionalProperties": true } - }, - "500": { - "description": "服务器错误", - "schema": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" - } } } } @@ -13021,6 +14020,74 @@ } } }, + "/system/admin/users/create": { + "post": { + "description": "Provision a new local user account (SystemAdmin only).\nWhen `password` is omitted or null, a cryptographically random\npassword is generated (OIDC-style crypto/rand + base64url)\nand returned once in the response body. Any provided value,\nincluding empty string, is policy-checked. Tenant provisioning\nfollows the shared auth.default_tenant_mode policy.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "System Admin" + ], + "summary": "Create a new user (SystemAdmin)", + "parameters": [ + { + "description": "User creation request", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest" + } + } + ], + "responses": { + "200": { + "description": "Identity already exists, returns the existing user", + "schema": { + "$ref": "#/definitions/internal_handler.CreateSystemUserResponse" + } + }, + "201": { + "description": "User created successfully", + "schema": { + "$ref": "#/definitions/internal_handler.CreateSystemUserResponse" + } + }, + "400": { + "description": "Invalid request or weak password", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "403": { + "description": "Forbidden: not a system admin", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "409": { + "description": "Email and username refer to conflicting identities", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "500": { + "description": "Internal error", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/system/admin/users/reset-password": { "post": { "description": "Replace another user's local password and revoke all of their existing sessions (SystemAdmin only).\nA system administrator cannot reset their own password through this endpoint; self-service password change still requires the old password.", @@ -15706,6 +16773,26 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest": { + "type": "object", + "required": [ + "email", + "username" + ], + "properties": { + "email": { + "type": "string" + }, + "password": { + "type": "string" + }, + "username": { + "type": "string", + "maxLength": 50, + "minLength": 2 + } + } + }, "github_com_Tencent_WeKnora_internal_types.AgentStep": { "type": "object", "properties": { @@ -15768,6 +16855,7 @@ "system.admin_promoted", "system.admin_revoked", "system.user_password_reset", + "system.user_created", "system.api_key_created", "system.api_key_revoked", "system.queue_task_retried", @@ -15831,6 +16919,7 @@ "AuditActionSystemAdminPromoted", "AuditActionSystemAdminRevoked", "AuditActionSystemUserPasswordReset", + "AuditActionSystemUserCreated", "AuditActionSystemAPIKeyCreated", "AuditActionSystemAPIKeyRevoked", "AuditActionSystemQueueTaskRetried", @@ -16385,6 +17474,10 @@ "type": "string" } }, + "memory_enabled": { + "description": "Whether this agent may read the user's long-term memory. Nil inherits\nthe workspace setting; false opts a single agent out of memory even when\nthe workspace has it on. There is no \"on\" that overrides the workspace.", + "type": "boolean" + }, "model_id": { "description": "===== Model Settings =====\nModel ID to use for conversations", "type": "string" @@ -16610,8 +17703,44 @@ "github_com_Tencent_WeKnora_internal_types.DockerSandboxConfig": { "type": "object", "properties": { + "cpu_limit": { + "description": "CPULimit is the number of CPU cores one sandbox may use. 0 uses the\nbuilt-in default.", + "type": "number" + }, + "host": { + "description": "Host is the daemon endpoint in DOCKER_HOST form. Empty means the local\nunix socket.", + "type": "string" + }, + "http_timeout_sec": { + "description": "HTTPTimeoutSec bounds each Engine API call. 0 uses the built-in default.", + "type": "integer" + }, + "idle_ttl_seconds": { + "description": "IdleTTLSeconds is how long a session container may go unused before it\nis reclaimed. The daemon has no idle timeout of its own, so this is what\nstops an abandoned session from pinning host memory indefinitely.", + "type": "integer" + }, "image": { "type": "string" + }, + "memory_limit_mb": { + "description": "MemoryLimitMB caps one sandbox's memory. 0 uses the built-in default.", + "type": "integer" + }, + "network_mode": { + "description": "NetworkMode is the Docker network sandboxes join: \"bridge\" (default) or\n\"none\" for no egress. Nothing else is accepted — host and container:\nmodes share another namespace outright, and a named network is usually\nthe deployment's own compose network, which would put the sandbox next\nto Postgres and Redis.", + "type": "string" + }, + "pids_limit": { + "description": "PidsLimit caps how many processes one sandbox may run. 0 uses the\nbuilt-in default.", + "type": "integer" + }, + "runtime": { + "description": "Runtime selects an alternative OCI runtime such as \"runsc\" (gVisor).\nEmpty uses the daemon default.", + "type": "string" + }, + "tls_cert_path": { + "description": "TLSCertPath is a directory on the WeKnora host containing ca.pem,\ncert.pem and key.pem. Required when Host is a TCP endpoint.", + "type": "string" } } }, @@ -17156,147 +18285,6 @@ } } }, - "github_com_Tencent_WeKnora_internal_types.Knowledge": { - "type": "object", - "properties": { - "channel": { - "description": "Channel indicates through which channel the knowledge was ingested (web, api, browser_extension, wechat, etc.)", - "type": "string" - }, - "created_at": { - "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": [ - { - "$ref": "#/definitions/gorm.DeletedAt" - } - ] - }, - "description": { - "description": "Description of the knowledge", - "type": "string" - }, - "embedding_model_id": { - "description": "ID of the embedding model", - "type": "string" - }, - "enable_status": { - "description": "Enable status of the knowledge", - "type": "string" - }, - "error_message": { - "description": "Error message of the knowledge", - "type": "string" - }, - "file_hash": { - "description": "File hash of the knowledge", - "type": "string" - }, - "file_name": { - "description": "File name of the knowledge", - "type": "string" - }, - "file_path": { - "description": "File path of the knowledge", - "type": "string" - }, - "file_size": { - "description": "File size of the knowledge", - "type": "integer" - }, - "file_type": { - "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" - }, - "knowledge_base_id": { - "description": "ID of the knowledge base", - "type": "string" - }, - "knowledge_base_name": { - "description": "Knowledge base name (not stored in database, populated on query)", - "type": "string" - }, - "last_faq_import_result": { - "description": "Last FAQ import result (for FAQ type knowledge only)", - "type": "array", - "items": { - "type": "integer" - } - }, - "metadata": { - "description": "Metadata of the knowledge", - "type": "array", - "items": { - "type": "integer" - } - }, - "parse_status": { - "description": "Parse status of the knowledge", - "type": "string" - }, - "pending_subtasks_count": { - "description": "PendingSubtasksCount is the outstanding enrichment subtask count\n(summary + question + graph chunks). Only meaningful while\nParseStatus == \"finalizing\"; defaults to 0 in any terminal state.", - "type": "integer" - }, - "processed_at": { - "description": "Processed time of the knowledge", - "type": "string" - }, - "source": { - "description": "Source of the knowledge (e.g. URL address for url type, \"manual\" for manual type)", - "type": "string" - }, - "storage_size": { - "description": "Storage size of the knowledge", - "type": "integer" - }, - "summary_status": { - "description": "Summary status for async summary generation", - "type": "string" - }, - "tags": { - "description": "Tags holds the tags associated with this knowledge (populated on query, not persisted directly).", - "type": "array", - "items": { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.KnowledgeTag" - } - }, - "tenant_id": { - "description": "Workspace ID", - "type": "integer" - }, - "title": { - "description": "Title of the knowledge", - "type": "string" - }, - "type": { - "description": "Type of the knowledge", - "type": "string" - }, - "updated_at": { - "description": "Last updated time of the knowledge", - "type": "string" - } - } - }, "github_com_Tencent_WeKnora_internal_types.KnowledgeBase": { "type": "object", "properties": { @@ -17687,47 +18675,6 @@ } } }, - "github_com_Tencent_WeKnora_internal_types.KnowledgeTag": { - "type": "object", - "properties": { - "color": { - "description": "Optional display color", - "type": "string" - }, - "created_at": { - "description": "Creation time", - "type": "string" - }, - "id": { - "description": "Unique identifier of the tag (UUID)", - "type": "string" - }, - "knowledge_base_id": { - "description": "Knowledge base ID that this tag belongs to", - "type": "string" - }, - "name": { - "description": "Tag name, unique within the same knowledge base", - "type": "string" - }, - "seq_id": { - "description": "SeqID is an auto-increment integer ID for external API usage", - "type": "integer" - }, - "sort_order": { - "description": "Sort order within the same knowledge base", - "type": "integer" - }, - "tenant_id": { - "description": "Workspace ID", - "type": "integer" - }, - "updated_at": { - "description": "Last updated time", - "type": "string" - } - } - }, "github_com_Tencent_WeKnora_internal_types.ListMembersResponse": { "type": "object", "properties": { @@ -18111,6 +19058,55 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.MemoryConfig": { + "type": "object", + "properties": { + "embedding_model_id": { + "description": "EmbeddingModelID is the single model used to score memory against a\nquestion. It is pinned per workspace: knowledge bases each have their\nown embedding model, and grabbing whichever one happens to be listed\nfirst would mix incomparable vector spaces. Blank means semantic recall\nis off and matching stays lexical.", + "type": "string" + }, + "enabled": { + "description": "Enabled defaults to false. Memory retains user statements across\nsessions, so a workspace admin has to turn it on deliberately.", + "type": "boolean" + }, + "extract_delay_seconds": { + "description": "ExtractDelaySeconds is how long a finished turn waits before\ndistillation runs. Waiting lets one model call cover the several\nmessages a user usually sends in a row. 0 means the default.", + "type": "integer" + }, + "extract_instructions": { + "description": "ExtractInstructions are workspace-specific rules appended to the\ndistillation prompt, for policies the product cannot guess (\"never record\ncustomer names\", \"always note the environment a question is about\").", + "type": "string" + }, + "extract_min_interval_seconds": { + "description": "ExtractMinIntervalSeconds is the floor between two distillation runs for\nthe same person, and exists purely to bound cost. It never drops a turn:\na turn arriving inside the interval is queued and picked up by the next\nrun. 0 means the default.", + "type": "integer" + }, + "extract_model_id": { + "description": "ExtractModelID is the model used by the background extraction task.\nEmpty means \"use the model the conversation itself used\", which is what\nthe settings UI promises, so the extraction task must never fail merely\nbecause this is blank.", + "type": "string" + }, + "interest_threshold": { + "description": "InterestThreshold is how many separate conversations must touch a topic\nbefore it becomes a stored interest. 0 means the default. Setting it to 1\nrecords every topic on first sight, which is usually too noisy.", + "type": "integer" + }, + "max_items": { + "description": "MaxItems caps active items per subject. 0 means DefaultMemoryMaxItems.", + "type": "integer" + }, + "retrieval_conditioning": { + "description": "RetrievalConditioning lets memory shape retrieval — query rewriting and\nper-document ranking — rather than only being appended to the answer\nprompt. This is where memory earns its keep in a knowledge-base product.", + "type": "boolean" + }, + "vector_recall": { + "description": "VectorRecall adds semantic similarity to memory recall. Nil means on\nwhen an embedding model is reachable.\n\nLexical matching alone cannot find a memory the user has re-worded, which\nis most of them: \"回答直接给结论\" and \"别铺垫那么多\" share no tokens. The\ncost is one embedding call per turn, bounded and degraded to lexical on\nfailure, so the feature never becomes a reason a chat is slow.", + "type": "boolean" + }, + "write_mode": { + "description": "WriteMode is MemoryWriteExplicitOnly or MemoryWriteAuto.", + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.MentionedItem": { "type": "object", "properties": { @@ -18254,6 +19250,21 @@ "updated_at": { "description": "Last update timestamp", "type": "string" + }, + "usage": { + "description": "LLM token usage aggregated across every round of the turn that produced this\nassistant message. Persisted so history reads can attribute cost after the\nlive stream is gone; NULL (nil) for user messages and pre-feature rows.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.TokenUsage" + } + ] + }, + "used_memories": { + "description": "UsedMemories records which long-term memories were injected into this\nanswer, so the chat UI can show them and let the user delete one on the\nspot. Persisted rather than only streamed so reopening a conversation\nstill explains what the answer saw.", + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UsedMemory" + } } } }, @@ -18877,6 +19888,21 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.PromptCacheStatus": { + "type": "string", + "enum": [ + "unsupported", + "unreported", + "miss", + "hit" + ], + "x-enum-varnames": [ + "PromptCacheStatusUnsupported", + "PromptCacheStatusUnreported", + "PromptCacheStatusMiss", + "PromptCacheStatusHit" + ] + }, "github_com_Tencent_WeKnora_internal_types.QuestionGenerationConfig": { "type": "object", "properties": { @@ -19684,6 +20710,31 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.SkillImageConfig": { + "type": "object", + "properties": { + "base_template_id": { + "description": "BaseTemplateID is the template this chain was originally built from;\nthe rebuild path starts over from it.", + "type": "string" + }, + "built_at": { + "description": "BuiltAt records when this generation was produced.", + "type": "string" + }, + "generation": { + "description": "Generation increments on every successful install/remove, for naming\nand troubleshooting.", + "type": "integer" + }, + "owner_fingerprint": { + "description": "OwnerFingerprint identifies the provider account that owns the snapshot.\nSnapshots are invisible across accounts, so a mismatch means \"fall back\nto the base template\" rather than \"fail\".", + "type": "string" + }, + "snapshot_id": { + "description": "SnapshotID is the currently effective snapshot; empty = base template.", + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.StarterSuggestionConfig": { "type": "object", "properties": { @@ -20083,6 +21134,14 @@ "description": "ID", "type": "integer" }, + "memory_config": { + "description": "Memory config: workspace switch for cross-session long-term memory", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.MemoryConfig" + } + ] + }, "name": { "description": "Name", "type": "string" @@ -20191,6 +21250,18 @@ "description": "SandboxType selects the sandbox backend. Named configs may use \"cube\",\n\"e2b\", \"docker\", or \"local\". \"disabled\" is reserved for the hidden\nworkspace policy row.", "type": "string" }, + "skill_image": { + "description": "SkillImage points at the snapshot that carries this config's installed\nskills. Empty means \"use the base template\". Written only by the skill\ninstall/remove path: MergeSandboxConfigForUpdate ignores client values\nso a settings-form save cannot wipe or plant the pointer.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.SkillImageConfig" + } + ] + }, + "skill_rollout": { + "description": "SkillRollout decides whether sessions that already hold a sandbox of\nthis config rebuild after a skill install or removal. Empty and\nSkillRolloutNextTurn rebuild on the next chat turn. SkillRolloutNewSession\nleaves those sandboxes on the previous image; only sessions that start\nafterwards boot the new snapshot.", + "type": "string" + }, "volume_mount": { "description": "VolumeMount configures an optional shared volume mounted into every\nsandbox created for this tenant. Currently used for tenant-installed\nskills, but the configuration itself is skill-agnostic and can serve\nany volume-mount use case (shared datasets, pre-installed toolchains,\netc.).", "allOf": [ @@ -20201,6 +21272,39 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.TokenUsage": { + "type": "object", + "properties": { + "cache_miss_tokens": { + "type": "integer" + }, + "cache_read_tokens": { + "type": "integer" + }, + "cache_reported": { + "type": "boolean" + }, + "cache_status": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PromptCacheStatus" + }, + "cache_write_tokens": { + "type": "integer" + }, + "cached_tokens": { + "description": "CachedTokens is the legacy alias for CacheReadTokens. It remains on the\nwire for compatibility with existing API consumers.", + "type": "integer" + }, + "completion_tokens": { + "type": "integer" + }, + "prompt_tokens": { + "type": "integer" + }, + "total_tokens": { + "type": "integer" + } + } + }, "github_com_Tencent_WeKnora_internal_types.ToolCall": { "type": "object", "properties": { @@ -20337,6 +21441,20 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.UsedMemory": { + "type": "object", + "properties": { + "content": { + "type": "string" + }, + "id": { + "type": "string" + }, + "kind": { + "type": "string" + } + } + }, "github_com_Tencent_WeKnora_internal_types.User": { "type": "object", "properties": { @@ -20915,6 +22033,10 @@ "description": "populated in ego mode", "type": "integer" }, + "familiar_count": { + "description": "FamiliarCount is how many returned nodes are lit up for this person.", + "type": "integer" + }, "mode": { "type": "string" }, @@ -20935,6 +22057,10 @@ "github_com_Tencent_WeKnora_internal_types.WikiGraphNode": { "type": "object", "properties": { + "familiar": { + "description": "Familiar is true when this page was built from a document this person\nkeeps citing in answers. It is a personal overlay, not a property of\nthe page: two people looking at the same wiki see different highlights.", + "type": "boolean" + }, "link_count": { "description": "Number of inbound + outbound links", "type": "integer" @@ -21528,6 +22654,18 @@ } } }, + "internal_handler.CreateSystemUserResponse": { + "type": "object", + "properties": { + "generated_password": { + "description": "GeneratedPassword is the plaintext password when the server\nauto-generated one. Absent when the caller supplied the password.", + "type": "string" + }, + "user": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo" + } + } + }, "internal_handler.DeleteTagRequest": { "type": "object", "properties": { @@ -22753,6 +23891,23 @@ } } }, + "internal_handler.UpdateKnowledgeRequest": { + "type": "object", + "properties": { + "custom_metadata": { + "type": "array", + "items": { + "type": "integer" + } + }, + "description": { + "type": "string" + }, + "title": { + "type": "string" + } + } + }, "internal_handler.UpdateModelRequest": { "type": "object", "properties": { @@ -23068,6 +24223,24 @@ } } }, + "internal_handler.skillPatchRequest": { + "type": "object", + "properties": { + "enabled": { + "description": "Enabled is a pointer because its absence is a bad request rather than a\nrequest to disable the skill.", + "type": "boolean" + } + } + }, + "internal_handler.skillSourceRequest": { + "type": "object", + "properties": { + "source": { + "description": "Source is a ClawHub/SkillHub slug or page URL, a skills.sh / GitHub /\nGitLab locator, or a direct zip/SKILL.md URL. It must be readable\nanonymously: the fetch carries no credential of any kind.", + "type": "string" + } + } + }, "internal_handler.storageBackendRequest": { "type": "object", "required": [ @@ -23411,4 +24584,4 @@ "in": "header" } } -} +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 6ed28308..d8e4f45b 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -240,6 +240,20 @@ definitions: model_id: type: string type: object + github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest: + properties: + email: + type: string + password: + type: string + username: + maxLength: 50 + minLength: 2 + type: string + required: + - email + - username + type: object github_com_Tencent_WeKnora_internal_types.AgentStep: properties: iteration: @@ -294,6 +308,7 @@ definitions: - system.admin_promoted - system.admin_revoked - system.user_password_reset + - system.user_created - system.api_key_created - system.api_key_revoked - system.queue_task_retried @@ -357,6 +372,7 @@ definitions: - AuditActionSystemAdminPromoted - AuditActionSystemAdminRevoked - AuditActionSystemUserPasswordReset + - AuditActionSystemUserCreated - AuditActionSystemAPIKeyCreated - AuditActionSystemAPIKeyRevoked - AuditActionSystemQueueTaskRetried @@ -869,6 +885,12 @@ definitions: items: type: string type: array + memory_enabled: + description: |- + Whether this agent may read the user's long-term memory. Nil inherits + the workspace setting; false opts a single agent out of memory even when + the workspace has it on. There is no "on" that overrides the workspace. + type: boolean model_id: description: |- ===== Model Settings ===== @@ -1068,8 +1090,55 @@ definitions: type: object github_com_Tencent_WeKnora_internal_types.DockerSandboxConfig: properties: + cpu_limit: + description: |- + CPULimit is the number of CPU cores one sandbox may use. 0 uses the + built-in default. + type: number + host: + description: |- + Host is the daemon endpoint in DOCKER_HOST form. Empty means the local + unix socket. + type: string + http_timeout_sec: + description: HTTPTimeoutSec bounds each Engine API call. 0 uses the built-in + default. + type: integer + idle_ttl_seconds: + description: |- + IdleTTLSeconds is how long a session container may go unused before it + is reclaimed. The daemon has no idle timeout of its own, so this is what + stops an abandoned session from pinning host memory indefinitely. + type: integer image: type: string + memory_limit_mb: + description: MemoryLimitMB caps one sandbox's memory. 0 uses the built-in + default. + type: integer + network_mode: + description: |- + NetworkMode is the Docker network sandboxes join: "bridge" (default) or + "none" for no egress. Nothing else is accepted — host and container: + modes share another namespace outright, and a named network is usually + the deployment's own compose network, which would put the sandbox next + to Postgres and Redis. + type: string + pids_limit: + description: |- + PidsLimit caps how many processes one sandbox may run. 0 uses the + built-in default. + type: integer + runtime: + description: |- + Runtime selects an alternative OCI runtime such as "runsc" (gVisor). + Empty uses the daemon default. + type: string + tls_cert_path: + description: |- + TLSCertPath is a directory on the WeKnora host containing ca.pem, + cert.pem and key.pem. Required when Host is a TCP endpoint. + type: string type: object github_com_Tencent_WeKnora_internal_types.E2BSandboxConfig: properties: @@ -1464,121 +1533,6 @@ definitions: secret_key: type: string type: object - github_com_Tencent_WeKnora_internal_types.Knowledge: - properties: - channel: - description: Channel indicates through which channel the knowledge was ingested - (web, api, browser_extension, wechat, etc.) - type: string - 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' - description: Deletion time of the knowledge - description: - description: Description of the knowledge - type: string - embedding_model_id: - description: ID of the embedding model - type: string - enable_status: - description: Enable status of the knowledge - type: string - error_message: - description: Error message of the knowledge - type: string - file_hash: - description: File hash of the knowledge - type: string - file_name: - description: File name of the knowledge - type: string - file_path: - description: File path of the knowledge - type: string - file_size: - description: File size of the knowledge - type: integer - 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 - knowledge_base_id: - description: ID of the knowledge base - type: string - knowledge_base_name: - description: Knowledge base name (not stored in database, populated on query) - type: string - last_faq_import_result: - description: Last FAQ import result (for FAQ type knowledge only) - items: - type: integer - type: array - metadata: - description: Metadata of the knowledge - items: - type: integer - type: array - parse_status: - description: Parse status of the knowledge - type: string - pending_subtasks_count: - description: |- - PendingSubtasksCount is the outstanding enrichment subtask count - (summary + question + graph chunks). Only meaningful while - ParseStatus == "finalizing"; defaults to 0 in any terminal state. - type: integer - processed_at: - description: Processed time of the knowledge - type: string - source: - description: Source of the knowledge (e.g. URL address for url type, "manual" - for manual type) - type: string - storage_size: - description: Storage size of the knowledge - type: integer - summary_status: - description: Summary status for async summary generation - type: string - tags: - description: Tags holds the tags associated with this knowledge (populated - on query, not persisted directly). - items: - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.KnowledgeTag' - type: array - tenant_id: - description: Workspace ID - type: integer - title: - description: Title of the knowledge - type: string - type: - description: Type of the knowledge - type: string - updated_at: - description: Last updated time of the knowledge - type: string - type: object github_com_Tencent_WeKnora_internal_types.KnowledgeBase: properties: asr_config: @@ -1867,36 +1821,6 @@ definitions: vlm_config: $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.VLMConfig' type: object - github_com_Tencent_WeKnora_internal_types.KnowledgeTag: - properties: - color: - description: Optional display color - type: string - created_at: - description: Creation time - type: string - id: - description: Unique identifier of the tag (UUID) - type: string - knowledge_base_id: - description: Knowledge base ID that this tag belongs to - type: string - name: - description: Tag name, unique within the same knowledge base - type: string - seq_id: - description: SeqID is an auto-increment integer ID for external API usage - type: integer - sort_order: - description: Sort order within the same knowledge base - type: integer - tenant_id: - description: Workspace ID - type: integer - updated_at: - description: Last updated time - type: string - type: object github_com_Tencent_WeKnora_internal_types.ListMembersResponse: properties: members: @@ -2182,6 +2106,76 @@ definitions: tenant_name: type: string type: object + github_com_Tencent_WeKnora_internal_types.MemoryConfig: + properties: + embedding_model_id: + description: |- + EmbeddingModelID is the single model used to score memory against a + question. It is pinned per workspace: knowledge bases each have their + own embedding model, and grabbing whichever one happens to be listed + first would mix incomparable vector spaces. Blank means semantic recall + is off and matching stays lexical. + type: string + enabled: + description: |- + Enabled defaults to false. Memory retains user statements across + sessions, so a workspace admin has to turn it on deliberately. + type: boolean + extract_delay_seconds: + description: |- + ExtractDelaySeconds is how long a finished turn waits before + distillation runs. Waiting lets one model call cover the several + messages a user usually sends in a row. 0 means the default. + type: integer + extract_instructions: + description: |- + ExtractInstructions are workspace-specific rules appended to the + distillation prompt, for policies the product cannot guess ("never record + customer names", "always note the environment a question is about"). + type: string + extract_min_interval_seconds: + description: |- + ExtractMinIntervalSeconds is the floor between two distillation runs for + the same person, and exists purely to bound cost. It never drops a turn: + a turn arriving inside the interval is queued and picked up by the next + run. 0 means the default. + type: integer + extract_model_id: + description: |- + ExtractModelID is the model used by the background extraction task. + Empty means "use the model the conversation itself used", which is what + the settings UI promises, so the extraction task must never fail merely + because this is blank. + type: string + interest_threshold: + description: |- + InterestThreshold is how many separate conversations must touch a topic + before it becomes a stored interest. 0 means the default. Setting it to 1 + records every topic on first sight, which is usually too noisy. + type: integer + max_items: + description: MaxItems caps active items per subject. 0 means DefaultMemoryMaxItems. + type: integer + retrieval_conditioning: + description: |- + RetrievalConditioning lets memory shape retrieval — query rewriting and + per-document ranking — rather than only being appended to the answer + prompt. This is where memory earns its keep in a knowledge-base product. + type: boolean + vector_recall: + description: |- + VectorRecall adds semantic similarity to memory recall. Nil means on + when an embedding model is reachable. + + Lexical matching alone cannot find a memory the user has re-worded, which + is most of them: "回答直接给结论" and "别铺垫那么多" share no tokens. The + cost is one embedding call per turn, bounded and degraded to lexical on + failure, so the feature never becomes a reason a chat is slow. + type: boolean + write_mode: + description: WriteMode is MemoryWriteExplicitOnly or MemoryWriteAuto. + type: string + type: object github_com_Tencent_WeKnora_internal_types.MentionedItem: properties: id: @@ -2302,6 +2296,22 @@ definitions: updated_at: description: Last update timestamp type: string + usage: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.TokenUsage' + description: |- + LLM token usage aggregated across every round of the turn that produced this + assistant message. Persisted so history reads can attribute cost after the + live stream is gone; NULL (nil) for user messages and pre-feature rows. + used_memories: + description: |- + UsedMemories records which long-term memories were injected into this + answer, so the chat UI can show them and let the user delete one on the + spot. Persisted rather than only streamed so reopening a conversation + still explains what the answer saw. + items: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.UsedMemory' + type: array type: object github_com_Tencent_WeKnora_internal_types.MessageArtifact: properties: @@ -2779,6 +2789,18 @@ definitions: nil preserves the parser default; an explicit false disables the mode. type: boolean type: object + github_com_Tencent_WeKnora_internal_types.PromptCacheStatus: + enum: + - unsupported + - unreported + - miss + - hit + type: string + x-enum-varnames: + - PromptCacheStatusUnsupported + - PromptCacheStatusUnreported + - PromptCacheStatusMiss + - PromptCacheStatusHit github_com_Tencent_WeKnora_internal_types.QuestionGenerationConfig: properties: custom_instructions: @@ -3394,6 +3416,32 @@ definitions: - organization_id - permission type: object + github_com_Tencent_WeKnora_internal_types.SkillImageConfig: + properties: + base_template_id: + description: |- + BaseTemplateID is the template this chain was originally built from; + the rebuild path starts over from it. + type: string + built_at: + description: BuiltAt records when this generation was produced. + type: string + generation: + description: |- + Generation increments on every successful install/remove, for naming + and troubleshooting. + type: integer + owner_fingerprint: + description: |- + OwnerFingerprint identifies the provider account that owns the snapshot. + Snapshots are invisible across accounts, so a mismatch means "fall back + to the base template" rather than "fail". + type: string + snapshot_id: + description: SnapshotID is the currently effective snapshot; empty = base + template. + type: string + type: object github_com_Tencent_WeKnora_internal_types.StarterSuggestionConfig: properties: count: @@ -3690,6 +3738,11 @@ definitions: id: description: ID type: integer + memory_config: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.MemoryConfig' + description: 'Memory config: workspace switch for cross-session long-term + memory' name: description: Name type: string @@ -3775,6 +3828,22 @@ definitions: "e2b", "docker", or "local". "disabled" is reserved for the hidden workspace policy row. type: string + skill_image: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.SkillImageConfig' + description: |- + SkillImage points at the snapshot that carries this config's installed + skills. Empty means "use the base template". Written only by the skill + install/remove path: MergeSandboxConfigForUpdate ignores client values + so a settings-form save cannot wipe or plant the pointer. + skill_rollout: + description: |- + SkillRollout decides whether sessions that already hold a sandbox of + this config rebuild after a skill install or removal. Empty and + SkillRolloutNextTurn rebuild on the next chat turn. SkillRolloutNewSession + leaves those sandboxes on the previous image; only sessions that start + afterwards boot the new snapshot. + type: string volume_mount: allOf: - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.VolumeMountConfig' @@ -3785,6 +3854,30 @@ definitions: any volume-mount use case (shared datasets, pre-installed toolchains, etc.). type: object + github_com_Tencent_WeKnora_internal_types.TokenUsage: + properties: + cache_miss_tokens: + type: integer + cache_read_tokens: + type: integer + cache_reported: + type: boolean + cache_status: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.PromptCacheStatus' + cache_write_tokens: + type: integer + cached_tokens: + description: |- + CachedTokens is the legacy alias for CacheReadTokens. It remains on the + wire for compatibility with existing API consumers. + type: integer + completion_tokens: + type: integer + prompt_tokens: + type: integer + total_tokens: + type: integer + type: object github_com_Tencent_WeKnora_internal_types.ToolCall: properties: args: @@ -3878,6 +3971,15 @@ definitions: required: - permission type: object + github_com_Tencent_WeKnora_internal_types.UsedMemory: + properties: + content: + type: string + id: + type: string + kind: + type: string + type: object github_com_Tencent_WeKnora_internal_types.User: properties: avatar: @@ -4350,6 +4452,10 @@ definitions: depth: description: populated in ego mode type: integer + familiar_count: + description: FamiliarCount is how many returned nodes are lit up for this + person. + type: integer mode: type: string returned: @@ -4364,6 +4470,12 @@ definitions: type: object github_com_Tencent_WeKnora_internal_types.WikiGraphNode: properties: + familiar: + description: |- + Familiar is true when this page was built from a document this person + keeps citing in answers. It is a personal overlay, not a property of + the page: two people looking at the same wiki see different highlights. + type: boolean link_count: description: Number of inbound + outbound links type: integer @@ -4808,6 +4920,16 @@ definitions: - engine_type - name type: object + internal_handler.CreateSystemUserResponse: + properties: + generated_password: + description: |- + GeneratedPassword is the plaintext password when the server + auto-generated one. Absent when the caller supplied the password. + type: string + user: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo' + type: object internal_handler.DeleteTagRequest: properties: exclude_ids: @@ -5668,6 +5790,17 @@ definitions: required: - name type: object + internal_handler.UpdateKnowledgeRequest: + properties: + custom_metadata: + items: + type: integer + type: array + description: + type: string + title: + type: string + type: object internal_handler.UpdateModelRequest: properties: description: @@ -5878,6 +6011,23 @@ definitions: required: - name type: object + internal_handler.skillPatchRequest: + properties: + enabled: + description: |- + Enabled is a pointer because its absence is a bad request rather than a + request to disable the skill. + type: boolean + type: object + internal_handler.skillSourceRequest: + properties: + source: + description: |- + Source is a ClawHub/SkillHub slug or page URL, a skills.sh / GitHub / + GitLab locator, or a direct zip/SKILL.md URL. It must be readable + anonymously: the fetch carries no credential of any kind. + type: string + type: object internal_handler.storageBackendRequest: properties: config: @@ -10018,6 +10168,44 @@ paths: summary: 知识问答 tags: - 问答 + /knowledge-search: + post: + consumes: + - application/json + description: 在知识库中搜索(不使用LLM总结) + parameters: + - description: 搜索请求 + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler_session.SearchKnowledgeRequest' + - default: handle + description: 文件引用形式,public 返回可加载直链 + enum: + - handle + - public + in: query + name: resource_urls + 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: + - 问答 /knowledge/{id}: delete: consumes: @@ -10084,19 +10272,19 @@ paths: put: consumes: - application/json - description: 更新知识条目信息 + description: 部分更新知识条目(标题/描述/自定义元数据);未传字段保持不变,显式传空 description 可清空摘要 parameters: - description: 知识ID in: path name: id required: true type: string - - description: 知识信息 + - description: 更新字段(均可选) in: body name: request required: true schema: - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Knowledge' + $ref: '#/definitions/internal_handler.UpdateKnowledgeRequest' produces: - application/json responses: @@ -10537,12 +10725,15 @@ paths: in: query name: keyword type: string - - description: Offset for pagination + - description: Offset for pagination (minimum 0) in: query + minimum: 0 name: offset type: integer - - description: Limit for pagination (default 20) + - description: Limit for pagination (default 20, maximum 100) in: query + maximum: 100 + minimum: 1 name: limit type: integer - description: Comma-separated file extensions to filter (e.g., csv,xlsx) @@ -11894,6 +12085,365 @@ paths: summary: 获取我的待处理邀请数 tags: - 我的邀请 + /memory/consolidate: + post: + description: 合并意思接近的条目、归档到期事项,不等待每日后台整理 + produces: + - application/json + responses: + "200": + description: 整理结果 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 立刻整理我的记忆 + tags: + - 长期记忆 + /memory/documents: + get: + description: 返回当前用户回答里反复引用的文档,次数未达习惯门槛的不展示 + parameters: + - default: 50 + description: 每页条数 + in: query + name: limit + type: integer + - description: 偏移量 + in: query + name: offset + type: integer + produces: + - application/json + responses: + "200": + description: 文档列表 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 列出常用资料 + tags: + - 长期记忆 + /memory/documents/{id}: + delete: + description: 删除一条文档亲和度计数,之后检索不再因为这份文档而加权 + parameters: + - description: 亲和度 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 删除成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 停止用某份文档做个性化检索 + tags: + - 长期记忆 + /memory/export: + get: + description: 以 JSON 导出当前用户的全部记忆 + produces: + - application/json + responses: + "200": + description: 记忆导出 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 导出我的记忆 + tags: + - 长期记忆 + /memory/items: + delete: + description: 永久删除当前用户的全部记忆 + produces: + - application/json + responses: + "200": + description: 清空成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 清空我的记忆 + tags: + - 长期记忆 + get: + description: 分页返回当前用户的记忆条目,可按状态过滤 + parameters: + - description: 状态过滤 + enum: + - active + - superseded + - archived + - pending + in: query + name: status + type: string + - default: 50 + description: 每页条数 + in: query + name: limit + type: integer + - description: 偏移量 + in: query + name: offset + type: integer + produces: + - application/json + responses: + "200": + description: 记忆列表 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 列出我的记忆 + tags: + - 长期记忆 + post: + consumes: + - application/json + description: 手动添加一条长期记忆 + parameters: + - description: 记忆内容 + in: body + name: request + required: true + schema: + type: object + produces: + - application/json + responses: + "200": + description: 新增的记忆 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 新增一条记忆 + tags: + - 长期记忆 + /memory/items/{id}: + delete: + description: 永久删除一条记忆 + parameters: + - description: 记忆ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 删除成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + 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: + type: object + produces: + - application/json + responses: + "200": + description: 更新后的记忆 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 修改一条记忆 + tags: + - 长期记忆 + /memory/items/{id}/confirm: + post: + description: 接受系统推断的记忆,使其开始生效 + parameters: + - description: 记忆 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 确认成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 确认一条推断出的记忆 + tags: + - 长期记忆 + /memory/items/{id}/reject: + post: + description: 拒绝系统推断的记忆,并记住这次拒绝 + parameters: + - description: 记忆 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 否决成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 否决一条推断出的记忆 + tags: + - 长期记忆 + /memory/settings: + get: + description: 返回合并后的记忆开关状态(空间级 + 个人级)与记忆条数 + produces: + - application/json + responses: + "200": + description: 记忆设置 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 获取我的记忆设置 + tags: + - 长期记忆 + put: + consumes: + - application/json + description: 开启或关闭当前用户自己的长期记忆 + parameters: + - description: 设置 + in: body + name: request + required: true + schema: + type: object + produces: + - application/json + responses: + "200": + description: 更新后的设置 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 更新我的记忆设置 + tags: + - 长期记忆 + /memory/topics: + get: + description: 返回已计数、尚未提升为长期关注的主题,以及距离阈值还差几次 + parameters: + - default: 50 + description: 每页条数 + in: query + name: limit + type: integer + - description: 偏移量 + in: query + name: offset + type: integer + produces: + - application/json + responses: + "200": + description: 主题列表 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 列出正在观察的主题 + tags: + - 长期记忆 + /memory/topics/{id}: + delete: + description: 删除尚未提升的主题计数,并记住这次拒绝,之后不会再自动记为长期关注 + parameters: + - description: 主题 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 删除成功 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 停止跟踪一个主题 + tags: + - 长期记忆 + /memory/topics/{id}/promote: + post: + description: 不等待剩余次数,把正在观察的主题提升为一条长期关注记忆 + parameters: + - description: 主题 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 新增的记忆 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 立即记为长期关注 + tags: + - 长期记忆 /messages/{session_id}/{id}: delete: consumes: @@ -13092,6 +13642,300 @@ paths: summary: Inspect sandbox config inventory tags: - SandboxConfig + /sandbox-configs/{id}/skills: + get: + description: List the agent skills installed onto one sandbox config's image. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: Installed skills + schema: + additionalProperties: true + type: object + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Sandbox config not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: List installed skills + tags: + - SandboxConfig + post: + consumes: + - application/json + - multipart/form-data + description: |- + Install a skill onto this sandbox config's image. Send a zip + as multipart form field "file", or JSON {"source":"..."} to + pull from ClawHub, SkillHub, skills.sh, GitHub, GitLab, or a + direct archive URL. The source must be readable anonymously. + The install boots a sandbox and runs for minutes, so the + request is only accepted; follow it via the install-events + stream. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill bundle (zip) + in: formData + name: file + type: file + - description: Install from a registry, git host, or archive URL + in: body + name: request + schema: + $ref: '#/definitions/internal_handler.skillSourceRequest' + produces: + - application/json + responses: + "202": + description: Install accepted + schema: + additionalProperties: true + type: object + "400": + description: Missing, oversized or invalid bundle or source + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Sandbox config not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Install a skill + tags: + - SandboxConfig + /sandbox-configs/{id}/skills/{skillId}: + delete: + description: |- + Remove a skill from the config's image. The removal rebuilds + the image and runs for minutes, so it is only accepted; follow + it via the install-events stream. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill ID + in: path + name: skillId + required: true + type: string + produces: + - application/json + responses: + "202": + description: Removal accepted + schema: + additionalProperties: true + type: object + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Skill not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Remove an installed skill + tags: + - SandboxConfig + get: + description: Retrieve one installed skill of a sandbox config. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill ID + in: path + name: skillId + required: true + type: string + produces: + - application/json + responses: + "200": + description: Installed skill + schema: + additionalProperties: true + type: object + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Skill not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Get an installed skill + tags: + - SandboxConfig + patch: + consumes: + - application/json + description: Show or hide an installed skill. The files stay in the image either + way; removal is a separate flow. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill ID + in: path + name: skillId + required: true + type: string + - description: Fields to update + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler.skillPatchRequest' + produces: + - application/json + responses: + "200": + description: Updated skill + schema: + additionalProperties: true + type: object + "400": + description: Invalid request + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Skill not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Update an installed skill + tags: + - SandboxConfig + /sandbox-configs/{id}/skills/{skillId}/install-events: + get: + description: |- + Server-sent progress for one install or removal. The stream + always terminates: with the run's own terminal event, with one + derived from the durable status, or with a "detached" frame + when it stops following a run that is still going. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill ID + in: path + name: skillId + required: true + type: string + produces: + - text/event-stream + responses: + "200": + description: SSE stream of progress events + schema: + type: string + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Skill not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Follow an install or removal + tags: + - SandboxConfig + /sandbox-configs/{id}/skills/{skillId}/transcript: + get: + description: |- + Server-sent replay of everything the installer agent did — the + prompt it was given, its thinking, the commands it ran and + their output — followed live while the install is still + running. Frames are the same shape the chat stream uses, so a + console renders an install with the components it renders a + chat turn with. 404 once the event log has expired; the + durable message history is the fallback. + parameters: + - description: Sandbox config ID + in: path + name: id + required: true + type: string + - description: Skill ID + in: path + name: skillId + required: true + type: string + produces: + - text/event-stream + responses: + "200": + description: SSE stream of transcript events + schema: + type: string + "401": + description: Unauthorized + schema: + additionalProperties: true + type: object + "404": + description: Skill or transcript not found + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + - ApiKeyAuth: [] + summary: Follow an install's agent transcript + tags: + - SandboxConfig /sessions: get: consumes: @@ -13610,44 +14454,6 @@ paths: summary: 继续流式响应 tags: - 问答 - /knowledge-search: - post: - consumes: - - application/json - description: 在知识库中搜索(不使用LLM总结) - parameters: - - description: 搜索请求 - in: body - name: request - required: true - schema: - $ref: '#/definitions/internal_handler_session.SearchKnowledgeRequest' - - default: handle - description: 文件引用形式,public 返回可加载直链 - enum: - - handle - - public - in: query - name: resource_urls - 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: - - 问答 /shared-agents: get: description: 返回所有共享给当前用户所在组织的智能体 @@ -13689,7 +14495,12 @@ paths: get: consumes: - application/json - description: 获取所有预装的Agent Skills元数据 + description: 返回指定沙盒配置镜像内、智能体实际能调用的已安装技能(ready 且启用)。不传 sandbox_config_id 时列表为空。 + parameters: + - description: Sandbox config ID + in: query + name: sandbox_config_id + type: string produces: - application/json responses: @@ -13698,14 +14509,10 @@ paths: schema: additionalProperties: true type: object - "500": - description: 服务器错误 - schema: - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' security: - Bearer: [] - ApiKeyAuth: [] - summary: 获取预装Skills列表 + summary: 获取当前沙盒配置上可执行的 Skills tags: - Skills /storage-backends: @@ -14469,6 +15276,58 @@ paths: summary: Apply the default storage quota to every existing workspace tags: - System Admin + /system/admin/users/create: + post: + consumes: + - application/json + description: |- + Provision a new local user account (SystemAdmin only). + When `password` is omitted or null, a cryptographically random + password is generated (OIDC-style crypto/rand + base64url) + and returned once in the response body. Any provided value, + including empty string, is policy-checked. Tenant provisioning + follows the shared auth.default_tenant_mode policy. + parameters: + - description: User creation request + in: body + name: request + required: true + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AdminCreateUserRequest' + produces: + - application/json + responses: + "200": + description: Identity already exists, returns the existing user + schema: + $ref: '#/definitions/internal_handler.CreateSystemUserResponse' + "201": + description: User created successfully + schema: + $ref: '#/definitions/internal_handler.CreateSystemUserResponse' + "400": + description: Invalid request or weak password + schema: + additionalProperties: true + type: object + "403": + description: 'Forbidden: not a system admin' + schema: + additionalProperties: true + type: object + "409": + description: Email and username refer to conflicting identities + schema: + additionalProperties: true + type: object + "500": + description: Internal error + schema: + additionalProperties: true + type: object + summary: Create a new user (SystemAdmin) + tags: + - System Admin /system/admin/users/reset-password: post: consumes: diff --git a/frontend/src/api/system/index.ts b/frontend/src/api/system/index.ts index fd91c89c..0a7d541e 100644 --- a/frontend/src/api/system/index.ts +++ b/frontend/src/api/system/index.ts @@ -1038,7 +1038,7 @@ export function uploadConfigSkill( export function installConfigSkillFromSource( configId: string, - payload: { source: string; token?: string }, + payload: { source: string }, ): Promise<{ data: { skill_id: string } }> { return post(`/api/v1/sandbox-configs/${configId}/skills`, payload, { timeout: 2 * 60 * 1000, diff --git a/frontend/src/components/SandboxSkillsPanel.vue b/frontend/src/components/SandboxSkillsPanel.vue index 2a6a222c..15ec24e4 100644 --- a/frontend/src/components/SandboxSkillsPanel.vue +++ b/frontend/src/components/SandboxSkillsPanel.vue @@ -83,18 +83,6 @@ -
-

{{ $t('settings.sandbox.skillSourceTokenLabel') }}

- -

{{ $t('settings.sandbox.skillSourceTokenHint') }}

-
{{ $t('settings.sandbox.skillInstallOr') }}
@@ -333,8 +321,6 @@ const uploading = ref(false) const installingFromSource = ref(false) const uploadPercent = ref(0) const sourceInput = ref('') -const sourceToken = ref('') -const forceRegistryToken = ref(false) const skills = ref([]) const skillImage = ref(null) const togglingId = ref('') @@ -369,8 +355,6 @@ const uploadHint = computed(() => : t('settings.sandbox.skillUploadHint'), ) const installBusy = computed(() => uploading.value || installingFromSource.value) -const sourceNeedsRegistryToken = computed(() => looksLikePrivateSkillHub(sourceInput.value)) -const showRegistryToken = computed(() => sourceNeedsRegistryToken.value || forceRegistryToken.value) const deleteHint = computed(() => skillRollout.value === 'new_session' ? t('settings.sandbox.skillDeleteHintNewSession') @@ -382,48 +366,6 @@ const runtimeTemplateId = computed(() => { }) const hasSkillSnapshot = computed(() => Boolean(skillImage.value?.snapshot_id?.trim())) -const PUBLIC_SKILL_HOSTS = new Set([ - 'github.com', - 'www.github.com', - 'codeload.github.com', - 'gitlab.com', - 'www.gitlab.com', - 'skills.sh', - 'www.skills.sh', - 'clawhub.ai', - 'www.clawhub.ai', - 'clawhub.com', - 'www.clawhub.com', - 'skillhub.cn', - 'www.skillhub.cn', - 'api.skillhub.cn', -]) - -function looksLikePrivateSkillHub(raw: string): boolean { - const input = raw.trim() - if (!input.includes('://')) return false - try { - const parsed = new URL(input) - if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return false - return !PUBLIC_SKILL_HOSTS.has(parsed.hostname.toLowerCase()) - } catch { - return false - } -} - -function isRegistryAuthError(err: unknown): boolean { - const message = err && typeof err === 'object' && 'message' in err - ? String((err as { message?: unknown }).message) - : String(err ?? '') - return /\bHTTP 401\b/.test(message) || /\bHTTP 403\b/.test(message) -} - -watch(sourceInput, (value) => { - if (!looksLikePrivateSkillHub(value)) { - forceRegistryToken.value = false - } -}) - function readLastChatModelID(): string { try { return localStorage.getItem(LAST_CHAT_MODEL_KEY) || '' @@ -750,21 +692,14 @@ async function installFromSource() { installingFromSource.value = true try { await persistInstallerModel(installerModelId.value) - const token = showRegistryToken.value ? sourceToken.value.trim() : '' - const res = await installConfigSkillFromSource(props.record.id, { - source, - ...(token ? { token } : {}), - }) + const res = await installConfigSkillFromSource(props.record.id, { source }) MessagePlugin.success(t('settings.sandbox.skillUploadAccepted')) sourceInput.value = '' - sourceToken.value = '' - forceRegistryToken.value = false const skillId = res?.data?.skill_id await loadSkills() await refreshImage() if (skillId) followProgress(skillId) } catch (e: any) { - if (isRegistryAuthError(e)) forceRegistryToken.value = true MessagePlugin.error(e?.message || t('settings.sandbox.skillSourceFailed')) } finally { installingFromSource.value = false @@ -999,28 +934,6 @@ onUnmounted(() => { } } -.skill-token-row { - margin-top: 8px; - display: flex; - flex-direction: column; - align-items: stretch; - gap: 6px; -} - -.skill-token-label { - margin: 0; - font-size: 12px; - line-height: 1.4; - color: var(--td-text-color-secondary); -} - -.skill-token-hint { - margin: 0; - font-size: 12px; - line-height: 1.4; - color: var(--td-text-color-placeholder); -} - .skill-install-split { display: flex; align-items: center; diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index e0d06f19..979541ea 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -1282,9 +1282,6 @@ export default { skillUploadHint: 'Install writes the skill onto the current image and takes a new snapshot. This can take several minutes. The current chat turn is not interrupted; open sessions rebuild their sandbox on the next turn, which clears the session workspace scratch.', skillUploadHintNewSession: 'Install writes the skill onto the current image and takes a new snapshot. This can take several minutes. Already-open sessions keep their current sandbox until they end; only newly started sessions pick up this install.', skillSourcePlaceholder: 'Paste a URL or {\'@\'}owner/slug', - skillSourceTokenLabel: 'Private SkillHub token', - skillSourceTokenPlaceholder: 'Optional', - skillSourceTokenHint: 'Only needed for a self-hosted or private SkillHub. Used for this download only, not stored.', skillSourceInstall: 'Install', skillInstallOr: 'or', skillSourceFailed: 'Failed to install the skill from the registry', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 8fd6c1c1..d4101307 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -5121,9 +5121,6 @@ export default { skillUploadHint: '설치하면 현재 이미지에 스킬을 쓰고 새 스냅샷을 만듭니다. 몇 분이 걸릴 수 있습니다. 현재 대화 턴은 중단되지 않으며, 이미 열린 세션은 다음 턴에서 새 이미지로 샌드박스를 다시 만들고 그때 세션 작업 공간 초안이 지워집니다.', skillUploadHintNewSession: '설치하면 현재 이미지에 스킬을 쓰고 새 스냅샷을 만듭니다. 몇 분이 걸릴 수 있습니다. 이미 열린 세션은 세션이 끝날 때까지 기존 샌드박스를 유지하며, 이번에 설치한 스킬은 새로 시작한 세션에만 적용됩니다.', skillSourcePlaceholder: 'URL 또는 {\'@\'}owner/slug 붙여넣기', - skillSourceTokenLabel: '비공개 SkillHub 토큰', - skillSourceTokenPlaceholder: '선택 사항', - skillSourceTokenHint: '자체 호스팅 또는 비공개 SkillHub에서만 필요합니다. 이번 다운로드에만 사용되며 저장되지 않습니다.', skillSourceInstall: '설치', skillInstallOr: '또는', skillSourceFailed: '레지스트리에서 스킬을 설치하지 못했습니다', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 72927d2b..2e6fe2c0 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -5121,9 +5121,6 @@ export default { skillUploadHint: 'Установка записывает навык в текущий образ и создаёт новый снимок. Это может занять несколько минут. Текущий ход диалога не прерывается; открытые сессии пересоздадут песочницу при следующем сообщении, и тогда черновики рабочей области сессии будут очищены.', skillUploadHintNewSession: 'Установка записывает навык в текущий образ и создаёт новый снимок. Это может занять несколько минут. Уже открытые сессии продолжают использовать текущую песочницу до своего завершения; этот навык появится только у новых сессий.', skillSourcePlaceholder: 'Вставьте URL или {\'@\'}owner/slug', - skillSourceTokenLabel: 'Токен закрытого SkillHub', - skillSourceTokenPlaceholder: 'Необязательно', - skillSourceTokenHint: 'Нужен только для собственного или закрытого SkillHub. Используется только для этой загрузки и не сохраняется.', skillSourceInstall: 'Установить', skillInstallOr: 'или', skillSourceFailed: 'Не удалось установить навык из реестра', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 2b4ee4d2..272b380c 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -5123,9 +5123,6 @@ export default { skillUploadHint: '安装会在当前镜像上生成新快照,可能需要数分钟。当前这一轮对话不会中断;下一轮提问时才会按新镜像重建沙箱,会话工作区草稿会在那时清空。', skillUploadHintNewSession: '安装会在当前镜像上生成新快照,可能需要数分钟。已打开的会话继续使用原沙箱,直到该会话结束;只有新打开的会话才会带上这次安装的技能。', skillSourcePlaceholder: '粘贴链接或 {\'@\'}owner/slug', - skillSourceTokenLabel: '私有 SkillHub 访问令牌', - skillSourceTokenPlaceholder: '可选', - skillSourceTokenHint: '只发给这个平台,不会保存。公开 ClawHub / GitHub 技能不用填。', skillSourceInstall: '安装', skillInstallOr: '或', skillSourceFailed: '从托管平台安装技能失败', diff --git a/internal/application/service/tenant_skill_source.go b/internal/application/service/tenant_skill_source.go index 8d87c847..710f4c1e 100644 --- a/internal/application/service/tenant_skill_source.go +++ b/internal/application/service/tenant_skill_source.go @@ -15,6 +15,7 @@ import ( "sync" "time" + apperrors "github.com/Tencent/WeKnora/internal/errors" secutils "github.com/Tencent/WeKnora/internal/utils" ) @@ -71,10 +72,26 @@ type skillSourceHandoff struct { // InstallSkillFromSource resolves a ClawHub / SkillHub / skills.sh / git / // direct-zip locator to a skill bundle and runs the same install as an upload. +// +// Every fetch is anonymous. Private registries are deliberately out of scope: +// carrying a credential here would mean deciding, per hop, which of a +// registry's handoff targets may see it, and there is no private registry to +// validate that against yet. func (s *TenantSkillService) InstallSkillFromSource( - ctx context.Context, tenantID uint64, configID, source, token string, + ctx context.Context, tenantID uint64, configID, source string, ) (string, error) { - archive, err := fetchSkillArchive(ctx, source, token, s.sourceHTTP) + // The config is authorized before the fetch, not by InstallSkill after it. + // The source is a caller-supplied host, so an unknown config ID must not + // be able to spend an outbound request and a body-sized download first. + cfgEntity, err := s.configs.GetByID(ctx, tenantID, configID) + if err != nil { + return "", err + } + if cfgEntity == nil { + return "", apperrors.NewNotFoundError("sandbox config not found") + } + + archive, err := fetchSkillArchive(ctx, source, s.sourceHTTP) if err != nil { return "", err } @@ -93,17 +110,46 @@ func skillSourceHTTPClient(override *http.Client) *http.Client { return skillSourceHTTPDefault } -func fetchSkillArchive(ctx context.Context, source, token string, client *http.Client) ([]byte, error) { +func fetchSkillArchive(ctx context.Context, source string, client *http.Client) ([]byte, error) { parsed, err := parseSkillSource(source) if err != nil { return nil, err } httpClient := skillSourceHTTPClient(client) - body, contentType, err := fetchSkillSourceBytes(ctx, httpClient, parsed, token, 0) + fetched, err := fetchSkillSourceBytes(ctx, httpClient, parsed, 0) if err != nil { - return nil, err + // A bare "owner/slug" is both a GitHub repo and a registry slug, and + // the paste usually came from the registry listing. Only the failure + // of the first reading tells us which one it was. + alt, ok := registrySlugFallback(source, parsed) + if !ok { + return nil, err + } + altFetched, altErr := fetchSkillSourceBytes(ctx, httpClient, alt, 0) + if altErr != nil { + return nil, err + } + fetched = altFetched } - return normalizeFetchedSkillArchive(body, contentType, parsed.Subdir) + return normalizeFetchedSkillArchive(fetched.body, fetched.contentType, fetched.subdir) +} + +// registrySlugFallback re-reads a shorthand that was taken for a GitHub repo as +// a registry slug. It applies only to a bare "owner/slug": anything carrying a +// ref, a subdirectory or a scheme said what it meant. +func registrySlugFallback(raw string, parsed parsedSkillSource) (parsedSkillSource, bool) { + if parsed.Kind != skillSourceGitHub || parsed.Subdir != "" || parsed.Ref != "HEAD" { + return parsedSkillSource{}, false + } + spec := strings.TrimRight(strings.TrimSpace(raw), "/") + if spec == "" || strings.Contains(spec, "://") || strings.Contains(spec, "@") { + return parsedSkillSource{}, false + } + alt, err := parseRegistrySlug(defaultSkillRegistryOrigin, spec) + if err != nil { + return parsedSkillSource{}, false + } + return alt, true } func parseSkillSource(raw string) (parsedSkillSource, error) { @@ -457,6 +503,17 @@ func splitPath(p string) []string { return out } +// escapePathSegments escapes a value that spans several path segments, such as +// a "refs/heads/main" ref or a GitLab "group/subgroup" owner, without turning +// its separators into %2F. +func escapePathSegments(p string) string { + parts := strings.Split(p, "/") + for i, part := range parts { + parts[i] = url.PathEscape(part) + } + return strings.Join(parts, "/") +} + func isDirectArchivePath(p string) bool { lower := strings.ToLower(p) for _, ext := range []string{".zip", ".tgz", ".tar.gz", ".tar", ".md"} { @@ -494,71 +551,65 @@ func (s parsedSkillSource) fetchURL() (string, error) { ref = "HEAD" } return fmt.Sprintf("https://codeload.github.com/%s/%s/zip/%s", - s.Owner, s.Repo, ref), nil + escapePathSegments(s.Owner), url.PathEscape(s.Repo), escapePathSegments(ref)), nil case skillSourceGitLab: ref := s.Ref if ref == "" { ref = "HEAD" } - return fmt.Sprintf("https://gitlab.com/%s/%s/-/archive/%s/%s-%s.zip", - s.Owner, s.Repo, ref, s.Repo, ref), nil + return fmt.Sprintf("https://gitlab.com/%s/%s/-/archive/%s/%s.zip", + escapePathSegments(s.Owner), url.PathEscape(s.Repo), + escapePathSegments(ref), url.PathEscape(s.Repo+"-"+ref)), nil default: return "", fmt.Errorf("%w: cannot resolve source", ErrSkillSourceInvalid) } } +// fetchedSkillSource is the archive a source resolved to, plus the skill root +// inside it. The subdir is carried out of the fetch rather than re-derived from +// the original locator: a registry handoff to a monorepo zip names the one +// skill it meant, and only the last hop knows it. +type fetchedSkillSource struct { + body []byte + contentType string + subdir string +} + func fetchSkillSourceBytes( - ctx context.Context, client *http.Client, src parsedSkillSource, token string, hop int, -) ([]byte, string, error) { + ctx context.Context, client *http.Client, src parsedSkillSource, hop int, +) (fetchedSkillSource, error) { if hop > skillSourceMaxHops { - return nil, "", fmt.Errorf("%w: too many source redirects", ErrSkillSourceInvalid) + return fetchedSkillSource{}, fmt.Errorf("%w: too many source redirects", ErrSkillSourceInvalid) } target, err := src.fetchURL() if err != nil { - return nil, "", err + return fetchedSkillSource{}, err } - body, contentType, err := getSkillURL(ctx, client, target, token, shouldSendSkillToken(src, token)) + body, contentType, err := getSkillURL(ctx, client, target) if err != nil { - return nil, "", err + return fetchedSkillSource{}, err } + fetched := fetchedSkillSource{body: body, contentType: contentType, subdir: src.Subdir} if isZipMagic(body) || looksLikeSkillMarkdown(body) { - return body, contentType, nil + return fetched, nil } if !looksLikeJSON(contentType, body) { if isZipPayload(contentType, body) { - return body, contentType, nil + return fetched, nil } - return nil, "", fmt.Errorf("%w: remote did not return a skill archive", ErrSkillSourceInvalid) + return fetchedSkillSource{}, fmt.Errorf( + "%w: remote did not return a skill archive", ErrSkillSourceInvalid) } var handoff skillSourceHandoff if err := json.Unmarshal(body, &handoff); err != nil { - return nil, "", fmt.Errorf("%w: remote JSON is not a skill archive", ErrSkillSourceInvalid) + return fetchedSkillSource{}, fmt.Errorf( + "%w: remote JSON is not a skill archive", ErrSkillSourceInvalid) } next, err := sourceFromHandoff(src, handoff) if err != nil { - return nil, "", err + return fetchedSkillSource{}, err } - return fetchSkillSourceBytes(ctx, client, next, token, hop+1) -} - -func shouldSendSkillToken(src parsedSkillSource, token string) bool { - if token == "" || src.Kind == skillSourceGitHub || src.Kind == skillSourceGitLab { - return false - } - target, err := src.fetchURL() - if err != nil { - return false - } - host := "" - if u, err := url.Parse(target); err == nil { - host = strings.ToLower(u.Hostname()) - } - switch host { - case "github.com", "www.github.com", "codeload.github.com", - "gitlab.com", "www.gitlab.com", "skills.sh", "www.skills.sh": - return false - } - return src.Kind == skillSourceRegistry || src.Kind == skillSourceDirect + return fetchSkillSourceBytes(ctx, client, next, hop+1) } func sourceFromHandoff(prev parsedSkillSource, handoff skillSourceHandoff) (parsedSkillSource, error) { @@ -576,9 +627,14 @@ func sourceFromHandoff(prev parsedSkillSource, handoff skillSourceHandoff) (pars } archiveURL = strings.TrimRight(prev.Registry, "/") + archiveURL } + // A handoff that is not a parseable http(s) URL is refused rather than + // passed through as a direct target: SSRF validation normalises a + // scheme-less string by prepending https://, which would turn a malformed + // response into a fetch of a host we never agreed to read. next, err := parseSkillSourceURL(archiveURL) if err != nil { - next = parsedSkillSource{Kind: skillSourceDirect, DirectURL: archiveURL} + return parsedSkillSource{}, fmt.Errorf( + "%w: registry archive URL is not usable: %v", ErrSkillSourceInvalid, err) } if next.Subdir == "" && strings.TrimSpace(handoff.Path) != "" { next.Subdir = strings.Trim(handoff.Path, "/") @@ -590,7 +646,7 @@ func sourceFromHandoff(prev parsedSkillSource, handoff skillSourceHandoff) (pars } func getSkillURL( - ctx context.Context, client *http.Client, rawURL, token string, sendToken bool, + ctx context.Context, client *http.Client, rawURL string, ) ([]byte, string, error) { if err := secutils.ValidateURLForSSRF(rawURL); err != nil { return nil, "", fmt.Errorf("%w: %s", ErrSkillSourceInvalid, @@ -602,9 +658,6 @@ func getSkillURL( } req.Header.Set("User-Agent", skillSourceUserAgent) req.Header.Set("Accept", "application/zip, application/octet-stream, application/json, text/plain;q=0.9, */*;q=0.8") - if sendToken && token != "" { - req.Header.Set("Authorization", "Bearer "+token) - } resp, err := client.Do(req) if err != nil { if errors.Is(err, secutils.ErrSSRFRedirectBlocked) { diff --git a/internal/application/service/tenant_skill_source_test.go b/internal/application/service/tenant_skill_source_test.go index 2de17d6d..932fa7e5 100644 --- a/internal/application/service/tenant_skill_source_test.go +++ b/internal/application/service/tenant_skill_source_test.go @@ -5,6 +5,7 @@ import ( "net/http" "net/http/httptest" "strings" + "sync" "testing" "github.com/Tencent/WeKnora/internal/utils" @@ -155,9 +156,7 @@ func TestSkillHubCNMapsToDownloadAPI(t *testing.T) { func TestFetchSkillArchiveFromRegistry(t *testing.T) { archive := zipBundle(t, map[string]string{"SKILL.md": validSkillMD}) - var sawAuth string server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - sawAuth = r.Header.Get("Authorization") if r.URL.Path != "/api/v1/download" || r.URL.Query().Get("slug") != "owner/demo" { http.NotFound(w, r) return @@ -168,15 +167,128 @@ func TestFetchSkillArchiveFromRegistry(t *testing.T) { t.Cleanup(server.Close) allowLoopbackSkillFetch(t) - got, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", "sk_test", server.Client()) + got, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", server.Client()) require.NoError(t, err) - require.Equal(t, "Bearer sk_test", sawAuth) bundle, err := ParseSkillBundle(got) require.NoError(t, err) require.Equal(t, "pdf-tools", bundle.Name) } +// Skill sources are read anonymously. Nothing in this flow holds a credential, +// so no hop may present one. +func TestFetchSkillArchiveSendsNoCredentials(t *testing.T) { + archive := zipBundle(t, map[string]string{"SKILL.md": validSkillMD}) + + var archiveAuth, registryAuth string + var mu sync.Mutex + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mu.Lock() + defer mu.Unlock() + switch r.URL.Path { + case "/api/v1/download": + registryAuth = r.Header.Get("Authorization") + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(skillSourceHandoff{ + ArchiveURL: "http://" + r.Host + "/skill.zip", + }) + case "/skill.zip": + archiveAuth = r.Header.Get("Authorization") + w.Header().Set("Content-Type", "application/zip") + _, _ = w.Write(archive) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(server.Close) + allowLoopbackSkillFetch(t) + + _, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", server.Client()) + require.NoError(t, err) + require.Empty(t, registryAuth) + require.Empty(t, archiveAuth) +} + +// The handoff's path is what names one skill inside a monorepo zip; losing it +// makes a multi-skill repo either ambiguous or wrong. +func TestFetchSkillArchiveUsesHandoffPath(t *testing.T) { + otherSkillMD := strings.Replace(validSkillMD, "name: pdf-tools", "name: csv-tools", 1) + archive := zipBundle(t, map[string]string{ + "repo-main/README.md": "# repo", + "repo-main/skills/pdf/SKILL.md": validSkillMD, + "repo-main/skills/pdf/extract.py": "print('pdf')\n", + "repo-main/skills/csv/SKILL.md": otherSkillMD, + "repo-main/skills/csv/transform.py": "print('csv')\n", + }) + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/api/v1/download": + _ = json.NewEncoder(w).Encode(skillSourceHandoff{ + SourceRef: "public-github", + ArchiveURL: "http://" + r.Host + "/archive.zip", + Path: "skills/csv", + }) + case "/archive.zip": + w.Header().Set("Content-Type", "application/zip") + _, _ = w.Write(archive) + default: + http.NotFound(w, r) + } + })) + t.Cleanup(server.Close) + allowLoopbackSkillFetch(t) + + got, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", server.Client()) + require.NoError(t, err) + bundle, err := ParseSkillBundle(got) + require.NoError(t, err) + require.Equal(t, "csv-tools", bundle.Name) + require.Contains(t, bundle.Files, "transform.py") + require.NotContains(t, bundle.Files, "extract.py") +} + +// A malformed handoff is refused: SSRF validation normalises a scheme-less +// string by prepending https://, so passing it through would fetch a host the +// response never legally named. +func TestFetchSkillArchiveRejectsUnusableHandoffURL(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(skillSourceHandoff{ArchiveURL: "evil.example.com/skill.zip"}) + })) + t.Cleanup(server.Close) + allowLoopbackSkillFetch(t) + + _, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", server.Client()) + require.ErrorIs(t, err, ErrSkillSourceInvalid) + require.ErrorContains(t, err, "archive URL is not usable") +} + +// A bare "owner/slug" reads as a GitHub repo and as a registry slug. The +// registry is the fallback, but only for a shorthand that named nothing else. +func TestRegistrySlugFallback(t *testing.T) { + bare := "clawhub_pskoett/self-improving-agent" + parsed, err := parseSkillSource(bare) + require.NoError(t, err) + require.Equal(t, skillSourceGitHub, parsed.Kind) + + alt, ok := registrySlugFallback(bare, parsed) + require.True(t, ok) + require.Equal(t, skillSourceRegistry, alt.Kind) + require.Equal(t, defaultSkillRegistryOrigin, alt.Registry) + require.Equal(t, bare, alt.Slug) + + withSubdir := "vercel-labs/agent-skills@frontend-design" + parsed, err = parseSkillSource(withSubdir) + require.NoError(t, err) + _, ok = registrySlugFallback(withSubdir, parsed) + require.False(t, ok, "a shorthand that named a skill directory meant GitHub") + + parsed, err = parseSkillSource("https://github.com/vercel-labs/agent-skills") + require.NoError(t, err) + _, ok = registrySlugFallback("https://github.com/vercel-labs/agent-skills", parsed) + require.False(t, ok, "an explicit GitHub URL is not a registry slug") +} + func TestFetchSkillArchiveFollowsGitHubHandoff(t *testing.T) { archive := zipBundle(t, map[string]string{ "repo-main/README.md": "# repo", @@ -201,7 +313,7 @@ func TestFetchSkillArchiveFollowsGitHubHandoff(t *testing.T) { t.Cleanup(server.Close) allowLoopbackSkillFetch(t) - got, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", "", server.Client()) + got, err := fetchSkillArchive(t.Context(), server.URL+"/owner/demo", server.Client()) require.NoError(t, err) bundle, err := ParseSkillBundle(got) require.NoError(t, err) @@ -218,23 +330,13 @@ func TestFetchSkillArchiveFromSkillMarkdown(t *testing.T) { t.Cleanup(server.Close) allowLoopbackSkillFetch(t) - got, err := fetchSkillArchive(t.Context(), server.URL+"/SKILL.md", "", server.Client()) + got, err := fetchSkillArchive(t.Context(), server.URL+"/SKILL.md", server.Client()) require.NoError(t, err) bundle, err := ParseSkillBundle(got) require.NoError(t, err) require.Equal(t, "pdf-tools", bundle.Name) } -func TestFetchSkillArchiveDoesNotSendTokenToGitHub(t *testing.T) { - src := parsedSkillSource{ - Kind: skillSourceGitHub, Owner: "o", Repo: "r", Ref: "HEAD", - } - require.False(t, shouldSendSkillToken(src, "sk_secret")) - src.Kind = skillSourceRegistry - src.Registry = "https://skillhub.example.com" - require.True(t, shouldSendSkillToken(src, "sk_secret")) -} - func TestParseSkillBundleNestedRemoteArchive(t *testing.T) { data := zipBundle(t, map[string]string{ "repo-abc/LICENSE": "MIT", @@ -267,7 +369,7 @@ func TestFetchSkillArchiveRejectsNonSkillHTML(t *testing.T) { t.Cleanup(server.Close) allowLoopbackSkillFetch(t) - _, err := fetchSkillArchive(t.Context(), server.URL+"/demo.zip", "", server.Client()) + _, err := fetchSkillArchive(t.Context(), server.URL+"/demo.zip", server.Client()) require.ErrorIs(t, err, ErrSkillSourceInvalid) require.True(t, strings.Contains(err.Error(), "skill archive") || strings.Contains(err.Error(), "zip skill bundle")) diff --git a/internal/handler/sandbox_skill.go b/internal/handler/sandbox_skill.go index 989d54bb..c69747d5 100644 --- a/internal/handler/sandbox_skill.go +++ b/internal/handler/sandbox_skill.go @@ -49,7 +49,7 @@ type sandboxSkillService interface { ) (*types.TenantSkillEntity, error) InstallSkill(ctx context.Context, tenantID uint64, configID string, archive []byte) (string, error) InstallSkillFromSource( - ctx context.Context, tenantID uint64, configID, source, token string, + ctx context.Context, tenantID uint64, configID, source string, ) (string, error) RemoveSkill(ctx context.Context, tenantID uint64, configID, skillID string) error LastProgress( @@ -190,9 +190,10 @@ func (h *SandboxSkillHandler) Get(c *gin.Context) { // @Description Install a skill onto this sandbox config's image. Send a zip // @Description as multipart form field "file", or JSON {"source":"..."} to // @Description pull from ClawHub, SkillHub, skills.sh, GitHub, GitLab, or a -// @Description direct archive URL. The install boots a sandbox and runs for -// @Description minutes, so the request is only accepted; follow it via the -// @Description install-events stream. +// @Description direct archive URL. The source must be readable anonymously. +// @Description The install boots a sandbox and runs for minutes, so the +// @Description request is only accepted; follow it via the install-events +// @Description stream. // @Tags SandboxConfig // @Accept json // @Accept multipart/form-data @@ -258,11 +259,9 @@ func (h *SandboxSkillHandler) Upload(c *gin.Context) { type skillSourceRequest struct { // Source is a ClawHub/SkillHub slug or page URL, a skills.sh / GitHub / - // GitLab locator, or a direct zip/SKILL.md URL. + // GitLab locator, or a direct zip/SKILL.md URL. It must be readable + // anonymously: the fetch carries no credential of any kind. Source string `json:"source"` - // Token is an optional registry bearer token (private SkillHub). It is - // used only for that fetch and is never stored. - Token string `json:"token"` } func (h *SandboxSkillHandler) installFromSource(c *gin.Context) { @@ -283,7 +282,7 @@ func (h *SandboxSkillHandler) installFromSource(c *gin.Context) { } skillID, err := h.service.InstallSkillFromSource( - c.Request.Context(), sandboxConfigTenantID(c), c.Param("id"), source, req.Token, + c.Request.Context(), sandboxConfigTenantID(c), c.Param("id"), source, ) if err != nil { respondSkillServiceError(c, err) diff --git a/internal/handler/sandbox_skill_test.go b/internal/handler/sandbox_skill_test.go index 73a917e6..e7c15e61 100644 --- a/internal/handler/sandbox_skill_test.go +++ b/internal/handler/sandbox_skill_test.go @@ -38,7 +38,6 @@ type fakeSandboxSkillService struct { installID string installErr error installSource string - installToken string sourceErr error removeErr error @@ -124,10 +123,10 @@ func (f *fakeSandboxSkillService) InstallSkill( } func (f *fakeSandboxSkillService) InstallSkillFromSource( - _ context.Context, tenantID uint64, configID, source, token string, + _ context.Context, tenantID uint64, configID, source string, ) (string, error) { f.installTenant, f.installConfig = tenantID, configID - f.installSource, f.installToken = source, token + f.installSource = source return f.installID, f.sourceErr } @@ -281,7 +280,7 @@ func TestSandboxSkillInstallFromSourceAcceptedReturnsSkillID(t *testing.T) { svc := &fakeSandboxSkillService{installID: "skill-9"} router := newSkillTestRouter(NewSandboxSkillHandler(svc, nil)) - body := `{"source":"@owner/demo","token":"sk_test"}` + body := `{"source":"@owner/demo"}` req := httptest.NewRequest(http.MethodPost, "/sandbox-configs/cfg-a/skills", strings.NewReader(body)) req.Header.Set("Content-Type", "application/json") @@ -292,7 +291,6 @@ func TestSandboxSkillInstallFromSourceAcceptedReturnsSkillID(t *testing.T) { require.Equal(t, testSkillTenantID, svc.installTenant) require.Equal(t, "cfg-a", svc.installConfig) require.Equal(t, "@owner/demo", svc.installSource) - require.Equal(t, "sk_test", svc.installToken) require.Nil(t, svc.installBytes, "a source install must not look like an upload") } diff --git a/internal/handler/skill_handler.go b/internal/handler/skill_handler.go index 63888a89..d2773550 100644 --- a/internal/handler/skill_handler.go +++ b/internal/handler/skill_handler.go @@ -41,7 +41,6 @@ type SkillInfoResponse struct { // @Produce json // @Param sandbox_config_id query string false "Sandbox config ID" // @Success 200 {object} map[string]interface{} "Skills列表" -// @Failure 500 {object} errors.AppError "服务器错误" // @Security Bearer // @Security ApiKeyAuth // @Router /skills [get]