Skip to content

Commit fcb02c1

Browse files
perf(web): scoped model availability compiles without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a702563 commit fcb02c1

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ProviderInstanceId, UnifiedSettings } from "@t3tools/contracts";
2-
import { useCallback } from "react";
32

43
import { mergeEnvironmentSettings } from "../../hooks/useSettings";
54
import { getCustomModelOptionsByInstance } from "../../modelSelection";
@@ -17,35 +16,32 @@ export function useScopedModelDisabledReason(
1716
) {
1817
const { targets } = useSettingsScope();
1918
const { environments } = useEnvironments();
20-
return useCallback(
21-
(instanceId: ProviderInstanceId, model: string): string | null => {
22-
const sourceEntry = entries.find((entry) => entry.instanceId === instanceId);
23-
for (const candidate of targets) {
24-
const environment = environments.find(
25-
(entry) => entry.environmentId === candidate.environmentId,
26-
);
27-
const config = environment?.serverConfig;
28-
if (!config) continue;
29-
const entry = applyProviderInstanceSettings(
30-
deriveProviderInstanceEntries(config.providers),
31-
candidate.settings,
32-
candidate.projectId,
33-
).find((option) => option.instanceId === instanceId);
34-
const options = getCustomModelOptionsByInstance(
35-
mergeEnvironmentSettings(candidate.settings, settings),
36-
config.providers,
37-
).get(instanceId);
38-
if (
39-
!entry?.enabled ||
40-
!entry.isAvailable ||
41-
entry.driverKind !== sourceEntry?.driverKind ||
42-
!options?.some((option) => option.slug === model && !option.isUnavailable)
43-
) {
44-
return `This model is unavailable on ${environment?.label ?? "a selected environment"}. Select that environment to choose its model separately.`;
45-
}
19+
return (instanceId: ProviderInstanceId, model: string): string | null => {
20+
const sourceEntry = entries.find((entry) => entry.instanceId === instanceId);
21+
for (const candidate of targets) {
22+
const environment = environments.find(
23+
(entry) => entry.environmentId === candidate.environmentId,
24+
);
25+
const config = environment?.serverConfig;
26+
if (!config) continue;
27+
const entry = applyProviderInstanceSettings(
28+
deriveProviderInstanceEntries(config.providers),
29+
candidate.settings,
30+
candidate.projectId,
31+
).find((option) => option.instanceId === instanceId);
32+
const options = getCustomModelOptionsByInstance(
33+
mergeEnvironmentSettings(candidate.settings, settings),
34+
config.providers,
35+
).get(instanceId);
36+
if (
37+
!entry?.enabled ||
38+
!entry.isAvailable ||
39+
entry.driverKind !== sourceEntry?.driverKind ||
40+
!options?.some((option) => option.slug === model && !option.isUnavailable)
41+
) {
42+
return `This model is unavailable on ${environment?.label ?? "a selected environment"}. Select that environment to choose its model separately.`;
4643
}
47-
return null;
48-
},
49-
[entries, environments, settings, targets],
50-
);
44+
}
45+
return null;
46+
};
5147
}

0 commit comments

Comments
 (0)