@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,182 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { getSolverDir } from './solver/config.js';
|
|
4
|
+
const PACKAGE_NAME = '@mercuryo-ai/agentbrowse';
|
|
5
|
+
const PACKAGE_JSON_URL = new URL('../package.json', import.meta.url);
|
|
6
|
+
const REGISTRY_METADATA_URL = `https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}`;
|
|
7
|
+
const DEFAULT_UPDATE_CHECK_TIMEOUT_MS = 1500;
|
|
8
|
+
const DEFAULT_UPDATE_TTL_MS = 12 * 60 * 60 * 1000;
|
|
9
|
+
export function compareVersions(left, right) {
|
|
10
|
+
const parsedLeft = parseVersion(left);
|
|
11
|
+
const parsedRight = parseVersion(right);
|
|
12
|
+
if (!parsedLeft || !parsedRight) {
|
|
13
|
+
return left.localeCompare(right, undefined, {
|
|
14
|
+
numeric: true,
|
|
15
|
+
sensitivity: 'base',
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
for (let i = 0; i < 3; i += 1) {
|
|
19
|
+
const diff = parsedLeft.core[i] - parsedRight.core[i];
|
|
20
|
+
if (diff !== 0) {
|
|
21
|
+
return diff;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (!parsedLeft.prerelease && !parsedRight.prerelease) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
if (!parsedLeft.prerelease) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (!parsedRight.prerelease) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
const length = Math.max(parsedLeft.prerelease.length, parsedRight.prerelease.length);
|
|
34
|
+
for (let i = 0; i < length; i += 1) {
|
|
35
|
+
const leftPart = parsedLeft.prerelease[i];
|
|
36
|
+
const rightPart = parsedRight.prerelease[i];
|
|
37
|
+
if (leftPart === undefined) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
if (rightPart === undefined) {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
if (typeof leftPart === 'number' && typeof rightPart === 'number') {
|
|
44
|
+
const diff = leftPart - rightPart;
|
|
45
|
+
if (diff !== 0) {
|
|
46
|
+
return diff;
|
|
47
|
+
}
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (typeof leftPart === 'number') {
|
|
51
|
+
return -1;
|
|
52
|
+
}
|
|
53
|
+
if (typeof rightPart === 'number') {
|
|
54
|
+
return 1;
|
|
55
|
+
}
|
|
56
|
+
const diff = leftPart.localeCompare(rightPart);
|
|
57
|
+
if (diff !== 0) {
|
|
58
|
+
return diff;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
export async function checkForLaunchUpdate(options = {}) {
|
|
64
|
+
const currentVersion = readCurrentPackageVersion();
|
|
65
|
+
const now = options.now ?? new Date();
|
|
66
|
+
const ttlMs = options.ttlMs ?? DEFAULT_UPDATE_TTL_MS;
|
|
67
|
+
const cachedState = readUpdateState();
|
|
68
|
+
const cachedNotice = buildLaunchUpdateNotice(currentVersion, cachedState?.latestVersion);
|
|
69
|
+
if (cachedState && !isCacheStale(cachedState.lastCheckedAt, now, ttlMs)) {
|
|
70
|
+
return cachedNotice;
|
|
71
|
+
}
|
|
72
|
+
const latestVersion = await fetchLatestVersion({
|
|
73
|
+
fetchImpl: options.fetchImpl,
|
|
74
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_UPDATE_CHECK_TIMEOUT_MS,
|
|
75
|
+
}).catch(() => null);
|
|
76
|
+
if (!latestVersion) {
|
|
77
|
+
return cachedNotice;
|
|
78
|
+
}
|
|
79
|
+
writeUpdateState({
|
|
80
|
+
packageName: PACKAGE_NAME,
|
|
81
|
+
latestVersion,
|
|
82
|
+
lastCheckedAt: now.toISOString(),
|
|
83
|
+
});
|
|
84
|
+
return buildLaunchUpdateNotice(currentVersion, latestVersion);
|
|
85
|
+
}
|
|
86
|
+
function parseVersion(version) {
|
|
87
|
+
const match = version
|
|
88
|
+
.trim()
|
|
89
|
+
.match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+.*)?$/);
|
|
90
|
+
if (!match) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
const prerelease = match[4]
|
|
94
|
+
? match[4].split('.').map((part) => (/^\d+$/.test(part) ? Number(part) : part))
|
|
95
|
+
: null;
|
|
96
|
+
return {
|
|
97
|
+
core: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
98
|
+
prerelease,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function buildLaunchUpdateNotice(currentVersion, latestVersion) {
|
|
102
|
+
if (!latestVersion || compareVersions(latestVersion, currentVersion) <= 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
currentVersion,
|
|
107
|
+
latestVersion,
|
|
108
|
+
message: `A newer agentbrowse version is available: ${latestVersion} (current: ${currentVersion}). Update with: npm i -g ${PACKAGE_NAME}@latest`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function readCurrentPackageVersion() {
|
|
112
|
+
const raw = JSON.parse(readFileSync(PACKAGE_JSON_URL, 'utf-8'));
|
|
113
|
+
if (!raw.version || typeof raw.version !== 'string') {
|
|
114
|
+
throw new Error('Package version is missing from package.json.');
|
|
115
|
+
}
|
|
116
|
+
return raw.version;
|
|
117
|
+
}
|
|
118
|
+
function readUpdateState() {
|
|
119
|
+
const updateStatePath = getUpdateStatePath();
|
|
120
|
+
if (!existsSync(updateStatePath)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const raw = JSON.parse(readFileSync(updateStatePath, 'utf-8'));
|
|
125
|
+
if (raw.packageName !== PACKAGE_NAME ||
|
|
126
|
+
typeof raw.latestVersion !== 'string' ||
|
|
127
|
+
typeof raw.lastCheckedAt !== 'string') {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
packageName: raw.packageName,
|
|
132
|
+
latestVersion: raw.latestVersion,
|
|
133
|
+
lastCheckedAt: raw.lastCheckedAt,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function writeUpdateState(state) {
|
|
141
|
+
const solverDir = getSolverDir();
|
|
142
|
+
mkdirSync(solverDir, { recursive: true });
|
|
143
|
+
writeFileSync(getUpdateStatePath(), JSON.stringify(state, null, 2) + '\n', 'utf-8');
|
|
144
|
+
}
|
|
145
|
+
function isCacheStale(lastCheckedAt, now, ttlMs) {
|
|
146
|
+
const lastCheckedAtMs = new Date(lastCheckedAt).getTime();
|
|
147
|
+
if (!Number.isFinite(lastCheckedAtMs)) {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
return now.getTime() - lastCheckedAtMs >= ttlMs;
|
|
151
|
+
}
|
|
152
|
+
async function fetchLatestVersion(options) {
|
|
153
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
154
|
+
if (typeof fetchImpl !== 'function') {
|
|
155
|
+
throw new Error('Global fetch is not available.');
|
|
156
|
+
}
|
|
157
|
+
const controller = new AbortController();
|
|
158
|
+
const timeout = setTimeout(() => controller.abort(), options.timeoutMs);
|
|
159
|
+
try {
|
|
160
|
+
const response = await fetchImpl(REGISTRY_METADATA_URL, {
|
|
161
|
+
headers: {
|
|
162
|
+
Accept: 'application/json',
|
|
163
|
+
},
|
|
164
|
+
signal: controller.signal,
|
|
165
|
+
});
|
|
166
|
+
if (!response.ok) {
|
|
167
|
+
throw new Error(`Registry responded with ${response.status}.`);
|
|
168
|
+
}
|
|
169
|
+
const metadata = (await response.json());
|
|
170
|
+
const latestVersion = metadata['dist-tags']?.latest;
|
|
171
|
+
if (!latestVersion || typeof latestVersion !== 'string') {
|
|
172
|
+
throw new Error('Registry metadata does not include dist-tags.latest.');
|
|
173
|
+
}
|
|
174
|
+
return latestVersion;
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
clearTimeout(timeout);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function getUpdateStatePath() {
|
|
181
|
+
return join(getSolverDir(), 'update-state.json');
|
|
182
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { StoredSecretFieldKey } from './secrets/types.js';
|
|
2
|
+
export interface CachedTransientSecretEntry {
|
|
3
|
+
requestId: string;
|
|
4
|
+
fillRef: string;
|
|
5
|
+
storedSecretRef: string;
|
|
6
|
+
cachedAt: string;
|
|
7
|
+
approvedAt?: string;
|
|
8
|
+
expiresAt?: string;
|
|
9
|
+
values: Partial<Record<StoredSecretFieldKey, string>>;
|
|
10
|
+
}
|
|
11
|
+
export interface BrowseWorkflowContext {
|
|
12
|
+
browserSessionId?: string;
|
|
13
|
+
activeRunId?: string;
|
|
14
|
+
intentSessionId?: string;
|
|
15
|
+
currentRequestId?: string;
|
|
16
|
+
lastKnownStatus?: string;
|
|
17
|
+
lastEventSeq?: number;
|
|
18
|
+
transientSecretCache?: Record<string, CachedTransientSecretEntry>;
|
|
19
|
+
}
|
|
20
|
+
export declare function cleanupTransientSecretCache(session: BrowseWorkflowContext, options?: {
|
|
21
|
+
now?: string;
|
|
22
|
+
}): boolean;
|
|
23
|
+
export declare function cacheTransientSecret(session: BrowseWorkflowContext, entry: CachedTransientSecretEntry): CachedTransientSecretEntry;
|
|
24
|
+
export declare function getCachedTransientSecret(session: BrowseWorkflowContext, requestId: string, options?: {
|
|
25
|
+
now?: string;
|
|
26
|
+
}): CachedTransientSecretEntry | null;
|
|
27
|
+
export declare function deleteCachedTransientSecret(session: BrowseWorkflowContext, requestId: string): boolean;
|
|
28
|
+
export declare function buildWorkflowContextForPersistence(session: BrowseWorkflowContext, resolvedBrowserSessionId: string): BrowseWorkflowContext | null;
|
|
29
|
+
export declare function canHydrateWorkflowContext(resolvedBrowserSessionId: string, workflowContext: BrowseWorkflowContext): boolean;
|
|
30
|
+
//# sourceMappingURL=workflow-session-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-session-state.d.ts","sourceRoot":"","sources":["../src/workflow-session-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,qBAAqB;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;CACnE;AAUD,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,qBAAqB,EAC9B,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7B,OAAO,CAqBT;AAED,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,EAC9B,KAAK,EAAE,0BAA0B,GAChC,0BAA0B,CAQ5B;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC7B,0BAA0B,GAAG,IAAI,CAMnC;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,qBAAqB,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAWT;AAED,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,qBAAqB,EAC9B,wBAAwB,EAAE,MAAM,GAC/B,qBAAqB,GAAG,IAAI,CAmB9B;AAED,wBAAgB,yBAAyB,CACvC,wBAAwB,EAAE,MAAM,EAChC,eAAe,EAAE,qBAAqB,GACrC,OAAO,CAKT"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function isExpired(expiresAt, now) {
|
|
2
|
+
if (!expiresAt) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
return new Date(expiresAt).getTime() <= new Date(now).getTime();
|
|
6
|
+
}
|
|
7
|
+
export function cleanupTransientSecretCache(session, options = {}) {
|
|
8
|
+
const cache = session.transientSecretCache;
|
|
9
|
+
if (!cache) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const now = options.now ?? new Date().toISOString();
|
|
13
|
+
let changed = false;
|
|
14
|
+
for (const [requestId, entry] of Object.entries(cache)) {
|
|
15
|
+
if (isExpired(entry.expiresAt, now)) {
|
|
16
|
+
delete cache[requestId];
|
|
17
|
+
changed = true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (Object.keys(cache).length === 0) {
|
|
21
|
+
delete session.transientSecretCache;
|
|
22
|
+
changed = true;
|
|
23
|
+
}
|
|
24
|
+
return changed;
|
|
25
|
+
}
|
|
26
|
+
export function cacheTransientSecret(session, entry) {
|
|
27
|
+
cleanupTransientSecretCache(session);
|
|
28
|
+
const cache = (session.transientSecretCache ??= {});
|
|
29
|
+
cache[entry.requestId] = {
|
|
30
|
+
...entry,
|
|
31
|
+
values: { ...entry.values },
|
|
32
|
+
};
|
|
33
|
+
return cache[entry.requestId];
|
|
34
|
+
}
|
|
35
|
+
export function getCachedTransientSecret(session, requestId, options = {}) {
|
|
36
|
+
if (cleanupTransientSecretCache(session, options)) {
|
|
37
|
+
// Keep the in-memory workflow context sanitized for callers that save immediately after load.
|
|
38
|
+
}
|
|
39
|
+
return session.transientSecretCache?.[requestId] ?? null;
|
|
40
|
+
}
|
|
41
|
+
export function deleteCachedTransientSecret(session, requestId) {
|
|
42
|
+
const cache = session.transientSecretCache;
|
|
43
|
+
if (!cache?.[requestId]) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
delete cache[requestId];
|
|
47
|
+
if (Object.keys(cache).length === 0) {
|
|
48
|
+
delete session.transientSecretCache;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
export function buildWorkflowContextForPersistence(session, resolvedBrowserSessionId) {
|
|
53
|
+
const workflowContext = {
|
|
54
|
+
...((session.activeRunId ||
|
|
55
|
+
session.intentSessionId ||
|
|
56
|
+
session.currentRequestId ||
|
|
57
|
+
session.lastKnownStatus ||
|
|
58
|
+
session.transientSecretCache) &&
|
|
59
|
+
resolvedBrowserSessionId
|
|
60
|
+
? { browserSessionId: resolvedBrowserSessionId }
|
|
61
|
+
: {}),
|
|
62
|
+
...(session.activeRunId ? { activeRunId: session.activeRunId } : {}),
|
|
63
|
+
...(session.intentSessionId ? { intentSessionId: session.intentSessionId } : {}),
|
|
64
|
+
...(session.currentRequestId ? { currentRequestId: session.currentRequestId } : {}),
|
|
65
|
+
...(session.lastKnownStatus ? { lastKnownStatus: session.lastKnownStatus } : {}),
|
|
66
|
+
...(typeof session.lastEventSeq === 'number' ? { lastEventSeq: session.lastEventSeq } : {}),
|
|
67
|
+
...(session.transientSecretCache ? { transientSecretCache: session.transientSecretCache } : {}),
|
|
68
|
+
};
|
|
69
|
+
return Object.keys(workflowContext).length > 0 ? workflowContext : null;
|
|
70
|
+
}
|
|
71
|
+
export function canHydrateWorkflowContext(resolvedBrowserSessionId, workflowContext) {
|
|
72
|
+
return (!workflowContext.browserSessionId ||
|
|
73
|
+
workflowContext.browserSessionId === resolvedBrowserSessionId);
|
|
74
|
+
}
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# AgentBrowse Docs
|
|
2
|
+
|
|
3
|
+
Public guides for `@mercuryo-ai/agentbrowse`.
|
|
4
|
+
|
|
5
|
+
Start here:
|
|
6
|
+
|
|
7
|
+
- [getting-started.md](./getting-started.md)
|
|
8
|
+
The first guide to read after the package README. It explains the normal
|
|
9
|
+
session flow and what each main API is for.
|
|
10
|
+
- [api-reference.md](./api-reference.md)
|
|
11
|
+
Compact reference for the public API, result shapes, observe payloads, and
|
|
12
|
+
extraction schema input.
|
|
13
|
+
- [configuration.md](./configuration.md)
|
|
14
|
+
Persistence, proxy, diagnostics, and client configuration.
|
|
15
|
+
- [assistive-runtime.md](./assistive-runtime.md)
|
|
16
|
+
How to connect an OpenAI-compatible LLM backend for extraction and better
|
|
17
|
+
goal-based page understanding.
|
|
18
|
+
- [protected-fill.md](./protected-fill.md)
|
|
19
|
+
How protected fill works and when to use it instead of a normal fill action.
|
|
20
|
+
- [integration-checklist.md](./integration-checklist.md)
|
|
21
|
+
Current contract checklist for packages and services that integrate AgentBrowse.
|
|
22
|
+
- [testing.md](./testing.md)
|
|
23
|
+
Stable testing helpers for packages that wrap AgentBrowse.
|
|
24
|
+
- [troubleshooting.md](./troubleshooting.md)
|
|
25
|
+
Common launch, observe, extract, and anti-bot issues.
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# AgentBrowse API Reference
|
|
2
|
+
|
|
3
|
+
This page is the compact reference for the public `@mercuryo-ai/agentbrowse`
|
|
4
|
+
library surface.
|
|
5
|
+
|
|
6
|
+
## Main Functions
|
|
7
|
+
|
|
8
|
+
### `launch(url?, options?)`
|
|
9
|
+
|
|
10
|
+
Starts a managed browser session.
|
|
11
|
+
|
|
12
|
+
Success result includes:
|
|
13
|
+
|
|
14
|
+
- `session`
|
|
15
|
+
- `url`
|
|
16
|
+
- `title`
|
|
17
|
+
|
|
18
|
+
### `attach(cdpUrl, options?)`
|
|
19
|
+
|
|
20
|
+
Attaches to an existing browser over CDP.
|
|
21
|
+
|
|
22
|
+
Success result includes:
|
|
23
|
+
|
|
24
|
+
- `session`
|
|
25
|
+
- `url`
|
|
26
|
+
- `title`
|
|
27
|
+
|
|
28
|
+
### `observe(session, goal?)`
|
|
29
|
+
|
|
30
|
+
Inspects the current page and returns the current page inventory.
|
|
31
|
+
|
|
32
|
+
Success result includes:
|
|
33
|
+
|
|
34
|
+
- `targets: ObserveTarget[]`
|
|
35
|
+
- `scopes: ObserveScope[]`
|
|
36
|
+
- `signals: ObserveSignal[]`
|
|
37
|
+
- `fillableForms: ObserveFillableForm[]`
|
|
38
|
+
- `observationMode`
|
|
39
|
+
- `targetCount`
|
|
40
|
+
- `scopeCount`
|
|
41
|
+
- `projectedTargetCount`
|
|
42
|
+
- `pageRef`
|
|
43
|
+
- `url`
|
|
44
|
+
- `title`
|
|
45
|
+
|
|
46
|
+
### `act(session, targetRef, action, value?)`
|
|
47
|
+
|
|
48
|
+
Runs a deterministic browser action against a previously observed target.
|
|
49
|
+
|
|
50
|
+
### `extract(session, schema, scopeRef?)`
|
|
51
|
+
|
|
52
|
+
Extracts structured data from the current page or a previously observed scope.
|
|
53
|
+
|
|
54
|
+
`schema` accepts either:
|
|
55
|
+
|
|
56
|
+
- a plain schema object
|
|
57
|
+
- a Zod schema
|
|
58
|
+
|
|
59
|
+
Plain schema example:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const result = await extract(session, {
|
|
63
|
+
total: 'number',
|
|
64
|
+
currency: 'string',
|
|
65
|
+
flights: [{ code: 'string', fare: 'string' }],
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Zod example:
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
const result = await extract(
|
|
73
|
+
session,
|
|
74
|
+
z.object({
|
|
75
|
+
total: z.number(),
|
|
76
|
+
currency: z.string(),
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `navigate(session, url)`
|
|
82
|
+
|
|
83
|
+
Navigates the current page.
|
|
84
|
+
|
|
85
|
+
### `status(session)`
|
|
86
|
+
|
|
87
|
+
Returns current liveness and runtime summary information.
|
|
88
|
+
|
|
89
|
+
The root package also exports `BROWSER_STATUS_OUTCOME_TYPES` for the stable
|
|
90
|
+
outcome categories used by `status(session)`.
|
|
91
|
+
|
|
92
|
+
### `screenshot(session, path?)`
|
|
93
|
+
|
|
94
|
+
Captures a screenshot of the current page.
|
|
95
|
+
|
|
96
|
+
### `close(session)`
|
|
97
|
+
|
|
98
|
+
Closes the browser session.
|
|
99
|
+
|
|
100
|
+
## Stable Error Code Arrays
|
|
101
|
+
|
|
102
|
+
The root package exports stable top-level error code arrays for command
|
|
103
|
+
branching:
|
|
104
|
+
|
|
105
|
+
- `ACT_ERROR_CODES`
|
|
106
|
+
- `ATTACH_ERROR_CODES`
|
|
107
|
+
- `CLOSE_ERROR_CODES`
|
|
108
|
+
- `EXTRACT_ERROR_CODES`
|
|
109
|
+
- `LAUNCH_ERROR_CODES`
|
|
110
|
+
- `NAVIGATE_ERROR_CODES`
|
|
111
|
+
- `OBSERVE_ERROR_CODES`
|
|
112
|
+
- `SCREENSHOT_ERROR_CODES`
|
|
113
|
+
|
|
114
|
+
These arrays back the exported `*ErrorCode` types.
|
|
115
|
+
|
|
116
|
+
## Core Result Shapes
|
|
117
|
+
|
|
118
|
+
All main commands use the same top-level pattern:
|
|
119
|
+
|
|
120
|
+
- success: `{ success: true, ... }`
|
|
121
|
+
- failure: `{ success: false, error, outcomeType, message, reason, ... }`
|
|
122
|
+
|
|
123
|
+
## Observe Types
|
|
124
|
+
|
|
125
|
+
### `ObserveTarget`
|
|
126
|
+
|
|
127
|
+
Fields most applications use directly:
|
|
128
|
+
|
|
129
|
+
- `ref`
|
|
130
|
+
- `label`
|
|
131
|
+
- `kind`
|
|
132
|
+
- `capability`
|
|
133
|
+
- `availability`
|
|
134
|
+
- `surfaceRef`
|
|
135
|
+
|
|
136
|
+
Additional fields are available for richer UI or routing:
|
|
137
|
+
|
|
138
|
+
- `displayLabel`
|
|
139
|
+
- `placeholder`
|
|
140
|
+
- `inputName`
|
|
141
|
+
- `inputType`
|
|
142
|
+
- `autocomplete`
|
|
143
|
+
- `validation`
|
|
144
|
+
- `context`
|
|
145
|
+
- `state`
|
|
146
|
+
- `structure`
|
|
147
|
+
- `availabilityReason`
|
|
148
|
+
- `source`
|
|
149
|
+
|
|
150
|
+
### `ObserveScope`
|
|
151
|
+
|
|
152
|
+
Represents a scope or container on the page.
|
|
153
|
+
|
|
154
|
+
Fields:
|
|
155
|
+
|
|
156
|
+
- `ref`
|
|
157
|
+
- `kind`
|
|
158
|
+
- `label`
|
|
159
|
+
- `parentSurfaceRef`
|
|
160
|
+
- `childSurfaceRefs`
|
|
161
|
+
- `extractScopeLifetime`
|
|
162
|
+
- `targets`
|
|
163
|
+
- `source`
|
|
164
|
+
|
|
165
|
+
### `ObserveFillableForm`
|
|
166
|
+
|
|
167
|
+
Represents a form that can be passed into protected fill.
|
|
168
|
+
|
|
169
|
+
Fields:
|
|
170
|
+
|
|
171
|
+
- `fillRef`
|
|
172
|
+
- `scopeRef`
|
|
173
|
+
- `purpose`
|
|
174
|
+
- `presence`
|
|
175
|
+
- `fields`
|
|
176
|
+
- `storedSecretCandidates`
|
|
177
|
+
|
|
178
|
+
### `ObserveSignal`
|
|
179
|
+
|
|
180
|
+
Represents page-level signals such as notices, status text, or confirmation
|
|
181
|
+
messages.
|
|
182
|
+
|
|
183
|
+
Fields:
|
|
184
|
+
|
|
185
|
+
- `kind`
|
|
186
|
+
- `text`
|
|
187
|
+
- `framePath`
|
|
188
|
+
- `source`
|
|
189
|
+
|
|
190
|
+
## Ref Glossary
|
|
191
|
+
|
|
192
|
+
- `ref`
|
|
193
|
+
A stable target or scope reference returned by `observe(...)`.
|
|
194
|
+
- `scopeRef`
|
|
195
|
+
A scope reference used for scoped extraction or protected-fill bindings.
|
|
196
|
+
- `fillRef`
|
|
197
|
+
A stable protected-fill binding reference returned inside `fillableForms`.
|
|
198
|
+
- `pageRef`
|
|
199
|
+
AgentBrowse's current page identity inside the session runtime.
|
|
200
|
+
|
|
201
|
+
## Extraction Schema Rules
|
|
202
|
+
|
|
203
|
+
Plain schema objects use a small descriptor language:
|
|
204
|
+
|
|
205
|
+
- `'string'`
|
|
206
|
+
- `'number'`
|
|
207
|
+
- `'boolean'`
|
|
208
|
+
- nested objects
|
|
209
|
+
- arrays with one schema element, for example `[{ label: 'string' }]`
|
|
210
|
+
|
|
211
|
+
The extractor uses only the schema you provide. It does not invent missing
|
|
212
|
+
fields and does not treat the schema stringification format as part of the API.
|
|
213
|
+
|
|
214
|
+
## Assistive Runtime Types
|
|
215
|
+
|
|
216
|
+
The root package exports the current assistive runtime contract:
|
|
217
|
+
|
|
218
|
+
- `AgentbrowseAssistiveChatCompletionRequest`
|
|
219
|
+
- `AgentbrowseAssistiveChatCompletionOptions`
|
|
220
|
+
- `AgentbrowseAssistiveChatCompletionResult`
|
|
221
|
+
- `AgentbrowseAssistiveChatMessage`
|
|
222
|
+
- `AgentbrowseAssistiveImageInput`
|
|
223
|
+
- `AgentbrowseAssistiveResponseModel`
|
|
224
|
+
- `AgentbrowseAssistiveLlmUsage`
|
|
225
|
+
|
|
226
|
+
Your adapter receives `args.options.messages`, optional
|
|
227
|
+
`args.options.response_model`, optional `args.options.image`, and optional
|
|
228
|
+
`temperature` / `maxOutputTokens`.
|
|
229
|
+
|
|
230
|
+
## Testing Subpath
|
|
231
|
+
|
|
232
|
+
The package publishes a dedicated testing surface:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import {
|
|
236
|
+
installFetchBackedTestAssistiveRuntime,
|
|
237
|
+
uninstallTestAssistiveRuntime,
|
|
238
|
+
} from '@mercuryo-ai/agentbrowse/testing';
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Use it when a package wraps AgentBrowse and needs a stable fetch-backed
|
|
242
|
+
assistive runtime in tests.
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# AgentBrowse Assistive Runtime Guide
|
|
2
|
+
|
|
3
|
+
This guide explains when you need an assistive runtime and how to connect one.
|
|
4
|
+
|
|
5
|
+
## What "Assistive" Means
|
|
6
|
+
|
|
7
|
+
AgentBrowse has two broad kinds of behavior:
|
|
8
|
+
|
|
9
|
+
- browser-only behavior, which does not call an LLM
|
|
10
|
+
- assistive behavior, which can call an LLM to better understand the page or
|
|
11
|
+
produce structured output
|
|
12
|
+
|
|
13
|
+
Today, assistive behavior matters mainly for:
|
|
14
|
+
|
|
15
|
+
- `extract(session, schema, scopeRef?)`
|
|
16
|
+
- higher-quality goal-based `observe(session, goal)`
|
|
17
|
+
|
|
18
|
+
If you only need browser actions and normal page inspection, you can ignore
|
|
19
|
+
assistive runtime completely.
|
|
20
|
+
|
|
21
|
+
## The Runtime Contract
|
|
22
|
+
|
|
23
|
+
AgentBrowse does not ship a built-in OpenAI or OpenRouter adapter.
|
|
24
|
+
|
|
25
|
+
Instead, you provide a small runtime object with one responsibility:
|
|
26
|
+
create a chat-completions client.
|
|
27
|
+
|
|
28
|
+
The shape is:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
{
|
|
32
|
+
createLlmClient: () => ({
|
|
33
|
+
async createChatCompletion(args) {
|
|
34
|
+
const { messages, response_model, image, temperature, maxOutputTokens } = args.options;
|
|
35
|
+
// map these values to your provider here
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
That means any OpenAI-compatible chat-completions backend can work, as long as
|
|
42
|
+
your adapter returns the expected response shape.
|
|
43
|
+
|
|
44
|
+
## Recommended Setup
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createAgentbrowseClient } from '@mercuryo-ai/agentbrowse';
|
|
48
|
+
|
|
49
|
+
const client = createAgentbrowseClient({
|
|
50
|
+
assistiveRuntime: {
|
|
51
|
+
createLlmClient: () => ({
|
|
52
|
+
async createChatCompletion(args) {
|
|
53
|
+
const { messages, response_model, image, temperature, maxOutputTokens } = args.options;
|
|
54
|
+
|
|
55
|
+
const json = await callStructuredProvider({
|
|
56
|
+
messages,
|
|
57
|
+
responseModel: response_model,
|
|
58
|
+
image,
|
|
59
|
+
temperature,
|
|
60
|
+
maxOutputTokens,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
data: json.data,
|
|
65
|
+
usage: json.usage,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
This pattern works well when:
|
|
74
|
+
|
|
75
|
+
- your app is multi-tenant
|
|
76
|
+
- you run parallel tests
|
|
77
|
+
- different consumers in one process need different LLM settings
|
|
78
|
+
|
|
79
|
+
## OpenAI-Compatible Helper Example
|
|
80
|
+
|
|
81
|
+
You can wrap the adapter once and reuse it:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
function createOpenAiCompatibleAssistiveRuntime(input: {
|
|
85
|
+
baseUrl: string;
|
|
86
|
+
apiKey: string;
|
|
87
|
+
}) {
|
|
88
|
+
return {
|
|
89
|
+
createLlmClient: () => ({
|
|
90
|
+
async createChatCompletion(args) {
|
|
91
|
+
const { messages, response_model, image, temperature, maxOutputTokens } = args.options;
|
|
92
|
+
|
|
93
|
+
const json = await callStructuredProvider({
|
|
94
|
+
baseUrl: input.baseUrl,
|
|
95
|
+
apiKey: input.apiKey,
|
|
96
|
+
messages,
|
|
97
|
+
responseModel: response_model,
|
|
98
|
+
image,
|
|
99
|
+
temperature,
|
|
100
|
+
maxOutputTokens,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
data: json.data,
|
|
105
|
+
usage: json.usage,
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Examples:
|
|
114
|
+
|
|
115
|
+
- OpenAI base URL:
|
|
116
|
+
`https://api.openai.com/v1`
|
|
117
|
+
- OpenRouter base URL:
|
|
118
|
+
`https://openrouter.ai/api/v1`
|
|
119
|
+
|
|
120
|
+
## Small Script Fallback
|
|
121
|
+
|
|
122
|
+
For small scripts, you can also use:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { configureAgentbrowseAssistiveRuntime } from '@mercuryo-ai/agentbrowse';
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This is a convenience fallback, not the preferred embedded pattern.
|
|
129
|
+
|
|
130
|
+
## What Happens Without Assistive Runtime
|
|
131
|
+
|
|
132
|
+
- `extract(...)` cannot run successfully
|
|
133
|
+
- `observe(session, goal)` still runs, but quality may be lower because
|
|
134
|
+
AgentBrowse falls back to local heuristics instead of LLM-assisted ranking
|
|
135
|
+
|
|
136
|
+
## Testing Runtime
|
|
137
|
+
|
|
138
|
+
For test suites that wrap AgentBrowse, use the dedicated testing subpath:
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
import {
|
|
142
|
+
installFetchBackedTestAssistiveRuntime,
|
|
143
|
+
uninstallTestAssistiveRuntime,
|
|
144
|
+
} from '@mercuryo-ai/agentbrowse/testing';
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
That helper installs a fetch-backed runtime with the same public assistive
|
|
148
|
+
runtime contract used by the main package.
|