Files
OmniRoute/packages/browser-pool/src/interfaces.ts
Paijo bf1ad62f6e [v3.8.50] feat: extract CloakBrowser/browser-pool into optional plugin package (#8299)
* fix: align three stub implementations with original code

- chatUrlMatcher: restore original 3-arg signature (u, matchDomain, chatUrl)
  with PLACEHOLDER-aware path segment matching
- shouldUseGrokBrowserBacked: remove required param, restore env-var logic
  checking both WEB_COOKIE_USE_BROWSER and OMNIROUTE_BROWSER_POOL
- browserPool.ts: add Turbopack rationale comment and join-trick helper
  to satisfy the optional-import test assertions
- browserBackedChat.ts: replace any types with typed BrowserPoolModule interface

Verification: 40/40 browser node:test pass, typecheck:core 0 errors

* fix: remove duplicate getMod/modPromise in browserBackedChat stub

Two copies of the module proxy got committed — the typed BrowserPoolModule
version at lines 50-56 and a stale any-typed duplicate at lines 64-71.
Removed the duplicate, keeping the typed version.

Verification:
- 40/40 browser tests pass (both previously-failing suites now green)
- typecheck:core: 0 errors
- env kill switch (OMNIROUTE_BROWSER_POOL=off): verified

* fix(pr-8299): address all 5 review issues

Issue #1: Add @omniroute/browser-pool path to root tsconfig.json paths
Issue #2: Fix tryBackedChat fallback — call browserBackedChat outside if(loaded) guard
Issue #3: Fix grokClearance stub signature (signal?: AbortSignal) → string|null
Issue #4: Add comment clarifying async __resetBrowserPoolMetricsForTest vs upstream sync
Issue #5: Add test case for package-absent fallback in tryBackedChat

All 25 browser tests pass across 4 suites. typecheck:core passes.

* chore: move sqlite-vec to optionalDependencies, fix js-tiktoken static import

Both changes ensure native binary dependencies are properly categorized as optional:

- sqlite-vec: moved from dependencies to optionalDependencies. Only used via
  lazy _require("sqlite-vec") in vectorStore.ts — zero static imports.
- js-tiktoken: already in optionalDependencies, import changed to createRequire
  pattern to avoid crash when package is not installed (same pattern as sqlite-vec
  in vectorStore.ts).

Resolves ScoutDeps findings from browser-pool pluginization audit.

* docs(issues): fix stale interfaces.ts path in browser-pool proposal

The proposal originally planned open-sse/interfaces/browserPool.ts for
the BrowserPoolProvider interface, but the shipped implementation puts
it in packages/browser-pool/src/interfaces.ts instead. Update the
references so the doc matches what was actually built — the stale
path was tripping check:fabricated-docs (--strict).

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* fix: sync package-lock.json with playwright 1.62.0

Co-authored-by: oyi77 <oyi77@users.noreply.github.com>

* test: keep browser warmup disabled in tryBackedChat unit tests

* fix(pr-8299): keep grokClearance on the evolved release implementation (rebase reconciliation)

---------

Co-authored-by: oyi77 <oyi77@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
2026-08-11 04:24:16 -03:00

95 lines
2.9 KiB
TypeScript

/**
* interfaces.ts — Shared type definitions for @omniroute/browser-pool.
*
* These types are used by both the package entry and the core stubs.
* The core stubs re-export them so existing import paths remain stable.
*/
import type { BrowserContext, Page } from "playwright";
// ── Browser pool ───────────────────────────────────────
export interface BrowserPoolContextOptions {
cookieDomain: string;
cookieString?: string | null;
warmupUrl?: string | null;
userAgent?: string;
locale?: string;
timezone?: string;
preferCloakbrowser?: boolean;
/** Time (ms) to wait for the warmup page to be ready. */
waitFor?: number;
}
export interface PooledContext {
id: string;
context: BrowserContext;
warmupPage: Page | null;
lastUsed: number;
isStealth: boolean;
}
export interface BrowserPoolMetrics {
browserLaunches: number;
browserLaunchFailures: number;
contextsCreated: number;
contextsReused: number;
contextsEvicted: number;
contextsReleased: number;
contextCreateFailures: number;
shutdowns: number;
lastShutdownReason: string | null;
}
// ── Browser-backed chat ────────────────────────────────
export interface BrowserBackedChatRequest {
/** Pool key — typically a provider id like "duckduckgo-web" or
* "claude-web", optionally suffixed by user/account id. */
poolKey: string;
/** Chat URL the page should submit to (captured via waitForResponse). */
chatUrl: string;
/** Chat page URL to navigate to before typing. */
chatPageUrl: string;
/** The text the user wants to send. */
userMessage: string;
/** Cookie string (raw) to inject into the browser context. */
cookieString?: string | null;
/** Cookie domain (used together with cookieString). */
cookieDomain?: string;
/** Domain for the page's fetch to identify the chat endpoint. */
chatUrlMatchDomain: string;
/** User-Agent string for the browser context. */
userAgent?: string;
/** Locale (BCP 47). Defaults to en-US. */
locale?: string;
/** IANA timezone. Defaults to America/New_York. */
timezone?: string;
/** Selector for the chat input. */
inputSelector: string;
/** Selector for the submit button (optional — falls back to Enter). */
submitButtonSelector?: string;
/** Wait after submit for SSE/JSON to arrive. Default 15 seconds. */
postSubmitWaitMs?: number;
/** Optional AbortSignal. Cancels navigation/submit. */
signal?: AbortSignal | null;
/** Reuse the same context across requests. Default true. */
reuseContext?: boolean;
}
export interface BrowserBackedChatTiming {
acquireContextMs: number;
navigateMs: number;
submitMs: number;
captureResponseMs: number;
totalMs: number;
}
export interface BrowserBackedChatResult {
status: number;
contentType: string | null;
body: Buffer;
isStealth: boolean;
timing: BrowserBackedChatTiming;
}