@get-bb/plugin-sdk 0.6.164 → 0.6.178

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.
@@ -1534,6 +1534,15 @@ var projectExecutionDefaultsSchema = z2.object({
1534
1534
  // ../domain/src/plugin-id.ts
1535
1535
  import { z as z3 } from "zod";
1536
1536
  var pluginIdSchema = z3.string().regex(/^[a-z0-9][a-z0-9-]*$/u);
1537
+ var CORE_PLUGIN_DIRECTORIES = {
1538
+ npmPackages: "npm",
1539
+ cache: "cache",
1540
+ runtime: "runtime",
1541
+ stateSnapshots: "snapshots"
1542
+ };
1543
+ var coreOwnedPluginDirectoryNames = new Set(
1544
+ Object.values(CORE_PLUGIN_DIRECTORIES)
1545
+ );
1537
1546
 
1538
1547
  // ../domain/src/app-keybindings.ts
1539
1548
  import { z as z4 } from "zod";
@@ -1603,6 +1612,7 @@ var APP_COMMAND_IDS = [
1603
1612
  "window.new",
1604
1613
  "window.find",
1605
1614
  "window.reload",
1615
+ "window.forceReload",
1606
1616
  "app.back",
1607
1617
  "settings.open",
1608
1618
  "settings.openServers",
@@ -1728,6 +1738,7 @@ function layoutAppShortcutKey(input) {
1728
1738
  return input.shiftKey ? SHIFTED_KEY_BASES[input.key] ?? input.key : input.key;
1729
1739
  }
1730
1740
  function normalizeAppShortcutInputKey(input) {
1741
+ if (/^Digit[0-9]$/u.test(input.code)) return input.code.slice(5);
1731
1742
  const usePhysicalKey = input.altKey ? !isAsciiAlphanumeric(input.key) : isNonLatinCharacter(input.key);
1732
1743
  if (usePhysicalKey) {
1733
1744
  const fromCode = baseKeyFromCode(input.code);
@@ -1853,6 +1864,7 @@ var threadCreateOriginSchema = z6.enum(threadCreateOriginValues);
1853
1864
 
1854
1865
  // ../domain/src/environment.ts
1855
1866
  import { z as z7 } from "zod";
1867
+ var environmentHolderSchema = z7.literal("user");
1856
1868
  var environmentMachineSelectionSchema = z7.discriminatedUnion("type", [
1857
1869
  z7.object({ type: z7.literal("existing"), hostId: z7.string().min(1) }),
1858
1870
  z7.object({
@@ -1926,12 +1938,14 @@ var environmentSchema = z7.object({
1926
1938
  defaultBranch: z7.string().nullable(),
1927
1939
  mergeBaseBranch: z7.string().nullable(),
1928
1940
  status: environmentStatusSchema,
1941
+ statusMessage: z7.string().nullable(),
1929
1942
  environmentProviderId: z7.string().nullable(),
1930
1943
  lifecycle: environmentLifecycleSchema,
1931
1944
  hostLifecycle: environmentHostLifecycleSchema,
1932
1945
  environmentProviderSelection: environmentProviderSelectionSchema.nullable(),
1933
1946
  environmentProviderInstanceKey: z7.string().nullable(),
1934
1947
  managed: z7.boolean(),
1948
+ heldBy: environmentHolderSchema.nullable(),
1935
1949
  workspaceProvisionType: workspaceProvisionTypeSchema.nullable(),
1936
1950
  createdAt: z7.number(),
1937
1951
  updatedAt: z7.number()
@@ -4043,7 +4057,7 @@ function adaptSidebarFooterAction(registration) {
4043
4057
  label: registration.title,
4044
4058
  icon: registration.icon,
4045
4059
  kind: "action",
4046
- onActivate: ({ openPluginDetails }) => registration.run({ openSettings: openPluginDetails }),
4060
+ onActivate: ({ openPluginDetails, ...context }) => registration.run({ ...context, openSettings: openPluginDetails }),
4047
4061
  runtime: new SidebarFooterItemRuntime()
4048
4062
  };
4049
4063
  }
@@ -4167,6 +4181,14 @@ function checkStaleNavPanelKeys(kind, registration, onWarning) {
4167
4181
  }
4168
4182
  }
4169
4183
  }
4184
+ function readLegacyCardSectionTitle(kind, registration, onWarning) {
4185
+ const title = "title" in registration ? registration.title : void 0;
4186
+ if (typeof title !== "string" || title === "") return null;
4187
+ onWarning(
4188
+ `${kind}: "title" is retired; render experimental_InfoSection from the component instead.`
4189
+ );
4190
+ return title;
4191
+ }
4170
4192
  function createCommandShortcutSchema() {
4171
4193
  return z22.object({
4172
4194
  key: z22.string().min(1).max(32).refine(
@@ -4782,10 +4804,14 @@ function collectPluginAppRegistrations(definition, onWarning = (message) => cons
4782
4804
  requireUniqueId(kind, seenIds.threadContextCardSection, id);
4783
4805
  collected.threadContextCardSections.push({
4784
4806
  id,
4785
- title: requireNonEmptyString(kind, "title", registration.title),
4786
4807
  group: requireNonEmptyString(kind, "group", registration.group),
4787
4808
  ...requireOptionalOrder(kind, registration.order),
4788
- component: requireComponent(kind, registration.component)
4809
+ component: requireComponent(kind, registration.component),
4810
+ legacyTitle: readLegacyCardSectionTitle(
4811
+ kind,
4812
+ registration,
4813
+ onWarning
4814
+ )
4789
4815
  });
4790
4816
  },
4791
4817
  experimental_threadAction(registration) {
@@ -6043,6 +6069,7 @@ function TestInfoListRow({
6043
6069
  ] });
6044
6070
  }
6045
6071
  var activeClipboard = null;
6072
+ var loadingWithServers = false;
6046
6073
  function captureClipboardWrites(result) {
6047
6074
  const writes = [];
6048
6075
  activeClipboard = (content) => {
@@ -6157,6 +6184,15 @@ var testPluginSdkApp = {
6157
6184
  );
6158
6185
  return composer.apiList;
6159
6186
  },
6187
+ experimental_useActiveComposer() {
6188
+ const composer = useSlotEnv("experimental_useActiveComposer").composer;
6189
+ useSyncExternalStore2(
6190
+ composer.subscribe,
6191
+ composer.getVersionSnapshot,
6192
+ composer.getVersionSnapshot
6193
+ );
6194
+ return composer.api;
6195
+ },
6160
6196
  ThreadChat: TestThreadChat,
6161
6197
  Markdown: TestMarkdown,
6162
6198
  experimental_FileLink: TestFileLink,
@@ -6243,6 +6279,9 @@ var testPluginSdkApp = {
6243
6279
  experimental_useServers() {
6244
6280
  return useSlotEnv("experimental_useServers").servers;
6245
6281
  },
6282
+ experimental_hasServers() {
6283
+ return loadingWithServers;
6284
+ },
6246
6285
  experimental_copyToClipboard(content) {
6247
6286
  return activeClipboard?.(content) ?? Promise.resolve(true);
6248
6287
  },
@@ -6259,6 +6298,22 @@ var testPluginSdkApp = {
6259
6298
  options
6260
6299
  );
6261
6300
  },
6301
+ experimental_useThreadRequests() {
6302
+ const calls = useSlotEnv(
6303
+ "experimental_useThreadRequests"
6304
+ ).threadRequestCalls;
6305
+ return useMemo3(
6306
+ () => ({
6307
+ async requestArchive(threadIds) {
6308
+ calls.push({ method: "requestArchive", threadIds: [...threadIds] });
6309
+ },
6310
+ async requestDelete(threadIds) {
6311
+ calls.push({ method: "requestDelete", threadIds: [...threadIds] });
6312
+ }
6313
+ }),
6314
+ [calls]
6315
+ );
6316
+ },
6262
6317
  experimental_useArchiveEnvironmentThreads() {
6263
6318
  const calls = useSlotEnv(
6264
6319
  "experimental_useArchiveEnvironmentThreads"
@@ -6414,7 +6469,7 @@ function installTestPluginRuntime() {
6414
6469
  pluginSdkApp: testPluginSdkApp
6415
6470
  };
6416
6471
  }
6417
- async function loadPluginApp(source) {
6472
+ async function loadPluginApp(source, options = {}) {
6418
6473
  installTestPluginRuntime();
6419
6474
  const resolved = typeof source === "function" ? await source() : source;
6420
6475
  const definition = isPluginAppDefinition(resolved) ? resolved : resolved.default;
@@ -6423,7 +6478,12 @@ async function loadPluginApp(source) {
6423
6478
  "the bundle's default export is not definePluginApp(...) from @get-bb/plugin-sdk/app"
6424
6479
  );
6425
6480
  }
6426
- return collectPluginAppRegistrations(definition);
6481
+ loadingWithServers = options.hasServers ?? false;
6482
+ try {
6483
+ return collectPluginAppRegistrations(definition);
6484
+ } finally {
6485
+ loadingWithServers = false;
6486
+ }
6427
6487
  }
6428
6488
  async function mountPluginContentScripts(app, options) {
6429
6489
  const controller = new AbortController();
@@ -6815,6 +6875,7 @@ function renderSlot(registration, props, options = {}) {
6815
6875
  }
6816
6876
  };
6817
6877
  const environmentArchiveCalls = [];
6878
+ const threadRequestCalls = [];
6818
6879
  const sidebarDraftThreadIds = new Set(
6819
6880
  options.sidebarDraftThreadIds ?? []
6820
6881
  );
@@ -7197,7 +7258,11 @@ ${block}
7197
7258
  realtimeHandlers,
7198
7259
  realtimeConnection,
7199
7260
  settingsState: { values: options.settings, isLoading: false },
7200
- bbContext: { projectId, threadId },
7261
+ bbContext: {
7262
+ projectId,
7263
+ threadId,
7264
+ experimental_pluginPanel: options.context?.experimental_pluginPanel ?? null
7265
+ },
7201
7266
  pluginId: options.pluginId ?? "test-plugin",
7202
7267
  questionFormHost: {
7203
7268
  shortcuts: /* @__PURE__ */ new Map(),
@@ -7220,6 +7285,7 @@ ${block}
7220
7285
  sidebarNavigation,
7221
7286
  sidebarNavigationCalls,
7222
7287
  environmentArchiveCalls,
7288
+ threadRequestCalls,
7223
7289
  threadActions: options.threadActions ?? NO_THREAD_ACTIONS,
7224
7290
  threadBulkActions: options.threadBulkActions ?? NO_THREAD_BULK_ACTIONS,
7225
7291
  threadActionRegistrations: options.threadActionRegistrations ?? NO_THREAD_ACTION_REGISTRATIONS,
@@ -7339,6 +7405,7 @@ ${block}
7339
7405
  sidebarActionCalls,
7340
7406
  sidebarNavigationCalls,
7341
7407
  experimental_environmentArchiveCalls: environmentArchiveCalls,
7408
+ experimental_threadRequestCalls: threadRequestCalls,
7342
7409
  sdkCalls,
7343
7410
  experimental_clipboardWrites,
7344
7411
  composer: composerLog,
@@ -7360,6 +7427,7 @@ ${block}
7360
7427
  sidebarActionCalls,
7361
7428
  sidebarNavigationCalls,
7362
7429
  experimental_environmentArchiveCalls: environmentArchiveCalls,
7430
+ experimental_threadRequestCalls: threadRequestCalls,
7363
7431
  sdkCalls,
7364
7432
  experimental_clipboardWrites,
7365
7433
  composer: composerLog
@@ -1940,11 +1940,22 @@ function enforcePluginCliOutputLimit(result, jsonOutput) {
1940
1940
  };
1941
1941
  return jsonOutput ? {
1942
1942
  exitCode: 1,
1943
- stdout: JSON.stringify({ error }),
1943
+ stdout: JSON.stringify({ ok: false, error }),
1944
1944
  stderr: "",
1945
1945
  error
1946
1946
  } : { exitCode: 1, stdout: "", stderr: error.message, error };
1947
1947
  }
1948
+ function pluginCliFailureResult(failure, jsonOutput) {
1949
+ return enforcePluginCliOutputLimit(
1950
+ {
1951
+ exitCode: 1,
1952
+ stdout: jsonOutput ? `${JSON.stringify({ ok: false, error: failure }, null, 2)}
1953
+ ` : "",
1954
+ stderr: failure.message
1955
+ },
1956
+ jsonOutput
1957
+ );
1958
+ }
1948
1959
  function adoptHttpRouteResponse(value) {
1949
1960
  if (value instanceof Response) return value;
1950
1961
  if (!isResponseLike(value)) {
@@ -2148,19 +2159,22 @@ function validatePluginEnvironmentProviderDeclaration(declaration) {
2148
2159
  declaration.availability,
2149
2160
  "availability"
2150
2161
  );
2162
+ const existingPath = declaration.apiVersion === 2 ? void 0 : declaration.experimental_existingPath;
2163
+ const locate = declaration.locate;
2151
2164
  assertOptionalFunction(
2152
2165
  "environment provider",
2153
2166
  id,
2154
- declaration.experimental_existingPath,
2167
+ existingPath,
2155
2168
  "experimental_existingPath"
2156
2169
  );
2170
+ assertOptionalFunction("environment provider", id, locate, "a locate");
2157
2171
  assertOptionalFunction(
2158
2172
  "environment provider",
2159
2173
  id,
2160
2174
  declaration.restore,
2161
2175
  "a restore"
2162
2176
  );
2163
- return {
2177
+ const common = {
2164
2178
  id,
2165
2179
  displayName,
2166
2180
  description,
@@ -2169,11 +2183,33 @@ function validatePluginEnvironmentProviderDeclaration(declaration) {
2169
2183
  inputs: inputs === null ? null : inputs.schema,
2170
2184
  inputsJsonSchema: inputs === null ? null : inputs.jsonSchema,
2171
2185
  availability: declaration.availability ?? null,
2186
+ locate: locate ?? (existingPath === void 0 ? null : ({ inputs: inputs2 }) => {
2187
+ const path = existingPath(inputs2);
2188
+ return path === null ? null : { path, reuse: true };
2189
+ }),
2190
+ remove: declaration.remove
2191
+ };
2192
+ if (declaration.apiVersion === 2) {
2193
+ return {
2194
+ ...common,
2195
+ apiVersion: 2,
2196
+ validate: declaration.validate ?? null,
2197
+ create: declaration.create,
2198
+ restore: declaration.restore ?? null,
2199
+ policy: environmentProviderV2PolicySchema.parse(declaration.policy ?? {})
2200
+ };
2201
+ }
2202
+ if (declaration.apiVersion !== void 0 && declaration.apiVersion !== 1) {
2203
+ throw new Error(
2204
+ `environment provider "${id}" declares apiVersion ${JSON.stringify(declaration.apiVersion)}; this bb supports 1 and 2`
2205
+ );
2206
+ }
2207
+ return {
2208
+ ...common,
2209
+ apiVersion: 1,
2172
2210
  validate: declaration.validate ?? null,
2173
- experimental_existingPath: declaration.experimental_existingPath ?? null,
2174
2211
  create: declaration.create,
2175
2212
  restore: declaration.restore ?? null,
2176
- remove: declaration.remove,
2177
2213
  policy: environmentProviderPolicySchema.parse(declaration.policy ?? {})
2178
2214
  };
2179
2215
  }
@@ -2208,6 +2244,10 @@ var environmentProviderPolicySchema = z6.object({
2208
2244
  retireGraceMs: z6.number().int().nonnegative().nullable().default(3e5),
2209
2245
  pathKeys: z6.enum(["per-thread", "per-attempt"]).default("per-thread")
2210
2246
  }).strict();
2247
+ var environmentProviderV2PolicySchema = z6.object({
2248
+ retireGraceMs: z6.number().int().nonnegative().nullable().default(3e5),
2249
+ pathKeys: z6.enum(["per-environment", "per-attempt"]).default("per-environment")
2250
+ }).strict();
2211
2251
  var MACHINE_PROVIDER_DESCRIPTION_MAX_CHARS = 200;
2212
2252
  function validatePluginMachineProviderDeclaration(declaration) {
2213
2253
  const { id, displayName } = requireProviderIdAndDisplayName(
@@ -2650,20 +2690,19 @@ function normalizeInteractionRequest(request) {
2650
2690
  `ui.requestInput title must be 1-${PLUGIN_INTERACTION_MAX_TITLE_LENGTH} characters`
2651
2691
  );
2652
2692
  }
2653
- let payload;
2693
+ let json;
2654
2694
  try {
2655
- const json = JSON.stringify(request.payload);
2656
- if (json === void 0) throw new Error();
2657
- if (Buffer.byteLength(json, "utf8") > PLUGIN_INTERACTION_MAX_PAYLOAD_BYTES) {
2658
- throw new Error("ui.requestInput payload exceeds 64 KiB");
2659
- }
2660
- payload = JSON.parse(json);
2661
- } catch (error) {
2662
- if (error instanceof Error && error.message.includes("64 KiB")) {
2663
- throw error;
2664
- }
2695
+ json = JSON.stringify(request.payload);
2696
+ } catch {
2697
+ throw new Error("ui.requestInput payload must be JSON-serializable");
2698
+ }
2699
+ if (json === void 0) {
2665
2700
  throw new Error("ui.requestInput payload must be JSON-serializable");
2666
2701
  }
2702
+ if (Buffer.byteLength(json, "utf8") > PLUGIN_INTERACTION_MAX_PAYLOAD_BYTES) {
2703
+ throw new Error("ui.requestInput payload exceeds 64 KiB");
2704
+ }
2705
+ const payload = JSON.parse(json);
2667
2706
  const timeoutMs = request.timeoutMs ?? 10 * 60 * 1e3;
2668
2707
  if (!Number.isInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > PLUGIN_INTERACTION_MAX_TIMEOUT_MS) {
2669
2708
  throw new Error(
@@ -2975,7 +3014,7 @@ function normalizeRpcJsonResult(value, fail) {
2975
3014
  }
2976
3015
 
2977
3016
  // src/testing/fake-plugin-host.ts
2978
- import { mkdtempSync, rmSync } from "node:fs";
3017
+ import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
2979
3018
  import { tmpdir } from "node:os";
2980
3019
  import { join } from "node:path";
2981
3020
  import Database from "better-sqlite3";
@@ -3311,6 +3350,12 @@ function createFakePluginHostInternal(options, sharedState) {
3311
3350
  migrate(database, statements) {
3312
3351
  assertLive();
3313
3352
  runPluginStorageMigrations(database, statements);
3353
+ },
3354
+ experimental_directory() {
3355
+ assertLive();
3356
+ const directory = join(storageRoot, "files");
3357
+ mkdirSync(directory, { recursive: true, mode: 448 });
3358
+ return directory;
3314
3359
  }
3315
3360
  };
3316
3361
  const settingsDescriptors = {};
@@ -4347,11 +4392,10 @@ function createFakePluginHostInternal(options, sharedState) {
4347
4392
  argv.includes("--json")
4348
4393
  );
4349
4394
  } catch (error) {
4350
- return enforcePluginCliOutputLimit(
4395
+ return pluginCliFailureResult(
4351
4396
  {
4352
- exitCode: 1,
4353
- stdout: "",
4354
- stderr: `bb ${registration.name} failed: ${errorMessage(error)}`
4397
+ code: "command_failed",
4398
+ message: `bb ${registration.name} failed: ${errorMessage(error)}`
4355
4399
  },
4356
4400
  argv.includes("--json")
4357
4401
  );
@@ -4791,8 +4835,10 @@ function makeMessageDispatchHookContext(overrides = {}) {
4791
4835
  lifecycle: { phase: "active", retireAt: null, teardown: null },
4792
4836
  hostLifecycle: "active",
4793
4837
  managed: false,
4838
+ heldBy: null,
4794
4839
  workspaceProvisionType: null,
4795
4840
  status: "ready",
4841
+ statusMessage: null,
4796
4842
  createdAt: 0,
4797
4843
  updatedAt: 0
4798
4844
  };
@@ -4886,6 +4932,49 @@ function makePanelController(overrides = {}) {
4886
4932
  ...overrides
4887
4933
  };
4888
4934
  }
4935
+ function makeActionContext(overrides = {}) {
4936
+ const calls = [];
4937
+ const record = (member, args) => {
4938
+ calls.push({ member, args });
4939
+ };
4940
+ const navigate = new Proxy({}, {
4941
+ get: (_target, method) => (...args) => {
4942
+ record(`navigate.${String(method)}`, args);
4943
+ return false;
4944
+ }
4945
+ });
4946
+ const sdk = new Proxy({}, {
4947
+ get: (_target, area) => new Proxy(
4948
+ {},
4949
+ {
4950
+ get: (_area, method) => (...args) => {
4951
+ const member = `sdk.${String(area)}.${String(method)}`;
4952
+ record(member, args);
4953
+ return Promise.reject(
4954
+ new Error(
4955
+ `${member} is not stubbed; pass sdk in the overrides`
4956
+ )
4957
+ );
4958
+ }
4959
+ }
4960
+ )
4961
+ });
4962
+ return {
4963
+ sdk: overrides.sdk ?? sdk,
4964
+ navigate: overrides.navigate ?? navigate,
4965
+ panel: overrides.panel ?? makePanelController(),
4966
+ composer: overrides.composer ?? null,
4967
+ threadRequests: overrides.threadRequests ?? {
4968
+ async requestArchive(threadIds) {
4969
+ record("threadRequests.requestArchive", [threadIds]);
4970
+ },
4971
+ async requestDelete(threadIds) {
4972
+ record("threadRequests.requestDelete", [threadIds]);
4973
+ }
4974
+ },
4975
+ calls
4976
+ };
4977
+ }
4889
4978
 
4890
4979
  // src/testing/public-sdk-only.ts
4891
4980
  import { readdirSync, readFileSync } from "node:fs";
@@ -5577,6 +5666,7 @@ export {
5577
5666
  createFakeSdk,
5578
5667
  experimental_createDescendantPipe,
5579
5668
  experimental_createProcessLifeline,
5669
+ makeActionContext as experimental_makeActionContext,
5580
5670
  makePanelController as experimental_makePanelController,
5581
5671
  scanPublicSdkOnly as experimental_scanPublicSdkOnly,
5582
5672
  experimental_trackChildProcesses,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.164",
3
+ "version": "0.6.178",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/get-bb/bb#readme",
6
6
  "bugs": {