Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function ScheduledTaskModelPickerRouteScreen() {
() => buildModelOptions(config, selectedModel, undefined, projectId),
[config, selectedModel, projectId],
);
const providerGroups = useMemo(() => groupByProvider(models), [models]);
const providerGroups = useMemo(
() => groupByProvider(models, config, projectId),
[models, config, projectId],
);
const selectedOption = models.find(
(option) =>
option.selection.instanceId === selectedModel?.instanceId &&
Expand Down
41 changes: 33 additions & 8 deletions apps/mobile/src/features/threads/ThreadSettingsSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ import {
pendingModelAfterPress,
providerSectionIsCollapsed,
} from "./thread-settings-sheet-state";
import { formatProviderUpdateRequiredNotice } from "@t3tools/client-runtime/providerUpdateRequiredModels";
import {
formatProviderRestrictedModelsNotice,
formatProviderUpdateRequiredNotice,
} from "@t3tools/client-runtime/providerUpdateRequiredModels";

const PRIMARY_PROVIDER_DRIVERS: ReadonlySet<string> = new Set([
"claudeAgent",
Expand Down Expand Up @@ -359,6 +362,9 @@ function ThreadSettingsSessionProvider(
props.projectId,
true,
),
config,
props.projectId,
props.lockedProviderInstanceId,
)
: props.providerGroups;
const legacyFavorites = AsyncResult.isSuccess(preferences)
Expand Down Expand Up @@ -752,7 +758,8 @@ function buildThreadSettingsCatalogItems(
) {
return [];
}
const driver = group.models[0]?.providerDriver ?? group.providerKey;
const driver =
group.models[0]?.providerDriver ?? group.withheldModels?.driver ?? group.providerKey;
const catalogModels =
session.manageHidden ||
session.showLegacy ||
Expand All @@ -775,11 +782,15 @@ function buildThreadSettingsCatalogItems(
),
session.favoriteKeys,
);
const updateRequiredNotice =
group.updateRequired && session.providerFilter !== FAVORITES_PROVIDER_FILTER
? formatProviderUpdateRequiredNotice(group.updateRequired, session.searchQuery)
: null;
if (visibleModels.length === 0 && !updateRequiredNotice) {
const withheldModels =
session.providerFilter !== FAVORITES_PROVIDER_FILTER ? group.withheldModels : undefined;
const updateRequiredNotice = withheldModels
? formatProviderUpdateRequiredNotice(withheldModels, session.searchQuery)
: null;
const restrictedNotice = withheldModels
? formatProviderRestrictedModelsNotice(withheldModels, session.searchQuery)
: null;
if (visibleModels.length === 0 && !updateRequiredNotice && !restrictedNotice) {
return [];
}
const isPrimary = driver !== undefined && PRIMARY_PROVIDER_DRIVERS.has(driver);
Expand Down Expand Up @@ -823,6 +834,15 @@ function buildThreadSettingsCatalogItems(
},
]
: []),
...(!collapsed && restrictedNotice
? [
{
kind: "notice" as const,
key: `restricted:${group.providerKey}`,
text: restrictedNotice,
},
]
: []),
];
});
}
Expand Down Expand Up @@ -1555,7 +1575,12 @@ export function ExistingThreadSettingsRouteScreen({
projectId={selectedThread.projectId}
providerInstanceId={modelSelection.instanceId}
{...(lockedProviderInstanceId ? { lockedProviderInstanceId } : {})}
providerGroups={groupByProvider(modelOptions)}
providerGroups={groupByProvider(
modelOptions,
serverConfig,
selectedThread.projectId,
lockedProviderInstanceId,
)}
selectedModel={modelSelection}
prompt={prompt}
onPromptChange={(text) => setComposerDraftText(draftKey, text)}
Expand Down
6 changes: 5 additions & 1 deletion apps/mobile/src/features/threads/new-task-flow-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ export function NewTaskFlowProvider(
setStickyComposerModelSelection(nextSelection);
};

const providerGroups = groupByProvider(modelOptions);
const providerGroups = groupByProvider(
modelOptions,
selectedEnvironmentServerConfig,
selectedProject?.id ?? null,
);
const setPrompt = (value: string) => {
if (!selectedProjectDraftKey) {
return;
Expand Down
91 changes: 91 additions & 0 deletions apps/mobile/src/lib/modelOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,97 @@ describe("mobile model options", () => {
},
);

it("never sends a model the organization turned off, and says why", () => {
const config = {
providers: [
{
instanceId: "claude_work",
driver: "claudeAgent",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [
{
slug: "claude-opus-5-5",
name: "Claude Opus 5.5",
isDefault: true,
capabilities: null,
},
],
restrictedModels: [{ slug: "claude-fable-5-1", name: "Claude Fable 5.1" }],
},
],
settings: { providerInstances: { claude_work: { driver: "claudeAgent" } } },
} as unknown as ServerConfig;
const instanceId = ProviderInstanceId.make("claude_work");
const turnedOff = { instanceId, model: "claude-fable-5-1" };

expect(isModelSelectionUnavailable(config, turnedOff, null)).toBe(true);
expect(describeUnavailableModelSelection(config, turnedOff, null).title).toBe(
"Model turned off by your organization",
);
const options = buildModelOptions(config, turnedOff, instanceId, null);
expect(options.find((option) => option.selection.model === turnedOff.model)).toMatchObject({
label: "Claude Fable 5.1",
isUnavailable: true,
});
expect(
resolveNewTaskModelSelection({
draftSelection: null,
projectDefaultSelection: null,
stickySelection: resolveDefaultableModelSelection(config, turnedOff, null),
modelOptions: options,
}),
).toMatchObject({ instanceId, model: "claude-opus-5-5" });
});

it("explains turned-off models when the stored selection is the provider's only row", () => {
const restrictedModels = [{ slug: "claude-fable-5-1", name: "Claude Fable 5.1" }];
const config = {
providers: [
{
instanceId: "claude_work",
driver: "claudeAgent",
enabled: true,
installed: true,
auth: { status: "authenticated" },
models: [{ slug: "claude-opus-5-5", name: "Claude Opus 5.5", capabilities: null }],
restrictedModels,
},
],
settings: {
providerInstances: { claude_work: { driver: "claudeAgent" } },
providerModelPreferences: { claude_work: { hiddenModels: ["claude-opus-5-5"] } },
},
} as unknown as ServerConfig;
const instanceId = ProviderInstanceId.make("claude_work");

const groups = groupByProvider(
buildModelOptions(config, { instanceId, model: "claude-fable-5-1" }, instanceId, null),
);

expect(groups.map((group) => group.models.map((option) => option.selection.model))).toEqual([
["claude-fable-5-1"],
]);
expect(groups[0]?.withheldModels?.restrictedModels).toEqual(restrictedModels);
expect(
groupByProvider(buildModelOptions(config, null, instanceId, null), config),
).toMatchObject([
{ providerKey: instanceId, models: [], withheldModels: { restrictedModels } },
]);
expect(
groupByProvider([], {
...config,
settings: {
...config.settings,
providerInstances: {
[instanceId]: { ...config.settings.providerInstances[instanceId]!, enabled: false },
},
},
}),
).toEqual([]);
});

it("rejects stored selections whose provider is not usable", () => {
const config = {
providers: [
Expand Down
Loading
Loading