@orkestrel/browser 0.0.23 → 0.0.24

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.
@@ -22,9 +22,12 @@ import type { ChildProcess } from 'node:child_process';
22
22
  import type { EmitterErrorHandler } from '@orkestrel/emitter';
23
23
  import type { EmitterHooks } from '@orkestrel/emitter';
24
24
  import type { EmitterInterface } from '@orkestrel/emitter';
25
+ import type { PoolToken } from '@orkestrel/pool';
25
26
  import type { Readable } from 'node:stream';
26
27
  import type { Result } from '@orkestrel/contract';
27
28
  import type { StdioServerOptions } from '@orkestrel/mcp/server';
29
+ import type { ToolDefinition } from '@orkestrel/tool';
30
+ import type { ToolInterface } from '@orkestrel/tool';
28
31
 
29
32
  /**
30
33
  * Discovers, launches, connects to, and owns Chromium-family browser sessions.
@@ -185,12 +188,21 @@ export declare const BROWSER_RUN_DIRECTORY = "runs";
185
188
  /** Names the persisted run snapshot. */
186
189
  export declare const BROWSER_RUN_FILE = "run.json";
187
190
 
191
+ /** Names the refusal when every browser is admitted to a holder. */
192
+ export declare const BROWSER_SERVER_BUSY = "BROWSER_SERVER_BUSY";
193
+
194
+ /** Defines the holder tools independently of the shared browser's vocabulary. */
195
+ export declare const BROWSER_SERVER_COPY: Readonly<Record<BrowserServerToolName, ToolDefinition>>;
196
+
188
197
  /** Names the notice that a browser and its session state were lost. */
189
198
  export declare const BROWSER_SERVER_CRASH = "BROWSER_SERVER_CRASH";
190
199
 
191
200
  /** Names the diagnostic when the warm floor spends its restart bound. */
192
201
  export declare const BROWSER_SERVER_EXHAUSTED = "BROWSER_SERVER_EXHAUSTED";
193
202
 
203
+ /** Names the refusal for an unknown or ended holder. */
204
+ export declare const BROWSER_SERVER_HOLDER = "BROWSER_SERVER_HOLDER";
205
+
194
206
  /** Names a failed attempt to warm a browser. */
195
207
  export declare const BROWSER_SERVER_LAUNCH = "BROWSER_SERVER_LAUNCH";
196
208
 
@@ -482,7 +494,7 @@ export declare interface BrowserInterface {
482
494
  * Creates a browser a browse server connects while warming its pool.
483
495
  *
484
496
  * @param options - The launch the server composes: `headless`, `executable`, the profile it
485
- * owns, `cdp.discover` set to `false`, and the signal its `destroy()` aborts
497
+ * owns, the optional `viewport`, `cdp.discover` set to `false`, and the signal its `destroy()` aborts
486
498
  * @returns A browser whose `connect()` launches it
487
499
  */
488
500
  export declare type BrowserLaunchFunction = (options: BrowserOptions) => BrowserInterface;
@@ -499,8 +511,11 @@ export declare type BrowserLaunchFunction = (options: BrowserOptions) => Browser
499
511
  * absent. After the launch, a tool the toolset's manager adds under another name, such as a page
500
512
  * tool it adopts, is mirrored as a dispatcher with that tool's definition, and the mirror is
501
513
  * removed when the toolset withdraws the tool, so the server's tool list changes and a subscribed
502
- * client is notified. Startup warms the pool and leases one validated browser. The legacy
503
- * handshake and every tool call await that setup; concurrent callers share a replacement lease.
514
+ * client is notified. The server also advertises `acquire`, `execute`, `tools`, and `destroy` with
515
+ * `BROWSER_SERVER_COPY`. Startup warms the pool and leases the shared browser. The legacy
516
+ * handshake and browser calls await that setup. Named holders each own a lease, a pending grant,
517
+ * and loss notices; concurrent calls on a holder share its replacement grant. Ending a holder
518
+ * destroys its token, and admission counts that holder until disposal settles.
504
519
  * A launch creates `ROOT/.profiles/PID-UUID/` exclusively, connects a browser that never attaches to an
505
520
  * existing endpoint, opens one page in an isolated context, and constructs the page toolset with
506
521
  * that context and the file journey and run stores under the root, on a manager the toolset owns.
@@ -510,6 +525,8 @@ export declare type BrowserLaunchFunction = (options: BrowserOptions) => Browser
510
525
  * A disconnect or current-page crash retires its slot. A failed call receives a liveness ping;
511
526
  * loss makes its outcome unresolved, while a known success remains successful. Pending losses
512
527
  * prefix the next outcome on a successor, or a refusal, and calls are never repeated.
528
+ * Concurrent checks share one ping per slot. Cancelling a call ends only its wait; the ping keeps
529
+ * its deadline and records loss for the next call.
513
530
  *
514
531
  * `start()` serves stdio and destroys the server at the end of its input, on `SIGINT`, and on
515
532
  * `SIGTERM`. `destroy()` stops reading requests and removes every dispatcher, then destroys every
@@ -545,7 +562,7 @@ export declare class BrowserMCPServer implements BrowserMCPServerInterface {
545
562
  export declare interface BrowserMCPServerInterface {
546
563
  /**
547
564
  * Serves stdio, sweeps the profiles ended servers left, warms the pool, and resolves after the
548
- * session leases a warm browser; the legacy handshake and every tool call await the same setup.
565
+ * shared holder leases a warm browser; the legacy handshake and every tool call await the same setup.
549
566
  * Rejects with `BROWSER_SERVER_UNAVAILABLE` when no browser can serve and with
550
567
  * `BROWSER_TOOLSET_ENDED` after `destroy()`, and resolves when `destroy()` interrupts setup.
551
568
  */
@@ -566,6 +583,8 @@ export declare interface BrowserMCPServerInterface {
566
583
  * `true`
567
584
  * - `executable` — the path of the Chromium executable the server launches. Default: the browser
568
585
  * `findSystemBrowser` finds
586
+ * - `viewport` — the default viewport for every page in each browser's isolated context;
587
+ * omission keeps the browser's launch default
569
588
  * - `readonly` — if `true`, refuses `record`, `save`, `edit`, and `forget`, and `replay` still writes runs;
570
589
  * if `false` or omitted, every tool runs
571
590
  * - `launch` — creates each browser the pool warms. Default: `createBrowser`
@@ -580,6 +599,7 @@ export declare interface BrowserMCPServerOptions {
580
599
  readonly root?: string;
581
600
  readonly headless?: boolean;
582
601
  readonly executable?: string;
602
+ readonly viewport?: BrowserViewport;
583
603
  readonly readonly?: boolean;
584
604
  readonly launch?: BrowserLaunchFunction;
585
605
  readonly stdio?: StdioServerOptions;
@@ -653,6 +673,30 @@ export declare interface BrowserProfileResult {
653
673
  readonly temporary: boolean;
654
674
  }
655
675
 
676
+ /** Describes the JSON catalog returned by the holder tools. */
677
+ export declare interface BrowserServerCatalog {
678
+ readonly holder: string;
679
+ readonly tools: readonly ToolDefinition[];
680
+ }
681
+
682
+ /** Identifies one admitted browser lifetime independently of its current pool token. */
683
+ export declare interface BrowserServerHolder {
684
+ readonly id: string;
685
+ readonly purpose: string;
686
+ readonly abort: AbortController;
687
+ }
688
+
689
+ /** Binds shared catalog subscriptions to the exact token that published them. */
690
+ export declare interface BrowserServerMirror {
691
+ readonly token: PoolToken<BrowserSlot>;
692
+ readonly added: (tool: ToolInterface) => void;
693
+ readonly removed: (tool: ToolInterface) => void;
694
+ readonly cleared: (tools: readonly ToolInterface[]) => void;
695
+ }
696
+
697
+ /** Names the server tools that manage independent browser holders. */
698
+ export declare type BrowserServerToolName = 'acquire' | 'execute' | 'tools' | 'destroy';
699
+
656
700
  /** Holds one warm browser a browse server owns: the browser, its profile, its isolated context, and its started toolset. */
657
701
  export declare interface BrowserSlot {
658
702
  readonly browser: BrowserInterface;
@@ -832,6 +876,7 @@ export declare class FileBrowserJourneyStore implements BrowserJourneyStoreInter
832
876
  export declare class FileBrowserRunStore implements BrowserRunStoreInterface {
833
877
  #private;
834
878
  constructor(options: FileBrowserStoreOptions);
879
+ snapshot(bytes: Uint8Array, options?: BrowserStoreOptions): Promise<string>;
835
880
  open(name: string, options?: BrowserStoreOptions): Promise<BrowserRunSlot>;
836
881
  get(name: string, id: string, options?: BrowserStoreOptions): Promise<BrowserRun | undefined>;
837
882
  set(run: BrowserRun, options?: BrowserStoreOptions): Promise<void>;
@@ -1003,6 +1048,15 @@ export declare function parseBrowserLockEntry(name: string): number | undefined;
1003
1048
  */
1004
1049
  export declare function parseBrowserProfileRecord(text: string): BrowserProfileRecord | undefined;
1005
1050
 
1051
+ /**
1052
+ * Parses positive integer viewport dimensions in WIDTHxHEIGHT form.
1053
+ * @param value - The viewport environment variable, or undefined when unset
1054
+ * @returns The viewport, or undefined when absent or malformed
1055
+ * @example
1056
+ * parseBrowserViewport('1280x720') // { width: 1280, height: 720 }
1057
+ */
1058
+ export declare function parseBrowserViewport(value: string | undefined): BrowserViewport | undefined;
1059
+
1006
1060
  /** Probes PATH (`which`/`where`) for every resolvable command name, in the given order. */
1007
1061
  export declare function probePathNames(names: readonly string[], platform: string): readonly string[];
1008
1062
 
@@ -22,9 +22,12 @@ import type { ChildProcess } from 'node:child_process';
22
22
  import type { EmitterErrorHandler } from '@orkestrel/emitter';
23
23
  import type { EmitterHooks } from '@orkestrel/emitter';
24
24
  import type { EmitterInterface } from '@orkestrel/emitter';
25
+ import type { PoolToken } from '@orkestrel/pool';
25
26
  import type { Readable } from 'node:stream';
26
27
  import type { Result } from '@orkestrel/contract';
27
28
  import type { StdioServerOptions } from '@orkestrel/mcp/server';
29
+ import type { ToolDefinition } from '@orkestrel/tool';
30
+ import type { ToolInterface } from '@orkestrel/tool';
28
31
 
29
32
  /**
30
33
  * Discovers, launches, connects to, and owns Chromium-family browser sessions.
@@ -185,12 +188,21 @@ export declare const BROWSER_RUN_DIRECTORY = "runs";
185
188
  /** Names the persisted run snapshot. */
186
189
  export declare const BROWSER_RUN_FILE = "run.json";
187
190
 
191
+ /** Names the refusal when every browser is admitted to a holder. */
192
+ export declare const BROWSER_SERVER_BUSY = "BROWSER_SERVER_BUSY";
193
+
194
+ /** Defines the holder tools independently of the shared browser's vocabulary. */
195
+ export declare const BROWSER_SERVER_COPY: Readonly<Record<BrowserServerToolName, ToolDefinition>>;
196
+
188
197
  /** Names the notice that a browser and its session state were lost. */
189
198
  export declare const BROWSER_SERVER_CRASH = "BROWSER_SERVER_CRASH";
190
199
 
191
200
  /** Names the diagnostic when the warm floor spends its restart bound. */
192
201
  export declare const BROWSER_SERVER_EXHAUSTED = "BROWSER_SERVER_EXHAUSTED";
193
202
 
203
+ /** Names the refusal for an unknown or ended holder. */
204
+ export declare const BROWSER_SERVER_HOLDER = "BROWSER_SERVER_HOLDER";
205
+
194
206
  /** Names a failed attempt to warm a browser. */
195
207
  export declare const BROWSER_SERVER_LAUNCH = "BROWSER_SERVER_LAUNCH";
196
208
 
@@ -482,7 +494,7 @@ export declare interface BrowserInterface {
482
494
  * Creates a browser a browse server connects while warming its pool.
483
495
  *
484
496
  * @param options - The launch the server composes: `headless`, `executable`, the profile it
485
- * owns, `cdp.discover` set to `false`, and the signal its `destroy()` aborts
497
+ * owns, the optional `viewport`, `cdp.discover` set to `false`, and the signal its `destroy()` aborts
486
498
  * @returns A browser whose `connect()` launches it
487
499
  */
488
500
  export declare type BrowserLaunchFunction = (options: BrowserOptions) => BrowserInterface;
@@ -499,8 +511,11 @@ export declare type BrowserLaunchFunction = (options: BrowserOptions) => Browser
499
511
  * absent. After the launch, a tool the toolset's manager adds under another name, such as a page
500
512
  * tool it adopts, is mirrored as a dispatcher with that tool's definition, and the mirror is
501
513
  * removed when the toolset withdraws the tool, so the server's tool list changes and a subscribed
502
- * client is notified. Startup warms the pool and leases one validated browser. The legacy
503
- * handshake and every tool call await that setup; concurrent callers share a replacement lease.
514
+ * client is notified. The server also advertises `acquire`, `execute`, `tools`, and `destroy` with
515
+ * `BROWSER_SERVER_COPY`. Startup warms the pool and leases the shared browser. The legacy
516
+ * handshake and browser calls await that setup. Named holders each own a lease, a pending grant,
517
+ * and loss notices; concurrent calls on a holder share its replacement grant. Ending a holder
518
+ * destroys its token, and admission counts that holder until disposal settles.
504
519
  * A launch creates `ROOT/.profiles/PID-UUID/` exclusively, connects a browser that never attaches to an
505
520
  * existing endpoint, opens one page in an isolated context, and constructs the page toolset with
506
521
  * that context and the file journey and run stores under the root, on a manager the toolset owns.
@@ -510,6 +525,8 @@ export declare type BrowserLaunchFunction = (options: BrowserOptions) => Browser
510
525
  * A disconnect or current-page crash retires its slot. A failed call receives a liveness ping;
511
526
  * loss makes its outcome unresolved, while a known success remains successful. Pending losses
512
527
  * prefix the next outcome on a successor, or a refusal, and calls are never repeated.
528
+ * Concurrent checks share one ping per slot. Cancelling a call ends only its wait; the ping keeps
529
+ * its deadline and records loss for the next call.
513
530
  *
514
531
  * `start()` serves stdio and destroys the server at the end of its input, on `SIGINT`, and on
515
532
  * `SIGTERM`. `destroy()` stops reading requests and removes every dispatcher, then destroys every
@@ -545,7 +562,7 @@ export declare class BrowserMCPServer implements BrowserMCPServerInterface {
545
562
  export declare interface BrowserMCPServerInterface {
546
563
  /**
547
564
  * Serves stdio, sweeps the profiles ended servers left, warms the pool, and resolves after the
548
- * session leases a warm browser; the legacy handshake and every tool call await the same setup.
565
+ * shared holder leases a warm browser; the legacy handshake and every tool call await the same setup.
549
566
  * Rejects with `BROWSER_SERVER_UNAVAILABLE` when no browser can serve and with
550
567
  * `BROWSER_TOOLSET_ENDED` after `destroy()`, and resolves when `destroy()` interrupts setup.
551
568
  */
@@ -566,6 +583,8 @@ export declare interface BrowserMCPServerInterface {
566
583
  * `true`
567
584
  * - `executable` — the path of the Chromium executable the server launches. Default: the browser
568
585
  * `findSystemBrowser` finds
586
+ * - `viewport` — the default viewport for every page in each browser's isolated context;
587
+ * omission keeps the browser's launch default
569
588
  * - `readonly` — if `true`, refuses `record`, `save`, `edit`, and `forget`, and `replay` still writes runs;
570
589
  * if `false` or omitted, every tool runs
571
590
  * - `launch` — creates each browser the pool warms. Default: `createBrowser`
@@ -580,6 +599,7 @@ export declare interface BrowserMCPServerOptions {
580
599
  readonly root?: string;
581
600
  readonly headless?: boolean;
582
601
  readonly executable?: string;
602
+ readonly viewport?: BrowserViewport;
583
603
  readonly readonly?: boolean;
584
604
  readonly launch?: BrowserLaunchFunction;
585
605
  readonly stdio?: StdioServerOptions;
@@ -653,6 +673,30 @@ export declare interface BrowserProfileResult {
653
673
  readonly temporary: boolean;
654
674
  }
655
675
 
676
+ /** Describes the JSON catalog returned by the holder tools. */
677
+ export declare interface BrowserServerCatalog {
678
+ readonly holder: string;
679
+ readonly tools: readonly ToolDefinition[];
680
+ }
681
+
682
+ /** Identifies one admitted browser lifetime independently of its current pool token. */
683
+ export declare interface BrowserServerHolder {
684
+ readonly id: string;
685
+ readonly purpose: string;
686
+ readonly abort: AbortController;
687
+ }
688
+
689
+ /** Binds shared catalog subscriptions to the exact token that published them. */
690
+ export declare interface BrowserServerMirror {
691
+ readonly token: PoolToken<BrowserSlot>;
692
+ readonly added: (tool: ToolInterface) => void;
693
+ readonly removed: (tool: ToolInterface) => void;
694
+ readonly cleared: (tools: readonly ToolInterface[]) => void;
695
+ }
696
+
697
+ /** Names the server tools that manage independent browser holders. */
698
+ export declare type BrowserServerToolName = 'acquire' | 'execute' | 'tools' | 'destroy';
699
+
656
700
  /** Holds one warm browser a browse server owns: the browser, its profile, its isolated context, and its started toolset. */
657
701
  export declare interface BrowserSlot {
658
702
  readonly browser: BrowserInterface;
@@ -832,6 +876,7 @@ export declare class FileBrowserJourneyStore implements BrowserJourneyStoreInter
832
876
  export declare class FileBrowserRunStore implements BrowserRunStoreInterface {
833
877
  #private;
834
878
  constructor(options: FileBrowserStoreOptions);
879
+ snapshot(bytes: Uint8Array, options?: BrowserStoreOptions): Promise<string>;
835
880
  open(name: string, options?: BrowserStoreOptions): Promise<BrowserRunSlot>;
836
881
  get(name: string, id: string, options?: BrowserStoreOptions): Promise<BrowserRun | undefined>;
837
882
  set(run: BrowserRun, options?: BrowserStoreOptions): Promise<void>;
@@ -1003,6 +1048,15 @@ export declare function parseBrowserLockEntry(name: string): number | undefined;
1003
1048
  */
1004
1049
  export declare function parseBrowserProfileRecord(text: string): BrowserProfileRecord | undefined;
1005
1050
 
1051
+ /**
1052
+ * Parses positive integer viewport dimensions in WIDTHxHEIGHT form.
1053
+ * @param value - The viewport environment variable, or undefined when unset
1054
+ * @returns The viewport, or undefined when absent or malformed
1055
+ * @example
1056
+ * parseBrowserViewport('1280x720') // { width: 1280, height: 720 }
1057
+ */
1058
+ export declare function parseBrowserViewport(value: string | undefined): BrowserViewport | undefined;
1059
+
1006
1060
  /** Probes PATH (`which`/`where`) for every resolvable command name, in the given order. */
1007
1061
  export declare function probePathNames(names: readonly string[], platform: string): readonly string[];
1008
1062