Skip to content

Commit 6620e15

Browse files
committed
Fixes after rebase
1 parent 63523a8 commit 6620e15

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

web/demo/App.tsx

+8-6
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ const INITIAL_CONTEXT: InitialContext = {
3636
isDirectory: true,
3737
}
3838

39+
const agentPromise = createCodyAgent({
40+
accessToken,
41+
serverEndpoint,
42+
createAgentWorker: CREATE_AGENT_WORKER,
43+
telemetryClientName: 'codydemo.testing',
44+
})
45+
3946
export const App: FC = () => {
4047
const [agent, setAgent] = useState<CodyWebAgent | null>(null)
4148

4249
useEffect(() => {
43-
createCodyAgent({
44-
accessToken,
45-
serverEndpoint,
46-
createAgentWorker: CREATE_AGENT_WORKER,
47-
telemetryClientName: 'codydemo.testing',
48-
}).then(agent => {
50+
agentPromise.then(agent => {
4951
agent?.createNewChat()
5052
setAgent(agent)
5153
}, setAgent)

web/lib/agent/agent.client.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ interface AgentClientOptions {
2121
createAgentWorker: () => Worker
2222
telemetryClientName?: string
2323
customHeaders?: Record<string, string>
24-
repository?: string
2524
debug?: boolean
2625
trace?: boolean
2726
}
@@ -31,7 +30,6 @@ export async function createAgentClient({
3130
accessToken,
3231
createAgentWorker,
3332
customHeaders,
34-
repository,
3533
telemetryClientName,
3634
debug = true,
3735
trace = false,
@@ -70,9 +68,7 @@ export async function createAgentClient({
7068
const serverInfo: ServerInfo = await rpc.sendRequest('initialize', {
7169
name: process.env.CODY_WEB_DEMO_STANDALONE_MODE === 'true' ? 'standalone-web' : 'web',
7270
version: '0.0.1',
73-
// Empty root URI leads to openctx configuration resolution failure, any non-empty
74-
// mock value (Cody Web doesn't really use any workspace related features)
75-
workspaceRootUri: `repo:${repository ?? ''}`,
71+
workspaceRootUri: '',
7672
capabilities: {
7773
edit: 'none',
7874
completions: 'none',

web/lib/components/CodyWebChat.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
type FC,
44
type FunctionComponent,
55
useCallback,
6+
useEffect,
67
useLayoutEffect,
78
useMemo,
89
useRef,
@@ -128,6 +129,12 @@ export const CodyWebChat: FunctionComponent<CodyWebChatProps> = ({
128129
return <ChatSkeleton className={classNames(className, styles.root)} />
129130
}
130131

132+
useEffect(() => {
133+
agent.client.rpc.sendNotification('workspaceFolder/didChange', {
134+
uris: initialContext?.repository.name ? [`repo:${initialContext.repository.name}`] : [],
135+
})
136+
}, [initialContext?.repository, agent.client])
137+
131138
return (
132139
<AppWrapper>
133140
<div className={classNames(className, styles.root)}>

web/lib/components/use-cody-agent.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface UseCodyWebAgentInput {
2626
}
2727

2828
export interface CodyWebAgent {
29+
client: AgentClient
2930
vscodeAPI: VSCodeWrapper
3031
createNewChat: () => Promise<void>
3132
}
@@ -41,7 +42,7 @@ export async function createCodyAgent(input: UseCodyWebAgentInput): Promise<Cody
4142
const activeWebviewPanelIDRef = { current: '' }
4243

4344
try {
44-
const agent = await createAgentClient({
45+
const client = await createAgentClient({
4546
customHeaders,
4647
telemetryClientName,
4748
createAgentWorker,
@@ -52,24 +53,24 @@ export async function createCodyAgent(input: UseCodyWebAgentInput): Promise<Cody
5253
// Special override for chat creating for Cody Web, otherwise the create new chat doesn't work
5354
// TODO: Move this special logic to the Cody Web agent handle "chat/web/new"
5455
const createNewChat = async () => {
55-
const { panelId, chatId } = await agent.rpc.sendRequest<{
56+
const { panelId, chatId } = await client.rpc.sendRequest<{
5657
panelId: string
5758
chatId: string
5859
}>('chat/web/new', null)
5960

6061
activeWebviewPanelIDRef.current = panelId
6162

62-
await agent.rpc.sendRequest('webview/receiveMessage', {
63+
await client.rpc.sendRequest('webview/receiveMessage', {
6364
id: activeWebviewPanelIDRef.current,
6465
message: { chatID: chatId, command: 'restoreHistory' },
6566
})
6667
}
6768

68-
const vscodeAPI = createVSCodeAPI({ activeWebviewPanelIDRef, createNewChat, client: agent })
69+
const vscodeAPI = createVSCodeAPI({ activeWebviewPanelIDRef, createNewChat, client: client })
6970
// Runtime sync side effect, ensure that later any cody UI
7071
// components will have access to the mocked/synthetic VSCode API
7172
setVSCodeWrapper(vscodeAPI)
72-
return { vscodeAPI, createNewChat }
73+
return { vscodeAPI, createNewChat, client }
7374
} catch (error) {
7475
console.error('Cody Web Agent creation failed', error)
7576
throw error

0 commit comments

Comments
 (0)