@ynhcj/xiaoyi-channel 0.0.48-beta → 0.0.48-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/index.d.ts +0 -2
- package/dist/index.js +44 -2
- package/dist/src/bot.d.ts +1 -0
- package/dist/src/bot.js +47 -49
- package/dist/src/channel.js +32 -4
- package/dist/src/client.js +0 -9
- package/dist/src/cspl/call-api.d.ts +3 -0
- package/dist/src/cspl/call-api.js +86 -0
- package/dist/src/cspl/config.d.ts +19 -0
- package/dist/src/cspl/config.js +50 -0
- package/dist/src/cspl/constants.d.ts +43 -0
- package/dist/src/cspl/constants.js +22 -0
- package/dist/src/cspl/utils.d.ts +10 -0
- package/dist/src/cspl/utils.js +57 -0
- package/dist/src/file-upload.js +1 -11
- package/dist/src/formatter.d.ts +2 -0
- package/dist/src/formatter.js +13 -28
- package/dist/src/heartbeat.js +0 -4
- package/dist/src/monitor.js +8 -10
- package/dist/src/onboarding.d.ts +3 -4
- package/dist/src/onboarding.js +2 -2
- package/dist/src/outbound.d.ts +2 -1
- package/dist/src/outbound.js +1 -19
- package/dist/src/parser.d.ts +6 -0
- package/dist/src/parser.js +16 -0
- package/dist/src/provider.d.ts +2 -0
- package/dist/src/provider.js +108 -0
- package/dist/src/push.js +0 -21
- package/dist/src/reply-dispatcher.d.ts +4 -0
- package/dist/src/reply-dispatcher.js +46 -6
- package/dist/src/steer-injector.d.ts +16 -0
- package/dist/src/steer-injector.js +74 -0
- package/dist/src/thread-bindings.d.ts +54 -0
- package/dist/src/thread-bindings.js +214 -0
- package/dist/src/tools/calendar-tool.js +2 -37
- package/dist/src/tools/call-phone-tool.js +3 -60
- package/dist/src/tools/create-alarm-tool.js +6 -81
- package/dist/src/tools/delete-alarm-tool.js +3 -45
- package/dist/src/tools/device-tool-map.d.ts +4 -0
- package/dist/src/tools/device-tool-map.js +36 -0
- package/dist/src/tools/image-reading-tool.js +24 -49
- package/dist/src/tools/location-tool.js +1 -32
- package/dist/src/tools/modify-alarm-tool.js +6 -84
- package/dist/src/tools/modify-note-tool.js +1 -34
- package/dist/src/tools/note-tool.js +2 -4
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +5 -0
- package/dist/src/tools/save-media-to-gallery-tool.js +178 -0
- package/dist/src/tools/search-alarm-tool.js +3 -61
- package/dist/src/tools/search-calendar-tool.js +2 -39
- package/dist/src/tools/search-contact-tool.js +0 -30
- package/dist/src/tools/search-file-tool.js +0 -33
- package/dist/src/tools/search-message-tool.js +0 -33
- package/dist/src/tools/search-note-tool.js +1 -26
- package/dist/src/tools/search-photo-gallery-tool.js +2 -31
- package/dist/src/tools/send-command-to-car-tool.d.ts +5 -0
- package/dist/src/tools/send-command-to-car-tool.js +85 -0
- package/dist/src/tools/send-file-to-user-tool.js +1 -39
- package/dist/src/tools/send-message-tool.js +1 -39
- package/dist/src/tools/session-manager.d.ts +1 -0
- package/dist/src/tools/session-manager.js +0 -45
- package/dist/src/tools/timestamp-to-utc8-tool.d.ts +12 -0
- package/dist/src/tools/timestamp-to-utc8-tool.js +104 -0
- package/dist/src/tools/upload-file-tool.js +2 -51
- package/dist/src/tools/upload-photo-tool.js +0 -42
- package/dist/src/tools/view-push-result-tool.js +0 -11
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +4 -0
- package/dist/src/tools/xiaoyi-add-collection-tool.js +173 -0
- package/dist/src/tools/xiaoyi-collection-tool.js +46 -89
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +4 -0
- package/dist/src/tools/xiaoyi-delete-collection-tool.js +163 -0
- package/dist/src/tools/xiaoyi-gui-tool.js +0 -34
- package/dist/src/utils/runtime-manager.d.ts +7 -0
- package/dist/src/utils/runtime-manager.js +42 -0
- package/dist/src/websocket.js +33 -13
- package/openclaw.plugin.json +1 -0
- package/package.json +3 -4
- package/dist/src/tools/search-photo-tool.d.ts +0 -9
- package/dist/src/tools/search-photo-tool.js +0 -270
- package/dist/src/utils/session.d.ts +0 -34
- package/dist/src/utils/session.js +0 -50
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Device type to tool name mapping.
|
|
2
|
+
// Supports two modes:
|
|
3
|
+
// - allowlist: only listed tools are available (used for restrictive devices like car)
|
|
4
|
+
// - denylist: listed tools are blocked, everything else is available (used for permissive devices like pc)
|
|
5
|
+
// Tools NOT listed in any device entry → available to all devices (no restriction).
|
|
6
|
+
/** Known device type enum. */
|
|
7
|
+
export const DEVICE_TYPES = ["car", "2in1", "phone"];
|
|
8
|
+
const DEVICE_TOOL_POLICY = {
|
|
9
|
+
"2in1": {
|
|
10
|
+
allowlist: false,
|
|
11
|
+
tools: [
|
|
12
|
+
"xiaoyi_gui_agent",
|
|
13
|
+
"call_phone",
|
|
14
|
+
"send_message",
|
|
15
|
+
"search_message",
|
|
16
|
+
"send_command_to_car",
|
|
17
|
+
"search_contact",
|
|
18
|
+
"QueryCollection",
|
|
19
|
+
"AddCollection",
|
|
20
|
+
"DeleteCollection",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export function filterToolsByDevice(tools, deviceType) {
|
|
25
|
+
if (!deviceType)
|
|
26
|
+
return tools;
|
|
27
|
+
const policy = DEVICE_TOOL_POLICY[deviceType];
|
|
28
|
+
if (!policy)
|
|
29
|
+
return tools; // unrecognized device → no filtering
|
|
30
|
+
if (policy.allowlist) {
|
|
31
|
+
return tools.filter((tool) => policy.tools.includes(tool.name));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return tools.filter((tool) => !policy.tools.includes(tool.name));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Image Reading tool implementation
|
|
2
2
|
import { XYFileUploadService } from "../file-upload.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
5
4
|
import fetch from "node-fetch";
|
|
6
5
|
import fs from "fs/promises";
|
|
7
6
|
import path from "path";
|
|
@@ -34,7 +33,6 @@ async function isLocalFile(value) {
|
|
|
34
33
|
* Download remote file to local temp directory
|
|
35
34
|
*/
|
|
36
35
|
async function downloadRemoteFile(url) {
|
|
37
|
-
logger.log(`[IMAGE_READING_TOOL] 📥 Downloading remote file: ${url}`);
|
|
38
36
|
try {
|
|
39
37
|
const response = await fetch(url);
|
|
40
38
|
if (!response.ok) {
|
|
@@ -56,11 +54,9 @@ async function downloadRemoteFile(url) {
|
|
|
56
54
|
const arrayBuffer = await response.arrayBuffer();
|
|
57
55
|
const buffer = Buffer.from(arrayBuffer);
|
|
58
56
|
await fs.writeFile(localPath, buffer);
|
|
59
|
-
logger.log(`[IMAGE_READING_TOOL] ✅ File downloaded to: ${localPath}`);
|
|
60
57
|
return localPath;
|
|
61
58
|
}
|
|
62
59
|
catch (error) {
|
|
63
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ Failed to download file from ${url}:`, error);
|
|
64
60
|
throw new Error(`Failed to download remote file: ${error instanceof Error ? error.message : String(error)}`);
|
|
65
61
|
}
|
|
66
62
|
}
|
|
@@ -68,22 +64,22 @@ async function downloadRemoteFile(url) {
|
|
|
68
64
|
* Process image input: validate and convert local file to OBS URL, keep remote URL unchanged
|
|
69
65
|
*/
|
|
70
66
|
async function processImageInput(imageInput, uploadService) {
|
|
71
|
-
logger.log(`[IMAGE_READING_TOOL] 🔄 Processing image input: ${imageInput}`);
|
|
72
67
|
// Check if it's a remote URL
|
|
73
68
|
if (isRemoteUrl(imageInput)) {
|
|
74
|
-
logger.log(`[IMAGE_READING_TOOL] 🌐 Input is remote URL, downloading...`);
|
|
75
69
|
const localPath = await downloadRemoteFile(imageInput);
|
|
76
|
-
logger.log(`[IMAGE_READING_TOOL] 📤 Uploading downloaded file to OBS...`);
|
|
77
70
|
const imageUrl = await uploadService.uploadFileAndGetUrl(localPath, "TEMPORARY_MATERIAL_DOC");
|
|
78
|
-
|
|
71
|
+
if (!imageUrl) {
|
|
72
|
+
throw new Error("图片上传失败:无法获取图片访问地址");
|
|
73
|
+
}
|
|
79
74
|
return { imageUrl, localPath };
|
|
80
75
|
}
|
|
81
76
|
// Check if it's a local file
|
|
82
77
|
const isLocal = await isLocalFile(imageInput);
|
|
83
78
|
if (isLocal) {
|
|
84
|
-
logger.log(`[IMAGE_READING_TOOL] 📁 Input is local file, uploading...`);
|
|
85
79
|
const imageUrl = await uploadService.uploadFileAndGetUrl(imageInput, "TEMPORARY_MATERIAL_DOC");
|
|
86
|
-
|
|
80
|
+
if (!imageUrl) {
|
|
81
|
+
throw new Error("图片上传失败:无法获取图片访问地址");
|
|
82
|
+
}
|
|
87
83
|
return { imageUrl };
|
|
88
84
|
}
|
|
89
85
|
throw new Error(`Invalid image input: must be a remote URL or local file path, got: ${imageInput}`);
|
|
@@ -91,11 +87,8 @@ async function processImageInput(imageInput, uploadService) {
|
|
|
91
87
|
/**
|
|
92
88
|
* Call image understanding API with streaming response
|
|
93
89
|
*/
|
|
94
|
-
async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid) {
|
|
95
|
-
|
|
96
|
-
logger.log(`[IMAGE_READING_TOOL] - imageUrl: ${imageUrl}`);
|
|
97
|
-
logger.log(`[IMAGE_READING_TOOL] - prompt: ${text}`);
|
|
98
|
-
const apiUrl = "https://hag-drcn.op.dbankcloud.com/celia-claw/v1/sse-api/skill/execute";
|
|
90
|
+
async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid, fileUploadUrl) {
|
|
91
|
+
const apiUrl = `${fileUploadUrl}/celia-claw/v1/sse-api/skill/execute`;
|
|
99
92
|
const traceId = uuidv4();
|
|
100
93
|
const headers = {
|
|
101
94
|
"Content-Type": "application/json",
|
|
@@ -141,7 +134,6 @@ async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid) {
|
|
|
141
134
|
},
|
|
142
135
|
],
|
|
143
136
|
};
|
|
144
|
-
logger.log(`[IMAGE_READING_TOOL] 📡 Sending request with trace ID: ${traceId}`);
|
|
145
137
|
try {
|
|
146
138
|
const response = await fetch(apiUrl, {
|
|
147
139
|
method: "POST",
|
|
@@ -150,19 +142,14 @@ async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid) {
|
|
|
150
142
|
// @ts-ignore - node-fetch supports this
|
|
151
143
|
timeout: 120000, // 2 minutes timeout
|
|
152
144
|
});
|
|
153
|
-
logger.log(`[IMAGE_READING_TOOL] 📨 Response status: ${response.status}`);
|
|
154
|
-
logger.log(`[IMAGE_READING_TOOL] 📨 Content-Type: ${response.headers.get("Content-Type")}`);
|
|
155
145
|
if (!response.ok) {
|
|
156
146
|
const errorText = await response.text();
|
|
157
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ API request failed: ${response.status}`);
|
|
158
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ Response: ${errorText}`);
|
|
159
147
|
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
|
160
148
|
}
|
|
161
149
|
// Process SSE stream
|
|
162
150
|
let lastCaption = "";
|
|
163
151
|
let lineCount = 0;
|
|
164
152
|
let buffer = "";
|
|
165
|
-
logger.log(`[IMAGE_READING_TOOL] 📖 Reading SSE stream...`);
|
|
166
153
|
// Read the response body as a stream
|
|
167
154
|
if (!response.body) {
|
|
168
155
|
throw new Error("Response body is null");
|
|
@@ -190,29 +177,23 @@ async function callImageUnderstandingAPI(imageUrl, text, apiKey, uid) {
|
|
|
190
177
|
const streamContent = info.actionExecutorResult.reply.streamInfo.streamContent;
|
|
191
178
|
if (streamContent) {
|
|
192
179
|
lastCaption = streamContent;
|
|
193
|
-
logger.log(`[IMAGE_READING_TOOL] 📝 Updated caption (length: ${streamContent.length})`);
|
|
194
180
|
}
|
|
195
181
|
}
|
|
196
182
|
}
|
|
197
183
|
}
|
|
198
184
|
}
|
|
199
185
|
catch (parseError) {
|
|
200
|
-
logger.warn(`[IMAGE_READING_TOOL] ⚠️ Failed to parse JSON data:`, parseError);
|
|
201
186
|
}
|
|
202
187
|
}
|
|
203
188
|
}
|
|
204
189
|
}
|
|
205
190
|
}
|
|
206
|
-
logger.log(`[IMAGE_READING_TOOL] ✅ Stream processing complete`);
|
|
207
|
-
logger.log(`[IMAGE_READING_TOOL] - Total lines processed: ${lineCount}`);
|
|
208
|
-
logger.log(`[IMAGE_READING_TOOL] - Final caption length: ${lastCaption.length}`);
|
|
209
191
|
if (!lastCaption) {
|
|
210
192
|
throw new Error("No caption received from image understanding API");
|
|
211
193
|
}
|
|
212
194
|
return lastCaption;
|
|
213
195
|
}
|
|
214
196
|
catch (error) {
|
|
215
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ API call failed:`, error);
|
|
216
197
|
throw error;
|
|
217
198
|
}
|
|
218
199
|
}
|
|
@@ -270,26 +251,17 @@ d. 返回图像理解的文本描述内容`,
|
|
|
270
251
|
},
|
|
271
252
|
},
|
|
272
253
|
async execute(toolCallId, params) {
|
|
273
|
-
logger.log(`[IMAGE_READING_TOOL] 🚀 Starting execution`);
|
|
274
|
-
logger.log(`[IMAGE_READING_TOOL] - toolCallId: ${toolCallId}`);
|
|
275
|
-
logger.log(`[IMAGE_READING_TOOL] - params:`, JSON.stringify(params));
|
|
276
|
-
logger.log(`[IMAGE_READING_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
277
254
|
// Validate that at least one parameter is provided
|
|
278
255
|
if (!params.localUrl && !params.remoteUrl) {
|
|
279
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ Missing both localUrl and remoteUrl parameters`);
|
|
280
256
|
throw new Error("At least one of localUrl or remoteUrl must be provided");
|
|
281
257
|
}
|
|
282
258
|
// Get prompt (default to "描述这张图片内容")
|
|
283
259
|
const prompt = params.prompt || "描述这张图片内容";
|
|
284
|
-
logger.log(`[IMAGE_READING_TOOL] 📝 Using prompt: ${prompt}`);
|
|
285
260
|
// Get session context
|
|
286
|
-
logger.log(`[IMAGE_READING_TOOL] 🔍 Getting session context...`);
|
|
287
261
|
const sessionContext = getCurrentSessionContext();
|
|
288
262
|
if (!sessionContext) {
|
|
289
|
-
logger.error(`[IMAGE_READING_TOOL] ❌ No active session found!`);
|
|
290
263
|
throw new Error("No active XY session found. Image reading tool can only be used during an active conversation.");
|
|
291
264
|
}
|
|
292
|
-
logger.log(`[IMAGE_READING_TOOL] ✅ Session context found`);
|
|
293
265
|
const { config } = sessionContext;
|
|
294
266
|
// Create upload service
|
|
295
267
|
const uploadService = new XYFileUploadService(config.fileUploadUrl, config.apiKey, config.uid);
|
|
@@ -298,27 +270,19 @@ d. 返回图像理解的文本描述内容`,
|
|
|
298
270
|
try {
|
|
299
271
|
// Process image input (prefer localUrl over remoteUrl)
|
|
300
272
|
const imageInput = params.localUrl || params.remoteUrl;
|
|
301
|
-
logger.log(`[IMAGE_READING_TOOL] 🖼️ Processing image: ${imageInput}`);
|
|
302
273
|
processedImage = await processImageInput(imageInput, uploadService);
|
|
303
274
|
// Track downloaded file for cleanup
|
|
304
275
|
if (processedImage.localPath) {
|
|
305
276
|
downloadedFile = processedImage.localPath;
|
|
306
277
|
}
|
|
307
|
-
logger.log(`[IMAGE_READING_TOOL] ✅ Image processed successfully`);
|
|
308
|
-
logger.log(`[IMAGE_READING_TOOL] - OBS URL: ${processedImage.imageUrl}`);
|
|
309
278
|
// Call image understanding API
|
|
310
|
-
const caption = await callImageUnderstandingAPI(processedImage.imageUrl, prompt, config.apiKey, config.uid);
|
|
311
|
-
logger.log(`[IMAGE_READING_TOOL] 🎉 Image understanding completed successfully`);
|
|
312
|
-
logger.log(`[IMAGE_READING_TOOL] - Caption length: ${caption.length} characters`);
|
|
279
|
+
const caption = await callImageUnderstandingAPI(processedImage.imageUrl, prompt, config.apiKey, config.uid, config.fileUploadUrl);
|
|
313
280
|
// Clean up downloaded file if any
|
|
314
281
|
if (downloadedFile) {
|
|
315
|
-
logger.log(`[IMAGE_READING_TOOL] 🧹 Cleaning up downloaded file...`);
|
|
316
282
|
try {
|
|
317
283
|
await fs.unlink(downloadedFile);
|
|
318
|
-
logger.log(`[IMAGE_READING_TOOL] ✅ Cleaned up: ${downloadedFile}`);
|
|
319
284
|
}
|
|
320
285
|
catch (error) {
|
|
321
|
-
logger.warn(`[IMAGE_READING_TOOL] ⚠️ Failed to clean up file:`, error);
|
|
322
286
|
}
|
|
323
287
|
}
|
|
324
288
|
return {
|
|
@@ -338,16 +302,27 @@ d. 返回图像理解的文本描述内容`,
|
|
|
338
302
|
catch (error) {
|
|
339
303
|
// Clean up downloaded file on error
|
|
340
304
|
if (downloadedFile) {
|
|
341
|
-
logger.log(`[IMAGE_READING_TOOL] 🧹 Cleaning up downloaded file after error...`);
|
|
342
305
|
try {
|
|
343
306
|
await fs.unlink(downloadedFile);
|
|
344
307
|
}
|
|
345
308
|
catch (cleanupError) {
|
|
346
|
-
logger.warn(`[IMAGE_READING_TOOL] ⚠️ Failed to clean up file:`, cleanupError);
|
|
347
309
|
}
|
|
348
310
|
}
|
|
349
|
-
|
|
350
|
-
|
|
311
|
+
const errorMessage = error instanceof Error ? error.message : "图片分析失败";
|
|
312
|
+
// Return error result instead of throwing
|
|
313
|
+
return {
|
|
314
|
+
content: [
|
|
315
|
+
{
|
|
316
|
+
type: "text",
|
|
317
|
+
text: JSON.stringify({
|
|
318
|
+
error: errorMessage,
|
|
319
|
+
prompt,
|
|
320
|
+
imageSource: params.localUrl ? "local" : "remote",
|
|
321
|
+
success: false,
|
|
322
|
+
}),
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
};
|
|
351
326
|
}
|
|
352
327
|
},
|
|
353
328
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getXYWebSocketManager } from "../client.js";
|
|
2
2
|
import { sendCommand } from "../formatter.js";
|
|
3
3
|
import { getCurrentSessionContext } from "./session-manager.js";
|
|
4
|
-
import { logger } from "../utils/logger.js";
|
|
5
4
|
/**
|
|
6
5
|
* XY location tool - gets user's current location.
|
|
7
6
|
* Returns WGS84 coordinates (latitude, longitude).
|
|
@@ -9,38 +8,22 @@ import { logger } from "../utils/logger.js";
|
|
|
9
8
|
export const locationTool = {
|
|
10
9
|
name: "get_user_location",
|
|
11
10
|
label: "Get User Location",
|
|
12
|
-
description: "获取用户当前位置(经纬度坐标,WGS84坐标系)。需要用户设备授权位置访问权限。注意:操作超时时间为60
|
|
11
|
+
description: "获取用户当前位置(经纬度坐标,WGS84坐标系)。需要用户设备授权位置访问权限。注意:操作超时时间为60秒,请勿重复调用此工具,如果超时或失败,最多重试一次。回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。",
|
|
13
12
|
parameters: {
|
|
14
13
|
type: "object",
|
|
15
14
|
properties: {},
|
|
16
15
|
required: [],
|
|
17
16
|
},
|
|
18
17
|
async execute(toolCallId, params) {
|
|
19
|
-
logger.log(`[LOCATION_TOOL] 🚀 Starting execution`);
|
|
20
|
-
logger.log(`[LOCATION_TOOL] - toolCallId: ${toolCallId}`);
|
|
21
|
-
logger.log(`[LOCATION_TOOL] - params:`, JSON.stringify(params));
|
|
22
|
-
logger.log(`[LOCATION_TOOL] - timestamp: ${new Date().toISOString()}`);
|
|
23
18
|
// Get session context
|
|
24
|
-
logger.log(`[LOCATION_TOOL] 🔍 Attempting to get session context...`);
|
|
25
19
|
const sessionContext = getCurrentSessionContext();
|
|
26
20
|
if (!sessionContext) {
|
|
27
|
-
logger.error(`[LOCATION_TOOL] ❌ FAILED: No active session found!`);
|
|
28
|
-
logger.error(`[LOCATION_TOOL] - toolCallId: ${toolCallId}`);
|
|
29
|
-
logger.error(`[LOCATION_TOOL] - This suggests the session was not registered or already cleaned up`);
|
|
30
21
|
throw new Error("No active XY session found. Location tool can only be used during an active conversation.");
|
|
31
22
|
}
|
|
32
|
-
logger.log(`[LOCATION_TOOL] ✅ Session context found`);
|
|
33
|
-
logger.log(`[LOCATION_TOOL] - sessionId: ${sessionContext.sessionId}`);
|
|
34
|
-
logger.log(`[LOCATION_TOOL] - taskId: ${sessionContext.taskId}`);
|
|
35
|
-
logger.log(`[LOCATION_TOOL] - messageId: ${sessionContext.messageId}`);
|
|
36
|
-
logger.log(`[LOCATION_TOOL] - agentId: ${sessionContext.agentId}`);
|
|
37
23
|
const { config, sessionId, taskId, messageId } = sessionContext;
|
|
38
24
|
// Get WebSocket manager
|
|
39
|
-
logger.log(`[LOCATION_TOOL] 🔌 Getting WebSocket manager...`);
|
|
40
25
|
const wsManager = getXYWebSocketManager(config);
|
|
41
|
-
logger.log(`[LOCATION_TOOL] ✅ WebSocket manager obtained`);
|
|
42
26
|
// Build GetCurrentLocation command
|
|
43
|
-
logger.log(`[LOCATION_TOOL] 📦 Building GetCurrentLocation command...`);
|
|
44
27
|
const command = {
|
|
45
28
|
header: {
|
|
46
29
|
namespace: "Common",
|
|
@@ -72,25 +55,17 @@ export const locationTool = {
|
|
|
72
55
|
},
|
|
73
56
|
};
|
|
74
57
|
// Send command and wait for response (60 second timeout)
|
|
75
|
-
logger.log(`[LOCATION_TOOL] ⏳ Setting up promise to wait for location response...`);
|
|
76
|
-
logger.log(`[LOCATION_TOOL] - Timeout: 60 seconds`);
|
|
77
58
|
return new Promise((resolve, reject) => {
|
|
78
59
|
const timeout = setTimeout(() => {
|
|
79
|
-
logger.error(`[LOCATION_TOOL] ⏰ Timeout: No response received within 60 seconds`);
|
|
80
60
|
wsManager.off("data-event", handler);
|
|
81
61
|
reject(new Error("获取位置超时(60秒)"));
|
|
82
62
|
}, 60000);
|
|
83
63
|
// Listen for data events from WebSocket
|
|
84
64
|
const handler = (event) => {
|
|
85
|
-
logger.log(`[LOCATION_TOOL] 📨 Received data event:`, JSON.stringify(event));
|
|
86
65
|
if (event.intentName === "GetCurrentLocation") {
|
|
87
|
-
logger.log(`[LOCATION_TOOL] 🎯 GetCurrentLocation event received`);
|
|
88
|
-
logger.log(`[LOCATION_TOOL] - status: ${event.status}`);
|
|
89
66
|
clearTimeout(timeout);
|
|
90
67
|
wsManager.off("data-event", handler);
|
|
91
68
|
if (event.status === "success" && event.outputs) {
|
|
92
|
-
logger.log(`[LOCATION_TOOL] ✅ Location retrieved successfully`);
|
|
93
|
-
logger.log(`[LOCATION_TOOL] - outputs:`, JSON.stringify(event.outputs));
|
|
94
69
|
// 成功,直接返回完整的 event.outputs JSON 字符串
|
|
95
70
|
resolve({
|
|
96
71
|
content: [
|
|
@@ -102,18 +77,14 @@ export const locationTool = {
|
|
|
102
77
|
});
|
|
103
78
|
}
|
|
104
79
|
else {
|
|
105
|
-
logger.error(`[LOCATION_TOOL] ❌ Location retrieval failed`);
|
|
106
|
-
logger.error(`[LOCATION_TOOL] - status: ${event.status}`);
|
|
107
80
|
reject(new Error(`获取位置失败: ${event.status}`));
|
|
108
81
|
}
|
|
109
82
|
}
|
|
110
83
|
};
|
|
111
84
|
// Register event handler
|
|
112
85
|
// Note: The WebSocket manager needs to emit 'data-event' when receiving data events
|
|
113
|
-
logger.log(`[LOCATION_TOOL] 📡 Registering data-event handler on WebSocket manager`);
|
|
114
86
|
wsManager.on("data-event", handler);
|
|
115
87
|
// Send the command
|
|
116
|
-
logger.log(`[LOCATION_TOOL] 📤 Sending GetCurrentLocation command...`);
|
|
117
88
|
sendCommand({
|
|
118
89
|
config,
|
|
119
90
|
sessionId,
|
|
@@ -121,9 +92,7 @@ export const locationTool = {
|
|
|
121
92
|
messageId,
|
|
122
93
|
command,
|
|
123
94
|
}).then(() => {
|
|
124
|
-
logger.log(`[LOCATION_TOOL] ✅ Command sent successfully, waiting for response...`);
|
|
125
95
|
}).catch((error) => {
|
|
126
|
-
logger.error(`[LOCATION_TOOL] ❌ Failed to send command:`, error);
|
|
127
96
|
clearTimeout(timeout);
|
|
128
97
|
wsManager.off("data-event", handler);
|
|
129
98
|
reject(error);
|