(webview: vscode.Webview)
| 1218 | } |
| 1219 | |
| 1220 | private async getHMRHtmlContent(webview: vscode.Webview): Promise<string> { |
| 1221 | let localPort = "5173" |
| 1222 | |
| 1223 | try { |
| 1224 | const fs = require("fs") |
| 1225 | const path = require("path") |
| 1226 | const portFilePath = path.resolve(__dirname, "../../.vite-port") |
| 1227 | |
| 1228 | if (fs.existsSync(portFilePath)) { |
| 1229 | localPort = fs.readFileSync(portFilePath, "utf8").trim() |
| 1230 | console.log(`[ClineProvider:Vite] Using Vite server port from ${portFilePath}: ${localPort}`) |
| 1231 | } else { |
| 1232 | console.log( |
| 1233 | `[ClineProvider:Vite] Port file not found at ${portFilePath}, using default port: ${localPort}`, |
| 1234 | ) |
| 1235 | } |
| 1236 | } catch (err) { |
| 1237 | console.error("[ClineProvider:Vite] Failed to read Vite port file:", err) |
| 1238 | } |
| 1239 | |
| 1240 | const localServerUrl = `localhost:${localPort}` |
| 1241 | |
| 1242 | // Check if local dev server is running. |
| 1243 | try { |
| 1244 | await axios.get(`http://${localServerUrl}`) |
| 1245 | } catch (error) { |
| 1246 | vscode.window.showErrorMessage(t("common:errors.hmr_not_running")) |
| 1247 | return this.getHtmlContent(webview) |
| 1248 | } |
| 1249 | |
| 1250 | const nonce = getNonce() |
| 1251 | |
| 1252 | // Get the OpenRouter base URL from configuration |
| 1253 | const { apiConfiguration } = await this.getState() |
| 1254 | const openRouterBaseUrl = apiConfiguration.openRouterBaseUrl || "https://openrouter.ai" |
| 1255 | // Extract the domain for CSP |
| 1256 | const openRouterDomain = openRouterBaseUrl.match(/^(https?:\/\/[^\/]+)/)?.[1] || "https://openrouter.ai" |
| 1257 | |
| 1258 | const stylesUri = getUri(webview, this.contextProxy.extensionUri, [ |
| 1259 | "webview-ui", |
| 1260 | "build", |
| 1261 | "assets", |
| 1262 | "index.css", |
| 1263 | ]) |
| 1264 | |
| 1265 | const codiconsUri = getUri(webview, this.contextProxy.extensionUri, ["assets", "codicons", "codicon.css"]) |
| 1266 | const materialIconsUri = getUri(webview, this.contextProxy.extensionUri, [ |
| 1267 | "assets", |
| 1268 | "vscode-material-icons", |
| 1269 | "icons", |
| 1270 | ]) |
| 1271 | const imagesUri = getUri(webview, this.contextProxy.extensionUri, ["assets", "images"]) |
| 1272 | const audioUri = getUri(webview, this.contextProxy.extensionUri, ["webview-ui", "audio"]) |
| 1273 | |
| 1274 | const file = "src/index.tsx" |
| 1275 | const scriptUri = `http://${localServerUrl}/${file}` |
| 1276 | |
| 1277 | const reactRefresh = /*html*/ ` |
no test coverage detected