From c860c5a9f7eab6f65191654ad6fbe5b1a05f5f22 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:23:48 -0500 Subject: [PATCH 01/33] test(settings): profile limits project providers Signed-off-by: Yordis Prieto --- packages/contracts/src/settings.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts index 1db913e38ba3b..53fab7d47a667 100644 --- a/packages/contracts/src/settings.test.ts +++ b/packages/contracts/src/settings.test.ts @@ -488,6 +488,31 @@ describe("resolveProjectProviderInstanceEnabled", () => { }; expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(false); }); + + it("limits an assigned project to its profile even when a project override enables another instance", () => { + const settings = decodeServerSettings({ + providerInstances: { + [instanceId]: { driver: "codex", enabled: true }, + claude_work: { driver: "claudeAgent", enabled: true }, + }, + projectSettingsOverrides: { + [projectId]: { providerInstances: { claude_work: { enabled: true } } }, + }, + trogonStack: { + providerProfiles: { personal: { name: "Personal", providerInstanceIds: [instanceId] } }, + projectProfiles: { [projectId]: "personal" }, + }, + }); + expect(resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)).toBe(true); + expect( + resolveProjectProviderInstanceEnabled( + settings, + projectId, + ProviderInstanceId.make("claude_work"), + ), + ).toBe(false); + expect(encodeServerSettings(settings)).toHaveProperty("trogonStack"); + }); }); describe("requiredScopesForProjectMutation", () => { From 8b362b4c6ec54ecf74b0a39a7778fb5cda9e73db Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:28:01 -0500 Subject: [PATCH 02/33] feat(settings): enforce project provider profiles Signed-off-by: Yordis Prieto --- .../src/orchestration-v2/Orchestrator.ts | 10 +++- packages/contracts/src/settings.ts | 58 +++++++++++++++++-- packages/shared/src/serverSettings.ts | 29 ++++++++++ 3 files changed, 91 insertions(+), 6 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 96237476477a7..ef1d86f27d596 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -71,6 +71,7 @@ import { isRuntimeModeAbove, resolveProviderInstanceEnabled, resolveProjectProviderInstanceEnabled, + isProviderInstanceAllowedByProfile, type ProviderSessionId, RunId, RuntimeMode, @@ -2544,9 +2545,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ? settings.providerInstances[queuedRun.providerInstanceId] : undefined; const instanceDisabledForProject = - projectOverride !== undefined + !isProviderInstanceAllowedByProfile( + settings, + projection.thread.projectId, + queuedRun.providerInstanceId, + ) || + (projectOverride !== undefined ? !projectOverride - : machineInstance !== undefined && !resolveProviderInstanceEnabled(machineInstance); + : machineInstance !== undefined && !resolveProviderInstanceEnabled(machineInstance)); if ( worktreeMissing || instanceDisabledForProject || diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index b58c1d59de1df..a4d8f0af4e1e1 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -1359,7 +1359,26 @@ export const CloudSpeechCredentials = Schema.Struct({ openrouter: CloudSpeechCredential, }); +export const ProviderProfile = Schema.Struct({ + name: TrimmedNonEmptyString, + providerInstanceIds: Schema.Array(ProviderInstanceId), +}); +export type ProviderProfile = typeof ProviderProfile.Type; + +export const TrogonStackSettings = Schema.Struct({ + providerProfiles: Schema.Record(TrimmedNonEmptyString, ProviderProfile).pipe( + Schema.withDecodingDefault(Effect.succeed({})), + ), + projectProfiles: Schema.Record(ProjectId, TrimmedNonEmptyString).pipe( + Schema.withDecodingDefault(Effect.succeed({})), + ), +}); +export type TrogonStackSettings = typeof TrogonStackSettings.Type; + export const ServerSettings = Schema.Struct({ + trogonStack: TrogonStackSettings.pipe( + Schema.withDecodingDefault(Effect.succeed(Schema.decodeSync(TrogonStackSettings)({}))), + ), // Null means unmigrated; empty is authoritative and must not resurrect cleared preferences. favorites: Schema.NullOr(ModelFavorites).pipe(Schema.withDecodingDefault(Effect.succeed(null))), providerModelPreferences: Schema.NullOr(ProviderModelPreferences).pipe( @@ -1636,10 +1655,12 @@ export const resolveProviderInstanceEnabled = ( }; export const resolveProjectProviderInstanceEnabled = ( - settings: Pick, + settings: Pick & + Partial>, projectId: ProjectId | null, instanceId: ProviderInstanceId, ): boolean => { + if (!isProviderInstanceAllowedByProfile(settings, projectId, instanceId)) return false; const override = projectId === null ? undefined @@ -1653,6 +1674,20 @@ export const resolveProjectProviderInstanceEnabled = ( : isUnconfiguredDefaultInstanceEnabled(instanceId); }; +export const isProviderInstanceAllowedByProfile = ( + settings: Partial>, + projectId: ProjectId | null, + instanceId: ProviderInstanceId, +): boolean => { + if (projectId === null) return true; + const profileId = settings.trogonStack?.projectProfiles[projectId]; + if (profileId === undefined) return true; + return ( + settings.trogonStack?.providerProfiles[profileId]?.providerInstanceIds.includes(instanceId) ?? + false + ); +}; + /** The text generator a selection names, if any; it takes precedence over a provider instance. */ export const textGeneratorForSelection = ( settings: Pick, @@ -1667,12 +1702,14 @@ export const resolveTextGenerationSelectionEnabled = ( settings: Pick< ServerSettings, "providerInstances" | "projectSettingsOverrides" | "textGenerators" - >, + > & + Partial>, projectId: ProjectId | null, instanceId: ProviderInstanceId, ): boolean => - textGeneratorForSelection(settings, instanceId)?.enabled ?? - resolveProjectProviderInstanceEnabled(settings, projectId, instanceId); + isProviderInstanceAllowedByProfile(settings, projectId, instanceId) && + (textGeneratorForSelection(settings, instanceId)?.enabled ?? + resolveProjectProviderInstanceEnabled(settings, projectId, instanceId)); const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings); @@ -1794,6 +1831,16 @@ const ModelSelectionPatch = Schema.Struct({ }); export const ServerSettingsPatch = Schema.Struct({ + trogonStack: Schema.optionalKey( + Schema.Struct({ + providerProfiles: Schema.optionalKey( + Schema.Record(TrimmedNonEmptyString, Schema.NullOr(ProviderProfile)), + ), + projectProfiles: Schema.optionalKey( + Schema.Record(ProjectId, Schema.NullOr(TrimmedNonEmptyString)), + ), + }), + ), setModelFavorites: Schema.optionalKey( Schema.Array(Schema.Struct({ ...ModelFavorite.fields, favorite: Schema.Boolean })), ), @@ -1998,6 +2045,9 @@ export function requiredScopesForServerSettingsPatch( if (value === undefined) continue; if (key === "requireConnectDeviceApproval") { changesAccess = true; + } else if (key === "trogonStack") { + changesProviders = true; + changesSettings = true; } else if ( key === "providers" || key === "providerInstances" || diff --git a/packages/shared/src/serverSettings.ts b/packages/shared/src/serverSettings.ts index 023c6eb74333e..42e5e52b8dcb2 100644 --- a/packages/shared/src/serverSettings.ts +++ b/packages/shared/src/serverSettings.ts @@ -383,6 +383,20 @@ function patchedIdleCompaction( return globalIdleCompaction(current) === "off" ? "off" : "onReturn"; } +function applyNullableEntries( + current: Readonly>, + patch: Readonly> | undefined, +): Record { + const next = { ...current } as Record; + if (patch === undefined) return next; + for (const key of Object.keys(patch) as Key[]) { + const value = patch[key]; + if (value === null) delete next[key]; + else if (value !== undefined) next[key] = value; + } + return next; +} + export function applyServerSettingsPatch( current: ServerSettings, rawPatch: ServerSettingsPatch, @@ -409,6 +423,7 @@ export function applyServerSettingsPatch( usageModelAliases: usageModelAliasesPatch, // Entry replacement: deepMerge would keep keys the client meant to clear. projectSettingsOverrides: projectSettingsOverridesPatch, + trogonStack: trogonStackPatch, projectAgentBrowserAccessOverrides: _legacyBrowserAccess, projectAutoPullOverrides: _legacyAutoPull, projectScriptOverrides: _legacyScripts, @@ -506,6 +521,20 @@ export function applyServerSettingsPatch( ...next, favorites, providerModelPreferences: nextModelPreferences, + ...(trogonStackPatch === undefined + ? {} + : { + trogonStack: { + providerProfiles: applyNullableEntries( + current.trogonStack.providerProfiles, + trogonStackPatch.providerProfiles, + ), + projectProfiles: applyNullableEntries( + current.trogonStack.projectProfiles, + trogonStackPatch.projectProfiles, + ), + }, + }), ...(worktreeCleanupPatch === undefined ? {} : { From 9209d234b4dc77f55d22d27f09337cd5cf046d32 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:30:49 -0500 Subject: [PATCH 03/33] test(server): reject profile-disallowed text generation Signed-off-by: Yordis Prieto --- .../CodexTextGeneration.test.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/apps/server/src/textGeneration/CodexTextGeneration.test.ts b/apps/server/src/textGeneration/CodexTextGeneration.test.ts index 1a1a5c43b0a0d..2b0884475d086 100644 --- a/apps/server/src/textGeneration/CodexTextGeneration.test.ts +++ b/apps/server/src/textGeneration/CodexTextGeneration.test.ts @@ -635,6 +635,7 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => { const PREFLIGHT_PRIMARY_STATES = [ "ready", + "profile blocks primary", "pending", "exhausted", "not installed", @@ -750,6 +751,16 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima }, }, defaultModelSelection: threadDefault, + ...(primaryState === "profile blocks primary" + ? { + trogonStack: { + providerProfiles: { + work: { name: "Work", providerInstanceIds: [fallback] }, + }, + projectProfiles: { [projectId]: "work" }, + }, + } + : {}), ...(primaryState === "not installed, fallback disabled for project" ? { projectSettingsOverrides: { @@ -766,15 +777,20 @@ it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (prima ), ), ); - expect( - yield* service.generateThreadTitle({ - cwd: "/tmp", - message: "hello", - linkedContext: "", - modelSelection: selection, - projectId, - }), - ).toEqual({ title: "Generated title" }); + const generation = service.generateThreadTitle({ + cwd: "/tmp", + message: "hello", + linkedContext: "", + modelSelection: selection, + projectId, + }); + if (primaryState === "profile blocks primary") { + const error = yield* generation.pipe(Effect.flip); + expect(error._tag).toBe("TextGenerationError"); + expect(calls).toEqual([]); + return; + } + expect(yield* generation).toEqual({ title: "Generated title" }); expect(calls).toEqual([ primaryState === "ready" || primaryState === "pending" || From 877c5b1eb58d4a31e7903bc65323c011425f7ed6 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:32:42 -0500 Subject: [PATCH 04/33] fix(server): respect profiles during text generation Signed-off-by: Yordis Prieto --- .../src/textGeneration/TextGeneration.ts | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/server/src/textGeneration/TextGeneration.ts b/apps/server/src/textGeneration/TextGeneration.ts index 818afb4fae553..5a53a5173f564 100644 --- a/apps/server/src/textGeneration/TextGeneration.ts +++ b/apps/server/src/textGeneration/TextGeneration.ts @@ -4,6 +4,7 @@ import * as Layer from "effect/Layer"; import type { ModelSelection, ProjectId, ProviderInstanceId } from "@t3tools/contracts"; import { isProviderAvailable, + isProviderInstanceAllowedByProfile, isProviderTextGenerationCapable, resolveProjectProviderInstanceEnabled, } from "@t3tools/contracts"; @@ -86,6 +87,24 @@ export const make = Effect.gen(function* () { modelSelection: ModelSelection, ) => Effect.Effect, ) { + const profileSettings = yield* serverSettings.getSettings.pipe( + Effect.mapError( + (cause) => + new TextGenerationError({ + operation, + detail: "Could not read provider profile settings.", + cause, + }), + ), + ); + if ( + !isProviderInstanceAllowedByProfile(profileSettings, projectId ?? null, selection.instanceId) + ) { + return yield* new TextGenerationError({ + operation, + detail: "This provider is not allowed by the project's provider profile.", + }); + } const textGenerator = yield* textGenerators.runner(selection.instanceId); // A review guide reaches a text generator only through a fallback; it needs an agent instead. const textGeneratorId = selection.instanceId; @@ -114,16 +133,7 @@ export const make = Effect.gen(function* () { (selected.status === "error" && (!selected.installed || selected.auth.status === "unauthenticated")))); if (unusable || exhaustedUsageWindow(selected, now, selection.model)) { - const settings = yield* serverSettings.getSettings.pipe( - Effect.mapError( - (cause) => - new TextGenerationError({ - operation, - detail: "Could not read fallback model settings.", - cause, - }), - ), - ); + const settings = profileSettings; selection = fallbackTextGenerationModelSelection( settings.providerInstances, From b36f1cf3c299b60c459e05660c239d6998c1bd50 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:34:57 -0500 Subject: [PATCH 05/33] test(server): require profile for new projects Signed-off-by: Yordis Prieto --- apps/mobile/src/lib/modelOptions.test.ts | 133 ++++++++++++++++++ apps/mobile/src/lib/modelOptions.ts | 33 +++++ .../server/src/project/ProjectService.test.ts | 31 +++- 3 files changed, 196 insertions(+), 1 deletion(-) diff --git a/apps/mobile/src/lib/modelOptions.test.ts b/apps/mobile/src/lib/modelOptions.test.ts index 73ce33f99dbf1..7a4a2d135b009 100644 --- a/apps/mobile/src/lib/modelOptions.test.ts +++ b/apps/mobile/src/lib/modelOptions.test.ts @@ -614,6 +614,139 @@ describe("mobile model options", () => { } as unknown as ServerConfig; } + it("allows only named provider instances in the assigned profile, without restricting legacy projects", () => { + const otherProjectId = ProjectId.make("legacy-project"); + const personalInstance = ProviderInstanceId.make("codex_personal"); + const settings: ServerSettings = { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true }, + [personalInstance]: { driver: ProviderDriverKind.make("codex"), enabled: true }, + }, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: { + work: { name: "Work", providerInstanceIds: [instanceId] }, + }, + projectProfiles: { [projectId]: "work" }, + }, + }; + const config = { + ...configWith(settings), + providers: [ + ...configWith(settings).providers, + { + ...configWith(settings).providers[0], + instanceId: personalInstance, + displayName: "Codex Personal", + }, + ], + } as ServerConfig; + const personalSelection = { instanceId: personalInstance, model: "model-a" }; + + expect( + buildModelOptions(config, null, undefined, projectId).map((option) => option.providerKey), + ).toEqual([instanceId]); + expect( + buildModelOptions(config, null, undefined, otherProjectId).map( + (option) => option.providerKey, + ), + ).toEqual([instanceId, personalInstance]); + expect(isModelSelectionUnavailable(config, personalSelection, projectId)).toBe(true); + expect(resolveSelectableModelSelection(config, personalSelection, projectId)).toBeNull(); + expect(resolveDefaultableModelSelection(config, personalSelection, projectId)).toBeNull(); + expect(buildModelOptions(config, personalSelection, undefined, projectId)).toMatchObject([ + { providerKey: instanceId }, + { providerKey: personalInstance, isUnavailable: true }, + ]); + expect(describeUnavailableModelSelection(config, personalSelection, projectId)).toMatchObject( + { + title: "Provider not in this project's profile", + }, + ); + }); + + it("fails closed when an assigned profile has been removed", () => { + const settings: ServerSettings = { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true }, + }, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: {}, + projectProfiles: { [projectId]: "missing" }, + }, + }; + const selection = { instanceId, model: "model-a" }; + const config = configWith(settings); + + expect(buildModelOptions(config, null, undefined, projectId)).toEqual([]); + expect(isModelSelectionUnavailable(config, selection, projectId)).toBe(true); + expect(resolveSelectableModelSelection(config, selection, projectId)).toBeNull(); + }); + + it("blocks a new project pending assignment without changing a legacy project's access", () => { + const legacyProjectId = ProjectId.make("legacy-project"); + const settings = { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { + [instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true }, + }, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: { work: { name: "Work", providerInstanceIds: [instanceId] } }, + projectProfiles: {}, + projectsRequiringProfile: { [projectId]: true }, + }, + } satisfies ServerSettings; + const config = configWith(settings); + const selection = { instanceId, model: "model-a" }; + + expect(buildModelOptions(config, null, undefined, projectId)).toEqual([]); + expect(isModelSelectionUnavailable(config, selection, projectId)).toBe(true); + expect(resolveSelectableModelSelection(config, selection, projectId)).toBeNull(); + expect(buildModelOptions(config, null, undefined, legacyProjectId)).toHaveLength(1); + expect(describeUnavailableModelSelection(config, selection, projectId).title).toBe( + "Provider profile required for this project", + ); + }); + + it("rejects a saved Antigravity selection excluded by an assigned profile", () => { + const antigravityInstanceId = ProviderInstanceId.make("antigravity_work"); + const config = { + providers: [ + { + instanceId: antigravityInstanceId, + driver: "antigravity", + enabled: true, + installed: true, + auth: { status: "authenticated" }, + availability: "available", + models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: null }], + }, + ], + settings: { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { + [antigravityInstanceId]: { + driver: ProviderDriverKind.make("antigravity"), + enabled: true, + }, + }, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: { work: { name: "Work", providerInstanceIds: [] } }, + projectProfiles: { [projectId]: "work" }, + }, + }, + } as unknown as ServerConfig; + const selection = { instanceId: antigravityInstanceId, model: "model-a" }; + + expect(resolveSelectableModelSelection(config, selection, projectId)).toBeNull(); + expect(isModelSelectionUnavailable(config, selection, projectId)).toBe(true); + }); + it("refuses to send a non-Antigravity model the project turned off", () => { const settings: ServerSettings = { ...DEFAULT_SERVER_SETTINGS, diff --git a/apps/mobile/src/lib/modelOptions.ts b/apps/mobile/src/lib/modelOptions.ts index e68a84b585417..67c68697503e1 100644 --- a/apps/mobile/src/lib/modelOptions.ts +++ b/apps/mobile/src/lib/modelOptions.ts @@ -15,6 +15,7 @@ import { disallowedProviderMessage, isManagedDriverAllowed, isProviderDriverKind, + isProviderInstanceAllowedByProfile, resolveProjectProviderInstanceEnabled, } from "@t3tools/contracts"; import { @@ -110,6 +111,12 @@ function isDisabledForProject( instanceId: ModelSelection["instanceId"], projectId: ProjectId | null, ): boolean { + if ( + config?.settings && + !isProviderInstanceAllowedByProfile(config.settings, projectId, instanceId) + ) { + return true; + } if (isProjectDisabledOverride(config, instanceId, projectId)) { return true; } @@ -222,6 +229,26 @@ export function describeUnavailableModelSelection( detail: `${disallowedProviderMessage(config?.managedPolicy?.organization, label)} Choose another model.`, }; } + if ( + projectId !== null && + config?.settings?.trogonStack.projectsRequiringProfile?.[projectId] === true && + config.settings.trogonStack.projectProfiles[projectId] === undefined + ) { + return { + title: "Provider profile required for this project", + detail: "Assign a provider profile in project Settings before choosing a model.", + }; + } + if ( + config?.settings && + !isProviderInstanceAllowedByProfile(config.settings, projectId, selection.instanceId) + ) { + return { + title: "Provider not in this project's profile", + detail: + "Choose an instance in this project's provider profile or change the project's profile in Settings.", + }; + } return isDisabledForProject(config, provider, selection.instanceId, projectId) ? { title: "Model turned off for this project", @@ -241,6 +268,12 @@ export function resolveSelectableModelSelection( if (!selection || !config) { return selection; } + if ( + config.settings && + !isProviderInstanceAllowedByProfile(config.settings, projectId, selection.instanceId) + ) { + return null; + } const provider = config.providers.find( (candidate) => candidate.instanceId === selection.instanceId, ); diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index 492379beecc26..c2de08a42b585 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -5,7 +5,13 @@ import * as Tracer from "effect/Tracer"; import { assert, it } from "@effect/vitest"; import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NodeServices from "@effect/platform-node/NodeServices"; -import { CommandId, type Project, ProjectId, ProviderInstanceId } from "@t3tools/contracts"; +import { + CommandId, + type Project, + ProjectId, + ProviderInstanceId, + resolveProjectProviderInstanceEnabled, +} from "@t3tools/contracts"; import * as Deferred from "effect/Deferred"; import * as Effect from "effect/Effect"; import * as Fiber from "effect/Fiber"; @@ -230,6 +236,29 @@ const waitForProject = Effect.fn("ProjectServiceTest.waitForProject")(function* }); it.layer(layerTest)("ProjectService", (it) => { + it.effect("requires a profile for projects created after profiles are configured", () => + Effect.gen(function* () { + const settings = yield* ServerSettings.ServerSettingsService; + const service = yield* ProjectService.ProjectService; + const projectId = ProjectId.make("project:needs-profile"); + const instanceId = ProviderInstanceId.make("codex"); + yield* settings.updateSettings({ + trogonStack: { + providerProfiles: { work: { name: "Work", providerInstanceIds: [instanceId] } }, + }, + }); + yield* service.create({ + commandId: CommandId.make("command:project:needs-profile"), + projectId, + title: "New project", + workspaceRoot: "/work/needs-profile", + }); + assert.isFalse( + resolveProjectProviderInstanceEnabled(yield* settings.getSettings, projectId, instanceId), + ); + }), + ); + it.effect("creates, updates, resolves, snapshots, and soft-deletes projects", () => Effect.gen(function* () { const service = yield* ProjectService.ProjectService; From 74a4588049ee41e9abde24768b36b450d101ff4c Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:39:19 -0500 Subject: [PATCH 06/33] feat(server): require profiles for new projects Signed-off-by: Yordis Prieto --- .../server/src/project/ProjectService.test.ts | 28 +++++++++++++++++++ apps/server/src/project/ProjectService.ts | 10 +++++++ packages/contracts/src/settings.ts | 9 +++++- packages/shared/src/serverSettings.test.ts | 25 +++++++++++++++++ packages/shared/src/serverSettings.ts | 4 +++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/apps/server/src/project/ProjectService.test.ts b/apps/server/src/project/ProjectService.test.ts index c2de08a42b585..11f8dafb5e8d8 100644 --- a/apps/server/src/project/ProjectService.test.ts +++ b/apps/server/src/project/ProjectService.test.ts @@ -241,7 +241,14 @@ it.layer(layerTest)("ProjectService", (it) => { const settings = yield* ServerSettings.ServerSettingsService; const service = yield* ProjectService.ProjectService; const projectId = ProjectId.make("project:needs-profile"); + const legacyProjectId = ProjectId.make("project:legacy-profile"); const instanceId = ProviderInstanceId.make("codex"); + yield* service.create({ + commandId: CommandId.make("command:project:legacy-profile"), + projectId: legacyProjectId, + title: "Existing project", + workspaceRoot: "/work/legacy-profile", + }); yield* settings.updateSettings({ trogonStack: { providerProfiles: { work: { name: "Work", providerInstanceIds: [instanceId] } }, @@ -256,6 +263,27 @@ it.layer(layerTest)("ProjectService", (it) => { assert.isFalse( resolveProjectProviderInstanceEnabled(yield* settings.getSettings, projectId, instanceId), ); + assert.isTrue( + resolveProjectProviderInstanceEnabled( + yield* settings.getSettings, + legacyProjectId, + instanceId, + ), + ); + yield* settings.updateSettings({ + trogonStack: { projectProfiles: { [projectId]: "work" } }, + }); + assert.isTrue( + resolveProjectProviderInstanceEnabled(yield* settings.getSettings, projectId, instanceId), + ); + yield* service.delete({ + commandId: CommandId.make("command:project:needs-profile:delete"), + projectId, + }); + yield* service.delete({ + commandId: CommandId.make("command:project:legacy-profile:delete"), + projectId: legacyProjectId, + }); }), ); diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index 1db031456f2d7..a696ad957d6e4 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -401,6 +401,12 @@ export const make = Effect.gen(function* () { createIfMissing: input.createWorkspaceRootIfMissing ?? false, }); yield* rejectWorktreeContainer(input.projectId, workspaceRoot); + const settings = yield* serverSettings.getSettings; + if (Object.keys(settings.trogonStack.providerProfiles).length > 0) { + yield* serverSettings.updateSettings({ + trogonStack: { projectsRequiringProfile: { [input.projectId]: true } }, + }); + } yield* commit({ type: "project.create", commandId: input.commandId, @@ -557,6 +563,10 @@ export const make = Effect.gen(function* () { projectSettingsOverrides: { [projectId]: deletedProjectOverridePatch(projectSettingsOverrides[projectId]), }, + trogonStack: { + projectProfiles: { [projectId]: null }, + projectsRequiringProfile: { [projectId]: null }, + }, }), ), Effect.asVoid, diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index a4d8f0af4e1e1..8b7edd7a878b9 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -1372,6 +1372,9 @@ export const TrogonStackSettings = Schema.Struct({ projectProfiles: Schema.Record(ProjectId, TrimmedNonEmptyString).pipe( Schema.withDecodingDefault(Effect.succeed({})), ), + projectsRequiringProfile: Schema.Record(ProjectId, Schema.Boolean).pipe( + Schema.withDecodingDefault(Effect.succeed({})), + ), }); export type TrogonStackSettings = typeof TrogonStackSettings.Type; @@ -1681,7 +1684,8 @@ export const isProviderInstanceAllowedByProfile = ( ): boolean => { if (projectId === null) return true; const profileId = settings.trogonStack?.projectProfiles[projectId]; - if (profileId === undefined) return true; + if (profileId === undefined) + return settings.trogonStack?.projectsRequiringProfile[projectId] !== true; return ( settings.trogonStack?.providerProfiles[profileId]?.providerInstanceIds.includes(instanceId) ?? false @@ -1839,6 +1843,9 @@ export const ServerSettingsPatch = Schema.Struct({ projectProfiles: Schema.optionalKey( Schema.Record(ProjectId, Schema.NullOr(TrimmedNonEmptyString)), ), + projectsRequiringProfile: Schema.optionalKey( + Schema.Record(ProjectId, Schema.NullOr(Schema.Boolean)), + ), }), ), setModelFavorites: Schema.optionalKey( diff --git a/packages/shared/src/serverSettings.test.ts b/packages/shared/src/serverSettings.test.ts index 5cf8770b33e4b..f755fd244234e 100644 --- a/packages/shared/src/serverSettings.test.ts +++ b/packages/shared/src/serverSettings.test.ts @@ -91,6 +91,31 @@ describe("fallbackTextGenerationModelSelection", () => { }); describe("serverSettings helpers", () => { + it("updates profile entries without replacing other profiles or project assignments", () => { + const projectId = ProjectId.make("project-1"); + const otherProjectId = ProjectId.make("project-2"); + const codexId = ProviderInstanceId.make("codex"); + const initial = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, { + trogonStack: { + providerProfiles: { + personal: { name: "Personal", providerInstanceIds: [codexId] }, + work: { name: "Work", providerInstanceIds: [] }, + }, + projectProfiles: { [projectId]: "work", [otherProjectId]: "personal" }, + }, + }); + const updated = applyServerSettingsPatch(initial, { + trogonStack: { + providerProfiles: { work: null }, + projectProfiles: { [projectId]: null }, + }, + }); + expect(updated.trogonStack.providerProfiles).toEqual({ + personal: { name: "Personal", providerInstanceIds: [codexId] }, + }); + expect(updated.trogonStack.projectProfiles).toEqual({ [otherProjectId]: "personal" }); + }); + it("translates a shipped client's idle compaction switch into a mode", () => { const off = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, { idleCompaction: "off" }); expect([off.idleCompaction, off.compactIdleThreads]).toEqual(["off", false]); diff --git a/packages/shared/src/serverSettings.ts b/packages/shared/src/serverSettings.ts index 42e5e52b8dcb2..323d24ea16ccc 100644 --- a/packages/shared/src/serverSettings.ts +++ b/packages/shared/src/serverSettings.ts @@ -533,6 +533,10 @@ export function applyServerSettingsPatch( current.trogonStack.projectProfiles, trogonStackPatch.projectProfiles, ), + projectsRequiringProfile: applyNullableEntries( + current.trogonStack.projectsRequiringProfile, + trogonStackPatch.projectsRequiringProfile, + ), }, }), ...(worktreeCleanupPatch === undefined From fea2e64370296f97865ca0238f890fd4f2bc4644 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 02:42:37 -0500 Subject: [PATCH 07/33] test(web): preserve project restrictions when a profile is deleted Signed-off-by: Yordis Prieto --- .../settings/providerProfiles.logic.test.ts | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 apps/web/src/components/settings/providerProfiles.logic.test.ts diff --git a/apps/web/src/components/settings/providerProfiles.logic.test.ts b/apps/web/src/components/settings/providerProfiles.logic.test.ts new file mode 100644 index 0000000000000..f236f8b326885 --- /dev/null +++ b/apps/web/src/components/settings/providerProfiles.logic.test.ts @@ -0,0 +1,78 @@ +import { ProjectId, ProviderInstanceId, type ServerSettings } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { + profileAssignmentLabel, + removeProfilePatch, + setProfilePatch, + setProjectProfilePatch, + toggleProfileInstance, +} from "./providerProfiles.logic"; + +const projectId = ProjectId.make("work"); +const instanceId = ProviderInstanceId.make("company-codex"); +const profile = { name: "Company", providerInstanceIds: [instanceId] }; + +describe("provider profile patches", () => { + it("upserts a single profile and toggles only its named provider instances", () => { + expect(setProfilePatch("company", profile)).toEqual({ + trogonStack: { providerProfiles: { company: profile } }, + }); + expect(toggleProfileInstance(profile, instanceId, true)).toEqual(profile); + expect(toggleProfileInstance(profile, instanceId, false)).toEqual({ + ...profile, + providerInstanceIds: [], + }); + expect( + toggleProfileInstance({ ...profile, providerInstanceIds: [] }, instanceId, true), + ).toEqual(profile); + }); + + it("assigns or unassigns one project without replacing other assignments", () => { + expect(setProjectProfilePatch(projectId, "company")).toEqual({ + trogonStack: { projectProfiles: { [projectId]: "company" } }, + }); + expect(setProjectProfilePatch(projectId, null)).toEqual({ + trogonStack: { projectProfiles: { [projectId]: null } }, + }); + }); + + it("removes a profile without restoring unrestricted access to assigned projects", () => { + const settings = { + trogonStack: { + providerProfiles: { + company: profile, + personal: { name: "Personal", providerInstanceIds: [] }, + }, + projectProfiles: { + [projectId]: "company", + other: "personal", + missing: "deleted", + }, + projectsRequiringProfile: { [projectId]: true }, + }, + } satisfies Pick; + + expect(removeProfilePatch(settings, "company")).toEqual({ + trogonStack: { + providerProfiles: { company: null }, + }, + }); + expect(profileAssignmentLabel(settings, projectId)).toBe("Company"); + expect(profileAssignmentLabel(settings, ProjectId.make("missing"))).toBe( + "Missing profile (providers blocked)", + ); + expect(profileAssignmentLabel(settings, ProjectId.make("new"))).toBe( + "No profile (legacy access)", + ); + const pendingSettings = { + trogonStack: { + ...settings.trogonStack, + projectsRequiringProfile: { [ProjectId.make("new")]: true }, + }, + }; + expect(profileAssignmentLabel(pendingSettings, ProjectId.make("new"))).toBe( + "Choose a profile before using providers", + ); + }); +}); From 4eb8a9be034053b99c28b5d1216d84ff83c53dc9 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 03:22:28 -0500 Subject: [PATCH 08/33] test(server): drop removed provider instances from profiles Signed-off-by: Yordis Prieto --- apps/server/src/serverSettings.test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/server/src/serverSettings.test.ts b/apps/server/src/serverSettings.test.ts index 4183c2176fcb2..ce5cf90c73901 100644 --- a/apps/server/src/serverSettings.test.ts +++ b/apps/server/src/serverSettings.test.ts @@ -46,6 +46,27 @@ const decodeServerSettings = Schema.decodeUnknownEffect(ServerSettings); const decodeServerSettingsJson = Schema.decodeUnknownEffect(Schema.fromJsonString(ServerSettings)); const decodeServerSettingsPatch = Schema.decodeUnknownEffect(ServerSettingsPatch); +it("removes a deleted provider instance from every provider profile", () => { + const instanceId = ProviderInstanceId.make("codex_company"); + const settings: ServerSettings = { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { [instanceId]: { driver: ProviderDriverKind.make("codex") } }, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: { + company: { name: "Company", providerInstanceIds: [instanceId] }, + }, + }, + }; + assert.deepEqual( + ServerSettingsModule.applyProviderInstanceMutation(settings, { + operation: "remove", + instanceId, + }).trogonStack.providerProfiles.company?.providerInstanceIds, + [], + ); +}); + const layerServerSettings = (policy?: ManagedPolicyDocument) => ServerSettingsModule.layer.pipe( Layer.provide(ServerSecretStore.layer), From a2fa254171b354c083118fe9eaccc5990c6a1d1a Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 03:23:36 -0500 Subject: [PATCH 09/33] fix(server): drop removed provider instances from profiles Signed-off-by: Yordis Prieto --- apps/server/src/serverSettings.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/server/src/serverSettings.ts b/apps/server/src/serverSettings.ts index 99deb6df8fbb5..1fbbbcc53922d 100644 --- a/apps/server/src/serverSettings.ts +++ b/apps/server/src/serverSettings.ts @@ -191,10 +191,26 @@ export function applyProviderInstanceMutation( const providerInstances = { ...settings.providerInstances }; if (mutation.operation === "upsert" || mutation.operation === "create") { providerInstances[mutation.instanceId] = mutation.instance; - } else { - delete providerInstances[mutation.instanceId]; + return { ...settings, providerInstances }; } - return { ...settings, providerInstances }; + delete providerInstances[mutation.instanceId]; + // A dangling id would re-allow a later instance that reuses it. + const providerProfiles = Object.fromEntries( + Object.entries(settings.trogonStack.providerProfiles).map(([profileId, profile]) => [ + profileId, + { + ...profile, + providerInstanceIds: profile.providerInstanceIds.filter( + (instanceId) => instanceId !== mutation.instanceId, + ), + }, + ]), + ); + return { + ...settings, + providerInstances, + trogonStack: { ...settings.trogonStack, providerProfiles }, + }; } const secretProviderConfigGuards = new Map( From 2d0bebd91327c160052e3d1b0879fb470806904d Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 03:28:19 -0500 Subject: [PATCH 10/33] fix(server): surface settings failures when creating a project Signed-off-by: Yordis Prieto --- apps/server/src/project/ProjectService.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/server/src/project/ProjectService.ts b/apps/server/src/project/ProjectService.ts index a696ad957d6e4..b530192316372 100644 --- a/apps/server/src/project/ProjectService.ts +++ b/apps/server/src/project/ProjectService.ts @@ -401,12 +401,23 @@ export const make = Effect.gen(function* () { createIfMissing: input.createWorkspaceRootIfMissing ?? false, }); yield* rejectWorktreeContainer(input.projectId, workspaceRoot); - const settings = yield* serverSettings.getSettings; - if (Object.keys(settings.trogonStack.providerProfiles).length > 0) { - yield* serverSettings.updateSettings({ - trogonStack: { projectsRequiringProfile: { [input.projectId]: true } }, - }); - } + yield* Effect.gen(function* () { + const settings = yield* serverSettings.getSettings; + if (Object.keys(settings.trogonStack.providerProfiles).length > 0) { + yield* serverSettings.updateSettings({ + trogonStack: { projectsRequiringProfile: { [input.projectId]: true } }, + }); + } + }).pipe( + Effect.mapError( + (cause) => + new ProjectOperationError({ + operation: "dispatch-project-command", + projectId: input.projectId, + cause, + }), + ), + ); yield* commit({ type: "project.create", commandId: input.commandId, From cd403a02a183094225f6349c723289b14881a93a Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 03:28:34 -0500 Subject: [PATCH 11/33] feat(web): manage provider profiles in settings Signed-off-by: Yordis Prieto --- .../ProjectSettingsPanel.browser.test.tsx | 42 +++ .../settings/ProjectSettingsPanel.tsx | 16 + .../ProviderProfilesSettings.browser.test.tsx | 84 +++++ .../settings/ProviderProfilesSettings.tsx | 321 ++++++++++++++++++ .../settings/ProviderSettingsPanel.tsx | 31 +- .../settings/providerProfiles.logic.test.ts | 6 +- .../settings/providerProfiles.logic.ts | 58 ++++ .../src/components/settings/settingsSearch.ts | 12 + 8 files changed, 566 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx create mode 100644 apps/web/src/components/settings/ProviderProfilesSettings.tsx create mode 100644 apps/web/src/components/settings/providerProfiles.logic.ts diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx index a8d2efe7e04db..192f4f8ed11ee 100644 --- a/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx +++ b/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx @@ -5,6 +5,7 @@ import type { } from "@t3tools/client-runtime/state/projects"; import { AuthOrchestrationOperateScope, + AuthProvidersManageScope, AuthSettingsWriteScope, DEFAULT_SERVER_SETTINGS, EnvironmentId, @@ -12,6 +13,7 @@ import { ProviderInstanceId, type AuthEnvironmentScope, type AuthSessionState, + type ServerSettingsPatch, } from "@t3tools/contracts"; import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; @@ -50,6 +52,7 @@ const state = vi.hoisted(() => ({ input: DeleteProjectInput; }) => Promise> >(), + updateSettings: vi.fn<(patch: ServerSettingsPatch) => void>(), confirm: vi.fn<() => Promise>(), releaseUploads: vi.fn(), clearDraft: vi.fn(), @@ -112,6 +115,10 @@ vi.mock(import("~/hooks/useSettings"), async (original) => ({ ...(await original()), useClientSettings: ((selector?: (settings: typeof DEFAULT_CLIENT_SETTINGS) => unknown) => selector ? selector(DEFAULT_CLIENT_SETTINGS) : DEFAULT_CLIENT_SETTINGS) as never, + useEnvironmentSettings: ((id: EnvironmentId) => + environments.find((environment) => environment.environmentId === id)?.serverConfig.settings ?? + DEFAULT_SERVER_SETTINGS) as never, + useUpdateEnvironmentSettings: (() => state.updateSettings) as never, })); vi.mock(import("~/localApi"), async (original) => ({ ...(await original()), @@ -189,6 +196,8 @@ function deferred() { function setup() { vi.clearAllMocks(); + for (const environment of environments) + environment.serverConfig.settings = DEFAULT_SERVER_SETTINGS; state.sessions.clear(); for (const id of [primaryId, remoteId]) state.sessions.set(id, Atom.make(writable()).pipe(Atom.keepAlive)); @@ -363,6 +372,39 @@ describe("project organization", () => { }); }); +describe("project provider profile", () => { + it("labels a pending project and assigns it with a targeted settings patch", async () => { + setup(); + await grant( + primaryId, + AsyncResult.success( + session([AuthOrchestrationOperateScope, AuthSettingsWriteScope, AuthProvidersManageScope]), + ), + ); + const projectId = state.projects.find((project) => project.environmentId === primaryId)!.id; + environments[0]!.serverConfig.settings = { + ...DEFAULT_SERVER_SETTINGS, + trogonStack: { + ...DEFAULT_SERVER_SETTINGS.trogonStack, + providerProfiles: { company: { name: "Company", providerInstanceIds: [instanceId] } }, + projectsRequiringProfile: { [projectId]: true }, + }, + }; + + await using screen = await mountPanel({ machine: primaryId }); + await expect + .element(screen.getByText("Choose a profile before using providers").first()) + .toBeVisible(); + await userEvent.click(screen.getByRole("combobox", { name: "Provider profile" })); + await userEvent.click(page.getByRole("option", { name: "Company" })); + + expect(state.updateSettings).toHaveBeenCalledWith( + { trogonStack: { projectProfiles: { [projectId]: "company" } } }, + expect.any(Object), + ); + }); +}); + describe("project settings permissions", () => { it("disables shared edits when any member lacks project access", async () => { setup(); diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.tsx index cc5ceba8984ee..b97fd86b85dad 100644 --- a/apps/web/src/components/settings/ProjectSettingsPanel.tsx +++ b/apps/web/src/components/settings/ProjectSettingsPanel.tsx @@ -50,6 +50,7 @@ import { ProjectFaviconPickerDialog, } from "./ProjectFaviconPickerDialog"; import { ProjectActionsSettings } from "./ProjectActionsSettings"; +import { ProjectProviderProfileAssignment } from "./ProviderProfilesSettings"; import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings"; import { defaultProjectIcon, @@ -712,6 +713,21 @@ function ProjectDetail({ ) : null} + + {group.memberProjects.map((member) => ( + 1 + ? { + label: `${member.environmentLabel ?? member.environmentId} · ${member.workspaceRoot}`, + } + : {})} + /> + ))} + {checkoutChoices} diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx new file mode 100644 index 0000000000000..4e10d8b6b6606 --- /dev/null +++ b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx @@ -0,0 +1,84 @@ +import { + DEFAULT_SERVER_SETTINGS, + ProjectId, + ProviderDriverKind, + ProviderInstanceId, + type ServerSettings, + type ServerSettingsPatch, +} from "@t3tools/contracts"; +import { expect, it, vi } from "vite-plus/test"; +import { userEvent } from "vite-plus/test/browser"; + +import "~/index.css"; +import { render } from "../../../test/render"; +import { ProviderProfilesSettings } from "./ProviderProfilesSettings"; + +const instanceId = ProviderInstanceId.make("company-codex"); +const projectId = ProjectId.make("client"); +const settings: ServerSettings = { + ...DEFAULT_SERVER_SETTINGS, + providerInstances: { + [instanceId]: { driver: ProviderDriverKind.make("codex"), displayName: "Company Codex" }, + }, + trogonStack: { + providerProfiles: { company: { name: "Company", providerInstanceIds: [] } }, + projectProfiles: { [projectId]: "company" }, + projectsRequiringProfile: {}, + }, +}; + +it("sends targeted patches when editing a profile's name and allowed instances", async () => { + const onPatch = vi.fn((_: ServerSettingsPatch, options?: { onSaved?: () => void }) => + options?.onSaved?.(), + ); + await using screen = await render( + , + ); + + await screen.getByRole("checkbox", { name: "Company: Company Codex" }).click(); + expect(onPatch).toHaveBeenLastCalledWith( + { + trogonStack: { + providerProfiles: { company: { name: "Company", providerInstanceIds: [instanceId] } }, + }, + }, + expect.any(Object), + ); + + const name = screen.getByRole("textbox", { name: "Rename provider profile Company" }); + await name.fill("New name"); + await userEvent.tab(); + expect(onPatch).toHaveBeenLastCalledWith( + { + trogonStack: { providerProfiles: { company: { name: "New name", providerInstanceIds: [] } } }, + }, + expect.any(Object), + ); +}); + +it("starts new profiles with no allowed providers", async () => { + const onPatch = vi.fn((_: ServerSettingsPatch, options?: { onSaved?: () => void }) => + options?.onSaved?.(), + ); + await using screen = await render( + , + ); + + await screen.getByRole("textbox", { name: "New provider profile name" }).fill("Personal"); + await screen.getByRole("button", { name: "Create" }).click(); + const [patch] = onPatch.mock.lastCall!; + expect(Object.values(patch.trogonStack?.providerProfiles ?? {})).toEqual([ + { name: "Personal", providerInstanceIds: [] }, + ]); + expect(Object.keys(patch.trogonStack?.providerProfiles ?? {})).toHaveLength(1); +}); diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.tsx new file mode 100644 index 0000000000000..074e5aa31cab0 --- /dev/null +++ b/apps/web/src/components/settings/ProviderProfilesSettings.tsx @@ -0,0 +1,321 @@ +import { + AuthProvidersManageScope, + AuthSettingsWriteScope, + type EnvironmentId, + type ProjectId, + type ProviderInstanceId, + type ProviderProfile, + type ServerProvider, + type ServerSettings, + type ServerSettingsPatch, +} from "@t3tools/contracts"; +import { PlusIcon, Trash2Icon } from "lucide-react"; +import { useState } from "react"; + +import { useEnvironmentSettings, useUpdateEnvironmentSettings } from "../../hooks/useSettings"; +import { randomUUID } from "../../lib/utils"; +import { providerInstanceEntriesFor } from "../../providerInstances"; +import { useEnvironmentScope } from "../../state/session"; +import { Button } from "../ui/button"; +import { Checkbox } from "../ui/checkbox"; +import { Input } from "../ui/input"; +import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; +import { ensureLocalApi } from "../../localApi"; +import { providerClients } from "./providerDriverMeta"; +import { + profileAssignmentLabel, + projectRequiresProfile, + removeProfilePatch, + setProfilePatch, + setProjectProfilePatch, + toggleProfileInstance, +} from "./providerProfiles.logic"; +import { SettingsRow, SettingsSection } from "./settingsLayout"; + +type SettingsWriter = ( + patch: ServerSettingsPatch, + options?: { readonly onSaved?: () => void; readonly onFailed?: () => void }, +) => void; + +const NO_PROFILE = "__no_provider_profile__"; + +function ProfileEditor({ + profileId, + profile, + settings, + availableInstances, + disabled, + onPatch, +}: { + profileId: string; + profile: ProviderProfile; + settings: ServerSettings; + availableInstances: ReadonlyArray<{ instanceId: ProviderInstanceId; label: string }>; + disabled: boolean; + onPatch: SettingsWriter; +}) { + const [saving, setSaving] = useState(false); + const save = (patch: ServerSettingsPatch) => { + setSaving(true); + onPatch(patch, { onSaved: () => setSaving(false), onFailed: () => setSaving(false) }); + }; + const assignedProjects = Object.values(settings.trogonStack.projectProfiles).filter( + (assignedId) => assignedId === profileId, + ).length; + const knownIds = new Set(availableInstances.map(({ instanceId }) => instanceId)); + const instances = [ + ...availableInstances, + ...profile.providerInstanceIds + .filter((instanceId) => !knownIds.has(instanceId)) + .map((instanceId) => ({ instanceId, label: `${instanceId} (missing)` })), + ]; + const remove = async () => { + if (assignedProjects > 0) return; + const confirmed = await ensureLocalApi().dialogs.confirm( + `Delete the ${profile.name} provider profile?`, + { variant: "destructive" }, + ); + if (confirmed) save(removeProfilePatch(profileId)); + }; + + return ( + 0} + onClick={() => void remove()} + > + + + } + > +
+ { + const name = event.currentTarget.value.trim(); + if (name && name !== profile.name) + save(setProfilePatch(profileId, { ...profile, name })); + else event.currentTarget.value = profile.name; + }} + onKeyDown={(event) => { + if (event.nativeEvent.isComposing || event.keyCode === 229) return; + if (event.key === "Enter") event.currentTarget.blur(); + }} + /> + {instances.length ? ( +
+ {instances.map(({ instanceId, label }) => ( + + ))} +
+ ) : ( +

Add a provider instance to allow it here.

+ )} +
+
+ ); +} + +export function ProviderProfilesSettings({ + settings, + providers, + disabled, + onPatch, +}: { + settings: ServerSettings; + providers: ReadonlyArray; + disabled: boolean; + onPatch: SettingsWriter; +}) { + const [newName, setNewName] = useState(""); + const [creating, setCreating] = useState(false); + const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => + left[1].name.localeCompare(right[1].name), + ); + const fromProviders = providerInstanceEntriesFor(providers, settings, null).map((entry) => ({ + instanceId: entry.instanceId, + label: entry.displayName, + })); + const knownIds = new Set(fromProviders.map((entry) => entry.instanceId)); + const availableInstances = [ + ...fromProviders, + ...Object.entries(settings.providerInstances) + .filter(([instanceId]) => !knownIds.has(instanceId as ProviderInstanceId)) + .map(([instanceId, instance]) => ({ + instanceId: instanceId as ProviderInstanceId, + label: + instance.displayName?.trim() || providerClients.get(instance.driver)?.label || instanceId, + })), + ]; + const create = () => { + const name = newName.trim(); + if (!name || creating) return; + setCreating(true); + onPatch(setProfilePatch(randomUUID(), { name, providerInstanceIds: [] }), { + onSaved: () => { + setNewName(""); + setCreating(false); + }, + onFailed: () => setCreating(false), + }); + }; + + return ( + + + setNewName(event.currentTarget.value)} + onKeyDown={(event) => { + if (event.nativeEvent.isComposing || event.keyCode === 229) return; + if (event.key === "Enter") create(); + }} + /> + + + } + /> + {profiles.map(([profileId, profile]) => ( + + ))} + + ); +} + +function ProviderProfileAssignment({ + settings, + projectId, + label, + disabled, + onPatch, +}: { + settings: ServerSettings; + projectId: ProjectId; + label?: string; + disabled: boolean; + onPatch: SettingsWriter; +}) { + const [saving, setSaving] = useState(false); + const profileId = settings.trogonStack.projectProfiles[projectId]; + const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => + left[1].name.localeCompare(right[1].name), + ); + const hasProfile = profileId !== undefined && settings.trogonStack.providerProfiles[profileId]; + const status = profileAssignmentLabel(settings, projectId); + return ( + + + + } + /> + ); +} + +export function ProjectProviderProfileAssignment({ + environmentId, + projectId, + label, + available = true, +}: { + environmentId: EnvironmentId; + projectId: ProjectId; + label?: string; + available?: boolean; +}) { + const settings = useEnvironmentSettings(environmentId); + const canWriteSettings = useEnvironmentScope(environmentId, AuthSettingsWriteScope); + const canManageProviders = useEnvironmentScope(environmentId, AuthProvidersManageScope); + const updateSettings = useUpdateEnvironmentSettings(environmentId); + return ( + + ); +} diff --git a/apps/web/src/components/settings/ProviderSettingsPanel.tsx b/apps/web/src/components/settings/ProviderSettingsPanel.tsx index c3cf285980147..42506c4a21bd5 100644 --- a/apps/web/src/components/settings/ProviderSettingsPanel.tsx +++ b/apps/web/src/components/settings/ProviderSettingsPanel.tsx @@ -99,6 +99,10 @@ import { useSecretSources } from "./SecretSourceInput"; import { TextGeneratorsSettings } from "./TextGeneratorsSettings"; import { UsageProviderSettings } from "./UsageProviderSettings"; import { ProviderSetupSection, readAntigravityAuthMethod } from "./ProviderSetupSection"; +import { + ProjectProviderProfileAssignment, + ProviderProfilesSettings, +} from "./ProviderProfilesSettings"; import { ProviderAuthenticationSection } from "./ProviderAuthenticationSection"; import { CodexSetupSection, CodexManagedRuntimeFields } from "./CodexSetupSection"; import { readCodexSetupMode } from "./CodexSetupSection.logic"; @@ -553,6 +557,7 @@ export function EnvironmentProviderSettings({ const canAddProvider = !readOnly && managedPolicy?.limits?.providers?.allowedDrivers?.length !== 0; const canWriteSettings = useEnvironmentScope(environmentId, AuthSettingsWriteScope); + const canManageProfiles = useEnvironmentScope(environmentId, AuthProvidersManageScope); const canRefreshProviders = useEnvironmentScope(environmentId, AuthOrchestrationReadScope); const updateSettings = useUpdateEnvironmentSettings(environmentId); const updateModelPreferences = useUpdateEnvironmentModelPreferences(environmentId); @@ -931,7 +936,11 @@ export function EnvironmentProviderSettings({ const representativeProjectId = projectIds[0]; const renderProviderInstance = (row: InstanceRow, mode: "list" | "editor") => { const showProjectOverride = - representativeProjectId !== undefined && supportsProjectProviderOverrides; + representativeProjectId !== undefined && + supportsProjectProviderOverrides && + projectIds.every( + (projectId) => settings.trogonStack.projectProfiles[projectId] === undefined, + ); return ( + {projectIds.length > 0 ? ( + + {projectIds.map((projectId) => ( + 1 ? { label: String(projectId) } : {})} + /> + ))} + + ) : null} + + + { }, projectProfiles: { [projectId]: "company", - other: "personal", - missing: "deleted", + [ProjectId.make("other")]: "personal", + [ProjectId.make("missing")]: "deleted", }, projectsRequiringProfile: { [projectId]: true }, }, } satisfies Pick; - expect(removeProfilePatch(settings, "company")).toEqual({ + expect(removeProfilePatch("company")).toEqual({ trogonStack: { providerProfiles: { company: null }, }, diff --git a/apps/web/src/components/settings/providerProfiles.logic.ts b/apps/web/src/components/settings/providerProfiles.logic.ts new file mode 100644 index 0000000000000..875a1dbe3b783 --- /dev/null +++ b/apps/web/src/components/settings/providerProfiles.logic.ts @@ -0,0 +1,58 @@ +import type { + ProjectId, + ProviderInstanceId, + ProviderProfile, + ServerSettings, + ServerSettingsPatch, +} from "@t3tools/contracts"; + +export function setProfilePatch(profileId: string, profile: ProviderProfile): ServerSettingsPatch { + return { trogonStack: { providerProfiles: { [profileId]: profile } } }; +} + +export function setProjectProfilePatch( + projectId: ProjectId, + profileId: string | null, +): ServerSettingsPatch { + return { trogonStack: { projectProfiles: { [projectId]: profileId } } }; +} + +export function toggleProfileInstance( + profile: ProviderProfile, + instanceId: ProviderInstanceId, + allowed: boolean, +): ProviderProfile { + const included = profile.providerInstanceIds.includes(instanceId); + if (included === allowed) return profile; + return { + ...profile, + providerInstanceIds: allowed + ? [...profile.providerInstanceIds, instanceId] + : profile.providerInstanceIds.filter((candidate) => candidate !== instanceId), + }; +} + +export function removeProfilePatch(profileId: string): ServerSettingsPatch { + return { trogonStack: { providerProfiles: { [profileId]: null } } }; +} + +export function profileAssignmentLabel( + settings: Pick, + projectId: ProjectId, +): string { + const profileId = settings.trogonStack.projectProfiles[projectId]; + if (!profileId) + return projectRequiresProfile(settings, projectId) + ? "Choose a profile before using providers" + : "No profile (legacy access)"; + return ( + settings.trogonStack.providerProfiles[profileId]?.name ?? "Missing profile (providers blocked)" + ); +} + +export function projectRequiresProfile( + settings: Pick, + projectId: string, +): boolean { + return settings.trogonStack.projectsRequiringProfile[projectId as ProjectId] === true; +} diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index f77a72cbc12b2..d11d41ca2e606 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -283,6 +283,12 @@ export const SETTINGS_SEARCH_ITEMS = [ to: "/settings/projects", searchTerms: ["name icon emoji image checkout remove delete"], }, + { + id: "project-provider-profile", + title: "Project provider profile", + to: "/settings/projects", + searchTerms: ["assign provider profile project company personal access separation"], + }, { id: "default-model", title: "Default model", @@ -985,6 +991,12 @@ export const SETTINGS_SEARCH_ITEMS = [ "agents cli codex claude cursor grok fx kiro opencode antigravity google sign in sign out install subscription instances authentication api key models configuration binary path config directory codex_home shadow home endpoint arguments environment variables display name accent color custom favorite hidden auto compact native sessions import resume", ], }, + { + id: "provider-profiles", + title: "Provider profiles", + to: "/settings/providers", + searchTerms: ["company personal provider instances allowlist separation project policy"], + }, { id: "usage-providers", title: "Usage providers", From 65e53776f8a87d4cddfe6a677516ecfc1eb32c83 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 03:29:06 -0500 Subject: [PATCH 12/33] feat(mobile): manage provider profiles in settings Signed-off-by: Yordis Prieto --- .../settings/ProviderProfilesSettings.tsx | 351 ++++++++++++++++++ .../SettingsProjectOverviewRouteScreen.tsx | 16 + .../SettingsProviderAccountsRouteScreen.tsx | 39 +- .../src/features/settings/settings-search.ts | 1 + apps/mobile/src/lib/modelOptions.test.ts | 2 +- 5 files changed, 392 insertions(+), 17 deletions(-) create mode 100644 apps/mobile/src/features/settings/ProviderProfilesSettings.tsx diff --git a/apps/mobile/src/features/settings/ProviderProfilesSettings.tsx b/apps/mobile/src/features/settings/ProviderProfilesSettings.tsx new file mode 100644 index 0000000000000..67f9aab51a87b --- /dev/null +++ b/apps/mobile/src/features/settings/ProviderProfilesSettings.tsx @@ -0,0 +1,351 @@ +import { + AuthProvidersManageScope, + AuthSettingsWriteScope, + isManagedDriverAllowed, + type EnvironmentId, + type ProjectId, + type ProviderProfile, + type ServerProvider, + type ServerSettingsPatch, +} from "@t3tools/contracts"; +import { + isAtomCommandInterrupted, + squashAtomCommandFailure, +} from "@t3tools/client-runtime/state/runtime"; +import { useRef, useState } from "react"; +import { View } from "react-native"; + +import { AppText as Text, AppTextInput } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; +import * as Dialog from "../../components/ui/Dialog"; +import { ListChoiceRow } from "../../components/ui/ListChoiceRow"; +import { uuidv4 } from "../../lib/uuid"; +import { serverEnvironment } from "../../state/server"; +import { readEnvironmentScope, useEnvironmentScope } from "../../state/session"; +import { useAtomCommand } from "../../state/use-atom-command"; +import type { SettingsTarget } from "./settings-environment-filter"; +import { SettingsSection } from "./components/SettingsSection"; +import { SettingsSwitchRow } from "./components/SettingsSwitchRow"; + +function useProfileSettingsWrite(environmentId: EnvironmentId) { + const [pending, setPending] = useState(false); + const pendingRef = useRef(false); + const updateSettings = useAtomCommand(serverEnvironment.updateSettings, { + label: "provider profile update", + reportFailure: true, + }); + const write = async (patch: ServerSettingsPatch): Promise => { + if ( + pendingRef.current || + !readEnvironmentScope(environmentId, AuthSettingsWriteScope) || + !readEnvironmentScope(environmentId, AuthProvidersManageScope) + ) { + return false; + } + pendingRef.current = true; + setPending(true); + try { + const result = await updateSettings({ environmentId, input: { patch } }); + if (result._tag === "Failure") { + if (!isAtomCommandInterrupted(result)) { + const error = squashAtomCommandFailure(result); + Dialog.alert("Could not save provider profile", String(error)); + } + return false; + } + return true; + } finally { + pendingRef.current = false; + setPending(false); + } + }; + return { write, pending }; +} + +export function ProjectProviderProfileSection(props: { + readonly environment: SettingsTarget | undefined; + readonly projectId: ProjectId; + readonly checkoutLabel: string; + readonly showCheckoutLabel: boolean; +}) { + if (!props.environment) { + return ( + + + Connect this checkout to view its provider profile. + + + ); + } + return ; +} + +function ConnectedProjectProviderProfileSection(props: { + readonly environment: SettingsTarget; + readonly projectId: ProjectId; + readonly checkoutLabel: string; + readonly showCheckoutLabel: boolean; +}) { + const { environment, projectId } = props; + const allowed = useEnvironmentScope(environment.environmentId, AuthSettingsWriteScope); + const canManageProviders = useEnvironmentScope( + environment.environmentId, + AuthProvidersManageScope, + ); + const { write, pending } = useProfileSettingsWrite(environment.environmentId); + const { providerProfiles, projectProfiles } = environment.serverConfig.settings.trogonStack; + const selectedId = projectProfiles[projectId] ?? null; + const needsProfile = + selectedId === null && + environment.serverConfig.settings.trogonStack.projectsRequiringProfile?.[projectId] === true; + const choices = Object.entries(providerProfiles).sort((left, right) => + left[1].name.localeCompare(right[1].name), + ); + const select = (profileId: string | null) => { + const save = () => { + void write({ trogonStack: { projectProfiles: { [projectId]: profileId } } }); + }; + if (profileId === selectedId) return; + if (selectedId === null && profileId !== null) { + save(); + return; + } + Dialog.confirm({ + title: profileId === null ? "Remove provider profile?" : "Change provider profile?", + message: + profileId === null + ? needsProfile + ? "Removing the assignment blocks providers until another profile is assigned. Existing thread context is not erased." + : "Removing the assignment returns this project to legacy, unrestricted provider access. Existing thread context is not erased." + : "Changing this assignment does not remove existing thread context.", + confirmText: profileId === null ? "Remove profile" : "Change profile", + onConfirm: save, + }); + }; + + return ( + + + {props.showCheckoutLabel ? ( + {props.checkoutLabel} + ) : null} + + {selectedId === null + ? needsProfile + ? "Profile required: providers are blocked until you assign one." + : "Legacy project: providers are not restricted by a profile." + : providerProfiles[selectedId] + ? "Only the selected profile's provider instances are available for future turns. Existing thread context is unchanged." + : "Assigned profile is missing. No provider instances are allowed until you select a profile."} + + + select(null)} + /> + {choices.map(([id, profile]) => ( + select(id)} + /> + ))} + {choices.length === 0 ? ( + + Add a provider profile in Provider settings before assigning this project. + + ) : null} + + ); +} + +export function ProviderProfilesSection(props: { + readonly environment: SettingsTarget; + readonly providers: ReadonlyArray; +}) { + const { environment } = props; + const [name, setName] = useState(""); + const allowed = useEnvironmentScope(environment.environmentId, AuthSettingsWriteScope); + const canManageProviders = useEnvironmentScope( + environment.environmentId, + AuthProvidersManageScope, + ); + const { write, pending } = useProfileSettingsWrite(environment.environmentId); + const profiles = environment.serverConfig.settings.trogonStack.providerProfiles; + const create = async () => { + const nextName = name.trim(); + if ( + !nextName || + Object.values(profiles).some( + (profile) => profile.name.toLowerCase() === nextName.toLowerCase(), + ) + ) { + Dialog.alert("Choose a unique profile name"); + return; + } + // A reused id would silently rebind projects still pointing at a deleted profile. + const saved = await write({ + trogonStack: { + providerProfiles: { [uuidv4()]: { name: nextName, providerInstanceIds: [] } }, + }, + }); + if (saved) setName(""); + }; + + return ( + + + + Profiles allow only selected provider instances. New providers stay off until added to a + profile. + + void create()} + /> + - ) : ( -

Add a provider instance to allow it here.

- )} + ))}
); } +export function ProviderInstanceProfiles({ + settings, + instanceId, + disabled, + onPatch, +}: { + settings: ServerSettings; + instanceId: ProviderInstanceId; + disabled: boolean; + onPatch: SettingsWriter; +}) { + const [saving, setSaving] = useState(false); + const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => + left[1].name.localeCompare(right[1].name), + ); + if (profiles.length === 0) return null; + return ( + + {profiles.map(([profileId, profile]) => ( + + ))} + + } + /> + ); +} + export function ProviderProfilesSettings({ settings, instances, @@ -172,7 +212,7 @@ export function ProviderProfilesSettings({ 0 ? settings.favorites : NO_FAVORITES; @@ -977,6 +980,8 @@ export function EnvironmentProviderSettings({ modelPreferences={settings.providerModelPreferences?.[row.instanceId]} favorites={favorites} actions={actions} + profileSettings={mode === "editor" ? settings : undefined} + profilesDisabled={readOnly || !canWriteSettings || !canManageProfiles} /> ); }; @@ -1251,6 +1256,7 @@ interface ProviderInstanceRowActions { readonly updateModelPreferences: ReturnType; readonly toggleModelFavorite: ReturnType; readonly selectInstance: (instanceId: ProviderInstanceId) => void; + readonly patchSettings: ReturnType; } const NO_MODELS: ReadonlyArray = []; @@ -1276,6 +1282,8 @@ function ProviderInstanceRow({ modelPreferences, favorites, actions, + profileSettings, + profilesDisabled, }: { readonly environmentId: EnvironmentId; readonly environmentLabel: string; @@ -1298,6 +1306,8 @@ function ProviderInstanceRow({ | undefined; readonly favorites: UnifiedSettings["favorites"]; readonly actions: ProviderInstanceRowActions; + readonly profileSettings: ServerSettings | undefined; + readonly profilesDisabled: boolean; }) { const allProjects = useProjects(); const secretSources = useSecretSources(environmentId); @@ -1363,6 +1373,16 @@ function ProviderInstanceRow({ ) : undefined } canWriteSettings={canWriteSettings} + profiles={ + profileSettings ? ( + + ) : null + } setup={ mode === "editor" && driver === "antigravity" ? ( Date: Tue, 17 Nov 2026 04:11:39 -0500 Subject: [PATCH 22/33] docs(user): profiles are chosen on the provider Signed-off-by: Yordis Prieto --- docs/user/project-settings.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/user/project-settings.md b/docs/user/project-settings.md index 8a600af455d17..23c00822132f8 100644 --- a/docs/user/project-settings.md +++ b/docs/user/project-settings.md @@ -203,13 +203,14 @@ A provider profile is a named list of the provider instances a project may use. company or account boundary, such as Personal and Company A, when a project must never run on another boundary's models. -Create profiles in **Settings → Providers** under **Provider profiles**, and tick the instances -each one allows. Assign a profile to a project in **Settings → Projects** under **Provider -profile**. Each environment keeps its own profiles and assignments. +Create profiles in **Settings → Providers** under **Provider profiles**. Open a provider in the +same page and tick the profiles it belongs to under **Profiles**. Then pick a profile for each +project in **Settings → Projects** under **Provider profile**. Each environment keeps its own +profiles and assignments. - A project with a profile can only use that profile's instances, for agent turns and for text generation alike. Other instances are hidden from its model picker and refused by the server. -- A provider instance you add later belongs to no profile until you tick it. +- A provider instance you add later belongs to no profile until you tick one on its settings. - Once at least one profile exists, a new project cannot run providers until you assign it one. Projects that existed before stay unrestricted until you assign them. - A profile can be deleted only when no project uses it. Removing a provider instance also From fdde6b4d392c8189f2efa89a76a05b3f20afd842 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 04:18:18 -0500 Subject: [PATCH 23/33] fix(web): a provider's profiles are switches like other settings Signed-off-by: Yordis Prieto --- .../settings/ProviderInstanceCard.tsx | 3 +- .../ProviderProfilesSettings.browser.test.tsx | 2 +- .../settings/ProviderProfilesSettings.tsx | 42 ++++++++++--------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/web/src/components/settings/ProviderInstanceCard.tsx b/apps/web/src/components/settings/ProviderInstanceCard.tsx index 55383c29469a5..b4cdb92e3751e 100644 --- a/apps/web/src/components/settings/ProviderInstanceCard.tsx +++ b/apps/web/src/components/settings/ProviderInstanceCard.tsx @@ -1340,9 +1340,10 @@ export function ProviderInstanceCard({ } /> - {mode === "editor" ? profiles : null} + {mode === "editor" ? profiles : null} + {setup || environmentFields.length > 0 ? ( {setup} diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx index 94e8f9f04ac27..46b5299eea727 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx @@ -65,7 +65,7 @@ it("adds an instance to a profile from the instance's own settings", async () => />, ); - await screen.getByRole("checkbox", { name: "Company profile" }).click(); + await screen.getByRole("switch", { name: "Company profile" }).click(); expect(onPatch).toHaveBeenLastCalledWith( { trogonStack: { diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.tsx index 81d51edf4bdd9..39bcfa54bcd71 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.tsx @@ -15,9 +15,9 @@ import { useEnvironmentSettings, useUpdateEnvironmentSettings } from "../../hook import { randomUUID } from "../../lib/utils"; import { useEnvironmentScope } from "../../state/session"; import { Button } from "../ui/button"; -import { Checkbox } from "../ui/checkbox"; import { Input } from "../ui/input"; import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; +import { Switch } from "../ui/switch"; import { ensureLocalApi } from "../../localApi"; import { profileAssignmentLabel, @@ -147,34 +147,38 @@ export function ProviderInstanceProfiles({ ); if (profiles.length === 0) return null; return ( - - {profiles.map(([profileId, profile]) => ( - - ))} - - } - /> + } + /> + ); + })} + ); } From f12e94d45c613f6b83c93156f44e958fcf65f1b7 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 04:18:30 -0500 Subject: [PATCH 24/33] docs(user): profiles are switched on from the provider Signed-off-by: Yordis Prieto --- docs/user/project-settings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user/project-settings.md b/docs/user/project-settings.md index 23c00822132f8..de8b39abc6c2a 100644 --- a/docs/user/project-settings.md +++ b/docs/user/project-settings.md @@ -204,13 +204,13 @@ company or account boundary, such as Personal and Company A, when a project must another boundary's models. Create profiles in **Settings → Providers** under **Provider profiles**. Open a provider in the -same page and tick the profiles it belongs to under **Profiles**. Then pick a profile for each +same page and turn on the profiles it belongs to under **Profiles**. Then pick a profile for each project in **Settings → Projects** under **Provider profile**. Each environment keeps its own profiles and assignments. - A project with a profile can only use that profile's instances, for agent turns and for text generation alike. Other instances are hidden from its model picker and refused by the server. -- A provider instance you add later belongs to no profile until you tick one on its settings. +- A provider instance you add later belongs to no profile until you turn one on in its settings. - Once at least one profile exists, a new project cannot run providers until you assign it one. Projects that existed before stay unrestricted until you assign them. - A profile can be deleted only when no project uses it. Removing a provider instance also From daa3ff3e7157ddacf3143f1047361afa50325b75 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 04:29:22 -0500 Subject: [PATCH 25/33] fix(web): pick a provider's profiles from one multi-select Signed-off-by: Yordis Prieto --- .../settings/ProviderInstanceCard.tsx | 3 +- .../ProviderProfilesSettings.browser.test.tsx | 3 +- .../settings/ProviderProfilesSettings.tsx | 56 ++++++++++--------- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/apps/web/src/components/settings/ProviderInstanceCard.tsx b/apps/web/src/components/settings/ProviderInstanceCard.tsx index b4cdb92e3751e..55383c29469a5 100644 --- a/apps/web/src/components/settings/ProviderInstanceCard.tsx +++ b/apps/web/src/components/settings/ProviderInstanceCard.tsx @@ -1340,10 +1340,9 @@ export function ProviderInstanceCard({ } /> + {mode === "editor" ? profiles : null} - {mode === "editor" ? profiles : null} - {setup || environmentFields.length > 0 ? ( {setup} diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx index 46b5299eea727..d7fdea938aa7e 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx @@ -65,7 +65,8 @@ it("adds an instance to a profile from the instance's own settings", async () => />, ); - await screen.getByRole("switch", { name: "Company profile" }).click(); + await screen.getByRole("button", { name: "Profiles: No profiles" }).click(); + await screen.getByRole("menuitemcheckbox", { name: "Company" }).click(); expect(onPatch).toHaveBeenLastCalledWith( { trogonStack: { diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.tsx index 39bcfa54bcd71..61adad819a17a 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.tsx @@ -8,7 +8,7 @@ import { type ServerSettings, type ServerSettingsPatch, } from "@t3tools/contracts"; -import { PlusIcon, Trash2Icon, XIcon } from "lucide-react"; +import { ChevronDownIcon, PlusIcon, Trash2Icon, XIcon } from "lucide-react"; import { useState } from "react"; import { useEnvironmentSettings, useUpdateEnvironmentSettings } from "../../hooks/useSettings"; @@ -16,8 +16,8 @@ import { randomUUID } from "../../lib/utils"; import { useEnvironmentScope } from "../../state/session"; import { Button } from "../ui/button"; import { Input } from "../ui/input"; +import { Menu, MenuCheckboxItem, MenuPopup, MenuTrigger } from "../ui/menu"; import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; -import { Switch } from "../ui/switch"; import { ensureLocalApi } from "../../localApi"; import { profileAssignmentLabel, @@ -146,24 +146,28 @@ export function ProviderInstanceProfiles({ left[1].name.localeCompare(right[1].name), ); if (profiles.length === 0) return null; + const selected = profiles + .filter(([, profile]) => profile.providerInstanceIds.includes(instanceId)) + .map(([, profile]) => profile.name); + const label = selected.length ? selected.join(", ") : "No profiles"; return ( - - {profiles.map(([profileId, profile]) => { - const projects = Object.values(settings.trogonStack.projectProfiles).filter( - (assignedId) => assignedId === profileId, - ).length; - return ( - + } + aria-label={`Profiles: ${label}`} + disabled={disabled} + > + {label} + + + + {profiles.map(([profileId, profile]) => ( + { @@ -173,12 +177,14 @@ export function ProviderInstanceProfiles({ { onSaved: () => setSaving(false), onFailed: () => setSaving(false) }, ); }} - /> - } - /> - ); - })} - + > + {profile.name} + + ))} + + + } + /> ); } From 46ca8d25057761f3fca29ce17188eeab5200c4fd Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 04:29:33 -0500 Subject: [PATCH 26/33] docs(user): profiles are chosen from the provider's menu Signed-off-by: Yordis Prieto --- docs/user/project-settings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user/project-settings.md b/docs/user/project-settings.md index de8b39abc6c2a..23209cdb34d92 100644 --- a/docs/user/project-settings.md +++ b/docs/user/project-settings.md @@ -204,13 +204,13 @@ company or account boundary, such as Personal and Company A, when a project must another boundary's models. Create profiles in **Settings → Providers** under **Provider profiles**. Open a provider in the -same page and turn on the profiles it belongs to under **Profiles**. Then pick a profile for each +same page and choose the profiles it belongs to under **Profiles**. Then pick a profile for each project in **Settings → Projects** under **Provider profile**. Each environment keeps its own profiles and assignments. - A project with a profile can only use that profile's instances, for agent turns and for text generation alike. Other instances are hidden from its model picker and refused by the server. -- A provider instance you add later belongs to no profile until you turn one on in its settings. +- A provider instance you add later belongs to no profile until you choose one in its settings. - Once at least one profile exists, a new project cannot run providers until you assign it one. Projects that existed before stay unrestricted until you assign them. - A profile can be deleted only when no project uses it. Removing a provider instance also From bb32e1926d39a62f51b8405ea39e4133ac58a240 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Tue, 17 Nov 2026 04:42:34 -0500 Subject: [PATCH 27/33] feat(web): provider profiles get their own settings page Signed-off-by: Yordis Prieto --- .../ProjectSettingsPanel.browser.test.tsx | 2 +- .../settings/ProjectSettingsPanel.tsx | 2 +- .../ProviderProfilesSettings.browser.test.tsx | 49 +- .../settings/ProviderProfilesSettings.tsx | 537 ++++++++++++------ .../settings/ProviderSettingsPanel.tsx | 134 +---- .../settings/SettingsSidebarNav.tsx | 2 + .../settings/providerInstanceRows.ts | 143 +++++ .../settings/providerProfiles.logic.test.ts | 55 +- .../settings/providerProfiles.logic.ts | 102 +++- .../src/components/settings/settingsSearch.ts | 17 +- apps/web/src/routeTree.gen.ts | 22 + .../_chat.settings.provider-profiles.tsx | 22 + apps/web/src/routes/_chat.settings.tsx | 4 +- 13 files changed, 738 insertions(+), 353 deletions(-) create mode 100644 apps/web/src/components/settings/providerInstanceRows.ts create mode 100644 apps/web/src/routes/_chat.settings.provider-profiles.tsx diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx index 192f4f8ed11ee..35680adf01f8f 100644 --- a/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx +++ b/apps/web/src/components/settings/ProjectSettingsPanel.browser.test.tsx @@ -393,7 +393,7 @@ describe("project provider profile", () => { await using screen = await mountPanel({ machine: primaryId }); await expect - .element(screen.getByText("Choose a profile before using providers").first()) + .element(screen.getByText("Blocked until you pick a profile.").first()) .toBeVisible(); await userEvent.click(screen.getByRole("combobox", { name: "Provider profile" })); await userEvent.click(page.getByRole("option", { name: "Company" })); diff --git a/apps/web/src/components/settings/ProjectSettingsPanel.tsx b/apps/web/src/components/settings/ProjectSettingsPanel.tsx index b97fd86b85dad..2c1258455b982 100644 --- a/apps/web/src/components/settings/ProjectSettingsPanel.tsx +++ b/apps/web/src/components/settings/ProjectSettingsPanel.tsx @@ -722,7 +722,7 @@ function ProjectDetail({ available={environmentById.get(member.environmentId)?.serverConfig != null} {...(group.memberProjects.length > 1 ? { - label: `${member.environmentLabel ?? member.environmentId} · ${member.workspaceRoot}`, + title: `Provider profile · ${member.environmentLabel ?? member.environmentId} · ${member.workspaceRoot}`, } : {})} /> diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx index d7fdea938aa7e..ee674ed199e2d 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.browser.test.tsx @@ -7,14 +7,15 @@ import { type ServerSettingsPatch, } from "@t3tools/contracts"; import { expect, it, vi } from "vite-plus/test"; -import { userEvent } from "vite-plus/test/browser"; import "~/index.css"; import { render } from "../../../test/render"; -import { ProviderInstanceProfiles, ProviderProfilesSettings } from "./ProviderProfilesSettings"; +import { ProviderInstanceProfiles, ProviderProfilesView } from "./ProviderProfilesSettings"; const instanceId = ProviderInstanceId.make("company-codex"); const projectId = ProjectId.make("client"); +const options = [{ instanceId, label: "Company Codex" }]; +const projects = [{ id: projectId, title: "client", workspaceRoot: "/work/client" }]; const settings: ServerSettings = { ...DEFAULT_SERVER_SETTINGS, providerInstances: { @@ -27,23 +28,25 @@ const settings: ServerSettings = { }, }; -it("sends targeted patches when editing a profile's name and membership", async () => { +it("sends targeted patches when renaming a profile", async () => { const onPatch = vi.fn((_: ServerSettingsPatch, options?: { onSaved?: () => void }) => options?.onSaved?.(), ); await using screen = await render( - , ); - expect(screen.getByText(/Allows no providers yet/)).toBeVisible(); - const name = screen.getByRole("textbox", { name: "Rename provider profile Company" }); - await name.fill("New name"); - await userEvent.tab(); + expect(screen.getByText(/Used by client\./)).toBeVisible(); + await screen.getByRole("button", { name: "More actions for Company" }).click(); + await screen.getByRole("menuitem", { name: "Rename" }).click(); + await screen.getByRole("textbox", { name: "Profile name" }).fill("New name"); + await screen.getByRole("button", { name: "Save" }).click(); expect(onPatch).toHaveBeenLastCalledWith( { trogonStack: { providerProfiles: { company: { name: "New name", providerInstanceIds: [] } } }, @@ -82,9 +85,10 @@ it("starts new profiles with no allowed providers", async () => { options?.onSaved?.(), ); await using screen = await render( - , @@ -98,3 +102,26 @@ it("starts new profiles with no allowed providers", async () => { ]); expect(Object.keys(patch.trogonStack?.providerProfiles ?? {})).toHaveLength(1); }); + +it("assigns a project to a profile or removes its profile", async () => { + const onPatch = vi.fn((_: ServerSettingsPatch, options?: { onSaved?: () => void }) => + options?.onSaved?.(), + ); + await using screen = await render( + , + ); + + expect(screen.getByText("Can use no providers. Add some to Company.")).toBeVisible(); + await screen.getByRole("combobox", { name: "Provider profile for client" }).click(); + await screen.getByRole("option", { name: "No profile" }).click(); + expect(onPatch).toHaveBeenLastCalledWith( + { trogonStack: { projectProfiles: { [projectId]: null } } }, + expect.any(Object), + ); +}); diff --git a/apps/web/src/components/settings/ProviderProfilesSettings.tsx b/apps/web/src/components/settings/ProviderProfilesSettings.tsx index 61adad819a17a..8d2530fff2077 100644 --- a/apps/web/src/components/settings/ProviderProfilesSettings.tsx +++ b/apps/web/src/components/settings/ProviderProfilesSettings.tsx @@ -8,26 +8,42 @@ import { type ServerSettings, type ServerSettingsPatch, } from "@t3tools/contracts"; -import { ChevronDownIcon, PlusIcon, Trash2Icon, XIcon } from "lucide-react"; +import { ChevronDownIcon, MoreVertical, PlusIcon } from "lucide-react"; import { useState } from "react"; import { useEnvironmentSettings, useUpdateEnvironmentSettings } from "../../hooks/useSettings"; import { randomUUID } from "../../lib/utils"; +import { ensureLocalApi } from "../../localApi"; +import { useProjects } from "../../state/entities"; import { useEnvironmentScope } from "../../state/session"; import { Button } from "../ui/button"; +import { + Dialog, + DialogFooter, + DialogHeader, + DialogPanel, + DialogPopup, + DialogTitle, +} from "../ui/dialog"; import { Input } from "../ui/input"; -import { Menu, MenuCheckboxItem, MenuPopup, MenuTrigger } from "../ui/menu"; +import { Menu, MenuCheckboxItem, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu"; import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; -import { ensureLocalApi } from "../../localApi"; +import { useProviderInstanceOptions } from "./providerInstanceRows"; import { - profileAssignmentLabel, - projectRequiresProfile, + profileNameTaken, + profileProviderLabels, + profileUsageText, + projectDisplayTitles, + projectProfileDescription, + projectsUsingProfile, removeProfilePatch, setProfilePatch, setProjectProfilePatch, + sortedProfiles, toggleProfileInstance, + type ProviderInstanceOption, } from "./providerProfiles.logic"; -import { SettingsRow, SettingsSection } from "./settingsLayout"; +import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout"; type SettingsWriter = ( patch: ServerSettingsPatch, @@ -36,100 +52,6 @@ type SettingsWriter = ( const NO_PROFILE = "__no_provider_profile__"; -function ProfileEditor({ - profileId, - profile, - settings, - availableInstances, - disabled, - onPatch, -}: { - profileId: string; - profile: ProviderProfile; - settings: ServerSettings; - availableInstances: ReadonlyArray<{ instanceId: ProviderInstanceId; label: string }>; - disabled: boolean; - onPatch: SettingsWriter; -}) { - const [saving, setSaving] = useState(false); - const save = (patch: ServerSettingsPatch) => { - setSaving(true); - onPatch(patch, { onSaved: () => setSaving(false), onFailed: () => setSaving(false) }); - }; - const assignedProjects = Object.values(settings.trogonStack.projectProfiles).filter( - (assignedId) => assignedId === profileId, - ).length; - const knownIds = new Set(availableInstances.map(({ instanceId }) => instanceId)); - const allowedLabels = availableInstances - .filter(({ instanceId }) => profile.providerInstanceIds.includes(instanceId)) - .map(({ label }) => label); - const unlistedIds = profile.providerInstanceIds.filter((instanceId) => !knownIds.has(instanceId)); - const remove = async () => { - if (assignedProjects > 0) return; - const confirmed = await ensureLocalApi().dialogs.confirm( - `Delete the ${profile.name} provider profile?`, - { variant: "destructive" }, - ); - if (confirmed) save(removeProfilePatch(profileId)); - }; - - return ( - 0} - onClick={() => void remove()} - > - - - } - > -
- { - const name = event.currentTarget.value.trim(); - if (name && name !== profile.name) - save(setProfilePatch(profileId, { ...profile, name })); - else event.currentTarget.value = profile.name; - }} - onKeyDown={(event) => { - if (event.nativeEvent.isComposing || event.keyCode === 229) return; - if (event.key === "Enter") event.currentTarget.blur(); - }} - /> - {unlistedIds.map((instanceId) => ( -
- - {instanceId} (not in Providers) - - -
- ))} -
-
- ); -} - export function ProviderInstanceProfiles({ settings, instanceId, @@ -142,9 +64,7 @@ export function ProviderInstanceProfiles({ onPatch: SettingsWriter; }) { const [saving, setSaving] = useState(false); - const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => - left[1].name.localeCompare(right[1].name), - ); + const profiles = sortedProfiles(settings); if (profiles.length === 0) return null; const selected = profiles .filter(([, profile]) => profile.providerInstanceIds.includes(instanceId)) @@ -188,26 +108,197 @@ export function ProviderInstanceProfiles({ ); } -export function ProviderProfilesSettings({ +function RenameProfileDialog({ + settings, + profileId, + profile, + onSave, + onClose, +}: { + settings: ServerSettings; + profileId: string; + profile: ProviderProfile; + onSave: (name: string) => void; + onClose: () => void; +}) { + const [name, setName] = useState(profile.name); + const trimmed = name.trim(); + const taken = profileNameTaken(settings, trimmed, profileId); + const valid = trimmed !== "" && trimmed !== profile.name && !taken; + return ( + !open && onClose()}> + +
{ + event.preventDefault(); + if (valid) onSave(trimmed); + }} + > + + Rename profile + + +
+ setName(event.currentTarget.value)} + /> + {taken ? ( +

+ Another profile already has that name. +

+ ) : null} +
+
+ + + + +
+
+
+ ); +} + +function ProfileRow({ + settings, + profileId, + profile, + usedBy, + options, + disabled, + onPatch, +}: { + settings: ServerSettings; + profileId: string; + profile: ProviderProfile; + usedBy: ReadonlyArray; + options: ReadonlyArray; + disabled: boolean; + onPatch: SettingsWriter; +}) { + const [saving, setSaving] = useState(false); + const [renaming, setRenaming] = useState(false); + const save = (patch: ServerSettingsPatch, onSaved?: () => void) => { + setSaving(true); + onPatch(patch, { + onSaved: () => { + setSaving(false); + onSaved?.(); + }, + onFailed: () => setSaving(false), + }); + }; + const labels = profileProviderLabels(profile, options); + const buttonLabel = labels.length ? labels.join(", ") : "No providers"; + const inUse = usedBy.length > 0; + const known = new Set(options.map(({ instanceId }) => instanceId)); + const removedIds = profile.providerInstanceIds.filter((instanceId) => !known.has(instanceId)); + const remove = async () => { + const confirmed = await ensureLocalApi().dialogs.confirm( + `Delete the ${profile.name} provider profile?`, + { variant: "destructive" }, + ); + if (confirmed) save(removeProfilePatch(profileId)); + }; + const setMember = (instanceId: ProviderInstanceId, checked: boolean) => + save(setProfilePatch(profileId, toggleProfileInstance(profile, instanceId, checked))); + + return ( + + + } + aria-label={`Providers for ${profile.name}: ${buttonLabel}`} + disabled={disabled || saving} + > + {buttonLabel} + + + + {options.map(({ instanceId, label }) => ( + setMember(instanceId, checked)} + > + {label} + + ))} + {removedIds.map((instanceId) => ( + setMember(instanceId, checked)} + > + {instanceId} (removed) + + ))} + + + + + } + disabled={disabled || saving} + > + + + + setRenaming(true)}>Rename + void remove()}> + Delete + + + + {renaming ? ( + setRenaming(false)} + onSave={(name) => + save(setProfilePatch(profileId, { ...profile, name }), () => setRenaming(false)) + } + /> + ) : null} + + } + /> + ); +} + +function NewProfileRow({ settings, - instances, disabled, onPatch, }: { settings: ServerSettings; - /** The instances the Providers list shows, so a profile offers the same ones. */ - instances: ReadonlyArray<{ instanceId: ProviderInstanceId; label: string }>; disabled: boolean; onPatch: SettingsWriter; }) { const [newName, setNewName] = useState(""); const [creating, setCreating] = useState(false); - const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => - left[1].name.localeCompare(right[1].name), - ); + const name = newName.trim(); + const taken = profileNameTaken(settings, name); const create = () => { - const name = newName.trim(); - if (!name || creating) return; + if (!name || taken || creating) return; setCreating(true); onPatch(setProfilePatch(randomUUID(), { name, providerInstanceIds: [] }), { onSaved: () => { @@ -217,81 +308,71 @@ export function ProviderProfilesSettings({ onFailed: () => setCreating(false), }); }; - return ( - - - setNewName(event.currentTarget.value)} - onKeyDown={(event) => { - if (event.nativeEvent.isComposing || event.keyCode === 229) return; - if (event.key === "Enter") create(); - }} - /> - - - } - /> - {profiles.map(([profileId, profile]) => ( - - ))} - + + setNewName(event.currentTarget.value)} + onKeyDown={(event) => { + if (event.nativeEvent.isComposing || event.keyCode === 229) return; + if (event.key === "Enter") create(); + }} + /> + + + } + /> ); } -function ProviderProfileAssignment({ +function ProjectProfileRow({ settings, projectId, - label, + title, + ariaLabel, + options, disabled, onPatch, }: { settings: ServerSettings; projectId: ProjectId; - label?: string; + title: string; + ariaLabel: string; + options: ReadonlyArray; disabled: boolean; onPatch: SettingsWriter; }) { const [saving, setSaving] = useState(false); const profileId = settings.trogonStack.projectProfiles[projectId]; - const profiles = Object.entries(settings.trogonStack.providerProfiles).toSorted((left, right) => - left[1].name.localeCompare(right[1].name), - ); - const hasProfile = profileId !== undefined && settings.trogonStack.providerProfiles[profileId]; - const status = profileAssignmentLabel(settings, projectId); + const profile = + profileId === undefined ? undefined : settings.trogonStack.providerProfiles[profileId]; return (