@oya-ai/cli 1.0.242 → 1.0.244

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.
Files changed (2) hide show
  1. package/dist/index.js +28 -5
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -3129,7 +3129,7 @@ function saveKey(apiKey, baseUrl) {
3129
3129
  return true;
3130
3130
  }
3131
3131
  var OPTIONS_ORIGIN = { apiKeyFrom: "the apiKey option", baseUrlFrom: "the baseUrl option", savedKey: false };
3132
- var Http = class {
3132
+ var Http = class _Http {
3133
3133
  /** Stores where to call, with which key, how long to wait, which fetch to use, and where the key and address came from. */
3134
3134
  constructor(baseUrl, apiKey, timeoutMs, fetchImpl, origin3 = OPTIONS_ORIGIN, defaults = {}) {
3135
3135
  this.baseUrl = baseUrl;
@@ -3145,6 +3145,14 @@ var Http = class {
3145
3145
  fetchImpl;
3146
3146
  origin;
3147
3147
  defaults;
3148
+ /**
3149
+ * The same client with `headers` on every request it sends. A browser that shares a person's
3150
+ * desktop names its lane this way once, so no call it makes can leave the lane out.
3151
+ */
3152
+ withHeaders(headers) {
3153
+ const merged = { ...this.defaults, ...headers };
3154
+ return new _Http(this.baseUrl, this.apiKey, this.timeoutMs, this.fetchImpl, this.origin, merged);
3155
+ }
3148
3156
  /** Sends one request and returns the parsed answer, or throws an OyaError when it failed. */
3149
3157
  async request(method, path, body, timeoutMs = this.timeoutMs, headers = {}) {
3150
3158
  const res = await this.send(`${this.baseUrl}${path}`, this.init(method, body, timeoutMs, headers), timeoutMs);
@@ -3387,15 +3395,20 @@ var Run = class {
3387
3395
  return watchRun(this, this.http.baseUrl, cb, pollMs);
3388
3396
  }
3389
3397
  };
3398
+ var LANE_HEADER = "X-Oya-Agent";
3399
+ var sdkLane = () => `sdk-${globalThis.crypto.randomUUID()}`;
3390
3400
  var Browser = class {
3391
- /** Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. */
3401
+ /**
3402
+ * Wraps a started browser; `autoCaptcha` solves CAPTCHAs after every `goto()`. A browser
3403
+ * handed over already running (a person's desktop app) gets one lane for its whole life,
3404
+ * so the desktop gives its goto, ask and play one tab of its own, never the person's.
3405
+ */
3392
3406
  constructor(http, info, autoCaptcha) {
3393
- this.http = http;
3394
3407
  this.autoCaptcha = autoCaptcha;
3395
3408
  ({ id: this.id, provider: this.provider, persona: this.persona, cdpUrl: this.cdpUrl } = info);
3396
3409
  this.reused = info.reused === true;
3410
+ this.http = this.reused ? http.withHeaders({ [LANE_HEADER]: sdkLane() }) : http;
3397
3411
  }
3398
- http;
3399
3412
  autoCaptcha;
3400
3413
  /** The browser's id. */
3401
3414
  id;
@@ -3407,6 +3420,8 @@ var Browser = class {
3407
3420
  cdpUrl;
3408
3421
  /** True when `start()` handed over a browser that was already running, such as the desktop app. */
3409
3422
  reused;
3423
+ /** How this browser reaches the API: with its lane on every request when it shares someone's browser. */
3424
+ http;
3410
3425
  /** Runs one browser command; a command that ran and failed throws. */
3411
3426
  async command(action, params = {}, timeoutMs) {
3412
3427
  const path = `/api/browsers/${this.id}/command`;
@@ -3604,9 +3619,17 @@ var Browser = class {
3604
3619
  * CDP session is handed back to its provider, a desktop browser disconnects.
3605
3620
  */
3606
3621
  stop() {
3607
- if (this.reused) return Promise.resolve({ id: this.id, ok: true, reused: true });
3622
+ if (this.reused) return this.endLane();
3608
3623
  return this.http.request("POST", `/api/browsers/${this.id}/stop`, {}, STOP_TIMEOUT_MS);
3609
3624
  }
3625
+ /**
3626
+ * Ends this browser's lane, best effort: a server too old to know lanes, or one out of reach,
3627
+ * leaves the tab to lapse on its own, and `stop()` on someone's browser has never thrown.
3628
+ */
3629
+ async endLane() {
3630
+ await this.http.request("POST", `/api/browsers/${this.id}/lane/end`, {}, STOP_TIMEOUT_MS).catch(() => void 0);
3631
+ return { id: this.id, ok: true, reused: true };
3632
+ }
3610
3633
  /** `await using browser = await oya.browser.start()` stops it however the block exits, errors included. */
3611
3634
  async [Symbol.asyncDispose]() {
3612
3635
  await this.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oya-ai/cli",
3
- "version": "1.0.242",
3
+ "version": "1.0.244",
4
4
  "description": "Command line for Oya, the HIPAA-compliant agentic browser: start browsers and run playbooks from your terminal.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://oyabrowser.com",
@@ -50,7 +50,7 @@
50
50
  "access": "public"
51
51
  },
52
52
  "devDependencies": {
53
- "@oya-ai/browser": "1.0.242",
53
+ "@oya-ai/browser": "1.0.244",
54
54
  "@types/node": "^20.19.43",
55
55
  "tsup": "^9.0.0",
56
56
  "typescript": "^6.0.3"