(message: ExtensionToWebviewMessage)
| 1237 | } |
| 1238 | |
| 1239 | private postMessage(message: ExtensionToWebviewMessage): void { |
| 1240 | const shouldLog = message.type !== "chatEvent" && message.type !== "orpcStreamData"; |
| 1241 | |
| 1242 | if (!this.view) { |
| 1243 | if (shouldLog) { |
| 1244 | muxLogDebug("mux.chatView: -> drop postMessage (no view)", { |
| 1245 | traceId: this.traceId, |
| 1246 | type: message.type, |
| 1247 | }); |
| 1248 | } |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | if (!this.isWebviewReady) { |
| 1253 | if (shouldLog) { |
| 1254 | muxLogDebug("mux.chatView: -> drop postMessage (webview not ready)", { |
| 1255 | traceId: this.traceId, |
| 1256 | type: message.type, |
| 1257 | }); |
| 1258 | } |
| 1259 | return; |
| 1260 | } |
| 1261 | |
| 1262 | const seq = this.nextWebviewMessageSeq++; |
| 1263 | const meta = { |
| 1264 | traceId: this.traceId, |
| 1265 | seq, |
| 1266 | sentAtMs: Date.now(), |
| 1267 | }; |
| 1268 | |
| 1269 | const envelope: Record<string, unknown> = { __muxMeta: meta, ...message }; |
| 1270 | |
| 1271 | void this.view.webview.postMessage(envelope).then( |
| 1272 | (delivered) => { |
| 1273 | if (shouldLog) { |
| 1274 | muxLogDebug("mux.chatView: -> postMessage", { |
| 1275 | traceId: this.traceId, |
| 1276 | seq, |
| 1277 | type: message.type, |
| 1278 | delivered, |
| 1279 | }); |
| 1280 | } |
| 1281 | }, |
| 1282 | (error) => { |
| 1283 | muxLogWarn("mux.chatView: postMessage failed", { |
| 1284 | traceId: this.traceId, |
| 1285 | seq, |
| 1286 | type: message.type, |
| 1287 | error: formatError(error), |
| 1288 | }); |
| 1289 | } |
| 1290 | ); |
| 1291 | } |
| 1292 | |
| 1293 | private async onWebviewMessage(raw: unknown): Promise<void> { |
| 1294 | const msg = parseWebviewToExtensionMessage(raw); |
no test coverage detected