@ynhcj/xiaoyi-channel 0.0.44-next → 0.0.45-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.
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
// Device type to tool name mapping.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
2
|
+
// Supports two modes:
|
|
3
|
+
// - allowlist: only listed tools are available (used for restrictive devices like car)
|
|
4
|
+
// - denylist: listed tools are blocked, everything else is available (used for permissive devices like pc)
|
|
5
|
+
// Tools NOT listed in any device entry → available to all devices (no restriction).
|
|
4
6
|
/** Known device type enum. */
|
|
5
7
|
export const DEVICE_TYPES = ["car", "pc", "phone"];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const DEVICE_TOOL_POLICY = {
|
|
9
|
+
car: { allowlist: true, tools: ["send_command_to_car"] },
|
|
10
|
+
pc: {
|
|
11
|
+
allowlist: false,
|
|
12
|
+
tools: [
|
|
13
|
+
"xiaoyi_gui_agent",
|
|
14
|
+
"call_phone",
|
|
15
|
+
"send_message",
|
|
16
|
+
"search_contact",
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
phone: { allowlist: true, tools: ["get_user_location"] },
|
|
16
20
|
};
|
|
17
21
|
export function filterToolsByDevice(tools, deviceType) {
|
|
18
22
|
if (!deviceType)
|
|
19
23
|
return tools;
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
24
|
+
const policy = DEVICE_TOOL_POLICY[deviceType];
|
|
25
|
+
if (!policy)
|
|
22
26
|
return tools; // unrecognized device → no filtering
|
|
23
|
-
|
|
27
|
+
if (policy.allowlist) {
|
|
28
|
+
return tools.filter((tool) => policy.tools.includes(tool.name));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return tools.filter((tool) => !policy.tools.includes(tool.name));
|
|
32
|
+
}
|
|
24
33
|
}
|