@get-bb/plugin-sdk 0.4.56 → 0.4.87

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.
@@ -5,8 +5,82 @@
5
5
  // Confused by the API, or need a symbol that isn't here? Clone the BB repo
6
6
  // and read the real source: https://github.com/get-bb/bb
7
7
 
8
+ import { StandardSchemaV1 as StandardSchemaV1$1, StandardSchemaV1InferOutput, PluginMachineValidateDecision, JsonValue as JsonValue$2, PluginEnvironmentProviderRequirements as PluginEnvironmentProviderRequirements$1, PluginEnvironmentValidateDecision, BbPluginApi, PluginSettingValue as PluginSettingValue$1, PluginSharedPortTunnelIdentity, PluginAgentToolPresentation, PluginAgentToolContext, PluginAgentToolResult, PluginCliCommandInfo, PluginCliContext, PluginCliResult, PluginHttpAuthMode, PluginHttpHandler, PluginMentionTrigger, PluginMentionSearchContext, PluginMentionItem, PluginCliExecutionResult, PluginThreadEventName, PluginThreadEventPayloads, PluginAgentConfigurationContext, ExperimentalPluginProviderEnvContext, ExperimentalPluginProviderEnvEntry, ExperimentalPluginProviderEnvHealthContext, ExperimentalPluginProviderEnvHealth, PluginSettingDescriptors, ExperimentalPluginWebSocketHandler, PluginAgentConfiguration, PluginHookName, PluginHookHandler, PluginAiServiceDeclaration, PluginInteractionRequest, MessageDispatchHookContext } from '@get-bb/plugin-sdk';
8
9
  import { z } from 'zod';
9
- import { StandardSchemaV1 as StandardSchemaV1$1, PluginEnvironmentProviderRequirements as PluginEnvironmentProviderRequirements$1, StandardSchemaV1InferOutput, PluginEnvironmentValidateDecision, JsonValue as JsonValue$2, BbPluginApi, PluginSettingValue as PluginSettingValue$1, PluginSharedPortTunnelIdentity, PluginAgentToolPresentation, PluginAgentToolContext, PluginAgentToolResult, PluginCliCommandInfo, PluginCliContext, PluginCliResult, PluginHttpAuthMode, PluginHttpHandler, PluginMentionTrigger, PluginMentionSearchContext, PluginMentionItem, PluginCliExecutionResult, PluginThreadEventName, PluginThreadEventPayloads, PluginAgentConfigurationContext, ExperimentalPluginProviderEnvContext, ExperimentalPluginProviderEnvEntry, ExperimentalPluginProviderEnvHealthContext, ExperimentalPluginProviderEnvHealth, PluginSettingDescriptors, ExperimentalPluginWebSocketHandler, PluginAgentConfiguration, PluginHookName, PluginHookHandler, PluginAiServiceDeclaration, PluginInteractionRequest, MessageDispatchHookContext } from '@get-bb/plugin-sdk';
10
+
11
+ type PluginMachineProviderResource = Exclude<JsonValue$2, null>;
12
+ type PluginMachineProviderInputsSchema = StandardSchemaV1$1 | undefined;
13
+ type InputsValue$1<S> = S extends StandardSchemaV1$1 ? StandardSchemaV1InferOutput<S> : null;
14
+ interface PluginMachineProviderProgress {
15
+ step(text: string): void;
16
+ log(text: string): void;
17
+ }
18
+ type PluginMachineProviderAvailability = {
19
+ status: "available";
20
+ } | {
21
+ status: "setup-required";
22
+ message: string;
23
+ } | {
24
+ status: "unavailable";
25
+ message: string;
26
+ };
27
+ type PluginMachineProviderValidateContext<S extends PluginMachineProviderInputsSchema = PluginMachineProviderInputsSchema> = {
28
+ inputs: InputsValue$1<S>;
29
+ };
30
+ interface PluginMachineProviderLifecycleContext {
31
+ checkpoint(resource: PluginMachineProviderResource): Promise<void>;
32
+ report: PluginMachineProviderProgress;
33
+ signal: AbortSignal;
34
+ }
35
+ type PluginMachineProviderCreateContext<S extends PluginMachineProviderInputsSchema = PluginMachineProviderInputsSchema> = PluginMachineProviderValidateContext<S> & PluginMachineProviderLifecycleContext & {
36
+ key: string;
37
+ attempt: number;
38
+ };
39
+ type PluginMachineProviderCreateResult = {
40
+ status: "created";
41
+ name: string;
42
+ resource: PluginMachineProviderResource;
43
+ } | {
44
+ status: "failed";
45
+ message: string;
46
+ };
47
+ type PluginMachineProviderResourceLifecycleContext = PluginMachineProviderLifecycleContext & {
48
+ hostId: string;
49
+ resource: PluginMachineProviderResource;
50
+ };
51
+ type PluginMachineProviderRemoveContext = Omit<PluginMachineProviderResourceLifecycleContext, "checkpoint">;
52
+ interface PluginMachineProviderResourceResult {
53
+ resource: PluginMachineProviderResource;
54
+ }
55
+ type PluginMachineProviderRemoveResult = {
56
+ status: "removed";
57
+ } | {
58
+ status: "failed";
59
+ message: string;
60
+ };
61
+ interface PluginMachineProviderDefinition<S extends PluginMachineProviderInputsSchema = PluginMachineProviderInputsSchema> {
62
+ id: string;
63
+ displayName: string;
64
+ /** One line telling a user what choosing this provider gets them, shown wherever a machine is added. */
65
+ description: string;
66
+ /** Provider glyph, declared icon, or plugin-relative icon path. */
67
+ icon: string;
68
+ ephemeral?: boolean;
69
+ /** Persisted and readable by every plugin. Store secret references, never secrets. */
70
+ inputs?: S;
71
+ availability?(): PluginMachineProviderAvailability | Promise<PluginMachineProviderAvailability>;
72
+ validate?(context: PluginMachineProviderValidateContext<S>): PluginMachineValidateDecision | Promise<PluginMachineValidateDecision>;
73
+ create(context: PluginMachineProviderCreateContext<S>): Promise<PluginMachineProviderCreateResult>;
74
+ /** Reconcile and remove an uncertain allocation by durable key without creating or bootstrapping. Return failed while allocation intent remains unresolved. */
75
+ reconcileCleanup(context: {
76
+ key: string;
77
+ report: PluginMachineProviderProgress;
78
+ signal: AbortSignal;
79
+ }): Promise<PluginMachineProviderRemoveResult>;
80
+ suspend?(context: PluginMachineProviderResourceLifecycleContext): Promise<PluginMachineProviderResourceResult>;
81
+ resume?(context: PluginMachineProviderResourceLifecycleContext): Promise<PluginMachineProviderResourceResult>;
82
+ remove(context: PluginMachineProviderRemoveContext): Promise<PluginMachineProviderRemoveResult>;
83
+ }
10
84
 
11
85
  /** Input-form entry: a path, or a path with options. */
12
86
  declare const providerNativeRootInputSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
@@ -74,10 +148,14 @@ declare const environmentSchema: z.ZodObject<{
74
148
  environmentProviderInstanceKey: z.ZodNullable<z.ZodString>;
75
149
  environmentProviderSelection: z.ZodNullable<z.ZodObject<{
76
150
  inputs: z.ZodNullable<z.ZodType<JsonValue$1, unknown, z.core.$ZodTypeInternals<JsonValue$1, unknown>>>;
77
- machine: z.ZodObject<{
151
+ machine: z.ZodDiscriminatedUnion<[z.ZodObject<{
78
152
  hostId: z.ZodString;
79
153
  type: z.ZodLiteral<"existing">;
80
- }, z.core.$strip>;
154
+ }, z.core.$strip>, z.ZodObject<{
155
+ inputs: z.ZodNullable<z.ZodType<JsonValue$1, unknown, z.core.$ZodTypeInternals<JsonValue$1, unknown>>>;
156
+ machineProviderId: z.ZodString;
157
+ type: z.ZodLiteral<"new">;
158
+ }, z.core.$strip>], "type">;
81
159
  }, z.core.$strip>>;
82
160
  hostId: z.ZodString;
83
161
  id: z.ZodString;
@@ -127,6 +205,29 @@ declare const hostSchema: z.ZodObject<{
127
205
  id: z.ZodString;
128
206
  lastRejectedProtocolVersion: z.ZodNullable<z.ZodNumber>;
129
207
  lastSeenAt: z.ZodNullable<z.ZodNumber>;
208
+ lifecycle: z.ZodObject<{
209
+ message: z.ZodNullable<z.ZodString>;
210
+ pendingLog: z.ZodString;
211
+ phase: z.ZodEnum<{
212
+ active: "active";
213
+ creating: "creating";
214
+ destroyed: "destroyed";
215
+ removing: "removing";
216
+ resuming: "resuming";
217
+ suspended: "suspended";
218
+ suspending: "suspending";
219
+ }>;
220
+ suspendedAt: z.ZodNullable<z.ZodNumber>;
221
+ teardown: z.ZodNullable<z.ZodObject<{
222
+ attempt: z.ZodNumber;
223
+ status: z.ZodEnum<{
224
+ failed: "failed";
225
+ removed: "removed";
226
+ running: "running";
227
+ }>;
228
+ }, z.core.$strip>>;
229
+ }, z.core.$strip>;
230
+ machineProviderId: z.ZodNullable<z.ZodString>;
130
231
  maxPermissionMode: z.ZodEnum<{
131
232
  "accept-edits": "accept-edits";
132
233
  auto: "auto";
@@ -138,6 +239,7 @@ declare const hostSchema: z.ZodObject<{
138
239
  disconnected: "disconnected";
139
240
  }>;
140
241
  type: z.ZodEnum<{
242
+ ephemeral: "ephemeral";
141
243
  persistent: "persistent";
142
244
  }>;
143
245
  updatedAt: z.ZodNumber;
@@ -221,8 +323,10 @@ type Checkout<R> = R extends {
221
323
  gitCheckout: true;
222
324
  } ? {
223
325
  path: string;
326
+ experimental_ownsPath: boolean;
224
327
  } : {
225
328
  path: string;
329
+ experimental_ownsPath: boolean;
226
330
  } | null;
227
331
  type InputsValue<S> = S extends StandardSchemaV1$1 ? StandardSchemaV1InferOutput<S> : null;
228
332
  /** Attempt-scoped updates; core persists each update before this call returns. */
@@ -306,8 +410,10 @@ interface PluginEnvironmentProviderPolicy {
306
410
  interface PluginEnvironmentProviderDefinition<R extends PluginEnvironmentProviderRequirements$1 = PluginEnvironmentProviderRequirements$1, S extends PluginEnvironmentProviderInputsSchema = PluginEnvironmentProviderInputsSchema> {
307
411
  id: string;
308
412
  displayName: string;
413
+ /** Short explanation shown in environment choices. */
414
+ description: string;
309
415
  /** Host glyph, plugin-relative icon path, or this plugin’s declared namespaced icon. */
310
- icon?: string;
416
+ icon: string;
311
417
  requires?: R;
312
418
  inputs?: S;
313
419
  policy?: Partial<PluginEnvironmentProviderPolicy>;
@@ -318,6 +424,30 @@ interface PluginEnvironmentProviderDefinition<R extends PluginEnvironmentProvide
318
424
  remove(context: PluginEnvironmentProviderRemoveContext): Promise<PluginEnvironmentProviderRemoveResult>;
319
425
  }
320
426
 
427
+ interface MachineExecutorRequest {
428
+ command: string[];
429
+ timeoutMs: number;
430
+ signal: AbortSignal;
431
+ stdin: string;
432
+ onOutput: (chunk: string) => void;
433
+ }
434
+ interface MachineExecutor {
435
+ exec(request: MachineExecutorRequest): Promise<{
436
+ exitCode: number;
437
+ }>;
438
+ }
439
+ interface MachineBootstrapRequest {
440
+ key: string;
441
+ executor: MachineExecutor;
442
+ report: PluginMachineProviderProgress;
443
+ signal: AbortSignal;
444
+ }
445
+ interface MachineBootstrapApi {
446
+ bootstrap(request: MachineBootstrapRequest): Promise<{
447
+ hostId: string;
448
+ }>;
449
+ }
450
+
321
451
  /**
322
452
  * A value that survives a JSON round trip without coercion or data loss.
323
453
  *
@@ -389,6 +519,36 @@ interface PluginEnvironmentProviderRequirements {
389
519
  * supplied pathKey. Provider ids are unique across running plugins.
390
520
  */
391
521
  type PluginEnvironmentProviderDeclaration<Requires extends PluginEnvironmentProviderRequirements = PluginEnvironmentProviderRequirements, Inputs extends PluginEnvironmentProviderInputsSchema = PluginEnvironmentProviderInputsSchema> = PluginEnvironmentProviderDefinition<Requires, Inputs>;
522
+ type PluginMachineProviderDeclaration<Inputs extends PluginMachineProviderInputsSchema = PluginMachineProviderInputsSchema> = PluginMachineProviderDefinition<Inputs>;
523
+ interface ServerAccessGrant {
524
+ id: string;
525
+ serverUrl: string;
526
+ headers?: Record<string, string>;
527
+ }
528
+ interface ServerAccessProviderDeclaration {
529
+ id: string;
530
+ displayName: string;
531
+ description: string;
532
+ availability(): (PluginMachineProviderAvailability & {
533
+ serverUrl?: string;
534
+ }) | Promise<PluginMachineProviderAvailability & {
535
+ serverUrl?: string;
536
+ }>;
537
+ acquire(context: {
538
+ key: string;
539
+ hostId: string;
540
+ signal: AbortSignal;
541
+ }): Promise<ServerAccessGrant | {
542
+ status: "failed";
543
+ message: string;
544
+ }>;
545
+ release(context: {
546
+ key: string;
547
+ hostId: string;
548
+ /** Null when acquisition was interrupted before a grant was returned. Reconcile using key and hostId. */
549
+ grantId: string | null;
550
+ }): Promise<void>;
551
+ }
392
552
  /**
393
553
  * Permission modes a provider can run a session in — BB's own permission
394
554
  * vocabulary, ordered least ("accept-edits") to most ("full") privileged.
@@ -761,9 +921,19 @@ declare const ENVIRONMENT_PROVIDER_REQUIREMENT_NAMES: readonly ["projectCheckout
761
921
  type NormalizedPluginEnvironmentProviderRequirements = {
762
922
  [K in (typeof ENVIRONMENT_PROVIDER_REQUIREMENT_NAMES)[number]]: boolean;
763
923
  };
924
+ declare const environmentCompositionSchema: z.ZodObject<{
925
+ description: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | null, string | undefined>>;
926
+ displayName: z.ZodString;
927
+ environmentProviderId: z.ZodString;
928
+ icon: z.ZodPipe<z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>, z.ZodTransform<string | null, string | undefined>>;
929
+ id: z.ZodString;
930
+ machineProviderId: z.ZodString;
931
+ }, z.core.$strict>;
932
+ type NormalizedPluginEnvironmentComposition = z.infer<typeof environmentCompositionSchema>;
764
933
  interface NormalizedPluginEnvironmentProvider {
765
934
  id: string;
766
935
  displayName: string;
936
+ description: string | null;
767
937
  icon: string | null;
768
938
  requires: NormalizedPluginEnvironmentProviderRequirements;
769
939
  inputs: StandardSchemaV1 | null;
@@ -774,14 +944,24 @@ interface NormalizedPluginEnvironmentProvider {
774
944
  remove: PluginEnvironmentProviderDeclaration["remove"];
775
945
  policy: PluginEnvironmentProviderPolicy;
776
946
  }
947
+ interface NormalizedPluginMachineProvider {
948
+ id: string;
949
+ displayName: string;
950
+ description: string;
951
+ icon: string;
952
+ ephemeral: boolean;
953
+ inputs: StandardSchemaV1 | null;
954
+ inputsJsonSchema: JsonValue | null;
955
+ availability: NonNullable<PluginMachineProviderDeclaration["availability"]> | null;
956
+ validate: NonNullable<PluginMachineProviderDeclaration["validate"]> | null;
957
+ reconcileCleanup: PluginMachineProviderDeclaration["reconcileCleanup"];
958
+ create: PluginMachineProviderDeclaration["create"];
959
+ suspend: NonNullable<PluginMachineProviderDeclaration["suspend"]> | null;
960
+ resume: NonNullable<PluginMachineProviderDeclaration["resume"]> | null;
961
+ remove: PluginMachineProviderDeclaration["remove"];
962
+ }
777
963
 
778
964
  type BbSdk = BbPluginApi["sdk"];
779
- /**
780
- * Recordable `bb.sdk` stand-in for {@link createFakePluginHost}. Every call
781
- * through the fake is recorded (post plugin-attribution defaulting, so
782
- * assertions see what the server would receive); calls without a stubbed
783
- * implementation throw with a message naming the exact path to stub.
784
- */
785
965
  /** One recorded `bb.sdk` call. `path` is dot-joined, e.g. "threads.spawn". */
786
966
  interface FakeSdkCall {
787
967
  path: string;
@@ -802,13 +982,24 @@ type FakeSdkOverrideTree<T> = {
802
982
  };
803
983
  type FakeSdkOverrides = FakeSdkOverrideTree<BbSdk>;
804
984
  interface FakeSdkHarness {
805
- /** Every `bb.sdk` call in order, including ones whose stub threw. */
985
+ /**
986
+ * Every `bb.sdk` call in order, including ones whose stub threw. Calls
987
+ * rejected by argument validation are not recorded.
988
+ */
806
989
  readonly calls: FakeSdkCall[];
807
990
  /** Argument lists of the calls to one dot-joined path. */
808
991
  callsTo(path: string): unknown[][];
809
992
  /** Add or replace one method's implementation after creation. */
810
993
  stub(path: string, implementation: (...args: never[]) => unknown): void;
811
994
  }
995
+ /**
996
+ * Recordable `bb.sdk` stand-in for {@link createFakePluginHost}. Calls are
997
+ * recorded after the plugin-bound normalization the server applies, so
998
+ * assertions see what the server would receive. Arguments the real SDK
999
+ * rejects before sending, such as invalid `pluginMetadata`, return a rejected
1000
+ * promise and are not recorded. Calls without a stubbed implementation throw
1001
+ * with a message naming the exact path to stub.
1002
+ */
812
1003
  declare function createFakeSdk(options: {
813
1004
  pluginId: string;
814
1005
  overrides?: FakeSdkOverrides;
@@ -955,7 +1146,10 @@ interface FakePluginRegistrations {
955
1146
  hooks: {
956
1147
  [K in PluginHookName]: PluginHookHandler<K> | null;
957
1148
  };
1149
+ environmentCompositions: ReadonlyMap<string, NormalizedPluginEnvironmentComposition>;
958
1150
  environmentProviders: ReadonlyMap<string, NormalizedPluginEnvironmentProvider>;
1151
+ machineProviders: ReadonlyMap<string, NormalizedPluginMachineProvider>;
1152
+ serverAccessProviders: ReadonlyMap<string, ServerAccessProviderDeclaration>;
959
1153
  mentionProviders: FakeMentionProviderRecord[];
960
1154
  /** Live provider registrations from `bb.providers.register`
961
1155
  * (normalized declarations, registration order; dispose removes). */
@@ -1060,7 +1254,10 @@ interface FakePluginBehaviorDrivers {
1060
1254
  callAgentTool(name: string, input: unknown, ctx?: Partial<PluginAgentToolContext>): Promise<PluginAgentToolResult>;
1061
1255
  /** Evaluate `bb.agents.configure` with production validation/fail-closed
1062
1256
  * semantics. With no callback, every registered tool/declared test skill is
1063
- * selected. Callback failures are logged and return empty selections. */
1257
+ * selected. The callback receives a copy of `context` whose `pluginMetadata`
1258
+ * is a validated, deep-frozen clone; invalid metadata rejects instead of
1259
+ * reaching the callback. Callback failures are logged and return empty
1260
+ * selections. */
1064
1261
  resolveAgentConfiguration(context: PluginAgentConfigurationContext): Promise<{
1065
1262
  tools: FakeAgentToolRecord[];
1066
1263
  skills: string[];
@@ -1095,6 +1292,8 @@ interface FakePluginHarness extends FakePluginInspectionState, FakePluginBehavio
1095
1292
  readonly lifecycle: FakePluginLifecycleControls;
1096
1293
  }
1097
1294
  interface CreateFakePluginHostOptions {
1295
+ machineBootstrap?: MachineBootstrapApi;
1296
+ machineResource?: (hostId: string) => Promise<JsonValue$2 | null>;
1098
1297
  /** Defaults to "test-plugin". */
1099
1298
  pluginId?: string;
1100
1299
  /**
@@ -1156,6 +1355,7 @@ type ThreadResponse = PluginThreadEventPayloads["thread.created"]["thread"];
1156
1355
  type QueueEntry = PluginThreadEventPayloads["message.queued"]["entry"];
1157
1356
  type TurnFailedEvent = PluginThreadEventPayloads["turn.failed"];
1158
1357
  type PluginAgentConfigurationContextOverrides = {
1358
+ pluginMetadata?: PluginAgentConfigurationContext["pluginMetadata"];
1159
1359
  thread?: Partial<PluginAgentConfigurationContext["thread"]>;
1160
1360
  project?: Partial<PluginAgentConfigurationContext["project"]>;
1161
1361
  environment?: Partial<PluginAgentConfigurationContext["environment"]>;