qwen-audio-agent 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,9 +33,10 @@ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
33
33
  ### 核心特色
34
34
 
35
35
  - 全双工实时语音交互、自然打断和持续多轮对话
36
- - 一键连接你喜欢的各种 Agent,使用已有的模型、工具、MCP、Skill
37
- - 对话与后台任务并行,可随时查询进度或取消任务
38
- - 任务结果自动回到当前上下文,支持继续追问和修改
36
+ - 一键选择你喜欢的办事 Agent,复用已有的工具、MCP、Skill
37
+ - 前台对话与后台任务并驾齐驱,可随时追问任务进度或取消任务
38
+ - 支持创建多个独立任务,由后台 Agent 异步执行,并持续追踪任务状态
39
+ - 任务结果自动回到当前对话,支持继续追问和修改
39
40
  - 支持 WebUI、终端 TUI 和 macOS 桌面悬浮球
40
41
  - 支持本地用户档案与跨会话个人记忆
41
42
 
@@ -250,15 +251,18 @@ AGENT_PROTOCOL=opencode
250
251
  AGENT_PROTOCOL=qoder
251
252
  ```
252
253
 
253
- Kimi Code、Hermes、CodeBuddy、Codex 和 Claude Code 也可直接选择:
254
+ 后台 Agent 需要用户自行安装并完成原生配置;qwen-audio-agent 会复用其
255
+ 用户级模型、工具、MCP、Skill 和认证。
254
256
 
255
- ```dotenv
256
- AGENT_PROTOCOL=kimi
257
- # 或 hermes、codebuddy、codex、claude
257
+ 其中部分 Agent 通过外部 ACP 适配器接入,除本体外,还需要全局安装对应的适配器。
258
+ 以 Codex 为例:
259
+
260
+ ```bash
261
+ npm install -g @agentclientprotocol/codex-acp
258
262
  ```
259
263
 
260
- 以上其他后台暂时需要用户自行安装并完成原生配置;qwen-audio-agent 会复用其
261
- 用户级模型、工具、MCP、Skill 和认证。
264
+ CLI 模式缺少适配器时会尝试通过 npx 按需启动;桌面版为保证启动可靠,仅使用已安装的
265
+ 组件,请提前安装。
262
266
 
263
267
  使用其他支持 ACP stdio 的 Agent:
264
268
 
@@ -317,6 +321,17 @@ npm run desktop # macOS 桌面悬浮球
317
321
 
318
322
  更多构建、测试和发布说明见 [CONTRIBUTING.md](CONTRIBUTING.md)。
319
323
 
324
+ ## 交流与分享
325
+
326
+ 你可以直接在 [GitHub Issues](https://github.com/QwenAudio/qwen-audio-agent/issues) 发起讨论。
327
+
328
+ 对中国用户,也可以扫描左侧二维码加入微信交流群;如果群二维码已满或过期,
329
+ 扫描右侧任一维护者的个人二维码,维护者会邀请你进群。
330
+
331
+ | 微信交流群 | 个人微信 | 个人微信 |
332
+ | :---: | :---: | :---: |
333
+ | <img src="docs/wechat-group-qr.png" width="240" alt="微信交流群二维码"> | <img src="docs/wechat-contact-qr.png" width="240" alt="李旭个人微信二维码"> | <img src="docs/wechat-pigeon-dan-qr.png" width="240" alt="Pigeon.Dan 个人微信二维码"> |
334
+
320
335
  ## 参与贡献与安全
321
336
 
322
337
  - 开发与提交说明:[CONTRIBUTING.md](CONTRIBUTING.md)
package/README_EN.md CHANGED
@@ -41,12 +41,14 @@ https://github.com/user-attachments/assets/42022655-36d1-46b2-9c26-ff0765284000
41
41
 
42
42
  - Full-duplex realtime voice interaction, natural interruption, and continuous
43
43
  multi-turn conversation
44
- - One-click connection to the Agents you prefer, reusing their existing
45
- models, tools, MCP servers, and Skills
46
- - Voice conversation and backend tasks run in parallel, with progress queries
47
- and cancellation available at any time
48
- - Task results return automatically to the current context for follow-up and
49
- revision
44
+ - Choose your preferred Agent with one click, reusing its existing tools, MCP
45
+ servers, and Skills
46
+ - Foreground conversation and background tasks move forward in parallel, with
47
+ progress checks and cancellation available at any time
48
+ - Create multiple independent tasks for asynchronous execution by backend
49
+ Agents, with continuous status tracking
50
+ - Task results return automatically to the current conversation for follow-up
51
+ and revision
50
52
  - WebUI, terminal TUI, and a macOS desktop orb
51
53
  - Local user profile and personal memory across sessions
52
54
 
@@ -281,17 +283,20 @@ Use Qoder:
281
283
  AGENT_PROTOCOL=qoder
282
284
  ```
283
285
 
284
- Kimi Code, Hermes, CodeBuddy, Codex, and Claude Code can also be selected
285
- directly:
286
+ Backend Agents require the user to install and configure the native Agent
287
+ first. qwen-audio-agent reuses its user-level model, tools, MCP servers,
288
+ Skills, and authentication.
286
289
 
287
- ```dotenv
288
- AGENT_PROTOCOL=kimi
289
- # Or hermes, codebuddy, codex, or claude
290
+ Some Agents connect through external ACP adapters. Besides the Agent itself,
291
+ install the matching adapter globally. For example, for Codex:
292
+
293
+ ```bash
294
+ npm install -g @agentclientprotocol/codex-acp
290
295
  ```
291
296
 
292
- These other backends currently require the user to install and configure the
293
- native Agent first. qwen-audio-agent reuses its user-level model, tools, MCP
294
- servers, Skills, and authentication.
297
+ The CLI falls back to starting a missing adapter on demand with npx; the
298
+ desktop app only uses installed components for reliable startup, so install
299
+ the adapter up front.
295
300
 
296
301
  Use another Agent that supports ACP over stdio:
297
302
 
@@ -363,6 +368,19 @@ npm run desktop # macOS desktop orb
363
368
  See [CONTRIBUTING.md](CONTRIBUTING.md) for more about building, testing, and
364
369
  releasing.
365
370
 
371
+ ## Discussion & Sharing
372
+
373
+ You can start a discussion directly in
374
+ [GitHub Issues](https://github.com/QwenAudio/qwen-audio-agent/issues).
375
+
376
+ For users in China, you can also scan the QR code on the left to join our
377
+ WeChat group. If the group code is full or expired, scan either maintainer's
378
+ personal QR code on the right and they will invite you to the group.
379
+
380
+ | WeChat Group | Personal WeChat | Personal WeChat |
381
+ | :---: | :---: | :---: |
382
+ | <img src="docs/wechat-group-qr.png" width="240" alt="WeChat group QR code"> | <img src="docs/wechat-contact-qr.png" width="240" alt="Li Xu's personal WeChat QR code"> | <img src="docs/wechat-pigeon-dan-qr.png" width="240" alt="Pigeon.Dan's personal WeChat QR code"> |
383
+
366
384
  ## Contributing and Security
367
385
 
368
386
  - Development and contribution guide: [CONTRIBUTING.md](CONTRIBUTING.md)
package/cli/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/cli",
3
3
  "private": true,
4
- "version": "1.1.1",
4
+ "version": "1.2.0",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "qwenaudio": "./bin/qwenaudio.mjs"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qwen-audio-agent",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "A realtime voice frontend for mainstream AI agents.",
5
5
  "author": "qwen-audio-agent contributors",
6
6
  "license": "Apache-2.0",
@@ -113,6 +113,7 @@
113
113
  "dependencies": {
114
114
  "@agentclientprotocol/sdk": "1.3.0",
115
115
  "@modelcontextprotocol/sdk": "1.29.0",
116
+ "electron-updater": "6.8.9",
116
117
  "express": "^4.22.2",
117
118
  "ws": "^8.21.1",
118
119
  "zod": "^4.4.3"
@@ -2,16 +2,10 @@
2
2
 
3
3
  import { spawnSync } from 'node:child_process'
4
4
 
5
- const TEMPORARY_BUILD_ADVISORIES = new Map([
6
- [
7
- 1124334,
8
- {
9
- id: 'GHSA-mh99-v99m-4gvg',
10
- expires: '2026-08-15',
11
- reason: 'electron-builder 的间接 glob 构建链尚无兼容的稳定版修复',
12
- },
13
- ],
14
- ])
5
+ // 无当前生效的临时例外;新增例外时按 1124334(GHSA-mh99-v99m-4gvg)的
6
+ // 格式加入:source id -> { id, expires, reason }。已修复或不再出现的例外
7
+ // 必须及时删除,脚本会在例外失效时强制报错提醒。
8
+ const TEMPORARY_BUILD_ADVISORIES = new Map([])
15
9
 
16
10
  function runAudit(args) {
17
11
  const npmExecutable = process.env.npm_execpath
@@ -2,109 +2,180 @@
2
2
 
3
3
  import { spawnSync } from 'node:child_process'
4
4
  import { dirname, posix, resolve } from 'node:path'
5
- import { fileURLToPath } from 'node:url'
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
6
  import { readFileSync } from 'node:fs'
7
7
 
8
8
  const root = resolve(dirname(fileURLToPath(import.meta.url)), '..')
9
- const npmExecutable = process.env.npm_execpath
10
- const command = npmExecutable ? process.execPath : (
11
- process.platform === 'win32' ? 'npm.cmd' : 'npm'
12
- )
13
- const args = [
14
- ...(npmExecutable ? [npmExecutable] : []),
15
- 'pack',
16
- '--dry-run',
17
- '--json',
18
- '--ignore-scripts',
19
- ]
20
- const result = spawnSync(command, args, {
21
- cwd: root,
22
- env: process.env,
23
- encoding: 'utf8',
24
- shell: !npmExecutable && process.platform === 'win32',
25
- })
26
- if (result.error) throw result.error
27
- if (result.status !== 0) {
28
- process.stderr.write(result.stderr)
29
- throw new Error('npm pack 自检失败')
30
- }
31
9
 
32
- const jsonStart = result.stdout.lastIndexOf('[\n {\n "id":')
33
- if (jsonStart < 0) {
34
- process.stderr.write(result.stdout)
35
- throw new Error('npm pack 输出中缺少成品 JSON')
36
- }
37
- const packages = JSON.parse(result.stdout.slice(jsonStart))
38
- if (packages.length !== 1) throw new Error('npm pack 返回了意外的包数量')
39
- const files = new Set(packages[0].files.map(file => file.path))
40
- const required = [
41
- 'cli/bin/qwenaudio.mjs',
42
- 'config/openclaw/workspace/AGENTS.md',
43
- 'config/hermes/workspace/AGENTS.md',
44
- 'config/codebuddy/workspace/AGENTS.md',
45
- 'config/codebuddy/workspace/.codebuddy/models.json',
46
- 'config/codex/workspace/AGENTS.md',
47
- 'config/claude/workspace/AGENTS.md',
48
- 'config/acp/workspace/AGENTS.md',
49
- 'config/opencode/workspace/AGENTS.md',
50
- 'config/qoder/workspace/AGENTS.md',
51
- 'config/kimi/workspace/AGENTS.md',
52
- 'CONTRIBUTING.md',
53
- 'docs/architecture.md',
54
- 'docs/architecture-overview.png',
55
- 'NOTICE',
56
- 'PRIVACY.md',
57
- 'SECURITY.md',
58
- 'THIRD_PARTY_NOTICES.md',
59
- 'scripts/audit-dependencies.mjs',
60
- 'scripts/check-desktop-release-env.mjs',
61
- 'scripts/codex-acp',
62
- 'scripts/claude-code-acp',
63
- 'scripts/install-global.mjs',
64
- 'scripts/opencode-acp',
65
- 'scripts/prepare-build.mjs',
66
- 'server/src/agent/acp-backend-adapter.mjs',
67
- 'server/src/agent/acp-process-client.mjs',
68
- 'server/src/agent/acp-session-registry.mjs',
69
- 'server/src/agent/acp-session-tools.mjs',
70
- 'server/src/core/package-version.mjs',
71
- 'server/src/index.mjs',
72
- 'shared/runtime-environment.mjs',
73
- 'tui/src/index.mjs',
74
- 'web/dist/index.html',
75
- ]
76
- const missing = required.filter(file => !files.has(file))
77
- if (missing.length) {
78
- throw new Error(`npm 成品缺少必要文件:${missing.join(', ')}`)
79
- }
80
- const forbidden = [...files].filter(file => (
81
- file.includes('/__pycache__/')
82
- || file.endsWith('.pyc')
83
- || file.includes('/node_modules/')
84
- || file.startsWith('desktop/src/')
85
- ))
86
- if (forbidden.length) {
87
- throw new Error(`npm 成品包含不应发布的文件:${forbidden.join(', ')}`)
10
+ /**
11
+ * Parse `npm pack --dry-run --json` stdout into a list of package entries.
12
+ *
13
+ * npm <=10 emits an array: [ { id, name, files, ... }, ... ]
14
+ * npm >=11 emits an object map: { "<pkgName>": { id, name, files, ... }, ... }
15
+ * Both shapes carry identical per-package fields, so we normalise to an array
16
+ * and let callers treat them uniformly.
17
+ *
18
+ * @param {string} stdout Raw stdout from `npm pack --dry-run --json`.
19
+ * @returns {Array<object>} Package entries (one per packed package).
20
+ */
21
+ export function parsePackOutput(stdout) {
22
+ const trimmed = stdout.trim()
23
+ if (!trimmed) {
24
+ throw new Error('npm pack 输出为空')
25
+ }
26
+ const jsonText = extractLastJsonBlock(trimmed)
27
+ if (!jsonText) {
28
+ throw new Error('无法解析 npm pack 输出的 JSON:未找到 JSON 块')
29
+ }
30
+ let parsed
31
+ try {
32
+ parsed = JSON.parse(jsonText)
33
+ } catch (error) {
34
+ throw new Error(`无法解析 npm pack 输出的 JSON:${error.message}`)
35
+ }
36
+ const entries = Array.isArray(parsed) ? parsed : Object.values(parsed)
37
+ return entries.filter(Boolean)
88
38
  }
89
- const brokenMarkdownLinks = []
90
- for (const file of files) {
91
- if (!file.endsWith('.md')) continue
92
- const content = readFileSync(resolve(root, file), 'utf8')
93
- for (const match of content.matchAll(/\[[^\]]*\]\(([^)]+)\)/g)) {
94
- const target = match[1].trim().replace(/^<|>$/g, '').split('#')[0]
95
- if (!target || /^[a-z][a-z\d+.-]*:/i.test(target)) continue
96
- const packagedTarget = posix.normalize(posix.join(posix.dirname(file), target))
97
- if (!files.has(packagedTarget)) {
98
- brokenMarkdownLinks.push(`${file} -> ${packagedTarget}`)
39
+
40
+ // npm 10 在 `npm pack` 时会触发 `prepare` 生命周期脚本,构建工具(vite 等)的
41
+ // 日志会混入 stdout,污染 pack 的 JSON 输出(`--ignore-scripts` 不阻止 prepare)。
42
+ // 这里从 stdout 末尾按括号配对提取最后一个 JSON 块,以兼容前导/尾部噪声,同时
43
+ // 兼容 npm <=10 的数组与 npm >=11 的对象两种结构。
44
+ function extractLastJsonBlock(text) {
45
+ let end = -1
46
+ let endChar = ''
47
+ for (let i = text.length - 1; i >= 0; i--) {
48
+ const char = text[i]
49
+ if (char === '}' || char === ']') {
50
+ end = i
51
+ endChar = char
52
+ break
53
+ }
54
+ }
55
+ if (end === -1) return null
56
+ const startChar = endChar === '}' ? '{' : '['
57
+ let depth = 1
58
+ let start = -1
59
+ for (let i = end - 1; i >= 0; i--) {
60
+ const char = text[i]
61
+ if (char === endChar) depth++
62
+ else if (char === startChar) {
63
+ depth--
64
+ if (depth === 0) {
65
+ start = i
66
+ break
67
+ }
99
68
  }
100
69
  }
70
+ if (start === -1) return null
71
+ return text.slice(start, end + 1)
101
72
  }
102
- if (brokenMarkdownLinks.length) {
103
- throw new Error(
104
- `npm 成品包含失效的 Markdown 链接:${brokenMarkdownLinks.join(', ')}`,
73
+
74
+ const isMain = process.argv[1]
75
+ && import.meta.url === pathToFileURL(process.argv[1]).href
76
+
77
+ if (isMain) {
78
+ const npmExecutable = process.env.npm_execpath
79
+ const command = npmExecutable ? process.execPath : (
80
+ process.platform === 'win32' ? 'npm.cmd' : 'npm'
105
81
  )
106
- }
82
+ const args = [
83
+ ...(npmExecutable ? [npmExecutable] : []),
84
+ 'pack',
85
+ '--dry-run',
86
+ '--json',
87
+ '--ignore-scripts',
88
+ ]
89
+ const result = spawnSync(command, args, {
90
+ cwd: root,
91
+ env: process.env,
92
+ encoding: 'utf8',
93
+ shell: !npmExecutable && process.platform === 'win32',
94
+ })
95
+ if (result.error) throw result.error
96
+ if (result.status !== 0) {
97
+ process.stderr.write(result.stderr)
98
+ throw new Error('npm pack 自检失败')
99
+ }
107
100
 
108
- process.stdout.write(
109
- `npm 成品自检通过:${packages[0].filename},共 ${files.size} 个文件。\n`,
110
- )
101
+ let packages
102
+ try {
103
+ packages = parsePackOutput(result.stdout)
104
+ } catch (error) {
105
+ process.stderr.write(result.stdout)
106
+ throw error
107
+ }
108
+ if (packages.length !== 1) throw new Error('npm pack 返回了意外的包数量')
109
+ const files = new Set(packages[0].files.map(file => file.path))
110
+ const required = [
111
+ 'cli/bin/qwenaudio.mjs',
112
+ 'config/openclaw/workspace/AGENTS.md',
113
+ 'config/hermes/workspace/AGENTS.md',
114
+ 'config/codebuddy/workspace/AGENTS.md',
115
+ 'config/codebuddy/workspace/.codebuddy/models.json',
116
+ 'config/codex/workspace/AGENTS.md',
117
+ 'config/claude/workspace/AGENTS.md',
118
+ 'config/acp/workspace/AGENTS.md',
119
+ 'config/opencode/workspace/AGENTS.md',
120
+ 'config/qoder/workspace/AGENTS.md',
121
+ 'config/kimi/workspace/AGENTS.md',
122
+ 'CONTRIBUTING.md',
123
+ 'docs/architecture.md',
124
+ 'docs/architecture-overview.png',
125
+ 'NOTICE',
126
+ 'PRIVACY.md',
127
+ 'SECURITY.md',
128
+ 'THIRD_PARTY_NOTICES.md',
129
+ 'scripts/audit-dependencies.mjs',
130
+ 'scripts/check-desktop-release-env.mjs',
131
+ 'scripts/codex-acp',
132
+ 'scripts/claude-code-acp',
133
+ 'scripts/install-global.mjs',
134
+ 'scripts/opencode-acp',
135
+ 'scripts/prepare-build.mjs',
136
+ 'server/src/agent/acp-backend-adapter.mjs',
137
+ 'server/src/agent/acp-process-client.mjs',
138
+ 'server/src/agent/acp-session-registry.mjs',
139
+ 'server/src/agent/acp-session-tools.mjs',
140
+ 'server/src/core/package-version.mjs',
141
+ 'server/src/index.mjs',
142
+ 'shared/runtime-environment.mjs',
143
+ 'tui/src/index.mjs',
144
+ 'web/dist/index.html',
145
+ ]
146
+ const missing = required.filter(file => !files.has(file))
147
+ if (missing.length) {
148
+ throw new Error(`npm 成品缺少必要文件:${missing.join(', ')}`)
149
+ }
150
+ const forbidden = [...files].filter(file => (
151
+ file.includes('/__pycache__/')
152
+ || file.endsWith('.pyc')
153
+ || file.includes('/node_modules/')
154
+ || file.startsWith('desktop/src/')
155
+ ))
156
+ if (forbidden.length) {
157
+ throw new Error(`npm 成品包含不应发布的文件:${forbidden.join(', ')}`)
158
+ }
159
+ const brokenMarkdownLinks = []
160
+ for (const file of files) {
161
+ if (!file.endsWith('.md')) continue
162
+ const content = readFileSync(resolve(root, file), 'utf8')
163
+ for (const match of content.matchAll(/\[[^\]]*\]\(([^)]+)\)/g)) {
164
+ const target = match[1].trim().replace(/^<|>$/g, '').split('#')[0]
165
+ if (!target || /^[a-z][a-z\d+.-]*:/i.test(target)) continue
166
+ const packagedTarget = posix.normalize(posix.join(posix.dirname(file), target))
167
+ if (!files.has(packagedTarget)) {
168
+ brokenMarkdownLinks.push(`${file} -> ${packagedTarget}`)
169
+ }
170
+ }
171
+ }
172
+ if (brokenMarkdownLinks.length) {
173
+ throw new Error(
174
+ `npm 成品包含失效的 Markdown 链接:${brokenMarkdownLinks.join(', ')}`,
175
+ )
176
+ }
177
+
178
+ process.stdout.write(
179
+ `npm 成品自检通过:${packages[0].filename},共 ${files.size} 个文件。\n`,
180
+ )
181
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qwen-audio-agent/server",
3
3
  "private": true,
4
- "version": "1.1.1",
4
+ "version": "1.2.0",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "node --watch src/index.mjs",
@@ -0,0 +1,184 @@
1
+ import {
2
+ buildFrontendContext,
3
+ loadFrontendPrompt,
4
+ } from '../conversation/frontend-agent-context.mjs'
5
+
6
+ export const SPAWN_THINKING_TOOL_NAME = 'spawn_thinking'
7
+ export const DELEGATE_TOOL_NAME = SPAWN_THINKING_TOOL_NAME
8
+ export const CANCEL_AGENT_TASK_TOOL_NAME = 'cancel_agent_task'
9
+ export const GET_AGENT_TASK_STATUS_TOOL_NAME = 'get_agent_task_status'
10
+ export const GET_CURRENT_TIME_TOOL_NAME = 'get_current_time'
11
+ export const USER_MEMORY_TOOL_NAME = 'user_memory'
12
+ export const RESPOND_AGENT_PERMISSION_TOOL_NAME = 'respond_agent_permission'
13
+
14
+ const delegateTool = {
15
+ type: 'function',
16
+ function: {
17
+ name: DELEGATE_TOOL_NAME,
18
+ description: '把明确的新执行或调查要求交给后台 Agent。需要当前信息、搜索、检查、工具、文件、屏幕、应用、代码、创作,或要求继续、修改已有工作时调用;询问此前工作的状态、进度、阶段产物或已经发现了什么统一改用 get_agent_task_status。缺少不可推断的核心目标时先问一个必要问题。可以按需先说一句具体行动预告,不要使用“好的、收到”等通用承接语。返回 accepted 只表示已受理;结合本轮已有发言判断是否还需回应,不重复确认或声称完成。',
19
+ parameters: {
20
+ type: 'object',
21
+ properties: {
22
+ objective: {
23
+ type: 'string',
24
+ description: '必须是已经可以执行的目标,忠实保留本轮用户要求并写明对象、动作、约束和期望结果,不得用“待用户说明主题”等占位内容启动空执行。仅在当前对话已经明确时消解“它、刚才那个”等指代;不要猜测或补造事实。后台 Agent 会同时收到近期对话和后台执行状态,因此这里是意图交接,不是对历史的替代。',
25
+ },
26
+ },
27
+ required: ['objective'],
28
+ additionalProperties: false,
29
+ },
30
+ },
31
+ }
32
+
33
+ const cancelAgentTaskTool = {
34
+ type: 'function',
35
+ function: {
36
+ name: CANCEL_AGENT_TASK_TOOL_NAME,
37
+ description: '取消用户此前交给后台、目前仍在排队或执行的工作。用户明确说取消、停止、别做了、不要继续,或要求取消“刚才那个任务”时必须调用,不要只口头说忽略结果。能够从运行上下文确定 work_id 时传入;用户泛指刚才的工作时可省略,系统会取消最近提交且仍活跃的工作。',
38
+ parameters: {
39
+ type: 'object',
40
+ properties: {
41
+ work_id: {
42
+ type: 'string',
43
+ description: '要取消的 work_id。仅在运行上下文已明确给出时填写;不得猜造。省略则取消当前语音会话最近提交且仍活跃的工作。',
44
+ },
45
+ },
46
+ additionalProperties: false,
47
+ },
48
+ },
49
+ }
50
+
51
+ const getAgentTaskStatusTool = {
52
+ type: 'function',
53
+ function: {
54
+ name: GET_AGENT_TASK_STATUS_TOOL_NAME,
55
+ description: '查询此前交给后台工作的状态、进度或阶段性结果。用户询问“刚才那个怎么样了、还在做吗、做到哪一步、已经发现了什么、是否完成”时统一调用,不要自行判断普通任务或第三层任务,也不要改用 spawn_thinking。系统会直接回答普通任务,并自动查询第三层任务。能够从运行上下文确定 work_id 时传入;省略时查询当前语音会话最近的工作。',
56
+ parameters: {
57
+ type: 'object',
58
+ properties: {
59
+ work_id: {
60
+ type: 'string',
61
+ description: '要查询的 work_id。仅在运行上下文已明确给出时填写,不得猜造;省略时查询当前语音会话最近的工作。',
62
+ },
63
+ question: {
64
+ type: 'string',
65
+ description: '用户本轮对任务状态、进度或阶段结果的原始问题。尽量忠实保留,不要自行改写成另一项任务;省略时系统会使用本轮语音转写。',
66
+ },
67
+ },
68
+ additionalProperties: false,
69
+ },
70
+ },
71
+ }
72
+
73
+ const getCurrentTimeTool = {
74
+ type: 'function',
75
+ function: {
76
+ name: GET_CURRENT_TIME_TOOL_NAME,
77
+ description: '获取用户本地时区中的准确当前日期、时间和星期。用户询问当前时间、今天日期、星期或相对日期判断时调用;不用于创建提醒。',
78
+ parameters: {
79
+ type: 'object',
80
+ properties: {},
81
+ additionalProperties: false,
82
+ },
83
+ },
84
+ }
85
+
86
+ const userMemoryTool = {
87
+ type: 'function',
88
+ function: {
89
+ name: USER_MEMORY_TOOL_NAME,
90
+ description: '管理千问Audio前台持有的用户记忆。profile 用于称呼、时区、语言和稳定交互偏好;long_term 用于用户明确希望跨会话保留的个人事实、喜好、目标和约定;不要保存项目执行历史或后台工作细节。使用 recall 回忆,remember 新增,replace 用新事实替换明确相关的旧记录,forget 遗忘。',
91
+ parameters: {
92
+ type: 'object',
93
+ properties: {
94
+ action: {
95
+ type: 'string',
96
+ enum: ['recall', 'remember', 'replace', 'forget'],
97
+ description: '要执行的记忆操作。',
98
+ },
99
+ scope: {
100
+ type: 'string',
101
+ enum: ['profile', 'long_term', 'all'],
102
+ description: '记忆范围。remember 和 replace 必须使用 profile 或 long_term;recall 和 forget 可以使用 all。',
103
+ },
104
+ content: {
105
+ type: 'string',
106
+ description: 'remember 或 replace 时要保存的完整、简洁事实。',
107
+ },
108
+ query: {
109
+ type: 'string',
110
+ description: 'recall 或 forget 时用于匹配记忆的自然语言查询。',
111
+ },
112
+ memory_ids: {
113
+ type: 'array',
114
+ items: { type: 'string' },
115
+ maxItems: 20,
116
+ description: 'replace 时要被新事实取代的旧记忆 ID;必须来自本轮 recall 结果,不得猜造。',
117
+ },
118
+ all: {
119
+ type: 'boolean',
120
+ description: '仅用于 forget;用户明确要求清空所选范围时设为 true。',
121
+ },
122
+ },
123
+ required: ['action', 'scope'],
124
+ additionalProperties: false,
125
+ },
126
+ },
127
+ }
128
+
129
+ const respondAgentPermissionTool = {
130
+ type: 'function',
131
+ function: {
132
+ name: RESPOND_AGENT_PERMISSION_TOOL_NAME,
133
+ description: '回复当前正在等待用户决定的后台权限请求。由你结合刚提出的具体权限问题和用户本轮自然表达,智能判断为本会话自动允许、拒绝或尚不明确;不要依赖固定关键词。用户回答“可以”“行”“好”“允许”“同意”“没问题”等自然肯定表达就是明确同意,应调用 always,不得要求复述固定口令。明确拒绝时调用 reject,不明确时不要调用并继续询问。',
134
+ parameters: {
135
+ type: 'object',
136
+ properties: {
137
+ authorization_id: {
138
+ type: 'string',
139
+ description: '待确认请求的 authorization_id,必须来自当前运行上下文,不得猜造。',
140
+ },
141
+ decision: {
142
+ type: 'string',
143
+ enum: ['always', 'reject'],
144
+ description: 'always 表示允许当前操作,并由 Gateway 在本次前台会话中自动允许后续权限请求;reject 表示拒绝当前操作,后续请求仍继续询问。',
145
+ },
146
+ },
147
+ required: ['authorization_id', 'decision'],
148
+ additionalProperties: false,
149
+ },
150
+ },
151
+ }
152
+
153
+ export const TOOLS = [
154
+ delegateTool,
155
+ cancelAgentTaskTool,
156
+ getAgentTaskStatusTool,
157
+ getCurrentTimeTool,
158
+ userMemoryTool,
159
+ respondAgentPermissionTool,
160
+ ]
161
+
162
+ export const resultResponseInstructions = [
163
+ '这是先前提交工作的最终结果,不是用户的新请求。',
164
+ '把 result 当作事实材料,结合当前对话自然回应;可以按语境概括、合并、承接或询问必要信息,避免重复已经表达过的内容。',
165
+ '输入包含多个 event 时,必须覆盖每个 event 的实质结果;不得只说其中一个,也不得让过程性或状态性内容掩盖真正完成的工作。',
166
+ '开头直接说实际结果、关键发现、阻塞或必要问题,不用“好的、收到、任务完成了”等空泛承接语。',
167
+ '不要朗读协议前缀、字段、执行 ID、路径、URL 或不适合口语的长内容。',
168
+ '不要调用工具,不要添加事件中没有的事实,也不要把未完成说成完成。',
169
+ ].join(' ')
170
+
171
+ export function speakResponseInstructions(content) {
172
+ return `请以自然口语传达下面的信息,保持事实一致,不调用工具:\n${content}`
173
+ }
174
+
175
+ export const permissionResponseInstructions = [
176
+ '这是后台 Agent 的权限请求。',
177
+ '自然、简短地说明操作,并询问用户是否同意授权。',
178
+ '不要规定具体回答方式,也不要提供或要求复述固定口令。',
179
+ '不要调用工具或朗读内部字段,等待用户回答。',
180
+ ].join(' ')
181
+
182
+ export function buildFrontendInstructions(agentContext = {}) {
183
+ return `${loadFrontendPrompt()}\n\n${buildFrontendContext(agentContext)}`
184
+ }