diff --git a/.changeset/auto-mode-tenant-switch.md b/.changeset/auto-mode-tenant-switch.md new file mode 100644 index 0000000000..e2ca412341 --- /dev/null +++ b/.changeset/auto-mode-tenant-switch.md @@ -0,0 +1,9 @@ +--- +'@truefoundry/trueforge-core': patch +'@truefoundry/trueforge': patch +'@truefoundry/trueforge-ui': patch +'@truefoundry/trueforge-assistant-ui-runtime': patch +'@truefoundry/trueforge-sdk': patch +--- + +Add a tenant switch for Auto mode, on by default, on the Models settings page. Admins reach the page in TrueFoundry mode when model routing is set up for the tenant; provider editing stays with the platform there. Turning it off turns off all model routing for the tenant: Auto leaves the model picker, `auto` specs are rejected, chats that already use Auto fail their next turn with "Auto mode is turned off for this tenant", and subagents run on their parent's model. `GET /api/v1/capabilities` leaves `auto` out when routing isn't set up for the tenant and gives a `reason` when it is unavailable. The configuration manifest adds `auto: { enabled }`. diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.json index 9c84039e70..68ac22c721 100644 --- a/.github/fern/openapi/openapi.json +++ b/.github/fern/openapi/openapi.json @@ -345,9 +345,27 @@ "type": "object" }, "AutoCapability": { + "description": "Present only when model routing is set up for the tenant; absent means Auto mode settings are hidden.", "properties": { "enabled": { - "description": "Whether Auto mode can be selected: the user has at least one model in every routing cluster.", + "description": "Whether Auto mode can be selected: the tenant allows it and the user has the models it picks from.", + "type": "boolean" + }, + "reason": { + "description": "Present when Auto mode is unavailable. Explains why.", + "type": "string" + } + }, + "required": [ + "enabled" + ], + "type": "object" + }, + "AutoConfiguration": { + "additionalProperties": false, + "properties": { + "enabled": { + "description": "Whether this tenant may use Auto mode, which picks a model for each turn and each subagent.", "type": "boolean" } }, @@ -518,7 +536,6 @@ "skill", "settings", "web_search", - "auto", "session_sharing" ], "type": "object" @@ -1006,6 +1023,9 @@ "ConfigurationManifest": { "additionalProperties": false, "properties": { + "auto": { + "$ref": "#/components/schemas/AutoConfiguration" + }, "memory": { "$ref": "#/components/schemas/MemoryConfiguration" }, @@ -1015,13 +1035,17 @@ }, "required": [ "web_search", - "memory" + "memory", + "auto" ], "type": "object" }, "ConfigurationManifestPatch": { "additionalProperties": false, "properties": { + "auto": { + "$ref": "#/components/schemas/AutoConfiguration" + }, "memory": { "$ref": "#/components/schemas/MemoryConfiguration" }, diff --git a/docs/openapi.json b/docs/openapi.json index 9c84039e70..68ac22c721 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -345,9 +345,27 @@ "type": "object" }, "AutoCapability": { + "description": "Present only when model routing is set up for the tenant; absent means Auto mode settings are hidden.", "properties": { "enabled": { - "description": "Whether Auto mode can be selected: the user has at least one model in every routing cluster.", + "description": "Whether Auto mode can be selected: the tenant allows it and the user has the models it picks from.", + "type": "boolean" + }, + "reason": { + "description": "Present when Auto mode is unavailable. Explains why.", + "type": "string" + } + }, + "required": [ + "enabled" + ], + "type": "object" + }, + "AutoConfiguration": { + "additionalProperties": false, + "properties": { + "enabled": { + "description": "Whether this tenant may use Auto mode, which picks a model for each turn and each subagent.", "type": "boolean" } }, @@ -518,7 +536,6 @@ "skill", "settings", "web_search", - "auto", "session_sharing" ], "type": "object" @@ -1006,6 +1023,9 @@ "ConfigurationManifest": { "additionalProperties": false, "properties": { + "auto": { + "$ref": "#/components/schemas/AutoConfiguration" + }, "memory": { "$ref": "#/components/schemas/MemoryConfiguration" }, @@ -1015,13 +1035,17 @@ }, "required": [ "web_search", - "memory" + "memory", + "auto" ], "type": "object" }, "ConfigurationManifestPatch": { "additionalProperties": false, "properties": { + "auto": { + "$ref": "#/components/schemas/AutoConfiguration" + }, "memory": { "$ref": "#/components/schemas/MemoryConfiguration" }, diff --git a/packages/assistant-ui-runtime/src/server/types.ts b/packages/assistant-ui-runtime/src/server/types.ts index 6908863e33..dabc051744 100644 --- a/packages/assistant-ui-runtime/src/server/types.ts +++ b/packages/assistant-ui-runtime/src/server/types.ts @@ -602,10 +602,10 @@ export interface AgentBuilderCapabilitiesResponse { /** Absent when the host does not offer memory, which hides memory settings; `reason` explains a locked toggle. */ memory?: { enabled: boolean; reason?: string }; /** - * Whether Auto mode can be selected in the model picker. Enabled when model routing is on and the user has a model - * in every routing cluster; absent means Auto mode cannot be selected. + * Absent when the host does not set up model routing, which hides Auto mode and its settings switch. Enabled when + * the tenant allows Auto mode and the user has the models it picks from; `reason` explains why it is unavailable. */ - auto?: { enabled: boolean }; + auto?: { enabled: boolean; reason?: string }; /** Finest supported sharing scope; `subject` allows invite-by-user as well as tenant-wide sharing. */ sessionSharing: { granularity: 'tenant' | 'subject' }; }; @@ -1097,12 +1097,14 @@ export interface TenantConfigurationSwitch { export interface TenantConfiguration { webSearch: TenantConfigurationSwitch; memory: TenantConfigurationSwitch; + auto: TenantConfigurationSwitch; } export interface UpdateTenantConfigurationRequest { /** Omit a switch to leave it as stored. */ webSearch?: TenantConfigurationSwitch; memory?: TenantConfigurationSwitch; + auto?: TenantConfigurationSwitch; } /** diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsx index 6102c2c370..a7ec9be02a 100644 --- a/packages/frontend/src/App.tsx +++ b/packages/frontend/src/App.tsx @@ -150,7 +150,7 @@ export function App() { if (first === undefined) { setBoot({ status: 'ready', - openSettings: capabilities.settings.modelProviders.enabled, + openSettings: capabilities.settings.modelProviders.manageProviders, defaultAgentSpec: { model: { name: '' }, config: sandboxConfig, diff --git a/packages/trueforge-core/src/agent-session/SessionHandle.ts b/packages/trueforge-core/src/agent-session/SessionHandle.ts index 5040c2b4bd..e2df0cb482 100644 --- a/packages/trueforge-core/src/agent-session/SessionHandle.ts +++ b/packages/trueforge-core/src/agent-session/SessionHandle.ts @@ -548,7 +548,7 @@ export class SessionHandle< } // If creating a new turn, route on the conversation and the new user input. if (input.routeModel === undefined) { - throw new AgentHarnessError('auto_model_unavailable', 'Auto model selection needs model routing for this tenant'); + throw new AgentHarnessError('auto_model_unavailable', 'Auto mode is turned off for this tenant'); } const routed = await input.routeModel({ threadId: MAIN_THREAD_ID, diff --git a/packages/trueforge-core/tests/agent-session/autoModel.test.ts b/packages/trueforge-core/tests/agent-session/autoModel.test.ts index d3139c1a71..f4c8fab45a 100644 --- a/packages/trueforge-core/tests/agent-session/autoModel.test.ts +++ b/packages/trueforge-core/tests/agent-session/autoModel.test.ts @@ -239,7 +239,7 @@ describe('auto model selection', () => { }), ).rejects.toMatchObject({ code: 'auto_model_unavailable', - message: 'Auto model selection needs model routing for this tenant', + message: 'Auto mode is turned off for this tenant', } satisfies Partial); }); diff --git a/packages/trueforge-sdk/src/api/types/AutoCapability.ts b/packages/trueforge-sdk/src/api/types/AutoCapability.ts index e17f1bedcd..01d5bdfbe6 100644 --- a/packages/trueforge-sdk/src/api/types/AutoCapability.ts +++ b/packages/trueforge-sdk/src/api/types/AutoCapability.ts @@ -1,6 +1,11 @@ // This file was auto-generated by Fern from our API Definition. +/** + * Present only when model routing is set up for the tenant; absent means Auto mode settings are hidden. + */ export interface AutoCapability { - /** Whether Auto mode can be selected: the user has at least one model in every routing cluster. */ + /** Whether Auto mode can be selected: the tenant allows it and the user has the models it picks from. */ enabled: boolean; + /** Present when Auto mode is unavailable. Explains why. */ + reason?: string; } diff --git a/packages/trueforge-sdk/src/api/types/AutoConfiguration.ts b/packages/trueforge-sdk/src/api/types/AutoConfiguration.ts new file mode 100644 index 0000000000..153b894d83 --- /dev/null +++ b/packages/trueforge-sdk/src/api/types/AutoConfiguration.ts @@ -0,0 +1,6 @@ +// This file was auto-generated by Fern from our API Definition. + +export interface AutoConfiguration { + /** Whether this tenant may use Auto mode, which picks a model for each turn and each subagent. */ + enabled: boolean; +} diff --git a/packages/trueforge-sdk/src/api/types/CapabilitiesData.ts b/packages/trueforge-sdk/src/api/types/CapabilitiesData.ts index 7f6478fe4b..83e9500d8c 100644 --- a/packages/trueforge-sdk/src/api/types/CapabilitiesData.ts +++ b/packages/trueforge-sdk/src/api/types/CapabilitiesData.ts @@ -3,7 +3,7 @@ import type * as TrueForge from "../index.js"; export interface CapabilitiesData { - auto: TrueForge.AutoCapability; + auto?: TrueForge.AutoCapability; memory?: TrueForge.MemoryCapability; sandbox: TrueForge.SandboxCapability; sessionSharing: TrueForge.SessionSharingCapability; diff --git a/packages/trueforge-sdk/src/api/types/ConfigurationManifest.ts b/packages/trueforge-sdk/src/api/types/ConfigurationManifest.ts index fe48173087..1eafa9a6bc 100644 --- a/packages/trueforge-sdk/src/api/types/ConfigurationManifest.ts +++ b/packages/trueforge-sdk/src/api/types/ConfigurationManifest.ts @@ -3,6 +3,7 @@ import type * as TrueForge from "../index.js"; export interface ConfigurationManifest { + auto: TrueForge.AutoConfiguration; memory: TrueForge.MemoryConfiguration; webSearch: TrueForge.WebSearchConfiguration; } diff --git a/packages/trueforge-sdk/src/api/types/ConfigurationManifestPatch.ts b/packages/trueforge-sdk/src/api/types/ConfigurationManifestPatch.ts index df5988f492..d82e5d517f 100644 --- a/packages/trueforge-sdk/src/api/types/ConfigurationManifestPatch.ts +++ b/packages/trueforge-sdk/src/api/types/ConfigurationManifestPatch.ts @@ -3,6 +3,7 @@ import type * as TrueForge from "../index.js"; export interface ConfigurationManifestPatch { + auto?: TrueForge.AutoConfiguration; memory?: TrueForge.MemoryConfiguration; webSearch?: TrueForge.WebSearchConfiguration; } diff --git a/packages/trueforge-sdk/src/api/types/index.ts b/packages/trueforge-sdk/src/api/types/index.ts index 76d82433c2..dcfd7b1860 100644 --- a/packages/trueforge-sdk/src/api/types/index.ts +++ b/packages/trueforge-sdk/src/api/types/index.ts @@ -13,6 +13,7 @@ export * from "./ApprovalDecision.js"; export * from "./ApprovalDeny.js"; export * from "./AskUserQuestionsConfig.js"; export * from "./AutoCapability.js"; +export * from "./AutoConfiguration.js"; export * from "./AvailableMcpServer.js"; export * from "./AvailableModel.js"; export * from "./AvailableModelProvider.js"; diff --git a/packages/trueforge-sdk/src/serialization/types/AutoCapability.ts b/packages/trueforge-sdk/src/serialization/types/AutoCapability.ts index 57e754aa87..160afc0aa4 100644 --- a/packages/trueforge-sdk/src/serialization/types/AutoCapability.ts +++ b/packages/trueforge-sdk/src/serialization/types/AutoCapability.ts @@ -7,10 +7,12 @@ import type * as serializers from "../index.js"; export const AutoCapability: core.serialization.ObjectSchema = core.serialization.object({ enabled: core.serialization.boolean(), + reason: core.serialization.string().optional(), }); export declare namespace AutoCapability { export interface Raw { enabled: boolean; + reason?: string | null; } } diff --git a/packages/trueforge-sdk/src/serialization/types/AutoConfiguration.ts b/packages/trueforge-sdk/src/serialization/types/AutoConfiguration.ts new file mode 100644 index 0000000000..8927bc1184 --- /dev/null +++ b/packages/trueforge-sdk/src/serialization/types/AutoConfiguration.ts @@ -0,0 +1,18 @@ +// This file was auto-generated by Fern from our API Definition. + +import type * as TrueForge from "../../api/index.js"; +import * as core from "../../core/index.js"; +import type * as serializers from "../index.js"; + +export const AutoConfiguration: core.serialization.ObjectSchema< + serializers.AutoConfiguration.Raw, + TrueForge.AutoConfiguration +> = core.serialization.object({ + enabled: core.serialization.boolean(), +}); + +export declare namespace AutoConfiguration { + export interface Raw { + enabled: boolean; + } +} diff --git a/packages/trueforge-sdk/src/serialization/types/CapabilitiesData.ts b/packages/trueforge-sdk/src/serialization/types/CapabilitiesData.ts index b701e88dd2..96fcf1bfa9 100644 --- a/packages/trueforge-sdk/src/serialization/types/CapabilitiesData.ts +++ b/packages/trueforge-sdk/src/serialization/types/CapabilitiesData.ts @@ -15,7 +15,7 @@ export const CapabilitiesData: core.serialization.ObjectSchema< serializers.CapabilitiesData.Raw, TrueForge.CapabilitiesData > = core.serialization.object({ - auto: AutoCapability, + auto: AutoCapability.optional(), memory: MemoryCapability.optional(), sandbox: SandboxCapability, sessionSharing: core.serialization.property("session_sharing", SessionSharingCapability), @@ -26,7 +26,7 @@ export const CapabilitiesData: core.serialization.ObjectSchema< export declare namespace CapabilitiesData { export interface Raw { - auto: AutoCapability.Raw; + auto?: AutoCapability.Raw | null; memory?: MemoryCapability.Raw | null; sandbox: SandboxCapability.Raw; session_sharing: SessionSharingCapability.Raw; diff --git a/packages/trueforge-sdk/src/serialization/types/ConfigurationManifest.ts b/packages/trueforge-sdk/src/serialization/types/ConfigurationManifest.ts index 9895e86222..75457a21ac 100644 --- a/packages/trueforge-sdk/src/serialization/types/ConfigurationManifest.ts +++ b/packages/trueforge-sdk/src/serialization/types/ConfigurationManifest.ts @@ -3,6 +3,7 @@ import type * as TrueForge from "../../api/index.js"; import * as core from "../../core/index.js"; import type * as serializers from "../index.js"; +import { AutoConfiguration } from "./AutoConfiguration.js"; import { MemoryConfiguration } from "./MemoryConfiguration.js"; import { WebSearchConfiguration } from "./WebSearchConfiguration.js"; @@ -10,12 +11,14 @@ export const ConfigurationManifest: core.serialization.ObjectSchema< serializers.ConfigurationManifest.Raw, TrueForge.ConfigurationManifest > = core.serialization.object({ + auto: AutoConfiguration, memory: MemoryConfiguration, webSearch: core.serialization.property("web_search", WebSearchConfiguration), }); export declare namespace ConfigurationManifest { export interface Raw { + auto: AutoConfiguration.Raw; memory: MemoryConfiguration.Raw; web_search: WebSearchConfiguration.Raw; } diff --git a/packages/trueforge-sdk/src/serialization/types/ConfigurationManifestPatch.ts b/packages/trueforge-sdk/src/serialization/types/ConfigurationManifestPatch.ts index 18e3b5785f..4aa665474a 100644 --- a/packages/trueforge-sdk/src/serialization/types/ConfigurationManifestPatch.ts +++ b/packages/trueforge-sdk/src/serialization/types/ConfigurationManifestPatch.ts @@ -3,6 +3,7 @@ import type * as TrueForge from "../../api/index.js"; import * as core from "../../core/index.js"; import type * as serializers from "../index.js"; +import { AutoConfiguration } from "./AutoConfiguration.js"; import { MemoryConfiguration } from "./MemoryConfiguration.js"; import { WebSearchConfiguration } from "./WebSearchConfiguration.js"; @@ -10,12 +11,14 @@ export const ConfigurationManifestPatch: core.serialization.ObjectSchema< serializers.ConfigurationManifestPatch.Raw, TrueForge.ConfigurationManifestPatch > = core.serialization.object({ + auto: AutoConfiguration.optional(), memory: MemoryConfiguration.optional(), webSearch: core.serialization.property("web_search", WebSearchConfiguration.optional()), }); export declare namespace ConfigurationManifestPatch { export interface Raw { + auto?: AutoConfiguration.Raw | null; memory?: MemoryConfiguration.Raw | null; web_search?: WebSearchConfiguration.Raw | null; } diff --git a/packages/trueforge-sdk/src/serialization/types/index.ts b/packages/trueforge-sdk/src/serialization/types/index.ts index 76d82433c2..dcfd7b1860 100644 --- a/packages/trueforge-sdk/src/serialization/types/index.ts +++ b/packages/trueforge-sdk/src/serialization/types/index.ts @@ -13,6 +13,7 @@ export * from "./ApprovalDecision.js"; export * from "./ApprovalDeny.js"; export * from "./AskUserQuestionsConfig.js"; export * from "./AutoCapability.js"; +export * from "./AutoConfiguration.js"; export * from "./AvailableMcpServer.js"; export * from "./AvailableModel.js"; export * from "./AvailableModelProvider.js"; diff --git a/packages/trueforge-sdk/tests/wire/server.test.ts b/packages/trueforge-sdk/tests/wire/server.test.ts index 5d45a26108..83d131bf5b 100644 --- a/packages/trueforge-sdk/tests/wire/server.test.ts +++ b/packages/trueforge-sdk/tests/wire/server.test.ts @@ -11,7 +11,7 @@ describe("ServerClient", () => { const rawResponseBody = { data: { - auto: { enabled: true }, + auto: { enabled: true, reason: "reason" }, memory: { enabled: true, reason: "reason" }, sandbox: { enabled: true, environments: { enabled: true } }, session_sharing: { granularity: "tenant" }, @@ -41,6 +41,7 @@ describe("ServerClient", () => { data: { auto: { enabled: true, + reason: "reason", }, memory: { enabled: true, diff --git a/packages/trueforge-sdk/tests/wire/settings/configuration.test.ts b/packages/trueforge-sdk/tests/wire/settings/configuration.test.ts index 5ec49ced77..a55903c6ff 100644 --- a/packages/trueforge-sdk/tests/wire/settings/configuration.test.ts +++ b/packages/trueforge-sdk/tests/wire/settings/configuration.test.ts @@ -11,7 +11,7 @@ describe("ConfigurationClient", () => { const rawResponseBody = { data: { - manifest: { memory: { enabled: true }, web_search: { enabled: true } }, + manifest: { auto: { enabled: true }, memory: { enabled: true }, web_search: { enabled: true } }, updated_at: "2024-01-15T09:30:00Z", }, }; @@ -28,6 +28,9 @@ describe("ConfigurationClient", () => { expect(response).toEqual({ data: { manifest: { + auto: { + enabled: true, + }, memory: { enabled: true, }, @@ -84,7 +87,7 @@ describe("ConfigurationClient", () => { const rawRequestBody = { manifest: {} }; const rawResponseBody = { data: { - manifest: { memory: { enabled: true }, web_search: { enabled: true } }, + manifest: { auto: { enabled: true }, memory: { enabled: true }, web_search: { enabled: true } }, updated_at: "2024-01-15T09:30:00Z", }, }; @@ -104,6 +107,9 @@ describe("ConfigurationClient", () => { expect(response).toEqual({ data: { manifest: { + auto: { + enabled: true, + }, memory: { enabled: true, }, diff --git a/packages/trueforge-ui/src/analytics/events.ts b/packages/trueforge-ui/src/analytics/events.ts index b135a3ac7d..3b442f0fcd 100644 --- a/packages/trueforge-ui/src/analytics/events.ts +++ b/packages/trueforge-ui/src/analytics/events.ts @@ -49,6 +49,7 @@ export const AnalyticsEvents = { WEB_SEARCH_PROVIDER_SAVED: 'trueforge.settings.web_search_provider_saved', WEB_SEARCH_TENANT_TOGGLED: 'trueforge.settings.web_search_tenant_toggled', MEMORY_TENANT_TOGGLED: 'trueforge.settings.memory_tenant_toggled', + AUTO_MODE_TENANT_TOGGLED: 'trueforge.settings.auto_mode_tenant_toggled', MEMORY_PROVIDER_SAVED: 'trueforge.settings.memory_provider_saved', TYPEFACE_CHANGED: 'trueforge.settings.typeface_changed', TYPEFACE_RESET: 'trueforge.settings.typeface_reset', diff --git a/packages/trueforge-ui/src/atoms/draft/DraftModelCatalogPanel.tsx b/packages/trueforge-ui/src/atoms/draft/DraftModelCatalogPanel.tsx index 51512ffd37..6d4a3174c6 100644 --- a/packages/trueforge-ui/src/atoms/draft/DraftModelCatalogPanel.tsx +++ b/packages/trueforge-ui/src/atoms/draft/DraftModelCatalogPanel.tsx @@ -7,7 +7,7 @@ import { cn } from '../lib/cn.js'; import { auiInputClass } from '../lib/inputClasses.js'; import { CatalogLogo } from '../primitives/CatalogLogo.js'; import { Tooltip, type TooltipSide } from '../primitives/Tooltip.js'; -import { AUTO_MODEL, AUTO_MODEL_LABEL, AUTO_MODEL_UNAVAILABLE_HINT } from './autoModel.js'; +import { AUTO_MODEL, AUTO_MODEL_LABEL } from './autoModel.js'; import { DraftCatalogEmptyState } from './DraftCatalogEmptyState.js'; import { modelMatchesQuery, normalizeModelSearchText } from './modelSearch.js'; @@ -55,6 +55,8 @@ export function ProviderMark({ logo, label, className }: { logo?: string; label: export type DraftAutoModelOption = { enabled: boolean; + /** Shown under the option while it is disabled. */ + unavailableHint: string; onSelect: () => void; }; @@ -214,7 +216,7 @@ export function DraftModelCatalogPanel({ {AUTO_MODEL_LABEL} {autoOption.enabled ? null : ( - {AUTO_MODEL_UNAVAILABLE_HINT} + {autoOption.unavailableHint} )} diff --git a/packages/trueforge-ui/src/atoms/draft/DraftModelSelector.tsx b/packages/trueforge-ui/src/atoms/draft/DraftModelSelector.tsx index 8e741368d5..dc4220e43d 100644 --- a/packages/trueforge-ui/src/atoms/draft/DraftModelSelector.tsx +++ b/packages/trueforge-ui/src/atoms/draft/DraftModelSelector.tsx @@ -17,7 +17,7 @@ import { useIsMobile } from '../lib/useIsMobile.js'; import { BottomSheet } from '../primitives/BottomSheet.js'; import { Button } from '../primitives/Button.js'; import { Tooltip } from '../primitives/Tooltip.js'; -import { AUTO_MODEL, AUTO_MODEL_PATCH, keepsAutoModel } from './autoModel.js'; +import { AUTO_MODEL, AUTO_MODEL_PATCH, AUTO_MODEL_UNAVAILABLE_HINT, keepsAutoModel } from './autoModel.js'; import { useDraftCatalog } from './DraftCatalogProvider.js'; import { displayModelLabel, DraftModelCatalogPanel, ModelWarningMark, ProviderMark } from './DraftModelCatalogPanel.js'; import { DraftReasoningEffortMenu } from './DraftReasoningEffortMenu.js'; @@ -159,10 +159,15 @@ export function DraftModelSelector({ disabled, isRunning }: DraftModelSelectorPr setEffortTarget(null); }} listboxId={menuId} - autoOption={{ - enabled: capabilities?.auto?.enabled === true, - onSelect: () => commit(AUTO_MODEL_PATCH), - }} + autoOption={ + capabilities?.auto === undefined + ? undefined + : { + enabled: capabilities.auto.enabled, + unavailableHint: capabilities.auto.reason ?? AUTO_MODEL_UNAVAILABLE_HINT, + onSelect: () => commit(AUTO_MODEL_PATCH), + } + } reasoning={{ effortLabel: model => hasReasoningEfforts(model.properties.reasoningEfforts) ? reasoningEffortLabel(effortFor(model)) : undefined, diff --git a/packages/trueforge-ui/src/containers/SettingsBuilder/AutoModeSetting.tsx b/packages/trueforge-ui/src/containers/SettingsBuilder/AutoModeSetting.tsx new file mode 100644 index 0000000000..cb540c2ba8 --- /dev/null +++ b/packages/trueforge-ui/src/containers/SettingsBuilder/AutoModeSetting.tsx @@ -0,0 +1,90 @@ +'use client'; + +import { useEffect, useState } from 'react'; + +import { useTrackAnalytics } from '@/analytics/AnalyticsProvider.js'; +import { AnalyticsEvents } from '@/analytics/events.js'; +import { Switch } from '../../atoms/primitives/Switch.js'; +import { useOptionalConfigurationServer, useOptionalRefreshServerCapabilities } from '../../server/ServerContext.js'; +import { getErrorMessage } from '../../utils/getErrorMessage.js'; +import { useToasterOptional } from '../ToasterContainer.js'; + +/** The tenant's Auto mode switch. Renders nothing without a configuration port. */ +const AutoModeSetting = () => { + const configuration = useOptionalConfigurationServer(); + const refreshCapabilities = useOptionalRefreshServerCapabilities(); + const toaster = useToasterOptional(); + const track = useTrackAnalytics(); + + // `null` until the switch loads, so the control is not rendered half-known. + const [enabled, setEnabled] = useState(null); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + if (!configuration) return; + let cancelled = false; + void configuration + .getConfiguration() + .then(loaded => { + if (!cancelled) setEnabled(loaded.auto.enabled); + }) + .catch((err: unknown) => { + if (!cancelled) setError(getErrorMessage(err, 'Failed to load the Auto mode setting')); + }); + return () => { + cancelled = true; + }; + }, [configuration]); + + if (!configuration) return null; + + const handleToggle = async (next: boolean) => { + setBusy(true); + setError(null); + try { + const saved = await configuration.updateConfiguration({ auto: { enabled: next } }); + setEnabled(saved.auto.enabled); + // The model picker offers or withholds Auto with this switch. + refreshCapabilities?.(); + toaster?.showSuccess({ title: saved.auto.enabled ? 'Auto mode turned on' : 'Auto mode turned off' }); + track(AnalyticsEvents.Settings.AUTO_MODE_TENANT_TOGGLED, { enabled: saved.auto.enabled }); + } catch (err) { + setError(getErrorMessage(err, 'Failed to save the Auto mode setting')); + } finally { + setBusy(false); + } + }; + + return ( + <> + {error ? ( +

+ {error} +

+ ) : null} + {enabled !== null ? ( +
+
+

Allow Auto mode

+

+ {enabled + ? 'Chats can pick Auto, which chooses a model for each turn and each subagent.' + : 'Auto is unavailable, including in chats that already use it, and subagents run on their parent model.'} +

+
+ { + void handleToggle(next); + }} + /> +
+ ) : null} + + ); +}; + +export default AutoModeSetting; diff --git a/packages/trueforge-ui/src/containers/SettingsBuilder/ModelSettings.tsx b/packages/trueforge-ui/src/containers/SettingsBuilder/ModelSettings.tsx index ba5e7c52bd..59a610a874 100644 --- a/packages/trueforge-ui/src/containers/SettingsBuilder/ModelSettings.tsx +++ b/packages/trueforge-ui/src/containers/SettingsBuilder/ModelSettings.tsx @@ -8,6 +8,7 @@ import { Button } from '@/atoms/primitives/Button.js'; import { CatalogLogo } from '@/atoms/primitives/CatalogLogo.js'; import ConfirmDeleteDialog from '@/atoms/primitives/ConfirmDeleteDialog.js'; import SearchInput from '@/atoms/primitives/SearchInput.js'; +import AutoModeSetting from '@/containers/SettingsBuilder/AutoModeSetting.js'; import ConfigureModelProviderForm, { type ModelProviderKeyDraft, } from '@/containers/SettingsBuilder/ConfigureModelProviderForm.js'; @@ -16,7 +17,7 @@ import CustomModelProviderForm, { } from '@/containers/SettingsBuilder/CustomModelProviderForm.js'; import { useToasterOptional } from '@/containers/ToasterContainer.js'; import { Icon } from '@/icons/Icon.js'; -import { useCatalogServer } from '@/server/ServerContext.js'; +import { useCatalogServer, useServerCapabilities, useServerCapabilitiesSettled } from '@/server/ServerContext.js'; import type { ModelEntry, ModelProviderBase, ModelProviderCatalogEntry } from '@/server/types.js'; import { getErrorMessage } from '@/utils/getErrorMessage.js'; @@ -48,9 +49,16 @@ function catalogBaseUrl(provider: ModelProviderCatalogEntry): string { const ModelSettings = () => { const { modelCatalog } = useCatalogServer(); + const capabilities = useServerCapabilities(); + const capabilitiesSettled = useServerCapabilitiesSettled(); const toaster = useToasterOptional(); const track = useTrackAnalytics(); + // Providers belong to the platform when `manageProviders` is false, so only the Auto mode + // switch is the caller's to change. Unsettled capabilities withhold the provider calls. + const canManageProviders = capabilitiesSettled && capabilities?.settings?.modelProviders?.manageProviders !== false; + const showAutoMode = capabilities?.auto !== undefined; + const [query, setQuery] = useState(''); const [configured, setConfigured] = useState([]); const [catalog, setCatalog] = useState([]); @@ -80,6 +88,12 @@ const ModelSettings = () => { const normalizedQuery = query.trim().toLowerCase(); const refresh = useCallback(async () => { + if (!canManageProviders) { + setConfigured([]); + setCatalog([]); + setLoading(false); + return; + } setLoading(true); setError(null); try { @@ -94,7 +108,7 @@ const ModelSettings = () => { } finally { setLoading(false); } - }, [modelCatalog]); + }, [modelCatalog, canManageProviders]); useEffect(() => { void refresh(); @@ -322,7 +336,11 @@ const ModelSettings = () => { return ( <>

Models

-

Connect providers and choose which models are available.

+

+ {canManageProviders + ? 'Connect providers and choose which models are available.' + : 'Choose how models are picked for your chats.'} +

{error ? (

@@ -330,286 +348,290 @@ const ModelSettings = () => {

) : null} -
-
-
-
- -
- { - setFormError(null); - setCustomProviderToEdit(null); - setCustomProviderOpen(true); - }} - > - - Add Custom Provider - -
- -
- {loading ?

Loading…

: null} + {showAutoMode ? : null} - {!loading && matchingConfigured.length > 0 ? ( -
-
- Configured -
+ {canManageProviders ? ( +
+
+
+
+ +
+ { + setFormError(null); + setCustomProviderToEdit(null); + setCustomProviderOpen(true); + }} + > + + Add Custom Provider + +
-
- {matchingConfigured.map(provider => { - const catalogModels = catalogModelsByType.get(provider.type) ?? []; - const configuredIds = new Set(provider.models.map(model => model.id)); - const availableModels = catalogModels.filter(model => !configuredIds.has(model.id)); - const logoSrc = modelProviderIconMap[provider.name]; - - return ( -
-
-
-
- {logoSrc ? ( - - ) : ( - - )} +
+ {loading ?

Loading…

: null} + + {!loading && matchingConfigured.length > 0 ? ( +
+
+ Configured +
+ +
+ {matchingConfigured.map(provider => { + const catalogModels = catalogModelsByType.get(provider.type) ?? []; + const configuredIds = new Set(provider.models.map(model => model.id)); + const availableModels = catalogModels.filter(model => !configuredIds.has(model.id)); + const logoSrc = modelProviderIconMap[provider.name]; + + return ( +
+
+
+
+ {logoSrc ? ( + + ) : ( + + )} +
+
{provider.name}
-
{provider.name}
-
-
- - - Connected - - { - if (provider.type === 'custom') { - closeKeyEditor(); - setFormError(null); - setCustomProviderToEdit(provider); - setCustomProviderOpen(true); - } else { - setKeyError(null); - setEditingCatalogType(null); - setEditingProviderId(provider.id); - } - }} - > - - Edit - - {modelCatalog.deleteModelProvider ? ( +
+ + + Connected + { - setRemoveError(null); - setPendingRemoval({ kind: 'provider', provider }); + if (provider.type === 'custom') { + closeKeyEditor(); + setFormError(null); + setCustomProviderToEdit(provider); + setCustomProviderOpen(true); + } else { + setKeyError(null); + setEditingCatalogType(null); + setEditingProviderId(provider.id); + } }} > - Remove + + Edit - ) : null} -
-
- -
- {provider.models.map(model => ( -
- {model.name} - {/* The last model can only go by removing the provider with it. */} - {provider.models.length > 1 || modelCatalog.deleteModelProvider ? ( - + Remove + ) : null}
- ))} + - {availableModels.length > 0 ? ( -
-
- Available to add · {availableModels.length} -
- {availableModels.map(model => ( -
- {model.name} - + {provider.models.map(model => ( +
+ {model.name} + {/* The last model can only go by removing the provider with it. */} + {provider.models.length > 1 || modelCatalog.deleteModelProvider ? ( +
- ))} -
- ) : null} -
-
- ); - })} -
-
- ) : null} - - {!loading && matchingAvailable.length > 0 ? ( -
-
- Available -
+ + + ) : null} +
+ ))} -
- {matchingAvailable.map(provider => { - const logoSrc = modelProviderIconMap[provider.name]; - return ( -
-
-
- - {logoSrc ? ( - - ) : ( - - )} - -
-
{provider.name}
-

- {provider.models.map(model => model.name).join(' · ')} -

-
+ {availableModels.length > 0 ? ( +
+
+ Available to add · {availableModels.length} +
+ {availableModels.map(model => ( +
+ {model.name} + { + void updateModels({ provider, models: [...provider.models, model] }).catch( + () => {}, + ); + }} + > + Add + +
+ ))} +
+ ) : null}
- { - setKeyError(null); - setEditingProviderId(null); - setEditingCatalogType(provider.type); - }} - > - - Configure - -
-
- ); - })} + + ); + })} +
+ + ) : null} + + {!loading && matchingAvailable.length > 0 ? ( +
+
+ Available +
+ +
+ {matchingAvailable.map(provider => { + const logoSrc = modelProviderIconMap[provider.name]; + return ( +
+
+
+ + {logoSrc ? ( + + ) : ( + + )} + +
+
{provider.name}
+

+ {provider.models.map(model => model.name).join(' · ')} +

+
+
+ { + setKeyError(null); + setEditingProviderId(null); + setEditingCatalogType(provider.type); + }} + > + + Configure + +
+
+ ); + })} +
+
+ ) : null} + + {!loading && matchingConfigured.length === 0 && matchingAvailable.length === 0 ? ( +
+ {normalizedQuery ? `No providers match “${query.trim()}”.` : 'No model providers yet.'}
- - ) : null} + ) : null} +
- {!loading && matchingConfigured.length === 0 && matchingAvailable.length === 0 ? ( -
- {normalizedQuery ? `No providers match “${query.trim()}”.` : 'No model providers yet.'} -
+ {pendingRemoval ? ( + { + handleConfirmRemoval(pendingRemoval); + }} + /> ) : null} -
- {pendingRemoval ? ( - { + if (!open) closeKeyEditor(); + }} + onSave={draft => { + if (editingProvider) return handleReplaceKey(editingProvider, draft); + if (editingCatalogEntry) return handleCreateFromCatalog(editingCatalogEntry, draft); + }} + title={editingProvider ? 'Edit Provider Details' : 'Configure Provider Details'} + initialBaseUrl={ + editingProvider + ? (editingProvider.baseUrl ?? '') + : editingCatalogEntry + ? catalogBaseUrl(editingCatalogEntry) + : '' } - description={removalDescription(pendingRemoval)} + requireApiKey={editingProvider == null} + submitLabel={editingProvider ? 'Save' : 'Create'} busy={busy} - error={removeError} - onCancel={closeRemoveDialog} - onConfirm={() => { - handleConfirmRemoval(pendingRemoval); + error={keyError} + /> + + { + setCustomProviderOpen(open); + if (!open) { + setFormError(null); + setCustomProviderToEdit(null); + } }} + isEditMode={customProviderToEdit !== null} + initialValues={customProviderInitialValues} + onSubmit={customProviderToEdit ? handleUpdateCustomProvider : handleAddCustomProvider} + reasoningEffortOptions={supportedReasoningEfforts} + busy={busy} + error={formError} /> - ) : null} - - { - if (!open) closeKeyEditor(); - }} - onSave={draft => { - if (editingProvider) return handleReplaceKey(editingProvider, draft); - if (editingCatalogEntry) return handleCreateFromCatalog(editingCatalogEntry, draft); - }} - title={editingProvider ? 'Edit Provider Details' : 'Configure Provider Details'} - initialBaseUrl={ - editingProvider - ? (editingProvider.baseUrl ?? '') - : editingCatalogEntry - ? catalogBaseUrl(editingCatalogEntry) - : '' - } - requireApiKey={editingProvider == null} - submitLabel={editingProvider ? 'Save' : 'Create'} - busy={busy} - error={keyError} - /> - - { - setCustomProviderOpen(open); - if (!open) { - setFormError(null); - setCustomProviderToEdit(null); - } - }} - isEditMode={customProviderToEdit !== null} - initialValues={customProviderInitialValues} - onSubmit={customProviderToEdit ? handleUpdateCustomProvider : handleAddCustomProvider} - reasoningEffortOptions={supportedReasoningEfforts} - busy={busy} - error={formError} - /> + - + ) : null} ); }; diff --git a/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/configurationServer.ts b/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/configurationServer.ts index d56b0451a7..39e52bd944 100644 --- a/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/configurationServer.ts +++ b/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/configurationServer.ts @@ -9,6 +9,7 @@ function toUiConfiguration(manifest: TrueForgeApi.ConfigurationManifest): Tenant return { webSearch: { enabled: manifest.webSearch.enabled }, memory: { enabled: manifest.memory.enabled }, + auto: { enabled: manifest.auto.enabled }, }; } @@ -23,6 +24,7 @@ export function createConfigurationServer(client: TrueForge): ConfigurationServe manifest: { ...(req.webSearch === undefined ? {} : { webSearch: { enabled: req.webSearch.enabled } }), ...(req.memory === undefined ? {} : { memory: { enabled: req.memory.enabled } }), + ...(req.auto === undefined ? {} : { auto: { enabled: req.auto.enabled } }), }, }); return toUiConfiguration(body.data.manifest); diff --git a/packages/trueforge-ui/test/atoms/draft/DraftModelSelector.test.tsx b/packages/trueforge-ui/test/atoms/draft/DraftModelSelector.test.tsx index 7c7f153b3e..0cd701d4e6 100644 --- a/packages/trueforge-ui/test/atoms/draft/DraftModelSelector.test.tsx +++ b/packages/trueforge-ui/test/atoms/draft/DraftModelSelector.test.tsx @@ -134,6 +134,29 @@ describe('DraftModelSelector', () => { expect(screen.getByRole('tooltip')).toHaveTextContent(longName); }); + it('lists Auto when the server offers it, disabled with its reason while the tenant has it off', async () => { + const reason = 'Auto mode is turned off for this tenant - an admin can turn it back on in settings.'; + const base = createMockAgentUIServer(); + renderSelector( + {}, + { + getModels: async () => models, + getCapabilities: async () => { + const { data } = await base.getCapabilities(); + return { data: { ...data, auto: { enabled: false, reason } } }; + }, + }, + ); + + const trigger = await screen.findByRole('button', { name: 'Select model' }); + await waitFor(() => expect(trigger).toHaveTextContent('gpt-4.1')); + fireEvent.click(trigger); + + const auto = await screen.findByRole('option', { name: /Auto/ }); + expect(auto).toBeDisabled(); + expect(auto).toHaveTextContent(reason); + }); + it('filters models and updates the agent spec when a model is selected', async () => { renderSelector(); @@ -147,11 +170,7 @@ describe('DraftModelSelector', () => { within(listbox) .getAllByRole('option') .map(option => option.textContent), - ).toEqual([ - expect.stringContaining('Auto'), - expect.stringContaining('gpt-4.1'), - expect.stringContaining('claude-3.7-sonnet'), - ]); + ).toEqual([expect.stringContaining('gpt-4.1'), expect.stringContaining('claude-3.7-sonnet')]); expect(within(listbox).getByText(/128K context/)).toBeInTheDocument(); const providerGroups = within(listbox).getAllByRole('group'); expect(providerGroups).toHaveLength(2); diff --git a/packages/trueforge-ui/test/containers/SettingsBuilder/MemorySettings.test.tsx b/packages/trueforge-ui/test/containers/SettingsBuilder/MemorySettings.test.tsx index 035a450e2b..8bda6b720b 100644 --- a/packages/trueforge-ui/test/containers/SettingsBuilder/MemorySettings.test.tsx +++ b/packages/trueforge-ui/test/containers/SettingsBuilder/MemorySettings.test.tsx @@ -30,7 +30,7 @@ const memoryCatalog: MemoryCatalogServer = { }; const memoryOn: ConfigurationServer = { - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }), updateConfiguration: unavailable, }; @@ -63,7 +63,11 @@ function renderSettings( describe('MemorySettings tenant switch', () => { it('shows the stored value', async () => { renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: false } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: false }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }); @@ -73,9 +77,17 @@ describe('MemorySettings tenant switch', () => { }); it('saves only the memory switch and re-renders from the response', async () => { - const updateConfiguration = vi.fn(async () => ({ webSearch: { enabled: true }, memory: { enabled: false } })); + const updateConfiguration = vi.fn(async () => ({ + webSearch: { enabled: true }, + memory: { enabled: false }, + auto: { enabled: true }, + })); renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration, }); @@ -92,8 +104,16 @@ describe('MemorySettings tenant switch', () => { it('refreshes capabilities after saving, so the agent Memory toggle unlocks right away', async () => { const { getCapabilities } = renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: false } }), - updateConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: false }, + auto: { enabled: true }, + }), + updateConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), }); const toggle = await screen.findByRole('switch', { name: 'Allow memory' }); @@ -162,8 +182,11 @@ describe('MemorySettings providers', () => { }); it('waits for the switch before listing providers, so an off tenant never flashes them', async () => { - let resolveConfiguration: (value: { webSearch: { enabled: boolean }; memory: { enabled: boolean } }) => void = () => - undefined; + let resolveConfiguration: (value: { + webSearch: { enabled: boolean }; + memory: { enabled: boolean }; + auto: { enabled: boolean }; + }) => void = () => undefined; const getMemoryProviderCatalog = vi.fn(memoryCatalog.getMemoryProviderCatalog); renderSettings( { @@ -183,7 +206,7 @@ describe('MemorySettings providers', () => { await act(() => new Promise(resolve => setTimeout(resolve, 20))); expect(screen.queryByText('Zep')).not.toBeInTheDocument(); - resolveConfiguration({ webSearch: { enabled: true }, memory: { enabled: true } }); + resolveConfiguration({ webSearch: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }); expect(await screen.findByText('Zep')).toBeInTheDocument(); }); }); diff --git a/packages/trueforge-ui/test/containers/SettingsBuilder/ModelSettings.test.tsx b/packages/trueforge-ui/test/containers/SettingsBuilder/ModelSettings.test.tsx index 4658ec1afc..972bd80f44 100644 --- a/packages/trueforge-ui/test/containers/SettingsBuilder/ModelSettings.test.tsx +++ b/packages/trueforge-ui/test/containers/SettingsBuilder/ModelSettings.test.tsx @@ -5,8 +5,9 @@ import { beforeAll, describe, expect, it, vi } from 'vitest'; import type { CustomProviderDraft } from '@/containers/SettingsBuilder/CustomModelProviderForm.js'; import ModelSettings from '@/containers/SettingsBuilder/ModelSettings.js'; import { ServerProvider } from '@/server/ServerContext.js'; -import type { ModelProviderBase, UpdateModelProviderRequest } from '@/server/types.js'; -import { createMockAgentUIServer, createMockCatalog } from '../../server/mockServer.js'; +import type { ConfigurationServer, ModelProviderBase, UpdateModelProviderRequest } from '@/server/types.js'; +import { createMockAgentUIServer, createMockCatalog, tenantSessionSharing } from '../../server/mockServer.js'; +import { allSettingsSections } from '../../server/settingsCapabilityFixture.js'; beforeAll(() => { HTMLDialogElement.prototype.showModal = function showModal() { @@ -155,3 +156,88 @@ describe('ModelSettings removal', () => { expect(screen.queryByRole('button', { name: 'Remove gpt-4-1' })).toBeNull(); }); }); + +describe('ModelSettings Auto mode switch', () => { + const autoOn = { webSearch: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }; + + function renderAutoSettings({ + auto, + manageProviders = true, + configuration, + }: { + auto: { enabled: boolean } | undefined; + manageProviders?: boolean; + configuration: ConfigurationServer; + }) { + const listModelProviders = vi.fn(async () => [builtInProvider]); + const getCapabilities = vi.fn(async () => ({ + data: { + sandbox: { enabled: true }, + skill: { enabled: true }, + sessionSharing: tenantSessionSharing, + settings: { ...allSettingsSections(true), modelProviders: { enabled: true, manageProviders } }, + ...(auto ? { auto } : {}), + }, + })); + const server = createMockAgentUIServer({ + catalog: createMockCatalog({ + modelCatalog: { + getModelProviderCatalog: async () => [], + listModelProviders, + createModelProvider: vi.fn(), + updateModelProvider: vi.fn(), + }, + }), + configuration, + getCapabilities, + }); + render( + + + , + ); + return { getCapabilities, listModelProviders }; + } + + it('saves only the Auto mode switch and refreshes capabilities so the picker updates', async () => { + const updateConfiguration = vi.fn(async () => ({ ...autoOn, auto: { enabled: false } })); + const { getCapabilities } = renderAutoSettings({ + auto: { enabled: true }, + configuration: { getConfiguration: async () => autoOn, updateConfiguration }, + }); + + const toggle = await screen.findByRole('switch', { name: 'Allow Auto mode' }); + expect(toggle).toHaveAttribute('aria-checked', 'true'); + await waitFor(() => expect(getCapabilities).toHaveBeenCalled()); + const callsBeforeSave = getCapabilities.mock.calls.length; + toggle.click(); + + await waitFor(() => expect(updateConfiguration).toHaveBeenCalledWith({ auto: { enabled: false } })); + await waitFor(() => + expect(screen.getByRole('switch', { name: 'Allow Auto mode' })).toHaveAttribute('aria-checked', 'false'), + ); + expect(getCapabilities.mock.calls.length).toBeGreaterThan(callsBeforeSave); + }); + + it('shows only the switch when the platform owns the providers', async () => { + const { listModelProviders } = renderAutoSettings({ + auto: { enabled: true }, + manageProviders: false, + configuration: { getConfiguration: async () => autoOn, updateConfiguration: vi.fn() }, + }); + + await screen.findByRole('switch', { name: 'Allow Auto mode' }); + expect(screen.queryByRole('button', { name: /Add Custom Provider/ })).toBeNull(); + expect(listModelProviders).not.toHaveBeenCalled(); + }); + + it('shows no switch when the server does not set up Auto mode', async () => { + renderAutoSettings({ + auto: undefined, + configuration: { getConfiguration: async () => autoOn, updateConfiguration: vi.fn() }, + }); + + await screen.findByText('gpt-4-1'); + expect(screen.queryByRole('switch', { name: 'Allow Auto mode' })).toBeNull(); + }); +}); diff --git a/packages/trueforge-ui/test/containers/SettingsBuilder/WebSearchSettings.test.tsx b/packages/trueforge-ui/test/containers/SettingsBuilder/WebSearchSettings.test.tsx index 8801668d89..fbd1a9c24a 100644 --- a/packages/trueforge-ui/test/containers/SettingsBuilder/WebSearchSettings.test.tsx +++ b/packages/trueforge-ui/test/containers/SettingsBuilder/WebSearchSettings.test.tsx @@ -57,7 +57,11 @@ function renderSettings( describe('WebSearchSettings tenant switch', () => { it('shows the switch on and lists providers when the tenant allows web search', async () => { renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }); @@ -68,7 +72,11 @@ describe('WebSearchSettings tenant switch', () => { it('hides the provider list while the tenant switch is off', async () => { renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: false }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: false }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }); @@ -81,7 +89,11 @@ describe('WebSearchSettings tenant switch', () => { it('says the switch can be turned back on while it is off', async () => { renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: false }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: false }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }); @@ -94,7 +106,11 @@ describe('WebSearchSettings tenant switch', () => { it('drops the provider sentence when the platform owns providers', async () => { renderSettings( { - getConfiguration: async () => ({ webSearch: { enabled: false }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: false }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }, { manageProviders: false }, @@ -105,9 +121,17 @@ describe('WebSearchSettings tenant switch', () => { }); it('asks before turning web search off, then saves and re-renders from the response', async () => { - const updateConfiguration = vi.fn(async () => ({ webSearch: { enabled: false }, memory: { enabled: true } })); + const updateConfiguration = vi.fn(async () => ({ + webSearch: { enabled: false }, + memory: { enabled: true }, + auto: { enabled: true }, + })); renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration, }); @@ -133,7 +157,11 @@ describe('WebSearchSettings tenant switch', () => { it('leaves web search on when the turn-off confirmation is cancelled', async () => { const updateConfiguration = vi.fn(unavailable); renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration, }); @@ -147,9 +175,17 @@ describe('WebSearchSettings tenant switch', () => { }); it('turns web search back on without a confirmation', async () => { - const updateConfiguration = vi.fn(async () => ({ webSearch: { enabled: true }, memory: { enabled: true } })); + const updateConfiguration = vi.fn(async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + })); renderSettings({ - getConfiguration: async () => ({ webSearch: { enabled: false }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: false }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration, }); @@ -176,7 +212,11 @@ describe('WebSearchSettings tenant switch', () => { const listWebSearchProviders = vi.fn(async () => []); renderSettings( { - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }, { manageProviders: false, catalog: { ...webSearchCatalog, listWebSearchProviders } }, @@ -190,8 +230,11 @@ describe('WebSearchSettings tenant switch', () => { }); it('waits for the switch before listing providers, so an off tenant never flashes them', async () => { - let resolveConfiguration: (value: { webSearch: { enabled: boolean }; memory: { enabled: boolean } }) => void = () => - undefined; + let resolveConfiguration: (value: { + webSearch: { enabled: boolean }; + memory: { enabled: boolean }; + auto: { enabled: boolean }; + }) => void = () => undefined; renderSettings({ getConfiguration: () => new Promise(resolve => { @@ -204,7 +247,7 @@ describe('WebSearchSettings tenant switch', () => { expect(screen.queryByText('Parallel')).not.toBeInTheDocument(); }); - resolveConfiguration({ webSearch: { enabled: true }, memory: { enabled: true } }); + resolveConfiguration({ webSearch: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }); expect(await screen.findByText('Parallel')).toBeInTheDocument(); }); }); diff --git a/packages/trueforge-ui/test/containers/SettingsBuilder/index.test.tsx b/packages/trueforge-ui/test/containers/SettingsBuilder/index.test.tsx index d0f2ba8132..74d9f04cf0 100644 --- a/packages/trueforge-ui/test/containers/SettingsBuilder/index.test.tsx +++ b/packages/trueforge-ui/test/containers/SettingsBuilder/index.test.tsx @@ -229,7 +229,11 @@ describe('TruefoundrySettingsBuilder', () => { const server = createMockAgentUIServer({ catalog: createMockCatalog({}), configuration: { - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }, getCapabilities: async () => ({ @@ -258,7 +262,11 @@ describe('TruefoundrySettingsBuilder', () => { const server = createMockAgentUIServer({ catalog: createMockCatalog({}), configuration: { - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }, }); @@ -273,7 +281,11 @@ describe('TruefoundrySettingsBuilder', () => { const server = createMockAgentUIServer({ catalog: createMockCatalog({}), configuration: { - getConfiguration: async () => ({ webSearch: { enabled: true }, memory: { enabled: true } }), + getConfiguration: async () => ({ + webSearch: { enabled: true }, + memory: { enabled: true }, + auto: { enabled: true }, + }), updateConfiguration: unavailable, }, getCapabilities: async () => ({ diff --git a/packages/trueforge/src/apis/capabilities.ts b/packages/trueforge/src/apis/capabilities.ts index 824ccc916a..b1ffd35194 100644 --- a/packages/trueforge/src/apis/capabilities.ts +++ b/packages/trueforge/src/apis/capabilities.ts @@ -5,6 +5,7 @@ import type { Logger } from 'winston'; import { areCatalogSettingsAvailable, hasAdminRole, type ResolveRequestContext } from '../auth/identity'; import { enabledTenantModelRouting, trueFoundryModelRouting } from '../config'; import { + isAutoEnabledForTenant, isMemoryEnabledForTenant, isWebSearchEnabledForTenant, type IConfigurationStore, @@ -38,25 +39,32 @@ function skillDisabledReason(status: SandboxEnvironmentVersionStatus | undefined * Settings sections the caller may open. * * Catalog sections need a deployment that owns its own catalogs; the tenant switches - * (web search, memory) only need the admin role, so a TrueFoundry tenant admin reaches + * (web search, memory, Auto mode) only need the admin role, so a TrueFoundry tenant admin reaches * them while provider editing stays with the platform. In TrueFoundry mode the memory - * section also needs the platform's provider, which the env offers per tenant. + * section also needs the platform's provider, which the env offers per tenant, and the models + * section opens for its Auto mode switch when model routing is set up for the tenant. */ function settingsCapability({ isAdmin, ownsCatalogs, hasMemoryProvider, + hasModelRouting, }: { isAdmin: boolean; /** False in TrueFoundry mode, where the platform owns the provider catalogs. */ ownsCatalogs: boolean; /** In TrueFoundry mode, true when the platform's env offers memory to the tenant. */ hasMemoryProvider: boolean; + /** True when the env sets up model routing for the tenant, so its Auto mode switch applies. */ + hasModelRouting: boolean; }) { const canManageProviders = ownsCatalogs && isAdmin; const catalogSection = { enabled: canManageProviders, manage_providers: canManageProviders }; return { - model_providers: catalogSection, + model_providers: { + enabled: canManageProviders || (isAdmin && hasModelRouting), + manage_providers: canManageProviders, + }, mcp_servers: catalogSection, skills: catalogSection, sandbox_providers: catalogSection, @@ -65,21 +73,32 @@ function settingsCapability({ }; } +const AUTO_TURNED_OFF_REASON = 'Auto mode is turned off for this tenant - an admin can turn it back on in settings.'; +const AUTO_UNAVAILABLE_REASON = 'Auto mode is not available for now'; + /** - * Auto needs model routing on for the tenant and a model the user has in every routing cluster. A failed listing - * fails the request, so clients keep their last known capabilities instead of dropping a selected Auto. + * Auto needs model routing set up for the tenant, the tenant switch on, and a model the user has in every routing + * cluster. Undefined when routing isn't set up, so clients hide Auto entirely. A failed listing fails the request, + * so clients keep their last known capabilities instead of dropping a selected Auto. */ -async function isAutoModelAvailable({ +async function autoCapability({ tenant_id, - store, + modelProviderStore, + configurationStore, }: { tenant_id: string; - store: IModelProviderStore; -}): Promise { + modelProviderStore: IModelProviderStore; + configurationStore: IConfigurationStore; +}): Promise<{ enabled: boolean; reason?: string } | undefined> { if (enabledTenantModelRouting(trueFoundryModelRouting(), tenant_id) === undefined) { - return false; + return undefined; + } + if (!(await isAutoEnabledForTenant({ tenant_id, store: configurationStore }))) { + return { enabled: false, reason: AUTO_TURNED_OFF_REASON }; } - return canRouteEveryCategory(await store.listModels({ tenant_id, has_catalog_info: true })); + return canRouteEveryCategory(await modelProviderStore.listModels({ tenant_id, has_catalog_info: true })) + ? { enabled: true } + : { enabled: false, reason: AUTO_UNAVAILABLE_REASON }; } export function createCapabilitiesRouter(deps: { @@ -110,7 +129,7 @@ export function createCapabilitiesRouter(deps: { (await deps.sandboxEnvironmentStore.getDefaultEnvironment({ tenant_id: requestContext.tenant_id }))?.version .status, ); - const [hasProvider, tenantAllowsWebSearch, tenantAllowsMemory, hasMemoryProvider, autoEnabled] = await Promise.all([ + const [hasProvider, tenantAllowsWebSearch, tenantAllowsMemory, hasMemoryProvider, auto] = await Promise.all([ hasConfiguredWebSearchProvider({ tenant_id: requestContext.tenant_id, store: deps.webSearchProviderStore, @@ -127,9 +146,10 @@ export function createCapabilitiesRouter(deps: { tenant_id: requestContext.tenant_id, store: deps.memoryProviderStore, }), - isAutoModelAvailable({ + autoCapability({ tenant_id: requestContext.tenant_id, - store: deps.resolveModelProviderStore(c), + modelProviderStore: deps.resolveModelProviderStore(c), + configurationStore: deps.configurationStore, }), ]); @@ -169,10 +189,11 @@ export function createCapabilitiesRouter(deps: { isAdmin: hasAdminRole(requestContext), ownsCatalogs: areCatalogSettingsAvailable(), hasMemoryProvider, + hasModelRouting: auto !== undefined, }), web_search: webSearchResponse, ...(memoryResponse && { memory: memoryResponse }), - auto: { enabled: autoEnabled }, + ...(auto && { auto }), session_sharing: sessionSharing, }, }, diff --git a/packages/trueforge/src/apis/configuration.ts b/packages/trueforge/src/apis/configuration.ts index 21421eb38f..ee4a963bbf 100644 --- a/packages/trueforge/src/apis/configuration.ts +++ b/packages/trueforge/src/apis/configuration.ts @@ -31,6 +31,7 @@ function applyPatch({ return { web_search: patch.web_search ?? current.web_search, memory: patch.memory ?? current.memory, + auto: patch.auto ?? current.auto, }; } diff --git a/packages/trueforge/src/apis/schedules.ts b/packages/trueforge/src/apis/schedules.ts index 16203cb267..9c3b16cd5c 100644 --- a/packages/trueforge/src/apis/schedules.ts +++ b/packages/trueforge/src/apis/schedules.ts @@ -30,6 +30,7 @@ import { } from '../controller/scheduleDispatch'; import type { AgentRecord, IAgentStore } from '../db/agentStore'; import { EmptyCapabilitiesStore } from '../db/capabilitiesStore'; +import type { IConfigurationStore } from '../db/configurationStore'; import type { IMcpServerWithAuthStore } from '../db/mcpServerStore'; import type { IModelProviderStore } from '../db/modelProviderStore'; import type { ISandboxEnvironmentStore } from '../db/sandboxEnvironmentStore'; @@ -90,6 +91,8 @@ export interface ScheduleTurnExecutionDeps { /** Previous-turn cancel, and rebuilding a missing event stream. */ sessionStore: Pick, 'getTurn' | 'listTurnEvents'>; webSearchProviderStore: IWebSearchProviderStore; + /** Tenant switches read during a turn: the Auto mode switch gates model routing. */ + configurationStore: IConfigurationStore; } export interface SchedulesRouterDeps extends ScheduleTurnExecutionDeps { @@ -132,6 +135,7 @@ export async function startScheduleRunOnRequest(params: { sandboxProviderStore: deps.sandboxProviderStore, sandboxEnvironmentStore: deps.sandboxEnvironmentStore, webSearchProviderStore: deps.webSearchProviderStore, + configurationStore: deps.configurationStore, skillStore: deps.resolveTurnSkillsStore({}), // Schedules have no caller `x-tfg-tools`. capabilitiesStore: new EmptyCapabilitiesStore(), diff --git a/packages/trueforge/src/apis/turns.ts b/packages/trueforge/src/apis/turns.ts index 417be83a76..f93f7f98f2 100644 --- a/packages/trueforge/src/apis/turns.ts +++ b/packages/trueforge/src/apis/turns.ts @@ -87,6 +87,7 @@ import configuration, { import type { IAccessControlStore } from '../db/accessControlStore'; import type { AgentRecord, IAgentStore } from '../db/agentStore'; import { EmptyCapabilitiesStore, type ICapabilitiesStore } from '../db/capabilitiesStore'; +import { isAutoEnabledForTenant, type IConfigurationStore } from '../db/configurationStore'; import type { IMcpServerWithAuthStore } from '../db/mcpServerStore'; import type { IModelProviderStore } from '../db/modelProviderStore'; import type { ISandboxEnvironmentStore } from '../db/sandboxEnvironmentStore'; @@ -203,6 +204,8 @@ export interface TurnExecutionStores { skillStore: Pick, 'resolveTurnSkills'>; sandboxProviderStore: ISandboxProviderStore; webSearchProviderStore: IWebSearchProviderStore; + /** Tenant switches read during a turn: the Auto mode switch gates model routing. */ + configurationStore: IConfigurationStore; /** Undefined for sessions that never use memory (scheduled runs). */ memory: TenantMemoryDeps | undefined; } @@ -263,6 +266,8 @@ export type BeginTurnExecutionDeps = Pick< sandboxProviderStore: ISandboxProviderStore; webSearchProviderStore: IWebSearchProviderStore; skillStore: Pick; + /** Tenant switches read during a turn: the Auto mode switch gates model routing. */ + configurationStore: IConfigurationStore; /** Undefined for sessions that never use memory (scheduled runs). */ memory: TenantMemoryDeps | undefined; /** Previous-turn cancel, and rebuilding a missing event stream. */ @@ -371,15 +376,17 @@ interface BeginTurnExecutionParams { deps: BeginTurnExecutionDeps; } -/** This turn's model routing inputs, or undefined when routing is off for the tenant. */ +/** This turn's model routing inputs, or undefined when routing is off for the tenant or its Auto mode switch is off. */ function turnModelRouting(input: { routing: TrueFoundryModelRouting | undefined; + /** The tenant's Auto mode switch; off turns every kind of routing off. */ + isAutoAllowed: boolean; tenant_id: string; modelProviderStore: IModelProviderStore; turnMetadata: TurnMetadata; }): ModelRouterDeps | undefined { const { routing, tenant_id, modelProviderStore, turnMetadata } = input; - if (routing === undefined) { + if (routing === undefined || !input.isAutoAllowed) { return undefined; } const tenantRouting = enabledTenantModelRouting(routing, tenant_id); @@ -787,7 +794,7 @@ async function prepareTurnExecution(input: { }> { assertGatewayMetadataRequestHeaders(input.requestHeaders); const abortController = new AbortController(); - const [webSearchProvider, memoryCapability] = await Promise.all([ + const [webSearchProvider, memoryCapability, isAutoAllowed] = await Promise.all([ resolveWebSearchProvider({ tenant_id: input.session.tenant_id, store: input.deps.webSearchProviderStore, @@ -801,6 +808,7 @@ async function prepareTurnExecution(input: { agentStore: input.deps.agentStore, logger: input.deps.logger, }), + isAutoEnabledForTenant({ tenant_id: input.session.tenant_id, store: input.deps.configurationStore }), ]); const sessionAgent = input.session.record.agent; @@ -825,6 +833,7 @@ async function prepareTurnExecution(input: { modelProviderStore: input.deps.modelProviderStore, modelRouting: turnModelRouting({ routing: trueFoundryModelRouting(), + isAutoAllowed, tenant_id: input.session.tenant_id, modelProviderStore: input.deps.modelProviderStore, turnMetadata, @@ -2464,6 +2473,8 @@ export interface InternalSessionTurnsDeps { sessions: Sessions; sessionStore: Pick, 'getTurn' | 'listTurnEvents'>; webSearchProviderStore: IWebSearchProviderStore; + /** Tenant switches read during a turn: the Auto mode switch gates model routing. */ + configurationStore: IConfigurationStore; } /** Register internal create-turn on a shared `/api/internal/sessions` router. */ @@ -2533,6 +2544,7 @@ export function registerInternalSessionTurnRoutes( sandboxProviderStore: deps.sandboxProviderStore, sandboxEnvironmentStore: deps.sandboxEnvironmentStore, webSearchProviderStore: deps.webSearchProviderStore, + configurationStore: deps.configurationStore, // Registry resolve uses the service API key (same as schedules); omit `c`. skillStore: deps.resolveTurnSkillsStore({}), // Internal create-turn has no caller `x-tfg-tools`. diff --git a/packages/trueforge/src/app.ts b/packages/trueforge/src/app.ts index 2eca2075c3..d579f9c66a 100644 --- a/packages/trueforge/src/app.ts +++ b/packages/trueforge/src/app.ts @@ -527,6 +527,7 @@ export function createServerApp(deps: ServerDeps) { sessions: deps.sessions, sessionStore: deps.sessionStore, webSearchProviderStore: deps.webSearchProviderStore, + configurationStore: deps.configurationStore, }; app.route( '/api/internal/schedules', @@ -620,6 +621,7 @@ export function createServerApp(deps: ServerDeps) { sessions: deps.sessions, sessionStore: deps.sessionStore, webSearchProviderStore: deps.webSearchProviderStore, + configurationStore: deps.configurationStore, }); app.route('/api/internal/sessions', internalSessionsRouter); app.route( diff --git a/packages/trueforge/src/db/configurationStore.ts b/packages/trueforge/src/db/configurationStore.ts index dc04af44d8..08cc98bf0f 100644 --- a/packages/trueforge/src/db/configurationStore.ts +++ b/packages/trueforge/src/db/configurationStore.ts @@ -51,6 +51,19 @@ export async function isWebSearchEnabledForTenant({ return manifest.web_search.enabled; } +/** Whether the tenant switch lets this tenant use Auto mode and model routing. Reads only; never writes the row. */ +export async function isAutoEnabledForTenant({ + tenant_id, + store, +}: { + tenant_id: string; + store: IConfigurationStore; +}): Promise { + const record = await store.getConfiguration(tenant_id); + const manifest = record?.manifest ?? DEFAULT_CONFIGURATION_MANIFEST; + return manifest.auto.enabled; +} + /** Whether agents in this tenant may use memory. Creates the row if missing: ingestion only sees tenants with one. */ export async function isMemoryEnabledForTenant({ tenant_id, diff --git a/packages/trueforge/src/resolvers.ts b/packages/trueforge/src/resolvers.ts index 2a67820110..793b213b3a 100644 --- a/packages/trueforge/src/resolvers.ts +++ b/packages/trueforge/src/resolvers.ts @@ -428,6 +428,7 @@ export function createRequestStoreResolvers(input: { skillStore: turnSkillStoreFor({ headers: turnInput.requestHeaders, allowInlineResources }), sandboxProviderStore, webSearchProviderStore, + configurationStore, memory, }); }; diff --git a/packages/trueforge/src/routes/capabilityRoutes.ts b/packages/trueforge/src/routes/capabilityRoutes.ts index b34ea602ee..354db09f19 100644 --- a/packages/trueforge/src/routes/capabilityRoutes.ts +++ b/packages/trueforge/src/routes/capabilityRoutes.ts @@ -67,8 +67,10 @@ const AutoCapabilitySchema = z .object({ enabled: z .boolean() - .describe('Whether Auto mode can be selected: the user has at least one model in every routing cluster.'), + .describe('Whether Auto mode can be selected: the tenant allows it and the user has the models it picks from.'), + reason: z.string().optional().describe('Present when Auto mode is unavailable. Explains why.'), }) + .describe('Present only when model routing is set up for the tenant; absent means Auto mode settings are hidden.') .openapi('AutoCapability'); const SessionSharingCapabilitySchema = z @@ -90,7 +92,7 @@ const CapabilitiesDataSchema = z settings: SettingsCapabilitySchema, web_search: WebSearchCapabilitySchema, memory: MemoryCapabilitySchema.optional(), - auto: AutoCapabilitySchema, + auto: AutoCapabilitySchema.optional(), session_sharing: SessionSharingCapabilitySchema, }) .openapi('CapabilitiesData'); diff --git a/packages/trueforge/src/runtime/sessionResources.ts b/packages/trueforge/src/runtime/sessionResources.ts index dd9240f77f..80f1461302 100644 --- a/packages/trueforge/src/runtime/sessionResources.ts +++ b/packages/trueforge/src/runtime/sessionResources.ts @@ -17,6 +17,7 @@ import { join } from 'node:path'; import type { Logger } from 'winston'; import configuration, { enabledTenantModelRouting, type TrueFoundryModelRouting } from '../config'; import { + isAutoEnabledForTenant, isMemoryEnabledForTenant, isWebSearchEnabledForTenant, type IConfigurationStore, @@ -41,6 +42,8 @@ import { import type { ReasoningEffort } from '../schemas/modelProvider'; import { hasConfiguredWebSearchProvider } from '../websearch/providers'; +export const AUTO_MODE_TURNED_OFF_MESSAGE = 'Auto mode is turned off for this tenant'; + /** Split `provider/model` FQN. Returns undefined when the shape is not exactly one slash. */ export function parseModelFqn(name: string): { providerName: string; modelName: string } | undefined { const slash = name.indexOf('/'); @@ -306,7 +309,7 @@ export async function validateAgentSpec({ /** This process's model routing config. `auto` is rejected when this tenant's routing is off. */ modelRouting: TrueFoundryModelRouting | undefined; }): Promise { - // `auto` names no catalog model. It is only valid when this tenant routes models. + // `auto` names no catalog model. It is only valid when this tenant routes models and allows Auto mode. if (spec.model.name === AUTO_MODEL) { if (enabledTenantModelRouting(modelRouting, tenant_id) === undefined) { throw new HTTPException(422, { @@ -318,6 +321,9 @@ export async function validateAgentSpec({ message: 'Model "auto" does not accept model params', }); } + if (!(await isAutoEnabledForTenant({ tenant_id, store: configurationStore }))) { + throw new HTTPException(422, { message: AUTO_MODE_TURNED_OFF_MESSAGE }); + } } else { const resolved = await getModelDetails({ tenant_id, diff --git a/packages/trueforge/src/schemas/configuration.ts b/packages/trueforge/src/schemas/configuration.ts index b18b903888..8712c91545 100644 --- a/packages/trueforge/src/schemas/configuration.ts +++ b/packages/trueforge/src/schemas/configuration.ts @@ -16,10 +16,20 @@ const MemoryConfigurationSchema = z .strict() .openapi('MemoryConfiguration'); +const AutoConfigurationSchema = z + .object({ + enabled: z + .boolean() + .describe('Whether this tenant may use Auto mode, which picks a model for each turn and each subagent.'), + }) + .strict() + .openapi('AutoConfiguration'); + const ConfigurationManifestSchema = z .object({ web_search: WebSearchConfigurationSchema, memory: MemoryConfigurationSchema, + auto: AutoConfigurationSchema, }) .strict() .openapi('ConfigurationManifest'); @@ -62,6 +72,7 @@ export type ConfigurationFeature = keyof ConfigurationManifest; export const DEFAULT_CONFIGURATION_MANIFEST: ConfigurationManifest = { web_search: { enabled: true }, memory: { enabled: true }, + auto: { enabled: true }, }; /** diff --git a/packages/trueforge/tests/db/configurationStoreContractSuite.ts b/packages/trueforge/tests/db/configurationStoreContractSuite.ts index f00315cb2d..516e1599fa 100644 --- a/packages/trueforge/tests/db/configurationStoreContractSuite.ts +++ b/packages/trueforge/tests/db/configurationStoreContractSuite.ts @@ -2,7 +2,11 @@ * Backend-agnostic behavioural contract for IConfigurationStore. * Runs under jest against a fresh store per test (see backend test files). */ -import { isMemoryEnabledForTenant, type IConfigurationStore } from '../../src/db/configurationStore'; +import { + isAutoEnabledForTenant, + isMemoryEnabledForTenant, + type IConfigurationStore, +} from '../../src/db/configurationStore'; import type { ConfigurationManifest } from '../../src/schemas/configuration'; export interface ConfigurationStoreContractEnv { @@ -14,11 +18,11 @@ export interface ConfigurationStoreContractEnv { } function manifest({ webSearch, memory }: { webSearch: boolean; memory: boolean }): ConfigurationManifest { - return { web_search: { enabled: webSearch }, memory: { enabled: memory } }; + return { web_search: { enabled: webSearch }, memory: { enabled: memory }, auto: { enabled: true } }; } const LEGACY_MANIFEST_JSON = '{"web_search":{"enabled":false}}'; -const SEEDED = { web_search: { enabled: false }, memory: { enabled: true } }; +const SEEDED = { web_search: { enabled: false }, memory: { enabled: true }, auto: { enabled: true } }; export function runConfigurationStoreContractSuite(getEnv: () => ConfigurationStoreContractEnv): void { it('lists only tenants whose stored row has the given feature on', async () => { @@ -46,6 +50,7 @@ export function runConfigurationStoreContractSuite(getEnv: () => ConfigurationSt expect((await store.getConfiguration('legacy'))?.manifest).toEqual(SEEDED); expect(await readRawManifest('legacy')).toEqual(SEEDED); await expect(isMemoryEnabledForTenant({ tenant_id: 'legacy', store })).resolves.toBe(true); + await expect(isAutoEnabledForTenant({ tenant_id: 'legacy', store })).resolves.toBe(true); }); it('getOrCreateConfiguration seeds a missing switch without replacing the stored ones', async () => { diff --git a/packages/trueforge/tests/unit/apis/agents.test.ts b/packages/trueforge/tests/unit/apis/agents.test.ts index dd481ac1d1..2b8a3cf301 100644 --- a/packages/trueforge/tests/unit/apis/agents.test.ts +++ b/packages/trueforge/tests/unit/apis/agents.test.ts @@ -474,7 +474,7 @@ describe('agents router', () => { }); await configurationStore.upsertConfiguration({ tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id, - manifest: { web_search: { enabled: true }, memory: { enabled: false } }, + manifest: { web_search: { enabled: true }, memory: { enabled: false }, auto: { enabled: true } }, }); const webSearchManifest = { ...manifest, @@ -489,7 +489,7 @@ describe('agents router', () => { await configurationStore.upsertConfiguration({ tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id, - manifest: { web_search: { enabled: false }, memory: { enabled: false } }, + manifest: { web_search: { enabled: false }, memory: { enabled: false }, auto: { enabled: true } }, }); const res = await router.request( @@ -507,7 +507,7 @@ describe('agents router', () => { }); await configurationStore.upsertConfiguration({ tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id, - manifest: { web_search: { enabled: false }, memory: { enabled: true } }, + manifest: { web_search: { enabled: false }, memory: { enabled: true }, auto: { enabled: true } }, }); const memoryManifest = { ...manifest, @@ -522,7 +522,7 @@ describe('agents router', () => { await configurationStore.upsertConfiguration({ tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id, - manifest: { web_search: { enabled: false }, memory: { enabled: false } }, + manifest: { web_search: { enabled: false }, memory: { enabled: false }, auto: { enabled: true } }, }); const res = await router.request( diff --git a/packages/trueforge/tests/unit/apis/capabilities.test.ts b/packages/trueforge/tests/unit/apis/capabilities.test.ts index 911cfc3812..24cafda4f3 100644 --- a/packages/trueforge/tests/unit/apis/capabilities.test.ts +++ b/packages/trueforge/tests/unit/apis/capabilities.test.ts @@ -9,7 +9,8 @@ import { createAuthMiddleware } from '../../../src/auth/middleware'; import { disableOidcAuth, enableOidcAuth, initOidc } from '../../../src/auth/oidc'; import { OidcAuthenticator } from '../../../src/auth/oidcAuthenticator'; import { StandaloneAuthenticator } from '../../../src/auth/standaloneAuthenticator'; -import configuration, { type OIDCConfig } from '../../../src/config'; +import * as configModule from '../../../src/config'; +import configuration, { parseTrueFoundryModelRouting, type OIDCConfig } from '../../../src/config'; import type { IConfigurationStore } from '../../../src/db/configurationStore'; import type { IMemoryProviderStore } from '../../../src/db/memoryProviderStore'; import type { ISandboxEnvironmentStore, SandboxEnvironmentWithVersion } from '../../../src/db/sandboxEnvironmentStore'; @@ -44,6 +45,7 @@ const ALL_SETTINGS_OFF = { const NO_PROVIDER_REASON = 'Web search needs a provider, which is not configured.'; const TENANT_OFF_REASON = 'Web search is turned off for this tenant - an admin can turn it back on in settings.'; const MEMORY_TENANT_OFF_REASON = 'Memory is turned off for this tenant - an admin can turn it back on in settings.'; +const AUTO_TENANT_OFF_REASON = 'Auto mode is turned off for this tenant - an admin can turn it back on in settings.'; let mockActiveDefaultStatus: SandboxEnvironmentVersionStatus | undefined; let mockLatestDefaultStatus: SandboxEnvironmentVersionStatus | undefined; @@ -104,6 +106,7 @@ describe('capabilities routers', () => { webSearchStore, tenantWebSearchEnabled = true, tenantMemoryEnabled = true, + tenantAutoEnabled = true, hasMemoryProvider = true, userStore = new EmptyUserStore(), }: { @@ -111,6 +114,7 @@ describe('capabilities routers', () => { webSearchStore?: IWebSearchProviderStore; tenantWebSearchEnabled?: boolean; tenantMemoryEnabled?: boolean; + tenantAutoEnabled?: boolean; hasMemoryProvider?: boolean; userStore?: IUserStore; } = {}): OpenAPIHono { @@ -135,7 +139,11 @@ describe('capabilities routers', () => { }; const storedConfiguration = { tenant_id: 'default', - manifest: { web_search: { enabled: tenantWebSearchEnabled }, memory: { enabled: tenantMemoryEnabled } }, + manifest: { + web_search: { enabled: tenantWebSearchEnabled }, + memory: { enabled: tenantMemoryEnabled }, + auto: { enabled: tenantAutoEnabled }, + }, updated_at: '2026-01-01T00:00:00.000Z', }; const configurationStore: IConfigurationStore = { @@ -184,7 +192,6 @@ describe('capabilities routers', () => { settings: ALL_SETTINGS_ON, web_search: { enabled: false, reason: NO_PROVIDER_REASON }, memory: { enabled: true }, - auto: { enabled: false }, session_sharing: { granularity: 'tenant' }, }, }); @@ -263,6 +270,43 @@ describe('capabilities routers', () => { expect(body).not.toHaveProperty('data.memory'); }); + describe('auto', () => { + const routingForDefaultTenant = parseTrueFoundryModelRouting( + JSON.stringify({ tenants: { default: { enabled: 'on', decision_model: 'typesafe/jev-1.13.0' } } }), + ); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('omits auto when model routing is not set up for the tenant', async () => { + disableOidcAuth(); + const response = await makeRouter().request('/'); + expect(response.status).toBe(200); + expect(await response.json()).not.toHaveProperty('data.auto'); + }); + + it('reports auto disabled with a reason when the tenant turned it off', async () => { + disableOidcAuth(); + jest.spyOn(configModule, 'trueFoundryModelRouting').mockReturnValue(routingForDefaultTenant); + const response = await makeRouter({ tenantAutoEnabled: false }).request('/'); + expect(response.status).toBe(200); + expect(await response.json()).toMatchObject({ + data: { auto: { enabled: false, reason: AUTO_TENANT_OFF_REASON } }, + }); + }); + + it('reports auto unavailable when the tenant allows it but has no models to route to', async () => { + disableOidcAuth(); + jest.spyOn(configModule, 'trueFoundryModelRouting').mockReturnValue(routingForDefaultTenant); + const response = await makeRouter().request('/'); + expect(response.status).toBe(200); + expect(await response.json()).toMatchObject({ + data: { auto: { enabled: false, reason: 'Auto mode is not available for now' } }, + }); + }); + }); + it.each([ { granularity: 'tenant', userStore: new EmptyUserStore() }, { @@ -299,7 +343,6 @@ describe('capabilities routers', () => { settings: ALL_SETTINGS_ON, web_search: { enabled: false, reason: NO_PROVIDER_REASON }, memory: { enabled: true }, - auto: { enabled: false }, session_sharing: { granularity: 'tenant' }, }, }); @@ -319,7 +362,6 @@ describe('capabilities routers', () => { settings: ALL_SETTINGS_ON, web_search: { enabled: false, reason: NO_PROVIDER_REASON }, memory: { enabled: true }, - auto: { enabled: false }, session_sharing: { granularity: 'tenant' }, }, }); @@ -563,7 +605,6 @@ describe('capabilities routers', () => { settings: ALL_SETTINGS_ON, web_search: { enabled: false, reason: NO_PROVIDER_REASON }, memory: { enabled: true }, - auto: { enabled: false }, session_sharing: { granularity: 'tenant' }, }, }); @@ -585,7 +626,6 @@ describe('capabilities routers', () => { settings: ALL_SETTINGS_OFF, web_search: { enabled: false, reason: NO_PROVIDER_REASON }, memory: { enabled: true }, - auto: { enabled: false }, session_sharing: { granularity: 'tenant' }, }, }); diff --git a/packages/trueforge/tests/unit/apis/configuration.test.ts b/packages/trueforge/tests/unit/apis/configuration.test.ts index bd5a406977..91d8662909 100644 --- a/packages/trueforge/tests/unit/apis/configuration.test.ts +++ b/packages/trueforge/tests/unit/apis/configuration.test.ts @@ -32,11 +32,14 @@ describe('settings configuration router', () => { const response = await router.request('/'); expect(response.status).toBe(200); expect(await response.json()).toEqual({ - data: { manifest: { web_search: { enabled: true }, memory: { enabled: true } }, updated_at: expect.any(String) }, + data: { + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }, + updated_at: expect.any(String), + }, }); await expect(store.getConfiguration(STANDALONE_REQUEST_CONTEXT.tenant_id)).resolves.toEqual({ tenant_id: STANDALONE_REQUEST_CONTEXT.tenant_id, - manifest: { web_search: { enabled: true }, memory: { enabled: true } }, + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }, updated_at: expect.any(String), }); }); @@ -90,6 +93,17 @@ describe('settings configuration router', () => { }); }); + it('PATCH turns Auto mode off without touching the other switches', async () => { + const { router, store } = await createRouter(); + + const patched = await router.request('/', patchInit({ auto: { enabled: false } })); + expect(patched.status).toBe(200); + + await expect(store.getConfiguration(STANDALONE_REQUEST_CONTEXT.tenant_id)).resolves.toMatchObject({ + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: false } }, + }); + }); + it('PATCH leaves switches the body does not mention', async () => { const { router, store } = await createRouter(); @@ -112,7 +126,7 @@ describe('settings configuration router', () => { getOrCreateConfiguration: async input => { await store.upsertConfiguration({ tenant_id, - manifest: { web_search: { enabled: false }, memory: { enabled: false } }, + manifest: { web_search: { enabled: false }, memory: { enabled: false }, auto: { enabled: true } }, }); return await store.getOrCreateConfiguration(input); }, @@ -152,6 +166,7 @@ describe('settings configuration router', () => { expect(JSON.parse(stored.rows[0]?.raw ?? 'null')).toEqual({ web_search: { enabled: false }, memory: { enabled: true }, + auto: { enabled: true }, }); }); diff --git a/packages/trueforge/tests/unit/apis/deletedSessionCrud.test.ts b/packages/trueforge/tests/unit/apis/deletedSessionCrud.test.ts index a7895a192f..57328a3bd8 100644 --- a/packages/trueforge/tests/unit/apis/deletedSessionCrud.test.ts +++ b/packages/trueforge/tests/unit/apis/deletedSessionCrud.test.ts @@ -95,6 +95,7 @@ describe('public CRUD after session deletion', () => { skillStore, sandboxProviderStore, webSearchProviderStore, + configurationStore, memory: undefined, }), sandboxEnvironmentStore, diff --git a/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts b/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts index 6c49e240b1..2e3d07e9e7 100644 --- a/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts +++ b/packages/trueforge/tests/unit/apis/sandboxFileDownload.test.ts @@ -12,6 +12,7 @@ import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite'; import { SqliteAccessControlStore } from '../../../src/db/sqlite/access-control-store/SqliteAccessControlStore'; import { SqliteAgentStore } from '../../../src/db/sqlite/agent-store/SqliteAgentStore'; import { createSqliteDb } from '../../../src/db/sqlite/client'; +import { SqliteConfigurationStore } from '../../../src/db/sqlite/configuration-store/SqliteConfigurationStore'; import { SqliteMcpServerStore } from '../../../src/db/sqlite/mcp-server-store/SqliteMcpServerStore'; import { SqliteModelProviderStore } from '../../../src/db/sqlite/model-provider-store/SqliteModelProviderStore'; import { SqliteSandboxEnvironmentStore } from '../../../src/db/sqlite/sandbox-environment-store/SqliteSandboxEnvironmentStore'; @@ -62,6 +63,7 @@ async function buildApp() { skillStore: new SqliteSkillStore(db), sandboxProviderStore: new SqliteSandboxProviderStore(db), webSearchProviderStore: new SqliteWebSearchProviderStore(db), + configurationStore: new SqliteConfigurationStore(db), memory: undefined, }), sandboxEnvironmentStore: new SqliteSandboxEnvironmentStore(db), diff --git a/packages/trueforge/tests/unit/apis/schedules.test.ts b/packages/trueforge/tests/unit/apis/schedules.test.ts index 155ad29c96..072f69895c 100644 --- a/packages/trueforge/tests/unit/apis/schedules.test.ts +++ b/packages/trueforge/tests/unit/apis/schedules.test.ts @@ -74,6 +74,7 @@ function stubTurnExecutionDeps( sessions: new Sessions({ sessionStore }), sessionStore, webSearchProviderStore: {} as never, + configurationStore: {} as never, }; } diff --git a/packages/trueforge/tests/unit/apis/sessionGrants.test.ts b/packages/trueforge/tests/unit/apis/sessionGrants.test.ts index 1ac74c8315..56fe66e35e 100644 --- a/packages/trueforge/tests/unit/apis/sessionGrants.test.ts +++ b/packages/trueforge/tests/unit/apis/sessionGrants.test.ts @@ -123,6 +123,7 @@ function buildApp(input: { db: Kysely; sessionStore: SqliteSessionStor skillStore: new SqliteSkillStore(db), sandboxProviderStore: new SqliteSandboxProviderStore(db), webSearchProviderStore: new SqliteWebSearchProviderStore(db), + configurationStore: new SqliteConfigurationStore(db), memory: undefined, }), sandboxEnvironmentStore: new SqliteSandboxEnvironmentStore(db), diff --git a/packages/trueforge/tests/unit/apis/sessionHttp.test.ts b/packages/trueforge/tests/unit/apis/sessionHttp.test.ts index 940afc93c1..33adb7ccf2 100644 --- a/packages/trueforge/tests/unit/apis/sessionHttp.test.ts +++ b/packages/trueforge/tests/unit/apis/sessionHttp.test.ts @@ -177,6 +177,7 @@ describe('sessions HTTP agent binding', () => { skillStore, sandboxProviderStore, webSearchProviderStore, + configurationStore, memory: undefined, }), sandboxEnvironmentStore, @@ -981,7 +982,7 @@ describe('sessions HTTP agent binding', () => { await configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: false }, memory: { enabled: false } }, + manifest: { web_search: { enabled: false }, memory: { enabled: false }, auto: { enabled: true } }, }); try { // The agent was saved while web search was allowed, so its stored spec is grandfathered. @@ -999,7 +1000,7 @@ describe('sessions HTTP agent binding', () => { } finally { await configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: false } }, + manifest: { web_search: { enabled: true }, memory: { enabled: false }, auto: { enabled: true } }, }); } diff --git a/packages/trueforge/tests/unit/apis/turnHarnessErrorStatus.test.ts b/packages/trueforge/tests/unit/apis/turnHarnessErrorStatus.test.ts index c1e50d7d4e..43661d1345 100644 --- a/packages/trueforge/tests/unit/apis/turnHarnessErrorStatus.test.ts +++ b/packages/trueforge/tests/unit/apis/turnHarnessErrorStatus.test.ts @@ -13,6 +13,7 @@ import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite'; import { SqliteAccessControlStore } from '../../../src/db/sqlite/access-control-store/SqliteAccessControlStore'; import { SqliteAgentStore } from '../../../src/db/sqlite/agent-store/SqliteAgentStore'; import { createSqliteDb } from '../../../src/db/sqlite/client'; +import { SqliteConfigurationStore } from '../../../src/db/sqlite/configuration-store/SqliteConfigurationStore'; import { SqliteMcpServerStore } from '../../../src/db/sqlite/mcp-server-store/SqliteMcpServerStore'; import { SqliteModelProviderStore } from '../../../src/db/sqlite/model-provider-store/SqliteModelProviderStore'; import { SqliteSandboxEnvironmentStore } from '../../../src/db/sqlite/sandbox-environment-store/SqliteSandboxEnvironmentStore'; @@ -91,6 +92,7 @@ async function postTurnRejectingWith(error: AgentHarnessError): Promise) { skillStore: new SqliteSkillStore(db), sandboxProviderStore: new SqliteSandboxProviderStore(db), webSearchProviderStore: new SqliteWebSearchProviderStore(db), + configurationStore: new SqliteConfigurationStore(db), memory: undefined, }; } diff --git a/packages/trueforge/tests/unit/apis/turns.test.ts b/packages/trueforge/tests/unit/apis/turns.test.ts index 1e62331513..571d1abf46 100644 --- a/packages/trueforge/tests/unit/apis/turns.test.ts +++ b/packages/trueforge/tests/unit/apis/turns.test.ts @@ -35,6 +35,7 @@ import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite'; import { SqliteAccessControlStore } from '../../../src/db/sqlite/access-control-store/SqliteAccessControlStore'; import { SqliteAgentStore } from '../../../src/db/sqlite/agent-store/SqliteAgentStore'; import { createSqliteDb } from '../../../src/db/sqlite/client'; +import { SqliteConfigurationStore } from '../../../src/db/sqlite/configuration-store/SqliteConfigurationStore'; import { SqliteMcpServerStore } from '../../../src/db/sqlite/mcp-server-store/SqliteMcpServerStore'; import { SqliteModelProviderStore } from '../../../src/db/sqlite/model-provider-store/SqliteModelProviderStore'; import { SqliteSandboxEnvironmentStore } from '../../../src/db/sqlite/sandbox-environment-store/SqliteSandboxEnvironmentStore'; @@ -65,6 +66,7 @@ function turnExecutionStores(db: Kysely, tokenStore: SqliteOAuthTokenS skillStore: new SqliteSkillStore(db), sandboxProviderStore: new SqliteSandboxProviderStore(db), webSearchProviderStore: new SqliteWebSearchProviderStore(db), + configurationStore: new SqliteConfigurationStore(db), memory: undefined, }; } diff --git a/packages/trueforge/tests/unit/memory/providers.test.ts b/packages/trueforge/tests/unit/memory/providers.test.ts index d476bdf568..4e75fcb392 100644 --- a/packages/trueforge/tests/unit/memory/providers.test.ts +++ b/packages/trueforge/tests/unit/memory/providers.test.ts @@ -27,7 +27,7 @@ async function setup() { const setSwitch = (tenant_id: string, enabled: boolean) => configurationStore.upsertConfiguration({ tenant_id, - manifest: { web_search: { enabled: true }, memory: { enabled } }, + manifest: { web_search: { enabled: true }, memory: { enabled }, auto: { enabled: true } }, }); return { deps, memoryProviderStore, setSwitch }; } diff --git a/packages/trueforge/tests/unit/memory/sessionMemory.test.ts b/packages/trueforge/tests/unit/memory/sessionMemory.test.ts index a532397862..7c72135853 100644 --- a/packages/trueforge/tests/unit/memory/sessionMemory.test.ts +++ b/packages/trueforge/tests/unit/memory/sessionMemory.test.ts @@ -85,7 +85,7 @@ function tenantMemory({ }; const storedConfiguration = (tenantId: string) => ({ tenant_id: tenantId, - manifest: { web_search: { enabled: true }, memory: { enabled: tenantEnabled } }, + manifest: { web_search: { enabled: true }, memory: { enabled: tenantEnabled }, auto: { enabled: true } }, updated_at: '2026-10-01T00:00:00.000Z', }); const configurationStore: IConfigurationStore = { diff --git a/packages/trueforge/tests/unit/runtime/sessionResources.test.ts b/packages/trueforge/tests/unit/runtime/sessionResources.test.ts index 530bb5a2b8..10a9404444 100644 --- a/packages/trueforge/tests/unit/runtime/sessionResources.test.ts +++ b/packages/trueforge/tests/unit/runtime/sessionResources.test.ts @@ -211,6 +211,32 @@ describe('validateAgentSpec', () => { } satisfies Partial); }); + it('rejects auto when the tenant turned Auto mode off, even with model routing on', async () => { + const stores = await setup(); + await stores.configurationStore.upsertConfiguration({ + tenant_id: 'default', + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: false } }, + }); + const modelRouting = parseTrueFoundryModelRouting( + JSON.stringify({ tenants: { default: { enabled: 'on', decision_model: 'typesafe/jev-1.13.0' } } }), + ); + await expect( + validateAgentSpec({ + spec: AgentSpecSchema.parse({ + model: { name: 'auto' }, + instructions: 'test', + }), + tenant_id: 'default', + created_by_subject_id: 'test-subject', + ...stores, + modelRouting, + }), + ).rejects.toMatchObject({ + status: 422, + message: 'Auto mode is turned off for this tenant', + } satisfies Partial); + }); + it('rejects malformed model FQN with 422', async () => { const stores = await setup(); await expect( @@ -381,7 +407,7 @@ describe('validateAgentSpec', () => { jest.mocked(hasConfiguredWebSearchProvider).mockResolvedValue(true); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: false }, memory: { enabled: true } }, + manifest: { web_search: { enabled: false }, memory: { enabled: true }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -405,7 +431,7 @@ describe('validateAgentSpec', () => { jest.mocked(hasConfiguredWebSearchProvider).mockResolvedValue(true); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: false }, memory: { enabled: true } }, + manifest: { web_search: { enabled: false }, memory: { enabled: true }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -451,7 +477,7 @@ describe('validateAgentSpec', () => { const stores = await setup(); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: false }, memory: { enabled: true } }, + manifest: { web_search: { enabled: false }, memory: { enabled: true }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -476,7 +502,7 @@ describe('validateAgentSpec', () => { const stores = await setup(); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: false } }, + manifest: { web_search: { enabled: true }, memory: { enabled: false }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -499,7 +525,7 @@ describe('validateAgentSpec', () => { const stores = await setup(); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: false } }, + manifest: { web_search: { enabled: true }, memory: { enabled: false }, auto: { enabled: true } }, }); const memorySpec = AgentSpecSchema.parse({ model: { name: 'test-provider/test-model' }, @@ -525,7 +551,7 @@ describe('validateAgentSpec', () => { }); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: false } }, + manifest: { web_search: { enabled: true }, memory: { enabled: false }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -553,7 +579,7 @@ describe('validateAgentSpec', () => { const stores = await setup(); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: true } }, + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }, }); await expect( validateAgentSpec({ @@ -596,7 +622,7 @@ describe('validateAgentSpec', () => { const stores = await setup(); await stores.configurationStore.upsertConfiguration({ tenant_id: 'default', - manifest: { web_search: { enabled: true }, memory: { enabled: true } }, + manifest: { web_search: { enabled: true }, memory: { enabled: true }, auto: { enabled: true } }, }); await stores.memoryProviderStore.upsertProvider({ tenant_id: 'default', diff --git a/python/trueforge_sdk/src/trueforge_sdk/__init__.py b/python/trueforge_sdk/src/trueforge_sdk/__init__.py index ebfb432715..225bac3209 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/__init__.py +++ b/python/trueforge_sdk/src/trueforge_sdk/__init__.py @@ -22,6 +22,7 @@ ApprovalDeny, AskUserQuestionsConfig, AutoCapability, + AutoConfiguration, AvailableMcpServer, AvailableModel, AvailableModelProvider, @@ -357,6 +358,7 @@ "AskUserQuestionsConfig": ".types", "AsyncTrueForge": ".client", "AutoCapability": ".types", + "AutoConfiguration": ".types", "AvailableMcpServer": ".types", "AvailableModel": ".types", "AvailableModelProvider": ".types", @@ -713,6 +715,7 @@ def __dir__(): "AskUserQuestionsConfig", "AsyncTrueForge", "AutoCapability", + "AutoConfiguration", "AvailableMcpServer", "AvailableModel", "AvailableModelProvider", diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/__init__.py b/python/trueforge_sdk/src/trueforge_sdk/types/__init__.py index 4733c782cf..70fe565196 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/types/__init__.py +++ b/python/trueforge_sdk/src/trueforge_sdk/types/__init__.py @@ -21,6 +21,7 @@ from .approval_deny import ApprovalDeny from .ask_user_questions_config import AskUserQuestionsConfig from .auto_capability import AutoCapability + from .auto_configuration import AutoConfiguration from .available_mcp_server import AvailableMcpServer from .available_model import AvailableModel from .available_model_provider import AvailableModelProvider @@ -321,6 +322,7 @@ "ApprovalDeny": ".approval_deny", "AskUserQuestionsConfig": ".ask_user_questions_config", "AutoCapability": ".auto_capability", + "AutoConfiguration": ".auto_configuration", "AvailableMcpServer": ".available_mcp_server", "AvailableModel": ".available_model", "AvailableModelProvider": ".available_model_provider", @@ -645,6 +647,7 @@ def __dir__(): "ApprovalDeny", "AskUserQuestionsConfig", "AutoCapability", + "AutoConfiguration", "AvailableMcpServer", "AvailableModel", "AvailableModelProvider", diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/auto_capability.py b/python/trueforge_sdk/src/trueforge_sdk/types/auto_capability.py index c2bf54ef52..d1f905df5b 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/types/auto_capability.py +++ b/python/trueforge_sdk/src/trueforge_sdk/types/auto_capability.py @@ -8,9 +8,18 @@ class AutoCapability(UncheckedBaseModel): + """ + Present only when model routing is set up for the tenant; absent means Auto mode settings are hidden. + """ + enabled: bool = pydantic.Field() """ - Whether Auto mode can be selected: the user has at least one model in every routing cluster. + Whether Auto mode can be selected: the tenant allows it and the user has the models it picks from. + """ + + reason: typing.Optional[str] = pydantic.Field(default=None) + """ + Present when Auto mode is unavailable. Explains why. """ if IS_PYDANTIC_V2: diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/auto_configuration.py b/python/trueforge_sdk/src/trueforge_sdk/types/auto_configuration.py new file mode 100644 index 0000000000..61f4d9c915 --- /dev/null +++ b/python/trueforge_sdk/src/trueforge_sdk/types/auto_configuration.py @@ -0,0 +1,22 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +import pydantic +from ..core.pydantic_utilities import IS_PYDANTIC_V2 +from ..core.unchecked_base_model import UncheckedBaseModel + + +class AutoConfiguration(UncheckedBaseModel): + enabled: bool = pydantic.Field() + """ + Whether this tenant may use Auto mode, which picks a model for each turn and each subagent. + """ + + if IS_PYDANTIC_V2: + model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow") # type: ignore # Pydantic v2 + else: + + class Config: + smart_union = True + extra = pydantic.Extra.allow diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/capabilities_data.py b/python/trueforge_sdk/src/trueforge_sdk/types/capabilities_data.py index 4ced6d0f1c..87d1fb1c4a 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/types/capabilities_data.py +++ b/python/trueforge_sdk/src/trueforge_sdk/types/capabilities_data.py @@ -15,7 +15,7 @@ class CapabilitiesData(UncheckedBaseModel): - auto: AutoCapability + auto: typing.Optional[AutoCapability] = None memory: typing.Optional[MemoryCapability] = None sandbox: SandboxCapability session_sharing: SessionSharingCapability diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest.py b/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest.py index 39c1907626..be235c9a6a 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest.py +++ b/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest.py @@ -5,11 +5,13 @@ import pydantic from ..core.pydantic_utilities import IS_PYDANTIC_V2 from ..core.unchecked_base_model import UncheckedBaseModel +from .auto_configuration import AutoConfiguration from .memory_configuration import MemoryConfiguration from .web_search_configuration import WebSearchConfiguration class ConfigurationManifest(UncheckedBaseModel): + auto: AutoConfiguration memory: MemoryConfiguration web_search: WebSearchConfiguration diff --git a/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest_patch.py b/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest_patch.py index bd082d6ad2..3be068886b 100644 --- a/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest_patch.py +++ b/python/trueforge_sdk/src/trueforge_sdk/types/configuration_manifest_patch.py @@ -5,11 +5,13 @@ import pydantic from ..core.pydantic_utilities import IS_PYDANTIC_V2 from ..core.unchecked_base_model import UncheckedBaseModel +from .auto_configuration import AutoConfiguration from .memory_configuration import MemoryConfiguration from .web_search_configuration import WebSearchConfiguration class ConfigurationManifestPatch(UncheckedBaseModel): + auto: typing.Optional[AutoConfiguration] = None memory: typing.Optional[MemoryConfiguration] = None web_search: typing.Optional[WebSearchConfiguration] = None