@glodon-aiot/bot-client-sdk 3.26.0-alpha.21 → 3.26.0-alpha.24

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.
@@ -2,36 +2,36 @@ var K = Object.defineProperty, X = Object.defineProperties;
2
2
  var Q = Object.getOwnPropertyDescriptors;
3
3
  var C = Object.getOwnPropertySymbols;
4
4
  var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
5
- var D = (e, t, o) => t in e ? K(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, s = (e, t) => {
6
- for (var o in t || (t = {}))
7
- Y.call(t, o) && D(e, o, t[o]);
5
+ var D = (e, t, n) => t in e ? K(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, s = (e, t) => {
6
+ for (var n in t || (t = {}))
7
+ Y.call(t, n) && D(e, n, t[n]);
8
8
  if (C)
9
- for (var o of C(t))
10
- Z.call(t, o) && D(e, o, t[o]);
9
+ for (var n of C(t))
10
+ Z.call(t, n) && D(e, n, t[n]);
11
11
  return e;
12
12
  }, _ = (e, t) => X(e, Q(t));
13
- var U = (e, t, o) => new Promise((a, m) => {
14
- var d = (n) => {
13
+ var U = (e, t, n) => new Promise((a, m) => {
14
+ var d = (o) => {
15
15
  try {
16
- c(o.next(n));
16
+ c(n.next(o));
17
17
  } catch (r) {
18
18
  m(r);
19
19
  }
20
- }, f = (n) => {
20
+ }, f = (o) => {
21
21
  try {
22
- c(o.throw(n));
22
+ c(n.throw(o));
23
23
  } catch (r) {
24
24
  m(r);
25
25
  }
26
- }, c = (n) => n.done ? a(n.value) : Promise.resolve(n.value).then(d, f);
27
- c((o = o.apply(e, t)).next());
26
+ }, c = (o) => o.done ? a(o.value) : Promise.resolve(o.value).then(d, f);
27
+ c((n = n.apply(e, t)).next());
28
28
  });
29
29
  import { v4 as k } from "uuid";
30
30
  import ee from "../Logger.mjs";
31
31
  import { HostBridgeAdapter as H } from "../localFiles/adapters/HostBridgeAdapter.mjs";
32
32
  import { domError as V } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
33
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";
34
+ import { cancelledError as T, workspaceNotGranted as ne, ToolError as u, ToolCode as l, toToolError as oe } from "../localFiles/errors.mjs";
35
35
  import { validateToolInput as re } from "../localFiles/validate.mjs";
36
36
  import { BrowserCommandRunner as ie } from "./browserRuntime/BrowserCommandRunner.mjs";
37
37
  import { withOutputLimit as L } from "./command.mjs";
@@ -51,14 +51,14 @@ const Te = {
51
51
  read_skill_resource: ye,
52
52
  run_skill_script: xe
53
53
  }, x = new ee("[BuiltinTools] "), j = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
54
- function we(e, t, o) {
54
+ function we(e, t, n) {
55
55
  var a, m;
56
56
  if (e.commandRunner)
57
57
  return L(e.commandRunner);
58
58
  if (t instanceof H) {
59
59
  if (t.protocolMismatch) {
60
60
  const d = `${(a = t.sandboxVersion) != null ? a : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
61
- o.rejectedSandbox !== d && (o.rejectedSandbox = d, x.error("sandbox-protocol", {
61
+ n.rejectedSandbox !== d && (n.rejectedSandbox = d, x.error("sandbox-protocol", {
62
62
  sandboxVersion: t.sandboxVersion,
63
63
  sandboxProtocol: t.sandboxProtocol,
64
64
  supported: te
@@ -75,25 +75,25 @@ function we(e, t, o) {
75
75
  };
76
76
  }
77
77
  if (e.browserRuntime.enabled)
78
- return (o.adapter !== t || !o.runner) && (o.adapter = t, o.runner = L(new ie({
78
+ return (n.adapter !== t || !n.runner) && (n.adapter = t, n.runner = L(new ie({
79
79
  adapter: t,
80
80
  sensitive: e.sensitive,
81
81
  moduleURL: e.browserRuntime.bashModuleURL,
82
82
  pyodideIndexURL: e.browserRuntime.pyodideIndexURL
83
- }))), o.runner;
83
+ }))), n.runner;
84
84
  }
85
85
  function Ie(e, t) {
86
86
  if (e.commandRunner)
87
87
  return L(e.commandRunner);
88
88
  if (t instanceof H) {
89
89
  if (!t.canExec) {
90
- const o = t.unavailableMessage();
90
+ const n = t.unavailableMessage();
91
91
  return {
92
- exec: () => Promise.reject(V("NotAllowedError", o))
92
+ exec: () => Promise.reject(V("NotAllowedError", n))
93
93
  };
94
94
  }
95
95
  return {
96
- exec: (o) => t.exec(o)
96
+ exec: (n) => t.exec(n)
97
97
  };
98
98
  }
99
99
  }
@@ -107,19 +107,19 @@ function Ee(e) {
107
107
  }
108
108
  }
109
109
  function Oe(e) {
110
- const t = e instanceof DOMException ? e.name : "", o = e instanceof Error ? e.message : "";
110
+ const t = e instanceof DOMException ? e.name : "", n = e instanceof Error ? e.message : "";
111
111
  if (t === "NotFoundError")
112
112
  return new u(l.NotFound, "脚本或目录不存在。");
113
113
  if (t === "SecurityError")
114
114
  return new u(l.Forbidden, "命令路径不在工作区内。");
115
115
  if (t === "AbortError")
116
- return o.includes("超时") ? new u(l.Timeout, "命令运行超时,已中止。") : o.includes("已有") ? new u(l.TooManyRequests, "已有一个命令在运行。") : T();
116
+ return n.includes("超时") ? new u(l.Timeout, "命令运行超时,已中止。") : n.includes("已有") || n.includes("上限") ? new u(l.TooManyRequests, n) : T();
117
117
  if (t === "NotAllowedError")
118
- return o.startsWith("沙箱") ? new u(l.NotImplemented, o) : new u(l.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
118
+ return n.startsWith("沙箱") ? new u(l.NotImplemented, n) : new u(l.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
119
119
  }
120
120
  function Re(e) {
121
- return new Promise((t, o) => {
122
- e.aborted && o(T()), e.addEventListener("abort", () => o(T()), {
121
+ return new Promise((t, n) => {
122
+ e.aborted && n(T()), e.addEventListener("abort", () => n(T()), {
123
123
  once: !0
124
124
  });
125
125
  });
@@ -129,8 +129,8 @@ function $(e, t = 160) {
129
129
  }
130
130
  function pe(e) {
131
131
  const t = {};
132
- for (const o of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
133
- typeof e[o] == "string" && (t[o] = e[o]);
132
+ for (const n of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
133
+ typeof e[n] == "string" && (t[n] = e[n]);
134
134
  return typeof e.command == "string" && (t.command = $(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;
135
135
  }
136
136
  function Le(e) {
@@ -145,11 +145,11 @@ function Ve({
145
145
  pluginCode: e,
146
146
  workspace: t
147
147
  }) {
148
- const o = /* @__PURE__ */ new Map(), a = {}, m = {};
148
+ const n = /* @__PURE__ */ new Map(), a = {}, m = {};
149
149
  return se.forEach((d) => {
150
- m[d] = (f, c, n) => {
150
+ m[d] = (f, c, o) => {
151
151
  let r = !1;
152
- Se(t, o, a, d, f, (p) => {
152
+ Se(t, n, a, d, f, (p) => {
153
153
  if (!r) {
154
154
  r = !0;
155
155
  try {
@@ -158,7 +158,7 @@ function Ve({
158
158
  console.error("[BuiltinTools] callback failed", I);
159
159
  }
160
160
  }
161
- }, _(s({}, n), {
161
+ }, _(s({}, o), {
162
162
  pluginCode: e
163
163
  }));
164
164
  };
@@ -166,7 +166,7 @@ function Ve({
166
166
  [e]: m
167
167
  };
168
168
  }
169
- function Se(e, t, o, a, m, d, f) {
169
+ function Se(e, t, n, a, m, d, f) {
170
170
  return U(this, null, function* () {
171
171
  var N, M, F, A, v;
172
172
  const c = {
@@ -176,7 +176,7 @@ function Se(e, t, o, a, m, d, f) {
176
176
  pluginCode: f.pluginCode,
177
177
  functionCode: a,
178
178
  signal: f.signal
179
- }, n = {
179
+ }, o = {
180
180
  requestId: c.requestId,
181
181
  sessionId: c.sessionId,
182
182
  functionCode: a
@@ -192,22 +192,23 @@ function Se(e, t, o, a, m, d, f) {
192
192
  const S = Date.now();
193
193
  try {
194
194
  const O = Ee(m), i = re(O, ae[a].parameters);
195
- if (typeof i.path == "string" && (n.path = i.path), x.log("start", s(s({}, n), pe(i))), yield e.ready, r.signal.aborted)
195
+ if (typeof i.path == "string" && (o.path = i.path), x.log("start", s(s({}, o), pe(i))), yield e.ready, r.signal.aborted)
196
196
  throw T();
197
197
  const g = e.adapter;
198
198
  if (!g)
199
- throw oe();
200
- if (b = e.acquireSlot(), !b)
199
+ throw ne();
200
+ if (j.has(a)) {
201
+ if (y = e.acquireCommand(), !y)
202
+ throw new u(l.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
203
+ } else if (b = e.acquireSlot(), !b)
201
204
  throw new u(l.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
202
- if (j.has(a) && (y = e.acquireCommand(), !y))
203
- throw new u(l.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
204
- E = e.track(r), e.emit("tool:start", s({}, n));
205
+ E = e.track(r), e.emit("tool:start", s({}, o));
205
206
  const q = c.sessionId || "default";
206
207
  let h = t.get(q);
207
208
  h || (h = {
208
209
  cwd: le
209
210
  }, t.set(q, h));
210
- const J = we(e, g, o), W = h.cwd, z = {
211
+ const J = we(e, g, n), W = h.cwd, z = {
211
212
  adapter: g,
212
213
  runner: J,
213
214
  signal: r.signal,
@@ -222,7 +223,7 @@ function Se(e, t, o, a, m, d, f) {
222
223
  };
223
224
  R.truncated && (B.truncated = !0);
224
225
  const G = Date.now() - S, P = R.data.exitCode;
225
- x.log("finish", s(s(s(_(s({}, n), {
226
+ x.log("finish", s(s(s(_(s({}, o), {
226
227
  elapsedMs: G,
227
228
  code: l.Ok
228
229
  }), R.truncated ? {
@@ -232,21 +233,21 @@ function Se(e, t, o, a, m, d, f) {
232
233
  } : {}), a === "shell" ? {
233
234
  cwd: h.cwd,
234
235
  cwdChanged: h.cwd !== W
235
- } : {})), e.emit("tool:finish", _(s({}, n), {
236
+ } : {})), e.emit("tool:finish", _(s({}, o), {
236
237
  code: l.Ok
237
238
  })), j.has(a) && e.notifyFilesChanged(), d(B);
238
239
  } catch (O) {
239
- let i = (F = Oe(O)) != null ? F : ne(O);
240
+ let i = (F = Oe(O)) != null ? F : oe(O);
240
241
  w ? i = new u(l.Timeout, "操作超时,已中止。") : r.signal.aborted && i.code !== l.Cancelled && (i = T());
241
242
  const g = Date.now() - S;
242
- i.code === l.Cancelled ? (x.log("cancelled", _(s({}, n), {
243
+ i.code === l.Cancelled ? (x.log("cancelled", _(s({}, o), {
243
244
  elapsedMs: g,
244
245
  timedOut: w
245
- })), e.emit("tool:cancelled", s({}, n))) : (x.error("error", _(s({}, n), {
246
+ })), e.emit("tool:cancelled", s({}, o))) : (x.error("error", _(s({}, o), {
246
247
  elapsedMs: g,
247
248
  code: i.code,
248
249
  message: $(i.message, 300)
249
- })), e.emit("tool:error", _(s({}, n), {
250
+ })), e.emit("tool:error", _(s({}, o), {
250
251
  code: i.code,
251
252
  message: i.message,
252
253
  reason: (A = i.data) == null ? void 0 : A.reason
@@ -1,13 +1,13 @@
1
- import { MAX_COMMAND_CHARS as s, MAX_WRITE_BYTES as n, BUILTIN_FUNCTION_CODES as r } from "./constants.mjs";
1
+ import { MAX_COMMAND_CHARS as o, MAX_WRITE_BYTES as r, BUILTIN_FUNCTION_CODES as p } from "./constants.mjs";
2
2
  const e = (i) => ({
3
3
  type: "string",
4
4
  minLength: 1,
5
5
  description: i
6
- }), t = "必填。工作区内绝对路径,以 / 开头,例如 /说明.md。不要使用 /input、/output、/uploads、/tmp,也不要新建这些目录。", o = {
6
+ }), n = "脚本能否联网由运行环境决定;被宿主网络策略拒绝的地址会在结果里列出。", t = "必填。工作区内绝对路径,以 / 开头,例如 /说明.md。不要使用 /input、/output、/uploads、/tmp,也不要新建这些目录。", a = {
7
7
  shell: {
8
8
  functionCode: "shell",
9
9
  name: "执行命令",
10
- description: "在当前会话工作区中执行一条 shell 命令并返回标准输出。每次调用都是新的 shell,只保留上次停留的目录;环境变量不会保留,需要时在同一条命令里设置。当前目录是工作区根目录。用相对路径,或以 / 开头表示工作区内已有的路径,例如 notes/a.md、/说明.md。不要使用或新建 input、output、uploads、tmp。/dev、/usr、/bin 仍是系统路径。写进脚本文件里的路径要用相对路径(见 run_file)。超过 20000 字的脚本请用 write_file 写到工作区文件后再调用 run_file;读取文件正文或结构摘要请用 read_file 的 start_line 和 end_line,不要用 cat、sed 或 head 把大文件正文打到标准输出。",
10
+ description: `在当前会话工作区中执行一条 shell 命令并返回标准输出。每次调用都是新的 shell,只保留上次停留的目录;环境变量不会保留,需要时在同一条命令里设置。当前目录是工作区根目录。用相对路径,或以 / 开头表示工作区内已有的路径,例如 notes/a.md、/说明.md。不要使用或新建 input、output、uploads、tmp。/dev、/usr、/bin 仍是系统路径。写进脚本文件里的路径要用相对路径(见 run_file)。超过 20000 字的脚本请用 write_file 写到工作区文件后再调用 run_file;读取文件正文或结构摘要请用 read_file 的 start_line 和 end_line,不要用 cat、sed 或 head 把大文件正文打到标准输出。${n}`,
11
11
  parameters: {
12
12
  type: "object",
13
13
  required: ["command"],
@@ -15,7 +15,7 @@ const e = (i) => ({
15
15
  command: {
16
16
  type: "string",
17
17
  minLength: 1,
18
- maxLength: s,
18
+ maxLength: o,
19
19
  description: "必填。一条不超过 20000 字的 shell 命令。当前目录已是工作区根目录。可以包含短的 python 或 heredoc。读取文件正文请改用 read_file。"
20
20
  }
21
21
  }
@@ -46,7 +46,7 @@ const e = (i) => ({
46
46
  write_file: {
47
47
  functionCode: "write_file",
48
48
  name: "写入文件",
49
- description: `把文本写入工作区内文件,path 为工作区内绝对路径,文件已存在时覆盖。单次覆盖写入按 UTF-8 字节计,默认不超过 ${n} 字节。超限时先写一段,再用 edit_file 修改,或用 append_file 追加下一段。SVG 和整页 HTML 由工作区里的脚本生成,不要直接放进 content。`,
49
+ description: `把文本写入工作区内文件,path 为工作区内绝对路径,文件已存在时覆盖。单次覆盖写入按 UTF-8 字节计,默认不超过 ${r} 字节。超限时先写一段,再用 edit_file 修改,或用 append_file 追加下一段。SVG 和整页 HTML 由工作区里的脚本生成,不要直接放进 content。`,
50
50
  parameters: {
51
51
  type: "object",
52
52
  required: ["path", "content"],
@@ -54,7 +54,7 @@ const e = (i) => ({
54
54
  path: e(t),
55
55
  content: {
56
56
  type: "string",
57
- description: `必填。覆盖写入的文本,UTF-8 不超过 ${n} 字节。不要放入 SVG 或整页 HTML。`
57
+ description: `必填。覆盖写入的文本,UTF-8 不超过 ${r} 字节。不要放入 SVG 或整页 HTML。`
58
58
  }
59
59
  }
60
60
  }
@@ -78,7 +78,7 @@ const e = (i) => ({
78
78
  run_file: {
79
79
  functionCode: "run_file",
80
80
  name: "执行文件",
81
- description: "执行工作区里已经存在的 .py、.sh 或 .js 脚本文件。生成 SVG、HTML、JSON 等产物时优先使用:先用 write_file 写脚本,脚本自行读取工作区文件并写出产物,再调用本工具。脚本运行时当前目录是工作区根目录,脚本里访问工作区文件要写相对路径,例如 data.json、notes/a.py。不要使用或新建 input、output、uploads、tmp。需要查看文件正文时用 read_file,不要把整份文件打印到标准输出。",
81
+ description: `执行工作区里已经存在的 .py、.sh 或 .js 脚本文件。生成 SVG、HTML、JSON 等产物时优先使用:先用 write_file 写脚本,脚本自行读取工作区文件并写出产物,再调用本工具。脚本运行时当前目录是工作区根目录,脚本里访问工作区文件要写相对路径,例如 data.json、notes/a.py。不要使用或新建 input、output、uploads、tmp。需要查看文件正文时用 read_file,不要把整份文件打印到标准输出。${n}`,
82
82
  parameters: {
83
83
  type: "object",
84
84
  required: ["path"],
@@ -182,7 +182,7 @@ const e = (i) => ({
182
182
  run_skill_script: {
183
183
  functionCode: "run_skill_script",
184
184
  name: "运行技能脚本",
185
- description: "执行平台技能包内的脚本并返回输出。当前目录是工作区根目录,参数里的用户文件按相对工作区根目录传,例如 docs/a.docx。技能自己的资源按脚本文件所在目录查找,不在工程的 skills 目录里。",
185
+ description: `执行平台技能包内的脚本并返回输出。当前目录是工作区根目录,参数里的用户文件按相对工作区根目录传,例如 docs/a.docx。技能自己的资源按脚本文件所在目录查找,不在工程的 skills 目录里。${n}`,
186
186
  parameters: {
187
187
  type: "object",
188
188
  required: ["skill_name", "script_name"],
@@ -208,9 +208,9 @@ const e = (i) => ({
208
208
  }
209
209
  }
210
210
  }
211
- }, p = Object.keys(o);
212
- if (p.length !== r.length || r.some((i) => !p.includes(i)))
211
+ }, s = Object.keys(a);
212
+ if (s.length !== p.length || p.some((i) => !s.includes(i)))
213
213
  throw new Error("BUILTIN_TOOL_SCHEMAS 与 BUILTIN_FUNCTION_CODES 不一致");
214
214
  export {
215
- o as BUILTIN_TOOL_SCHEMAS
215
+ a as BUILTIN_TOOL_SCHEMAS
216
216
  };