@glodon-aiot/bot-client-sdk 3.26.0-alpha.17 → 3.26.0-alpha.19
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 +58 -30
- package/dist/es/Session.mjs +35 -23
- package/dist/es/index.mjs +50 -46
- package/dist/es/localFiles/host/protocol.mjs +8 -7
- package/dist/es/localFiles/host/sandboxClient.mjs +19 -19
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +24 -18
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +188 -0
- package/dist/es/package.json.mjs +2 -2
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/lib/index.js +43 -43
- package/dist/src/Session.d.ts +6 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/localFiles/host/protocol.d.ts +2 -0
- package/dist/src/localFiles/index.d.ts +3 -1
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +7 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +54 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -323,42 +323,70 @@ const disclosureAcked = await workspace.isDisclosureAcknowledged();
|
|
|
323
323
|
|
|
324
324
|
说明弹窗的「继续」按钮同样不能先 `await acknowledgeDisclosure()` 再 `pick()`。`acknowledgeDisclosure` 按 `applicationId` 记住,同一应用下不再重复提示。
|
|
325
325
|
|
|
326
|
-
###
|
|
326
|
+
### 读和写文件
|
|
327
|
+
|
|
328
|
+
`status === 'granted'` 之后,用 `workspace.files` 操作这个文件夹。路径写成 `notes/a.md`,或写成 `/notes/a.md`。根目录用 `''`,也可以把参数省略。`..`、盘符、空字符会失败。
|
|
327
329
|
|
|
328
|
-
|
|
330
|
+
| 方法 | 作用 |
|
|
331
|
+
| --- | --- |
|
|
332
|
+
| `list(path?)` | 只列这一层,不递归 |
|
|
333
|
+
| `stat(path?)` | 看这一项是文件还是目录 |
|
|
334
|
+
| `read(path)` | 读出整个文件,得到 `Blob` |
|
|
335
|
+
| `readText(path)` | 读出整个文件的 UTF-8 文本 |
|
|
336
|
+
| `write(path, source)` | 覆盖写入。`source` 可以是字符串、`Uint8Array` 或字节流。父目录不存在时会创建 |
|
|
337
|
+
| `append(path, source)` | 在末尾追加字符串或 `Uint8Array`。文件不存在时创建 |
|
|
338
|
+
| `mkdir(path)` | 逐级创建目录。目录已存在时不做任何事 |
|
|
339
|
+
| `remove(path, options?)` | 删除文件或目录。目录里还有内容时要传 `{ recursive: true }` |
|
|
340
|
+
| `move(from, to)` | 移动或重命名。`to` 是新的完整路径,例如把 `a/old.txt` 改成 `b/new.txt`。`to` 的父目录要已经存在 |
|
|
341
|
+
|
|
342
|
+
`list` 和 `stat` 返回的每一项都有:
|
|
343
|
+
|
|
344
|
+
| 字段 | 含义 |
|
|
345
|
+
| --- | --- |
|
|
346
|
+
| `name` | 这一层的名字 |
|
|
347
|
+
| `path` | 相对工作区根的路径。根目录本身是 `''` |
|
|
348
|
+
| `kind` | `file` 或 `directory` |
|
|
349
|
+
| `size` | 字节数。网页里选的文件夹,列目录时常常没有这一项 |
|
|
350
|
+
| `lastModified` | 修改时间。同样可能没有 |
|
|
351
|
+
| `sensitive` | 是否为敏感文件,例如 `.env`、密钥、证书。目录恒为 `false` |
|
|
329
352
|
|
|
330
353
|
```ts
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
return entries.map((entry) => {
|
|
337
|
-
const path = dir ? `${dir}/${entry.name}` : entry.name;
|
|
338
|
-
return {
|
|
339
|
-
path,
|
|
340
|
-
...entry,
|
|
341
|
-
sensitive: entry.kind === 'file' && workspace.sensitive.isSensitive(path),
|
|
342
|
-
};
|
|
343
|
-
});
|
|
344
|
-
} catch (error) {
|
|
345
|
-
if (isNotAllowed(error)) void workspace.handlePermissionLost();
|
|
346
|
-
throw error;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
354
|
+
const entries = await workspace.files.list('notes');
|
|
355
|
+
const text = await workspace.files.readText('notes/a.md');
|
|
356
|
+
await workspace.files.write('notes/a.md', `${text}\n`);
|
|
357
|
+
await workspace.files.move('notes/a.md', 'notes/b.md');
|
|
358
|
+
```
|
|
349
359
|
|
|
350
|
-
|
|
351
|
-
|
|
360
|
+
失败时抛 `ToolError`。用 `code` 和 `data.reason` 区分原因,文案里没有本机绝对路径。
|
|
361
|
+
|
|
362
|
+
| `data.reason` | 什么时候 |
|
|
363
|
+
| --- | --- |
|
|
364
|
+
| `workspace_not_granted` | 还没授权。授权中途失效时,`status` 会先离开 `granted`,然后再抛这个错误 |
|
|
365
|
+
| `path_outside_workspace` | 路径越出了工作区 |
|
|
366
|
+
| `sensitive_file` | 读、写、追加、删除或移动敏感文件。`list` 和 `stat` 仍会返回这些文件,只是 `sensitive` 为 `true` |
|
|
367
|
+
|
|
368
|
+
`code` 的完整含义见[错误码](#错误码)。当前工作区如果只是一次文件选择留下的内存快照(`attachFileSnapshot`),可以读、列目录和在内存里写;`mkdir`、`remove`、`move` 的 `code` 为 501,内容也不会写回磁盘。
|
|
369
|
+
|
|
370
|
+
`write`、`append`、`mkdir`、`remove`、`move` 成功后会发出 `files:changed`,见下面的目录树。
|
|
371
|
+
|
|
372
|
+
### 目录树
|
|
373
|
+
|
|
374
|
+
展开哪一层,就列哪一层。根目录不传路径:
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
async function loadDirectory(dir = '') {
|
|
378
|
+
return workspace.files.list(dir);
|
|
352
379
|
}
|
|
353
380
|
```
|
|
354
381
|
|
|
355
|
-
|
|
382
|
+
记下用户已经展开的目录。文件有变化时,SDK 大约每 150 毫秒把要重读的目录合成一次 `files:changed`:
|
|
356
383
|
|
|
357
384
|
| 来源 | `paths` |
|
|
358
385
|
| --- | --- |
|
|
359
|
-
|
|
|
360
|
-
|
|
|
361
|
-
| `shell`、`run_file`、`run_skill_script` 结束 | `[]
|
|
386
|
+
| 网页里的文件变化(Chrome、Edge 的 `FileSystemObserver`) | 发生变化的目录。根目录是 `''` |
|
|
387
|
+
| 宿主推送的 `fs-changed` | 宿主给出的相对目录 |
|
|
388
|
+
| `shell`、`run_file`、`run_skill_script` 结束 | `[]`。空数组表示重读根目录,以及当前已经展开的每一层 |
|
|
389
|
+
| 上面的 `files` 写入、建目录、删除、移动 | 被改动那一项的父目录 |
|
|
362
390
|
|
|
363
391
|
```ts
|
|
364
392
|
const expanded = new Set<string>();
|
|
@@ -369,7 +397,7 @@ workspace.on('files:changed', (event) => {
|
|
|
369
397
|
});
|
|
370
398
|
```
|
|
371
399
|
|
|
372
|
-
|
|
400
|
+
有的环境看不到资源管理器里的改动。窗口重新得到焦点时,重读根目录和已展开的目录。助手改完文件时还会发 `tool:finish`,用它刷新被改文件的父目录。
|
|
373
401
|
|
|
374
402
|
```ts
|
|
375
403
|
window.addEventListener('focus', () => {
|
|
@@ -385,7 +413,7 @@ workspace.on('tool:finish', (event) => {
|
|
|
385
413
|
});
|
|
386
414
|
```
|
|
387
415
|
|
|
388
|
-
|
|
416
|
+
目录树只展示名字和层级。用户打开某个文件时,用 `files.read` 或 `files.readText` 取内容。展示给用户的内容和交给模型的内容分开:交给模型的文件内容只来自助手自己调用的内置工具。
|
|
389
417
|
|
|
390
418
|
### 确认弹窗
|
|
391
419
|
|
|
@@ -472,7 +500,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
472
500
|
|
|
473
501
|
| 能力 | 行为 |
|
|
474
502
|
| --- | --- |
|
|
475
|
-
| shell | 按需 `import(bashModuleURL)` 加载 just-bash
|
|
503
|
+
| shell | 按需 `import(bashModuleURL)` 加载 just-bash,读写当前已授权的工作区 |
|
|
476
504
|
| Python | Blob Module Worker 加载 Pyodide;白名单包:numpy、pandas、matplotlib、pillow、lxml |
|
|
477
505
|
| Node / `.js` | 明确报错,提示改用 python3 或 shell |
|
|
478
506
|
| pip / 任意第三方 | 不支持 |
|
|
@@ -553,7 +581,7 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
|
|
|
553
581
|
|
|
554
582
|
## 安全与限额
|
|
555
583
|
|
|
556
|
-
|
|
584
|
+
敏感文件不可读、不可写、不可上传、不可运行,也不出现在搜索结果里。助手的 `list_directory`、`stat_file`,以及 `files.list`、`files.stat`,仍会返回它们,并带上 `sensitive: true`。真正去读或改这些文件时返回 403,`reason` 为 `sensitive_file`,`data.ruleId` 是规则 ID。
|
|
557
585
|
|
|
558
586
|
基线(`SDK_SENSITIVE_BASELINE`)始终生效,`sensitiveRulesAppend` 只能再加规则:
|
|
559
587
|
|
package/dist/es/Session.mjs
CHANGED
|
@@ -9,7 +9,7 @@ var b = (l, e, t) => e in l ? T(l, e, { enumerable: !0, configurable: !0, writab
|
|
|
9
9
|
for (var t of E(e))
|
|
10
10
|
O.call(e, t) && b(l, t, e[t]);
|
|
11
11
|
return l;
|
|
12
|
-
},
|
|
12
|
+
}, y = (l, e) => C(l, M(e));
|
|
13
13
|
var p = (l, e, t) => (b(l, typeof e != "symbol" ? e + "" : e, t), t);
|
|
14
14
|
var c = (l, e, t) => new Promise((s, a) => {
|
|
15
15
|
var n = (i) => {
|
|
@@ -35,9 +35,10 @@ import { configuration as S } from "./Config.mjs";
|
|
|
35
35
|
import B from "./EventBus.mjs";
|
|
36
36
|
import { getCVForceService as H } from "./api/index.mjs";
|
|
37
37
|
import K from "dayjs";
|
|
38
|
+
import { uploadSessionFile as Y } from "./sessionUpload.mjs";
|
|
38
39
|
const V = 100, u = new U("[Session] ");
|
|
39
|
-
var
|
|
40
|
-
class
|
|
40
|
+
var D = /* @__PURE__ */ ((l) => (l.DataRequestFailed = "data request error", l.SocketConnectionFailed = "socket error", l.IdUndefined = "session id is not defined", l.SendingEmptyContent = "failed at sending empty content", l.Frozen = "session is frozen", l.UserModeError = "failed at setting socket user mode", l.Inactive = "session is inactive", l))(D || {});
|
|
41
|
+
class se {
|
|
41
42
|
/**
|
|
42
43
|
* Session 类的构造函数,用于初始化会话实例。
|
|
43
44
|
* @param token - 用户的身份验证令牌,用于解析应用 ID。
|
|
@@ -100,7 +101,7 @@ class te {
|
|
|
100
101
|
applicationId: this._applicationId
|
|
101
102
|
}).then((h) => c(this, null, function* () {
|
|
102
103
|
var m;
|
|
103
|
-
this._id = h.id, this.data =
|
|
104
|
+
this._id = h.id, this.data = y(f({}, h), {
|
|
104
105
|
knowledges: s == null ? void 0 : s.knowledges
|
|
105
106
|
}), this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id);
|
|
106
107
|
try {
|
|
@@ -108,19 +109,19 @@ class te {
|
|
|
108
109
|
if (s != null && s.knowledges)
|
|
109
110
|
return this.setKnowledges((s == null ? void 0 : s.knowledges) || void 0);
|
|
110
111
|
}))();
|
|
111
|
-
} catch (
|
|
112
|
-
u.error(
|
|
112
|
+
} catch (I) {
|
|
113
|
+
u.error(I);
|
|
113
114
|
}
|
|
114
115
|
yield (() => {
|
|
115
116
|
if (s != null && s.promptVariables) {
|
|
116
|
-
const
|
|
117
|
+
const I = this._promptVariables.map((v) => {
|
|
117
118
|
var _, o;
|
|
118
119
|
const w = ((o = (_ = s.promptVariables) == null ? void 0 : _.find((g) => g.key === v.key && g.type === v.type)) == null ? void 0 : o.value) || "";
|
|
119
|
-
return
|
|
120
|
+
return y(f({}, v), {
|
|
120
121
|
value: w
|
|
121
122
|
});
|
|
122
123
|
}).sort((v, w) => v.key.localeCompare(w.key));
|
|
123
|
-
return this.setPromptVariables(
|
|
124
|
+
return this.setPromptVariables(I || []);
|
|
124
125
|
} else
|
|
125
126
|
return;
|
|
126
127
|
})(), this.event.emit("data:created", this.data), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), ((m = this.application) == null ? void 0 : m.type) !== Q.Agent && (this._ready = !0, this.event.emit("ready"));
|
|
@@ -204,12 +205,12 @@ class te {
|
|
|
204
205
|
}
|
|
205
206
|
setPromptVariables(e) {
|
|
206
207
|
return c(this, null, function* () {
|
|
207
|
-
const t = e == null ? void 0 : e.map((n) => n.type ? n :
|
|
208
|
+
const t = e == null ? void 0 : e.map((n) => n.type ? n : y(f({}, n), {
|
|
208
209
|
type: "instruction"
|
|
209
210
|
})), s = this._promptVariables.map((n) => {
|
|
210
211
|
var r;
|
|
211
212
|
const d = ((r = t == null ? void 0 : t.find((i) => i.key === n.key && i.type === n.type)) == null ? void 0 : r.value) || n.value;
|
|
212
|
-
return
|
|
213
|
+
return y(f({}, n), {
|
|
213
214
|
value: d
|
|
214
215
|
});
|
|
215
216
|
}).sort((n, d) => n.key.localeCompare(d.key));
|
|
@@ -298,10 +299,10 @@ class te {
|
|
|
298
299
|
e = f(f({}, t), e), this.event.emit("history:loading"), u.log("history:loading"), (e.endTime || e.startTime) && (this.event.emit("history:moreloading", e), u.log("history:moreloading", e)), this._loadingMessages = !0;
|
|
299
300
|
const n = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), d = n.map((i, h) => {
|
|
300
301
|
var v, w;
|
|
301
|
-
let m = [],
|
|
302
|
-
return typeof ((v = i.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(i.agentHistoryList.agentList).reduce((o, g) => (o[g.data.step - 1] || (o[g.data.step - 1] = []), o[g.data.step - 1].push(g), o), [])), h === n.length - 1 && (
|
|
302
|
+
let m = [], I;
|
|
303
|
+
return typeof ((v = i.agentHistoryList) == null ? void 0 : v.agentList) == "string" && (m = JSON.parse(i.agentHistoryList.agentList).reduce((o, g) => (o[g.data.step - 1] || (o[g.data.step - 1] = []), o[g.data.step - 1].push(g), o), [])), h === n.length - 1 && (I = (w = this.data) == null ? void 0 : w.lastRelatedQuestion), y(f({}, i), {
|
|
303
304
|
actions: m,
|
|
304
|
-
relatedQuesion:
|
|
305
|
+
relatedQuesion: I,
|
|
305
306
|
fromHistory: !0
|
|
306
307
|
});
|
|
307
308
|
});
|
|
@@ -417,6 +418,17 @@ class te {
|
|
|
417
418
|
get messagesLoading() {
|
|
418
419
|
return this._loadingMessages;
|
|
419
420
|
}
|
|
421
|
+
/**
|
|
422
|
+
* 把文件上传到当前会话的对象存储,返回可访问的地址。
|
|
423
|
+
* 图片地址放进 send 的 imageContent。
|
|
424
|
+
*/
|
|
425
|
+
upload(e) {
|
|
426
|
+
return c(this, null, function* () {
|
|
427
|
+
if (!this._id)
|
|
428
|
+
throw Error("session is not avalible. id is undefined");
|
|
429
|
+
return Y(this.cvforceApi, this._id, e);
|
|
430
|
+
});
|
|
431
|
+
}
|
|
420
432
|
send(s) {
|
|
421
433
|
return c(this, arguments, function* (e, t = {
|
|
422
434
|
stream: S.stream
|
|
@@ -462,7 +474,7 @@ class te {
|
|
|
462
474
|
return u.error(o), this.event.emit("error", o), !1;
|
|
463
475
|
}
|
|
464
476
|
this.frozen = !0, this._stopAnswer = !1;
|
|
465
|
-
const
|
|
477
|
+
const I = {
|
|
466
478
|
sessionId: this.id,
|
|
467
479
|
role: 2,
|
|
468
480
|
content: r,
|
|
@@ -480,7 +492,7 @@ class te {
|
|
|
480
492
|
referenceFirst: n,
|
|
481
493
|
imageContent: m
|
|
482
494
|
};
|
|
483
|
-
this.pushMessage(
|
|
495
|
+
this.pushMessage(I), this.event.emit("question:content", r);
|
|
484
496
|
const w = (o) => c(this, null, function* () {
|
|
485
497
|
if (o.role !== A.Robot)
|
|
486
498
|
return;
|
|
@@ -510,10 +522,10 @@ class te {
|
|
|
510
522
|
this.pushMessage(o);
|
|
511
523
|
this.frozen = !1;
|
|
512
524
|
});
|
|
513
|
-
return this.addEventListener("answer:finish", w), this.sendQuestion(v,
|
|
525
|
+
return this.addEventListener("answer:finish", w), this.sendQuestion(v, y(f({}, t), {
|
|
514
526
|
stream: a,
|
|
515
527
|
referenceFirst: n
|
|
516
|
-
})),
|
|
528
|
+
})), I;
|
|
517
529
|
});
|
|
518
530
|
}
|
|
519
531
|
currentUserQuestion() {
|
|
@@ -537,7 +549,7 @@ class te {
|
|
|
537
549
|
content: s
|
|
538
550
|
}).catch((h) => null);
|
|
539
551
|
if (!a) {
|
|
540
|
-
const h = [], m =
|
|
552
|
+
const h = [], m = y(f({}, e), {
|
|
541
553
|
relatedQuesion: h,
|
|
542
554
|
index: -3,
|
|
543
555
|
isLoading: !1
|
|
@@ -548,7 +560,7 @@ class te {
|
|
|
548
560
|
}
|
|
549
561
|
const n = (i = a.content) == null ? void 0 : i.split("*").map(F).map(N).filter((h) => !!h);
|
|
550
562
|
e.relatedQuesion = n, e.index = -3, e.isLoading = !1;
|
|
551
|
-
const d =
|
|
563
|
+
const d = y(f({}, e), {
|
|
552
564
|
relatedQuesion: n,
|
|
553
565
|
index: -3,
|
|
554
566
|
isLoading: !1
|
|
@@ -610,7 +622,7 @@ class te {
|
|
|
610
622
|
this.getRelatedQuesion(i), this.removeEventListener("message:content", r), this.frozen = !1;
|
|
611
623
|
}
|
|
612
624
|
});
|
|
613
|
-
this.addEventListener("message:content", r), this.sendQuestion(d,
|
|
625
|
+
this.addEventListener("message:content", r), this.sendQuestion(d, y(f({}, e), {
|
|
614
626
|
stream: s
|
|
615
627
|
}));
|
|
616
628
|
});
|
|
@@ -783,6 +795,6 @@ class te {
|
|
|
783
795
|
}
|
|
784
796
|
export {
|
|
785
797
|
V as MAX_KNOWLEDGES_AND_FILES_COUNT,
|
|
786
|
-
|
|
787
|
-
|
|
798
|
+
D as SessionErrors,
|
|
799
|
+
se as default
|
|
788
800
|
};
|
package/dist/es/index.mjs
CHANGED
|
@@ -2,67 +2,71 @@ import { configuration as e, configure as r, getRegisteredLocalFilesPluginCode a
|
|
|
2
2
|
import { default as I } from "./BotClient.mjs";
|
|
3
3
|
import { default as A } from "./Session.mjs";
|
|
4
4
|
import { default as O } from "./AgentPlugin.mjs";
|
|
5
|
-
import { ToolCode as
|
|
6
|
-
import { LOCAL_FILE_TOOL_SCHEMAS as
|
|
7
|
-
import { BUILTIN_TOOL_SCHEMAS as
|
|
5
|
+
import { ToolCode as C, ToolError as N, toToolError as D } from "./localFiles/errors.mjs";
|
|
6
|
+
import { LOCAL_FILE_TOOL_SCHEMAS as R } from "./localFiles/schemas.mjs";
|
|
7
|
+
import { BUILTIN_TOOL_SCHEMAS as f } from "./builtinTools/schemas.mjs";
|
|
8
8
|
import { createLocalFilesPlugin as s } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
9
9
|
import { LocalWorkspace as m } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { WorkspaceFiles as U, normalizeFilePath as M } from "./localFiles/workspace/WorkspaceFiles.mjs";
|
|
11
|
+
import { createIndexedDbStore as B, createMemoryStore as H } from "./localFiles/workspace/handleStore.mjs";
|
|
11
12
|
import { FileSystemAccessAdapter as d } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
|
|
12
|
-
import { MemoryWorkspaceAdapter as
|
|
13
|
-
import { HOST_BRIDGE_GLOBAL as
|
|
14
|
-
import { createDefaultSessionFileTransfer as
|
|
15
|
-
import { getDownloadUrlAllowlist as
|
|
16
|
-
import { SDK_SENSITIVE_BASELINE as
|
|
17
|
-
import { BINARY_SNIFF_BYTES as
|
|
13
|
+
import { MemoryWorkspaceAdapter as g } from "./localFiles/adapters/MemoryWorkspaceAdapter.mjs";
|
|
14
|
+
import { HOST_BRIDGE_GLOBAL as u, HOST_CHANNEL as G, SANDBOX_MAX_FILE_BYTES as W, registerHostBridge as Y } from "./localFiles/host/protocol.mjs";
|
|
15
|
+
import { createDefaultSessionFileTransfer as k } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
16
|
+
import { getDownloadUrlAllowlist as K, isDownloadUrlAllowed as b } from "./localFiles/security/downloadUrlPolicy.mjs";
|
|
17
|
+
import { SDK_SENSITIVE_BASELINE as v } from "./localFiles/security/sensitiveFiles.mjs";
|
|
18
|
+
import { BINARY_SNIFF_BYTES as V, BUILTIN_TOOLS_PLUGIN_CODE as Z, BUILTIN_TOOLS_PLUGIN_CODES as j, DEFAULT_DOWNLOAD_URL_ALLOWLIST as q, DEFAULT_IGNORED_DIRECTORIES as J, DEFAULT_IGNORED_FILE_PATTERNS as Q, DEFAULT_LIMITS as $, KiB as oo, LIST_DIRECTORY_DEFAULT_LIMIT as _o, LIST_DIRECTORY_MAX_LIMIT as eo, LOCAL_FILES_FUNCTION_CODES as ro, LOCAL_FILES_PLUGIN_CODES as Eo, MiB as To, SEARCH_DEFAULT_DEPTH as Lo, SEARCH_FUNCTION_CODES as Io, SEARCH_MAX_DEPTH as So, TEXT_SEARCH_MAX_CONTEXT_LINES as Ao, TEXT_SEARCH_MAX_FILES as to, TEXT_SEARCH_MAX_FILE_BYTES as Oo, TEXT_SEARCH_MAX_LINE_CHARS as lo, TRANSFER_FILE_SIZE_LIMIT_MB as Co, TRANSFER_FUNCTION_CODES as No, WORKSPACE_GRANT_ID as Do, WRITE_FUNCTION_CODES as Fo } from "./localFiles/constants.mjs";
|
|
18
19
|
export {
|
|
19
20
|
O as AgentPlugin,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
V as BINARY_SNIFF_BYTES,
|
|
22
|
+
Z as BUILTIN_TOOLS_PLUGIN_CODE,
|
|
23
|
+
j as BUILTIN_TOOLS_PLUGIN_CODES,
|
|
24
|
+
f as BUILTIN_TOOL_SCHEMAS,
|
|
24
25
|
I as BotClient,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
q as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
27
|
+
J as DEFAULT_IGNORED_DIRECTORIES,
|
|
28
|
+
Q as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
29
|
+
$ as DEFAULT_LIMITS,
|
|
29
30
|
d as FileSystemAccessAdapter,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
u as HOST_BRIDGE_GLOBAL,
|
|
32
|
+
G as HOST_CHANNEL,
|
|
33
|
+
oo as KiB,
|
|
34
|
+
_o as LIST_DIRECTORY_DEFAULT_LIMIT,
|
|
35
|
+
eo as LIST_DIRECTORY_MAX_LIMIT,
|
|
36
|
+
ro as LOCAL_FILES_FUNCTION_CODES,
|
|
37
|
+
Eo as LOCAL_FILES_PLUGIN_CODES,
|
|
38
|
+
R as LOCAL_FILE_TOOL_SCHEMAS,
|
|
38
39
|
m as LocalWorkspace,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
g as MemoryWorkspaceAdapter,
|
|
41
|
+
To as MiB,
|
|
42
|
+
W as SANDBOX_MAX_FILE_BYTES,
|
|
43
|
+
v as SDK_SENSITIVE_BASELINE,
|
|
44
|
+
Lo as SEARCH_DEFAULT_DEPTH,
|
|
45
|
+
Io as SEARCH_FUNCTION_CODES,
|
|
46
|
+
So as SEARCH_MAX_DEPTH,
|
|
45
47
|
A as Session,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
Ao as TEXT_SEARCH_MAX_CONTEXT_LINES,
|
|
49
|
+
to as TEXT_SEARCH_MAX_FILES,
|
|
50
|
+
Oo as TEXT_SEARCH_MAX_FILE_BYTES,
|
|
51
|
+
lo as TEXT_SEARCH_MAX_LINE_CHARS,
|
|
52
|
+
Co as TRANSFER_FILE_SIZE_LIMIT_MB,
|
|
53
|
+
No as TRANSFER_FUNCTION_CODES,
|
|
54
|
+
C as ToolCode,
|
|
53
55
|
N as ToolError,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
Do as WORKSPACE_GRANT_ID,
|
|
57
|
+
Fo as WRITE_FUNCTION_CODES,
|
|
58
|
+
U as WorkspaceFiles,
|
|
56
59
|
e as configuration,
|
|
57
60
|
r as configure,
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
k as createDefaultSessionFileTransfer,
|
|
62
|
+
B as createIndexedDbStore,
|
|
60
63
|
s as createLocalFilesPlugin,
|
|
61
64
|
H as createMemoryStore,
|
|
62
|
-
|
|
65
|
+
K as getDownloadUrlAllowlist,
|
|
63
66
|
E as getRegisteredLocalFilesPluginCode,
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
b as isDownloadUrlAllowed,
|
|
68
|
+
M as normalizeFilePath,
|
|
69
|
+
Y as registerHostBridge,
|
|
66
70
|
T as resolveLocalFilesPluginCode,
|
|
67
71
|
D as toToolError
|
|
68
72
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const i = "glodon-workspace", o = "__glodonHostBridge", c = 1;
|
|
2
|
-
function
|
|
1
|
+
const i = "glodon-workspace", o = "__glodonHostBridge", c = 1, f = 524288e3;
|
|
2
|
+
function d(t) {
|
|
3
3
|
let e = t;
|
|
4
4
|
if (typeof e == "string")
|
|
5
5
|
try {
|
|
@@ -20,11 +20,11 @@ function r(t) {
|
|
|
20
20
|
if (!(typeof e.postMessage != "function" || typeof e.addEventListener != "function" || typeof e.removeEventListener != "function"))
|
|
21
21
|
return e;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function g(t) {
|
|
24
24
|
const e = globalThis;
|
|
25
25
|
t ? e[o] = t : delete e[o];
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function u() {
|
|
28
28
|
var e;
|
|
29
29
|
const t = r(globalThis[o]);
|
|
30
30
|
return t || r((e = globalThis.chrome) == null ? void 0 : e.webview);
|
|
@@ -32,8 +32,9 @@ function g() {
|
|
|
32
32
|
export {
|
|
33
33
|
o as HOST_BRIDGE_GLOBAL,
|
|
34
34
|
i as HOST_CHANNEL,
|
|
35
|
+
f as SANDBOX_MAX_FILE_BYTES,
|
|
35
36
|
c as SANDBOX_PROTOCOL,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
u as getHostBridge,
|
|
38
|
+
d as parseHostMessage,
|
|
39
|
+
g as registerHostBridge
|
|
39
40
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var M = Object.defineProperty, O = Object.defineProperties;
|
|
2
|
-
var
|
|
2
|
+
var _ = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var v = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
4
|
+
var C = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
|
|
5
5
|
var A = (a, t, e) => t in a ? M(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e, y = (a, t) => {
|
|
6
6
|
for (var e in t || (t = {}))
|
|
7
|
-
|
|
7
|
+
C.call(t, e) && A(a, e, t[e]);
|
|
8
8
|
if (v)
|
|
9
9
|
for (var e of v(t))
|
|
10
10
|
T.call(t, e) && A(a, e, t[e]);
|
|
11
11
|
return a;
|
|
12
|
-
}, x = (a, t) => O(a,
|
|
12
|
+
}, x = (a, t) => O(a, _(t));
|
|
13
13
|
var m = (a, t, e) => (A(a, typeof t != "symbol" ? t + "" : t, e), e);
|
|
14
14
|
var p = (a, t, e) => new Promise((r, s) => {
|
|
15
15
|
var o = (i) => {
|
|
@@ -29,16 +29,16 @@ var p = (a, t, e) => new Promise((r, s) => {
|
|
|
29
29
|
});
|
|
30
30
|
import { MAX_COMMAND_OUTPUT_CHARS as w } from "../../builtinTools/command.mjs";
|
|
31
31
|
import { domError as f } from "../adapters/WorkspaceFileAdapter.mjs";
|
|
32
|
-
import { SANDBOX_PROTOCOL as S } from "./protocol.mjs";
|
|
33
|
-
import { decodeBinaryFrame as
|
|
32
|
+
import { SANDBOX_PROTOCOL as S, SANDBOX_MAX_FILE_BYTES as j } from "./protocol.mjs";
|
|
33
|
+
import { decodeBinaryFrame as E, MAX_BINARY_PAYLOAD as N, encodeBinaryFrame as P } from "./sandboxFrames.mjs";
|
|
34
34
|
const k = "沙箱已退出。";
|
|
35
|
-
function
|
|
35
|
+
function b(a) {
|
|
36
36
|
if (a instanceof Uint8Array)
|
|
37
37
|
return a;
|
|
38
38
|
if (a instanceof ArrayBuffer)
|
|
39
39
|
return new Uint8Array(a);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function B(a, t, e, r) {
|
|
42
42
|
const s = a.length > w ? a.slice(a.length - w) : a;
|
|
43
43
|
if (!t && !e && !r && a.length <= w)
|
|
44
44
|
return s;
|
|
@@ -46,7 +46,7 @@ function C(a, t, e, r) {
|
|
|
46
46
|
…输出已截断`;
|
|
47
47
|
return e && (o += `,完整输出见 ${e}`), r && (o += ",日志已截断"), s + o;
|
|
48
48
|
}
|
|
49
|
-
class
|
|
49
|
+
class R {
|
|
50
50
|
constructor(t = (e) => new WebSocket(e)) {
|
|
51
51
|
m(this, "notice");
|
|
52
52
|
m(this, "socket");
|
|
@@ -90,7 +90,7 @@ class L {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
read(o) {
|
|
93
|
-
return p(this, arguments, function* (t, e = 0, r =
|
|
93
|
+
return p(this, arguments, function* (t, e = 0, r = j, s) {
|
|
94
94
|
const n = this.begin({
|
|
95
95
|
op: "read",
|
|
96
96
|
path: t,
|
|
@@ -99,9 +99,9 @@ class L {
|
|
|
99
99
|
}, s), l = [];
|
|
100
100
|
let i;
|
|
101
101
|
for (; !i; ) {
|
|
102
|
-
const d = yield this.next(n), g =
|
|
102
|
+
const d = yield this.next(n), g = b(d);
|
|
103
103
|
if (g) {
|
|
104
|
-
l.push(
|
|
104
|
+
l.push(E(g).payload);
|
|
105
105
|
continue;
|
|
106
106
|
}
|
|
107
107
|
i = d;
|
|
@@ -160,9 +160,9 @@ class L {
|
|
|
160
160
|
}, o), l = [];
|
|
161
161
|
let i;
|
|
162
162
|
for (; !i; ) {
|
|
163
|
-
const d = yield this.next(n), g =
|
|
163
|
+
const d = yield this.next(n), g = b(d);
|
|
164
164
|
if (g) {
|
|
165
|
-
l.push(
|
|
165
|
+
l.push(E(g).payload);
|
|
166
166
|
continue;
|
|
167
167
|
}
|
|
168
168
|
i = d;
|
|
@@ -260,8 +260,8 @@ class L {
|
|
|
260
260
|
return {
|
|
261
261
|
exitCode: typeof c.exitCode == "number" ? c.exitCode : 1,
|
|
262
262
|
timedOut: c.timedOut === !0,
|
|
263
|
-
stdout:
|
|
264
|
-
stderr:
|
|
263
|
+
stdout: B(o, l, u, d),
|
|
264
|
+
stderr: B(n, i, u, d),
|
|
265
265
|
cwd: typeof c.cwd == "string" ? c.cwd : void 0
|
|
266
266
|
};
|
|
267
267
|
}
|
|
@@ -342,9 +342,9 @@ class L {
|
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
344
|
onFrame(t) {
|
|
345
|
-
const e =
|
|
345
|
+
const e = b(t);
|
|
346
346
|
if (e) {
|
|
347
|
-
const s =
|
|
347
|
+
const s = E(e);
|
|
348
348
|
this.push(s.id, e);
|
|
349
349
|
return;
|
|
350
350
|
}
|
|
@@ -391,5 +391,5 @@ class L {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
export {
|
|
394
|
-
|
|
394
|
+
R as SandboxClient
|
|
395
395
|
};
|