Skip to content

Commit

Permalink
possible fix for zlib problem in Cody Web
Browse files Browse the repository at this point in the history
  • Loading branch information
vovakulikov authored and arafatkatze committed Nov 25, 2024
1 parent 5bde0b6 commit 0738e71
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
17 changes: 4 additions & 13 deletions vscode/webviews/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import { View } from './tabs'
import type { VSCodeWrapper } from './utils/VSCodeApi'
import { ComposedWrappers, type Wrapper } from './utils/composeWrappers'
import { updateDisplayPathEnvInfoForWebview } from './utils/displayPathEnvInfo'
import {
TelemetryRecorderContext,
WebviewTelemetryServiceContext,
createWebviewTelemetryRecorder,
} from './utils/telemetry'
import { TelemetryRecorderContext, createWebviewTelemetryRecorder } from './utils/telemetry'
import { type Config, ConfigProvider } from './utils/useConfig'

export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vscodeAPI }) => {
Expand Down Expand Up @@ -160,6 +156,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
const service = WebviewOpenTelemetryService.getInstance()
return service
}, [])

useEffect(() => {
if (config) {
webviewTelemetryService.configure({
Expand All @@ -172,8 +169,8 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
}, [config, webviewTelemetryService])

const wrappers = useMemo<Wrapper[]>(
() => getAppWrappers({ vscodeAPI, telemetryRecorder, config, webviewTelemetryService }),
[vscodeAPI, telemetryRecorder, config, webviewTelemetryService]
() => getAppWrappers({ vscodeAPI, telemetryRecorder, config }),
[vscodeAPI, telemetryRecorder, config]
)

// Wait for all the data to be loaded before rendering Chat View
Expand Down Expand Up @@ -217,15 +214,13 @@ interface GetAppWrappersOptions {
telemetryRecorder: TelemetryRecorder
config: Config | null
staticDefaultContext?: DefaultContext
webviewTelemetryService: WebviewOpenTelemetryService
}

export function getAppWrappers({
vscodeAPI,
telemetryRecorder,
config,
staticDefaultContext,
webviewTelemetryService,
}: GetAppWrappersOptions): Wrapper[] {
return [
{
Expand All @@ -240,9 +235,5 @@ export function getAppWrappers({
component: ConfigProvider,
props: { value: config },
} satisfies Wrapper<any, ComponentProps<typeof ConfigProvider>>,
{
provider: WebviewTelemetryServiceContext.Provider,
value: webviewTelemetryService,
} satisfies Wrapper<WebviewOpenTelemetryService>,
]
}
4 changes: 0 additions & 4 deletions vscode/webviews/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createContext, useContext } from 'react'
import type { WebviewRecordEventParameters } from '../../src/chat/protocol'
import type { ApiPostMessage } from '../Chat'
import type { VSCodeWrapper } from './VSCodeApi'
import { WebviewOpenTelemetryService } from './webviewOpenTelemetryService'

/**
* Create a new {@link TelemetryRecorder} for use in the VS Code webviews for V2 telemetry.
Expand All @@ -28,9 +27,6 @@ export function createWebviewTelemetryRecorder(
},
}
}
export const WebviewTelemetryServiceContext = createContext<WebviewOpenTelemetryService>(
new WebviewOpenTelemetryService()
)

export const TelemetryRecorderContext = createContext<TelemetryRecorder | null>(null)

Expand Down
6 changes: 5 additions & 1 deletion web/lib/agent/shims/stream.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export function Readable(): unknown {
return null
return { Readable: {} }
}

export function Writable(): unknown {
return null
}

export default {
Readable: { prototype: {} },
}
11 changes: 11 additions & 0 deletions web/lib/agent/shims/zlib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function Readable(): unknown {
return { Readable: {} }
}

export function Writable(): unknown {
return null
}

export default {
Readable: { prototype: {} },
}
6 changes: 1 addition & 5 deletions web/lib/components/CodyWebChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { useCodyWebAgent } from './use-cody-agent'
// Include global Cody Web styles to the styles bundle
import '../global-styles/styles.css'
import type { DefaultContext } from '@sourcegraph/cody-shared/src/codebase-context/messages'
import { WebviewOpenTelemetryService } from 'cody-ai/webviews/utils/webviewOpenTelemetryService'
import styles from './CodyWebChat.module.css'
import { ChatSkeleton } from './skeleton/ChatSkeleton'

Expand Down Expand Up @@ -229,18 +228,15 @@ const CodyWebPanel: FC<CodyWebPanelProps> = props => {
return { initialContext, corpusContext }
}, [initialContextData])

const webviewTelemetryService = WebviewOpenTelemetryService.getInstance()

const wrappers = useMemo<Wrapper[]>(
() =>
getAppWrappers({
vscodeAPI,
telemetryRecorder,
config,
staticDefaultContext,
webviewTelemetryService,
}),
[vscodeAPI, telemetryRecorder, config, staticDefaultContext, webviewTelemetryService]
[vscodeAPI, telemetryRecorder, config, staticDefaultContext]
)

const CONTEXT_MENTIONS_SETTINGS = useMemo<ChatMentionsSettings>(() => {
Expand Down
2 changes: 2 additions & 0 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export default defineProjectWithDefaults(__dirname, {
replacement: resolve(__dirname, 'node_modules/path-browserify'),
},
{ find: 'node:stream', replacement: resolve(__dirname, 'node_modules/stream-browserify') },
{ find: 'zlib', replacement: resolve(__dirname, 'lib/agent/shims/zlib.ts') },
{ find: 'stream', replacement: resolve(__dirname, 'lib/agent/shims/stream.ts') },
{ find: /^(node:)?events$/, replacement: resolve(__dirname, 'node_modules/events') },
{ find: /^(node:)?util$/, replacement: resolve(__dirname, 'node_modules/util') },
{ find: /^(node:)?buffer$/, replacement: resolve(__dirname, 'node_modules/buffer') },
Expand Down

0 comments on commit 0738e71

Please sign in to comment.