@oya-ai/browser 1.0.261 → 1.0.265
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 +78 -26
- package/dist/index.js +78 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -114,16 +114,50 @@ function savedConfig() {
|
|
|
114
114
|
return {};
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
var PRIVATE_DIR = 448;
|
|
117
118
|
var PRIVATE_FILE = 384;
|
|
118
119
|
var JSON_INDENT = 2;
|
|
120
|
+
function ensurePrivateDir(fs, dir) {
|
|
121
|
+
fs.mkdirSync(dir, { recursive: true, mode: PRIVATE_DIR });
|
|
122
|
+
try {
|
|
123
|
+
fs.chmodSync(dir, PRIVATE_DIR);
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function openTemp(fs, tmp) {
|
|
128
|
+
const { O_WRONLY, O_CREAT, O_EXCL, O_NOFOLLOW = 0 } = fs.constants;
|
|
129
|
+
return fs.openSync(tmp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, PRIVATE_FILE);
|
|
130
|
+
}
|
|
131
|
+
function writeFd(fs, fd, text) {
|
|
132
|
+
try {
|
|
133
|
+
fs.writeFileSync(fd, text);
|
|
134
|
+
} finally {
|
|
135
|
+
fs.closeSync(fd);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function removeTemp(fs, tmp) {
|
|
139
|
+
try {
|
|
140
|
+
fs.unlinkSync(tmp);
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
var tempFile = (file2) => `${file2.slice(0, file2.lastIndexOf("/"))}/.config.json.${node()?.pid ?? 0}-${globalThis.crypto.randomUUID()}.tmp`;
|
|
145
|
+
function writePrivate(fs, file2, text) {
|
|
146
|
+
const tmp = tempFile(file2);
|
|
147
|
+
try {
|
|
148
|
+
writeFd(fs, openTemp(fs, tmp), text);
|
|
149
|
+
fs.renameSync(tmp, file2);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
removeTemp(fs, tmp);
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
119
155
|
function saveKey(apiKey, baseUrl) {
|
|
120
156
|
const fs = builtin("node:fs");
|
|
121
157
|
const file2 = configFile();
|
|
122
158
|
if (!fs || !file2 || savedConfig().apiKey) return false;
|
|
123
|
-
fs
|
|
124
|
-
fs
|
|
125
|
-
mode: PRIVATE_FILE
|
|
126
|
-
});
|
|
159
|
+
ensurePrivateDir(fs, file2.slice(0, file2.lastIndexOf("/")));
|
|
160
|
+
writePrivate(fs, file2, JSON.stringify({ ...savedConfig(), apiKey, baseUrl }, null, JSON_INDENT));
|
|
127
161
|
return true;
|
|
128
162
|
}
|
|
129
163
|
|
|
@@ -387,12 +421,12 @@ var Run = class {
|
|
|
387
421
|
/** Settles with the result when the run succeeds, or rejects when it fails. */
|
|
388
422
|
done;
|
|
389
423
|
/** The run's current state. */
|
|
390
|
-
status() {
|
|
391
|
-
return this.http.request("GET", `/api/runs/${
|
|
424
|
+
async status() {
|
|
425
|
+
return this.http.request("GET", `/api/runs/${segment(this.id)}`);
|
|
392
426
|
}
|
|
393
427
|
/** Answer the open attention request: `'done'` after handling it by hand, or your reply to the agent. */
|
|
394
428
|
async respond(response = "done") {
|
|
395
|
-
await this.http.request("POST", `/api/runs/${
|
|
429
|
+
await this.http.request("POST", `/api/runs/${segment(this.id)}/respond`, { response });
|
|
396
430
|
}
|
|
397
431
|
/** Polls until the run ends, firing callbacks on the way. */
|
|
398
432
|
watch(cb, pollMs) {
|
|
@@ -430,7 +464,7 @@ var Browser = class {
|
|
|
430
464
|
http;
|
|
431
465
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
432
466
|
async command(action, params = {}, timeoutMs) {
|
|
433
|
-
const path = `/api/browsers/${this.id}/command`;
|
|
467
|
+
const path = `/api/browsers/${segment(this.id)}/command`;
|
|
434
468
|
const result = await this.http.request("POST", path, { action, params }, timeoutMs);
|
|
435
469
|
if (result.ok === false) throw new OyaError(result.error || `${action} failed`, Status.UNPROCESSABLE, result);
|
|
436
470
|
return result.data;
|
|
@@ -513,15 +547,25 @@ var Browser = class {
|
|
|
513
547
|
* Detect and clear a CAPTCHA. Providers that solve natively are left to do
|
|
514
548
|
* it; everything else goes to the configured solver.
|
|
515
549
|
*/
|
|
516
|
-
solveCaptcha() {
|
|
517
|
-
return this.http.request(
|
|
550
|
+
async solveCaptcha() {
|
|
551
|
+
return this.http.request(
|
|
552
|
+
"POST",
|
|
553
|
+
`/api/browsers/${segment(this.id)}/captcha`,
|
|
554
|
+
{},
|
|
555
|
+
CHALLENGE_TIMEOUT_MS
|
|
556
|
+
);
|
|
518
557
|
}
|
|
519
558
|
/**
|
|
520
559
|
* Answer an MFA prompt with the persona's configured factor. When nothing can
|
|
521
560
|
* answer it, `liveViewUrl` is where a person finishes by hand.
|
|
522
561
|
*/
|
|
523
562
|
async completeMfa() {
|
|
524
|
-
const result = await this.http.request(
|
|
563
|
+
const result = await this.http.request(
|
|
564
|
+
"POST",
|
|
565
|
+
`/api/browsers/${segment(this.id)}/mfa`,
|
|
566
|
+
{},
|
|
567
|
+
CHALLENGE_TIMEOUT_MS
|
|
568
|
+
);
|
|
525
569
|
if (result.liveViewUrl) result.liveViewUrl = new URL(result.liveViewUrl, this.http.baseUrl).href;
|
|
526
570
|
return result;
|
|
527
571
|
}
|
|
@@ -533,7 +577,7 @@ var Browser = class {
|
|
|
533
577
|
*/
|
|
534
578
|
async ask(prompt, { data, secrets } = {}) {
|
|
535
579
|
const body = { messages: [{ role: "user", content: prompt }], data, secrets };
|
|
536
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
580
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
537
581
|
return agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS)).text;
|
|
538
582
|
}
|
|
539
583
|
/**
|
|
@@ -542,7 +586,7 @@ var Browser = class {
|
|
|
542
586
|
*/
|
|
543
587
|
async extract(prompt, schema, values = {}) {
|
|
544
588
|
const body = { messages: [{ role: "user", content: prompt }], ...values, schema };
|
|
545
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
589
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
546
590
|
const res = agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS));
|
|
547
591
|
if (res.failed || res.data === void 0) throw new OyaError(res.text, Status.UNPROCESSABLE, res);
|
|
548
592
|
return res.data;
|
|
@@ -553,8 +597,13 @@ var Browser = class {
|
|
|
553
597
|
* `defaults`, so `play()` with nothing repeats the run and any one value can be
|
|
554
598
|
* swapped. `code` is the same flow as a Playwright module, to read or run yourself.
|
|
555
599
|
*/
|
|
556
|
-
toPlaybook(name) {
|
|
557
|
-
return this.http.request(
|
|
600
|
+
async toPlaybook(name) {
|
|
601
|
+
return this.http.request(
|
|
602
|
+
"POST",
|
|
603
|
+
`/api/browsers/${segment(this.id)}/playbooks`,
|
|
604
|
+
{ name },
|
|
605
|
+
PLAYBOOK_TIMEOUT_MS
|
|
606
|
+
);
|
|
558
607
|
}
|
|
559
608
|
/**
|
|
560
609
|
* Replay a playbook with no LLM in the loop. Variables left out reuse the
|
|
@@ -563,7 +612,7 @@ var Browser = class {
|
|
|
563
612
|
* replaces the broken steps in the playbook (`healed`); off, the step's error is thrown.
|
|
564
613
|
*/
|
|
565
614
|
async play(name, data = {}, { autoHeal = true } = {}) {
|
|
566
|
-
const path = `/api/browsers/${this.id}/playbooks/${segment(name, "name")}/play`;
|
|
615
|
+
const path = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
|
|
567
616
|
return agentAnswer(
|
|
568
617
|
await this.http.request("POST", path, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
|
|
569
618
|
);
|
|
@@ -576,7 +625,10 @@ var Browser = class {
|
|
|
576
625
|
*/
|
|
577
626
|
async submit(task, options = {}) {
|
|
578
627
|
const { onSuccess, onFailure, onHumanAttention, onHealed, pollMs, ...body } = options;
|
|
579
|
-
const started = await this.http.request("POST", `/api/browsers/${this.id}/runs`, {
|
|
628
|
+
const started = await this.http.request("POST", `/api/browsers/${segment(this.id)}/runs`, {
|
|
629
|
+
...task,
|
|
630
|
+
...body
|
|
631
|
+
});
|
|
580
632
|
return new Run(this.http, started.id, { onSuccess, onFailure, onHumanAttention, onHealed }, pollMs);
|
|
581
633
|
}
|
|
582
634
|
/**
|
|
@@ -592,9 +644,9 @@ var Browser = class {
|
|
|
592
644
|
* 60 seconds. Mint one per viewer, the first connection spends it.
|
|
593
645
|
*/
|
|
594
646
|
async liveStreamUrl() {
|
|
595
|
-
const path = `/api/control/sessions/${
|
|
647
|
+
const path = `/api/control/sessions/${segment(this.id)}/ticket`;
|
|
596
648
|
const { ticket } = await this.http.request("POST", path, {});
|
|
597
|
-
return `${this.http.baseUrl}/api/live/${this.id}?ticket=${encodeURIComponent(ticket)}`;
|
|
649
|
+
return `${this.http.baseUrl}/api/live/${segment(this.id)}?ticket=${encodeURIComponent(ticket)}`;
|
|
598
650
|
}
|
|
599
651
|
/**
|
|
600
652
|
* A shareable link to this browser's live view, for handing to a person or
|
|
@@ -608,7 +660,7 @@ var Browser = class {
|
|
|
608
660
|
* expires or you revoke it, so treat it like a password.
|
|
609
661
|
*/
|
|
610
662
|
async shareUrl({ control = false, expiresInSeconds = 3600 } = {}) {
|
|
611
|
-
const path = `/api/control/sessions/${
|
|
663
|
+
const path = `/api/control/sessions/${segment(this.id)}/share`;
|
|
612
664
|
const c = await this.http.request("POST", path, { control, expiresIn: expiresInSeconds });
|
|
613
665
|
return { url: shareLink(this.http.baseUrl, this.id, c.token), id: c.id, expiresAt: c.expiresAt };
|
|
614
666
|
}
|
|
@@ -617,23 +669,23 @@ var Browser = class {
|
|
|
617
669
|
await this.http.request("DELETE", `/api/control/credentials/${segment(id)}`);
|
|
618
670
|
}
|
|
619
671
|
/** Counters, health and the last 50 things this browser did. */
|
|
620
|
-
status() {
|
|
621
|
-
return this.http.request("GET", `/api/browsers/${this.id}`);
|
|
672
|
+
async status() {
|
|
673
|
+
return this.http.request("GET", `/api/browsers/${segment(this.id)}`);
|
|
622
674
|
}
|
|
623
675
|
/**
|
|
624
676
|
* Stop it, whatever it is: a cloud sandbox is destroyed so billing ends, a
|
|
625
677
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
626
678
|
*/
|
|
627
|
-
stop() {
|
|
679
|
+
async stop() {
|
|
628
680
|
if (this.reused) return this.endLane();
|
|
629
|
-
return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
|
|
681
|
+
return this.http.request("POST", `/api/browsers/${segment(this.id)}/stop`, {}, STOP_TIMEOUT_MS);
|
|
630
682
|
}
|
|
631
683
|
/**
|
|
632
684
|
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
633
685
|
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
634
686
|
*/
|
|
635
687
|
async endLane() {
|
|
636
|
-
await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
688
|
+
await this.http.request("POST", `/api/browsers/${segment(this.id)}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
637
689
|
return { id: this.id, ok: true, reused: true };
|
|
638
690
|
}
|
|
639
691
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
@@ -670,7 +722,7 @@ function consoleLink(baseUrl, id) {
|
|
|
670
722
|
return `${baseUrl}/dashboard/?browser=${encodeURIComponent(id)}`;
|
|
671
723
|
}
|
|
672
724
|
function shareLink(baseUrl, id, token) {
|
|
673
|
-
return `${baseUrl}/live/${
|
|
725
|
+
return `${baseUrl}/live/${segment(id)}#t=${encodeURIComponent(token)}`;
|
|
674
726
|
}
|
|
675
727
|
|
|
676
728
|
// src/api/browsers.ts
|
package/dist/index.js
CHANGED
|
@@ -82,16 +82,50 @@ function savedConfig() {
|
|
|
82
82
|
return {};
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
var PRIVATE_DIR = 448;
|
|
85
86
|
var PRIVATE_FILE = 384;
|
|
86
87
|
var JSON_INDENT = 2;
|
|
88
|
+
function ensurePrivateDir(fs, dir) {
|
|
89
|
+
fs.mkdirSync(dir, { recursive: true, mode: PRIVATE_DIR });
|
|
90
|
+
try {
|
|
91
|
+
fs.chmodSync(dir, PRIVATE_DIR);
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function openTemp(fs, tmp) {
|
|
96
|
+
const { O_WRONLY, O_CREAT, O_EXCL, O_NOFOLLOW = 0 } = fs.constants;
|
|
97
|
+
return fs.openSync(tmp, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW, PRIVATE_FILE);
|
|
98
|
+
}
|
|
99
|
+
function writeFd(fs, fd, text) {
|
|
100
|
+
try {
|
|
101
|
+
fs.writeFileSync(fd, text);
|
|
102
|
+
} finally {
|
|
103
|
+
fs.closeSync(fd);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function removeTemp(fs, tmp) {
|
|
107
|
+
try {
|
|
108
|
+
fs.unlinkSync(tmp);
|
|
109
|
+
} catch {
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
var tempFile = (file2) => `${file2.slice(0, file2.lastIndexOf("/"))}/.config.json.${node()?.pid ?? 0}-${globalThis.crypto.randomUUID()}.tmp`;
|
|
113
|
+
function writePrivate(fs, file2, text) {
|
|
114
|
+
const tmp = tempFile(file2);
|
|
115
|
+
try {
|
|
116
|
+
writeFd(fs, openTemp(fs, tmp), text);
|
|
117
|
+
fs.renameSync(tmp, file2);
|
|
118
|
+
} catch (err) {
|
|
119
|
+
removeTemp(fs, tmp);
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
87
123
|
function saveKey(apiKey, baseUrl) {
|
|
88
124
|
const fs = builtin("node:fs");
|
|
89
125
|
const file2 = configFile();
|
|
90
126
|
if (!fs || !file2 || savedConfig().apiKey) return false;
|
|
91
|
-
fs
|
|
92
|
-
fs
|
|
93
|
-
mode: PRIVATE_FILE
|
|
94
|
-
});
|
|
127
|
+
ensurePrivateDir(fs, file2.slice(0, file2.lastIndexOf("/")));
|
|
128
|
+
writePrivate(fs, file2, JSON.stringify({ ...savedConfig(), apiKey, baseUrl }, null, JSON_INDENT));
|
|
95
129
|
return true;
|
|
96
130
|
}
|
|
97
131
|
|
|
@@ -355,12 +389,12 @@ var Run = class {
|
|
|
355
389
|
/** Settles with the result when the run succeeds, or rejects when it fails. */
|
|
356
390
|
done;
|
|
357
391
|
/** The run's current state. */
|
|
358
|
-
status() {
|
|
359
|
-
return this.http.request("GET", `/api/runs/${
|
|
392
|
+
async status() {
|
|
393
|
+
return this.http.request("GET", `/api/runs/${segment(this.id)}`);
|
|
360
394
|
}
|
|
361
395
|
/** Answer the open attention request: `'done'` after handling it by hand, or your reply to the agent. */
|
|
362
396
|
async respond(response = "done") {
|
|
363
|
-
await this.http.request("POST", `/api/runs/${
|
|
397
|
+
await this.http.request("POST", `/api/runs/${segment(this.id)}/respond`, { response });
|
|
364
398
|
}
|
|
365
399
|
/** Polls until the run ends, firing callbacks on the way. */
|
|
366
400
|
watch(cb, pollMs) {
|
|
@@ -398,7 +432,7 @@ var Browser = class {
|
|
|
398
432
|
http;
|
|
399
433
|
/** Runs one browser command; a command that ran and failed throws. */
|
|
400
434
|
async command(action, params = {}, timeoutMs) {
|
|
401
|
-
const path = `/api/browsers/${this.id}/command`;
|
|
435
|
+
const path = `/api/browsers/${segment(this.id)}/command`;
|
|
402
436
|
const result = await this.http.request("POST", path, { action, params }, timeoutMs);
|
|
403
437
|
if (result.ok === false) throw new OyaError(result.error || `${action} failed`, Status.UNPROCESSABLE, result);
|
|
404
438
|
return result.data;
|
|
@@ -481,15 +515,25 @@ var Browser = class {
|
|
|
481
515
|
* Detect and clear a CAPTCHA. Providers that solve natively are left to do
|
|
482
516
|
* it; everything else goes to the configured solver.
|
|
483
517
|
*/
|
|
484
|
-
solveCaptcha() {
|
|
485
|
-
return this.http.request(
|
|
518
|
+
async solveCaptcha() {
|
|
519
|
+
return this.http.request(
|
|
520
|
+
"POST",
|
|
521
|
+
`/api/browsers/${segment(this.id)}/captcha`,
|
|
522
|
+
{},
|
|
523
|
+
CHALLENGE_TIMEOUT_MS
|
|
524
|
+
);
|
|
486
525
|
}
|
|
487
526
|
/**
|
|
488
527
|
* Answer an MFA prompt with the persona's configured factor. When nothing can
|
|
489
528
|
* answer it, `liveViewUrl` is where a person finishes by hand.
|
|
490
529
|
*/
|
|
491
530
|
async completeMfa() {
|
|
492
|
-
const result = await this.http.request(
|
|
531
|
+
const result = await this.http.request(
|
|
532
|
+
"POST",
|
|
533
|
+
`/api/browsers/${segment(this.id)}/mfa`,
|
|
534
|
+
{},
|
|
535
|
+
CHALLENGE_TIMEOUT_MS
|
|
536
|
+
);
|
|
493
537
|
if (result.liveViewUrl) result.liveViewUrl = new URL(result.liveViewUrl, this.http.baseUrl).href;
|
|
494
538
|
return result;
|
|
495
539
|
}
|
|
@@ -501,7 +545,7 @@ var Browser = class {
|
|
|
501
545
|
*/
|
|
502
546
|
async ask(prompt, { data, secrets } = {}) {
|
|
503
547
|
const body = { messages: [{ role: "user", content: prompt }], data, secrets };
|
|
504
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
548
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
505
549
|
return agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS)).text;
|
|
506
550
|
}
|
|
507
551
|
/**
|
|
@@ -510,7 +554,7 @@ var Browser = class {
|
|
|
510
554
|
*/
|
|
511
555
|
async extract(prompt, schema, values = {}) {
|
|
512
556
|
const body = { messages: [{ role: "user", content: prompt }], ...values, schema };
|
|
513
|
-
const path = `/api/browsers/${this.id}/chat`;
|
|
557
|
+
const path = `/api/browsers/${segment(this.id)}/chat`;
|
|
514
558
|
const res = agentAnswer(await this.http.request("POST", path, body, AGENT_TIMEOUT_MS));
|
|
515
559
|
if (res.failed || res.data === void 0) throw new OyaError(res.text, Status.UNPROCESSABLE, res);
|
|
516
560
|
return res.data;
|
|
@@ -521,8 +565,13 @@ var Browser = class {
|
|
|
521
565
|
* `defaults`, so `play()` with nothing repeats the run and any one value can be
|
|
522
566
|
* swapped. `code` is the same flow as a Playwright module, to read or run yourself.
|
|
523
567
|
*/
|
|
524
|
-
toPlaybook(name) {
|
|
525
|
-
return this.http.request(
|
|
568
|
+
async toPlaybook(name) {
|
|
569
|
+
return this.http.request(
|
|
570
|
+
"POST",
|
|
571
|
+
`/api/browsers/${segment(this.id)}/playbooks`,
|
|
572
|
+
{ name },
|
|
573
|
+
PLAYBOOK_TIMEOUT_MS
|
|
574
|
+
);
|
|
526
575
|
}
|
|
527
576
|
/**
|
|
528
577
|
* Replay a playbook with no LLM in the loop. Variables left out reuse the
|
|
@@ -531,7 +580,7 @@ var Browser = class {
|
|
|
531
580
|
* replaces the broken steps in the playbook (`healed`); off, the step's error is thrown.
|
|
532
581
|
*/
|
|
533
582
|
async play(name, data = {}, { autoHeal = true } = {}) {
|
|
534
|
-
const path = `/api/browsers/${this.id}/playbooks/${segment(name, "name")}/play`;
|
|
583
|
+
const path = `/api/browsers/${segment(this.id)}/playbooks/${segment(name, "name")}/play`;
|
|
535
584
|
return agentAnswer(
|
|
536
585
|
await this.http.request("POST", path, { variables: data, autoHeal }, AGENT_TIMEOUT_MS)
|
|
537
586
|
);
|
|
@@ -544,7 +593,10 @@ var Browser = class {
|
|
|
544
593
|
*/
|
|
545
594
|
async submit(task, options = {}) {
|
|
546
595
|
const { onSuccess, onFailure, onHumanAttention, onHealed, pollMs, ...body } = options;
|
|
547
|
-
const started = await this.http.request("POST", `/api/browsers/${this.id}/runs`, {
|
|
596
|
+
const started = await this.http.request("POST", `/api/browsers/${segment(this.id)}/runs`, {
|
|
597
|
+
...task,
|
|
598
|
+
...body
|
|
599
|
+
});
|
|
548
600
|
return new Run(this.http, started.id, { onSuccess, onFailure, onHumanAttention, onHealed }, pollMs);
|
|
549
601
|
}
|
|
550
602
|
/**
|
|
@@ -560,9 +612,9 @@ var Browser = class {
|
|
|
560
612
|
* 60 seconds. Mint one per viewer, the first connection spends it.
|
|
561
613
|
*/
|
|
562
614
|
async liveStreamUrl() {
|
|
563
|
-
const path = `/api/control/sessions/${
|
|
615
|
+
const path = `/api/control/sessions/${segment(this.id)}/ticket`;
|
|
564
616
|
const { ticket } = await this.http.request("POST", path, {});
|
|
565
|
-
return `${this.http.baseUrl}/api/live/${this.id}?ticket=${encodeURIComponent(ticket)}`;
|
|
617
|
+
return `${this.http.baseUrl}/api/live/${segment(this.id)}?ticket=${encodeURIComponent(ticket)}`;
|
|
566
618
|
}
|
|
567
619
|
/**
|
|
568
620
|
* A shareable link to this browser's live view, for handing to a person or
|
|
@@ -576,7 +628,7 @@ var Browser = class {
|
|
|
576
628
|
* expires or you revoke it, so treat it like a password.
|
|
577
629
|
*/
|
|
578
630
|
async shareUrl({ control = false, expiresInSeconds = 3600 } = {}) {
|
|
579
|
-
const path = `/api/control/sessions/${
|
|
631
|
+
const path = `/api/control/sessions/${segment(this.id)}/share`;
|
|
580
632
|
const c = await this.http.request("POST", path, { control, expiresIn: expiresInSeconds });
|
|
581
633
|
return { url: shareLink(this.http.baseUrl, this.id, c.token), id: c.id, expiresAt: c.expiresAt };
|
|
582
634
|
}
|
|
@@ -585,23 +637,23 @@ var Browser = class {
|
|
|
585
637
|
await this.http.request("DELETE", `/api/control/credentials/${segment(id)}`);
|
|
586
638
|
}
|
|
587
639
|
/** Counters, health and the last 50 things this browser did. */
|
|
588
|
-
status() {
|
|
589
|
-
return this.http.request("GET", `/api/browsers/${this.id}`);
|
|
640
|
+
async status() {
|
|
641
|
+
return this.http.request("GET", `/api/browsers/${segment(this.id)}`);
|
|
590
642
|
}
|
|
591
643
|
/**
|
|
592
644
|
* Stop it, whatever it is: a cloud sandbox is destroyed so billing ends, a
|
|
593
645
|
* CDP session is handed back to its provider, a desktop browser disconnects.
|
|
594
646
|
*/
|
|
595
|
-
stop() {
|
|
647
|
+
async stop() {
|
|
596
648
|
if (this.reused) return this.endLane();
|
|
597
|
-
return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
|
|
649
|
+
return this.http.request("POST", `/api/browsers/${segment(this.id)}/stop`, {}, STOP_TIMEOUT_MS);
|
|
598
650
|
}
|
|
599
651
|
/**
|
|
600
652
|
* Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
|
|
601
653
|
* leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
|
|
602
654
|
*/
|
|
603
655
|
async endLane() {
|
|
604
|
-
await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
656
|
+
await this.http.request("POST", `/api/browsers/${segment(this.id)}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
|
|
605
657
|
return { id: this.id, ok: true, reused: true };
|
|
606
658
|
}
|
|
607
659
|
/** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
|
|
@@ -638,7 +690,7 @@ function consoleLink(baseUrl, id) {
|
|
|
638
690
|
return `${baseUrl}/dashboard/?browser=${encodeURIComponent(id)}`;
|
|
639
691
|
}
|
|
640
692
|
function shareLink(baseUrl, id, token) {
|
|
641
|
-
return `${baseUrl}/live/${
|
|
693
|
+
return `${baseUrl}/live/${segment(id)}#t=${encodeURIComponent(token)}`;
|
|
642
694
|
}
|
|
643
695
|
|
|
644
696
|
// src/api/browsers.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oya-ai/browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.265",
|
|
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",
|