@ynhcj/xiaoyi-channel 0.0.105-next → 0.0.106-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.
Files changed (47) hide show
  1. package/dist/src/channel.js +11 -9
  2. package/dist/src/tools/calendar-tool.d.ts +1 -1
  3. package/dist/src/tools/call-device-tool.d.ts +1 -1
  4. package/dist/src/tools/call-phone-tool.d.ts +1 -1
  5. package/dist/src/tools/create-alarm-tool.d.ts +1 -1
  6. package/dist/src/tools/create-all-tools.d.ts +1 -1
  7. package/dist/src/tools/delete-alarm-tool.d.ts +1 -1
  8. package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -1
  9. package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -1
  10. package/dist/src/tools/get-collection-tool-schema.d.ts +1 -1
  11. package/dist/src/tools/get-contact-tool-schema.d.ts +1 -1
  12. package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -1
  13. package/dist/src/tools/get-email-tool-schema.d.ts +1 -1
  14. package/dist/src/tools/get-note-tool-schema.d.ts +1 -1
  15. package/dist/src/tools/get-photo-tool-schema.d.ts +1 -1
  16. package/dist/src/tools/image-reading-tool.d.ts +1 -1
  17. package/dist/src/tools/location-tool.d.ts +1 -1
  18. package/dist/src/tools/login-token-tool.d.ts +1 -1
  19. package/dist/src/tools/modify-alarm-tool.d.ts +1 -1
  20. package/dist/src/tools/modify-note-tool.d.ts +1 -1
  21. package/dist/src/tools/note-tool.d.ts +1 -1
  22. package/dist/src/tools/query-app-message-tool.d.ts +1 -1
  23. package/dist/src/tools/query-memory-data-tool.d.ts +1 -1
  24. package/dist/src/tools/query-todo-task-tool.d.ts +1 -1
  25. package/dist/src/tools/save-file-to-phone-tool.d.ts +1 -1
  26. package/dist/src/tools/save-media-to-gallery-tool.d.ts +1 -1
  27. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +1 -1
  28. package/dist/src/tools/search-alarm-tool.d.ts +1 -1
  29. package/dist/src/tools/search-calendar-tool.d.ts +1 -1
  30. package/dist/src/tools/search-contact-tool.d.ts +1 -1
  31. package/dist/src/tools/search-email-tool.d.ts +1 -1
  32. package/dist/src/tools/search-file-tool.d.ts +1 -1
  33. package/dist/src/tools/search-message-tool.d.ts +1 -1
  34. package/dist/src/tools/search-note-tool.d.ts +1 -1
  35. package/dist/src/tools/search-photo-gallery-tool.d.ts +1 -1
  36. package/dist/src/tools/send-email-tool.d.ts +1 -1
  37. package/dist/src/tools/send-file-to-user-tool.d.ts +1 -1
  38. package/dist/src/tools/send-message-tool.d.ts +1 -1
  39. package/dist/src/tools/session-helper.d.ts +15 -4
  40. package/dist/src/tools/session-helper.js +34 -8
  41. package/dist/src/tools/upload-file-tool.d.ts +1 -1
  42. package/dist/src/tools/upload-photo-tool.d.ts +1 -1
  43. package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +1 -1
  44. package/dist/src/tools/xiaoyi-collection-tool.d.ts +1 -1
  45. package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +1 -1
  46. package/dist/src/tools/xiaoyi-gui-tool.d.ts +1 -1
  47. package/package.json +1 -1
@@ -44,18 +44,20 @@ export const xyPlugin = {
44
44
  },
45
45
  outbound: xyOutbound,
46
46
  agentTools: () => {
47
- // agentTools factory is called during agent run setup.
48
- // ALS is still valid at this point read sessionKey from it.
47
+ // agentTools factory may be called before ALS is active (e.g. during
48
+ // dispatcher setup). Don't bail outtools will resolve their
49
+ // session at execute time via requireSession() which falls back to ALS.
49
50
  const alsContext = xyAsyncLocalStorage.getStore();
50
51
  const sessionKey = alsContext?.openclawSessionKey;
51
- if (!sessionKey) {
52
- logger.log("[CHANNEL-TOOLS] no sessionKey in ALS, returning empty tools");
53
- return [];
54
- }
55
- const session = getSession(sessionKey);
56
- const allTools = createAllTools(sessionKey);
52
+ const allTools = createAllTools(sessionKey ?? undefined);
53
+ const session = sessionKey ? getSession(sessionKey) : null;
57
54
  const filtered = filterToolsByDevice(allTools, session?.deviceType);
58
- logger.log(`[CHANNEL-TOOLS] sessionKey=${sessionKey} deviceType=${session?.deviceType ?? "(none)"}, tools: ${allTools.length} → ${filtered.length} (${filtered.map(t => t.name).join(", ")})`);
55
+ if (sessionKey) {
56
+ logger.log(`[CHANNEL-TOOLS] sessionKey=${sessionKey} deviceType=${session?.deviceType ?? "(none)"}, tools: ${allTools.length} → ${filtered.length}`);
57
+ }
58
+ else {
59
+ logger.log(`[CHANNEL-TOOLS] no ALS at factory time, created ${filtered.length} tools (will resolve session at execute time)`);
60
+ }
59
61
  return filtered;
60
62
  },
61
63
  messaging: {
@@ -3,4 +3,4 @@
3
3
  * Requires title, dtStart (start time), and dtEnd (end time) parameters.
4
4
  * Time format must be: yyyy-mm-dd hh:mm:ss
5
5
  */
6
- export declare function createCalendarTool(sessionKey: string): any;
6
+ export declare function createCalendarTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * call_device_tool - 通用端工具调度器。
3
3
  * LLM 必须先通过 get_xxx_tool_schema 获取具体工具 schema,再用本工具执行。
4
4
  */
5
- export declare function createCallDeviceTool(sessionKey: string): any;
5
+ export declare function createCallDeviceTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY call phone tool - makes a phone call on user's device.
3
3
  * Requires phoneNumber parameter and optional slotId (0 for primary SIM, 1 for secondary SIM).
4
4
  */
5
- export declare function createCallPhoneTool(sessionKey: string): any;
5
+ export declare function createCallPhoneTool(sessionKey: string | undefined): any;
@@ -4,4 +4,4 @@
4
4
  *
5
5
  * Time format: YYYYMMDD hhmmss (e.g., 20240315 143000)
6
6
  */
7
- export declare function makeAlarmTool(sessionKey: string): any;
7
+ export declare function makeAlarmTool(sessionKey: string | undefined): any;
@@ -12,4 +12,4 @@ import type { ChannelAgentTool } from "openclaw/plugin-sdk";
12
12
  * @param sessionKey - The OpenClaw session key for the current turn.
13
13
  * Tools will look up the live session context at execute time.
14
14
  */
15
- export declare function createAllTools(sessionKey: string): ChannelAgentTool[];
15
+ export declare function createAllTools(sessionKey: string | undefined): ChannelAgentTool[];
@@ -8,4 +8,4 @@
8
8
  *
9
9
  * Supports deleting single or multiple alarms in one call.
10
10
  */
11
- export declare function createDeleteAlarmTool(sessionKey: string): any;
11
+ export declare function createDeleteAlarmTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
- export declare function createGetAlarmToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetAlarmToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetCalendarToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetCalendarToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetCollectionToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetCollectionToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetContactToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetContactToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetDeviceFileToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetDeviceFileToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetEmailToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetEmailToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetNoteToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetNoteToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -1,4 +1,4 @@
1
- export declare function createGetPhotoToolSchemaTool(sessionKey: string): {
1
+ export declare function createGetPhotoToolSchemaTool(sessionKey: string | undefined): {
2
2
  name: string;
3
3
  label: string;
4
4
  description: string;
@@ -2,4 +2,4 @@
2
2
  * XY Image Reading tool - performs image understanding using local or remote image URLs.
3
3
  * Supports both local file paths and remote URLs, up to 10 images at once.
4
4
  */
5
- export declare function createImageReadingTool(sessionKey: string): any;
5
+ export declare function createImageReadingTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY location tool - gets user's current location.
3
3
  * Returns WGS84 coordinates (latitude, longitude).
4
4
  */
5
- export declare function createLocationTool(sessionKey: string): any;
5
+ export declare function createLocationTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * huawei_id_tool 工具
3
3
  * 当 skill 依赖用户获取鉴权信息时,此工具协助用户快速获取鉴权信息。
4
4
  */
5
- export declare function createLoginTokenTool(sessionKey: string): any;
5
+ export declare function createLoginTokenTool(sessionKey: string | undefined): any;
@@ -6,4 +6,4 @@
6
6
  * 1. Call search_alarm or create_alarm tool first to get entityId
7
7
  * 2. Use the entityId to identify which alarm to modify
8
8
  */
9
- export declare function createModifyAlarmTool(sessionKey: string): any;
9
+ export declare function createModifyAlarmTool(sessionKey: string | undefined): any;
@@ -6,4 +6,4 @@
6
6
  * 1. Call search_notes tool first to get the entityId of target note
7
7
  * 2. Use the entityId to append content to that note
8
8
  */
9
- export declare function createModifyNoteTool(sessionKey: string): any;
9
+ export declare function createModifyNoteTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY note tool - creates a note on user's device.
3
3
  * Requires title and content parameters.
4
4
  */
5
- export declare function createNoteTool(sessionKey: string): any;
5
+ export declare function createNoteTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 查询指定时间范围内的设备通知消息。
3
3
  */
4
- export declare function createQueryAppMessageTool(sessionKey: string): any;
4
+ export declare function createQueryAppMessageTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 查询存储在设备本地的结构化记忆数据。
3
3
  */
4
- export declare function createQueryMemoryDataTool(sessionKey: string): any;
4
+ export declare function createQueryMemoryDataTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * 获取指定时间范围内的全局待办任务列表。
3
3
  */
4
- export declare function createQueryTodoTaskTool(sessionKey: string): any;
4
+ export declare function createQueryTodoTaskTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY save file to phone tool - saves files to user's device file manager.
3
3
  * Supports local file paths (auto-uploaded to get public URL) and public URLs.
4
4
  */
5
- export declare function createSaveFileToPhoneTool(sessionKey: string): any;
5
+ export declare function createSaveFileToPhoneTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY save media to gallery tool - saves image or video files to user's device gallery.
3
3
  * Supports local file paths (auto-uploaded to get public URL) and public URLs.
4
4
  */
5
- export declare function createSaveMediaToGalleryTool(sessionKey: string): any;
5
+ export declare function createSaveMediaToGalleryTool(sessionKey: string | undefined): any;
@@ -1 +1 @@
1
- export declare function createSaveSelfEvolutionSkillTool(sessionKey: string): any;
1
+ export declare function createSaveSelfEvolutionSkillTool(sessionKey: string | undefined): any;
@@ -5,4 +5,4 @@
5
5
  * At least one search criterion must be provided.
6
6
  * Multiple criteria can be combined.
7
7
  */
8
- export declare function createSearchAlarmTool(sessionKey: string): any;
8
+ export declare function createSearchAlarmTool(sessionKey: string | undefined): any;
@@ -9,4 +9,4 @@
9
9
  * - For evening: 18:00:00 to 24:00:00
10
10
  * - For a specific time: use ±1 hour range (e.g., for 3PM, use 14:00:00 to 16:00:00)
11
11
  */
12
- export declare function createSearchCalendarTool(sessionKey: string): any;
12
+ export declare function createSearchCalendarTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY search contact tool - searches contacts on user's device.
3
3
  * Returns matching contact information based on name.
4
4
  */
5
- export declare function createSearchContactTool(sessionKey: string): any;
5
+ export declare function createSearchContactTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY search email tool - searches emails on user's device (花瓣邮箱).
3
3
  * Returns matching emails based on query text and search type.
4
4
  */
5
- export declare function createSearchEmailTool(sessionKey: string): any;
5
+ export declare function createSearchEmailTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY search file tool - searches files on user's device file system.
3
3
  * Returns matching files based on keyword search in file name or content.
4
4
  */
5
- export declare function createSearchFileTool(sessionKey: string): any;
5
+ export declare function createSearchFileTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY search message tool - searches SMS messages on user's device.
3
3
  * Returns matching messages based on content keyword search.
4
4
  */
5
- export declare function createSearchMessageTool(sessionKey: string): any;
5
+ export declare function createSearchMessageTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY search note tool - searches notes on user's device.
3
3
  * Returns matching notes based on query string.
4
4
  */
5
- export declare function createSearchNoteTool(sessionKey: string): any;
5
+ export declare function createSearchNoteTool(sessionKey: string | undefined): any;
@@ -5,4 +5,4 @@
5
5
  * IMPORTANT: The returned mediaUris are LOCAL URIs that cannot be downloaded directly.
6
6
  * To get publicly accessible URLs, use the upload_photo tool with these URIs.
7
7
  */
8
- export declare function createSearchPhotoGalleryTool(sessionKey: string): any;
8
+ export declare function createSearchPhotoGalleryTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * XY send email tool - sends an email via 花瓣邮箱 on user's device.
3
3
  */
4
- export declare function createSendEmailTool(sessionKey: string): any;
4
+ export declare function createSendEmailTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY send file to user tool - sends local files or remote files to user's device.
3
3
  * Supports both local file paths and remote URLs.
4
4
  */
5
- export declare function createSendFileToUserTool(sessionKey: string): any;
5
+ export declare function createSendFileToUserTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY send message tool - sends SMS message on user's device.
3
3
  * Requires phoneNumber (with +86 prefix) and content parameters.
4
4
  */
5
- export declare function createSendMessageTool(sessionKey: string): any;
5
+ export declare function createSendMessageTool(sessionKey: string | undefined): any;
@@ -2,12 +2,23 @@
2
2
  * Tool session helper — provides a simple API for tools to access
3
3
  * the current session context via sessionKey.
4
4
  *
5
- * Tools capture `sessionKey` at creation time and call `requireSession()`
6
- * at execute time to get the live XYSession (with latest taskId).
5
+ * Tools capture `sessionKey` at creation time (may be empty if ALS
6
+ * was not available at agentTools factory time) and call
7
+ * `requireSession()` at execute time. If the captured sessionKey
8
+ * doesn't resolve, we fall back to ALS — the agent run is always
9
+ * within the ALS context set by bot.ts.
7
10
  */
8
11
  import { type XYSession } from "../xy-session-store.js";
9
12
  /**
10
13
  * Get the session for a sessionKey, throwing if not found.
11
- * Used at the top of every tool's execute() to get live context.
14
+ *
15
+ * Resolution order:
16
+ * 1. Closure-captured sessionKey (set at agentTools factory time)
17
+ * 2. ALS (set by bot.ts before the agent run)
18
+ * 3. Store enumeration — safe only when a single session is active
19
+ *
20
+ * Layers 1 and 2 can both fail: agentTools may be called before ALS is
21
+ * active, and pi-agent-core tool execute may cross async boundaries that
22
+ * lose the ALS context. Layer 3 is the ultimate fallback.
12
23
  */
13
- export declare function requireSession(sessionKey: string): XYSession;
24
+ export declare function requireSession(sessionKey?: string | null): XYSession;
@@ -2,18 +2,44 @@
2
2
  * Tool session helper — provides a simple API for tools to access
3
3
  * the current session context via sessionKey.
4
4
  *
5
- * Tools capture `sessionKey` at creation time and call `requireSession()`
6
- * at execute time to get the live XYSession (with latest taskId).
5
+ * Tools capture `sessionKey` at creation time (may be empty if ALS
6
+ * was not available at agentTools factory time) and call
7
+ * `requireSession()` at execute time. If the captured sessionKey
8
+ * doesn't resolve, we fall back to ALS — the agent run is always
9
+ * within the ALS context set by bot.ts.
7
10
  */
8
- import { getSession } from "../xy-session-store.js";
11
+ import { getSession, xyAsyncLocalStorage, getAllActiveSessions } from "../xy-session-store.js";
9
12
  /**
10
13
  * Get the session for a sessionKey, throwing if not found.
11
- * Used at the top of every tool's execute() to get live context.
14
+ *
15
+ * Resolution order:
16
+ * 1. Closure-captured sessionKey (set at agentTools factory time)
17
+ * 2. ALS (set by bot.ts before the agent run)
18
+ * 3. Store enumeration — safe only when a single session is active
19
+ *
20
+ * Layers 1 and 2 can both fail: agentTools may be called before ALS is
21
+ * active, and pi-agent-core tool execute may cross async boundaries that
22
+ * lose the ALS context. Layer 3 is the ultimate fallback.
12
23
  */
13
24
  export function requireSession(sessionKey) {
14
- const session = getSession(sessionKey);
15
- if (!session) {
16
- throw new Error(`XY session not found for key: ${sessionKey}`);
25
+ // Layer 1: closure-captured sessionKey
26
+ if (sessionKey) {
27
+ const session = getSession(sessionKey);
28
+ if (session)
29
+ return session;
30
+ }
31
+ // Layer 2: ALS (works when the async chain preserves the context)
32
+ const alsContext = xyAsyncLocalStorage.getStore();
33
+ const alsKey = alsContext?.openclawSessionKey;
34
+ if (alsKey) {
35
+ const session = getSession(alsKey);
36
+ if (session)
37
+ return session;
38
+ }
39
+ // Layer 3: store enumeration — reliable when only one session is active
40
+ const allSessions = getAllActiveSessions();
41
+ if (allSessions.length === 1) {
42
+ return allSessions[0].session;
17
43
  }
18
- return session;
44
+ throw new Error(`XY session not found (sessionKey=${sessionKey ?? "none"}, alsKey=${alsKey ?? "none"}, activeSessions=${allSessions.length})`);
19
45
  }
@@ -10,4 +10,4 @@
10
10
  * - After getting public URLs, if further processing is needed, download the file first
11
11
  * - URLs returned are publicly accessible
12
12
  */
13
- export declare function createUploadFileTool(sessionKey: string): any;
13
+ export declare function createUploadFileTool(sessionKey: string | undefined): any;
@@ -6,4 +6,4 @@
6
6
  * 1. Call search_photo_gallery tool first to get mediaUris of photos
7
7
  * 2. Use the mediaUris (maximum 5 at a time) to get public URLs
8
8
  */
9
- export declare function createUploadPhotoTool(sessionKey: string): any;
9
+ export declare function createUploadPhotoTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * XY add collection tool - adds data to user's XiaoYi collection.
3
3
  */
4
- export declare function createXiaoyiAddCollectionTool(sessionKey: string): any;
4
+ export declare function createXiaoyiAddCollectionTool(sessionKey: string | undefined): any;
@@ -2,4 +2,4 @@
2
2
  * XY collection tool - retrieves user's collection data from XiaoYi.
3
3
  * Returns personalized knowledge data saved in user's collection.
4
4
  */
5
- export declare function createXiaoyiCollectionTool(sessionKey: string): any;
5
+ export declare function createXiaoyiCollectionTool(sessionKey: string | undefined): any;
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * XY delete collection tool - deletes data from user's XiaoYi collection.
3
3
  */
4
- export declare function createXiaoyiDeleteCollectionTool(sessionKey: string): any;
4
+ export declare function createXiaoyiDeleteCollectionTool(sessionKey: string | undefined): any;
@@ -3,4 +3,4 @@
3
3
  * Simulates user interactions on phone screen (click, swipe, input, navigation, etc.)
4
4
  * to complete tasks that cannot be done through internet APIs.
5
5
  */
6
- export declare function createXiaoyiGuiTool(sessionKey: string): any;
6
+ export declare function createXiaoyiGuiTool(sessionKey: string | undefined): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ynhcj/xiaoyi-channel",
3
- "version": "0.0.105-next",
3
+ "version": "0.0.106-next",
4
4
  "description": "OpenClaw Xiaoyi Channel plugin - Xiaoyi A2A protocol integration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",