Skip to content

Commit

Permalink
register pinned agent command to command service
Browse files Browse the repository at this point in the history
  • Loading branch information
atahankilc committed Dec 20, 2024
1 parent 44221b7 commit 905c243
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
10 changes: 8 additions & 2 deletions packages/ai-chat-ui/src/browser/ai-chat-ui-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import { inject, injectable } from '@theia/core/shared/inversify';
import { CommandRegistry, QuickInputButton, QuickInputService, QuickPickItem } from '@theia/core';
import { Widget } from '@theia/core/lib/browser';
import { AI_CHAT_NEW_CHAT_WINDOW_COMMAND, AI_CHAT_SHOW_CHATS_COMMAND, ChatCommands } from './chat-view-commands';
import { ChatAgentLocation, ChatService } from '@theia/ai-chat';
import { AI_CHAT_NEW_CHAT_WINDOW_COMMAND, AI_CHAT_NEW_CHAT_WINDOW_WITH_PINNED_AGENT_COMMAND, AI_CHAT_SHOW_CHATS_COMMAND, ChatCommands } from './chat-view-commands';
import { ChatAgent, ChatAgentLocation, ChatService } from '@theia/ai-chat';
import { AbstractViewContribution } from '@theia/core/lib/browser/shell/view-contribution';
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
import { ChatViewWidget } from './chat-view-widget';
Expand Down Expand Up @@ -79,6 +79,12 @@ export class AIChatContribution extends AbstractViewContribution<ChatViewWidget>
isEnabled: widget => this.withWidget(widget, () => true),
isVisible: widget => this.withWidget(widget, () => true),
});
registry.registerCommand(AI_CHAT_NEW_CHAT_WINDOW_WITH_PINNED_AGENT_COMMAND, {
// TODO - not working if function arg is set to type ChatAgent | undefined ?
execute: (...args: unknown[]) => this.chatService.createSession(ChatAgentLocation.Panel, {focus: true}, args[1] as ChatAgent | undefined),
isEnabled: widget => this.withWidget(widget, () => true),
isVisible: widget => this.withWidget(widget, () => true),
});
registry.registerCommand(AI_CHAT_SHOW_CHATS_COMMAND, {
execute: () => this.selectChat(),
isEnabled: widget => this.withWidget(widget, () => true) && this.chatService.getSessions().length > 1,
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-chat-ui/src/browser/chat-input-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu

const handleUnpin = () => {
props.onUnpin();
}
};

return <div className='theia-ChatInput'>
<div className='theia-ChatInput-Editor-Box'>
Expand Down
5 changes: 5 additions & 0 deletions packages/ai-chat-ui/src/browser/chat-view-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export const AI_CHAT_NEW_CHAT_WINDOW_COMMAND: Command = {
iconClass: codicon('add')
};

export const AI_CHAT_NEW_CHAT_WINDOW_WITH_PINNED_AGENT_COMMAND: Command = {
id: 'ai-chat-ui.new-chat-with-pinned-agent',
iconClass: codicon('add')
};

export const AI_CHAT_SHOW_CHATS_COMMAND: Command = {
id: 'ai-chat-ui.show-chats',
iconClass: codicon('history')
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-chat-ui/src/browser/chat-view-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class ChatViewWidget extends BaseWidget implements ExtractableWidget, Sta
this.chatSession = this.chatService.createSession();

this.inputWidget.onQuery = this.onQuery.bind(this);
this.inputWidget.onUnpin = this.onUnpin.bind(this)
this.inputWidget.onUnpin = this.onUnpin.bind(this);
this.inputWidget.onCancel = this.onCancel.bind(this);
this.inputWidget.chatModel = this.chatSession.model;
this.inputWidget.pinnedAgent = this.chatSession.pinnedAgent;
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-chat-ui/src/browser/style/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ div:last-child>.theia-ChatNode {
position: relative;
bottom: -5px;
right: -2px;
padding-top: 7px;
padding-top: 9px;
padding-left: 10px;
padding-right: 10px;
padding-bottom: 9px;
padding-bottom: 11px;
display: flex;
flex-direction: row;
align-items: start;
Expand Down
8 changes: 4 additions & 4 deletions packages/ai-chat/src/common/chat-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { ChatAgent, ChatAgentLocation } from './chat-agents';
import { ParsedChatRequestAgentPart, ParsedChatRequestVariablePart, ParsedChatRequest } from './parsed-chat-request';
import { AIVariableService } from '@theia/ai-core';
import { Event } from '@theia/core/shared/vscode-languageserver-protocol';
import { OrchestratorChatAgentId } from "./orchestrator-chat-agent";
import { OrchestratorChatAgentId } from './orchestrator-chat-agent';

export interface ChatRequestInvocation {
/**
Expand Down Expand Up @@ -80,7 +80,7 @@ export interface ChatService {

getSession(id: string): ChatSession | undefined;
getSessions(): ChatSession[];
createSession(location?: ChatAgentLocation, options?: SessionOptions): ChatSession;
createSession(location?: ChatAgentLocation, options?: SessionOptions, pinnedAgent?: ChatAgent): ChatSession;
deleteSession(sessionId: string): void;
setActiveSession(sessionId: string, options?: SessionOptions): void;

Expand Down Expand Up @@ -124,13 +124,13 @@ export class ChatServiceImpl implements ChatService {
return this._sessions.find(session => session.id === id);
}

createSession(location = ChatAgentLocation.Panel, options?: SessionOptions): ChatSession {
createSession(location = ChatAgentLocation.Panel, options?: SessionOptions, pinnedAgent?: ChatAgent): ChatSession {
const model = new ChatModelImpl(location);
const session: ChatSessionInternal = {
id: model.id,
model,
isActive: true,
pinnedAgent: undefined
pinnedAgent: pinnedAgent
};
this._sessions.push(session);
this.setActiveSession(session.id, options);
Expand Down

0 comments on commit 905c243

Please sign in to comment.