merge updates

This commit is contained in:
Andrew Pareles 2025-02-18 16:12:16 -08:00
parent 9ab9196b38
commit 5699cf19f4
6 changed files with 35 additions and 12 deletions

View file

@ -42,6 +42,7 @@ import { ILLMMessageService } from '../common/llmMessageService.js';
import { LLMChatMessage, errorDetails } from '../common/llmMessageTypes.js';
import { IMetricsService } from '../common/metricsService.js';
import { VSReadFile } from './helpers/readFile.js';
import { IFileService } from '../../../../platform/files/common/files.js';
const configOfBG = (color: Color) => {
return { dark: color, light: color, hcDark: color, hcLight: color, }
@ -254,6 +255,7 @@ class EditCodeService extends Disposable implements IEditCodeService {
@IMetricsService private readonly _metricsService: IMetricsService,
@INotificationService private readonly _notificationService: INotificationService,
@ICommandService private readonly _commandService: ICommandService,
@IFileService private readonly _fileService: IFileService,
) {
super();

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------*/
import { ChatMessage } from '../browser/chatThreadService.js'
import { InternalToolInfo } from './toolsService.js'
import { InternalToolInfo, ToolName } from './toolsService.js'
import { FeatureName, ProviderName, SettingsOfProvider } from './voidSettingsTypes.js'
@ -37,15 +37,16 @@ export type LLMChatMessage = {
id: string;
}
export type LLMToolCallType = {
name: string;
export type ToolCallType = {
name: ToolName;
params: string;
id: string;
}
export type OnText = (p: { newText: string, fullText: string }) => void
export type OnFinalMessage = (p: { fullText: string, toolCalls?: LLMToolCallType[] }) => void // id is tool_use_id
export type OnFinalMessage = (p: { fullText: string, toolCalls?: ToolCallType[] }) => void // id is tool_use_id
export type OnError = (p: { message: string, fullError: Error | null }) => void
export type AbortRef = { current: (() => void) | null }

View file

@ -8,6 +8,7 @@ import { _InternalSendLLMChatMessageFnType } from '../../common/llmMessageTypes.
import { anthropicMaxPossibleTokens, developerInfoOfModelName, developerInfoOfProviderName } from '../../common/voidSettingsTypes.js';
import { InternalToolInfo } from '../../common/toolsService.js';
import { addSystemMessageAndToolSupport } from './preprocessLLMMessages.js';
import { isAToolName } from './postprocessToolCalls.js';
@ -86,7 +87,13 @@ export const sendAnthropicChat: _InternalSendLLMChatMessageFnType = ({ messages:
stream.on('finalMessage', (response) => {
// stringify the response's content
const content = response.content.map(c => c.type === 'text' ? c.text : '').join('\n\n')
const toolCalls = response.content.map(c => c.type === 'tool_use' ? { name: c.name, params: JSON.stringify(c.input), id: c.id } : null).filter(c => !!c)
const toolCalls = response.content
.map(c => {
if (c.type !== 'tool_use') return null
if (!isAToolName(c.name)) return null
return c.type === 'tool_use' ? { name: c.name, params: JSON.stringify(c.input), id: c.id } : null
})
.filter(t => !!t)
onFinalMessage({ fullText: content, toolCalls })
})

View file

@ -9,6 +9,7 @@ import { Model } from 'openai/resources/models.js';
import { InternalToolInfo } from '../../common/toolsService.js';
import { addSystemMessageAndToolSupport } from './preprocessLLMMessages.js';
import { developerInfoOfModelName, developerInfoOfProviderName } from '../../common/voidSettingsTypes.js';
import { isAToolName } from './postprocessToolCalls.js';
// import { parseMaxTokensStr } from './util.js';
@ -205,10 +206,15 @@ export const sendOpenAIChat: _InternalSendLLMChatMessageFnType = ({ messages: me
onText({ newText, fullText });
}
onFinalMessage({
fullText, toolCalls: Object.keys(toolCallOfIndex).map(index => {
const tool = toolCallOfIndex[index]
return { name: tool.name, id: tool.id, params: tool.params }
})
fullText,
toolCalls: Object.keys(toolCallOfIndex)
.map(index => {
const tool = toolCallOfIndex[index]
if (isAToolName(tool.name))
return { name: tool.name, id: tool.id, params: tool.params }
return null
})
.filter(t => !!t)
});
})
// when error/fail - this catches errors of both .create() and .then(for await)

View file

@ -0,0 +1,10 @@
import { ToolName, toolNames } from '../../common/toolsService';
const toolNamesSet = new Set<string>(toolNames)
export const isAToolName = (toolName: string): toolName is ToolName => {
const isAToolName = toolNamesSet.has(toolName)
return isAToolName
}

View file

@ -262,9 +262,6 @@ export const addSystemMessageAndToolSupport = (modelName: string, providerName:
/*