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

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 (73) hide show
  1. package/README.md +271 -225
  2. package/dist/es/AgentSession.mjs +301 -228
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +56 -67
  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/PayloadTypes.mjs +13 -2
  9. package/dist/es/Session.mjs +405 -312
  10. package/dist/es/api/index.mjs +31 -30
  11. package/dist/es/builtinTools/constants.mjs +12 -5
  12. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
  13. package/dist/es/builtinTools/paths.mjs +34 -27
  14. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  15. package/dist/es/builtinTools/schemas.mjs +63 -18
  16. package/dist/es/builtinTools/tools.mjs +368 -244
  17. package/dist/es/index.mjs +73 -67
  18. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  19. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
  20. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
  21. package/dist/es/localFiles/constants.mjs +24 -28
  22. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  23. package/dist/es/localFiles/errors.mjs +44 -35
  24. package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
  25. package/dist/es/localFiles/host/protocol.mjs +27 -14
  26. package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
  27. package/dist/es/localFiles/preview.mjs +33 -0
  28. package/dist/es/localFiles/schemas.mjs +22 -53
  29. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
  30. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  31. package/dist/es/localMcp/client.mjs +234 -0
  32. package/dist/es/localMcp/endpoints.mjs +94 -0
  33. package/dist/es/localMcp/register.mjs +207 -0
  34. package/dist/es/localMcp/registry.mjs +43 -0
  35. package/dist/es/package.json.mjs +34 -54
  36. package/dist/es/sessionUpload.mjs +49 -0
  37. package/dist/es/utils.mjs +24 -11
  38. package/dist/lib/index.js +48 -40
  39. package/dist/src/AgentSession.d.ts +13 -0
  40. package/dist/src/BotClient.d.ts +13 -1
  41. package/dist/src/Config.d.ts +6 -7
  42. package/dist/src/EventBus.d.ts +3 -0
  43. package/dist/src/Logger.d.ts +15 -8
  44. package/dist/src/PayloadTypes.d.ts +20 -0
  45. package/dist/src/Session.d.ts +24 -3
  46. package/dist/src/api/index.d.ts +2 -2
  47. package/dist/src/builtinTools/command.d.ts +7 -0
  48. package/dist/src/builtinTools/constants.d.ts +10 -2
  49. package/dist/src/builtinTools/paths.d.ts +3 -2
  50. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  51. package/dist/src/builtinTools/tools.d.ts +13 -0
  52. package/dist/src/constant.d.ts +1 -1
  53. package/dist/src/index.d.ts +6 -3
  54. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  55. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
  56. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
  57. package/dist/src/localFiles/constants.d.ts +4 -13
  58. package/dist/src/localFiles/errors.d.ts +1 -1
  59. package/dist/src/localFiles/host/protocol.d.ts +14 -3
  60. package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
  61. package/dist/src/localFiles/index.d.ts +9 -5
  62. package/dist/src/localFiles/preview.d.ts +2 -0
  63. package/dist/src/localFiles/schemas.d.ts +0 -2
  64. package/dist/src/localFiles/types.d.ts +2 -22
  65. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
  66. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  67. package/dist/src/localMcp/client.d.ts +15 -0
  68. package/dist/src/localMcp/endpoints.d.ts +19 -0
  69. package/dist/src/localMcp/register.d.ts +34 -0
  70. package/dist/src/localMcp/registry.d.ts +27 -0
  71. package/dist/src/sessionUpload.d.ts +14 -0
  72. package/dist/src/utils.d.ts +6 -0
  73. package/package.json +4 -24
@@ -2,49 +2,50 @@ var g = Object.defineProperty, d = Object.defineProperties;
2
2
  var E = Object.getOwnPropertyDescriptors;
3
3
  var u = Object.getOwnPropertySymbols;
4
4
  var x = Object.prototype.hasOwnProperty, v = Object.prototype.propertyIsEnumerable;
5
- var f = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, m = (t, e) => {
6
- for (var r in e || (e = {}))
7
- x.call(e, r) && f(t, r, e[r]);
5
+ var f = (r, t, e) => t in r ? g(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, m = (r, t) => {
6
+ for (var e in t || (t = {}))
7
+ x.call(t, e) && f(r, e, t[e]);
8
8
  if (u)
9
- for (var r of u(e))
10
- v.call(e, r) && f(t, r, e[r]);
11
- return t;
12
- }, h = (t, e) => d(t, E(e));
9
+ for (var e of u(t))
10
+ v.call(t, e) && f(r, e, t[e]);
11
+ return r;
12
+ }, h = (r, t) => d(r, E(t));
13
13
  import I from "axios";
14
- import { isExpired as $ } from "../utils.mjs";
15
- import { CVForceApi as w, AIShopApi as z } from "@glodon-aiot/apis";
16
- function b(t, e, r) {
17
- return new w(A(t, "/data/v1", e, r), S(r));
14
+ import { isExpired as k } from "../utils.mjs";
15
+ import { CVForceApi as $, AIShopApi as w } from "@glodon-aiot/apis";
16
+ function V(r, t, e) {
17
+ return new $(A(r, "/data/v1", t, e), S(e));
18
18
  }
19
- function B(t, e, r) {
20
- return new z(A(t, "/aishop", e, r), S(r));
19
+ function b(r, t, e) {
20
+ return new w(A(r, "/aishop", t, e), S(e));
21
21
  }
22
- function A(t, e, r, o) {
23
- const i = (n) => {
24
- var s;
25
- return r && ($(r) && o(403, "aiotToken is timeout"), n.headers = (s = n.headers) != null ? s : {}, n.headers = h(m({}, n.headers), {
26
- Authorization: r ? `Bearer ${r}` : ""
22
+ function A(r, t, e, o) {
23
+ const s = (n) => {
24
+ var a;
25
+ const i = e();
26
+ return i && (k(i) && o(403, "aiotToken is timeout"), n.headers = (a = n.headers) != null ? a : {}, n.headers = h(m({}, n.headers), {
27
+ Authorization: i ? `Bearer ${i}` : ""
27
28
  })), n;
28
29
  };
29
- function a(n, s = !0) {
30
- const c = `${t}${n}`, p = I.create({
31
- baseURL: c
30
+ function p(n, i = !0) {
31
+ const a = `${r}${n}`, c = I.create({
32
+ baseURL: a
32
33
  });
33
- return s && p.interceptors.request.use(i), p;
34
+ return i && c.interceptors.request.use(s), c;
34
35
  }
35
- return a(e);
36
+ return p(t);
36
37
  }
37
- function S(t) {
38
+ function S(r) {
38
39
  return {
39
- onHttpStatusError: (o, i) => {
40
- o === 401 && t(o, "aiotToken is invalid");
40
+ onHttpStatusError: (o, s) => {
41
+ o === 401 && r(o, "aiotToken is invalid");
41
42
  },
42
- onAppStatusError: (o, i) => {
43
- o !== 10001 && o !== 10215 && t(o, i);
43
+ onAppStatusError: (o, s) => {
44
+ o !== 10001 && o !== 10215 && r(o, s);
44
45
  }
45
46
  };
46
47
  }
47
48
  export {
48
- B as getAIShopService,
49
- b as getCVForceService
49
+ b as getAIShopService,
50
+ V as getCVForceService
50
51
  };
@@ -1,10 +1,17 @@
1
- const _ = ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "run_skill_script"], e = 81920, s = 81920, l = 2e4, i = ".", n = "/workspace", o = [".py", ".sh", ".js"];
1
+ const s = ["shell", "read_file", "write_file", "append_file", "run_file", "edit_file", "grep", "find", "load_skill", "read_skill_resource", "list_skill_files", "grep_skill", "run_skill_script"], _ = 81920, e = 81920, l = 2e4, i = ".", n = "/workspace", o = {
2
+ ".py": "python3",
3
+ ".sh": "sh",
4
+ ".bash": "sh",
5
+ ".js": "node",
6
+ ".mjs": "node",
7
+ ".cjs": "node"
8
+ };
2
9
  export {
3
- _ as BUILTIN_FUNCTION_CODES,
10
+ s as BUILTIN_FUNCTION_CODES,
4
11
  l as MAX_COMMAND_CHARS,
5
- e as MAX_READ_BYTES,
6
- s as MAX_WRITE_BYTES,
7
- o as RUNNABLE_EXTENSIONS,
12
+ _ as MAX_READ_BYTES,
13
+ e as MAX_WRITE_BYTES,
14
+ o as SCRIPT_PROGRAMS,
8
15
  i as SHELL_CWD,
9
16
  n as WORKSPACE_MOUNT
10
17
  };
@@ -1,73 +1,75 @@
1
- var z = Object.defineProperty, G = Object.defineProperties;
2
- var K = Object.getOwnPropertyDescriptors;
3
- var P = Object.getOwnPropertySymbols;
4
- var X = Object.prototype.hasOwnProperty, Q = Object.prototype.propertyIsEnumerable;
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
- for (var o in t || (t = {}))
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]);
1
+ var W = Object.defineProperty, X = Object.defineProperties;
2
+ var Q = Object.getOwnPropertyDescriptors;
3
+ var C = Object.getOwnPropertySymbols;
4
+ var Y = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
5
+ var j = (e, t, n) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, l = (e, t) => {
6
+ for (var n in t || (t = {}))
7
+ Y.call(t, n) && j(e, n, t[n]);
8
+ if (C)
9
+ for (var n of C(t))
10
+ Z.call(t, n) && j(e, n, t[n]);
11
11
  return e;
12
- }, h = (e, t) => G(e, K(t));
13
- var D = (e, t, o) => new Promise((a, m) => {
14
- var d = (n) => {
12
+ }, _ = (e, t) => X(e, Q(t));
13
+ var H = (e, t, n) => new Promise((o, m) => {
14
+ var d = (r) => {
15
15
  try {
16
- c(o.next(n));
17
- } catch (r) {
18
- m(r);
16
+ c(n.next(r));
17
+ } catch (i) {
18
+ m(i);
19
19
  }
20
- }, f = (n) => {
20
+ }, f = (r) => {
21
21
  try {
22
- c(o.throw(n));
23
- } catch (r) {
24
- m(r);
22
+ c(n.throw(r));
23
+ } catch (i) {
24
+ m(i);
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 = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(d, f);
27
+ c((n = n.apply(e, t)).next());
28
28
  });
29
- import { v4 as Y } from "uuid";
30
- import Z from "../Logger.mjs";
31
- import { HostBridgeAdapter as k } from "../localFiles/adapters/HostBridgeAdapter.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";
41
- const Te = {
42
- shell: de,
43
- read_file: ce,
44
- write_file: me,
45
- append_file: ue,
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;
29
+ import { v4 as ee } from "uuid";
30
+ import te from "../Logger.mjs";
31
+ import { HostBridgeAdapter as V } from "../localFiles/adapters/HostBridgeAdapter.mjs";
32
+ import { domError as $ } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
33
+ import { SANDBOX_PROTOCOL as ne } from "../localFiles/host/protocol.mjs";
34
+ import { cancelledError as w, workspaceNotGranted as oe, ToolError as u, ToolCode as a, toToolError as re } from "../localFiles/errors.mjs";
35
+ import { validateToolInput as ie } from "../localFiles/validate.mjs";
36
+ import { BrowserCommandRunner as se } from "./browserRuntime/BrowserCommandRunner.mjs";
37
+ import { withOutputLimit as L } from "./command.mjs";
38
+ import { BUILTIN_FUNCTION_CODES as le, SHELL_CWD as ae } from "./constants.mjs";
39
+ import { BUILTIN_TOOL_SCHEMAS as de } from "./schemas.mjs";
40
+ import { shell as ce, readFile as me, writeFile as ue, appendFile as fe, runFile as ge, editFile as he, grep as _e, find as be, loadSkill as ye, readSkillResource as xe, listSkillFiles as we, grepSkill as Te, runSkillScript as Ie } from "./tools.mjs";
41
+ const pe = {
42
+ shell: ce,
43
+ read_file: me,
44
+ write_file: ue,
45
+ append_file: fe,
46
+ run_file: ge,
47
+ edit_file: he,
48
+ grep: _e,
49
+ find: be,
50
+ load_skill: ye,
51
+ read_skill_resource: xe,
52
+ list_skill_files: we,
53
+ grep_skill: Te,
54
+ run_skill_script: Ie
55
+ }, b = new te("[BuiltinTools] "), S = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
56
+ function Ee(e, t, n) {
57
+ var o, m;
56
58
  if (e.commandRunner)
57
- return U(e.commandRunner);
58
- if (t instanceof k) {
59
+ return L(e.commandRunner);
60
+ if (t instanceof V) {
59
61
  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
+ const d = `${(o = t.sandboxVersion) != null ? o : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
63
+ n.rejectedSandbox !== d && (n.rejectedSandbox = d, b.error("sandbox-protocol", {
62
64
  sandboxVersion: t.sandboxVersion,
63
65
  sandboxProtocol: t.sandboxProtocol,
64
- supported: te
66
+ supported: ne
65
67
  }));
66
68
  }
67
69
  if (!t.canExec) {
68
70
  const d = t.unavailableMessage();
69
71
  return {
70
- exec: () => Promise.reject(ee("NotAllowedError", d))
72
+ exec: () => Promise.reject($("NotAllowedError", d))
71
73
  };
72
74
  }
73
75
  return {
@@ -75,75 +77,92 @@ function pe(e, t, o) {
75
77
  };
76
78
  }
77
79
  if (e.browserRuntime.enabled)
78
- return (o.adapter !== t || !o.runner) && (o.adapter = t, o.runner = U(new ie({
80
+ return (n.adapter !== t || !n.runner) && (n.adapter = t, n.runner = L(new se({
79
81
  adapter: t,
80
82
  sensitive: e.sensitive,
81
83
  moduleURL: e.browserRuntime.bashModuleURL,
82
84
  pyodideIndexURL: e.browserRuntime.pyodideIndexURL
83
- }))), o.runner;
85
+ }))), n.runner;
84
86
  }
85
- function Ie(e) {
87
+ function Oe(e, t) {
88
+ if (e.commandRunner)
89
+ return L(e.commandRunner);
90
+ if (t instanceof V) {
91
+ if (!t.canExec) {
92
+ const n = t.unavailableMessage();
93
+ return {
94
+ exec: () => Promise.reject($("NotAllowedError", n))
95
+ };
96
+ }
97
+ return {
98
+ exec: (n) => t.exec(n)
99
+ };
100
+ }
101
+ }
102
+ function Re(e) {
86
103
  if (typeof e != "string")
87
104
  return e;
88
105
  try {
89
106
  return JSON.parse(e);
90
107
  } catch (t) {
91
- throw new u(l.BadRequest, "参数不是合法的 JSON 对象。");
108
+ throw new u(a.BadRequest, "参数不是合法的 JSON 对象。");
92
109
  }
93
110
  }
94
- function xe(e) {
95
- const t = e instanceof DOMException ? e.name : "", o = e instanceof Error ? e.message : "";
111
+ function Se(e) {
112
+ const t = e instanceof DOMException ? e.name : "", n = e instanceof Error ? e.message : "";
96
113
  if (t === "NotFoundError")
97
- return new u(l.NotFound, "脚本或目录不存在。");
114
+ return new u(a.NotFound, "脚本或目录不存在。");
98
115
  if (t === "SecurityError")
99
- return new u(l.Forbidden, "命令路径不在工作区内。");
116
+ return new u(a.Forbidden, "命令路径不在工作区内。");
100
117
  if (t === "AbortError")
101
- return o.includes("超时") ? new u(l.Timeout, "命令运行超时,已中止。") : o.includes("已有") ? new u(l.TooManyRequests, "已有一个命令在运行。") : T();
102
- if (t === "NotAllowedError")
103
- return o.startsWith("沙箱") ? new u(l.NotImplemented, o) : new u(l.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
118
+ return n.includes("超时") ? new u(a.Timeout, "命令运行超时,已中止。") : n.includes("已有") || n.includes("上限") ? new u(a.TooManyRequests, n) : w();
119
+ if (t === "NotAllowedError") {
120
+ const o = n.trim();
121
+ return o && o !== "NotAllowedError" ? new u(a.NotImplemented, o) : new u(a.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
122
+ }
104
123
  }
105
- function Oe(e) {
106
- return new Promise((t, o) => {
107
- e.aborted && o(T()), e.addEventListener("abort", () => o(T()), {
124
+ function Le(e) {
125
+ return new Promise((t, n) => {
126
+ e.aborted && n(w()), e.addEventListener("abort", () => n(w()), {
108
127
  once: !0
109
128
  });
110
129
  });
111
130
  }
112
- function H(e, t = 160) {
131
+ function k(e, t = 160) {
113
132
  return e.length > t ? `${e.slice(0, t)}…` : e;
114
133
  }
115
- function Ee(e) {
134
+ function Ne(e) {
116
135
  const t = {};
117
- for (const o of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
118
- typeof e[o] == "string" && (t[o] = e[o]);
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;
136
+ for (const n of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
137
+ typeof e[n] == "string" && (t[n] = e[n]);
138
+ return typeof e.command == "string" && (t.command = k(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;
120
139
  }
121
- function Le(e) {
122
- return s({
140
+ function Me(e) {
141
+ return l({
123
142
  code: e.code,
124
143
  message: e.message
125
144
  }, e.data ? {
126
145
  data: e.data
127
146
  } : {});
128
147
  }
129
- function He({
148
+ function Je({
130
149
  pluginCode: e,
131
150
  workspace: t
132
151
  }) {
133
- const o = /* @__PURE__ */ new Map(), a = {}, m = {};
134
- return se.forEach((d) => {
135
- m[d] = (f, c, n) => {
136
- let r = !1;
137
- Se(t, o, a, d, f, (L) => {
138
- if (!r) {
139
- r = !0;
152
+ const n = /* @__PURE__ */ new Map(), o = {}, m = {};
153
+ return le.forEach((d) => {
154
+ m[d] = (f, c, r) => {
155
+ let i = !1;
156
+ Fe(t, n, o, d, f, (I) => {
157
+ if (!i) {
158
+ i = !0;
140
159
  try {
141
- c(L);
142
- } catch (I) {
143
- console.error("[BuiltinTools] callback failed", I);
160
+ c(I);
161
+ } catch (R) {
162
+ b.report("callback failed", R);
144
163
  }
145
164
  }
146
- }, h(s({}, n), {
165
+ }, _(l({}, r), {
147
166
  pluginCode: e
148
167
  }));
149
168
  };
@@ -151,94 +170,97 @@ function He({
151
170
  [e]: m
152
171
  };
153
172
  }
154
- function Se(e, t, o, a, m, d, f) {
155
- return D(this, null, function* () {
156
- var N, R, M, F, A;
173
+ function Fe(e, t, n, o, m, d, f) {
174
+ return H(this, null, function* () {
175
+ var F, A, v, q, P;
157
176
  const c = {
158
- requestId: f.requestId || Y(),
177
+ requestId: f.requestId || ee(),
159
178
  applicationId: f.applicationId || e.applicationId,
160
179
  sessionId: f.sessionId || "",
161
180
  pluginCode: f.pluginCode,
162
- functionCode: a,
181
+ functionCode: o,
163
182
  signal: f.signal
164
- }, n = {
183
+ }, r = {
165
184
  requestId: c.requestId,
166
185
  sessionId: c.sessionId,
167
- functionCode: a
168
- }, r = new AbortController();
169
- let p = !1;
170
- const L = setTimeout(() => {
171
- p = !0, r.abort();
172
- }, e.limits.toolTimeoutMs), I = () => r.abort();
173
- (N = c.signal) == null || N.addEventListener("abort", I, {
186
+ functionCode: o
187
+ }, i = new AbortController();
188
+ let T = !1;
189
+ const I = S.has(o) ? e.limits.commandTimeoutMs : e.limits.toolTimeoutMs, R = setTimeout(() => {
190
+ T = !0, i.abort();
191
+ }, I), N = () => i.abort();
192
+ (F = c.signal) == null || F.addEventListener("abort", N, {
174
193
  once: !0
175
- }), (R = c.signal) != null && R.aborted && r.abort();
176
- let b = null, y = null, x;
177
- const S = Date.now();
194
+ }), (A = c.signal) != null && A.aborted && i.abort();
195
+ let y = null, x = null, p;
196
+ const M = Date.now();
178
197
  try {
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();
182
- const _ = e.adapter;
183
- if (!_)
198
+ const E = Re(m), s = ie(E, de[o].parameters);
199
+ if (typeof s.path == "string" && (r.path = s.path), b.log("start", l(l({}, r), Ne(s))), yield e.ready, i.signal.aborted)
200
+ throw w();
201
+ const g = e.adapter;
202
+ if (!g)
184
203
  throw oe();
185
- if (b = e.acquireSlot(), !b)
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";
191
- let g = t.get(v);
192
- g || (g = {
193
- cwd: le
194
- }, t.set(v, g));
195
- const V = pe(e, _, o), $ = g.cwd, J = {
196
- adapter: _,
197
- runner: V,
198
- signal: r.signal,
199
- timeoutMs: e.limits.toolTimeoutMs,
200
- shellCwd: g
201
- }, E = yield Promise.race([Te[a](i, J), Oe(r.signal)]), q = {
202
- code: l.Ok,
204
+ if (S.has(o)) {
205
+ if (x = e.acquireCommand(), !x)
206
+ throw new u(a.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
207
+ } else if (y = e.acquireSlot(), !y)
208
+ throw new u(a.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
209
+ p = e.track(i), e.emit("tool:start", l({}, r));
210
+ const B = c.sessionId || "default";
211
+ let h = t.get(B);
212
+ h || (h = {
213
+ cwd: ae
214
+ }, t.set(B, h));
215
+ const J = Ee(e, g, n), z = h.cwd, G = {
216
+ adapter: g,
217
+ runner: J,
218
+ signal: i.signal,
219
+ timeoutMs: I,
220
+ shellCwd: h,
221
+ skills: e.platformSkills,
222
+ skillRunner: Oe(e, g)
223
+ }, O = yield Promise.race([pe[o](s, G), Le(i.signal)]), D = {
224
+ code: a.Ok,
203
225
  message: "ok",
204
- data: E.data
226
+ data: O.data
205
227
  };
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 ? {
228
+ O.truncated && (D.truncated = !0);
229
+ const K = Date.now() - M, U = O.data.exitCode;
230
+ b.log("finish", l(l(l(_(l({}, r), {
231
+ elapsedMs: K,
232
+ code: a.Ok
233
+ }), O.truncated ? {
212
234
  truncated: !0
213
- } : {}), typeof B == "number" ? {
214
- exitCode: B
215
- } : {}), a === "shell" ? {
216
- cwd: g.cwd,
217
- cwdChanged: g.cwd !== $
218
- } : {})), e.emit("tool:finish", h(s({}, n), {
219
- code: l.Ok
220
- })), j.has(a) && e.notifyFilesChanged(), d(q);
221
- } catch (O) {
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), {
226
- elapsedMs: _,
227
- timedOut: p
228
- })), e.emit("tool:cancelled", s({}, n))) : (w.error("error", h(s({}, n), {
229
- elapsedMs: _,
230
- code: i.code,
231
- message: H(i.message, 300)
232
- })), e.emit("tool:error", h(s({}, n), {
233
- code: i.code,
234
- message: i.message,
235
- reason: (F = i.data) == null ? void 0 : F.reason
236
- }))), d(Le(i));
235
+ } : {}), typeof U == "number" ? {
236
+ exitCode: U
237
+ } : {}), o === "shell" ? {
238
+ cwd: h.cwd,
239
+ cwdChanged: h.cwd !== z
240
+ } : {})), e.emit("tool:finish", _(l({}, r), {
241
+ code: a.Ok
242
+ })), S.has(o) && e.notifyFilesChanged(), d(D);
243
+ } catch (E) {
244
+ let s = (v = Se(E)) != null ? v : re(E);
245
+ T ? s = new u(a.Timeout, "操作超时,已中止。") : i.signal.aborted && s.code !== a.Cancelled && (s = w());
246
+ const g = Date.now() - M;
247
+ s.code === a.Cancelled ? (b.log("cancelled", _(l({}, r), {
248
+ elapsedMs: g,
249
+ timedOut: T
250
+ })), e.emit("tool:cancelled", l({}, r))) : (b.error("error", _(l({}, r), {
251
+ elapsedMs: g,
252
+ code: s.code,
253
+ message: k(s.message, 300)
254
+ })), e.emit("tool:error", _(l({}, r), {
255
+ code: s.code,
256
+ message: s.message,
257
+ reason: (q = s.data) == null ? void 0 : q.reason
258
+ }))), d(Me(s));
237
259
  } finally {
238
- clearTimeout(L), (A = c.signal) == null || A.removeEventListener("abort", I), b == null || b(), y == null || y(), x == null || x();
260
+ clearTimeout(R), (P = c.signal) == null || P.removeEventListener("abort", N), y == null || y(), x == null || x(), p == null || p();
239
261
  }
240
262
  });
241
263
  }
242
264
  export {
243
- He as createBuiltinToolsPlugin
265
+ Je as createBuiltinToolsPlugin
244
266
  };
@@ -1,39 +1,45 @@
1
1
  import { ToolError as o, ToolCode as i } from "../localFiles/errors.mjs";
2
- const l = ["input", "output", "uploads", "tmp"], h = "不要使用 input、output、uploads、tmp,也不要新建这些目录。请把文件直接放在工作区已有位置或根目录。", c = /(?:^|[\s'"=;|&<>`:])\/?(?:input|output|uploads|tmp)(?=\/|[\s'"=;|&<>`:]|$)/;
3
- function d(t) {
4
- return c.test(t);
2
+ const f = ["input", "output", "uploads", "tmp"], c = "不要使用 input、output、uploads、tmp,也不要新建这些目录。请把文件直接放在工作区已有位置或根目录。", h = /(?:^|[\s'"=;|&<>`:])\/?(?:input|output|uploads|tmp)(?=\/|[\s'"=;|&<>`:]|$)/, d = /(?:^|[\s'"=;|&<>`:])\/?skills(?=\/|[\s'"=;|&<>`:]|$)/;
3
+ function a(t) {
4
+ return d.test(t);
5
+ }
6
+ function w(t) {
7
+ return h.test(t);
5
8
  }
6
9
  function u(t) {
7
10
  const n = t.split("/")[0];
8
- return l.includes(n);
11
+ return f.includes(n);
9
12
  }
10
13
  function r(t) {
11
14
  throw new o(i.Forbidden, t, {
12
15
  reason: "path_outside_workspace"
13
16
  });
14
17
  }
15
- function f(t) {
18
+ function l(t) {
16
19
  if (typeof t != "string" || t.length === 0)
17
- throw new o(i.BadRequest, "path 必须是工作区内绝对路径。");
20
+ throw new o(i.BadRequest, "path 必须是工作区内路径。");
18
21
  (t.includes("\0") || t.includes("\\")) && r("路径不能包含反斜杠。");
19
22
  const n = t.normalize("NFC").trim();
20
- if (!n.startsWith("/"))
21
- throw new o(i.BadRequest, "path 必须是工作区内绝对路径,例如 /说明.md。");
22
- const e = n.split("/").filter((s) => s.length > 0);
23
- if (e.some((s) => s === "." || s === "..") && r("路径不能包含 . 或 .. 。"), e.length > 0 && u(e[0]))
24
- throw new o(i.BadRequest, h);
23
+ if (!n)
24
+ throw new o(i.BadRequest, "path 必须是工作区内路径。");
25
+ /^[a-zA-Z]:/.test(n) && r("路径不能包含盘符。");
26
+ const e = n.split("/").filter((s) => s.length > 0 && s !== ".");
27
+ if (e.some((s) => s === "..") && r("路径不能包含 .. 。"), e.length > 0 && u(e[0]))
28
+ throw new o(i.BadRequest, c);
29
+ if (e[0] === "skills")
30
+ throw new o(i.Forbidden, "技能文件只能通过技能工具访问。");
25
31
  return e.join("/");
26
32
  }
27
- function a(t) {
28
- return f(t);
33
+ function R(t) {
34
+ return l(t);
29
35
  }
30
- function w(t) {
31
- return f(t);
36
+ function S(t) {
37
+ return l(t);
32
38
  }
33
- function R(t) {
39
+ function g(t) {
34
40
  return t ? `/${t}` : "/";
35
41
  }
36
- function S(t) {
42
+ function I(t) {
37
43
  if (t === ".")
38
44
  return !0;
39
45
  if (!t || t.startsWith("/") || t.includes("\\") || t.includes("\0"))
@@ -41,7 +47,7 @@ function S(t) {
41
47
  const n = t.split("/").filter((e) => e.length > 0);
42
48
  return n.length > 0 && n.every((e) => e !== "." && e !== "..") && !u(n[0]);
43
49
  }
44
- function g(t, n) {
50
+ function T(t, n) {
45
51
  if (!t || /[\\/\0]/.test(t) || t === "." || t === "..")
46
52
  throw new o(i.BadRequest, "skill_name 必须是单个技能目录名。");
47
53
  if (!n || n.startsWith("/") || n.includes("\\") || n.includes("\0"))
@@ -50,14 +56,15 @@ function g(t, n) {
50
56
  return (e.length === 0 || e.some((s) => s === "." || s === "..")) && r("资源路径不能跳出技能目录。"), `skills/${t}/${e.join("/")}`;
51
57
  }
52
58
  export {
53
- l as SYNTHETIC_DIRS,
54
- h as SYNTHETIC_DIR_MESSAGE,
55
- S as isSafeCwd,
59
+ f as SYNTHETIC_DIRS,
60
+ c as SYNTHETIC_DIR_MESSAGE,
61
+ I as isSafeCwd,
56
62
  u as isSyntheticCwd,
57
- d as mentionsSyntheticDir,
58
- a as resolveFilePath,
59
- w as resolveRunPath,
60
- f as resolveWorkspacePath,
61
- g as skillRelative,
62
- R as toVirtualPath
63
+ a as mentionsSkillDir,
64
+ w as mentionsSyntheticDir,
65
+ R as resolveFilePath,
66
+ S as resolveRunPath,
67
+ l as resolveWorkspacePath,
68
+ T as skillRelative,
69
+ g as toVirtualPath
63
70
  };