Open History to see the last commit
1import { Schema } from "effect";
2
3import { EnvironmentId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
4import { PreviewTabId } from "./preview.ts";
5import { ProviderInstanceId } from "./providerInstance.ts";
6
7const BoundedUrl = Schema.String.check(Schema.isTrimmed())
8 .check(
9 Schema.isNonEmpty({
10 description:
11 "Absolute http(s) URL or a schemeless host such as t3.chat or localhost:5173. Schemeless public hosts use https; loopback hosts use http.",
12 }),
13 )
14 .check(Schema.isMaxLength(2048));
15const OptionalTimeoutMs = Schema.optional(
16 Schema.Int.check(Schema.isGreaterThan(0))
17 .check(Schema.isLessThanOrEqualTo(60_000))
18 .annotate({ description: "Maximum wait in milliseconds. Defaults to 15000; maximum 60000." }),
19).annotate({ description: "Maximum wait in milliseconds. Defaults to 15000; maximum 60000." });
20
21export const PreviewAutomationOperation = Schema.Literals([
22 "status",
23 "open",
24 "navigate",
25 "snapshot",
26 "click",
27 "type",
28 "press",
29 "scroll",
30 "evaluate",
31 "waitFor",
32 "recordingStart",
33 "recordingStop",
34]);
35export type PreviewAutomationOperation = typeof PreviewAutomationOperation.Type;
36
37export const PreviewAutomationStatus = Schema.Struct({
38 available: Schema.Boolean,
39 visible: Schema.Boolean,
40 tabId: Schema.NullOr(PreviewTabId),
41 url: Schema.NullOr(Schema.String),
42 title: Schema.NullOr(Schema.String),
43 loading: Schema.Boolean,
44});
45export type PreviewAutomationStatus = typeof PreviewAutomationStatus.Type;
46
47export const PreviewAutomationOpenInput = Schema.Struct({
48 url: Schema.optional(BoundedUrl).annotate({
49 description:
50 "Optional initial page URL, for example https://t3.chat or localhost:5173. Omit to open a blank tab.",
51 }),
52 show: Schema.optional(
53 Schema.Boolean.annotate({
54 description: "Whether to reveal the preview panel to the human. Defaults to true.",
55 }),
56 ),
57 reuseExistingTab: Schema.optional(
58 Schema.Boolean.annotate({
59 description:
60 "Reuse the thread's active browser tab when available. Defaults to true; set false to create a new tab.",
61 }),
62 ),
63}).annotate({
64 description:
65 "Opens the collaborative browser for the current thread. Use preview_navigate afterward when readiness waiting matters.",
66});
67export type PreviewAutomationOpenInput = typeof PreviewAutomationOpenInput.Type;
68
69export const BrowserNavigationTarget = Schema.Union([
70 Schema.Struct({
71 kind: Schema.Literal("url").annotate({
72 description: "Selects direct URL navigation.",
73 }),
74 url: BoundedUrl.annotate({
75 description: "Direct website URL.",
76 }),
77 }),
78 Schema.Struct({
79 kind: Schema.Literal("environment-port").annotate({
80 description: "Selects a dev-server port relative to the current execution environment.",
81 }),
82 port: Schema.Int.check(Schema.isGreaterThan(0))
83 .check(Schema.isLessThan(65_536))
84 .annotate({ description: "Dev-server TCP port inside the current environment." }),
85 protocol: Schema.optional(
86 Schema.Literals(["http", "https"]).annotate({
87 description: "Dev-server protocol. Defaults to http.",
88 }),
89 ),
90 path: Schema.optional(
91 Schema.String.annotate({
92 description: "Optional path, query, and fragment, for example /settings?tab=account.",
93 }),
94 ),
95 }),
96]);
97export type BrowserNavigationTarget = typeof BrowserNavigationTarget.Type;
98
99export const PreviewAutomationNavigateInput = Schema.Struct({
100 url: Schema.optional(BoundedUrl).annotate({
101 description:
102 "Website URL, for example https://t3.chat. Use this for public pages and directly reachable URLs.",
103 }),
104 target: Schema.optional(
105 BrowserNavigationTarget.annotate({
106 description:
107 "Environment-relative target. Prefer {kind:'environment-port',port:5173} for a dev server in the current environment.",
108 }),
109 ).annotate({
110 description:
111 "Environment-relative target. Prefer {kind:'environment-port',port:5173} for a dev server in the current environment.",
112 }),
113 readiness: Schema.optional(
114 Schema.Literals(["load", "domContentLoaded", "none"]).annotate({
115 description:
116 "Readiness milestone before returning. 'load' waits for loading to stop (default), 'domContentLoaded' waits for an interactive document, and 'none' returns immediately.",
117 }),
118 ).annotate({
119 description:
120 "Readiness milestone before returning. 'load' is the default; use 'none' only when a later wait call will verify the page.",
121 }),
122 timeoutMs: OptionalTimeoutMs,
123})
124 .check(
125 Schema.makeFilter(
126 (input) =>
127 Number(input.url !== undefined) + Number(input.target !== undefined) === 1 ||
128 "Provide exactly one of url or target.",
129 ),
130 )
131 .annotate({
132 description:
133 "Navigates the active browser tab. Provide exactly one of url or target; for most public pages use url.",
134 });
135export type PreviewAutomationNavigateInput = typeof PreviewAutomationNavigateInput.Type;
136
137const Locator = TrimmedNonEmptyString.annotate({
138 description:
139 "Playwright selector, preferably role/text based, for example role=button[name='Send'] or text=Continue. Use snapshot first to inspect the page.",
140});
141
142const LegacySelector = TrimmedNonEmptyString.annotate({
143 description:
144 "Legacy CSS selector such as button[type='submit']. Prefer locator for resilient role/text targeting.",
145});
146
147export const PreviewAutomationClickInput = Schema.Struct({
148 selector: Schema.optional(LegacySelector).annotate({
149 description:
150 "Legacy CSS selector such as button[type='submit']. Prefer locator for resilient role/text targeting.",
151 }),
152 locator: Schema.optional(Locator).annotate({
153 description:
154 "Playwright selector, preferably role/text based, for example role=button[name='Send'] or text=Continue. Use snapshot first to inspect the page.",
155 }),
156 x: Schema.optional(
157 Schema.Finite.annotate({
158 description: "Viewport-relative X coordinate in CSS pixels. Must be paired with y.",
159 }),
160 ),
161 y: Schema.optional(
162 Schema.Finite.annotate({
163 description: "Viewport-relative Y coordinate in CSS pixels. Must be paired with x.",
164 }),
165 ),
166 timeoutMs: OptionalTimeoutMs,
167})
168 .check(
169 Schema.makeFilter((input) => {
170 const selectorModes =
171 Number(input.selector !== undefined) + Number(input.locator !== undefined);
172 const hasX = input.x !== undefined;
173 const hasY = input.y !== undefined;
174 if (hasX !== hasY) return "Coordinates require both x and y.";
175 const coordinateModes = hasX && hasY ? 1 : 0;
176 return selectorModes + coordinateModes === 1 || "Provide exactly one click target.";
177 }),
178 )
179 .annotate({
180 description:
181 "Clicks one target. Provide exactly one of locator, selector, or the x/y coordinate pair.",
182 });
183export type PreviewAutomationClickInput = typeof PreviewAutomationClickInput.Type;
184
185export const PreviewAutomationTypeInput = Schema.Struct({
186 text: Schema.String.annotate({ description: "Literal text to insert." }),
187 selector: Schema.optional(LegacySelector).annotate({
188 description: "Legacy CSS selector for the input. Prefer locator.",
189 }),
190 locator: Schema.optional(Locator).annotate({
191 description:
192 "Playwright selector for the input, for example role=textbox[name='Message'] or textarea[placeholder*='Message'].",
193 }),
194 clear: Schema.optional(
195 Schema.Boolean.annotate({
196 description: "Clear the existing input value before inserting text. Defaults to false.",
197 }),
198 ),
199 timeoutMs: OptionalTimeoutMs,
200})
201 .check(
202 Schema.makeFilter(
203 (input) =>
204 !(input.selector !== undefined && input.locator !== undefined) ||
205 "Provide at most one of selector or locator.",
206 ),
207 )
208 .annotate({
209 description:
210 "Types into locator/selector, or into the currently focused element when neither target is provided.",
211 });
212export type PreviewAutomationTypeInput = typeof PreviewAutomationTypeInput.Type;
213
214export const PreviewAutomationPressInput = Schema.Struct({
215 key: Schema.String.check(Schema.isTrimmed())
216 .check(
217 Schema.isNonEmpty({
218 description:
219 "Keyboard key name such as Enter, Escape, Tab, ArrowDown, Backspace, or a single character.",
220 }),
221 )
222 .annotateKey({
223 description:
224 "Keyboard key name such as Enter, Escape, Tab, ArrowDown, Backspace, or a single character.",
225 }),
226 modifiers: Schema.optional(
227 Schema.Array(Schema.Literals(["Alt", "Control", "Meta", "Shift"])).annotate({
228 description: "Modifier keys held while pressing key.",
229 }),
230 ),
231}).annotate({ description: "Presses one keyboard key in the active browser tab." });
232export type PreviewAutomationPressInput = typeof PreviewAutomationPressInput.Type;
233
234export const PreviewAutomationScrollInput = Schema.Struct({
235 deltaX: Schema.optional(
236 Schema.Finite.annotate({
237 description: "Horizontal scroll delta in CSS pixels. Positive scrolls right. Defaults to 0.",
238 }),
239 ),
240 deltaY: Schema.optional(
241 Schema.Finite.annotate({
242 description: "Vertical scroll delta in CSS pixels. Positive scrolls down. Defaults to 0.",
243 }),
244 ),
245 selector: Schema.optional(LegacySelector).annotate({
246 description: "Legacy CSS selector for a scrollable container. Omit to scroll the viewport.",
247 }),
248 locator: Schema.optional(Locator).annotate({
249 description: "Playwright selector for a scrollable container. Omit to scroll the viewport.",
250 }),
251})
252 .check(
253 Schema.makeFilter((input) => {
254 if (input.selector !== undefined && input.locator !== undefined) {
255 return "Provide at most one of selector or locator.";
256 }
257 return (
258 input.deltaX !== undefined || input.deltaY !== undefined || "Provide deltaX or deltaY."
259 );
260 }),
261 )
262 .annotate({
263 description:
264 "Scrolls the viewport, or a locator/selector container. Provide deltaX, deltaY, or both.",
265 });
266export type PreviewAutomationScrollInput = typeof PreviewAutomationScrollInput.Type;
267
268export const PreviewAutomationEvaluateInput = Schema.Struct({
269 expression: Schema.String.check(Schema.isTrimmed())
270 .check(
271 Schema.isNonEmpty({
272 description:
273 "JavaScript expression evaluated in the page's main frame, for example document.title or (() => ({href: location.href}))().",
274 }),
275 )
276 .check(Schema.isMaxLength(64_000))
277 .annotateKey({
278 description:
279 "JavaScript expression evaluated in the page's main frame, for example document.title or (() => ({href: location.href}))().",
280 }),
281 awaitPromise: Schema.optional(
282 Schema.Boolean.annotate({ description: "Await a returned Promise. Defaults to true." }),
283 ),
284 returnByValue: Schema.optional(
285 Schema.Boolean.annotate({
286 description:
287 "Serialize and return the value instead of a remote object reference. Defaults to true.",
288 }),
289 ),
290}).annotate({
291 description:
292 "Evaluates JavaScript in the page. Prefer snapshot and semantic actions; use evaluate for inspection or unsupported interactions.",
293});
294export type PreviewAutomationEvaluateInput = typeof PreviewAutomationEvaluateInput.Type;
295
296export const PreviewAutomationWaitForInput = Schema.Struct({
297 selector: Schema.optional(LegacySelector).annotate({
298 description: "Legacy CSS selector that must match an element. Prefer locator.",
299 }),
300 locator: Schema.optional(Locator).annotate({
301 description:
302 "Playwright selector that must match an element, for example role=button[name='Send'].",
303 }),
304 text: Schema.optional(
305 TrimmedNonEmptyString.annotate({
306 description: "Case-sensitive substring that must appear in visible document text.",
307 }),
308 ).annotate({
309 description: "Case-sensitive substring that must appear in visible document text.",
310 }),
311 urlIncludes: Schema.optional(
312 TrimmedNonEmptyString.annotate({
313 description: "Substring that must appear in the current absolute URL.",
314 }),
315 ).annotate({ description: "Substring that must appear in the current absolute URL." }),
316 timeoutMs: OptionalTimeoutMs,
317})
318 .check(
319 Schema.makeFilter((input) => {
320 if (input.selector !== undefined && input.locator !== undefined) {
321 return "Provide at most one of selector or locator.";
322 }
323 return (
324 input.selector !== undefined ||
325 input.locator !== undefined ||
326 input.text !== undefined ||
327 input.urlIncludes !== undefined ||
328 "Provide at least one wait condition."
329 );
330 }),
331 )
332 .annotate({
333 description:
334 "Waits until all provided conditions match. Use after click/type when the page changes asynchronously.",
335 });
336export type PreviewAutomationWaitForInput = typeof PreviewAutomationWaitForInput.Type;
337
338export const PreviewAutomationElement = Schema.Struct({
339 tag: Schema.String,
340 role: Schema.NullOr(Schema.String),
341 name: Schema.String,
342 selector: Schema.String,
343 x: Schema.Number,
344 y: Schema.Number,
345 width: Schema.Number,
346 height: Schema.Number,
347});
348export type PreviewAutomationElement = typeof PreviewAutomationElement.Type;
349
350export const PreviewAutomationConsoleEntry = Schema.Struct({
351 level: Schema.String,
352 text: Schema.String,
353 timestamp: Schema.String,
354 source: Schema.optional(Schema.String),
355});
356export type PreviewAutomationConsoleEntry = typeof PreviewAutomationConsoleEntry.Type;
357
358export const PreviewAutomationNetworkEntry = Schema.Struct({
359 url: Schema.String,
360 method: Schema.String,
361 status: Schema.NullOr(Schema.Number),
362 failed: Schema.Boolean,
363 errorText: Schema.optional(Schema.String),
364 timestamp: Schema.String,
365});
366export type PreviewAutomationNetworkEntry = typeof PreviewAutomationNetworkEntry.Type;
367
368export const PreviewAutomationActionEvent = Schema.Struct({
369 id: Schema.String,
370 action: Schema.String,
371 status: Schema.Literals(["running", "succeeded", "failed", "interrupted"]),
372 startedAt: Schema.String,
373 completedAt: Schema.optional(Schema.String),
374 error: Schema.optional(Schema.String),
375});
376export type PreviewAutomationActionEvent = typeof PreviewAutomationActionEvent.Type;
377
378export const PreviewAutomationSnapshot = Schema.Struct({
379 url: Schema.String,
380 title: Schema.String,
381 loading: Schema.Boolean,
382 visibleText: Schema.String,
383 interactiveElements: Schema.Array(PreviewAutomationElement),
384 accessibilityTree: Schema.Unknown,
385 consoleEntries: Schema.Array(PreviewAutomationConsoleEntry),
386 networkEntries: Schema.Array(PreviewAutomationNetworkEntry),
387 actionTimeline: Schema.Array(PreviewAutomationActionEvent),
388 screenshot: Schema.Struct({
389 mimeType: Schema.Literal("image/png"),
390 data: Schema.String,
391 width: Schema.Int,
392 height: Schema.Int,
393 }),
394});
395export type PreviewAutomationSnapshot = typeof PreviewAutomationSnapshot.Type;
396
397export const PreviewAutomationRecordingStatus = Schema.Struct({
398 tabId: PreviewTabId,
399 recording: Schema.Boolean,
400 startedAt: Schema.NullOr(Schema.String),
401});
402export type PreviewAutomationRecordingStatus = typeof PreviewAutomationRecordingStatus.Type;
403
404export const PreviewAutomationRecordingArtifact = Schema.Struct({
405 id: Schema.String,
406 tabId: PreviewTabId,
407 path: Schema.String,
408 mimeType: Schema.String,
409 sizeBytes: Schema.Int,
410 createdAt: Schema.String,
411});
412export type PreviewAutomationRecordingArtifact = typeof PreviewAutomationRecordingArtifact.Type;
413
414export const PreviewAutomationOwnerIdentity = Schema.Struct({
415 clientId: TrimmedNonEmptyString,
416 environmentId: EnvironmentId,
417 threadId: ThreadId,
418});
419export type PreviewAutomationOwnerIdentity = typeof PreviewAutomationOwnerIdentity.Type;
420
421export const PreviewAutomationOwner = Schema.Struct({
422 ...PreviewAutomationOwnerIdentity.fields,
423 tabId: Schema.NullOr(PreviewTabId),
424 visible: Schema.Boolean,
425 supportsAutomation: Schema.Boolean,
426 focusedAt: Schema.String,
427});
428export type PreviewAutomationOwner = typeof PreviewAutomationOwner.Type;
429
430export const PreviewAutomationRequest = Schema.Struct({
431 requestId: TrimmedNonEmptyString,
432 threadId: ThreadId,
433 tabId: Schema.optional(PreviewTabId),
434 operation: PreviewAutomationOperation,
435 input: Schema.Unknown,
436 timeoutMs: Schema.Int.check(Schema.isGreaterThan(0)),
437});
438export type PreviewAutomationRequest = typeof PreviewAutomationRequest.Type;
439
440export const PreviewAutomationResponse = Schema.Struct({
441 requestId: TrimmedNonEmptyString,
442 ok: Schema.Boolean,
443 result: Schema.optional(Schema.Unknown),
444 error: Schema.optional(
445 Schema.Struct({
446 _tag: TrimmedNonEmptyString,
447 message: Schema.String,
448 detail: Schema.optional(Schema.Unknown),
449 }),
450 ),
451});
452export type PreviewAutomationResponse = typeof PreviewAutomationResponse.Type;
453
454export class PreviewAutomationUnavailableError extends Schema.TaggedErrorClass<PreviewAutomationUnavailableError>()(
455 "PreviewAutomationUnavailableError",
456 {
457 capability: Schema.Literal("preview"),
458 environmentId: EnvironmentId,
459 threadId: ThreadId,
460 providerSessionId: TrimmedNonEmptyString,
461 providerInstanceId: ProviderInstanceId,
462 },
463) {
464 override get message(): string {
465 return `MCP credential does not grant the ${this.capability} capability.`;
466 }
467}
468
469const PreviewAutomationScopeErrorFields = {
470 operation: PreviewAutomationOperation,
471 environmentId: EnvironmentId,
472 threadId: ThreadId,
473 providerSessionId: TrimmedNonEmptyString,
474 providerInstanceId: ProviderInstanceId,
475};
476
477const PreviewAutomationRequestErrorFields = {
478 ...PreviewAutomationScopeErrorFields,
479 clientId: TrimmedNonEmptyString,
480 requestId: TrimmedNonEmptyString,
481 tabId: Schema.optional(PreviewTabId),
482 timeoutMs: Schema.Int.check(Schema.isGreaterThan(0)),
483};
484
485const PreviewAutomationRemoteDiagnosticFields = {
486 remoteTag: TrimmedNonEmptyString,
487 remoteMessageLength: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
488 remoteDetailKind: Schema.optional(
489 Schema.Literals(["null", "array", "object", "string", "number", "boolean"]),
490 ),
491 cause: Schema.Defect(),
492};
493
494const PreviewAutomationOptionalRemoteDiagnosticFields = {
495 remoteTag: Schema.optional(TrimmedNonEmptyString),
496 remoteMessageLength: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
497 remoteDetailKind: Schema.optional(
498 Schema.Literals(["null", "array", "object", "string", "number", "boolean"]),
499 ),
500 cause: Schema.optional(Schema.Defect()),
501};
502
503export class PreviewAutomationNoFocusedOwnerError extends Schema.TaggedErrorClass<PreviewAutomationNoFocusedOwnerError>()(
504 "PreviewAutomationNoFocusedOwnerError",
505 {
506 ...PreviewAutomationScopeErrorFields,
507 clientId: Schema.optional(TrimmedNonEmptyString),
508 requestId: Schema.optional(TrimmedNonEmptyString),
509 tabId: Schema.optional(PreviewTabId),
510 timeoutMs: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
511 ...PreviewAutomationOptionalRemoteDiagnosticFields,
512 },
513) {
514 override get message(): string {
515 const summary = `No focused preview automation owner is available for ${this.operation} in thread ${this.threadId}.`;
516 return summary;
517 }
518}
519
520export class PreviewAutomationUnsupportedClientError extends Schema.TaggedErrorClass<PreviewAutomationUnsupportedClientError>()(
521 "PreviewAutomationUnsupportedClientError",
522 {
523 ...PreviewAutomationRequestErrorFields,
524 ...PreviewAutomationRemoteDiagnosticFields,
525 },
526) {
527 override get message(): string {
528 return `Preview automation client ${this.clientId} does not support ${this.operation}.`;
529 }
530}
531
532export class PreviewAutomationTabNotFoundError extends Schema.TaggedErrorClass<PreviewAutomationTabNotFoundError>()(
533 "PreviewAutomationTabNotFoundError",
534 {
535 ...PreviewAutomationRequestErrorFields,
536 ...PreviewAutomationRemoteDiagnosticFields,
537 },
538) {
539 override get message(): string {
540 const summary = this.tabId
541 ? `Preview tab ${this.tabId} was not found for ${this.operation}.`
542 : `No active preview tab was found for ${this.operation}.`;
543 return summary;
544 }
545}
546
547export class PreviewAutomationTimeoutError extends Schema.TaggedErrorClass<PreviewAutomationTimeoutError>()(
548 "PreviewAutomationTimeoutError",
549 {
550 ...PreviewAutomationRequestErrorFields,
551 ...PreviewAutomationOptionalRemoteDiagnosticFields,
552 },
553) {
554 override get message(): string {
555 const summary = `Preview automation ${this.operation} timed out after ${this.timeoutMs}ms.`;
556 return summary;
557 }
558}
559
560export class PreviewAutomationControlInterruptedError extends Schema.TaggedErrorClass<PreviewAutomationControlInterruptedError>()(
561 "PreviewAutomationControlInterruptedError",
562 {
563 ...PreviewAutomationRequestErrorFields,
564 ...PreviewAutomationRemoteDiagnosticFields,
565 },
566) {
567 override get message(): string {
568 return `Preview automation ${this.operation} was interrupted on client ${this.clientId}.`;
569 }
570}
571
572export class PreviewAutomationExecutionError extends Schema.TaggedErrorClass<PreviewAutomationExecutionError>()(
573 "PreviewAutomationExecutionError",
574 {
575 ...PreviewAutomationRequestErrorFields,
576 ...PreviewAutomationRemoteDiagnosticFields,
577 },
578) {
579 override get message(): string {
580 return `Preview automation ${this.operation} failed on client ${this.clientId}.`;
581 }
582}
583
584export class PreviewAutomationInvalidSelectorError extends Schema.TaggedErrorClass<PreviewAutomationInvalidSelectorError>()(
585 "PreviewAutomationInvalidSelectorError",
586 {
587 ...PreviewAutomationRequestErrorFields,
588 ...PreviewAutomationRemoteDiagnosticFields,
589 selectorKind: Schema.optional(Schema.Literals(["locator", "selector"])),
590 selectorLength: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))),
591 },
592) {
593 override get message(): string {
594 if (this.selectorKind !== undefined && this.selectorLength !== undefined) {
595 return `Preview automation ${this.operation} received an invalid ${this.selectorKind} (${this.selectorLength} characters).`;
596 }
597 return `Preview automation ${this.operation} received an invalid selector.`;
598 }
599}
600
601export class PreviewAutomationResultTooLargeError extends Schema.TaggedErrorClass<PreviewAutomationResultTooLargeError>()(
602 "PreviewAutomationResultTooLargeError",
603 {
604 ...PreviewAutomationRequestErrorFields,
605 ...PreviewAutomationRemoteDiagnosticFields,
606 maximumBytes: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
607 },
608) {
609 override get message(): string {
610 const summary =
611 this.maximumBytes === undefined
612 ? `Preview automation ${this.operation} produced a result that is too large.`
613 : `Preview automation ${this.operation} produced a result larger than ${this.maximumBytes} bytes.`;
614 return summary;
615 }
616}
617
618export class PreviewAutomationHostNotConnectedError extends Schema.TaggedErrorClass<PreviewAutomationHostNotConnectedError>()(
619 "PreviewAutomationHostNotConnectedError",
620 {
621 ...PreviewAutomationScopeErrorFields,
622 clientId: TrimmedNonEmptyString,
623 },
624) {
625 override get message(): string {
626 return `Preview automation host ${this.clientId} is not connected for ${this.operation}.`;
627 }
628}
629
630export class PreviewAutomationClientDisconnectedError extends Schema.TaggedErrorClass<PreviewAutomationClientDisconnectedError>()(
631 "PreviewAutomationClientDisconnectedError",
632 PreviewAutomationRequestErrorFields,
633) {
634 override get message(): string {
635 return `Preview automation client ${this.clientId} disconnected during ${this.operation}.`;
636 }
637}
638
639export class PreviewAutomationRequestQueueClosedError extends Schema.TaggedErrorClass<PreviewAutomationRequestQueueClosedError>()(
640 "PreviewAutomationRequestQueueClosedError",
641 PreviewAutomationRequestErrorFields,
642) {
643 override get message(): string {
644 return `Preview automation client ${this.clientId} stopped accepting ${this.operation} requests.`;
645 }
646}
647
648export class PreviewAutomationRemoteUnavailableError extends Schema.TaggedErrorClass<PreviewAutomationRemoteUnavailableError>()(
649 "PreviewAutomationRemoteUnavailableError",
650 {
651 ...PreviewAutomationRequestErrorFields,
652 ...PreviewAutomationRemoteDiagnosticFields,
653 },
654) {
655 override get message(): string {
656 return `Preview automation ${this.operation} is unavailable on client ${this.clientId}.`;
657 }
658}
659
660export class PreviewAutomationMalformedResponseError extends Schema.TaggedErrorClass<PreviewAutomationMalformedResponseError>()(
661 "PreviewAutomationMalformedResponseError",
662 PreviewAutomationRequestErrorFields,
663) {
664 override get message(): string {
665 return `Preview automation client ${this.clientId} returned a malformed response for ${this.operation}.`;
666 }
667}
668
669export const PreviewAutomationError = Schema.Union([
670 PreviewAutomationUnavailableError,
671 PreviewAutomationNoFocusedOwnerError,
672 PreviewAutomationUnsupportedClientError,
673 PreviewAutomationTabNotFoundError,
674 PreviewAutomationTimeoutError,
675 PreviewAutomationControlInterruptedError,
676 PreviewAutomationExecutionError,
677 PreviewAutomationInvalidSelectorError,
678 PreviewAutomationResultTooLargeError,
679 PreviewAutomationHostNotConnectedError,
680 PreviewAutomationClientDisconnectedError,
681 PreviewAutomationRequestQueueClosedError,
682 PreviewAutomationRemoteUnavailableError,
683 PreviewAutomationMalformedResponseError,
684]);
685export type PreviewAutomationError = typeof PreviewAutomationError.Type;
686
687export const PreviewUrlResolution = Schema.Struct({
688 requestedUrl: Schema.String,
689 resolvedUrl: Schema.String,
690 resolutionKind: Schema.Literals(["direct", "direct-private-network"]),
691 environmentId: EnvironmentId,
692});
693export type PreviewUrlResolution = typeof PreviewUrlResolution.Type;