@glodon-aiot/agent-cli-sdk 2.4.7
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/README.md +70 -0
- package/dist/agent-cli-sdk.js +34975 -0
- package/dist/agent-cli-sdk.umd.cjs +150 -0
- package/dist/cdn/agent-cli-sdk.js +32945 -0
- package/dist/cdn/agent-cli-sdk.umd.cjs +140 -0
- package/dist/cdn/src/AgentPlugin.d.ts +17 -0
- package/dist/cdn/src/AgentSession.d.ts +8 -0
- package/dist/cdn/src/BotClient.d.ts +46 -0
- package/dist/cdn/src/Config.d.ts +32 -0
- package/dist/cdn/src/DialogSession.d.ts +21 -0
- package/dist/cdn/src/EventBus.d.ts +23 -0
- package/dist/cdn/src/Logger.d.ts +12 -0
- package/dist/cdn/src/PayloadTypes.d.ts +84 -0
- package/dist/cdn/src/Session.d.ts +156 -0
- package/dist/cdn/src/__ tests __/AgentClient.spec.d.ts +1 -0
- package/dist/cdn/src/__ tests __/AgentSession.spec.d.ts +1 -0
- package/dist/cdn/src/__ tests __/DialogClient.spec.d.ts +1 -0
- package/dist/cdn/src/api/fetchEventSource/fetch.d.ts +44 -0
- package/dist/cdn/src/api/fetchEventSource/index.d.ts +1 -0
- package/dist/cdn/src/api/fetchEventSource/parse.d.ts +36 -0
- package/dist/cdn/src/api/index.d.ts +2 -0
- package/dist/cdn/src/index.d.ts +5 -0
- package/dist/cdn/src/utils.d.ts +4 -0
- package/dist/es/AgentPlugin.mjs +20 -0
- package/dist/es/AgentSession.mjs +243 -0
- package/dist/es/BotClient.mjs +242 -0
- package/dist/es/Config.mjs +34 -0
- package/dist/es/DialogSession.mjs +281 -0
- package/dist/es/EventBus.mjs +64 -0
- package/dist/es/Logger.mjs +31 -0
- package/dist/es/PayloadTypes.mjs +4 -0
- package/dist/es/Session.mjs +527 -0
- package/dist/es/_virtual/_commonjsHelpers.mjs +4 -0
- package/dist/es/_virtual/index.mjs +4 -0
- package/dist/es/_virtual/index2.mjs +4 -0
- package/dist/es/_virtual/index3.mjs +4 -0
- package/dist/es/_virtual/minio-zj.mjs +4 -0
- package/dist/es/api/fetchEventSource/fetch.mjs +112 -0
- package/dist/es/api/fetchEventSource/parse.mjs +97 -0
- package/dist/es/api/index.mjs +48 -0
- package/dist/es/index.mjs +11 -0
- package/dist/es/node_modules/@glodon-aiot/minio/dist/minio-zj.mjs +26485 -0
- package/dist/es/node_modules/@socket.io/component-emitter/lib/esm/index.mjs +54 -0
- package/dist/es/node_modules/base64-js/index.mjs +47 -0
- package/dist/es/node_modules/buffer/index.mjs +927 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/has-cors.mjs +9 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseqs.mjs +18 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseuri.mjs +24 -0
- package/dist/es/node_modules/engine.io-client/build/esm/contrib/yeast.mjs +19 -0
- package/dist/es/node_modules/engine.io-client/build/esm/globalThis.browser.mjs +4 -0
- package/dist/es/node_modules/engine.io-client/build/esm/socket.mjs +317 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transport.mjs +113 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/index.mjs +11 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/polling.mjs +273 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket-constructor.browser.mjs +8 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket.mjs +87 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/webtransport.mjs +52 -0
- package/dist/es/node_modules/engine.io-client/build/esm/transports/xmlhttprequest.browser.mjs +21 -0
- package/dist/es/node_modules/engine.io-client/build/esm/util.mjs +23 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/commons.mjs +21 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.mjs +14 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/decodePacket.browser.mjs +39 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/encodePacket.browser.mjs +28 -0
- package/dist/es/node_modules/engine.io-parser/build/esm/index.mjs +105 -0
- package/dist/es/node_modules/ieee754/index.mjs +28 -0
- package/dist/es/node_modules/js-base64/base64.mjs +31 -0
- package/dist/es/node_modules/socket.io-client/build/esm/contrib/backo2.mjs +26 -0
- package/dist/es/node_modules/socket.io-client/build/esm/index.mjs +25 -0
- package/dist/es/node_modules/socket.io-client/build/esm/manager.mjs +242 -0
- package/dist/es/node_modules/socket.io-client/build/esm/on.mjs +8 -0
- package/dist/es/node_modules/socket.io-client/build/esm/socket.mjs +608 -0
- package/dist/es/node_modules/socket.io-client/build/esm/url.mjs +19 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/binary.mjs +52 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/index.mjs +203 -0
- package/dist/es/node_modules/socket.io-parser/build/esm/is-binary.mjs +26 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/native.mjs +6 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/rng.mjs +10 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs +9 -0
- package/dist/es/node_modules/uuid/dist/esm-browser/v4.mjs +19 -0
- package/dist/es/packages/apis/dist/es/aecpilot/model.mjs +4 -0
- package/dist/es/packages/apis/dist/es/aecpilotui/index.mjs +8 -0
- package/dist/es/packages/apis/dist/es/agentcliui/index.mjs +8 -0
- package/dist/es/packages/apis/dist/es/base/index.mjs +154 -0
- package/dist/es/packages/apis/dist/es/cvforce/index.mjs +431 -0
- package/dist/es/packages/apis/dist/es/cvforce/model.mjs +5 -0
- package/dist/es/packages/apis/dist/es/node_modules/uuid/dist/esm-browser/native.mjs +1 -0
- package/dist/es/packages/apis/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs +3 -0
- package/dist/es/utils.mjs +11 -0
- package/dist/lib/index.js +126 -0
- package/dist/src/AgentPlugin.d.ts +17 -0
- package/dist/src/AgentSession.d.ts +8 -0
- package/dist/src/BotClient.d.ts +46 -0
- package/dist/src/Config.d.ts +32 -0
- package/dist/src/DialogSession.d.ts +21 -0
- package/dist/src/EventBus.d.ts +23 -0
- package/dist/src/Logger.d.ts +12 -0
- package/dist/src/PayloadTypes.d.ts +84 -0
- package/dist/src/Session.d.ts +155 -0
- package/dist/src/__ tests __/AgentClient.spec.d.ts +1 -0
- package/dist/src/__ tests __/AgentSession.spec.d.ts +1 -0
- package/dist/src/__ tests __/DialogClient.spec.d.ts +1 -0
- package/dist/src/api/fetchEventSource/fetch.d.ts +44 -0
- package/dist/src/api/fetchEventSource/index.d.ts +1 -0
- package/dist/src/api/fetchEventSource/parse.d.ts +36 -0
- package/dist/src/api/index.d.ts +2 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/utils.d.ts +4 -0
- package/package.json +102 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
var C = Object.defineProperty, E = Object.defineProperties;
|
|
2
|
+
var S = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var R = Object.getOwnPropertySymbols;
|
|
4
|
+
var b = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var A = (a, t, i) => t in a ? C(a, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : a[t] = i, l = (a, t) => {
|
|
6
|
+
for (var i in t || (t = {}))
|
|
7
|
+
b.call(t, i) && A(a, i, t[i]);
|
|
8
|
+
if (R)
|
|
9
|
+
for (var i of R(t))
|
|
10
|
+
x.call(t, i) && A(a, i, t[i]);
|
|
11
|
+
return a;
|
|
12
|
+
}, y = (a, t) => E(a, S(t));
|
|
13
|
+
var p = (a, t, i) => new Promise((h, n) => {
|
|
14
|
+
var s = (c) => {
|
|
15
|
+
try {
|
|
16
|
+
r(i.next(c));
|
|
17
|
+
} catch (m) {
|
|
18
|
+
n(m);
|
|
19
|
+
}
|
|
20
|
+
}, e = (c) => {
|
|
21
|
+
try {
|
|
22
|
+
r(i.throw(c));
|
|
23
|
+
} catch (m) {
|
|
24
|
+
n(m);
|
|
25
|
+
}
|
|
26
|
+
}, r = (c) => c.done ? h(c.value) : Promise.resolve(c.value).then(s, e);
|
|
27
|
+
r((i = i.apply(a, t)).next());
|
|
28
|
+
});
|
|
29
|
+
import "axios";
|
|
30
|
+
import "./node_modules/@glodon-aiot/minio/dist/minio-zj.mjs";
|
|
31
|
+
import "dayjs";
|
|
32
|
+
import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/native.mjs";
|
|
33
|
+
import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs";
|
|
34
|
+
import "./packages/apis/dist/es/agentcliui/index.mjs";
|
|
35
|
+
import "./packages/apis/dist/es/aecpilotui/index.mjs";
|
|
36
|
+
import { ChatMessageRole as k } from "./packages/apis/dist/es/cvforce/model.mjs";
|
|
37
|
+
import L from "./Logger.mjs";
|
|
38
|
+
import { configuration as w } from "./Config.mjs";
|
|
39
|
+
import { io as U } from "./node_modules/socket.io-client/build/esm/index.mjs";
|
|
40
|
+
import { UserMode as v } from "./PayloadTypes.mjs";
|
|
41
|
+
import q, { SessionErrors as I } from "./Session.mjs";
|
|
42
|
+
const u = new L("[AgentClient] ");
|
|
43
|
+
class j extends q {
|
|
44
|
+
constructor(t, i = "", h, n) {
|
|
45
|
+
super(t, i, h, n);
|
|
46
|
+
}
|
|
47
|
+
prepareConnection() {
|
|
48
|
+
return new Promise((t) => p(this, null, function* () {
|
|
49
|
+
this.socket && t(!0);
|
|
50
|
+
const i = {
|
|
51
|
+
version: "1.0",
|
|
52
|
+
stream: "false",
|
|
53
|
+
appId: this._applicationId,
|
|
54
|
+
sessionId: this._id,
|
|
55
|
+
Authorization: `${this.token}`,
|
|
56
|
+
userMode: w.debug ? v.Debug : v.Normal
|
|
57
|
+
}, h = new URL(w.apiRoot), n = yield U(h.origin, {
|
|
58
|
+
path: h.pathname.replace("api", "socketio") + "/copilot",
|
|
59
|
+
query: i,
|
|
60
|
+
transports: ["websocket"]
|
|
61
|
+
});
|
|
62
|
+
n.on("connect", () => {
|
|
63
|
+
u.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
|
|
64
|
+
}), n.on("disconnect", () => {
|
|
65
|
+
u.log("socket:disconnect"), this.event.emit("socket:disconnect");
|
|
66
|
+
}), n.on("ready", (s) => {
|
|
67
|
+
if (s.code === 200) {
|
|
68
|
+
u.log("ready");
|
|
69
|
+
const e = w.debug ? v.Debug : v.Normal;
|
|
70
|
+
e === v.Debug && e !== s.userMode && console.warn(I.UserModeError), this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, t(!0);
|
|
71
|
+
} else {
|
|
72
|
+
this._ready && (this._ready = !1);
|
|
73
|
+
const e = new Error(
|
|
74
|
+
I.SocketConnectionFailed
|
|
75
|
+
// , {
|
|
76
|
+
// cause: data,
|
|
77
|
+
// }
|
|
78
|
+
);
|
|
79
|
+
u.error("error", e), this.event.emit("error", e), t(!1);
|
|
80
|
+
}
|
|
81
|
+
}), n.on("action", (s, e) => p(this, null, function* () {
|
|
82
|
+
if (this._stopAnswer || !this._id)
|
|
83
|
+
return;
|
|
84
|
+
const {
|
|
85
|
+
type: r,
|
|
86
|
+
data: {
|
|
87
|
+
runnerIsClient: c,
|
|
88
|
+
pluginCode: m,
|
|
89
|
+
funcCode: g,
|
|
90
|
+
parameters: o,
|
|
91
|
+
requestBody: N
|
|
92
|
+
}
|
|
93
|
+
} = s, d = this.messages[this.messages.length - 1];
|
|
94
|
+
if (!d.messageId)
|
|
95
|
+
d.actions || (d.actions = []), d.actions[s.data.step - 1] || (d.actions[s.data.step - 1] = []), d.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
|
|
96
|
+
messageId: d.messageId,
|
|
97
|
+
action: s
|
|
98
|
+
}), this.event.emit("message:updated", d);
|
|
99
|
+
else {
|
|
100
|
+
const f = {
|
|
101
|
+
messageId: "",
|
|
102
|
+
content: "",
|
|
103
|
+
role: k.Robot,
|
|
104
|
+
sessionId: this._id,
|
|
105
|
+
reference: [],
|
|
106
|
+
searchReference: [],
|
|
107
|
+
isLoading: !0,
|
|
108
|
+
messageTime: "",
|
|
109
|
+
actions: [[s]]
|
|
110
|
+
};
|
|
111
|
+
this.pushMessage(f), this.event.emit("message:action", {
|
|
112
|
+
messageId: f.messageId,
|
|
113
|
+
action: s
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (this.inactivating) {
|
|
117
|
+
const f = new Error(
|
|
118
|
+
I.Inactive
|
|
119
|
+
// {
|
|
120
|
+
// cause: {
|
|
121
|
+
// code: -1,
|
|
122
|
+
// message:
|
|
123
|
+
// 'session is inactive, skipping plugin client function call',
|
|
124
|
+
// },
|
|
125
|
+
// }
|
|
126
|
+
);
|
|
127
|
+
u.warn("error", f), this.event.emit("error", f);
|
|
128
|
+
} else if (r === "FUNCTION_CALL" && c) {
|
|
129
|
+
if (u.log(`calling function ${g} of plugin ${m} with argument:
|
|
130
|
+
${JSON.stringify(o)}`), !w.plugins[m]) {
|
|
131
|
+
e({
|
|
132
|
+
code: 404,
|
|
133
|
+
message: "对不起,没有找到插件。"
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const f = w.plugins[m].functions[g];
|
|
138
|
+
typeof f != "function" && e({
|
|
139
|
+
code: 404,
|
|
140
|
+
message: "对不起,没有找到插件方法。"
|
|
141
|
+
});
|
|
142
|
+
let _ = o == null ? void 0 : o.query;
|
|
143
|
+
try {
|
|
144
|
+
_ = JSON.parse(o == null ? void 0 : o.query);
|
|
145
|
+
} catch (M) {
|
|
146
|
+
}
|
|
147
|
+
f(_, (...M) => {
|
|
148
|
+
this._stopAnswer || e(...M);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
})), n.on("answer", (s) => {
|
|
152
|
+
if (!this._stopAnswer)
|
|
153
|
+
if (s.data.code !== 200 && (s.data.index = -1, this.event.emit("error", s.data)), s.data.index === -1) {
|
|
154
|
+
let e = this.messages[this.messages.length - 1];
|
|
155
|
+
if (e && !e.messageId)
|
|
156
|
+
e = l(l({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", e);
|
|
157
|
+
else {
|
|
158
|
+
const r = l({
|
|
159
|
+
messageId: "",
|
|
160
|
+
content: "",
|
|
161
|
+
role: k.Robot,
|
|
162
|
+
sessionId: this._id,
|
|
163
|
+
reference: [],
|
|
164
|
+
searchReference: [],
|
|
165
|
+
isLoading: !1,
|
|
166
|
+
messageTime: "",
|
|
167
|
+
actions: []
|
|
168
|
+
}, s.data);
|
|
169
|
+
this.event.emit("message:content", r), this.pushMessage(r), this.event.emit("answer:finish", r);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
let e = this.messages[this.messages.length - 1];
|
|
173
|
+
e && !e.messageId ? (e = l(l({}, e), s.data), this.messages[this.messages.length - 1] = e, this.event.emit("message:content", e), this.event.emit("message:updated", e)) : (this.pushMessage(s.data), this.event.emit("message:content", s.data));
|
|
174
|
+
}
|
|
175
|
+
}), n.on("reference", (s) => p(this, null, function* () {
|
|
176
|
+
if (this._stopAnswer)
|
|
177
|
+
return;
|
|
178
|
+
if (!this._id) {
|
|
179
|
+
const o = new Error(
|
|
180
|
+
I.IdUndefined
|
|
181
|
+
// {
|
|
182
|
+
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
183
|
+
// }
|
|
184
|
+
);
|
|
185
|
+
u.error(o), this.event.emit("error", o), this.frozen = !1;
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const {
|
|
189
|
+
type: e,
|
|
190
|
+
data: r,
|
|
191
|
+
requestId: c
|
|
192
|
+
} = s, m = this.messages.findIndex((o) => o.messageId === c && o.role === k.User);
|
|
193
|
+
if (m < 0)
|
|
194
|
+
return;
|
|
195
|
+
const g = m + 1;
|
|
196
|
+
if (g >= this.messages.length) {
|
|
197
|
+
const o = {
|
|
198
|
+
messageId: "",
|
|
199
|
+
content: "",
|
|
200
|
+
role: k.Robot,
|
|
201
|
+
sessionId: this._id,
|
|
202
|
+
reference: [],
|
|
203
|
+
searchReference: [],
|
|
204
|
+
isLoading: !0,
|
|
205
|
+
messageTime: "",
|
|
206
|
+
actions: []
|
|
207
|
+
};
|
|
208
|
+
this.pushMessage(o);
|
|
209
|
+
}
|
|
210
|
+
e === "KG" ? (this.messages[g] = y(l({}, this.messages[g]), {
|
|
211
|
+
reference: r.knowledgeReference
|
|
212
|
+
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", r.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : e === "WEB_SEARCH" && (this.messages[g] = y(l({}, this.messages[g]), {
|
|
213
|
+
searchReference: r.knowledgeReference
|
|
214
|
+
}), this.event.emit("message:searchreference", r.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
215
|
+
})), this.socket = n, n.open();
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
sendQuestion(t, i) {
|
|
219
|
+
return p(this, null, function* () {
|
|
220
|
+
var h, n;
|
|
221
|
+
if (!this.active) {
|
|
222
|
+
if (yield this.activate(), !this.socket) {
|
|
223
|
+
const s = new Error(
|
|
224
|
+
I.SocketConnectionFailed
|
|
225
|
+
// {
|
|
226
|
+
// cause: { code: -1, message: 'socket is null' },
|
|
227
|
+
// }
|
|
228
|
+
);
|
|
229
|
+
return u.warn("error", s), this.event.emit("error", s), !1;
|
|
230
|
+
}
|
|
231
|
+
(h = this.socket) == null || h.emit("question", t);
|
|
232
|
+
}
|
|
233
|
+
(n = this.socket) == null || n.emit("question", t);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
stopAnswer() {
|
|
237
|
+
var t;
|
|
238
|
+
(t = this.socket) == null || t.emit("stop_answer");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
export {
|
|
242
|
+
j as default
|
|
243
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var y = (c, i, t) => i in c ? u(c, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[i] = t;
|
|
3
|
+
var a = (c, i, t) => (y(c, typeof i != "symbol" ? i + "" : i, t), t);
|
|
4
|
+
var r = (c, i, t) => new Promise((e, s) => {
|
|
5
|
+
var h = (n) => {
|
|
6
|
+
try {
|
|
7
|
+
o(t.next(n));
|
|
8
|
+
} catch (l) {
|
|
9
|
+
s(l);
|
|
10
|
+
}
|
|
11
|
+
}, p = (n) => {
|
|
12
|
+
try {
|
|
13
|
+
o(t.throw(n));
|
|
14
|
+
} catch (l) {
|
|
15
|
+
s(l);
|
|
16
|
+
}
|
|
17
|
+
}, o = (n) => n.done ? e(n.value) : Promise.resolve(n.value).then(h, p);
|
|
18
|
+
o((t = t.apply(c, i)).next());
|
|
19
|
+
});
|
|
20
|
+
import { parseJWT as d } from "./utils.mjs";
|
|
21
|
+
import v from "./Logger.mjs";
|
|
22
|
+
import { getCVForceService as g } from "./api/index.mjs";
|
|
23
|
+
import { configure as m, configuration as f } from "./Config.mjs";
|
|
24
|
+
import "axios";
|
|
25
|
+
import "./node_modules/@glodon-aiot/minio/dist/minio-zj.mjs";
|
|
26
|
+
import "dayjs";
|
|
27
|
+
import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/native.mjs";
|
|
28
|
+
import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs";
|
|
29
|
+
import "./packages/apis/dist/es/agentcliui/index.mjs";
|
|
30
|
+
import "./packages/apis/dist/es/aecpilotui/index.mjs";
|
|
31
|
+
import { ApplicationTypes as _ } from "./packages/apis/dist/es/cvforce/model.mjs";
|
|
32
|
+
import S from "./AgentSession.mjs";
|
|
33
|
+
import w from "./DialogSession.mjs";
|
|
34
|
+
import k from "./EventBus.mjs";
|
|
35
|
+
const A = new v("[BotClient] ");
|
|
36
|
+
class F {
|
|
37
|
+
constructor(i, t, e = !0) {
|
|
38
|
+
a(this, "event", new k());
|
|
39
|
+
a(this, "cvforceApi");
|
|
40
|
+
//从token解析出来的用户信息
|
|
41
|
+
a(this, "_applicationId");
|
|
42
|
+
a(this, "_application", null);
|
|
43
|
+
//session列表,被加载过的session将会被缓存到这个列表中
|
|
44
|
+
a(this, "_sessions", []);
|
|
45
|
+
//活跃的session,只支持一个活跃的session
|
|
46
|
+
a(this, "_activeSession");
|
|
47
|
+
a(this, "_ready", !1);
|
|
48
|
+
//问题长度
|
|
49
|
+
a(this, "_questionContextMaxLength", 4e3);
|
|
50
|
+
a(this, "_promptVariables", []);
|
|
51
|
+
if (this._token = i, this.lazyload = e, m(t), this._applicationId = d(i).rid || f.applicationId, !this._applicationId)
|
|
52
|
+
throw "token is not vaild";
|
|
53
|
+
this.cvforceApi = this.getService(), this.loadApplication().then(() => {
|
|
54
|
+
this.event.emit("ready");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
checkReady() {
|
|
58
|
+
if (!this.ready)
|
|
59
|
+
throw Error("client is not ready.");
|
|
60
|
+
}
|
|
61
|
+
get ready() {
|
|
62
|
+
return this._ready;
|
|
63
|
+
}
|
|
64
|
+
set ready(i) {
|
|
65
|
+
this._ready = i;
|
|
66
|
+
}
|
|
67
|
+
get questionContextMaxLength() {
|
|
68
|
+
return this.checkReady(), this._questionContextMaxLength;
|
|
69
|
+
}
|
|
70
|
+
get promptVariables() {
|
|
71
|
+
return this.checkReady(), this._promptVariables;
|
|
72
|
+
}
|
|
73
|
+
get knowledges() {
|
|
74
|
+
var i;
|
|
75
|
+
return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
|
|
76
|
+
}
|
|
77
|
+
get sessions() {
|
|
78
|
+
return this.checkReady(), this._sessions;
|
|
79
|
+
}
|
|
80
|
+
set sessions(i) {
|
|
81
|
+
this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
|
|
82
|
+
}
|
|
83
|
+
loadApplication() {
|
|
84
|
+
return r(this, null, function* () {
|
|
85
|
+
var t, e;
|
|
86
|
+
this._application = yield this.cvforceApi.getApplicationId(this._applicationId);
|
|
87
|
+
const i = (e = (t = this._application.arrange) == null ? void 0 : t[0]) == null ? void 0 : e.llmModel;
|
|
88
|
+
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((s) => s.maxModelLength)), this._promptVariables = yield this.cvforceApi.getPrompts(this._applicationId), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
getService() {
|
|
92
|
+
return this.cvforceApi ? this.cvforceApi : g(f.apiRoot, this.token, (i, t) => A.error(t));
|
|
93
|
+
}
|
|
94
|
+
get token() {
|
|
95
|
+
return this._token;
|
|
96
|
+
}
|
|
97
|
+
set token(i) {
|
|
98
|
+
this.checkReady(), this._token = i, this.ready = !1;
|
|
99
|
+
const t = d(i).rid;
|
|
100
|
+
this._applicationId !== t && (this._applicationId = t, this._application = null, this.loadApplication().then(() => {
|
|
101
|
+
this.event.emit("ready");
|
|
102
|
+
}), this.clean());
|
|
103
|
+
}
|
|
104
|
+
get applicationId() {
|
|
105
|
+
return this._applicationId;
|
|
106
|
+
}
|
|
107
|
+
get application() {
|
|
108
|
+
return this.checkReady(), this._application;
|
|
109
|
+
}
|
|
110
|
+
get activeSession() {
|
|
111
|
+
var i;
|
|
112
|
+
return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
|
|
113
|
+
}
|
|
114
|
+
set activeSession(i) {
|
|
115
|
+
this.checkReady(), this.loadSession(i).then((t) => {
|
|
116
|
+
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = t;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
createSession(i, t, e, s) {
|
|
120
|
+
return r(this, null, function* () {
|
|
121
|
+
return new Promise((h, p) => {
|
|
122
|
+
const o = (n) => r(this, null, function* () {
|
|
123
|
+
if (n === _.Agent)
|
|
124
|
+
h(new S(i, t, e, s));
|
|
125
|
+
else if (n === _.Dialog)
|
|
126
|
+
h(new w(i, t, e, s));
|
|
127
|
+
else
|
|
128
|
+
throw Error(`不支持的应用类型:${n}`);
|
|
129
|
+
});
|
|
130
|
+
if (this.ready) {
|
|
131
|
+
if (!this._application)
|
|
132
|
+
throw Error("client is not ready");
|
|
133
|
+
o(this._application.type);
|
|
134
|
+
} else
|
|
135
|
+
this.event.on("ready", () => {
|
|
136
|
+
if (!this._application)
|
|
137
|
+
throw Error("_application is null");
|
|
138
|
+
o(this._application.type);
|
|
139
|
+
}, !0);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
getSessions(i) {
|
|
144
|
+
return r(this, null, function* () {
|
|
145
|
+
return new Promise((t, e) => {
|
|
146
|
+
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((h) => {
|
|
147
|
+
const p = [];
|
|
148
|
+
return h.forEach((o) => r(this, null, function* () {
|
|
149
|
+
const n = this._sessions.find((l) => o.id === l.id);
|
|
150
|
+
if (n)
|
|
151
|
+
n.data = o, p.push(n);
|
|
152
|
+
else {
|
|
153
|
+
const l = yield this.createSession(this.token, o.id, o, this.lazyload);
|
|
154
|
+
p.push(l);
|
|
155
|
+
}
|
|
156
|
+
})), this.sessions = p, p;
|
|
157
|
+
});
|
|
158
|
+
if (this.ready) {
|
|
159
|
+
if (!this._application)
|
|
160
|
+
throw Error("_application is null");
|
|
161
|
+
t(s());
|
|
162
|
+
} else
|
|
163
|
+
this.event.on("ready", () => {
|
|
164
|
+
if (!this._application)
|
|
165
|
+
throw Error("_application is null");
|
|
166
|
+
t(s());
|
|
167
|
+
}, !0);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
loadSession(i = "", t) {
|
|
172
|
+
return r(this, null, function* () {
|
|
173
|
+
this.checkReady();
|
|
174
|
+
let e = this.sessions.find((s) => s.id === i);
|
|
175
|
+
if (e || (e = yield this.createSession(this.token, i, t)), this._activeSession) {
|
|
176
|
+
if (this._activeSession === e)
|
|
177
|
+
return e;
|
|
178
|
+
this._activeSession.inactivate();
|
|
179
|
+
}
|
|
180
|
+
return e.id ? (e.activate(), this._activeSession = e) : e.addEventListener("data:loaded", () => {
|
|
181
|
+
e == null || e.activate(), this._activeSession = e;
|
|
182
|
+
}), e;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
reload() {
|
|
186
|
+
return this.loadApplication().then(() => {
|
|
187
|
+
this.event.emit("ready");
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
reloadSession(i) {
|
|
191
|
+
return r(this, null, function* () {
|
|
192
|
+
yield this.reload();
|
|
193
|
+
let t = i ? this._sessions.find((e) => e.id === i) : this._activeSession;
|
|
194
|
+
if (!t) {
|
|
195
|
+
console.warn("reloadSession session failed.");
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
return yield t.reload(), t;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
setTop(i, t, e = "top_time desc, sort_status desc, updated_at desc") {
|
|
202
|
+
return r(this, null, function* () {
|
|
203
|
+
let s = i ? this._sessions.find((h) => h.id === i) : this._activeSession;
|
|
204
|
+
if (!s) {
|
|
205
|
+
console.warn("setTop session failed.");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
return yield s.setTop(t), this.getSessions({
|
|
209
|
+
order: e
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
addEventListener(i, t, e = !1) {
|
|
214
|
+
if (typeof t != "function")
|
|
215
|
+
throw Error("event listener is not a function");
|
|
216
|
+
if (e) {
|
|
217
|
+
this.event.once(i, t);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.event.on(i, t);
|
|
221
|
+
}
|
|
222
|
+
removeEventListener(i, t) {
|
|
223
|
+
this.event.off(i, t);
|
|
224
|
+
}
|
|
225
|
+
removeSession(i, t) {
|
|
226
|
+
return r(this, null, function* () {
|
|
227
|
+
this.checkReady();
|
|
228
|
+
let e = -1;
|
|
229
|
+
if (typeof i == "string" ? e = this._sessions.findIndex((s) => s.id === i) : e = this._sessions.findIndex((s) => s === i), e > -1) {
|
|
230
|
+
const s = this._sessions[e];
|
|
231
|
+
t && (yield s.delete()), this._sessions.splice(e, 1);
|
|
232
|
+
} else
|
|
233
|
+
console.warn("session delete failed, session is not exist.");
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
clean() {
|
|
237
|
+
this._sessions.forEach((i) => i.destroy()), this.sessions = [];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
export {
|
|
241
|
+
F as default
|
|
242
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var v = Object.defineProperty, s = Object.defineProperties;
|
|
2
|
+
var u = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var n = Object.getOwnPropertySymbols;
|
|
4
|
+
var p = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var d = (o, t, e) => t in o ? v(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, i = (o, t) => {
|
|
6
|
+
for (var e in t || (t = {}))
|
|
7
|
+
p.call(t, e) && d(o, e, t[e]);
|
|
8
|
+
if (n)
|
|
9
|
+
for (var e of n(t))
|
|
10
|
+
h.call(t, e) && d(o, e, t[e]);
|
|
11
|
+
return o;
|
|
12
|
+
}, g = (o, t) => s(o, u(t));
|
|
13
|
+
import l from "./Logger.mjs";
|
|
14
|
+
const R = new l("[Config] ");
|
|
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 || {});
|
|
16
|
+
let c = {
|
|
17
|
+
debug: !1,
|
|
18
|
+
env: "prod",
|
|
19
|
+
//AIoT 环境, 与apiRoot配对使用
|
|
20
|
+
apiRoot: "https://copilot.glodon.com/api/cvforce",
|
|
21
|
+
//https://${hostname}/${PRODUCD_CODE}
|
|
22
|
+
applicationId: "",
|
|
23
|
+
plugins: {}
|
|
24
|
+
};
|
|
25
|
+
function x(o) {
|
|
26
|
+
console.log("configure", o), l.debug = (o == null ? void 0 : o.debug) || !1, c = g(i(i({}, c), o), {
|
|
27
|
+
apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
|
|
28
|
+
}), R.log("updated", c);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
f as ApiUrl,
|
|
32
|
+
c as configuration,
|
|
33
|
+
x as configure
|
|
34
|
+
};
|