From 0bc8e4ff29dc2f25f95d16fecf89fe65051a652e Mon Sep 17 00:00:00 2001 From: Beatrix Date: Fri, 27 Dec 2024 11:00:28 -0800 Subject: [PATCH] rename steps to processes --- .../SerializedChatMessage.kt | 2 +- lib/shared/src/chat/transcript/index.ts | 2 +- lib/shared/src/chat/transcript/messages.ts | 4 +- vscode/src/chat/agentic/CodyChatAgent.ts | 2 +- vscode/src/chat/agentic/ProcessManager.ts | 18 ++-- vscode/src/chat/chat-view/ChatBuilder.ts | 17 +--- .../src/chat/chat-view/ChatController.test.ts | 28 +++--- vscode/webviews/chat/Transcript.tsx | 2 +- .../cells/contextCell/ContextCell.story.tsx | 4 +- .../chat/cells/contextCell/ContextCell.tsx | 90 ++++++++++--------- 10 files changed, 83 insertions(+), 86 deletions(-) diff --git a/agent/bindings/kotlin/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/SerializedChatMessage.kt b/agent/bindings/kotlin/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/SerializedChatMessage.kt index c7167ecafc49..bdac4dfb10ff 100644 --- a/agent/bindings/kotlin/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/SerializedChatMessage.kt +++ b/agent/bindings/kotlin/lib/src/main/kotlin/com/sourcegraph/cody/agent/protocol_generated/SerializedChatMessage.kt @@ -13,7 +13,7 @@ data class SerializedChatMessage( val intent: IntentEnum? = null, // Oneof: search, chat, edit, insert val manuallySelectedIntent: ManuallySelectedIntentEnum? = null, // Oneof: search, chat, edit, insert val search: Any? = null, - val steps: List<>? = null, + val processes: List<>? = null, ) { enum class SpeakerEnum { diff --git a/lib/shared/src/chat/transcript/index.ts b/lib/shared/src/chat/transcript/index.ts index bb36eadaf449..8d3a0ecb6f7f 100644 --- a/lib/shared/src/chat/transcript/index.ts +++ b/lib/shared/src/chat/transcript/index.ts @@ -34,6 +34,6 @@ export function serializeChatMessage(chatMessage: ChatMessage): SerializedChatMe intent: chatMessage.intent, manuallySelectedIntent: chatMessage.manuallySelectedIntent, search: chatMessage.search, - steps: chatMessage.steps, + processes: chatMessage.processes, } } diff --git a/lib/shared/src/chat/transcript/messages.ts b/lib/shared/src/chat/transcript/messages.ts index b046bb2b4f4d..c208f4f56238 100644 --- a/lib/shared/src/chat/transcript/messages.ts +++ b/lib/shared/src/chat/transcript/messages.ts @@ -39,7 +39,7 @@ export interface ChatMessage extends Message { intent?: 'search' | 'chat' | 'edit' | 'insert' | undefined | null manuallySelectedIntent?: 'search' | 'chat' | 'edit' | 'insert' | undefined | null search?: ChatMessageSearch | undefined | null - steps?: ProcessingStep[] | undefined | null + processes?: ProcessingStep[] | undefined | null } /** @@ -101,7 +101,7 @@ export interface SerializedChatMessage { intent?: ChatMessage['intent'] manuallySelectedIntent?: ChatMessage['manuallySelectedIntent'] search?: ChatMessage['search'] - steps?: ChatMessage['steps'] + processes?: ChatMessage['processes'] } export interface ChatError { diff --git a/vscode/src/chat/agentic/CodyChatAgent.ts b/vscode/src/chat/agentic/CodyChatAgent.ts index 764a79295a66..03e71241cf39 100644 --- a/vscode/src/chat/agentic/CodyChatAgent.ts +++ b/vscode/src/chat/agentic/CodyChatAgent.ts @@ -92,7 +92,7 @@ export abstract class CodyChatAgent { // Create a steps manager to handle state updates efficiently const stepsManager = new ProcessManager(steps => { - this.chatBuilder.setLastMessageSteps(steps) + this.chatBuilder.setLastMessageProcesses(steps) this.postMessageCallback?.(model) }) diff --git a/vscode/src/chat/agentic/ProcessManager.ts b/vscode/src/chat/agentic/ProcessManager.ts index c30dab3b7a12..9fe91fc4abd3 100644 --- a/vscode/src/chat/agentic/ProcessManager.ts +++ b/vscode/src/chat/agentic/ProcessManager.ts @@ -1,12 +1,12 @@ import { type ProcessingStep, errorToChatError } from '@sourcegraph/cody-shared' export class ProcessManager { - private steps: ProcessingStep[] = [] + private processes: ProcessingStep[] = [] - constructor(private readonly onChange: (steps: ProcessingStep[]) => void) {} + constructor(private readonly onChange: (processes: ProcessingStep[]) => void) {} public initializeStep(): void { - this.steps = [ + this.processes = [ { content: '', id: '', @@ -18,10 +18,10 @@ export class ProcessManager { } public addStep(toolName: string, content: string): void { - this.steps.push({ + this.processes.push({ content, id: toolName, - step: this.steps.length, + step: this.processes.length, status: 'pending', }) this.notifyChange() @@ -30,7 +30,7 @@ export class ProcessManager { public completeStep(toolName?: string, error?: Error): void { if (toolName) { // Update specific tool - this.steps = this.steps.map(step => + this.processes = this.processes.map(step => step.id === toolName ? { ...step, @@ -40,8 +40,8 @@ export class ProcessManager { : step ) } else { - // Complete all pending steps - this.steps = this.steps.map(step => ({ + // Complete all pending processes + this.processes = this.processes.map(step => ({ ...step, status: step.status === 'error' ? step.status : 'success', })) @@ -50,6 +50,6 @@ export class ProcessManager { } private notifyChange(): void { - this.onChange(this.steps) + this.onChange(this.processes) } } diff --git a/vscode/src/chat/chat-view/ChatBuilder.ts b/vscode/src/chat/chat-view/ChatBuilder.ts index 170a8a76f89d..ffd1ef410ffb 100644 --- a/vscode/src/chat/chat-view/ChatBuilder.ts +++ b/vscode/src/chat/chat-view/ChatBuilder.ts @@ -224,26 +224,15 @@ export class ChatBuilder { this.changeNotifications.next() } - public getLastMessageSteps(): ProcessingStep[] | undefined { + public setLastMessageProcesses(processes: ProcessingStep[]): void { const lastMessage = this.messages.at(-1) if (!lastMessage) { throw new Error('no last message') } if (lastMessage.speaker !== 'human') { - throw new Error('Cannot set steps for bot message') + throw new Error('Cannot set processes for bot message') } - return lastMessage.steps || undefined - } - - public setLastMessageSteps(steps: ProcessingStep[]): void { - const lastMessage = this.messages.at(-1) - if (!lastMessage) { - throw new Error('no last message') - } - if (lastMessage.speaker !== 'human') { - throw new Error('Cannot set steps for bot message') - } - lastMessage.steps = steps + lastMessage.processes = processes this.changeNotifications.next() } diff --git a/vscode/src/chat/chat-view/ChatController.test.ts b/vscode/src/chat/chat-view/ChatController.test.ts index af7d14aeacda..0b3df5c6164e 100644 --- a/vscode/src/chat/chat-view/ChatController.test.ts +++ b/vscode/src/chat/chat-view/ChatController.test.ts @@ -147,7 +147,7 @@ describe('ChatController', () => { error: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -159,7 +159,7 @@ describe('ChatController', () => { editorState: undefined, text: undefined, contextFiles: undefined, - steps: undefined, + processes: undefined, }, ], }) @@ -184,7 +184,7 @@ describe('ChatController', () => { search: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -196,7 +196,7 @@ describe('ChatController', () => { text: 'Test reply 1', search: undefined, contextFiles: undefined, - steps: undefined, + processes: undefined, }, ], }) @@ -237,7 +237,7 @@ describe('ChatController', () => { search: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -249,7 +249,7 @@ describe('ChatController', () => { text: 'Test reply 1', search: undefined, contextFiles: undefined, - steps: undefined, + processes: undefined, }, { speaker: 'human', @@ -261,7 +261,7 @@ describe('ChatController', () => { error: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -273,7 +273,7 @@ describe('ChatController', () => { text: 'Test reply 2', contextFiles: undefined, search: undefined, - steps: undefined, + processes: undefined, }, ], }) @@ -313,7 +313,7 @@ describe('ChatController', () => { search: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -325,7 +325,7 @@ describe('ChatController', () => { text: 'Test reply 1', search: undefined, contextFiles: undefined, - steps: undefined, + processes: undefined, }, { speaker: 'human', @@ -337,7 +337,7 @@ describe('ChatController', () => { error: undefined, editorState: null, contextFiles: [], - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -349,7 +349,7 @@ describe('ChatController', () => { editorState: undefined, text: 'Test reply 3', contextFiles: undefined, - steps: undefined, + processes: undefined, }, ], }) @@ -398,7 +398,7 @@ describe('ChatController', () => { intent: 'chat', manuallySelectedIntent: undefined, search: undefined, - steps: undefined, + processes: undefined, }, { speaker: 'assistant', @@ -410,7 +410,7 @@ describe('ChatController', () => { text: undefined, contextFiles: undefined, search: undefined, - steps: undefined, + processes: undefined, }, ], }) diff --git a/vscode/webviews/chat/Transcript.tsx b/vscode/webviews/chat/Transcript.tsx index 9b66b38dac5e..a39498be469b 100644 --- a/vscode/webviews/chat/Transcript.tsx +++ b/vscode/webviews/chat/Transcript.tsx @@ -645,7 +645,7 @@ const TranscriptInteraction: FC = memo(props => { assistantMessage?.model?.includes('deep-cody') && humanMessage.index < 3 } // Open the context cell for the first 2 human messages when Deep Cody is run. - steps={humanMessage?.steps ?? undefined} + processes={humanMessage?.processes ?? undefined} /> )} {assistantMessage && !isContextLoading && ( diff --git a/vscode/webviews/chat/cells/contextCell/ContextCell.story.tsx b/vscode/webviews/chat/cells/contextCell/ContextCell.story.tsx index 33271e207ea8..c26ee9a95c3d 100644 --- a/vscode/webviews/chat/cells/contextCell/ContextCell.story.tsx +++ b/vscode/webviews/chat/cells/contextCell/ContextCell.story.tsx @@ -175,7 +175,7 @@ export const WithSteps: Story = { contextItems: [{ type: 'file', uri: URI.file('/foo/bar.go') }], isForFirstMessage: true, model: 'deep-cody', - steps: [ + processes: [ { id: 'Code Search', status: 'success', @@ -201,7 +201,7 @@ export const LoadingWithSteps: Story = { contextItems: [{ type: 'file', uri: URI.file('/foo/bar.go') }], isForFirstMessage: true, model: 'deep-cody', - steps: [ + processes: [ { id: 'Code Search', status: 'success', diff --git a/vscode/webviews/chat/cells/contextCell/ContextCell.tsx b/vscode/webviews/chat/cells/contextCell/ContextCell.tsx index a755544369f8..016965948834 100644 --- a/vscode/webviews/chat/cells/contextCell/ContextCell.tsx +++ b/vscode/webviews/chat/cells/contextCell/ContextCell.tsx @@ -65,7 +65,7 @@ export const ContextCell: FunctionComponent<{ onManuallyEditContext: () => void editContextNode: React.ReactNode experimentalOneBoxEnabled?: boolean - steps?: ProcessingStep[] + processes?: ProcessingStep[] }> = memo( ({ contextItems, @@ -81,7 +81,7 @@ export const ContextCell: FunctionComponent<{ editContextNode, intent, experimentalOneBoxEnabled, - steps, + processes, }) => { const __storybook__initialOpen = useContext(__ContextCellStorybookContext)?.initialOpen ?? false @@ -187,7 +187,7 @@ export const ContextCell: FunctionComponent<{ onClick={triggerAccordion} title={itemCountLabel} className="tw-flex tw-items-center tw-gap-4" - disabled={isContextLoading && steps === undefined} + disabled={isContextLoading && processes === undefined} > {isDeepCodyEnabled && ( - )} @@ -309,31 +309,35 @@ export const ContextCell: FunctionComponent<{ )} - {!isContextLoading && isDeepCodyEnabled && steps?.length && ( -
  • - - - - - Reviewed by context agent - - - - Deep Cody fetches additional context to - improve response quality when needed - - -
  • - )} - {!isContextLoading && !steps?.length && ( + {!isContextLoading && + isDeepCodyEnabled && + processes?.length && ( +
  • + + + + + + Reviewed by context agent + + + + + Deep Cody fetches additional context to + improve response quality when needed + + +
  • + )} + {!isContextLoading && !processes?.length && (
  • @@ -446,15 +450,19 @@ export const EditContextButtonChat = ( ) -const ProcessingStepList: FC<{ steps: ProcessingStep[]; isContextLoading: boolean }> = ({ - steps, +const ProcessList: FC<{ processes: ProcessingStep[]; isContextLoading: boolean }> = ({ + processes, isContextLoading, }) => { return (
    - {steps.map(step => ( - + {processes.map(process => ( + ))}
    {isContextLoading && ( @@ -469,11 +477,11 @@ const ProcessingStepList: FC<{ steps: ProcessingStep[]; isContextLoading: boolea ) } -const ProcessingStepItem: FC<{ step: ProcessingStep; isContextLoading: boolean }> = ({ - step, +const ProcessItem: FC<{ process: ProcessingStep; isContextLoading: boolean }> = ({ + process, isContextLoading, }) => { - if (!step.id && !step.content) { + if (!process.id && !process.content) { return null } @@ -481,13 +489,13 @@ const ProcessingStepItem: FC<{ step: ProcessingStep; isContextLoading: boolean }
    - {step.status === 'pending' && isContextLoading ? ( + {process.status === 'pending' && isContextLoading ? ( - ) : step.status === 'error' ? ( + ) : process.status === 'error' ? (
    - Running {step.id} + Running {process.id}...
    - {step.content} + {process.content}