@glodon-aiot/bot-client-sdk 3.26.0-alpha.9 → 3.27.0-alpha.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 (72) hide show
  1. package/README.md +246 -225
  2. package/dist/es/AgentSession.mjs +275 -197
  3. package/dist/es/BotClient.mjs +200 -123
  4. package/dist/es/Config.mjs +58 -68
  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/constants.mjs +12 -5
  11. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +182 -160
  12. package/dist/es/builtinTools/paths.mjs +34 -27
  13. package/dist/es/builtinTools/platformSkills.mjs +248 -0
  14. package/dist/es/builtinTools/schemas.mjs +63 -18
  15. package/dist/es/builtinTools/tools.mjs +368 -244
  16. package/dist/es/index.mjs +62 -61
  17. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  18. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +113 -131
  19. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +60 -55
  20. package/dist/es/localFiles/constants.mjs +24 -28
  21. package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
  22. package/dist/es/localFiles/errors.mjs +44 -35
  23. package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
  24. package/dist/es/localFiles/host/protocol.mjs +27 -14
  25. package/dist/es/localFiles/host/sandboxClient.mjs +297 -127
  26. package/dist/es/localFiles/preview.mjs +33 -0
  27. package/dist/es/localFiles/schemas.mjs +22 -53
  28. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +156 -89
  29. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  30. package/dist/es/localMcp/client.mjs +234 -0
  31. package/dist/es/localMcp/endpoints.mjs +94 -0
  32. package/dist/es/localMcp/register.mjs +207 -0
  33. package/dist/es/localMcp/registry.mjs +43 -0
  34. package/dist/es/package.json.mjs +29 -49
  35. package/dist/es/sessionUpload.mjs +49 -0
  36. package/dist/es/utils.mjs +24 -11
  37. package/dist/lib/index.js +48 -40
  38. package/dist/src/AgentSession.d.ts +13 -0
  39. package/dist/src/BotClient.d.ts +13 -1
  40. package/dist/src/Config.d.ts +14 -7
  41. package/dist/src/EventBus.d.ts +3 -0
  42. package/dist/src/Logger.d.ts +15 -8
  43. package/dist/src/PayloadTypes.d.ts +7 -0
  44. package/dist/src/Session.d.ts +19 -2
  45. package/dist/src/api/index.d.ts +2 -2
  46. package/dist/src/builtinTools/command.d.ts +7 -0
  47. package/dist/src/builtinTools/constants.d.ts +10 -2
  48. package/dist/src/builtinTools/paths.d.ts +3 -2
  49. package/dist/src/builtinTools/platformSkills.d.ts +92 -0
  50. package/dist/src/builtinTools/tools.d.ts +13 -0
  51. package/dist/src/constant.d.ts +1 -1
  52. package/dist/src/index.d.ts +2 -1
  53. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  54. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +7 -4
  55. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +8 -0
  56. package/dist/src/localFiles/constants.d.ts +4 -13
  57. package/dist/src/localFiles/errors.d.ts +1 -1
  58. package/dist/src/localFiles/host/protocol.d.ts +14 -3
  59. package/dist/src/localFiles/host/sandboxClient.d.ts +50 -0
  60. package/dist/src/localFiles/index.d.ts +9 -5
  61. package/dist/src/localFiles/preview.d.ts +2 -0
  62. package/dist/src/localFiles/schemas.d.ts +0 -2
  63. package/dist/src/localFiles/types.d.ts +2 -22
  64. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +25 -3
  65. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  66. package/dist/src/localMcp/client.d.ts +15 -0
  67. package/dist/src/localMcp/endpoints.d.ts +19 -0
  68. package/dist/src/localMcp/register.d.ts +34 -0
  69. package/dist/src/localMcp/registry.d.ts +27 -0
  70. package/dist/src/sessionUpload.d.ts +14 -0
  71. package/dist/src/utils.d.ts +6 -0
  72. package/package.json +4 -24
@@ -1,96 +1,128 @@
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) => {
1
+ var b = Object.defineProperty, x = Object.defineProperties;
2
+ var E = Object.getOwnPropertyDescriptors;
3
+ var S = Object.getOwnPropertySymbols;
4
+ var L = Object.prototype.hasOwnProperty, W = Object.prototype.propertyIsEnumerable;
5
+ var m = (l, e, i) => e in l ? b(l, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : l[e] = i, g = (l, e) => {
6
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) => {
7
+ L.call(e, i) && m(l, i, e[i]);
8
+ if (S)
9
+ for (var i of S(e))
10
+ W.call(e, i) && m(l, i, e[i]);
11
+ return l;
12
+ }, u = (l, e) => x(l, E(e));
13
+ var h = (l, e, i) => (m(l, typeof e != "symbol" ? e + "" : e, i), i);
14
+ var p = (l, e, i) => new Promise((t, o) => {
15
15
  var n = (a) => {
16
16
  try {
17
- o(i.next(a));
18
- } catch (h) {
19
- s(h);
17
+ s(i.next(a));
18
+ } catch (c) {
19
+ o(c);
20
20
  }
21
21
  }, r = (a) => {
22
22
  try {
23
- o(i.throw(a));
24
- } catch (h) {
25
- s(h);
23
+ s(i.throw(a));
24
+ } catch (c) {
25
+ o(c);
26
26
  }
27
- }, o = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
28
- o((i = i.apply(c, e)).next());
27
+ }, s = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
28
+ s((i = i.apply(l, e)).next());
29
29
  });
30
- import { parseJWT as y } from "./utils.mjs";
31
- import W from "./Logger.mjs";
30
+ import { parseJWT as y, sameResourceTokenPayload as T } from "./utils.mjs";
31
+ import B from "./Logger.mjs";
32
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 V } from "./localFiles/workspace/LocalWorkspace.mjs";
36
- import { createIndexedDbStore as B } 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 F from "./EventBus.mjs";
42
- import P from "./package.json.mjs";
43
- const I = new W("[BotClient] ");
44
- class ie {
45
- constructor(e, i, t = !0, s = {
33
+ import { configure as w, configuration as f, setActiveLocalWorkspace as A, refreshBuiltinPlugins as I } from "./Config.mjs";
34
+ import { PlatformSkillSync as V, pullArrangeSkills as O } from "./builtinTools/platformSkills.mjs";
35
+ import { HostBridgeAdapter as H } from "./localFiles/adapters/HostBridgeAdapter.mjs";
36
+ import { connectHostBridge as D } from "./localFiles/host/connectHostBridge.mjs";
37
+ import { connectLocalMcpBridge as F } from "./localMcp/endpoints.mjs";
38
+ import { LocalWorkspace as j } from "./localFiles/workspace/LocalWorkspace.mjs";
39
+ import { createIndexedDbStore as z } from "./localFiles/workspace/handleStore.mjs";
40
+ import { createDefaultSessionFileTransfer as Q } from "./localFiles/transfer/SessionFileTransfer.mjs";
41
+ import { ApplicationTypes as k, PromptVariableType as R } from "@glodon-aiot/apis";
42
+ import J from "./AgentSession.mjs";
43
+ import P from "./DialogSession.mjs";
44
+ import $ from "./EventBus.mjs";
45
+ import U from "./package.json.mjs";
46
+ const d = new B("[BotClient] ");
47
+ class he {
48
+ constructor(e, i, t = !0, o = {
46
49
  analytics: {
47
50
  enabled: !1
48
51
  }
49
52
  }) {
50
- l(this, "event", new F());
51
- l(this, "cvforceApi");
53
+ h(this, "event", new $());
54
+ h(this, "cvforceApi");
52
55
  //从token解析出来的用户信息
53
- l(this, "_applicationId");
54
- l(this, "_application", null);
56
+ h(this, "_applicationId");
57
+ h(this, "_application", null);
55
58
  //session列表,被加载过的session将会被缓存到这个列表中
56
- l(this, "_sessions", []);
59
+ h(this, "_sessions", []);
57
60
  //活跃的session,只支持一个活跃的session
58
- l(this, "_activeSession");
59
- l(this, "_ready", !1);
61
+ h(this, "_activeSession");
62
+ h(this, "_ready", !1);
60
63
  //问题长度
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), this._applicationId = y(e).rid || p.applicationId, !this._applicationId)
64
+ h(this, "_questionContextMaxLength", 4e3);
65
+ h(this, "_promptVariables", []);
66
+ h(this, "_localWorkspace");
67
+ h(this, "_disconnectHost");
68
+ /** 后进入的会话作废尚未返回的编排刷新。 */
69
+ h(this, "arrangeSkillEpoch", 0);
70
+ if (this._token = e, this.lazyload = t, this.sdkConfigs = o, w(i, {
71
+ refreshBuiltinPlugins: !1
72
+ }), this._applicationId = y(e).rid || f.applicationId, !this._applicationId)
66
73
  throw "token is not vaild";
67
- this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
68
- k(_(f({}, i), {
69
- stream: i.stream === void 0 ? (n == null ? void 0 : n.type) === u.Dialog || (n == null ? void 0 : n.type) === u.Agent : i.stream
70
- })), this.event.emit("ready");
74
+ this.cvforceApi = this.getService(), F(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
75
+ w(u(g({}, i), {
76
+ stream: i.stream === void 0 ? (n == null ? void 0 : n.type) === k.Dialog || (n == null ? void 0 : n.type) === k.Agent : i.stream
77
+ })), this.logReady(), this.event.emit("ready");
78
+ });
79
+ }
80
+ logReady() {
81
+ var e, i;
82
+ d.log("ready", {
83
+ applicationId: this._applicationId,
84
+ type: (e = this._application) == null ? void 0 : e.type,
85
+ stream: f.stream,
86
+ workspace: (i = this._localWorkspace) == null ? void 0 : i.status
71
87
  });
72
88
  }
73
89
  setupLocalWorkspace() {
74
- var s, n;
75
- const e = (s = p.builtinPlugins) == null ? void 0 : s.localFiles;
90
+ var o, n, r;
91
+ const e = (o = f.builtinPlugins) == null ? void 0 : o.localFiles;
76
92
  if (!(e != null && e.enabled)) {
77
- S(void 0), w();
93
+ d.log("workspace:disabled"), A(void 0), I();
78
94
  return;
79
95
  }
80
- const i = [], t = (n = e.backend) != null ? n : "file-system-access";
96
+ d.log("workspace:setup", {
97
+ backend: (n = e.backend) != null ? n : "file-system-access"
98
+ });
99
+ const i = [], t = (r = e.backend) != null ? r : "file-system-access";
81
100
  if (t !== "file-system-access" && t !== "host-bridge")
82
101
  i.push(new Error(`[LocalFiles] 不支持的 backend:${e.backend}`));
83
102
  else {
84
- const r = M(p.apiRoot, this.token, (o, a) => I.error(a));
85
- this._localWorkspace = new V({
103
+ const s = M(f.apiRoot, () => this.token, (a, c) => d.error(c));
104
+ this._localWorkspace = new j({
86
105
  applicationId: this._applicationId,
87
106
  config: e,
88
- store: B(),
107
+ store: z(),
89
108
  picker: t === "host-bridge" ? null : void 0,
90
- transfer: O(() => this.cvforceApi, () => r)
91
- }), S(this._localWorkspace), t === "host-bridge" ? this._disconnectHost = T(this._localWorkspace) : this._localWorkspace.restore();
109
+ transfer: Q(() => this.cvforceApi, () => s)
110
+ }), A(this._localWorkspace), this._localWorkspace.platformSkills = new V({
111
+ applicationId: () => this._applicationId,
112
+ getToken: () => this.token,
113
+ getSkills: () => {
114
+ var a, c, _, v;
115
+ return (v = (_ = (c = (a = this._application) == null ? void 0 : a.arrange) == null ? void 0 : c[0]) == null ? void 0 : _.skills) != null ? v : [];
116
+ },
117
+ apiRoot: () => f.apiRoot,
118
+ getSandbox: () => {
119
+ var c;
120
+ const a = (c = this._localWorkspace) == null ? void 0 : c.adapter;
121
+ return a instanceof H ? a.sandbox : void 0;
122
+ }
123
+ }), t === "host-bridge" ? this._disconnectHost = D(this._localWorkspace) : this._localWorkspace.restore();
92
124
  }
93
- i.push(...w()), i.length && Promise.resolve().then(() => i.forEach((r) => this.event.emit("error", r)));
125
+ i.push(...I()), i.length && Promise.resolve().then(() => i.forEach((s) => this.event.emit("error", s)));
94
126
  }
95
127
  /** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
96
128
  get localWorkspace() {
@@ -123,40 +155,49 @@ class ie {
123
155
  this.checkReady(), this._sessions = e, this.event.emit("sessions:updated", e);
124
156
  }
125
157
  loadApplication() {
126
- return d(this, null, function* () {
127
- var i, t, s, n, r;
158
+ return p(this, null, function* () {
159
+ var i, t, o, n, r;
128
160
  this._application = yield this.cvforceApi.getApplicationId(
129
161
  this._applicationId,
130
162
  // 这里记录应用的名称和版本,以便后期数据分析
131
163
  {
132
164
  ui: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
133
165
  uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
134
- sdkVersion: P.version
166
+ sdkVersion: U.version
135
167
  }
136
- ).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), {
137
- arrange: [_(f({}, o.arrange[0]), {
138
- recommendQuestionOpen: p.loadRelatedQuesions && o.arrange[0].recommendQuestionOpen
168
+ ).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), u(g({}, s), {
169
+ arrange: [u(g({}, s.arrange[0]), {
170
+ recommendQuestionOpen: f.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
139
171
  })]
140
172
  })));
141
- const e = (r = (n = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
142
- return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((o) => o.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
143
- type: A.User
173
+ const e = (r = (n = (o = this._application) == null ? void 0 : o.arrange) == null ? void 0 : n[0]) == null ? void 0 : r.llmModel;
174
+ return e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((s) => s.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
175
+ type: R.User
144
176
  }), this.cvforceApi.getPrompts(this._applicationId, {
145
- type: A.System
146
- })]).then(([o, a]) => [...o, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
177
+ type: R.System
178
+ })]).then(([s, a]) => [...s, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
147
179
  });
148
180
  }
149
181
  getService() {
150
- return this.cvforceApi ? this.cvforceApi : C(p.apiRoot, this.token, (e, i) => I.error(i));
182
+ return this.cvforceApi ? this.cvforceApi : C(f.apiRoot, () => this.token, (e, i) => d.error(i));
151
183
  }
152
184
  get token() {
153
185
  return this._token;
154
186
  }
187
+ /**
188
+ * 更新 resource token。
189
+ * rid / ten / ext / label 都相同时只换票,不卸会话;
190
+ * 任一不同时沿用原逻辑(ready 置 false,应用 id 变则重载并 clean)。
191
+ */
155
192
  set token(e) {
156
- this.checkReady(), this._token = e, this.ready = !1;
193
+ if (this.checkReady(), T(this._token, e)) {
194
+ this._token = e, this.notifySessionsResourceToken(e);
195
+ return;
196
+ }
197
+ this._token = e, this.ready = !1;
157
198
  const i = y(e).rid;
158
199
  this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
159
- this.event.emit("ready");
200
+ this.logReady(), this.event.emit("ready");
160
201
  }), this.clean());
161
202
  }
162
203
  get applicationId() {
@@ -174,27 +215,27 @@ class ie {
174
215
  this._activeSession && this._activeSession.id !== e && this._activeSession.inactivate(), this._activeSession = i;
175
216
  });
176
217
  }
177
- createSession(e, i, t, s, n) {
178
- return d(this, null, function* () {
218
+ createSession(e, i, t, o, n) {
219
+ return p(this, null, function* () {
179
220
  const r = this;
180
- return new Promise((o, a) => {
181
- const h = (g) => d(this, null, function* () {
182
- if (g === u.Agent)
183
- o(new D(e, i, t, s, n, r));
184
- else if (g === u.Dialog)
185
- o(new H(e, i, t, s, n, r));
221
+ return new Promise((s, a) => {
222
+ const c = (_) => p(this, null, function* () {
223
+ if (_ === k.Agent)
224
+ s(new J(e, i, t, o, n, r));
225
+ else if (_ === k.Dialog)
226
+ s(new P(e, i, t, o, n, r));
186
227
  else
187
- throw Error(`不支持的应用类型:${g}`);
228
+ throw Error(`不支持的应用类型:${_}`);
188
229
  });
189
230
  if (this.ready) {
190
231
  if (!this._application)
191
232
  throw Error("client is not ready");
192
- h(this._application.type);
233
+ c(this._application.type);
193
234
  } else
194
235
  this.event.on("ready", () => {
195
236
  if (!this._application)
196
237
  throw Error("_application is null");
197
- h(this._application.type);
238
+ c(this._application.type);
198
239
  }, !0);
199
240
  });
200
241
  });
@@ -203,37 +244,40 @@ class ie {
203
244
  * 获取会话产出物。不传 sessionId 时取当前活跃会话。没有产出物时返回空数组。
204
245
  */
205
246
  getArtifacts(e) {
206
- return d(this, null, function* () {
247
+ return p(this, null, function* () {
207
248
  var n, r;
208
249
  this.checkReady();
209
250
  const i = e || ((n = this._activeSession) == null ? void 0 : n.id);
210
251
  if (!i)
211
252
  throw new Error("session id is not defined");
212
- const t = this._sessions.find((o) => o.id === i);
253
+ const t = this._sessions.find((s) => s.id === i);
213
254
  if (t)
214
255
  return t.getArtifacts();
215
- const s = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
216
- return (r = s == null ? void 0 : s.artifacts) != null ? r : [];
256
+ const o = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
257
+ return (r = o == null ? void 0 : o.artifacts) != null ? r : [];
217
258
  });
218
259
  }
219
260
  getSessions(e) {
220
- return d(this, null, function* () {
261
+ return p(this, null, function* () {
221
262
  return new Promise((i, t) => {
222
- const s = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => d(this, null, function* () {
263
+ const o = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => p(this, null, function* () {
223
264
  const r = [];
224
- for (const o of n) {
225
- const a = this._sessions.find((h) => h.id === o.id);
265
+ for (const s of n) {
266
+ const a = this._sessions.find((c) => c.id === s.id);
226
267
  if (a)
227
- a.data = o, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
268
+ a.data = s, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
228
269
  else {
229
- const h = yield this.createSession(this.token, o.id, o, this.lazyload, this._application || void 0);
230
- r.push(h);
270
+ const c = yield this.createSession(this.token, s.id, s, this.lazyload, this._application || void 0);
271
+ r.push(c);
231
272
  }
232
273
  }
233
- if (e != null && e.pageSize) {
234
- const o = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
235
- for (const h of o)
236
- a.set(h.id, h);
274
+ if (d.log("sessions", {
275
+ count: r.length,
276
+ paged: !!(e != null && e.pageSize)
277
+ }), e != null && e.pageSize) {
278
+ const s = [...this._sessions, ...r], a = /* @__PURE__ */ new Map();
279
+ for (const c of s)
280
+ a.set(c.id, c);
237
281
  return this.sessions = Array.from(a.values()), this.sessions;
238
282
  } else
239
283
  return this.sessions = r, r;
@@ -241,21 +285,47 @@ class ie {
241
285
  if (this.ready) {
242
286
  if (!this._application)
243
287
  throw Error("_application is null");
244
- i(s());
288
+ i(o());
245
289
  } else
246
290
  this.event.on("ready", () => {
247
291
  if (!this._application)
248
292
  throw Error("_application is null");
249
- i(s());
293
+ i(o());
250
294
  }, !0);
251
295
  });
252
296
  });
253
297
  }
298
+ /** 只更新 arrange[0].skills。查询失败时保留内存中的名单,会话仍可进入。 */
299
+ refreshArrangeSkills() {
300
+ return p(this, null, function* () {
301
+ var t, o, n;
302
+ const e = (o = (t = this._application) == null ? void 0 : t.arrange) == null ? void 0 : o[0], i = ++this.arrangeSkillEpoch;
303
+ try {
304
+ yield O({
305
+ // 已发布的 IArrange 类型尚未带上 skills,与 getSkills 一样在这里收窄。
306
+ arrange: e,
307
+ fetchApplication: () => this.cvforceApi.getApplicationId(this._applicationId),
308
+ stillCurrent: () => {
309
+ var s, a;
310
+ return i === this.arrangeSkillEpoch && ((a = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : a[0]) === e;
311
+ }
312
+ });
313
+ const r = (n = e == null ? void 0 : e.skills) != null ? n : [];
314
+ d.log("arrange:skills", r.map((s) => s.name).filter(Boolean));
315
+ } catch (r) {
316
+ d.error("刷新编排技能失败", r);
317
+ }
318
+ });
319
+ }
254
320
  loadSession(e = "", i) {
255
- return d(this, null, function* () {
256
- this.checkReady();
257
- let t = this.sessions.find((s) => s.id === e);
258
- if (t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
321
+ return p(this, null, function* () {
322
+ var o, n;
323
+ this.checkReady(), yield this.refreshArrangeSkills(), (n = (o = this._localWorkspace) == null ? void 0 : o.platformSkills) == null || n.sync();
324
+ let t = this.sessions.find((r) => r.id === e);
325
+ if (d.log("loadSession", {
326
+ sessionId: e || "(new)",
327
+ existing: !!t
328
+ }), t || (t = yield this.createSession(this.token, e, i), this._sessions.push(t)), this._activeSession) {
259
329
  if (this._activeSession === t)
260
330
  return t;
261
331
  this._activeSession.inactivate();
@@ -266,29 +336,29 @@ class ie {
266
336
  });
267
337
  }
268
338
  reload() {
269
- return this.loadApplication().then(() => d(this, null, function* () {
339
+ return this.loadApplication().then(() => p(this, null, function* () {
270
340
  return yield this.getSessions(), this.event.emit("ready"), this;
271
341
  }));
272
342
  }
273
343
  reloadSession(e) {
274
- return d(this, null, function* () {
344
+ return p(this, null, function* () {
275
345
  yield this.reload();
276
346
  let i = this._sessions.find((t) => t.id === e) || this._activeSession;
277
347
  if (!i) {
278
- console.warn("reloadSession session failed.");
348
+ d.warn("reloadSession session failed.");
279
349
  return;
280
350
  }
281
351
  return yield i.reload(), i;
282
352
  });
283
353
  }
284
354
  setTop(e, i, t = "top_time desc, sort_status desc, updated_at desc") {
285
- return d(this, null, function* () {
286
- let s = e ? this._sessions.find((n) => n.id === e) : this._activeSession;
287
- if (!s) {
288
- console.warn("setTop session failed.");
355
+ return p(this, null, function* () {
356
+ let o = e ? this._sessions.find((n) => n.id === e) : this._activeSession;
357
+ if (!o) {
358
+ d.warn("setTop session failed.");
289
359
  return;
290
360
  }
291
- return yield s.setTop(i), this.getSessions({
361
+ return yield o.setTop(i), this.getSessions({
292
362
  order: t
293
363
  });
294
364
  });
@@ -306,21 +376,28 @@ class ie {
306
376
  this.event.off(e, i);
307
377
  }
308
378
  removeSession(e, i) {
309
- return d(this, null, function* () {
379
+ return p(this, null, function* () {
310
380
  this.checkReady();
311
381
  let t = -1;
312
- if (typeof e == "string" ? t = this._sessions.findIndex((s) => s.id === e) : t = this._sessions.findIndex((s) => s.id === e.id), t > -1) {
313
- const s = this._sessions[t];
314
- i && (yield s.delete()), this._sessions.splice(t, 1);
382
+ if (typeof e == "string" ? t = this._sessions.findIndex((o) => o.id === e) : t = this._sessions.findIndex((o) => o.id === e.id), t > -1) {
383
+ const o = this._sessions[t];
384
+ i && (yield o.delete()), this._sessions.splice(t, 1);
315
385
  } else
316
- console.warn("session delete failed, session is not exist.");
386
+ d.warn("session delete failed, session is not exist.");
317
387
  });
318
388
  }
319
389
  clean() {
320
390
  var e;
321
- (e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this.sessions = [];
391
+ (e = this._disconnectHost) == null || e.call(this), this._disconnectHost = void 0, this._sessions.forEach((i) => i.destroy()), this._sessions = [], this._activeSession = void 0, this.event.emit("sessions:updated", []);
392
+ }
393
+ /** 同 payload 换票后,让已连接的 Agent 会话向服务端发 `update`。 */
394
+ notifySessionsResourceToken(e) {
395
+ const i = new Set(this._sessions);
396
+ this._activeSession && i.add(this._activeSession);
397
+ for (const t of i)
398
+ t.updateSocketResourceToken(e);
322
399
  }
323
400
  }
324
401
  export {
325
- ie as default
402
+ he as default
326
403
  };
@@ -1,21 +1,22 @@
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, n, i) => n in e ? R(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i, r = (e, n) => {
6
- for (var i in n || (n = {}))
7
- w.call(n, i) && C(e, i, n[i]);
8
- if (P)
9
- for (var i of P(n))
10
- O.call(n, i) && C(e, i, n[i]);
1
+ var B = Object.defineProperty, R = Object.defineProperties;
2
+ var w = Object.getOwnPropertyDescriptors;
3
+ var v = Object.getOwnPropertySymbols;
4
+ var k = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
5
+ var b = (e, i, o) => i in e ? B(e, i, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[i] = o, c = (e, i) => {
6
+ for (var o in i || (i = {}))
7
+ k.call(i, o) && b(e, o, i[o]);
8
+ if (v)
9
+ for (var o of v(i))
10
+ E.call(i, o) && b(e, o, i[o]);
11
11
  return e;
12
- }, L = (e, n) => _(e, B(n));
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 = {
12
+ }, P = (e, i) => R(e, w(i));
13
+ import h from "./Logger.mjs";
14
+ import { LOCAL_FILES_PLUGIN_CODES as I } from "./localFiles/constants.mjs";
15
+ import { createBuiltinToolsPlugin as S } from "./builtinTools/createBuiltinToolsPlugin.mjs";
16
+ import { applyLocalMcpPlugins as T } from "./localMcp/registry.mjs";
17
+ const C = new h("[Config] ");
18
+ var L = /* @__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))(L || {});
19
+ let n = {
19
20
  debug: !1,
20
21
  env: "prod",
21
22
  //AIoT 环境, 与apiRoot配对使用
@@ -29,75 +30,64 @@ let o = {
29
30
  builtinPlugins: void 0,
30
31
  mcp: void 0,
31
32
  loadRelatedQuesions: !0,
32
- stream: !1
33
+ stream: !1,
34
+ appVersion: "latest"
33
35
  }, u, l;
34
- const c = /* @__PURE__ */ new Set();
35
- function Q(e) {
36
- u !== e && (u = e, l = void 0, c.clear());
36
+ const r = /* @__PURE__ */ new Set();
37
+ function G(e) {
38
+ u !== e && (u = e, l = void 0, r.clear());
37
39
  }
38
- function Y() {
40
+ function M() {
39
41
  if (!l)
40
42
  return;
41
43
  const {
42
44
  pluginCode: e,
43
- table: n
44
- } = l, i = o.plugins[e], t = n[e];
45
- if (!(!i || i.shell !== t.shell))
45
+ table: i
46
+ } = l, o = n.plugins[e], t = i[e];
47
+ if (!(!o || o.shell !== t.shell))
46
48
  return e;
47
49
  }
48
- function j() {
49
- if (!l)
50
- return;
51
- const {
52
- pluginCode: e,
53
- table: n
54
- } = l, i = o.plugins[e], t = n[e];
55
- if (!(!i || i.run_file !== t.run_file))
56
- return e;
57
- }
58
- function T(e, n) {
59
- return (e == null ? void 0 : e.pluginCode) || k[n];
50
+ function _(e, i) {
51
+ return (e == null ? void 0 : e.pluginCode) || I[i];
60
52
  }
61
- function N(e, n, i) {
62
- return (e == null ? void 0 : e.pluginCode) || i || E[n];
63
- }
64
- function D() {
65
- var v, b, p;
66
- const e = (v = o.businessPlugins) != null ? v : {}, n = (b = o.builtinPlugins) == null ? void 0 : b.localFiles, i = (p = o.builtinPlugins) == null ? void 0 : p.localPython, t = [], d = r({}, e);
67
- if (!!!(n != null && n.enabled || i != null && i.enabled))
68
- return o.plugins = d, t;
53
+ function O() {
54
+ var f, p;
55
+ const e = (f = n.businessPlugins) != null ? f : {}, i = (p = n.builtinPlugins) == null ? void 0 : p.localFiles, o = [], t = c({}, e);
56
+ if (!!!(i != null && i.enabled))
57
+ return g(t), o;
69
58
  if (!u)
70
- return t.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), o.plugins = d, t;
71
- const f = n != null && n.enabled ? T(n, o.env) : void 0, s = f || (i != null && i.enabled ? N(i, o.env, f) : void 0);
72
- return s ? e[s] ? t.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== u || l.pluginCode !== s) && (l = {
59
+ return o.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), g(t), o;
60
+ const s = i != null && i.enabled ? _(i, n.env) : void 0;
61
+ return s ? e[s] ? o.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${s}」,已保留业务插件,内置工具未注册。`) : (((l == null ? void 0 : l.workspace) !== u || l.pluginCode !== s) && (l = {
73
62
  workspace: u,
74
63
  pluginCode: s,
75
- table: I({
64
+ table: S({
76
65
  pluginCode: s,
77
66
  workspace: u
78
67
  })
79
- }), d[s] = l.table[s]) : t.push(`[BuiltinTools] 当前环境(env: ${o.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), o.plugins = d, t;
68
+ }), t[s] = l.table[s]) : o.push(`[BuiltinTools] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), g(t), o;
69
+ }
70
+ function g(e) {
71
+ T(e), n.plugins = e;
80
72
  }
81
- function G() {
82
- return D().filter((e) => !c.has(e)).map((e) => (c.add(e), console.error(e), new Error(e)));
73
+ function W() {
74
+ return O().filter((e) => !r.has(e)).map((e) => (r.add(e), C.report(e), new Error(e)));
83
75
  }
84
- function q(e) {
85
- var n, i, t;
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),
76
+ function N(e, i = {}) {
77
+ var o, t, d;
78
+ h.debug = (e == null ? void 0 : e.debug) || !1, n = P(c(c({}, n), e), {
79
+ apiRoot: (e == null ? void 0 : e.apiRoot) || n.apiRoot || (e != null && e.env ? L[e.env || "prod"] : n.apiRoot),
88
80
  // 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
89
- businessPlugins: (i = (n = e == null ? void 0 : e.plugins) != null ? n : o.businessPlugins) != null ? i : {},
90
- builtinPlugins: (t = e == null ? void 0 : e.builtinPlugins) != null ? t : o.builtinPlugins
91
- }), G(), g.debug && S.log("updated", o);
81
+ businessPlugins: (t = (o = e == null ? void 0 : e.plugins) != null ? o : n.businessPlugins) != null ? t : {},
82
+ builtinPlugins: (d = e == null ? void 0 : e.builtinPlugins) != null ? d : n.builtinPlugins
83
+ }), i.refreshBuiltinPlugins !== !1 && W(), C.log("updated", n);
92
84
  }
93
85
  export {
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
86
+ L as ApiUrl,
87
+ n as configuration,
88
+ N as configure,
89
+ M as getRegisteredLocalFilesPluginCode,
90
+ W as refreshBuiltinPlugins,
91
+ _ as resolveLocalFilesPluginCode,
92
+ G as setActiveLocalWorkspace
103
93
  };