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

feat(ui): llm conversation about error #34750

Merged
merged 38 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9dc816f
feat(ui): llm conversation about error
Skn0tt Feb 12, 2025
75c239b
implement proper sse
Skn0tt Feb 13, 2025
4708672
merge llm files
Skn0tt Feb 13, 2025
9bc2c28
move into cookies
Skn0tt Feb 13, 2025
e08c0cf
move into utils
Skn0tt Feb 13, 2025
5a796fd
also support in trace viewer
Skn0tt Feb 13, 2025
9039c59
strip header
Skn0tt Feb 13, 2025
2d11c29
more
Skn0tt Feb 13, 2025
8e562bb
types
Skn0tt Feb 13, 2025
6662cfc
sticky input
Skn0tt Feb 13, 2025
1388043
give each error own button state
Skn0tt Feb 13, 2025
6e910d9
toggle
Skn0tt Feb 13, 2025
a3f2984
more
Skn0tt Feb 13, 2025
e6b81d8
Merge branch 'main' into ai-error-conversation
Skn0tt Feb 13, 2025
a91775e
fix aborting
Skn0tt Feb 13, 2025
3cbd591
key on walltime
Skn0tt Feb 13, 2025
c58566c
more
Skn0tt Feb 13, 2025
30d3291
more
Skn0tt Feb 13, 2025
3a8ba54
rewrite first
Skn0tt Feb 13, 2025
956a66a
migrate second
Skn0tt Feb 13, 2025
37d842c
remove experimental
Skn0tt Feb 13, 2025
7967e6a
lint
Skn0tt Feb 13, 2025
554ef49
add divider
Skn0tt Feb 13, 2025
8af86e4
stable
Skn0tt Feb 14, 2025
a142e9e
Merge branch 'main' into ai-error-conversation
Skn0tt Feb 14, 2025
d6ece15
regen package-lock
Skn0tt Feb 14, 2025
7d93780
another try
Skn0tt Feb 14, 2025
6ac8641
another try
Skn0tt Feb 14, 2025
fa81f6f
fix package
Skn0tt Feb 14, 2025
366fde1
lint
Skn0tt Feb 14, 2025
11cd84f
make chat creation explicit
Skn0tt Feb 14, 2025
98a2202
more refactoring
Skn0tt Feb 14, 2025
5890b03
use smaller library
Skn0tt Feb 14, 2025
6ac45df
remove unused import
Skn0tt Feb 14, 2025
7aed043
update test
Skn0tt Feb 14, 2025
fe50345
fix deps checker
Skn0tt Feb 14, 2025
6ee931c
apply feedback
Skn0tt Feb 14, 2025
2005471
fix package-lock
Skn0tt Feb 14, 2025
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
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"formidable": "^2.1.1",
"immutable": "^4.3.7",
"license-checker": "^25.0.1",
"markdown-to-jsx": "^7.7.3",
"mime": "^3.0.0",
"node-stream-zip": "^1.15.0",
"react": "^18.1.0",
Expand Down
10 changes: 10 additions & 0 deletions packages/playwright-core/src/server/trace/viewer/traceViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
server.routePath('/', (_, response) => {
response.statusCode = 302;
response.setHeader('Location', urlPath);

if (process.env.OPENAI_API_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to not work with PW_HMR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me follow up on that

response.appendHeader('Set-Cookie', `openai_api_key=${process.env.OPENAI_API_KEY}`);
if (process.env.OPENAI_BASE_URL)
response.appendHeader('Set-Cookie', `openai_base_url=${process.env.OPENAI_BASE_URL}`);
if (process.env.ANTHROPIC_API_KEY)
response.appendHeader('Set-Cookie', `anthropic_api_key=${process.env.ANTHROPIC_API_KEY}`);
if (process.env.ANTHROPIC_BASE_URL)
response.appendHeader('Set-Cookie', `anthropic_base_url=${process.env.ANTHROPIC_BASE_URL}`);

response.end();
return true;
});
Expand Down
6 changes: 6 additions & 0 deletions packages/trace-viewer/src/sw/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ async function doFetch(event: FetchEvent): Promise<Response> {
if (event.request.url.startsWith('chrome-extension://'))
return fetch(event.request);

if (event.request.headers.get('x-pw-serviceworker') === 'forward') {
const request = new Request(event.request);
request.headers.delete('x-pw-serviceworker');
return fetch(request);
}

const request = event.request;
const client = await self.clients.get(event.clientId);

Expand Down
128 changes: 128 additions & 0 deletions packages/trace-viewer/src/ui/aiConversation.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

.chat-container {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
color: #e0e0e0;
}

.chat-disclaimer {
text-align: center;
color: var(--vscode-editorBracketMatch-border);
margin: 0px;
}

.chat-container hr {
width: 100%;
border: none;
border-top: 1px solid var(--vscode-titleBar-inactiveBackground);
}

.messages-container {
Skn0tt marked this conversation as resolved.
Show resolved Hide resolved
flex: 1;
overflow-y: auto;
padding: 16px;

display: flex;
flex-direction: column;
gap: 16px;
}

.message {
gap: 12px;
Skn0tt marked this conversation as resolved.
Show resolved Hide resolved
max-width: 85%;
}

.user-message {
flex-direction: row-reverse;
margin-left: auto;
width: fit-content
}

.message-icon {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--vscode-titleBar-inactiveBackground);
flex-shrink: 0;
}

.message-content {
background-color: var(--vscode-titleBar-inactiveBackground);
Skn0tt marked this conversation as resolved.
Show resolved Hide resolved
color: var(--vscode-titleBar-activeForeground);
padding: 2px 8px;
}

.message-content pre {
text-wrap: auto;
overflow-wrap: anywhere;
}

.user-message .message-content {
background-color: var(--vscode-titleBar-activeBackground);
}

/* Input form styles */
.input-form {
position: sticky;
bottom: 0;
display: flex;
height: 64px;
gap: 8px;
padding: 10px;
background-color: var(--vscode-sideBar-background);
border-top: 1px solid var(--vscode-sideBarSectionHeader-border);
}

.message-input {
flex: 1;
padding: 8px 12px;
border: 1px solid var(--vscode-settings-textInputBorder);
background-color: var(--vscode-settings-textInputBackground);
font-size: 14px;
outline: none;
transition: border-color 0.2s;
}

.message-input:focus {
border-color: #0078d4;
}

.send-button {
display: flex;
align-items: center;
justify-content: center;
padding: 8px;
background-color: var(--vscode-button-background);
border: none;
color: white;
cursor: pointer;
transition: background-color 0.2s;
}

.send-button:hover {
background-color: var(--vscode-button-hoverBackground);
}

.send-button:disabled {
background-color: var(--vscode-disabledForeground);
cursor: not-allowed;
}
84 changes: 84 additions & 0 deletions packages/trace-viewer/src/ui/aiConversation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { useCallback, useState } from 'react';
import Markdown from 'markdown-to-jsx';
import './aiConversation.css';
import { clsx } from '@web/uiUtils';
import { useLLMConversation } from './llm';

export function AIConversation({ conversationId }: { conversationId: string }) {
const [history, conversation] = useLLMConversation(conversationId);
const [input, setInput] = useState('');

const onSubmit = useCallback(() => {
setInput(content => {
conversation.send(content);
return '';
});
}, [conversation]);

return (
<div className='chat-container'>
<p className='chat-disclaimer'>Chat based on {conversation.chat.api.name}. Check for mistakes.</p>
<hr/>
<div className='messages-container'>
{history.filter(({ role }) => role !== 'developer').map((message, index) => (
<div
key={'' + index}
Skn0tt marked this conversation as resolved.
Show resolved Hide resolved
className={clsx('message', message.role === 'user' && 'user-message')}
>
{message.role === 'assistant' && (
<div className='message-icon'>
<img src='playwright-logo.svg' />
</div>
)}
<div className='message-content'>
<Markdown>{message.displayContent ?? message.content}</Markdown>
Skn0tt marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
))}
</div>

<div className='input-form'>
<textarea
name='content'
value={input}
onChange={e => setInput(e.target.value)}
onKeyDown={e => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
onSubmit();
}
}}
placeholder='Ask a question...'
className='message-input'
/>
{conversation.isSending() ? (
<button type='button' className='send-button' onClick={evt => {
evt.preventDefault();
conversation.abortSending();
}}>
Cancel
</button>
) : (
<button className='send-button' disabled={!input.trim()} onClick={onSubmit}>
Send
</button>
)}
</div>
</div>
);
}
Loading
Loading