@trops/dash-core 0.1.848 → 0.1.849

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.
@@ -103353,6 +103353,26 @@ function requireProfileLoadV2 () {
103353
103353
 
103354
103354
  // ---- applying -------------------------------------------------------------
103355
103355
 
103356
+ /**
103357
+ * A dashboard's name, folder and theme as the profile has them, in this
103358
+ * computer's terms (folders and themes mapped to their ids here). Only
103359
+ * what the profile says and this computer has.
103360
+ */
103361
+ function dashboardMeta(entry, folderId, themeKey) {
103362
+ const meta = {};
103363
+ if (typeof entry.name === "string" && entry.name.trim()) {
103364
+ meta.name = entry.name;
103365
+ meta.label = entry.name;
103366
+ }
103367
+ if (entry.folder != null && own(folderId, entry.folder)) {
103368
+ meta.menuId = folderId[entry.folder];
103369
+ }
103370
+ if (entry.theme && own(themeKey, entry.theme)) {
103371
+ meta.themeKey = themeKey[entry.theme];
103372
+ }
103373
+ return Object.keys(meta).length ? meta : null;
103374
+ }
103375
+
103356
103376
  /**
103357
103377
  * Provider names a profile's settings may name: the ones its file lists
103358
103378
  * (each shown in the preview), as this computer calls them. Anything else
@@ -103379,8 +103399,11 @@ function requireProfileLoadV2 () {
103379
103399
  ws,
103380
103400
  overlay,
103381
103401
  nameProvider = (n) => n,
103382
- { fillOnly = false } = {},
103402
+ { fillOnly = false, blankedSecret = null } = {},
103383
103403
  ) {
103404
+ // `blankedSecret(key, field)`: when given (keeping in step), an empty
103405
+ // value replaces this computer's unless it's a key or password the
103406
+ // profile left blank; otherwise an empty value never replaces one here.
103384
103407
  if (!ws || !overlay || !overlay.items || typeof overlay.items !== "object") {
103385
103408
  return ws;
103386
103409
  }
@@ -103405,7 +103428,13 @@ function requireProfileLoadV2 () {
103405
103428
  if (UNSAFE_KEYS.has(field) || LOCAL_PREFS.has(field)) continue;
103406
103429
  const here = prefs[field];
103407
103430
  const hasHere = here !== undefined && here !== null && here !== "";
103408
- if (value === "" && hasHere) continue;
103431
+ if (
103432
+ value === "" &&
103433
+ hasHere &&
103434
+ (!blankedSecret || blankedSecret(key, field))
103435
+ ) {
103436
+ continue;
103437
+ }
103409
103438
  if (fillOnly && hasHere) continue;
103410
103439
  prefs[field] = value;
103411
103440
  }
@@ -103474,6 +103503,16 @@ function requireProfileLoadV2 () {
103474
103503
 
103475
103504
  // Target (checked before anything is installed).
103476
103505
  const replacing = plan.target.mode === "replace" && !choices.asNew;
103506
+ // Loading a profile's own account copy into the profile it's linked to
103507
+ // (keeping it in step): the account's copy wins — what's already here
103508
+ // takes its names, folders, themes, widget settings and bot choices, not
103509
+ // just what's missing. A blanked key still never overwrites one here.
103510
+ // Set by the main process only (never from the renderer).
103511
+ const sync =
103512
+ choices.syncLinked === true &&
103513
+ replacing &&
103514
+ choices.linkedProfileId != null &&
103515
+ plan.target.profileId === choices.linkedProfileId;
103477
103516
  const name = replacing
103478
103517
  ? plan.target.name
103479
103518
  : String(choices.name || plan.target.name).trim();
@@ -103517,6 +103556,18 @@ function requireProfileLoadV2 () {
103517
103556
  row.action === "install" ||
103518
103557
  (row.action === "update" && !keep.has(id(row))) ||
103519
103558
  (row.action === "keep" && take.has(id(row)));
103559
+ // Rows the user kept at this computer's version.
103560
+ const keptHere = (row) =>
103561
+ (row.action === "keep" && !take.has(id(row))) ||
103562
+ (row.action === "update" && keep.has(id(row)));
103563
+ // Keys and passwords the profile left blank ("<item key>|<field>"), and
103564
+ // anything named like one.
103565
+ const blankedSecrets = new Set(
103566
+ (manifest.secretsToEnter || []).map((s) => `${s.item}|${s.field}`),
103567
+ );
103568
+ const { looksSecretName } = requireSecretFields();
103569
+ const blankedSecret = (key, field) =>
103570
+ blankedSecrets.has(`${key}|${field}`) || looksSecretName(field);
103520
103571
  const counts = { added: 0, updated: 0 };
103521
103572
  const count = (row) =>
103522
103573
  row.action === "install" ? (counts.added += 1) : (counts.updated += 1);
@@ -103568,12 +103619,36 @@ function requireProfileLoadV2 () {
103568
103619
  // 3. Folders the dashboards go in — by this computer's own folder ids.
103569
103620
  const folders = d.folderFile(appId);
103570
103621
  const folderId = Object.create(null);
103622
+ let foldersChanged = false;
103623
+ const folderElsewhere = (fid) =>
103624
+ store.hasProfiles(appId) &&
103625
+ store
103626
+ .list(appId)
103627
+ .some(
103628
+ (p) =>
103629
+ p.id !== plan.target.profileId &&
103630
+ ((p.items && p.items.folders) || [])
103631
+ .map(String)
103632
+ .includes(String(fid)),
103633
+ );
103571
103634
  for (const f of folders) {
103572
103635
  if (f && f.id != null) folderId[String(f.id)] = f.id;
103573
103636
  }
103574
- let foldersChanged = false;
103575
103637
  for (const f of manifest.folders) {
103576
- if (own(folderId, f.id)) continue;
103638
+ if (own(folderId, f.id)) {
103639
+ // Keeping in step: the account's folder name comes too — unless
103640
+ // another profile here uses that folder (folder 1 is on every
103641
+ // computer; renaming it would change theirs).
103642
+ const here =
103643
+ sync && !folderElsewhere(f.id)
103644
+ ? folders.find((x) => x && String(x.id) === String(f.id))
103645
+ : null;
103646
+ if (here && f.name && here.name !== f.name) {
103647
+ here.name = f.name;
103648
+ foldersChanged = true;
103649
+ }
103650
+ continue;
103651
+ }
103577
103652
  const newId = /^\d+$/.test(f.id) ? Number(f.id) : f.id;
103578
103653
  folders.push({
103579
103654
  id: newId,
@@ -103590,7 +103665,10 @@ function requireProfileLoadV2 () {
103590
103665
  for (const row of of("dashboard")) {
103591
103666
  const entry = manifest.dashboards[row.package] || {};
103592
103667
  if (row.localId != null) dashId[row.package] = row.localId;
103593
- let fillOnly = true;
103668
+ // Kept at this computer's version: its settings stay this computer's
103669
+ // (they belong to that version's layout) — only its name, folder and
103670
+ // theme follow the account.
103671
+ let fillOnly = !sync || keptHere(row);
103594
103672
  if (loads(row)) {
103595
103673
  const res = await d.installDashboard(win, appId, row.package, {
103596
103674
  version: row.version,
@@ -103617,7 +103695,7 @@ function requireProfileLoadV2 () {
103617
103695
  continue;
103618
103696
  }
103619
103697
  dashId[row.package] = res.workspace.id;
103620
- fillOnly = row.localId != null;
103698
+ fillOnly = !sync && row.localId != null;
103621
103699
  count(row);
103622
103700
  }
103623
103701
  if (dashId[row.package] == null) continue;
@@ -103625,15 +103703,21 @@ function requireProfileLoadV2 () {
103625
103703
  const overlay = own(dashboards, row.package)
103626
103704
  ? dashboards[row.package]
103627
103705
  : null;
103628
- if (!overlay) continue;
103706
+ // Keeping in step: the account's name, folder and theme come too.
103707
+ const meta = sync ? dashboardMeta(entry, folderId, themeKey) : null;
103708
+ if (!overlay && !meta) continue;
103629
103709
  const ws = d
103630
103710
  .workspaceFile(appId)
103631
103711
  .find((w) => String(w.id) === String(dashId[row.package]));
103632
103712
  if (ws) {
103633
- d.saveWorkspace(
103634
- appId,
103635
- applyDashboardOverlay(ws, overlay, nameProvider, { fillOnly }),
103636
- );
103713
+ let next = overlay
103714
+ ? applyDashboardOverlay(ws, overlay, nameProvider, {
103715
+ fillOnly,
103716
+ blankedSecret: sync && !fillOnly ? blankedSecret : null,
103717
+ })
103718
+ : ws;
103719
+ if (meta) next = { ...next, ...meta };
103720
+ d.saveWorkspace(appId, next);
103637
103721
  }
103638
103722
  }
103639
103723
 
@@ -103710,6 +103794,53 @@ function requireProfileLoadV2 () {
103710
103794
  count(row);
103711
103795
  }
103712
103796
 
103797
+ // Keeping in step: bots already here take the account's choices too
103798
+ // (an update in place or one already here otherwise keeps this computer's).
103799
+ if (sync) {
103800
+ const bots = d.allBots() || [];
103801
+ // A patch that would leave a bot here without any of its providers
103802
+ // (none of the account's map to one here) keeps this computer's.
103803
+ const syncPatch = (o, botId) => {
103804
+ const patch = botPatch(o, nameProvider);
103805
+ if (!patch) return null;
103806
+ const here = bots.find((b) => String(b.id) === String(botId));
103807
+ const hadSome =
103808
+ here && Array.isArray(here.mcpServers) && here.mcpServers.length > 0;
103809
+ if (hadSome && patch.mcpServers.length === 0) {
103810
+ delete patch.mcpServers;
103811
+ delete patch.toolSelections;
103812
+ }
103813
+ return patch;
103814
+ };
103815
+ for (const row of [...of("bot"), ...of("team")]) {
103816
+ if (row.action === "install" || row.action === "unavailable") continue;
103817
+ // Kept at this computer's version: it keeps how it runs here.
103818
+ if (keptHere(row)) continue;
103819
+ const overlay = own(botSettings, row.package)
103820
+ ? botSettings[row.package]
103821
+ : null;
103822
+ if (!overlay) continue;
103823
+ if (row.kind === "bot") {
103824
+ const patch = syncPatch(overlay, row.localId);
103825
+ if (patch && row.localId != null) d.updateBot(row.localId, patch);
103826
+ continue;
103827
+ }
103828
+ const entry = manifest.bots[row.package] || {};
103829
+ const wsId = entry.dashboard ? dashId[entry.dashboard] : null;
103830
+ // Members by name (a member renamed here keeps its own choices).
103831
+ for (const b of bots) {
103832
+ if (String(b.workspaceId) !== String(wsId)) continue;
103833
+ if (!refMatches("bot-team", b, row.package)) continue;
103834
+ const o =
103835
+ overlay.members && own(overlay.members, b.name)
103836
+ ? overlay.members[b.name]
103837
+ : null;
103838
+ const patch = syncPatch(o, b.id);
103839
+ if (patch) d.updateBot(b.id, patch);
103840
+ }
103841
+ }
103842
+ }
103843
+
103713
103844
  // 6. The profile: what it holds on this computer — its dashboards, every
103714
103845
  // bot on them (teams, leads, a dashboard's own team), its other bots.
103715
103846
  const after = d.allBots() || [];
@@ -105423,12 +105554,18 @@ const profileController$1 = {
105423
105554
  BrowserWindow.getAllWindows()[0] ||
105424
105555
  null;
105425
105556
  const { applyLoadV2 } = requireProfileLoadV2();
105426
- const { linkedProfileId: _notFromRenderer, ...chosen } = picked;
105557
+ const {
105558
+ linkedProfileId: _notFromRenderer,
105559
+ syncLinked: _notFromRendererEither,
105560
+ ...chosen
105561
+ } = picked;
105427
105562
  const fromAccount = entry.read.account || null;
105428
105563
  const result = await applyLoadV2(win, appId, entry.read.v2, {
105429
105564
  ...chosen,
105430
105565
  defaultItems,
105431
105566
  linkedProfileId: fromAccount ? entry.read.linkedProfileId : null,
105567
+ // The account's copy into the profile it's linked to: keep in step.
105568
+ syncLinked: !!(fromAccount && entry.read.linkedProfileId),
105432
105569
  });
105433
105570
  if (result.success) {
105434
105571
  openedFiles.delete(token);