@ynhcj/xiaoyi-channel 0.0.122-beta → 0.0.124-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 (94) hide show
  1. package/dist/src/channel.js +2 -17
  2. package/dist/src/client.js +7 -1
  3. package/dist/src/monitor.js +10 -1
  4. package/dist/src/provider.js +9 -5
  5. package/dist/src/task-manager.js +6 -1
  6. package/dist/src/tools/calendar-tool.d.ts +2 -1
  7. package/dist/src/tools/calendar-tool.js +112 -116
  8. package/dist/src/tools/call-device-tool.d.ts +2 -1
  9. package/dist/src/tools/call-device-tool.js +126 -103
  10. package/dist/src/tools/call-phone-tool.d.ts +2 -1
  11. package/dist/src/tools/call-phone-tool.js +109 -113
  12. package/dist/src/tools/create-alarm-tool.d.ts +2 -1
  13. package/dist/src/tools/create-alarm-tool.js +227 -231
  14. package/dist/src/tools/create-all-tools.d.ts +16 -0
  15. package/dist/src/tools/create-all-tools.js +50 -0
  16. package/dist/src/tools/delete-alarm-tool.d.ts +2 -1
  17. package/dist/src/tools/delete-alarm-tool.js +131 -135
  18. package/dist/src/tools/get-alarm-tool-schema.d.ts +2 -1
  19. package/dist/src/tools/get-alarm-tool-schema.js +16 -10
  20. package/dist/src/tools/get-calendar-tool-schema.d.ts +2 -1
  21. package/dist/src/tools/get-calendar-tool-schema.js +12 -8
  22. package/dist/src/tools/get-collection-tool-schema.d.ts +2 -1
  23. package/dist/src/tools/get-collection-tool-schema.js +11 -9
  24. package/dist/src/tools/get-contact-tool-schema.d.ts +2 -1
  25. package/dist/src/tools/get-contact-tool-schema.js +16 -10
  26. package/dist/src/tools/get-device-file-tool-schema.d.ts +2 -1
  27. package/dist/src/tools/get-device-file-tool-schema.js +13 -9
  28. package/dist/src/tools/get-email-tool-schema.d.ts +2 -1
  29. package/dist/src/tools/get-email-tool-schema.js +11 -8
  30. package/dist/src/tools/get-note-tool-schema.d.ts +2 -1
  31. package/dist/src/tools/get-note-tool-schema.js +14 -9
  32. package/dist/src/tools/get-photo-tool-schema.d.ts +2 -1
  33. package/dist/src/tools/get-photo-tool-schema.js +12 -9
  34. package/dist/src/tools/image-reading-tool.d.ts +2 -1
  35. package/dist/src/tools/image-reading-tool.js +86 -90
  36. package/dist/src/tools/location-tool.d.ts +2 -1
  37. package/dist/src/tools/location-tool.js +87 -91
  38. package/dist/src/tools/login-token-tool.d.ts +2 -1
  39. package/dist/src/tools/login-token-tool.js +113 -116
  40. package/dist/src/tools/modify-alarm-tool.d.ts +2 -1
  41. package/dist/src/tools/modify-alarm-tool.js +232 -236
  42. package/dist/src/tools/modify-note-tool.d.ts +2 -1
  43. package/dist/src/tools/modify-note-tool.js +104 -108
  44. package/dist/src/tools/note-tool.d.ts +2 -1
  45. package/dist/src/tools/note-tool.js +103 -107
  46. package/dist/src/tools/query-app-message-tool.d.ts +2 -1
  47. package/dist/src/tools/query-app-message-tool.js +108 -111
  48. package/dist/src/tools/query-memory-data-tool.d.ts +2 -1
  49. package/dist/src/tools/query-memory-data-tool.js +109 -112
  50. package/dist/src/tools/query-todo-task-tool.d.ts +2 -1
  51. package/dist/src/tools/query-todo-task-tool.js +103 -106
  52. package/dist/src/tools/save-file-to-phone-tool.d.ts +2 -1
  53. package/dist/src/tools/save-file-to-phone-tool.js +127 -131
  54. package/dist/src/tools/save-media-to-gallery-tool.d.ts +2 -1
  55. package/dist/src/tools/save-media-to-gallery-tool.js +134 -138
  56. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +2 -1
  57. package/dist/src/tools/save-self-evolution-skill-tool.js +194 -196
  58. package/dist/src/tools/search-alarm-tool.d.ts +2 -1
  59. package/dist/src/tools/search-alarm-tool.js +171 -175
  60. package/dist/src/tools/search-calendar-tool.d.ts +2 -1
  61. package/dist/src/tools/search-calendar-tool.js +145 -149
  62. package/dist/src/tools/search-contact-tool.d.ts +2 -1
  63. package/dist/src/tools/search-contact-tool.js +98 -102
  64. package/dist/src/tools/search-email-tool.d.ts +2 -1
  65. package/dist/src/tools/search-email-tool.js +107 -111
  66. package/dist/src/tools/search-file-tool.d.ts +2 -1
  67. package/dist/src/tools/search-file-tool.js +99 -103
  68. package/dist/src/tools/search-message-tool.d.ts +2 -1
  69. package/dist/src/tools/search-message-tool.js +100 -104
  70. package/dist/src/tools/search-note-tool.d.ts +2 -1
  71. package/dist/src/tools/search-note-tool.js +95 -99
  72. package/dist/src/tools/search-photo-gallery-tool.d.ts +2 -1
  73. package/dist/src/tools/search-photo-gallery-tool.js +34 -38
  74. package/dist/src/tools/send-email-tool.d.ts +2 -1
  75. package/dist/src/tools/send-email-tool.js +105 -108
  76. package/dist/src/tools/send-file-to-user-tool.d.ts +2 -1
  77. package/dist/src/tools/send-file-to-user-tool.js +151 -155
  78. package/dist/src/tools/send-message-tool.d.ts +2 -1
  79. package/dist/src/tools/send-message-tool.js +119 -123
  80. package/dist/src/tools/session-manager.d.ts +21 -6
  81. package/dist/src/tools/session-manager.js +129 -18
  82. package/dist/src/tools/upload-file-tool.d.ts +2 -1
  83. package/dist/src/tools/upload-file-tool.js +78 -82
  84. package/dist/src/tools/upload-photo-tool.d.ts +2 -1
  85. package/dist/src/tools/upload-photo-tool.js +69 -73
  86. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +2 -1
  87. package/dist/src/tools/xiaoyi-add-collection-tool.js +143 -147
  88. package/dist/src/tools/xiaoyi-collection-tool.d.ts +2 -1
  89. package/dist/src/tools/xiaoyi-collection-tool.js +111 -115
  90. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +2 -1
  91. package/dist/src/tools/xiaoyi-delete-collection-tool.js +124 -128
  92. package/dist/src/tools/xiaoyi-gui-tool.d.ts +2 -1
  93. package/dist/src/tools/xiaoyi-gui-tool.js +84 -88
  94. package/package.json +1 -1
@@ -1,24 +1,9 @@
1
1
  import { resolveXYConfig, listXYAccountIds, getDefaultXYAccountId } from "./config.js";
2
2
  import { xyConfigSchema } from "./config-schema.js";
3
3
  import { xyOutbound } from "./outbound.js";
4
- import { locationTool } from "./tools/location-tool.js";
5
- import { xiaoyiGuiTool } from "./tools/xiaoyi-gui-tool.js";
6
- import { sendFileToUserTool } from "./tools/send-file-to-user-tool.js";
7
- import { viewPushResultTool } from "./tools/view-push-result-tool.js";
8
- import { imageReadingTool } from "./tools/image-reading-tool.js";
9
- import { timestampToUtc8Tool } from "./tools/timestamp-to-utc8-tool.js";
10
- import { saveSelfEvolutionSkillTool } from "./tools/save-self-evolution-skill-tool.js";
11
- import { callDeviceTool } from "./tools/call-device-tool.js";
12
- import { getNoteToolSchemaTool } from "./tools/get-note-tool-schema.js";
13
- import { getCalendarToolSchemaTool } from "./tools/get-calendar-tool-schema.js";
14
- import { getContactToolSchemaTool } from "./tools/get-contact-tool-schema.js";
15
- import { getPhotoToolSchemaTool } from "./tools/get-photo-tool-schema.js";
16
- import { getDeviceFileToolSchemaTool } from "./tools/get-device-file-tool-schema.js";
17
- import { getAlarmToolSchemaTool } from "./tools/get-alarm-tool-schema.js";
18
- import { getCollectionToolSchemaTool } from "./tools/get-collection-tool-schema.js";
19
- import { loginTokenTool } from "./tools/login-token-tool.js";
20
4
  import { filterToolsByDevice } from "./tools/device-tool-map.js";
21
5
  import { getCurrentSessionContext } from "./tools/session-manager.js";
6
+ import { createAllTools } from "./tools/create-all-tools.js";
22
7
  import { logger } from "./utils/logger.js";
23
8
  /**
24
9
  * Xiaoyi Channel Plugin for OpenClaw.
@@ -59,8 +44,8 @@ export const xyPlugin = {
59
44
  },
60
45
  outbound: xyOutbound,
61
46
  agentTools: () => {
62
- const allTools = [locationTool, callDeviceTool, getNoteToolSchemaTool, getCalendarToolSchemaTool, getContactToolSchemaTool, getPhotoToolSchemaTool, xiaoyiGuiTool, getDeviceFileToolSchemaTool, getAlarmToolSchemaTool, getCollectionToolSchemaTool, sendFileToUserTool, viewPushResultTool, imageReadingTool, timestampToUtc8Tool, saveSelfEvolutionSkillTool, loginTokenTool];
63
47
  const ctx = getCurrentSessionContext();
48
+ const allTools = createAllTools(ctx);
64
49
  const filtered = filterToolsByDevice(allTools, ctx?.deviceType);
65
50
  logger.log(`[DEVICE-FILTER] deviceType=${ctx?.deviceType ?? "(none)"}, tools: ${allTools.length} → ${filtered.length} (${filtered.map(t => t.name).join(", ")})`);
66
51
  return filtered;
@@ -12,8 +12,14 @@ export function setClientRuntime(rt) {
12
12
  /**
13
13
  * Global cache for WebSocket managers.
14
14
  * Key format: `${apiKey}-${agentId}`
15
+ * Uses globalThis to ensure a single cache across all module copies
16
+ * (same fix as session-manager.ts for openclaw multi-instance loading).
15
17
  */
16
- const wsManagerCache = new Map();
18
+ const _g = globalThis;
19
+ if (!_g.__xyWsManagerCache) {
20
+ _g.__xyWsManagerCache = new Map();
21
+ }
22
+ const wsManagerCache = _g.__xyWsManagerCache;
17
23
  /**
18
24
  * Get or create a WebSocket manager for the given configuration.
19
25
  * Reuses existing managers if config matches.
@@ -8,6 +8,7 @@ import { handleTriggerEvent } from "./trigger-handler.js";
8
8
  import { handleSelfEvolutionEvent, handleSelfEvolutionStateGetEvent } from "./self-evolution-handler.js";
9
9
  import { handleLoginTokenEvent } from "./login-token-handler.js";
10
10
  import { cleanupStaleTempFiles } from "./reply-dispatcher.js";
11
+ import { cleanupStaleSessions, getActiveSessionCount, cleanupAllSessions } from "./tools/session-manager.js";
11
12
  /**
12
13
  * Per-session serial queue that ensures messages from the same session are processed
13
14
  * in arrival order while allowing different sessions to run concurrently.
@@ -198,9 +199,11 @@ export async function monitorXYProvider(opts = {}) {
198
199
  wsManager.disconnect();
199
200
  // ✅ Remove manager from cache to prevent reusing dirty state
200
201
  removeXYWebSocketManager(account);
202
+ // Clean up all active sessions
203
+ cleanupAllSessions();
201
204
  loggedServers.clear();
202
205
  activeMessages.clear();
203
- log(`[MONITOR-HANDLER] 🧹 Cleanup complete, cleared active messages`);
206
+ log(`[MONITOR-HANDLER] 🧹 Cleanup complete, cleared active messages and sessions`);
204
207
  // 🔍 Diagnose after cleanup
205
208
  console.log("🔍 [DIAGNOSTICS] Checking WebSocket managers after cleanup...");
206
209
  diagnoseAllManagers();
@@ -264,6 +267,12 @@ export async function monitorXYProvider(opts = {}) {
264
267
  if (cleaned > 0) {
265
268
  console.log(`🧹 [HEALTH CHECK] Auto-cleaned ${cleaned} manager(s) with orphan connections`);
266
269
  }
270
+ // Cleanup stale sessions (older than 10min TTL)
271
+ const cleanedSessions = cleanupStaleSessions();
272
+ const remainingSessions = getActiveSessionCount();
273
+ if (cleanedSessions > 0 || remainingSessions > 0) {
274
+ console.log(`🧹 [HEALTH CHECK] Sessions: cleaned=${cleanedSessions}, active=${remainingSessions}`);
275
+ }
267
276
  // Cleanup stale temp files (older than 24 hours)
268
277
  void cleanupStaleTempFiles();
269
278
  }, 6 * 60 * 60 * 1000); // 6 hours
@@ -230,6 +230,8 @@ const HEADER_SESSION_ID = "x-session-id";
230
230
  const HEADER_INTERACTION_ID = "x-interaction-id";
231
231
  /** Internal key for passing fallback uid prefix from prepareExtraParams to wrapStreamFn. */
232
232
  const FALLBACK_PREFIX_KEY = "_xiaoyi_fallback_prefix";
233
+ /** Internal key for passing deviceType from prepareExtraParams to wrapStreamFn. */
234
+ const DEVICE_TYPE_KEY = "_xiaoyi_device_type";
233
235
  const SELF_EVOLUTION_PROMPT_BEGIN = "<self_evolution_prompt>";
234
236
  const SELF_EVOLUTION_PROMPT_END = "</self_evolution_prompt>";
235
237
  const SELF_EVOLUTION_ENABLED_PROMPT_SECTION = `
@@ -413,6 +415,7 @@ export const xiaoyiProvider = {
413
415
  [HEADER_TRACE_ID]: taskId,
414
416
  [HEADER_SESSION_ID]: sessionId,
415
417
  [HEADER_INTERACTION_ID]: interactionId,
418
+ [DEVICE_TYPE_KEY]: sessionCtx.deviceType ?? "",
416
419
  };
417
420
  }
418
421
  // Fallback: store uid prefix for lazy timestamp generation in wrapStreamFn.
@@ -486,7 +489,9 @@ export const xiaoyiProvider = {
486
489
  if (context.systemPrompt) {
487
490
  console.log(`[xiaoyiprovider] system prompt length: ${context.systemPrompt.length}`);
488
491
  }
489
- const sessionCtx = getCurrentSessionContext();
492
+ // Reuse deviceType from extraParams instead of calling getCurrentSessionContext()
493
+ // again (which may be ambiguous in multi-session or async scenarios).
494
+ const deviceType = ctx.extraParams?.[DEVICE_TYPE_KEY] || undefined;
490
495
  // 在发送给模型前,优化 systemPrompt 结构
491
496
  if (context.systemPrompt) {
492
497
  let sp = context.systemPrompt;
@@ -519,10 +524,9 @@ export const xiaoyiProvider = {
519
524
  const selfEvolutionEnabled = await selfEvolutionManager.isEnabled();
520
525
  logger.log(`[selfEvolution] selfEvolution flag: ${selfEvolutionEnabled}`);
521
526
  context.systemPrompt = applySelfEvolutionPrompt(context.systemPrompt, selfEvolutionEnabled);
522
- // Append device context to systemPrompt
523
- if (sessionCtx?.deviceType) {
524
- const rawDevice = sessionCtx.deviceType;
525
- const displayDevice = (rawDevice === "2in1") ? "鸿蒙PC" : rawDevice;
527
+ // Append device context to systemPrompt (using pre-captured deviceType from prepareExtraParams)
528
+ if (deviceType) {
529
+ const displayDevice = (deviceType === "2in1") ? "鸿蒙PC" : deviceType;
526
530
  const deviceSection = `\n\n## Current User Device Context\nThe current user is using the following device: ${displayDevice}\nYou need to be aware of the user's current device and provide guidance accordingly. If the response involves device-related tools or actions, you must tailor the reply based on the user's current device, using device-specific references such as "saved to the Notes/Calendar on your {deviceType}.\n"`;
527
531
  context.systemPrompt = (context.systemPrompt ?? "") + deviceSection;
528
532
  }
@@ -5,8 +5,13 @@ import { logger } from "./utils/logger.js";
5
5
  * Session到活跃TaskId的映射
6
6
  * Key: sessionId (注意:这里用sessionId,不是sessionKey)
7
7
  * Value: TaskIdBinding
8
+ * Uses globalThis to ensure a single Map across all module copies.
8
9
  */
9
- const activeTaskIds = new Map();
10
+ const _g = globalThis;
11
+ if (!_g.__xyActiveTaskIds) {
12
+ _g.__xyActiveTaskIds = new Map();
13
+ }
14
+ const activeTaskIds = _g.__xyActiveTaskIds;
10
15
  /**
11
16
  * 注册或更新session的活跃taskId
12
17
  * 返回是否是更新(用于判断是否是第二条消息)
@@ -1,6 +1,7 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * XY calendar event tool - creates a calendar event on user's device.
3
4
  * Requires title, dtStart (start time), and dtEnd (end time) parameters.
4
5
  * Time format must be: yyyy-mm-dd hh:mm:ss
5
6
  */
6
- export declare const calendarTool: any;
7
+ export declare function createCalendarTool(ctx: SessionContext): any;
@@ -1,134 +1,130 @@
1
1
  import { getXYWebSocketManager } from "../client.js";
2
2
  import { sendCommand } from "../formatter.js";
3
- import { getCurrentSessionContext } from "./session-manager.js";
4
3
  /**
5
4
  * XY calendar event tool - creates a calendar event on user's device.
6
5
  * Requires title, dtStart (start time), and dtEnd (end time) parameters.
7
6
  * Time format must be: yyyy-mm-dd hh:mm:ss
8
7
  */
9
- export const calendarTool = {
10
- name: "create_calendar_event",
11
- label: "Create Calendar Event",
12
- description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
8
+ export function createCalendarTool(ctx) {
9
+ const { config, sessionId, taskId, messageId } = ctx;
10
+ return {
11
+ name: "create_calendar_event",
12
+ label: "Create Calendar Event",
13
+ description: `在用户设备上创建日程。需要提供日程标题、开始时间和结束时间。时间格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)。注意:该工具执行时间较长(最多60秒),请勿重复调用,超时或失败时最多重试一次。
13
14
  注意事项:使用该工具之前需获取当前真实时间
14
15
 
15
16
  回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。
16
17
  `,
17
- parameters: {
18
- type: "object",
19
- properties: {
20
- title: {
21
- type: "string",
22
- description: "日程标题/名称",
23
- },
24
- dtStart: {
25
- type: "string",
26
- description: "日程开始时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)",
27
- },
28
- dtEnd: {
29
- type: "string",
30
- description: "日程结束时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 17:30:00)",
18
+ parameters: {
19
+ type: "object",
20
+ properties: {
21
+ title: {
22
+ type: "string",
23
+ description: "日程标题/名称",
24
+ },
25
+ dtStart: {
26
+ type: "string",
27
+ description: "日程开始时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 14:30:00)",
28
+ },
29
+ dtEnd: {
30
+ type: "string",
31
+ description: "日程结束时间,格式必须为:yyyy-mm-dd hh:mm:ss(例如:2024-01-15 17:30:00)",
32
+ },
31
33
  },
34
+ required: ["title", "dtStart", "dtEnd"],
32
35
  },
33
- required: ["title", "dtStart", "dtEnd"],
34
- },
35
- async execute(toolCallId, params) {
36
- // Validate parameters
37
- if (!params.title || !params.dtStart || !params.dtEnd) {
38
- throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
39
- }
40
- // Convert time strings to millisecond timestamps
41
- const dtStartMs = new Date(params.dtStart).getTime();
42
- const dtEndMs = new Date(params.dtEnd).getTime();
43
- if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
44
- throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
45
- }
46
- // Get session context
47
- const sessionContext = getCurrentSessionContext();
48
- if (!sessionContext) {
49
- throw new Error("No active XY session found. Calendar tool can only be used during an active conversation.");
50
- }
51
- const { config, sessionId, taskId, messageId } = sessionContext;
52
- // Get WebSocket manager
53
- const wsManager = getXYWebSocketManager(config);
54
- // Build CreateCalendarEvent command
55
- const command = {
56
- header: {
57
- namespace: "Common",
58
- name: "ActionAndResult",
59
- },
60
- payload: {
61
- cardParam: {},
62
- executeParam: {
63
- executeMode: "background",
64
- intentName: "CreateCalendarEvent",
65
- bundleName: "com.huawei.hmos.calendardata",
66
- dimension: "",
67
- needUnlock: true,
68
- actionResponse: true,
69
- timeOut: 5,
70
- intentParam: {
71
- title: params.title,
72
- dtStart: dtStartMs,
73
- dtEnd: dtEndMs,
74
- },
75
- achieveType: "INTENT",
36
+ async execute(toolCallId, params) {
37
+ // Validate parameters
38
+ if (!params.title || !params.dtStart || !params.dtEnd) {
39
+ throw new Error("Missing required parameters: title, dtStart, and dtEnd are required");
40
+ }
41
+ // Convert time strings to millisecond timestamps
42
+ const dtStartMs = new Date(params.dtStart).getTime();
43
+ const dtEndMs = new Date(params.dtEnd).getTime();
44
+ if (isNaN(dtStartMs) || isNaN(dtEndMs)) {
45
+ throw new Error("Invalid time format. Required format: yyyy-mm-dd hh:mm:ss (e.g., 2024-01-15 14:30:00)");
46
+ }
47
+ // Get WebSocket manager
48
+ const wsManager = getXYWebSocketManager(config);
49
+ // Build CreateCalendarEvent command
50
+ const command = {
51
+ header: {
52
+ namespace: "Common",
53
+ name: "ActionAndResult",
76
54
  },
77
- responses: [
78
- {
79
- resultCode: "",
80
- displayText: "",
81
- ttsText: "",
55
+ payload: {
56
+ cardParam: {},
57
+ executeParam: {
58
+ executeMode: "background",
59
+ intentName: "CreateCalendarEvent",
60
+ bundleName: "com.huawei.hmos.calendardata",
61
+ dimension: "",
62
+ needUnlock: true,
63
+ actionResponse: true,
64
+ timeOut: 5,
65
+ intentParam: {
66
+ title: params.title,
67
+ dtStart: dtStartMs,
68
+ dtEnd: dtEndMs,
69
+ },
70
+ achieveType: "INTENT",
82
71
  },
83
- ],
84
- needUploadResult: true,
85
- noHalfPage: false,
86
- pageControlRelated: false,
87
- },
88
- };
89
- // Send command and wait for response (60 second timeout)
90
- return new Promise((resolve, reject) => {
91
- const timeout = setTimeout(() => {
92
- wsManager.off("data-event", handler);
93
- reject(new Error("创建日程超时(60秒)"));
94
- }, 60000);
95
- // Listen for data events from WebSocket
96
- const handler = (event) => {
97
- if (event.intentName === "CreateCalendarEvent") {
98
- clearTimeout(timeout);
72
+ responses: [
73
+ {
74
+ resultCode: "",
75
+ displayText: "",
76
+ ttsText: "",
77
+ },
78
+ ],
79
+ needUploadResult: true,
80
+ noHalfPage: false,
81
+ pageControlRelated: false,
82
+ },
83
+ };
84
+ // Send command and wait for response (60 second timeout)
85
+ return new Promise((resolve, reject) => {
86
+ const timeout = setTimeout(() => {
99
87
  wsManager.off("data-event", handler);
100
- if (event.status === "success" && event.outputs) {
101
- resolve({
102
- content: [
103
- {
104
- type: "text",
105
- text: JSON.stringify(event.outputs),
106
- },
107
- ],
108
- });
109
- }
110
- else {
111
- reject(new Error(`创建日程失败: ${event.status}`));
88
+ reject(new Error("创建日程超时(60秒)"));
89
+ }, 60000);
90
+ // Listen for data events from WebSocket
91
+ const handler = (event) => {
92
+ if (event.intentName === "CreateCalendarEvent") {
93
+ clearTimeout(timeout);
94
+ wsManager.off("data-event", handler);
95
+ if (event.status === "success" && event.outputs) {
96
+ resolve({
97
+ content: [
98
+ {
99
+ type: "text",
100
+ text: JSON.stringify(event.outputs),
101
+ },
102
+ ],
103
+ });
104
+ }
105
+ else {
106
+ reject(new Error(`创建日程失败: ${event.status}`));
107
+ }
112
108
  }
113
- }
114
- };
115
- // Register event handler
116
- wsManager.on("data-event", handler);
117
- // Send the command
118
- sendCommand({
119
- config,
120
- sessionId,
121
- taskId,
122
- messageId,
123
- command,
124
- })
125
- .then(() => {
126
- })
127
- .catch((error) => {
128
- clearTimeout(timeout);
129
- wsManager.off("data-event", handler);
130
- reject(error);
109
+ };
110
+ // Register event handler
111
+ wsManager.on("data-event", handler);
112
+ // Send the command
113
+ sendCommand({
114
+ config,
115
+ sessionId,
116
+ taskId,
117
+ messageId,
118
+ command,
119
+ })
120
+ .then(() => {
121
+ })
122
+ .catch((error) => {
123
+ clearTimeout(timeout);
124
+ wsManager.off("data-event", handler);
125
+ reject(error);
126
+ });
131
127
  });
132
- });
133
- },
134
- };
128
+ },
129
+ };
130
+ }
@@ -1,5 +1,6 @@
1
+ import type { SessionContext } from "./session-manager.js";
1
2
  /**
2
3
  * call_device_tool - 通用端工具调度器。
3
4
  * LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
4
5
  */
5
- export declare const callDeviceTool: any;
6
+ export declare function createCallDeviceTool(ctx: SessionContext): any;