MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ToolsPage

Function ToolsPage

packages/react/src/pages/tools.tsx:36–186  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34 tool.static ? String(tool.address) : `${tool.integration}.${tool.name}`;
35
36export function ToolsPage() {
37 useExecutorDocumentTitle("Tools");
38 // Merged across BOTH owners (omit-owner read). The page dedupes to one row per
39 // `<integration>.<tool>` policy id, so owner is irrelevant here — the global
40 // Tools page is a flat policy tree, not an account-grouped view. Policy writes
41 // still target a specific owner (Workspace default; see usePolicyActions).
42 const tools = useAtomValue(toolsAllAtom);
43 const refreshTools = useAtomRefresh(toolsAllAtom);
44 const policies = useAtomValue(policiesOptimisticAtom);
45 const policyActions = usePolicyActions("org");
46 // Policies here are workspace rules, which the server refuses for non-admin
47 // members. Offer the menus only to those who can actually write them.
48 const canSetPolicy = useCanCreateWorkspaceConnections();
49 const onSetPolicy = canSetPolicy
50 ? (pattern: string, action: ToolPolicyAction) => void policyActions.set(pattern, action)
51 : undefined;
52 const onClearPolicy = canSetPolicy
53 ? (pattern: string, policyId?: string) => void policyActions.clear(pattern, policyId)
54 : undefined;
55
56 const [selectedToolId, setSelectedToolId] = useState<string | null>(null);
57
58 const policyList = useMemo(
59 () => (AsyncResult.isSuccess(policies) ? policies.value : []),
60 [policies],
61 );
62
63 const sortedPolicies = useMemo(
64 () =>
65 [...policyList].sort((a, b) => {
66 if (a.position < b.position) return -1;
67 if (a.position > b.position) return 1;
68 return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
69 }),
70 [policyList],
71 );
72
73 // Address + static flag per selection id, so the detail view can fetch the
74 // right schema for the selected `<integration>.<tool>` id and its policy
75 // badge can write the matching pattern form.
76 const selectionById = useMemo(() => {
77 const map = new Map<string, { readonly address: ToolAddress; readonly static: boolean }>();
78 if (!AsyncResult.isSuccess(tools)) return map;
79 for (const t of tools.value as readonly ToolRow[]) {
80 const id = policyId(t);
81 if (!map.has(id)) map.set(id, { address: t.address, static: t.static === true });
82 }
83 return map;
84 }, [tools]);
85
86 const summaries: ToolSummary[] = useMemo(() => {
87 if (!AsyncResult.isSuccess(tools)) return [];
88 const seen = new Set<string>();
89 const rows: ToolSummary[] = [];
90 for (const t of tools.value as readonly ToolRow[]) {
91 const id = policyId(t);
92 if (seen.has(id)) continue;
93 seen.add(id);

Callers

nothing calls this directly

Calls 11

useExecutorDocumentTitleFunction · 0.90
usePolicyActionsFunction · 0.90
isAsyncResultLoadingFunction · 0.90
policyIdFunction · 0.85
clearMethod · 0.80
pushMethod · 0.80
setMethod · 0.65
replaceMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected