@glodon-aiot/bot-client-sdk 3.25.1-alpha.6 → 3.26.0-alpha.4
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 +543 -98
- package/dist/es/AgentSession.mjs +230 -165
- package/dist/es/BotClient.mjs +186 -136
- package/dist/es/Config.mjs +111 -26
- package/dist/es/Session.mjs +12 -0
- package/dist/es/api/index.mjs +42 -33
- package/dist/es/index.mjs +68 -9
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +174 -0
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +172 -0
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +162 -0
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +50 -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/createLocalPythonPlugin.mjs +196 -0
- package/dist/es/localFiles/errors.mjs +57 -0
- package/dist/es/localFiles/host/connectHostBridge.mjs +50 -0
- package/dist/es/localFiles/host/protocol.mjs +26 -0
- package/dist/es/localFiles/limits.mjs +22 -0
- package/dist/es/localFiles/schemas.mjs +327 -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 +339 -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 +7 -4
- package/dist/lib/index.js +9 -4
- 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/index.d.ts +4 -2
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +17 -0
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +24 -0
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +18 -0
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +26 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +39 -0
- package/dist/src/localFiles/constants.d.ts +50 -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 +33 -0
- package/dist/src/localFiles/index.d.ts +21 -0
- package/dist/src/localFiles/limits.d.ts +3 -0
- package/dist/src/localFiles/schemas.d.ts +30 -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 +306 -0
- package/dist/src/localFiles/validate.d.ts +2 -0
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +99 -0
- package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
- package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
- package/package.json +7 -4
package/dist/es/api/index.mjs
CHANGED
|
@@ -1,41 +1,50 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
|
|
1
|
+
var g = Object.defineProperty, d = Object.defineProperties;
|
|
2
|
+
var E = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var u = Object.getOwnPropertySymbols;
|
|
4
|
+
var x = Object.prototype.hasOwnProperty, v = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var f = (t, e, r) => e in t ? g(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, m = (t, e) => {
|
|
6
|
+
for (var r in e || (e = {}))
|
|
7
|
+
x.call(e, r) && f(t, r, e[r]);
|
|
8
|
+
if (u)
|
|
9
|
+
for (var r of u(e))
|
|
10
|
+
v.call(e, r) && f(t, r, e[r]);
|
|
11
11
|
return t;
|
|
12
|
-
},
|
|
13
|
-
import
|
|
12
|
+
}, h = (t, e) => d(t, E(e));
|
|
13
|
+
import I from "axios";
|
|
14
14
|
import { isExpired as $ } from "../utils.mjs";
|
|
15
|
-
import { CVForceApi as
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
import { CVForceApi as w, AIShopApi as z } from "@glodon-aiot/apis";
|
|
16
|
+
function b(t, e, r) {
|
|
17
|
+
return new w(A(t, "/data/v1", e, r), S(r));
|
|
18
|
+
}
|
|
19
|
+
function B(t, e, r) {
|
|
20
|
+
return new z(A(t, "/aishop", e, r), S(r));
|
|
21
|
+
}
|
|
22
|
+
function A(t, e, r, o) {
|
|
23
|
+
const i = (n) => {
|
|
24
|
+
var s;
|
|
25
|
+
return r && ($(r) && o(403, "aiotToken is timeout"), n.headers = (s = n.headers) != null ? s : {}, n.headers = h(m({}, n.headers), {
|
|
26
|
+
Authorization: r ? `Bearer ${r}` : ""
|
|
27
|
+
})), n;
|
|
22
28
|
};
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
baseURL:
|
|
29
|
+
function a(n, s = !0) {
|
|
30
|
+
const c = `${t}${n}`, p = I.create({
|
|
31
|
+
baseURL: c
|
|
26
32
|
});
|
|
27
|
-
return
|
|
33
|
+
return s && p.interceptors.request.use(i), p;
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
onAppStatusError:
|
|
37
|
-
|
|
35
|
+
return a(e);
|
|
36
|
+
}
|
|
37
|
+
function S(t) {
|
|
38
|
+
return {
|
|
39
|
+
onHttpStatusError: (o, i) => {
|
|
40
|
+
o === 401 && t(o, "aiotToken is invalid");
|
|
41
|
+
},
|
|
42
|
+
onAppStatusError: (o, i) => {
|
|
43
|
+
o !== 10001 && o !== 10215 && t(o, i);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
38
46
|
}
|
|
39
47
|
export {
|
|
40
|
-
|
|
48
|
+
B as getAIShopService,
|
|
49
|
+
b as getCVForceService
|
|
41
50
|
};
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,11 +1,70 @@
|
|
|
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 t } from "./AgentPlugin.mjs";
|
|
5
|
+
import { ToolCode as l, ToolError as D, toToolError as R } from "./localFiles/errors.mjs";
|
|
6
|
+
import { BUILTIN_TOOL_SCHEMAS as a, LOCAL_FILE_TOOL_SCHEMAS as U, LOCAL_PYTHON_TOOL_SCHEMA as M } from "./localFiles/schemas.mjs";
|
|
7
|
+
import { createLocalFilesPlugin as i } from "./localFiles/createLocalFilesPlugin.mjs";
|
|
8
|
+
import { LocalWorkspace as P } from "./localFiles/workspace/LocalWorkspace.mjs";
|
|
9
|
+
import { createIndexedDbStore as H, createMemoryStore as m } from "./localFiles/workspace/handleStore.mjs";
|
|
10
|
+
import { FileSystemAccessAdapter as d } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
|
|
11
|
+
import { MemoryWorkspaceAdapter as c } from "./localFiles/adapters/MemoryWorkspaceAdapter.mjs";
|
|
12
|
+
import { createDefaultSessionFileTransfer as X } from "./localFiles/transfer/SessionFileTransfer.mjs";
|
|
13
|
+
import { getDownloadUrlAllowlist as B, isDownloadUrlAllowed as Y } from "./localFiles/security/downloadUrlPolicy.mjs";
|
|
14
|
+
import { SDK_SENSITIVE_BASELINE as W } from "./localFiles/security/sensitiveFiles.mjs";
|
|
15
|
+
import { BINARY_SNIFF_BYTES as y, BUILTIN_TOOLS_PLUGIN_CODE as K, BUILTIN_TOOLS_PLUGIN_CODES as k, DEFAULT_DOWNLOAD_URL_ALLOWLIST as b, DEFAULT_IGNORED_DIRECTORIES as h, DEFAULT_IGNORED_FILE_PATTERNS as v, DEFAULT_LIMITS as V, KiB as Z, LIST_DIRECTORY_DEFAULT_LIMIT as j, LIST_DIRECTORY_MAX_LIMIT as q, LOCAL_FILES_FUNCTION_CODES as z, LOCAL_FILES_PLUGIN_CODES as J, LOCAL_PYTHON_FUNCTION_CODE as Q, LOCAL_PYTHON_PLUGIN_CODES as $, MiB as __, PYTHON_DEFAULT_TIMEOUT_MS as o_, PYTHON_MAX_ARGS as e_, PYTHON_MAX_TIMEOUT_MS as T_, SEARCH_DEFAULT_DEPTH as E_, SEARCH_FUNCTION_CODES as r_, SEARCH_MAX_DEPTH as L_, TEXT_SEARCH_MAX_CONTEXT_LINES as I_, TEXT_SEARCH_MAX_FILES as S_, TEXT_SEARCH_MAX_FILE_BYTES as A_, TEXT_SEARCH_MAX_LINE_CHARS as O_, TRANSFER_FILE_SIZE_LIMIT_MB as C_, TRANSFER_FUNCTION_CODES as t_, WORKSPACE_GRANT_ID as N_, WRITE_FUNCTION_CODES as l_ } from "./localFiles/constants.mjs";
|
|
5
16
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
t as AgentPlugin,
|
|
18
|
+
y as BINARY_SNIFF_BYTES,
|
|
19
|
+
K as BUILTIN_TOOLS_PLUGIN_CODE,
|
|
20
|
+
k as BUILTIN_TOOLS_PLUGIN_CODES,
|
|
21
|
+
a as BUILTIN_TOOL_SCHEMAS,
|
|
22
|
+
S as BotClient,
|
|
23
|
+
b as DEFAULT_DOWNLOAD_URL_ALLOWLIST,
|
|
24
|
+
h as DEFAULT_IGNORED_DIRECTORIES,
|
|
25
|
+
v as DEFAULT_IGNORED_FILE_PATTERNS,
|
|
26
|
+
V as DEFAULT_LIMITS,
|
|
27
|
+
d as FileSystemAccessAdapter,
|
|
28
|
+
Z as KiB,
|
|
29
|
+
j as LIST_DIRECTORY_DEFAULT_LIMIT,
|
|
30
|
+
q as LIST_DIRECTORY_MAX_LIMIT,
|
|
31
|
+
z as LOCAL_FILES_FUNCTION_CODES,
|
|
32
|
+
J as LOCAL_FILES_PLUGIN_CODES,
|
|
33
|
+
U as LOCAL_FILE_TOOL_SCHEMAS,
|
|
34
|
+
Q as LOCAL_PYTHON_FUNCTION_CODE,
|
|
35
|
+
$ as LOCAL_PYTHON_PLUGIN_CODES,
|
|
36
|
+
M as LOCAL_PYTHON_TOOL_SCHEMA,
|
|
37
|
+
P as LocalWorkspace,
|
|
38
|
+
c as MemoryWorkspaceAdapter,
|
|
39
|
+
__ as MiB,
|
|
40
|
+
o_ as PYTHON_DEFAULT_TIMEOUT_MS,
|
|
41
|
+
e_ as PYTHON_MAX_ARGS,
|
|
42
|
+
T_ as PYTHON_MAX_TIMEOUT_MS,
|
|
43
|
+
W as SDK_SENSITIVE_BASELINE,
|
|
44
|
+
E_ as SEARCH_DEFAULT_DEPTH,
|
|
45
|
+
r_ as SEARCH_FUNCTION_CODES,
|
|
46
|
+
L_ as SEARCH_MAX_DEPTH,
|
|
47
|
+
O as Session,
|
|
48
|
+
I_ as TEXT_SEARCH_MAX_CONTEXT_LINES,
|
|
49
|
+
S_ as TEXT_SEARCH_MAX_FILES,
|
|
50
|
+
A_ as TEXT_SEARCH_MAX_FILE_BYTES,
|
|
51
|
+
O_ as TEXT_SEARCH_MAX_LINE_CHARS,
|
|
52
|
+
C_ as TRANSFER_FILE_SIZE_LIMIT_MB,
|
|
53
|
+
t_ as TRANSFER_FUNCTION_CODES,
|
|
54
|
+
l as ToolCode,
|
|
55
|
+
D as ToolError,
|
|
56
|
+
N_ as WORKSPACE_GRANT_ID,
|
|
57
|
+
l_ as WRITE_FUNCTION_CODES,
|
|
58
|
+
e as configuration,
|
|
59
|
+
T as configure,
|
|
60
|
+
X as createDefaultSessionFileTransfer,
|
|
61
|
+
H as createIndexedDbStore,
|
|
62
|
+
i as createLocalFilesPlugin,
|
|
63
|
+
m as createMemoryStore,
|
|
64
|
+
B as getDownloadUrlAllowlist,
|
|
65
|
+
E as getRegisteredLocalFilesPluginCode,
|
|
66
|
+
r as getRegisteredLocalPythonPluginCode,
|
|
67
|
+
Y as isDownloadUrlAllowed,
|
|
68
|
+
L as resolveLocalFilesPluginCode,
|
|
69
|
+
R as toToolError
|
|
11
70
|
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var g = (i, e) => {
|
|
2
|
+
if (e = Symbol[i])
|
|
3
|
+
return e;
|
|
4
|
+
throw Error("Symbol." + i + " is not defined");
|
|
5
|
+
};
|
|
6
|
+
var d = (i, e, r) => new Promise((t, a) => {
|
|
7
|
+
var n = (o) => {
|
|
8
|
+
try {
|
|
9
|
+
c(r.next(o));
|
|
10
|
+
} catch (s) {
|
|
11
|
+
a(s);
|
|
12
|
+
}
|
|
13
|
+
}, h = (o) => {
|
|
14
|
+
try {
|
|
15
|
+
c(r.throw(o));
|
|
16
|
+
} catch (s) {
|
|
17
|
+
a(s);
|
|
18
|
+
}
|
|
19
|
+
}, c = (o) => o.done ? t(o.value) : Promise.resolve(o.value).then(n, h);
|
|
20
|
+
c((r = r.apply(i, e)).next());
|
|
21
|
+
});
|
|
22
|
+
var y = (i, e, r) => (e = i[g("asyncIterator")]) ? e.call(i) : (i = i[g("iterator")](), e = {}, r = (t, a) => (a = i[t]) && (e[t] = (n) => new Promise((h, c, o) => (n = a.call(i, n), o = n.done, Promise.resolve(n.value).then((s) => h({ value: s, done: o }), c)))), r("next"), r("return"), e);
|
|
23
|
+
import { domError as F, toChunks as v } from "./WorkspaceFileAdapter.mjs";
|
|
24
|
+
import { throwIfAborted as u } from "../errors.mjs";
|
|
25
|
+
import { splitPath as w } from "../security/pathPolicy.mjs";
|
|
26
|
+
function p(i, e) {
|
|
27
|
+
return !!i && typeof i == "object" && i.name === e;
|
|
28
|
+
}
|
|
29
|
+
class H {
|
|
30
|
+
constructor(e) {
|
|
31
|
+
this.root = e;
|
|
32
|
+
}
|
|
33
|
+
get displayName() {
|
|
34
|
+
return this.root.name;
|
|
35
|
+
}
|
|
36
|
+
resolveDirectory(e, r = !1) {
|
|
37
|
+
return d(this, null, function* () {
|
|
38
|
+
let t = this.root;
|
|
39
|
+
for (const a of e)
|
|
40
|
+
t = yield t.getDirectoryHandle(a, {
|
|
41
|
+
create: r
|
|
42
|
+
});
|
|
43
|
+
return t;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
resolveFile(e) {
|
|
47
|
+
return d(this, null, function* () {
|
|
48
|
+
const r = w(e), t = r.pop();
|
|
49
|
+
if (!t)
|
|
50
|
+
throw F("TypeMismatchError");
|
|
51
|
+
return (yield this.resolveDirectory(r)).getFileHandle(t);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
stat(e) {
|
|
55
|
+
return d(this, null, function* () {
|
|
56
|
+
const r = w(e), t = r.pop();
|
|
57
|
+
if (!t)
|
|
58
|
+
return {
|
|
59
|
+
name: this.root.name,
|
|
60
|
+
kind: "directory"
|
|
61
|
+
};
|
|
62
|
+
const a = yield this.resolveDirectory(r);
|
|
63
|
+
try {
|
|
64
|
+
const n = yield (yield a.getFileHandle(t)).getFile();
|
|
65
|
+
return {
|
|
66
|
+
name: t,
|
|
67
|
+
kind: "file",
|
|
68
|
+
size: n.size,
|
|
69
|
+
lastModified: n.lastModified
|
|
70
|
+
};
|
|
71
|
+
} catch (n) {
|
|
72
|
+
if (!p(n, "TypeMismatchError"))
|
|
73
|
+
throw n;
|
|
74
|
+
return yield a.getDirectoryHandle(t), {
|
|
75
|
+
name: t,
|
|
76
|
+
kind: "directory"
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
listEntries(e, r) {
|
|
82
|
+
return d(this, null, function* () {
|
|
83
|
+
const t = yield this.resolveDirectory(w(e)), a = [];
|
|
84
|
+
try {
|
|
85
|
+
for (var n = y(t.values()), h, c, o; h = !(c = yield n.next()).done; h = !1) {
|
|
86
|
+
const s = c.value;
|
|
87
|
+
if (u(r), s.kind === "directory")
|
|
88
|
+
a.push({
|
|
89
|
+
name: s.name,
|
|
90
|
+
kind: "directory"
|
|
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
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch (c) {
|
|
111
|
+
o = [c];
|
|
112
|
+
} finally {
|
|
113
|
+
try {
|
|
114
|
+
h && (c = n.return) && (yield c.call(n));
|
|
115
|
+
} finally {
|
|
116
|
+
if (o)
|
|
117
|
+
throw o[0];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return a;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
readFile(e) {
|
|
124
|
+
return d(this, null, function* () {
|
|
125
|
+
return (yield this.resolveFile(e)).getFile();
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
writeFile(a, n) {
|
|
129
|
+
return d(this, arguments, function* (e, r, t = {}) {
|
|
130
|
+
const h = w(e), c = h.pop();
|
|
131
|
+
if (!c)
|
|
132
|
+
throw F("TypeMismatchError");
|
|
133
|
+
const o = yield this.resolveDirectory(h, t.createDirectories);
|
|
134
|
+
let s = !0;
|
|
135
|
+
try {
|
|
136
|
+
yield o.getFileHandle(c);
|
|
137
|
+
} catch (m) {
|
|
138
|
+
if (!p(m, "NotFoundError"))
|
|
139
|
+
throw m;
|
|
140
|
+
s = !1;
|
|
141
|
+
}
|
|
142
|
+
const l = yield o.getFileHandle(c, {
|
|
143
|
+
create: !0
|
|
144
|
+
});
|
|
145
|
+
let f;
|
|
146
|
+
try {
|
|
147
|
+
f = yield l.createWritable();
|
|
148
|
+
try {
|
|
149
|
+
for (var N = y(v(r)), b, T, x; b = !(T = yield N.next()).done; b = !1) {
|
|
150
|
+
const m = T.value;
|
|
151
|
+
u(t.signal), yield f.write(m);
|
|
152
|
+
}
|
|
153
|
+
} catch (T) {
|
|
154
|
+
x = [T];
|
|
155
|
+
} finally {
|
|
156
|
+
try {
|
|
157
|
+
b && (T = N.return) && (yield T.call(N));
|
|
158
|
+
} finally {
|
|
159
|
+
if (x)
|
|
160
|
+
throw x[0];
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
u(t.signal), yield f.close();
|
|
164
|
+
} catch (m) {
|
|
165
|
+
throw yield f == null ? void 0 : f.abort().catch(() => {
|
|
166
|
+
}), s || (yield o.removeEntry(c).catch(() => {
|
|
167
|
+
})), m;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
H as FileSystemAccessAdapter
|
|
174
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var h = Object.getOwnPropertySymbols;
|
|
3
|
+
var N = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var m = (n, t) => {
|
|
5
|
+
if (t = Symbol[n])
|
|
6
|
+
return t;
|
|
7
|
+
throw Error("Symbol." + n + " is not defined");
|
|
8
|
+
};
|
|
9
|
+
var u = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, b = (n, t) => {
|
|
10
|
+
for (var e in t || (t = {}))
|
|
11
|
+
N.call(t, e) && u(n, e, t[e]);
|
|
12
|
+
if (h)
|
|
13
|
+
for (var e of h(t))
|
|
14
|
+
x.call(t, e) && u(n, e, t[e]);
|
|
15
|
+
return n;
|
|
16
|
+
};
|
|
17
|
+
var p = (n, t, e) => (u(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
18
|
+
var y = (n, t, e) => new Promise((r, s) => {
|
|
19
|
+
var o = (i) => {
|
|
20
|
+
try {
|
|
21
|
+
a(e.next(i));
|
|
22
|
+
} catch (d) {
|
|
23
|
+
s(d);
|
|
24
|
+
}
|
|
25
|
+
}, c = (i) => {
|
|
26
|
+
try {
|
|
27
|
+
a(e.throw(i));
|
|
28
|
+
} catch (d) {
|
|
29
|
+
s(d);
|
|
30
|
+
}
|
|
31
|
+
}, a = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(o, c);
|
|
32
|
+
a((e = e.apply(n, t)).next());
|
|
33
|
+
});
|
|
34
|
+
var w = (n, t, e) => (t = n[m("asyncIterator")]) ? t.call(n) : (n = n[m("iterator")](), t = {}, e = (r, s) => (s = n[r]) && (t[r] = (o) => new Promise((c, a, i) => (o = s.call(n, o), i = o.done, Promise.resolve(o.value).then((d) => c({ value: d, done: i }), a)))), e("next"), e("return"), t);
|
|
35
|
+
import { domError as f, toChunks as B } from "./WorkspaceFileAdapter.mjs";
|
|
36
|
+
import { throwIfAborted as A } from "../errors.mjs";
|
|
37
|
+
import { HOST_CHANNEL as M } from "../host/protocol.mjs";
|
|
38
|
+
const k = 3e4;
|
|
39
|
+
function v(n) {
|
|
40
|
+
let t = "";
|
|
41
|
+
for (let r = 0; r < n.length; r += 32768)
|
|
42
|
+
t += String.fromCharCode(...n.subarray(r, r + 32768));
|
|
43
|
+
return btoa(t);
|
|
44
|
+
}
|
|
45
|
+
function O(n) {
|
|
46
|
+
const t = atob(n), 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 E(n, t) {
|
|
52
|
+
const e = n && typeof n == "object" ? n : {}, r = e.kind === "directory" ? "directory" : "file", s = {
|
|
53
|
+
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
54
|
+
kind: r
|
|
55
|
+
};
|
|
56
|
+
return r === "file" && typeof e.size == "number" && (s.size = e.size), typeof e.lastModified == "number" && (s.lastModified = e.lastModified), s;
|
|
57
|
+
}
|
|
58
|
+
class S {
|
|
59
|
+
constructor(t, e = "") {
|
|
60
|
+
p(this, "displayName");
|
|
61
|
+
p(this, "seq", 0);
|
|
62
|
+
p(this, "pending", /* @__PURE__ */ new Map());
|
|
63
|
+
this.view = t, this.displayName = e;
|
|
64
|
+
}
|
|
65
|
+
settle(t) {
|
|
66
|
+
const e = this.pending.get(t.id);
|
|
67
|
+
if (e) {
|
|
68
|
+
if (clearTimeout(e.timer), this.pending.delete(t.id), t.ok === !1) {
|
|
69
|
+
e.reject(f(t.name || "NotAllowedError", t.message || t.name || "NotAllowedError"));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
e.resolve(t);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
call(t, e, r, s = k) {
|
|
76
|
+
A(r);
|
|
77
|
+
const o = `host-${++this.seq}`;
|
|
78
|
+
return new Promise((c, a) => {
|
|
79
|
+
const i = setTimeout(() => {
|
|
80
|
+
this.pending.delete(o), a(f("AbortError"));
|
|
81
|
+
}, s), d = () => {
|
|
82
|
+
clearTimeout(i), this.pending.delete(o), a(f("AbortError"));
|
|
83
|
+
};
|
|
84
|
+
r == null || r.addEventListener("abort", d, {
|
|
85
|
+
once: !0
|
|
86
|
+
}), this.pending.set(o, {
|
|
87
|
+
resolve: (C) => {
|
|
88
|
+
r == null || r.removeEventListener("abort", d), c(C);
|
|
89
|
+
},
|
|
90
|
+
reject: a,
|
|
91
|
+
timer: i
|
|
92
|
+
}), this.view.postMessage(b({
|
|
93
|
+
channel: M,
|
|
94
|
+
id: o,
|
|
95
|
+
op: t
|
|
96
|
+
}, e));
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
stat(t) {
|
|
100
|
+
return y(this, null, function* () {
|
|
101
|
+
const e = yield this.call("stat", {
|
|
102
|
+
path: t
|
|
103
|
+
});
|
|
104
|
+
return E(e.entry, t.split("/").pop() || this.displayName);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
listEntries(t, e) {
|
|
108
|
+
return y(this, null, function* () {
|
|
109
|
+
const r = yield this.call("list", {
|
|
110
|
+
path: t
|
|
111
|
+
}, e);
|
|
112
|
+
return (Array.isArray(r.entries) ? r.entries : []).map((o) => E(o, ""));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
readFile(t) {
|
|
116
|
+
return y(this, null, function* () {
|
|
117
|
+
var s;
|
|
118
|
+
const e = yield this.call("read", {
|
|
119
|
+
path: t
|
|
120
|
+
}), r = O((s = e.contentBase64) != null ? s : "");
|
|
121
|
+
return new Blob([r]);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
runPython(t, e, r, s) {
|
|
125
|
+
return y(this, null, function* () {
|
|
126
|
+
var c, a;
|
|
127
|
+
const o = yield this.call("run_python", {
|
|
128
|
+
path: t,
|
|
129
|
+
args: e,
|
|
130
|
+
timeoutMs: r
|
|
131
|
+
}, s, r + 15e3);
|
|
132
|
+
return {
|
|
133
|
+
exitCode: typeof o.exitCode == "number" ? o.exitCode : 1,
|
|
134
|
+
timedOut: o.timedOut === !0,
|
|
135
|
+
stdout: (c = o.stdout) != null ? c : "",
|
|
136
|
+
stderr: (a = o.stderr) != null ? a : ""
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
writeFile(s, o) {
|
|
141
|
+
return y(this, arguments, function* (t, e, r = {}) {
|
|
142
|
+
const c = [];
|
|
143
|
+
try {
|
|
144
|
+
for (var C = w(B(e)), D, F, I; D = !(F = yield C.next()).done; D = !1) {
|
|
145
|
+
const l = F.value;
|
|
146
|
+
A(r.signal), c.push(l);
|
|
147
|
+
}
|
|
148
|
+
} catch (F) {
|
|
149
|
+
I = [F];
|
|
150
|
+
} finally {
|
|
151
|
+
try {
|
|
152
|
+
D && (F = C.return) && (yield F.call(C));
|
|
153
|
+
} finally {
|
|
154
|
+
if (I)
|
|
155
|
+
throw I[0];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
const a = c.reduce((l, T) => l + T.byteLength, 0), i = new Uint8Array(a);
|
|
159
|
+
let d = 0;
|
|
160
|
+
c.forEach((l) => {
|
|
161
|
+
i.set(l, d), d += l.byteLength;
|
|
162
|
+
}), yield this.call("write", {
|
|
163
|
+
path: t,
|
|
164
|
+
contentBase64: v(i),
|
|
165
|
+
createDirectories: r.createDirectories === !0
|
|
166
|
+
}, r.signal);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
S as HostBridgeAdapter
|
|
172
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var D = Object.defineProperty;
|
|
2
|
+
var g = (s, e) => {
|
|
3
|
+
if (e = Symbol[s])
|
|
4
|
+
return e;
|
|
5
|
+
throw Error("Symbol." + s + " is not defined");
|
|
6
|
+
};
|
|
7
|
+
var b = (s, e, r) => e in s ? D(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
|
|
8
|
+
var E = (s, e, r) => (b(s, typeof e != "symbol" ? e + "" : e, r), r);
|
|
9
|
+
var f = (s, e, r) => new Promise((t, o) => {
|
|
10
|
+
var i = (n) => {
|
|
11
|
+
try {
|
|
12
|
+
d(r.next(n));
|
|
13
|
+
} catch (c) {
|
|
14
|
+
o(c);
|
|
15
|
+
}
|
|
16
|
+
}, a = (n) => {
|
|
17
|
+
try {
|
|
18
|
+
d(r.throw(n));
|
|
19
|
+
} catch (c) {
|
|
20
|
+
o(c);
|
|
21
|
+
}
|
|
22
|
+
}, d = (n) => n.done ? t(n.value) : Promise.resolve(n.value).then(i, a);
|
|
23
|
+
d((r = r.apply(s, e)).next());
|
|
24
|
+
});
|
|
25
|
+
var M = (s, e, r) => (e = s[g("asyncIterator")]) ? e.call(s) : (s = s[g("iterator")](), e = {}, r = (t, o) => (o = s[t]) && (e[t] = (i) => new Promise((a, d, n) => (i = o.call(s, i), n = i.done, Promise.resolve(i.value).then((c) => a({ value: c, done: n }), d)))), r("next"), r("return"), e);
|
|
26
|
+
import { domError as l, toChunks as N } from "./WorkspaceFileAdapter.mjs";
|
|
27
|
+
import { throwIfAborted as m } from "../errors.mjs";
|
|
28
|
+
import { splitPath as y } from "../security/pathPolicy.mjs";
|
|
29
|
+
function v() {
|
|
30
|
+
return {
|
|
31
|
+
kind: "directory",
|
|
32
|
+
children: /* @__PURE__ */ new Map()
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
class x {
|
|
36
|
+
constructor(e = {}, r = "memory-workspace") {
|
|
37
|
+
E(this, "root", v());
|
|
38
|
+
this.displayName = r, Object.entries(e).forEach(([t, o]) => this.seed(t, o));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 直接写入文件(含中间目录),用于构造测试数据或模拟外部修改。
|
|
42
|
+
* 以 `/` 结尾的路径表示创建空目录。
|
|
43
|
+
*/
|
|
44
|
+
seed(e, r = "", t = Date.now()) {
|
|
45
|
+
const o = e.split("/").filter(Boolean);
|
|
46
|
+
if (e.endsWith("/")) {
|
|
47
|
+
this.resolveDirectory(o, !0);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const i = o.pop();
|
|
51
|
+
if (!i)
|
|
52
|
+
return;
|
|
53
|
+
const a = this.resolveDirectory(o, !0), d = typeof r == "string" ? new TextEncoder().encode(r) : r;
|
|
54
|
+
a.children.set(i, {
|
|
55
|
+
kind: "file",
|
|
56
|
+
data: d,
|
|
57
|
+
lastModified: t
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
resolveDirectory(e, r = !1) {
|
|
61
|
+
let t = this.root;
|
|
62
|
+
for (const o of e) {
|
|
63
|
+
let i = t.children.get(o);
|
|
64
|
+
if (!i) {
|
|
65
|
+
if (!r)
|
|
66
|
+
throw l("NotFoundError");
|
|
67
|
+
i = v(), t.children.set(o, i);
|
|
68
|
+
}
|
|
69
|
+
if (i.kind !== "directory")
|
|
70
|
+
throw l("TypeMismatchError");
|
|
71
|
+
t = i;
|
|
72
|
+
}
|
|
73
|
+
return t;
|
|
74
|
+
}
|
|
75
|
+
resolveNode(e) {
|
|
76
|
+
const r = y(e), t = r.pop();
|
|
77
|
+
if (t === void 0)
|
|
78
|
+
return this.root;
|
|
79
|
+
const o = this.resolveDirectory(r).children.get(t);
|
|
80
|
+
if (!o)
|
|
81
|
+
throw l("NotFoundError");
|
|
82
|
+
return o;
|
|
83
|
+
}
|
|
84
|
+
stat(e) {
|
|
85
|
+
return f(this, null, function* () {
|
|
86
|
+
var o;
|
|
87
|
+
const r = this.resolveNode(e), t = (o = y(e).pop()) != null ? o : this.displayName;
|
|
88
|
+
return r.kind === "directory" ? {
|
|
89
|
+
name: t,
|
|
90
|
+
kind: "directory"
|
|
91
|
+
} : {
|
|
92
|
+
name: t,
|
|
93
|
+
kind: "file",
|
|
94
|
+
size: r.data.byteLength,
|
|
95
|
+
lastModified: r.lastModified
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
listEntries(e, r) {
|
|
100
|
+
return f(this, null, function* () {
|
|
101
|
+
m(r);
|
|
102
|
+
const t = this.resolveDirectory(y(e));
|
|
103
|
+
return Array.from(t.children.entries()).map(([o, i]) => i.kind === "directory" ? {
|
|
104
|
+
name: o,
|
|
105
|
+
kind: "directory"
|
|
106
|
+
} : {
|
|
107
|
+
name: o,
|
|
108
|
+
kind: "file",
|
|
109
|
+
size: i.data.byteLength,
|
|
110
|
+
lastModified: i.lastModified
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
readFile(e) {
|
|
115
|
+
return f(this, null, function* () {
|
|
116
|
+
const r = this.resolveNode(e);
|
|
117
|
+
if (r.kind !== "file")
|
|
118
|
+
throw l("TypeMismatchError");
|
|
119
|
+
return new Blob([r.data]);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
writeFile(o, i) {
|
|
123
|
+
return f(this, arguments, function* (e, r, t = {}) {
|
|
124
|
+
const a = y(e), d = a.pop();
|
|
125
|
+
if (!d)
|
|
126
|
+
throw l("TypeMismatchError");
|
|
127
|
+
const n = this.resolveDirectory(a, t.createDirectories), c = n.children.get(d);
|
|
128
|
+
if ((c == null ? void 0 : c.kind) === "directory")
|
|
129
|
+
throw l("TypeMismatchError");
|
|
130
|
+
const p = [];
|
|
131
|
+
let u = 0;
|
|
132
|
+
try {
|
|
133
|
+
for (var W = M(N(r)), j, C, I; j = !(C = yield W.next()).done; j = !1) {
|
|
134
|
+
const h = C.value;
|
|
135
|
+
m(t.signal), p.push(h), u += h.byteLength;
|
|
136
|
+
}
|
|
137
|
+
} catch (C) {
|
|
138
|
+
I = [C];
|
|
139
|
+
} finally {
|
|
140
|
+
try {
|
|
141
|
+
j && (C = W.return) && (yield C.call(W));
|
|
142
|
+
} finally {
|
|
143
|
+
if (I)
|
|
144
|
+
throw I[0];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
m(t.signal);
|
|
148
|
+
const k = new Uint8Array(u);
|
|
149
|
+
let w = 0;
|
|
150
|
+
p.forEach((h) => {
|
|
151
|
+
k.set(h, w), w += h.byteLength;
|
|
152
|
+
}), n.children.set(d, {
|
|
153
|
+
kind: "file",
|
|
154
|
+
data: k,
|
|
155
|
+
lastModified: Date.now()
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export {
|
|
161
|
+
x as MemoryWorkspaceAdapter
|
|
162
|
+
};
|