fix(vscode): prevent early SSE replay loss
This commit is contained in:
@@ -415,7 +415,7 @@ export class SessionEditorPanelProvider {
|
||||
private async _startSseProxy(message: BridgeRequest, entry: SessionPanelState): 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) {
|
||||
@@ -427,8 +427,11 @@ export class SessionEditorPanelProvider {
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
entry.sseStreams.set(streamId, controller);
|
||||
|
||||
try {
|
||||
const start = await openSseProxy({
|
||||
@@ -442,8 +445,6 @@ export class SessionEditorPanelProvider {
|
||||
},
|
||||
});
|
||||
|
||||
entry.sseStreams.set(streamId, controller);
|
||||
|
||||
start.run
|
||||
.then(() => {
|
||||
entry.panel?.webview?.postMessage({ type: 'api:sse:end', streamId });
|
||||
@@ -469,6 +470,7 @@ export class SessionEditorPanelProvider {
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
entry.sseStreams.delete(streamId);
|
||||
const messageText = error instanceof Error ? error.message : String(error);
|
||||
return {
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user