@edlsh/browse-core 0.6.4 → 0.8.0

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.
Files changed (49) hide show
  1. package/README.md +23 -2
  2. package/dist/broker-client.d.ts +4 -2
  3. package/dist/broker-client.js +12 -6
  4. package/dist/broker-protocol.d.ts +3 -2
  5. package/dist/broker-protocol.js +11 -7
  6. package/dist/broker.js +12 -12
  7. package/dist/cdp-connection.d.ts +18 -0
  8. package/dist/cdp-connection.js +59 -0
  9. package/dist/config.d.ts +101 -0
  10. package/dist/config.js +78 -0
  11. package/dist/contexts.d.ts +10 -0
  12. package/dist/contexts.js +27 -0
  13. package/dist/errors.d.ts +29 -0
  14. package/dist/errors.js +83 -0
  15. package/dist/har.d.ts +1 -6
  16. package/dist/har.js +16 -56
  17. package/dist/host-model.d.ts +24 -0
  18. package/dist/host-model.js +35 -0
  19. package/dist/http-auth.d.ts +14 -0
  20. package/dist/http-auth.js +114 -0
  21. package/dist/index.d.ts +10 -13
  22. package/dist/index.js +11 -15
  23. package/dist/jev.js +9 -3
  24. package/dist/page-operations.d.ts +11 -1
  25. package/dist/page-operations.js +62 -11
  26. package/dist/real-browser-ai.d.ts +1 -1
  27. package/dist/real-browser-ai.js +1 -1
  28. package/dist/real-browser-client.js +1 -1
  29. package/dist/real-browser-session.d.ts +1 -1
  30. package/dist/real-browser-session.js +24 -5
  31. package/dist/schema.d.ts +34 -0
  32. package/dist/schema.js +29 -6
  33. package/dist/session-runtime.d.ts +42 -0
  34. package/dist/session-runtime.js +144 -0
  35. package/dist/session.d.ts +29 -108
  36. package/dist/session.js +189 -364
  37. package/dist/settings.js +47 -6
  38. package/dist/tool-results.d.ts +28 -0
  39. package/dist/tool-results.js +40 -0
  40. package/extensions/http-auth/README.md +27 -0
  41. package/extensions/http-auth/background.js +85 -0
  42. package/extensions/http-auth/manifest.json +27 -0
  43. package/extensions/http-auth/native/README.md +31 -0
  44. package/extensions/http-auth/native/host.py +97 -0
  45. package/extensions/http-auth/native/install.py +62 -0
  46. package/extensions/http-auth/options.html +25 -0
  47. package/extensions/http-auth/options.js +36 -0
  48. package/extensions/http-auth/origin.js +16 -0
  49. package/package.json +14 -2
package/dist/session.d.ts CHANGED
@@ -1,74 +1,10 @@
1
+ import { type BatchProgress } from "./errors.ts";
2
+ import { type ConfigResolver, type ConfigurationContext } from "./config.ts";
1
3
  import type { Stagehand } from "@browserbasehq/stagehand";
4
+ import { z } from "zod";
2
5
  import type { AIParams, BrowserParams } from "./schema.ts";
3
6
  import { type CookieProvider } from "./browser-cookies.ts";
4
7
  import { type HostClassify } from "./classifier.ts";
5
- export interface BrowseConfig {
6
- apiKey?: string;
7
- projectId?: string;
8
- model?: string;
9
- modelApiKey?: string;
10
- /** Vercel AI Gateway key for JEV's default classifier; resolvers should load it only for purpose "jev". */
11
- jevApiKey?: string;
12
- /**
13
- * Classifier for JEV targeting: absent or `vercel` (Jev on Vercel AI Gateway), `workers-ai` (Jev 1.14 on Workers AI)
14
- * or `workers-ai/<model>`, or a host classifier as `<provider>/<id>`.
15
- */
16
- jevModel?: string;
17
- /** Classifier for ask's bool and choice fields: absent is Clef on Workers AI; takes the same values as jevModel. */
18
- askModel?: string;
19
- /**
20
- * Cloudflare account and Workers AI token for ask, and for JEV on Workers AI; resolvers should load the token only for
21
- * purposes "ask" and "jev".
22
- */
23
- cloudflareAccountId?: string;
24
- cloudflareApiKey?: string;
25
- /** Optional profile-specific file containing only saved-context identifiers. */
26
- contextHistoryPath?: string;
27
- /** Browserbase region for new sessions; validated against the SDK's regions. Absent uses Browserbase's default (us-west-2). */
28
- region?: string;
29
- /**
30
- * Chrome user data directory for local launches, so logins and installed extensions persist across launches. Absent
31
- * launches a temporary profile that close deletes. Only one browser can use the directory at a time.
32
- */
33
- localUserDataDir?: string;
34
- /** Chrome or Chromium executable for local launches; absent uses CHROME_PATH or Stagehand's discovery of an installed Chrome. */
35
- localExecutablePath?: string;
36
- /**
37
- * Bare domains, each with its subdomains, that this profile's browsers may reach; every other http(s) request fails,
38
- * page resources included. A start can narrow the list, never widen it.
39
- */
40
- allowedDomains?: string[];
41
- /** Bare domains, each with its subdomains, that this profile's browsers never reach; a start can add more. */
42
- blockedDomains?: string[];
43
- /** Browserbase navigation policy for hosted sessions (browserSettings.riskPolicyId); the project must enforce policies. */
44
- navigationPolicyId?: string;
45
- /**
46
- * Browsers start can attach to by name (endpoint): a DevTools URL, headers for an authenticated gateway (secrets that
47
- * never reach results), and the URL Stagehand's in-browser extension uses when the browser runs on another machine.
48
- */
49
- remoteBrowsers?: Record<string, RemoteBrowser>;
50
- /**
51
- * The user's own browser, through OpenCode Browse: `command` is the argv that runs `browse mcp`, on this machine or
52
- * over SSH on the machine with the browser. When set, a local start that names no cdpUrl, endpoint, or headless works
53
- * in that browser instead of launching one.
54
- */
55
- realBrowser?: {
56
- command: string[];
57
- };
58
- }
59
- /** A browser to attach to. extensionCdpUrl is the browser-level DevTools URL the browser itself reaches without headers. */
60
- export interface RemoteBrowser {
61
- cdpUrl: string;
62
- headers?: Record<string, string>;
63
- extensionCdpUrl?: string;
64
- }
65
- /** A browser's domain fence as bare domains, each covering its subdomains. */
66
- export interface DomainLists {
67
- allowedDomains?: string[];
68
- blockedDomains?: string[];
69
- }
70
- /** The profile's domain lists, narrowed by start: start's allowed domains must fall inside the profile's, and blocked ones add up. */
71
- export declare function domainLists(config: BrowseConfig, start: Pick<BrowserParams, "allowedDomains" | "blockedDomains">): DomainLists | undefined;
72
8
  type StagehandModel = NonNullable<NonNullable<Parameters<typeof Stagehand.create>[0]>["model"]>;
73
9
  /** Stagehand's bring-your-own-LLM callback: default inference for act/observe/extract when no model is configured. */
74
10
  export type ClientGenerate = Extract<StagehandModel, {
@@ -76,8 +12,9 @@ export type ClientGenerate = Extract<StagehandModel, {
76
12
  }>["generate"];
77
13
  /** Stagehand's default inference when no Stagehand model is configured. */
78
14
  export interface ClientInference {
79
- generate: ClientGenerate;
80
- /** Names the model `generate` runs now, for status. */
15
+ /** Default for AI runs. Hosts that supply a provider for each run can omit this method. */
16
+ generate?(params: Parameters<ClientGenerate>[0], signal: AbortSignal): ReturnType<ClientGenerate>;
17
+ /** Names the host model for status. */
81
18
  describe: () => Promise<string>;
82
19
  }
83
20
  /** The host running the core: `name` appears in messages, `integration` in Browserbase metadata, HAR files, and temp paths. */
@@ -100,42 +37,6 @@ export interface AnsweredDialog {
100
37
  message: string;
101
38
  answer: "ok" | "cancel";
102
39
  }
103
- export interface ConfigurationContext {
104
- sessionId: string;
105
- profile: string;
106
- cwd: string;
107
- signal: AbortSignal;
108
- purpose: "browser" | "ai" | "jev" | "ask";
109
- /** Selected browser backend; local controls do not need Browserbase credentials. */
110
- backend?: "browserbase" | "local";
111
- /**
112
- * For purposes "jev" and "ask", the classifier chosen with /browse jev-model or ask-model. It replaces the returned jevModel or askModel,
113
- * so load the credentials it needs.
114
- */
115
- classifier?: string;
116
- }
117
- export type ConfigResolver = (context: ConfigurationContext) => BrowseConfig | Promise<BrowseConfig>;
118
- export declare function environmentConfig(): BrowseConfig;
119
- /** How far a batch got. */
120
- export interface BatchProgress {
121
- total: number;
122
- /** Steps confirmed to have completed; absent when a lost reply, deadline, or cancellation leaves that unknown. */
123
- completed?: number;
124
- /** Zero-based index of the step that stopped the batch. */
125
- failedIndex?: number;
126
- /** True when steps may have run without being confirmed: inspect the page before repeating anything. */
127
- outcomeUnknown: boolean;
128
- error?: {
129
- code: string;
130
- message: string;
131
- };
132
- }
133
- export declare class BrowseToolError extends Error {
134
- readonly code: string;
135
- readonly batch?: BatchProgress | undefined;
136
- /** `batch` is set on a failed batch call. */
137
- constructor(code: string, message: string, batch?: BatchProgress | undefined);
138
- }
139
40
  export interface BrowserOutput {
140
41
  action: string;
141
42
  sessionId: string | null;
@@ -177,6 +78,7 @@ export declare class BrowseSession {
177
78
  private snapshotNumber;
178
79
  private generation;
179
80
  private readonly contextReadyAt;
81
+ private readonly results;
180
82
  private readonly secrets;
181
83
  /** Cleared for the process lifetime once Browserbase refuses keepAlive for this plan. */
182
84
  private keepAliveAllowed;
@@ -190,21 +92,37 @@ export declare class BrowseSession {
190
92
  private readonly extensions;
191
93
  /** Default inference for every Stagehand instance; without it, unconfigured AI calls use Model Gateway's automatic selection. */
192
94
  private readonly stagehandModel;
95
+ private readonly aiOwner;
193
96
  private readonly describeInference;
97
+ private readonly defaultGenerate;
194
98
  /** Backend for a start, open, tab_new, or cookie_import that names none while no browser is open: the profile's /browse backend setting, else the loader's default, else local. */
195
99
  defaultBackend: "browserbase" | "local";
196
100
  constructor(resolveConfig?: ConfigResolver, inference?: ClientInference, hostClassify?: HostClassify | undefined, identity?: HostIdentity, options?: BrowseSessionOptions);
101
+ /** Host-facing output. Keep raw run() available for SDK consumers and the broker. */
102
+ encodeResult(output: BrowserOutput, scope: Pick<ConfigurationContext, "profile" | "sessionId">): {
103
+ json: string;
104
+ metadata: Record<string, z.JSONType>;
105
+ image: Uint8Array<ArrayBufferLike> | undefined;
106
+ isError: boolean;
107
+ };
108
+ encodeError(cause: unknown): {
109
+ json: string;
110
+ metadata: Record<string, z.JSONType>;
111
+ isError: true;
112
+ image: undefined;
113
+ };
197
114
  redact(text: string): string;
198
115
  /**
199
116
  * Queues one operation behind this conversation's earlier ones. `ai` marks a browse_ai call; as a function it runs
200
117
  * once the call reaches the front of the queue, so per-call state such as the inference model belongs to the running call.
201
118
  */
202
- run(params: BrowserParams | AIParams, context: Omit<ConfigurationContext, "signal" | "purpose">, signal?: AbortSignal, ai?: boolean | (() => void)): Promise<BrowserOutput>;
119
+ run(params: BrowserParams | AIParams, context: Omit<ConfigurationContext, "signal" | "purpose">, signal?: AbortSignal, ai?: boolean | ((signal: AbortSignal) => ClientGenerate | void)): Promise<BrowserOutput>;
203
120
  shutdown(): Promise<void>;
204
121
  /** Which credentials resolve for this profile. Starts no browser and leaves the session alone. */
205
122
  readiness(context: Omit<ConfigurationContext, "signal" | "purpose">, signal: AbortSignal): Promise<{
206
123
  credentials: boolean;
207
124
  region: string;
125
+ regionValid: boolean;
208
126
  aiModel: string | undefined;
209
127
  jevModel: string;
210
128
  jevKey: boolean;
@@ -287,6 +205,8 @@ export declare class BrowseSession {
287
205
  private ownedByOther;
288
206
  /** The tabs this conversation may use: all of them, except in a shared browser the ones another conversation uses. */
289
207
  private visiblePages;
208
+ /** Browser-level DevTools endpoint of a browser we launched or the provider hosts. */
209
+ private devToolsUrl;
290
210
  /** Starts recording every tab's network traffic over a DevTools connection of its own. */
291
211
  private harStart;
292
212
  private closeOwned;
@@ -307,6 +227,8 @@ export declare class BrowseSession {
307
227
  private prepare;
308
228
  /** Applies a completed action to the conversation's state (selected tab, snapshot refs) and returns what its result reports. */
309
229
  private finish;
230
+ /** Stagehand 4.4 keyPress loses printable Shift key metadata. Send this chord through the selected tab's DevTools target. */
231
+ private shiftedKey;
310
232
  private direct;
311
233
  /**
312
234
  * batch: the steps run in order beside the browser in one request, under one deadline. The first failure stops the
@@ -330,8 +252,7 @@ export declare class BrowseSession {
330
252
  */
331
253
  private ask;
332
254
  /**
333
- * JEV mode: a classifier (Jev unless jevModel names another) picks the element for a plain-language target from a
334
- * fresh snapshot; no xpath means it declined to act.
255
+ * JEV mode: a classifier (Jev unless jevModel names another) picks a versioned snapshot ref. The worker must still verify it after inference.
335
256
  */
336
257
  private locate;
337
258
  /** Jev's pick among the candidates; a failed request says whether retrying can help. */