@glodon-aiot/agent-cli-sdk 3.1.0-beta.16 → 3.2.2-beta.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.
- package/dist/agent-cli-sdk.js +33145 -0
- package/dist/agent-cli-sdk.umd.cjs +140 -0
- package/dist/src/AgentSession.d.ts +2 -2
- package/dist/src/BotClient.d.ts +2 -2
- package/dist/src/Config.d.ts +2 -0
- package/dist/src/DialogSession.d.ts +2 -2
- package/dist/src/Session.d.ts +11 -9
- 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 +1 -1
- package/dist/src/api/fetchEventSource/index.d.ts +1 -1
- package/package.json +20 -16
- package/dist/es/AgentPlugin.mjs +0 -20
- package/dist/es/AgentSession.mjs +0 -246
- package/dist/es/BotClient.mjs +0 -236
- package/dist/es/Config.mjs +0 -34
- package/dist/es/DialogSession.mjs +0 -274
- package/dist/es/EventBus.mjs +0 -64
- package/dist/es/Logger.mjs +0 -31
- package/dist/es/PayloadTypes.mjs +0 -4
- package/dist/es/Session.mjs +0 -690
- package/dist/es/api/fetchEventSource/fetch.mjs +0 -112
- package/dist/es/api/fetchEventSource/parse.mjs +0 -97
- package/dist/es/api/index.mjs +0 -41
- package/dist/es/index.mjs +0 -11
- package/dist/es/utils.mjs +0 -11
- package/dist/lib/index.js +0 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IApplication, ISession } from '@glodon-aiot/apis';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import Session, { QuestionBody, QuestionConfig } from './Session';
|
|
3
|
+
import BotClient from './BotClient';
|
|
4
4
|
export default class AgentSession extends Session {
|
|
5
5
|
constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
|
|
6
6
|
prepareConnection(): Promise<boolean>;
|
package/dist/src/BotClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Session from './Session';
|
|
2
2
|
import { BotClientConfig } from './Config';
|
|
3
3
|
import { IApplication, IPrompt, ISession, ISessionPrompt, SessionQueryParams } from '@glodon-aiot/apis';
|
|
4
|
-
import
|
|
4
|
+
import EventBus from './EventBus';
|
|
5
5
|
export type ClientEventName = 'ready' | 'application:loaded';
|
|
6
6
|
export default class BotClient {
|
|
7
7
|
private _token;
|
package/dist/src/Config.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface BotClientConfig {
|
|
|
4
4
|
applicationId?: string;
|
|
5
5
|
plugins?: AgentPluginMap;
|
|
6
6
|
apiRoot?: string;
|
|
7
|
+
loadRelatedQuesions?: boolean;
|
|
7
8
|
}
|
|
8
9
|
export interface AgentPluginRegistor {
|
|
9
10
|
[key: string]: Function;
|
|
@@ -24,6 +25,7 @@ export declare let configuration: {
|
|
|
24
25
|
apiRoot: string;
|
|
25
26
|
applicationId: string;
|
|
26
27
|
plugins: AgentPluginMap;
|
|
28
|
+
loadRelatedQuesions: boolean;
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
29
31
|
* 配置SDK,可以在SDK被使用前被调用,该方法被调用后将改变是否debug模式、是否测试环境等基本配置
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IApplication, ISession } from '@glodon-aiot/apis';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import Session, { QuestionBody, QuestionConfig } from './Session';
|
|
3
|
+
import BotClient from './BotClient';
|
|
4
4
|
export default class DialogSession extends Session {
|
|
5
5
|
private ctrl;
|
|
6
6
|
constructor(token: string, _id?: string, _data?: Partial<ISession>, lazyload?: boolean, application?: IApplication, client?: BotClient);
|
package/dist/src/Session.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ChatMessageRole, IApplication, IChatMessage, ICommentParam, ISession, ISessionPrompt
|
|
1
|
+
import { ChatMessageRole, IApplication, IChatMessage, ICommentParam, ISession, ISessionPrompt } from '@glodon-aiot/apis';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
|
-
import
|
|
3
|
+
import EventBus from './EventBus';
|
|
4
4
|
import { ActionPayload, PluginFunctionBasic, Thought } from './PayloadTypes';
|
|
5
|
-
import {
|
|
5
|
+
import { CVForceApi } from '@glodon-aiot/apis';
|
|
6
|
+
import { ChatHistoryParams, IKnowledge } from '@glodon-aiot/apis';
|
|
7
|
+
import BotClient from './BotClient';
|
|
6
8
|
export declare enum NetOpen {
|
|
7
9
|
enable = 1,
|
|
8
10
|
disable = 2
|
|
@@ -118,15 +120,15 @@ export default abstract class Session {
|
|
|
118
120
|
role: ChatMessageRole;
|
|
119
121
|
userId?: string | undefined;
|
|
120
122
|
sessionId: string;
|
|
121
|
-
reference: import(
|
|
122
|
-
searchReference: import(
|
|
123
|
-
comment?: import(
|
|
123
|
+
reference: import("@glodon-aiot/apis").IReference[];
|
|
124
|
+
searchReference: import("@glodon-aiot/apis").ISearchRefernce[];
|
|
125
|
+
comment?: import("@glodon-aiot/apis/dist/src/cvforce").ICommentParam | undefined;
|
|
124
126
|
knowledges?: IKnowledge[] | undefined;
|
|
125
127
|
isLoading?: boolean | undefined;
|
|
126
128
|
messageTime: string;
|
|
127
129
|
fileId?: string | undefined;
|
|
128
|
-
file?: import(
|
|
129
|
-
chatMode?: import(
|
|
130
|
+
file?: import("@glodon-aiot/apis/dist/src/cvforce").KnowledgeFileMetadata | undefined;
|
|
131
|
+
chatMode?: import("@glodon-aiot/apis").ChatMode | undefined;
|
|
130
132
|
llmModel?: string | undefined;
|
|
131
133
|
isContext?: boolean | undefined;
|
|
132
134
|
index?: number | undefined;
|
|
@@ -145,7 +147,7 @@ export default abstract class Session {
|
|
|
145
147
|
stream?: boolean | undefined;
|
|
146
148
|
fileIds?: string[] | undefined;
|
|
147
149
|
isReplying?: boolean | undefined;
|
|
148
|
-
files?: import(
|
|
150
|
+
files?: import("@glodon-aiot/apis").ChatMessageFile[] | undefined;
|
|
149
151
|
thinkingSecs?: number | undefined;
|
|
150
152
|
thinkingStatus?: "end" | "start" | undefined;
|
|
151
153
|
reasoningContent?: string | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./fetch";
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glodon-aiot/agent-cli-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.2-beta.0",
|
|
4
4
|
"author": "glodoncv",
|
|
5
5
|
"description": "aiot agent client js sdk",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"sideEffects": false,
|
|
8
7
|
"keywords": [
|
|
9
8
|
"aiot",
|
|
10
9
|
"agent",
|
|
@@ -14,15 +13,13 @@
|
|
|
14
13
|
"files": [
|
|
15
14
|
"dist"
|
|
16
15
|
],
|
|
17
|
-
"module": "./dist/
|
|
18
|
-
"main": "./dist/
|
|
16
|
+
"module": "./dist/agent-cli-sdk.js",
|
|
17
|
+
"main": "./dist/agent-cli-sdk.umd.cjs",
|
|
19
18
|
"typings": "./dist/src/index.d.ts",
|
|
20
19
|
"exports": {
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"types": "./dist/src/index.d.ts"
|
|
25
|
-
}
|
|
20
|
+
"import": "./dist/agent-cli-sdk.js",
|
|
21
|
+
"require": "./dist/agent-cli-sdk.umd.cjs",
|
|
22
|
+
"types": "./dist/src/index.d.ts"
|
|
26
23
|
},
|
|
27
24
|
"license": "MIT",
|
|
28
25
|
"scripts": {
|
|
@@ -30,22 +27,26 @@
|
|
|
30
27
|
"example": "node ./example/server.js",
|
|
31
28
|
"dev": "npm-run-all -p watch example",
|
|
32
29
|
"start": "vite",
|
|
33
|
-
"build": "tsc && vite build --mode prod
|
|
30
|
+
"build": "tsc && vite build --mode prod",
|
|
34
31
|
"build:npm": "tsc && vite build --mode prod",
|
|
35
32
|
"build:cdn": "tsc && vite build --mode prod --config ./vite.config.cdn.ts",
|
|
36
33
|
"preview": "vite preview",
|
|
37
34
|
"check": "yarn prettier --check .",
|
|
38
35
|
"write": "yarn prettier --write .",
|
|
39
|
-
"lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js"
|
|
36
|
+
"lint": "eslint --ext .tsx,.ts --fix ./example -c .eslintrc.js",
|
|
37
|
+
"test": "yarn dev && yarn jest"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
42
40
|
"@babel/core": "^7.20.12",
|
|
43
41
|
"@commitlint/cli": "^17.0.3",
|
|
44
42
|
"@commitlint/config-conventional": "^17.0.3",
|
|
45
|
-
"@
|
|
43
|
+
"@jest/globals": "^29.7.0",
|
|
46
44
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
45
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
47
46
|
"@types/express": "^4",
|
|
48
47
|
"@types/identity-obj-proxy": "^3",
|
|
48
|
+
"@types/jest": "^29.5.14",
|
|
49
|
+
"@types/uuid": "^9",
|
|
49
50
|
"@typescript-eslint/eslint-plugin": "^5.35.1",
|
|
50
51
|
"@typescript-eslint/parser": "^5.35.1",
|
|
51
52
|
"babel-loader": "^8.3.0",
|
|
@@ -60,14 +61,16 @@
|
|
|
60
61
|
"express": "4",
|
|
61
62
|
"http-proxy-middleware": "^3.0.0",
|
|
62
63
|
"identity-obj-proxy": "^3.0.0",
|
|
64
|
+
"jest": "^29.7.0",
|
|
65
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
66
|
+
"jest-transform-stub": "^2.0.0",
|
|
63
67
|
"npm-run-all": "^4.1.5",
|
|
64
68
|
"prettier": "2.7.1",
|
|
65
69
|
"socket.io": "^4.7.5",
|
|
70
|
+
"ts-jest": "^29.2.5",
|
|
66
71
|
"ts-node": "^10.9.2",
|
|
67
72
|
"typescript": "*",
|
|
68
73
|
"vite": "^4.1.1",
|
|
69
|
-
"vite-plugin-dts": "^4.3.0",
|
|
70
|
-
"vite-plugin-externalize-deps": "^0.9.0",
|
|
71
74
|
"vite-tsconfig-paths": "^5.1.4"
|
|
72
75
|
},
|
|
73
76
|
"lint-staged": {
|
|
@@ -78,12 +81,13 @@
|
|
|
78
81
|
"registry": "https://registry.npmjs.org/"
|
|
79
82
|
},
|
|
80
83
|
"dependencies": {
|
|
81
|
-
"@glodon-aiot/apis": "^3.
|
|
84
|
+
"@glodon-aiot/apis": "^3.2.2-beta.0",
|
|
82
85
|
"axios": "0.24.0",
|
|
83
86
|
"buffer": "^6.0.3",
|
|
84
87
|
"dayjs": "^1.11.13",
|
|
85
88
|
"js-base64": "^3.7.7",
|
|
86
89
|
"socket.io-client": "^4.7.5",
|
|
87
|
-
"uuid": "^
|
|
90
|
+
"uuid": "^9.0.1",
|
|
91
|
+
"vite-plugin-dts": "^4.3.0"
|
|
88
92
|
}
|
|
89
93
|
}
|
package/dist/es/AgentPlugin.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var c = Object.defineProperty;
|
|
2
|
-
var a = (e, t, i) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
|
|
3
|
-
var s = (e, t, i) => (a(e, typeof t != "symbol" ? t + "" : t, i), i);
|
|
4
|
-
class d {
|
|
5
|
-
constructor(t, i = {}, o) {
|
|
6
|
-
s(this, "code");
|
|
7
|
-
s(this, "description", "");
|
|
8
|
-
s(this, "loaded", !1);
|
|
9
|
-
s(this, "functions", {});
|
|
10
|
-
this.code = t, i && (this.functions = i);
|
|
11
|
-
}
|
|
12
|
-
fetchData() {
|
|
13
|
-
this.description = "描述", this.loaded = !0;
|
|
14
|
-
}
|
|
15
|
-
checkFunctions() {
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export {
|
|
19
|
-
d as default
|
|
20
|
-
};
|
package/dist/es/AgentSession.mjs
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
var C = Object.defineProperty, S = Object.defineProperties;
|
|
2
|
-
var b = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var A = Object.getOwnPropertySymbols;
|
|
4
|
-
var x = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var _ = (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
|
-
x.call(t, i) && _(a, i, t[i]);
|
|
8
|
-
if (A)
|
|
9
|
-
for (var i of A(t))
|
|
10
|
-
E.call(t, i) && _(a, i, t[i]);
|
|
11
|
-
return a;
|
|
12
|
-
}, k = (a, t) => S(a, b(t));
|
|
13
|
-
var p = (a, t, i) => new Promise((m, n) => {
|
|
14
|
-
var s = (c) => {
|
|
15
|
-
try {
|
|
16
|
-
r(i.next(c));
|
|
17
|
-
} catch (h) {
|
|
18
|
-
n(h);
|
|
19
|
-
}
|
|
20
|
-
}, e = (c) => {
|
|
21
|
-
try {
|
|
22
|
-
r(i.throw(c));
|
|
23
|
-
} catch (h) {
|
|
24
|
-
n(h);
|
|
25
|
-
}
|
|
26
|
-
}, r = (c) => c.done ? m(c.value) : Promise.resolve(c.value).then(s, e);
|
|
27
|
-
r((i = i.apply(a, t)).next());
|
|
28
|
-
});
|
|
29
|
-
import { ChatMessageRole as I } from "@glodon-aiot/apis";
|
|
30
|
-
import L from "./Logger.mjs";
|
|
31
|
-
import { configuration as w } from "./Config.mjs";
|
|
32
|
-
import { io as q } from "socket.io-client";
|
|
33
|
-
import { UserMode as v } from "./PayloadTypes.mjs";
|
|
34
|
-
import N, { SessionErrors as y } from "./Session.mjs";
|
|
35
|
-
const u = new L("[AgentSession] ");
|
|
36
|
-
class J extends N {
|
|
37
|
-
constructor(t, i = "", m, n, s, e) {
|
|
38
|
-
super(t, i, m, n, s, e);
|
|
39
|
-
}
|
|
40
|
-
prepareConnection() {
|
|
41
|
-
return new Promise((t) => p(this, null, function* () {
|
|
42
|
-
this.socket && t(!0);
|
|
43
|
-
const i = {
|
|
44
|
-
version: "1.0",
|
|
45
|
-
stream: "false",
|
|
46
|
-
appId: this._applicationId,
|
|
47
|
-
sessionId: this.id,
|
|
48
|
-
Authorization: `${this.token}`,
|
|
49
|
-
userMode: w.debug ? v.Debug : v.Normal
|
|
50
|
-
}, m = new URL(w.apiRoot), n = yield q(m.origin, {
|
|
51
|
-
path: m.pathname.replace("api", "socketio") + "/copilot",
|
|
52
|
-
query: i,
|
|
53
|
-
transports: ["websocket"]
|
|
54
|
-
});
|
|
55
|
-
n.on("connect", () => {
|
|
56
|
-
u.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
|
|
57
|
-
}), n.on("disconnect", () => {
|
|
58
|
-
u.log("socket:disconnect"), this.event.emit("socket:disconnect");
|
|
59
|
-
}), n.on("ready", (s) => {
|
|
60
|
-
if (s.code === 200) {
|
|
61
|
-
u.log("ready");
|
|
62
|
-
const e = w.debug ? v.Debug : v.Normal;
|
|
63
|
-
e === v.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, t(!0);
|
|
64
|
-
} else {
|
|
65
|
-
this._ready && (this._ready = !1);
|
|
66
|
-
const e = new Error(
|
|
67
|
-
y.SocketConnectionFailed
|
|
68
|
-
// , {
|
|
69
|
-
// cause: data,
|
|
70
|
-
// }
|
|
71
|
-
);
|
|
72
|
-
u.error("error", e), this.event.emit("error", e), t(!1);
|
|
73
|
-
}
|
|
74
|
-
}), n.on("action", (s, e) => p(this, null, function* () {
|
|
75
|
-
if (this._stopAnswer || !this.id)
|
|
76
|
-
return;
|
|
77
|
-
const {
|
|
78
|
-
type: r,
|
|
79
|
-
data: {
|
|
80
|
-
runnerIsClient: c,
|
|
81
|
-
pluginCode: h,
|
|
82
|
-
funcCode: g,
|
|
83
|
-
parameters: o,
|
|
84
|
-
requestBody: U
|
|
85
|
-
}
|
|
86
|
-
} = s, d = this.messages[this.messages.length - 1];
|
|
87
|
-
if (!d.messageId)
|
|
88
|
-
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", {
|
|
89
|
-
messageId: d.messageId,
|
|
90
|
-
action: s
|
|
91
|
-
}), this.event.emit("message:updated", d);
|
|
92
|
-
else {
|
|
93
|
-
const f = {
|
|
94
|
-
messageId: "",
|
|
95
|
-
content: "",
|
|
96
|
-
role: I.Robot,
|
|
97
|
-
sessionId: this.id,
|
|
98
|
-
reference: [],
|
|
99
|
-
searchReference: [],
|
|
100
|
-
isLoading: !0,
|
|
101
|
-
messageTime: "",
|
|
102
|
-
actions: [[s]],
|
|
103
|
-
comment: {
|
|
104
|
-
isAgree: 0
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
this.pushMessage(f), this.event.emit("message:action", {
|
|
108
|
-
messageId: f.messageId,
|
|
109
|
-
action: s
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (this.inactivating) {
|
|
113
|
-
const f = new Error(
|
|
114
|
-
y.Inactive
|
|
115
|
-
// {
|
|
116
|
-
// cause: {
|
|
117
|
-
// code: -1,
|
|
118
|
-
// message:
|
|
119
|
-
// 'session is inactive, skipping plugin client function call',
|
|
120
|
-
// },
|
|
121
|
-
// }
|
|
122
|
-
);
|
|
123
|
-
u.warn("error", f), this.event.emit("error", f);
|
|
124
|
-
} else if (r === "FUNCTION_CALL" && c) {
|
|
125
|
-
if (u.log(`calling function ${g} of plugin ${h} with argument:
|
|
126
|
-
${JSON.stringify(o)}`), !w.plugins[h]) {
|
|
127
|
-
e({
|
|
128
|
-
code: 404,
|
|
129
|
-
message: "对不起,没有找到插件。"
|
|
130
|
-
});
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const f = w.plugins[h][g];
|
|
134
|
-
typeof f != "function" && e({
|
|
135
|
-
code: 404,
|
|
136
|
-
message: "对不起,没有找到插件方法。"
|
|
137
|
-
});
|
|
138
|
-
let M = o == null ? void 0 : o.query;
|
|
139
|
-
try {
|
|
140
|
-
M = JSON.parse(o == null ? void 0 : o.query);
|
|
141
|
-
} catch (R) {
|
|
142
|
-
}
|
|
143
|
-
f(M, (...R) => {
|
|
144
|
-
this._stopAnswer || e(...R);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
})), n.on("answer", (s) => {
|
|
148
|
-
if (!this._stopAnswer)
|
|
149
|
-
if (s.data.code !== 200 && (s.data.index = -1, this.event.emit("error", s.data)), s.data.index === -1) {
|
|
150
|
-
let e = this.messages[this.messages.length - 1];
|
|
151
|
-
if (e && !e.messageId)
|
|
152
|
-
e = l(l({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", e);
|
|
153
|
-
else {
|
|
154
|
-
const r = l({
|
|
155
|
-
messageId: "",
|
|
156
|
-
content: "",
|
|
157
|
-
role: I.Robot,
|
|
158
|
-
sessionId: this.id,
|
|
159
|
-
reference: [],
|
|
160
|
-
searchReference: [],
|
|
161
|
-
isLoading: !1,
|
|
162
|
-
messageTime: "",
|
|
163
|
-
actions: [],
|
|
164
|
-
comment: {
|
|
165
|
-
isAgree: 0
|
|
166
|
-
}
|
|
167
|
-
}, s.data);
|
|
168
|
-
this.event.emit("message:content", r), this.pushMessage(r), this.event.emit("answer:finish", r);
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
let e = this.messages[this.messages.length - 1];
|
|
172
|
-
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));
|
|
173
|
-
}
|
|
174
|
-
}), n.on("reference", (s) => p(this, null, function* () {
|
|
175
|
-
if (this._stopAnswer)
|
|
176
|
-
return;
|
|
177
|
-
if (!this.id) {
|
|
178
|
-
const o = new Error(
|
|
179
|
-
y.IdUndefined
|
|
180
|
-
// {
|
|
181
|
-
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
182
|
-
// }
|
|
183
|
-
);
|
|
184
|
-
u.error(o), this.event.emit("error", o), this.frozen = !1;
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const {
|
|
188
|
-
type: e,
|
|
189
|
-
data: r,
|
|
190
|
-
requestId: c
|
|
191
|
-
} = s, h = this.messages.findIndex((o) => o.messageId === c && o.role === I.User);
|
|
192
|
-
if (h < 0)
|
|
193
|
-
return;
|
|
194
|
-
const g = h + 1;
|
|
195
|
-
if (g >= this.messages.length) {
|
|
196
|
-
const o = {
|
|
197
|
-
messageId: "",
|
|
198
|
-
content: "",
|
|
199
|
-
role: I.Robot,
|
|
200
|
-
sessionId: this.id,
|
|
201
|
-
reference: [],
|
|
202
|
-
searchReference: [],
|
|
203
|
-
isLoading: !0,
|
|
204
|
-
messageTime: "",
|
|
205
|
-
actions: [],
|
|
206
|
-
comment: {
|
|
207
|
-
isAgree: 0
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
this.pushMessage(o);
|
|
211
|
-
}
|
|
212
|
-
e === "KG" ? (this.messages[g] = k(l({}, this.messages[g]), {
|
|
213
|
-
reference: r.knowledgeReference
|
|
214
|
-
}), 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] = k(l({}, this.messages[g]), {
|
|
215
|
-
searchReference: r.knowledgeReference
|
|
216
|
-
}), this.event.emit("message:searchreference", r.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
217
|
-
})), this.socket = n, n.open();
|
|
218
|
-
}));
|
|
219
|
-
}
|
|
220
|
-
sendQuestion(t, i) {
|
|
221
|
-
return p(this, null, function* () {
|
|
222
|
-
var m, n;
|
|
223
|
-
if (!this.active) {
|
|
224
|
-
if (yield this.activate(), !this.socket) {
|
|
225
|
-
const s = new Error(
|
|
226
|
-
y.SocketConnectionFailed
|
|
227
|
-
// {
|
|
228
|
-
// cause: { code: -1, message: 'socket is null' },
|
|
229
|
-
// }
|
|
230
|
-
);
|
|
231
|
-
return u.warn("error", s), this.event.emit("error", s), !1;
|
|
232
|
-
}
|
|
233
|
-
(m = this.socket) == null || m.emit("question", t);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
(n = this.socket) == null || n.emit("question", t);
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
stopAnswer() {
|
|
240
|
-
var t;
|
|
241
|
-
(t = this.socket) == null || t.emit("stop_answer");
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
export {
|
|
245
|
-
J as default
|
|
246
|
-
};
|