@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.4

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 (70) hide show
  1. package/README.md +543 -98
  2. package/dist/es/AgentSession.mjs +230 -165
  3. package/dist/es/BotClient.mjs +186 -136
  4. package/dist/es/Config.mjs +111 -26
  5. package/dist/es/Session.mjs +12 -0
  6. package/dist/es/api/index.mjs +42 -33
  7. package/dist/es/index.mjs +68 -9
  8. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +174 -0
  9. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +172 -0
  10. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +162 -0
  11. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +50 -0
  12. package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
  13. package/dist/es/localFiles/constants.mjs +47 -0
  14. package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
  15. package/dist/es/localFiles/createLocalPythonPlugin.mjs +196 -0
  16. package/dist/es/localFiles/errors.mjs +57 -0
  17. package/dist/es/localFiles/host/connectHostBridge.mjs +50 -0
  18. package/dist/es/localFiles/host/protocol.mjs +26 -0
  19. package/dist/es/localFiles/limits.mjs +22 -0
  20. package/dist/es/localFiles/schemas.mjs +327 -0
  21. package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
  22. package/dist/es/localFiles/security/glob.mjs +28 -0
  23. package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
  24. package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
  25. package/dist/es/localFiles/tools/readTools.mjs +333 -0
  26. package/dist/es/localFiles/tools/runtime.mjs +108 -0
  27. package/dist/es/localFiles/tools/transferTools.mjs +228 -0
  28. package/dist/es/localFiles/tools/writeTools.mjs +173 -0
  29. package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
  30. package/dist/es/localFiles/validate.mjs +66 -0
  31. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +339 -0
  32. package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
  33. package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
  34. package/dist/es/package.json.mjs +7 -4
  35. package/dist/lib/index.js +9 -4
  36. package/dist/src/AgentSession.d.ts +9 -0
  37. package/dist/src/BotClient.d.ts +12 -2
  38. package/dist/src/Config.d.ts +22 -0
  39. package/dist/src/Session.d.ts +5 -1
  40. package/dist/src/api/index.d.ts +3 -1
  41. package/dist/src/index.d.ts +4 -2
  42. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +17 -0
  43. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +24 -0
  44. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +18 -0
  45. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +26 -0
  46. package/dist/src/localFiles/adapters/fsaTypes.d.ts +39 -0
  47. package/dist/src/localFiles/constants.d.ts +50 -0
  48. package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
  49. package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
  50. package/dist/src/localFiles/errors.d.ts +34 -0
  51. package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
  52. package/dist/src/localFiles/host/protocol.d.ts +33 -0
  53. package/dist/src/localFiles/index.d.ts +21 -0
  54. package/dist/src/localFiles/limits.d.ts +3 -0
  55. package/dist/src/localFiles/schemas.d.ts +30 -0
  56. package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
  57. package/dist/src/localFiles/security/glob.d.ts +3 -0
  58. package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
  59. package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
  60. package/dist/src/localFiles/tools/readTools.d.ts +7 -0
  61. package/dist/src/localFiles/tools/runtime.d.ts +43 -0
  62. package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
  63. package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
  64. package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
  65. package/dist/src/localFiles/types.d.ts +306 -0
  66. package/dist/src/localFiles/validate.d.ts +2 -0
  67. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +99 -0
  68. package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
  69. package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
  70. package/package.json +7 -4
@@ -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,327 @@
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 = {
15
+ type: "string",
16
+ enum: [m],
17
+ description: `工作区 ID。省略时按 ${m} 处理,传其他值会被拒绝。`
18
+ }, n = (t) => ({
19
+ type: "string",
20
+ description: `${t}使用相对工作区根目录的路径,以 / 分隔,不能包含 .. 或绝对路径。`
21
+ }), s = {
22
+ type: "string",
23
+ description: "文件当前内容的 hash(sha256:<hex>),来自 read_file 或 stat_file 的返回值。"
24
+ }, _ = {
25
+ list_directory: {
26
+ functionCode: "list_directory",
27
+ name: "列出本地目录",
28
+ description: `${p}列出某个目录的直接子项(目录在前),支持分页。`,
29
+ parameters: {
30
+ type: "object",
31
+ required: ["grantId"],
32
+ properties: {
33
+ grantId: r,
34
+ path: n('要列出的目录,省略或传 "." 表示工作区根目录。'),
35
+ offset: {
36
+ type: "integer",
37
+ minimum: 0,
38
+ description: "分页起始位置,默认 0。"
39
+ },
40
+ limit: {
41
+ type: "integer",
42
+ minimum: 1,
43
+ maximum: 1e3,
44
+ description: "每页条数,默认 200。"
45
+ }
46
+ }
47
+ }
48
+ },
49
+ read_file: {
50
+ functionCode: "read_file",
51
+ name: "读取本地文件",
52
+ description: `${p}按行读取文本文件,单次最多返回 1 MiB,超出部分会被截断(truncated: true)。返回内容的 hash 可用于后续修改。`,
53
+ parameters: {
54
+ type: "object",
55
+ required: ["grantId", "path"],
56
+ properties: {
57
+ grantId: r,
58
+ path: n("要读取的文件。"),
59
+ startLine: {
60
+ type: "integer",
61
+ minimum: 1,
62
+ description: "起始行(从 1 开始,含)。"
63
+ },
64
+ endLine: {
65
+ type: "integer",
66
+ minimum: 1,
67
+ description: "结束行(含)。"
68
+ },
69
+ maxBytes: {
70
+ type: "integer",
71
+ minimum: 1,
72
+ description: "返回内容的最大字节数,不超过 1 MiB。"
73
+ },
74
+ encoding: {
75
+ type: "string",
76
+ enum: ["utf-8", "gbk", "gb18030"],
77
+ description: "文本编码,默认 utf-8。"
78
+ }
79
+ }
80
+ }
81
+ },
82
+ stat_file: {
83
+ functionCode: "stat_file",
84
+ name: "查看本地文件信息",
85
+ description: `${p}返回文件或目录的类型、大小、修改时间,可选返回 hash。不返回文件内容。`,
86
+ parameters: {
87
+ type: "object",
88
+ required: ["grantId", "path"],
89
+ properties: {
90
+ grantId: r,
91
+ path: n("要查看的文件或目录。"),
92
+ includeHash: {
93
+ type: "boolean",
94
+ description: "是否计算文件 hash。"
95
+ }
96
+ }
97
+ }
98
+ },
99
+ search_files: {
100
+ functionCode: "search_files",
101
+ name: "查找本地文件",
102
+ description: `${p}按文件名或 glob(支持 *、?、**)查找文件。不含 / 的模式匹配文件名,含 / 的模式匹配相对 path 的路径。`,
103
+ parameters: {
104
+ type: "object",
105
+ required: ["grantId", "pattern"],
106
+ properties: {
107
+ grantId: r,
108
+ pattern: {
109
+ type: "string",
110
+ minLength: 1,
111
+ description: "如 *.xlsx 或 reports/**/*.docx。"
112
+ },
113
+ path: n("搜索起点目录,默认工作区根目录。"),
114
+ maxDepth: {
115
+ type: "integer",
116
+ minimum: 1,
117
+ maximum: 16,
118
+ description: "最大目录深度,默认 8。"
119
+ },
120
+ maxResults: {
121
+ type: "integer",
122
+ minimum: 1,
123
+ maximum: 200,
124
+ description: "最多返回条数,默认 200。"
125
+ }
126
+ }
127
+ }
128
+ },
129
+ search_text: {
130
+ functionCode: "search_text",
131
+ name: "搜索本地文本",
132
+ description: `${p}在指定文件或目录(递归)中搜索普通文本(不支持正则),返回所在文件、行号与该行内容。必须指定 path,不能搜索整个文件夹。`,
133
+ parameters: {
134
+ type: "object",
135
+ required: ["grantId", "path", "query"],
136
+ properties: {
137
+ grantId: r,
138
+ path: n("搜索范围,可以是文件或目录。"),
139
+ query: {
140
+ type: "string",
141
+ minLength: 1,
142
+ description: "要查找的文本。"
143
+ },
144
+ caseSensitive: {
145
+ type: "boolean",
146
+ description: "是否区分大小写,默认否。"
147
+ },
148
+ isRegex: {
149
+ type: "boolean",
150
+ description: "暂不支持正则,传 true 会返回 501。"
151
+ },
152
+ glob: {
153
+ type: "string",
154
+ description: "只搜索匹配该 glob 的文件,如 *.md。"
155
+ },
156
+ maxResults: {
157
+ type: "integer",
158
+ minimum: 1,
159
+ maximum: 200,
160
+ description: "最多返回条数,默认 200。"
161
+ },
162
+ contextLines: {
163
+ type: "integer",
164
+ minimum: 0,
165
+ maximum: 3,
166
+ description: "附带的上下文行数,默认 0。"
167
+ }
168
+ }
169
+ }
170
+ },
171
+ apply_patch: {
172
+ functionCode: "apply_patch",
173
+ name: "修改本地文件",
174
+ description: `${p}以查找替换的方式修改 UTF-8 文本文件。每条修改的 oldText 必须在文件中唯一出现(或设置 replaceAll)。执行前需要用户确认。`,
175
+ parameters: {
176
+ type: "object",
177
+ required: ["grantId", "path", "expectedHash", "edits"],
178
+ properties: {
179
+ grantId: r,
180
+ path: n("要修改的文件。"),
181
+ expectedHash: s,
182
+ edits: {
183
+ type: "array",
184
+ minItems: 1,
185
+ description: "按顺序应用的修改。",
186
+ items: {
187
+ type: "object",
188
+ required: ["oldText", "newText"],
189
+ properties: {
190
+ oldText: {
191
+ type: "string",
192
+ minLength: 1,
193
+ description: "要替换的原文,需包含足够上下文以保证唯一。"
194
+ },
195
+ newText: {
196
+ type: "string",
197
+ description: "替换后的文本。"
198
+ },
199
+ replaceAll: {
200
+ type: "boolean",
201
+ description: "是否替换所有出现位置,默认否。"
202
+ }
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+ },
209
+ write_file: {
210
+ functionCode: "write_file",
211
+ name: "写入本地文件",
212
+ description: `${p}新建文件,或整体覆盖已有文件(覆盖时必须提供 expectedHash)。修改已有文件优先使用 apply_patch。执行前需要用户确认。`,
213
+ parameters: {
214
+ type: "object",
215
+ required: ["grantId", "path", "content"],
216
+ properties: {
217
+ grantId: r,
218
+ path: n("要写入的文件。"),
219
+ content: {
220
+ type: "string",
221
+ description: "完整的文件内容(UTF-8)。"
222
+ },
223
+ expectedHash: s,
224
+ createDirectories: {
225
+ type: "boolean",
226
+ description: "父目录不存在时是否自动创建,默认否。"
227
+ }
228
+ }
229
+ }
230
+ },
231
+ upload_file: {
232
+ functionCode: "upload_file",
233
+ name: "上传本地文件",
234
+ description: `${p}把本地文件夹中的文件上传到平台文件服务,返回 fileId、name、size 和 url。url 是文件访问地址,可直接用于后续推理或对话。下载回本地文件夹时使用 download_file,source.type 为 platformFile。单文件不超过 50 MB。执行前需要用户确认。`,
235
+ parameters: {
236
+ type: "object",
237
+ required: ["grantId", "path"],
238
+ properties: {
239
+ grantId: r,
240
+ path: n("要上传的文件。"),
241
+ target: {
242
+ type: "string",
243
+ description: "上传目标,目前只支持 session(默认),其他值返回 501。"
244
+ },
245
+ mimeHint: {
246
+ type: "string",
247
+ description: "可选的 MIME 类型。"
248
+ }
249
+ }
250
+ }
251
+ },
252
+ download_file: {
253
+ functionCode: "download_file",
254
+ name: "下载到本地文件夹",
255
+ description: `${p}把会话文件、平台文件或 https 地址保存到本地文件夹。source.type 为 url 时必须同时填写 source.url(完整地址),为 sessionFile 或 platformFile 时必须同时填写 source.fileId。不要只传 type。单文件不超过 50 MB。执行前需要用户确认。`,
256
+ parameters: {
257
+ type: "object",
258
+ required: ["grantId", "destPath", "source"],
259
+ properties: {
260
+ grantId: r,
261
+ destPath: n("保存位置(文件路径)。"),
262
+ source: {
263
+ type: "object",
264
+ required: ["type"],
265
+ description: "下载来源。type 为 url 时必填 url;type 为 sessionFile 或 platformFile 时必填 fileId。",
266
+ properties: {
267
+ type: {
268
+ type: "string",
269
+ enum: ["sessionFile", "platformFile", "url"],
270
+ description: "sessionFile:当前会话文件;platformFile:平台文件(upload_file 返回的 fileId);url:https 地址。"
271
+ },
272
+ fileId: {
273
+ type: "string",
274
+ description: "type 为 sessionFile 或 platformFile 时必填,不能只传 type。"
275
+ },
276
+ url: {
277
+ type: "string",
278
+ description: "type 为 url 时必填,填写完整 https 地址。不能只传 type。默认只允许 glodon.com 及其子域。"
279
+ }
280
+ }
281
+ },
282
+ overwrite: {
283
+ type: "boolean",
284
+ description: "目标已存在时是否覆盖,默认否。"
285
+ },
286
+ expectedHash: s
287
+ }
288
+ }
289
+ }
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
+ });
323
+ export {
324
+ L as BUILTIN_TOOL_SCHEMAS,
325
+ _ as LOCAL_FILE_TOOL_SCHEMAS,
326
+ I as LOCAL_PYTHON_TOOL_SCHEMA
327
+ };
@@ -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
+ };