@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,32 +1,32 @@
1
- var p = Object.defineProperty;
2
- var m = (r, t) => {
1
+ var u = Object.defineProperty;
2
+ var h = (r, t) => {
3
3
  if (t = Symbol[r])
4
4
  return t;
5
5
  throw Error("Symbol." + r + " is not defined");
6
6
  };
7
- var u = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
8
- var l = (r, t, e) => (u(r, typeof t != "symbol" ? t + "" : t, e), e);
9
- var n = (r, t, e) => new Promise((s, a) => {
10
- var o = (i) => {
7
+ var g = (r, t, e) => t in r ? u(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
8
+ var y = (r, t, e) => (g(r, typeof t != "symbol" ? t + "" : t, e), e);
9
+ var o = (r, t, e) => new Promise((s, a) => {
10
+ var n = (i) => {
11
11
  try {
12
- y(e.next(i));
12
+ d(e.next(i));
13
13
  } catch (c) {
14
14
  a(c);
15
15
  }
16
- }, d = (i) => {
16
+ }, l = (i) => {
17
17
  try {
18
- y(e.throw(i));
18
+ d(e.throw(i));
19
19
  } catch (c) {
20
20
  a(c);
21
21
  }
22
- }, y = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, d);
23
- y((e = e.apply(r, t)).next());
22
+ }, d = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(n, l);
23
+ d((e = e.apply(r, t)).next());
24
24
  });
25
- var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (o) => new Promise((d, y, i) => (o = a.call(r, o), i = o.done, Promise.resolve(o.value).then((c) => d({ value: c, done: i }), y)))), e("next"), e("return"), t);
26
- import { throwIfAborted as g } from "../errors.mjs";
27
- import { SandboxClient as v } from "../host/sandboxClient.mjs";
25
+ var f = (r, t, e) => (t = r[h("asyncIterator")]) ? t.call(r) : (r = r[h("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (n) => new Promise((l, d, i) => (n = a.call(r, n), i = n.done, Promise.resolve(n.value).then((c) => l({ value: c, done: i }), d)))), e("next"), e("return"), t);
26
+ import { throwIfAborted as v } from "../errors.mjs";
27
+ import { SandboxClient as w } from "../host/sandboxClient.mjs";
28
28
  import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
29
- import { domError as w, toChunks as M } from "./WorkspaceFileAdapter.mjs";
29
+ import { domError as m, toChunks as M } from "./WorkspaceFileAdapter.mjs";
30
30
  function x(r, t) {
31
31
  const e = r && typeof r == "object" ? r : {}, s = e.kind === "directory" ? "directory" : "file", a = {
32
32
  name: typeof e.name == "string" && e.name ? e.name : t,
@@ -34,13 +34,13 @@ function x(r, t) {
34
34
  };
35
35
  return s === "file" && typeof e.size == "number" && (a.size = e.size), typeof e.lastModified == "number" && (a.lastModified = e.lastModified), a;
36
36
  }
37
- class S {
38
- constructor(t, e = "", s = new v()) {
39
- l(this, "displayName");
40
- l(this, "capabilities", /* @__PURE__ */ new Set());
41
- l(this, "sandboxVersion");
42
- l(this, "sandboxProtocol");
43
- l(this, "sandbox");
37
+ class P {
38
+ constructor(t, e = "", s = new w()) {
39
+ y(this, "displayName");
40
+ y(this, "capabilities", /* @__PURE__ */ new Set());
41
+ y(this, "sandboxVersion");
42
+ y(this, "sandboxProtocol");
43
+ y(this, "sandbox");
44
44
  this.displayName = e, this.sandbox = s;
45
45
  }
46
46
  setCapabilities(t, e = {}) {
@@ -50,7 +50,7 @@ class S {
50
50
  applySandbox(t) {
51
51
  this.sandboxProtocol = t == null ? void 0 : t.protocol, this.sandbox.apply(t);
52
52
  }
53
- /** 沙箱已就绪且协议为 2 时,命令走直连。 */
53
+ /** 沙箱已就绪且协议为 1 时,命令走直连。 */
54
54
  get canExec() {
55
55
  return this.sandbox.ready;
56
56
  }
@@ -61,65 +61,70 @@ class S {
61
61
  return this.sandbox.unavailableMessage();
62
62
  }
63
63
  stat(t) {
64
- return n(this, null, function* () {
64
+ return o(this, null, function* () {
65
65
  const e = yield this.sandbox.stat(t);
66
66
  return x(e.entry, t.split("/").pop() || this.displayName);
67
67
  });
68
68
  }
69
69
  listEntries(t, e) {
70
- return n(this, null, function* () {
70
+ return o(this, null, function* () {
71
71
  const s = yield this.sandbox.list(t, e);
72
- return (Array.isArray(s.entries) ? s.entries : []).map((o) => x(o, ""));
72
+ return (Array.isArray(s.entries) ? s.entries : []).map((n) => x(n, ""));
73
+ });
74
+ }
75
+ url(t) {
76
+ return o(this, null, function* () {
77
+ const e = yield this.sandbox.url(t), s = this.sandbox.httpOrigin();
78
+ if (!s)
79
+ throw m("NotAllowedError", this.unavailableMessage());
80
+ return {
81
+ url: `http://${s}/file/${e}`,
82
+ release: () => {
83
+ this.sandbox.releaseUrl(e).catch(() => {
84
+ });
85
+ }
86
+ };
73
87
  });
74
88
  }
75
89
  readFile(t, e) {
76
- return n(this, null, function* () {
90
+ return o(this, null, function* () {
77
91
  var a;
78
92
  const s = yield this.sandbox.read(t, (a = e == null ? void 0 : e.offset) != null ? a : 0, e == null ? void 0 : e.maxBytes);
79
93
  return new Blob([s]);
80
94
  });
81
95
  }
82
96
  createDirectory(t) {
83
- return n(this, null, function* () {
97
+ return o(this, null, function* () {
84
98
  yield this.sandbox.mkdir(t);
85
99
  });
86
100
  }
87
101
  remove(s) {
88
- return n(this, arguments, function* (t, e = {}) {
102
+ return o(this, arguments, function* (t, e = {}) {
89
103
  yield this.sandbox.remove(t, e.recursive === !0);
90
104
  });
91
105
  }
92
106
  move(t, e) {
93
- return n(this, null, function* () {
107
+ return o(this, null, function* () {
94
108
  yield this.sandbox.move(t, e);
95
109
  });
96
110
  }
97
111
  exec(t) {
98
- return n(this, null, function* () {
112
+ return o(this, null, function* () {
99
113
  const e = yield this.sandbox.exec({
100
114
  op: "exec",
101
115
  cwd: t.cwd,
102
116
  command: t.command,
103
117
  argv: t.argv,
104
- timeoutMs: t.timeoutMs
118
+ timeoutMs: t.timeoutMs,
119
+ skill: t.skill
105
120
  }, t.signal, t.onOutput);
106
121
  if (e.timedOut)
107
- throw w("AbortError", "命令运行超时。");
122
+ throw m("AbortError", "命令运行超时。");
108
123
  return e;
109
124
  });
110
125
  }
111
- runPython(t, e, s, a) {
112
- return n(this, null, function* () {
113
- return this.sandbox.exec({
114
- op: "run_python",
115
- path: t,
116
- args: e,
117
- timeoutMs: s
118
- }, a);
119
- });
120
- }
121
- writeFile(a, o) {
122
- return n(this, arguments, function* (t, e, s = {}) {
126
+ writeFile(a, n) {
127
+ return o(this, arguments, function* (t, e, s = {}) {
123
128
  if (typeof e == "string") {
124
129
  yield this.sandbox.write(t, new TextEncoder().encode(e), s.createDirectories === !0, s.signal);
125
130
  return;
@@ -128,30 +133,30 @@ class S {
128
133
  yield this.sandbox.write(t, e, s.createDirectories === !0, s.signal);
129
134
  return;
130
135
  }
131
- const d = [];
136
+ const l = [];
132
137
  try {
133
- for (var N = f(M(e)), z, L, F; z = !(L = yield N.next()).done; z = !1) {
138
+ for (var C = f(M(e)), z, L, U; z = !(L = yield C.next()).done; z = !1) {
134
139
  const b = L.value;
135
- g(s.signal), d.push(b);
140
+ v(s.signal), l.push(b);
136
141
  }
137
142
  } catch (L) {
138
- F = [L];
143
+ U = [L];
139
144
  } finally {
140
145
  try {
141
- z && (L = N.return) && (yield L.call(N));
146
+ z && (L = C.return) && (yield L.call(C));
142
147
  } finally {
143
- if (F)
144
- throw F[0];
148
+ if (U)
149
+ throw U[0];
145
150
  }
146
151
  }
147
- const y = d.reduce((b, h) => b + h.byteLength, 0), i = new Uint8Array(y);
152
+ const d = l.reduce((b, p) => b + p.byteLength, 0), i = new Uint8Array(d);
148
153
  let c = 0;
149
- d.forEach((b) => {
154
+ l.forEach((b) => {
150
155
  i.set(b, c), c += b.byteLength;
151
156
  }), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
152
157
  });
153
158
  }
154
159
  }
155
160
  export {
156
- S as HostBridgeAdapter
161
+ P as HostBridgeAdapter
157
162
  };
@@ -1,47 +1,43 @@
1
- const s = ["list_directory", "read_file", "stat_file", "search_files", "search_text", "apply_patch", "write_file", "upload_file", "download_file"], _ = "builtin_tools", t = {
1
+ const T = ["list_directory", "read_file", "stat_file", "search_files", "search_text", "apply_patch", "write_file", "upload_file", "download_file"], _ = "builtin_tools", t = {
2
2
  dev: _,
3
3
  test: _,
4
4
  prod: _,
5
5
  local: _
6
- }, E = t, c = "run_python", I = t, n = 2e4, O = 12e4, L = 16, S = "current-workspace", o = 1024, e = 1024 * 1024, T = 50, A = Object.freeze({
6
+ }, E = t, c = "current-workspace", o = 1024, e = 1024 * 1024, s = 50, I = Object.freeze({
7
7
  maxReadBytes: 1 * e,
8
8
  maxWriteBytes: 5 * e,
9
9
  maxSearchResults: 200,
10
10
  maxConcurrentRequests: 4,
11
- maxTransferBytes: T * e,
11
+ maxTransferBytes: s * e,
12
12
  toolTimeoutMs: 3e4,
13
+ commandTimeoutMs: 10 * 6e4,
13
14
  searchTimeoutMs: 6e4,
14
15
  transferTimeoutMs: 10 * 6e4,
15
16
  approvalTimeoutMs: 5 * 6e4
16
- }), N = 200, C = 1e3, a = 8, l = 16, R = 2e3, r = 1 * e, i = 500, D = 3, F = 8 * o, M = Object.freeze(["glodon.com"]), U = Object.freeze([".git", "node_modules", ".svn", ".idea", ".vscode"]), d = Object.freeze(["~$*", ".~lock*", "*.tmp"]), f = ["apply_patch", "write_file", "upload_file", "download_file"], p = ["search_files", "search_text"], H = ["upload_file", "download_file"];
17
+ }), n = 200, L = 1e3, S = 8, a = 16, l = 2e3, O = 1 * e, A = 500, R = 3, i = 8 * o, r = Object.freeze(["glodon.com"]), C = Object.freeze([".git", "node_modules", ".svn", ".idea", ".vscode"]), N = Object.freeze(["~$*", ".~lock*", "*.tmp"]), D = ["apply_patch", "write_file", "upload_file", "download_file"], d = ["search_files", "search_text"], F = ["upload_file", "download_file"];
17
18
  export {
18
- F as BINARY_SNIFF_BYTES,
19
+ i as BINARY_SNIFF_BYTES,
19
20
  _ as BUILTIN_TOOLS_PLUGIN_CODE,
20
21
  t as BUILTIN_TOOLS_PLUGIN_CODES,
21
- M as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
22
- U as DEFAULT_IGNORED_DIRECTORIES,
23
- d as DEFAULT_IGNORED_FILE_PATTERNS,
24
- A as DEFAULT_LIMITS,
22
+ r as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
23
+ C as DEFAULT_IGNORED_DIRECTORIES,
24
+ N as DEFAULT_IGNORED_FILE_PATTERNS,
25
+ I as DEFAULT_LIMITS,
25
26
  o as KiB,
26
- N as LIST_DIRECTORY_DEFAULT_LIMIT,
27
- C as LIST_DIRECTORY_MAX_LIMIT,
28
- s as LOCAL_FILES_FUNCTION_CODES,
27
+ n as LIST_DIRECTORY_DEFAULT_LIMIT,
28
+ L as LIST_DIRECTORY_MAX_LIMIT,
29
+ T as LOCAL_FILES_FUNCTION_CODES,
29
30
  E as LOCAL_FILES_PLUGIN_CODES,
30
- c as LOCAL_PYTHON_FUNCTION_CODE,
31
- I as LOCAL_PYTHON_PLUGIN_CODES,
32
31
  e as MiB,
33
- n as PYTHON_DEFAULT_TIMEOUT_MS,
34
- L as PYTHON_MAX_ARGS,
35
- O as PYTHON_MAX_TIMEOUT_MS,
36
- a as SEARCH_DEFAULT_DEPTH,
37
- p as SEARCH_FUNCTION_CODES,
38
- l as SEARCH_MAX_DEPTH,
39
- D as TEXT_SEARCH_MAX_CONTEXT_LINES,
40
- R as TEXT_SEARCH_MAX_FILES,
41
- r as TEXT_SEARCH_MAX_FILE_BYTES,
42
- i as TEXT_SEARCH_MAX_LINE_CHARS,
43
- T as TRANSFER_FILE_SIZE_LIMIT_MB,
44
- H as TRANSFER_FUNCTION_CODES,
45
- S as WORKSPACE_GRANT_ID,
46
- f as WRITE_FUNCTION_CODES
32
+ S as SEARCH_DEFAULT_DEPTH,
33
+ d as SEARCH_FUNCTION_CODES,
34
+ a as SEARCH_MAX_DEPTH,
35
+ R as TEXT_SEARCH_MAX_CONTEXT_LINES,
36
+ l as TEXT_SEARCH_MAX_FILES,
37
+ O as TEXT_SEARCH_MAX_FILE_BYTES,
38
+ A as TEXT_SEARCH_MAX_LINE_CHARS,
39
+ s as TRANSFER_FILE_SIZE_LIMIT_MB,
40
+ F as TRANSFER_FUNCTION_CODES,
41
+ c as WORKSPACE_GRANT_ID,
42
+ D as WRITE_FUNCTION_CODES
47
43
  };
@@ -9,7 +9,7 @@ var E = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writab
9
9
  for (var r of G(t))
10
10
  Q.call(t, r) && E(e, r, t[r]);
11
11
  return e;
12
- }, f = (e, t) => B(e, K(t));
12
+ }, h = (e, t) => B(e, K(t));
13
13
  var _ = (e, t, r) => (E(e, typeof t != "symbol" ? t + "" : t, r), r);
14
14
  var F = (e, t, r) => new Promise((d, s) => {
15
15
  var o = (a) => {
@@ -28,26 +28,27 @@ var F = (e, t, r) => new Promise((d, s) => {
28
28
  i((r = r.apply(e, t)).next());
29
29
  });
30
30
  import { v4 as U } from "uuid";
31
- import { LOCAL_FILES_FUNCTION_CODES as V, TRANSFER_FUNCTION_CODES as X, SEARCH_FUNCTION_CODES as Y, WORKSPACE_GRANT_ID as Z } from "./constants.mjs";
32
- import { cancelledError as g, workspaceNotGranted as $, ToolError as h, ToolCode as m, toToolError as k } from "./errors.mjs";
33
- import { LOCAL_FILE_TOOL_SCHEMAS as ee } from "./schemas.mjs";
34
- import { assertGrantId as te } from "./security/pathPolicy.mjs";
35
- import { listDirectory as re, readFile as ie, statFile as ae, searchFiles as oe, searchText as ne } from "./tools/readTools.mjs";
36
- import { uploadFile as se, downloadFile as le } from "./tools/transferTools.mjs";
37
- import { applyPatch as de, writeFile as ce } from "./tools/writeTools.mjs";
38
- import { validateToolInput as ue } from "./validate.mjs";
39
- const me = {
40
- list_directory: re,
41
- read_file: ie,
42
- stat_file: ae,
43
- search_files: oe,
44
- search_text: ne,
45
- apply_patch: de,
46
- write_file: ce,
47
- upload_file: se,
48
- download_file: le
31
+ import V from "../Logger.mjs";
32
+ import { LOCAL_FILES_FUNCTION_CODES as X, TRANSFER_FUNCTION_CODES as Y, SEARCH_FUNCTION_CODES as Z, WORKSPACE_GRANT_ID as $ } from "./constants.mjs";
33
+ import { cancelledError as g, workspaceNotGranted as k, ToolError as f, ToolCode as m, toToolError as ee } from "./errors.mjs";
34
+ import { LOCAL_FILE_TOOL_SCHEMAS as te } from "./schemas.mjs";
35
+ import { assertGrantId as re } from "./security/pathPolicy.mjs";
36
+ import { listDirectory as ie, readFile as ae, statFile as oe, searchFiles as ne, searchText as se } from "./tools/readTools.mjs";
37
+ import { uploadFile as le, downloadFile as de } from "./tools/transferTools.mjs";
38
+ import { applyPatch as ce, writeFile as ue } from "./tools/writeTools.mjs";
39
+ import { validateToolInput as me } from "./validate.mjs";
40
+ const fe = new V("[LocalFiles] "), he = {
41
+ list_directory: ie,
42
+ read_file: ae,
43
+ stat_file: oe,
44
+ search_files: ne,
45
+ search_text: se,
46
+ apply_patch: ce,
47
+ write_file: ue,
48
+ upload_file: le,
49
+ download_file: de
49
50
  };
50
- class he {
51
+ class ge {
51
52
  constructor(t, r) {
52
53
  _(this, "remaining");
53
54
  _(this, "startedAt", 0);
@@ -66,23 +67,23 @@ class he {
66
67
  this.pause(), this.remaining = 0;
67
68
  }
68
69
  }
69
- function fe(e, t) {
70
- return X.includes(t) ? e.limits.transferTimeoutMs : Y.includes(t) ? e.limits.searchTimeoutMs : e.limits.toolTimeoutMs;
70
+ function pe(e, t) {
71
+ return Y.includes(t) ? e.limits.transferTimeoutMs : Z.includes(t) ? e.limits.searchTimeoutMs : e.limits.toolTimeoutMs;
71
72
  }
72
- function ge(e) {
73
+ function ve(e) {
73
74
  if (typeof e != "string")
74
75
  return e;
75
76
  try {
76
77
  return JSON.parse(e);
77
78
  } catch (t) {
78
- throw new h(m.BadRequest, "参数不是合法的 JSON 对象。");
79
+ throw new f(m.BadRequest, "参数不是合法的 JSON 对象。");
79
80
  }
80
81
  }
81
- function pe(e) {
82
+ function Ie(e) {
82
83
  if (!e || typeof e != "object" || Array.isArray(e))
83
84
  return;
84
85
  const t = e;
85
- return (t.grantId === void 0 || t.grantId === null || t.grantId === "") && (t.grantId = Z), t.grantId;
86
+ return (t.grantId === void 0 || t.grantId === null || t.grantId === "") && (t.grantId = $), t.grantId;
86
87
  }
87
88
  function W(e) {
88
89
  return new Promise((t, r) => {
@@ -91,7 +92,7 @@ function W(e) {
91
92
  });
92
93
  });
93
94
  }
94
- function ve(e) {
95
+ function be(e) {
95
96
  return u({
96
97
  code: e.code,
97
98
  message: e.message
@@ -99,7 +100,7 @@ function ve(e) {
99
100
  data: e.data
100
101
  } : {});
101
102
  }
102
- function Ie(e, t, r, d, s) {
103
+ function Te(e, t, r, d, s) {
103
104
  return F(this, null, function* () {
104
105
  var N, S, q, P, C, D, R, x;
105
106
  const o = {
@@ -115,7 +116,7 @@ function Ie(e, t, r, d, s) {
115
116
  functionCode: t
116
117
  }, i = new AbortController();
117
118
  let a = !1;
118
- const c = new he(fe(e, t), () => {
119
+ const c = new ge(pe(e, t), () => {
119
120
  a = !0, i.abort();
120
121
  }), v = () => i.abort();
121
122
  (N = o.signal) == null || N.addEventListener("abort", v, {
@@ -123,16 +124,16 @@ function Ie(e, t, r, d, s) {
123
124
  }), (S = o.signal) != null && S.aborted && i.abort();
124
125
  let p = null, I, L = !1;
125
126
  try {
126
- const b = ge(r), l = pe(b);
127
- l != null && te(l);
128
- const w = ue(b, ee[t].parameters), M = (q = w.path) != null ? q : w.destPath;
127
+ const b = ve(r), l = Ie(b);
128
+ l != null && re(l);
129
+ const w = me(b, te[t].parameters), M = (q = w.path) != null ? q : w.destPath;
129
130
  if (typeof M == "string" && (n.path = M), yield e.ready, i.signal.aborted)
130
131
  throw g();
131
132
  const y = e.adapter;
132
133
  if (!y)
133
- throw $();
134
+ throw k();
134
135
  if (p = e.acquireSlot(), !p)
135
- throw new h(m.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
136
+ throw new f(m.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
136
137
  I = e.track(i), L = !0, e.emit("tool:start", u({}, n)), c.resume();
137
138
  const H = {
138
139
  adapter: y,
@@ -143,11 +144,11 @@ function Ie(e, t, r, d, s) {
143
144
  allowWorkspaceWideTextSearch: e.allowWorkspaceWideTextSearch,
144
145
  transfer: e.transfer,
145
146
  fetch: e.fetch,
146
- context: f(u({}, o), {
147
+ context: h(u({}, o), {
147
148
  signal: i.signal
148
149
  }),
149
150
  signal: i.signal,
150
- requestApproval: (O, j) => be(e, {
151
+ requestApproval: (O, j) => _e(e, {
151
152
  approvalPath: O,
152
153
  preview: j,
153
154
  context: o,
@@ -157,32 +158,32 @@ function Ie(e, t, r, d, s) {
157
158
  base: n
158
159
  }),
159
160
  progress: (O) => e.emit("tool:progress", u(u({}, n), O))
160
- }, T = yield Promise.race([me[t](w, H), W(i.signal)]), A = {
161
+ }, T = yield Promise.race([he[t](w, H), W(i.signal)]), A = {
161
162
  code: m.Ok,
162
163
  message: "ok",
163
164
  data: T.data
164
165
  };
165
- T.truncated && (A.truncated = !0), (C = T.warnings) != null && C.length && (A.warnings = T.warnings), e.emit("tool:finish", f(u({}, n), {
166
+ T.truncated && (A.truncated = !0), (C = T.warnings) != null && C.length && (A.warnings = T.warnings), e.emit("tool:finish", h(u({}, n), {
166
167
  code: m.Ok
167
168
  })), d(A);
168
169
  } catch (b) {
169
- let l = k(b);
170
- a ? l = new h(m.Timeout, "操作超时,已中止。") : i.signal.aborted && l.code !== m.Cancelled && (l = g()), ((D = l.data) == null ? void 0 : D.reason) === "workspace_not_granted" && L && e.handlePermissionLost(), l.code === m.Cancelled ? e.emit("tool:cancelled", u({}, n)) : e.emit("tool:error", f(u({}, n), {
170
+ let l = ee(b);
171
+ a ? l = new f(m.Timeout, "操作超时,已中止。") : i.signal.aborted && l.code !== m.Cancelled && (l = g()), ((D = l.data) == null ? void 0 : D.reason) === "workspace_not_granted" && L && e.handlePermissionLost(), l.code === m.Cancelled ? e.emit("tool:cancelled", u({}, n)) : e.emit("tool:error", h(u({}, n), {
171
172
  code: l.code,
172
173
  message: l.message,
173
174
  reason: (R = l.data) == null ? void 0 : R.reason
174
- })), d(ve(l));
175
+ })), d(be(l));
175
176
  } finally {
176
177
  c.clear(), (x = o.signal) == null || x.removeEventListener("abort", v), p == null || p(), I == null || I();
177
178
  }
178
179
  });
179
180
  }
180
- function be(e, t) {
181
+ function _e(e, t) {
181
182
  return F(this, null, function* () {
182
183
  var i;
183
184
  const r = e.getApprovalHandler();
184
185
  if (!r)
185
- throw new h(m.Forbidden, "当前环境未提供操作确认能力,无法执行写入或传输操作。", {
186
+ throw new f(m.Forbidden, "当前环境未提供操作确认能力,无法执行写入或传输操作。", {
186
187
  reason: "approval_unavailable"
187
188
  });
188
189
  if (t.signal.aborted)
@@ -201,7 +202,7 @@ function be(e, t) {
201
202
  preview: t.preview,
202
203
  signal: d.signal
203
204
  };
204
- t.timer.pause(), e.emit("tool:approval-required", f(u({}, t.base), {
205
+ t.timer.pause(), e.emit("tool:approval-required", h(u({}, t.base), {
205
206
  path: t.approvalPath,
206
207
  approvalId: o.id
207
208
  }));
@@ -213,11 +214,11 @@ function be(e, t) {
213
214
  if (t.signal.aborted)
214
215
  throw g();
215
216
  if (a !== !0)
216
- throw new h(m.Forbidden, "用户拒绝了本次操作。", {
217
+ throw new f(m.Forbidden, "用户拒绝了本次操作。", {
217
218
  reason: "user_rejected"
218
219
  });
219
220
  } catch (a) {
220
- throw a instanceof h ? a : new h(m.Forbidden, "操作确认失败,已取消本次操作。", {
221
+ throw a instanceof f ? a : new f(m.Forbidden, "操作确认失败,已取消本次操作。", {
221
222
  reason: "user_rejected"
222
223
  });
223
224
  } finally {
@@ -225,24 +226,24 @@ function be(e, t) {
225
226
  }
226
227
  });
227
228
  }
228
- function Se({
229
+ function Ce({
229
230
  pluginCode: e,
230
231
  workspace: t
231
232
  }) {
232
233
  const r = {};
233
- return V.forEach((d) => {
234
+ return X.forEach((d) => {
234
235
  r[d] = (s, o, n) => {
235
236
  let i = !1;
236
- Ie(t, d, s, (c) => {
237
+ Te(t, d, s, (c) => {
237
238
  if (!i) {
238
239
  i = !0;
239
240
  try {
240
241
  o(c);
241
242
  } catch (v) {
242
- console.error("[LocalFiles] callback failed", v);
243
+ fe.report("callback failed", v);
243
244
  }
244
245
  }
245
- }, f(u({}, n), {
246
+ }, h(u({}, n), {
246
247
  pluginCode: e
247
248
  }));
248
249
  };
@@ -251,5 +252,5 @@ function Se({
251
252
  };
252
253
  }
253
254
  export {
254
- Se as createLocalFilesPlugin
255
+ Ce as createLocalFilesPlugin
255
256
  };
@@ -1,57 +1,66 @@
1
- var i = Object.defineProperty;
2
- var E = (r, t, e) => t in r ? i(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
- var a = (r, t, e) => (E(r, typeof t != "symbol" ? t + "" : t, e), e);
4
- var f = /* @__PURE__ */ ((r) => (r[r.Ok = 0] = "Ok", r[r.BadRequest = 400] = "BadRequest", r[r.Forbidden = 403] = "Forbidden", r[r.NotFound = 404] = "NotFound", r[r.Timeout = 408] = "Timeout", r[r.Conflict = 409] = "Conflict", r[r.TooLarge = 413] = "TooLarge", r[r.TooManyRequests = 429] = "TooManyRequests", r[r.Cancelled = 499] = "Cancelled", r[r.Internal = 500] = "Internal", r[r.NotImplemented = 501] = "NotImplemented", r))(f || {});
5
- class n extends Error {
6
- constructor(e, u, s) {
7
- super(u);
8
- a(this, "code");
9
- a(this, "data");
10
- this.name = "ToolError", this.code = e, this.data = s;
1
+ var E = Object.defineProperty;
2
+ var f = (t, e, n) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var s = (t, e, n) => (f(t, typeof e != "symbol" ? e + "" : e, n), n);
4
+ var w = /* @__PURE__ */ ((t) => (t[t.Ok = 0] = "Ok", t[t.BadRequest = 400] = "BadRequest", t[t.Forbidden = 403] = "Forbidden", t[t.NotFound = 404] = "NotFound", t[t.Timeout = 408] = "Timeout", t[t.Conflict = 409] = "Conflict", t[t.TooLarge = 413] = "TooLarge", t[t.TooManyRequests = 429] = "TooManyRequests", t[t.Cancelled = 499] = "Cancelled", t[t.Internal = 500] = "Internal", t[t.NotImplemented = 501] = "NotImplemented", t))(w || {});
5
+ class r extends Error {
6
+ constructor(n, a, i) {
7
+ super(a);
8
+ s(this, "code");
9
+ s(this, "data");
10
+ this.name = "ToolError", this.code = n, this.data = i;
11
11
  }
12
12
  }
13
- const w = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
14
- function m() {
15
- return new n(403, w, {
13
+ const m = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
14
+ function d() {
15
+ return new r(403, m, {
16
16
  reason: "workspace_not_granted"
17
17
  });
18
18
  }
19
- function c() {
20
- return new n(499, "操作已取消。");
19
+ function u() {
20
+ return new r(499, "操作已取消。");
21
21
  }
22
- function N(r) {
23
- if (r != null && r.aborted)
24
- throw c();
22
+ function N(t) {
23
+ if (t != null && t.aborted)
24
+ throw u();
25
25
  }
26
- function o(r) {
27
- if (r instanceof n)
28
- return r;
29
- switch (r && typeof r == "object" && "name" in r ? String(r.name) : "") {
26
+ function c(t) {
27
+ const e = t && typeof t == "object" && "message" in t ? String(t.message) : "";
28
+ return /[\u4e00-\u9fff]/.test(e) ? e : void 0;
29
+ }
30
+ function p(t) {
31
+ var n, a;
32
+ if (t instanceof r)
33
+ return t;
34
+ switch (t && typeof t == "object" && "name" in t ? String(t.name) : "") {
30
35
  case "NotFoundError":
31
- return new n(404, "文件或目录不存在。");
36
+ return new r(404, "文件或目录不存在。");
32
37
  case "TypeMismatchError":
33
- return new n(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
38
+ return new r(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
34
39
  case "NotAllowedError":
35
40
  case "SecurityError":
36
- return m();
41
+ return d();
37
42
  case "AbortError":
38
- return c();
43
+ return u();
39
44
  case "NoModificationAllowedError":
40
45
  case "InvalidModificationError":
41
46
  case "InvalidStateError":
42
- return new n(403, "文件当前不可写,可能正被其他程序占用或为只读。");
47
+ return new r(403, "文件当前不可写,可能正被其他程序占用或为只读。");
43
48
  case "QuotaExceededError":
44
- return new n(413, "磁盘空间不足或超出写入配额。");
49
+ return new r(413, (n = c(t)) != null ? n : "磁盘空间不足或超出写入配额。");
50
+ case "TooManyRequestsError":
51
+ return new r(429, (a = c(t)) != null ? a : "排队的文件操作过多,请稍后重试。");
52
+ case "PreviewLimitError":
53
+ return new r(413, "同时预览的文件过多,请先关掉一些预览。");
45
54
  default:
46
- return new n(500, "本地文件操作失败,请稍后重试。");
55
+ return new r(500, "本地文件操作失败,请稍后重试。");
47
56
  }
48
57
  }
49
58
  export {
50
- f as ToolCode,
51
- n as ToolError,
52
- w as WORKSPACE_NOT_GRANTED_MESSAGE,
53
- c as cancelledError,
59
+ w as ToolCode,
60
+ r as ToolError,
61
+ m as WORKSPACE_NOT_GRANTED_MESSAGE,
62
+ u as cancelledError,
54
63
  N as throwIfAborted,
55
- o as toToolError,
56
- m as workspaceNotGranted
64
+ p as toToolError,
65
+ d as workspaceNotGranted
57
66
  };