@get-bb/plugin-sdk 0.6.31 → 0.6.37

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.
@@ -2,7 +2,9 @@
2
2
  import * as React from "react";
3
3
  import {
4
4
  createContext,
5
+ useCallback,
5
6
  useContext,
7
+ useLayoutEffect,
6
8
  useEffect,
7
9
  useMemo,
8
10
  useRef,
@@ -104,6 +106,7 @@ var mentionSchema = z.discriminatedUnion("kind", [
104
106
  origin: z.enum(["builtin", "project", "user"]),
105
107
  argumentHint: z.string().nullable()
106
108
  }),
109
+ z.object({ ...range, kind: z.literal("attachment"), path: z.string() }),
107
110
  z.object({
108
111
  ...range,
109
112
  kind: z.literal("plugin"),
@@ -954,6 +957,14 @@ function normalizeExperimentalFileOpenOptions(value) {
954
957
  return { target, location };
955
958
  }
956
959
 
960
+ // src/thread-action-groups.ts
961
+ var experimental_THREAD_ACTION_GROUPS = {
962
+ open: "1_open",
963
+ organize: "2_organize",
964
+ settings: "3_settings",
965
+ lifecycle: "4_lifecycle"
966
+ };
967
+
957
968
  // src/internal/plugin-app-collector.ts
958
969
  import { z as z2 } from "zod";
959
970
  var sidebarFooterCommandSequence = 0;
@@ -1174,10 +1185,9 @@ function collectPluginAppRegistrations(definition, onComposerCustomizationReject
1174
1185
  pendingInteractions: [],
1175
1186
  sidebarFooterActions: [],
1176
1187
  experimentalSidebarFooterItems: [],
1177
- experimentalSidebarNavigations: [],
1178
- experimentalSidebarHeaders: [],
1179
1188
  threadLists: [],
1180
1189
  threadHeaderActions: [],
1190
+ threadActions: [],
1181
1191
  browserToolbarActions: [],
1182
1192
  fileOpeners: [],
1183
1193
  sourceCodeRenderers: [],
@@ -1204,10 +1214,9 @@ function collectPluginAppRegistrations(definition, onComposerCustomizationReject
1204
1214
  composerPopup: /* @__PURE__ */ new Set(),
1205
1215
  pendingInteraction: /* @__PURE__ */ new Set(),
1206
1216
  sidebarFooterItem: /* @__PURE__ */ new Set(),
1207
- sidebarNavigation: /* @__PURE__ */ new Set(),
1208
- sidebarHeader: /* @__PURE__ */ new Set(),
1209
1217
  threadList: /* @__PURE__ */ new Set(),
1210
1218
  threadHeaderAction: /* @__PURE__ */ new Set(),
1219
+ threadAction: /* @__PURE__ */ new Set(),
1211
1220
  browserToolbarAction: /* @__PURE__ */ new Set(),
1212
1221
  fileOpener: /* @__PURE__ */ new Set(),
1213
1222
  sourceCodeRenderer: /* @__PURE__ */ new Set(),
@@ -1425,24 +1434,6 @@ function collectPluginAppRegistrations(definition, onComposerCustomizationReject
1425
1434
  collected.sidebarFooterActions.push(legacyRegistration);
1426
1435
  sidebarFooterItems.push(adaptSidebarFooterAction(legacyRegistration));
1427
1436
  },
1428
- experimental_sidebarNavigation(registration) {
1429
- collected.experimentalSidebarNavigations.push(
1430
- collectTitledComponent(
1431
- "slots.experimental_sidebarNavigation",
1432
- seenIds.sidebarNavigation,
1433
- registration
1434
- )
1435
- );
1436
- },
1437
- experimental_sidebarHeader(registration) {
1438
- collected.experimentalSidebarHeaders.push(
1439
- collectTitledComponent(
1440
- "slots.experimental_sidebarHeader",
1441
- seenIds.sidebarHeader,
1442
- registration
1443
- )
1444
- );
1445
- },
1446
1437
  experimental_threadList(registration) {
1447
1438
  collected.threadLists.push(
1448
1439
  collectTitledComponent(
@@ -1462,6 +1453,29 @@ function collectPluginAppRegistrations(definition, onComposerCustomizationReject
1462
1453
  component: requireComponent(kind, registration.component)
1463
1454
  });
1464
1455
  },
1456
+ experimental_threadAction(registration) {
1457
+ const kind = "slots.experimental_threadAction";
1458
+ const id = requireSlotId(kind, registration?.id);
1459
+ requireUniqueId(kind, seenIds.threadAction, id);
1460
+ if (typeof registration.item !== "function") {
1461
+ throw new Error(`${kind}: "item" must be a function`);
1462
+ }
1463
+ if (registration.useData !== void 0 && typeof registration.useData !== "function") {
1464
+ throw new Error(`${kind}: "useData" must be a function`);
1465
+ }
1466
+ if (registration.order !== void 0 && !Number.isFinite(registration.order)) {
1467
+ throw new Error(`${kind}: "order" must be a finite number`);
1468
+ }
1469
+ collected.threadActions.push({
1470
+ id,
1471
+ title: requireNonEmptyString(kind, "title", registration.title),
1472
+ icon: requireNonEmptyString(kind, "icon", registration.icon),
1473
+ group: requireNonEmptyString(kind, "group", registration.group),
1474
+ ...registration.order !== void 0 ? { order: registration.order } : {},
1475
+ ...registration.useData !== void 0 ? { useData: registration.useData } : {},
1476
+ item: registration.item
1477
+ });
1478
+ },
1465
1479
  experimental_browserToolbarAction(registration) {
1466
1480
  const kind = "slots.experimental_browserToolbarAction";
1467
1481
  const id = requireSlotId(kind, registration?.id);
@@ -1676,6 +1690,7 @@ function testComposerMentionText(mention) {
1676
1690
  case "command":
1677
1691
  return `${mention.trigger}${mention.name}`;
1678
1692
  case "plugin":
1693
+ case "attachment":
1679
1694
  return `@${mention.label}`;
1680
1695
  case "path": {
1681
1696
  const path = mention.source === "thread-storage" ? `thread-storage:${mention.path}` : mention.path;
@@ -1716,16 +1731,22 @@ function TestThreadTitle({ threadId }) {
1716
1731
  if (thread === void 0) return null;
1717
1732
  return /* @__PURE__ */ jsx("span", { "data-thread-title": threadId, children: thread.displayTitle });
1718
1733
  }
1719
- function TestSidebarNavigationIcon({
1720
- icon,
1721
- className
1734
+ function TestThreadStatusGlyph({
1735
+ indicator,
1736
+ archived = false,
1737
+ rowStatus = null,
1738
+ hideIdleDraftLabel = false,
1739
+ size = "default"
1722
1740
  }) {
1741
+ if (!archived && indicator === "none" && rowStatus === null) return null;
1723
1742
  return /* @__PURE__ */ jsx(
1724
1743
  "span",
1725
1744
  {
1726
- "aria-hidden": "true",
1727
- className,
1728
- "data-sidebar-navigation-icon": icon.kind === "host" ? icon.name : `${icon.pluginId}/${icon.icon ?? ""}`
1745
+ "data-thread-status-glyph": archived ? "archived" : indicator,
1746
+ "data-row-status": rowStatus?.label,
1747
+ "data-row-status-tone": rowStatus?.tone,
1748
+ "data-hide-idle-draft-label": hideIdleDraftLabel ? "" : void 0,
1749
+ "data-size": size
1729
1750
  }
1730
1751
  );
1731
1752
  }
@@ -1737,6 +1758,161 @@ function SlotLifecycleGuard({
1737
1758
  return children;
1738
1759
  }
1739
1760
  var SlotEnvContext = createContext(null);
1761
+ var NO_THREAD_ACTIONS = () => [];
1762
+ var NO_THREAD_ACTION_REGISTRATIONS = [];
1763
+ function noRenameEditor() {
1764
+ }
1765
+ function useTestThreadActions(hook, thread, options) {
1766
+ const entries = useSlotEnv(hook).threadActions(thread, {
1767
+ requestRename: options?.requestRename ?? noRenameEditor
1768
+ });
1769
+ const keys = options?.keys;
1770
+ if (keys === void 0) return entries;
1771
+ return keys.flatMap((key) => {
1772
+ const entry = entries.find((candidate) => candidate.key === key);
1773
+ return entry === void 0 ? [] : [entry];
1774
+ });
1775
+ }
1776
+ function TestThreadActionsMenuItems({
1777
+ hook,
1778
+ thread,
1779
+ inline = [],
1780
+ requestRename,
1781
+ onClose
1782
+ }) {
1783
+ const rename = requestRename ?? noRenameEditor;
1784
+ const entries = useTestThreadActions(hook, thread, { requestRename: rename });
1785
+ const rows = [
1786
+ ...entries.map((entry) => ({
1787
+ key: entry.key,
1788
+ action: entry.action,
1789
+ run: () => entry.action.run()
1790
+ })),
1791
+ ...inline.map((item) => ({
1792
+ key: item.key,
1793
+ action: item.action,
1794
+ run: () => item.action.run({ requestRename: rename })
1795
+ }))
1796
+ ];
1797
+ return /* @__PURE__ */ jsx("div", { role: "menu", "aria-label": "Thread actions", children: rows.map((row) => /* @__PURE__ */ jsx(
1798
+ "button",
1799
+ {
1800
+ type: "button",
1801
+ role: "menuitem",
1802
+ "data-thread-action": row.key,
1803
+ disabled: row.action.disabled,
1804
+ onClick: () => {
1805
+ void row.run();
1806
+ onClose();
1807
+ },
1808
+ children: row.action.label
1809
+ },
1810
+ row.key
1811
+ )) });
1812
+ }
1813
+ function useTestMenuOpenState({
1814
+ onOpenChange,
1815
+ onCloseAutoFocus
1816
+ }) {
1817
+ const [open, setOpen] = useState(false);
1818
+ return {
1819
+ open,
1820
+ show: () => {
1821
+ setOpen(true);
1822
+ onOpenChange?.(true);
1823
+ },
1824
+ close: () => {
1825
+ setOpen(false);
1826
+ onOpenChange?.(false);
1827
+ onCloseAutoFocus?.(new Event("focus", { cancelable: true }));
1828
+ }
1829
+ };
1830
+ }
1831
+ var TEST_TRIGGER_HOST_CLASS = "bb-test-thread-actions-trigger";
1832
+ function TestThreadActionsMenu({
1833
+ thread,
1834
+ trigger,
1835
+ inline,
1836
+ requestRename,
1837
+ onOpenChange,
1838
+ onCloseAutoFocus
1839
+ }) {
1840
+ const menu = useTestMenuOpenState({ onOpenChange, onCloseAutoFocus });
1841
+ const triggerElement = useRef(null);
1842
+ useLayoutEffect(() => {
1843
+ const element = triggerElement.current;
1844
+ if (element?.getAttribute("aria-haspopup") !== "menu") {
1845
+ throw new Error(
1846
+ "experimental_ThreadActionsMenu: `trigger` must spread the props and ref it receives onto the button it renders, or the menu never opens"
1847
+ );
1848
+ }
1849
+ if (!element.classList.contains(TEST_TRIGGER_HOST_CLASS)) {
1850
+ throw new Error(
1851
+ "experimental_ThreadActionsMenu: `trigger` replaced the host's className; merge props.className into its own"
1852
+ );
1853
+ }
1854
+ });
1855
+ return /* @__PURE__ */ jsxs("span", { "data-testid": "bb-thread-actions-menu", "data-thread-id": thread.id, children: [
1856
+ trigger({
1857
+ ref: triggerElement,
1858
+ type: "button",
1859
+ className: TEST_TRIGGER_HOST_CLASS,
1860
+ "aria-haspopup": "menu",
1861
+ "aria-expanded": menu.open,
1862
+ onClick: menu.show
1863
+ }),
1864
+ menu.open ? /* @__PURE__ */ jsx(
1865
+ TestThreadActionsMenuItems,
1866
+ {
1867
+ hook: "experimental_ThreadActionsMenu",
1868
+ thread,
1869
+ inline,
1870
+ requestRename,
1871
+ onClose: menu.close
1872
+ }
1873
+ ) : null
1874
+ ] });
1875
+ }
1876
+ function TestThreadActionsContextMenu({
1877
+ thread,
1878
+ children,
1879
+ inline,
1880
+ requestRename,
1881
+ onOpenChange,
1882
+ onCloseAutoFocus,
1883
+ disabled,
1884
+ dragging
1885
+ }) {
1886
+ const menu = useTestMenuOpenState({ onOpenChange, onCloseAutoFocus });
1887
+ return /* @__PURE__ */ jsxs(
1888
+ "div",
1889
+ {
1890
+ "data-testid": "bb-thread-actions-context-menu",
1891
+ "data-thread-id": thread.id,
1892
+ "data-disabled": disabled === true ? "true" : "false",
1893
+ "data-dragging": dragging === true ? "true" : "false",
1894
+ className: "contents",
1895
+ onContextMenu: (event) => {
1896
+ if (disabled === true || dragging === true) return;
1897
+ event.preventDefault();
1898
+ menu.show();
1899
+ },
1900
+ children: [
1901
+ children,
1902
+ menu.open ? /* @__PURE__ */ jsx(
1903
+ TestThreadActionsMenuItems,
1904
+ {
1905
+ hook: "experimental_ThreadActionsContextMenu",
1906
+ thread,
1907
+ inline,
1908
+ requestRename,
1909
+ onClose: menu.close
1910
+ }
1911
+ ) : null
1912
+ ]
1913
+ }
1914
+ );
1915
+ }
1740
1916
  function useSlotEnv(hook) {
1741
1917
  const env = useContext(SlotEnvContext);
1742
1918
  if (!env) {
@@ -2312,6 +2488,30 @@ var testPluginSdkApp = {
2312
2488
  experimental_useSidebarThreadActions() {
2313
2489
  return useSlotEnv("experimental_useSidebarThreadActions").sidebarActions;
2314
2490
  },
2491
+ experimental_useThreadActions(thread, options) {
2492
+ return useTestThreadActions(
2493
+ "experimental_useThreadActions",
2494
+ thread,
2495
+ options
2496
+ );
2497
+ },
2498
+ experimental_useArchiveEnvironmentThreads() {
2499
+ const calls = useSlotEnv(
2500
+ "experimental_useArchiveEnvironmentThreads"
2501
+ ).environmentArchiveCalls;
2502
+ return useCallback(
2503
+ async (environmentId) => {
2504
+ calls.push(environmentId);
2505
+ },
2506
+ [calls]
2507
+ );
2508
+ },
2509
+ experimental_useThreadActionRegistrations() {
2510
+ return useSlotEnv("experimental_useThreadActionRegistrations").threadActionRegistrations;
2511
+ },
2512
+ experimental_ThreadActionsMenu: TestThreadActionsMenu,
2513
+ experimental_ThreadActionsContextMenu: TestThreadActionsContextMenu,
2514
+ experimental_THREAD_ACTION_GROUPS,
2315
2515
  experimental_useSidebarThreadSplit(threadId) {
2316
2516
  const env = useSlotEnv("experimental_useSidebarThreadSplit");
2317
2517
  return useMemo(
@@ -2352,28 +2552,7 @@ var testPluginSdkApp = {
2352
2552
  return env.sidebarShortcuts.get(threadId) ?? null;
2353
2553
  },
2354
2554
  ThreadTitle: TestThreadTitle,
2355
- experimental_useSidebarNavigation() {
2356
- return useSlotEnv("experimental_useSidebarNavigation").sidebarNavigation;
2357
- },
2358
- experimental_useSidebarNavigationSplit(itemId, _options) {
2359
- const env = useSlotEnv("experimental_useSidebarNavigationSplit");
2360
- return useMemo(
2361
- () => ({
2362
- splitProps: {
2363
- onPointerDown: () => {
2364
- env.sidebarNavigationCalls.push({
2365
- method: "beginSplitDrag",
2366
- itemId
2367
- });
2368
- }
2369
- },
2370
- isAvailable: true,
2371
- layout: null
2372
- }),
2373
- [env, itemId]
2374
- );
2375
- },
2376
- experimental_SidebarNavigationIcon: TestSidebarNavigationIcon,
2555
+ experimental_ThreadStatusGlyph: TestThreadStatusGlyph,
2377
2556
  useEnvironmentProviders() {
2378
2557
  return useSlotEnv("useEnvironmentProviders").environmentProviders;
2379
2558
  },
@@ -2666,43 +2845,7 @@ function renderSlot(registration, props, options = {}) {
2666
2845
  }
2667
2846
  };
2668
2847
  const sidebarActionCalls = [];
2669
- const sidebarNavigationCalls = [];
2670
- const sidebarNavigation = {
2671
- items: options.sidebarNavigation?.items ?? [],
2672
- activeItemId: options.sidebarNavigation?.activeItemId ?? null,
2673
- isShortcutModifierHeld: options.sidebarNavigation?.isShortcutModifierHeld ?? false,
2674
- actions: {
2675
- activate(itemId, activationOptions) {
2676
- sidebarNavigationCalls.push({
2677
- method: "activate",
2678
- itemId,
2679
- openInSplit: activationOptions.openInSplit
2680
- });
2681
- },
2682
- setVisible(itemId, isVisible) {
2683
- sidebarNavigationCalls.push({
2684
- method: "setVisible",
2685
- itemId,
2686
- isVisible
2687
- });
2688
- },
2689
- setOrder(itemIds) {
2690
- sidebarNavigationCalls.push({
2691
- method: "setOrder",
2692
- itemIds: [...itemIds]
2693
- });
2694
- },
2695
- openCustomize() {
2696
- sidebarNavigationCalls.push({ method: "openCustomize" });
2697
- },
2698
- openDetails(itemId) {
2699
- sidebarNavigationCalls.push({ method: "openDetails", itemId });
2700
- },
2701
- async disablePlugin(itemId) {
2702
- sidebarNavigationCalls.push({ method: "disablePlugin", itemId });
2703
- }
2704
- }
2705
- };
2848
+ const environmentArchiveCalls = [];
2706
2849
  const sidebarPullRequests = new Map(
2707
2850
  Object.entries(options.sidebarPullRequests ?? {})
2708
2851
  );
@@ -2778,8 +2921,12 @@ function renderSlot(registration, props, options = {}) {
2778
2921
  }
2779
2922
  };
2780
2923
  const navigate = {
2781
- toThread(threadId2) {
2782
- navigateCalls.push({ method: "toThread", threadId: threadId2 });
2924
+ toThread(threadId2, threadOptions) {
2925
+ navigateCalls.push({
2926
+ method: "toThread",
2927
+ threadId: threadId2,
2928
+ ...threadOptions !== void 0 ? { options: threadOptions } : {}
2929
+ });
2783
2930
  },
2784
2931
  toProject(projectId2) {
2785
2932
  navigateCalls.push({ method: "toProject", projectId: projectId2 });
@@ -3083,13 +3230,14 @@ ${block}
3083
3230
  sidebarThreads,
3084
3231
  sidebarActions,
3085
3232
  sidebarActionCalls,
3233
+ environmentArchiveCalls,
3234
+ threadActions: options.threadActions ?? NO_THREAD_ACTIONS,
3235
+ threadActionRegistrations: options.threadActionRegistrations ?? NO_THREAD_ACTION_REGISTRATIONS,
3086
3236
  sidebarPullRequests,
3087
3237
  sidebarDraftThreadIds,
3088
3238
  sidebarRowStatuses,
3089
3239
  sidebarShortcuts,
3090
3240
  sidebarSplitLayout: options.sidebarSplitLayout ?? null,
3091
- sidebarNavigation,
3092
- sidebarNavigationCalls,
3093
3241
  environmentProviders,
3094
3242
  sdk,
3095
3243
  sdkCalls,
@@ -3161,7 +3309,7 @@ ${block}
3161
3309
  navigateCalls,
3162
3310
  experimental_fixedTabOpenCalls,
3163
3311
  sidebarActionCalls,
3164
- sidebarNavigationCalls,
3312
+ experimental_environmentArchiveCalls: environmentArchiveCalls,
3165
3313
  sdkCalls,
3166
3314
  experimental_clipboardWrites,
3167
3315
  composer: composerLog,
@@ -3176,7 +3324,7 @@ ${block}
3176
3324
  navigateCalls,
3177
3325
  experimental_fixedTabOpenCalls,
3178
3326
  sidebarActionCalls,
3179
- sidebarNavigationCalls,
3327
+ experimental_environmentArchiveCalls: environmentArchiveCalls,
3180
3328
  sdkCalls,
3181
3329
  experimental_clipboardWrites,
3182
3330
  composer: composerLog
@@ -445,6 +445,7 @@ var settingDescriptorSchema = z5.discriminatedUnion("type", [
445
445
  type: z5.literal("select"),
446
446
  ...settingsBaseFields,
447
447
  options: z5.array(z5.string().min(1)).min(1),
448
+ experimental_optionLabels: z5.record(z5.string().min(1), z5.string().min(1)).optional(),
448
449
  experimental_schema: stringSettingSchemaSchema.optional(),
449
450
  default: z5.string().optional()
450
451
  }).strict(),
@@ -480,6 +481,16 @@ function registerSettingDescriptors(target, added) {
480
481
  `default for setting "${key}" must be one of its options`
481
482
  );
482
483
  }
484
+ if (descriptor.type === "select") {
485
+ const unknownLabel = Object.keys(
486
+ descriptor.experimental_optionLabels ?? {}
487
+ ).find((option) => !descriptor.options.includes(option));
488
+ if (unknownLabel !== void 0) {
489
+ throw new Error(
490
+ `label for setting "${key}" names "${unknownLabel}", which is not one of its options`
491
+ );
492
+ }
493
+ }
483
494
  if (descriptor.default !== void 0) {
484
495
  const errors = validateSettingsUpdate(
485
496
  { [key]: descriptor },
@@ -2823,6 +2834,7 @@ function normalizeCallArgs(pluginId, path, args) {
2823
2834
  case "threads.fork":
2824
2835
  return withThreadAttribution(pluginId, args);
2825
2836
  case "threads.getPluginMetadata":
2837
+ case "threads.experimental_listPluginMetadata":
2826
2838
  return withPluginMetadataTarget(pluginId, args, false);
2827
2839
  case "threads.updatePluginMetadata":
2828
2840
  return withPluginMetadataTarget(pluginId, args, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.31",
3
+ "version": "0.6.37",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"