@scalebrowser/sdk 1.2.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/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) {
@@ -600,1044 +643,1708 @@ var IdentityApi = class extends ClientCore {
600
643
  }
601
644
  };
602
645
 
603
- // src/client-tasks.ts
604
- var TasksApi = class extends ClientCore {
605
- // -- Tasks ------------------------------------------------------------------
606
- //
607
- // Fleet-wide by default, and deliberately so: the question this surface exists
608
- // for is "what is outstanding across my twenty accounts", and a per-profile
609
- // route would make a client ask it twenty times and sort the answers itself.
610
- //
611
- // None of these starts a browser. A task is a row, so reading the whole fleet's
612
- // list costs nothing from the plan's concurrent-browser allowance. Reserve only
613
- // the profiles that turn out to have work.
614
- /**
615
- * What is still to be done. No filter means every task of every profile.
616
- *
617
- * Pass `state: 'open'` for what is outstanding; without it, tasks finished
618
- * within the last day are included too.
619
- */
620
- listTasks(params, signal) {
621
- return this.request("GET", "/v1/tasks", void 0, {
622
- query: { ...params },
623
- signal
624
- });
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 });
625
651
  }
626
- /**
627
- * Put the same task on one or many profiles, one row each.
628
- *
629
- * A task is a LINE, not a document: name the work and leave the material where
630
- * it lives. `due_at` is a deadline, not a trigger; nothing runs by itself.
631
- *
632
- * Profiles that no longer exist come back in `missing` instead of failing the
633
- * whole call.
634
- */
635
- createTasks(body) {
636
- return this.request("POST", "/v1/tasks", body);
652
+ getGroup(id, signal) {
653
+ return this.request("GET", `/v1/groups/${enc(id)}`, void 0, { signal });
637
654
  }
638
- /**
639
- * Call a task off.
640
- *
641
- * Only a task nobody has claimed can be cancelled here. One an agent is working
642
- * on right now is stopped by telling that agent, which is a channel that already
643
- * reaches it; this surface answers `409` for it rather than pretending.
644
- */
645
- cancelTask(id) {
646
- return this.request("PATCH", `/v1/tasks/${enc(id)}`, { state: "cancelled" });
655
+ createGroup(body) {
656
+ return this.request("POST", "/v1/groups", body);
647
657
  }
648
- /** Remove a task outright. */
649
- deleteTask(id) {
650
- return this.request("DELETE", `/v1/tasks/${enc(id)}`);
658
+ updateGroup(id, body) {
659
+ return this.request("PATCH", `/v1/groups/${enc(id)}`, body);
651
660
  }
652
- // -- Profile memory ---------------------------------------------------------
653
- /**
654
- * A profile's durable memory, the `PROFILE.md` at the top of its directory.
655
- *
656
- * `content` is `null` while nobody has written one: a profile starts with no
657
- * file, not with an empty one.
658
- */
659
- getProfileMemory(profileId, signal) {
660
- return this.request("GET", `/v1/profiles/${enc(profileId)}/memory`, void 0, {
661
- signal
662
- });
661
+ deleteGroup(id) {
662
+ return this.request("DELETE", `/v1/groups/${enc(id)}`);
663
663
  }
664
- /**
665
- * Replace a profile's memory.
666
- *
667
- * Stored verbatim: no trimming, no appended newline, no line-ending
668
- * translation. The last write wins and nothing warns, exactly as with a file
669
- * two people can open.
670
- */
671
- putProfileMemory(profileId, content) {
672
- return this.request("PUT", `/v1/profiles/${enc(profileId)}/memory`, { content });
664
+ listPresets(signal) {
665
+ return this.request("GET", "/v1/presets", void 0, { signal });
673
666
  }
674
- /** Remove a profile's memory. Removing one that is not there is not an error. */
675
- deleteProfileMemory(profileId) {
676
- return this.request("DELETE", `/v1/profiles/${enc(profileId)}/memory`);
667
+ getPreset(id, signal) {
668
+ return this.request("GET", `/v1/presets/${enc(id)}`, void 0, { signal });
677
669
  }
678
- };
679
-
680
- // src/client-runs.ts
681
- var RunsApi = class extends ClientCore {
682
- // ── Agent runs ─────────────────────────────────────────────────────────────
683
- /** Runs, newest first. Read-only, all of it. */
684
- listRuns(params = {}, signal) {
685
- return this.request("GET", "/v1/runs", void 0, {
686
- query: { profile_id: params.profile_id, limit: params.limit, offset: params.offset },
687
- signal
688
- });
670
+ createPreset(body) {
671
+ return this.request("POST", "/v1/presets", body);
689
672
  }
690
- /** One run. */
691
- getRun(runId, signal) {
692
- return this.request("GET", `/v1/runs/${enc(runId)}`, void 0, { signal });
673
+ updatePreset(id, body) {
674
+ return this.request("PATCH", `/v1/presets/${enc(id)}`, body);
693
675
  }
694
- /** A run's steps, oldest first: the order they happened in. */
695
- listRunSteps(runId, params = {}, signal) {
696
- return this.request("GET", `/v1/runs/${enc(runId)}/steps`, void 0, {
697
- query: { limit: params.limit, offset: params.offset },
698
- signal
699
- });
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 });
700
714
  }
701
715
  /**
702
- * The still taken at one step, as JPEG bytes.
703
- *
704
- * The picture shows a customer's account, so it is decrypted only on the way
705
- * 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.
706
719
  */
707
- getRunShot(runId, seq, signal) {
708
- return this.requestBytes("GET", `/v1/runs/${enc(runId)}/shots/${seq}`, { signal });
709
- }
710
- /** What every running profile currently shows. */
711
- getActivity(signal) {
712
- return this.request("GET", "/v1/activity", void 0, { signal });
720
+ getPersonaConstraints(signal) {
721
+ return this.request(
722
+ "GET",
723
+ "/v1/persona/constraints",
724
+ void 0,
725
+ { signal }
726
+ );
713
727
  }
714
728
  };
715
729
 
716
- // src/client-videos.ts
717
- var VideosApi = class extends ClientCore {
718
- // ── Videos ────────────────────────────────────────────────────────────────
719
- /** One gallery page, newest first. Running renders are videos too. */
720
- listVideos(params = {}, signal) {
721
- 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, {
722
735
  query: {
723
- q: params.q,
724
- profile_id: params.profile_id,
725
- run_id: params.run_id,
726
- kind: params.kind,
727
- preset: params.preset,
736
+ group: params.group,
728
737
  state: params.state,
729
- page: params.page
738
+ q: params.q,
739
+ limit: params.limit,
740
+ offset: params.offset,
741
+ sort: params.sort,
742
+ order: params.order
730
743
  },
731
744
  signal
732
745
  });
733
746
  }
734
- /** One video row, progress included while it renders. */
735
- getVideo(videoId, signal) {
736
- return this.request("GET", `/v1/videos/${enc(videoId)}`, void 0, { signal });
737
- }
738
- /** Rename. The title also lands in the MP4's metadata on the NEXT render. */
739
- renameVideo(videoId, title, signal) {
740
- return this.request("PATCH", `/v1/videos/${enc(videoId)}`, { title }, { signal });
741
- }
742
747
  /**
743
- * Delete a video (`raw: true` also purges its recording's raw material).
744
- * A live share link is revoked first; 409 `job_running` while it renders.
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.
745
752
  */
746
- deleteVideo(videoId, opts = {}, signal) {
747
- return this.request("DELETE", `/v1/videos/${enc(videoId)}`, void 0, {
748
- query: { raw: opts.raw },
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
+ },
749
762
  signal
750
763
  });
751
764
  }
752
- /** Cancel a queued or rendering video. `done` stays done (409). */
753
- cancelVideo(videoId, signal) {
754
- return this.request("POST", `/v1/videos/${enc(videoId)}/cancel`, void 0, {
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 },
755
779
  signal
756
780
  });
757
781
  }
758
- /** Render a failed or cancelled video again: same id, new job. */
759
- rerenderVideo(videoId, body = {}, signal) {
760
- 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 });
761
784
  }
762
- /** A short-lived fetchable address for one asset (default the video). */
763
- videoAccess(videoId, asset, signal) {
764
- return this.request(
765
- "POST",
766
- `/v1/videos/${enc(videoId)}/access`,
767
- asset ? { asset } : {},
768
- { signal }
769
- );
785
+ createProfile(body) {
786
+ return this.request("POST", "/v1/profiles", body);
770
787
  }
771
- /** One asset's bytes, through a freshly minted grant. */
772
- async downloadVideoFile(videoId, asset = "video", signal) {
773
- const grant = await this.videoAccess(videoId, asset, signal);
774
- const grantParam = new URL(grant.url, "http://x").searchParams.get("grant") ?? "";
775
- return this.requestBytes("GET", `/v1/videos/${enc(videoId)}/file`, {
776
- query: { asset, grant: grantParam },
777
- signal
778
- });
788
+ updateProfile(id, body) {
789
+ return this.request("PATCH", `/v1/profiles/${enc(id)}`, body);
779
790
  }
780
- /** What recordings and videos cost on disk, plus the caps. */
781
- videosStorage(signal) {
782
- return this.request("GET", "/v1/videos/storage", void 0, { signal });
791
+ deleteProfile(id) {
792
+ return this.request("DELETE", `/v1/profiles/${enc(id)}`);
783
793
  }
784
- // ── Recordings ────────────────────────────────────────────────────────────
785
- /** Recordings, newest first. The row outlives its raw bytes. */
786
- listRecordings(params = {}, signal) {
787
- return this.request("GET", "/v1/recordings", void 0, {
788
- query: { profile_id: params.profile_id },
789
- signal
790
- });
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);
791
797
  }
792
- getRecording(recordingId, signal) {
793
- return this.request("GET", `/v1/recordings/${enc(recordingId)}`, void 0, {
794
- signal
795
- });
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);
796
821
  }
797
822
  /**
798
- * Purge a recording's RAW material; the row stays forever
799
- * (`raw_purged_at`). 409 `job_running` while a render of it is open.
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.
800
827
  */
801
- deleteRecordingRaw(recordingId, signal) {
802
- return this.request("DELETE", `/v1/recordings/${enc(recordingId)}`, void 0, {
803
- signal
804
- });
828
+ bulkStart(ids, headless) {
829
+ return this.request("POST", "/v1/bulk/start", { ids, headless });
805
830
  }
806
- /** A NEW video from this recording (the same body the `video` tool takes). */
807
- renderRecording(recordingId, body = {}, signal) {
808
- return this.request("POST", `/v1/recordings/${enc(recordingId)}/renders`, body, {
809
- signal
810
- });
831
+ bulkStop(ids) {
832
+ return this.request("POST", "/v1/bulk/stop", { ids });
811
833
  }
812
- // ── Codecs ────────────────────────────────────────────────────────────────
813
- /** What this machine can encode with. The hardware list is PROBED, not read
814
- * off the binary: `h264_nvenc` is always listed and fails without a driver. */
815
- getCodecs(signal) {
816
- return this.request("GET", "/v1/codecs", void 0, { signal });
834
+ bulkDelete(ids) {
835
+ return this.request("POST", "/v1/bulk/delete", { ids });
817
836
  }
818
- /** Turn Cisco's OpenH264 on or off. The hardware encoders are not switchable. */
819
- setCodecEnabled(codec, enabled, signal) {
820
- 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 });
821
839
  }
822
- // -- Sharing ----------------------------------------------------------------
823
- /** Make a finished video public. Measures every file, asks the control plane
824
- * for permission, uploads, and has the result confirmed. */
825
- share(videoId, body = {}, signal) {
826
- return this.request("POST", `/v1/videos/${enc(videoId)}/share`, body, {
827
- signal
828
- });
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 });
829
849
  }
830
- /** The share ORDER as this machine knows it. How many people watched and
831
- * whether the link still lives is read from the control plane, not from
832
- * here: a number carried along would be wrong the moment another machine
833
- * revoked. */
834
- shareStatus(videoId, signal) {
835
- return this.request(
836
- "GET",
837
- `/v1/videos/${enc(videoId)}/share`,
838
- void 0,
839
- { signal }
840
- );
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`);
841
858
  }
842
- /** Revoke the link. The files fall at once; the order stays until the control
843
- * plane confirms. */
844
- revokeShare(videoId, signal) {
845
- 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, {
846
862
  signal
847
863
  });
848
864
  }
849
- // -- Media ------------------------------------------------------------------
850
- /** Files a preset points at: background image, music bed, subtitle font. */
851
- listMedia(kind, signal) {
852
- return this.request("GET", "/v1/media", void 0, {
853
- query: { kind },
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, {
854
874
  signal
855
875
  });
856
876
  }
857
- /** Upload one file. The body IS the file; `name` and `mime` ride in the query. */
858
- uploadMedia(kind, name, mime, bytes, signal) {
859
- return this.request("POST", "/v1/media", bytes, {
860
- query: { kind, name, mime },
861
- signal
862
- });
877
+ // ── Session bundles ─────────────────────────────────────────────────────────
878
+ exportSession(profileId, body) {
879
+ return this.request("POST", `/v1/profiles/${enc(profileId)}/session/export`, body);
863
880
  }
864
- /** Remove a file. Refuses with 409 while a preset still points at it. */
865
- deleteMedia(id, signal) {
866
- 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);
867
883
  }
868
- /** The file itself. */
869
- mediaFile(id, signal) {
870
- return this.requestBytes("GET", `/v1/media/${enc(id)}/file`, { signal });
884
+ // ── Trusted input ──────────────────────────────────────────────────────────
885
+ sendInput(profileId, body) {
886
+ return this.request("POST", `/v1/profiles/${enc(profileId)}/input`, body);
871
887
  }
872
- // -- Voice providers --------------------------------------------------------
873
- /** Which speech providers have a key. The key itself never comes back: the
874
- * answer carries a hint, and that is on purpose. */
875
- listTtsProviders(signal) {
876
- return this.request("GET", "/v1/tts-providers", void 0, { signal });
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 });
877
896
  }
878
- /** Store a key, or rename one. Leaving `apiKey` out keeps the stored key.
879
- *
880
- * `apiKey` may also be a secret reference (`{{sb:...}}`), which is what an
881
- * agent gets back after fetching a key from the provider's own site: it is
882
- * not allowed to read the value. A reference needs `profileId`, because the
883
- * value belongs to one profile and there is nothing to open without it.
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.
884
917
  */
885
- putTtsProvider(provider, body, signal) {
886
- return this.request(
887
- "PUT",
888
- `/v1/tts-providers/${enc(provider)}`,
889
- { api_key: body.apiKey, label: body.label, profile_id: body.profileId },
890
- { signal }
891
- );
918
+ checkProxyConfig(body) {
919
+ return this.request("POST", "/v1/proxies/check", body);
892
920
  }
893
- /** Call the provider once for real, and record that the key works.
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.
894
936
  *
895
- * Costs one short sentence of the account's own quota. Until this runs, a
896
- * provider row says `verified_at: null`, which means untested rather than
897
- * broken.
937
+ * Pass `state: 'open'` for what is outstanding; without it, tasks finished
938
+ * within the last day are included too.
898
939
  */
899
- verifyTtsProvider(provider, signal) {
900
- return this.request(
901
- "POST",
902
- `/v1/tts-providers/${enc(provider)}/verify`,
903
- void 0,
904
- { signal }
905
- );
906
- }
907
- /** Forget a provider's key. */
908
- deleteTtsProvider(provider, signal) {
909
- 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 },
910
943
  signal
911
944
  });
912
945
  }
913
- };
914
-
915
- // src/events.ts
916
- var MAX_BACKOFF_MS = 15e3;
917
- function subscribeEvents(params, handlers) {
918
- const controller = new AbortController();
919
- const fetchImpl = params.fetch ?? globalThis.fetch;
920
- let closed = false;
921
- let attempt = 0;
922
- let lastSeq = null;
923
- let everConnected = false;
924
- const setStatus = (s) => handlers.onStatus?.(s);
925
- const resync = (dropped) => handlers.onEvent({ type: "resync", dropped, at: Math.floor(Date.now() / 1e3) });
926
- const deliver = (event) => {
927
- if (typeof event.seq === "number") {
928
- if (lastSeq !== null && event.seq > lastSeq + 1) resync(event.seq - lastSeq - 1);
929
- lastSeq = event.seq;
930
- }
931
- handlers.onEvent(event);
932
- };
933
- async function connect() {
934
- while (!closed) {
935
- setStatus("connecting");
936
- try {
937
- const headers = { Accept: "text/event-stream" };
938
- if (params.token) headers["Authorization"] = `Bearer ${params.token}`;
939
- const res = await fetchImpl(`${params.baseUrl}/v1/events`, {
940
- headers,
941
- signal: controller.signal
942
- });
943
- if (res.status === 401) {
944
- params.onUnauthorized?.();
945
- break;
946
- }
947
- if (!res.ok || !res.body) {
948
- throw new NetworkError(`event stream failed (HTTP ${res.status})`);
949
- }
950
- attempt = 0;
951
- setStatus("open");
952
- lastSeq = null;
953
- if (everConnected) resync(0);
954
- everConnected = true;
955
- await pump(res.body, deliver, controller.signal);
956
- } catch {
957
- if (closed || controller.signal.aborted) break;
958
- }
959
- if (closed) break;
960
- setStatus("connecting");
961
- attempt += 1;
962
- const delay2 = Math.min(MAX_BACKOFF_MS, 500 * 2 ** Math.min(attempt, 5));
963
- await sleep(delay2, controller.signal);
964
- }
965
- 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);
966
957
  }
967
- void connect();
968
- return () => {
969
- closed = true;
970
- controller.abort();
971
- };
972
- }
973
- async function pump(body, onEvent, signal) {
974
- const reader = body.getReader();
975
- const decoder = new TextDecoder();
976
- let buffer = "";
977
- try {
978
- while (!signal.aborted) {
979
- const { value, done } = await reader.read();
980
- if (done) break;
981
- buffer += decoder.decode(value, { stream: true });
982
- let sep;
983
- while ((sep = indexOfFrameEnd(buffer)) !== -1) {
984
- const frame = buffer.slice(0, sep);
985
- buffer = buffer.slice(sep).replace(/^(\r?\n){1,2}/, "");
986
- const event = parseSseFrame(frame);
987
- if (event) onEvent(event);
988
- }
989
- }
990
- } finally {
991
- 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
992
982
  });
993
983
  }
994
- }
995
- function indexOfFrameEnd(buffer) {
996
- const lf = buffer.indexOf("\n\n");
997
- const crlf = buffer.indexOf("\r\n\r\n");
998
- if (lf === -1) return crlf;
999
- if (crlf === -1) return lf;
1000
- return Math.min(lf, crlf);
1001
- }
1002
- function parseSseFrame(frame) {
1003
- const dataLines = [];
1004
- for (const line of frame.split(/\r?\n/)) {
1005
- 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 });
1006
993
  }
1007
- if (dataLines.length === 0) return null;
1008
- const payload = dataLines.join("\n");
1009
- if (!payload || payload === "[DONE]") return null;
1010
- try {
1011
- return JSON.parse(payload);
1012
- } catch {
1013
- 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`);
1014
997
  }
1015
- }
1016
- function eventStream(params) {
1017
- const buffer = [];
1018
- const waiters = [];
1019
- let done = false;
1020
- const unsubscribe = subscribeEvents(params, {
1021
- onEvent: (event) => {
1022
- const waiter = waiters.shift();
1023
- if (waiter) waiter({ value: event, done: false });
1024
- else buffer.push(event);
1025
- }
1026
- });
1027
- const finish = () => {
1028
- if (!done) {
1029
- done = true;
1030
- unsubscribe();
1031
- for (const w of waiters.splice(0)) w({ value: void 0, done: true });
1032
- }
1033
- return { value: void 0, done: true };
1034
- };
1035
- return {
1036
- next() {
1037
- const next = buffer.shift();
1038
- if (next !== void 0) return Promise.resolve({ value: next, done: false });
1039
- if (done) return Promise.resolve({ value: void 0, done: true });
1040
- return new Promise((resolve) => waiters.push(resolve));
1041
- },
1042
- return() {
1043
- return Promise.resolve(finish());
1044
- },
1045
- [Symbol.asyncIterator]() {
1046
- return this;
1047
- }
1048
- };
1049
- }
1050
- function sleep(ms, signal) {
1051
- return new Promise((resolve) => {
1052
- if (signal.aborted) return resolve();
1053
- const t = setTimeout(resolve, ms);
1054
- signal.addEventListener(
1055
- "abort",
1056
- () => {
1057
- clearTimeout(t);
1058
- resolve();
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
1059
1050
  },
1060
- { once: true }
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 }
1061
1089
  );
1062
- });
1063
- }
1064
- var CdpConnection = class {
1065
- #ws;
1066
- #nextId = 0;
1067
- #pending = /* @__PURE__ */ new Map();
1068
- #subscribers = /* @__PURE__ */ new Set();
1069
- #closeListeners = /* @__PURE__ */ new Set();
1070
- #closeReason = null;
1071
- constructor(ws) {
1072
- this.#ws = ws;
1073
- ws.on("message", (data) => this.#onMessage(data));
1074
- ws.on("close", () => this.#onClose(new CdpError(-1, "CDP connection closed")));
1075
- ws.on("error", (err) => this.#onClose(new NetworkError("CDP connection error", err)));
1076
1090
  }
1077
- request(method, params, sessionId) {
1078
- if (this.#closeReason) return Promise.reject(this.#closeReason);
1079
- const id = ++this.#nextId;
1080
- const frame = { id, method };
1081
- if (params !== void 0) frame["params"] = params;
1082
- if (sessionId !== void 0) frame["sessionId"] = sessionId;
1083
- return new Promise((resolve, reject) => {
1084
- this.#pending.set(id, { resolve, reject });
1085
- this.#ws.send(JSON.stringify(frame), (err) => {
1086
- if (err) {
1087
- this.#pending.delete(id);
1088
- reject(new NetworkError("failed to send CDP command", err));
1089
- }
1090
- });
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
1091
1098
  });
1092
1099
  }
1093
- subscribe(cb) {
1094
- this.#subscribers.add(cb);
1095
- return () => this.#subscribers.delete(cb);
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 });
1096
1103
  }
1097
- /** Register a callback fired once when the connection closes (immediately if
1098
- * it already has); event streams use this to end instead of hanging. */
1099
- onClose(cb) {
1100
- if (this.#closeReason) {
1101
- cb();
1102
- return () => {
1103
- };
1104
- }
1105
- this.#closeListeners.add(cb);
1106
- 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
+ });
1107
1111
  }
1108
- close() {
1109
- this.#ws.close();
1112
+ getRecording(recordingId, signal) {
1113
+ return this.request("GET", `/v1/recordings/${enc(recordingId)}`, void 0, {
1114
+ signal
1115
+ });
1110
1116
  }
1111
- get closed() {
1112
- return this.#closeReason !== null;
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
+ });
1113
1125
  }
1114
- #onMessage(data) {
1115
- let frame;
1116
- try {
1117
- frame = JSON.parse(rawToString(data));
1118
- } catch {
1119
- return;
1120
- }
1121
- if (typeof frame.id === "number") {
1122
- const pending = this.#pending.get(frame.id);
1123
- if (!pending) return;
1124
- this.#pending.delete(frame.id);
1125
- if (frame.error) pending.reject(new CdpError(frame.error.code, frame.error.message, frame.error.data));
1126
- else pending.resolve(frame.result);
1127
- return;
1128
- }
1129
- if (typeof frame.method === "string") {
1130
- const event = { method: frame.method, params: frame.params ?? {}, sessionId: frame.sessionId };
1131
- for (const cb of [...this.#subscribers]) cb(event);
1132
- }
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
+ });
1133
1131
  }
1134
- #onClose(reason) {
1135
- if (this.#closeReason) return;
1136
- this.#closeReason = reason;
1137
- for (const [, pending] of this.#pending) pending.reject(reason);
1138
- this.#pending.clear();
1139
- this.#subscribers.clear();
1140
- for (const cb of [...this.#closeListeners]) cb();
1141
- this.#closeListeners.clear();
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
+ );
1226
+ }
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
+ });
1232
+ }
1233
+ };
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
+ );
1142
1249
  }
1143
- };
1144
- function rawToString(data) {
1145
- if (typeof data === "string") return data;
1146
- if (Buffer.isBuffer(data)) return data.toString("utf8");
1147
- if (Array.isArray(data)) return Buffer.concat(data).toString("utf8");
1148
- return Buffer.from(data).toString("utf8");
1149
- }
1150
- var CdpSession = class _CdpSession {
1151
- #conn;
1152
- sessionId;
1153
- #client;
1154
- #profileId;
1155
- constructor(conn, sessionId, client, profileId) {
1156
- this.#conn = conn;
1157
- this.sessionId = sessionId;
1158
- this.#client = client;
1159
- this.#profileId = profileId;
1250
+ /** Every table outside the bin. */
1251
+ listTables(signal) {
1252
+ return this.request("GET", "/v1/tables", void 0, { signal });
1160
1253
  }
1161
- /** Send a raw CDP command and await its result (by id). */
1162
- send(method, params) {
1163
- return this.#conn.request(method, params, this.sessionId);
1254
+ /** A local table with its first columns. */
1255
+ createTable(body) {
1256
+ return this.request("POST", "/v1/tables", body);
1164
1257
  }
1165
- /** Register a callback for a CDP event scoped to this session. Returns unsubscribe. */
1166
- on(method, callback) {
1167
- return this.#conn.subscribe((event) => {
1168
- if (event.method === method && event.sessionId === this.sessionId) callback(event.params);
1169
- });
1258
+ getTable(id, signal) {
1259
+ return this.request("GET", `/v1/tables/${enc(id)}`, void 0, { signal });
1170
1260
  }
1171
- /** `for await (const event of session.events())` over this session's CDP events. */
1172
- events() {
1173
- return scopedEventStream(this.#conn, this.sessionId);
1261
+ /** Rename, describe or change the delete rule. */
1262
+ updateTable(id, body) {
1263
+ return this.request("PATCH", `/v1/tables/${enc(id)}`, body);
1174
1264
  }
1175
- /** Attach to a page target, returning a page-bound child session. */
1176
- async attachToPage(opts = {}) {
1177
- let targetId = opts.targetId;
1178
- if (opts.create) {
1179
- const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
1180
- targetId = created.targetId;
1181
- } else if (!targetId) {
1182
- const { targetInfos } = await this.send("Target.getTargets");
1183
- const page = targetInfos.find((t) => t.type === "page");
1184
- if (page) {
1185
- targetId = page.targetId;
1186
- } else {
1187
- const created = await this.send("Target.createTarget", { url: opts.url ?? "about:blank" });
1188
- targetId = created.targetId;
1189
- }
1190
- }
1191
- const { sessionId } = await this.send("Target.attachToTarget", { targetId, flatten: true });
1192
- return new _CdpSession(this.#conn, sessionId, this.#client, this.#profileId);
1265
+ /** To the bin for 30 days. */
1266
+ deleteTable(id) {
1267
+ return this.request("DELETE", `/v1/tables/${enc(id)}`);
1193
1268
  }
1194
- /** Navigate the page; optionally wait for load. Never calls `Runtime.enable`. */
1195
- async navigate(url, opts = {}) {
1196
- const res = await this.send("Page.navigate", { url });
1197
- if (res.errorText) throw new CdpError(-1, `navigation failed: ${res.errorText}`);
1198
- if (opts.wait !== false) await this.#waitForLoad(opts.timeout ?? 3e4);
1199
- return res;
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
1275
+ });
1200
1276
  }
1201
- /** Evaluate a JS expression in the page (or an isolated world) and return its value. */
1202
- async evaluate(expression, opts = {}) {
1203
- const params = {
1204
- expression,
1205
- awaitPromise: opts.awaitPromise ?? true,
1206
- returnByValue: opts.returnByValue ?? true
1207
- };
1208
- if (opts.isolated) params["contextId"] = await this.createIsolatedWorld();
1209
- const res = await this.send("Runtime.evaluate", params);
1210
- if (res.exceptionDetails) {
1211
- throw new CdpError(-1, res.exceptionDetails.text || res.exceptionDetails.exception?.description || "evaluate exception");
1212
- }
1213
- return res.result.value;
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
1282
+ });
1283
+ }
1284
+ /** Ops in order, one result each. */
1285
+ editTable(id, body) {
1286
+ return this.request("POST", `/v1/tables/${enc(id)}/edit`, body);
1214
1287
  }
1215
1288
  /**
1216
- * Create an isolated world for the (main) frame and return its execution context id.
1217
- *
1218
- * The id belongs to the document that is loaded right now. After a navigation it
1219
- * names a context that no longer exists, so ask again instead of keeping it:
1220
- * Chrome hands back the same world for the same name, so asking costs one round
1221
- * trip.
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.
1222
1293
  */
1223
- async createIsolatedWorld(frameId, worldName = "__sb") {
1224
- let frame = frameId;
1225
- if (!frame) {
1226
- const { frameTree } = await this.send("Page.getFrameTree");
1227
- frame = frameTree.frame.id;
1228
- }
1229
- const { executionContextId } = await this.send("Page.createIsolatedWorld", {
1230
- frameId: frame,
1231
- worldName,
1232
- grantUniveralAccess: false
1294
+ importTable(id, file, params) {
1295
+ return this.request("POST", `/v1/tables/${enc(id)}/import`, file, {
1296
+ query: { ...params }
1233
1297
  });
1234
- return executionContextId;
1235
1298
  }
1236
- // ── Humanized trusted input (routes through the daemon) ────────────────────
1237
- humanizeMove(x, y, opts = {}) {
1238
- return this.#input({ action: "move", x, y, width: opts.width });
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 });
1239
1302
  }
1240
- humanizeClick(x, y, opts = {}) {
1241
- return this.#input({
1242
- action: "click",
1243
- x,
1244
- y,
1245
- button: opts.button ?? "left",
1246
- click_count: opts.clickCount ?? 1,
1247
- width: opts.width
1248
- });
1303
+ /** The tables in the bin. */
1304
+ listTableTrash(signal) {
1305
+ return this.request("GET", "/v1/tables/trash", void 0, { signal });
1306
+ }
1307
+ /** Take tables back out of the bin. */
1308
+ restoreTables(ids) {
1309
+ return this.request("POST", "/v1/tables/trash/restore", { ids });
1310
+ }
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;
1249
1315
  }
1250
1316
  /**
1251
- * B5: humanized move to the CENTRE of an element box, with the box width fed to the
1252
- * daemon's Fitts-law approach so the pointer lands *within* the element (not on a
1253
- * fixed corner). Pass a `getBoundingClientRect()`-shaped box.
1317
+ * Start connecting a Google account: open `auth_url` in the default browser;
1318
+ * the connection appears once the person agreed there.
1254
1319
  */
1255
- humanizeMoveToElement(box) {
1256
- return this.humanizeMove(box.x + box.width / 2, box.y + box.height / 2, { width: box.width });
1320
+ connectGoogle(body = {}) {
1321
+ return this.request("POST", "/v1/connections/google", body);
1257
1322
  }
1258
- /** B5: humanized click at the centre of an element box (see {@link humanizeMoveToElement}). */
1259
- humanizeClickElement(box, opts = {}) {
1260
- return this.humanizeClick(box.x + box.width / 2, box.y + box.height / 2, { ...opts, width: box.width });
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;
1261
1327
  }
1262
- humanizeType(text) {
1263
- return this.#input({ action: "type", text });
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);
1264
1334
  }
1265
- humanizeScroll(x, y, opts = {}) {
1266
- return this.#input({ action: "scroll", x, y, delta_x: opts.deltaX ?? 0, delta_y: opts.deltaY ?? 0 });
1335
+ };
1336
+
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
+ });
1267
1354
  }
1268
- /** Close the underlying CDP connection. */
1269
- close() {
1270
- this.#conn.close();
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
+ });
1271
1361
  }
1272
- #input(body) {
1273
- if (!this.#client || !this.#profileId) {
1274
- return Promise.reject(
1275
- new CdpError(-1, "humanize requires a CDP session created via client.connectCdp(result, profileId)")
1276
- );
1277
- }
1278
- return this.#client.sendInput(this.#profileId, { ...body, humanize: true });
1362
+ renameWorkflow(id, name) {
1363
+ return this.request("PATCH", `/v1/workflows/${enc(id)}`, { name });
1279
1364
  }
1280
- // The poll reads in an isolated world: a page that wraps `document.readyState`
1281
- // sees a read from its own world, with a caller that is none of its scripts.
1282
- // While the new document commits, the world of the old one can vanish between
1283
- // asking for it and reading in it; the browser refuses that read with its own
1284
- // error code, and it is retried. A closed connection still fails at once.
1285
- async #waitForLoad(timeout) {
1286
- const deadline = Date.now() + timeout;
1287
- for (; ; ) {
1288
- const ready = await this.evaluate("document.readyState", { isolated: true }).catch((err) => {
1289
- if (err instanceof CdpError && err.code !== -1) return void 0;
1290
- throw err;
1291
- });
1292
- if (ready === "complete") return;
1293
- if (Date.now() > deadline) throw new CdpError(-1, "navigation wait timed out");
1294
- await delay(50);
1295
- }
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
+ });
1296
1370
  }
1297
- };
1298
- async function openCdpSession(url, options = {}) {
1299
- const headers = {};
1300
- if (options.token) headers["Authorization"] = `Bearer ${options.token}`;
1301
- const ws = new WebSocket__default.default(url, { headers, handshakeTimeout: options.openTimeout ?? 3e4 });
1302
- await waitForOpen(ws);
1303
- const conn = new CdpConnection(ws);
1304
- const root = new CdpSession(conn, void 0, options.client, options.profileId);
1305
- if (options.autoAttach === false) return root;
1306
- return root.attachToPage({ create: options.createTarget ?? false, url: options.targetUrl });
1307
- }
1308
- function waitForOpen(ws) {
1309
- return new Promise((resolve, reject) => {
1310
- const onOpen = () => {
1311
- cleanup();
1312
- resolve();
1313
- };
1314
- const onError = (err) => {
1315
- cleanup();
1316
- reject(new NetworkError("CDP websocket failed to open", err));
1317
- };
1318
- const cleanup = () => {
1319
- ws.off("open", onOpen);
1320
- ws.off("error", onError);
1321
- };
1322
- ws.on("open", onOpen);
1323
- ws.on("error", onError);
1324
- });
1325
- }
1326
- function scopedEventStream(conn, sessionId) {
1327
- const buffer = [];
1328
- const waiters = [];
1329
- let done = false;
1330
- const unsubscribe = conn.subscribe((event) => {
1331
- if (event.sessionId !== sessionId) return;
1332
- const waiter = waiters.shift();
1333
- if (waiter) waiter({ value: event, done: false });
1334
- else buffer.push(event);
1335
- });
1336
- let offClose = () => {
1337
- };
1338
- const finish = () => {
1339
- if (!done) {
1340
- done = true;
1341
- unsubscribe();
1342
- offClose();
1343
- for (const w of waiters.splice(0)) w({ value: void 0, done: true });
1344
- }
1345
- return { value: void 0, done: true };
1346
- };
1347
- offClose = conn.onClose(() => {
1348
- finish();
1349
- });
1350
- return {
1351
- next() {
1352
- const next = buffer.shift();
1353
- if (next !== void 0) return Promise.resolve({ value: next, done: false });
1354
- if (done) return Promise.resolve({ value: void 0, done: true });
1355
- return new Promise((resolve) => waiters.push(resolve));
1356
- },
1357
- return() {
1358
- return Promise.resolve(finish());
1359
- },
1360
- [Symbol.asyncIterator]() {
1361
- return this;
1362
- }
1363
- };
1364
- }
1365
- function delay(ms) {
1366
- return new Promise((resolve) => setTimeout(resolve, ms));
1367
- }
1368
-
1369
- // src/client.ts
1370
- var DEFAULT_CAPACITY = {
1371
- max_concurrent: 64,
1372
- ram_budget_mb: 24576,
1373
- vram_budget_mb: null
1374
- };
1375
- var ScalebrowserClient = class extends ClientCore {
1376
- // ── Profiles ───────────────────────────────────────────────────────────────
1377
- listProfiles(params = {}, signal) {
1378
- return this.request("GET", "/v1/profiles", void 0, {
1379
- query: {
1380
- group: params.group,
1381
- state: params.state,
1382
- q: params.q,
1383
- limit: params.limit,
1384
- offset: params.offset,
1385
- sort: params.sort,
1386
- order: params.order
1387
- },
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, {
1396
+ signal
1397
+ });
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
+ }
1408
+ /**
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.
1411
+ */
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 },
1442
+ signal
1443
+ });
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 },
1388
1469
  signal
1389
1470
  });
1390
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
+ }
1391
1476
  /**
1392
- * Every id matching `params`, unpaged: what "act on all matches" needs.
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.
1393
1493
  *
1394
- * `listProfiles` is paged, so acting on "everything" from it only ever covers the
1395
- * page you fetched. Asking for ids costs one request and no persona payloads.
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`.
1396
1500
  */
1397
- listProfileIds(params = {}, signal) {
1398
- return this.request("GET", "/v1/profiles/ids", void 0, {
1399
- query: {
1400
- group: params.group,
1401
- state: params.state,
1402
- q: params.q,
1403
- sort: params.sort,
1404
- order: params.order
1405
- },
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 },
1510
+ signal
1511
+ });
1512
+ }
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 },
1406
1517
  signal
1407
1518
  });
1408
1519
  }
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
+ });
1526
+ }
1527
+ /** This machine's folder boundary for file blocks. */
1528
+ getWorkflowFileAccess(signal) {
1529
+ return this.request("GET", "/v1/workflow-file-access", void 0, { signal });
1530
+ }
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
+ });
1536
+ }
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 });
1540
+ }
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
+ });
1546
+ }
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 });
1550
+ }
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)}`);
1554
+ }
1555
+ /** Take a domain off the fast mode's list. */
1556
+ deleteWorkflowFastDomain(domain) {
1557
+ return this.request("DELETE", `/v1/workflow-fast-domains/${enc(domain)}`);
1558
+ }
1409
1559
  /**
1410
- * How many profiles match `params`, split by runtime state. One request, and
1411
- * its size does not grow with the fleet.
1412
- *
1413
- * `listProfiles` is paged and answers a bare array, so counting what came back
1414
- * counts the page. `listProfileIds` carries the same total but ships an
1415
- * identifier per profile to do it, and cannot split by state at all.
1416
- *
1417
- * `params.state` is ignored here on purpose: a caller labelling every state is
1418
- * sitting in one of them.
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.
1419
1563
  */
1420
- countProfiles(params = {}, signal) {
1421
- return this.request("GET", "/v1/profiles/count", void 0, {
1422
- query: { group: params.group, q: params.q },
1564
+ getWorkflowReadiness(signal) {
1565
+ return this.request("GET", "/v1/workflow-readiness", void 0, { signal });
1566
+ }
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, {
1423
1570
  signal
1424
1571
  });
1572
+ return out.approvals;
1425
1573
  }
1426
- getProfile(id, signal) {
1427
- return this.request("GET", `/v1/profiles/${enc(id)}`, void 0, { signal });
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);
1428
1577
  }
1429
- createProfile(body) {
1430
- return this.request("POST", "/v1/profiles", body);
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 });
1431
1584
  }
1432
- updateProfile(id, body) {
1433
- return this.request("PATCH", `/v1/profiles/${enc(id)}`, body);
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);
1434
1588
  }
1435
- deleteProfile(id) {
1436
- return this.request("DELETE", `/v1/profiles/${enc(id)}`);
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
+ });
1437
1594
  }
1438
- /** Start a profile → CDP ws endpoint. Errors: 4002/4003/4005/4006/4008. */
1439
- startProfile(id, body = {}) {
1440
- return this.request("POST", `/v1/profiles/${enc(id)}/start`, body);
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 });
1441
1598
  }
1442
- stopProfile(id) {
1443
- return this.request("POST", `/v1/profiles/${enc(id)}/stop`, {});
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`);
1444
1602
  }
1445
- /** Drop the profile's lease, the operator's way out.
1446
- *
1447
- * An agent releases with its handle; this call needs none. The daemon stops
1448
- * the browser first when one is still up, then lets the lease go, so a dead
1449
- * session cannot park the profile until its TTL runs out. `released: false`
1450
- * is an honest no-op: there was nothing to let go. */
1451
- releaseProfile(id) {
1452
- return this.request("POST", `/v1/profiles/${enc(id)}/release`, {});
1603
+ /**
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`);
1453
1611
  }
1454
- /** Ask for a profile that is open on another machine of this account.
1455
- *
1456
- * Closes nothing here and nothing there: the control plane revokes the holder's
1457
- * right, the holder closes its own browser at its next heartbeat. Start only
1458
- * after this answered `free`. Errors: 4012 when it is held elsewhere. */
1459
- takeoverProfile(id) {
1460
- return this.request("POST", `/v1/profiles/${enc(id)}/takeover`, {});
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);
1461
1621
  }
1462
- // ── Bulk (PRD §D2) ───────────────────────────────────────────────────────
1463
- bulkCreateProfiles(body) {
1464
- return this.request("POST", "/v1/bulk/profiles", body);
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);
1465
1625
  }
1466
1626
  /**
1467
- * Start a batch. `headless` is the ONE visibility decision for the run; omitted
1468
- * means headless, the right default for an unattended client. The daemon stops at
1469
- * the machine's capacity limit and reports how far it got (`started` /
1470
- * `remaining` / `stopped_reason`) instead of failing every remaining id.
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.
1471
1629
  */
1472
- bulkStart(ids, headless) {
1473
- return this.request("POST", "/v1/bulk/start", { ids, headless });
1630
+ forkWorkflowRun(runId, body) {
1631
+ return this.request("POST", `/v1/workflow-runs/${enc(runId)}/fork`, body);
1474
1632
  }
1475
- bulkStop(ids) {
1476
- return this.request("POST", "/v1/bulk/stop", { ids });
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
+ });
1477
1639
  }
1478
- bulkDelete(ids) {
1479
- return this.request("POST", "/v1/bulk/delete", { ids });
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 });
1480
1643
  }
1481
- bulkAssignProxy(ids, proxyId) {
1482
- return this.request("POST", "/v1/bulk/assign-proxy", { ids, proxy_id: proxyId });
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 });
1483
1658
  }
1484
1659
  /**
1485
- * Give every id exactly this set of extensions.
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.
1486
1778
  *
1487
- * It REPLACES rather than adds, the same shape as assigning a proxy: picking a
1488
- * set for a batch states what those profiles carry. An empty list is a
1489
- * legitimate "none". An id the library does not hold refuses the whole call.
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).
1490
1782
  */
1491
- bulkAssignExtensions(ids, extRefs) {
1492
- return this.request("POST", "/v1/bulk/assign-extensions", { ids, ext_refs: extRefs });
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
+ });
1493
1788
  }
1494
- // ── Groups & presets ───────────────────────────────────────────────────────
1495
- listGroups(signal) {
1496
- return this.request("GET", "/v1/groups", void 0, { signal });
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 });
1497
1798
  }
1498
- getGroup(id, signal) {
1499
- return this.request("GET", `/v1/groups/${enc(id)}`, void 0, { signal });
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`);
1500
1805
  }
1501
- createGroup(body) {
1502
- return this.request("POST", "/v1/groups", body);
1806
+ /** The ready-made starting points. */
1807
+ workflowTemplates(signal) {
1808
+ return this.request("GET", "/v1/workflow-templates", void 0, { signal });
1503
1809
  }
1504
- updateGroup(id, body) {
1505
- return this.request("PATCH", `/v1/groups/${enc(id)}`, body);
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
+ );
1506
1817
  }
1507
- deleteGroup(id) {
1508
- return this.request("DELETE", `/v1/groups/${enc(id)}`);
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 });
1509
1829
  }
1510
- listPresets(signal) {
1511
- return this.request("GET", "/v1/presets", void 0, { signal });
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);
1512
1840
  }
1513
- getPreset(id, signal) {
1514
- return this.request("GET", `/v1/presets/${enc(id)}`, void 0, { signal });
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;
1515
1845
  }
1516
- createPreset(body) {
1517
- return this.request("POST", "/v1/presets", body);
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");
1518
1934
  }
1519
- updatePreset(id, body) {
1520
- return this.request("PATCH", `/v1/presets/${enc(id)}`, body);
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
+ });
1521
1961
  }
1522
- deletePreset(id) {
1523
- return this.request("DELETE", `/v1/presets/${enc(id)}`);
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(/^ /, ""));
1524
1974
  }
1525
- // ── Video presets ──────────────────────────────────────────────────────────
1526
- listVideoPresets(signal) {
1527
- return this.request("GET", "/v1/video-presets", void 0, { signal });
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;
1528
1982
  }
1529
- getVideoPreset(id, signal) {
1530
- return this.request("GET", `/v1/video-presets/${enc(id)}`, void 0, { signal });
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)));
1531
2046
  }
1532
- /** The daemon validates `config` strictly and names the failing field path. */
1533
- createVideoPreset(body) {
1534
- return this.request("POST", "/v1/video-presets", body);
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
+ });
1535
2062
  }
1536
- /** A built-in preset refuses edits. Duplicate it and edit the copy. */
1537
- updateVideoPreset(id, body) {
1538
- return this.request("PATCH", `/v1/video-presets/${enc(id)}`, body);
2063
+ subscribe(cb) {
2064
+ this.#subscribers.add(cb);
2065
+ return () => this.#subscribers.delete(cb);
1539
2066
  }
1540
- /** The only way to make a built-in preset yours: copy, then edit the copy. */
1541
- duplicateVideoPreset(id, body = {}) {
1542
- return this.request("POST", `/v1/video-presets/${enc(id)}/duplicate`, body);
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);
1543
2077
  }
1544
- deleteVideoPreset(id) {
1545
- return this.request("DELETE", `/v1/video-presets/${enc(id)}`);
2078
+ close() {
2079
+ this.#ws.close();
1546
2080
  }
1547
- /** One still of the sample film under an UNSAVED config, drawn by the daemon's own renderer.
1548
- * `moment` wins over `frame`; both absent means the daemon's default moment. */
1549
- previewVideoPreset(body, signal) {
1550
- return this.request("POST", "/v1/video-presets/preview", body, { signal });
2081
+ get closed() {
2082
+ return this.#closeReason !== null;
1551
2083
  }
1552
- /** A clip of the sample film, blocking until it is encoded (the editor uses the SSE form of the
1553
- * same route; a script waits). Fetch the bytes with `downloadVideoPresetClip`. */
1554
- previewVideoPresetClip(body, signal) {
1555
- return this.request("POST", "/v1/video-presets/preview/clip", body, { signal });
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
+ }
1556
2103
  }
1557
- /** The clip's MP4 bytes. */
1558
- downloadVideoPresetClip(id, signal) {
1559
- return this.requestBytes("GET", `/v1/video-presets/preview/clip/${enc(id)}`, { signal });
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();
1560
2112
  }
1561
- /**
1562
- * The values a preset's `constraints` may take. Ask rather than hardcode: the
1563
- * region list comes from the daemon's embedded persona model, so a pinned copy
1564
- * drifts the moment that model changes and every create 400s.
1565
- */
1566
- getPersonaConstraints(signal) {
1567
- return this.request(
1568
- "GET",
1569
- "/v1/persona/constraints",
1570
- void 0,
1571
- { signal }
1572
- );
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;
1573
2132
  }
1574
- // ── Proxies (credentials write-only) ────────────────────────────────────────
1575
- /** The list carries `used_by` per row; `getProxy` below does not. */
1576
- listProxies(signal) {
1577
- 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);
1578
2136
  }
1579
- getProxy(id, signal) {
1580
- return this.request("GET", `/v1/proxies/${enc(id)}`, void 0, { signal });
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
+ });
1581
2142
  }
1582
- createProxy(body) {
1583
- return this.request("POST", "/v1/proxies", body);
2143
+ /** `for await (const event of session.events())` over this session's CDP events. */
2144
+ events() {
2145
+ return scopedEventStream(this.#conn, this.sessionId);
1584
2146
  }
1585
- updateProxy(id, body) {
1586
- return this.request("PATCH", `/v1/proxies/${enc(id)}`, body);
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);
1587
2165
  }
1588
- deleteProxy(id) {
1589
- return this.request("DELETE", `/v1/proxies/${enc(id)}`);
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;
1590
2172
  }
1591
- /** Health + geo check (exit-ip/country/healthy + JA4↔JA4T verdict). */
1592
- checkProxy(id) {
1593
- return this.request("POST", `/v1/proxies/${enc(id)}/check`, {});
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;
1594
2186
  }
1595
2187
  /**
1596
- * Probe a proxy config WITHOUT persisting it: validate before you commit.
1597
- * Pass `id` (and omit the credentials) to probe an existing proxy's stored,
1598
- * write-only credentials in an edit form.
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.
1599
2194
  */
1600
- checkProxyConfig(body) {
1601
- return this.request("POST", "/v1/proxies/check", body);
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;
1602
2207
  }
1603
- // ── Live detector audit ─────────────────────────────────────────────────────
1604
- //
1605
- // Drives the profile's OWN running browser through ~15 third-party fingerprint
1606
- // sites and keeps what each one saw. The profile must be RUNNING; the run takes
1607
- // minutes, so `startAudit` returns immediately and you poll `getAudit`.
1608
- /** Queue a run → the status right after queueing. `409` if not running / already running. */
1609
- startAudit(profileId) {
1610
- 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 });
1611
2211
  }
1612
- /** State plus the last stored report. */
1613
- getAudit(profileId, signal) {
1614
- return this.request("GET", `/v1/profiles/${enc(profileId)}/audit`, void 0, {
1615
- signal
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
1616
2220
  });
1617
2221
  }
1618
- // ── Exit-address exclusivity ────────────────────────────────────────────────
1619
- /** Which exit addresses this profile owns, and how far the rule reaches.
1620
- *
1621
- * `scope` is `'machine'` while this computer has no account key. That is the
1622
- * ordinary state of a second machine until sync is unlocked there once, and it is
1623
- * reported rather than hidden: believing the rule spans three machines when it
1624
- * spans one is worse than knowing. */
1625
- getExitStatus(profileId, signal) {
1626
- return this.request("GET", `/v1/profiles/${enc(profileId)}/exit`, void 0, {
1627
- signal
1628
- });
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 });
1629
2229
  }
1630
- // ── Session bundles ─────────────────────────────────────────────────────────
1631
- exportSession(profileId, body) {
1632
- return this.request("POST", `/v1/profiles/${enc(profileId)}/session/export`, body);
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 });
1633
2233
  }
1634
- importSession(profileId, body) {
1635
- return this.request("POST", `/v1/profiles/${enc(profileId)}/session/import`, body);
2234
+ humanizeType(text) {
2235
+ return this.#input({ action: "type", text });
1636
2236
  }
1637
- // ── Trusted input ──────────────────────────────────────────────────────────
1638
- sendInput(profileId, body) {
1639
- return this.request("POST", `/v1/profiles/${enc(profileId)}/input`, body);
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
+ }
1640
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 {
1641
2348
  // ── Metrics (with graceful fallback) ────────────────────────────────────────
1642
2349
  async getMetrics(signal) {
1643
2350
  try {
@@ -1761,22 +2468,34 @@ function deriveMetricsFromProfiles(profiles) {
1761
2468
  };
1762
2469
  }
1763
2470
  applyMixins(ScalebrowserClient, [
2471
+ ProfilesApi,
2472
+ PresetsApi,
2473
+ ProxiesApi,
1764
2474
  IdentityApi,
1765
2475
  RunsApi,
1766
2476
  VideosApi,
1767
2477
  ControlApi,
1768
2478
  ExtensionsApi,
1769
- TasksApi
2479
+ TasksApi,
2480
+ WorkflowsApi,
2481
+ WorkflowRunsApi,
2482
+ WorkflowAiApi,
2483
+ WorkflowSyncApi,
2484
+ WorkflowSharesApi,
2485
+ WorkflowAgencyApi,
2486
+ TablesApi
1770
2487
  ]);
1771
2488
 
2489
+ // src/types-proxies.ts
2490
+ var PROXY_KINDS = ["http", "socks5", "gateway"];
2491
+ var ROTATIONS = ["sticky", "rotating"];
2492
+
1772
2493
  // src/types.ts
1773
2494
  var RUNTIME_STATES = ["stopped", "starting", "running", "crashed"];
1774
2495
  var GEO_MODES = ["strict_expected", "follow_exit", "off"];
1775
- var PROXY_KINDS = ["http", "socks5", "gateway"];
1776
- var ROTATIONS = ["sticky", "rotating"];
1777
2496
 
1778
2497
  // src/index.ts
1779
- var VERSION = "1.2.0";
2498
+ var VERSION = "1.3.0";
1780
2499
 
1781
2500
  exports.ApiError = ApiError;
1782
2501
  exports.CdpError = CdpError;