@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.5
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 +572 -98
- package/dist/es/AgentSession.mjs +230 -165
- package/dist/es/BotClient.mjs +186 -136
- package/dist/es/Config.mjs +89 -26
- package/dist/es/Session.mjs +12 -0
- package/dist/es/api/index.mjs +42 -33
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +236 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +63 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +471 -0
- package/dist/es/index.mjs +69 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +233 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
- package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
- package/dist/es/localFiles/constants.mjs +47 -0
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +54 -0
- package/dist/es/localFiles/host/protocol.mjs +27 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +312 -0
- package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
- package/dist/es/localFiles/security/glob.mjs +28 -0
- package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
- package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
- package/dist/es/localFiles/tools/readTools.mjs +333 -0
- package/dist/es/localFiles/tools/runtime.mjs +108 -0
- package/dist/es/localFiles/tools/transferTools.mjs +228 -0
- package/dist/es/localFiles/tools/writeTools.mjs +173 -0
- package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
- package/dist/es/localFiles/validate.mjs +66 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
- package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
- package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
- package/dist/es/package.json.mjs +38 -29
- package/dist/lib/index.js +373 -5
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +22 -0
- package/dist/src/Session.d.ts +5 -1
- package/dist/src/api/index.d.ts +3 -1
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +26 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +15 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +60 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +43 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
- package/dist/src/localFiles/constants.d.ts +51 -0
- package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
- package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
- package/dist/src/localFiles/errors.d.ts +34 -0
- package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
- package/dist/src/localFiles/host/protocol.d.ts +46 -0
- package/dist/src/localFiles/index.d.ts +22 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +29 -0
- package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
- package/dist/src/localFiles/security/glob.d.ts +3 -0
- package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
- package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
- package/dist/src/localFiles/tools/readTools.d.ts +7 -0
- package/dist/src/localFiles/tools/runtime.d.ts +43 -0
- package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
- package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
- package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
- package/dist/src/localFiles/types.d.ts +319 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +13 -4
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const n = "glodon-workspace", i = 1;
|
|
2
|
+
function s(t) {
|
|
3
|
+
let e = t;
|
|
4
|
+
if (typeof e == "string")
|
|
5
|
+
try {
|
|
6
|
+
e = JSON.parse(e);
|
|
7
|
+
} catch (r) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (!e || typeof e != "object")
|
|
11
|
+
return;
|
|
12
|
+
const o = e;
|
|
13
|
+
if (o.channel === n)
|
|
14
|
+
return o;
|
|
15
|
+
}
|
|
16
|
+
function c() {
|
|
17
|
+
var e;
|
|
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;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
n as HOST_CHANNEL,
|
|
24
|
+
i as SANDBOX_PROTOCOL,
|
|
25
|
+
c as getHostWebView,
|
|
26
|
+
s as parseHostMessage
|
|
27
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DEFAULT_DOWNLOAD_URL_ALLOWLIST as l } from "../constants.mjs";
|
|
2
|
+
const i = /^[a-z0-9-]+(\.[a-z0-9-]+)+$/;
|
|
3
|
+
function a(t) {
|
|
4
|
+
if (typeof t != "string")
|
|
5
|
+
return null;
|
|
6
|
+
const r = t.trim().toLowerCase().replace(/^\*?\./, "").replace(/\.$/, "");
|
|
7
|
+
return !i.test(r) || s(r) ? null : r;
|
|
8
|
+
}
|
|
9
|
+
function s(t) {
|
|
10
|
+
return t.startsWith("[") || t.includes(":") ? !0 : /^[0-9.]+$/.test(t) || /^0x[0-9a-f.]+$/i.test(t);
|
|
11
|
+
}
|
|
12
|
+
function f(t = []) {
|
|
13
|
+
const r = new Set(l);
|
|
14
|
+
for (const n of t) {
|
|
15
|
+
const e = a(n);
|
|
16
|
+
e && r.add(e);
|
|
17
|
+
}
|
|
18
|
+
return Array.from(r);
|
|
19
|
+
}
|
|
20
|
+
function d(t, r) {
|
|
21
|
+
return u(t, f(r));
|
|
22
|
+
}
|
|
23
|
+
function u(t, r) {
|
|
24
|
+
let n;
|
|
25
|
+
try {
|
|
26
|
+
n = new URL(t);
|
|
27
|
+
} catch (o) {
|
|
28
|
+
return !1;
|
|
29
|
+
}
|
|
30
|
+
if (n.protocol !== "https:" || n.username || n.password)
|
|
31
|
+
return !1;
|
|
32
|
+
const e = n.hostname.toLowerCase().replace(/\.$/, "");
|
|
33
|
+
return !e || s(e) || e === "localhost" || e.endsWith(".localhost") ? !1 : r.some((o) => e === o || e.endsWith(`.${o}`));
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
f as getDownloadUrlAllowlist,
|
|
37
|
+
d as isDownloadUrlAllowed,
|
|
38
|
+
u as isDownloadUrlAllowedByList
|
|
39
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const i = /* @__PURE__ */ new Map();
|
|
2
|
+
function u(e) {
|
|
3
|
+
return /[\\^$.|+()[\]{}]/.test(e) ? `\\${e}` : e;
|
|
4
|
+
}
|
|
5
|
+
function r(e, n = !1) {
|
|
6
|
+
const o = `${n ? "s" : "i"}:${e}`, f = i.get(o);
|
|
7
|
+
if (f)
|
|
8
|
+
return f;
|
|
9
|
+
let c = "";
|
|
10
|
+
for (let s = 0; s < e.length; s++) {
|
|
11
|
+
const t = e[s];
|
|
12
|
+
t === "*" ? e[s + 1] === "*" ? (s++, e[s + 1] === "/" ? (s++, c += "(?:.*/)?") : c += ".*") : c += "[^/]*" : t === "?" ? c += "[^/]" : c += u(t);
|
|
13
|
+
}
|
|
14
|
+
const l = new RegExp(`^${c}$`, n ? "" : "i");
|
|
15
|
+
return i.set(o, l), l;
|
|
16
|
+
}
|
|
17
|
+
function g(e, n, o = !1) {
|
|
18
|
+
return r(e, o).test(n);
|
|
19
|
+
}
|
|
20
|
+
function x(e) {
|
|
21
|
+
const n = e.lastIndexOf("/");
|
|
22
|
+
return n < 0 ? e : e.slice(n + 1);
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
x as basename,
|
|
26
|
+
r as globToRegExp,
|
|
27
|
+
g as matchGlob
|
|
28
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { WORKSPACE_GRANT_ID as u } from "../constants.mjs";
|
|
2
|
+
import { ToolError as e, ToolCode as r } from "../errors.mjs";
|
|
3
|
+
const d = "路径必须是工作区内的相对路径,不能包含 ..、绝对路径或盘符。";
|
|
4
|
+
function i() {
|
|
5
|
+
return new e(r.Forbidden, d, {
|
|
6
|
+
reason: "path_outside_workspace"
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function l(t) {
|
|
10
|
+
if (t !== u)
|
|
11
|
+
throw new e(r.Forbidden, `未知的工作区 grantId,当前仅支持 ${u}。`, {
|
|
12
|
+
reason: "path_outside_workspace"
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function m(t, {
|
|
16
|
+
allowRoot: o = !1,
|
|
17
|
+
field: s = "path"
|
|
18
|
+
} = {}) {
|
|
19
|
+
if (t == null) {
|
|
20
|
+
if (o)
|
|
21
|
+
return "";
|
|
22
|
+
throw new e(r.BadRequest, `缺少参数 ${s}。`);
|
|
23
|
+
}
|
|
24
|
+
if (typeof t != "string")
|
|
25
|
+
throw new e(r.BadRequest, `参数 ${s} 必须是字符串。`);
|
|
26
|
+
if (t.includes("\0") || /%(2e|2f|5c|00)/i.test(t))
|
|
27
|
+
throw i();
|
|
28
|
+
const f = t.normalize("NFC").replace(/\\/g, "/").trim();
|
|
29
|
+
if (f.startsWith("/") || /^[a-zA-Z]:/.test(f))
|
|
30
|
+
throw i();
|
|
31
|
+
const a = [];
|
|
32
|
+
for (const n of f.split("/"))
|
|
33
|
+
if (!(n === "" || n === ".")) {
|
|
34
|
+
if (n === "..")
|
|
35
|
+
throw i();
|
|
36
|
+
a.push(n);
|
|
37
|
+
}
|
|
38
|
+
const c = a.join("/");
|
|
39
|
+
if (!c && !o)
|
|
40
|
+
throw new e(r.BadRequest, `参数 ${s} 不能指向工作区根目录。`);
|
|
41
|
+
return c;
|
|
42
|
+
}
|
|
43
|
+
function p(t) {
|
|
44
|
+
return t ? t.split("/") : [];
|
|
45
|
+
}
|
|
46
|
+
function _(t) {
|
|
47
|
+
const o = t.lastIndexOf("/");
|
|
48
|
+
return o < 0 ? "" : t.slice(0, o);
|
|
49
|
+
}
|
|
50
|
+
function $(t, o) {
|
|
51
|
+
return t ? `${t}/${o}` : o;
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
l as assertGrantId,
|
|
55
|
+
$ as joinPath,
|
|
56
|
+
m as normalizeWorkspacePath,
|
|
57
|
+
_ as parentPath,
|
|
58
|
+
p as splitPath
|
|
59
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var l = Object.defineProperty, u = Object.defineProperties;
|
|
2
|
+
var b = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var i = Object.getOwnPropertySymbols;
|
|
4
|
+
var k = Object.prototype.hasOwnProperty, m = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var a = (r, e, s) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[e] = s, o = (r, e) => {
|
|
6
|
+
for (var s in e || (e = {}))
|
|
7
|
+
k.call(e, s) && a(r, s, e[s]);
|
|
8
|
+
if (i)
|
|
9
|
+
for (var s of i(e))
|
|
10
|
+
m.call(e, s) && a(r, s, e[s]);
|
|
11
|
+
return r;
|
|
12
|
+
}, c = (r, e) => u(r, b(e));
|
|
13
|
+
var d = (r, e, s) => (a(r, typeof e != "symbol" ? e + "" : e, s), s);
|
|
14
|
+
import { basename as S, matchGlob as f } from "./glob.mjs";
|
|
15
|
+
const h = Object.freeze([{
|
|
16
|
+
id: "env-files",
|
|
17
|
+
pattern: ".env*",
|
|
18
|
+
reason: "环境变量文件可能包含密钥",
|
|
19
|
+
source: "sdk-baseline"
|
|
20
|
+
}, {
|
|
21
|
+
id: "pem",
|
|
22
|
+
pattern: "*.pem",
|
|
23
|
+
reason: "证书或密钥文件",
|
|
24
|
+
source: "sdk-baseline"
|
|
25
|
+
}, {
|
|
26
|
+
id: "key",
|
|
27
|
+
pattern: "*.key",
|
|
28
|
+
reason: "密钥文件",
|
|
29
|
+
source: "sdk-baseline"
|
|
30
|
+
}, {
|
|
31
|
+
id: "p12",
|
|
32
|
+
pattern: "*.p12",
|
|
33
|
+
reason: "证书文件",
|
|
34
|
+
source: "sdk-baseline"
|
|
35
|
+
}, {
|
|
36
|
+
id: "pfx",
|
|
37
|
+
pattern: "*.pfx",
|
|
38
|
+
reason: "证书文件",
|
|
39
|
+
source: "sdk-baseline"
|
|
40
|
+
}, {
|
|
41
|
+
id: "id-rsa",
|
|
42
|
+
pattern: "id_rsa*",
|
|
43
|
+
reason: "SSH 私钥",
|
|
44
|
+
source: "sdk-baseline"
|
|
45
|
+
}, {
|
|
46
|
+
id: "id-ed25519",
|
|
47
|
+
pattern: "id_ed25519*",
|
|
48
|
+
reason: "SSH 私钥",
|
|
49
|
+
source: "sdk-baseline"
|
|
50
|
+
}, {
|
|
51
|
+
id: "id-ecdsa",
|
|
52
|
+
pattern: "id_ecdsa*",
|
|
53
|
+
reason: "SSH 私钥",
|
|
54
|
+
source: "sdk-baseline"
|
|
55
|
+
}, {
|
|
56
|
+
id: "credentials",
|
|
57
|
+
pattern: ".credentials",
|
|
58
|
+
reason: "凭据文件",
|
|
59
|
+
source: "sdk-baseline"
|
|
60
|
+
}, {
|
|
61
|
+
id: "npmrc",
|
|
62
|
+
pattern: ".npmrc",
|
|
63
|
+
reason: "可能包含 registry token",
|
|
64
|
+
source: "sdk-baseline"
|
|
65
|
+
}, {
|
|
66
|
+
id: "pypirc",
|
|
67
|
+
pattern: ".pypirc",
|
|
68
|
+
reason: "可能包含仓库凭据",
|
|
69
|
+
source: "sdk-baseline"
|
|
70
|
+
}, {
|
|
71
|
+
id: "aws-credentials",
|
|
72
|
+
pattern: "**/.aws/credentials",
|
|
73
|
+
match: "path",
|
|
74
|
+
reason: "云服务凭据",
|
|
75
|
+
source: "sdk-baseline"
|
|
76
|
+
}, {
|
|
77
|
+
id: "ssh-dir",
|
|
78
|
+
pattern: "**/.ssh/**",
|
|
79
|
+
match: "path",
|
|
80
|
+
reason: "SSH 配置与密钥",
|
|
81
|
+
source: "sdk-baseline"
|
|
82
|
+
}]), y = "该文件被列为敏感文件,不允许访问";
|
|
83
|
+
class g {
|
|
84
|
+
constructor(e = []) {
|
|
85
|
+
d(this, "rules");
|
|
86
|
+
const s = e.filter((t) => t && typeof t.pattern == "string" && t.pattern).map((t) => c(o({}, t), {
|
|
87
|
+
id: String(t.id || t.pattern),
|
|
88
|
+
source: t.source === "enterprise" ? "enterprise" : "product"
|
|
89
|
+
}));
|
|
90
|
+
this.rules = [...h, ...s];
|
|
91
|
+
}
|
|
92
|
+
match(e, s) {
|
|
93
|
+
if (!e)
|
|
94
|
+
return null;
|
|
95
|
+
const t = S(e);
|
|
96
|
+
for (const n of this.rules) {
|
|
97
|
+
if (n.operations && !n.operations.includes(s))
|
|
98
|
+
continue;
|
|
99
|
+
const p = n.match === "path" ? e : t;
|
|
100
|
+
if (f(n.pattern, p))
|
|
101
|
+
return n;
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
isSensitive(e) {
|
|
106
|
+
return ["read", "write", "search"].some((s) => this.match(e, s) !== null);
|
|
107
|
+
}
|
|
108
|
+
static reasonOf(e) {
|
|
109
|
+
return `${e.reason || y},已拒绝访问。`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
h as SDK_SENSITIVE_BASELINE,
|
|
114
|
+
g as SensitiveFilePolicy
|
|
115
|
+
};
|