@glodon-aiot/bot-client-sdk 3.25.1-alpha.6 → 3.26.0-alpha.10

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 (101) hide show
  1. package/README.md +555 -98
  2. package/dist/es/AgentSession.mjs +231 -167
  3. package/dist/es/BotClient.mjs +188 -136
  4. package/dist/es/Config.mjs +89 -26
  5. package/dist/es/DialogSession.mjs +39 -40
  6. package/dist/es/Session.mjs +83 -63
  7. package/dist/es/api/index.mjs +42 -33
  8. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  9. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  10. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  11. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  12. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  13. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  14. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  15. package/dist/es/builtinTools/command.mjs +56 -0
  16. package/dist/es/builtinTools/constants.mjs +10 -0
  17. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +244 -0
  18. package/dist/es/builtinTools/overview.mjs +77 -0
  19. package/dist/es/builtinTools/paths.mjs +63 -0
  20. package/dist/es/builtinTools/schemas.mjs +216 -0
  21. package/dist/es/builtinTools/tools.mjs +471 -0
  22. package/dist/es/index.mjs +69 -9
  23. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
  24. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +157 -0
  25. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
  26. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
  27. package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
  28. package/dist/es/localFiles/constants.mjs +47 -0
  29. package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
  30. package/dist/es/localFiles/errors.mjs +57 -0
  31. package/dist/es/localFiles/host/connectHostBridge.mjs +53 -0
  32. package/dist/es/localFiles/host/protocol.mjs +27 -0
  33. package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
  34. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  35. package/dist/es/localFiles/limits.mjs +22 -0
  36. package/dist/es/localFiles/schemas.mjs +312 -0
  37. package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
  38. package/dist/es/localFiles/security/glob.mjs +28 -0
  39. package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
  40. package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
  41. package/dist/es/localFiles/tools/readTools.mjs +333 -0
  42. package/dist/es/localFiles/tools/runtime.mjs +108 -0
  43. package/dist/es/localFiles/tools/transferTools.mjs +228 -0
  44. package/dist/es/localFiles/tools/writeTools.mjs +173 -0
  45. package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
  46. package/dist/es/localFiles/validate.mjs +66 -0
  47. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
  48. package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
  49. package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
  50. package/dist/es/package.json.mjs +38 -29
  51. package/dist/lib/index.js +374 -5
  52. package/dist/src/AgentSession.d.ts +9 -0
  53. package/dist/src/BotClient.d.ts +12 -2
  54. package/dist/src/Config.d.ts +25 -1
  55. package/dist/src/Session.d.ts +9 -1
  56. package/dist/src/api/index.d.ts +3 -1
  57. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  58. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  59. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  60. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  61. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  62. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  63. package/dist/src/builtinTools/command.d.ts +28 -0
  64. package/dist/src/builtinTools/constants.d.ts +17 -0
  65. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  66. package/dist/src/builtinTools/overview.d.ts +5 -0
  67. package/dist/src/builtinTools/paths.d.ts +15 -0
  68. package/dist/src/builtinTools/schemas.d.ts +3 -0
  69. package/dist/src/builtinTools/tools.d.ts +60 -0
  70. package/dist/src/index.d.ts +4 -2
  71. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
  72. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +37 -0
  73. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
  74. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
  75. package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
  76. package/dist/src/localFiles/constants.d.ts +51 -0
  77. package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
  78. package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
  79. package/dist/src/localFiles/errors.d.ts +34 -0
  80. package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
  81. package/dist/src/localFiles/host/protocol.d.ts +40 -0
  82. package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
  83. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  84. package/dist/src/localFiles/index.d.ts +22 -0
  85. package/dist/src/localFiles/limits.d.ts +3 -0
  86. package/dist/src/localFiles/schemas.d.ts +29 -0
  87. package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
  88. package/dist/src/localFiles/security/glob.d.ts +3 -0
  89. package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
  90. package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
  91. package/dist/src/localFiles/tools/readTools.d.ts +7 -0
  92. package/dist/src/localFiles/tools/runtime.d.ts +43 -0
  93. package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
  94. package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
  95. package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
  96. package/dist/src/localFiles/types.d.ts +319 -0
  97. package/dist/src/localFiles/validate.d.ts +2 -0
  98. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
  99. package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
  100. package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
  101. package/package.json +13 -4
@@ -0,0 +1,324 @@
1
+ var N = Object.defineProperty;
2
+ var b = Object.getOwnPropertySymbols;
3
+ var C = Object.prototype.hasOwnProperty, M = Object.prototype.propertyIsEnumerable;
4
+ var A = (i, t, e) => t in i ? N(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, S = (i, t) => {
5
+ for (var e in t || (t = {}))
6
+ C.call(t, e) && A(i, e, t[e]);
7
+ if (b)
8
+ for (var e of b(t))
9
+ M.call(t, e) && A(i, e, t[e]);
10
+ return i;
11
+ };
12
+ var m = (i, t, e) => (A(i, typeof t != "symbol" ? t + "" : t, e), e);
13
+ var g = (i, t, e) => new Promise((r, s) => {
14
+ var o = (a) => {
15
+ try {
16
+ c(e.next(a));
17
+ } catch (h) {
18
+ s(h);
19
+ }
20
+ }, n = (a) => {
21
+ try {
22
+ c(e.throw(a));
23
+ } catch (h) {
24
+ s(h);
25
+ }
26
+ }, c = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(o, n);
27
+ c((e = e.apply(i, t)).next());
28
+ });
29
+ import { MAX_COMMAND_OUTPUT_CHARS as w } from "../../builtinTools/command.mjs";
30
+ import { domError as d } from "../adapters/WorkspaceFileAdapter.mjs";
31
+ import { SANDBOX_PROTOCOL as k } from "./protocol.mjs";
32
+ import { decodeBinaryFrame as v, MAX_BINARY_PAYLOAD as O, encodeBinaryFrame as P } from "./sandboxFrames.mjs";
33
+ const y = "沙箱已退出。";
34
+ function E(i) {
35
+ if (i instanceof Uint8Array)
36
+ return i;
37
+ if (i instanceof ArrayBuffer)
38
+ return new Uint8Array(i);
39
+ }
40
+ function x(i, t, e, r) {
41
+ const s = i.length > w ? i.slice(i.length - w) : i;
42
+ if (!t && !e && !r && i.length <= w)
43
+ return s;
44
+ let o = `
45
+ …输出已截断`;
46
+ return e && (o += `,完整输出见 ${e}`), r && (o += ",日志已截断"), s + o;
47
+ }
48
+ class D {
49
+ constructor(t = (e) => new WebSocket(e)) {
50
+ m(this, "notice");
51
+ m(this, "socket");
52
+ m(this, "generation", 0);
53
+ m(this, "authed", !1);
54
+ m(this, "seq", 0);
55
+ m(this, "calls", /* @__PURE__ */ new Map());
56
+ m(this, "outgoing", []);
57
+ this.openSocket = t;
58
+ }
59
+ get ready() {
60
+ const t = this.notice;
61
+ return (t == null ? void 0 : t.state) === "ready" && t.protocol === k && !!(t.url && t.token);
62
+ }
63
+ unavailableMessage() {
64
+ var t, e, r, s;
65
+ return ((t = this.notice) == null ? void 0 : t.state) === "starting" ? "沙箱正在启动。" : (e = this.notice) != null && e.message ? this.notice.message : ((r = this.notice) == null ? void 0 : r.state) === "exited" || ((s = this.notice) == null ? void 0 : s.state) === "failed" ? y : "沙箱没有就绪。";
66
+ }
67
+ apply(t) {
68
+ const e = this.notice;
69
+ if (this.notice = t, !this.ready || !(t != null && t.url) || !t.token) {
70
+ this.failAll(d("NotAllowedError", this.unavailableMessage())), this.stop();
71
+ return;
72
+ }
73
+ (e == null ? void 0 : e.url) === t.url && e.token === t.token && this.socket && this.socket.readyState <= 1 || (this.failAll(d("AbortError", y)), this.stop(), this.connect(t.url, t.token));
74
+ }
75
+ stat(t) {
76
+ return g(this, null, function* () {
77
+ return this.invoke({
78
+ op: "stat",
79
+ path: t
80
+ });
81
+ });
82
+ }
83
+ list(t, e) {
84
+ return g(this, null, function* () {
85
+ return this.invoke({
86
+ op: "list",
87
+ path: t
88
+ }, e);
89
+ });
90
+ }
91
+ read(o) {
92
+ return g(this, arguments, function* (t, e = 0, r = 50 * 1024 * 1024, s) {
93
+ const n = this.begin({
94
+ op: "read",
95
+ path: t,
96
+ offset: e,
97
+ maxBytes: r
98
+ }, s), c = [];
99
+ let a;
100
+ for (; !a; ) {
101
+ const u = yield this.next(n), p = E(u);
102
+ if (p) {
103
+ c.push(v(p).payload);
104
+ continue;
105
+ }
106
+ a = u;
107
+ }
108
+ if (this.calls.delete(n), a.ok === !1)
109
+ throw d(String(a.name || "NotAllowedError"), String(a.message || "读取失败。"));
110
+ const h = c.reduce((u, p) => u + p.length, 0), l = new Uint8Array(h);
111
+ let f = 0;
112
+ return c.forEach((u) => {
113
+ l.set(u, f), f += u.length;
114
+ }), l;
115
+ });
116
+ }
117
+ write(t, e, r, s) {
118
+ return g(this, null, function* () {
119
+ const o = this.begin({
120
+ op: "write",
121
+ path: t,
122
+ size: e.length,
123
+ createDirectories: r
124
+ }, s);
125
+ let n = 0;
126
+ for (; n < e.length; ) {
127
+ const a = e.subarray(n, n + O), h = n + a.length;
128
+ this.send(P(o, n, h === e.length, a)), n = h;
129
+ const f = yield this.next(o);
130
+ if (f.ok === !1)
131
+ throw this.calls.delete(o), d(String(f.name || "NotAllowedError"), String(f.message || "写入失败。"));
132
+ if (f.op !== "ack" && f.ok === !0) {
133
+ this.calls.delete(o);
134
+ return;
135
+ }
136
+ }
137
+ const c = yield this.next(o);
138
+ if (this.calls.delete(o), c.ok === !1)
139
+ throw d(String(c.name || "NotAllowedError"), String(c.message || "写入失败。"));
140
+ });
141
+ }
142
+ mkdir(t) {
143
+ return g(this, null, function* () {
144
+ yield this.invoke({
145
+ op: "mkdir",
146
+ path: t
147
+ });
148
+ });
149
+ }
150
+ remove(t, e) {
151
+ return g(this, null, function* () {
152
+ yield this.invoke({
153
+ op: "remove",
154
+ path: t,
155
+ recursive: e
156
+ });
157
+ });
158
+ }
159
+ move(t, e) {
160
+ return g(this, null, function* () {
161
+ yield this.invoke({
162
+ op: "move",
163
+ from: t,
164
+ to: e
165
+ });
166
+ });
167
+ }
168
+ exec(t, e, r) {
169
+ return g(this, null, function* () {
170
+ var h;
171
+ const s = this.begin(S({}, t), e, () => {
172
+ this.send({
173
+ protocol: k,
174
+ id: s,
175
+ op: "cancel"
176
+ });
177
+ });
178
+ let o = "", n = "", c = !1, a = !1;
179
+ for (; this.calls.has(s); ) {
180
+ const l = yield this.next(s);
181
+ if (l.op === "stdout" || l.op === "stderr") {
182
+ const p = String((h = l.text) != null ? h : "");
183
+ r == null || r(l.op, p), l.op === "stdout" ? (o += p, o.length > w && (c = !0), o = o.slice(-w)) : (n += p, n.length > w && (a = !0), n = n.slice(-w));
184
+ continue;
185
+ }
186
+ if (this.calls.delete(s), l.ok === !1)
187
+ throw d(String(l.name || "NotAllowedError"), String(l.message || "命令失败。"));
188
+ const f = typeof l.logPath == "string" ? l.logPath : void 0, u = l.logTruncated === !0;
189
+ return {
190
+ exitCode: typeof l.exitCode == "number" ? l.exitCode : 1,
191
+ timedOut: l.timedOut === !0,
192
+ stdout: x(o, c, f, u),
193
+ stderr: x(n, a, f, u),
194
+ cwd: typeof l.cwd == "string" ? l.cwd : void 0
195
+ };
196
+ }
197
+ throw d("AbortError", y);
198
+ });
199
+ }
200
+ invoke(t, e) {
201
+ const r = this.begin(t, e);
202
+ return this.next(r).then((s) => {
203
+ this.calls.delete(r);
204
+ const o = s;
205
+ if (o.ok === !1)
206
+ throw d(String(o.name || "NotAllowedError"), String(o.message || "请求失败。"));
207
+ return o;
208
+ });
209
+ }
210
+ begin(t, e, r) {
211
+ if (!this.ready)
212
+ throw d("NotAllowedError", this.unavailableMessage());
213
+ if (e != null && e.aborted)
214
+ throw d("AbortError");
215
+ const s = `sbx-${++this.seq}`;
216
+ let o = () => {
217
+ };
218
+ const n = {
219
+ messages: [],
220
+ waiters: [],
221
+ reject: (a) => o(a)
222
+ };
223
+ this.calls.set(s, n);
224
+ const c = () => {
225
+ r == null || r(), n.reject(d("AbortError"));
226
+ };
227
+ return e == null || e.addEventListener("abort", c, {
228
+ once: !0
229
+ }), o = (a) => {
230
+ e == null || e.removeEventListener("abort", c), this.calls.delete(s);
231
+ const h = n.waiters.shift();
232
+ h && h(Promise.reject(a));
233
+ }, this.send(S({
234
+ protocol: k,
235
+ id: s
236
+ }, t)), s;
237
+ }
238
+ next(t) {
239
+ const e = this.calls.get(t);
240
+ if (!e)
241
+ return Promise.reject(d("AbortError", y));
242
+ const r = e.messages.shift();
243
+ return r !== void 0 ? Promise.resolve(r) : new Promise((s, o) => {
244
+ e.waiters.push(s), e.reject = (n) => {
245
+ this.calls.delete(t), o(n);
246
+ };
247
+ });
248
+ }
249
+ send(t) {
250
+ var r;
251
+ const e = () => {
252
+ var o;
253
+ const s = t instanceof Uint8Array ? t : JSON.stringify(t);
254
+ (o = this.socket) == null || o.send(s);
255
+ };
256
+ this.authed && ((r = this.socket) == null ? void 0 : r.readyState) === 1 ? e() : this.outgoing.push(e);
257
+ }
258
+ connect(t, e) {
259
+ const r = ++this.generation, s = this.openSocket(t);
260
+ this.socket = s, this.authed = !1, s.binaryType = "arraybuffer", s.onopen = () => {
261
+ r === this.generation && s.send(JSON.stringify({
262
+ protocol: k,
263
+ op: "auth",
264
+ token: e
265
+ }));
266
+ }, s.onmessage = (o) => {
267
+ r === this.generation && this.onFrame(o.data);
268
+ }, s.onclose = () => {
269
+ r === this.generation && (this.authed = !1, this.failAll(d("AbortError", y)));
270
+ }, s.onerror = () => {
271
+ };
272
+ }
273
+ onFrame(t) {
274
+ const e = E(t);
275
+ if (e) {
276
+ const s = v(e);
277
+ this.push(s.id, e);
278
+ return;
279
+ }
280
+ let r;
281
+ try {
282
+ r = JSON.parse(String(t));
283
+ } catch (s) {
284
+ return;
285
+ }
286
+ if (r.op === "auth") {
287
+ if (r.ok === !0) {
288
+ this.authed = !0;
289
+ const s = this.outgoing;
290
+ this.outgoing = [], s.forEach((o) => o());
291
+ }
292
+ return;
293
+ }
294
+ if (r.op === "bye") {
295
+ this.failAll(d("AbortError", y)), this.stop();
296
+ return;
297
+ }
298
+ typeof r.id == "string" && this.push(r.id, r);
299
+ }
300
+ push(t, e) {
301
+ const r = this.calls.get(t);
302
+ if (!r)
303
+ return;
304
+ const s = r.waiters.shift();
305
+ s ? s(e) : r.messages.push(e);
306
+ }
307
+ failAll(t) {
308
+ for (const e of this.calls.values())
309
+ e.reject(t);
310
+ this.calls.clear();
311
+ }
312
+ stop() {
313
+ this.generation += 1, this.authed = !1, this.outgoing = [];
314
+ const t = this.socket;
315
+ this.socket = void 0;
316
+ try {
317
+ t == null || t.close();
318
+ } catch (e) {
319
+ }
320
+ }
321
+ }
322
+ export {
323
+ D as SandboxClient
324
+ };
@@ -0,0 +1,21 @@
1
+ const g = 1048576;
2
+ function f(e, o, c, n) {
3
+ const s = new TextEncoder().encode(e), t = new Uint8Array(4 + s.length + 8), i = new DataView(t.buffer);
4
+ i.setUint8(0, 1), i.setUint8(1, c ? 1 : 0), i.setUint16(2, s.length), t.set(s, 4), i.setBigUint64(4 + s.length, BigInt(o));
5
+ const r = new Uint8Array(t.length + n.length);
6
+ return r.set(t, 0), r.set(n, t.length), r;
7
+ }
8
+ function h(e) {
9
+ const o = new DataView(e.buffer, e.byteOffset, e.byteLength), n = 4 + o.getUint16(2), s = new TextDecoder().decode(e.subarray(4, n)), t = Number(o.getBigUint64(n)), i = (o.getUint8(1) & 1) === 1;
10
+ return {
11
+ id: s,
12
+ offset: t,
13
+ eof: i,
14
+ payload: e.subarray(n + 8)
15
+ };
16
+ }
17
+ export {
18
+ g as MAX_BINARY_PAYLOAD,
19
+ h as decodeBinaryFrame,
20
+ f as encodeBinaryFrame
21
+ };
@@ -0,0 +1,22 @@
1
+ var u = Object.defineProperty;
2
+ var n = Object.getOwnPropertySymbols;
3
+ var c = Object.prototype.hasOwnProperty, f = Object.prototype.propertyIsEnumerable;
4
+ var s = (r, e, t) => e in r ? u(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, m = (r, e) => {
5
+ for (var t in e || (e = {}))
6
+ c.call(e, t) && s(r, t, e[t]);
7
+ if (n)
8
+ for (var t of n(e))
9
+ f.call(e, t) && s(r, t, e[t]);
10
+ return r;
11
+ };
12
+ import { DEFAULT_LIMITS as o } from "./constants.mjs";
13
+ function l(r = {}) {
14
+ const e = m({}, o);
15
+ return Object.keys(o).forEach((t) => {
16
+ const i = r[t];
17
+ typeof i == "number" && Number.isFinite(i) && i > 0 && (e[t] = Math.min(i, o[t]));
18
+ }), e;
19
+ }
20
+ export {
21
+ l as resolveLimits
22
+ };
@@ -0,0 +1,312 @@
1
+ import { LOCAL_PYTHON_FUNCTION_CODE as s, WORKSPACE_GRANT_ID as p } from "./constants.mjs";
2
+ const t = "只操作用户在当前浏览器里选择的本地文件夹,路径相对该文件夹。云端工作区的文件不要用本工具。", e = {
3
+ type: "string",
4
+ enum: [p],
5
+ description: `工作区 ID。省略时按 ${p} 处理,传其他值会被拒绝。`
6
+ }, i = (n) => ({
7
+ type: "string",
8
+ description: `${n}使用相对工作区根目录的路径,以 / 分隔,不能包含 .. 或绝对路径。`
9
+ }), r = {
10
+ type: "string",
11
+ description: "文件当前内容的 hash(sha256:<hex>),来自 read_file 或 stat_file 的返回值。"
12
+ }, d = {
13
+ list_directory: {
14
+ functionCode: "list_directory",
15
+ name: "列出本地目录",
16
+ description: `${t}列出某个目录的直接子项(目录在前),支持分页。`,
17
+ parameters: {
18
+ type: "object",
19
+ required: ["grantId"],
20
+ properties: {
21
+ grantId: e,
22
+ path: i('要列出的目录,省略或传 "." 表示工作区根目录。'),
23
+ offset: {
24
+ type: "integer",
25
+ minimum: 0,
26
+ description: "分页起始位置,默认 0。"
27
+ },
28
+ limit: {
29
+ type: "integer",
30
+ minimum: 1,
31
+ maximum: 1e3,
32
+ description: "每页条数,默认 200。"
33
+ }
34
+ }
35
+ }
36
+ },
37
+ read_file: {
38
+ functionCode: "read_file",
39
+ name: "读取本地文件",
40
+ description: `${t}按行读取文本文件,单次最多返回 1 MiB,超出部分会被截断(truncated: true)。返回内容的 hash 可用于后续修改。`,
41
+ parameters: {
42
+ type: "object",
43
+ required: ["grantId", "path"],
44
+ properties: {
45
+ grantId: e,
46
+ path: i("要读取的文件。"),
47
+ startLine: {
48
+ type: "integer",
49
+ minimum: 1,
50
+ description: "起始行(从 1 开始,含)。"
51
+ },
52
+ endLine: {
53
+ type: "integer",
54
+ minimum: 1,
55
+ description: "结束行(含)。"
56
+ },
57
+ maxBytes: {
58
+ type: "integer",
59
+ minimum: 1,
60
+ description: "返回内容的最大字节数,不超过 1 MiB。"
61
+ },
62
+ encoding: {
63
+ type: "string",
64
+ enum: ["utf-8", "gbk", "gb18030"],
65
+ description: "文本编码,默认 utf-8。"
66
+ }
67
+ }
68
+ }
69
+ },
70
+ stat_file: {
71
+ functionCode: "stat_file",
72
+ name: "查看本地文件信息",
73
+ description: `${t}返回文件或目录的类型、大小、修改时间,可选返回 hash。不返回文件内容。`,
74
+ parameters: {
75
+ type: "object",
76
+ required: ["grantId", "path"],
77
+ properties: {
78
+ grantId: e,
79
+ path: i("要查看的文件或目录。"),
80
+ includeHash: {
81
+ type: "boolean",
82
+ description: "是否计算文件 hash。"
83
+ }
84
+ }
85
+ }
86
+ },
87
+ search_files: {
88
+ functionCode: "search_files",
89
+ name: "查找本地文件",
90
+ description: `${t}按文件名或 glob(支持 *、?、**)查找文件。不含 / 的模式匹配文件名,含 / 的模式匹配相对 path 的路径。`,
91
+ parameters: {
92
+ type: "object",
93
+ required: ["grantId", "pattern"],
94
+ properties: {
95
+ grantId: e,
96
+ pattern: {
97
+ type: "string",
98
+ minLength: 1,
99
+ description: "如 *.xlsx 或 reports/**/*.docx。"
100
+ },
101
+ path: i("搜索起点目录,默认工作区根目录。"),
102
+ maxDepth: {
103
+ type: "integer",
104
+ minimum: 1,
105
+ maximum: 16,
106
+ description: "最大目录深度,默认 8。"
107
+ },
108
+ maxResults: {
109
+ type: "integer",
110
+ minimum: 1,
111
+ maximum: 200,
112
+ description: "最多返回条数,默认 200。"
113
+ }
114
+ }
115
+ }
116
+ },
117
+ search_text: {
118
+ functionCode: "search_text",
119
+ name: "搜索本地文本",
120
+ description: `${t}在指定文件或目录(递归)中搜索普通文本(不支持正则),返回所在文件、行号与该行内容。必须指定 path,不能搜索整个文件夹。`,
121
+ parameters: {
122
+ type: "object",
123
+ required: ["grantId", "path", "query"],
124
+ properties: {
125
+ grantId: e,
126
+ path: i("搜索范围,可以是文件或目录。"),
127
+ query: {
128
+ type: "string",
129
+ minLength: 1,
130
+ description: "要查找的文本。"
131
+ },
132
+ caseSensitive: {
133
+ type: "boolean",
134
+ description: "是否区分大小写,默认否。"
135
+ },
136
+ isRegex: {
137
+ type: "boolean",
138
+ description: "暂不支持正则,传 true 会返回 501。"
139
+ },
140
+ glob: {
141
+ type: "string",
142
+ description: "只搜索匹配该 glob 的文件,如 *.md。"
143
+ },
144
+ maxResults: {
145
+ type: "integer",
146
+ minimum: 1,
147
+ maximum: 200,
148
+ description: "最多返回条数,默认 200。"
149
+ },
150
+ contextLines: {
151
+ type: "integer",
152
+ minimum: 0,
153
+ maximum: 3,
154
+ description: "附带的上下文行数,默认 0。"
155
+ }
156
+ }
157
+ }
158
+ },
159
+ apply_patch: {
160
+ functionCode: "apply_patch",
161
+ name: "修改本地文件",
162
+ description: `${t}以查找替换的方式修改 UTF-8 文本文件。每条修改的 oldText 必须在文件中唯一出现(或设置 replaceAll)。执行前需要用户确认。`,
163
+ parameters: {
164
+ type: "object",
165
+ required: ["grantId", "path", "expectedHash", "edits"],
166
+ properties: {
167
+ grantId: e,
168
+ path: i("要修改的文件。"),
169
+ expectedHash: r,
170
+ edits: {
171
+ type: "array",
172
+ minItems: 1,
173
+ description: "按顺序应用的修改。",
174
+ items: {
175
+ type: "object",
176
+ required: ["oldText", "newText"],
177
+ properties: {
178
+ oldText: {
179
+ type: "string",
180
+ minLength: 1,
181
+ description: "要替换的原文,需包含足够上下文以保证唯一。"
182
+ },
183
+ newText: {
184
+ type: "string",
185
+ description: "替换后的文本。"
186
+ },
187
+ replaceAll: {
188
+ type: "boolean",
189
+ description: "是否替换所有出现位置,默认否。"
190
+ }
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ },
197
+ write_file: {
198
+ functionCode: "write_file",
199
+ name: "写入本地文件",
200
+ description: `${t}新建文件,或整体覆盖已有文件(覆盖时必须提供 expectedHash)。修改已有文件优先使用 apply_patch。执行前需要用户确认。`,
201
+ parameters: {
202
+ type: "object",
203
+ required: ["grantId", "path", "content"],
204
+ properties: {
205
+ grantId: e,
206
+ path: i("要写入的文件。"),
207
+ content: {
208
+ type: "string",
209
+ description: "完整的文件内容(UTF-8)。"
210
+ },
211
+ expectedHash: r,
212
+ createDirectories: {
213
+ type: "boolean",
214
+ description: "父目录不存在时是否自动创建,默认否。"
215
+ }
216
+ }
217
+ }
218
+ },
219
+ upload_file: {
220
+ functionCode: "upload_file",
221
+ name: "上传本地文件",
222
+ description: `${t}把本地文件夹中的文件上传到平台文件服务,返回 fileId、name、size 和 url。url 是文件访问地址,可直接用于后续推理或对话。下载回本地文件夹时使用 download_file,source.type 为 platformFile。单文件不超过 50 MB。执行前需要用户确认。`,
223
+ parameters: {
224
+ type: "object",
225
+ required: ["grantId", "path"],
226
+ properties: {
227
+ grantId: e,
228
+ path: i("要上传的文件。"),
229
+ target: {
230
+ type: "string",
231
+ description: "上传目标,目前只支持 session(默认),其他值返回 501。"
232
+ },
233
+ mimeHint: {
234
+ type: "string",
235
+ description: "可选的 MIME 类型。"
236
+ }
237
+ }
238
+ }
239
+ },
240
+ download_file: {
241
+ functionCode: "download_file",
242
+ name: "下载到本地文件夹",
243
+ description: `${t}把会话文件、平台文件或 https 地址保存到本地文件夹。source.type 为 url 时必须同时填写 source.url(完整地址),为 sessionFile 或 platformFile 时必须同时填写 source.fileId。不要只传 type。单文件不超过 50 MB。执行前需要用户确认。`,
244
+ parameters: {
245
+ type: "object",
246
+ required: ["grantId", "destPath", "source"],
247
+ properties: {
248
+ grantId: e,
249
+ destPath: i("保存位置(文件路径)。"),
250
+ source: {
251
+ type: "object",
252
+ required: ["type"],
253
+ description: "下载来源。type 为 url 时必填 url;type 为 sessionFile 或 platformFile 时必填 fileId。",
254
+ properties: {
255
+ type: {
256
+ type: "string",
257
+ enum: ["sessionFile", "platformFile", "url"],
258
+ description: "sessionFile:当前会话文件;platformFile:平台文件(upload_file 返回的 fileId);url:https 地址。"
259
+ },
260
+ fileId: {
261
+ type: "string",
262
+ description: "type 为 sessionFile 或 platformFile 时必填,不能只传 type。"
263
+ },
264
+ url: {
265
+ type: "string",
266
+ description: "type 为 url 时必填,填写完整 https 地址。不能只传 type。默认只允许 glodon.com 及其子域。"
267
+ }
268
+ }
269
+ },
270
+ overwrite: {
271
+ type: "boolean",
272
+ description: "目标已存在时是否覆盖,默认否。"
273
+ },
274
+ expectedHash: r
275
+ }
276
+ }
277
+ }
278
+ }, o = "在已绑定的本地工程目录中运行已有 .py,路径相对该目录。不要用于云端工作区,不要传 shell 或代码,只能传 path 和 args。", c = {
279
+ functionCode: s,
280
+ name: "运行本地 Python 脚本",
281
+ description: `${o}每次运行需用户单独确认,文件读写授权不能代替。确认后脚本可直接读写该目录并使用标准库,改动立即落盘。不能联网,不能在运行中安装包,也不能访问该目录以外的文件。第三方包写在工程根目录 sandbox-requirements.txt。结果打印到标准输出。code 为 0 只表示已结束,成功看 data.exitCode,超时看 data.timedOut。`,
282
+ parameters: {
283
+ type: "object",
284
+ required: ["grantId", "path"],
285
+ properties: {
286
+ grantId: e,
287
+ path: {
288
+ type: "string",
289
+ description: "要运行的脚本。必须是已存在、以 .py 结尾的相对路径,以 / 分隔,不能包含 .. 、盘符或绝对路径。"
290
+ },
291
+ args: {
292
+ type: "array",
293
+ maxItems: 16,
294
+ description: "传给脚本的参数,最多 16 个。每个参数单独一项,不能含空格、引号或 shell 语法,只能包含字母、数字、下划线以及 . / : @ = + - , 。",
295
+ items: {
296
+ type: "string",
297
+ description: "一个脚本参数。"
298
+ }
299
+ },
300
+ timeoutMs: {
301
+ type: "integer",
302
+ minimum: 1e3,
303
+ maximum: 12e4,
304
+ description: "超时毫秒数。默认 20000,最大 120000。到时脚本会被终止。"
305
+ }
306
+ }
307
+ }
308
+ };
309
+ export {
310
+ d as LOCAL_FILE_TOOL_SCHEMAS,
311
+ c as LOCAL_PYTHON_TOOL_SCHEMA
312
+ };