@glodon-aiot/bot-client-sdk 3.26.0-alpha.19 → 3.26.0-alpha.21
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 +18 -7
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +47 -33
- package/dist/es/localFiles/errors.mjs +21 -19
- package/dist/es/localFiles/host/sandboxClient.mjs +196 -171
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +19 -16
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +191 -133
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +22 -22
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +4 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +4 -0
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +1 -0
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +13 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -258,7 +258,7 @@ const workspace = client.localWorkspace;
|
|
|
258
258
|
|
|
259
259
|
**`find`** 按文件名通配查找,`name` 等同 `find -name`。`data.files` 是匹配路径,一行一个。
|
|
260
260
|
|
|
261
|
-
**`shell`** 执行一条 shell 命令(每次新 shell,只保留上次 cwd)。起始目录是工作区根。命令不超过 20000 字。执行器见[命令和脚本](#命令和脚本)。工具 `code` 为 0 时进程退出码在 `data.exitCode
|
|
261
|
+
**`shell`** 执行一条 shell 命令(每次新 shell,只保留上次 cwd)。起始目录是工作区根。命令不超过 20000 字。执行器见[命令和脚本](#命令和脚本)。工具 `code` 为 0 时进程退出码在 `data.exitCode`。脚本能否联网由宿主决定;被拒绝的地址写在 `stderr` 里。
|
|
262
262
|
|
|
263
263
|
**`run_file`** 执行已存在的脚本。浏览器:`.py`(Pyodide)、`.sh`(just-bash);`.js` / `node` 明确不支持。宿主沙箱:另支持 `.js`(沙箱自带 Node)。
|
|
264
264
|
|
|
@@ -333,6 +333,8 @@ const disclosureAcked = await workspace.isDisclosureAcknowledged();
|
|
|
333
333
|
| `stat(path?)` | 看这一项是文件还是目录 |
|
|
334
334
|
| `read(path)` | 读出整个文件,得到 `Blob` |
|
|
335
335
|
| `readText(path)` | 读出整个文件的 UTF-8 文本 |
|
|
336
|
+
| `url(path)` | 给 `<img>`、`<video>`、`<audio>` 的地址。浏览器自己拉字节 |
|
|
337
|
+
| `releaseUrl(url)` | 页面不再显示这个地址时调用。引用归零后地址作废 |
|
|
336
338
|
| `write(path, source)` | 覆盖写入。`source` 可以是字符串、`Uint8Array` 或字节流。父目录不存在时会创建 |
|
|
337
339
|
| `append(path, source)` | 在末尾追加字符串或 `Uint8Array`。文件不存在时创建 |
|
|
338
340
|
| `mkdir(path)` | 逐级创建目录。目录已存在时不做任何事 |
|
|
@@ -363,7 +365,7 @@ await workspace.files.move('notes/a.md', 'notes/b.md');
|
|
|
363
365
|
| --- | --- |
|
|
364
366
|
| `workspace_not_granted` | 还没授权。授权中途失效时,`status` 会先离开 `granted`,然后再抛这个错误 |
|
|
365
367
|
| `path_outside_workspace` | 路径越出了工作区 |
|
|
366
|
-
| `sensitive_file` |
|
|
368
|
+
| `sensitive_file` | 读、写、追加、删除、移动敏感文件,或为它签发地址。`list` 和 `stat` 仍会返回这些文件,只是 `sensitive` 为 `true` |
|
|
367
369
|
|
|
368
370
|
`code` 的完整含义见[错误码](#错误码)。当前工作区如果只是一次文件选择留下的内存快照(`attachFileSnapshot`),可以读、列目录和在内存里写;`mkdir`、`remove`、`move` 的 `code` 为 501,内容也不会写回磁盘。
|
|
369
371
|
|
|
@@ -413,7 +415,15 @@ workspace.on('tool:finish', (event) => {
|
|
|
413
415
|
});
|
|
414
416
|
```
|
|
415
417
|
|
|
416
|
-
|
|
418
|
+
目录树只展示名字和层级。用户打开文本时,用 `files.read` 或 `files.readText`。图片、音视频和 PDF 用 `url`,把返回的地址放进标签,离开画面时 `releaseUrl`。不要用 `read` 再转成地址,那会把整个文件放进页面内存。这个地址只给界面,不要写进发给模型的内容。交给模型的文件内容只来自助手自己调用的内置工具。
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
const url = await workspace.files.url('shots/a.png');
|
|
422
|
+
// <img src={url} alt="" loading="lazy" />
|
|
423
|
+
workspace.files.releaseUrl(url);
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
沙箱里的地址是 `http://127.0.0.1:<端口>/file/<票据>`。票据只对应这一个相对路径,不是连接令牌。30 分钟没有再次读取就会过期,浏览器因为 `no-cache` 重新请求时会顺延;`releaseUrl` 或工作区关闭后立即作废。这个地址每次请求都读磁盘上的当前内容。网页里选的文件夹则是 `blob:` 地址,内容停在取地址的那一刻,文件改了要再调用 `url`。只能用于图片、音视频和 PDF,其他文件会失败。
|
|
417
427
|
|
|
418
428
|
### 确认弹窗
|
|
419
429
|
|
|
@@ -483,7 +493,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
483
493
|
|
|
484
494
|
## 命令和脚本
|
|
485
495
|
|
|
486
|
-
`shell`、`run_file` 共用同一套执行器选择(`runnerFor`)。`run_skill_script` 只用注入的执行器或已就绪的宿主沙箱,没有沙箱时不改走浏览器运行时。成功时 `data` 为 `{ exitCode, stdout, stderr, cwd? }`。`exitCode !== 0` 仍是工具成功(`code === 0`)。跨命令只保留 cwd
|
|
496
|
+
`shell`、`run_file` 共用同一套执行器选择(`runnerFor`)。`run_skill_script` 只用注入的执行器或已就绪的宿主沙箱,没有沙箱时不改走浏览器运行时。成功时 `data` 为 `{ exitCode, stdout, stderr, cwd? }`。`exitCode !== 0` 仍是工具成功(`code === 0`)。跨命令只保留 cwd,不保留环境变量。浏览器运行时同一工作区一次只跑一条命令。连上本地沙箱后,页面不再限制条数,同时能跑几条由沙箱的 `exec.maxConcurrent` 决定;超出时沙箱拒绝,工具 `code` 为 429。
|
|
487
497
|
|
|
488
498
|
### 执行器选择顺序
|
|
489
499
|
|
|
@@ -520,15 +530,16 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
520
530
|
|
|
521
531
|
### 宿主沙箱(摘要)
|
|
522
532
|
|
|
523
|
-
- 宿主把沙箱放进独立进程组,启动 `workspace-sandbox --listen --root <工程绝对路径> --origin
|
|
524
|
-
-
|
|
525
|
-
- 页面从 `sandbox.url` / `sandbox.token` 直连。HTTPS 页面仍连 `ws://127.0.0.1`,不提供 `wss
|
|
533
|
+
- 宿主把沙箱放进独立进程组,启动 `workspace-sandbox --listen --root <工程绝对路径> --origin <页面来源>`。联网、Python 依赖安装和同时命令数由 `--policy` 决定,页面不能改
|
|
534
|
+
- 宿主只做这些事:启动、读 ready、可选地询问 status、经 stdin 更新策略、shutdown(3 秒后结束进程组)、把退出告诉页面
|
|
535
|
+
- 页面从 `sandbox.url` / `sandbox.token` 直连。HTTPS 页面仍连 `ws://127.0.0.1`,不提供 `wss://`。认证回复和之后的 `policy` 推送带策略摘要:`exec.maxConcurrent`、`network.mode`、`network.allow`、`packages.python.enabled`。不含上游代理和镜像地址
|
|
526
536
|
- CSP 的 `connect-src` 要放行 `ws://127.0.0.1:*`。SDK 只加载在可信页面上,同页脚本能读到令牌
|
|
527
537
|
- 启动失败的 `reason` 对应固定说明,例如 `listen-failed` 是「沙箱没有监听到端口。」消息里没有令牌和绝对路径
|
|
528
538
|
- 运行中崩溃时推送 `sandbox.state: "exited"`。同一次打开最多自动重启一次
|
|
529
539
|
- 文件被其他程序占用时原文件保持不变,错误是「文件正在被占用,没有写入。」
|
|
530
540
|
- 随安装包分发:`Resources/node/`(Node 24)+ `Resources/workspace-sandbox/`(`yarn bundle --platform …` 产物),可选 `python/`
|
|
531
541
|
- 输出做路径反向替换,页面看不到工程绝对路径,也看不到技能缓存的绝对路径
|
|
542
|
+
- 默认断网。`allowlist` 下被拒绝的 `host:port` 追加在 `stderr`:「宿主网络策略拒绝了:…。不要重试这些地址;需要时请用户在宿主设置里允许。」`open` 且宿主允许安装时,脚本可以直接运行 `pip`。其他情况把包名写进工程根的 `sandbox-requirements.txt`;宿主关闭安装后,工程里有这个文件的命令不会运行。策略文件格式见 `@glodon-aiot/workspace-sandbox` 的 README
|
|
532
543
|
- 平台技能:进入会话时按编排 `arrange[0].skills` 核对已发布版本(`version >= 1`)。页面用当时的 `client.token` 作 `Authorization: Bearer` 下载 ZIP,再经已认证的本地 WebSocket 交给沙箱 `installSkill`。沙箱收不到这个令牌。缓存按系统放在用户目录(Windows `%LOCALAPPDATA%\glodon-workspace-sandbox`,macOS `~/Library/Caches/glodon-workspace-sandbox`,Linux `$XDG_CACHE_HOME` 或 `~/.cache` 下的同名目录),不在工程内。删除会话不删缓存;编排不再引用且没有脚本在跑的版本,下次进入会话时删除。非 debug 的对话气泡不显示这三个技能工具
|
|
533
544
|
- 细节与 Windows 步骤见 [`local-workspace-windows-host.md`](../bot-client-ui/docs/local-workspace-windows-host.md)
|
|
534
545
|
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var h = (r, t) => {
|
|
3
3
|
if (t = Symbol[r])
|
|
4
4
|
return t;
|
|
5
5
|
throw Error("Symbol." + r + " is not defined");
|
|
6
6
|
};
|
|
7
|
-
var g = (r, t, e) => t in r ?
|
|
8
|
-
var
|
|
7
|
+
var g = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
8
|
+
var y = (r, t, e) => (g(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
9
9
|
var o = (r, t, e) => new Promise((s, a) => {
|
|
10
10
|
var n = (i) => {
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
d(e.next(i));
|
|
13
13
|
} catch (c) {
|
|
14
14
|
a(c);
|
|
15
15
|
}
|
|
16
|
-
},
|
|
16
|
+
}, l = (i) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
d(e.throw(i));
|
|
19
19
|
} catch (c) {
|
|
20
20
|
a(c);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
23
|
-
|
|
22
|
+
}, d = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(n, l);
|
|
23
|
+
d((e = e.apply(r, t)).next());
|
|
24
24
|
});
|
|
25
|
-
var f = (r, t, e) => (t = r[
|
|
26
|
-
import { throwIfAborted as
|
|
27
|
-
import { SandboxClient as
|
|
25
|
+
var f = (r, t, e) => (t = r[h("asyncIterator")]) ? t.call(r) : (r = r[h("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (n) => new Promise((l, d, i) => (n = a.call(r, n), i = n.done, Promise.resolve(n.value).then((c) => l({ value: c, done: i }), d)))), e("next"), e("return"), t);
|
|
26
|
+
import { throwIfAborted as v } from "../errors.mjs";
|
|
27
|
+
import { SandboxClient as w } from "../host/sandboxClient.mjs";
|
|
28
28
|
import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
|
|
29
|
-
import { domError as
|
|
29
|
+
import { domError as m, toChunks as M } from "./WorkspaceFileAdapter.mjs";
|
|
30
30
|
function x(r, t) {
|
|
31
31
|
const e = r && typeof r == "object" ? r : {}, s = e.kind === "directory" ? "directory" : "file", a = {
|
|
32
32
|
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
@@ -34,13 +34,13 @@ function x(r, t) {
|
|
|
34
34
|
};
|
|
35
35
|
return s === "file" && typeof e.size == "number" && (a.size = e.size), typeof e.lastModified == "number" && (a.lastModified = e.lastModified), a;
|
|
36
36
|
}
|
|
37
|
-
class
|
|
38
|
-
constructor(t, e = "", s = new
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
class P {
|
|
38
|
+
constructor(t, e = "", s = new w()) {
|
|
39
|
+
y(this, "displayName");
|
|
40
|
+
y(this, "capabilities", /* @__PURE__ */ new Set());
|
|
41
|
+
y(this, "sandboxVersion");
|
|
42
|
+
y(this, "sandboxProtocol");
|
|
43
|
+
y(this, "sandbox");
|
|
44
44
|
this.displayName = e, this.sandbox = s;
|
|
45
45
|
}
|
|
46
46
|
setCapabilities(t, e = {}) {
|
|
@@ -72,6 +72,20 @@ class S {
|
|
|
72
72
|
return (Array.isArray(s.entries) ? s.entries : []).map((n) => x(n, ""));
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
+
url(t) {
|
|
76
|
+
return o(this, null, function* () {
|
|
77
|
+
const e = yield this.sandbox.url(t), s = this.sandbox.httpOrigin();
|
|
78
|
+
if (!s)
|
|
79
|
+
throw m("NotAllowedError", this.unavailableMessage());
|
|
80
|
+
return {
|
|
81
|
+
url: `http://${s}/file/${e}`,
|
|
82
|
+
release: () => {
|
|
83
|
+
this.sandbox.releaseUrl(e).catch(() => {
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
75
89
|
readFile(t, e) {
|
|
76
90
|
return o(this, null, function* () {
|
|
77
91
|
var a;
|
|
@@ -105,7 +119,7 @@ class S {
|
|
|
105
119
|
skill: t.skill
|
|
106
120
|
}, t.signal, t.onOutput);
|
|
107
121
|
if (e.timedOut)
|
|
108
|
-
throw
|
|
122
|
+
throw m("AbortError", "命令运行超时。");
|
|
109
123
|
return e;
|
|
110
124
|
});
|
|
111
125
|
}
|
|
@@ -119,30 +133,30 @@ class S {
|
|
|
119
133
|
yield this.sandbox.write(t, e, s.createDirectories === !0, s.signal);
|
|
120
134
|
return;
|
|
121
135
|
}
|
|
122
|
-
const
|
|
136
|
+
const l = [];
|
|
123
137
|
try {
|
|
124
|
-
for (var
|
|
125
|
-
const
|
|
126
|
-
|
|
138
|
+
for (var C = f(M(e)), z, L, U; z = !(L = yield C.next()).done; z = !1) {
|
|
139
|
+
const b = L.value;
|
|
140
|
+
v(s.signal), l.push(b);
|
|
127
141
|
}
|
|
128
142
|
} catch (L) {
|
|
129
|
-
|
|
143
|
+
U = [L];
|
|
130
144
|
} finally {
|
|
131
145
|
try {
|
|
132
|
-
z && (L =
|
|
146
|
+
z && (L = C.return) && (yield L.call(C));
|
|
133
147
|
} finally {
|
|
134
|
-
if (
|
|
135
|
-
throw
|
|
148
|
+
if (U)
|
|
149
|
+
throw U[0];
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
|
-
const
|
|
152
|
+
const d = l.reduce((b, p) => b + p.byteLength, 0), i = new Uint8Array(d);
|
|
139
153
|
let c = 0;
|
|
140
|
-
|
|
141
|
-
i.set(
|
|
154
|
+
l.forEach((b) => {
|
|
155
|
+
i.set(b, c), c += b.byteLength;
|
|
142
156
|
}), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
|
|
143
157
|
});
|
|
144
158
|
}
|
|
145
159
|
}
|
|
146
160
|
export {
|
|
147
|
-
|
|
161
|
+
P as HostBridgeAdapter
|
|
148
162
|
};
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var E = (r, t,
|
|
3
|
-
var a = (r, t,
|
|
4
|
-
var
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
1
|
+
var s = Object.defineProperty;
|
|
2
|
+
var E = (r, t, n) => t in r ? s(r, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[t] = n;
|
|
3
|
+
var a = (r, t, n) => (E(r, typeof t != "symbol" ? t + "" : t, n), n);
|
|
4
|
+
var w = /* @__PURE__ */ ((r) => (r[r.Ok = 0] = "Ok", r[r.BadRequest = 400] = "BadRequest", r[r.Forbidden = 403] = "Forbidden", r[r.NotFound = 404] = "NotFound", r[r.Timeout = 408] = "Timeout", r[r.Conflict = 409] = "Conflict", r[r.TooLarge = 413] = "TooLarge", r[r.TooManyRequests = 429] = "TooManyRequests", r[r.Cancelled = 499] = "Cancelled", r[r.Internal = 500] = "Internal", r[r.NotImplemented = 501] = "NotImplemented", r))(w || {});
|
|
5
|
+
class e extends Error {
|
|
6
|
+
constructor(n, u, i) {
|
|
7
7
|
super(u);
|
|
8
8
|
a(this, "code");
|
|
9
9
|
a(this, "data");
|
|
10
|
-
this.name = "ToolError", this.code =
|
|
10
|
+
this.name = "ToolError", this.code = n, this.data = i;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const f = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
|
|
14
14
|
function m() {
|
|
15
|
-
return new
|
|
15
|
+
return new e(403, f, {
|
|
16
16
|
reason: "workspace_not_granted"
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function c() {
|
|
20
|
-
return new
|
|
20
|
+
return new e(499, "操作已取消。");
|
|
21
21
|
}
|
|
22
22
|
function N(r) {
|
|
23
23
|
if (r != null && r.aborted)
|
|
24
24
|
throw c();
|
|
25
25
|
}
|
|
26
26
|
function o(r) {
|
|
27
|
-
if (r instanceof
|
|
27
|
+
if (r instanceof e)
|
|
28
28
|
return r;
|
|
29
29
|
switch (r && typeof r == "object" && "name" in r ? String(r.name) : "") {
|
|
30
30
|
case "NotFoundError":
|
|
31
|
-
return new
|
|
31
|
+
return new e(404, "文件或目录不存在。");
|
|
32
32
|
case "TypeMismatchError":
|
|
33
|
-
return new
|
|
33
|
+
return new e(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
|
|
34
34
|
case "NotAllowedError":
|
|
35
35
|
case "SecurityError":
|
|
36
36
|
return m();
|
|
@@ -39,17 +39,19 @@ function o(r) {
|
|
|
39
39
|
case "NoModificationAllowedError":
|
|
40
40
|
case "InvalidModificationError":
|
|
41
41
|
case "InvalidStateError":
|
|
42
|
-
return new
|
|
42
|
+
return new e(403, "文件当前不可写,可能正被其他程序占用或为只读。");
|
|
43
43
|
case "QuotaExceededError":
|
|
44
|
-
return new
|
|
44
|
+
return new e(413, "磁盘空间不足或超出写入配额。");
|
|
45
|
+
case "PreviewLimitError":
|
|
46
|
+
return new e(413, "同时预览的文件过多,请先关掉一些预览。");
|
|
45
47
|
default:
|
|
46
|
-
return new
|
|
48
|
+
return new e(500, "本地文件操作失败,请稍后重试。");
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
export {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
w as ToolCode,
|
|
53
|
+
e as ToolError,
|
|
54
|
+
f as WORKSPACE_NOT_GRANTED_MESSAGE,
|
|
53
55
|
c as cancelledError,
|
|
54
56
|
N as throwIfAborted,
|
|
55
57
|
o as toToolError,
|