@get-bb/plugin-sdk 0.4.87 → 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.
- package/bundled-types/bb-plugin-sdk-app.d.ts +81 -31
- package/bundled-types/bb-plugin-sdk-host.d.ts +9 -0
- package/bundled-types/bb-plugin-sdk-internal-host-policy.d.ts +51 -2
- package/bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts +16 -3
- package/bundled-types/bb-plugin-sdk-provider-bridge-testing.d.ts +8 -0
- package/bundled-types/bb-plugin-sdk-provider-bridge.d.ts +10 -0
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +3 -4
- package/bundled-types/bb-plugin-sdk-testing.d.ts +27 -6
- package/bundled-types/bb-plugin-sdk.d.ts +171 -42
- package/dist/internal/host-policy.js +63 -2
- package/dist/internal/plugin-app-collector.js +13834 -22
- package/dist/provider-bridge-acp.js +384 -306
- package/dist/provider-bridge-testing.js +2 -0
- package/dist/provider-bridge.js +393 -377
- package/dist/testing/app.js +13987 -175
- package/dist/testing/index.js +70 -4
- package/package.json +1 -1
|
@@ -1421,6 +1421,11 @@ function isStandardSchema(value) {
|
|
|
1421
1421
|
const standard = Reflect.get(value, "~standard");
|
|
1422
1422
|
return typeof standard === "object" && standard !== null && Reflect.get(standard, "version") === 1 && typeof Reflect.get(standard, "vendor") === "string" && typeof Reflect.get(standard, "validate") === "function";
|
|
1423
1423
|
}
|
|
1424
|
+
var rpcDescriptionSchema = z4.string().trim().min(1).max(4096).optional().transform((value) => value ?? null);
|
|
1425
|
+
var rpcPublicationOptionsSchema = z4.object({
|
|
1426
|
+
experimental_discoverable: z4.boolean().default(false),
|
|
1427
|
+
experimental_description: rpcDescriptionSchema
|
|
1428
|
+
}).strict();
|
|
1424
1429
|
function readRpcMethodContract(method, value) {
|
|
1425
1430
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1426
1431
|
throw new Error(
|
|
@@ -1439,7 +1444,59 @@ function readRpcMethodContract(method, value) {
|
|
|
1439
1444
|
`rpc method "${method}" output must be a Standard Schema v1 validator`
|
|
1440
1445
|
);
|
|
1441
1446
|
}
|
|
1442
|
-
|
|
1447
|
+
const description = rpcDescriptionSchema.parse(
|
|
1448
|
+
Reflect.get(value, "experimental_description")
|
|
1449
|
+
);
|
|
1450
|
+
return description === null ? { input, output } : { input, output, experimental_description: description };
|
|
1451
|
+
}
|
|
1452
|
+
function readRpcPublicationOptions(value) {
|
|
1453
|
+
return rpcPublicationOptionsSchema.parse(value ?? {});
|
|
1454
|
+
}
|
|
1455
|
+
function publishedRpcSchema(schema, direction) {
|
|
1456
|
+
const converter = schema["~standard"].jsonSchema;
|
|
1457
|
+
if (converter === void 0 || typeof converter[direction] !== "function") {
|
|
1458
|
+
throw new Error(
|
|
1459
|
+
"discoverable RPC requires Standard JSON Schema export support"
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
const serialized = JSON.stringify(
|
|
1463
|
+
converter[direction]({ target: "draft-2020-12" })
|
|
1464
|
+
);
|
|
1465
|
+
if (serialized === void 0 || new TextEncoder().encode(serialized).byteLength > 128 * 1024) {
|
|
1466
|
+
throw new Error("published RPC schema must be JSON and at most 128 KiB");
|
|
1467
|
+
}
|
|
1468
|
+
const result = z4.record(z4.string(), jsonValueSchema).parse(JSON.parse(serialized));
|
|
1469
|
+
const inspect = (value) => {
|
|
1470
|
+
if (value === null || typeof value !== "object") return;
|
|
1471
|
+
if (Array.isArray(value)) {
|
|
1472
|
+
for (const item of value) inspect(item);
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
for (const [key, item] of Object.entries(value)) {
|
|
1476
|
+
if ((key === "$ref" || key === "$dynamicRef") && typeof item === "string" && !item.startsWith("#")) {
|
|
1477
|
+
throw new Error("published RPC schemas must use local references");
|
|
1478
|
+
}
|
|
1479
|
+
inspect(item);
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
inspect(result);
|
|
1483
|
+
return result;
|
|
1484
|
+
}
|
|
1485
|
+
function publishRpcMethod(method, contract, options) {
|
|
1486
|
+
if (!options.experimental_discoverable) return null;
|
|
1487
|
+
try {
|
|
1488
|
+
return {
|
|
1489
|
+
method,
|
|
1490
|
+
registrationDescription: options.experimental_description,
|
|
1491
|
+
methodDescription: contract.experimental_description ?? null,
|
|
1492
|
+
inputSchema: publishedRpcSchema(contract.input, "input"),
|
|
1493
|
+
outputSchema: publishedRpcSchema(contract.output, "output")
|
|
1494
|
+
};
|
|
1495
|
+
} catch (error) {
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
`rpc method "${method}" cannot be published: ${error instanceof Error ? error.message : String(error)}`
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1443
1500
|
}
|
|
1444
1501
|
function isZodSchemaLike(value) {
|
|
1445
1502
|
return typeof value === "object" && value !== null && typeof value.safeParse === "function";
|
|
@@ -2115,13 +2172,14 @@ function normalizeWebSocketRouteRegistration(path, handler, opts, existingRoutes
|
|
|
2115
2172
|
}
|
|
2116
2173
|
return { path, auth };
|
|
2117
2174
|
}
|
|
2118
|
-
function normalizeRpcRegistration(contract, handlers, registered) {
|
|
2175
|
+
function normalizeRpcRegistration(contract, handlers, registered, options) {
|
|
2119
2176
|
if (typeof contract !== "object" || contract === null || Array.isArray(contract)) {
|
|
2120
2177
|
throw new Error("rpc.register contract must be an object");
|
|
2121
2178
|
}
|
|
2122
2179
|
if (typeof handlers !== "object" || handlers === null || Array.isArray(handlers)) {
|
|
2123
2180
|
throw new Error("rpc.register handlers must be an object");
|
|
2124
2181
|
}
|
|
2182
|
+
const publicationOptions = readRpcPublicationOptions(options);
|
|
2125
2183
|
const pending = [];
|
|
2126
2184
|
const contractEntries = Object.entries(contract);
|
|
2127
2185
|
const contractNames = new Set(contractEntries.map(([name]) => name));
|
|
@@ -2149,6 +2207,7 @@ function normalizeRpcRegistration(contract, handlers, registered) {
|
|
|
2149
2207
|
pending.push([
|
|
2150
2208
|
name,
|
|
2151
2209
|
{
|
|
2210
|
+
publication: publishRpcMethod(name, methodContract, publicationOptions),
|
|
2152
2211
|
inputSchema: methodContract.input,
|
|
2153
2212
|
outputSchema: methodContract.output,
|
|
2154
2213
|
handler
|
|
@@ -2730,6 +2789,8 @@ export {
|
|
|
2730
2789
|
providerAlreadyRegisteredMessage,
|
|
2731
2790
|
providerIconRefusalMessage,
|
|
2732
2791
|
providerWithoutBridgeMessage,
|
|
2792
|
+
publishRpcMethod,
|
|
2793
|
+
readRpcPublicationOptions,
|
|
2733
2794
|
registerSettingDescriptors,
|
|
2734
2795
|
runPluginStorageMigrations,
|
|
2735
2796
|
storePluginHook,
|