| 1 | import { createSelector } from "@reduxjs/toolkit"; |
| 2 | import { Tool } from "core"; |
| 3 | import { RootState } from "../store"; |
| 4 | |
| 5 | export const selectActiveTools = createSelector( |
| 6 | [ |
| 7 | (store: RootState) => store.session.mode, |
| 8 | (store: RootState) => store.config.config.tools, |
| 9 | (store: RootState) => store.ui.toolSettings, |
| 10 | (store: RootState) => store.ui.toolGroupSettings, |
| 11 | ], |
| 12 | (mode, tools, policies, groupPolicies): Tool[] => { |
| 13 | if (mode === "chat") { |
| 14 | return []; |
| 15 | } |
| 16 | else if (mode === "agent") { |
| 17 | return tools.filter( |
| 18 | (tool) => |
| 19 | policies[tool.function.name] !== "disabled" && |
| 20 | groupPolicies[tool.group] !== "exclude", |
| 21 | ); |
| 22 | } |
| 23 | else { |
| 24 | return []; |
| 25 | } |
| 26 | }, |
| 27 | ); |