@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glodon-aiot/bot-client-sdk",
3
- "version": "3.26.0-alpha.4",
3
+ "version": "3.26.0-alpha.5",
4
4
  "author": "glodoncv",
5
5
  "description": "aiot bot client js sdk",
6
6
  "type": "module",
@@ -37,6 +37,10 @@
37
37
  "check": "yarn prettier --check .",
38
38
  "write": "yarn prettier --write .",
39
39
  "lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
40
+ "build:just-bash": "node scripts/build-just-bash.mjs",
41
+ "upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
42
+ "build:pyodide": "node scripts/build-pyodide.mjs",
43
+ "upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
40
44
  "test": "vitest run",
41
45
  "test:watch": "vitest"
42
46
  },
@@ -62,8 +66,10 @@
62
66
  "express": "4",
63
67
  "http-proxy-middleware": "^3.0.0",
64
68
  "identity-obj-proxy": "^3.0.0",
69
+ "just-bash": "3.6.0",
65
70
  "npm-run-all": "^4.1.5",
66
71
  "prettier": "2.7.1",
72
+ "pyodide": "314.0.7",
67
73
  "rollup-plugin-visualizer": "^6.0.1",
68
74
  "socket.io": "^4.7.5",
69
75
  "ts-node": "^10.9.2",
@@ -82,7 +88,7 @@
82
88
  "registry": "https://registry.npmjs.org/"
83
89
  },
84
90
  "dependencies": {
85
- "@glodon-aiot/apis": "^3.26.0-alpha.4",
91
+ "@glodon-aiot/apis": "^3.26.0-alpha.5",
86
92
  "axios": "0.24.0",
87
93
  "buffer": "^6.0.3",
88
94
  "dayjs": "^1.11.13",
@@ -1,196 +0,0 @@
1
- var b = (r, i, a) => new Promise((m, c) => {
2
- var d = (t) => {
3
- try {
4
- u(a.next(t));
5
- } catch (s) {
6
- c(s);
7
- }
8
- }, e = (t) => {
9
- try {
10
- u(a.throw(t));
11
- } catch (s) {
12
- c(s);
13
- }
14
- }, u = (t) => t.done ? m(t.value) : Promise.resolve(t.value).then(d, e);
15
- u((a = a.apply(r, i)).next());
16
- });
17
- import { v4 as _ } from "uuid";
18
- import { HostBridgeAdapter as P } from "./adapters/HostBridgeAdapter.mjs";
19
- import { LOCAL_PYTHON_FUNCTION_CODE as T, WORKSPACE_GRANT_ID as A, PYTHON_MAX_ARGS as R, PYTHON_DEFAULT_TIMEOUT_MS as L } from "./constants.mjs";
20
- import { ToolError as o, ToolCode as n, cancelledError as w, workspaceNotGranted as O, toToolError as q } from "./errors.mjs";
21
- import { assertGrantId as F, normalizeWorkspacePath as M } from "./security/pathPolicy.mjs";
22
- import { validateToolInput as C } from "./validate.mjs";
23
- const S = /^[\p{L}\p{N}_./:@=+\-,]+$/u, B = {
24
- type: "object",
25
- required: ["grantId", "path"],
26
- properties: {
27
- grantId: {
28
- type: "string",
29
- enum: [A]
30
- },
31
- path: {
32
- type: "string",
33
- minLength: 1
34
- },
35
- args: {
36
- type: "array",
37
- items: {
38
- type: "string",
39
- minLength: 1
40
- }
41
- },
42
- timeoutMs: {
43
- type: "integer",
44
- minimum: 1e3,
45
- maximum: 12e4
46
- }
47
- }
48
- };
49
- function G(r) {
50
- const i = r instanceof DOMException ? r.name : "", a = r instanceof Error ? r.message : "";
51
- switch (i) {
52
- case "NotFoundError":
53
- return new o(n.NotFound, "脚本不存在。");
54
- case "TypeMismatchError":
55
- return new o(n.BadRequest, "只能运行 .py 文件。");
56
- case "SecurityError":
57
- return new o(n.BadRequest, "脚本路径不合法。");
58
- case "AbortError":
59
- return a.includes("已有") ? new o(n.TooManyRequests, "已有一个脚本在沙箱里运行。") : new o(n.Timeout, "脚本运行超时,已中止。");
60
- default:
61
- return new o(n.NotImplemented, "当前环境不能运行本地脚本。");
62
- }
63
- }
64
- function j(r, i, a, m, c) {
65
- return b(this, null, function* () {
66
- if (!i)
67
- throw new o(n.Forbidden, "当前环境未提供脚本运行确认,无法执行。", {
68
- reason: "approval_unavailable"
69
- });
70
- if (c.aborted)
71
- throw w();
72
- const d = new AbortController(), e = () => d.abort();
73
- c.addEventListener("abort", e, {
74
- once: !0
75
- });
76
- let u;
77
- try {
78
- const t = yield Promise.race([Promise.resolve().then(() => {
79
- var s;
80
- return i({
81
- requestId: m.requestId,
82
- sessionId: m.sessionId,
83
- path: a.path,
84
- args: a.args,
85
- workspaceName: (s = r.displayName) != null ? s : "",
86
- signal: d.signal
87
- });
88
- }), new Promise((s) => {
89
- u = setTimeout(() => s(!1), r.limits.approvalTimeoutMs);
90
- })]);
91
- if (c.aborted)
92
- throw w();
93
- if (t !== !0)
94
- throw new o(n.Forbidden, "用户拒绝了本次脚本运行。", {
95
- reason: "user_rejected"
96
- });
97
- } catch (t) {
98
- throw t instanceof o ? t : new o(n.Forbidden, "脚本运行确认失败,已取消本次运行。", {
99
- reason: "user_rejected"
100
- });
101
- } finally {
102
- clearTimeout(u), c.removeEventListener("abort", e), d.abort();
103
- }
104
- });
105
- }
106
- function D(r, i, a, m, c) {
107
- return b(this, null, function* () {
108
- var u, t, s, g;
109
- const d = new AbortController(), e = () => d.abort();
110
- (u = m.signal) == null || u.addEventListener("abort", e);
111
- try {
112
- const l = typeof i == "string" ? JSON.parse(i) : i;
113
- if (l && typeof l == "object" && !Array.isArray(l)) {
114
- const h = l;
115
- (h.grantId === void 0 || h.grantId === null || h.grantId === "") && (h.grantId = A);
116
- }
117
- const f = C(l, B);
118
- F(f.grantId);
119
- const p = M(f.path);
120
- if (!p.toLowerCase().endsWith(".py"))
121
- throw new o(n.BadRequest, "只能运行工程内已有的 .py 文件。");
122
- const y = (t = f.args) != null ? t : [];
123
- if (y.length > R || y.some((h) => !S.test(h)))
124
- throw new o(n.BadRequest, "脚本参数不合法。每个参数单独填写,不能包含空格或 shell 语法。");
125
- const E = r.sensitive.match(p, "read");
126
- if (E)
127
- throw new o(n.Forbidden, "该脚本被列为敏感文件,不能运行。", {
128
- reason: "sensitive_file",
129
- ruleId: E.id
130
- });
131
- if (yield r.ready, d.signal.aborted)
132
- throw w();
133
- const I = r.adapter;
134
- if (!I)
135
- throw O();
136
- if (!(I instanceof P))
137
- throw new o(n.NotImplemented, "当前环境不能运行本地脚本。");
138
- yield j(r, c, {
139
- path: p,
140
- args: y
141
- }, m, d.signal);
142
- const v = yield I.runPython(p, y, (s = f.timeoutMs) != null ? s : L, d.signal);
143
- r.notifyFilesChanged();
144
- const N = {
145
- code: n.Ok,
146
- message: "ok",
147
- data: v
148
- };
149
- a(N);
150
- } catch (l) {
151
- const f = d.signal.aborted ? w() : l instanceof SyntaxError ? new o(n.BadRequest, "参数不是合法的 JSON 对象。") : l instanceof o ? l : G(l), p = q(f);
152
- a({
153
- code: p.code,
154
- message: p.message,
155
- data: p.data
156
- });
157
- } finally {
158
- (g = m.signal) == null || g.removeEventListener("abort", e);
159
- }
160
- });
161
- }
162
- function X({
163
- pluginCode: r,
164
- workspace: i,
165
- onApprovalRequired: a
166
- }) {
167
- const m = (c, d, e) => {
168
- var s, g, l;
169
- let u = !1;
170
- D(i, c, (f) => {
171
- if (!u) {
172
- u = !0;
173
- try {
174
- d(f);
175
- } catch (p) {
176
- console.error("[LocalPython] callback failed", p);
177
- }
178
- }
179
- }, {
180
- requestId: (s = e == null ? void 0 : e.requestId) != null ? s : _(),
181
- applicationId: (g = e == null ? void 0 : e.applicationId) != null ? g : i.applicationId,
182
- sessionId: (l = e == null ? void 0 : e.sessionId) != null ? l : "",
183
- pluginCode: r,
184
- functionCode: T,
185
- signal: e == null ? void 0 : e.signal
186
- }, a);
187
- };
188
- return {
189
- [r]: {
190
- [T]: m
191
- }
192
- };
193
- }
194
- export {
195
- X as createLocalPythonPlugin
196
- };