@get-bb/plugin-sdk 0.6.90 → 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 +105 -56
- 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 +1 -1
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +13 -2
- package/bundled-types/bb-plugin-sdk.d.ts +103 -55
- package/dist/app.js +4 -0
- package/dist/host.js +93 -1
- package/dist/internal/plugin-app-collector.js +29 -10
- package/dist/internal/rpc-query-host.js +69 -41
- package/dist/process.js +100 -3
- package/dist/provider-bridge-acp-next.js +118 -19
- package/dist/provider-bridge-acp.js +118 -19
- 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 +105 -54
- package/package.json +3 -3
|
@@ -80,7 +80,7 @@ var experimental_PluginRpcRefusal = class extends Error {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
// src/internal/rpc-query-host.ts
|
|
83
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2 } from "react";
|
|
83
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
84
84
|
import { useIsFetching } from "@tanstack/react-query";
|
|
85
85
|
|
|
86
86
|
// ../query-tags/src/index.ts
|
|
@@ -1089,11 +1089,16 @@ function createTaggedKeyedQueryOwner(options) {
|
|
|
1089
1089
|
registerKeyedView(client, queryKey, keyedRowsView(collection));
|
|
1090
1090
|
const keys = /* @__PURE__ */ new Map();
|
|
1091
1091
|
let readingKeys = /* @__PURE__ */ new Set();
|
|
1092
|
+
let collecting = false;
|
|
1092
1093
|
let missingOnly = false;
|
|
1093
1094
|
let refreshAll = false;
|
|
1094
1095
|
const dirtyKeys = /* @__PURE__ */ new Set();
|
|
1095
|
-
const
|
|
1096
|
-
queueMicrotask(() =>
|
|
1096
|
+
const takeSubscribedKeys = (take) => new Promise((resolve) => {
|
|
1097
|
+
queueMicrotask(() => {
|
|
1098
|
+
readingKeys = new Set(take([...keys.keys()]));
|
|
1099
|
+
collecting = false;
|
|
1100
|
+
resolve([...readingKeys]);
|
|
1101
|
+
});
|
|
1097
1102
|
});
|
|
1098
1103
|
const observer = new QueryObserver(client, {
|
|
1099
1104
|
queryKey,
|
|
@@ -1120,23 +1125,26 @@ function createTaggedKeyedQueryOwner(options) {
|
|
|
1120
1125
|
const refreshedKeys = /* @__PURE__ */ new Set();
|
|
1121
1126
|
let refreshedAll = false;
|
|
1122
1127
|
return runTaggedRead(client, queryKey, async () => {
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1128
|
+
collecting = true;
|
|
1129
|
+
let all = false;
|
|
1130
|
+
const requested = await takeSubscribedKeys((subscribed) => {
|
|
1131
|
+
all = refreshAll || refresh;
|
|
1132
|
+
refresh = false;
|
|
1133
|
+
const dirty = new Set(dirtyKeys);
|
|
1134
|
+
refreshedAll ||= all;
|
|
1135
|
+
if (all)
|
|
1136
|
+
for (const key of Object.keys(previous?.result ?? {}))
|
|
1137
|
+
dirtyKeys.add(key);
|
|
1138
|
+
refreshAll = false;
|
|
1139
|
+
const taken = subscribed.filter(
|
|
1140
|
+
(key) => all || dirty.has(key) || !Object.hasOwn(previous?.result ?? {}, key)
|
|
1141
|
+
);
|
|
1142
|
+
for (const key of taken) {
|
|
1143
|
+
refreshedKeys.add(key);
|
|
1144
|
+
dirtyKeys.delete(key);
|
|
1145
|
+
}
|
|
1146
|
+
return taken;
|
|
1147
|
+
});
|
|
1140
1148
|
const started = tick();
|
|
1141
1149
|
try {
|
|
1142
1150
|
const results = await Promise.all(
|
|
@@ -1192,13 +1200,15 @@ function createTaggedKeyedQueryOwner(options) {
|
|
|
1192
1200
|
let stop;
|
|
1193
1201
|
return {
|
|
1194
1202
|
observer,
|
|
1195
|
-
async
|
|
1203
|
+
async refresh(requested) {
|
|
1196
1204
|
const subscribed = requested.filter((key) => keys.has(key));
|
|
1197
1205
|
if (subscribed.length === 0) return;
|
|
1198
|
-
|
|
1199
|
-
|
|
1206
|
+
const fetching = observer.getCurrentQuery().state.fetchStatus === "fetching";
|
|
1207
|
+
const unread = fetching && !collecting ? subscribed.filter((key) => !readingKeys.has(key)) : subscribed;
|
|
1208
|
+
if (unread.length === 0) return;
|
|
1209
|
+
for (const key of unread) dirtyKeys.add(key);
|
|
1210
|
+
if (fetching && !collecting)
|
|
1200
1211
|
restartTaggedRead(observer.getCurrentQuery());
|
|
1201
|
-
}
|
|
1202
1212
|
await observer.refetch({ cancelRefetch: false });
|
|
1203
1213
|
},
|
|
1204
1214
|
subscribe(requested, listener) {
|
|
@@ -1220,7 +1230,7 @@ function createTaggedKeyedQueryOwner(options) {
|
|
|
1220
1230
|
}
|
|
1221
1231
|
if (added && pending.length > 0) {
|
|
1222
1232
|
if (observer.getCurrentResult().isFetching) {
|
|
1223
|
-
if (
|
|
1233
|
+
if (!collecting && pending.some((key) => !readingKeys.has(key)))
|
|
1224
1234
|
restartTaggedRead(observer.getCurrentQuery());
|
|
1225
1235
|
} else {
|
|
1226
1236
|
missingOnly = true;
|
|
@@ -2283,6 +2293,8 @@ var rpcQueryKey = (pluginId, method, input) => [
|
|
|
2283
2293
|
input
|
|
2284
2294
|
];
|
|
2285
2295
|
var keyedQueryKey = (pluginId, method) => rpcQueryKey(pluginId, method, { keyed: true });
|
|
2296
|
+
var keyListSchema = z19.array(z19.string());
|
|
2297
|
+
var jsonRecordSchema = z19.record(z19.string(), jsonValueSchema);
|
|
2286
2298
|
var keyedCollections = /* @__PURE__ */ new Map();
|
|
2287
2299
|
function keyedCollection(pluginId, method) {
|
|
2288
2300
|
const name = JSON.stringify([pluginId, method]);
|
|
@@ -2417,7 +2429,7 @@ function createRpcQueryHooks(useHost) {
|
|
|
2417
2429
|
const enabled = options.enabled ?? true;
|
|
2418
2430
|
const identity = JSON.stringify([...new Set(options.keys)].sort());
|
|
2419
2431
|
const keys = useMemo2(
|
|
2420
|
-
() =>
|
|
2432
|
+
() => keyListSchema.parse(JSON.parse(identity)),
|
|
2421
2433
|
[identity]
|
|
2422
2434
|
);
|
|
2423
2435
|
let cache = owners.get(host.queryClient);
|
|
@@ -2443,7 +2455,7 @@ function createRpcQueryHooks(useHost) {
|
|
|
2443
2455
|
);
|
|
2444
2456
|
return {
|
|
2445
2457
|
...response,
|
|
2446
|
-
result:
|
|
2458
|
+
result: jsonRecordSchema.parse(response.result)
|
|
2447
2459
|
};
|
|
2448
2460
|
}
|
|
2449
2461
|
});
|
|
@@ -2452,8 +2464,7 @@ function createRpcQueryHooks(useHost) {
|
|
|
2452
2464
|
const current = owner;
|
|
2453
2465
|
useSubscription(host, pluginId, enabled && keys.length > 0);
|
|
2454
2466
|
const subscribe = useCallback2(
|
|
2455
|
-
(listener) => enabled
|
|
2456
|
-
},
|
|
2467
|
+
(listener) => current.subscribe(enabled ? keys : [], listener),
|
|
2457
2468
|
[current, keys, enabled]
|
|
2458
2469
|
);
|
|
2459
2470
|
const getSnapshot = useCallback2(
|
|
@@ -2480,23 +2491,39 @@ function createRpcQueryHooks(useHost) {
|
|
|
2480
2491
|
[keys, enabled, selectRows]
|
|
2481
2492
|
);
|
|
2482
2493
|
const query = useQuerySelection(subscribe, getSnapshot, select);
|
|
2494
|
+
const watches = useMemo2(
|
|
2495
|
+
() => /* @__PURE__ */ new Map(),
|
|
2496
|
+
[host, pluginId, options.method]
|
|
2497
|
+
);
|
|
2498
|
+
useEffect2(
|
|
2499
|
+
() => () => {
|
|
2500
|
+
for (const release of watches.values()) release?.();
|
|
2501
|
+
watches.clear();
|
|
2502
|
+
},
|
|
2503
|
+
[watches]
|
|
2504
|
+
);
|
|
2483
2505
|
useEffect2(() => {
|
|
2484
|
-
|
|
2485
|
-
const
|
|
2486
|
-
(
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2506
|
+
const wanted = new Set(enabled ? keys : []);
|
|
2507
|
+
for (const [key, release] of watches) {
|
|
2508
|
+
if (wanted.has(key)) continue;
|
|
2509
|
+
release?.();
|
|
2510
|
+
watches.delete(key);
|
|
2511
|
+
}
|
|
2512
|
+
for (const key of wanted) {
|
|
2513
|
+
if (!watches.has(key))
|
|
2514
|
+
watches.set(key, host.watch?.(pluginId, options.method, { key }));
|
|
2515
|
+
}
|
|
2516
|
+
}, [host, pluginId, options.method, keys, enabled, watches]);
|
|
2517
|
+
const heldKeys = useRef2(keys);
|
|
2518
|
+
useEffect2(() => {
|
|
2519
|
+
heldKeys.current = keys;
|
|
2520
|
+
}, [keys]);
|
|
2492
2521
|
const refetch = useCallback2(async () => {
|
|
2493
|
-
await current.
|
|
2522
|
+
await current.refresh(heldKeys.current);
|
|
2494
2523
|
}, [current]);
|
|
2495
2524
|
const refetchKeys = useCallback2(
|
|
2496
2525
|
async (requested) => {
|
|
2497
|
-
await current.
|
|
2498
|
-
requested.filter((key) => keys.includes(key))
|
|
2499
|
-
);
|
|
2526
|
+
await current.refresh(requested.filter((key) => keys.includes(key)));
|
|
2500
2527
|
},
|
|
2501
2528
|
[current, keys]
|
|
2502
2529
|
);
|
|
@@ -2511,6 +2538,7 @@ function createRpcQueryHooks(useHost) {
|
|
|
2511
2538
|
const pluginId = resolvePluginId(host, options.pluginId);
|
|
2512
2539
|
const mutation = useTaggedMutation({
|
|
2513
2540
|
client: host.queryClient,
|
|
2541
|
+
meta: { showErrorToast: false },
|
|
2514
2542
|
invalidate: (tags) => invalidateTags(host.queryClient, pluginTagScope(pluginId), tags),
|
|
2515
2543
|
call: async (input) => {
|
|
2516
2544
|
const response = await callRpc(
|
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");
|
|
@@ -23612,7 +23702,9 @@ async function startAgentSession(request) {
|
|
|
23612
23702
|
providerThreadId: sessionId,
|
|
23613
23703
|
sessionRestorable: session.supportsLoadSession
|
|
23614
23704
|
});
|
|
23615
|
-
|
|
23705
|
+
if (request.kind !== "resume" || !request.continuesTurn) {
|
|
23706
|
+
sendThreadDeltas(bbThreadId, [{ kind: "session.reset" }]);
|
|
23707
|
+
}
|
|
23616
23708
|
publishSessionSnapshot(session);
|
|
23617
23709
|
if (createdFreshSession) {
|
|
23618
23710
|
emitGrokContextWindow(session, 0);
|
|
@@ -24017,12 +24109,7 @@ function runTurn(session, firstInput, turnAlreadyOpen = false) {
|
|
|
24017
24109
|
}
|
|
24018
24110
|
setActivePromptKind(session, "turn");
|
|
24019
24111
|
session.turnSettled = previousSession.turnSettled;
|
|
24020
|
-
|
|
24021
|
-
emitForSession(session, ACP_TURN_STARTED_METHOD, {
|
|
24022
|
-
threadId: session.bbThreadId
|
|
24023
|
-
});
|
|
24024
|
-
session.awaitingFirstPrompt = false;
|
|
24025
|
-
}
|
|
24112
|
+
session.awaitingFirstPrompt = false;
|
|
24026
24113
|
const prompt = buildPromptContentBlocks(session, pending.input);
|
|
24027
24114
|
let inputAccepted = false;
|
|
24028
24115
|
let busyRetries = 0;
|
|
@@ -24196,20 +24283,31 @@ async function rebuildAgentSession(session, construction) {
|
|
|
24196
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.";
|
|
24197
24284
|
const queuedInputs = session.queuedInputs.splice(0);
|
|
24198
24285
|
const continuingTurn = session.activePromptKind === "turn";
|
|
24199
|
-
|
|
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
|
+
}
|
|
24200
24295
|
let replacement;
|
|
24201
24296
|
try {
|
|
24202
24297
|
replacement = await startAgentSession({
|
|
24203
24298
|
kind: "resume",
|
|
24204
24299
|
params: construction,
|
|
24205
|
-
resumeProviderThreadId: previousProviderThreadId
|
|
24300
|
+
resumeProviderThreadId: previousProviderThreadId,
|
|
24301
|
+
continuesTurn: continuingTurn
|
|
24206
24302
|
});
|
|
24207
24303
|
} catch (error) {
|
|
24208
24304
|
if (continuingTurn) {
|
|
24209
|
-
|
|
24210
|
-
|
|
24211
|
-
|
|
24212
|
-
|
|
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);
|
|
24213
24311
|
}
|
|
24214
24312
|
throw error;
|
|
24215
24313
|
}
|
|
@@ -24620,7 +24718,8 @@ async function handleRequest2(request) {
|
|
|
24620
24718
|
request.method === "thread/resume" ? {
|
|
24621
24719
|
kind: "resume",
|
|
24622
24720
|
params: sessionParams,
|
|
24623
|
-
resumeProviderThreadId: request.params.providerThreadId
|
|
24721
|
+
resumeProviderThreadId: request.params.providerThreadId,
|
|
24722
|
+
continuesTurn: false
|
|
24624
24723
|
} : request.method === "thread/fork" ? {
|
|
24625
24724
|
kind: "fork",
|
|
24626
24725
|
params: sessionParams,
|