fix(vscode): prevent early SSE replay loss
This commit is contained in:
@@ -536,7 +536,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
private async _startSseProxy(message: BridgeRequest): Promise<BridgeResponse> {
|
||||
const { id, type, payload } = message;
|
||||
|
||||
const { path, headers } = (payload || {}) as { path?: string; headers?: Record<string, string> };
|
||||
const { path, headers, streamId: requestedStreamId } = (payload || {}) as { path?: string; headers?: Record<string, string>; streamId?: string };
|
||||
const normalizedPath = typeof path === 'string' && path.trim().length > 0 ? path.trim() : '/event';
|
||||
|
||||
if (!this._openCodeManager) {
|
||||
@@ -548,8 +548,11 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
};
|
||||
}
|
||||
|
||||
const streamId = `sse_${++this._sseCounter}_${Date.now()}`;
|
||||
const streamId = typeof requestedStreamId === 'string' && /^sse_webview_\d+_\d+$/.test(requestedStreamId)
|
||||
? requestedStreamId
|
||||
: `sse_${++this._sseCounter}_${Date.now()}`;
|
||||
const controller = new AbortController();
|
||||
this._sseStreams.set(streamId, { controller, view: this._view });
|
||||
|
||||
try {
|
||||
const start = await openSseProxy({
|
||||
@@ -562,8 +565,6 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
},
|
||||
});
|
||||
|
||||
this._sseStreams.set(streamId, { controller, view: this._view });
|
||||
|
||||
start.run
|
||||
.then(() => {
|
||||
this._view?.webview.postMessage({ type: 'api:sse:end', streamId });
|
||||
@@ -589,6 +590,7 @@ export class ChatViewProvider implements vscode.WebviewViewProvider {
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
this._sseStreams.delete(streamId);
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user