@oya-ai/browser 1.0.241 → 1.0.243
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/dist/index.cjs +28 -5
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +28 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -129,7 +129,7 @@ function saveKey(apiKey, baseUrl) {
|
|
|
129
129
|
|
|
130
130
|
// src/client.ts
|
|
131
131
|
var OPTIONS_ORIGIN = { apiKeyFrom: "the apiKey option", baseUrlFrom: "the baseUrl option", savedKey: false };
|
|
132
|
-
var Http = class {
|
|
132
|
+
var Http = class _Http {
|
|
133
133
|
/** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
|
|
134
134
|
constructor(baseUrl, apiKey, timeoutMs, fetchImpl, origin = OPTIONS_ORIGIN, defaults = {}) {
|
|
135
135
|
this.baseUrl = baseUrl;
|
|
@@ -145,6 +145,14 @@ var Http = class {
|
|
|
145
145
|
fetchImpl;
|
|
146
146
|
origin;
|
|
147
147
|
defaults;
|
|
148
|
+
/**
|
|
149
|
+
* The same client with `headers` on every request it sends. A browser that shares a person's
|
|
150
|
+
* desktop names its lane this way once, so no call it makes can leave the lane out.
|
|
151
|
+
*/
|
|
152
|
+
withHeaders(headers) {
|
|
153
|
+
const merged = { ...this.defaults, ...headers };
|
|
154
|
+
return new _Http(this.baseUrl, this.apiKey, this.timeoutMs, this.fetchImpl, this.origin, merged);
|
|
155
|
+
}
|
|
148
156
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
149
157
|
async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
|
|
150
158
|
const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
|
|
@@ -393,15 +401,20 @@ var Run = class {
|
|
|
393
401
|
};
|
|
394
402
|
|
|
395
403
|
// src/browser.ts
|
|
404
|
+
var LANE_HEADER = "X-Oya-Agent";
|
|
405
|
+
var sdkLane = () => `sdk-${globalThis.crypto.randomUUID()}`;
|
|
396
406
|
var Browser = class {
|
|
397
|
-
/**
|
|
407
|
+
/**
|
|
408
|
+
* Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. A browser
|
|
409
|
+
* handed over already running (a person's desktop app) gets one lane for its whole life,
|
|
410
|
+
* so the desktop gives its goto, ask and play one tab of its own, never the person's.
|
|
411
|
+
*/
|
|
398
412
|
constructor(http, info, autoCaptcha) {
|
|
399
|
-
this.http = http;
|
|
400
413
|
this.autoCaptcha = autoCaptcha;
|
|
401
414
|
({ id: this.id, provider: this.provider, persona: this.persona, cdpUrl: this.cdpUrl } = info);
|
|
402
415
|
this.reused = info.reused === true;
|
|
416
|
+
this.http = this.reused ? http.withHeaders({ [LANE_HEADER]: sdkLane() }) : http;
|
|
403
417
|
}
|
|
404
|
-
http;
|
|
405
418
|
autoCaptcha;
|
|
406
419
|
/** The browser's id. */
|
|
407
420
|
id;
|
|
@@ -413,6 +426,8 @@ var Browser = class {
|
|
|
413
426
|
cdpUrl;
|
|
414
427
|
/** True when `start()` handed over a browser that was already running, such as the desktop app. */
|
|
415
428
|
reused;
|
|
429
|
+
/** How this browser reaches the API: with its lane on every request when it shares someone's browser. */
|
|
430
|
+
http;
|
|
416
431
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
417
432
|
async command(action, params = {}, timeoutMs) {
|
|
418
433
|
const path = `/api/browsers/${this.id}/command`;
|
|
@@ -610,9 +625,17 @@ var Browser = class {
|
|
|
610
625
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
611
626
|
*/
|
|
612
627
|
stop() {
|
|
613
|
-
if (this.reused) return
|
|
628
|
+
if (this.reused) return this.endLane();
|
|
614
629
|
return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
|
|
615
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
633
|
+
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
634
|
+
*/
|
|
635
|
+
async endLane() {
|
|
636
|
+
await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
637
|
+
return { id: this.id, ok: true, reused: true };
|
|
638
|
+
}
|
|
616
639
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
617
640
|
async [Symbol.asyncDispose]() {
|
|
618
641
|
await this.stop();
|
package/dist/index.d.cts
CHANGED
|
@@ -1071,6 +1071,11 @@ declare class Http {
|
|
|
1071
1071
|
private readonly defaults;
|
|
1072
1072
|
/** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
|
|
1073
1073
|
constructor(baseUrl: string, apiKey: string, timeoutMs: number, fetchImpl: typeof globalThis.fetch, origin?: Origin, defaults?: Record<string, string>);
|
|
1074
|
+
/**
|
|
1075
|
+
* The same client with `headers` on every request it sends. A browser that shares a person's
|
|
1076
|
+
* desktop names its lane this way once, so no call it makes can leave the lane out.
|
|
1077
|
+
*/
|
|
1078
|
+
withHeaders(headers: Record<string, string>): Http;
|
|
1074
1079
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
1075
1080
|
request<T>(method: string, path: string, body?: unknown, timeoutMs?: number, headers?: Record<string, string>): Promise<T>;
|
|
1076
1081
|
/** The fetch options for one call, with this client's key on them. */
|
|
@@ -1373,7 +1378,6 @@ declare class Run {
|
|
|
1373
1378
|
* bug; call `analyze()` again.
|
|
1374
1379
|
*/
|
|
1375
1380
|
declare class Browser {
|
|
1376
|
-
private readonly http;
|
|
1377
1381
|
private readonly autoCaptcha;
|
|
1378
1382
|
/** The browser's id. */
|
|
1379
1383
|
readonly id: string;
|
|
@@ -1385,7 +1389,13 @@ declare class Browser {
|
|
|
1385
1389
|
readonly cdpUrl?: string;
|
|
1386
1390
|
/** True when `start()` handed over a browser that was already running, such as the desktop app. */
|
|
1387
1391
|
readonly reused: boolean;
|
|
1388
|
-
/**
|
|
1392
|
+
/** How this browser reaches the API: with its lane on every request when it shares someone's browser. */
|
|
1393
|
+
private readonly http;
|
|
1394
|
+
/**
|
|
1395
|
+
* Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. A browser
|
|
1396
|
+
* handed over already running (a person's desktop app) gets one lane for its whole life,
|
|
1397
|
+
* so the desktop gives its goto, ask and play one tab of its own, never the person's.
|
|
1398
|
+
*/
|
|
1389
1399
|
constructor(http: Http, info: StartResult, autoCaptcha: boolean);
|
|
1390
1400
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
1391
1401
|
private command;
|
|
@@ -1503,6 +1513,11 @@ declare class Browser {
|
|
|
1503
1513
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
1504
1514
|
*/
|
|
1505
1515
|
stop(): Promise<StopResult>;
|
|
1516
|
+
/**
|
|
1517
|
+
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
1518
|
+
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
1519
|
+
*/
|
|
1520
|
+
private endLane;
|
|
1506
1521
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
1507
1522
|
[Symbol.asyncDispose](): Promise<void>;
|
|
1508
1523
|
/** @deprecated use stop(), close() only dropped the socket, and a cloud browser redialled. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1071,6 +1071,11 @@ declare class Http {
|
|
|
1071
1071
|
private readonly defaults;
|
|
1072
1072
|
/** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
|
|
1073
1073
|
constructor(baseUrl: string, apiKey: string, timeoutMs: number, fetchImpl: typeof globalThis.fetch, origin?: Origin, defaults?: Record<string, string>);
|
|
1074
|
+
/**
|
|
1075
|
+
* The same client with `headers` on every request it sends. A browser that shares a person's
|
|
1076
|
+
* desktop names its lane this way once, so no call it makes can leave the lane out.
|
|
1077
|
+
*/
|
|
1078
|
+
withHeaders(headers: Record<string, string>): Http;
|
|
1074
1079
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
1075
1080
|
request<T>(method: string, path: string, body?: unknown, timeoutMs?: number, headers?: Record<string, string>): Promise<T>;
|
|
1076
1081
|
/** The fetch options for one call, with this client's key on them. */
|
|
@@ -1373,7 +1378,6 @@ declare class Run {
|
|
|
1373
1378
|
* bug; call `analyze()` again.
|
|
1374
1379
|
*/
|
|
1375
1380
|
declare class Browser {
|
|
1376
|
-
private readonly http;
|
|
1377
1381
|
private readonly autoCaptcha;
|
|
1378
1382
|
/** The browser's id. */
|
|
1379
1383
|
readonly id: string;
|
|
@@ -1385,7 +1389,13 @@ declare class Browser {
|
|
|
1385
1389
|
readonly cdpUrl?: string;
|
|
1386
1390
|
/** True when `start()` handed over a browser that was already running, such as the desktop app. */
|
|
1387
1391
|
readonly reused: boolean;
|
|
1388
|
-
/**
|
|
1392
|
+
/** How this browser reaches the API: with its lane on every request when it shares someone's browser. */
|
|
1393
|
+
private readonly http;
|
|
1394
|
+
/**
|
|
1395
|
+
* Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. A browser
|
|
1396
|
+
* handed over already running (a person's desktop app) gets one lane for its whole life,
|
|
1397
|
+
* so the desktop gives its goto, ask and play one tab of its own, never the person's.
|
|
1398
|
+
*/
|
|
1389
1399
|
constructor(http: Http, info: StartResult, autoCaptcha: boolean);
|
|
1390
1400
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
1391
1401
|
private command;
|
|
@@ -1503,6 +1513,11 @@ declare class Browser {
|
|
|
1503
1513
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
1504
1514
|
*/
|
|
1505
1515
|
stop(): Promise<StopResult>;
|
|
1516
|
+
/**
|
|
1517
|
+
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
1518
|
+
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
1519
|
+
*/
|
|
1520
|
+
private endLane;
|
|
1506
1521
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
1507
1522
|
[Symbol.asyncDispose](): Promise<void>;
|
|
1508
1523
|
/** @deprecated use stop(), close() only dropped the socket, and a cloud browser redialled. */
|
package/dist/index.js
CHANGED
|
@@ -97,7 +97,7 @@ function saveKey(apiKey, baseUrl) {
|
|
|
97
97
|
|
|
98
98
|
// src/client.ts
|
|
99
99
|
var OPTIONS_ORIGIN = { apiKeyFrom: "the apiKey option", baseUrlFrom: "the baseUrl option", savedKey: false };
|
|
100
|
-
var Http = class {
|
|
100
|
+
var Http = class _Http {
|
|
101
101
|
/** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
|
|
102
102
|
constructor(baseUrl, apiKey, timeoutMs, fetchImpl, origin = OPTIONS_ORIGIN, defaults = {}) {
|
|
103
103
|
this.baseUrl = baseUrl;
|
|
@@ -113,6 +113,14 @@ var Http = class {
|
|
|
113
113
|
fetchImpl;
|
|
114
114
|
origin;
|
|
115
115
|
defaults;
|
|
116
|
+
/**
|
|
117
|
+
* The same client with `headers` on every request it sends. A browser that shares a person's
|
|
118
|
+
* desktop names its lane this way once, so no call it makes can leave the lane out.
|
|
119
|
+
*/
|
|
120
|
+
withHeaders(headers) {
|
|
121
|
+
const merged = { ...this.defaults, ...headers };
|
|
122
|
+
return new _Http(this.baseUrl, this.apiKey, this.timeoutMs, this.fetchImpl, this.origin, merged);
|
|
123
|
+
}
|
|
116
124
|
/** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
|
|
117
125
|
async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
|
|
118
126
|
const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
|
|
@@ -361,15 +369,20 @@ var Run = class {
|
|
|
361
369
|
};
|
|
362
370
|
|
|
363
371
|
// src/browser.ts
|
|
372
|
+
var LANE_HEADER = "X-Oya-Agent";
|
|
373
|
+
var sdkLane = () => `sdk-${globalThis.crypto.randomUUID()}`;
|
|
364
374
|
var Browser = class {
|
|
365
|
-
/**
|
|
375
|
+
/**
|
|
376
|
+
* Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. A browser
|
|
377
|
+
* handed over already running (a person's desktop app) gets one lane for its whole life,
|
|
378
|
+
* so the desktop gives its goto, ask and play one tab of its own, never the person's.
|
|
379
|
+
*/
|
|
366
380
|
constructor(http, info, autoCaptcha) {
|
|
367
|
-
this.http = http;
|
|
368
381
|
this.autoCaptcha = autoCaptcha;
|
|
369
382
|
({ id: this.id, provider: this.provider, persona: this.persona, cdpUrl: this.cdpUrl } = info);
|
|
370
383
|
this.reused = info.reused === true;
|
|
384
|
+
this.http = this.reused ? http.withHeaders({ [LANE_HEADER]: sdkLane() }) : http;
|
|
371
385
|
}
|
|
372
|
-
http;
|
|
373
386
|
autoCaptcha;
|
|
374
387
|
/** The browser's id. */
|
|
375
388
|
id;
|
|
@@ -381,6 +394,8 @@ var Browser = class {
|
|
|
381
394
|
cdpUrl;
|
|
382
395
|
/** True when `start()` handed over a browser that was already running, such as the desktop app. */
|
|
383
396
|
reused;
|
|
397
|
+
/** How this browser reaches the API: with its lane on every request when it shares someone's browser. */
|
|
398
|
+
http;
|
|
384
399
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
385
400
|
async command(action, params = {}, timeoutMs) {
|
|
386
401
|
const path = `/api/browsers/${this.id}/command`;
|
|
@@ -578,9 +593,17 @@ var Browser = class {
|
|
|
578
593
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
579
594
|
*/
|
|
580
595
|
stop() {
|
|
581
|
-
if (this.reused) return
|
|
596
|
+
if (this.reused) return this.endLane();
|
|
582
597
|
return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
|
|
583
598
|
}
|
|
599
|
+
/**
|
|
600
|
+
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
601
|
+
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
602
|
+
*/
|
|
603
|
+
async endLane() {
|
|
604
|
+
await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
605
|
+
return { id: this.id, ok: true, reused: true };
|
|
606
|
+
}
|
|
584
607
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
585
608
|
async [Symbol.asyncDispose]() {
|
|
586
609
|
await this.stop();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oya-ai/browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.243",
|
|
4
4
|
"description": "TypeScript SDK for Oya, the HIPAA-compliant agentic browser: start cloud browsers, run playbooks, attach Playwright.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://oyabrowser.com",
|