Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ChatSubmitType user-newchat #5792

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion agent/src/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ export class TestClient extends MessageHandler {
message: {
command: 'submit',
text,
submitType: 'user',
contextItems: params?.contextFiles,
},
})
Expand Down
12 changes: 5 additions & 7 deletions agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import * as uuid from 'uuid'
import type { MessageConnection } from 'vscode-jsonrpc'
import type { CommandResult } from '../../vscode/src/CommandResult'
import { formatURL } from '../../vscode/src/auth/auth'
import { executeExplainCommand, executeSmellCommand } from '../../vscode/src/commands/execute'
import type { CodyCommandArgs } from '../../vscode/src/commands/types'
import { loadTscRetriever } from '../../vscode/src/completions/context/retrievers/tsc/load-tsc-retriever'
import { supportedTscLanguages } from '../../vscode/src/completions/context/retrievers/tsc/supportedTscLanguages'
import type { CompletionItemID } from '../../vscode/src/completions/logger'
Expand Down Expand Up @@ -1099,12 +1101,10 @@ export class Agent extends MessageHandler implements ExtensionClient {
})

// The arguments to pass to the command to make sure edit commands would also run in chat mode
const commandArgs = [{ source: 'editor' }]
const commandArgs: Partial<CodyCommandArgs> = { source: 'editor' }

this.registerAuthenticatedRequest('commands/explain', () => {
return this.createChatPanel(
vscode.commands.executeCommand('cody.command.explain-code', commandArgs)
)
return this.createChatPanel(executeExplainCommand(commandArgs))
})

this.registerAuthenticatedRequest('editTask/accept', async ({ id }) => {
Expand Down Expand Up @@ -1196,9 +1196,7 @@ export class Agent extends MessageHandler implements ExtensionClient {
})

this.registerAuthenticatedRequest('commands/smell', () => {
return this.createChatPanel(
vscode.commands.executeCommand('cody.command.smell-code', commandArgs)
)
return this.createChatPanel(executeSmellCommand(commandArgs))
})

this.registerAuthenticatedRequest('commands/custom', ({ key }) => {
Expand Down
1 change: 0 additions & 1 deletion agent/src/cli/command-bench/strategy-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function evaluateChatStrategy(
id,
message: {
command: 'submit',
submitType: 'user',
text: task.question,
contextItems,
},
Expand Down
1 change: 0 additions & 1 deletion agent/src/cli/command-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ export async function chatAction(options: ChatOptions): Promise<number> {
id,
message: {
command: 'submit',
submitType: 'user',
text: messageText,
contextItems,
},
Expand Down
4 changes: 0 additions & 4 deletions agent/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'My name is Lars Monsen.',
submitType: 'user',
},
})
)
Expand All @@ -284,7 +283,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What is my name?',
submitType: 'user',
},
})
)
Expand Down Expand Up @@ -315,7 +313,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What model are you?',
submitType: 'user',
},
})
)
Expand All @@ -332,7 +329,6 @@ describe('Agent', () => {
message: {
command: 'submit',
text: 'What model are you?',
submitType: 'user',
},
})
)
Expand Down
11 changes: 0 additions & 11 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ import type { ChatIntentAPIClient } from '../context/chatIntentAPIClient'
import { observeInitialContext } from '../initialContext'
import {
CODY_BLOG_URL_o1_WAITLIST,
type ChatSubmitType,
type ConfigurationSubsetForWebview,
type ExtensionMessage,
type LocalEnv,
Expand Down Expand Up @@ -272,7 +271,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
await this.handleUserMessageSubmission({
requestID: uuid.v4(),
inputText: PromptString.unsafe_fromUserQuery(message.text),
submitType: message.submitType,
mentions: message.contextItems ?? [],
editorState: message.editorState as SerializedPromptEditorState,
signal: this.startNewSubmitOrEditOperation(),
Expand Down Expand Up @@ -592,7 +590,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
public async handleUserMessageSubmission({
requestID,
inputText,
submitType,
mentions,
editorState,
signal,
Expand All @@ -604,7 +601,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
}: {
requestID: string
inputText: PromptString
submitType: ChatSubmitType
mentions: ContextItem[]
editorState: SerializedPromptEditorState | null
signal: AbortSignal
Expand Down Expand Up @@ -661,12 +657,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return this.clearAndRestartSession()
}

if (submitType === 'user-newchat' && !this.chatBuilder.isEmpty()) {
span.addEvent('clearAndRestartSession')
await this.clearAndRestartSession()
signal.throwIfAborted()
}

this.chatBuilder.addHumanMessage({
text: inputText,
editorState,
Expand Down Expand Up @@ -992,7 +982,6 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
return await this.handleUserMessageSubmission({
requestID,
inputText: text,
submitType: 'user',
mentions: contextFiles,
editorState,
signal: abortSignal,
Expand Down
5 changes: 2 additions & 3 deletions vscode/src/chat/chat-view/ChatsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,23 @@ export class ChatsController implements vscode.Disposable {
*/
private async submitChat({
text,
submitType,
contextItems,
source = DEFAULT_EVENT_SOURCE,
command,
}: ExecuteChatArguments): Promise<ChatSession | undefined> {
let provider: ChatController
// If the sidebar panel is visible and empty, use it instead of creating a new panel
if (submitType === 'user-newchat' && this.panel.isVisible() && this.panel.isEmpty()) {
if (this.panel.isVisible() && this.panel.isEmpty()) {
provider = this.panel
} else {
provider = await this.getOrCreateEditorChatController()
}
await provider.clearAndRestartSession()
const abortSignal = provider.startNewSubmitOrEditOperation()
const editorState = editorStateFromPromptString(text)
await provider.handleUserMessageSubmission({
requestID: uuid.v4(),
inputText: text,
submitType,
mentions: contextItems ?? [],
editorState,
signal: abortSignal,
Expand Down
8 changes: 0 additions & 8 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,8 @@ interface ExtensionAttributionMessage {
error?: string | undefined | null
}

/**
* ChatSubmitType represents the type of chat submission.
* - 'user': The user starts a new chat panel.
* - 'user-newchat': The user reuses the current chat panel.
*/
export type ChatSubmitType = 'user' | 'user-newchat'

export interface WebviewSubmitMessage extends WebviewContextMessage {
text: string
submitType: ChatSubmitType

/** An opaque value representing the text editor's state. @see {ChatMessage.editorState} */
editorState?: unknown | undefined | null
Expand Down
1 change: 0 additions & 1 deletion vscode/src/code-actions/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class ExplainCodeAction implements vscode.CodeActionProvider {
{
text: instruction,
source: 'code-action:explain',
submitType: 'user-newchat',
} satisfies ExecuteChatArguments,
],
title: 'Ask Cody to Explain',
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ async function docChatCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Doc,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/explain-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async function explainHistoryCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/explain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export async function explainCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Explain,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/smell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ async function smellCommand(

return {
text: prompt,
submitType: 'user-newchat',
contextItems,
source: args?.source,
command: DefaultChatCommands.Smell,
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export async function executeExplainOutput(
type: 'chat',
session: await executeChat({
text: prompt,
submitType: 'user-newchat',
contextItems: [],
source,
}),
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/execute/test-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ async function unitTestCommand(
text: prompt,
contextItems,
source: args?.source,
submitType: 'user-newchat',
command: DefaultChatCommands.Test,
}
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/menus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export async function showCommandMenu(
} else {
void executeChat({
text: value.trim(),
submitType: 'user-newchat',
source,
})
}
Expand Down
1 change: 0 additions & 1 deletion vscode/src/commands/services/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class CommandRunner implements vscode.Disposable {
type: 'chat',
session: await executeChat({
text: prompt,
submitType: 'user',
contextItems,
source: 'custom-commands',
command: DefaultChatCommands.Custom,
Expand Down
2 changes: 0 additions & 2 deletions vscode/test/integration/single-root/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ suite('Chat', function () {
await chatView.handleUserMessageSubmission({
requestID: 'test',
inputText: getPs()`hello from the human`,
submitType: 'user',
mentions: [],
editorState: null,
signal: new AbortController().signal,
Expand All @@ -55,7 +54,6 @@ suite('Chat', function () {
await chatView.handleUserMessageSubmission({
requestID: 'test',
inputText: getPs()`hello from the human`,
submitType: 'user',
mentions: [],
editorState: null,
signal: new AbortController().signal,
Expand Down
1 change: 0 additions & 1 deletion vscode/webviews/chat/Transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ function submitHumanMessage({
}): void {
getVSCodeAPI().postMessage({
command: 'submit',
submitType: 'user',
text: editorValue.text,
editorState: editorValue.editorState,
contextItems: editorValue.contextItems.map(deserializeContextItem),
Expand Down
Loading