@astrale-os/cli 1.0.0-beta.19 → 1.0.0-beta.20

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/astrale.js CHANGED
@@ -2578,7 +2578,7 @@ var package_default;
2578
2578
  var init_package = __esm(() => {
2579
2579
  package_default = {
2580
2580
  name: "@astrale-os/cli",
2581
- version: "1.0.0-beta.19",
2581
+ version: "1.0.0-beta.20",
2582
2582
  description: "Astrale CLI — connect to existing Astrale kernels",
2583
2583
  keywords: [
2584
2584
  "astrale",
@@ -2654,8 +2654,8 @@ var init_package = __esm(() => {
2654
2654
  },
2655
2655
  devDependencies: {
2656
2656
  "@astrale-os/ox": ">=0.1.3 <1.0.0",
2657
- "@astrale-os/sdk": "0.5.0-beta.49",
2658
- "@astrale-os/shell": "0.4.2-beta.3",
2657
+ "@astrale-os/sdk": "0.5.0-beta.50",
2658
+ "@astrale-os/shell": "0.4.2-beta.5",
2659
2659
  "@astrale/commitlint-config": "jsr:~2.0.1",
2660
2660
  "@commitlint/cli": "21.2.2",
2661
2661
  "@commitlint/config-conventional": "21.2.2",
@@ -33806,7 +33806,7 @@ var init_paths = __esm(() => {
33806
33806
  init_url();
33807
33807
  });
33808
33808
 
33809
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/configuration.js
33809
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/configuration.js
33810
33810
  var init_configuration3 = __esm(() => {
33811
33811
  init_configuration2();
33812
33812
  init_paths();
@@ -34023,12 +34023,12 @@ var init_exchange = __esm(() => {
34023
34023
  init_errors5();
34024
34024
  });
34025
34025
 
34026
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/response.js
34026
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/response.js
34027
34027
  var init_response = __esm(() => {
34028
34028
  init_exchange();
34029
34029
  });
34030
34030
 
34031
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/index.js
34031
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/exchange/index.js
34032
34032
  var exports_exchange = {};
34033
34033
  __export(exports_exchange, {
34034
34034
  MEDIA_TYPE: () => MEDIA_TYPE,
@@ -34042,7 +34042,7 @@ var init_exchange2 = __esm(() => {
34042
34042
  init_response();
34043
34043
  });
34044
34044
 
34045
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/index.js
34045
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/auth/index.js
34046
34046
  var init_auth4 = __esm(() => {
34047
34047
  init_auth3();
34048
34048
  init_exchange2();
@@ -37691,7 +37691,7 @@ var init_dns_label = __esm(() => {
37691
37691
  dnsLabelSchema = exports_external.string().min(1).max(63).regex(DNS_LABEL_RE, "must be a lowercase DNS label [a-z0-9-], ≤63 chars, no leading/trailing hyphen");
37692
37692
  });
37693
37693
 
37694
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/value/index.js
37694
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/value/index.js
37695
37695
  var init_value3 = __esm(() => {
37696
37696
  init_dns_label();
37697
37697
  init_value();
@@ -47274,18 +47274,18 @@ var init_graph4 = __esm(() => {
47274
47274
  init_query();
47275
47275
  });
47276
47276
 
47277
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/client/index.js
47277
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/client/index.js
47278
47278
  var init_client3 = __esm(() => {
47279
47279
  init_graph4();
47280
47280
  init_dist2();
47281
47281
  });
47282
47282
 
47283
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/node/index.js
47283
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/node/index.js
47284
47284
  var init_node2 = __esm(() => {
47285
47285
  init_node();
47286
47286
  });
47287
47287
 
47288
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/path/index.js
47288
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/path/index.js
47289
47289
  var init_path3 = __esm(() => {
47290
47290
  init_path2();
47291
47291
  });
@@ -47761,10 +47761,36 @@ async function realpathIfExists(path2) {
47761
47761
  throw error52;
47762
47762
  }
47763
47763
  }
47764
- async function writeInstallMetadata(meta3, path2 = INSTALL_PATH) {
47765
- await mkdir6(dirname6(path2), { recursive: true });
47766
- await writeFile2(path2, JSON.stringify(meta3, null, 2) + `
47764
+ async function writeInstallMetadata(meta3, path2 = INSTALL_PATH, filesystem = { mkdir: mkdir6, rename: rename2, rm, writeFile: writeFile2 }) {
47765
+ const staged = `${path2}.next`;
47766
+ const previous = `${path2}.previous`;
47767
+ await filesystem.mkdir(dirname6(path2), { recursive: true });
47768
+ await filesystem.rm(staged, { force: true });
47769
+ await filesystem.rm(previous, { force: true });
47770
+ await filesystem.writeFile(staged, JSON.stringify(meta3, null, 2) + `
47767
47771
  `);
47772
+ let backedUp = false;
47773
+ try {
47774
+ try {
47775
+ await filesystem.rename(path2, previous);
47776
+ backedUp = true;
47777
+ } catch (error52) {
47778
+ if (!isMissingFile(error52))
47779
+ throw error52;
47780
+ }
47781
+ await filesystem.rename(staged, path2);
47782
+ await filesystem.rm(previous, { force: true });
47783
+ } catch (error52) {
47784
+ const rollback = [];
47785
+ if (backedUp) {
47786
+ await filesystem.rename(previous, path2).catch((failure) => rollback.push(failure));
47787
+ }
47788
+ await filesystem.rm(staged, { force: true }).catch((failure) => rollback.push(failure));
47789
+ if (rollback.length > 0) {
47790
+ throw new AggregateError([error52, ...rollback], "Install metadata update and rollback both failed.");
47791
+ }
47792
+ throw error52;
47793
+ }
47768
47794
  }
47769
47795
  function releaseBase(meta3, req) {
47770
47796
  if (process.env.ASTRALE_UPDATE_BASE)
@@ -47783,7 +47809,101 @@ async function fetchManifest(base2) {
47783
47809
  function shouldUpdate(currentVersion, manifestVersion) {
47784
47810
  return currentVersion !== manifestVersion;
47785
47811
  }
47786
- async function updateAstrale(req) {
47812
+ async function replaceStandaloneCohort(installedBinary, nextBinary, nextViewerDist, filesystem = {}) {
47813
+ const fs = { ...defaultCohortFilesystem, ...filesystem };
47814
+ const binDirectory = dirname6(installedBinary);
47815
+ const previousBinary = `${installedBinary}.previous`;
47816
+ const stagedBinary = `${installedBinary}.next`;
47817
+ const viewer = join4(binDirectory, "viewer");
47818
+ const previousViewer = join4(binDirectory, "viewer.previous");
47819
+ const stagedViewer = join4(binDirectory, "viewer.next");
47820
+ const stagedViewerDist = join4(stagedViewer, "dist");
47821
+ try {
47822
+ await fs.rm(stagedViewer, { recursive: true, force: true });
47823
+ await fs.mkdir(stagedViewerDist, { recursive: true });
47824
+ await fs.copyFile(join4(nextViewerDist, "main.js"), join4(stagedViewerDist, "main.js"));
47825
+ await fs.copyFile(join4(nextViewerDist, "index.html"), join4(stagedViewerDist, "index.html"));
47826
+ await fs.copyFile(installedBinary, previousBinary);
47827
+ await fs.copyFile(nextBinary, stagedBinary);
47828
+ await fs.chmod(stagedBinary, 493);
47829
+ } catch (error52) {
47830
+ await fs.rm(stagedViewer, { recursive: true, force: true }).catch(() => {
47831
+ return;
47832
+ });
47833
+ await fs.rm(stagedBinary, { force: true }).catch(() => {
47834
+ return;
47835
+ });
47836
+ throw error52;
47837
+ }
47838
+ await fs.rm(previousViewer, { recursive: true, force: true });
47839
+ let viewerBackedUp = false;
47840
+ let viewerCommitted = false;
47841
+ let binaryCommitted = false;
47842
+ try {
47843
+ try {
47844
+ await fs.rename(viewer, previousViewer);
47845
+ viewerBackedUp = true;
47846
+ } catch (error52) {
47847
+ if (error52.code !== "ENOENT")
47848
+ throw error52;
47849
+ }
47850
+ await fs.rename(stagedViewer, viewer);
47851
+ viewerCommitted = true;
47852
+ await fs.rename(stagedBinary, installedBinary);
47853
+ binaryCommitted = true;
47854
+ } catch (error52) {
47855
+ const rollback = [];
47856
+ if (binaryCommitted) {
47857
+ await fs.copyFile(previousBinary, installedBinary).catch((failure) => rollback.push(failure));
47858
+ await fs.chmod(installedBinary, 493).catch((failure) => rollback.push(failure));
47859
+ }
47860
+ if (viewerCommitted) {
47861
+ await fs.rm(viewer, { recursive: true, force: true }).catch((failure) => rollback.push(failure));
47862
+ }
47863
+ if (viewerBackedUp) {
47864
+ await fs.rename(previousViewer, viewer).catch((failure) => rollback.push(failure));
47865
+ }
47866
+ if (rollback.length > 0) {
47867
+ throw new AggregateError([error52, ...rollback], "Standalone update and rollback both failed.");
47868
+ }
47869
+ throw error52;
47870
+ } finally {
47871
+ await fs.rm(stagedViewer, { recursive: true, force: true }).catch(() => {
47872
+ return;
47873
+ });
47874
+ await fs.rm(stagedBinary, { force: true }).catch(() => {
47875
+ return;
47876
+ });
47877
+ }
47878
+ let settled = false;
47879
+ return Object.freeze({
47880
+ finalize: async () => {
47881
+ if (settled)
47882
+ return;
47883
+ settled = true;
47884
+ await fs.rm(previousViewer, { recursive: true, force: true }).catch(() => {
47885
+ return;
47886
+ });
47887
+ },
47888
+ rollback: async () => {
47889
+ if (settled)
47890
+ return;
47891
+ settled = true;
47892
+ const rollback = [];
47893
+ await fs.copyFile(previousBinary, installedBinary).catch((failure) => rollback.push(failure));
47894
+ await fs.chmod(installedBinary, 493).catch((failure) => rollback.push(failure));
47895
+ await fs.rm(viewer, { recursive: true, force: true }).catch((failure) => rollback.push(failure));
47896
+ if (viewerBackedUp) {
47897
+ await fs.rename(previousViewer, viewer).catch((failure) => rollback.push(failure));
47898
+ }
47899
+ if (rollback.length > 0) {
47900
+ throw new AggregateError(rollback, "Standalone update rollback failed.");
47901
+ }
47902
+ }
47903
+ });
47904
+ }
47905
+ async function updateAstrale(req, dependencies = {}) {
47906
+ const update = { ...defaultUpdateDependencies, ...dependencies };
47787
47907
  const execution = req.execution ?? detectUpdateExecution();
47788
47908
  if (execution.kind === "package-managed") {
47789
47909
  return {
@@ -47832,22 +47952,26 @@ async function updateAstrale(req) {
47832
47952
  }
47833
47953
  await extractTarGz(archive, tmp);
47834
47954
  const nextBin = join4(tmp, "astrale");
47955
+ const nextViewer = join4(tmp, "viewer", "dist");
47835
47956
  await chmod2(nextBin, 493);
47836
47957
  await smokeVersion(nextBin, manifest.binaryVersion ?? manifest.version);
47837
- const previous = `${meta3.bin}.previous`;
47838
- const staged = `${meta3.bin}.next`;
47839
- await copyFile(meta3.bin, previous).catch(() => {
47840
- return;
47841
- });
47842
- await copyFile(nextBin, staged);
47843
- await chmod2(staged, 493);
47844
- await rename2(staged, meta3.bin);
47845
- await writeInstallMetadata({
47846
- ...meta3,
47847
- channel: manifest.channel,
47848
- version: manifest.version,
47849
- installedAt: new Date().toISOString()
47850
- }, req.installPath);
47958
+ const replacement = await update.replaceStandaloneCohort(meta3.bin, nextBin, nextViewer);
47959
+ try {
47960
+ await update.writeInstallMetadata({
47961
+ ...meta3,
47962
+ channel: manifest.channel,
47963
+ version: manifest.version,
47964
+ installedAt: new Date().toISOString()
47965
+ }, req.installPath);
47966
+ } catch (error52) {
47967
+ try {
47968
+ await replacement.rollback();
47969
+ } catch (rollbackError) {
47970
+ throw new AggregateError([error52, rollbackError], "Standalone update metadata commit and cohort rollback both failed.");
47971
+ }
47972
+ throw error52;
47973
+ }
47974
+ await replacement.finalize();
47851
47975
  return {
47852
47976
  status: "updated",
47853
47977
  previousVersion: currentVersion,
@@ -47910,7 +48034,7 @@ async function smokeVersion(bin, expectedVersion) {
47910
48034
  throw new Error(`Updated binary reported version ${actual}, expected ${expectedVersion}`);
47911
48035
  }
47912
48036
  }
47913
- var DEFAULT_REPO = "astrale-os/cli", DEFAULT_UPDATE_CHANNEL = "beta", InstallMetadataSchema, ManifestAssetSchema, UpdateManifestSchema, admittedScriptInstall;
48037
+ var DEFAULT_REPO = "astrale-os/cli", DEFAULT_UPDATE_CHANNEL = "beta", InstallMetadataSchema, ManifestAssetSchema, UpdateManifestSchema, admittedScriptInstall, defaultCohortFilesystem, defaultUpdateDependencies;
47914
48038
  var init_update = __esm(() => {
47915
48039
  init_zod();
47916
48040
  init_errors2();
@@ -47939,6 +48063,8 @@ var init_update = __esm(() => {
47939
48063
  ]))
47940
48064
  });
47941
48065
  admittedScriptInstall = Symbol("admittedScriptInstall");
48066
+ defaultCohortFilesystem = { chmod: chmod2, copyFile, mkdir: mkdir6, rename: rename2, rm };
48067
+ defaultUpdateDependencies = Object.freeze({ replaceStandaloneCohort, writeInstallMetadata });
47942
48068
  });
47943
48069
 
47944
48070
  // src/lib/admin-target.ts
@@ -75670,7 +75796,7 @@ var init_schema8 = __esm(() => {
75670
75796
  init_core5();
75671
75797
  });
75672
75798
 
75673
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/schema/index.js
75799
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/schema/index.js
75674
75800
  var KernelSchema2;
75675
75801
  var init_schema9 = __esm(() => {
75676
75802
  init_schema8();
@@ -79267,7 +79393,7 @@ var init_session2 = __esm(() => {
79267
79393
  init_reference3();
79268
79394
  });
79269
79395
 
79270
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/client/session/index.js
79396
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/client/session/index.js
79271
79397
  var init_session3 = __esm(() => {
79272
79398
  init_session2();
79273
79399
  });
@@ -81855,7 +81981,7 @@ Examples:
81855
81981
  };
81856
81982
  });
81857
81983
 
81858
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/class/index.js
81984
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/class/index.js
81859
81985
  var init_class5 = __esm(() => {
81860
81986
  init_addressing();
81861
81987
  });
@@ -81881,7 +82007,7 @@ var init_class6 = __esm(() => {
81881
82007
  init_path3();
81882
82008
  });
81883
82009
 
81884
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/application/mutation/index.js
82010
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/application/mutation/index.js
81885
82011
  var init_mutation2 = __esm(() => {
81886
82012
  init_mutate();
81887
82013
  });
@@ -81910,7 +82036,7 @@ function isLegacyPatchData(input) {
81910
82036
  var init_mutation3 = __esm(() => {
81911
82037
  init_mutation2();
81912
82038
  });
81913
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/application/query/index.js
82039
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/application/query/index.js
81914
82040
  var init_query5 = __esm(() => {
81915
82041
  init_query();
81916
82042
  });
@@ -82701,6 +82827,32 @@ async function findFreePort(start, span = 20, host = LOOPBACK) {
82701
82827
  var LOOPBACK = "127.0.0.1";
82702
82828
  var init_port = () => {};
82703
82829
 
82830
+ // src/lib/view/external-open-origins.ts
82831
+ function admitExternalOpenOrigins(input) {
82832
+ if (input === undefined)
82833
+ return Object.freeze([]);
82834
+ const admitted = new Set;
82835
+ for (const candidate2 of input) {
82836
+ let url3;
82837
+ try {
82838
+ url3 = new URL(candidate2);
82839
+ } catch (cause) {
82840
+ throw invalidExternalOrigin(candidate2, cause);
82841
+ }
82842
+ if (url3.protocol !== "https:" || url3.hostname.includes("*") || url3.username !== "" || url3.password !== "" || url3.pathname !== "/" || url3.search !== "" || url3.hash !== "") {
82843
+ throw invalidExternalOrigin(candidate2);
82844
+ }
82845
+ admitted.add(url3.origin);
82846
+ }
82847
+ return Object.freeze([...admitted]);
82848
+ }
82849
+ function invalidExternalOrigin(candidate2, cause) {
82850
+ return new AstraleError("INVALID_EXTERNAL_ORIGIN", `External navigation grant "${candidate2}" is not an exact HTTPS origin.`, "Pass an origin such as https://connect.example.com with no credentials, path, query, or fragment.", cause === undefined ? undefined : { cause });
82851
+ }
82852
+ var init_external_open_origins = __esm(() => {
82853
+ init_errors2();
82854
+ });
82855
+
82704
82856
  // src/lib/view/session.ts
82705
82857
  import { closeSync, fchmodSync, openSync } from "node:fs";
82706
82858
  import { chmod as chmod3, mkdir as mkdir9, readdir as readdir2, readFile as readFile12, rm as rm2 } from "node:fs/promises";
@@ -82873,7 +83025,7 @@ import { existsSync as existsSync5, statSync } from "node:fs";
82873
83025
  import { copyFile as copyFile2 } from "node:fs/promises";
82874
83026
  import { dirname as dirname9, join as join13 } from "node:path";
82875
83027
  import { fileURLToPath } from "node:url";
82876
- function viewerDistDir(moduleUrl = import.meta.url, entry2 = process.argv[1] ?? ".") {
83028
+ function viewerDistDir(moduleUrl = import.meta.url, entry2 = process.argv[1] ?? ".", executable = process.execPath) {
82877
83029
  const override = process.env.ASTRALE_VIEWER_DIR;
82878
83030
  if (override)
82879
83031
  return override;
@@ -82881,7 +83033,8 @@ function viewerDistDir(moduleUrl = import.meta.url, entry2 = process.argv[1] ??
82881
83033
  const published = join13(moduleDirectory, "..", "viewer", "dist");
82882
83034
  const source2 = join13(moduleDirectory, "..", "..", "..", "viewer", "dist");
82883
83035
  const legacy = join13(dirname9(entry2), "..", "viewer", "dist");
82884
- const complete = [published, source2, legacy].find(hasViewerBundle);
83036
+ const standalone = entry2.startsWith("/$bunfs/") ? join13(dirname9(executable), "viewer", "dist") : undefined;
83037
+ const complete = [standalone, published, source2, legacy].find((candidate2) => candidate2 !== undefined && hasViewerBundle(candidate2));
82885
83038
  if (complete)
82886
83039
  return complete;
82887
83040
  if (hasViewerSource(join13(source2, "..")))
@@ -82991,7 +83144,8 @@ function startViewServer(config2) {
82991
83144
  kernelIssuer: proxy.issuer,
82992
83145
  identity: session3.identity ?? null,
82993
83146
  instance: session3.instance ?? null,
82994
- sessionId: session3.id
83147
+ sessionId: session3.id,
83148
+ externalOrigins: config2.externalOrigins
82995
83149
  });
82996
83150
  return;
82997
83151
  }
@@ -83204,11 +83358,15 @@ var init_snapshot = __esm(() => {
83204
83358
  // src/commands/view.ts
83205
83359
  var exports_view3 = {};
83206
83360
  __export(exports_view3, {
83361
+ createViewServeConfig: () => createViewServeConfig,
83207
83362
  default: () => view_default,
83208
83363
  devDistIsStale: () => devDistIsStale,
83364
+ directServeRuntime: () => directServeRuntime,
83209
83365
  rejectUnrepresentableOverrides: () => rejectUnrepresentableOverrides,
83366
+ resolveServeRuntime: () => resolveServeRuntime,
83210
83367
  resolveSession: () => resolveSession,
83211
- runSnapshotExtras: () => runSnapshotExtras
83368
+ runSnapshotExtras: () => runSnapshotExtras,
83369
+ viewServeInvocation: () => viewServeInvocation
83212
83370
  });
83213
83371
  import { randomBytes } from "node:crypto";
83214
83372
  import { closeSync as closeSync2, existsSync as existsSync6, statSync as statSync2 } from "node:fs";
@@ -83259,18 +83417,30 @@ async function chooseCandidate(candidates, anchor, selector, opts) {
83259
83417
  }
83260
83418
  throw new AstraleError("AMBIGUOUS_VIEW", `${anchor} resolves ${candidates.length} views — pick one with --view <slug>: ${candidates.map(candidateSlug).join(", ")}`);
83261
83419
  }
83262
- async function resolveServeRuntime() {
83263
- const entry2 = process.argv[1];
83264
- const node4 = await findOnPath("node");
83265
- if (node4 && entry2?.endsWith(".js") && existsSync6(entry2))
83420
+ async function resolveServeRuntime(environment = {}) {
83421
+ const entry2 = environment.entry ?? process.argv[1];
83422
+ const executable = environment.executable ?? process.execPath;
83423
+ const exists = environment.exists ?? existsSync6;
83424
+ const find = environment.find ?? findOnPath;
83425
+ const node4 = await find("node");
83426
+ if (node4 && entry2?.endsWith(".js") && exists(entry2))
83266
83427
  return { file: node4, args: [entry2] };
83267
83428
  if (node4 && entry2?.endsWith(".ts")) {
83268
83429
  const dist = join15(dirname10(entry2), "..", "dist", "astrale.js");
83269
83430
  await ensureDevDist(entry2, dist);
83270
- if (existsSync6(dist))
83431
+ if (exists(dist))
83271
83432
  return { file: node4, args: [dist] };
83272
83433
  }
83273
- return { file: process.execPath, args: entry2 && existsSync6(entry2) ? [entry2] : [] };
83434
+ return directServeRuntime(executable, entry2, entry2 !== undefined && exists(entry2));
83435
+ }
83436
+ function directServeRuntime(executable, entry2, entryExists = entry2 !== undefined && existsSync6(entry2)) {
83437
+ return {
83438
+ file: executable,
83439
+ args: entry2 && !entry2.startsWith("/$bunfs/") && entryExists ? [entry2] : []
83440
+ };
83441
+ }
83442
+ function viewServeInvocation(runtime, config2) {
83443
+ return { file: runtime.file, args: [...runtime.args, "__view-serve", "--config", config2] };
83274
83444
  }
83275
83445
  async function findOnPath(name) {
83276
83446
  const lookup = process.platform === "win32" ? run("where", [name]) : run("sh", ["-c", `command -v ${name}`]);
@@ -83333,6 +83503,26 @@ async function startSession(view2, opts) {
83333
83503
  ]);
83334
83504
  return withViewPortAllocationLock(() => startSessionLocked(view2, opts, kernelTarget, instances.active, identities.default, runtime));
83335
83505
  }
83506
+ function createViewServeConfig(record12, opts, kernelTarget) {
83507
+ return {
83508
+ session: record12,
83509
+ kernel: {
83510
+ url: opts.url,
83511
+ instance: opts.instance,
83512
+ as: opts.as,
83513
+ creds: opts.creds,
83514
+ timeout: opts.timeout
83515
+ },
83516
+ proxy: {
83517
+ kernelUrl: kernelTarget.url,
83518
+ issuer: kernelTarget.kernelIssuer,
83519
+ caFile: kernelTarget.caFile,
83520
+ direct: isPublicHttps(kernelTarget.url) && !kernelTarget.caFile
83521
+ },
83522
+ externalOrigins: admitExternalOpenOrigins(opts.allowExternalOrigin),
83523
+ idleMs: IDLE_MS
83524
+ };
83525
+ }
83336
83526
  async function startSessionLocked(view2, opts, kernelTarget, activeInstance, defaultIdentity, runtime) {
83337
83527
  const port = await findFreePort(VIEW_PORT_BASE, VIEW_PORT_SPAN);
83338
83528
  if (port === null) {
@@ -83351,26 +83541,11 @@ async function startSessionLocked(view2, opts, kernelTarget, activeInstance, def
83351
83541
  identity: opts.creds ? "(pre-signed creds)" : opts.as ?? defaultIdentity,
83352
83542
  createdAt: new Date().toISOString()
83353
83543
  };
83354
- const serveConfig = {
83355
- session: record12,
83356
- kernel: {
83357
- url: opts.url,
83358
- instance: opts.instance,
83359
- as: opts.as,
83360
- creds: opts.creds,
83361
- timeout: opts.timeout
83362
- },
83363
- proxy: {
83364
- kernelUrl: kernelTarget.url,
83365
- issuer: kernelTarget.kernelIssuer,
83366
- caFile: kernelTarget.caFile,
83367
- direct: isPublicHttps(kernelTarget.url) && !kernelTarget.caFile
83368
- },
83369
- idleMs: IDLE_MS
83370
- };
83544
+ const serveConfig = createViewServeConfig(record12, opts, kernelTarget);
83371
83545
  await saveServeConfig(serveConfig);
83372
83546
  const logFd = await openSessionLog(id);
83373
- const child3 = spawnHandle(runtime.file, [...runtime.args, "__view-serve", "--config", configPath(id)], {
83547
+ const invocation3 = viewServeInvocation(runtime, configPath(id));
83548
+ const child3 = spawnHandle(invocation3.file, invocation3.args, {
83374
83549
  detached: true,
83375
83550
  stdio: ["ignore", logFd, logFd]
83376
83551
  });
@@ -83538,6 +83713,7 @@ var init_view7 = __esm(() => {
83538
83713
  init_output();
83539
83714
  init_port();
83540
83715
  init_proc();
83716
+ init_external_open_origins();
83541
83717
  init_port_allocation();
83542
83718
  init_resolve2();
83543
83719
  init_server();
@@ -83581,7 +83757,11 @@ var init_view7 = __esm(() => {
83581
83757
  flags: "--close [id]",
83582
83758
  description: "Close a view session (bare: the only open one; with --all: every session)"
83583
83759
  },
83584
- { flags: "--all", description: "With --close: close every session" }
83760
+ { flags: "--all", description: "With --close: close every session" },
83761
+ {
83762
+ flags: "--allow-external-origin <origin...>",
83763
+ description: "Grant this View exact HTTPS origins it may open in a new browser context"
83764
+ }
83585
83765
  ],
83586
83766
  afterHelpText: `
83587
83767
  What it does:
@@ -83600,6 +83780,7 @@ Examples:
83600
83780
  $ astrale view /:crm.example.dev:view.dashboard
83601
83781
  $ astrale view /:agents.astrale.ai:view.agent --target @f00d1234 --as alice
83602
83782
  $ astrale view @customer --snapshot
83783
+ $ astrale view /:integrations.astrale.ai:view.application --allow-external-origin https://connect.nango.dev https://connect.composio.dev
83603
83784
  $ astrale view --list
83604
83785
  $ astrale view --sessions ; astrale view --close --all
83605
83786
  `,
@@ -86313,7 +86494,7 @@ var init_dist20 = __esm(() => {
86313
86494
  init_issuer2();
86314
86495
  });
86315
86496
 
86316
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/publication/index.js
86497
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/publication/index.js
86317
86498
  var init_publication4 = __esm(() => {
86318
86499
  init_dist20();
86319
86500
  });
@@ -87237,17 +87418,17 @@ var init_create5 = __esm(() => {
87237
87418
  };
87238
87419
  });
87239
87420
 
87240
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/edge/index.js
87421
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/edge/index.js
87241
87422
  var init_edge3 = __esm(() => {
87242
87423
  init_edge();
87243
87424
  });
87244
87425
 
87245
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/properties/index.js
87426
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/properties/index.js
87246
87427
  var init_properties2 = __esm(() => {
87247
87428
  init_properties();
87248
87429
  });
87249
87430
 
87250
- // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.49_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/index.js
87431
+ // node_modules/.pnpm/@astrale-os+sdk@0.5.0-beta.50_@astrale-os+ox@0.1.3_oxfmt@0.63.0_oxlint@1.78.0__msgpackr@2.0.5_oxlint@1.78.0/node_modules/@astrale-os/sdk/dist/platform/graph/index.js
87251
87432
  var init_graph7 = __esm(() => {
87252
87433
  init_graph2();
87253
87434
  init_edge3();