@cbxss/eoka 0.0.0-stage → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +577 -2
- package/dist/LICENSE +21 -0
- package/dist/browser-install-diagnostics.d.ts +1 -0
- package/dist/browser-install-diagnostics.js +21 -0
- package/dist/browser-install-engine.d.ts +10 -0
- package/dist/browser-install-engine.js +286 -0
- package/dist/browser-install-inventory.d.ts +34 -0
- package/dist/browser-install-inventory.js +107 -0
- package/dist/browser-install-worker.d.ts +21 -0
- package/dist/browser-install-worker.js +65 -0
- package/dist/browser-install.d.ts +22 -0
- package/dist/browser-install.js +7 -0
- package/dist/browser.d.ts +59 -0
- package/dist/browser.js +445 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.js +44 -0
- package/dist/generated/protocol.d.ts +3929 -0
- package/dist/generated/protocol.js +2 -0
- package/dist/generated/schema-bundle.json +18964 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +11 -0
- package/dist/install-errors.d.ts +4 -0
- package/dist/install-errors.js +6 -0
- package/dist/operations.d.ts +22 -0
- package/dist/operations.js +87 -0
- package/dist/page.d.ts +77 -0
- package/dist/page.js +250 -0
- package/dist/platform.d.ts +4 -0
- package/dist/platform.js +27 -0
- package/dist/recording.d.ts +27 -0
- package/dist/recording.js +124 -0
- package/dist/release-manifest.json +101 -0
- package/dist/release.d.ts +36 -0
- package/dist/release.js +76 -0
- package/dist/server-binary.d.ts +11 -0
- package/dist/server-binary.js +107 -0
- package/dist/transport.d.ts +89 -0
- package/dist/transport.js +737 -0
- package/examples/capture.mjs +36 -0
- package/examples/consume-schema.mjs +7 -0
- package/examples/explicit-paths.mjs +42 -0
- package/examples/install-browser.mjs +20 -0
- package/examples/offline.mjs +20 -0
- package/package.json +70 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { Browser } from "./browser.js";
|
|
2
|
+
export type { BrowserOptions, LaunchOptions, ConnectOptions } from "./browser.js";
|
|
3
|
+
export { installBrowser } from "./browser-install.js";
|
|
4
|
+
export type { InstallBrowserOptions, InstallProgress, BrowserInstallation } from "./browser-install.js";
|
|
5
|
+
export { InstallationError } from "./install-errors.js";
|
|
6
|
+
export { releaseManifest } from "./release.js";
|
|
7
|
+
export type { ReleaseManifest, ChromeRelease, ChromePlatformRelease, ServerRelease, ServerPlatformRelease, } from "./release.js";
|
|
8
|
+
export { detectPlatform, selectPlatform } from "./platform.js";
|
|
9
|
+
export type { PlatformId } from "./platform.js";
|
|
10
|
+
export { Page } from "./page.js";
|
|
11
|
+
export type { PerformOptions, LocatorInput, PageWaitOptions, AgentStepOptions, AgentObserveOptions, FetchOptions, BoundedFetchOptions, ViewportOptions, ScreenshotOptions, ScreenshotFileOptions, RecordOptions, } from "./page.js";
|
|
12
|
+
export { Operation, OperationError } from "./operations.js";
|
|
13
|
+
export type { WaitOptions } from "./operations.js";
|
|
14
|
+
export { Recording, RecordingError } from "./recording.js";
|
|
15
|
+
export { SidecarTransport } from "./transport.js";
|
|
16
|
+
export type { SidecarStartOptions } from "./transport.js";
|
|
17
|
+
export { EokaError, ConfigurationError, TransportError, ProtocolError, ServerOperationError, } from "./errors.js";
|
|
18
|
+
export type { ErrorDetails, RequestState } from "./errors.js";
|
|
19
|
+
export type { CallOptions, InvokeClient } from "./client.js";
|
|
20
|
+
export { protocolVersion, methodNames } from "./generated/protocol.js";
|
|
21
|
+
export type { Action, ActionOptions, ActionOutcome, ActionReceipt, AgentAction, AgentMode, AgentObservation, AgentStepResult, BrowserState, Artifact, ArtifactContainer, ScreenshotClip, ScreenshotFormat, RecordingRecord, RecordingState, RecordingFailure, RecordingFailureStage, DispatchState, ErrorCode, ErrorData, ErrorDetail, Expectation, HelloParams, HelloResult, LocatorQuery, LocatorSpec, MethodName, MethodParams, MethodResults, OperationRecord, OperationState, ProtocolRequest, ProtocolResponse, ProtocolVersion, ServerError, TransportLimits, } from "./generated/protocol.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Browser } from "./browser.js";
|
|
2
|
+
export { installBrowser } from "./browser-install.js";
|
|
3
|
+
export { InstallationError } from "./install-errors.js";
|
|
4
|
+
export { releaseManifest } from "./release.js";
|
|
5
|
+
export { detectPlatform, selectPlatform } from "./platform.js";
|
|
6
|
+
export { Page } from "./page.js";
|
|
7
|
+
export { Operation, OperationError } from "./operations.js";
|
|
8
|
+
export { Recording, RecordingError } from "./recording.js";
|
|
9
|
+
export { SidecarTransport } from "./transport.js";
|
|
10
|
+
export { EokaError, ConfigurationError, TransportError, ProtocolError, ServerOperationError, } from "./errors.js";
|
|
11
|
+
export { protocolVersion, methodNames } from "./generated/protocol.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CallOptions, InvokeClient } from './client.js';
|
|
2
|
+
import { EokaError, type ErrorDetails } from './errors.js';
|
|
3
|
+
import type { OperationRecord } from './generated/protocol.js';
|
|
4
|
+
export interface WaitOptions extends CallOptions {
|
|
5
|
+
waitTimeoutMs?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class OperationError extends EokaError {
|
|
8
|
+
readonly record: OperationRecord | undefined;
|
|
9
|
+
constructor(code: string, message: string, operationId: string, record?: OperationRecord, details?: ErrorDetails);
|
|
10
|
+
}
|
|
11
|
+
export declare function operationFailure(error: unknown, id: string, record?: OperationRecord): OperationError;
|
|
12
|
+
export declare function validateOperationRecord(record: OperationRecord, id: string, targetId?: string): void;
|
|
13
|
+
export declare class Operation {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
private readonly client;
|
|
16
|
+
private latest;
|
|
17
|
+
constructor(client: InvokeClient, id: string, record?: OperationRecord);
|
|
18
|
+
get record(): OperationRecord | undefined;
|
|
19
|
+
get(options?: CallOptions): Promise<OperationRecord>;
|
|
20
|
+
wait(options?: WaitOptions): Promise<OperationRecord>;
|
|
21
|
+
cancel(options?: CallOptions): Promise<OperationRecord>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { EokaError } from './errors.js';
|
|
2
|
+
export class OperationError extends EokaError {
|
|
3
|
+
record;
|
|
4
|
+
constructor(code, message, operationId, record, details = {}) {
|
|
5
|
+
const errorDetails = { ...details, operationId };
|
|
6
|
+
if (details.receipt === undefined && record?.receipt != null)
|
|
7
|
+
errorDetails.receipt = record.receipt;
|
|
8
|
+
super(code, message, errorDetails);
|
|
9
|
+
this.record = record;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function operationFailure(error, id, record) {
|
|
13
|
+
if (error instanceof OperationError && error.operationId === id)
|
|
14
|
+
return error;
|
|
15
|
+
const details = { cause: error };
|
|
16
|
+
if (error instanceof EokaError) {
|
|
17
|
+
if (error.requestId !== undefined)
|
|
18
|
+
details.requestId = error.requestId;
|
|
19
|
+
if (error.requestState !== undefined)
|
|
20
|
+
details.requestState = error.requestState;
|
|
21
|
+
if (error.receipt !== undefined)
|
|
22
|
+
details.receipt = error.receipt;
|
|
23
|
+
if (error.data !== undefined)
|
|
24
|
+
details.data = error.data;
|
|
25
|
+
if (error.stderr !== undefined)
|
|
26
|
+
details.stderr = error.stderr;
|
|
27
|
+
}
|
|
28
|
+
return new OperationError(error instanceof EokaError ? error.code : 'Operation', error instanceof Error ? error.message : String(error), id, record, details);
|
|
29
|
+
}
|
|
30
|
+
export function validateOperationRecord(record, id, targetId) {
|
|
31
|
+
if (record.id !== id || (targetId !== undefined && record.target_id !== targetId) || (record.receipt != null && record.receipt.target_id !== record.target_id)) {
|
|
32
|
+
throw new OperationError('Protocol', `Received an inconsistent operation record for ${id}${targetId === undefined ? '' : ` on page ${targetId}`}.`, id, record, { requestState: 'acknowledged' });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export class Operation {
|
|
36
|
+
id;
|
|
37
|
+
client;
|
|
38
|
+
latest;
|
|
39
|
+
constructor(client, id, record) {
|
|
40
|
+
this.client = client;
|
|
41
|
+
this.id = id;
|
|
42
|
+
if (record !== undefined)
|
|
43
|
+
validateOperationRecord(record, id);
|
|
44
|
+
this.latest = record;
|
|
45
|
+
}
|
|
46
|
+
get record() {
|
|
47
|
+
return this.latest;
|
|
48
|
+
}
|
|
49
|
+
async get(options) {
|
|
50
|
+
try {
|
|
51
|
+
const record = await this.client.invoke('operations.get', { id: this.id }, { ...options, operationId: this.id });
|
|
52
|
+
validateOperationRecord(record, this.id, this.latest?.target_id);
|
|
53
|
+
this.latest = record;
|
|
54
|
+
return record;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw operationFailure(error, this.id, this.latest);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async wait(options = {}) {
|
|
61
|
+
const { waitTimeoutMs, ...localOptions } = options;
|
|
62
|
+
try {
|
|
63
|
+
const params = { id: this.id };
|
|
64
|
+
if (waitTimeoutMs !== undefined)
|
|
65
|
+
params.timeout_ms = waitTimeoutMs;
|
|
66
|
+
localOptions.operationId = this.id;
|
|
67
|
+
const record = await this.client.invoke('operations.wait', params, localOptions);
|
|
68
|
+
validateOperationRecord(record, this.id, this.latest?.target_id);
|
|
69
|
+
this.latest = record;
|
|
70
|
+
return record;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
throw operationFailure(error, this.id, this.latest);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async cancel(options) {
|
|
77
|
+
try {
|
|
78
|
+
const record = await this.client.invoke('operations.cancel', { id: this.id }, { ...options, operationId: this.id });
|
|
79
|
+
validateOperationRecord(record, this.id, this.latest?.target_id);
|
|
80
|
+
this.latest = record;
|
|
81
|
+
return record;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw operationFailure(error, this.id, this.latest);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import type { CallOptions, InvokeClient } from './client.js';
|
|
3
|
+
import type { Action, ActionOptions, ActionReceipt, AgentAction, AgentMode, AgentObservation, AgentStepResult, BrowserState, Expectation, LocatorSpec, MethodName, MethodParams, MethodResults, OperationRecord } from './generated/protocol.js';
|
|
4
|
+
import { Operation } from './operations.js';
|
|
5
|
+
import { Recording } from './recording.js';
|
|
6
|
+
export type LocatorInput = string | LocatorSpec;
|
|
7
|
+
export interface PerformOptions {
|
|
8
|
+
operationId?: string;
|
|
9
|
+
actionOptions?: ActionOptions;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PageWaitOptions extends CallOptions {
|
|
14
|
+
waitTimeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentObserveOptions extends CallOptions {
|
|
17
|
+
observationTimeoutMs?: number;
|
|
18
|
+
maxControls?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentStepOptions extends AgentObserveOptions {
|
|
21
|
+
expect?: Expectation;
|
|
22
|
+
mode?: AgentMode;
|
|
23
|
+
actionTimeoutMs?: number;
|
|
24
|
+
}
|
|
25
|
+
export type FetchOptions = Pick<MethodParams['page.fetch'], 'method' | 'headers' | 'body' | 'redirect'>;
|
|
26
|
+
export type BoundedFetchOptions = Pick<MethodParams['page.fetch_bounded'], 'method' | 'headers' | 'body' | 'redirect' | 'maxBytes'>;
|
|
27
|
+
export type ViewportOptions = Pick<MethodParams['page.set_viewport'], 'width' | 'height' | 'deviceScaleFactor'>;
|
|
28
|
+
export type ScreenshotOptions = Pick<MethodParams['page.screenshot'], 'format' | 'quality' | 'clip' | 'fullPage'>;
|
|
29
|
+
export type ScreenshotFileOptions = ScreenshotOptions & Pick<MethodParams['page.screenshot_to_file'], 'path'> & CallOptions;
|
|
30
|
+
export type RecordOptions = Pick<MethodParams['recording.start'], 'path' | 'fps' | 'maxWidth' | 'maxHeight'> & CallOptions & {
|
|
31
|
+
recordingId?: string;
|
|
32
|
+
};
|
|
33
|
+
export declare class Page implements InvokeClient {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
private readonly client;
|
|
36
|
+
constructor(client: InvokeClient, id: string);
|
|
37
|
+
supports(method: string): boolean;
|
|
38
|
+
hasCapability(name: string): boolean;
|
|
39
|
+
invoke<M extends MethodName>(method: M, params: MethodParams[M], options?: CallOptions): Promise<MethodResults[M]>;
|
|
40
|
+
operation(id: string): Operation;
|
|
41
|
+
listOperations(params?: MethodParams['operations.list'], options?: CallOptions): Promise<OperationRecord[]>;
|
|
42
|
+
perform(action: Action, options?: PerformOptions): Promise<Operation>;
|
|
43
|
+
private verified;
|
|
44
|
+
goto(url: string, options?: PerformOptions): Promise<ActionReceipt>;
|
|
45
|
+
fill(target: LocatorInput, value: string, options?: PerformOptions): Promise<ActionReceipt>;
|
|
46
|
+
select(target: LocatorInput, value: string | string[], options?: PerformOptions): Promise<ActionReceipt>;
|
|
47
|
+
hover(target: LocatorInput, options?: PerformOptions): Promise<ActionReceipt>;
|
|
48
|
+
click(target: LocatorInput, options?: PerformOptions): Promise<ActionReceipt>;
|
|
49
|
+
type(target: LocatorInput, text: string, options?: PerformOptions): Promise<ActionReceipt>;
|
|
50
|
+
pressKey(key: string, options?: PerformOptions): Promise<ActionReceipt>;
|
|
51
|
+
submit(target: LocatorInput, options?: PerformOptions): Promise<ActionReceipt>;
|
|
52
|
+
drag(target: LocatorInput, dx: number, dy: number, options?: PerformOptions): Promise<ActionReceipt>;
|
|
53
|
+
text(options?: CallOptions): Promise<string>;
|
|
54
|
+
content(options?: CallOptions): Promise<string>;
|
|
55
|
+
title(options?: CallOptions): Promise<string>;
|
|
56
|
+
url(options?: CallOptions): Promise<string>;
|
|
57
|
+
getText(selector: string, options?: CallOptions): Promise<string>;
|
|
58
|
+
getAttribute(selector: string, name: string, options?: CallOptions): Promise<string | null>;
|
|
59
|
+
exists(selector: string, options?: CallOptions): Promise<boolean>;
|
|
60
|
+
waitFor(selector: string, options?: PageWaitOptions): Promise<void>;
|
|
61
|
+
waitForVisible(selector: string, options?: PageWaitOptions): Promise<void>;
|
|
62
|
+
waitForText(text: string, options?: PageWaitOptions): Promise<void>;
|
|
63
|
+
evaluate(js: string, options?: CallOptions): Promise<unknown>;
|
|
64
|
+
execute(js: string, options?: CallOptions): Promise<void>;
|
|
65
|
+
captureState(options?: CallOptions): Promise<BrowserState>;
|
|
66
|
+
restoreState(state: BrowserState, options?: CallOptions): Promise<void>;
|
|
67
|
+
fetch(url: string, fetchOptions?: FetchOptions, options?: CallOptions): Promise<MethodResults['page.fetch']>;
|
|
68
|
+
fetchBounded(url: string, fetchOptions?: BoundedFetchOptions, options?: CallOptions): Promise<MethodResults['page.fetch_bounded']>;
|
|
69
|
+
screenshot(options?: ScreenshotOptions & CallOptions): Promise<Buffer>;
|
|
70
|
+
screenshotToFile(options: ScreenshotFileOptions): Promise<MethodResults['page.screenshot_to_file']>;
|
|
71
|
+
record(options: RecordOptions): Promise<Recording>;
|
|
72
|
+
setViewport(viewport: ViewportOptions, options?: CallOptions): Promise<void>;
|
|
73
|
+
resetViewport(options?: CallOptions): Promise<void>;
|
|
74
|
+
observe(options?: AgentObserveOptions): Promise<AgentObservation>;
|
|
75
|
+
step(action: AgentAction, options?: AgentStepOptions): Promise<AgentStepResult>;
|
|
76
|
+
close(options?: CallOptions): Promise<void>;
|
|
77
|
+
}
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { Operation, OperationError, operationFailure, validateOperationRecord } from './operations.js';
|
|
5
|
+
import { Recording, RecordingError, recordingFailure, requireCaptureCapability, validateRecordingRecord } from './recording.js';
|
|
6
|
+
const recordingIdPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
7
|
+
function locator(target) {
|
|
8
|
+
return typeof target === 'string' ? { query: { kind: 'css', selector: target } } : target;
|
|
9
|
+
}
|
|
10
|
+
export class Page {
|
|
11
|
+
id;
|
|
12
|
+
client;
|
|
13
|
+
constructor(client, id) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
this.id = id;
|
|
16
|
+
}
|
|
17
|
+
supports(method) { return this.client.supports?.(method) === true; }
|
|
18
|
+
hasCapability(name) { return this.client.hasCapability?.(name) === true; }
|
|
19
|
+
invoke(method, params, options) {
|
|
20
|
+
return this.client.invoke(method, params, options);
|
|
21
|
+
}
|
|
22
|
+
operation(id) {
|
|
23
|
+
return new Operation(this.client, id);
|
|
24
|
+
}
|
|
25
|
+
listOperations(params = {}, options) {
|
|
26
|
+
return this.invoke('operations.list', params, options);
|
|
27
|
+
}
|
|
28
|
+
async perform(action, options = {}) {
|
|
29
|
+
const id = options.operationId ?? randomUUID();
|
|
30
|
+
if ((action.kind === 'click' || action.kind === 'type' || action.kind === 'press_key' || action.kind === 'submit' || action.kind === 'drag' || action.kind === 'insert_text') && options.actionOptions?.expect == null) {
|
|
31
|
+
throw new OperationError('expectation_required', 'This action requires actionOptions.expect before dispatch.', id, undefined, { requestState: 'not_sent' });
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const params = { pageId: this.id, operation_id: id, action };
|
|
35
|
+
if (options.actionOptions !== undefined)
|
|
36
|
+
params.options = options.actionOptions;
|
|
37
|
+
const callOptions = { operationId: id };
|
|
38
|
+
if (options.signal !== undefined)
|
|
39
|
+
callOptions.signal = options.signal;
|
|
40
|
+
if (options.timeoutMs !== undefined)
|
|
41
|
+
callOptions.timeoutMs = options.timeoutMs;
|
|
42
|
+
const record = await this.invoke('actions.perform', params, callOptions);
|
|
43
|
+
validateOperationRecord(record, id, this.id);
|
|
44
|
+
return new Operation(this.client, id, record);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
throw operationFailure(error, id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async verified(action, options = {}) {
|
|
51
|
+
const timeoutMs = options.timeoutMs ?? 30_000;
|
|
52
|
+
const deadline = performance.now() + timeoutMs;
|
|
53
|
+
const operation = await this.perform(action, { ...options, timeoutMs });
|
|
54
|
+
let record = operation.record;
|
|
55
|
+
const remaining = deadline - performance.now();
|
|
56
|
+
if (remaining <= 0) {
|
|
57
|
+
throw new OperationError('DeadlineExceeded', 'The local action deadline elapsed; recover the operation by ID to learn its outcome.', operation.id, record, { requestState: 'acknowledged' });
|
|
58
|
+
}
|
|
59
|
+
if (record?.state === 'running' || record === undefined) {
|
|
60
|
+
const waitOptions = { timeoutMs: remaining, waitTimeoutMs: Math.floor(remaining) };
|
|
61
|
+
if (options.signal !== undefined)
|
|
62
|
+
waitOptions.signal = options.signal;
|
|
63
|
+
record = await operation.wait(waitOptions);
|
|
64
|
+
}
|
|
65
|
+
validateOperationRecord(record, operation.id, this.id);
|
|
66
|
+
if (performance.now() >= deadline) {
|
|
67
|
+
throw new OperationError('DeadlineExceeded', 'The local action deadline elapsed; recover the operation by ID to learn its outcome.', operation.id, record, { requestState: 'acknowledged' });
|
|
68
|
+
}
|
|
69
|
+
if (record.state !== 'finished' || record.outcome !== 'verified_complete' || record.receipt?.outcome !== 'verified_complete' || record.error_code != null) {
|
|
70
|
+
throw new OperationError(record.error_code ?? (record.state === 'running' ? 'OperationRunning' : record.outcome), `Operation ${operation.id} is ${record.state} with outcome ${record.outcome}; verified completion was not established.`, operation.id, record, { requestState: 'acknowledged' });
|
|
71
|
+
}
|
|
72
|
+
return record.receipt;
|
|
73
|
+
}
|
|
74
|
+
goto(url, options) {
|
|
75
|
+
return this.verified({ kind: 'navigate', url }, options);
|
|
76
|
+
}
|
|
77
|
+
fill(target, value, options) {
|
|
78
|
+
return this.verified({ kind: 'fill', target: locator(target), value }, options);
|
|
79
|
+
}
|
|
80
|
+
select(target, value, options) {
|
|
81
|
+
return this.verified({ kind: 'select', target: locator(target), values: typeof value === 'string' ? [value] : value }, options);
|
|
82
|
+
}
|
|
83
|
+
hover(target, options) {
|
|
84
|
+
return this.verified({ kind: 'hover', target: locator(target) }, options);
|
|
85
|
+
}
|
|
86
|
+
click(target, options) {
|
|
87
|
+
return this.verified({ kind: 'click', target: locator(target) }, options);
|
|
88
|
+
}
|
|
89
|
+
type(target, text, options) {
|
|
90
|
+
return this.verified({ kind: 'type', target: locator(target), text }, options);
|
|
91
|
+
}
|
|
92
|
+
pressKey(key, options) {
|
|
93
|
+
return this.verified({ kind: 'press_key', key }, options);
|
|
94
|
+
}
|
|
95
|
+
submit(target, options) {
|
|
96
|
+
return this.verified({ kind: 'submit', target: locator(target) }, options);
|
|
97
|
+
}
|
|
98
|
+
drag(target, dx, dy, options) {
|
|
99
|
+
return this.verified({ kind: 'drag', target: locator(target), dx, dy }, options);
|
|
100
|
+
}
|
|
101
|
+
async text(options) {
|
|
102
|
+
return (await this.invoke('page.text', { pageId: this.id }, options)).text;
|
|
103
|
+
}
|
|
104
|
+
async content(options) {
|
|
105
|
+
return (await this.invoke('page.content', { pageId: this.id }, options)).html;
|
|
106
|
+
}
|
|
107
|
+
async title(options) {
|
|
108
|
+
return (await this.invoke('page.title', { pageId: this.id }, options)).title;
|
|
109
|
+
}
|
|
110
|
+
async url(options) {
|
|
111
|
+
return (await this.invoke('page.url', { pageId: this.id }, options)).url;
|
|
112
|
+
}
|
|
113
|
+
async getText(selector, options) {
|
|
114
|
+
return (await this.invoke('page.get_text', { pageId: this.id, selector }, options)).text;
|
|
115
|
+
}
|
|
116
|
+
async getAttribute(selector, name, options) {
|
|
117
|
+
return (await this.invoke('page.get_attribute', { pageId: this.id, selector, name }, options)).value ?? null;
|
|
118
|
+
}
|
|
119
|
+
async exists(selector, options) {
|
|
120
|
+
return (await this.invoke('page.exists', { pageId: this.id, selector }, options)).exists;
|
|
121
|
+
}
|
|
122
|
+
async waitFor(selector, options = {}) {
|
|
123
|
+
const { waitTimeoutMs = 30_000, ...localOptions } = options;
|
|
124
|
+
await this.invoke('page.wait_for', { pageId: this.id, selector, timeoutMs: waitTimeoutMs }, localOptions);
|
|
125
|
+
}
|
|
126
|
+
async waitForVisible(selector, options = {}) {
|
|
127
|
+
const { waitTimeoutMs = 30_000, ...localOptions } = options;
|
|
128
|
+
await this.invoke('page.wait_for_visible', { pageId: this.id, selector, timeoutMs: waitTimeoutMs }, localOptions);
|
|
129
|
+
}
|
|
130
|
+
async waitForText(text, options = {}) {
|
|
131
|
+
const { waitTimeoutMs = 30_000, ...localOptions } = options;
|
|
132
|
+
await this.invoke('page.wait_for_text', { pageId: this.id, text, timeoutMs: waitTimeoutMs }, localOptions);
|
|
133
|
+
}
|
|
134
|
+
async evaluate(js, options) {
|
|
135
|
+
return (await this.invoke('page.evaluate', { pageId: this.id, js }, options)).result;
|
|
136
|
+
}
|
|
137
|
+
async execute(js, options) {
|
|
138
|
+
await this.invoke('page.execute', { pageId: this.id, js }, options);
|
|
139
|
+
}
|
|
140
|
+
async captureState(options) {
|
|
141
|
+
return (await this.invoke('page.capture_state', { pageId: this.id }, options)).state;
|
|
142
|
+
}
|
|
143
|
+
async restoreState(state, options) {
|
|
144
|
+
await this.invoke('page.restore_state', { pageId: this.id, state }, options);
|
|
145
|
+
}
|
|
146
|
+
fetch(url, fetchOptions = {}, options) {
|
|
147
|
+
return this.invoke('page.fetch', { ...fetchOptions, pageId: this.id, url }, options);
|
|
148
|
+
}
|
|
149
|
+
fetchBounded(url, fetchOptions = {}, options) {
|
|
150
|
+
return this.invoke('page.fetch_bounded', { ...fetchOptions, pageId: this.id, url }, options);
|
|
151
|
+
}
|
|
152
|
+
async screenshot(options = {}) {
|
|
153
|
+
requireCaptureCapability(this.client, 'page.screenshot', 'screenshotOptions');
|
|
154
|
+
const { signal, timeoutMs, operationId, ...capture } = options;
|
|
155
|
+
const localOptions = {};
|
|
156
|
+
if (signal !== undefined)
|
|
157
|
+
localOptions.signal = signal;
|
|
158
|
+
if (timeoutMs !== undefined)
|
|
159
|
+
localOptions.timeoutMs = timeoutMs;
|
|
160
|
+
if (operationId !== undefined)
|
|
161
|
+
localOptions.operationId = operationId;
|
|
162
|
+
return Buffer.from((await this.invoke('page.screenshot', { ...capture, pageId: this.id }, localOptions)).dataBase64, 'base64');
|
|
163
|
+
}
|
|
164
|
+
async screenshotToFile(options) {
|
|
165
|
+
requireCaptureCapability(this.client, 'page.screenshot_to_file', 'screenshotFile');
|
|
166
|
+
const { signal, timeoutMs, operationId, path, ...capture } = options;
|
|
167
|
+
const localOptions = {};
|
|
168
|
+
if (signal !== undefined)
|
|
169
|
+
localOptions.signal = signal;
|
|
170
|
+
if (timeoutMs !== undefined)
|
|
171
|
+
localOptions.timeoutMs = timeoutMs;
|
|
172
|
+
if (operationId !== undefined)
|
|
173
|
+
localOptions.operationId = operationId;
|
|
174
|
+
return this.invoke('page.screenshot_to_file', { ...capture, pageId: this.id, path: resolve(path) }, localOptions);
|
|
175
|
+
}
|
|
176
|
+
async record(options) {
|
|
177
|
+
const id = options.recordingId ?? randomUUID();
|
|
178
|
+
let path;
|
|
179
|
+
try {
|
|
180
|
+
path = resolve(options.path);
|
|
181
|
+
requireCaptureCapability(this.client, 'recording.start', 'nativeRecording');
|
|
182
|
+
if (!recordingIdPattern.test(id)) {
|
|
183
|
+
throw new RecordingError('Configuration', 'recordingId must be a UUID.', id, undefined, { requestState: 'not_sent' }, path);
|
|
184
|
+
}
|
|
185
|
+
const { signal, timeoutMs, operationId, recordingId, path: outputPath, ...nativeOptions } = options;
|
|
186
|
+
const localOptions = {};
|
|
187
|
+
if (signal !== undefined)
|
|
188
|
+
localOptions.signal = signal;
|
|
189
|
+
if (timeoutMs !== undefined)
|
|
190
|
+
localOptions.timeoutMs = timeoutMs;
|
|
191
|
+
if (operationId !== undefined)
|
|
192
|
+
localOptions.operationId = operationId;
|
|
193
|
+
const record = await this.invoke('recording.start', { ...nativeOptions, pageId: this.id, recordingId: id, path }, localOptions);
|
|
194
|
+
validateRecordingRecord(record, id, this.id, path);
|
|
195
|
+
if (record.state === 'failed' || record.state === 'cancelled') {
|
|
196
|
+
throw new RecordingError(record.failure?.code ?? 'RecordingInvalidState', record.failure?.message ?? `Recording ${id} is ${record.state}.`, id, record, { requestState: 'acknowledged' });
|
|
197
|
+
}
|
|
198
|
+
return new Recording(this.client, id, record);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
throw recordingFailure(error, id, undefined, path, this.id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async setViewport(viewport, options) {
|
|
205
|
+
await this.invoke('page.set_viewport', { ...viewport, pageId: this.id }, options);
|
|
206
|
+
}
|
|
207
|
+
async resetViewport(options) {
|
|
208
|
+
await this.invoke('page.reset_viewport', { pageId: this.id }, options);
|
|
209
|
+
}
|
|
210
|
+
observe(options = {}) {
|
|
211
|
+
const { observationTimeoutMs, maxControls, ...localOptions } = options;
|
|
212
|
+
const params = { pageId: this.id };
|
|
213
|
+
if (observationTimeoutMs !== undefined)
|
|
214
|
+
params.timeout_ms = observationTimeoutMs;
|
|
215
|
+
if (maxControls !== undefined)
|
|
216
|
+
params.max_controls = maxControls;
|
|
217
|
+
return this.invoke('agent.observe', params, localOptions);
|
|
218
|
+
}
|
|
219
|
+
async step(action, options = {}) {
|
|
220
|
+
const { operationId = randomUUID(), observationTimeoutMs, maxControls, actionTimeoutMs, expect, mode, ...localOptions } = options;
|
|
221
|
+
try {
|
|
222
|
+
const params = { pageId: this.id, action, operation_id: operationId };
|
|
223
|
+
if (expect !== undefined)
|
|
224
|
+
params.expect = expect;
|
|
225
|
+
if (mode !== undefined)
|
|
226
|
+
params.mode = mode;
|
|
227
|
+
if (actionTimeoutMs !== undefined)
|
|
228
|
+
params.action_timeout_ms = actionTimeoutMs;
|
|
229
|
+
if (observationTimeoutMs !== undefined)
|
|
230
|
+
params.timeout_ms = observationTimeoutMs;
|
|
231
|
+
if (maxControls !== undefined)
|
|
232
|
+
params.max_controls = maxControls;
|
|
233
|
+
const callOptions = localOptions;
|
|
234
|
+
callOptions.operationId = operationId;
|
|
235
|
+
const result = await this.invoke('agent.step', params, callOptions);
|
|
236
|
+
if (result.operation_id !== operationId) {
|
|
237
|
+
throw new OperationError('Protocol', `Received an agent result for a different operation than ${operationId}.`, operationId, result.operation ?? undefined, { requestState: 'acknowledged' });
|
|
238
|
+
}
|
|
239
|
+
if (result.operation != null)
|
|
240
|
+
validateOperationRecord(result.operation, operationId, this.id);
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
throw operationFailure(error, operationId);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async close(options) {
|
|
248
|
+
await this.invoke('page.close', { pageId: this.id }, options);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const platformIds: readonly ["linux-x64-gnu", "linux-arm64-gnu", "darwin-x64", "darwin-arm64", "win32-x64"];
|
|
2
|
+
export type PlatformId = typeof platformIds[number];
|
|
3
|
+
export declare function selectPlatform(os: string, arch: string, glibcRuntimeVersion?: string): PlatformId;
|
|
4
|
+
export declare function detectPlatform(): PlatformId;
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { InstallationError } from './install-errors.js';
|
|
2
|
+
export const platformIds = ['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-x64', 'darwin-arm64', 'win32-x64'];
|
|
3
|
+
export function selectPlatform(os, arch, glibcRuntimeVersion) {
|
|
4
|
+
if (os === 'linux' && (arch === 'x64' || arch === 'arm64')) {
|
|
5
|
+
const version = glibcRuntimeVersion?.match(/^(\d+)\.(\d+)(?:\.\d+)?$/);
|
|
6
|
+
if (!version) {
|
|
7
|
+
throw new InstallationError('UnsupportedPlatform', 'Managed Eoka requires GNU/Linux with glibc >= 2.35; musl/Alpine and unidentified libc are unsupported. Use explicit serverPath and executablePath only as an expert override.');
|
|
8
|
+
}
|
|
9
|
+
const major = Number(version[1]);
|
|
10
|
+
const minor = Number(version[2]);
|
|
11
|
+
if (major < 2 || (major === 2 && minor < 35)) {
|
|
12
|
+
throw new InstallationError('UnsupportedPlatform', `Managed Eoka requires glibc >= 2.35; detected ${glibcRuntimeVersion}. Upgrade the OS or supply both binaries explicitly.`);
|
|
13
|
+
}
|
|
14
|
+
return arch === 'x64' ? 'linux-x64-gnu' : 'linux-arm64-gnu';
|
|
15
|
+
}
|
|
16
|
+
if (os === 'darwin' && arch === 'x64')
|
|
17
|
+
return 'darwin-x64';
|
|
18
|
+
if (os === 'darwin' && arch === 'arm64')
|
|
19
|
+
return 'darwin-arm64';
|
|
20
|
+
if (os === 'win32' && arch === 'x64')
|
|
21
|
+
return 'win32-x64';
|
|
22
|
+
throw new InstallationError('UnsupportedPlatform', `Managed Eoka does not support ${os}/${arch}. Supported platforms: ${platformIds.join(', ')}. Supply both binaries explicitly only as an expert override.`);
|
|
23
|
+
}
|
|
24
|
+
export function detectPlatform() {
|
|
25
|
+
const report = process.platform === 'linux' ? process.report.getReport() : undefined;
|
|
26
|
+
return selectPlatform(process.platform, process.arch, report?.header.glibcVersionRuntime);
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CallOptions, InvokeClient } from './client.js';
|
|
2
|
+
import { EokaError, type ErrorDetails } from './errors.js';
|
|
3
|
+
import type { Artifact, RecordingFailure, RecordingRecord } from './generated/protocol.js';
|
|
4
|
+
export declare function requireCaptureCapability(client: InvokeClient, method: string, capability: string): void;
|
|
5
|
+
export declare class RecordingError extends EokaError {
|
|
6
|
+
readonly recordingId: string;
|
|
7
|
+
readonly record: RecordingRecord | undefined;
|
|
8
|
+
readonly failure: RecordingFailure | undefined;
|
|
9
|
+
readonly path: string | undefined;
|
|
10
|
+
readonly partialPath: string | undefined;
|
|
11
|
+
readonly cleanupUncertain: boolean | undefined;
|
|
12
|
+
constructor(code: string, message: string, recordingId: string, record?: RecordingRecord, details?: ErrorDetails, path?: string);
|
|
13
|
+
}
|
|
14
|
+
export declare function recordingFailure(error: unknown, id: string, record?: RecordingRecord, path?: string, pageId?: string): RecordingError;
|
|
15
|
+
export declare function validateRecordingRecord(record: RecordingRecord, id: string, pageId?: string, path?: string): void;
|
|
16
|
+
export declare class Recording {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
private readonly client;
|
|
19
|
+
private latest;
|
|
20
|
+
constructor(client: InvokeClient, id: string, record?: RecordingRecord);
|
|
21
|
+
get record(): RecordingRecord | undefined;
|
|
22
|
+
private remember;
|
|
23
|
+
private call;
|
|
24
|
+
status(options?: CallOptions): Promise<RecordingRecord>;
|
|
25
|
+
stop(options?: CallOptions): Promise<Artifact>;
|
|
26
|
+
cancel(options?: CallOptions): Promise<RecordingRecord>;
|
|
27
|
+
}
|