@glodon-aiot/bot-client-sdk 3.26.0-alpha.21 → 3.26.0-alpha.23
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 +130 -180
- package/dist/es/BotClient.mjs +136 -154
- package/dist/es/Config.mjs +88 -51
- package/dist/es/Session.mjs +23 -35
- package/dist/es/index.mjs +64 -66
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -185
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +137 -127
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
- package/dist/es/localFiles/constants.mjs +29 -24
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/errors.mjs +19 -21
- package/dist/es/localFiles/host/connectHostBridge.mjs +34 -37
- package/dist/es/localFiles/host/protocol.mjs +13 -27
- package/dist/es/localFiles/schemas.mjs +86 -40
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +87 -161
- package/dist/es/package.json.mjs +29 -38
- package/dist/lib/index.js +9 -373
- package/dist/src/Config.d.ts +7 -5
- package/dist/src/Session.d.ts +0 -6
- package/dist/src/index.d.ts +1 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +14 -30
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -22
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
- package/dist/src/localFiles/constants.d.ts +13 -3
- package/dist/src/localFiles/host/protocol.d.ts +16 -34
- package/dist/src/localFiles/index.d.ts +6 -11
- package/dist/src/localFiles/schemas.d.ts +5 -2
- package/dist/src/localFiles/types.d.ts +23 -16
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +1 -32
- 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 -261
- package/dist/es/builtinTools/overview.mjs +0 -77
- package/dist/es/builtinTools/paths.mjs +0 -69
- package/dist/es/builtinTools/platformSkills.mjs +0 -210
- package/dist/es/builtinTools/schemas.mjs +0 -216
- package/dist/es/builtinTools/tools.mjs +0 -494
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +0 -160
- package/dist/es/localFiles/host/sandboxClient.mjs +0 -420
- package/dist/es/localFiles/host/sandboxFrames.mjs +0 -21
- package/dist/es/localFiles/preview.mjs +0 -33
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +0 -246
- package/dist/es/sessionUpload.mjs +0 -49
- 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 -35
- 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 -16
- package/dist/src/builtinTools/platformSkills.d.ts +0 -67
- package/dist/src/builtinTools/schemas.d.ts +0 -3
- package/dist/src/builtinTools/tools.d.ts +0 -64
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +0 -24
- package/dist/src/localFiles/host/sandboxClient.d.ts +0 -81
- package/dist/src/localFiles/host/sandboxFrames.d.ts +0 -9
- package/dist/src/localFiles/preview.d.ts +0 -2
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +0 -63
- package/dist/src/sessionUpload.d.ts +0 -14
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
var A = Object.defineProperty;
|
|
2
|
-
var B = (n, t, e) => t in n ? A(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
-
var p = (n, t, e) => (B(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
-
var a = (n, t, e) => new Promise((s, r) => {
|
|
5
|
-
var i = (c) => {
|
|
6
|
-
try {
|
|
7
|
-
h(e.next(c));
|
|
8
|
-
} catch (w) {
|
|
9
|
-
r(w);
|
|
10
|
-
}
|
|
11
|
-
}, o = (c) => {
|
|
12
|
-
try {
|
|
13
|
-
h(e.throw(c));
|
|
14
|
-
} catch (w) {
|
|
15
|
-
r(w);
|
|
16
|
-
}
|
|
17
|
-
}, h = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(i, o);
|
|
18
|
-
h((e = e.apply(n, t)).next());
|
|
19
|
-
});
|
|
20
|
-
import { ToolError as l, ToolCode as f, toToolError as F, workspaceNotGranted as E } from "../errors.mjs";
|
|
21
|
-
import { mediaTypeOf as k, PREVIEW_TYPE_MESSAGE as R } from "../preview.mjs";
|
|
22
|
-
import { parentPath as d } from "../security/pathPolicy.mjs";
|
|
23
|
-
import { SensitiveFilePolicy as U } from "../security/sensitiveFiles.mjs";
|
|
24
|
-
const b = "路径必须在工作区内,不能包含 ..、盘符或空字符。";
|
|
25
|
-
function m() {
|
|
26
|
-
return new l(f.Forbidden, b, {
|
|
27
|
-
reason: "path_outside_workspace"
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function u(n, t) {
|
|
31
|
-
if (n == null || n === "") {
|
|
32
|
-
if (t)
|
|
33
|
-
return "";
|
|
34
|
-
throw new l(f.BadRequest, "缺少参数 path。");
|
|
35
|
-
}
|
|
36
|
-
if (typeof n != "string")
|
|
37
|
-
throw new l(f.BadRequest, "path 必须是字符串。");
|
|
38
|
-
if (n.includes("\0") || /%(2e|2f|5c|00)/i.test(n))
|
|
39
|
-
throw m();
|
|
40
|
-
const e = n.normalize("NFC").replace(/\\/g, "/").trim();
|
|
41
|
-
if (/^[a-zA-Z]:/.test(e))
|
|
42
|
-
throw m();
|
|
43
|
-
const s = [];
|
|
44
|
-
for (const i of e.split("/"))
|
|
45
|
-
if (!(i === "" || i === ".")) {
|
|
46
|
-
if (i === "..")
|
|
47
|
-
throw m();
|
|
48
|
-
s.push(i);
|
|
49
|
-
}
|
|
50
|
-
const r = s.join("/");
|
|
51
|
-
if (!r && !t)
|
|
52
|
-
throw new l(f.BadRequest, "path 不能指向工作区根目录。");
|
|
53
|
-
return r;
|
|
54
|
-
}
|
|
55
|
-
function g(n) {
|
|
56
|
-
return new l(f.NotImplemented, `当前工作区不能${n}。`);
|
|
57
|
-
}
|
|
58
|
-
function P(n, t, e) {
|
|
59
|
-
return {
|
|
60
|
-
name: e.name,
|
|
61
|
-
path: t,
|
|
62
|
-
kind: e.kind,
|
|
63
|
-
size: e.size,
|
|
64
|
-
lastModified: e.lastModified,
|
|
65
|
-
sensitive: e.kind === "file" && n.sensitive.isSensitive(t)
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
class C {
|
|
69
|
-
constructor(t) {
|
|
70
|
-
p(this, "previews", /* @__PURE__ */ new Map());
|
|
71
|
-
p(this, "previewByPath", /* @__PURE__ */ new Map());
|
|
72
|
-
this.host = t;
|
|
73
|
-
}
|
|
74
|
-
stat(t = "") {
|
|
75
|
-
return a(this, null, function* () {
|
|
76
|
-
const e = u(t, !0), s = yield this.run((r) => r.stat(e));
|
|
77
|
-
return P(this.host, e, s);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
list() {
|
|
81
|
-
return a(this, arguments, function* (t = "", e = {}) {
|
|
82
|
-
const s = u(t, !0);
|
|
83
|
-
return (yield this.run((i) => i.listEntries(s, e.signal))).map((i) => {
|
|
84
|
-
const o = s ? `${s}/${i.name}` : i.name;
|
|
85
|
-
return P(this.host, o, i);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* 给 `<img>`、`<video>`、`<audio>` 的地址。浏览器自己拉字节,调用方拿不到文件内容。
|
|
91
|
-
* 同一路径在大小和修改时间没变时返回同一个地址,并增加引用。用完调用 `releaseUrl`。
|
|
92
|
-
*/
|
|
93
|
-
url(t) {
|
|
94
|
-
return a(this, null, function* () {
|
|
95
|
-
var c, w;
|
|
96
|
-
const e = u(t, !1);
|
|
97
|
-
if (this.assertAccess(e, "read"), !k(e))
|
|
98
|
-
throw new l(f.BadRequest, R);
|
|
99
|
-
const s = yield this.stat(e);
|
|
100
|
-
if (s.kind !== "file")
|
|
101
|
-
throw new l(f.BadRequest, "目标是目录,不是文件。");
|
|
102
|
-
const r = `${(c = s.size) != null ? c : ""}:${(w = s.lastModified) != null ? w : ""}`, i = this.previewByPath.get(e);
|
|
103
|
-
if ((i == null ? void 0 : i.stamp) === r)
|
|
104
|
-
return i.refs += 1, i.url;
|
|
105
|
-
const o = yield this.openPreview(e), h = {
|
|
106
|
-
url: o.url,
|
|
107
|
-
path: e,
|
|
108
|
-
stamp: r,
|
|
109
|
-
refs: 1,
|
|
110
|
-
release: o.release
|
|
111
|
-
};
|
|
112
|
-
return this.previews.set(h.url, h), this.previewByPath.set(e, h), h.url;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/** 页面不再显示这个地址时调用。引用归零后,blob 地址会撤销,沙箱票据会作废。 */
|
|
116
|
-
releaseUrl(t) {
|
|
117
|
-
const e = this.previews.get(t);
|
|
118
|
-
e && (e.refs -= 1, !(e.refs > 0) && this.dropPreview(e));
|
|
119
|
-
}
|
|
120
|
-
/** 工作区断开时释放还没归还的地址。 */
|
|
121
|
-
releaseAllUrls() {
|
|
122
|
-
const t = [...this.previews.values()];
|
|
123
|
-
this.previews.clear(), this.previewByPath.clear(), t.forEach((e) => e.release());
|
|
124
|
-
}
|
|
125
|
-
read(t) {
|
|
126
|
-
return a(this, null, function* () {
|
|
127
|
-
const e = u(t, !1);
|
|
128
|
-
return this.assertAccess(e, "read"), this.run((s) => a(this, null, function* () {
|
|
129
|
-
if ((yield s.stat(e)).kind !== "file")
|
|
130
|
-
throw new l(f.BadRequest, "目标是目录,不是文件。");
|
|
131
|
-
return s.readFile(e);
|
|
132
|
-
}));
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
readText(t) {
|
|
136
|
-
return a(this, null, function* () {
|
|
137
|
-
return (yield this.read(t)).text();
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
write(r, i) {
|
|
141
|
-
return a(this, arguments, function* (t, e, s = {}) {
|
|
142
|
-
const o = u(t, !1);
|
|
143
|
-
this.assertAccess(o, "write"), yield this.run((h) => h.writeFile(o, e, {
|
|
144
|
-
createDirectories: s.createDirectories !== !1,
|
|
145
|
-
signal: s.signal
|
|
146
|
-
})), this.host.notifyFilesChanged([d(o)]);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
append(r, i) {
|
|
150
|
-
return a(this, arguments, function* (t, e, s = {}) {
|
|
151
|
-
const o = u(t, !1);
|
|
152
|
-
this.assertAccess(o, "write");
|
|
153
|
-
const h = typeof e == "string" ? new TextEncoder().encode(e) : e;
|
|
154
|
-
yield this.run((c) => a(this, null, function* () {
|
|
155
|
-
let w = new Uint8Array();
|
|
156
|
-
try {
|
|
157
|
-
if ((yield c.stat(o)).kind !== "file")
|
|
158
|
-
throw new l(f.BadRequest, "目标是目录,不是文件。");
|
|
159
|
-
w = new Uint8Array(yield (yield c.readFile(o)).arrayBuffer());
|
|
160
|
-
} catch (y) {
|
|
161
|
-
if (y instanceof l || F(y).code !== f.NotFound)
|
|
162
|
-
throw y;
|
|
163
|
-
}
|
|
164
|
-
const v = new Uint8Array(w.byteLength + h.byteLength);
|
|
165
|
-
v.set(w), v.set(h, w.byteLength), yield c.writeFile(o, v, {
|
|
166
|
-
createDirectories: !0,
|
|
167
|
-
signal: s.signal
|
|
168
|
-
});
|
|
169
|
-
})), this.host.notifyFilesChanged([d(o)]);
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
mkdir(t) {
|
|
173
|
-
return a(this, null, function* () {
|
|
174
|
-
const e = u(t, !0);
|
|
175
|
-
e && (yield this.run((s) => a(this, null, function* () {
|
|
176
|
-
if (!s.createDirectory)
|
|
177
|
-
throw g("创建目录");
|
|
178
|
-
yield s.createDirectory(e);
|
|
179
|
-
})), this.host.notifyFilesChanged([d(e)]));
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
remove(s) {
|
|
183
|
-
return a(this, arguments, function* (t, e = {}) {
|
|
184
|
-
const r = u(t, !1);
|
|
185
|
-
this.assertAccess(r, "write"), yield this.run((i) => a(this, null, function* () {
|
|
186
|
-
if (!i.remove)
|
|
187
|
-
throw g("删除");
|
|
188
|
-
yield i.remove(r, e);
|
|
189
|
-
})), this.host.notifyFilesChanged([d(r)]);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
move(t, e) {
|
|
193
|
-
return a(this, null, function* () {
|
|
194
|
-
const s = u(t, !1), r = u(e, !1);
|
|
195
|
-
this.assertAccess(s, "write"), this.assertAccess(r, "write"), yield this.run((i) => a(this, null, function* () {
|
|
196
|
-
if (!i.move)
|
|
197
|
-
throw g("移动");
|
|
198
|
-
yield i.move(s, r);
|
|
199
|
-
})), this.host.notifyFilesChanged([d(s), d(r)]);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
openPreview(t) {
|
|
203
|
-
return a(this, null, function* () {
|
|
204
|
-
return this.run((e) => a(this, null, function* () {
|
|
205
|
-
if (e.url)
|
|
206
|
-
return e.url(t);
|
|
207
|
-
const s = yield e.readFile(t), r = URL.createObjectURL(s);
|
|
208
|
-
return {
|
|
209
|
-
url: r,
|
|
210
|
-
release: () => URL.revokeObjectURL(r)
|
|
211
|
-
};
|
|
212
|
-
}));
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
dropPreview(t) {
|
|
216
|
-
t.release(), this.previews.delete(t.url), this.previewByPath.get(t.path) === t && this.previewByPath.delete(t.path);
|
|
217
|
-
}
|
|
218
|
-
assertAccess(t, e) {
|
|
219
|
-
const s = this.host.sensitive.match(t, e);
|
|
220
|
-
if (s)
|
|
221
|
-
throw new l(f.Forbidden, U.reasonOf(s), {
|
|
222
|
-
reason: "sensitive_file",
|
|
223
|
-
ruleId: s.id
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
run(t) {
|
|
227
|
-
return a(this, null, function* () {
|
|
228
|
-
var s;
|
|
229
|
-
const e = this.host.adapter;
|
|
230
|
-
if (!e)
|
|
231
|
-
throw E();
|
|
232
|
-
try {
|
|
233
|
-
return yield t(e);
|
|
234
|
-
} catch (r) {
|
|
235
|
-
if (r instanceof l)
|
|
236
|
-
throw r;
|
|
237
|
-
const i = F(r);
|
|
238
|
-
throw ((s = i.data) == null ? void 0 : s.reason) === "workspace_not_granted" && (yield this.host.handlePermissionLost()), i;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
export {
|
|
244
|
-
C as WorkspaceFiles,
|
|
245
|
-
u as normalizeFilePath
|
|
246
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
var l = (t, e, o) => new Promise((c, n) => {
|
|
2
|
-
var p = (i) => {
|
|
3
|
-
try {
|
|
4
|
-
s(o.next(i));
|
|
5
|
-
} catch (a) {
|
|
6
|
-
n(a);
|
|
7
|
-
}
|
|
8
|
-
}, r = (i) => {
|
|
9
|
-
try {
|
|
10
|
-
s(o.throw(i));
|
|
11
|
-
} catch (a) {
|
|
12
|
-
n(a);
|
|
13
|
-
}
|
|
14
|
-
}, s = (i) => i.done ? c(i.value) : Promise.resolve(i.value).then(p, r);
|
|
15
|
-
s((o = o.apply(t, e)).next());
|
|
16
|
-
});
|
|
17
|
-
import { v4 as u } from "uuid";
|
|
18
|
-
function $(t, e, o) {
|
|
19
|
-
return l(this, null, function* () {
|
|
20
|
-
var s;
|
|
21
|
-
if (!e)
|
|
22
|
-
throw new Error("session is not avalible. id is undefined");
|
|
23
|
-
const c = d(o.name), n = yield t.postUploadTicket({
|
|
24
|
-
files: [c],
|
|
25
|
-
isv: "minio",
|
|
26
|
-
knowledgeId: e,
|
|
27
|
-
type: 1
|
|
28
|
-
}), r = (yield t.uploadMinioFile(n.minio, o)) || ((s = n.minio.fileKeys) == null ? void 0 : s[0]);
|
|
29
|
-
return {
|
|
30
|
-
url: f(n.minio, r),
|
|
31
|
-
name: o.name || c,
|
|
32
|
-
size: o.size
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function d(t) {
|
|
37
|
-
const e = t.split(/[/\\]/).pop() || "", o = /\.([A-Za-z0-9]{1,16})$/.exec(e);
|
|
38
|
-
return o ? `${u()}.${o[1].toLowerCase()}` : u();
|
|
39
|
-
}
|
|
40
|
-
function f(t, e) {
|
|
41
|
-
var n;
|
|
42
|
-
const o = (n = t.endpoints) == null ? void 0 : n[0];
|
|
43
|
-
if (!o || !t.bucket || !e)
|
|
44
|
-
throw new Error("上传没有返回文件地址。");
|
|
45
|
-
return `${t.useSSL ? "https:" : typeof location != "undefined" && location.protocol ? location.protocol : "http:"}//${o}/${t.bucket}/${e}`;
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
$ as uploadSessionFile
|
|
49
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
|
|
2
|
-
import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
|
|
3
|
-
import { CommandRequest, CommandResult, CommandRunner } from '../command';
|
|
4
|
-
import { WorkerLike } from './PythonRunner';
|
|
5
|
-
export declare const NO_NODE_MESSAGE = "\u5F53\u524D\u73AF\u5883\u6CA1\u6709 Node\uFF0C\u8BF7\u6539\u7528 python3 \u6216 shell \u547D\u4EE4\u3002\n";
|
|
6
|
-
export interface BrowserCommandRunnerOptions {
|
|
7
|
-
adapter: WorkspaceFileAdapter;
|
|
8
|
-
sensitive: SensitiveFilePolicy;
|
|
9
|
-
/** just-bash 浏览器构建的地址,默认 DEFAULT_BASH_MODULE_URL。 */
|
|
10
|
-
moduleURL?: string;
|
|
11
|
-
/** Pyodide 目录,默认 DEFAULT_PYODIDE_INDEX_URL。 */
|
|
12
|
-
pyodideIndexURL?: string;
|
|
13
|
-
createWorker?: (source: string) => WorkerLike;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 纯网页里的命令执行器:just-bash 解释 shell,文件读写落到当前工作区。
|
|
17
|
-
* 每条命令新建一个 shell,只有文件和 cwd 跨命令保留。
|
|
18
|
-
*/
|
|
19
|
-
export declare class BrowserCommandRunner implements CommandRunner {
|
|
20
|
-
private readonly options;
|
|
21
|
-
private readonly python;
|
|
22
|
-
constructor(options: BrowserCommandRunnerOptions);
|
|
23
|
-
private load;
|
|
24
|
-
private create;
|
|
25
|
-
exec(request: CommandRequest): Promise<CommandResult>;
|
|
26
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
|
|
2
|
-
import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
|
|
3
|
-
export declare const NO_PIP_MESSAGE: string;
|
|
4
|
-
export declare const MAX_SYNC_FILE_BYTES: number;
|
|
5
|
-
export declare const MAX_SYNC_TOTAL_BYTES: number;
|
|
6
|
-
/** 把 shell 或工具传来的目录换成 Pyodide 里的工作区路径。 */
|
|
7
|
-
export declare function toMount(cwd: string): string;
|
|
8
|
-
/** Worker 的最小接口,测试里用 Node 的 worker_threads 实现。 */
|
|
9
|
-
export interface WorkerLike {
|
|
10
|
-
onmessage: ((event: {
|
|
11
|
-
data: unknown;
|
|
12
|
-
}) => void) | null;
|
|
13
|
-
onerror: ((event: unknown) => void) | null;
|
|
14
|
-
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
15
|
-
terminate(): void;
|
|
16
|
-
}
|
|
17
|
-
export interface PythonRunnerOptions {
|
|
18
|
-
adapter: WorkspaceFileAdapter;
|
|
19
|
-
sensitive: SensitiveFilePolicy;
|
|
20
|
-
/** Pyodide 目录,以 `/` 结尾,默认 DEFAULT_PYODIDE_INDEX_URL。 */
|
|
21
|
-
indexURL?: string;
|
|
22
|
-
createWorker?: (source: string) => WorkerLike;
|
|
23
|
-
}
|
|
24
|
-
export interface PythonRequest {
|
|
25
|
-
/** `python3` 后面的参数。 */
|
|
26
|
-
args: string[];
|
|
27
|
-
/** shell 里的目录。`.` 或 `/workspace` 表示工作区根。 */
|
|
28
|
-
cwd: string;
|
|
29
|
-
stdin?: Uint8Array;
|
|
30
|
-
signal?: AbortSignal;
|
|
31
|
-
}
|
|
32
|
-
export interface PythonResult {
|
|
33
|
-
exitCode: number;
|
|
34
|
-
stdout: string;
|
|
35
|
-
stderr: string;
|
|
36
|
-
}
|
|
37
|
-
type Invocation = {
|
|
38
|
-
mode: 'c' | 'm' | 'file';
|
|
39
|
-
target: string;
|
|
40
|
-
argv: string[];
|
|
41
|
-
stdin: Uint8Array;
|
|
42
|
-
};
|
|
43
|
-
/** 按 python3 命令行解析参数;不需要启动解释器的情况直接给出结果。 */
|
|
44
|
-
export declare function parsePythonArgs(args: string[], cwd: string, stdin: Uint8Array): Invocation | PythonResult;
|
|
45
|
-
/**
|
|
46
|
-
* 浏览器里的 python3:Pyodide 跑在专用 Worker 里,执行前把工作区文件快照同步进去,执行后把改动写回。
|
|
47
|
-
* 同一时间只跑一个请求;超时或取消时终止 Worker,下次重新创建。
|
|
48
|
-
*/
|
|
49
|
-
export declare class PythonRunner {
|
|
50
|
-
private readonly options;
|
|
51
|
-
private state?;
|
|
52
|
-
private queue;
|
|
53
|
-
private nextId;
|
|
54
|
-
constructor(options: PythonRunnerOptions);
|
|
55
|
-
private get indexURL();
|
|
56
|
-
private loadError;
|
|
57
|
-
private dispose;
|
|
58
|
-
private spawn;
|
|
59
|
-
run(request: PythonRequest): Promise<PythonResult>;
|
|
60
|
-
private runNow;
|
|
61
|
-
/** 执行前把整个工作区读进 Pyodide。 */
|
|
62
|
-
private collect;
|
|
63
|
-
private exists;
|
|
64
|
-
/** 把 Python 里的改动写回工作区,返回是否有写回失败。 */
|
|
65
|
-
private writeBack;
|
|
66
|
-
}
|
|
67
|
-
export {};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { BufferEncoding, CpOptions, FileContent, FsStat, IFileSystem, MkdirOptions, RmOptions } from 'just-bash/browser';
|
|
2
|
-
import { WorkspaceFileAdapter } from '../../localFiles/adapters/WorkspaceFileAdapter';
|
|
3
|
-
import { SensitiveFilePolicy } from '../../localFiles/security/sensitiveFiles';
|
|
4
|
-
type EncodingOption = {
|
|
5
|
-
encoding?: BufferEncoding | null;
|
|
6
|
-
} | BufferEncoding | undefined;
|
|
7
|
-
interface DirentEntry {
|
|
8
|
-
name: string;
|
|
9
|
-
isFile: boolean;
|
|
10
|
-
isDirectory: boolean;
|
|
11
|
-
isSymbolicLink: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 把工作区挂到 just-bash 的一个目录。root 为空表示整个工作区。
|
|
15
|
-
* 收到的路径相对挂载点,以 `/` 开头。
|
|
16
|
-
*/
|
|
17
|
-
export declare class WorkspaceBashFs implements IFileSystem {
|
|
18
|
-
private readonly adapter;
|
|
19
|
-
private readonly root;
|
|
20
|
-
private readonly sensitive;
|
|
21
|
-
constructor(adapter: WorkspaceFileAdapter, root: string, sensitive: SensitiveFilePolicy);
|
|
22
|
-
private relative;
|
|
23
|
-
private shown;
|
|
24
|
-
private isRoot;
|
|
25
|
-
private guard;
|
|
26
|
-
private mapError;
|
|
27
|
-
private entry;
|
|
28
|
-
private ensureRoot;
|
|
29
|
-
readFileBuffer(path: string): Promise<Uint8Array>;
|
|
30
|
-
readFile(path: string, options?: EncodingOption): Promise<string>;
|
|
31
|
-
writeFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
|
|
32
|
-
appendFile(path: string, content: FileContent, options?: EncodingOption): Promise<void>;
|
|
33
|
-
exists(path: string): Promise<boolean>;
|
|
34
|
-
stat(path: string): Promise<FsStat>;
|
|
35
|
-
lstat(path: string): Promise<FsStat>;
|
|
36
|
-
mkdir(path: string, options?: MkdirOptions): Promise<void>;
|
|
37
|
-
readdirWithFileTypes(path: string): Promise<DirentEntry[]>;
|
|
38
|
-
readdir(path: string): Promise<string[]>;
|
|
39
|
-
rm(path: string, options?: RmOptions): Promise<void>;
|
|
40
|
-
cp(src: string, dest: string, options?: CpOptions): Promise<void>;
|
|
41
|
-
mv(src: string, dest: string): Promise<void>;
|
|
42
|
-
resolvePath(base: string, path: string): string;
|
|
43
|
-
getAllPaths(): string[];
|
|
44
|
-
chmod(path: string): Promise<void>;
|
|
45
|
-
symlink(_target: string, linkPath: string): Promise<void>;
|
|
46
|
-
link(_existingPath: string, newPath: string): Promise<void>;
|
|
47
|
-
readlink(path: string): Promise<string>;
|
|
48
|
-
realpath(path: string): Promise<string>;
|
|
49
|
-
utimes(path: string): Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** 公司 OBS 上的前端依赖目录,按 `<包名>/<版本>/` 存放。 */
|
|
2
|
-
export declare const CDN_LIBS_ROOT = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/";
|
|
3
|
-
/** 必须与 package.json 里 just-bash 的版本一致;升级时先上传新版本目录。 */
|
|
4
|
-
export declare const JUST_BASH_VERSION = "3.6.0";
|
|
5
|
-
export declare const DEFAULT_BASH_MODULE_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/just-bash/3.6.0/just-bash.mjs";
|
|
6
|
-
/** 必须与 package.json 里 pyodide 的版本一致;升级时先上传新版本目录。 */
|
|
7
|
-
export declare const PYODIDE_VERSION = "314.0.7";
|
|
8
|
-
export declare const DEFAULT_PYODIDE_INDEX_URL = "https://cv-cdn.obs.cn-north-4.myhuaweicloud.com/glodon/libs/pyodide/314.0.7/";
|
|
9
|
-
/**
|
|
10
|
-
* 浏览器里可以 import 的第三方包,构建脚本按它们的依赖闭包上传 wheel 并改写 pyodide-lock.json。
|
|
11
|
-
* 调整后需要重新构建并上传新的 Pyodide 目录。
|
|
12
|
-
*/
|
|
13
|
-
export declare const PYODIDE_PACKAGES: string[];
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/** Emscripten 的 ErrnoError 不是 Error,只带 errno 和 code。 */
|
|
2
|
-
declare function describe(error: any): any;
|
|
3
|
-
declare function networkDenied(url: any): TypeError;
|
|
4
|
-
/** 只放行 indexURL 下的资源(Pyodide 自身和白名单 wheel),其余请求一律拒绝。 */
|
|
5
|
-
declare function guardNetwork(indexURL: any): void;
|
|
6
|
-
declare function collector(): {
|
|
7
|
-
write(bytes: any): void;
|
|
8
|
-
finish(): string;
|
|
9
|
-
};
|
|
10
|
-
declare function init({ indexURL, packages, runner }: {
|
|
11
|
-
indexURL: any;
|
|
12
|
-
packages: any;
|
|
13
|
-
runner: any;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
declare function dirname(path: any): any;
|
|
16
|
-
/** 主脚本、`-c` 代码,以及主脚本目录和 cwd 下的 .py 文件里出现的 import。 */
|
|
17
|
-
declare function sourcesToScan({ files, cwd, mode, target }: {
|
|
18
|
-
files: any;
|
|
19
|
-
cwd: any;
|
|
20
|
-
mode: any;
|
|
21
|
-
target: any;
|
|
22
|
-
}): any[];
|
|
23
|
-
declare function loadPackages(sources: any, stderr: any): Promise<void>;
|
|
24
|
-
declare function lstat(path: any): any;
|
|
25
|
-
declare function removeTree(path: any): void;
|
|
26
|
-
declare function walk(path: any, files: any, dirs: any): void;
|
|
27
|
-
declare function sameBytes(a: any, b: any): boolean;
|
|
28
|
-
declare function execute(message: any): Promise<{
|
|
29
|
-
exitCode: any;
|
|
30
|
-
stdout: string;
|
|
31
|
-
stderr: string;
|
|
32
|
-
written: {
|
|
33
|
-
path: any;
|
|
34
|
-
data: any;
|
|
35
|
-
}[];
|
|
36
|
-
removed: any[];
|
|
37
|
-
createdDirs: any[];
|
|
38
|
-
removedDirs: string[];
|
|
39
|
-
}>;
|
|
40
|
-
declare const ROOTS: string[];
|
|
41
|
-
declare const OUTPUT_LIMIT: number;
|
|
42
|
-
declare let pyodide: null;
|
|
43
|
-
declare let runPython: null;
|
|
44
|
-
declare let sink: null;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/** 在工作区里执行命令。由端侧宿主沙箱、浏览器运行时或测试注入实现。 */
|
|
2
|
-
export interface CommandRequest {
|
|
3
|
-
/** shell 命令。与 argv 二选一。 */
|
|
4
|
-
command?: string;
|
|
5
|
-
/** 直接执行的程序和参数,不经过 shell。 */
|
|
6
|
-
argv?: string[];
|
|
7
|
-
/** 工作区相对目录。`.` 表示工作区根。 */
|
|
8
|
-
cwd: string;
|
|
9
|
-
timeoutMs?: number;
|
|
10
|
-
signal?: AbortSignal;
|
|
11
|
-
/** 命令还在跑时收到的一块 stdout 或 stderr。 */
|
|
12
|
-
onOutput?: (stream: 'stdout' | 'stderr', text: string) => void;
|
|
13
|
-
/** 只在 run_skill_script 中设置。沙箱据此只读挂载该版本目录。 */
|
|
14
|
-
skill?: {
|
|
15
|
-
applicationId: string;
|
|
16
|
-
skillId: string;
|
|
17
|
-
version: number;
|
|
18
|
-
name: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export interface CommandResult {
|
|
22
|
-
exitCode: number;
|
|
23
|
-
stdout: string;
|
|
24
|
-
stderr: string;
|
|
25
|
-
/** 命令结束后的工作区相对目录。shell 用来保留上次停留的目录。 */
|
|
26
|
-
cwd?: string;
|
|
27
|
-
}
|
|
28
|
-
export interface CommandRunner {
|
|
29
|
-
exec(request: CommandRequest): Promise<CommandResult>;
|
|
30
|
-
}
|
|
31
|
-
/** stdout、stderr 各自返回给模型的字符上限。 */
|
|
32
|
-
export declare const MAX_COMMAND_OUTPUT_CHARS = 16000;
|
|
33
|
-
export declare const OUTPUT_TRUNCATED_NOTE = "\n\u2026\u8F93\u51FA\u5DF2\u622A\u65AD";
|
|
34
|
-
export declare function limitOutput(text: string): string;
|
|
35
|
-
export declare function withOutputLimit(runner: CommandRunner): CommandRunner;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const BUILTIN_FUNCTION_CODES: readonly ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "run_skill_script"];
|
|
2
|
-
export type BuiltinFunctionCode = (typeof BUILTIN_FUNCTION_CODES)[number];
|
|
3
|
-
/** 单次 read_file 按原文返回的上限。超出后结构化文本改为概览。 */
|
|
4
|
-
export declare const MAX_READ_BYTES = 81920;
|
|
5
|
-
/** write_file 单次覆盖写入的 UTF-8 字节上限。 */
|
|
6
|
-
export declare const MAX_WRITE_BYTES = 81920;
|
|
7
|
-
export declare const MAX_COMMAND_CHARS = 20000;
|
|
8
|
-
/** shell 一开始停在工作区根目录。 */
|
|
9
|
-
export declare const SHELL_CWD = ".";
|
|
10
|
-
/**
|
|
11
|
-
* 浏览器 shell 把工作区挂在这里。命令里的工作区绝对路径会改写到这个前缀,
|
|
12
|
-
* 输出再换回以 / 开头的工作区路径。
|
|
13
|
-
*/
|
|
14
|
-
export declare const WORKSPACE_MOUNT = "/workspace";
|
|
15
|
-
/** 技能目录在工作区根下。 */
|
|
16
|
-
export declare const SKILLS_DIR = "skills";
|
|
17
|
-
export declare const RUNNABLE_EXTENSIONS: readonly [".py", ".sh", ".js"];
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LocalWorkspace } from '../localFiles/workspace/LocalWorkspace';
|
|
2
|
-
import { ClientPluginCallback, ToolContext } from '../localFiles/types';
|
|
3
|
-
import { BuiltinFunctionCode } from './constants';
|
|
4
|
-
export type BuiltinHandler = (params: unknown, callback: ClientPluginCallback, context?: Partial<ToolContext>) => void;
|
|
5
|
-
export type BuiltinPluginTable = Record<string, Record<BuiltinFunctionCode, BuiltinHandler>>;
|
|
6
|
-
export interface CreateBuiltinToolsPluginOptions {
|
|
7
|
-
pluginCode: string;
|
|
8
|
-
workspace: LocalWorkspace;
|
|
9
|
-
}
|
|
10
|
-
/** 组装内置工具插件:`{ [pluginCode]: { shell, read_file, ... } }`。 */
|
|
11
|
-
export declare function createBuiltinToolsPlugin({ pluginCode, workspace, }: CreateBuiltinToolsPluginOptions): BuiltinPluginTable;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare function isStructuredPath(path: string): boolean;
|
|
2
|
-
export declare function structureOverview(path: string, text: string): string;
|
|
3
|
-
export declare function extensionOf(path: string): string;
|
|
4
|
-
export declare function isImagePath(path: string): boolean;
|
|
5
|
-
export declare function isPdf(path: string, bytes?: Uint8Array): boolean;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const SYNTHETIC_DIRS: readonly ["input", "output", "uploads", "tmp"];
|
|
2
|
-
export declare const SYNTHETIC_DIR_MESSAGE = "\u4E0D\u8981\u4F7F\u7528 input\u3001output\u3001uploads\u3001tmp\uFF0C\u4E5F\u4E0D\u8981\u65B0\u5EFA\u8FD9\u4E9B\u76EE\u5F55\u3002\u8BF7\u628A\u6587\u4EF6\u76F4\u63A5\u653E\u5728\u5DE5\u4F5C\u533A\u5DF2\u6709\u4F4D\u7F6E\u6216\u6839\u76EE\u5F55\u3002";
|
|
3
|
-
export declare function mentionsSkillDir(text: string): boolean;
|
|
4
|
-
export declare function mentionsSyntheticDir(text: string): boolean;
|
|
5
|
-
export declare function isSyntheticCwd(cwd: string): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* 把工作区内绝对路径转成相对工作区根的路径。`/` 表示工作区根。
|
|
8
|
-
* 拒绝相对路径、盘符和 .. 。
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveWorkspacePath(input: string): string;
|
|
11
|
-
export declare function resolveFilePath(input: string): string;
|
|
12
|
-
export declare function resolveRunPath(input: string): string;
|
|
13
|
-
export declare function toVirtualPath(relative: string): string;
|
|
14
|
-
/** shell 回传的目录必须仍在工作区内。`.` 表示工作区根。 */
|
|
15
|
-
export declare function isSafeCwd(cwd: string): boolean;
|
|
16
|
-
export declare function skillRelative(skillName: string, relativeName: string): string;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
export interface ArrangeSkillInput {
|
|
2
|
-
skillId?: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
displayName?: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
version?: number;
|
|
7
|
-
}
|
|
8
|
-
export interface SkillRecord {
|
|
9
|
-
skillId: string;
|
|
10
|
-
name: string;
|
|
11
|
-
version: number;
|
|
12
|
-
}
|
|
13
|
-
export interface SkillSandbox {
|
|
14
|
-
ready: boolean;
|
|
15
|
-
unavailableMessage(): string;
|
|
16
|
-
skillStatus(applicationId: string, signal?: AbortSignal): Promise<unknown>;
|
|
17
|
-
skillRead(applicationId: string, skillId: string, version: number, path: string, signal?: AbortSignal): Promise<Uint8Array>;
|
|
18
|
-
installSkill(fields: {
|
|
19
|
-
applicationId: string;
|
|
20
|
-
skillId: string;
|
|
21
|
-
version: number;
|
|
22
|
-
name: string;
|
|
23
|
-
}, bytes: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
24
|
-
skillPrune(applicationId: string, keep: Array<{
|
|
25
|
-
skillId: string;
|
|
26
|
-
version: number;
|
|
27
|
-
}>, busy: Array<{
|
|
28
|
-
skillId: string;
|
|
29
|
-
version: number;
|
|
30
|
-
}>, signal?: AbortSignal): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
/** 缺省、空数组和非数组都当成没有技能。 */
|
|
33
|
-
export declare function listedSkills(arrange?: {
|
|
34
|
-
skills?: ArrangeSkillInput[];
|
|
35
|
-
} | null): ArrangeSkillInput[];
|
|
36
|
-
export declare class PlatformSkillSync {
|
|
37
|
-
private readonly options;
|
|
38
|
-
private readonly inflight;
|
|
39
|
-
private readonly busy;
|
|
40
|
-
constructor(options: {
|
|
41
|
-
applicationId: () => string;
|
|
42
|
-
getToken: () => string;
|
|
43
|
-
getSkills: () => ArrangeSkillInput[];
|
|
44
|
-
apiRoot: () => string;
|
|
45
|
-
getSandbox: () => SkillSandbox | undefined;
|
|
46
|
-
fetch?: typeof fetch;
|
|
47
|
-
});
|
|
48
|
-
/** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
|
|
49
|
-
sync(): Promise<void | undefined>;
|
|
50
|
-
read(name: string, relative: string, signal?: AbortSignal): Promise<Uint8Array<ArrayBufferLike>>;
|
|
51
|
-
target(name: string, signal?: AbortSignal): Promise<{
|
|
52
|
-
applicationId: string;
|
|
53
|
-
skillId: string;
|
|
54
|
-
version: number;
|
|
55
|
-
name: string;
|
|
56
|
-
}>;
|
|
57
|
-
track(skillId: string, version: number): () => void;
|
|
58
|
-
private requireSandbox;
|
|
59
|
-
private prepare;
|
|
60
|
-
private bound;
|
|
61
|
-
private reconcile;
|
|
62
|
-
private ensure;
|
|
63
|
-
private installIfNeeded;
|
|
64
|
-
private alreadyInstalled;
|
|
65
|
-
private prune;
|
|
66
|
-
private waitReady;
|
|
67
|
-
}
|