@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
package/dist/es/index.mjs
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
import { configuration as e, configure as
|
|
2
|
-
import { default as
|
|
3
|
-
import { default as
|
|
4
|
-
import { default as
|
|
5
|
-
import { ToolCode as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
import { configuration as e, configure as r, getRegisteredLocalFilesPluginCode as E, resolveLocalFilesPluginCode as T } from "./Config.mjs";
|
|
2
|
+
import { default as I } from "./BotClient.mjs";
|
|
3
|
+
import { default as A } from "./Session.mjs";
|
|
4
|
+
import { default as O } from "./AgentPlugin.mjs";
|
|
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
|
+
import { createLocalFilesPlugin as s } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
9
|
+
import { LocalWorkspace as m } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
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";
|
|
10
12
|
import { FileSystemAccessAdapter as d } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
|
|
11
|
-
import { MemoryWorkspaceAdapter as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
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";
|
|
16
19
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
O as AgentPlugin,
|
|
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,
|
|
25
|
+
I as BotClient,
|
|
26
|
+
q as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
27
|
+
J as DEFAULT_IGNORED_DIRECTORIES,
|
|
28
|
+
Q as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
29
|
+
$ as DEFAULT_LIMITS,
|
|
27
30
|
d as FileSystemAccessAdapter,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
N_ as WORKSPACE_GRANT_ID,
|
|
57
|
-
l_ as WRITE_FUNCTION_CODES,
|
|
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,
|
|
39
|
+
m as LocalWorkspace,
|
|
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,
|
|
47
|
+
A as Session,
|
|
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,
|
|
55
|
+
N as ToolError,
|
|
56
|
+
Do as WORKSPACE_GRANT_ID,
|
|
57
|
+
Fo as WRITE_FUNCTION_CODES,
|
|
58
|
+
U as WorkspaceFiles,
|
|
58
59
|
e as configuration,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
r as configure,
|
|
61
|
+
k as createDefaultSessionFileTransfer,
|
|
62
|
+
B as createIndexedDbStore,
|
|
63
|
+
s as createLocalFilesPlugin,
|
|
64
|
+
H as createMemoryStore,
|
|
65
|
+
K as getDownloadUrlAllowlist,
|
|
65
66
|
E as getRegisteredLocalFilesPluginCode,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
b as isDownloadUrlAllowed,
|
|
68
|
+
M as normalizeFilePath,
|
|
69
|
+
Y as registerHostBridge,
|
|
70
|
+
T as resolveLocalFilesPluginCode,
|
|
71
|
+
D as toToolError
|
|
70
72
|
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var y = (n, r) => {
|
|
3
|
+
if (r = Symbol[n])
|
|
4
|
+
return r;
|
|
5
|
+
throw Error("Symbol." + n + " is not defined");
|
|
6
|
+
};
|
|
7
|
+
var g = (n, r, e) => r in n ? M(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
|
|
8
|
+
var m = (n, r, e) => (g(n, typeof r != "symbol" ? r + "" : r, e), e);
|
|
9
|
+
var f = (n, r, e) => new Promise((t, o) => {
|
|
10
|
+
var i = (s) => {
|
|
11
|
+
try {
|
|
12
|
+
c(e.next(s));
|
|
13
|
+
} catch (d) {
|
|
14
|
+
o(d);
|
|
15
|
+
}
|
|
16
|
+
}, l = (s) => {
|
|
17
|
+
try {
|
|
18
|
+
c(e.throw(s));
|
|
19
|
+
} catch (d) {
|
|
20
|
+
o(d);
|
|
21
|
+
}
|
|
22
|
+
}, c = (s) => s.done ? t(s.value) : Promise.resolve(s.value).then(i, l);
|
|
23
|
+
c((e = e.apply(n, r)).next());
|
|
24
|
+
});
|
|
25
|
+
var u = (n, r, e) => (r = n[y("asyncIterator")]) ? r.call(n) : (n = n[y("iterator")](), r = {}, e = (t, o) => (o = n[t]) && (r[t] = (i) => new Promise((l, c, s) => (i = o.call(n, i), s = i.done, Promise.resolve(i.value).then((d) => l({ value: d, done: s }), c)))), e("next"), e("return"), r);
|
|
26
|
+
import { domError as a, toChunks as D } from "./WorkspaceFileAdapter.mjs";
|
|
27
|
+
import { throwIfAborted as w } from "../errors.mjs";
|
|
28
|
+
import { splitPath as h } from "../security/pathPolicy.mjs";
|
|
29
|
+
function k() {
|
|
30
|
+
return {
|
|
31
|
+
kind: "directory",
|
|
32
|
+
children: /* @__PURE__ */ new Map()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
class A {
|
|
36
|
+
constructor(r, e) {
|
|
37
|
+
m(this, "root", k());
|
|
38
|
+
var t;
|
|
39
|
+
this.displayName = e;
|
|
40
|
+
for (const o of r) {
|
|
41
|
+
const i = E(o, e);
|
|
42
|
+
i && this.writeNode(i, o.blob, (t = o.lastModified) != null ? t : Date.now());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
writeNode(r, e, t) {
|
|
46
|
+
const o = r.split("/").filter(Boolean), i = o.pop();
|
|
47
|
+
if (!i)
|
|
48
|
+
return;
|
|
49
|
+
this.resolveDirectory(o, !0).children.set(i, {
|
|
50
|
+
kind: "file",
|
|
51
|
+
blob: e,
|
|
52
|
+
lastModified: t
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
resolveDirectory(r, e = !1) {
|
|
56
|
+
let t = this.root;
|
|
57
|
+
for (const o of r) {
|
|
58
|
+
let i = t.children.get(o);
|
|
59
|
+
if (!i) {
|
|
60
|
+
if (!e)
|
|
61
|
+
throw a("NotFoundError");
|
|
62
|
+
i = k(), t.children.set(o, i);
|
|
63
|
+
}
|
|
64
|
+
if (i.kind !== "directory")
|
|
65
|
+
throw a("TypeMismatchError");
|
|
66
|
+
t = i;
|
|
67
|
+
}
|
|
68
|
+
return t;
|
|
69
|
+
}
|
|
70
|
+
resolveNode(r) {
|
|
71
|
+
const e = h(r), t = e.pop();
|
|
72
|
+
if (t === void 0)
|
|
73
|
+
return this.root;
|
|
74
|
+
const o = this.resolveDirectory(e).children.get(t);
|
|
75
|
+
if (!o)
|
|
76
|
+
throw a("NotFoundError");
|
|
77
|
+
return o;
|
|
78
|
+
}
|
|
79
|
+
stat(r) {
|
|
80
|
+
return f(this, null, function* () {
|
|
81
|
+
var o;
|
|
82
|
+
const e = this.resolveNode(r), t = (o = h(r).pop()) != null ? o : this.displayName;
|
|
83
|
+
return e.kind === "directory" ? {
|
|
84
|
+
name: t,
|
|
85
|
+
kind: "directory"
|
|
86
|
+
} : {
|
|
87
|
+
name: t,
|
|
88
|
+
kind: "file",
|
|
89
|
+
size: e.blob.size,
|
|
90
|
+
lastModified: e.lastModified
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
listEntries(r, e) {
|
|
95
|
+
return f(this, null, function* () {
|
|
96
|
+
w(e);
|
|
97
|
+
const t = this.resolveDirectory(h(r));
|
|
98
|
+
return Array.from(t.children.entries()).map(([o, i]) => i.kind === "directory" ? {
|
|
99
|
+
name: o,
|
|
100
|
+
kind: "directory"
|
|
101
|
+
} : {
|
|
102
|
+
name: o,
|
|
103
|
+
kind: "file",
|
|
104
|
+
size: i.blob.size,
|
|
105
|
+
lastModified: i.lastModified
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
readFile(r) {
|
|
110
|
+
return f(this, null, function* () {
|
|
111
|
+
const e = this.resolveNode(r);
|
|
112
|
+
if (e.kind !== "file")
|
|
113
|
+
throw a("TypeMismatchError");
|
|
114
|
+
return e.blob;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/** 只更新内存中的快照,不会写回用户磁盘。 */
|
|
118
|
+
writeFile(o, i) {
|
|
119
|
+
return f(this, arguments, function* (r, e, t = {}) {
|
|
120
|
+
const l = h(r), c = l.pop();
|
|
121
|
+
if (!c)
|
|
122
|
+
throw a("TypeMismatchError");
|
|
123
|
+
const s = this.resolveDirectory(l, t.createDirectories), d = s.children.get(c);
|
|
124
|
+
if ((d == null ? void 0 : d.kind) === "directory")
|
|
125
|
+
throw a("TypeMismatchError");
|
|
126
|
+
const p = [];
|
|
127
|
+
try {
|
|
128
|
+
for (var B = u(D(e)), C, I, R; C = !(I = yield B.next()).done; C = !1) {
|
|
129
|
+
const v = I.value;
|
|
130
|
+
w(t.signal), p.push(v);
|
|
131
|
+
}
|
|
132
|
+
} catch (I) {
|
|
133
|
+
R = [I];
|
|
134
|
+
} finally {
|
|
135
|
+
try {
|
|
136
|
+
C && (I = B.return) && (yield I.call(B));
|
|
137
|
+
} finally {
|
|
138
|
+
if (R)
|
|
139
|
+
throw R[0];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const b = new Blob(p);
|
|
143
|
+
s.children.set(c, {
|
|
144
|
+
kind: "file",
|
|
145
|
+
blob: b,
|
|
146
|
+
lastModified: Date.now()
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function E(n, r) {
|
|
152
|
+
const e = (n.webkitRelativePath || n.name).replace(/\\/g, "/").replace(/^\/+/, "");
|
|
153
|
+
if (!e)
|
|
154
|
+
return "";
|
|
155
|
+
const t = `${r}/`;
|
|
156
|
+
return e.startsWith(t) ? e.slice(t.length) : e;
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
A as FileSnapshotAdapter
|
|
160
|
+
};
|
|
@@ -1,174 +1,246 @@
|
|
|
1
|
-
var g = (
|
|
2
|
-
if (
|
|
3
|
-
return
|
|
4
|
-
throw Error("Symbol." +
|
|
1
|
+
var g = (o, t) => {
|
|
2
|
+
if (t = Symbol[o])
|
|
3
|
+
return t;
|
|
4
|
+
throw Error("Symbol." + o + " is not defined");
|
|
5
5
|
};
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var w = (o, t, r) => new Promise((e, a) => {
|
|
7
|
+
var c = (i) => {
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
} catch (
|
|
11
|
-
a(
|
|
9
|
+
s(r.next(i));
|
|
10
|
+
} catch (n) {
|
|
11
|
+
a(n);
|
|
12
12
|
}
|
|
13
|
-
},
|
|
13
|
+
}, d = (i) => {
|
|
14
14
|
try {
|
|
15
|
-
|
|
16
|
-
} catch (
|
|
17
|
-
a(
|
|
15
|
+
s(r.throw(i));
|
|
16
|
+
} catch (n) {
|
|
17
|
+
a(n);
|
|
18
18
|
}
|
|
19
|
-
},
|
|
20
|
-
|
|
19
|
+
}, s = (i) => i.done ? e(i.value) : Promise.resolve(i.value).then(c, d);
|
|
20
|
+
s((r = r.apply(o, t)).next());
|
|
21
21
|
});
|
|
22
|
-
var
|
|
23
|
-
import { domError as
|
|
24
|
-
import { throwIfAborted as
|
|
25
|
-
import { splitPath as
|
|
26
|
-
function
|
|
27
|
-
return !!
|
|
22
|
+
var v = (o, t, r) => (t = o[g("asyncIterator")]) ? t.call(o) : (o = o[g("iterator")](), t = {}, r = (e, a) => (a = o[e]) && (t[e] = (c) => new Promise((d, s, i) => (c = a.call(o, c), i = c.done, Promise.resolve(c.value).then((n) => d({ value: n, done: i }), s)))), r("next"), r("return"), t);
|
|
23
|
+
import { domError as u, toChunks as F, isSameOrInside as H } from "./WorkspaceFileAdapter.mjs";
|
|
24
|
+
import { throwIfAborted as p } from "../errors.mjs";
|
|
25
|
+
import { splitPath as h } from "../security/pathPolicy.mjs";
|
|
26
|
+
function m(o, t) {
|
|
27
|
+
return !!o && typeof o == "object" && o.name === t;
|
|
28
28
|
}
|
|
29
|
-
class
|
|
30
|
-
constructor(
|
|
31
|
-
this.root =
|
|
29
|
+
class b {
|
|
30
|
+
constructor(t) {
|
|
31
|
+
this.root = t;
|
|
32
32
|
}
|
|
33
33
|
get displayName() {
|
|
34
34
|
return this.root.name;
|
|
35
35
|
}
|
|
36
|
-
resolveDirectory(
|
|
37
|
-
return
|
|
38
|
-
let
|
|
39
|
-
for (const a of
|
|
40
|
-
|
|
36
|
+
resolveDirectory(t, r = !1) {
|
|
37
|
+
return w(this, null, function* () {
|
|
38
|
+
let e = this.root;
|
|
39
|
+
for (const a of t)
|
|
40
|
+
e = yield e.getDirectoryHandle(a, {
|
|
41
41
|
create: r
|
|
42
42
|
});
|
|
43
|
-
return
|
|
43
|
+
return e;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
resolveFile(
|
|
47
|
-
return
|
|
48
|
-
const r =
|
|
49
|
-
if (!
|
|
50
|
-
throw
|
|
51
|
-
return (yield this.resolveDirectory(r)).getFileHandle(
|
|
46
|
+
resolveFile(t) {
|
|
47
|
+
return w(this, null, function* () {
|
|
48
|
+
const r = h(t), e = r.pop();
|
|
49
|
+
if (!e)
|
|
50
|
+
throw u("TypeMismatchError");
|
|
51
|
+
return (yield this.resolveDirectory(r)).getFileHandle(e);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
stat(
|
|
55
|
-
return
|
|
56
|
-
const r =
|
|
57
|
-
if (!
|
|
54
|
+
stat(t) {
|
|
55
|
+
return w(this, null, function* () {
|
|
56
|
+
const r = h(t), e = r.pop();
|
|
57
|
+
if (!e)
|
|
58
58
|
return {
|
|
59
59
|
name: this.root.name,
|
|
60
60
|
kind: "directory"
|
|
61
61
|
};
|
|
62
62
|
const a = yield this.resolveDirectory(r);
|
|
63
63
|
try {
|
|
64
|
-
const
|
|
64
|
+
const c = yield (yield a.getFileHandle(e)).getFile();
|
|
65
65
|
return {
|
|
66
|
-
name:
|
|
66
|
+
name: e,
|
|
67
67
|
kind: "file",
|
|
68
|
-
size:
|
|
69
|
-
lastModified:
|
|
68
|
+
size: c.size,
|
|
69
|
+
lastModified: c.lastModified
|
|
70
70
|
};
|
|
71
|
-
} catch (
|
|
72
|
-
if (!
|
|
73
|
-
throw
|
|
74
|
-
return yield a.getDirectoryHandle(
|
|
75
|
-
name:
|
|
71
|
+
} catch (c) {
|
|
72
|
+
if (!m(c, "TypeMismatchError"))
|
|
73
|
+
throw c;
|
|
74
|
+
return yield a.getDirectoryHandle(e), {
|
|
75
|
+
name: e,
|
|
76
76
|
kind: "directory"
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
-
listEntries(
|
|
82
|
-
return
|
|
83
|
-
const
|
|
81
|
+
listEntries(t, r) {
|
|
82
|
+
return w(this, null, function* () {
|
|
83
|
+
const e = yield this.resolveDirectory(h(t)), a = [];
|
|
84
84
|
try {
|
|
85
|
-
for (var
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
else
|
|
93
|
-
try {
|
|
94
|
-
const l = yield s.getFile();
|
|
95
|
-
a.push({
|
|
96
|
-
name: s.name,
|
|
97
|
-
kind: "file",
|
|
98
|
-
size: l.size,
|
|
99
|
-
lastModified: l.lastModified
|
|
100
|
-
});
|
|
101
|
-
} catch (l) {
|
|
102
|
-
if (p(l, "NotAllowedError"))
|
|
103
|
-
throw l;
|
|
104
|
-
a.push({
|
|
105
|
-
name: s.name,
|
|
106
|
-
kind: "file"
|
|
107
|
-
});
|
|
108
|
-
}
|
|
85
|
+
for (var c = v(e.values()), d, s, i; d = !(s = yield c.next()).done; d = !1) {
|
|
86
|
+
const n = s.value;
|
|
87
|
+
p(r), a.push({
|
|
88
|
+
name: n.name,
|
|
89
|
+
kind: n.kind === "directory" ? "directory" : "file"
|
|
90
|
+
});
|
|
109
91
|
}
|
|
110
|
-
} catch (
|
|
111
|
-
|
|
92
|
+
} catch (s) {
|
|
93
|
+
i = [s];
|
|
112
94
|
} finally {
|
|
113
95
|
try {
|
|
114
|
-
|
|
96
|
+
d && (s = c.return) && (yield s.call(c));
|
|
115
97
|
} finally {
|
|
116
|
-
if (
|
|
117
|
-
throw
|
|
98
|
+
if (i)
|
|
99
|
+
throw i[0];
|
|
118
100
|
}
|
|
119
101
|
}
|
|
120
102
|
return a;
|
|
121
103
|
});
|
|
122
104
|
}
|
|
123
|
-
readFile(
|
|
124
|
-
return
|
|
125
|
-
return (yield this.resolveFile(
|
|
105
|
+
readFile(t) {
|
|
106
|
+
return w(this, null, function* () {
|
|
107
|
+
return (yield this.resolveFile(t)).getFile();
|
|
126
108
|
});
|
|
127
109
|
}
|
|
128
|
-
writeFile(a,
|
|
129
|
-
return
|
|
130
|
-
const
|
|
131
|
-
if (!
|
|
132
|
-
throw
|
|
133
|
-
const
|
|
134
|
-
let
|
|
110
|
+
writeFile(a, c) {
|
|
111
|
+
return w(this, arguments, function* (t, r, e = {}) {
|
|
112
|
+
const d = h(t), s = d.pop();
|
|
113
|
+
if (!s)
|
|
114
|
+
throw u("TypeMismatchError");
|
|
115
|
+
const i = yield this.resolveDirectory(d, e.createDirectories);
|
|
116
|
+
let n = !0;
|
|
135
117
|
try {
|
|
136
|
-
yield
|
|
137
|
-
} catch (
|
|
138
|
-
if (!
|
|
139
|
-
throw
|
|
140
|
-
|
|
118
|
+
yield i.getFileHandle(s);
|
|
119
|
+
} catch (f) {
|
|
120
|
+
if (!m(f, "NotFoundError"))
|
|
121
|
+
throw f;
|
|
122
|
+
n = !1;
|
|
141
123
|
}
|
|
142
|
-
const
|
|
124
|
+
const y = yield i.getFileHandle(s, {
|
|
143
125
|
create: !0
|
|
144
126
|
});
|
|
145
|
-
let
|
|
127
|
+
let l;
|
|
146
128
|
try {
|
|
147
|
-
|
|
129
|
+
l = yield y.createWritable();
|
|
148
130
|
try {
|
|
149
|
-
for (var
|
|
150
|
-
const
|
|
151
|
-
|
|
131
|
+
for (var A = v(F(r)), S, z, W; S = !(z = yield A.next()).done; S = !1) {
|
|
132
|
+
const f = z.value;
|
|
133
|
+
p(e.signal), yield l.write(f);
|
|
152
134
|
}
|
|
153
|
-
} catch (
|
|
154
|
-
|
|
135
|
+
} catch (z) {
|
|
136
|
+
W = [z];
|
|
155
137
|
} finally {
|
|
156
138
|
try {
|
|
157
|
-
|
|
139
|
+
S && (z = A.return) && (yield z.call(A));
|
|
158
140
|
} finally {
|
|
159
|
-
if (
|
|
160
|
-
throw
|
|
141
|
+
if (W)
|
|
142
|
+
throw W[0];
|
|
161
143
|
}
|
|
162
144
|
}
|
|
163
|
-
|
|
164
|
-
} catch (
|
|
165
|
-
throw yield
|
|
166
|
-
}),
|
|
167
|
-
})),
|
|
145
|
+
p(e.signal), yield l.close();
|
|
146
|
+
} catch (f) {
|
|
147
|
+
throw yield l == null ? void 0 : l.abort().catch(() => {
|
|
148
|
+
}), n || (yield i.removeEntry(s).catch(() => {
|
|
149
|
+
})), f;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
createDirectory(t) {
|
|
154
|
+
return w(this, null, function* () {
|
|
155
|
+
yield this.resolveDirectory(h(t), !0);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
remove(e) {
|
|
159
|
+
return w(this, arguments, function* (t, r = {}) {
|
|
160
|
+
const a = h(t), c = a.pop();
|
|
161
|
+
if (!c)
|
|
162
|
+
throw u("InvalidModificationError");
|
|
163
|
+
yield (yield this.resolveDirectory(a)).removeEntry(c, {
|
|
164
|
+
recursive: r.recursive === !0
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
move(t, r) {
|
|
169
|
+
return w(this, null, function* () {
|
|
170
|
+
const e = h(t), a = h(r), c = e.pop(), d = a.pop();
|
|
171
|
+
if (!c || !d)
|
|
172
|
+
throw u("InvalidModificationError");
|
|
173
|
+
const s = yield this.resolveDirectory(e), i = yield E(s, c), n = yield this.resolveDirectory(a);
|
|
174
|
+
if (H(t, r))
|
|
175
|
+
throw u("InvalidModificationError");
|
|
176
|
+
let y;
|
|
177
|
+
try {
|
|
178
|
+
y = yield E(n, d);
|
|
179
|
+
} catch (l) {
|
|
180
|
+
if (!m(l, "NotFoundError"))
|
|
181
|
+
throw l;
|
|
168
182
|
}
|
|
183
|
+
if (y && (y.kind === "directory" || i.kind === "directory"))
|
|
184
|
+
throw u("InvalidModificationError");
|
|
185
|
+
if (!y && typeof i.move == "function")
|
|
186
|
+
try {
|
|
187
|
+
yield i.move(n, d);
|
|
188
|
+
return;
|
|
189
|
+
} catch (l) {
|
|
190
|
+
if (!m(l, "NotSupportedError") && !(l instanceof TypeError))
|
|
191
|
+
throw l;
|
|
192
|
+
}
|
|
193
|
+
yield D(i, n, d), yield s.removeEntry(c, {
|
|
194
|
+
recursive: !0
|
|
195
|
+
});
|
|
169
196
|
});
|
|
170
197
|
}
|
|
171
198
|
}
|
|
199
|
+
function E(o, t) {
|
|
200
|
+
return w(this, null, function* () {
|
|
201
|
+
try {
|
|
202
|
+
return yield o.getFileHandle(t);
|
|
203
|
+
} catch (r) {
|
|
204
|
+
if (!m(r, "TypeMismatchError"))
|
|
205
|
+
throw r;
|
|
206
|
+
return o.getDirectoryHandle(t);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function D(o, t, r) {
|
|
211
|
+
return w(this, null, function* () {
|
|
212
|
+
if (o.kind === "file") {
|
|
213
|
+
const i = yield o.getFile(), n = yield (yield t.getFileHandle(r, {
|
|
214
|
+
create: !0
|
|
215
|
+
})).createWritable();
|
|
216
|
+
try {
|
|
217
|
+
yield n.write(i), yield n.close();
|
|
218
|
+
} catch (y) {
|
|
219
|
+
throw yield n.abort().catch(() => {
|
|
220
|
+
}), y;
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const e = yield t.getDirectoryHandle(r, {
|
|
225
|
+
create: !0
|
|
226
|
+
});
|
|
227
|
+
try {
|
|
228
|
+
for (var a = v(o.values()), c, d, s; c = !(d = yield a.next()).done; c = !1) {
|
|
229
|
+
const i = d.value;
|
|
230
|
+
yield D(i, e, i.name);
|
|
231
|
+
}
|
|
232
|
+
} catch (d) {
|
|
233
|
+
s = [d];
|
|
234
|
+
} finally {
|
|
235
|
+
try {
|
|
236
|
+
c && (d = a.return) && (yield d.call(a));
|
|
237
|
+
} finally {
|
|
238
|
+
if (s)
|
|
239
|
+
throw s[0];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
172
244
|
export {
|
|
173
|
-
|
|
245
|
+
b as FileSystemAccessAdapter
|
|
174
246
|
};
|