diff --git a/.env.example b/.env.example index 96dc9955d5..8b257e5b6f 100644 --- a/.env.example +++ b/.env.example @@ -220,6 +220,11 @@ SILO_DATA_ROOT=/opt/silo # SILO_TMDB_API_KEY= # SILO_MDBLIST_API_KEY= # SILO_MEILISEARCH_INDEX=silo_media_items +# Recommendations. SILO_RECOMMENDATIONS_PROVIDER names a connected AI provider +# that serves embeddings, by id, such as one the deployment document declares. +# SILO_RECOMMENDATIONS_ENABLED=true +# SILO_RECOMMENDATIONS_PROVIDER= +# SILO_RECOMMENDATIONS_MODEL= # Storage: SILO_ARTWORK_STORAGE (auto, local or s3), SILO_ARTWORK_PATH, and # SILO_S3_PUBLIC_* and SILO_S3_PRIVATE_* with ENDPOINT, REGION, BUCKET, # KEY_PREFIX, PATH_STYLE, ACCESS_KEY and SECRET_KEY, plus @@ -234,6 +239,13 @@ SILO_DATA_ROOT=/opt/silo # SILO_SCANNER_WORKERS= # SILO_MATCHER_WORKERS= +# Deployment document: JSON inline in SILO_CONFIG, or a JSON or YAML file named +# by SILO_CONFIG_FILE. It installs and configures official plugins (plugins:) +# and connects AI providers (ai_providers:), each keyed by its id, with secrets +# given as {fromFile: } or {fromEnv: }. SILO_PLUGINS and +# SILO_PLUGINS_FILE name the same document; set only one of the four. +# SILO_CONFIG_FILE=/config/deployment.yaml + # Run from source / advanced overrides # DATABASE_URL and SECRET_KEY are required when running Silo outside the default # Docker Compose file. REDIS_URL is optional for integrated/API mode and diff --git a/cmd/silo/env_settings.go b/cmd/silo/env_settings.go index 55f75b7c8e..6155484721 100644 --- a/cmd/silo/env_settings.go +++ b/cmd/silo/env_settings.go @@ -23,30 +23,58 @@ func bootstrapPoolSize(env config.EnvSettings) int { return 20 } +// deploymentAIProviders are the AI providers the deployment document +// declares. Without an ai_providers section (declared false) the stored +// registry is left as it is; an empty section releases every provider. +type deploymentAIProviders struct { + declared bool + providers []config.AIProvider + variable string +} + // applyEnvSettings checks the settings the environment sets the way an admin // save checks them, stores the cluster-wide ones that differ from stored in // one batch (through the encrypting repo, so secrets rest encrypted), and // overlays every one on settings, the map startup builds its config from. It // returns the checked values and the stored keys it changed. // +// The AI providers the deployment document declares go into the registry in +// the same batch, checked with the environment's values, so a +// recommendations variable can name one of them and the recommendation +// engine starts with them on this start. +// // The check and the write share one settings transaction, as an admin save's // do, so the check sees the rows the write replaces: a storage transition // another server commits while this one starts cannot slip between them. -func applyEnvSettings(ctx context.Context, repo *catalog.EncryptedSettingsRepo, settings map[string]string, env config.EnvSettings, redisBootstrapURL string) (config.EnvSettings, []string, error) { - if len(env) == 0 { +func applyEnvSettings(ctx context.Context, repo *catalog.EncryptedSettingsRepo, settings map[string]string, env config.EnvSettings, ai deploymentAIProviders, redisBootstrapURL string) (config.EnvSettings, []string, error) { + if len(env) == 0 && !ai.declared { return env, nil, nil } normalizedRedis, redisErr := config.NormalizeRedisURL(redisBootstrapURL) redisBootstrapAvailable := normalizedRedis != "" && redisErr == nil var checked config.EnvSettings - var changed, snapshot map[string]string + var changed, snapshot, declared map[string]string var checkErr error err := repo.UpdateAtomic(ctx, func(current map[string]string) (map[string]string, error) { - if checked, checkErr = handlers.CheckEnvironmentSettings(current, env, redisBootstrapAvailable); checkErr != nil { + declared = nil + if ai.declared { + registry, err := config.ApplyDeclaredAIProviders(current[config.AIProvidersSettingKey], ai.providers, ai.variable) + if err != nil { + checkErr = fmt.Errorf("%s: ai_providers: %w", ai.variable, err) + return nil, checkErr + } + declared = map[string]string{config.AIProvidersSettingKey: registry} + } + if checked, checkErr = handlers.CheckDeploymentSettings(current, env, declared, ai.variable, redisBootstrapAvailable); checkErr != nil { return nil, checkErr } snapshot = maps.Clone(current) changed = map[string]string{} + for key, value := range declared { + if current[key] != value { + changed[key] = value + } + } for key, value := range checked.Values(config.EnvScopeStored) { if current[key] != value { changed[key] = value @@ -65,6 +93,7 @@ func applyEnvSettings(ctx context.Context, repo *catalog.EncryptedSettingsRepo, // the earlier read, which another server may have changed since. clear(settings) maps.Copy(settings, snapshot) + maps.Copy(settings, declared) maps.Copy(settings, checked.All()) return checked, slices.Sorted(maps.Keys(changed)), nil } diff --git a/cmd/silo/main.go b/cmd/silo/main.go index 327b0e0558..628692986e 100644 --- a/cmd/silo/main.go +++ b/cmd/silo/main.go @@ -937,11 +937,24 @@ func main() { // SILO_DB_MAX_CONNECTIONS sizes it. isPrimaryNode := bc.Mode == "integrated" || bc.Mode == "api" || bc.Mode == "" var envSettings config.EnvSettings + // The deployment document (SILO_CONFIG or SILO_CONFIG_FILE) is read with + // them: its AI providers are stored with the environment's settings, and + // its plugins section goes to the provisioning writer once plugins load. + var deploymentDocument *plugins.ProvisionDocument + var declaredAIProviders deploymentAIProviders if isPrimaryNode && !*migrateOnly && !*migrateStatus && *migrateDownTo < 0 { envSettings, err = config.ReadEnvSettings(os.Getenv) if err != nil { log.Fatalf("%v", err) } + if deploymentDocument, err = plugins.ReadProvisionDocument(); err != nil { + log.Fatalf("read deployment configuration: %v", err) + } + providers, declared, err := deploymentDocument.DeclaredAIProviders() + if err != nil { + log.Fatalf("%s: %v", deploymentDocument.Variable(), err) + } + declaredAIProviders = deploymentAIProviders{declared: declared, providers: providers, variable: deploymentDocument.Variable()} } // Step 2: Connect to PostgreSQL (bootstrap pool sized by @@ -1067,7 +1080,7 @@ func main() { // The settings the environment sets win over the stored ones. Cluster-wide // ones are stored so the admin UI and the other servers see the values in // effect; per-process ones only overlay this process's settings. - envSettings, envChangedKeys, err := applyEnvSettings(ctx, settingsRepo, settings, envSettings, bc.RedisURL) + envSettings, envChangedKeys, err := applyEnvSettings(ctx, settingsRepo, settings, envSettings, declaredAIProviders, bc.RedisURL) if err != nil { log.Fatalf("%v", err) } @@ -2077,12 +2090,17 @@ func main() { installer, plugins.NewHostAdapter(pluginHost), ) - provisionDocument, err := plugins.ReadProvisionDocument() - if err != nil { - log.Fatalf("read plugin provisioning: %v", err) + // A frontend server provisions plugins but stores no settings from + // its environment, so it reads the document here. + if bc.Mode == "frontend" { + if deploymentDocument, err = plugins.ReadProvisionDocument(); err != nil { + log.Fatalf("read deployment configuration: %v", err) + } } - if provisionDocument != nil { - pluginProvisionWriter = plugins.NewProvisionWriter(deps.DB, repositoryStore, installationStore, installer, catalogService, runtimeConfigStore, pluginService, provisionDocument, + // A deployment document without a plugins section leaves plugin + // installations as they are, as no document does. + if deploymentDocument.DeclaresPlugins() { + pluginProvisionWriter = plugins.NewProvisionWriter(deps.DB, repositoryStore, installationStore, installer, catalogService, runtimeConfigStore, pluginService, deploymentDocument, metadata.ApplyProvisionedMetadataPlacement) runtimeConfigStore.SetProvisionWriter(pluginProvisionWriter) deps.PluginProvisionStatus = runtimeConfigStore.ListProvisionStatus diff --git a/contracts/api/v2/breaking-approvals.json b/contracts/api/v2/breaking-approvals.json index 8f8bdc1b10..08ac789b35 100644 --- a/contracts/api/v2/breaking-approvals.json +++ b/contracts/api/v2/breaking-approvals.json @@ -1,312 +1,3 @@ { - "approvals": [ - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "04893a4903cb32e93db8f53ca78507369c0090fb9434bdc27a8de73cfea46408", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "0640ac17953947c7cf8a021233021ba0b63257a6cd60777345d58c9a1cd73d31", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "0eb201b6c8fcb978e3f8d4043b3b025cd7a8194b32bb60a8675793658f16ba16", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "22b23b95e8386bc904c1d1496fe19b734f4db8a203ebc12322610e9efd8f04a3", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "2cc1b21bf7e5c5dfe5cdacddb6b05f728933d388e79ffeff8db9b1350c98e159", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "3cd452ed2c4b4f39c90014dec94498fbc26c5f3a92e4c9fb5e733ec21b1e975b", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "3cf289e9b77f4f30c39e0299dd56c922b95c1bf1b2913b8c1610da3d8499e518", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "45ad808ef852a80758bcf2a52a9eb803fa051661420fc4e1ca7fac348e8fb330", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "4d113f878b6a5a984970ffebaf3b5d44b9f3300f693f69f7d9dcb81846e06029", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "515c17343fb176bbc3f4bd8f83d7ff70f5082a4a67cfcdb3415a8a1f9859e561", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "5354d4218f29088dd60995f67b9305688ddeb2512237d315a86d40d4684efadc", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "535b1583e64cfa3862282a6d23f9a0155c13a1e19ec8dd8f14104873a0cb4506", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "64a111ac5c1b10aac3a66adc7f277669dff290006c160eaa99052e6955b4fa03", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "77f687943992cff51cd0a6665638f2f0761c93dabd8e2752ab511aa8c93f1d21", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "889177b078585e6930d8951b34e32af184ded7bafb0d87ef32ed104e0a32043c", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "93980f5715d6eed73c4695c363366ec95fe8c8f7090249c2931227a1bb538d2f", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "cb4f56ec73e069dfc5181951062ee8a49fb8da6338e82c946c83a0ff67bb5f4e", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "d11ad09ae2c119cae710d08a6152f2fb27e40c0b80430549b81ef319d0f1757b", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "d888874218dedb368705e1a83058b91ce3474cd9388e52130880ab756d054639", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "e392d86727872f9be9f15a4776330812e20fb402976281f4260c4ca6b5956962", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "f49144772bca3e7fe25089eb1f761fa834b02505ddc21d20a005c5531fff891a", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupUploadRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "f59900fbdec9eeaaa36055ad096a3144ab894db1146fed7b526fd780a02c4d04", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "0a908a853b27b557bac7cbed9e18eaa79607a633595d5c600869f405bd6619a7", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "1f081a9e8ae554fc3796b0f2dd276e7a76a73d731231203ee0d6eab47d79c127", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "3cfda317beaa61e3f6418a91f979b0dbebf5bae9382e037bcc5237cfe4c92989", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "4322f7e2eda949af6b584fb0c358107399b70304fec80cdce3890ce599df68b8", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "525ae100c57b281a3dd784c81ec704a1dc2f5520002c2a6dd5934cb29ee16c36", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "5e88e6c8140ce76c15caf4094e7bb91ff49a3878d1b798d3399bc4df385a8b8e", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "6126053e1117a34083030f41639e7a00753ebc87e703e8262af0f8e3b0c2fb92", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "6629c381edc0a2f6a34e693406c66e1338d454b2f3c8a82c49c1d15ceca0bcb1", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "6d35dc88858e9f71d49d1a2557b4fe244fd6f9332df5fa3e9b91ff1f386002a2", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "783b2ceb5c17f99a37f70ca56557023e51739243c2b3e857696684353cfa954d", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "8c63110ffb50638e230b407aac33a7a10c79ccbca15197b8849fabd3db0d14f3", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "920575d9028120baa304d17d2add72169d4fdf996870191102329a02e9769137", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "9278baf88e918940f1c80813e8cf7d839a42a87b31bbc6ce2f3e1e3a78bfce8f", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "94305e1ea3a2d496e14a9362fb3966be3dfda853faaf3bca0a8fee5a04cc19a3", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "9ca15be7fbe8673ff3f5cdc995d630b5e163b812de8f4c2a484b8ae8af9beb6b", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "b27759a5ad5115ab9b622f04505742c3c45147c664f05bacc83eefe736f8fdfd", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "b29239a0b91f2bd6991cfe24f2f2ed935599b74f9c80ddb3af40beb678e961f6", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "b3e08e56303617dff5992aada1f4b5a6bad2d284c90b8400c7b6d6f905c8ca72", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "b56fe69d4dcba185b3750f685e285ddc7f8ce9d2d4ea6c67e76b384a0572ef1f", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "c886ab23e8efc3cfc55778608b078f5e2063b7235be8c08cd3007667b82e9f82", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "e65ecdcc42e9dc7a7f606f14a333d0760110fc886d1ef4263c004ebc16e1c8a7", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - }, - { - "operation_id": "getAdminBackupRestoreSet", - "change_id": "response-property-enum-value-added", - "fingerprint": "fa82f174ee7896d7a5265070a2eac33017f5d55948111619c422f97ed4387f95", - "reason": "Selective restore change lists become declared codes that the web shows in the interface language, instead of English display words. Only the web restore flow reads them (silo-apple, silo-android and silo-roku have no backup restore screens); it is updated in the same change.", - "approved_in": "#4757" - } - ] + "approvals": [] } diff --git a/contracts/api/v2/openapi.json b/contracts/api/v2/openapi.json index 3e080daaa1..be029364e6 100644 --- a/contracts/api/v2/openapi.json +++ b/contracts/api/v2/openapi.json @@ -594,6 +594,10 @@ "id": { "type": "string" }, + "managed_by_env_var": { + "description": "The variable in the server's environment that declares this provider, such as SILO_CONFIG_FILE, when the deployment declares it. Updating or deleting such a provider is 422 validation_failed with code managed_by_environment.", + "type": "string" + }, "name": { "type": "string" }, @@ -65464,7 +65468,7 @@ "bearerAuth": [] } ], - "summary": "Disconnect a provider and discard its key. A provider a job uses cannot be deleted.", + "summary": "Disconnect a provider and discard its key. A provider a job uses cannot be deleted, and one the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment.", "tags": [ "admin-ai" ], @@ -65656,7 +65660,7 @@ "bearerAuth": [] } ], - "summary": "Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request.", + "summary": "Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request. A provider the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment.", "tags": [ "admin-ai" ], diff --git a/contracts/plugins/provisioning/v1/embed.go b/contracts/plugins/provisioning/v1/embed.go index d2e8cef40d..a44d4ebe64 100644 --- a/contracts/plugins/provisioning/v1/embed.go +++ b/contracts/plugins/provisioning/v1/embed.go @@ -3,7 +3,9 @@ package provisioningv1 import _ "embed" -// Schema describes the document consumed through SILO_PLUGINS and SILO_PLUGINS_FILE. +// Schema describes the deployment document consumed through SILO_CONFIG or +// SILO_CONFIG_FILE, and through SILO_PLUGINS or SILO_PLUGINS_FILE, the names it +// had when it declared plugins alone. // //go:embed schema.json var Schema []byte diff --git a/contracts/plugins/provisioning/v1/schema.json b/contracts/plugins/provisioning/v1/schema.json index bafbc44658..34f61596a8 100644 --- a/contracts/plugins/provisioning/v1/schema.json +++ b/contracts/plugins/provisioning/v1/schema.json @@ -1,9 +1,9 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://raw.githubusercontent.com/Silo-Server/silo-server/main/contracts/plugins/provisioning/v1/schema.json", - "title": "Silo plugin provisioning", + "title": "Silo deployment configuration", "type": "object", - "required": ["apiVersion", "plugins"], + "required": ["apiVersion"], "additionalProperties": false, "properties": { "apiVersion": { "type": "integer", "const": 1 }, @@ -11,6 +11,11 @@ "type": "object", "propertyNames": { "pattern": "^[a-z0-9]+([._-][a-z0-9]+)*$" }, "additionalProperties": { "$ref": "#/$defs/plugin" } + }, + "ai_providers": { + "type": "object", + "propertyNames": { "pattern": "^[a-z0-9][a-z0-9-]{0,63}$" }, + "additionalProperties": { "$ref": "#/$defs/aiProvider" } } }, "$defs": { @@ -48,6 +53,35 @@ } } }, + "aiProvider": { + "type": "object", + "additionalProperties": false, + "required": ["type"], + "properties": { + "type": { "enum": ["openai", "gemini", "openrouter", "groq", "ollama", "whisper", "custom"] }, + "name": { "type": "string", "minLength": 1, "maxLength": 80 }, + "base_url": { "type": "string", "minLength": 1 }, + "capabilities": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { "enum": ["chat", "embeddings", "speech"] } + }, + "api_key": { "$ref": "#/$defs/secretReference" } + } + }, + "secretReference": { + "anyOf": [ + { + "type": "object", "required": ["fromFile"], "additionalProperties": false, + "properties": { "fromFile": { "type": "string", "minLength": 1 } } + }, + { + "type": "object", "required": ["fromEnv"], "additionalProperties": false, + "properties": { "fromEnv": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*$" } } + } + ] + }, "value": { "anyOf": [ { "type": ["string", "number", "boolean"] }, diff --git a/docs/admin-settings-api.md b/docs/admin-settings-api.md index ca2ff1a84d..761048ed93 100644 --- a/docs/admin-settings-api.md +++ b/docs/admin-settings-api.md @@ -125,6 +125,23 @@ clients never handled a query; that job stays unconfigured and startup logs a warning naming the legacy setting. HTTP Basic authentication through the URL is not supported; such a proxy needs to accept the provider's API key. +The deployment can also declare providers, in the `ai_providers` section of +its deployment document (`SILO_CONFIG` or `SILO_CONFIG_FILE`, or the older +names `SILO_PLUGINS` and `SILO_PLUGINS_FILE`). Each API server +that reads the document stores them when it starts, in the same transaction as +the settings its environment sets, so the last server to start wins, as for +those settings: give every API server that reads the document the same one. A +declared provider carries `managed_by_env_var`, the document's variable, and +the update and delete operations below refuse it with `422` and code +`managed_by_environment`. A provider stays declared until an API server starts +with a document whose `ai_providers` section leaves it out, and +`ai_providers: {}` releases them all; a server that starts without the +document, or with one that has no `ai_providers` section, changes nothing, so +removing the variable leaves the providers locked. At startup the provider +bindings are checked only where the start can change them: those the +environment sets and those naming a provider the document declares. The user +manual covers writing the document. + The following operations require an acting administrator: - `GET /api/v2/admin/ai/providers` lists providers without keys (`has_api_key` diff --git a/internal/api/handlers/admin.go b/internal/api/handlers/admin.go index 844a22385d..ac2ddcd1aa 100644 --- a/internal/api/handlers/admin.go +++ b/internal/api/handlers/admin.go @@ -1340,8 +1340,9 @@ var adminSettingDependencyGroups = [][]string{ {"matcher.enable_tv_series_root_queue", "matcher.enable_tv_series_group_queue"}, {"ai.max_concurrent_jobs", "subtitle_ai.max_concurrent_jobs"}, {"ai.chat_model", "subtitle_ai.chat_model", "ai.reasoning_effort"}, //nolint:goconst // Keep the complete setting dependency explicit. - // A provider binding is checked against the registry it names. - append([]string{config.AIProvidersSettingKey}, config.AIProviderBindingKeys()...), + // A provider binding is checked against the registry it names, and the + // text binding against the auth mode that can leave it idle. + append([]string{config.AIProvidersSettingKey, config.AIAuthModeSettingKey}, config.AIProviderBindingKeys()...), { diagnostics.KeyMaxBundleBytes, diagnostics.KeyMaxUncompressedBytes, diff --git a/internal/api/handlers/admin_ai_providers.go b/internal/api/handlers/admin_ai_providers.go index efc9ec6c36..0d960175c4 100644 --- a/internal/api/handlers/admin_ai_providers.go +++ b/internal/api/handlers/admin_ai_providers.go @@ -22,6 +22,10 @@ var ( ErrAIProviderInvalid = errors.New("invalid AI provider") // ErrAIProviderConflict wraps a message naming the jobs that block the change. ErrAIProviderConflict = errors.New("AI provider is in use") + // ErrAIProviderManaged refuses a change to a provider the deployment + // declares (config.AIProvider.ManagedBy); it wraps a message naming the + // variable to change instead. + ErrAIProviderManaged = errors.New("AI provider is set by the deployment") ) // AdminAIProviderView is one connected provider without its key. @@ -33,6 +37,9 @@ type AdminAIProviderView struct { HasAPIKey bool Capabilities []string UsedBy []string + // ManagedByEnvVar names the deployment variable that declares the + // provider, such as SILO_CONFIG_FILE; empty when an admin connected it. + ManagedByEnvVar string } // AdminAIProviderInput carries the editable fields. On update a nil field is @@ -130,6 +137,9 @@ func (h *AdminHandler) UpdateAIProvider(ctx context.Context, id string, in Admin return ErrAIProviderNotFound } provider := registry.Providers[i] + if err := refuseManagedAIProvider(provider); err != nil { + return err + } if in.Type != "" && in.Type != string(provider.Type) { return aiProviderInvalid(errors.New("a provider's type cannot change; connect a new provider instead")) } @@ -164,6 +174,9 @@ func (h *AdminHandler) DeleteAIProvider(ctx context.Context, id string) error { if i < 0 { return ErrAIProviderNotFound } + if err := refuseManagedAIProvider(registry.Providers[i]); err != nil { + return err + } if users := config.AIProviderUsers(effective, id); len(users) > 0 { return fmt.Errorf("%w: %s is used by the %s; choose another provider there first", ErrAIProviderConflict, registry.Providers[i].Name, aiJobLabels(users)) } @@ -379,14 +392,24 @@ func aiProviderView(provider config.AIProvider, effective map[string]string) Adm usedBy[i] = string(job) } return AdminAIProviderView{ - ID: provider.ID, - Type: string(provider.Type), - Name: provider.Name, - BaseURL: provider.BaseURL, - HasAPIKey: provider.APIKey != "", - Capabilities: capabilities, - UsedBy: usedBy, + ID: provider.ID, + Type: string(provider.Type), + Name: provider.Name, + BaseURL: provider.BaseURL, + HasAPIKey: provider.APIKey != "", + Capabilities: capabilities, + UsedBy: usedBy, + ManagedByEnvVar: provider.ManagedBy, + } +} + +// refuseManagedAIProvider refuses to change a provider the deployment +// declares: the next start would put the declaration back. +func refuseManagedAIProvider(provider config.AIProvider) error { + if provider.ManagedBy == "" { + return nil } + return fmt.Errorf("%w: %s is declared by the deployment document in %s; change it there and restart, or leave it out of the document's ai_providers section (ai_providers: {} releases them all) to release it", ErrAIProviderManaged, provider.Name, provider.ManagedBy) } func aiProviderIndex(registry *config.AIProviderRegistry, id string) int { diff --git a/internal/api/handlers/admin_settings_env.go b/internal/api/handlers/admin_settings_env.go index f72598339b..7dd5699976 100644 --- a/internal/api/handlers/admin_settings_env.go +++ b/internal/api/handlers/admin_settings_env.go @@ -19,6 +19,15 @@ import ( // storage location guard (storage moves only through a managed transition), // and the cross-field validation over the settings the process will run on. func CheckEnvironmentSettings(stored map[string]string, env config.EnvSettings, redisBootstrapAvailable bool) (config.EnvSettings, error) { + return CheckDeploymentSettings(stored, env, nil, "", redisBootstrapAvailable) +} + +// CheckDeploymentSettings is CheckEnvironmentSettings with the machine-managed +// settings the deployment document writes, such as the AI provider registry, +// checked together with the environment's values: a recommendations +// variable can name a provider the document declares. declaredBy names the +// document's variable in errors. +func CheckDeploymentSettings(stored map[string]string, env config.EnvSettings, declared map[string]string, declaredBy string, redisBootstrapAvailable bool) (config.EnvSettings, error) { checked := make(config.EnvSettings, 0, len(env)) normalized := make(map[string]string, len(env)) for _, setting := range env { @@ -38,6 +47,15 @@ func CheckEnvironmentSettings(stored map[string]string, env config.EnvSettings, normalized[setting.Key] = value } + // A registry the document leaves unchanged isn't a change, so its binding + // group isn't checked again on every start. + declaredChanged := false + for key, value := range declared { + if stored[key] != value { + normalized[key] = value + declaredChanged = true + } + } prospective := make(map[string]string, len(stored)+len(normalized)) maps.Copy(prospective, stored) maps.Copy(prospective, normalized) @@ -50,12 +68,41 @@ func CheckEnvironmentSettings(stored map[string]string, env config.EnvSettings, } } + skipBindingsOutsideDeclaration(prospective, normalized, declaredBy) + if err := validateProspectiveAdminSettings(adminSettingsValidationSnapshot(prospective, normalized), redisBootstrapAvailable); err != nil { - return nil, fmt.Errorf("the settings from the environment are invalid (%s): %w", strings.Join(checked.VarsFor(nil), ", "), err) + vars := checked.VarsFor(nil) + if declaredChanged { + vars = append(vars, declaredBy) + } + return nil, fmt.Errorf("the settings from the environment are invalid (%s): %w", strings.Join(vars, ", "), err) } return checked, nil } +// skipBindingsOutsideDeclaration leaves out of the startup check each stored +// provider binding the deployment can't have broken: one the environment +// doesn't set that names a provider the document doesn't declare (with no +// document, every stored binding). Declaring never removes a provider, so +// such a binding is as valid as it was, and one already naming a missing +// provider (as a restore into another deployment can leave) stays the +// admin's to fix instead of stopping startup. +func skipBindingsOutsideDeclaration(prospective, fromEnvironment map[string]string, declaredBy string) { + registry, err := config.ParseAIProviderRegistry(prospective[config.AIProvidersSettingKey]) + if err != nil { + return // The registry check reports it. + } + for _, key := range config.AIProviderBindingKeys() { + if _, set := fromEnvironment[key]; set { + continue + } + provider, found := registry.Find(strings.TrimSpace(prospective[key])) + if !found || declaredBy == "" || provider.ManagedBy != declaredBy { + prospective[key] = "" + } + } +} + // storageLocationKeys are the settings rejectArtworkIdentityChange compares. var storageLocationKeys = map[string]bool{ artworkStorageBackendKey: true, diff --git a/internal/api/handlers/admin_settings_env_test.go b/internal/api/handlers/admin_settings_env_test.go index 1c2f3ff447..6b3f255ae5 100644 --- a/internal/api/handlers/admin_settings_env_test.go +++ b/internal/api/handlers/admin_settings_env_test.go @@ -1,6 +1,7 @@ package handlers import ( + "errors" "strings" "testing" @@ -102,3 +103,80 @@ func TestCheckEnvironmentSettingsDeploymentSettings(t *testing.T) { } } + +// SILO_RECOMMENDATIONS_PROVIDER can name a provider the deployment document +// declares in the same start, and only a connected one that serves +// embeddings. +func TestCheckDeploymentSettingsBindsDeclaredProvider(t *testing.T) { + embed, err := config.NewDeclaredAIProvider("local-embed", config.AIProviderCustom, "Local embeddings", "http://embed:8080/v1", "", []config.AICapability{config.AICapabilityEmbeddings}) + if err != nil { + t.Fatal(err) + } + registry, err := config.ApplyDeclaredAIProviders("", []config.AIProvider{embed}, "SILO_CONFIG_FILE") + if err != nil { + t.Fatal(err) + } + declared := map[string]string{config.AIProvidersSettingKey: registry} + env := readEnv(t, map[string]string{ + "SILO_RECOMMENDATIONS_ENABLED": "true", + "SILO_RECOMMENDATIONS_PROVIDER": "local-embed", + "SILO_RECOMMENDATIONS_MODEL": "nomic-embed-text", + }) + checked, err := CheckDeploymentSettings(nil, env, declared, "SILO_CONFIG_FILE", false) + if err != nil { + t.Fatal(err) + } + if got := checked.Values(config.EnvScopeStored)[config.EmbeddingProviderSettingKey]; got != "local-embed" { + t.Errorf("embedding provider = %q, want local-embed", got) + } + + // Without the document the provider isn't connected, and startup stops. + if _, err := CheckEnvironmentSettings(nil, env, false); err == nil || !strings.Contains(err.Error(), "SILO_RECOMMENDATIONS_PROVIDER") { + t.Errorf("provider not declared: error = %v, want one naming SILO_RECOMMENDATIONS_PROVIDER", err) + } + + // A stored binding the document can't have broken, such as one a restore + // into another deployment left naming a provider that's gone, doesn't stop + // startup; one to a declared provider that can't serve it does. + if _, err := CheckDeploymentSettings(map[string]string{config.AITextProviderSettingKey: "openai-1a2b3c"}, env, declared, "SILO_CONFIG_FILE", false); err != nil { + t.Errorf("stored binding to a missing provider: %v", err) + } + if _, err := CheckDeploymentSettings(map[string]string{config.AITextProviderSettingKey: "local-embed"}, env, declared, "SILO_CONFIG_FILE", false); err == nil || !strings.Contains(err.Error(), "SILO_CONFIG_FILE") { + t.Errorf("stored binding to a declared provider that can't serve it: error = %v, want one naming SILO_CONFIG_FILE", err) + } + // The same holds with no document, when only the variables touch the + // bindings, and for a text binding the ChatGPT plan leaves idle. + connected := config.AIProviderRegistry{Providers: []config.AIProvider{embed}}.Encode() + if _, err := CheckDeploymentSettings(map[string]string{config.AIProvidersSettingKey: connected, config.AITextProviderSettingKey: "openai-1a2b3c"}, env, nil, "", false); err != nil { + t.Errorf("variables only, stored binding to a missing provider: %v", err) + } + if _, err := CheckDeploymentSettings(map[string]string{config.AIAuthModeSettingKey: "chatgpt", config.AITextProviderSettingKey: "local-embed"}, env, declared, "SILO_CONFIG_FILE", false); err != nil { + t.Errorf("idle text binding under the ChatGPT plan: %v", err) + } +} + +// A provider the deployment declares is listed with its variable, and the +// admin API refuses to edit or remove it until a document releases it. +func TestAdminAIProvidersRefuseDeclaredProvider(t *testing.T) { + embed, err := config.NewDeclaredAIProvider("local-embed", config.AIProviderCustom, "Local embeddings", "http://embed:8080/v1", "", []config.AICapability{config.AICapabilityEmbeddings}) + if err != nil { + t.Fatal(err) + } + registry, err := config.ApplyDeclaredAIProviders("", []config.AIProvider{embed}, "SILO_CONFIG_FILE") + if err != nil { + t.Fatal(err) + } + handler := &AdminHandler{SettingsRepo: newSerializedSettingsStore(map[string]string{config.AIProvidersSettingKey: registry})} + + views, err := handler.ListAIProviders(t.Context()) + if err != nil || len(views) != 1 || views[0].ManagedByEnvVar != "SILO_CONFIG_FILE" { + t.Fatalf("views = %+v, error = %v; want the declared provider with its variable", views, err) + } + name := "Renamed" + if _, err := handler.UpdateAIProvider(t.Context(), "local-embed", AdminAIProviderInput{Name: &name}); !errors.Is(err, ErrAIProviderManaged) { + t.Errorf("update: error = %v, want ErrAIProviderManaged", err) + } + if err := handler.DeleteAIProvider(t.Context(), "local-embed"); !errors.Is(err, ErrAIProviderManaged) { + t.Errorf("delete: error = %v, want ErrAIProviderManaged", err) + } +} diff --git a/internal/apiv2/admin_ai_providers.go b/internal/apiv2/admin_ai_providers.go index 45f19a2300..90b3b2ed23 100644 --- a/internal/apiv2/admin_ai_providers.go +++ b/internal/apiv2/admin_ai_providers.go @@ -21,13 +21,14 @@ type AdminAIProviderService interface { } type AdminAIProvider struct { - ID string `json:"id"` - Type string `json:"type" enum:"openai,gemini,openrouter,groq,ollama,whisper,custom"` - Name string `json:"name"` - BaseURL string `json:"base_url" format:"uri"` - HasAPIKey bool `json:"has_api_key"` - Capabilities []string `json:"capabilities" enum:"chat,embeddings,speech" doc:"What the provider serves."` - UsedBy []string `json:"used_by" enum:"text,speech,embeddings" doc:"Jobs currently sending requests to the provider. A provider in use cannot be deleted."` + ID string `json:"id"` + Type string `json:"type" enum:"openai,gemini,openrouter,groq,ollama,whisper,custom"` + Name string `json:"name"` + BaseURL string `json:"base_url" format:"uri"` + HasAPIKey bool `json:"has_api_key"` + Capabilities []string `json:"capabilities" enum:"chat,embeddings,speech" doc:"What the provider serves."` + UsedBy []string `json:"used_by" enum:"text,speech,embeddings" doc:"Jobs currently sending requests to the provider. A provider in use cannot be deleted."` + ManagedByEnvVar string `json:"managed_by_env_var,omitempty" doc:"The variable in the server's environment that declares this provider, such as SILO_CONFIG_FILE, when the deployment declares it. Updating or deleting such a provider is 422 validation_failed with code managed_by_environment."` } type AdminAIProviderType struct { @@ -93,6 +94,7 @@ func adminAIProviderOf(view handlers.AdminAIProviderView) AdminAIProvider { return AdminAIProvider{ ID: view.ID, Type: view.Type, Name: view.Name, BaseURL: view.BaseURL, HasAPIKey: view.HasAPIKey, Capabilities: nonNilStrings(view.Capabilities), UsedBy: nonNilStrings(view.UsedBy), + ManagedByEnvVar: view.ManagedByEnvVar, } } @@ -132,6 +134,8 @@ func adminAIProviderProblem(err error, action string) error { return NewProblem(TypeValidationFailed, detail(handlers.ErrAIProviderInvalid)) case errors.Is(err, handlers.ErrAIProviderConflict): return NewProblem(TypeConflict, detail(handlers.ErrAIProviderConflict)) + case errors.Is(err, handlers.ErrAIProviderManaged): + return validationProblem("path.id", codeManagedByEnvironment, detail(handlers.ErrAIProviderManaged)) case errors.Is(err, handlers.ErrAdminSettingsUnavailable): return unavailable("AI providers") default: @@ -186,7 +190,7 @@ func registerAdminAIProviders(reg *Registry) { return &AdminAIProviderOutput{Body: adminAIProviderOf(view)}, nil }) - Register(reg, op("PATCH", "/admin/ai/providers/{id}", "updateAdminAIProvider", "Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request."), func(ctx context.Context, in *AdminAIProviderUpdateInput) (*AdminAIProviderOutput, error) { + Register(reg, op("PATCH", "/admin/ai/providers/{id}", "updateAdminAIProvider", "Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request. A provider the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment."), func(ctx context.Context, in *AdminAIProviderUpdateInput) (*AdminAIProviderOutput, error) { svc, err := service() if err != nil { return nil, err @@ -199,7 +203,7 @@ func registerAdminAIProviders(reg *Registry) { return &AdminAIProviderOutput{Body: adminAIProviderOf(view)}, nil }) - Register(reg, op("DELETE", "/admin/ai/providers/{id}", "deleteAdminAIProvider", "Disconnect a provider and discard its key. A provider a job uses cannot be deleted."), func(ctx context.Context, in *AdminAIProviderIDInput) (*struct{}, error) { + Register(reg, op("DELETE", "/admin/ai/providers/{id}", "deleteAdminAIProvider", "Disconnect a provider and discard its key. A provider a job uses cannot be deleted, and one the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment."), func(ctx context.Context, in *AdminAIProviderIDInput) (*struct{}, error) { svc, err := service() if err != nil { return nil, err diff --git a/internal/apiv2/admin_ai_providers_test.go b/internal/apiv2/admin_ai_providers_test.go new file mode 100644 index 0000000000..d864546fa1 --- /dev/null +++ b/internal/apiv2/admin_ai_providers_test.go @@ -0,0 +1,20 @@ +package apiv2 + +import ( + "errors" + "fmt" + "net/http" + "testing" + + "github.com/Silo-Server/silo-server/internal/api/handlers" +) + +// Editing or deleting an AI provider the deployment document declares is a +// validation failure with code managed_by_environment, not a server error. +func TestAdminAIProviderRefusesDeclaredProvider(t *testing.T) { + err := fmt.Errorf("%w: OpenAI is declared by the deployment document in SILO_CONFIG_FILE", handlers.ErrAIProviderManaged) + p, ok := errors.AsType[*Problem](adminAIProviderProblem(err, "update")) + if !ok || p.Status != http.StatusUnprocessableEntity || len(p.Errors) != 1 || p.Errors[0].Code != codeManagedByEnvironment { + t.Fatalf("problem %+v, want validation_failed with code managed_by_environment", p) + } +} diff --git a/internal/config/ai_providers.go b/internal/config/ai_providers.go index 809c33705d..6c84c5dbdf 100644 --- a/internal/config/ai_providers.go +++ b/internal/config/ai_providers.go @@ -161,6 +161,10 @@ type AIProvider struct { BaseURL string `json:"base_url"` APIKey string `json:"api_key,omitempty"` Capabilities []AICapability `json:"capabilities"` + // ManagedBy names the deployment variable that declares the provider, + // such as SILO_CONFIG_FILE (ApplyDeclaredAIProviders). Admins cannot edit + // or delete a declared provider. Empty for one an admin connected. + ManagedBy string `json:"managed_by,omitempty"` } // Supports reports whether the provider serves capability. @@ -414,6 +418,11 @@ func ValidateAIProviderBindings(values map[string]string) error { if id == "" { continue } + // The text binding is idle while the ChatGPT plan serves text, as in + // AIProviderUsers, so it needs no provider until the plan is left. + if binding.job == AIJobText && strings.TrimSpace(values[AIAuthModeSettingKey]) == aiAuthModeChatGPT { + continue + } provider, ok := registry.Find(id) if !ok { return fmt.Errorf("the %s provider %q is not connected", binding.label, id) diff --git a/internal/config/ai_providers_declared.go b/internal/config/ai_providers_declared.go new file mode 100644 index 0000000000..adb677ffe3 --- /dev/null +++ b/internal/config/ai_providers_declared.go @@ -0,0 +1,97 @@ +package config + +import ( + "fmt" + "slices" + "strings" +) + +// NewDeclaredAIProvider builds a provider the deployment declares. A name or +// address left empty comes from the type, as when an admin connects one, and +// the result is normalized like an admin's. Only a custom provider takes +// capabilities; a known type's are fixed, so declaring them is an error +// rather than silently ignored. +func NewDeclaredAIProvider(id string, t AIProviderType, name, baseURL, apiKey string, capabilities []AICapability) (AIProvider, error) { + spec, ok := LookupAIProviderType(t) + if !ok { + return AIProvider{}, fmt.Errorf("unknown AI provider type %q", t) + } + if spec.Capabilities != nil && len(capabilities) > 0 { + return AIProvider{}, fmt.Errorf("a %s provider's capabilities are fixed; capabilities apply only to custom providers", spec.Label) + } + provider := AIProvider{ + ID: id, Type: t, Name: spec.Label, BaseURL: spec.DefaultBaseURL, APIKey: apiKey, + Capabilities: slices.Clone(capabilities), + } + if name != "" { + provider.Name = name + } + if baseURL != "" { + provider.BaseURL = baseURL + } + return NormalizeAIProvider(provider) +} + +// ApplyDeclaredAIProviders returns the stored registry raw with the declared +// providers in it, each owned by managedBy. A declared provider replaces the +// stored one with its id whole, key included, or is added after the others. +// A provider an earlier declaration owned that this one leaves out is +// released: it stays connected, and admins can edit or delete it again. The +// registry's version is kept, so a legacy conversion that has not run yet +// still runs. +func ApplyDeclaredAIProviders(raw string, declared []AIProvider, managedBy string) (string, error) { + registry, err := ParseAIProviderRegistry(raw) + if err != nil { + return "", err + } + byID := make(map[string]bool, len(declared)) + byName := make(map[string]string, len(declared)) + for _, provider := range declared { + byID[provider.ID] = true + name := strings.ToLower(provider.Name) + if other, taken := byName[name]; taken { + return "", fmt.Errorf("%s and %s are both named %q; give each declared provider a name of its own", other, provider.ID, provider.Name) + } + byName[name] = provider.ID + } + for i, stored := range registry.Providers { + if !byID[stored.ID] { + registry.Providers[i].ManagedBy = "" + } + } + for _, provider := range declared { + // A declared name an undeclared provider already has would otherwise + // fail as a duplicate name with no hint of the fix. + for _, stored := range registry.Providers { + if !byID[stored.ID] && strings.EqualFold(provider.Name, stored.Name) { + return "", nameTakenError(provider, stored) + } + } + provider.ManagedBy = managedBy + if i := slices.IndexFunc(registry.Providers, func(p AIProvider) bool { return p.ID == provider.ID }); i >= 0 { + // As for an admin's edit: the models bound to a provider are its + // type's, so a new type takes a new id. + if stored := registry.Providers[i]; stored.Type != provider.Type { + return "", fmt.Errorf("%s: a provider's type cannot change (it is %s, declared as %s); declare the %s provider under a new id with a name of its own", + provider.ID, stored.Type, provider.Type, provider.Type) + } + registry.Providers[i] = provider + } else { + registry.Providers = append(registry.Providers, provider) + } + } + if err := registry.Validate(); err != nil { + return "", err + } + return registry.Encode(), nil +} + +func nameTakenError(declared, stored AIProvider) error { + // Taking the other provider over is a way out only when it keeps its type. + if stored.Type != declared.Type { + return fmt.Errorf("%s: another AI provider, %s, is already named %q; give the declared provider a name of its own", + declared.ID, stored.ID, stored.Name) + } + return fmt.Errorf("%s: another AI provider, %s, is already named %q; give the declared provider a name of its own, or declare %s to take that provider over", + declared.ID, stored.ID, stored.Name, stored.ID) +} diff --git a/internal/config/ai_providers_declared_test.go b/internal/config/ai_providers_declared_test.go new file mode 100644 index 0000000000..a0244f8b9a --- /dev/null +++ b/internal/config/ai_providers_declared_test.go @@ -0,0 +1,81 @@ +package config + +import ( + "strings" + "testing" +) + +// The deployment's providers replace the ones with their ids, whole, join the +// others, and release the ones an earlier declaration owned. +func TestApplyDeclaredAIProviders(t *testing.T) { + openai, err := NewDeclaredAIProvider("openai-main", AIProviderOpenAI, "", "", "sk-declared", nil) + if err != nil { + t.Fatal(err) + } + if openai.Name != "OpenAI" || openai.BaseURL != openAIBaseURL || len(openai.Capabilities) != 3 { + t.Fatalf("declared provider = %+v, want the type's name, address and capabilities", openai) + } + stored := AIProviderRegistry{Version: aiProvidersVersion, Providers: []AIProvider{ + {ID: "openai-main", Type: AIProviderOpenAI, Name: "Old OpenAI", BaseURL: "https://proxy.example.com", APIKey: "sk-admin", Capabilities: []AICapability{AICapabilityChat}}, + {ID: "ollama-old", Type: AIProviderOllama, Name: "Ollama", BaseURL: ollamaBaseURL, ManagedBy: "SILO_CONFIG_FILE"}, + {ID: "groq-admin", Type: AIProviderGroq, Name: "Groq", BaseURL: groqBaseURL, APIKey: "gsk"}, + }}.Encode() + + raw, err := ApplyDeclaredAIProviders(stored, []AIProvider{openai}, "SILO_CONFIG_FILE") + if err != nil { + t.Fatal(err) + } + registry, err := ParseAIProviderRegistry(raw) + if err != nil { + t.Fatal(err) + } + if registry.Version != aiProvidersVersion || len(registry.Providers) != 3 { + t.Fatalf("registry = %+v, want three providers at the stored version", registry) + } + got, _ := registry.Find("openai-main") + if got.Name != "OpenAI" || got.BaseURL != openAIBaseURL || got.APIKey != "sk-declared" || got.ManagedBy != "SILO_CONFIG_FILE" { + t.Errorf("adopted provider = %+v, want the declaration whole, owned by SILO_CONFIG_FILE", got) + } + if released, _ := registry.Find("ollama-old"); released.ManagedBy != "" { + t.Errorf("provider no longer declared = %+v, want it kept and released", released) + } + if admin, _ := registry.Find("groq-admin"); admin.APIKey != "gsk" || admin.ManagedBy != "" { + t.Errorf("admin provider = %+v, want it untouched", admin) + } + if again, err := ApplyDeclaredAIProviders(raw, []AIProvider{openai}, "SILO_CONFIG_FILE"); err != nil || again != raw { + t.Errorf("applying the same declaration again changed the registry: %v", err) + } + + // A declared provider can't take a name another provider already has. + groq, err := NewDeclaredAIProvider("groq-declared", AIProviderGroq, "", "", "gsk-2", nil) + if err != nil { + t.Fatal(err) + } + if _, err := ApplyDeclaredAIProviders(raw, []AIProvider{openai, groq}, "SILO_CONFIG_FILE"); err == nil || !strings.Contains(err.Error(), "groq-admin") { + t.Errorf("name collision: error = %v, want one naming groq-admin, the provider to take over or rename around", err) + } + + // A provider keeps its type, as an admin's edit does: its bound models + // are that type's. + retyped, err := NewDeclaredAIProvider("groq-admin", AIProviderOpenAI, "Retyped", "", "sk-3", nil) + if err != nil { + t.Fatal(err) + } + if _, err := ApplyDeclaredAIProviders(raw, []AIProvider{retyped}, "SILO_CONFIG_FILE"); err == nil || !strings.Contains(err.Error(), "type cannot change") { + t.Errorf("retyped provider: error = %v, want a refusal of the type change", err) + } + + // Two declarations may not share a name; the error names both. + other, err := NewDeclaredAIProvider("openai-batch", AIProviderOpenAI, "", "", "sk-2", nil) + if err != nil { + t.Fatal(err) + } + if _, err := ApplyDeclaredAIProviders("", []AIProvider{openai, other}, "SILO_CONFIG_FILE"); err == nil || !strings.Contains(err.Error(), "openai-batch") { + t.Errorf("duplicate declared names: error = %v, want one naming both providers", err) + } + + // A known type's capabilities are fixed, so declaring them is refused. + if _, err := NewDeclaredAIProvider("openai-chat", AIProviderOpenAI, "", "", "sk", []AICapability{AICapabilityChat}); err == nil { + t.Error("capabilities on an OpenAI provider were accepted") + } +} diff --git a/internal/config/env_settings.go b/internal/config/env_settings.go index b3a6186ffe..6084658f0d 100644 --- a/internal/config/env_settings.go +++ b/internal/config/env_settings.go @@ -111,6 +111,10 @@ var envSettingVars = []EnvSettingVar{ {"SILO_BACKUP_INCLUDE_SUBTITLES", BackupIncludeSubtitlesSettingKey, EnvScopeStored}, {"SILO_BACKUP_INCLUDE_INTRO_FINGERPRINTS", BackupIncludeIntroFingerprintsSettingKey, EnvScopeStored}, + {"SILO_RECOMMENDATIONS_ENABLED", "recommendations.enabled", EnvScopeStored}, + {"SILO_RECOMMENDATIONS_PROVIDER", EmbeddingProviderSettingKey, EnvScopeStored}, + {"SILO_RECOMMENDATIONS_MODEL", "recommendations.embedding_model", EnvScopeStored}, + {"SILO_TMDB_API_KEY", "tmdb.api_key", EnvScopeStored}, {"SILO_MDBLIST_API_KEY", "mdblist.api_key", EnvScopeStored}, diff --git a/internal/plugins/provision_document.go b/internal/plugins/provision_document.go index f527f67256..f10798508f 100644 --- a/internal/plugins/provision_document.go +++ b/internal/plugins/provision_document.go @@ -18,15 +18,33 @@ import ( "github.com/santhosh-tekuri/jsonschema/v6" provisioningv1 "github.com/Silo-Server/silo-server/contracts/plugins/provisioning/v1" + "github.com/Silo-Server/silo-server/internal/config" "github.com/Silo-Server/silo-server/internal/provisiondoc" ) -// ProvisionDocument holds the declaration and a snapshot of its local secret -// inputs. Only resolved fields of a verified manifest are passed to a plugin. +// ProvisionDocument holds the deployment's declaration and a snapshot of its +// local secret inputs. Only resolved fields of a verified manifest are passed +// to a plugin. A section the document leaves out is nil: what it would +// declare is left as stored, where an empty section releases it. type ProvisionDocument struct { - APIVersion provisionInt `json:"apiVersion"` - Plugins map[string]ProvisionPlugin `json:"plugins"` - secrets map[provisionReference]string + APIVersion provisionInt `json:"apiVersion"` + Plugins map[string]ProvisionPlugin `json:"plugins"` + AIProviders map[string]ProvisionAIProvider `json:"ai_providers"` + secrets map[provisionReference]string + // secretBytes counts every secret the document's references read, plugin + // and AI keys alike, against the one 1 MiB limit. + secretBytes int + variable string +} + +// ProvisionAIProvider is one AI provider the deployment declares. APIKey is a +// fromFile or fromEnv reference; the schema refuses a literal key. +type ProvisionAIProvider struct { + Type string `json:"type"` + Name string `json:"name"` + BaseURL string `json:"base_url"` + Capabilities []string `json:"capabilities"` + APIKey map[string]any `json:"api_key"` } type ProvisionPlugin struct { @@ -59,25 +77,115 @@ func (v *provisionInt) UnmarshalJSON(data []byte) error { const maxProvisionBytes = provisiondoc.MaxBytes +// provisionDocumentVars name the deployment document: inline JSON, or a JSON +// or YAML file. SILO_CONFIG and SILO_CONFIG_FILE are its names for +// everything it declares; SILO_PLUGINS and SILO_PLUGINS_FILE, the names it +// had when it declared plugins alone, still work. +var provisionDocumentVars = []struct { + name string + file bool +}{ + {"SILO_CONFIG", false}, {"SILO_CONFIG_FILE", true}, {"SILO_PLUGINS", false}, {"SILO_PLUGINS_FILE", true}, +} + // ReadProvisionDocument is called by API hosts only. A nil document means // that this instance reads the committed deployment state. func ReadProvisionDocument() (*ProvisionDocument, error) { - inline := os.Getenv("SILO_PLUGINS") - path := os.Getenv("SILO_PLUGINS_FILE") + var set []string + var source struct { + name string + file bool + } + for _, v := range provisionDocumentVars { + if os.Getenv(v.name) != "" { + set = append(set, v.name) + source = v + } + } switch { - case inline != "" && path != "": - return nil, errors.New("set only one of SILO_PLUGINS and SILO_PLUGINS_FILE") - case path != "": - data, err := provisiondoc.ReadFile(path) + case len(set) == 0: + return nil, nil + case len(set) > 1: + return nil, fmt.Errorf("set only one of %s and %s", strings.Join(set[:len(set)-1], ", "), set[len(set)-1]) + } + data := []byte(os.Getenv(source.name)) + if source.file { + var err error + if data, err = provisiondoc.ReadFile(string(data)); err != nil { + return nil, fmt.Errorf("%s: %w", source.name, err) + } + } + document, err := parseProvisionDocument(data, source.file) + if err != nil { + return nil, fmt.Errorf("%s: %w", source.name, err) + } + document.variable = source.name + return document, nil +} + +// Variable names the environment variable the document came from. +func (d *ProvisionDocument) Variable() string { + if d == nil { + return "" + } + return d.variable +} + +// DeclaresPlugins reports whether the document has a plugins section. A +// document without one leaves plugin installations as they are. +func (d *ProvisionDocument) DeclaresPlugins() bool { + return d != nil && d.Plugins != nil +} + +// DeclaredAIProviders returns the AI providers the document declares, in id +// order with their keys resolved, and whether it has an ai_providers section. +// An empty section declares none, which releases every provider an earlier +// document declared. +func (d *ProvisionDocument) DeclaredAIProviders() ([]config.AIProvider, bool, error) { + if d == nil || d.AIProviders == nil { + return nil, false, nil + } + providers := make([]config.AIProvider, 0, len(d.AIProviders)) + for _, id := range slices.Sorted(maps.Keys(d.AIProviders)) { + declared := d.AIProviders[id] + apiKey, err := d.resolveAIProviderKey(declared.APIKey) if err != nil { - return nil, fmt.Errorf("SILO_PLUGINS_FILE: %w", err) + return nil, true, fmt.Errorf("ai_providers.%s.api_key: %w", id, err) } - return parseProvisionDocument(data, true) - case inline != "": - return parseProvisionDocument([]byte(inline), false) - default: - return nil, nil + capabilities := make([]config.AICapability, len(declared.Capabilities)) + for i, capability := range declared.Capabilities { + capabilities[i] = config.AICapability(capability) + } + provider, err := config.NewDeclaredAIProvider(id, config.AIProviderType(declared.Type), declared.Name, declared.BaseURL, apiKey, capabilities) + if err != nil { + return nil, true, fmt.Errorf("ai_providers.%s: %w", id, err) + } + providers = append(providers, provider) + } + return providers, true, nil +} + +// resolveAIProviderKey reads a declared provider's key, which the schema +// allows only as a fromFile or fromEnv reference, within the document's secret +// budget. The key is read here rather than with the document, so a server +// that applies no providers, such as a frontend, needs no AI keys. +func (d *ProvisionDocument) resolveAIProviderKey(value map[string]any) (string, error) { + if value == nil { + return "", nil + } + ref, ok := referenceFrom(value) + if !ok { + return "", errors.New("expected a fromFile or fromEnv reference") + } + if err := d.captureSecret(ref, &d.secretBytes); err != nil { + return "", err + } + // A key that is only whitespace would be stored as no key at all, which a + // provider that takes an optional key would accept without a word. + if strings.TrimSpace(d.secrets[ref]) == "" { + return "", errors.New("the referenced secret holds only whitespace") } + return d.secrets[ref], nil } var provisionSchema = sync.OnceValues(func() (*jsonschema.Schema, error) { @@ -95,7 +203,7 @@ var provisionSchema = sync.OnceValues(func() (*jsonschema.Schema, error) { func parseProvisionDocument(data []byte, allowYAML bool) (*ProvisionDocument, error) { if len(data) > maxProvisionBytes || !utf8.Valid(data) { - return nil, errors.New("plugin provisioning expects UTF-8 input up to 1 MiB") + return nil, errors.New("the deployment document must be UTF-8 input up to 1 MiB") } if allowYAML && !jsontext.Value(data).IsValid() { // A malformed JSON document beginning with an object can still be a @@ -107,7 +215,7 @@ func parseProvisionDocument(data []byte, allowYAML bool) (*ProvisionDocument, er } } if !jsontext.Value(data).IsValid() { - return nil, errors.New("invalid plugin JSON: check syntax and duplicate keys") + return nil, errors.New("invalid deployment document JSON: check syntax and duplicate keys") } schema, err := provisionSchema() if err != nil { @@ -115,24 +223,23 @@ func parseProvisionDocument(data []byte, allowYAML bool) (*ProvisionDocument, er } value, err := jsonschema.UnmarshalJSON(bytes.NewReader(data)) if err != nil { - return nil, errors.New("invalid plugin declaration") + return nil, errors.New("invalid deployment declaration") } if err := schema.Validate(value); err != nil { if e, ok := errors.AsType[*jsonschema.ValidationError](err); ok { for len(e.Causes) == 1 { e = e.Causes[0] } - return nil, fmt.Errorf("invalid plugin declaration at /%s", strings.Join(e.InstanceLocation, "/")) + return nil, fmt.Errorf("invalid deployment declaration at /%s", strings.Join(e.InstanceLocation, "/")) } - return nil, errors.New("declaration does not match the plugin provisioning schema") + return nil, errors.New("declaration does not match the deployment document schema") } var document ProvisionDocument decoder := json.NewDecoder(bytes.NewReader(data)) decoder.UseNumber() // Keep plugin config integers exact through the encrypted store. if err := decoder.Decode(&document); err != nil { - return nil, errors.New("invalid plugin declaration") + return nil, errors.New("invalid deployment declaration") } - var secretBytes int document.secrets = make(map[provisionReference]string) for _, id := range slices.Sorted(maps.Keys(document.Plugins)) { plugin := document.Plugins[id] @@ -145,7 +252,7 @@ func parseProvisionDocument(data []byte, allowYAML bool) (*ProvisionDocument, er } for entry, fields := range plugin.Config { for field, value := range fields { - if err := document.captureReferences(value, &secretBytes); err != nil { + if err := document.captureReferences(value, &document.secretBytes); err != nil { return nil, fmt.Errorf("plugins.%s.config.%s.%s: %w", id, entry, field, err) } } diff --git a/internal/plugins/provision_document_test.go b/internal/plugins/provision_document_test.go index b48dd2cbc2..56dcd65951 100644 --- a/internal/plugins/provision_document_test.go +++ b/internal/plugins/provision_document_test.go @@ -5,10 +5,14 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" "testing" pluginv1 "github.com/Silo-Server/silo-plugin-sdk/pkg/pluginproto/silo/plugin/v1" + + provisioningv1 "github.com/Silo-Server/silo-server/contracts/plugins/provisioning/v1" + "github.com/Silo-Server/silo-server/internal/config" ) func TestReadProvisionDocumentEmptyEnvironment(t *testing.T) { @@ -18,25 +22,90 @@ func TestReadProvisionDocumentEmptyEnvironment(t *testing.T) { t.Fatal(err) } for _, tc := range []struct { - name, inline, path string - wantDocument, wantError bool + name string + env map[string]string + wantVariable string + wantError bool }{ - {"empty variables use committed state", "", "", false, false}, - {"inline release", release, "", true, false}, - {"file release", "", path, true, false}, - {"two declarations", release, path, false, true}, + {"empty variables use committed state", nil, "", false}, + {"inline release", map[string]string{"SILO_PLUGINS": release}, "SILO_PLUGINS", false}, + {"file release", map[string]string{"SILO_PLUGINS_FILE": path}, "SILO_PLUGINS_FILE", false}, + {"deployment document", map[string]string{"SILO_CONFIG": release}, "SILO_CONFIG", false}, + {"deployment document file", map[string]string{"SILO_CONFIG_FILE": path}, "SILO_CONFIG_FILE", false}, + {"two declarations", map[string]string{"SILO_PLUGINS": release, "SILO_PLUGINS_FILE": path}, "", true}, + {"old and new names", map[string]string{"SILO_CONFIG_FILE": path, "SILO_PLUGINS": release}, "", true}, } { t.Run(tc.name, func(t *testing.T) { - t.Setenv("SILO_PLUGINS", tc.inline) - t.Setenv("SILO_PLUGINS_FILE", tc.path) + for _, name := range []string{"SILO_CONFIG", "SILO_CONFIG_FILE", "SILO_PLUGINS", "SILO_PLUGINS_FILE"} { + t.Setenv(name, tc.env[name]) + } doc, err := ReadProvisionDocument() - if (err != nil) != tc.wantError || (doc != nil) != tc.wantDocument { + if (err != nil) != tc.wantError || (doc != nil) != (tc.wantVariable != "") { t.Fatalf("document present = %t, error = %v", doc != nil, err) } + if doc != nil && doc.Variable() != tc.wantVariable { + t.Fatalf("variable = %q, want %q", doc.Variable(), tc.wantVariable) + } }) } } +// The deployment document declares AI providers with keys taken by reference. +// A section it leaves out is left as stored; an empty one releases it. +func TestProvisionDocumentAIProviders(t *testing.T) { + t.Setenv("TEST_SILO_OPENAI_KEY", "sk-from-env") + doc, err := parseProvisionDocument([]byte(`{"apiVersion":1,"ai_providers":{ + "openai-main":{"type":"openai","api_key":{"fromEnv":"TEST_SILO_OPENAI_KEY"}}, + "local-embed":{"type":"custom","name":"Local embeddings","base_url":"http://embed:8080/v1","capabilities":["embeddings"]}}}`), false) + if err != nil { + t.Fatal(err) + } + if doc.DeclaresPlugins() { + t.Error("a document without a plugins section declares plugins") + } + providers, declared, err := doc.DeclaredAIProviders() + if err != nil || !declared || len(providers) != 2 { + t.Fatalf("providers = %+v, declared = %t, error = %v", providers, declared, err) + } + if p := providers[1]; p.ID != "openai-main" || p.APIKey != "sk-from-env" { + t.Errorf("openai-main = %+v, want the key from the environment", p) + } + if p := providers[0]; p.ID != "local-embed" || p.APIKey != "" { + t.Errorf("local-embed = %+v, want no key", p) + } + + empty, err := parseProvisionDocument([]byte(`{"apiVersion":1,"ai_providers":{}}`), false) + if err != nil { + t.Fatal(err) + } + if providers, declared, err := empty.DeclaredAIProviders(); err != nil || !declared || len(providers) != 0 { + t.Errorf("empty section: providers = %v, declared = %t, error = %v; want a release", providers, declared, err) + } + plugins, err := parseProvisionDocument([]byte(`{"apiVersion":1,"plugins":{}}`), false) + if err != nil { + t.Fatal(err) + } + if _, declared, _ := plugins.DeclaredAIProviders(); declared || !plugins.DeclaresPlugins() { + t.Error("a plugins-only document declares AI providers, or no plugins") + } + + t.Setenv("TEST_SILO_BLANK_KEY", " ") + for name, input := range map[string]string{ + "literal key": `{"apiVersion":1,"ai_providers":{"openai-main":{"type":"openai","api_key":"sk-private-literal"}}}`, + "key it requires": `{"apiVersion":1,"ai_providers":{"openai-main":{"type":"openai"}}}`, + "blank key": `{"apiVersion":1,"ai_providers":{"local":{"type":"ollama","api_key":{"fromEnv":"TEST_SILO_BLANK_KEY"}}}}`, + "empty capabilities": `{"apiVersion":1,"ai_providers":{"local":{"type":"ollama","capabilities":[]}}}`, + } { + doc, err := parseProvisionDocument([]byte(input), false) + if err == nil { + _, _, err = doc.DeclaredAIProviders() + } + if err == nil || strings.Contains(err.Error(), "sk-private-literal") { + t.Errorf("%s: error = %v, want a refusal that doesn't quote the key", name, err) + } + } +} + func TestProvisionDocumentResolvesOnlyVerifiedSecretFields(t *testing.T) { const id = "silo.auth.oidc" dir := t.TempDir() @@ -99,7 +168,6 @@ func TestProvisionDocumentRejectsAmbiguousInputs(t *testing.T) { "duplicate JSON release": {`{"apiVersion":1,"plugins":{"silo.auth.oidc":{"version":"1.0.0","version":"0.1.2"}}}`, false}, "duplicate YAML release": {"apiVersion: 1\nplugins:\n silo.auth.oidc:\n version: 1.0.0\n version: 0.1.2\n", true}, "multi document": {"apiVersion: 1\nplugins: {}\n---\nplugins: {}\n", true}, - "missing plugins": {`{"apiVersion":1}`, false}, "null releases no ownership": {`{"apiVersion":1,"plugins":null}`, false}, "misspelled host option": {`{"apiVersion":1,"plugins":{"silo.auth.oidc":{"authBinding":{}}}}`, false}, "conflicting secret sources": {`{"apiVersion":1,"plugins":{"silo.auth.oidc":{"config":{"connection":{"password":{"fromFile":"private-literal","fromEnv":"ALSO"}}}}}}`, false}, @@ -182,3 +250,36 @@ func TestProvisionDocumentHostIntegersAndPluginNumbers(t *testing.T) { t.Fatal("YAML rounded the number before validation") } } + +// The schema lists the provider types and capabilities the server knows, so a +// type added in config is declarable. +func TestProvisionSchemaMatchesAIProviderTypes(t *testing.T) { + var schema struct { + Defs struct { + AIProvider struct { + Properties struct { + Type struct{ Enum []string } `json:"type"` + Capabilities struct { + Items struct{ Enum []string } `json:"items"` + } `json:"capabilities"` + } `json:"properties"` + } `json:"aiProvider"` + } `json:"$defs"` + } + if err := json.Unmarshal(provisioningv1.Schema, &schema); err != nil { + t.Fatal(err) + } + var types, capabilities []string + for _, spec := range config.AIProviderTypes { + types = append(types, string(spec.Type)) + } + for _, capability := range config.AICapabilities { + capabilities = append(capabilities, string(capability)) + } + if got := schema.Defs.AIProvider.Properties.Type.Enum; !slices.Equal(got, types) { + t.Errorf("schema types = %v, want %v", got, types) + } + if got := schema.Defs.AIProvider.Properties.Capabilities.Items.Enum; !slices.Equal(got, capabilities) { + t.Errorf("schema capabilities = %v, want %v", got, capabilities) + } +} diff --git a/web/src/api/v2/schema.ts b/web/src/api/v2/schema.ts index b09dc3bb6f..f9482a5757 100644 --- a/web/src/api/v2/schema.ts +++ b/web/src/api/v2/schema.ts @@ -374,11 +374,11 @@ export interface paths { get?: never; put?: never; post?: never; - /** Disconnect a provider and discard its key. A provider a job uses cannot be deleted. */ + /** Disconnect a provider and discard its key. A provider a job uses cannot be deleted, and one the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment. */ delete: operations["deleteAdminAIProvider"]; options?: never; head?: never; - /** Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request. */ + /** Edit a provider. Every job using it switches to the new values at once. Its type is fixed, and a new host needs its key in the same request. A provider the deployment declares (managed_by_env_var) is 422 validation_failed with code managed_by_environment. */ patch: operations["updateAdminAIProvider"]; trace?: never; }; @@ -14302,6 +14302,8 @@ export interface components { capabilities: ("chat" | "embeddings" | "speech")[]; has_api_key: boolean; id: string; + /** @description The variable in the server's environment that declares this provider, such as SILO_CONFIG_FILE, when the deployment declares it. Updating or deleting such a provider is 422 validation_failed with code managed_by_environment. */ + managed_by_env_var?: string; name: string; /** @enum {string} */ type: "openai" | "gemini" | "openrouter" | "groq" | "ollama" | "whisper" | "custom"; diff --git a/web/src/pages/AdminRecommendations.tsx b/web/src/pages/AdminRecommendations.tsx index 7c32d914f2..d51e355f14 100644 --- a/web/src/pages/AdminRecommendations.tsx +++ b/web/src/pages/AdminRecommendations.tsx @@ -54,6 +54,8 @@ interface RecSettingFieldProps { localValues: RecLocalValues; sensitiveConfigured: string[]; isPending: boolean; + /** The variable that sets this field on the server; locks the control. */ + managedByEnv?: string; onLocalChange: (key: string, value: string) => void; onCommit: (key: string, value: string) => void; onToggle: (key: string, checked: boolean) => void; @@ -77,7 +79,8 @@ function RecSettingField({ serverValue, localValues, sensitiveConfigured, - isPending, + isPending: isPendingProp, + managedByEnv, onLocalChange, onCommit, onToggle, @@ -86,6 +89,13 @@ function RecSettingField({ const { key, label, type, hint, defaultValue } = field; const effectiveServerValue = serverValue || defaultValue || ""; const [confirmClear, setConfirmClear] = useState(false); + // The server refuses a save of an env-set key, so its control stays disabled. + const isPending = isPendingProp || managedByEnv != null; + const envNote = managedByEnv ? ( +

+ {t("web.admin.settings.fields.managedByEnv", { env: managedByEnv })} +

+ ) : null; if (type === "toggle") { const checked = serverValue === "true"; @@ -96,6 +106,7 @@ function RecSettingField({ {label} {hint &&

{hint}

} + {envNote} { if (!settings) return; + // A key the environment sets takes the server's value over any draft, so + // a draft from before the takeover can't come back, and be saved on + // blur, once the variable is removed. + const managed = sensitiveData?.managed_by_env_vars ?? {}; const next: RecLocalValues = {}; for (const field of getAllRecommendationFields()) { if (field.type === "password" || field.type === "toggle") continue; const serverVal = settings[field.key] || field.defaultValue || ""; - if (!(field.key in localValues)) { + if (!(field.key in localValues) || managed[field.key]) { next[field.key] = serverVal; } } setLocalValues((prev) => { const merged: RecLocalValues = { ...prev }; for (const [key, value] of Object.entries(next)) { - if (!(key in merged)) { + if (!(key in merged) || managed[key]) { merged[key] = value; } } return merged; }); + setDirtyKeys((prev) => + [...prev].some((key) => managed[key]) + ? new Set([...prev].filter((key) => !managed[key])) + : prev, + ); // eslint-disable-next-line react-hooks/exhaustive-deps -- seeds only keys missing from localValues; depending on it would rerun on every edit }, [settings, sensitiveData]); @@ -455,14 +475,23 @@ export default function AdminRecommendations() { setCollapsed((prev) => ({ ...prev, [id]: !prev[id] })); } + // A draft for a key the environment took over since it was typed is + // ignored wherever the page reads it, so the page and the connection check + // use the environment's value. + function draftFor(key: string): string | undefined { + return sensitiveData?.managed_by_env_vars?.[key] ? undefined : localValues[key]; + } + function buildEmbeddingCheckRequest( serverSettings: Record, ): AdminSettingsConnectionCheckRequest { return { values: Object.fromEntries( - EMBEDDING_CHECK_KEYS.map((key) => [key, localValues[key] ?? serverSettings[key] ?? ""]), + EMBEDDING_CHECK_KEYS.map((key) => [key, draftFor(key) ?? serverSettings[key] ?? ""]), + ), + dirty_keys: EMBEDDING_CHECK_KEYS.filter( + (key) => dirtyKeys.has(key) && draftFor(key) !== undefined, ), - dirty_keys: EMBEDDING_CHECK_KEYS.filter((key) => dirtyKeys.has(key)), }; } @@ -485,7 +514,9 @@ export default function AdminRecommendations() { } } - if (isLoading) + // Until the server says which settings its environment sets, a field could + // offer an edit the server would refuse. + if (isLoading || sensitiveLoading) return (
@@ -500,14 +531,14 @@ export default function AdminRecommendations() { ); const sensitiveConfigured = sensitiveData?.configured ?? []; + const envVars = sensitiveData?.managed_by_env_vars ?? {}; const serverSettings: Record = settings ?? {}; const embeddingLock = parseRecommendationEmbeddingLock( serverSettings["recommendations.embedding_lock"], ); const embeddingProviderID = - localValues[EMBEDDING_PROVIDER_KEY] ?? serverSettings[EMBEDDING_PROVIDER_KEY] ?? ""; - const embeddingModel = - localValues[EMBEDDING_MODEL_KEY] ?? serverSettings[EMBEDDING_MODEL_KEY] ?? ""; + draftFor(EMBEDDING_PROVIDER_KEY) ?? serverSettings[EMBEDDING_PROVIDER_KEY] ?? ""; + const embeddingModel = draftFor(EMBEDDING_MODEL_KEY) ?? serverSettings[EMBEDDING_MODEL_KEY] ?? ""; return (
@@ -635,6 +666,7 @@ export default function AdminRecommendations() { { setConnectionResult(null); void handleCommit(EMBEDDING_PROVIDER_KEY, id).then((saved) => { @@ -658,6 +690,7 @@ export default function AdminRecommendations() { kind="embeddings" value={embeddingModel} placeholder={EMBEDDING_MODEL_EXAMPLES} + managedByEnv={envVars[EMBEDDING_MODEL_KEY]} onChange={(next) => handleLocalChange(EMBEDDING_MODEL_KEY, next)} onCommit={(next) => { if (next !== (serverSettings[EMBEDDING_MODEL_KEY] ?? "")) { @@ -677,6 +710,7 @@ export default function AdminRecommendations() { localValues={localValues} sensitiveConfigured={sensitiveConfigured} isPending={updateSettings.isPending} + managedByEnv={envVars[field.key]} onLocalChange={handleLocalChange} onCommit={(key, value) => void handleCommit(key, value)} onToggle={handleToggle} diff --git a/web/src/pages/admin-settings/AIModelField.tsx b/web/src/pages/admin-settings/AIModelField.tsx index d5ddb88dd7..3ef4d23455 100644 --- a/web/src/pages/admin-settings/AIModelField.tsx +++ b/web/src/pages/admin-settings/AIModelField.tsx @@ -31,6 +31,7 @@ export function ModelField({ onChange, onCommit, placeholder, + managedByEnv, }: { label: string; description?: ReactNode; @@ -41,15 +42,20 @@ export function ModelField({ /** Called when focus leaves the field, for pages that save each field. */ onCommit?: (value: string) => void; placeholder?: string; + /** The variable that sets this model on the server; disables the field. */ + managedByEnv?: string; }) { const t = useT(); const inputID = useId(); const inputRef = useRef(null); const pickerOpen = useRef(false); - const models = useAIProviderModels(providerID); + // A model the environment sets can't be picked here, so its provider's + // models aren't fetched. + const listedProviderID = managedByEnv != null ? "" : providerID; + const models = useAIProviderModels(listedProviderID); const suggestions = (models.data?.models ?? []).filter((model) => model.kind === kind); const status = - providerID === "" ? undefined : models.isError ? ( + listedProviderID === "" ? undefined : models.isError ? ( {t("web.admin.settings.ai.modelField.loadFailed")} @@ -62,7 +68,13 @@ export function ModelField({ ) : undefined; return ( - +
{ @@ -79,6 +91,7 @@ export function ModelField({ placeholder={placeholder} autoComplete="off" spellCheck={false} + disabled={managedByEnv != null} className="font-mono text-[13px]" /> {suggestions.length > 0 && ( diff --git a/web/src/pages/admin-settings/AIProviders.test.tsx b/web/src/pages/admin-settings/AIProviders.test.tsx index aaafdf9fec..09c874571b 100644 --- a/web/src/pages/admin-settings/AIProviders.test.tsx +++ b/web/src/pages/admin-settings/AIProviders.test.tsx @@ -2,6 +2,8 @@ import { render, screen, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { beforeEach, describe, expect, it, vi } from "vitest"; +import type { AIProvider } from "@/hooks/queries/admin/aiProviders"; + import { AIProvidersList } from "./AIProviders"; const mocks = vi.hoisted(() => ({ update: vi.fn() })); @@ -15,7 +17,7 @@ vi.mock("@/hooks/queries/admin/aiProviders", () => ({ })); vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } })); -const provider = { +const provider: AIProvider = { id: "openai-1", type: "openai" as const, name: "OpenAI", @@ -34,8 +36,8 @@ const types = [ }, ]; -async function openProvider(user: ReturnType) { - render(); +async function openProvider(user: ReturnType, shown = provider) { + render(); await user.click(screen.getByRole("button", { name: "Manage" })); return screen.getByRole("group", { name: "OpenAI" }); } @@ -59,4 +61,21 @@ describe("AIProvidersList", () => { expect(draft.name).toBe("OpenAI work"); expect(draft.api_key).toBe(wantKey); }); + + // The server refuses to edit or delete a provider the deployment declares. + it("locks a provider the deployment declares", async () => { + const user = userEvent.setup(); + const panel = await openProvider(user, { + ...provider, + used_by: [], + managed_by_env_var: "SILO_CONFIG_FILE", + }); + expect( + within(panel).getByText("Set by SILO_CONFIG_FILE in the server’s environment."), + ).toBeInTheDocument(); + expect(within(panel).getByLabelText("Name")).toBeDisabled(); + expect(within(panel).queryByRole("button", { name: "Remove" })).not.toBeInTheDocument(); + expect(within(panel).queryByRole("button", { name: "Save" })).not.toBeInTheDocument(); + expect(within(panel).getByRole("button", { name: "Test" })).toBeEnabled(); + }); }); diff --git a/web/src/pages/admin-settings/AIProviders.tsx b/web/src/pages/admin-settings/AIProviders.tsx index b9fd4f0e39..4bf7978688 100644 --- a/web/src/pages/admin-settings/AIProviders.tsx +++ b/web/src/pages/admin-settings/AIProviders.tsx @@ -179,6 +179,9 @@ function ProviderRow({ const type = types.find((candidate) => candidate.type === provider.type); const [monogram, monogramClass] = TYPE_MONOGRAMS[provider.type]; const inUse = provider.used_by.length > 0; + // A declared provider's open panel edits nothing, so its row keeps its + // usage status rather than saying it is being edited. + const editing = expanded && provider.managed_by_env_var == null; return ( {expanded && type ? ( + // Remounted when the deployment takes the provider over or releases + // it, so no draft or test result from before carries across. void; }) { const t = useT(); - const [draft, setDraft] = useState(initial); + const [editDraft, setDraft] = useState(initial); const [test, setTest] = useState(); const [confirmDelete, setConfirmDelete] = useState(false); const create = useCreateAIProvider(); @@ -453,6 +459,12 @@ function ProviderPanel({ const remove = useDeleteAIProvider(); const check = useCheckAIProvider(); const custom = type.capabilities.length === 0; + // The deployment declares this provider; the server refuses edits to it. + const managedByEnv = provider?.managed_by_env_var; + const locked = managedByEnv != null; + // A locked panel shows and tests the stored provider, including one the + // deployment took over while an admin had edits open here. + const draft = locked ? initial : editDraft; const keyCleared = draft.api_key === "" && provider?.has_api_key === true; const dirty = !provider || @@ -529,15 +541,26 @@ function ProviderPanel({ return (
+ {managedByEnv ? ( + // A row of its own, spaced and divided like the fields, so the note + // reads as covering the whole panel rather than the name. +
+ + {t("web.admin.settings.fields.managedByEnv", { env: managedByEnv })} + +
+ ) : null} change({ name })} + disabled={locked} /> change({ base_url })} + disabled={locked} // eslint-disable-next-line formatjs/no-literal-string-in-jsx -- an example value, not text hint={type.default_base_url || "https://llm.example.net/v1"} dir="ltr" @@ -564,7 +587,16 @@ function ProviderPanel({ onKeep={() => change({ api_key: undefined })} onClear={provider?.has_api_key ? () => change({ api_key: "" }) : undefined} cleared={keyCleared} - hint={type.key_required ? undefined : t("web.admin.settings.ai.providers.apiKeyOptional")} + // A declared provider's key can't be replaced here, so it gets no + // editing hint; an empty hint replaces the field's default one. + hint={ + locked + ? "" + : type.key_required + ? undefined + : t("web.admin.settings.ai.providers.apiKeyOptional") + } + disabled={locked} /> {custom ? ( change({ capabilities: on @@ -594,6 +627,7 @@ function ProviderPanel({ } className={cn( "border-border hover:bg-accent rounded-md border px-3 py-1.5 text-xs transition-colors", + "disabled:pointer-events-none disabled:opacity-50", on && "border-primary bg-primary/5 text-primary", )} > @@ -610,7 +644,7 @@ function ProviderPanel({ {t("common.back")} ) : null} - {provider ? ( + {provider && !locked ? ( - {dirty ? ( + {dirty && !locked ? ( ) : null} - {provider && provider.used_by.length > 0 ? ( + {provider && !locked && provider.used_by.length > 0 ? (

{t("web.admin.settings.ai.providers.usedByNote", { jobs: usedByLabel(t, provider.used_by), })}

) : null} - {provider ? ( + {provider && !locked ? ( void; disabled?: boolean; restartRequired?: boolean; + /** The variable that sets the embedding provider; locks the choice. */ + managedByEnv?: string; }) { const t = useT(); const list = useAIProviders(); @@ -718,6 +757,7 @@ export function EmbeddingProviderField({ value={value || NO_EMBEDDING_PROVIDER} disabled={disabled || list.isLoading} restartRequired={restartRequired} + managedByEnv={managedByEnv} description={t("web.admin.settings.ai.embeddingProvider.description")} onChange={(next) => { if (next === ADD_PROVIDER) setAdding(true); diff --git a/web/src/pages/admin-settings/AISettings.tsx b/web/src/pages/admin-settings/AISettings.tsx index 433b946654..ede76aad5b 100644 --- a/web/src/pages/admin-settings/AISettings.tsx +++ b/web/src/pages/admin-settings/AISettings.tsx @@ -85,13 +85,18 @@ const KEYS: string[] = Array.from( ]), ); -/** The text provider select's value for the ChatGPT plan. */ -const CHATGPT_PROVIDER = "chatgpt"; +/** + * The text provider select's value for the ChatGPT plan. Like NO_PROVIDER it + * holds an underscore, so a provider a deployment declares as "chatgpt" stays + * an ordinary choice. + */ +const CHATGPT_PROVIDER = "__chatgpt__"; /** * A provider select's value for no provider. Choosing it releases the - * provider, so it can be removed once no job uses it. + * provider, so it can be removed once no job uses it. No provider id can + * contain an underscore, so a deployment's chosen ids never collide with it. */ -const NO_PROVIDER = "none"; +const NO_PROVIDER = "__none__"; /** Example model ids for the text model field; they read the same in every language. */ const TEXT_MODEL_PLACEHOLDER = "gpt-6-luna, gemini-2.5-flash, llama3.1"; @@ -296,7 +301,7 @@ function TextModelTile({ : ready ? "connected" : "not_connected"; - const chatGPT = authMode === CHATGPT_PROVIDER; + const chatGPT = authMode === "chatgpt"; const provider = providers.find((candidate) => candidate.id === providerID); const selected = chatGPT ? CHATGPT_PROVIDER : providerID; const supportsServiceTier = !chatGPT && provider?.type === "openai" && serviceTiers.length > 0; diff --git a/web/src/pages/setup-wizard/steps/FeaturesStep.tsx b/web/src/pages/setup-wizard/steps/FeaturesStep.tsx index 6b2afa1b3c..f741d03f2b 100644 --- a/web/src/pages/setup-wizard/steps/FeaturesStep.tsx +++ b/web/src/pages/setup-wizard/steps/FeaturesStep.tsx @@ -233,6 +233,7 @@ export function FeaturesStep() { description={t("web.setup.features.recommendationsDescription")} value={recsEnabled ? "true" : "false"} onChange={(v) => form.setValue("recommendations.enabled", v)} + managedByEnv={form.envVar("recommendations.enabled")} /> @@ -241,6 +242,7 @@ export function FeaturesStep() { form.setValue(EMBEDDING_PROVIDER_KEY, id)} + managedByEnv={form.envVar(EMBEDDING_PROVIDER_KEY)} /> form.setValue(EMBEDDING_MODEL_KEY, v)} + managedByEnv={form.envVar(EMBEDDING_MODEL_KEY)} // eslint-disable-next-line formatjs/no-literal-string-in-jsx -- example model identifier placeholder="gemini-embedding-001" />