@scalebrowser/sdk 1.1.0 → 1.3.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.
- package/CHANGELOG.md +80 -0
- package/README.md +97 -11
- package/dist/index.cjs +1623 -866
- package/dist/index.d.cts +3321 -792
- package/dist/index.d.ts +3321 -792
- package/dist/index.js +1623 -866
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -37,7 +37,14 @@ var ErrorCode = {
|
|
|
37
37
|
* the proxy): here the proxy is fine and the address is simply spoken for. Wait
|
|
38
38
|
* for a term to run out, let the daemon draw again, or turn exclusivity off for
|
|
39
39
|
* this profile. */
|
|
40
|
-
ExitAddressTaken: 4013
|
|
40
|
+
ExitAddressTaken: 4013,
|
|
41
|
+
/** The plan does not allow this: a 4th profile or workflow on Free, a schedule
|
|
42
|
+
* or webhook trigger on Free, or another feature the plan leaves out.
|
|
43
|
+
* Distinct from ConcurrencyLimit (4008 = too many browsers at once, free one or
|
|
44
|
+
* upgrade): here nothing is running too much, the plan itself stops it. The
|
|
45
|
+
* body's `plan_limit` names which limit, the allowed number, the plan and
|
|
46
|
+
* whether the 7-day trial is still open. */
|
|
47
|
+
PlanLimit: 4014
|
|
41
48
|
};
|
|
42
49
|
var CODE_LABELS = {
|
|
43
50
|
4001: "Not found",
|
|
@@ -50,7 +57,8 @@ var CODE_LABELS = {
|
|
|
50
57
|
4010: "Unauthorized",
|
|
51
58
|
4011: "No account connected to this machine",
|
|
52
59
|
4012: "This profile is open on another machine",
|
|
53
|
-
4013: "This exit address belongs to another profile"
|
|
60
|
+
4013: "This exit address belongs to another profile",
|
|
61
|
+
4014: "The plan does not allow this"
|
|
54
62
|
};
|
|
55
63
|
var ScalebrowserError = class extends Error {
|
|
56
64
|
constructor(message) {
|
|
@@ -61,12 +69,15 @@ var ScalebrowserError = class extends Error {
|
|
|
61
69
|
var ApiError = class extends ScalebrowserError {
|
|
62
70
|
status;
|
|
63
71
|
code;
|
|
72
|
+
/** The text code of the case, where the daemon names one. */
|
|
73
|
+
reason;
|
|
64
74
|
body;
|
|
65
75
|
constructor(status, body, fallbackMessage) {
|
|
66
76
|
const label = body?.code ? CODE_LABELS[body.code] : void 0;
|
|
67
77
|
super(body?.message || label || fallbackMessage || `Request failed (HTTP ${status})`);
|
|
68
78
|
this.status = status;
|
|
69
79
|
this.code = body?.code;
|
|
80
|
+
this.reason = body?.reason;
|
|
70
81
|
this.body = body;
|
|
71
82
|
}
|
|
72
83
|
/** True for auth failures that must trigger re-authentication. */
|
|
@@ -257,6 +268,30 @@ var ControlApi = class extends ClientCore {
|
|
|
257
268
|
query: { origin: params.origin, kind: params.kind, profile_id: params.profile_id }
|
|
258
269
|
});
|
|
259
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* What waits in a tab of a running profile. Operator locks and standing rules
|
|
273
|
+
* answer what they decide first; those come back under `already_answered`.
|
|
274
|
+
* Asking keeps the browser's prompts waiting for an answer for two minutes,
|
|
275
|
+
* instead of the browser refusing them on its own.
|
|
276
|
+
*/
|
|
277
|
+
listPendingInterruptions(profileId, opts = {}) {
|
|
278
|
+
return this.request("GET", `/v1/profiles/${enc(profileId)}/interruptions`, void 0, {
|
|
279
|
+
query: { target_id: opts.targetId },
|
|
280
|
+
signal: opts.signal
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Answer one prompt the way its own button would. A kind an operator lock
|
|
285
|
+
* decides is refused with 409: change the lock to answer it from here. A prompt
|
|
286
|
+
* that is gone comes back as `applied: false`, not as an error.
|
|
287
|
+
*/
|
|
288
|
+
respondInterruption(profileId, body) {
|
|
289
|
+
return this.request(
|
|
290
|
+
"POST",
|
|
291
|
+
`/v1/profiles/${enc(profileId)}/interruptions/respond`,
|
|
292
|
+
body
|
|
293
|
+
);
|
|
294
|
+
}
|
|
260
295
|
// ── Artifacts ──────────────────────────────────────────────────────────────
|
|
261
296
|
/**
|
|
262
297
|
* Hand the daemon a file so `interact action=upload` has something to attach.
|
|
@@ -496,6 +531,14 @@ var IdentityApi = class extends ClientCore {
|
|
|
496
531
|
unbindInbox(profileId, channel) {
|
|
497
532
|
return this.request("DELETE", `/v1/profiles/${enc(profileId)}/inbox/${enc(channel)}`);
|
|
498
533
|
}
|
|
534
|
+
/**
|
|
535
|
+
* Read the profile's bound mailbox: the messages, the code candidates in each,
|
|
536
|
+
* and every link with its full address. Needs the vault password, because a
|
|
537
|
+
* sign-in link IS the account. Waits up to `timeout_ms` for the first message.
|
|
538
|
+
*/
|
|
539
|
+
revealInbox(profileId, body) {
|
|
540
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/inbox/reveal`, body);
|
|
541
|
+
}
|
|
499
542
|
// ── Passkeys ───────────────────────────────────────────────────────────────
|
|
500
543
|
/** What this profile can sign in to without a password. Metadata only. */
|
|
501
544
|
listPasskeys(profileId, signal) {
|
|
@@ -588,1036 +631,1720 @@ var IdentityApi = class extends ClientCore {
|
|
|
588
631
|
revealCookies(profileId, body) {
|
|
589
632
|
return this.request("POST", `/v1/profiles/${enc(profileId)}/cookies/reveal`, body);
|
|
590
633
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// src/client-tasks.ts
|
|
594
|
-
var TasksApi = class extends ClientCore {
|
|
595
|
-
// -- Tasks ------------------------------------------------------------------
|
|
596
|
-
//
|
|
597
|
-
// Fleet-wide by default, and deliberately so: the question this surface exists
|
|
598
|
-
// for is "what is outstanding across my twenty accounts", and a per-profile
|
|
599
|
-
// route would make a client ask it twenty times and sort the answers itself.
|
|
600
|
-
//
|
|
601
|
-
// None of these starts a browser. A task is a row, so reading the whole fleet's
|
|
602
|
-
// list costs nothing from the plan's concurrent-browser allowance. Reserve only
|
|
603
|
-
// the profiles that turn out to have work.
|
|
634
|
+
// ── Recorded requests ──────────────────────────────────────────────────────
|
|
604
635
|
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
*
|
|
636
|
+
* The one door what a recorded request carried leaves through, and it needs the vault
|
|
637
|
+
* password: the full address with its query, every header value (`Cookie`,
|
|
638
|
+
* `Authorization`) and, on request, the body. The agent's `net_capture` answers by
|
|
639
|
+
* shape only. `seq` is the number it listed.
|
|
609
640
|
*/
|
|
610
|
-
|
|
611
|
-
return this.request("
|
|
612
|
-
query: { ...params },
|
|
613
|
-
signal
|
|
614
|
-
});
|
|
641
|
+
revealRequest(profileId, seq, body) {
|
|
642
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/network/${seq}/reveal`, body);
|
|
615
643
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
* whole call.
|
|
624
|
-
*/
|
|
625
|
-
createTasks(body) {
|
|
626
|
-
return this.request("POST", "/v1/tasks", body);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// src/client-presets.ts
|
|
647
|
+
var PresetsApi = class extends ClientCore {
|
|
648
|
+
// ── Groups & presets ───────────────────────────────────────────────────────
|
|
649
|
+
listGroups(signal) {
|
|
650
|
+
return this.request("GET", "/v1/groups", void 0, { signal });
|
|
627
651
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
*
|
|
631
|
-
* Only a task nobody has claimed can be cancelled here. One an agent is working
|
|
632
|
-
* on right now is stopped by telling that agent, which is a channel that already
|
|
633
|
-
* reaches it; this surface answers `409` for it rather than pretending.
|
|
634
|
-
*/
|
|
635
|
-
cancelTask(id) {
|
|
636
|
-
return this.request("PATCH", `/v1/tasks/${enc(id)}`, { state: "cancelled" });
|
|
652
|
+
getGroup(id, signal) {
|
|
653
|
+
return this.request("GET", `/v1/groups/${enc(id)}`, void 0, { signal });
|
|
637
654
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return this.request("DELETE", `/v1/tasks/${enc(id)}`);
|
|
655
|
+
createGroup(body) {
|
|
656
|
+
return this.request("POST", "/v1/groups", body);
|
|
641
657
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
* A profile's durable memory, the `PROFILE.md` at the top of its directory.
|
|
645
|
-
*
|
|
646
|
-
* `content` is `null` while nobody has written one: a profile starts with no
|
|
647
|
-
* file, not with an empty one.
|
|
648
|
-
*/
|
|
649
|
-
getProfileMemory(profileId, signal) {
|
|
650
|
-
return this.request("GET", `/v1/profiles/${enc(profileId)}/memory`, void 0, {
|
|
651
|
-
signal
|
|
652
|
-
});
|
|
658
|
+
updateGroup(id, body) {
|
|
659
|
+
return this.request("PATCH", `/v1/groups/${enc(id)}`, body);
|
|
653
660
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
*
|
|
657
|
-
* Stored verbatim: no trimming, no appended newline, no line-ending
|
|
658
|
-
* translation. The last write wins and nothing warns, exactly as with a file
|
|
659
|
-
* two people can open.
|
|
660
|
-
*/
|
|
661
|
-
putProfileMemory(profileId, content) {
|
|
662
|
-
return this.request("PUT", `/v1/profiles/${enc(profileId)}/memory`, { content });
|
|
661
|
+
deleteGroup(id) {
|
|
662
|
+
return this.request("DELETE", `/v1/groups/${enc(id)}`);
|
|
663
663
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
return this.request("DELETE", `/v1/profiles/${enc(profileId)}/memory`);
|
|
664
|
+
listPresets(signal) {
|
|
665
|
+
return this.request("GET", "/v1/presets", void 0, { signal });
|
|
667
666
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
// src/client-runs.ts
|
|
671
|
-
var RunsApi = class extends ClientCore {
|
|
672
|
-
// ── Agent runs ─────────────────────────────────────────────────────────────
|
|
673
|
-
/** Runs, newest first. Read-only, all of it. */
|
|
674
|
-
listRuns(params = {}, signal) {
|
|
675
|
-
return this.request("GET", "/v1/runs", void 0, {
|
|
676
|
-
query: { profile_id: params.profile_id, limit: params.limit, offset: params.offset },
|
|
677
|
-
signal
|
|
678
|
-
});
|
|
667
|
+
getPreset(id, signal) {
|
|
668
|
+
return this.request("GET", `/v1/presets/${enc(id)}`, void 0, { signal });
|
|
679
669
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return this.request("GET", `/v1/runs/${enc(runId)}`, void 0, { signal });
|
|
670
|
+
createPreset(body) {
|
|
671
|
+
return this.request("POST", "/v1/presets", body);
|
|
683
672
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
673
|
+
updatePreset(id, body) {
|
|
674
|
+
return this.request("PATCH", `/v1/presets/${enc(id)}`, body);
|
|
675
|
+
}
|
|
676
|
+
deletePreset(id) {
|
|
677
|
+
return this.request("DELETE", `/v1/presets/${enc(id)}`);
|
|
678
|
+
}
|
|
679
|
+
// ── Video presets ──────────────────────────────────────────────────────────
|
|
680
|
+
listVideoPresets(signal) {
|
|
681
|
+
return this.request("GET", "/v1/video-presets", void 0, { signal });
|
|
682
|
+
}
|
|
683
|
+
getVideoPreset(id, signal) {
|
|
684
|
+
return this.request("GET", `/v1/video-presets/${enc(id)}`, void 0, { signal });
|
|
685
|
+
}
|
|
686
|
+
/** The daemon validates `config` strictly and names the failing field path. */
|
|
687
|
+
createVideoPreset(body) {
|
|
688
|
+
return this.request("POST", "/v1/video-presets", body);
|
|
689
|
+
}
|
|
690
|
+
/** A built-in preset refuses edits. Duplicate it and edit the copy. */
|
|
691
|
+
updateVideoPreset(id, body) {
|
|
692
|
+
return this.request("PATCH", `/v1/video-presets/${enc(id)}`, body);
|
|
693
|
+
}
|
|
694
|
+
/** The only way to make a built-in preset yours: copy, then edit the copy. */
|
|
695
|
+
duplicateVideoPreset(id, body = {}) {
|
|
696
|
+
return this.request("POST", `/v1/video-presets/${enc(id)}/duplicate`, body);
|
|
697
|
+
}
|
|
698
|
+
deleteVideoPreset(id) {
|
|
699
|
+
return this.request("DELETE", `/v1/video-presets/${enc(id)}`);
|
|
700
|
+
}
|
|
701
|
+
/** One still of the sample film under an UNSAVED config, drawn by the daemon's own renderer.
|
|
702
|
+
* `moment` wins over `frame`; both absent means the daemon's default moment. */
|
|
703
|
+
previewVideoPreset(body, signal) {
|
|
704
|
+
return this.request("POST", "/v1/video-presets/preview", body, { signal });
|
|
705
|
+
}
|
|
706
|
+
/** A clip of the sample film, blocking until it is encoded (the editor uses the SSE form of the
|
|
707
|
+
* same route; a script waits). Fetch the bytes with `downloadVideoPresetClip`. */
|
|
708
|
+
previewVideoPresetClip(body, signal) {
|
|
709
|
+
return this.request("POST", "/v1/video-presets/preview/clip", body, { signal });
|
|
710
|
+
}
|
|
711
|
+
/** The clip's MP4 bytes. */
|
|
712
|
+
downloadVideoPresetClip(id, signal) {
|
|
713
|
+
return this.requestBytes("GET", `/v1/video-presets/preview/clip/${enc(id)}`, { signal });
|
|
690
714
|
}
|
|
691
715
|
/**
|
|
692
|
-
* The
|
|
693
|
-
*
|
|
694
|
-
*
|
|
695
|
-
* out and never cached anywhere shared.
|
|
716
|
+
* The values a preset's `constraints` may take. Ask rather than hardcode: the
|
|
717
|
+
* region list comes from the daemon's embedded persona model, so a pinned copy
|
|
718
|
+
* drifts the moment that model changes and every create 400s.
|
|
696
719
|
*/
|
|
697
|
-
|
|
698
|
-
return this.
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
720
|
+
getPersonaConstraints(signal) {
|
|
721
|
+
return this.request(
|
|
722
|
+
"GET",
|
|
723
|
+
"/v1/persona/constraints",
|
|
724
|
+
void 0,
|
|
725
|
+
{ signal }
|
|
726
|
+
);
|
|
703
727
|
}
|
|
704
728
|
};
|
|
705
729
|
|
|
706
|
-
// src/client-
|
|
707
|
-
var
|
|
708
|
-
// ──
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return this.request("GET", "/v1/videos", void 0, {
|
|
730
|
+
// src/client-profiles.ts
|
|
731
|
+
var ProfilesApi = class extends ClientCore {
|
|
732
|
+
// ── Profiles ───────────────────────────────────────────────────────────────
|
|
733
|
+
listProfiles(params = {}, signal) {
|
|
734
|
+
return this.request("GET", "/v1/profiles", void 0, {
|
|
712
735
|
query: {
|
|
713
|
-
|
|
714
|
-
profile_id: params.profile_id,
|
|
715
|
-
run_id: params.run_id,
|
|
716
|
-
kind: params.kind,
|
|
717
|
-
preset: params.preset,
|
|
736
|
+
group: params.group,
|
|
718
737
|
state: params.state,
|
|
719
|
-
|
|
738
|
+
q: params.q,
|
|
739
|
+
limit: params.limit,
|
|
740
|
+
offset: params.offset,
|
|
741
|
+
sort: params.sort,
|
|
742
|
+
order: params.order
|
|
720
743
|
},
|
|
721
744
|
signal
|
|
722
745
|
});
|
|
723
746
|
}
|
|
724
|
-
/** One video row, progress included while it renders. */
|
|
725
|
-
getVideo(videoId, signal) {
|
|
726
|
-
return this.request("GET", `/v1/videos/${enc(videoId)}`, void 0, { signal });
|
|
727
|
-
}
|
|
728
|
-
/** Rename. The title also lands in the MP4's metadata on the NEXT render. */
|
|
729
|
-
renameVideo(videoId, title, signal) {
|
|
730
|
-
return this.request("PATCH", `/v1/videos/${enc(videoId)}`, { title }, { signal });
|
|
731
|
-
}
|
|
732
747
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
748
|
+
* Every id matching `params`, unpaged: what "act on all matches" needs.
|
|
749
|
+
*
|
|
750
|
+
* `listProfiles` is paged, so acting on "everything" from it only ever covers the
|
|
751
|
+
* page you fetched. Asking for ids costs one request and no persona payloads.
|
|
735
752
|
*/
|
|
736
|
-
|
|
737
|
-
return this.request("
|
|
738
|
-
query: {
|
|
753
|
+
listProfileIds(params = {}, signal) {
|
|
754
|
+
return this.request("GET", "/v1/profiles/ids", void 0, {
|
|
755
|
+
query: {
|
|
756
|
+
group: params.group,
|
|
757
|
+
state: params.state,
|
|
758
|
+
q: params.q,
|
|
759
|
+
sort: params.sort,
|
|
760
|
+
order: params.order
|
|
761
|
+
},
|
|
739
762
|
signal
|
|
740
763
|
});
|
|
741
764
|
}
|
|
742
|
-
/**
|
|
743
|
-
|
|
744
|
-
|
|
765
|
+
/**
|
|
766
|
+
* How many profiles match `params`, split by runtime state. One request, and
|
|
767
|
+
* its size does not grow with the fleet.
|
|
768
|
+
*
|
|
769
|
+
* `listProfiles` is paged and answers a bare array, so counting what came back
|
|
770
|
+
* counts the page. `listProfileIds` carries the same total but ships an
|
|
771
|
+
* identifier per profile to do it, and cannot split by state at all.
|
|
772
|
+
*
|
|
773
|
+
* `params.state` is ignored here on purpose: a caller labelling every state is
|
|
774
|
+
* sitting in one of them.
|
|
775
|
+
*/
|
|
776
|
+
countProfiles(params = {}, signal) {
|
|
777
|
+
return this.request("GET", "/v1/profiles/count", void 0, {
|
|
778
|
+
query: { group: params.group, q: params.q },
|
|
745
779
|
signal
|
|
746
780
|
});
|
|
747
781
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
return this.request("POST", `/v1/videos/${enc(videoId)}/renders`, body, { signal });
|
|
782
|
+
getProfile(id, signal) {
|
|
783
|
+
return this.request("GET", `/v1/profiles/${enc(id)}`, void 0, { signal });
|
|
751
784
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
return this.request(
|
|
755
|
-
"POST",
|
|
756
|
-
`/v1/videos/${enc(videoId)}/access`,
|
|
757
|
-
asset ? { asset } : {},
|
|
758
|
-
{ signal }
|
|
759
|
-
);
|
|
785
|
+
createProfile(body) {
|
|
786
|
+
return this.request("POST", "/v1/profiles", body);
|
|
760
787
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const grant = await this.videoAccess(videoId, asset, signal);
|
|
764
|
-
const grantParam = new URL(grant.url, "http://x").searchParams.get("grant") ?? "";
|
|
765
|
-
return this.requestBytes("GET", `/v1/videos/${enc(videoId)}/file`, {
|
|
766
|
-
query: { asset, grant: grantParam },
|
|
767
|
-
signal
|
|
768
|
-
});
|
|
788
|
+
updateProfile(id, body) {
|
|
789
|
+
return this.request("PATCH", `/v1/profiles/${enc(id)}`, body);
|
|
769
790
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
return this.request("GET", "/v1/videos/storage", void 0, { signal });
|
|
791
|
+
deleteProfile(id) {
|
|
792
|
+
return this.request("DELETE", `/v1/profiles/${enc(id)}`);
|
|
773
793
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return this.request("GET", "/v1/recordings", void 0, {
|
|
778
|
-
query: { profile_id: params.profile_id },
|
|
779
|
-
signal
|
|
780
|
-
});
|
|
794
|
+
/** Start a profile → CDP ws endpoint. Errors: 4002/4003/4005/4006/4008. */
|
|
795
|
+
startProfile(id, body = {}) {
|
|
796
|
+
return this.request("POST", `/v1/profiles/${enc(id)}/start`, body);
|
|
781
797
|
}
|
|
782
|
-
|
|
783
|
-
return this.request("
|
|
784
|
-
|
|
785
|
-
|
|
798
|
+
stopProfile(id) {
|
|
799
|
+
return this.request("POST", `/v1/profiles/${enc(id)}/stop`, {});
|
|
800
|
+
}
|
|
801
|
+
/** Drop the profile's lease, the operator's way out.
|
|
802
|
+
*
|
|
803
|
+
* An agent releases with its handle; this call needs none. The daemon stops
|
|
804
|
+
* the browser first when one is still up, then lets the lease go, so a dead
|
|
805
|
+
* session cannot park the profile until its TTL runs out. `released: false`
|
|
806
|
+
* is an honest no-op: there was nothing to let go. */
|
|
807
|
+
releaseProfile(id) {
|
|
808
|
+
return this.request("POST", `/v1/profiles/${enc(id)}/release`, {});
|
|
809
|
+
}
|
|
810
|
+
/** Ask for a profile that is open on another machine of this account.
|
|
811
|
+
*
|
|
812
|
+
* Closes nothing here and nothing there: the control plane revokes the holder's
|
|
813
|
+
* right, the holder closes its own browser at its next heartbeat. Start only
|
|
814
|
+
* after this answered `free`. Errors: 4012 when it is held elsewhere. */
|
|
815
|
+
takeoverProfile(id) {
|
|
816
|
+
return this.request("POST", `/v1/profiles/${enc(id)}/takeover`, {});
|
|
817
|
+
}
|
|
818
|
+
// ── Bulk (PRD §D2) ───────────────────────────────────────────────────────
|
|
819
|
+
bulkCreateProfiles(body) {
|
|
820
|
+
return this.request("POST", "/v1/bulk/profiles", body);
|
|
786
821
|
}
|
|
787
822
|
/**
|
|
788
|
-
*
|
|
789
|
-
*
|
|
823
|
+
* Start a batch. `headless` is the ONE visibility decision for the run; omitted
|
|
824
|
+
* means headless, the right default for an unattended client. The daemon stops at
|
|
825
|
+
* the machine's capacity limit and reports how far it got (`started` /
|
|
826
|
+
* `remaining` / `stopped_reason`) instead of failing every remaining id.
|
|
790
827
|
*/
|
|
791
|
-
|
|
792
|
-
return this.request("
|
|
793
|
-
signal
|
|
794
|
-
});
|
|
828
|
+
bulkStart(ids, headless) {
|
|
829
|
+
return this.request("POST", "/v1/bulk/start", { ids, headless });
|
|
795
830
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
return this.request("POST", `/v1/recordings/${enc(recordingId)}/renders`, body, {
|
|
799
|
-
signal
|
|
800
|
-
});
|
|
831
|
+
bulkStop(ids) {
|
|
832
|
+
return this.request("POST", "/v1/bulk/stop", { ids });
|
|
801
833
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
* off the binary: `h264_nvenc` is always listed and fails without a driver. */
|
|
805
|
-
getCodecs(signal) {
|
|
806
|
-
return this.request("GET", "/v1/codecs", void 0, { signal });
|
|
834
|
+
bulkDelete(ids) {
|
|
835
|
+
return this.request("POST", "/v1/bulk/delete", { ids });
|
|
807
836
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
return this.request("PUT", `/v1/codecs/${enc(codec)}`, { enabled }, { signal });
|
|
837
|
+
bulkAssignProxy(ids, proxyId) {
|
|
838
|
+
return this.request("POST", "/v1/bulk/assign-proxy", { ids, proxy_id: proxyId });
|
|
811
839
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
*
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
840
|
+
/**
|
|
841
|
+
* Give every id exactly this set of extensions.
|
|
842
|
+
*
|
|
843
|
+
* It REPLACES rather than adds, the same shape as assigning a proxy: picking a
|
|
844
|
+
* set for a batch states what those profiles carry. An empty list is a
|
|
845
|
+
* legitimate "none". An id the library does not hold refuses the whole call.
|
|
846
|
+
*/
|
|
847
|
+
bulkAssignExtensions(ids, extRefs) {
|
|
848
|
+
return this.request("POST", "/v1/bulk/assign-extensions", { ids, ext_refs: extRefs });
|
|
819
849
|
}
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
void 0,
|
|
829
|
-
{ signal }
|
|
830
|
-
);
|
|
850
|
+
// ── Live detector audit ─────────────────────────────────────────────────────
|
|
851
|
+
//
|
|
852
|
+
// Drives the profile's OWN running browser through ~15 third-party fingerprint
|
|
853
|
+
// sites and keeps what each one saw. The profile must be RUNNING; the run takes
|
|
854
|
+
// minutes, so `startAudit` returns immediately and you poll `getAudit`.
|
|
855
|
+
/** Queue a run → the status right after queueing. `409` if not running / already running. */
|
|
856
|
+
startAudit(profileId) {
|
|
857
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/audit`);
|
|
831
858
|
}
|
|
832
|
-
/**
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return this.request("DELETE", `/v1/videos/${enc(videoId)}/share`, void 0, {
|
|
859
|
+
/** State plus the last stored report. */
|
|
860
|
+
getAudit(profileId, signal) {
|
|
861
|
+
return this.request("GET", `/v1/profiles/${enc(profileId)}/audit`, void 0, {
|
|
836
862
|
signal
|
|
837
863
|
});
|
|
838
864
|
}
|
|
839
|
-
//
|
|
840
|
-
/**
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
865
|
+
// ── Exit-address exclusivity ────────────────────────────────────────────────
|
|
866
|
+
/** Which exit addresses this profile owns, and how far the rule reaches.
|
|
867
|
+
*
|
|
868
|
+
* `scope` is `'machine'` while this computer has no account key. That is the
|
|
869
|
+
* ordinary state of a second machine until sync is unlocked there once, and it is
|
|
870
|
+
* reported rather than hidden: believing the rule spans three machines when it
|
|
871
|
+
* spans one is worse than knowing. */
|
|
872
|
+
getExitStatus(profileId, signal) {
|
|
873
|
+
return this.request("GET", `/v1/profiles/${enc(profileId)}/exit`, void 0, {
|
|
844
874
|
signal
|
|
845
875
|
});
|
|
846
876
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return this.request("POST",
|
|
850
|
-
query: { kind, name, mime },
|
|
851
|
-
signal
|
|
852
|
-
});
|
|
877
|
+
// ── Session bundles ─────────────────────────────────────────────────────────
|
|
878
|
+
exportSession(profileId, body) {
|
|
879
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/session/export`, body);
|
|
853
880
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
return this.request("DELETE", `/v1/media/${enc(id)}`, void 0, { signal });
|
|
881
|
+
importSession(profileId, body) {
|
|
882
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/session/import`, body);
|
|
857
883
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return this.
|
|
884
|
+
// ── Trusted input ──────────────────────────────────────────────────────────
|
|
885
|
+
sendInput(profileId, body) {
|
|
886
|
+
return this.request("POST", `/v1/profiles/${enc(profileId)}/input`, body);
|
|
861
887
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
// src/client-proxies.ts
|
|
891
|
+
var ProxiesApi = class extends ClientCore {
|
|
892
|
+
// ── Proxies (credentials write-only) ────────────────────────────────────────
|
|
893
|
+
/** The list carries `used_by` per row; `getProxy` below does not. */
|
|
894
|
+
listProxies(signal) {
|
|
895
|
+
return this.request("GET", "/v1/proxies", void 0, { signal });
|
|
867
896
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
897
|
+
getProxy(id, signal) {
|
|
898
|
+
return this.request("GET", `/v1/proxies/${enc(id)}`, void 0, { signal });
|
|
899
|
+
}
|
|
900
|
+
createProxy(body) {
|
|
901
|
+
return this.request("POST", "/v1/proxies", body);
|
|
902
|
+
}
|
|
903
|
+
updateProxy(id, body) {
|
|
904
|
+
return this.request("PATCH", `/v1/proxies/${enc(id)}`, body);
|
|
905
|
+
}
|
|
906
|
+
deleteProxy(id) {
|
|
907
|
+
return this.request("DELETE", `/v1/proxies/${enc(id)}`);
|
|
908
|
+
}
|
|
909
|
+
/** Health + geo check (exit-ip/country/healthy + JA4↔JA4T verdict). */
|
|
910
|
+
checkProxy(id) {
|
|
911
|
+
return this.request("POST", `/v1/proxies/${enc(id)}/check`, {});
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Probe a proxy config WITHOUT persisting it: validate before you commit.
|
|
915
|
+
* Pass `id` (and omit the credentials) to probe an existing proxy's stored,
|
|
916
|
+
* write-only credentials in an edit form.
|
|
874
917
|
*/
|
|
875
|
-
|
|
876
|
-
return this.request(
|
|
877
|
-
"PUT",
|
|
878
|
-
`/v1/tts-providers/${enc(provider)}`,
|
|
879
|
-
{ api_key: body.apiKey, label: body.label, profile_id: body.profileId },
|
|
880
|
-
{ signal }
|
|
881
|
-
);
|
|
918
|
+
checkProxyConfig(body) {
|
|
919
|
+
return this.request("POST", "/v1/proxies/check", body);
|
|
882
920
|
}
|
|
883
|
-
|
|
921
|
+
};
|
|
922
|
+
|
|
923
|
+
// src/client-tasks.ts
|
|
924
|
+
var TasksApi = class extends ClientCore {
|
|
925
|
+
// -- Tasks ------------------------------------------------------------------
|
|
926
|
+
//
|
|
927
|
+
// Fleet-wide by default, and deliberately so: the question this surface exists
|
|
928
|
+
// for is "what is outstanding across my twenty accounts", and a per-profile
|
|
929
|
+
// route would make a client ask it twenty times and sort the answers itself.
|
|
930
|
+
//
|
|
931
|
+
// None of these starts a browser. A task is a row, so reading the whole fleet's
|
|
932
|
+
// list costs nothing from the plan's concurrent-browser allowance. Reserve only
|
|
933
|
+
// the profiles that turn out to have work.
|
|
934
|
+
/**
|
|
935
|
+
* What is still to be done. No filter means every task of every profile.
|
|
884
936
|
*
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
* broken.
|
|
937
|
+
* Pass `state: 'open'` for what is outstanding; without it, tasks finished
|
|
938
|
+
* within the last day are included too.
|
|
888
939
|
*/
|
|
889
|
-
|
|
890
|
-
return this.request(
|
|
891
|
-
|
|
892
|
-
`/v1/tts-providers/${enc(provider)}/verify`,
|
|
893
|
-
void 0,
|
|
894
|
-
{ signal }
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
/** Forget a provider's key. */
|
|
898
|
-
deleteTtsProvider(provider, signal) {
|
|
899
|
-
return this.request("DELETE", `/v1/tts-providers/${enc(provider)}`, void 0, {
|
|
940
|
+
listTasks(params, signal) {
|
|
941
|
+
return this.request("GET", "/v1/tasks", void 0, {
|
|
942
|
+
query: { ...params },
|
|
900
943
|
signal
|
|
901
944
|
});
|
|
902
945
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
const setStatus = (s) => handlers.onStatus?.(s);
|
|
915
|
-
const resync = (dropped) => handlers.onEvent({ type: "resync", dropped, at: Math.floor(Date.now() / 1e3) });
|
|
916
|
-
const deliver = (event) => {
|
|
917
|
-
if (typeof event.seq === "number") {
|
|
918
|
-
if (lastSeq !== null && event.seq > lastSeq + 1) resync(event.seq - lastSeq - 1);
|
|
919
|
-
lastSeq = event.seq;
|
|
920
|
-
}
|
|
921
|
-
handlers.onEvent(event);
|
|
922
|
-
};
|
|
923
|
-
async function connect() {
|
|
924
|
-
while (!closed) {
|
|
925
|
-
setStatus("connecting");
|
|
926
|
-
try {
|
|
927
|
-
const headers = { Accept: "text/event-stream" };
|
|
928
|
-
if (params.token) headers["Authorization"] = `Bearer ${params.token}`;
|
|
929
|
-
const res = await fetchImpl(`${params.baseUrl}/v1/events`, {
|
|
930
|
-
headers,
|
|
931
|
-
signal: controller.signal
|
|
932
|
-
});
|
|
933
|
-
if (res.status === 401) {
|
|
934
|
-
params.onUnauthorized?.();
|
|
935
|
-
break;
|
|
936
|
-
}
|
|
937
|
-
if (!res.ok || !res.body) {
|
|
938
|
-
throw new NetworkError(`event stream failed (HTTP ${res.status})`);
|
|
939
|
-
}
|
|
940
|
-
attempt = 0;
|
|
941
|
-
setStatus("open");
|
|
942
|
-
lastSeq = null;
|
|
943
|
-
if (everConnected) resync(0);
|
|
944
|
-
everConnected = true;
|
|
945
|
-
await pump(res.body, deliver, controller.signal);
|
|
946
|
-
} catch {
|
|
947
|
-
if (closed || controller.signal.aborted) break;
|
|
948
|
-
}
|
|
949
|
-
if (closed) break;
|
|
950
|
-
setStatus("connecting");
|
|
951
|
-
attempt += 1;
|
|
952
|
-
const delay2 = Math.min(MAX_BACKOFF_MS, 500 * 2 ** Math.min(attempt, 5));
|
|
953
|
-
await sleep(delay2, controller.signal);
|
|
954
|
-
}
|
|
955
|
-
setStatus("closed");
|
|
946
|
+
/**
|
|
947
|
+
* Put the same task on one or many profiles, one row each.
|
|
948
|
+
*
|
|
949
|
+
* A task is a LINE, not a document: name the work and leave the material where
|
|
950
|
+
* it lives. `due_at` is a deadline, not a trigger; nothing runs by itself.
|
|
951
|
+
*
|
|
952
|
+
* Profiles that no longer exist come back in `missing` instead of failing the
|
|
953
|
+
* whole call.
|
|
954
|
+
*/
|
|
955
|
+
createTasks(body) {
|
|
956
|
+
return this.request("POST", "/v1/tasks", body);
|
|
956
957
|
}
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
void reader.cancel().catch(() => {
|
|
958
|
+
/**
|
|
959
|
+
* Call a task off.
|
|
960
|
+
*
|
|
961
|
+
* Only a task nobody has claimed can be cancelled here. One an agent is working
|
|
962
|
+
* on right now is stopped by telling that agent, which is a channel that already
|
|
963
|
+
* reaches it; this surface answers `409` for it rather than pretending.
|
|
964
|
+
*/
|
|
965
|
+
cancelTask(id) {
|
|
966
|
+
return this.request("PATCH", `/v1/tasks/${enc(id)}`, { state: "cancelled" });
|
|
967
|
+
}
|
|
968
|
+
/** Remove a task outright. */
|
|
969
|
+
deleteTask(id) {
|
|
970
|
+
return this.request("DELETE", `/v1/tasks/${enc(id)}`);
|
|
971
|
+
}
|
|
972
|
+
// -- Profile memory ---------------------------------------------------------
|
|
973
|
+
/**
|
|
974
|
+
* A profile's durable memory, the `PROFILE.md` at the top of its directory.
|
|
975
|
+
*
|
|
976
|
+
* `content` is `null` while nobody has written one: a profile starts with no
|
|
977
|
+
* file, not with an empty one.
|
|
978
|
+
*/
|
|
979
|
+
getProfileMemory(profileId, signal) {
|
|
980
|
+
return this.request("GET", `/v1/profiles/${enc(profileId)}/memory`, void 0, {
|
|
981
|
+
signal
|
|
982
982
|
});
|
|
983
983
|
}
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
const dataLines = [];
|
|
994
|
-
for (const line of frame.split(/\r?\n/)) {
|
|
995
|
-
if (line.startsWith("data:")) dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
984
|
+
/**
|
|
985
|
+
* Replace a profile's memory.
|
|
986
|
+
*
|
|
987
|
+
* Stored verbatim: no trimming, no appended newline, no line-ending
|
|
988
|
+
* translation. The last write wins and nothing warns, exactly as with a file
|
|
989
|
+
* two people can open.
|
|
990
|
+
*/
|
|
991
|
+
putProfileMemory(profileId, content) {
|
|
992
|
+
return this.request("PUT", `/v1/profiles/${enc(profileId)}/memory`, { content });
|
|
996
993
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
try {
|
|
1001
|
-
return JSON.parse(payload);
|
|
1002
|
-
} catch {
|
|
1003
|
-
return null;
|
|
994
|
+
/** Remove a profile's memory. Removing one that is not there is not an error. */
|
|
995
|
+
deleteProfileMemory(profileId) {
|
|
996
|
+
return this.request("DELETE", `/v1/profiles/${enc(profileId)}/memory`);
|
|
1004
997
|
}
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
return {
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
// src/client-runs.ts
|
|
1001
|
+
var RunsApi = class extends ClientCore {
|
|
1002
|
+
// ── Agent runs ─────────────────────────────────────────────────────────────
|
|
1003
|
+
/** Runs, newest first. Read-only, all of it. */
|
|
1004
|
+
listRuns(params = {}, signal) {
|
|
1005
|
+
return this.request("GET", "/v1/runs", void 0, {
|
|
1006
|
+
query: { profile_id: params.profile_id, limit: params.limit, offset: params.offset },
|
|
1007
|
+
signal
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
/** One run. */
|
|
1011
|
+
getRun(runId, signal) {
|
|
1012
|
+
return this.request("GET", `/v1/runs/${enc(runId)}`, void 0, { signal });
|
|
1013
|
+
}
|
|
1014
|
+
/** A run's steps, oldest first: the order they happened in. */
|
|
1015
|
+
listRunSteps(runId, params = {}, signal) {
|
|
1016
|
+
return this.request("GET", `/v1/runs/${enc(runId)}/steps`, void 0, {
|
|
1017
|
+
query: { limit: params.limit, offset: params.offset },
|
|
1018
|
+
signal
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* The still taken at one step, as JPEG bytes.
|
|
1023
|
+
*
|
|
1024
|
+
* The picture shows a customer's account, so it is decrypted only on the way
|
|
1025
|
+
* out and never cached anywhere shared.
|
|
1026
|
+
*/
|
|
1027
|
+
getRunShot(runId, seq, signal) {
|
|
1028
|
+
return this.requestBytes("GET", `/v1/runs/${enc(runId)}/shots/${seq}`, { signal });
|
|
1029
|
+
}
|
|
1030
|
+
/** What every running profile currently shows. */
|
|
1031
|
+
getActivity(signal) {
|
|
1032
|
+
return this.request("GET", "/v1/activity", void 0, { signal });
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
// src/client-videos.ts
|
|
1037
|
+
var VideosApi = class extends ClientCore {
|
|
1038
|
+
// ── Videos ────────────────────────────────────────────────────────────────
|
|
1039
|
+
/** One gallery page, newest first. Running renders are videos too. */
|
|
1040
|
+
listVideos(params = {}, signal) {
|
|
1041
|
+
return this.request("GET", "/v1/videos", void 0, {
|
|
1042
|
+
query: {
|
|
1043
|
+
q: params.q,
|
|
1044
|
+
profile_id: params.profile_id,
|
|
1045
|
+
run_id: params.run_id,
|
|
1046
|
+
kind: params.kind,
|
|
1047
|
+
preset: params.preset,
|
|
1048
|
+
state: params.state,
|
|
1049
|
+
page: params.page
|
|
1049
1050
|
},
|
|
1050
|
-
|
|
1051
|
+
signal
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
/** One video row, progress included while it renders. */
|
|
1055
|
+
getVideo(videoId, signal) {
|
|
1056
|
+
return this.request("GET", `/v1/videos/${enc(videoId)}`, void 0, { signal });
|
|
1057
|
+
}
|
|
1058
|
+
/** Rename. The title also lands in the MP4's metadata on the NEXT render. */
|
|
1059
|
+
renameVideo(videoId, title, signal) {
|
|
1060
|
+
return this.request("PATCH", `/v1/videos/${enc(videoId)}`, { title }, { signal });
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Delete a video (`raw: true` also purges its recording's raw material).
|
|
1064
|
+
* A live share link is revoked first; 409 `job_running` while it renders.
|
|
1065
|
+
*/
|
|
1066
|
+
deleteVideo(videoId, opts = {}, signal) {
|
|
1067
|
+
return this.request("DELETE", `/v1/videos/${enc(videoId)}`, void 0, {
|
|
1068
|
+
query: { raw: opts.raw },
|
|
1069
|
+
signal
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
/** Cancel a queued or rendering video. `done` stays done (409). */
|
|
1073
|
+
cancelVideo(videoId, signal) {
|
|
1074
|
+
return this.request("POST", `/v1/videos/${enc(videoId)}/cancel`, void 0, {
|
|
1075
|
+
signal
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
/** Render a failed or cancelled video again: same id, new job. */
|
|
1079
|
+
rerenderVideo(videoId, body = {}, signal) {
|
|
1080
|
+
return this.request("POST", `/v1/videos/${enc(videoId)}/renders`, body, { signal });
|
|
1081
|
+
}
|
|
1082
|
+
/** A short-lived fetchable address for one asset (default the video). */
|
|
1083
|
+
videoAccess(videoId, asset, signal) {
|
|
1084
|
+
return this.request(
|
|
1085
|
+
"POST",
|
|
1086
|
+
`/v1/videos/${enc(videoId)}/access`,
|
|
1087
|
+
asset ? { asset } : {},
|
|
1088
|
+
{ signal }
|
|
1051
1089
|
);
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
var CdpConnection = class {
|
|
1055
|
-
#ws;
|
|
1056
|
-
#nextId = 0;
|
|
1057
|
-
#pending = /* @__PURE__ */ new Map();
|
|
1058
|
-
#subscribers = /* @__PURE__ */ new Set();
|
|
1059
|
-
#closeListeners = /* @__PURE__ */ new Set();
|
|
1060
|
-
#closeReason = null;
|
|
1061
|
-
constructor(ws) {
|
|
1062
|
-
this.#ws = ws;
|
|
1063
|
-
ws.on("message", (data) => this.#onMessage(data));
|
|
1064
|
-
ws.on("close", () => this.#onClose(new CdpError(-1, "CDP connection closed")));
|
|
1065
|
-
ws.on("error", (err) => this.#onClose(new NetworkError("CDP connection error", err)));
|
|
1066
1090
|
}
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
const
|
|
1070
|
-
const
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
this.#pending.set(id, { resolve, reject });
|
|
1075
|
-
this.#ws.send(JSON.stringify(frame), (err) => {
|
|
1076
|
-
if (err) {
|
|
1077
|
-
this.#pending.delete(id);
|
|
1078
|
-
reject(new NetworkError("failed to send CDP command", err));
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1091
|
+
/** One asset's bytes, through a freshly minted grant. */
|
|
1092
|
+
async downloadVideoFile(videoId, asset = "video", signal) {
|
|
1093
|
+
const grant = await this.videoAccess(videoId, asset, signal);
|
|
1094
|
+
const grantParam = new URL(grant.url, "http://x").searchParams.get("grant") ?? "";
|
|
1095
|
+
return this.requestBytes("GET", `/v1/videos/${enc(videoId)}/file`, {
|
|
1096
|
+
query: { asset, grant: grantParam },
|
|
1097
|
+
signal
|
|
1081
1098
|
});
|
|
1082
1099
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
return (
|
|
1100
|
+
/** What recordings and videos cost on disk, plus the caps. */
|
|
1101
|
+
videosStorage(signal) {
|
|
1102
|
+
return this.request("GET", "/v1/videos/storage", void 0, { signal });
|
|
1086
1103
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1095
|
-
this.#closeListeners.add(cb);
|
|
1096
|
-
return () => this.#closeListeners.delete(cb);
|
|
1104
|
+
// ── Recordings ────────────────────────────────────────────────────────────
|
|
1105
|
+
/** Recordings, newest first. The row outlives its raw bytes. */
|
|
1106
|
+
listRecordings(params = {}, signal) {
|
|
1107
|
+
return this.request("GET", "/v1/recordings", void 0, {
|
|
1108
|
+
query: { profile_id: params.profile_id },
|
|
1109
|
+
signal
|
|
1110
|
+
});
|
|
1097
1111
|
}
|
|
1098
|
-
|
|
1099
|
-
this
|
|
1112
|
+
getRecording(recordingId, signal) {
|
|
1113
|
+
return this.request("GET", `/v1/recordings/${enc(recordingId)}`, void 0, {
|
|
1114
|
+
signal
|
|
1115
|
+
});
|
|
1100
1116
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1117
|
+
/**
|
|
1118
|
+
* Purge a recording's RAW material; the row stays forever
|
|
1119
|
+
* (`raw_purged_at`). 409 `job_running` while a render of it is open.
|
|
1120
|
+
*/
|
|
1121
|
+
deleteRecordingRaw(recordingId, signal) {
|
|
1122
|
+
return this.request("DELETE", `/v1/recordings/${enc(recordingId)}`, void 0, {
|
|
1123
|
+
signal
|
|
1124
|
+
});
|
|
1103
1125
|
}
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1126
|
+
/** A NEW video from this recording (the same body the `video` tool takes). */
|
|
1127
|
+
renderRecording(recordingId, body = {}, signal) {
|
|
1128
|
+
return this.request("POST", `/v1/recordings/${enc(recordingId)}/renders`, body, {
|
|
1129
|
+
signal
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
// ── Codecs ────────────────────────────────────────────────────────────────
|
|
1133
|
+
/** What this machine can encode with. The hardware list is PROBED, not read
|
|
1134
|
+
* off the binary: `h264_nvenc` is always listed and fails without a driver. */
|
|
1135
|
+
getCodecs(signal) {
|
|
1136
|
+
return this.request("GET", "/v1/codecs", void 0, { signal });
|
|
1137
|
+
}
|
|
1138
|
+
/** Turn Cisco's OpenH264 on or off. The hardware encoders are not switchable. */
|
|
1139
|
+
setCodecEnabled(codec, enabled, signal) {
|
|
1140
|
+
return this.request("PUT", `/v1/codecs/${enc(codec)}`, { enabled }, { signal });
|
|
1141
|
+
}
|
|
1142
|
+
// -- Sharing ----------------------------------------------------------------
|
|
1143
|
+
/** Make a finished video public. Measures every file, asks the control plane
|
|
1144
|
+
* for permission, uploads, and has the result confirmed. */
|
|
1145
|
+
share(videoId, body = {}, signal) {
|
|
1146
|
+
return this.request("POST", `/v1/videos/${enc(videoId)}/share`, body, {
|
|
1147
|
+
signal
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
/** The share ORDER as this machine knows it. How many people watched and
|
|
1151
|
+
* whether the link still lives is read from the control plane, not from
|
|
1152
|
+
* here: a number carried along would be wrong the moment another machine
|
|
1153
|
+
* revoked. */
|
|
1154
|
+
shareStatus(videoId, signal) {
|
|
1155
|
+
return this.request(
|
|
1156
|
+
"GET",
|
|
1157
|
+
`/v1/videos/${enc(videoId)}/share`,
|
|
1158
|
+
void 0,
|
|
1159
|
+
{ signal }
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
/** Revoke the link. The files fall at once; the order stays until the control
|
|
1163
|
+
* plane confirms. */
|
|
1164
|
+
revokeShare(videoId, signal) {
|
|
1165
|
+
return this.request("DELETE", `/v1/videos/${enc(videoId)}/share`, void 0, {
|
|
1166
|
+
signal
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
// -- Media ------------------------------------------------------------------
|
|
1170
|
+
/** Files a preset points at: background image, music bed, subtitle font. */
|
|
1171
|
+
listMedia(kind, signal) {
|
|
1172
|
+
return this.request("GET", "/v1/media", void 0, {
|
|
1173
|
+
query: { kind },
|
|
1174
|
+
signal
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
/** Upload one file. The body IS the file; `name` and `mime` ride in the query. */
|
|
1178
|
+
uploadMedia(kind, name, mime, bytes, signal) {
|
|
1179
|
+
return this.request("POST", "/v1/media", bytes, {
|
|
1180
|
+
query: { kind, name, mime },
|
|
1181
|
+
signal
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
/** Remove a file. Refuses with 409 while a preset still points at it. */
|
|
1185
|
+
deleteMedia(id, signal) {
|
|
1186
|
+
return this.request("DELETE", `/v1/media/${enc(id)}`, void 0, { signal });
|
|
1187
|
+
}
|
|
1188
|
+
/** The file itself. */
|
|
1189
|
+
mediaFile(id, signal) {
|
|
1190
|
+
return this.requestBytes("GET", `/v1/media/${enc(id)}/file`, { signal });
|
|
1191
|
+
}
|
|
1192
|
+
// -- Voice providers --------------------------------------------------------
|
|
1193
|
+
/** Which speech providers have a key. The key itself never comes back: the
|
|
1194
|
+
* answer carries a hint, and that is on purpose. */
|
|
1195
|
+
listTtsProviders(signal) {
|
|
1196
|
+
return this.request("GET", "/v1/tts-providers", void 0, { signal });
|
|
1197
|
+
}
|
|
1198
|
+
/** Store a key, or rename one. Leaving `apiKey` out keeps the stored key.
|
|
1199
|
+
*
|
|
1200
|
+
* `apiKey` may also be a secret reference (`{{sb:...}}`), which is what an
|
|
1201
|
+
* agent gets back after fetching a key from the provider's own site: it is
|
|
1202
|
+
* not allowed to read the value. A reference needs `profileId`, because the
|
|
1203
|
+
* value belongs to one profile and there is nothing to open without it.
|
|
1204
|
+
*/
|
|
1205
|
+
putTtsProvider(provider, body, signal) {
|
|
1206
|
+
return this.request(
|
|
1207
|
+
"PUT",
|
|
1208
|
+
`/v1/tts-providers/${enc(provider)}`,
|
|
1209
|
+
{ api_key: body.apiKey, label: body.label, profile_id: body.profileId },
|
|
1210
|
+
{ signal }
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
/** Call the provider once for real, and record that the key works.
|
|
1214
|
+
*
|
|
1215
|
+
* Costs one short sentence of the account's own quota. Until this runs, a
|
|
1216
|
+
* provider row says `verified_at: null`, which means untested rather than
|
|
1217
|
+
* broken.
|
|
1218
|
+
*/
|
|
1219
|
+
verifyTtsProvider(provider, signal) {
|
|
1220
|
+
return this.request(
|
|
1221
|
+
"POST",
|
|
1222
|
+
`/v1/tts-providers/${enc(provider)}/verify`,
|
|
1223
|
+
void 0,
|
|
1224
|
+
{ signal }
|
|
1225
|
+
);
|
|
1123
1226
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
this
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
this.#subscribers.clear();
|
|
1130
|
-
for (const cb of [...this.#closeListeners]) cb();
|
|
1131
|
-
this.#closeListeners.clear();
|
|
1227
|
+
/** Forget a provider's key. */
|
|
1228
|
+
deleteTtsProvider(provider, signal) {
|
|
1229
|
+
return this.request("DELETE", `/v1/tts-providers/${enc(provider)}`, void 0, {
|
|
1230
|
+
signal
|
|
1231
|
+
});
|
|
1132
1232
|
}
|
|
1133
1233
|
};
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
this.#client = client;
|
|
1150
|
-
this.#profileId = profileId;
|
|
1151
|
-
}
|
|
1152
|
-
/** Send a raw CDP command and await its result (by id). */
|
|
1153
|
-
send(method, params) {
|
|
1154
|
-
return this.#conn.request(method, params, this.sessionId);
|
|
1234
|
+
|
|
1235
|
+
// src/client-tables.ts
|
|
1236
|
+
var TablesApi = class extends ClientCore {
|
|
1237
|
+
/**
|
|
1238
|
+
* The tables a workflow uses, before deleting it: those only it uses (what
|
|
1239
|
+
* `deleteWorkflow(id, { tables: 'trash' })` takes to the bin) and those another
|
|
1240
|
+
* workflow uses too.
|
|
1241
|
+
*/
|
|
1242
|
+
workflowDeletePreview(workflowId, signal) {
|
|
1243
|
+
return this.request(
|
|
1244
|
+
"GET",
|
|
1245
|
+
`/v1/workflows/${enc(workflowId)}/delete-preview`,
|
|
1246
|
+
void 0,
|
|
1247
|
+
{ signal }
|
|
1248
|
+
);
|
|
1155
1249
|
}
|
|
1156
|
-
/**
|
|
1157
|
-
|
|
1158
|
-
return this
|
|
1159
|
-
if (event.method === method && event.sessionId === this.sessionId) callback(event.params);
|
|
1160
|
-
});
|
|
1250
|
+
/** Every table outside the bin. */
|
|
1251
|
+
listTables(signal) {
|
|
1252
|
+
return this.request("GET", "/v1/tables", void 0, { signal });
|
|
1161
1253
|
}
|
|
1162
|
-
/**
|
|
1163
|
-
|
|
1164
|
-
return
|
|
1254
|
+
/** A local table with its first columns. */
|
|
1255
|
+
createTable(body) {
|
|
1256
|
+
return this.request("POST", "/v1/tables", body);
|
|
1165
1257
|
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
let targetId = opts.targetId;
|
|
1169
|
-
if (opts.create) {
|
|
1170
|
-
const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
|
|
1171
|
-
targetId = created.targetId;
|
|
1172
|
-
} else if (!targetId) {
|
|
1173
|
-
const { targetInfos } = await this.send("Target.getTargets");
|
|
1174
|
-
const page = targetInfos.find((t) => t.type === "page");
|
|
1175
|
-
if (page) {
|
|
1176
|
-
targetId = page.targetId;
|
|
1177
|
-
} else {
|
|
1178
|
-
const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
|
|
1179
|
-
targetId = created.targetId;
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
const { sessionId } = await this.send("Target.attachToTarget", { targetId, flatten: true });
|
|
1183
|
-
return new _CdpSession(this.#conn, sessionId, this.#client, this.#profileId);
|
|
1258
|
+
getTable(id, signal) {
|
|
1259
|
+
return this.request("GET", `/v1/tables/${enc(id)}`, void 0, { signal });
|
|
1184
1260
|
}
|
|
1185
|
-
/**
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
if (res.errorText) throw new CdpError(-1, `navigation failed: ${res.errorText}`);
|
|
1189
|
-
if (opts.wait !== false) await this.#waitForLoad(opts.timeout ?? 3e4);
|
|
1190
|
-
return res;
|
|
1261
|
+
/** Rename, describe or change the delete rule. */
|
|
1262
|
+
updateTable(id, body) {
|
|
1263
|
+
return this.request("PATCH", `/v1/tables/${enc(id)}`, body);
|
|
1191
1264
|
}
|
|
1192
|
-
/**
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
expression,
|
|
1196
|
-
awaitPromise: opts.awaitPromise ?? true,
|
|
1197
|
-
returnByValue: opts.returnByValue ?? true
|
|
1198
|
-
};
|
|
1199
|
-
if (opts.isolated) params["contextId"] = await this.#isolatedContext();
|
|
1200
|
-
const res = await this.send("Runtime.evaluate", params);
|
|
1201
|
-
if (res.exceptionDetails) {
|
|
1202
|
-
throw new CdpError(-1, res.exceptionDetails.text || res.exceptionDetails.exception?.description || "evaluate exception");
|
|
1203
|
-
}
|
|
1204
|
-
return res.result.value;
|
|
1265
|
+
/** To the bin for 30 days. */
|
|
1266
|
+
deleteTable(id) {
|
|
1267
|
+
return this.request("DELETE", `/v1/tables/${enc(id)}`);
|
|
1205
1268
|
}
|
|
1206
|
-
/**
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
}
|
|
1213
|
-
const { executionContextId } = await this.send("Page.createIsolatedWorld", {
|
|
1214
|
-
frameId: frame,
|
|
1215
|
-
worldName,
|
|
1216
|
-
grantUniveralAccess: false
|
|
1269
|
+
/** One page of rows in order, with the total. */
|
|
1270
|
+
listTableRows(id, params, signal) {
|
|
1271
|
+
const { where, ...rest } = params ?? {};
|
|
1272
|
+
return this.request("GET", `/v1/tables/${enc(id)}/rows`, void 0, {
|
|
1273
|
+
query: { ...rest, ...where ? { where: JSON.stringify(where) } : {} },
|
|
1274
|
+
signal
|
|
1217
1275
|
});
|
|
1218
|
-
return executionContextId;
|
|
1219
|
-
}
|
|
1220
|
-
// ── Humanized trusted input (routes through the daemon) ────────────────────
|
|
1221
|
-
humanizeMove(x, y, opts = {}) {
|
|
1222
|
-
return this.#input({ action: "move", x, y, width: opts.width });
|
|
1223
1276
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
button: opts.button ?? "left",
|
|
1230
|
-
click_count: opts.clickCount ?? 1,
|
|
1231
|
-
width: opts.width
|
|
1277
|
+
/** How many rows the table has outside the bin. */
|
|
1278
|
+
countTableRows(id, signal) {
|
|
1279
|
+
return this.request("GET", `/v1/tables/${enc(id)}/rows`, void 0, {
|
|
1280
|
+
query: { count_only: true },
|
|
1281
|
+
signal
|
|
1232
1282
|
});
|
|
1233
1283
|
}
|
|
1284
|
+
/** Ops in order, one result each. */
|
|
1285
|
+
editTable(id, body) {
|
|
1286
|
+
return this.request("POST", `/v1/tables/${enc(id)}/edit`, body);
|
|
1287
|
+
}
|
|
1234
1288
|
/**
|
|
1235
|
-
*
|
|
1236
|
-
*
|
|
1237
|
-
*
|
|
1289
|
+
* Bring a file into a table: CSV (encoding and delimiter recognised), XLSX,
|
|
1290
|
+
* XLS or ODS, at most 10 MB, its first row naming the columns. A column
|
|
1291
|
+
* matches by name; a name the table lacks becomes a new column. The rows stay
|
|
1292
|
+
* invisible until the import is complete.
|
|
1238
1293
|
*/
|
|
1239
|
-
|
|
1240
|
-
return this.
|
|
1294
|
+
importTable(id, file, params) {
|
|
1295
|
+
return this.request("POST", `/v1/tables/${enc(id)}/import`, file, {
|
|
1296
|
+
query: { ...params }
|
|
1297
|
+
});
|
|
1241
1298
|
}
|
|
1242
|
-
/**
|
|
1243
|
-
|
|
1244
|
-
return this.
|
|
1299
|
+
/** The whole table as a file to save: CSV (UTF-8 with a byte order mark) or XLSX. */
|
|
1300
|
+
exportTable(id, format = "csv", signal) {
|
|
1301
|
+
return this.requestBytes("GET", `/v1/tables/${enc(id)}/export`, { query: { format }, signal });
|
|
1245
1302
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1303
|
+
/** The tables in the bin. */
|
|
1304
|
+
listTableTrash(signal) {
|
|
1305
|
+
return this.request("GET", "/v1/tables/trash", void 0, { signal });
|
|
1248
1306
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1307
|
+
/** Take tables back out of the bin. */
|
|
1308
|
+
restoreTables(ids) {
|
|
1309
|
+
return this.request("POST", "/v1/tables/trash/restore", { ids });
|
|
1251
1310
|
}
|
|
1252
|
-
/**
|
|
1253
|
-
|
|
1254
|
-
this
|
|
1311
|
+
/** The Google accounts connected for linked sheets. Never a token. */
|
|
1312
|
+
async listGoogleConnections(signal) {
|
|
1313
|
+
const r = await this.request("GET", "/v1/connections/google", void 0, { signal });
|
|
1314
|
+
return r.connections;
|
|
1255
1315
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
return this.#client.sendInput(this.#profileId, { ...body, humanize: true });
|
|
1316
|
+
/**
|
|
1317
|
+
* Start connecting a Google account: open `auth_url` in the default browser;
|
|
1318
|
+
* the connection appears once the person agreed there.
|
|
1319
|
+
*/
|
|
1320
|
+
connectGoogle(body = {}) {
|
|
1321
|
+
return this.request("POST", "/v1/connections/google", body);
|
|
1263
1322
|
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1323
|
+
/** Disconnect and revoke at Google; a connection a table still uses stays as revoked. */
|
|
1324
|
+
async disconnectGoogle(id) {
|
|
1325
|
+
const r = await this.request("DELETE", `/v1/connections/google/${enc(id)}`);
|
|
1326
|
+
return r.connections;
|
|
1267
1327
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
await delay(50);
|
|
1275
|
-
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Link a table to a sheet: open `auth_url` in the default browser, where Google
|
|
1330
|
+
* shows its own file picker; the link appears once the person picked the sheet.
|
|
1331
|
+
*/
|
|
1332
|
+
linkSheet(connectionId, body) {
|
|
1333
|
+
return this.request("POST", `/v1/connections/google/${enc(connectionId)}/link`, body);
|
|
1276
1334
|
}
|
|
1277
1335
|
};
|
|
1278
|
-
async function openCdpSession(url, options = {}) {
|
|
1279
|
-
const headers = {};
|
|
1280
|
-
if (options.token) headers["Authorization"] = `Bearer ${options.token}`;
|
|
1281
|
-
const ws = new WebSocket__default.default(url, { headers, handshakeTimeout: options.openTimeout ?? 3e4 });
|
|
1282
|
-
await waitForOpen(ws);
|
|
1283
|
-
const conn = new CdpConnection(ws);
|
|
1284
|
-
const root = new CdpSession(conn, void 0, options.client, options.profileId);
|
|
1285
|
-
if (options.autoAttach === false) return root;
|
|
1286
|
-
return root.attachToPage({ create: options.createTarget ?? false, url: options.targetUrl });
|
|
1287
|
-
}
|
|
1288
|
-
function waitForOpen(ws) {
|
|
1289
|
-
return new Promise((resolve, reject) => {
|
|
1290
|
-
const onOpen = () => {
|
|
1291
|
-
cleanup();
|
|
1292
|
-
resolve();
|
|
1293
|
-
};
|
|
1294
|
-
const onError = (err) => {
|
|
1295
|
-
cleanup();
|
|
1296
|
-
reject(new NetworkError("CDP websocket failed to open", err));
|
|
1297
|
-
};
|
|
1298
|
-
const cleanup = () => {
|
|
1299
|
-
ws.off("open", onOpen);
|
|
1300
|
-
ws.off("error", onError);
|
|
1301
|
-
};
|
|
1302
|
-
ws.on("open", onOpen);
|
|
1303
|
-
ws.on("error", onError);
|
|
1304
|
-
});
|
|
1305
|
-
}
|
|
1306
|
-
function scopedEventStream(conn, sessionId) {
|
|
1307
|
-
const buffer = [];
|
|
1308
|
-
const waiters = [];
|
|
1309
|
-
let done = false;
|
|
1310
|
-
const unsubscribe = conn.subscribe((event) => {
|
|
1311
|
-
if (event.sessionId !== sessionId) return;
|
|
1312
|
-
const waiter = waiters.shift();
|
|
1313
|
-
if (waiter) waiter({ value: event, done: false });
|
|
1314
|
-
else buffer.push(event);
|
|
1315
|
-
});
|
|
1316
|
-
let offClose = () => {
|
|
1317
|
-
};
|
|
1318
|
-
const finish = () => {
|
|
1319
|
-
if (!done) {
|
|
1320
|
-
done = true;
|
|
1321
|
-
unsubscribe();
|
|
1322
|
-
offClose();
|
|
1323
|
-
for (const w of waiters.splice(0)) w({ value: void 0, done: true });
|
|
1324
|
-
}
|
|
1325
|
-
return { value: void 0, done: true };
|
|
1326
|
-
};
|
|
1327
|
-
offClose = conn.onClose(() => {
|
|
1328
|
-
finish();
|
|
1329
|
-
});
|
|
1330
|
-
return {
|
|
1331
|
-
next() {
|
|
1332
|
-
const next = buffer.shift();
|
|
1333
|
-
if (next !== void 0) return Promise.resolve({ value: next, done: false });
|
|
1334
|
-
if (done) return Promise.resolve({ value: void 0, done: true });
|
|
1335
|
-
return new Promise((resolve) => waiters.push(resolve));
|
|
1336
|
-
},
|
|
1337
|
-
return() {
|
|
1338
|
-
return Promise.resolve(finish());
|
|
1339
|
-
},
|
|
1340
|
-
[Symbol.asyncIterator]() {
|
|
1341
|
-
return this;
|
|
1342
|
-
}
|
|
1343
|
-
};
|
|
1344
|
-
}
|
|
1345
|
-
function delay(ms) {
|
|
1346
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1347
|
-
}
|
|
1348
1336
|
|
|
1349
|
-
// src/client.ts
|
|
1350
|
-
var
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
};
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
return this.request("
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1337
|
+
// src/client-workflows.ts
|
|
1338
|
+
var WorkflowsApi = class extends ClientCore {
|
|
1339
|
+
// -- Definitions --------------------------------------------------------------
|
|
1340
|
+
/** Every workflow, by name. */
|
|
1341
|
+
listWorkflows(signal) {
|
|
1342
|
+
return this.request("GET", "/v1/workflows", void 0, { signal });
|
|
1343
|
+
}
|
|
1344
|
+
/** An empty workflow. Its draft starts at revision 0. */
|
|
1345
|
+
createWorkflow(body) {
|
|
1346
|
+
return this.request("POST", "/v1/workflows", body);
|
|
1347
|
+
}
|
|
1348
|
+
/** A workflow in full: summary, draft document and the findings of the checks. */
|
|
1349
|
+
getWorkflow(id, params, signal) {
|
|
1350
|
+
return this.request("GET", `/v1/workflows/${enc(id)}`, void 0, {
|
|
1351
|
+
query: { ...params },
|
|
1352
|
+
signal
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
/** What a field of one node may point at: the steps that run before it and the workflow's scopes. */
|
|
1356
|
+
getWorkflowReferenceSources(id, node, signal) {
|
|
1357
|
+
return this.request("GET", `/v1/workflows/${enc(id)}/reference-sources`, void 0, {
|
|
1358
|
+
query: { node },
|
|
1359
|
+
signal
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
renameWorkflow(id, name) {
|
|
1363
|
+
return this.request("PATCH", `/v1/workflows/${enc(id)}`, { name });
|
|
1364
|
+
}
|
|
1365
|
+
/** Delete a workflow with its draft, versions and runs. */
|
|
1366
|
+
deleteWorkflow(id, params) {
|
|
1367
|
+
return this.request("DELETE", `/v1/workflows/${enc(id)}`, void 0, {
|
|
1368
|
+
query: { ...params }
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Apply a batch of edit ops to the draft, as a person. The batch applies whole
|
|
1373
|
+
* or not at all; graph findings come back as `diagnostics`, not as a refusal.
|
|
1374
|
+
*
|
|
1375
|
+
* While another machine of the account edits this workflow the daemon answers
|
|
1376
|
+
* 409 with `reason: workflow_edit_locked` and the holder's name.
|
|
1377
|
+
*/
|
|
1378
|
+
editWorkflow(id, body) {
|
|
1379
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/edit`, body);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Move a part of the draft into a workflow of its own, published at once. One
|
|
1383
|
+
* "Run Workflow" step stands where the part was, and later steps read its
|
|
1384
|
+
* result. The part needs one line in, one line out, no trigger, both ends of
|
|
1385
|
+
* every pair and no step that writes a variable; otherwise the daemon answers
|
|
1386
|
+
* 422 with `reason: extract_invalid` and the sentence why in `why`.
|
|
1387
|
+
* `base_rev` must be the draft's revision, else 409.
|
|
1388
|
+
*/
|
|
1389
|
+
extractWorkflow(id, body) {
|
|
1390
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/extract`, body);
|
|
1391
|
+
}
|
|
1392
|
+
// -- Versions -----------------------------------------------------------------
|
|
1393
|
+
/** The versions, newest first. */
|
|
1394
|
+
listWorkflowVersions(id, signal) {
|
|
1395
|
+
return this.request("GET", `/v1/workflows/${enc(id)}/versions`, void 0, {
|
|
1368
1396
|
signal
|
|
1369
1397
|
});
|
|
1370
1398
|
}
|
|
1399
|
+
/** One version whole, with its graph document; a version of another workflow is 404. */
|
|
1400
|
+
getWorkflowVersion(id, versionId, signal) {
|
|
1401
|
+
return this.request(
|
|
1402
|
+
"GET",
|
|
1403
|
+
`/v1/workflows/${enc(id)}/versions/${enc(versionId)}`,
|
|
1404
|
+
void 0,
|
|
1405
|
+
{ signal }
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1371
1408
|
/**
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
* `listProfiles` is paged, so acting on "everything" from it only ever covers the
|
|
1375
|
-
* page you fetched. Asking for ids costs one request and no persona payloads.
|
|
1409
|
+
* Save the draft as a version. The same content twice is one version. A draft
|
|
1410
|
+
* with a hard finding (a cycle, an open region) answers 422 with the findings.
|
|
1376
1411
|
*/
|
|
1377
|
-
|
|
1378
|
-
return this.request("
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1412
|
+
saveWorkflowVersion(id, body) {
|
|
1413
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/versions`, body ?? {});
|
|
1414
|
+
}
|
|
1415
|
+
/** Publish a version; `null` withdraws. Schedules, agents and every profile use what is published. */
|
|
1416
|
+
publishWorkflow(id, versionId) {
|
|
1417
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/publish`, {
|
|
1418
|
+
version_id: versionId
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Restore a version: the draft takes its content back as one batch, and that
|
|
1423
|
+
* content is saved as a new version. Publishing it is a step of its own.
|
|
1424
|
+
*/
|
|
1425
|
+
revertWorkflow(id, body) {
|
|
1426
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/revert`, body);
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Take one batch of the draft back, as a person: its restore ops become a new
|
|
1430
|
+
* batch, which can itself be undone. With the `batch_id` that
|
|
1431
|
+
* `adoptWorkflowVersion` answered it takes an applied repair back. A batch
|
|
1432
|
+
* undone already, or one a later batch changed over (`reason: undo_conflict`),
|
|
1433
|
+
* answers 409; a batch the draft never had, 404.
|
|
1434
|
+
*/
|
|
1435
|
+
undoWorkflowBatch(id, batchId) {
|
|
1436
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/batches/${enc(batchId)}/undo`);
|
|
1437
|
+
}
|
|
1438
|
+
/** What changed from one version to another; without `to`, against the draft. */
|
|
1439
|
+
diffWorkflow(id, params, signal) {
|
|
1440
|
+
return this.request("GET", `/v1/workflows/${enc(id)}/diff`, void 0, {
|
|
1441
|
+
query: { ...params },
|
|
1386
1442
|
signal
|
|
1387
1443
|
});
|
|
1388
1444
|
}
|
|
1445
|
+
// -- Variables ----------------------------------------------------------------
|
|
1446
|
+
/** Every variable with its values; a secret value only as `{ withheld }`. */
|
|
1447
|
+
listWorkflowVariables(id, signal) {
|
|
1448
|
+
return this.request("GET", `/v1/workflows/${enc(id)}/variables`, void 0, {
|
|
1449
|
+
signal
|
|
1450
|
+
});
|
|
1451
|
+
}
|
|
1452
|
+
/** Set a value; a `secret` variable's value is stored sealed and never shown again. */
|
|
1453
|
+
setWorkflowVariable(id, varId, body) {
|
|
1454
|
+
return this.request("PUT", `/v1/workflows/${enc(id)}/variables/${enc(varId)}`, body);
|
|
1455
|
+
}
|
|
1456
|
+
/** The stored value in plain, behind the vault password. */
|
|
1457
|
+
revealWorkflowVariable(id, varId, body) {
|
|
1458
|
+
return this.request(
|
|
1459
|
+
"POST",
|
|
1460
|
+
`/v1/workflows/${enc(id)}/variables/${enc(varId)}/reveal`,
|
|
1461
|
+
body
|
|
1462
|
+
);
|
|
1463
|
+
}
|
|
1464
|
+
// -- Catalog ------------------------------------------------------------------
|
|
1465
|
+
/** The newest version of every node type. */
|
|
1466
|
+
listNodeTypes(params, signal) {
|
|
1467
|
+
return this.request("GET", "/v1/node-types", void 0, {
|
|
1468
|
+
query: { ...params },
|
|
1469
|
+
signal
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
/** One node type: `click` for its newest version, `click@1` for a given one. */
|
|
1473
|
+
getNodeType(type, signal) {
|
|
1474
|
+
return this.request("GET", `/v1/node-types/${enc(type)}`, void 0, { signal });
|
|
1475
|
+
}
|
|
1389
1476
|
/**
|
|
1390
|
-
*
|
|
1391
|
-
*
|
|
1392
|
-
*
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1477
|
+
* The workflow's own settings, shaped like a node type's schema: one property
|
|
1478
|
+
* per setting a run reads, keyed by the dotted path `set_workflow_settings`
|
|
1479
|
+
* takes (`repair.rights`), `x-human-only` where only a person changes it.
|
|
1480
|
+
*/
|
|
1481
|
+
getWorkflowSettingsSchema(signal) {
|
|
1482
|
+
return this.request("GET", "/v1/workflow-settings-schema", void 0, { signal });
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
|
|
1486
|
+
// src/client-workflow-runs.ts
|
|
1487
|
+
var WorkflowRunsApi = class extends ClientCore {
|
|
1488
|
+
// -- Runs ---------------------------------------------------------------------
|
|
1489
|
+
/**
|
|
1490
|
+
* Start a run. With `wait` the request holds up to that many seconds (at most
|
|
1491
|
+
* 110) and answers with the result of a run that succeeded in that time.
|
|
1492
|
+
* Without a free profile the run waits in the queue, by default for an hour.
|
|
1396
1493
|
*
|
|
1397
|
-
*
|
|
1398
|
-
*
|
|
1494
|
+
* A start of the published version (the default) where nothing is published
|
|
1495
|
+
* answers 409 with `reason: no_published_version`; `{ version: 'draft' }` runs
|
|
1496
|
+
* the draft. A copy from a link nobody trusted yet answers 409 with
|
|
1497
|
+
* `reason: code_trust_required`. A `run_on` no single machine carries answers
|
|
1498
|
+
* 422 with `reason: run_on_unknown`; a draft test run naming another machine
|
|
1499
|
+
* answers 422 with `reason: run_on_local_only`.
|
|
1399
1500
|
*/
|
|
1400
|
-
|
|
1401
|
-
return this.request("
|
|
1402
|
-
query: {
|
|
1501
|
+
startWorkflowRun(id, body, params) {
|
|
1502
|
+
return this.request("POST", `/v1/workflows/${enc(id)}/runs`, body ?? {}, {
|
|
1503
|
+
query: { ...params }
|
|
1504
|
+
});
|
|
1505
|
+
}
|
|
1506
|
+
/** Runs, newest first. */
|
|
1507
|
+
listWorkflowRuns(params, signal) {
|
|
1508
|
+
return this.request("GET", "/v1/workflow-runs", void 0, {
|
|
1509
|
+
query: { ...params },
|
|
1403
1510
|
signal
|
|
1404
1511
|
});
|
|
1405
1512
|
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1513
|
+
/** One run with the state of every node. */
|
|
1514
|
+
getWorkflowRun(runId, params, signal) {
|
|
1515
|
+
return this.request("GET", `/v1/workflow-runs/${enc(runId)}`, void 0, {
|
|
1516
|
+
query: { ...params },
|
|
1517
|
+
signal
|
|
1518
|
+
});
|
|
1408
1519
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1520
|
+
/** The steps of a run with what went in and what came out. */
|
|
1521
|
+
listWorkflowRunSteps(runId, params, signal) {
|
|
1522
|
+
return this.request("GET", `/v1/workflow-runs/${enc(runId)}/steps`, void 0, {
|
|
1523
|
+
query: { ...params },
|
|
1524
|
+
signal
|
|
1525
|
+
});
|
|
1411
1526
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1527
|
+
/** This machine's folder boundary for file blocks. */
|
|
1528
|
+
getWorkflowFileAccess(signal) {
|
|
1529
|
+
return this.request("GET", "/v1/workflow-file-access", void 0, { signal });
|
|
1414
1530
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1531
|
+
/** Switch "only granted folders" on or off for this machine. */
|
|
1532
|
+
setWorkflowFileAccess(onlyGrantedFolders) {
|
|
1533
|
+
return this.request("PUT", "/v1/workflow-file-access", {
|
|
1534
|
+
only_granted_folders: onlyGrantedFolders
|
|
1535
|
+
});
|
|
1417
1536
|
}
|
|
1418
|
-
/**
|
|
1419
|
-
|
|
1420
|
-
return this.request("POST",
|
|
1537
|
+
/** Grant a folder (a file's path grants its folder) for reading or writing. */
|
|
1538
|
+
grantWorkflowFolder(path, mode, via) {
|
|
1539
|
+
return this.request("POST", "/v1/workflow-file-access/folders", { path, mode, via });
|
|
1421
1540
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1541
|
+
/** Take a folder off the list. */
|
|
1542
|
+
ungrantWorkflowFolder(path) {
|
|
1543
|
+
return this.request("DELETE", "/v1/workflow-file-access/folders", void 0, {
|
|
1544
|
+
query: { path }
|
|
1545
|
+
});
|
|
1424
1546
|
}
|
|
1425
|
-
/**
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
* the browser first when one is still up, then lets the lease go, so a dead
|
|
1429
|
-
* session cannot park the profile until its TTL runs out. `released: false`
|
|
1430
|
-
* is an honest no-op: there was nothing to let go. */
|
|
1431
|
-
releaseProfile(id) {
|
|
1432
|
-
return this.request("POST", `/v1/profiles/${enc(id)}/release`, {});
|
|
1547
|
+
/** The fast mode's domain list, empty by default. */
|
|
1548
|
+
listWorkflowFastDomains(signal) {
|
|
1549
|
+
return this.request("GET", "/v1/workflow-fast-domains", void 0, { signal });
|
|
1433
1550
|
}
|
|
1434
|
-
/**
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
* right, the holder closes its own browser at its next heartbeat. Start only
|
|
1438
|
-
* after this answered `free`. Errors: 4012 when it is held elsewhere. */
|
|
1439
|
-
takeoverProfile(id) {
|
|
1440
|
-
return this.request("POST", `/v1/profiles/${enc(id)}/takeover`, {});
|
|
1551
|
+
/** Put a domain on the fast mode's list, or switch it on again after it switched itself off. */
|
|
1552
|
+
putWorkflowFastDomain(domain) {
|
|
1553
|
+
return this.request("PUT", `/v1/workflow-fast-domains/${enc(domain)}`);
|
|
1441
1554
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
return this.request("
|
|
1555
|
+
/** Take a domain off the fast mode's list. */
|
|
1556
|
+
deleteWorkflowFastDomain(domain) {
|
|
1557
|
+
return this.request("DELETE", `/v1/workflow-fast-domains/${enc(domain)}`);
|
|
1445
1558
|
}
|
|
1446
1559
|
/**
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
* the
|
|
1450
|
-
* `remaining` / `stopped_reason`) instead of failing every remaining id.
|
|
1560
|
+
* What this machine can do for a planned start that wakes it: sleep model, wake timers,
|
|
1561
|
+
* the wake task, autostart and sign-in, each with its reason. A fix runs at the machine,
|
|
1562
|
+
* from the app's card, because Windows asks for an administrator's confirmation.
|
|
1451
1563
|
*/
|
|
1452
|
-
|
|
1453
|
-
return this.request("
|
|
1564
|
+
getWorkflowReadiness(signal) {
|
|
1565
|
+
return this.request("GET", "/v1/workflow-readiness", void 0, { signal });
|
|
1454
1566
|
}
|
|
1455
|
-
|
|
1456
|
-
|
|
1567
|
+
/** The approvals of this machine waiting for an answer, oldest first. */
|
|
1568
|
+
async listWorkflowApprovals(signal) {
|
|
1569
|
+
const out = await this.request("GET", "/v1/workflow-approvals", void 0, {
|
|
1570
|
+
signal
|
|
1571
|
+
});
|
|
1572
|
+
return out.approvals;
|
|
1457
1573
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1574
|
+
/** Decide an approval from the app; the first valid decision counts. */
|
|
1575
|
+
decideWorkflowApproval(id, body) {
|
|
1576
|
+
return this.request("POST", `/v1/workflow-approvals/${enc(id)}/decide`, body);
|
|
1460
1577
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1578
|
+
/**
|
|
1579
|
+
* The account's approval webhook. Your system answers an announced approval with an
|
|
1580
|
+
* API key that carries `approvals:decide`, at the `answer_url` the announcement names.
|
|
1581
|
+
*/
|
|
1582
|
+
getApprovalWebhook(signal) {
|
|
1583
|
+
return this.request("GET", "/v1/workflow-approval-webhook", void 0, { signal });
|
|
1584
|
+
}
|
|
1585
|
+
/** Set the approval webhook for every machine of the account; `url: null` clears it. */
|
|
1586
|
+
setApprovalWebhook(body) {
|
|
1587
|
+
return this.request("PUT", "/v1/workflow-approval-webhook", body);
|
|
1588
|
+
}
|
|
1589
|
+
/** The files a run keeps (screenshots, PDFs), without their bytes. */
|
|
1590
|
+
listWorkflowRunFiles(runId, signal) {
|
|
1591
|
+
return this.request("GET", `/v1/workflow-runs/${enc(runId)}/files`, void 0, {
|
|
1592
|
+
signal
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
/** One file a run keeps, as bytes to save. */
|
|
1596
|
+
getWorkflowRunFile(runId, fileId, signal) {
|
|
1597
|
+
return this.requestBytes("GET", `/v1/workflow-runs/${enc(runId)}/files/${enc(fileId)}`, { signal });
|
|
1598
|
+
}
|
|
1599
|
+
/** Cancel a run that has not ended. An ended run answers 409. */
|
|
1600
|
+
cancelWorkflowRun(runId) {
|
|
1601
|
+
return this.request("POST", `/v1/workflow-runs/${enc(runId)}/cancel`);
|
|
1463
1602
|
}
|
|
1464
1603
|
/**
|
|
1465
|
-
*
|
|
1604
|
+
* Cancel a start that went to the machine its profile lives on, by the
|
|
1605
|
+
* `forward_ref` its start answered. Not yet fetched there, it ends
|
|
1606
|
+
* `cancelled` at once; fetched, it stays `sent` until that machine reports
|
|
1607
|
+
* its end. An ended one answers as it ended.
|
|
1608
|
+
*/
|
|
1609
|
+
cancelWorkflowForward(forwardRef) {
|
|
1610
|
+
return this.request("POST", `/v1/workflow-forwards/${enc(forwardRef)}/cancel`);
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Answer a halted run: an effect that may have landed stopped it. `done` counts
|
|
1614
|
+
* it as sent and the run goes on without sending again, `retry` sends once
|
|
1615
|
+
* more, `abort` ends the run. A run that does not stand halted answers 409.
|
|
1616
|
+
* With `row_key`, answer one row to check instead: `done`, `retry` (the next
|
|
1617
|
+
* run takes the row again) or `ignore`.
|
|
1618
|
+
*/
|
|
1619
|
+
decideWorkflowRun(runId, body) {
|
|
1620
|
+
return this.request("POST", `/v1/workflow-runs/${enc(runId)}/decide`, body);
|
|
1621
|
+
}
|
|
1622
|
+
/** What "run from step X" of a run would do: seeded, stale and coming nodes. */
|
|
1623
|
+
previewWorkflowRunFork(runId, body) {
|
|
1624
|
+
return this.request("POST", `/v1/workflow-runs/${enc(runId)}/fork-preview`, body);
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Start "run from step X" of a run: the same trigger's run, the outputs before
|
|
1628
|
+
* the node taken from the source, nothing of them run again.
|
|
1629
|
+
*/
|
|
1630
|
+
forkWorkflowRun(runId, body) {
|
|
1631
|
+
return this.request("POST", `/v1/workflow-runs/${enc(runId)}/fork`, body);
|
|
1632
|
+
}
|
|
1633
|
+
/** This machine's ended runs per workflow, profile or day, with the success rate. */
|
|
1634
|
+
getWorkflowUsage(params, signal) {
|
|
1635
|
+
return this.request("GET", "/v1/workflow-usage", void 0, {
|
|
1636
|
+
query: { ...params },
|
|
1637
|
+
signal
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
/** The runs that wait, each with why: queued ones with their place in the dispatch order. */
|
|
1641
|
+
getWorkflowQueue(signal) {
|
|
1642
|
+
return this.request("GET", "/v1/workflow-queue", void 0, { signal });
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Planned, queued and skipped starts of "Schedule Window" triggers, oldest
|
|
1646
|
+
* moment first, each with its reason.
|
|
1647
|
+
*/
|
|
1648
|
+
listWorkflowFires(params = {}, signal) {
|
|
1649
|
+
return this.request("GET", "/v1/workflow-fires", void 0, {
|
|
1650
|
+
query: { ...params },
|
|
1651
|
+
signal
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
// -- Switches -----------------------------------------------------------------
|
|
1655
|
+
/** Every switch that was ever flipped; a switch without a row is on. */
|
|
1656
|
+
listWorkflowSwitches(signal) {
|
|
1657
|
+
return this.request("GET", "/v1/workflow-switches", void 0, { signal });
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Flip a switch. A profile switch turned off ends that profile's begun runs at
|
|
1661
|
+
* once; its queued runs wait until it is on again.
|
|
1662
|
+
*/
|
|
1663
|
+
setWorkflowSwitch(body) {
|
|
1664
|
+
return this.request("PUT", "/v1/workflow-switches", body);
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Stop everything: the account switch off and every begun run ended. Nothing
|
|
1668
|
+
* starts until the account switch is on again.
|
|
1669
|
+
*/
|
|
1670
|
+
emergencyStopWorkflows() {
|
|
1671
|
+
return this.request("POST", "/v1/workflow-switches/emergency-stop");
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
|
|
1675
|
+
// src/client-workflow-ai.ts
|
|
1676
|
+
var WorkflowAiApi = class extends ClientCore {
|
|
1677
|
+
/** A repair's fixes, newest first; with `workflowId` those of one workflow. */
|
|
1678
|
+
listWorkflowRepairs(workflowId, signal) {
|
|
1679
|
+
return this.request("GET", "/v1/workflow-repairs", void 0, {
|
|
1680
|
+
signal,
|
|
1681
|
+
query: workflowId ? { workflow_id: workflowId } : void 0
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
/** The repair's key figures per version and node; 7 days unless `days` (1 to 365) says otherwise. */
|
|
1685
|
+
getWorkflowRepairMetrics(workflowId, days, signal) {
|
|
1686
|
+
return this.request("GET", "/v1/workflow-repair-metrics", void 0, {
|
|
1687
|
+
signal,
|
|
1688
|
+
query: days === void 0 ? { workflow_id: workflowId } : { workflow_id: workflowId, days: String(days) }
|
|
1689
|
+
});
|
|
1690
|
+
}
|
|
1691
|
+
/** One fix with the attempts that made or used it. */
|
|
1692
|
+
getWorkflowRepair(id, signal) {
|
|
1693
|
+
return this.request("GET", `/v1/workflow-repairs/${enc(id)}`, void 0, { signal });
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Take a published fix back: a version `rollback` is published at once, the draft is left
|
|
1697
|
+
* as it is; an element changed since the repair stays and is named.
|
|
1698
|
+
*/
|
|
1699
|
+
revertWorkflowRepair(id) {
|
|
1700
|
+
return this.request("POST", `/v1/workflow-repairs/${enc(id)}/revert`);
|
|
1701
|
+
}
|
|
1702
|
+
/**
|
|
1703
|
+
* Take a repair's version over into the draft as one batch of the repair (one undo takes it
|
|
1704
|
+
* back); a node a person changed since the repair's base is left and named.
|
|
1705
|
+
*/
|
|
1706
|
+
adoptWorkflowVersion(workflowId, versionId) {
|
|
1707
|
+
return this.request("POST", `/v1/workflows/${enc(workflowId)}/adopt`, {
|
|
1708
|
+
version_id: versionId
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
/** Every model source with this machine's health, by label; never a key. */
|
|
1712
|
+
listAiSources(signal) {
|
|
1713
|
+
return this.request("GET", "/v1/ai-sources", void 0, { signal });
|
|
1714
|
+
}
|
|
1715
|
+
/** Add a model source; its key is written once and never read back. */
|
|
1716
|
+
createAiSource(body) {
|
|
1717
|
+
return this.request("POST", "/v1/ai-sources", body);
|
|
1718
|
+
}
|
|
1719
|
+
/** Change a model source or replace its key. */
|
|
1720
|
+
updateAiSource(id, body) {
|
|
1721
|
+
return this.request("PATCH", `/v1/ai-sources/${enc(id)}`, body);
|
|
1722
|
+
}
|
|
1723
|
+
/** Remove a model source. */
|
|
1724
|
+
deleteAiSource(id) {
|
|
1725
|
+
return this.request("DELETE", `/v1/ai-sources/${enc(id)}`);
|
|
1726
|
+
}
|
|
1727
|
+
/** Check an API source now: its health, and what the model takes when it
|
|
1728
|
+
* answers (a few small paid calls). A coding agent is not checked here yet. */
|
|
1729
|
+
checkAiSource(id) {
|
|
1730
|
+
return this.request("POST", `/v1/ai-sources/${enc(id)}/check`);
|
|
1731
|
+
}
|
|
1732
|
+
/** The account's model settings: default order and subscription limits. */
|
|
1733
|
+
getAiSettings(signal) {
|
|
1734
|
+
return this.request("GET", "/v1/ai-settings", void 0, { signal });
|
|
1735
|
+
}
|
|
1736
|
+
/** Set the default order (existing sources only) and the subscription limits. */
|
|
1737
|
+
putAiSettings(body) {
|
|
1738
|
+
return this.request("PUT", "/v1/ai-settings", body);
|
|
1739
|
+
}
|
|
1740
|
+
/** The model calls of runs, newest first. */
|
|
1741
|
+
listAiInvocations(params = {}, signal) {
|
|
1742
|
+
return this.request("GET", "/v1/ai-invocations", void 0, {
|
|
1743
|
+
signal,
|
|
1744
|
+
query: { ...params }
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
|
|
1749
|
+
// src/client-workflow-sync.ts
|
|
1750
|
+
var WorkflowSyncApi = class extends ClientCore {
|
|
1751
|
+
/**
|
|
1752
|
+
* Every published workflow with a "Webhook" trigger, with the address to enter in
|
|
1753
|
+
* Zapier, Make or your own system, and the counts of held and expired calls.
|
|
1754
|
+
*/
|
|
1755
|
+
async workflowHooks(signal) {
|
|
1756
|
+
const out = await this.request("GET", "/v1/workflow-hooks", void 0, { signal });
|
|
1757
|
+
return out.hooks;
|
|
1758
|
+
}
|
|
1759
|
+
/** A new address for the workflow; the old one stops taking calls. */
|
|
1760
|
+
rotateWorkflowHook(workflowId) {
|
|
1761
|
+
return this.request("POST", `/v1/workflow-hooks/${enc(workflowId)}/rotate`);
|
|
1762
|
+
}
|
|
1763
|
+
/**
|
|
1764
|
+
* This machine and every machine that is home to a profile, with the home of
|
|
1765
|
+
* each profile: the binding a start names in `run_on`. Empty without an account.
|
|
1766
|
+
*/
|
|
1767
|
+
workflowMachines(signal) {
|
|
1768
|
+
return this.request("GET", "/v1/workflow-sync/machines", void 0, { signal });
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
// src/client-workflow-shares.ts
|
|
1773
|
+
var WorkflowSharesApi = class extends ClientCore {
|
|
1774
|
+
/**
|
|
1775
|
+
* Share a workflow by link. The link carries the published version, else the
|
|
1776
|
+
* newest saved one, or the version named in `versionId`; the draft is never
|
|
1777
|
+
* shared. Tables, variable values and secrets stay on this machine.
|
|
1466
1778
|
*
|
|
1467
|
-
*
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1779
|
+
* A refusal answers with a `reason`: `share_needs_version` (nothing is saved
|
|
1780
|
+
* yet), `share_unavailable` (no account is connected), `share_refused` or
|
|
1781
|
+
* `share_offline` (the account's server said no, or could not be reached).
|
|
1470
1782
|
*/
|
|
1471
|
-
|
|
1472
|
-
return this.request("POST", "/v1/
|
|
1783
|
+
shareWorkflow(workflowId, opts = {}) {
|
|
1784
|
+
return this.request("POST", "/v1/workflow-shares", {
|
|
1785
|
+
workflow_id: workflowId,
|
|
1786
|
+
...opts.versionId !== void 0 ? { version_id: opts.versionId } : {}
|
|
1787
|
+
});
|
|
1473
1788
|
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1789
|
+
/**
|
|
1790
|
+
* Open a link into a copy in this account. The copy keeps its sender's name
|
|
1791
|
+
* and asks a person's trust before its first start. A link that opens
|
|
1792
|
+
* nothing answers 400 with `reason: workflow_share_bad_link`; a revoked one
|
|
1793
|
+
* 404 with `workflow_share_revoked`; one from a newer Scalebrowser 422 with
|
|
1794
|
+
* `share_newer_format`.
|
|
1795
|
+
*/
|
|
1796
|
+
importSharedWorkflow(link) {
|
|
1797
|
+
return this.request("POST", "/v1/workflow-shares/import", { link });
|
|
1477
1798
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1799
|
+
/**
|
|
1800
|
+
* Stop a link from making new copies. Copies already made stay. Named for the
|
|
1801
|
+
* workflow because `revokeShare` already withdraws a shared video.
|
|
1802
|
+
*/
|
|
1803
|
+
revokeWorkflowShare(shareId) {
|
|
1804
|
+
return this.request("POST", `/v1/workflow-shares/${enc(shareId)}/revoke`);
|
|
1480
1805
|
}
|
|
1481
|
-
|
|
1482
|
-
|
|
1806
|
+
/** The ready-made starting points. */
|
|
1807
|
+
workflowTemplates(signal) {
|
|
1808
|
+
return this.request("GET", "/v1/workflow-templates", void 0, { signal });
|
|
1483
1809
|
}
|
|
1484
|
-
|
|
1485
|
-
|
|
1810
|
+
/** Make a workflow from a template; `name` replaces the template's own. */
|
|
1811
|
+
instantiateTemplate(templateId, opts = {}) {
|
|
1812
|
+
return this.request(
|
|
1813
|
+
"POST",
|
|
1814
|
+
`/v1/workflow-templates/${enc(templateId)}/instantiate`,
|
|
1815
|
+
opts.name !== void 0 ? { name: opts.name } : {}
|
|
1816
|
+
);
|
|
1486
1817
|
}
|
|
1487
|
-
|
|
1488
|
-
|
|
1818
|
+
};
|
|
1819
|
+
|
|
1820
|
+
// src/client-workflow-agency.ts
|
|
1821
|
+
var WorkflowAgencyApi = class extends ClientCore {
|
|
1822
|
+
/**
|
|
1823
|
+
* On a client app: what is shared with the agency, and the end-to-end mode
|
|
1824
|
+
* (`brief_mode`), which the agency switches and this call only shows. Before an
|
|
1825
|
+
* activation `activated` is `false` and `agency` is `null`.
|
|
1826
|
+
*/
|
|
1827
|
+
wlSharing(signal) {
|
|
1828
|
+
return this.request("GET", "/v1/wl/sharing", void 0, { signal });
|
|
1489
1829
|
}
|
|
1490
|
-
|
|
1491
|
-
|
|
1830
|
+
/**
|
|
1831
|
+
* On a client app: change what is shared with the agency. A scope left out
|
|
1832
|
+
* stays as it is; turning one off withdraws it from then on, and what the
|
|
1833
|
+
* agency already saw stays seen. Answers the state after the change.
|
|
1834
|
+
*
|
|
1835
|
+
* Before the app is connected to an agency this answers 409 with
|
|
1836
|
+
* `reason: wl_not_activated`.
|
|
1837
|
+
*/
|
|
1838
|
+
setWlSharing(body) {
|
|
1839
|
+
return this.request("PUT", "/v1/wl/sharing", body);
|
|
1492
1840
|
}
|
|
1493
|
-
|
|
1494
|
-
|
|
1841
|
+
/** On an agency: its end customers, with the mode each one's machine reported last. */
|
|
1842
|
+
async agencyClients(signal) {
|
|
1843
|
+
const out = await this.request("GET", "/v1/agency/clients", void 0, { signal });
|
|
1844
|
+
return out.clients;
|
|
1495
1845
|
}
|
|
1496
|
-
|
|
1497
|
-
|
|
1846
|
+
/**
|
|
1847
|
+
* On an agency: hand the published version of each workflow to a client. The
|
|
1848
|
+
* client's app adopts each one as its own published copy. A workflow that was
|
|
1849
|
+
* never published answers 409; publish it first.
|
|
1850
|
+
*/
|
|
1851
|
+
setAgencyDistribution(clientId, workflowIds) {
|
|
1852
|
+
return this.request("PUT", "/v1/agency/distribution", {
|
|
1853
|
+
client_id: clientId,
|
|
1854
|
+
workflow_ids: workflowIds
|
|
1855
|
+
});
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* On an agency: switch the end-to-end mode of one client. Only the agency can;
|
|
1859
|
+
* the client's own app shows the mode and cannot change it.
|
|
1860
|
+
*/
|
|
1861
|
+
setClientBriefMode(clientId, mode) {
|
|
1862
|
+
return this.request(
|
|
1863
|
+
"PUT",
|
|
1864
|
+
`/v1/agency/clients/${enc(clientId)}/brief-mode`,
|
|
1865
|
+
{ mode }
|
|
1866
|
+
);
|
|
1867
|
+
}
|
|
1868
|
+
/**
|
|
1869
|
+
* On an agency: set the model key its clients' apps use. Write-only: the
|
|
1870
|
+
* daemon keeps it and sends it, sealed, to every active client, and nothing
|
|
1871
|
+
* reads it back. Saving a key again sends it again. With `kind`, each client
|
|
1872
|
+
* turns it into a model source marked `agency`.
|
|
1873
|
+
*/
|
|
1874
|
+
setAgencyAiKey(key, options = {}) {
|
|
1875
|
+
const body = { key };
|
|
1876
|
+
if (options.kind !== void 0) body.kind = options.kind;
|
|
1877
|
+
if (options.model !== void 0) body.model = options.model;
|
|
1878
|
+
if (options.baseUrl !== void 0) body.base_url = options.baseUrl;
|
|
1879
|
+
return this.request("PUT", "/v1/agency/ai-key", body);
|
|
1880
|
+
}
|
|
1881
|
+
};
|
|
1882
|
+
|
|
1883
|
+
// src/events.ts
|
|
1884
|
+
var MAX_BACKOFF_MS = 15e3;
|
|
1885
|
+
function subscribeEvents(params, handlers) {
|
|
1886
|
+
const controller = new AbortController();
|
|
1887
|
+
const fetchImpl = params.fetch ?? globalThis.fetch;
|
|
1888
|
+
let closed = false;
|
|
1889
|
+
let attempt = 0;
|
|
1890
|
+
let lastSeq = null;
|
|
1891
|
+
let everConnected = false;
|
|
1892
|
+
const setStatus = (s) => handlers.onStatus?.(s);
|
|
1893
|
+
const resync = (dropped) => handlers.onEvent({ type: "resync", dropped, at: Math.floor(Date.now() / 1e3) });
|
|
1894
|
+
const deliver = (event) => {
|
|
1895
|
+
if (typeof event.seq === "number") {
|
|
1896
|
+
if (lastSeq !== null && event.seq > lastSeq + 1) resync(event.seq - lastSeq - 1);
|
|
1897
|
+
lastSeq = event.seq;
|
|
1898
|
+
}
|
|
1899
|
+
handlers.onEvent(event);
|
|
1900
|
+
};
|
|
1901
|
+
async function connect() {
|
|
1902
|
+
while (!closed) {
|
|
1903
|
+
setStatus("connecting");
|
|
1904
|
+
try {
|
|
1905
|
+
const headers = { Accept: "text/event-stream" };
|
|
1906
|
+
if (params.token) headers["Authorization"] = `Bearer ${params.token}`;
|
|
1907
|
+
const res = await fetchImpl(`${params.baseUrl}/v1/events`, {
|
|
1908
|
+
headers,
|
|
1909
|
+
signal: controller.signal
|
|
1910
|
+
});
|
|
1911
|
+
if (res.status === 401) {
|
|
1912
|
+
params.onUnauthorized?.();
|
|
1913
|
+
break;
|
|
1914
|
+
}
|
|
1915
|
+
if (!res.ok || !res.body) {
|
|
1916
|
+
throw new NetworkError(`event stream failed (HTTP ${res.status})`);
|
|
1917
|
+
}
|
|
1918
|
+
attempt = 0;
|
|
1919
|
+
setStatus("open");
|
|
1920
|
+
lastSeq = null;
|
|
1921
|
+
if (everConnected) resync(0);
|
|
1922
|
+
everConnected = true;
|
|
1923
|
+
await pump(res.body, deliver, controller.signal);
|
|
1924
|
+
} catch {
|
|
1925
|
+
if (closed || controller.signal.aborted) break;
|
|
1926
|
+
}
|
|
1927
|
+
if (closed) break;
|
|
1928
|
+
setStatus("connecting");
|
|
1929
|
+
attempt += 1;
|
|
1930
|
+
const delay2 = Math.min(MAX_BACKOFF_MS, 500 * 2 ** Math.min(attempt, 5));
|
|
1931
|
+
await sleep(delay2, controller.signal);
|
|
1932
|
+
}
|
|
1933
|
+
setStatus("closed");
|
|
1498
1934
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1935
|
+
void connect();
|
|
1936
|
+
return () => {
|
|
1937
|
+
closed = true;
|
|
1938
|
+
controller.abort();
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
async function pump(body, onEvent, signal) {
|
|
1942
|
+
const reader = body.getReader();
|
|
1943
|
+
const decoder = new TextDecoder();
|
|
1944
|
+
let buffer = "";
|
|
1945
|
+
try {
|
|
1946
|
+
while (!signal.aborted) {
|
|
1947
|
+
const { value, done } = await reader.read();
|
|
1948
|
+
if (done) break;
|
|
1949
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1950
|
+
let sep;
|
|
1951
|
+
while ((sep = indexOfFrameEnd(buffer)) !== -1) {
|
|
1952
|
+
const frame = buffer.slice(0, sep);
|
|
1953
|
+
buffer = buffer.slice(sep).replace(/^(\r?\n){1,2}/, "");
|
|
1954
|
+
const event = parseSseFrame(frame);
|
|
1955
|
+
if (event) onEvent(event);
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
} finally {
|
|
1959
|
+
void reader.cancel().catch(() => {
|
|
1960
|
+
});
|
|
1501
1961
|
}
|
|
1502
|
-
|
|
1503
|
-
|
|
1962
|
+
}
|
|
1963
|
+
function indexOfFrameEnd(buffer) {
|
|
1964
|
+
const lf = buffer.indexOf("\n\n");
|
|
1965
|
+
const crlf = buffer.indexOf("\r\n\r\n");
|
|
1966
|
+
if (lf === -1) return crlf;
|
|
1967
|
+
if (crlf === -1) return lf;
|
|
1968
|
+
return Math.min(lf, crlf);
|
|
1969
|
+
}
|
|
1970
|
+
function parseSseFrame(frame) {
|
|
1971
|
+
const dataLines = [];
|
|
1972
|
+
for (const line of frame.split(/\r?\n/)) {
|
|
1973
|
+
if (line.startsWith("data:")) dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
1504
1974
|
}
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1975
|
+
if (dataLines.length === 0) return null;
|
|
1976
|
+
const payload = dataLines.join("\n");
|
|
1977
|
+
if (!payload || payload === "[DONE]") return null;
|
|
1978
|
+
try {
|
|
1979
|
+
return JSON.parse(payload);
|
|
1980
|
+
} catch {
|
|
1981
|
+
return null;
|
|
1508
1982
|
}
|
|
1509
|
-
|
|
1510
|
-
|
|
1983
|
+
}
|
|
1984
|
+
function eventStream(params) {
|
|
1985
|
+
const buffer = [];
|
|
1986
|
+
const waiters = [];
|
|
1987
|
+
let done = false;
|
|
1988
|
+
const unsubscribe = subscribeEvents(params, {
|
|
1989
|
+
onEvent: (event) => {
|
|
1990
|
+
const waiter = waiters.shift();
|
|
1991
|
+
if (waiter) waiter({ value: event, done: false });
|
|
1992
|
+
else buffer.push(event);
|
|
1993
|
+
}
|
|
1994
|
+
});
|
|
1995
|
+
const finish = () => {
|
|
1996
|
+
if (!done) {
|
|
1997
|
+
done = true;
|
|
1998
|
+
unsubscribe();
|
|
1999
|
+
for (const w of waiters.splice(0)) w({ value: void 0, done: true });
|
|
2000
|
+
}
|
|
2001
|
+
return { value: void 0, done: true };
|
|
2002
|
+
};
|
|
2003
|
+
return {
|
|
2004
|
+
next() {
|
|
2005
|
+
const next = buffer.shift();
|
|
2006
|
+
if (next !== void 0) return Promise.resolve({ value: next, done: false });
|
|
2007
|
+
if (done) return Promise.resolve({ value: void 0, done: true });
|
|
2008
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
2009
|
+
},
|
|
2010
|
+
return() {
|
|
2011
|
+
return Promise.resolve(finish());
|
|
2012
|
+
},
|
|
2013
|
+
[Symbol.asyncIterator]() {
|
|
2014
|
+
return this;
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
function sleep(ms, signal) {
|
|
2019
|
+
return new Promise((resolve) => {
|
|
2020
|
+
if (signal.aborted) return resolve();
|
|
2021
|
+
const t = setTimeout(resolve, ms);
|
|
2022
|
+
signal.addEventListener(
|
|
2023
|
+
"abort",
|
|
2024
|
+
() => {
|
|
2025
|
+
clearTimeout(t);
|
|
2026
|
+
resolve();
|
|
2027
|
+
},
|
|
2028
|
+
{ once: true }
|
|
2029
|
+
);
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// src/cdp-connection.ts
|
|
2034
|
+
var CdpConnection = class {
|
|
2035
|
+
#ws;
|
|
2036
|
+
#nextId = 0;
|
|
2037
|
+
#pending = /* @__PURE__ */ new Map();
|
|
2038
|
+
#subscribers = /* @__PURE__ */ new Set();
|
|
2039
|
+
#closeListeners = /* @__PURE__ */ new Set();
|
|
2040
|
+
#closeReason = null;
|
|
2041
|
+
constructor(ws) {
|
|
2042
|
+
this.#ws = ws;
|
|
2043
|
+
ws.on("message", (data) => this.#onMessage(data));
|
|
2044
|
+
ws.on("close", () => this.#onClose(new CdpError(-1, "CDP connection closed")));
|
|
2045
|
+
ws.on("error", (err) => this.#onClose(new NetworkError("CDP connection error", err)));
|
|
1511
2046
|
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
2047
|
+
request(method, params, sessionId) {
|
|
2048
|
+
if (this.#closeReason) return Promise.reject(this.#closeReason);
|
|
2049
|
+
const id = ++this.#nextId;
|
|
2050
|
+
const frame = { id, method };
|
|
2051
|
+
if (params !== void 0) frame["params"] = params;
|
|
2052
|
+
if (sessionId !== void 0) frame["sessionId"] = sessionId;
|
|
2053
|
+
return new Promise((resolve, reject) => {
|
|
2054
|
+
this.#pending.set(id, { resolve, reject });
|
|
2055
|
+
this.#ws.send(JSON.stringify(frame), (err) => {
|
|
2056
|
+
if (err) {
|
|
2057
|
+
this.#pending.delete(id);
|
|
2058
|
+
reject(new NetworkError("failed to send CDP command", err));
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
});
|
|
1515
2062
|
}
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
return this.
|
|
2063
|
+
subscribe(cb) {
|
|
2064
|
+
this.#subscribers.add(cb);
|
|
2065
|
+
return () => this.#subscribers.delete(cb);
|
|
1519
2066
|
}
|
|
1520
|
-
/**
|
|
1521
|
-
|
|
1522
|
-
|
|
2067
|
+
/** Register a callback fired once when the connection closes (immediately if
|
|
2068
|
+
* it already has); event streams use this to end instead of hanging. */
|
|
2069
|
+
onClose(cb) {
|
|
2070
|
+
if (this.#closeReason) {
|
|
2071
|
+
cb();
|
|
2072
|
+
return () => {
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
this.#closeListeners.add(cb);
|
|
2076
|
+
return () => this.#closeListeners.delete(cb);
|
|
1523
2077
|
}
|
|
1524
|
-
|
|
1525
|
-
|
|
2078
|
+
close() {
|
|
2079
|
+
this.#ws.close();
|
|
1526
2080
|
}
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
previewVideoPreset(body, signal) {
|
|
1530
|
-
return this.request("POST", "/v1/video-presets/preview", body, { signal });
|
|
2081
|
+
get closed() {
|
|
2082
|
+
return this.#closeReason !== null;
|
|
1531
2083
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
2084
|
+
#onMessage(data) {
|
|
2085
|
+
let frame;
|
|
2086
|
+
try {
|
|
2087
|
+
frame = JSON.parse(rawToString(data));
|
|
2088
|
+
} catch {
|
|
2089
|
+
return;
|
|
2090
|
+
}
|
|
2091
|
+
if (typeof frame.id === "number") {
|
|
2092
|
+
const pending = this.#pending.get(frame.id);
|
|
2093
|
+
if (!pending) return;
|
|
2094
|
+
this.#pending.delete(frame.id);
|
|
2095
|
+
if (frame.error) pending.reject(new CdpError(frame.error.code, frame.error.message, frame.error.data));
|
|
2096
|
+
else pending.resolve(frame.result);
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
if (typeof frame.method === "string") {
|
|
2100
|
+
const event = { method: frame.method, params: frame.params ?? {}, sessionId: frame.sessionId };
|
|
2101
|
+
for (const cb of [...this.#subscribers]) cb(event);
|
|
2102
|
+
}
|
|
1536
2103
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
2104
|
+
#onClose(reason) {
|
|
2105
|
+
if (this.#closeReason) return;
|
|
2106
|
+
this.#closeReason = reason;
|
|
2107
|
+
for (const [, pending] of this.#pending) pending.reject(reason);
|
|
2108
|
+
this.#pending.clear();
|
|
2109
|
+
this.#subscribers.clear();
|
|
2110
|
+
for (const cb of [...this.#closeListeners]) cb();
|
|
2111
|
+
this.#closeListeners.clear();
|
|
1540
2112
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
2113
|
+
};
|
|
2114
|
+
function rawToString(data) {
|
|
2115
|
+
if (typeof data === "string") return data;
|
|
2116
|
+
if (Buffer.isBuffer(data)) return data.toString("utf8");
|
|
2117
|
+
if (Array.isArray(data)) return Buffer.concat(data).toString("utf8");
|
|
2118
|
+
return Buffer.from(data).toString("utf8");
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// src/cdp.ts
|
|
2122
|
+
var CdpSession = class _CdpSession {
|
|
2123
|
+
#conn;
|
|
2124
|
+
sessionId;
|
|
2125
|
+
#client;
|
|
2126
|
+
#profileId;
|
|
2127
|
+
constructor(conn, sessionId, client, profileId) {
|
|
2128
|
+
this.#conn = conn;
|
|
2129
|
+
this.sessionId = sessionId;
|
|
2130
|
+
this.#client = client;
|
|
2131
|
+
this.#profileId = profileId;
|
|
1553
2132
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
return this.request("GET", "/v1/proxies", void 0, { signal });
|
|
2133
|
+
/** Send a raw CDP command and await its result (by id). */
|
|
2134
|
+
send(method, params) {
|
|
2135
|
+
return this.#conn.request(method, params, this.sessionId);
|
|
1558
2136
|
}
|
|
1559
|
-
|
|
1560
|
-
|
|
2137
|
+
/** Register a callback for a CDP event scoped to this session. Returns unsubscribe. */
|
|
2138
|
+
on(method, callback) {
|
|
2139
|
+
return this.#conn.subscribe((event) => {
|
|
2140
|
+
if (event.method === method && event.sessionId === this.sessionId) callback(event.params);
|
|
2141
|
+
});
|
|
1561
2142
|
}
|
|
1562
|
-
|
|
1563
|
-
|
|
2143
|
+
/** `for await (const event of session.events())` over this session's CDP events. */
|
|
2144
|
+
events() {
|
|
2145
|
+
return scopedEventStream(this.#conn, this.sessionId);
|
|
1564
2146
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
2147
|
+
/** Attach to a page target, returning a page-bound child session. */
|
|
2148
|
+
async attachToPage(opts = {}) {
|
|
2149
|
+
let targetId = opts.targetId;
|
|
2150
|
+
if (opts.create) {
|
|
2151
|
+
const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
|
|
2152
|
+
targetId = created.targetId;
|
|
2153
|
+
} else if (!targetId) {
|
|
2154
|
+
const { targetInfos } = await this.send("Target.getTargets");
|
|
2155
|
+
const page = targetInfos.find((t) => t.type === "page");
|
|
2156
|
+
if (page) {
|
|
2157
|
+
targetId = page.targetId;
|
|
2158
|
+
} else {
|
|
2159
|
+
const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
|
|
2160
|
+
targetId = created.targetId;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
const { sessionId } = await this.send("Target.attachToTarget", { targetId, flatten: true });
|
|
2164
|
+
return new _CdpSession(this.#conn, sessionId, this.#client, this.#profileId);
|
|
1567
2165
|
}
|
|
1568
|
-
|
|
1569
|
-
|
|
2166
|
+
/** Navigate the page; optionally wait for load. Never calls `Runtime.enable`. */
|
|
2167
|
+
async navigate(url, opts = {}) {
|
|
2168
|
+
const res = await this.send("Page.navigate", { url });
|
|
2169
|
+
if (res.errorText) throw new CdpError(-1, `navigation failed: ${res.errorText}`);
|
|
2170
|
+
if (opts.wait !== false) await this.#waitForLoad(opts.timeout ?? 3e4);
|
|
2171
|
+
return res;
|
|
1570
2172
|
}
|
|
1571
|
-
/**
|
|
1572
|
-
|
|
1573
|
-
|
|
2173
|
+
/** Evaluate a JS expression in the page (or an isolated world) and return its value. */
|
|
2174
|
+
async evaluate(expression, opts = {}) {
|
|
2175
|
+
const params = {
|
|
2176
|
+
expression,
|
|
2177
|
+
awaitPromise: opts.awaitPromise ?? true,
|
|
2178
|
+
returnByValue: opts.returnByValue ?? true
|
|
2179
|
+
};
|
|
2180
|
+
if (opts.isolated) params["contextId"] = await this.createIsolatedWorld();
|
|
2181
|
+
const res = await this.send("Runtime.evaluate", params);
|
|
2182
|
+
if (res.exceptionDetails) {
|
|
2183
|
+
throw new CdpError(-1, res.exceptionDetails.text || res.exceptionDetails.exception?.description || "evaluate exception");
|
|
2184
|
+
}
|
|
2185
|
+
return res.result.value;
|
|
1574
2186
|
}
|
|
1575
2187
|
/**
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
*
|
|
2188
|
+
* Create an isolated world for the (main) frame and return its execution context id.
|
|
2189
|
+
*
|
|
2190
|
+
* The id belongs to the document that is loaded right now. After a navigation it
|
|
2191
|
+
* names a context that no longer exists, so ask again instead of keeping it:
|
|
2192
|
+
* Chrome hands back the same world for the same name, so asking costs one round
|
|
2193
|
+
* trip.
|
|
1579
2194
|
*/
|
|
1580
|
-
|
|
1581
|
-
|
|
2195
|
+
async createIsolatedWorld(frameId, worldName = "__sb") {
|
|
2196
|
+
let frame = frameId;
|
|
2197
|
+
if (!frame) {
|
|
2198
|
+
const { frameTree } = await this.send("Page.getFrameTree");
|
|
2199
|
+
frame = frameTree.frame.id;
|
|
2200
|
+
}
|
|
2201
|
+
const { executionContextId } = await this.send("Page.createIsolatedWorld", {
|
|
2202
|
+
frameId: frame,
|
|
2203
|
+
worldName,
|
|
2204
|
+
grantUniveralAccess: false
|
|
2205
|
+
});
|
|
2206
|
+
return executionContextId;
|
|
1582
2207
|
}
|
|
1583
|
-
// ──
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
// sites and keeps what each one saw. The profile must be RUNNING; the run takes
|
|
1587
|
-
// minutes, so `startAudit` returns immediately and you poll `getAudit`.
|
|
1588
|
-
/** Queue a run → the status right after queueing. `409` if not running / already running. */
|
|
1589
|
-
startAudit(profileId) {
|
|
1590
|
-
return this.request("POST", `/v1/profiles/${enc(profileId)}/audit`);
|
|
2208
|
+
// ── Humanized trusted input (routes through the daemon) ────────────────────
|
|
2209
|
+
humanizeMove(x, y, opts = {}) {
|
|
2210
|
+
return this.#input({ action: "move", x, y, width: opts.width });
|
|
1591
2211
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
2212
|
+
humanizeClick(x, y, opts = {}) {
|
|
2213
|
+
return this.#input({
|
|
2214
|
+
action: "click",
|
|
2215
|
+
x,
|
|
2216
|
+
y,
|
|
2217
|
+
button: opts.button ?? "left",
|
|
2218
|
+
click_count: opts.clickCount ?? 1,
|
|
2219
|
+
width: opts.width
|
|
1596
2220
|
});
|
|
1597
2221
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
*
|
|
1601
|
-
*
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
getExitStatus(profileId, signal) {
|
|
1606
|
-
return this.request("GET", `/v1/profiles/${enc(profileId)}/exit`, void 0, {
|
|
1607
|
-
signal
|
|
1608
|
-
});
|
|
2222
|
+
/**
|
|
2223
|
+
* B5: humanized move to the CENTRE of an element box, with the box width fed to the
|
|
2224
|
+
* daemon's Fitts-law approach so the pointer lands *within* the element (not on a
|
|
2225
|
+
* fixed corner). Pass a `getBoundingClientRect()`-shaped box.
|
|
2226
|
+
*/
|
|
2227
|
+
humanizeMoveToElement(box) {
|
|
2228
|
+
return this.humanizeMove(box.x + box.width / 2, box.y + box.height / 2, { width: box.width });
|
|
1609
2229
|
}
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
return this.
|
|
2230
|
+
/** B5: humanized click at the centre of an element box (see {@link humanizeMoveToElement}). */
|
|
2231
|
+
humanizeClickElement(box, opts = {}) {
|
|
2232
|
+
return this.humanizeClick(box.x + box.width / 2, box.y + box.height / 2, { ...opts, width: box.width });
|
|
1613
2233
|
}
|
|
1614
|
-
|
|
1615
|
-
return this
|
|
2234
|
+
humanizeType(text) {
|
|
2235
|
+
return this.#input({ action: "type", text });
|
|
1616
2236
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
2237
|
+
humanizeScroll(x, y, opts = {}) {
|
|
2238
|
+
return this.#input({ action: "scroll", x, y, delta_x: opts.deltaX ?? 0, delta_y: opts.deltaY ?? 0 });
|
|
2239
|
+
}
|
|
2240
|
+
/** Close the underlying CDP connection. */
|
|
2241
|
+
close() {
|
|
2242
|
+
this.#conn.close();
|
|
2243
|
+
}
|
|
2244
|
+
#input(body) {
|
|
2245
|
+
if (!this.#client || !this.#profileId) {
|
|
2246
|
+
return Promise.reject(
|
|
2247
|
+
new CdpError(-1, "humanize requires a CDP session created via client.connectCdp(result, profileId)")
|
|
2248
|
+
);
|
|
2249
|
+
}
|
|
2250
|
+
return this.#client.sendInput(this.#profileId, { ...body, humanize: true });
|
|
2251
|
+
}
|
|
2252
|
+
// The poll reads in an isolated world: a page that wraps `document.readyState`
|
|
2253
|
+
// sees a read from its own world, with a caller that is none of its scripts.
|
|
2254
|
+
// While the new document commits, the world of the old one can vanish between
|
|
2255
|
+
// asking for it and reading in it; the browser refuses that read with its own
|
|
2256
|
+
// error code, and it is retried. A closed connection still fails at once.
|
|
2257
|
+
async #waitForLoad(timeout) {
|
|
2258
|
+
const deadline = Date.now() + timeout;
|
|
2259
|
+
for (; ; ) {
|
|
2260
|
+
const ready = await this.evaluate("document.readyState", { isolated: true }).catch((err) => {
|
|
2261
|
+
if (err instanceof CdpError && err.code !== -1) return void 0;
|
|
2262
|
+
throw err;
|
|
2263
|
+
});
|
|
2264
|
+
if (ready === "complete") return;
|
|
2265
|
+
if (Date.now() > deadline) throw new CdpError(-1, "navigation wait timed out");
|
|
2266
|
+
await delay(50);
|
|
2267
|
+
}
|
|
1620
2268
|
}
|
|
2269
|
+
};
|
|
2270
|
+
async function openCdpSession(url, options = {}) {
|
|
2271
|
+
const headers = {};
|
|
2272
|
+
if (options.token) headers["Authorization"] = `Bearer ${options.token}`;
|
|
2273
|
+
const ws = new WebSocket__default.default(url, { headers, handshakeTimeout: options.openTimeout ?? 3e4 });
|
|
2274
|
+
await waitForOpen(ws);
|
|
2275
|
+
const conn = new CdpConnection(ws);
|
|
2276
|
+
const root = new CdpSession(conn, void 0, options.client, options.profileId);
|
|
2277
|
+
if (options.autoAttach === false) return root;
|
|
2278
|
+
return root.attachToPage({ create: options.createTarget ?? false, url: options.targetUrl });
|
|
2279
|
+
}
|
|
2280
|
+
function waitForOpen(ws) {
|
|
2281
|
+
return new Promise((resolve, reject) => {
|
|
2282
|
+
const onOpen = () => {
|
|
2283
|
+
cleanup();
|
|
2284
|
+
resolve();
|
|
2285
|
+
};
|
|
2286
|
+
const onError = (err) => {
|
|
2287
|
+
cleanup();
|
|
2288
|
+
reject(new NetworkError("CDP websocket failed to open", err));
|
|
2289
|
+
};
|
|
2290
|
+
const cleanup = () => {
|
|
2291
|
+
ws.off("open", onOpen);
|
|
2292
|
+
ws.off("error", onError);
|
|
2293
|
+
};
|
|
2294
|
+
ws.on("open", onOpen);
|
|
2295
|
+
ws.on("error", onError);
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function scopedEventStream(conn, sessionId) {
|
|
2299
|
+
const buffer = [];
|
|
2300
|
+
const waiters = [];
|
|
2301
|
+
let done = false;
|
|
2302
|
+
const unsubscribe = conn.subscribe((event) => {
|
|
2303
|
+
if (event.sessionId !== sessionId) return;
|
|
2304
|
+
const waiter = waiters.shift();
|
|
2305
|
+
if (waiter) waiter({ value: event, done: false });
|
|
2306
|
+
else buffer.push(event);
|
|
2307
|
+
});
|
|
2308
|
+
let offClose = () => {
|
|
2309
|
+
};
|
|
2310
|
+
const finish = () => {
|
|
2311
|
+
if (!done) {
|
|
2312
|
+
done = true;
|
|
2313
|
+
unsubscribe();
|
|
2314
|
+
offClose();
|
|
2315
|
+
for (const w of waiters.splice(0)) w({ value: void 0, done: true });
|
|
2316
|
+
}
|
|
2317
|
+
return { value: void 0, done: true };
|
|
2318
|
+
};
|
|
2319
|
+
offClose = conn.onClose(() => {
|
|
2320
|
+
finish();
|
|
2321
|
+
});
|
|
2322
|
+
return {
|
|
2323
|
+
next() {
|
|
2324
|
+
const next = buffer.shift();
|
|
2325
|
+
if (next !== void 0) return Promise.resolve({ value: next, done: false });
|
|
2326
|
+
if (done) return Promise.resolve({ value: void 0, done: true });
|
|
2327
|
+
return new Promise((resolve) => waiters.push(resolve));
|
|
2328
|
+
},
|
|
2329
|
+
return() {
|
|
2330
|
+
return Promise.resolve(finish());
|
|
2331
|
+
},
|
|
2332
|
+
[Symbol.asyncIterator]() {
|
|
2333
|
+
return this;
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
function delay(ms) {
|
|
2338
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// src/client.ts
|
|
2342
|
+
var DEFAULT_CAPACITY = {
|
|
2343
|
+
max_concurrent: 64,
|
|
2344
|
+
ram_budget_mb: 24576,
|
|
2345
|
+
vram_budget_mb: null
|
|
2346
|
+
};
|
|
2347
|
+
var ScalebrowserClient = class extends ClientCore {
|
|
1621
2348
|
// ── Metrics (with graceful fallback) ────────────────────────────────────────
|
|
1622
2349
|
async getMetrics(signal) {
|
|
1623
2350
|
try {
|
|
@@ -1665,6 +2392,24 @@ var ScalebrowserClient = class extends ClientCore {
|
|
|
1665
2392
|
async setExitRule(enabled, signal) {
|
|
1666
2393
|
return this.request("PUT", "/v1/exit-rule", { enabled }, { signal });
|
|
1667
2394
|
}
|
|
2395
|
+
/**
|
|
2396
|
+
* Which optional MCP tool groups agents on this machine see.
|
|
2397
|
+
*
|
|
2398
|
+
* Agents see the basic tools by default; video, tasks, profile management,
|
|
2399
|
+
* the captcha helpers, the extras and the developer tools are one switch each.
|
|
2400
|
+
*/
|
|
2401
|
+
async getAgentTools(signal) {
|
|
2402
|
+
return this.request("GET", "/v1/agent-tools", void 0, { signal });
|
|
2403
|
+
}
|
|
2404
|
+
/**
|
|
2405
|
+
* Turn one tool group on or off for every agent on this machine.
|
|
2406
|
+
*
|
|
2407
|
+
* It applies to the next tool list an agent asks for. A session that listed
|
|
2408
|
+
* its tools before keeps that list until it reconnects.
|
|
2409
|
+
*/
|
|
2410
|
+
async setAgentToolGroup(group, enabled, signal) {
|
|
2411
|
+
return this.request("PUT", "/v1/agent-tools", { group, enabled }, { signal });
|
|
2412
|
+
}
|
|
1668
2413
|
// ── Events (SSE) ───────────────────────────────────────────────────────────
|
|
1669
2414
|
/** Subscribe to lifecycle events. Returns an unsubscribe function. */
|
|
1670
2415
|
subscribeEvents(handlers) {
|
|
@@ -1723,22 +2468,34 @@ function deriveMetricsFromProfiles(profiles) {
|
|
|
1723
2468
|
};
|
|
1724
2469
|
}
|
|
1725
2470
|
applyMixins(ScalebrowserClient, [
|
|
2471
|
+
ProfilesApi,
|
|
2472
|
+
PresetsApi,
|
|
2473
|
+
ProxiesApi,
|
|
1726
2474
|
IdentityApi,
|
|
1727
2475
|
RunsApi,
|
|
1728
2476
|
VideosApi,
|
|
1729
2477
|
ControlApi,
|
|
1730
2478
|
ExtensionsApi,
|
|
1731
|
-
TasksApi
|
|
2479
|
+
TasksApi,
|
|
2480
|
+
WorkflowsApi,
|
|
2481
|
+
WorkflowRunsApi,
|
|
2482
|
+
WorkflowAiApi,
|
|
2483
|
+
WorkflowSyncApi,
|
|
2484
|
+
WorkflowSharesApi,
|
|
2485
|
+
WorkflowAgencyApi,
|
|
2486
|
+
TablesApi
|
|
1732
2487
|
]);
|
|
1733
2488
|
|
|
2489
|
+
// src/types-proxies.ts
|
|
2490
|
+
var PROXY_KINDS = ["http", "socks5", "gateway"];
|
|
2491
|
+
var ROTATIONS = ["sticky", "rotating"];
|
|
2492
|
+
|
|
1734
2493
|
// src/types.ts
|
|
1735
2494
|
var RUNTIME_STATES = ["stopped", "starting", "running", "crashed"];
|
|
1736
2495
|
var GEO_MODES = ["strict_expected", "follow_exit", "off"];
|
|
1737
|
-
var PROXY_KINDS = ["http", "socks5", "gateway"];
|
|
1738
|
-
var ROTATIONS = ["sticky", "rotating"];
|
|
1739
2496
|
|
|
1740
2497
|
// src/index.ts
|
|
1741
|
-
var VERSION = "1.
|
|
2498
|
+
var VERSION = "1.3.0";
|
|
1742
2499
|
|
|
1743
2500
|
exports.ApiError = ApiError;
|
|
1744
2501
|
exports.CdpError = CdpError;
|