@glodon-aiot/bot-client-sdk 3.26.0-alpha.8 → 3.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +284 -254
- package/dist/es/AgentSession.mjs +267 -197
- package/dist/es/BotClient.mjs +200 -123
- package/dist/es/Config.mjs +55 -88
- package/dist/es/DialogSession.mjs +123 -118
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +338 -284
- package/dist/es/api/index.mjs +31 -30
- 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 +17 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +266 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +70 -0
- package/dist/es/builtinTools/platformSkills.mjs +248 -0
- package/dist/es/builtinTools/schemas.mjs +261 -0
- package/dist/es/builtinTools/tools.mjs +595 -0
- package/dist/es/index.mjs +66 -64
- package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
- package/dist/es/localFiles/constants.mjs +24 -28
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/errors.mjs +44 -35
- package/dist/es/localFiles/host/connectHostBridge.mjs +43 -35
- package/dist/es/localFiles/host/protocol.mjs +27 -13
- package/dist/es/localFiles/host/sandboxClient.mjs +494 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/preview.mjs +33 -0
- package/dist/es/localFiles/schemas.mjs +40 -86
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +176 -90
- package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
- package/dist/es/localMcp/client.mjs +234 -0
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +207 -0
- package/dist/es/localMcp/registry.mjs +43 -0
- package/dist/es/package.json.mjs +49 -60
- package/dist/es/sessionUpload.mjs +49 -0
- package/dist/es/utils.mjs +24 -11
- package/dist/lib/index.js +382 -10
- package/dist/src/AgentSession.d.ts +13 -0
- package/dist/src/BotClient.d.ts +13 -1
- package/dist/src/Config.d.ts +7 -8
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/PayloadTypes.d.ts +2 -0
- package/dist/src/Session.d.ts +19 -2
- package/dist/src/api/index.d.ts +2 -2
- 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 +35 -0
- package/dist/src/builtinTools/constants.d.ts +25 -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 +16 -0
- package/dist/src/builtinTools/platformSkills.d.ts +92 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +73 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
- package/dist/src/localFiles/constants.d.ts +5 -13
- package/dist/src/localFiles/errors.d.ts +1 -1
- package/dist/src/localFiles/host/protocol.d.ts +34 -16
- package/dist/src/localFiles/host/sandboxClient.d.ts +112 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +11 -6
- package/dist/src/localFiles/preview.d.ts +2 -0
- package/dist/src/localFiles/schemas.d.ts +2 -5
- package/dist/src/localFiles/types.d.ts +16 -23
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
- package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
- package/dist/src/localMcp/client.d.ts +15 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +34 -0
- package/dist/src/localMcp/registry.d.ts +27 -0
- package/dist/src/sessionUpload.d.ts +14 -0
- package/dist/src/utils.d.ts +6 -0
- package/package.json +13 -24
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
|
@@ -1,50 +1,54 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a = (n, e) => {
|
|
2
2
|
if (e = Symbol[n])
|
|
3
3
|
return e;
|
|
4
4
|
throw Error("Symbol." + n + " is not defined");
|
|
5
5
|
};
|
|
6
|
-
var
|
|
6
|
+
var x = function(n, e) {
|
|
7
7
|
this[0] = n, this[1] = e;
|
|
8
|
-
},
|
|
9
|
-
var d = (t, f,
|
|
8
|
+
}, E = (n, e, y) => {
|
|
9
|
+
var d = (t, f, o, l) => {
|
|
10
10
|
try {
|
|
11
|
-
var
|
|
12
|
-
Promise.resolve(
|
|
13
|
-
} catch (
|
|
14
|
-
|
|
11
|
+
var c = y[t](f), p = (f = c.value) instanceof x, u = c.done;
|
|
12
|
+
Promise.resolve(p ? f[0] : f).then((s) => p ? d(t === "return" ? t : "next", f[1] ? { done: s.done, value: s.value } : s, o, l) : o({ value: s, done: u })).catch((s) => d("throw", s, o, l));
|
|
13
|
+
} catch (s) {
|
|
14
|
+
l(s);
|
|
15
15
|
}
|
|
16
|
-
},
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
var e = n[
|
|
20
|
-
return e == null ? (e = n[
|
|
21
|
-
if (
|
|
22
|
-
if (
|
|
16
|
+
}, r = (t) => i[t] = (f) => new Promise((o, l) => d(t, f, o, l)), i = {};
|
|
17
|
+
return y = y.apply(n, e), i[Symbol.asyncIterator] = () => i, r("next"), r("throw"), r("return"), i;
|
|
18
|
+
}, h = (n) => {
|
|
19
|
+
var e = n[a("asyncIterator")], y = !1, d, r = {};
|
|
20
|
+
return e == null ? (e = n[a("iterator")](), d = (i) => r[i] = (t) => e[i](t)) : (e = e.call(n), d = (i) => r[i] = (t) => {
|
|
21
|
+
if (y) {
|
|
22
|
+
if (y = !1, i === "throw")
|
|
23
23
|
throw t;
|
|
24
24
|
return t;
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return y = !0, {
|
|
27
27
|
done: !1,
|
|
28
|
-
value: new
|
|
29
|
-
var
|
|
30
|
-
if (!(
|
|
28
|
+
value: new x(new Promise((f) => {
|
|
29
|
+
var o = e[i](t);
|
|
30
|
+
if (!(o instanceof Object))
|
|
31
31
|
throw TypeError("Object expected");
|
|
32
|
-
f(
|
|
32
|
+
f(o);
|
|
33
33
|
}), 1)
|
|
34
34
|
};
|
|
35
|
-
}),
|
|
35
|
+
}), r[a("iterator")] = () => r, d("next"), "throw" in e ? d("throw") : r.throw = (i) => {
|
|
36
36
|
throw i;
|
|
37
|
-
}, "return" in e && d("return"),
|
|
37
|
+
}, "return" in e && d("return"), r;
|
|
38
38
|
};
|
|
39
|
-
function
|
|
39
|
+
function O(n, e) {
|
|
40
|
+
return e === n || e.startsWith(`${n}/`);
|
|
41
|
+
}
|
|
42
|
+
function g(n, e = n) {
|
|
40
43
|
return new DOMException(e, n);
|
|
41
44
|
}
|
|
42
|
-
function
|
|
43
|
-
return
|
|
44
|
-
typeof n == "string" ? yield new TextEncoder().encode(n) : n instanceof Uint8Array ? yield n : yield*
|
|
45
|
+
function k(n) {
|
|
46
|
+
return E(this, null, function* () {
|
|
47
|
+
typeof n == "string" ? yield new TextEncoder().encode(n) : n instanceof Uint8Array ? yield n : yield* h(n);
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
export {
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
g as domError,
|
|
52
|
+
O as isSameOrInside,
|
|
53
|
+
k as toChunks
|
|
50
54
|
};
|
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T = ["list_directory", "read_file", "stat_file", "search_files", "search_text", "apply_patch", "write_file", "upload_file", "download_file"], _ = "builtin_tools", t = {
|
|
2
2
|
dev: _,
|
|
3
3
|
test: _,
|
|
4
4
|
prod: _,
|
|
5
5
|
local: _
|
|
6
|
-
}, E = t, c = "
|
|
6
|
+
}, E = t, c = "current-workspace", o = 1024, e = 1024 * 1024, s = 50, I = Object.freeze({
|
|
7
7
|
maxReadBytes: 1 * e,
|
|
8
8
|
maxWriteBytes: 5 * e,
|
|
9
9
|
maxSearchResults: 200,
|
|
10
10
|
maxConcurrentRequests: 4,
|
|
11
|
-
maxTransferBytes:
|
|
11
|
+
maxTransferBytes: s * e,
|
|
12
12
|
toolTimeoutMs: 3e4,
|
|
13
|
+
commandTimeoutMs: 10 * 6e4,
|
|
13
14
|
searchTimeoutMs: 6e4,
|
|
14
15
|
transferTimeoutMs: 10 * 6e4,
|
|
15
16
|
approvalTimeoutMs: 5 * 6e4
|
|
16
|
-
}),
|
|
17
|
+
}), n = 200, L = 1e3, S = 8, a = 16, l = 2e3, O = 1 * e, A = 500, R = 3, i = 8 * o, r = Object.freeze(["glodon.com"]), C = Object.freeze([".git", "node_modules", ".svn", ".idea", ".vscode"]), N = Object.freeze(["~$*", ".~lock*", "*.tmp"]), D = ["apply_patch", "write_file", "upload_file", "download_file"], d = ["search_files", "search_text"], F = ["upload_file", "download_file"];
|
|
17
18
|
export {
|
|
18
|
-
|
|
19
|
+
i as BINARY_SNIFF_BYTES,
|
|
19
20
|
_ as BUILTIN_TOOLS_PLUGIN_CODE,
|
|
20
21
|
t as BUILTIN_TOOLS_PLUGIN_CODES,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
r as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
23
|
+
C as DEFAULT_IGNORED_DIRECTORIES,
|
|
24
|
+
N as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
25
|
+
I as DEFAULT_LIMITS,
|
|
25
26
|
o as KiB,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
n as LIST_DIRECTORY_DEFAULT_LIMIT,
|
|
28
|
+
L as LIST_DIRECTORY_MAX_LIMIT,
|
|
29
|
+
T as LOCAL_FILES_FUNCTION_CODES,
|
|
29
30
|
E as LOCAL_FILES_PLUGIN_CODES,
|
|
30
|
-
c as LOCAL_PYTHON_FUNCTION_CODE,
|
|
31
|
-
I as LOCAL_PYTHON_PLUGIN_CODES,
|
|
32
31
|
e as MiB,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
H as TRANSFER_FUNCTION_CODES,
|
|
45
|
-
S as WORKSPACE_GRANT_ID,
|
|
46
|
-
f as WRITE_FUNCTION_CODES
|
|
32
|
+
S as SEARCH_DEFAULT_DEPTH,
|
|
33
|
+
d as SEARCH_FUNCTION_CODES,
|
|
34
|
+
a as SEARCH_MAX_DEPTH,
|
|
35
|
+
R as TEXT_SEARCH_MAX_CONTEXT_LINES,
|
|
36
|
+
l as TEXT_SEARCH_MAX_FILES,
|
|
37
|
+
O as TEXT_SEARCH_MAX_FILE_BYTES,
|
|
38
|
+
A as TEXT_SEARCH_MAX_LINE_CHARS,
|
|
39
|
+
s as TRANSFER_FILE_SIZE_LIMIT_MB,
|
|
40
|
+
F as TRANSFER_FUNCTION_CODES,
|
|
41
|
+
c as WORKSPACE_GRANT_ID,
|
|
42
|
+
D as WRITE_FUNCTION_CODES
|
|
47
43
|
};
|
|
@@ -9,7 +9,7 @@ var E = (e, t, r) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writab
|
|
|
9
9
|
for (var r of G(t))
|
|
10
10
|
Q.call(t, r) && E(e, r, t[r]);
|
|
11
11
|
return e;
|
|
12
|
-
},
|
|
12
|
+
}, h = (e, t) => B(e, K(t));
|
|
13
13
|
var _ = (e, t, r) => (E(e, typeof t != "symbol" ? t + "" : t, r), r);
|
|
14
14
|
var F = (e, t, r) => new Promise((d, s) => {
|
|
15
15
|
var o = (a) => {
|
|
@@ -28,26 +28,27 @@ var F = (e, t, r) => new Promise((d, s) => {
|
|
|
28
28
|
i((r = r.apply(e, t)).next());
|
|
29
29
|
});
|
|
30
30
|
import { v4 as U } from "uuid";
|
|
31
|
-
import
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
import V from "../Logger.mjs";
|
|
32
|
+
import { LOCAL_FILES_FUNCTION_CODES as X, TRANSFER_FUNCTION_CODES as Y, SEARCH_FUNCTION_CODES as Z, WORKSPACE_GRANT_ID as $ } from "./constants.mjs";
|
|
33
|
+
import { cancelledError as g, workspaceNotGranted as k, ToolError as f, ToolCode as m, toToolError as ee } from "./errors.mjs";
|
|
34
|
+
import { LOCAL_FILE_TOOL_SCHEMAS as te } from "./schemas.mjs";
|
|
35
|
+
import { assertGrantId as re } from "./security/pathPolicy.mjs";
|
|
36
|
+
import { listDirectory as ie, readFile as ae, statFile as oe, searchFiles as ne, searchText as se } from "./tools/readTools.mjs";
|
|
37
|
+
import { uploadFile as le, downloadFile as de } from "./tools/transferTools.mjs";
|
|
38
|
+
import { applyPatch as ce, writeFile as ue } from "./tools/writeTools.mjs";
|
|
39
|
+
import { validateToolInput as me } from "./validate.mjs";
|
|
40
|
+
const fe = new V("[LocalFiles] "), he = {
|
|
41
|
+
list_directory: ie,
|
|
42
|
+
read_file: ae,
|
|
43
|
+
stat_file: oe,
|
|
44
|
+
search_files: ne,
|
|
45
|
+
search_text: se,
|
|
46
|
+
apply_patch: ce,
|
|
47
|
+
write_file: ue,
|
|
48
|
+
upload_file: le,
|
|
49
|
+
download_file: de
|
|
49
50
|
};
|
|
50
|
-
class
|
|
51
|
+
class ge {
|
|
51
52
|
constructor(t, r) {
|
|
52
53
|
_(this, "remaining");
|
|
53
54
|
_(this, "startedAt", 0);
|
|
@@ -66,23 +67,23 @@ class he {
|
|
|
66
67
|
this.pause(), this.remaining = 0;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
function
|
|
70
|
-
return
|
|
70
|
+
function pe(e, t) {
|
|
71
|
+
return Y.includes(t) ? e.limits.transferTimeoutMs : Z.includes(t) ? e.limits.searchTimeoutMs : e.limits.toolTimeoutMs;
|
|
71
72
|
}
|
|
72
|
-
function
|
|
73
|
+
function ve(e) {
|
|
73
74
|
if (typeof e != "string")
|
|
74
75
|
return e;
|
|
75
76
|
try {
|
|
76
77
|
return JSON.parse(e);
|
|
77
78
|
} catch (t) {
|
|
78
|
-
throw new
|
|
79
|
+
throw new f(m.BadRequest, "参数不是合法的 JSON 对象。");
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
|
-
function
|
|
82
|
+
function Ie(e) {
|
|
82
83
|
if (!e || typeof e != "object" || Array.isArray(e))
|
|
83
84
|
return;
|
|
84
85
|
const t = e;
|
|
85
|
-
return (t.grantId === void 0 || t.grantId === null || t.grantId === "") && (t.grantId =
|
|
86
|
+
return (t.grantId === void 0 || t.grantId === null || t.grantId === "") && (t.grantId = $), t.grantId;
|
|
86
87
|
}
|
|
87
88
|
function W(e) {
|
|
88
89
|
return new Promise((t, r) => {
|
|
@@ -91,7 +92,7 @@ function W(e) {
|
|
|
91
92
|
});
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
|
-
function
|
|
95
|
+
function be(e) {
|
|
95
96
|
return u({
|
|
96
97
|
code: e.code,
|
|
97
98
|
message: e.message
|
|
@@ -99,7 +100,7 @@ function ve(e) {
|
|
|
99
100
|
data: e.data
|
|
100
101
|
} : {});
|
|
101
102
|
}
|
|
102
|
-
function
|
|
103
|
+
function Te(e, t, r, d, s) {
|
|
103
104
|
return F(this, null, function* () {
|
|
104
105
|
var N, S, q, P, C, D, R, x;
|
|
105
106
|
const o = {
|
|
@@ -115,7 +116,7 @@ function Ie(e, t, r, d, s) {
|
|
|
115
116
|
functionCode: t
|
|
116
117
|
}, i = new AbortController();
|
|
117
118
|
let a = !1;
|
|
118
|
-
const c = new
|
|
119
|
+
const c = new ge(pe(e, t), () => {
|
|
119
120
|
a = !0, i.abort();
|
|
120
121
|
}), v = () => i.abort();
|
|
121
122
|
(N = o.signal) == null || N.addEventListener("abort", v, {
|
|
@@ -123,16 +124,16 @@ function Ie(e, t, r, d, s) {
|
|
|
123
124
|
}), (S = o.signal) != null && S.aborted && i.abort();
|
|
124
125
|
let p = null, I, L = !1;
|
|
125
126
|
try {
|
|
126
|
-
const b =
|
|
127
|
-
l != null &&
|
|
128
|
-
const w =
|
|
127
|
+
const b = ve(r), l = Ie(b);
|
|
128
|
+
l != null && re(l);
|
|
129
|
+
const w = me(b, te[t].parameters), M = (q = w.path) != null ? q : w.destPath;
|
|
129
130
|
if (typeof M == "string" && (n.path = M), yield e.ready, i.signal.aborted)
|
|
130
131
|
throw g();
|
|
131
132
|
const y = e.adapter;
|
|
132
133
|
if (!y)
|
|
133
|
-
throw
|
|
134
|
+
throw k();
|
|
134
135
|
if (p = e.acquireSlot(), !p)
|
|
135
|
-
throw new
|
|
136
|
+
throw new f(m.TooManyRequests, "同时进行的文件操作过多,请稍后重试。");
|
|
136
137
|
I = e.track(i), L = !0, e.emit("tool:start", u({}, n)), c.resume();
|
|
137
138
|
const H = {
|
|
138
139
|
adapter: y,
|
|
@@ -143,11 +144,11 @@ function Ie(e, t, r, d, s) {
|
|
|
143
144
|
allowWorkspaceWideTextSearch: e.allowWorkspaceWideTextSearch,
|
|
144
145
|
transfer: e.transfer,
|
|
145
146
|
fetch: e.fetch,
|
|
146
|
-
context:
|
|
147
|
+
context: h(u({}, o), {
|
|
147
148
|
signal: i.signal
|
|
148
149
|
}),
|
|
149
150
|
signal: i.signal,
|
|
150
|
-
requestApproval: (O, j) =>
|
|
151
|
+
requestApproval: (O, j) => _e(e, {
|
|
151
152
|
approvalPath: O,
|
|
152
153
|
preview: j,
|
|
153
154
|
context: o,
|
|
@@ -157,32 +158,32 @@ function Ie(e, t, r, d, s) {
|
|
|
157
158
|
base: n
|
|
158
159
|
}),
|
|
159
160
|
progress: (O) => e.emit("tool:progress", u(u({}, n), O))
|
|
160
|
-
}, T = yield Promise.race([
|
|
161
|
+
}, T = yield Promise.race([he[t](w, H), W(i.signal)]), A = {
|
|
161
162
|
code: m.Ok,
|
|
162
163
|
message: "ok",
|
|
163
164
|
data: T.data
|
|
164
165
|
};
|
|
165
|
-
T.truncated && (A.truncated = !0), (C = T.warnings) != null && C.length && (A.warnings = T.warnings), e.emit("tool:finish",
|
|
166
|
+
T.truncated && (A.truncated = !0), (C = T.warnings) != null && C.length && (A.warnings = T.warnings), e.emit("tool:finish", h(u({}, n), {
|
|
166
167
|
code: m.Ok
|
|
167
168
|
})), d(A);
|
|
168
169
|
} catch (b) {
|
|
169
|
-
let l =
|
|
170
|
-
a ? l = new
|
|
170
|
+
let l = ee(b);
|
|
171
|
+
a ? l = new f(m.Timeout, "操作超时,已中止。") : i.signal.aborted && l.code !== m.Cancelled && (l = g()), ((D = l.data) == null ? void 0 : D.reason) === "workspace_not_granted" && L && e.handlePermissionLost(), l.code === m.Cancelled ? e.emit("tool:cancelled", u({}, n)) : e.emit("tool:error", h(u({}, n), {
|
|
171
172
|
code: l.code,
|
|
172
173
|
message: l.message,
|
|
173
174
|
reason: (R = l.data) == null ? void 0 : R.reason
|
|
174
|
-
})), d(
|
|
175
|
+
})), d(be(l));
|
|
175
176
|
} finally {
|
|
176
177
|
c.clear(), (x = o.signal) == null || x.removeEventListener("abort", v), p == null || p(), I == null || I();
|
|
177
178
|
}
|
|
178
179
|
});
|
|
179
180
|
}
|
|
180
|
-
function
|
|
181
|
+
function _e(e, t) {
|
|
181
182
|
return F(this, null, function* () {
|
|
182
183
|
var i;
|
|
183
184
|
const r = e.getApprovalHandler();
|
|
184
185
|
if (!r)
|
|
185
|
-
throw new
|
|
186
|
+
throw new f(m.Forbidden, "当前环境未提供操作确认能力,无法执行写入或传输操作。", {
|
|
186
187
|
reason: "approval_unavailable"
|
|
187
188
|
});
|
|
188
189
|
if (t.signal.aborted)
|
|
@@ -201,7 +202,7 @@ function be(e, t) {
|
|
|
201
202
|
preview: t.preview,
|
|
202
203
|
signal: d.signal
|
|
203
204
|
};
|
|
204
|
-
t.timer.pause(), e.emit("tool:approval-required",
|
|
205
|
+
t.timer.pause(), e.emit("tool:approval-required", h(u({}, t.base), {
|
|
205
206
|
path: t.approvalPath,
|
|
206
207
|
approvalId: o.id
|
|
207
208
|
}));
|
|
@@ -213,11 +214,11 @@ function be(e, t) {
|
|
|
213
214
|
if (t.signal.aborted)
|
|
214
215
|
throw g();
|
|
215
216
|
if (a !== !0)
|
|
216
|
-
throw new
|
|
217
|
+
throw new f(m.Forbidden, "用户拒绝了本次操作。", {
|
|
217
218
|
reason: "user_rejected"
|
|
218
219
|
});
|
|
219
220
|
} catch (a) {
|
|
220
|
-
throw a instanceof
|
|
221
|
+
throw a instanceof f ? a : new f(m.Forbidden, "操作确认失败,已取消本次操作。", {
|
|
221
222
|
reason: "user_rejected"
|
|
222
223
|
});
|
|
223
224
|
} finally {
|
|
@@ -225,24 +226,24 @@ function be(e, t) {
|
|
|
225
226
|
}
|
|
226
227
|
});
|
|
227
228
|
}
|
|
228
|
-
function
|
|
229
|
+
function Ce({
|
|
229
230
|
pluginCode: e,
|
|
230
231
|
workspace: t
|
|
231
232
|
}) {
|
|
232
233
|
const r = {};
|
|
233
|
-
return
|
|
234
|
+
return X.forEach((d) => {
|
|
234
235
|
r[d] = (s, o, n) => {
|
|
235
236
|
let i = !1;
|
|
236
|
-
|
|
237
|
+
Te(t, d, s, (c) => {
|
|
237
238
|
if (!i) {
|
|
238
239
|
i = !0;
|
|
239
240
|
try {
|
|
240
241
|
o(c);
|
|
241
242
|
} catch (v) {
|
|
242
|
-
|
|
243
|
+
fe.report("callback failed", v);
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
|
-
},
|
|
246
|
+
}, h(u({}, n), {
|
|
246
247
|
pluginCode: e
|
|
247
248
|
}));
|
|
248
249
|
};
|
|
@@ -251,5 +252,5 @@ function Se({
|
|
|
251
252
|
};
|
|
252
253
|
}
|
|
253
254
|
export {
|
|
254
|
-
|
|
255
|
+
Ce as createLocalFilesPlugin
|
|
255
256
|
};
|
|
@@ -1,57 +1,66 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
class
|
|
6
|
-
constructor(
|
|
7
|
-
super(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
this.name = "ToolError", this.code =
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var f = (t, e, n) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var s = (t, e, n) => (f(t, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
|
+
var w = /* @__PURE__ */ ((t) => (t[t.Ok = 0] = "Ok", t[t.BadRequest = 400] = "BadRequest", t[t.Forbidden = 403] = "Forbidden", t[t.NotFound = 404] = "NotFound", t[t.Timeout = 408] = "Timeout", t[t.Conflict = 409] = "Conflict", t[t.TooLarge = 413] = "TooLarge", t[t.TooManyRequests = 429] = "TooManyRequests", t[t.Cancelled = 499] = "Cancelled", t[t.Internal = 500] = "Internal", t[t.NotImplemented = 501] = "NotImplemented", t))(w || {});
|
|
5
|
+
class r extends Error {
|
|
6
|
+
constructor(n, a, i) {
|
|
7
|
+
super(a);
|
|
8
|
+
s(this, "code");
|
|
9
|
+
s(this, "data");
|
|
10
|
+
this.name = "ToolError", this.code = n, this.data = i;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
function
|
|
15
|
-
return new
|
|
13
|
+
const m = "尚未授权工作文件夹,请先在助手中选择或恢复访问工作文件夹。";
|
|
14
|
+
function d() {
|
|
15
|
+
return new r(403, m, {
|
|
16
16
|
reason: "workspace_not_granted"
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
return new
|
|
19
|
+
function u() {
|
|
20
|
+
return new r(499, "操作已取消。");
|
|
21
21
|
}
|
|
22
|
-
function N(
|
|
23
|
-
if (
|
|
24
|
-
throw
|
|
22
|
+
function N(t) {
|
|
23
|
+
if (t != null && t.aborted)
|
|
24
|
+
throw u();
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
function c(t) {
|
|
27
|
+
const e = t && typeof t == "object" && "message" in t ? String(t.message) : "";
|
|
28
|
+
return /[\u4e00-\u9fff]/.test(e) ? e : void 0;
|
|
29
|
+
}
|
|
30
|
+
function p(t) {
|
|
31
|
+
var n, a;
|
|
32
|
+
if (t instanceof r)
|
|
33
|
+
return t;
|
|
34
|
+
switch (t && typeof t == "object" && "name" in t ? String(t.name) : "") {
|
|
30
35
|
case "NotFoundError":
|
|
31
|
-
return new
|
|
36
|
+
return new r(404, "文件或目录不存在。");
|
|
32
37
|
case "TypeMismatchError":
|
|
33
|
-
return new
|
|
38
|
+
return new r(400, "路径类型不匹配:目标是目录而不是文件,或路径中的某一段不是目录。");
|
|
34
39
|
case "NotAllowedError":
|
|
35
40
|
case "SecurityError":
|
|
36
|
-
return
|
|
41
|
+
return d();
|
|
37
42
|
case "AbortError":
|
|
38
|
-
return
|
|
43
|
+
return u();
|
|
39
44
|
case "NoModificationAllowedError":
|
|
40
45
|
case "InvalidModificationError":
|
|
41
46
|
case "InvalidStateError":
|
|
42
|
-
return new
|
|
47
|
+
return new r(403, "文件当前不可写,可能正被其他程序占用或为只读。");
|
|
43
48
|
case "QuotaExceededError":
|
|
44
|
-
return new
|
|
49
|
+
return new r(413, (n = c(t)) != null ? n : "磁盘空间不足或超出写入配额。");
|
|
50
|
+
case "TooManyRequestsError":
|
|
51
|
+
return new r(429, (a = c(t)) != null ? a : "排队的文件操作过多,请稍后重试。");
|
|
52
|
+
case "PreviewLimitError":
|
|
53
|
+
return new r(413, "同时预览的文件过多,请先关掉一些预览。");
|
|
45
54
|
default:
|
|
46
|
-
return new
|
|
55
|
+
return new r(500, "本地文件操作失败,请稍后重试。");
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
export {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
w as ToolCode,
|
|
60
|
+
r as ToolError,
|
|
61
|
+
m as WORKSPACE_NOT_GRANTED_MESSAGE,
|
|
62
|
+
u as cancelledError,
|
|
54
63
|
N as throwIfAborted,
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
p as toToolError,
|
|
65
|
+
d as workspaceNotGranted
|
|
57
66
|
};
|
|
@@ -1,50 +1,58 @@
|
|
|
1
|
+
import l from "../../Logger.mjs";
|
|
1
2
|
import { HostBridgeAdapter as f } from "../adapters/HostBridgeAdapter.mjs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { getHostBridge as y, HOST_CHANNEL as m, parseHostMessage as c } from "./protocol.mjs";
|
|
4
|
+
function u(o) {
|
|
5
|
+
if (!o || typeof o != "object")
|
|
6
|
+
return;
|
|
7
|
+
const e = o;
|
|
8
|
+
return {
|
|
9
|
+
state: e.state,
|
|
10
|
+
url: typeof e.url == "string" ? e.url : void 0,
|
|
11
|
+
token: typeof e.token == "string" ? e.token : void 0,
|
|
12
|
+
protocol: typeof e.protocol == "number" ? e.protocol : void 0,
|
|
13
|
+
exitCode: typeof e.exitCode == "number" ? e.exitCode : void 0,
|
|
14
|
+
detail: typeof e.detail == "string" ? e.detail : void 0,
|
|
15
|
+
message: typeof e.message == "string" ? e.message : void 0,
|
|
16
|
+
reason: typeof e.reason == "string" ? e.reason : void 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const d = new l("[HostBridge] ");
|
|
20
|
+
let s;
|
|
21
|
+
function h(o) {
|
|
22
|
+
s == null || s(), s = void 0;
|
|
23
|
+
const e = y();
|
|
24
|
+
if (!e)
|
|
25
|
+
return d.log("missing"), () => {
|
|
9
26
|
};
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
if (
|
|
14
|
-
const r =
|
|
15
|
-
|
|
27
|
+
const i = new f(e), p = (g) => {
|
|
28
|
+
const t = c(g.data);
|
|
29
|
+
if (t) {
|
|
30
|
+
if (t.type === "workspace") {
|
|
31
|
+
const r = t.granted === !0, n = typeof t.displayName == "string" ? t.displayName : "";
|
|
32
|
+
i.setCapabilities(t.capabilities, {
|
|
33
|
+
version: t.sandboxVersion
|
|
34
|
+
}), i.applySandbox(u(t.sandbox)), d.log("workspace", {
|
|
35
|
+
granted: r,
|
|
36
|
+
displayName: n
|
|
37
|
+
}), r ? (i.displayName = n || "工程目录", (o.status !== "granted" || o.displayName !== i.displayName) && o.attachAdapter(i, i.displayName)) : o.status === "granted" && o.clear();
|
|
16
38
|
return;
|
|
17
39
|
}
|
|
18
|
-
if (
|
|
19
|
-
const r = Array.isArray(
|
|
20
|
-
|
|
40
|
+
if (t.type === "fs-changed") {
|
|
41
|
+
const r = Array.isArray(t.paths) ? t.paths.filter((n) => typeof n == "string") : [];
|
|
42
|
+
o.notifyFilesChanged(r);
|
|
21
43
|
return;
|
|
22
44
|
}
|
|
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
|
-
});
|
|
37
45
|
}
|
|
38
46
|
};
|
|
39
|
-
|
|
40
|
-
channel:
|
|
47
|
+
e.addEventListener("message", p), d.log("hello"), e.postMessage({
|
|
48
|
+
channel: m,
|
|
41
49
|
type: "hello"
|
|
42
50
|
});
|
|
43
51
|
const a = () => {
|
|
44
|
-
|
|
52
|
+
e.removeEventListener("message", p), s === a && (s = void 0);
|
|
45
53
|
};
|
|
46
|
-
return
|
|
54
|
+
return s = a, a;
|
|
47
55
|
}
|
|
48
56
|
export {
|
|
49
|
-
|
|
57
|
+
h as connectHostBridge
|
|
50
58
|
};
|