Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit f7d4517

Browse files
authored
upgrade Cody Web, always create a new chat (#64334)
Incorporates https://github.com/sourcegraph/cody/pull/5129 ## Test plan Run in SvelteKit and non-SvelteKit. Ensure that the Cody standalone chat and Cody sidebar chats work.
1 parent ebaab12 commit f7d4517

File tree

7 files changed

+49
-88
lines changed

7 files changed

+49
-88
lines changed

client/web-sveltekit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"@sentry/sveltekit": "^8.7.0",
8181
"@sourcegraph/branded": "workspace:*",
8282
"@sourcegraph/client-api": "workspace:*",
83-
"@sourcegraph/cody-web": "^0.3.7",
83+
"@sourcegraph/cody-web": "^0.4.0",
8484
"@sourcegraph/common": "workspace:*",
8585
"@sourcegraph/http-client": "workspace:*",
8686
"@sourcegraph/shared": "workspace:*",

client/web-sveltekit/src/lib/cody/CodySidebarChat.svelte

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
<script context="module" lang="ts">
2-
function getTelemetrySourceClient(): string {
3-
if (window.context?.sourcegraphDotComMode) {
4-
return "dotcom.web";
5-
}
6-
return "server.web";
7-
}
2+
function getTelemetrySourceClient(): string {
3+
if (window.context?.sourcegraphDotComMode) {
4+
return 'dotcom.web'
5+
}
6+
return 'server.web'
7+
}
88
</script>
99

1010
<script lang="ts">
1111
import { createElement } from 'react'
1212
13-
import { CodyWebPanel, CodyWebPanelProvider } from '@sourcegraph/cody-web'
1413
import { createRoot, type Root } from 'react-dom/client'
1514
import { onDestroy } from 'svelte'
1615
16+
import { CodyWebPanel, CodyWebPanelProvider } from '@sourcegraph/cody-web'
17+
1718
import type { CodySidebar_ResolvedRevision } from './CodySidebar.gql'
1819
1920
import '@sourcegraph/cody-web/dist/style.css'
2021
21-
import { createLocalWritable } from '$lib/stores'
22-
import type { LineOrPositionOrRange } from '@sourcegraph/common';
22+
import type { LineOrPositionOrRange } from '@sourcegraph/common'
2323
2424
export let repository: CodySidebar_ResolvedRevision
2525
export let filePath: string
2626
export let lineOrPosition: LineOrPositionOrRange | undefined = undefined
2727
28-
const chatIDs = createLocalWritable<Record<string, string>>('cody.context-to-chat-ids', {})
2928
let container: HTMLDivElement
3029
let root: Root | null
3130
@@ -38,7 +37,11 @@ function getTelemetrySourceClient(): string {
3837
root = null
3938
})
4039
41-
function render(repository: CodySidebar_ResolvedRevision, filePath: string, lineOrPosition?: LineOrPositionOrRange) {
40+
function render(
41+
repository: CodySidebar_ResolvedRevision,
42+
filePath: string,
43+
lineOrPosition?: LineOrPositionOrRange
44+
) {
4245
if (!root) {
4346
root = createRoot(container)
4447
}
@@ -50,25 +53,20 @@ function getTelemetrySourceClient(): string {
5053
CodyWebPanelProvider,
5154
{
5255
accessToken: '',
53-
chatID: $chatIDs[`${repository.id}-${filePath}`] ?? null,
5456
initialContext: {
5557
repositories: [repository],
5658
fileURL: filePath ? (!filePath.startsWith('/') ? `/${filePath}` : filePath) : undefined,
5759
// Line range - 1 because of Cody Web initial context file range bug
58-
fileRange: hasFileRangeSelection ? {
59-
startLine: lineOrPosition.line - 1,
60-
endLine: lineOrPosition.endLine ? lineOrPosition.endLine - 1 : lineOrPosition.line - 1
61-
} : undefined
60+
fileRange: hasFileRangeSelection
61+
? {
62+
startLine: lineOrPosition.line - 1,
63+
endLine: lineOrPosition.endLine ? lineOrPosition.endLine - 1 : lineOrPosition.line - 1,
64+
}
65+
: undefined,
6266
},
6367
serverEndpoint: window.location.origin,
6468
customHeaders: window.context.xhrHeaders,
6569
telemetryClientName: getTelemetrySourceClient(),
66-
onNewChatCreated: (chatID: string) => {
67-
chatIDs.update(ids => {
68-
ids[`${repository.id}-${filePath}`] = chatID
69-
return ids
70-
})
71-
},
7270
},
7371
[chat]
7472
)
@@ -80,7 +78,7 @@ function getTelemetrySourceClient(): string {
8078

8179
<style lang="scss">
8280
.chat {
83-
--vscode-sideBar-background: transparent;
81+
--vscode-sideBar-background: var(--body-bg);
8482
--vscode-editor-background: var(--body-bg);
8583
--vscode-editor-foreground: var(--body-color);
8684
--vscode-input-background: var(--input-bg);
@@ -104,10 +102,12 @@ function getTelemetrySourceClient(): string {
104102
--vscode-foreground: var(--body-color);
105103
106104
line-height: 1.55;
105+
padding-bottom: 2rem;
107106
flex: 1;
108107
min-height: 0;
109108
110-
:global(h3) {
109+
:global(h3),
110+
:global(h4) {
111111
font-size: inherit;
112112
margin: 0;
113113
}
@@ -116,10 +116,6 @@ function getTelemetrySourceClient(): string {
116116
margin: 0;
117117
}
118118
119-
:global(a) {
120-
color: var(--link-color) !important;
121-
}
122-
123119
:global(code) {
124120
padding: 1px 3px;
125121
border-radius: 0.25rem;
@@ -157,6 +153,10 @@ function getTelemetrySourceClient(): string {
157153
:global(.tw-transition-all) {
158154
animation: none !important;
159155
}
156+
157+
:global([cmdk-root] input:focus-visible) {
158+
box-shadow: unset !important;
159+
}
160160
}
161161
162162
:global([data-floating-ui-portal]) {

client/web/src/cody/chat/new-chat/NewCodyChatPage.module.scss

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@
33
.root {
44
display: flex;
55
flex-direction: column;
6-
// stylelint-disable-next-line property-no-unknown
7-
container-type: inline-size;
86
padding-bottom: 0 !important;
9-
10-
@media (--sm-breakpoint-down) {
11-
// These need to be !important to override the `py-4`
12-
// default padding on the page
13-
padding-top: 0 !important;
14-
padding-bottom: 0 !important;
15-
16-
.page-header {
17-
display: none;
18-
}
19-
}
7+
width: 100%;
208
}
219

2210
.page-header {
@@ -28,18 +16,11 @@
2816
display: flex;
2917
flex-grow: 1;
3018
overflow: hidden;
31-
border-top: 1px solid var(--border-color);
32-
}
33-
34-
.chat-history {
35-
width: 30%;
36-
flex-shrink: 0;
37-
overflow: auto;
38-
padding-top: 0.5rem;
3919
}
4020

4121
.chat {
4222
flex-grow: 1;
43-
height: 100%;
44-
border-left: 1px solid var(--border-color);
23+
[role='tabpanel'] {
24+
overflow: auto;
25+
}
4526
}

client/web/src/cody/chat/new-chat/components/chat-ui/ChatUI.module.scss

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
// stylelint-disable custom-property-pattern
22

3-
:root {
4-
// Turn off background color for picker popover element
5-
// Which causes glitch effect in Cody Web
6-
--vscode-sideBar-background: transparent;
7-
}
8-
93
.chat {
104
--vscode-editor-background: var(--body-bg);
115
--vscode-editor-foreground: var(--body-color);
@@ -18,6 +12,7 @@
1812
--vscode-loading-dot-color: var(--body-color);
1913
--vscode-textPreformat-foreground: var(--body-color);
2014
--vscode-textPreformat-background: var(--secondary);
15+
--vscode-sideBar-background: var(--body-bg);
2116
--vscode-sideBarSectionHeader-border: var(--border-color);
2217
--mention-color-opacity: 100%;
2318

@@ -28,8 +23,10 @@
2823
--vscode-foreground: var(--body-color);
2924

3025
line-height: 1.55;
26+
padding-bottom: 2rem;
3127

32-
h3 {
28+
h3,
29+
h4 {
3330
font-size: inherit;
3431
margin: 0;
3532
}
@@ -38,10 +35,6 @@
3835
margin: 0;
3936
}
4037

41-
a {
42-
color: var(--link-color) !important;
43-
}
44-
4538
code {
4639
// stylelint-disable-next-line declaration-property-unit-allowed-list
4740
padding: 1px 3px;
@@ -79,3 +72,7 @@
7972
--vscode-foreground: var(--body-color);
8073
--vscode-widget-shadow: rgba(36, 41, 54, 0.2);
8174
}
75+
76+
[cmdk-root] :global(.focus-visible) {
77+
box-shadow: unset !important;
78+
}

client/web/src/cody/sidebar/new-cody-sidebar/NewCodySidebarWebChat.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { type FC, memo, useCallback, useMemo } from 'react'
1+
import { type FC, memo, useMemo } from 'react'
22

33
import { useLocation } from 'react-router-dom'
44

55
import { CodyWebPanelProvider, type InitialContext } from '@sourcegraph/cody-web'
66
import { SourcegraphURL } from '@sourcegraph/common'
7-
import { useLocalStorage } from '@sourcegraph/wildcard'
87

98
import { getTelemetrySourceClient } from '../../../telemetry'
109
import { ChatUi } from '../../chat/new-chat/components/chat-ui/ChatUi'
@@ -23,18 +22,6 @@ export const NewCodySidebarWebChat: FC<NewCodySidebarWebChatProps> = memo(functi
2322
const { filePath, repository } = props
2423

2524
const location = useLocation()
26-
const [contextToChatIds, setContextToChatIds] = useLocalStorage<Record<string, string>>(
27-
'cody.context-to-chat-ids',
28-
{}
29-
)
30-
31-
const handleNewChatCreated = useCallback(
32-
(chatId: string): void => {
33-
contextToChatIds[`${repository.id}-${filePath}`] = chatId
34-
setContextToChatIds(contextToChatIds)
35-
},
36-
[contextToChatIds, setContextToChatIds, filePath, repository.id]
37-
)
3825

3926
const contextInfo = useMemo<InitialContext>(() => {
4027
const lineOrPosition = SourcegraphURL.from(location).lineRange
@@ -53,17 +40,13 @@ export const NewCodySidebarWebChat: FC<NewCodySidebarWebChatProps> = memo(functi
5340
}
5441
}, [repository, filePath, location])
5542

56-
const chatID = contextToChatIds[`${repository.id}-${filePath}`] ?? null
57-
5843
return (
5944
<CodyWebPanelProvider
6045
accessToken=""
61-
chatID={chatID}
6246
initialContext={contextInfo}
6347
serverEndpoint={window.location.origin}
6448
customHeaders={window.context.xhrHeaders}
6549
telemetryClientName={getTelemetrySourceClient()}
66-
onNewChatCreated={handleNewChatCreated}
6750
>
6851
<ChatUi />
6952
</CodyWebPanelProvider>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
"@reach/visually-hidden": "^0.16.0",
310310
"@react-aria/live-announcer": "^3.1.0",
311311
"@sentry/browser": "^7.8.1",
312-
"@sourcegraph/cody-web": "^0.3.7",
312+
"@sourcegraph/cody-web": "^0.4.0",
313313
"@sourcegraph/extension-api-classes": "^1.1.0",
314314
"@stripe/react-stripe-js": "^2.7.0",
315315
"@stripe/stripe-js": "^3.3.0",

pnpm-lock.yaml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)