@glodon-aiot/bot-client-sdk 3.26.0-alpha.32 → 3.26.0-alpha.34
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 +234 -214
- package/dist/es/BotClient.mjs +125 -82
- package/dist/es/Config.mjs +42 -42
- package/dist/es/DialogSession.mjs +121 -116
- package/dist/es/EventBus.mjs +38 -34
- package/dist/es/Logger.mjs +19 -21
- package/dist/es/Session.mjs +306 -277
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +69 -69
- package/dist/es/builtinTools/platformSkills.mjs +85 -59
- package/dist/es/localFiles/createLocalFilesPlugin.mjs +53 -52
- package/dist/es/localFiles/host/connectHostBridge.mjs +20 -15
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +39 -34
- package/dist/es/localMcp/client.mjs +101 -90
- package/dist/es/localMcp/endpoints.mjs +94 -0
- package/dist/es/localMcp/register.mjs +149 -97
- package/dist/es/localMcp/registry.mjs +22 -18
- package/dist/es/package.json.mjs +28 -50
- package/dist/lib/index.js +45 -45
- package/dist/src/AgentSession.d.ts +2 -0
- package/dist/src/BotClient.d.ts +6 -1
- package/dist/src/Config.d.ts +2 -1
- package/dist/src/EventBus.d.ts +3 -0
- package/dist/src/Logger.d.ts +15 -8
- package/dist/src/Session.d.ts +4 -2
- package/dist/src/builtinTools/platformSkills.d.ts +22 -1
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/localMcp/client.d.ts +4 -0
- package/dist/src/localMcp/endpoints.d.ts +19 -0
- package/dist/src/localMcp/register.d.ts +2 -0
- package/dist/src/localMcp/registry.d.ts +1 -0
- package/package.json +3 -25
package/dist/es/AgentSession.mjs
CHANGED
|
@@ -1,196 +1,202 @@
|
|
|
1
|
-
var
|
|
1
|
+
var q = Object.defineProperty, x = Object.defineProperties;
|
|
2
2
|
var j = Object.getOwnPropertyDescriptors;
|
|
3
3
|
var P = Object.getOwnPropertySymbols;
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
for (var e in
|
|
7
|
-
|
|
4
|
+
var O = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var R = (r, d, e) => d in r ? q(r, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[d] = e, h = (r, d) => {
|
|
6
|
+
for (var e in d || (d = {}))
|
|
7
|
+
O.call(d, e) && R(r, e, d[e]);
|
|
8
8
|
if (P)
|
|
9
|
-
for (var e of P(
|
|
10
|
-
N.call(
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
9
|
+
for (var e of P(d))
|
|
10
|
+
N.call(d, e) && R(r, e, d[e]);
|
|
11
|
+
return r;
|
|
12
|
+
}, y = (r, d) => x(r, j(d));
|
|
13
|
+
var I = (r, d, e) => (R(r, typeof d != "symbol" ? d + "" : d, e), e);
|
|
14
|
+
var C = (r, d, e) => new Promise((n, c) => {
|
|
15
|
+
var i = (t) => {
|
|
16
16
|
try {
|
|
17
|
-
s(e.next(
|
|
17
|
+
s(e.next(t));
|
|
18
18
|
} catch (l) {
|
|
19
|
-
|
|
19
|
+
c(l);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, o = (t) => {
|
|
22
22
|
try {
|
|
23
|
-
s(e.throw(
|
|
23
|
+
s(e.throw(t));
|
|
24
24
|
} catch (l) {
|
|
25
|
-
|
|
25
|
+
c(l);
|
|
26
26
|
}
|
|
27
|
-
}, s = (
|
|
28
|
-
s((e = e.apply(
|
|
27
|
+
}, s = (t) => t.done ? n(t.value) : Promise.resolve(t.value).then(i, o);
|
|
28
|
+
s((e = e.apply(r, d)).next());
|
|
29
29
|
});
|
|
30
|
-
import { ChatMessageRole as
|
|
31
|
-
import
|
|
32
|
-
import { configuration as
|
|
33
|
-
import { io as
|
|
34
|
-
import { UserMode as
|
|
35
|
-
import
|
|
36
|
-
import
|
|
37
|
-
import { v4 as
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
import { ChatMessageRole as k, PromptVariableType as L } from "@glodon-aiot/apis";
|
|
31
|
+
import F from "./Logger.mjs";
|
|
32
|
+
import { configuration as p } from "./Config.mjs";
|
|
33
|
+
import { io as D } from "socket.io-client";
|
|
34
|
+
import { UserMode as w } from "./PayloadTypes.mjs";
|
|
35
|
+
import V, { SessionErrors as A } from "./Session.mjs";
|
|
36
|
+
import $ from "dayjs";
|
|
37
|
+
import { v4 as z } from "uuid";
|
|
38
|
+
import { connectLocalMcpBridge as B, subscribeLocalMcpEndpoints as J } from "./localMcp/endpoints.mjs";
|
|
39
|
+
import { registerLocalMcp as Q } from "./localMcp/register.mjs";
|
|
40
|
+
const a = new F("[AgentSession] ");
|
|
41
|
+
function _(r) {
|
|
42
|
+
if (typeof r != "string")
|
|
43
|
+
return r;
|
|
44
|
+
const d = r.trim();
|
|
45
|
+
if (d)
|
|
45
46
|
try {
|
|
46
|
-
return JSON.parse(
|
|
47
|
+
return JSON.parse(d);
|
|
47
48
|
} catch (e) {
|
|
48
|
-
return
|
|
49
|
+
return r;
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
52
|
+
function Y(r) {
|
|
53
|
+
const d = r.imageContent;
|
|
54
|
+
return Array.isArray(d) ? y(h({}, r), {
|
|
55
|
+
imageContent: `[${d.length}]`
|
|
56
|
+
}) : r;
|
|
53
57
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
58
|
+
function T(r) {
|
|
59
|
+
return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
|
|
60
|
+
}
|
|
61
|
+
function H(r, d) {
|
|
62
|
+
const e = _(r == null ? void 0 : r.query);
|
|
56
63
|
if (!T(e))
|
|
57
64
|
return e;
|
|
58
|
-
const
|
|
59
|
-
return T(
|
|
65
|
+
const n = _(d);
|
|
66
|
+
return T(n) && e != null ? e : n;
|
|
60
67
|
}
|
|
61
|
-
class
|
|
62
|
-
constructor(e,
|
|
63
|
-
super(e,
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
class oe extends V {
|
|
69
|
+
constructor(e, n = "", c, i, o, s) {
|
|
70
|
+
super(e, n, c, i, o, s);
|
|
71
|
+
I(this, "inflightCalls", /* @__PURE__ */ new Set());
|
|
72
|
+
I(this, "localMcpTicket", 0);
|
|
73
|
+
I(this, "stopLocalMcpUpdates");
|
|
66
74
|
}
|
|
67
75
|
prepareConnection() {
|
|
68
|
-
return new Promise((e) =>
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
return new Promise((e) => C(this, null, function* () {
|
|
77
|
+
var o;
|
|
78
|
+
if ((o = this.socket) != null && o.connected) {
|
|
79
|
+
a.log("socket:reuse", this.id), e(!0);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.socket && (this.socket.removeAllListeners(), this.socket.close(), this.socket = null);
|
|
83
|
+
const n = {
|
|
71
84
|
version: "1.0",
|
|
72
|
-
stream: JSON.stringify(
|
|
85
|
+
stream: JSON.stringify(p.stream),
|
|
73
86
|
appId: this._applicationId,
|
|
74
87
|
sessionId: this.id,
|
|
75
88
|
Authorization: `${this.token}`,
|
|
76
|
-
userMode:
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
|
|
89
|
+
userMode: p.debug ? w.Debug : w.Normal
|
|
90
|
+
}, c = new URL(p.apiRoot);
|
|
91
|
+
a.log("socket:connecting", {
|
|
92
|
+
sessionId: this.id,
|
|
93
|
+
origin: c.origin
|
|
94
|
+
});
|
|
95
|
+
const i = yield D(c.origin, {
|
|
96
|
+
path: c.pathname.replace("api", "socketio") + "/copilot",
|
|
97
|
+
query: n,
|
|
80
98
|
transports: ["websocket"]
|
|
81
99
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}),
|
|
85
|
-
|
|
86
|
-
}),
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
100
|
+
i.on("connect", () => {
|
|
101
|
+
a.log("socket:connect"), this.event.emit("socket:connect"), i.emit("init");
|
|
102
|
+
}), i.on("disconnect", () => {
|
|
103
|
+
a.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
|
|
104
|
+
}), i.on("ready", (s) => {
|
|
105
|
+
if (s.code === 200) {
|
|
106
|
+
a.log("ready");
|
|
107
|
+
const t = p.debug ? w.Debug : w.Normal;
|
|
108
|
+
t === w.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
|
|
91
109
|
} else {
|
|
92
110
|
this._ready && (this._ready = !1);
|
|
93
|
-
const
|
|
94
|
-
|
|
111
|
+
const t = new Error(
|
|
112
|
+
A.SocketConnectionFailed
|
|
95
113
|
// , {
|
|
96
114
|
// cause: data,
|
|
97
115
|
// }
|
|
98
116
|
);
|
|
99
|
-
|
|
117
|
+
a.error("error", t), this.event.emit("error", t), e(!1);
|
|
100
118
|
}
|
|
101
|
-
}),
|
|
119
|
+
}), i.on("action", (s, t) => C(this, null, function* () {
|
|
102
120
|
var S;
|
|
103
121
|
if (this._stopAnswer || !this.id)
|
|
104
122
|
return;
|
|
105
123
|
const {
|
|
106
|
-
type:
|
|
124
|
+
type: l,
|
|
107
125
|
data: {
|
|
108
|
-
runnerIsClient:
|
|
109
|
-
pluginCode:
|
|
126
|
+
runnerIsClient: m,
|
|
127
|
+
pluginCode: f,
|
|
110
128
|
funcCode: g,
|
|
111
|
-
parameters:
|
|
129
|
+
parameters: u,
|
|
112
130
|
requestBody: E
|
|
113
131
|
}
|
|
114
|
-
} =
|
|
115
|
-
if (!
|
|
116
|
-
|
|
117
|
-
messageId:
|
|
118
|
-
action:
|
|
119
|
-
}), this.event.emit("message:updated",
|
|
132
|
+
} = s, v = this.messages[this.messages.length - 1];
|
|
133
|
+
if (!v.messageId)
|
|
134
|
+
v.actions || (v.actions = []), v.actions[s.data.step - 1] || (v.actions[s.data.step - 1] = []), v.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
|
|
135
|
+
messageId: v.messageId,
|
|
136
|
+
action: s
|
|
137
|
+
}), this.event.emit("message:updated", v);
|
|
120
138
|
else {
|
|
121
|
-
const
|
|
139
|
+
const M = {
|
|
122
140
|
messageId: "",
|
|
123
141
|
content: "",
|
|
124
|
-
role:
|
|
142
|
+
role: k.Robot,
|
|
125
143
|
sessionId: this.id,
|
|
126
144
|
reference: [],
|
|
127
145
|
searchReference: [],
|
|
128
146
|
isLoading: !0,
|
|
129
147
|
messageTime: "",
|
|
130
|
-
actions: [[
|
|
148
|
+
actions: [[s]],
|
|
131
149
|
comment: {
|
|
132
150
|
isAgree: 0
|
|
133
151
|
},
|
|
134
152
|
isReplying: !0
|
|
135
153
|
};
|
|
136
|
-
this.pushMessage(
|
|
137
|
-
messageId:
|
|
138
|
-
action:
|
|
154
|
+
this.pushMessage(M), this.event.emit("message:action", {
|
|
155
|
+
messageId: M.messageId,
|
|
156
|
+
action: s
|
|
139
157
|
});
|
|
140
158
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
// message:
|
|
148
|
-
// 'session is inactive, skipping plugin client function call',
|
|
149
|
-
// },
|
|
150
|
-
// }
|
|
151
|
-
);
|
|
152
|
-
m.warn("error", v), this.event.emit("error", v);
|
|
153
|
-
} else if (i === "FUNCTION_CALL" && l) {
|
|
154
|
-
m.log(`calling function ${g} of plugin ${d} with argument:
|
|
155
|
-
${JSON.stringify(f)}`);
|
|
156
|
-
const v = (S = u.plugins) == null ? void 0 : S[d];
|
|
157
|
-
if (!v) {
|
|
158
|
-
s({
|
|
159
|
+
if (l === "FUNCTION_CALL" && !m && a.log("server function", f, g), l === "FUNCTION_CALL" && m) {
|
|
160
|
+
a.log(`calling function ${g} of plugin ${f} with argument:
|
|
161
|
+
${JSON.stringify(u)}`);
|
|
162
|
+
const M = (S = p.plugins) == null ? void 0 : S[f];
|
|
163
|
+
if (!M) {
|
|
164
|
+
a.error("plugin not found", f, g), t({
|
|
159
165
|
code: 404,
|
|
160
166
|
message: "没有找到插件。"
|
|
161
167
|
});
|
|
162
168
|
return;
|
|
163
169
|
}
|
|
164
|
-
const b =
|
|
170
|
+
const b = M[g];
|
|
165
171
|
if (typeof b != "function") {
|
|
166
|
-
|
|
172
|
+
a.error("plugin function not found", f, g), t({
|
|
167
173
|
code: 404,
|
|
168
174
|
message: "没有找到插件方法。"
|
|
169
175
|
});
|
|
170
176
|
return;
|
|
171
177
|
}
|
|
172
|
-
const
|
|
173
|
-
this.invokeClientPlugin(b,
|
|
174
|
-
requestId:
|
|
175
|
-
pluginCode:
|
|
178
|
+
const U = H(u, E);
|
|
179
|
+
this.invokeClientPlugin(b, U, t, {
|
|
180
|
+
requestId: s.requestId,
|
|
181
|
+
pluginCode: f,
|
|
176
182
|
functionCode: g
|
|
177
183
|
});
|
|
178
184
|
}
|
|
179
|
-
})),
|
|
180
|
-
if (!this._stopAnswer)
|
|
181
|
-
if (
|
|
182
|
-
let
|
|
183
|
-
if (
|
|
184
|
-
this.handleStreamAnswer(
|
|
185
|
+
})), i.on("answer", (s) => {
|
|
186
|
+
if (a.log("answer", s == null ? void 0 : s.data), !this._stopAnswer)
|
|
187
|
+
if (s.data.code !== 200 && (s.data.index = -1), s.data.stream || s.data.stream === void 0) {
|
|
188
|
+
let t = this.messages[this.messages.length - 1];
|
|
189
|
+
if (t && t.role === k.Robot)
|
|
190
|
+
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));
|
|
185
191
|
else {
|
|
186
|
-
const
|
|
192
|
+
const l = {
|
|
187
193
|
content: "",
|
|
188
|
-
role:
|
|
194
|
+
role: k.Robot,
|
|
189
195
|
reference: [],
|
|
190
196
|
searchReference: [],
|
|
191
197
|
messageId: "",
|
|
192
198
|
sessionId: this.id,
|
|
193
|
-
messageTime:
|
|
199
|
+
messageTime: $(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
|
|
194
200
|
comment: {
|
|
195
201
|
isAgree: 0
|
|
196
202
|
},
|
|
@@ -205,17 +211,17 @@ class se extends D {
|
|
|
205
211
|
thinkingStatus: "",
|
|
206
212
|
searchingStatus: ""
|
|
207
213
|
};
|
|
208
|
-
this.handleStreamAnswer(
|
|
214
|
+
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));
|
|
209
215
|
}
|
|
210
|
-
} else if (
|
|
211
|
-
let
|
|
212
|
-
if (
|
|
213
|
-
|
|
216
|
+
} 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) {
|
|
217
|
+
let t = this.messages[this.messages.length - 1];
|
|
218
|
+
if (t && !t.messageId)
|
|
219
|
+
t = h(h({}, t), s.data), this.event.emit("message:content", t), this.event.emit("message:updated", t), this.event.emit("answer:finish", t);
|
|
214
220
|
else {
|
|
215
|
-
const
|
|
221
|
+
const l = h({
|
|
216
222
|
messageId: "",
|
|
217
223
|
content: "",
|
|
218
|
-
role:
|
|
224
|
+
role: k.Robot,
|
|
219
225
|
sessionId: this.id,
|
|
220
226
|
reference: [],
|
|
221
227
|
searchReference: [],
|
|
@@ -226,15 +232,15 @@ class se extends D {
|
|
|
226
232
|
isAgree: 0
|
|
227
233
|
},
|
|
228
234
|
isReplying: !0
|
|
229
|
-
},
|
|
230
|
-
this.event.emit("message:content",
|
|
235
|
+
}, s.data);
|
|
236
|
+
this.event.emit("message:content", l), this.pushMessage(l), this.event.emit("answer:finish", l);
|
|
231
237
|
}
|
|
232
238
|
} else {
|
|
233
|
-
let
|
|
234
|
-
|
|
239
|
+
let t = this.messages[this.messages.length - 1];
|
|
240
|
+
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({
|
|
235
241
|
messageId: "",
|
|
236
242
|
content: "",
|
|
237
|
-
role:
|
|
243
|
+
role: k.Robot,
|
|
238
244
|
sessionId: this.id,
|
|
239
245
|
reference: [],
|
|
240
246
|
searchReference: [],
|
|
@@ -245,34 +251,40 @@ class se extends D {
|
|
|
245
251
|
isAgree: 0
|
|
246
252
|
},
|
|
247
253
|
isReplying: !0
|
|
248
|
-
},
|
|
254
|
+
}, s.data)), this.event.emit("message:content", s.data));
|
|
249
255
|
}
|
|
250
|
-
}),
|
|
256
|
+
}), i.on("reference", (s) => C(this, null, function* () {
|
|
251
257
|
if (this._stopAnswer)
|
|
252
258
|
return;
|
|
253
259
|
if (!this.id) {
|
|
254
|
-
const
|
|
255
|
-
|
|
260
|
+
const u = new Error(
|
|
261
|
+
A.IdUndefined
|
|
256
262
|
// {
|
|
257
263
|
// cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
|
|
258
264
|
// }
|
|
259
265
|
);
|
|
260
|
-
|
|
266
|
+
a.error(u), this.event.emit("error", u), this.frozen = !1;
|
|
261
267
|
return;
|
|
262
268
|
}
|
|
263
269
|
const {
|
|
264
|
-
type:
|
|
265
|
-
data:
|
|
266
|
-
requestId:
|
|
267
|
-
} =
|
|
268
|
-
|
|
270
|
+
type: t,
|
|
271
|
+
data: l,
|
|
272
|
+
requestId: m
|
|
273
|
+
} = s;
|
|
274
|
+
a.log("reference", {
|
|
275
|
+
type: t,
|
|
276
|
+
requestId: m,
|
|
277
|
+
data: l
|
|
278
|
+
});
|
|
279
|
+
const f = this.messages.findIndex((u) => u.messageId === m && u.role === k.User);
|
|
280
|
+
if (f < 0)
|
|
269
281
|
return;
|
|
270
|
-
const g =
|
|
282
|
+
const g = f + 1;
|
|
271
283
|
if (g >= this.messages.length) {
|
|
272
|
-
const
|
|
284
|
+
const u = {
|
|
273
285
|
messageId: "",
|
|
274
286
|
content: "",
|
|
275
|
-
role:
|
|
287
|
+
role: k.Robot,
|
|
276
288
|
sessionId: this.id,
|
|
277
289
|
reference: [],
|
|
278
290
|
searchReference: [],
|
|
@@ -284,126 +296,133 @@ class se extends D {
|
|
|
284
296
|
},
|
|
285
297
|
isReplying: !0
|
|
286
298
|
};
|
|
287
|
-
this.pushMessage(
|
|
299
|
+
this.pushMessage(u);
|
|
288
300
|
}
|
|
289
|
-
|
|
290
|
-
reference:
|
|
291
|
-
}), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference",
|
|
292
|
-
searchReference:
|
|
293
|
-
}), this.event.emit("message:searchreference",
|
|
294
|
-
})), this.socket =
|
|
301
|
+
t === "KG" ? (this.messages[g] = y(h({}, this.messages[g]), {
|
|
302
|
+
reference: l.knowledgeReference
|
|
303
|
+
}), 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]), {
|
|
304
|
+
searchReference: l.knowledgeReference
|
|
305
|
+
}), this.event.emit("message:searchreference", l.searchReference), this.event.emit("message:updated", this.messages[g]));
|
|
306
|
+
})), this.socket = i, i.open();
|
|
295
307
|
}));
|
|
296
308
|
}
|
|
297
309
|
registerMcpFromClientConfig() {
|
|
298
|
-
return
|
|
310
|
+
return p.mcp ? new Promise((e, n) => {
|
|
299
311
|
if (!this.socket) {
|
|
300
|
-
|
|
312
|
+
n("socket is undefined");
|
|
301
313
|
return;
|
|
302
314
|
}
|
|
303
|
-
this.socket.emit("add_mcp_servers",
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}), e(!0)) : (
|
|
315
|
+
this.socket.emit("add_mcp_servers", p.mcp, (c) => {
|
|
316
|
+
c.code === 200 ? (Object.keys(c.data).forEach((i) => {
|
|
317
|
+
c.data[i].code !== 200 && a.report(i, "MCP Server 注册失败。", c.data[i]);
|
|
318
|
+
}), a.log("mcp:registered", Object.keys(c.data)), e(!0)) : (a.error("MCP Server 注册失败。", c), n(c));
|
|
307
319
|
});
|
|
308
|
-
}) : Promise.resolve(!0);
|
|
320
|
+
}) : (a.log("mcp:skip"), Promise.resolve(!0));
|
|
309
321
|
}
|
|
310
322
|
registerLocalMcp() {
|
|
311
|
-
var
|
|
323
|
+
var c, i;
|
|
312
324
|
const e = this.socket;
|
|
313
325
|
if (!e)
|
|
314
326
|
return;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
B(), this.stopLocalMcpUpdates || (this.stopLocalMcpUpdates = J(() => this.registerLocalMcp()));
|
|
328
|
+
const n = ++this.localMcpTicket;
|
|
329
|
+
Q({
|
|
330
|
+
arrange: (i = (c = this.application) == null ? void 0 : c.arrange) == null ? void 0 : i[0],
|
|
331
|
+
initMcp: p.mcp,
|
|
332
|
+
apiRoot: p.apiRoot,
|
|
320
333
|
token: this.token,
|
|
321
334
|
socket: e,
|
|
322
|
-
isCurrent: () =>
|
|
323
|
-
}).catch((
|
|
324
|
-
|
|
335
|
+
isCurrent: () => n === this.localMcpTicket
|
|
336
|
+
}).catch((o) => {
|
|
337
|
+
a.report("local mcp", o instanceof Error ? o.message : String(o));
|
|
325
338
|
});
|
|
326
339
|
}
|
|
327
340
|
addMcpServers(e) {
|
|
328
|
-
return
|
|
329
|
-
return this.ready ? this.socket ? new Promise((
|
|
330
|
-
this.socket && this.socket.emit("add_mcp_servers", e, (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}),
|
|
341
|
+
return C(this, null, function* () {
|
|
342
|
+
return this.ready ? this.socket ? new Promise((n, c) => {
|
|
343
|
+
this.socket && this.socket.emit("add_mcp_servers", e, (i) => {
|
|
344
|
+
i.code === 200 ? (Object.keys(i.data).forEach((o) => {
|
|
345
|
+
i.data[o].code !== 200 && a.report(o, "MCP Server 注册失败。", i.data[o]);
|
|
346
|
+
}), a.log("mcp:registered", Object.keys(i.data)), n(!0)) : (a.error("MCP Server 注册失败。", i), c(i));
|
|
334
347
|
});
|
|
335
|
-
}) : (
|
|
348
|
+
}) : (a.error("socket is undefined."), Promise.reject("socket is undefined")) : (a.error("session is not avalible."), Promise.reject("session is not avalible"));
|
|
336
349
|
});
|
|
337
350
|
}
|
|
338
351
|
listMcpServers() {
|
|
339
|
-
return
|
|
340
|
-
return this.ready ? this.socket ? new Promise((e,
|
|
341
|
-
this.socket && this.socket.emit("list_mcp_servers", (
|
|
342
|
-
|
|
352
|
+
return C(this, null, function* () {
|
|
353
|
+
return this.ready ? this.socket ? new Promise((e, n) => {
|
|
354
|
+
this.socket && this.socket.emit("list_mcp_servers", (c) => {
|
|
355
|
+
c.code === 200 ? e(c.data) : n(c);
|
|
343
356
|
});
|
|
344
|
-
}) : (
|
|
357
|
+
}) : (a.error("socket is undefined."), Promise.reject("socket is undefined")) : (a.error("session is not avalible."), Promise.reject("session is not avalible"));
|
|
345
358
|
});
|
|
346
359
|
}
|
|
347
|
-
sendQuestion(e,
|
|
348
|
-
return
|
|
349
|
-
var
|
|
360
|
+
sendQuestion(e, n) {
|
|
361
|
+
return C(this, null, function* () {
|
|
362
|
+
var i;
|
|
350
363
|
this.convertKnowledgesToChatFormat(this.knowledges);
|
|
351
|
-
let
|
|
352
|
-
promptVariables: this.promptVariables.filter((
|
|
353
|
-
[
|
|
364
|
+
let c = y(h({}, e), {
|
|
365
|
+
promptVariables: this.promptVariables.filter((o) => o.type === L.User).reduce((o, s) => y(h({}, o), {
|
|
366
|
+
[s.key]: s.value
|
|
354
367
|
}), {}),
|
|
355
|
-
systemPromptVariables: this.promptVariables.filter((
|
|
356
|
-
[
|
|
368
|
+
systemPromptVariables: this.promptVariables.filter((o) => o.type === L.System).reduce((o, s) => y(h({}, o), {
|
|
369
|
+
[s.key]: s.value
|
|
357
370
|
}), {}),
|
|
358
|
-
knowledges: (
|
|
371
|
+
knowledges: (i = this.knowledges) == null ? void 0 : i.map((o) => o.id),
|
|
359
372
|
//agent支持指定文件时再放开
|
|
360
373
|
// knowledges: knowledgesForChat,
|
|
361
374
|
enableTitleSummary: this.resolveEnableTitleSummary()
|
|
362
375
|
});
|
|
363
376
|
if (!this.active) {
|
|
364
377
|
if (yield this.activate(), !this.socket) {
|
|
365
|
-
const
|
|
366
|
-
|
|
378
|
+
const o = new Error(
|
|
379
|
+
A.SocketConnectionFailed
|
|
367
380
|
// {
|
|
368
381
|
// cause: { code: -1, message: 'socket is null' },
|
|
369
382
|
// }
|
|
370
383
|
);
|
|
371
|
-
return
|
|
384
|
+
return a.warn("error", o), this.event.emit("error", o), !1;
|
|
372
385
|
}
|
|
373
|
-
|
|
386
|
+
this.emitQuestion(c);
|
|
374
387
|
return;
|
|
375
388
|
}
|
|
376
|
-
|
|
389
|
+
this.emitQuestion(c);
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
emitQuestion(e) {
|
|
393
|
+
var n;
|
|
394
|
+
a.log("question:request", Y(e)), (n = this.socket) == null || n.emit("question", e), a.log("question:sent", {
|
|
395
|
+
sessionId: this.id
|
|
377
396
|
});
|
|
378
397
|
}
|
|
379
398
|
/**
|
|
380
399
|
* 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
|
|
381
400
|
* 停止回答或调用被取消后不再回传。
|
|
382
401
|
*/
|
|
383
|
-
invokeClientPlugin(e,
|
|
384
|
-
const
|
|
385
|
-
this.inflightCalls.add(
|
|
402
|
+
invokeClientPlugin(e, n, c, i) {
|
|
403
|
+
const o = new AbortController();
|
|
404
|
+
this.inflightCalls.add(o);
|
|
386
405
|
let s = !1;
|
|
387
|
-
const
|
|
388
|
-
s || (s = !0, this.inflightCalls.delete(
|
|
406
|
+
const t = (...m) => {
|
|
407
|
+
s || (s = !0, this.inflightCalls.delete(o), !(this._stopAnswer || o.signal.aborted) && c(...m));
|
|
389
408
|
}, l = {
|
|
390
|
-
requestId:
|
|
409
|
+
requestId: i.requestId || z(),
|
|
391
410
|
applicationId: this._applicationId,
|
|
392
411
|
sessionId: this.id,
|
|
393
|
-
pluginCode:
|
|
394
|
-
functionCode:
|
|
395
|
-
signal:
|
|
412
|
+
pluginCode: i.pluginCode,
|
|
413
|
+
functionCode: i.functionCode,
|
|
414
|
+
signal: o.signal
|
|
396
415
|
};
|
|
397
416
|
try {
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
417
|
+
const m = e(n, t, l);
|
|
418
|
+
m && typeof m.catch == "function" && m.catch((f) => {
|
|
419
|
+
a.error("client plugin failed", f), t({
|
|
401
420
|
code: 500,
|
|
402
421
|
message: "客户端插件执行失败。"
|
|
403
422
|
});
|
|
404
423
|
});
|
|
405
|
-
} catch (
|
|
406
|
-
|
|
424
|
+
} catch (m) {
|
|
425
|
+
a.error("client plugin failed", m), t({
|
|
407
426
|
code: 500,
|
|
408
427
|
message: "客户端插件执行失败。"
|
|
409
428
|
});
|
|
@@ -411,25 +430,26 @@ class se extends D {
|
|
|
411
430
|
}
|
|
412
431
|
abortClientPluginCalls() {
|
|
413
432
|
const e = Array.from(this.inflightCalls);
|
|
414
|
-
this.inflightCalls.clear(), e.forEach((
|
|
433
|
+
this.inflightCalls.clear(), e.forEach((n) => n.abort());
|
|
415
434
|
}
|
|
416
435
|
stopAnswer() {
|
|
417
436
|
var e;
|
|
418
|
-
this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
|
|
437
|
+
a.log("stopAnswer", this.id), this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
|
|
419
438
|
}
|
|
420
439
|
inactivate(e = !1) {
|
|
421
|
-
return this.abortClientPluginCalls(), super.inactivate(e);
|
|
440
|
+
return !e && this.frozen && !!this.socket || this.abortClientPluginCalls(), super.inactivate(e);
|
|
422
441
|
}
|
|
423
442
|
destroy() {
|
|
424
|
-
|
|
443
|
+
var e;
|
|
444
|
+
return (e = this.stopLocalMcpUpdates) == null || e.call(this), this.stopLocalMcpUpdates = void 0, this.abortClientPluginCalls(), super.destroy();
|
|
425
445
|
}
|
|
426
446
|
convertKnowledgesToChatFormat(e) {
|
|
427
|
-
return e ? e.map((
|
|
428
|
-
id:
|
|
429
|
-
fileIds:
|
|
430
|
-
} :
|
|
447
|
+
return e ? e.map((n) => n != null && n.fileIds ? {
|
|
448
|
+
id: n.id,
|
|
449
|
+
fileIds: n.fileIds
|
|
450
|
+
} : n.id) : [];
|
|
431
451
|
}
|
|
432
452
|
}
|
|
433
453
|
export {
|
|
434
|
-
|
|
454
|
+
oe as default
|
|
435
455
|
};
|