@spencer-kit/coder-studio 0.4.6 → 0.4.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.
@@ -12231,6 +12231,13 @@ var init_manager5 = __esm({
12231
12231
  ...derivedColorFgBg ? { COLORFGBG: derivedColorFgBg } : {},
12232
12232
  ...spec.env
12233
12233
  };
12234
+ delete terminalEnv.COLORFGBG;
12235
+ if (derivedColorFgBg) {
12236
+ terminalEnv.COLORFGBG = derivedColorFgBg;
12237
+ }
12238
+ if (spec.env?.COLORFGBG) {
12239
+ terminalEnv.COLORFGBG = spec.env.COLORFGBG;
12240
+ }
12234
12241
  let pty;
12235
12242
  try {
12236
12243
  pty = this.deps.ptyHost.spawn(spec.argv, {
@@ -12630,7 +12637,7 @@ var init_update_service = __esm({
12630
12637
  "packages/server/src/update/update-service.ts"() {
12631
12638
  "use strict";
12632
12639
  init_src3();
12633
- UpdateService = class {
12640
+ UpdateService = class _UpdateService {
12634
12641
  constructor(deps) {
12635
12642
  this.deps = deps;
12636
12643
  this.now = deps.now ?? Date.now;
@@ -12652,12 +12659,14 @@ var init_update_service = __esm({
12652
12659
  this.spawnDetachedWorkerImpl = deps.spawnDetachedWorker;
12653
12660
  }
12654
12661
  deps;
12662
+ static CHECK_TIMEOUT_MS = 15e3;
12655
12663
  now;
12656
12664
  runtime;
12657
12665
  updateWorkerLogFilePath;
12658
12666
  runLatestVersionLookup;
12659
12667
  spawnDetachedWorkerImpl;
12660
12668
  scheduleTimer = null;
12669
+ inFlightCheck = null;
12661
12670
  start() {
12662
12671
  this.reconcileOnStartup();
12663
12672
  this.reloadScheduleFromSettings();
@@ -12688,10 +12697,8 @@ var init_update_service = __esm({
12688
12697
  this.scheduleTimer.unref?.();
12689
12698
  }
12690
12699
  getStateView() {
12691
- return {
12692
- ...this.deps.updateStateRepo.get(),
12693
- ...this.getSupportInfo()
12694
- };
12700
+ const persisted = this.deps.updateStateRepo.get();
12701
+ return this.composeStateView(persisted);
12695
12702
  }
12696
12703
  getPrepareInstallState() {
12697
12704
  const state = this.getStateView();
@@ -12708,36 +12715,15 @@ var init_update_service = __esm({
12708
12715
  if (current.updateStatus === "installing" || current.updateStatus === "restarting") {
12709
12716
  throw createBusyError("Update installation is already in progress");
12710
12717
  }
12711
- if (current.updateStatus === "checking") {
12718
+ if (this.inFlightCheck) {
12712
12719
  throw createBusyError("Update check is already in progress");
12713
12720
  }
12714
- this.persistAndBroadcast({
12715
- updateStatus: "checking",
12716
- finishedAt: null,
12717
- errorSummary: null
12718
- });
12721
+ this.inFlightCheck = this.runCheckForUpdates();
12722
+ this.broadcastStateChange();
12719
12723
  try {
12720
- const latestVersion = await this.runLatestVersionLookup(this.runtime.packageName);
12721
- const availability = compareVersions(latestVersion, this.runtime.currentVersion) > 0 ? "update_available" : "up_to_date";
12722
- return this.persistAndBroadcast({
12723
- currentVersion: this.runtime.currentVersion,
12724
- latestVersion,
12725
- availability,
12726
- updateStatus: "idle",
12727
- lastCheckedAt: this.now(),
12728
- errorSummary: null,
12729
- requiresManualStep: false,
12730
- manualCommand: null
12731
- });
12732
- } catch (error) {
12733
- const message = error instanceof Error ? error.message : String(error);
12734
- return this.persistAndBroadcast({
12735
- currentVersion: this.runtime.currentVersion,
12736
- availability: "check_failed",
12737
- updateStatus: "idle",
12738
- lastCheckedAt: this.now(),
12739
- errorSummary: message
12740
- });
12724
+ return await this.inFlightCheck;
12725
+ } finally {
12726
+ this.inFlightCheck = null;
12741
12727
  }
12742
12728
  }
12743
12729
  prepareInstall() {
@@ -12752,6 +12738,9 @@ var init_update_service = __esm({
12752
12738
  if (state.updateStatus === "installing" || state.updateStatus === "restarting") {
12753
12739
  throw createBusyError("Update installation is already in progress");
12754
12740
  }
12741
+ if (this.inFlightCheck) {
12742
+ throw createBusyError("Update check is already in progress");
12743
+ }
12755
12744
  const targetVersion = input.targetVersion ?? state.latestVersion;
12756
12745
  if (!targetVersion) {
12757
12746
  throw createValidationError("update_no_target", "No target version is available");
@@ -12826,6 +12815,15 @@ var init_update_service = __esm({
12826
12815
  errorSummary: null
12827
12816
  });
12828
12817
  }
12818
+ if (current.updateStatus === "checking") {
12819
+ return this.persistAndBroadcast({
12820
+ currentVersion: this.runtime.currentVersion,
12821
+ availability: "check_failed",
12822
+ updateStatus: "failed",
12823
+ finishedAt: this.now(),
12824
+ errorSummary: "Update check did not complete before the service restarted"
12825
+ });
12826
+ }
12829
12827
  if (current.updateStatus === "installing" || current.updateStatus === "restarting") {
12830
12828
  return this.persistAndBroadcast({
12831
12829
  currentVersion: this.runtime.currentVersion,
@@ -12876,18 +12874,6 @@ var init_update_service = __esm({
12876
12874
  hasActiveWork: runningTerminalCount > 0 || runningSessionCount > 0 || runningSupervisorCount > 0
12877
12875
  };
12878
12876
  }
12879
- persistAndBroadcast(patch) {
12880
- const snapshot = this.deps.updateStateRepo.update((current) => ({
12881
- ...patch,
12882
- currentVersion: patch.currentVersion ?? current.currentVersion
12883
- }));
12884
- const view = {
12885
- ...snapshot,
12886
- ...this.getSupportInfo()
12887
- };
12888
- this.deps.broadcaster.broadcast("update.state.changed", view);
12889
- return view;
12890
- }
12891
12877
  buildManualCommand(targetVersion) {
12892
12878
  return [
12893
12879
  `${this.runtime.npmCommand ?? "npm"} install -g ${this.runtime.packageName}@${targetVersion}`,
@@ -12917,6 +12903,83 @@ var init_update_service = __esm({
12917
12903
  });
12918
12904
  child.unref();
12919
12905
  }
12906
+ composeStateView(snapshot, options) {
12907
+ if (options?.includeInFlightCheck !== false && this.inFlightCheck) {
12908
+ return {
12909
+ ...snapshot,
12910
+ ...this.getSupportInfo(),
12911
+ updateStatus: "checking",
12912
+ errorSummary: null
12913
+ };
12914
+ }
12915
+ return {
12916
+ ...snapshot,
12917
+ ...this.getSupportInfo()
12918
+ };
12919
+ }
12920
+ broadcastStateChange() {
12921
+ this.deps.broadcaster.broadcast("update.state.changed", this.getStateView());
12922
+ }
12923
+ async runCheckForUpdates() {
12924
+ try {
12925
+ const latestVersion = await this.withCheckTimeout(
12926
+ this.runLatestVersionLookup(this.runtime.packageName)
12927
+ );
12928
+ const availability = compareVersions(latestVersion, this.runtime.currentVersion) > 0 ? "update_available" : "up_to_date";
12929
+ return this.persistAndBroadcast(
12930
+ {
12931
+ currentVersion: this.runtime.currentVersion,
12932
+ latestVersion,
12933
+ availability,
12934
+ updateStatus: "idle",
12935
+ lastCheckedAt: this.now(),
12936
+ errorSummary: null,
12937
+ requiresManualStep: false,
12938
+ manualCommand: null
12939
+ },
12940
+ false
12941
+ );
12942
+ } catch (error) {
12943
+ const message = error instanceof Error ? error.message : String(error);
12944
+ return this.persistAndBroadcast(
12945
+ {
12946
+ currentVersion: this.runtime.currentVersion,
12947
+ availability: "check_failed",
12948
+ updateStatus: "idle",
12949
+ lastCheckedAt: this.now(),
12950
+ errorSummary: message
12951
+ },
12952
+ false
12953
+ );
12954
+ }
12955
+ }
12956
+ async withCheckTimeout(promise) {
12957
+ let timeoutHandle = null;
12958
+ try {
12959
+ return await Promise.race([
12960
+ promise,
12961
+ new Promise((_, reject) => {
12962
+ timeoutHandle = setTimeout(() => {
12963
+ reject(new Error(`Update check timed out after ${_UpdateService.CHECK_TIMEOUT_MS}ms`));
12964
+ }, _UpdateService.CHECK_TIMEOUT_MS);
12965
+ timeoutHandle.unref?.();
12966
+ })
12967
+ ]);
12968
+ } finally {
12969
+ if (timeoutHandle) {
12970
+ clearTimeout(timeoutHandle);
12971
+ }
12972
+ }
12973
+ }
12974
+ persistAndBroadcast(patch, includeInFlightCheck = true) {
12975
+ const snapshot = this.deps.updateStateRepo.update((current) => ({
12976
+ ...patch,
12977
+ currentVersion: patch.currentVersion ?? current.currentVersion
12978
+ }));
12979
+ const view = this.composeStateView(snapshot, { includeInFlightCheck });
12980
+ this.deps.broadcaster.broadcast("update.state.changed", view);
12981
+ return view;
12982
+ }
12920
12983
  };
12921
12984
  }
12922
12985
  });