@glodon-aiot/bot-client-sdk 3.26.0-alpha.26 → 3.26.0-alpha.27
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 +12 -7
- package/dist/es/builtinTools/constants.mjs +12 -5
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +127 -125
- package/dist/es/builtinTools/platformSkills.mjs +96 -84
- package/dist/es/builtinTools/schemas.mjs +49 -4
- package/dist/es/builtinTools/tools.mjs +280 -179
- package/dist/es/localFiles/constants.mjs +10 -9
- package/dist/es/localFiles/host/sandboxClient.mjs +33 -8
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +45 -42
- package/dist/src/builtinTools/constants.d.ts +10 -2
- package/dist/src/builtinTools/platformSkills.d.ts +4 -0
- package/dist/src/builtinTools/tools.d.ts +9 -0
- package/dist/src/localFiles/constants.d.ts +2 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +2 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var l = (
|
|
1
|
+
var l = (e, t, n) => new Promise((r, s) => {
|
|
2
2
|
var a = (i) => {
|
|
3
3
|
try {
|
|
4
4
|
c(n.next(i));
|
|
@@ -12,99 +12,101 @@ var l = (t, e, n) => new Promise((r, s) => {
|
|
|
12
12
|
s(f);
|
|
13
13
|
}
|
|
14
14
|
}, c = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(a, o);
|
|
15
|
-
c((n = n.apply(
|
|
15
|
+
c((n = n.apply(e, t)).next());
|
|
16
16
|
});
|
|
17
|
-
import { throwIfAborted as
|
|
18
|
-
import { looksBinary as x, utf8ByteLength as
|
|
19
|
-
import { MAX_READ_BYTES as
|
|
20
|
-
import { isImagePath as
|
|
21
|
-
import { resolveFilePath as m, resolveRunPath as
|
|
22
|
-
function
|
|
23
|
-
return !!
|
|
24
|
-
}
|
|
25
|
-
function
|
|
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
26
|
try {
|
|
27
27
|
return new TextDecoder("utf-8", {
|
|
28
28
|
fatal: !0
|
|
29
|
-
}).decode(
|
|
30
|
-
} catch (
|
|
29
|
+
}).decode(e);
|
|
30
|
+
} catch (t) {
|
|
31
31
|
throw new d(u.BadRequest, "文件不是 UTF-8 文本。");
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
36
|
-
`) ?
|
|
34
|
+
function B(e) {
|
|
35
|
+
return e === "" ? [] : (e.endsWith(`
|
|
36
|
+
`) ? e.slice(0, -1) : e).split(`
|
|
37
37
|
`);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
if (
|
|
39
|
+
function ee(e, t, n) {
|
|
40
|
+
if (t !== void 0 && n !== void 0 && n < t)
|
|
41
41
|
throw new d(u.BadRequest, "end_line 不能小于 start_line。");
|
|
42
|
-
const r =
|
|
42
|
+
const r = B(e), s = Math.max((t != null ? t : 1) - 1, 0), a = n != null ? n : r.length;
|
|
43
43
|
return r.slice(s, a).join(`
|
|
44
44
|
`);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
47
|
-
if (
|
|
46
|
+
function O(e) {
|
|
47
|
+
if (j(e) <= $)
|
|
48
48
|
return {
|
|
49
|
-
text:
|
|
49
|
+
text: e,
|
|
50
50
|
truncated: !1
|
|
51
51
|
};
|
|
52
|
-
const
|
|
53
|
-
let n =
|
|
54
|
-
for (; n > 0 && (
|
|
52
|
+
const t = new TextEncoder().encode(e);
|
|
53
|
+
let n = $;
|
|
54
|
+
for (; n > 0 && (t[n] & 192) === 128; )
|
|
55
55
|
n -= 1;
|
|
56
|
-
const r = new TextDecoder().decode(
|
|
56
|
+
const r = new TextDecoder().decode(t.slice(0, n)), s = r.lastIndexOf(`
|
|
57
57
|
`);
|
|
58
58
|
return {
|
|
59
59
|
text: s > 0 ? r.slice(0, s) : r,
|
|
60
60
|
truncated: !0
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
function
|
|
63
|
+
function k(e, t) {
|
|
64
64
|
return l(this, null, function* () {
|
|
65
|
-
const n = yield
|
|
65
|
+
const n = yield e.stat(t);
|
|
66
66
|
if (n.kind !== "file")
|
|
67
67
|
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
68
|
-
const r = yield
|
|
68
|
+
const r = yield K(yield e.readFile(t));
|
|
69
69
|
return {
|
|
70
70
|
entry: n,
|
|
71
71
|
bytes: r
|
|
72
72
|
};
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
function
|
|
75
|
+
function D(e, t, n) {
|
|
76
76
|
const r = typeof n == "number" ? `${n} 字节,` : "";
|
|
77
|
-
return `${
|
|
77
|
+
return `${e},${r}路径 ${T(t)}。不返回正文。`;
|
|
78
78
|
}
|
|
79
|
-
function
|
|
80
|
-
const
|
|
81
|
-
if (!
|
|
82
|
-
|
|
83
|
-
|
|
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;
|
|
84
86
|
}
|
|
85
|
-
function
|
|
86
|
-
if (!
|
|
87
|
+
function Y(e) {
|
|
88
|
+
if (!e.runner)
|
|
87
89
|
throw new d(u.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
88
|
-
return
|
|
90
|
+
return e.runner;
|
|
89
91
|
}
|
|
90
|
-
function
|
|
92
|
+
function b(e, t, n, r) {
|
|
91
93
|
return l(this, null, function* () {
|
|
92
|
-
yield
|
|
94
|
+
yield e.writeFile(t, n, {
|
|
93
95
|
createDirectories: !0,
|
|
94
96
|
signal: r
|
|
95
97
|
});
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
function
|
|
100
|
+
function ge(e, t) {
|
|
99
101
|
return l(this, null, function* () {
|
|
100
|
-
const n = m(
|
|
101
|
-
if (
|
|
102
|
-
const i = yield
|
|
102
|
+
const n = m(e.path);
|
|
103
|
+
if (y(t.signal), A(n)) {
|
|
104
|
+
const i = yield t.adapter.stat(n);
|
|
103
105
|
if (i.kind !== "file")
|
|
104
106
|
throw new d(u.BadRequest, "目标是目录,不是文件。");
|
|
105
107
|
return {
|
|
106
108
|
data: {
|
|
107
|
-
content:
|
|
109
|
+
content: D("图片", n, i.size),
|
|
108
110
|
truncated: !1
|
|
109
111
|
}
|
|
110
112
|
};
|
|
@@ -112,19 +114,19 @@ function dt(t, e) {
|
|
|
112
114
|
const {
|
|
113
115
|
entry: r,
|
|
114
116
|
bytes: s
|
|
115
|
-
} = yield
|
|
116
|
-
if (
|
|
117
|
+
} = yield k(t.adapter, n);
|
|
118
|
+
if (U(n, s))
|
|
117
119
|
return {
|
|
118
120
|
data: {
|
|
119
|
-
content:
|
|
121
|
+
content: D("PDF", n, r.size),
|
|
120
122
|
truncated: !1
|
|
121
123
|
}
|
|
122
124
|
};
|
|
123
125
|
if (x(s))
|
|
124
126
|
throw new d(u.BadRequest, "文件不是文本,无法读取正文。");
|
|
125
|
-
const a =
|
|
126
|
-
if (
|
|
127
|
-
const i =
|
|
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);
|
|
128
130
|
return {
|
|
129
131
|
data: {
|
|
130
132
|
content: f.text,
|
|
@@ -132,14 +134,14 @@ function dt(t, e) {
|
|
|
132
134
|
}
|
|
133
135
|
};
|
|
134
136
|
}
|
|
135
|
-
if (s.byteLength >
|
|
137
|
+
if (s.byteLength > $ && H(n))
|
|
136
138
|
return {
|
|
137
139
|
data: {
|
|
138
|
-
content:
|
|
140
|
+
content: Q(n, a),
|
|
139
141
|
truncated: !0
|
|
140
142
|
}
|
|
141
143
|
};
|
|
142
|
-
const c =
|
|
144
|
+
const c = O(a);
|
|
143
145
|
return {
|
|
144
146
|
data: {
|
|
145
147
|
content: c.text,
|
|
@@ -148,74 +150,74 @@ function dt(t, e) {
|
|
|
148
150
|
};
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
|
-
function
|
|
153
|
+
function ye(e, t) {
|
|
152
154
|
return l(this, null, function* () {
|
|
153
|
-
const n = m(
|
|
154
|
-
if (
|
|
155
|
-
throw new d(u.TooLarge, `content 按 UTF-8 计超过 ${
|
|
156
|
-
return
|
|
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), {
|
|
157
159
|
data: {}
|
|
158
160
|
};
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
|
-
function
|
|
163
|
+
function xe(e, t) {
|
|
162
164
|
return l(this, null, function* () {
|
|
163
|
-
const n = m(
|
|
164
|
-
|
|
165
|
+
const n = m(e.path);
|
|
166
|
+
y(t.signal);
|
|
165
167
|
let r = "";
|
|
166
168
|
try {
|
|
167
169
|
const {
|
|
168
170
|
bytes: s
|
|
169
|
-
} = yield
|
|
171
|
+
} = yield k(t.adapter, n);
|
|
170
172
|
if (x(s))
|
|
171
173
|
throw new d(u.BadRequest, "文件不是文本,无法追加。");
|
|
172
|
-
r =
|
|
174
|
+
r = _(s);
|
|
173
175
|
} catch (s) {
|
|
174
|
-
if (!
|
|
176
|
+
if (!W(s))
|
|
175
177
|
throw s;
|
|
176
178
|
}
|
|
177
|
-
return yield
|
|
179
|
+
return yield b(t.adapter, n, r + e.content, t.signal), {
|
|
178
180
|
data: {}
|
|
179
181
|
};
|
|
180
182
|
});
|
|
181
183
|
}
|
|
182
|
-
function
|
|
184
|
+
function _e(e, t) {
|
|
183
185
|
return l(this, null, function* () {
|
|
184
|
-
const n = m(
|
|
185
|
-
|
|
186
|
+
const n = m(e.path);
|
|
187
|
+
y(t.signal);
|
|
186
188
|
const {
|
|
187
189
|
bytes: r
|
|
188
|
-
} = yield
|
|
190
|
+
} = yield k(t.adapter, n);
|
|
189
191
|
if (x(r))
|
|
190
192
|
throw new d(u.BadRequest, "文件不是文本,无法修改。");
|
|
191
|
-
const s =
|
|
193
|
+
const s = _(r), a = s.indexOf(e.old_text);
|
|
192
194
|
if (a < 0) {
|
|
193
|
-
const c =
|
|
195
|
+
const c = te(s, e.old_text);
|
|
194
196
|
throw new d(u.BadRequest, `找不到与 old_text 完全相同的内容。最接近的原文从第 ${c.line} 行开始,可复制后重试:
|
|
195
197
|
${c.excerpt}`, {
|
|
196
198
|
line: c.line,
|
|
197
199
|
excerpt: c.excerpt
|
|
198
200
|
});
|
|
199
201
|
}
|
|
200
|
-
const o = s.slice(0, a) +
|
|
201
|
-
return yield
|
|
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), {
|
|
202
204
|
data: {}
|
|
203
205
|
};
|
|
204
206
|
});
|
|
205
207
|
}
|
|
206
|
-
function
|
|
208
|
+
function te(e, t) {
|
|
207
209
|
var i;
|
|
208
|
-
const n =
|
|
210
|
+
const n = B(e);
|
|
209
211
|
if (n.length === 0)
|
|
210
212
|
return {
|
|
211
213
|
line: 1,
|
|
212
214
|
excerpt: ""
|
|
213
215
|
};
|
|
214
|
-
const r =
|
|
216
|
+
const r = t.split(`
|
|
215
217
|
`), s = ((i = r[0]) != null ? i : "").slice(0, 200);
|
|
216
218
|
let a = 0, o = -1;
|
|
217
219
|
for (let f = 0; f < n.length; f += 1) {
|
|
218
|
-
const w =
|
|
220
|
+
const w = ne(n[f], s);
|
|
219
221
|
w > o && (o = w, a = f);
|
|
220
222
|
}
|
|
221
223
|
const c = Math.min(Math.max(r.length, 1), 8);
|
|
@@ -225,94 +227,94 @@ function J(t, e) {
|
|
|
225
227
|
`)
|
|
226
228
|
};
|
|
227
229
|
}
|
|
228
|
-
function
|
|
229
|
-
if (!
|
|
230
|
+
function ne(e, t) {
|
|
231
|
+
if (!t)
|
|
230
232
|
return 0;
|
|
231
|
-
const n =
|
|
233
|
+
const n = e.toLowerCase(), r = t.toLowerCase();
|
|
232
234
|
let s = 0, a = 0;
|
|
233
235
|
for (const o of n)
|
|
234
236
|
a < r.length && o === r[a] && (s += 1, a += 1);
|
|
235
237
|
return s;
|
|
236
238
|
}
|
|
237
|
-
function
|
|
238
|
-
let
|
|
239
|
-
for (let n = 0; n <
|
|
240
|
-
const r =
|
|
239
|
+
function re(e) {
|
|
240
|
+
let t = "";
|
|
241
|
+
for (let n = 0; n < e.length; n += 1) {
|
|
242
|
+
const r = e[n];
|
|
241
243
|
if (r === "\\") {
|
|
242
|
-
const s =
|
|
244
|
+
const s = e[n + 1];
|
|
243
245
|
if (s === void 0) {
|
|
244
|
-
|
|
246
|
+
t += "\\\\";
|
|
245
247
|
continue;
|
|
246
248
|
}
|
|
247
|
-
n += 1,
|
|
249
|
+
n += 1, t += "+?|{}()".includes(s) ? `\\${s}` : s === "n" ? "\\n" : s === "t" ? "\\t" : S(s);
|
|
248
250
|
continue;
|
|
249
251
|
}
|
|
250
252
|
if ("+?|{}()".includes(r)) {
|
|
251
|
-
|
|
253
|
+
t += `\\${r}`;
|
|
252
254
|
continue;
|
|
253
255
|
}
|
|
254
256
|
if (r === "[") {
|
|
255
|
-
const s =
|
|
257
|
+
const s = e.indexOf("]", n + 1);
|
|
256
258
|
if (s < 0) {
|
|
257
|
-
|
|
259
|
+
t += "\\[";
|
|
258
260
|
continue;
|
|
259
261
|
}
|
|
260
|
-
|
|
262
|
+
t += e.slice(n, s + 1), n = s;
|
|
261
263
|
continue;
|
|
262
264
|
}
|
|
263
|
-
|
|
265
|
+
t += ".^$*".includes(r) ? r : S(r);
|
|
264
266
|
}
|
|
265
|
-
return new RegExp(
|
|
267
|
+
return new RegExp(t);
|
|
266
268
|
}
|
|
267
|
-
function
|
|
268
|
-
return /[\\^$.*+?()[\]{}|]/.test(
|
|
269
|
+
function S(e) {
|
|
270
|
+
return /[\\^$.*+?()[\]{}|]/.test(e) ? `\\${e}` : e;
|
|
269
271
|
}
|
|
270
|
-
function
|
|
272
|
+
function se(e) {
|
|
271
273
|
try {
|
|
272
|
-
return
|
|
273
|
-
} catch (
|
|
274
|
+
return re(e);
|
|
275
|
+
} catch (t) {
|
|
274
276
|
throw new d(u.BadRequest, "pattern 不是合法的 grep 基本正则。");
|
|
275
277
|
}
|
|
276
278
|
}
|
|
277
|
-
function
|
|
279
|
+
function F(e, t, n, r, s) {
|
|
278
280
|
return l(this, null, function* () {
|
|
279
281
|
if (r > 16)
|
|
280
282
|
return;
|
|
281
|
-
|
|
282
|
-
const a = yield
|
|
283
|
-
if (yield s(
|
|
283
|
+
y(n);
|
|
284
|
+
const a = yield e.stat(t);
|
|
285
|
+
if (yield s(t, a.kind), a.kind !== "directory")
|
|
284
286
|
return;
|
|
285
|
-
const o = yield
|
|
287
|
+
const o = yield e.listEntries(t, n);
|
|
286
288
|
o.sort((c, i) => c.name < i.name ? -1 : c.name > i.name ? 1 : 0);
|
|
287
289
|
for (const c of o) {
|
|
288
|
-
const i =
|
|
289
|
-
yield
|
|
290
|
+
const i = t ? `${t}/${c.name}` : c.name;
|
|
291
|
+
yield F(e, i, n, r + 1, s);
|
|
290
292
|
}
|
|
291
293
|
});
|
|
292
294
|
}
|
|
293
|
-
function
|
|
295
|
+
function ke(e, t) {
|
|
294
296
|
return l(this, null, function* () {
|
|
295
|
-
const n = m(
|
|
296
|
-
yield
|
|
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* () {
|
|
297
299
|
if (c !== "file" || s.length >= 200)
|
|
298
300
|
return;
|
|
299
301
|
const {
|
|
300
302
|
bytes: i
|
|
301
|
-
} = yield
|
|
302
|
-
if (x(i) ||
|
|
303
|
+
} = yield k(t.adapter, o);
|
|
304
|
+
if (x(i) || A(o) || U(o, i))
|
|
303
305
|
return;
|
|
304
306
|
let f;
|
|
305
307
|
try {
|
|
306
|
-
f =
|
|
308
|
+
f = _(i);
|
|
307
309
|
} catch (h) {
|
|
308
310
|
return;
|
|
309
311
|
}
|
|
310
|
-
const w =
|
|
312
|
+
const w = B(f);
|
|
311
313
|
for (let h = 0; h < w.length && s.length < 200; h += 1) {
|
|
312
314
|
if (!r.test(w[h]))
|
|
313
315
|
continue;
|
|
314
|
-
const
|
|
315
|
-
s.push(`${
|
|
316
|
+
const G = w[h].length > 500 ? `${w[h].slice(0, 500)}…` : w[h];
|
|
317
|
+
s.push(`${T(o)}:${h + 1}:${G}`);
|
|
316
318
|
}
|
|
317
319
|
}));
|
|
318
320
|
const a = s.join(`
|
|
@@ -325,31 +327,31 @@ function ht(t, e) {
|
|
|
325
327
|
};
|
|
326
328
|
});
|
|
327
329
|
}
|
|
328
|
-
function
|
|
330
|
+
function ae(e, t) {
|
|
329
331
|
let n = "^";
|
|
330
|
-
for (let r = 0; r <
|
|
331
|
-
const s =
|
|
332
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
333
|
+
const s = e[r];
|
|
332
334
|
if (s === "*")
|
|
333
335
|
n += ".*";
|
|
334
336
|
else if (s === "?")
|
|
335
337
|
n += ".";
|
|
336
338
|
else if (s === "[") {
|
|
337
|
-
const a =
|
|
338
|
-
a < 0 ? n += "\\[" : (n +=
|
|
339
|
+
const a = e.indexOf("]", r + 1);
|
|
340
|
+
a < 0 ? n += "\\[" : (n += e.slice(r, a + 1), r = a);
|
|
339
341
|
} else
|
|
340
|
-
n +=
|
|
342
|
+
n += S(s);
|
|
341
343
|
}
|
|
342
|
-
return new RegExp(`${n}$`).test(
|
|
344
|
+
return new RegExp(`${n}$`).test(t);
|
|
343
345
|
}
|
|
344
|
-
function
|
|
346
|
+
function pe(e, t) {
|
|
345
347
|
return l(this, null, function* () {
|
|
346
|
-
const n = m(
|
|
347
|
-
yield
|
|
348
|
+
const n = m(e.path), r = [];
|
|
349
|
+
yield F(t.adapter, n, t.signal, 0, (a) => l(this, null, function* () {
|
|
348
350
|
var c;
|
|
349
351
|
if (r.length >= 500)
|
|
350
352
|
return;
|
|
351
353
|
const o = (c = a.split("/").pop()) != null ? c : a;
|
|
352
|
-
|
|
354
|
+
ae(e.name, o) && r.push(T(a));
|
|
353
355
|
})), r.sort();
|
|
354
356
|
const s = r.join(`
|
|
355
357
|
`);
|
|
@@ -361,13 +363,13 @@ function mt(t, e) {
|
|
|
361
363
|
};
|
|
362
364
|
});
|
|
363
365
|
}
|
|
364
|
-
function
|
|
366
|
+
function ce(e, t, n) {
|
|
365
367
|
return l(this, null, function* () {
|
|
366
|
-
const r =
|
|
367
|
-
yield
|
|
368
|
+
const r = Y(n);
|
|
369
|
+
yield k(n.adapter, e);
|
|
368
370
|
const s = yield r.exec({
|
|
369
|
-
argv: [
|
|
370
|
-
cwd:
|
|
371
|
+
argv: [p(e), e, ...t],
|
|
372
|
+
cwd: N,
|
|
371
373
|
timeoutMs: n.timeoutMs,
|
|
372
374
|
signal: n.signal
|
|
373
375
|
});
|
|
@@ -380,32 +382,32 @@ function nt(t, e, n) {
|
|
|
380
382
|
};
|
|
381
383
|
});
|
|
382
384
|
}
|
|
383
|
-
function
|
|
385
|
+
function Re(e, t) {
|
|
384
386
|
return l(this, null, function* () {
|
|
385
|
-
const n =
|
|
386
|
-
return
|
|
387
|
+
const n = V(e.path);
|
|
388
|
+
return p(n), ce(n, [], t);
|
|
387
389
|
});
|
|
388
390
|
}
|
|
389
|
-
function
|
|
391
|
+
function $e(e, t) {
|
|
390
392
|
return l(this, null, function* () {
|
|
391
|
-
if (
|
|
393
|
+
if (v(e.command) || v(t.shellCwd.cwd))
|
|
392
394
|
throw new d(u.Forbidden, "技能文件只能通过技能工具访问。");
|
|
393
|
-
if (
|
|
395
|
+
if (P(e.command) || P(t.shellCwd.cwd))
|
|
394
396
|
return {
|
|
395
397
|
data: {
|
|
396
398
|
exitCode: 1,
|
|
397
399
|
stdout: "",
|
|
398
|
-
stderr: `${
|
|
400
|
+
stderr: `${J}
|
|
399
401
|
`
|
|
400
402
|
}
|
|
401
403
|
};
|
|
402
|
-
const r = yield
|
|
403
|
-
command:
|
|
404
|
-
cwd:
|
|
405
|
-
timeoutMs:
|
|
406
|
-
signal:
|
|
404
|
+
const r = yield Y(t).exec({
|
|
405
|
+
command: e.command,
|
|
406
|
+
cwd: t.shellCwd.cwd,
|
|
407
|
+
timeoutMs: t.timeoutMs,
|
|
408
|
+
signal: t.signal
|
|
407
409
|
});
|
|
408
|
-
return r.cwd &&
|
|
410
|
+
return r.cwd && Z(r.cwd) && (t.shellCwd.cwd = r.cwd), {
|
|
409
411
|
data: {
|
|
410
412
|
exitCode: r.exitCode,
|
|
411
413
|
stdout: r.stdout,
|
|
@@ -414,55 +416,152 @@ function xt(t, e) {
|
|
|
414
416
|
};
|
|
415
417
|
});
|
|
416
418
|
}
|
|
417
|
-
function
|
|
418
|
-
if (!
|
|
419
|
+
function g(e) {
|
|
420
|
+
if (!e.skills)
|
|
419
421
|
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
420
|
-
return
|
|
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";
|
|
421
433
|
}
|
|
422
|
-
function
|
|
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) {
|
|
423
439
|
return l(this, null, function* () {
|
|
424
|
-
|
|
425
|
-
const r = yield
|
|
440
|
+
R(e, t);
|
|
441
|
+
const r = yield g(n).read(e, t, n.signal);
|
|
426
442
|
if (x(r))
|
|
427
443
|
throw new d(u.BadRequest, "技能资源不是文本。");
|
|
428
|
-
return
|
|
444
|
+
return _(r);
|
|
429
445
|
});
|
|
430
446
|
}
|
|
431
|
-
function
|
|
432
|
-
|
|
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)
|
|
433
458
|
throw new d(u.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
|
|
434
|
-
return
|
|
459
|
+
return e.skillRunner;
|
|
435
460
|
}
|
|
436
|
-
function
|
|
461
|
+
function Se(e, t) {
|
|
437
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);
|
|
438
487
|
return {
|
|
439
488
|
data: {
|
|
440
|
-
|
|
489
|
+
files: yield E(e.skill_name, n, t)
|
|
441
490
|
}
|
|
442
491
|
};
|
|
443
492
|
});
|
|
444
493
|
}
|
|
445
|
-
function
|
|
494
|
+
function Te(e, t) {
|
|
446
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
|
+
}
|
|
447
503
|
return {
|
|
448
504
|
data: {
|
|
449
|
-
|
|
505
|
+
matches: r
|
|
450
506
|
}
|
|
451
507
|
};
|
|
452
508
|
});
|
|
453
509
|
}
|
|
454
|
-
function
|
|
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) {
|
|
455
554
|
return l(this, null, function* () {
|
|
456
555
|
var o;
|
|
457
|
-
const n =
|
|
458
|
-
|
|
459
|
-
const r =
|
|
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);
|
|
460
559
|
try {
|
|
461
560
|
const c = yield r.exec({
|
|
462
|
-
argv: [
|
|
463
|
-
cwd:
|
|
464
|
-
timeoutMs:
|
|
465
|
-
signal:
|
|
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,
|
|
466
565
|
skill: s
|
|
467
566
|
});
|
|
468
567
|
return {
|
|
@@ -473,22 +572,24 @@ function _t(t, e) {
|
|
|
473
572
|
}
|
|
474
573
|
};
|
|
475
574
|
} catch (c) {
|
|
476
|
-
throw
|
|
575
|
+
throw W(c) ? new d(u.NotFound, "技能脚本不存在。") : c;
|
|
477
576
|
} finally {
|
|
478
577
|
a();
|
|
479
578
|
}
|
|
480
579
|
});
|
|
481
580
|
}
|
|
482
581
|
export {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
|
494
595
|
};
|