@agentium/browser 3.1.0 → 3.1.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.
@@ -0,0 +1,83 @@
1
+ import type { BrowserAction } from "./types.js";
2
+ /**
3
+ * Detects two kinds of "stuck":
4
+ *
5
+ * 1. **Action loops** — the same action (after normalization) repeated too
6
+ * often in a rolling window. Replaces the v2.0.x exact-string compare
7
+ * that was easily fooled by tiny wording changes in `description`.
8
+ * 2. **Page stagnation** — the page hasn't changed (URL + interactive-
9
+ * element count + DOM text hash) for several steps in a row. Useful
10
+ * for catching cases where the agent keeps clicking but nothing
11
+ * happens (overlay blocking, dead button).
12
+ *
13
+ * Instead of hard-failing on the first sign of trouble like v2.0.x did,
14
+ * we emit a graduated severity level so the agent loop can:
15
+ * - 0/`none` — fine, do nothing
16
+ * - 1/`warn` — nudge the model ("you might be repeating yourself")
17
+ * - 2/`escalate` — stronger nudge ("you're definitely stuck, try a
18
+ * different approach")
19
+ * - 3/`abort` — force termination
20
+ *
21
+ * Thresholds are loosely modelled on browser-use's escalating nudges.
22
+ */
23
+ export type LoopSeverity = "none" | "warn" | "escalate" | "abort";
24
+ export interface LoopAdvice {
25
+ severity: LoopSeverity;
26
+ message?: string;
27
+ }
28
+ export interface PageFingerprint {
29
+ url: string;
30
+ interactiveCount: number;
31
+ /** Cheap hash of the first ~1000 chars of visible body text. */
32
+ textHash: number;
33
+ }
34
+ export declare class LoopDetector {
35
+ private actionWindow;
36
+ private pageHistory;
37
+ private readonly actionWindowSize;
38
+ private readonly pageHistorySize;
39
+ /** Thresholds: repeat counts at which each severity fires. */
40
+ private readonly actionThresholds;
41
+ /** Thresholds: consecutive unchanged-page counts at which each fires. */
42
+ private readonly pageThresholds;
43
+ constructor(opts?: {
44
+ actionWindowSize?: number;
45
+ pageHistorySize?: number;
46
+ actionThresholds?: {
47
+ warn?: number;
48
+ escalate?: number;
49
+ abort?: number;
50
+ };
51
+ pageThresholds?: {
52
+ warn?: number;
53
+ escalate?: number;
54
+ abort?: number;
55
+ };
56
+ });
57
+ /**
58
+ * Record an action and return advice for the runtime. `severity` of
59
+ * `abort` means the loop should terminate now.
60
+ */
61
+ recordAction(action: BrowserAction): LoopAdvice;
62
+ /**
63
+ * Record a page fingerprint and return advice if the page has been
64
+ * stagnant. Counts consecutive identical fingerprints at the END of
65
+ * the history (so a single navigation resets the counter).
66
+ */
67
+ recordPage(fp: PageFingerprint): LoopAdvice;
68
+ /** Combine two advices, returning the more severe one. */
69
+ static combine(a: LoopAdvice, b: LoopAdvice): LoopAdvice;
70
+ }
71
+ /**
72
+ * Normalize an action for loop comparison. The goal is to canonicalize
73
+ * tiny variations the LLM produces (e.g. different `description`s for
74
+ * the same click) into a single key while keeping actions that are
75
+ * fundamentally different (different `index`, `text`, `url`, …) distinct.
76
+ */
77
+ export declare function normalizeAction(action: BrowserAction): string;
78
+ /**
79
+ * Tiny non-cryptographic string hash, stable across runs. Used for the
80
+ * DOM-text portion of `PageFingerprint`.
81
+ */
82
+ export declare function fnvHash(s: string): number;
83
+ //# sourceMappingURL=loop-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-detector.d.ts","sourceRoot":"","sources":["../src/loop-detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC;AAElE,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,gEAAgE;IAChE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,8DAA8D;IAC9D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoD;IACrF,yEAAyE;IACzE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoD;gBAEvE,IAAI,CAAC,EAAE;QACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QACxE,cAAc,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;KACvE;IAeD;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,UAAU;IA8B/C;;;;OAIG;IACH,UAAU,CAAC,EAAE,EAAE,eAAe,GAAG,UAAU;IAmC3C,0DAA0D;IAC1D,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,UAAU;CAIzD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CA0D7D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAOzC"}
@@ -0,0 +1,21 @@
1
+ import type { ToolDef } from "@agentium/core";
2
+ import type { TabInfo } from "./action-space.js";
3
+ import type { DomScrollContext } from "./types.js";
4
+ export declare function buildSystemPrompt(viewport: {
5
+ width: number;
6
+ height: number;
7
+ }, extraInstructions?: string, credentialKeys?: string[], options?: {
8
+ overrideSystemMessage?: string;
9
+ maxActionsPerStep?: number;
10
+ allowEvaluate?: boolean;
11
+ tools?: ToolDef[];
12
+ useVision?: boolean | "auto";
13
+ useDOM?: boolean;
14
+ useThinking?: boolean;
15
+ }): string;
16
+ export declare function buildUserMessage(task: string, pageUrl: string, pageTitle: string, stepIndex: number, actionHistory: string[], domSnapshot?: string, lastExtract?: string, scroll?: DomScrollContext, nudge?: string, stepBudget?: {
17
+ current: number;
18
+ max: number;
19
+ }, tabs?: TabInfo[]): string;
20
+ export declare function summarizeAction(action: Record<string, unknown>): string;
21
+ //# sourceMappingURL=prompts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAC3C,iBAAiB,CAAC,EAAE,MAAM,EAC1B,cAAc,CAAC,EAAE,MAAM,EAAE,EACzB,OAAO,CAAC,EAAE;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;IAClB,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GACA,MAAM,CA2IR;AA6CD,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EAAE,EACvB,WAAW,CAAC,EAAE,MAAM,EACpB,WAAW,CAAC,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,gBAAgB,EACzB,KAAK,CAAC,EAAE,MAAM,EACd,UAAU,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAC7C,IAAI,CAAC,EAAE,OAAO,EAAE,GACf,MAAM,CAkER;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAwDvE"}
@@ -0,0 +1,27 @@
1
+ import type { StealthConfig } from "./types.js";
2
+ /** Pick a random realistic user-agent string. */
3
+ export declare function pickUserAgent(): string;
4
+ /**
5
+ * JavaScript that runs inside every page to patch common bot-detection vectors.
6
+ * Injected via Playwright's `context.addInitScript()`.
7
+ */
8
+ export declare function getStealthScript(): string;
9
+ /**
10
+ * Build Playwright context options from a StealthConfig.
11
+ */
12
+ export declare function buildStealthContextOpts(config: StealthConfig, viewport: {
13
+ width: number;
14
+ height: number;
15
+ }): Record<string, unknown>;
16
+ /**
17
+ * Build Playwright launch options for stealth.
18
+ */
19
+ export declare function buildStealthLaunchArgs(config: StealthConfig): {
20
+ args: string[];
21
+ proxy?: {
22
+ server: string;
23
+ username?: string;
24
+ password?: string;
25
+ };
26
+ };
27
+ //# sourceMappingURL=stealth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stealth.d.ts","sourceRoot":"","sources":["../src/stealth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAWhD,iDAAiD;AACjD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAoGzC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBzB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,GAAG;IAC7D,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClE,CAcA"}