@ynhcj/xiaoyi-channel 1.1.19 → 1.1.21

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 (38) hide show
  1. package/dist/index.d.ts +0 -5
  2. package/dist/index.js +107 -10
  3. package/dist/src/channel.js +2 -1
  4. package/dist/src/login-token-handler.d.ts +8 -0
  5. package/dist/src/login-token-handler.js +60 -0
  6. package/dist/src/monitor.js +14 -0
  7. package/dist/src/provider.js +319 -27
  8. package/dist/src/self-evolution-handler.d.ts +1 -0
  9. package/dist/src/self-evolution-handler.js +47 -0
  10. package/dist/src/skill-retriever/config.d.ts +4 -0
  11. package/dist/src/skill-retriever/config.js +23 -0
  12. package/dist/src/skill-retriever/hooks.d.ts +22 -0
  13. package/dist/src/skill-retriever/hooks.js +91 -0
  14. package/dist/src/skill-retriever/tool-search.d.ts +16 -0
  15. package/dist/src/skill-retriever/tool-search.js +159 -0
  16. package/dist/src/skill-retriever/types.d.ts +34 -0
  17. package/dist/src/skill-retriever/types.js +1 -0
  18. package/dist/src/tools/call-device-tool.js +4 -0
  19. package/dist/src/tools/get-email-tool-schema.d.ts +16 -0
  20. package/dist/src/tools/get-email-tool-schema.js +9 -0
  21. package/dist/src/tools/login-token-tool.d.ts +5 -0
  22. package/dist/src/tools/login-token-tool.js +136 -0
  23. package/dist/src/tools/query-app-message-tool.d.ts +4 -0
  24. package/dist/src/tools/query-app-message-tool.js +138 -0
  25. package/dist/src/tools/query-memory-data-tool.d.ts +4 -0
  26. package/dist/src/tools/query-memory-data-tool.js +154 -0
  27. package/dist/src/tools/query-todo-task-tool.d.ts +4 -0
  28. package/dist/src/tools/query-todo-task-tool.js +133 -0
  29. package/dist/src/tools/save-self-evolution-skill-tool.d.ts +1 -0
  30. package/dist/src/tools/save-self-evolution-skill-tool.js +412 -0
  31. package/dist/src/tools/session-manager.js +2 -0
  32. package/dist/src/utils/runtime-manager.js +24 -2
  33. package/dist/src/utils/self-evolution-manager.d.ts +5 -0
  34. package/dist/src/utils/self-evolution-manager.js +47 -0
  35. package/dist/src/utils/tool-call-nudge-manager.d.ts +16 -0
  36. package/dist/src/utils/tool-call-nudge-manager.js +47 -0
  37. package/dist/src/websocket.js +18 -0
  38. package/package.json +2 -2
@@ -0,0 +1,154 @@
1
+ // QueryMemoryData tool implementation
2
+ import { getXYWebSocketManager } from "../client.js";
3
+ import { sendCommand } from "../formatter.js";
4
+ import { getCurrentSessionContext } from "./session-manager.js";
5
+ class ToolInputError extends Error {
6
+ status = 400;
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "ToolInputError";
10
+ }
11
+ }
12
+ const VALID_CATEGORIES = ["ImportantDay", "Address", "Card", "ServiceOrder", "Event"];
13
+ const VALID_SUB_CATEGORIES = {
14
+ ImportantDay: ["Birthday", "Anniversary", "RepaymentDate", "ExamDate", "SalaryDate", "BigDay"],
15
+ Card: [
16
+ "IDCard", "Passport", "DrivingLicense", "VehicleLicense", "EEPtoHKMO",
17
+ "EEPtoTW", "Invoice", "BusinessCard", "VehicleInspectionCertificate",
18
+ "SocialSecurityCard", "BankCard",
19
+ ],
20
+ ServiceOrder: ["FilmTicket", "HotelOrder", "TrainTicket", "AirTicket"],
21
+ Event: [
22
+ "Delicacy", "Work", "FamilyActivities", "Travel", "Training",
23
+ "Health", "Life", "Entertainment", "Calendar",
24
+ ],
25
+ };
26
+ /**
27
+ * 查询存储在设备本地的结构化记忆数据。
28
+ */
29
+ export const queryMemoryDataTool = {
30
+ name: "query_memory_data",
31
+ label: "Query Memory Data",
32
+ description: `查询存储在设备本地的结构化记忆数据。适用于获取特定类别的个人信息,如重要日子、证件卡证、服务订单或日程事件。支持按分类、子分类进行过滤。
33
+ 注意:
34
+ a. 操作超时时间为60秒,请勿重复调用此工具
35
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
36
+ c. 调用工具前需认真检查调用参数是否满足工具要求
37
+
38
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
39
+ parameters: {
40
+ type: "object",
41
+ properties: {
42
+ category: {
43
+ type: "string",
44
+ description: '按数据大类进行过滤。可选值为 ""、"ImportantDay"、"Address"、"Card"、"ServiceOrder"、"Event"。默认值为 ""。',
45
+ },
46
+ subCategory: {
47
+ description: '在指定 category 下的子类别过滤,默认值为""。支持字符串或字符串数组。',
48
+ oneOf: [
49
+ { type: "string" },
50
+ { type: "array", items: { type: "string" } },
51
+ ],
52
+ },
53
+ },
54
+ required: [],
55
+ },
56
+ async execute(_toolCallId, params) {
57
+ const { category, subCategory } = params;
58
+ // Validate category
59
+ if (category && !VALID_CATEGORIES.includes(category)) {
60
+ throw new ToolInputError(`category 参数无效,可选值为:${VALID_CATEGORIES.join("、")}`);
61
+ }
62
+ // Validate subCategory when category is specified
63
+ if (category && subCategory && VALID_SUB_CATEGORIES[category]) {
64
+ const validValues = VALID_SUB_CATEGORIES[category];
65
+ const subValues = Array.isArray(subCategory) ? subCategory : [subCategory];
66
+ for (const sv of subValues) {
67
+ if (sv && !validValues.includes(sv)) {
68
+ throw new ToolInputError(`category 为 "${category}" 时,subCategory 可选值为:${validValues.join("、")}`);
69
+ }
70
+ }
71
+ }
72
+ const sessionContext = getCurrentSessionContext();
73
+ if (!sessionContext) {
74
+ throw new Error("No active XY session found.");
75
+ }
76
+ const { config, sessionId, taskId, messageId } = sessionContext;
77
+ const wsManager = getXYWebSocketManager(config);
78
+ const intentParam = {};
79
+ if (category)
80
+ intentParam.category = category;
81
+ if (subCategory !== undefined)
82
+ intentParam.subCategory = subCategory;
83
+ const command = {
84
+ header: {
85
+ namespace: "Common",
86
+ name: "Action",
87
+ },
88
+ payload: {
89
+ cardParam: {},
90
+ executeParam: {
91
+ executeMode: "background",
92
+ intentName: "QueryMemoryData",
93
+ bundleName: "com.huawei.hmos.vassistant",
94
+ needUnlock: true,
95
+ actionResponse: true,
96
+ appType: "OHOS_APP",
97
+ timeOut: 5,
98
+ intentParam,
99
+ permissionId: [],
100
+ achieveType: "INTENT",
101
+ },
102
+ responses: [
103
+ {
104
+ resultCode: "",
105
+ displayText: "",
106
+ ttsText: "",
107
+ },
108
+ ],
109
+ needUploadResult: true,
110
+ noHalfPage: false,
111
+ pageControlRelated: false,
112
+ },
113
+ };
114
+ return new Promise((resolve, reject) => {
115
+ const timeout = setTimeout(() => {
116
+ wsManager.off("data-event", handler);
117
+ reject(new Error("查询记忆数据超时(60秒)"));
118
+ }, 60000);
119
+ const handler = (event) => {
120
+ if (event.intentName === "QueryMemoryData") {
121
+ clearTimeout(timeout);
122
+ wsManager.off("data-event", handler);
123
+ if (event.status === "success" && event.outputs) {
124
+ resolve({
125
+ content: [
126
+ {
127
+ type: "text",
128
+ text: JSON.stringify(event.outputs),
129
+ },
130
+ ],
131
+ });
132
+ }
133
+ else {
134
+ reject(new Error(`查询记忆数据失败: ${event.status}`));
135
+ }
136
+ }
137
+ };
138
+ wsManager.on("data-event", handler);
139
+ sendCommand({
140
+ config,
141
+ sessionId,
142
+ taskId,
143
+ messageId,
144
+ command,
145
+ })
146
+ .then(() => { })
147
+ .catch((error) => {
148
+ clearTimeout(timeout);
149
+ wsManager.off("data-event", handler);
150
+ reject(error);
151
+ });
152
+ });
153
+ },
154
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 获取指定时间范围内的全局待办任务列表。
3
+ */
4
+ export declare const queryTodoTaskTool: any;
@@ -0,0 +1,133 @@
1
+ // QueryTodoTask tool implementation
2
+ import { getXYWebSocketManager } from "../client.js";
3
+ import { sendCommand } from "../formatter.js";
4
+ import { getCurrentSessionContext } from "./session-manager.js";
5
+ class ToolInputError extends Error {
6
+ status = 400;
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "ToolInputError";
10
+ }
11
+ }
12
+ /**
13
+ * 获取指定时间范围内的全局待办任务列表。
14
+ */
15
+ export const queryTodoTaskTool = {
16
+ name: "query_todo_task",
17
+ label: "Query Todo Task",
18
+ description: `获取指定时间范围内的全局待办任务列表。适用于需要查询历史任务、按完成状态筛选、或仅查看待处理任务的场景。支持按时间范围、任务状态进行过滤。
19
+ 注意:
20
+ a. 操作超时时间为60秒,请勿重复调用此工具
21
+ b. 如果遇到各类调用失败场景,最多只能重试一次,不可以重复调用多次。
22
+ c. 调用工具前需认真检查调用参数是否满足工具要求
23
+ d. 当只传入 startTime 时,返回该时间点之后的所有任务;当只传入 endTime 时,返回该时间点之前的所有任务;两者都不传则返回所有时间段的任务。
24
+
25
+ 回复约束:如果工具返回没有授权或者其他报错,只需要完整描述没有授权或者其他报错内容即可,不需要主动给用户提供解决方案,例如告诉用户如何授权,如何解决报错等都是不需要的,请严格遵守。`,
26
+ parameters: {
27
+ type: "object",
28
+ properties: {
29
+ startTime: {
30
+ type: "string",
31
+ description: "查询创建时间大于此值的任务(ISO 8601 字符串,如 2024-01-01T00:00:00Z)。",
32
+ },
33
+ endTime: {
34
+ type: "string",
35
+ description: "查询创建时间小于此值的任务(ISO 8601 字符串,如 2024-01-31T23:59:59Z)。",
36
+ },
37
+ status: {
38
+ type: "string",
39
+ description: '任务完成状态过滤。可选值为 "all"、"completed"、"pending"。默认为 "all"。',
40
+ },
41
+ },
42
+ required: [],
43
+ },
44
+ async execute(_toolCallId, params) {
45
+ const { status } = params;
46
+ if (status && !["all", "completed", "pending"].includes(status)) {
47
+ throw new ToolInputError('status 参数只能为 "all"、"completed" 或 "pending"');
48
+ }
49
+ const sessionContext = getCurrentSessionContext();
50
+ if (!sessionContext) {
51
+ throw new Error("No active XY session found.");
52
+ }
53
+ const { config, sessionId, taskId, messageId } = sessionContext;
54
+ const wsManager = getXYWebSocketManager(config);
55
+ const intentParam = {};
56
+ if (params.startTime !== undefined)
57
+ intentParam.startTime = params.startTime;
58
+ if (params.endTime !== undefined)
59
+ intentParam.endTime = params.endTime;
60
+ if (status !== undefined)
61
+ intentParam.status = status;
62
+ const command = {
63
+ header: {
64
+ namespace: "Common",
65
+ name: "Action",
66
+ },
67
+ payload: {
68
+ cardParam: {},
69
+ executeParam: {
70
+ executeMode: "background",
71
+ intentName: "QueryTodoTask",
72
+ bundleName: "com.huawei.hmos.vassistant",
73
+ needUnlock: true,
74
+ actionResponse: true,
75
+ appType: "OHOS_APP",
76
+ timeOut: 5,
77
+ intentParam,
78
+ permissionId: [],
79
+ achieveType: "INTENT",
80
+ },
81
+ responses: [
82
+ {
83
+ resultCode: "",
84
+ displayText: "",
85
+ ttsText: "",
86
+ },
87
+ ],
88
+ needUploadResult: true,
89
+ noHalfPage: false,
90
+ pageControlRelated: false,
91
+ },
92
+ };
93
+ return new Promise((resolve, reject) => {
94
+ const timeout = setTimeout(() => {
95
+ wsManager.off("data-event", handler);
96
+ reject(new Error("查询待办任务超时(60秒)"));
97
+ }, 60000);
98
+ const handler = (event) => {
99
+ if (event.intentName === "QueryTodoTask") {
100
+ clearTimeout(timeout);
101
+ wsManager.off("data-event", handler);
102
+ if (event.status === "success" && event.outputs) {
103
+ resolve({
104
+ content: [
105
+ {
106
+ type: "text",
107
+ text: JSON.stringify(event.outputs),
108
+ },
109
+ ],
110
+ });
111
+ }
112
+ else {
113
+ reject(new Error(`查询待办任务失败: ${event.status}`));
114
+ }
115
+ }
116
+ };
117
+ wsManager.on("data-event", handler);
118
+ sendCommand({
119
+ config,
120
+ sessionId,
121
+ taskId,
122
+ messageId,
123
+ command,
124
+ })
125
+ .then(() => { })
126
+ .catch((error) => {
127
+ clearTimeout(timeout);
128
+ wsManager.off("data-event", handler);
129
+ reject(error);
130
+ });
131
+ });
132
+ },
133
+ };
@@ -0,0 +1 @@
1
+ export declare const saveSelfEvolutionSkillTool: any;