@get-bb/plugin-sdk 0.4.88 → 0.4.94

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.
@@ -1456,6 +1456,11 @@ function isStandardSchema(value) {
1456
1456
  const standard = Reflect.get(value, "~standard");
1457
1457
  return typeof standard === "object" && standard !== null && Reflect.get(standard, "version") === 1 && typeof Reflect.get(standard, "vendor") === "string" && typeof Reflect.get(standard, "validate") === "function";
1458
1458
  }
1459
+ var rpcDescriptionSchema = z4.string().trim().min(1).max(4096).optional().transform((value) => value ?? null);
1460
+ var rpcPublicationOptionsSchema = z4.object({
1461
+ experimental_discoverable: z4.boolean().default(false),
1462
+ experimental_description: rpcDescriptionSchema
1463
+ }).strict();
1459
1464
  function readRpcMethodContract(method, value) {
1460
1465
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
1461
1466
  throw new Error(
@@ -1474,7 +1479,59 @@ function readRpcMethodContract(method, value) {
1474
1479
  `rpc method "${method}" output must be a Standard Schema v1 validator`
1475
1480
  );
1476
1481
  }
1477
- return { input, output };
1482
+ const description = rpcDescriptionSchema.parse(
1483
+ Reflect.get(value, "experimental_description")
1484
+ );
1485
+ return description === null ? { input, output } : { input, output, experimental_description: description };
1486
+ }
1487
+ function readRpcPublicationOptions(value) {
1488
+ return rpcPublicationOptionsSchema.parse(value ?? {});
1489
+ }
1490
+ function publishedRpcSchema(schema, direction) {
1491
+ const converter = schema["~standard"].jsonSchema;
1492
+ if (converter === void 0 || typeof converter[direction] !== "function") {
1493
+ throw new Error(
1494
+ "discoverable RPC requires Standard JSON Schema export support"
1495
+ );
1496
+ }
1497
+ const serialized = JSON.stringify(
1498
+ converter[direction]({ target: "draft-2020-12" })
1499
+ );
1500
+ if (serialized === void 0 || new TextEncoder().encode(serialized).byteLength > 128 * 1024) {
1501
+ throw new Error("published RPC schema must be JSON and at most 128 KiB");
1502
+ }
1503
+ const result = z4.record(z4.string(), jsonValueSchema).parse(JSON.parse(serialized));
1504
+ const inspect = (value) => {
1505
+ if (value === null || typeof value !== "object") return;
1506
+ if (Array.isArray(value)) {
1507
+ for (const item of value) inspect(item);
1508
+ return;
1509
+ }
1510
+ for (const [key, item] of Object.entries(value)) {
1511
+ if ((key === "$ref" || key === "$dynamicRef") && typeof item === "string" && !item.startsWith("#")) {
1512
+ throw new Error("published RPC schemas must use local references");
1513
+ }
1514
+ inspect(item);
1515
+ }
1516
+ };
1517
+ inspect(result);
1518
+ return result;
1519
+ }
1520
+ function publishRpcMethod(method, contract, options) {
1521
+ if (!options.experimental_discoverable) return null;
1522
+ try {
1523
+ return {
1524
+ method,
1525
+ registrationDescription: options.experimental_description,
1526
+ methodDescription: contract.experimental_description ?? null,
1527
+ inputSchema: publishedRpcSchema(contract.input, "input"),
1528
+ outputSchema: publishedRpcSchema(contract.output, "output")
1529
+ };
1530
+ } catch (error) {
1531
+ throw new Error(
1532
+ `rpc method "${method}" cannot be published: ${error instanceof Error ? error.message : String(error)}`
1533
+ );
1534
+ }
1478
1535
  }
1479
1536
  function isZodSchemaLike(value) {
1480
1537
  return typeof value === "object" && value !== null && typeof value.safeParse === "function";
@@ -2140,13 +2197,14 @@ function normalizeWebSocketRouteRegistration(path, handler, opts, existingRoutes
2140
2197
  }
2141
2198
  return { path, auth };
2142
2199
  }
2143
- function normalizeRpcRegistration(contract, handlers, registered) {
2200
+ function normalizeRpcRegistration(contract, handlers, registered, options) {
2144
2201
  if (typeof contract !== "object" || contract === null || Array.isArray(contract)) {
2145
2202
  throw new Error("rpc.register contract must be an object");
2146
2203
  }
2147
2204
  if (typeof handlers !== "object" || handlers === null || Array.isArray(handlers)) {
2148
2205
  throw new Error("rpc.register handlers must be an object");
2149
2206
  }
2207
+ const publicationOptions = readRpcPublicationOptions(options);
2150
2208
  const pending = [];
2151
2209
  const contractEntries = Object.entries(contract);
2152
2210
  const contractNames = new Set(contractEntries.map(([name]) => name));
@@ -2174,6 +2232,7 @@ function normalizeRpcRegistration(contract, handlers, registered) {
2174
2232
  pending.push([
2175
2233
  name,
2176
2234
  {
2235
+ publication: publishRpcMethod(name, methodContract, publicationOptions),
2177
2236
  inputSchema: methodContract.input,
2178
2237
  outputSchema: methodContract.output,
2179
2238
  handler
@@ -3045,12 +3104,13 @@ function createFakePluginHostInternal(options, sharedState) {
3045
3104
  };
3046
3105
  const rpcHandlers = /* @__PURE__ */ new Map();
3047
3106
  const rpc = {
3048
- register(contract, handlers) {
3107
+ register(contract, handlers, registrationOptions) {
3049
3108
  assertLive();
3050
3109
  for (const [name, record] of normalizeRpcRegistration(
3051
3110
  contract,
3052
3111
  handlers,
3053
- rpcHandlers
3112
+ rpcHandlers,
3113
+ registrationOptions
3054
3114
  )) {
3055
3115
  rpcHandlers.set(name, record);
3056
3116
  }
@@ -3642,6 +3702,11 @@ function createFakePluginHostInternal(options, sharedState) {
3642
3702
  settingsDescriptors,
3643
3703
  httpRoutes,
3644
3704
  websocketRoutes,
3705
+ get experimental_publishedRpcMethods() {
3706
+ return [...rpcHandlers.values()].flatMap(
3707
+ (record) => record.publication === null ? [] : [record.publication]
3708
+ );
3709
+ },
3645
3710
  get rpcMethods() {
3646
3711
  return [...rpcHandlers.keys()];
3647
3712
  },
@@ -4251,6 +4316,7 @@ function makeMessageDispatchHookContext(overrides = {}) {
4251
4316
  },
4252
4317
  attempt: "start-turn",
4253
4318
  queuedMessage: null,
4319
+ experimental_submission: null,
4254
4320
  origin: null,
4255
4321
  originPluginId: null,
4256
4322
  startedOnBehalfOf: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@get-bb/plugin-sdk",
3
- "version": "0.4.88",
3
+ "version": "0.4.94",
4
4
  "homepage": "https://github.com/get-bb/bb#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/get-bb/bb/issues"