@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,494 +0,0 @@
|
|
|
1
|
-
var l = (t, e, n) => new Promise((r, s) => {
|
|
2
|
-
var a = (i) => {
|
|
3
|
-
try {
|
|
4
|
-
c(n.next(i));
|
|
5
|
-
} catch (f) {
|
|
6
|
-
s(f);
|
|
7
|
-
}
|
|
8
|
-
}, o = (i) => {
|
|
9
|
-
try {
|
|
10
|
-
c(n.throw(i));
|
|
11
|
-
} catch (f) {
|
|
12
|
-
s(f);
|
|
13
|
-
}
|
|
14
|
-
}, c = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(a, o);
|
|
15
|
-
c((n = n.apply(t, e)).next());
|
|
16
|
-
});
|
|
17
|
-
import { throwIfAborted as g, ToolError as d, ToolCode as u } from "../localFiles/errors.mjs";
|
|
18
|
-
import { looksBinary as x, utf8ByteLength as M, readBytes as U } from "../localFiles/tools/runtime.mjs";
|
|
19
|
-
import { MAX_READ_BYTES as R, MAX_WRITE_BYTES as T, SHELL_CWD as I, RUNNABLE_EXTENSIONS as z } from "./constants.mjs";
|
|
20
|
-
import { isImagePath as L, isPdf as v, isStructuredPath as W, structureOverview as X, extensionOf as Y } from "./overview.mjs";
|
|
21
|
-
import { resolveFilePath as m, resolveRunPath as H, mentionsSkillDir as b, mentionsSyntheticDir as C, SYNTHETIC_DIR_MESSAGE as G, isSafeCwd as K, skillRelative as N, toVirtualPath as $ } from "./paths.mjs";
|
|
22
|
-
function D(t) {
|
|
23
|
-
return !!t && typeof t == "object" && t.name === "NotFoundError";
|
|
24
|
-
}
|
|
25
|
-
function y(t) {
|
|
26
|
-
try {
|
|
27
|
-
return new TextDecoder("utf-8", {
|
|
28
|
-
fatal: !0
|
|
29
|
-
}).decode(t);
|
|
30
|
-
} catch (e) {
|
|
31
|
-
throw new d(u.BadRequest, "文件不是 UTF-8 文本。");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function S(t) {
|
|
35
|
-
return t === "" ? [] : (t.endsWith(`
|
|
36
|
-
`) ? t.slice(0, -1) : t).split(`
|
|
37
|
-
`);
|
|
38
|
-
}
|
|
39
|
-
function V(t, e, n) {
|
|
40
|
-
if (e !== void 0 && n !== void 0 && n < e)
|
|
41
|
-
throw new d(u.BadRequest, "end_line 不能小于 start_line。");
|
|
42
|
-
const r = S(t), s = Math.max((e != null ? e : 1) - 1, 0), a = n != null ? n : r.length;
|
|
43
|
-
return r.slice(s, a).join(`
|
|
44
|
-
`);
|
|
45
|
-
}
|
|
46
|
-
function F(t) {
|
|
47
|
-
if (M(t) <= R)
|
|
48
|
-
return {
|
|
49
|
-
text: t,
|
|
50
|
-
truncated: !1
|
|
51
|
-
};
|
|
52
|
-
const e = new TextEncoder().encode(t);
|
|
53
|
-
let n = R;
|
|
54
|
-
for (; n > 0 && (e[n] & 192) === 128; )
|
|
55
|
-
n -= 1;
|
|
56
|
-
const r = new TextDecoder().decode(e.slice(0, n)), s = r.lastIndexOf(`
|
|
57
|
-
`);
|
|
58
|
-
return {
|
|
59
|
-
text: s > 0 ? r.slice(0, s) : r,
|
|
60
|
-
truncated: !0
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function p(t, e) {
|
|
64
|
-
return l(this, null, function* () {
|
|
65
|
-
const n = yield t.stat(e);
|
|
66
|
-
if (n.kind !== "file")
|
|
67
|
-
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
68
|
-
const r = yield U(yield t.readFile(e));
|
|
69
|
-
return {
|
|
70
|
-
entry: n,
|
|
71
|
-
bytes: r
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
function q(t, e, n) {
|
|
76
|
-
const r = typeof n == "number" ? `${n} 字节,` : "";
|
|
77
|
-
return `${t},${r}路径 ${$(e)}。不返回正文。`;
|
|
78
|
-
}
|
|
79
|
-
function _(t) {
|
|
80
|
-
const e = Y(t);
|
|
81
|
-
if (!z.includes(e))
|
|
82
|
-
throw new d(u.BadRequest, "只能执行 .py、.sh 或 .js 文件。");
|
|
83
|
-
return e === ".py" ? "python3" : e === ".js" ? "node" : "sh";
|
|
84
|
-
}
|
|
85
|
-
function O(t) {
|
|
86
|
-
if (!t.runner)
|
|
87
|
-
throw new d(u.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
88
|
-
return t.runner;
|
|
89
|
-
}
|
|
90
|
-
function B(t, e, n, r) {
|
|
91
|
-
return l(this, null, function* () {
|
|
92
|
-
yield t.writeFile(e, n, {
|
|
93
|
-
createDirectories: !0,
|
|
94
|
-
signal: r
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function dt(t, e) {
|
|
99
|
-
return l(this, null, function* () {
|
|
100
|
-
const n = m(t.path);
|
|
101
|
-
if (g(e.signal), L(n)) {
|
|
102
|
-
const i = yield e.adapter.stat(n);
|
|
103
|
-
if (i.kind !== "file")
|
|
104
|
-
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
105
|
-
return {
|
|
106
|
-
data: {
|
|
107
|
-
content: q("图片", n, i.size),
|
|
108
|
-
truncated: !1
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const {
|
|
113
|
-
entry: r,
|
|
114
|
-
bytes: s
|
|
115
|
-
} = yield p(e.adapter, n);
|
|
116
|
-
if (v(n, s))
|
|
117
|
-
return {
|
|
118
|
-
data: {
|
|
119
|
-
content: q("PDF", n, r.size),
|
|
120
|
-
truncated: !1
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
if (x(s))
|
|
124
|
-
throw new d(u.BadRequest, "文件不是文本,无法读取正文。");
|
|
125
|
-
const a = y(s);
|
|
126
|
-
if (t.start_line !== void 0 || t.end_line !== void 0) {
|
|
127
|
-
const i = V(a, t.start_line, t.end_line), f = F(i);
|
|
128
|
-
return {
|
|
129
|
-
data: {
|
|
130
|
-
content: f.text,
|
|
131
|
-
truncated: f.truncated
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
if (s.byteLength > R && W(n))
|
|
136
|
-
return {
|
|
137
|
-
data: {
|
|
138
|
-
content: X(n, a),
|
|
139
|
-
truncated: !0
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const c = F(a);
|
|
143
|
-
return {
|
|
144
|
-
data: {
|
|
145
|
-
content: c.text,
|
|
146
|
-
truncated: c.truncated
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function ut(t, e) {
|
|
152
|
-
return l(this, null, function* () {
|
|
153
|
-
const n = m(t.path);
|
|
154
|
-
if (M(t.content) > T)
|
|
155
|
-
throw new d(u.TooLarge, `content 按 UTF-8 计超过 ${T} 字节。请缩短后写入,或改用 append_file、edit_file。`);
|
|
156
|
-
return g(e.signal), yield B(e.adapter, n, t.content, e.signal), {
|
|
157
|
-
data: {}
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
function ft(t, e) {
|
|
162
|
-
return l(this, null, function* () {
|
|
163
|
-
const n = m(t.path);
|
|
164
|
-
g(e.signal);
|
|
165
|
-
let r = "";
|
|
166
|
-
try {
|
|
167
|
-
const {
|
|
168
|
-
bytes: s
|
|
169
|
-
} = yield p(e.adapter, n);
|
|
170
|
-
if (x(s))
|
|
171
|
-
throw new d(u.BadRequest, "文件不是文本,无法追加。");
|
|
172
|
-
r = y(s);
|
|
173
|
-
} catch (s) {
|
|
174
|
-
if (!D(s))
|
|
175
|
-
throw s;
|
|
176
|
-
}
|
|
177
|
-
return yield B(e.adapter, n, r + t.content, e.signal), {
|
|
178
|
-
data: {}
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function wt(t, e) {
|
|
183
|
-
return l(this, null, function* () {
|
|
184
|
-
const n = m(t.path);
|
|
185
|
-
g(e.signal);
|
|
186
|
-
const {
|
|
187
|
-
bytes: r
|
|
188
|
-
} = yield p(e.adapter, n);
|
|
189
|
-
if (x(r))
|
|
190
|
-
throw new d(u.BadRequest, "文件不是文本,无法修改。");
|
|
191
|
-
const s = y(r), a = s.indexOf(t.old_text);
|
|
192
|
-
if (a < 0) {
|
|
193
|
-
const c = J(s, t.old_text);
|
|
194
|
-
throw new d(u.BadRequest, `找不到与 old_text 完全相同的内容。最接近的原文从第 ${c.line} 行开始,可复制后重试:
|
|
195
|
-
${c.excerpt}`, {
|
|
196
|
-
line: c.line,
|
|
197
|
-
excerpt: c.excerpt
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
const o = s.slice(0, a) + t.new_text + s.slice(a + t.old_text.length);
|
|
201
|
-
return yield B(e.adapter, n, o, e.signal), {
|
|
202
|
-
data: {}
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
function J(t, e) {
|
|
207
|
-
var i;
|
|
208
|
-
const n = S(t);
|
|
209
|
-
if (n.length === 0)
|
|
210
|
-
return {
|
|
211
|
-
line: 1,
|
|
212
|
-
excerpt: ""
|
|
213
|
-
};
|
|
214
|
-
const r = e.split(`
|
|
215
|
-
`), s = ((i = r[0]) != null ? i : "").slice(0, 200);
|
|
216
|
-
let a = 0, o = -1;
|
|
217
|
-
for (let f = 0; f < n.length; f += 1) {
|
|
218
|
-
const w = Q(n[f], s);
|
|
219
|
-
w > o && (o = w, a = f);
|
|
220
|
-
}
|
|
221
|
-
const c = Math.min(Math.max(r.length, 1), 8);
|
|
222
|
-
return {
|
|
223
|
-
line: a + 1,
|
|
224
|
-
excerpt: n.slice(a, a + c).join(`
|
|
225
|
-
`)
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
function Q(t, e) {
|
|
229
|
-
if (!e)
|
|
230
|
-
return 0;
|
|
231
|
-
const n = t.toLowerCase(), r = e.toLowerCase();
|
|
232
|
-
let s = 0, a = 0;
|
|
233
|
-
for (const o of n)
|
|
234
|
-
a < r.length && o === r[a] && (s += 1, a += 1);
|
|
235
|
-
return s;
|
|
236
|
-
}
|
|
237
|
-
function Z(t) {
|
|
238
|
-
let e = "";
|
|
239
|
-
for (let n = 0; n < t.length; n += 1) {
|
|
240
|
-
const r = t[n];
|
|
241
|
-
if (r === "\\") {
|
|
242
|
-
const s = t[n + 1];
|
|
243
|
-
if (s === void 0) {
|
|
244
|
-
e += "\\\\";
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
n += 1, e += "+?|{}()".includes(s) ? `\\${s}` : s === "n" ? "\\n" : s === "t" ? "\\t" : k(s);
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
if ("+?|{}()".includes(r)) {
|
|
251
|
-
e += `\\${r}`;
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
if (r === "[") {
|
|
255
|
-
const s = t.indexOf("]", n + 1);
|
|
256
|
-
if (s < 0) {
|
|
257
|
-
e += "\\[";
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
e += t.slice(n, s + 1), n = s;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
e += ".^$*".includes(r) ? r : k(r);
|
|
264
|
-
}
|
|
265
|
-
return new RegExp(e);
|
|
266
|
-
}
|
|
267
|
-
function k(t) {
|
|
268
|
-
return /[\\^$.*+?()[\]{}|]/.test(t) ? `\\${t}` : t;
|
|
269
|
-
}
|
|
270
|
-
function tt(t) {
|
|
271
|
-
try {
|
|
272
|
-
return Z(t);
|
|
273
|
-
} catch (e) {
|
|
274
|
-
throw new d(u.BadRequest, "pattern 不是合法的 grep 基本正则。");
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
function E(t, e, n, r, s) {
|
|
278
|
-
return l(this, null, function* () {
|
|
279
|
-
if (r > 16)
|
|
280
|
-
return;
|
|
281
|
-
g(n);
|
|
282
|
-
const a = yield t.stat(e);
|
|
283
|
-
if (yield s(e, a.kind), a.kind !== "directory")
|
|
284
|
-
return;
|
|
285
|
-
const o = yield t.listEntries(e, n);
|
|
286
|
-
o.sort((c, i) => c.name < i.name ? -1 : c.name > i.name ? 1 : 0);
|
|
287
|
-
for (const c of o) {
|
|
288
|
-
const i = e ? `${e}/${c.name}` : c.name;
|
|
289
|
-
yield E(t, i, n, r + 1, s);
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
function ht(t, e) {
|
|
294
|
-
return l(this, null, function* () {
|
|
295
|
-
const n = m(t.path), r = tt(t.pattern), s = [];
|
|
296
|
-
yield E(e.adapter, n, e.signal, 0, (o, c) => l(this, null, function* () {
|
|
297
|
-
if (c !== "file" || s.length >= 200)
|
|
298
|
-
return;
|
|
299
|
-
const {
|
|
300
|
-
bytes: i
|
|
301
|
-
} = yield p(e.adapter, o);
|
|
302
|
-
if (x(i) || L(o) || v(o, i))
|
|
303
|
-
return;
|
|
304
|
-
let f;
|
|
305
|
-
try {
|
|
306
|
-
f = y(i);
|
|
307
|
-
} catch (h) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
const w = S(f);
|
|
311
|
-
for (let h = 0; h < w.length && s.length < 200; h += 1) {
|
|
312
|
-
if (!r.test(w[h]))
|
|
313
|
-
continue;
|
|
314
|
-
const A = w[h].length > 500 ? `${w[h].slice(0, 500)}…` : w[h];
|
|
315
|
-
s.push(`${$(o)}:${h + 1}:${A}`);
|
|
316
|
-
}
|
|
317
|
-
}));
|
|
318
|
-
const a = s.join(`
|
|
319
|
-
`);
|
|
320
|
-
return {
|
|
321
|
-
data: {
|
|
322
|
-
matches: s.length >= 200 ? `${a}
|
|
323
|
-
(匹配过多,已截断)` : a
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
function et(t, e) {
|
|
329
|
-
let n = "^";
|
|
330
|
-
for (let r = 0; r < t.length; r += 1) {
|
|
331
|
-
const s = t[r];
|
|
332
|
-
if (s === "*")
|
|
333
|
-
n += ".*";
|
|
334
|
-
else if (s === "?")
|
|
335
|
-
n += ".";
|
|
336
|
-
else if (s === "[") {
|
|
337
|
-
const a = t.indexOf("]", r + 1);
|
|
338
|
-
a < 0 ? n += "\\[" : (n += t.slice(r, a + 1), r = a);
|
|
339
|
-
} else
|
|
340
|
-
n += k(s);
|
|
341
|
-
}
|
|
342
|
-
return new RegExp(`${n}$`).test(e);
|
|
343
|
-
}
|
|
344
|
-
function mt(t, e) {
|
|
345
|
-
return l(this, null, function* () {
|
|
346
|
-
const n = m(t.path), r = [];
|
|
347
|
-
yield E(e.adapter, n, e.signal, 0, (a) => l(this, null, function* () {
|
|
348
|
-
var c;
|
|
349
|
-
if (r.length >= 500)
|
|
350
|
-
return;
|
|
351
|
-
const o = (c = a.split("/").pop()) != null ? c : a;
|
|
352
|
-
et(t.name, o) && r.push($(a));
|
|
353
|
-
})), r.sort();
|
|
354
|
-
const s = r.join(`
|
|
355
|
-
`);
|
|
356
|
-
return {
|
|
357
|
-
data: {
|
|
358
|
-
files: r.length >= 500 ? `${s}
|
|
359
|
-
(结果过多,已截断)` : s
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
function nt(t, e, n) {
|
|
365
|
-
return l(this, null, function* () {
|
|
366
|
-
const r = O(n);
|
|
367
|
-
yield p(n.adapter, t);
|
|
368
|
-
const s = yield r.exec({
|
|
369
|
-
argv: [_(t), t, ...e],
|
|
370
|
-
cwd: I,
|
|
371
|
-
timeoutMs: n.timeoutMs,
|
|
372
|
-
signal: n.signal
|
|
373
|
-
});
|
|
374
|
-
return {
|
|
375
|
-
data: {
|
|
376
|
-
exitCode: s.exitCode,
|
|
377
|
-
stdout: s.stdout,
|
|
378
|
-
stderr: s.stderr
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
function gt(t, e) {
|
|
384
|
-
return l(this, null, function* () {
|
|
385
|
-
const n = H(t.path);
|
|
386
|
-
return _(n), nt(n, [], e);
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
function xt(t, e) {
|
|
390
|
-
return l(this, null, function* () {
|
|
391
|
-
if (b(t.command) || b(e.shellCwd.cwd))
|
|
392
|
-
throw new d(u.Forbidden, "技能文件只能通过技能工具访问。");
|
|
393
|
-
if (C(t.command) || C(e.shellCwd.cwd))
|
|
394
|
-
return {
|
|
395
|
-
data: {
|
|
396
|
-
exitCode: 1,
|
|
397
|
-
stdout: "",
|
|
398
|
-
stderr: `${G}
|
|
399
|
-
`
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
const r = yield O(e).exec({
|
|
403
|
-
command: t.command,
|
|
404
|
-
cwd: e.shellCwd.cwd,
|
|
405
|
-
timeoutMs: e.timeoutMs,
|
|
406
|
-
signal: e.signal
|
|
407
|
-
});
|
|
408
|
-
return r.cwd && K(r.cwd) && (e.shellCwd.cwd = r.cwd), {
|
|
409
|
-
data: {
|
|
410
|
-
exitCode: r.exitCode,
|
|
411
|
-
stdout: r.stdout,
|
|
412
|
-
stderr: r.stderr
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
function P(t) {
|
|
418
|
-
if (!t.skills)
|
|
419
|
-
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
420
|
-
return t.skills;
|
|
421
|
-
}
|
|
422
|
-
function j(t, e, n) {
|
|
423
|
-
return l(this, null, function* () {
|
|
424
|
-
N(t, e);
|
|
425
|
-
const r = yield P(n).read(t, e, n.signal);
|
|
426
|
-
if (x(r))
|
|
427
|
-
throw new d(u.BadRequest, "技能资源不是文本。");
|
|
428
|
-
return y(r);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
function rt(t) {
|
|
432
|
-
if (!t.skillRunner)
|
|
433
|
-
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
434
|
-
return t.skillRunner;
|
|
435
|
-
}
|
|
436
|
-
function yt(t, e) {
|
|
437
|
-
return l(this, null, function* () {
|
|
438
|
-
return {
|
|
439
|
-
data: {
|
|
440
|
-
content: yield j(t.skill_name, "SKILL.md", e)
|
|
441
|
-
}
|
|
442
|
-
};
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
function pt(t, e) {
|
|
446
|
-
return l(this, null, function* () {
|
|
447
|
-
return {
|
|
448
|
-
data: {
|
|
449
|
-
content: yield j(t.skill_name, t.resource_name, e)
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
function _t(t, e) {
|
|
455
|
-
return l(this, null, function* () {
|
|
456
|
-
var o;
|
|
457
|
-
const n = P(e);
|
|
458
|
-
N(t.skill_name, t.script_name), _(t.script_name);
|
|
459
|
-
const r = rt(e), s = yield n.target(t.skill_name, e.signal), a = n.track(s.skillId, s.version);
|
|
460
|
-
try {
|
|
461
|
-
const c = yield r.exec({
|
|
462
|
-
argv: [_(t.script_name), t.script_name, ...(o = t.args) != null ? o : []],
|
|
463
|
-
cwd: I,
|
|
464
|
-
timeoutMs: e.timeoutMs,
|
|
465
|
-
signal: e.signal,
|
|
466
|
-
skill: s
|
|
467
|
-
});
|
|
468
|
-
return {
|
|
469
|
-
data: {
|
|
470
|
-
exitCode: c.exitCode,
|
|
471
|
-
stdout: c.stdout,
|
|
472
|
-
stderr: c.stderr
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
} catch (c) {
|
|
476
|
-
throw D(c) ? new d(u.NotFound, "技能脚本不存在。") : c;
|
|
477
|
-
} finally {
|
|
478
|
-
a();
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
export {
|
|
483
|
-
ft as appendFile,
|
|
484
|
-
wt as editFile,
|
|
485
|
-
mt as find,
|
|
486
|
-
ht as grep,
|
|
487
|
-
yt as loadSkill,
|
|
488
|
-
dt as readFile,
|
|
489
|
-
pt as readSkillResource,
|
|
490
|
-
gt as runFile,
|
|
491
|
-
_t as runSkillScript,
|
|
492
|
-
xt as shell,
|
|
493
|
-
ut as writeFile
|
|
494
|
-
};
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
var M = Object.defineProperty;
|
|
2
|
-
var y = (n, r) => {
|
|
3
|
-
if (r = Symbol[n])
|
|
4
|
-
return r;
|
|
5
|
-
throw Error("Symbol." + n + " is not defined");
|
|
6
|
-
};
|
|
7
|
-
var g = (n, r, e) => r in n ? M(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
|
|
8
|
-
var m = (n, r, e) => (g(n, typeof r != "symbol" ? r + "" : r, e), e);
|
|
9
|
-
var f = (n, r, e) => new Promise((t, o) => {
|
|
10
|
-
var i = (s) => {
|
|
11
|
-
try {
|
|
12
|
-
c(e.next(s));
|
|
13
|
-
} catch (d) {
|
|
14
|
-
o(d);
|
|
15
|
-
}
|
|
16
|
-
}, l = (s) => {
|
|
17
|
-
try {
|
|
18
|
-
c(e.throw(s));
|
|
19
|
-
} catch (d) {
|
|
20
|
-
o(d);
|
|
21
|
-
}
|
|
22
|
-
}, c = (s) => s.done ? t(s.value) : Promise.resolve(s.value).then(i, l);
|
|
23
|
-
c((e = e.apply(n, r)).next());
|
|
24
|
-
});
|
|
25
|
-
var u = (n, r, e) => (r = n[y("asyncIterator")]) ? r.call(n) : (n = n[y("iterator")](), r = {}, e = (t, o) => (o = n[t]) && (r[t] = (i) => new Promise((l, c, s) => (i = o.call(n, i), s = i.done, Promise.resolve(i.value).then((d) => l({ value: d, done: s }), c)))), e("next"), e("return"), r);
|
|
26
|
-
import { domError as a, toChunks as D } from "./WorkspaceFileAdapter.mjs";
|
|
27
|
-
import { throwIfAborted as w } from "../errors.mjs";
|
|
28
|
-
import { splitPath as h } from "../security/pathPolicy.mjs";
|
|
29
|
-
function k() {
|
|
30
|
-
return {
|
|
31
|
-
kind: "directory",
|
|
32
|
-
children: /* @__PURE__ */ new Map()
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
class A {
|
|
36
|
-
constructor(r, e) {
|
|
37
|
-
m(this, "root", k());
|
|
38
|
-
var t;
|
|
39
|
-
this.displayName = e;
|
|
40
|
-
for (const o of r) {
|
|
41
|
-
const i = E(o, e);
|
|
42
|
-
i && this.writeNode(i, o.blob, (t = o.lastModified) != null ? t : Date.now());
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
writeNode(r, e, t) {
|
|
46
|
-
const o = r.split("/").filter(Boolean), i = o.pop();
|
|
47
|
-
if (!i)
|
|
48
|
-
return;
|
|
49
|
-
this.resolveDirectory(o, !0).children.set(i, {
|
|
50
|
-
kind: "file",
|
|
51
|
-
blob: e,
|
|
52
|
-
lastModified: t
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
resolveDirectory(r, e = !1) {
|
|
56
|
-
let t = this.root;
|
|
57
|
-
for (const o of r) {
|
|
58
|
-
let i = t.children.get(o);
|
|
59
|
-
if (!i) {
|
|
60
|
-
if (!e)
|
|
61
|
-
throw a("NotFoundError");
|
|
62
|
-
i = k(), t.children.set(o, i);
|
|
63
|
-
}
|
|
64
|
-
if (i.kind !== "directory")
|
|
65
|
-
throw a("TypeMismatchError");
|
|
66
|
-
t = i;
|
|
67
|
-
}
|
|
68
|
-
return t;
|
|
69
|
-
}
|
|
70
|
-
resolveNode(r) {
|
|
71
|
-
const e = h(r), t = e.pop();
|
|
72
|
-
if (t === void 0)
|
|
73
|
-
return this.root;
|
|
74
|
-
const o = this.resolveDirectory(e).children.get(t);
|
|
75
|
-
if (!o)
|
|
76
|
-
throw a("NotFoundError");
|
|
77
|
-
return o;
|
|
78
|
-
}
|
|
79
|
-
stat(r) {
|
|
80
|
-
return f(this, null, function* () {
|
|
81
|
-
var o;
|
|
82
|
-
const e = this.resolveNode(r), t = (o = h(r).pop()) != null ? o : this.displayName;
|
|
83
|
-
return e.kind === "directory" ? {
|
|
84
|
-
name: t,
|
|
85
|
-
kind: "directory"
|
|
86
|
-
} : {
|
|
87
|
-
name: t,
|
|
88
|
-
kind: "file",
|
|
89
|
-
size: e.blob.size,
|
|
90
|
-
lastModified: e.lastModified
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
listEntries(r, e) {
|
|
95
|
-
return f(this, null, function* () {
|
|
96
|
-
w(e);
|
|
97
|
-
const t = this.resolveDirectory(h(r));
|
|
98
|
-
return Array.from(t.children.entries()).map(([o, i]) => i.kind === "directory" ? {
|
|
99
|
-
name: o,
|
|
100
|
-
kind: "directory"
|
|
101
|
-
} : {
|
|
102
|
-
name: o,
|
|
103
|
-
kind: "file",
|
|
104
|
-
size: i.blob.size,
|
|
105
|
-
lastModified: i.lastModified
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
readFile(r) {
|
|
110
|
-
return f(this, null, function* () {
|
|
111
|
-
const e = this.resolveNode(r);
|
|
112
|
-
if (e.kind !== "file")
|
|
113
|
-
throw a("TypeMismatchError");
|
|
114
|
-
return e.blob;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
/** 只更新内存中的快照,不会写回用户磁盘。 */
|
|
118
|
-
writeFile(o, i) {
|
|
119
|
-
return f(this, arguments, function* (r, e, t = {}) {
|
|
120
|
-
const l = h(r), c = l.pop();
|
|
121
|
-
if (!c)
|
|
122
|
-
throw a("TypeMismatchError");
|
|
123
|
-
const s = this.resolveDirectory(l, t.createDirectories), d = s.children.get(c);
|
|
124
|
-
if ((d == null ? void 0 : d.kind) === "directory")
|
|
125
|
-
throw a("TypeMismatchError");
|
|
126
|
-
const p = [];
|
|
127
|
-
try {
|
|
128
|
-
for (var B = u(D(e)), C, I, R; C = !(I = yield B.next()).done; C = !1) {
|
|
129
|
-
const v = I.value;
|
|
130
|
-
w(t.signal), p.push(v);
|
|
131
|
-
}
|
|
132
|
-
} catch (I) {
|
|
133
|
-
R = [I];
|
|
134
|
-
} finally {
|
|
135
|
-
try {
|
|
136
|
-
C && (I = B.return) && (yield I.call(B));
|
|
137
|
-
} finally {
|
|
138
|
-
if (R)
|
|
139
|
-
throw R[0];
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const b = new Blob(p);
|
|
143
|
-
s.children.set(c, {
|
|
144
|
-
kind: "file",
|
|
145
|
-
blob: b,
|
|
146
|
-
lastModified: Date.now()
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function E(n, r) {
|
|
152
|
-
const e = (n.webkitRelativePath || n.name).replace(/\\/g, "/").replace(/^\/+/, "");
|
|
153
|
-
if (!e)
|
|
154
|
-
return "";
|
|
155
|
-
const t = `${r}/`;
|
|
156
|
-
return e.startsWith(t) ? e.slice(t.length) : e;
|
|
157
|
-
}
|
|
158
|
-
export {
|
|
159
|
-
A as FileSnapshotAdapter
|
|
160
|
-
};
|