feat: provider config management (#193)
* feat: support scoped removal of provider config (auth, user, project, custom) * feat: implement UI session token management with cookies for window visibility control
This commit is contained in:
committed by
GitHub
parent
d4f1d8abbf
commit
05caf4cc58
@@ -653,6 +653,19 @@ function readConfig(workingDirectory) {
|
||||
return readConfigLayers(workingDirectory).mergedConfig;
|
||||
}
|
||||
|
||||
function getConfigForPath(layers, targetPath) {
|
||||
if (!targetPath) {
|
||||
return layers.userConfig;
|
||||
}
|
||||
if (layers.paths.customPath && targetPath === layers.paths.customPath) {
|
||||
return layers.customConfig;
|
||||
}
|
||||
if (layers.paths.projectPath && targetPath === layers.paths.projectPath) {
|
||||
return layers.projectConfig;
|
||||
}
|
||||
return layers.userConfig;
|
||||
}
|
||||
|
||||
function writeConfig(config, filePath = CONFIG_FILE) {
|
||||
try {
|
||||
if (fs.existsSync(filePath)) {
|
||||
@@ -1314,6 +1327,90 @@ function updateCommand(commandName, updates, workingDirectory) {
|
||||
console.log(`Updated command: ${commandName} (scope: ${targetScope}, md: ${mdModified}, json: ${jsonModified})`);
|
||||
}
|
||||
|
||||
function getProviderSources(providerId, workingDirectory) {
|
||||
const layers = readConfigLayers(workingDirectory);
|
||||
const { userConfig, projectConfig, customConfig, paths } = layers;
|
||||
|
||||
const customProviders = isPlainObject(customConfig?.provider) ? customConfig.provider : {};
|
||||
const customProvidersAlias = isPlainObject(customConfig?.providers) ? customConfig.providers : {};
|
||||
const projectProviders = isPlainObject(projectConfig?.provider) ? projectConfig.provider : {};
|
||||
const projectProvidersAlias = isPlainObject(projectConfig?.providers) ? projectConfig.providers : {};
|
||||
const userProviders = isPlainObject(userConfig?.provider) ? userConfig.provider : {};
|
||||
const userProvidersAlias = isPlainObject(userConfig?.providers) ? userConfig.providers : {};
|
||||
|
||||
const customExists =
|
||||
(customProviders && Object.prototype.hasOwnProperty.call(customProviders, providerId)) ||
|
||||
(customProvidersAlias && Object.prototype.hasOwnProperty.call(customProvidersAlias, providerId));
|
||||
const projectExists =
|
||||
(projectProviders && Object.prototype.hasOwnProperty.call(projectProviders, providerId)) ||
|
||||
(projectProvidersAlias && Object.prototype.hasOwnProperty.call(projectProvidersAlias, providerId));
|
||||
const userExists =
|
||||
(userProviders && Object.prototype.hasOwnProperty.call(userProviders, providerId)) ||
|
||||
(userProvidersAlias && Object.prototype.hasOwnProperty.call(userProvidersAlias, providerId));
|
||||
|
||||
return {
|
||||
sources: {
|
||||
auth: { exists: false },
|
||||
user: { exists: userExists, path: paths.userPath },
|
||||
project: { exists: projectExists, path: paths.projectPath || null },
|
||||
custom: { exists: customExists, path: paths.customPath }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function removeProviderConfig(providerId, workingDirectory, scope = 'user') {
|
||||
if (!providerId || typeof providerId !== 'string') {
|
||||
throw new Error('Provider ID is required');
|
||||
}
|
||||
|
||||
const layers = readConfigLayers(workingDirectory);
|
||||
let targetPath = layers.paths.userPath;
|
||||
|
||||
if (scope === 'project') {
|
||||
if (!workingDirectory) {
|
||||
throw new Error('Working directory is required for project scope');
|
||||
}
|
||||
targetPath = layers.paths.projectPath || targetPath;
|
||||
} else if (scope === 'custom') {
|
||||
if (!layers.paths.customPath) {
|
||||
return false;
|
||||
}
|
||||
targetPath = layers.paths.customPath;
|
||||
}
|
||||
|
||||
const targetConfig = getConfigForPath(layers, targetPath);
|
||||
const providerConfig = isPlainObject(targetConfig.provider) ? targetConfig.provider : {};
|
||||
const providersConfig = isPlainObject(targetConfig.providers) ? targetConfig.providers : {};
|
||||
const removedProvider = providerConfig && Object.prototype.hasOwnProperty.call(providerConfig, providerId);
|
||||
const removedProviders = providersConfig && Object.prototype.hasOwnProperty.call(providersConfig, providerId);
|
||||
|
||||
if (!removedProvider && !removedProviders) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (removedProvider) {
|
||||
delete providerConfig[providerId];
|
||||
if (Object.keys(providerConfig).length === 0) {
|
||||
delete targetConfig.provider;
|
||||
} else {
|
||||
targetConfig.provider = providerConfig;
|
||||
}
|
||||
}
|
||||
|
||||
if (removedProviders) {
|
||||
delete providersConfig[providerId];
|
||||
if (Object.keys(providersConfig).length === 0) {
|
||||
delete targetConfig.providers;
|
||||
} else {
|
||||
targetConfig.providers = providersConfig;
|
||||
}
|
||||
}
|
||||
|
||||
writeConfig(targetConfig, targetPath || CONFIG_FILE);
|
||||
console.log(`Removed provider ${providerId} from config: ${targetPath}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
function deleteCommand(commandName, workingDirectory) {
|
||||
let deleted = false;
|
||||
|
||||
@@ -1669,6 +1766,8 @@ export {
|
||||
deleteSkillSupportingFile,
|
||||
readConfig,
|
||||
writeConfig,
|
||||
getProviderSources,
|
||||
removeProviderConfig,
|
||||
AGENT_DIR,
|
||||
COMMAND_DIR,
|
||||
SKILL_DIR,
|
||||
|
||||
Reference in New Issue
Block a user