@glodon-aiot/bot-client-sdk 3.26.0-alpha.8 → 3.26.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 (99) hide show
  1. package/README.md +284 -254
  2. package/dist/es/AgentSession.mjs +267 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +55 -88
  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/browserRuntime/BrowserCommandRunner.mjs +201 -0
  11. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  12. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  13. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  14. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  15. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  16. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  17. package/dist/es/builtinTools/command.mjs +56 -0
  18. package/dist/es/builtinTools/constants.mjs +17 -0
  19. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +266 -0
  20. package/dist/es/builtinTools/overview.mjs +77 -0
  21. package/dist/es/builtinTools/paths.mjs +70 -0
  22. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  23. package/dist/es/builtinTools/schemas.mjs +261 -0
  24. package/dist/es/builtinTools/tools.mjs +595 -0
  25. package/dist/es/index.mjs +66 -64
  26. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  27. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
  28. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
  29. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  30. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  31. package/dist/es/localFiles/constants.mjs +24 -28
  32. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  33. package/dist/es/localFiles/errors.mjs +44 -35
  34. package/dist/es/localFiles/host/connectHostBridge.mjs +43 -35
  35. package/dist/es/localFiles/host/protocol.mjs +27 -13
  36. package/dist/es/localFiles/host/sandboxClient.mjs +494 -0
  37. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  38. package/dist/es/localFiles/preview.mjs +33 -0
  39. package/dist/es/localFiles/schemas.mjs +40 -86
  40. package/dist/es/localFiles/validate.mjs +37 -37
  41. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +176 -90
  42. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  43. package/dist/es/localMcp/client.mjs +234 -0
  44. package/dist/es/localMcp/endpoints.mjs +94 -0
  45. package/dist/es/localMcp/register.mjs +207 -0
  46. package/dist/es/localMcp/registry.mjs +43 -0
  47. package/dist/es/package.json.mjs +49 -60
  48. package/dist/es/sessionUpload.mjs +49 -0
  49. package/dist/es/utils.mjs +24 -11
  50. package/dist/lib/index.js +382 -10
  51. package/dist/src/AgentSession.d.ts +13 -0
  52. package/dist/src/BotClient.d.ts +13 -1
  53. package/dist/src/Config.d.ts +7 -8
  54. package/dist/src/EventBus.d.ts +3 -0
  55. package/dist/src/Logger.d.ts +15 -8
  56. package/dist/src/PayloadTypes.d.ts +2 -0
  57. package/dist/src/Session.d.ts +19 -2
  58. package/dist/src/api/index.d.ts +2 -2
  59. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  60. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  61. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  62. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  63. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  64. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  65. package/dist/src/builtinTools/command.d.ts +35 -0
  66. package/dist/src/builtinTools/constants.d.ts +25 -0
  67. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  68. package/dist/src/builtinTools/overview.d.ts +5 -0
  69. package/dist/src/builtinTools/paths.d.ts +16 -0
  70. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  71. package/dist/src/builtinTools/schemas.d.ts +3 -0
  72. package/dist/src/builtinTools/tools.d.ts +73 -0
  73. package/dist/src/constant.d.ts +1 -1
  74. package/dist/src/index.d.ts +2 -1
  75. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  76. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  77. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
  78. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  79. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
  80. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  81. package/dist/src/localFiles/constants.d.ts +5 -13
  82. package/dist/src/localFiles/errors.d.ts +1 -1
  83. package/dist/src/localFiles/host/protocol.d.ts +34 -16
  84. package/dist/src/localFiles/host/sandboxClient.d.ts +112 -0
  85. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  86. package/dist/src/localFiles/index.d.ts +11 -6
  87. package/dist/src/localFiles/preview.d.ts +2 -0
  88. package/dist/src/localFiles/schemas.d.ts +2 -5
  89. package/dist/src/localFiles/types.d.ts +16 -23
  90. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
  91. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  92. package/dist/src/localMcp/client.d.ts +15 -0
  93. package/dist/src/localMcp/endpoints.d.ts +19 -0
  94. package/dist/src/localMcp/register.d.ts +34 -0
  95. package/dist/src/localMcp/registry.d.ts +27 -0
  96. package/dist/src/sessionUpload.d.ts +14 -0
  97. package/dist/src/utils.d.ts +6 -0
  98. package/package.json +13 -24
  99. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -0,0 +1,70 @@
1
+ import { ToolError as o, ToolCode as i } from "../localFiles/errors.mjs";
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);
8
+ }
9
+ function u(t) {
10
+ const n = t.split("/")[0];
11
+ return f.includes(n);
12
+ }
13
+ function r(t) {
14
+ throw new o(i.Forbidden, t, {
15
+ reason: "path_outside_workspace"
16
+ });
17
+ }
18
+ function l(t) {
19
+ if (typeof t != "string" || t.length === 0)
20
+ throw new o(i.BadRequest, "path 必须是工作区内路径。");
21
+ (t.includes("\0") || t.includes("\\")) && r("路径不能包含反斜杠。");
22
+ const n = t.normalize("NFC").trim();
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, "技能文件只能通过技能工具访问。");
31
+ return e.join("/");
32
+ }
33
+ function R(t) {
34
+ return l(t);
35
+ }
36
+ function S(t) {
37
+ return l(t);
38
+ }
39
+ function g(t) {
40
+ return t ? `/${t}` : "/";
41
+ }
42
+ function I(t) {
43
+ if (t === ".")
44
+ return !0;
45
+ if (!t || t.startsWith("/") || t.includes("\\") || t.includes("\0"))
46
+ return !1;
47
+ const n = t.split("/").filter((e) => e.length > 0);
48
+ return n.length > 0 && n.every((e) => e !== "." && e !== "..") && !u(n[0]);
49
+ }
50
+ function T(t, n) {
51
+ if (!t || /[\\/\0]/.test(t) || t === "." || t === "..")
52
+ throw new o(i.BadRequest, "skill_name 必须是单个技能目录名。");
53
+ if (!n || n.startsWith("/") || n.includes("\\") || n.includes("\0"))
54
+ throw new o(i.BadRequest, "资源路径必须是技能目录内的相对路径。");
55
+ const e = n.split("/").filter((s) => s.length > 0);
56
+ return (e.length === 0 || e.some((s) => s === "." || s === "..")) && r("资源路径不能跳出技能目录。"), `skills/${t}/${e.join("/")}`;
57
+ }
58
+ export {
59
+ f as SYNTHETIC_DIRS,
60
+ c as SYNTHETIC_DIR_MESSAGE,
61
+ I as isSafeCwd,
62
+ u as isSyntheticCwd,
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
70
+ };
@@ -0,0 +1,248 @@
1
+ var b = Object.defineProperty;
2
+ var v = (e, t, n) => t in e ? b(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var y = (e, t, n) => (v(e, typeof t != "symbol" ? t + "" : t, n), n);
4
+ var o = (e, t, n) => new Promise((s, i) => {
5
+ var r = (a) => {
6
+ try {
7
+ d(n.next(a));
8
+ } catch (h) {
9
+ i(h);
10
+ }
11
+ }, l = (a) => {
12
+ try {
13
+ d(n.throw(a));
14
+ } catch (h) {
15
+ i(h);
16
+ }
17
+ }, d = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(r, l);
18
+ d((n = n.apply(e, t)).next());
19
+ });
20
+ import w from "../Logger.mjs";
21
+ import { ToolError as c, ToolCode as p } from "../localFiles/errors.mjs";
22
+ import { isExpired as g } from "../utils.mjs";
23
+ const u = new w("[PlatformSkills] "), S = 20 * 1024 * 1024, k = /^[A-Za-z0-9._-]+$/;
24
+ function f(e) {
25
+ const t = e == null ? void 0 : e.skills;
26
+ return Array.isArray(t) ? t.filter((n) => n && typeof n == "object") : [];
27
+ }
28
+ function m(e, t) {
29
+ t && (e.skills = t.skills);
30
+ }
31
+ function P(e) {
32
+ return o(this, null, function* () {
33
+ var n;
34
+ if (!e.arrange)
35
+ return;
36
+ const t = yield e.fetchApplication();
37
+ e.stillCurrent && !e.stillCurrent() || m(e.arrange, (n = t == null ? void 0 : t.arrange) == null ? void 0 : n[0]);
38
+ });
39
+ }
40
+ function x(e) {
41
+ if (!e)
42
+ return !1;
43
+ try {
44
+ return !g(e);
45
+ } catch (t) {
46
+ return !1;
47
+ }
48
+ }
49
+ function I(e) {
50
+ if (!(typeof e.skillId != "string" || !k.test(e.skillId)) && !(typeof e.name != "string" || !e.name || /[\\/\0]/.test(e.name) || e.name === "." || e.name === "..") && !(typeof e.version != "number" || !Number.isInteger(e.version) || e.version < 1))
51
+ return {
52
+ skillId: e.skillId,
53
+ name: e.name,
54
+ version: e.version
55
+ };
56
+ }
57
+ function $(e) {
58
+ return Array.isArray(e) ? e.flatMap((t) => {
59
+ if (!t || typeof t != "object")
60
+ return [];
61
+ const n = t;
62
+ return typeof n.skillId != "string" || typeof n.name != "string" || typeof n.version != "number" ? [] : [{
63
+ skillId: n.skillId,
64
+ name: n.name,
65
+ version: n.version
66
+ }];
67
+ }) : [];
68
+ }
69
+ class B {
70
+ constructor(t) {
71
+ y(this, "inflight", /* @__PURE__ */ new Map());
72
+ y(this, "busy", /* @__PURE__ */ new Set());
73
+ this.options = t;
74
+ }
75
+ /** 进入会话时调用。不阻塞历史,也不改沙箱就绪。 */
76
+ sync() {
77
+ const t = f({
78
+ skills: this.options.getSkills()
79
+ });
80
+ return u.log("sync", {
81
+ count: t.length,
82
+ sandbox: !!this.options.getSandbox()
83
+ }), this.reconcile().catch((n) => {
84
+ u.error("sync failed", n instanceof Error ? n.message : String(n));
85
+ });
86
+ }
87
+ read(t, n, s) {
88
+ return o(this, null, function* () {
89
+ const i = yield this.prepare(t, s);
90
+ return this.requireSandbox().skillRead(this.options.applicationId(), i.skillId, i.version, n, s);
91
+ });
92
+ }
93
+ list(t, n, s) {
94
+ return o(this, null, function* () {
95
+ const i = yield this.prepare(t, s);
96
+ return this.requireSandbox().skillList(this.options.applicationId(), i.skillId, i.version, n, s);
97
+ });
98
+ }
99
+ grep(t, n, s, i) {
100
+ return o(this, null, function* () {
101
+ const r = yield this.prepare(t, i);
102
+ return this.requireSandbox().skillGrep(this.options.applicationId(), r.skillId, r.version, s, n, i);
103
+ });
104
+ }
105
+ target(t, n) {
106
+ return o(this, null, function* () {
107
+ const s = yield this.prepare(t, n);
108
+ return {
109
+ applicationId: this.options.applicationId(),
110
+ skillId: s.skillId,
111
+ version: s.version,
112
+ name: s.name
113
+ };
114
+ });
115
+ }
116
+ track(t, n) {
117
+ const s = `${t}/${n}`;
118
+ this.busy.add(s);
119
+ let i = !1;
120
+ return () => {
121
+ i || (i = !0, this.busy.delete(s), this.prune().catch(() => {
122
+ }));
123
+ };
124
+ }
125
+ requireSandbox() {
126
+ const t = this.options.getSandbox();
127
+ if (!t)
128
+ throw new c(p.NotImplemented, "当前环境不能加载平台技能,需要端侧宿主。");
129
+ return t;
130
+ }
131
+ prepare(t, n) {
132
+ return o(this, null, function* () {
133
+ const s = this.bound(t);
134
+ if (!s)
135
+ throw new c(p.NotFound, "技能或资源不存在。");
136
+ return yield this.ensure(s, n), s;
137
+ });
138
+ }
139
+ bound(t) {
140
+ if (!k.test(this.options.applicationId()))
141
+ return;
142
+ const n = f({
143
+ skills: this.options.getSkills()
144
+ }).find((s) => s.name === t);
145
+ return n ? I(n) : void 0;
146
+ }
147
+ reconcile() {
148
+ return o(this, null, function* () {
149
+ if (!this.options.getSandbox())
150
+ return;
151
+ const n = f({
152
+ skills: this.options.getSkills()
153
+ }).flatMap((s) => {
154
+ const i = I(s);
155
+ return i ? [i] : [];
156
+ });
157
+ yield Promise.all(n.map((s) => this.ensure(s).catch((i) => {
158
+ u.error("install failed", s.name, i instanceof Error ? i.message : String(i));
159
+ }))), yield this.prune();
160
+ });
161
+ }
162
+ ensure(t, n) {
163
+ return o(this, null, function* () {
164
+ const s = `${this.options.applicationId()}/${t.skillId}/${t.version}`, i = this.inflight.get(s);
165
+ if (i)
166
+ return i;
167
+ const r = this.installIfNeeded(t, n).finally(() => {
168
+ this.inflight.get(s) === r && this.inflight.delete(s);
169
+ });
170
+ return this.inflight.set(s, r), r;
171
+ });
172
+ }
173
+ installIfNeeded(t, n) {
174
+ return o(this, null, function* () {
175
+ var a;
176
+ const s = this.requireSandbox();
177
+ if (s.ready && (yield this.alreadyInstalled(s, t, n))) {
178
+ u.log("installed", t.name, t.version);
179
+ return;
180
+ }
181
+ u.log("download", t.name, t.skillId, t.version);
182
+ const i = this.options.getToken();
183
+ if (!x(i))
184
+ throw new c(p.Forbidden, "技能下载令牌不可用。");
185
+ const r = this.options.apiRoot().replace(/\/$/, ""), l = yield ((a = this.options.fetch) != null ? a : fetch)(`${r}/skill/v1/skills/${encodeURIComponent(t.skillId)}/versions/${t.version}/download`, {
186
+ headers: {
187
+ Authorization: `Bearer ${i}`
188
+ },
189
+ signal: n
190
+ });
191
+ if (!l.ok)
192
+ throw new c(p.BadRequest, `技能下载失败(${l.status})。`);
193
+ const d = new Uint8Array(yield l.arrayBuffer());
194
+ if (d.byteLength > S)
195
+ throw new c(p.BadRequest, "技能压缩包超过 20 MB。");
196
+ yield this.waitReady(s, n), !(yield this.alreadyInstalled(s, t, n)) && (yield s.installSkill({
197
+ applicationId: this.options.applicationId(),
198
+ skillId: t.skillId,
199
+ version: t.version,
200
+ name: t.name
201
+ }, d, n));
202
+ });
203
+ }
204
+ alreadyInstalled(t, n, s) {
205
+ return o(this, null, function* () {
206
+ return $(yield t.skillStatus(this.options.applicationId(), s)).some((r) => r.skillId === n.skillId && r.version === n.version && r.name === n.name);
207
+ });
208
+ }
209
+ prune() {
210
+ return o(this, null, function* () {
211
+ const t = this.options.getSandbox();
212
+ if (!(t != null && t.ready))
213
+ return;
214
+ const n = f({
215
+ skills: this.options.getSkills()
216
+ }).flatMap((i) => typeof i.skillId != "string" || typeof i.version != "number" || i.version < 1 ? [] : [{
217
+ skillId: i.skillId,
218
+ version: i.version
219
+ }]), s = [...this.busy].map((i) => {
220
+ const [r, l] = i.split("/");
221
+ return {
222
+ skillId: r,
223
+ version: Number(l)
224
+ };
225
+ });
226
+ yield t.skillPrune(this.options.applicationId(), n, s);
227
+ });
228
+ }
229
+ waitReady(t, n) {
230
+ return o(this, null, function* () {
231
+ t.ready || (yield new Promise((s, i) => {
232
+ const r = setInterval(() => {
233
+ if (n != null && n.aborted) {
234
+ clearInterval(r), i(new c(p.Cancelled, "已取消。"));
235
+ return;
236
+ }
237
+ t.ready && (clearInterval(r), s());
238
+ }, 50);
239
+ }));
240
+ });
241
+ }
242
+ }
243
+ export {
244
+ B as PlatformSkillSync,
245
+ m as assignArrangeSkills,
246
+ f as listedSkills,
247
+ P as pullArrangeSkills
248
+ };
@@ -0,0 +1,261 @@
1
+ import { MAX_COMMAND_CHARS as o, MAX_WRITE_BYTES as r, BUILTIN_FUNCTION_CODES as p } from "./constants.mjs";
2
+ const e = (i) => ({
3
+ type: "string",
4
+ minLength: 1,
5
+ description: i
6
+ }), n = "脚本能否联网由运行环境决定;被宿主网络策略拒绝的地址会在结果里列出。", t = "必填。工作区内路径。以 / 开头,例如 /说明.md;也可以不写开头的斜杠,例如 notes/a.md。不要使用 input、output、uploads、tmp,也不要新建这些目录。", a = {
7
+ shell: {
8
+ functionCode: "shell",
9
+ name: "执行命令",
10
+ description: `在当前会话工作区中执行一条 shell 命令并返回标准输出。每次调用都是新的 shell,只保留上次停留的目录;环境变量不会保留,需要时在同一条命令里设置。当前目录是工作区根目录。用相对路径,或以 / 开头表示工作区内已有的路径,例如 notes/a.md、/说明.md。不要使用或新建 input、output、uploads、tmp。/dev、/usr、/bin 仍是系统路径。写进脚本文件里的路径要用相对路径(见 run_file)。超过 20000 字的脚本请用 write_file 写到工作区文件后再调用 run_file;读取文件正文或结构摘要请用 read_file 的 start_line 和 end_line,不要用 cat、sed 或 head 把大文件正文打到标准输出。${n}`,
11
+ parameters: {
12
+ type: "object",
13
+ required: ["command"],
14
+ properties: {
15
+ command: {
16
+ type: "string",
17
+ minLength: 1,
18
+ maxLength: o,
19
+ description: "必填。一条不超过 20000 字的 shell 命令。当前目录已是工作区根目录。可以包含短的 python 或 heredoc。读取文件正文请改用 read_file。"
20
+ }
21
+ }
22
+ }
23
+ },
24
+ read_file: {
25
+ functionCode: "read_file",
26
+ name: "读取文件",
27
+ description: "读取工作区内的文本文件并返回内容;读不到时返回失败原因。path 可以以 / 开头,也可以不写开头的斜杠。未超过上限的文本按原文返回;超过单次读取上限的结构化文本(JSON/XML/SVG/CSV/TSV)会先附带通用结构概览和短预览,需要特定片段时再用 start_line 和 end_line。PDF 和图片只返回文件摘要,不返回正文。",
28
+ parameters: {
29
+ type: "object",
30
+ required: ["path"],
31
+ properties: {
32
+ path: e(t),
33
+ start_line: {
34
+ type: "integer",
35
+ minimum: 1,
36
+ description: "可选。起始行号,从 1 开始,含本行。省略则从第 1 行读。"
37
+ },
38
+ end_line: {
39
+ type: "integer",
40
+ minimum: 1,
41
+ description: "可选。结束行号,从 1 开始,含本行。省略则读到文件末尾。"
42
+ }
43
+ }
44
+ }
45
+ },
46
+ write_file: {
47
+ functionCode: "write_file",
48
+ name: "写入文件",
49
+ description: `把文本写入工作区内文件。path 可以是以 / 开头的工作区路径,也可以不带开头斜杠,例如 /说明.md、notes/a.md。文件已存在时覆盖。单次覆盖写入按 UTF-8 字节计,默认不超过 ${r} 字节。超限时先写一段,再用 edit_file 修改,或用 append_file 追加下一段。SVG 和整页 HTML 由工作区里的脚本生成,不要直接放进 content。`,
50
+ parameters: {
51
+ type: "object",
52
+ required: ["path", "content"],
53
+ properties: {
54
+ path: e(t),
55
+ content: {
56
+ type: "string",
57
+ description: `必填。覆盖写入的文本,UTF-8 不超过 ${r} 字节。不要放入 SVG 或整页 HTML。`
58
+ }
59
+ }
60
+ }
61
+ },
62
+ append_file: {
63
+ functionCode: "append_file",
64
+ name: "追加文件",
65
+ description: "把一段文本追加到工作区内文件末尾。path 可以以 / 开头,也可以不写开头的斜杠。文件不存在时创建。覆盖写入超过字节上限时,用本工具把下一段接到同一文件。追加不设字节上限,但不要在一次调用里放入整份 HTML 或 SVG。",
66
+ parameters: {
67
+ type: "object",
68
+ required: ["path", "content"],
69
+ properties: {
70
+ path: e(t),
71
+ content: {
72
+ type: "string",
73
+ description: "必填。要追加到文件末尾的文本。不受覆盖写入的字节上限约束。"
74
+ }
75
+ }
76
+ }
77
+ },
78
+ run_file: {
79
+ functionCode: "run_file",
80
+ name: "执行文件",
81
+ description: `执行工作区里已经存在的 .py、.sh、.bash、.js、.mjs 或 .cjs 脚本文件。生成 SVG、HTML、JSON 等产物时优先使用:先用 write_file 写脚本,脚本自行读取工作区文件并写出产物,再调用本工具。脚本运行时当前目录是工作区根目录,脚本里访问工作区文件要写相对路径,例如 data.json、notes/a.py。不要使用或新建 input、output、uploads、tmp。需要查看文件正文时用 read_file,不要把整份文件打印到标准输出。${n}`,
82
+ parameters: {
83
+ type: "object",
84
+ required: ["path"],
85
+ properties: {
86
+ path: e("必填。要执行的 .py、.sh、.bash、.js、.mjs 或 .cjs 文件。可以是 /scripts/gen.py,也可以是 scripts/gen.py。")
87
+ }
88
+ }
89
+ },
90
+ edit_file: {
91
+ functionCode: "edit_file",
92
+ name: "修改文件",
93
+ description: "把工作区内文本文件中第一处与 old_text 完全相同的内容替换为 new_text。找不到 old_text 时返回最接近片段的行号,可直接复制原文重试,不必再读全文。old_text 与 new_text 不设长度上限。",
94
+ parameters: {
95
+ type: "object",
96
+ required: ["path", "old_text", "new_text"],
97
+ properties: {
98
+ path: e(t),
99
+ old_text: {
100
+ type: "string",
101
+ minLength: 1,
102
+ description: "必填。文件中要被替换的原文,必须完全一致。"
103
+ },
104
+ new_text: {
105
+ type: "string",
106
+ description: "必填。替换后的文本。可以是一整段生成逻辑,不必拆成追加。"
107
+ }
108
+ }
109
+ }
110
+ },
111
+ grep: {
112
+ functionCode: "grep",
113
+ name: "搜索文件",
114
+ description: "在工作区目录中递归搜索文本,返回带行号的匹配行。path 可以以 / 开头,也可以不写开头的斜杠。pattern 按 grep 基本正则匹配。用于定位内容,不要用来取回大文件全文。",
115
+ parameters: {
116
+ type: "object",
117
+ required: ["path", "pattern"],
118
+ properties: {
119
+ path: e(t),
120
+ pattern: {
121
+ type: "string",
122
+ minLength: 1,
123
+ description: "必填。grep 基本正则表达式。"
124
+ }
125
+ }
126
+ }
127
+ },
128
+ find: {
129
+ functionCode: "find",
130
+ name: "查找文件",
131
+ description: "按文件名通配在工作区目录中查找文件。path 为起始路径,可以以 / 开头,也可以不写开头的斜杠。name 传给 find 的 -name,例如 *.html。",
132
+ parameters: {
133
+ type: "object",
134
+ required: ["path", "name"],
135
+ properties: {
136
+ path: e(t),
137
+ name: {
138
+ type: "string",
139
+ minLength: 1,
140
+ description: "必填。find -name 通配,例如 *.svg 或 *.html。"
141
+ }
142
+ }
143
+ }
144
+ },
145
+ load_skill: {
146
+ functionCode: "load_skill",
147
+ name: "加载技能",
148
+ description: "按技能名称加载平台技能的完整说明(SKILL.md),并附上技能包内全部文件的相对路径。技能不在工程目录里。之后用 read_skill_resource 按这些路径读取,或用 grep_skill 搜索。",
149
+ parameters: {
150
+ type: "object",
151
+ required: ["skill_name"],
152
+ properties: {
153
+ skill_name: {
154
+ type: "string",
155
+ minLength: 1,
156
+ description: "必填。要加载的技能名称。"
157
+ }
158
+ }
159
+ }
160
+ },
161
+ read_skill_resource: {
162
+ functionCode: "read_skill_resource",
163
+ name: "读取技能资源",
164
+ description: "读取技能包内的文本。resource_name 是相对技能根目录的路径。传目录则列出该目录下的文件;传 . 列出整个技能包;以 grep: 开头则按基本正则搜索,例如 grep:portrait。",
165
+ parameters: {
166
+ type: "object",
167
+ required: ["skill_name", "resource_name"],
168
+ properties: {
169
+ skill_name: {
170
+ type: "string",
171
+ minLength: 1,
172
+ description: "必填。技能名称。"
173
+ },
174
+ resource_name: {
175
+ type: "string",
176
+ minLength: 1,
177
+ description: "必填。要读取的技能资源相对路径名称。"
178
+ }
179
+ }
180
+ }
181
+ },
182
+ list_skill_files: {
183
+ functionCode: "list_skill_files",
184
+ name: "列出技能文件",
185
+ description: "列出平台技能包内的文件和目录。不传 path 时列出整个技能包。技能不在工程目录里。",
186
+ parameters: {
187
+ type: "object",
188
+ required: ["skill_name"],
189
+ properties: {
190
+ skill_name: {
191
+ type: "string",
192
+ minLength: 1,
193
+ description: "必填。技能名称。"
194
+ },
195
+ path: {
196
+ type: "string",
197
+ description: "可选。技能包内的相对目录,例如 skills 或 tools/dwgkit。省略则从技能根目录列出。"
198
+ }
199
+ }
200
+ }
201
+ },
202
+ grep_skill: {
203
+ functionCode: "grep_skill",
204
+ name: "搜索技能内容",
205
+ description: "在平台技能包内按 grep 基本正则搜索文本,返回路径、行号和匹配行。",
206
+ parameters: {
207
+ type: "object",
208
+ required: ["skill_name", "pattern"],
209
+ properties: {
210
+ skill_name: {
211
+ type: "string",
212
+ minLength: 1,
213
+ description: "必填。技能名称。"
214
+ },
215
+ pattern: {
216
+ type: "string",
217
+ minLength: 1,
218
+ description: "必填。grep 基本正则,例如 portrait 或 def .*。"
219
+ },
220
+ path: {
221
+ type: "string",
222
+ description: "可选。只搜索该相对目录或文件,例如 skills/cad-drawing-understanding。"
223
+ }
224
+ }
225
+ }
226
+ },
227
+ run_skill_script: {
228
+ functionCode: "run_skill_script",
229
+ name: "运行技能脚本",
230
+ description: `执行平台技能包内的脚本并返回输出。当前目录是工作区根目录,参数里的用户文件按相对工作区根目录传,例如 docs/a.docx。技能自己的资源按脚本文件所在目录查找,不在工程的 skills 目录里。${n}`,
231
+ parameters: {
232
+ type: "object",
233
+ required: ["skill_name", "script_name"],
234
+ properties: {
235
+ skill_name: {
236
+ type: "string",
237
+ minLength: 1,
238
+ description: "必填。技能名称。"
239
+ },
240
+ script_name: {
241
+ type: "string",
242
+ minLength: 1,
243
+ description: "必填。要运行的技能脚本相对路径(保持技能说明中列出的目录前缀,如 scripts/run.py)。"
244
+ },
245
+ args: {
246
+ type: "array",
247
+ description: '传递给脚本的命令行位置参数数组,例如 ["input.docx", "--output", "result.idx"]。',
248
+ items: {
249
+ type: "string",
250
+ description: "单个脚本参数。"
251
+ }
252
+ }
253
+ }
254
+ }
255
+ }
256
+ }, s = Object.keys(a);
257
+ if (s.length !== p.length || p.some((i) => !s.includes(i)))
258
+ throw new Error("BUILTIN_TOOL_SCHEMAS 与 BUILTIN_FUNCTION_CODES 不一致");
259
+ export {
260
+ a as BUILTIN_TOOL_SCHEMAS
261
+ };