@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.9

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.
@@ -1,114 +1,122 @@
1
- var G = Object.defineProperty, K = Object.defineProperties;
2
- var W = Object.getOwnPropertyDescriptors;
3
- var D = Object.getOwnPropertySymbols;
1
+ var z = Object.defineProperty, G = Object.defineProperties;
2
+ var K = Object.getOwnPropertyDescriptors;
3
+ var P = Object.getOwnPropertySymbols;
4
4
  var X = Object.prototype.hasOwnProperty, Q = Object.prototype.propertyIsEnumerable;
5
- var P = (e, t, o) => t in e ? G(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, s = (e, t) => {
5
+ var C = (e, t, o) => t in e ? z(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, s = (e, t) => {
6
6
  for (var o in t || (t = {}))
7
- X.call(t, o) && P(e, o, t[o]);
8
- if (D)
9
- for (var o of D(t))
10
- Q.call(t, o) && P(e, o, t[o]);
7
+ X.call(t, o) && C(e, o, t[o]);
8
+ if (P)
9
+ for (var o of P(t))
10
+ Q.call(t, o) && C(e, o, t[o]);
11
11
  return e;
12
- }, h = (e, t) => K(e, W(t));
13
- var U = (e, t, o) => new Promise((l, u) => {
14
- var m = (n) => {
12
+ }, h = (e, t) => G(e, K(t));
13
+ var D = (e, t, o) => new Promise((a, m) => {
14
+ var d = (n) => {
15
15
  try {
16
- d(o.next(n));
16
+ c(o.next(n));
17
17
  } catch (r) {
18
- u(r);
18
+ m(r);
19
19
  }
20
- }, c = (n) => {
20
+ }, f = (n) => {
21
21
  try {
22
- d(o.throw(n));
22
+ c(o.throw(n));
23
23
  } catch (r) {
24
- u(r);
24
+ m(r);
25
25
  }
26
- }, d = (n) => n.done ? l(n.value) : Promise.resolve(n.value).then(m, c);
27
- d((o = o.apply(e, t)).next());
26
+ }, c = (n) => n.done ? a(n.value) : Promise.resolve(n.value).then(d, f);
27
+ c((o = o.apply(e, t)).next());
28
28
  });
29
29
  import { v4 as Y } from "uuid";
30
30
  import Z from "../Logger.mjs";
31
31
  import { HostBridgeAdapter as k } from "../localFiles/adapters/HostBridgeAdapter.mjs";
32
- import { SANDBOX_PROTOCOL as ee } from "../localFiles/host/protocol.mjs";
33
- import { cancelledError as w, workspaceNotGranted as te, ToolError as f, ToolCode as a, toToolError as oe } from "../localFiles/errors.mjs";
34
- import { validateToolInput as ne } from "../localFiles/validate.mjs";
35
- import { BrowserCommandRunner as re } from "./browserRuntime/BrowserCommandRunner.mjs";
36
- import { withOutputLimit as E } from "./command.mjs";
37
- import { BUILTIN_FUNCTION_CODES as ie, SHELL_CWD as se } from "./constants.mjs";
38
- import { BUILTIN_TOOL_SCHEMAS as le } from "./schemas.mjs";
39
- import { shell as ae, readFile as de, writeFile as ce, appendFile as ue, runFile as me, editFile as fe, grep as ge, find as he, loadSkill as _e, readSkillResource as be, runSkillScript as ye } from "./tools.mjs";
32
+ import { domError as ee } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
33
+ import { SANDBOX_PROTOCOL as te } from "../localFiles/host/protocol.mjs";
34
+ import { cancelledError as T, workspaceNotGranted as oe, ToolError as u, ToolCode as l, toToolError as ne } from "../localFiles/errors.mjs";
35
+ import { validateToolInput as re } from "../localFiles/validate.mjs";
36
+ import { BrowserCommandRunner as ie } from "./browserRuntime/BrowserCommandRunner.mjs";
37
+ import { withOutputLimit as U } from "./command.mjs";
38
+ import { BUILTIN_FUNCTION_CODES as se, SHELL_CWD as le } from "./constants.mjs";
39
+ import { BUILTIN_TOOL_SCHEMAS as ae } from "./schemas.mjs";
40
+ import { shell as de, readFile as ce, writeFile as me, appendFile as ue, runFile as fe, editFile as ge, grep as he, find as _e, loadSkill as be, readSkillResource as ye, runSkillScript as we } from "./tools.mjs";
40
41
  const Te = {
41
- shell: ae,
42
- read_file: de,
43
- write_file: ce,
42
+ shell: de,
43
+ read_file: ce,
44
+ write_file: me,
44
45
  append_file: ue,
45
- run_file: me,
46
- edit_file: fe,
47
- grep: ge,
48
- find: he,
49
- load_skill: _e,
50
- read_skill_resource: be,
51
- run_skill_script: ye
52
- }, T = new Z("[BuiltinTools] "), H = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
53
- function we(e, t, o) {
54
- var l, u;
46
+ run_file: fe,
47
+ edit_file: ge,
48
+ grep: he,
49
+ find: _e,
50
+ load_skill: be,
51
+ read_skill_resource: ye,
52
+ run_skill_script: we
53
+ }, w = new Z("[BuiltinTools] "), j = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
54
+ function pe(e, t, o) {
55
+ var a, m;
55
56
  if (e.commandRunner)
56
- return E(e.commandRunner);
57
- if (t instanceof k && t.capabilities.has("sandbox-exec")) {
58
- if (t.canExec)
59
- return E({
60
- exec: (c) => t.exec(c)
61
- });
62
- const m = `${(l = t.sandboxVersion) != null ? l : ""}@${(u = t.sandboxProtocol) != null ? u : ""}`;
63
- o.rejectedSandbox !== m && (o.rejectedSandbox = m, T.error("sandbox-protocol", {
64
- sandboxVersion: t.sandboxVersion,
65
- sandboxProtocol: t.sandboxProtocol,
66
- supported: ee
67
- }));
57
+ return U(e.commandRunner);
58
+ if (t instanceof k) {
59
+ if (t.protocolMismatch) {
60
+ const d = `${(a = t.sandboxVersion) != null ? a : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
61
+ o.rejectedSandbox !== d && (o.rejectedSandbox = d, w.error("sandbox-protocol", {
62
+ sandboxVersion: t.sandboxVersion,
63
+ sandboxProtocol: t.sandboxProtocol,
64
+ supported: te
65
+ }));
66
+ }
67
+ if (!t.canExec) {
68
+ const d = t.unavailableMessage();
69
+ return {
70
+ exec: () => Promise.reject(ee("NotAllowedError", d))
71
+ };
72
+ }
73
+ return {
74
+ exec: (d) => t.exec(d)
75
+ };
68
76
  }
69
77
  if (e.browserRuntime.enabled)
70
- return (o.adapter !== t || !o.runner) && (o.adapter = t, o.runner = E(new re({
78
+ return (o.adapter !== t || !o.runner) && (o.adapter = t, o.runner = U(new ie({
71
79
  adapter: t,
72
80
  sensitive: e.sensitive,
73
81
  moduleURL: e.browserRuntime.bashModuleURL,
74
82
  pyodideIndexURL: e.browserRuntime.pyodideIndexURL
75
83
  }))), o.runner;
76
84
  }
77
- function pe(e) {
85
+ function Ie(e) {
78
86
  if (typeof e != "string")
79
87
  return e;
80
88
  try {
81
89
  return JSON.parse(e);
82
90
  } catch (t) {
83
- throw new f(a.BadRequest, "参数不是合法的 JSON 对象。");
91
+ throw new u(l.BadRequest, "参数不是合法的 JSON 对象。");
84
92
  }
85
93
  }
86
94
  function xe(e) {
87
95
  const t = e instanceof DOMException ? e.name : "", o = e instanceof Error ? e.message : "";
88
96
  if (t === "NotFoundError")
89
- return new f(a.NotFound, "脚本或目录不存在。");
97
+ return new u(l.NotFound, "脚本或目录不存在。");
90
98
  if (t === "SecurityError")
91
- return new f(a.Forbidden, "命令路径不在工作区内。");
99
+ return new u(l.Forbidden, "命令路径不在工作区内。");
92
100
  if (t === "AbortError")
93
- return o.includes("超时") ? new f(a.Timeout, "命令运行超时,已中止。") : o.includes("已有") ? new f(a.TooManyRequests, "已有一个命令在运行。") : w();
101
+ return o.includes("超时") ? new u(l.Timeout, "命令运行超时,已中止。") : o.includes("已有") ? new u(l.TooManyRequests, "已有一个命令在运行。") : T();
94
102
  if (t === "NotAllowedError")
95
- return new f(a.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
103
+ return o.startsWith("沙箱") ? new u(l.NotImplemented, o) : new u(l.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
96
104
  }
97
- function Ie(e) {
105
+ function Oe(e) {
98
106
  return new Promise((t, o) => {
99
- e.aborted && o(w()), e.addEventListener("abort", () => o(w()), {
107
+ e.aborted && o(T()), e.addEventListener("abort", () => o(T()), {
100
108
  once: !0
101
109
  });
102
110
  });
103
111
  }
104
- function V(e, t = 160) {
112
+ function H(e, t = 160) {
105
113
  return e.length > t ? `${e.slice(0, t)}…` : e;
106
114
  }
107
- function Oe(e) {
115
+ function Ee(e) {
108
116
  const t = {};
109
117
  for (const o of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
110
118
  typeof e[o] == "string" && (t[o] = e[o]);
111
- return typeof e.command == "string" && (t.command = V(e.command)), typeof e.start_line == "number" && (t.start_line = e.start_line), typeof e.end_line == "number" && (t.end_line = e.end_line), typeof e.content == "string" && (t.contentLength = e.content.length), typeof e.old_text == "string" && (t.oldTextLength = e.old_text.length), typeof e.new_text == "string" && (t.newTextLength = e.new_text.length), Array.isArray(e.args) && (t.argCount = e.args.length), t;
119
+ return typeof e.command == "string" && (t.command = H(e.command)), typeof e.start_line == "number" && (t.start_line = e.start_line), typeof e.end_line == "number" && (t.end_line = e.end_line), typeof e.content == "string" && (t.contentLength = e.content.length), typeof e.old_text == "string" && (t.oldTextLength = e.old_text.length), typeof e.new_text == "string" && (t.newTextLength = e.new_text.length), Array.isArray(e.args) && (t.argCount = e.args.length), t;
112
120
  }
113
121
  function Le(e) {
114
122
  return s({
@@ -118,21 +126,21 @@ function Le(e) {
118
126
  data: e.data
119
127
  } : {});
120
128
  }
121
- function Ue({
129
+ function He({
122
130
  pluginCode: e,
123
131
  workspace: t
124
132
  }) {
125
- const o = /* @__PURE__ */ new Map(), l = {}, u = {};
126
- return ie.forEach((m) => {
127
- u[m] = (c, d, n) => {
133
+ const o = /* @__PURE__ */ new Map(), a = {}, m = {};
134
+ return se.forEach((d) => {
135
+ m[d] = (f, c, n) => {
128
136
  let r = !1;
129
- Se(t, o, l, m, c, (S) => {
137
+ Se(t, o, a, d, f, (L) => {
130
138
  if (!r) {
131
139
  r = !0;
132
140
  try {
133
- d(S);
134
- } catch (x) {
135
- console.error("[BuiltinTools] callback failed", x);
141
+ c(L);
142
+ } catch (I) {
143
+ console.error("[BuiltinTools] callback failed", I);
136
144
  }
137
145
  }
138
146
  }, h(s({}, n), {
@@ -140,97 +148,97 @@ function Ue({
140
148
  }));
141
149
  };
142
150
  }), {
143
- [e]: u
151
+ [e]: m
144
152
  };
145
153
  }
146
- function Se(e, t, o, l, u, m, c) {
147
- return U(this, null, function* () {
148
- var N, F, M, A, q;
149
- const d = {
150
- requestId: c.requestId || Y(),
151
- applicationId: c.applicationId || e.applicationId,
152
- sessionId: c.sessionId || "",
153
- pluginCode: c.pluginCode,
154
- functionCode: l,
155
- signal: c.signal
154
+ function Se(e, t, o, a, m, d, f) {
155
+ return D(this, null, function* () {
156
+ var N, R, M, F, A;
157
+ const c = {
158
+ requestId: f.requestId || Y(),
159
+ applicationId: f.applicationId || e.applicationId,
160
+ sessionId: f.sessionId || "",
161
+ pluginCode: f.pluginCode,
162
+ functionCode: a,
163
+ signal: f.signal
156
164
  }, n = {
157
- requestId: d.requestId,
158
- sessionId: d.sessionId,
159
- functionCode: l
165
+ requestId: c.requestId,
166
+ sessionId: c.sessionId,
167
+ functionCode: a
160
168
  }, r = new AbortController();
161
169
  let p = !1;
162
- const S = setTimeout(() => {
170
+ const L = setTimeout(() => {
163
171
  p = !0, r.abort();
164
- }, e.limits.toolTimeoutMs), x = () => r.abort();
165
- (N = d.signal) == null || N.addEventListener("abort", x, {
172
+ }, e.limits.toolTimeoutMs), I = () => r.abort();
173
+ (N = c.signal) == null || N.addEventListener("abort", I, {
166
174
  once: !0
167
- }), (F = d.signal) != null && F.aborted && r.abort();
168
- let b = null, y = null, I;
169
- const R = Date.now();
175
+ }), (R = c.signal) != null && R.aborted && r.abort();
176
+ let b = null, y = null, x;
177
+ const S = Date.now();
170
178
  try {
171
- const O = pe(u), i = ne(O, le[l].parameters);
172
- if (typeof i.path == "string" && (n.path = i.path), T.log("start", s(s({}, n), Oe(i))), yield e.ready, r.signal.aborted)
173
- throw w();
179
+ const O = Ie(m), i = re(O, ae[a].parameters);
180
+ if (typeof i.path == "string" && (n.path = i.path), w.log("start", s(s({}, n), Ee(i))), yield e.ready, r.signal.aborted)
181
+ throw T();
174
182
  const _ = e.adapter;
175
183
  if (!_)
176
- throw te();
184
+ throw oe();
177
185
  if (b = e.acquireSlot(), !b)
178
- throw new f(a.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
179
- if (H.has(l) && (y = e.acquireCommand(), !y))
180
- throw new f(a.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
181
- I = e.track(r), e.emit("tool:start", s({}, n));
182
- const v = d.sessionId || "default";
186
+ throw new u(l.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
187
+ if (j.has(a) && (y = e.acquireCommand(), !y))
188
+ throw new u(l.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
189
+ x = e.track(r), e.emit("tool:start", s({}, n));
190
+ const v = c.sessionId || "default";
183
191
  let g = t.get(v);
184
192
  g || (g = {
185
- cwd: se
193
+ cwd: le
186
194
  }, t.set(v, g));
187
- const $ = we(e, _, o), j = g.cwd, J = {
195
+ const V = pe(e, _, o), $ = g.cwd, J = {
188
196
  adapter: _,
189
- runner: $,
197
+ runner: V,
190
198
  signal: r.signal,
191
199
  timeoutMs: e.limits.toolTimeoutMs,
192
200
  shellCwd: g
193
- }, L = yield Promise.race([Te[l](i, J), Ie(r.signal)]), B = {
194
- code: a.Ok,
201
+ }, E = yield Promise.race([Te[a](i, J), Oe(r.signal)]), q = {
202
+ code: l.Ok,
195
203
  message: "ok",
196
- data: L.data
204
+ data: E.data
197
205
  };
198
- L.truncated && (B.truncated = !0);
199
- const z = Date.now() - R, C = L.data.exitCode;
200
- T.log("finish", s(s(s(h(s({}, n), {
201
- elapsedMs: z,
202
- code: a.Ok
203
- }), L.truncated ? {
206
+ E.truncated && (q.truncated = !0);
207
+ const W = Date.now() - S, B = E.data.exitCode;
208
+ w.log("finish", s(s(s(h(s({}, n), {
209
+ elapsedMs: W,
210
+ code: l.Ok
211
+ }), E.truncated ? {
204
212
  truncated: !0
205
- } : {}), typeof C == "number" ? {
206
- exitCode: C
207
- } : {}), l === "shell" ? {
213
+ } : {}), typeof B == "number" ? {
214
+ exitCode: B
215
+ } : {}), a === "shell" ? {
208
216
  cwd: g.cwd,
209
- cwdChanged: g.cwd !== j
217
+ cwdChanged: g.cwd !== $
210
218
  } : {})), e.emit("tool:finish", h(s({}, n), {
211
- code: a.Ok
212
- })), H.has(l) && e.notifyFilesChanged(), m(B);
219
+ code: l.Ok
220
+ })), j.has(a) && e.notifyFilesChanged(), d(q);
213
221
  } catch (O) {
214
- let i = (M = xe(O)) != null ? M : oe(O);
215
- p ? i = new f(a.Timeout, "操作超时,已中止。") : r.signal.aborted && i.code !== a.Cancelled && (i = w());
216
- const _ = Date.now() - R;
217
- i.code === a.Cancelled ? (T.log("cancelled", h(s({}, n), {
222
+ let i = (M = xe(O)) != null ? M : ne(O);
223
+ p ? i = new u(l.Timeout, "操作超时,已中止。") : r.signal.aborted && i.code !== l.Cancelled && (i = T());
224
+ const _ = Date.now() - S;
225
+ i.code === l.Cancelled ? (w.log("cancelled", h(s({}, n), {
218
226
  elapsedMs: _,
219
227
  timedOut: p
220
- })), e.emit("tool:cancelled", s({}, n))) : (T.error("error", h(s({}, n), {
228
+ })), e.emit("tool:cancelled", s({}, n))) : (w.error("error", h(s({}, n), {
221
229
  elapsedMs: _,
222
230
  code: i.code,
223
- message: V(i.message, 300)
231
+ message: H(i.message, 300)
224
232
  })), e.emit("tool:error", h(s({}, n), {
225
233
  code: i.code,
226
234
  message: i.message,
227
- reason: (A = i.data) == null ? void 0 : A.reason
228
- }))), m(Le(i));
235
+ reason: (F = i.data) == null ? void 0 : F.reason
236
+ }))), d(Le(i));
229
237
  } finally {
230
- clearTimeout(S), (q = d.signal) == null || q.removeEventListener("abort", x), b == null || b(), y == null || y(), I == null || I();
238
+ clearTimeout(L), (A = c.signal) == null || A.removeEventListener("abort", I), b == null || b(), y == null || y(), x == null || x();
231
239
  }
232
240
  });
233
241
  }
234
242
  export {
235
- Ue as createBuiltinToolsPlugin
243
+ He as createBuiltinToolsPlugin
236
244
  };