()
| 29 | tool.static ? String(tool.address) : `${tool.integration}.${tool.name}`; |
| 30 | |
| 31 | export function ToolsPage() { |
| 32 | useExecutorDocumentTitle("Tools"); |
| 33 | // Merged across BOTH owners (omit-owner read). The page dedupes to one row per |
| 34 | // `<integration>.<tool>` policy id, so owner is irrelevant here — the global |
| 35 | // Tools page is a flat policy tree, not an account-grouped view. Policy writes |
| 36 | // still target a specific owner (Workspace default; see usePolicyActions). |
| 37 | const tools = useAtomValue(toolsAllAtom); |
| 38 | const refreshTools = useAtomRefresh(toolsAllAtom); |
| 39 | const policies = useAtomValue(policiesOptimisticAtom); |
| 40 | const policyActions = usePolicyActions("org"); |
| 41 | |
| 42 | const [selectedToolId, setSelectedToolId] = useState<string | null>(null); |
| 43 | |
| 44 | const policyList = useMemo( |
| 45 | () => (AsyncResult.isSuccess(policies) ? policies.value : []), |
| 46 | [policies], |
| 47 | ); |
| 48 | |
| 49 | const sortedPolicies = useMemo( |
| 50 | () => |
| 51 | [...policyList].sort((a, b) => { |
| 52 | if (a.position < b.position) return -1; |
| 53 | if (a.position > b.position) return 1; |
| 54 | return a.id < b.id ? -1 : a.id > b.id ? 1 : 0; |
| 55 | }), |
| 56 | [policyList], |
| 57 | ); |
| 58 | |
| 59 | // Address + static flag per selection id, so the detail view can fetch the |
| 60 | // right schema for the selected `<integration>.<tool>` id and its policy |
| 61 | // badge can write the matching pattern form. |
| 62 | const selectionById = useMemo(() => { |
| 63 | const map = new Map<string, { readonly address: ToolAddress; readonly static: boolean }>(); |
| 64 | if (!AsyncResult.isSuccess(tools)) return map; |
| 65 | for (const t of tools.value as readonly ToolRow[]) { |
| 66 | const id = policyId(t); |
| 67 | if (!map.has(id)) map.set(id, { address: t.address, static: t.static === true }); |
| 68 | } |
| 69 | return map; |
| 70 | }, [tools]); |
| 71 | |
| 72 | const summaries: ToolSummary[] = useMemo(() => { |
| 73 | if (!AsyncResult.isSuccess(tools)) return []; |
| 74 | const seen = new Set<string>(); |
| 75 | const rows: ToolSummary[] = []; |
| 76 | for (const t of tools.value as readonly ToolRow[]) { |
| 77 | const id = policyId(t); |
| 78 | if (seen.has(id)) continue; |
| 79 | seen.add(id); |
| 80 | // `id` is the connection-agnostic display id; match policies against the |
| 81 | // FULL address (`integration.owner.connection.tool`, the address minus its |
| 82 | // `tools.` prefix) so connection-aware rules resolve. |
| 83 | const matchId = String(t.address).replace(/^tools\./, ""); |
| 84 | rows.push({ |
| 85 | id, |
| 86 | name: id, |
| 87 | description: t.description, |
| 88 | policy: effectivePolicyFromSorted(matchId, sortedPolicies, t.requiresApproval), |
nothing calls this directly
no test coverage detected