@glodon-aiot/bot-client-sdk 3.25.1-alpha.6 → 3.26.0-alpha.10

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 (101) hide show
  1. package/README.md +555 -98
  2. package/dist/es/AgentSession.mjs +231 -167
  3. package/dist/es/BotClient.mjs +188 -136
  4. package/dist/es/Config.mjs +89 -26
  5. package/dist/es/DialogSession.mjs +39 -40
  6. package/dist/es/Session.mjs +83 -63
  7. package/dist/es/api/index.mjs +42 -33
  8. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  9. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  10. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  11. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  12. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  13. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  14. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  15. package/dist/es/builtinTools/command.mjs +56 -0
  16. package/dist/es/builtinTools/constants.mjs +10 -0
  17. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +244 -0
  18. package/dist/es/builtinTools/overview.mjs +77 -0
  19. package/dist/es/builtinTools/paths.mjs +63 -0
  20. package/dist/es/builtinTools/schemas.mjs +216 -0
  21. package/dist/es/builtinTools/tools.mjs +471 -0
  22. package/dist/es/index.mjs +69 -9
  23. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +264 -0
  24. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +157 -0
  25. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +197 -0
  26. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +54 -0
  27. package/dist/es/localFiles/adapters/fsaTypes.mjs +9 -0
  28. package/dist/es/localFiles/constants.mjs +47 -0
  29. package/dist/es/localFiles/createLocalFilesPlugin.mjs +255 -0
  30. package/dist/es/localFiles/errors.mjs +57 -0
  31. package/dist/es/localFiles/host/connectHostBridge.mjs +53 -0
  32. package/dist/es/localFiles/host/protocol.mjs +27 -0
  33. package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
  34. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  35. package/dist/es/localFiles/limits.mjs +22 -0
  36. package/dist/es/localFiles/schemas.mjs +312 -0
  37. package/dist/es/localFiles/security/downloadUrlPolicy.mjs +39 -0
  38. package/dist/es/localFiles/security/glob.mjs +28 -0
  39. package/dist/es/localFiles/security/pathPolicy.mjs +59 -0
  40. package/dist/es/localFiles/security/sensitiveFiles.mjs +115 -0
  41. package/dist/es/localFiles/tools/readTools.mjs +333 -0
  42. package/dist/es/localFiles/tools/runtime.mjs +108 -0
  43. package/dist/es/localFiles/tools/transferTools.mjs +228 -0
  44. package/dist/es/localFiles/tools/writeTools.mjs +173 -0
  45. package/dist/es/localFiles/transfer/SessionFileTransfer.mjs +111 -0
  46. package/dist/es/localFiles/validate.mjs +66 -0
  47. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +358 -0
  48. package/dist/es/localFiles/workspace/handleStore.mjs +79 -0
  49. package/dist/es/localFiles/workspace/watchDirectory.mjs +38 -0
  50. package/dist/es/package.json.mjs +38 -29
  51. package/dist/lib/index.js +374 -5
  52. package/dist/src/AgentSession.d.ts +9 -0
  53. package/dist/src/BotClient.d.ts +12 -2
  54. package/dist/src/Config.d.ts +25 -1
  55. package/dist/src/Session.d.ts +9 -1
  56. package/dist/src/api/index.d.ts +3 -1
  57. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  58. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  59. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  60. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  61. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  62. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  63. package/dist/src/builtinTools/command.d.ts +28 -0
  64. package/dist/src/builtinTools/constants.d.ts +17 -0
  65. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  66. package/dist/src/builtinTools/overview.d.ts +5 -0
  67. package/dist/src/builtinTools/paths.d.ts +15 -0
  68. package/dist/src/builtinTools/schemas.d.ts +3 -0
  69. package/dist/src/builtinTools/tools.d.ts +60 -0
  70. package/dist/src/index.d.ts +4 -2
  71. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +20 -0
  72. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +37 -0
  73. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +21 -0
  74. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +40 -0
  75. package/dist/src/localFiles/adapters/fsaTypes.d.ts +41 -0
  76. package/dist/src/localFiles/constants.d.ts +51 -0
  77. package/dist/src/localFiles/createLocalFilesPlugin.d.ts +11 -0
  78. package/dist/src/localFiles/createLocalPythonPlugin.d.ts +12 -0
  79. package/dist/src/localFiles/errors.d.ts +34 -0
  80. package/dist/src/localFiles/host/connectHostBridge.d.ts +6 -0
  81. package/dist/src/localFiles/host/protocol.d.ts +40 -0
  82. package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
  83. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  84. package/dist/src/localFiles/index.d.ts +22 -0
  85. package/dist/src/localFiles/limits.d.ts +3 -0
  86. package/dist/src/localFiles/schemas.d.ts +29 -0
  87. package/dist/src/localFiles/security/downloadUrlPolicy.d.ts +4 -0
  88. package/dist/src/localFiles/security/glob.d.ts +3 -0
  89. package/dist/src/localFiles/security/pathPolicy.d.ts +14 -0
  90. package/dist/src/localFiles/security/sensitiveFiles.d.ts +23 -0
  91. package/dist/src/localFiles/tools/readTools.d.ts +7 -0
  92. package/dist/src/localFiles/tools/runtime.d.ts +43 -0
  93. package/dist/src/localFiles/tools/transferTools.d.ts +4 -0
  94. package/dist/src/localFiles/tools/writeTools.d.ts +4 -0
  95. package/dist/src/localFiles/transfer/SessionFileTransfer.d.ts +40 -0
  96. package/dist/src/localFiles/types.d.ts +319 -0
  97. package/dist/src/localFiles/validate.d.ts +2 -0
  98. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +111 -0
  99. package/dist/src/localFiles/workspace/handleStore.d.ts +11 -0
  100. package/dist/src/localFiles/workspace/watchDirectory.d.ts +7 -0
  101. package/package.json +13 -4
@@ -1,69 +1,103 @@
1
- var k = Object.defineProperty, A = Object.defineProperties;
2
- var x = Object.getOwnPropertyDescriptors;
3
- var y = Object.getOwnPropertySymbols;
4
- var I = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
5
- var g = (r, i, e) => i in r ? k(r, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[i] = e, p = (r, i) => {
6
- for (var e in i || (i = {}))
7
- I.call(i, e) && g(r, e, i[e]);
8
- if (y)
9
- for (var e of y(i))
10
- R.call(i, e) && g(r, e, i[e]);
11
- return r;
12
- }, f = (r, i) => A(r, x(i));
13
- var d = (r, i, e) => (g(r, typeof i != "symbol" ? i + "" : i, e), e);
14
- var l = (r, i, e) => new Promise((t, n) => {
15
- var a = (o) => {
1
+ var x = Object.defineProperty, b = Object.defineProperties;
2
+ var R = Object.getOwnPropertyDescriptors;
3
+ var m = Object.getOwnPropertySymbols;
4
+ var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
5
+ var v = (c, e, i) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : c[e] = i, f = (c, e) => {
6
+ for (var i in e || (e = {}))
7
+ E.call(e, i) && v(c, i, e[i]);
8
+ if (m)
9
+ for (var i of m(e))
10
+ L.call(e, i) && v(c, i, e[i]);
11
+ return c;
12
+ }, _ = (c, e) => b(c, R(e));
13
+ var l = (c, e, i) => (v(c, typeof e != "symbol" ? e + "" : e, i), i);
14
+ var d = (c, e, i) => new Promise((t, s) => {
15
+ var n = (a) => {
16
16
  try {
17
- s(e.next(o));
18
- } catch (c) {
19
- n(c);
17
+ o(i.next(a));
18
+ } catch (h) {
19
+ s(h);
20
20
  }
21
- }, h = (o) => {
21
+ }, r = (a) => {
22
22
  try {
23
- s(e.throw(o));
24
- } catch (c) {
25
- n(c);
23
+ o(i.throw(a));
24
+ } catch (h) {
25
+ s(h);
26
26
  }
27
- }, s = (o) => o.done ? t(o.value) : Promise.resolve(o.value).then(a, h);
28
- s((e = e.apply(r, i)).next());
27
+ }, o = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
28
+ o((i = i.apply(c, e)).next());
29
29
  });
30
- import { parseJWT as m } from "./utils.mjs";
31
- import E from "./Logger.mjs";
32
- import { getCVForceService as M } from "./api/index.mjs";
33
- import { configure as S, configuration as v } from "./Config.mjs";
34
- import { ApplicationTypes as _, PromptVariableType as w } from "@glodon-aiot/apis";
35
- import C from "./AgentSession.mjs";
36
- import L from "./DialogSession.mjs";
37
- import T from "./EventBus.mjs";
38
- import V from "./package.json.mjs";
39
- const b = new E("[BotClient] ");
40
- class W {
41
- constructor(i, e, t = !0, n = {
30
+ import { parseJWT as y } from "./utils.mjs";
31
+ import W from "./Logger.mjs";
32
+ import { getAIShopService as M, getCVForceService as C } from "./api/index.mjs";
33
+ import { configure as k, configuration as p, setActiveLocalWorkspace as S, refreshBuiltinPlugins as w } from "./Config.mjs";
34
+ import { connectHostBridge as T } from "./localFiles/host/connectHostBridge.mjs";
35
+ import { LocalWorkspace as B } from "./localFiles/workspace/LocalWorkspace.mjs";
36
+ import { createIndexedDbStore as V } from "./localFiles/workspace/handleStore.mjs";
37
+ import { createDefaultSessionFileTransfer as O } from "./localFiles/transfer/SessionFileTransfer.mjs";
38
+ import { ApplicationTypes as u, PromptVariableType as A } from "@glodon-aiot/apis";
39
+ import D from "./AgentSession.mjs";
40
+ import H from "./DialogSession.mjs";
41
+ import P from "./EventBus.mjs";
42
+ import F from "./package.json.mjs";
43
+ const I = new W("[BotClient] ");
44
+ class ie {
45
+ constructor(e, i, t = !0, s = {
42
46
  analytics: {
43
47
  enabled: !1
44
48
  }
45
49
  }) {
46
- d(this, "event", new T());
47
- d(this, "cvforceApi");
50
+ l(this, "event", new P());
51
+ l(this, "cvforceApi");
48
52
  //从token解析出来的用户信息
49
- d(this, "_applicationId");
50
- d(this, "_application", null);
53
+ l(this, "_applicationId");
54
+ l(this, "_application", null);
51
55
  //session列表,被加载过的session将会被缓存到这个列表中
52
- d(this, "_sessions", []);
56
+ l(this, "_sessions", []);
53
57
  //活跃的session,只支持一个活跃的session
54
- d(this, "_activeSession");
55
- d(this, "_ready", !1);
58
+ l(this, "_activeSession");
59
+ l(this, "_ready", !1);
56
60
  //问题长度
57
- d(this, "_questionContextMaxLength", 4e3);
58
- d(this, "_promptVariables", []);
59
- if (this._token = i, this.lazyload = t, this.sdkConfigs = n, S(e), this._applicationId = m(i).rid || v.applicationId, !this._applicationId)
61
+ l(this, "_questionContextMaxLength", 4e3);
62
+ l(this, "_promptVariables", []);
63
+ l(this, "_localWorkspace");
64
+ l(this, "_disconnectHost");
65
+ if (this._token = e, this.lazyload = t, this.sdkConfigs = s, k(i, {
66
+ refreshBuiltinPlugins: !1
67
+ }), this._applicationId = y(e).rid || p.applicationId, !this._applicationId)
60
68
  throw "token is not vaild";
61
- this.cvforceApi = this.getService(), this.loadApplication().then((a) => {
62
- S(f(p({}, e), {
63
- stream: e.stream === void 0 ? (a == null ? void 0 : a.type) === _.Dialog || (a == null ? void 0 : a.type) === _.Agent : e.stream
69
+ this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
70
+ k(_(f({}, i), {
71
+ stream: i.stream === void 0 ? (n == null ? void 0 : n.type) === u.Dialog || (n == null ? void 0 : n.type) === u.Agent : i.stream
64
72
  })), this.event.emit("ready");
65
73
  });
66
74
  }
75
+ setupLocalWorkspace() {
76
+ var s, n;
77
+ const e = (s = p.builtinPlugins) == null ? void 0 : s.localFiles;
78
+ if (!(e != null && e.enabled)) {
79
+ S(void 0), w();
80
+ return;
81
+ }
82
+ const i = [], t = (n = e.backend) != null ? n : "file-system-access";
83
+ if (t !== "file-system-access" && t !== "host-bridge")
84
+ i.push(new Error(`[LocalFiles] 不支持的 backend:${e.backend}`));
85
+ else {
86
+ const r = M(p.apiRoot, this.token, (o, a) => I.error(a));
87
+ this._localWorkspace = new B({
88
+ applicationId: this._applicationId,
89
+ config: e,
90
+ store: V(),
91
+ picker: t === "host-bridge" ? null : void 0,
92
+ transfer: O(() => this.cvforceApi, () => r)
93
+ }), S(this._localWorkspace), t === "host-bridge" ? this._disconnectHost = T(this._localWorkspace) : this._localWorkspace.restore();
94
+ }
95
+ i.push(...w()), i.length && Promise.resolve().then(() => i.forEach((r) => this.event.emit("error", r)));
96
+ }
97
+ /** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
98
+ get localWorkspace() {
99
+ return this._localWorkspace;
100
+ }
67
101
  checkReady() {
68
102
  if (!this.ready)
69
103
  throw Error("client is not ready.");
@@ -71,8 +105,8 @@ class W {
71
105
  get ready() {
72
106
  return this._ready;
73
107
  }
74
- set ready(i) {
75
- this._ready = i;
108
+ set ready(e) {
109
+ this._ready = e;
76
110
  }
77
111
  get questionContextMaxLength() {
78
112
  return this.checkReady(), this._questionContextMaxLength;
@@ -81,49 +115,49 @@ class W {
81
115
  return this.checkReady(), this._promptVariables;
82
116
  }
83
117
  get knowledges() {
84
- var i;
85
- return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
118
+ var e;
119
+ return this.checkReady(), (e = this._application) == null ? void 0 : e.arrange[0].knowledges;
86
120
  }
87
121
  get sessions() {
88
122
  return this.checkReady(), this._sessions;
89
123
  }
90
- set sessions(i) {
91
- this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
124
+ set sessions(e) {
125
+ this.checkReady(), this._sessions = e, this.event.emit("sessions:updated", e);
92
126
  }
93
127
  loadApplication() {
94
- return l(this, null, function* () {
95
- var e, t, n, a, h;
128
+ return d(this, null, function* () {
129
+ var i, t, s, n, r;
96
130
  this._application = yield this.cvforceApi.getApplicationId(
97
131
  this._applicationId,
98
132
  // 这里记录应用的名称和版本,以便后期数据分析
99
133
  {
100
- ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
134
+ ui: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
101
135
  uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
102
- sdkVersion: V.version
136
+ sdkVersion: F.version
103
137
  }
104
- ).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), f(p({}, s), {
105
- arrange: [f(p({}, s.arrange[0]), {
106
- recommendQuestionOpen: v.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
138
+ ).then((o) => (typeof o.arrange[0].thinkingModeOpen != "boolean" && (o.arrange[0].thinkingModeOpen = !0), typeof o.arrange[0].thinkingTextOpen != "boolean" && (o.arrange[0].thinkingTextOpen = !0), _(f({}, o), {
139
+ arrange: [_(f({}, o.arrange[0]), {
140
+ recommendQuestionOpen: p.loadRelatedQuesions && o.arrange[0].recommendQuestionOpen
107
141
  })]
108
142
  })));
109
- const i = (h = (a = (n = this._application) == null ? void 0 : n.arrange) == null ? void 0 : a[0]) == null ? void 0 : h.llmModel;
110
- return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
111
- type: w.User
143
+ const e = (r = (n = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
144
+ return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((o) => o.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
145
+ type: A.User
112
146
  }), this.cvforceApi.getPrompts(this._applicationId, {
113
- type: w.System
114
- })]).then(([s, o]) => [...s, ...o]), this._ready = !0, this.event.emit("application:loaded"), this._application;
147
+ type: A.System
148
+ })]).then(([o, a]) => [...o, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
115
149
  });
116
150
  }
117
151
  getService() {
118
- return this.cvforceApi ? this.cvforceApi : M(v.apiRoot, this.token, (i, e) => b.error(e));
152
+ return this.cvforceApi ? this.cvforceApi : C(p.apiRoot, this.token, (e, i) => I.error(i));
119
153
  }
120
154
  get token() {
121
155
  return this._token;
122
156
  }
123
- set token(i) {
124
- this.checkReady(), this._token = i, this.ready = !1;
125
- const e = m(i).rid;
126
- this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
157
+ set token(e) {
158
+ this.checkReady(), this._token = e, this.ready = !1;
159
+ const i = y(e).rid;
160
+ this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
127
161
  this.event.emit("ready");
128
162
  }), this.clean());
129
163
  }
@@ -134,79 +168,96 @@ class W {
134
168
  return this.checkReady(), this._application;
135
169
  }
136
170
  get activeSession() {
137
- var i;
138
- return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
171
+ var e;
172
+ return this.checkReady(), ((e = this._activeSession) == null ? void 0 : e.id) || "";
139
173
  }
140
- set activeSession(i) {
141
- this.checkReady(), this.loadSession(i).then((e) => {
142
- this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
174
+ set activeSession(e) {
175
+ this.checkReady(), this.loadSession(e).then((i) => {
176
+ this._activeSession && this._activeSession.id !== e && this._activeSession.inactivate(), this._activeSession = i;
143
177
  });
144
178
  }
145
- createSession(i, e, t, n, a) {
146
- return l(this, null, function* () {
147
- const h = this;
148
- return new Promise((s, o) => {
149
- const c = (u) => l(this, null, function* () {
150
- if (u === _.Agent)
151
- s(new C(i, e, t, n, a, h));
152
- else if (u === _.Dialog)
153
- s(new L(i, e, t, n, a, h));
179
+ createSession(e, i, t, s, n) {
180
+ return d(this, null, function* () {
181
+ const r = this;
182
+ return new Promise((o, a) => {
183
+ const h = (g) => d(this, null, function* () {
184
+ if (g === u.Agent)
185
+ o(new D(e, i, t, s, n, r));
186
+ else if (g === u.Dialog)
187
+ o(new H(e, i, t, s, n, r));
154
188
  else
155
- throw Error(`不支持的应用类型:${u}`);
189
+ throw Error(`不支持的应用类型:${g}`);
156
190
  });
157
191
  if (this.ready) {
158
192
  if (!this._application)
159
193
  throw Error("client is not ready");
160
- c(this._application.type);
194
+ h(this._application.type);
161
195
  } else
162
196
  this.event.on("ready", () => {
163
197
  if (!this._application)
164
198
  throw Error("_application is null");
165
- c(this._application.type);
199
+ h(this._application.type);
166
200
  }, !0);
167
201
  });
168
202
  });
169
203
  }
170
- getSessions(i) {
171
- return l(this, null, function* () {
172
- return new Promise((e, t) => {
173
- const n = () => this.cvforceApi.listSessions(this._applicationId, i).then((a) => l(this, null, function* () {
174
- const h = [];
175
- for (const s of a) {
176
- const o = this._sessions.find((c) => c.id === s.id);
177
- if (o)
178
- o.data = s, this._application ? o.application = this._application : yield o.loadApplicationInfo(), h.push(o);
204
+ /**
205
+ * 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
206
+ */
207
+ getArtifacts(e) {
208
+ return d(this, null, function* () {
209
+ var n, r;
210
+ this.checkReady();
211
+ const i = e || ((n = this._activeSession) == null ? void 0 : n.id);
212
+ if (!i)
213
+ throw new Error("session id is not defined");
214
+ const t = this._sessions.find((o) => o.id === i);
215
+ if (t)
216
+ return t.getArtifacts();
217
+ const s = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
218
+ return (r = s == null ? void 0 : s.artifacts) != null ? r : [];
219
+ });
220
+ }
221
+ getSessions(e) {
222
+ return d(this, null, function* () {
223
+ return new Promise((i, t) => {
224
+ const s = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => d(this, null, function* () {
225
+ const r = [];
226
+ for (const o of n) {
227
+ const a = this._sessions.find((h) => h.id === o.id);
228
+ if (a)
229
+ a.data = o, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
179
230
  else {
180
- const c = yield this.createSession(this.token, s.id, s, this.lazyload, this._application || void 0);
181
- h.push(c);
231
+ const h = yield this.createSession(this.token, o.id, o, this.lazyload, this._application || void 0);
232
+ r.push(h);
182
233
  }
183
234
  }
184
- if (i != null && i.pageSize) {
185
- const s = [...this._sessions, ...h], o = /* @__PURE__ */ new Map();
186
- for (const c of s)
187
- o.set(c.id, c);
188
- return this.sessions = Array.from(o.values()), this.sessions;
235
+ if (e != null && e.pageSize) {
236
+ const o = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
237
+ for (const h of o)
238
+ a.set(h.id, h);
239
+ return this.sessions = Array.from(a.values()), this.sessions;
189
240
  } else
190
- return this.sessions = h, h;
241
+ return this.sessions = r, r;
191
242
  }));
192
243
  if (this.ready) {
193
244
  if (!this._application)
194
245
  throw Error("_application is null");
195
- e(n());
246
+ i(s());
196
247
  } else
197
248
  this.event.on("ready", () => {
198
249
  if (!this._application)
199
250
  throw Error("_application is null");
200
- e(n());
251
+ i(s());
201
252
  }, !0);
202
253
  });
203
254
  });
204
255
  }
205
- loadSession(i = "", e) {
206
- return l(this, null, function* () {
256
+ loadSession(e = "", i) {
257
+ return d(this, null, function* () {
207
258
  this.checkReady();
208
- let t = this.sessions.find((n) => n.id === i);
209
- if (t || (t = yield this.createSession(this.token, i, e), this._sessions.push(t)), this._activeSession) {
259
+ let t = this.sessions.find((s) => s.id === e);
260
+ if (t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
210
261
  if (this._activeSession === t)
211
262
  return t;
212
263
  this._activeSession.inactivate();
@@ -217,60 +268,61 @@ class W {
217
268
  });
218
269
  }
219
270
  reload() {
220
- return this.loadApplication().then(() => l(this, null, function* () {
271
+ return this.loadApplication().then(() => d(this, null, function* () {
221
272
  return yield this.getSessions(), this.event.emit("ready"), this;
222
273
  }));
223
274
  }
224
- reloadSession(i) {
225
- return l(this, null, function* () {
275
+ reloadSession(e) {
276
+ return d(this, null, function* () {
226
277
  yield this.reload();
227
- let e = this._sessions.find((t) => t.id === i) || this._activeSession;
228
- if (!e) {
278
+ let i = this._sessions.find((t) => t.id === e) || this._activeSession;
279
+ if (!i) {
229
280
  console.warn("reloadSession session failed.");
230
281
  return;
231
282
  }
232
- return yield e.reload(), e;
283
+ return yield i.reload(), i;
233
284
  });
234
285
  }
235
- setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
236
- return l(this, null, function* () {
237
- let n = i ? this._sessions.find((a) => a.id === i) : this._activeSession;
238
- if (!n) {
286
+ setTop(e, i, t = "top_time desc, sort_status desc, updated_at desc") {
287
+ return d(this, null, function* () {
288
+ let s = e ? this._sessions.find((n) => n.id === e) : this._activeSession;
289
+ if (!s) {
239
290
  console.warn("setTop session failed.");
240
291
  return;
241
292
  }
242
- return yield n.setTop(e), this.getSessions({
293
+ return yield s.setTop(i), this.getSessions({
243
294
  order: t
244
295
  });
245
296
  });
246
297
  }
247
- addEventListener(i, e, t = !1) {
248
- if (typeof e != "function")
298
+ addEventListener(e, i, t = !1) {
299
+ if (typeof i != "function")
249
300
  throw Error("event listener is not a function");
250
301
  if (t) {
251
- this.event.once(i, e);
302
+ this.event.once(e, i);
252
303
  return;
253
304
  }
254
- this.event.on(i, e);
305
+ this.event.on(e, i);
255
306
  }
256
- removeEventListener(i, e) {
257
- this.event.off(i, e);
307
+ removeEventListener(e, i) {
308
+ this.event.off(e, i);
258
309
  }
259
- removeSession(i, e) {
260
- return l(this, null, function* () {
310
+ removeSession(e, i) {
311
+ return d(this, null, function* () {
261
312
  this.checkReady();
262
313
  let t = -1;
263
- if (typeof i == "string" ? t = this._sessions.findIndex((n) => n.id === i) : t = this._sessions.findIndex((n) => n.id === i.id), t > -1) {
264
- const n = this._sessions[t];
265
- e && (yield n.delete()), this._sessions.splice(t, 1);
314
+ if (typeof e == "string" ? t = this._sessions.findIndex((s) => s.id === e) : t = this._sessions.findIndex((s) => s.id === e.id), t > -1) {
315
+ const s = this._sessions[t];
316
+ i && (yield s.delete()), this._sessions.splice(t, 1);
266
317
  } else
267
318
  console.warn("session delete failed, session is not exist.");
268
319
  });
269
320
  }
270
321
  clean() {
271
- this._sessions.forEach((i) => i.destroy()), this.sessions = [];
322
+ var e;
323
+ (e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this.sessions = [];
272
324
  }
273
325
  }
274
326
  export {
275
- W as default
327
+ ie as default
276
328
  };
@@ -1,40 +1,103 @@
1
- var u = Object.defineProperty, f = Object.defineProperties;
2
- var v = Object.getOwnPropertyDescriptors;
3
- var n = Object.getOwnPropertySymbols;
4
- var p = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
5
- var g = (o, t, e) => t in o ? u(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, c = (o, t) => {
6
- for (var e in t || (t = {}))
7
- p.call(t, e) && g(o, e, t[e]);
8
- if (n)
9
- for (var e of n(t))
10
- h.call(t, e) && g(o, e, t[e]);
11
- return o;
12
- }, l = (o, t) => f(o, v(t));
13
- import d from "./Logger.mjs";
14
- const R = new d("[Config] ");
15
- var s = /* @__PURE__ */ ((o) => (o.dev = "https://aiot-dev.glodon.com/api/cvforcepd", o.test = "https://aiot-dev.glodon.com/api/cvforce", o.prod = "https://copilot.glodon.com/api/cvforce", o.local = "http://localhost:3000/api/cvforcepd", o))(s || {});
16
- let i = {
1
+ var R = Object.defineProperty, _ = Object.defineProperties;
2
+ var B = Object.getOwnPropertyDescriptors;
3
+ var P = Object.getOwnPropertySymbols;
4
+ var w = Object.prototype.hasOwnProperty, O = Object.prototype.propertyIsEnumerable;
5
+ var C = (e, i, n) => i in e ? R(e, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[i] = n, r = (e, i) => {
6
+ for (var n in i || (i = {}))
7
+ w.call(i, n) && C(e, n, i[n]);
8
+ if (P)
9
+ for (var n of P(i))
10
+ O.call(i, n) && C(e, n, i[n]);
11
+ return e;
12
+ }, L = (e, i) => _(e, B(i));
13
+ import g from "./Logger.mjs";
14
+ import { LOCAL_FILES_PLUGIN_CODES as k, LOCAL_PYTHON_PLUGIN_CODES as E } from "./localFiles/constants.mjs";
15
+ import { createBuiltinToolsPlugin as I } from "./builtinTools/createBuiltinToolsPlugin.mjs";
16
+ const S = new g("[Config] ");
17
+ var h = /* @__PURE__ */ ((e) => (e.dev = "https://aiot-dev.glodon.com/api/cvforcepd", e.test = "https://aiot-dev.glodon.com/api/cvforce", e.prod = "https://copilot.glodon.com/api/cvforce", e.local = "http://localhost:3000/api/cvforcepd", e))(h || {});
18
+ let o = {
17
19
  debug: !1,
18
20
  env: "prod",
19
21
  //AIoT 环境, 与apiRoot配对使用
20
22
  apiRoot: "https://copilot.glodon.com/api/cvforce",
21
23
  //https://${hostname}/${PRODUCD_CODE}
22
24
  applicationId: "",
25
+ /** 最终生效的插件表 = 业务插件 + 内置插件,由 configure() 计算,不要直接修改。 */
23
26
  plugins: {},
27
+ /** 集成方传入的原始 plugins。 */
28
+ businessPlugins: {},
29
+ builtinPlugins: void 0,
24
30
  mcp: void 0,
25
31
  loadRelatedQuesions: !0,
26
32
  stream: !1
27
- };
28
- function x(o) {
29
- var t, e;
30
- d.debug = (o == null ? void 0 : o.debug) || !1, i = l(c(c({}, i), o), {
31
- apiRoot: (o == null ? void 0 : o.apiRoot) || i.apiRoot || (o != null && o.env ? s[o.env || "prod"] : i.apiRoot),
33
+ }, d, l;
34
+ const c = /* @__PURE__ */ new Set();
35
+ function Q(e) {
36
+ d !== e && (d = e, l = void 0, c.clear());
37
+ }
38
+ function Y() {
39
+ if (!l)
40
+ return;
41
+ const {
42
+ pluginCode: e,
43
+ table: i
44
+ } = l, n = o.plugins[e], t = i[e];
45
+ if (!(!n || n.shell !== t.shell))
46
+ return e;
47
+ }
48
+ function j() {
49
+ if (!l)
50
+ return;
51
+ const {
52
+ pluginCode: e,
53
+ table: i
54
+ } = l, n = o.plugins[e], t = i[e];
55
+ if (!(!n || n.run_file !== t.run_file))
56
+ return e;
57
+ }
58
+ function T(e, i) {
59
+ return (e == null ? void 0 : e.pluginCode) || k[i];
60
+ }
61
+ function N(e, i, n) {
62
+ return (e == null ? void 0 : e.pluginCode) || n || E[i];
63
+ }
64
+ function D() {
65
+ var v, b, p;
66
+ const e = (v = o.businessPlugins) != null ? v : {}, i = (b = o.builtinPlugins) == null ? void 0 : b.localFiles, n = (p = o.builtinPlugins) == null ? void 0 : p.localPython, t = [], u = r({}, e);
67
+ if (!!!(i != null && i.enabled || n != null && n.enabled))
68
+ return o.plugins = u, t;
69
+ if (!d)
70
+ return t.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), o.plugins = u, t;
71
+ const f = i != null && i.enabled ? T(i, o.env) : void 0, s = f || (n != null && n.enabled ? N(n, o.env, f) : void 0);
72
+ return s ? e[s] ? t.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== d || l.pluginCode !== s) && (l = {
73
+ workspace: d,
74
+ pluginCode: s,
75
+ table: I({
76
+ pluginCode: s,
77
+ workspace: d
78
+ })
79
+ }), u[s] = l.table[s]) : t.push(`[BuiltinTools] 当前环境(env: ${o.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), o.plugins = u, t;
80
+ }
81
+ function G() {
82
+ return D().filter((e) => !c.has(e)).map((e) => (c.add(e), console.error(e), new Error(e)));
83
+ }
84
+ function q(e, i = {}) {
85
+ var n, t, u;
86
+ g.debug = (e == null ? void 0 : e.debug) || !1, o = L(r(r({}, o), e), {
87
+ apiRoot: (e == null ? void 0 : e.apiRoot) || o.apiRoot || (e != null && e.env ? h[e.env || "prod"] : o.apiRoot),
32
88
  // 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
33
- plugins: (e = (t = o == null ? void 0 : o.plugins) != null ? t : i.plugins) != null ? e : {}
34
- }), d.debug && R.log("updated", i);
89
+ businessPlugins: (t = (n = e == null ? void 0 : e.plugins) != null ? n : o.businessPlugins) != null ? t : {},
90
+ builtinPlugins: (u = e == null ? void 0 : e.builtinPlugins) != null ? u : o.builtinPlugins
91
+ }), i.refreshBuiltinPlugins !== !1 && G(), g.debug && S.log("updated", o);
35
92
  }
36
93
  export {
37
- s as ApiUrl,
38
- i as configuration,
39
- x as configure
94
+ h as ApiUrl,
95
+ o as configuration,
96
+ q as configure,
97
+ Y as getRegisteredLocalFilesPluginCode,
98
+ j as getRegisteredLocalPythonPluginCode,
99
+ G as refreshBuiltinPlugins,
100
+ T as resolveLocalFilesPluginCode,
101
+ N as resolveLocalPythonPluginCode,
102
+ Q as setActiveLocalWorkspace
40
103
  };