diff --git a/config/prompt_templates/agent_system_prompt.yaml b/config/prompt_templates/agent_system_prompt.yaml index ba88f932..85c3b1d5 100644 --- a/config/prompt_templates/agent_system_prompt.yaml +++ b/config/prompt_templates/agent_system_prompt.yaml @@ -186,6 +186,12 @@ templates: - When the user asks why something is not found, run knowledge_base.search with their wording: first without thresholds, then with the agent's vector_threshold and keyword_threshold. Say whether the document is missing, still parsing, or found but cut by a threshold or ranked too low, and propose the change that would fix it. - Probe operations change nothing, but a turn may run only a few. Check once, then report what you found. - When delegating to existing reasoning agents, follow the runtime coordination instructions and available collaboration tool definitions. + Scheduled and recurring work (automations): + - An automation has an agent run a task on a schedule as the user, in the background, and notifies them in WeKnora when a run finishes, fails or waits for their approval. Use it for anything to be done later or repeatedly ("every morning", "remind me at 5pm", "each Monday summarise"), instead of saying you cannot act after the conversation. Find the automation.* operations with find_operations. + - Turn the user's wording into a five-field cron expression (minute first) or a one-time at, with the user's IANA timezone (ask if you cannot tell). A one-time at is a wall-clock time in that timezone, "2006-01-02 15:04" or RFC3339; do not invent a UTC offset. Check it with automation.validate_trigger and tell the user the next run times, in their timezone, before creating it. + - Runs are at least 5 minutes apart. If the user asks for more often, say so and offer every 5 minutes or a longer interval rather than giving up. + - Nobody watches a run and it cannot ask questions, so write the instruction as the complete task: what to do, where to look, what the result should contain. Results arrive as WeKnora notifications, not on the user's phone or in chat apps; say so when they expect a reminder elsewhere. + - Leave access_level at confirm unless the user asks for changes to run without approval. After creating one, offer open_page with page automations and its automation_id. The user's past conversations: - You can read the user's own conversations and nobody else's, and you cannot change them. session.list shows recent ones or matches titles; message.search finds one by what was said; message.list reads one. - When the user refers to something from before ("last time", "what I asked about X"), search before saying it was never discussed. If message.search finds nothing, check message.chat_history_stats: without indexing it matches exact words only, so retry with the user's own wording and tell them search by meaning is off. diff --git a/docs/design/agent-automation.md b/docs/design/agent-automation.md index 1b20550c..9f6be0ec 100644 --- a/docs/design/agent-automation.md +++ b/docs/design/agent-automation.md @@ -1,6 +1,6 @@ # Agent 自动化(定时任务) -状态:设计稿,未实现。日期:2026-10-19。 +状态:第一版已实现,与设计的差异见 §13。日期:2026-10-19。 权限部分建立在 [Agent 执行权限模型](agent-permission-model.md) 之上:自动化不定义自己的审批策略或白名单,只使用该模型的 `deferred` 运行模式、`automation` 作用域授权和 `ActingVia` 身份。权限模型的前三步是本需求的前置条件。 @@ -242,3 +242,18 @@ operations 新增:`automation.list`、`automation.get`、`automation.create` - `persistent` 会话长期运行后的上下文压缩策略是否需要比普通会话更激进。 - 通知中心是否需要按工作空间隔离展示。 - 每租户数量与并发上限的默认值,以及是否放进系统设置页。 + +## 13. 实现说明 + +第一版按 §10 的第 1–4 步实现,以下几处与设计不同: + +- **没有抽出 `AgentRunService`**。执行器 `automation_runner.go` 照协作执行器的写法自己完成建消息对、挂事件流、监听完成与错误、落库;协作执行器不动。四个后台调用方的统一留作单独的重构。 +- **只有所有者能访问**。接口按所有者过滤,空间管理员不能查看或停用他人的自动化(§12 第一条仍待定)。API Key、IM 用户和自动化运行内部(`ActingVia` 非空)都不能创建或管理自动化。 +- **调度只走数据库**。所有实例每 15 秒扫描到期记录,用 `version` 做 CAS 领取,不经 Redis 投递;Lite 与多实例部署同一套逻辑。 +- **审批过期由调度器对账**,不改 HITL Broker 的过期时间:等待审批超过 `approval_timeout_minutes` 后运行记为失败并关闭提示。Broker 对挂起提示的回收如果更早,运行同样记为失败,原因取提示的关闭原因。 +- **长期授权从历史审批提升**。设置页不提供工具清单勾选,而是列出本自动化运行中请求过审批、尚未授权的写类与 destructive 调用,由所有者逐条确认;授权绑定 Agent 配置与所有者角色(`AutomationBinding`),变化后显示失效。需要每次审批的调用不会出现在候选里。 +- **限制只有时长**。`limits` 目前只有 `max_duration_minutes`(默认 30,上限 240,不含等待审批的时间);token 上限没有单独实现,由 Agent 自身的 `max_iterations` 约束。 +- **`persistent` 会话忙时跳过**。长期会话里还有进行中的运行(包括用户在该会话里手动对话)时,本次运行记为 `skipped`。 +- **内置助手的 `agent_id` 存为助手 ID**(`builtin-weknora-assistant`),空字符串只在创建时作为默认值。 +- **前端入口**:侧栏“自动化”页面(`/platform/automations`),运行详情直接打开自动化会话;通知链接 `/platform/automations/:id?run=:runId` 打开对应运行。右上角铃铛合并展示邀请与通知,60 秒轮询。 +- **助手审批卡**仍是通用的 operation 参数展示,未单独渲染触发描述与未来触发时间;助手需要先调用 `automation.validate_trigger` 并在对话里告知用户。 diff --git a/docs/docs.go b/docs/docs.go index 826588e6..931cf199 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -85,6 +85,88 @@ const docTemplate = `{ } } }, + "/agent/grants": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "列出当前用户在某个会话(根会话)中通过“本会话允许”记住的授权,包括其委派子任务上批准的授权。", + "produces": [ + "application/json" + ], + "tags": [ + "Agent" + ], + "summary": "列出会话内的 Agent 授权", + "parameters": [ + { + "type": "string", + "description": "根会话 ID", + "name": "session_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "授权列表", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/agent/grants/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "撤销当前用户的一条授权;之后同类调用会重新询问。", + "produces": [ + "application/json" + ], + "tags": [ + "Agent" + ], + "summary": "撤销 Agent 授权", + "parameters": [ + { + "type": "string", + "description": "授权 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "撤销结果", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "授权不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/agent/mcp-oauth-resolutions/{pending_id}": { "post": { "security": [ @@ -1832,6 +1914,801 @@ const docTemplate = `{ } } }, + "/automation-runs/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "获取运行记录", + "parameters": [ + { + "type": "string", + "description": "运行 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + } + } + } + }, + "/automation-runs/{id}/cancel": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "排队或等待审批的运行立即结束;执行中的运行在下一次检查时停止", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "停止运行", + "parameters": [ + { + "type": "string", + "description": "运行 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + } + } + } + }, + "/automations": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "列出当前用户在本空间创建的自动化(定时任务),最新的在前", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "列出我的自动化", + "responses": { + "200": { + "description": "自动化列表", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.list", + "max_items": 100, + "risk": "read" + }, + "x-agent-hint": "Lists the user's automations: scheduled tasks an agent runs on their behalf, with next and last run." + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "创建一个按计划由 Agent 以当前用户身份运行的任务", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "创建自动化", + "parameters": [ + { + "description": "自动化", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.CreateAutomationRequest" + } + } + ], + "responses": { + "201": { + "description": "创建的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "400": { + "description": "参数不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.create", + "label_param": "name", + "risk": "write", + "role": "viewer" + }, + "x-agent-hint": "Creates an automation the user runs as. Turn the user's wording into a cron expression (five fields, minute first) and an IANA timezone, and check it with automation.validate_trigger first, telling the user the next run times it returns. Runs are unattended: write the instruction as a complete task, since nobody can answer questions during a run. access_level defaults to confirm, where each change waits for the user's approval; only set auto_write when the user asks for it." + } + }, + "/automations/validate-trigger": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "校验 cron 或一次性触发器,返回未来 3 次触发时间", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "校验触发器", + "parameters": [ + { + "description": "触发器", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.ValidateTriggerRequest" + } + } + ], + "responses": { + "200": { + "description": "未来触发时间", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/internal_handler.ValidateTriggerResult" + } + } + } + ] + } + }, + "400": { + "description": "触发器不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.validate_trigger", + "risk": "probe" + }, + "x-agent-hint": "Checks a trigger and returns its next three run times in UTC; convert them to the trigger's timezone for the user." + } + }, + "/automations/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "获取自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "404": { + "description": "不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.get", + "risk": "read" + }, + "x-agent-hint": "Returns one automation, including its instruction." + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "只修改请求中出现的字段,其余保持不变", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "修改自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "要修改的字段", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationPatch" + } + } + ], + "responses": { + "200": { + "description": "修改后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "400": { + "description": "参数不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.update", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Changes the listed fields of an automation; a field left out is kept. Check a new trigger with automation.validate_trigger first. Use automation.pause and automation.resume to switch it off and on." + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "停止进行中的运行,删除自动化及其运行记录、会话和长期授权", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "删除自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "$ref": "#/definitions/internal_handler.SuccessResponse" + } + }, + "404": { + "description": "不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.delete", + "label": "name", + "risk": "destructive", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Deletes an automation with its run history and conversations. Cannot be undone; automation.pause keeps it." + } + }, + "/automations/{id}/grant-candidates": { + "get": { + "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 + } + } + } + } + }, + "/automations/{id}/grants": { + "get": { + "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 + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "让以后的运行无需确认即可执行某次运行请求过审批的调用;Agent 配置或所有者角色变化后失效", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "添加长期授权", + "parameters": [ + { + "type": "string", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "{prompt_id}", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "授权", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/automations/{id}/pause": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "停止按计划触发;进行中的运行不受影响", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "暂停自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "暂停后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.pause", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Stops an automation from running on schedule until automation.resume." + } + }, + "/automations/{id}/resume": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "从现在起重新按计划触发,并清零连续失败计数", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "恢复自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "恢复后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.resume", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Schedules a paused automation again from now; missed runs are not caught up." + } + }, + "/automations/{id}/run": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "排队一次手动运行;已有运行在排队或进行中时拒绝", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "立即运行自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "202": { + "description": "排队的运行", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + }, + "409": { + "description": "已有运行", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.run_now", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Queues a run now, in the background; follow it with automation.list_runs." + } + }, + "/automations/{id}/runs": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "列出运行记录", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "x-agent": true, + "description": "页码,从 1 开始", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "x-agent": true, + "x-agent-maximum": "20", + "description": "每页条数,最多 100", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.PageResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.list_runs", + "risk": "read" + }, + "x-agent-hint": "Lists an automation's runs, newest first, with status, error and the start of the answer." + } + }, "/chunker/preview": { "post": { "security": [ @@ -2597,7 +3474,7 @@ const docTemplate = `{ "id": "data_source.get_sync_log", "risk": "read" }, - "x-agent-hint": "Read the current status, counts and errors of a sync_log_id returned by data_source.sync or data_source.list_sync_logs. A started job is not a completed sync." + "x-agent-hint": "Read the current status and counts of a sync_log_id returned by data_source.sync or data_source.list_sync_logs. A started job is not a completed sync. Raw upstream errors are omitted; detailed failures remain on the data source settings page." } }, "/datasource/types": { @@ -2710,7 +3587,7 @@ const docTemplate = `{ "id": "data_source.get", "risk": "read" }, - "x-agent-hint": "Read a configured data source and its sync state; credentials and connector configuration are not returned." + "x-agent-hint": "Read a configured data source and its sync state; credentials, connector settings and raw upstream errors are omitted. For detailed failures use the data source settings page." }, "put": { "description": "Update an existing data source configuration", @@ -2854,7 +3731,7 @@ const docTemplate = `{ "id": "data_source.list_sync_logs", "risk": "read" }, - "x-agent-hint": "Read recent sync results, counts and errors. Use limit and offset for older records." + "x-agent-hint": "Read recent sync status and counts. Use limit and offset for older records. Raw upstream errors are omitted; detailed failures remain on the data source settings page." } }, "/datasource/{id}/pause": { @@ -12091,7 +12968,7 @@ const docTemplate = `{ "ApiKeyAuth": [] } ], - "description": "为指定 MCP 服务下的某个工具更新启用状态和/或人工审批要求。至少提供 require_approval 或 enabled 之一;省略的字段保持原值。", + "description": "为指定 MCP 服务下的某个工具更新启用状态、人工审批要求和/或风险等级。\n至少提供 require_approval、enabled、risk 之一;省略的字段保持原值。\nrisk 为 read/probe/write/destructive,空字符串表示改回按服务注解推断。", "consumes": [ "application/json" ], @@ -12118,7 +12995,7 @@ const docTemplate = `{ "required": true }, { - "description": "{require_approval?: bool, enabled?: bool}", + "description": "{require_approval?: bool, enabled?: bool, risk?: string}", "name": "request", "in": "body", "required": true, @@ -14239,6 +15116,84 @@ const docTemplate = `{ "x-agent-hint": "Copies a workspace-owned model configuration under a required new display_name. Choose model_id from model.list; builtin models cannot be copied. The upstream model name, connection parameters and saved credentials are copied on the backend; never request or resend credentials. The copy is not the default and does not change agent or knowledge base bindings. Active local models are reused without downloading again; copying an unfinished or failed local model starts a background download, so read the returned model_id with model.get until its status is active or download_failed." } }, + "/notifications": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "通知" + ], + "summary": "列出我的通知", + "parameters": [ + { + "type": "integer", + "description": "条数,最多 100", + "name": "limit", + "in": "query" + }, + { + "type": "boolean", + "description": "只看未读", + "name": "unread", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{items, unread}", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/notifications/read": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "ids 为空时全部标记已读", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "通知" + ], + "summary": "标记通知已读", + "parameters": [ + { + "description": "{ids}", + "name": "request", + "in": "body", + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "结果", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/organizations": { "get": { "security": [ @@ -24762,6 +25717,13 @@ const docTemplate = `{ "description": "Iteration number (0-indexed)", "type": "integer" }, + "progress": { + "description": "Progress is user-facing commentary from a non-terminal round. Thought stays intact for model replay.", + "type": "string" + }, + "progress_event_id": { + "type": "string" + }, "reasoning_content": { "description": "ReasoningContent stores the OpenAI-protocol reasoning_content emitted by the\nmodel in this round. Persisted on AgentStep so cross-turn replay can put it\nback on the assistant message — required by MiMo / DeepSeek V3.2+ thinking\nmode, ignored by providers that don't recognize the field.", "type": "string" @@ -25252,6 +26214,346 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.Automation": { + "type": "object", + "properties": { + "access_level": { + "description": "AccessLevel is how far runs may change data without asking, capped by\nthe agent's and the workspace's ceilings.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "AgentID is the agent that runs it; the WeKnora assistant's ID runs the\nassistant.", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "ApprovalTimeoutMinutes is how long a run waits for an approval before\nit fails.", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "CarryLastResult adds the last successful answer to each per-run\nconversation.", + "type": "boolean", + "x-agent": true + }, + "consecutive_failures": { + "type": "integer" + }, + "created_at": { + "type": "string" + }, + "description": { + "type": "string", + "x-agent": true + }, + "enabled": { + "type": "boolean", + "x-agent": true, + "x-agent-response": true + }, + "id": { + "type": "string", + "x-agent": "automation_id", + "x-agent-response": true + }, + "instruction": { + "description": "Instruction is the task, sent as the user message of each run after\nits variables are filled in.", + "type": "string", + "x-agent": true, + "x-agent-detail": true + }, + "last_run_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "last_run_status": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "last_success_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "type": "string", + "x-agent": true + }, + "name": { + "type": "string", + "x-agent": true + }, + "next_run_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "notify_on_success": { + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "type": "string", + "x-agent": true + }, + "owner_user_id": { + "description": "OwnerUserID is the account the automation runs as.", + "type": "string" + }, + "paused_reason": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "persistent_session_id": { + "description": "PersistentSessionID is the conversation of a persistent automation,\ncreated on its first run.", + "type": "string" + }, + "session_mode": { + "type": "string", + "x-agent": true + }, + "tenant_id": { + "type": "integer" + }, + "trigger": { + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + }, + "updated_at": { + "type": "string" + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationLimits": { + "type": "object", + "properties": { + "max_duration_minutes": { + "description": "MaxDurationMinutes caps a run's execution time, not counting time spent\nwaiting for approval. 0 uses the default.", + "type": "integer", + "x-agent": true + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationPatch": { + "type": "object", + "properties": { + "access_level": { + "description": "How far runs may change data without asking", + "enum": [ + "read_only", + "confirm", + "auto_write" + ], + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "Agent that runs it, from agent.list; empty runs the WeKnora assistant", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "How long a run waits for an approval before it fails, in minutes", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "Whether each per_run conversation gets the last successful answer", + "type": "boolean", + "x-agent": true + }, + "description": { + "description": "What it is for", + "type": "string", + "x-agent": true + }, + "enabled": { + "description": "Whether it is scheduled; on update use pause and resume instead", + "type": "boolean" + }, + "instruction": { + "description": "The task, sent as the user message of each run. May name now,\nlast_run_at, last_success_at, run_id or automation_name inside double\ncurly braces to have it filled in", + "type": "string", + "x-agent": true, + "x-agent-max-bytes": "32000" + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "description": "What happens to runs missed while the service was down or paused", + "type": "string", + "enum": [ + "skip", + "run_once" + ], + "x-agent": true + }, + "name": { + "description": "What the automation is called", + "type": "string", + "x-agent": true + }, + "notify_on_success": { + "description": "Whether a successful run notifies the owner", + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "description": "What happens when a run is due while the previous one is still going", + "type": "string", + "enum": [ + "skip", + "queue" + ], + "x-agent": true + }, + "session_mode": { + "description": "per_run starts a new conversation each run; persistent keeps one", + "type": "string", + "enum": [ + "per_run", + "persistent" + ], + "x-agent": true + }, + "trigger": { + "description": "When it runs", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationRun": { + "type": "object", + "properties": { + "answer": { + "description": "Answer is the start of the final answer, for listings.", + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "assistant_message_id": { + "type": "string" + }, + "automation_id": { + "type": "string" + }, + "cancel_requested": { + "description": "CancelRequested stops the run at its next check.", + "type": "boolean" + }, + "created_at": { + "type": "string" + }, + "error": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "finished_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "id": { + "type": "string", + "x-agent": "run_id", + "x-agent-response": true + }, + "pending_prompt_id": { + "description": "PendingPromptID is the approval a waiting run is suspended on.", + "type": "string" + }, + "scheduled_at": { + "description": "ScheduledAt is when the run was due; for a manual run, when it was\nasked for.", + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "session_id": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "started_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "status": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "tenant_id": { + "type": "integer" + }, + "trigger_kind": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "updated_at": { + "type": "string" + }, + "usage": { + "type": "object" + }, + "user_message_id": { + "description": "UserMessageID and AssistantMessageID are the run's turn in SessionID.", + "type": "string" + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationTrigger": { + "type": "object", + "properties": { + "at": { + "description": "At is when a once trigger fires.", + "type": "string", + "x-agent": true + }, + "expr": { + "description": "Expr is a cron expression: five fields (minute first) or six (seconds\nfirst), or a descriptor such as @daily.", + "type": "string", + "x-agent": true + }, + "timezone": { + "description": "Timezone is an IANA zone, e.g. Asia/Shanghai; empty means UTC.", + "type": "string", + "x-agent": true + }, + "type": { + "description": "Type is cron or once.", + "type": "string", + "x-agent": true + } + } + }, "github_com_Tencent_WeKnora_internal_types.COSEngineConfig": { "type": "object", "properties": { @@ -26055,6 +27357,14 @@ const docTemplate = `{ "github_com_Tencent_WeKnora_internal_types.CustomAgentConfig": { "type": "object", "properties": { + "access_level": { + "description": "AccessLevel is the highest access level a run of this agent gets: how\nfar it may change data (MCP tools, Wiki writes) without asking. Empty\nmeans auto_write. The WeKnora assistant uses the workspace's assistant\nceiling instead.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ] + }, "agent_mode": { "description": "===== Basic Settings =====\nAgent mode: \"quick-answer\" for RAG mode, \"smart-reasoning\" for ReAct agent mode", "type": "string", @@ -26194,7 +27504,7 @@ const docTemplate = `{ "type": "integer" }, "max_completion_tokens": { - "description": "Maximum completion tokens. Quick-answer uses this for the RAG answer.\nSmart-reasoning ReAct rounds send this value as-is (zero becomes\nDefaultMaxCompletionTokens at call time: 4096, or 24576 with a sandbox).", + "description": "Maximum completion tokens. Quick-answer uses this for the RAG answer.\nSmart-reasoning ReAct rounds send this value as-is (zero becomes\nDefaultMaxCompletionTokens at call time: 24576 for smart reasoning).", "type": "integer" }, "max_iterations": { @@ -29501,6 +30811,14 @@ const docTemplate = `{ "github_com_Tencent_WeKnora_internal_types.MCPTool": { "type": "object", "properties": { + "annotations": { + "description": "Annotations are the hints the service declares in tools/list. They come\nfrom outside and only seed the tool's risk.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations" + } + ] + }, "description": { "type": "string", "x-agent": true, @@ -29521,6 +30839,17 @@ const docTemplate = `{ } } }, + "github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations": { + "type": "object", + "properties": { + "destructiveHint": { + "type": "boolean" + }, + "readOnlyHint": { + "type": "boolean" + } + } + }, "github_com_Tencent_WeKnora_internal_types.MCPTransportType": { "type": "string", "enum": [ @@ -29952,6 +31281,10 @@ const docTemplate = `{ "description": "Channel indicates the source channel of this message (e.g., \"web\", \"api\", \"im\")", "type": "string" }, + "collaboration_status": { + "description": "CollaborationStatus is projected from durable collaboration state at read\ntime, including completed tasks after the transient stream has expired.", + "type": "object" + }, "content": { "description": "Message text content", "type": "string", @@ -29965,6 +31298,12 @@ const docTemplate = `{ "x-agent": true, "x-agent-response": true }, + "delegated_prompts": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + } + }, "deleted_at": { "description": "Soft delete timestamp", "allOf": [ @@ -30017,12 +31356,14 @@ const docTemplate = `{ "type": "string" }, "pending_prompt": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + }, + "prompt_history": { "description": "PendingPrompt is the prompt an awaiting_input message waits on. The\nmessage list fills it in for the prompt's owner; it is never stored.", - "allOf": [ - { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" - } - ] + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + } }, "request_id": { "description": "Request identifier for tracking API requests", @@ -31320,9 +32661,15 @@ const docTemplate = `{ "github_com_Tencent_WeKnora_internal_types.PendingPromptView": { "type": "object", "properties": { + "close_reason": { + "type": "string" + }, "created_at": { "type": "string" }, + "delegated_task": { + "type": "string" + }, "expires_at": { "type": "string" }, @@ -31335,6 +32682,12 @@ const docTemplate = `{ "request": { "type": "object" }, + "response": { + "type": "object" + }, + "status": { + "type": "string" + }, "tool_call_id": { "type": "string" } @@ -35939,6 +37292,105 @@ const docTemplate = `{ } } }, + "internal_handler.CreateAutomationRequest": { + "type": "object", + "required": [ + "instruction", + "name", + "trigger" + ], + "properties": { + "access_level": { + "description": "How far runs may change data without asking; default confirm", + "enum": [ + "read_only", + "confirm", + "auto_write" + ], + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "Agent that runs it, from agent.list; empty runs the WeKnora assistant", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "How long a run waits for an approval before it fails, in minutes; default 1440", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "Whether each per_run conversation gets the last successful answer", + "type": "boolean", + "x-agent": true + }, + "description": { + "description": "What it is for", + "type": "string", + "x-agent": true + }, + "instruction": { + "description": "The task, sent as the user message of each run. May name now,\nlast_run_at, last_success_at, run_id or automation_name inside double\ncurly braces to have it filled in", + "type": "string", + "x-agent": true, + "x-agent-max-bytes": "32000" + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "description": "What happens to runs missed while the service was down; default skip", + "type": "string", + "enum": [ + "skip", + "run_once" + ], + "x-agent": true + }, + "name": { + "description": "What the automation is called", + "type": "string", + "x-agent": true + }, + "notify_on_success": { + "description": "Whether a successful run notifies the owner; failures always do", + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "description": "What happens when a run is due while the previous one is still going; default skip", + "type": "string", + "enum": [ + "skip", + "queue" + ], + "x-agent": true + }, + "session_mode": { + "description": "per_run (default) starts a new conversation each run; persistent keeps one", + "type": "string", + "enum": [ + "per_run", + "persistent" + ], + "x-agent": true + }, + "trigger": { + "description": "When it runs", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, "internal_handler.CreateKnowledgeFromURLRequest": { "type": "object", "required": [ @@ -39645,6 +41097,36 @@ const docTemplate = `{ } } }, + "internal_handler.ValidateTriggerRequest": { + "type": "object", + "required": [ + "trigger" + ], + "properties": { + "trigger": { + "description": "The trigger to check", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, + "internal_handler.ValidateTriggerResult": { + "type": "object", + "properties": { + "next_runs": { + "description": "The next times the trigger fires, in UTC", + "type": "array", + "items": { + "type": "string" + }, + "x-agent": true + } + } + }, "internal_handler.WebSearchProviderTestResponse": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 5ae09e89..ae103ed0 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -78,6 +78,88 @@ } } }, + "/agent/grants": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "列出当前用户在某个会话(根会话)中通过“本会话允许”记住的授权,包括其委派子任务上批准的授权。", + "produces": [ + "application/json" + ], + "tags": [ + "Agent" + ], + "summary": "列出会话内的 Agent 授权", + "parameters": [ + { + "type": "string", + "description": "根会话 ID", + "name": "session_id", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "授权列表", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "400": { + "description": "请求参数错误", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, + "/agent/grants/{id}": { + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "撤销当前用户的一条授权;之后同类调用会重新询问。", + "produces": [ + "application/json" + ], + "tags": [ + "Agent" + ], + "summary": "撤销 Agent 授权", + "parameters": [ + { + "type": "string", + "description": "授权 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "撤销结果", + "schema": { + "type": "object", + "additionalProperties": true + } + }, + "404": { + "description": "授权不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + } + } + }, "/agent/mcp-oauth-resolutions/{pending_id}": { "post": { "security": [ @@ -1825,6 +1907,801 @@ } } }, + "/automation-runs/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "获取运行记录", + "parameters": [ + { + "type": "string", + "description": "运行 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + } + } + } + }, + "/automation-runs/{id}/cancel": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "排队或等待审批的运行立即结束;执行中的运行在下一次检查时停止", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "停止运行", + "parameters": [ + { + "type": "string", + "description": "运行 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + } + } + } + }, + "/automations": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "description": "列出当前用户在本空间创建的自动化(定时任务),最新的在前", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "列出我的自动化", + "responses": { + "200": { + "description": "自动化列表", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.list", + "max_items": 100, + "risk": "read" + }, + "x-agent-hint": "Lists the user's automations: scheduled tasks an agent runs on their behalf, with next and last run." + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "创建一个按计划由 Agent 以当前用户身份运行的任务", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "创建自动化", + "parameters": [ + { + "description": "自动化", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.CreateAutomationRequest" + } + } + ], + "responses": { + "201": { + "description": "创建的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "400": { + "description": "参数不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.create", + "label_param": "name", + "risk": "write", + "role": "viewer" + }, + "x-agent-hint": "Creates an automation the user runs as. Turn the user's wording into a cron expression (five fields, minute first) and an IANA timezone, and check it with automation.validate_trigger first, telling the user the next run times it returns. Runs are unattended: write the instruction as a complete task, since nobody can answer questions during a run. access_level defaults to confirm, where each change waits for the user's approval; only set auto_write when the user asks for it." + } + }, + "/automations/validate-trigger": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "校验 cron 或一次性触发器,返回未来 3 次触发时间", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "校验触发器", + "parameters": [ + { + "description": "触发器", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/internal_handler.ValidateTriggerRequest" + } + } + ], + "responses": { + "200": { + "description": "未来触发时间", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/internal_handler.ValidateTriggerResult" + } + } + } + ] + } + }, + "400": { + "description": "触发器不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.validate_trigger", + "risk": "probe" + }, + "x-agent-hint": "Checks a trigger and returns its next three run times in UTC; convert them to the trigger's timezone for the user." + } + }, + "/automations/{id}": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "获取自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "404": { + "description": "不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.get", + "risk": "read" + }, + "x-agent-hint": "Returns one automation, including its instruction." + }, + "put": { + "security": [ + { + "Bearer": [] + } + ], + "description": "只修改请求中出现的字段,其余保持不变", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "修改自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "要修改的字段", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationPatch" + } + } + ], + "responses": { + "200": { + "description": "修改后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + }, + "400": { + "description": "参数不合法", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.update", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Changes the listed fields of an automation; a field left out is kept. Check a new trigger with automation.validate_trigger first. Use automation.pause and automation.resume to switch it off and on." + }, + "delete": { + "security": [ + { + "Bearer": [] + } + ], + "description": "停止进行中的运行,删除自动化及其运行记录、会话和长期授权", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "删除自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "删除成功", + "schema": { + "$ref": "#/definitions/internal_handler.SuccessResponse" + } + }, + "404": { + "description": "不存在", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "id": "automation.delete", + "label": "name", + "risk": "destructive", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Deletes an automation with its run history and conversations. Cannot be undone; automation.pause keeps it." + } + }, + "/automations/{id}/grant-candidates": { + "get": { + "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 + } + } + } + } + }, + "/automations/{id}/grants": { + "get": { + "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 + } + } + } + }, + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "让以后的运行无需确认即可执行某次运行请求过审批的调用;Agent 配置或所有者角色变化后失效", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "添加长期授权", + "parameters": [ + { + "type": "string", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "description": "{prompt_id}", + "name": "request", + "in": "body", + "required": true, + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "授权", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/automations/{id}/pause": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "停止按计划触发;进行中的运行不受影响", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "暂停自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "暂停后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.pause", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Stops an automation from running on schedule until automation.resume." + } + }, + "/automations/{id}/resume": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "从现在起重新按计划触发,并清零连续失败计数", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "恢复自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "恢复后的自动化", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.Automation" + } + } + } + ] + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.resume", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Schedules a paused automation again from now; missed runs are not caught up." + } + }, + "/automations/{id}/run": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "排队一次手动运行;已有运行在排队或进行中时拒绝", + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "立即运行自动化", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "202": { + "description": "排队的运行", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.DataResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + ] + } + }, + "409": { + "description": "已有运行", + "schema": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError" + } + } + }, + "x-agent": { + "always_confirm": true, + "id": "automation.run_now", + "label": "name", + "risk": "write", + "role": "viewer", + "target": "automation.get" + }, + "x-agent-hint": "Queues a run now, in the background; follow it with automation.list_runs." + } + }, + "/automations/{id}/runs": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "自动化" + ], + "summary": "列出运行记录", + "parameters": [ + { + "type": "string", + "x-agent": "automation_id", + "description": "自动化 ID", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "integer", + "x-agent": true, + "description": "页码,从 1 开始", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "x-agent": true, + "x-agent-maximum": "20", + "description": "每页条数,最多 100", + "name": "page_size", + "in": "query" + } + ], + "responses": { + "200": { + "description": "运行记录", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/internal_handler.PageResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun" + } + } + } + } + ] + } + } + }, + "x-agent": { + "id": "automation.list_runs", + "risk": "read" + }, + "x-agent-hint": "Lists an automation's runs, newest first, with status, error and the start of the answer." + } + }, "/chunker/preview": { "post": { "security": [ @@ -2590,7 +3467,7 @@ "id": "data_source.get_sync_log", "risk": "read" }, - "x-agent-hint": "Read the current status, counts and errors of a sync_log_id returned by data_source.sync or data_source.list_sync_logs. A started job is not a completed sync." + "x-agent-hint": "Read the current status and counts of a sync_log_id returned by data_source.sync or data_source.list_sync_logs. A started job is not a completed sync. Raw upstream errors are omitted; detailed failures remain on the data source settings page." } }, "/datasource/types": { @@ -2703,7 +3580,7 @@ "id": "data_source.get", "risk": "read" }, - "x-agent-hint": "Read a configured data source and its sync state; credentials and connector configuration are not returned." + "x-agent-hint": "Read a configured data source and its sync state; credentials, connector settings and raw upstream errors are omitted. For detailed failures use the data source settings page." }, "put": { "description": "Update an existing data source configuration", @@ -2847,7 +3724,7 @@ "id": "data_source.list_sync_logs", "risk": "read" }, - "x-agent-hint": "Read recent sync results, counts and errors. Use limit and offset for older records." + "x-agent-hint": "Read recent sync status and counts. Use limit and offset for older records. Raw upstream errors are omitted; detailed failures remain on the data source settings page." } }, "/datasource/{id}/pause": { @@ -12084,7 +12961,7 @@ "ApiKeyAuth": [] } ], - "description": "为指定 MCP 服务下的某个工具更新启用状态和/或人工审批要求。至少提供 require_approval 或 enabled 之一;省略的字段保持原值。", + "description": "为指定 MCP 服务下的某个工具更新启用状态、人工审批要求和/或风险等级。\n至少提供 require_approval、enabled、risk 之一;省略的字段保持原值。\nrisk 为 read/probe/write/destructive,空字符串表示改回按服务注解推断。", "consumes": [ "application/json" ], @@ -12111,7 +12988,7 @@ "required": true }, { - "description": "{require_approval?: bool, enabled?: bool}", + "description": "{require_approval?: bool, enabled?: bool, risk?: string}", "name": "request", "in": "body", "required": true, @@ -14232,6 +15109,84 @@ "x-agent-hint": "Copies a workspace-owned model configuration under a required new display_name. Choose model_id from model.list; builtin models cannot be copied. The upstream model name, connection parameters and saved credentials are copied on the backend; never request or resend credentials. The copy is not the default and does not change agent or knowledge base bindings. Active local models are reused without downloading again; copying an unfinished or failed local model starts a background download, so read the returned model_id with model.get until its status is active or download_failed." } }, + "/notifications": { + "get": { + "security": [ + { + "Bearer": [] + } + ], + "produces": [ + "application/json" + ], + "tags": [ + "通知" + ], + "summary": "列出我的通知", + "parameters": [ + { + "type": "integer", + "description": "条数,最多 100", + "name": "limit", + "in": "query" + }, + { + "type": "boolean", + "description": "只看未读", + "name": "unread", + "in": "query" + } + ], + "responses": { + "200": { + "description": "{items, unread}", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, + "/notifications/read": { + "post": { + "security": [ + { + "Bearer": [] + } + ], + "description": "ids 为空时全部标记已读", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "通知" + ], + "summary": "标记通知已读", + "parameters": [ + { + "description": "{ids}", + "name": "request", + "in": "body", + "schema": { + "type": "object" + } + } + ], + "responses": { + "200": { + "description": "结果", + "schema": { + "type": "object", + "additionalProperties": true + } + } + } + } + }, "/organizations": { "get": { "security": [ @@ -24755,6 +25710,13 @@ "description": "Iteration number (0-indexed)", "type": "integer" }, + "progress": { + "description": "Progress is user-facing commentary from a non-terminal round. Thought stays intact for model replay.", + "type": "string" + }, + "progress_event_id": { + "type": "string" + }, "reasoning_content": { "description": "ReasoningContent stores the OpenAI-protocol reasoning_content emitted by the\nmodel in this round. Persisted on AgentStep so cross-turn replay can put it\nback on the assistant message — required by MiMo / DeepSeek V3.2+ thinking\nmode, ignored by providers that don't recognize the field.", "type": "string" @@ -25245,6 +26207,346 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.Automation": { + "type": "object", + "properties": { + "access_level": { + "description": "AccessLevel is how far runs may change data without asking, capped by\nthe agent's and the workspace's ceilings.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "AgentID is the agent that runs it; the WeKnora assistant's ID runs the\nassistant.", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "ApprovalTimeoutMinutes is how long a run waits for an approval before\nit fails.", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "CarryLastResult adds the last successful answer to each per-run\nconversation.", + "type": "boolean", + "x-agent": true + }, + "consecutive_failures": { + "type": "integer" + }, + "created_at": { + "type": "string" + }, + "description": { + "type": "string", + "x-agent": true + }, + "enabled": { + "type": "boolean", + "x-agent": true, + "x-agent-response": true + }, + "id": { + "type": "string", + "x-agent": "automation_id", + "x-agent-response": true + }, + "instruction": { + "description": "Instruction is the task, sent as the user message of each run after\nits variables are filled in.", + "type": "string", + "x-agent": true, + "x-agent-detail": true + }, + "last_run_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "last_run_status": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "last_success_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "type": "string", + "x-agent": true + }, + "name": { + "type": "string", + "x-agent": true + }, + "next_run_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "notify_on_success": { + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "type": "string", + "x-agent": true + }, + "owner_user_id": { + "description": "OwnerUserID is the account the automation runs as.", + "type": "string" + }, + "paused_reason": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "persistent_session_id": { + "description": "PersistentSessionID is the conversation of a persistent automation,\ncreated on its first run.", + "type": "string" + }, + "session_mode": { + "type": "string", + "x-agent": true + }, + "tenant_id": { + "type": "integer" + }, + "trigger": { + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + }, + "updated_at": { + "type": "string" + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationLimits": { + "type": "object", + "properties": { + "max_duration_minutes": { + "description": "MaxDurationMinutes caps a run's execution time, not counting time spent\nwaiting for approval. 0 uses the default.", + "type": "integer", + "x-agent": true + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationPatch": { + "type": "object", + "properties": { + "access_level": { + "description": "How far runs may change data without asking", + "enum": [ + "read_only", + "confirm", + "auto_write" + ], + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "Agent that runs it, from agent.list; empty runs the WeKnora assistant", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "How long a run waits for an approval before it fails, in minutes", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "Whether each per_run conversation gets the last successful answer", + "type": "boolean", + "x-agent": true + }, + "description": { + "description": "What it is for", + "type": "string", + "x-agent": true + }, + "enabled": { + "description": "Whether it is scheduled; on update use pause and resume instead", + "type": "boolean" + }, + "instruction": { + "description": "The task, sent as the user message of each run. May name now,\nlast_run_at, last_success_at, run_id or automation_name inside double\ncurly braces to have it filled in", + "type": "string", + "x-agent": true, + "x-agent-max-bytes": "32000" + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "description": "What happens to runs missed while the service was down or paused", + "type": "string", + "enum": [ + "skip", + "run_once" + ], + "x-agent": true + }, + "name": { + "description": "What the automation is called", + "type": "string", + "x-agent": true + }, + "notify_on_success": { + "description": "Whether a successful run notifies the owner", + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "description": "What happens when a run is due while the previous one is still going", + "type": "string", + "enum": [ + "skip", + "queue" + ], + "x-agent": true + }, + "session_mode": { + "description": "per_run starts a new conversation each run; persistent keeps one", + "type": "string", + "enum": [ + "per_run", + "persistent" + ], + "x-agent": true + }, + "trigger": { + "description": "When it runs", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationRun": { + "type": "object", + "properties": { + "answer": { + "description": "Answer is the start of the final answer, for listings.", + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "assistant_message_id": { + "type": "string" + }, + "automation_id": { + "type": "string" + }, + "cancel_requested": { + "description": "CancelRequested stops the run at its next check.", + "type": "boolean" + }, + "created_at": { + "type": "string" + }, + "error": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "finished_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "id": { + "type": "string", + "x-agent": "run_id", + "x-agent-response": true + }, + "pending_prompt_id": { + "description": "PendingPromptID is the approval a waiting run is suspended on.", + "type": "string" + }, + "scheduled_at": { + "description": "ScheduledAt is when the run was due; for a manual run, when it was\nasked for.", + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "session_id": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "started_at": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "status": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "tenant_id": { + "type": "integer" + }, + "trigger_kind": { + "type": "string", + "x-agent": true, + "x-agent-response": true + }, + "updated_at": { + "type": "string" + }, + "usage": { + "type": "object" + }, + "user_message_id": { + "description": "UserMessageID and AssistantMessageID are the run's turn in SessionID.", + "type": "string" + } + } + }, + "github_com_Tencent_WeKnora_internal_types.AutomationTrigger": { + "type": "object", + "properties": { + "at": { + "description": "At is when a once trigger fires.", + "type": "string", + "x-agent": true + }, + "expr": { + "description": "Expr is a cron expression: five fields (minute first) or six (seconds\nfirst), or a descriptor such as @daily.", + "type": "string", + "x-agent": true + }, + "timezone": { + "description": "Timezone is an IANA zone, e.g. Asia/Shanghai; empty means UTC.", + "type": "string", + "x-agent": true + }, + "type": { + "description": "Type is cron or once.", + "type": "string", + "x-agent": true + } + } + }, "github_com_Tencent_WeKnora_internal_types.COSEngineConfig": { "type": "object", "properties": { @@ -26048,6 +27350,14 @@ "github_com_Tencent_WeKnora_internal_types.CustomAgentConfig": { "type": "object", "properties": { + "access_level": { + "description": "AccessLevel is the highest access level a run of this agent gets: how\nfar it may change data (MCP tools, Wiki writes) without asking. Empty\nmeans auto_write. The WeKnora assistant uses the workspace's assistant\nceiling instead.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ] + }, "agent_mode": { "description": "===== Basic Settings =====\nAgent mode: \"quick-answer\" for RAG mode, \"smart-reasoning\" for ReAct agent mode", "type": "string", @@ -26187,7 +27497,7 @@ "type": "integer" }, "max_completion_tokens": { - "description": "Maximum completion tokens. Quick-answer uses this for the RAG answer.\nSmart-reasoning ReAct rounds send this value as-is (zero becomes\nDefaultMaxCompletionTokens at call time: 4096, or 24576 with a sandbox).", + "description": "Maximum completion tokens. Quick-answer uses this for the RAG answer.\nSmart-reasoning ReAct rounds send this value as-is (zero becomes\nDefaultMaxCompletionTokens at call time: 24576 for smart reasoning).", "type": "integer" }, "max_iterations": { @@ -29494,6 +30804,14 @@ "github_com_Tencent_WeKnora_internal_types.MCPTool": { "type": "object", "properties": { + "annotations": { + "description": "Annotations are the hints the service declares in tools/list. They come\nfrom outside and only seed the tool's risk.", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations" + } + ] + }, "description": { "type": "string", "x-agent": true, @@ -29514,6 +30832,17 @@ } } }, + "github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations": { + "type": "object", + "properties": { + "destructiveHint": { + "type": "boolean" + }, + "readOnlyHint": { + "type": "boolean" + } + } + }, "github_com_Tencent_WeKnora_internal_types.MCPTransportType": { "type": "string", "enum": [ @@ -29945,6 +31274,10 @@ "description": "Channel indicates the source channel of this message (e.g., \"web\", \"api\", \"im\")", "type": "string" }, + "collaboration_status": { + "description": "CollaborationStatus is projected from durable collaboration state at read\ntime, including completed tasks after the transient stream has expired.", + "type": "object" + }, "content": { "description": "Message text content", "type": "string", @@ -29958,6 +31291,12 @@ "x-agent": true, "x-agent-response": true }, + "delegated_prompts": { + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + } + }, "deleted_at": { "description": "Soft delete timestamp", "allOf": [ @@ -30010,12 +31349,14 @@ "type": "string" }, "pending_prompt": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + }, + "prompt_history": { "description": "PendingPrompt is the prompt an awaiting_input message waits on. The\nmessage list fills it in for the prompt's owner; it is never stored.", - "allOf": [ - { - "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" - } - ] + "type": "array", + "items": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView" + } }, "request_id": { "description": "Request identifier for tracking API requests", @@ -31313,9 +32654,15 @@ "github_com_Tencent_WeKnora_internal_types.PendingPromptView": { "type": "object", "properties": { + "close_reason": { + "type": "string" + }, "created_at": { "type": "string" }, + "delegated_task": { + "type": "string" + }, "expires_at": { "type": "string" }, @@ -31328,6 +32675,12 @@ "request": { "type": "object" }, + "response": { + "type": "object" + }, + "status": { + "type": "string" + }, "tool_call_id": { "type": "string" } @@ -35932,6 +37285,105 @@ } } }, + "internal_handler.CreateAutomationRequest": { + "type": "object", + "required": [ + "instruction", + "name", + "trigger" + ], + "properties": { + "access_level": { + "description": "How far runs may change data without asking; default confirm", + "enum": [ + "read_only", + "confirm", + "auto_write" + ], + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel" + } + ], + "x-agent": true + }, + "agent_id": { + "description": "Agent that runs it, from agent.list; empty runs the WeKnora assistant", + "type": "string", + "x-agent": true + }, + "approval_timeout_minutes": { + "description": "How long a run waits for an approval before it fails, in minutes; default 1440", + "type": "integer", + "x-agent": true + }, + "carry_last_result": { + "description": "Whether each per_run conversation gets the last successful answer", + "type": "boolean", + "x-agent": true + }, + "description": { + "description": "What it is for", + "type": "string", + "x-agent": true + }, + "instruction": { + "description": "The task, sent as the user message of each run. May name now,\nlast_run_at, last_success_at, run_id or automation_name inside double\ncurly braces to have it filled in", + "type": "string", + "x-agent": true, + "x-agent-max-bytes": "32000" + }, + "limits": { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits" + }, + "misfire_policy": { + "description": "What happens to runs missed while the service was down; default skip", + "type": "string", + "enum": [ + "skip", + "run_once" + ], + "x-agent": true + }, + "name": { + "description": "What the automation is called", + "type": "string", + "x-agent": true + }, + "notify_on_success": { + "description": "Whether a successful run notifies the owner; failures always do", + "type": "boolean", + "x-agent": true + }, + "overlap_policy": { + "description": "What happens when a run is due while the previous one is still going; default skip", + "type": "string", + "enum": [ + "skip", + "queue" + ], + "x-agent": true + }, + "session_mode": { + "description": "per_run (default) starts a new conversation each run; persistent keeps one", + "type": "string", + "enum": [ + "per_run", + "persistent" + ], + "x-agent": true + }, + "trigger": { + "description": "When it runs", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, "internal_handler.CreateKnowledgeFromURLRequest": { "type": "object", "required": [ @@ -39638,6 +41090,36 @@ } } }, + "internal_handler.ValidateTriggerRequest": { + "type": "object", + "required": [ + "trigger" + ], + "properties": { + "trigger": { + "description": "The trigger to check", + "allOf": [ + { + "$ref": "#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger" + } + ], + "x-agent": true + } + } + }, + "internal_handler.ValidateTriggerResult": { + "type": "object", + "properties": { + "next_runs": { + "description": "The next times the trigger fires, in UTC", + "type": "array", + "items": { + "type": "string" + }, + "x-agent": true + } + } + }, "internal_handler.WebSearchProviderTestResponse": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index ffa67070..e2c2b0a4 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1344,6 +1344,12 @@ definitions: iteration: description: Iteration number (0-indexed) type: integer + progress: + description: Progress is user-facing commentary from a non-terminal round. + Thought stays intact for model replay. + type: string + progress_event_id: + type: string reasoning_content: description: |- ReasoningContent stores the OpenAI-protocol reasoning_content emitted by the @@ -1744,6 +1750,280 @@ definitions: type: boolean x-agent: auto_tag_skip_if_tagged type: object + github_com_Tencent_WeKnora_internal_types.Automation: + properties: + access_level: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel' + description: |- + AccessLevel is how far runs may change data without asking, capped by + the agent's and the workspace's ceilings. + x-agent: true + agent_id: + description: |- + AgentID is the agent that runs it; the WeKnora assistant's ID runs the + assistant. + type: string + x-agent: true + approval_timeout_minutes: + description: |- + ApprovalTimeoutMinutes is how long a run waits for an approval before + it fails. + type: integer + x-agent: true + carry_last_result: + description: |- + CarryLastResult adds the last successful answer to each per-run + conversation. + type: boolean + x-agent: true + consecutive_failures: + type: integer + created_at: + type: string + description: + type: string + x-agent: true + enabled: + type: boolean + x-agent: true + x-agent-response: true + id: + type: string + x-agent: automation_id + x-agent-response: true + instruction: + description: |- + Instruction is the task, sent as the user message of each run after + its variables are filled in. + type: string + x-agent: true + x-agent-detail: true + last_run_at: + type: string + x-agent: true + x-agent-response: true + last_run_status: + type: string + x-agent: true + x-agent-response: true + last_success_at: + type: string + x-agent: true + x-agent-response: true + limits: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits' + misfire_policy: + type: string + x-agent: true + name: + type: string + x-agent: true + next_run_at: + type: string + x-agent: true + x-agent-response: true + notify_on_success: + type: boolean + x-agent: true + overlap_policy: + type: string + x-agent: true + owner_user_id: + description: OwnerUserID is the account the automation runs as. + type: string + paused_reason: + type: string + x-agent: true + x-agent-response: true + persistent_session_id: + description: |- + PersistentSessionID is the conversation of a persistent automation, + created on its first run. + type: string + session_mode: + type: string + x-agent: true + tenant_id: + type: integer + trigger: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger' + x-agent: true + updated_at: + type: string + type: object + github_com_Tencent_WeKnora_internal_types.AutomationLimits: + properties: + max_duration_minutes: + description: |- + MaxDurationMinutes caps a run's execution time, not counting time spent + waiting for approval. 0 uses the default. + type: integer + x-agent: true + type: object + github_com_Tencent_WeKnora_internal_types.AutomationPatch: + properties: + access_level: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel' + description: How far runs may change data without asking + enum: + - read_only + - confirm + - auto_write + x-agent: true + agent_id: + description: Agent that runs it, from agent.list; empty runs the WeKnora assistant + type: string + x-agent: true + approval_timeout_minutes: + description: How long a run waits for an approval before it fails, in minutes + type: integer + x-agent: true + carry_last_result: + description: Whether each per_run conversation gets the last successful answer + type: boolean + x-agent: true + description: + description: What it is for + type: string + x-agent: true + enabled: + description: Whether it is scheduled; on update use pause and resume instead + type: boolean + instruction: + description: |- + The task, sent as the user message of each run. May name now, + last_run_at, last_success_at, run_id or automation_name inside double + curly braces to have it filled in + type: string + x-agent: true + x-agent-max-bytes: "32000" + limits: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits' + misfire_policy: + description: What happens to runs missed while the service was down or paused + enum: + - skip + - run_once + type: string + x-agent: true + name: + description: What the automation is called + type: string + x-agent: true + notify_on_success: + description: Whether a successful run notifies the owner + type: boolean + x-agent: true + overlap_policy: + description: What happens when a run is due while the previous one is still + going + enum: + - skip + - queue + type: string + x-agent: true + session_mode: + description: per_run starts a new conversation each run; persistent keeps + one + enum: + - per_run + - persistent + type: string + x-agent: true + trigger: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger' + description: When it runs + x-agent: true + type: object + github_com_Tencent_WeKnora_internal_types.AutomationRun: + properties: + answer: + description: Answer is the start of the final answer, for listings. + type: string + x-agent: true + x-agent-response: true + assistant_message_id: + type: string + automation_id: + type: string + cancel_requested: + description: CancelRequested stops the run at its next check. + type: boolean + created_at: + type: string + error: + type: string + x-agent: true + x-agent-response: true + finished_at: + type: string + x-agent: true + x-agent-response: true + id: + type: string + x-agent: run_id + x-agent-response: true + pending_prompt_id: + description: PendingPromptID is the approval a waiting run is suspended on. + type: string + scheduled_at: + description: |- + ScheduledAt is when the run was due; for a manual run, when it was + asked for. + type: string + x-agent: true + x-agent-response: true + session_id: + type: string + x-agent: true + x-agent-response: true + started_at: + type: string + x-agent: true + x-agent-response: true + status: + type: string + x-agent: true + x-agent-response: true + tenant_id: + type: integer + trigger_kind: + type: string + x-agent: true + x-agent-response: true + updated_at: + type: string + usage: + type: object + user_message_id: + description: UserMessageID and AssistantMessageID are the run's turn in SessionID. + type: string + type: object + github_com_Tencent_WeKnora_internal_types.AutomationTrigger: + properties: + at: + description: At is when a once trigger fires. + type: string + x-agent: true + expr: + description: |- + Expr is a cron expression: five fields (minute first) or six (seconds + first), or a descriptor such as @daily. + type: string + x-agent: true + timezone: + description: Timezone is an IANA zone, e.g. Asia/Shanghai; empty means UTC. + type: string + x-agent: true + type: + description: Type is cron or once. + type: string + x-agent: true + type: object github_com_Tencent_WeKnora_internal_types.COSEngineConfig: properties: app_id: @@ -2392,6 +2672,14 @@ definitions: type: object github_com_Tencent_WeKnora_internal_types.CustomAgentConfig: properties: + access_level: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel' + description: |- + AccessLevel is the highest access level a run of this agent gets: how + far it may change data (MCP tools, Wiki writes) without asking. Empty + means auto_write. The WeKnora assistant uses the workspace's assistant + ceiling instead. agent_mode: description: |- ===== Basic Settings ===== @@ -2554,7 +2842,7 @@ definitions: description: |- Maximum completion tokens. Quick-answer uses this for the RAG answer. Smart-reasoning ReAct rounds send this value as-is (zero becomes - DefaultMaxCompletionTokens at call time: 4096, or 24576 with a sandbox). + DefaultMaxCompletionTokens at call time: 24576 for smart reasoning). type: integer max_iterations: description: |- @@ -5156,6 +5444,12 @@ definitions: type: object github_com_Tencent_WeKnora_internal_types.MCPTool: properties: + annotations: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations' + description: |- + Annotations are the hints the service declares in tools/list. They come + from outside and only seed the tool's risk. description: type: string x-agent: true @@ -5172,6 +5466,13 @@ definitions: type: boolean x-agent: true type: object + github_com_Tencent_WeKnora_internal_types.MCPToolAnnotations: + properties: + destructiveHint: + type: boolean + readOnlyHint: + type: boolean + type: object github_com_Tencent_WeKnora_internal_types.MCPTransportType: enum: - sse @@ -5551,6 +5852,11 @@ definitions: description: Channel indicates the source channel of this message (e.g., "web", "api", "im") type: string + collaboration_status: + description: |- + CollaborationStatus is projected from durable collaboration state at read + time, including completed tasks after the transient stream has expired. + type: object content: description: Message text content type: string @@ -5562,6 +5868,10 @@ definitions: type: string x-agent: true x-agent-response: true + delegated_prompts: + items: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView' + type: array deleted_at: allOf: - $ref: '#/definitions/gorm.DeletedAt' @@ -5606,11 +5916,14 @@ definitions: turn. It is useful for reproducibility and suggestion generation. type: string pending_prompt: - allOf: - - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView' + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView' + prompt_history: description: |- PendingPrompt is the prompt an awaiting_input message waits on. The message list fills it in for the prompt's owner; it is never stored. + items: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.PendingPromptView' + type: array request_id: description: Request identifier for tracking API requests type: string @@ -6597,8 +6910,12 @@ definitions: type: object github_com_Tencent_WeKnora_internal_types.PendingPromptView: properties: + close_reason: + type: string created_at: type: string + delegated_task: + type: string expires_at: type: string id: @@ -6607,6 +6924,10 @@ definitions: type: string request: type: object + response: + type: object + status: + type: string tool_call_id: type: string type: object @@ -10284,6 +10605,87 @@ definitions: required: - name type: object + internal_handler.CreateAutomationRequest: + properties: + access_level: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AssistantAccessLevel' + description: How far runs may change data without asking; default confirm + enum: + - read_only + - confirm + - auto_write + x-agent: true + agent_id: + description: Agent that runs it, from agent.list; empty runs the WeKnora assistant + type: string + x-agent: true + approval_timeout_minutes: + description: How long a run waits for an approval before it fails, in minutes; + default 1440 + type: integer + x-agent: true + carry_last_result: + description: Whether each per_run conversation gets the last successful answer + type: boolean + x-agent: true + description: + description: What it is for + type: string + x-agent: true + instruction: + description: |- + The task, sent as the user message of each run. May name now, + last_run_at, last_success_at, run_id or automation_name inside double + curly braces to have it filled in + type: string + x-agent: true + x-agent-max-bytes: "32000" + limits: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationLimits' + misfire_policy: + description: What happens to runs missed while the service was down; default + skip + enum: + - skip + - run_once + type: string + x-agent: true + name: + description: What the automation is called + type: string + x-agent: true + notify_on_success: + description: Whether a successful run notifies the owner; failures always + do + type: boolean + x-agent: true + overlap_policy: + description: What happens when a run is due while the previous one is still + going; default skip + enum: + - skip + - queue + type: string + x-agent: true + session_mode: + description: per_run (default) starts a new conversation each run; persistent + keeps one + enum: + - per_run + - persistent + type: string + x-agent: true + trigger: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger' + description: When it runs + x-agent: true + required: + - instruction + - name + - trigger + type: object internal_handler.CreateKnowledgeFromURLRequest: properties: channel: @@ -12950,6 +13352,25 @@ definitions: user: $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.UserInfo' type: object + internal_handler.ValidateTriggerRequest: + properties: + trigger: + allOf: + - $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationTrigger' + description: The trigger to check + x-agent: true + required: + - trigger + type: object + internal_handler.ValidateTriggerResult: + properties: + next_runs: + description: The next times the trigger fires, in UTC + items: + type: string + type: array + x-agent: true + type: object internal_handler.WebSearchProviderTestResponse: properties: error: @@ -13941,6 +14362,58 @@ paths: summary: Agent问答 tags: - 问答 + /agent/grants: + get: + description: 列出当前用户在某个会话(根会话)中通过“本会话允许”记住的授权,包括其委派子任务上批准的授权。 + parameters: + - description: 根会话 ID + in: query + name: session_id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 授权列表 + schema: + additionalProperties: true + type: object + "400": + description: 请求参数错误 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 列出会话内的 Agent 授权 + tags: + - Agent + /agent/grants/{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 + "404": + description: 授权不存在 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 撤销 Agent 授权 + tags: + - Agent /agent/mcp-oauth-resolutions/{pending_id}: post: consumes: @@ -15072,6 +15545,509 @@ paths: summary: 验证令牌 tags: - 认证 + /automation-runs/{id}: + get: + parameters: + - description: 运行 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 运行记录 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun' + type: object + security: + - Bearer: [] + summary: 获取运行记录 + tags: + - 自动化 + /automation-runs/{id}/cancel: + post: + description: 排队或等待审批的运行立即结束;执行中的运行在下一次检查时停止 + parameters: + - description: 运行 ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: 运行记录 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun' + type: object + security: + - Bearer: [] + summary: 停止运行 + tags: + - 自动化 + /automations: + get: + description: 列出当前用户在本空间创建的自动化(定时任务),最新的在前 + produces: + - application/json + responses: + "200": + description: 自动化列表 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + items: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: array + type: object + security: + - Bearer: [] + summary: 列出我的自动化 + tags: + - 自动化 + x-agent: + id: automation.list + max_items: 100 + risk: read + x-agent-hint: 'Lists the user''s automations: scheduled tasks an agent runs + on their behalf, with next and last run.' + post: + consumes: + - application/json + description: 创建一个按计划由 Agent 以当前用户身份运行的任务 + parameters: + - description: 自动化 + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler.CreateAutomationRequest' + produces: + - application/json + responses: + "201": + description: 创建的自动化 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: object + "400": + description: 参数不合法 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 创建自动化 + tags: + - 自动化 + x-agent: + always_confirm: true + id: automation.create + label_param: name + risk: write + role: viewer + x-agent-hint: 'Creates an automation the user runs as. Turn the user''s wording + into a cron expression (five fields, minute first) and an IANA timezone, and + check it with automation.validate_trigger first, telling the user the next + run times it returns. Runs are unattended: write the instruction as a complete + task, since nobody can answer questions during a run. access_level defaults + to confirm, where each change waits for the user''s approval; only set auto_write + when the user asks for it.' + /automations/{id}: + delete: + description: 停止进行中的运行,删除自动化及其运行记录、会话和长期授权 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + produces: + - application/json + responses: + "200": + description: 删除成功 + schema: + $ref: '#/definitions/internal_handler.SuccessResponse' + "404": + description: 不存在 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 删除自动化 + tags: + - 自动化 + x-agent: + id: automation.delete + label: name + risk: destructive + role: viewer + target: automation.get + x-agent-hint: Deletes an automation with its run history and conversations. + Cannot be undone; automation.pause keeps it. + get: + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + produces: + - application/json + responses: + "200": + description: 自动化 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: object + "404": + description: 不存在 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 获取自动化 + tags: + - 自动化 + x-agent: + id: automation.get + risk: read + x-agent-hint: Returns one automation, including its instruction. + put: + consumes: + - application/json + description: 只修改请求中出现的字段,其余保持不变 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + - description: 要修改的字段 + in: body + name: request + required: true + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationPatch' + produces: + - application/json + responses: + "200": + description: 修改后的自动化 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: object + "400": + description: 参数不合法 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 修改自动化 + tags: + - 自动化 + x-agent: + always_confirm: true + id: automation.update + label: name + risk: write + role: viewer + target: automation.get + x-agent-hint: Changes the listed fields of an automation; a field left out is + kept. Check a new trigger with automation.validate_trigger first. Use automation.pause + and automation.resume to switch it off and on. + /automations/{id}/grant-candidates: + get: + 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: + - 自动化 + /automations/{id}/grants: + get: + 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: + - 自动化 + post: + consumes: + - application/json + description: 让以后的运行无需确认即可执行某次运行请求过审批的调用;Agent 配置或所有者角色变化后失效 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + - description: '{prompt_id}' + in: body + name: request + required: true + schema: + type: object + produces: + - application/json + responses: + "200": + description: 授权 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 添加长期授权 + tags: + - 自动化 + /automations/{id}/pause: + post: + description: 停止按计划触发;进行中的运行不受影响 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + produces: + - application/json + responses: + "200": + description: 暂停后的自动化 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: object + security: + - Bearer: [] + summary: 暂停自动化 + tags: + - 自动化 + x-agent: + id: automation.pause + label: name + risk: write + role: viewer + target: automation.get + x-agent-hint: Stops an automation from running on schedule until automation.resume. + /automations/{id}/resume: + post: + description: 从现在起重新按计划触发,并清零连续失败计数 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + produces: + - application/json + responses: + "200": + description: 恢复后的自动化 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.Automation' + type: object + security: + - Bearer: [] + summary: 恢复自动化 + tags: + - 自动化 + x-agent: + always_confirm: true + id: automation.resume + label: name + risk: write + role: viewer + target: automation.get + x-agent-hint: Schedules a paused automation again from now; missed runs are + not caught up. + /automations/{id}/run: + post: + description: 排队一次手动运行;已有运行在排队或进行中时拒绝 + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + produces: + - application/json + responses: + "202": + description: 排队的运行 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun' + type: object + "409": + description: 已有运行 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 立即运行自动化 + tags: + - 自动化 + x-agent: + always_confirm: true + id: automation.run_now + label: name + risk: write + role: viewer + target: automation.get + x-agent-hint: Queues a run now, in the background; follow it with automation.list_runs. + /automations/{id}/runs: + get: + parameters: + - description: 自动化 ID + in: path + name: id + required: true + type: string + x-agent: automation_id + - description: 页码,从 1 开始 + in: query + name: page + type: integer + x-agent: true + - description: 每页条数,最多 100 + in: query + name: page_size + type: integer + x-agent: true + x-agent-maximum: "20" + produces: + - application/json + responses: + "200": + description: 运行记录 + schema: + allOf: + - $ref: '#/definitions/internal_handler.PageResponse' + - properties: + data: + items: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_types.AutomationRun' + type: array + type: object + security: + - Bearer: [] + summary: 列出运行记录 + tags: + - 自动化 + x-agent: + id: automation.list_runs + risk: read + x-agent-hint: Lists an automation's runs, newest first, with status, error and + the start of the answer. + /automations/validate-trigger: + post: + consumes: + - application/json + description: 校验 cron 或一次性触发器,返回未来 3 次触发时间 + parameters: + - description: 触发器 + in: body + name: request + required: true + schema: + $ref: '#/definitions/internal_handler.ValidateTriggerRequest' + produces: + - application/json + responses: + "200": + description: 未来触发时间 + schema: + allOf: + - $ref: '#/definitions/internal_handler.DataResponse' + - properties: + data: + $ref: '#/definitions/internal_handler.ValidateTriggerResult' + type: object + "400": + description: 触发器不合法 + schema: + $ref: '#/definitions/github_com_Tencent_WeKnora_internal_errors.AppError' + security: + - Bearer: [] + summary: 校验触发器 + tags: + - 自动化 + x-agent: + id: automation.validate_trigger + risk: probe + x-agent-hint: Checks a trigger and returns its next three run times in UTC; + convert them to the trigger's timezone for the user. /chunker/preview: post: consumes: @@ -15599,8 +16575,9 @@ paths: x-agent: id: data_source.get risk: read - x-agent-hint: Read a configured data source and its sync state; credentials - and connector configuration are not returned. + x-agent-hint: Read a configured data source and its sync state; credentials, + connector settings and raw upstream errors are omitted. For detailed failures + use the data source settings page. put: consumes: - application/json @@ -15679,8 +16656,9 @@ paths: x-agent: id: data_source.list_sync_logs risk: read - x-agent-hint: Read recent sync results, counts and errors. Use limit and offset - for older records. + x-agent-hint: Read recent sync status and counts. Use limit and offset for older + records. Raw upstream errors are omitted; detailed failures remain on the + data source settings page. /datasource/{id}/pause: post: description: Pause a data source's scheduled syncs @@ -15966,9 +16944,10 @@ paths: x-agent: id: data_source.get_sync_log risk: read - x-agent-hint: Read the current status, counts and errors of a sync_log_id returned - by data_source.sync or data_source.list_sync_logs. A started job is not a - completed sync. + x-agent-hint: Read the current status and counts of a sync_log_id returned by + data_source.sync or data_source.list_sync_logs. A started job is not a completed + sync. Raw upstream errors are omitted; detailed failures remain on the data + source settings page. /datasource/types: get: description: Get list of available data source connectors @@ -21733,8 +22712,10 @@ paths: put: consumes: - application/json - description: 为指定 MCP 服务下的某个工具更新启用状态和/或人工审批要求。至少提供 require_approval 或 enabled - 之一;省略的字段保持原值。 + description: |- + 为指定 MCP 服务下的某个工具更新启用状态、人工审批要求和/或风险等级。 + 至少提供 require_approval、enabled、risk 之一;省略的字段保持原值。 + risk 为 read/probe/write/destructive,空字符串表示改回按服务注解推断。 parameters: - description: MCP 服务 ID in: path @@ -21746,7 +22727,7 @@ paths: name: tool_name required: true type: string - - description: '{require_approval?: bool, enabled?: bool}' + - description: '{require_approval?: bool, enabled?: bool, risk?: string}' in: body name: request required: true @@ -23103,6 +24084,54 @@ paths: summary: 检查 WeKnoraCloud 凭证状态 tags: - WeKnoraCloud + /notifications: + get: + parameters: + - description: 条数,最多 100 + in: query + name: limit + type: integer + - description: 只看未读 + in: query + name: unread + type: boolean + produces: + - application/json + responses: + "200": + description: '{items, unread}' + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 列出我的通知 + tags: + - 通知 + /notifications/read: + post: + consumes: + - application/json + description: ids 为空时全部标记已读 + parameters: + - description: '{ids}' + in: body + name: request + schema: + type: object + produces: + - application/json + responses: + "200": + description: 结果 + schema: + additionalProperties: true + type: object + security: + - Bearer: [] + summary: 标记通知已读 + tags: + - 通知 /organizations: get: description: 获取当前空间所属的所有组织,并附带各空间内知识库/智能体数量 diff --git a/frontend/src/api/automation.ts b/frontend/src/api/automation.ts new file mode 100644 index 00000000..ebef9259 --- /dev/null +++ b/frontend/src/api/automation.ts @@ -0,0 +1,225 @@ +import { get, post, put, del } from '@/utils/request' +import type { AssistantAccessLevel } from '@/api/assistant' + +// Shapes mirror internal/types/automation.go. Every endpoint works on the +// caller's own automations; the server derives the owner from the request. + +export type AutomationTriggerType = 'cron' | 'once' +export type AutomationSessionMode = 'per_run' | 'persistent' +export type AutomationMisfirePolicy = 'skip' | 'run_once' +export type AutomationOverlapPolicy = 'skip' | 'queue' +export type AutomationRunStatus = + | 'queued' + | 'running' + | 'awaiting_approval' + | 'succeeded' + | 'failed' + | 'cancelled' + | 'skipped' + | 'needs_attention' +export type AutomationRunTrigger = 'schedule' | 'manual' | 'misfire' + +export interface AutomationTrigger { + type: AutomationTriggerType + /** Five fields (minute first), six (seconds first) or a descriptor such as @daily. */ + expr?: string + /** When a once trigger fires, RFC 3339. */ + at?: string + /** IANA zone; empty means UTC. */ + timezone?: string +} + +export interface AutomationLimits { + /** Execution time of one run, not counting approval waits. 0 uses the default. */ + max_duration_minutes?: number +} + +export interface Automation { + id: string + name: string + description: string + enabled: boolean + agent_id: string + instruction: string + trigger: AutomationTrigger + session_mode: AutomationSessionMode + persistent_session_id: string + carry_last_result: boolean + misfire_policy: AutomationMisfirePolicy + overlap_policy: AutomationOverlapPolicy + access_level: AssistantAccessLevel + approval_timeout_minutes: number + limits: AutomationLimits + notify_on_success: boolean + next_run_at: string | null + last_run_at: string | null + last_success_at: string | null + last_run_status: AutomationRunStatus | '' + consecutive_failures: number + paused_reason: string + created_at: string + updated_at: string +} + +/** Fields of a create or update; on update a field left out is kept. */ +export type AutomationInput = Partial> + +export interface AutomationRun { + id: string + automation_id: string + scheduled_at: string + trigger_kind: AutomationRunTrigger + status: AutomationRunStatus + session_id: string + user_message_id: string + assistant_message_id: string + pending_prompt_id: string + cancel_requested: boolean + answer: string + error: string + started_at: string | null + finished_at: string | null + created_at: string +} + +export interface AutomationGrant { + id: string + grant_key: string + label: string + risk: string + prompt_id: string + created_at: string + last_used_at: string | null + /** Why the grant no longer applies, e.g. the agent changed. Empty while it does. */ + lapse?: string +} + +export interface AutomationGrantCandidate { + prompt_id: string + grant_key: string + label: string + risk: string + tool: string + service_name?: string + asked_at: string +} + +const base = '/api/v1/automations' +const enc = encodeURIComponent + +export function listAutomations() { + return get<{ success: boolean; data: Automation[] }>(base) +} + +export function getAutomation(id: string) { + return get<{ success: boolean; data: Automation }>(`${base}/${enc(id)}`) +} + +export function getAutomationBySession(sessionId: string) { + return get<{ success: boolean; data: Automation }>(`${base}/by-session/${enc(sessionId)}`) +} + +export function createAutomation(input: AutomationInput) { + return post<{ success: boolean; data: Automation }>(base, input) +} + +export function updateAutomation(id: string, input: AutomationInput) { + return put<{ success: boolean; data: Automation }>(`${base}/${enc(id)}`, input) +} + +export function deleteAutomation(id: string) { + return del<{ success: boolean }>(`${base}/${enc(id)}`) +} + +export function pauseAutomation(id: string) { + return post<{ success: boolean; data: Automation }>(`${base}/${enc(id)}/pause`, {}) +} + +/** Schedule again from now and clear the failure count; missed runs are not caught up. */ +export function resumeAutomation(id: string) { + return post<{ success: boolean; data: Automation }>(`${base}/${enc(id)}/resume`, {}) +} + +export function runAutomationNow(id: string) { + return post<{ success: boolean; data: AutomationRun }>(`${base}/${enc(id)}/run`, {}) +} + +/** The next three times trigger fires, in UTC; rejects an invalid or too frequent trigger. */ +export function validateAutomationTrigger(trigger: AutomationTrigger) { + return post<{ success: boolean; data: { next_runs: string[] } }>(`${base}/validate-trigger`, { trigger }) +} + +export function listAutomationRuns(id: string, page = 1, pageSize = 20) { + return get<{ success: boolean; data: AutomationRun[]; total: number }>( + `${base}/${enc(id)}/runs?page=${page}&page_size=${pageSize}`, + ) +} + +export function cancelAutomationRun(runId: string) { + return post<{ success: boolean; data: AutomationRun }>(`/api/v1/automation-runs/${enc(runId)}/cancel`, {}) +} + +export function listAutomationGrants(id: string) { + return get<{ success: boolean; data: AutomationGrant[] }>(`${base}/${enc(id)}/grants`) +} + +export function listAutomationGrantCandidates(id: string) { + return get<{ success: boolean; data: AutomationGrantCandidate[] }>(`${base}/${enc(id)}/grant-candidates`) +} + +/** Let later runs make the call a past run asked approval for without asking. */ +export function addAutomationGrant(id: string, promptId: string) { + return post<{ success: boolean; data: AutomationGrant }>(`${base}/${enc(id)}/grants`, { prompt_id: promptId }) +} + +export function revokeAutomationGrant(grantId: string) { + return del<{ success: boolean }>(`/api/v1/agent/grants/${enc(grantId)}`) +} + +// --------------------------------------------------------------------------- +// In-app notifications. +// --------------------------------------------------------------------------- + +export type NotificationKind = + | 'automation.succeeded' + | 'automation.failed' + | 'automation.awaiting_approval' + | 'automation.paused' + +export interface AppNotification { + id: string + kind: NotificationKind | string + title: string + body: string + /** In-app route the notification opens. */ + link: string + source_type: string + source_id: string + read_at: string | null + created_at: string +} + +export function listNotifications(limit = 20) { + return get<{ success: boolean; data: { items: AppNotification[]; unread: number } }>( + `/api/v1/notifications?limit=${limit}`, + ) +} + +/** Mark ids read; no ids marks all of them. */ +export function markNotificationsRead(ids: string[] = []) { + return post<{ success: boolean }>('/api/v1/notifications/read', { ids }) +} diff --git a/frontend/src/assets/img/automation-green.svg b/frontend/src/assets/img/automation-green.svg new file mode 100644 index 00000000..f7373fac --- /dev/null +++ b/frontend/src/assets/img/automation-green.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/src/assets/img/automation.svg b/frontend/src/assets/img/automation.svg new file mode 100644 index 00000000..f01f5923 --- /dev/null +++ b/frontend/src/assets/img/automation.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/frontend/src/components/ChatHeader.vue b/frontend/src/components/ChatHeader.vue index 47055342..4fd4eb2a 100644 --- a/frontend/src/components/ChatHeader.vue +++ b/frontend/src/components/ChatHeader.vue @@ -26,6 +26,22 @@ {{ displayTitle }} + + + {{ automation.name }} + + + + {{ t('chatHeader.automationTask') }} + diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index e57f0289..a5b8ec47 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -1,13 +1,13 @@