Skip to content

Commit

Permalink
Rename the chat agent API to "participant" (#205477)
Browse files Browse the repository at this point in the history
* Start renaming chat API from "agent" to "participant"

* Rename the rest of the API

* Rename in integration test

* Update integration test api proposals

* Bump distro
  • Loading branch information
roblourens authored Feb 19, 2024
1 parent b2b60ac commit 05bf957
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 275 deletions.
4 changes: 2 additions & 2 deletions extensions/vscode-api-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"enabledApiProposals": [
"activeComment",
"authSession",
"chatAgents2",
"chatParticipant",
"languageModels",
"defaultChatAgent",
"defaultChatParticipant",
"contribViewsRemote",
"contribStatusBarItems",
"createFileSystemWatcher",
Expand Down
48 changes: 24 additions & 24 deletions extensions/vscode-api-tests/src/singlefolder-tests/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as assert from 'assert';
import 'mocha';
import { CancellationToken, ChatAgentContext, ChatAgentRequest, ChatAgentResult2, ChatVariableLevel, Disposable, Event, EventEmitter, InteractiveSession, ProviderResult, chat, interactive } from 'vscode';
import { CancellationToken, ChatContext, ChatRequest, ChatResult, ChatVariableLevel, Disposable, Event, EventEmitter, InteractiveSession, ProviderResult, chat, interactive } from 'vscode';
import { DeferredPromise, assertNoRpc, closeAllEditors, disposeAll } from '../utils';

suite('chat', () => {
Expand All @@ -21,15 +21,15 @@ suite('chat', () => {
disposeAll(disposables);
});

function getDeferredForRequest(): DeferredPromise<ChatAgentRequest> {
const deferred = new DeferredPromise<ChatAgentRequest>();
disposables.push(setupAgent()(request => deferred.complete(request.request)));
function getDeferredForRequest(): DeferredPromise<ChatRequest> {
const deferred = new DeferredPromise<ChatRequest>();
disposables.push(setupParticipant()(request => deferred.complete(request.request)));

return deferred;
}

function setupAgent(): Event<{ request: ChatAgentRequest; context: ChatAgentContext }> {
const emitter = new EventEmitter<{ request: ChatAgentRequest; context: ChatAgentContext }>();
function setupParticipant(): Event<{ request: ChatRequest; context: ChatContext }> {
const emitter = new EventEmitter<{ request: ChatRequest; context: ChatContext }>();
disposables.push();
disposables.push(interactive.registerInteractiveSessionProvider('provider', {
prepareSession: (_token: CancellationToken): ProviderResult<InteractiveSession> => {
Expand All @@ -40,48 +40,48 @@ suite('chat', () => {
},
}));

const agent = chat.createChatAgent('agent', (request, context, _progress, _token) => {
const participant = chat.createChatParticipant('participant', (request, context, _progress, _token) => {
emitter.fire({ request, context });
return null;
});
agent.isDefault = true;
agent.commandProvider = {
participant.isDefault = true;
participant.commandProvider = {
provideCommands: (_token) => {
return [{ name: 'hello', description: 'Hello' }];
}
};
disposables.push(agent);
disposables.push(participant);
return emitter.event;
}

test('agent and slash command', async () => {
const onRequest = setupAgent();
interactive.sendInteractiveRequestToProvider('provider', { message: '@agent /hello friend' });
test('participant and slash command', async () => {
const onRequest = setupParticipant();
interactive.sendInteractiveRequestToProvider('provider', { message: '@participant /hello friend' });

let i = 0;
onRequest(request => {
if (i === 0) {
assert.deepStrictEqual(request.request.command, 'hello');
assert.strictEqual(request.request.prompt, 'friend');
i++;
interactive.sendInteractiveRequestToProvider('provider', { message: '@agent /hello friend' });
interactive.sendInteractiveRequestToProvider('provider', { message: '@participant /hello friend' });
} else {
assert.strictEqual(request.context.history.length, 1);
assert.strictEqual(request.context.history[0].agent.agent, 'agent');
assert.strictEqual(request.context.history[0].participant.participant, 'participant');
assert.strictEqual(request.context.history[0].command, 'hello');
}
});
});

test('agent and variable', async () => {
test('participant and variable', async () => {
disposables.push(chat.registerVariable('myVar', 'My variable', {
resolve(_name, _context, _token) {
return [{ level: ChatVariableLevel.Full, value: 'myValue' }];
}
}));

const deferred = getDeferredForRequest();
interactive.sendInteractiveRequestToProvider('provider', { message: '@agent hi #myVar' });
interactive.sendInteractiveRequestToProvider('provider', { message: '@participant hi #myVar' });
const request = await deferred.p;
assert.strictEqual(request.prompt, 'hi #myVar');
assert.strictEqual(request.variables[0].values[0].value, 'myValue');
Expand All @@ -97,25 +97,25 @@ suite('chat', () => {
},
}));

const deferred = new DeferredPromise<ChatAgentResult2>();
const agent = chat.createChatAgent('agent', (_request, _context, _progress, _token) => {
const deferred = new DeferredPromise<ChatResult>();
const participant = chat.createChatParticipant('participant', (_request, _context, _progress, _token) => {
return { metadata: { key: 'value' } };
});
agent.isDefault = true;
agent.commandProvider = {
participant.isDefault = true;
participant.commandProvider = {
provideCommands: (_token) => {
return [{ name: 'hello', description: 'Hello' }];
}
};
agent.followupProvider = {
participant.followupProvider = {
provideFollowups(result, _token) {
deferred.complete(result);
return [];
},
};
disposables.push(agent);
disposables.push(participant);

interactive.sendInteractiveRequestToProvider('provider', { message: '@agent /hello friend' });
interactive.sendInteractiveRequestToProvider('provider', { message: '@participant /hello friend' });
const result = await deferred.p;
assert.deepStrictEqual(result.metadata, { key: 'value' });
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.87.0",
"distro": "664b4b796ea2343e71889a507e125feb14390bdf",
"distro": "af73a537ea203329debad3df7ca7b42b4799473f",
"author": {
"name": "Microsoft Corporation"
},
Expand Down
16 changes: 8 additions & 8 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1410,15 +1410,15 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostChatProvider.registerLanguageModel(extension, id, provider, metadata);
},
registerVariable(name: string, description: string, resolver: vscode.ChatVariableResolver) {
checkProposedApiEnabled(extension, 'chatAgents2');
checkProposedApiEnabled(extension, 'chatParticipant');
return extHostChatVariables.registerVariableResolver(extension, name, description, resolver);
},
registerMappedEditsProvider(selector: vscode.DocumentSelector, provider: vscode.MappedEditsProvider) {
checkProposedApiEnabled(extension, 'mappedEditsProvider');
return extHostLanguageFeatures.registerMappedEditsProvider(extension, selector, provider);
},
createChatAgent(name: string, handler: vscode.ChatAgentExtendedRequestHandler) {
checkProposedApiEnabled(extension, 'chatAgents2');
createChatParticipant(name: string, handler: vscode.ChatExtendedRequestHandler) {
checkProposedApiEnabled(extension, 'chatParticipant');
return extHostChatAgents2.createChatAgent(extension, name, handler);
},
};
Expand Down Expand Up @@ -1472,9 +1472,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
// types
Breakpoint: extHostTypes.Breakpoint,
TerminalOutputAnchor: extHostTypes.TerminalOutputAnchor,
ChatAgentResultFeedbackKind: extHostTypes.ChatAgentResultFeedbackKind,
ChatResultFeedbackKind: extHostTypes.ChatResultFeedbackKind,
ChatVariableLevel: extHostTypes.ChatVariableLevel,
ChatAgentCompletionItem: extHostTypes.ChatAgentCompletionItem,
ChatCompletionItem: extHostTypes.ChatCompletionItem,
CallHierarchyIncomingCall: extHostTypes.CallHierarchyIncomingCall,
CallHierarchyItem: extHostTypes.CallHierarchyItem,
CallHierarchyOutgoingCall: extHostTypes.CallHierarchyOutgoingCall,
Expand Down Expand Up @@ -1664,7 +1664,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
LogLevel: LogLevel,
EditSessionIdentityMatch: EditSessionIdentityMatch,
InteractiveSessionVoteDirection: extHostTypes.InteractiveSessionVoteDirection,
ChatAgentCopyKind: extHostTypes.ChatAgentCopyKind,
ChatCopyKind: extHostTypes.ChatCopyKind,
InteractiveEditorResponseFeedbackKind: extHostTypes.InteractiveEditorResponseFeedbackKind,
StackFrameFocus: extHostTypes.StackFrameFocus,
ThreadFocus: extHostTypes.ThreadFocus,
Expand All @@ -1678,8 +1678,8 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
ChatResponseProgressPart: extHostTypes.ChatResponseProgressPart,
ChatResponseReferencePart: extHostTypes.ChatResponseReferencePart,
ChatResponseCommandButtonPart: extHostTypes.ChatResponseCommandButtonPart,
ChatAgentRequestTurn: extHostTypes.ChatAgentRequestTurn,
ChatAgentResponseTurn: extHostTypes.ChatAgentResponseTurn,
ChatRequestTurn: extHostTypes.ChatRequestTurn,
ChatResponseTurn: extHostTypes.ChatResponseTurn,
LanguageModelSystemMessage: extHostTypes.LanguageModelSystemMessage,
LanguageModelUserMessage: extHostTypes.LanguageModelUserMessage,
LanguageModelAssistantMessage: extHostTypes.LanguageModelAssistantMessage,
Expand Down
Loading

0 comments on commit 05bf957

Please sign in to comment.