@glodon-aiot/bot-client-sdk 3.25.1-alpha.7 → 3.26.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +572 -98
- package/dist/es/AgentSession.mjs +230 -165
- package/dist/es/BotClient.mjs +186 -136
- package/dist/es/Config.mjs +89 -26
- package/dist/es/Session.mjs +12 -0
- package/dist/es/api/index.mjs +42 -33
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +236 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +63 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +471 -0
- package/dist/es/index.mjs +69 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +233 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
- package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
- package/dist/es/localFiles/constants.mjs +47 -0
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +54 -0
- package/dist/es/localFiles/host/protocol.mjs +27 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +312 -0
- package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
- package/dist/es/localFiles/security/glob.mjs +28 -0
- package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
- package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
- package/dist/es/localFiles/tools/readTools.mjs +333 -0
- package/dist/es/localFiles/tools/runtime.mjs +108 -0
- package/dist/es/localFiles/tools/transferTools.mjs +228 -0
- package/dist/es/localFiles/tools/writeTools.mjs +173 -0
- package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
- package/dist/es/localFiles/validate.mjs +66 -0
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
- package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
- package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
- package/dist/es/package.json.mjs +38 -29
- package/dist/lib/index.js +373 -5
- package/dist/src/AgentSession.d.ts +9 -0
- package/dist/src/BotClient.d.ts +12 -2
- package/dist/src/Config.d.ts +22 -0
- package/dist/src/Session.d.ts +5 -1
- package/dist/src/api/index.d.ts +3 -1
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +26 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +15 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +60 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +43 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
- package/dist/src/localFiles/constants.d.ts +51 -0
- package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
- package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
- package/dist/src/localFiles/errors.d.ts +34 -0
- package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
- package/dist/src/localFiles/host/protocol.d.ts +46 -0
- package/dist/src/localFiles/index.d.ts +22 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +29 -0
- package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
- package/dist/src/localFiles/security/glob.d.ts +3 -0
- package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
- package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
- package/dist/src/localFiles/tools/readTools.d.ts +7 -0
- package/dist/src/localFiles/tools/runtime.d.ts +43 -0
- package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
- package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
- package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
- package/dist/src/localFiles/types.d.ts +319 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +13 -4
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,233 @@
|
|
|
1
|
+
var N = Object.defineProperty;
|
|
2
|
+
var f = Object.getOwnPropertySymbols;
|
|
3
|
+
var O = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var m = (i, t) => {
|
|
5
|
+
if (t = Symbol[i])
|
|
6
|
+
return t;
|
|
7
|
+
throw Error("Symbol." + i + " is not defined");
|
|
8
|
+
};
|
|
9
|
+
var u = (i, t, e) => t in i ? N(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e, b = (i, t) => {
|
|
10
|
+
for (var e in t || (t = {}))
|
|
11
|
+
O.call(t, e) && u(i, e, t[e]);
|
|
12
|
+
if (f)
|
|
13
|
+
for (var e of f(t))
|
|
14
|
+
T.call(t, e) && u(i, e, t[e]);
|
|
15
|
+
return i;
|
|
16
|
+
};
|
|
17
|
+
var p = (i, t, e) => (u(i, typeof t != "symbol" ? t + "" : t, e), e);
|
|
18
|
+
var l = (i, t, e) => new Promise((r, o) => {
|
|
19
|
+
var s = (n) => {
|
|
20
|
+
try {
|
|
21
|
+
c(e.next(n));
|
|
22
|
+
} catch (d) {
|
|
23
|
+
o(d);
|
|
24
|
+
}
|
|
25
|
+
}, a = (n) => {
|
|
26
|
+
try {
|
|
27
|
+
c(e.throw(n));
|
|
28
|
+
} catch (d) {
|
|
29
|
+
o(d);
|
|
30
|
+
}
|
|
31
|
+
}, c = (n) => n.done ? r(n.value) : Promise.resolve(n.value).then(s, a);
|
|
32
|
+
c((e = e.apply(i, t)).next());
|
|
33
|
+
});
|
|
34
|
+
var w = (i, t, e) => (t = i[m("asyncIterator")]) ? t.call(i) : (i = i[m("iterator")](), t = {}, e = (r, o) => (o = i[r]) && (t[r] = (s) => new Promise((a, c, n) => (s = o.call(i, s), n = s.done, Promise.resolve(s.value).then((d) => a({ value: d, done: n }), c)))), e("next"), e("return"), t);
|
|
35
|
+
import { domError as h, toChunks as L } from "./WorkspaceFileAdapter.mjs";
|
|
36
|
+
import { throwIfAborted as A } from "../errors.mjs";
|
|
37
|
+
import { SANDBOX_PROTOCOL as C, HOST_CHANNEL as M } from "../host/protocol.mjs";
|
|
38
|
+
const x = 3e4;
|
|
39
|
+
function B(i) {
|
|
40
|
+
let t = "";
|
|
41
|
+
for (let r = 0; r < i.length; r += 32768)
|
|
42
|
+
t += String.fromCharCode(...i.subarray(r, r + 32768));
|
|
43
|
+
return btoa(t);
|
|
44
|
+
}
|
|
45
|
+
function k(i) {
|
|
46
|
+
const t = atob(i), e = new Uint8Array(t.length);
|
|
47
|
+
for (let r = 0; r < t.length; r++)
|
|
48
|
+
e[r] = t.charCodeAt(r);
|
|
49
|
+
return e;
|
|
50
|
+
}
|
|
51
|
+
function v(i, t) {
|
|
52
|
+
const e = i && typeof i == "object" ? i : {}, r = e.kind === "directory" ? "directory" : "file", o = {
|
|
53
|
+
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
54
|
+
kind: r
|
|
55
|
+
};
|
|
56
|
+
return r === "file" && typeof e.size == "number" && (o.size = e.size), typeof e.lastModified == "number" && (o.lastModified = e.lastModified), o;
|
|
57
|
+
}
|
|
58
|
+
class q {
|
|
59
|
+
constructor(t, e = "") {
|
|
60
|
+
p(this, "displayName");
|
|
61
|
+
/** 宿主最近一次 workspace 消息声明的能力。 */
|
|
62
|
+
p(this, "capabilities", /* @__PURE__ */ new Set());
|
|
63
|
+
/** 宿主随 sandbox-exec 声明的沙箱包版本和协议。 */
|
|
64
|
+
p(this, "sandboxVersion");
|
|
65
|
+
p(this, "sandboxProtocol");
|
|
66
|
+
p(this, "seq", 0);
|
|
67
|
+
p(this, "pending", /* @__PURE__ */ new Map());
|
|
68
|
+
this.view = t, this.displayName = e;
|
|
69
|
+
}
|
|
70
|
+
setCapabilities(t, e = {}) {
|
|
71
|
+
const r = Array.isArray(t) ? t.filter((o) => typeof o == "string") : [];
|
|
72
|
+
this.capabilities = new Set(r), this.sandboxVersion = typeof e.version == "string" ? e.version : void 0, this.sandboxProtocol = typeof e.protocol == "number" ? e.protocol : void 0;
|
|
73
|
+
}
|
|
74
|
+
/** 声明了 sandbox-exec 且协议版本与 SDK 一致时才把命令交给宿主。 */
|
|
75
|
+
get canExec() {
|
|
76
|
+
return this.capabilities.has("sandbox-exec") && this.sandboxProtocol === C;
|
|
77
|
+
}
|
|
78
|
+
requireCapability(t) {
|
|
79
|
+
if (!this.capabilities.has(t))
|
|
80
|
+
throw h("NotAllowedError", `宿主未声明 ${t}。`);
|
|
81
|
+
}
|
|
82
|
+
settle(t) {
|
|
83
|
+
const e = this.pending.get(t.id);
|
|
84
|
+
if (e) {
|
|
85
|
+
if (clearTimeout(e.timer), this.pending.delete(t.id), t.ok === !1) {
|
|
86
|
+
e.reject(h(t.name || "NotAllowedError", t.message || t.name || "NotAllowedError"));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
e.resolve(t);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
call(t, e, r, o = x) {
|
|
93
|
+
A(r);
|
|
94
|
+
const s = `host-${++this.seq}`;
|
|
95
|
+
return new Promise((a, c) => {
|
|
96
|
+
const n = setTimeout(() => {
|
|
97
|
+
this.pending.delete(s), c(h("AbortError"));
|
|
98
|
+
}, o), d = () => {
|
|
99
|
+
clearTimeout(n), this.pending.delete(s), c(h("AbortError"));
|
|
100
|
+
};
|
|
101
|
+
r == null || r.addEventListener("abort", d, {
|
|
102
|
+
once: !0
|
|
103
|
+
}), this.pending.set(s, {
|
|
104
|
+
resolve: (E) => {
|
|
105
|
+
r == null || r.removeEventListener("abort", d), a(E);
|
|
106
|
+
},
|
|
107
|
+
reject: c,
|
|
108
|
+
timer: n
|
|
109
|
+
}), this.view.postMessage(b({
|
|
110
|
+
channel: M,
|
|
111
|
+
id: s,
|
|
112
|
+
op: t
|
|
113
|
+
}, e));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
stat(t) {
|
|
117
|
+
return l(this, null, function* () {
|
|
118
|
+
const e = yield this.call("stat", {
|
|
119
|
+
path: t
|
|
120
|
+
});
|
|
121
|
+
return v(e.entry, t.split("/").pop() || this.displayName);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
listEntries(t, e) {
|
|
125
|
+
return l(this, null, function* () {
|
|
126
|
+
const r = yield this.call("list", {
|
|
127
|
+
path: t
|
|
128
|
+
}, e);
|
|
129
|
+
return (Array.isArray(r.entries) ? r.entries : []).map((s) => v(s, ""));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
readFile(t) {
|
|
133
|
+
return l(this, null, function* () {
|
|
134
|
+
var o;
|
|
135
|
+
const e = yield this.call("read", {
|
|
136
|
+
path: t
|
|
137
|
+
}), r = k((o = e.contentBase64) != null ? o : "");
|
|
138
|
+
return new Blob([r]);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
createDirectory(t) {
|
|
142
|
+
return l(this, null, function* () {
|
|
143
|
+
this.requireCapability("fs-mutate"), yield this.call("mkdir", {
|
|
144
|
+
path: t
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
remove(r) {
|
|
149
|
+
return l(this, arguments, function* (t, e = {}) {
|
|
150
|
+
this.requireCapability("fs-mutate"), yield this.call("remove", {
|
|
151
|
+
path: t,
|
|
152
|
+
recursive: e.recursive === !0
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
move(t, e) {
|
|
157
|
+
return l(this, null, function* () {
|
|
158
|
+
this.requireCapability("fs-mutate"), yield this.call("move", {
|
|
159
|
+
from: t,
|
|
160
|
+
to: e
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
exec(t) {
|
|
165
|
+
return l(this, null, function* () {
|
|
166
|
+
var o, s, a;
|
|
167
|
+
this.requireCapability("sandbox-exec");
|
|
168
|
+
const e = (o = t.timeoutMs) != null ? o : x, r = yield this.call("exec", {
|
|
169
|
+
protocol: C,
|
|
170
|
+
cwd: t.cwd,
|
|
171
|
+
command: t.command,
|
|
172
|
+
argv: t.argv,
|
|
173
|
+
timeoutMs: e
|
|
174
|
+
}, t.signal, e + 15e3);
|
|
175
|
+
if (r.timedOut)
|
|
176
|
+
throw h("AbortError", "命令运行超时。");
|
|
177
|
+
return {
|
|
178
|
+
exitCode: typeof r.exitCode == "number" ? r.exitCode : 1,
|
|
179
|
+
stdout: (s = r.stdout) != null ? s : "",
|
|
180
|
+
stderr: (a = r.stderr) != null ? a : "",
|
|
181
|
+
cwd: typeof r.cwd == "string" ? r.cwd : void 0
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
runPython(t, e, r, o) {
|
|
186
|
+
return l(this, null, function* () {
|
|
187
|
+
var a, c;
|
|
188
|
+
const s = yield this.call("run_python", {
|
|
189
|
+
path: t,
|
|
190
|
+
args: e,
|
|
191
|
+
timeoutMs: r
|
|
192
|
+
}, o, r + 15e3);
|
|
193
|
+
return {
|
|
194
|
+
exitCode: typeof s.exitCode == "number" ? s.exitCode : 1,
|
|
195
|
+
timedOut: s.timedOut === !0,
|
|
196
|
+
stdout: (a = s.stdout) != null ? a : "",
|
|
197
|
+
stderr: (c = s.stderr) != null ? c : ""
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
writeFile(o, s) {
|
|
202
|
+
return l(this, arguments, function* (t, e, r = {}) {
|
|
203
|
+
const a = [];
|
|
204
|
+
try {
|
|
205
|
+
for (var E = w(L(e)), U, F, I; U = !(F = yield E.next()).done; U = !1) {
|
|
206
|
+
const y = F.value;
|
|
207
|
+
A(r.signal), a.push(y);
|
|
208
|
+
}
|
|
209
|
+
} catch (F) {
|
|
210
|
+
I = [F];
|
|
211
|
+
} finally {
|
|
212
|
+
try {
|
|
213
|
+
U && (F = E.return) && (yield F.call(E));
|
|
214
|
+
} finally {
|
|
215
|
+
if (I)
|
|
216
|
+
throw I[0];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const c = a.reduce((y, g) => y + g.byteLength, 0), n = new Uint8Array(c);
|
|
220
|
+
let d = 0;
|
|
221
|
+
a.forEach((y) => {
|
|
222
|
+
n.set(y, d), d += y.byteLength;
|
|
223
|
+
}), yield this.call("write", {
|
|
224
|
+
path: t,
|
|
225
|
+
contentBase64: B(n),
|
|
226
|
+
createDirectories: r.createDirectories === !0
|
|
227
|
+
}, r.signal);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export {
|
|
232
|
+
q as HostBridgeAdapter
|
|
233
|
+
};
|