Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import {
3 type EnvironmentId,
4 PROVIDER_DISPLAY_NAMES,
5 type ProviderDriverKind,
6 type ProviderInstanceId,
7} from "@t3tools/contracts";
8import * as Option from "effect/Option";
9import { Atom } from "effect/reactivity";
10
11import { brandProviderInstanceEntries, deriveProviderInstanceEntries } from "~/providerInstances";
12import { serverEnvironment } from "~/state/server";
13import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
14
15interface ProviderStartingPresentation {
16 readonly displayName: string;
17 readonly acpRegistryAgentId: string | undefined;
18 readonly acpRegistryIconUrl: string | undefined;
19}
20
21// Keyed per instance so provider status pushes don't rerender the live row.
22const providerStartingPresentationAtom = Atom.family((key: string) =>
23 Atom.make((get): ProviderStartingPresentation | null => {
24 const [environmentId, instanceId] = key.split("\u0000") as [string, string];
25 const config = get(serverEnvironment.configValueAtom(environmentId as EnvironmentId));
26 const provider = config?.providers.find((candidate) => candidate.instanceId === instanceId);
27 if (!config || !provider) return null;
28 const [entry] = brandProviderInstanceEntries(
29 deriveProviderInstanceEntries([provider]),
30 config.settings,
31 );
32 if (!entry) return null;
33 const next = {
34 displayName: entry.displayName,
35 acpRegistryAgentId: entry.acpRegistryAgentId,
36 acpRegistryIconUrl: entry.acpRegistryIconUrl,
37 };
38 const previous = Option.getOrNull(get.self<ProviderStartingPresentation | null>());
39 return previous &&
40 previous.displayName === next.displayName &&
41 previous.acpRegistryAgentId === next.acpRegistryAgentId &&
42 previous.acpRegistryIconUrl === next.acpRegistryIconUrl
43 ? previous
44 : next;
45 }).pipe(Atom.withLabel("provider-starting-presentation")),
46);
47
48/** The logo of the provider a run is waiting on, shown in place of the thinking icon. */
49export function ProviderStartingIcon(props: {
50 readonly environmentId: EnvironmentId | null;
51 readonly instanceId: ProviderInstanceId;
52 readonly driver: ProviderDriverKind;
53}) {
54 const presentation = useAtomValue(
55 providerStartingPresentationAtom(`${props.environmentId ?? ""}\u0000${props.instanceId}`),
56 );
57 return (
58 <ProviderInstanceIcon
59 driverKind={props.driver}
60 displayName={presentation?.displayName ?? PROVIDER_DISPLAY_NAMES[props.driver] ?? ""}
61 acpRegistryAgentId={presentation?.acpRegistryAgentId}
62 acpRegistryIconUrl={presentation?.acpRegistryIconUrl}
63 className="z-auto"
64 iconClassName="size-4"
65 />
66 );
67}