@glodon-aiot/bot-client-sdk 3.26.0-alpha.20 → 3.26.0-alpha.23
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 +130 -179
- package/dist/es/BotClient.mjs +136 -154
- package/dist/es/Config.mjs +88 -51
- package/dist/es/Session.mjs +23 -35
- package/dist/es/index.mjs +64 -66
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -185
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +137 -127
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +97 -132
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +28 -32
- package/dist/es/localFiles/constants.mjs +29 -24
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/errors.mjs +19 -21
- package/dist/es/localFiles/host/connectHostBridge.mjs +34 -37
- package/dist/es/localFiles/host/protocol.mjs +13 -27
- package/dist/es/localFiles/schemas.mjs +86 -40
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +87 -161
- package/dist/es/package.json.mjs +29 -38
- package/dist/lib/index.js +9 -373
- package/dist/src/Config.d.ts +7 -5
- package/dist/src/Session.d.ts +0 -6
- package/dist/src/index.d.ts +1 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +14 -30
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +1 -4
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +0 -22
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +0 -2
- package/dist/src/localFiles/constants.d.ts +13 -3
- package/dist/src/localFiles/host/protocol.d.ts +16 -34
- package/dist/src/localFiles/index.d.ts +6 -11
- package/dist/src/localFiles/schemas.d.ts +5 -2
- package/dist/src/localFiles/types.d.ts +23 -16
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +1 -32
- package/package.json +4 -13
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +0 -201
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +0 -356
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +0 -350
- package/dist/es/builtinTools/browserRuntime/assets.mjs +0 -9
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +0 -17
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +0 -96
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +0 -242
- package/dist/es/builtinTools/command.mjs +0 -56
- package/dist/es/builtinTools/constants.mjs +0 -10
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +0 -261
- package/dist/es/builtinTools/overview.mjs +0 -77
- package/dist/es/builtinTools/paths.mjs +0 -69
- package/dist/es/builtinTools/platformSkills.mjs +0 -210
- package/dist/es/builtinTools/schemas.mjs +0 -216
- package/dist/es/builtinTools/tools.mjs +0 -494
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +0 -160
- package/dist/es/localFiles/host/sandboxClient.mjs +0 -420
- package/dist/es/localFiles/host/sandboxFrames.mjs +0 -21
- package/dist/es/localFiles/preview.mjs +0 -33
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +0 -246
- package/dist/es/sessionUpload.mjs +0 -49
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +0 -26
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +0 -67
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +0 -51
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +0 -13
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +0 -3
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +0 -44
- package/dist/src/builtinTools/command.d.ts +0 -35
- package/dist/src/builtinTools/constants.d.ts +0 -17
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +0 -11
- package/dist/src/builtinTools/overview.d.ts +0 -5
- package/dist/src/builtinTools/paths.d.ts +0 -16
- package/dist/src/builtinTools/platformSkills.d.ts +0 -67
- package/dist/src/builtinTools/schemas.d.ts +0 -3
- package/dist/src/builtinTools/tools.d.ts +0 -64
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +0 -24
- package/dist/src/localFiles/host/sandboxClient.d.ts +0 -81
- package/dist/src/localFiles/host/sandboxFrames.d.ts +0 -9
- package/dist/src/localFiles/preview.d.ts +0 -2
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +0 -63
- package/dist/src/sessionUpload.d.ts +0 -14
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
var E = (r, t,
|
|
3
|
-
var a = (r, t,
|
|
4
|
-
var
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
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
7
|
super(u);
|
|
8
8
|
a(this, "code");
|
|
9
9
|
a(this, "data");
|
|
10
|
-
this.name = "ToolError", this.code =
|
|
10
|
+
this.name = "ToolError", this.code = e, this.data = s;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const w = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
|
|
14
14
|
function m() {
|
|
15
|
-
return new
|
|
15
|
+
return new n(403, w, {
|
|
16
16
|
reason: "workspace_not_granted"
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
function c() {
|
|
20
|
-
return new
|
|
20
|
+
return new n(499, "操作已取消。");
|
|
21
21
|
}
|
|
22
22
|
function N(r) {
|
|
23
23
|
if (r != null && r.aborted)
|
|
24
24
|
throw c();
|
|
25
25
|
}
|
|
26
26
|
function o(r) {
|
|
27
|
-
if (r instanceof
|
|
27
|
+
if (r instanceof n)
|
|
28
28
|
return r;
|
|
29
29
|
switch (r && typeof r == "object" && "name" in r ? String(r.name) : "") {
|
|
30
30
|
case "NotFoundError":
|
|
31
|
-
return new
|
|
31
|
+
return new n(404, "文件或目录不存在。");
|
|
32
32
|
case "TypeMismatchError":
|
|
33
|
-
return new
|
|
33
|
+
return new n(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
|
|
34
34
|
case "NotAllowedError":
|
|
35
35
|
case "SecurityError":
|
|
36
36
|
return m();
|
|
@@ -39,19 +39,17 @@ function o(r) {
|
|
|
39
39
|
case "NoModificationAllowedError":
|
|
40
40
|
case "InvalidModificationError":
|
|
41
41
|
case "InvalidStateError":
|
|
42
|
-
return new
|
|
42
|
+
return new n(403, "文件当前不可写,可能正被其他程序占用或为只读。");
|
|
43
43
|
case "QuotaExceededError":
|
|
44
|
-
return new
|
|
45
|
-
case "PreviewLimitError":
|
|
46
|
-
return new e(413, "同时预览的文件过多,请先关掉一些预览。");
|
|
44
|
+
return new n(413, "磁盘空间不足或超出写入配额。");
|
|
47
45
|
default:
|
|
48
|
-
return new
|
|
46
|
+
return new n(500, "本地文件操作失败,请稍后重试。");
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
export {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
f as ToolCode,
|
|
51
|
+
n as ToolError,
|
|
52
|
+
w as WORKSPACE_NOT_GRANTED_MESSAGE,
|
|
55
53
|
c as cancelledError,
|
|
56
54
|
N as throwIfAborted,
|
|
57
55
|
o as toToolError,
|
|
@@ -1,53 +1,50 @@
|
|
|
1
1
|
import { HostBridgeAdapter as f } from "../adapters/HostBridgeAdapter.mjs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
state: e.state,
|
|
9
|
-
url: typeof e.url == "string" ? e.url : void 0,
|
|
10
|
-
token: typeof e.token == "string" ? e.token : void 0,
|
|
11
|
-
protocol: typeof e.protocol == "number" ? e.protocol : void 0,
|
|
12
|
-
exitCode: typeof e.exitCode == "number" ? e.exitCode : void 0,
|
|
13
|
-
detail: typeof e.detail == "string" ? e.detail : void 0,
|
|
14
|
-
message: typeof e.message == "string" ? e.message : void 0,
|
|
15
|
-
reason: typeof e.reason == "string" ? e.reason : void 0
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
let s;
|
|
19
|
-
function v(o) {
|
|
20
|
-
s == null || s(), s = void 0;
|
|
21
|
-
const e = g();
|
|
22
|
-
if (!e)
|
|
2
|
+
import { getHostWebView as m, HOST_CHANNEL as g, parseHostMessage as y } from "./protocol.mjs";
|
|
3
|
+
let t;
|
|
4
|
+
function c(s) {
|
|
5
|
+
t == null || t(), t = void 0;
|
|
6
|
+
const i = m();
|
|
7
|
+
if (!i)
|
|
23
8
|
return () => {
|
|
24
9
|
};
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
version: t.sandboxVersion
|
|
32
|
-
}), i.applySandbox(m(t.sandbox)), n ? (i.displayName = r || "工程目录", (o.status !== "granted" || o.displayName !== i.displayName) && o.attachAdapter(i, i.displayName)) : o.status === "granted" && o.clear();
|
|
10
|
+
const n = new f(i), d = (p) => {
|
|
11
|
+
const e = y(p.data);
|
|
12
|
+
if (e) {
|
|
13
|
+
if (e.type === "workspace") {
|
|
14
|
+
const r = e.granted === !0, o = typeof e.displayName == "string" ? e.displayName : "";
|
|
15
|
+
r ? (n.displayName = o || "工程目录", (s.status !== "granted" || s.displayName !== n.displayName) && s.attachAdapter(n, n.displayName)) : s.status === "granted" && s.clear();
|
|
33
16
|
return;
|
|
34
17
|
}
|
|
35
|
-
if (
|
|
36
|
-
const
|
|
37
|
-
|
|
18
|
+
if (e.type === "fs-changed") {
|
|
19
|
+
const r = Array.isArray(e.paths) ? e.paths.filter((o) => typeof o == "string") : [];
|
|
20
|
+
s.notifyFilesChanged(r);
|
|
38
21
|
return;
|
|
39
22
|
}
|
|
23
|
+
typeof e.id == "string" && n.settle({
|
|
24
|
+
channel: g,
|
|
25
|
+
id: e.id,
|
|
26
|
+
ok: e.ok !== !1,
|
|
27
|
+
name: typeof e.name == "string" ? e.name : void 0,
|
|
28
|
+
entries: e.entries,
|
|
29
|
+
entry: e.entry,
|
|
30
|
+
contentBase64: typeof e.contentBase64 == "string" ? e.contentBase64 : void 0,
|
|
31
|
+
exitCode: typeof e.exitCode == "number" ? e.exitCode : void 0,
|
|
32
|
+
timedOut: e.timedOut === !0,
|
|
33
|
+
stdout: typeof e.stdout == "string" ? e.stdout : void 0,
|
|
34
|
+
stderr: typeof e.stderr == "string" ? e.stderr : void 0,
|
|
35
|
+
message: typeof e.message == "string" ? e.message : void 0
|
|
36
|
+
});
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
|
-
|
|
43
|
-
channel:
|
|
39
|
+
i.addEventListener("message", d), i.postMessage({
|
|
40
|
+
channel: g,
|
|
44
41
|
type: "hello"
|
|
45
42
|
});
|
|
46
43
|
const a = () => {
|
|
47
|
-
|
|
44
|
+
i.removeEventListener("message", d), t === a && (t = void 0);
|
|
48
45
|
};
|
|
49
|
-
return
|
|
46
|
+
return t = a, a;
|
|
50
47
|
}
|
|
51
48
|
export {
|
|
52
|
-
|
|
49
|
+
c as connectHostBridge
|
|
53
50
|
};
|
|
@@ -1,40 +1,26 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
1
|
+
const n = "glodon-workspace";
|
|
2
|
+
function i(t) {
|
|
3
3
|
let e = t;
|
|
4
4
|
if (typeof e == "string")
|
|
5
5
|
try {
|
|
6
6
|
e = JSON.parse(e);
|
|
7
|
-
} catch (
|
|
7
|
+
} catch (r) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
if (!e || typeof e != "object")
|
|
11
11
|
return;
|
|
12
|
-
const
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
12
|
+
const o = e;
|
|
13
|
+
if (o.channel === n)
|
|
14
|
+
return o;
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
if (!t || typeof t != "object")
|
|
18
|
-
return;
|
|
19
|
-
const e = t;
|
|
20
|
-
if (!(typeof e.postMessage != "function" || typeof e.addEventListener != "function" || typeof e.removeEventListener != "function"))
|
|
21
|
-
return e;
|
|
22
|
-
}
|
|
23
|
-
function g(t) {
|
|
24
|
-
const e = globalThis;
|
|
25
|
-
t ? e[o] = t : delete e[o];
|
|
26
|
-
}
|
|
27
|
-
function u() {
|
|
16
|
+
function s() {
|
|
28
17
|
var e;
|
|
29
|
-
const t =
|
|
30
|
-
|
|
18
|
+
const t = (e = globalThis.chrome) == null ? void 0 : e.webview;
|
|
19
|
+
if (!(!t || typeof t.postMessage != "function" || typeof t.addEventListener != "function"))
|
|
20
|
+
return t;
|
|
31
21
|
}
|
|
32
22
|
export {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
c as SANDBOX_PROTOCOL,
|
|
37
|
-
u as getHostBridge,
|
|
38
|
-
d as parseHostMessage,
|
|
39
|
-
g as registerHostBridge
|
|
23
|
+
n as HOST_CHANNEL,
|
|
24
|
+
s as getHostWebView,
|
|
25
|
+
i as parseHostMessage
|
|
40
26
|
};
|
|
@@ -1,25 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var l = Object.defineProperty, u = Object.defineProperties;
|
|
2
|
+
var y = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var o = Object.getOwnPropertySymbols;
|
|
4
|
+
var h = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var a = (t, e, i) => e in t ? l(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, d = (t, e) => {
|
|
6
|
+
for (var i in e || (e = {}))
|
|
7
|
+
h.call(e, i) && a(t, i, e[i]);
|
|
8
|
+
if (o)
|
|
9
|
+
for (var i of o(e))
|
|
10
|
+
g.call(e, i) && a(t, i, e[i]);
|
|
11
|
+
return t;
|
|
12
|
+
}, c = (t, e) => u(t, y(e));
|
|
13
|
+
import { LOCAL_PYTHON_FUNCTION_CODE as f, WORKSPACE_GRANT_ID as m } from "./constants.mjs";
|
|
14
|
+
const p = "只操作用户在当前浏览器里选择的本地文件夹,路径相对该文件夹。云端工作区的文件不要用本工具。", r = {
|
|
3
15
|
type: "string",
|
|
4
|
-
enum: [
|
|
5
|
-
description: `工作区 ID。省略时按 ${
|
|
6
|
-
},
|
|
16
|
+
enum: [m],
|
|
17
|
+
description: `工作区 ID。省略时按 ${m} 处理,传其他值会被拒绝。`
|
|
18
|
+
}, n = (t) => ({
|
|
7
19
|
type: "string",
|
|
8
|
-
description: `${
|
|
9
|
-
}),
|
|
20
|
+
description: `${t}使用相对工作区根目录的路径,以 / 分隔,不能包含 .. 或绝对路径。`
|
|
21
|
+
}), s = {
|
|
10
22
|
type: "string",
|
|
11
23
|
description: "文件当前内容的 hash(sha256:<hex>),来自 read_file 或 stat_file 的返回值。"
|
|
12
|
-
},
|
|
24
|
+
}, _ = {
|
|
13
25
|
list_directory: {
|
|
14
26
|
functionCode: "list_directory",
|
|
15
27
|
name: "列出本地目录",
|
|
16
|
-
description: `${
|
|
28
|
+
description: `${p}列出某个目录的直接子项(目录在前),支持分页。`,
|
|
17
29
|
parameters: {
|
|
18
30
|
type: "object",
|
|
19
31
|
required: ["grantId"],
|
|
20
32
|
properties: {
|
|
21
|
-
grantId:
|
|
22
|
-
path:
|
|
33
|
+
grantId: r,
|
|
34
|
+
path: n('要列出的目录,省略或传 "." 表示工作区根目录。'),
|
|
23
35
|
offset: {
|
|
24
36
|
type: "integer",
|
|
25
37
|
minimum: 0,
|
|
@@ -37,13 +49,13 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
37
49
|
read_file: {
|
|
38
50
|
functionCode: "read_file",
|
|
39
51
|
name: "读取本地文件",
|
|
40
|
-
description: `${
|
|
52
|
+
description: `${p}按行读取文本文件,单次最多返回 1 MiB,超出部分会被截断(truncated: true)。返回内容的 hash 可用于后续修改。`,
|
|
41
53
|
parameters: {
|
|
42
54
|
type: "object",
|
|
43
55
|
required: ["grantId", "path"],
|
|
44
56
|
properties: {
|
|
45
|
-
grantId:
|
|
46
|
-
path:
|
|
57
|
+
grantId: r,
|
|
58
|
+
path: n("要读取的文件。"),
|
|
47
59
|
startLine: {
|
|
48
60
|
type: "integer",
|
|
49
61
|
minimum: 1,
|
|
@@ -70,13 +82,13 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
70
82
|
stat_file: {
|
|
71
83
|
functionCode: "stat_file",
|
|
72
84
|
name: "查看本地文件信息",
|
|
73
|
-
description: `${
|
|
85
|
+
description: `${p}返回文件或目录的类型、大小、修改时间,可选返回 hash。不返回文件内容。`,
|
|
74
86
|
parameters: {
|
|
75
87
|
type: "object",
|
|
76
88
|
required: ["grantId", "path"],
|
|
77
89
|
properties: {
|
|
78
|
-
grantId:
|
|
79
|
-
path:
|
|
90
|
+
grantId: r,
|
|
91
|
+
path: n("要查看的文件或目录。"),
|
|
80
92
|
includeHash: {
|
|
81
93
|
type: "boolean",
|
|
82
94
|
description: "是否计算文件 hash。"
|
|
@@ -87,18 +99,18 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
87
99
|
search_files: {
|
|
88
100
|
functionCode: "search_files",
|
|
89
101
|
name: "查找本地文件",
|
|
90
|
-
description: `${
|
|
102
|
+
description: `${p}按文件名或 glob(支持 *、?、**)查找文件。不含 / 的模式匹配文件名,含 / 的模式匹配相对 path 的路径。`,
|
|
91
103
|
parameters: {
|
|
92
104
|
type: "object",
|
|
93
105
|
required: ["grantId", "pattern"],
|
|
94
106
|
properties: {
|
|
95
|
-
grantId:
|
|
107
|
+
grantId: r,
|
|
96
108
|
pattern: {
|
|
97
109
|
type: "string",
|
|
98
110
|
minLength: 1,
|
|
99
111
|
description: "如 *.xlsx 或 reports/**/*.docx。"
|
|
100
112
|
},
|
|
101
|
-
path:
|
|
113
|
+
path: n("搜索起点目录,默认工作区根目录。"),
|
|
102
114
|
maxDepth: {
|
|
103
115
|
type: "integer",
|
|
104
116
|
minimum: 1,
|
|
@@ -117,13 +129,13 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
117
129
|
search_text: {
|
|
118
130
|
functionCode: "search_text",
|
|
119
131
|
name: "搜索本地文本",
|
|
120
|
-
description: `${
|
|
132
|
+
description: `${p}在指定文件或目录(递归)中搜索普通文本(不支持正则),返回所在文件、行号与该行内容。必须指定 path,不能搜索整个文件夹。`,
|
|
121
133
|
parameters: {
|
|
122
134
|
type: "object",
|
|
123
135
|
required: ["grantId", "path", "query"],
|
|
124
136
|
properties: {
|
|
125
|
-
grantId:
|
|
126
|
-
path:
|
|
137
|
+
grantId: r,
|
|
138
|
+
path: n("搜索范围,可以是文件或目录。"),
|
|
127
139
|
query: {
|
|
128
140
|
type: "string",
|
|
129
141
|
minLength: 1,
|
|
@@ -159,14 +171,14 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
159
171
|
apply_patch: {
|
|
160
172
|
functionCode: "apply_patch",
|
|
161
173
|
name: "修改本地文件",
|
|
162
|
-
description: `${
|
|
174
|
+
description: `${p}以查找替换的方式修改 UTF-8 文本文件。每条修改的 oldText 必须在文件中唯一出现(或设置 replaceAll)。执行前需要用户确认。`,
|
|
163
175
|
parameters: {
|
|
164
176
|
type: "object",
|
|
165
177
|
required: ["grantId", "path", "expectedHash", "edits"],
|
|
166
178
|
properties: {
|
|
167
|
-
grantId:
|
|
168
|
-
path:
|
|
169
|
-
expectedHash:
|
|
179
|
+
grantId: r,
|
|
180
|
+
path: n("要修改的文件。"),
|
|
181
|
+
expectedHash: s,
|
|
170
182
|
edits: {
|
|
171
183
|
type: "array",
|
|
172
184
|
minItems: 1,
|
|
@@ -197,18 +209,18 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
197
209
|
write_file: {
|
|
198
210
|
functionCode: "write_file",
|
|
199
211
|
name: "写入本地文件",
|
|
200
|
-
description: `${
|
|
212
|
+
description: `${p}新建文件,或整体覆盖已有文件(覆盖时必须提供 expectedHash)。修改已有文件优先使用 apply_patch。执行前需要用户确认。`,
|
|
201
213
|
parameters: {
|
|
202
214
|
type: "object",
|
|
203
215
|
required: ["grantId", "path", "content"],
|
|
204
216
|
properties: {
|
|
205
|
-
grantId:
|
|
206
|
-
path:
|
|
217
|
+
grantId: r,
|
|
218
|
+
path: n("要写入的文件。"),
|
|
207
219
|
content: {
|
|
208
220
|
type: "string",
|
|
209
221
|
description: "完整的文件内容(UTF-8)。"
|
|
210
222
|
},
|
|
211
|
-
expectedHash:
|
|
223
|
+
expectedHash: s,
|
|
212
224
|
createDirectories: {
|
|
213
225
|
type: "boolean",
|
|
214
226
|
description: "父目录不存在时是否自动创建,默认否。"
|
|
@@ -219,13 +231,13 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
219
231
|
upload_file: {
|
|
220
232
|
functionCode: "upload_file",
|
|
221
233
|
name: "上传本地文件",
|
|
222
|
-
description: `${
|
|
234
|
+
description: `${p}把本地文件夹中的文件上传到平台文件服务,返回 fileId、name、size 和 url。url 是文件访问地址,可直接用于后续推理或对话。下载回本地文件夹时使用 download_file,source.type 为 platformFile。单文件不超过 50 MB。执行前需要用户确认。`,
|
|
223
235
|
parameters: {
|
|
224
236
|
type: "object",
|
|
225
237
|
required: ["grantId", "path"],
|
|
226
238
|
properties: {
|
|
227
|
-
grantId:
|
|
228
|
-
path:
|
|
239
|
+
grantId: r,
|
|
240
|
+
path: n("要上传的文件。"),
|
|
229
241
|
target: {
|
|
230
242
|
type: "string",
|
|
231
243
|
description: "上传目标,目前只支持 session(默认),其他值返回 501。"
|
|
@@ -240,13 +252,13 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
240
252
|
download_file: {
|
|
241
253
|
functionCode: "download_file",
|
|
242
254
|
name: "下载到本地文件夹",
|
|
243
|
-
description: `${
|
|
255
|
+
description: `${p}把会话文件、平台文件或 https 地址保存到本地文件夹。source.type 为 url 时必须同时填写 source.url(完整地址),为 sessionFile 或 platformFile 时必须同时填写 source.fileId。不要只传 type。单文件不超过 50 MB。执行前需要用户确认。`,
|
|
244
256
|
parameters: {
|
|
245
257
|
type: "object",
|
|
246
258
|
required: ["grantId", "destPath", "source"],
|
|
247
259
|
properties: {
|
|
248
|
-
grantId:
|
|
249
|
-
destPath:
|
|
260
|
+
grantId: r,
|
|
261
|
+
destPath: n("保存位置(文件路径)。"),
|
|
250
262
|
source: {
|
|
251
263
|
type: "object",
|
|
252
264
|
required: ["type"],
|
|
@@ -271,11 +283,45 @@ const e = "只操作用户在当前浏览器里选择的本地文件夹,路径
|
|
|
271
283
|
type: "boolean",
|
|
272
284
|
description: "目标已存在时是否覆盖,默认否。"
|
|
273
285
|
},
|
|
274
|
-
expectedHash:
|
|
286
|
+
expectedHash: s
|
|
275
287
|
}
|
|
276
288
|
}
|
|
277
289
|
}
|
|
278
|
-
}
|
|
290
|
+
}, x = "在已绑定的本地工程目录中运行已有 .py,路径相对该目录。不要用于云端工作区,不要传 shell 或代码,只能传 path 和 args。", I = {
|
|
291
|
+
functionCode: f,
|
|
292
|
+
name: "运行本地 Python 脚本",
|
|
293
|
+
description: `${x}每次运行需用户单独确认,文件读写授权不能代替。确认后脚本可直接读写该目录并使用标准库,改动立即落盘。不能联网,不能在运行中安装包,也不能访问该目录以外的文件。第三方包写在工程根目录 sandbox-requirements.txt。结果打印到标准输出。code 为 0 只表示已结束,成功看 data.exitCode,超时看 data.timedOut。`,
|
|
294
|
+
parameters: {
|
|
295
|
+
type: "object",
|
|
296
|
+
required: ["grantId", "path"],
|
|
297
|
+
properties: {
|
|
298
|
+
grantId: r,
|
|
299
|
+
path: {
|
|
300
|
+
type: "string",
|
|
301
|
+
description: "要运行的脚本。必须是已存在、以 .py 结尾的相对路径,以 / 分隔,不能包含 .. 、盘符或绝对路径。"
|
|
302
|
+
},
|
|
303
|
+
args: {
|
|
304
|
+
type: "array",
|
|
305
|
+
maxItems: 16,
|
|
306
|
+
description: "传给脚本的参数,最多 16 个。每个参数单独一项,不能含空格、引号或 shell 语法,只能包含字母、数字、下划线以及 . / : @ = + - , 。",
|
|
307
|
+
items: {
|
|
308
|
+
type: "string",
|
|
309
|
+
description: "一个脚本参数。"
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
timeoutMs: {
|
|
313
|
+
type: "integer",
|
|
314
|
+
minimum: 1e3,
|
|
315
|
+
maximum: 12e4,
|
|
316
|
+
description: "超时毫秒数。默认 20000,最大 120000。到时脚本会被终止。"
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}, L = c(d({}, _), {
|
|
321
|
+
run_python: I
|
|
322
|
+
});
|
|
279
323
|
export {
|
|
280
|
-
|
|
324
|
+
L as BUILTIN_TOOL_SCHEMAS,
|
|
325
|
+
_ as LOCAL_FILE_TOOL_SCHEMAS,
|
|
326
|
+
I as LOCAL_PYTHON_TOOL_SCHEMA
|
|
281
327
|
};
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var j = Object.defineProperty, p = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var $ = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var g = (i,
|
|
6
|
-
for (var
|
|
7
|
-
|
|
4
|
+
var A = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var g = (i, r, n) => r in i ? j(i, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[r] = n, s = (i, r) => {
|
|
6
|
+
for (var n in r || (r = {}))
|
|
7
|
+
A.call(r, n) && g(i, n, r[n]);
|
|
8
8
|
if ($)
|
|
9
|
-
for (var
|
|
10
|
-
|
|
9
|
+
for (var n of $(r))
|
|
10
|
+
I.call(r, n) && g(i, n, r[n]);
|
|
11
11
|
return i;
|
|
12
|
-
},
|
|
13
|
-
import { ToolError as
|
|
14
|
-
function
|
|
15
|
-
throw new
|
|
12
|
+
}, c = (i, r) => p(i, x(r));
|
|
13
|
+
import { ToolError as O, ToolCode as w } from "./errors.mjs";
|
|
14
|
+
function t(i, r) {
|
|
15
|
+
throw new O(w.BadRequest, i ? `参数 ${i} ${r}` : `参数${r}`);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
return typeof i != "string" ? i : (
|
|
17
|
+
function N(i, r) {
|
|
18
|
+
return typeof i != "string" ? i : (r.type === "integer" || r.type === "number") && /^-?\d+(\.\d+)?$/.test(i.trim()) ? Number(i) : r.type === "boolean" && (i === "true" || i === "false") ? i === "true" : i;
|
|
19
19
|
}
|
|
20
|
-
function y(i,
|
|
21
|
-
switch (i =
|
|
20
|
+
function y(i, r, n) {
|
|
21
|
+
switch (i = N(i, r), r.type) {
|
|
22
22
|
case "string":
|
|
23
|
-
typeof i != "string" &&
|
|
23
|
+
typeof i != "string" && t(n, "必须是字符串。"), r.minLength !== void 0 && i.length < r.minLength && t(n, "不能为空。");
|
|
24
24
|
break;
|
|
25
25
|
case "integer":
|
|
26
|
-
(typeof i != "number" || !Number.isInteger(i)) &&
|
|
26
|
+
(typeof i != "number" || !Number.isInteger(i)) && t(n, "必须是整数。");
|
|
27
27
|
break;
|
|
28
28
|
case "number":
|
|
29
|
-
(typeof i != "number" || !Number.isFinite(i)) &&
|
|
29
|
+
(typeof i != "number" || !Number.isFinite(i)) && t(n, "必须是数字。");
|
|
30
30
|
break;
|
|
31
31
|
case "boolean":
|
|
32
|
-
typeof i != "boolean" &&
|
|
32
|
+
typeof i != "boolean" && t(n, "必须是布尔值。");
|
|
33
33
|
break;
|
|
34
34
|
case "array":
|
|
35
|
-
if (Array.isArray(i) ||
|
|
36
|
-
const e =
|
|
37
|
-
return i.map((f, m) => y(f, e, `${
|
|
35
|
+
if (Array.isArray(i) || t(n, "必须是数组。"), r.minItems !== void 0 && i.length < r.minItems && t(n, "不能为空。"), r.items) {
|
|
36
|
+
const e = r.items;
|
|
37
|
+
return i.map((f, m) => y(f, e, `${n}[${m}]`));
|
|
38
38
|
}
|
|
39
39
|
break;
|
|
40
40
|
case "object":
|
|
41
|
-
return
|
|
41
|
+
return k(i, r, n);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return r.enum && !r.enum.includes(i) && t(n, `必须是 ${r.enum.join("、")} 之一。`), typeof i == "number" && (r.minimum !== void 0 && i < r.minimum && t(n, `不能小于 ${r.minimum}。`), r.maximum !== void 0 && i > r.maximum && t(n, `不能大于 ${r.maximum}。`)), i;
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function k(i, r, n) {
|
|
46
46
|
var m, d;
|
|
47
|
-
(!i || typeof i != "object" || Array.isArray(i)) &&
|
|
47
|
+
(!i || typeof i != "object" || Array.isArray(i)) && t(n, "必须是对象。");
|
|
48
48
|
const e = i, f = {};
|
|
49
|
-
for (const
|
|
50
|
-
(e[
|
|
51
|
-
for (const [
|
|
52
|
-
if (e[
|
|
49
|
+
for (const o of (m = r.required) != null ? m : [])
|
|
50
|
+
(e[o] === void 0 || e[o] === null) && t(n ? `${n}.${o}` : o, "是必填项。");
|
|
51
|
+
for (const [o, b] of Object.entries((d = r.properties) != null ? d : {})) {
|
|
52
|
+
if (e[o] === void 0 || e[o] === null)
|
|
53
53
|
continue;
|
|
54
|
-
const u =
|
|
55
|
-
f[
|
|
54
|
+
const u = n ? `${n}.${o}` : o;
|
|
55
|
+
f[o] = b.oneOf ? (y(e[o], c(s({}, b), {
|
|
56
56
|
oneOf: void 0
|
|
57
|
-
}), u), e[
|
|
57
|
+
}), u), e[o]) : y(e[o], b, u);
|
|
58
58
|
}
|
|
59
59
|
return f;
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
return
|
|
61
|
+
function L(i, r) {
|
|
62
|
+
return k(i, r, "");
|
|
63
63
|
}
|
|
64
64
|
export {
|
|
65
|
-
|
|
65
|
+
L as validateToolInput
|
|
66
66
|
};
|