forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
65 changed files
with
1,527 additions
and
311 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,80 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { DisposableMap, IDisposable } from 'vs/base/common/lifecycle'; | ||
import { revive } from 'vs/base/common/marshalling'; | ||
import { IProgress } from 'vs/platform/progress/common/progress'; | ||
import { ExtHostChatAgentsShape2, ExtHostContext, IChatResponseProgressDto, IExtensionChatAgentMetadata, MainContext, MainThreadChatAgentsShape2 } from 'vs/workbench/api/common/extHost.protocol'; | ||
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents'; | ||
import { IChatProgress } from 'vs/workbench/contrib/chat/common/chatService'; | ||
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers'; | ||
|
||
|
||
type AgentData = { | ||
dispose: () => void; | ||
name: string; | ||
hasSlashCommands?: boolean; | ||
hasFollowups?: boolean; | ||
}; | ||
|
||
@extHostNamedCustomer(MainContext.MainThreadChatAgents2) | ||
export class MainThreadChatAgents implements MainThreadChatAgentsShape2, IDisposable { | ||
|
||
private readonly _agents = new DisposableMap<number, AgentData>; | ||
private readonly _pendingProgress = new Map<number, IProgress<IChatProgress>>(); | ||
private readonly _proxy: ExtHostChatAgentsShape2; | ||
|
||
constructor( | ||
extHostContext: IExtHostContext, | ||
@IChatAgentService private readonly _chatAgentService: IChatAgentService | ||
) { | ||
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostChatAgents2); | ||
} | ||
|
||
$unregisterAgent(handle: number): void { | ||
this._agents.deleteAndDispose(handle); | ||
} | ||
|
||
dispose(): void { | ||
this._agents.clearAndDisposeAll(); | ||
} | ||
|
||
$registerAgent(handle: number, name: string, metadata: IExtensionChatAgentMetadata): void { | ||
const d = this._chatAgentService.registerAgent({ | ||
id: name, | ||
metadata: revive(metadata), | ||
invoke: async (request, progress, history, token) => { | ||
const requestId = Math.random(); // Make this a guid | ||
this._pendingProgress.set(requestId, progress); | ||
try { | ||
return await this._proxy.$invokeAgent(handle, requestId, request, { history }, token) ?? {}; | ||
} finally { | ||
this._pendingProgress.delete(requestId); | ||
} | ||
}, | ||
provideSlashCommands: async (token) => { | ||
if (!this._agents.get(handle)?.hasSlashCommands) { | ||
return []; // safe an IPC call | ||
} | ||
return this._proxy.$provideSlashCommands(handle, token); | ||
} | ||
}); | ||
this._agents.set(handle, { name, dispose: d.dispose, hasSlashCommands: metadata.hasSlashCommands }); | ||
} | ||
|
||
$updateAgent(handle: number, metadataUpdate: IExtensionChatAgentMetadata): void { | ||
const data = this._agents.get(handle); | ||
if (!data) { | ||
throw new Error(`No agent with handle ${handle} registered`); | ||
} | ||
data.hasSlashCommands = metadataUpdate.hasSlashCommands; | ||
this._chatAgentService.updateAgent(data.name, revive(metadataUpdate)); | ||
} | ||
|
||
async $handleProgressChunk(requestId: number, chunk: IChatResponseProgressDto): Promise<void> { | ||
// TODO copy/move $acceptResponseProgress from MainThreadChat | ||
this._pendingProgress.get(requestId)?.report(revive(chunk) as any); | ||
} | ||
} |
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,81 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { CancellationTokenSource } from 'vs/base/common/cancellation'; | ||
import { Emitter } from 'vs/base/common/event'; | ||
import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; | ||
import { ILogService } from 'vs/platform/log/common/log'; | ||
import { ExtHostContext, ExtHostSpeechShape, MainContext, MainThreadSpeechShape } from 'vs/workbench/api/common/extHost.protocol'; | ||
import { ISpeechProviderMetadata, ISpeechService, ISpeechToTextEvent } from 'vs/workbench/contrib/speech/common/speechService'; | ||
import { IExtHostContext, extHostNamedCustomer } from 'vs/workbench/services/extensions/common/extHostCustomers'; | ||
|
||
type SpeechToTextSession = { | ||
readonly onDidChange: Emitter<ISpeechToTextEvent>; | ||
}; | ||
|
||
@extHostNamedCustomer(MainContext.MainThreadSpeech) | ||
export class MainThreadSpeech extends Disposable implements MainThreadSpeechShape { | ||
|
||
private readonly proxy: ExtHostSpeechShape; | ||
|
||
private readonly providerRegistrations = new Map<number, IDisposable>(); | ||
private readonly providerSessions = new Map<number, SpeechToTextSession>(); | ||
|
||
constructor( | ||
extHostContext: IExtHostContext, | ||
@ISpeechService private readonly speechService: ISpeechService, | ||
@ILogService private readonly logService: ILogService | ||
) { | ||
super(); | ||
|
||
this.proxy = extHostContext.getProxy(ExtHostContext.ExtHostSpeech); | ||
} | ||
|
||
$registerProvider(handle: number, identifier: string, metadata: ISpeechProviderMetadata): void { | ||
this.logService.trace('[Speech] extension registered provider', metadata.extension.value); | ||
|
||
const registration = this.speechService.registerSpeechProvider(identifier, { | ||
metadata, | ||
createSpeechToTextSession: token => { | ||
const cts = new CancellationTokenSource(token); | ||
const session = Math.random(); | ||
|
||
this.proxy.$createSpeechToTextSession(handle, session, cts.token); | ||
|
||
const onDidChange = new Emitter<ISpeechToTextEvent>(); | ||
this.providerSessions.set(session, { onDidChange }); | ||
|
||
return { | ||
onDidChange: onDidChange.event, | ||
dispose: () => { | ||
cts.dispose(true); | ||
onDidChange.dispose(); | ||
this.providerSessions.delete(session); | ||
} | ||
}; | ||
} | ||
}); | ||
this.providerRegistrations.set(handle, { | ||
dispose: () => { | ||
registration.dispose(); | ||
} | ||
}); | ||
} | ||
|
||
$unregisterProvider(handle: number): void { | ||
const registration = this.providerRegistrations.get(handle); | ||
if (registration) { | ||
registration.dispose(); | ||
this.providerRegistrations.delete(handle); | ||
} | ||
} | ||
|
||
$emitSpeechToTextEvent(session: number, event: ISpeechToTextEvent): void { | ||
const providerSession = this.providerSessions.get(session); | ||
if (providerSession) { | ||
providerSession.onDidChange.fire(event); | ||
} | ||
} | ||
} |
Oops, something went wrong.