@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
@@ -0,0 +1,207 @@
1
+ var L = Object.defineProperty;
2
+ var B = Object.getOwnPropertySymbols;
3
+ var T = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
4
+ var P = (e, o, t) => o in e ? L(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t, $ = (e, o) => {
5
+ for (var t in o || (o = {}))
6
+ T.call(o, t) && P(e, t, o[t]);
7
+ if (B)
8
+ for (var t of B(o))
9
+ k.call(o, t) && P(e, t, o[t]);
10
+ return e;
11
+ };
12
+ var y = (e, o, t) => new Promise((r, n) => {
13
+ var l = (f) => {
14
+ try {
15
+ d(t.next(f));
16
+ } catch (u) {
17
+ n(u);
18
+ }
19
+ }, a = (f) => {
20
+ try {
21
+ d(t.throw(f));
22
+ } catch (u) {
23
+ n(u);
24
+ }
25
+ }, d = (f) => f.done ? r(f.value) : Promise.resolve(f.value).then(l, a);
26
+ d((t = t.apply(e, o)).next());
27
+ });
28
+ import { refreshBuiltinPlugins as z } from "../Config.mjs";
29
+ import H from "../Logger.mjs";
30
+ import { retainMcpSessions as A, listMcpTools as O, dropUnusedMcpSession as I, callMcpTool as U } from "./client.mjs";
31
+ import { currentLocalMcpEndpoints as b } from "./endpoints.mjs";
32
+ import { replaceLocalMcpTools as E, localMcpBindings as D, localMcpBinding as R } from "./registry.mjs";
33
+ const m = new H("[LocalMcp] ");
34
+ function Z(e) {
35
+ const o = e == null ? void 0 : e.mcps;
36
+ return Array.isArray(o) ? o.filter((t) => t && typeof t == "object" && t.runtime === "local" && t.id) : [];
37
+ }
38
+ function F(e, o, t) {
39
+ return e == null || e.includes(o) ? !0 : !!t && e.includes(t);
40
+ }
41
+ function V(e) {
42
+ if (!e || typeof e != "object")
43
+ return {};
44
+ const o = {};
45
+ for (const [t, r] of Object.entries(e))
46
+ typeof r == "string" && (o[t] = r);
47
+ return o;
48
+ }
49
+ function W(e) {
50
+ var a, d;
51
+ if (!e || typeof e != "object")
52
+ return null;
53
+ const o = e;
54
+ if (typeof o.code == "number" && o.code !== 200)
55
+ return null;
56
+ const t = o.data && typeof o.data == "object" ? o.data : o, r = typeof t.code == "string" ? t.code : "", n = r ? (a = t.mcpServers) == null ? void 0 : a[r] : void 0, l = typeof (n == null ? void 0 : n.url) == "string" ? n.url : void 0;
57
+ return {
58
+ code: r,
59
+ deployType: typeof ((d = t.deployConfig) == null ? void 0 : d.type) == "string" ? t.deployConfig.type : void 0,
60
+ url: l,
61
+ headers: V(n == null ? void 0 : n.headers)
62
+ };
63
+ }
64
+ function q(n, l, a) {
65
+ return y(this, arguments, function* (e, o, t, r = fetch) {
66
+ const d = e.replace(/\/$/, ""), f = o.startsWith("Bearer ") ? o : `Bearer ${o}`, u = yield r(`${d}/mcpmgr/v1/mcpserver/${encodeURIComponent(t)}`, {
67
+ headers: {
68
+ Authorization: f
69
+ }
70
+ }), g = yield u.json().catch(() => null);
71
+ if (!u.ok)
72
+ throw new Error(`MCP 详情 HTTP ${u.status}`);
73
+ const h = W(g);
74
+ if (!h)
75
+ throw new Error("MCP 详情不可用");
76
+ return h;
77
+ });
78
+ }
79
+ function G(e) {
80
+ return /^[A-Za-z][A-Za-z0-9.+-]* /.test(e) ? e : `Bearer ${e}`;
81
+ }
82
+ function J(e, o) {
83
+ if (!(o != null && o.token))
84
+ return $({}, e);
85
+ const t = {};
86
+ for (const [r, n] of Object.entries(e))
87
+ r.toLowerCase() !== "authorization" && (t[r] = n);
88
+ return t.Authorization = G(o.token), t;
89
+ }
90
+ function K(e, o, t) {
91
+ const r = e.find((n) => !o.has(n) && t(n));
92
+ return r && o.add(r), r;
93
+ }
94
+ function N(e, o, t) {
95
+ return K(e, o, (r) => r.code === t || r.id === t);
96
+ }
97
+ function Q(e, o, t) {
98
+ var l;
99
+ const r = e == null ? void 0 : e.mcpServers;
100
+ if (!r)
101
+ return;
102
+ const n = (l = r[t]) != null ? l : r[o];
103
+ return (n == null ? void 0 : n.url) || void 0;
104
+ }
105
+ function X(e, o) {
106
+ return (t, r, n) => {
107
+ const l = R(e);
108
+ if (!l) {
109
+ r({
110
+ code: 500,
111
+ message: "缺少 MCP 地址"
112
+ });
113
+ return;
114
+ }
115
+ U(l, e, t, n == null ? void 0 : n.signal, o).then((a) => r({
116
+ code: 0,
117
+ message: "ok",
118
+ data: a
119
+ })).catch((a) => {
120
+ r({
121
+ code: 500,
122
+ message: a instanceof Error ? a.message : String(a)
123
+ });
124
+ });
125
+ };
126
+ }
127
+ function ne(e) {
128
+ return y(this, null, function* () {
129
+ var h, _;
130
+ const o = (h = e.fetchImpl) != null ? h : fetch, t = e.initMcp ? Object.keys((_ = e.initMcp.mcpServers) != null ? _ : {}) : null, r = Z(e.arrange), n = b().revision, l = () => b().revision !== n || (e.isCurrent ? !e.isCurrent() : !1);
131
+ if (!r.length) {
132
+ if (l())
133
+ return;
134
+ m.log("编排里没有 runtime=local 的 MCP,不发送 register_client_mcp_tools"), E([]), A([]), z();
135
+ return;
136
+ }
137
+ const a = [...b().servers], d = /* @__PURE__ */ new Set(), f = yield Promise.all(r.map((c) => y(this, null, function* () {
138
+ var j, w;
139
+ const s = c.id;
140
+ let p;
141
+ const v = () => {
142
+ p && (d.delete(p), p = void 0);
143
+ };
144
+ try {
145
+ const i = yield q(e.apiRoot, e.token, s, o);
146
+ if (!F(t, s, i.code))
147
+ return null;
148
+ p = i.code ? N(a, d, i.code) : void 0;
149
+ const C = (w = (j = p == null ? void 0 : p.url) != null ? j : Q(e.initMcp, s, i.code)) != null ? w : i.url;
150
+ if (i.deployType !== "streamableHttp" || !i.code || !C)
151
+ return m.log("skip local mcp", s), v(), null;
152
+ const M = {
153
+ code: i.code,
154
+ url: C,
155
+ headers: J(i.headers, p)
156
+ }, S = yield O(M, o);
157
+ return S.length ? {
158
+ code: i.code,
159
+ url: M.url,
160
+ binding: M,
161
+ tools: S
162
+ } : (v(), null);
163
+ } catch (i) {
164
+ return v(), m.report("local mcp failed", s, i instanceof Error ? i.message : String(i)), null;
165
+ }
166
+ })));
167
+ if (l()) {
168
+ const c = D();
169
+ for (const s of f)
170
+ s && I(s.binding, c);
171
+ return;
172
+ }
173
+ const u = {}, g = [];
174
+ for (const c of f)
175
+ if (c) {
176
+ u[c.code] = {
177
+ type: "streamableHttp",
178
+ url: c.url,
179
+ tools: c.tools
180
+ };
181
+ for (const s of c.tools)
182
+ g.push({
183
+ name: s.name,
184
+ binding: c.binding,
185
+ handler: X(s.name, o)
186
+ });
187
+ }
188
+ if (E(g), A(g.map((c) => c.binding)), z(), !Object.keys(u).length || !e.socket) {
189
+ m.log("没有可注册的本地 MCP 工具,不发送 register_client_mcp_tools");
190
+ return;
191
+ }
192
+ m.log("发送 register_client_mcp_tools", Object.entries(u).map(([c, s]) => `${c}: ${s.tools.map((p) => p.name).join(", ")}`).join("; ")), e.socket.emit("register_client_mcp_tools", {
193
+ mcpServers: u
194
+ }, (c) => {
195
+ const s = c && typeof c == "object" ? c.code : void 0;
196
+ typeof s == "number" && s !== 200 && m.report("register_client_mcp_tools", s);
197
+ });
198
+ });
199
+ }
200
+ export {
201
+ F as detailMatchesInit,
202
+ q as fetchMcpDetail,
203
+ J as headersForEndpoint,
204
+ Z as listedLocalMcps,
205
+ W as parseMcpDetail,
206
+ ne as registerLocalMcp
207
+ };
@@ -0,0 +1,43 @@
1
+ var f = Object.defineProperty, p = Object.defineProperties;
2
+ var s = Object.getOwnPropertyDescriptors;
3
+ var i = Object.getOwnPropertySymbols;
4
+ var M = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
5
+ var r = (l, n, c) => n in l ? f(l, n, { enumerable: !0, configurable: !0, writable: !0, value: c }) : l[n] = c, e = (l, n) => {
6
+ for (var c in n || (n = {}))
7
+ M.call(n, c) && r(l, c, n[c]);
8
+ if (i)
9
+ for (var c of i(n))
10
+ g.call(n, c) && r(l, c, n[c]);
11
+ return l;
12
+ }, u = (l, n) => p(l, s(n));
13
+ const a = "MCP", t = /* @__PURE__ */ new Map();
14
+ let o = null;
15
+ function b(l, n, c) {
16
+ t.set(l, n), o = u(e({}, o != null ? o : {}), {
17
+ [l]: c
18
+ });
19
+ }
20
+ function L(l) {
21
+ t.clear(), o = null;
22
+ for (const n of l)
23
+ b(n.name, n.binding, n.handler);
24
+ o && !Object.keys(o).length && (o = null);
25
+ }
26
+ function P(l) {
27
+ return t.get(l);
28
+ }
29
+ function y() {
30
+ return [...t.values()];
31
+ }
32
+ function C(l) {
33
+ var n;
34
+ !o || !Object.keys(o).length || (l[a] = e(e({}, (n = l[a]) != null ? n : {}), o));
35
+ }
36
+ export {
37
+ a as MCP_PLUGIN_CODE,
38
+ C as applyLocalMcpPlugins,
39
+ P as localMcpBinding,
40
+ y as localMcpBindings,
41
+ b as rememberLocalMcpTool,
42
+ L as replaceLocalMcpTools
43
+ };
@@ -1,110 +1,99 @@
1
- const e = "@glodon-aiot/bot-client-sdk", t = "3.26.0-alpha.8", i = "glodoncv", s = "aiot bot client js sdk", n = "module", y = !1, o = [
1
+ const s = "@glodon-aiot/bot-client-sdk", t = "3.26.0", e = "glodoncv", i = "aiot bot client js sdk", n = "module", y = !1, d = [
2
2
  "aiot",
3
3
  "bot",
4
4
  "bot client",
5
5
  "sdk"
6
- ], l = [
6
+ ], o = [
7
7
  "dist"
8
- ], p = "./dist/es/index.mjs", c = "./dist/lib/index.js", r = "./dist/src/index.d.ts", d = {
8
+ ], c = "./dist/es/index.mjs", l = "./dist/lib/index.js", p = "./dist/src/index.d.ts", r = {
9
9
  ".": {
10
10
  import: "./dist/es/index.mjs",
11
11
  require: "./dist/lib/index.js",
12
12
  types: "./dist/src/index.d.ts"
13
13
  }
14
- }, a = "MIT", u = {
14
+ }, u = "MIT", a = {
15
15
  watch: "yarn build --watch",
16
- example: "node ./example/server.js",
17
- dev: "npm-run-all -p watch example",
18
- start: "vite",
19
16
  build: "tsc && vite build --mode prod && yarn build:cdn",
20
17
  "build:npm": "tsc && vite build --mode prod",
21
18
  "build:cdn": "tsc && vite build --mode prod --config ./vite.config.cdn.ts",
22
- preview: "vite preview",
23
19
  check: "yarn prettier --check .",
24
20
  write: "yarn prettier --write .",
25
- lint: "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js"
26
- }, g = {
21
+ lint: "eslint --ext .ts src -c .eslintrc.cjs",
22
+ "build:just-bash": "node scripts/build-just-bash.mjs",
23
+ "upload:just-bash": "node scripts/build-just-bash.mjs && node scripts/upload-cdn-libs.cjs just-bash",
24
+ "build:pyodide": "node scripts/build-pyodide.mjs",
25
+ "upload:pyodide": "node scripts/build-pyodide.mjs && node scripts/upload-cdn-libs.cjs pyodide",
26
+ test: "vitest run",
27
+ "test:e2e": "vitest run -c vitest.e2e.config.ts",
28
+ "test:watch": "vitest"
29
+ }, b = {
27
30
  "@babel/core": "^7.20.12",
28
31
  "@commitlint/cli": "^17.0.3",
29
32
  "@commitlint/config-conventional": "^17.0.3",
30
33
  "@rollup/plugin-babel": "^6.0.4",
31
34
  "@rollup/plugin-typescript": "^11.1.6",
32
- "@types/express": "^4",
33
- "@types/identity-obj-proxy": "^3",
34
35
  "@typescript-eslint/eslint-plugin": "^5.35.1",
35
36
  "@typescript-eslint/parser": "^5.35.1",
36
- "babel-loader": "^8.3.0",
37
37
  eslint: "^8.0.1",
38
38
  "eslint-config-prettier": "^8.5.0",
39
- "eslint-config-standard-with-typescript": "^22.0.0",
40
- "eslint-plugin-import": "^2.25.2",
41
- "eslint-plugin-n": "^15.0.0",
42
- "eslint-plugin-promise": "^6.0.0",
43
- "eslint-plugin-react": "^7.31.0",
44
- "eslint-plugin-storybook": "^0.6.10",
45
- express: "4",
46
- "http-proxy-middleware": "^3.0.0",
47
- "identity-obj-proxy": "^3.0.0",
48
- "npm-run-all": "^4.1.5",
39
+ "just-bash": "3.6.0",
49
40
  prettier: "2.7.1",
50
- "rollup-plugin-visualizer": "^6.0.1",
41
+ pyodide: "314.0.7",
51
42
  "socket.io": "^4.7.5",
52
- "ts-node": "^10.9.2",
53
43
  typescript: "*",
54
44
  vite: "^4.1.1",
55
45
  "vite-plugin-dts": "^4.3.0",
56
46
  "vite-plugin-externalize-deps": "^0.9.0",
57
- "vite-tsconfig-paths": "^5.1.4"
58
- }, m = {
47
+ vitest: "^0.34.6"
48
+ }, j = {
59
49
  access: "public",
60
50
  registry: "https://registry.npmjs.org/"
61
- }, b = {
62
- "@glodon-aiot/apis": "^3.26.0-alpha.8",
51
+ }, m = {
52
+ "@glodon-aiot/apis": "^3.26.0",
63
53
  axios: "0.24.0",
64
- buffer: "^6.0.3",
65
54
  dayjs: "^1.11.13",
66
55
  "js-base64": "^3.7.7",
67
56
  "socket.io-client": "^4.7.5",
68
57
  uuid: "^11.1.0"
69
- }, x = {
70
- name: e,
58
+ }, g = {
59
+ name: s,
71
60
  version: t,
72
- author: i,
73
- description: s,
61
+ author: e,
62
+ description: i,
74
63
  type: n,
75
64
  sideEffects: !1,
76
- keywords: o,
77
- files: l,
78
- module: p,
79
- main: c,
80
- typings: r,
81
- exports: d,
82
- license: a,
83
- scripts: u,
84
- devDependencies: g,
65
+ keywords: d,
66
+ files: o,
67
+ module: c,
68
+ main: l,
69
+ typings: p,
70
+ exports: r,
71
+ license: u,
72
+ scripts: a,
73
+ devDependencies: b,
85
74
  "lint-staged": {
86
75
  "*.{js,css,md,jsx,less,ts,tsx,json}": "prettier --write"
87
76
  },
88
- publishConfig: m,
89
- dependencies: b
77
+ publishConfig: j,
78
+ dependencies: m
90
79
  };
91
80
  export {
92
- i as author,
93
- x as default,
94
- b as dependencies,
95
- s as description,
96
- g as devDependencies,
97
- d as exports,
98
- l as files,
99
- o as keywords,
100
- a as license,
101
- c as main,
102
- p as module,
103
- e as name,
104
- m as publishConfig,
105
- u as scripts,
81
+ e as author,
82
+ g as default,
83
+ m as dependencies,
84
+ i as description,
85
+ b as devDependencies,
86
+ r as exports,
87
+ o as files,
88
+ d as keywords,
89
+ u as license,
90
+ l as main,
91
+ c as module,
92
+ s as name,
93
+ j as publishConfig,
94
+ a as scripts,
106
95
  y as sideEffects,
107
96
  n as type,
108
- r as typings,
97
+ p as typings,
109
98
  t as version
110
99
  };
@@ -0,0 +1,49 @@
1
+ var l = (t, e, o) => new Promise((c, n) => {
2
+ var p = (i) => {
3
+ try {
4
+ s(o.next(i));
5
+ } catch (a) {
6
+ n(a);
7
+ }
8
+ }, r = (i) => {
9
+ try {
10
+ s(o.throw(i));
11
+ } catch (a) {
12
+ n(a);
13
+ }
14
+ }, s = (i) => i.done ? c(i.value) : Promise.resolve(i.value).then(p, r);
15
+ s((o = o.apply(t, e)).next());
16
+ });
17
+ import { v4 as u } from "uuid";
18
+ function $(t, e, o) {
19
+ return l(this, null, function* () {
20
+ var s;
21
+ if (!e)
22
+ throw new Error("session is not avalible. id is undefined");
23
+ const c = d(o.name), n = yield t.postUploadTicket({
24
+ files: [c],
25
+ isv: "minio",
26
+ knowledgeId: e,
27
+ type: 1
28
+ }), r = (yield t.uploadMinioFile(n.minio, o)) || ((s = n.minio.fileKeys) == null ? void 0 : s[0]);
29
+ return {
30
+ url: f(n.minio, r),
31
+ name: o.name || c,
32
+ size: o.size
33
+ };
34
+ });
35
+ }
36
+ function d(t) {
37
+ const e = t.split(/[/\\]/).pop() || "", o = /\.([A-Za-z0-9]{1,16})$/.exec(e);
38
+ return o ? `${u()}.${o[1].toLowerCase()}` : u();
39
+ }
40
+ function f(t, e) {
41
+ var n;
42
+ const o = (n = t.endpoints) == null ? void 0 : n[0];
43
+ if (!o || !t.bucket || !e)
44
+ throw new Error("上传没有返回文件地址。");
45
+ return `${t.useSSL ? "https:" : typeof location != "undefined" && location.protocol ? location.protocol : "http:"}//${o}/${t.bucket}/${e}`;
46
+ }
47
+ export {
48
+ $ as uploadSessionFile
49
+ };
package/dist/es/utils.mjs CHANGED
@@ -1,18 +1,31 @@
1
- import { decode as o } from "js-base64";
2
- const t = (n) => JSON.parse(o(n.split(".")[1])), w = (n) => {
3
- const e = t(n).exp;
1
+ import { decode as f } from "js-base64";
2
+ const i = (n) => JSON.parse(f(n.split(".")[1])), y = (n) => {
3
+ const e = i(n).exp;
4
4
  return (/* @__PURE__ */ new Date()).valueOf() / 1e3 >= e;
5
- }, f = (n) => n == null ? void 0 : n.replace(/[\r\n]+/gm, ""), T = (n) => n.replace(/\\|\\/g, ""), g = (n, e, c, i) => {
5
+ };
6
+ function t(n) {
7
+ if (n === null || typeof n != "object")
8
+ return JSON.stringify(n);
9
+ if (Array.isArray(n))
10
+ return `[${n.map(t).join(",")}]`;
11
+ const e = n;
12
+ return `{${Object.keys(e).sort().map((r) => `${JSON.stringify(r)}:${t(e[r])}`).join(",")}}`;
13
+ }
14
+ const a = (n, e) => {
15
+ const s = i(n), r = i(e);
16
+ return s.rid === r.rid && s.ten === r.ten && t(s.ext) === t(r.ext) && t(s.label) === t(r.label);
17
+ }, g = (n) => n == null ? void 0 : n.replace(/[\r\n]+/gm, ""), d = (n) => n.replace(/\\|\\/g, ""), w = (n, e, s, r) => {
6
18
  if (n !== !0)
7
19
  return null;
8
- const s = (e == null ? void 0 : e.includeUserQuestion) === !0, u = (e == null ? void 0 : e.includeAiAnswer) === !0 || !s, r = [];
9
- return s && r.push(`问题:${i}`), u && r.push(`回答:${c}`), r.join(`
20
+ const o = (e == null ? void 0 : e.includeUserQuestion) === !0, u = (e == null ? void 0 : e.includeAiAnswer) === !0 || !o, c = [];
21
+ return o && c.push(`问题:${r}`), u && c.push(`回答:${s}`), c.join(`
10
22
  `);
11
23
  };
12
24
  export {
13
- w as isExpired,
14
- t as parseJWT,
15
- T as removeLeadingAndTrailingBackslashes,
16
- f as removeNewlines,
17
- g as resolveRelatedQuestionContent
25
+ y as isExpired,
26
+ i as parseJWT,
27
+ d as removeLeadingAndTrailingBackslashes,
28
+ g as removeNewlines,
29
+ w as resolveRelatedQuestionContent,
30
+ a as sameResourceTokenPayload
18
31
  };