Skip to content

Commit 74445e5

Browse files
committed
feat(settings): providers can be turned on or off per project
Signed-off-by: Yordis Prieto <[email protected]>
1 parent a4c8745 commit 74445e5

43 files changed

Lines changed: 844 additions & 61 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/settings/ScheduledTaskPickerScreens.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export function ScheduledTaskModelPickerRouteScreen() {
2525
const { editor, setEditor } = useScheduledTaskEditor();
2626
const config = useEnvironmentServerConfig(editor?.environmentId ?? null);
2727
const selectedModel = editor?.draft.modelSelection ?? null;
28-
const models = useMemo(() => buildModelOptions(config, selectedModel), [config, selectedModel]);
28+
const projectId = editor?.draft.projectId ?? null;
29+
const models = useMemo(
30+
() => buildModelOptions(config, selectedModel, undefined, projectId),
31+
[config, selectedModel, projectId],
32+
);
2933
const providerGroups = useMemo(() => groupByProvider(models), [models]);
3034
const selectedOption = models.find(
3135
(option) =>

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ function TaskForm({
582582
);
583583
const projects = useProjects().filter((project) => project.environmentId === environmentId);
584584
const config = useEnvironmentServerConfig(environmentId);
585-
const modelOptions = useMemo(() => buildModelOptions(config, null), [config]);
585+
const modelOptions = useMemo(
586+
() => buildModelOptions(config, null, undefined, draft.projectId),
587+
[config, draft.projectId],
588+
);
586589
const canOperate = useAtomValue(
587590
serverEnvironment.upsertScheduledTask.permissionAtom(environmentId),
588591
);

‎apps/mobile/src/features/settings/scheduledTaskDraft.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ export function scheduledTaskDefaultModel(
3434
draftSelection: null,
3535
projectDefaultSelection,
3636
stickySelection: null,
37-
modelOptions: buildModelOptions(config, projectDefaultSelection),
37+
modelOptions: buildModelOptions(
38+
config,
39+
projectDefaultSelection,
40+
undefined,
41+
project?.id ?? null,
42+
),
3843
});
3944
}
4045

‎apps/mobile/src/features/threads/ThreadComposer.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,19 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
651651
? undefined
652652
: currentModelSelection.instanceId;
653653
const modelOptions = useMemo(
654-
() => buildModelOptions(props.serverConfig, currentModelSelection, lockedProviderInstanceId),
655-
[props.serverConfig, currentModelSelection, lockedProviderInstanceId],
654+
() =>
655+
buildModelOptions(
656+
props.serverConfig,
657+
currentModelSelection,
658+
lockedProviderInstanceId,
659+
props.selectedThread.projectId,
660+
),
661+
[
662+
props.serverConfig,
663+
currentModelSelection,
664+
lockedProviderInstanceId,
665+
props.selectedThread.projectId,
666+
],
656667
);
657668
const threadProviderGroups = useMemo(() => groupByProvider(modelOptions), [modelOptions]);
658669
const currentModelOption =

‎apps/mobile/src/features/threads/new-task-flow-provider.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,15 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
583583
buildModelOptions(
584584
selectedEnvironmentServerConfig,
585585
draftModelSelection ?? projectDefaultModelSelection ?? stickyModelSelection,
586+
undefined,
587+
selectedProject?.id ?? null,
586588
),
587589
[
588590
selectedEnvironmentServerConfig,
589591
draftModelSelection,
590592
projectDefaultModelSelection,
591593
stickyModelSelection,
594+
selectedProject?.id,
592595
],
593596
);
594597

‎apps/mobile/src/lib/modelOptions.test.ts‎

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { describe, expect, it } from "vite-plus/test";
22

3-
import { ProviderInstanceId, type ModelSelection, type ServerConfig } from "@t3tools/contracts";
3+
import {
4+
DEFAULT_SERVER_SETTINGS,
5+
ProjectId,
6+
ProviderDriverKind,
7+
ProviderInstanceId,
8+
type ModelSelection,
9+
type ServerConfig,
10+
type ServerSettings,
11+
} from "@t3tools/contracts";
412

513
import {
614
buildModelOptions,
@@ -503,4 +511,68 @@ describe("mobile model options", () => {
503511
}),
504512
).toBeNull();
505513
});
514+
515+
describe("project-aware enablement", () => {
516+
const projectId = ProjectId.make("project-a");
517+
const instanceId = ProviderInstanceId.make("codex_work");
518+
519+
function configWith(settings: ServerSettings): ServerConfig {
520+
return {
521+
providers: [
522+
{
523+
instanceId,
524+
driver: "codex",
525+
displayName: "Codex Work",
526+
enabled: true,
527+
installed: true,
528+
auth: { status: "authenticated" },
529+
models: [{ slug: "model-a", name: "Model A", isCustom: false, capabilities: null }],
530+
},
531+
],
532+
settings,
533+
} as unknown as ServerConfig;
534+
}
535+
536+
it("hides an instance the project disables even though the machine enables it", () => {
537+
const settings: ServerSettings = {
538+
...DEFAULT_SERVER_SETTINGS,
539+
providerInstances: {
540+
[instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
541+
},
542+
projectSettingsOverrides: {
543+
[projectId]: { providerInstanceEnablement: { [instanceId]: false } },
544+
},
545+
};
546+
547+
expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toEqual([]);
548+
});
549+
550+
it("shows an instance the project enables even though the machine disables it", () => {
551+
const settings: ServerSettings = {
552+
...DEFAULT_SERVER_SETTINGS,
553+
providerInstances: {
554+
[instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: false },
555+
},
556+
projectSettingsOverrides: {
557+
[projectId]: { providerInstanceEnablement: { [instanceId]: true } },
558+
},
559+
};
560+
561+
expect(buildModelOptions(configWith(settings), null, undefined, projectId)).toHaveLength(1);
562+
});
563+
564+
it("falls back to the machine value with no project in scope", () => {
565+
const settings: ServerSettings = {
566+
...DEFAULT_SERVER_SETTINGS,
567+
providerInstances: {
568+
[instanceId]: { driver: ProviderDriverKind.make("codex"), enabled: true },
569+
},
570+
projectSettingsOverrides: {
571+
[projectId]: { providerInstanceEnablement: { [instanceId]: false } },
572+
},
573+
};
574+
575+
expect(buildModelOptions(configWith(settings), null, undefined, null)).toHaveLength(1);
576+
});
577+
});
506578
});

‎apps/mobile/src/lib/modelOptions.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import type { MenuAction } from "@react-native-menu/menu";
22
import type {
33
ModelCapabilities,
44
ModelSelection,
5+
ProjectId,
56
RuntimeMode,
67
ServerConfig as T3ServerConfig,
78
} from "@t3tools/contracts";
9+
import { resolveProjectProviderInstanceEnabled } from "@t3tools/contracts";
810
import {
911
buildExplicitProviderOptionSelectionsFromDescriptors,
1012
getProviderOptionDescriptors,
@@ -167,13 +169,20 @@ export function buildModelOptions(
167169
config: T3ServerConfig | null | undefined,
168170
fallbackModelSelection: ModelSelection | null,
169171
providerInstanceId?: ModelSelection["instanceId"],
172+
projectId: ProjectId | null = null,
170173
): ReadonlyArray<ModelOption> {
171174
const options = new Map<string, ModelOption>();
172175

173176
for (const provider of config?.providers ?? []) {
177+
// `provider.enabled` reflects the machine plus any project's keep-alive
178+
// override, so it alone can't tell this project apart from one that
179+
// merely shares the instance. Settings carry the real per-project view.
180+
const isEnabledForProject = config?.settings
181+
? resolveProjectProviderInstanceEnabled(config.settings, projectId, provider.instanceId)
182+
: provider.enabled;
174183
if (
175184
(providerInstanceId !== undefined && provider.instanceId !== providerInstanceId) ||
176-
!provider.enabled ||
185+
!isEnabledForProject ||
177186
!provider.installed ||
178187
provider.auth.status === "unauthenticated" ||
179188
(provider.driver === "antigravity" && provider.availability === "unavailable")

‎apps/server/src/mcp/McpToolAccess.race.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
2121
import * as ProjectionStore from "../orchestration-v2/ProjectionStore.ts";
2222
import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts";
2323
import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
24+
import * as ServerSettings from "../serverSettings.ts";
2425
import * as ProviderReplayHarness from "../orchestration-v2/testkit/ProviderReplayHarness.ts";
2526
import * as McpHttpServer from "./McpHttpServer.ts";
2627
import * as McpInvocationContext from "./McpInvocationContext.ts";
@@ -184,7 +185,7 @@ it.layer(layerOrchestrator)("writesThreads against a mode raise", (it) => {
184185
const shell = yield* projections.getThreadShell(threadId);
185186
assert.equal(shell?.runtimeMode, "full-access");
186187
assert.equal(shell?.title, "Before");
187-
}).pipe(Effect.provide(ThreadManagement.layer)),
188+
}).pipe(Effect.provide(ThreadManagement.layer.pipe(Layer.provide(ServerSettings.layerTest())))),
188189
);
189190

190191
it.effect("lets the write through when the thread stays within the caller's modes", () =>
@@ -195,6 +196,6 @@ it.layer(layerOrchestrator)("writesThreads against a mode raise", (it) => {
195196
const outcome = yield* renameRacingTheUser(threadId, false);
196197
assert.deepEqual(outcome, { renamed: true });
197198
assert.equal((yield* projections.getThreadShell(threadId))?.title, "Renamed by the agent");
198-
}).pipe(Effect.provide(ThreadManagement.layer)),
199+
}).pipe(Effect.provide(ThreadManagement.layer.pipe(Layer.provide(ServerSettings.layerTest())))),
199200
);
200201
});

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ function threadManagementFailure(error: unknown): OrchestratorMcpFailure {
213213
case "ThreadManagementProjectThreadsListError":
214214
case "ThreadManagementDurableRunProjectionError":
215215
return failure("orchestration_error", error.message);
216+
case "ThreadManagementProviderInstanceDisabledError":
217+
return failure("invalid_request", error.message);
216218
}
217219
}
218220

‎apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { threadShellFromProjection } from "../orchestration-v2/ProjectionStore.t
5757
import * as EventSink from "../orchestration-v2/EventSink.ts";
5858
import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
5959
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
60+
import * as ServerSettings from "../serverSettings.ts";
6061
import * as ThreadSearch from "../orchestration-v2/ThreadSearch.ts";
6162
import * as ProviderAdapterRegistry from "../orchestration-v2/ProviderAdapterRegistry.ts";
6263
import * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
@@ -611,7 +612,10 @@ describe("orchestrator MCP toolkit", () => {
611612
).pipe(Layer.provide(layerContinuationProbe));
612613
const layerOrchestration = Layer.merge(
613614
layerOrchestrator,
614-
ThreadManagementService.layer.pipe(Layer.provide(layerOrchestrator)),
615+
ThreadManagementService.layer.pipe(
616+
Layer.provide(layerOrchestrator),
617+
Layer.provide(ServerSettings.layerTest()),
618+
),
615619
);
616620
const layerProviderRegistry = ProviderRegistryMock.layer([
617621
makeProviderSnapshot({
@@ -3807,7 +3811,10 @@ describe("orchestrator MCP toolkit", () => {
38073811
);
38083812
const layerOrchestration = Layer.merge(
38093813
layerOrchestrator,
3810-
ThreadManagementService.layer.pipe(Layer.provide(layerOrchestrator)),
3814+
ThreadManagementService.layer.pipe(
3815+
Layer.provide(layerOrchestrator),
3816+
Layer.provide(ServerSettings.layerTest()),
3817+
),
38113818
);
38123819
const layerProviderRegistry = ProviderRegistryMock.layer([
38133820
makeProviderSnapshot({

0 commit comments

Comments
 (0)