fix(web): resolve sidebar provider icons from the thread's own environment (#7292)
Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
18f6d03489
commit
f3fcfe1f63
3 files changed
+96
-11
No files matched your search
@@ -165,11 +165,10 @@ import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
|
||||
import { getTriggerDisplayModelLabel } from "./chat/providerIconUtils";
|
||||
import {
|
||||
deriveProviderInstanceEntries,
|
||||
deriveProviderEntriesByEnvironment,
|
||||
shouldShowInstanceBadge,
|
||||
type ProviderInstanceEntry,
|
||||
} from "../providerInstances";
|
||||
import { primaryServerProvidersAtom } from "../state/server";
|
||||
import { useThreadRunningTerminalIds } from "../state/terminalSessions";
|
||||
import { stackedThreadToast, toastManager } from "./ui/toast";
|
||||
import { Button } from "./ui/button";
|
||||
@@ -247,6 +246,8 @@ function WorkingDuration(props: { startedAt: string | null }) {
|
||||
);
|
||||
}
|
||||
|
||||
const EMPTY_PROVIDER_ENTRIES: ReadonlyMap<string, ProviderInstanceEntry> = new Map();
|
||||
|
||||
function terminalProcessLabel(count: number): string {
|
||||
return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
|
||||
}
|
||||
@@ -1862,15 +1863,18 @@ export default function Sidebar() {
|
||||
() => sortLogicalProjectsForSidebar(unsortedProjectGroups, threads, sidebarProjectSortOrder),
|
||||
[sidebarProjectSortOrder, threads, unsortedProjectGroups],
|
||||
);
|
||||
const serverProviders = useAtomValue(primaryServerProvidersAtom);
|
||||
const providerEntryByInstanceId = useMemo(
|
||||
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
|
||||
// Threads on non-primary environments (T3 Connect, hosted) resolve their
|
||||
// provider entry from their own environment's config: default instance ids
|
||||
// are driver slugs, so a flat map would collide across environments.
|
||||
const providerEntriesByEnvironment = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
deriveProviderInstanceEntries(serverProviders).map(
|
||||
(entry) => [entry.instanceId as string, entry] as const,
|
||||
deriveProviderEntriesByEnvironment(
|
||||
[...serverConfigs].map(
|
||||
([environmentId, config]) => [environmentId, config.providers] as const,
|
||||
),
|
||||
),
|
||||
[serverProviders],
|
||||
[serverConfigs],
|
||||
);
|
||||
const projectCwdByKey = useMemo(
|
||||
() =>
|
||||
@@ -1991,7 +1995,6 @@ export default function Sidebar() {
|
||||
// the partition works directly off live shells: no archived-snapshot
|
||||
// merging, no optimistic holds. Archived threads remain hidden here —
|
||||
// archive keeps its original "remove from sidebar" meaning.
|
||||
const serverConfigs = useAtomValue(environmentServerConfigsAtom);
|
||||
const {
|
||||
pinnedThreads,
|
||||
reorderablePinnedKeys,
|
||||
@@ -3598,7 +3601,10 @@ export default function Sidebar() {
|
||||
) ?? null
|
||||
}
|
||||
environmentLabel={environmentLabelById.get(thread.environmentId) ?? null}
|
||||
providerEntryByInstanceId={providerEntryByInstanceId}
|
||||
providerEntryByInstanceId={
|
||||
providerEntriesByEnvironment.get(thread.environmentId) ??
|
||||
EMPTY_PROVIDER_ENTRIES
|
||||
}
|
||||
isHighlighted={activeSearchResultIndex === index}
|
||||
isRouteActive={routeThreadKey === threadKey}
|
||||
resultId={`sidebar-thread-search-result-${index}`}
|
||||
@@ -3707,7 +3713,10 @@ export default function Sidebar() {
|
||||
`${thread.environmentId}:${thread.projectId}`,
|
||||
) ?? null
|
||||
}
|
||||
providerEntryByInstanceId={providerEntryByInstanceId}
|
||||
providerEntryByInstanceId={
|
||||
providerEntriesByEnvironment.get(thread.environmentId) ??
|
||||
EMPTY_PROVIDER_ENTRIES
|
||||
}
|
||||
timestampFormat={timestampFormat}
|
||||
onThreadClick={handleThreadClick}
|
||||
onThreadActivate={navigateToThread}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import {
|
||||
applyProviderInstanceSettings,
|
||||
deriveProviderEntriesByEnvironment,
|
||||
deriveProviderInstanceEntries,
|
||||
getDefaultProviderInstanceModel,
|
||||
isProviderInstancePickerReady,
|
||||
@@ -17,6 +18,7 @@ function provider(input: {
|
||||
enabled?: boolean;
|
||||
availability?: ServerProvider["availability"];
|
||||
displayName?: string;
|
||||
accentColor?: string;
|
||||
status?: ServerProvider["status"];
|
||||
models?: ServerProvider["models"];
|
||||
}): ServerProvider {
|
||||
@@ -24,6 +26,7 @@ function provider(input: {
|
||||
instanceId: ProviderInstanceId.make(input.instanceId),
|
||||
driver: input.provider,
|
||||
...(input.displayName ? { displayName: input.displayName } : {}),
|
||||
...(input.accentColor ? { accentColor: input.accentColor } : {}),
|
||||
enabled: input.enabled ?? true,
|
||||
installed: true,
|
||||
version: null,
|
||||
@@ -132,6 +135,52 @@ describe("deriveProviderInstanceEntries", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("deriveProviderEntriesByEnvironment", () => {
|
||||
it("keeps same-id default instances distinct per environment", () => {
|
||||
const byEnvironment = deriveProviderEntriesByEnvironment([
|
||||
[
|
||||
"local",
|
||||
[
|
||||
provider({
|
||||
provider: ProviderDriverKind.make("claude"),
|
||||
instanceId: "claude",
|
||||
displayName: "Claude Local",
|
||||
accentColor: "#112233",
|
||||
}),
|
||||
],
|
||||
],
|
||||
[
|
||||
"remote",
|
||||
[
|
||||
provider({
|
||||
provider: ProviderDriverKind.make("claude"),
|
||||
instanceId: "claude",
|
||||
displayName: "Claude Remote",
|
||||
accentColor: "#445566",
|
||||
}),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
expect(byEnvironment.get("local")?.get("claude")?.displayName).toBe("Claude Local");
|
||||
expect(byEnvironment.get("local")?.get("claude")?.accentColor).toBe("#112233");
|
||||
expect(byEnvironment.get("remote")?.get("claude")?.displayName).toBe("Claude Remote");
|
||||
expect(byEnvironment.get("remote")?.get("claude")?.accentColor).toBe("#445566");
|
||||
});
|
||||
|
||||
it("never falls back to another environment's instances", () => {
|
||||
const byEnvironment = deriveProviderEntriesByEnvironment([
|
||||
["local", [provider({ provider: ProviderDriverKind.make("codex"), instanceId: "codex" })]],
|
||||
["empty", []],
|
||||
]);
|
||||
|
||||
expect(byEnvironment.get("empty")?.get("codex")).toBeUndefined();
|
||||
// Every environment gets its own bucket, so an absent lookup is a real
|
||||
// "this environment has no such instance", not a missing key.
|
||||
expect(byEnvironment.get("empty")?.size).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveSelectableProviderInstance", () => {
|
||||
it("returns the requested instance when it is enabled and available", () => {
|
||||
const requested = ProviderInstanceId.make("claude_work");
|
||||
|
||||
@@ -200,6 +200,33 @@ export function deriveProviderInstanceEntries(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Project several environments' `ServerProvider[]` into a nested
|
||||
* `environmentId → instanceId → entry` lookup.
|
||||
*
|
||||
* Instance ids are per-environment routing keys, and `defaultInstanceIdForDriver`
|
||||
* makes the default id literally the driver slug, so every environment running
|
||||
* the same driver reports the same id. Flattening across environments would
|
||||
* clobber entries and mis-resolve accent colors; lookups must stay scoped to
|
||||
* the thread's own environment.
|
||||
*/
|
||||
export function deriveProviderEntriesByEnvironment(
|
||||
providersByEnvironment: Iterable<readonly [string, ReadonlyArray<ServerProvider>]>,
|
||||
): ReadonlyMap<string, ReadonlyMap<string, ProviderInstanceEntry>> {
|
||||
const byEnvironment = new Map<string, ReadonlyMap<string, ProviderInstanceEntry>>();
|
||||
for (const [environmentId, providers] of providersByEnvironment) {
|
||||
byEnvironment.set(
|
||||
environmentId,
|
||||
new Map(
|
||||
deriveProviderInstanceEntries(providers).map(
|
||||
(entry) => [entry.instanceId as string, entry] as const,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return byEnvironment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overlay the current settings configuration onto streamed provider snapshots.
|
||||
* Provider probes can briefly retain their previous `enabled` value after a
|
||||
|
||||
Reference in new issue
Block a user