Open History to see the last commit
1import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2import {
3 normalizeProviderAccentColor,
4 resolveProviderInstanceDisplayName,
5 shouldShowInstanceBadge,
6} from "@t3tools/client-runtime/state/provider-instance-display";
7import type { EnvironmentId, ProviderDriverKind, ServerConfig } from "@t3tools/contracts";
8
9/** What a thread row needs to draw the provider glyph and its account badge. */
10export interface ThreadRowProviderInstance {
11 readonly driverKind: ProviderDriverKind;
12 readonly displayName: string;
13 readonly accentColor?: string | undefined;
14 readonly showBadge: boolean;
15}
16
17/**
18 * Resolve the provider instance a thread runs on, scoped to the thread's own
19 * environment: default instance ids are the driver slug, so the same id
20 * names a different account on every server.
21 */
22export function resolveThreadProviderInstance(
23 serverConfigs: ReadonlyMap<EnvironmentId, ServerConfig>,
24 thread: EnvironmentThreadShell,
25): ThreadRowProviderInstance | null {
26 const providers = serverConfigs.get(thread.environmentId)?.providers ?? [];
27 const instanceId = thread.session?.providerInstanceId ?? thread.modelSelection.instanceId;
28 const snapshot = providers.find((provider) => provider.instanceId === instanceId);
29 if (!snapshot) return null;
30 const entry = {
31 driverKind: snapshot.driver,
32 displayName: resolveProviderInstanceDisplayName(snapshot),
33 accentColor: normalizeProviderAccentColor(snapshot.accentColor),
34 };
35 return {
36 ...entry,
37 showBadge: shouldShowInstanceBadge(
38 entry,
39 providers.map((provider) => ({ driverKind: provider.driver })),
40 ),
41 };
42}