@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.10
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 +555 -98
- package/dist/es/AgentSession.mjs +231 -167
- package/dist/es/BotClient.mjs +188 -136
- package/dist/es/Config.mjs +89 -26
- package/dist/es/DialogSession.mjs +39 -40
- package/dist/es/Session.mjs +83 -63
- 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 +244 -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 +157 -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 +53 -0
- package/dist/es/localFiles/host/protocol.mjs +27 -0
- package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -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 +374 -5
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +25 -1
- package/dist/src/Session.d.ts +9 -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 +28 -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 +37 -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 +40 -0
- package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -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
package/dist/es/index.mjs
CHANGED
|
@@ -1,11 +1,71 @@
|
|
|
1
|
-
import { configuration as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
1
|
+
import { configuration as e, configure as T, getRegisteredLocalFilesPluginCode as E, getRegisteredLocalPythonPluginCode as r, resolveLocalFilesPluginCode as L } from "./Config.mjs";
|
|
2
|
+
import { default as S } from "./BotClient.mjs";
|
|
3
|
+
import { default as O } from "./Session.mjs";
|
|
4
|
+
import { default as C } from "./AgentPlugin.mjs";
|
|
5
|
+
import { ToolCode as l, ToolError as D, toToolError as R } from "./localFiles/errors.mjs";
|
|
6
|
+
import { LOCAL_FILE_TOOL_SCHEMAS as a, LOCAL_PYTHON_TOOL_SCHEMA as U } from "./localFiles/schemas.mjs";
|
|
7
|
+
import { BUILTIN_TOOL_SCHEMAS as M } from "./builtinTools/schemas.mjs";
|
|
8
|
+
import { createLocalFilesPlugin as s } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
9
|
+
import { LocalWorkspace as P } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
10
|
+
import { createIndexedDbStore as H, createMemoryStore as n } from "./localFiles/workspace/handleStore.mjs";
|
|
11
|
+
import { FileSystemAccessAdapter as d } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
|
|
12
|
+
import { MemoryWorkspaceAdapter as g } from "./localFiles/adapters/MemoryWorkspaceAdapter.mjs";
|
|
13
|
+
import { createDefaultSessionFileTransfer as u } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
14
|
+
import { getDownloadUrlAllowlist as Y, isDownloadUrlAllowed as G } from "./localFiles/security/downloadUrlPolicy.mjs";
|
|
15
|
+
import { SDK_SENSITIVE_BASELINE as w } from "./localFiles/security/sensitiveFiles.mjs";
|
|
16
|
+
import { BINARY_SNIFF_BYTES as K, BUILTIN_TOOLS_PLUGIN_CODE as k, BUILTIN_TOOLS_PLUGIN_CODES as b, DEFAULT_DOWNLOAD_URL_ALLOWLIST as h, DEFAULT_IGNORED_DIRECTORIES as v, DEFAULT_IGNORED_FILE_PATTERNS as V, DEFAULT_LIMITS as Z, KiB as j, LIST_DIRECTORY_DEFAULT_LIMIT as q, LIST_DIRECTORY_MAX_LIMIT as z, LOCAL_FILES_FUNCTION_CODES as J, LOCAL_FILES_PLUGIN_CODES as Q, LOCAL_PYTHON_FUNCTION_CODE as $, LOCAL_PYTHON_PLUGIN_CODES as __, MiB as o_, PYTHON_DEFAULT_TIMEOUT_MS as e_, PYTHON_MAX_ARGS as T_, PYTHON_MAX_TIMEOUT_MS as E_, SEARCH_DEFAULT_DEPTH as r_, SEARCH_FUNCTION_CODES as L_, SEARCH_MAX_DEPTH as I_, TEXT_SEARCH_MAX_CONTEXT_LINES as S_, TEXT_SEARCH_MAX_FILES as A_, TEXT_SEARCH_MAX_FILE_BYTES as O_, TEXT_SEARCH_MAX_LINE_CHARS as t_, TRANSFER_FILE_SIZE_LIMIT_MB as C_, TRANSFER_FUNCTION_CODES as N_, WORKSPACE_GRANT_ID as l_, WRITE_FUNCTION_CODES as D_ } from "./localFiles/constants.mjs";
|
|
5
17
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
18
|
+
C as AgentPlugin,
|
|
19
|
+
K as BINARY_SNIFF_BYTES,
|
|
20
|
+
k as BUILTIN_TOOLS_PLUGIN_CODE,
|
|
21
|
+
b as BUILTIN_TOOLS_PLUGIN_CODES,
|
|
22
|
+
M as BUILTIN_TOOL_SCHEMAS,
|
|
23
|
+
S as BotClient,
|
|
24
|
+
h as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
25
|
+
v as DEFAULT_IGNORED_DIRECTORIES,
|
|
26
|
+
V as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
27
|
+
Z as DEFAULT_LIMITS,
|
|
28
|
+
d as FileSystemAccessAdapter,
|
|
29
|
+
j as KiB,
|
|
30
|
+
q as LIST_DIRECTORY_DEFAULT_LIMIT,
|
|
31
|
+
z as LIST_DIRECTORY_MAX_LIMIT,
|
|
32
|
+
J as LOCAL_FILES_FUNCTION_CODES,
|
|
33
|
+
Q as LOCAL_FILES_PLUGIN_CODES,
|
|
34
|
+
a as LOCAL_FILE_TOOL_SCHEMAS,
|
|
35
|
+
$ as LOCAL_PYTHON_FUNCTION_CODE,
|
|
36
|
+
__ as LOCAL_PYTHON_PLUGIN_CODES,
|
|
37
|
+
U as LOCAL_PYTHON_TOOL_SCHEMA,
|
|
38
|
+
P as LocalWorkspace,
|
|
39
|
+
g as MemoryWorkspaceAdapter,
|
|
40
|
+
o_ as MiB,
|
|
41
|
+
e_ as PYTHON_DEFAULT_TIMEOUT_MS,
|
|
42
|
+
T_ as PYTHON_MAX_ARGS,
|
|
43
|
+
E_ as PYTHON_MAX_TIMEOUT_MS,
|
|
44
|
+
w as SDK_SENSITIVE_BASELINE,
|
|
45
|
+
r_ as SEARCH_DEFAULT_DEPTH,
|
|
46
|
+
L_ as SEARCH_FUNCTION_CODES,
|
|
47
|
+
I_ as SEARCH_MAX_DEPTH,
|
|
48
|
+
O as Session,
|
|
49
|
+
S_ as TEXT_SEARCH_MAX_CONTEXT_LINES,
|
|
50
|
+
A_ as TEXT_SEARCH_MAX_FILES,
|
|
51
|
+
O_ as TEXT_SEARCH_MAX_FILE_BYTES,
|
|
52
|
+
t_ as TEXT_SEARCH_MAX_LINE_CHARS,
|
|
53
|
+
C_ as TRANSFER_FILE_SIZE_LIMIT_MB,
|
|
54
|
+
N_ as TRANSFER_FUNCTION_CODES,
|
|
55
|
+
l as ToolCode,
|
|
56
|
+
D as ToolError,
|
|
57
|
+
l_ as WORKSPACE_GRANT_ID,
|
|
58
|
+
D_ as WRITE_FUNCTION_CODES,
|
|
59
|
+
e as configuration,
|
|
60
|
+
T as configure,
|
|
61
|
+
u as createDefaultSessionFileTransfer,
|
|
62
|
+
H as createIndexedDbStore,
|
|
63
|
+
s as createLocalFilesPlugin,
|
|
64
|
+
n as createMemoryStore,
|
|
65
|
+
Y as getDownloadUrlAllowlist,
|
|
66
|
+
E as getRegisteredLocalFilesPluginCode,
|
|
67
|
+
r as getRegisteredLocalPythonPluginCode,
|
|
68
|
+
G as isDownloadUrlAllowed,
|
|
69
|
+
L as resolveLocalFilesPluginCode,
|
|
70
|
+
R as toToolError
|
|
11
71
|
};
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
var g = (o, t) => {
|
|
2
|
+
if (t = Symbol[o])
|
|
3
|
+
return t;
|
|
4
|
+
throw Error("Symbol." + o + " is not defined");
|
|
5
|
+
};
|
|
6
|
+
var y = (o, t, e) => new Promise((r, a) => {
|
|
7
|
+
var c = (i) => {
|
|
8
|
+
try {
|
|
9
|
+
l(e.next(i));
|
|
10
|
+
} catch (n) {
|
|
11
|
+
a(n);
|
|
12
|
+
}
|
|
13
|
+
}, w = (i) => {
|
|
14
|
+
try {
|
|
15
|
+
l(e.throw(i));
|
|
16
|
+
} catch (n) {
|
|
17
|
+
a(n);
|
|
18
|
+
}
|
|
19
|
+
}, l = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(c, w);
|
|
20
|
+
l((e = e.apply(o, t)).next());
|
|
21
|
+
});
|
|
22
|
+
var p = (o, t, e) => (t = o[g("asyncIterator")]) ? t.call(o) : (o = o[g("iterator")](), t = {}, e = (r, a) => (a = o[r]) && (t[r] = (c) => new Promise((w, l, i) => (c = a.call(o, c), i = c.done, Promise.resolve(c.value).then((n) => w({ value: n, done: i }), l)))), e("next"), e("return"), t);
|
|
23
|
+
import { domError as m, toChunks as D, isSameOrInside as k } from "./WorkspaceFileAdapter.mjs";
|
|
24
|
+
import { throwIfAborted as v } from "../errors.mjs";
|
|
25
|
+
import { splitPath as f } from "../security/pathPolicy.mjs";
|
|
26
|
+
function u(o, t) {
|
|
27
|
+
return !!o && typeof o == "object" && o.name === t;
|
|
28
|
+
}
|
|
29
|
+
class b {
|
|
30
|
+
constructor(t) {
|
|
31
|
+
this.root = t;
|
|
32
|
+
}
|
|
33
|
+
get displayName() {
|
|
34
|
+
return this.root.name;
|
|
35
|
+
}
|
|
36
|
+
resolveDirectory(t, e = !1) {
|
|
37
|
+
return y(this, null, function* () {
|
|
38
|
+
let r = this.root;
|
|
39
|
+
for (const a of t)
|
|
40
|
+
r = yield r.getDirectoryHandle(a, {
|
|
41
|
+
create: e
|
|
42
|
+
});
|
|
43
|
+
return r;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
resolveFile(t) {
|
|
47
|
+
return y(this, null, function* () {
|
|
48
|
+
const e = f(t), r = e.pop();
|
|
49
|
+
if (!r)
|
|
50
|
+
throw m("TypeMismatchError");
|
|
51
|
+
return (yield this.resolveDirectory(e)).getFileHandle(r);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
stat(t) {
|
|
55
|
+
return y(this, null, function* () {
|
|
56
|
+
const e = f(t), r = e.pop();
|
|
57
|
+
if (!r)
|
|
58
|
+
return {
|
|
59
|
+
name: this.root.name,
|
|
60
|
+
kind: "directory"
|
|
61
|
+
};
|
|
62
|
+
const a = yield this.resolveDirectory(e);
|
|
63
|
+
try {
|
|
64
|
+
const c = yield (yield a.getFileHandle(r)).getFile();
|
|
65
|
+
return {
|
|
66
|
+
name: r,
|
|
67
|
+
kind: "file",
|
|
68
|
+
size: c.size,
|
|
69
|
+
lastModified: c.lastModified
|
|
70
|
+
};
|
|
71
|
+
} catch (c) {
|
|
72
|
+
if (!u(c, "TypeMismatchError"))
|
|
73
|
+
throw c;
|
|
74
|
+
return yield a.getDirectoryHandle(r), {
|
|
75
|
+
name: r,
|
|
76
|
+
kind: "directory"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
listEntries(t, e) {
|
|
82
|
+
return y(this, null, function* () {
|
|
83
|
+
const r = yield this.resolveDirectory(f(t)), a = [];
|
|
84
|
+
try {
|
|
85
|
+
for (var c = p(r.values()), w, l, i; w = !(l = yield c.next()).done; w = !1) {
|
|
86
|
+
const n = l.value;
|
|
87
|
+
if (v(e), n.kind === "directory")
|
|
88
|
+
a.push({
|
|
89
|
+
name: n.name,
|
|
90
|
+
kind: "directory"
|
|
91
|
+
});
|
|
92
|
+
else
|
|
93
|
+
try {
|
|
94
|
+
const s = yield n.getFile();
|
|
95
|
+
a.push({
|
|
96
|
+
name: n.name,
|
|
97
|
+
kind: "file",
|
|
98
|
+
size: s.size,
|
|
99
|
+
lastModified: s.lastModified
|
|
100
|
+
});
|
|
101
|
+
} catch (s) {
|
|
102
|
+
if (u(s, "NotAllowedError"))
|
|
103
|
+
throw s;
|
|
104
|
+
a.push({
|
|
105
|
+
name: n.name,
|
|
106
|
+
kind: "file"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (l) {
|
|
111
|
+
i = [l];
|
|
112
|
+
} finally {
|
|
113
|
+
try {
|
|
114
|
+
w && (l = c.return) && (yield l.call(c));
|
|
115
|
+
} finally {
|
|
116
|
+
if (i)
|
|
117
|
+
throw i[0];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return a;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
readFile(t) {
|
|
124
|
+
return y(this, null, function* () {
|
|
125
|
+
return (yield this.resolveFile(t)).getFile();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
writeFile(a, c) {
|
|
129
|
+
return y(this, arguments, function* (t, e, r = {}) {
|
|
130
|
+
const w = f(t), l = w.pop();
|
|
131
|
+
if (!l)
|
|
132
|
+
throw m("TypeMismatchError");
|
|
133
|
+
const i = yield this.resolveDirectory(w, r.createDirectories);
|
|
134
|
+
let n = !0;
|
|
135
|
+
try {
|
|
136
|
+
yield i.getFileHandle(l);
|
|
137
|
+
} catch (h) {
|
|
138
|
+
if (!u(h, "NotFoundError"))
|
|
139
|
+
throw h;
|
|
140
|
+
n = !1;
|
|
141
|
+
}
|
|
142
|
+
const s = yield i.getFileHandle(l, {
|
|
143
|
+
create: !0
|
|
144
|
+
});
|
|
145
|
+
let d;
|
|
146
|
+
try {
|
|
147
|
+
d = yield s.createWritable();
|
|
148
|
+
try {
|
|
149
|
+
for (var A = p(D(e)), x, S, W; x = !(S = yield A.next()).done; x = !1) {
|
|
150
|
+
const h = S.value;
|
|
151
|
+
v(r.signal), yield d.write(h);
|
|
152
|
+
}
|
|
153
|
+
} catch (S) {
|
|
154
|
+
W = [S];
|
|
155
|
+
} finally {
|
|
156
|
+
try {
|
|
157
|
+
x && (S = A.return) && (yield S.call(A));
|
|
158
|
+
} finally {
|
|
159
|
+
if (W)
|
|
160
|
+
throw W[0];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
v(r.signal), yield d.close();
|
|
164
|
+
} catch (h) {
|
|
165
|
+
throw yield d == null ? void 0 : d.abort().catch(() => {
|
|
166
|
+
}), n || (yield i.removeEntry(l).catch(() => {
|
|
167
|
+
})), h;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
createDirectory(t) {
|
|
172
|
+
return y(this, null, function* () {
|
|
173
|
+
yield this.resolveDirectory(f(t), !0);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
remove(r) {
|
|
177
|
+
return y(this, arguments, function* (t, e = {}) {
|
|
178
|
+
const a = f(t), c = a.pop();
|
|
179
|
+
if (!c)
|
|
180
|
+
throw m("InvalidModificationError");
|
|
181
|
+
yield (yield this.resolveDirectory(a)).removeEntry(c, {
|
|
182
|
+
recursive: e.recursive === !0
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
move(t, e) {
|
|
187
|
+
return y(this, null, function* () {
|
|
188
|
+
const r = f(t), a = f(e), c = r.pop(), w = a.pop();
|
|
189
|
+
if (!c || !w)
|
|
190
|
+
throw m("InvalidModificationError");
|
|
191
|
+
const l = yield this.resolveDirectory(r), i = yield E(l, c), n = yield this.resolveDirectory(a);
|
|
192
|
+
if (k(t, e))
|
|
193
|
+
throw m("InvalidModificationError");
|
|
194
|
+
let s;
|
|
195
|
+
try {
|
|
196
|
+
s = yield E(n, w);
|
|
197
|
+
} catch (d) {
|
|
198
|
+
if (!u(d, "NotFoundError"))
|
|
199
|
+
throw d;
|
|
200
|
+
}
|
|
201
|
+
if (s && (s.kind === "directory" || i.kind === "directory"))
|
|
202
|
+
throw m("InvalidModificationError");
|
|
203
|
+
if (!s && typeof i.move == "function")
|
|
204
|
+
try {
|
|
205
|
+
yield i.move(n, w);
|
|
206
|
+
return;
|
|
207
|
+
} catch (d) {
|
|
208
|
+
if (!u(d, "NotSupportedError") && !(d instanceof TypeError))
|
|
209
|
+
throw d;
|
|
210
|
+
}
|
|
211
|
+
yield F(i, n, w), yield l.removeEntry(c, {
|
|
212
|
+
recursive: !0
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function E(o, t) {
|
|
218
|
+
return y(this, null, function* () {
|
|
219
|
+
try {
|
|
220
|
+
return yield o.getFileHandle(t);
|
|
221
|
+
} catch (e) {
|
|
222
|
+
if (!u(e, "TypeMismatchError"))
|
|
223
|
+
throw e;
|
|
224
|
+
return o.getDirectoryHandle(t);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
function F(o, t, e) {
|
|
229
|
+
return y(this, null, function* () {
|
|
230
|
+
if (o.kind === "file") {
|
|
231
|
+
const i = yield o.getFile(), n = yield (yield t.getFileHandle(e, {
|
|
232
|
+
create: !0
|
|
233
|
+
})).createWritable();
|
|
234
|
+
try {
|
|
235
|
+
yield n.write(i), yield n.close();
|
|
236
|
+
} catch (s) {
|
|
237
|
+
throw yield n.abort().catch(() => {
|
|
238
|
+
}), s;
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const r = yield t.getDirectoryHandle(e, {
|
|
243
|
+
create: !0
|
|
244
|
+
});
|
|
245
|
+
try {
|
|
246
|
+
for (var a = p(o.values()), c, w, l; c = !(w = yield a.next()).done; c = !1) {
|
|
247
|
+
const i = w.value;
|
|
248
|
+
yield F(i, r, i.name);
|
|
249
|
+
}
|
|
250
|
+
} catch (w) {
|
|
251
|
+
l = [w];
|
|
252
|
+
} finally {
|
|
253
|
+
try {
|
|
254
|
+
c && (w = a.return) && (yield w.call(a));
|
|
255
|
+
} finally {
|
|
256
|
+
if (l)
|
|
257
|
+
throw l[0];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
export {
|
|
263
|
+
b as FileSystemAccessAdapter
|
|
264
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var m = (r, t) => {
|
|
3
|
+
if (t = Symbol[r])
|
|
4
|
+
return t;
|
|
5
|
+
throw Error("Symbol." + r + " is not defined");
|
|
6
|
+
};
|
|
7
|
+
var u = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
8
|
+
var l = (r, t, e) => (u(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
9
|
+
var n = (r, t, e) => new Promise((s, a) => {
|
|
10
|
+
var o = (i) => {
|
|
11
|
+
try {
|
|
12
|
+
y(e.next(i));
|
|
13
|
+
} catch (c) {
|
|
14
|
+
a(c);
|
|
15
|
+
}
|
|
16
|
+
}, d = (i) => {
|
|
17
|
+
try {
|
|
18
|
+
y(e.throw(i));
|
|
19
|
+
} catch (c) {
|
|
20
|
+
a(c);
|
|
21
|
+
}
|
|
22
|
+
}, y = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, d);
|
|
23
|
+
y((e = e.apply(r, t)).next());
|
|
24
|
+
});
|
|
25
|
+
var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (o) => new Promise((d, y, i) => (o = a.call(r, o), i = o.done, Promise.resolve(o.value).then((c) => d({ value: c, done: i }), y)))), e("next"), e("return"), t);
|
|
26
|
+
import { throwIfAborted as g } from "../errors.mjs";
|
|
27
|
+
import { SandboxClient as v } from "../host/sandboxClient.mjs";
|
|
28
|
+
import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
|
|
29
|
+
import { domError as w, toChunks as M } from "./WorkspaceFileAdapter.mjs";
|
|
30
|
+
function x(r, t) {
|
|
31
|
+
const e = r && typeof r == "object" ? r : {}, s = e.kind === "directory" ? "directory" : "file", a = {
|
|
32
|
+
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
33
|
+
kind: s
|
|
34
|
+
};
|
|
35
|
+
return s === "file" && typeof e.size == "number" && (a.size = e.size), typeof e.lastModified == "number" && (a.lastModified = e.lastModified), a;
|
|
36
|
+
}
|
|
37
|
+
class S {
|
|
38
|
+
constructor(t, e = "", s = new v()) {
|
|
39
|
+
l(this, "displayName");
|
|
40
|
+
l(this, "capabilities", /* @__PURE__ */ new Set());
|
|
41
|
+
l(this, "sandboxVersion");
|
|
42
|
+
l(this, "sandboxProtocol");
|
|
43
|
+
l(this, "sandbox");
|
|
44
|
+
this.displayName = e, this.sandbox = s;
|
|
45
|
+
}
|
|
46
|
+
setCapabilities(t, e = {}) {
|
|
47
|
+
const s = Array.isArray(t) ? t.filter((a) => typeof a == "string") : [];
|
|
48
|
+
this.capabilities = new Set(s), this.sandboxVersion = typeof e.version == "string" ? e.version : void 0;
|
|
49
|
+
}
|
|
50
|
+
applySandbox(t) {
|
|
51
|
+
this.sandboxProtocol = t == null ? void 0 : t.protocol, this.sandbox.apply(t);
|
|
52
|
+
}
|
|
53
|
+
/** 沙箱已就绪且协议为 2 时,命令走直连。 */
|
|
54
|
+
get canExec() {
|
|
55
|
+
return this.sandbox.ready;
|
|
56
|
+
}
|
|
57
|
+
get protocolMismatch() {
|
|
58
|
+
return this.sandboxProtocol !== void 0 && this.sandboxProtocol !== A;
|
|
59
|
+
}
|
|
60
|
+
unavailableMessage() {
|
|
61
|
+
return this.sandbox.unavailableMessage();
|
|
62
|
+
}
|
|
63
|
+
stat(t) {
|
|
64
|
+
return n(this, null, function* () {
|
|
65
|
+
const e = yield this.sandbox.stat(t);
|
|
66
|
+
return x(e.entry, t.split("/").pop() || this.displayName);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
listEntries(t, e) {
|
|
70
|
+
return n(this, null, function* () {
|
|
71
|
+
const s = yield this.sandbox.list(t, e);
|
|
72
|
+
return (Array.isArray(s.entries) ? s.entries : []).map((o) => x(o, ""));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
readFile(t, e) {
|
|
76
|
+
return n(this, null, function* () {
|
|
77
|
+
var a;
|
|
78
|
+
const s = yield this.sandbox.read(t, (a = e == null ? void 0 : e.offset) != null ? a : 0, e == null ? void 0 : e.maxBytes);
|
|
79
|
+
return new Blob([s]);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
createDirectory(t) {
|
|
83
|
+
return n(this, null, function* () {
|
|
84
|
+
yield this.sandbox.mkdir(t);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
remove(s) {
|
|
88
|
+
return n(this, arguments, function* (t, e = {}) {
|
|
89
|
+
yield this.sandbox.remove(t, e.recursive === !0);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
move(t, e) {
|
|
93
|
+
return n(this, null, function* () {
|
|
94
|
+
yield this.sandbox.move(t, e);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exec(t) {
|
|
98
|
+
return n(this, null, function* () {
|
|
99
|
+
const e = yield this.sandbox.exec({
|
|
100
|
+
op: "exec",
|
|
101
|
+
cwd: t.cwd,
|
|
102
|
+
command: t.command,
|
|
103
|
+
argv: t.argv,
|
|
104
|
+
timeoutMs: t.timeoutMs
|
|
105
|
+
}, t.signal, t.onOutput);
|
|
106
|
+
if (e.timedOut)
|
|
107
|
+
throw w("AbortError", "命令运行超时。");
|
|
108
|
+
return e;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
runPython(t, e, s, a) {
|
|
112
|
+
return n(this, null, function* () {
|
|
113
|
+
return this.sandbox.exec({
|
|
114
|
+
op: "run_python",
|
|
115
|
+
path: t,
|
|
116
|
+
args: e,
|
|
117
|
+
timeoutMs: s
|
|
118
|
+
}, a);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
writeFile(a, o) {
|
|
122
|
+
return n(this, arguments, function* (t, e, s = {}) {
|
|
123
|
+
if (typeof e == "string") {
|
|
124
|
+
yield this.sandbox.write(t, new TextEncoder().encode(e), s.createDirectories === !0, s.signal);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (e instanceof Uint8Array) {
|
|
128
|
+
yield this.sandbox.write(t, e, s.createDirectories === !0, s.signal);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const d = [];
|
|
132
|
+
try {
|
|
133
|
+
for (var N = f(M(e)), z, L, F; z = !(L = yield N.next()).done; z = !1) {
|
|
134
|
+
const b = L.value;
|
|
135
|
+
g(s.signal), d.push(b);
|
|
136
|
+
}
|
|
137
|
+
} catch (L) {
|
|
138
|
+
F = [L];
|
|
139
|
+
} finally {
|
|
140
|
+
try {
|
|
141
|
+
z && (L = N.return) && (yield L.call(N));
|
|
142
|
+
} finally {
|
|
143
|
+
if (F)
|
|
144
|
+
throw F[0];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const y = d.reduce((b, h) => b + h.byteLength, 0), i = new Uint8Array(y);
|
|
148
|
+
let c = 0;
|
|
149
|
+
d.forEach((b) => {
|
|
150
|
+
i.set(b, c), c += b.byteLength;
|
|
151
|
+
}), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
S as HostBridgeAdapter
|
|
157
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var g = (n, r) => {
|
|
3
|
+
if (r = Symbol[n])
|
|
4
|
+
return r;
|
|
5
|
+
throw Error("Symbol." + n + " is not defined");
|
|
6
|
+
};
|
|
7
|
+
var N = (n, r, e) => r in n ? M(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
|
|
8
|
+
var k = (n, r, e) => (N(n, typeof r != "symbol" ? r + "" : r, e), e);
|
|
9
|
+
var h = (n, r, e) => new Promise((o, t) => {
|
|
10
|
+
var i = (c) => {
|
|
11
|
+
try {
|
|
12
|
+
s(e.next(c));
|
|
13
|
+
} catch (l) {
|
|
14
|
+
t(l);
|
|
15
|
+
}
|
|
16
|
+
}, d = (c) => {
|
|
17
|
+
try {
|
|
18
|
+
s(e.throw(c));
|
|
19
|
+
} catch (l) {
|
|
20
|
+
t(l);
|
|
21
|
+
}
|
|
22
|
+
}, s = (c) => c.done ? o(c.value) : Promise.resolve(c.value).then(i, d);
|
|
23
|
+
s((e = e.apply(n, r)).next());
|
|
24
|
+
});
|
|
25
|
+
var E = (n, r, e) => (r = n[g("asyncIterator")]) ? r.call(n) : (n = n[g("iterator")](), r = {}, e = (o, t) => (t = n[o]) && (r[o] = (i) => new Promise((d, s, c) => (i = t.call(n, i), c = i.done, Promise.resolve(i.value).then((l) => d({ value: l, done: c }), s)))), e("next"), e("return"), r);
|
|
26
|
+
import { domError as a, toChunks as b, isSameOrInside as I } from "./WorkspaceFileAdapter.mjs";
|
|
27
|
+
import { throwIfAborted as p } from "../errors.mjs";
|
|
28
|
+
import { splitPath as f } from "../security/pathPolicy.mjs";
|
|
29
|
+
function D() {
|
|
30
|
+
return {
|
|
31
|
+
kind: "directory",
|
|
32
|
+
children: /* @__PURE__ */ new Map()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
class x {
|
|
36
|
+
constructor(r = {}, e = "memory-workspace") {
|
|
37
|
+
k(this, "root", D());
|
|
38
|
+
this.displayName = e, Object.entries(r).forEach(([o, t]) => this.seed(o, t));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 直接写入文件(含中间目录),用于构造测试数据或模拟外部修改。
|
|
42
|
+
* 以 `/` 结尾的路径表示创建空目录。
|
|
43
|
+
*/
|
|
44
|
+
seed(r, e = "", o = Date.now()) {
|
|
45
|
+
const t = r.split("/").filter(Boolean);
|
|
46
|
+
if (r.endsWith("/")) {
|
|
47
|
+
this.resolveDirectory(t, !0);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const i = t.pop();
|
|
51
|
+
if (!i)
|
|
52
|
+
return;
|
|
53
|
+
const d = this.resolveDirectory(t, !0), s = typeof e == "string" ? new TextEncoder().encode(e) : e;
|
|
54
|
+
d.children.set(i, {
|
|
55
|
+
kind: "file",
|
|
56
|
+
data: s,
|
|
57
|
+
lastModified: o
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
resolveDirectory(r, e = !1) {
|
|
61
|
+
let o = this.root;
|
|
62
|
+
for (const t of r) {
|
|
63
|
+
let i = o.children.get(t);
|
|
64
|
+
if (!i) {
|
|
65
|
+
if (!e)
|
|
66
|
+
throw a("NotFoundError");
|
|
67
|
+
i = D(), o.children.set(t, i);
|
|
68
|
+
}
|
|
69
|
+
if (i.kind !== "directory")
|
|
70
|
+
throw a("TypeMismatchError");
|
|
71
|
+
o = i;
|
|
72
|
+
}
|
|
73
|
+
return o;
|
|
74
|
+
}
|
|
75
|
+
resolveNode(r) {
|
|
76
|
+
const e = f(r), o = e.pop();
|
|
77
|
+
if (o === void 0)
|
|
78
|
+
return this.root;
|
|
79
|
+
const t = this.resolveDirectory(e).children.get(o);
|
|
80
|
+
if (!t)
|
|
81
|
+
throw a("NotFoundError");
|
|
82
|
+
return t;
|
|
83
|
+
}
|
|
84
|
+
stat(r) {
|
|
85
|
+
return h(this, null, function* () {
|
|
86
|
+
var t;
|
|
87
|
+
const e = this.resolveNode(r), o = (t = f(r).pop()) != null ? t : this.displayName;
|
|
88
|
+
return e.kind === "directory" ? {
|
|
89
|
+
name: o,
|
|
90
|
+
kind: "directory"
|
|
91
|
+
} : {
|
|
92
|
+
name: o,
|
|
93
|
+
kind: "file",
|
|
94
|
+
size: e.data.byteLength,
|
|
95
|
+
lastModified: e.lastModified
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
listEntries(r, e) {
|
|
100
|
+
return h(this, null, function* () {
|
|
101
|
+
p(e);
|
|
102
|
+
const o = this.resolveDirectory(f(r));
|
|
103
|
+
return Array.from(o.children.entries()).map(([t, i]) => i.kind === "directory" ? {
|
|
104
|
+
name: t,
|
|
105
|
+
kind: "directory"
|
|
106
|
+
} : {
|
|
107
|
+
name: t,
|
|
108
|
+
kind: "file",
|
|
109
|
+
size: i.data.byteLength,
|
|
110
|
+
lastModified: i.lastModified
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
readFile(r) {
|
|
115
|
+
return h(this, null, function* () {
|
|
116
|
+
const e = this.resolveNode(r);
|
|
117
|
+
if (e.kind !== "file")
|
|
118
|
+
throw a("TypeMismatchError");
|
|
119
|
+
return new Blob([e.data]);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
writeFile(t, i) {
|
|
123
|
+
return h(this, arguments, function* (r, e, o = {}) {
|
|
124
|
+
const d = f(r), s = d.pop();
|
|
125
|
+
if (!s)
|
|
126
|
+
throw a("TypeMismatchError");
|
|
127
|
+
const c = this.resolveDirectory(d, o.createDirectories), l = c.children.get(s);
|
|
128
|
+
if ((l == null ? void 0 : l.kind) === "directory")
|
|
129
|
+
throw a("TypeMismatchError");
|
|
130
|
+
const y = [];
|
|
131
|
+
let u = 0;
|
|
132
|
+
try {
|
|
133
|
+
for (var O = E(b(e)), W, j, C; W = !(j = yield O.next()).done; W = !1) {
|
|
134
|
+
const m = j.value;
|
|
135
|
+
p(o.signal), y.push(m), u += m.byteLength;
|
|
136
|
+
}
|
|
137
|
+
} catch (j) {
|
|
138
|
+
C = [j];
|
|
139
|
+
} finally {
|
|
140
|
+
try {
|
|
141
|
+
W && (j = O.return) && (yield j.call(O));
|
|
142
|
+
} finally {
|
|
143
|
+
if (C)
|
|
144
|
+
throw C[0];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
p(o.signal);
|
|
148
|
+
const v = new Uint8Array(u);
|
|
149
|
+
let w = 0;
|
|
150
|
+
y.forEach((m) => {
|
|
151
|
+
v.set(m, w), w += m.byteLength;
|
|
152
|
+
}), c.children.set(s, {
|
|
153
|
+
kind: "file",
|
|
154
|
+
data: v,
|
|
155
|
+
lastModified: Date.now()
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
createDirectory(r) {
|
|
160
|
+
return h(this, null, function* () {
|
|
161
|
+
this.resolveDirectory(f(r), !0);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
remove(o) {
|
|
165
|
+
return h(this, arguments, function* (r, e = {}) {
|
|
166
|
+
const t = f(r), i = t.pop();
|
|
167
|
+
if (i === void 0)
|
|
168
|
+
throw a("InvalidModificationError");
|
|
169
|
+
const d = this.resolveDirectory(t), s = d.children.get(i);
|
|
170
|
+
if (!s)
|
|
171
|
+
throw a("NotFoundError");
|
|
172
|
+
if (s.kind === "directory" && s.children.size > 0 && !e.recursive)
|
|
173
|
+
throw a("InvalidModificationError");
|
|
174
|
+
d.children.delete(i);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
move(r, e) {
|
|
178
|
+
return h(this, null, function* () {
|
|
179
|
+
const o = f(r), t = f(e), i = o.pop(), d = t.pop();
|
|
180
|
+
if (i === void 0 || d === void 0)
|
|
181
|
+
throw a("InvalidModificationError");
|
|
182
|
+
const s = this.resolveDirectory(o), c = s.children.get(i);
|
|
183
|
+
if (!c)
|
|
184
|
+
throw a("NotFoundError");
|
|
185
|
+
const l = this.resolveDirectory(t);
|
|
186
|
+
if (I(r, e))
|
|
187
|
+
throw a("InvalidModificationError");
|
|
188
|
+
const y = l.children.get(d);
|
|
189
|
+
if (y && (y.kind === "directory" || c.kind === "directory"))
|
|
190
|
+
throw a("InvalidModificationError");
|
|
191
|
+
s.children.delete(i), l.children.set(d, c);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
x as MemoryWorkspaceAdapter
|
|
197
|
+
};
|