@glodon-aiot/bot-client-sdk 3.26.0-alpha.10 → 3.26.0-alpha.11
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 +11 -9
- package/dist/es/index.mjs +56 -52
- package/dist/es/localFiles/host/connectHostBridge.mjs +1 -1
- package/dist/es/localFiles/host/protocol.mjs +26 -14
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +35 -35
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +2 -2
- package/dist/src/localFiles/host/protocol.d.ts +11 -2
- package/dist/src/localFiles/index.d.ts +6 -4
- package/dist/src/localFiles/types.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ AIoT 应用客户端 SDK,支持 Agent 应用和对话型应用。会话、消
|
|
|
10
10
|
| 命令与脚本(shell / run_file) | Agent | 浏览器运行时或端侧宿主沙箱 | [命令和脚本](#命令和脚本) |
|
|
11
11
|
| 本地 Python(`localPython` / `run_python`) | Agent | **优先端侧宿主**;浏览器可用 Pyodide | [命令和脚本](#命令和脚本) |
|
|
12
12
|
|
|
13
|
-
浏览器指现代浏览器(命令运行时另需能加载公司 OBS 上的 just-bash / Pyodide
|
|
13
|
+
浏览器指现代浏览器(命令运行时另需能加载公司 OBS 上的 just-bash / Pyodide)。端侧宿主是内嵌此页面、选择本地工程并管理 `@glodon-aiot/workspace-sandbox` 进程的桌面程序;文件和命令由页面直连沙箱,不经过宿主转发,见[宿主通道](#宿主通道)。
|
|
14
14
|
|
|
15
15
|
集成方总览见仓库内 [`bot-client-ui/docs/agent-integration-handbook.md`](../bot-client-ui/docs/agent-integration-handbook.md)。
|
|
16
16
|
|
|
@@ -158,7 +158,7 @@ const client = new BotClient(token, {
|
|
|
158
158
|
|
|
159
159
|
`localFiles` 或 `localPython` 任一启用后,SDK 把同一套内置工具注册到 `pluginCode` `builtin_tools`。`client.localWorkspace` 只在 `localFiles.enabled === true` 时存在。
|
|
160
160
|
|
|
161
|
-
`shell` / `run_file` / `run_skill_script` 按[命令和脚本](#命令和脚本)选择执行器:注入的 `commandRunner` →
|
|
161
|
+
`shell` / `run_file` / `run_skill_script` 按[命令和脚本](#命令和脚本)选择执行器:注入的 `commandRunner` → 已就绪的协议 2 沙箱 → 无宿主页面中的 just-bash / Pyodide(默认开启)→ 否则 501。宿主工作区已授权但沙箱未就绪时直接失败,不降级到浏览器运行时。
|
|
162
162
|
|
|
163
163
|
业务 `plugins` 里如果已经有 `builtin_tools` 这个 key,内置工具不会注册,`error` 事件会带上原因。同一页面只支持一个启用了内置插件的 `BotClient`(插件表是全局配置)。
|
|
164
164
|
|
|
@@ -244,7 +244,7 @@ const client = new BotClient(token, {
|
|
|
244
244
|
const workspace = client.localWorkspace;
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
-
`transfer`
|
|
247
|
+
`transfer` 仍可供旧的上传下载实现使用。当前注册的内置工具不走这套传输。宿主沙箱由 `workspace.sandbox.state === "ready"` 且 `protocol === 2` 表示可用,不在 `commandRuntime` 里配置;`capabilities` 只用于兼容旧的 workspace 消息。
|
|
248
248
|
|
|
249
249
|
### 十一个工具
|
|
250
250
|
|
|
@@ -463,12 +463,12 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
463
463
|
|
|
464
464
|
### 执行器选择顺序
|
|
465
465
|
|
|
466
|
-
1. **注入的** `LocalWorkspace.commandRunner`(测试 /
|
|
466
|
+
1. **注入的** `LocalWorkspace.commandRunner`(测试 / 自定义,优先级最高)
|
|
467
467
|
2. **沙箱直连**:宿主工作区已授权,且 `sandbox.state` 为 `ready`、`protocol` 为 `2` → 页面对 `ws://127.0.0.1` 发 WebSocket,不经宿主转发文件和命令
|
|
468
468
|
3. **浏览器运行时**:没有宿主 WebView 时,`commandRuntime.browser.enabled` 默认为 `true` → just-bash + Pyodide Worker
|
|
469
469
|
4. 以上皆不可用 → **501**
|
|
470
470
|
|
|
471
|
-
宿主工作区已经授权时,沙箱没就绪不会改走浏览器运行时。`starting`
|
|
471
|
+
宿主工作区已经授权时,沙箱没就绪不会改走浏览器运行时。`starting` 时说明正在启动;失败说明使用 `sandbox.message`。协议不是 2 时另发一次 `error` 事件。收到 `bye`、`exited` 或 `failed` 后,在途调用以 `AbortError` 失败且不会重放;只有新的 `ready` 到达后才使用新地址和令牌连接。
|
|
472
472
|
|
|
473
473
|
参照宿主:`examples/qt-workspace-host`。
|
|
474
474
|
|
|
@@ -497,7 +497,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
497
497
|
### 宿主沙箱(摘要)
|
|
498
498
|
|
|
499
499
|
- 宿主把沙箱放进独立进程组,启动 `workspace-sandbox --listen --root <工程绝对路径> --origin <页面来源>`
|
|
500
|
-
- 宿主只做五件事:启动、读 ready
|
|
500
|
+
- 宿主只做五件事:启动、读 ready、可选地询问 status、shutdown(3 秒后结束进程组)、把退出告诉页面
|
|
501
501
|
- 页面从 `sandbox.url` / `sandbox.token` 直连。HTTPS 页面仍连 `ws://127.0.0.1`,不提供 `wss://`
|
|
502
502
|
- CSP 的 `connect-src` 要放行 `ws://127.0.0.1:*`。SDK 只加载在可信页面上,同页脚本能读到令牌
|
|
503
503
|
- 启动失败的 `reason` 对应固定说明,例如 `listen-failed` 是「沙箱没有监听到端口。」消息里没有令牌和绝对路径
|
|
@@ -509,9 +509,11 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
509
509
|
|
|
510
510
|
## 宿主通道
|
|
511
511
|
|
|
512
|
-
|
|
512
|
+
端侧宿主是内嵌此页面的桌面程序。页面由哪种内核显示没有要求。
|
|
513
513
|
|
|
514
|
-
`localFiles.backend` 为 `host-bridge`
|
|
514
|
+
`localFiles.backend` 为 `host-bridge` 时,宿主在页面脚本运行前提供消息桥 `globalThis.__glodonHostBridge`。它需要三个方法:`postMessage(message)`、`addEventListener('message', listener)` 和 `removeEventListener('message', listener)`。页面也可以调用 `registerHostBridge(bridge)` 挂上同一个对象。自带 `chrome.webview` 且方法一致的环境,没有注册时会直接使用它。
|
|
515
|
+
|
|
516
|
+
通道名固定 `glodon-workspace`。消息里只有相对路径和文件夹名,绝对路径留在宿主内。页面上不再出现「选择工作文件夹」。宿主还没推送目录时,`status` 为 `unsupported`。
|
|
515
517
|
|
|
516
518
|
页面加载后先发:
|
|
517
519
|
|
|
@@ -538,7 +540,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
538
540
|
}
|
|
539
541
|
```
|
|
540
542
|
|
|
541
|
-
`granted` 为 `false` 时页面断开工作区。`displayName` 只放文件夹名。`sandbox.state` 还可以是 `starting`、`failed`、`exited`。`failed` 带固定 `message
|
|
543
|
+
`granted` 为 `false` 时页面断开工作区。`displayName` 只放文件夹名。`sandbox.state` 还可以是 `starting`、`failed`、`exited`。`failed` 带固定 `message`,不带令牌和绝对路径。`capabilities` 和 `sandboxVersion` 是兼容/诊断字段,是否建立直连只取决于 `sandbox.state`、`url`、`token` 和 `protocol`。页面不向宿主发送文件或命令操作。
|
|
542
544
|
|
|
543
545
|
目录有增删时再推一条。`paths` 是发生变化的目录,相对工程根,根目录用 `""`。空数组表示让页面重读已展开的全部目录。短时间内多次变化可以合成一条。
|
|
544
546
|
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,71 +1,75 @@
|
|
|
1
1
|
import { configuration as e, configure as T, getRegisteredLocalFilesPluginCode as E, getRegisteredLocalPythonPluginCode as r, resolveLocalFilesPluginCode as L } from "./Config.mjs";
|
|
2
2
|
import { default as S } from "./BotClient.mjs";
|
|
3
|
-
import { default as
|
|
3
|
+
import { default as A } from "./Session.mjs";
|
|
4
4
|
import { default as C } from "./AgentPlugin.mjs";
|
|
5
5
|
import { ToolCode as l, ToolError as D, toToolError as R } from "./localFiles/errors.mjs";
|
|
6
|
-
import { LOCAL_FILE_TOOL_SCHEMAS as a, LOCAL_PYTHON_TOOL_SCHEMA as
|
|
7
|
-
import { BUILTIN_TOOL_SCHEMAS as
|
|
8
|
-
import { createLocalFilesPlugin as
|
|
9
|
-
import { LocalWorkspace as
|
|
10
|
-
import { createIndexedDbStore as
|
|
11
|
-
import { FileSystemAccessAdapter as
|
|
6
|
+
import { LOCAL_FILE_TOOL_SCHEMAS as a, LOCAL_PYTHON_TOOL_SCHEMA as f } from "./localFiles/schemas.mjs";
|
|
7
|
+
import { BUILTIN_TOOL_SCHEMAS as U } from "./builtinTools/schemas.mjs";
|
|
8
|
+
import { createLocalFilesPlugin as H } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
9
|
+
import { LocalWorkspace as p } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
10
|
+
import { createIndexedDbStore as P, createMemoryStore as x } from "./localFiles/workspace/handleStore.mjs";
|
|
11
|
+
import { FileSystemAccessAdapter as n } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
|
|
12
12
|
import { MemoryWorkspaceAdapter as g } from "./localFiles/adapters/MemoryWorkspaceAdapter.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { HOST_BRIDGE_GLOBAL as X, HOST_CHANNEL as u, registerHostBridge as Y } from "./localFiles/host/protocol.mjs";
|
|
14
|
+
import { createDefaultSessionFileTransfer as W } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
15
|
+
import { getDownloadUrlAllowlist as y, isDownloadUrlAllowed as K } from "./localFiles/security/downloadUrlPolicy.mjs";
|
|
16
|
+
import { SDK_SENSITIVE_BASELINE as b } from "./localFiles/security/sensitiveFiles.mjs";
|
|
17
|
+
import { BINARY_SNIFF_BYTES as v, BUILTIN_TOOLS_PLUGIN_CODE as V, BUILTIN_TOOLS_PLUGIN_CODES as Z, DEFAULT_DOWNLOAD_URL_ALLOWLIST as j, DEFAULT_IGNORED_DIRECTORIES as q, DEFAULT_IGNORED_FILE_PATTERNS as z, DEFAULT_LIMITS as J, KiB as Q, LIST_DIRECTORY_DEFAULT_LIMIT as $, LIST_DIRECTORY_MAX_LIMIT as __, LOCAL_FILES_FUNCTION_CODES as o_, LOCAL_FILES_PLUGIN_CODES as e_, LOCAL_PYTHON_FUNCTION_CODE as T_, LOCAL_PYTHON_PLUGIN_CODES as E_, MiB as r_, PYTHON_DEFAULT_TIMEOUT_MS as L_, PYTHON_MAX_ARGS as I_, PYTHON_MAX_TIMEOUT_MS as S_, SEARCH_DEFAULT_DEPTH as O_, SEARCH_FUNCTION_CODES as A_, SEARCH_MAX_DEPTH as t_, TEXT_SEARCH_MAX_CONTEXT_LINES as C_, TEXT_SEARCH_MAX_FILES as N_, TEXT_SEARCH_MAX_FILE_BYTES as l_, TEXT_SEARCH_MAX_LINE_CHARS as D_, TRANSFER_FILE_SIZE_LIMIT_MB as R_, TRANSFER_FUNCTION_CODES as F_, WORKSPACE_GRANT_ID as a_, WRITE_FUNCTION_CODES as f_ } from "./localFiles/constants.mjs";
|
|
17
18
|
export {
|
|
18
19
|
C as AgentPlugin,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
v as BINARY_SNIFF_BYTES,
|
|
21
|
+
V as BUILTIN_TOOLS_PLUGIN_CODE,
|
|
22
|
+
Z as BUILTIN_TOOLS_PLUGIN_CODES,
|
|
23
|
+
U as BUILTIN_TOOL_SCHEMAS,
|
|
23
24
|
S as BotClient,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
j as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
26
|
+
q as DEFAULT_IGNORED_DIRECTORIES,
|
|
27
|
+
z as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
28
|
+
J as DEFAULT_LIMITS,
|
|
29
|
+
n as FileSystemAccessAdapter,
|
|
30
|
+
X as HOST_BRIDGE_GLOBAL,
|
|
31
|
+
u as HOST_CHANNEL,
|
|
32
|
+
Q as KiB,
|
|
33
|
+
$ as LIST_DIRECTORY_DEFAULT_LIMIT,
|
|
34
|
+
__ as LIST_DIRECTORY_MAX_LIMIT,
|
|
35
|
+
o_ as LOCAL_FILES_FUNCTION_CODES,
|
|
36
|
+
e_ as LOCAL_FILES_PLUGIN_CODES,
|
|
34
37
|
a as LOCAL_FILE_TOOL_SCHEMAS,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
T_ as LOCAL_PYTHON_FUNCTION_CODE,
|
|
39
|
+
E_ as LOCAL_PYTHON_PLUGIN_CODES,
|
|
40
|
+
f as LOCAL_PYTHON_TOOL_SCHEMA,
|
|
41
|
+
p as LocalWorkspace,
|
|
39
42
|
g as MemoryWorkspaceAdapter,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
r_ as MiB,
|
|
44
|
+
L_ as PYTHON_DEFAULT_TIMEOUT_MS,
|
|
45
|
+
I_ as PYTHON_MAX_ARGS,
|
|
46
|
+
S_ as PYTHON_MAX_TIMEOUT_MS,
|
|
47
|
+
b as SDK_SENSITIVE_BASELINE,
|
|
48
|
+
O_ as SEARCH_DEFAULT_DEPTH,
|
|
49
|
+
A_ as SEARCH_FUNCTION_CODES,
|
|
50
|
+
t_ as SEARCH_MAX_DEPTH,
|
|
51
|
+
A as Session,
|
|
52
|
+
C_ as TEXT_SEARCH_MAX_CONTEXT_LINES,
|
|
53
|
+
N_ as TEXT_SEARCH_MAX_FILES,
|
|
54
|
+
l_ as TEXT_SEARCH_MAX_FILE_BYTES,
|
|
55
|
+
D_ as TEXT_SEARCH_MAX_LINE_CHARS,
|
|
56
|
+
R_ as TRANSFER_FILE_SIZE_LIMIT_MB,
|
|
57
|
+
F_ as TRANSFER_FUNCTION_CODES,
|
|
55
58
|
l as ToolCode,
|
|
56
59
|
D as ToolError,
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
a_ as WORKSPACE_GRANT_ID,
|
|
61
|
+
f_ as WRITE_FUNCTION_CODES,
|
|
59
62
|
e as configuration,
|
|
60
63
|
T as configure,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
W as createDefaultSessionFileTransfer,
|
|
65
|
+
P as createIndexedDbStore,
|
|
66
|
+
H as createLocalFilesPlugin,
|
|
67
|
+
x as createMemoryStore,
|
|
68
|
+
y as getDownloadUrlAllowlist,
|
|
66
69
|
E as getRegisteredLocalFilesPluginCode,
|
|
67
70
|
r as getRegisteredLocalPythonPluginCode,
|
|
68
|
-
|
|
71
|
+
K as isDownloadUrlAllowed,
|
|
72
|
+
Y as registerHostBridge,
|
|
69
73
|
L as resolveLocalFilesPluginCode,
|
|
70
74
|
R as toToolError
|
|
71
75
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HostBridgeAdapter as f } from "../adapters/HostBridgeAdapter.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { getHostBridge as g, HOST_CHANNEL as l, parseHostMessage as y } from "./protocol.mjs";
|
|
3
3
|
function m(o) {
|
|
4
4
|
if (!o || typeof o != "object")
|
|
5
5
|
return;
|
|
@@ -1,27 +1,39 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const i = "glodon-workspace", o = "__glodonHostBridge", c = 2;
|
|
2
|
+
function f(t) {
|
|
3
3
|
let e = t;
|
|
4
4
|
if (typeof e == "string")
|
|
5
5
|
try {
|
|
6
6
|
e = JSON.parse(e);
|
|
7
|
-
} catch (
|
|
7
|
+
} catch (s) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
if (!e || typeof e != "object")
|
|
11
11
|
return;
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
12
|
+
const n = e;
|
|
13
|
+
if (n.channel === i)
|
|
14
|
+
return n;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function r(t) {
|
|
17
|
+
if (!t || typeof t != "object")
|
|
18
|
+
return;
|
|
19
|
+
const e = t;
|
|
20
|
+
if (!(typeof e.postMessage != "function" || typeof e.addEventListener != "function" || typeof e.removeEventListener != "function"))
|
|
21
|
+
return e;
|
|
22
|
+
}
|
|
23
|
+
function d(t) {
|
|
24
|
+
const e = globalThis;
|
|
25
|
+
t ? e[o] = t : delete e[o];
|
|
26
|
+
}
|
|
27
|
+
function g() {
|
|
17
28
|
var e;
|
|
18
|
-
const t = (
|
|
19
|
-
|
|
20
|
-
return t;
|
|
29
|
+
const t = r(globalThis[o]);
|
|
30
|
+
return t || r((e = globalThis.chrome) == null ? void 0 : e.webview);
|
|
21
31
|
}
|
|
22
32
|
export {
|
|
23
|
-
|
|
24
|
-
i as
|
|
25
|
-
c as
|
|
26
|
-
|
|
33
|
+
o as HOST_BRIDGE_GLOBAL,
|
|
34
|
+
i as HOST_CHANNEL,
|
|
35
|
+
c as SANDBOX_PROTOCOL,
|
|
36
|
+
g as getHostBridge,
|
|
37
|
+
f as parseHostMessage,
|
|
38
|
+
d as registerHostBridge
|
|
27
39
|
};
|
package/dist/es/package.json.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.
|
|
1
|
+
const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.11", t = "glodoncv", i = "aiot bot client js sdk", n = "module", g = !1, o = [
|
|
2
2
|
"aiot",
|
|
3
3
|
"bot",
|
|
4
4
|
"bot client",
|
|
@@ -68,7 +68,7 @@ const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.10", t = "glodoncv",
|
|
|
68
68
|
access: "public",
|
|
69
69
|
registry: "https://registry.npmjs.org/"
|
|
70
70
|
}, y = {
|
|
71
|
-
"@glodon-aiot/apis": "^3.26.0-alpha.
|
|
71
|
+
"@glodon-aiot/apis": "^3.26.0-alpha.11",
|
|
72
72
|
axios: "0.24.0",
|
|
73
73
|
buffer: "^6.0.3",
|
|
74
74
|
dayjs: "^1.11.13",
|