@glodon-aiot/bot-client-sdk 3.27.0-alpha.0 → 3.27.0-alpha.1

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.
@@ -1,56 +1,56 @@
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) => {
1
+ var x = Object.defineProperty, E = Object.defineProperties;
2
+ var L = Object.getOwnPropertyDescriptors;
3
+ var y = Object.getOwnPropertySymbols;
4
+ var W = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
5
+ var v = (l, e, i) => e in l ? x(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
- 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]);
7
+ W.call(e, i) && v(l, i, e[i]);
8
+ if (y)
9
+ for (var i of y(e))
10
+ T.call(e, i) && v(l, i, e[i]);
11
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);
12
+ }, u = (l, e) => E(l, L(e));
13
+ var h = (l, e, i) => (v(l, typeof e != "symbol" ? e + "" : e, i), i);
14
14
  var p = (l, e, i) => new Promise((t, o) => {
15
- var n = (a) => {
15
+ var n = (s) => {
16
16
  try {
17
- s(i.next(a));
17
+ a(i.next(s));
18
18
  } catch (c) {
19
19
  o(c);
20
20
  }
21
- }, r = (a) => {
21
+ }, r = (s) => {
22
22
  try {
23
- s(i.throw(a));
23
+ a(i.throw(s));
24
24
  } catch (c) {
25
25
  o(c);
26
26
  }
27
- }, s = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, r);
28
- s((i = i.apply(l, e)).next());
27
+ }, a = (s) => s.done ? t(s.value) : Promise.resolve(s.value).then(n, r);
28
+ a((i = i.apply(l, e)).next());
29
29
  });
30
- import { parseJWT as y, sameResourceTokenPayload as T } from "./utils.mjs";
31
- import B from "./Logger.mjs";
32
- import { getAIShopService as M, getCVForceService as C } from "./api/index.mjs";
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 {
30
+ import { parseJWT as w, sameResourceTokenPayload as B } from "./utils.mjs";
31
+ import M from "./Logger.mjs";
32
+ import { getAIShopService as C, getCVForceService as V } from "./api/index.mjs";
33
+ import { configure as A, configuration as f, setActiveLocalWorkspace as I, refreshBuiltinPlugins as R, resolveAppVersion as m } from "./Config.mjs";
34
+ import { PlatformSkillSync as O, pullArrangeSkills as H } from "./builtinTools/platformSkills.mjs";
35
+ import { HostBridgeAdapter as D } from "./localFiles/adapters/HostBridgeAdapter.mjs";
36
+ import { connectHostBridge as F } from "./localFiles/host/connectHostBridge.mjs";
37
+ import { connectLocalMcpBridge as j } from "./localMcp/endpoints.mjs";
38
+ import { LocalWorkspace as z } from "./localFiles/workspace/LocalWorkspace.mjs";
39
+ import { createIndexedDbStore as Q } from "./localFiles/workspace/handleStore.mjs";
40
+ import { createDefaultSessionFileTransfer as J } from "./localFiles/transfer/SessionFileTransfer.mjs";
41
+ import { ApplicationTypes as k, PromptVariableType as b } from "@glodon-aiot/apis";
42
+ import P from "./AgentSession.mjs";
43
+ import $ from "./DialogSession.mjs";
44
+ import U from "./EventBus.mjs";
45
+ import G from "./package.json.mjs";
46
+ const d = new M("[BotClient] ");
47
+ class pe {
48
48
  constructor(e, i, t = !0, o = {
49
49
  analytics: {
50
50
  enabled: !1
51
51
  }
52
52
  }) {
53
- h(this, "event", new $());
53
+ h(this, "event", new U());
54
54
  h(this, "cvforceApi");
55
55
  //从token解析出来的用户信息
56
56
  h(this, "_applicationId");
@@ -67,12 +67,12 @@ class he {
67
67
  h(this, "_disconnectHost");
68
68
  /** 后进入的会话作废尚未返回的编排刷新。 */
69
69
  h(this, "arrangeSkillEpoch", 0);
70
- if (this._token = e, this.lazyload = t, this.sdkConfigs = o, w(i, {
70
+ if (this._token = e, this.lazyload = t, this.sdkConfigs = o, A(i, {
71
71
  refreshBuiltinPlugins: !1
72
- }), this._applicationId = y(e).rid || f.applicationId, !this._applicationId)
72
+ }), this._applicationId = w(e).rid || f.applicationId, !this._applicationId)
73
73
  throw "token is not vaild";
74
- this.cvforceApi = this.getService(), F(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
75
- w(u(g({}, i), {
74
+ this.cvforceApi = this.getService(), j(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
75
+ A(u(g({}, i), {
76
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
77
  })), this.logReady(), this.event.emit("ready");
78
78
  });
@@ -90,7 +90,7 @@ class he {
90
90
  var o, n, r;
91
91
  const e = (o = f.builtinPlugins) == null ? void 0 : o.localFiles;
92
92
  if (!(e != null && e.enabled)) {
93
- d.log("workspace:disabled"), A(void 0), I();
93
+ d.log("workspace:disabled"), I(void 0), R();
94
94
  return;
95
95
  }
96
96
  d.log("workspace:setup", {
@@ -100,29 +100,29 @@ class he {
100
100
  if (t !== "file-system-access" && t !== "host-bridge")
101
101
  i.push(new Error(`[LocalFiles] 不支持的 backend:${e.backend}`));
102
102
  else {
103
- const s = M(f.apiRoot, () => this.token, (a, c) => d.error(c));
104
- this._localWorkspace = new j({
103
+ const a = C(f.apiRoot, () => this.token, (s, c) => d.error(c));
104
+ this._localWorkspace = new z({
105
105
  applicationId: this._applicationId,
106
106
  config: e,
107
- store: z(),
107
+ store: Q(),
108
108
  picker: t === "host-bridge" ? null : void 0,
109
- transfer: Q(() => this.cvforceApi, () => s)
110
- }), A(this._localWorkspace), this._localWorkspace.platformSkills = new V({
109
+ transfer: J(() => this.cvforceApi, () => a)
110
+ }), I(this._localWorkspace), this._localWorkspace.platformSkills = new O({
111
111
  applicationId: () => this._applicationId,
112
112
  getToken: () => this.token,
113
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 : [];
114
+ var s, c, _, S;
115
+ return (S = (_ = (c = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : c[0]) == null ? void 0 : _.skills) != null ? S : [];
116
116
  },
117
117
  apiRoot: () => f.apiRoot,
118
118
  getSandbox: () => {
119
119
  var c;
120
- const a = (c = this._localWorkspace) == null ? void 0 : c.adapter;
121
- return a instanceof H ? a.sandbox : void 0;
120
+ const s = (c = this._localWorkspace) == null ? void 0 : c.adapter;
121
+ return s instanceof D ? s.sandbox : void 0;
122
122
  }
123
- }), t === "host-bridge" ? this._disconnectHost = D(this._localWorkspace) : this._localWorkspace.restore();
123
+ }), t === "host-bridge" ? this._disconnectHost = F(this._localWorkspace) : this._localWorkspace.restore();
124
124
  }
125
- i.push(...I()), i.length && Promise.resolve().then(() => i.forEach((s) => this.event.emit("error", s)));
125
+ i.push(...R()), i.length && Promise.resolve().then(() => i.forEach((a) => this.event.emit("error", a)));
126
126
  }
127
127
  /** 启用 builtinPlugins.localFiles 后可用;UI 与纯 SDK 集成共用此实例。 */
128
128
  get localWorkspace() {
@@ -156,30 +156,35 @@ class he {
156
156
  }
157
157
  loadApplication() {
158
158
  return p(this, null, function* () {
159
- var i, t, o, n, r;
159
+ var t, o, n, r, a;
160
160
  this._application = yield this.cvforceApi.getApplicationId(
161
161
  this._applicationId,
162
162
  // 这里记录应用的名称和版本,以便后期数据分析
163
163
  {
164
- ui: (i = this.sdkConfigs.ui) == null ? void 0 : i.name,
165
- uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
166
- sdkVersion: U.version
164
+ ui: (t = this.sdkConfigs.ui) == null ? void 0 : t.name,
165
+ uiVersion: (o = this.sdkConfigs.ui) == null ? void 0 : o.version,
166
+ sdkVersion: G.version,
167
+ version: m()
167
168
  }
168
169
  ).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
170
  arrange: [u(g({}, s.arrange[0]), {
170
171
  recommendQuestionOpen: f.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
171
172
  })]
172
173
  })));
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
174
+ const e = (a = (r = (n = this._application) == null ? void 0 : n.arrange) == null ? void 0 : r[0]) == null ? void 0 : a.llmModel;
175
+ e && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(e).then((s) => s.maxModelLength));
176
+ const i = m();
177
+ return this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
178
+ type: b.User,
179
+ version: i
176
180
  }), this.cvforceApi.getPrompts(this._applicationId, {
177
- type: R.System
178
- })]).then(([s, a]) => [...s, ...a]), this._ready = !0, this.event.emit("application:loaded"), this._application;
181
+ type: b.System,
182
+ version: i
183
+ })]).then(([s, c]) => [...s, ...c]), this._ready = !0, this.event.emit("application:loaded"), this._application;
179
184
  });
180
185
  }
181
186
  getService() {
182
- return this.cvforceApi ? this.cvforceApi : C(f.apiRoot, () => this.token, (e, i) => d.error(i));
187
+ return this.cvforceApi ? this.cvforceApi : V(f.apiRoot, () => this.token, (e, i) => d.error(i));
183
188
  }
184
189
  get token() {
185
190
  return this._token;
@@ -190,12 +195,12 @@ class he {
190
195
  * 任一不同时沿用原逻辑(ready 置 false,应用 id 变则重载并 clean)。
191
196
  */
192
197
  set token(e) {
193
- if (this.checkReady(), T(this._token, e)) {
198
+ if (this.checkReady(), B(this._token, e)) {
194
199
  this._token = e, this.notifySessionsResourceToken(e);
195
200
  return;
196
201
  }
197
202
  this._token = e, this.ready = !1;
198
- const i = y(e).rid;
203
+ const i = w(e).rid;
199
204
  this._applicationId !== i && (this._applicationId = i, this._application = null, this.loadApplication().then(() => {
200
205
  this.logReady(), this.event.emit("ready");
201
206
  }), this.clean());
@@ -218,12 +223,12 @@ class he {
218
223
  createSession(e, i, t, o, n) {
219
224
  return p(this, null, function* () {
220
225
  const r = this;
221
- return new Promise((s, a) => {
226
+ return new Promise((a, s) => {
222
227
  const c = (_) => p(this, null, function* () {
223
228
  if (_ === k.Agent)
224
- s(new J(e, i, t, o, n, r));
229
+ a(new P(e, i, t, o, n, r));
225
230
  else if (_ === k.Dialog)
226
- s(new P(e, i, t, o, n, r));
231
+ a(new $(e, i, t, o, n, r));
227
232
  else
228
233
  throw Error(`不支持的应用类型:${_}`);
229
234
  });
@@ -250,7 +255,7 @@ class he {
250
255
  const i = e || ((n = this._activeSession) == null ? void 0 : n.id);
251
256
  if (!i)
252
257
  throw new Error("session id is not defined");
253
- const t = this._sessions.find((s) => s.id === i);
258
+ const t = this._sessions.find((a) => a.id === i);
254
259
  if (t)
255
260
  return t.getArtifacts();
256
261
  const o = yield this.cvforceApi.getSessionArtifacts(this._applicationId, i);
@@ -262,12 +267,12 @@ class he {
262
267
  return new Promise((i, t) => {
263
268
  const o = () => this.cvforceApi.listSessions(this._applicationId, e).then((n) => p(this, null, function* () {
264
269
  const r = [];
265
- for (const s of n) {
266
- const a = this._sessions.find((c) => c.id === s.id);
267
- if (a)
268
- a.data = s, this._application ? a.application = this._application : yield a.loadApplicationInfo(), r.push(a);
270
+ for (const a of n) {
271
+ const s = this._sessions.find((c) => c.id === a.id);
272
+ if (s)
273
+ s.data = a, this._application ? s.application = this._application : yield s.loadApplicationInfo(), r.push(s);
269
274
  else {
270
- const c = yield this.createSession(this.token, s.id, s, this.lazyload, this._application || void 0);
275
+ const c = yield this.createSession(this.token, a.id, a, this.lazyload, this._application || void 0);
271
276
  r.push(c);
272
277
  }
273
278
  }
@@ -275,10 +280,10 @@ class he {
275
280
  count: r.length,
276
281
  paged: !!(e != null && e.pageSize)
277
282
  }), 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);
281
- return this.sessions = Array.from(a.values()), this.sessions;
283
+ const a = [...this._sessions, ...r], s = /* @__PURE__ */ new Map();
284
+ for (const c of a)
285
+ s.set(c.id, c);
286
+ return this.sessions = Array.from(s.values()), this.sessions;
282
287
  } else
283
288
  return this.sessions = r, r;
284
289
  }));
@@ -301,17 +306,19 @@ class he {
301
306
  var t, o, n;
302
307
  const e = (o = (t = this._application) == null ? void 0 : t.arrange) == null ? void 0 : o[0], i = ++this.arrangeSkillEpoch;
303
308
  try {
304
- yield O({
309
+ yield H({
305
310
  // 已发布的 IArrange 类型尚未带上 skills,与 getSkills 一样在这里收窄。
306
311
  arrange: e,
307
- fetchApplication: () => this.cvforceApi.getApplicationId(this._applicationId),
312
+ fetchApplication: () => this.cvforceApi.getApplicationId(this._applicationId, {
313
+ version: m()
314
+ }),
308
315
  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;
316
+ var a, s;
317
+ return i === this.arrangeSkillEpoch && ((s = (a = this._application) == null ? void 0 : a.arrange) == null ? void 0 : s[0]) === e;
311
318
  }
312
319
  });
313
320
  const r = (n = e == null ? void 0 : e.skills) != null ? n : [];
314
- d.log("arrange:skills", r.map((s) => s.name).filter(Boolean));
321
+ d.log("arrange:skills", r.map((a) => a.name).filter(Boolean));
315
322
  } catch (r) {
316
323
  d.error("刷新编排技能失败", r);
317
324
  }
@@ -399,5 +406,5 @@ class he {
399
406
  }
400
407
  }
401
408
  export {
402
- he as default
409
+ pe as default
403
410
  };
@@ -32,62 +32,67 @@ let n = {
32
32
  loadRelatedQuesions: !0,
33
33
  stream: !1,
34
34
  appVersion: "latest"
35
- }, u, l;
36
- const r = /* @__PURE__ */ new Set();
35
+ }, u, s;
36
+ const g = /* @__PURE__ */ new Set();
37
+ function F() {
38
+ var e;
39
+ return ((e = n.appVersion) == null ? void 0 : e.trim()) || "latest";
40
+ }
37
41
  function G(e) {
38
- u !== e && (u = e, l = void 0, r.clear());
42
+ u !== e && (u = e, s = void 0, g.clear());
39
43
  }
40
44
  function M() {
41
- if (!l)
45
+ if (!s)
42
46
  return;
43
47
  const {
44
48
  pluginCode: e,
45
49
  table: i
46
- } = l, o = n.plugins[e], t = i[e];
50
+ } = s, o = n.plugins[e], t = i[e];
47
51
  if (!(!o || o.shell !== t.shell))
48
52
  return e;
49
53
  }
50
- function _(e, i) {
54
+ function V(e, i) {
51
55
  return (e == null ? void 0 : e.pluginCode) || I[i];
52
56
  }
53
- function O() {
57
+ function _() {
54
58
  var f, p;
55
59
  const e = (f = n.businessPlugins) != null ? f : {}, i = (p = n.builtinPlugins) == null ? void 0 : p.localFiles, o = [], t = c({}, e);
56
60
  if (!!!(i != null && i.enabled))
57
- return g(t), o;
61
+ return d(t), o;
58
62
  if (!u)
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 = {
63
+ return o.push("[BuiltinTools] 内置工具依赖已启用的本地工作区。工具未注册。"), d(t), o;
64
+ const l = i != null && i.enabled ? V(i, n.env) : void 0;
65
+ return l ? e[l] ? o.push(`[BuiltinTools] 业务插件中已存在 pluginCode「${l}」,已保留业务插件,内置工具未注册。`) : (((s == null ? void 0 : s.workspace) !== u || s.pluginCode !== l) && (s = {
62
66
  workspace: u,
63
- pluginCode: s,
67
+ pluginCode: l,
64
68
  table: S({
65
- pluginCode: s,
69
+ pluginCode: l,
66
70
  workspace: u
67
71
  })
68
- }), t[s] = l.table[s]) : o.push(`[BuiltinTools] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), g(t), o;
72
+ }), t[l] = s.table[l]) : o.push(`[BuiltinTools] 当前环境(env: ${n.env})没有默认的内置工具插件编码,请配置 builtinPlugins.localFiles.pluginCode。内置工具未注册。`), d(t), o;
69
73
  }
70
- function g(e) {
74
+ function d(e) {
71
75
  T(e), n.plugins = e;
72
76
  }
73
- function W() {
74
- return O().filter((e) => !r.has(e)).map((e) => (r.add(e), C.report(e), new Error(e)));
77
+ function O() {
78
+ return _().filter((e) => !g.has(e)).map((e) => (g.add(e), C.report(e), new Error(e)));
75
79
  }
76
80
  function N(e, i = {}) {
77
- var o, t, d;
81
+ var o, t, r;
78
82
  h.debug = (e == null ? void 0 : e.debug) || !1, n = P(c(c({}, n), e), {
79
83
  apiRoot: (e == null ? void 0 : e.apiRoot) || n.apiRoot || (e != null && e.env ? L[e.env || "prod"] : n.apiRoot),
80
84
  // 应用未注册插件时 param.plugins 为 undefined,避免覆盖默认空表
81
85
  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);
86
+ builtinPlugins: (r = e == null ? void 0 : e.builtinPlugins) != null ? r : n.builtinPlugins
87
+ }), i.refreshBuiltinPlugins !== !1 && O(), C.log("updated", n);
84
88
  }
85
89
  export {
86
90
  L as ApiUrl,
87
91
  n as configuration,
88
92
  N as configure,
89
93
  M as getRegisteredLocalFilesPluginCode,
90
- W as refreshBuiltinPlugins,
91
- _ as resolveLocalFilesPluginCode,
94
+ O as refreshBuiltinPlugins,
95
+ F as resolveAppVersion,
96
+ V as resolveLocalFilesPluginCode,
92
97
  G as setActiveLocalWorkspace
93
98
  };
@@ -1,15 +1,15 @@
1
- var V = Object.defineProperty, M = Object.defineProperties;
2
- var O = Object.getOwnPropertyDescriptors;
1
+ var M = Object.defineProperty, O = Object.defineProperties;
2
+ var R = Object.getOwnPropertyDescriptors;
3
3
  var x = Object.getOwnPropertySymbols;
4
- var R = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
5
- var b = (p, e, t) => e in p ? V(p, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[e] = t, u = (p, e) => {
4
+ var z = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable;
5
+ var b = (p, e, t) => e in p ? M(p, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[e] = t, u = (p, e) => {
6
6
  for (var t in e || (e = {}))
7
- R.call(e, t) && b(p, t, e[t]);
7
+ z.call(e, t) && b(p, t, e[t]);
8
8
  if (x)
9
9
  for (var t of x(e))
10
- z.call(e, t) && b(p, t, e[t]);
10
+ P.call(e, t) && b(p, t, e[t]);
11
11
  return p;
12
- }, y = (p, e) => M(p, O(e));
12
+ }, y = (p, e) => O(p, R(e));
13
13
  var f = (p, e, t) => (b(p, typeof e != "symbol" ? e + "" : e, t), t);
14
14
  var c = (p, e, t) => new Promise((i, o) => {
15
15
  var n = (a) => {
@@ -28,17 +28,17 @@ var c = (p, e, t) => new Promise((i, o) => {
28
28
  d((t = t.apply(p, e)).next());
29
29
  });
30
30
  import { v4 as Q } from "uuid";
31
- import { parseJWT as P, resolveRelatedQuestionContent as q, removeNewlines as F, removeLeadingAndTrailingBackslashes as N } from "./utils.mjs";
32
- import { ApplicationTypes as T, PromptStatus as U, PromptVariableType as L, ChatMessageRole as S } from "@glodon-aiot/apis";
33
- import B from "./Logger.mjs";
34
- import { configuration as _ } from "./Config.mjs";
35
- import H from "./EventBus.mjs";
36
- import { getCVForceService as K } from "./api/index.mjs";
37
- import Y from "dayjs";
38
- import { uploadSessionFile as G } from "./sessionUpload.mjs";
39
- const C = 100, l = new B("[Session] ");
40
- var j = /* @__PURE__ */ ((p) => (p.DataRequestFailed = "data request error", p.SocketConnectionFailed = "socket error", p.IdUndefined = "session id is not defined", p.SendingEmptyContent = "failed at sending empty content", p.Frozen = "session is frozen", p.UserModeError = "failed at setting socket user mode", p.Inactive = "session is inactive", p))(j || {});
41
- class ne {
31
+ import { parseJWT as q, resolveRelatedQuestionContent as F, removeNewlines as N, removeLeadingAndTrailingBackslashes as U } from "./utils.mjs";
32
+ import { ApplicationTypes as T, PromptStatus as B, PromptVariableType as L, ChatMessageRole as S } from "@glodon-aiot/apis";
33
+ import H from "./Logger.mjs";
34
+ import { configuration as _, resolveAppVersion as C } from "./Config.mjs";
35
+ import K from "./EventBus.mjs";
36
+ import { getCVForceService as Y } from "./api/index.mjs";
37
+ import G from "dayjs";
38
+ import { uploadSessionFile as j } from "./sessionUpload.mjs";
39
+ const V = 100, l = new H("[Session] ");
40
+ var D = /* @__PURE__ */ ((p) => (p.DataRequestFailed = "data request error", p.SocketConnectionFailed = "socket error", p.IdUndefined = "session id is not defined", p.SendingEmptyContent = "failed at sending empty content", p.Frozen = "session is frozen", p.UserModeError = "failed at setting socket user mode", p.Inactive = "session is inactive", p))(D || {});
41
+ class ae {
42
42
  /**
43
43
  * Session 类的构造函数,用于初始化会话实例。
44
44
  * @param token - 用户的身份验证令牌,用于解析应用 ID。
@@ -55,7 +55,7 @@ class ne {
55
55
  f(this, "inactivating", !1);
56
56
  f(this, "_ready", !1);
57
57
  // ready = false;
58
- f(this, "event", new H());
58
+ f(this, "event", new K());
59
59
  //从token解析出来的用户信息
60
60
  f(this, "_applicationId");
61
61
  f(this, "_application", null);
@@ -73,7 +73,7 @@ class ne {
73
73
  f(this, "_dataLoading", !1);
74
74
  f(this, "_dataLoaded", !1);
75
75
  f(this, "_mcpServers", null);
76
- this.token = e, this.lazyload = o, this.client = h || null, this._applicationId = P(e).rid || _.applicationId, this.cvforceApi = this.getService(), n && (this._application = n), this.event.emit("init", {
76
+ this.token = e, this.lazyload = o, this.client = h || null, this._applicationId = q(e).rid || _.applicationId, this.cvforceApi = this.getService(), n && (this._application = n), this.event.emit("init", {
77
77
  applicationId: this._applicationId,
78
78
  sessionId: t
79
79
  }), this.loadApplicationInfo().then(() => {
@@ -98,7 +98,8 @@ class ne {
98
98
  // @ts-ignore
99
99
  netOpen: i == null ? void 0 : i.netOpen,
100
100
  knowledgeIdList: (d = i == null ? void 0 : i.knowledges) == null ? void 0 : d.map((s) => s.id),
101
- applicationId: this._applicationId
101
+ applicationId: this._applicationId,
102
+ version: C()
102
103
  }).then((s) => c(this, null, function* () {
103
104
  var m;
104
105
  this._id = s.id, this.data = y(u({}, s), {
@@ -159,7 +160,9 @@ class ne {
159
160
  if (this._application)
160
161
  return Promise.resolve(this._application);
161
162
  if (this._applicationId && !this._application)
162
- return this.event.emit("application:data:loading"), this.cvforceApi.getApplicationId(this._applicationId).then((e) => (this._application = e, this.event.emit("application:data:loaded", e), e));
163
+ return this.event.emit("application:data:loading"), this.cvforceApi.getApplicationId(this._applicationId, {
164
+ version: C()
165
+ }).then((e) => (this._application = e, this.event.emit("application:data:loaded", e), e));
163
166
  throw Error("application id is not defined");
164
167
  }
165
168
  get ready() {
@@ -186,8 +189,8 @@ class ne {
186
189
  var d, a;
187
190
  const h = (a = (d = n.fileIds) == null ? void 0 : d.length) != null ? a : 0;
188
191
  return o + (h > 0 ? h : 1);
189
- }, 0) > C)
190
- throw Error(`knowledges and fileIds total count cannot exceed ${C}`);
192
+ }, 0) > V)
193
+ throw Error(`knowledges and fileIds total count cannot exceed ${V}`);
191
194
  return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
192
195
  knowledges: e
193
196
  }), this.data.knowledges = e, this.event.emit("data:updated", this.data), this.event.emit("data:updated:knowledges", {
@@ -200,7 +203,7 @@ class ne {
200
203
  throw Error("session id is not defined");
201
204
  if (!this.data)
202
205
  throw Error("session data is not loaded");
203
- const e = this.promptVariables.filter((t) => t.status === U.Quoted).filter((t) => !t.value);
206
+ const e = this.promptVariables.filter((t) => t.status === B.Quoted).filter((t) => !t.value);
204
207
  if (e.length)
205
208
  throw Error(`在提示词中被引用的变量值不能为空, 请检查以下变量: ${e.map((t) => t.key).join(", ")}`);
206
209
  }
@@ -279,7 +282,7 @@ class ne {
279
282
  updateSocketResourceToken(e) {
280
283
  }
281
284
  getService() {
282
- return K(_.apiRoot, () => this.requestToken, (e, t) => {
285
+ return Y(_.apiRoot, () => this.requestToken, (e, t) => {
283
286
  const i = new Error("data request error", {
284
287
  cause: {
285
288
  status: e,
@@ -444,7 +447,7 @@ class ne {
444
447
  return c(this, null, function* () {
445
448
  if (!this._id)
446
449
  throw Error("session is not avalible. id is undefined");
447
- return G(this.cvforceApi, this._id, e);
450
+ return j(this.cvforceApi, this._id, e);
448
451
  });
449
452
  }
450
453
  send(i) {
@@ -574,7 +577,7 @@ class ne {
574
577
  sensitive: !!e.isSensitive,
575
578
  hasContent: !!e.content
576
579
  }), e;
577
- const i = q(t == null ? void 0 : t.recommendQuestionOpen, t == null ? void 0 : t.relatedQuestionApp, e.content, this.currentUserQuestion());
580
+ const i = F(t == null ? void 0 : t.recommendQuestionOpen, t == null ? void 0 : t.relatedQuestionApp, e.content, this.currentUserQuestion());
578
581
  if (i === null)
579
582
  return l.log("related:skip", {
580
583
  recommendQuestionOpen: t == null ? void 0 : t.recommendQuestionOpen
@@ -593,7 +596,7 @@ class ne {
593
596
  relatedQuesion: s
594
597
  }), this.event.emit("message:updated", m), m;
595
598
  }
596
- const n = (a = o.content) == null ? void 0 : a.split("*").map(F).map(N).filter((s) => !!s);
599
+ const n = (a = o.content) == null ? void 0 : a.split("*").map(N).map(U).filter((s) => !!s);
597
600
  e.relatedQuesion = n, e.index = -3, e.isLoading = !1;
598
601
  const h = y(u({}, e), {
599
602
  relatedQuesion: n,
@@ -697,7 +700,7 @@ class ne {
697
700
  // 标记消息已停止加载
698
701
  index: -2,
699
702
  // 消息索引,用于标识特殊状态
700
- messageTime: Y(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
703
+ messageTime: G(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
701
704
  // 消息时间
702
705
  content: "",
703
706
  // 消息内容
@@ -836,7 +839,7 @@ class ne {
836
839
  }
837
840
  }
838
841
  export {
839
- C as MAX_KNOWLEDGES_AND_FILES_COUNT,
840
- j as SessionErrors,
841
- ne as default
842
+ V as MAX_KNOWLEDGES_AND_FILES_COUNT,
843
+ D as SessionErrors,
844
+ ae as default
842
845
  };