-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40d9d64
commit 5213a9e
Showing
7 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-') | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\`\`\``; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters