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