@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.
Files changed (99) hide show
  1. package/README.md +284 -254
  2. package/dist/es/AgentSession.mjs +267 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +55 -88
  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/browserRuntime/BrowserCommandRunner.mjs +201 -0
  11. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  12. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  13. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  14. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  15. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  16. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  17. package/dist/es/builtinTools/command.mjs +56 -0
  18. package/dist/es/builtinTools/constants.mjs +17 -0
  19. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +266 -0
  20. package/dist/es/builtinTools/overview.mjs +77 -0
  21. package/dist/es/builtinTools/paths.mjs +70 -0
  22. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  23. package/dist/es/builtinTools/schemas.mjs +261 -0
  24. package/dist/es/builtinTools/tools.mjs +595 -0
  25. package/dist/es/index.mjs +66 -64
  26. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  27. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
  28. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
  29. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  30. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  31. package/dist/es/localFiles/constants.mjs +24 -28
  32. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  33. package/dist/es/localFiles/errors.mjs +44 -35
  34. package/dist/es/localFiles/host/connectHostBridge.mjs +43 -35
  35. package/dist/es/localFiles/host/protocol.mjs +27 -13
  36. package/dist/es/localFiles/host/sandboxClient.mjs +494 -0
  37. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  38. package/dist/es/localFiles/preview.mjs +33 -0
  39. package/dist/es/localFiles/schemas.mjs +40 -86
  40. package/dist/es/localFiles/validate.mjs +37 -37
  41. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +176 -90
  42. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  43. package/dist/es/localMcp/client.mjs +234 -0
  44. package/dist/es/localMcp/endpoints.mjs +94 -0
  45. package/dist/es/localMcp/register.mjs +207 -0
  46. package/dist/es/localMcp/registry.mjs +43 -0
  47. package/dist/es/package.json.mjs +49 -60
  48. package/dist/es/sessionUpload.mjs +49 -0
  49. package/dist/es/utils.mjs +24 -11
  50. package/dist/lib/index.js +382 -10
  51. package/dist/src/AgentSession.d.ts +13 -0
  52. package/dist/src/BotClient.d.ts +13 -1
  53. package/dist/src/Config.d.ts +7 -8
  54. package/dist/src/EventBus.d.ts +3 -0
  55. package/dist/src/Logger.d.ts +15 -8
  56. package/dist/src/PayloadTypes.d.ts +2 -0
  57. package/dist/src/Session.d.ts +19 -2
  58. package/dist/src/api/index.d.ts +2 -2
  59. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  60. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  61. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  62. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  63. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  64. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  65. package/dist/src/builtinTools/command.d.ts +35 -0
  66. package/dist/src/builtinTools/constants.d.ts +25 -0
  67. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  68. package/dist/src/builtinTools/overview.d.ts +5 -0
  69. package/dist/src/builtinTools/paths.d.ts +16 -0
  70. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  71. package/dist/src/builtinTools/schemas.d.ts +3 -0
  72. package/dist/src/builtinTools/tools.d.ts +73 -0
  73. package/dist/src/constant.d.ts +1 -1
  74. package/dist/src/index.d.ts +2 -1
  75. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  76. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  77. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
  78. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  79. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
  80. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  81. package/dist/src/localFiles/constants.d.ts +5 -13
  82. package/dist/src/localFiles/errors.d.ts +1 -1
  83. package/dist/src/localFiles/host/protocol.d.ts +34 -16
  84. package/dist/src/localFiles/host/sandboxClient.d.ts +112 -0
  85. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  86. package/dist/src/localFiles/index.d.ts +11 -6
  87. package/dist/src/localFiles/preview.d.ts +2 -0
  88. package/dist/src/localFiles/schemas.d.ts +2 -5
  89. package/dist/src/localFiles/types.d.ts +16 -23
  90. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
  91. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  92. package/dist/src/localMcp/client.d.ts +15 -0
  93. package/dist/src/localMcp/endpoints.d.ts +19 -0
  94. package/dist/src/localMcp/register.d.ts +34 -0
  95. package/dist/src/localMcp/registry.d.ts +27 -0
  96. package/dist/src/sessionUpload.d.ts +14 -0
  97. package/dist/src/utils.d.ts +6 -0
  98. package/package.json +13 -24
  99. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -1,46 +1,50 @@
1
- var _ = Object.defineProperty, k = Object.defineProperties;
2
- var S = Object.getOwnPropertyDescriptors;
3
- var w = Object.getOwnPropertySymbols;
4
- var C = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable;
5
- var u = (r, e, t) => e in r ? _(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e) => {
1
+ var S = Object.defineProperty, b = Object.defineProperties;
2
+ var H = Object.getOwnPropertyDescriptors;
3
+ var k = Object.getOwnPropertySymbols;
4
+ var R = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
5
+ var p = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e) => {
6
6
  for (var t in e || (e = {}))
7
- C.call(e, t) && u(r, t, e[t]);
8
- if (w)
9
- for (var t of w(e))
10
- P.call(e, t) && u(r, t, e[t]);
7
+ R.call(e, t) && p(r, t, e[t]);
8
+ if (k)
9
+ for (var t of k(e))
10
+ T.call(e, t) && p(r, t, e[t]);
11
11
  return r;
12
- }, A = (r, e) => k(r, S(e));
13
- var s = (r, e, t) => (u(r, typeof e != "symbol" ? e + "" : e, t), t);
14
- var o = (r, e, t) => new Promise((i, a) => {
15
- var n = (l) => {
12
+ }, C = (r, e) => b(r, H(e));
13
+ var s = (r, e, t) => (p(r, typeof e != "symbol" ? e + "" : e, t), t);
14
+ var d = (r, e, t) => new Promise((i, n) => {
15
+ var a = (o) => {
16
16
  try {
17
- c(t.next(l));
18
- } catch (d) {
19
- a(d);
17
+ l(t.next(o));
18
+ } catch (c) {
19
+ n(c);
20
20
  }
21
- }, h = (l) => {
21
+ }, h = (o) => {
22
22
  try {
23
- c(t.throw(l));
24
- } catch (d) {
25
- a(d);
23
+ l(t.throw(o));
24
+ } catch (c) {
25
+ n(c);
26
26
  }
27
- }, c = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(n, h);
28
- c((t = t.apply(r, e)).next());
27
+ }, l = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(a, h);
28
+ l((t = t.apply(r, e)).next());
29
29
  });
30
- import H from "../../EventBus.mjs";
31
- import { FileSystemAccessAdapter as b } from "../adapters/FileSystemAccessAdapter.mjs";
32
- import { getNativeDirectoryPicker as D } from "../adapters/fsaTypes.mjs";
33
- import { LOCAL_FILES_FUNCTION_CODES as T } from "../constants.mjs";
34
- import { getDownloadUrlAllowlist as F } from "../security/downloadUrlPolicy.mjs";
35
- import { SensitiveFilePolicy as W } from "../security/sensitiveFiles.mjs";
36
- import { resolveLimits as q } from "../limits.mjs";
37
- import { createDefaultSessionFileTransfer as N } from "../transfer/SessionFileTransfer.mjs";
38
- import { createMemoryStore as I } from "./handleStore.mjs";
39
- import { watchDirectoryHandle as E } from "./watchDirectory.mjs";
40
- const p = {
30
+ import F from "../../Logger.mjs";
31
+ import D from "../../EventBus.mjs";
32
+ import { FileSystemAccessAdapter as _ } from "../adapters/FileSystemAccessAdapter.mjs";
33
+ import { HostBridgeAdapter as W } from "../adapters/HostBridgeAdapter.mjs";
34
+ import { FileSnapshotAdapter as L } from "../adapters/FileSnapshotAdapter.mjs";
35
+ import { getNativeDirectoryPicker as E } from "../adapters/fsaTypes.mjs";
36
+ import { LOCAL_FILES_FUNCTION_CODES as I } from "../constants.mjs";
37
+ import { getDownloadUrlAllowlist as N } from "../security/downloadUrlPolicy.mjs";
38
+ import { SensitiveFilePolicy as q } from "../security/sensitiveFiles.mjs";
39
+ import { resolveLimits as U } from "../limits.mjs";
40
+ import { createDefaultSessionFileTransfer as j } from "../transfer/SessionFileTransfer.mjs";
41
+ import { createMemoryStore as x } from "./handleStore.mjs";
42
+ import { watchDirectoryHandle as K } from "./watchDirectory.mjs";
43
+ import { WorkspaceFiles as V } from "./WorkspaceFiles.mjs";
44
+ const m = {
41
45
  mode: "readwrite"
42
46
  };
43
- function K(r) {
47
+ function M(r) {
44
48
  const e = r.replace(/\\/g, "/").trim().replace(/^\.\/+/, "").replace(/\/+$/, "");
45
49
  if (!e || e === ".")
46
50
  return "";
@@ -50,10 +54,11 @@ function K(r) {
50
54
  if (!t.some((i) => !i || i === "." || i === ".."))
51
55
  return t.join("/");
52
56
  }
53
- function L(r) {
57
+ function O(r) {
54
58
  return !!r && typeof r == "object" && r.name === "AbortError";
55
59
  }
56
- class J {
60
+ const P = new F("[LocalWorkspace] ");
61
+ class ne {
57
62
  constructor(e) {
58
63
  s(this, "applicationId");
59
64
  s(this, "limits");
@@ -62,15 +67,22 @@ class J {
62
67
  s(this, "allowWorkspaceWideTextSearch");
63
68
  s(this, "transfer");
64
69
  s(this, "fetch");
70
+ s(this, "commandRunner");
71
+ /** 平台技能同步。由 BotClient 在启用本地工作区后挂上。 */
72
+ s(this, "platformSkills");
73
+ s(this, "browserRuntime");
74
+ /** 接入方的文件操作入口。不要使用 `adapter`。 */
75
+ s(this, "files");
65
76
  s(this, "store");
66
77
  s(this, "picker");
67
- s(this, "event", new H(!0));
78
+ s(this, "event", new D(!0));
68
79
  s(this, "_status");
69
80
  s(this, "_displayName");
70
81
  s(this, "_adapter", null);
71
82
  s(this, "pendingHandle", null);
72
83
  s(this, "approvalHandler");
73
84
  s(this, "activeCalls", 0);
85
+ s(this, "activeCommands", 0);
74
86
  s(this, "inflight", /* @__PURE__ */ new Set());
75
87
  s(this, "_ready", Promise.resolve());
76
88
  s(this, "stopWatching", () => {
@@ -78,17 +90,25 @@ class J {
78
90
  s(this, "pendingChangePaths", /* @__PURE__ */ new Set());
79
91
  s(this, "changeTimer");
80
92
  s(this, "refreshAllVisible", !1);
81
- var n, h, c, l, d, m, g, y, v;
82
- const t = (n = e.config) != null ? n : {};
83
- this.applicationId = e.applicationId, this.store = (h = e.store) != null ? h : I(), this.picker = e.picker === null ? void 0 : (c = e.picker) != null ? c : D(), this.limits = q(t.limits), this.sensitive = new W(t.sensitiveRulesAppend), this.downloadUrlAllowlist = F(t.downloadUrlAllowlistAppend), this.allowWorkspaceWideTextSearch = !!t.allowWorkspaceWideTextSearch, this.approvalHandler = t.onApprovalRequired;
84
- const i = (l = e.transfer) != null ? l : N(() => {
93
+ /** 选择、关闭会推进它。进行中的 restore 若发现已经变了,就不再覆盖当前目录。 */
94
+ s(this, "epoch", 0);
95
+ var h, l, o, c, f, g, v, y, w, A;
96
+ const t = (h = e.config) != null ? h : {};
97
+ this.applicationId = e.applicationId, this.store = (l = e.store) != null ? l : x(), this.picker = e.picker === null ? void 0 : (o = e.picker) != null ? o : E(), this.limits = U(t.limits), this.sensitive = new q(t.sensitiveRulesAppend), this.downloadUrlAllowlist = N(t.downloadUrlAllowlistAppend), this.allowWorkspaceWideTextSearch = !!t.allowWorkspaceWideTextSearch, this.approvalHandler = t.onApprovalRequired;
98
+ const i = (c = e.transfer) != null ? c : j(() => {
85
99
  });
86
100
  this.transfer = {
87
- upload: (m = (d = t.transfer) == null ? void 0 : d.upload) != null ? m : i.upload,
88
- resolveDownload: (y = (g = t.transfer) == null ? void 0 : g.resolveDownload) != null ? y : i.resolveDownload
101
+ upload: (g = (f = t.transfer) == null ? void 0 : f.upload) != null ? g : i.upload,
102
+ resolveDownload: (y = (v = t.transfer) == null ? void 0 : v.resolveDownload) != null ? y : i.resolveDownload
89
103
  };
90
- const a = (v = e.fetch) != null ? v : typeof fetch == "function" ? fetch : void 0;
91
- this.fetch = a ? a.bind(globalThis) : () => Promise.reject(new Error("fetch is not available")), this._status = this.picker ? "none" : "unsupported";
104
+ const n = (w = e.fetch) != null ? w : typeof fetch == "function" ? fetch : void 0;
105
+ this.fetch = n ? n.bind(globalThis) : () => Promise.reject(new Error("fetch is not available")), this.commandRunner = e.commandRunner;
106
+ const a = (A = t.commandRuntime) == null ? void 0 : A.browser;
107
+ this.browserRuntime = {
108
+ enabled: (a == null ? void 0 : a.enabled) !== !1,
109
+ bashModuleURL: a == null ? void 0 : a.bashModuleURL,
110
+ pyodideIndexURL: a == null ? void 0 : a.pyodideIndexURL
111
+ }, this._status = this.picker ? "none" : "unsupported", this.files = new V(this);
92
112
  }
93
113
  // -------------------------------------------------------------------------
94
114
  // 状态
@@ -107,7 +127,10 @@ class J {
107
127
  get ready() {
108
128
  return this._ready;
109
129
  }
110
- /** @internal 已授权时可用的 Adapter。 */
130
+ /**
131
+ * @internal 已授权时的磁盘后端,供内置工具使用。
132
+ * 接入方用 `files`:这里的路径必须已规范化,异常里也可能带系统路径。
133
+ */
111
134
  get adapter() {
112
135
  return this._status === "granted" ? this._adapter : null;
113
136
  }
@@ -118,13 +141,19 @@ class J {
118
141
  return `disclosure:${this.applicationId}`;
119
142
  }
120
143
  setStatus(e, t = this._displayName) {
121
- e === this._status && t === this._displayName || (this._status = e, this._displayName = t, this.emit("workspace:changed", {
144
+ e === this._status && t === this._displayName || (this._status = e, this._displayName = t, P.log("status", {
145
+ status: e,
146
+ displayName: t
147
+ }), this.emit("workspace:changed", {
122
148
  status: e,
123
149
  displayName: t
124
150
  }));
125
151
  }
152
+ replaceAdapter(e) {
153
+ this._adapter !== e && this.files.releaseAllUrls(), this._adapter = e;
154
+ }
126
155
  attachHandle(e) {
127
- this.cancelFilesChanged(), this.pendingHandle = e, this._adapter = new b(e), this.setStatus("granted", e.name), this.unwatchDirectory(), this.stopWatching = E(e, (t) => this.notifyFilesChanged(t));
156
+ this.cancelFilesChanged(), this.pendingHandle = e, this.replaceAdapter(new _(e)), this.setStatus("granted", e.name), this.unwatchDirectory(), this.stopWatching = K(e, (t) => this.notifyFilesChanged(t));
128
157
  }
129
158
  // -------------------------------------------------------------------------
130
159
  // 授权
@@ -144,18 +173,13 @@ class J {
144
173
  } catch (t) {
145
174
  return Promise.reject(t);
146
175
  }
147
- return e.then((t) => o(this, null, function* () {
148
- var a, n;
149
- this.cancelAll();
150
- const i = (n = yield (a = t.queryPermission) == null ? void 0 : a.call(t, p)) != null ? n : "granted";
151
- return yield this.store.set(this.handleKey, {
152
- handle: t,
153
- displayName: t.name,
154
- savedAt: Date.now()
155
- }).catch(() => {
156
- }), i === "denied" ? (this.pendingHandle = t, this._adapter = null, this.setStatus("denied", t.name), !1) : (this.attachHandle(t), !0);
157
- }), (t) => {
158
- if (L(t))
176
+ return e.then((t) => (this.epoch += 1, this.cancelAll(), this.attachHandle(t), this.store.set(this.handleKey, {
177
+ handle: t,
178
+ displayName: t.name,
179
+ savedAt: Date.now()
180
+ }).catch(() => {
181
+ }), !0), (t) => {
182
+ if (O(t))
159
183
  return !1;
160
184
  throw t;
161
185
  });
@@ -165,29 +189,51 @@ class J {
165
189
  return this._ready = this.doRestore(), this._ready;
166
190
  }
167
191
  doRestore() {
168
- return o(this, null, function* () {
169
- var i, a, n;
192
+ return d(this, null, function* () {
193
+ var n, a, h;
194
+ const e = this.epoch;
170
195
  if (!this.picker) {
171
196
  this._adapter || this.setStatus("unsupported");
172
197
  return;
173
198
  }
174
- let e;
199
+ let t;
175
200
  try {
176
- e = yield this.store.get(this.handleKey);
177
- } catch (h) {
178
- e = void 0;
201
+ t = yield this.store.get(this.handleKey);
202
+ } catch (l) {
203
+ t = void 0;
179
204
  }
180
- if (!(e != null && e.handle)) {
181
- this.pendingHandle = null, this._adapter = null, this.setStatus("none", void 0);
205
+ if (e !== this.epoch)
206
+ return;
207
+ if (!(t != null && t.handle)) {
208
+ this.pendingHandle = null, this.replaceAdapter(null), this.setStatus("none", void 0);
182
209
  return;
183
210
  }
184
- let t;
211
+ let i;
185
212
  try {
186
- t = (n = yield (a = (i = e.handle).queryPermission) == null ? void 0 : a.call(i, p)) != null ? n : "prompt";
187
- } catch (h) {
188
- t = "prompt";
213
+ i = (h = yield (a = (n = t.handle).queryPermission) == null ? void 0 : a.call(n, m)) != null ? h : "prompt";
214
+ } catch (l) {
215
+ i = "prompt";
216
+ }
217
+ if (e === this.epoch) {
218
+ if (i === "granted" || i === "prompt" && (yield this.canList(t.handle))) {
219
+ if (e !== this.epoch)
220
+ return;
221
+ this.attachHandle(t.handle);
222
+ return;
223
+ }
224
+ this.pendingHandle = t.handle, this.replaceAdapter(null), this.setStatus(i === "denied" ? "denied" : "prompt", t.displayName);
189
225
  }
190
- t === "granted" ? this.attachHandle(e.handle) : (this.pendingHandle = e.handle, this._adapter = null, this.setStatus(t === "denied" ? "denied" : "prompt", e.displayName));
226
+ });
227
+ }
228
+ /** queryPermission 仍可能是 prompt,但选择框留下的句柄其实列得出目录。 */
229
+ canList(e) {
230
+ return d(this, null, function* () {
231
+ const t = new _(e);
232
+ let i;
233
+ const n = new Promise((l) => {
234
+ i = setTimeout(() => l(!1), 2e3);
235
+ }), a = t.listEntries("").then(() => !0).catch(() => !1), h = yield Promise.race([a, n]);
236
+ return clearTimeout(i), h;
191
237
  });
192
238
  }
193
239
  /** 对已保存的目录重新申请权限。必须在用户点击事件中调用。 */
@@ -197,22 +243,36 @@ class J {
197
243
  return Promise.resolve(!1);
198
244
  let t;
199
245
  try {
200
- t = e.requestPermission(p);
246
+ t = e.requestPermission(m);
201
247
  } catch (i) {
202
248
  return Promise.reject(i);
203
249
  }
204
- return t.then((i) => i === "granted" ? (this.attachHandle(e), !0) : (this._adapter = null, this.setStatus(i === "denied" ? "denied" : "prompt", e.name), !1));
250
+ return t.then((i) => i === "granted" ? (this.attachHandle(e), !0) : (this.replaceAdapter(null), this.setStatus(i === "denied" ? "denied" : "prompt", e.name), !1));
205
251
  }
206
252
  /** 断开工作区并删除持久化句柄。状态立即变为未授权,存储删除在其后完成。 */
207
253
  clear() {
208
- return o(this, null, function* () {
209
- this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this.pendingHandle = null, this._adapter = null, this.setStatus(this.picker ? "none" : "unsupported", void 0), yield this.store.delete(this.handleKey).catch(() => {
254
+ return d(this, null, function* () {
255
+ this.epoch += 1, this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this.pendingHandle = null, this.replaceAdapter(null), this.setStatus(this.picker ? "none" : "unsupported", void 0), yield this.store.delete(this.handleKey).catch(() => {
210
256
  });
211
257
  });
212
258
  }
259
+ /**
260
+ * 用文件列表挂上工作区。路径来自 webkitRelativePath,选完就能列出层级。
261
+ * 写入只留在内存里,不会出现在用户磁盘上。需要落盘时用 pick()。
262
+ */
263
+ attachFileSnapshot(e, t) {
264
+ var h, l, o;
265
+ const i = Array.from(e), n = t || ((l = (h = i[0]) == null ? void 0 : h.webkitRelativePath) == null ? void 0 : l.split(/[/\\]/)[0]) || ((o = i[0]) == null ? void 0 : o.name) || "工作文件夹", a = i.map((c) => ({
266
+ name: c.name,
267
+ webkitRelativePath: c.webkitRelativePath,
268
+ lastModified: c.lastModified,
269
+ blob: c
270
+ }));
271
+ this.attachAdapter(new L(a, n), n);
272
+ }
213
273
  /** 直接挂载一个 Adapter(测试或自定义后端),视为已授权。 */
214
274
  attachAdapter(e, t = e.displayName) {
215
- this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this.pendingHandle = null, this._adapter = e, this.setStatus("granted", t);
275
+ this.epoch += 1, this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this.pendingHandle = null, this.replaceAdapter(e), this.setStatus("granted", t);
216
276
  }
217
277
  /**
218
278
  * 通知目录树重读。`paths` 是相对工作区根的目录;省略时重读当前展开的全部目录。
@@ -224,7 +284,7 @@ class J {
224
284
  this.refreshAllVisible = !0;
225
285
  else
226
286
  for (const t of e) {
227
- const i = K(t);
287
+ const i = M(t);
228
288
  i === void 0 ? this.refreshAllVisible = !0 : this.pendingChangePaths.add(i);
229
289
  }
230
290
  clearTimeout(this.changeTimer), this.changeTimer = setTimeout(() => this.flushFilesChanged(), 150);
@@ -232,19 +292,29 @@ class J {
232
292
  }
233
293
  /** @internal 工具执行中遇到权限错误时调用,重新检查并更新状态。 */
234
294
  handlePermissionLost() {
235
- return o(this, null, function* () {
295
+ return d(this, null, function* () {
236
296
  const e = this.pendingHandle;
237
297
  if (!(e != null && e.queryPermission))
238
298
  return;
239
- const t = yield e.queryPermission(p).catch(() => "prompt");
240
- t !== "granted" && (this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this._adapter = null, this.setStatus(t === "denied" ? "denied" : "prompt", e.name));
299
+ const t = yield e.queryPermission(m).catch(() => "prompt");
300
+ if (t !== "granted") {
301
+ if (t === "prompt" && this._adapter)
302
+ try {
303
+ yield this._adapter.listEntries("");
304
+ return;
305
+ } catch (i) {
306
+ if ((i && typeof i == "object" ? i.name : void 0) !== "NotAllowedError")
307
+ return;
308
+ }
309
+ this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this.replaceAdapter(null), this.setStatus(t === "denied" ? "denied" : "prompt", e.name);
310
+ }
241
311
  });
242
312
  }
243
313
  // -------------------------------------------------------------------------
244
314
  // 外发提示
245
315
  // -------------------------------------------------------------------------
246
316
  isDisclosureAcknowledged() {
247
- return o(this, null, function* () {
317
+ return d(this, null, function* () {
248
318
  try {
249
319
  return !!(yield this.store.get(this.disclosureKey));
250
320
  } catch (e) {
@@ -253,7 +323,7 @@ class J {
253
323
  });
254
324
  }
255
325
  acknowledgeDisclosure() {
256
- return o(this, null, function* () {
326
+ return d(this, null, function* () {
257
327
  yield this.store.set(this.disclosureKey, !0).catch(() => {
258
328
  });
259
329
  });
@@ -281,6 +351,22 @@ class J {
281
351
  e || (e = !0, this.activeCalls--);
282
352
  };
283
353
  }
354
+ /**
355
+ * 占用一个浏览器运行时的命令名额。本地沙箱在时页面不设上限,并发由沙箱的 exec.maxConcurrent 决定。
356
+ * 浏览器运行时一次只放一条。
357
+ */
358
+ acquireCommand() {
359
+ if (this._adapter instanceof W)
360
+ return () => {
361
+ };
362
+ if (this.activeCommands >= 1)
363
+ return null;
364
+ this.activeCommands++;
365
+ let e = !1;
366
+ return () => {
367
+ e || (e = !0, this.activeCommands--);
368
+ };
369
+ }
284
370
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
285
371
  track(e) {
286
372
  return this.inflight.add(e), () => this.inflight.delete(e);
@@ -291,14 +377,14 @@ class J {
291
377
  this.inflight.clear(), e.forEach((t) => t.abort());
292
378
  }
293
379
  handshake() {
294
- const e = Object.fromEntries(T.map((t) => [t, !0]));
380
+ const e = Object.fromEntries(I.map((t) => [t, !0]));
295
381
  return {
296
382
  protocolVersion: "1.0",
297
- capabilities: A(f({}, e), {
383
+ capabilities: C(u({}, e), {
298
384
  cancellation: !0,
299
385
  atomicWrite: !0
300
386
  }),
301
- limits: f({}, this.limits)
387
+ limits: u({}, this.limits)
302
388
  };
303
389
  }
304
390
  // -------------------------------------------------------------------------
@@ -320,7 +406,7 @@ class J {
320
406
  }
321
407
  flushFilesChanged() {
322
408
  this.changeTimer = void 0;
323
- const e = this.refreshAllVisible, t = [...this.pendingChangePaths].sort((i, a) => i < a ? -1 : i > a ? 1 : 0);
409
+ const e = this.refreshAllVisible, t = [...this.pendingChangePaths].sort((i, n) => i < n ? -1 : i > n ? 1 : 0);
324
410
  this.pendingChangePaths.clear(), this.refreshAllVisible = !1, this._status === "granted" && this.emit("files:changed", {
325
411
  paths: e ? [] : t
326
412
  });
@@ -330,10 +416,10 @@ class J {
330
416
  try {
331
417
  this.event.emit(e, t);
332
418
  } catch (i) {
333
- console.error(`[LocalWorkspace] ${e} listener failed`, i);
419
+ P.report(`${e} listener failed`, i);
334
420
  }
335
421
  }
336
422
  }
337
423
  export {
338
- J as LocalWorkspace
424
+ ne as LocalWorkspace
339
425
  };