Skip to content
Source
Sign inSign up

desktopBrowser.ts

48 lines1.7 KB

1import * as Schema from "effect/Schema";
2​
3import { TrimmedNonEmptyString } from "./baseSchemas.ts";
4​
5const TabKey = {
6 threadId: TrimmedNonEmptyString,
7 tabId: TrimmedNonEmptyString,
8};
9​
10export const DesktopBrowserEvent = Schema.Union([
11 Schema.Struct({ type: Schema.Literal("attached"), ...TabKey }),
12 /** Its `<webview>` went away: closed, crashed, swapped, or devtools took the debugger. */
13 Schema.Struct({ type: Schema.Literal("detached"), ...TabKey }),
14 Schema.Struct({ type: Schema.Literal("cdp"), ...TabKey, message: Schema.String }),
15 /**
16 * The tab's page failed to load. The desktop starts a tab's first load before
17 * the server connects, so the server cannot always observe the failure itself.
18 */
19 Schema.Struct({
20 type: Schema.Literal("loadFailed"),
21 ...TabKey,
22 url: Schema.String,
23 code: Schema.Int,
24 description: Schema.String,
25 }),
26 /** Its `<webview>` started or stopped being on screen in a desktop window. */
27 Schema.Struct({ type: Schema.Literal("shown"), ...TabKey, shown: Schema.Boolean }),
28]);
29export type DesktopBrowserEvent = typeof DesktopBrowserEvent.Type;
30​
31export const DesktopBrowserCommand = Schema.Union([
32 Schema.Struct({ type: Schema.Literal("cdp"), ...TabKey, message: Schema.String }),
33 Schema.Struct({ type: Schema.Literal("release"), ...TabKey }),
34 Schema.Struct({
35 type: Schema.Literal("pointer"),
36 ...TabKey,
37 phase: Schema.Literals(["move", "click"]),
38 x: Schema.Finite,
39 y: Schema.Finite,
40 }),
41 /** Whether an agent turn runs on the thread, so the tabs it uses stay focused between steps. */
42 Schema.Struct({
43 type: Schema.Literal("turn"),
44 threadId: TrimmedNonEmptyString,
45 active: Schema.Boolean,
46 }),
47]);
48export type DesktopBrowserCommand = typeof DesktopBrowserCommand.Type;