Skip to content

Commit ee14be4

Browse files
committed
fix(preview): preserve tab routing during favicon lookup
1 parent b79dd1a commit ee14be4

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎apps/server/src/mcp/PreviewAutomationBroker.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ it.effect("does not let an older response replace a newer explicit tab target",
166166
.pipe(Effect.forkScoped);
167167
yield* Fiber.join(newer);
168168
yield* Fiber.join(older);
169+
yield* broker.invoke({
170+
scope,
171+
operation: "status",
172+
input: {},
173+
tabId: olderTabId,
174+
updateCurrentTab: false,
175+
});
169176
yield* broker.invoke({ scope, operation: "snapshot", input: {} });
170177

171178
expect(routedRequests.at(-1)?.tabId).toBe(newerTabId);

‎apps/server/src/mcp/PreviewAutomationBroker.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface PreviewAutomationInvokeInput {
4444
readonly input: unknown;
4545
readonly tabId?: PreviewTabId;
4646
readonly timeoutMs?: number;
47+
/** Background metadata reads must not change the agent's current tab. */
48+
readonly updateCurrentTab?: boolean;
4749
}
4850

4951
export class PreviewAutomationBroker extends Context.Service<
@@ -575,6 +577,7 @@ export const make = Effect.gen(function* PreviewAutomationBrokerMake() {
575577
});
576578
});
577579
const result = yield* awaitResponse().pipe(Effect.ensuring(removePending));
580+
if (input.updateCurrentTab === false) return result;
578581
const responseTabId = readResultTabId(result);
579582
const resultTabId = responseTabId === undefined ? input.tabId : responseTabId;
580583
if (resultTabId === undefined) return result;

‎apps/server/src/mcp/toolkits/preview/handlers.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const invoke = Effect.fn("PreviewToolkit.invoke")(function* <A>(
8080
operation: "status",
8181
input: {},
8282
timeoutMs: 500,
83+
updateCurrentTab: false,
8384
...(statusTabId === undefined ? {} : { tabId: statusTabId }),
8485
})
8586
.pipe(Effect.catch(() => Effect.succeed(null)));

‎apps/server/src/orchestration/ActivityPayloadProjection.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ describe("projectActivityPayload", () => {
264264
{ tool: "t3-code_preview_status", state: { output: '{"url":"https://example.com/"}' } },
265265
{
266266
toolName: "mcp__t3_code__preview_snapshot",
267-
result: { content: [{ type: "text", text: '{"url":"https://example.com/"}' }] },
267+
result: {
268+
content: [
269+
{ type: "text", text: '{"url":"https://example.com/"}' },
270+
{ type: "text", text: "Snapshot text was bounded. Omitted: accessibilityTree." },
271+
],
272+
},
268273
},
269274
{
270275
toolName: "mcp__t3-code__preview_click",

‎apps/server/src/orchestration/ActivityPayloadProjection.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
OrchestrationThreadDetailSnapshot,
55
} from "@t3tools/contracts";
66
import { isWorkspaceImagePreviewPath } from "@t3tools/shared/filePreview";
7+
import { extractJsonObject } from "@t3tools/shared/schemaJson";
78

89
function asRecord(value: unknown): Record<string, unknown> | null {
910
return value !== null && typeof value === "object" && !Array.isArray(value)
@@ -269,7 +270,7 @@ function projectPreviewToolMetadata(data: Record<string, unknown>, status: unkno
269270
const text = extractMcpResultText(result);
270271
if (!text || text.length > 2 * 1024 * 1024) return {};
271272
try {
272-
page = asRecord(JSON.parse(text));
273+
page = asRecord(JSON.parse(extractJsonObject(text)));
273274
} catch {
274275
return {};
275276
}

0 commit comments

Comments
 (0)