-
Notifications
You must be signed in to change notification settings - Fork 37.5k
chat: support sendToNewChat option and SendToNewChatAction delegation… #286767
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
Open
sandorsett
wants to merge
1
commit into
microsoft:main
Choose a base branch
from
sandorsett:feature/chat-send-to-new
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
106 changes: 106 additions & 0 deletions
106
src/vs/workbench/contrib/chat/test/browser/actions/sendToNewChat.test.ts
This file contains hidden or 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,106 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import assert from 'assert'; | ||
| import { workbenchInstantiationService } from '../../../../../test/browser/workbenchTestServices.js'; | ||
| import { SendToNewChatAction } from '../../../../browser/actions/chatExecuteActions.js'; | ||
| import { IChatWidget } from '../../../../browser/chat.js'; | ||
| import { DisposableStore } from '../../../../../../../base/common/lifecycle.js'; | ||
| import { ChatWidget } from '../../../../browser/widget/chatWidget.js'; | ||
|
|
||
| suite('SendToNewChatAction', () => { | ||
| let store: DisposableStore; | ||
|
|
||
| setup(() => { | ||
| store = new DisposableStore(); | ||
| }); | ||
|
|
||
| teardown(() => { | ||
| store.dispose(); | ||
| }); | ||
|
|
||
| test('delegates to widget.acceptInput with sendToNewChat option', async () => { | ||
| const insta = workbenchInstantiationService(undefined, store); | ||
| const action = new SendToNewChatAction(); | ||
|
|
||
| let capturedInput: string | undefined; | ||
| let capturedOptions: any | undefined; | ||
|
|
||
| const fakeWidget: Partial<IChatWidget> = { | ||
| getInput: () => 'hello', | ||
| acceptInput: async (input?: string, options?: any) => { | ||
| capturedInput = input; | ||
| capturedOptions = options; | ||
| return undefined as any; | ||
| } | ||
| }; | ||
|
|
||
| // call action with the widget provided in the context | ||
| await insta.invokeFunction(accessor => action.run(accessor, { widget: fakeWidget as IChatWidget })); | ||
|
|
||
| assert.strictEqual(capturedInput, 'hello'); | ||
| assert.ok(capturedOptions?.sendToNewChat, 'sendToNewChat option should be set'); | ||
| assert.strictEqual(capturedOptions?.storeToHistory, true, 'storeToHistory should be true'); | ||
| }); | ||
|
|
||
| test('does nothing when widget is not available', async () => { | ||
| const insta = workbenchInstantiationService(undefined, store); | ||
| const action = new SendToNewChatAction(); | ||
|
|
||
| // Should not throw | ||
| await insta.invokeFunction(accessor => action.run(accessor, undefined)); | ||
| }); | ||
|
|
||
| test('ChatWidget _acceptInput with sendToNewChat clears and sends to original session', async () => { | ||
| // Build a minimal fake 'this' that mirrors the fields used by _acceptInput | ||
| const sent: Array<{ session: string; message: string }> = []; | ||
| let cancelledSession: string | undefined; | ||
| let cleared = false; | ||
| let accessibilityAccepted: string | undefined; | ||
| let accessibilityDisposed: string | undefined; | ||
|
|
||
| const fakeThis: any = { | ||
| viewModel: { sessionResource: { toString: () => 'session:1' }, getItems: () => [] }, | ||
|
|
||
| getInput: () => 'editor text', | ||
| _applyPromptFileIfSet: async () => { }, | ||
| _autoAttachInstructions: async () => { }, | ||
| chatService: { | ||
| sendRequest: async (session: any, message: string) => { | ||
| sent.push({ session: session.toString ? session.toString() : String(session), message }); | ||
| return { | ||
| responseCompletePromise: Promise.resolve(), | ||
| responseCreatedPromise: Promise.resolve({}), | ||
| agent: {} | ||
| }; | ||
| }, | ||
| cancelCurrentRequestForSession: (s: any) => { cancelledSession = s.toString ? s.toString() : String(s); } | ||
| }, | ||
| chatAccessibilityService: { | ||
| acceptRequest: (s: any) => { accessibilityAccepted = s.toString ? s.toString() : String(s); }, | ||
| disposeRequest: (s: any) => { accessibilityDisposed = s.toString ? s.toString() : String(s); }, | ||
| acceptResponse: () => { /* noop */ } | ||
| }, | ||
| currentRequest: undefined, | ||
| clear: async () => { cleared = true; }, | ||
| handleDelegationExitIfNeeded: async () => { /* noop */ }, | ||
| viewOptions: {}, | ||
| _location: { resolveData: () => undefined }, | ||
| input: { currentLanguageModel: undefined, currentModeKind: undefined, getAttachedContext: () => ({ asArray: () => [] }), getAttachedAndImplicitContext: () => ({ asArray: () => [] }), acceptInput: () => { /* noop */ } }, | ||
| getModeRequestOptions: () => ({}), | ||
| updateChatViewVisibility: () => { /* noop */ }, | ||
| }; | ||
|
|
||
| // Call private method | ||
| await (ChatWidget as any).prototype._acceptInput.call(fakeThis, { query: 'my request' }, { sendToNewChat: true }); | ||
|
|
||
| assert.strictEqual(cancelledSession, 'session:1'); | ||
| assert.strictEqual(cleared, true); | ||
| assert.strictEqual(sent.length, 1); | ||
| assert.strictEqual(sent[0].session, 'session:1'); | ||
| assert.strictEqual(sent[0].message, 'my request'); | ||
| assert.strictEqual(accessibilityAccepted, 'session:1'); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this name backwards? It's not sending to a new chat, it's sending to the current chat then opening a new chat... I will have to think of a catchy name