cascade-ai 0.79.0 → 0.80.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.d.ts CHANGED
@@ -6889,6 +6889,88 @@ interface BrowserViewInfo {
6889
6889
  /** Where to watch it, when the provider can stream one. */
6890
6890
  liveViewUrl?: string;
6891
6891
  }
6892
+ /**
6893
+ * One rendered frame of a run's browser, on its way to whoever is watching.
6894
+ *
6895
+ * A JPEG rather than a video stream, and deliberately: CDP's screencast is
6896
+ * adaptive — Chrome sends a frame when the page actually changes, not on a
6897
+ * clock — so an idle page costs nothing, and there is no media pipeline to run
6898
+ * inside the deployment. It is worse than WebRTC for video-heavy pages and
6899
+ * better than it for everything else this feature is pointed at.
6900
+ */
6901
+ interface BrowserFrame {
6902
+ /** base64 JPEG, as CDP hands it over. Never decoded on the way through. */
6903
+ data: string;
6904
+ /** The remote viewport, so a canvas can size itself without guessing. */
6905
+ width: number;
6906
+ height: number;
6907
+ /**
6908
+ * Which watch this frame belongs to. See `watchGen`.
6909
+ *
6910
+ * Travels with the picture so the receipt the client sends back names the
6911
+ * watch it actually saw, rather than whichever one is current by the time it
6912
+ * arrives.
6913
+ */
6914
+ generation: number;
6915
+ }
6916
+ /** Who is driving a run's browser, and whether it is being pictured. */
6917
+ interface BrowserControlState {
6918
+ /** True while a person holds it and the agent is being refused. */
6919
+ human: boolean;
6920
+ /** Whether frames are being produced right now. See `setCapture`. */
6921
+ capturing: boolean;
6922
+ /**
6923
+ * Whether THIS watch has confirmed receiving a picture. See `seenGen`.
6924
+ *
6925
+ * Pushed rather than inferred, for the same reason ownership is: the client
6926
+ * cannot work it out while the picture is off, because it is the frames that
6927
+ * would tell it. A client left to guess would guess from what it remembers of
6928
+ * a previous watch, which is exactly the state this distinguishes.
6929
+ */
6930
+ confirmed: boolean;
6931
+ }
6932
+ /**
6933
+ * One thing a person did to the page while they held it.
6934
+ *
6935
+ * Coordinates are NORMALISED — 0..1 across the frame — rather than pixels, and
6936
+ * that is a boundary decision rather than a convenience. The picture the user
6937
+ * clicked is a JPEG scaled twice on its way to them: once by CDP into
6938
+ * `maxWidth`/`maxHeight`, once by the panel into whatever width the layout
6939
+ * gave it. Only this side knows the viewport those pixels came from, so only
6940
+ * this side can turn a click back into a page coordinate. A client sending
6941
+ * pixels would have to reconstruct both scalings and would silently miss by a
6942
+ * few pixels whenever it got one wrong — which, on a page of small controls, is
6943
+ * a click on the wrong thing.
6944
+ *
6945
+ * Typing is `text` rather than a stream of key events because `Input.insertText`
6946
+ * puts the whole string in at once: no IME to emulate, no per-character key
6947
+ * codes to get wrong for anything but a US layout, and no chance of a password
6948
+ * arriving one keystroke per socket message. `key` covers the keys that are
6949
+ * commands rather than characters, from a fixed list — see `KEYS`.
6950
+ */
6951
+ type BrowserInput = {
6952
+ kind: 'move';
6953
+ x: number;
6954
+ y: number;
6955
+ } | {
6956
+ kind: 'click';
6957
+ x: number;
6958
+ y: number;
6959
+ button?: 'left' | 'right' | 'middle';
6960
+ clicks?: number;
6961
+ } | {
6962
+ kind: 'scroll';
6963
+ x: number;
6964
+ y: number;
6965
+ deltaY: number;
6966
+ } | {
6967
+ kind: 'text';
6968
+ text: string;
6969
+ } | {
6970
+ kind: 'key';
6971
+ key: string;
6972
+ modifiers?: Array<'Control' | 'Meta' | 'Shift'>;
6973
+ };
6892
6974
  interface RemoteBrowserControllerOptions {
6893
6975
  provider: RemoteBrowserProvider;
6894
6976
  /**
@@ -6898,6 +6980,25 @@ interface RemoteBrowserControllerOptions {
6898
6980
  maxSessions?: number;
6899
6981
  /** Told when a run's live view becomes available, so the owner can watch. */
6900
6982
  onLiveView?: (runId: string, liveViewUrl: string | undefined) => void;
6983
+ /**
6984
+ * Something that must finish before this controller may open anything.
6985
+ *
6986
+ * For ROTATION. A settings change builds a new controller and disposes the
6987
+ * old one, and disposal is not instant: it detaches CDP sessions and hands
6988
+ * provider sessions back over the network. Installing the replacement
6989
+ * immediately meant the first action after a rotation could call
6990
+ * `createSession` while the previous controller was still releasing — two
6991
+ * controllers holding sessions against one provider's cap, which the pool
6992
+ * here cannot see because it counts only its own. On a provider that
6993
+ * enforces its own limit that action simply fails, and it is the first one
6994
+ * after an operator changed a setting, which is the worst moment for it.
6995
+ *
6996
+ * Awaited once, before the pool slot is reserved, and never awaited again.
6997
+ * A rejection is ignored on purpose: the old controller failing to tidy up
6998
+ * is not a reason to refuse the new one work, and `dispose` already reports
6999
+ * its own trouble.
7000
+ */
7001
+ ready?: Promise<unknown>;
6901
7002
  }
6902
7003
  declare class RemoteBrowserController {
6903
7004
  private provider;
@@ -6911,6 +7012,17 @@ declare class RemoteBrowserController {
6911
7012
  * bearer capability for a browser somebody else is driving.
6912
7013
  */
6913
7014
  private liveViewListeners;
7015
+ /**
7016
+ * Told when a run's browser changes hands, or stops being pictured.
7017
+ *
7018
+ * Needed because a takeover can end without anybody asking. The hold lapses
7019
+ * on its own after `HUMAN_IDLE_MS`, and a client left believing it still has
7020
+ * control would keep sending input into a lease it no longer holds — every
7021
+ * event refused, with nothing on screen saying why.
7022
+ */
7023
+ private controlListeners;
7024
+ /** What each run's listener was last told, so unchanged states stay quiet. */
7025
+ private controlAnnounced;
6914
7026
  /** An embedder that wants every run's live view, told which run each is. */
6915
7027
  private onLiveViewAll;
6916
7028
  private runs;
@@ -6967,12 +7079,46 @@ declare class RemoteBrowserController {
6967
7079
  */
6968
7080
  private leases;
6969
7081
  constructor(options: RemoteBrowserControllerOptions);
7082
+ /**
7083
+ * The predecessor's teardown, until it has been waited for once.
7084
+ *
7085
+ * Cleared as soon as it settles so the wait is not re-entered on every open
7086
+ * — and so the promise itself is not retained for the life of the process.
7087
+ */
7088
+ private ready;
7089
+ /**
7090
+ * This controller has been retired and will never open anything again.
7091
+ *
7092
+ * Stronger than "its runs were ended", and it has to be. A caller parked on
7093
+ * the `ready` gate above is invisible to `dispose()` — it holds no run and
7094
+ * has reserved no slot, because it has not got that far — so a SECOND
7095
+ * settings change, arriving while the first retirement is still settling,
7096
+ * found nothing to wait for and let the newest controller start immediately.
7097
+ * The parked caller then woke up on a controller nobody holds a reference to
7098
+ * and allocated a session against the superseded configuration, with the
7099
+ * newest controller free to allocate its own.
7100
+ *
7101
+ * Set synchronously at the top of `dispose`, so anything already waiting is
7102
+ * excluded the moment retirement begins rather than when it finishes.
7103
+ */
7104
+ private retired;
6970
7105
  private leaseFor;
6971
7106
  /** The controller to hand to `Cascade.setBrowserController`. */
6972
7107
  get controller(): (action: BrowserAction, context: BrowserActionContext) => Promise<BrowserActionOutcome>;
6973
7108
  /** Watch one run's browser. The URL never goes to any other run's listener. */
6974
7109
  onLiveViewFor(runKey: string, listener: (info: BrowserViewInfo) => void): void;
6975
7110
  offLiveViewFor(runKey: string): void;
7111
+ onControlFor(runKey: string, listener: (state: BrowserControlState) => void): void;
7112
+ offControlFor(runKey: string): void;
7113
+ /**
7114
+ * Say who has the browser, but only when the answer has changed.
7115
+ *
7116
+ * The lease reports every ownership change, and during ordinary work that is
7117
+ * one per action as workers take it and give it back. None of those are
7118
+ * interesting to a viewer — the agent had it before and has it now — and
7119
+ * emitting them would put a socket message on every click the agent makes.
7120
+ */
7121
+ private announceControl;
6976
7122
  /**
6977
7123
  * Tell a run's listener what its browser situation is.
6978
7124
  *
@@ -6995,6 +7141,184 @@ declare class RemoteBrowserController {
6995
7141
  dispose(): Promise<void>;
6996
7142
  /** A worker finished; it will never ask for the browser again. */
6997
7143
  actorEnded(actorId: string): void;
7144
+ /**
7145
+ * Start streaming this run's page to whoever is watching it.
7146
+ *
7147
+ * Nothing streams until someone asks. That is the whole reason this is a
7148
+ * method rather than something `open()` does: an unwatched run would
7149
+ * otherwise pay to encode frames nobody sees, on every run, forever — and on
7150
+ * a metered provider it would pay for the bandwidth too.
7151
+ *
7152
+ * Frames are ACKED after they are handed on, never before. Chrome sends the
7153
+ * next frame only once the previous is acknowledged, so this bounds it to one
7154
+ * outstanding frame against OUR OWN handling. It does not reach further than
7155
+ * that, and an earlier version of this comment claimed it did: `onFrame` ends
7156
+ * at a socket emit, which hands the JPEG to a transport rather than to a
7157
+ * viewer, so the ack says nothing about what the person actually received.
7158
+ * Bounding the rest of the path is the transport's job — see `emitFrame`,
7159
+ * where frames go out lossy so a slow connection drops pictures instead of
7160
+ * banking stale ones. Dropping the ack stops the stream dead, which is why it
7161
+ * is best-effort but unconditional.
7162
+ *
7163
+ * Returns false when there is nothing to watch — the run has no browser, or
7164
+ * it is already being watched. Callers use that to avoid promising a viewer
7165
+ * a stream that will never arrive.
7166
+ */
7167
+ startWatching(runId: string, onFrame: (frame: BrowserFrame) => void): Promise<boolean>;
7168
+ /**
7169
+ * Run one watch or unwatch after every one already asked for.
7170
+ *
7171
+ * The chain is kept non-rejecting on purpose: a failed attach must not poison
7172
+ * every later request for this run, which is what a bare `.then` chain would
7173
+ * do. The caller still sees its own failure, because that is the promise
7174
+ * returned rather than the one stored.
7175
+ */
7176
+ private queueWatch;
7177
+ /**
7178
+ * Attach at most one physical CDP screencast session at a time.
7179
+ *
7180
+ * `startWatching()` already serializes watcher lifecycle through `watchQueue`,
7181
+ * but the agent's detached-hidden restore cannot join that queue: it holds the
7182
+ * action slot, while an earlier unwatch may be waiting for exactly that slot.
7183
+ * Sharing only the physical attach closes the two-session race without making
7184
+ * watcher teardown and agent mutation wait on each other in a cycle.
7185
+ *
7186
+ * A real watcher claims `onFrame` immediately, before it waits for an attach
7187
+ * already started by the agent. The lower-level attach never writes the sink,
7188
+ * so finishing an older temporary attempt cannot overwrite a newer viewer.
7189
+ */
7190
+ private attachScreencast;
7191
+ /** Open one new CDP session and start the stream when it is safe to do so. */
7192
+ private attachScreencastFresh;
7193
+ /** Nobody is watching any more: stop paying to render frames. */
7194
+ stopWatching(runId: string): Promise<void>;
7195
+ /**
7196
+ * Suspend or resume the picture without giving up control.
7197
+ *
7198
+ * The credential case, and the only reason this is separate from watching. A
7199
+ * person who has taken the page over to sign in is about to type a password
7200
+ * into a field whose contents are echoed as dots — but a password manager's
7201
+ * dropdown, a "show password" toggle, a one-time code in plain text and the
7202
+ * confirmation page afterwards are not, and all of them would otherwise be
7203
+ * encoded into frames and sent across the network.
7204
+ *
7205
+ * What this does NOT do is hide anything from the agent: it stops the
7206
+ * picture, not the page. Nothing about a suspended capture would stop a
7207
+ * `extract_text` from reading the same screen — it is the lease that stops
7208
+ * that, by refusing the agent for as long as the person holds it.
7209
+ *
7210
+ * Answers whether frames are flowing afterwards, which is what a UI needs to
7211
+ * show and is not always what was asked for: a run with nobody watching has
7212
+ * no session to suspend.
7213
+ */
7214
+ setCapture(runId: string, on: boolean): Promise<boolean>;
7215
+ /**
7216
+ * The capture transition itself, with no lease bookkeeping.
7217
+ *
7218
+ * Separate because the agent's restore in `act()` already holds the action
7219
+ * slot — taking it again there would deadlock against itself, and the whole
7220
+ * point of that call site is that it happens INSIDE the agent's turn.
7221
+ *
7222
+ * `confirmWithFrame` is used only by the agent's visibility gate. There, a
7223
+ * successful CDP command is not enough: the externally visible state remains
7224
+ * paused until a frame arrives, and the frame handler is the only code that
7225
+ * promotes it to capturing. This makes a restore timeout sticky rather than
7226
+ * a one-action refusal.
7227
+ */
7228
+ private applyCapture;
7229
+ /**
7230
+ * Wait, briefly, for Chrome to produce a frame.
7231
+ *
7232
+ * `Page.startScreencast` resolves when the command is accepted, which is not
7233
+ * when a picture exists. The agent's visibility gate — "the page must be
7234
+ * VISIBLE before anything changes it" — was therefore satisfied by a request
7235
+ * rather than by a repaint, and the agent could click while the panel was
7236
+ * still showing the page from before it was hidden, or nothing at all.
7237
+ *
7238
+ * A frame rather than a client receipt, deliberately. A receipt would prove
7239
+ * somebody SAW it, which is stronger — and would make the agent's progress
7240
+ * depend on a viewer that may not exist: this path runs after a handback or a
7241
+ * lapse, when there may be nobody watching at all, and an agent that stalls
7242
+ * because a tab was closed is a worse failure than the one being fixed. What
7243
+ * this does guarantee is ours to guarantee: the stream is producing again.
7244
+ *
7245
+ * Bounded, and the bound rests on the property rounds 14 and 15 already rely
7246
+ * on — a screencast that has just been started emits its first frame at once,
7247
+ * whatever the page is doing. If one does not arrive, the picture genuinely
7248
+ * has not come back, and the caller refuses on the same trade it already
7249
+ * makes when the restore itself fails.
7250
+ */
7251
+ private nextFrame;
7252
+ /** Whether a person is driving this run's browser right now. */
7253
+ humanHolds(runId: string): boolean;
7254
+ /**
7255
+ * Hand this run's browser to the person watching it.
7256
+ *
7257
+ * The wait is the substance. An agent action already inside Playwright cannot
7258
+ * be interrupted — `click` waits for its element to become actionable and
7259
+ * then clicks, whatever anyone decided in the meantime — so a takeover that
7260
+ * returned immediately would put the person on a page an action was still
7261
+ * about to change. Bounded by the action ceiling, because that is the longest
7262
+ * an action can legitimately take; past it something is wedged, and saying so
7263
+ * is better than a spinner that never resolves.
7264
+ *
7265
+ * Idempotent for someone who already holds it: a second click of Take control
7266
+ * just says they are still there.
7267
+ */
7268
+ takeOver(runId: string): Promise<{
7269
+ ok: boolean;
7270
+ detail?: string;
7271
+ }>;
7272
+ /** The person is done. Answers whether they were holding it at all. */
7273
+ /**
7274
+ * The viewer confirms it received a picture of this run's page.
7275
+ *
7276
+ * Reliable, one per watch, and the only thing that opens Hide. Checked
7277
+ * against the CURRENT watch: a receipt that names an older one is from a
7278
+ * viewer that has since been replaced, and vouching for its successor is the
7279
+ * reconnect hole this counter exists to close.
7280
+ */
7281
+ frameSeen(runId: string, generation: number): void;
7282
+ handBack(runId: string): boolean;
7283
+ /**
7284
+ * One thing the person did to the page.
7285
+ *
7286
+ * Authorised per event, not per session. A takeover is not a channel that
7287
+ * stays open once opened: between two clicks the run can be stopped, the hold
7288
+ * can lapse, the page can close, and each of those has to stop the NEXT
7289
+ * event rather than be noticed at the end. So every event re-checks that this
7290
+ * run is live and that the lease is still the person's, and every accepted
7291
+ * event says so by extending the hold.
7292
+ */
7293
+ input(runId: string, event: BrowserInput): Promise<{
7294
+ ok: boolean;
7295
+ detail?: string;
7296
+ }>;
7297
+ /**
7298
+ * The page's own coordinate space, measured rather than inferred.
7299
+ *
7300
+ * Cached, because a click should not cost a round trip, and invalidated by
7301
+ * the frame metadata changing shape — which arrives free with every frame. A
7302
+ * failed measurement falls back to the last good one rather than to a guess:
7303
+ * a stale viewport is off by a resize, an invented one is off by anything.
7304
+ */
7305
+ private pageViewport;
7306
+ /**
7307
+ * Turn one authorised event into CDP calls. Coordinates arrive normalised.
7308
+ *
7309
+ * A switch with a default that REFUSES, rather than a chain of ifs ending in
7310
+ * the click branch. This is a mutation boundary reached from a socket, so the
7311
+ * question is not what a well-formed event does but what a malformed one
7312
+ * does: the chain answered "clicks", which meant a version-skewed client
7313
+ * sending `{ kind: 'drag', x, y }` pressed the mouse on a real page, and a
7314
+ * kind with no coordinates at all clamped to 0 and clicked the top-left
7315
+ * corner. Unknown input has to fail closed.
7316
+ *
7317
+ * The `never` in the default is the other half: adding a member to
7318
+ * `BrowserInput` without handling it here stops compiling, so the next kind
7319
+ * cannot silently inherit whatever the last branch happened to be.
7320
+ */
7321
+ private dispatch;
6998
7322
  /** The user stopped this run. Refuses further actions and clears its queue. */
6999
7323
  stopRun(runId: string): void;
7000
7324
  /** A run ended: release its browser rather than pay for an idle session. */
@@ -7032,6 +7356,25 @@ declare class RemoteBrowserController {
7032
7356
  private open;
7033
7357
  /** The part that may fail, with the pool slot already reserved. */
7034
7358
  private openReserved;
7359
+ /** Count main-frame navigation only while this page is the run's active page. */
7360
+ private trackPageNavigation;
7361
+ /**
7362
+ * Follow a page opened by the action that just finished.
7363
+ *
7364
+ * A popup/new tab is part of the same user gesture (OAuth is the common
7365
+ * example). Keeping `held.page` and the screencast on its opener makes the
7366
+ * new page both invisible and impossible to drive. This runs while the SAME
7367
+ * action slot is still held, after the opening click/key has fully landed, so
7368
+ * no later human/agent event can slip between detecting the popup and moving
7369
+ * the view to it.
7370
+ */
7371
+ private followOpenedPage;
7372
+ /**
7373
+ * Make one live page the run's controlled/viewed page. Used in both
7374
+ * directions: into a popup opened by an action, and back to another surviving
7375
+ * page when that popup closes itself after OAuth/login completion.
7376
+ */
7377
+ private adoptPage;
7035
7378
  private perform;
7036
7379
  }
7037
7380
 
@@ -7089,7 +7432,7 @@ declare class SteelProvider implements RemoteBrowserProvider {
7089
7432
  * the capability was switched off is neither. Reporting all three as "busy"
7090
7433
  * had a model politely retrying something that would never be granted.
7091
7434
  */
7092
- type LeaseResult = 'granted' | 'busy' | 'cancelled' | 'off';
7435
+ type LeaseResult = 'granted' | 'busy' | 'cancelled' | 'off' | 'human';
7093
7436
  interface BrowserLeaseOptions {
7094
7437
  /**
7095
7438
  * Whether a run has been stopped. The lease skips revoked runs when handing
@@ -7118,10 +7461,65 @@ declare class BrowserLease {
7118
7461
  * took the slot may release it.
7119
7462
  */
7120
7463
  private action;
7464
+ /** Whether the current action slot represents activity by its holder. */
7465
+ private actionCountsAsHumanActivity;
7466
+ /**
7467
+ * The human action that has already consumed its one idle-deadline grace.
7468
+ * A single wedged CDP request must not look like fresh activity every two
7469
+ * minutes forever. The first deadline may yield to an event that began before
7470
+ * it; a second deadline for that SAME event becomes a pending lapse instead.
7471
+ */
7472
+ private idleGraceAction;
7473
+ /** Release the human hold as soon as this overlong action finally unwinds. */
7474
+ private idleLapseAfterAction;
7475
+ /**
7476
+ * Everyone waiting for that slot, IN THE ORDER THEY ASKED.
7477
+ *
7478
+ * A queue rather than a poll, and the ordering is the whole reason for it.
7479
+ * `acquireActionSlot` used to spin on a 25ms timer, which decides nothing
7480
+ * about who goes first: each waiter checks on its own phase, so the one that
7481
+ * asked SECOND can find the slot free a full poll ahead of the one that asked
7482
+ * first. The person types one event per keypress — `{ kind: 'text', text }`
7483
+ * carries a single character — so that reordering is not a theoretical
7484
+ * unfairness, it is "passowrd" appearing in the box.
7485
+ *
7486
+ * The slot is handed straight from `endAction` to the head of this line while
7487
+ * still synchronous, so nothing can slip in between the two, and a waiter
7488
+ * that reaches the front never has to be told the slot is already taken.
7489
+ */
7490
+ private actionQueue;
7491
+ /** Lapses a human hold nobody is using. See `HUMAN_IDLE_MS`. */
7492
+ private humanTimer;
7493
+ /**
7494
+ * The person ASKED for the hold to end and it could not end yet.
7495
+ *
7496
+ * Kept as a request rather than only a retry timer, because the retry shares
7497
+ * `humanTimer` with the idle deadline: an authorised event settling after the
7498
+ * request would otherwise call `touch()`, re-arm that timer for a full idle
7499
+ * interval, and quietly cancel a handback the person had already asked for.
7500
+ * "Give it back" is not undone by activity that was already under way when
7501
+ * they said it.
7502
+ *
7503
+ * Explicit requests ONLY. An idle expiry must never set this: a deadline that
7504
+ * lands on the person's own in-flight event is evidence they were THERE, and
7505
+ * recording it here made `touch()` bail afterwards, so the hold dropped the
7506
+ * instant a fresh interaction finished. See `lapse()`.
7507
+ */
7508
+ private handBackWanted;
7121
7509
  private isRevoked;
7122
7510
  private onChange;
7123
7511
  constructor(options?: BrowserLeaseOptions);
7124
7512
  get holderActor(): string | null;
7513
+ /** Whether a person, rather than the agent, is driving the page right now. */
7514
+ get heldByHuman(): boolean;
7515
+ /**
7516
+ * Whether THIS actor is the one holding the browser right now.
7517
+ *
7518
+ * For asking again after a wait. `acquire` is re-entrant for the holder, so
7519
+ * "I was granted the lease" is a fact about the moment it was granted and
7520
+ * says nothing about the moment the caller finally gets to act.
7521
+ */
7522
+ heldBy(actorId: string): boolean;
7125
7523
  get holderSession(): string | null;
7126
7524
  get queueDepth(): number;
7127
7525
  get actionInFlight(): boolean;
@@ -7160,6 +7558,57 @@ declare class BrowserLease {
7160
7558
  * refusal path runs a Stop may already have handed the lease on.
7161
7559
  */
7162
7560
  releaseIfHeldBy(actorId: string): void;
7561
+ /**
7562
+ * Give the browser to the person watching it.
7563
+ *
7564
+ * Callers must have waited the in-flight action out first — see
7565
+ * `acquireActionSlot`. This does not interrupt one, because it cannot: a
7566
+ * Playwright call already inside the page finishes whatever it started, and
7567
+ * taking the lease off it would only mean the person and a still-running
7568
+ * `fill` were both touching the same form. Waiting is what makes "you have
7569
+ * control" true when the UI says it.
7570
+ *
7571
+ * Every queued worker is turned away rather than left in line, for the same
7572
+ * reason `acquire` refuses: they were planned against a page the person is
7573
+ * about to change.
7574
+ */
7575
+ takeOver(sessionId: string): void;
7576
+ /**
7577
+ * The person is still there — anything they did counts.
7578
+ *
7579
+ * Called per authorised input rather than on a heartbeat, so the hold is
7580
+ * extended by USE and not merely by a tab being open. A left-open panel on a
7581
+ * forgotten laptop stops holding a billed session two minutes later.
7582
+ */
7583
+ touch(): void;
7584
+ /** (Re)start the idle interval. The only place the deadline is set. */
7585
+ private armIdle;
7586
+ /**
7587
+ * The idle deadline came round.
7588
+ *
7589
+ * Both ways a hold ends obey the same rule — never while one of the person's
7590
+ * own events is still landing — but they resolve that clash in OPPOSITE
7591
+ * directions, and routing the lapse through `handBack()` collapsed them into
7592
+ * one. An event in flight BEGAN before this deadline, which makes it evidence
7593
+ * the person was there; deferring the lapse and then releasing the moment
7594
+ * that event lands ends the hold immediately after a fresh interaction, which
7595
+ * is the precise opposite of what an idle deadline measures. So an
7596
+ * interrupted lapse yields: the interval starts again, and the next silence
7597
+ * decides.
7598
+ *
7599
+ * `handBack()` keeps the deferral instead, because "Give it back" is a
7600
+ * decision and activity already under way when it was made does not withdraw
7601
+ * it. Same rule, different answer, which is why they are different methods.
7602
+ */
7603
+ private lapse;
7604
+ /**
7605
+ * The person hands the browser back, or their hold lapses.
7606
+ *
7607
+ * Answers whether there was a human hold to end, so a caller can tell a real
7608
+ * handback from a duplicate click or a lapse that already happened.
7609
+ */
7610
+ handBack(): boolean;
7611
+ private clearHumanIdle;
7163
7612
  /** Drop every queued waiter belonging to a run, and the lease if it holds it. */
7164
7613
  dropRun(sessionId: string): void;
7165
7614
  /** Turn everyone away — the capability itself has gone. */
@@ -7169,19 +7618,67 @@ declare class BrowserLease {
7169
7618
  /** Arm the deadlock ceiling. Not a release schedule — see the constant. */
7170
7619
  armCeiling(): void;
7171
7620
  clearCeiling(): void;
7172
- /** Take the per-action slot, or null when one is already running. */
7173
- beginAction(): symbol | null;
7174
- /** Release the slot, but only for the action that took it. */
7621
+ /**
7622
+ * Take the per-action slot, or null when one is already running.
7623
+ *
7624
+ * PRIVATE, so the queue is the only way in. A caller that could take the slot
7625
+ * without joining the line would be exactly the jump-the-queue the ordering
7626
+ * is there to prevent.
7627
+ */
7628
+ private beginAction;
7629
+ /**
7630
+ * Release the slot, but only for the action that took it.
7631
+ *
7632
+ * Hands it to the head of the line rather than merely clearing it, and does
7633
+ * so SYNCHRONOUSLY: the waiter's `beginAction` runs before this call returns,
7634
+ * so there is no window in which the slot is free and somebody who asked
7635
+ * later can take it.
7636
+ */
7175
7637
  endAction(token: symbol): boolean;
7176
7638
  /**
7177
- * Wait, briefly, for an outgoing action to unwind.
7639
+ * Take the slot only if it is free RIGHT NOW, never joining the line.
7640
+ *
7641
+ * For input that is a SAMPLE rather than a decision — pointer movement. A
7642
+ * click or a keystroke is a thing the person meant to do and has to happen,
7643
+ * so it waits its turn; a pointer position is one of many on the way
7644
+ * somewhere, and one that cannot be applied now is worth less than the one
7645
+ * behind it. Queueing them is actively harmful: on an endpoint slower than
7646
+ * the client's sampling interval the backlog grows, and the click behind it
7647
+ * can age out against `acquireActionSlot`'s bound and be refused — movement
7648
+ * costing the person the action they actually intended.
7649
+ *
7650
+ * The queue length is checked as well as the slot, so a sample cannot step
7651
+ * over a click that is already waiting.
7652
+ */
7653
+ tryActionSlot(): symbol | null;
7654
+ /**
7655
+ * Take the per-action slot, waiting in line for it if somebody has it.
7178
7656
  *
7179
7657
  * A release can hand the browser on while the previous holder's abort is
7180
7658
  * still propagating through an awaited navigation. That is a handoff, not a
7181
- * conflict, so it is waited out rather than refused — but bounded, because a
7182
- * wedged action must not pin the queue.
7183
- */
7184
- awaitActionSlot(): Promise<boolean>;
7659
+ * conflict, so it is normally bounded: a wedged action must not pin an agent
7660
+ * or a takeover forever. Human discrete input is the exception and passes
7661
+ * `null`: once a click, key or committed text has been accepted into this
7662
+ * ordered queue, expiring it merely because earlier accepted input took more
7663
+ * than two seconds silently truncates what the person typed.
7664
+ *
7665
+ * Waiting and TAKING are one step, which they deliberately were not before:
7666
+ * the wait used to answer "the slot looks free" and leave the caller to call
7667
+ * `beginAction` afterwards. Two callers woken by the same release both saw it
7668
+ * free, and the loser was told "another action is already running" — a
7669
+ * refusal for having asked first. Granting it here means whoever reaches the
7670
+ * front of the line gets it, and everybody else is still waiting rather than
7671
+ * refused.
7672
+ *
7673
+ * `null` as a RESULT means a bounded wait ran out OR a caller-supplied queue
7674
+ * cap refused a new waiter. `null` as `withinMs` means an ACCEPTED operation
7675
+ * is intentionally unbounded by time and will leave the queue only when its
7676
+ * turn arrives; it does not require accepting infinitely many operations.
7677
+ * `countsAsHumanActivity=false` is for
7678
+ * lifecycle barriers: they still serialize, but an idle deadline must not
7679
+ * mistake framework cleanup for evidence that the person is present.
7680
+ */
7681
+ acquireActionSlot(withinMs?: number | null, countsAsHumanActivity?: boolean, maxQueued?: number | null): Promise<symbol | null>;
7185
7682
  /**
7186
7683
  * Queue one actor, resolving when it gets the browser or is turned away.
7187
7684
  *
@@ -8316,4 +8813,4 @@ declare function gatherSyncBundle(config: CascadeConfig): SyncBundle;
8316
8813
  /** Merge a pulled bundle into a config, returning the updated config to persist. */
8317
8814
  declare function applySyncBundle(bundle: SyncBundle, config: CascadeConfig, cleanup?: RetiredProviderCleanup): CascadeConfig;
8318
8815
 
8319
- export { AZURE_BASE_MODELS, AZURE_BASE_URL_TEMPLATE, type AcceptanceOptions, type AcceptanceProbe, type AcceptanceResult, type AcceptanceVerdict, type ApprovalRequest, type ApprovalResponse, type AuditEntry, AuditLogger, type AzureDeploymentInput, type BenchmarksConfig, type Block, type BrowserAction, type BrowserActionOutcome, BrowserControlTool, type BrowserController, BrowserLease, type BudgetConfig, CASCADE_AUDIT_FILE, CASCADE_CONFIG_DIR, CASCADE_CONFIG_FILE, CASCADE_DASHBOARD_SECRET_FILE, CASCADE_DB_FILE, CASCADE_IGNORE_FILE, CASCADE_KEYSTORE_FILE, CASCADE_MD_FILE, CASCADE_VERSION, CHARS_PER_TOKEN, COMPLEXITY_T2_COUNT, Cascade, CascadeCancelledError, type CascadeConfig, CascadeConfigSchema, type CascadeEvent, type CascadeEventType, CascadeIgnore, type CascadeMessage, CascadeRouter, type CascadeRunOptions, type CascadeRunResult, type CascadeThemeName, CascadeToolError, type ChartSeries, type ChartSpec, type Chunk, type ChunkOptions, CloudClient, type CloudConversation, type CloudMessage, type CloudSession, type CloudSessionStore, type CloudTurnInput, type CloudUser, type CodeChunkOptions, type CodeChunker, CodeSearchTool, type CompileTaskGraphOptions, type CompiledTaskGraph, type CompleteFn, type CompletedNode, ConfigManager, type ConversationMessage, type CredentialDisposition, type CredentialEndpoint, type CredentialWriteOutcome, type CurrentPageProvider, type CurrentPageSnapshot, CurrentPageTool, DEFAULT_API_PORT, DEFAULT_APPROVAL_REQUIRED, DEFAULT_AUTO_SUMMARIZE_AT, DEFAULT_CLOUD_URL, DEFAULT_CONTEXT_LIMIT, DEFAULT_DASHBOARD_PORT, DEFAULT_MAX_SESSION_MESSAGES, DEFAULT_RETENTION_DAYS, DEFAULT_THEME, DOCUMENT_MIME, type DashboardConfig, DashboardServer, DependencyScheduler, type DeviceStart, type DiscoveredMcpTool, type DistilledFact, type ChartKind as DocumentChartKind, type DocumentFormat, type Embedder, type EncryptedBlob, type EscalationDecision, type EscalationPayload, type ExtendedContextConfig, type FileManifest, FileMcpOAuthStore, GLOBAL_CONFIG_DIR, GLOBAL_CREDENTIALS_FILE, GLOBAL_DB_FILE, GLOBAL_KEYSTORE_FILE, GLOBAL_RUNTIME_DB_FILE, GenerateDocumentTool, type GenerateOptions, type GenerateResult, GenericCdpProvider, type GraphFactSource, GraphRetriever, type GraphSearchOptions, GraphSearchTool, type HookDefinition, type HooksConfig, HooksRunner, type Identity, type ImageAttachment, type ImageByteLoader, type ImageInfo, type ImageRef, type InlineRun, Keystore, LLMReranker, LM_STUDIO_BASE_URL, type LegacyThemeName, type LoadedImage, MAX_PAGE_TEXT_CHARS, MCP_TOOL_PREFIX, MODELS, type ManifestDiff, McpClient, type McpDiscoveryResult, McpOAuthProvider, type McpOAuthState, type McpOAuthStore, type McpServerConfig$1 as McpServerConfig, type McpServerRename, type MemoryConfig, MemoryStore, type Message, type MessageContent, type MessagePayload, type MessageStatus, type MessageType, type ModelInfo, type ModelOverrides, type NativeProvider, OLLAMA_BASE_URL, OpenAICompatibleEmbedder, type OpenAIEmbedderOptions, PROVIDER_DISPLAY_NAMES, type PeerMessage, type PeerMessageEvent, type PeerSyncPayload, type PeerSyncType, type PermissionDecision, type PermissionDecisionPayload, type PermissionRequest, type PermissionTrailEntry, type PlanReviewConfig, type ProviderConfig, type ProviderType, RESUME_SCHEMA_VERSION, type RankedFact, type RefreshResult, type RemoteBrowserConfig, RemoteBrowserController, type RemoteBrowserProvider, type RemoteBrowserSession, type RenderOptions, type Reranker, type ResumeCheckpoint, type ResumeReason, ResumeStore, type ResumeStoreOptions, type RetrievalContext, type RetrievalMode, type RetrievalPlan, Retriever, type RetrieverSearchOptions, type RuntimeNode, type RuntimeNodeLog, type RuntimeRefreshPayload, type RuntimeScope, type RuntimeSession, type RuntimeSnapshotPayload, type ScheduledTask, type SchedulerExecutionMode, type SchedulerHooks, type SchedulerOptions, type SchedulerResult, type ScoredChunk, type SearchOptions, type Session, type SessionCheckpoint, type SessionMetadata, type SessionSubscriptionPayload, type SettingsCommitResult, type SettingsCredentialResult, type SettingsPayload, type SettingsSnapshot, type Slide, SqliteVectorStore, type StatusUpdate, SteelProvider, type StoredMessage, type StreamChunk, type SyncBundle, T1Administrator, type T1ToT2Assignment, T1_MODEL_PRIORITY, T2Manager, type T2Result, type T2ToT3Assignment, T2_MODEL_PRIORITY, type T3Result, type T3ResultPayload, type T3SubtaskSpec, T3Worker, T3_MODEL_PRIORITY, THEME_NAMES, TOOL_NAMES, type TaskComplexity, type TaskGraph, type TaskGraphInputNode, type TaskGraphIssue, type TaskGraphIssueCode, type TaskGraphNode, type TaskGraphNodeKind, TaskGraphValidationError, type TaskGraphValidationMode, TaskScheduler, type TaskType, Telemetry, type TelemetryConfig, type Theme, type ThemeColors, type ThemeName, type TierConfig, type TierLimits, type TierRole, type TierStatus, type TokenUsage, type ToolCall, type ToolDefinition, type ToolExecuteOptions, ToolRegistry, type ToolResult, type ToolsConfig, VISION_MODEL_PRIORITY, type VectorStore, type WebSearchConfig, type WebhookConfig, type WorkspaceConfig, type WorkspaceFileReader, WorkspaceIndex, type WorkspaceIndexOptions, applyEndpointEdit, applyProviderApiKey, applyProviderCredential, applySettingsCredentials, applySettingsPayload, applySyncBundle, azureModelForDeployment, beginMcpOAuth, buildDocumentTools, buildManifest, buildSessionTranscript, bytesToBase64, cagCharBudget, chartKind, chartToTableRows, chatCompleterFromProviders, chunkCode, chunkText, commitSettings, compileSectionGraph, compileSubtaskGraph, compileTaskGraph, completeMcpOAuth, connectMcpWithLoopbackOAuth, createCascade, credentialDispositionForEdit, credentialEndpointIdentity, decryptJSON as decryptSyncBlob, diffManifest, disambiguateMcpServerNames, discoverMcpAuthServer, discoverMcpTools, distillSessionFacts, embedderFromProviders, encryptJSON as encryptSyncBlob, endpointFromSettingsPayload, evaluateAcceptance, explainRefusal, extractCharts, failures, fileExt, fileOAuthProvider, gatherSyncBundle, hasDefaultEndpoint, hasProviderCredential, hasUsableProvider, hashContent, heuristicCodeChunker, inferAzureBaseModel, inlineRuns, isCdpEndpoint, isDocumentFormat, isMcpToolName, matchImageLine, mcpServerPrefix, mcpToolName, nodeHttpFetch, normalizeEndpoint, parseBlocks, parseChartSpec, parseDelimited, parseRankOrder, parseSlide, planRetrieval, preferIpv4Host, priorAzureRow, reciprocalRankFusion, refreshMcpToken, removeMcpServerDenials, renderDocument, renderDocx, renderPptx, renderXlsx, runCascade, sameAzureEndpoint, sameCredentialEndpoint, sameEndpoint, sessionWorthRemembering, settingsSnapshot, sniffImage, splitSlides, streamCascade, stripInline, summarizeCompleted, undecided, uniqueMcpServerName };
8816
+ export { AZURE_BASE_MODELS, AZURE_BASE_URL_TEMPLATE, type AcceptanceOptions, type AcceptanceProbe, type AcceptanceResult, type AcceptanceVerdict, type ApprovalRequest, type ApprovalResponse, type AuditEntry, AuditLogger, type AzureDeploymentInput, type BenchmarksConfig, type Block, type BrowserAction, type BrowserActionOutcome, type BrowserControlState, BrowserControlTool, type BrowserController, type BrowserFrame, type BrowserInput, BrowserLease, type BudgetConfig, CASCADE_AUDIT_FILE, CASCADE_CONFIG_DIR, CASCADE_CONFIG_FILE, CASCADE_DASHBOARD_SECRET_FILE, CASCADE_DB_FILE, CASCADE_IGNORE_FILE, CASCADE_KEYSTORE_FILE, CASCADE_MD_FILE, CASCADE_VERSION, CHARS_PER_TOKEN, COMPLEXITY_T2_COUNT, Cascade, CascadeCancelledError, type CascadeConfig, CascadeConfigSchema, type CascadeEvent, type CascadeEventType, CascadeIgnore, type CascadeMessage, CascadeRouter, type CascadeRunOptions, type CascadeRunResult, type CascadeThemeName, CascadeToolError, type ChartSeries, type ChartSpec, type Chunk, type ChunkOptions, CloudClient, type CloudConversation, type CloudMessage, type CloudSession, type CloudSessionStore, type CloudTurnInput, type CloudUser, type CodeChunkOptions, type CodeChunker, CodeSearchTool, type CompileTaskGraphOptions, type CompiledTaskGraph, type CompleteFn, type CompletedNode, ConfigManager, type ConversationMessage, type CredentialDisposition, type CredentialEndpoint, type CredentialWriteOutcome, type CurrentPageProvider, type CurrentPageSnapshot, CurrentPageTool, DEFAULT_API_PORT, DEFAULT_APPROVAL_REQUIRED, DEFAULT_AUTO_SUMMARIZE_AT, DEFAULT_CLOUD_URL, DEFAULT_CONTEXT_LIMIT, DEFAULT_DASHBOARD_PORT, DEFAULT_MAX_SESSION_MESSAGES, DEFAULT_RETENTION_DAYS, DEFAULT_THEME, DOCUMENT_MIME, type DashboardConfig, DashboardServer, DependencyScheduler, type DeviceStart, type DiscoveredMcpTool, type DistilledFact, type ChartKind as DocumentChartKind, type DocumentFormat, type Embedder, type EncryptedBlob, type EscalationDecision, type EscalationPayload, type ExtendedContextConfig, type FileManifest, FileMcpOAuthStore, GLOBAL_CONFIG_DIR, GLOBAL_CREDENTIALS_FILE, GLOBAL_DB_FILE, GLOBAL_KEYSTORE_FILE, GLOBAL_RUNTIME_DB_FILE, GenerateDocumentTool, type GenerateOptions, type GenerateResult, GenericCdpProvider, type GraphFactSource, GraphRetriever, type GraphSearchOptions, GraphSearchTool, type HookDefinition, type HooksConfig, HooksRunner, type Identity, type ImageAttachment, type ImageByteLoader, type ImageInfo, type ImageRef, type InlineRun, Keystore, LLMReranker, LM_STUDIO_BASE_URL, type LegacyThemeName, type LoadedImage, MAX_PAGE_TEXT_CHARS, MCP_TOOL_PREFIX, MODELS, type ManifestDiff, McpClient, type McpDiscoveryResult, McpOAuthProvider, type McpOAuthState, type McpOAuthStore, type McpServerConfig$1 as McpServerConfig, type McpServerRename, type MemoryConfig, MemoryStore, type Message, type MessageContent, type MessagePayload, type MessageStatus, type MessageType, type ModelInfo, type ModelOverrides, type NativeProvider, OLLAMA_BASE_URL, OpenAICompatibleEmbedder, type OpenAIEmbedderOptions, PROVIDER_DISPLAY_NAMES, type PeerMessage, type PeerMessageEvent, type PeerSyncPayload, type PeerSyncType, type PermissionDecision, type PermissionDecisionPayload, type PermissionRequest, type PermissionTrailEntry, type PlanReviewConfig, type ProviderConfig, type ProviderType, RESUME_SCHEMA_VERSION, type RankedFact, type RefreshResult, type RemoteBrowserConfig, RemoteBrowserController, type RemoteBrowserProvider, type RemoteBrowserSession, type RenderOptions, type Reranker, type ResumeCheckpoint, type ResumeReason, ResumeStore, type ResumeStoreOptions, type RetrievalContext, type RetrievalMode, type RetrievalPlan, Retriever, type RetrieverSearchOptions, type RuntimeNode, type RuntimeNodeLog, type RuntimeRefreshPayload, type RuntimeScope, type RuntimeSession, type RuntimeSnapshotPayload, type ScheduledTask, type SchedulerExecutionMode, type SchedulerHooks, type SchedulerOptions, type SchedulerResult, type ScoredChunk, type SearchOptions, type Session, type SessionCheckpoint, type SessionMetadata, type SessionSubscriptionPayload, type SettingsCommitResult, type SettingsCredentialResult, type SettingsPayload, type SettingsSnapshot, type Slide, SqliteVectorStore, type StatusUpdate, SteelProvider, type StoredMessage, type StreamChunk, type SyncBundle, T1Administrator, type T1ToT2Assignment, T1_MODEL_PRIORITY, T2Manager, type T2Result, type T2ToT3Assignment, T2_MODEL_PRIORITY, type T3Result, type T3ResultPayload, type T3SubtaskSpec, T3Worker, T3_MODEL_PRIORITY, THEME_NAMES, TOOL_NAMES, type TaskComplexity, type TaskGraph, type TaskGraphInputNode, type TaskGraphIssue, type TaskGraphIssueCode, type TaskGraphNode, type TaskGraphNodeKind, TaskGraphValidationError, type TaskGraphValidationMode, TaskScheduler, type TaskType, Telemetry, type TelemetryConfig, type Theme, type ThemeColors, type ThemeName, type TierConfig, type TierLimits, type TierRole, type TierStatus, type TokenUsage, type ToolCall, type ToolDefinition, type ToolExecuteOptions, ToolRegistry, type ToolResult, type ToolsConfig, VISION_MODEL_PRIORITY, type VectorStore, type WebSearchConfig, type WebhookConfig, type WorkspaceConfig, type WorkspaceFileReader, WorkspaceIndex, type WorkspaceIndexOptions, applyEndpointEdit, applyProviderApiKey, applyProviderCredential, applySettingsCredentials, applySettingsPayload, applySyncBundle, azureModelForDeployment, beginMcpOAuth, buildDocumentTools, buildManifest, buildSessionTranscript, bytesToBase64, cagCharBudget, chartKind, chartToTableRows, chatCompleterFromProviders, chunkCode, chunkText, commitSettings, compileSectionGraph, compileSubtaskGraph, compileTaskGraph, completeMcpOAuth, connectMcpWithLoopbackOAuth, createCascade, credentialDispositionForEdit, credentialEndpointIdentity, decryptJSON as decryptSyncBlob, diffManifest, disambiguateMcpServerNames, discoverMcpAuthServer, discoverMcpTools, distillSessionFacts, embedderFromProviders, encryptJSON as encryptSyncBlob, endpointFromSettingsPayload, evaluateAcceptance, explainRefusal, extractCharts, failures, fileExt, fileOAuthProvider, gatherSyncBundle, hasDefaultEndpoint, hasProviderCredential, hasUsableProvider, hashContent, heuristicCodeChunker, inferAzureBaseModel, inlineRuns, isCdpEndpoint, isDocumentFormat, isMcpToolName, matchImageLine, mcpServerPrefix, mcpToolName, nodeHttpFetch, normalizeEndpoint, parseBlocks, parseChartSpec, parseDelimited, parseRankOrder, parseSlide, planRetrieval, preferIpv4Host, priorAzureRow, reciprocalRankFusion, refreshMcpToken, removeMcpServerDenials, renderDocument, renderDocx, renderPptx, renderXlsx, runCascade, sameAzureEndpoint, sameCredentialEndpoint, sameEndpoint, sessionWorthRemembering, settingsSnapshot, sniffImage, splitSlides, streamCascade, stripInline, summarizeCompleted, undecided, uniqueMcpServerName };