diff --git a/typescript/playground-common/src/baml_wasm_web/EventListener.tsx b/typescript/playground-common/src/baml_wasm_web/EventListener.tsx index 41aa5868f..ac4470518 100644 --- a/typescript/playground-common/src/baml_wasm_web/EventListener.tsx +++ b/typescript/playground-common/src/baml_wasm_web/EventListener.tsx @@ -548,6 +548,7 @@ export const EventListener: React.FC<{ children: React.ReactNode }> = ({ childre break case 'port_number': + console.log('Setting port number', content.port) setEnvKeyValueStorage((prev) => { let keyExists = false const updated: [string, string][] = prev.map(([key, value]) => { diff --git a/typescript/vscode-ext/packages/language-server/src/server.ts b/typescript/vscode-ext/packages/language-server/src/server.ts index 1ddc6f9eb..801e939e0 100644 --- a/typescript/vscode-ext/packages/language-server/src/server.ts +++ b/typescript/vscode-ext/packages/language-server/src/server.ts @@ -37,7 +37,6 @@ import { z } from 'zod' // import { getVersion, getEnginesVersion } from './lib/wasm/internals' import BamlProjectManager from './lib/baml_project_manager' import type { LSOptions, LSSettings } from './lib/types' -;(globalThis as any).crypto = require('node:crypto').webcrypto const packageJson = require('../../package.json') // eslint-disable-line function getConnection(options?: LSOptions): Connection { diff --git a/typescript/vscode-ext/packages/package.json b/typescript/vscode-ext/packages/package.json index 9efe17520..f5f13f45b 100644 --- a/typescript/vscode-ext/packages/package.json +++ b/typescript/vscode-ext/packages/package.json @@ -2,7 +2,7 @@ "name": "baml-extension", "displayName": "Baml", "description": "BAML is a DSL for AI applications.", - "version": "0.36.0", + "version": "0.36.2", "publisher": "Boundary", "repository": "https://github.com/BoundaryML/baml", "homepage": "https://www.boundaryml.com", diff --git a/typescript/vscode-ext/packages/vscode/src/extension.ts b/typescript/vscode-ext/packages/vscode/src/extension.ts index 10d3ea647..aa8037d69 100644 --- a/typescript/vscode-ext/packages/vscode/src/extension.ts +++ b/typescript/vscode-ext/packages/vscode/src/extension.ts @@ -188,9 +188,16 @@ export function activate(context: vscode.ExtensionContext) { root_path: 'default', function_name: args?.functionName ?? 'default', }) - }, 1000) + + WebPanelView.currentPanel?.postMessage('port_number', { + port: port, + }) + }, 2000) console.info('Opening BAML panel') requestDiagnostics() + WebPanelView.currentPanel?.postMessage('port_number', { + port: port, + }) }, ) @@ -247,42 +254,48 @@ export function activate(context: vscode.ExtensionContext) { vscode.commands.executeCommand('baml.openBamlPanel') } - const app = require('express')() - app.use(cors()) - var port: number - const server = app.listen(0, () => { - port = server.address().port - WebPanelView.currentPanel?.postMessage('port_number', { - port: port, + try { + const app = require('express')() + app.use(cors()) + var port: number + const server = app.listen(0, () => { + port = server.address().port + console.log('Server started on port ' + port) + WebPanelView.currentPanel?.postMessage('port_number', { + port: port, + }) }) - }) - app.use( - createProxyMiddleware({ - changeOrigin: true, - router: (req) => { - // Extract the original target URL from the custom header - const originalUrl = req.headers['baml-original-url'] - - if (typeof originalUrl === 'string') { - delete req.headers['baml-original-url'] - req.headers['origin'] = `http://localhost:${port}` - return originalUrl - } else { - throw new Error('baml-original-url header is missing or invalid') - } - }, - logger: console, - on: { - proxyRes: (proxyRes, req, res) => { - proxyRes.headers['Access-Control-Allow-Origin'] = '*' + app.use( + createProxyMiddleware({ + changeOrigin: true, + router: (req) => { + // Extract the original target URL from the custom header + const originalUrl = req.headers['baml-original-url'] + + if (typeof originalUrl === 'string') { + delete req.headers['baml-original-url'] + req.headers['origin'] = `http://localhost:${port}` + return originalUrl + } else { + throw new Error('baml-original-url header is missing or invalid') + } }, - error: (error) => { - console.error('proxy error:', error) + logger: console, + on: { + proxyRes: (proxyRes, req, res) => { + proxyRes.headers['Access-Control-Allow-Origin'] = '*' + }, + error: (error) => { + console.error('proxy error:', error) + }, }, - }, - }), - ) + }), + ) + } catch (error) { + console.error('Failed to start proxy server:', error) + vscode.window.showErrorMessage('Failed to BAML localhost server. Contact support for help.') + } // Add a catch-all route to handle 404 errors