@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.
@@ -1,66 +1,66 @@
1
- var C = Object.defineProperty, S = Object.defineProperties;
2
- var b = Object.getOwnPropertyDescriptors;
1
+ var C = Object.defineProperty, b = Object.defineProperties;
2
+ var S = Object.getOwnPropertyDescriptors;
3
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]);
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 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) => {
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
- r(i.next(c));
17
- } catch (h) {
18
- n(h);
16
+ i(n.next(a));
17
+ } catch (m) {
18
+ o(m);
19
19
  }
20
- }, e = (c) => {
20
+ }, e = (a) => {
21
21
  try {
22
- r(i.throw(c));
23
- } catch (h) {
24
- n(h);
22
+ i(n.throw(a));
23
+ } catch (m) {
24
+ o(m);
25
25
  }
26
- }, r = (c) => c.done ? m(c.value) : Promise.resolve(c.value).then(s, e);
27
- r((i = i.apply(a, t)).next());
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 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";
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 L("[AgentSession] ");
36
- class J extends N {
37
- constructor(t, i = "", m, n, s, e) {
38
- super(t, i, m, n, s, e);
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) => p(this, null, function* () {
41
+ return new Promise((t) => w(this, null, function* () {
42
42
  this.socket && t(!0);
43
- const i = {
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: 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,
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
- n.on("connect", () => {
56
- u.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
57
- }), n.on("disconnect", () => {
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
- }), n.on("ready", (s) => {
59
+ }), o.on("ready", (s) => {
60
60
  if (s.code === 200) {
61
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);
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
- }), n.on("action", (s, e) => p(this, null, function* () {
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: r,
78
+ type: i,
79
79
  data: {
80
- runnerIsClient: c,
81
- pluginCode: h,
80
+ runnerIsClient: a,
81
+ pluginCode: m,
82
82
  funcCode: g,
83
- parameters: o,
83
+ parameters: r,
84
84
  requestBody: U
85
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,
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", d);
91
+ }), this.event.emit("message:updated", f);
92
92
  else {
93
- const f = {
93
+ const l = {
94
94
  messageId: "",
95
95
  content: "",
96
- role: I.Robot,
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(f), this.event.emit("message:action", {
108
- messageId: f.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 f = new Error(
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", 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]) {
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 f = w.plugins[h][g];
134
- typeof f != "function" && e({
133
+ const l = v.plugins[m][g];
134
+ typeof l != "function" && e({
135
135
  code: 404,
136
136
  message: "对不起,没有找到插件方法。"
137
137
  });
138
- let M = o == null ? void 0 : o.query;
138
+ let M = r == null ? void 0 : r.query;
139
139
  try {
140
- M = JSON.parse(o == null ? void 0 : o.query);
140
+ M = JSON.parse(r == null ? void 0 : r.query);
141
141
  } catch (R) {
142
142
  }
143
- f(M, (...R) => {
143
+ l(M, (...R) => {
144
144
  this._stopAnswer || e(...R);
145
145
  });
146
146
  }
147
- })), n.on("answer", (s) => {
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 = l(l({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", 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 r = l({
154
+ const i = h({
155
155
  messageId: "",
156
156
  content: "",
157
- role: I.Robot,
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", r), this.pushMessage(r), this.event.emit("answer:finish", r);
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 = 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));
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
- }), n.on("reference", (s) => p(this, null, function* () {
174
+ }), o.on("reference", (s) => w(this, null, function* () {
175
175
  if (this._stopAnswer)
176
176
  return;
177
177
  if (!this.id) {
178
- const o = new Error(
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(o), this.event.emit("error", o), this.frozen = !1;
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: r,
190
- requestId: c
191
- } = s, h = this.messages.findIndex((o) => o.messageId === c && o.role === I.User);
192
- if (h < 0)
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 = h + 1;
194
+ const g = m + 1;
195
195
  if (g >= this.messages.length) {
196
- const o = {
196
+ const r = {
197
197
  messageId: "",
198
198
  content: "",
199
- role: I.Robot,
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(o);
210
+ this.pushMessage(r);
211
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();
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, i) {
221
- return p(this, null, function* () {
222
- var m, n;
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 s = new Error(
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", s), this.event.emit("error", s), !1;
237
+ return u.warn("error", i), this.event.emit("error", i), !1;
232
238
  }
233
- (m = this.socket) == null || m.emit("question", t);
239
+ (s = this.socket) == null || s.emit("question", d);
234
240
  return;
235
241
  }
236
- (n = this.socket) == null || n.emit("question", t);
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
- J as default
251
+ B as default
246
252
  };