@ynhcj/xiaoyi-channel 0.0.51-beta → 0.0.53-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.
Files changed (46) hide show
  1. package/dist/index.d.ts +0 -2
  2. package/dist/index.js +0 -2
  3. package/dist/src/bot.js +0 -16
  4. package/dist/src/channel.js +16 -2
  5. package/dist/src/client.js +0 -2
  6. package/dist/src/cspl/call-api.js +30 -2
  7. package/dist/src/cspl/constants.d.ts +1 -1
  8. package/dist/src/cspl/constants.js +1 -1
  9. package/dist/src/formatter.js +3 -23
  10. package/dist/src/heartbeat.js +0 -1
  11. package/dist/src/onboarding.d.ts +3 -4
  12. package/dist/src/onboarding.js +2 -2
  13. package/dist/src/outbound.d.ts +2 -1
  14. package/dist/src/reply-dispatcher.js +38 -2
  15. package/dist/src/thread-bindings.d.ts +54 -0
  16. package/dist/src/thread-bindings.js +214 -0
  17. package/dist/src/tools/calendar-tool.js +2 -37
  18. package/dist/src/tools/call-phone-tool.js +1 -42
  19. package/dist/src/tools/create-alarm-tool.js +3 -74
  20. package/dist/src/tools/delete-alarm-tool.js +3 -45
  21. package/dist/src/tools/image-reading-tool.js +0 -47
  22. package/dist/src/tools/location-tool.js +1 -32
  23. package/dist/src/tools/modify-alarm-tool.js +3 -77
  24. package/dist/src/tools/modify-note-tool.js +1 -34
  25. package/dist/src/tools/note-tool.js +2 -4
  26. package/dist/src/tools/search-alarm-tool.js +3 -61
  27. package/dist/src/tools/search-calendar-tool.js +2 -39
  28. package/dist/src/tools/search-contact-tool.js +0 -30
  29. package/dist/src/tools/search-file-tool.js +0 -33
  30. package/dist/src/tools/search-message-tool.js +0 -33
  31. package/dist/src/tools/search-note-tool.js +1 -26
  32. package/dist/src/tools/search-photo-gallery-tool.js +2 -31
  33. package/dist/src/tools/send-file-to-user-tool.js +0 -39
  34. package/dist/src/tools/send-message-tool.js +1 -39
  35. package/dist/src/tools/session-manager.js +0 -45
  36. package/dist/src/tools/upload-file-tool.js +0 -49
  37. package/dist/src/tools/upload-photo-tool.js +0 -42
  38. package/dist/src/tools/view-push-result-tool.js +0 -11
  39. package/dist/src/tools/xiaoyi-collection-tool.js +4 -82
  40. package/dist/src/tools/xiaoyi-gui-tool.js +0 -34
  41. package/dist/src/websocket.js +24 -8
  42. package/package.json +2 -2
  43. package/dist/src/tools/search-photo-tool.d.ts +0 -9
  44. package/dist/src/tools/search-photo-tool.js +0 -270
  45. package/dist/src/utils/session.d.ts +0 -34
  46. package/dist/src/utils/session.js +0 -50
@@ -2,7 +2,6 @@
2
2
  import { getXYWebSocketManager } from "../client.js";
3
3
  import { sendCommand } from "../formatter.js";
4
4
  import { getCurrentSessionContext } from "./session-manager.js";
5
- import { logger } from "../utils/logger.js";
6
5
  /**
7
6
  * XiaoYi GUI tool - executes phone app interactions through GUI agent.
8
7
  * Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
@@ -38,35 +37,19 @@ export const xiaoyiGuiTool = {
38
37
  required: ["query"],
39
38
  },
40
39
  async execute(toolCallId, params) {
41
- logger.log(`[XIAOYI_GUI_TOOL] 🚀 Starting execution`);
42
- logger.log(`[XIAOYI_GUI_TOOL] - toolCallId: ${toolCallId}`);
43
- logger.log(`[XIAOYI_GUI_TOOL] - query: ${params.query}`);
44
- logger.log(`[XIAOYI_GUI_TOOL] - timestamp: ${new Date().toISOString()}`);
45
40
  // Validate parameters
46
41
  if (!params.query || typeof params.query !== "string") {
47
- logger.error(`[XIAOYI_GUI_TOOL] ❌ FAILED: Invalid query parameter`);
48
42
  throw new Error("Missing or invalid required parameter: query must be a non-empty string");
49
43
  }
50
44
  // Get session context
51
- logger.log(`[XIAOYI_GUI_TOOL] 🔍 Attempting to get session context...`);
52
45
  const sessionContext = getCurrentSessionContext();
53
46
  if (!sessionContext) {
54
- logger.error(`[XIAOYI_GUI_TOOL] ❌ FAILED: No active session found!`);
55
- logger.error(`[XIAOYI_GUI_TOOL] - toolCallId: ${toolCallId}`);
56
47
  throw new Error("No active XY session found. XiaoYi GUI tool can only be used during an active conversation.");
57
48
  }
58
- logger.log(`[XIAOYI_GUI_TOOL] ✅ Session context found`);
59
- logger.log(`[XIAOYI_GUI_TOOL] - sessionId: ${sessionContext.sessionId}`);
60
- logger.log(`[XIAOYI_GUI_TOOL] - taskId (interactionId): ${sessionContext.taskId}`);
61
- logger.log(`[XIAOYI_GUI_TOOL] - messageId: ${sessionContext.messageId}`);
62
- logger.log(`[XIAOYI_GUI_TOOL] - agentId: ${sessionContext.agentId}`);
63
49
  const { config, sessionId, taskId, messageId } = sessionContext;
64
50
  // Get WebSocket manager
65
- logger.log(`[XIAOYI_GUI_TOOL] 🔌 Getting WebSocket manager...`);
66
51
  const wsManager = getXYWebSocketManager(config);
67
- logger.log(`[XIAOYI_GUI_TOOL] ✅ WebSocket manager obtained`);
68
52
  // Build InvokeJarvisGUIAgentRequest command
69
- logger.log(`[XIAOYI_GUI_TOOL] 📦 Building InvokeJarvisGUIAgentRequest command...`);
70
53
  const command = {
71
54
  header: {
72
55
  namespace: "ClawAgent",
@@ -78,32 +61,23 @@ export const xiaoyiGuiTool = {
78
61
  interactionId: taskId, // taskId corresponds to interactionId
79
62
  },
80
63
  };
81
- logger.log(`[XIAOYI_GUI_TOOL] 📋 Command details:`, JSON.stringify(command, null, 2));
82
64
  // Send command and wait for response (5 minute timeout)
83
- logger.log(`[XIAOYI_GUI_TOOL] ⏳ Setting up promise to wait for GUI agent response...`);
84
- logger.log(`[XIAOYI_GUI_TOOL] - Timeout: 300 seconds (5 minutes)`);
85
65
  return new Promise((resolve, reject) => {
86
66
  const timeout = setTimeout(() => {
87
- logger.error(`[XIAOYI_GUI_TOOL] ⏰ Timeout: No response received within 300 seconds (5 minutes)`);
88
67
  wsManager.off("gui-agent-response", handler);
89
68
  reject(new Error("XiaoYi GUI Agent 操作超时(5分钟)"));
90
69
  }, 180000); // 5 minutes timeout
91
70
  // Listen for GUI agent response events
92
71
  const handler = (event) => {
93
- logger.log(`[XIAOYI_GUI_TOOL] 📨 Received event:`, JSON.stringify(event));
94
72
  // Check if this is the InvokeJarvisGUIAgentResponse we're waiting for
95
73
  if (event.header?.namespace === "ClawAgent" &&
96
74
  event.header?.name === "InvokeJarvisGUIAgentResponse") {
97
- logger.log(`[XIAOYI_GUI_TOOL] 🎯 InvokeJarvisGUIAgentResponse event received`);
98
- logger.log(`[XIAOYI_GUI_TOOL] - isFinal: ${event.payload?.isFinal}`);
99
75
  // According to the spec, we only get one response (isFinal: true)
100
76
  if (event.payload?.isFinal === true) {
101
77
  clearTimeout(timeout);
102
78
  wsManager.off("gui-agent-response", handler);
103
79
  const streamContent = event.payload?.streamInfo?.streamContent;
104
80
  if (streamContent) {
105
- logger.log(`[XIAOYI_GUI_TOOL] ✅ GUI Agent operation completed successfully`);
106
- logger.log(`[XIAOYI_GUI_TOOL] - streamContent: ${streamContent}`);
107
81
  resolve({
108
82
  content: [
109
83
  {
@@ -114,23 +88,18 @@ export const xiaoyiGuiTool = {
114
88
  });
115
89
  }
116
90
  else {
117
- logger.error(`[XIAOYI_GUI_TOOL] ❌ Response missing streamContent`);
118
- logger.error(`[XIAOYI_GUI_TOOL] - payload:`, JSON.stringify(event.payload));
119
91
  reject(new Error("XiaoYi GUI Agent 响应格式错误:缺少 streamContent"));
120
92
  }
121
93
  }
122
94
  else if (event.payload?.isFinal === false) {
123
95
  // According to spec, we shouldn't get intermediate responses, but log if we do
124
- logger.log(`[XIAOYI_GUI_TOOL] 📝 Intermediate response received (isFinal: false), waiting for final...`);
125
96
  }
126
97
  }
127
98
  };
128
99
  // Register event handler
129
100
  // Note: The WebSocket manager needs to emit 'gui-agent-response' when receiving this type of response
130
- logger.log(`[XIAOYI_GUI_TOOL] 📡 Registering gui-agent-response handler on WebSocket manager`);
131
101
  wsManager.on("gui-agent-response", handler);
132
102
  // Send the command
133
- logger.log(`[XIAOYI_GUI_TOOL] 📤 Sending InvokeJarvisGUIAgentRequest command...`);
134
103
  sendCommand({
135
104
  config,
136
105
  sessionId,
@@ -138,10 +107,7 @@ export const xiaoyiGuiTool = {
138
107
  messageId,
139
108
  command,
140
109
  }).then(() => {
141
- logger.log(`[XIAOYI_GUI_TOOL] ✅ Command sent successfully, waiting for response...`);
142
- logger.log(`[XIAOYI_GUI_TOOL] - This may take up to 5 minutes depending on the task complexity`);
143
110
  }).catch((error) => {
144
- logger.error(`[XIAOYI_GUI_TOOL] ❌ Failed to send command:`, error);
145
111
  clearTimeout(timeout);
146
112
  wsManager.off("gui-agent-response", handler);
147
113
  reject(error);
@@ -323,24 +323,40 @@ export class XYWebSocketManager extends EventEmitter {
323
323
  const messageStr = data.toString();
324
324
  console.log(`[WS-RECV] Raw message frame, size: ${messageStr.length} bytes`);
325
325
  const parsed = JSON.parse(messageStr);
326
- console.log("[WS-RECV] Parsed message:", JSON.stringify(parsed, null, 2));
326
+ // 提取并打印消息内容(只显示 text,data 只打印提示)
327
+ const parts = parsed.params?.message?.parts;
328
+ if (parts && Array.isArray(parts) && parts.length > 0) {
329
+ const textParts = parts.filter((p) => p?.kind === "text");
330
+ const dataParts = parts.filter((p) => p?.kind === "data");
331
+ // 打印 text 内容
332
+ if (textParts.length > 0) {
333
+ const textContents = textParts
334
+ .map((p) => p?.text || "")
335
+ .filter((text) => text.length > 0)
336
+ .join(" ");
337
+ if (textContents.length > 0) {
338
+ console.log("[WS-RECV] Text:", textContents);
339
+ }
340
+ }
341
+ // 打印 data 提示
342
+ if (dataParts.length > 0) {
343
+ console.log("[WS-RECV] Data: received data message(s)");
344
+ }
345
+ }
327
346
  // Check if message is in direct A2A JSON-RPC format (server push)
328
347
  if (parsed.jsonrpc === "2.0") {
329
348
  const a2aRequest = parsed;
330
- console.log(`[XY] Message type: Direct A2A JSON-RPC, method: ${a2aRequest.method}`);
331
349
  // Extract sessionId from params
332
350
  const sessionId = a2aRequest.params?.sessionId;
333
351
  if (!sessionId) {
334
352
  console.error("[XY] Message missing sessionId");
335
353
  return;
336
354
  }
337
- console.log(`[XY] Session ID: ${sessionId}`);
338
355
  // Check if message contains only data parts (tool results)
339
356
  const dataParts = a2aRequest.params?.message?.parts?.filter((p) => p.kind === "data");
340
357
  const hasOnlyDataParts = dataParts && dataParts.length > 0 &&
341
358
  dataParts.length === a2aRequest.params?.message?.parts?.length;
342
359
  if (hasOnlyDataParts) {
343
- console.log("[XY] Message contains only data parts, processing as tool result");
344
360
  for (const dataPart of dataParts) {
345
361
  const events = dataPart.data?.events;
346
362
  if (!Array.isArray(events)) {
@@ -355,11 +371,11 @@ export class XYWebSocketManager extends EventEmitter {
355
371
  outputs: item.payload.outputs || {},
356
372
  status: "success",
357
373
  };
358
- console.log("[XY] Emitting data-event:", dataEvent);
374
+ console.log(`[XY] Emitting data-event, intentName: ${item.payload.intentName}, size: ${JSON.stringify(dataEvent).length} bytes`);
359
375
  this.emit("data-event", dataEvent);
360
376
  }
361
377
  else if (item.header?.namespace === "ClawAgent" && item.header?.name === "InvokeJarvisGUIAgentResponse") {
362
- console.log("[XY] Emitting gui-agent-response:", item);
378
+ console.log(`[XY] Emitting gui-agent-response, size: ${JSON.stringify(item).length} bytes`);
363
379
  this.emit("gui-agent-response", item);
364
380
  }
365
381
  else if (item.header?.namespace === "Common" && item.header?.name === "Trigger") {
@@ -410,11 +426,11 @@ export class XYWebSocketManager extends EventEmitter {
410
426
  outputs: item.payload.outputs || {},
411
427
  status: "success",
412
428
  };
413
- console.log("[XY] Emitting data-event:", dataEvent);
429
+ console.log(`[XY] Emitting data-event, intentName: ${item.payload.intentName}, size: ${JSON.stringify(dataEvent).length} bytes`);
414
430
  this.emit("data-event", dataEvent);
415
431
  }
416
432
  else if (item.header?.namespace === "ClawAgent" && item.header?.name === "InvokeJarvisGUIAgentResponse") {
417
- console.log("[XY] Emitting gui-agent-response:", item);
433
+ console.log(`[XY] Emitting gui-agent-response, size: ${JSON.stringify(item).length} bytes`);
418
434
  this.emit("gui-agent-response", item);
419
435
  }
420
436
  else if (item.header?.namespace === "Common" && item.header?.name === "Trigger") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.51-beta",
3
+ "version": "0.0.53-beta",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -49,7 +49,7 @@
49
49
  }
50
50
  },
51
51
  "peerDependencies": {
52
- "openclaw": ">=2026.3.1"
52
+ "openclaw": ">=2026.3.24"
53
53
  },
54
54
  "peerDependenciesMeta": {
55
55
  "openclaw": {
@@ -1,9 +0,0 @@
1
- /**
2
- * XY search photo tool - searches photos in user's gallery.
3
- * Returns publicly accessible URLs of matching photos based on query description.
4
- *
5
- * This tool performs a two-step operation:
6
- * 1. Search for photos using query description
7
- * 2. Upload found photos to get publicly accessible URLs
8
- */
9
- export declare const searchPhotoTool: any;
@@ -1,270 +0,0 @@
1
- import { getXYWebSocketManager } from "../client.js";
2
- import { sendCommand } from "../formatter.js";
3
- import { getLatestSessionContext } from "./session-manager.js";
4
- import { logger } from "../utils/logger.js";
5
- /**
6
- * XY search photo tool - searches photos in user's gallery.
7
- * Returns publicly accessible URLs of matching photos based on query description.
8
- *
9
- * This tool performs a two-step operation:
10
- * 1. Search for photos using query description
11
- * 2. Upload found photos to get publicly accessible URLs
12
- */
13
- export const searchPhotoTool = {
14
- name: "search_photo",
15
- label: "Search Photo",
16
- description: "搜索用户手机图库中的照片。根据图像描述语料检索匹配的照片,并返回照片的可公网访问URL。注意:操作超时时间为120秒,请勿重复调用此工具,如果超时或失败,最多重试一次。",
17
- parameters: {
18
- type: "object",
19
- properties: {
20
- query: {
21
- type: "string",
22
- description: "图像描述语料,用于检索匹配的照片(例如:'小狗的照片'、'带有键盘的图片'等)",
23
- },
24
- },
25
- required: ["query"],
26
- },
27
- async execute(toolCallId, params) {
28
- logger.log(`[SEARCH_PHOTO_TOOL] 🚀 Starting execution`);
29
- logger.log(`[SEARCH_PHOTO_TOOL] - toolCallId: ${toolCallId}`);
30
- logger.log(`[SEARCH_PHOTO_TOOL] - params:`, JSON.stringify(params));
31
- logger.log(`[SEARCH_PHOTO_TOOL] - timestamp: ${new Date().toISOString()}`);
32
- // Validate parameters
33
- if (!params.query) {
34
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ Missing required parameter: query`);
35
- throw new Error("Missing required parameter: query is required");
36
- }
37
- // Get session context
38
- logger.log(`[SEARCH_PHOTO_TOOL] 🔍 Attempting to get session context...`);
39
- const sessionContext = getLatestSessionContext();
40
- if (!sessionContext) {
41
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ FAILED: No active session found!`);
42
- logger.error(`[SEARCH_PHOTO_TOOL] - toolCallId: ${toolCallId}`);
43
- throw new Error("No active XY session found. Search photo tool can only be used during an active conversation.");
44
- }
45
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ Session context found`);
46
- logger.log(`[SEARCH_PHOTO_TOOL] - sessionId: ${sessionContext.sessionId}`);
47
- logger.log(`[SEARCH_PHOTO_TOOL] - taskId: ${sessionContext.taskId}`);
48
- logger.log(`[SEARCH_PHOTO_TOOL] - messageId: ${sessionContext.messageId}`);
49
- const { config, sessionId, taskId, messageId } = sessionContext;
50
- // Get WebSocket manager
51
- logger.log(`[SEARCH_PHOTO_TOOL] 🔌 Getting WebSocket manager...`);
52
- const wsManager = getXYWebSocketManager(config);
53
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ WebSocket manager obtained`);
54
- // Step 1: Search for photos
55
- logger.log(`[SEARCH_PHOTO_TOOL] 📸 STEP 1: Searching for photos...`);
56
- const mediaUris = await searchPhotos(wsManager, config, sessionId, taskId, messageId, params.query);
57
- if (!mediaUris || mediaUris.length === 0) {
58
- logger.warn(`[SEARCH_PHOTO_TOOL] ⚠️ No photos found for query: ${params.query}`);
59
- return {
60
- content: [
61
- {
62
- type: "text",
63
- text: JSON.stringify({ imageUrls: [], message: "未找到匹配的照片" }),
64
- },
65
- ],
66
- };
67
- }
68
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ Found ${mediaUris.length} photos`);
69
- logger.log(`[SEARCH_PHOTO_TOOL] - mediaUris:`, JSON.stringify(mediaUris));
70
- // Step 2: Get public URLs for the photos
71
- logger.log(`[SEARCH_PHOTO_TOOL] 🌐 STEP 2: Getting public URLs for photos...`);
72
- const imageUrls = await getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris);
73
- logger.log(`[SEARCH_PHOTO_TOOL] 🎉 Successfully retrieved ${imageUrls.length} photo URLs`);
74
- return {
75
- content: [
76
- {
77
- type: "text",
78
- text: JSON.stringify({ imageUrls }),
79
- },
80
- ],
81
- };
82
- },
83
- };
84
- /**
85
- * Step 1: Search for photos using query description
86
- * Returns array of mediaUri strings
87
- */
88
- async function searchPhotos(wsManager, config, sessionId, taskId, messageId, query) {
89
- logger.log(`[SEARCH_PHOTO_TOOL] 📦 Building SearchPhotoVideo command...`);
90
- const command = {
91
- header: {
92
- namespace: "Common",
93
- name: "Action",
94
- },
95
- payload: {
96
- cardParam: {},
97
- executeParam: {
98
- executeMode: "background",
99
- intentName: "SearchPhotoVideo",
100
- bundleName: "com.huawei.hmos.aidispatchservice",
101
- needUnlock: true,
102
- actionResponse: true,
103
- appType: "OHOS_APP",
104
- timeOut: 5,
105
- intentParam: {
106
- query: query,
107
- },
108
- permissionId: [],
109
- achieveType: "INTENT",
110
- },
111
- responses: [
112
- {
113
- resultCode: "",
114
- displayText: "",
115
- ttsText: "",
116
- },
117
- ],
118
- needUploadResult: true,
119
- noHalfPage: false,
120
- pageControlRelated: false,
121
- },
122
- };
123
- return new Promise((resolve, reject) => {
124
- const timeout = setTimeout(() => {
125
- logger.error(`[SEARCH_PHOTO_TOOL] ⏰ Timeout: No response for SearchPhotoVideo within 60 seconds`);
126
- wsManager.off("data-event", handler);
127
- reject(new Error("搜索照片超时(60秒)"));
128
- }, 60000);
129
- const handler = (event) => {
130
- logger.log(`[SEARCH_PHOTO_TOOL] 📨 Received data event (Step 1):`, JSON.stringify(event));
131
- if (event.intentName === "SearchPhotoVideo") {
132
- logger.log(`[SEARCH_PHOTO_TOOL] 🎯 SearchPhotoVideo event received`);
133
- logger.log(`[SEARCH_PHOTO_TOOL] - status: ${event.status}`);
134
- clearTimeout(timeout);
135
- wsManager.off("data-event", handler);
136
- if (event.status === "success" && event.outputs) {
137
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ Photo search completed successfully`);
138
- const result = event.outputs.result;
139
- const items = result?.items || [];
140
- // Extract mediaUri from each item
141
- const mediaUris = items.map((item) => item.mediaUri).filter(Boolean);
142
- logger.log(`[SEARCH_PHOTO_TOOL] 📊 Extracted ${mediaUris.length} mediaUris`);
143
- resolve(mediaUris);
144
- }
145
- else {
146
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ Photo search failed`);
147
- logger.error(`[SEARCH_PHOTO_TOOL] - status: ${event.status}`);
148
- reject(new Error(`搜索照片失败: ${event.status}`));
149
- }
150
- }
151
- };
152
- logger.log(`[SEARCH_PHOTO_TOOL] 📡 Registering data-event handler for SearchPhotoVideo`);
153
- wsManager.on("data-event", handler);
154
- logger.log(`[SEARCH_PHOTO_TOOL] 📤 Sending SearchPhotoVideo command...`);
155
- sendCommand({
156
- config,
157
- sessionId,
158
- taskId,
159
- messageId,
160
- command,
161
- })
162
- .then(() => {
163
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ SearchPhotoVideo command sent successfully`);
164
- })
165
- .catch((error) => {
166
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ Failed to send SearchPhotoVideo command:`, error);
167
- clearTimeout(timeout);
168
- wsManager.off("data-event", handler);
169
- reject(error);
170
- });
171
- });
172
- }
173
- /**
174
- * Step 2: Get public URLs for photos using mediaUris
175
- * Returns array of publicly accessible image URLs
176
- */
177
- async function getPhotoUrls(wsManager, config, sessionId, taskId, messageId, mediaUris) {
178
- logger.log(`[SEARCH_PHOTO_TOOL] 📦 Building ImageUploadForClaw command...`);
179
- // Build imageInfos array from mediaUris
180
- const imageInfos = mediaUris.map(mediaUri => ({ mediaUri }));
181
- const command = {
182
- header: {
183
- namespace: "Common",
184
- name: "Action",
185
- },
186
- payload: {
187
- cardParam: {},
188
- executeParam: {
189
- executeMode: "background",
190
- intentName: "ImageUploadForClaw",
191
- bundleName: "com.huawei.hmos.vassistant",
192
- needUnlock: true,
193
- actionResponse: true,
194
- appType: "OHOS_APP",
195
- timeOut: 5,
196
- intentParam: {
197
- imageInfos: imageInfos,
198
- },
199
- permissionId: [],
200
- achieveType: "INTENT",
201
- },
202
- responses: [
203
- {
204
- resultCode: "",
205
- displayText: "",
206
- ttsText: "",
207
- },
208
- ],
209
- needUploadResult: true,
210
- noHalfPage: false,
211
- pageControlRelated: false,
212
- },
213
- };
214
- return new Promise((resolve, reject) => {
215
- const timeout = setTimeout(() => {
216
- logger.error(`[SEARCH_PHOTO_TOOL] ⏰ Timeout: No response for ImageUploadForClaw within 60 seconds`);
217
- wsManager.off("data-event", handler);
218
- reject(new Error("获取照片URL超时(60秒)"));
219
- }, 60000);
220
- const handler = (event) => {
221
- logger.log(`[SEARCH_PHOTO_TOOL] 📨 Received data event (Step 2):`, JSON.stringify(event));
222
- if (event.intentName === "ImageUploadForClaw") {
223
- logger.log(`[SEARCH_PHOTO_TOOL] 🎯 ImageUploadForClaw event received`);
224
- logger.log(`[SEARCH_PHOTO_TOOL] - status: ${event.status}`);
225
- clearTimeout(timeout);
226
- wsManager.off("data-event", handler);
227
- if (event.status === "success" && event.outputs) {
228
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ Image URL retrieval completed successfully`);
229
- const result = event.outputs.result;
230
- let imageUrls = result?.imageUrls || [];
231
- // Decode Unicode escape sequences in URLs
232
- // Replace \u003d with = and \u0026 with &
233
- imageUrls = imageUrls.map((url) => {
234
- const decodedUrl = url
235
- .replace(/\\u003d/g, '=')
236
- .replace(/\\u0026/g, '&');
237
- logger.log(`[SEARCH_PHOTO_TOOL] 🔄 Decoded URL: ${url} -> ${decodedUrl}`);
238
- return decodedUrl;
239
- });
240
- logger.log(`[SEARCH_PHOTO_TOOL] 📊 Retrieved and decoded ${imageUrls.length} image URLs`);
241
- resolve(imageUrls);
242
- }
243
- else {
244
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ Image URL retrieval failed`);
245
- logger.error(`[SEARCH_PHOTO_TOOL] - status: ${event.status}`);
246
- reject(new Error(`获取照片URL失败: ${event.status}`));
247
- }
248
- }
249
- };
250
- logger.log(`[SEARCH_PHOTO_TOOL] 📡 Registering data-event handler for ImageUploadForClaw`);
251
- wsManager.on("data-event", handler);
252
- logger.log(`[SEARCH_PHOTO_TOOL] 📤 Sending ImageUploadForClaw command...`);
253
- sendCommand({
254
- config,
255
- sessionId,
256
- taskId,
257
- messageId,
258
- command,
259
- })
260
- .then(() => {
261
- logger.log(`[SEARCH_PHOTO_TOOL] ✅ ImageUploadForClaw command sent successfully`);
262
- })
263
- .catch((error) => {
264
- logger.error(`[SEARCH_PHOTO_TOOL] ❌ Failed to send ImageUploadForClaw command:`, error);
265
- clearTimeout(timeout);
266
- wsManager.off("data-event", handler);
267
- reject(error);
268
- });
269
- });
270
- }
@@ -1,34 +0,0 @@
1
- import type { SessionBinding, ServerIdentifier } from "../types.js";
2
- /**
3
- * Session-to-server binding cache.
4
- * Tracks which WebSocket server each session is bound to.
5
- */
6
- declare class SessionManager {
7
- private bindings;
8
- /**
9
- * Bind a session to a specific server.
10
- */
11
- bind(sessionId: string, server: ServerIdentifier): void;
12
- /**
13
- * Get the server binding for a session.
14
- */
15
- getBinding(sessionId: string): ServerIdentifier | null;
16
- /**
17
- * Check if a session is bound to a server.
18
- */
19
- isBound(sessionId: string): boolean;
20
- /**
21
- * Unbind a session.
22
- */
23
- unbind(sessionId: string): void;
24
- /**
25
- * Clear all bindings.
26
- */
27
- clear(): void;
28
- /**
29
- * Get all bindings.
30
- */
31
- getAll(): SessionBinding[];
32
- }
33
- export declare const sessionManager: SessionManager;
34
- export {};
@@ -1,50 +0,0 @@
1
- /**
2
- * Session-to-server binding cache.
3
- * Tracks which WebSocket server each session is bound to.
4
- */
5
- class SessionManager {
6
- bindings = new Map();
7
- /**
8
- * Bind a session to a specific server.
9
- */
10
- bind(sessionId, server) {
11
- this.bindings.set(sessionId, {
12
- sessionId,
13
- server,
14
- boundAt: Date.now(),
15
- });
16
- }
17
- /**
18
- * Get the server binding for a session.
19
- */
20
- getBinding(sessionId) {
21
- const binding = this.bindings.get(sessionId);
22
- return binding ? binding.server : null;
23
- }
24
- /**
25
- * Check if a session is bound to a server.
26
- */
27
- isBound(sessionId) {
28
- return this.bindings.has(sessionId);
29
- }
30
- /**
31
- * Unbind a session.
32
- */
33
- unbind(sessionId) {
34
- this.bindings.delete(sessionId);
35
- }
36
- /**
37
- * Clear all bindings.
38
- */
39
- clear() {
40
- this.bindings.clear();
41
- }
42
- /**
43
- * Get all bindings.
44
- */
45
- getAll() {
46
- return Array.from(this.bindings.values());
47
- }
48
- }
49
- // Singleton instance
50
- export const sessionManager = new SessionManager();