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

Commit 34ff925

Browse files
authored
feat(svelte): Add cody chat page (#64448)
Closes #srch-906 This commit adds the cody chat page to svelte. This is simply reusing the existing wrapper around the React component and renders it in a standalone page. When merged this will cause the cody chat page to be handled by new web app on dotcom by default. ## Test plan - Verified that chat loads and the tabs are clickable. - Verified that the scroll behavior works as in the React app. - Verified that the sidebar chat still works as expected (scroll behavior, default context loading/switching)
1 parent f9f3cd8 commit 34ff925

File tree

7 files changed

+114
-7
lines changed

7 files changed

+114
-7
lines changed

client/web-sveltekit/src/lib/cody/CodySidebarChat.svelte renamed to client/web-sveltekit/src/lib/cody/CodyChat.svelte

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function getTelemetrySourceClient(): string {
2121
2222
import type { LineOrPositionOrRange } from '@sourcegraph/common'
2323
24-
export let repository: CodySidebar_ResolvedRevision
25-
export let filePath: string
24+
export let repository: CodySidebar_ResolvedRevision | undefined = undefined
25+
export let filePath: string | undefined = undefined
2626
export let lineOrPosition: LineOrPositionOrRange | undefined = undefined
2727
2828
let container: HTMLDivElement
@@ -38,8 +38,8 @@ function getTelemetrySourceClient(): string {
3838
})
3939
4040
function render(
41-
repository: CodySidebar_ResolvedRevision,
42-
filePath: string,
41+
repository?: CodySidebar_ResolvedRevision,
42+
filePath?: string,
4343
lineOrPosition?: LineOrPositionOrRange
4444
) {
4545
if (!root) {
@@ -54,7 +54,7 @@ function getTelemetrySourceClient(): string {
5454
{
5555
accessToken: '',
5656
initialContext: {
57-
repositories: [repository],
57+
repositories: repository ? [repository] : [],
5858
fileURL: filePath ? (!filePath.startsWith('/') ? `/${filePath}` : filePath) : undefined,
5959
// Line range - 1 because of Cody Web initial context file range bug
6060
fileRange: hasFileRangeSelection
@@ -108,7 +108,6 @@ function getTelemetrySourceClient(): string {
108108
--vscode-keybindingLabel-foreground: var(--body-color);
109109
110110
line-height: 1.55;
111-
padding-bottom: 2rem;
112111
flex: 1;
113112
min-height: 0;
114113
@@ -249,4 +248,14 @@ function getTelemetrySourceClient(): string {
249248
--vscode-list-activeSelectionBackground: #031824;
250249
}
251250
}
251+
252+
:global([data-cody-web-chat]) {
253+
height: 100%;
254+
overflow: auto;
255+
background-color: var(--vscode-editor-background);
256+
font-size: var(--vscode-font-size);
257+
font-family: var(--vscode-font-family);
258+
color: var(--vscode-editor-foreground);
259+
padding-bottom: 2rem;
260+
}
252261
</style>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const CODY_SIDEBAR_ID = uniqueID("cody-sidebar");
4444
</Tooltip>
4545
</div>
4646
{#if $user}
47-
{#await import('./CodySidebarChat.svelte')}
47+
{#await import('./CodyChat.svelte')}
4848
<LoadingSpinner />
4949
{:then module}
5050
<svelte:component this={module.default} {repository} {filePath} {lineOrPosition} />

client/web-sveltekit/src/lib/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const svelteKitRoutes: SvelteKitRoute[] = [
6666
pattern: new RegExp('^/(backstage|chakraui|cncf|julia|kubernetes|o3de|stackstorm|stanford|temporal)/?$'),
6767
isRepoRoot: false,
6868
},
69+
{
70+
id: '/cody/chat',
71+
pattern: new RegExp('^/cody/chat/?$'),
72+
isRepoRoot: false,
73+
},
6974
{
7075
id: '/search',
7176
pattern: new RegExp('^/search/?$'),
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<script lang="ts">
2+
// @sg EnableRollout
3+
import Icon from '$lib/Icon.svelte'
4+
import LoadingSpinner from '$lib/LoadingSpinner.svelte'
5+
import { Alert, Button } from '$lib/wildcard'
6+
import ProductStatusBadge from '$lib/wildcard/ProductStatusBadge.svelte'
7+
8+
import type { PageData } from './$types'
9+
10+
export let data: PageData
11+
</script>
12+
13+
<svelte:head>
14+
<title>Cody Chat - Sourcegraph</title>
15+
</svelte:head>
16+
17+
<section>
18+
<header>
19+
<h2>
20+
<Icon icon={ISgCody} aria-hidden --icon-color="initial" />
21+
<span>Cody Chat</span>
22+
<ProductStatusBadge status="beta" />
23+
</h2>
24+
25+
<div class="actions">
26+
<a href={data.dashboardRoute}>Editor extensions</a>
27+
&nbsp;
28+
<Button variant="secondary">
29+
<a slot="custom" let:buttonClass class={buttonClass} href={data.dashboardRoute}> Dashboard </a>
30+
</Button>
31+
</div>
32+
</header>
33+
34+
{#await import('$lib/cody/CodyChat.svelte')}
35+
<LoadingSpinner center />
36+
{:then module}
37+
<svelte:component this={module.default} />
38+
{:catch}
39+
<Alert variant="warning">Failed to load Cody Chat</Alert>
40+
{/await}
41+
</section>
42+
43+
<style lang="scss">
44+
section {
45+
max-width: var(--viewport-lg);
46+
width: 100%;
47+
margin: 2rem auto 0 auto;
48+
display: flex;
49+
flex-direction: column;
50+
overflow: hidden;
51+
}
52+
53+
header {
54+
display: flex;
55+
justify-content: space-between;
56+
57+
margin-bottom: 1rem;
58+
}
59+
60+
h2 > * {
61+
vertical-align: middle;
62+
}
63+
</style>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { redirect } from '@sveltejs/kit'
2+
3+
import type { PageLoad } from './$types'
4+
5+
export const load: PageLoad = async ({ parent }) => {
6+
const dashboardRoute = window.context.sourcegraphDotComMode ? '/cody/manage' : '/cody/dashboard'
7+
const data = await parent()
8+
9+
if (!data.user) {
10+
redirect(302, '/sign-in')
11+
}
12+
13+
if (!window.context?.codyEnabledForCurrentUser) {
14+
redirect(303, dashboardRoute)
15+
}
16+
17+
return {
18+
dashboardRoute,
19+
}
20+
}

client/web/src/sveltekit/routes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ export const svelteKitRoutes: SvelteKitRoute[] = [
6666
pattern: new RegExp('^/(backstage|chakraui|cncf|julia|kubernetes|o3de|stackstorm|stanford|temporal)/?$'),
6767
isRepoRoot: false,
6868
},
69+
{
70+
id: '/cody/chat',
71+
pattern: new RegExp('^/cody/chat/?$'),
72+
isRepoRoot: false,
73+
},
6974
{
7075
id: '/search',
7176
pattern: new RegExp('^/search/?$'),

cmd/frontend/internal/app/ui/sveltekit/routes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ var svelteKitRoutes = []svelteKitRoute{
7373
Pattern: regexp.MustCompile("^/(backstage|chakraui|cncf|julia|kubernetes|o3de|stackstorm|stanford|temporal)/?$"),
7474
Tag: tags.EnableOptIn | tags.EnableRollout | tags.Dotcom,
7575
},
76+
{
77+
Id: "/cody/chat",
78+
Pattern: regexp.MustCompile("^/cody/chat/?$"),
79+
Tag: tags.EnableOptIn | tags.EnableRollout,
80+
},
7681
{
7782
Id: "/search",
7883
Pattern: regexp.MustCompile("^/search/?$"),

0 commit comments

Comments
 (0)