@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.
- package/dist/src/channel.js +11 -9
- package/dist/src/tools/calendar-tool.d.ts +1 -1
- package/dist/src/tools/call-device-tool.d.ts +1 -1
- package/dist/src/tools/call-phone-tool.d.ts +1 -1
- package/dist/src/tools/create-alarm-tool.d.ts +1 -1
- package/dist/src/tools/create-all-tools.d.ts +1 -1
- package/dist/src/tools/delete-alarm-tool.d.ts +1 -1
- package/dist/src/tools/get-alarm-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-calendar-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-collection-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-contact-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-device-file-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-email-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-note-tool-schema.d.ts +1 -1
- package/dist/src/tools/get-photo-tool-schema.d.ts +1 -1
- package/dist/src/tools/image-reading-tool.d.ts +1 -1
- package/dist/src/tools/location-tool.d.ts +1 -1
- package/dist/src/tools/login-token-tool.d.ts +1 -1
- package/dist/src/tools/modify-alarm-tool.d.ts +1 -1
- package/dist/src/tools/modify-note-tool.d.ts +1 -1
- package/dist/src/tools/note-tool.d.ts +1 -1
- package/dist/src/tools/query-app-message-tool.d.ts +1 -1
- package/dist/src/tools/query-memory-data-tool.d.ts +1 -1
- package/dist/src/tools/query-todo-task-tool.d.ts +1 -1
- package/dist/src/tools/save-file-to-phone-tool.d.ts +1 -1
- package/dist/src/tools/save-media-to-gallery-tool.d.ts +1 -1
- package/dist/src/tools/save-self-evolution-skill-tool.d.ts +1 -1
- package/dist/src/tools/search-alarm-tool.d.ts +1 -1
- package/dist/src/tools/search-calendar-tool.d.ts +1 -1
- package/dist/src/tools/search-contact-tool.d.ts +1 -1
- package/dist/src/tools/search-email-tool.d.ts +1 -1
- package/dist/src/tools/search-file-tool.d.ts +1 -1
- package/dist/src/tools/search-message-tool.d.ts +1 -1
- package/dist/src/tools/search-note-tool.d.ts +1 -1
- package/dist/src/tools/search-photo-gallery-tool.d.ts +1 -1
- package/dist/src/tools/send-email-tool.d.ts +1 -1
- package/dist/src/tools/send-file-to-user-tool.d.ts +1 -1
- package/dist/src/tools/send-message-tool.d.ts +1 -1
- package/dist/src/tools/session-helper.d.ts +15 -4
- package/dist/src/tools/session-helper.js +34 -8
- package/dist/src/tools/upload-file-tool.d.ts +1 -1
- package/dist/src/tools/upload-photo-tool.d.ts +1 -1
- package/dist/src/tools/xiaoyi-add-collection-tool.d.ts +1 -1
- package/dist/src/tools/xiaoyi-collection-tool.d.ts +1 -1
- package/dist/src/tools/xiaoyi-delete-collection-tool.d.ts +1 -1
- package/dist/src/tools/xiaoyi-gui-tool.d.ts +1 -1
- package/package.json +1 -1
package/dist/src/channel.js
CHANGED
|
@@ -44,18 +44,20 @@ export const xyPlugin = {
|
|
|
44
44
|
},
|
|
45
45
|
outbound: xyOutbound,
|
|
46
46
|
agentTools: () => {
|
|
47
|
-
// agentTools factory
|
|
48
|
-
//
|
|
47
|
+
// agentTools factory may be called before ALS is active (e.g. during
|
|
48
|
+
// dispatcher setup). Don't bail out — tools 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
|
-
|
|
52
|
-
|
|
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
|
-
|
|
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
|
* 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;
|
|
@@ -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[];
|
|
@@ -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;
|
|
@@ -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 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;
|
|
@@ -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;
|
|
@@ -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;
|
|
@@ -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
|
|
6
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
6
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -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;
|
|
@@ -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;
|