@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.8
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 +76 -105
- package/dist/es/AgentSession.mjs +32 -33
- package/dist/es/Config.mjs +85 -63
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +71 -63
- package/dist/es/index.mjs +48 -49
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +103 -193
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +77 -138
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
- package/dist/es/localFiles/constants.mjs +1 -1
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +18 -22
- package/dist/es/localFiles/host/protocol.mjs +5 -6
- package/dist/es/localFiles/schemas.mjs +60 -45
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +52 -71
- package/dist/es/package.json.mjs +29 -38
- package/dist/lib/index.js +9 -372
- package/dist/src/Config.d.ts +2 -2
- package/dist/src/Session.d.ts +4 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +1 -20
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -14
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
- package/dist/src/localFiles/constants.d.ts +1 -2
- package/dist/src/localFiles/host/protocol.d.ts +0 -13
- package/dist/src/localFiles/index.d.ts +2 -3
- package/dist/src/localFiles/schemas.d.ts +3 -2
- package/dist/src/localFiles/types.d.ts +1 -14
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +0 -12
- package/package.json +4 -13
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
- package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
- package/dist/es/builtinTools/command.mjs +0 -56
- package/dist/es/builtinTools/constants.mjs +0 -10
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -236
- package/dist/es/builtinTools/overview.mjs +0 -77
- package/dist/es/builtinTools/paths.mjs +0 -63
- package/dist/es/builtinTools/schemas.mjs +0 -216
- package/dist/es/builtinTools/tools.mjs +0 -471
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
- package/dist/src/builtinTools/command.d.ts +0 -26
- package/dist/src/builtinTools/constants.d.ts +0 -17
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
- package/dist/src/builtinTools/overview.d.ts +0 -5
- package/dist/src/builtinTools/paths.d.ts +0 -15
- package/dist/src/builtinTools/schemas.d.ts +0 -3
- package/dist/src/builtinTools/tools.d.ts +0 -60
package/README.md
CHANGED
|
@@ -7,12 +7,9 @@ AIoT 应用客户端 SDK,支持 Agent 应用和对话型应用。会话、消
|
|
|
7
7
|
| 会话与流式对话 | Agent、对话型 | 浏览器、端侧宿主 | [对话界面](#对话界面) |
|
|
8
8
|
| 会话产出物 | Agent、对话型 | 浏览器、端侧宿主 | [产出物](#产出物) |
|
|
9
9
|
| 业务插件、本地文件 | Agent | 浏览器、端侧宿主 | [Agent 插件](#agent-插件) |
|
|
10
|
-
|
|
|
11
|
-
| 本地 Python(`localPython` / `run_python`) | Agent | **优先端侧宿主**;浏览器可用 Pyodide | [命令和脚本](#命令和脚本) |
|
|
10
|
+
| 本地 Python | Agent | **仅端侧宿主** | [本地 Python](#本地-python) |
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
集成方总览见仓库内 [`bot-client-ui/docs/agent-integration-handbook.md`](../bot-client-ui/docs/agent-integration-handbook.md)。
|
|
12
|
+
浏览器指现代浏览器。端侧宿主是内嵌此页面、负责读写本地工程和运行脚本的桌面程序,见[宿主通道](#宿主通道)。
|
|
16
13
|
|
|
17
14
|
## 安装
|
|
18
15
|
|
|
@@ -122,7 +119,7 @@ Agent 应用里,平台上标记为**客户端执行**的插件函数由 SDK
|
|
|
122
119
|
| 配置 | 内容 | `pluginCode` |
|
|
123
120
|
| --- | --- | --- |
|
|
124
121
|
| `plugins` | 接入方自己实现的业务插件 | 平台分配,作为 key |
|
|
125
|
-
| `builtinPlugins` | SDK
|
|
122
|
+
| `builtinPlugins` | SDK 内置的本地文件工具和 `run_python` | 固定 `buildin_tools`,不用传 |
|
|
126
123
|
|
|
127
124
|
```ts
|
|
128
125
|
const client = new BotClient(token, {
|
|
@@ -156,27 +153,24 @@ const client = new BotClient(token, {
|
|
|
156
153
|
|
|
157
154
|
### 内置插件
|
|
158
155
|
|
|
159
|
-
`localFiles`
|
|
160
|
-
|
|
161
|
-
`shell` / `run_file` / `run_skill_script` 按[命令和脚本](#命令和脚本)选择执行器:注入的 `commandRunner` → 宿主声明 `sandbox-exec`(协议一致)→ 浏览器 just-bash / Pyodide(默认开启)→ 否则 501。
|
|
156
|
+
`localFiles` 和 `localPython` 在平台上是同一个客户端插件,`pluginCode` 为 `buildin_tools`,两个开关只决定客户端注册哪些函数。某项 `enabled` 不为 `true` 时,对应函数不注册。`client.localWorkspace` 只在 `localFiles.enabled === true` 时存在。
|
|
162
157
|
|
|
163
|
-
业务 `plugins` 里如果已经有 `
|
|
158
|
+
业务 `plugins` 里如果已经有 `buildin_tools` 这个 key,内置工具不会注册,`error` 事件会带上原因。同一页面只支持一个启用了内置插件的 `BotClient`(插件表是全局配置)。
|
|
164
159
|
|
|
165
160
|
平台上注册该插件时,`functionCode` 不可改名。参数定义从 `BUILTIN_TOOL_SCHEMAS` 读取:
|
|
166
161
|
|
|
167
|
-
| functionCode | 名称 | 运行环境 |
|
|
168
|
-
| --- | --- | --- |
|
|
169
|
-
| `
|
|
170
|
-
| `read_file` | 读取文件 | 浏览器、端侧宿主 |
|
|
171
|
-
| `
|
|
172
|
-
| `
|
|
173
|
-
| `
|
|
174
|
-
| `
|
|
175
|
-
| `
|
|
176
|
-
| `
|
|
177
|
-
| `
|
|
178
|
-
| `
|
|
179
|
-
| `run_skill_script` | 运行技能脚本 | 同 `run_file` |
|
|
162
|
+
| functionCode | 名称 | 执行前需要确认 | 运行环境 |
|
|
163
|
+
| --- | --- | --- | --- |
|
|
164
|
+
| `list_directory` | 列出目录 | 否 | 浏览器、端侧宿主 |
|
|
165
|
+
| `read_file` | 读取文件 | 否 | 浏览器、端侧宿主 |
|
|
166
|
+
| `stat_file` | 查看文件信息 | 否 | 浏览器、端侧宿主 |
|
|
167
|
+
| `search_files` | 查找文件 | 否 | 浏览器、端侧宿主 |
|
|
168
|
+
| `search_text` | 搜索文本 | 否 | 浏览器、端侧宿主 |
|
|
169
|
+
| `apply_patch` | 修改文件 | 是 | 浏览器、端侧宿主 |
|
|
170
|
+
| `write_file` | 写入文件 | 是 | 浏览器、端侧宿主 |
|
|
171
|
+
| `upload_file` | 上传文件到会话 | 是 | 浏览器、端侧宿主 |
|
|
172
|
+
| `download_file` | 下载文件到工作区 | 是 | 浏览器、端侧宿主 |
|
|
173
|
+
| `run_python` | 运行 Python 脚本 | 是,且与文件确认分开 | **仅端侧宿主** |
|
|
180
174
|
|
|
181
175
|
### 展示工具步骤
|
|
182
176
|
|
|
@@ -200,17 +194,12 @@ const schema = pluginCodes.includes(pluginCode)
|
|
|
200
194
|
|
|
201
195
|
## 本地工作文件夹
|
|
202
196
|
|
|
203
|
-
内置插件 `localFiles
|
|
204
|
-
|
|
205
|
-
**路径约定(以当前 Schema / 代码为准):**
|
|
206
|
-
|
|
207
|
-
- 工具参数使用工作区内以 `/` 开头的绝对路径,或相对工作区根的相对路径,例如 `/说明.md`、`notes/a.md`。
|
|
208
|
-
- **不要**使用或新建 `input`、`output`、`uploads`、`tmp` 作为约定根目录。
|
|
209
|
-
- 技能在 `skills/<名称>/` 下,只通过技能工具访问。
|
|
210
|
-
- `/dev`、`/usr`、`/bin` 仍是系统路径。写进脚本文件里的路径请用相对路径。
|
|
197
|
+
内置插件 `localFiles`。应用中的助手只能访问一个文件夹:网页里由用户选择,或由宿主指定。读、搜、改、上传、下载是 SDK 内置的 9 个工具。界面负责四件事:让用户授权文件夹(宿主接入时改为等待宿主推送)、在写入和传输前确认、展示进度、展示并刷新目录。
|
|
211
198
|
|
|
212
199
|
网页里由用户选择文件夹时依赖 File System Access API,只在 Chromium 内核(Chrome、Edge、WebView2)的安全上下文(https 或 localhost)中可用。端侧宿主自己掌握工程目录时,页面不再弹选择框,见[宿主通道](#宿主通道)。
|
|
213
200
|
|
|
201
|
+
每个工具都有 `grantId`,固定为 `current-workspace`(常量 `WORKSPACE_GRANT_ID`)。模型漏传时 SDK 会补上;传了其他值返回 403。
|
|
202
|
+
|
|
214
203
|
### 开启
|
|
215
204
|
|
|
216
205
|
```ts
|
|
@@ -230,13 +219,6 @@ const client = new BotClient(token, {
|
|
|
230
219
|
limits: { maxReadBytes: 512 * 1024 },
|
|
231
220
|
// 为 true 时 search_text 可以不指定子目录、搜整个工作区。默认 false
|
|
232
221
|
allowWorkspaceWideTextSearch: false,
|
|
233
|
-
// 无宿主沙箱时,是否在页面里跑 shell / python(默认 true)
|
|
234
|
-
commandRuntime: {
|
|
235
|
-
browser: {
|
|
236
|
-
enabled: true,
|
|
237
|
-
// bashModuleURL / pyodideIndexURL 可覆盖公司 OBS 默认地址
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
222
|
},
|
|
241
223
|
},
|
|
242
224
|
});
|
|
@@ -244,33 +226,39 @@ const client = new BotClient(token, {
|
|
|
244
226
|
const workspace = client.localWorkspace;
|
|
245
227
|
```
|
|
246
228
|
|
|
247
|
-
`
|
|
229
|
+
确认回调可以写在配置里,也可以等界面挂载后再 `workspace.setApprovalHandler`。没有回调时,`apply_patch`、`write_file`、`upload_file`、`download_file` 一律返回 403(`approval_unavailable`),不会写盘、不会传输。返回值只有严格的 `true` 会继续执行。
|
|
230
|
+
|
|
231
|
+
`transfer` 可替换上传和下载与平台文件服务的交互。默认实现走会话文件接口。一般集成不用改。
|
|
248
232
|
|
|
249
|
-
###
|
|
233
|
+
### 九个工具
|
|
250
234
|
|
|
251
|
-
|
|
235
|
+
路径一律相对工作区根,用 `/` 分隔。绝对路径、盘符、`..`、反斜杠、URL 编码遍历返回 403(`path_outside_workspace`)。
|
|
252
236
|
|
|
253
|
-
**`
|
|
237
|
+
**`list_directory`** 只列一层直接子项。目录在前、名称升序,然后分页。`path` 省略或 `"."` 表示根。`offset` 默认 0,`limit` 默认 200、最大 1000。返回 `entries`、`total`、`hasMore`。敏感文件仍在列表里,并带 `sensitive: true`。
|
|
254
238
|
|
|
255
|
-
**`
|
|
239
|
+
**`read_file`** 按行读文本。`startLine` / `endLine` 从 1 计、含端点。`encoding` 为 `utf-8`(默认)、`gbk` 或 `gb18030`。单次最多返回 `limits.maxReadBytes`(默认 1 MiB),超出时结果带 `truncated: true`。完整扫描过文件时返回 `totalLines` 和 `hash`(`sha256:<hex>`),后续修改要用这个 hash。二进制文件返回 400。
|
|
256
240
|
|
|
257
|
-
**`
|
|
241
|
+
**`stat_file`** 返回 `kind`、`size`、`lastModified`、`sensitive`。`includeHash: true` 时对不超过传输上限的文件计算 hash。不返回内容。
|
|
258
242
|
|
|
259
|
-
**`
|
|
243
|
+
**`search_files`** 按文件名或 glob 找文件。`*`、`?`、`**` 可用。模式不含 `/` 时匹配文件名,含 `/` 时匹配相对 `path` 的路径。`path` 默认根,`maxDepth` 默认 8、最大 16,`maxResults` 默认并最多 200。跳过 `.git`、`node_modules`、`.svn`、`.idea`、`.vscode`,以及 `~$*`、`.~lock*`、`*.tmp`。敏感文件不出现在结果里。
|
|
260
244
|
|
|
261
|
-
**`
|
|
245
|
+
**`search_text`** 在指定文件或目录里搜普通文本,返回文件、行号、列号和该行内容。`caseSensitive` 默认否。`glob` 可限制文件名,`contextLines` 为 0–3。`isRegex: true` 返回 501。默认必须把 `path` 指到子目录或文件;要搜整个工作区,配置 `allowWorkspaceWideTextSearch: true`。单文件超过 1 MiB 的不扫,超过 500 字的行会截断,最多扫描 2000 个文件。敏感文件和上面那些忽略目录同样跳过。
|
|
262
246
|
|
|
263
|
-
**`
|
|
247
|
+
**`apply_patch`** 对已有 UTF-8 文件做查找替换。必须带 `expectedHash`。`edits` 按顺序应用,每条 `oldText` 在文件中只能出现一次,除非 `replaceAll: true`。执行前确认。确认前、确认后各校验一次 hash,期间文件被外部改过则返回 409,`data.currentHash` 是当前值。先写临时副本,失败或取消时原文件不变。
|
|
264
248
|
|
|
265
|
-
**`
|
|
249
|
+
**`write_file`** 新建或整体覆盖。`content` 是完整 UTF-8 文本。覆盖已有文件必须带 `expectedHash`;新建不要带。`createDirectories: true` 时才会创建尚不存在的父目录,默认否(父目录不存在返回 404)。执行前确认。同样先写临时副本。修改已有文件优先用 `apply_patch`。
|
|
266
250
|
|
|
267
|
-
**`
|
|
251
|
+
**`upload_file`** 把工作区里的一个文件上传到平台文件服务。`target` 只支持 `session`(默认),其他值返回 501。单文件不超过 50 MB。执行前确认。成功返回 `fileId`、`name`、`size`、`url`。`url` 交给模型使用。返回即视为成功,不等待平台解析完成。敏感文件不能上传。
|
|
268
252
|
|
|
269
|
-
**`
|
|
253
|
+
**`download_file`** 把文件保存到 `destPath`。`source.type` 三选一:
|
|
270
254
|
|
|
271
|
-
|
|
255
|
+
| type | 还要带 | 含义 |
|
|
256
|
+
| --- | --- | --- |
|
|
257
|
+
| `sessionFile` | `fileId` | 当前会话里的文件 |
|
|
258
|
+
| `platformFile` | `fileId` | `upload_file` 返回的 `fileId` |
|
|
259
|
+
| `url` | `url` | 完整 https 地址 |
|
|
272
260
|
|
|
273
|
-
|
|
261
|
+
只传 `type`、不传 `fileId` 或 `url` 会失败。`overwrite` 默认否,目标已存在返回 409。覆盖时可再带 `expectedHash`。单文件不超过 50 MB。执行前确认。URL 规则见下文。
|
|
274
262
|
|
|
275
263
|
### 浏览器里授权
|
|
276
264
|
|
|
@@ -457,53 +445,52 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
457
445
|
|
|
458
446
|
`workspace.on` 返回取消订阅的函数。
|
|
459
447
|
|
|
460
|
-
##
|
|
461
|
-
|
|
462
|
-
`shell`、`run_file`、`run_skill_script` 共用同一套执行器选择(`runnerFor`),成功时 `data` 为 `{ exitCode, stdout, stderr, cwd? }`。`exitCode !== 0` 仍是工具成功(`code === 0`)。跨命令只保留 cwd,不保留环境变量。
|
|
463
|
-
|
|
464
|
-
### 执行器选择顺序
|
|
448
|
+
## 本地 Python
|
|
465
449
|
|
|
466
|
-
|
|
467
|
-
2. **宿主沙箱**:`backend: 'host-bridge'`,且 `workspace` 消息声明 `capabilities` 含 `sandbox-exec`,且 `sandboxProtocol === 1` → 经宿主转发 `@glodon-aiot/workspace-sandbox`(MXC 隔离)
|
|
468
|
-
3. **浏览器运行时**:`commandRuntime.browser.enabled` 默认为 `true` → just-bash + Pyodide Worker
|
|
469
|
-
4. 以上皆不可用 → **501**
|
|
450
|
+
> 只能在端侧宿主里使用。普通浏览器里不会运行脚本,调用返回 501。
|
|
470
451
|
|
|
471
|
-
|
|
452
|
+
内置插件 `localPython`。使用前需同时满足:
|
|
472
453
|
|
|
473
|
-
|
|
454
|
+
- 页面运行在端侧宿主里,且宿主按[宿主通道](#宿主通道)实现了 `run_python`;
|
|
455
|
+
- `localFiles.enabled: true` 且 `backend: 'host-bridge'`;
|
|
456
|
+
- 配置了 `localPython.onApprovalRequired`。
|
|
474
457
|
|
|
475
|
-
|
|
458
|
+
没有启用本地工作区时,脚本工具不会注册,`error` 事件里会说明原因。`run_python` 和文件工具在同一个客户端插件里,但文件工具已经授权,也不能代替这一次脚本确认。
|
|
476
459
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
460
|
+
```ts
|
|
461
|
+
builtinPlugins: {
|
|
462
|
+
localFiles: {
|
|
463
|
+
enabled: true,
|
|
464
|
+
backend: 'host-bridge',
|
|
465
|
+
onApprovalRequired: async (request) => askUser(request),
|
|
466
|
+
},
|
|
467
|
+
localPython: {
|
|
468
|
+
enabled: true, // 仅端侧宿主可用,需配合 backend: 'host-bridge'
|
|
469
|
+
onApprovalRequired: async (request) => askUser(request),
|
|
470
|
+
},
|
|
471
|
+
}
|
|
472
|
+
```
|
|
483
473
|
|
|
484
|
-
|
|
474
|
+
平台上的函数名是 `run_python`。参数:
|
|
485
475
|
|
|
486
|
-
|
|
|
476
|
+
| 字段 | 含义 |
|
|
487
477
|
| --- | --- |
|
|
488
|
-
| `
|
|
489
|
-
| `
|
|
490
|
-
|
|
491
|
-
|
|
478
|
+
| `grantId` | 固定 `current-workspace`,漏传会补上 |
|
|
479
|
+
| `path` | 工程内已有的 `.py`,相对工程根 |
|
|
480
|
+
| `args` | 字符串数组。最多 16 个。每个参数只能含字母、数字、`_`、`.`、`/`、`:`、`@`、`=`、`+`、`-`、`,`,不能有空格或 shell 语法 |
|
|
481
|
+
| `timeoutMs` | 1000–120000,默认 20000 |
|
|
492
482
|
|
|
493
|
-
|
|
483
|
+
确认请求是 `PythonApprovalRequest`:`path`、`args`、`workspaceName`、`signal`。与文件确认分开,每次运行都要单独问一次。没有回调、用户拒绝、或脚本命中敏感规则时返回 403,不会启动进程。
|
|
494
484
|
|
|
495
|
-
|
|
485
|
+
成功时 `data` 为 `{ exitCode, timedOut, stdout, stderr }`。`exitCode !== 0` 仍然是工具成功(`code === 0`),脚本自己的失败在 `exitCode` 里。超时后 `timedOut === true`。同一时间只能跑一个脚本,再调返回 429。
|
|
496
486
|
|
|
497
|
-
|
|
487
|
+
脚本可能改了工程里的文件。运行结束后 SDK 发出 `files:changed`,`paths` 为空,目录树应重读当前看得到的各层。
|
|
498
488
|
|
|
499
|
-
|
|
500
|
-
- 随安装包分发:`Resources/node/`(Node 24)+ `Resources/workspace-sandbox/`(`yarn bundle --platform …` 产物),可选 `python/`
|
|
501
|
-
- 输出做路径反向替换,页面看不到工程绝对路径
|
|
502
|
-
- 细节与 Windows 步骤见 [`local-workspace-windows-host.md`](../bot-client-ui/docs/local-workspace-windows-host.md)
|
|
489
|
+
沙箱由宿主启动:工程目录可读写,解释器只读,运行时不能联网,也不能访问工程和解释器以外的文件。工程根下的 `sandbox-requirements.txt` 会在跑脚本前安装(每行一个 PyPI 包,最多 20 行)。参照实现是仓库里的 `examples/qt-workspace-host`。
|
|
503
490
|
|
|
504
491
|
## 宿主通道
|
|
505
492
|
|
|
506
|
-
端侧宿主(下文简称宿主)是内嵌此页面的桌面程序,例如用 WebView2
|
|
493
|
+
端侧宿主(下文简称宿主)是内嵌此页面的桌面程序,例如用 WebView2 加载页面的客户端。本地 Python 只能通过它运行。
|
|
507
494
|
|
|
508
495
|
`localFiles.backend` 为 `host-bridge` 时,页面通过 `window.chrome.webview` 和宿主说话。通道名固定 `glodon-workspace`。消息里只有相对路径和文件夹名,绝对路径留在宿主内。页面上不再出现「选择工作文件夹」。宿主还没推送目录时,`status` 为 `unsupported`。
|
|
509
496
|
|
|
@@ -516,23 +503,10 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
516
503
|
宿主立刻回当前工程。之后每次打开或关闭工程再推一次:
|
|
517
504
|
|
|
518
505
|
```json
|
|
519
|
-
{
|
|
520
|
-
"channel": "glodon-workspace",
|
|
521
|
-
"type": "workspace",
|
|
522
|
-
"granted": true,
|
|
523
|
-
"displayName": "sample-project",
|
|
524
|
-
"capabilities": ["fs-mutate", "sandbox-exec"],
|
|
525
|
-
"sandboxVersion": "0.1.0",
|
|
526
|
-
"sandboxProtocol": 1
|
|
527
|
-
}
|
|
506
|
+
{ "channel": "glodon-workspace", "type": "workspace", "granted": true, "displayName": "sample-project" }
|
|
528
507
|
```
|
|
529
508
|
|
|
530
|
-
`granted` 为 `false` 时页面断开工作区。`displayName`
|
|
531
|
-
|
|
532
|
-
| capability | 含义 |
|
|
533
|
-
| --- | --- |
|
|
534
|
-
| `sandbox-exec` | 支持 `exec`(经 workspace-sandbox);须同时带 `sandboxProtocol: 1` |
|
|
535
|
-
| `fs-mutate` | 支持 `mkdir` / `remove` / `move` |
|
|
509
|
+
`granted` 为 `false` 时页面断开工作区。`displayName` 只放文件夹名。
|
|
536
510
|
|
|
537
511
|
目录有增删时再推一条。`paths` 是发生变化的目录,相对工程根,根目录用 `""`。空数组表示让页面重读已展开的全部目录。短时间内多次变化可以合成一条。
|
|
538
512
|
|
|
@@ -542,7 +516,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
542
516
|
|
|
543
517
|
脚本跑完、用户在资源管理器里改文件,都应推送。Qt 示例用目录监视做这件事,默认不监视 `.git`、`node_modules`、`__pycache__` 内部。
|
|
544
518
|
|
|
545
|
-
其余请求都带 `id` 和 `op`。路径用 `/`,不能含 `..`、盘符、反斜杠或绝对路径。不合法时回 `{ "id", "ok": false, "name": "SecurityError" }
|
|
519
|
+
其余请求都带 `id` 和 `op`。路径用 `/`,不能含 `..`、盘符、反斜杠或绝对路径。不合法时回 `{ "id", "ok": false, "name": "SecurityError" }`,不要访问磁盘。
|
|
546
520
|
|
|
547
521
|
| op | 页面发来的字段 | 成功时宿主回 |
|
|
548
522
|
| --- | --- | --- |
|
|
@@ -550,8 +524,6 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
550
524
|
| `stat` | `path` | `entry`:同样的字段 |
|
|
551
525
|
| `read` | `path` | `contentBase64`。单文件不超过 50 MB |
|
|
552
526
|
| `write` | `path`、`contentBase64`、`createDirectories` | `{ "ok": true }`。父目录不存在且 `createDirectories` 不是 `true` 时回 `NotFoundError` |
|
|
553
|
-
| `mkdir` / `remove` / `move` | 路径规则同 write;`move` 用 `from`/`to`;需 `fs-mutate` | `{ "ok": true }` |
|
|
554
|
-
| `exec` | `protocol`(当前为 1)、`cwd`(工作区相对目录)、`command` 或 `argv`、`timeoutMs` | `exitCode`、`stdout`、`stderr`、`cwd?`、`timedOut?` |
|
|
555
527
|
| `run_python` | `path`、`args`、`timeoutMs` | `exitCode`、`timedOut`、`stdout`、`stderr` |
|
|
556
528
|
|
|
557
529
|
失败时统一 `{ "id", "ok": false, "name" }`:
|
|
@@ -565,9 +537,8 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
565
537
|
| `QuotaExceededError` | 读写超过 50 MB |
|
|
566
538
|
| `NoModificationAllowedError` | 写入没有完成 |
|
|
567
539
|
| `AbortError` | 已经有一个脚本在跑,或调用超时 |
|
|
568
|
-
| `InvalidModificationError` | 非空目录删除未带 `recursive` 等 |
|
|
569
540
|
|
|
570
|
-
`lastModified` 用 Unix 毫秒。`size` 用字节数。搜索、按行修改、上传、下载仍由页面完成,底层落到上面的 `list` / `read` / `write
|
|
541
|
+
`lastModified` 用 Unix 毫秒。`size` 用字节数。搜索、按行修改、上传、下载仍由页面完成,底层落到上面的 `list` / `read` / `write`。宿主不要自己实现那 9 个工具名。
|
|
571
542
|
|
|
572
543
|
## 安全与限额
|
|
573
544
|
|
|
@@ -618,7 +589,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
618
589
|
| 429 | 并发过多,或已有一个脚本在运行 |
|
|
619
590
|
| 499 | 已取消(停止回答、更换文件夹) |
|
|
620
591
|
| 500 | 内部异常。消息里不含路径和调用栈 |
|
|
621
|
-
| 501 |
|
|
592
|
+
| 501 | 当前不支持:正则搜索、非 session 的上传目标、网页环境里的 `run_python` |
|
|
622
593
|
|
|
623
594
|
## 开发
|
|
624
595
|
|
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
1
|
+
var q = Object.defineProperty, j = Object.defineProperties;
|
|
2
2
|
var L = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var
|
|
3
|
+
var b = Object.getOwnPropertySymbols;
|
|
4
4
|
var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var M = (r, c, e) => c in r ?
|
|
5
|
+
var M = (r, c, e) => c in r ? q(r, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[c] = e, m = (r, c) => {
|
|
6
6
|
for (var e in c || (c = {}))
|
|
7
7
|
F.call(c, e) && M(r, e, c[e]);
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
8
|
+
if (b)
|
|
9
|
+
for (var e of b(c))
|
|
10
10
|
N.call(c, e) && M(r, e, c[e]);
|
|
11
11
|
return r;
|
|
12
12
|
}, w = (r, c) => j(r, L(c));
|
|
13
|
-
var
|
|
13
|
+
var P = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
|
|
14
14
|
var y = (r, c, e) => new Promise((o, a) => {
|
|
15
15
|
var n = (i) => {
|
|
16
16
|
try {
|
|
@@ -47,20 +47,20 @@ function _(r) {
|
|
|
47
47
|
return r;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function E(r) {
|
|
51
51
|
return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
|
|
52
52
|
}
|
|
53
53
|
function Y(r, c) {
|
|
54
54
|
const e = _(r == null ? void 0 : r.query);
|
|
55
|
-
if (!
|
|
55
|
+
if (!E(e))
|
|
56
56
|
return e;
|
|
57
57
|
const o = _(c);
|
|
58
|
-
return
|
|
58
|
+
return E(o) && e != null ? e : o;
|
|
59
59
|
}
|
|
60
60
|
class Z extends D {
|
|
61
61
|
constructor(e, o = "", a, n, t, s) {
|
|
62
62
|
super(e, o, a, n, t, s);
|
|
63
|
-
|
|
63
|
+
P(this, "inflightCalls", /* @__PURE__ */ new Set());
|
|
64
64
|
}
|
|
65
65
|
prepareConnection() {
|
|
66
66
|
return new Promise((e) => y(this, null, function* () {
|
|
@@ -106,8 +106,8 @@ class Z extends D {
|
|
|
106
106
|
runnerIsClient: d,
|
|
107
107
|
pluginCode: l,
|
|
108
108
|
funcCode: g,
|
|
109
|
-
parameters:
|
|
110
|
-
requestBody:
|
|
109
|
+
parameters: h,
|
|
110
|
+
requestBody: x
|
|
111
111
|
}
|
|
112
112
|
} = t, u = this.messages[this.messages.length - 1];
|
|
113
113
|
if (!u.messageId)
|
|
@@ -150,7 +150,7 @@ class Z extends D {
|
|
|
150
150
|
f.warn("error", p), this.event.emit("error", p);
|
|
151
151
|
} else if (i === "FUNCTION_CALL" && d) {
|
|
152
152
|
f.log(`calling function ${g} of plugin ${l} with argument:
|
|
153
|
-
${JSON.stringify(
|
|
153
|
+
${JSON.stringify(h)}`);
|
|
154
154
|
const p = (R = C.plugins) == null ? void 0 : R[l];
|
|
155
155
|
if (!p) {
|
|
156
156
|
s({
|
|
@@ -159,16 +159,16 @@ class Z extends D {
|
|
|
159
159
|
});
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
const
|
|
163
|
-
if (typeof
|
|
162
|
+
const S = p[g];
|
|
163
|
+
if (typeof S != "function") {
|
|
164
164
|
s({
|
|
165
165
|
code: 404,
|
|
166
166
|
message: "没有找到插件方法。"
|
|
167
167
|
});
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
|
-
const
|
|
171
|
-
this.invokeClientPlugin(
|
|
170
|
+
const T = Y(h, x);
|
|
171
|
+
this.invokeClientPlugin(S, T, s, {
|
|
172
172
|
requestId: t.requestId,
|
|
173
173
|
pluginCode: l,
|
|
174
174
|
functionCode: g
|
|
@@ -205,12 +205,12 @@ class Z extends D {
|
|
|
205
205
|
};
|
|
206
206
|
this.handleStreamAnswer(t.data, i), this.pushMessage(i), this.event.emit("message:content", i), i.index === -1 && (i.isReplying = !1, this.event.emit("answer:finish", i));
|
|
207
207
|
}
|
|
208
|
-
} else if (t.data.updateSession && this.data && (this.data =
|
|
208
|
+
} else if (t.data.updateSession && this.data && (this.data = m(m({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
|
|
209
209
|
let s = this.messages[this.messages.length - 1];
|
|
210
210
|
if (s && !s.messageId)
|
|
211
|
-
s =
|
|
211
|
+
s = m(m({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
|
|
212
212
|
else {
|
|
213
|
-
const i =
|
|
213
|
+
const i = m({
|
|
214
214
|
messageId: "",
|
|
215
215
|
content: "",
|
|
216
216
|
role: v.Robot,
|
|
@@ -229,7 +229,7 @@ class Z extends D {
|
|
|
229
229
|
}
|
|
230
230
|
} else {
|
|
231
231
|
let s = this.messages[this.messages.length - 1];
|
|
232
|
-
s && !s.messageId ? (s =
|
|
232
|
+
s && !s.messageId ? (s = m(m({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(m({
|
|
233
233
|
messageId: "",
|
|
234
234
|
content: "",
|
|
235
235
|
role: v.Robot,
|
|
@@ -249,25 +249,25 @@ class Z extends D {
|
|
|
249
249
|
if (this._stopAnswer)
|
|
250
250
|
return;
|
|
251
251
|
if (!this.id) {
|
|
252
|
-
const
|
|
252
|
+
const h = new Error(
|
|
253
253
|
k.IdUndefined
|
|
254
254
|
// {
|
|
255
255
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
256
256
|
// }
|
|
257
257
|
);
|
|
258
|
-
f.error(
|
|
258
|
+
f.error(h), this.event.emit("error", h), this.frozen = !1;
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
261
|
const {
|
|
262
262
|
type: s,
|
|
263
263
|
data: i,
|
|
264
264
|
requestId: d
|
|
265
|
-
} = t, l = this.messages.findIndex((
|
|
265
|
+
} = t, l = this.messages.findIndex((h) => h.messageId === d && h.role === v.User);
|
|
266
266
|
if (l < 0)
|
|
267
267
|
return;
|
|
268
268
|
const g = l + 1;
|
|
269
269
|
if (g >= this.messages.length) {
|
|
270
|
-
const
|
|
270
|
+
const h = {
|
|
271
271
|
messageId: "",
|
|
272
272
|
content: "",
|
|
273
273
|
role: v.Robot,
|
|
@@ -282,11 +282,11 @@ class Z extends D {
|
|
|
282
282
|
},
|
|
283
283
|
isReplying: !0
|
|
284
284
|
};
|
|
285
|
-
this.pushMessage(
|
|
285
|
+
this.pushMessage(h);
|
|
286
286
|
}
|
|
287
|
-
s === "KG" ? (this.messages[g] = w(
|
|
287
|
+
s === "KG" ? (this.messages[g] = w(m({}, this.messages[g]), {
|
|
288
288
|
reference: i.knowledgeReference
|
|
289
|
-
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(
|
|
289
|
+
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(m({}, this.messages[g]), {
|
|
290
290
|
searchReference: i.knowledgeReference
|
|
291
291
|
}), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
292
292
|
})), this.socket = n, n.open();
|
|
@@ -329,18 +329,17 @@ class Z extends D {
|
|
|
329
329
|
return y(this, null, function* () {
|
|
330
330
|
var n, t, s;
|
|
331
331
|
this.convertKnowledgesToChatFormat(this.knowledges);
|
|
332
|
-
let a = w(
|
|
333
|
-
promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(
|
|
332
|
+
let a = w(m({}, e), {
|
|
333
|
+
promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(m({}, i), {
|
|
334
334
|
[d.key]: d.value
|
|
335
335
|
}), {}),
|
|
336
|
-
systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(
|
|
336
|
+
systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(m({}, i), {
|
|
337
337
|
[d.key]: d.value
|
|
338
338
|
}), {}),
|
|
339
339
|
knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
|
|
340
340
|
//agent支持指定文件时再放开
|
|
341
341
|
// knowledges: knowledgesForChat,
|
|
342
|
-
|
|
343
|
-
enableTitleSummary: !0
|
|
342
|
+
enableTitleSummary: this.resolveEnableTitleSummary()
|
|
344
343
|
});
|
|
345
344
|
if (!this.active) {
|
|
346
345
|
if (yield this.activate(), !this.socket) {
|