Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-grant-work committed Feb 20, 2025
1 parent 40d9d64 commit 5213a9e
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 12 deletions.
6 changes: 3 additions & 3 deletions packages/ai-chat-ui/src/browser/chat-input-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,10 @@ const ChatInput: React.FunctionComponent<ChatInputProperties> = (props: ChatInpu
setInProgress(ChatRequestModel.isInProgress(event.request))
);
} else if (ChatChangeEvent.isChangeSetEvent(event)) {
if (event.changeSet) {
setChangeSetUI(buildChangeSetUI(event.changeSet, props.labelProvider, onDeleteChangeSet, onDeleteChangeSetElement));
} else {
if (event.kind === 'removeChangeSet') {
setChangeSetUI(undefined);
} else {
setChangeSetUI(buildChangeSetUI(event.changeSet, props.labelProvider, onDeleteChangeSet, onDeleteChangeSetElement));
}
}
});
Expand Down
64 changes: 64 additions & 0 deletions packages/ai-chat/src/common/change-set-variable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// *****************************************************************************
// Copyright (C) 2025 EclipseSource GmbH and others.
//
// 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
// *****************************************************************************

// *****************************************************************************
// Copyright (C) 2025 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 { MaybePromise, nls } from '@theia/core';
import { injectable } from '@theia/core/shared/inversify';
import { AIVariable, ResolvedAIVariable, AIVariableContribution, AIVariableResolver, AIVariableService, AIVariableResolutionRequest, AIVariableContext } from '@theia/ai-core';
import { ChatSessionContext } from './chat-service';

export const CHANGE_SET_SUMMARY_VARIABLE: AIVariable = {
id: 'changeSetSummary',
description: nls.localize('theia/ai/core/changeSetSummaryVariable/description', 'Provides a summary of the files in a change set and their contents.'),

name: 'changeSetSummary',
};

@injectable()
export class ContextSummaryVariableContribution implements AIVariableContribution, AIVariableResolver {

registerVariables(service: AIVariableService): void {
service.registerResolver(CHANGE_SET_SUMMARY_VARIABLE, this);
}

canResolve(request: AIVariableResolutionRequest, context: AIVariableContext): MaybePromise<number> {
return request.variable.name === CHANGE_SET_SUMMARY_VARIABLE.name ? 50 : 0;
}

async resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined> {
if (!ChatSessionContext.is(context) || request.variable.name !== CHANGE_SET_SUMMARY_VARIABLE.name || !context.session.changeSet?.getElements().length) { return undefined; }
return {
variable: CHANGE_SET_SUMMARY_VARIABLE,
value: context.session.changeSet.getElements().map(element => `- file: ${element.uri.toString()}, status: ${element.state}`).join('\n-')
};
}
}

61 changes: 61 additions & 0 deletions packages/ai-chat/src/common/context-details-variable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// *****************************************************************************
// Copyright (C) 2025 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 { MaybePromise, nls } from '@theia/core';
import { injectable } from '@theia/core/shared/inversify';
import { AIVariable, ResolvedAIVariable, AIVariableContribution, AIVariableResolver, AIVariableService, AIVariableResolutionRequest, AIVariableContext } from '@theia/ai-core';
import { ChatSessionContext } from './chat-service';

export const CONTEXT_DETAILS_VARIABLE: AIVariable = {
id: 'contextDetails',
description: nls.localize('theia/ai/core/contextDetailsVariable/description', 'Provides full text values and descriptions for all context variables.'),
name: 'contextDetails',
};

@injectable()
export class ContextSummaryVariableContribution implements AIVariableContribution, AIVariableResolver {
protected variableService: AIVariableService | undefined;

registerVariables(service: AIVariableService): void {
this.variableService = service;
service.registerResolver(CONTEXT_DETAILS_VARIABLE, this);
}

canResolve(request: AIVariableResolutionRequest, context: AIVariableContext): MaybePromise<number> {
return request.variable.name === CONTEXT_DETAILS_VARIABLE.name ? 50 : 0;
}

async resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined> {
if (!ChatSessionContext.is(context) || request.variable.name !== CONTEXT_DETAILS_VARIABLE.name || !this.variableService) { return undefined; }
return {
variable: CONTEXT_DETAILS_VARIABLE,
value: await this.resolveAllContextVariables(context)
};
}

protected async resolveAllContextVariables(context: ChatSessionContext): Promise<string> {
const values = await Promise.all(context.session.context.getVariables().map(variable => this.variableService?.resolveVariable(variable, context)));
const data = values.filter((candidate): candidate is ResolvedAIVariable => !!candidate)
.map(resolved => ({
variableKind: resolved.variable.name,
variableKindDescription: resolved.variable.description,
variableInstanceData: resolved.arg,
value: resolved.value
}));
return `\`\`\`json\n${JSON.stringify(data)}\n\`\`\``;
}
}

2 changes: 1 addition & 1 deletion packages/ai-chat/src/common/context-summary-variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { ChatSessionContext } from './chat-service';

export const CONTEXT_SUMMARY_VARIABLE: AIVariable = {
id: 'contextSummary',
description: nls.localize('theia/ai/core/todayVariable/description', 'Does something for today'),
description: nls.localize('theia/ai/core/contextSummaryVariable/description', 'Describes files in the context for a given session.'),
name: 'contextSummary',
};

Expand Down
18 changes: 10 additions & 8 deletions packages/ai-ide/src/common/coder-replace-prompt-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
FILE_CONTENT_FUNCTION_ID,
GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID
} from './workspace-functions';
import { CHAT_CONTEXT_VARIABLE } from './context-variables';
import { CHANGE_SET_SUMMARY_VARIABLE, CHAT_CONTEXT_VARIABLE } from './context-variables';
import { UPDATE_CONTEXT_FILES_FUNCTION_ID } from './context-functions';

export const CODER_REWRITE_PROMPT_TEMPLATE_ID = 'coder-rewrite';
Expand All @@ -38,23 +38,25 @@ Use the following functions to interact with the workspace files if you require
- **~{${GET_WORKSPACE_DIRECTORY_STRUCTURE_FUNCTION_ID}}**: Returns the complete directory structure.
- **~{${GET_WORKSPACE_FILE_LIST_FUNCTION_ID}}**: Lists files and directories in a specific directory.
- **~{${FILE_CONTENT_FUNCTION_ID}}**: Retrieves the content of a specific file.
## Context Update
Use following function to add additional files to the context if you find that they are of interest:
- **~{${UPDATE_CONTEXT_FILES_FUNCTION_ID}}**: Updates the context and returns the new list of files.
- **~{${UPDATE_CONTEXT_FILES_FUNCTION_ID}}**: Remember file locations that are relevant for completing your tasks. Only add files that are really relevant to look at later.
## Propose Code Changes
To propose code changes or any file changes to the user, never print code or new file content in your response.
Instead, for each file you want to propose changes for:
- **Always Retrieve Current Content**: Use ${FILE_CONTENT_FUNCTION_ID} to get the latest content of the target file.
- **Change Content**: Use ~{changeSet_writeChangeToFile}${withSearchAndReplace ? ' or ~{changeSet_replaceContentInFile}' : ''} to suggest file changes to the user.\
- **Always Retrieve Current Content**: Use ${FILE_CONTENT_FUNCTION_ID} to get the latest content of the target file.
- **Change Content**: Use ~{changeSet_writeChangeToFile}${withSearchAndReplace ? ' or ~{changeSet_replaceContentInFile}' : ''} to suggest file changes to the user.\
${withSearchAndReplace ? 'Only select and call one function per file.' : ''}
## Additional Context
The following files have been provided for additional context. Some of them may also be referred to above:
The following files have been provided for additional context. Some of them may also be referred to above.\
Always look at the relevant files to understand your task using getFileContent
{{${CHAT_CONTEXT_VARIABLE}}}
## Previously Proposed Changes
Changes have been proposed for the following files. Some suggestions may have been accepted, while others may still be pending.
{{${CHANGE_SET_SUMMARY_VARIABLE}}}
`,
...(!withSearchAndReplace ? { variantOf: CODER_REPLACE_PROMPT_TEMPLATE_ID } : {}),
};
Expand Down
2 changes: 2 additions & 0 deletions packages/ai-ide/src/common/context-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
// *****************************************************************************

export const CHAT_CONTEXT_VARIABLE = 'contextSummary';
export const CHAT_CONTEXT_DETAILS_VARIABLE = 'contextDetails';
export const CHANGE_SET_SUMMARY_VARIABLE = 'changeSetSummary';
5 changes: 5 additions & 0 deletions packages/ai-ide/src/common/universal-chat-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { LanguageModelRequirement, PromptTemplate } from '@theia/ai-core/lib/com
import { injectable } from '@theia/core/shared/inversify';
import { AbstractStreamParsingChatAgent } from '@theia/ai-chat/lib/common/chat-agents';
import { nls } from '@theia/core';
import { CHAT_CONTEXT_DETAILS_VARIABLE } from './context-variables';

export const universalTemplate: PromptTemplate = {
id: 'universal-system',
Expand Down Expand Up @@ -73,6 +74,10 @@ simple solutions.
- **Question:** "What is the capital of France?"
**Answer:** "I'm here to assist with programming-related queries. For other topics, please refer to a specialized source."
### Current Context
Some files and other pieces of data may already have been added to the context of the chat. If any have, the details can be found below.
{{${CHAT_CONTEXT_DETAILS_VARIABLE}}}
`
};

Expand Down

0 comments on commit 5213a9e

Please sign in to comment.