@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.9
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 +20 -37
- package/dist/es/AgentSession.mjs +32 -33
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +71 -63
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +136 -128
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +102 -178
- package/dist/es/localFiles/host/connectHostBridge.mjs +38 -39
- package/dist/es/localFiles/host/protocol.mjs +1 -1
- package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +43 -42
- package/dist/src/Session.d.ts +4 -0
- package/dist/src/builtinTools/command.d.ts +2 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +14 -20
- package/dist/src/localFiles/host/protocol.d.ts +16 -22
- package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/package.json +2 -2
|
@@ -1,233 +1,157 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var m = (i, t) => {
|
|
5
|
-
if (t = Symbol[i])
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var m = (r, t) => {
|
|
3
|
+
if (t = Symbol[r])
|
|
6
4
|
return t;
|
|
7
|
-
throw Error("Symbol." +
|
|
5
|
+
throw Error("Symbol." + r + " is not defined");
|
|
8
6
|
};
|
|
9
|
-
var u = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (var e of f(t))
|
|
14
|
-
T.call(t, e) && u(i, e, t[e]);
|
|
15
|
-
return i;
|
|
16
|
-
};
|
|
17
|
-
var p = (i, t, e) => (u(i, typeof t != "symbol" ? t + "" : t, e), e);
|
|
18
|
-
var l = (i, t, e) => new Promise((r, o) => {
|
|
19
|
-
var s = (n) => {
|
|
7
|
+
var u = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
8
|
+
var l = (r, t, e) => (u(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
9
|
+
var n = (r, t, e) => new Promise((s, a) => {
|
|
10
|
+
var o = (i) => {
|
|
20
11
|
try {
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
|
|
12
|
+
y(e.next(i));
|
|
13
|
+
} catch (c) {
|
|
14
|
+
a(c);
|
|
24
15
|
}
|
|
25
|
-
},
|
|
16
|
+
}, d = (i) => {
|
|
26
17
|
try {
|
|
27
|
-
|
|
28
|
-
} catch (
|
|
29
|
-
|
|
18
|
+
y(e.throw(i));
|
|
19
|
+
} catch (c) {
|
|
20
|
+
a(c);
|
|
30
21
|
}
|
|
31
|
-
},
|
|
32
|
-
|
|
22
|
+
}, y = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, d);
|
|
23
|
+
y((e = e.apply(r, t)).next());
|
|
33
24
|
});
|
|
34
|
-
var
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import { SANDBOX_PROTOCOL as
|
|
38
|
-
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
for (let r = 0; r < i.length; r += 32768)
|
|
42
|
-
t += String.fromCharCode(...i.subarray(r, r + 32768));
|
|
43
|
-
return btoa(t);
|
|
44
|
-
}
|
|
45
|
-
function k(i) {
|
|
46
|
-
const t = atob(i), e = new Uint8Array(t.length);
|
|
47
|
-
for (let r = 0; r < t.length; r++)
|
|
48
|
-
e[r] = t.charCodeAt(r);
|
|
49
|
-
return e;
|
|
50
|
-
}
|
|
51
|
-
function v(i, t) {
|
|
52
|
-
const e = i && typeof i == "object" ? i : {}, r = e.kind === "directory" ? "directory" : "file", o = {
|
|
25
|
+
var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (o) => new Promise((d, y, i) => (o = a.call(r, o), i = o.done, Promise.resolve(o.value).then((c) => d({ value: c, done: i }), y)))), e("next"), e("return"), t);
|
|
26
|
+
import { throwIfAborted as g } from "../errors.mjs";
|
|
27
|
+
import { SandboxClient as v } from "../host/sandboxClient.mjs";
|
|
28
|
+
import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
|
|
29
|
+
import { domError as w, toChunks as M } from "./WorkspaceFileAdapter.mjs";
|
|
30
|
+
function x(r, t) {
|
|
31
|
+
const e = r && typeof r == "object" ? r : {}, s = e.kind === "directory" ? "directory" : "file", a = {
|
|
53
32
|
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
54
|
-
kind:
|
|
33
|
+
kind: s
|
|
55
34
|
};
|
|
56
|
-
return
|
|
35
|
+
return s === "file" && typeof e.size == "number" && (a.size = e.size), typeof e.lastModified == "number" && (a.lastModified = e.lastModified), a;
|
|
57
36
|
}
|
|
58
|
-
class
|
|
59
|
-
constructor(t, e = "") {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
p(this, "seq", 0);
|
|
67
|
-
p(this, "pending", /* @__PURE__ */ new Map());
|
|
68
|
-
this.view = t, this.displayName = e;
|
|
37
|
+
class S {
|
|
38
|
+
constructor(t, e = "", s = new v()) {
|
|
39
|
+
l(this, "displayName");
|
|
40
|
+
l(this, "capabilities", /* @__PURE__ */ new Set());
|
|
41
|
+
l(this, "sandboxVersion");
|
|
42
|
+
l(this, "sandboxProtocol");
|
|
43
|
+
l(this, "sandbox");
|
|
44
|
+
this.displayName = e, this.sandbox = s;
|
|
69
45
|
}
|
|
70
46
|
setCapabilities(t, e = {}) {
|
|
71
|
-
const
|
|
72
|
-
this.capabilities = new Set(
|
|
47
|
+
const s = Array.isArray(t) ? t.filter((a) => typeof a == "string") : [];
|
|
48
|
+
this.capabilities = new Set(s), this.sandboxVersion = typeof e.version == "string" ? e.version : void 0;
|
|
49
|
+
}
|
|
50
|
+
applySandbox(t) {
|
|
51
|
+
this.sandboxProtocol = t == null ? void 0 : t.protocol, this.sandbox.apply(t);
|
|
73
52
|
}
|
|
74
|
-
/**
|
|
53
|
+
/** 沙箱已就绪且协议为 2 时,命令走直连。 */
|
|
75
54
|
get canExec() {
|
|
76
|
-
return this.
|
|
55
|
+
return this.sandbox.ready;
|
|
77
56
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
throw h("NotAllowedError", `宿主未声明 ${t}。`);
|
|
57
|
+
get protocolMismatch() {
|
|
58
|
+
return this.sandboxProtocol !== void 0 && this.sandboxProtocol !== A;
|
|
81
59
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (e) {
|
|
85
|
-
if (clearTimeout(e.timer), this.pending.delete(t.id), t.ok === !1) {
|
|
86
|
-
e.reject(h(t.name || "NotAllowedError", t.message || t.name || "NotAllowedError"));
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
e.resolve(t);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
call(t, e, r, o = x) {
|
|
93
|
-
A(r);
|
|
94
|
-
const s = `host-${++this.seq}`;
|
|
95
|
-
return new Promise((a, c) => {
|
|
96
|
-
const n = setTimeout(() => {
|
|
97
|
-
this.pending.delete(s), c(h("AbortError"));
|
|
98
|
-
}, o), d = () => {
|
|
99
|
-
clearTimeout(n), this.pending.delete(s), c(h("AbortError"));
|
|
100
|
-
};
|
|
101
|
-
r == null || r.addEventListener("abort", d, {
|
|
102
|
-
once: !0
|
|
103
|
-
}), this.pending.set(s, {
|
|
104
|
-
resolve: (E) => {
|
|
105
|
-
r == null || r.removeEventListener("abort", d), a(E);
|
|
106
|
-
},
|
|
107
|
-
reject: c,
|
|
108
|
-
timer: n
|
|
109
|
-
}), this.view.postMessage(b({
|
|
110
|
-
channel: M,
|
|
111
|
-
id: s,
|
|
112
|
-
op: t
|
|
113
|
-
}, e));
|
|
114
|
-
});
|
|
60
|
+
unavailableMessage() {
|
|
61
|
+
return this.sandbox.unavailableMessage();
|
|
115
62
|
}
|
|
116
63
|
stat(t) {
|
|
117
|
-
return
|
|
118
|
-
const e = yield this.
|
|
119
|
-
|
|
120
|
-
});
|
|
121
|
-
return v(e.entry, t.split("/").pop() || this.displayName);
|
|
64
|
+
return n(this, null, function* () {
|
|
65
|
+
const e = yield this.sandbox.stat(t);
|
|
66
|
+
return x(e.entry, t.split("/").pop() || this.displayName);
|
|
122
67
|
});
|
|
123
68
|
}
|
|
124
69
|
listEntries(t, e) {
|
|
125
|
-
return
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
}, e);
|
|
129
|
-
return (Array.isArray(r.entries) ? r.entries : []).map((s) => v(s, ""));
|
|
70
|
+
return n(this, null, function* () {
|
|
71
|
+
const s = yield this.sandbox.list(t, e);
|
|
72
|
+
return (Array.isArray(s.entries) ? s.entries : []).map((o) => x(o, ""));
|
|
130
73
|
});
|
|
131
74
|
}
|
|
132
|
-
readFile(t) {
|
|
133
|
-
return
|
|
134
|
-
var
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
}), r = k((o = e.contentBase64) != null ? o : "");
|
|
138
|
-
return new Blob([r]);
|
|
75
|
+
readFile(t, e) {
|
|
76
|
+
return n(this, null, function* () {
|
|
77
|
+
var a;
|
|
78
|
+
const s = yield this.sandbox.read(t, (a = e == null ? void 0 : e.offset) != null ? a : 0, e == null ? void 0 : e.maxBytes);
|
|
79
|
+
return new Blob([s]);
|
|
139
80
|
});
|
|
140
81
|
}
|
|
141
82
|
createDirectory(t) {
|
|
142
|
-
return
|
|
143
|
-
|
|
144
|
-
path: t
|
|
145
|
-
});
|
|
83
|
+
return n(this, null, function* () {
|
|
84
|
+
yield this.sandbox.mkdir(t);
|
|
146
85
|
});
|
|
147
86
|
}
|
|
148
|
-
remove(
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
path: t,
|
|
152
|
-
recursive: e.recursive === !0
|
|
153
|
-
});
|
|
87
|
+
remove(s) {
|
|
88
|
+
return n(this, arguments, function* (t, e = {}) {
|
|
89
|
+
yield this.sandbox.remove(t, e.recursive === !0);
|
|
154
90
|
});
|
|
155
91
|
}
|
|
156
92
|
move(t, e) {
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
from: t,
|
|
160
|
-
to: e
|
|
161
|
-
});
|
|
93
|
+
return n(this, null, function* () {
|
|
94
|
+
yield this.sandbox.move(t, e);
|
|
162
95
|
});
|
|
163
96
|
}
|
|
164
97
|
exec(t) {
|
|
165
|
-
return
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const e = (o = t.timeoutMs) != null ? o : x, r = yield this.call("exec", {
|
|
169
|
-
protocol: C,
|
|
98
|
+
return n(this, null, function* () {
|
|
99
|
+
const e = yield this.sandbox.exec({
|
|
100
|
+
op: "exec",
|
|
170
101
|
cwd: t.cwd,
|
|
171
102
|
command: t.command,
|
|
172
103
|
argv: t.argv,
|
|
173
|
-
timeoutMs:
|
|
174
|
-
}, t.signal,
|
|
175
|
-
if (
|
|
176
|
-
throw
|
|
177
|
-
return
|
|
178
|
-
exitCode: typeof r.exitCode == "number" ? r.exitCode : 1,
|
|
179
|
-
stdout: (s = r.stdout) != null ? s : "",
|
|
180
|
-
stderr: (a = r.stderr) != null ? a : "",
|
|
181
|
-
cwd: typeof r.cwd == "string" ? r.cwd : void 0
|
|
182
|
-
};
|
|
104
|
+
timeoutMs: t.timeoutMs
|
|
105
|
+
}, t.signal, t.onOutput);
|
|
106
|
+
if (e.timedOut)
|
|
107
|
+
throw w("AbortError", "命令运行超时。");
|
|
108
|
+
return e;
|
|
183
109
|
});
|
|
184
110
|
}
|
|
185
|
-
runPython(t, e,
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
111
|
+
runPython(t, e, s, a) {
|
|
112
|
+
return n(this, null, function* () {
|
|
113
|
+
return this.sandbox.exec({
|
|
114
|
+
op: "run_python",
|
|
189
115
|
path: t,
|
|
190
116
|
args: e,
|
|
191
|
-
timeoutMs:
|
|
192
|
-
},
|
|
193
|
-
return {
|
|
194
|
-
exitCode: typeof s.exitCode == "number" ? s.exitCode : 1,
|
|
195
|
-
timedOut: s.timedOut === !0,
|
|
196
|
-
stdout: (a = s.stdout) != null ? a : "",
|
|
197
|
-
stderr: (c = s.stderr) != null ? c : ""
|
|
198
|
-
};
|
|
117
|
+
timeoutMs: s
|
|
118
|
+
}, a);
|
|
199
119
|
});
|
|
200
120
|
}
|
|
201
|
-
writeFile(
|
|
202
|
-
return
|
|
203
|
-
|
|
121
|
+
writeFile(a, o) {
|
|
122
|
+
return n(this, arguments, function* (t, e, s = {}) {
|
|
123
|
+
if (typeof e == "string") {
|
|
124
|
+
yield this.sandbox.write(t, new TextEncoder().encode(e), s.createDirectories === !0, s.signal);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (e instanceof Uint8Array) {
|
|
128
|
+
yield this.sandbox.write(t, e, s.createDirectories === !0, s.signal);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const d = [];
|
|
204
132
|
try {
|
|
205
|
-
for (var
|
|
206
|
-
const
|
|
207
|
-
|
|
133
|
+
for (var N = f(M(e)), z, L, F; z = !(L = yield N.next()).done; z = !1) {
|
|
134
|
+
const b = L.value;
|
|
135
|
+
g(s.signal), d.push(b);
|
|
208
136
|
}
|
|
209
|
-
} catch (
|
|
210
|
-
|
|
137
|
+
} catch (L) {
|
|
138
|
+
F = [L];
|
|
211
139
|
} finally {
|
|
212
140
|
try {
|
|
213
|
-
|
|
141
|
+
z && (L = N.return) && (yield L.call(N));
|
|
214
142
|
} finally {
|
|
215
|
-
if (
|
|
216
|
-
throw
|
|
143
|
+
if (F)
|
|
144
|
+
throw F[0];
|
|
217
145
|
}
|
|
218
146
|
}
|
|
219
|
-
const
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}), yield this.
|
|
224
|
-
path: t,
|
|
225
|
-
contentBase64: B(n),
|
|
226
|
-
createDirectories: r.createDirectories === !0
|
|
227
|
-
}, r.signal);
|
|
147
|
+
const y = d.reduce((b, h) => b + h.byteLength, 0), i = new Uint8Array(y);
|
|
148
|
+
let c = 0;
|
|
149
|
+
d.forEach((b) => {
|
|
150
|
+
i.set(b, c), c += b.byteLength;
|
|
151
|
+
}), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
|
|
228
152
|
});
|
|
229
153
|
}
|
|
230
154
|
}
|
|
231
155
|
export {
|
|
232
|
-
|
|
156
|
+
S as HostBridgeAdapter
|
|
233
157
|
};
|
|
@@ -1,54 +1,53 @@
|
|
|
1
1
|
import { HostBridgeAdapter as f } from "../adapters/HostBridgeAdapter.mjs";
|
|
2
|
-
import { getHostWebView as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
2
|
+
import { getHostWebView as g, HOST_CHANNEL as l, parseHostMessage as y } from "./protocol.mjs";
|
|
3
|
+
function m(o) {
|
|
4
|
+
if (!o || typeof o != "object")
|
|
5
|
+
return;
|
|
6
|
+
const e = o;
|
|
7
|
+
return {
|
|
8
|
+
state: e.state,
|
|
9
|
+
url: typeof e.url == "string" ? e.url : void 0,
|
|
10
|
+
token: typeof e.token == "string" ? e.token : void 0,
|
|
11
|
+
protocol: typeof e.protocol == "number" ? e.protocol : void 0,
|
|
12
|
+
exitCode: typeof e.exitCode == "number" ? e.exitCode : void 0,
|
|
13
|
+
detail: typeof e.detail == "string" ? e.detail : void 0,
|
|
14
|
+
message: typeof e.message == "string" ? e.message : void 0,
|
|
15
|
+
reason: typeof e.reason == "string" ? e.reason : void 0
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
let s;
|
|
19
|
+
function v(o) {
|
|
20
|
+
s == null || s(), s = void 0;
|
|
21
|
+
const e = g();
|
|
22
|
+
if (!e)
|
|
8
23
|
return () => {
|
|
9
24
|
};
|
|
10
|
-
const i = new f(
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
if (
|
|
14
|
-
const
|
|
15
|
-
i.setCapabilities(
|
|
16
|
-
version:
|
|
17
|
-
|
|
18
|
-
}), a ? (i.displayName = r || "工程目录", (s.status !== "granted" || s.displayName !== i.displayName) && s.attachAdapter(i, i.displayName)) : s.status === "granted" && s.clear();
|
|
25
|
+
const i = new f(e), d = (p) => {
|
|
26
|
+
const t = y(p.data);
|
|
27
|
+
if (t) {
|
|
28
|
+
if (t.type === "workspace") {
|
|
29
|
+
const n = t.granted === !0, r = typeof t.displayName == "string" ? t.displayName : "";
|
|
30
|
+
i.setCapabilities(t.capabilities, {
|
|
31
|
+
version: t.sandboxVersion
|
|
32
|
+
}), i.applySandbox(m(t.sandbox)), n ? (i.displayName = r || "工程目录", (o.status !== "granted" || o.displayName !== i.displayName) && o.attachAdapter(i, i.displayName)) : o.status === "granted" && o.clear();
|
|
19
33
|
return;
|
|
20
34
|
}
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
|
|
35
|
+
if (t.type === "fs-changed") {
|
|
36
|
+
const n = Array.isArray(t.paths) ? t.paths.filter((r) => typeof r == "string") : [];
|
|
37
|
+
o.notifyFilesChanged(n);
|
|
24
38
|
return;
|
|
25
39
|
}
|
|
26
|
-
typeof e.id == "string" && i.settle({
|
|
27
|
-
channel: p,
|
|
28
|
-
id: e.id,
|
|
29
|
-
ok: e.ok !== !1,
|
|
30
|
-
name: typeof e.name == "string" ? e.name : void 0,
|
|
31
|
-
entries: e.entries,
|
|
32
|
-
entry: e.entry,
|
|
33
|
-
contentBase64: typeof e.contentBase64 == "string" ? e.contentBase64 : void 0,
|
|
34
|
-
exitCode: typeof e.exitCode == "number" ? e.exitCode : void 0,
|
|
35
|
-
timedOut: e.timedOut === !0,
|
|
36
|
-
stdout: typeof e.stdout == "string" ? e.stdout : void 0,
|
|
37
|
-
stderr: typeof e.stderr == "string" ? e.stderr : void 0,
|
|
38
|
-
cwd: typeof e.cwd == "string" ? e.cwd : void 0,
|
|
39
|
-
message: typeof e.message == "string" ? e.message : void 0
|
|
40
|
-
});
|
|
41
40
|
}
|
|
42
41
|
};
|
|
43
|
-
|
|
44
|
-
channel:
|
|
42
|
+
e.addEventListener("message", d), e.postMessage({
|
|
43
|
+
channel: l,
|
|
45
44
|
type: "hello"
|
|
46
45
|
});
|
|
47
|
-
const
|
|
48
|
-
|
|
46
|
+
const a = () => {
|
|
47
|
+
e.removeEventListener("message", d), s === a && (s = void 0);
|
|
49
48
|
};
|
|
50
|
-
return
|
|
49
|
+
return s = a, a;
|
|
51
50
|
}
|
|
52
51
|
export {
|
|
53
|
-
|
|
52
|
+
v as connectHostBridge
|
|
54
53
|
};
|