@glodon-aiot/bot-client-sdk 3.26.0-alpha.4 → 3.26.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +105 -76
  2. package/dist/es/Config.mjs +63 -85
  3. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  4. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  5. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  6. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  7. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  8. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  9. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  10. package/dist/es/builtinTools/command.mjs +56 -0
  11. package/dist/es/builtinTools/constants.mjs +10 -0
  12. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +236 -0
  13. package/dist/es/builtinTools/overview.mjs +77 -0
  14. package/dist/es/builtinTools/paths.mjs +63 -0
  15. package/dist/es/builtinTools/schemas.mjs +216 -0
  16. package/dist/es/builtinTools/tools.mjs +471 -0
  17. package/dist/es/index.mjs +49 -48
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +193 -103
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +138 -77
  20. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  21. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  22. package/dist/es/localFiles/constants.mjs +1 -1
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +22 -18
  24. package/dist/es/localFiles/host/protocol.mjs +6 -5
  25. package/dist/es/localFiles/schemas.mjs +45 -60
  26. package/dist/es/localFiles/validate.mjs +37 -37
  27. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +71 -52
  28. package/dist/es/package.json.mjs +33 -27
  29. package/dist/lib/index.js +372 -9
  30. package/dist/src/Config.d.ts +2 -2
  31. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  32. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  33. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  34. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  35. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  36. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  37. package/dist/src/builtinTools/command.d.ts +26 -0
  38. package/dist/src/builtinTools/constants.d.ts +17 -0
  39. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  40. package/dist/src/builtinTools/overview.d.ts +5 -0
  41. package/dist/src/builtinTools/paths.d.ts +15 -0
  42. package/dist/src/builtinTools/schemas.d.ts +3 -0
  43. package/dist/src/builtinTools/tools.d.ts +60 -0
  44. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  45. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +20 -1
  46. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  47. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +14 -0
  48. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  49. package/dist/src/localFiles/constants.d.ts +2 -1
  50. package/dist/src/localFiles/host/protocol.d.ts +13 -0
  51. package/dist/src/localFiles/index.d.ts +3 -2
  52. package/dist/src/localFiles/schemas.d.ts +2 -3
  53. package/dist/src/localFiles/types.d.ts +14 -1
  54. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +12 -0
  55. package/package.json +8 -2
  56. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -1,46 +1,46 @@
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, C = Object.defineProperties;
2
+ var P = Object.getOwnPropertyDescriptors;
3
+ var _ = Object.getOwnPropertySymbols;
4
+ var H = Object.prototype.hasOwnProperty, R = 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, m = (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
+ H.call(e, t) && p(r, t, e[t]);
8
+ if (_)
9
+ for (var t of _(e))
10
+ R.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
+ }, k = (r, e) => C(r, P(e));
13
+ var s = (r, e, t) => (p(r, typeof e != "symbol" ? e + "" : e, t), t);
14
+ var o = (r, e, t) => new Promise((i, n) => {
15
+ var a = (l) => {
16
16
  try {
17
17
  c(t.next(l));
18
18
  } catch (d) {
19
- a(d);
19
+ n(d);
20
20
  }
21
21
  }, h = (l) => {
22
22
  try {
23
23
  c(t.throw(l));
24
24
  } catch (d) {
25
- a(d);
25
+ n(d);
26
26
  }
27
- }, c = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(n, h);
27
+ }, c = (l) => l.done ? i(l.value) : Promise.resolve(l.value).then(a, h);
28
28
  c((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";
30
+ import b from "../../EventBus.mjs";
31
+ import { FileSystemAccessAdapter as D } from "../adapters/FileSystemAccessAdapter.mjs";
32
+ import { getNativeDirectoryPicker as T } from "../adapters/fsaTypes.mjs";
33
+ import { LOCAL_FILES_FUNCTION_CODES as F } from "../constants.mjs";
34
+ import { getDownloadUrlAllowlist as W } from "../security/downloadUrlPolicy.mjs";
35
+ import { SensitiveFilePolicy as q } from "../security/sensitiveFiles.mjs";
36
+ import { resolveLimits as I } from "../limits.mjs";
37
+ import { createDefaultSessionFileTransfer as L } from "../transfer/SessionFileTransfer.mjs";
38
+ import { createMemoryStore as N } from "./handleStore.mjs";
39
39
  import { watchDirectoryHandle as E } from "./watchDirectory.mjs";
40
- const p = {
40
+ const u = {
41
41
  mode: "readwrite"
42
42
  };
43
- function K(r) {
43
+ function U(r) {
44
44
  const e = r.replace(/\\/g, "/").trim().replace(/^\.\/+/, "").replace(/\/+$/, "");
45
45
  if (!e || e === ".")
46
46
  return "";
@@ -50,10 +50,10 @@ function K(r) {
50
50
  if (!t.some((i) => !i || i === "." || i === ".."))
51
51
  return t.join("/");
52
52
  }
53
- function L(r) {
53
+ function x(r) {
54
54
  return !!r && typeof r == "object" && r.name === "AbortError";
55
55
  }
56
- class J {
56
+ class X {
57
57
  constructor(e) {
58
58
  s(this, "applicationId");
59
59
  s(this, "limits");
@@ -62,15 +62,18 @@ class J {
62
62
  s(this, "allowWorkspaceWideTextSearch");
63
63
  s(this, "transfer");
64
64
  s(this, "fetch");
65
+ s(this, "commandRunner");
66
+ s(this, "browserRuntime");
65
67
  s(this, "store");
66
68
  s(this, "picker");
67
- s(this, "event", new H(!0));
69
+ s(this, "event", new b(!0));
68
70
  s(this, "_status");
69
71
  s(this, "_displayName");
70
72
  s(this, "_adapter", null);
71
73
  s(this, "pendingHandle", null);
72
74
  s(this, "approvalHandler");
73
75
  s(this, "activeCalls", 0);
76
+ s(this, "commandRunning", !1);
74
77
  s(this, "inflight", /* @__PURE__ */ new Set());
75
78
  s(this, "_ready", Promise.resolve());
76
79
  s(this, "stopWatching", () => {
@@ -78,17 +81,23 @@ class J {
78
81
  s(this, "pendingChangePaths", /* @__PURE__ */ new Set());
79
82
  s(this, "changeTimer");
80
83
  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(() => {
84
+ var h, c, l, d, f, g, y, v, w, A;
85
+ const t = (h = e.config) != null ? h : {};
86
+ this.applicationId = e.applicationId, this.store = (c = e.store) != null ? c : N(), this.picker = e.picker === null ? void 0 : (l = e.picker) != null ? l : T(), this.limits = I(t.limits), this.sensitive = new q(t.sensitiveRulesAppend), this.downloadUrlAllowlist = W(t.downloadUrlAllowlistAppend), this.allowWorkspaceWideTextSearch = !!t.allowWorkspaceWideTextSearch, this.approvalHandler = t.onApprovalRequired;
87
+ const i = (d = e.transfer) != null ? d : L(() => {
85
88
  });
86
89
  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
90
+ upload: (g = (f = t.transfer) == null ? void 0 : f.upload) != null ? g : i.upload,
91
+ resolveDownload: (v = (y = t.transfer) == null ? void 0 : y.resolveDownload) != null ? v : i.resolveDownload
89
92
  };
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";
93
+ const n = (w = e.fetch) != null ? w : typeof fetch == "function" ? fetch : void 0;
94
+ this.fetch = n ? n.bind(globalThis) : () => Promise.reject(new Error("fetch is not available")), this.commandRunner = e.commandRunner;
95
+ const a = (A = t.commandRuntime) == null ? void 0 : A.browser;
96
+ this.browserRuntime = {
97
+ enabled: (a == null ? void 0 : a.enabled) !== !1,
98
+ bashModuleURL: a == null ? void 0 : a.bashModuleURL,
99
+ pyodideIndexURL: a == null ? void 0 : a.pyodideIndexURL
100
+ }, this._status = this.picker ? "none" : "unsupported";
92
101
  }
93
102
  // -------------------------------------------------------------------------
94
103
  // 状态
@@ -124,7 +133,7 @@ class J {
124
133
  }));
125
134
  }
126
135
  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));
136
+ this.cancelFilesChanged(), this.pendingHandle = e, this._adapter = new D(e), this.setStatus("granted", e.name), this.unwatchDirectory(), this.stopWatching = E(e, (t) => this.notifyFilesChanged(t));
128
137
  }
129
138
  // -------------------------------------------------------------------------
130
139
  // 授权
@@ -145,9 +154,9 @@ class J {
145
154
  return Promise.reject(t);
146
155
  }
147
156
  return e.then((t) => o(this, null, function* () {
148
- var a, n;
157
+ var n, a;
149
158
  this.cancelAll();
150
- const i = (n = yield (a = t.queryPermission) == null ? void 0 : a.call(t, p)) != null ? n : "granted";
159
+ const i = (a = yield (n = t.queryPermission) == null ? void 0 : n.call(t, u)) != null ? a : "granted";
151
160
  return yield this.store.set(this.handleKey, {
152
161
  handle: t,
153
162
  displayName: t.name,
@@ -155,7 +164,7 @@ class J {
155
164
  }).catch(() => {
156
165
  }), i === "denied" ? (this.pendingHandle = t, this._adapter = null, this.setStatus("denied", t.name), !1) : (this.attachHandle(t), !0);
157
166
  }), (t) => {
158
- if (L(t))
167
+ if (x(t))
159
168
  return !1;
160
169
  throw t;
161
170
  });
@@ -166,7 +175,7 @@ class J {
166
175
  }
167
176
  doRestore() {
168
177
  return o(this, null, function* () {
169
- var i, a, n;
178
+ var i, n, a;
170
179
  if (!this.picker) {
171
180
  this._adapter || this.setStatus("unsupported");
172
181
  return;
@@ -183,7 +192,7 @@ class J {
183
192
  }
184
193
  let t;
185
194
  try {
186
- t = (n = yield (a = (i = e.handle).queryPermission) == null ? void 0 : a.call(i, p)) != null ? n : "prompt";
195
+ t = (a = yield (n = (i = e.handle).queryPermission) == null ? void 0 : n.call(i, u)) != null ? a : "prompt";
187
196
  } catch (h) {
188
197
  t = "prompt";
189
198
  }
@@ -197,7 +206,7 @@ class J {
197
206
  return Promise.resolve(!1);
198
207
  let t;
199
208
  try {
200
- t = e.requestPermission(p);
209
+ t = e.requestPermission(u);
201
210
  } catch (i) {
202
211
  return Promise.reject(i);
203
212
  }
@@ -224,7 +233,7 @@ class J {
224
233
  this.refreshAllVisible = !0;
225
234
  else
226
235
  for (const t of e) {
227
- const i = K(t);
236
+ const i = U(t);
228
237
  i === void 0 ? this.refreshAllVisible = !0 : this.pendingChangePaths.add(i);
229
238
  }
230
239
  clearTimeout(this.changeTimer), this.changeTimer = setTimeout(() => this.flushFilesChanged(), 150);
@@ -236,7 +245,7 @@ class J {
236
245
  const e = this.pendingHandle;
237
246
  if (!(e != null && e.queryPermission))
238
247
  return;
239
- const t = yield e.queryPermission(p).catch(() => "prompt");
248
+ const t = yield e.queryPermission(u).catch(() => "prompt");
240
249
  t !== "granted" && (this.cancelAll(), this.cancelFilesChanged(), this.unwatchDirectory(), this._adapter = null, this.setStatus(t === "denied" ? "denied" : "prompt", e.name));
241
250
  });
242
251
  }
@@ -281,6 +290,16 @@ class J {
281
290
  e || (e = !0, this.activeCalls--);
282
291
  };
283
292
  }
293
+ /** @internal 同一工作区同一时间只跑一个命令;已有命令在运行时返回 null。 */
294
+ acquireCommand() {
295
+ if (this.commandRunning)
296
+ return null;
297
+ this.commandRunning = !0;
298
+ let e = !1;
299
+ return () => {
300
+ e || (e = !0, this.commandRunning = !1);
301
+ };
302
+ }
284
303
  /** @internal 登记进行中的调用,更换或断开工作区时统一中止。 */
285
304
  track(e) {
286
305
  return this.inflight.add(e), () => this.inflight.delete(e);
@@ -291,14 +310,14 @@ class J {
291
310
  this.inflight.clear(), e.forEach((t) => t.abort());
292
311
  }
293
312
  handshake() {
294
- const e = Object.fromEntries(T.map((t) => [t, !0]));
313
+ const e = Object.fromEntries(F.map((t) => [t, !0]));
295
314
  return {
296
315
  protocolVersion: "1.0",
297
- capabilities: A(f({}, e), {
316
+ capabilities: k(m({}, e), {
298
317
  cancellation: !0,
299
318
  atomicWrite: !0
300
319
  }),
301
- limits: f({}, this.limits)
320
+ limits: m({}, this.limits)
302
321
  };
303
322
  }
304
323
  // -------------------------------------------------------------------------
@@ -320,7 +339,7 @@ class J {
320
339
  }
321
340
  flushFilesChanged() {
322
341
  this.changeTimer = void 0;
323
- const e = this.refreshAllVisible, t = [...this.pendingChangePaths].sort((i, a) => i < a ? -1 : i > a ? 1 : 0);
342
+ const e = this.refreshAllVisible, t = [...this.pendingChangePaths].sort((i, n) => i < n ? -1 : i > n ? 1 : 0);
324
343
  this.pendingChangePaths.clear(), this.refreshAllVisible = !1, this._status === "granted" && this.emit("files:changed", {
325
344
  paths: e ? [] : t
326
345
  });
@@ -335,5 +354,5 @@ class J {
335
354
  }
336
355
  }
337
356
  export {
338
- J as LocalWorkspace
357
+ X as LocalWorkspace
339
358
  };
@@ -1,11 +1,11 @@
1
- const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.4", i = "glodoncv", s = "aiot bot client js sdk", n = "module", y = !1, o = [
1
+ const e = "@glodon-aiot/bot-client-sdk", s = "3.26.0-alpha.5", t = "glodoncv", i = "aiot bot client js sdk", n = "module", g = !1, o = [
2
2
  "aiot",
3
3
  "bot",
4
4
  "bot client",
5
5
  "sdk"
6
- ], l = [
6
+ ], d = [
7
7
  "dist"
8
- ], p = "./dist/es/index.mjs", c = "./dist/lib/index.js", r = "./dist/src/index.d.ts", d = {
8
+ ], p = "./dist/es/index.mjs", l = "./dist/lib/index.js", c = "./dist/src/index.d.ts", r = {
9
9
  ".": {
10
10
  import: "./dist/es/index.mjs",
11
11
  require: "./dist/lib/index.js",
@@ -23,9 +23,13 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.4", i = "glodoncv", s
23
23
  check: "yarn prettier --check .",
24
24
  write: "yarn prettier --write .",
25
25
  lint: "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
26
+ "build:just-bash": "node scripts/build-just-bash.mjs",
27
+ "upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
28
+ "build:pyodide": "node scripts/build-pyodide.mjs",
29
+ "upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
26
30
  test: "vitest run",
27
31
  "test:watch": "vitest"
28
- }, g = {
32
+ }, b = {
29
33
  "@babel/core": "^7.20.12",
30
34
  "@commitlint/cli": "^17.0.3",
31
35
  "@commitlint/config-conventional": "^17.0.3",
@@ -47,8 +51,10 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.4", i = "glodoncv", s
47
51
  express: "4",
48
52
  "http-proxy-middleware": "^3.0.0",
49
53
  "identity-obj-proxy": "^3.0.0",
54
+ "just-bash": "3.6.0",
50
55
  "npm-run-all": "^4.1.5",
51
56
  prettier: "2.7.1",
57
+ pyodide: "314.0.7",
52
58
  "rollup-plugin-visualizer": "^6.0.1",
53
59
  "socket.io": "^4.7.5",
54
60
  "ts-node": "^10.9.2",
@@ -61,53 +67,53 @@ const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.4", i = "glodoncv", s
61
67
  }, m = {
62
68
  access: "public",
63
69
  registry: "https://registry.npmjs.org/"
64
- }, b = {
65
- "@glodon-aiot/apis": "^3.26.0-alpha.4",
70
+ }, y = {
71
+ "@glodon-aiot/apis": "^3.26.0-alpha.5",
66
72
  axios: "0.24.0",
67
73
  buffer: "^6.0.3",
68
74
  dayjs: "^1.11.13",
69
75
  "js-base64": "^3.7.7",
70
76
  "socket.io-client": "^4.7.5",
71
77
  uuid: "^11.1.0"
72
- }, x = {
78
+ }, j = {
73
79
  name: e,
74
- version: t,
75
- author: i,
76
- description: s,
80
+ version: s,
81
+ author: t,
82
+ description: i,
77
83
  type: n,
78
84
  sideEffects: !1,
79
85
  keywords: o,
80
- files: l,
86
+ files: d,
81
87
  module: p,
82
- main: c,
83
- typings: r,
84
- exports: d,
88
+ main: l,
89
+ typings: c,
90
+ exports: r,
85
91
  license: a,
86
92
  scripts: u,
87
- devDependencies: g,
93
+ devDependencies: b,
88
94
  "lint-staged": {
89
95
  "*.{js,css,md,jsx,less,ts,tsx,json}": "prettier --write"
90
96
  },
91
97
  publishConfig: m,
92
- dependencies: b
98
+ dependencies: y
93
99
  };
94
100
  export {
95
- i as author,
96
- x as default,
97
- b as dependencies,
98
- s as description,
99
- g as devDependencies,
100
- d as exports,
101
- l as files,
101
+ t as author,
102
+ j as default,
103
+ y as dependencies,
104
+ i as description,
105
+ b as devDependencies,
106
+ r as exports,
107
+ d as files,
102
108
  o as keywords,
103
109
  a as license,
104
- c as main,
110
+ l as main,
105
111
  p as module,
106
112
  e as name,
107
113
  m as publishConfig,
108
114
  u as scripts,
109
- y as sideEffects,
115
+ g as sideEffects,
110
116
  n as type,
111
- r as typings,
112
- t as version
117
+ c as typings,
118
+ s as version
113
119
  };