@mercuryo-ai/agentbrowse 0.2.50
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/CHANGELOG.md +15 -0
- package/README.md +335 -0
- package/dist/assistive-runtime.d.ts +110 -0
- package/dist/assistive-runtime.d.ts.map +1 -0
- package/dist/assistive-runtime.js +79 -0
- package/dist/assistive-runtime.test-support.d.ts +7 -0
- package/dist/assistive-runtime.test-support.d.ts.map +1 -0
- package/dist/assistive-runtime.test-support.js +106 -0
- package/dist/assistive-stagehand.d.ts +12 -0
- package/dist/assistive-stagehand.d.ts.map +1 -0
- package/dist/assistive-stagehand.js +10 -0
- package/dist/browser-session-state.d.ts +95 -0
- package/dist/browser-session-state.d.ts.map +1 -0
- package/dist/browser-session-state.js +279 -0
- package/dist/client-bindings.d.ts +10 -0
- package/dist/client-bindings.d.ts.map +1 -0
- package/dist/client-bindings.js +18 -0
- package/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +63 -0
- package/dist/command-api-tracing.d.ts +20 -0
- package/dist/command-api-tracing.d.ts.map +1 -0
- package/dist/command-api-tracing.js +149 -0
- package/dist/command-name.d.ts +3 -0
- package/dist/command-name.d.ts.map +1 -0
- package/dist/command-name.js +11 -0
- package/dist/commands/act.d.ts +43 -0
- package/dist/commands/act.d.ts.map +1 -0
- package/dist/commands/act.js +1107 -0
- package/dist/commands/action-acceptance.d.ts +93 -0
- package/dist/commands/action-acceptance.d.ts.map +1 -0
- package/dist/commands/action-acceptance.js +1938 -0
- package/dist/commands/action-artifacts.d.ts +33 -0
- package/dist/commands/action-artifacts.d.ts.map +1 -0
- package/dist/commands/action-artifacts.js +104 -0
- package/dist/commands/action-execution-guards.d.ts +5 -0
- package/dist/commands/action-execution-guards.d.ts.map +1 -0
- package/dist/commands/action-execution-guards.js +3 -0
- package/dist/commands/action-executor-helpers.d.ts +21 -0
- package/dist/commands/action-executor-helpers.d.ts.map +1 -0
- package/dist/commands/action-executor-helpers.js +265 -0
- package/dist/commands/action-executor.d.ts +14 -0
- package/dist/commands/action-executor.d.ts.map +1 -0
- package/dist/commands/action-executor.js +46 -0
- package/dist/commands/action-fallbacks.d.ts +6 -0
- package/dist/commands/action-fallbacks.d.ts.map +1 -0
- package/dist/commands/action-fallbacks.js +43 -0
- package/dist/commands/action-result-resolution.d.ts +17 -0
- package/dist/commands/action-result-resolution.d.ts.map +1 -0
- package/dist/commands/action-result-resolution.js +132 -0
- package/dist/commands/action-value-projection.d.ts +32 -0
- package/dist/commands/action-value-projection.d.ts.map +1 -0
- package/dist/commands/action-value-projection.js +151 -0
- package/dist/commands/attach.d.ts +41 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +103 -0
- package/dist/commands/browse-actions.d.ts +4 -0
- package/dist/commands/browse-actions.d.ts.map +1 -0
- package/dist/commands/browse-actions.js +4 -0
- package/dist/commands/browser-status.d.ts +57 -0
- package/dist/commands/browser-status.d.ts.map +1 -0
- package/dist/commands/browser-status.js +243 -0
- package/dist/commands/click-action-executor.d.ts +12 -0
- package/dist/commands/click-action-executor.d.ts.map +1 -0
- package/dist/commands/click-action-executor.js +111 -0
- package/dist/commands/click-activation-policy.d.ts +5 -0
- package/dist/commands/click-activation-policy.d.ts.map +1 -0
- package/dist/commands/click-activation-policy.js +13 -0
- package/dist/commands/close.d.ts +26 -0
- package/dist/commands/close.d.ts.map +1 -0
- package/dist/commands/close.js +124 -0
- package/dist/commands/datepicker-action-executor.d.ts +12 -0
- package/dist/commands/datepicker-action-executor.d.ts.map +1 -0
- package/dist/commands/datepicker-action-executor.js +218 -0
- package/dist/commands/descriptor-validation.d.ts +27 -0
- package/dist/commands/descriptor-validation.d.ts.map +1 -0
- package/dist/commands/descriptor-validation.js +192 -0
- package/dist/commands/extract-scope-resolution.d.ts +20 -0
- package/dist/commands/extract-scope-resolution.d.ts.map +1 -0
- package/dist/commands/extract-scope-resolution.js +109 -0
- package/dist/commands/extract-scoped-dialog-text.d.ts +3 -0
- package/dist/commands/extract-scoped-dialog-text.d.ts.map +1 -0
- package/dist/commands/extract-scoped-dialog-text.js +210 -0
- package/dist/commands/extract-snapshot-sanitizer.d.ts +5 -0
- package/dist/commands/extract-snapshot-sanitizer.d.ts.map +1 -0
- package/dist/commands/extract-snapshot-sanitizer.js +98 -0
- package/dist/commands/extract-stagehand-executor.d.ts +17 -0
- package/dist/commands/extract-stagehand-executor.d.ts.map +1 -0
- package/dist/commands/extract-stagehand-executor.js +112 -0
- package/dist/commands/extract.d.ts +57 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +668 -0
- package/dist/commands/interaction-kernel.d.ts +46 -0
- package/dist/commands/interaction-kernel.d.ts.map +1 -0
- package/dist/commands/interaction-kernel.js +215 -0
- package/dist/commands/launch.d.ts +41 -0
- package/dist/commands/launch.d.ts.map +1 -0
- package/dist/commands/launch.js +182 -0
- package/dist/commands/navigate.d.ts +31 -0
- package/dist/commands/navigate.d.ts.map +1 -0
- package/dist/commands/navigate.js +202 -0
- package/dist/commands/observe-accessibility.d.ts +22 -0
- package/dist/commands/observe-accessibility.d.ts.map +1 -0
- package/dist/commands/observe-accessibility.js +566 -0
- package/dist/commands/observe-display-label.d.ts +4 -0
- package/dist/commands/observe-display-label.d.ts.map +1 -0
- package/dist/commands/observe-display-label.js +26 -0
- package/dist/commands/observe-dom-label-contract.d.ts +2 -0
- package/dist/commands/observe-dom-label-contract.d.ts.map +1 -0
- package/dist/commands/observe-dom-label-contract.js +564 -0
- package/dist/commands/observe-fallback-semantics.d.ts +6 -0
- package/dist/commands/observe-fallback-semantics.d.ts.map +1 -0
- package/dist/commands/observe-fallback-semantics.js +86 -0
- package/dist/commands/observe-inventory.d.ts +149 -0
- package/dist/commands/observe-inventory.d.ts.map +1 -0
- package/dist/commands/observe-inventory.js +3545 -0
- package/dist/commands/observe-label-policy.d.ts +8 -0
- package/dist/commands/observe-label-policy.d.ts.map +1 -0
- package/dist/commands/observe-label-policy.js +21 -0
- package/dist/commands/observe-page-state.d.ts +11 -0
- package/dist/commands/observe-page-state.d.ts.map +1 -0
- package/dist/commands/observe-page-state.js +89 -0
- package/dist/commands/observe-persistence.d.ts +15 -0
- package/dist/commands/observe-persistence.d.ts.map +1 -0
- package/dist/commands/observe-persistence.js +238 -0
- package/dist/commands/observe-projection.d.ts +119 -0
- package/dist/commands/observe-projection.d.ts.map +1 -0
- package/dist/commands/observe-projection.js +726 -0
- package/dist/commands/observe-protected.d.ts +6 -0
- package/dist/commands/observe-protected.d.ts.map +1 -0
- package/dist/commands/observe-protected.js +31 -0
- package/dist/commands/observe-semantics.d.ts +10 -0
- package/dist/commands/observe-semantics.d.ts.map +1 -0
- package/dist/commands/observe-semantics.js +535 -0
- package/dist/commands/observe-signals.d.ts +48 -0
- package/dist/commands/observe-signals.d.ts.map +1 -0
- package/dist/commands/observe-signals.js +461 -0
- package/dist/commands/observe-stagehand.d.ts +49 -0
- package/dist/commands/observe-stagehand.d.ts.map +1 -0
- package/dist/commands/observe-stagehand.js +94 -0
- package/dist/commands/observe-surfaces.d.ts +11 -0
- package/dist/commands/observe-surfaces.d.ts.map +1 -0
- package/dist/commands/observe-surfaces.js +290 -0
- package/dist/commands/observe.d.ts +113 -0
- package/dist/commands/observe.d.ts.map +1 -0
- package/dist/commands/observe.js +556 -0
- package/dist/commands/screenshot.d.ts +37 -0
- package/dist/commands/screenshot.d.ts.map +1 -0
- package/dist/commands/screenshot.js +269 -0
- package/dist/commands/select-action-executor.d.ts +10 -0
- package/dist/commands/select-action-executor.d.ts.map +1 -0
- package/dist/commands/select-action-executor.js +156 -0
- package/dist/commands/semantic-observe-lexical.d.ts +31 -0
- package/dist/commands/semantic-observe-lexical.d.ts.map +1 -0
- package/dist/commands/semantic-observe-lexical.js +186 -0
- package/dist/commands/semantic-observe.d.ts +37 -0
- package/dist/commands/semantic-observe.d.ts.map +1 -0
- package/dist/commands/semantic-observe.js +1339 -0
- package/dist/commands/structured-grid-action-executor.d.ts +3 -0
- package/dist/commands/structured-grid-action-executor.d.ts.map +1 -0
- package/dist/commands/structured-grid-action-executor.js +4 -0
- package/dist/commands/target-resolution.d.ts +4 -0
- package/dist/commands/target-resolution.d.ts.map +1 -0
- package/dist/commands/target-resolution.js +33 -0
- package/dist/commands/text-input-action-executor.d.ts +5 -0
- package/dist/commands/text-input-action-executor.d.ts.map +1 -0
- package/dist/commands/text-input-action-executor.js +116 -0
- package/dist/commands/user-actionable.d.ts +4 -0
- package/dist/commands/user-actionable.d.ts.map +1 -0
- package/dist/commands/user-actionable.js +216 -0
- package/dist/control-semantics.d.ts +30 -0
- package/dist/control-semantics.d.ts.map +1 -0
- package/dist/control-semantics.js +419 -0
- package/dist/diagnostics.d.ts +132 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +120 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +350 -0
- package/dist/library.d.ts +17 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +14 -0
- package/dist/output.d.ts +32 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +33 -0
- package/dist/owned-browser.d.ts +12 -0
- package/dist/owned-browser.d.ts.map +1 -0
- package/dist/owned-browser.js +69 -0
- package/dist/owned-process.d.ts +19 -0
- package/dist/owned-process.d.ts.map +1 -0
- package/dist/owned-process.js +145 -0
- package/dist/playwright-runtime.d.ts +43 -0
- package/dist/playwright-runtime.d.ts.map +1 -0
- package/dist/playwright-runtime.js +339 -0
- package/dist/protected-fill-browser.d.ts +22 -0
- package/dist/protected-fill-browser.d.ts.map +1 -0
- package/dist/protected-fill-browser.js +52 -0
- package/dist/protected-fill.d.ts +82 -0
- package/dist/protected-fill.d.ts.map +1 -0
- package/dist/protected-fill.js +20 -0
- package/dist/runtime-metrics.d.ts +27 -0
- package/dist/runtime-metrics.d.ts.map +1 -0
- package/dist/runtime-metrics.js +66 -0
- package/dist/runtime-page-state.d.ts +11 -0
- package/dist/runtime-page-state.d.ts.map +1 -0
- package/dist/runtime-page-state.js +62 -0
- package/dist/runtime-protected-state.d.ts +14 -0
- package/dist/runtime-protected-state.d.ts.map +1 -0
- package/dist/runtime-protected-state.js +148 -0
- package/dist/runtime-resolution.d.ts +9 -0
- package/dist/runtime-resolution.d.ts.map +1 -0
- package/dist/runtime-resolution.js +19 -0
- package/dist/runtime-state.d.ts +251 -0
- package/dist/runtime-state.d.ts.map +1 -0
- package/dist/runtime-state.js +599 -0
- package/dist/secrets/catalog-applicability.d.ts +5 -0
- package/dist/secrets/catalog-applicability.d.ts.map +1 -0
- package/dist/secrets/catalog-applicability.js +59 -0
- package/dist/secrets/field-policy.d.ts +3 -0
- package/dist/secrets/field-policy.d.ts.map +1 -0
- package/dist/secrets/field-policy.js +3 -0
- package/dist/secrets/fill-ordering.d.ts +10 -0
- package/dist/secrets/fill-ordering.d.ts.map +1 -0
- package/dist/secrets/fill-ordering.js +41 -0
- package/dist/secrets/form-matcher.d.ts +60 -0
- package/dist/secrets/form-matcher.d.ts.map +1 -0
- package/dist/secrets/form-matcher.js +948 -0
- package/dist/secrets/protected-artifact-guard.d.ts +39 -0
- package/dist/secrets/protected-artifact-guard.d.ts.map +1 -0
- package/dist/secrets/protected-artifact-guard.js +44 -0
- package/dist/secrets/protected-bindings.d.ts +14 -0
- package/dist/secrets/protected-bindings.d.ts.map +1 -0
- package/dist/secrets/protected-bindings.js +29 -0
- package/dist/secrets/protected-exact-value-redaction.d.ts +14 -0
- package/dist/secrets/protected-exact-value-redaction.d.ts.map +1 -0
- package/dist/secrets/protected-exact-value-redaction.js +360 -0
- package/dist/secrets/protected-field-semantics.d.ts +9 -0
- package/dist/secrets/protected-field-semantics.d.ts.map +1 -0
- package/dist/secrets/protected-field-semantics.js +154 -0
- package/dist/secrets/protected-field-values.d.ts +15 -0
- package/dist/secrets/protected-field-values.d.ts.map +1 -0
- package/dist/secrets/protected-field-values.js +131 -0
- package/dist/secrets/protected-fill.d.ts +47 -0
- package/dist/secrets/protected-fill.d.ts.map +1 -0
- package/dist/secrets/protected-fill.js +446 -0
- package/dist/secrets/protected-value-adapters.d.ts +4 -0
- package/dist/secrets/protected-value-adapters.d.ts.map +1 -0
- package/dist/secrets/protected-value-adapters.js +118 -0
- package/dist/secrets/types.d.ts +70 -0
- package/dist/secrets/types.d.ts.map +1 -0
- package/dist/secrets/types.js +30 -0
- package/dist/session.d.ts +19 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +120 -0
- package/dist/solver/browser-launcher.d.ts +14 -0
- package/dist/solver/browser-launcher.d.ts.map +1 -0
- package/dist/solver/browser-launcher.js +799 -0
- package/dist/solver/config.d.ts +18 -0
- package/dist/solver/config.d.ts.map +1 -0
- package/dist/solver/config.js +67 -0
- package/dist/solver/fingerprint.d.ts +9 -0
- package/dist/solver/fingerprint.d.ts.map +1 -0
- package/dist/solver/fingerprint.js +96 -0
- package/dist/solver/profile-manager.d.ts +8 -0
- package/dist/solver/profile-manager.d.ts.map +1 -0
- package/dist/solver/profile-manager.js +74 -0
- package/dist/solver/turnstile-challenge.d.ts +3 -0
- package/dist/solver/turnstile-challenge.d.ts.map +1 -0
- package/dist/solver/turnstile-challenge.js +173 -0
- package/dist/solver/types.d.ts +67 -0
- package/dist/solver/types.d.ts.map +1 -0
- package/dist/solver/types.js +1 -0
- package/dist/stagehand-runtime.d.ts +4 -0
- package/dist/stagehand-runtime.d.ts.map +1 -0
- package/dist/stagehand-runtime.js +10 -0
- package/dist/stagehand.d.ts +15 -0
- package/dist/stagehand.d.ts.map +1 -0
- package/dist/stagehand.js +19 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +4 -0
- package/dist/update-check.d.ts +14 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +182 -0
- package/dist/workflow-session-state.d.ts +30 -0
- package/dist/workflow-session-state.d.ts.map +1 -0
- package/dist/workflow-session-state.js +74 -0
- package/docs/README.md +25 -0
- package/docs/api-reference.md +242 -0
- package/docs/assistive-runtime.md +148 -0
- package/docs/configuration.md +287 -0
- package/docs/getting-started.md +237 -0
- package/docs/integration-checklist.md +36 -0
- package/docs/protected-fill.md +112 -0
- package/docs/testing.md +50 -0
- package/docs/troubleshooting.md +71 -0
- package/examples/README.md +18 -0
- package/examples/attach.ts +27 -0
- package/examples/basic.ts +36 -0
- package/examples/extract.ts +50 -0
- package/package.json +83 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { connectConfiguredAssistiveStagehand } from './assistive-runtime.js';
|
|
2
|
+
/**
|
|
3
|
+
* Connect Stagehand with the currently configured assistive runtime.
|
|
4
|
+
*
|
|
5
|
+
* This stays separate from the generic Stagehand connector so the browser-core
|
|
6
|
+
* layer does not own orchestration/backend setup directly.
|
|
7
|
+
*/
|
|
8
|
+
export async function connectAssistiveStagehand(cdpUrl, options = {}) {
|
|
9
|
+
return connectConfiguredAssistiveStagehand(cdpUrl, options);
|
|
10
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { BrowseRuntimeState } from "./runtime-state.js";
|
|
2
|
+
import type { ProxyConfig } from "./solver/types.js";
|
|
3
|
+
/** Browser capabilities discovered or provisioned for the session. */
|
|
4
|
+
export interface BrowserSessionCapabilities {
|
|
5
|
+
captchaSolve?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** Persisted browser session state shared across AgentBrowse commands. */
|
|
8
|
+
export interface BrowserSessionState {
|
|
9
|
+
cdpUrl: string;
|
|
10
|
+
pid?: number;
|
|
11
|
+
launchedAt: string;
|
|
12
|
+
port?: number;
|
|
13
|
+
profile?: string;
|
|
14
|
+
identity?: BrowseSessionIdentity;
|
|
15
|
+
transport?: BrowseSessionTransport;
|
|
16
|
+
capabilities?: BrowserSessionCapabilities;
|
|
17
|
+
runtime?: BrowseRuntimeState;
|
|
18
|
+
}
|
|
19
|
+
/** Browser session state plus transient run-scoped metadata. */
|
|
20
|
+
export interface BrowserCommandSession extends BrowserSessionState {
|
|
21
|
+
activeRunId?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Stable identity metadata for an attached or owned browser session. */
|
|
24
|
+
export interface BrowseSessionIdentity {
|
|
25
|
+
browserInstanceRef: string;
|
|
26
|
+
endpoint: string;
|
|
27
|
+
pid?: number;
|
|
28
|
+
profile?: string;
|
|
29
|
+
provider?: string;
|
|
30
|
+
launchedAt: string;
|
|
31
|
+
ownership: "agentbrowse" | "external";
|
|
32
|
+
}
|
|
33
|
+
/** Transport metadata for the attached browser connection. */
|
|
34
|
+
export interface BrowseSessionTransport {
|
|
35
|
+
proxyMode: "direct" | "proxy";
|
|
36
|
+
proxy?: ProxyConfig;
|
|
37
|
+
}
|
|
38
|
+
/** Filesystem-backed session store used by the CLI and local wrappers. */
|
|
39
|
+
export interface BrowserSessionStore {
|
|
40
|
+
readonly rootDir: string;
|
|
41
|
+
readonly sessionPath: string;
|
|
42
|
+
serialize(session: BrowserSessionState): string;
|
|
43
|
+
save(session: BrowserSessionState): void;
|
|
44
|
+
load(): BrowserSessionState | null;
|
|
45
|
+
delete(): void;
|
|
46
|
+
}
|
|
47
|
+
type ManagedBrowserSessionInput = Omit<BrowserSessionState, "port" | "identity" | "pid" | "capabilities"> & {
|
|
48
|
+
pid: number;
|
|
49
|
+
capabilities?: BrowserSessionCapabilities;
|
|
50
|
+
};
|
|
51
|
+
type AttachedBrowserSessionInput = Omit<BrowserSessionState, "port" | "identity" | "pid" | "profile" | "capabilities"> & {
|
|
52
|
+
capabilities?: BrowserSessionCapabilities;
|
|
53
|
+
browserInstanceRef?: string;
|
|
54
|
+
provider?: string;
|
|
55
|
+
};
|
|
56
|
+
export declare function parseSessionPort(cdpUrl: string): number | undefined;
|
|
57
|
+
/** Converts a CDP websocket or HTTP endpoint into the matching DevTools HTTP endpoint. */
|
|
58
|
+
export declare function buildCdpHttpEndpointUrl(cdpUrl: string, resourcePath?: "/json/version" | "/json/list"): string | null;
|
|
59
|
+
/** Extracts a stable browser instance reference from a CDP endpoint. */
|
|
60
|
+
export declare function parseBrowserInstanceRef(cdpUrl: string): string;
|
|
61
|
+
/** Serializes a browser session while omitting protected value payloads. */
|
|
62
|
+
export declare function serializeBrowserSession(session: BrowserSessionState): string;
|
|
63
|
+
/** Creates the default filesystem-backed session store used by AgentBrowse. */
|
|
64
|
+
export declare function createBrowserSessionStore(options?: {
|
|
65
|
+
rootDir?: string;
|
|
66
|
+
sessionFileName?: string;
|
|
67
|
+
}): BrowserSessionStore;
|
|
68
|
+
/** Saves the current browser session to the default local session store. */
|
|
69
|
+
export declare function saveBrowserSession(session: BrowserSessionState): void;
|
|
70
|
+
/** Loads the current browser session from the default local session store. */
|
|
71
|
+
export declare function loadBrowserSession(): BrowserSessionState | null;
|
|
72
|
+
/** Deletes the current browser session from the default local session store. */
|
|
73
|
+
export declare function deleteBrowserSession(): void;
|
|
74
|
+
/** Resolves a stable browser identifier for logs, tracing, and local state. */
|
|
75
|
+
export declare function resolveBrowserSessionId(session: Pick<BrowserSessionState, "cdpUrl" | "identity" | "pid">): string;
|
|
76
|
+
/** Builds a managed AgentBrowse-owned browser session snapshot. */
|
|
77
|
+
export declare function buildOwnedSession(session: ManagedBrowserSessionInput): BrowserSessionState;
|
|
78
|
+
/** Builds an attached external browser session snapshot. */
|
|
79
|
+
export declare function buildAttachedSession(session: AttachedBrowserSessionInput): BrowserSessionState;
|
|
80
|
+
/** Returns the most likely DevTools port for the current session. */
|
|
81
|
+
export declare function getSessionPort(session: BrowserSessionState | null): number;
|
|
82
|
+
/** Returns `true` when the session advertises captcha-solving capability. */
|
|
83
|
+
export declare function supportsCaptchaSolve(session: BrowserSessionState | null): boolean;
|
|
84
|
+
/** Returns `true` when the session belongs to an AgentBrowse-managed browser. */
|
|
85
|
+
export declare function isOwnedSession(session: BrowserSessionState | null | undefined): session is BrowserSessionState & {
|
|
86
|
+
identity: BrowseSessionIdentity;
|
|
87
|
+
};
|
|
88
|
+
/** Returns `true` when the session refers to an externally managed browser. */
|
|
89
|
+
export declare function isAttachedSession(session: BrowserSessionState | null | undefined): session is BrowserSessionState & {
|
|
90
|
+
identity: BrowseSessionIdentity;
|
|
91
|
+
};
|
|
92
|
+
/** Checks whether the persisted browser session still points to a live browser instance. */
|
|
93
|
+
export declare function isSessionAlive(session: BrowserSessionState): Promise<boolean>;
|
|
94
|
+
export {};
|
|
95
|
+
//# sourceMappingURL=browser-session-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-session-state.d.ts","sourceRoot":"","sources":["../src/browser-session-state.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,sEAAsE;AACtE,MAAM,WAAW,0BAA0B;IACzC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,0EAA0E;AAC1E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,SAAS,CAAC,EAAE,sBAAsB,CAAC;IACnC,YAAY,CAAC,EAAE,0BAA0B,CAAC;IAC1C,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,gEAAgE;AAChE,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,yEAAyE;AACzE,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAA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G,SAAS,GAC9C,OAAO,IAAI,mBAAmB,GAAG;IAAE,QAAQ,EAAE,qBAAqB,CAAA;CAAE,CAWtE;AAED,4FAA4F;AAC5F,wBAAsB,cAAc,CAClC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,CA0BlB"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { scrubProtectedExactValues } from "./secrets/protected-exact-value-redaction.js";
|
|
5
|
+
const BLOCKED_SESSION_KEYS = new Set([
|
|
6
|
+
"rawValue",
|
|
7
|
+
"rawValues",
|
|
8
|
+
"secretValue",
|
|
9
|
+
"secretValues",
|
|
10
|
+
"resolvedValues",
|
|
11
|
+
"protectedValues",
|
|
12
|
+
]);
|
|
13
|
+
function getDefaultAgentbrowseStateDir() {
|
|
14
|
+
return join(homedir(), ".agentbrowse");
|
|
15
|
+
}
|
|
16
|
+
function getBrowserSessionPath(stateDir, sessionFileName) {
|
|
17
|
+
return join(stateDir, sessionFileName);
|
|
18
|
+
}
|
|
19
|
+
function ensureStateDir(stateDir) {
|
|
20
|
+
if (!existsSync(stateDir)) {
|
|
21
|
+
mkdirSync(stateDir, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function atomicWriteJson(path, contents) {
|
|
25
|
+
const tempPath = `${path}.${process.pid}.tmp`;
|
|
26
|
+
try {
|
|
27
|
+
writeFileSync(tempPath, contents);
|
|
28
|
+
renameSync(tempPath, path);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
rmSync(tempPath, { force: true });
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function parseSessionPort(cdpUrl) {
|
|
36
|
+
try {
|
|
37
|
+
const url = new URL(cdpUrl);
|
|
38
|
+
if (!url.port) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const port = Number(url.port);
|
|
42
|
+
return Number.isFinite(port) && port > 0 ? port : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Converts a CDP websocket or HTTP endpoint into the matching DevTools HTTP endpoint. */
|
|
49
|
+
export function buildCdpHttpEndpointUrl(cdpUrl, resourcePath = "/json/version") {
|
|
50
|
+
try {
|
|
51
|
+
const url = new URL(cdpUrl);
|
|
52
|
+
if (url.protocol === "ws:") {
|
|
53
|
+
url.protocol = "http:";
|
|
54
|
+
}
|
|
55
|
+
else if (url.protocol === "wss:") {
|
|
56
|
+
url.protocol = "https:";
|
|
57
|
+
}
|
|
58
|
+
else if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
url.pathname = resourcePath;
|
|
62
|
+
url.search = "";
|
|
63
|
+
url.hash = "";
|
|
64
|
+
return url.toString();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Extracts a stable browser instance reference from a CDP endpoint. */
|
|
71
|
+
export function parseBrowserInstanceRef(cdpUrl) {
|
|
72
|
+
try {
|
|
73
|
+
const url = new URL(cdpUrl);
|
|
74
|
+
const pathSegments = url.pathname.split("/").filter(Boolean);
|
|
75
|
+
return pathSegments.at(-1) ?? cdpUrl;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
const pathSegments = cdpUrl.split("/").filter(Boolean);
|
|
79
|
+
return pathSegments.at(-1) ?? cdpUrl;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function probeSessionEndpoint(session) {
|
|
83
|
+
const endpoint = session.identity?.endpoint ?? session.cdpUrl;
|
|
84
|
+
const versionUrl = buildCdpHttpEndpointUrl(endpoint, "/json/version");
|
|
85
|
+
if (!versionUrl) {
|
|
86
|
+
return "unreachable";
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const response = await fetch(versionUrl);
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
return "unreachable";
|
|
92
|
+
}
|
|
93
|
+
const payload = (await response.json());
|
|
94
|
+
const liveEndpoint = payload.webSocketDebuggerUrl?.trim();
|
|
95
|
+
if (!liveEndpoint) {
|
|
96
|
+
return "unreachable";
|
|
97
|
+
}
|
|
98
|
+
const expectedEndpoint = session.identity?.endpoint ?? session.cdpUrl;
|
|
99
|
+
if (liveEndpoint === expectedEndpoint) {
|
|
100
|
+
return "match";
|
|
101
|
+
}
|
|
102
|
+
const expectedBrowserInstanceRef = session.identity?.browserInstanceRef ??
|
|
103
|
+
parseBrowserInstanceRef(expectedEndpoint);
|
|
104
|
+
return parseBrowserInstanceRef(liveEndpoint) === expectedBrowserInstanceRef
|
|
105
|
+
? "match"
|
|
106
|
+
: "mismatch";
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
return "unreachable";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Serializes a browser session while omitting protected value payloads. */
|
|
113
|
+
export function serializeBrowserSession(session) {
|
|
114
|
+
const scrubbedSession = scrubProtectedExactValues(session, session);
|
|
115
|
+
return JSON.stringify(scrubbedSession, (key, value) => {
|
|
116
|
+
if (BLOCKED_SESSION_KEYS.has(key)) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}, 2);
|
|
121
|
+
}
|
|
122
|
+
/** Creates the default filesystem-backed session store used by AgentBrowse. */
|
|
123
|
+
export function createBrowserSessionStore(options = {}) {
|
|
124
|
+
const rootDir = options.rootDir ?? getDefaultAgentbrowseStateDir();
|
|
125
|
+
const sessionPath = getBrowserSessionPath(rootDir, options.sessionFileName?.trim() || "browse-session.json");
|
|
126
|
+
return {
|
|
127
|
+
rootDir,
|
|
128
|
+
sessionPath,
|
|
129
|
+
serialize: serializeBrowserSession,
|
|
130
|
+
save(session) {
|
|
131
|
+
ensureStateDir(rootDir);
|
|
132
|
+
atomicWriteJson(sessionPath, serializeBrowserSession(session));
|
|
133
|
+
},
|
|
134
|
+
load() {
|
|
135
|
+
if (!existsSync(sessionPath)) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const raw = JSON.parse(readFileSync(sessionPath, "utf-8"));
|
|
140
|
+
if (!raw.cdpUrl) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return raw;
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
delete() {
|
|
150
|
+
if (existsSync(sessionPath)) {
|
|
151
|
+
unlinkSync(sessionPath);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** Saves the current browser session to the default local session store. */
|
|
157
|
+
export function saveBrowserSession(session) {
|
|
158
|
+
createBrowserSessionStore().save(session);
|
|
159
|
+
}
|
|
160
|
+
/** Loads the current browser session from the default local session store. */
|
|
161
|
+
export function loadBrowserSession() {
|
|
162
|
+
return createBrowserSessionStore().load();
|
|
163
|
+
}
|
|
164
|
+
/** Deletes the current browser session from the default local session store. */
|
|
165
|
+
export function deleteBrowserSession() {
|
|
166
|
+
createBrowserSessionStore().delete();
|
|
167
|
+
}
|
|
168
|
+
/** Resolves a stable browser identifier for logs, tracing, and local state. */
|
|
169
|
+
export function resolveBrowserSessionId(session) {
|
|
170
|
+
if (session.identity?.browserInstanceRef) {
|
|
171
|
+
return session.identity.browserInstanceRef;
|
|
172
|
+
}
|
|
173
|
+
if (typeof session.pid === "number" &&
|
|
174
|
+
Number.isFinite(session.pid) &&
|
|
175
|
+
session.pid > 0) {
|
|
176
|
+
return `pid-${session.pid}`;
|
|
177
|
+
}
|
|
178
|
+
return `cdp-${parseBrowserInstanceRef(session.cdpUrl)}`;
|
|
179
|
+
}
|
|
180
|
+
function buildManagedSessionIdentity(session) {
|
|
181
|
+
return {
|
|
182
|
+
browserInstanceRef: parseBrowserInstanceRef(session.cdpUrl),
|
|
183
|
+
endpoint: session.cdpUrl,
|
|
184
|
+
pid: session.pid,
|
|
185
|
+
profile: session.profile,
|
|
186
|
+
launchedAt: session.launchedAt,
|
|
187
|
+
ownership: "agentbrowse",
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function buildAttachedSessionIdentity(session) {
|
|
191
|
+
return {
|
|
192
|
+
browserInstanceRef: session.browserInstanceRef ?? parseBrowserInstanceRef(session.cdpUrl),
|
|
193
|
+
endpoint: session.cdpUrl,
|
|
194
|
+
...(session.provider ? { provider: session.provider } : {}),
|
|
195
|
+
launchedAt: session.launchedAt,
|
|
196
|
+
ownership: "external",
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/** Builds a managed AgentBrowse-owned browser session snapshot. */
|
|
200
|
+
export function buildOwnedSession(session) {
|
|
201
|
+
return {
|
|
202
|
+
...session,
|
|
203
|
+
port: parseSessionPort(session.cdpUrl),
|
|
204
|
+
identity: buildManagedSessionIdentity(session),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** Builds an attached external browser session snapshot. */
|
|
208
|
+
export function buildAttachedSession(session) {
|
|
209
|
+
return {
|
|
210
|
+
...session,
|
|
211
|
+
port: parseSessionPort(session.cdpUrl),
|
|
212
|
+
identity: buildAttachedSessionIdentity(session),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** Returns the most likely DevTools port for the current session. */
|
|
216
|
+
export function getSessionPort(session) {
|
|
217
|
+
if (session?.port)
|
|
218
|
+
return session.port;
|
|
219
|
+
if (session?.cdpUrl) {
|
|
220
|
+
const parsedPort = parseSessionPort(session.cdpUrl);
|
|
221
|
+
if (parsedPort) {
|
|
222
|
+
return parsedPort;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return 9222;
|
|
226
|
+
}
|
|
227
|
+
/** Returns `true` when the session advertises captcha-solving capability. */
|
|
228
|
+
export function supportsCaptchaSolve(session) {
|
|
229
|
+
return session?.capabilities?.captchaSolve === true;
|
|
230
|
+
}
|
|
231
|
+
/** Returns `true` when the session belongs to an AgentBrowse-managed browser. */
|
|
232
|
+
export function isOwnedSession(session) {
|
|
233
|
+
if (!session?.identity) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (session.identity.ownership !== "agentbrowse") {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return (typeof session.pid === "number" &&
|
|
240
|
+
Number.isFinite(session.pid) &&
|
|
241
|
+
session.identity.endpoint === session.cdpUrl &&
|
|
242
|
+
session.identity.pid === session.pid &&
|
|
243
|
+
session.identity.launchedAt === session.launchedAt &&
|
|
244
|
+
session.identity.browserInstanceRef.length > 0 &&
|
|
245
|
+
session.identity.profile === session.profile);
|
|
246
|
+
}
|
|
247
|
+
/** Returns `true` when the session refers to an externally managed browser. */
|
|
248
|
+
export function isAttachedSession(session) {
|
|
249
|
+
if (!session?.identity) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return (session.identity.ownership === "external" &&
|
|
253
|
+
session.identity.endpoint === session.cdpUrl &&
|
|
254
|
+
session.identity.launchedAt === session.launchedAt &&
|
|
255
|
+
session.identity.browserInstanceRef.length > 0);
|
|
256
|
+
}
|
|
257
|
+
/** Checks whether the persisted browser session still points to a live browser instance. */
|
|
258
|
+
export async function isSessionAlive(session) {
|
|
259
|
+
const endpointProbe = await probeSessionEndpoint(session);
|
|
260
|
+
if (endpointProbe === "match") {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
if (endpointProbe === "mismatch" ||
|
|
264
|
+
session.identity?.ownership === "agentbrowse") {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (typeof session.pid !== "number" ||
|
|
268
|
+
!Number.isFinite(session.pid) ||
|
|
269
|
+
session.pid <= 0) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
process.kill(session.pid, 0);
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BrowserSessionState } from './browser-session-state.js';
|
|
2
|
+
import type { AgentbrowseAssistiveRuntime } from './assistive-runtime.js';
|
|
3
|
+
import type { AgentbrowseDiagnosticsHooks } from './diagnostics.js';
|
|
4
|
+
export interface AgentbrowseSessionBindings {
|
|
5
|
+
assistiveRuntime?: AgentbrowseAssistiveRuntime | null;
|
|
6
|
+
diagnostics?: AgentbrowseDiagnosticsHooks | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function bindAgentbrowseSession(session: BrowserSessionState, bindings: AgentbrowseSessionBindings): BrowserSessionState;
|
|
9
|
+
export declare function getAgentbrowseSessionBindings(session: BrowserSessionState | null | undefined): AgentbrowseSessionBindings | null;
|
|
10
|
+
//# sourceMappingURL=client-bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-bindings.d.ts","sourceRoot":"","sources":["../src/client-bindings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,WAAW,0BAA0B;IACzC,gBAAgB,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAC;IACtD,WAAW,CAAC,EAAE,2BAA2B,GAAG,IAAI,CAAC;CAClD;AAID,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,0BAA0B,GACnC,mBAAmB,CAWrB;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,mBAAmB,GAAG,IAAI,GAAG,SAAS,GAC9C,0BAA0B,GAAG,IAAI,CAMnC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const bindingsBySession = new WeakMap();
|
|
2
|
+
export function bindAgentbrowseSession(session, bindings) {
|
|
3
|
+
if (!bindings.assistiveRuntime && !bindings.diagnostics) {
|
|
4
|
+
bindingsBySession.delete(session);
|
|
5
|
+
return session;
|
|
6
|
+
}
|
|
7
|
+
bindingsBySession.set(session, {
|
|
8
|
+
...(bindings.assistiveRuntime ? { assistiveRuntime: bindings.assistiveRuntime } : {}),
|
|
9
|
+
...(bindings.diagnostics ? { diagnostics: bindings.diagnostics } : {}),
|
|
10
|
+
});
|
|
11
|
+
return session;
|
|
12
|
+
}
|
|
13
|
+
export function getAgentbrowseSessionBindings(session) {
|
|
14
|
+
if (!session) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return bindingsBySession.get(session) ?? null;
|
|
18
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BrowserCommandSession, BrowserSessionState } from './browser-session-state.js';
|
|
2
|
+
import type { AgentbrowseAssistiveRuntime } from './assistive-runtime.js';
|
|
3
|
+
import type { AgentbrowseDiagnosticsHooks } from './diagnostics.js';
|
|
4
|
+
import { type ActResult, type BrowseAction } from './commands/act.js';
|
|
5
|
+
import { type AttachOptions, type AttachResult } from './commands/attach.js';
|
|
6
|
+
import { type BrowserStatusResult } from './commands/browser-status.js';
|
|
7
|
+
import { type CloseResult } from './commands/close.js';
|
|
8
|
+
import { type ExtractResult, type ExtractSchemaInput } from './commands/extract.js';
|
|
9
|
+
import { type LaunchOptions, type LaunchResult } from './commands/launch.js';
|
|
10
|
+
import { type NavigateResult } from './commands/navigate.js';
|
|
11
|
+
import { type ObserveResult } from './commands/observe.js';
|
|
12
|
+
import { type ScreenshotResult } from './commands/screenshot.js';
|
|
13
|
+
/** Client-scoped bindings for assistive runtime and diagnostics hooks. */
|
|
14
|
+
export interface AgentbrowseClientOptions {
|
|
15
|
+
assistiveRuntime?: AgentbrowseAssistiveRuntime | null;
|
|
16
|
+
diagnostics?: AgentbrowseDiagnosticsHooks | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Embedded library surface with client-scoped configuration.
|
|
20
|
+
*
|
|
21
|
+
* Use this when your application wants to keep assistive runtime and diagnostics
|
|
22
|
+
* local to one tenant, workflow, or test process instead of relying on
|
|
23
|
+
* process-global helpers.
|
|
24
|
+
*/
|
|
25
|
+
export interface AgentbrowseClient {
|
|
26
|
+
/** Binds assistive runtime and diagnostics hooks to a session object in-place. */
|
|
27
|
+
bindSession<TSession extends BrowserSessionState>(session: TSession): TSession;
|
|
28
|
+
/** Attaches to an existing browser via a websocket or HTTP CDP endpoint. */
|
|
29
|
+
attach(cdpUrl: string, options?: AttachOptions): Promise<AttachResult>;
|
|
30
|
+
/** Launches a managed browser session. */
|
|
31
|
+
launch(url?: string, options?: LaunchOptions): Promise<LaunchResult>;
|
|
32
|
+
/** Reads the current browser and page status. */
|
|
33
|
+
status(session: BrowserCommandSession): Promise<BrowserStatusResult>;
|
|
34
|
+
/** Navigates the current page to a new URL. */
|
|
35
|
+
navigate(session: BrowserCommandSession, nextUrl: string): Promise<NavigateResult>;
|
|
36
|
+
/** Observes the current page and returns action targets and scopes. */
|
|
37
|
+
observe(session: BrowserCommandSession, instruction?: string): Promise<ObserveResult>;
|
|
38
|
+
/** Runs a deterministic action against a stored observed target. */
|
|
39
|
+
act(session: BrowserCommandSession, targetRef: string, action: BrowseAction, value?: string): Promise<ActResult>;
|
|
40
|
+
/** Extracts structured data using a plain schema object or Zod schema. */
|
|
41
|
+
extract(session: BrowserCommandSession, schema: ExtractSchemaInput, scopeRef?: string): Promise<ExtractResult>;
|
|
42
|
+
/** Captures a screenshot of the current page. */
|
|
43
|
+
screenshot(session: BrowserCommandSession, outputPath?: string): Promise<ScreenshotResult>;
|
|
44
|
+
/** Closes the current browser session when AgentBrowse owns it. */
|
|
45
|
+
close(session: BrowserCommandSession): Promise<CloseResult>;
|
|
46
|
+
}
|
|
47
|
+
/** Creates an AgentBrowse client with client-scoped assistive runtime and diagnostics hooks. */
|
|
48
|
+
export declare function createAgentbrowseClient(options?: AgentbrowseClientOptions): AgentbrowseClient;
|
|
49
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC7F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAAS,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAkB,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAU,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAEpF,0EAA0E;AAC1E,MAAM,WAAW,wBAAwB;IACvC,gBAAgB,CAAC,EAAE,2BAA2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mEAAmE;IACnE,KAAK,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC7D;AAED,gGAAgG;AAChG,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,iBAAiB,CAsDjG"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { bindAgentbrowseSession } from './client-bindings.js';
|
|
2
|
+
import { actBrowser } from './commands/act.js';
|
|
3
|
+
import { attach } from './commands/attach.js';
|
|
4
|
+
import { browserStatus } from './commands/browser-status.js';
|
|
5
|
+
import { close } from './commands/close.js';
|
|
6
|
+
import { extractBrowser } from './commands/extract.js';
|
|
7
|
+
import { launch } from './commands/launch.js';
|
|
8
|
+
import { navigateBrowser } from './commands/navigate.js';
|
|
9
|
+
import { observeBrowser } from './commands/observe.js';
|
|
10
|
+
import { screenshotBrowser } from './commands/screenshot.js';
|
|
11
|
+
/** Creates an AgentBrowse client with client-scoped assistive runtime and diagnostics hooks. */
|
|
12
|
+
export function createAgentbrowseClient(options = {}) {
|
|
13
|
+
const bindings = {
|
|
14
|
+
...(options.assistiveRuntime ? { assistiveRuntime: options.assistiveRuntime } : {}),
|
|
15
|
+
...(options.diagnostics ? { diagnostics: options.diagnostics } : {}),
|
|
16
|
+
};
|
|
17
|
+
const bindSession = (session) => bindAgentbrowseSession(session, bindings);
|
|
18
|
+
return {
|
|
19
|
+
bindSession,
|
|
20
|
+
async attach(cdpUrl, attachOptions = {}) {
|
|
21
|
+
const result = await attach(cdpUrl, attachOptions);
|
|
22
|
+
if (result.success) {
|
|
23
|
+
bindSession(result.session);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
},
|
|
27
|
+
async launch(url, launchOptions = {}) {
|
|
28
|
+
const result = await launch(url, launchOptions);
|
|
29
|
+
if (result.success) {
|
|
30
|
+
bindSession(result.session);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
},
|
|
34
|
+
status(session) {
|
|
35
|
+
bindSession(session);
|
|
36
|
+
return browserStatus(session);
|
|
37
|
+
},
|
|
38
|
+
navigate(session, nextUrl) {
|
|
39
|
+
bindSession(session);
|
|
40
|
+
return navigateBrowser(session, nextUrl);
|
|
41
|
+
},
|
|
42
|
+
observe(session, instruction) {
|
|
43
|
+
bindSession(session);
|
|
44
|
+
return observeBrowser(session, instruction);
|
|
45
|
+
},
|
|
46
|
+
act(session, targetRef, action, value) {
|
|
47
|
+
bindSession(session);
|
|
48
|
+
return actBrowser(session, targetRef, action, value);
|
|
49
|
+
},
|
|
50
|
+
extract(session, schema, scopeRef) {
|
|
51
|
+
bindSession(session);
|
|
52
|
+
return extractBrowser(session, schema, scopeRef);
|
|
53
|
+
},
|
|
54
|
+
screenshot(session, outputPath) {
|
|
55
|
+
bindSession(session);
|
|
56
|
+
return screenshotBrowser(session, outputPath);
|
|
57
|
+
},
|
|
58
|
+
close(session) {
|
|
59
|
+
bindSession(session);
|
|
60
|
+
return close(session);
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type DiagnosticCommand } from './diagnostics.js';
|
|
2
|
+
type ApiTraceContext = {
|
|
3
|
+
runId?: string;
|
|
4
|
+
stepId?: string;
|
|
5
|
+
command: DiagnosticCommand;
|
|
6
|
+
};
|
|
7
|
+
type TracedFetchOptions = {
|
|
8
|
+
spanName: string;
|
|
9
|
+
attributes?: Record<string, unknown>;
|
|
10
|
+
fetchImpl?: typeof fetch;
|
|
11
|
+
};
|
|
12
|
+
type TracedStepOperationOptions = {
|
|
13
|
+
spanName: string;
|
|
14
|
+
attributes?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
export declare function withApiTraceContext<T>(context: ApiTraceContext, run: () => Promise<T>): Promise<T>;
|
|
17
|
+
export declare function tracedStepOperation<T>(run: () => Promise<T> | T, options?: TracedStepOperationOptions): Promise<T>;
|
|
18
|
+
export declare function tracedFetch(input: RequestInfo | URL, init?: RequestInit, options?: TracedFetchOptions): Promise<Response>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=command-api-tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-api-tracing.d.ts","sourceRoot":"","sources":["../src/command-api-tracing.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE/F,KAAK,eAAe,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAoEF,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,OAAO,EAAE,eAAe,EACxB,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACpB,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,GAAG,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EACzB,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,CAAC,CAAC,CA2CZ;AAED,wBAAsB,WAAW,CAC/B,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,QAAQ,CAAC,CA6CnB"}
|