@liberseek/boft-cli-linux-x64 0.7.6 → 0.7.7

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.
@@ -219,8 +219,8 @@ function parseTarget(value) {
219
219
  webSocketDebuggerUrl
220
220
  };
221
221
  }
222
- function defaultFetch(url) {
223
- return fetch(url);
222
+ function defaultFetch(url, init) {
223
+ return fetch(url, init);
224
224
  }
225
225
  function defaultSocketFactory(url) {
226
226
  return new WebSocket(url);
@@ -247,10 +247,10 @@ function parseResponse(value) {
247
247
  }
248
248
  return response;
249
249
  }
250
- async function listCdpTargets(endpoint, fetchImpl = defaultFetch) {
250
+ async function listCdpTargets(endpoint, fetchImpl = defaultFetch, signal) {
251
251
  const baseUrl = loopbackUrl(endpoint, ["http:", "https:"]);
252
252
  const targetsUrl = new URL("/json/list", baseUrl).toString();
253
- const response = await fetchImpl(targetsUrl);
253
+ const response = await fetchImpl(targetsUrl, signal ? { signal } : void 0);
254
254
  if (!response.ok) throw new Error(`CDP target discovery failed with HTTP ${response.status}`);
255
255
  const value = await response.json();
256
256
  if (!Array.isArray(value)) throw new Error("CDP target discovery did not return an array");
@@ -1319,6 +1319,33 @@ function isRecord2(value) {
1319
1319
  function sleep(milliseconds) {
1320
1320
  return new Promise((resolve) => setTimeout(resolve, milliseconds));
1321
1321
  }
1322
+ function discoveryTimeoutSignal(timeoutMs, signal) {
1323
+ const timeout = AbortSignal.timeout(timeoutMs);
1324
+ return signal ? AbortSignal.any([timeout, signal]) : timeout;
1325
+ }
1326
+ function abortFailure(signal, fallback) {
1327
+ return signal.reason instanceof Error ? signal.reason : new Error(fallback);
1328
+ }
1329
+ function awaitWithSignal(promise, signal, timeoutMessage) {
1330
+ if (signal.aborted) return Promise.reject(abortFailure(signal, timeoutMessage));
1331
+ return new Promise((resolve, reject) => {
1332
+ const onAbort = () => {
1333
+ signal.removeEventListener("abort", onAbort);
1334
+ reject(abortFailure(signal, timeoutMessage));
1335
+ };
1336
+ signal.addEventListener("abort", onAbort, { once: true });
1337
+ promise.then(
1338
+ (value) => {
1339
+ signal.removeEventListener("abort", onAbort);
1340
+ resolve(value);
1341
+ },
1342
+ (error) => {
1343
+ signal.removeEventListener("abort", onAbort);
1344
+ reject(error);
1345
+ }
1346
+ );
1347
+ });
1348
+ }
1322
1349
  function sameAgents(actual, expected) {
1323
1350
  const expectedSet = new Set(expected);
1324
1351
  return actual.length === expected.length && new Set(actual).size === actual.length && actual.every((agent) => expectedSet.has(agent));
@@ -1358,21 +1385,36 @@ function validateBindingStatus(value, expectedAgents) {
1358
1385
  }
1359
1386
  return value;
1360
1387
  }
1361
- async function waitForPrimaryTarget(endpoint, operations, timeoutMs, pollIntervalMs, preferredTargetId) {
1362
- const deadline = Date.now() + timeoutMs;
1388
+ async function waitForPrimaryTarget(endpoint, operations, timeoutMs, pollIntervalMs, preferredTargetId, signal) {
1389
+ const discovery = discoveryTimeoutSignal(timeoutMs, signal);
1363
1390
  let lastError;
1364
- while (Date.now() < deadline) {
1391
+ while (!discovery.aborted) {
1365
1392
  try {
1366
1393
  const target = selectPrimaryRendererTarget(
1367
- await operations.listTargets(endpoint),
1394
+ await awaitWithSignal(
1395
+ operations.listTargets(endpoint, discovery),
1396
+ discovery,
1397
+ "Renderer CDP target discovery timed out"
1398
+ ),
1368
1399
  preferredTargetId
1369
1400
  );
1370
1401
  if (target) return target;
1371
1402
  lastError = new Error("Renderer CDP has no primary app://-/index.html page target");
1372
1403
  } catch (error) {
1373
1404
  lastError = error;
1405
+ if (discovery.aborted) break;
1406
+ }
1407
+ if (discovery.aborted) break;
1408
+ try {
1409
+ await awaitWithSignal(
1410
+ sleep(pollIntervalMs),
1411
+ discovery,
1412
+ "Renderer CDP target discovery timed out"
1413
+ );
1414
+ } catch (error) {
1415
+ lastError = error;
1416
+ break;
1374
1417
  }
1375
- await sleep(pollIntervalMs);
1376
1418
  }
1377
1419
  const detail = lastError instanceof Error ? `: ${lastError.message}` : "";
1378
1420
  throw new Error(`Primary Codex Renderer CDP target did not become ready${detail}`);
@@ -1514,7 +1556,7 @@ var InstalledRendererCdpControlSession = class {
1514
1556
  }
1515
1557
  };
1516
1558
  var defaultOperations = {
1517
- listTargets: (endpoint) => listCdpTargets(endpoint),
1559
+ listTargets: (endpoint, signal) => listCdpTargets(endpoint, fetch, signal),
1518
1560
  connect: (webSocketDebuggerUrl) => CdpClient.connect(webSocketDebuggerUrl),
1519
1561
  installDraftPrewarmPolicy: installRendererDraftPrewarmPolicyDirect
1520
1562
  };
@@ -1527,7 +1569,9 @@ async function createRendererCdpControlSession(options) {
1527
1569
  options.rendererCdpEndpoint,
1528
1570
  operations,
1529
1571
  timeoutMs,
1530
- pollIntervalMs
1572
+ pollIntervalMs,
1573
+ void 0,
1574
+ options.signal
1531
1575
  );
1532
1576
  const installed = await installTarget(
1533
1577
  target,
@@ -1746,7 +1790,8 @@ ${rendererSource}`,
1746
1790
  "qoder-cn",
1747
1791
  "kimi-code"
1748
1792
  ],
1749
- timeoutMs: PRODUCTION_INSTALL_TIMEOUT_MS
1793
+ timeoutMs: PRODUCTION_INSTALL_TIMEOUT_MS,
1794
+ signal
1750
1795
  },
1751
1796
  dependencies
1752
1797
  );
@@ -1754,14 +1799,6 @@ ${rendererSource}`,
1754
1799
  return installed;
1755
1800
  };
1756
1801
  startupTrace("initialization started");
1757
- try {
1758
- session = await createSession();
1759
- recordRecoverySuccess();
1760
- } catch (error) {
1761
- startupTrace("initial Renderer Session unavailable", error);
1762
- session = void 0;
1763
- recordRecoveryFailure(error);
1764
- }
1765
1802
  let operation = Promise.resolve(void 0);
1766
1803
  const useSession = (callback) => {
1767
1804
  const next = operation.then(callback, callback);
@@ -1809,6 +1846,17 @@ ${rendererSource}`,
1809
1846
  state: "compatible",
1810
1847
  issues: []
1811
1848
  });
1849
+ await useSession(async () => {
1850
+ if (session) return;
1851
+ try {
1852
+ session = await createSession();
1853
+ recordRecoverySuccess();
1854
+ } catch (error) {
1855
+ startupTrace("initial Renderer Session unavailable", error);
1856
+ session = void 0;
1857
+ recordRecoveryFailure(error);
1858
+ }
1859
+ });
1812
1860
  while (!signal.aborted) {
1813
1861
  await dependencies.sleep(dependencies.monitorIntervalMs);
1814
1862
  if (signal.aborted) continue;