@glodon-aiot/bot-client-sdk 3.26.0-alpha.28 → 3.26.0-alpha.30
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.
- package/README.md +1 -1
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +66 -64
- package/dist/es/builtinTools/paths.mjs +6 -5
- package/dist/es/builtinTools/schemas.mjs +7 -7
- package/dist/es/localFiles/errors.mjs +41 -34
- package/dist/es/localFiles/host/sandboxClient.mjs +169 -176
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +40 -40
- package/dist/src/builtinTools/paths.d.ts +2 -2
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/sandboxClient.d.ts +6 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -543,7 +543,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
543
543
|
- 文件被其他程序占用时原文件保持不变,错误是「文件正在被占用,没有写入。」
|
|
544
544
|
- 随安装包分发:`Resources/node/`(Node 24)+ `Resources/workspace-sandbox/`(`yarn bundle --platform …` 产物),可选 `python/`
|
|
545
545
|
- 输出做路径反向替换,页面看不到工程绝对路径,也看不到技能缓存的绝对路径
|
|
546
|
-
- 默认断网。`allowlist` 下被拒绝的 `host:port` 追加在 `stderr
|
|
546
|
+
- 默认断网。`allowlist` 下被拒绝的 `host:port` 追加在 `stderr`:「宿主网络策略拒绝了:…。不要重试这些地址;需要时请用户在宿主设置里允许。」宿主允许安装时,`pip install` 直接装进工程 venv,不要求先把网络改成 `open`。其他 pip 子命令仍要 `open`,或把包名写进工程根的 `sandbox-requirements.txt`。宿主关闭安装后,工程里有这个文件的命令不会运行。策略文件格式见 `@glodon-aiot/workspace-sandbox` 的 README
|
|
547
547
|
- 平台技能:进入会话时按编排 `arrange[0].skills` 核对已发布版本(`version >= 1`)。页面用当时的 `client.token` 作 `Authorization: Bearer` 下载 ZIP,再经已认证的本地 WebSocket 交给沙箱 `installSkill`。沙箱收不到这个令牌。缓存按系统放在用户目录(Windows `%LOCALAPPDATA%\glodon-workspace-sandbox`,macOS `~/Library/Caches/glodon-workspace-sandbox`,Linux `$XDG_CACHE_HOME` 或 `~/.cache` 下的同名目录),不在工程内。删除会话不删缓存;编排不再引用且没有脚本在跑的版本,下次进入会话时删除。非 debug 的对话气泡不显示这三个技能工具
|
|
548
548
|
- 细节与 Windows 步骤见 [`local-workspace-windows-host.md`](../bot-client-ui/docs/local-workspace-windows-host.md)
|
|
549
549
|
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
var
|
|
1
|
+
var W = 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 j = (e, t,
|
|
6
|
-
for (var
|
|
7
|
-
Y.call(t,
|
|
5
|
+
var j = (e, t, o) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o, l = (e, t) => {
|
|
6
|
+
for (var o in t || (t = {}))
|
|
7
|
+
Y.call(t, o) && j(e, o, t[o]);
|
|
8
8
|
if (C)
|
|
9
|
-
for (var
|
|
10
|
-
Z.call(t,
|
|
9
|
+
for (var o of C(t))
|
|
10
|
+
Z.call(t, o) && j(e, o, t[o]);
|
|
11
11
|
return e;
|
|
12
12
|
}, _ = (e, t) => X(e, Q(t));
|
|
13
|
-
var H = (e, t,
|
|
14
|
-
var d = (
|
|
13
|
+
var H = (e, t, o) => new Promise((n, m) => {
|
|
14
|
+
var d = (r) => {
|
|
15
15
|
try {
|
|
16
|
-
c(
|
|
16
|
+
c(o.next(r));
|
|
17
17
|
} catch (i) {
|
|
18
18
|
m(i);
|
|
19
19
|
}
|
|
20
|
-
}, f = (
|
|
20
|
+
}, f = (r) => {
|
|
21
21
|
try {
|
|
22
|
-
c(
|
|
22
|
+
c(o.throw(r));
|
|
23
23
|
} catch (i) {
|
|
24
24
|
m(i);
|
|
25
25
|
}
|
|
26
|
-
}, c = (
|
|
27
|
-
c((
|
|
26
|
+
}, c = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(d, f);
|
|
27
|
+
c((o = o.apply(e, t)).next());
|
|
28
28
|
});
|
|
29
29
|
import { v4 as ee } from "uuid";
|
|
30
30
|
import te from "../Logger.mjs";
|
|
31
31
|
import { HostBridgeAdapter as V } from "../localFiles/adapters/HostBridgeAdapter.mjs";
|
|
32
32
|
import { domError as $ } from "../localFiles/adapters/WorkspaceFileAdapter.mjs";
|
|
33
|
-
import { SANDBOX_PROTOCOL as
|
|
34
|
-
import { cancelledError as T, workspaceNotGranted as
|
|
33
|
+
import { SANDBOX_PROTOCOL as oe } from "../localFiles/host/protocol.mjs";
|
|
34
|
+
import { cancelledError as T, workspaceNotGranted as ne, ToolError as u, ToolCode as a, toToolError as re } from "../localFiles/errors.mjs";
|
|
35
35
|
import { validateToolInput as ie } from "../localFiles/validate.mjs";
|
|
36
36
|
import { BrowserCommandRunner as se } from "./browserRuntime/BrowserCommandRunner.mjs";
|
|
37
37
|
import { withOutputLimit as L } from "./command.mjs";
|
|
38
38
|
import { BUILTIN_FUNCTION_CODES as le, SHELL_CWD as ae } from "./constants.mjs";
|
|
39
39
|
import { BUILTIN_TOOL_SCHEMAS as de } from "./schemas.mjs";
|
|
40
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 Te, grepSkill as we, runSkillScript as Ie } from "./tools.mjs";
|
|
41
|
-
const
|
|
41
|
+
const Ee = {
|
|
42
42
|
shell: ce,
|
|
43
43
|
read_file: me,
|
|
44
44
|
write_file: ue,
|
|
@@ -53,17 +53,17 @@ const pe = {
|
|
|
53
53
|
grep_skill: we,
|
|
54
54
|
run_skill_script: Ie
|
|
55
55
|
}, x = new te("[BuiltinTools] "), S = /* @__PURE__ */ new Set(["shell", "run_file", "run_skill_script"]);
|
|
56
|
-
function
|
|
57
|
-
var
|
|
56
|
+
function pe(e, t, o) {
|
|
57
|
+
var n, m;
|
|
58
58
|
if (e.commandRunner)
|
|
59
59
|
return L(e.commandRunner);
|
|
60
60
|
if (t instanceof V) {
|
|
61
61
|
if (t.protocolMismatch) {
|
|
62
|
-
const d = `${(
|
|
63
|
-
|
|
62
|
+
const d = `${(n = t.sandboxVersion) != null ? n : ""}@${(m = t.sandboxProtocol) != null ? m : ""}`;
|
|
63
|
+
o.rejectedSandbox !== d && (o.rejectedSandbox = d, x.error("sandbox-protocol", {
|
|
64
64
|
sandboxVersion: t.sandboxVersion,
|
|
65
65
|
sandboxProtocol: t.sandboxProtocol,
|
|
66
|
-
supported:
|
|
66
|
+
supported: oe
|
|
67
67
|
}));
|
|
68
68
|
}
|
|
69
69
|
if (!t.canExec) {
|
|
@@ -77,25 +77,25 @@ function Ee(e, t, n) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
if (e.browserRuntime.enabled)
|
|
80
|
-
return (
|
|
80
|
+
return (o.adapter !== t || !o.runner) && (o.adapter = t, o.runner = L(new se({
|
|
81
81
|
adapter: t,
|
|
82
82
|
sensitive: e.sensitive,
|
|
83
83
|
moduleURL: e.browserRuntime.bashModuleURL,
|
|
84
84
|
pyodideIndexURL: e.browserRuntime.pyodideIndexURL
|
|
85
|
-
}))),
|
|
85
|
+
}))), o.runner;
|
|
86
86
|
}
|
|
87
87
|
function Oe(e, t) {
|
|
88
88
|
if (e.commandRunner)
|
|
89
89
|
return L(e.commandRunner);
|
|
90
90
|
if (t instanceof V) {
|
|
91
91
|
if (!t.canExec) {
|
|
92
|
-
const
|
|
92
|
+
const o = t.unavailableMessage();
|
|
93
93
|
return {
|
|
94
|
-
exec: () => Promise.reject($("NotAllowedError",
|
|
94
|
+
exec: () => Promise.reject($("NotAllowedError", o))
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
return {
|
|
98
|
-
exec: (
|
|
98
|
+
exec: (o) => t.exec(o)
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -109,19 +109,21 @@ function Re(e) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
function Se(e) {
|
|
112
|
-
const t = e instanceof DOMException ? e.name : "",
|
|
112
|
+
const t = e instanceof DOMException ? e.name : "", o = e instanceof Error ? e.message : "";
|
|
113
113
|
if (t === "NotFoundError")
|
|
114
114
|
return new u(a.NotFound, "脚本或目录不存在。");
|
|
115
115
|
if (t === "SecurityError")
|
|
116
116
|
return new u(a.Forbidden, "命令路径不在工作区内。");
|
|
117
117
|
if (t === "AbortError")
|
|
118
|
-
return
|
|
119
|
-
if (t === "NotAllowedError")
|
|
120
|
-
|
|
118
|
+
return o.includes("超时") ? new u(a.Timeout, "命令运行超时,已中止。") : o.includes("已有") || o.includes("上限") ? new u(a.TooManyRequests, o) : T();
|
|
119
|
+
if (t === "NotAllowedError") {
|
|
120
|
+
const n = o.trim();
|
|
121
|
+
return n && n !== "NotAllowedError" ? new u(a.NotImplemented, n) : new u(a.NotImplemented, "当前环境不能执行命令或脚本,需要端侧宿主。");
|
|
122
|
+
}
|
|
121
123
|
}
|
|
122
124
|
function Le(e) {
|
|
123
|
-
return new Promise((t,
|
|
124
|
-
e.aborted &&
|
|
125
|
+
return new Promise((t, o) => {
|
|
126
|
+
e.aborted && o(T()), e.addEventListener("abort", () => o(T()), {
|
|
125
127
|
once: !0
|
|
126
128
|
});
|
|
127
129
|
});
|
|
@@ -131,8 +133,8 @@ function k(e, t = 160) {
|
|
|
131
133
|
}
|
|
132
134
|
function Ne(e) {
|
|
133
135
|
const t = {};
|
|
134
|
-
for (const
|
|
135
|
-
typeof e[
|
|
136
|
+
for (const o of ["path", "skill_name", "resource_name", "script_name", "pattern", "name"])
|
|
137
|
+
typeof e[o] == "string" && (t[o] = e[o]);
|
|
136
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;
|
|
137
139
|
}
|
|
138
140
|
function Me(e) {
|
|
@@ -147,11 +149,11 @@ function Je({
|
|
|
147
149
|
pluginCode: e,
|
|
148
150
|
workspace: t
|
|
149
151
|
}) {
|
|
150
|
-
const
|
|
152
|
+
const o = /* @__PURE__ */ new Map(), n = {}, m = {};
|
|
151
153
|
return le.forEach((d) => {
|
|
152
|
-
m[d] = (f, c,
|
|
154
|
+
m[d] = (f, c, r) => {
|
|
153
155
|
let i = !1;
|
|
154
|
-
Fe(t,
|
|
156
|
+
Fe(t, o, n, d, f, (I) => {
|
|
155
157
|
if (!i) {
|
|
156
158
|
i = !0;
|
|
157
159
|
try {
|
|
@@ -160,7 +162,7 @@ function Je({
|
|
|
160
162
|
console.error("[BuiltinTools] callback failed", R);
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
|
-
}, _(l({},
|
|
165
|
+
}, _(l({}, r), {
|
|
164
166
|
pluginCode: e
|
|
165
167
|
}));
|
|
166
168
|
};
|
|
@@ -168,7 +170,7 @@ function Je({
|
|
|
168
170
|
[e]: m
|
|
169
171
|
};
|
|
170
172
|
}
|
|
171
|
-
function Fe(e, t,
|
|
173
|
+
function Fe(e, t, o, n, m, d, f) {
|
|
172
174
|
return H(this, null, function* () {
|
|
173
175
|
var F, A, v, q, B;
|
|
174
176
|
const c = {
|
|
@@ -176,41 +178,41 @@ function Fe(e, t, n, r, m, d, f) {
|
|
|
176
178
|
applicationId: f.applicationId || e.applicationId,
|
|
177
179
|
sessionId: f.sessionId || "",
|
|
178
180
|
pluginCode: f.pluginCode,
|
|
179
|
-
functionCode:
|
|
181
|
+
functionCode: n,
|
|
180
182
|
signal: f.signal
|
|
181
|
-
},
|
|
183
|
+
}, r = {
|
|
182
184
|
requestId: c.requestId,
|
|
183
185
|
sessionId: c.sessionId,
|
|
184
|
-
functionCode:
|
|
186
|
+
functionCode: n
|
|
185
187
|
}, i = new AbortController();
|
|
186
188
|
let w = !1;
|
|
187
|
-
const I = S.has(
|
|
189
|
+
const I = S.has(n) ? e.limits.commandTimeoutMs : e.limits.toolTimeoutMs, R = setTimeout(() => {
|
|
188
190
|
w = !0, i.abort();
|
|
189
191
|
}, I), N = () => i.abort();
|
|
190
192
|
(F = c.signal) == null || F.addEventListener("abort", N, {
|
|
191
193
|
once: !0
|
|
192
194
|
}), (A = c.signal) != null && A.aborted && i.abort();
|
|
193
|
-
let b = null, y = null,
|
|
195
|
+
let b = null, y = null, E;
|
|
194
196
|
const M = Date.now();
|
|
195
197
|
try {
|
|
196
|
-
const
|
|
197
|
-
if (typeof s.path == "string" && (
|
|
198
|
+
const p = Re(m), s = ie(p, de[n].parameters);
|
|
199
|
+
if (typeof s.path == "string" && (r.path = s.path), x.log("start", l(l({}, r), Ne(s))), yield e.ready, i.signal.aborted)
|
|
198
200
|
throw T();
|
|
199
201
|
const g = e.adapter;
|
|
200
202
|
if (!g)
|
|
201
|
-
throw
|
|
202
|
-
if (S.has(
|
|
203
|
+
throw ne();
|
|
204
|
+
if (S.has(n)) {
|
|
203
205
|
if (y = e.acquireCommand(), !y)
|
|
204
206
|
throw new u(a.TooManyRequests, "已有一个命令在运行,请等它结束后再试。");
|
|
205
207
|
} else if (b = e.acquireSlot(), !b)
|
|
206
208
|
throw new u(a.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
|
|
207
|
-
|
|
209
|
+
E = e.track(i), e.emit("tool:start", l({}, r));
|
|
208
210
|
const P = c.sessionId || "default";
|
|
209
211
|
let h = t.get(P);
|
|
210
212
|
h || (h = {
|
|
211
213
|
cwd: ae
|
|
212
214
|
}, t.set(P, h));
|
|
213
|
-
const J =
|
|
215
|
+
const J = pe(e, g, o), z = h.cwd, G = {
|
|
214
216
|
adapter: g,
|
|
215
217
|
runner: J,
|
|
216
218
|
signal: i.signal,
|
|
@@ -218,44 +220,44 @@ function Fe(e, t, n, r, m, d, f) {
|
|
|
218
220
|
shellCwd: h,
|
|
219
221
|
skills: e.platformSkills,
|
|
220
222
|
skillRunner: Oe(e, g)
|
|
221
|
-
}, O = yield Promise.race([
|
|
223
|
+
}, O = yield Promise.race([Ee[n](s, G), Le(i.signal)]), D = {
|
|
222
224
|
code: a.Ok,
|
|
223
225
|
message: "ok",
|
|
224
226
|
data: O.data
|
|
225
227
|
};
|
|
226
228
|
O.truncated && (D.truncated = !0);
|
|
227
|
-
const
|
|
228
|
-
x.log("finish", l(l(l(_(l({},
|
|
229
|
-
elapsedMs:
|
|
229
|
+
const K = Date.now() - M, U = O.data.exitCode;
|
|
230
|
+
x.log("finish", l(l(l(_(l({}, r), {
|
|
231
|
+
elapsedMs: K,
|
|
230
232
|
code: a.Ok
|
|
231
233
|
}), O.truncated ? {
|
|
232
234
|
truncated: !0
|
|
233
235
|
} : {}), typeof U == "number" ? {
|
|
234
236
|
exitCode: U
|
|
235
|
-
} : {}),
|
|
237
|
+
} : {}), n === "shell" ? {
|
|
236
238
|
cwd: h.cwd,
|
|
237
|
-
cwdChanged: h.cwd !==
|
|
238
|
-
} : {})), e.emit("tool:finish", _(l({},
|
|
239
|
+
cwdChanged: h.cwd !== z
|
|
240
|
+
} : {})), e.emit("tool:finish", _(l({}, r), {
|
|
239
241
|
code: a.Ok
|
|
240
|
-
})), S.has(
|
|
241
|
-
} catch (
|
|
242
|
-
let s = (v = Se(
|
|
242
|
+
})), S.has(n) && e.notifyFilesChanged(), d(D);
|
|
243
|
+
} catch (p) {
|
|
244
|
+
let s = (v = Se(p)) != null ? v : re(p);
|
|
243
245
|
w ? s = new u(a.Timeout, "操作超时,已中止。") : i.signal.aborted && s.code !== a.Cancelled && (s = T());
|
|
244
246
|
const g = Date.now() - M;
|
|
245
|
-
s.code === a.Cancelled ? (x.log("cancelled", _(l({},
|
|
247
|
+
s.code === a.Cancelled ? (x.log("cancelled", _(l({}, r), {
|
|
246
248
|
elapsedMs: g,
|
|
247
249
|
timedOut: w
|
|
248
|
-
})), e.emit("tool:cancelled", l({},
|
|
250
|
+
})), e.emit("tool:cancelled", l({}, r))) : (x.error("error", _(l({}, r), {
|
|
249
251
|
elapsedMs: g,
|
|
250
252
|
code: s.code,
|
|
251
253
|
message: k(s.message, 300)
|
|
252
|
-
})), e.emit("tool:error", _(l({},
|
|
254
|
+
})), e.emit("tool:error", _(l({}, r), {
|
|
253
255
|
code: s.code,
|
|
254
256
|
message: s.message,
|
|
255
257
|
reason: (q = s.data) == null ? void 0 : q.reason
|
|
256
258
|
}))), d(Me(s));
|
|
257
259
|
} finally {
|
|
258
|
-
clearTimeout(R), (B = c.signal) == null || B.removeEventListener("abort", N), b == null || b(), y == null || y(),
|
|
260
|
+
clearTimeout(R), (B = c.signal) == null || B.removeEventListener("abort", N), b == null || b(), y == null || y(), E == null || E();
|
|
259
261
|
}
|
|
260
262
|
});
|
|
261
263
|
}
|
|
@@ -17,13 +17,14 @@ function r(t) {
|
|
|
17
17
|
}
|
|
18
18
|
function l(t) {
|
|
19
19
|
if (typeof t != "string" || t.length === 0)
|
|
20
|
-
throw new o(i.BadRequest, "path
|
|
20
|
+
throw new o(i.BadRequest, "path 必须是工作区内路径。");
|
|
21
21
|
(t.includes("\0") || t.includes("\\")) && r("路径不能包含反斜杠。");
|
|
22
22
|
const n = t.normalize("NFC").trim();
|
|
23
|
-
if (!n
|
|
24
|
-
throw new o(i.BadRequest, "path
|
|
25
|
-
|
|
26
|
-
|
|
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]))
|
|
27
28
|
throw new o(i.BadRequest, c);
|
|
28
29
|
if (e[0] === "skills")
|
|
29
30
|
throw new o(i.Forbidden, "技能文件只能通过技能工具访问。");
|
|
@@ -3,7 +3,7 @@ const e = (i) => ({
|
|
|
3
3
|
type: "string",
|
|
4
4
|
minLength: 1,
|
|
5
5
|
description: i
|
|
6
|
-
}), n = "脚本能否联网由运行环境决定;被宿主网络策略拒绝的地址会在结果里列出。", t = "
|
|
6
|
+
}), n = "脚本能否联网由运行环境决定;被宿主网络策略拒绝的地址会在结果里列出。", t = "必填。工作区内路径。以 / 开头,例如 /说明.md;也可以不写开头的斜杠,例如 notes/a.md。不要使用 input、output、uploads、tmp,也不要新建这些目录。", a = {
|
|
7
7
|
shell: {
|
|
8
8
|
functionCode: "shell",
|
|
9
9
|
name: "执行命令",
|
|
@@ -24,7 +24,7 @@ const e = (i) => ({
|
|
|
24
24
|
read_file: {
|
|
25
25
|
functionCode: "read_file",
|
|
26
26
|
name: "读取文件",
|
|
27
|
-
description: "
|
|
27
|
+
description: "读取工作区内的文本文件并返回内容;读不到时返回失败原因。path 可以以 / 开头,也可以不写开头的斜杠。未超过上限的文本按原文返回;超过单次读取上限的结构化文本(JSON/XML/SVG/CSV/TSV)会先附带通用结构概览和短预览,需要特定片段时再用 start_line 和 end_line。PDF 和图片只返回文件摘要,不返回正文。",
|
|
28
28
|
parameters: {
|
|
29
29
|
type: "object",
|
|
30
30
|
required: ["path"],
|
|
@@ -46,7 +46,7 @@ const e = (i) => ({
|
|
|
46
46
|
write_file: {
|
|
47
47
|
functionCode: "write_file",
|
|
48
48
|
name: "写入文件",
|
|
49
|
-
description:
|
|
49
|
+
description: `把文本写入工作区内文件。path 可以是以 / 开头的工作区路径,也可以不带开头斜杠,例如 /说明.md、notes/a.md。文件已存在时覆盖。单次覆盖写入按 UTF-8 字节计,默认不超过 ${r} 字节。超限时先写一段,再用 edit_file 修改,或用 append_file 追加下一段。SVG 和整页 HTML 由工作区里的脚本生成,不要直接放进 content。`,
|
|
50
50
|
parameters: {
|
|
51
51
|
type: "object",
|
|
52
52
|
required: ["path", "content"],
|
|
@@ -62,7 +62,7 @@ const e = (i) => ({
|
|
|
62
62
|
append_file: {
|
|
63
63
|
functionCode: "append_file",
|
|
64
64
|
name: "追加文件",
|
|
65
|
-
description: "
|
|
65
|
+
description: "把一段文本追加到工作区内文件末尾。path 可以以 / 开头,也可以不写开头的斜杠。文件不存在时创建。覆盖写入超过字节上限时,用本工具把下一段接到同一文件。追加不设字节上限,但不要在一次调用里放入整份 HTML 或 SVG。",
|
|
66
66
|
parameters: {
|
|
67
67
|
type: "object",
|
|
68
68
|
required: ["path", "content"],
|
|
@@ -83,7 +83,7 @@ const e = (i) => ({
|
|
|
83
83
|
type: "object",
|
|
84
84
|
required: ["path"],
|
|
85
85
|
properties: {
|
|
86
|
-
path: e("必填。要执行的 .py、.sh、.bash、.js、.mjs 或 .cjs
|
|
86
|
+
path: e("必填。要执行的 .py、.sh、.bash、.js、.mjs 或 .cjs 文件。可以是 /scripts/gen.py,也可以是 scripts/gen.py。")
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
},
|
|
@@ -111,7 +111,7 @@ const e = (i) => ({
|
|
|
111
111
|
grep: {
|
|
112
112
|
functionCode: "grep",
|
|
113
113
|
name: "搜索文件",
|
|
114
|
-
description: "在工作区目录中递归搜索文本,返回带行号的匹配行。path
|
|
114
|
+
description: "在工作区目录中递归搜索文本,返回带行号的匹配行。path 可以以 / 开头,也可以不写开头的斜杠。pattern 按 grep 基本正则匹配。用于定位内容,不要用来取回大文件全文。",
|
|
115
115
|
parameters: {
|
|
116
116
|
type: "object",
|
|
117
117
|
required: ["path", "pattern"],
|
|
@@ -128,7 +128,7 @@ const e = (i) => ({
|
|
|
128
128
|
find: {
|
|
129
129
|
functionCode: "find",
|
|
130
130
|
name: "查找文件",
|
|
131
|
-
description: "按文件名通配在工作区目录中查找文件。path
|
|
131
|
+
description: "按文件名通配在工作区目录中查找文件。path 为起始路径,可以以 / 开头,也可以不写开头的斜杠。name 传给 find 的 -name,例如 *.html。",
|
|
132
132
|
parameters: {
|
|
133
133
|
type: "object",
|
|
134
134
|
required: ["path", "name"],
|
|
@@ -1,59 +1,66 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var w = /* @__PURE__ */ ((
|
|
5
|
-
class
|
|
6
|
-
constructor(n,
|
|
7
|
-
super(
|
|
8
|
-
|
|
9
|
-
|
|
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
10
|
this.name = "ToolError", this.code = n, this.data = i;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
return new
|
|
13
|
+
const m = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
|
|
14
|
+
function d() {
|
|
15
|
+
return new r(403, m, {
|
|
16
16
|
reason: "workspace_not_granted"
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return new
|
|
19
|
+
function u() {
|
|
20
|
+
return new r(499, "操作已取消。");
|
|
21
21
|
}
|
|
22
|
-
function N(
|
|
23
|
-
if (
|
|
24
|
-
throw
|
|
22
|
+
function N(t) {
|
|
23
|
+
if (t != null && t.aborted)
|
|
24
|
+
throw u();
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
36
|
+
return new r(404, "文件或目录不存在。");
|
|
32
37
|
case "TypeMismatchError":
|
|
33
|
-
return new
|
|
38
|
+
return new r(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
|
|
34
39
|
case "NotAllowedError":
|
|
35
40
|
case "SecurityError":
|
|
36
|
-
return
|
|
41
|
+
return d();
|
|
37
42
|
case "AbortError":
|
|
38
|
-
return
|
|
43
|
+
return u();
|
|
39
44
|
case "NoModificationAllowedError":
|
|
40
45
|
case "InvalidModificationError":
|
|
41
46
|
case "InvalidStateError":
|
|
42
|
-
return new
|
|
47
|
+
return new r(403, "文件当前不可写,可能正被其他程序占用或为只读。");
|
|
43
48
|
case "QuotaExceededError":
|
|
44
|
-
return new
|
|
49
|
+
return new r(413, (n = c(t)) != null ? n : "磁盘空间不足或超出写入配额。");
|
|
50
|
+
case "TooManyRequestsError":
|
|
51
|
+
return new r(429, (a = c(t)) != null ? a : "排队的文件操作过多,请稍后重试。");
|
|
45
52
|
case "PreviewLimitError":
|
|
46
|
-
return new
|
|
53
|
+
return new r(413, "同时预览的文件过多,请先关掉一些预览。");
|
|
47
54
|
default:
|
|
48
|
-
return new
|
|
55
|
+
return new r(500, "本地文件操作失败,请稍后重试。");
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
export {
|
|
52
59
|
w as ToolCode,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
r as ToolError,
|
|
61
|
+
m as WORKSPACE_NOT_GRANTED_MESSAGE,
|
|
62
|
+
u as cancelledError,
|
|
56
63
|
N as throwIfAborted,
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
p as toToolError,
|
|
65
|
+
d as workspaceNotGranted
|
|
59
66
|
};
|