@dev-anywhere/proxy 0.9.0 → 0.9.1

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/serve.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  stripProxyProfileArgs,
12
12
  unlinkIfPresent,
13
13
  writeSessionRuntimeIpcVersions
14
- } from "./chunk-K72MFCMC.js";
14
+ } from "./chunk-OFD4UVPB.js";
15
15
  import {
16
16
  ContentBlockDeltaSchema,
17
17
  IGNORED_EVENT_TYPES,
@@ -22,8 +22,9 @@ import {
22
22
  getSeqCounterFor
23
23
  } from "./chunk-57LA2LWY.js";
24
24
  import {
25
- compareStableVersions
26
- } from "./chunk-HWPURRXB.js";
25
+ compareStableVersions,
26
+ selectHighestStableVersion
27
+ } from "./chunk-7LUBU2WA.js";
27
28
  import {
28
29
  PROXY_PACKAGE_ROOT,
29
30
  PROXY_VERSION
@@ -66,6 +67,7 @@ import {
66
67
  PTY_INITIAL_MIN_COLS,
67
68
  PTY_INITIAL_MIN_ROWS,
68
69
  PreviewSourceSchema,
70
+ ProxyUpgradeBootstrapResponseSchema,
69
71
  RELAY_CONTROL_PROTOCOL_VERSION,
70
72
  RELAY_JSON_MESSAGE_MAX_BYTES,
71
73
  RelayCloseCode,
@@ -91,7 +93,7 @@ import {
91
93
  serializeIpc,
92
94
  serializeWorkerMsg,
93
95
  summarizeToolActivity
94
- } from "./chunk-RN3KQK6E.js";
96
+ } from "./chunk-NTL4CXBA.js";
95
97
  import {
96
98
  classifyCodexActiveWriterError,
97
99
  codexActiveWriterMessage,
@@ -12520,6 +12522,132 @@ function createRelayAutoUpdater(options) {
12520
12522
  };
12521
12523
  }
12522
12524
 
12525
+ // src/relay-upgrade-bootstrap.ts
12526
+ var DEFAULT_BOOTSTRAP_TIMEOUT_MS = 5e3;
12527
+ var DEFAULT_RETRY_INITIAL_MS = 5e3;
12528
+ var DEFAULT_RETRY_MAX_MS = 5 * 6e4;
12529
+ function relayUpgradeBootstrapUrl(relayUrl) {
12530
+ const url = new URL(relayUrl);
12531
+ if (url.protocol === "ws:") url.protocol = "http:";
12532
+ else if (url.protocol === "wss:") url.protocol = "https:";
12533
+ else throw new Error(`Unsupported Relay URL protocol: ${url.protocol}`);
12534
+ url.pathname = `${url.pathname.replace(/\/$/, "")}/api/proxy-upgrade-bootstrap`;
12535
+ url.search = "";
12536
+ url.hash = "";
12537
+ return url;
12538
+ }
12539
+ async function fetchRelayUpgradeBootstrap(options) {
12540
+ const fetchImpl = options.fetchImpl ?? fetch;
12541
+ const headers = options.token ? { authorization: `Bearer ${options.token}` } : void 0;
12542
+ const response = await fetchImpl(relayUpgradeBootstrapUrl(options.relayUrl), {
12543
+ headers,
12544
+ redirect: "error",
12545
+ cache: "no-store",
12546
+ signal: options.signal
12547
+ });
12548
+ if (response.status === 404) return null;
12549
+ if (!response.ok) throw new Error(`Relay upgrade bootstrap returned HTTP ${response.status}`);
12550
+ const parsed = ProxyUpgradeBootstrapResponseSchema.safeParse(await response.json());
12551
+ if (!parsed.success) throw new Error("Relay upgrade bootstrap returned an invalid response");
12552
+ return parsed.data;
12553
+ }
12554
+ function createRelayUpgradeBootstrapMonitor(options) {
12555
+ let disposed = false;
12556
+ let active = false;
12557
+ let inFlight = null;
12558
+ let retryTimer = null;
12559
+ let retryAttempt = 0;
12560
+ const clearRetry = () => {
12561
+ if (!retryTimer) return;
12562
+ clearTimeout(retryTimer);
12563
+ retryTimer = null;
12564
+ };
12565
+ const suspend = () => {
12566
+ active = false;
12567
+ retryAttempt = 0;
12568
+ clearRetry();
12569
+ inFlight?.abort();
12570
+ inFlight = null;
12571
+ };
12572
+ const scheduleRetry = () => {
12573
+ if (disposed || !active || inFlight || retryTimer) return;
12574
+ const initial = options.retryInitialMs ?? DEFAULT_RETRY_INITIAL_MS;
12575
+ const maximum = options.retryMaxMs ?? DEFAULT_RETRY_MAX_MS;
12576
+ const delay3 = Math.min(initial * 2 ** Math.min(retryAttempt, 30), maximum);
12577
+ retryAttempt += 1;
12578
+ retryTimer = setTimeout(() => {
12579
+ retryTimer = null;
12580
+ probe();
12581
+ }, delay3);
12582
+ retryTimer.unref?.();
12583
+ };
12584
+ const probe = () => {
12585
+ if (disposed || !active || inFlight) return;
12586
+ const controller = new AbortController();
12587
+ const timeout = setTimeout(
12588
+ () => controller.abort(),
12589
+ options.timeoutMs ?? DEFAULT_BOOTSTRAP_TIMEOUT_MS
12590
+ );
12591
+ timeout.unref?.();
12592
+ inFlight = controller;
12593
+ void fetchRelayUpgradeBootstrap({
12594
+ relayUrl: options.relayUrl,
12595
+ token: options.token,
12596
+ signal: controller.signal,
12597
+ fetchImpl: options.fetchImpl
12598
+ }).then((bootstrap) => {
12599
+ if (disposed || !active || !bootstrap) return;
12600
+ active = false;
12601
+ retryAttempt = 0;
12602
+ clearRetry();
12603
+ options.logger.info(
12604
+ {
12605
+ relayVersion: bootstrap.relayVersion,
12606
+ controlProtocolVersion: bootstrap.controlProtocolVersion
12607
+ },
12608
+ "Received Relay upgrade bootstrap"
12609
+ );
12610
+ options.onVersion(bootstrap.relayVersion);
12611
+ if (bootstrap.controlProtocolVersion !== RELAY_CONTROL_PROTOCOL_VERSION) {
12612
+ options.logger.warn(
12613
+ {
12614
+ localControlProtocolVersion: RELAY_CONTROL_PROTOCOL_VERSION,
12615
+ relayControlProtocolVersion: bootstrap.controlProtocolVersion
12616
+ },
12617
+ "Relay control protocol differs; waiting for Proxy update"
12618
+ );
12619
+ }
12620
+ }).catch((error) => {
12621
+ if (disposed || !active || controller.signal.aborted) return;
12622
+ options.logger.debug(
12623
+ { error: error instanceof Error ? error.message : String(error) },
12624
+ "Relay upgrade bootstrap unavailable"
12625
+ );
12626
+ }).finally(() => {
12627
+ clearTimeout(timeout);
12628
+ if (inFlight === controller) inFlight = null;
12629
+ scheduleRetry();
12630
+ });
12631
+ };
12632
+ return {
12633
+ request() {
12634
+ if (disposed) return;
12635
+ if (!active) {
12636
+ active = true;
12637
+ retryAttempt = 0;
12638
+ }
12639
+ if (!retryTimer) probe();
12640
+ },
12641
+ markControlProtocolConnected() {
12642
+ suspend();
12643
+ },
12644
+ dispose() {
12645
+ disposed = true;
12646
+ suspend();
12647
+ }
12648
+ };
12649
+ }
12650
+
12523
12651
  // src/serve/device-preview/default-device-preview-backend.ts
12524
12652
  import sharp from "sharp";
12525
12653
 
@@ -16526,10 +16654,20 @@ async function startService(options) {
16526
16654
  });
16527
16655
  let serviceReadyForAutoUpdate = false;
16528
16656
  let pendingRelayVersion = null;
16529
- relayConnection.on("relay_version", (version) => {
16530
- pendingRelayVersion = version;
16657
+ const considerRelayVersion = (version) => {
16658
+ pendingRelayVersion = selectHighestStableVersion(pendingRelayVersion, version);
16531
16659
  if (serviceReadyForAutoUpdate) autoUpdater.considerRelayVersion(version);
16660
+ };
16661
+ const upgradeBootstrap = createRelayUpgradeBootstrapMonitor({
16662
+ relayUrl,
16663
+ token: relayToken,
16664
+ logger: serviceLogger,
16665
+ onVersion: considerRelayVersion
16532
16666
  });
16667
+ relayConnection.on("relay_version", considerRelayVersion);
16668
+ relayConnection.on("connected", () => upgradeBootstrap.markControlProtocolConnected());
16669
+ relayConnection.on("disconnected", () => upgradeBootstrap.request());
16670
+ upgradeBootstrap.request();
16533
16671
  const relaySend = (data) => relayConnection.sendRaw(data);
16534
16672
  const previewManager = new PreviewManager({
16535
16673
  persistPath: PREVIEWS_PATH,
@@ -16753,7 +16891,10 @@ async function startService(options) {
16753
16891
  });
16754
16892
  const shutdown = createServeShutdown({
16755
16893
  logger: serviceLogger,
16756
- autoUpdaterDispose: () => autoUpdater.dispose(),
16894
+ autoUpdaterDispose: () => {
16895
+ upgradeBootstrap.dispose();
16896
+ autoUpdater.dispose();
16897
+ },
16757
16898
  sessionManagerStopReaper: () => sessionManager.stopReaper(),
16758
16899
  relayRouterDestroy: () => relayRouter.destroy(),
16759
16900
  previewManagerShutdown: () => previewManager.shutdown(),