@glodon-aiot/bot-client-sdk 3.26.0-alpha.8 → 3.26.0
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 +284 -254
- package/dist/es/AgentSession.mjs +267 -197
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +55 -88
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +338 -284
- package/dist/es/api/index.mjs +31 -30
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +17 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +266 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +70 -0
- package/dist/es/builtinTools/platformSkills.mjs +248 -0
- package/dist/es/builtinTools/schemas.mjs +261 -0
- package/dist/es/builtinTools/tools.mjs +595 -0
- package/dist/es/index.mjs +66 -64
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
- package/dist/es/localFiles/constants.mjs +24 -28
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/errors.mjs +44 -35
- package/dist/es/localFiles/host/connectHostBridge.mjs +43 -35
- package/dist/es/localFiles/host/protocol.mjs +27 -13
- package/dist/es/localFiles/host/sandboxClient.mjs +494 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +40 -86
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +176 -90
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +234 -0
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +207 -0
- package/dist/es/localMcp/registry.mjs +43 -0
- package/dist/es/package.json.mjs +49 -60
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/es/utils.mjs +24 -11
- package/dist/lib/index.js +382 -10
- package/dist/src/AgentSession.d.ts +13 -0
- package/dist/src/BotClient.d.ts +13 -1
- package/dist/src/Config.d.ts +7 -8
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +2 -0
- package/dist/src/Session.d.ts +19 -2
- package/dist/src/api/index.d.ts +2 -2
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +35 -0
- package/dist/src/builtinTools/constants.d.ts +25 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +16 -0
- package/dist/src/builtinTools/platformSkills.d.ts +92 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +73 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
- package/dist/src/localFiles/constants.d.ts +5 -13
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +34 -16
- package/dist/src/localFiles/host/sandboxClient.d.ts +112 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +11 -6
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +2 -5
- package/dist/src/localFiles/types.d.ts +16 -23
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +15 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +34 -0
- package/dist/src/localMcp/registry.d.ts +27 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +13 -24
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
var l = (e, t, 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(e, t)).next());
|
|
16
|
+
});
|
|
17
|
+
import { throwIfAborted as y, ToolError as d, ToolCode as u } from "../localFiles/errors.mjs";
|
|
18
|
+
import { looksBinary as x, utf8ByteLength as j, readBytes as K } from "../localFiles/tools/runtime.mjs";
|
|
19
|
+
import { MAX_READ_BYTES as $, MAX_WRITE_BYTES as M, SHELL_CWD as N, SCRIPT_PROGRAMS as L } from "./constants.mjs";
|
|
20
|
+
import { isImagePath as A, isPdf as U, isStructuredPath as H, structureOverview as Q, extensionOf as X } from "./overview.mjs";
|
|
21
|
+
import { resolveFilePath as m, resolveRunPath as V, mentionsSkillDir as v, mentionsSyntheticDir as P, SYNTHETIC_DIR_MESSAGE as J, isSafeCwd as Z, skillRelative as R, toVirtualPath as T } from "./paths.mjs";
|
|
22
|
+
function W(e) {
|
|
23
|
+
return !!e && typeof e == "object" && e.name === "NotFoundError";
|
|
24
|
+
}
|
|
25
|
+
function _(e) {
|
|
26
|
+
try {
|
|
27
|
+
return new TextDecoder("utf-8", {
|
|
28
|
+
fatal: !0
|
|
29
|
+
}).decode(e);
|
|
30
|
+
} catch (t) {
|
|
31
|
+
throw new d(u.BadRequest, "文件不是 UTF-8 文本。");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function B(e) {
|
|
35
|
+
return e === "" ? [] : (e.endsWith(`
|
|
36
|
+
`) ? e.slice(0, -1) : e).split(`
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
39
|
+
function ee(e, t, n) {
|
|
40
|
+
if (t !== void 0 && n !== void 0 && n < t)
|
|
41
|
+
throw new d(u.BadRequest, "end_line 不能小于 start_line。");
|
|
42
|
+
const r = B(e), s = Math.max((t != null ? t : 1) - 1, 0), a = n != null ? n : r.length;
|
|
43
|
+
return r.slice(s, a).join(`
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
function O(e) {
|
|
47
|
+
if (j(e) <= $)
|
|
48
|
+
return {
|
|
49
|
+
text: e,
|
|
50
|
+
truncated: !1
|
|
51
|
+
};
|
|
52
|
+
const t = new TextEncoder().encode(e);
|
|
53
|
+
let n = $;
|
|
54
|
+
for (; n > 0 && (t[n] & 192) === 128; )
|
|
55
|
+
n -= 1;
|
|
56
|
+
const r = new TextDecoder().decode(t.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 k(e, t) {
|
|
64
|
+
return l(this, null, function* () {
|
|
65
|
+
const n = yield e.stat(t);
|
|
66
|
+
if (n.kind !== "file")
|
|
67
|
+
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
68
|
+
const r = yield K(yield e.readFile(t));
|
|
69
|
+
return {
|
|
70
|
+
entry: n,
|
|
71
|
+
bytes: r
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function D(e, t, n) {
|
|
76
|
+
const r = typeof n == "number" ? `${n} 字节,` : "";
|
|
77
|
+
return `${e},${r}路径 ${T(t)}。不返回正文。`;
|
|
78
|
+
}
|
|
79
|
+
function p(e) {
|
|
80
|
+
const t = L[X(e)];
|
|
81
|
+
if (!t) {
|
|
82
|
+
const n = Object.keys(L), r = `${n.slice(0, -1).join("、")} 或 ${n.at(-1)}`;
|
|
83
|
+
throw new d(u.BadRequest, `只能执行 ${r} 文件。`);
|
|
84
|
+
}
|
|
85
|
+
return t;
|
|
86
|
+
}
|
|
87
|
+
function Y(e) {
|
|
88
|
+
if (!e.runner)
|
|
89
|
+
throw new d(u.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
90
|
+
return e.runner;
|
|
91
|
+
}
|
|
92
|
+
function b(e, t, n, r) {
|
|
93
|
+
return l(this, null, function* () {
|
|
94
|
+
yield e.writeFile(t, n, {
|
|
95
|
+
createDirectories: !0,
|
|
96
|
+
signal: r
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function ge(e, t) {
|
|
101
|
+
return l(this, null, function* () {
|
|
102
|
+
const n = m(e.path);
|
|
103
|
+
if (y(t.signal), A(n)) {
|
|
104
|
+
const i = yield t.adapter.stat(n);
|
|
105
|
+
if (i.kind !== "file")
|
|
106
|
+
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
107
|
+
return {
|
|
108
|
+
data: {
|
|
109
|
+
content: D("图片", n, i.size),
|
|
110
|
+
truncated: !1
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const {
|
|
115
|
+
entry: r,
|
|
116
|
+
bytes: s
|
|
117
|
+
} = yield k(t.adapter, n);
|
|
118
|
+
if (U(n, s))
|
|
119
|
+
return {
|
|
120
|
+
data: {
|
|
121
|
+
content: D("PDF", n, r.size),
|
|
122
|
+
truncated: !1
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
if (x(s))
|
|
126
|
+
throw new d(u.BadRequest, "文件不是文本,无法读取正文。");
|
|
127
|
+
const a = _(s);
|
|
128
|
+
if (e.start_line !== void 0 || e.end_line !== void 0) {
|
|
129
|
+
const i = ee(a, e.start_line, e.end_line), f = O(i);
|
|
130
|
+
return {
|
|
131
|
+
data: {
|
|
132
|
+
content: f.text,
|
|
133
|
+
truncated: f.truncated
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (s.byteLength > $ && H(n))
|
|
138
|
+
return {
|
|
139
|
+
data: {
|
|
140
|
+
content: Q(n, a),
|
|
141
|
+
truncated: !0
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const c = O(a);
|
|
145
|
+
return {
|
|
146
|
+
data: {
|
|
147
|
+
content: c.text,
|
|
148
|
+
truncated: c.truncated
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function ye(e, t) {
|
|
154
|
+
return l(this, null, function* () {
|
|
155
|
+
const n = m(e.path);
|
|
156
|
+
if (j(e.content) > M)
|
|
157
|
+
throw new d(u.TooLarge, `content 按 UTF-8 计超过 ${M} 字节。请缩短后写入,或改用 append_file、edit_file。`);
|
|
158
|
+
return y(t.signal), yield b(t.adapter, n, e.content, t.signal), {
|
|
159
|
+
data: {}
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function xe(e, t) {
|
|
164
|
+
return l(this, null, function* () {
|
|
165
|
+
const n = m(e.path);
|
|
166
|
+
y(t.signal);
|
|
167
|
+
let r = "";
|
|
168
|
+
try {
|
|
169
|
+
const {
|
|
170
|
+
bytes: s
|
|
171
|
+
} = yield k(t.adapter, n);
|
|
172
|
+
if (x(s))
|
|
173
|
+
throw new d(u.BadRequest, "文件不是文本,无法追加。");
|
|
174
|
+
r = _(s);
|
|
175
|
+
} catch (s) {
|
|
176
|
+
if (!W(s))
|
|
177
|
+
throw s;
|
|
178
|
+
}
|
|
179
|
+
return yield b(t.adapter, n, r + e.content, t.signal), {
|
|
180
|
+
data: {}
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function _e(e, t) {
|
|
185
|
+
return l(this, null, function* () {
|
|
186
|
+
const n = m(e.path);
|
|
187
|
+
y(t.signal);
|
|
188
|
+
const {
|
|
189
|
+
bytes: r
|
|
190
|
+
} = yield k(t.adapter, n);
|
|
191
|
+
if (x(r))
|
|
192
|
+
throw new d(u.BadRequest, "文件不是文本,无法修改。");
|
|
193
|
+
const s = _(r), a = s.indexOf(e.old_text);
|
|
194
|
+
if (a < 0) {
|
|
195
|
+
const c = te(s, e.old_text);
|
|
196
|
+
throw new d(u.BadRequest, `找不到与 old_text 完全相同的内容。最接近的原文从第 ${c.line} 行开始,可复制后重试:
|
|
197
|
+
${c.excerpt}`, {
|
|
198
|
+
line: c.line,
|
|
199
|
+
excerpt: c.excerpt
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const o = s.slice(0, a) + e.new_text + s.slice(a + e.old_text.length);
|
|
203
|
+
return yield b(t.adapter, n, o, t.signal), {
|
|
204
|
+
data: {}
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function te(e, t) {
|
|
209
|
+
var i;
|
|
210
|
+
const n = B(e);
|
|
211
|
+
if (n.length === 0)
|
|
212
|
+
return {
|
|
213
|
+
line: 1,
|
|
214
|
+
excerpt: ""
|
|
215
|
+
};
|
|
216
|
+
const r = t.split(`
|
|
217
|
+
`), s = ((i = r[0]) != null ? i : "").slice(0, 200);
|
|
218
|
+
let a = 0, o = -1;
|
|
219
|
+
for (let f = 0; f < n.length; f += 1) {
|
|
220
|
+
const w = ne(n[f], s);
|
|
221
|
+
w > o && (o = w, a = f);
|
|
222
|
+
}
|
|
223
|
+
const c = Math.min(Math.max(r.length, 1), 8);
|
|
224
|
+
return {
|
|
225
|
+
line: a + 1,
|
|
226
|
+
excerpt: n.slice(a, a + c).join(`
|
|
227
|
+
`)
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
function ne(e, t) {
|
|
231
|
+
if (!t)
|
|
232
|
+
return 0;
|
|
233
|
+
const n = e.toLowerCase(), r = t.toLowerCase();
|
|
234
|
+
let s = 0, a = 0;
|
|
235
|
+
for (const o of n)
|
|
236
|
+
a < r.length && o === r[a] && (s += 1, a += 1);
|
|
237
|
+
return s;
|
|
238
|
+
}
|
|
239
|
+
function re(e) {
|
|
240
|
+
let t = "";
|
|
241
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
242
|
+
const r = e[n];
|
|
243
|
+
if (r === "\\") {
|
|
244
|
+
const s = e[n + 1];
|
|
245
|
+
if (s === void 0) {
|
|
246
|
+
t += "\\\\";
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
n += 1, t += "+?|{}()".includes(s) ? `\\${s}` : s === "n" ? "\\n" : s === "t" ? "\\t" : S(s);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if ("+?|{}()".includes(r)) {
|
|
253
|
+
t += `\\${r}`;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (r === "[") {
|
|
257
|
+
const s = e.indexOf("]", n + 1);
|
|
258
|
+
if (s < 0) {
|
|
259
|
+
t += "\\[";
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
t += e.slice(n, s + 1), n = s;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
t += ".^$*".includes(r) ? r : S(r);
|
|
266
|
+
}
|
|
267
|
+
return new RegExp(t);
|
|
268
|
+
}
|
|
269
|
+
function S(e) {
|
|
270
|
+
return /[\\^$.*+?()[\]{}|]/.test(e) ? `\\${e}` : e;
|
|
271
|
+
}
|
|
272
|
+
function se(e) {
|
|
273
|
+
try {
|
|
274
|
+
return re(e);
|
|
275
|
+
} catch (t) {
|
|
276
|
+
throw new d(u.BadRequest, "pattern 不是合法的 grep 基本正则。");
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
function F(e, t, n, r, s) {
|
|
280
|
+
return l(this, null, function* () {
|
|
281
|
+
if (r > 16)
|
|
282
|
+
return;
|
|
283
|
+
y(n);
|
|
284
|
+
const a = yield e.stat(t);
|
|
285
|
+
if (yield s(t, a.kind), a.kind !== "directory")
|
|
286
|
+
return;
|
|
287
|
+
const o = yield e.listEntries(t, n);
|
|
288
|
+
o.sort((c, i) => c.name < i.name ? -1 : c.name > i.name ? 1 : 0);
|
|
289
|
+
for (const c of o) {
|
|
290
|
+
const i = t ? `${t}/${c.name}` : c.name;
|
|
291
|
+
yield F(e, i, n, r + 1, s);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function ke(e, t) {
|
|
296
|
+
return l(this, null, function* () {
|
|
297
|
+
const n = m(e.path), r = se(e.pattern), s = [];
|
|
298
|
+
yield F(t.adapter, n, t.signal, 0, (o, c) => l(this, null, function* () {
|
|
299
|
+
if (c !== "file" || s.length >= 200)
|
|
300
|
+
return;
|
|
301
|
+
const {
|
|
302
|
+
bytes: i
|
|
303
|
+
} = yield k(t.adapter, o);
|
|
304
|
+
if (x(i) || A(o) || U(o, i))
|
|
305
|
+
return;
|
|
306
|
+
let f;
|
|
307
|
+
try {
|
|
308
|
+
f = _(i);
|
|
309
|
+
} catch (h) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const w = B(f);
|
|
313
|
+
for (let h = 0; h < w.length && s.length < 200; h += 1) {
|
|
314
|
+
if (!r.test(w[h]))
|
|
315
|
+
continue;
|
|
316
|
+
const G = w[h].length > 500 ? `${w[h].slice(0, 500)}…` : w[h];
|
|
317
|
+
s.push(`${T(o)}:${h + 1}:${G}`);
|
|
318
|
+
}
|
|
319
|
+
}));
|
|
320
|
+
const a = s.join(`
|
|
321
|
+
`);
|
|
322
|
+
return {
|
|
323
|
+
data: {
|
|
324
|
+
matches: s.length >= 200 ? `${a}
|
|
325
|
+
(匹配过多,已截断)` : a
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function ae(e, t) {
|
|
331
|
+
let n = "^";
|
|
332
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
333
|
+
const s = e[r];
|
|
334
|
+
if (s === "*")
|
|
335
|
+
n += ".*";
|
|
336
|
+
else if (s === "?")
|
|
337
|
+
n += ".";
|
|
338
|
+
else if (s === "[") {
|
|
339
|
+
const a = e.indexOf("]", r + 1);
|
|
340
|
+
a < 0 ? n += "\\[" : (n += e.slice(r, a + 1), r = a);
|
|
341
|
+
} else
|
|
342
|
+
n += S(s);
|
|
343
|
+
}
|
|
344
|
+
return new RegExp(`${n}$`).test(t);
|
|
345
|
+
}
|
|
346
|
+
function pe(e, t) {
|
|
347
|
+
return l(this, null, function* () {
|
|
348
|
+
const n = m(e.path), r = [];
|
|
349
|
+
yield F(t.adapter, n, t.signal, 0, (a) => l(this, null, function* () {
|
|
350
|
+
var c;
|
|
351
|
+
if (r.length >= 500)
|
|
352
|
+
return;
|
|
353
|
+
const o = (c = a.split("/").pop()) != null ? c : a;
|
|
354
|
+
ae(e.name, o) && r.push(T(a));
|
|
355
|
+
})), r.sort();
|
|
356
|
+
const s = r.join(`
|
|
357
|
+
`);
|
|
358
|
+
return {
|
|
359
|
+
data: {
|
|
360
|
+
files: r.length >= 500 ? `${s}
|
|
361
|
+
(结果过多,已截断)` : s
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function ce(e, t, n) {
|
|
367
|
+
return l(this, null, function* () {
|
|
368
|
+
const r = Y(n);
|
|
369
|
+
yield k(n.adapter, e);
|
|
370
|
+
const s = yield r.exec({
|
|
371
|
+
argv: [p(e), e, ...t],
|
|
372
|
+
cwd: N,
|
|
373
|
+
timeoutMs: n.timeoutMs,
|
|
374
|
+
signal: n.signal
|
|
375
|
+
});
|
|
376
|
+
return {
|
|
377
|
+
data: {
|
|
378
|
+
exitCode: s.exitCode,
|
|
379
|
+
stdout: s.stdout,
|
|
380
|
+
stderr: s.stderr
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
function Re(e, t) {
|
|
386
|
+
return l(this, null, function* () {
|
|
387
|
+
const n = V(e.path);
|
|
388
|
+
return p(n), ce(n, [], t);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function $e(e, t) {
|
|
392
|
+
return l(this, null, function* () {
|
|
393
|
+
if (v(e.command) || v(t.shellCwd.cwd))
|
|
394
|
+
throw new d(u.Forbidden, "技能文件只能通过技能工具访问。");
|
|
395
|
+
if (P(e.command) || P(t.shellCwd.cwd))
|
|
396
|
+
return {
|
|
397
|
+
data: {
|
|
398
|
+
exitCode: 1,
|
|
399
|
+
stdout: "",
|
|
400
|
+
stderr: `${J}
|
|
401
|
+
`
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const r = yield Y(t).exec({
|
|
405
|
+
command: e.command,
|
|
406
|
+
cwd: t.shellCwd.cwd,
|
|
407
|
+
timeoutMs: t.timeoutMs,
|
|
408
|
+
signal: t.signal
|
|
409
|
+
});
|
|
410
|
+
return r.cwd && Z(r.cwd) && (t.shellCwd.cwd = r.cwd), {
|
|
411
|
+
data: {
|
|
412
|
+
exitCode: r.exitCode,
|
|
413
|
+
stdout: r.stdout,
|
|
414
|
+
stderr: r.stderr
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
function g(e) {
|
|
420
|
+
if (!e.skills)
|
|
421
|
+
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
422
|
+
return e.skills;
|
|
423
|
+
}
|
|
424
|
+
const ie = "技能包文件(相对技能根目录)。用 read_skill_resource 按路径读取;resource_name 传目录则列出其中文件;以 grep: 开头则按基本正则搜索整个技能包,例如 grep:portrait。";
|
|
425
|
+
function C(e) {
|
|
426
|
+
return R(e, "SKILL.md"), "";
|
|
427
|
+
}
|
|
428
|
+
function q(e, t) {
|
|
429
|
+
return R(e, t).slice(`skills/${e}/`.length);
|
|
430
|
+
}
|
|
431
|
+
function oe(e) {
|
|
432
|
+
return !!e && typeof e == "object" && "name" in e && e.name === "TypeMismatchError";
|
|
433
|
+
}
|
|
434
|
+
function I(e) {
|
|
435
|
+
const t = e && typeof e == "object" && "name" in e ? String(e.name) : "", n = e instanceof Error ? e.message : "";
|
|
436
|
+
throw t === "TypeError" ? new d(u.BadRequest, n || "搜索表达式不合法。") : t === "NotFoundError" ? new d(u.NotFound, "技能或资源不存在。") : e;
|
|
437
|
+
}
|
|
438
|
+
function z(e, t, n) {
|
|
439
|
+
return l(this, null, function* () {
|
|
440
|
+
R(e, t);
|
|
441
|
+
const r = yield g(n).read(e, t, n.signal);
|
|
442
|
+
if (x(r))
|
|
443
|
+
throw new d(u.BadRequest, "技能资源不是文本。");
|
|
444
|
+
return _(r);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
function E(e, t, n) {
|
|
448
|
+
return l(this, null, function* () {
|
|
449
|
+
try {
|
|
450
|
+
return yield g(n).list(e, t, n.signal);
|
|
451
|
+
} catch (r) {
|
|
452
|
+
I(r);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function le(e) {
|
|
457
|
+
if (!e.skillRunner)
|
|
458
|
+
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
459
|
+
return e.skillRunner;
|
|
460
|
+
}
|
|
461
|
+
function Se(e, t) {
|
|
462
|
+
return l(this, null, function* () {
|
|
463
|
+
const n = yield z(e.skill_name, "SKILL.md", t);
|
|
464
|
+
let r = "";
|
|
465
|
+
try {
|
|
466
|
+
r = yield g(t).list(e.skill_name, "", t.signal);
|
|
467
|
+
} catch (s) {
|
|
468
|
+
r = "";
|
|
469
|
+
}
|
|
470
|
+
return r ? {
|
|
471
|
+
data: {
|
|
472
|
+
content: `${n}
|
|
473
|
+
|
|
474
|
+
${ie}
|
|
475
|
+
${r}`
|
|
476
|
+
}
|
|
477
|
+
} : {
|
|
478
|
+
data: {
|
|
479
|
+
content: n
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
function Ee(e, t) {
|
|
485
|
+
return l(this, null, function* () {
|
|
486
|
+
const n = e.path ? q(e.skill_name, e.path) : C(e.skill_name);
|
|
487
|
+
return {
|
|
488
|
+
data: {
|
|
489
|
+
files: yield E(e.skill_name, n, t)
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function Te(e, t) {
|
|
495
|
+
return l(this, null, function* () {
|
|
496
|
+
const n = e.path ? q(e.skill_name, e.path) : C(e.skill_name);
|
|
497
|
+
let r = "";
|
|
498
|
+
try {
|
|
499
|
+
r = yield g(t).grep(e.skill_name, e.pattern, n, t.signal);
|
|
500
|
+
} catch (s) {
|
|
501
|
+
I(s);
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
data: {
|
|
505
|
+
matches: r
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
function Be(e, t) {
|
|
511
|
+
return l(this, null, function* () {
|
|
512
|
+
if (e.resource_name.startsWith("grep:")) {
|
|
513
|
+
const r = e.resource_name.slice(5);
|
|
514
|
+
if (!r)
|
|
515
|
+
throw new d(u.BadRequest, "grep: 后面要写搜索表达式。");
|
|
516
|
+
C(e.skill_name);
|
|
517
|
+
let s = "";
|
|
518
|
+
try {
|
|
519
|
+
s = yield g(t).grep(e.skill_name, r, "", t.signal);
|
|
520
|
+
} catch (a) {
|
|
521
|
+
I(a);
|
|
522
|
+
}
|
|
523
|
+
return {
|
|
524
|
+
data: {
|
|
525
|
+
content: s || "没有匹配。"
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
if (e.resource_name === "." || e.resource_name === "./")
|
|
530
|
+
return {
|
|
531
|
+
data: {
|
|
532
|
+
content: (yield E(e.skill_name, "", t)) || "(空目录)"
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
const n = q(e.skill_name, e.resource_name.replace(/\/+$/, ""));
|
|
536
|
+
try {
|
|
537
|
+
return {
|
|
538
|
+
data: {
|
|
539
|
+
content: yield z(e.skill_name, n, t)
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
} catch (r) {
|
|
543
|
+
if (!oe(r))
|
|
544
|
+
throw r;
|
|
545
|
+
return {
|
|
546
|
+
data: {
|
|
547
|
+
content: (yield E(e.skill_name, n, t)) || "(空目录)"
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
function be(e, t) {
|
|
554
|
+
return l(this, null, function* () {
|
|
555
|
+
var o;
|
|
556
|
+
const n = g(t);
|
|
557
|
+
R(e.skill_name, e.script_name), p(e.script_name);
|
|
558
|
+
const r = le(t), s = yield n.target(e.skill_name, t.signal), a = n.track(s.skillId, s.version);
|
|
559
|
+
try {
|
|
560
|
+
const c = yield r.exec({
|
|
561
|
+
argv: [p(e.script_name), e.script_name, ...(o = e.args) != null ? o : []],
|
|
562
|
+
cwd: N,
|
|
563
|
+
timeoutMs: t.timeoutMs,
|
|
564
|
+
signal: t.signal,
|
|
565
|
+
skill: s
|
|
566
|
+
});
|
|
567
|
+
return {
|
|
568
|
+
data: {
|
|
569
|
+
exitCode: c.exitCode,
|
|
570
|
+
stdout: c.stdout,
|
|
571
|
+
stderr: c.stderr
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
} catch (c) {
|
|
575
|
+
throw W(c) ? new d(u.NotFound, "技能脚本不存在。") : c;
|
|
576
|
+
} finally {
|
|
577
|
+
a();
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
export {
|
|
582
|
+
xe as appendFile,
|
|
583
|
+
_e as editFile,
|
|
584
|
+
pe as find,
|
|
585
|
+
ke as grep,
|
|
586
|
+
Te as grepSkill,
|
|
587
|
+
Ee as listSkillFiles,
|
|
588
|
+
Se as loadSkill,
|
|
589
|
+
ge as readFile,
|
|
590
|
+
Be as readSkillResource,
|
|
591
|
+
Re as runFile,
|
|
592
|
+
be as runSkillScript,
|
|
593
|
+
$e as shell,
|
|
594
|
+
ye as writeFile
|
|
595
|
+
};
|