Skip to content
TypeScript

fix(desktop): allow preview automation in agent-created threads (#8483)

Theo Browne2fbe313096b5
diff --git a/apps/desktop/src/ipc/methods/preview.test.ts b/apps/desktop/src/ipc/methods/preview.test.ts
index 92336cc7362..e7770dc629d 100644
--- a/apps/desktop/src/ipc/methods/preview.test.ts
+++ b/apps/desktop/src/ipc/methods/preview.test.ts
@@ -1,4 +1,5 @@
import { it as effectIt } from "@effect/vitest";
+import { PreviewAutomationStatus } from "@t3tools/contracts";
import * as Cause from "effect/Cause";
import * as Effect from "effect/Effect";
import * as Exit from "effect/Exit";
@@ -51,4 +52,46 @@ describe("preview IPC methods", () => {
},
),
);
+
+ effectIt.effect("returns automation status for long runtime tab ids", () =>
+ Effect.gen(function* () {
+ const tabId =
+ `["environment-1","thread:delegated-task:${"a".repeat(120)}",` +
+ `"server-epoch-1","preview-1"]`;
+ const status = {
+ available: false,
+ visible: true,
+ tabId,
+ url: null,
+ title: null,
+ loading: false,
+ };
+ const manager = PreviewManager.PreviewManager.of({
+ automationStatus: () => Effect.succeed(status),
+ } as unknown as PreviewManager.PreviewManager["Service"]);
+
+ expect(tabId.length).toBeGreaterThan(128);
+ expect(
+ yield* PreviewIpc.automationStatus
+ .handler({ tabId })
+ .pipe(Effect.provideService(PreviewManager.PreviewManager, manager)),
+ ).toEqual(status);
+ }),
+ );
+
+ it("keeps the public automation status tab id limit", () => {
+ const encode = Schema.encodeUnknownSync(PreviewAutomationStatus);
+ const tabId = "t".repeat(129);
+
+ expect(() =>
+ encode({
+ available: false,
+ visible: true,
+ tabId,
+ url: null,
+ title: null,
+ loading: false,
+ }),
+ ).toThrow();
+ });
});
diff --git a/apps/desktop/src/ipc/methods/preview.ts b/apps/desktop/src/ipc/methods/preview.ts
index 9850230a03a..5229d36c31f 100644
--- a/apps/desktop/src/ipc/methods/preview.ts
+++ b/apps/desktop/src/ipc/methods/preview.ts
@@ -5,6 +5,7 @@ import {
DesktopPreviewAutomationEvaluateInputSchema,
DesktopPreviewAutomationPressInputSchema,
DesktopPreviewAutomationScrollInputSchema,
+ DesktopPreviewAutomationStatusSchema,
DesktopPreviewAutomationTypeInputSchema,
DesktopPreviewAutomationWaitForInputSchema,
DesktopPreviewConfigInputSchema,
@@ -20,7 +21,6 @@ import {
DesktopPreviewWebviewConfigSchema,
PreviewAnnotationSubmissionResultSchema,
PreviewAutomationSnapshot,
- PreviewAutomationStatus,
} from "@t3tools/contracts";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";
@@ -282,7 +282,7 @@ export const copyArtifactToClipboard = DesktopIpc.makeIpcMethod({
export const automationStatus = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_STATUS_CHANNEL,
payload: DesktopPreviewTabInputSchema,
- result: PreviewAutomationStatus,
+ result: DesktopPreviewAutomationStatusSchema,
handler: Effect.fn("desktop.ipc.preview.automationStatus")(function* ({ tabId }) {
const manager = yield* PreviewManager.PreviewManager;
return yield* manager.automationStatus(tabId);
diff --git a/apps/desktop/src/preview/Manager.ts b/apps/desktop/src/preview/Manager.ts
index 0d90e0175fe..87539d0b912 100644
--- a/apps/desktop/src/preview/Manager.ts
+++ b/apps/desktop/src/preview/Manager.ts
@@ -7,6 +7,7 @@
*/
import type {
DesktopPreviewAnnotationTheme,
+ DesktopPreviewAutomationStatus,
DesktopPreviewColorScheme,
DesktopPreviewFavicon,
DesktopPreviewPointerEvent,
@@ -25,7 +26,6 @@ import type {
PreviewAutomationNetworkEntry,
PreviewAutomationScrollInput,
PreviewAutomationSnapshot,
- PreviewAutomationStatus,
PreviewAutomationTypeInput,
PreviewAutomationWaitForInput,
} from "@t3tools/contracts";
@@ -4089,7 +4089,7 @@ export class PreviewManager extends Context.Service<
) => Effect.Effect<DesktopPreviewRecordingArtifact, PreviewManagerError>;
readonly automationStatus: (
tabId: string,
- ) => Effect.Effect<PreviewAutomationStatus, PreviewManagerError>;
+ ) => Effect.Effect<DesktopPreviewAutomationStatus, PreviewManagerError>;
readonly automationSnapshot: (
tabId: string,
) => Effect.Effect<PreviewAutomationSnapshot, PreviewManagerError>;
diff --git a/packages/contracts/src/ipc.ts b/packages/contracts/src/ipc.ts
index e753596f3d3..98b8bf8c835 100644
--- a/packages/contracts/src/ipc.ts
+++ b/packages/contracts/src/ipc.ts
@@ -584,6 +584,12 @@ export const DesktopPreviewTabIdSchema = Schema.String.check(Schema.isTrimmed())
Schema.isNonEmpty(),
);
+export const DesktopPreviewAutomationStatusSchema = Schema.Struct({
+ ...PreviewAutomationStatus.fields,
+ tabId: Schema.NullOr(DesktopPreviewTabIdSchema),
+});
+export type DesktopPreviewAutomationStatus = typeof DesktopPreviewAutomationStatusSchema.Type;
+
export const DesktopPreviewNavStatusSchema = Schema.Union([
Schema.Struct({ kind: Schema.Literal("Idle") }),
Schema.Struct({
@@ -1217,7 +1223,7 @@ export interface DesktopPreviewBridge {
onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => () => void;
};
automation: {
- status: (tabId: string) => Promise<PreviewAutomationStatus>;
+ status: (tabId: string) => Promise<DesktopPreviewAutomationStatus>;
snapshot: (tabId: string) => Promise<PreviewAutomationSnapshot>;
click: (tabId: string, input: PreviewAutomationClickInput) => Promise<void>;
type: (tabId: string, input: PreviewAutomationTypeInput) => Promise<void>;