diff --git a/packages/ai-core/src/browser/ai-core-frontend-module.ts b/packages/ai-core/src/browser/ai-core-frontend-module.ts index 589c6d4f216dd..8bd611a770103 100644 --- a/packages/ai-core/src/browser/ai-core-frontend-module.ts +++ b/packages/ai-core/src/browser/ai-core-frontend-module.ts @@ -36,6 +36,10 @@ import { import { FrontendPromptServiceImpl } from './frontend-prompt-service'; import { bindPromptPreferences } from './prompt-preferences'; +import { bindViewContribution, WidgetFactory } from '@theia/core/lib/browser'; + +import { AISettingsWidget } from './ai-settings-widget'; +import { AISettingsViewContribution } from './ai-settings-view-contribution' export default new ContainerModule(bind => { bindContributionProvider(bind, LanguageModelProvider); @@ -64,4 +68,15 @@ export default new ContainerModule(bind => { bindPromptPreferences(bind); bind(FrontendPromptServiceImpl).toSelf().inSingletonScope(); bind(PromptService).toService(FrontendPromptServiceImpl); + + bind(AISettingsWidget).toSelf().inSingletonScope(); + bind(WidgetFactory) + .toDynamicValue(ctx => ({ + id: AISettingsWidget.ID, + createWidget: () => ctx.container.get(AISettingsWidget) + })) + .inSingletonScope(); + + bindViewContribution(bind, AISettingsViewContribution); + }); diff --git a/packages/ai-core/src/browser/ai-settings-view-contribution.ts b/packages/ai-core/src/browser/ai-settings-view-contribution.ts new file mode 100644 index 0000000000000..bbb2dd5211ae1 --- /dev/null +++ b/packages/ai-core/src/browser/ai-settings-view-contribution.ts @@ -0,0 +1,30 @@ +// ***************************************************************************** +// Copyright (C) 2024 EclipseSource GmbH. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 +// ***************************************************************************** +import { AbstractViewContribution } from '@theia/core/lib/browser'; +import { AISettingsWidget } from './ai-settings-widget'; + +export class AISettingsViewContribution extends AbstractViewContribution { + + constructor() { + super({ + widgetId: AISettingsWidget.ID, + widgetName: AISettingsWidget.LABEL, + defaultWidgetOptions: { + area: 'right', + } + }); + } +} diff --git a/packages/ai-core/src/browser/ai-settings-widget.tsx b/packages/ai-core/src/browser/ai-settings-widget.tsx new file mode 100644 index 0000000000000..12c324a83cf38 --- /dev/null +++ b/packages/ai-core/src/browser/ai-settings-widget.tsx @@ -0,0 +1,67 @@ +// ***************************************************************************** +// Copyright (C) 2024 EclipseSource GmbH. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 +// ***************************************************************************** + +import { ContributionProvider, nls } from '@theia/core'; +import { codicon, Panel, ReactWidget, StatefulWidget } from '@theia/core/lib/browser'; +import { inject, injectable, named, postConstruct } from '@theia/core/shared/inversify'; +import { Agent } from '../common/'; +import * as React from '@theia/core/shared/react'; + +@injectable() +export class AISettingsWidget extends ReactWidget implements StatefulWidget { + + static readonly ID = 'ai_settings_widget'; + static readonly LABEL = nls.localizeByDefault('AI Settings'); + + protected readonly settingsWidget: Panel; + + @inject(ContributionProvider) @named(Agent) + protected readonly agents: ContributionProvider; + + + @postConstruct() + protected init(): void { + this.id = AISettingsWidget.ID; + this.title.label = AISettingsWidget.LABEL; + this.title.closable = true; + this.addClass('theia-settings-container'); + this.title.iconClass = codicon('hubot'); + + this.update(); + } + + protected render(): React.ReactNode { + return ( +
+ {this.renderAgentSettings()} +
+ ); + } + + protected renderAgentSettings(): React.ReactNode { + return null; + } + + storeState(): object | undefined { + // Implement the logic to store the state of the widget + return {}; + } + + restoreState(oldState: object): void { + // Implement the logic to restore the state of the widget + } +} +