@get-bb/plugin-sdk 0.6.43 → 0.6.49
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 +87 -21
- package/bundled-types/bb-plugin-sdk-internal-host-policy.d.ts +8 -0
- package/bundled-types/bb-plugin-sdk-provider-bridge-testing.d.ts +1 -0
- package/bundled-types/bb-plugin-sdk.d.ts +85 -20
- package/dist/app.js +3 -0
- package/dist/index.js +1 -0
- package/dist/provider-bridge-acp-next.js +6 -1
- package/dist/provider-bridge-acp.js +6 -1
- package/dist/provider-bridge-testing.js +132 -62
- package/dist/replay-provider-child.mjs +6 -3
- package/dist/testing/app.js +4 -0
- package/dist/testing/index.js +364 -18
- package/package.json +1 -1
|
@@ -17824,7 +17824,12 @@ async function handleModelList(id, params, dialectId) {
|
|
|
17824
17824
|
);
|
|
17825
17825
|
return;
|
|
17826
17826
|
}
|
|
17827
|
-
|
|
17827
|
+
if (params.listCommand) {
|
|
17828
|
+
throw new Error(
|
|
17829
|
+
"ACP model list command failed to provide a model catalog."
|
|
17830
|
+
);
|
|
17831
|
+
}
|
|
17832
|
+
const sessionDiscoveredModels = params.agent ? await loadSessionDiscoveredModels(
|
|
17828
17833
|
params.agent,
|
|
17829
17834
|
params.reasoningProbePriorityModelIds,
|
|
17830
17835
|
params.parameterizedModelPicker
|
|
@@ -2634,6 +2634,7 @@ function asTextDeltaEvent(event) {
|
|
|
2634
2634
|
return void 0;
|
|
2635
2635
|
}
|
|
2636
2636
|
}
|
|
2637
|
+
var TEXT_DELTA_FLUSH_MS = 50;
|
|
2637
2638
|
var SEP = THREAD_DELTA_KEY_SEPARATOR;
|
|
2638
2639
|
function itemKeyString(key) {
|
|
2639
2640
|
return [
|
|
@@ -2663,7 +2664,7 @@ function trimOldestEntries(map, max) {
|
|
|
2663
2664
|
function createDeltaAssembler(options) {
|
|
2664
2665
|
const entropyPrefix = options.entropyPrefix ?? `da${randomUUID().slice(0, 8)}`;
|
|
2665
2666
|
const progressThrottleMs = options.progressThrottleMs ?? 500;
|
|
2666
|
-
const textDeltaFlushMs = options.textDeltaFlushMs ??
|
|
2667
|
+
const textDeltaFlushMs = options.textDeltaFlushMs ?? TEXT_DELTA_FLUSH_MS;
|
|
2667
2668
|
const now = options.now ?? Date.now;
|
|
2668
2669
|
let turnCounter = 0;
|
|
2669
2670
|
let itemCounter = 0;
|
|
@@ -2696,8 +2697,8 @@ function createDeltaAssembler(options) {
|
|
|
2696
2697
|
settledItemKeys: /* @__PURE__ */ new Set(),
|
|
2697
2698
|
progressLastEmitByKey: /* @__PURE__ */ new Map(),
|
|
2698
2699
|
pendingProgressByKey: /* @__PURE__ */ new Map(),
|
|
2699
|
-
|
|
2700
|
-
|
|
2700
|
+
pendingTextByStream: /* @__PURE__ */ new Map(),
|
|
2701
|
+
pendingTextTimer: void 0
|
|
2701
2702
|
};
|
|
2702
2703
|
states.set(threadId, created);
|
|
2703
2704
|
pruneIdleStates();
|
|
@@ -2760,59 +2761,67 @@ function createDeltaAssembler(options) {
|
|
|
2760
2761
|
}
|
|
2761
2762
|
}
|
|
2762
2763
|
function flushPendingText(state, out) {
|
|
2763
|
-
if (state.
|
|
2764
|
-
|
|
2764
|
+
if (state.pendingTextTimer !== void 0) {
|
|
2765
|
+
clearTimeout(state.pendingTextTimer);
|
|
2766
|
+
state.pendingTextTimer = void 0;
|
|
2765
2767
|
}
|
|
2766
|
-
const
|
|
2767
|
-
for (const [streamKey, pending] of state.pendingTextByStream) {
|
|
2768
|
+
for (const pending of state.pendingTextByStream.values()) {
|
|
2768
2769
|
out.push({ ...pending.event, delta: pending.text });
|
|
2769
|
-
state.textLastEmitByStream.set(streamKey, nowMs);
|
|
2770
2770
|
}
|
|
2771
2771
|
state.pendingTextByStream.clear();
|
|
2772
|
-
trimOldestEntries(state.textLastEmitByStream, MAX_ID_MAP_ENTRIES);
|
|
2773
2772
|
}
|
|
2774
2773
|
function flushElapsedPendingText(state, out) {
|
|
2775
2774
|
const nowMs = now();
|
|
2776
|
-
for (const
|
|
2777
|
-
|
|
2778
|
-
if (last === void 0 || nowMs - last >= textDeltaFlushMs) {
|
|
2775
|
+
for (const pending of state.pendingTextByStream.values()) {
|
|
2776
|
+
if (nowMs - pending.openedAt >= textDeltaFlushMs) {
|
|
2779
2777
|
flushPendingText(state, out);
|
|
2780
2778
|
return;
|
|
2781
2779
|
}
|
|
2782
2780
|
}
|
|
2783
2781
|
}
|
|
2784
|
-
function
|
|
2785
|
-
const
|
|
2786
|
-
if (
|
|
2787
|
-
flushPendingText(state, out);
|
|
2788
|
-
out.push(event);
|
|
2789
|
-
state.textLastEmitByStream.set(streamKey, now());
|
|
2790
|
-
trimOldestEntries(state.textLastEmitByStream, MAX_ID_MAP_ENTRIES);
|
|
2782
|
+
function schedulePendingTextFlush(threadId, state) {
|
|
2783
|
+
const onDeferredEvents = options.onDeferredEvents;
|
|
2784
|
+
if (onDeferredEvents === void 0 || state.pendingTextTimer !== void 0) {
|
|
2791
2785
|
return;
|
|
2792
2786
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
trimOldestEntries(state.textLastEmitByStream, MAX_ID_MAP_ENTRIES);
|
|
2787
|
+
let openedAt = Number.POSITIVE_INFINITY;
|
|
2788
|
+
for (const pending of state.pendingTextByStream.values()) {
|
|
2789
|
+
openedAt = Math.min(openedAt, pending.openedAt);
|
|
2790
|
+
}
|
|
2791
|
+
if (openedAt === Number.POSITIVE_INFINITY) {
|
|
2799
2792
|
return;
|
|
2800
2793
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2794
|
+
state.pendingTextTimer = setTimeout(
|
|
2795
|
+
() => {
|
|
2796
|
+
state.pendingTextTimer = void 0;
|
|
2797
|
+
const events = [];
|
|
2798
|
+
flushPendingText(state, events);
|
|
2799
|
+
if (events.length > 0) {
|
|
2800
|
+
onDeferredEvents(threadId, events);
|
|
2801
|
+
}
|
|
2802
|
+
},
|
|
2803
|
+
Math.max(0, openedAt + textDeltaFlushMs - now())
|
|
2804
|
+
);
|
|
2805
|
+
state.pendingTextTimer.unref?.();
|
|
2806
|
+
}
|
|
2807
|
+
function bufferTextDelta(state, event, out) {
|
|
2808
|
+
if (event.type === "item/commandExecution/outputDelta" && event.reset === true) {
|
|
2808
2809
|
flushPendingText(state, out);
|
|
2810
|
+
out.push(event);
|
|
2809
2811
|
return;
|
|
2810
2812
|
}
|
|
2813
|
+
const streamKey = `${event.type}${SEP}${event.itemId}`;
|
|
2814
|
+
const pending = state.pendingTextByStream.get(streamKey);
|
|
2811
2815
|
if (pending === void 0) {
|
|
2812
|
-
state.pendingTextByStream.set(streamKey, {
|
|
2813
|
-
|
|
2816
|
+
state.pendingTextByStream.set(streamKey, {
|
|
2817
|
+
event,
|
|
2818
|
+
openedAt: now(),
|
|
2819
|
+
text: event.delta
|
|
2820
|
+
});
|
|
2821
|
+
} else {
|
|
2822
|
+
pending.text += event.delta;
|
|
2814
2823
|
}
|
|
2815
|
-
|
|
2824
|
+
flushElapsedPendingText(state, out);
|
|
2816
2825
|
}
|
|
2817
2826
|
function rememberSettledKey(state, key) {
|
|
2818
2827
|
state.settledItemKeys.add(key);
|
|
@@ -4193,13 +4202,13 @@ function createDeltaAssembler(options) {
|
|
|
4193
4202
|
push: (...newEvents) => {
|
|
4194
4203
|
for (const event of newEvents) {
|
|
4195
4204
|
const textDelta = textDeltaFlushMs > 0 ? asTextDeltaEvent(event) : void 0;
|
|
4196
|
-
const
|
|
4197
|
-
if (textDelta !== void 0 &&
|
|
4198
|
-
bufferTextDelta(
|
|
4205
|
+
const state2 = states.get(args.threadId);
|
|
4206
|
+
if (textDelta !== void 0 && state2 !== void 0) {
|
|
4207
|
+
bufferTextDelta(state2, textDelta, events);
|
|
4199
4208
|
continue;
|
|
4200
4209
|
}
|
|
4201
|
-
if (
|
|
4202
|
-
flushPendingText(
|
|
4210
|
+
if (state2 !== void 0) {
|
|
4211
|
+
flushPendingText(state2, events);
|
|
4203
4212
|
}
|
|
4204
4213
|
events.push(event);
|
|
4205
4214
|
}
|
|
@@ -4218,21 +4227,19 @@ function createDeltaAssembler(options) {
|
|
|
4218
4227
|
}
|
|
4219
4228
|
for (const delta of args.deltas) {
|
|
4220
4229
|
if (delta.kind === "session.reset") {
|
|
4221
|
-
const
|
|
4222
|
-
if (
|
|
4223
|
-
flushPendingText(
|
|
4230
|
+
const state2 = states.get(args.threadId);
|
|
4231
|
+
if (state2 !== void 0) {
|
|
4232
|
+
flushPendingText(state2, events);
|
|
4224
4233
|
}
|
|
4225
4234
|
states.delete(args.threadId);
|
|
4226
4235
|
continue;
|
|
4227
4236
|
}
|
|
4228
|
-
if (delta.kind === "item.textClose" || delta.kind === "item.close" || delta.kind === "session.ended") {
|
|
4229
|
-
const state = states.get(args.threadId);
|
|
4230
|
-
if (state !== void 0) {
|
|
4231
|
-
flushPendingText(state, events);
|
|
4232
|
-
}
|
|
4233
|
-
}
|
|
4234
4237
|
handleDelta(stateFor(args.threadId), delta, sink);
|
|
4235
4238
|
}
|
|
4239
|
+
const state = states.get(args.threadId);
|
|
4240
|
+
if (state !== void 0) {
|
|
4241
|
+
schedulePendingTextFlush(args.threadId, state);
|
|
4242
|
+
}
|
|
4236
4243
|
return events;
|
|
4237
4244
|
},
|
|
4238
4245
|
getBbItemId(threadId, providerItemId) {
|
|
@@ -6609,6 +6616,17 @@ var REPLAY_CHILD_PATH = fileURLToPath2(
|
|
|
6609
6616
|
new URL("./replay-provider-child.mjs", import.meta.url)
|
|
6610
6617
|
);
|
|
6611
6618
|
var PARITY_INITIALIZE_ID = "parity-initialize";
|
|
6619
|
+
var BRIDGE_EXIT_STDERR_TAIL_CHARS = 2e3;
|
|
6620
|
+
function describeBridgeExit(child) {
|
|
6621
|
+
if (child.pid === void 0) return "never started";
|
|
6622
|
+
if (child.signalCode !== null) return `signal ${child.signalCode}`;
|
|
6623
|
+
return `code ${String(child.exitCode)}`;
|
|
6624
|
+
}
|
|
6625
|
+
function stderrTail(stderr) {
|
|
6626
|
+
const trimmed = stderr.trim();
|
|
6627
|
+
if (trimmed === "") return "; no stderr";
|
|
6628
|
+
return `; stderr: ${trimmed.slice(-BRIDGE_EXIT_STDERR_TAIL_CHARS)}`;
|
|
6629
|
+
}
|
|
6612
6630
|
function sleep(ms) {
|
|
6613
6631
|
return new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
|
|
6614
6632
|
}
|
|
@@ -6632,7 +6650,20 @@ async function acquireReplayStartup() {
|
|
|
6632
6650
|
else next();
|
|
6633
6651
|
};
|
|
6634
6652
|
}
|
|
6653
|
+
var BRIDGE_STARTUP_ATTEMPTS = 2;
|
|
6635
6654
|
async function replayRecording(options) {
|
|
6655
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
6656
|
+
const { run, crashedBeforeInitialize } = await replayRecordingAttempt(options);
|
|
6657
|
+
if (!crashedBeforeInitialize || attempt >= BRIDGE_STARTUP_ATTEMPTS) {
|
|
6658
|
+
return run;
|
|
6659
|
+
}
|
|
6660
|
+
process.stderr.write(
|
|
6661
|
+
`parity replay of ${options.recordingDir}: retrying after a bridge startup crash: ${run.stalls.join("; ")}
|
|
6662
|
+
`
|
|
6663
|
+
);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
async function replayRecordingAttempt(options) {
|
|
6636
6667
|
const timeoutMs = options.timeoutMs ?? 15e3;
|
|
6637
6668
|
const orderTimeoutMs = options.orderTimeoutMs ?? 5e3;
|
|
6638
6669
|
const settleMs = options.settleMs ?? 750;
|
|
@@ -6749,6 +6780,7 @@ async function replayRecording(options) {
|
|
|
6749
6780
|
providerId
|
|
6750
6781
|
).events.length : null;
|
|
6751
6782
|
const answeredIds = /* @__PURE__ */ new Set();
|
|
6783
|
+
const sentRequestIds = [];
|
|
6752
6784
|
const pendingBridgeRequests = [];
|
|
6753
6785
|
const recordedAnswers = /* @__PURE__ */ new Map();
|
|
6754
6786
|
for (const step of steps) {
|
|
@@ -6825,15 +6857,33 @@ async function replayRecording(options) {
|
|
|
6825
6857
|
stalls.push(`oversized bridge line (${bytes} bytes)`);
|
|
6826
6858
|
}
|
|
6827
6859
|
});
|
|
6860
|
+
let reportedBridgeExit = false;
|
|
6828
6861
|
async function waitFor(label, predicate, limitMs = timeoutMs, reportStall = true) {
|
|
6862
|
+
const diagnostic = () => JSON.stringify({
|
|
6863
|
+
events: events.length,
|
|
6864
|
+
plannedEvents: plannedEventCount,
|
|
6865
|
+
grammarViolationCount: grammarViolations.length,
|
|
6866
|
+
grammarViolations: grammarViolations.slice(-5),
|
|
6867
|
+
unansweredRequests: sentRequestIds.filter(
|
|
6868
|
+
(id) => !answeredIds.has(id)
|
|
6869
|
+
),
|
|
6870
|
+
exitCode: child.exitCode,
|
|
6871
|
+
signal: child.signalCode,
|
|
6872
|
+
millisecondsSinceOutput: Date.now() - lastOutputAt,
|
|
6873
|
+
stderrTail: stderr.slice(-2e3)
|
|
6874
|
+
});
|
|
6829
6875
|
const deadline = Date.now() + limitMs;
|
|
6830
6876
|
while (!predicate()) {
|
|
6831
6877
|
if (child.exitCode !== null || child.signalCode !== null || child.pid === void 0) {
|
|
6832
|
-
stalls.push(
|
|
6878
|
+
stalls.push(
|
|
6879
|
+
`bridge exited (${describeBridgeExit(child)}) while waiting for ${label}${reportedBridgeExit ? "" : stderrTail(stderr)}: ${diagnostic()}`
|
|
6880
|
+
);
|
|
6881
|
+
reportedBridgeExit = true;
|
|
6833
6882
|
return;
|
|
6834
6883
|
}
|
|
6835
6884
|
if (Date.now() > deadline) {
|
|
6836
|
-
if (reportStall)
|
|
6885
|
+
if (reportStall)
|
|
6886
|
+
stalls.push(`timed out waiting for ${label}: ${diagnostic()}`);
|
|
6837
6887
|
return;
|
|
6838
6888
|
}
|
|
6839
6889
|
await sleep(10);
|
|
@@ -6858,13 +6908,30 @@ async function replayRecording(options) {
|
|
|
6858
6908
|
);
|
|
6859
6909
|
await waitFor("initialize response", () => answeredIds.has(initializeId));
|
|
6860
6910
|
const initialized = answeredIds.has(initializeId);
|
|
6911
|
+
const crashedBeforeInitialize = !initialized && (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null);
|
|
6861
6912
|
if (!initialized) {
|
|
6862
6913
|
if (child.pid !== void 0 && child.exitCode === null && child.signalCode === null)
|
|
6863
6914
|
child.kill("SIGKILL");
|
|
6864
6915
|
await childEnded;
|
|
6865
6916
|
}
|
|
6866
6917
|
releaseStartup();
|
|
6867
|
-
|
|
6918
|
+
if (crashedBeforeInitialize) {
|
|
6919
|
+
return {
|
|
6920
|
+
run: {
|
|
6921
|
+
providerId,
|
|
6922
|
+
recordingDir: options.recordingDir,
|
|
6923
|
+
lines,
|
|
6924
|
+
lineTimes,
|
|
6925
|
+
lineAfter,
|
|
6926
|
+
events,
|
|
6927
|
+
grammarViolations,
|
|
6928
|
+
stalls,
|
|
6929
|
+
stderr,
|
|
6930
|
+
exitCode: child.exitCode
|
|
6931
|
+
},
|
|
6932
|
+
crashedBeforeInitialize
|
|
6933
|
+
};
|
|
6934
|
+
}
|
|
6868
6935
|
for (const step of initialized ? steps : []) {
|
|
6869
6936
|
if (step.message === null || !isRequest(step.message)) {
|
|
6870
6937
|
if (step.message !== null && !isResponse(step.message)) {
|
|
@@ -6955,16 +7022,19 @@ async function replayRecording(options) {
|
|
|
6955
7022
|
]);
|
|
6956
7023
|
clearTimeout(shutdownTimer);
|
|
6957
7024
|
return {
|
|
6958
|
-
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
6962
|
-
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
7025
|
+
run: {
|
|
7026
|
+
providerId,
|
|
7027
|
+
recordingDir: options.recordingDir,
|
|
7028
|
+
lines,
|
|
7029
|
+
lineTimes,
|
|
7030
|
+
lineAfter,
|
|
7031
|
+
events,
|
|
7032
|
+
grammarViolations,
|
|
7033
|
+
stalls,
|
|
7034
|
+
stderr,
|
|
7035
|
+
exitCode
|
|
7036
|
+
},
|
|
7037
|
+
crashedBeforeInitialize: false
|
|
6968
7038
|
};
|
|
6969
7039
|
} finally {
|
|
6970
7040
|
if (spawnedChild !== void 0 && spawnedChild.pid !== void 0 && spawnedChild.exitCode === null && spawnedChild.signalCode === null) {
|
|
@@ -281,16 +281,19 @@ function readCursor(stateDir) {
|
|
|
281
281
|
let text;
|
|
282
282
|
try {
|
|
283
283
|
text = readFileSync(join(stateDir, "cursor"), "utf8").trim();
|
|
284
|
-
} catch {
|
|
285
|
-
return null;
|
|
284
|
+
} catch (error) {
|
|
285
|
+
return error?.code === "ENOENT" ? null : false;
|
|
286
286
|
}
|
|
287
|
-
if (text === "end"
|
|
287
|
+
if (text === "end") return null;
|
|
288
|
+
if (!/^\d+ \d+$/u.test(text)) return false;
|
|
288
289
|
const [run, seq] = text.split(" ").map(Number);
|
|
290
|
+
if (!Number.isSafeInteger(run) || !Number.isSafeInteger(seq)) return false;
|
|
289
291
|
return { run, seq };
|
|
290
292
|
}
|
|
291
293
|
|
|
292
294
|
function cursorAllows(cursor, entry) {
|
|
293
295
|
if (cursor === null) return true;
|
|
296
|
+
if (cursor === false) return false;
|
|
294
297
|
return entry.run < cursor.run || (entry.run === cursor.run && entry.seq < cursor.seq);
|
|
295
298
|
}
|
|
296
299
|
|
package/dist/testing/app.js
CHANGED
|
@@ -960,6 +960,7 @@ function normalizeExperimentalFileOpenOptions(value) {
|
|
|
960
960
|
// src/thread-action-groups.ts
|
|
961
961
|
var experimental_THREAD_ACTION_GROUPS = {
|
|
962
962
|
open: "1_open",
|
|
963
|
+
state: "1_state",
|
|
963
964
|
organize: "2_organize",
|
|
964
965
|
settings: "3_settings",
|
|
965
966
|
lifecycle: "4_lifecycle"
|
|
@@ -2517,6 +2518,9 @@ var testPluginSdkApp = {
|
|
|
2517
2518
|
experimental_copyToClipboard(content) {
|
|
2518
2519
|
return activeClipboard?.(content) ?? Promise.resolve(true);
|
|
2519
2520
|
},
|
|
2521
|
+
experimental_saveFile() {
|
|
2522
|
+
return Promise.resolve("started");
|
|
2523
|
+
},
|
|
2520
2524
|
experimental_useSidebarThreadActions() {
|
|
2521
2525
|
return useSlotEnv("experimental_useSidebarThreadActions").sidebarActions;
|
|
2522
2526
|
},
|