@glodon-aiot/agent-cli-sdk 3.0.11-beta.14 → 3.0.11-beta.16
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 +103 -97
- package/dist/es/Session.mjs +148 -158
- package/dist/lib/index.js +3 -3
- package/dist/src/Session.d.ts +1 -1
- package/package.json +2 -2
- package/dist/agent-cli-sdk.js +0 -33144
- package/dist/agent-cli-sdk.umd.cjs +0 -140
- package/dist/src/__ tests __/AgentClient.spec.d.ts +0 -1
- package/dist/src/__ tests __/AgentSession.spec.d.ts +0 -1
- package/dist/src/__ tests __/DialogClient.spec.d.ts +0 -1
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
var C = Object.defineProperty,
|
|
2
|
-
var
|
|
1
|
+
var C = Object.defineProperty, b = Object.defineProperties;
|
|
2
|
+
var S = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var A = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var _ = (
|
|
6
|
-
for (var
|
|
7
|
-
|
|
4
|
+
var q = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var _ = (c, t, n) => t in c ? C(c, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : c[t] = n, h = (c, t) => {
|
|
6
|
+
for (var n in t || (t = {}))
|
|
7
|
+
q.call(t, n) && _(c, n, t[n]);
|
|
8
8
|
if (A)
|
|
9
|
-
for (var
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var s = (
|
|
9
|
+
for (var n of A(t))
|
|
10
|
+
x.call(t, n) && _(c, n, t[n]);
|
|
11
|
+
return c;
|
|
12
|
+
}, p = (c, t) => b(c, S(t));
|
|
13
|
+
var w = (c, t, n) => new Promise((d, o) => {
|
|
14
|
+
var s = (a) => {
|
|
15
15
|
try {
|
|
16
|
-
|
|
17
|
-
} catch (
|
|
18
|
-
|
|
16
|
+
i(n.next(a));
|
|
17
|
+
} catch (m) {
|
|
18
|
+
o(m);
|
|
19
19
|
}
|
|
20
|
-
}, e = (
|
|
20
|
+
}, e = (a) => {
|
|
21
21
|
try {
|
|
22
|
-
|
|
23
|
-
} catch (
|
|
24
|
-
|
|
22
|
+
i(n.throw(a));
|
|
23
|
+
} catch (m) {
|
|
24
|
+
o(m);
|
|
25
25
|
}
|
|
26
|
-
},
|
|
27
|
-
|
|
26
|
+
}, i = (a) => a.done ? d(a.value) : Promise.resolve(a.value).then(s, e);
|
|
27
|
+
i((n = n.apply(c, t)).next());
|
|
28
28
|
});
|
|
29
|
-
import { ChatMessageRole as
|
|
30
|
-
import
|
|
31
|
-
import { configuration as
|
|
32
|
-
import { io as
|
|
33
|
-
import { UserMode as
|
|
29
|
+
import { ChatMessageRole as k } from "@glodon-aiot/apis";
|
|
30
|
+
import E from "./Logger.mjs";
|
|
31
|
+
import { configuration as v } from "./Config.mjs";
|
|
32
|
+
import { io as L } from "socket.io-client";
|
|
33
|
+
import { UserMode as I } from "./PayloadTypes.mjs";
|
|
34
34
|
import N, { SessionErrors as y } from "./Session.mjs";
|
|
35
|
-
const u = new
|
|
36
|
-
class
|
|
37
|
-
constructor(t,
|
|
38
|
-
super(t,
|
|
35
|
+
const u = new E("[AgentSession] ");
|
|
36
|
+
class B extends N {
|
|
37
|
+
constructor(t, n = "", d, o, s, e) {
|
|
38
|
+
super(t, n, d, o, s, e);
|
|
39
39
|
}
|
|
40
40
|
prepareConnection() {
|
|
41
|
-
return new Promise((t) =>
|
|
41
|
+
return new Promise((t) => w(this, null, function* () {
|
|
42
42
|
this.socket && t(!0);
|
|
43
|
-
const
|
|
43
|
+
const n = {
|
|
44
44
|
version: "1.0",
|
|
45
45
|
stream: "false",
|
|
46
46
|
appId: this._applicationId,
|
|
47
47
|
sessionId: this.id,
|
|
48
48
|
Authorization: `${this.token}`,
|
|
49
|
-
userMode:
|
|
50
|
-
},
|
|
51
|
-
path:
|
|
52
|
-
query:
|
|
49
|
+
userMode: v.debug ? I.Debug : I.Normal
|
|
50
|
+
}, d = new URL(v.apiRoot), o = yield L(d.origin, {
|
|
51
|
+
path: d.pathname.replace("api", "socketio") + "/copilot",
|
|
52
|
+
query: n,
|
|
53
53
|
transports: ["websocket"]
|
|
54
54
|
});
|
|
55
|
-
|
|
56
|
-
u.log("socket:connect"), this.event.emit("socket:connect"),
|
|
57
|
-
}),
|
|
55
|
+
o.on("connect", () => {
|
|
56
|
+
u.log("socket:connect"), this.event.emit("socket:connect"), o.emit("init");
|
|
57
|
+
}), o.on("disconnect", () => {
|
|
58
58
|
u.log("socket:disconnect"), this.event.emit("socket:disconnect");
|
|
59
|
-
}),
|
|
59
|
+
}), o.on("ready", (s) => {
|
|
60
60
|
if (s.code === 200) {
|
|
61
61
|
u.log("ready");
|
|
62
|
-
const e =
|
|
63
|
-
e ===
|
|
62
|
+
const e = v.debug ? I.Debug : I.Normal;
|
|
63
|
+
e === I.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, t(!0);
|
|
64
64
|
} else {
|
|
65
65
|
this._ready && (this._ready = !1);
|
|
66
66
|
const e = new Error(
|
|
@@ -71,29 +71,29 @@ class J extends N {
|
|
|
71
71
|
);
|
|
72
72
|
u.error("error", e), this.event.emit("error", e), t(!1);
|
|
73
73
|
}
|
|
74
|
-
}),
|
|
74
|
+
}), o.on("action", (s, e) => w(this, null, function* () {
|
|
75
75
|
if (this._stopAnswer || !this.id)
|
|
76
76
|
return;
|
|
77
77
|
const {
|
|
78
|
-
type:
|
|
78
|
+
type: i,
|
|
79
79
|
data: {
|
|
80
|
-
runnerIsClient:
|
|
81
|
-
pluginCode:
|
|
80
|
+
runnerIsClient: a,
|
|
81
|
+
pluginCode: m,
|
|
82
82
|
funcCode: g,
|
|
83
|
-
parameters:
|
|
83
|
+
parameters: r,
|
|
84
84
|
requestBody: U
|
|
85
85
|
}
|
|
86
|
-
} = s,
|
|
87
|
-
if (!
|
|
88
|
-
|
|
89
|
-
messageId:
|
|
86
|
+
} = s, f = this.messages[this.messages.length - 1];
|
|
87
|
+
if (!f.messageId)
|
|
88
|
+
f.actions || (f.actions = []), f.actions[s.data.step - 1] || (f.actions[s.data.step - 1] = []), f.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
|
|
89
|
+
messageId: f.messageId,
|
|
90
90
|
action: s
|
|
91
|
-
}), this.event.emit("message:updated",
|
|
91
|
+
}), this.event.emit("message:updated", f);
|
|
92
92
|
else {
|
|
93
|
-
const
|
|
93
|
+
const l = {
|
|
94
94
|
messageId: "",
|
|
95
95
|
content: "",
|
|
96
|
-
role:
|
|
96
|
+
role: k.Robot,
|
|
97
97
|
sessionId: this.id,
|
|
98
98
|
reference: [],
|
|
99
99
|
searchReference: [],
|
|
@@ -104,13 +104,13 @@ class J extends N {
|
|
|
104
104
|
isAgree: 0
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
this.pushMessage(
|
|
108
|
-
messageId:
|
|
107
|
+
this.pushMessage(l), this.event.emit("message:action", {
|
|
108
|
+
messageId: l.messageId,
|
|
109
109
|
action: s
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
if (this.inactivating) {
|
|
113
|
-
const
|
|
113
|
+
const l = new Error(
|
|
114
114
|
y.Inactive
|
|
115
115
|
// {
|
|
116
116
|
// cause: {
|
|
@@ -120,41 +120,41 @@ class J extends N {
|
|
|
120
120
|
// },
|
|
121
121
|
// }
|
|
122
122
|
);
|
|
123
|
-
u.warn("error",
|
|
124
|
-
} else if (
|
|
125
|
-
if (u.log(`calling function ${g} of plugin ${
|
|
126
|
-
${JSON.stringify(
|
|
123
|
+
u.warn("error", l), this.event.emit("error", l);
|
|
124
|
+
} else if (i === "FUNCTION_CALL" && a) {
|
|
125
|
+
if (u.log(`calling function ${g} of plugin ${m} with argument:
|
|
126
|
+
${JSON.stringify(r)}`), !v.plugins[m]) {
|
|
127
127
|
e({
|
|
128
128
|
code: 404,
|
|
129
129
|
message: "对不起,没有找到插件。"
|
|
130
130
|
});
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
|
-
const
|
|
134
|
-
typeof
|
|
133
|
+
const l = v.plugins[m][g];
|
|
134
|
+
typeof l != "function" && e({
|
|
135
135
|
code: 404,
|
|
136
136
|
message: "对不起,没有找到插件方法。"
|
|
137
137
|
});
|
|
138
|
-
let M =
|
|
138
|
+
let M = r == null ? void 0 : r.query;
|
|
139
139
|
try {
|
|
140
|
-
M = JSON.parse(
|
|
140
|
+
M = JSON.parse(r == null ? void 0 : r.query);
|
|
141
141
|
} catch (R) {
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
l(M, (...R) => {
|
|
144
144
|
this._stopAnswer || e(...R);
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
})),
|
|
147
|
+
})), o.on("answer", (s) => {
|
|
148
148
|
if (!this._stopAnswer)
|
|
149
149
|
if (s.data.code !== 200 && (s.data.index = -1, this.event.emit("error", s.data)), s.data.index === -1) {
|
|
150
150
|
let e = this.messages[this.messages.length - 1];
|
|
151
151
|
if (e && !e.messageId)
|
|
152
|
-
e =
|
|
152
|
+
e = h(h({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", e);
|
|
153
153
|
else {
|
|
154
|
-
const
|
|
154
|
+
const i = h({
|
|
155
155
|
messageId: "",
|
|
156
156
|
content: "",
|
|
157
|
-
role:
|
|
157
|
+
role: k.Robot,
|
|
158
158
|
sessionId: this.id,
|
|
159
159
|
reference: [],
|
|
160
160
|
searchReference: [],
|
|
@@ -165,38 +165,38 @@ class J extends N {
|
|
|
165
165
|
isAgree: 0
|
|
166
166
|
}
|
|
167
167
|
}, s.data);
|
|
168
|
-
this.event.emit("message:content",
|
|
168
|
+
this.event.emit("message:content", i), this.pushMessage(i), this.event.emit("answer:finish", i);
|
|
169
169
|
}
|
|
170
170
|
} else {
|
|
171
171
|
let e = this.messages[this.messages.length - 1];
|
|
172
|
-
e && !e.messageId ? (e =
|
|
172
|
+
e && !e.messageId ? (e = h(h({}, 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
173
|
}
|
|
174
|
-
}),
|
|
174
|
+
}), o.on("reference", (s) => w(this, null, function* () {
|
|
175
175
|
if (this._stopAnswer)
|
|
176
176
|
return;
|
|
177
177
|
if (!this.id) {
|
|
178
|
-
const
|
|
178
|
+
const r = new Error(
|
|
179
179
|
y.IdUndefined
|
|
180
180
|
// {
|
|
181
181
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
182
182
|
// }
|
|
183
183
|
);
|
|
184
|
-
u.error(
|
|
184
|
+
u.error(r), this.event.emit("error", r), this.frozen = !1;
|
|
185
185
|
return;
|
|
186
186
|
}
|
|
187
187
|
const {
|
|
188
188
|
type: e,
|
|
189
|
-
data:
|
|
190
|
-
requestId:
|
|
191
|
-
} = s,
|
|
192
|
-
if (
|
|
189
|
+
data: i,
|
|
190
|
+
requestId: a
|
|
191
|
+
} = s, m = this.messages.findIndex((r) => r.messageId === a && r.role === k.User);
|
|
192
|
+
if (m < 0)
|
|
193
193
|
return;
|
|
194
|
-
const g =
|
|
194
|
+
const g = m + 1;
|
|
195
195
|
if (g >= this.messages.length) {
|
|
196
|
-
const
|
|
196
|
+
const r = {
|
|
197
197
|
messageId: "",
|
|
198
198
|
content: "",
|
|
199
|
-
role:
|
|
199
|
+
role: k.Robot,
|
|
200
200
|
sessionId: this.id,
|
|
201
201
|
reference: [],
|
|
202
202
|
searchReference: [],
|
|
@@ -207,33 +207,39 @@ class J extends N {
|
|
|
207
207
|
isAgree: 0
|
|
208
208
|
}
|
|
209
209
|
};
|
|
210
|
-
this.pushMessage(
|
|
210
|
+
this.pushMessage(r);
|
|
211
211
|
}
|
|
212
|
-
e === "KG" ? (this.messages[g] =
|
|
213
|
-
reference:
|
|
214
|
-
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference",
|
|
215
|
-
searchReference:
|
|
216
|
-
}), this.event.emit("message:searchreference",
|
|
217
|
-
})), this.socket =
|
|
212
|
+
e === "KG" ? (this.messages[g] = p(h({}, this.messages[g]), {
|
|
213
|
+
reference: i.knowledgeReference
|
|
214
|
+
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : e === "WEB_SEARCH" && (this.messages[g] = p(h({}, this.messages[g]), {
|
|
215
|
+
searchReference: i.knowledgeReference
|
|
216
|
+
}), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
217
|
+
})), this.socket = o, o.open();
|
|
218
218
|
}));
|
|
219
219
|
}
|
|
220
|
-
sendQuestion(t,
|
|
221
|
-
return
|
|
222
|
-
var
|
|
220
|
+
sendQuestion(t, n) {
|
|
221
|
+
return w(this, null, function* () {
|
|
222
|
+
var o, s, e;
|
|
223
|
+
let d = p(h({}, t), {
|
|
224
|
+
promptVariables: this.promptVariables.reduce((i, a) => p(h({}, i), {
|
|
225
|
+
[a.key]: a.value
|
|
226
|
+
}), {}),
|
|
227
|
+
knowledges: (o = this.knowledges) == null ? void 0 : o.map((i) => i.id)
|
|
228
|
+
});
|
|
223
229
|
if (!this.active) {
|
|
224
230
|
if (yield this.activate(), !this.socket) {
|
|
225
|
-
const
|
|
231
|
+
const i = new Error(
|
|
226
232
|
y.SocketConnectionFailed
|
|
227
233
|
// {
|
|
228
234
|
// cause: { code: -1, message: 'socket is null' },
|
|
229
235
|
// }
|
|
230
236
|
);
|
|
231
|
-
return u.warn("error",
|
|
237
|
+
return u.warn("error", i), this.event.emit("error", i), !1;
|
|
232
238
|
}
|
|
233
|
-
(
|
|
239
|
+
(s = this.socket) == null || s.emit("question", d);
|
|
234
240
|
return;
|
|
235
241
|
}
|
|
236
|
-
(
|
|
242
|
+
(e = this.socket) == null || e.emit("question", d);
|
|
237
243
|
});
|
|
238
244
|
}
|
|
239
245
|
stopAnswer() {
|
|
@@ -242,5 +248,5 @@ class J extends N {
|
|
|
242
248
|
}
|
|
243
249
|
}
|
|
244
250
|
export {
|
|
245
|
-
|
|
251
|
+
B as default
|
|
246
252
|
};
|