@glodon-aiot/bot-client-sdk 3.3.3 → 3.3.4-beta.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.
- package/dist/es/AgentSession.mjs +172 -131
- package/dist/es/BotClient.mjs +83 -77
- package/dist/es/Config.mjs +7 -6
- package/dist/es/DialogSession.mjs +142 -169
- package/dist/es/Session.mjs +252 -211
- package/dist/es/package.json.mjs +11 -11
- package/dist/lib/index.js +4 -4
- package/dist/src/Config.d.ts +2 -0
- package/dist/src/Session.d.ts +7 -1
- package/package.json +2 -2
package/dist/es/BotClient.mjs
CHANGED
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var k = Object.defineProperty, A = Object.defineProperties;
|
|
2
|
+
var x = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var m = Object.getOwnPropertySymbols;
|
|
4
|
+
var I = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var u = (r, i, e) => i in r ? k(r, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[i] = e, d = (r, i) => {
|
|
6
6
|
for (var e in i || (i = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var h = (
|
|
15
|
-
var
|
|
7
|
+
I.call(i, e) && u(r, e, i[e]);
|
|
8
|
+
if (m)
|
|
9
|
+
for (var e of m(i))
|
|
10
|
+
R.call(i, e) && u(r, e, i[e]);
|
|
11
|
+
return r;
|
|
12
|
+
}, f = (r, i) => A(r, x(i));
|
|
13
|
+
var p = (r, i, e) => (u(r, typeof i != "symbol" ? i + "" : i, e), e);
|
|
14
|
+
var h = (r, i, e) => new Promise((t, s) => {
|
|
15
|
+
var a = (o) => {
|
|
16
16
|
try {
|
|
17
|
-
n(e.next(
|
|
18
|
-
} catch (
|
|
19
|
-
s(
|
|
17
|
+
n(e.next(o));
|
|
18
|
+
} catch (l) {
|
|
19
|
+
s(l);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, c = (o) => {
|
|
22
22
|
try {
|
|
23
|
-
n(e.throw(
|
|
24
|
-
} catch (
|
|
25
|
-
s(
|
|
23
|
+
n(e.throw(o));
|
|
24
|
+
} catch (l) {
|
|
25
|
+
s(l);
|
|
26
26
|
}
|
|
27
|
-
}, n = (
|
|
28
|
-
n((e = e.apply(
|
|
27
|
+
}, n = (o) => o.done ? t(o.value) : Promise.resolve(o.value).then(a, c);
|
|
28
|
+
n((e = e.apply(r, i)).next());
|
|
29
29
|
});
|
|
30
|
-
import { parseJWT as
|
|
31
|
-
import
|
|
32
|
-
import { getCVForceService as
|
|
33
|
-
import { configure as
|
|
34
|
-
import { ApplicationTypes as
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
const
|
|
40
|
-
class
|
|
30
|
+
import { parseJWT as g } from "./utils.mjs";
|
|
31
|
+
import E from "./Logger.mjs";
|
|
32
|
+
import { getCVForceService as L } from "./api/index.mjs";
|
|
33
|
+
import { configure as S, configuration as y } from "./Config.mjs";
|
|
34
|
+
import { ApplicationTypes as v, PromptVariableType as w } from "@glodon-aiot/apis";
|
|
35
|
+
import C from "./AgentSession.mjs";
|
|
36
|
+
import M from "./DialogSession.mjs";
|
|
37
|
+
import V from "./EventBus.mjs";
|
|
38
|
+
import T from "./package.json.mjs";
|
|
39
|
+
const b = new E("[BotClient] ");
|
|
40
|
+
class U {
|
|
41
41
|
constructor(i, e, t = !0, s = {
|
|
42
42
|
analytics: {
|
|
43
43
|
enabled: !1
|
|
44
44
|
}
|
|
45
45
|
}) {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
p(this, "event", new V());
|
|
47
|
+
p(this, "cvforceApi");
|
|
48
48
|
//从token解析出来的用户信息
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
p(this, "_applicationId");
|
|
50
|
+
p(this, "_application", null);
|
|
51
51
|
//session列表,被加载过的session将会被缓存到这个列表中
|
|
52
|
-
|
|
52
|
+
p(this, "_sessions", []);
|
|
53
53
|
//活跃的session,只支持一个活跃的session
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
p(this, "_activeSession");
|
|
55
|
+
p(this, "_ready", !1);
|
|
56
56
|
//问题长度
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (this._token = i, this.lazyload = t, this.sdkConfigs = s,
|
|
57
|
+
p(this, "_questionContextMaxLength", 4e3);
|
|
58
|
+
p(this, "_promptVariables", []);
|
|
59
|
+
if (this._token = i, this.lazyload = t, this.sdkConfigs = s, S(e), this._applicationId = g(i).rid || y.applicationId, !this._applicationId)
|
|
60
60
|
throw "token is not vaild";
|
|
61
|
-
this.cvforceApi = this.getService(), this.loadApplication().then(() => {
|
|
62
|
-
|
|
61
|
+
this.cvforceApi = this.getService(), this.loadApplication().then((a) => {
|
|
62
|
+
S(f(d({}, e), {
|
|
63
|
+
stream: e.stream === void 0 ? (a == null ? void 0 : a.type) === v.Dialog : e.stream
|
|
64
|
+
})), this.event.emit("ready");
|
|
63
65
|
});
|
|
64
66
|
}
|
|
65
67
|
checkReady() {
|
|
@@ -90,33 +92,37 @@ class F {
|
|
|
90
92
|
}
|
|
91
93
|
loadApplication() {
|
|
92
94
|
return h(this, null, function* () {
|
|
93
|
-
var e, t, s,
|
|
95
|
+
var e, t, s, a, c;
|
|
94
96
|
this._application = yield this.cvforceApi.getApplicationId(
|
|
95
97
|
this._applicationId,
|
|
96
98
|
// 这里记录应用的名称和版本,以便后期数据分析
|
|
97
99
|
{
|
|
98
100
|
ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
|
|
99
101
|
uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
|
|
100
|
-
sdkVersion:
|
|
102
|
+
sdkVersion: T.version
|
|
101
103
|
}
|
|
102
|
-
).then((n) => (typeof n.arrange[0].recommendQuestionOpen != "boolean" && (n.arrange[0].recommendQuestionOpen = !0),
|
|
103
|
-
arrange: [
|
|
104
|
-
recommendQuestionOpen:
|
|
104
|
+
).then((n) => (typeof n.arrange[0].recommendQuestionOpen != "boolean" && (n.arrange[0].recommendQuestionOpen = !0), f(d({}, n), {
|
|
105
|
+
arrange: [f(d({}, n.arrange[0]), {
|
|
106
|
+
recommendQuestionOpen: y.loadRelatedQuesions && n.arrange[0].recommendQuestionOpen
|
|
105
107
|
})]
|
|
106
108
|
})));
|
|
107
|
-
const i = (
|
|
108
|
-
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((n) => n.maxModelLength)), this._promptVariables = yield this.cvforceApi.getPrompts(this._applicationId
|
|
109
|
+
const i = (c = (a = (s = this._application) == null ? void 0 : s.arrange) == null ? void 0 : a[0]) == null ? void 0 : c.llmModel;
|
|
110
|
+
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((n) => n.maxModelLength)), this._promptVariables = yield Promise.all([this.cvforceApi.getPrompts(this._applicationId, {
|
|
111
|
+
type: w.User
|
|
112
|
+
}), this.cvforceApi.getPrompts(this._applicationId, {
|
|
113
|
+
type: w.System
|
|
114
|
+
})]).then(([n, o]) => [...n, ...o]), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
109
115
|
});
|
|
110
116
|
}
|
|
111
117
|
getService() {
|
|
112
|
-
return this.cvforceApi ? this.cvforceApi :
|
|
118
|
+
return this.cvforceApi ? this.cvforceApi : L(y.apiRoot, this.token, (i, e) => b.error(e));
|
|
113
119
|
}
|
|
114
120
|
get token() {
|
|
115
121
|
return this._token;
|
|
116
122
|
}
|
|
117
123
|
set token(i) {
|
|
118
124
|
this.checkReady(), this._token = i, this.ready = !1;
|
|
119
|
-
const e =
|
|
125
|
+
const e = g(i).rid;
|
|
120
126
|
this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
|
|
121
127
|
this.event.emit("ready");
|
|
122
128
|
}), this.clean());
|
|
@@ -136,27 +142,27 @@ class F {
|
|
|
136
142
|
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
|
-
createSession(i, e, t, s,
|
|
145
|
+
createSession(i, e, t, s, a) {
|
|
140
146
|
return h(this, null, function* () {
|
|
141
|
-
const
|
|
142
|
-
return new Promise((n,
|
|
143
|
-
const
|
|
144
|
-
if (
|
|
145
|
-
n(new
|
|
146
|
-
else if (
|
|
147
|
-
n(new
|
|
147
|
+
const c = this;
|
|
148
|
+
return new Promise((n, o) => {
|
|
149
|
+
const l = (_) => h(this, null, function* () {
|
|
150
|
+
if (_ === v.Agent)
|
|
151
|
+
n(new C(i, e, t, s, a, c));
|
|
152
|
+
else if (_ === v.Dialog)
|
|
153
|
+
n(new M(i, e, t, s, a, c));
|
|
148
154
|
else
|
|
149
|
-
throw Error(`不支持的应用类型:${
|
|
155
|
+
throw Error(`不支持的应用类型:${_}`);
|
|
150
156
|
});
|
|
151
157
|
if (this.ready) {
|
|
152
158
|
if (!this._application)
|
|
153
159
|
throw Error("client is not ready");
|
|
154
|
-
|
|
160
|
+
l(this._application.type);
|
|
155
161
|
} else
|
|
156
162
|
this.event.on("ready", () => {
|
|
157
163
|
if (!this._application)
|
|
158
164
|
throw Error("_application is null");
|
|
159
|
-
|
|
165
|
+
l(this._application.type);
|
|
160
166
|
}, !0);
|
|
161
167
|
});
|
|
162
168
|
});
|
|
@@ -164,17 +170,17 @@ class F {
|
|
|
164
170
|
getSessions(i) {
|
|
165
171
|
return h(this, null, function* () {
|
|
166
172
|
return new Promise((e, t) => {
|
|
167
|
-
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((
|
|
168
|
-
const
|
|
169
|
-
return
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
+
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((a) => {
|
|
174
|
+
const c = [];
|
|
175
|
+
return a.forEach((n) => h(this, null, function* () {
|
|
176
|
+
const o = this._sessions.find((l) => n.id === l.id);
|
|
177
|
+
if (o)
|
|
178
|
+
o.data = n, this._application ? o.application = this._application : o.loadApplicationInfo(), c.push(o);
|
|
173
179
|
else {
|
|
174
|
-
const
|
|
175
|
-
|
|
180
|
+
const l = yield this.createSession(this.token, n.id, n, this.lazyload, this._application || void 0);
|
|
181
|
+
c.push(l);
|
|
176
182
|
}
|
|
177
|
-
})), this.sessions =
|
|
183
|
+
})), this.sessions = c, c;
|
|
178
184
|
});
|
|
179
185
|
if (this.ready) {
|
|
180
186
|
if (!this._application)
|
|
@@ -221,7 +227,7 @@ class F {
|
|
|
221
227
|
}
|
|
222
228
|
setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
|
|
223
229
|
return h(this, null, function* () {
|
|
224
|
-
let s = i ? this._sessions.find((
|
|
230
|
+
let s = i ? this._sessions.find((a) => a.id === i) : this._activeSession;
|
|
225
231
|
if (!s) {
|
|
226
232
|
console.warn("setTop session failed.");
|
|
227
233
|
return;
|
|
@@ -259,5 +265,5 @@ class F {
|
|
|
259
265
|
}
|
|
260
266
|
}
|
|
261
267
|
export {
|
|
262
|
-
|
|
268
|
+
U as default
|
|
263
269
|
};
|
package/dist/es/Config.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var s = Object.defineProperty, v = Object.defineProperties;
|
|
2
2
|
var u = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var n = Object.getOwnPropertySymbols;
|
|
4
4
|
var p = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var g = (o, t, e) => t in o ?
|
|
5
|
+
var g = (o, t, e) => t in o ? s(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, i = (o, t) => {
|
|
6
6
|
for (var e in t || (t = {}))
|
|
7
7
|
p.call(t, e) && g(o, e, t[e]);
|
|
8
8
|
if (n)
|
|
9
9
|
for (var e of n(t))
|
|
10
10
|
h.call(t, e) && g(o, e, t[e]);
|
|
11
11
|
return o;
|
|
12
|
-
}, l = (o, t) =>
|
|
12
|
+
}, l = (o, t) => v(o, u(t));
|
|
13
13
|
import d from "./Logger.mjs";
|
|
14
14
|
const R = new d("[Config] ");
|
|
15
15
|
var f = /* @__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))(f || {});
|
|
@@ -22,9 +22,10 @@ let c = {
|
|
|
22
22
|
applicationId: "",
|
|
23
23
|
plugins: {},
|
|
24
24
|
mcp: void 0,
|
|
25
|
-
loadRelatedQuesions: !0
|
|
25
|
+
loadRelatedQuesions: !0,
|
|
26
|
+
stream: !1
|
|
26
27
|
};
|
|
27
|
-
function
|
|
28
|
+
function w(o) {
|
|
28
29
|
d.debug = (o == null ? void 0 : o.debug) || !1, c = l(i(i({}, c), o), {
|
|
29
30
|
apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
|
|
30
31
|
}), d.debug && R.log("updated", c);
|
|
@@ -32,5 +33,5 @@ function x(o) {
|
|
|
32
33
|
export {
|
|
33
34
|
f as ApiUrl,
|
|
34
35
|
c as configuration,
|
|
35
|
-
|
|
36
|
+
w as configure
|
|
36
37
|
};
|