@mearl/client 3.0.12 → 3.1.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/unified.js CHANGED
@@ -3,7 +3,7 @@ import { stageFile, exportArtifact } from './artifacts.js';
3
3
  import WebSocket from 'ws';
4
4
  import { DEFAULT_CONNECT_TIMEOUT, DEFAULT_HEARTBEAT_INTERVAL, DEFAULT_REQUEST_TIMEOUT, MAX_BUFFER_SIZE, isHeartbeatMessage, resolveCloudConnectorSelector, } from '@mearl/cloud-types';
5
5
  import { resolveActionTimeoutSec } from './actionTimeouts.js';
6
- import { validateRequiredActionTabId, parseBrowserListParams, } from '@mearl/browser-core';
6
+ import { validateRequiredActionTabId, parseBrowserListParams, parseBrowserManageParams, parseSessionManageParams, resolveSessionManageId, } from '@mearl/browser-core';
7
7
  import { invoke as invokeLocalBrowser, resolveLocalActionTarget } from './socket.js';
8
8
  import { loadCloudServerConfig, loadLocalConnectorId } from './unifiedConfig.js';
9
9
  const RESPONSE_GRACE_MS = 1_000;
@@ -76,12 +76,12 @@ function browserMatches(browser, selector) {
76
76
  browser.name.toLowerCase() === normalized ||
77
77
  browser.originalName?.toLowerCase() === normalized);
78
78
  }
79
- function findBrowsers(browsers, selector, connectedOnly = true) {
79
+ function findBrowsers(browsers, selector, connectedOnly = true, exactOnly = false) {
80
80
  const candidates = connectedOnly
81
81
  ? browsers.filter(browser => browser.status === 'connected')
82
82
  : browsers;
83
83
  const exact = candidates.filter(browser => browserMatches(browser, selector));
84
- if (exact.length > 0)
84
+ if (exact.length > 0 || exactOnly)
85
85
  return exact;
86
86
  const normalized = normalizeBrowserSelector(selector);
87
87
  return candidates.filter(browser => browser.browserId.toLowerCase().includes(normalized) ||
@@ -150,12 +150,8 @@ export class UnifiedClient {
150
150
  async invoke(action, data = {}, options = {}) {
151
151
  const discovery = action === 'browser_list' ? parseBrowserListParams(data) : undefined;
152
152
  if (discovery &&
153
- (!options.local ||
154
- options.connector ||
155
- options.transport ||
156
- options.session ||
157
- options.controlSessionId))
158
- throw new Error('Provider discovery requires explicit --local without connector, transport, socket or session overrides');
153
+ (!options.local || options.connector || options.session || options.controlSessionId))
154
+ throw new Error('Provider discovery requires explicit --local without connector or session overrides');
159
155
  if (action === 'plugin_state') {
160
156
  const { PluginStateClient } = await import('./plugins/clients/pluginState.js');
161
157
  const state = new PluginStateClient();
@@ -200,23 +196,55 @@ export class UnifiedClient {
200
196
  connection.disconnect();
201
197
  }
202
198
  }
199
+ if (action === 'browser_manage') {
200
+ const command = parseBrowserManageParams(data);
201
+ if (options.session || options.controlSessionId)
202
+ throw new Error('browser_manage does not accept a control session');
203
+ if ((command.operation === 'close' || command.operation === 'detach') && !options.browser)
204
+ throw new Error('Specify the browser with --browser <id|name>');
205
+ }
206
+ if (action === 'session_list') {
207
+ if (options.session || options.controlSessionId)
208
+ throw new Error('session_list does not accept a session override');
209
+ if (Object.keys(data).length)
210
+ throw new Error('session_list does not accept a payload');
211
+ return this.listSessions(options);
212
+ }
213
+ if (action === 'session_manage') {
214
+ const command = parseSessionManageParams(data);
215
+ if (options.session === 'new' || options.controlSessionId === 'new')
216
+ throw new Error('Use operation "new" to create a session');
217
+ if (command.operation === 'new') {
218
+ if (options.session || options.controlSessionId)
219
+ throw new Error('session_manage new does not accept a session id');
220
+ }
221
+ else {
222
+ const id = resolveSessionManageId(command, options.session ?? options.controlSessionId);
223
+ if (options.controlSessionId && id !== options.controlSessionId)
224
+ throw new Error('Conflicting session IDs');
225
+ if (!id && !options.browser)
226
+ throw new Error('Specify a sessionId or --session <id>, or select an external Provider browser');
227
+ if (id) {
228
+ const { sessionId: _id, ...payload } = command;
229
+ data = payload;
230
+ options = { ...options, session: id };
231
+ }
232
+ }
233
+ }
203
234
  if (options.session && options.session !== 'new') {
204
235
  const session = await this.resolveControlSession(options.session, options);
205
236
  const selected = decodeBrowserTarget(options.browser);
206
237
  const pinned = decodeBrowserTarget(session.browser);
207
238
  if (options.browser &&
208
- (!selected ||
209
- selected.browser !== pinned?.browser ||
210
- selected.connector !== pinned?.connector)) {
239
+ (selected
240
+ ? selected.browser !== pinned?.browser || selected.connector !== pinned?.connector
241
+ : options.browser !== pinned?.browser)) {
211
242
  throw new Error('The selected browser does not match the control session');
212
243
  }
213
- if (options.transport && session.transport !== options.transport)
214
- throw new Error('A control session cannot change transport');
215
244
  options = {
216
245
  ...options,
217
246
  browser: session.browser,
218
247
  controlSessionId: session.id,
219
- ...(session.transport === 'cdp' && !pinned?.connector ? { transport: 'cdp' } : {}),
220
248
  };
221
249
  }
222
250
  else if (options.session === 'new') {
@@ -304,13 +332,10 @@ export class UnifiedClient {
304
332
  const target = decodeBrowserTarget(options.browser);
305
333
  if (target && !options.connector)
306
334
  return options;
307
- const local = options.local ||
308
- options.transport === 'cdp' ||
309
- (!this.options.serverUrl && !options.connector);
335
+ const local = options.local || (!this.options.serverUrl && !options.connector);
310
336
  if (local) {
311
337
  const resolved = resolveLocalActionTarget('page_eval', data, {
312
338
  browser: options.browser,
313
- transport: options.transport,
314
339
  });
315
340
  if (resolved?.socketPath)
316
341
  return { ...options, socketPath: resolved.socketPath };
@@ -335,7 +360,7 @@ export class UnifiedClient {
335
360
  }
336
361
  const listing = (await this.invokeRouted('browser_list', {}, options));
337
362
  const connected = listing.browsers.filter(browser => browser.status === 'connected' && (!local || browser.transport !== 'provider'));
338
- const implicitHost = options.local || options.transport === 'cdp' || options.connector || !this.options.serverUrl;
363
+ const implicitHost = options.local || options.connector || !this.options.serverUrl;
339
364
  const automatic = connected.find(browser => browser.browserId === listing.defaultBrowserId) ??
340
365
  (implicitHost || connected.length === 1 ? connected[0] : undefined);
341
366
  const candidates = options.browser
@@ -348,15 +373,13 @@ export class UnifiedClient {
348
373
  const browser = candidates[0];
349
374
  const pinned = { ...options, browser: browser.browserId };
350
375
  delete pinned.connector;
351
- if (browser.transport === 'cdp' && !decodeBrowserTarget(browser.browserId)?.connector)
352
- pinned.transport = 'cdp';
353
376
  return pinned;
354
377
  }
355
378
  async invokeRouted(action, data = {}, options = {}) {
356
379
  validateRequiredActionTabId(action, data);
357
380
  const timeoutSec = options.timeoutSec ?? resolveActionTimeoutSec(action, data, this.options.requestTimeoutSec);
358
381
  if (options.socketPath)
359
- return this.invokeLocal(action, data, timeoutSec, undefined, options.transport, options.controlSessionId, options.socketPath);
382
+ return this.invokeLocal(action, data, timeoutSec, undefined, options.controlSessionId, options.socketPath);
360
383
  if (action === 'connector_list')
361
384
  return this.listConnectors(timeoutSec);
362
385
  if (action === 'browser_list') {
@@ -369,8 +392,8 @@ export class UnifiedClient {
369
392
  throw new Error('Provider launch-form discovery is not supported by this host');
370
393
  return this.applyConfiguredDefault(this.decorateListing(result, { kind: 'local' }));
371
394
  }
372
- if (options.local || options.transport === 'cdp') {
373
- return this.listLocalBrowsers(timeoutSec, options.transport);
395
+ if (options.local) {
396
+ return this.listLocalBrowsers(timeoutSec);
374
397
  }
375
398
  const connector = options.connector ?? this.defaultConnector;
376
399
  return connector
@@ -380,26 +403,22 @@ export class UnifiedClient {
380
403
  if (action === 'browser_select_browser') {
381
404
  return this.selectDefaultBrowser(data, options, timeoutSec);
382
405
  }
383
- if (options.local || options.transport === 'cdp') {
406
+ if (options.local) {
384
407
  return this.invokeExplicitLocal(action, data, options, timeoutSec);
385
408
  }
386
409
  const optionTarget = decodeBrowserTarget(options.browser);
387
410
  const defaultTarget = options.browser ? undefined : decodeBrowserTarget(this.defaultBrowser);
388
- const closeTarget = action === 'browser_close' && typeof data.browser === 'string'
389
- ? decodeBrowserTarget(data.browser)
390
- : undefined;
391
- const target = optionTarget ?? closeTarget ?? defaultTarget;
411
+ const target = optionTarget ?? defaultTarget;
392
412
  const connector = target?.connector ?? options.connector ?? this.defaultConnector;
393
413
  const browser = optionTarget?.browser ??
394
414
  defaultTarget?.browser ??
395
415
  (options.browser && !optionTarget ? options.browser : undefined) ??
396
416
  (this.defaultBrowser && !defaultTarget ? this.defaultBrowser : undefined);
397
- const requestData = closeTarget ? { ...data, browser: closeTarget.browser } : data;
398
417
  if (target && !target.connector) {
399
418
  if (options.connector) {
400
419
  throw new Error('A local browser cannot be used together with --connector.');
401
420
  }
402
- return this.invokeLocal(action, requestData, timeoutSec, target.browser, undefined, options.controlSessionId);
421
+ return this.invokeLocal(action, data, timeoutSec, target.browser, options.controlSessionId);
403
422
  }
404
423
  if (connector) {
405
424
  const selected = target?.connector && !options.connector && !this.defaultConnector
@@ -408,42 +427,32 @@ export class UnifiedClient {
408
427
  if (target?.connector && selected.connectorId !== target.connector) {
409
428
  throw new Error('The selected browser belongs to a different cloud connector.');
410
429
  }
411
- return this.invokeRemote(action, requestData, timeoutSec, browser, selected, options.controlSessionId);
430
+ return this.invokeRemote(action, data, timeoutSec, browser, selected, options.controlSessionId);
412
431
  }
413
432
  if (!this.options.serverUrl) {
414
- return this.invokeLocal(action, requestData, timeoutSec, options.browser ?? this.defaultBrowser, undefined, options.controlSessionId);
415
- }
416
- const selector = options.browser ??
417
- this.defaultBrowser ??
418
- (action === 'browser_close' && typeof data.browser === 'string' ? data.browser : undefined);
419
- const resolved = await this.resolveUnifiedBrowser(selector, timeoutSec, action === 'browser_close');
420
- if (resolved) {
421
- if (action === 'browser_close') {
422
- const nextOptions = { ...options };
423
- delete nextOptions.browser;
424
- return this.invoke(action, { ...data, browser: resolved }, nextOptions);
425
- }
426
- return this.invoke(action, data, { ...options, browser: resolved });
433
+ return this.invokeLocal(action, data, timeoutSec, options.browser ?? this.defaultBrowser, options.controlSessionId);
427
434
  }
428
- if (action === 'browser_launch') {
429
- return this.invokeLaunchWithoutControlBrowser(data, timeoutSec);
435
+ const selector = options.browser ?? this.defaultBrowser;
436
+ const instanceOperation = action === 'browser_manage' && (data.operation === 'close' || data.operation === 'detach');
437
+ const resolved = await this.resolveUnifiedBrowser(selector, timeoutSec, instanceOperation, instanceOperation);
438
+ if (resolved)
439
+ return this.invokeRouted(action, data, { ...options, browser: resolved });
440
+ if (action === 'browser_manage' &&
441
+ (data.operation === 'launch' || data.operation === 'attach')) {
442
+ return this.invokeOpenWithoutControlBrowser(data, timeoutSec);
430
443
  }
431
444
  throw new Error('No connected browser is available. Run `mearl browser_list` to inspect all sources.');
432
445
  }
433
446
  async invokeExplicitLocal(action, data, options, timeoutSec) {
434
447
  const optionTarget = decodeBrowserTarget(options.browser);
435
448
  const defaultTarget = options.browser ? undefined : decodeBrowserTarget(this.defaultBrowser);
436
- const closeTarget = action === 'browser_close' && typeof data.browser === 'string'
437
- ? decodeBrowserTarget(data.browser)
438
- : undefined;
439
- if (optionTarget?.connector || defaultTarget?.connector || closeTarget?.connector) {
440
- throw new Error('A remote browser cannot be used together with --local or --cdp.');
449
+ if (optionTarget?.connector || defaultTarget?.connector) {
450
+ throw new Error('A remote browser cannot be used together with --local.');
441
451
  }
442
452
  const browser = optionTarget?.browser ?? defaultTarget?.browser ?? options.browser ?? this.defaultBrowser;
443
- const requestData = closeTarget ? { ...data, browser: closeTarget.browser } : data;
444
- return this.invokeLocal(action, requestData, timeoutSec, browser, options.transport, options.controlSessionId);
453
+ return this.invokeLocal(action, data, timeoutSec, browser, options.controlSessionId);
445
454
  }
446
- async invokeLaunchWithoutControlBrowser(data, timeoutSec) {
455
+ async invokeOpenWithoutControlBrowser(data, timeoutSec) {
447
456
  const local = await this.tryLocalBrowserList(timeoutSec);
448
457
  const discoveredConnectors = await this.listConnectors(timeoutSec).then(result => result.connectors);
449
458
  const localAvailable = local !== null;
@@ -452,10 +461,10 @@ export class UnifiedClient {
452
461
  ? discoveredConnectors.filter(connector => connector.connectorId !== localConnectorId)
453
462
  : discoveredConnectors;
454
463
  if (localAvailable && connectors.length === 0) {
455
- return this.invokeLocal('browser_launch', data, timeoutSec, undefined);
464
+ return this.invokeLocal('browser_manage', data, timeoutSec, undefined);
456
465
  }
457
466
  if (!localAvailable && connectors.length === 1) {
458
- return this.invokeRemote('browser_launch', data, timeoutSec, undefined, connectors[0]);
467
+ return this.invokeRemote('browser_manage', data, timeoutSec, undefined, connectors[0]);
459
468
  }
460
469
  if (!localAvailable && connectors.length === 0) {
461
470
  throw new Error('No browser host is available. Install @mearl/native-host locally or connect a cloud connector.');
@@ -464,7 +473,7 @@ export class UnifiedClient {
464
473
  ...(localAvailable ? ['this machine [--local]'] : []),
465
474
  ...connectors.map(connector => `${connector.name} [${connector.connectorId}]`),
466
475
  ].join(', ');
467
- throw new Error('The browser host for browser_launch is ambiguous. ' +
476
+ throw new Error('The browser host for browser_manage is ambiguous. ' +
468
477
  `Pass --local, --connector <id|name>, or --browser <global-id>. Available: ${availableHosts}`);
469
478
  }
470
479
  async selectDefaultBrowser(data, options, timeoutSec) {
@@ -477,7 +486,6 @@ export class UnifiedClient {
477
486
  const listing = (await this.invoke('browser_list', {}, {
478
487
  timeoutSec,
479
488
  ...(options.local ? { local: true } : {}),
480
- ...(options.transport ? { transport: options.transport } : {}),
481
489
  ...(options.connector ? { connector: options.connector } : {}),
482
490
  }));
483
491
  const matches = findBrowsers(listing.browsers, selector);
@@ -491,10 +499,10 @@ export class UnifiedClient {
491
499
  this.defaultConnector = undefined;
492
500
  return { selected: { browserId: match.browserId, name: match.name } };
493
501
  }
494
- async resolveUnifiedBrowser(selector, timeoutSec, includeDisconnected) {
502
+ async resolveUnifiedBrowser(selector, timeoutSec, includeDisconnected, exactOnly = false) {
495
503
  const listing = await this.listAllBrowsers(timeoutSec);
496
504
  if (selector) {
497
- const matches = findBrowsers(listing.browsers, selector, !includeDisconnected);
505
+ const matches = findBrowsers(listing.browsers, selector, !includeDisconnected, exactOnly);
498
506
  if (matches.length > 1) {
499
507
  throw new Error(`Browser selector "${selector}" is ambiguous. Use an exact global browserId from browser_list.`);
500
508
  }
@@ -532,8 +540,8 @@ export class UnifiedClient {
532
540
  }
533
541
  return selection.connector;
534
542
  }
535
- async listLocalBrowsers(timeoutSec, transport) {
536
- const result = await invokeLocalBrowser('browser_list', {}, { timeoutSec, ...(transport ? { transport } : {}), controlSource: 'local' });
543
+ async listLocalBrowsers(timeoutSec) {
544
+ const result = await invokeLocalBrowser('browser_list', {}, { timeoutSec, controlSource: 'local' });
537
545
  return this.applyConfiguredDefault(this.decorateListing(result, { kind: 'local' }));
538
546
  }
539
547
  async tryLocalBrowserList(timeoutSec) {
@@ -584,6 +592,56 @@ export class UnifiedClient {
584
592
  connectorName: connector.name,
585
593
  }));
586
594
  }
595
+ async listSessions(options) {
596
+ const timeoutSec = options.timeoutSec ?? this.options.requestTimeoutSec;
597
+ const target = decodeBrowserTarget(options.browser);
598
+ if (options.local && (target?.connector || options.connector))
599
+ throw new Error('Use either --local or a remote connector');
600
+ if (target && !target.connector && options.connector)
601
+ throw new Error('A local browser cannot be used together with --connector.');
602
+ const connector = target?.connector ?? options.connector;
603
+ if (connector) {
604
+ const selected = target?.connector && !options.connector
605
+ ? { connectorId: target.connector, name: target.connector }
606
+ : await this.resolveConnector(options.connector ?? connector, timeoutSec);
607
+ if (target?.connector && target.connector !== selected.connectorId)
608
+ throw new Error('The selected browser belongs to a different cloud connector.');
609
+ return this.invokeRemote('session_list', {}, timeoutSec, target?.browser ?? options.browser, selected);
610
+ }
611
+ if (options.local || target || !this.options.serverUrl)
612
+ return this.invokeLocal('session_list', {}, timeoutSec, target?.browser ?? options.browser);
613
+ if (options.browser) {
614
+ const browser = await this.resolveUnifiedBrowser(options.browser, timeoutSec, true);
615
+ if (!browser)
616
+ throw new Error('No browser matches the session list filter');
617
+ return this.listSessions({ ...options, browser });
618
+ }
619
+ const local = this.invokeLocal('session_list', {}, timeoutSec, undefined);
620
+ const remote = this.listConnectors(timeoutSec);
621
+ const [localResult, connectors] = await Promise.allSettled([local, remote]);
622
+ const localConnectorId = localResult.status === 'fulfilled' && !process.env.MEARL_SOCKET_PATH
623
+ ? loadLocalConnectorId()
624
+ : null;
625
+ const sources = connectors.status === 'fulfilled'
626
+ ? connectors.value.connectors.filter(item => item.connectorId !== localConnectorId)
627
+ : [];
628
+ const results = [
629
+ localResult,
630
+ ...(await Promise.allSettled(sources.map(item => this.invokeRemote('session_list', {}, timeoutSec, undefined, item)))),
631
+ ];
632
+ const warnings = connectors.status === 'rejected' ? [errorMessage(connectors.reason)] : [];
633
+ const sessions = results.flatMap((result, index) => {
634
+ const name = index ? sources[index - 1].name : 'this machine';
635
+ if (result.status === 'rejected') {
636
+ warnings.push(`${name}: ${errorMessage(result.reason)}`);
637
+ return [];
638
+ }
639
+ for (const warning of result.value.warnings ?? [])
640
+ warnings.push(`${name}: ${warning}`);
641
+ return result.value.sessions;
642
+ });
643
+ return { sessions, ...(warnings.length ? { warnings } : {}) };
644
+ }
587
645
  async listAllBrowsers(timeoutSec) {
588
646
  const warnings = [];
589
647
  const localPromise = this.tryLocalBrowserList(timeoutSec);
@@ -648,12 +706,11 @@ export class UnifiedClient {
648
706
  ...(warnings.length > 0 ? { warnings } : {}),
649
707
  });
650
708
  }
651
- async invokeLocal(action, data, timeoutSec, browser, transport, controlSessionId, socketPath) {
709
+ async invokeLocal(action, data, timeoutSec, browser, controlSessionId, socketPath) {
652
710
  const result = await invokeLocalBrowser(action, data, {
653
711
  timeoutSec,
654
712
  ...(this.requestDeadline === undefined ? {} : { deadline: this.requestDeadline }),
655
713
  ...(browser ? { browser } : {}),
656
- ...(transport ? { transport } : {}),
657
714
  ...(socketPath ? { socketPath } : {}),
658
715
  controlSource: 'local',
659
716
  ...(controlSessionId ? { controlSessionId } : {}),
@@ -689,8 +746,9 @@ export class UnifiedClient {
689
746
  },
690
747
  };
691
748
  }
692
- if (typeof result?.browserId === 'string' && action.startsWith('__artifact_')) {
693
- return {
749
+ if (typeof result?.browserId === 'string' &&
750
+ (action.startsWith('__artifact_') || action === 'page_record')) {
751
+ result = {
694
752
  ...result,
695
753
  browserId: encodeBrowserTarget({
696
754
  browser: result.browserId,
@@ -698,38 +756,67 @@ export class UnifiedClient {
698
756
  }),
699
757
  };
700
758
  }
701
- if (result?.download?.browserId)
759
+ const artifactKey = action === 'page_record' ? 'recording' : 'download';
760
+ const artifact = result?.[artifactKey];
761
+ if (artifact?.browserId)
702
762
  result = {
703
763
  ...result,
704
- download: {
705
- ...result.download,
764
+ [artifactKey]: {
765
+ ...artifact,
706
766
  browserId: encodeBrowserTarget({
707
- browser: result.download.browserId,
767
+ browser: artifact.browserId,
708
768
  ...(source.connectorId ? { connector: source.connectorId } : {}),
709
769
  }),
710
770
  },
711
771
  };
712
- if (action !== 'browser_launch' || typeof result?.browserId !== 'string')
772
+ if (action === 'session_list' && Array.isArray(result?.sessions)) {
773
+ return {
774
+ ...result,
775
+ sessions: result.sessions.map((session) => ({
776
+ ...session,
777
+ browserId: encodeBrowserTarget({
778
+ browser: session.browserId,
779
+ connector: source.connectorId,
780
+ }),
781
+ })),
782
+ };
783
+ }
784
+ if (action !== 'browser_manage' || typeof result?.browserId !== 'string')
713
785
  return result;
714
- return decorateBrowser(result, source);
786
+ return typeof result.name === 'string'
787
+ ? decorateBrowser(result, source)
788
+ : {
789
+ ...result,
790
+ browserId: encodeBrowserTarget({
791
+ browser: result.browserId,
792
+ connector: source.connectorId,
793
+ }),
794
+ };
715
795
  }
716
796
  async resolveControlSession(id, options) {
717
797
  if (!/^s_[A-Za-z0-9_-]{8}$/.test(id))
718
798
  throw new Error('Invalid session id; reuse session.sessionId from the first response');
719
799
  const cached = this.controlSessions.get(id);
720
- if (cached)
800
+ const target = decodeBrowserTarget(options.browser);
801
+ if (options.local && (target?.connector || options.connector))
802
+ throw new Error('Use either --local or a remote connector');
803
+ const connector = options.connector ?? target?.connector;
804
+ if (cached && !connector && (!options.local || !decodeBrowserTarget(cached.browser)?.connector))
721
805
  return cached;
722
806
  const timeoutSec = options.timeoutSec ?? 15;
723
- const localLookup = this.invokeLocal('__control_session_resolve', { sessionId: id }, timeoutSec, undefined);
807
+ const localLookup = connector
808
+ ? Promise.resolve({ session: null })
809
+ : this.invokeLocal('__control_session_resolve', { sessionId: id }, timeoutSec, undefined);
724
810
  const discover = async () => {
725
- const { connectors } = await this.listConnectors(timeoutSec);
726
- return Promise.allSettled(connectors.map(connector => this.invokeRemote('__control_session_resolve', { sessionId: id }, timeoutSec, undefined, connector)));
811
+ const sources = connector
812
+ ? [await this.resolveConnector(connector, timeoutSec)]
813
+ : (await this.listConnectors(timeoutSec)).connectors;
814
+ return Promise.allSettled(sources.map(connector => this.invokeRemote('__control_session_resolve', { sessionId: id }, timeoutSec, undefined, connector)));
727
815
  };
816
+ const queryRemote = this.options.serverUrl && !options.local && (!target || connector);
728
817
  const [local, remote] = await Promise.allSettled([
729
818
  localLookup,
730
- this.options.serverUrl && !options.local && !options.transport
731
- ? discover()
732
- : Promise.resolve([]),
819
+ queryRemote ? discover() : Promise.resolve([]),
733
820
  ]);
734
821
  const localSession = local.status === 'fulfilled' ? local.value?.session : undefined;
735
822
  const localTarget = decodeBrowserTarget(localSession?.browserId);
@@ -760,9 +847,9 @@ export class UnifiedClient {
760
847
  const errors = results.flatMap(result => result.status === 'rejected' ? [errorMessage(result.reason)] : []);
761
848
  throw new Error(`CONTROL_SESSION_NOT_FOUND: ${id}${errors.length ? ` (${errors.join('; ')})` : ''}`);
762
849
  }
763
- const target = { browser: session.browserId, id, transport: session.transport };
764
- this.controlSessions.set(id, target);
765
- return target;
850
+ const resolved = { browser: session.browserId, id, transport: session.transport };
851
+ this.controlSessions.set(id, resolved);
852
+ return resolved;
766
853
  }
767
854
  async ensureConnected() {
768
855
  if (this.ws?.readyState === WebSocket.OPEN)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/client",
3
- "version": "3.0.12",
3
+ "version": "3.1.0",
4
4
  "description": "Unified Mearl SDK & CLI for local and remote browsers",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -68,11 +68,11 @@
68
68
  "commander": "^14.0.3",
69
69
  "fastest-levenshtein": "^1.0.16",
70
70
  "ws": "^8.18.0",
71
- "@mearl/daemon-core": "3.0.12",
72
- "@mearl/cloud-types": "3.0.12",
73
- "@mearl/provider": "3.0.12",
74
- "@mearl/agent-runtime": "3.0.12",
75
- "@mearl/browser-core": "3.0.12"
71
+ "@mearl/daemon-core": "3.1.0",
72
+ "@mearl/provider": "3.1.0",
73
+ "@mearl/cloud-types": "3.1.0",
74
+ "@mearl/browser-core": "3.1.0",
75
+ "@mearl/agent-runtime": "3.1.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/node": "^24.9.1",