Fix provider management profile scoping
This commit is contained in:
@@ -2,7 +2,7 @@ import { readFile } from 'fs/promises'
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { getActiveEnvPath, getActiveAuthPath, getActiveProfileName, getProfileDir, listProfileNamesFromDisk } from '../../services/hermes/hermes-profile'
|
||||
import { readConfigYaml, readConfigYamlForProfile, updateConfigYaml, fetchProviderModels, buildModelGroups, PROVIDER_ENV_MAP } from '../../services/config-helpers'
|
||||
import { readConfigYaml, readConfigYamlForProfile, updateConfigYaml, updateConfigYamlForProfile, fetchProviderModels, buildModelGroups, PROVIDER_ENV_MAP } from '../../services/config-helpers'
|
||||
import { buildProviderModelMap, PROVIDER_PRESETS } from '../../shared/providers'
|
||||
import { getCopilotModelsDetailed, resolveCopilotOAuthToken, type CopilotModelMeta } from '../../services/hermes/copilot-models'
|
||||
import { readAppConfig, writeAppConfig, type ModelVisibilityRule } from '../../services/app-config'
|
||||
@@ -200,6 +200,10 @@ function requestedProfileName(ctx: any): string {
|
||||
return typeof queryProfile === 'string' && queryProfile.trim() ? queryProfile.trim() : ''
|
||||
}
|
||||
|
||||
function requestScopedProfileName(ctx: any): string {
|
||||
return ctx.state?.profile?.name || getActiveProfileName() || 'default'
|
||||
}
|
||||
|
||||
function visibleProfileNamesForUser(ctx: any): string[] {
|
||||
const diskProfiles = listProfileNamesFromDisk()
|
||||
const user = ctx.state?.user
|
||||
@@ -859,7 +863,7 @@ export async function setModelAlias(ctx: any) {
|
||||
|
||||
export async function getConfigModels(ctx: any) {
|
||||
try {
|
||||
const config = await readConfigYaml()
|
||||
const config = await readConfigYamlForProfile(requestScopedProfileName(ctx))
|
||||
ctx.body = buildModelGroups(config)
|
||||
} catch (err: any) {
|
||||
ctx.status = 500
|
||||
@@ -875,7 +879,8 @@ export async function setConfigModel(ctx: any) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await updateConfigYaml((config) => {
|
||||
const profile = requestScopedProfileName(ctx)
|
||||
await updateConfigYamlForProfile(profile, (config) => {
|
||||
config.model = {}
|
||||
config.model.default = defaultModel
|
||||
if (reqProvider) { config.model.provider = reqProvider }
|
||||
|
||||
Reference in New Issue
Block a user