Skip to content

Commit

Permalink
chore: align with ai-features preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
sdirix authored and eneufeld committed Sep 20, 2024
1 parent c029ec3 commit 574940b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions packages/ai-core/src/browser/ai-settings-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { AISettings, AISettingsService, AgentSettings } from '../common';
@injectable()
export class AISettingsServiceImpl implements AISettingsService {
@inject(PreferenceService) protected preferenceService: PreferenceService;
static readonly PREFERENCE_NAME = 'ai.settings';
static readonly PREFERENCE_NAME = 'ai-features.agentSettings';

protected toDispose = new DisposableCollection();

Expand All @@ -31,21 +31,20 @@ export class AISettingsServiceImpl implements AISettingsService {

async updateAgentSettings(agent: string, agentSettings: Partial<AgentSettings>): Promise<void> {
const settings = await this.getSettings();
const newAgentSettings = { ...settings.agents[agent], ...agentSettings };
settings.agents[agent] = newAgentSettings;
const newAgentSettings = { ...settings[agent], ...agentSettings };
settings[agent] = newAgentSettings;
this.preferenceService.set(AISettingsServiceImpl.PREFERENCE_NAME, settings, PreferenceScope.User);
this.onDidChangeEmitter.fire();
}

async getAgentSettings(agent: string): Promise<AgentSettings | undefined> {
const settings = await this.getSettings();
return settings.agents[agent];
return settings[agent];
}

async getSettings(): Promise<AISettings> {
await this.preferenceService.ready;
const pref = this.preferenceService.inspect<AISettings & JSONObject>(AISettingsServiceImpl.PREFERENCE_NAME);
return pref?.value ? pref.value : { agents: {} };
return pref?.value ? pref.value : {};
}

}
3 changes: 1 addition & 2 deletions packages/ai-core/src/common/agent-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ export class AgentServiceImpl implements AgentService {
@postConstruct()
protected init(): void {
this.aiSettingsService?.getSettings().then(settings => {
const allAgentsSettings = settings.agents;
Object.entries(allAgentsSettings).forEach(([agentId, agentSettings]) => {
Object.entries(settings).forEach(([agentId, agentSettings]) => {
if (agentSettings.enable === false) {
this.disabledAgents.add(agentId);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ai-core/src/common/settings-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ import { Event } from '@theia/core';
import { LanguageModelRequirement } from './language-model';

export const AISettingsService = Symbol('AISettingsService');
/**
* Service to store and retrieve settings on a per-agent basis.
*/
export interface AISettingsService {
updateAgentSettings(agent: string, agentSettings: Partial<AgentSettings>): Promise<void>;
getAgentSettings(agent: string): Promise<AgentSettings | undefined>;
getSettings(): Promise<AISettings>;
onDidChange: Event<void>;
}
export interface AISettings {
agents: Record<string, AgentSettings>
}

export type AISettings = Record<string, AgentSettings>;
export interface AgentSettings {
languageModelRequirements: LanguageModelRequirement[];
enable: boolean;
Expand Down

0 comments on commit 574940b

Please sign in to comment.