@trops/dash-core 0.1.682 → 0.1.683

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -13845,6 +13845,13 @@ function parseEventString(eventString) {
13845
13845
  }
13846
13846
 
13847
13847
  /** Build an event string in the canonical runtime format. */
13848
+ /**
13849
+ * Bots publish on the same bus (`bot:<ref>[<botId>].<event>`); as listener
13850
+ * sources they aren't widgets in the layout (bot-teams TEAM-012).
13851
+ */
13852
+ function isBotSource(component) {
13853
+ return typeof component === "string" && component.startsWith("bot:");
13854
+ }
13848
13855
  function formatEventString(component, itemId, event) {
13849
13856
  return "".concat(component, "[").concat(itemId, "].").concat(event);
13850
13857
  }
@@ -14034,6 +14041,7 @@ function getCurrentWiring(workspace) {
14034
14041
  * message.
14035
14042
  */
14036
14043
  function getOrphanedListeners(workspace, getWidgetConfig) {
14044
+ var botEmitters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
14037
14045
  var wiring = getCurrentWiring(workspace);
14038
14046
  if (wiring.length === 0) return [];
14039
14047
 
@@ -14065,34 +14073,55 @@ function getOrphanedListeners(workspace, getWidgetConfig) {
14065
14073
  var _iterator2 = _createForOfIteratorHelper$O(wiring),
14066
14074
  _step2;
14067
14075
  try {
14076
+ var _loop = function _loop() {
14077
+ var w = _step2.value;
14078
+ // Bot sources (TEAM-012): judged against the dashboard's bots once they
14079
+ // are known (`botEmitters`); before that, left alone.
14080
+ if (isBotSource(w.sourceComponent)) {
14081
+ if (!Array.isArray(botEmitters)) return 0; // continue
14082
+ var bot = botEmitters.find(function (b) {
14083
+ return b.component === w.sourceComponent && String(b.itemId) === String(w.sourceItemId);
14084
+ });
14085
+ if (!bot) orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14086
+ reason: "bot-missing"
14087
+ }));else if (!bot.events.includes(w.eventName)) {
14088
+ orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14089
+ reason: "event-not-emitted"
14090
+ }));
14091
+ }
14092
+ return 0; // continue
14093
+ }
14094
+ var srcKey = "".concat(w.sourceComponent, "|").concat(w.sourceItemId);
14095
+ var src = byCompositeKey.get(srcKey);
14096
+ if (!src) {
14097
+ // No (component, id) match. If some OTHER widget still owns
14098
+ // this id, the source component changed; otherwise it's truly
14099
+ // missing. Preserves the user's ability to see whether a
14100
+ // rename happened vs. a delete.
14101
+ var fallback = byItemId.get(String(w.sourceItemId));
14102
+ orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14103
+ reason: fallback ? "source-component-mismatch" : "source-missing"
14104
+ }));
14105
+ return 0; // continue
14106
+ }
14107
+ if (!src.events.includes(w.eventName)) {
14108
+ orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14109
+ reason: "event-not-emitted"
14110
+ }));
14111
+ return 0; // continue
14112
+ }
14113
+ var receiverKey = "".concat(w.receiverComponent, "|").concat(w.receiverItemId);
14114
+ var receiver = byCompositeKey.get(receiverKey);
14115
+ if (receiver && !receiver.eventHandlers.includes(w.handlerName)) {
14116
+ orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14117
+ reason: "handler-not-declared"
14118
+ }));
14119
+ }
14120
+ },
14121
+ _ret;
14068
14122
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
14069
- var w = _step2.value;
14070
- var srcKey = "".concat(w.sourceComponent, "|").concat(w.sourceItemId);
14071
- var src = byCompositeKey.get(srcKey);
14072
- if (!src) {
14073
- // No (component, id) match. If some OTHER widget still owns
14074
- // this id, the source component changed; otherwise it's truly
14075
- // missing. Preserves the user's ability to see whether a
14076
- // rename happened vs. a delete.
14077
- var fallback = byItemId.get(String(w.sourceItemId));
14078
- orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14079
- reason: fallback ? "source-component-mismatch" : "source-missing"
14080
- }));
14081
- continue;
14082
- }
14083
- if (!src.events.includes(w.eventName)) {
14084
- orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14085
- reason: "event-not-emitted"
14086
- }));
14087
- continue;
14088
- }
14089
- var receiverKey = "".concat(w.receiverComponent, "|").concat(w.receiverItemId);
14090
- var receiver = byCompositeKey.get(receiverKey);
14091
- if (receiver && !receiver.eventHandlers.includes(w.handlerName)) {
14092
- orphans.push(_objectSpread$1b(_objectSpread$1b({}, w), {}, {
14093
- reason: "handler-not-declared"
14094
- }));
14095
- }
14123
+ _ret = _loop();
14124
+ if (_ret === 0) continue;
14096
14125
  }
14097
14126
  } catch (err) {
14098
14127
  _iterator2.e(err);
@@ -14184,7 +14213,9 @@ function pruneDeadListenerReferences(workspace) {
14184
14213
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
14185
14214
  var raw = _step6.value;
14186
14215
  var parsed = parseEventString(raw);
14187
- if (parsed && liveKeys.has("".concat(parsed.component, "|").concat(parsed.itemId))) {
14216
+ if (parsed && (
14217
+ // Bot sources live outside the layout — never pruned here.
14218
+ isBotSource(parsed.component) || liveKeys.has("".concat(parsed.component, "|").concat(parsed.itemId)))) {
14188
14219
  kept.push(raw);
14189
14220
  } else {
14190
14221
  removed += 1;
@@ -14347,7 +14378,7 @@ function applyToItem(listeners, _ref2) {
14347
14378
  var _iterator0 = _createForOfIteratorHelper$O(removes),
14348
14379
  _step0;
14349
14380
  try {
14350
- var _loop = function _loop() {
14381
+ var _loop2 = function _loop2() {
14351
14382
  var r = _step0.value;
14352
14383
  var target = r.handlerName;
14353
14384
  if (!target) return 0; // continue
@@ -14363,10 +14394,10 @@ function applyToItem(listeners, _ref2) {
14363
14394
  next[target] = filtered;
14364
14395
  }
14365
14396
  },
14366
- _ret;
14397
+ _ret2;
14367
14398
  for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
14368
- _ret = _loop();
14369
- if (_ret === 0) continue;
14399
+ _ret2 = _loop2();
14400
+ if (_ret2 === 0) continue;
14370
14401
  }
14371
14402
  } catch (err) {
14372
14403
  _iterator0.e(err);
@@ -48493,6 +48524,443 @@ function SharedFieldRow(_ref6) {
48493
48524
  function _createForOfIteratorHelper$q(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$q(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
48494
48525
  function _unsupportedIterableToArray$q(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$q(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$q(r, a) : void 0; } }
48495
48526
  function _arrayLikeToArray$q(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
48527
+
48528
+ /**
48529
+ * @param {Array<object>} workspaces dashboards (each with id, name, layout/pages)
48530
+ * @param {(component: string) => object|null} getWidgetConfig
48531
+ * @returns {Array<{ workspaceId: string, name: string,
48532
+ * widgets: Array<{ ref: string, instanceId: string, label: string, events: string[] }> }>}
48533
+ * dashboards with at least one event-emitting widget
48534
+ */
48535
+ function buildWidgetEventCatalog(workspaces, getWidgetConfig) {
48536
+ if (!Array.isArray(workspaces)) return [];
48537
+ var out = [];
48538
+ var _iterator = _createForOfIteratorHelper$q(workspaces),
48539
+ _step;
48540
+ try {
48541
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
48542
+ var ws = _step.value;
48543
+ if (!ws || ws.id === undefined || ws.id === null) continue;
48544
+ var widgets = getEmitters(ws, getWidgetConfig).filter(function (e) {
48545
+ return e.itemId != null && e.events.length;
48546
+ }).map(function (e) {
48547
+ return {
48548
+ ref: e.component,
48549
+ instanceId: String(e.itemId),
48550
+ label: e.label || e.component,
48551
+ events: e.events
48552
+ };
48553
+ });
48554
+ if (!widgets.length) continue;
48555
+ out.push({
48556
+ workspaceId: String(ws.id),
48557
+ name: ws.name || "Dashboard ".concat(ws.id),
48558
+ widgets: widgets
48559
+ });
48560
+ }
48561
+ // Dashboards can share a name (e.g. copies of "Kitchen Sink"); number the
48562
+ // duplicates so each picker entry is distinguishable.
48563
+ } catch (err) {
48564
+ _iterator.e(err);
48565
+ } finally {
48566
+ _iterator.f();
48567
+ }
48568
+ var totals = {};
48569
+ for (var _i = 0, _out = out; _i < _out.length; _i++) {
48570
+ var w = _out[_i];
48571
+ totals[w.name] = (totals[w.name] || 0) + 1;
48572
+ }
48573
+ var seen = {};
48574
+ for (var _i2 = 0, _out2 = out; _i2 < _out2.length; _i2++) {
48575
+ var _w = _out2[_i2];
48576
+ if (totals[_w.name] > 1) {
48577
+ seen[_w.name] = (seen[_w.name] || 0) + 1;
48578
+ _w.name = "".concat(_w.name, " (").concat(seen[_w.name], ")");
48579
+ }
48580
+ }
48581
+ return out;
48582
+ }
48583
+
48584
+ /** A subscription to one widget event, picked from the catalog. */
48585
+ function widgetSubscription(workspace, widget, event) {
48586
+ return {
48587
+ eventType: formatEventString(widget.ref, widget.instanceId, event),
48588
+ source: {
48589
+ kind: "widget",
48590
+ ref: widget.ref,
48591
+ instanceId: widget.instanceId,
48592
+ event: event,
48593
+ workspaceId: workspace.workspaceId
48594
+ },
48595
+ label: "".concat(workspace.name, " \u203A ").concat(widget.label, " \u203A ").concat(event)
48596
+ };
48597
+ }
48598
+
48599
+ /**
48600
+ * How to show a saved subscription: its label from the live catalog, and
48601
+ * whether its widget/event is gone (`missing`). Subscriptions saved before
48602
+ * the picker (bare eventType) get a friendly label when they still resolve;
48603
+ * otherwise they show as typed.
48604
+ */
48605
+ function describeSubscription(sub, catalog) {
48606
+ var botCatalog = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
48607
+ var eventType = sub && sub.eventType;
48608
+ // Bot subscriptions resolve against the bot catalog; `kind` lets the form
48609
+ // say "bot missing" instead of "widget missing".
48610
+ if (sub && sub.source && sub.source.kind === "bot") {
48611
+ var _iterator2 = _createForOfIteratorHelper$q(botCatalog || []),
48612
+ _step2;
48613
+ try {
48614
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
48615
+ var b = _step2.value;
48616
+ var _iterator3 = _createForOfIteratorHelper$q(b.events),
48617
+ _step3;
48618
+ try {
48619
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
48620
+ var ev = _step3.value;
48621
+ var s = botSubscription(b, ev);
48622
+ if (s.eventType === eventType) {
48623
+ return {
48624
+ label: s.label,
48625
+ missing: false,
48626
+ kind: "bot"
48627
+ };
48628
+ }
48629
+ }
48630
+ } catch (err) {
48631
+ _iterator3.e(err);
48632
+ } finally {
48633
+ _iterator3.f();
48634
+ }
48635
+ }
48636
+ } catch (err) {
48637
+ _iterator2.e(err);
48638
+ } finally {
48639
+ _iterator2.f();
48640
+ }
48641
+ return {
48642
+ label: sub.label || eventType,
48643
+ missing: true,
48644
+ kind: "bot"
48645
+ };
48646
+ }
48647
+ var _iterator4 = _createForOfIteratorHelper$q(catalog || []),
48648
+ _step4;
48649
+ try {
48650
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
48651
+ var ws = _step4.value;
48652
+ var _iterator5 = _createForOfIteratorHelper$q(ws.widgets),
48653
+ _step5;
48654
+ try {
48655
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
48656
+ var w = _step5.value;
48657
+ var _iterator6 = _createForOfIteratorHelper$q(w.events),
48658
+ _step6;
48659
+ try {
48660
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
48661
+ var _ev = _step6.value;
48662
+ if (formatEventString(w.ref, w.instanceId, _ev) === eventType) {
48663
+ return {
48664
+ label: widgetSubscription(ws, w, _ev).label,
48665
+ missing: false
48666
+ };
48667
+ }
48668
+ }
48669
+ } catch (err) {
48670
+ _iterator6.e(err);
48671
+ } finally {
48672
+ _iterator6.f();
48673
+ }
48674
+ }
48675
+ } catch (err) {
48676
+ _iterator5.e(err);
48677
+ } finally {
48678
+ _iterator5.f();
48679
+ }
48680
+ }
48681
+ } catch (err) {
48682
+ _iterator4.e(err);
48683
+ } finally {
48684
+ _iterator4.f();
48685
+ }
48686
+ if (sub && sub.source) {
48687
+ return {
48688
+ label: sub.label || eventType,
48689
+ missing: true
48690
+ };
48691
+ }
48692
+ return {
48693
+ label: eventType || "",
48694
+ missing: false
48695
+ };
48696
+ }
48697
+
48698
+ /**
48699
+ * Events other bots publish (bot:<ref>[<botId>].<event>, PRD US-010), for the
48700
+ * "Another bot" side of the picker. Derived from each bot's settings — never
48701
+ * hand-declared: Completed, Failed, and one `tool.<providerType>.<tool>` per
48702
+ * tool the bot may use (the provider's tools, narrowed by the bot's
48703
+ * selection). Providers with no known type or tool list are skipped.
48704
+ *
48705
+ * @param {Array<object>} bots
48706
+ * @param {Array<{name, type, tools}>} toolSources bots.listToolSources()
48707
+ * @param {string} [excludeBotId] the bot being edited — can't trigger itself
48708
+ */
48709
+ function buildBotEventCatalog(bots, toolSources) {
48710
+ var excludeBotId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
48711
+ if (!Array.isArray(bots)) return [];
48712
+ var sources = Array.isArray(toolSources) ? toolSources : [];
48713
+ var out = [];
48714
+ var _iterator7 = _createForOfIteratorHelper$q(bots),
48715
+ _step7;
48716
+ try {
48717
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
48718
+ var bot = _step7.value;
48719
+ if (!bot || !bot.id || !bot.ref || bot.id === excludeBotId) continue;
48720
+ var events = [{
48721
+ event: "completed",
48722
+ label: "Completed"
48723
+ }, {
48724
+ event: "failed",
48725
+ label: "Failed"
48726
+ }];
48727
+ var _iterator8 = _createForOfIteratorHelper$q(bot.mcpServers || []),
48728
+ _step8;
48729
+ try {
48730
+ var _loop = function _loop() {
48731
+ var provider = _step8.value;
48732
+ var src = sources.find(function (s) {
48733
+ return s && s.name === provider;
48734
+ });
48735
+ if (!src || !src.type || !Array.isArray(src.tools)) return 1; // continue
48736
+ var sel = bot.toolSelections && bot.toolSelections[provider];
48737
+ var tools = Array.isArray(sel) ? src.tools.filter(function (t) {
48738
+ return sel.includes(t);
48739
+ }) : src.tools;
48740
+ var _iterator9 = _createForOfIteratorHelper$q(tools),
48741
+ _step9;
48742
+ try {
48743
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
48744
+ var tool = _step9.value;
48745
+ events.push({
48746
+ event: "tool.".concat(src.type, ".").concat(tool),
48747
+ label: "".concat(provider, " \u203A ").concat(tool)
48748
+ });
48749
+ }
48750
+ } catch (err) {
48751
+ _iterator9.e(err);
48752
+ } finally {
48753
+ _iterator9.f();
48754
+ }
48755
+ };
48756
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
48757
+ if (_loop()) continue;
48758
+ }
48759
+ } catch (err) {
48760
+ _iterator8.e(err);
48761
+ } finally {
48762
+ _iterator8.f();
48763
+ }
48764
+ out.push({
48765
+ botId: bot.id,
48766
+ ref: bot.ref,
48767
+ name: bot.name || bot.id,
48768
+ events: events
48769
+ });
48770
+ }
48771
+ } catch (err) {
48772
+ _iterator7.e(err);
48773
+ } finally {
48774
+ _iterator7.f();
48775
+ }
48776
+ return out;
48777
+ }
48778
+
48779
+ /** A subscription to one bot event, picked from the bot catalog. */
48780
+ function botSubscription(botEntry, ev) {
48781
+ return {
48782
+ eventType: "bot:".concat(botEntry.ref, "[").concat(botEntry.botId, "].").concat(ev.event),
48783
+ source: {
48784
+ kind: "bot",
48785
+ ref: botEntry.ref,
48786
+ instanceId: botEntry.botId,
48787
+ event: ev.event
48788
+ },
48789
+ label: "".concat(botEntry.name, " \u203A ").concat(ev.label)
48790
+ };
48791
+ }
48792
+ function botEventLabel(ev) {
48793
+ if (!ev.event.startsWith("tool.")) return ev.label;
48794
+ // Tool events are labelled "<provider> › <tool>" in the catalog.
48795
+ var _String$split = String(ev.label).split(" › "),
48796
+ _String$split2 = _slicedToArray(_String$split, 2),
48797
+ provider = _String$split2[0],
48798
+ tool = _String$split2[1];
48799
+ return tool ? "uses ".concat(tool, " (").concat(provider, ")") : ev.label;
48800
+ }
48801
+
48802
+ /**
48803
+ * Everything that can trigger a bot, flattened for one "Runs when…" picker
48804
+ * (bot-teams TEAM-012): `{ value, label, group, subscription }`, value = the
48805
+ * subscription's eventType.
48806
+ *
48807
+ * A team bot only runs on its own dashboard's events, so it's offered that
48808
+ * dashboard's widgets ("Widgets on <dashboard>") and its teammates ("Bots on
48809
+ * this team"). An unassigned bot is offered every dashboard's widgets and
48810
+ * every bot ("Bots", labelled with their dashboard). The bot itself and
48811
+ * triggers it already has are left out; two copies of one widget are
48812
+ * numbered.
48813
+ *
48814
+ * @param {{ team: string|null, workspaces: object[], getWidgetConfig: Function,
48815
+ * bots: object[], toolSources: object[], botId?: string,
48816
+ * existing?: string[] }} input
48817
+ */
48818
+ function buildTriggerOptions(_ref) {
48819
+ var _ref$team = _ref.team,
48820
+ team = _ref$team === void 0 ? null : _ref$team,
48821
+ _ref$workspaces = _ref.workspaces,
48822
+ workspaces = _ref$workspaces === void 0 ? [] : _ref$workspaces,
48823
+ _ref$getWidgetConfig = _ref.getWidgetConfig,
48824
+ getWidgetConfig = _ref$getWidgetConfig === void 0 ? null : _ref$getWidgetConfig,
48825
+ _ref$bots = _ref.bots,
48826
+ bots = _ref$bots === void 0 ? [] : _ref$bots,
48827
+ _ref$toolSources = _ref.toolSources,
48828
+ toolSources = _ref$toolSources === void 0 ? [] : _ref$toolSources,
48829
+ _ref$botId = _ref.botId,
48830
+ botId = _ref$botId === void 0 ? null : _ref$botId,
48831
+ _ref$existing = _ref.existing,
48832
+ existing = _ref$existing === void 0 ? [] : _ref$existing;
48833
+ var teamKey = team === null || team === undefined || team === "" ? null : String(team);
48834
+ var taken = new Set(existing || []);
48835
+ var out = [];
48836
+
48837
+ // Widgets.
48838
+ var wsList = (Array.isArray(workspaces) ? workspaces : []).filter(function (ws) {
48839
+ return ws && (teamKey === null || String(ws.id) === teamKey);
48840
+ });
48841
+ var _iterator0 = _createForOfIteratorHelper$q(buildWidgetEventCatalog(wsList, getWidgetConfig)),
48842
+ _step0;
48843
+ try {
48844
+ for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
48845
+ var ws = _step0.value;
48846
+ var group = "Widgets on ".concat(ws.name);
48847
+ var seen = {};
48848
+ var _iterator10 = _createForOfIteratorHelper$q(ws.widgets),
48849
+ _step10;
48850
+ try {
48851
+ for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
48852
+ var widget = _step10.value;
48853
+ seen[widget.label] = (seen[widget.label] || 0) + 1;
48854
+ var name = seen[widget.label] > 1 ? "".concat(widget.label, " (").concat(seen[widget.label], ")") : widget.label;
48855
+ var _iterator11 = _createForOfIteratorHelper$q(widget.events),
48856
+ _step11;
48857
+ try {
48858
+ for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
48859
+ var event = _step11.value;
48860
+ var subscription = widgetSubscription(ws, widget, event);
48861
+ if (taken.has(subscription.eventType)) continue;
48862
+ out.push({
48863
+ value: subscription.eventType,
48864
+ label: "".concat(name, " \u203A ").concat(event),
48865
+ group: group,
48866
+ subscription: subscription
48867
+ });
48868
+ }
48869
+ } catch (err) {
48870
+ _iterator11.e(err);
48871
+ } finally {
48872
+ _iterator11.f();
48873
+ }
48874
+ }
48875
+ } catch (err) {
48876
+ _iterator10.e(err);
48877
+ } finally {
48878
+ _iterator10.f();
48879
+ }
48880
+ }
48881
+
48882
+ // Bots.
48883
+ } catch (err) {
48884
+ _iterator0.e(err);
48885
+ } finally {
48886
+ _iterator0.f();
48887
+ }
48888
+ var nameOfWs = new Map((Array.isArray(workspaces) ? workspaces : []).filter(Boolean).map(function (ws) {
48889
+ return [String(ws.id), ws.name || "Dashboard ".concat(ws.id)];
48890
+ }));
48891
+ var candidates = (Array.isArray(bots) ? bots : []).filter(function (b) {
48892
+ return b && (teamKey === null || b.workspaceId !== null && b.workspaceId !== undefined && String(b.workspaceId) === teamKey);
48893
+ });
48894
+ var wsOf = new Map(candidates.map(function (b) {
48895
+ return [b.id, b.workspaceId];
48896
+ }));
48897
+ var _iterator1 = _createForOfIteratorHelper$q(buildBotEventCatalog(candidates, toolSources, botId)),
48898
+ _step1;
48899
+ try {
48900
+ for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
48901
+ var entry = _step1.value;
48902
+ var where = teamKey === null && wsOf.get(entry.botId) !== null && wsOf.get(entry.botId) !== undefined ? " (".concat(nameOfWs.get(String(wsOf.get(entry.botId))) || "another dashboard", ")") : "";
48903
+ var _iterator12 = _createForOfIteratorHelper$q(entry.events),
48904
+ _step12;
48905
+ try {
48906
+ for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
48907
+ var ev = _step12.value;
48908
+ var _subscription = botSubscription(entry, ev);
48909
+ if (taken.has(_subscription.eventType)) continue;
48910
+ out.push({
48911
+ value: _subscription.eventType,
48912
+ label: "".concat(entry.name).concat(where, " \u203A ").concat(botEventLabel(ev)),
48913
+ group: teamKey === null ? "Bots" : "Bots on this team",
48914
+ subscription: _subscription
48915
+ });
48916
+ }
48917
+ } catch (err) {
48918
+ _iterator12.e(err);
48919
+ } finally {
48920
+ _iterator12.f();
48921
+ }
48922
+ }
48923
+ } catch (err) {
48924
+ _iterator1.e(err);
48925
+ } finally {
48926
+ _iterator1.f();
48927
+ }
48928
+ return out;
48929
+ }
48930
+
48931
+ /**
48932
+ * A dashboard's bots as Dashboard Config › Listeners sources (bot-teams
48933
+ * TEAM-012), shaped like getEmitters() entries: component `bot:<ref>`,
48934
+ * itemId = bot id, so a wired handler stores `bot:<ref>[<botId>].<event>` —
48935
+ * exactly what bots publish on the bus.
48936
+ *
48937
+ * @param {object[]} bots
48938
+ * @param {object[]} toolSources bots.listToolSources()
48939
+ * @param {string|number} workspaceId
48940
+ */
48941
+ function getBotEmitters(bots, toolSources, workspaceId) {
48942
+ if (workspaceId === null || workspaceId === undefined || workspaceId === "") {
48943
+ return [];
48944
+ }
48945
+ var team = (Array.isArray(bots) ? bots : []).filter(function (b) {
48946
+ return b && b.workspaceId !== null && b.workspaceId !== undefined && String(b.workspaceId) === String(workspaceId);
48947
+ });
48948
+ return buildBotEventCatalog(team, toolSources).map(function (entry) {
48949
+ return {
48950
+ key: "bot:".concat(entry.ref, "|").concat(entry.botId),
48951
+ component: "bot:".concat(entry.ref),
48952
+ itemId: entry.botId,
48953
+ label: "".concat(entry.name, " (bot)"),
48954
+ events: entry.events.map(function (e) {
48955
+ return e.event;
48956
+ })
48957
+ };
48958
+ });
48959
+ }
48960
+
48961
+ function _createForOfIteratorHelper$p(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$p(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
48962
+ function _unsupportedIterableToArray$p(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$p(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$p(r, a) : void 0; } }
48963
+ function _arrayLikeToArray$p(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
48496
48964
  var PermissionsTab = function PermissionsTab(_ref) {
48497
48965
  var workspace = _ref.workspace;
48498
48966
  var _React$useContext = React__default.useContext(AppContext),
@@ -48719,7 +49187,7 @@ var PermissionsTab = function PermissionsTab(_ref) {
48719
49187
  return _context4.abrupt("return");
48720
49188
  case 3:
48721
49189
  next = currentGrant;
48722
- _iterator = _createForOfIteratorHelper$q(declaredTools);
49190
+ _iterator = _createForOfIteratorHelper$p(declaredTools);
48723
49191
  try {
48724
49192
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
48725
49193
  tool = _step.value;
@@ -48879,7 +49347,7 @@ var PermissionsTab = function PermissionsTab(_ref) {
48879
49347
  }
48880
49348
  }
48881
49349
  targets = labels.length > 0 ? labels : [serverName];
48882
- _iterator2 = _createForOfIteratorHelper$q(targets);
49350
+ _iterator2 = _createForOfIteratorHelper$p(targets);
48883
49351
  _context8.prev = 1;
48884
49352
  _iterator2.s();
48885
49353
  case 2:
@@ -48935,7 +49403,7 @@ var PermissionsTab = function PermissionsTab(_ref) {
48935
49403
  case 0:
48936
49404
  setBusy(true);
48937
49405
  _context9.prev = 1;
48938
- _iterator3 = _createForOfIteratorHelper$q(filteredRows);
49406
+ _iterator3 = _createForOfIteratorHelper$p(filteredRows);
48939
49407
  _context9.prev = 2;
48940
49408
  _iterator3.s();
48941
49409
  case 3:
@@ -48994,7 +49462,7 @@ var PermissionsTab = function PermissionsTab(_ref) {
48994
49462
  case 0:
48995
49463
  setBusy(true);
48996
49464
  _context0.prev = 1;
48997
- _iterator4 = _createForOfIteratorHelper$q(filteredRows);
49465
+ _iterator4 = _createForOfIteratorHelper$p(filteredRows);
48998
49466
  _context0.prev = 2;
48999
49467
  _iterator4.s();
49000
49468
  case 3:
@@ -49154,9 +49622,9 @@ var PermissionsTab = function PermissionsTab(_ref) {
49154
49622
  });
49155
49623
  };
49156
49624
 
49157
- function _createForOfIteratorHelper$p(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$p(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
49158
- function _unsupportedIterableToArray$p(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$p(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$p(r, a) : void 0; } }
49159
- function _arrayLikeToArray$p(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
49625
+ function _createForOfIteratorHelper$o(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$o(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
49626
+ function _unsupportedIterableToArray$o(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$o(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$o(r, a) : void 0; } }
49627
+ function _arrayLikeToArray$o(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
49160
49628
  /**
49161
49629
  * teamUtils.js
49162
49630
  *
@@ -49189,7 +49657,7 @@ function dashboardOptions(workspaces) {
49189
49657
  return w && norm(w.id) !== null;
49190
49658
  });
49191
49659
  var totals = {};
49192
- var _iterator = _createForOfIteratorHelper$p(list),
49660
+ var _iterator = _createForOfIteratorHelper$o(list),
49193
49661
  _step;
49194
49662
  try {
49195
49663
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -49236,7 +49704,7 @@ function groupBotsByTeam(bots, workspaces) {
49236
49704
  label: "Unassigned",
49237
49705
  bots: []
49238
49706
  };
49239
- var _iterator2 = _createForOfIteratorHelper$p(list),
49707
+ var _iterator2 = _createForOfIteratorHelper$o(list),
49240
49708
  _step2;
49241
49709
  try {
49242
49710
  var _loop = function _loop() {
@@ -49977,9 +50445,9 @@ var BotsTab = function BotsTab(_ref2) {
49977
50445
  });
49978
50446
  };
49979
50447
 
49980
- function _createForOfIteratorHelper$o(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$o(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
49981
- function _unsupportedIterableToArray$o(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$o(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$o(r, a) : void 0; } }
49982
- function _arrayLikeToArray$o(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
50448
+ function _createForOfIteratorHelper$n(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$n(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
50449
+ function _unsupportedIterableToArray$n(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$n(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$n(r, a) : void 0; } }
50450
+ function _arrayLikeToArray$n(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
49983
50451
  function ownKeys$A(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
49984
50452
  function _objectSpread$A(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$A(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$A(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
49985
50453
  var ConfigTab = function ConfigTab(_ref) {
@@ -50138,7 +50606,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50138
50606
  };
50139
50607
  if (!appProviders) return byType;
50140
50608
  if (Array.isArray(appProviders)) {
50141
- var _iterator = _createForOfIteratorHelper$o(appProviders),
50609
+ var _iterator = _createForOfIteratorHelper$n(appProviders),
50142
50610
  _step;
50143
50611
  try {
50144
50612
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -50204,7 +50672,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50204
50672
  });
50205
50673
  }
50206
50674
  if (Array.isArray(workspace === null || workspace === void 0 ? void 0 : workspace.pages)) {
50207
- var _iterator2 = _createForOfIteratorHelper$o(workspace.pages),
50675
+ var _iterator2 = _createForOfIteratorHelper$n(workspace.pages),
50208
50676
  _step2;
50209
50677
  try {
50210
50678
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -50231,7 +50699,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50231
50699
  var visitedByLocation = new WeakSet();
50232
50700
  var _collect = function collect(items, location) {
50233
50701
  if (!Array.isArray(items)) return;
50234
- var _iterator3 = _createForOfIteratorHelper$o(items),
50702
+ var _iterator3 = _createForOfIteratorHelper$n(items),
50235
50703
  _step3;
50236
50704
  try {
50237
50705
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
@@ -50302,9 +50770,33 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50302
50770
  return null;
50303
50771
  };
50304
50772
  }, [getWidgetConfig]);
50773
+ // This dashboard's bots as Listeners sources (TEAM-012); null until
50774
+ // loaded so their wiring isn't judged before the bots are known.
50775
+ var _useState9 = useState(null),
50776
+ _useState0 = _slicedToArray(_useState9, 2),
50777
+ botEmitters = _useState0[0],
50778
+ setBotEmitters = _useState0[1];
50779
+ var workspaceId = workspace ? workspace.id : null;
50780
+ useEffect(function () {
50781
+ var _window$mainApi;
50782
+ var bots = typeof window !== "undefined" && ((_window$mainApi = window.mainApi) === null || _window$mainApi === void 0 ? void 0 : _window$mainApi.bots);
50783
+ if (!isOpen || !bots || !bots.list || workspaceId == null) return undefined;
50784
+ var alive = true;
50785
+ Promise.all([bots.list(), bots.listToolSources ? bots.listToolSources() : Promise.resolve([])]).then(function (_ref5) {
50786
+ var _ref6 = _slicedToArray(_ref5, 2),
50787
+ list = _ref6[0],
50788
+ sources = _ref6[1];
50789
+ if (alive) setBotEmitters(getBotEmitters(list, sources, workspaceId));
50790
+ })["catch"](function () {
50791
+ if (alive) setBotEmitters([]);
50792
+ });
50793
+ return function () {
50794
+ alive = false;
50795
+ };
50796
+ }, [isOpen, workspaceId]);
50305
50797
  var emitters = useMemo(function () {
50306
- return getEmitters(workspace, wConfig);
50307
- }, [workspace, wConfig]);
50798
+ return [].concat(_toConsumableArray(getEmitters(workspace, wConfig)), _toConsumableArray(botEmitters || []));
50799
+ }, [workspace, wConfig, botEmitters]);
50308
50800
  var receivers = useMemo(function () {
50309
50801
  return getReceivers(workspace, wConfig);
50310
50802
  }, [workspace, wConfig]);
@@ -50312,8 +50804,8 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50312
50804
  return getCurrentWiring(workspace);
50313
50805
  }, [workspace]);
50314
50806
  var orphans = useMemo(function () {
50315
- return getOrphanedListeners(workspace, wConfig);
50316
- }, [workspace, wConfig]);
50807
+ return getOrphanedListeners(workspace, wConfig, botEmitters);
50808
+ }, [workspace, wConfig, botEmitters]);
50317
50809
  var effectiveWiring = useMemo(function () {
50318
50810
  // Apply staged removes/adds to the persisted wiring for an
50319
50811
  // accurate "what will be there after save" view, then annotate
@@ -50329,7 +50821,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50329
50821
  }
50330
50822
  if (stagedListeners.adds.length > 0) {
50331
50823
  // Append; avoid duplicates against current state.
50332
- var _iterator4 = _createForOfIteratorHelper$o(stagedListeners.adds),
50824
+ var _iterator4 = _createForOfIteratorHelper$n(stagedListeners.adds),
50333
50825
  _step4;
50334
50826
  try {
50335
50827
  var _loop = function _loop() {
@@ -50353,7 +50845,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50353
50845
  }
50354
50846
  if (orphans.length === 0) return next;
50355
50847
  var orphanIndex = new Map();
50356
- var _iterator5 = _createForOfIteratorHelper$o(orphans),
50848
+ var _iterator5 = _createForOfIteratorHelper$n(orphans),
50357
50849
  _step5;
50358
50850
  try {
50359
50851
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
@@ -50395,7 +50887,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50395
50887
  function stagePrefFieldForAll(targetWidgets, key, value) {
50396
50888
  setStagedPrefs(function (prev) {
50397
50889
  var next = _objectSpread$A({}, prev);
50398
- var _iterator6 = _createForOfIteratorHelper$o(targetWidgets),
50890
+ var _iterator6 = _createForOfIteratorHelper$n(targetWidgets),
50399
50891
  _step6;
50400
50892
  try {
50401
50893
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
@@ -50440,7 +50932,7 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50440
50932
  });
50441
50933
  setStaged(function (prev) {
50442
50934
  var next = _objectSpread$A({}, prev);
50443
- var _iterator7 = _createForOfIteratorHelper$o(affected),
50935
+ var _iterator7 = _createForOfIteratorHelper$n(affected),
50444
50936
  _step7;
50445
50937
  try {
50446
50938
  for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
@@ -50741,29 +51233,29 @@ var DashboardConfigModal = function DashboardConfigModal(_ref2) {
50741
51233
  * write fails the user can re-toggle. No staging — the bulk modal
50742
51234
  * doesn't gate the user behind a Save button for boolean prefs.
50743
51235
  */
50744
- function NotificationsTab(_ref5) {
50745
- var workspace = _ref5.workspace;
51236
+ function NotificationsTab(_ref7) {
51237
+ var workspace = _ref7.workspace;
50746
51238
  var _useConfigTokens3 = useConfigTokens(),
50747
51239
  muted = _useConfigTokens3.muted,
50748
51240
  hairline = _useConfigTokens3.hairline;
50749
- var _useState9 = useState(""),
50750
- _useState0 = _slicedToArray(_useState9, 2),
50751
- searchQuery = _useState0[0],
50752
- setSearchQuery = _useState0[1];
51241
+ var _useState1 = useState(""),
51242
+ _useState10 = _slicedToArray(_useState1, 2),
51243
+ searchQuery = _useState10[0],
51244
+ setSearchQuery = _useState10[1];
50753
51245
  // Local mirror of widgetUuid -> { typeKey: bool }. Seeded from the
50754
51246
  // main process on mount; updated optimistically on toggle.
50755
- var _useState1 = useState({}),
50756
- _useState10 = _slicedToArray(_useState1, 2),
50757
- prefs = _useState10[0],
50758
- setPrefs = _useState10[1];
50759
- var _useState11 = useState(false),
51247
+ var _useState11 = useState({}),
50760
51248
  _useState12 = _slicedToArray(_useState11, 2),
50761
- loaded = _useState12[0],
50762
- setLoaded = _useState12[1];
51249
+ prefs = _useState12[0],
51250
+ setPrefs = _useState12[1];
51251
+ var _useState13 = useState(false),
51252
+ _useState14 = _slicedToArray(_useState13, 2),
51253
+ loaded = _useState14[0],
51254
+ setLoaded = _useState14[1];
50763
51255
  React__default.useEffect(function () {
50764
- var _window$mainApi;
51256
+ var _window$mainApi2;
50765
51257
  var cancelled = false;
50766
- if (!((_window$mainApi = window.mainApi) !== null && _window$mainApi !== void 0 && (_window$mainApi = _window$mainApi.notifications) !== null && _window$mainApi !== void 0 && _window$mainApi.getPreferences)) {
51258
+ if (!((_window$mainApi2 = window.mainApi) !== null && _window$mainApi2 !== void 0 && (_window$mainApi2 = _window$mainApi2.notifications) !== null && _window$mainApi2 !== void 0 && _window$mainApi2.getPreferences)) {
50767
51259
  setLoaded(true);
50768
51260
  return function () {
50769
51261
  cancelled = true;
@@ -50857,11 +51349,11 @@ function NotificationsTab(_ref5) {
50857
51349
  return !!defaultEnabled;
50858
51350
  };
50859
51351
  var setOne = function setOne(uuid, typeKey, value) {
50860
- var _window$mainApi2;
51352
+ var _window$mainApi3;
50861
51353
  setPrefs(function (prev) {
50862
51354
  return _objectSpread$A(_objectSpread$A({}, prev), {}, _defineProperty({}, uuid, _objectSpread$A(_objectSpread$A({}, prev[uuid] || {}), {}, _defineProperty({}, typeKey, value))));
50863
51355
  });
50864
- (_window$mainApi2 = window.mainApi) === null || _window$mainApi2 === void 0 || (_window$mainApi2 = _window$mainApi2.notifications) === null || _window$mainApi2 === void 0 || _window$mainApi2.setPreferences(uuid, _defineProperty({}, typeKey, value));
51356
+ (_window$mainApi3 = window.mainApi) === null || _window$mainApi3 === void 0 || (_window$mainApi3 = _window$mainApi3.notifications) === null || _window$mainApi3 === void 0 || _window$mainApi3.setPreferences(uuid, _defineProperty({}, typeKey, value));
50865
51357
  };
50866
51358
  var setAllVisible = function setAllVisible(value) {
50867
51359
  // Update local state in one pass + fire one IPC per widget.
@@ -50877,12 +51369,12 @@ function NotificationsTab(_ref5) {
50877
51369
  return next;
50878
51370
  });
50879
51371
  filtered.forEach(function (wi) {
50880
- var _window$mainApi3;
51372
+ var _window$mainApi4;
50881
51373
  var update = {};
50882
51374
  wi.notifications.forEach(function (n) {
50883
51375
  update[n.key] = value;
50884
51376
  });
50885
- (_window$mainApi3 = window.mainApi) === null || _window$mainApi3 === void 0 || (_window$mainApi3 = _window$mainApi3.notifications) === null || _window$mainApi3 === void 0 || _window$mainApi3.setPreferences(wi.uuid, update);
51377
+ (_window$mainApi4 = window.mainApi) === null || _window$mainApi4 === void 0 || (_window$mainApi4 = _window$mainApi4.notifications) === null || _window$mainApi4 === void 0 || _window$mainApi4.setPreferences(wi.uuid, update);
50886
51378
  });
50887
51379
  };
50888
51380
  if (!loaded) {
@@ -50986,12 +51478,12 @@ function NotificationsTab(_ref5) {
50986
51478
  * dot per-type when any widget of that type is unresolved). Column 2
50987
51479
  * shows the selected type's bulk dropdown + per-widget dropdowns.
50988
51480
  */
50989
- function ProvidersTab(_ref6) {
51481
+ function ProvidersTab(_ref8) {
50990
51482
  var _typeEntries$, _selectedRows$;
50991
- var grouped = _ref6.grouped,
50992
- providersByType = _ref6.providersByType,
50993
- onBulk = _ref6.onBulk,
50994
- onPerWidget = _ref6.onPerWidget;
51483
+ var grouped = _ref8.grouped,
51484
+ providersByType = _ref8.providersByType,
51485
+ onBulk = _ref8.onBulk,
51486
+ onPerWidget = _ref8.onPerWidget;
50995
51487
  var _useConfigTokens4 = useConfigTokens(),
50996
51488
  muted = _useConfigTokens4.muted,
50997
51489
  hairline = _useConfigTokens4.hairline,
@@ -50999,10 +51491,10 @@ function ProvidersTab(_ref6) {
50999
51491
  var typeEntries = useMemo(function () {
51000
51492
  return Array.from(grouped.entries());
51001
51493
  }, [grouped]);
51002
- var _useState13 = useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
51003
- _useState14 = _slicedToArray(_useState13, 2),
51004
- selectedType = _useState14[0],
51005
- setSelectedType = _useState14[1];
51494
+ var _useState15 = useState(((_typeEntries$ = typeEntries[0]) === null || _typeEntries$ === void 0 ? void 0 : _typeEntries$[0]) || null),
51495
+ _useState16 = _slicedToArray(_useState15, 2),
51496
+ selectedType = _useState16[0],
51497
+ setSelectedType = _useState16[1];
51006
51498
 
51007
51499
  // If the selected type disappears (workspace changed), fall back.
51008
51500
  useMemo(function () {
@@ -51032,10 +51524,10 @@ function ProvidersTab(_ref6) {
51032
51524
  children: "Provider Types"
51033
51525
  }), /*#__PURE__*/jsx("div", {
51034
51526
  className: "overflow-y-auto flex-1 flex flex-col gap-1",
51035
- children: typeEntries.map(function (_ref7) {
51036
- var _ref8 = _slicedToArray(_ref7, 2),
51037
- providerType = _ref8[0],
51038
- rows = _ref8[1];
51527
+ children: typeEntries.map(function (_ref9) {
51528
+ var _ref0 = _slicedToArray(_ref9, 2),
51529
+ providerType = _ref0[0],
51530
+ rows = _ref0[1];
51039
51531
  var unresolvedHere = rows.filter(function (r) {
51040
51532
  return r.required && !r.resolvedProviderName;
51041
51533
  }).length;
@@ -51178,8 +51670,8 @@ function ProvidersTab(_ref6) {
51178
51670
  * package (no `config.id` / `config.package` / item.workspace hint).
51179
51671
  * Usually this is a stale layout item whose widget got uninstalled.
51180
51672
  */
51181
- function DependenciesTab(_ref0) {
51182
- var dependencies = _ref0.dependencies;
51673
+ function DependenciesTab(_ref10) {
51674
+ var dependencies = _ref10.dependencies;
51183
51675
  var _useConfigTokens5 = useConfigTokens(),
51184
51676
  muted = _useConfigTokens5.muted,
51185
51677
  hairline = _useConfigTokens5.hairline;
@@ -51256,24 +51748,24 @@ function sameWiringEntry(a, b) {
51256
51748
  * adjusts wiring per handler from a single dropdown of all emitters'
51257
51749
  * (widget × event) pairs.
51258
51750
  */
51259
- function ListenersTab(_ref1) {
51751
+ function ListenersTab(_ref11) {
51260
51752
  var _receivers$;
51261
- var emitters = _ref1.emitters,
51262
- receivers = _ref1.receivers,
51263
- wiring = _ref1.wiring,
51264
- onAdd = _ref1.onAdd,
51265
- onRemove = _ref1.onRemove;
51753
+ var emitters = _ref11.emitters,
51754
+ receivers = _ref11.receivers,
51755
+ wiring = _ref11.wiring,
51756
+ onAdd = _ref11.onAdd,
51757
+ onRemove = _ref11.onRemove;
51266
51758
  var _useConfigTokens6 = useConfigTokens(),
51267
51759
  muted = _useConfigTokens6.muted,
51268
51760
  hairline = _useConfigTokens6.hairline;
51269
- var _useState17 = useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
51270
- _useState18 = _slicedToArray(_useState17, 2),
51271
- selectedReceiverKey = _useState18[0],
51272
- setSelectedReceiverKey = _useState18[1];
51273
- var _useState19 = useState(null),
51761
+ var _useState19 = useState(((_receivers$ = receivers[0]) === null || _receivers$ === void 0 ? void 0 : _receivers$.key) || null),
51274
51762
  _useState20 = _slicedToArray(_useState19, 2),
51275
- selectedHandler = _useState20[0],
51276
- setSelectedHandler = _useState20[1];
51763
+ selectedReceiverKey = _useState20[0],
51764
+ setSelectedReceiverKey = _useState20[1];
51765
+ var _useState21 = useState(null),
51766
+ _useState22 = _slicedToArray(_useState21, 2),
51767
+ selectedHandler = _useState22[0],
51768
+ setSelectedHandler = _useState22[1];
51277
51769
 
51278
51770
  // Re-anchor selection if the previously-selected widget disappeared
51279
51771
  // (workspace switched, widget deleted, etc.).
@@ -51289,7 +51781,7 @@ function ListenersTab(_ref1) {
51289
51781
  // Receiver lookup (by composite key) for label resolution in chips.
51290
51782
  var receiverByKey = useMemo(function () {
51291
51783
  var m = new Map();
51292
- var _iterator8 = _createForOfIteratorHelper$o(receivers),
51784
+ var _iterator8 = _createForOfIteratorHelper$n(receivers),
51293
51785
  _step8;
51294
51786
  try {
51295
51787
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
@@ -51372,14 +51864,14 @@ function ListenersTab(_ref1) {
51372
51864
  * third column. Matches the left-column look from
51373
51865
  * PanelEditItemHandlers.
51374
51866
  */
51375
- function HandlersColumn(_ref11) {
51376
- var receiver = _ref11.receiver,
51377
- myWiring = _ref11.myWiring,
51378
- selectedHandler = _ref11.selectedHandler,
51379
- onSelectHandler = _ref11.onSelectHandler;
51867
+ function HandlersColumn(_ref13) {
51868
+ var receiver = _ref13.receiver,
51869
+ myWiring = _ref13.myWiring,
51870
+ selectedHandler = _ref13.selectedHandler,
51871
+ onSelectHandler = _ref13.onSelectHandler;
51380
51872
  var countsByHandler = useMemo(function () {
51381
51873
  var m = new Map();
51382
- var _iterator9 = _createForOfIteratorHelper$o(myWiring),
51874
+ var _iterator9 = _createForOfIteratorHelper$n(myWiring),
51383
51875
  _step9;
51384
51876
  try {
51385
51877
  for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
@@ -51441,13 +51933,13 @@ function HandlersColumn(_ref11) {
51441
51933
  * Checked = wired; toggling commits an add/remove. Mirrors the
51442
51934
  * right-column UX of PanelEditItemHandlers.
51443
51935
  */
51444
- function EventsColumn(_ref12) {
51445
- var receiver = _ref12.receiver,
51446
- handlerName = _ref12.handlerName,
51447
- myWiring = _ref12.myWiring,
51448
- emitters = _ref12.emitters,
51449
- onAdd = _ref12.onAdd,
51450
- onRemove = _ref12.onRemove;
51936
+ function EventsColumn(_ref14) {
51937
+ var receiver = _ref14.receiver,
51938
+ handlerName = _ref14.handlerName,
51939
+ myWiring = _ref14.myWiring,
51940
+ emitters = _ref14.emitters,
51941
+ onAdd = _ref14.onAdd,
51942
+ onRemove = _ref14.onRemove;
51451
51943
  var _useConfigTokens8 = useConfigTokens(),
51452
51944
  muted = _useConfigTokens8.muted,
51453
51945
  hairline = _useConfigTokens8.hairline;
@@ -51456,7 +51948,7 @@ function EventsColumn(_ref12) {
51456
51948
  var wiredHere = useMemo(function () {
51457
51949
  var seen = new Set();
51458
51950
  var out = [];
51459
- var _iterator0 = _createForOfIteratorHelper$o(myWiring),
51951
+ var _iterator0 = _createForOfIteratorHelper$n(myWiring),
51460
51952
  _step0;
51461
51953
  try {
51462
51954
  for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
@@ -51533,7 +52025,7 @@ function EventsColumn(_ref12) {
51533
52025
  className: "flex-1 overflow-y-auto p-4 flex flex-col gap-3",
51534
52026
  children: emittersForList.length === 0 ? /*#__PURE__*/jsx("div", {
51535
52027
  className: "text-sm ".concat(muted),
51536
- children: "No other widgets in this dashboard emit events."
52028
+ children: "Nothing else on this dashboard emits events \u2014 no widgets or bots."
51537
52029
  }) : emittersForList.map(function (e) {
51538
52030
  return /*#__PURE__*/jsxs("div", {
51539
52031
  className: "rounded-lg border px-3 py-2 flex flex-col gap-1 ".concat(hairline),
@@ -52511,296 +53003,8 @@ function parseCron(cron) {
52511
53003
  };
52512
53004
  }
52513
53005
 
52514
- function _createForOfIteratorHelper$n(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$n(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
52515
- function _unsupportedIterableToArray$n(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$n(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$n(r, a) : void 0; } }
52516
- function _arrayLikeToArray$n(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
52517
-
52518
- /**
52519
- * @param {Array<object>} workspaces dashboards (each with id, name, layout/pages)
52520
- * @param {(component: string) => object|null} getWidgetConfig
52521
- * @returns {Array<{ workspaceId: string, name: string,
52522
- * widgets: Array<{ ref: string, instanceId: string, label: string, events: string[] }> }>}
52523
- * dashboards with at least one event-emitting widget
52524
- */
52525
- function buildWidgetEventCatalog(workspaces, getWidgetConfig) {
52526
- if (!Array.isArray(workspaces)) return [];
52527
- var out = [];
52528
- var _iterator = _createForOfIteratorHelper$n(workspaces),
52529
- _step;
52530
- try {
52531
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
52532
- var ws = _step.value;
52533
- if (!ws || ws.id === undefined || ws.id === null) continue;
52534
- var widgets = getEmitters(ws, getWidgetConfig).filter(function (e) {
52535
- return e.itemId != null && e.events.length;
52536
- }).map(function (e) {
52537
- return {
52538
- ref: e.component,
52539
- instanceId: String(e.itemId),
52540
- label: e.label || e.component,
52541
- events: e.events
52542
- };
52543
- });
52544
- if (!widgets.length) continue;
52545
- out.push({
52546
- workspaceId: String(ws.id),
52547
- name: ws.name || "Dashboard ".concat(ws.id),
52548
- widgets: widgets
52549
- });
52550
- }
52551
- // Dashboards can share a name (e.g. copies of "Kitchen Sink"); number the
52552
- // duplicates so each picker entry is distinguishable.
52553
- } catch (err) {
52554
- _iterator.e(err);
52555
- } finally {
52556
- _iterator.f();
52557
- }
52558
- var totals = {};
52559
- for (var _i = 0, _out = out; _i < _out.length; _i++) {
52560
- var w = _out[_i];
52561
- totals[w.name] = (totals[w.name] || 0) + 1;
52562
- }
52563
- var seen = {};
52564
- for (var _i2 = 0, _out2 = out; _i2 < _out2.length; _i2++) {
52565
- var _w = _out2[_i2];
52566
- if (totals[_w.name] > 1) {
52567
- seen[_w.name] = (seen[_w.name] || 0) + 1;
52568
- _w.name = "".concat(_w.name, " (").concat(seen[_w.name], ")");
52569
- }
52570
- }
52571
- return out;
52572
- }
52573
-
52574
- /** A subscription to one widget event, picked from the catalog. */
52575
- function widgetSubscription(workspace, widget, event) {
52576
- return {
52577
- eventType: formatEventString(widget.ref, widget.instanceId, event),
52578
- source: {
52579
- kind: "widget",
52580
- ref: widget.ref,
52581
- instanceId: widget.instanceId,
52582
- event: event,
52583
- workspaceId: workspace.workspaceId
52584
- },
52585
- label: "".concat(workspace.name, " \u203A ").concat(widget.label, " \u203A ").concat(event)
52586
- };
52587
- }
52588
-
52589
- /**
52590
- * How to show a saved subscription: its label from the live catalog, and
52591
- * whether its widget/event is gone (`missing`). Subscriptions saved before
52592
- * the picker (bare eventType) get a friendly label when they still resolve;
52593
- * otherwise they show as typed.
52594
- */
52595
- function describeSubscription(sub, catalog) {
52596
- var botCatalog = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
52597
- var eventType = sub && sub.eventType;
52598
- // Bot subscriptions resolve against the bot catalog; `kind` lets the form
52599
- // say "bot missing" instead of "widget missing".
52600
- if (sub && sub.source && sub.source.kind === "bot") {
52601
- var _iterator2 = _createForOfIteratorHelper$n(botCatalog || []),
52602
- _step2;
52603
- try {
52604
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
52605
- var b = _step2.value;
52606
- var _iterator3 = _createForOfIteratorHelper$n(b.events),
52607
- _step3;
52608
- try {
52609
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
52610
- var ev = _step3.value;
52611
- var s = botSubscription(b, ev);
52612
- if (s.eventType === eventType) {
52613
- return {
52614
- label: s.label,
52615
- missing: false,
52616
- kind: "bot"
52617
- };
52618
- }
52619
- }
52620
- } catch (err) {
52621
- _iterator3.e(err);
52622
- } finally {
52623
- _iterator3.f();
52624
- }
52625
- }
52626
- } catch (err) {
52627
- _iterator2.e(err);
52628
- } finally {
52629
- _iterator2.f();
52630
- }
52631
- return {
52632
- label: sub.label || eventType,
52633
- missing: true,
52634
- kind: "bot"
52635
- };
52636
- }
52637
- var _iterator4 = _createForOfIteratorHelper$n(catalog || []),
52638
- _step4;
52639
- try {
52640
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
52641
- var ws = _step4.value;
52642
- var _iterator5 = _createForOfIteratorHelper$n(ws.widgets),
52643
- _step5;
52644
- try {
52645
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
52646
- var w = _step5.value;
52647
- var _iterator6 = _createForOfIteratorHelper$n(w.events),
52648
- _step6;
52649
- try {
52650
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
52651
- var _ev = _step6.value;
52652
- if (formatEventString(w.ref, w.instanceId, _ev) === eventType) {
52653
- return {
52654
- label: widgetSubscription(ws, w, _ev).label,
52655
- missing: false
52656
- };
52657
- }
52658
- }
52659
- } catch (err) {
52660
- _iterator6.e(err);
52661
- } finally {
52662
- _iterator6.f();
52663
- }
52664
- }
52665
- } catch (err) {
52666
- _iterator5.e(err);
52667
- } finally {
52668
- _iterator5.f();
52669
- }
52670
- }
52671
- } catch (err) {
52672
- _iterator4.e(err);
52673
- } finally {
52674
- _iterator4.f();
52675
- }
52676
- if (sub && sub.source) {
52677
- return {
52678
- label: sub.label || eventType,
52679
- missing: true
52680
- };
52681
- }
52682
- return {
52683
- label: eventType || "",
52684
- missing: false
52685
- };
52686
- }
52687
-
52688
- /**
52689
- * Events other bots publish (bot:<ref>[<botId>].<event>, PRD US-010), for the
52690
- * "Another bot" side of the picker. Derived from each bot's settings — never
52691
- * hand-declared: Completed, Failed, and one `tool.<providerType>.<tool>` per
52692
- * tool the bot may use (the provider's tools, narrowed by the bot's
52693
- * selection). Providers with no known type or tool list are skipped.
52694
- *
52695
- * @param {Array<object>} bots
52696
- * @param {Array<{name, type, tools}>} toolSources bots.listToolSources()
52697
- * @param {string} [excludeBotId] the bot being edited — can't trigger itself
52698
- */
52699
- function buildBotEventCatalog(bots, toolSources) {
52700
- var excludeBotId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
52701
- if (!Array.isArray(bots)) return [];
52702
- var sources = Array.isArray(toolSources) ? toolSources : [];
52703
- var out = [];
52704
- var _iterator7 = _createForOfIteratorHelper$n(bots),
52705
- _step7;
52706
- try {
52707
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
52708
- var bot = _step7.value;
52709
- if (!bot || !bot.id || !bot.ref || bot.id === excludeBotId) continue;
52710
- var events = [{
52711
- event: "completed",
52712
- label: "Completed"
52713
- }, {
52714
- event: "failed",
52715
- label: "Failed"
52716
- }];
52717
- var _iterator8 = _createForOfIteratorHelper$n(bot.mcpServers || []),
52718
- _step8;
52719
- try {
52720
- var _loop = function _loop() {
52721
- var provider = _step8.value;
52722
- var src = sources.find(function (s) {
52723
- return s && s.name === provider;
52724
- });
52725
- if (!src || !src.type || !Array.isArray(src.tools)) return 1; // continue
52726
- var sel = bot.toolSelections && bot.toolSelections[provider];
52727
- var tools = Array.isArray(sel) ? src.tools.filter(function (t) {
52728
- return sel.includes(t);
52729
- }) : src.tools;
52730
- var _iterator9 = _createForOfIteratorHelper$n(tools),
52731
- _step9;
52732
- try {
52733
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
52734
- var tool = _step9.value;
52735
- events.push({
52736
- event: "tool.".concat(src.type, ".").concat(tool),
52737
- label: "".concat(provider, " \u203A ").concat(tool)
52738
- });
52739
- }
52740
- } catch (err) {
52741
- _iterator9.e(err);
52742
- } finally {
52743
- _iterator9.f();
52744
- }
52745
- };
52746
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
52747
- if (_loop()) continue;
52748
- }
52749
- } catch (err) {
52750
- _iterator8.e(err);
52751
- } finally {
52752
- _iterator8.f();
52753
- }
52754
- out.push({
52755
- botId: bot.id,
52756
- ref: bot.ref,
52757
- name: bot.name || bot.id,
52758
- events: events
52759
- });
52760
- }
52761
- } catch (err) {
52762
- _iterator7.e(err);
52763
- } finally {
52764
- _iterator7.f();
52765
- }
52766
- return out;
52767
- }
52768
-
52769
- /** A subscription to one bot event, picked from the bot catalog. */
52770
- function botSubscription(botEntry, ev) {
52771
- return {
52772
- eventType: "bot:".concat(botEntry.ref, "[").concat(botEntry.botId, "].").concat(ev.event),
52773
- source: {
52774
- kind: "bot",
52775
- ref: botEntry.ref,
52776
- instanceId: botEntry.botId,
52777
- event: ev.event
52778
- },
52779
- label: "".concat(botEntry.name, " \u203A ").concat(ev.label)
52780
- };
52781
- }
52782
-
52783
53006
  function ownKeys$y(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
52784
53007
  function _objectSpread$y(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$y(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$y(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
52785
- var EVENT_FROM_OPTIONS = [{
52786
- value: "widget",
52787
- label: "A dashboard widget"
52788
- }, {
52789
- value: "bot",
52790
- label: "Another bot"
52791
- }];
52792
-
52793
- /**
52794
- * BotDetail — create/edit form for a Bot Factory bot (Settings → Bots).
52795
- *
52796
- * Built for a non-technical user: Providers (the user's Dash MCP providers —
52797
- * what the bot can use), the AI model, and the schedule are all
52798
- * pick-from-a-list, never free text. "Provider" always means a Dash provider;
52799
- * the LLM choice is labelled "Model source". The raw cron lives behind an "Advanced"
52800
- * toggle for power users. All inputs are @trops/dash-react primitives.
52801
- */
52802
-
52803
- // Friendly, Title-case provider labels for the dropdown.
52804
53008
  var PROVIDER_LABELS = {
52805
53009
  anthropic: "Anthropic",
52806
53010
  openai: "OpenAI",
@@ -53110,19 +53314,15 @@ var BotDetail = function BotDetail(_ref) {
53110
53314
  var eventCatalog = useMemo(function () {
53111
53315
  return buildWidgetEventCatalog(workspaces, getWidgetConfig);
53112
53316
  }, [workspaces, getWidgetConfig]);
53113
- var _useState41 = useState("widget"),
53114
- _useState42 = _slicedToArray(_useState41, 2),
53115
- pickFrom = _useState42[0],
53116
- setPickFrom = _useState42[1];
53117
53317
  // Team = the dashboard this bot belongs to ("" = Unassigned). A bot on a
53118
53318
  // team only hears its own dashboard's events (bot-teams TEAM-001).
53119
- var _useState43 = useState(function () {
53319
+ var _useState41 = useState(function () {
53120
53320
  var id = bot ? bot.workspaceId : defaultWorkspaceId;
53121
53321
  return id === undefined || id === null || id === "" ? "" : String(id);
53122
53322
  }),
53123
- _useState44 = _slicedToArray(_useState43, 2),
53124
- team = _useState44[0],
53125
- setTeam = _useState44[1];
53323
+ _useState42 = _slicedToArray(_useState41, 2),
53324
+ team = _useState42[0],
53325
+ setTeam = _useState42[1];
53126
53326
  var teamOptions = useMemo(function () {
53127
53327
  return [{
53128
53328
  value: "",
@@ -53130,40 +53330,33 @@ var BotDetail = function BotDetail(_ref) {
53130
53330
  }].concat(_toConsumableArray(dashboardOptions(workspaces)));
53131
53331
  }, [workspaces]);
53132
53332
  var offTeam = offTeamSubscriptions(subscriptions, team);
53133
- // The event picker opens on the bot's own dashboard.
53134
- var _useState45 = useState(team),
53333
+ // "Runs when…" (TEAM-012): one picker of everything that can trigger the
53334
+ // bot; a just-added trigger reminds the user to Save.
53335
+ var _useState43 = useState(""),
53336
+ _useState44 = _slicedToArray(_useState43, 2),
53337
+ pickTrigger = _useState44[0],
53338
+ setPickTrigger = _useState44[1];
53339
+ var _useState45 = useState(false),
53135
53340
  _useState46 = _slicedToArray(_useState45, 2),
53136
- pickWorkspace = _useState46[0],
53137
- setPickWorkspace = _useState46[1];
53138
- var _useState47 = useState(""),
53139
- _useState48 = _slicedToArray(_useState47, 2),
53140
- pickWidget = _useState48[0],
53141
- setPickWidget = _useState48[1];
53142
- var _useState49 = useState(""),
53143
- _useState50 = _slicedToArray(_useState49, 2),
53144
- pickBot = _useState50[0],
53145
- setPickBot = _useState50[1];
53146
- var _useState51 = useState(""),
53147
- _useState52 = _slicedToArray(_useState51, 2),
53148
- pickEvent = _useState52[0],
53149
- setPickEvent = _useState52[1];
53341
+ triggerAdded = _useState46[0],
53342
+ setTriggerAdded = _useState46[1];
53150
53343
  var _ref3 = useContext(ThemeContext) || {},
53151
53344
  _ref3$currentTheme = _ref3.currentTheme,
53152
53345
  currentTheme = _ref3$currentTheme === void 0 ? {} : _ref3$currentTheme;
53153
53346
  var hairline = currentTheme["border-neutral-dark"] || "border-gray-700";
53154
- var _useState53 = useState(false),
53155
- _useState54 = _slicedToArray(_useState53, 2),
53156
- saving = _useState54[0],
53157
- setSaving = _useState54[1];
53158
- var _useState55 = useState(null),
53159
- _useState56 = _slicedToArray(_useState55, 2),
53160
- error = _useState56[0],
53161
- setError = _useState56[1];
53347
+ var _useState47 = useState(false),
53348
+ _useState48 = _slicedToArray(_useState47, 2),
53349
+ saving = _useState48[0],
53350
+ setSaving = _useState48[1];
53351
+ var _useState49 = useState(null),
53352
+ _useState50 = _slicedToArray(_useState49, 2),
53353
+ error = _useState50[0],
53354
+ setError = _useState50[1];
53162
53355
  // "Saved" shows after a successful save until the next edit.
53163
- var _useState57 = useState(false),
53164
- _useState58 = _slicedToArray(_useState57, 2),
53165
- justSaved = _useState58[0],
53166
- setJustSaved = _useState58[1];
53356
+ var _useState51 = useState(false),
53357
+ _useState52 = _slicedToArray(_useState51, 2),
53358
+ justSaved = _useState52[0],
53359
+ setJustSaved = _useState52[1];
53167
53360
 
53168
53361
  // Unsaved changes: the editable fields now vs. when the form opened (or
53169
53362
  // last saved).
@@ -53186,10 +53379,10 @@ var BotDetail = function BotDetail(_ref) {
53186
53379
  subscriptions: subscriptions,
53187
53380
  team: team
53188
53381
  });
53189
- var _useState59 = useState(snapshot),
53190
- _useState60 = _slicedToArray(_useState59, 2),
53191
- baseline = _useState60[0],
53192
- setBaseline = _useState60[1];
53382
+ var _useState53 = useState(snapshot),
53383
+ _useState54 = _slicedToArray(_useState53, 2),
53384
+ baseline = _useState54[0],
53385
+ setBaseline = _useState54[1];
53193
53386
  var dirty = snapshot !== baseline;
53194
53387
  useEffect(function () {
53195
53388
  if (dirty) setJustSaved(false);
@@ -53349,35 +53542,39 @@ var BotDetail = function BotDetail(_ref) {
53349
53542
  });
53350
53543
  };
53351
53544
 
53352
- // Cascading picker options. A widget's option value is "ref|instanceId".
53353
- var pickedWs = eventCatalog.find(function (w) {
53354
- return w.workspaceId === pickWorkspace;
53355
- });
53356
- var pickedWidget = pickedWs ? pickedWs.widgets.find(function (w) {
53357
- return "".concat(w.ref, "|").concat(w.instanceId) === pickWidget;
53358
- }) : null;
53359
-
53360
- // Other bots' events, derived from their providers + tools (this bot
53361
- // excluded — it can't trigger itself).
53545
+ // Other bots' events (this bot excluded — it can't trigger itself), for
53546
+ // labelling the triggers already on the bot.
53362
53547
  var botCatalog = useMemo(function () {
53363
53548
  return buildBotEventCatalog(bots, toolSources, (bot === null || bot === void 0 ? void 0 : bot.id) || null);
53364
53549
  }, [bots, toolSources, bot === null || bot === void 0 ? void 0 : bot.id]);
53365
- var pickedBot = botCatalog.find(function (b) {
53366
- return b.botId === pickBot;
53550
+
53551
+ // Everything that can trigger this bot, grouped (TEAM-012).
53552
+ var triggerOptions = useMemo(function () {
53553
+ return buildTriggerOptions({
53554
+ team: team || null,
53555
+ workspaces: workspaces,
53556
+ getWidgetConfig: getWidgetConfig,
53557
+ bots: bots,
53558
+ toolSources: toolSources,
53559
+ botId: (bot === null || bot === void 0 ? void 0 : bot.id) || null,
53560
+ existing: subscriptions.map(function (s) {
53561
+ return s.eventType;
53562
+ })
53563
+ });
53564
+ }, [team, workspaces, getWidgetConfig, bots, toolSources, bot === null || bot === void 0 ? void 0 : bot.id, subscriptions]);
53565
+ var pickedTrigger = triggerOptions.find(function (o) {
53566
+ return o.value === pickTrigger;
53367
53567
  }) || null;
53368
- var pickedBotEvent = pickedBot ? pickedBot.events.find(function (e) {
53369
- return e.event === pickEvent;
53370
- }) || null : null;
53371
- var canAddEvent = pickFrom === "bot" ? !!pickedBotEvent : !!(pickedWidget && pickEvent);
53372
53568
  var addSubscription = function addSubscription() {
53373
- if (!canAddEvent) return;
53374
- var sub = pickFrom === "bot" ? botSubscription(pickedBot, pickedBotEvent) : widgetSubscription(pickedWs, pickedWidget, pickEvent);
53569
+ if (!pickedTrigger) return;
53570
+ var sub = pickedTrigger.subscription;
53375
53571
  setSubscriptions(function (prev) {
53376
53572
  return prev.some(function (s) {
53377
53573
  return s.eventType === sub.eventType;
53378
53574
  }) ? prev : [].concat(_toConsumableArray(prev), [sub]);
53379
53575
  });
53380
- setPickEvent("");
53576
+ setPickTrigger("");
53577
+ setTriggerAdded(true);
53381
53578
  };
53382
53579
  var removeSubscription = function removeSubscription(eventType) {
53383
53580
  setSubscriptions(function (prev) {
@@ -53749,101 +53946,32 @@ var BotDetail = function BotDetail(_ref) {
53749
53946
  }) : /*#__PURE__*/jsx("span", {
53750
53947
  className: "text-xs opacity-50",
53751
53948
  children: "This bot doesn't run on any events yet."
53752
- }), /*#__PURE__*/jsx(SelectInput, {
53753
- label: "From",
53754
- value: pickFrom,
53755
- onChange: function onChange(v) {
53756
- setPickFrom(v);
53757
- setPickEvent("");
53758
- },
53759
- options: EVENT_FROM_OPTIONS
53760
- }), pickFrom === "bot" ? botCatalog.length ? /*#__PURE__*/jsxs("div", {
53949
+ }), triggerOptions.length ? /*#__PURE__*/jsxs("div", {
53761
53950
  className: "flex flex-col gap-2",
53762
53951
  children: [/*#__PURE__*/jsx(SelectInput, {
53763
- label: "Bot",
53764
- value: pickBot,
53765
- onChange: function onChange(v) {
53766
- setPickBot(v);
53767
- setPickEvent("");
53768
- },
53769
- placeholder: "Choose a bot\u2026",
53770
- options: botCatalog.map(function (b) {
53771
- return {
53772
- value: b.botId,
53773
- label: b.name
53774
- };
53775
- })
53776
- }), /*#__PURE__*/jsx(SelectInput, {
53777
- label: "Event",
53778
- value: pickEvent,
53779
- onChange: setPickEvent,
53780
- placeholder: "Choose an event\u2026",
53781
- options: (pickedBot ? pickedBot.events : []).map(function (e) {
53952
+ label: "Runs when\u2026",
53953
+ value: pickTrigger,
53954
+ onChange: setPickTrigger,
53955
+ placeholder: "Choose what triggers this bot\u2026",
53956
+ options: triggerOptions.map(function (o) {
53782
53957
  return {
53783
- value: e.event,
53784
- label: e.label
53958
+ value: o.value,
53959
+ label: o.label,
53960
+ group: o.group
53785
53961
  };
53786
53962
  })
53787
53963
  }), /*#__PURE__*/jsx(Button, {
53788
- title: "Add event",
53964
+ title: "Add trigger",
53789
53965
  onClick: addSubscription,
53790
53966
  size: "sm",
53791
- disabled: !canAddEvent
53792
- })]
53793
- }) : /*#__PURE__*/jsx("span", {
53794
- className: "text-xs opacity-50",
53795
- children: "No other bots yet. Create another bot to trigger this one when it finishes or uses a tool."
53796
- }) : eventCatalog.length ? /*#__PURE__*/jsxs("div", {
53797
- className: "flex flex-col gap-2",
53798
- children: [/*#__PURE__*/jsx(SelectInput, {
53799
- label: "Dashboard",
53800
- value: pickWorkspace,
53801
- onChange: function onChange(v) {
53802
- setPickWorkspace(v);
53803
- setPickWidget("");
53804
- setPickEvent("");
53805
- },
53806
- placeholder: "Choose a dashboard\u2026",
53807
- options: eventCatalog.map(function (w) {
53808
- return {
53809
- value: w.workspaceId,
53810
- label: w.name
53811
- };
53812
- })
53813
- }), /*#__PURE__*/jsx(SelectInput, {
53814
- label: "Widget",
53815
- value: pickWidget,
53816
- onChange: function onChange(v) {
53817
- setPickWidget(v);
53818
- setPickEvent("");
53819
- },
53820
- placeholder: "Choose a widget\u2026",
53821
- options: (pickedWs ? pickedWs.widgets : []).map(function (w) {
53822
- return {
53823
- value: "".concat(w.ref, "|").concat(w.instanceId),
53824
- label: w.label
53825
- };
53826
- })
53827
- }), /*#__PURE__*/jsx(SelectInput, {
53828
- label: "Event",
53829
- value: pickEvent,
53830
- onChange: setPickEvent,
53831
- placeholder: "Choose an event\u2026",
53832
- options: (pickedWidget ? pickedWidget.events : []).map(function (ev) {
53833
- return {
53834
- value: ev,
53835
- label: ev
53836
- };
53837
- })
53838
- }), /*#__PURE__*/jsx(Button, {
53839
- title: "Add event",
53840
- onClick: addSubscription,
53841
- size: "sm",
53842
- disabled: !pickedWidget || !pickEvent
53843
- })]
53967
+ disabled: !pickedTrigger
53968
+ }), triggerAdded && dirty ? /*#__PURE__*/jsx("span", {
53969
+ className: "text-xs opacity-70",
53970
+ children: "Save to keep this trigger."
53971
+ }) : null]
53844
53972
  }) : /*#__PURE__*/jsx("span", {
53845
53973
  className: "text-xs opacity-50",
53846
- children: "No widgets on your dashboards publish events yet. Add a widget that publishes events to a dashboard to trigger this bot from it."
53974
+ children: team ? "Nothing can trigger this bot yet. Add a widget that publishes events to this dashboard, or another bot to its team." : "Nothing can trigger this bot yet. Add a widget that publishes events to a dashboard, or create another bot."
53847
53975
  }), /*#__PURE__*/jsx("span", {
53848
53976
  className: "text-xs opacity-50",
53849
53977
  children: "The bot runs automatically when one of these events fires."
@@ -70502,6 +70630,11 @@ function pruneListeners(listeners, liveCanonicalKeys) {
70502
70630
  continue;
70503
70631
  }
70504
70632
  var kept = value.filter(function (eventStr) {
70633
+ var _parseEventString;
70634
+ // Bots aren't layout widgets, so they never appear in
70635
+ // liveCanonicalKeys. Their wiring is checked against the bot list
70636
+ // in the Listeners tab instead.
70637
+ if (isBotSource((_parseEventString = parseEventString(eventStr)) === null || _parseEventString === void 0 ? void 0 : _parseEventString.component)) return true;
70505
70638
  var key = eventStringToCanonicalKey(eventStr);
70506
70639
  if (!key) return true; // unparseable — leave alone
70507
70640
  return liveCanonicalKeys.has(key);