@get-bb/plugin-sdk 0.6.89 → 0.6.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 +157 -83
- package/bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts +14 -3
- package/bundled-types/bb-plugin-sdk-internal-rpc-query-host.d.ts +8 -1
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +18 -2
- package/bundled-types/bb-plugin-sdk.d.ts +152 -82
- package/dist/app.js +16 -0
- package/dist/host.js +93 -1
- package/dist/internal/plugin-app-collector.js +29 -10
- package/dist/internal/rpc-query-host.js +130 -84
- package/dist/process.js +100 -3
- package/dist/provider-bridge-acp-next.js +133 -22
- package/dist/provider-bridge-acp.js +133 -22
- package/dist/provider-bridge-testing.js +95 -5
- package/dist/provider-bridge-worker-entry.mjs +93 -1
- package/dist/provider-bridge.js +95 -5
- package/dist/testing/app.js +172 -97
- package/package.json +3 -3
package/dist/process.js
CHANGED
|
@@ -112,6 +112,97 @@ function whichCommandSync(command, options = {}) {
|
|
|
112
112
|
return void 0;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// ../process-utils/src/node-network.ts
|
|
116
|
+
var NODE_NETWORK_FLAGS = {
|
|
117
|
+
"--use-system-ca": "NODE_USE_SYSTEM_CA",
|
|
118
|
+
"--use-env-proxy": "NODE_USE_ENV_PROXY"
|
|
119
|
+
};
|
|
120
|
+
var ENV_PROXY_FLAG = "--use-env-proxy";
|
|
121
|
+
var PROXY_KEYS = /* @__PURE__ */ new Set(["HTTP_PROXY", "HTTPS_PROXY"]);
|
|
122
|
+
var NO_PROXY_KEY = "NO_PROXY";
|
|
123
|
+
var LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "::1", "[::1]"];
|
|
124
|
+
function isNodeNetworkFlag(arg) {
|
|
125
|
+
return Object.hasOwn(NODE_NETWORK_FLAGS, arg);
|
|
126
|
+
}
|
|
127
|
+
function isHttpProxyUrl(value) {
|
|
128
|
+
if (/[\r\n]/u.test(value)) return false;
|
|
129
|
+
try {
|
|
130
|
+
const url = new URL(value);
|
|
131
|
+
return (url.protocol === "http:" || url.protocol === "https:") && url.hostname !== "";
|
|
132
|
+
} catch {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function proxyEntries(env) {
|
|
137
|
+
return Object.entries(env).filter(
|
|
138
|
+
(entry) => PROXY_KEYS.has(entry[0].toUpperCase()) && entry[1] !== void 0 && entry[1] !== ""
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function appendLoopback(value) {
|
|
142
|
+
const entries = value.split(/[\s,]+/u).filter(Boolean);
|
|
143
|
+
if (entries.includes("*")) return value;
|
|
144
|
+
const present = new Set(entries.map((entry) => entry.toLowerCase()));
|
|
145
|
+
return [
|
|
146
|
+
...entries,
|
|
147
|
+
...LOOPBACK_HOSTS.filter((host) => !present.has(host))
|
|
148
|
+
].join(",");
|
|
149
|
+
}
|
|
150
|
+
function withLoopbackNoProxy(env) {
|
|
151
|
+
const result = { ...env };
|
|
152
|
+
const keys = Object.keys(result).filter(
|
|
153
|
+
(key) => key.toUpperCase() === NO_PROXY_KEY && result[key] !== void 0
|
|
154
|
+
);
|
|
155
|
+
for (const key of keys.length > 0 ? keys : [NO_PROXY_KEY])
|
|
156
|
+
result[key] = appendLoopback(result[key] ?? "");
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
function nodeNetworkLaunch(nodeArgs, env) {
|
|
160
|
+
const enabled = nodeArgs.filter(
|
|
161
|
+
(arg) => !isNodeNetworkFlag(arg) || env[NODE_NETWORK_FLAGS[arg]] !== "0"
|
|
162
|
+
);
|
|
163
|
+
if (!enabled.includes(ENV_PROXY_FLAG))
|
|
164
|
+
return { nodeArgs: enabled, env, rejectedProxyKeys: [] };
|
|
165
|
+
const proxies = proxyEntries(env);
|
|
166
|
+
const rejectedProxyKeys = proxies.filter(([, value]) => !isHttpProxyUrl(value)).map(([key]) => key);
|
|
167
|
+
if (rejectedProxyKeys.length > 0)
|
|
168
|
+
return {
|
|
169
|
+
nodeArgs: enabled.filter((arg) => arg !== ENV_PROXY_FLAG),
|
|
170
|
+
env,
|
|
171
|
+
rejectedProxyKeys
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
nodeArgs: enabled,
|
|
175
|
+
env: proxies.length > 0 ? withLoopbackNoProxy(env) : env,
|
|
176
|
+
rejectedProxyKeys: []
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
var warnedProxyKeys = /* @__PURE__ */ new Set();
|
|
180
|
+
function prepareNodeNetworkLaunch(nodeArgs, env) {
|
|
181
|
+
const launch = nodeNetworkLaunch(nodeArgs, env);
|
|
182
|
+
const unwarned = launch.rejectedProxyKeys.filter(
|
|
183
|
+
(key) => !warnedProxyKeys.has(key)
|
|
184
|
+
);
|
|
185
|
+
if (unwarned.length > 0) {
|
|
186
|
+
for (const key of unwarned) warnedProxyKeys.add(key);
|
|
187
|
+
process.emitWarning(
|
|
188
|
+
`bb started a Node process without --use-env-proxy because ${unwarned.join(", ")} is not an http:// or https:// URL. Add the scheme, for example http://proxy.example:3128, so bb uses the proxy.`,
|
|
189
|
+
{ code: "BB_INVALID_PROXY_ENV" }
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return { nodeArgs: launch.nodeArgs, env: launch.env };
|
|
193
|
+
}
|
|
194
|
+
function prepareNodeNetworkCommand(args, env) {
|
|
195
|
+
const scriptIndex = args.findIndex(
|
|
196
|
+
(arg) => arg === "--" || !arg.startsWith("-")
|
|
197
|
+
);
|
|
198
|
+
const optionCount = scriptIndex < 0 ? args.length : scriptIndex;
|
|
199
|
+
const launch = prepareNodeNetworkLaunch(args.slice(0, optionCount), env);
|
|
200
|
+
return {
|
|
201
|
+
args: [...launch.nodeArgs, ...args.slice(optionCount)],
|
|
202
|
+
env: launch.env
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
115
206
|
// ../process-utils/src/host-toolchain.ts
|
|
116
207
|
var NETWORK_KEYS = [
|
|
117
208
|
"HTTP_PROXY",
|
|
@@ -472,7 +563,8 @@ var HostToolchain = class {
|
|
|
472
563
|
if (/(?:^|[\\/])(?:npm|npx)-cli\.js$/u.test(args[0] ?? "")) {
|
|
473
564
|
env.PATH = mergePath(dirname(file), env.PATH);
|
|
474
565
|
}
|
|
475
|
-
|
|
566
|
+
const network = prepareNodeNetworkCommand(args, env);
|
|
567
|
+
return { command: file, args: network.args, env: network.env };
|
|
476
568
|
}
|
|
477
569
|
};
|
|
478
570
|
var toolchainKey = /* @__PURE__ */ Symbol.for("@bb/process-utils/host-toolchain");
|
|
@@ -497,9 +589,14 @@ function spawnHostProcess(command, args = [], options = {}) {
|
|
|
497
589
|
);
|
|
498
590
|
}
|
|
499
591
|
function forkHostProcess(modulePath, args = [], options = {}) {
|
|
500
|
-
const env =
|
|
592
|
+
const { nodeArgs: execArgv, env } = prepareNodeNetworkLaunch(
|
|
593
|
+
options.execArgv ?? process.execArgv,
|
|
594
|
+
hostToolchain.environment(options.env)
|
|
595
|
+
);
|
|
501
596
|
const execPath = options.execPath === void 0 || options.execPath === process.execPath ? hostToolchain.node({ env, cwd: options.cwd }) : options.execPath;
|
|
502
|
-
return observe(
|
|
597
|
+
return observe(
|
|
598
|
+
nodeFork(modulePath, args, { ...options, env, execArgv, execPath })
|
|
599
|
+
);
|
|
503
600
|
}
|
|
504
601
|
function prepareExecFile(command, args, options) {
|
|
505
602
|
const launch = hostToolchain.command(command, args, options);
|
|
@@ -3390,8 +3390,7 @@ var toolCallRequestParamsSchema = z28.object({
|
|
|
3390
3390
|
turnId: z28.union([z28.string().min(1), z28.null()]),
|
|
3391
3391
|
callId: z28.string().min(1),
|
|
3392
3392
|
tool: z28.string().min(1),
|
|
3393
|
-
arguments: z28.unknown()
|
|
3394
|
-
providerNativeIds: z28.boolean().optional()
|
|
3393
|
+
arguments: z28.unknown()
|
|
3395
3394
|
}).passthrough();
|
|
3396
3395
|
var toolCallResultSchema = z28.object({
|
|
3397
3396
|
success: z28.boolean(),
|
|
@@ -3409,8 +3408,7 @@ var interactionRequestParamsSchema = z28.object({
|
|
|
3409
3408
|
providerThreadId: z28.string().min(1),
|
|
3410
3409
|
threadId: z28.string().min(1).optional(),
|
|
3411
3410
|
turnId: z28.union([z28.string().min(1), z28.null()]),
|
|
3412
|
-
payload: pendingInteractionPayloadSchema
|
|
3413
|
-
providerNativeIds: z28.boolean().optional()
|
|
3411
|
+
payload: pendingInteractionPayloadSchema
|
|
3414
3412
|
}).passthrough();
|
|
3415
3413
|
|
|
3416
3414
|
// ../provider-bridge-protocol/src/thread-delta.ts
|
|
@@ -4501,6 +4499,97 @@ function whichCommandSync(command, options = {}) {
|
|
|
4501
4499
|
return void 0;
|
|
4502
4500
|
}
|
|
4503
4501
|
|
|
4502
|
+
// ../process-utils/src/node-network.ts
|
|
4503
|
+
var NODE_NETWORK_FLAGS = {
|
|
4504
|
+
"--use-system-ca": "NODE_USE_SYSTEM_CA",
|
|
4505
|
+
"--use-env-proxy": "NODE_USE_ENV_PROXY"
|
|
4506
|
+
};
|
|
4507
|
+
var ENV_PROXY_FLAG = "--use-env-proxy";
|
|
4508
|
+
var PROXY_KEYS = /* @__PURE__ */ new Set(["HTTP_PROXY", "HTTPS_PROXY"]);
|
|
4509
|
+
var NO_PROXY_KEY = "NO_PROXY";
|
|
4510
|
+
var LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "::1", "[::1]"];
|
|
4511
|
+
function isNodeNetworkFlag(arg) {
|
|
4512
|
+
return Object.hasOwn(NODE_NETWORK_FLAGS, arg);
|
|
4513
|
+
}
|
|
4514
|
+
function isHttpProxyUrl(value) {
|
|
4515
|
+
if (/[\r\n]/u.test(value)) return false;
|
|
4516
|
+
try {
|
|
4517
|
+
const url2 = new URL(value);
|
|
4518
|
+
return (url2.protocol === "http:" || url2.protocol === "https:") && url2.hostname !== "";
|
|
4519
|
+
} catch {
|
|
4520
|
+
return false;
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
function proxyEntries(env) {
|
|
4524
|
+
return Object.entries(env).filter(
|
|
4525
|
+
(entry) => PROXY_KEYS.has(entry[0].toUpperCase()) && entry[1] !== void 0 && entry[1] !== ""
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4528
|
+
function appendLoopback(value) {
|
|
4529
|
+
const entries = value.split(/[\s,]+/u).filter(Boolean);
|
|
4530
|
+
if (entries.includes("*")) return value;
|
|
4531
|
+
const present = new Set(entries.map((entry) => entry.toLowerCase()));
|
|
4532
|
+
return [
|
|
4533
|
+
...entries,
|
|
4534
|
+
...LOOPBACK_HOSTS.filter((host) => !present.has(host))
|
|
4535
|
+
].join(",");
|
|
4536
|
+
}
|
|
4537
|
+
function withLoopbackNoProxy(env) {
|
|
4538
|
+
const result = { ...env };
|
|
4539
|
+
const keys = Object.keys(result).filter(
|
|
4540
|
+
(key) => key.toUpperCase() === NO_PROXY_KEY && result[key] !== void 0
|
|
4541
|
+
);
|
|
4542
|
+
for (const key of keys.length > 0 ? keys : [NO_PROXY_KEY])
|
|
4543
|
+
result[key] = appendLoopback(result[key] ?? "");
|
|
4544
|
+
return result;
|
|
4545
|
+
}
|
|
4546
|
+
function nodeNetworkLaunch(nodeArgs, env) {
|
|
4547
|
+
const enabled = nodeArgs.filter(
|
|
4548
|
+
(arg) => !isNodeNetworkFlag(arg) || env[NODE_NETWORK_FLAGS[arg]] !== "0"
|
|
4549
|
+
);
|
|
4550
|
+
if (!enabled.includes(ENV_PROXY_FLAG))
|
|
4551
|
+
return { nodeArgs: enabled, env, rejectedProxyKeys: [] };
|
|
4552
|
+
const proxies = proxyEntries(env);
|
|
4553
|
+
const rejectedProxyKeys = proxies.filter(([, value]) => !isHttpProxyUrl(value)).map(([key]) => key);
|
|
4554
|
+
if (rejectedProxyKeys.length > 0)
|
|
4555
|
+
return {
|
|
4556
|
+
nodeArgs: enabled.filter((arg) => arg !== ENV_PROXY_FLAG),
|
|
4557
|
+
env,
|
|
4558
|
+
rejectedProxyKeys
|
|
4559
|
+
};
|
|
4560
|
+
return {
|
|
4561
|
+
nodeArgs: enabled,
|
|
4562
|
+
env: proxies.length > 0 ? withLoopbackNoProxy(env) : env,
|
|
4563
|
+
rejectedProxyKeys: []
|
|
4564
|
+
};
|
|
4565
|
+
}
|
|
4566
|
+
var warnedProxyKeys = /* @__PURE__ */ new Set();
|
|
4567
|
+
function prepareNodeNetworkLaunch(nodeArgs, env) {
|
|
4568
|
+
const launch = nodeNetworkLaunch(nodeArgs, env);
|
|
4569
|
+
const unwarned = launch.rejectedProxyKeys.filter(
|
|
4570
|
+
(key) => !warnedProxyKeys.has(key)
|
|
4571
|
+
);
|
|
4572
|
+
if (unwarned.length > 0) {
|
|
4573
|
+
for (const key of unwarned) warnedProxyKeys.add(key);
|
|
4574
|
+
process.emitWarning(
|
|
4575
|
+
`bb started a Node process without --use-env-proxy because ${unwarned.join(", ")} is not an http:// or https:// URL. Add the scheme, for example http://proxy.example:3128, so bb uses the proxy.`,
|
|
4576
|
+
{ code: "BB_INVALID_PROXY_ENV" }
|
|
4577
|
+
);
|
|
4578
|
+
}
|
|
4579
|
+
return { nodeArgs: launch.nodeArgs, env: launch.env };
|
|
4580
|
+
}
|
|
4581
|
+
function prepareNodeNetworkCommand(args, env) {
|
|
4582
|
+
const scriptIndex = args.findIndex(
|
|
4583
|
+
(arg) => arg === "--" || !arg.startsWith("-")
|
|
4584
|
+
);
|
|
4585
|
+
const optionCount = scriptIndex < 0 ? args.length : scriptIndex;
|
|
4586
|
+
const launch = prepareNodeNetworkLaunch(args.slice(0, optionCount), env);
|
|
4587
|
+
return {
|
|
4588
|
+
args: [...launch.nodeArgs, ...args.slice(optionCount)],
|
|
4589
|
+
env: launch.env
|
|
4590
|
+
};
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4504
4593
|
// ../process-utils/src/host-toolchain.ts
|
|
4505
4594
|
var NETWORK_KEYS = [
|
|
4506
4595
|
"HTTP_PROXY",
|
|
@@ -4861,7 +4950,8 @@ var HostToolchain = class {
|
|
|
4861
4950
|
if (/(?:^|[\\/])(?:npm|npx)-cli\.js$/u.test(args[0] ?? "")) {
|
|
4862
4951
|
env.PATH = mergePath(dirname(file), env.PATH);
|
|
4863
4952
|
}
|
|
4864
|
-
|
|
4953
|
+
const network = prepareNodeNetworkCommand(args, env);
|
|
4954
|
+
return { command: file, args: network.args, env: network.env };
|
|
4865
4955
|
}
|
|
4866
4956
|
};
|
|
4867
4957
|
var toolchainKey = /* @__PURE__ */ Symbol.for("@bb/process-utils/host-toolchain");
|
|
@@ -23325,6 +23415,12 @@ function dialectLaunchEnv(dialectId, permissionMode) {
|
|
|
23325
23415
|
})
|
|
23326
23416
|
};
|
|
23327
23417
|
}
|
|
23418
|
+
function additionalSessionDirectories(params, capabilities) {
|
|
23419
|
+
const directories = params.workspaceWriteRoots.filter(
|
|
23420
|
+
(root) => root !== params.cwd
|
|
23421
|
+
);
|
|
23422
|
+
return directories.length > 0 && capabilities.session.additionalDirectories ? { additionalDirectories: directories } : {};
|
|
23423
|
+
}
|
|
23328
23424
|
async function startAgentSession(request) {
|
|
23329
23425
|
const params = request.params;
|
|
23330
23426
|
const bbThreadId = params.threadId;
|
|
@@ -23489,7 +23585,8 @@ async function startAgentSession(request) {
|
|
|
23489
23585
|
params: {
|
|
23490
23586
|
sessionId: request.sourceProviderThreadId,
|
|
23491
23587
|
cwd: params.cwd,
|
|
23492
|
-
mcpServers
|
|
23588
|
+
mcpServers,
|
|
23589
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23493
23590
|
},
|
|
23494
23591
|
resultSchema: acpSessionForkResultSchema,
|
|
23495
23592
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
@@ -23515,7 +23612,8 @@ async function startAgentSession(request) {
|
|
|
23515
23612
|
params: {
|
|
23516
23613
|
sessionId: request.resumeProviderThreadId,
|
|
23517
23614
|
cwd: params.cwd,
|
|
23518
|
-
mcpServers
|
|
23615
|
+
mcpServers,
|
|
23616
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23519
23617
|
},
|
|
23520
23618
|
resultSchema: z49.union([acpConfigStateResultSchema, z49.null()]),
|
|
23521
23619
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
@@ -23542,7 +23640,11 @@ async function startAgentSession(request) {
|
|
|
23542
23640
|
session.pendingLoadUsageUpdate = void 0;
|
|
23543
23641
|
const newSession = await connection.request({
|
|
23544
23642
|
method: "session/new",
|
|
23545
|
-
params: {
|
|
23643
|
+
params: {
|
|
23644
|
+
cwd: params.cwd,
|
|
23645
|
+
mcpServers,
|
|
23646
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23647
|
+
},
|
|
23546
23648
|
resultSchema: acpSessionNewResultSchema,
|
|
23547
23649
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
23548
23650
|
});
|
|
@@ -23600,7 +23702,9 @@ async function startAgentSession(request) {
|
|
|
23600
23702
|
providerThreadId: sessionId,
|
|
23601
23703
|
sessionRestorable: session.supportsLoadSession
|
|
23602
23704
|
});
|
|
23603
|
-
|
|
23705
|
+
if (request.kind !== "resume" || !request.continuesTurn) {
|
|
23706
|
+
sendThreadDeltas(bbThreadId, [{ kind: "session.reset" }]);
|
|
23707
|
+
}
|
|
23604
23708
|
publishSessionSnapshot(session);
|
|
23605
23709
|
if (createdFreshSession) {
|
|
23606
23710
|
emitGrokContextWindow(session, 0);
|
|
@@ -24005,12 +24109,7 @@ function runTurn(session, firstInput, turnAlreadyOpen = false) {
|
|
|
24005
24109
|
}
|
|
24006
24110
|
setActivePromptKind(session, "turn");
|
|
24007
24111
|
session.turnSettled = previousSession.turnSettled;
|
|
24008
|
-
|
|
24009
|
-
emitForSession(session, ACP_TURN_STARTED_METHOD, {
|
|
24010
|
-
threadId: session.bbThreadId
|
|
24011
|
-
});
|
|
24012
|
-
session.awaitingFirstPrompt = false;
|
|
24013
|
-
}
|
|
24112
|
+
session.awaitingFirstPrompt = false;
|
|
24014
24113
|
const prompt = buildPromptContentBlocks(session, pending.input);
|
|
24015
24114
|
let inputAccepted = false;
|
|
24016
24115
|
let busyRetries = 0;
|
|
@@ -24184,20 +24283,31 @@ async function rebuildAgentSession(session, construction) {
|
|
|
24184
24283
|
const reason = session.connection.exited ? "The ACP agent exited unexpectedly; its session was rebuilt before continuing." : session.restartAfterCancelError ? "The ACP agent failed during cancellation; its session was rebuilt before continuing." : "Execution settings changed; the ACP session was rebuilt to apply them.";
|
|
24185
24284
|
const queuedInputs = session.queuedInputs.splice(0);
|
|
24186
24285
|
const continuingTurn = session.activePromptKind === "turn";
|
|
24187
|
-
|
|
24286
|
+
if (continuingTurn) {
|
|
24287
|
+
emitForSession(session, ACP_PROMPT_INTERRUPTED_METHOD, {
|
|
24288
|
+
threadId: session.bbThreadId
|
|
24289
|
+
});
|
|
24290
|
+
for (const controller of session.pendingToolCalls) controller.abort();
|
|
24291
|
+
setActivePromptKind(session, null);
|
|
24292
|
+
session.promptRequestPending = false;
|
|
24293
|
+
session.cancelRequested = false;
|
|
24294
|
+
}
|
|
24188
24295
|
let replacement;
|
|
24189
24296
|
try {
|
|
24190
24297
|
replacement = await startAgentSession({
|
|
24191
24298
|
kind: "resume",
|
|
24192
24299
|
params: construction,
|
|
24193
|
-
resumeProviderThreadId: previousProviderThreadId
|
|
24300
|
+
resumeProviderThreadId: previousProviderThreadId,
|
|
24301
|
+
continuesTurn: continuingTurn
|
|
24194
24302
|
});
|
|
24195
24303
|
} catch (error) {
|
|
24196
24304
|
if (continuingTurn) {
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24305
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
24306
|
+
emitForSession(session, "error", {
|
|
24307
|
+
threadId: session.bbThreadId,
|
|
24308
|
+
message
|
|
24309
|
+
});
|
|
24310
|
+
emitSessionError(session, message);
|
|
24201
24311
|
}
|
|
24202
24312
|
throw error;
|
|
24203
24313
|
}
|
|
@@ -24608,7 +24718,8 @@ async function handleRequest2(request) {
|
|
|
24608
24718
|
request.method === "thread/resume" ? {
|
|
24609
24719
|
kind: "resume",
|
|
24610
24720
|
params: sessionParams,
|
|
24611
|
-
resumeProviderThreadId: request.params.providerThreadId
|
|
24721
|
+
resumeProviderThreadId: request.params.providerThreadId,
|
|
24722
|
+
continuesTurn: false
|
|
24612
24723
|
} : request.method === "thread/fork" ? {
|
|
24613
24724
|
kind: "fork",
|
|
24614
24725
|
params: sessionParams,
|
|
@@ -3390,8 +3390,7 @@ var toolCallRequestParamsSchema = z28.object({
|
|
|
3390
3390
|
turnId: z28.union([z28.string().min(1), z28.null()]),
|
|
3391
3391
|
callId: z28.string().min(1),
|
|
3392
3392
|
tool: z28.string().min(1),
|
|
3393
|
-
arguments: z28.unknown()
|
|
3394
|
-
providerNativeIds: z28.boolean().optional()
|
|
3393
|
+
arguments: z28.unknown()
|
|
3395
3394
|
}).passthrough();
|
|
3396
3395
|
var toolCallResultSchema = z28.object({
|
|
3397
3396
|
success: z28.boolean(),
|
|
@@ -3409,8 +3408,7 @@ var interactionRequestParamsSchema = z28.object({
|
|
|
3409
3408
|
providerThreadId: z28.string().min(1),
|
|
3410
3409
|
threadId: z28.string().min(1).optional(),
|
|
3411
3410
|
turnId: z28.union([z28.string().min(1), z28.null()]),
|
|
3412
|
-
payload: pendingInteractionPayloadSchema
|
|
3413
|
-
providerNativeIds: z28.boolean().optional()
|
|
3411
|
+
payload: pendingInteractionPayloadSchema
|
|
3414
3412
|
}).passthrough();
|
|
3415
3413
|
|
|
3416
3414
|
// ../provider-bridge-protocol/src/thread-delta.ts
|
|
@@ -4501,6 +4499,97 @@ function whichCommandSync(command, options = {}) {
|
|
|
4501
4499
|
return void 0;
|
|
4502
4500
|
}
|
|
4503
4501
|
|
|
4502
|
+
// ../process-utils/src/node-network.ts
|
|
4503
|
+
var NODE_NETWORK_FLAGS = {
|
|
4504
|
+
"--use-system-ca": "NODE_USE_SYSTEM_CA",
|
|
4505
|
+
"--use-env-proxy": "NODE_USE_ENV_PROXY"
|
|
4506
|
+
};
|
|
4507
|
+
var ENV_PROXY_FLAG = "--use-env-proxy";
|
|
4508
|
+
var PROXY_KEYS = /* @__PURE__ */ new Set(["HTTP_PROXY", "HTTPS_PROXY"]);
|
|
4509
|
+
var NO_PROXY_KEY = "NO_PROXY";
|
|
4510
|
+
var LOOPBACK_HOSTS = ["localhost", "127.0.0.1", "::1", "[::1]"];
|
|
4511
|
+
function isNodeNetworkFlag(arg) {
|
|
4512
|
+
return Object.hasOwn(NODE_NETWORK_FLAGS, arg);
|
|
4513
|
+
}
|
|
4514
|
+
function isHttpProxyUrl(value) {
|
|
4515
|
+
if (/[\r\n]/u.test(value)) return false;
|
|
4516
|
+
try {
|
|
4517
|
+
const url2 = new URL(value);
|
|
4518
|
+
return (url2.protocol === "http:" || url2.protocol === "https:") && url2.hostname !== "";
|
|
4519
|
+
} catch {
|
|
4520
|
+
return false;
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
function proxyEntries(env) {
|
|
4524
|
+
return Object.entries(env).filter(
|
|
4525
|
+
(entry) => PROXY_KEYS.has(entry[0].toUpperCase()) && entry[1] !== void 0 && entry[1] !== ""
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4528
|
+
function appendLoopback(value) {
|
|
4529
|
+
const entries = value.split(/[\s,]+/u).filter(Boolean);
|
|
4530
|
+
if (entries.includes("*")) return value;
|
|
4531
|
+
const present = new Set(entries.map((entry) => entry.toLowerCase()));
|
|
4532
|
+
return [
|
|
4533
|
+
...entries,
|
|
4534
|
+
...LOOPBACK_HOSTS.filter((host) => !present.has(host))
|
|
4535
|
+
].join(",");
|
|
4536
|
+
}
|
|
4537
|
+
function withLoopbackNoProxy(env) {
|
|
4538
|
+
const result = { ...env };
|
|
4539
|
+
const keys = Object.keys(result).filter(
|
|
4540
|
+
(key) => key.toUpperCase() === NO_PROXY_KEY && result[key] !== void 0
|
|
4541
|
+
);
|
|
4542
|
+
for (const key of keys.length > 0 ? keys : [NO_PROXY_KEY])
|
|
4543
|
+
result[key] = appendLoopback(result[key] ?? "");
|
|
4544
|
+
return result;
|
|
4545
|
+
}
|
|
4546
|
+
function nodeNetworkLaunch(nodeArgs, env) {
|
|
4547
|
+
const enabled = nodeArgs.filter(
|
|
4548
|
+
(arg) => !isNodeNetworkFlag(arg) || env[NODE_NETWORK_FLAGS[arg]] !== "0"
|
|
4549
|
+
);
|
|
4550
|
+
if (!enabled.includes(ENV_PROXY_FLAG))
|
|
4551
|
+
return { nodeArgs: enabled, env, rejectedProxyKeys: [] };
|
|
4552
|
+
const proxies = proxyEntries(env);
|
|
4553
|
+
const rejectedProxyKeys = proxies.filter(([, value]) => !isHttpProxyUrl(value)).map(([key]) => key);
|
|
4554
|
+
if (rejectedProxyKeys.length > 0)
|
|
4555
|
+
return {
|
|
4556
|
+
nodeArgs: enabled.filter((arg) => arg !== ENV_PROXY_FLAG),
|
|
4557
|
+
env,
|
|
4558
|
+
rejectedProxyKeys
|
|
4559
|
+
};
|
|
4560
|
+
return {
|
|
4561
|
+
nodeArgs: enabled,
|
|
4562
|
+
env: proxies.length > 0 ? withLoopbackNoProxy(env) : env,
|
|
4563
|
+
rejectedProxyKeys: []
|
|
4564
|
+
};
|
|
4565
|
+
}
|
|
4566
|
+
var warnedProxyKeys = /* @__PURE__ */ new Set();
|
|
4567
|
+
function prepareNodeNetworkLaunch(nodeArgs, env) {
|
|
4568
|
+
const launch = nodeNetworkLaunch(nodeArgs, env);
|
|
4569
|
+
const unwarned = launch.rejectedProxyKeys.filter(
|
|
4570
|
+
(key) => !warnedProxyKeys.has(key)
|
|
4571
|
+
);
|
|
4572
|
+
if (unwarned.length > 0) {
|
|
4573
|
+
for (const key of unwarned) warnedProxyKeys.add(key);
|
|
4574
|
+
process.emitWarning(
|
|
4575
|
+
`bb started a Node process without --use-env-proxy because ${unwarned.join(", ")} is not an http:// or https:// URL. Add the scheme, for example http://proxy.example:3128, so bb uses the proxy.`,
|
|
4576
|
+
{ code: "BB_INVALID_PROXY_ENV" }
|
|
4577
|
+
);
|
|
4578
|
+
}
|
|
4579
|
+
return { nodeArgs: launch.nodeArgs, env: launch.env };
|
|
4580
|
+
}
|
|
4581
|
+
function prepareNodeNetworkCommand(args, env) {
|
|
4582
|
+
const scriptIndex = args.findIndex(
|
|
4583
|
+
(arg) => arg === "--" || !arg.startsWith("-")
|
|
4584
|
+
);
|
|
4585
|
+
const optionCount = scriptIndex < 0 ? args.length : scriptIndex;
|
|
4586
|
+
const launch = prepareNodeNetworkLaunch(args.slice(0, optionCount), env);
|
|
4587
|
+
return {
|
|
4588
|
+
args: [...launch.nodeArgs, ...args.slice(optionCount)],
|
|
4589
|
+
env: launch.env
|
|
4590
|
+
};
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4504
4593
|
// ../process-utils/src/host-toolchain.ts
|
|
4505
4594
|
var NETWORK_KEYS = [
|
|
4506
4595
|
"HTTP_PROXY",
|
|
@@ -4861,7 +4950,8 @@ var HostToolchain = class {
|
|
|
4861
4950
|
if (/(?:^|[\\/])(?:npm|npx)-cli\.js$/u.test(args[0] ?? "")) {
|
|
4862
4951
|
env.PATH = mergePath(dirname(file), env.PATH);
|
|
4863
4952
|
}
|
|
4864
|
-
|
|
4953
|
+
const network = prepareNodeNetworkCommand(args, env);
|
|
4954
|
+
return { command: file, args: network.args, env: network.env };
|
|
4865
4955
|
}
|
|
4866
4956
|
};
|
|
4867
4957
|
var toolchainKey = /* @__PURE__ */ Symbol.for("@bb/process-utils/host-toolchain");
|
|
@@ -23325,6 +23415,12 @@ function dialectLaunchEnv(dialectId, permissionMode) {
|
|
|
23325
23415
|
})
|
|
23326
23416
|
};
|
|
23327
23417
|
}
|
|
23418
|
+
function additionalSessionDirectories(params, capabilities) {
|
|
23419
|
+
const directories = params.workspaceWriteRoots.filter(
|
|
23420
|
+
(root) => root !== params.cwd
|
|
23421
|
+
);
|
|
23422
|
+
return directories.length > 0 && capabilities.session.additionalDirectories ? { additionalDirectories: directories } : {};
|
|
23423
|
+
}
|
|
23328
23424
|
async function startAgentSession(request) {
|
|
23329
23425
|
const params = request.params;
|
|
23330
23426
|
const bbThreadId = params.threadId;
|
|
@@ -23489,7 +23585,8 @@ async function startAgentSession(request) {
|
|
|
23489
23585
|
params: {
|
|
23490
23586
|
sessionId: request.sourceProviderThreadId,
|
|
23491
23587
|
cwd: params.cwd,
|
|
23492
|
-
mcpServers
|
|
23588
|
+
mcpServers,
|
|
23589
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23493
23590
|
},
|
|
23494
23591
|
resultSchema: acpSessionForkResultSchema,
|
|
23495
23592
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
@@ -23515,7 +23612,8 @@ async function startAgentSession(request) {
|
|
|
23515
23612
|
params: {
|
|
23516
23613
|
sessionId: request.resumeProviderThreadId,
|
|
23517
23614
|
cwd: params.cwd,
|
|
23518
|
-
mcpServers
|
|
23615
|
+
mcpServers,
|
|
23616
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23519
23617
|
},
|
|
23520
23618
|
resultSchema: z49.union([acpConfigStateResultSchema, z49.null()]),
|
|
23521
23619
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
@@ -23542,7 +23640,11 @@ async function startAgentSession(request) {
|
|
|
23542
23640
|
session.pendingLoadUsageUpdate = void 0;
|
|
23543
23641
|
const newSession = await connection.request({
|
|
23544
23642
|
method: "session/new",
|
|
23545
|
-
params: {
|
|
23643
|
+
params: {
|
|
23644
|
+
cwd: params.cwd,
|
|
23645
|
+
mcpServers,
|
|
23646
|
+
...additionalSessionDirectories(params, capabilities)
|
|
23647
|
+
},
|
|
23546
23648
|
resultSchema: acpSessionNewResultSchema,
|
|
23547
23649
|
timeoutMs: ACP_SESSION_SETUP_TIMEOUT_MS
|
|
23548
23650
|
});
|
|
@@ -23600,7 +23702,9 @@ async function startAgentSession(request) {
|
|
|
23600
23702
|
providerThreadId: sessionId,
|
|
23601
23703
|
sessionRestorable: session.supportsLoadSession
|
|
23602
23704
|
});
|
|
23603
|
-
|
|
23705
|
+
if (request.kind !== "resume" || !request.continuesTurn) {
|
|
23706
|
+
sendThreadDeltas(bbThreadId, [{ kind: "session.reset" }]);
|
|
23707
|
+
}
|
|
23604
23708
|
publishSessionSnapshot(session);
|
|
23605
23709
|
if (createdFreshSession) {
|
|
23606
23710
|
emitGrokContextWindow(session, 0);
|
|
@@ -24005,12 +24109,7 @@ function runTurn(session, firstInput, turnAlreadyOpen = false) {
|
|
|
24005
24109
|
}
|
|
24006
24110
|
setActivePromptKind(session, "turn");
|
|
24007
24111
|
session.turnSettled = previousSession.turnSettled;
|
|
24008
|
-
|
|
24009
|
-
emitForSession(session, ACP_TURN_STARTED_METHOD, {
|
|
24010
|
-
threadId: session.bbThreadId
|
|
24011
|
-
});
|
|
24012
|
-
session.awaitingFirstPrompt = false;
|
|
24013
|
-
}
|
|
24112
|
+
session.awaitingFirstPrompt = false;
|
|
24014
24113
|
const prompt = buildPromptContentBlocks(session, pending.input);
|
|
24015
24114
|
let inputAccepted = false;
|
|
24016
24115
|
let busyRetries = 0;
|
|
@@ -24184,20 +24283,31 @@ async function rebuildAgentSession(session, construction) {
|
|
|
24184
24283
|
const reason = session.connection.exited ? "The ACP agent exited unexpectedly; its session was rebuilt before continuing." : session.restartAfterCancelError ? "The ACP agent failed during cancellation; its session was rebuilt before continuing." : "Execution settings changed; the ACP session was rebuilt to apply them.";
|
|
24185
24284
|
const queuedInputs = session.queuedInputs.splice(0);
|
|
24186
24285
|
const continuingTurn = session.activePromptKind === "turn";
|
|
24187
|
-
|
|
24286
|
+
if (continuingTurn) {
|
|
24287
|
+
emitForSession(session, ACP_PROMPT_INTERRUPTED_METHOD, {
|
|
24288
|
+
threadId: session.bbThreadId
|
|
24289
|
+
});
|
|
24290
|
+
for (const controller of session.pendingToolCalls) controller.abort();
|
|
24291
|
+
setActivePromptKind(session, null);
|
|
24292
|
+
session.promptRequestPending = false;
|
|
24293
|
+
session.cancelRequested = false;
|
|
24294
|
+
}
|
|
24188
24295
|
let replacement;
|
|
24189
24296
|
try {
|
|
24190
24297
|
replacement = await startAgentSession({
|
|
24191
24298
|
kind: "resume",
|
|
24192
24299
|
params: construction,
|
|
24193
|
-
resumeProviderThreadId: previousProviderThreadId
|
|
24300
|
+
resumeProviderThreadId: previousProviderThreadId,
|
|
24301
|
+
continuesTurn: continuingTurn
|
|
24194
24302
|
});
|
|
24195
24303
|
} catch (error) {
|
|
24196
24304
|
if (continuingTurn) {
|
|
24197
|
-
|
|
24198
|
-
|
|
24199
|
-
|
|
24200
|
-
|
|
24305
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
24306
|
+
emitForSession(session, "error", {
|
|
24307
|
+
threadId: session.bbThreadId,
|
|
24308
|
+
message
|
|
24309
|
+
});
|
|
24310
|
+
emitSessionError(session, message);
|
|
24201
24311
|
}
|
|
24202
24312
|
throw error;
|
|
24203
24313
|
}
|
|
@@ -24608,7 +24718,8 @@ async function handleRequest2(request) {
|
|
|
24608
24718
|
request.method === "thread/resume" ? {
|
|
24609
24719
|
kind: "resume",
|
|
24610
24720
|
params: sessionParams,
|
|
24611
|
-
resumeProviderThreadId: request.params.providerThreadId
|
|
24721
|
+
resumeProviderThreadId: request.params.providerThreadId,
|
|
24722
|
+
continuesTurn: false
|
|
24612
24723
|
} : request.method === "thread/fork" ? {
|
|
24613
24724
|
kind: "fork",
|
|
24614
24725
|
params: sessionParams,
|