@trops/dash-core 0.1.841 → 0.1.842

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.
@@ -2064,13 +2064,13 @@ const NAME_RE$1 = /^[a-z0-9][a-z0-9._-]{0,127}$/i;
2064
2064
  * `{ scope, name }`; null for a bare name (its scope is unknown) or
2065
2065
  * anything malformed.
2066
2066
  */
2067
- function normalizePackageRef(input) {
2067
+ function normalizePackageRef$2(input) {
2068
2068
  let scope;
2069
2069
  let name;
2070
2070
  if (input && typeof input === "object") {
2071
2071
  scope = input.scope;
2072
2072
  name = input.name;
2073
- if (!scope && typeof name === "string") return normalizePackageRef(name);
2073
+ if (!scope && typeof name === "string") return normalizePackageRef$2(name);
2074
2074
  } else if (typeof input === "string") {
2075
2075
  const m = input.trim().match(/^@?([^/]+)\/([^/]+)$/);
2076
2076
  if (!m) return null;
@@ -2096,7 +2096,7 @@ function bareName(pkg) {
2096
2096
 
2097
2097
  /** A `registryRef` to store on a record, or null when the package is unknown. */
2098
2098
  function makeRegistryRef$3({ package: pkg, kind, version, origin, at } = {}) {
2099
- const ref = normalizePackageRef(pkg);
2099
+ const ref = normalizePackageRef$2(pkg);
2100
2100
  if (!ref || !KINDS$3.includes(kind) || !ORIGINS.includes(origin)) return null;
2101
2101
  return {
2102
2102
  package: ref.id,
@@ -2111,7 +2111,7 @@ function makeRegistryRef$3({ package: pkg, kind, version, origin, at } = {}) {
2111
2111
  // an older record kept only a bare name; `name` is always the bare name,
2112
2112
  // lowercased.
2113
2113
  function found(pkg, kind, version, origin) {
2114
- const ref = normalizePackageRef(pkg);
2114
+ const ref = normalizePackageRef$2(pkg);
2115
2115
  const name = ref ? ref.name.toLowerCase() : bareName(pkg);
2116
2116
  if (!name) return null;
2117
2117
  return {
@@ -2132,10 +2132,10 @@ function found(pkg, kind, version, origin) {
2132
2132
  * @returns {{package: string|null, name: string, kind: string,
2133
2133
  * version: string|null, origin: "installed"|"published"|"local"}|null}
2134
2134
  */
2135
- function readRegistryRef(kind, record) {
2135
+ function readRegistryRef$2(kind, record) {
2136
2136
  if (!record || typeof record !== "object") return null;
2137
2137
  const r = record.registryRef;
2138
- if (r && r.kind === kind && normalizePackageRef(r.package)) {
2138
+ if (r && r.kind === kind && normalizePackageRef$2(r.package)) {
2139
2139
  return found(r.package, kind, r.version, r.origin);
2140
2140
  }
2141
2141
 
@@ -2195,7 +2195,7 @@ function readRegistryRef(kind, record) {
2195
2195
  * Whether two `readRegistryRef` results name the same package. When either
2196
2196
  * kept only a bare name, the bare names are compared.
2197
2197
  */
2198
- function samePackage(a, b) {
2198
+ function samePackage$1(a, b) {
2199
2199
  if (!a || !b) return false;
2200
2200
  if (a.package && b.package) {
2201
2201
  return a.package.toLowerCase() === b.package.toLowerCase();
@@ -2210,32 +2210,37 @@ function withoutRegistryRef$1(record) {
2210
2210
  return rest;
2211
2211
  }
2212
2212
 
2213
+ // Where a dashboard came from: `registryRef`, and `_dashboardConfig` (the
2214
+ // older record — install source, version, author, whether it can be
2215
+ // published).
2216
+ const PACKAGE_FIELDS = ["registryRef", "_dashboardConfig"];
2217
+
2213
2218
  /**
2214
2219
  * The record to store when `incoming` replaces `existing`: the dashboard
2215
- * editor saves from a model that doesn't carry `registryRef`, so the stored
2216
- * one is kept unless the incoming record says otherwise.
2220
+ * editor saves from a model that doesn't carry where the dashboard came
2221
+ * from, so the stored fields are kept unless the incoming record has them
2222
+ * (even as undefined, to clear one).
2217
2223
  */
2218
2224
  function keepRegistryRef$1(incoming, existing) {
2219
- if (
2220
- !incoming ||
2221
- !existing ||
2222
- "registryRef" in incoming ||
2223
- !existing.registryRef
2224
- ) {
2225
- return incoming;
2225
+ if (!incoming || !existing) return incoming;
2226
+ let out = incoming;
2227
+ for (const field of PACKAGE_FIELDS) {
2228
+ if (field in incoming || existing[field] === undefined) continue;
2229
+ if (out === incoming) out = { ...incoming };
2230
+ out[field] = existing[field];
2226
2231
  }
2227
- return { ...incoming, registryRef: existing.registryRef };
2232
+ return out;
2228
2233
  }
2229
2234
 
2230
2235
  var packageRef = {
2231
2236
  KINDS: KINDS$3,
2232
2237
  withoutRegistryRef: withoutRegistryRef$1,
2233
2238
  keepRegistryRef: keepRegistryRef$1,
2234
- normalizePackageRef,
2239
+ normalizePackageRef: normalizePackageRef$2,
2235
2240
  bareName,
2236
2241
  makeRegistryRef: makeRegistryRef$3,
2237
- readRegistryRef,
2238
- samePackage,
2242
+ readRegistryRef: readRegistryRef$2,
2243
+ samePackage: samePackage$1,
2239
2244
  };
2240
2245
 
2241
2246
  const { writeFileSync: writeFileSync$2 } = require$$0$3;
@@ -60544,7 +60549,7 @@ function _parse(v) {
60544
60549
  return { parts: m[1].split(".").map(Number), pre: m[2] || null };
60545
60550
  }
60546
60551
 
60547
- function isNewerVersion$1(latest, installed) {
60552
+ function isNewerVersion$2(latest, installed) {
60548
60553
  if (!latest || latest === installed) return false;
60549
60554
  const a = _parse(latest);
60550
60555
  const b = _parse(installed);
@@ -60561,7 +60566,7 @@ function isNewerVersion$1(latest, installed) {
60561
60566
  return false;
60562
60567
  }
60563
60568
 
60564
- var isNewerVersion_1 = { isNewerVersion: isNewerVersion$1 };
60569
+ var isNewerVersion_1 = { isNewerVersion: isNewerVersion$2 };
60565
60570
 
60566
60571
  /**
60567
60572
  * registryController.js
@@ -60579,7 +60584,7 @@ const path$d = require$$1$2;
60579
60584
  const fs$a = require$$0$3;
60580
60585
  const os$2 = require$$1$3;
60581
60586
  const { toPackageId } = packageId;
60582
- const { isNewerVersion } = isNewerVersion_1;
60587
+ const { isNewerVersion: isNewerVersion$1 } = isNewerVersion_1;
60583
60588
  const { getStoredToken: getStoredToken$2, authedFetch } = registryAuthController$1;
60584
60589
  const {
60585
60590
  registryDownloadFetch: registryDownloadFetch$2,
@@ -61046,7 +61051,7 @@ async function checkUpdates(installedWidgets = []) {
61046
61051
  if (!result || !result.exists) continue;
61047
61052
  // Only offer a higher version — a local install can be ahead of
61048
61053
  // the registry, and offering the registry's copy would downgrade.
61049
- if (isNewerVersion(result.latestVersion, ref.installed.version)) {
61054
+ if (isNewerVersion$1(result.latestVersion, ref.installed.version)) {
61050
61055
  // Build the download URL deterministically — same shape the
61051
61056
  // existing index serves (`/api/packages/<scope>/<name>/download?version=<v>`).
61052
61057
  // Constructed client-side because check-versions intentionally
@@ -61086,7 +61091,7 @@ async function checkUpdates(installedWidgets = []) {
61086
61091
  if (p.name === installedId) return true;
61087
61092
  return false;
61088
61093
  });
61089
- if (pkg && isNewerVersion(pkg.version, installed.version)) {
61094
+ if (pkg && isNewerVersion$1(pkg.version, installed.version)) {
61090
61095
  updates.push({
61091
61096
  name: installed.name,
61092
61097
  currentVersion: installed.version,
@@ -67212,7 +67217,7 @@ var colorUtils = /*#__PURE__*/Object.freeze({
67212
67217
  toDisplayColor: toDisplayColor$2
67213
67218
  });
67214
67219
 
67215
- var require$$10 = /*@__PURE__*/getAugmentedNamespace(colorUtils);
67220
+ var require$$11 = /*@__PURE__*/getAugmentedNamespace(colorUtils);
67216
67221
 
67217
67222
  /**
67218
67223
  * themeGenerator.js
@@ -67776,7 +67781,7 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(themeGenerator);
67776
67781
  * a complete theme object compatible with ThemeModel.
67777
67782
  */
67778
67783
 
67779
- const { TAILWIND_COLORS: TAILWIND_COLORS$1 } = require$$10;
67784
+ const { TAILWIND_COLORS: TAILWIND_COLORS$1 } = require$$11;
67780
67785
  const { generateThemeName } = require$$1;
67781
67786
 
67782
67787
  const VALID_HEX_RE = /^#[0-9a-fA-F]{6}$/;
@@ -72456,7 +72461,7 @@ function withDefaults$3(def = {}) {
72456
72461
  * @param {object} def
72457
72462
  * @returns {{ valid: boolean, errors: string[] }}
72458
72463
  */
72459
- function validateBotDefinition$3(def) {
72464
+ function validateBotDefinition$4(def) {
72460
72465
  const errors = [];
72461
72466
  if (!def || typeof def !== "object") {
72462
72467
  return { valid: false, errors: ["definition must be an object"] };
@@ -72571,7 +72576,7 @@ var botSchema = {
72571
72576
  newBotId: newBotId$1,
72572
72577
  isValidBotId: isValidBotId$1,
72573
72578
  withDefaults: withDefaults$3,
72574
- validateBotDefinition: validateBotDefinition$3,
72579
+ validateBotDefinition: validateBotDefinition$4,
72575
72580
  };
72576
72581
 
72577
72582
  /**
@@ -73700,6 +73705,379 @@ var teamManifest = {
73700
73705
  describeTeam,
73701
73706
  };
73702
73707
 
73708
+ /**
73709
+ * secretFields.js
73710
+ *
73711
+ * Keep secret values out of anything that leaves this computer — profile
73712
+ * files and Export Everything. A widget setting the user typed a key or
73713
+ * password into is stored in plain text in the dashboard (`userPrefs`);
73714
+ * the setting itself travels (so the other computer knows it's needed),
73715
+ * its value doesn't.
73716
+ *
73717
+ * A setting is secret when its widget declares it `type: "secret"` (or
73718
+ * "password"), or when its name clearly says so (apiKey, accessToken,
73719
+ * password, clientSecret, …). Provider settings that are kept (MCP
73720
+ * arguments, URLs) have token-like values redacted.
73721
+ */
73722
+
73723
+ var secretFields;
73724
+ var hasRequiredSecretFields;
73725
+
73726
+ function requireSecretFields () {
73727
+ if (hasRequiredSecretFields) return secretFields;
73728
+ hasRequiredSecretFields = 1;
73729
+ const fs = require$$0$3;
73730
+ const path = require$$1$2;
73731
+
73732
+ const SECRET_TYPES = new Set(["secret", "password"]);
73733
+
73734
+ // Words that make a setting's name a secret on their own, and the words
73735
+ // that make "key" one (an "apiKey" is, a "sortKey" isn't).
73736
+ const SECRET_WORDS = new Set([
73737
+ "token",
73738
+ "tokens",
73739
+ "password",
73740
+ "passwd",
73741
+ "passphrase",
73742
+ "secret",
73743
+ "secrets",
73744
+ "credential",
73745
+ "credentials",
73746
+ "bearer",
73747
+ ]);
73748
+ const KEY_PREFIXES = new Set([
73749
+ "api",
73750
+ "access",
73751
+ "private",
73752
+ "secret",
73753
+ "auth",
73754
+ "client",
73755
+ "license",
73756
+ "signing",
73757
+ ]);
73758
+
73759
+ function nameWords(name) {
73760
+ return String(name || "")
73761
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
73762
+ .toLowerCase()
73763
+ .split(/[^a-z0-9]+/)
73764
+ .filter(Boolean);
73765
+ }
73766
+
73767
+ /** Does a setting's name say it holds a secret? */
73768
+ function looksSecretName(name) {
73769
+ const words = nameWords(name);
73770
+ for (let i = 0; i < words.length; i++) {
73771
+ if (SECRET_WORDS.has(words[i])) return true;
73772
+ if (words[i] === "key" && i > 0 && KEY_PREFIXES.has(words[i - 1])) {
73773
+ return true;
73774
+ }
73775
+ if (words[i] === "apikey" || words[i] === "accesskey") return true;
73776
+ }
73777
+ return false;
73778
+ }
73779
+
73780
+ /** The setting names a widget config declares secret. */
73781
+ function secretFieldsOfConfig(config) {
73782
+ const out = new Set();
73783
+ const userConfig = config && config.userConfig;
73784
+ if (!userConfig || typeof userConfig !== "object") return out;
73785
+ for (const [field, spec] of Object.entries(userConfig)) {
73786
+ if (spec && typeof spec === "object" && SECRET_TYPES.has(spec.type)) {
73787
+ out.add(field);
73788
+ }
73789
+ }
73790
+ return out;
73791
+ }
73792
+
73793
+ /**
73794
+ * Read an installed widget package's `.dash.js` files (the safe AST
73795
+ * parser — never evaluated) → Map<componentName, Set<secret field>>.
73796
+ */
73797
+ function secretFieldsOfPackage(packagePath) {
73798
+ const map = new Map();
73799
+ if (!packagePath) return map;
73800
+ const { parseDashConfig } = dashConfigParser;
73801
+ let dirs = [];
73802
+ for (const rel of ["widgets", "configs/widgets", "configs"]) {
73803
+ const dir = path.join(packagePath, rel);
73804
+ if (fs.existsSync(dir)) dirs.push(dir);
73805
+ }
73806
+ for (const dir of dirs) {
73807
+ let files = [];
73808
+ try {
73809
+ files = fs.readdirSync(dir);
73810
+ } catch (_e) {
73811
+ files = [];
73812
+ }
73813
+ for (const file of files) {
73814
+ if (!file.endsWith(".dash.js")) continue;
73815
+ let parsed;
73816
+ try {
73817
+ parsed = parseDashConfig(fs.readFileSync(path.join(dir, file), "utf8"));
73818
+ } catch (_e) {
73819
+ continue;
73820
+ }
73821
+ if (!parsed || !parsed.ok) continue;
73822
+ const name =
73823
+ (typeof parsed.config.name === "string" && parsed.config.name) ||
73824
+ file.replace(/\.dash\.js$/, "");
73825
+ map.set(name, secretFieldsOfConfig(parsed.config));
73826
+ }
73827
+ }
73828
+ return map;
73829
+ }
73830
+
73831
+ function isEmpty(value) {
73832
+ return (
73833
+ value == null ||
73834
+ value === "" ||
73835
+ (Array.isArray(value) && value.length === 0) ||
73836
+ (typeof value === "object" &&
73837
+ !Array.isArray(value) &&
73838
+ Object.keys(value).length === 0)
73839
+ );
73840
+ }
73841
+
73842
+ /** The component name of a layout item ("scope.pkg.Comp" → "Comp"). */
73843
+ function componentOf(item) {
73844
+ const c = String((item && (item.componentName || item.component)) || "");
73845
+ return c.split(".").pop();
73846
+ }
73847
+
73848
+ /**
73849
+ * A copy of a dashboard with `visit(item, key)` applied to every layout
73850
+ * item. Item ids repeat across pages (and the top-level layout mirrors
73851
+ * the active page), so an item's key includes where it is:
73852
+ * "layout/<id>", "sidebar/<id>" or "page:<pageId>/<id>".
73853
+ */
73854
+ function mapItems(workspace, visit) {
73855
+ const walkIn = (section) => {
73856
+ const walk = (item) => {
73857
+ if (!item || typeof item !== "object") return item;
73858
+ const next = visit(item, `${section}/${item.uuid || item.id}`);
73859
+ if (Array.isArray(item.items)) next.items = item.items.map(walk);
73860
+ if (Array.isArray(item.layout)) next.layout = item.layout.map(walk);
73861
+ return next;
73862
+ };
73863
+ return walk;
73864
+ };
73865
+ const out = { ...workspace };
73866
+ if (Array.isArray(out.layout)) out.layout = out.layout.map(walkIn("layout"));
73867
+ if (Array.isArray(out.sidebarLayout)) {
73868
+ out.sidebarLayout = out.sidebarLayout.map(walkIn("sidebar"));
73869
+ }
73870
+ if (Array.isArray(out.pages)) {
73871
+ out.pages = out.pages.map((page) =>
73872
+ page && Array.isArray(page.layout)
73873
+ ? { ...page, layout: page.layout.map(walkIn(`page:${page.id}`)) }
73874
+ : page,
73875
+ );
73876
+ }
73877
+ return out;
73878
+ }
73879
+
73880
+ /** Is this setting secret — declared so by its widget, or named so? */
73881
+ function isSecretSetting(field, declared) {
73882
+ return declared.has(field) || looksSecretName(field);
73883
+ }
73884
+
73885
+ /**
73886
+ * A copy of a dashboard with every secret widget setting's value blanked,
73887
+ * and the list of what was blanked. `secretFieldsFor(item)` returns the
73888
+ * Set of setting names its widget declares secret.
73889
+ */
73890
+ function blankDashboardSecrets(workspace, secretFieldsFor = () => new Set()) {
73891
+ const blanked = [];
73892
+ if (!workspace || typeof workspace !== "object") {
73893
+ return { workspace, blanked };
73894
+ }
73895
+ const out = mapItems(workspace, (item, key) => {
73896
+ const next = { ...item };
73897
+ if (item.userPrefs && typeof item.userPrefs === "object") {
73898
+ const declared = secretFieldsFor(item) || new Set();
73899
+ const prefs = { ...item.userPrefs };
73900
+ for (const field of Object.keys(prefs)) {
73901
+ if (!isSecretSetting(field, declared) || isEmpty(prefs[field])) {
73902
+ continue;
73903
+ }
73904
+ prefs[field] = "";
73905
+ blanked.push({
73906
+ item: key,
73907
+ component: componentOf(item),
73908
+ title: item.userPrefs.title || null,
73909
+ field,
73910
+ });
73911
+ }
73912
+ next.userPrefs = prefs;
73913
+ }
73914
+ return next;
73915
+ });
73916
+ return { workspace: out, blanked };
73917
+ }
73918
+
73919
+ /**
73920
+ * item → the Set of settings its widget declares secret, looked up in this
73921
+ * computer's installed packages (cached per package).
73922
+ */
73923
+ function secretFieldLookup(registry) {
73924
+ const cache = new Map();
73925
+ return (item) => {
73926
+ const pkg = item && (item.packageId || item._sourcePackage);
73927
+ if (!pkg || !registry) return new Set();
73928
+ if (!cache.has(pkg)) {
73929
+ let installed = null;
73930
+ try {
73931
+ installed = registry.getWidget(pkg);
73932
+ } catch (_e) {
73933
+ installed = null;
73934
+ }
73935
+ cache.set(pkg, secretFieldsOfPackage(installed && installed.path));
73936
+ }
73937
+ return cache.get(pkg).get(componentOf(item)) || new Set();
73938
+ };
73939
+ }
73940
+
73941
+ /**
73942
+ * Blank secrets in every dashboard, looking each widget's declared secret
73943
+ * settings up in this computer's installed packages.
73944
+ * @param {Array} workspaces
73945
+ * @param {{getWidget: (pkg: string) => object|null}|null} registry
73946
+ */
73947
+ function blankSecretsInDashboards(workspaces, registry) {
73948
+ const fieldsFor = secretFieldLookup(registry);
73949
+ const blanked = [];
73950
+ const out = (Array.isArray(workspaces) ? workspaces : []).map((w) => {
73951
+ const res = blankDashboardSecrets(w, fieldsFor);
73952
+ for (const b of res.blanked) {
73953
+ blanked.push({
73954
+ dashboardId: w && w.id,
73955
+ dashboard: (w && (w.name || w.label)) || "Untitled",
73956
+ ...b,
73957
+ });
73958
+ }
73959
+ return res.workspace;
73960
+ });
73961
+ return { workspaces: out, blanked };
73962
+ }
73963
+
73964
+ /** Every layout item of a dashboard, by its key (see mapItems). */
73965
+ function itemsByKey(workspace) {
73966
+ const out = new Map();
73967
+ if (workspace && typeof workspace === "object") {
73968
+ mapItems(workspace, (item, key) => {
73969
+ out.set(key, item);
73970
+ return { ...item };
73971
+ });
73972
+ }
73973
+ return out;
73974
+ }
73975
+
73976
+ /**
73977
+ * A dashboard loaded over this computer's copy keeps the secret values
73978
+ * this computer already has (the file never carries them).
73979
+ */
73980
+ function restoreSecrets(incoming, local, secretFieldsFor = () => new Set()) {
73981
+ if (!incoming || !local) return incoming;
73982
+ const mine = itemsByKey(local);
73983
+ return mapItems(incoming, (item, key) => {
73984
+ const next = { ...item };
73985
+ const here = mine.get(key);
73986
+ if (item.userPrefs && here && here.userPrefs) {
73987
+ const declared = secretFieldsFor(item) || new Set();
73988
+ const prefs = { ...item.userPrefs };
73989
+ for (const field of Object.keys(here.userPrefs)) {
73990
+ if (!isSecretSetting(field, declared)) continue;
73991
+ if (isEmpty(prefs[field]) && !isEmpty(here.userPrefs[field])) {
73992
+ prefs[field] = here.userPrefs[field];
73993
+ }
73994
+ }
73995
+ next.userPrefs = prefs;
73996
+ }
73997
+ return next;
73998
+ });
73999
+ }
74000
+
74001
+ /** Does this computer's copy of a dashboard have a value for a setting? */
74002
+ function hasSecretValue(local, itemKey, field) {
74003
+ const item = itemsByKey(local).get(String(itemKey));
74004
+ return !!(item && item.userPrefs && !isEmpty(item.userPrefs[field]));
74005
+ }
74006
+
74007
+ const REDACTED = "";
74008
+
74009
+ /** A URL without a password or token-like query values. */
74010
+ function redactUrl(value) {
74011
+ if (typeof value !== "string" || !/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
74012
+ return value;
74013
+ }
74014
+ let url;
74015
+ try {
74016
+ url = new URL(value);
74017
+ } catch (_e) {
74018
+ return value;
74019
+ }
74020
+ let changed = false;
74021
+ if (url.password) {
74022
+ url.password = "";
74023
+ changed = true;
74024
+ }
74025
+ for (const key of [...url.searchParams.keys()]) {
74026
+ if (looksSecretName(key) || /^(key|sig|signature|code)$/i.test(key)) {
74027
+ url.searchParams.set(key, REDACTED);
74028
+ changed = true;
74029
+ }
74030
+ }
74031
+ return changed ? url.toString() : value;
74032
+ }
74033
+
74034
+ /** MCP arguments without token-like values (`--token=x`, `--api-key x`). */
74035
+ function redactArgs(args) {
74036
+ if (!Array.isArray(args)) return args;
74037
+ const out = [];
74038
+ for (let i = 0; i < args.length; i++) {
74039
+ const arg = args[i];
74040
+ if (typeof arg !== "string") {
74041
+ out.push(arg);
74042
+ continue;
74043
+ }
74044
+ const flag = arg.match(/^(--?[A-Za-z0-9_-]+)=(.*)$/);
74045
+ if (flag && looksSecretName(flag[1].replace(/^-+/, ""))) {
74046
+ out.push(`${flag[1]}=${REDACTED}`);
74047
+ continue;
74048
+ }
74049
+ const prev = i > 0 ? args[i - 1] : null;
74050
+ if (
74051
+ typeof prev === "string" &&
74052
+ /^--?[A-Za-z0-9_-]+$/.test(prev) &&
74053
+ looksSecretName(prev.replace(/^-+/, "")) &&
74054
+ !arg.startsWith("-")
74055
+ ) {
74056
+ out.push(REDACTED);
74057
+ continue;
74058
+ }
74059
+ out.push(redactUrl(arg));
74060
+ }
74061
+ return out;
74062
+ }
74063
+
74064
+ secretFields = {
74065
+ looksSecretName,
74066
+ secretFieldsOfConfig,
74067
+ secretFieldsOfPackage,
74068
+ blankDashboardSecrets,
74069
+ blankSecretsInDashboards,
74070
+ secretFieldLookup,
74071
+ restoreSecrets,
74072
+ hasSecretValue,
74073
+ redactUrl,
74074
+ redactArgs,
74075
+ mapItems,
74076
+ itemsByKey,
74077
+ };
74078
+ return secretFields;
74079
+ }
74080
+
73703
74081
  /**
73704
74082
  * dashboardConfigUtils.js
73705
74083
  *
@@ -74220,7 +74598,7 @@ function checkDashboardCompatibility(
74220
74598
  };
74221
74599
  }
74222
74600
 
74223
- const { toDisplayColor: toDisplayColor$1 } = require$$10;
74601
+ const { toDisplayColor: toDisplayColor$1 } = require$$11;
74224
74602
 
74225
74603
  /**
74226
74604
  * Generate a registry manifest from a dashboard config.
@@ -74487,38 +74865,35 @@ function checkDashboardUpdates(workspaces = [], registryPackages = []) {
74487
74865
 
74488
74866
  const updates = [];
74489
74867
 
74868
+ const { readRegistryRef } = packageRef;
74869
+ const { isNewerVersion } = isNewerVersion_1;
74490
74870
  for (const ws of workspaces) {
74491
- const config = ws._dashboardConfig;
74492
- if (!config || !config.registryPackage) continue;
74493
-
74494
- // Lookup chain: try the scoped form first, fall back to bare. The
74495
- // installed config may record either. Scope is stored on the
74496
- // config by the install flow (or set here by the publish persist
74497
- // step we just added).
74498
- const installedScope =
74499
- config.registryScope ||
74500
- (config.registryPackage.startsWith("@")
74501
- ? config.registryPackage.slice(1).split("/")[0]
74502
- : null);
74503
- const installedName = config.registryPackage.includes("/")
74504
- ? config.registryPackage.split("/").pop()
74505
- : config.registryPackage;
74506
- const scopedKey = asKey(installedScope, installedName);
74871
+ // Which package and version this is — installed or published from
74872
+ // here (registryRef, else the older _dashboardConfig fields).
74873
+ const ref = readRegistryRef("dashboard", ws);
74874
+ if (!ref) continue;
74875
+ const config = ws._dashboardConfig || {};
74876
+ const installedScope = ref.package
74877
+ ? ref.package.slice(1).split("/")[0]
74878
+ : null;
74879
+ const scopedKey = asKey(installedScope, ref.name);
74507
74880
 
74508
74881
  const registryPkg =
74509
74882
  (scopedKey && registryByKey.get(scopedKey)) ||
74510
- registryByKey.get(config.registryPackage) ||
74511
- registryByKey.get(installedName);
74883
+ (config.registryPackage && registryByKey.get(config.registryPackage)) ||
74884
+ registryByKey.get(ref.name);
74512
74885
  if (!registryPkg) continue;
74513
74886
 
74514
- const installedVersion = config.installedVersion || "0.0.0";
74887
+ const installedVersion = ref.version || "0.0.0";
74515
74888
  const latestVersion = registryPkg.version || "0.0.0";
74516
74889
 
74517
- if (installedVersion !== latestVersion) {
74890
+ // Only a newer version is an update (a dashboard published from here
74891
+ // is already at the latest).
74892
+ if (isNewerVersion(latestVersion, installedVersion)) {
74518
74893
  updates.push({
74519
74894
  workspaceId: ws.id,
74520
74895
  workspaceName: ws.name || ws.label || "",
74521
- registryPackage: config.registryPackage,
74896
+ registryPackage: config.registryPackage || ref.package,
74522
74897
  registryScope: installedScope,
74523
74898
  installedVersion,
74524
74899
  latestVersion,
@@ -74791,6 +75166,54 @@ function stripPersonalizationFromWorkspace$1(workspace) {
74791
75166
  return cleaned;
74792
75167
  }
74793
75168
 
75169
+ /**
75170
+ * The reverse, for updating a dashboard in place from its published copy:
75171
+ * each widget keeps the settings (userPrefs) and providers this computer
75172
+ * gave it, matched by section and widget id — or, when the page ids differ
75173
+ * (the editor names pages after this computer's dashboard id), by the same
75174
+ * widget and component anywhere, if that's unambiguous. A widget the update
75175
+ * adds starts with its defaults; one it removes goes with its settings.
75176
+ * Pure — returns a new workspace.
75177
+ */
75178
+ function keepPersonalization$1(incoming, local) {
75179
+ if (!incoming || !local) return incoming;
75180
+ const { mapItems, itemsByKey } = requireSecretFields();
75181
+ const mine = itemsByKey(local);
75182
+ const widgetKey = (item) =>
75183
+ `${item.uuid || item.id}|${item.componentName || item.component || ""}`;
75184
+ // The same widget in several places (the top-level layout mirrors the
75185
+ // active page) counts once; different settings make it ambiguous.
75186
+ const byWidget = new Map();
75187
+ for (const item of mine.values()) {
75188
+ const k = widgetKey(item);
75189
+ const seen = byWidget.get(k);
75190
+ if (seen === undefined) byWidget.set(k, item);
75191
+ else if (
75192
+ seen &&
75193
+ JSON.stringify(seen.userPrefs || null) !==
75194
+ JSON.stringify(item.userPrefs || null)
75195
+ ) {
75196
+ byWidget.set(k, null);
75197
+ }
75198
+ }
75199
+ const next = mapItems(incoming, (item, key) => {
75200
+ const out = { ...item };
75201
+ const here = mine.get(key) || byWidget.get(widgetKey(item)) || null;
75202
+ if (!here) return out;
75203
+ if (here.userPrefs && typeof here.userPrefs === "object") {
75204
+ out.userPrefs = { ...(item.userPrefs || {}), ...here.userPrefs };
75205
+ }
75206
+ if (here.selectedProviders !== undefined) {
75207
+ out.selectedProviders = here.selectedProviders;
75208
+ }
75209
+ return out;
75210
+ });
75211
+ if (local.selectedProviders !== undefined) {
75212
+ next.selectedProviders = local.selectedProviders;
75213
+ }
75214
+ return next;
75215
+ }
75216
+
74794
75217
  /**
74795
75218
  * Remap each layout item's `packageId` from a local-only scope (e.g.
74796
75219
  * `@ai-built/foo`) to the caller's published scope (`@<callerScope>/foo`)
@@ -75089,11 +75512,261 @@ var dashboardConfigUtils$1 = {
75089
75512
  buildProviderSetupManifest,
75090
75513
  checkApiCompatibility,
75091
75514
  stripPersonalizationFromWorkspace: stripPersonalizationFromWorkspace$1,
75515
+ keepPersonalization: keepPersonalization$1,
75092
75516
  remapLayoutPackageScopes: remapLayoutPackageScopes$1,
75093
75517
  repointLayoutPackage,
75094
75518
  assertNoLocalScopes: assertNoLocalScopes$1,
75095
75519
  };
75096
75520
 
75521
+ /**
75522
+ * registryPackages.js
75523
+ *
75524
+ * What the registry knows about one package, and the publish decisions
75525
+ * that follow from it (dash-profiles v2 groundwork):
75526
+ *
75527
+ * - getPackageInfo: its kind, versions, latest version and visibility,
75528
+ * as the signed-in user sees it;
75529
+ * - nextFreeVersion: the version to publish — never one the registry
75530
+ * already has (it refuses those), never below its newest;
75531
+ * - kindConflict: the name already belongs to another kind of package
75532
+ * (the registry refuses that too; this says so before publishing).
75533
+ */
75534
+
75535
+ const { isNewerVersion } = isNewerVersion_1;
75536
+ const { normalizePackageRef: normalizePackageRef$1 } = packageRef;
75537
+
75538
+ function registryBase() {
75539
+ return (
75540
+ process.env.DASH_REGISTRY_API_URL ||
75541
+ "https://main.d919rwhuzp7rj.amplifyapp.com"
75542
+ );
75543
+ }
75544
+
75545
+ /**
75546
+ * The registry's details for "@scope/name".
75547
+ *
75548
+ * @param {string|{scope: string, name: string}} pkg
75549
+ * @param {{fetch?: Function}} [opts] a fetch to use (tests); defaults to
75550
+ * the signed-in `authedFetch`
75551
+ * @returns {Promise<object|null|"unreachable">} null when it isn't there or
75552
+ * this user can't see it (the registry answers 404 for someone else's
75553
+ * private package); "unreachable" when the registry couldn't be asked
75554
+ */
75555
+ async function getPackageInfo(pkg, opts = {}) {
75556
+ const ref = normalizePackageRef$1(pkg);
75557
+ if (!ref) return null;
75558
+ const doFetch =
75559
+ opts.fetch || registryAuthController$1.authedFetch;
75560
+ let res;
75561
+ try {
75562
+ res = await doFetch(
75563
+ `${registryBase()}/api/packages/${encodeURIComponent(ref.scope)}/${encodeURIComponent(ref.name)}`,
75564
+ );
75565
+ } catch (_e) {
75566
+ return "unreachable";
75567
+ }
75568
+ if (!res || res.status === 404 || res.status === 401 || res.status === 403) {
75569
+ return null;
75570
+ }
75571
+ if (!res.ok) return "unreachable";
75572
+ const body = await res.json().catch(() => null);
75573
+ if (!body || typeof body !== "object") return "unreachable";
75574
+ return {
75575
+ package: ref.id,
75576
+ scope: ref.scope,
75577
+ name: ref.name,
75578
+ // Packages published before kinds existed are widgets.
75579
+ type: body.type || "widget",
75580
+ latestVersion: body.latestVersion || null,
75581
+ versions: (Array.isArray(body.versions) ? body.versions : [])
75582
+ .map((v) => v && v.version)
75583
+ .filter(Boolean),
75584
+ visibility: body.visibility || null,
75585
+ };
75586
+ }
75587
+
75588
+ function bumpPatch(version) {
75589
+ const m = String(version || "").match(/^(\d+)\.(\d+)\.(\d+)/);
75590
+ if (!m) return "1.0.0";
75591
+ return `${m[1]}.${m[2]}.${Number(m[3]) + 1}`;
75592
+ }
75593
+
75594
+ /** The first version at or after `version` that isn't in `taken`. */
75595
+ function freeVersion(version, taken) {
75596
+ const have = new Set(taken || []);
75597
+ let v = /^\d+\.\d+\.\d+/.test(String(version || "")) ? version : "1.0.0";
75598
+ // Never below what's published: start past the newest taken version.
75599
+ for (const t of have) {
75600
+ if (isNewerVersion(t, v)) v = t;
75601
+ }
75602
+ while (have.has(v)) v = bumpPatch(v);
75603
+ return v;
75604
+ }
75605
+
75606
+ /**
75607
+ * The version to publish next: this computer's version, or the next free
75608
+ * one when the registry already has it (or anything newer).
75609
+ *
75610
+ * @param {string|null} localVersion
75611
+ * @param {object|null|"unreachable"} info getPackageInfo's answer
75612
+ */
75613
+ function nextFreeVersion(localVersion, info) {
75614
+ const taken = info && typeof info === "object" ? info.versions : [];
75615
+ return freeVersion(localVersion, taken);
75616
+ }
75617
+
75618
+ /**
75619
+ * Why `pkg` can't be published as a `kind` package, or null. Mirrors the
75620
+ * registry's rule: a package keeps its kind.
75621
+ */
75622
+ function kindConflict(pkg, kind, info) {
75623
+ if (!info || typeof info !== "object") return null;
75624
+ const was = info.type || "widget";
75625
+ const now = kind || "widget";
75626
+ if (was === now) return null;
75627
+ const ref = normalizePackageRef$1(pkg);
75628
+ const id = ref ? ref.id : String(pkg);
75629
+ return `"${id}" is already a ${was} package — a ${now} can't be published under the same name. Choose another name.`;
75630
+ }
75631
+
75632
+ const EXACT_VERSION$1 = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
75633
+
75634
+ /**
75635
+ * The registry entry to install, at an exact version when one is asked for
75636
+ * (profiles list exact versions) — otherwise the latest.
75637
+ *
75638
+ * @param {string} ref any form registryController.getPackage accepts
75639
+ * @param {{kinds?: string[], version?: string}} [opts] the package kinds
75640
+ * this install accepts ("dashboard", "theme", "bot"/"bot-team"…)
75641
+ * @param {{getPackage?: Function, refreshIndex?: Function}} [deps]
75642
+ * @returns {Promise<{pkg: object}|{error: string}>} `pkg.version` is the
75643
+ * version to download
75644
+ */
75645
+ async function resolveForInstall$2(ref, opts = {}, deps = {}) {
75646
+ const registry = () => registryController$3;
75647
+ const lookup = deps.getPackage || ((r) => registry().getPackage(r));
75648
+ const refresh =
75649
+ deps.refreshIndex || (() => registry().fetchRegistryIndex(true));
75650
+ let pkg = await lookup(ref);
75651
+ // Published from another computer a moment ago: the cached index (a few
75652
+ // minutes old) may not list it yet.
75653
+ if (!pkg && normalizePackageRef$1(ref)) {
75654
+ try {
75655
+ await refresh();
75656
+ } catch (_e) {
75657
+ // the lookup below says it wasn't found
75658
+ }
75659
+ pkg = await lookup(ref);
75660
+ }
75661
+ if (!pkg) return { error: `"${ref}" was not found in the registry.` };
75662
+ // A listing without a kind isn't refused here: the download itself shows
75663
+ // whether it's the right kind of package.
75664
+ if (pkg.type && Array.isArray(opts.kinds) && !opts.kinds.includes(pkg.type)) {
75665
+ return { error: `"${ref}" is a ${pkg.type}, not a ${opts.kinds[0]}.` };
75666
+ }
75667
+ const exact =
75668
+ typeof opts.version === "string" && EXACT_VERSION$1.test(opts.version)
75669
+ ? opts.version
75670
+ : null;
75671
+ // Asked for a version that isn't one ("^1.2.0"): say so rather than
75672
+ // quietly installing — and recording — the latest. "*" / "latest" mean it.
75673
+ if (opts.version && !exact && !["*", "latest"].includes(opts.version)) {
75674
+ return { error: `"${opts.version}" isn't a version of "${ref}".` };
75675
+ }
75676
+ return {
75677
+ pkg: {
75678
+ ...pkg,
75679
+ version: exact || pkg.version || pkg.latestVersion || "1.0.0",
75680
+ },
75681
+ };
75682
+ }
75683
+
75684
+ /** The registry download endpoint for "@scope/name" at `version` (or the latest). */
75685
+ function packageDownloadUrl$1(pkg, version) {
75686
+ const ref = normalizePackageRef$1(pkg);
75687
+ if (!ref) return null;
75688
+ return `${registryBase()}/api/packages/${encodeURIComponent(ref.scope)}/${encodeURIComponent(
75689
+ ref.name,
75690
+ )}/download${version ? `?version=${encodeURIComponent(version)}` : ""}`;
75691
+ }
75692
+
75693
+ /**
75694
+ * Whether a package scope is the signed-in user's own — what they can
75695
+ * publish again (the registry only accepts publishes under your username).
75696
+ */
75697
+ function isOwnScope$1(scope, username) {
75698
+ let user = username;
75699
+ if (user === undefined) {
75700
+ try {
75701
+ user =
75702
+ registryAuthController$1.getStoredUsername();
75703
+ } catch (_e) {
75704
+ user = null;
75705
+ }
75706
+ }
75707
+ const a = String(scope || "")
75708
+ .replace(/^@/, "")
75709
+ .toLowerCase();
75710
+ const b = String(user || "")
75711
+ .replace(/^@/, "")
75712
+ .toLowerCase();
75713
+ return !!a && a === b;
75714
+ }
75715
+
75716
+ /**
75717
+ * Where an installed theme goes in `themes` (keyed by name): over the theme
75718
+ * already installed from or published as this package, else under its own
75719
+ * name — and when another theme has that name, "<name> (2)" and so on,
75720
+ * never over it.
75721
+ */
75722
+ function themeKeyFor$1(themes, pkg, preferredKey) {
75723
+ const {
75724
+ readRegistryRef,
75725
+ samePackage,
75726
+ normalizePackageRef: norm,
75727
+ } = packageRef;
75728
+ const want = norm(pkg);
75729
+ const all = themes && typeof themes === "object" ? themes : {};
75730
+ if (want) {
75731
+ const target = { package: want.id, name: want.name.toLowerCase() };
75732
+ for (const [key, theme] of Object.entries(all)) {
75733
+ const ref = readRegistryRef("theme", theme);
75734
+ // Older records may keep only a bare name; only a scoped match counts.
75735
+ if (ref && ref.package && samePackage(ref, target)) return key;
75736
+ }
75737
+ }
75738
+ const base = String(preferredKey || (want && want.name) || "Theme");
75739
+ if (!Object.prototype.hasOwnProperty.call(all, base)) return base;
75740
+ // An older install under that name that kept only the bare package name:
75741
+ // the same package, so it's updated.
75742
+ const there = readRegistryRef("theme", all[base]);
75743
+ if (
75744
+ want &&
75745
+ there &&
75746
+ !there.package &&
75747
+ there.name === want.name.toLowerCase()
75748
+ ) {
75749
+ return base;
75750
+ }
75751
+ for (let n = 2; ; n++) {
75752
+ const key = `${base} (${n})`;
75753
+ if (!Object.prototype.hasOwnProperty.call(all, key)) return key;
75754
+ }
75755
+ }
75756
+
75757
+ var registryPackages = {
75758
+ EXACT_VERSION: EXACT_VERSION$1,
75759
+ isOwnScope: isOwnScope$1,
75760
+ themeKeyFor: themeKeyFor$1,
75761
+ resolveForInstall: resolveForInstall$2,
75762
+ packageDownloadUrl: packageDownloadUrl$1,
75763
+ getPackageInfo,
75764
+ nextFreeVersion,
75765
+ freeVersion,
75766
+ bumpPatch,
75767
+ kindConflict,
75768
+ };
75769
+
75097
75770
  /**
75098
75771
  * publisherKeyController.js
75099
75772
  *
@@ -75788,6 +76461,10 @@ const themeController$3 = themeController_1;
75788
76461
  const registryController$1 = registryController$3;
75789
76462
  const registryApiController$2 = registryApiController$3;
75790
76463
  const { makeRegistryRef: makeRegistryRef$2 } = packageRef;
76464
+ const {
76465
+ resolveForInstall: resolveForInstall$1,
76466
+ themeKeyFor,
76467
+ } = registryPackages;
75791
76468
  const {
75792
76469
  getAuthStatus: getAuthStatus$1,
75793
76470
  getRegistryProfile: getRegistryProfile$2,
@@ -75848,7 +76525,7 @@ function generateThemeRegistryManifest(themeData, themeKey, options = {}) {
75848
76525
  const {
75849
76526
  TAILWIND_COLORS,
75850
76527
  toDisplayColor,
75851
- } = require$$10;
76528
+ } = require$$11;
75852
76529
 
75853
76530
  /**
75854
76531
  * Extract primary/secondary/tertiary/neutral colors from a theme object.
@@ -76090,19 +76767,28 @@ async function prepareThemeForPublish$1(win, appId, themeKey, options = {}) {
76090
76767
  * @param {string} packageName - Registry package name (e.g., "username/ocean-depth")
76091
76768
  * @returns {Object} Result with success, themeKey, theme
76092
76769
  */
76093
- async function installThemeFromRegistry$1(win, appId, packageName) {
76770
+ async function installThemeFromRegistry$1(win, appId, packageName, options = {}) {
76094
76771
  const TAG = "[ThemeInstall]";
76095
76772
  try {
76096
- // Stage 1: Package lookup
76773
+ // Stage 1: Package lookup — at an exact version when asked
76774
+ // (options.version; a profile lists exact versions), else the latest
76097
76775
  console.log(`${TAG} [1/5 Package Lookup] input="${packageName}"`);
76098
- const pkg = await registryController$1.getPackage(packageName);
76099
- if (!pkg) {
76100
- console.log(`${TAG} [1/5 Package Lookup] FAIL — package not found`);
76776
+ const resolved = await resolveForInstall$1(
76777
+ packageName,
76778
+ { kinds: ["theme"], version: options.version || null },
76779
+ {
76780
+ getPackage: (ref) => registryController$1.getPackage(ref),
76781
+ refreshIndex: () => registryController$1.fetchRegistryIndex?.(true),
76782
+ },
76783
+ );
76784
+ if (resolved.error) {
76785
+ console.log(`${TAG} [1/5 Package Lookup] FAIL — ${resolved.error}`);
76101
76786
  return {
76102
76787
  success: false,
76103
- error: `Package lookup failed: "${packageName}" was not found in the registry index. The package may have been removed or the name may be incorrect.`,
76788
+ error: `Package lookup failed: ${resolved.error} The package may have been removed or the name may be incorrect.`,
76104
76789
  };
76105
76790
  }
76791
+ const pkg = resolved.pkg;
76106
76792
  console.log(
76107
76793
  `${TAG} [1/5 Package Lookup] resolved scope="${pkg.scope}" name="${pkg.name}" version="${pkg.version || "1.0.0"}"`,
76108
76794
  );
@@ -76360,8 +77046,15 @@ async function installThemeFromRegistry$1(win, appId, packageName) {
76360
77046
  if (registryRef) themeData.registryRef = registryRef;
76361
77047
  else delete themeData.registryRef;
76362
77048
 
76363
- // Stage 5: Theme save
76364
- const themeKey = pkg.displayName || pkg.name;
77049
+ // Stage 5: Theme save — over the theme already installed from this
77050
+ // package (an update), never over a different theme with the same name
77051
+ const existingThemes =
77052
+ themeController$3.listThemesForApplication(win, appId)?.themes || {};
77053
+ const themeKey = themeKeyFor(
77054
+ existingThemes,
77055
+ { scope: pkg.scope, name: pkg.name },
77056
+ pkg.displayName || pkg.name,
77057
+ );
76365
77058
  console.log(
76366
77059
  `${TAG} [5/5 Theme Save] themeKey="${themeKey}" hasName=${!!themeData.name} hasColors=${!!(themeData.colors || themeData.primary)}`,
76367
77060
  );
@@ -76729,7 +77422,7 @@ const {
76729
77422
  newBotId,
76730
77423
  isValidBotId,
76731
77424
  withDefaults: withDefaults$2,
76732
- validateBotDefinition: validateBotDefinition$2,
77425
+ validateBotDefinition: validateBotDefinition$3,
76733
77426
  } = botSchema;
76734
77427
  const { botRef: botRef$1 } = botEvents;
76735
77428
 
@@ -76838,7 +77531,7 @@ let BotStore$1 = class BotStore {
76838
77531
  */
76839
77532
  create(def, { keepId = false } = {}) {
76840
77533
  const filled = withDefaults$2(def);
76841
- const { valid, errors } = validateBotDefinition$2(filled);
77534
+ const { valid, errors } = validateBotDefinition$3(filled);
76842
77535
  if (!valid) {
76843
77536
  throw new Error(`BotStore.create: invalid bot — ${errors.join("; ")}`);
76844
77537
  }
@@ -76898,7 +77591,7 @@ let BotStore$1 = class BotStore {
76898
77591
  } = patch || {};
76899
77592
  const merged = { ...existing, ...safePatch, updatedAt: this._now() };
76900
77593
 
76901
- const { valid, errors } = validateBotDefinition$2(merged);
77594
+ const { valid, errors } = validateBotDefinition$3(merged);
76902
77595
  if (!valid) {
76903
77596
  throw new Error(`BotStore.update: invalid bot — ${errors.join("; ")}`);
76904
77597
  }
@@ -81625,22 +82318,26 @@ function registryBaseUrl() {
81625
82318
 
81626
82319
  /**
81627
82320
  * @param {string} packageRef "scope/name" (any form registryController.getPackage accepts)
82321
+ * @param {{version?: string}} [opts] an exact version (else the latest)
81628
82322
  * @returns {Promise<{ files: { [path]: string }, pkg: object } |
81629
82323
  * { error: string, authRequired?: boolean }>}
81630
82324
  */
81631
- async function downloadBotPackage$1(packageRef) {
81632
- const registryController = registryController$3;
82325
+ async function downloadBotPackage$1(packageRef, opts = {}) {
82326
+ const { resolveForInstall } = registryPackages;
81633
82327
  const {
81634
82328
  registryDownloadFetch,
81635
82329
  downloadRefusal,
81636
82330
  } = registryDownload;
81637
82331
 
81638
- const pkg = await registryController.getPackage(packageRef);
81639
- if (!pkg) return { error: `"${packageRef}" wasn't found in the registry.` };
82332
+ const resolved = await resolveForInstall(packageRef, {
82333
+ version: opts.version || null,
82334
+ });
82335
+ if (resolved.error) return { error: resolved.error };
82336
+ const pkg = resolved.pkg;
81640
82337
  if (pkg.type !== "bot" && pkg.type !== "bot-team") {
81641
82338
  return { error: `"${packageRef}" isn't a bot or a team.` };
81642
82339
  }
81643
- const version = pkg.version || pkg.latestVersion || "1.0.0";
82340
+ const version = pkg.version;
81644
82341
  const scopePath = pkg.scope ? `${encodeURIComponent(pkg.scope)}/` : "";
81645
82342
  const url = `${registryBaseUrl()}/api/packages/${scopePath}${encodeURIComponent(pkg.name)}/download?version=${encodeURIComponent(version)}`;
81646
82343
 
@@ -82158,6 +82855,60 @@ async function zipAndPublish$1(files, manifest) {
82158
82855
 
82159
82856
  var botPublish = { registryIdentity: registryIdentity$1, zipAndPublish: zipAndPublish$1 };
82160
82857
 
82858
+ /**
82859
+ * botUpdate.js
82860
+ *
82861
+ * Updating a bot already on this computer from a newer copy of its registry
82862
+ * package (dash-profiles v2): what the bot does comes from the package —
82863
+ * name, instructions, model, engine, schedules, what it publishes — while
82864
+ * how it runs here stays: its providers and tool choices, approval policy,
82865
+ * subscriptions (its wiring), dashboard, session and run state.
82866
+ *
82867
+ * A provider type the new version uses that the bot isn't connected to is
82868
+ * reported, never added: adding one would give the bot new tools without
82869
+ * the user choosing to.
82870
+ */
82871
+
82872
+ /**
82873
+ * @param {object} existing the stored bot
82874
+ * @param {{definition: object, needs?: Array<{type: string, chosen: string|null}>}} member
82875
+ * one member of planTeamInstall(...) for the new version
82876
+ * @param {object} [extra] fields to set as well (installedFrom, registryRef)
82877
+ * @returns {{patch: object, missingProviders: string[]}}
82878
+ */
82879
+ function botUpdatePatch$1(existing, member, extra = {}) {
82880
+ const planned = (member && member.definition) || {};
82881
+ const patch = {
82882
+ name: planned.name,
82883
+ instructions: planned.instructions,
82884
+ engine: planned.engine === undefined ? existing.engine : planned.engine,
82885
+ schedules: Array.isArray(planned.schedules)
82886
+ ? planned.schedules
82887
+ : existing.schedules,
82888
+ publishes: Array.isArray(planned.publishes)
82889
+ ? planned.publishes
82890
+ : existing.publishes,
82891
+ ...extra,
82892
+ };
82893
+ // The package's model only when this computer has that AI (the plan
82894
+ // leaves it out otherwise); else the bot keeps the one it runs on here.
82895
+ if (planned.provider) {
82896
+ patch.provider = planned.provider;
82897
+ patch.model = planned.model;
82898
+ }
82899
+ for (const key of Object.keys(patch)) {
82900
+ if (patch[key] === undefined) delete patch[key];
82901
+ }
82902
+ const connected = new Set(existing.mcpServers || []);
82903
+ const missingProviders = (member.needs || [])
82904
+ .filter((n) => !(n.chosen && connected.has(n.chosen)))
82905
+ .filter((n) => !(n.options || []).some((name) => connected.has(name)))
82906
+ .map((n) => n.type);
82907
+ return { patch, missingProviders };
82908
+ }
82909
+
82910
+ var botUpdate = { botUpdatePatch: botUpdatePatch$1 };
82911
+
82161
82912
  /**
82162
82913
  * teams.js
82163
82914
  *
@@ -84736,7 +85487,7 @@ const crypto$1 = require$$0$4;
84736
85487
  const { Cron: Cron$1 } = require$$1$4;
84737
85488
  const { botRef, botEventType: botEventType$1 } = botEvents;
84738
85489
  const {
84739
- validateBotDefinition: validateBotDefinition$1,
85490
+ validateBotDefinition: validateBotDefinition$2,
84740
85491
  withDefaults: withDefaults$1,
84741
85492
  RESULT_NAME_RE,
84742
85493
  } = botSchema;
@@ -84955,7 +85706,7 @@ function buildDraft$1({
84955
85706
  ...(publishes.length ? { publishes } : {}),
84956
85707
  });
84957
85708
  delete definition.session;
84958
- const { valid, errors } = validateBotDefinition$1(definition);
85709
+ const { valid, errors } = validateBotDefinition$2(definition);
84959
85710
  if (!valid) return { error: `The draft isn't valid: ${errors.join("; ")}` };
84960
85711
 
84961
85712
  const dup = team.find(
@@ -87859,7 +88610,7 @@ var editTarget = {
87859
88610
  * @returns {{ errors: string[], warnings: string[] }}
87860
88611
  */
87861
88612
 
87862
- const { validateBotDefinition, withDefaults } = botSchema;
88613
+ const { validateBotDefinition: validateBotDefinition$1, withDefaults } = botSchema;
87863
88614
 
87864
88615
  const list = (v) => (Array.isArray(v) ? v : []);
87865
88616
 
@@ -87869,7 +88620,7 @@ function checkBot$1(def, ctx = {}) {
87869
88620
  const existing = ctx.existing || null;
87870
88621
 
87871
88622
  // As the store checks it: with the defaults filled in.
87872
- const shape = validateBotDefinition(
88623
+ const shape = validateBotDefinition$1(
87873
88624
  def && typeof def === "object" ? withDefaults(def) : def,
87874
88625
  );
87875
88626
  if (!shape.valid) errors.push(...shape.errors);
@@ -89266,7 +90017,13 @@ const BOT_WIDGETS = {
89266
90017
  activity: "dash.bots.BotActivity",
89267
90018
  };
89268
90019
  const { registryIdentity, zipAndPublish } = botPublish;
89269
- const { makeRegistryRef: makeRegistryRef$1 } = packageRef;
90020
+ const {
90021
+ makeRegistryRef: makeRegistryRef$1,
90022
+ readRegistryRef: readRegistryRef$1,
90023
+ samePackage,
90024
+ } = packageRef;
90025
+ const { validateBotDefinition } = botSchema;
90026
+ const { botUpdatePatch } = botUpdate;
89270
90027
  const { unassignTeam, isOnTeam } = teams;
89271
90028
  const {
89272
90029
  TEAM_SERVER,
@@ -90763,8 +91520,11 @@ const botController$1 = {
90763
91520
  * preview id — installFromRegistry installs from it, never from a copy the
90764
91521
  * renderer sends back.
90765
91522
  */
90766
- async previewRegistryInstall(workspaceId, packageRef) {
90767
- const dl = await downloadBotPackage(packageRef);
91523
+ async previewRegistryInstall(workspaceId, packageRef, opts = {}) {
91524
+ // opts.version: an exact version (a profile lists them), else the latest.
91525
+ const dl = await downloadBotPackage(packageRef, {
91526
+ version: opts.version || null,
91527
+ });
90768
91528
  if (dl.error) return dl;
90769
91529
  const read = readPackageFiles(dl.files);
90770
91530
  if (read.error) return read;
@@ -90796,6 +91556,84 @@ const botController$1 = {
90796
91556
  };
90797
91557
  },
90798
91558
 
91559
+ /**
91560
+ * Update bots already on this computer from the previewed package (a
91561
+ * newer version of what they were installed from or published as):
91562
+ * `botIdsByRole` names the existing bot for each of the package's roles
91563
+ * (one bot: its only role). What a bot does comes from the package; how
91564
+ * it runs here — providers, approvals, wiring, run state — stays. A role
91565
+ * with no bot here is skipped (installFromRegistry adds new ones).
91566
+ */
91567
+ updateFromRegistry(previewId, botIdsByRole = {}) {
91568
+ const preview =
91569
+ this._registryPreviews && this._registryPreviews.get(previewId);
91570
+ if (!preview) {
91571
+ return { error: "That preview has expired — find the package again." };
91572
+ }
91573
+ this._registryPreviews.delete(previewId);
91574
+ const plan = planTeamInstall(preview.manifest, {
91575
+ workspaceId: null,
91576
+ providers: this._providerList(),
91577
+ });
91578
+ const source = preview.source;
91579
+ const registryRef = makeRegistryRef$1({
91580
+ package: source.package,
91581
+ kind: source.kind === "bot-team" ? "bot-team" : "bot",
91582
+ version: source.version,
91583
+ origin: "installed",
91584
+ });
91585
+ const skipped = [];
91586
+ const missingProviders = [];
91587
+ const changes = [];
91588
+ const fromPackage = readRegistryRef$1("bot", { installedFrom: source });
91589
+ // Every bot checked before any changes: it must be a copy of this
91590
+ // package (installed from it or published as it), and its updated
91591
+ // definition must be valid — a bad one can't leave half a team updated.
91592
+ for (const member of plan.members) {
91593
+ const id = botIdsByRole[member.role];
91594
+ const existing = id ? this._store.get(id) : null;
91595
+ if (!existing) {
91596
+ skipped.push(member.role);
91597
+ continue;
91598
+ }
91599
+ const ref =
91600
+ readRegistryRef$1("bot", existing) ||
91601
+ readRegistryRef$1("bot-team", existing);
91602
+ if (!samePackage(ref, fromPackage)) {
91603
+ return {
91604
+ error: `${existing.name} isn't a copy of ${source.package}, so it wasn't updated.`,
91605
+ };
91606
+ }
91607
+ const { patch, missingProviders: missing } = botUpdatePatch(
91608
+ existing,
91609
+ member,
91610
+ {
91611
+ installedFrom: { ...source, role: member.role },
91612
+ ...(registryRef ? { registryRef } : {}),
91613
+ },
91614
+ );
91615
+ const { valid, errors } = validateBotDefinition({
91616
+ ...existing,
91617
+ ...patch,
91618
+ });
91619
+ if (!valid) {
91620
+ return {
91621
+ error: `${existing.name} wasn't updated: ${errors.join("; ")}`,
91622
+ };
91623
+ }
91624
+ changes.push({ id, patch });
91625
+ for (const type of missing) {
91626
+ missingProviders.push(`${existing.name}: ${type}`);
91627
+ }
91628
+ }
91629
+ for (const { id, patch } of changes) this._store.update(id, patch);
91630
+ return {
91631
+ updated: changes.map((c) => c.id),
91632
+ skipped,
91633
+ missingProviders,
91634
+ };
91635
+ },
91636
+
90799
91637
  /** Install the previewed registry package — all bots, or the ones picked. */
90800
91638
  installFromRegistry(workspaceId, previewId, choices = {}, roles = null) {
90801
91639
  const preview =
@@ -93036,6 +93874,7 @@ const {
93036
93874
  buildProviderRequirements,
93037
93875
  applyEventWiringToLayout,
93038
93876
  stripPersonalizationFromWorkspace,
93877
+ keepPersonalization,
93039
93878
  remapLayoutPackageScopes,
93040
93879
  assertNoLocalScopes,
93041
93880
  } = dashboardConfigUtils$1;
@@ -93048,7 +93887,15 @@ const themeController$2 = themeController_1;
93048
93887
  const {
93049
93888
  makeRegistryRef,
93050
93889
  withoutRegistryRef,
93890
+ readRegistryRef,
93891
+ normalizePackageRef,
93051
93892
  } = packageRef;
93893
+ const {
93894
+ resolveForInstall,
93895
+ packageDownloadUrl,
93896
+ isOwnScope,
93897
+ EXACT_VERSION,
93898
+ } = registryPackages;
93052
93899
 
93053
93900
  const configFilename = "workspaces.json";
93054
93901
 
@@ -93578,12 +94425,43 @@ async function processDashboardConfig(
93578
94425
  // Try to find the widget in the registry and install it
93579
94426
  try {
93580
94427
  const registryPkg = await getPackage(packageName);
93581
- if (registryPkg && registryPkg.downloadUrl) {
93582
- const config = await widgetRegistry.downloadWidget(
93583
- packageName,
93584
- registryPkg.downloadUrl,
93585
- registryPkg.dashConfigUrl || null,
93586
- );
94428
+ // The version the dashboard was published with, when the caller
94429
+ // asks for exact versions (a profile); otherwise the latest, so a
94430
+ // gallery install doesn't start out with old widgets.
94431
+ const exactUrl =
94432
+ options.exactWidgetVersions &&
94433
+ registryPkg &&
94434
+ EXACT_VERSION.test(String(widgetDep.version || ""))
94435
+ ? packageDownloadUrl(
94436
+ registryPkg.scope
94437
+ ? { scope: registryPkg.scope, name: registryPkg.name }
94438
+ : packageName,
94439
+ widgetDep.version,
94440
+ )
94441
+ : null;
94442
+ if (registryPkg && (exactUrl || registryPkg.downloadUrl)) {
94443
+ let config = null;
94444
+ if (exactUrl) {
94445
+ try {
94446
+ config = await widgetRegistry.downloadWidget(
94447
+ packageName,
94448
+ exactUrl,
94449
+ );
94450
+ } catch (exactErr) {
94451
+ // That version is gone (or private): the latest instead.
94452
+ if (!registryPkg.downloadUrl) throw exactErr;
94453
+ console.warn(
94454
+ `[DashboardConfigController] ${packageName}@${widgetDep.version} didn't install (${exactErr.message}); installing the latest`,
94455
+ );
94456
+ }
94457
+ }
94458
+ if (!config) {
94459
+ config = await widgetRegistry.downloadWidget(
94460
+ packageName,
94461
+ registryPkg.downloadUrl,
94462
+ registryPkg.dashConfigUrl || null,
94463
+ );
94464
+ }
93587
94465
  installSummary.installed.push({ packageName, config });
93588
94466
  installedPackages.add(packageName);
93589
94467
  // Also add the canonical form so a subsequent dep that
@@ -93650,6 +94528,7 @@ async function processDashboardConfig(
93650
94528
  let themeInstalled = null;
93651
94529
  // A theme the registry wouldn't install isn't bound to the dashboard.
93652
94530
  let themeFailed = false;
94531
+ let registryThemeKey = null;
93653
94532
  if (dashboardConfig.theme) {
93654
94533
  const bundledTheme = dashboardConfig.theme;
93655
94534
  const themeDisplay =
@@ -93740,6 +94619,10 @@ async function processDashboardConfig(
93740
94619
  if (themeResult && themeResult.success === false) {
93741
94620
  throw new Error(themeResult.error || "The theme didn't install");
93742
94621
  }
94622
+ // Where it went (not over a different theme with that name).
94623
+ if (themeResult && themeResult.themeKey) {
94624
+ registryThemeKey = themeResult.themeKey;
94625
+ }
93743
94626
  console.log(
93744
94627
  `[DashboardConfigController] Installed theme from registry: ${bundledTheme.registryPackage}`,
93745
94628
  );
@@ -93777,7 +94660,7 @@ async function processDashboardConfig(
93777
94660
  });
93778
94661
  }
93779
94662
  // Bind the workspace to the theme, unless it didn't install
93780
- if (!themeFailed) themeInstalled = themeKey;
94663
+ if (!themeFailed) themeInstalled = registryThemeKey || themeKey;
93781
94664
  }
93782
94665
  } catch (themeErr) {
93783
94666
  console.warn(
@@ -93804,16 +94687,45 @@ async function processDashboardConfig(
93804
94687
  };
93805
94688
  }
93806
94689
 
93807
- // Generate a unique ID for the imported workspace
93808
- workspace.id = Date.now();
94690
+ // Into an existing dashboard (an update, or loading a profile): it keeps
94691
+ // its id — so folders, profiles and links still point at it — its name,
94692
+ // folder and theme, and the widget settings made on this computer (a
94693
+ // published dashboard carries none).
94694
+ let existing = null;
94695
+ if (
94696
+ options.intoWorkspaceId !== undefined &&
94697
+ options.intoWorkspaceId !== null
94698
+ ) {
94699
+ const all = getFileContents$2(getAppFilePath$2(appId, "workspaces.json")) || [];
94700
+ // Ids are numbers here but may arrive as strings (a profile file).
94701
+ existing =
94702
+ all.find((w) => w && String(w.id) === String(options.intoWorkspaceId)) ||
94703
+ null;
94704
+ if (!existing) {
94705
+ return {
94706
+ success: false,
94707
+ error: "The dashboard to update isn't on this computer.",
94708
+ };
94709
+ }
94710
+ Object.assign(workspace, keepPersonalization(workspace, existing), {
94711
+ id: existing.id,
94712
+ name: existing.name,
94713
+ menuId: existing.menuId,
94714
+ themeKey: existing.themeKey,
94715
+ });
94716
+ } else {
94717
+ // Generate a unique ID for the imported workspace
94718
+ workspace.id = Date.now();
94719
+ }
93809
94720
 
93810
94721
  // Apply name/menuId/themeKey overrides if provided
93811
94722
  if (options.name) workspace.name = options.name;
93812
94723
  if (options.menuId !== undefined) workspace.menuId = options.menuId;
93813
94724
  if (options.themeKey !== undefined) workspace.themeKey = options.themeKey;
93814
94725
 
93815
- // Set themeKey from bundled theme if it was installed and no override given
93816
- if (themeInstalled && options.themeKey === undefined) {
94726
+ // Set themeKey from bundled theme if it was installed and no override
94727
+ // given (an existing dashboard keeps its own)
94728
+ if (themeInstalled && options.themeKey === undefined && !existing) {
93817
94729
  workspace.themeKey = themeInstalled;
93818
94730
  }
93819
94731
 
@@ -93832,9 +94744,10 @@ async function processDashboardConfig(
93832
94744
  }
93833
94745
  }
93834
94746
 
93835
- // 5. Mark as not shareable (imported dashboards cannot be re-published)
94747
+ // 5. Mark as not shareable (someone else's dashboard can't be published
94748
+ // again); one from the user's own account can.
93836
94749
  workspace._dashboardConfig = {
93837
- shareable: false,
94750
+ shareable: !!options.ownPackage,
93838
94751
  source,
93839
94752
  importedFrom: dashboardConfig.name,
93840
94753
  importedAt: new Date().toISOString(),
@@ -93845,8 +94758,9 @@ async function processDashboardConfig(
93845
94758
  };
93846
94759
  // Which registry package this is ("@scope/name" + version); a dashboard
93847
94760
  // imported from a file has none.
93848
- if (options.registryRef) workspace.registryRef = options.registryRef;
93849
- else delete workspace.registryRef;
94761
+ // (Set to undefined rather than deleted, so an update in place doesn't
94762
+ // keep the old one; it isn't written.)
94763
+ workspace.registryRef = options.registryRef || undefined;
93850
94764
 
93851
94765
  // Save workspace to workspaces.json
93852
94766
  const workspaceController = workspaceController_1;
@@ -93865,8 +94779,10 @@ async function processDashboardConfig(
93865
94779
 
93866
94780
  // The dashboard's bots (create-entry 5a, US-027): created paused, wired
93867
94781
  // to this dashboard's widgets and to each other.
94782
+ // `withTeam: false` leaves them out (a profile installs its bots as their
94783
+ // own packages); updating a dashboard in place never adds them again.
93868
94784
  let botsSummary = null;
93869
- if (dashboardConfig.team) {
94785
+ if (dashboardConfig.team && options.withTeam !== false && !existing) {
93870
94786
  botsSummary = installTeamForImport(workspace.id, dashboardConfig.team);
93871
94787
  }
93872
94788
 
@@ -93952,22 +94868,35 @@ function installTeamForImport(workspaceId, team) {
93952
94868
  * @returns {Promise<{ success: true, registryPkg, dashboardConfig } |
93953
94869
  * { success: false, error, authRequired? }>}
93954
94870
  */
93955
- async function downloadDashboardPackage(packageName, { purpose = null } = {}) {
93956
- // 1. Look up the dashboard package in the registry
93957
- const registryPkg = await getPackage(packageName);
93958
- if (!registryPkg) {
94871
+ async function downloadDashboardPackage(
94872
+ packageName,
94873
+ { purpose = null, version = null } = {},
94874
+ ) {
94875
+ // 1. Look up the dashboard package in the registry — at an exact
94876
+ // version when asked (a profile lists exact versions), else the latest
94877
+ const resolved = await resolveForInstall(
94878
+ packageName,
94879
+ { kinds: ["dashboard"], version },
94880
+ {
94881
+ getPackage,
94882
+ refreshIndex: () =>
94883
+ registryController$3.fetchRegistryIndex?.(true),
94884
+ },
94885
+ );
94886
+ if (resolved.error) {
93959
94887
  return {
93960
94888
  success: false,
93961
- error: `Dashboard package not found in registry: ${packageName}`,
94889
+ error: `Couldn't install the dashboard: ${resolved.error}`,
93962
94890
  };
93963
94891
  }
94892
+ const registryPkg = resolved.pkg;
93964
94893
 
93965
94894
  // 2. Construct download URL via /api/packages/.../download endpoint
93966
94895
  // (matches theme download flow in themeRegistryController.js)
93967
94896
  const registryBaseUrl =
93968
94897
  process.env.DASH_REGISTRY_API_URL ||
93969
94898
  "https://main.d919rwhuzp7rj.amplifyapp.com";
93970
- const downloadUrl = `${registryBaseUrl}/api/packages/${encodeURIComponent(registryPkg.scope)}/${encodeURIComponent(registryPkg.name)}/download?version=${encodeURIComponent(registryPkg.version || "1.0.0")}`;
94899
+ const downloadUrl = `${registryBaseUrl}/api/packages/${encodeURIComponent(registryPkg.scope)}/${encodeURIComponent(registryPkg.name)}/download?version=${encodeURIComponent(registryPkg.version)}`;
93971
94900
 
93972
94901
  console.log(
93973
94902
  `[DashboardConfigController] Fetching dashboard from: ${downloadUrl}`,
@@ -93989,6 +94918,8 @@ async function downloadDashboardPackage(packageName, { purpose = null } = {}) {
93989
94918
  const contentType = response.headers.get("content-type") || "";
93990
94919
  const arrayBuffer = await response.arrayBuffer();
93991
94920
  let zipBuffer = Buffer.from(arrayBuffer);
94921
+ // The publisher's signing details, from the registry's JSON answer.
94922
+ let signingMeta = {};
93992
94923
 
93993
94924
  if (zipBuffer.length === 0) {
93994
94925
  return {
@@ -94022,6 +94953,12 @@ async function downloadDashboardPackage(packageName, { purpose = null } = {}) {
94022
94953
  };
94023
94954
  }
94024
94955
  if (jsonData.downloadUrl) {
94956
+ signingMeta = {
94957
+ zipSignature: jsonData.zipSignature || null,
94958
+ publisherCert: jsonData.publisherCert || null,
94959
+ publisherKeyId: jsonData.publisherKeyId || null,
94960
+ publisherFingerprint: jsonData.publisherFingerprint || null,
94961
+ };
94025
94962
  let zipResponse;
94026
94963
  try {
94027
94964
  zipResponse = await fetch(jsonData.downloadUrl);
@@ -94047,6 +94984,31 @@ async function downloadDashboardPackage(packageName, { purpose = null } = {}) {
94047
94984
  }
94048
94985
  }
94049
94986
 
94987
+ // Verify the publisher's signature before opening the zip, like themes,
94988
+ // bots and widgets (strict refuses; the default, warn, logs and goes on).
94989
+ try {
94990
+ const {
94991
+ verifyDownloadedPackage,
94992
+ } = requireVerifyRegistryInstall();
94993
+ const verified = await verifyDownloadedPackage({
94994
+ zipBuffer,
94995
+ zipSignature: signingMeta.zipSignature,
94996
+ publisherCert: signingMeta.publisherCert,
94997
+ publisherKeyId: signingMeta.publisherKeyId,
94998
+ publisherFingerprint: signingMeta.publisherFingerprint,
94999
+ });
95000
+ if (!verified.verified && verified.mode === "warn") {
95001
+ console.warn(
95002
+ `[DashboardConfigController] Installing unverified dashboard "${packageName}" — ${verified.reason}`,
95003
+ );
95004
+ }
95005
+ } catch (verifyErr) {
95006
+ return {
95007
+ success: false,
95008
+ error: `Install verification failed: ${verifyErr.message || verifyErr}`,
95009
+ };
95010
+ }
95011
+
94050
95012
  const zip = new AdmZip$1(zipBuffer);
94051
95013
 
94052
95014
  // 3. Validate ZIP entries
@@ -94138,7 +95100,10 @@ async function installDashboardFromRegistry$1(
94138
95100
  installOptions = {},
94139
95101
  ) {
94140
95102
  try {
94141
- const downloaded = await downloadDashboardPackage(packageName);
95103
+ // installOptions.version: an exact version (else the latest).
95104
+ const downloaded = await downloadDashboardPackage(packageName, {
95105
+ version: installOptions.version || null,
95106
+ });
94142
95107
  if (!downloaded.success) return downloaded;
94143
95108
  const { registryPkg, dashboardConfig } = downloaded;
94144
95109
 
@@ -94163,6 +95128,10 @@ async function installDashboardFromRegistry$1(
94163
95128
  name: installOptions.name,
94164
95129
  menuId: installOptions.menuId,
94165
95130
  themeKey: installOptions.themeKey,
95131
+ intoWorkspaceId: installOptions.intoWorkspaceId,
95132
+ withTeam: installOptions.withTeam,
95133
+ exactWidgetVersions: !!installOptions.exactWidgetVersions,
95134
+ ownPackage: isOwnScope(registryPkg.scope),
94166
95135
  },
94167
95136
  );
94168
95137
  } catch (error) {
@@ -94520,10 +95489,18 @@ async function prepareDashboardForPublish$1(
94520
95489
  };
94521
95490
  }
94522
95491
 
94523
- // 2. Check shareable flag — imported dashboards cannot be published
95492
+ // 2. Check shareable flag — someone else's imported dashboard can't be
95493
+ // published; one installed from the user's own account can (older
95494
+ // installs of it were marked not shareable too)
95495
+ const fromOwnAccount = (() => {
95496
+ const ref = readRegistryRef("dashboard", workspace);
95497
+ const parsed = ref && normalizePackageRef(ref.package);
95498
+ return !!parsed && isOwnScope(parsed.scope);
95499
+ })();
94524
95500
  if (
94525
95501
  workspace._dashboardConfig &&
94526
- workspace._dashboardConfig.shareable === false
95502
+ workspace._dashboardConfig.shareable === false &&
95503
+ !fromOwnAccount
94527
95504
  ) {
94528
95505
  return {
94529
95506
  success: false,
@@ -95275,377 +96252,6 @@ var onboardingController$1 = {
95275
96252
  _clearRecord: () => getStore$1().delete("onboarding"),
95276
96253
  };
95277
96254
 
95278
- /**
95279
- * secretFields.js
95280
- *
95281
- * Keep secret values out of anything that leaves this computer — profile
95282
- * files and Export Everything. A widget setting the user typed a key or
95283
- * password into is stored in plain text in the dashboard (`userPrefs`);
95284
- * the setting itself travels (so the other computer knows it's needed),
95285
- * its value doesn't.
95286
- *
95287
- * A setting is secret when its widget declares it `type: "secret"` (or
95288
- * "password"), or when its name clearly says so (apiKey, accessToken,
95289
- * password, clientSecret, …). Provider settings that are kept (MCP
95290
- * arguments, URLs) have token-like values redacted.
95291
- */
95292
-
95293
- var secretFields;
95294
- var hasRequiredSecretFields;
95295
-
95296
- function requireSecretFields () {
95297
- if (hasRequiredSecretFields) return secretFields;
95298
- hasRequiredSecretFields = 1;
95299
- const fs = require$$0$3;
95300
- const path = require$$1$2;
95301
-
95302
- const SECRET_TYPES = new Set(["secret", "password"]);
95303
-
95304
- // Words that make a setting's name a secret on their own, and the words
95305
- // that make "key" one (an "apiKey" is, a "sortKey" isn't).
95306
- const SECRET_WORDS = new Set([
95307
- "token",
95308
- "tokens",
95309
- "password",
95310
- "passwd",
95311
- "passphrase",
95312
- "secret",
95313
- "secrets",
95314
- "credential",
95315
- "credentials",
95316
- "bearer",
95317
- ]);
95318
- const KEY_PREFIXES = new Set([
95319
- "api",
95320
- "access",
95321
- "private",
95322
- "secret",
95323
- "auth",
95324
- "client",
95325
- "license",
95326
- "signing",
95327
- ]);
95328
-
95329
- function nameWords(name) {
95330
- return String(name || "")
95331
- .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
95332
- .toLowerCase()
95333
- .split(/[^a-z0-9]+/)
95334
- .filter(Boolean);
95335
- }
95336
-
95337
- /** Does a setting's name say it holds a secret? */
95338
- function looksSecretName(name) {
95339
- const words = nameWords(name);
95340
- for (let i = 0; i < words.length; i++) {
95341
- if (SECRET_WORDS.has(words[i])) return true;
95342
- if (words[i] === "key" && i > 0 && KEY_PREFIXES.has(words[i - 1])) {
95343
- return true;
95344
- }
95345
- if (words[i] === "apikey" || words[i] === "accesskey") return true;
95346
- }
95347
- return false;
95348
- }
95349
-
95350
- /** The setting names a widget config declares secret. */
95351
- function secretFieldsOfConfig(config) {
95352
- const out = new Set();
95353
- const userConfig = config && config.userConfig;
95354
- if (!userConfig || typeof userConfig !== "object") return out;
95355
- for (const [field, spec] of Object.entries(userConfig)) {
95356
- if (spec && typeof spec === "object" && SECRET_TYPES.has(spec.type)) {
95357
- out.add(field);
95358
- }
95359
- }
95360
- return out;
95361
- }
95362
-
95363
- /**
95364
- * Read an installed widget package's `.dash.js` files (the safe AST
95365
- * parser — never evaluated) → Map<componentName, Set<secret field>>.
95366
- */
95367
- function secretFieldsOfPackage(packagePath) {
95368
- const map = new Map();
95369
- if (!packagePath) return map;
95370
- const { parseDashConfig } = dashConfigParser;
95371
- let dirs = [];
95372
- for (const rel of ["widgets", "configs/widgets", "configs"]) {
95373
- const dir = path.join(packagePath, rel);
95374
- if (fs.existsSync(dir)) dirs.push(dir);
95375
- }
95376
- for (const dir of dirs) {
95377
- let files = [];
95378
- try {
95379
- files = fs.readdirSync(dir);
95380
- } catch (_e) {
95381
- files = [];
95382
- }
95383
- for (const file of files) {
95384
- if (!file.endsWith(".dash.js")) continue;
95385
- let parsed;
95386
- try {
95387
- parsed = parseDashConfig(fs.readFileSync(path.join(dir, file), "utf8"));
95388
- } catch (_e) {
95389
- continue;
95390
- }
95391
- if (!parsed || !parsed.ok) continue;
95392
- const name =
95393
- (typeof parsed.config.name === "string" && parsed.config.name) ||
95394
- file.replace(/\.dash\.js$/, "");
95395
- map.set(name, secretFieldsOfConfig(parsed.config));
95396
- }
95397
- }
95398
- return map;
95399
- }
95400
-
95401
- function isEmpty(value) {
95402
- return (
95403
- value == null ||
95404
- value === "" ||
95405
- (Array.isArray(value) && value.length === 0) ||
95406
- (typeof value === "object" &&
95407
- !Array.isArray(value) &&
95408
- Object.keys(value).length === 0)
95409
- );
95410
- }
95411
-
95412
- /** The component name of a layout item ("scope.pkg.Comp" → "Comp"). */
95413
- function componentOf(item) {
95414
- const c = String((item && (item.componentName || item.component)) || "");
95415
- return c.split(".").pop();
95416
- }
95417
-
95418
- /**
95419
- * A copy of a dashboard with `visit(item, key)` applied to every layout
95420
- * item. Item ids repeat across pages (and the top-level layout mirrors
95421
- * the active page), so an item's key includes where it is:
95422
- * "layout/<id>", "sidebar/<id>" or "page:<pageId>/<id>".
95423
- */
95424
- function mapItems(workspace, visit) {
95425
- const walkIn = (section) => {
95426
- const walk = (item) => {
95427
- if (!item || typeof item !== "object") return item;
95428
- const next = visit(item, `${section}/${item.uuid || item.id}`);
95429
- if (Array.isArray(item.items)) next.items = item.items.map(walk);
95430
- if (Array.isArray(item.layout)) next.layout = item.layout.map(walk);
95431
- return next;
95432
- };
95433
- return walk;
95434
- };
95435
- const out = { ...workspace };
95436
- if (Array.isArray(out.layout)) out.layout = out.layout.map(walkIn("layout"));
95437
- if (Array.isArray(out.sidebarLayout)) {
95438
- out.sidebarLayout = out.sidebarLayout.map(walkIn("sidebar"));
95439
- }
95440
- if (Array.isArray(out.pages)) {
95441
- out.pages = out.pages.map((page) =>
95442
- page && Array.isArray(page.layout)
95443
- ? { ...page, layout: page.layout.map(walkIn(`page:${page.id}`)) }
95444
- : page,
95445
- );
95446
- }
95447
- return out;
95448
- }
95449
-
95450
- /** Is this setting secret — declared so by its widget, or named so? */
95451
- function isSecretSetting(field, declared) {
95452
- return declared.has(field) || looksSecretName(field);
95453
- }
95454
-
95455
- /**
95456
- * A copy of a dashboard with every secret widget setting's value blanked,
95457
- * and the list of what was blanked. `secretFieldsFor(item)` returns the
95458
- * Set of setting names its widget declares secret.
95459
- */
95460
- function blankDashboardSecrets(workspace, secretFieldsFor = () => new Set()) {
95461
- const blanked = [];
95462
- if (!workspace || typeof workspace !== "object") {
95463
- return { workspace, blanked };
95464
- }
95465
- const out = mapItems(workspace, (item, key) => {
95466
- const next = { ...item };
95467
- if (item.userPrefs && typeof item.userPrefs === "object") {
95468
- const declared = secretFieldsFor(item) || new Set();
95469
- const prefs = { ...item.userPrefs };
95470
- for (const field of Object.keys(prefs)) {
95471
- if (!isSecretSetting(field, declared) || isEmpty(prefs[field])) {
95472
- continue;
95473
- }
95474
- prefs[field] = "";
95475
- blanked.push({
95476
- item: key,
95477
- component: componentOf(item),
95478
- title: item.userPrefs.title || null,
95479
- field,
95480
- });
95481
- }
95482
- next.userPrefs = prefs;
95483
- }
95484
- return next;
95485
- });
95486
- return { workspace: out, blanked };
95487
- }
95488
-
95489
- /**
95490
- * item → the Set of settings its widget declares secret, looked up in this
95491
- * computer's installed packages (cached per package).
95492
- */
95493
- function secretFieldLookup(registry) {
95494
- const cache = new Map();
95495
- return (item) => {
95496
- const pkg = item && (item.packageId || item._sourcePackage);
95497
- if (!pkg || !registry) return new Set();
95498
- if (!cache.has(pkg)) {
95499
- let installed = null;
95500
- try {
95501
- installed = registry.getWidget(pkg);
95502
- } catch (_e) {
95503
- installed = null;
95504
- }
95505
- cache.set(pkg, secretFieldsOfPackage(installed && installed.path));
95506
- }
95507
- return cache.get(pkg).get(componentOf(item)) || new Set();
95508
- };
95509
- }
95510
-
95511
- /**
95512
- * Blank secrets in every dashboard, looking each widget's declared secret
95513
- * settings up in this computer's installed packages.
95514
- * @param {Array} workspaces
95515
- * @param {{getWidget: (pkg: string) => object|null}|null} registry
95516
- */
95517
- function blankSecretsInDashboards(workspaces, registry) {
95518
- const fieldsFor = secretFieldLookup(registry);
95519
- const blanked = [];
95520
- const out = (Array.isArray(workspaces) ? workspaces : []).map((w) => {
95521
- const res = blankDashboardSecrets(w, fieldsFor);
95522
- for (const b of res.blanked) {
95523
- blanked.push({
95524
- dashboardId: w && w.id,
95525
- dashboard: (w && (w.name || w.label)) || "Untitled",
95526
- ...b,
95527
- });
95528
- }
95529
- return res.workspace;
95530
- });
95531
- return { workspaces: out, blanked };
95532
- }
95533
-
95534
- /** Every layout item of a dashboard, by its key (see mapItems). */
95535
- function itemsByKey(workspace) {
95536
- const out = new Map();
95537
- if (workspace && typeof workspace === "object") {
95538
- mapItems(workspace, (item, key) => {
95539
- out.set(key, item);
95540
- return { ...item };
95541
- });
95542
- }
95543
- return out;
95544
- }
95545
-
95546
- /**
95547
- * A dashboard loaded over this computer's copy keeps the secret values
95548
- * this computer already has (the file never carries them).
95549
- */
95550
- function restoreSecrets(incoming, local, secretFieldsFor = () => new Set()) {
95551
- if (!incoming || !local) return incoming;
95552
- const mine = itemsByKey(local);
95553
- return mapItems(incoming, (item, key) => {
95554
- const next = { ...item };
95555
- const here = mine.get(key);
95556
- if (item.userPrefs && here && here.userPrefs) {
95557
- const declared = secretFieldsFor(item) || new Set();
95558
- const prefs = { ...item.userPrefs };
95559
- for (const field of Object.keys(here.userPrefs)) {
95560
- if (!isSecretSetting(field, declared)) continue;
95561
- if (isEmpty(prefs[field]) && !isEmpty(here.userPrefs[field])) {
95562
- prefs[field] = here.userPrefs[field];
95563
- }
95564
- }
95565
- next.userPrefs = prefs;
95566
- }
95567
- return next;
95568
- });
95569
- }
95570
-
95571
- /** Does this computer's copy of a dashboard have a value for a setting? */
95572
- function hasSecretValue(local, itemKey, field) {
95573
- const item = itemsByKey(local).get(String(itemKey));
95574
- return !!(item && item.userPrefs && !isEmpty(item.userPrefs[field]));
95575
- }
95576
-
95577
- const REDACTED = "";
95578
-
95579
- /** A URL without a password or token-like query values. */
95580
- function redactUrl(value) {
95581
- if (typeof value !== "string" || !/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
95582
- return value;
95583
- }
95584
- let url;
95585
- try {
95586
- url = new URL(value);
95587
- } catch (_e) {
95588
- return value;
95589
- }
95590
- let changed = false;
95591
- if (url.password) {
95592
- url.password = "";
95593
- changed = true;
95594
- }
95595
- for (const key of [...url.searchParams.keys()]) {
95596
- if (looksSecretName(key) || /^(key|sig|signature|code)$/i.test(key)) {
95597
- url.searchParams.set(key, REDACTED);
95598
- changed = true;
95599
- }
95600
- }
95601
- return changed ? url.toString() : value;
95602
- }
95603
-
95604
- /** MCP arguments without token-like values (`--token=x`, `--api-key x`). */
95605
- function redactArgs(args) {
95606
- if (!Array.isArray(args)) return args;
95607
- const out = [];
95608
- for (let i = 0; i < args.length; i++) {
95609
- const arg = args[i];
95610
- if (typeof arg !== "string") {
95611
- out.push(arg);
95612
- continue;
95613
- }
95614
- const flag = arg.match(/^(--?[A-Za-z0-9_-]+)=(.*)$/);
95615
- if (flag && looksSecretName(flag[1].replace(/^-+/, ""))) {
95616
- out.push(`${flag[1]}=${REDACTED}`);
95617
- continue;
95618
- }
95619
- const prev = i > 0 ? args[i - 1] : null;
95620
- if (
95621
- typeof prev === "string" &&
95622
- /^--?[A-Za-z0-9_-]+$/.test(prev) &&
95623
- looksSecretName(prev.replace(/^-+/, "")) &&
95624
- !arg.startsWith("-")
95625
- ) {
95626
- out.push(REDACTED);
95627
- continue;
95628
- }
95629
- out.push(redactUrl(arg));
95630
- }
95631
- return out;
95632
- }
95633
-
95634
- secretFields = {
95635
- looksSecretName,
95636
- secretFieldsOfConfig,
95637
- secretFieldsOfPackage,
95638
- blankDashboardSecrets,
95639
- blankSecretsInDashboards,
95640
- secretFieldLookup,
95641
- restoreSecrets,
95642
- hasSecretValue,
95643
- redactUrl,
95644
- redactArgs,
95645
- };
95646
- return secretFields;
95647
- }
95648
-
95649
96255
  /**
95650
96256
  * exportController.js
95651
96257
  *
@@ -97631,133 +98237,6 @@ clientCache$1.registerFactory("openai", (credentials) => {
97631
98237
  return new OpenAI({ apiKey: credentials.apiKey });
97632
98238
  });
97633
98239
 
97634
- /**
97635
- * registryPackages.js
97636
- *
97637
- * What the registry knows about one package, and the publish decisions
97638
- * that follow from it (dash-profiles v2 groundwork):
97639
- *
97640
- * - getPackageInfo: its kind, versions, latest version and visibility,
97641
- * as the signed-in user sees it;
97642
- * - nextFreeVersion: the version to publish — never one the registry
97643
- * already has (it refuses those), never below its newest;
97644
- * - kindConflict: the name already belongs to another kind of package
97645
- * (the registry refuses that too; this says so before publishing).
97646
- */
97647
-
97648
- var registryPackages;
97649
- var hasRequiredRegistryPackages;
97650
-
97651
- function requireRegistryPackages () {
97652
- if (hasRequiredRegistryPackages) return registryPackages;
97653
- hasRequiredRegistryPackages = 1;
97654
- const { isNewerVersion } = isNewerVersion_1;
97655
- const { normalizePackageRef } = packageRef;
97656
-
97657
- function registryBase() {
97658
- return (
97659
- process.env.DASH_REGISTRY_API_URL ||
97660
- "https://main.d919rwhuzp7rj.amplifyapp.com"
97661
- );
97662
- }
97663
-
97664
- /**
97665
- * The registry's details for "@scope/name".
97666
- *
97667
- * @param {string|{scope: string, name: string}} pkg
97668
- * @param {{fetch?: Function}} [opts] a fetch to use (tests); defaults to
97669
- * the signed-in `authedFetch`
97670
- * @returns {Promise<object|null|"unreachable">} null when it isn't there or
97671
- * this user can't see it (the registry answers 404 for someone else's
97672
- * private package); "unreachable" when the registry couldn't be asked
97673
- */
97674
- async function getPackageInfo(pkg, opts = {}) {
97675
- const ref = normalizePackageRef(pkg);
97676
- if (!ref) return null;
97677
- const doFetch =
97678
- opts.fetch || registryAuthController$1.authedFetch;
97679
- let res;
97680
- try {
97681
- res = await doFetch(
97682
- `${registryBase()}/api/packages/${encodeURIComponent(ref.scope)}/${encodeURIComponent(ref.name)}`,
97683
- );
97684
- } catch (_e) {
97685
- return "unreachable";
97686
- }
97687
- if (!res || res.status === 404 || res.status === 401 || res.status === 403) {
97688
- return null;
97689
- }
97690
- if (!res.ok) return "unreachable";
97691
- const body = await res.json().catch(() => null);
97692
- if (!body || typeof body !== "object") return "unreachable";
97693
- return {
97694
- package: ref.id,
97695
- scope: ref.scope,
97696
- name: ref.name,
97697
- // Packages published before kinds existed are widgets.
97698
- type: body.type || "widget",
97699
- latestVersion: body.latestVersion || null,
97700
- versions: (Array.isArray(body.versions) ? body.versions : [])
97701
- .map((v) => v && v.version)
97702
- .filter(Boolean),
97703
- visibility: body.visibility || null,
97704
- };
97705
- }
97706
-
97707
- function bumpPatch(version) {
97708
- const m = String(version || "").match(/^(\d+)\.(\d+)\.(\d+)/);
97709
- if (!m) return "1.0.0";
97710
- return `${m[1]}.${m[2]}.${Number(m[3]) + 1}`;
97711
- }
97712
-
97713
- /** The first version at or after `version` that isn't in `taken`. */
97714
- function freeVersion(version, taken) {
97715
- const have = new Set(taken || []);
97716
- let v = /^\d+\.\d+\.\d+/.test(String(version || "")) ? version : "1.0.0";
97717
- // Never below what's published: start past the newest taken version.
97718
- for (const t of have) {
97719
- if (isNewerVersion(t, v)) v = t;
97720
- }
97721
- while (have.has(v)) v = bumpPatch(v);
97722
- return v;
97723
- }
97724
-
97725
- /**
97726
- * The version to publish next: this computer's version, or the next free
97727
- * one when the registry already has it (or anything newer).
97728
- *
97729
- * @param {string|null} localVersion
97730
- * @param {object|null|"unreachable"} info getPackageInfo's answer
97731
- */
97732
- function nextFreeVersion(localVersion, info) {
97733
- const taken = info && typeof info === "object" ? info.versions : [];
97734
- return freeVersion(localVersion, taken);
97735
- }
97736
-
97737
- /**
97738
- * Why `pkg` can't be published as a `kind` package, or null. Mirrors the
97739
- * registry's rule: a package keeps its kind.
97740
- */
97741
- function kindConflict(pkg, kind, info) {
97742
- if (!info || typeof info !== "object") return null;
97743
- const was = info.type || "widget";
97744
- const now = kind || "widget";
97745
- if (was === now) return null;
97746
- const ref = normalizePackageRef(pkg);
97747
- const id = ref ? ref.id : String(pkg);
97748
- return `"${id}" is already a ${was} package — a ${now} can't be published under the same name. Choose another name.`;
97749
- }
97750
-
97751
- registryPackages = {
97752
- getPackageInfo,
97753
- nextFreeVersion,
97754
- freeVersion,
97755
- bumpPatch,
97756
- kindConflict,
97757
- };
97758
- return registryPackages;
97759
- }
97760
-
97761
98240
  /**
97762
98241
  * profileFile.js
97763
98242
  *
@@ -98033,7 +98512,7 @@ function requireProfileFile () {
98033
98512
  * either, so it goes in the file.
98034
98513
  */
98035
98514
  function lookupRegistryPackage(pkg) {
98036
- return requireRegistryPackages().getPackageInfo(pkg);
98515
+ return registryPackages.getPackageInfo(pkg);
98037
98516
  }
98038
98517
 
98039
98518
  /** "@scope/name" for a dependency (or the bare name when it has no scope). */
@@ -99383,7 +99862,7 @@ function requireProfilePublish () {
99383
99862
  bumpPatch,
99384
99863
  nextFreeVersion,
99385
99864
  kindConflict,
99386
- } = requireRegistryPackages();
99865
+ } = registryPackages;
99387
99866
 
99388
99867
  function splitPackage(pkg) {
99389
99868
  const m = String(pkg || "").match(/^@?([^/]+)\/(.+)$/);