MCPcopy Index your code
hub / github.com/CommonstackAI/UncommonRoute / Routing

Function Routing

frontend/dashboard/src/components/Routing.tsx:34–348  ·  view source on GitHub ↗
({ onRefresh }: Props)

Source from the content-addressed store, hash-verified

32}
33
34export default function Routing({ onRefresh }: Props) {
35 const [config, setConfig] = useState<RoutingConfigState | null>(null);
36 const [mapping, setMapping] = useState<Mapping | null>(null);
37 const [drafts, setDrafts] = useState<Record<string, DraftState>>({});
38 const [busyKey, setBusyKey] = useState<string | null>(null);
39 const [notice, setNotice] = useState<NoticeState | null>(null);
40 const [editorMode, setEditorMode] = useState<ModeName>("auto");
41
42 const load = useCallback(async () => {
43 const [nextConfig, nextMapping] = await Promise.all([
44 fetchRoutingConfig(),
45 fetchMapping(),
46 ]);
47 if (nextConfig) {
48 setConfig(nextConfig);
49 setDrafts(buildDrafts(nextConfig));
50 setEditorMode(nextConfig.default_mode as ModeName);
51 }
52 if (nextMapping) setMapping(nextMapping);
53 }, []);
54
55 useEffect(() => {
56 load();
57 }, [load]);
58
59 useEffect(() => {
60 if (!notice) return;
61 const timeoutId = window.setTimeout(() => setNotice(null), 2400);
62 return () => window.clearTimeout(timeoutId);
63 }, [notice]);
64
65 const defaultMode = config?.default_mode ?? "auto";
66 const editable = config?.editable ?? true;
67 const modeMeta = getModeMeta(defaultMode);
68 const editModeMeta = getModeMeta(editorMode);
69 const selectedModeRows = config?.modes?.[editorMode]?.tiers ?? {};
70 const modelOptions = mapping?.pool.map((model) => model.id) ?? [];
71 const modeSwitchBusy = busyKey?.startsWith("mode:") ?? false;
72
73 function applyConfig(next: RoutingConfigState) {
74 setConfig(next);
75 setDrafts(buildDrafts(next));
76 }
77
78 function showNotice(text: string, tone: NoticeState["tone"] = "success") {
79 setNotice({ text, tone });
80 }
81
82 async function handleModeChange(nextMode: ModeName) {
83 if (!editable || nextMode === defaultMode) return;
84 setBusyKey(`mode:${nextMode}`);
85 setNotice(null);
86 const next = await setDefaultRoutingMode(nextMode);
87 if (next) {
88 applyConfig(next);
89 showNotice(`Default mode set to ${nextMode}.`);
90 onRefresh?.();
91 } else {

Callers

nothing calls this directly

Calls 8

fetchRoutingConfigFunction · 0.90
fetchMappingFunction · 0.90
buildDraftsFunction · 0.85
handleModeChangeFunction · 0.85
draftKeyFunction · 0.85
createDraftFunction · 0.85
loadFunction · 0.70
getModeMetaFunction · 0.70

Tested by

no test coverage detected