Skip to content

Commit

Permalink
Add initial AI Settings view (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraBuzila committed Jul 29, 2024
1 parent dd74bab commit c3c2efd
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/ai-core/src/browser/ai-core-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

});
30 changes: 30 additions & 0 deletions packages/ai-core/src/browser/ai-settings-view-contribution.ts
Original file line number Diff line number Diff line change
@@ -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<AISettingsWidget> {

constructor() {
super({
widgetId: AISettingsWidget.ID,
widgetName: AISettingsWidget.LABEL,
defaultWidgetOptions: {
area: 'right',
}
});
}
}
67 changes: 67 additions & 0 deletions packages/ai-core/src/browser/ai-settings-widget.tsx
Original file line number Diff line number Diff line change
@@ -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<Agent>;


@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 (
<div>
{this.renderAgentSettings()}
</div >
);
}

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
}
}

0 comments on commit c3c2efd

Please sign in to comment.