@glodon-aiot/bot-client-sdk 3.27.0-alpha.0 → 3.27.0-alpha.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/README.md +1 -1
- package/dist/es/AgentSession.mjs +141 -144
- package/dist/es/BotClient.mjs +90 -83
- package/dist/es/Config.mjs +27 -22
- package/dist/es/Session.mjs +36 -33
- package/dist/es/index.mjs +67 -66
- package/dist/es/package.json.mjs +2 -2
- package/dist/lib/index.js +45 -45
- package/dist/src/Config.d.ts +3 -0
- package/dist/src/index.d.ts +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ client.addEventListener('ready', () => {
|
|
|
66
66
|
|
|
67
67
|
应用类型由平台应用决定,`loadSession` 按类型创建对应会话。
|
|
68
68
|
|
|
69
|
-
`appVersion`
|
|
69
|
+
`appVersion` 作用于 Agent 的 WebSocket 建连,以及应用详情、prompt 变量、推荐问题、常用提示词和创建会话。HTTP 查询或创建会话请求体里的字段名是 `version`。`draft` 使用草稿,`v1` / `v2` 等指定已发布版本(大小写不敏感),`latest` 始终使用最新版本。不传或传空白时 SDK 默认传 `latest`。其他值不会导致连接失败,服务端会改用最新版本。ready 带回的版本与请求不一致时,SDK 输出告警。
|
|
70
70
|
|
|
71
71
|
## 对话界面
|
|
72
72
|
|
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var E = Object.defineProperty, x = Object.defineProperties;
|
|
2
|
+
var j = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var P = Object.getOwnPropertySymbols;
|
|
4
|
+
var O = Object.prototype.hasOwnProperty, V = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var A = (n, d, e) => d in n ? E(n, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[d] = e, h = (n, d) => {
|
|
6
6
|
for (var e in d || (d = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var e of
|
|
10
|
-
|
|
7
|
+
O.call(d, e) && A(n, e, d[e]);
|
|
8
|
+
if (P)
|
|
9
|
+
for (var e of P(d))
|
|
10
|
+
V.call(d, e) && A(n, e, d[e]);
|
|
11
11
|
return n;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
12
|
+
}, y = (n, d) => x(n, j(d));
|
|
13
|
+
var M = (n, d, e) => (A(n, typeof d != "symbol" ? d + "" : d, e), e);
|
|
14
14
|
var v = (n, d, e) => new Promise((i, a) => {
|
|
15
15
|
var o = (t) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
a(
|
|
17
|
+
s(e.next(t));
|
|
18
|
+
} catch (l) {
|
|
19
|
+
a(l);
|
|
20
20
|
}
|
|
21
21
|
}, c = (t) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
a(
|
|
23
|
+
s(e.throw(t));
|
|
24
|
+
} catch (l) {
|
|
25
|
+
a(l);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, s = (t) => t.done ? i(t.value) : Promise.resolve(t.value).then(o, c);
|
|
28
|
+
s((e = e.apply(n, d)).next());
|
|
29
29
|
});
|
|
30
|
-
import { ChatMessageRole as
|
|
31
|
-
import
|
|
32
|
-
import { configuration as
|
|
30
|
+
import { ChatMessageRole as C, PromptVariableType as T } from "@glodon-aiot/apis";
|
|
31
|
+
import F from "./Logger.mjs";
|
|
32
|
+
import { configuration as u, resolveAppVersion as N } from "./Config.mjs";
|
|
33
33
|
import { io as $ } from "socket.io-client";
|
|
34
|
-
import { UserMode as
|
|
35
|
-
import D, { SessionErrors as
|
|
34
|
+
import { UserMode as I } from "./PayloadTypes.mjs";
|
|
35
|
+
import D, { SessionErrors as R } from "./Session.mjs";
|
|
36
36
|
import z from "dayjs";
|
|
37
37
|
import { v4 as B } from "uuid";
|
|
38
38
|
import { connectLocalMcpBridge as J, subscribeLocalMcpEndpoints as Q } from "./localMcp/endpoints.mjs";
|
|
39
39
|
import { registerLocalMcp as Y } from "./localMcp/register.mjs";
|
|
40
|
-
const r = new
|
|
41
|
-
function
|
|
40
|
+
const r = new F("[AgentSession] ");
|
|
41
|
+
function L(n) {
|
|
42
42
|
if (typeof n != "string")
|
|
43
43
|
return n;
|
|
44
44
|
const d = n.trim();
|
|
@@ -51,7 +51,7 @@ function U(n) {
|
|
|
51
51
|
}
|
|
52
52
|
function H(n) {
|
|
53
53
|
const d = n.imageContent;
|
|
54
|
-
return Array.isArray(d) ?
|
|
54
|
+
return Array.isArray(d) ? y(h({}, n), {
|
|
55
55
|
imageContent: `[${d.length}]`
|
|
56
56
|
}) : n;
|
|
57
57
|
}
|
|
@@ -61,28 +61,28 @@ function K(n, d) {
|
|
|
61
61
|
const e = d.trim();
|
|
62
62
|
!e || n.trim().toLowerCase() === e.toLowerCase() || console.warn(`[AgentSession] 应用版本「${n}」未生效,服务端已改用「${e}」。`);
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function U(n) {
|
|
65
65
|
return n == null || n === "" || typeof n == "object" && !Array.isArray(n) && Object.keys(n).length === 0;
|
|
66
66
|
}
|
|
67
67
|
function G(n, d) {
|
|
68
|
-
const e =
|
|
69
|
-
if (!
|
|
68
|
+
const e = L(n == null ? void 0 : n.query);
|
|
69
|
+
if (!U(e))
|
|
70
70
|
return e;
|
|
71
|
-
const i =
|
|
72
|
-
return
|
|
71
|
+
const i = L(d);
|
|
72
|
+
return U(i) && e != null ? e : i;
|
|
73
73
|
}
|
|
74
74
|
class ce extends D {
|
|
75
|
-
constructor(e, i = "", a, o, c,
|
|
76
|
-
super(e, i, a, o, c,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
constructor(e, i = "", a, o, c, s) {
|
|
76
|
+
super(e, i, a, o, c, s);
|
|
77
|
+
M(this, "inflightCalls", /* @__PURE__ */ new Set());
|
|
78
|
+
M(this, "localMcpTicket", 0);
|
|
79
|
+
M(this, "stopLocalMcpUpdates");
|
|
80
80
|
/** 已发出 `update`、尚未收到结果;下一条 ready / ack 按换票结果处理,不拆连接。 */
|
|
81
|
-
|
|
81
|
+
M(this, "pendingTokenUpdate", !1);
|
|
82
82
|
}
|
|
83
83
|
prepareConnection() {
|
|
84
84
|
return new Promise((e) => v(this, null, function* () {
|
|
85
|
-
var c
|
|
85
|
+
var c;
|
|
86
86
|
if ((c = this.socket) != null && c.connected) {
|
|
87
87
|
r.log("socket:reuse", this.id), e(!0);
|
|
88
88
|
return;
|
|
@@ -90,14 +90,14 @@ class ce extends D {
|
|
|
90
90
|
this.socket && (this.socket.removeAllListeners(), this.socket.close(), this.socket = null);
|
|
91
91
|
const i = {
|
|
92
92
|
version: "1.0",
|
|
93
|
-
stream: JSON.stringify(
|
|
93
|
+
stream: JSON.stringify(u.stream),
|
|
94
94
|
appId: this._applicationId,
|
|
95
95
|
sessionId: this.id,
|
|
96
96
|
Authorization: `${this.requestToken}`,
|
|
97
|
-
userMode:
|
|
97
|
+
userMode: u.debug ? I.Debug : I.Normal
|
|
98
98
|
};
|
|
99
|
-
i.appVersion = (
|
|
100
|
-
const a = new URL(
|
|
99
|
+
i.appVersion = N();
|
|
100
|
+
const a = new URL(u.apiRoot);
|
|
101
101
|
r.log("socket:connecting", {
|
|
102
102
|
sessionId: this.id,
|
|
103
103
|
origin: a.origin
|
|
@@ -111,101 +111,98 @@ class ce extends D {
|
|
|
111
111
|
r.log("socket:connect"), this.event.emit("socket:connect"), o.emit("init");
|
|
112
112
|
}), o.on("disconnect", () => {
|
|
113
113
|
r.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1, this.pendingTokenUpdate = !1;
|
|
114
|
-
}), o.on("ready", (
|
|
114
|
+
}), o.on("ready", (s) => {
|
|
115
115
|
if (this.pendingTokenUpdate) {
|
|
116
|
-
this.handleResourceTokenUpdateResult(
|
|
116
|
+
this.handleResourceTokenUpdateResult(s);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
|
-
if (
|
|
120
|
-
r.log("ready"), K(i.appVersion,
|
|
121
|
-
const
|
|
122
|
-
|
|
119
|
+
if (s.code === 200) {
|
|
120
|
+
r.log("ready"), K(i.appVersion, s.appVersion);
|
|
121
|
+
const t = u.debug ? I.Debug : I.Normal;
|
|
122
|
+
t === I.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
|
|
123
123
|
} else {
|
|
124
124
|
this._ready && (this._ready = !1);
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// }
|
|
130
|
-
);
|
|
131
|
-
r.error("error", s), this.event.emit("error", s), e(!1);
|
|
125
|
+
const t = new Error(R.SocketConnectionFailed, {
|
|
126
|
+
cause: s
|
|
127
|
+
});
|
|
128
|
+
r.error("error", t), this.event.emit("error", t), e(!1);
|
|
132
129
|
}
|
|
133
|
-
}), o.on("action", (
|
|
134
|
-
var
|
|
130
|
+
}), o.on("action", (s, t) => v(this, null, function* () {
|
|
131
|
+
var S;
|
|
135
132
|
if (this._stopAnswer || !this.id)
|
|
136
133
|
return;
|
|
137
134
|
const {
|
|
138
135
|
type: l,
|
|
139
136
|
data: {
|
|
140
|
-
runnerIsClient:
|
|
141
|
-
pluginCode:
|
|
142
|
-
funcCode:
|
|
143
|
-
parameters:
|
|
144
|
-
requestBody:
|
|
137
|
+
runnerIsClient: m,
|
|
138
|
+
pluginCode: f,
|
|
139
|
+
funcCode: g,
|
|
140
|
+
parameters: p,
|
|
141
|
+
requestBody: _
|
|
145
142
|
}
|
|
146
|
-
} =
|
|
143
|
+
} = s, k = this.messages[this.messages.length - 1];
|
|
147
144
|
if (!k.messageId)
|
|
148
|
-
k.actions || (k.actions = []), k.actions[
|
|
145
|
+
k.actions || (k.actions = []), k.actions[s.data.step - 1] || (k.actions[s.data.step - 1] = []), k.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
|
|
149
146
|
messageId: k.messageId,
|
|
150
|
-
action:
|
|
147
|
+
action: s
|
|
151
148
|
}), this.event.emit("message:updated", k);
|
|
152
149
|
else {
|
|
153
|
-
const
|
|
150
|
+
const w = {
|
|
154
151
|
messageId: "",
|
|
155
152
|
content: "",
|
|
156
|
-
role:
|
|
153
|
+
role: C.Robot,
|
|
157
154
|
sessionId: this.id,
|
|
158
155
|
reference: [],
|
|
159
156
|
searchReference: [],
|
|
160
157
|
isLoading: !0,
|
|
161
158
|
messageTime: "",
|
|
162
|
-
actions: [[
|
|
159
|
+
actions: [[s]],
|
|
163
160
|
comment: {
|
|
164
161
|
isAgree: 0
|
|
165
162
|
},
|
|
166
163
|
isReplying: !0
|
|
167
164
|
};
|
|
168
|
-
this.pushMessage(
|
|
169
|
-
messageId:
|
|
170
|
-
action:
|
|
165
|
+
this.pushMessage(w), this.event.emit("message:action", {
|
|
166
|
+
messageId: w.messageId,
|
|
167
|
+
action: s
|
|
171
168
|
});
|
|
172
169
|
}
|
|
173
|
-
if (l === "FUNCTION_CALL" && !
|
|
174
|
-
r.log(`calling function ${
|
|
175
|
-
${JSON.stringify(
|
|
176
|
-
const
|
|
177
|
-
if (!
|
|
178
|
-
r.error("plugin not found",
|
|
170
|
+
if (l === "FUNCTION_CALL" && !m && r.log("server function", f, g), l === "FUNCTION_CALL" && m) {
|
|
171
|
+
r.log(`calling function ${g} of plugin ${f} with argument:
|
|
172
|
+
${JSON.stringify(p)}`);
|
|
173
|
+
const w = (S = u.plugins) == null ? void 0 : S[f];
|
|
174
|
+
if (!w) {
|
|
175
|
+
r.error("plugin not found", f, g), t({
|
|
179
176
|
code: 404,
|
|
180
177
|
message: "没有找到插件。"
|
|
181
178
|
});
|
|
182
179
|
return;
|
|
183
180
|
}
|
|
184
|
-
const
|
|
185
|
-
if (typeof
|
|
186
|
-
r.error("plugin function not found",
|
|
181
|
+
const b = w[g];
|
|
182
|
+
if (typeof b != "function") {
|
|
183
|
+
r.error("plugin function not found", f, g), t({
|
|
187
184
|
code: 404,
|
|
188
185
|
message: "没有找到插件方法。"
|
|
189
186
|
});
|
|
190
187
|
return;
|
|
191
188
|
}
|
|
192
|
-
const
|
|
193
|
-
this.invokeClientPlugin(
|
|
194
|
-
requestId:
|
|
195
|
-
pluginCode:
|
|
196
|
-
functionCode:
|
|
189
|
+
const q = G(p, _);
|
|
190
|
+
this.invokeClientPlugin(b, q, t, {
|
|
191
|
+
requestId: s.requestId,
|
|
192
|
+
pluginCode: f,
|
|
193
|
+
functionCode: g
|
|
197
194
|
});
|
|
198
195
|
}
|
|
199
|
-
})), o.on("answer", (
|
|
200
|
-
if (r.log("answer",
|
|
201
|
-
if (
|
|
202
|
-
let
|
|
203
|
-
if (
|
|
204
|
-
this.handleStreamAnswer(
|
|
196
|
+
})), o.on("answer", (s) => {
|
|
197
|
+
if (r.log("answer", s == null ? void 0 : s.data), !this._stopAnswer)
|
|
198
|
+
if (s.data.code !== 200 && (s.data.index = -1), s.data.stream || s.data.stream === void 0) {
|
|
199
|
+
let t = this.messages[this.messages.length - 1];
|
|
200
|
+
if (t && t.role === C.Robot)
|
|
201
|
+
this.handleStreamAnswer(s.data, t), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t), t.index === -1 && (t.isReplying = !1, this.event.emit("answer:finish", t));
|
|
205
202
|
else {
|
|
206
203
|
const l = {
|
|
207
204
|
content: "",
|
|
208
|
-
role:
|
|
205
|
+
role: C.Robot,
|
|
209
206
|
reference: [],
|
|
210
207
|
searchReference: [],
|
|
211
208
|
messageId: "",
|
|
@@ -225,17 +222,17 @@ class ce extends D {
|
|
|
225
222
|
thinkingStatus: "",
|
|
226
223
|
searchingStatus: ""
|
|
227
224
|
};
|
|
228
|
-
this.handleStreamAnswer(
|
|
225
|
+
this.handleStreamAnswer(s.data, l), this.pushMessage(l), this.event.emit("message:content", l), l.index === -1 && (l.isReplying = !1, this.event.emit("answer:finish", l));
|
|
229
226
|
}
|
|
230
|
-
} else if (
|
|
231
|
-
let
|
|
232
|
-
if (
|
|
233
|
-
|
|
227
|
+
} else if (s.data.updateSession && this.data && (this.data = h(h({}, this.data), s.data.updateSession), this.event.emit("data:updated", this.data)), s.data.index === -1) {
|
|
228
|
+
let t = this.messages[this.messages.length - 1];
|
|
229
|
+
if (t && !t.messageId)
|
|
230
|
+
t = h(h({}, t), s.data), this.event.emit("message:content", t), this.event.emit("message:updated", t), this.event.emit("answer:finish", t);
|
|
234
231
|
else {
|
|
235
|
-
const l =
|
|
232
|
+
const l = h({
|
|
236
233
|
messageId: "",
|
|
237
234
|
content: "",
|
|
238
|
-
role:
|
|
235
|
+
role: C.Robot,
|
|
239
236
|
sessionId: this.id,
|
|
240
237
|
reference: [],
|
|
241
238
|
searchReference: [],
|
|
@@ -246,15 +243,15 @@ class ce extends D {
|
|
|
246
243
|
isAgree: 0
|
|
247
244
|
},
|
|
248
245
|
isReplying: !0
|
|
249
|
-
},
|
|
246
|
+
}, s.data);
|
|
250
247
|
this.event.emit("message:content", l), this.pushMessage(l), this.event.emit("answer:finish", l);
|
|
251
248
|
}
|
|
252
249
|
} else {
|
|
253
|
-
let
|
|
254
|
-
|
|
250
|
+
let t = this.messages[this.messages.length - 1];
|
|
251
|
+
t && !t.messageId ? (t = h(h({}, t), s.data), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t)) : (this.pushMessage(h({
|
|
255
252
|
messageId: "",
|
|
256
253
|
content: "",
|
|
257
|
-
role:
|
|
254
|
+
role: C.Robot,
|
|
258
255
|
sessionId: this.id,
|
|
259
256
|
reference: [],
|
|
260
257
|
searchReference: [],
|
|
@@ -265,40 +262,40 @@ class ce extends D {
|
|
|
265
262
|
isAgree: 0
|
|
266
263
|
},
|
|
267
264
|
isReplying: !0
|
|
268
|
-
},
|
|
265
|
+
}, s.data)), this.event.emit("message:content", s.data));
|
|
269
266
|
}
|
|
270
|
-
}), o.on("reference", (
|
|
267
|
+
}), o.on("reference", (s) => v(this, null, function* () {
|
|
271
268
|
if (this._stopAnswer)
|
|
272
269
|
return;
|
|
273
270
|
if (!this.id) {
|
|
274
|
-
const
|
|
275
|
-
|
|
271
|
+
const p = new Error(
|
|
272
|
+
R.IdUndefined
|
|
276
273
|
// {
|
|
277
274
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
278
275
|
// }
|
|
279
276
|
);
|
|
280
|
-
r.error(
|
|
277
|
+
r.error(p), this.event.emit("error", p), this.frozen = !1;
|
|
281
278
|
return;
|
|
282
279
|
}
|
|
283
280
|
const {
|
|
284
|
-
type:
|
|
281
|
+
type: t,
|
|
285
282
|
data: l,
|
|
286
|
-
requestId:
|
|
287
|
-
} =
|
|
283
|
+
requestId: m
|
|
284
|
+
} = s;
|
|
288
285
|
r.log("reference", {
|
|
289
|
-
type:
|
|
290
|
-
requestId:
|
|
286
|
+
type: t,
|
|
287
|
+
requestId: m,
|
|
291
288
|
data: l
|
|
292
289
|
});
|
|
293
|
-
const
|
|
294
|
-
if (
|
|
290
|
+
const f = this.messages.findIndex((p) => p.messageId === m && p.role === C.User);
|
|
291
|
+
if (f < 0)
|
|
295
292
|
return;
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
298
|
-
const
|
|
293
|
+
const g = f + 1;
|
|
294
|
+
if (g >= this.messages.length) {
|
|
295
|
+
const p = {
|
|
299
296
|
messageId: "",
|
|
300
297
|
content: "",
|
|
301
|
-
role:
|
|
298
|
+
role: C.Robot,
|
|
302
299
|
sessionId: this.id,
|
|
303
300
|
reference: [],
|
|
304
301
|
searchReference: [],
|
|
@@ -310,23 +307,23 @@ class ce extends D {
|
|
|
310
307
|
},
|
|
311
308
|
isReplying: !0
|
|
312
309
|
};
|
|
313
|
-
this.pushMessage(
|
|
310
|
+
this.pushMessage(p);
|
|
314
311
|
}
|
|
315
|
-
|
|
312
|
+
t === "KG" ? (this.messages[g] = y(h({}, this.messages[g]), {
|
|
316
313
|
reference: l.knowledgeReference
|
|
317
|
-
}), yield this.fillMessageReference(this.messages[
|
|
314
|
+
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", l.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : t === "WEB_SEARCH" && (this.messages[g] = y(h({}, this.messages[g]), {
|
|
318
315
|
searchReference: l.knowledgeReference
|
|
319
|
-
}), this.event.emit("message:searchreference", l.searchReference), this.event.emit("message:updated", this.messages[
|
|
316
|
+
}), this.event.emit("message:searchreference", l.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
320
317
|
})), this.socket = o, o.open();
|
|
321
318
|
}));
|
|
322
319
|
}
|
|
323
320
|
registerMcpFromClientConfig() {
|
|
324
|
-
return
|
|
321
|
+
return u.mcp ? new Promise((e, i) => {
|
|
325
322
|
if (!this.socket) {
|
|
326
323
|
i("socket is undefined");
|
|
327
324
|
return;
|
|
328
325
|
}
|
|
329
|
-
this.socket.emit("add_mcp_servers",
|
|
326
|
+
this.socket.emit("add_mcp_servers", u.mcp, (a) => {
|
|
330
327
|
a.code === 200 ? (Object.keys(a.data).forEach((o) => {
|
|
331
328
|
a.data[o].code !== 200 && r.report(o, "MCP Server 注册失败。", a.data[o]);
|
|
332
329
|
}), r.log("mcp:registered", Object.keys(a.data)), e(!0)) : (r.error("MCP Server 注册失败。", a), i(a));
|
|
@@ -342,8 +339,8 @@ class ce extends D {
|
|
|
342
339
|
const i = ++this.localMcpTicket;
|
|
343
340
|
Y({
|
|
344
341
|
arrange: (o = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : o[0],
|
|
345
|
-
initMcp:
|
|
346
|
-
apiRoot:
|
|
342
|
+
initMcp: u.mcp,
|
|
343
|
+
apiRoot: u.apiRoot,
|
|
347
344
|
token: this.requestToken,
|
|
348
345
|
socket: e,
|
|
349
346
|
isCurrent: () => i === this.localMcpTicket
|
|
@@ -375,12 +372,12 @@ class ce extends D {
|
|
|
375
372
|
return v(this, null, function* () {
|
|
376
373
|
var o;
|
|
377
374
|
this.convertKnowledgesToChatFormat(this.knowledges);
|
|
378
|
-
let a =
|
|
379
|
-
promptVariables: this.promptVariables.filter((c) => c.type ===
|
|
380
|
-
[
|
|
375
|
+
let a = y(h({}, e), {
|
|
376
|
+
promptVariables: this.promptVariables.filter((c) => c.type === T.User).reduce((c, s) => y(h({}, c), {
|
|
377
|
+
[s.key]: s.value
|
|
381
378
|
}), {}),
|
|
382
|
-
systemPromptVariables: this.promptVariables.filter((c) => c.type ===
|
|
383
|
-
[
|
|
379
|
+
systemPromptVariables: this.promptVariables.filter((c) => c.type === T.System).reduce((c, s) => y(h({}, c), {
|
|
380
|
+
[s.key]: s.value
|
|
384
381
|
}), {}),
|
|
385
382
|
knowledges: (o = this.knowledges) == null ? void 0 : o.map((c) => c.id),
|
|
386
383
|
//agent支持指定文件时再放开
|
|
@@ -390,7 +387,7 @@ class ce extends D {
|
|
|
390
387
|
if (!this.active) {
|
|
391
388
|
if (yield this.activate(), !this.socket) {
|
|
392
389
|
const c = new Error(
|
|
393
|
-
|
|
390
|
+
R.SocketConnectionFailed
|
|
394
391
|
// {
|
|
395
392
|
// cause: { code: -1, message: 'socket is null' },
|
|
396
393
|
// }
|
|
@@ -416,10 +413,10 @@ class ce extends D {
|
|
|
416
413
|
invokeClientPlugin(e, i, a, o) {
|
|
417
414
|
const c = new AbortController();
|
|
418
415
|
this.inflightCalls.add(c);
|
|
419
|
-
let
|
|
420
|
-
const t = (...
|
|
421
|
-
|
|
422
|
-
},
|
|
416
|
+
let s = !1;
|
|
417
|
+
const t = (...m) => {
|
|
418
|
+
s || (s = !0, this.inflightCalls.delete(c), !(this._stopAnswer || c.signal.aborted) && a(...m));
|
|
419
|
+
}, l = {
|
|
423
420
|
requestId: o.requestId || B(),
|
|
424
421
|
applicationId: this._applicationId,
|
|
425
422
|
sessionId: this.id,
|
|
@@ -428,15 +425,15 @@ class ce extends D {
|
|
|
428
425
|
signal: c.signal
|
|
429
426
|
};
|
|
430
427
|
try {
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
r.error("client plugin failed",
|
|
428
|
+
const m = e(i, t, l);
|
|
429
|
+
m && typeof m.catch == "function" && m.catch((f) => {
|
|
430
|
+
r.error("client plugin failed", f), t({
|
|
434
431
|
code: 500,
|
|
435
432
|
message: "客户端插件执行失败。"
|
|
436
433
|
});
|
|
437
434
|
});
|
|
438
|
-
} catch (
|
|
439
|
-
r.error("client plugin failed",
|
|
435
|
+
} catch (m) {
|
|
436
|
+
r.error("client plugin failed", m), t({
|
|
440
437
|
code: 500,
|
|
441
438
|
message: "客户端插件执行失败。"
|
|
442
439
|
});
|
|
@@ -466,7 +463,7 @@ class ce extends D {
|
|
|
466
463
|
r.log("socket:update:ok", this.id);
|
|
467
464
|
return;
|
|
468
465
|
}
|
|
469
|
-
const i = new Error(
|
|
466
|
+
const i = new Error(R.SocketConnectionFailed, {
|
|
470
467
|
cause: e
|
|
471
468
|
});
|
|
472
469
|
r.error("socket:update:failed", e), this.event.emit("error", i);
|