@ynhcj/xiaoyi-channel 0.0.126-beta → 0.0.127-beta
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/src/formatter.js +17 -38
- package/dist/src/websocket.js +0 -1
- package/package.json +1 -1
package/dist/src/formatter.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
// OpenClaw → A2A format conversion
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import { getXYWebSocketManager } from "./client.js";
|
|
4
|
-
import {
|
|
4
|
+
import { logger } from "./utils/logger.js";
|
|
5
5
|
/**
|
|
6
6
|
* Send an A2A artifact update response.
|
|
7
7
|
*/
|
|
8
8
|
export async function sendA2AResponse(params) {
|
|
9
9
|
const { config, sessionId, taskId, messageId, text, append, final, files, errorCode, errorMessage } = params;
|
|
10
|
-
const runtime = getXYRuntime();
|
|
11
|
-
const log = runtime?.log ?? console.log;
|
|
12
|
-
const errorFn = runtime?.error ?? console.error;
|
|
13
10
|
// Build artifact update event
|
|
14
11
|
const artifact = {
|
|
15
12
|
taskId,
|
|
@@ -48,7 +45,7 @@ export async function sendA2AResponse(params) {
|
|
|
48
45
|
code: errorCode,
|
|
49
46
|
message: errorMessage ?? "任务执行异常,请重试",
|
|
50
47
|
};
|
|
51
|
-
log(`[A2A_RESPONSE] ⚠️ Including error code: ${errorCode}`);
|
|
48
|
+
logger.log(`[A2A_RESPONSE] ⚠️ Including error code: ${errorCode}`);
|
|
52
49
|
}
|
|
53
50
|
// Send via WebSocket
|
|
54
51
|
const wsManager = getXYWebSocketManager(config);
|
|
@@ -60,13 +57,13 @@ export async function sendA2AResponse(params) {
|
|
|
60
57
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
61
58
|
};
|
|
62
59
|
// 📋 Log complete response body
|
|
63
|
-
log(`[A2A_RESPONSE] 📤 Sending A2A artifact-update response: taskId: ${taskId}`);
|
|
64
|
-
log(`[A2A_RESPONSE] - append: ${append}`);
|
|
65
|
-
log(`[A2A_RESPONSE] - final: ${final}`);
|
|
66
|
-
log(`[A2A_RESPONSE] - text: ${text.length <= 10 ? text : text.slice(0, 5) + '***' + text.slice(-5)}`);
|
|
67
|
-
log(`[A2A_RESPONSE] - files count: ${files?.length ?? 0}`);
|
|
60
|
+
logger.log(`[A2A_RESPONSE] 📤 Sending A2A artifact-update response: taskId: ${taskId}`);
|
|
61
|
+
logger.log(`[A2A_RESPONSE] - append: ${append}`);
|
|
62
|
+
logger.log(`[A2A_RESPONSE] - final: ${final}`);
|
|
63
|
+
logger.log(`[A2A_RESPONSE] - text: ${text.length <= 10 ? text : text.slice(0, 5) + '***' + text.slice(-5)}`);
|
|
64
|
+
logger.log(`[A2A_RESPONSE] - files count: ${files?.length ?? 0}`);
|
|
68
65
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
69
|
-
log(`[A2A_RESPONSE] ✅ Message sent successfully`);
|
|
66
|
+
logger.log(`[A2A_RESPONSE] ✅ Message sent successfully`);
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
69
|
* Send an A2A artifact-update with reasoningText part.
|
|
@@ -75,9 +72,6 @@ export async function sendA2AResponse(params) {
|
|
|
75
72
|
*/
|
|
76
73
|
export async function sendReasoningTextUpdate(params) {
|
|
77
74
|
const { config, sessionId, taskId, messageId, text, append = true } = params;
|
|
78
|
-
const runtime = getXYRuntime();
|
|
79
|
-
const log = runtime?.log ?? console.log;
|
|
80
|
-
const error = runtime?.error ?? console.error;
|
|
81
75
|
const artifact = {
|
|
82
76
|
taskId,
|
|
83
77
|
kind: "artifact-update",
|
|
@@ -115,9 +109,6 @@ export async function sendReasoningTextUpdate(params) {
|
|
|
115
109
|
*/
|
|
116
110
|
export async function sendStatusUpdate(params) {
|
|
117
111
|
const { config, sessionId, taskId, messageId, text, state } = params;
|
|
118
|
-
const runtime = getXYRuntime();
|
|
119
|
-
const log = runtime?.log ?? console.log;
|
|
120
|
-
const error = runtime?.error ?? console.error;
|
|
121
112
|
// Build status update event following A2A protocol standard
|
|
122
113
|
const statusUpdate = {
|
|
123
114
|
taskId,
|
|
@@ -152,9 +143,9 @@ export async function sendStatusUpdate(params) {
|
|
|
152
143
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
153
144
|
};
|
|
154
145
|
// 📋 Log complete response body
|
|
155
|
-
log(`[A2A_STATUS] 📤 Sending A2A status-update:`);
|
|
156
|
-
log(`[A2A_STATUS] - taskId: ${taskId}`);
|
|
157
|
-
log(`[A2A_STATUS] - text: "${text}"`);
|
|
146
|
+
logger.log(`[A2A_STATUS] 📤 Sending A2A status-update:`);
|
|
147
|
+
logger.log(`[A2A_STATUS] - taskId: ${taskId}`);
|
|
148
|
+
logger.log(`[A2A_STATUS] - text: "${text}"`);
|
|
158
149
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
159
150
|
}
|
|
160
151
|
/**
|
|
@@ -162,9 +153,6 @@ export async function sendStatusUpdate(params) {
|
|
|
162
153
|
*/
|
|
163
154
|
export async function sendCommand(params) {
|
|
164
155
|
const { config, sessionId, taskId, messageId, command } = params;
|
|
165
|
-
const runtime = getXYRuntime();
|
|
166
|
-
const log = runtime?.log ?? console.log;
|
|
167
|
-
const error = runtime?.error ?? console.error;
|
|
168
156
|
// Build artifact update with command as data
|
|
169
157
|
// Wrap command in commands array as per protocol requirement
|
|
170
158
|
const artifact = {
|
|
@@ -201,18 +189,15 @@ export async function sendCommand(params) {
|
|
|
201
189
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
202
190
|
};
|
|
203
191
|
// 📋 Log complete response body
|
|
204
|
-
log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${taskId}`);
|
|
192
|
+
logger.log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${taskId}`);
|
|
205
193
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
206
|
-
log(`[A2A_COMMAND] ✅ Command sent successfully`);
|
|
194
|
+
logger.log(`[A2A_COMMAND] ✅ Command sent successfully`);
|
|
207
195
|
}
|
|
208
196
|
/**
|
|
209
197
|
* Send a clearContext response.
|
|
210
198
|
*/
|
|
211
199
|
export async function sendClearContextResponse(params) {
|
|
212
200
|
const { config, sessionId, messageId } = params;
|
|
213
|
-
const runtime = getXYRuntime();
|
|
214
|
-
const log = runtime?.log ?? console.log;
|
|
215
|
-
const error = runtime?.error ?? console.error;
|
|
216
201
|
// Build JSON-RPC response for clearContext
|
|
217
202
|
const jsonRpcResponse = {
|
|
218
203
|
jsonrpc: "2.0",
|
|
@@ -238,16 +223,13 @@ export async function sendClearContextResponse(params) {
|
|
|
238
223
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
239
224
|
};
|
|
240
225
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
241
|
-
log(`Sent clearContext response: sessionId=${sessionId}`);
|
|
226
|
+
logger.log(`Sent clearContext response: sessionId=${sessionId}`);
|
|
242
227
|
}
|
|
243
228
|
/**
|
|
244
229
|
* Send a tasks/cancel response.
|
|
245
230
|
*/
|
|
246
231
|
export async function sendTasksCancelResponse(params) {
|
|
247
232
|
const { config, sessionId, taskId, messageId } = params;
|
|
248
|
-
const runtime = getXYRuntime();
|
|
249
|
-
const log = runtime?.log ?? console.log;
|
|
250
|
-
const error = runtime?.error ?? console.error;
|
|
251
233
|
// Build JSON-RPC response for tasks/cancel
|
|
252
234
|
// Note: Using any to bypass type check as the response format differs from standard A2A types
|
|
253
235
|
const jsonRpcResponse = {
|
|
@@ -274,16 +256,13 @@ export async function sendTasksCancelResponse(params) {
|
|
|
274
256
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
275
257
|
};
|
|
276
258
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
277
|
-
log(`Sent tasks/cancel response: sessionId=${sessionId}, taskId=${taskId}`);
|
|
259
|
+
logger.log(`Sent tasks/cancel response: sessionId=${sessionId}, taskId=${taskId}`);
|
|
278
260
|
}
|
|
279
261
|
/**
|
|
280
262
|
* Send a Trigger response with pushData content.
|
|
281
263
|
*/
|
|
282
264
|
export async function sendTriggerResponse(params) {
|
|
283
265
|
const { config, sessionId, taskId, messageId, content } = params;
|
|
284
|
-
const runtime = getXYRuntime();
|
|
285
|
-
const log = runtime?.log ?? console.log;
|
|
286
|
-
const error = runtime?.error ?? console.error;
|
|
287
266
|
// Build JSON-RPC response for Trigger
|
|
288
267
|
const jsonRpcResponse = {
|
|
289
268
|
jsonrpc: "2.0",
|
|
@@ -318,7 +297,7 @@ export async function sendTriggerResponse(params) {
|
|
|
318
297
|
taskId,
|
|
319
298
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
320
299
|
};
|
|
321
|
-
log(`[TRIGGER_RESPONSE] Sending Trigger response: sessionId=${sessionId}, taskId=${taskId}`);
|
|
300
|
+
logger.log(`[TRIGGER_RESPONSE] Sending Trigger response: sessionId=${sessionId}, taskId=${taskId}`);
|
|
322
301
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
323
|
-
log(`[TRIGGER_RESPONSE] Trigger response sent successfully`);
|
|
302
|
+
logger.log(`[TRIGGER_RESPONSE] Trigger response sent successfully`);
|
|
324
303
|
}
|
package/dist/src/websocket.js
CHANGED
|
@@ -114,7 +114,6 @@ export class XYWebSocketManager extends EventEmitter {
|
|
|
114
114
|
throw new Error("WebSocket not ready");
|
|
115
115
|
}
|
|
116
116
|
const messageStr = JSON.stringify(message);
|
|
117
|
-
this.log(`[WS-SEND] sessionId=${sessionId} taskId=${message.taskId} msgType=${message.msgType} len=${messageStr.length}`);
|
|
118
117
|
this.ws.send(messageStr);
|
|
119
118
|
}
|
|
120
119
|
/**
|