Merge pull request #384 from voideditor/model-selection

Model selection
This commit is contained in:
Andrew Pareles 2025-04-09 16:57:59 -07:00 committed by GitHub
commit 8a8a982d21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 9 deletions

View file

@ -654,10 +654,12 @@ const defaultChat = {
submenu: MenuId.ChatTitleBarMenu,
title: localize('title4', "Copilot"),
icon: Codicon.copilot,
when: ContextKeyExpr.and(
ChatContextKeys.supported,
ContextKeyExpr.has('config.chat.commandCenter.enabled')
),
// Void commented this out - copilot head
when: ContextKeyExpr.false(),
// when: ContextKeyExpr.and(
// ChatContextKeys.supported,
// ContextKeyExpr.has('config.chat.commandCenter.enabled')
// ),
order: 10001 // to the right of command center
});
@ -667,11 +669,13 @@ MenuRegistry.appendMenuItem(MenuId.TitleBar, {
title: localize('title4', "Copilot"),
group: 'navigation',
icon: Codicon.copilot,
when: ContextKeyExpr.and(
ChatContextKeys.supported,
ContextKeyExpr.has('config.chat.commandCenter.enabled'),
ContextKeyExpr.has('config.window.commandCenter').negate(),
),
when: ContextKeyExpr.false(),
// Void commented this out - copilot head
// when: ContextKeyExpr.and(
// ChatContextKeys.supported,
// ContextKeyExpr.has('config.chat.commandCenter.enabled'),
// ContextKeyExpr.has('config.window.commandCenter').negate(),
// ),
order: 1
}); */

View file

@ -661,6 +661,7 @@ class ChatThreadService extends Disposable implements IChatThreadService {
// above just defines helpers, below starts the actual function
const { chatMode } = this._settingsService.state.globalSettings // should not change as we loop even if user changes it, so it goes here
console.log('a', chatMode)
// clear any previous error
this._setStreamState(threadId, { error: undefined }, 'set')
@ -669,11 +670,13 @@ class ChatThreadService extends Disposable implements IChatThreadService {
let isRunningWhenEnd: IsRunningType = undefined
let aborted = false
console.log('b')
// before enter loop, call tool
if (callThisToolFirst) {
const { interrupted } = await this._runToolCall(threadId, callThisToolFirst.name, { preapproved: true, validatedParams: callThisToolFirst.params })
if (interrupted) return
}
console.log('c')
// tool use loop
while (shouldSendAnotherMessage) {
@ -685,14 +688,17 @@ class ChatThreadService extends Disposable implements IChatThreadService {
let resMessageIsDonePromise: (toolCall?: RawToolCallObj | undefined) => void // resolves when user approves this tool use (or if tool doesn't require approval)
const messageIsDonePromise = new Promise<RawToolCallObj | undefined>((res, rej) => { resMessageIsDonePromise = res })
console.log('d')
// send llm message
this._setStreamState(threadId, { isRunning: 'LLM' }, 'merge')
const systemMessage = await this._generateSystemMessage(chatMode)
console.log('e0')
const llmMessages = await this._generateLLMMessages(threadId)
const messages: LLMChatMessage[] = [
{ role: 'system', content: systemMessage },
...llmMessages
]
console.log('e')
const llmCancelToken = this._llmMessageService.sendLLMMessage({
messagesType: 'chatMessages',
@ -734,14 +740,20 @@ class ChatThreadService extends Disposable implements IChatThreadService {
break
}
this._setStreamState(threadId, { streamingToken: llmCancelToken }, 'merge') // new stream token for the new message
console.log('waiting...')
const toolCall = await messageIsDonePromise // wait for message to complete
console.log('done!')
if (aborted) { return }
console.log('H')
this._setStreamState(threadId, { streamingToken: undefined }, 'merge') // streaming message is done
console.log('I')
// call tool if there is one
const tool: RawToolCallObj | undefined = toolCall
if (tool) {
console.log('J')
const { awaitingUserApproval, interrupted } = await this._runToolCall(threadId, tool.name, { preapproved: false, unvalidatedToolParams: tool.rawParams })
console.log('K')
// stop if interrupted. we don't have to do this for llmMessage because we have a stream token for it and onAbort gets called, but we don't have the equivalent for tools.
// just detect tool interruption which is the same as chat interruption right now
@ -756,14 +768,17 @@ class ChatThreadService extends Disposable implements IChatThreadService {
}
} // end while
console.log('L')
// if awaiting user approval, keep isRunning true, else end isRunning
this._setStreamState(threadId, { isRunning: isRunningWhenEnd }, 'merge')
console.log('M')
// add checkpoint before the next user message
if (!isRunningWhenEnd)
this._addUserCheckpoint({ threadId })
console.log('N')
// capture number of messages sent
this._metricsService.capture('Agent Loop Done', { nMessagesSent, chatMode })