@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 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.
Files changed (72) hide show
  1. package/README.md +243 -225
  2. package/dist/es/AgentSession.mjs +267 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +56 -67
  5. package/dist/es/DialogSession.mjs +123 -118
  6. package/dist/es/EventBus.mjs +38 -34
  7. package/dist/es/Logger.mjs +19 -21
  8. package/dist/es/Session.mjs +338 -284
  9. package/dist/es/api/index.mjs +31 -30
  10. package/dist/es/builtinTools/constants.mjs +12 -5
  11. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
  12. package/dist/es/builtinTools/paths.mjs +34 -27
  13. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  14. package/dist/es/builtinTools/schemas.mjs +63 -18
  15. package/dist/es/builtinTools/tools.mjs +368 -244
  16. package/dist/es/index.mjs +62 -61
  17. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
  20. package/dist/es/localFiles/constants.mjs +24 -28
  21. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  22. package/dist/es/localFiles/errors.mjs +44 -35
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
  24. package/dist/es/localFiles/host/protocol.mjs +27 -14
  25. package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
  26. package/dist/es/localFiles/preview.mjs +33 -0
  27. package/dist/es/localFiles/schemas.mjs +22 -53
  28. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
  29. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  30. package/dist/es/localMcp/client.mjs +234 -0
  31. package/dist/es/localMcp/endpoints.mjs +94 -0
  32. package/dist/es/localMcp/register.mjs +207 -0
  33. package/dist/es/localMcp/registry.mjs +43 -0
  34. package/dist/es/package.json.mjs +34 -54
  35. package/dist/es/sessionUpload.mjs +49 -0
  36. package/dist/es/utils.mjs +24 -11
  37. package/dist/lib/index.js +48 -40
  38. package/dist/src/AgentSession.d.ts +13 -0
  39. package/dist/src/BotClient.d.ts +13 -1
  40. package/dist/src/Config.d.ts +6 -7
  41. package/dist/src/EventBus.d.ts +3 -0
  42. package/dist/src/Logger.d.ts +15 -8
  43. package/dist/src/PayloadTypes.d.ts +2 -0
  44. package/dist/src/Session.d.ts +19 -2
  45. package/dist/src/api/index.d.ts +2 -2
  46. package/dist/src/builtinTools/command.d.ts +7 -0
  47. package/dist/src/builtinTools/constants.d.ts +10 -2
  48. package/dist/src/builtinTools/paths.d.ts +3 -2
  49. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  50. package/dist/src/builtinTools/tools.d.ts +13 -0
  51. package/dist/src/constant.d.ts +1 -1
  52. package/dist/src/index.d.ts +2 -1
  53. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  54. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
  55. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
  56. package/dist/src/localFiles/constants.d.ts +4 -13
  57. package/dist/src/localFiles/errors.d.ts +1 -1
  58. package/dist/src/localFiles/host/protocol.d.ts +14 -3
  59. package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
  60. package/dist/src/localFiles/index.d.ts +9 -5
  61. package/dist/src/localFiles/preview.d.ts +2 -0
  62. package/dist/src/localFiles/schemas.d.ts +0 -2
  63. package/dist/src/localFiles/types.d.ts +2 -22
  64. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
  65. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  66. package/dist/src/localMcp/client.d.ts +15 -0
  67. package/dist/src/localMcp/endpoints.d.ts +19 -0
  68. package/dist/src/localMcp/register.d.ts +34 -0
  69. package/dist/src/localMcp/registry.d.ts +27 -0
  70. package/dist/src/sessionUpload.d.ts +14 -0
  71. package/dist/src/utils.d.ts +6 -0
  72. package/package.json +4 -24
package/dist/es/index.mjs CHANGED
@@ -1,71 +1,72 @@
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";
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
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";
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";
11
12
  import { FileSystemAccessAdapter as d } from "./localFiles/adapters/FileSystemAccessAdapter.mjs";
12
13
  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";
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";
17
19
  export {
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,
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,
28
30
  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,
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,
39
40
  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,
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,
59
59
  e as configuration,
60
- T as configure,
61
- u as createDefaultSessionFileTransfer,
62
- H as createIndexedDbStore,
60
+ r as configure,
61
+ k as createDefaultSessionFileTransfer,
62
+ B as createIndexedDbStore,
63
63
  s as createLocalFilesPlugin,
64
- n as createMemoryStore,
65
- Y as getDownloadUrlAllowlist,
64
+ H as createMemoryStore,
65
+ K as getDownloadUrlAllowlist,
66
66
  E as getRegisteredLocalFilesPluginCode,
67
- r as getRegisteredLocalPythonPluginCode,
68
- G as isDownloadUrlAllowed,
69
- L as resolveLocalFilesPluginCode,
70
- R as toToolError
67
+ b as isDownloadUrlAllowed,
68
+ M as normalizeFilePath,
69
+ Y as registerHostBridge,
70
+ T as resolveLocalFilesPluginCode,
71
+ D as toToolError
71
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
+ };
@@ -3,27 +3,27 @@ var g = (o, t) => {
3
3
  return t;
4
4
  throw Error("Symbol." + o + " is not defined");
5
5
  };
6
- var y = (o, t, e) => new Promise((r, a) => {
6
+ var w = (o, t, r) => new Promise((e, a) => {
7
7
  var c = (i) => {
8
8
  try {
9
- l(e.next(i));
9
+ s(r.next(i));
10
10
  } catch (n) {
11
11
  a(n);
12
12
  }
13
- }, w = (i) => {
13
+ }, d = (i) => {
14
14
  try {
15
- l(e.throw(i));
15
+ s(r.throw(i));
16
16
  } catch (n) {
17
17
  a(n);
18
18
  }
19
- }, l = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(c, w);
20
- l((e = e.apply(o, t)).next());
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 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) {
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
27
  return !!o && typeof o == "object" && o.name === t;
28
28
  }
29
29
  class b {
@@ -33,85 +33,67 @@ class b {
33
33
  get displayName() {
34
34
  return this.root.name;
35
35
  }
36
- resolveDirectory(t, e = !1) {
37
- return y(this, null, function* () {
38
- let r = this.root;
36
+ resolveDirectory(t, r = !1) {
37
+ return w(this, null, function* () {
38
+ let e = this.root;
39
39
  for (const a of t)
40
- r = yield r.getDirectoryHandle(a, {
41
- create: e
40
+ e = yield e.getDirectoryHandle(a, {
41
+ create: r
42
42
  });
43
- return r;
43
+ return e;
44
44
  });
45
45
  }
46
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);
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
54
  stat(t) {
55
- return y(this, null, function* () {
56
- const e = f(t), r = e.pop();
57
- if (!r)
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
- const a = yield this.resolveDirectory(e);
62
+ const a = yield this.resolveDirectory(r);
63
63
  try {
64
- const c = yield (yield a.getFileHandle(r)).getFile();
64
+ const c = yield (yield a.getFileHandle(e)).getFile();
65
65
  return {
66
- name: r,
66
+ name: e,
67
67
  kind: "file",
68
68
  size: c.size,
69
69
  lastModified: c.lastModified
70
70
  };
71
71
  } catch (c) {
72
- if (!u(c, "TypeMismatchError"))
72
+ if (!m(c, "TypeMismatchError"))
73
73
  throw c;
74
- return yield a.getDirectoryHandle(r), {
75
- name: r,
74
+ return yield a.getDirectoryHandle(e), {
75
+ name: e,
76
76
  kind: "directory"
77
77
  };
78
78
  }
79
79
  });
80
80
  }
81
- listEntries(t, e) {
82
- return y(this, null, function* () {
83
- const r = yield this.resolveDirectory(f(t)), a = [];
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 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
- }
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 (l) {
111
- i = [l];
92
+ } catch (s) {
93
+ i = [s];
112
94
  } finally {
113
95
  try {
114
- w && (l = c.return) && (yield l.call(c));
96
+ d && (s = c.return) && (yield s.call(c));
115
97
  } finally {
116
98
  if (i)
117
99
  throw i[0];
@@ -121,140 +103,140 @@ class b {
121
103
  });
122
104
  }
123
105
  readFile(t) {
124
- return y(this, null, function* () {
106
+ return w(this, null, function* () {
125
107
  return (yield this.resolveFile(t)).getFile();
126
108
  });
127
109
  }
128
110
  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);
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);
134
116
  let n = !0;
135
117
  try {
136
- yield i.getFileHandle(l);
137
- } catch (h) {
138
- if (!u(h, "NotFoundError"))
139
- throw h;
118
+ yield i.getFileHandle(s);
119
+ } catch (f) {
120
+ if (!m(f, "NotFoundError"))
121
+ throw f;
140
122
  n = !1;
141
123
  }
142
- const s = yield i.getFileHandle(l, {
124
+ const y = yield i.getFileHandle(s, {
143
125
  create: !0
144
126
  });
145
- let d;
127
+ let l;
146
128
  try {
147
- d = yield s.createWritable();
129
+ l = yield y.createWritable();
148
130
  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);
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 (S) {
154
- W = [S];
135
+ } catch (z) {
136
+ W = [z];
155
137
  } finally {
156
138
  try {
157
- x && (S = A.return) && (yield S.call(A));
139
+ S && (z = A.return) && (yield z.call(A));
158
140
  } finally {
159
141
  if (W)
160
142
  throw W[0];
161
143
  }
162
144
  }
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;
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;
168
150
  }
169
151
  });
170
152
  }
171
153
  createDirectory(t) {
172
- return y(this, null, function* () {
173
- yield this.resolveDirectory(f(t), !0);
154
+ return w(this, null, function* () {
155
+ yield this.resolveDirectory(h(t), !0);
174
156
  });
175
157
  }
176
- remove(r) {
177
- return y(this, arguments, function* (t, e = {}) {
178
- const a = f(t), c = a.pop();
158
+ remove(e) {
159
+ return w(this, arguments, function* (t, r = {}) {
160
+ const a = h(t), c = a.pop();
179
161
  if (!c)
180
- throw m("InvalidModificationError");
162
+ throw u("InvalidModificationError");
181
163
  yield (yield this.resolveDirectory(a)).removeEntry(c, {
182
- recursive: e.recursive === !0
164
+ recursive: r.recursive === !0
183
165
  });
184
166
  });
185
167
  }
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;
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;
195
177
  try {
196
- s = yield E(n, w);
197
- } catch (d) {
198
- if (!u(d, "NotFoundError"))
199
- throw d;
178
+ y = yield E(n, d);
179
+ } catch (l) {
180
+ if (!m(l, "NotFoundError"))
181
+ throw l;
200
182
  }
201
- if (s && (s.kind === "directory" || i.kind === "directory"))
202
- throw m("InvalidModificationError");
203
- if (!s && typeof i.move == "function")
183
+ if (y && (y.kind === "directory" || i.kind === "directory"))
184
+ throw u("InvalidModificationError");
185
+ if (!y && typeof i.move == "function")
204
186
  try {
205
- yield i.move(n, w);
187
+ yield i.move(n, d);
206
188
  return;
207
- } catch (d) {
208
- if (!u(d, "NotSupportedError") && !(d instanceof TypeError))
209
- throw d;
189
+ } catch (l) {
190
+ if (!m(l, "NotSupportedError") && !(l instanceof TypeError))
191
+ throw l;
210
192
  }
211
- yield F(i, n, w), yield l.removeEntry(c, {
193
+ yield D(i, n, d), yield s.removeEntry(c, {
212
194
  recursive: !0
213
195
  });
214
196
  });
215
197
  }
216
198
  }
217
199
  function E(o, t) {
218
- return y(this, null, function* () {
200
+ return w(this, null, function* () {
219
201
  try {
220
202
  return yield o.getFileHandle(t);
221
- } catch (e) {
222
- if (!u(e, "TypeMismatchError"))
223
- throw e;
203
+ } catch (r) {
204
+ if (!m(r, "TypeMismatchError"))
205
+ throw r;
224
206
  return o.getDirectoryHandle(t);
225
207
  }
226
208
  });
227
209
  }
228
- function F(o, t, e) {
229
- return y(this, null, function* () {
210
+ function D(o, t, r) {
211
+ return w(this, null, function* () {
230
212
  if (o.kind === "file") {
231
- const i = yield o.getFile(), n = yield (yield t.getFileHandle(e, {
213
+ const i = yield o.getFile(), n = yield (yield t.getFileHandle(r, {
232
214
  create: !0
233
215
  })).createWritable();
234
216
  try {
235
217
  yield n.write(i), yield n.close();
236
- } catch (s) {
218
+ } catch (y) {
237
219
  throw yield n.abort().catch(() => {
238
- }), s;
220
+ }), y;
239
221
  }
240
222
  return;
241
223
  }
242
- const r = yield t.getDirectoryHandle(e, {
224
+ const e = yield t.getDirectoryHandle(r, {
243
225
  create: !0
244
226
  });
245
227
  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);
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);
249
231
  }
250
- } catch (w) {
251
- l = [w];
232
+ } catch (d) {
233
+ s = [d];
252
234
  } finally {
253
235
  try {
254
- c && (w = a.return) && (yield w.call(a));
236
+ c && (d = a.return) && (yield d.call(a));
255
237
  } finally {
256
- if (l)
257
- throw l[0];
238
+ if (s)
239
+ throw s[0];
258
240
  }
259
241
  }
260
242
  });