@get-bb/plugin-sdk 0.6.60 → 0.6.65

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,6 +1,102 @@
1
+ // src/rpc-contract.ts
2
+ var rpcErrorCodes = [
3
+ "forbidden",
4
+ "not_found",
5
+ "conflict",
6
+ "invalid",
7
+ "invalid_json",
8
+ "invalid_input",
9
+ "handler_error",
10
+ "invalid_output",
11
+ "non_json_result",
12
+ "unknown_method",
13
+ "transport_error",
14
+ "invalid_response",
15
+ "unknown_error"
16
+ ];
17
+ var callErrorBrand = /* @__PURE__ */ Symbol.for("@get-bb/plugin-sdk/rpc-call-error");
18
+ var experimental_PluginRpcCallError = class _experimental_PluginRpcCallError extends Error {
19
+ /** Recognizes errors across the packed SDK's separately bundled entries. */
20
+ static [Symbol.hasInstance](value) {
21
+ return typeof value === "object" && value !== null && Reflect.get(value, callErrorBrand) === true && rpcErrorCodes.some((code) => code === Reflect.get(value, "code")) && typeof Reflect.get(value, "message") === "string";
22
+ }
23
+ code;
24
+ issues;
25
+ status;
26
+ serverCode;
27
+ constructor(args) {
28
+ super(args.message);
29
+ this.name = "experimental_PluginRpcCallError";
30
+ Object.defineProperty(this, callErrorBrand, { value: true });
31
+ this.code = args.code;
32
+ this.issues = args.issues;
33
+ this.status = args.status;
34
+ this.serverCode = args.serverCode;
35
+ }
36
+ /** Normalize failures at the RPC boundary; preserves an existing client error. */
37
+ static from(error, fallback = "transport_error") {
38
+ if (error instanceof _experimental_PluginRpcCallError) return error;
39
+ const record = typeof error === "object" && error !== null ? error : {};
40
+ const rawCode = Reflect.get(record, "code");
41
+ const code = rpcErrorCodes.find((value) => value === rawCode);
42
+ const message = Reflect.get(record, "message");
43
+ const status = Reflect.get(record, "status");
44
+ const rawIssues = Reflect.get(record, "issues");
45
+ const issues = [];
46
+ if (Array.isArray(rawIssues))
47
+ for (const issue of rawIssues) {
48
+ if (typeof issue !== "object" || issue === null || typeof Reflect.get(issue, "message") !== "string")
49
+ continue;
50
+ const path = Reflect.get(issue, "path");
51
+ if (path !== void 0 && (!Array.isArray(path) || !path.every(
52
+ (part) => typeof part === "string" || typeof part === "number" && Number.isFinite(part)
53
+ )))
54
+ continue;
55
+ issues.push({
56
+ message: Reflect.get(issue, "message"),
57
+ ...path === void 0 ? {} : { path }
58
+ });
59
+ }
60
+ return new _experimental_PluginRpcCallError({
61
+ code: code ?? (typeof rawCode === "string" ? "unknown_error" : fallback),
62
+ message: typeof message === "string" ? message : typeof error === "string" ? error : "Plugin RPC request failed",
63
+ ...issues.length === 0 ? {} : { issues },
64
+ ...typeof status === "number" ? { status } : {},
65
+ ...typeof rawCode === "string" && code === void 0 ? { serverCode: rawCode } : {}
66
+ });
67
+ }
68
+ };
69
+ var refusalBrand = /* @__PURE__ */ Symbol.for("@get-bb/plugin-sdk/rpc-refusal");
70
+ var experimental_PluginRpcRefusal = class extends Error {
71
+ [refusalBrand] = true;
72
+ code;
73
+ issues;
74
+ constructor(args) {
75
+ super(args.message);
76
+ this.name = "experimental_PluginRpcRefusal";
77
+ this.code = args.code;
78
+ this.issues = args.issues;
79
+ }
80
+ };
81
+
82
+ // src/internal/rpc-tags.ts
83
+ import { z } from "zod";
84
+ var rpcInvalidationTags = z.array(z.string().min(1)).min(1);
85
+ function rpcResponseTags(declarations, input, output) {
86
+ const tags = z.array(z.string().min(1)).parse(declarations.tags?.(input, output) ?? []);
87
+ const keyTags = {};
88
+ if (declarations.keyTags && typeof output === "object" && output !== null && !Array.isArray(output)) {
89
+ for (const [key, value] of Object.entries(output)) {
90
+ keyTags[key] = z.array(z.string().min(1)).parse(declarations.keyTags(key, value));
91
+ }
92
+ }
93
+ const invalidated = z.array(z.string().min(1)).parse(declarations.invalidates?.(input, output) ?? []);
94
+ return { tags, keyTags, invalidated };
95
+ }
96
+
1
97
  // src/internal/host-policy.ts
2
98
  import { createHash } from "node:crypto";
3
- import { z as z5 } from "zod";
99
+ import { z as z6 } from "zod";
4
100
 
5
101
  // ../domain/src/plugin-icon.ts
6
102
  function isPluginOwnedIconPath(icon) {
@@ -53,14 +149,14 @@ var PLUGIN_INTERACTION_MAX_PAYLOAD_BYTES = 64 * 1024;
53
149
  var PLUGIN_INTERACTION_MAX_TIMEOUT_MS = 7 * 24 * 60 * 60 * 1e3;
54
150
 
55
151
  // ../domain/src/provider-fork.ts
56
- import { z } from "zod";
152
+ import { z as z2 } from "zod";
57
153
  var PROVIDER_FORK_VALUES = ["none", "tip", "checkpoint"];
58
- var providerForkSchema = z.enum(PROVIDER_FORK_VALUES);
154
+ var providerForkSchema = z2.enum(PROVIDER_FORK_VALUES);
59
155
 
60
156
  // ../domain/src/completed-turn-display.ts
61
- import { z as z2 } from "zod";
157
+ import { z as z3 } from "zod";
62
158
  var COMPLETED_TURN_DISPLAY_VALUES = ["collapse", "flat"];
63
- var completedTurnDisplaySchema = z2.enum(COMPLETED_TURN_DISPLAY_VALUES);
159
+ var completedTurnDisplaySchema = z3.enum(COMPLETED_TURN_DISPLAY_VALUES);
64
160
  var DEFAULT_COMPLETED_TURN_DISPLAY = "collapse";
65
161
 
66
162
  // ../domain/src/provider-skill-roots.ts
@@ -85,53 +181,53 @@ function isRelativeProviderSkillRootPath(value) {
85
181
  }
86
182
 
87
183
  // ../domain/src/json-value.ts
88
- import { z as z3 } from "zod";
89
- var jsonValueSchema = z3.lazy(
90
- () => z3.union([
91
- z3.string(),
92
- z3.number(),
93
- z3.boolean(),
94
- z3.null(),
95
- z3.array(jsonValueSchema),
96
- z3.record(z3.string(), jsonValueSchema)
184
+ import { z as z4 } from "zod";
185
+ var jsonValueSchema = z4.lazy(
186
+ () => z4.union([
187
+ z4.string(),
188
+ z4.number(),
189
+ z4.boolean(),
190
+ z4.null(),
191
+ z4.array(jsonValueSchema),
192
+ z4.record(z4.string(), jsonValueSchema)
97
193
  ])
98
194
  );
99
- var jsonObjectSchema = z3.record(
100
- z3.string(),
195
+ var jsonObjectSchema = z4.record(
196
+ z4.string(),
101
197
  jsonValueSchema
102
198
  );
103
199
 
104
200
  // ../domain/src/native-roots.ts
105
- import { z as z4 } from "zod";
201
+ import { z as z5 } from "zod";
106
202
  var PROVIDER_NATIVE_ROOTS_MAX = 32;
107
203
  var PROVIDER_NATIVE_ROOT_NAME_PREFIX_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,62}:$/u;
108
- var nativeRootNamePrefixSchema = z4.string().refine(
204
+ var nativeRootNamePrefixSchema = z5.string().refine(
109
205
  (value) => value === "" || PROVIDER_NATIVE_ROOT_NAME_PREFIX_PATTERN.test(value),
110
206
  "A root name prefix is a plugin-name-like token ending in ':'"
111
207
  );
112
- var nativeRootManifestPathSchema = z4.string().min(1).refine(
208
+ var nativeRootManifestPathSchema = z5.string().min(1).refine(
113
209
  isRelativeProviderSkillRootPath,
114
210
  "A manifest marker is a relative path without dot segments"
115
211
  );
116
- var relativeNativeRootPathSchema = z4.string().min(1).refine(
212
+ var relativeNativeRootPathSchema = z5.string().min(1).refine(
117
213
  isRelativeProviderSkillRootPath,
118
214
  "Roots must be relative paths without dot segments"
119
215
  );
120
- var absoluteNativeRootPathSchema = z4.string().min(1).refine(
216
+ var absoluteNativeRootPathSchema = z5.string().min(1).refine(
121
217
  isAbsoluteProviderSkillRootPath,
122
218
  "Absolute roots must be absolute paths without dot segments"
123
219
  );
124
- var providerNativeRootInputSchema = z4.union([
125
- z4.string().min(1),
126
- z4.object({
127
- path: z4.string().min(1),
220
+ var providerNativeRootInputSchema = z5.union([
221
+ z5.string().min(1),
222
+ z5.object({
223
+ path: z5.string().min(1),
128
224
  /** Skills nest in subdirectories (the agent scans recursively). */
129
- recursive: z4.boolean().optional(),
225
+ recursive: z5.boolean().optional(),
130
226
  /**
131
227
  * Scan the same relative directory in every ancestor of the workspace
132
228
  * up to the repository root (`project` roots only).
133
229
  */
134
- ancestors: z4.boolean().optional(),
230
+ ancestors: z5.boolean().optional(),
135
231
  /**
136
232
  * Prepended to every name under the root, a vendor plugin's
137
233
  * `plugin-name:`; a prefixed root is listed as a plugin root.
@@ -146,14 +242,14 @@ var providerNativeRootInputSchema = z4.union([
146
242
  skipIfManifest: nativeRootManifestPathSchema.optional()
147
243
  }).strict()
148
244
  ]);
149
- var providerNativeRootsInputSchema = z4.object({
150
- user: z4.array(providerNativeRootInputSchema).optional(),
151
- project: z4.array(providerNativeRootInputSchema).optional()
245
+ var providerNativeRootsInputSchema = z5.object({
246
+ user: z5.array(providerNativeRootInputSchema).optional(),
247
+ project: z5.array(providerNativeRootInputSchema).optional()
152
248
  }).strict();
153
- var providerNativeRootSchema = z4.object({
154
- path: z4.string().min(1),
155
- recursive: z4.boolean(),
156
- ancestors: z4.boolean(),
249
+ var providerNativeRootSchema = z5.object({
250
+ path: z5.string().min(1),
251
+ recursive: z5.boolean(),
252
+ ancestors: z5.boolean(),
157
253
  namePrefix: nativeRootNamePrefixSchema,
158
254
  /** Absent: every skill-shaped directory under the root is a skill. */
159
255
  skipIfManifest: nativeRootManifestPathSchema.optional()
@@ -162,7 +258,7 @@ function uniqueByPath(roots) {
162
258
  return new Set(roots.map((root) => root.path)).size === roots.length;
163
259
  }
164
260
  function nativeRootSideSchema(side) {
165
- return z4.array(
261
+ return z5.array(
166
262
  providerNativeRootSchema.extend({ path: relativeNativeRootPathSchema }).superRefine((root, context) => {
167
263
  if (root.ancestors && side !== "project") {
168
264
  context.addIssue({
@@ -173,7 +269,7 @@ function nativeRootSideSchema(side) {
173
269
  })
174
270
  ).max(PROVIDER_NATIVE_ROOTS_MAX).refine(uniqueByPath, "Roots must not repeat a path");
175
271
  }
176
- var providerNativeRootsSchema = z4.object({
272
+ var providerNativeRootsSchema = z5.object({
177
273
  user: nativeRootSideSchema("user"),
178
274
  project: nativeRootSideSchema("project")
179
275
  }).strict();
@@ -199,19 +295,19 @@ function normalizeProviderNativeRoots(roots) {
199
295
  project: (roots?.project ?? []).map(normalizeProviderNativeRoot)
200
296
  };
201
297
  }
202
- var providerResolvedNativeRootShapeSchema = z4.enum([
298
+ var providerResolvedNativeRootShapeSchema = z5.enum([
203
299
  "skills",
204
300
  "skill",
205
301
  "skill-file",
206
302
  "commands",
207
303
  "command-file"
208
304
  ]);
209
- var resolvedNativeRootFieldsSchema = z4.object({
305
+ var resolvedNativeRootFieldsSchema = z5.object({
210
306
  path: absoluteNativeRootPathSchema,
211
- origin: z4.enum(["user", "project"]),
212
- recursive: z4.boolean(),
307
+ origin: z5.enum(["user", "project"]),
308
+ recursive: z5.boolean(),
213
309
  /** Only with origin `project`, for a path inside the workspace. */
214
- ancestors: z4.boolean(),
310
+ ancestors: z5.boolean(),
215
311
  namePrefix: nativeRootNamePrefixSchema,
216
312
  shape: providerResolvedNativeRootShapeSchema,
217
313
  /**
@@ -219,7 +315,7 @@ var resolvedNativeRootFieldsSchema = z4.object({
219
315
  * none. A vendor plugin's root SKILL.md takes the plugin's name; absent
220
316
  * means the parent directory's name.
221
317
  */
222
- fallbackName: z4.string().min(1).optional(),
318
+ fallbackName: z5.string().min(1).optional(),
223
319
  /**
224
320
  * `skills` only: a file, relative to a skill directory under this root,
225
321
  * that marks the directory as a vendor plugin rather than a skill; the
@@ -263,14 +359,14 @@ var resolvedCommandShapes = /* @__PURE__ */ new Set([
263
359
  "command-file"
264
360
  ]);
265
361
  var PROVIDER_RESOLVED_NATIVE_ROOTS_MAX = 256;
266
- var providerResolvedNativeRootsSchema = z4.object({
267
- skills: z4.array(
362
+ var providerResolvedNativeRootsSchema = z5.object({
363
+ skills: z5.array(
268
364
  providerResolvedNativeRootSchema.refine(
269
365
  (root) => resolvedSkillShapes.has(root.shape),
270
366
  "A skills root needs a skill shape"
271
367
  )
272
368
  ).max(PROVIDER_RESOLVED_NATIVE_ROOTS_MAX),
273
- commands: z4.array(
369
+ commands: z5.array(
274
370
  providerResolvedNativeRootSchema.refine(
275
371
  (root) => resolvedCommandShapes.has(root.shape),
276
372
  "A commands root needs a command shape"
@@ -281,7 +377,7 @@ var EMPTY_PROVIDER_RESOLVED_NATIVE_ROOTS = Object.freeze({
281
377
  skills: Object.freeze([]),
282
378
  commands: Object.freeze([])
283
379
  });
284
- var providerNativeRootSetSchema = z4.object({
380
+ var providerNativeRootSetSchema = z5.object({
285
381
  skills: providerNativeRootsSchema,
286
382
  commands: providerNativeRootsSchema,
287
383
  resolved: providerResolvedNativeRootsSchema
@@ -359,15 +455,15 @@ var CLI_COMMAND_NAME_PATTERN = /^[a-z0-9-]+$/;
359
455
  var AGENT_TOOL_NAME_PATTERN = /^[a-zA-Z0-9_-]+$/;
360
456
  var PLUGIN_PROVIDER_ENV_NAME_PATTERN = /^[A-Z_][A-Z0-9_]*$/;
361
457
  var PLUGIN_PROVIDER_ENV_MAX_ENTRIES = 32;
362
- var pluginProviderEnvEntrySchema = z5.object({
363
- name: z5.string().regex(PLUGIN_PROVIDER_ENV_NAME_PATTERN),
364
- value: z5.union([
365
- z5.string(),
366
- z5.object({ serverPath: z5.string().startsWith("/") }).strict()
458
+ var pluginProviderEnvEntrySchema = z6.object({
459
+ name: z6.string().regex(PLUGIN_PROVIDER_ENV_NAME_PATTERN),
460
+ value: z6.union([
461
+ z6.string(),
462
+ z6.object({ serverPath: z6.string().startsWith("/") }).strict()
367
463
  ]),
368
- reason: z5.string()
464
+ reason: z6.string()
369
465
  }).strict();
370
- var pluginProviderEnvEntriesSchema = z5.array(pluginProviderEnvEntrySchema).max(PLUGIN_PROVIDER_ENV_MAX_ENTRIES).superRefine((entries, context) => {
466
+ var pluginProviderEnvEntriesSchema = z6.array(pluginProviderEnvEntrySchema).max(PLUGIN_PROVIDER_ENV_MAX_ENTRIES).superRefine((entries, context) => {
371
467
  const names = /* @__PURE__ */ new Set();
372
468
  for (let index = 0; index < entries.length; index += 1) {
373
469
  const name = entries[index]?.name;
@@ -402,26 +498,26 @@ var PROVIDER_ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
402
498
  var PLUGIN_PROVIDER_BRIDGE_OPTIONS_MAX_BYTES = 64 * 1024;
403
499
  var SETTING_KEY_PATTERN = /^[a-zA-Z0-9_-]+$/;
404
500
  var settingsBaseFields = {
405
- label: z5.string().min(1),
406
- description: z5.string().min(1).optional()
501
+ label: z6.string().min(1),
502
+ description: z6.string().min(1).optional()
407
503
  };
408
- var stringSettingSchemaSchema = z5.custom(
504
+ var stringSettingSchemaSchema = z6.custom(
409
505
  (value) => isStandardSchema(value)
410
506
  );
411
- var booleanSettingSchemaSchema = z5.custom(
507
+ var booleanSettingSchemaSchema = z6.custom(
412
508
  (value) => isStandardSchema(value)
413
509
  );
414
- var numberSettingSchemaSchema = z5.custom(
510
+ var numberSettingSchemaSchema = z6.custom(
415
511
  (value) => isStandardSchema(value)
416
512
  );
417
- var settingDescriptorSchema = z5.discriminatedUnion("type", [
418
- z5.object({
419
- type: z5.literal("string"),
513
+ var settingDescriptorSchema = z6.discriminatedUnion("type", [
514
+ z6.object({
515
+ type: z6.literal("string"),
420
516
  ...settingsBaseFields,
421
- secret: z5.literal(true).optional(),
422
- experimental_multiline: z5.boolean().optional(),
517
+ secret: z6.literal(true).optional(),
518
+ experimental_multiline: z6.boolean().optional(),
423
519
  experimental_schema: stringSettingSchemaSchema.optional(),
424
- default: z5.string().optional()
520
+ default: z6.string().optional()
425
521
  }).strict().refine(
426
522
  (descriptor) => !(descriptor.secret === true && descriptor.experimental_multiline === true),
427
523
  {
@@ -429,31 +525,31 @@ var settingDescriptorSchema = z5.discriminatedUnion("type", [
429
525
  path: ["experimental_multiline"]
430
526
  }
431
527
  ),
432
- z5.object({
433
- type: z5.literal("boolean"),
528
+ z6.object({
529
+ type: z6.literal("boolean"),
434
530
  ...settingsBaseFields,
435
531
  experimental_schema: booleanSettingSchemaSchema.optional(),
436
- default: z5.boolean().optional()
532
+ default: z6.boolean().optional()
437
533
  }).strict(),
438
- z5.object({
439
- type: z5.literal("number"),
534
+ z6.object({
535
+ type: z6.literal("number"),
440
536
  ...settingsBaseFields,
441
537
  experimental_schema: numberSettingSchemaSchema.optional(),
442
- default: z5.number().finite().optional()
538
+ default: z6.number().finite().optional()
443
539
  }).strict(),
444
- z5.object({
445
- type: z5.literal("select"),
540
+ z6.object({
541
+ type: z6.literal("select"),
446
542
  ...settingsBaseFields,
447
- options: z5.array(z5.string().min(1)).min(1),
448
- experimental_optionLabels: z5.record(z5.string().min(1), z5.string().min(1)).optional(),
543
+ options: z6.array(z6.string().min(1)).min(1),
544
+ experimental_optionLabels: z6.record(z6.string().min(1), z6.string().min(1)).optional(),
449
545
  experimental_schema: stringSettingSchemaSchema.optional(),
450
- default: z5.string().optional()
546
+ default: z6.string().optional()
451
547
  }).strict(),
452
- z5.object({
453
- type: z5.literal("project"),
548
+ z6.object({
549
+ type: z6.literal("project"),
454
550
  ...settingsBaseFields,
455
551
  experimental_schema: stringSettingSchemaSchema.optional(),
456
- default: z5.string().optional()
552
+ default: z6.string().optional()
457
553
  }).strict()
458
554
  ]);
459
555
  function registerSettingDescriptors(target, added) {
@@ -1453,9 +1549,9 @@ function isStandardSchema(value) {
1453
1549
  const standard = Reflect.get(value, "~standard");
1454
1550
  return typeof standard === "object" && standard !== null && Reflect.get(standard, "version") === 1 && typeof Reflect.get(standard, "vendor") === "string" && typeof Reflect.get(standard, "validate") === "function";
1455
1551
  }
1456
- var rpcDescriptionSchema = z5.string().trim().min(1).max(4096).optional().transform((value) => value ?? null);
1457
- var rpcPublicationOptionsSchema = z5.object({
1458
- experimental_discoverable: z5.boolean().default(false),
1552
+ var rpcDescriptionSchema = z6.string().trim().min(1).max(4096).optional().transform((value) => value ?? null);
1553
+ var rpcPublicationOptionsSchema = z6.object({
1554
+ experimental_discoverable: z6.boolean().default(false),
1459
1555
  experimental_description: rpcDescriptionSchema
1460
1556
  }).strict();
1461
1557
  function readRpcMethodContract(method, value) {
@@ -1479,7 +1575,21 @@ function readRpcMethodContract(method, value) {
1479
1575
  const description = rpcDescriptionSchema.parse(
1480
1576
  Reflect.get(value, "experimental_description")
1481
1577
  );
1482
- return description === null ? { input, output } : { input, output, experimental_description: description };
1578
+ const declarations = {};
1579
+ for (const name of ["tags", "keyTags", "invalidates"]) {
1580
+ const declaration = Reflect.get(value, name);
1581
+ if (declaration !== void 0) {
1582
+ if (typeof declaration !== "function")
1583
+ throw new Error(`rpc ${method} ${name} must be a function`);
1584
+ Reflect.set(declarations, name, declaration);
1585
+ }
1586
+ }
1587
+ return {
1588
+ input,
1589
+ output,
1590
+ ...declarations,
1591
+ ...description === null ? {} : { experimental_description: description }
1592
+ };
1483
1593
  }
1484
1594
  function readRpcPublicationOptions(value) {
1485
1595
  return rpcPublicationOptionsSchema.parse(value ?? {});
@@ -1497,7 +1607,7 @@ function publishedRpcSchema(schema, direction) {
1497
1607
  if (serialized === void 0 || new TextEncoder().encode(serialized).byteLength > 128 * 1024) {
1498
1608
  throw new Error("published RPC schema must be JSON and at most 128 KiB");
1499
1609
  }
1500
- const result = z5.record(z5.string(), jsonValueSchema).parse(JSON.parse(serialized));
1610
+ const result = z6.record(z6.string(), jsonValueSchema).parse(JSON.parse(serialized));
1501
1611
  const inspect = (value) => {
1502
1612
  if (value === null || typeof value !== "object") return;
1503
1613
  if (Array.isArray(value)) {
@@ -1547,7 +1657,7 @@ function zodSchemaToJsonSchema(schema) {
1547
1657
  if (typeof schema.toJSONSchema === "function") {
1548
1658
  return schema.toJSONSchema({ io: "input" });
1549
1659
  }
1550
- return z5.toJSONSchema(schema, { io: "input" });
1660
+ return z6.toJSONSchema(schema, { io: "input" });
1551
1661
  }
1552
1662
  var SINGLE_SCHEMA_KEYWORDS = [
1553
1663
  "additionalItems",
@@ -1878,15 +1988,15 @@ var ENVIRONMENT_PROVIDER_REQUIREMENT_NAMES = [
1878
1988
  "gitRemote",
1879
1989
  "projectless"
1880
1990
  ];
1881
- var environmentCompositionSchema = z5.object({
1882
- id: z5.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN),
1883
- displayName: z5.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DISPLAY_NAME_MAX_CHARS),
1884
- description: z5.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DESCRIPTION_MAX_CHARS).optional().transform((value) => value ?? null),
1885
- icon: z5.string().trim().min(1).transform(
1991
+ var environmentCompositionSchema = z6.object({
1992
+ id: z6.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN),
1993
+ displayName: z6.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DISPLAY_NAME_MAX_CHARS),
1994
+ description: z6.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DESCRIPTION_MAX_CHARS).optional().transform((value) => value ?? null),
1995
+ icon: z6.string().trim().min(1).transform(
1886
1996
  (icon) => isPluginOwnedIconPath(icon) ? validateProviderRelativePath(icon, "Composition icon") : icon
1887
1997
  ).optional().transform((value) => value ?? null),
1888
- machineProviderId: z5.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN),
1889
- environmentProviderId: z5.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN)
1998
+ machineProviderId: z6.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN),
1999
+ environmentProviderId: z6.string().regex(ENVIRONMENT_PROVIDER_ID_PATTERN)
1890
2000
  }).strict();
1891
2001
  function requireProviderIdAndDisplayName(noun, declaration) {
1892
2002
  if (typeof declaration !== "object" || declaration === null) {
@@ -1952,8 +2062,8 @@ function validatePluginEnvironmentProviderDeclaration(declaration) {
1952
2062
  "environment provider",
1953
2063
  declaration
1954
2064
  );
1955
- const description = z5.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DESCRIPTION_MAX_CHARS).optional().transform((value) => value ?? null).parse(declaration.description);
1956
- const icon = z5.string().trim().min(1).optional().transform((value) => value ?? null).parse(declaration.icon);
2065
+ const description = z6.string().trim().min(1).max(ENVIRONMENT_PROVIDER_DESCRIPTION_MAX_CHARS).optional().transform((value) => value ?? null).parse(declaration.description);
2066
+ const icon = z6.string().trim().min(1).optional().transform((value) => value ?? null).parse(declaration.icon);
1957
2067
  if (icon !== null) {
1958
2068
  assertProviderIconShape("environment provider", id, icon);
1959
2069
  }
@@ -2036,9 +2146,9 @@ function normalizeEnvironmentProviderRequirements(id, declaration) {
2036
2146
  }
2037
2147
  return normalized;
2038
2148
  }
2039
- var environmentProviderPolicySchema = z5.object({
2040
- retireGraceMs: z5.number().int().nonnegative().nullable().default(3e5),
2041
- pathKeys: z5.enum(["per-thread", "per-attempt"]).default("per-thread")
2149
+ var environmentProviderPolicySchema = z6.object({
2150
+ retireGraceMs: z6.number().int().nonnegative().nullable().default(3e5),
2151
+ pathKeys: z6.enum(["per-thread", "per-attempt"]).default("per-thread")
2042
2152
  }).strict();
2043
2153
  var MACHINE_PROVIDER_DESCRIPTION_MAX_CHARS = 200;
2044
2154
  function validatePluginMachineProviderDeclaration(declaration) {
@@ -2046,10 +2156,10 @@ function validatePluginMachineProviderDeclaration(declaration) {
2046
2156
  "machine provider",
2047
2157
  declaration
2048
2158
  );
2049
- const description = z5.string().trim().min(1).max(MACHINE_PROVIDER_DESCRIPTION_MAX_CHARS).parse(declaration.description);
2050
- const icon = z5.string().trim().min(1).parse(declaration.icon);
2159
+ const description = z6.string().trim().min(1).max(MACHINE_PROVIDER_DESCRIPTION_MAX_CHARS).parse(declaration.description);
2160
+ const icon = z6.string().trim().min(1).parse(declaration.icon);
2051
2161
  assertProviderIconShape("machine provider", id, icon);
2052
- const ephemeral = z5.boolean().default(false).parse(declaration.ephemeral);
2162
+ const ephemeral = z6.boolean().default(false).parse(declaration.ephemeral);
2053
2163
  const inputs = normalizeProviderInputs(
2054
2164
  "machine provider",
2055
2165
  id,
@@ -2240,6 +2350,7 @@ function normalizeRpcRegistration(contract, handlers, registered, options) {
2240
2350
  name,
2241
2351
  {
2242
2352
  publication: publishRpcMethod(name, methodContract, publicationOptions),
2353
+ declarations: methodContract,
2243
2354
  inputSchema: methodContract.input,
2244
2355
  outputSchema: methodContract.output,
2245
2356
  handler
@@ -2709,6 +2820,22 @@ function normalizeRpcIssues(issues) {
2709
2820
  };
2710
2821
  });
2711
2822
  }
2823
+ var rpcRefusalSchema = z6.object({
2824
+ code: z6.enum(["forbidden", "not_found", "conflict", "invalid"]),
2825
+ message: z6.string(),
2826
+ issues: z6.array(
2827
+ z6.object({
2828
+ message: z6.string(),
2829
+ path: z6.array(z6.union([z6.string(), z6.number()])).optional()
2830
+ })
2831
+ ).optional()
2832
+ });
2833
+ function readPluginRpcRefusal(error) {
2834
+ if (typeof error !== "object" || error === null || Reflect.get(error, /* @__PURE__ */ Symbol.for("@get-bb/plugin-sdk/rpc-refusal")) !== true)
2835
+ return null;
2836
+ const parsed = rpcRefusalSchema.safeParse(error);
2837
+ return parsed.success ? parsed.data : null;
2838
+ }
2712
2839
  async function validateRpcValue(schema, value, phase, fail) {
2713
2840
  let result;
2714
2841
  try {
@@ -2943,10 +3070,7 @@ function jsonRoundTrip(value, what) {
2943
3070
  return JSON.parse(json);
2944
3071
  }
2945
3072
  function throwRpcError(error) {
2946
- const thrown = new Error(error.message);
2947
- Reflect.set(thrown, "code", error.code);
2948
- if (error.issues !== void 0) Reflect.set(thrown, "issues", error.issues);
2949
- throw thrown;
3073
+ throw new experimental_PluginRpcCallError(error);
2950
3074
  }
2951
3075
  var fakeHostDisposers = /* @__PURE__ */ new WeakMap();
2952
3076
  function createFakePluginHost(options = {}) {
@@ -3122,7 +3246,16 @@ function createFakePluginHostInternal(options, sharedState) {
3122
3246
  }
3123
3247
  };
3124
3248
  const rpcHandlers = /* @__PURE__ */ new Map();
3249
+ const rpcInvalidations = [];
3125
3250
  const rpc = {
3251
+ experimental_invalidate(tags) {
3252
+ assertLive();
3253
+ rpcInvalidations.push(rpcInvalidationTags.parse(tags));
3254
+ },
3255
+ experimental_invalidateAll() {
3256
+ assertLive();
3257
+ rpcInvalidations.push(null);
3258
+ },
3126
3259
  register(contract, handlers, registrationOptions) {
3127
3260
  assertLive();
3128
3261
  for (const [name, record] of normalizeRpcRegistration(
@@ -3727,6 +3860,7 @@ function createFakePluginHostInternal(options, sharedState) {
3727
3860
  },
3728
3861
  pluginId,
3729
3862
  logEntries,
3863
+ experimental_rpcInvalidations: rpcInvalidations,
3730
3864
  realtimeSignals,
3731
3865
  needsConfigurationMessages,
3732
3866
  get recheckCount() {
@@ -3920,6 +4054,8 @@ function createFakePluginHostInternal(options, sharedState) {
3920
4054
  }
3921
4055
  });
3922
4056
  } catch (error) {
4057
+ const refusal = readPluginRpcRefusal(error);
4058
+ if (refusal !== null) return throwRpcError(refusal);
3923
4059
  return throwRpcError({
3924
4060
  code: "handler_error",
3925
4061
  message: errorMessage(error)
@@ -3931,7 +4067,14 @@ function createFakePluginHostInternal(options, sharedState) {
3931
4067
  "output",
3932
4068
  throwRpcError
3933
4069
  );
3934
- return normalizeRpcJsonResult(validatedOutput, throwRpcError);
4070
+ const jsonResult = normalizeRpcJsonResult(validatedOutput, throwRpcError);
4071
+ const { invalidated: invalidated2 } = rpcResponseTags(
4072
+ record.declarations,
4073
+ validatedInput,
4074
+ validatedOutput
4075
+ );
4076
+ if (invalidated2.length > 0) rpc.experimental_invalidate(invalidated2);
4077
+ return jsonResult;
3935
4078
  },
3936
4079
  async runCli(argv, ctx = {}) {
3937
4080
  const registration = cliRecord.registration;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.6.60",
3
+ "version": "0.6.65",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"
@@ -127,6 +127,18 @@
127
127
  "types": "./bundled-types/bb-plugin-sdk-testing-host.d.ts",
128
128
  "import": "./dist/testing/host.js",
129
129
  "default": "./dist/testing/host.js"
130
+ },
131
+ "./internal/rpc-tags": {
132
+ "source": "./src/internal/rpc-tags.ts",
133
+ "types": "./bundled-types/bb-plugin-sdk-internal-rpc-tags.d.ts",
134
+ "import": "./dist/internal/rpc-tags.js",
135
+ "default": "./dist/internal/rpc-tags.js"
136
+ },
137
+ "./internal/rpc-query-host": {
138
+ "source": "./src/internal/rpc-query-host.ts",
139
+ "types": "./bundled-types/bb-plugin-sdk-internal-rpc-query-host.d.ts",
140
+ "import": "./dist/internal/rpc-query-host.js",
141
+ "default": "./dist/internal/rpc-query-host.js"
130
142
  }
131
143
  },
132
144
  "types": "./bundled-types/bb-plugin-sdk.d.ts",
@@ -140,6 +152,7 @@
140
152
  "typecheck": "tsrs --noEmit"
141
153
  },
142
154
  "dependencies": {
155
+ "@tanstack/react-query": "^5.62.0",
143
156
  "cross-spawn": "^7.0.6",
144
157
  "zod": "^4.6.5"
145
158
  },
@@ -166,7 +179,8 @@
166
179
  "rollup-plugin-dts": "^6.4.1",
167
180
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
168
181
  "typescript": "npm:@typescript/typescript6@^6.0.2",
169
- "vitest": "^4.1.1"
182
+ "vitest": "^4.1.1",
183
+ "@bb/query-tags": "workspace:*"
170
184
  },
171
185
  "peerDependencies": {
172
186
  "@testing-library/react": "^16.3.2",