@get-bb/plugin-sdk 0.6.65 → 0.6.73

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.
@@ -1,4 +1,56 @@
1
- // src/internal/plugin-app-collector.ts
1
+ // src/internal/sidebar-footer-runtime.ts
2
+ var sidebarFooterCommandSequence = 0;
3
+ var SidebarFooterItemRuntime = class {
4
+ listeners = /* @__PURE__ */ new Set();
5
+ snapshot = {
6
+ command: null
7
+ };
8
+ subscribe = (listener) => {
9
+ this.listeners.add(listener);
10
+ return () => this.listeners.delete(listener);
11
+ };
12
+ getSnapshot = () => this.snapshot;
13
+ acknowledgeCommand = (sequence) => {
14
+ if (this.snapshot.command?.sequence !== sequence) return;
15
+ this.snapshot = { ...this.snapshot, command: null };
16
+ this.emit();
17
+ };
18
+ createDisclosureController() {
19
+ return Object.freeze({
20
+ open: () => this.request("open"),
21
+ close: () => this.request("close"),
22
+ toggle: () => this.request("toggle")
23
+ });
24
+ }
25
+ request(kind) {
26
+ sidebarFooterCommandSequence += 1;
27
+ this.snapshot = {
28
+ ...this.snapshot,
29
+ command: { sequence: sidebarFooterCommandSequence, kind }
30
+ };
31
+ this.emit();
32
+ }
33
+ emit() {
34
+ for (const listener of this.listeners) listener();
35
+ }
36
+ };
37
+ function adaptSidebarFooterAction(registration) {
38
+ return {
39
+ source: "sidebarFooterAction",
40
+ id: registration.id,
41
+ label: registration.title,
42
+ icon: registration.icon,
43
+ kind: "action",
44
+ onActivate: ({ openPluginDetails }) => registration.run({ openSettings: openPluginDetails }),
45
+ runtime: new SidebarFooterItemRuntime()
46
+ };
47
+ }
48
+ var sidebarFooterItemsByRegistrationSet = /* @__PURE__ */ new WeakMap();
49
+ function getCollectedSidebarFooterItems(registrations) {
50
+ return sidebarFooterItemsByRegistrationSet.get(registrations) ?? null;
51
+ }
52
+
53
+ // src/internal/plugin-app-registration-collector.ts
2
54
  import { z } from "zod";
3
55
 
4
56
  // src/internal/composer-customization-validation.ts
@@ -247,9 +299,8 @@ function collectComposerCustomization(registration, seenIds, onRejected, seenPop
247
299
  }
248
300
  }
249
301
 
250
- // src/internal/plugin-app-collector.ts
302
+ // src/internal/plugin-app-registration-collector.ts
251
303
  var CODE_FENCE_LANGUAGE_PATTERN = /^[a-z0-9][a-z0-9+#._-]*$/;
252
- var sidebarFooterCommandSequence = 0;
253
304
  var SIDEBAR_FOOTER_ACTION_KEYS = /* @__PURE__ */ new Set([
254
305
  "id",
255
306
  "label",
@@ -264,51 +315,6 @@ var SIDEBAR_FOOTER_DISCLOSURE_KEYS = /* @__PURE__ */ new Set([
264
315
  "kind",
265
316
  "component"
266
317
  ]);
267
- var SidebarFooterItemRuntime = class {
268
- listeners = /* @__PURE__ */ new Set();
269
- snapshot = {
270
- command: null
271
- };
272
- subscribe = (listener) => {
273
- this.listeners.add(listener);
274
- return () => this.listeners.delete(listener);
275
- };
276
- getSnapshot = () => this.snapshot;
277
- acknowledgeCommand = (sequence) => {
278
- if (this.snapshot.command?.sequence !== sequence) return;
279
- this.snapshot = { ...this.snapshot, command: null };
280
- this.emit();
281
- };
282
- createDisclosureController() {
283
- return Object.freeze({
284
- open: () => this.request("open"),
285
- close: () => this.request("close"),
286
- toggle: () => this.request("toggle")
287
- });
288
- }
289
- request(kind) {
290
- sidebarFooterCommandSequence += 1;
291
- this.snapshot = {
292
- ...this.snapshot,
293
- command: { sequence: sidebarFooterCommandSequence, kind }
294
- };
295
- this.emit();
296
- }
297
- emit() {
298
- for (const listener of this.listeners) listener();
299
- }
300
- };
301
- function adaptSidebarFooterAction(registration) {
302
- return {
303
- source: "sidebarFooterAction",
304
- id: registration.id,
305
- label: registration.title,
306
- icon: registration.icon,
307
- kind: "action",
308
- onActivate: ({ openPluginDetails }) => registration.run({ openSettings: openPluginDetails }),
309
- runtime: new SidebarFooterItemRuntime()
310
- };
311
- }
312
318
  var SidebarFooterCollector = class {
313
319
  constructor(collected, allCollected, seenIds) {
314
320
  this.collected = collected;
@@ -370,20 +376,18 @@ var SidebarFooterCollector = class {
370
376
  }
371
377
  }
372
378
  };
373
- var NAV_PANEL_REGISTRATION_KEYS = new Set(
374
- Object.keys({
375
- id: true,
376
- title: true,
377
- icon: true,
378
- path: true,
379
- component: true,
380
- fixedTabs: true,
381
- experimental_useBadge: true,
382
- experimental_usePageTitle: true,
383
- experimental_sidebar: true,
384
- headerContent: true
385
- })
386
- );
379
+ var NAV_PANEL_REGISTRATION_KEYS = {
380
+ id: true,
381
+ title: true,
382
+ icon: true,
383
+ path: true,
384
+ component: true,
385
+ fixedTabs: true,
386
+ experimental_useBadge: true,
387
+ experimental_usePageTitle: true,
388
+ experimental_sidebar: true,
389
+ headerContent: true
390
+ };
387
391
  var RENAMED_NAV_PANEL_KEYS = /* @__PURE__ */ new Map([
388
392
  ["experimental_fixedTabs", 'was renamed to "fixedTabs" in SDK 0.4.16']
389
393
  ]);
@@ -395,7 +399,7 @@ var RETIRED_NAV_PANEL_KEYS = /* @__PURE__ */ new Map([
395
399
  ]);
396
400
  function checkStaleNavPanelKeys(kind, registration, onWarning) {
397
401
  for (const key of Object.keys(registration)) {
398
- if (NAV_PANEL_REGISTRATION_KEYS.has(key)) continue;
402
+ if (Object.hasOwn(NAV_PANEL_REGISTRATION_KEYS, key)) continue;
399
403
  const renamed = RENAMED_NAV_PANEL_KEYS.get(key);
400
404
  if (renamed !== void 0) {
401
405
  throw new Error(`${kind}: "${key}" ${renamed}`);
@@ -410,30 +414,35 @@ function checkStaleNavPanelKeys(kind, registration, onWarning) {
410
414
  }
411
415
  }
412
416
  }
413
- var commandShortcutSchema = z.object({
414
- key: z.string().min(1).max(32).refine(
415
- (key) => ![
416
- "Alt",
417
- "Control",
418
- "Meta",
419
- "OS",
420
- "Shift",
421
- "Dead",
422
- "Unidentified"
423
- ].includes(key)
424
- ),
425
- mod: z.boolean().default(false),
426
- meta: z.boolean().default(false),
427
- control: z.boolean().default(false),
428
- alt: z.boolean().default(false),
429
- shift: z.boolean().default(false)
430
- }).strict().refine(
431
- (shortcut) => shortcut.mod || shortcut.meta || shortcut.control || shortcut.alt || /^F(?:[1-9]|1[0-9]|2[0-4])$/u.test(shortcut.key),
432
- "Use Command, Control, or Alt with a key, or a function key"
433
- );
434
- var sidebarFooterItemsByRegistrationSet = /* @__PURE__ */ new WeakMap();
435
- function getCollectedSidebarFooterItems(registrations) {
436
- return sidebarFooterItemsByRegistrationSet.get(registrations) ?? null;
417
+ function createCommandShortcutSchema() {
418
+ return z.object({
419
+ key: z.string().min(1).max(32).refine(
420
+ (key) => ![
421
+ "Alt",
422
+ "Control",
423
+ "Meta",
424
+ "OS",
425
+ "Shift",
426
+ "Dead",
427
+ "Unidentified"
428
+ ].includes(key)
429
+ ),
430
+ mod: z.boolean().default(false),
431
+ meta: z.boolean().default(false),
432
+ control: z.boolean().default(false),
433
+ alt: z.boolean().default(false),
434
+ shift: z.boolean().default(false)
435
+ }).strict().refine(
436
+ (shortcut) => shortcut.mod || shortcut.meta || shortcut.control || shortcut.alt || /^F(?:[1-9]|1[0-9]|2[0-4])$/u.test(shortcut.key),
437
+ "Use Command, Control, or Alt with a key, or a function key"
438
+ );
439
+ }
440
+ function requireOptionalOrder(kind, order) {
441
+ if (order === void 0) return {};
442
+ if (!Number.isFinite(order)) {
443
+ throw new Error(`${kind}: "order" must be a finite number`);
444
+ }
445
+ return { order };
437
446
  }
438
447
  function collectTitledComponent(kind, seen, registration) {
439
448
  const id = requireSlotId(kind, registration?.id);
@@ -469,13 +478,19 @@ function collectPanelAction(kind, seen, registration) {
469
478
  };
470
479
  }
471
480
  function collectPluginAppRegistrations(definition, onWarning = (message) => console.warn(message)) {
481
+ const commandShortcutSchema = createCommandShortcutSchema();
472
482
  const sidebarFooterItems = [];
473
483
  const collected = {
474
484
  homepageSections: [],
475
485
  settingsSections: [],
476
486
  appOverlays: [],
477
487
  navPanels: [],
478
- threadPanelActions: [],
488
+ tabs: [],
489
+ get threadPanelActions() {
490
+ return this.tabs.filter(
491
+ (tab) => tab.context.kind === "thread" && tab.availability === "action"
492
+ );
493
+ },
479
494
  newThreadPanelActions: [],
480
495
  composerCustomizations: [],
481
496
  pendingInteractions: [],
@@ -484,11 +499,14 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
484
499
  threadLists: [],
485
500
  experimentalSidebarNavigations: [],
486
501
  threadHeaderActions: [],
502
+ threadInfoRows: [],
503
+ threadInfoSections: [],
487
504
  threadActions: [],
488
505
  browserToolbarActions: [],
489
506
  fileOpeners: [],
490
507
  sourceCodeRenderers: [],
491
508
  diffRenderers: [],
509
+ composers: [],
492
510
  messageDirectives: [],
493
511
  codeFenceRenderers: [],
494
512
  messageActions: [],
@@ -506,7 +524,7 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
506
524
  settingsSection: /* @__PURE__ */ new Set(),
507
525
  appOverlay: /* @__PURE__ */ new Set(),
508
526
  navPanel: /* @__PURE__ */ new Set(),
509
- threadPanelAction: /* @__PURE__ */ new Set(),
527
+ tab: /* @__PURE__ */ new Set(),
510
528
  newThreadPanelAction: /* @__PURE__ */ new Set(),
511
529
  composerCustomization: /* @__PURE__ */ new Set(),
512
530
  composerPopup: /* @__PURE__ */ new Set(),
@@ -516,11 +534,14 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
516
534
  sidebarNavigation: /* @__PURE__ */ new Set(),
517
535
  sidebarHeader: /* @__PURE__ */ new Set(),
518
536
  threadHeaderAction: /* @__PURE__ */ new Set(),
537
+ threadInfoRow: /* @__PURE__ */ new Set(),
538
+ threadInfoSection: /* @__PURE__ */ new Set(),
519
539
  threadAction: /* @__PURE__ */ new Set(),
520
540
  browserToolbarAction: /* @__PURE__ */ new Set(),
521
541
  fileOpener: /* @__PURE__ */ new Set(),
522
542
  sourceCodeRenderer: /* @__PURE__ */ new Set(),
523
543
  diffRenderer: /* @__PURE__ */ new Set(),
544
+ composer: /* @__PURE__ */ new Set(),
524
545
  messageDirective: /* @__PURE__ */ new Set(),
525
546
  codeFenceRenderer: /* @__PURE__ */ new Set(),
526
547
  codeFenceLanguage: /* @__PURE__ */ new Set(),
@@ -532,6 +553,54 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
532
553
  machineProviderInputs: /* @__PURE__ */ new Set(),
533
554
  contentScript: /* @__PURE__ */ new Set()
534
555
  };
556
+ function collectTab(value, legacy = false) {
557
+ const registration = value;
558
+ const kind = "slots.experimental_tab";
559
+ const id = requireSlotId(kind, registration?.id);
560
+ const context = registration.context;
561
+ if (context?.kind !== "thread" && context?.kind !== "nav-panel") {
562
+ throw new Error(`${kind}: context must be thread or nav-panel`);
563
+ }
564
+ if (context.kind === "nav-panel") requireSlotId(kind, context.panelId);
565
+ const availability = registration.availability;
566
+ if (availability !== "fixed" && availability !== "action") {
567
+ throw new Error(`${kind}: availability must be fixed or action`);
568
+ }
569
+ requireUniqueId(
570
+ kind,
571
+ seenIds.tab,
572
+ `${context.kind}/${context.kind === "nav-panel" ? context.panelId : ""}/${id}`
573
+ );
574
+ if (registration.useVisible !== void 0 && typeof registration.useVisible !== "function") {
575
+ throw new Error(`${kind}: useVisible must be a function`);
576
+ }
577
+ if (availability === "fixed" && (registration.run !== void 0 || registration.params !== void 0)) {
578
+ throw new Error(`${kind}: run and params require action availability`);
579
+ }
580
+ const target = registration.experimental_target;
581
+ if (target !== void 0 && (context.kind !== "nav-panel" || availability !== "fixed" || typeof target?.validate !== "function")) {
582
+ throw new Error(
583
+ `${kind}: experimental_target requires a nav-panel fixed tab and a validate function`
584
+ );
585
+ }
586
+ const validated = {
587
+ ...registration,
588
+ ...collectPanelAction(kind, /* @__PURE__ */ new Set(), {
589
+ ...registration,
590
+ icon: legacy && registration.icon === "" ? void 0 : registration.icon
591
+ }),
592
+ icon: legacy && registration.icon === "" ? "" : requireNonEmptyString(kind, "icon", registration.icon),
593
+ ...registration.tooltip === void 0 ? {} : {
594
+ tooltip: requireNonEmptyString(
595
+ kind,
596
+ "tooltip",
597
+ registration.tooltip
598
+ )
599
+ },
600
+ ...availability === "action" && registration.params !== void 0 ? { params: z.json().parse(registration.params) } : {}
601
+ };
602
+ collected.tabs.push(validated);
603
+ }
535
604
  function collectCommand(kind, registration) {
536
605
  const id = requireSlotId(kind, registration?.id);
537
606
  requireUniqueId(kind, seenIds.command, id);
@@ -566,6 +635,26 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
566
635
  }
567
636
  const legacySidebarHeaders = [];
568
637
  const legacySlotAliases = {
638
+ threadPanelAction(registration) {
639
+ try {
640
+ const action = collectPanelAction(
641
+ "slots.threadPanelAction",
642
+ /* @__PURE__ */ new Set(),
643
+ registration
644
+ );
645
+ collectTab(
646
+ {
647
+ ...action,
648
+ icon: action.icon ?? "",
649
+ context: { kind: "thread" },
650
+ availability: "action"
651
+ },
652
+ true
653
+ );
654
+ } catch (error) {
655
+ onWarning(`Legacy threadPanelAction ignored: ${String(error)}`);
656
+ }
657
+ },
569
658
  experimental_sidebarHeader(registration) {
570
659
  legacySidebarHeaders.push(
571
660
  collectTitledComponent(
@@ -653,63 +742,45 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
653
742
  `${kind}: "experimental_usePageTitle" must be a React hook function when set`
654
743
  );
655
744
  }
656
- const fixedTabs = (() => {
657
- if (registration.fixedTabs === void 0) return [];
658
- if (!Array.isArray(registration.fixedTabs)) {
659
- throw new Error(`${kind}: "fixedTabs" must be an array when set`);
660
- }
661
- const seenFixedTabIds = /* @__PURE__ */ new Set();
662
- return registration.fixedTabs.map((value, index) => {
663
- const fixedTabKind = `${kind}.fixedTabs[${index}]`;
664
- const fixedTab = value;
665
- const id2 = requireSlotId(fixedTabKind, fixedTab?.id);
666
- requireUniqueId(fixedTabKind, seenFixedTabIds, id2);
667
- const layout = fixedTab?.layout;
668
- if (layout !== void 0 && layout !== "padded" && layout !== "flush") {
669
- throw new Error(
670
- `${fixedTabKind}: "layout" must be "padded" or "flush" when set`
671
- );
672
- }
673
- const fixedTabPanelId = requireNonEmptyString(
674
- fixedTabKind,
675
- "panelId",
676
- fixedTab?.panelId
677
- );
678
- if (fixedTabPanelId !== panelId) {
679
- throw new Error(
680
- `${fixedTabKind}: "panelId" must match its containing navPanel id ${JSON.stringify(panelId)}`
681
- );
682
- }
683
- const experimentalTarget = fixedTab?.experimental_target;
684
- if (experimentalTarget !== void 0 && (typeof experimentalTarget !== "object" || experimentalTarget === null || typeof Reflect.get(experimentalTarget, "validate") !== "function")) {
685
- throw new Error(
686
- `${fixedTabKind}: "experimental_target.validate" must be a function when set`
687
- );
688
- }
689
- return {
745
+ const legacy = registration;
746
+ const fixedTabs = [];
747
+ if (legacy.fixedTabs !== void 0 && !Array.isArray(legacy.fixedTabs)) {
748
+ onWarning("Legacy navPanel.fixedTabs ignored: expected an array");
749
+ }
750
+ for (const value of Array.isArray(legacy.fixedTabs) ? legacy.fixedTabs : []) {
751
+ try {
752
+ const id2 = requireSlotId(kind, value?.id);
753
+ const tab = {
690
754
  id: id2,
691
- panelId: fixedTabPanelId,
692
- title: requireNonEmptyString(
693
- fixedTabKind,
694
- "title",
695
- fixedTab?.title
696
- ),
697
- icon: requireNonEmptyString(fixedTabKind, "icon", fixedTab?.icon),
698
- component: requireComponent(fixedTabKind, fixedTab?.component),
699
- ...layout === void 0 ? {} : { layout },
700
- ...experimentalTarget === void 0 ? {} : {
701
- experimental_target: experimentalTarget
702
- }
755
+ panelId,
756
+ title: requireNonEmptyString(kind, "title", value.title ?? id2),
757
+ icon: typeof value.icon === "string" ? value.icon : "",
758
+ component: requireComponent(kind, value.component),
759
+ ...value.layout === "flush" ? { layout: "flush" } : {},
760
+ ...typeof value.experimental_target?.validate === "function" ? { experimental_target: value.experimental_target } : {}
703
761
  };
704
- });
705
- })();
762
+ collectTab(
763
+ {
764
+ ...tab,
765
+ context: { kind: "nav-panel", panelId },
766
+ availability: "fixed"
767
+ },
768
+ true
769
+ );
770
+ fixedTabs.push(tab);
771
+ } catch (error) {
772
+ onWarning(
773
+ `Legacy navPanel.fixedTabs entry ignored: ${String(error)}`
774
+ );
775
+ }
776
+ }
706
777
  collected.navPanels.push({
707
778
  id,
708
779
  title: requireNonEmptyString(kind, "title", registration.title),
709
780
  icon: requireNonEmptyString(kind, "icon", registration.icon),
710
781
  path,
782
+ ...fixedTabs.length === 0 ? {} : { fixedTabs },
711
783
  component: requireComponent(kind, registration.component),
712
- ...fixedTabs.length > 0 ? { fixedTabs } : {},
713
784
  ...registration.experimental_useBadge !== void 0 ? {
714
785
  experimental_useBadge: registration.experimental_useBadge
715
786
  } : {},
@@ -720,14 +791,8 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
720
791
  ...registration.headerContent !== void 0 ? { headerContent: registration.headerContent } : {}
721
792
  });
722
793
  },
723
- threadPanelAction(registration) {
724
- collected.threadPanelActions.push(
725
- collectPanelAction(
726
- "slots.threadPanelAction",
727
- seenIds.threadPanelAction,
728
- registration
729
- )
730
- );
794
+ experimental_tab(registration) {
795
+ collectTab(registration);
731
796
  },
732
797
  experimental_newThreadPanelAction(registration) {
733
798
  collected.newThreadPanelActions.push(
@@ -805,6 +870,28 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
805
870
  component: requireComponent(kind, registration.component)
806
871
  });
807
872
  },
873
+ experimental_threadInfoRow(registration) {
874
+ const kind = "slots.experimental_threadInfoRow";
875
+ const id = requireSlotId(kind, registration?.id);
876
+ requireUniqueId(kind, seenIds.threadInfoRow, id);
877
+ collected.threadInfoRows.push({
878
+ id,
879
+ group: requireNonEmptyString(kind, "group", registration.group),
880
+ ...requireOptionalOrder(kind, registration.order),
881
+ component: requireComponent(kind, registration.component)
882
+ });
883
+ },
884
+ experimental_threadInfoSection(registration) {
885
+ const kind = "slots.experimental_threadInfoSection";
886
+ const id = requireSlotId(kind, registration?.id);
887
+ requireUniqueId(kind, seenIds.threadInfoSection, id);
888
+ collected.threadInfoSections.push({
889
+ id,
890
+ group: requireNonEmptyString(kind, "group", registration.group),
891
+ ...requireOptionalOrder(kind, registration.order),
892
+ component: requireComponent(kind, registration.component)
893
+ });
894
+ },
808
895
  experimental_threadAction(registration) {
809
896
  const kind = "slots.experimental_threadAction";
810
897
  const id = requireSlotId(kind, registration?.id);
@@ -815,15 +902,12 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
815
902
  if (registration.useData !== void 0 && typeof registration.useData !== "function") {
816
903
  throw new Error(`${kind}: "useData" must be a function`);
817
904
  }
818
- if (registration.order !== void 0 && !Number.isFinite(registration.order)) {
819
- throw new Error(`${kind}: "order" must be a finite number`);
820
- }
821
905
  collected.threadActions.push({
822
906
  id,
823
907
  title: requireNonEmptyString(kind, "title", registration.title),
824
908
  icon: requireNonEmptyString(kind, "icon", registration.icon),
825
909
  group: requireNonEmptyString(kind, "group", registration.group),
826
- ...registration.order !== void 0 ? { order: registration.order } : {},
910
+ ...requireOptionalOrder(kind, registration.order),
827
911
  ...registration.useData !== void 0 ? { useData: registration.useData } : {},
828
912
  item: registration.item
829
913
  });
@@ -881,6 +965,15 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
881
965
  )
882
966
  );
883
967
  },
968
+ experimental_composer(registration) {
969
+ collected.composers.push(
970
+ collectTitledComponent(
971
+ "slots.experimental_composer",
972
+ seenIds.composer,
973
+ registration
974
+ )
975
+ );
976
+ },
884
977
  messageDirective(registration) {
885
978
  const kind = "slots.messageDirective";
886
979
  const id = requireMessageDirectiveId(kind, registration?.id);