Skip to content

Commit

Permalink
fix: update Chat Agent per lastest API (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
formulahendry authored Jan 22, 2024
1 parent 0424204 commit c2565e7
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 97 deletions.
14 changes: 7 additions & 7 deletions src/copilot-chat/copilotChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ let specifications: ApiCenterApiVersionDefinitionExport[] = [];
let promptFind = '';

export interface IChatAgentResult extends vscode.ChatAgentResult2 {
slashCommand: string;
subCommand: string;
}

export async function handleChatMessage(request: vscode.ChatAgentRequest, ctx: vscode.ChatAgentContext, progress: vscode.Progress<vscode.ChatAgentProgress>, token: vscode.CancellationToken): Promise<IChatAgentResult> {
const cmd = request.slashCommand?.name;
const cmd = request.subCommand;
const eventName = cmd ? `${TelemetryEvent.copilotChat}.${cmd}` : TelemetryEvent.copilotChat;
let parsedError: IParsedError | undefined;

Expand All @@ -27,7 +27,7 @@ export async function handleChatMessage(request: vscode.ChatAgentRequest, ctx: v

if (!cmd) {
progress.report({ content: 'Hi! What can I help you with? Please use `/list` or `/find` to chat with me!' });
return { slashCommand: '' };
return { subCommand: '' };
}

if (['list', 'find'].includes(cmd ?? "")) {
Expand All @@ -45,7 +45,7 @@ export async function handleChatMessage(request: vscode.ChatAgentRequest, ctx: v
const specificationsToShow = specifications.slice(index, index + specificationsCount);
if (specificationsToShow.length === 0) {
progress.report({ content: "\`>\` There are no more API Specifications.\n\n" });
return { slashCommand: '' };
return { subCommand: '' };
}
specificationsContent = specificationsToShow.map((specification, index) => `## Spec ${index + 1}:\n${specification.value}\n`).join('\n');
}
Expand All @@ -69,7 +69,7 @@ export async function handleChatMessage(request: vscode.ChatAgentRequest, ctx: v
const incomingText = fragment.replace('[RESPONSE END]', '');
progress.report({ content: incomingText });
}
return { slashCommand: 'list' };
return { subCommand: 'list' };
} else if ((cmd === 'find')) {
progress.report({ content: `\`>\` Parsing API Specifications for '${promptFind}'...\n\n` });
const access = await vscode.chat.requestChatAccess('copilot');
Expand All @@ -89,10 +89,10 @@ export async function handleChatMessage(request: vscode.ChatAgentRequest, ctx: v
const incomingText = fragment.replace('[RESPONSE END]', '');
progress.report({ content: incomingText });
}
return { slashCommand: 'find' };
return { subCommand: 'find' };
}

return { slashCommand: '' };
return { subCommand: '' };
} catch (error) {
parsedError = parseError(error);
throw error;
Expand Down
Loading

0 comments on commit c2565e7

Please sign in to comment.