Skip to content

Commit dff6cb1

Browse files
committed
feat: more message related logs
1 parent 4696faa commit dff6cb1

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

src/proxy/bridge-non-streaming.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ async function collectFullResponse(
155155
scheduleToolCallBridgeEnd();
156156
},
157157
(_info: McpToolCallUpdateInfo) => {},
158+
undefined,
158159
(checkpointBytes) => {
159160
updateConversationCheckpoint(convKey, checkpointBytes);
160161
bridgeCloseController.noteCheckpoint();

src/proxy/bridge-streaming.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
createConnectFrameParser,
4141
createThinkingTagFilter,
4242
type McpToolCallUpdateInfo,
43+
type StepUpdateInfo,
4344
parseConnectEndStream,
4445
processServerMessage,
4546
scheduleBridgeEnd,
@@ -471,6 +472,47 @@ function createBridgeStreamResponse(
471472
});
472473

473474
},
475+
(info: StepUpdateInfo) => {
476+
const existingActiveBridge = activeBridges.get(bridgeKey);
477+
if (existingActiveBridge) {
478+
existingActiveBridge.diagnostics = {
479+
announcedToolCallIds:
480+
existingActiveBridge.diagnostics?.announcedToolCallIds ?? [],
481+
publishedToolCallIds:
482+
existingActiveBridge.diagnostics?.publishedToolCallIds ?? [],
483+
lastMcpUpdate:
484+
info.updateCase === "stepCompleted"
485+
? `${info.updateCase}:${info.stepId}:${info.stepDurationMs ?? "unknown"}`
486+
: `${info.updateCase}:${info.stepId}`,
487+
publishedAtMs: existingActiveBridge.diagnostics?.publishedAtMs,
488+
lastResumeAttemptAtMs:
489+
existingActiveBridge.diagnostics?.lastResumeAttemptAtMs,
490+
};
491+
}
492+
logPluginInfo("Tracking Cursor step boundary in streaming bridge", {
493+
modelId,
494+
bridgeKey,
495+
convKey,
496+
updateCase: info.updateCase,
497+
stepId: info.stepId,
498+
stepDurationMs: info.stepDurationMs,
499+
toolCallsFlushed,
500+
mcpExecReceived,
501+
pendingExecToolCallIds: sortedIds(
502+
state.pendingExecs.map((candidate) => candidate.toolCallId),
503+
),
504+
streamedToolCallIds: sortedIds(streamedToolCalls.keys()),
505+
hasStoredActiveBridge: Boolean(existingActiveBridge),
506+
storedActiveBridgePendingExecToolCallIds: existingActiveBridge
507+
? sortedIds(
508+
existingActiveBridge.pendingExecs.map(
509+
(candidate) => candidate.toolCallId,
510+
),
511+
)
512+
: [],
513+
storedActiveBridgeDiagnostics: existingActiveBridge?.diagnostics,
514+
});
515+
},
474516
(checkpointBytes) => {
475517
updateConversationCheckpoint(convKey, checkpointBytes);
476518
bridgeCloseController.noteCheckpoint();

src/proxy/stream-dispatch.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ export interface McpToolCallUpdateInfo {
8383
toolName?: string;
8484
}
8585

86+
export interface StepUpdateInfo {
87+
updateCase: "stepStarted" | "stepCompleted";
88+
stepId: string;
89+
stepDurationMs?: string;
90+
}
91+
8692
export function parseConnectEndStream(data: Uint8Array): Error | null {
8793
try {
8894
const payload = JSON.parse(new TextDecoder().decode(data));
@@ -228,6 +234,7 @@ export function processServerMessage(
228234
onText: (text: string, isThinking?: boolean) => void,
229235
onMcpExec: (exec: PendingExec) => void,
230236
onMcpToolCallUpdate?: (info: McpToolCallUpdateInfo) => void,
237+
onStepUpdate?: (info: StepUpdateInfo) => void,
231238
onCheckpoint?: (checkpointBytes: Uint8Array) => void,
232239
onTurnEnded?: () => void,
233240
onUnsupportedMessage?: (info: UnsupportedServerMessageInfo) => void,
@@ -241,6 +248,7 @@ export function processServerMessage(
241248
state,
242249
onText,
243250
onMcpToolCallUpdate,
251+
onStepUpdate,
244252
onTurnEnded,
245253
onUnsupportedMessage,
246254
);
@@ -288,6 +296,7 @@ function handleInteractionUpdate(
288296
state: StreamState,
289297
onText: (text: string, isThinking?: boolean) => void,
290298
onMcpToolCallUpdate?: (info: McpToolCallUpdateInfo) => void,
299+
onStepUpdate?: (info: StepUpdateInfo) => void,
291300
onTurnEnded?: () => void,
292301
onUnsupportedMessage?: (info: UnsupportedServerMessageInfo) => void,
293302
): void {
@@ -325,6 +334,21 @@ function handleInteractionUpdate(
325334
}
326335
}
327336

337+
if (updateCase === "stepStarted" || updateCase === "stepCompleted") {
338+
const stepValue = update.message?.value;
339+
const stepId = stepValue?.stepId;
340+
if (stepId !== undefined && stepId !== null) {
341+
onStepUpdate?.({
342+
updateCase,
343+
stepId: String(stepId),
344+
stepDurationMs:
345+
updateCase === "stepCompleted" && stepValue?.stepDurationMs !== undefined
346+
? String(stepValue.stepDurationMs)
347+
: undefined,
348+
});
349+
}
350+
}
351+
328352
if (updateCase === "textDelta") {
329353
const delta = update.message.value.text || "";
330354
if (delta) onText(delta, false);

0 commit comments

Comments
 (0)