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