Skip to content

Commit

Permalink
Update for API breakages (#6430)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Oct 28, 2024
1 parent 7c3da33 commit 0eeb6c8
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 460 deletions.
407 changes: 0 additions & 407 deletions src/@types/vscode.proposed.lmTools.d.ts

This file was deleted.

26 changes: 13 additions & 13 deletions src/lm/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { IToolCall, TOOL_COMMAND_RESULT, TOOL_MARKDOWN_RESULT } from './tools/to
export class ChatParticipantState {
private _messages: vscode.LanguageModelChatMessage[] = [];

get lastToolResult(): (string | vscode.LanguageModelToolResultPart | vscode.LanguageModelToolCallPart)[] {
get lastToolResult(): (vscode.LanguageModelTextPart | vscode.LanguageModelToolResultPart | vscode.LanguageModelToolCallPart)[] {
for (let i = this._messages.length - 1; i >= 0; i--) {
const message = this._messages[i];
for (const part of message.content2) {
for (const part of message.content) {
if (part instanceof vscode.LanguageModelToolResultPart) {
return message.content2;
return message.content;
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ export class ChatParticipant implements vscode.Disposable {
return {
name: tool.name,
description: tool.description,
parametersSchema: tool.parametersSchema ?? {}
inputSchema: tool.inputSchema ?? {}
};
});

Expand Down Expand Up @@ -133,14 +133,14 @@ export class ChatParticipant implements vscode.Disposable {
throw new Error('Got invalid tool choice: ' + part.name);
}

let parameters: any;
let input: any;
try {
parameters = part.parameters;
input = part.input;
} catch (err) {
throw new Error(`Got invalid tool use parameters: "${JSON.stringify(part.parameters)}". (${(err as Error).message})`);
throw new Error(`Got invalid tool use parameters: "${JSON.stringify(part.input)}". (${(err as Error).message})`);
}

const invocationOptions = { parameters, toolInvocationToken: request.toolInvocationToken, requestedContentTypes: ['text/plain', 'text/markdown', 'text/json', 'text/display', 'command'] };
const invocationOptions: vscode.LanguageModelToolInvocationOptions<any> = { input, toolInvocationToken: request.toolInvocationToken };
toolCalls.push({
call: part,
result: vscode.lm.invokeTool(tool.name, invocationOptions, token),
Expand All @@ -151,14 +151,14 @@ export class ChatParticipant implements vscode.Disposable {

if (toolCalls.length) {
const assistantMsg = vscode.LanguageModelChatMessage.Assistant('');
assistantMsg.content2 = toolCalls.map(toolCall => new vscode.LanguageModelToolCallPart(toolCall.call.callId, toolCall.tool.name, toolCall.call.parameters));
assistantMsg.content = toolCalls.map(toolCall => new vscode.LanguageModelToolCallPart(toolCall.call.callId, toolCall.tool.name, toolCall.call.input));
this.state.addMessage(assistantMsg);

let shownToUser = false;
for (const toolCall of toolCalls) {
let toolCallResult = (await toolCall.result);

const additionalContent: string[] = [];
const additionalContent: vscode.LanguageModelTextPart[] = [];
let result: vscode.LanguageModelToolResultPart | undefined;

for (let i = 0; i < toolCallResult.content.length; i++) {
Expand All @@ -180,16 +180,16 @@ export class ChatParticipant implements vscode.Disposable {
if (!result) {
result = new vscode.LanguageModelToolResultPart(toolCall.call.callId, [part]);
} else {
additionalContent.push(part.value);
additionalContent.push(part);
}
}
}
const message = vscode.LanguageModelChatMessage.User('');
message.content2 = [result!];
message.content = [result!];
this.state.addMessage(message);
if (additionalContent.length) {
const additionalMessage = vscode.LanguageModelChatMessage.User('');
additionalMessage.content2 = additionalContent;
additionalMessage.content = additionalContent;
this.state.addMessage(additionalMessage);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/lm/tools/displayIssuesTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class DisplayIssuesTool extends ToolBase<DisplayIssuesParameters> {

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<DisplayIssuesParameters>): Promise<vscode.PreparedToolInvocation> {
const maxDisplay = 10;
const foundIssuesCount = this.foundIssuesCount(options.parameters);
const foundIssuesCount = this.foundIssuesCount(options.input);
const actualDisplay = Math.min(maxDisplay, foundIssuesCount);
if (actualDisplay === 0) {
return {
Expand All @@ -137,11 +137,11 @@ export class DisplayIssuesTool extends ToolBase<DisplayIssuesParameters> {

async invoke(options: vscode.LanguageModelToolInvocationOptions<DisplayIssuesParameters>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
const issueItemsInfo: vscode.LanguageModelTextPart | undefined = this.chatParticipantState.firstUserMessage;
const issueItems: IssueSearchResultItem[] = options.parameters.arrayOfIssues;
const issueItems: IssueSearchResultItem[] = options.input.arrayOfIssues;
if (issueItems.length === 0) {
return new vscode.LanguageModelToolResult([new vscode.LanguageModelTextPart(vscode.l10n.t('No issues found. Please try another query.'))]);
}
Logger.debug(`Displaying ${this.foundIssuesCount(options.parameters)} issues, first issue ${issueItems[0].number}`, DisplayIssuesTool.ID);
Logger.debug(`Displaying ${this.foundIssuesCount(options.input)} issues, first issue ${issueItems[0].number}`, DisplayIssuesTool.ID);
const importantColumns = await this.getImportantColumns(issueItemsInfo, issueItems, token);

const titleRow = `| ${importantColumns.join(' | ')} |`;
Expand Down
14 changes: 7 additions & 7 deletions src/lm/tools/fetchIssueTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
public static readonly toolId = 'github-pull-request_issue_fetch';

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchIssueToolParameters>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> {
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.parameters.repo?.owner, name: options.parameters.repo?.name });
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, options.parameters.issueNumber);
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, options.input.issueNumber);
if (!issueOrPullRequest) {
throw new Error(`No issue or PR found for ${owner}/${name}/${options.parameters.issueNumber}. Make sure the issue or PR exists.`);
throw new Error(`No issue or PR found for ${owner}/${name}/${options.input.issueNumber}. Make sure the issue or PR exists.`);
}
const result: FetchIssueResult = {
owner,
Expand Down Expand Up @@ -69,15 +69,15 @@ export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
}

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchIssueToolParameters>): Promise<vscode.PreparedToolInvocation> {
if (!options.parameters.issueNumber) {
if (!options.input.issueNumber) {
return {
invocationMessage: vscode.l10n.t('Fetching item from GitHub')
};
}
const { owner, name } = await this.getRepoInfo({ owner: options.parameters.repo?.owner, name: options.parameters.repo?.name });
const url = (owner && name) ? `https://github.com/${owner}/${name}/issues/${options.parameters.issueNumber}` : undefined;
const { owner, name } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });
const url = (owner && name) ? `https://github.com/${owner}/${name}/issues/${options.input.issueNumber}` : undefined;
return {
invocationMessage: url ? vscode.l10n.t('Fetching item [#{0}]({1}) from GitHub', options.parameters.issueNumber, url) : vscode.l10n.t('Fetching item #{0} from GitHub', options.parameters.issueNumber),
invocationMessage: url ? vscode.l10n.t('Fetching item [#{0}]({1}) from GitHub', options.input.issueNumber, url) : vscode.l10n.t('Fetching item #{0} from GitHub', options.input.issueNumber),
};

}
Expand Down
2 changes: 1 addition & 1 deletion src/lm/tools/fetchNotificationTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
if (!github) {
return undefined;
}
const threadId = options.parameters.thread_id;
const threadId = options.input.thread_id;
const thread = await github.octokit.api.activity.getThread({
thread_id: threadId
});
Expand Down
10 changes: 5 additions & 5 deletions src/lm/tools/searchTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ You are getting ready to make a GitHub search query. Given a natural language qu
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<ConvertToQuerySyntaxParameters>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.parameters.repo?.owner, name: options.parameters.repo?.name });
const firstUserMessage = `${this.chatParticipantState.firstUserMessage?.value}, ${options.parameters.naturalLanguageString}`;
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });
const firstUserMessage = `${this.chatParticipantState.firstUserMessage?.value}, ${options.input.naturalLanguageString}`;

const allLabels = await folderManager.getLabels(undefined, { owner, repo: name });

Expand Down Expand Up @@ -438,17 +438,17 @@ export class SearchTool extends RepoToolBase<SearchToolParameters> {
}

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<SearchToolParameters>): Promise<vscode.PreparedToolInvocation> {
const parameterQuery = options.parameters.query;
const parameterQuery = options.input.query;

return {
invocationMessage: vscode.l10n.t('Searching for issues with "{0}". [Open on GitHub.com]({1})', escapeMarkdown(parameterQuery), escapeMarkdown(this.toGitHubUrl(parameterQuery)))
};
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<SearchToolParameters>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
const { folderManager } = await this.getRepoInfo({ owner: options.parameters.repo?.owner, name: options.parameters.repo?.name });
const { folderManager } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });

const parameterQuery = options.parameters.query;
const parameterQuery = options.input.query;
Logger.debug(`Searching with query \`${parameterQuery}\``, SearchTool.ID);

const searchResult = await folderManager.getIssues(parameterQuery);
Expand Down
14 changes: 7 additions & 7 deletions src/lm/tools/suggestFixTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export class SuggestFixTool extends RepoToolBase<IssueToolParameters> {

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<IssueToolParameters>): Promise<vscode.PreparedToolInvocation> {
return {
invocationMessage: options.parameters.issueNumber ? vscode.l10n.t('Suggesting a fix for issue #{0}', options.parameters.issueNumber) : vscode.l10n.t('Suggesting a fix for the issue')
invocationMessage: options.input.issueNumber ? vscode.l10n.t('Suggesting a fix for issue #{0}', options.input.issueNumber) : vscode.l10n.t('Suggesting a fix for the issue')
};
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<IssueToolParameters>, token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
const { folderManager } = await this.getRepoInfo(options.parameters.repo);
const { folderManager } = await this.getRepoInfo(options.input.repo);
if (!folderManager) {
throw new Error(`No folder manager found for ${options.parameters.repo.owner}/${options.parameters.repo.name}. Make sure to have the repository open.`);
throw new Error(`No folder manager found for ${options.input.repo.owner}/${options.input.repo.name}. Make sure to have the repository open.`);
}
const issue = await folderManager.resolveIssue(options.parameters.repo.owner, options.parameters.repo.name, options.parameters.issueNumber, true);
const issue = await folderManager.resolveIssue(options.input.repo.owner, options.input.repo.name, options.input.issueNumber, true);
if (!issue) {
throw new Error(`No issue found for ${options.parameters.repo.owner}/${options.parameters.repo.name}/${options.parameters.issueNumber}. Make sure the issue exists.`);
throw new Error(`No issue found for ${options.input.repo.owner}/${options.input.repo.name}/${options.input.issueNumber}. Make sure the issue exists.`);
}

const result: IssueResult = {
Expand All @@ -53,7 +53,7 @@ export class SuggestFixTool extends RepoToolBase<IssueToolParameters> {

const copilotCodebaseResult = await vscode.lm.invokeTool('copilot_codebase', {
toolInvocationToken: undefined,
parameters: {
input: {
query: result.title
}
}, token);
Expand All @@ -62,7 +62,7 @@ export class SuggestFixTool extends RepoToolBase<IssueToolParameters> {
if (plainTextResult instanceof vscode.LanguageModelTextPart) {
messages.push(vscode.LanguageModelChatMessage.User(`Below is some potential relevant workspace context to the issue. The user cannot see this result, so you should explain it to the user if referencing it in your answer.`));
const toolMessage = vscode.LanguageModelChatMessage.User('');
toolMessage.content2 = [plainTextResult.value];
toolMessage.content = [plainTextResult];
messages.push(toolMessage);
}

Expand Down
16 changes: 8 additions & 8 deletions src/lm/tools/summarizeIssueTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ export class IssueSummarizationTool implements vscode.LanguageModelTool<FetchIss
public static readonly toolId = 'github-pull-request_issue_summarize';

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchIssueResult>): Promise<vscode.PreparedToolInvocation> {
if (!options.parameters.title) {
if (!options.input.title) {
return {
invocationMessage: vscode.l10n.t('Summarizing issue')
};
}
const shortenedTitle = options.parameters.title.length > 40;
const maxLengthTitle = shortenedTitle ? options.parameters.title.substring(0, 40) : options.parameters.title;
const shortenedTitle = options.input.title.length > 40;
const maxLengthTitle = shortenedTitle ? options.input.title.substring(0, 40) : options.input.title;
return {
invocationMessage: vscode.l10n.t('Summarizing "{0}', maxLengthTitle)
};
}

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchIssueResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
let issueOrPullRequestInfo: string = `
Title : ${options.parameters.title}
Body : ${options.parameters.body}
Title : ${options.input.title}
Body : ${options.input.body}
`;
const fileChanges = options.parameters.fileChanges;
const fileChanges = options.input.fileChanges;
if (fileChanges) {
issueOrPullRequestInfo += `
The following are the files changed:
Expand All @@ -41,7 +41,7 @@ Patch: ${fileChange.patch}
`;
}
}
const comments = options.parameters.comments;
const comments = options.input.comments;
for (const [index, comment] of comments.entries()) {
issueOrPullRequestInfo += `
Comment ${index} :
Expand All @@ -56,7 +56,7 @@ Body: ${comment.body}
const model = models[0];

if (model) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.parameters.repo, options.parameters.owner))];
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.input.repo, options.input.owner))];
messages.push(vscode.LanguageModelChatMessage.User(`The issue or pull request information is as follows:`));
messages.push(vscode.LanguageModelChatMessage.User(issueOrPullRequestInfo));
const response = await model.sendRequest(messages, {});
Expand Down
18 changes: 9 additions & 9 deletions src/lm/tools/summarizeNotificationsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class NotificationSummarizationTool implements vscode.LanguageModelTool<F
public static readonly toolId = 'github-pull-request_notification_summarize';

async prepareInvocation(options: vscode.LanguageModelToolInvocationPrepareOptions<FetchNotificationResult>): Promise<vscode.PreparedToolInvocation> {
const parameters = options.parameters;
const parameters = options.input;
if (!parameters.itemType || !parameters.itemNumber) {
return {
invocationMessage: vscode.l10n.t('Summarizing notification')
Expand All @@ -27,16 +27,16 @@ export class NotificationSummarizationTool implements vscode.LanguageModelTool<F

async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchNotificationResult>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult | undefined> {
let notificationInfo: string = '';
const lastReadAt = options.parameters.lastReadAt;
const lastReadAt = options.input.lastReadAt;
if (!lastReadAt) {
// First time the thread is viewed, so no lastReadAt field
notificationInfo += `This thread is viewed for the first time. Here is the main item information of the thread:`;
}
notificationInfo += `
Title : ${options.parameters.title}
Body : ${options.parameters.body}
Title : ${options.input.title}
Body : ${options.input.body}
`;
const fileChanges = options.parameters.fileChanges;
const fileChanges = options.input.fileChanges;
if (fileChanges) {
notificationInfo += `
The following are the files changed:
Expand All @@ -49,7 +49,7 @@ Patch: ${fileChange.patch}
}
}

const unreadComments = options.parameters.comments;
const unreadComments = options.input.comments;
if (unreadComments && unreadComments.length > 0) {
notificationInfo += `
The following are the unread comments of the thread:
Expand All @@ -68,8 +68,8 @@ Body: ${comment.body}
});
const model = models[0];
const content: vscode.LanguageModelTextPart[] = [];
const threadId = options.parameters.threadId;
const notificationKey = options.parameters.notificationKey;
const threadId = options.input.threadId;
const notificationKey = options.input.notificationKey;
if (threadId && notificationKey) {
const markAsReadCommand = {
title: 'Mark As Read',
Expand All @@ -80,7 +80,7 @@ Body: ${comment.body}
content.push(new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)));
}
if (model) {
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.parameters.owner, options.parameters.repo))];
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.input.owner, options.input.repo))];
messages.push(vscode.LanguageModelChatMessage.User(`The notification information is as follows:`));
messages.push(vscode.LanguageModelChatMessage.User(notificationInfo));
const response = await model.sendRequest(messages, {});
Expand Down

0 comments on commit 0eeb6c8

Please sign in to comment.