@ynhcj/xiaoyi-channel 0.0.100-next → 0.0.101-next
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
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { v4 as uuidv4 } from "uuid";
|
|
3
3
|
import { getXYWebSocketManager } from "./client.js";
|
|
4
4
|
import { logger } from "./utils/logger.js";
|
|
5
|
+
import { getCurrentTaskId, getCurrentMessageId } from "./task-manager.js";
|
|
5
6
|
/**
|
|
6
7
|
* Send an A2A artifact update response.
|
|
7
8
|
*/
|
|
@@ -111,9 +112,13 @@ export async function sendReasoningTextUpdate(params) {
|
|
|
111
112
|
export async function sendStatusUpdate(params) {
|
|
112
113
|
const { config, sessionId, taskId, messageId, text, state, runtime } = params;
|
|
113
114
|
const log = runtime?.log ?? console.log;
|
|
115
|
+
// Dynamic lookup: use latest taskId/messageId from task-manager (handles steer/interrupt),
|
|
116
|
+
// fall back to closure-captured values
|
|
117
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
118
|
+
const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
|
|
114
119
|
// Build status update event following A2A protocol standard
|
|
115
120
|
const statusUpdate = {
|
|
116
|
-
taskId,
|
|
121
|
+
taskId: currentTaskId,
|
|
117
122
|
kind: "status-update",
|
|
118
123
|
final: false, // Status updates should not end the stream
|
|
119
124
|
status: {
|
|
@@ -132,7 +137,7 @@ export async function sendStatusUpdate(params) {
|
|
|
132
137
|
// Build JSON-RPC response
|
|
133
138
|
const jsonRpcResponse = {
|
|
134
139
|
jsonrpc: "2.0",
|
|
135
|
-
id:
|
|
140
|
+
id: currentMessageId,
|
|
136
141
|
result: statusUpdate,
|
|
137
142
|
};
|
|
138
143
|
// Send via WebSocket
|
|
@@ -141,12 +146,12 @@ export async function sendStatusUpdate(params) {
|
|
|
141
146
|
msgType: "agent_response",
|
|
142
147
|
agentId: config.agentId,
|
|
143
148
|
sessionId,
|
|
144
|
-
taskId,
|
|
149
|
+
taskId: currentTaskId,
|
|
145
150
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
146
151
|
};
|
|
147
152
|
// 📋 Log complete response body
|
|
148
153
|
log(`[A2A_STATUS] 📤 Sending A2A status-update:`);
|
|
149
|
-
log(`[A2A_STATUS] - taskId: ${
|
|
154
|
+
log(`[A2A_STATUS] - taskId: ${currentTaskId}`);
|
|
150
155
|
log(`[A2A_STATUS] - text: "${text}"`);
|
|
151
156
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
152
157
|
}
|
|
@@ -155,10 +160,14 @@ export async function sendStatusUpdate(params) {
|
|
|
155
160
|
*/
|
|
156
161
|
export async function sendCommand(params) {
|
|
157
162
|
const { config, sessionId, taskId, messageId, command } = params;
|
|
163
|
+
// Dynamic lookup: use latest taskId/messageId from task-manager (handles steer/interrupt),
|
|
164
|
+
// fall back to closure-captured values
|
|
165
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
166
|
+
const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
|
|
158
167
|
// Build artifact update with command as data
|
|
159
168
|
// Wrap command in commands array as per protocol requirement
|
|
160
169
|
const artifact = {
|
|
161
|
-
taskId,
|
|
170
|
+
taskId: currentTaskId,
|
|
162
171
|
kind: "artifact-update",
|
|
163
172
|
append: false,
|
|
164
173
|
lastChunk: true,
|
|
@@ -178,7 +187,7 @@ export async function sendCommand(params) {
|
|
|
178
187
|
// Build JSON-RPC response
|
|
179
188
|
const jsonRpcResponse = {
|
|
180
189
|
jsonrpc: "2.0",
|
|
181
|
-
id:
|
|
190
|
+
id: currentMessageId,
|
|
182
191
|
result: artifact,
|
|
183
192
|
};
|
|
184
193
|
// Send via WebSocket
|
|
@@ -187,11 +196,11 @@ export async function sendCommand(params) {
|
|
|
187
196
|
msgType: "agent_response",
|
|
188
197
|
agentId: config.agentId,
|
|
189
198
|
sessionId,
|
|
190
|
-
taskId,
|
|
199
|
+
taskId: currentTaskId,
|
|
191
200
|
msgDetail: JSON.stringify(jsonRpcResponse),
|
|
192
201
|
};
|
|
193
202
|
// 📋 Log complete response body
|
|
194
|
-
logger.log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${
|
|
203
|
+
logger.log(`[A2A_COMMAND] 📤 Sending A2A command: taskId: ${currentTaskId}`);
|
|
195
204
|
await wsManager.sendMessage(sessionId, outboundMessage);
|
|
196
205
|
logger.log(`[A2A_COMMAND] ✅ Command sent successfully`);
|
|
197
206
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { XYFileUploadService } from "../file-upload.js";
|
|
3
3
|
import { logger } from "../utils/logger.js";
|
|
4
|
+
import { getCurrentTaskId, getCurrentMessageId } from "../task-manager.js";
|
|
4
5
|
import fetch from "node-fetch";
|
|
5
6
|
import fs from "fs/promises";
|
|
6
7
|
import path from "path";
|
|
@@ -122,6 +123,9 @@ b. 操作超时时间为2分钟(120秒),请勿重复调用此工具,如
|
|
|
122
123
|
},
|
|
123
124
|
},
|
|
124
125
|
async execute(toolCallId, params) {
|
|
126
|
+
// Dynamic lookup: use latest taskId/messageId from task-manager (handles steer/interrupt)
|
|
127
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
128
|
+
const currentMessageId = getCurrentMessageId(sessionId) ?? messageId;
|
|
125
129
|
// Set timeout for the entire operation (2 minutes)
|
|
126
130
|
const TOOL_TIMEOUT = 120000; // 2 minutes in milliseconds
|
|
127
131
|
let timeoutHandle = null;
|
|
@@ -211,17 +215,17 @@ b. 操作超时时间为2分钟(120秒),请勿重复调用此工具,如
|
|
|
211
215
|
msgType: "agent_response",
|
|
212
216
|
agentId: config.agentId,
|
|
213
217
|
sessionId: sessionId,
|
|
214
|
-
taskId:
|
|
218
|
+
taskId: currentTaskId,
|
|
215
219
|
msgDetail: JSON.stringify({
|
|
216
220
|
jsonrpc: "2.0",
|
|
217
|
-
id:
|
|
221
|
+
id: currentMessageId,
|
|
218
222
|
result: {
|
|
219
223
|
kind: "artifact-update",
|
|
220
224
|
append: true,
|
|
221
225
|
lastChunk: false,
|
|
222
226
|
final: false,
|
|
223
227
|
artifact: {
|
|
224
|
-
artifactId:
|
|
228
|
+
artifactId: currentTaskId,
|
|
225
229
|
parts: [
|
|
226
230
|
{
|
|
227
231
|
kind: "file",
|
|
@@ -237,7 +241,7 @@ b. 操作超时时间为2分钟(120秒),请勿重复调用此工具,如
|
|
|
237
241
|
error: { code: 0 },
|
|
238
242
|
}),
|
|
239
243
|
};
|
|
240
|
-
logger.log(`[SEND-FILE-TO-USER] 🚀 EXEC sending: sessionId=${sessionId} taskId=${
|
|
244
|
+
logger.log(`[SEND-FILE-TO-USER] 🚀 EXEC sending: sessionId=${sessionId} taskId=${currentTaskId} fileName=${fileName}`);
|
|
241
245
|
// Send WebSocket message
|
|
242
246
|
await wsManager.sendMessage(sessionId, agentResponse);
|
|
243
247
|
logger.log(`send ${fileName} file to user success`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// XiaoYi GUI tool implementation - simulates phone screen interactions
|
|
2
2
|
import { getXYWebSocketManager } from "../client.js";
|
|
3
3
|
import { sendCommand } from "../formatter.js";
|
|
4
|
+
import { getCurrentTaskId } from "../task-manager.js";
|
|
4
5
|
/**
|
|
5
6
|
* XiaoYi GUI tool - executes phone app interactions through GUI agent.
|
|
6
7
|
* Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
|
|
@@ -38,6 +39,8 @@ export function createXiaoyiGuiTool(ctx) {
|
|
|
38
39
|
required: ["query"],
|
|
39
40
|
},
|
|
40
41
|
async execute(toolCallId, params) {
|
|
42
|
+
// Dynamic lookup: use latest taskId from task-manager (handles steer/interrupt)
|
|
43
|
+
const currentTaskId = getCurrentTaskId(sessionId) ?? taskId;
|
|
41
44
|
// Validate parameters
|
|
42
45
|
if (!params.query || typeof params.query !== "string") {
|
|
43
46
|
throw new Error("Missing or invalid required parameter: query must be a non-empty string");
|
|
@@ -53,7 +56,7 @@ export function createXiaoyiGuiTool(ctx) {
|
|
|
53
56
|
payload: {
|
|
54
57
|
query: params.query,
|
|
55
58
|
sessionId: sessionId,
|
|
56
|
-
interactionId:
|
|
59
|
+
interactionId: currentTaskId, // taskId corresponds to interactionId; use dynamic lookup for steer safety
|
|
57
60
|
},
|
|
58
61
|
};
|
|
59
62
|
// Send command and wait for response (5 minute timeout)
|