@get-bb/plugin-sdk 0.6.150 → 0.6.164
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/README.md +4 -1
- package/bundled-types/bb-plugin-sdk-app.d.ts +707 -86
- package/bundled-types/bb-plugin-sdk-environment-provider.d.ts +3 -0
- package/bundled-types/bb-plugin-sdk-host.d.ts +4 -1
- package/bundled-types/bb-plugin-sdk-internal-host-policy.d.ts +3 -0
- package/bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts +6 -3
- package/bundled-types/bb-plugin-sdk-internal-thread-event-gate.d.ts +1001 -0
- package/bundled-types/bb-plugin-sdk-provider-bridge-acp-next.d.ts +56 -6
- package/bundled-types/bb-plugin-sdk-provider-bridge-acp.d.ts +56 -6
- package/bundled-types/bb-plugin-sdk-provider-bridge.d.ts +45 -8
- package/bundled-types/bb-plugin-sdk-testing.d.ts +104 -20
- package/bundled-types/bb-plugin-sdk.d.ts +869 -300
- package/dist/app.js +8 -0
- package/dist/host.js +27 -3
- package/dist/index.js +19 -1
- package/dist/internal/host-policy.js +24 -2
- package/dist/internal/plugin-app-collector.js +20 -0
- package/dist/internal/rpc-query-host.js +1 -0
- package/dist/internal/thread-event-gate.js +95 -0
- package/dist/process.js +7 -1
- package/dist/provider-bridge-acp-next.js +503 -144
- package/dist/provider-bridge-acp.js +503 -144
- package/dist/provider-bridge-testing.js +21 -7
- package/dist/provider-bridge-worker-entry.mjs +9 -3
- package/dist/provider-bridge.js +124 -37
- package/dist/replay-provider-child.mjs +158 -31
- package/dist/testing/app.js +627 -347
- package/dist/testing/index.js +432 -77
- package/package.json +9 -1
package/dist/testing/index.js
CHANGED
|
@@ -329,6 +329,23 @@ var PLUGIN_INTERACTION_MAX_TITLE_LENGTH = 160;
|
|
|
329
329
|
var PLUGIN_INTERACTION_MAX_PAYLOAD_BYTES = 64 * 1024;
|
|
330
330
|
var PLUGIN_INTERACTION_MAX_TIMEOUT_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
331
331
|
|
|
332
|
+
// ../text-utils/src/utf16.ts
|
|
333
|
+
function isHighSurrogateAt(value, index) {
|
|
334
|
+
const code = value.charCodeAt(index);
|
|
335
|
+
return code >= 55296 && code <= 56319;
|
|
336
|
+
}
|
|
337
|
+
function isLowSurrogateAt(value, index) {
|
|
338
|
+
const code = value.charCodeAt(index);
|
|
339
|
+
return code >= 56320 && code <= 57343;
|
|
340
|
+
}
|
|
341
|
+
function sliceUtf16Head(value, maxChars) {
|
|
342
|
+
let end = Math.min(value.length, Math.max(0, maxChars));
|
|
343
|
+
if (isHighSurrogateAt(value, end - 1) && isLowSurrogateAt(value, end)) {
|
|
344
|
+
end -= 1;
|
|
345
|
+
}
|
|
346
|
+
return value.slice(0, end);
|
|
347
|
+
}
|
|
348
|
+
|
|
332
349
|
// ../domain/src/plugin-icon.ts
|
|
333
350
|
function isPluginOwnedIconPath(icon) {
|
|
334
351
|
return icon.startsWith("./");
|
|
@@ -2268,7 +2285,9 @@ function runPluginStorageMigrations(database, statements) {
|
|
|
2268
2285
|
if (!migrationColumns.some((column) => column.name === "statement_hash")) {
|
|
2269
2286
|
database.exec("ALTER TABLE _bb_migrations ADD COLUMN statement_hash TEXT");
|
|
2270
2287
|
}
|
|
2271
|
-
const rows = database.prepare(
|
|
2288
|
+
const rows = database.prepare(
|
|
2289
|
+
"SELECT id, statement_hash FROM _bb_migrations ORDER BY id"
|
|
2290
|
+
).all();
|
|
2272
2291
|
const applied = /* @__PURE__ */ new Map();
|
|
2273
2292
|
for (const row of rows) applied.set(row.id, row.statement_hash);
|
|
2274
2293
|
const statementHashes = statements.map(migrationStatementHash);
|
|
@@ -2398,8 +2417,8 @@ function normalizeRpcRegistration(contract, handlers, registered, options) {
|
|
|
2398
2417
|
}
|
|
2399
2418
|
return pending;
|
|
2400
2419
|
}
|
|
2401
|
-
function normalizeRealtimePayload(
|
|
2402
|
-
if (typeof
|
|
2420
|
+
function normalizeRealtimePayload(channel2, payload) {
|
|
2421
|
+
if (typeof channel2 !== "string" || channel2.length === 0) {
|
|
2403
2422
|
throw new Error("realtime channel must be a non-empty string");
|
|
2404
2423
|
}
|
|
2405
2424
|
if (payload === void 0) return null;
|
|
@@ -2411,7 +2430,7 @@ function normalizeRealtimePayload(channel, payload) {
|
|
|
2411
2430
|
}
|
|
2412
2431
|
if (json === void 0) {
|
|
2413
2432
|
throw new Error(
|
|
2414
|
-
`realtime payload for channel "${
|
|
2433
|
+
`realtime payload for channel "${channel2}" is not JSON-serializable`
|
|
2415
2434
|
);
|
|
2416
2435
|
}
|
|
2417
2436
|
return JSON.parse(json);
|
|
@@ -2821,7 +2840,10 @@ function normalizePluginAgentConfiguration(args) {
|
|
|
2821
2840
|
if (output.instructions !== void 0 && typeof output.instructions !== "string") {
|
|
2822
2841
|
throw new Error("configure() output.instructions must be a string");
|
|
2823
2842
|
}
|
|
2824
|
-
const instructions = typeof output.instructions === "string" && output.instructions.trim().length > 0 ?
|
|
2843
|
+
const instructions = typeof output.instructions === "string" && output.instructions.trim().length > 0 ? sliceUtf16Head(
|
|
2844
|
+
output.instructions,
|
|
2845
|
+
PLUGIN_DYNAMIC_INSTRUCTIONS_MAX_CHARS
|
|
2846
|
+
) : null;
|
|
2825
2847
|
const toolSelections = normalizePluginAgentToolSelections({
|
|
2826
2848
|
knownIds: args.knownToolIds,
|
|
2827
2849
|
pluginId: args.pluginId,
|
|
@@ -3041,6 +3063,10 @@ function createFakeSdk(options) {
|
|
|
3041
3063
|
`bb.sdk.${path} is not stubbed \u2014 pass an implementation via createFakePluginHost({ sdk: { ... } }) or harness.sdk.stub("${path}", fn)`
|
|
3042
3064
|
);
|
|
3043
3065
|
}
|
|
3066
|
+
const track = options.trackThreadCreation;
|
|
3067
|
+
if (track !== void 0 && (path === "threads.spawn" || path === "threads.fork")) {
|
|
3068
|
+
return track(async () => stub(...args));
|
|
3069
|
+
}
|
|
3044
3070
|
return stub(...args);
|
|
3045
3071
|
}
|
|
3046
3072
|
const nodes = /* @__PURE__ */ new Map();
|
|
@@ -3072,6 +3098,98 @@ function createFakeSdk(options) {
|
|
|
3072
3098
|
return { sdk: node(""), harness };
|
|
3073
3099
|
}
|
|
3074
3100
|
|
|
3101
|
+
// src/internal/thread-event-gate.ts
|
|
3102
|
+
function fromThread(thread) {
|
|
3103
|
+
return { threadId: thread.id, createdAt: thread.createdAt };
|
|
3104
|
+
}
|
|
3105
|
+
function fromThreadId(threadId) {
|
|
3106
|
+
return { threadId, createdAt: null };
|
|
3107
|
+
}
|
|
3108
|
+
var THREAD_OF_EVENT = {
|
|
3109
|
+
"experimental_environment.removed": () => null,
|
|
3110
|
+
"experimental_thread.events": ({ thread }) => fromThread(thread),
|
|
3111
|
+
"experimental_thread.parentChanged": ({ thread }) => fromThread(thread),
|
|
3112
|
+
"experimental_thread.read": ({ thread }) => fromThread(thread),
|
|
3113
|
+
"experimental_terminal.input": () => null,
|
|
3114
|
+
"experimental_host.deleted": () => null,
|
|
3115
|
+
"thread.created": ({ thread }) => fromThread(thread),
|
|
3116
|
+
"thread.active": ({ thread }) => fromThread(thread),
|
|
3117
|
+
"thread.idle": ({ thread }) => fromThread(thread),
|
|
3118
|
+
"thread.failed": ({ thread }) => fromThread(thread),
|
|
3119
|
+
"thread.archived": ({ thread }) => fromThread(thread),
|
|
3120
|
+
"thread.unarchived": ({ thread }) => fromThread(thread),
|
|
3121
|
+
"thread.deleted": ({ thread }) => fromThread(thread),
|
|
3122
|
+
"interaction.pending": ({ thread }) => fromThread(thread),
|
|
3123
|
+
"message.queued": ({ entry }) => fromThreadId(entry.threadId),
|
|
3124
|
+
"message.dispatched": ({ entry }) => fromThreadId(entry.threadId),
|
|
3125
|
+
"message.cancelled": ({ entry }) => fromThreadId(entry.threadId),
|
|
3126
|
+
"turn.failed": ({ threadId }) => fromThreadId(threadId),
|
|
3127
|
+
"experimental_thread.settled": ({ thread }) => fromThread(thread)
|
|
3128
|
+
};
|
|
3129
|
+
function threadOfEvent(event, payload) {
|
|
3130
|
+
const extract = THREAD_OF_EVENT[event];
|
|
3131
|
+
return extract(payload);
|
|
3132
|
+
}
|
|
3133
|
+
function createThreadEventGate(options = {}) {
|
|
3134
|
+
const now = options.now ?? Date.now;
|
|
3135
|
+
const schedule = options.schedule ?? ((run) => void setImmediate(run));
|
|
3136
|
+
const callsStartedAt = /* @__PURE__ */ new Map();
|
|
3137
|
+
let held = [];
|
|
3138
|
+
function createdDuringCall(createdAt) {
|
|
3139
|
+
if (createdAt === null) return false;
|
|
3140
|
+
for (const startedAt of callsStartedAt.values()) {
|
|
3141
|
+
if (startedAt <= createdAt) return true;
|
|
3142
|
+
}
|
|
3143
|
+
return false;
|
|
3144
|
+
}
|
|
3145
|
+
function release() {
|
|
3146
|
+
const pending = held;
|
|
3147
|
+
held = [];
|
|
3148
|
+
const stillHeld = /* @__PURE__ */ new Set();
|
|
3149
|
+
for (const entry of pending) {
|
|
3150
|
+
if (stillHeld.has(entry.threadId) || createdDuringCall(entry.createdAt)) {
|
|
3151
|
+
stillHeld.add(entry.threadId);
|
|
3152
|
+
held.push(entry);
|
|
3153
|
+
continue;
|
|
3154
|
+
}
|
|
3155
|
+
entry.deliver();
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
return {
|
|
3159
|
+
async track(call) {
|
|
3160
|
+
const token = /* @__PURE__ */ Symbol("thread-creating-call");
|
|
3161
|
+
callsStartedAt.set(token, now());
|
|
3162
|
+
try {
|
|
3163
|
+
return await call();
|
|
3164
|
+
} finally {
|
|
3165
|
+
callsStartedAt.delete(token);
|
|
3166
|
+
schedule(release);
|
|
3167
|
+
}
|
|
3168
|
+
},
|
|
3169
|
+
deliver(subject, deliver) {
|
|
3170
|
+
if (subject === null) {
|
|
3171
|
+
deliver();
|
|
3172
|
+
return;
|
|
3173
|
+
}
|
|
3174
|
+
const threadId = subject.threadId;
|
|
3175
|
+
if (held.some((entry) => entry.threadId === threadId)) {
|
|
3176
|
+
held.push({ threadId, createdAt: null, deliver });
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
if (callsStartedAt.size === 0) {
|
|
3180
|
+
deliver();
|
|
3181
|
+
return;
|
|
3182
|
+
}
|
|
3183
|
+
const createdAt = subject.createdAt();
|
|
3184
|
+
if (!createdDuringCall(createdAt)) {
|
|
3185
|
+
deliver();
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
3188
|
+
held.push({ threadId, createdAt, deliver });
|
|
3189
|
+
}
|
|
3190
|
+
};
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3075
3193
|
// src/testing/fake-plugin-host.ts
|
|
3076
3194
|
var PluginContextStaleError = class extends Error {
|
|
3077
3195
|
constructor(pluginId) {
|
|
@@ -3110,7 +3228,6 @@ function jsonRoundTrip(value, what) {
|
|
|
3110
3228
|
function throwRpcError(error) {
|
|
3111
3229
|
throw new experimental_PluginRpcCallError(error);
|
|
3112
3230
|
}
|
|
3113
|
-
var FAKE_TUNNEL_INGRESS_FIRST_PORT = 41e3;
|
|
3114
3231
|
var fakeHostDisposers = /* @__PURE__ */ new WeakMap();
|
|
3115
3232
|
function createFakePluginHost(options = {}) {
|
|
3116
3233
|
return createFakePluginHostInternal(options);
|
|
@@ -3322,11 +3439,11 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3322
3439
|
};
|
|
3323
3440
|
const realtimeSignals = [];
|
|
3324
3441
|
const realtime = {
|
|
3325
|
-
publish(
|
|
3442
|
+
publish(channel2, payload) {
|
|
3326
3443
|
assertLive();
|
|
3327
3444
|
realtimeSignals.push({
|
|
3328
|
-
channel,
|
|
3329
|
-
payload: normalizeRealtimePayload(
|
|
3445
|
+
channel: channel2,
|
|
3446
|
+
payload: normalizeRealtimePayload(channel2, payload)
|
|
3330
3447
|
});
|
|
3331
3448
|
}
|
|
3332
3449
|
};
|
|
@@ -3503,37 +3620,13 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3503
3620
|
get experimental_dataDir() {
|
|
3504
3621
|
assertLive();
|
|
3505
3622
|
return dataDir;
|
|
3506
|
-
},
|
|
3507
|
-
async internal_DO_NOT_USE_openTunnelIngress(ingressOptions) {
|
|
3508
|
-
assertLive();
|
|
3509
|
-
const audience = ingressOptions?.audience;
|
|
3510
|
-
if (typeof audience !== "string" || audience.length === 0) {
|
|
3511
|
-
throw new Error(
|
|
3512
|
-
"bb.server.internal_DO_NOT_USE_openTunnelIngress needs a non-empty audience"
|
|
3513
|
-
);
|
|
3514
|
-
}
|
|
3515
|
-
const shared = tunnelIngresses.find(
|
|
3516
|
-
(entry2) => entry2.audience === audience && !entry2.closed
|
|
3517
|
-
);
|
|
3518
|
-
const entry = {
|
|
3519
|
-
audience,
|
|
3520
|
-
baseUrl: shared?.baseUrl ?? `http://127.0.0.1:${FAKE_TUNNEL_INGRESS_FIRST_PORT + tunnelIngresses.length}`,
|
|
3521
|
-
closed: false
|
|
3522
|
-
};
|
|
3523
|
-
tunnelIngresses.push(entry);
|
|
3524
|
-
const close = async () => {
|
|
3525
|
-
entry.closed = true;
|
|
3526
|
-
const index = disposeHooks.indexOf(close);
|
|
3527
|
-
if (index !== -1) disposeHooks.splice(index, 1);
|
|
3528
|
-
};
|
|
3529
|
-
disposeHooks.push(close);
|
|
3530
|
-
return { baseUrl: entry.baseUrl, close };
|
|
3531
3623
|
}
|
|
3532
3624
|
};
|
|
3533
|
-
const
|
|
3625
|
+
const threadEventGate = createThreadEventGate();
|
|
3534
3626
|
const { sdk, harness: sdkHarness } = createFakeSdk({
|
|
3535
3627
|
pluginId,
|
|
3536
|
-
overrides: options.sdk
|
|
3628
|
+
overrides: options.sdk,
|
|
3629
|
+
trackThreadCreation: (call) => threadEventGate.track(call)
|
|
3537
3630
|
});
|
|
3538
3631
|
const threadEventHandlers = {
|
|
3539
3632
|
"experimental_thread.events": [],
|
|
@@ -3553,8 +3646,52 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3553
3646
|
"message.dispatched": [],
|
|
3554
3647
|
"turn.failed": [],
|
|
3555
3648
|
"message.cancelled": [],
|
|
3649
|
+
"experimental_thread.settled": [],
|
|
3556
3650
|
"thread.unarchived": []
|
|
3557
3651
|
};
|
|
3652
|
+
function deliverThreadEvent(event, payload) {
|
|
3653
|
+
const thread = threadOfEvent(event, payload);
|
|
3654
|
+
return new Promise((resolve2) => {
|
|
3655
|
+
threadEventGate.deliver(
|
|
3656
|
+
thread === null ? null : { threadId: thread.threadId, createdAt: () => thread.createdAt },
|
|
3657
|
+
() => {
|
|
3658
|
+
void (async () => {
|
|
3659
|
+
const errors = [];
|
|
3660
|
+
for (const handler of [...threadEventHandlers[event]]) {
|
|
3661
|
+
try {
|
|
3662
|
+
await handler(payload);
|
|
3663
|
+
} catch (error) {
|
|
3664
|
+
errors.push(error);
|
|
3665
|
+
emitLog(
|
|
3666
|
+
"warn",
|
|
3667
|
+
`${event} handler failed: ${errorMessage(error)}`
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
resolve2({ errors });
|
|
3672
|
+
})();
|
|
3673
|
+
}
|
|
3674
|
+
);
|
|
3675
|
+
});
|
|
3676
|
+
}
|
|
3677
|
+
function settledEventFor(event, payload) {
|
|
3678
|
+
const delivered = {
|
|
3679
|
+
[event]: payload
|
|
3680
|
+
};
|
|
3681
|
+
if (delivered["thread.idle"] !== void 0) {
|
|
3682
|
+
return { outcome: "completed", ...delivered["thread.idle"] };
|
|
3683
|
+
}
|
|
3684
|
+
if (delivered["thread.failed"] !== void 0) {
|
|
3685
|
+
return { outcome: "failed", ...delivered["thread.failed"] };
|
|
3686
|
+
}
|
|
3687
|
+
if (delivered["thread.archived"] !== void 0) {
|
|
3688
|
+
return { outcome: "archived", ...delivered["thread.archived"] };
|
|
3689
|
+
}
|
|
3690
|
+
if (delivered["thread.deleted"] !== void 0) {
|
|
3691
|
+
return { outcome: "deleted", ...delivered["thread.deleted"] };
|
|
3692
|
+
}
|
|
3693
|
+
return null;
|
|
3694
|
+
}
|
|
3558
3695
|
const hooks = {
|
|
3559
3696
|
"message.dispatch": null
|
|
3560
3697
|
};
|
|
@@ -3603,9 +3740,6 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3603
3740
|
});
|
|
3604
3741
|
}
|
|
3605
3742
|
const sharedPortDeclarations = [];
|
|
3606
|
-
let nextTunnelConfig = null;
|
|
3607
|
-
let nextTunnelStatuses = [];
|
|
3608
|
-
const nextTunnelListeners = /* @__PURE__ */ new Set();
|
|
3609
3743
|
const hostRpcCalls = [];
|
|
3610
3744
|
const hostWorkerExitSubscriptions = [];
|
|
3611
3745
|
const hostSignalSubscriptions = [];
|
|
@@ -3737,27 +3871,10 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3737
3871
|
} else {
|
|
3738
3872
|
sharedPortDeclarations[existingIndex] = replacement;
|
|
3739
3873
|
}
|
|
3740
|
-
},
|
|
3741
|
-
internal_DO_NOT_USE_setNextTunnels(config) {
|
|
3742
|
-
assertLive();
|
|
3743
|
-
nextTunnelConfig = config === null ? null : { domain: config.domain, server: { ...config.server } };
|
|
3744
|
-
},
|
|
3745
|
-
internal_DO_NOT_USE_nextTunnelStatuses() {
|
|
3746
|
-
assertLive();
|
|
3747
|
-
return structuredClone(nextTunnelStatuses);
|
|
3748
|
-
},
|
|
3749
|
-
internal_DO_NOT_USE_onNextTunnelStatusChange(listener) {
|
|
3750
|
-
assertLive();
|
|
3751
|
-
nextTunnelListeners.add(listener);
|
|
3752
|
-
return () => {
|
|
3753
|
-
nextTunnelListeners.delete(listener);
|
|
3754
|
-
};
|
|
3755
3874
|
}
|
|
3756
3875
|
};
|
|
3757
3876
|
disposeHooks.push(() => {
|
|
3758
3877
|
sharedPortDeclarations.length = 0;
|
|
3759
|
-
nextTunnelConfig = null;
|
|
3760
|
-
nextTunnelListeners.clear();
|
|
3761
3878
|
});
|
|
3762
3879
|
const events = {
|
|
3763
3880
|
on(event, handler) {
|
|
@@ -3983,15 +4100,7 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
3983
4100
|
get recheckCount() {
|
|
3984
4101
|
return requestedDrains;
|
|
3985
4102
|
},
|
|
3986
|
-
internal_DO_NOT_USE_tunnelIngresses: tunnelIngresses,
|
|
3987
4103
|
sharedPortDeclarations,
|
|
3988
|
-
get internal_DO_NOT_USE_nextTunnelConfig() {
|
|
3989
|
-
return nextTunnelConfig;
|
|
3990
|
-
},
|
|
3991
|
-
internal_DO_NOT_USE_setNextTunnelStatuses(statuses) {
|
|
3992
|
-
nextTunnelStatuses = structuredClone([...statuses]);
|
|
3993
|
-
for (const listener of [...nextTunnelListeners]) listener();
|
|
3994
|
-
},
|
|
3995
4104
|
experimental_hostRpcCalls: hostRpcCalls,
|
|
3996
4105
|
sdk: sdkHarness,
|
|
3997
4106
|
registrations: {
|
|
@@ -4037,6 +4146,7 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
4037
4146
|
"message.dispatched": threadEventHandlers["message.dispatched"].length,
|
|
4038
4147
|
"turn.failed": threadEventHandlers["turn.failed"].length,
|
|
4039
4148
|
"message.cancelled": threadEventHandlers["message.cancelled"].length,
|
|
4149
|
+
"experimental_thread.settled": threadEventHandlers["experimental_thread.settled"].length,
|
|
4040
4150
|
"thread.unarchived": threadEventHandlers["thread.unarchived"].length
|
|
4041
4151
|
};
|
|
4042
4152
|
},
|
|
@@ -4429,14 +4539,12 @@ function createFakePluginHostInternal(options, sharedState) {
|
|
|
4429
4539
|
await schedule.fn();
|
|
4430
4540
|
},
|
|
4431
4541
|
async emitThreadEvent(event, payload) {
|
|
4432
|
-
const errors =
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
emitLog("warn", `${event} handler failed: ${errorMessage(error)}`);
|
|
4439
|
-
}
|
|
4542
|
+
const { errors } = await deliverThreadEvent(event, payload);
|
|
4543
|
+
const settled = settledEventFor(event, payload);
|
|
4544
|
+
if (settled !== null) {
|
|
4545
|
+
errors.push(
|
|
4546
|
+
...(await deliverThreadEvent("experimental_thread.settled", settled)).errors
|
|
4547
|
+
);
|
|
4440
4548
|
}
|
|
4441
4549
|
return { errors };
|
|
4442
4550
|
},
|
|
@@ -5054,9 +5162,9 @@ function isPunct(token, value) {
|
|
|
5054
5162
|
function isName(token, value) {
|
|
5055
5163
|
return token?.kind === "name" && (value === void 0 || token.value === value);
|
|
5056
5164
|
}
|
|
5057
|
-
function closingIndex(tokens,
|
|
5165
|
+
function closingIndex(tokens, open2, opener, closer) {
|
|
5058
5166
|
let depth = 0;
|
|
5059
|
-
for (let index =
|
|
5167
|
+
for (let index = open2; index < tokens.length; index++) {
|
|
5060
5168
|
if (isPunct(tokens[index], opener)) depth++;
|
|
5061
5169
|
if (isPunct(tokens[index], closer) && --depth === 0) return index;
|
|
5062
5170
|
}
|
|
@@ -5120,11 +5228,11 @@ function moduleReferences(source, options) {
|
|
|
5120
5228
|
references.push({ specifier: argument.value, dynamic: false });
|
|
5121
5229
|
return;
|
|
5122
5230
|
}
|
|
5123
|
-
const
|
|
5231
|
+
const open2 = tokens[index + 1];
|
|
5124
5232
|
const closeToken = tokens[close];
|
|
5125
|
-
if (
|
|
5233
|
+
if (open2 === void 0 || closeToken === void 0) return;
|
|
5126
5234
|
references.push({
|
|
5127
|
-
specifier: source.slice(
|
|
5235
|
+
specifier: source.slice(open2.end, closeToken.start).trim(),
|
|
5128
5236
|
dynamic: true
|
|
5129
5237
|
});
|
|
5130
5238
|
return;
|
|
@@ -5219,12 +5327,259 @@ function scanPublicSdkOnly(packageRoot, options = {}) {
|
|
|
5219
5327
|
)
|
|
5220
5328
|
};
|
|
5221
5329
|
}
|
|
5330
|
+
|
|
5331
|
+
// ../test-helpers/src/child-processes.ts
|
|
5332
|
+
import { ChildProcess, execFile } from "node:child_process";
|
|
5333
|
+
import { randomBytes } from "node:crypto";
|
|
5334
|
+
import { channel } from "node:diagnostics_channel";
|
|
5335
|
+
import { mkdtemp, open, rm } from "node:fs/promises";
|
|
5336
|
+
import { createServer } from "node:net";
|
|
5337
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
5338
|
+
import { join as join3 } from "node:path";
|
|
5339
|
+
var POSIX_SOCKET_PATH_LIMIT = 100;
|
|
5340
|
+
function hasExited(child) {
|
|
5341
|
+
return child.exitCode !== null || child.signalCode !== null;
|
|
5342
|
+
}
|
|
5343
|
+
function waitForExit(child) {
|
|
5344
|
+
if (hasExited(child)) return Promise.resolve();
|
|
5345
|
+
return new Promise((resolveExit, rejectExit) => {
|
|
5346
|
+
const onExit = () => {
|
|
5347
|
+
child.off("error", onError);
|
|
5348
|
+
resolveExit();
|
|
5349
|
+
};
|
|
5350
|
+
const onError = (error) => {
|
|
5351
|
+
if (child.pid !== void 0) return;
|
|
5352
|
+
child.off("exit", onExit);
|
|
5353
|
+
rejectExit(error);
|
|
5354
|
+
};
|
|
5355
|
+
child.once("exit", onExit);
|
|
5356
|
+
child.on("error", onError);
|
|
5357
|
+
});
|
|
5358
|
+
}
|
|
5359
|
+
function trackChildProcesses() {
|
|
5360
|
+
const children = [];
|
|
5361
|
+
const closures = [];
|
|
5362
|
+
const childProcessChannel = channel("child_process");
|
|
5363
|
+
const onChildProcess = (message) => {
|
|
5364
|
+
if (typeof message === "object" && message !== null && "process" in message && message.process instanceof ChildProcess) {
|
|
5365
|
+
const child = message.process;
|
|
5366
|
+
children.push(child);
|
|
5367
|
+
closures.push(
|
|
5368
|
+
new Promise(
|
|
5369
|
+
(resolveClose) => child.once("close", () => resolveClose())
|
|
5370
|
+
)
|
|
5371
|
+
);
|
|
5372
|
+
}
|
|
5373
|
+
};
|
|
5374
|
+
childProcessChannel.subscribe(onChildProcess);
|
|
5375
|
+
const dispose = () => {
|
|
5376
|
+
childProcessChannel.unsubscribe(onChildProcess);
|
|
5377
|
+
};
|
|
5378
|
+
return {
|
|
5379
|
+
children,
|
|
5380
|
+
running: () => children.filter((child) => child.pid !== void 0 && !hasExited(child)),
|
|
5381
|
+
async waitForExit() {
|
|
5382
|
+
let pending = children.filter((child) => !hasExited(child));
|
|
5383
|
+
while (pending.length > 0) {
|
|
5384
|
+
await Promise.all(pending.map(waitForExit));
|
|
5385
|
+
pending = children.filter((child) => !hasExited(child));
|
|
5386
|
+
}
|
|
5387
|
+
},
|
|
5388
|
+
async waitForClose() {
|
|
5389
|
+
let waited = 0;
|
|
5390
|
+
while (waited < closures.length) {
|
|
5391
|
+
const pending = closures.slice(waited);
|
|
5392
|
+
waited = closures.length;
|
|
5393
|
+
await Promise.all(pending);
|
|
5394
|
+
}
|
|
5395
|
+
},
|
|
5396
|
+
killRunning(signal = "SIGKILL") {
|
|
5397
|
+
for (const child of children) {
|
|
5398
|
+
if (child.pid !== void 0 && !hasExited(child)) child.kill(signal);
|
|
5399
|
+
}
|
|
5400
|
+
},
|
|
5401
|
+
dispose,
|
|
5402
|
+
[Symbol.dispose]: dispose
|
|
5403
|
+
};
|
|
5404
|
+
}
|
|
5405
|
+
async function lifelinePath() {
|
|
5406
|
+
if (process.platform === "win32") {
|
|
5407
|
+
return {
|
|
5408
|
+
path: `\\\\.\\pipe\\bb-lifeline-${randomBytes(8).toString("hex")}`,
|
|
5409
|
+
cleanup: async () => {
|
|
5410
|
+
}
|
|
5411
|
+
};
|
|
5412
|
+
}
|
|
5413
|
+
const base = join3(tmpdir2(), "bb-lifeline-XXXXXX", "s").length < POSIX_SOCKET_PATH_LIMIT ? tmpdir2() : "/tmp";
|
|
5414
|
+
const directory = await mkdtemp(join3(base, "bb-lifeline-"));
|
|
5415
|
+
return {
|
|
5416
|
+
path: join3(directory, "s"),
|
|
5417
|
+
cleanup: () => rm(directory, { recursive: true, force: true })
|
|
5418
|
+
};
|
|
5419
|
+
}
|
|
5420
|
+
function parseHello(line) {
|
|
5421
|
+
try {
|
|
5422
|
+
const value = JSON.parse(line);
|
|
5423
|
+
if (typeof value === "object" && value !== null && "label" in value && "pid" in value && typeof value.label === "string" && typeof value.pid === "number" && Number.isSafeInteger(value.pid)) {
|
|
5424
|
+
return { label: value.label, pid: value.pid };
|
|
5425
|
+
}
|
|
5426
|
+
} catch {
|
|
5427
|
+
}
|
|
5428
|
+
return null;
|
|
5429
|
+
}
|
|
5430
|
+
async function createProcessLifeline() {
|
|
5431
|
+
const { path, cleanup } = await lifelinePath();
|
|
5432
|
+
const holders = [];
|
|
5433
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
5434
|
+
const waiters = /* @__PURE__ */ new Set();
|
|
5435
|
+
const notify = () => {
|
|
5436
|
+
for (const waiter of waiters) waiter();
|
|
5437
|
+
};
|
|
5438
|
+
const server = createServer((socket) => {
|
|
5439
|
+
sockets.add(socket);
|
|
5440
|
+
let buffered = "";
|
|
5441
|
+
let closed = false;
|
|
5442
|
+
let resolveExited = () => {
|
|
5443
|
+
};
|
|
5444
|
+
const exited = new Promise((resolvePromise) => {
|
|
5445
|
+
resolveExited = resolvePromise;
|
|
5446
|
+
});
|
|
5447
|
+
socket.setEncoding("utf8");
|
|
5448
|
+
socket.on("error", () => {
|
|
5449
|
+
});
|
|
5450
|
+
socket.on("close", () => {
|
|
5451
|
+
closed = true;
|
|
5452
|
+
sockets.delete(socket);
|
|
5453
|
+
resolveExited();
|
|
5454
|
+
});
|
|
5455
|
+
const onData = (chunk) => {
|
|
5456
|
+
buffered += chunk;
|
|
5457
|
+
const newline = buffered.indexOf("\n");
|
|
5458
|
+
if (newline === -1) return;
|
|
5459
|
+
socket.off("data", onData);
|
|
5460
|
+
const hello = parseHello(buffered.slice(0, newline));
|
|
5461
|
+
if (hello === null) {
|
|
5462
|
+
socket.destroy();
|
|
5463
|
+
return;
|
|
5464
|
+
}
|
|
5465
|
+
holders.push({
|
|
5466
|
+
label: hello.label,
|
|
5467
|
+
pid: hello.pid,
|
|
5468
|
+
exited,
|
|
5469
|
+
alive: () => !closed,
|
|
5470
|
+
kill(signal = "SIGKILL") {
|
|
5471
|
+
if (closed) return false;
|
|
5472
|
+
try {
|
|
5473
|
+
process.kill(hello.pid, signal);
|
|
5474
|
+
return true;
|
|
5475
|
+
} catch {
|
|
5476
|
+
return false;
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
});
|
|
5480
|
+
socket.write("held\n");
|
|
5481
|
+
notify();
|
|
5482
|
+
};
|
|
5483
|
+
socket.on("data", onData);
|
|
5484
|
+
});
|
|
5485
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
5486
|
+
server.once("error", rejectListen);
|
|
5487
|
+
server.listen(path, () => {
|
|
5488
|
+
server.off("error", rejectListen);
|
|
5489
|
+
resolveListen();
|
|
5490
|
+
});
|
|
5491
|
+
});
|
|
5492
|
+
server.unref();
|
|
5493
|
+
return {
|
|
5494
|
+
path,
|
|
5495
|
+
holders,
|
|
5496
|
+
holdSource(label, onHeld) {
|
|
5497
|
+
const afterWrite = onHeld === void 0 ? "s.unref();" : `s.once("data",()=>{s.unref();${onHeld}});`;
|
|
5498
|
+
return `{const s=process.getBuiltinModule("node:net").connect(${JSON.stringify(path)});s.on("error",()=>{});s.write(JSON.stringify({label:${JSON.stringify(label)},pid:process.pid})+"\\n");${afterWrite}}`;
|
|
5499
|
+
},
|
|
5500
|
+
waitForHolders(count) {
|
|
5501
|
+
if (holders.length >= count) return Promise.resolve(holders.slice());
|
|
5502
|
+
return new Promise((resolveHolders) => {
|
|
5503
|
+
const waiter = () => {
|
|
5504
|
+
if (holders.length < count) return;
|
|
5505
|
+
waiters.delete(waiter);
|
|
5506
|
+
resolveHolders(holders.slice());
|
|
5507
|
+
};
|
|
5508
|
+
waiters.add(waiter);
|
|
5509
|
+
});
|
|
5510
|
+
},
|
|
5511
|
+
async close() {
|
|
5512
|
+
for (const holder of holders) holder.kill("SIGKILL");
|
|
5513
|
+
await Promise.all(holders.map((holder) => holder.exited));
|
|
5514
|
+
for (const socket of sockets) socket.destroy();
|
|
5515
|
+
await new Promise(
|
|
5516
|
+
(resolveClose) => server.close(() => resolveClose())
|
|
5517
|
+
);
|
|
5518
|
+
await cleanup();
|
|
5519
|
+
}
|
|
5520
|
+
};
|
|
5521
|
+
}
|
|
5522
|
+
async function createDescendantPipe() {
|
|
5523
|
+
if (process.platform === "win32") {
|
|
5524
|
+
throw new Error("createDescendantPipe needs POSIX named pipes");
|
|
5525
|
+
}
|
|
5526
|
+
const directory = await mkdtemp(join3(tmpdir2(), "bb-descendant-pipe-"));
|
|
5527
|
+
const path = join3(directory, "pipe");
|
|
5528
|
+
await new Promise((resolveFifo, rejectFifo) => {
|
|
5529
|
+
execFile(
|
|
5530
|
+
"mkfifo",
|
|
5531
|
+
[path],
|
|
5532
|
+
(error) => error === null ? resolveFifo() : rejectFifo(error)
|
|
5533
|
+
);
|
|
5534
|
+
});
|
|
5535
|
+
const reader = open(path, "r");
|
|
5536
|
+
const closed = reader.then(
|
|
5537
|
+
(handle) => new Promise((resolveClosed, rejectClosed) => {
|
|
5538
|
+
const stream = handle.createReadStream();
|
|
5539
|
+
stream.on("error", rejectClosed);
|
|
5540
|
+
stream.on("close", () => resolveClosed());
|
|
5541
|
+
stream.resume();
|
|
5542
|
+
})
|
|
5543
|
+
);
|
|
5544
|
+
let isOpen = false;
|
|
5545
|
+
const opened = reader.then(() => {
|
|
5546
|
+
isOpen = true;
|
|
5547
|
+
});
|
|
5548
|
+
return {
|
|
5549
|
+
path,
|
|
5550
|
+
opened,
|
|
5551
|
+
closed,
|
|
5552
|
+
async dispose() {
|
|
5553
|
+
if (!isOpen) {
|
|
5554
|
+
const writer = await open(path, "w");
|
|
5555
|
+
await writer.close();
|
|
5556
|
+
}
|
|
5557
|
+
await closed.catch(() => {
|
|
5558
|
+
});
|
|
5559
|
+
await rm(directory, { recursive: true, force: true });
|
|
5560
|
+
}
|
|
5561
|
+
};
|
|
5562
|
+
}
|
|
5563
|
+
|
|
5564
|
+
// src/testing/processes.ts
|
|
5565
|
+
function experimental_trackChildProcesses() {
|
|
5566
|
+
return trackChildProcesses();
|
|
5567
|
+
}
|
|
5568
|
+
function experimental_createProcessLifeline() {
|
|
5569
|
+
return createProcessLifeline();
|
|
5570
|
+
}
|
|
5571
|
+
function experimental_createDescendantPipe() {
|
|
5572
|
+
return createDescendantPipe();
|
|
5573
|
+
}
|
|
5222
5574
|
export {
|
|
5223
5575
|
PluginContextStaleError,
|
|
5224
5576
|
createFakePluginHost,
|
|
5225
5577
|
createFakeSdk,
|
|
5578
|
+
experimental_createDescendantPipe,
|
|
5579
|
+
experimental_createProcessLifeline,
|
|
5226
5580
|
makePanelController as experimental_makePanelController,
|
|
5227
5581
|
scanPublicSdkOnly as experimental_scanPublicSdkOnly,
|
|
5582
|
+
experimental_trackChildProcesses,
|
|
5228
5583
|
makeHostResponse,
|
|
5229
5584
|
makeMessageDispatchHookContext,
|
|
5230
5585
|
makePluginAgentConfigurationContext,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@get-bb/plugin-sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.164",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/get-bb/bb#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -99,6 +99,12 @@
|
|
|
99
99
|
"import": "./dist/internal/thread-status.js",
|
|
100
100
|
"default": "./dist/internal/thread-status.js"
|
|
101
101
|
},
|
|
102
|
+
"./internal/thread-event-gate": {
|
|
103
|
+
"source": "./src/internal/thread-event-gate.ts",
|
|
104
|
+
"types": "./bundled-types/bb-plugin-sdk-internal-thread-event-gate.d.ts",
|
|
105
|
+
"import": "./dist/internal/thread-event-gate.js",
|
|
106
|
+
"default": "./dist/internal/thread-event-gate.js"
|
|
107
|
+
},
|
|
102
108
|
"./internal/file-navigation-validation": {
|
|
103
109
|
"source": "./src/internal/file-navigation-validation.ts",
|
|
104
110
|
"types": "./bundled-types/bb-plugin-sdk-internal-file-navigation-validation.d.ts",
|
|
@@ -179,6 +185,8 @@
|
|
|
179
185
|
"@bb/sdk": "workspace:*",
|
|
180
186
|
"@bb/server-contract": "workspace:*",
|
|
181
187
|
"@bb/skill-index": "workspace:*",
|
|
188
|
+
"@bb/test-helpers": "workspace:*",
|
|
189
|
+
"@bb/text-utils": "workspace:*",
|
|
182
190
|
"@bb/tsconfig": "workspace:*",
|
|
183
191
|
"@testing-library/react": "^16.3.3",
|
|
184
192
|
"@types/better-sqlite3": "^7.6.13",
|