@get-bb/plugin-sdk 0.4.14 → 0.4.16
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 +3 -3
- package/bundled-types/bb-plugin-sdk-ai-services.d.ts +141 -0
- package/bundled-types/bb-plugin-sdk-app.d.ts +144 -21
- package/bundled-types/bb-plugin-sdk-host.d.ts +479 -2
- package/bundled-types/bb-plugin-sdk-internal-composer-customization-validation.d.ts +10 -1
- package/bundled-types/bb-plugin-sdk-internal-host-policy.d.ts +339 -32
- package/bundled-types/bb-plugin-sdk-internal-plugin-app-collector.d.ts +2 -1
- package/bundled-types/bb-plugin-sdk-provider-bridge-acp.d.ts +807 -0
- package/bundled-types/bb-plugin-sdk-provider-bridge-testing.d.ts +1742 -211
- package/bundled-types/bb-plugin-sdk-provider-bridge.d.ts +2985 -2442
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +4 -3
- package/bundled-types/bb-plugin-sdk-testing.d.ts +551 -9
- package/bundled-types/bb-plugin-sdk.d.ts +1335 -1350
- package/dist/ai-services.js +91 -0
- package/dist/app.js +2 -2
- package/dist/host.js +14547 -1
- package/dist/internal/composer-customization-validation.js +11 -0
- package/dist/internal/host-policy.js +656 -91
- package/dist/internal/plugin-app-collector.js +58 -14
- package/dist/provider-bridge-acp.js +9753 -0
- package/dist/provider-bridge-testing.js +3355 -1771
- package/dist/provider-bridge-worker-entry.mjs +917 -0
- package/dist/provider-bridge.js +2255 -3718
- package/dist/replay-provider-child.mjs +650 -0
- package/dist/testing/app.js +63 -19
- package/dist/testing/index.js +803 -115
- package/package.json +14 -1
|
@@ -0,0 +1,917 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from "node:module";
|
|
2
|
+
import { dirname as __pathDirname } from "node:path";
|
|
3
|
+
import { fileURLToPath as __fileURLToPath } from "node:url";
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __pathDirname(__filename);
|
|
7
|
+
var __create = Object.create;
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
13
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
14
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
15
|
+
}) : x)(function(x) {
|
|
16
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
17
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
18
|
+
});
|
|
19
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
20
|
+
try {
|
|
21
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
throw mod = 0, e;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
|
|
44
|
+
var require_windows = __commonJS({
|
|
45
|
+
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
|
|
46
|
+
module.exports = isexe;
|
|
47
|
+
isexe.sync = sync;
|
|
48
|
+
var fs = __require("fs");
|
|
49
|
+
function checkPathExt(path, options) {
|
|
50
|
+
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
|
|
51
|
+
if (!pathext) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
pathext = pathext.split(";");
|
|
55
|
+
if (pathext.indexOf("") !== -1) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
for (var i = 0; i < pathext.length; i++) {
|
|
59
|
+
var p = pathext[i].toLowerCase();
|
|
60
|
+
if (p && path.substr(-p.length).toLowerCase() === p) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function checkStat(stat, path, options) {
|
|
67
|
+
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return checkPathExt(path, options);
|
|
71
|
+
}
|
|
72
|
+
function isexe(path, options, cb) {
|
|
73
|
+
fs.stat(path, function(er, stat) {
|
|
74
|
+
cb(er, er ? false : checkStat(stat, path, options));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function sync(path, options) {
|
|
78
|
+
return checkStat(fs.statSync(path), path, options);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
|
|
84
|
+
var require_mode = __commonJS({
|
|
85
|
+
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
|
|
86
|
+
module.exports = isexe;
|
|
87
|
+
isexe.sync = sync;
|
|
88
|
+
var fs = __require("fs");
|
|
89
|
+
function isexe(path, options, cb) {
|
|
90
|
+
fs.stat(path, function(er, stat) {
|
|
91
|
+
cb(er, er ? false : checkStat(stat, options));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function sync(path, options) {
|
|
95
|
+
return checkStat(fs.statSync(path), options);
|
|
96
|
+
}
|
|
97
|
+
function checkStat(stat, options) {
|
|
98
|
+
return stat.isFile() && checkMode(stat, options);
|
|
99
|
+
}
|
|
100
|
+
function checkMode(stat, options) {
|
|
101
|
+
var mod = stat.mode;
|
|
102
|
+
var uid = stat.uid;
|
|
103
|
+
var gid = stat.gid;
|
|
104
|
+
var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
|
|
105
|
+
var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
|
|
106
|
+
var u = parseInt("100", 8);
|
|
107
|
+
var g = parseInt("010", 8);
|
|
108
|
+
var o = parseInt("001", 8);
|
|
109
|
+
var ug = u | g;
|
|
110
|
+
var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
|
|
111
|
+
return ret;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
|
|
117
|
+
var require_isexe = __commonJS({
|
|
118
|
+
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
|
|
119
|
+
var fs = __require("fs");
|
|
120
|
+
var core;
|
|
121
|
+
if (process.platform === "win32" || global.TESTING_WINDOWS) {
|
|
122
|
+
core = require_windows();
|
|
123
|
+
} else {
|
|
124
|
+
core = require_mode();
|
|
125
|
+
}
|
|
126
|
+
module.exports = isexe;
|
|
127
|
+
isexe.sync = sync;
|
|
128
|
+
function isexe(path, options, cb) {
|
|
129
|
+
if (typeof options === "function") {
|
|
130
|
+
cb = options;
|
|
131
|
+
options = {};
|
|
132
|
+
}
|
|
133
|
+
if (!cb) {
|
|
134
|
+
if (typeof Promise !== "function") {
|
|
135
|
+
throw new TypeError("callback not provided");
|
|
136
|
+
}
|
|
137
|
+
return new Promise(function(resolve2, reject) {
|
|
138
|
+
isexe(path, options || {}, function(er, is) {
|
|
139
|
+
if (er) {
|
|
140
|
+
reject(er);
|
|
141
|
+
} else {
|
|
142
|
+
resolve2(is);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
core(path, options || {}, function(er, is) {
|
|
148
|
+
if (er) {
|
|
149
|
+
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
150
|
+
er = null;
|
|
151
|
+
is = false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
cb(er, is);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function sync(path, options) {
|
|
158
|
+
try {
|
|
159
|
+
return core.sync(path, options || {});
|
|
160
|
+
} catch (er) {
|
|
161
|
+
if (options && options.ignoreErrors || er.code === "EACCES") {
|
|
162
|
+
return false;
|
|
163
|
+
} else {
|
|
164
|
+
throw er;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
|
|
172
|
+
var require_which = __commonJS({
|
|
173
|
+
"../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
|
|
174
|
+
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
175
|
+
var path = __require("path");
|
|
176
|
+
var COLON = isWindows ? ";" : ":";
|
|
177
|
+
var isexe = require_isexe();
|
|
178
|
+
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
179
|
+
var getPathInfo = (cmd, opt) => {
|
|
180
|
+
const colon = opt.colon || COLON;
|
|
181
|
+
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
|
|
182
|
+
// windows always checks the cwd first
|
|
183
|
+
...isWindows ? [process.cwd()] : [],
|
|
184
|
+
...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
|
|
185
|
+
"").split(colon)
|
|
186
|
+
];
|
|
187
|
+
const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
|
|
188
|
+
const pathExt = isWindows ? pathExtExe.split(colon) : [""];
|
|
189
|
+
if (isWindows) {
|
|
190
|
+
if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
|
|
191
|
+
pathExt.unshift("");
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
pathEnv,
|
|
195
|
+
pathExt,
|
|
196
|
+
pathExtExe
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
var which = (cmd, opt, cb) => {
|
|
200
|
+
if (typeof opt === "function") {
|
|
201
|
+
cb = opt;
|
|
202
|
+
opt = {};
|
|
203
|
+
}
|
|
204
|
+
if (!opt)
|
|
205
|
+
opt = {};
|
|
206
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
207
|
+
const found = [];
|
|
208
|
+
const step = (i) => new Promise((resolve2, reject) => {
|
|
209
|
+
if (i === pathEnv.length)
|
|
210
|
+
return opt.all && found.length ? resolve2(found) : reject(getNotFoundError(cmd));
|
|
211
|
+
const ppRaw = pathEnv[i];
|
|
212
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
213
|
+
const pCmd = path.join(pathPart, cmd);
|
|
214
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
215
|
+
resolve2(subStep(p, i, 0));
|
|
216
|
+
});
|
|
217
|
+
const subStep = (p, i, ii) => new Promise((resolve2, reject) => {
|
|
218
|
+
if (ii === pathExt.length)
|
|
219
|
+
return resolve2(step(i + 1));
|
|
220
|
+
const ext = pathExt[ii];
|
|
221
|
+
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
222
|
+
if (!er && is) {
|
|
223
|
+
if (opt.all)
|
|
224
|
+
found.push(p + ext);
|
|
225
|
+
else
|
|
226
|
+
return resolve2(p + ext);
|
|
227
|
+
}
|
|
228
|
+
return resolve2(subStep(p, i, ii + 1));
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
232
|
+
};
|
|
233
|
+
var whichSync = (cmd, opt) => {
|
|
234
|
+
opt = opt || {};
|
|
235
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
236
|
+
const found = [];
|
|
237
|
+
for (let i = 0; i < pathEnv.length; i++) {
|
|
238
|
+
const ppRaw = pathEnv[i];
|
|
239
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
240
|
+
const pCmd = path.join(pathPart, cmd);
|
|
241
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
242
|
+
for (let j = 0; j < pathExt.length; j++) {
|
|
243
|
+
const cur = p + pathExt[j];
|
|
244
|
+
try {
|
|
245
|
+
const is = isexe.sync(cur, { pathExt: pathExtExe });
|
|
246
|
+
if (is) {
|
|
247
|
+
if (opt.all)
|
|
248
|
+
found.push(cur);
|
|
249
|
+
else
|
|
250
|
+
return cur;
|
|
251
|
+
}
|
|
252
|
+
} catch (ex) {
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (opt.all && found.length)
|
|
257
|
+
return found;
|
|
258
|
+
if (opt.nothrow)
|
|
259
|
+
return null;
|
|
260
|
+
throw getNotFoundError(cmd);
|
|
261
|
+
};
|
|
262
|
+
module.exports = which;
|
|
263
|
+
which.sync = whichSync;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
|
|
268
|
+
var require_path_key = __commonJS({
|
|
269
|
+
"../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports, module) {
|
|
270
|
+
"use strict";
|
|
271
|
+
var pathKey = (options = {}) => {
|
|
272
|
+
const environment = options.env || process.env;
|
|
273
|
+
const platform = options.platform || process.platform;
|
|
274
|
+
if (platform !== "win32") {
|
|
275
|
+
return "PATH";
|
|
276
|
+
}
|
|
277
|
+
return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
|
|
278
|
+
};
|
|
279
|
+
module.exports = pathKey;
|
|
280
|
+
module.exports.default = pathKey;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
285
|
+
var require_resolveCommand = __commonJS({
|
|
286
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
|
|
287
|
+
"use strict";
|
|
288
|
+
var path = __require("path");
|
|
289
|
+
var which = require_which();
|
|
290
|
+
var getPathKey = require_path_key();
|
|
291
|
+
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
292
|
+
const env = parsed.options.env || process.env;
|
|
293
|
+
const cwd = process.cwd();
|
|
294
|
+
const hasCustomCwd = parsed.options.cwd != null;
|
|
295
|
+
const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
|
|
296
|
+
if (shouldSwitchCwd) {
|
|
297
|
+
try {
|
|
298
|
+
process.chdir(parsed.options.cwd);
|
|
299
|
+
} catch (err) {
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
let resolved;
|
|
303
|
+
try {
|
|
304
|
+
resolved = which.sync(parsed.command, {
|
|
305
|
+
path: env[getPathKey({ env })],
|
|
306
|
+
pathExt: withoutPathExt ? path.delimiter : void 0
|
|
307
|
+
});
|
|
308
|
+
} catch (e) {
|
|
309
|
+
} finally {
|
|
310
|
+
if (shouldSwitchCwd) {
|
|
311
|
+
process.chdir(cwd);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (resolved) {
|
|
315
|
+
resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
316
|
+
}
|
|
317
|
+
return resolved;
|
|
318
|
+
}
|
|
319
|
+
function resolveCommand(parsed) {
|
|
320
|
+
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
321
|
+
}
|
|
322
|
+
module.exports = resolveCommand;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
|
|
327
|
+
var require_escape = __commonJS({
|
|
328
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module) {
|
|
329
|
+
"use strict";
|
|
330
|
+
var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
331
|
+
function escapeCommand(arg) {
|
|
332
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
333
|
+
return arg;
|
|
334
|
+
}
|
|
335
|
+
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
336
|
+
arg = `${arg}`;
|
|
337
|
+
arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
|
|
338
|
+
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
339
|
+
arg = `"${arg}"`;
|
|
340
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
341
|
+
if (doubleEscapeMetaChars) {
|
|
342
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
343
|
+
}
|
|
344
|
+
return arg;
|
|
345
|
+
}
|
|
346
|
+
module.exports.command = escapeCommand;
|
|
347
|
+
module.exports.argument = escapeArgument;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
// ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
|
|
352
|
+
var require_shebang_regex = __commonJS({
|
|
353
|
+
"../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports, module) {
|
|
354
|
+
"use strict";
|
|
355
|
+
module.exports = /^#!(.*)/;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
|
|
360
|
+
var require_shebang_command = __commonJS({
|
|
361
|
+
"../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports, module) {
|
|
362
|
+
"use strict";
|
|
363
|
+
var shebangRegex = require_shebang_regex();
|
|
364
|
+
module.exports = (string = "") => {
|
|
365
|
+
const match = string.match(shebangRegex);
|
|
366
|
+
if (!match) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
370
|
+
const binary = path.split("/").pop();
|
|
371
|
+
if (binary === "env") {
|
|
372
|
+
return argument;
|
|
373
|
+
}
|
|
374
|
+
return argument ? `${binary} ${argument}` : binary;
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
|
|
380
|
+
var require_readShebang = __commonJS({
|
|
381
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
|
|
382
|
+
"use strict";
|
|
383
|
+
var fs = __require("fs");
|
|
384
|
+
var shebangCommand = require_shebang_command();
|
|
385
|
+
function readShebang(command) {
|
|
386
|
+
const size = 150;
|
|
387
|
+
const buffer = Buffer.alloc(size);
|
|
388
|
+
let fd;
|
|
389
|
+
try {
|
|
390
|
+
fd = fs.openSync(command, "r");
|
|
391
|
+
fs.readSync(fd, buffer, 0, size, 0);
|
|
392
|
+
fs.closeSync(fd);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
}
|
|
395
|
+
return shebangCommand(buffer.toString());
|
|
396
|
+
}
|
|
397
|
+
module.exports = readShebang;
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
|
|
402
|
+
var require_parse = __commonJS({
|
|
403
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
|
|
404
|
+
"use strict";
|
|
405
|
+
var path = __require("path");
|
|
406
|
+
var resolveCommand = require_resolveCommand();
|
|
407
|
+
var escape = require_escape();
|
|
408
|
+
var readShebang = require_readShebang();
|
|
409
|
+
var isWin = process.platform === "win32";
|
|
410
|
+
var isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
411
|
+
var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
412
|
+
function detectShebang(parsed) {
|
|
413
|
+
parsed.file = resolveCommand(parsed);
|
|
414
|
+
const shebang = parsed.file && readShebang(parsed.file);
|
|
415
|
+
if (shebang) {
|
|
416
|
+
parsed.args.unshift(parsed.file);
|
|
417
|
+
parsed.command = shebang;
|
|
418
|
+
return resolveCommand(parsed);
|
|
419
|
+
}
|
|
420
|
+
return parsed.file;
|
|
421
|
+
}
|
|
422
|
+
function parseNonShell(parsed) {
|
|
423
|
+
if (!isWin) {
|
|
424
|
+
return parsed;
|
|
425
|
+
}
|
|
426
|
+
const commandFile = detectShebang(parsed);
|
|
427
|
+
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
428
|
+
if (parsed.options.forceShell || needsShell) {
|
|
429
|
+
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
430
|
+
parsed.command = path.normalize(parsed.command);
|
|
431
|
+
parsed.command = escape.command(parsed.command);
|
|
432
|
+
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
433
|
+
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
434
|
+
parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
|
|
435
|
+
parsed.command = process.env.comspec || "cmd.exe";
|
|
436
|
+
parsed.options.windowsVerbatimArguments = true;
|
|
437
|
+
}
|
|
438
|
+
return parsed;
|
|
439
|
+
}
|
|
440
|
+
function parse(command, args, options) {
|
|
441
|
+
if (args && !Array.isArray(args)) {
|
|
442
|
+
options = args;
|
|
443
|
+
args = null;
|
|
444
|
+
}
|
|
445
|
+
args = args ? args.slice(0) : [];
|
|
446
|
+
options = Object.assign({}, options);
|
|
447
|
+
const parsed = {
|
|
448
|
+
command,
|
|
449
|
+
args,
|
|
450
|
+
options,
|
|
451
|
+
file: void 0,
|
|
452
|
+
original: {
|
|
453
|
+
command,
|
|
454
|
+
args
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
return options.shell ? parsed : parseNonShell(parsed);
|
|
458
|
+
}
|
|
459
|
+
module.exports = parse;
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
|
|
464
|
+
var require_enoent = __commonJS({
|
|
465
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module) {
|
|
466
|
+
"use strict";
|
|
467
|
+
var isWin = process.platform === "win32";
|
|
468
|
+
function notFoundError(original, syscall) {
|
|
469
|
+
return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
|
|
470
|
+
code: "ENOENT",
|
|
471
|
+
errno: "ENOENT",
|
|
472
|
+
syscall: `${syscall} ${original.command}`,
|
|
473
|
+
path: original.command,
|
|
474
|
+
spawnargs: original.args
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function hookChildProcess(cp, parsed) {
|
|
478
|
+
if (!isWin) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
const originalEmit = cp.emit;
|
|
482
|
+
cp.emit = function(name, arg1) {
|
|
483
|
+
if (name === "exit") {
|
|
484
|
+
const err = verifyENOENT(arg1, parsed);
|
|
485
|
+
if (err) {
|
|
486
|
+
return originalEmit.call(cp, "error", err);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return originalEmit.apply(cp, arguments);
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function verifyENOENT(status, parsed) {
|
|
493
|
+
if (isWin && status === 1 && !parsed.file) {
|
|
494
|
+
return notFoundError(parsed.original, "spawn");
|
|
495
|
+
}
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
function verifyENOENTSync(status, parsed) {
|
|
499
|
+
if (isWin && status === 1 && !parsed.file) {
|
|
500
|
+
return notFoundError(parsed.original, "spawnSync");
|
|
501
|
+
}
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
module.exports = {
|
|
505
|
+
hookChildProcess,
|
|
506
|
+
verifyENOENT,
|
|
507
|
+
verifyENOENTSync,
|
|
508
|
+
notFoundError
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
|
|
514
|
+
var require_cross_spawn = __commonJS({
|
|
515
|
+
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module) {
|
|
516
|
+
"use strict";
|
|
517
|
+
var cp = __require("child_process");
|
|
518
|
+
var parse = require_parse();
|
|
519
|
+
var enoent = require_enoent();
|
|
520
|
+
function spawn(command, args, options) {
|
|
521
|
+
const parsed = parse(command, args, options);
|
|
522
|
+
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
523
|
+
enoent.hookChildProcess(spawned, parsed);
|
|
524
|
+
return spawned;
|
|
525
|
+
}
|
|
526
|
+
function spawnSync(command, args, options) {
|
|
527
|
+
const parsed = parse(command, args, options);
|
|
528
|
+
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
529
|
+
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
530
|
+
return result;
|
|
531
|
+
}
|
|
532
|
+
module.exports = spawn;
|
|
533
|
+
module.exports.spawn = spawn;
|
|
534
|
+
module.exports.sync = spawnSync;
|
|
535
|
+
module.exports._parse = parse;
|
|
536
|
+
module.exports._enoent = enoent;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
// ../provider-bridge-protocol/src/bridge-worker-entry.ts
|
|
541
|
+
import { rmSync } from "node:fs";
|
|
542
|
+
import { isAbsolute } from "node:path";
|
|
543
|
+
import { pathToFileURL } from "node:url";
|
|
544
|
+
|
|
545
|
+
// ../process-utils/src/plugin-process-paths.ts
|
|
546
|
+
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
547
|
+
import { tmpdir } from "node:os";
|
|
548
|
+
import { join } from "node:path";
|
|
549
|
+
function safePluginSegment(pluginId2) {
|
|
550
|
+
return encodeURIComponent(pluginId2);
|
|
551
|
+
}
|
|
552
|
+
async function createPluginProcessTempDir(args) {
|
|
553
|
+
return mkdtemp(
|
|
554
|
+
join(tmpdir(), `${args.prefix}-${safePluginSegment(args.pluginId)}-`)
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// ../process-utils/src/index.ts
|
|
559
|
+
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
560
|
+
|
|
561
|
+
// ../provider-bridge-protocol/src/bridge-kit/bounded-line-reader.ts
|
|
562
|
+
import { StringDecoder } from "node:string_decoder";
|
|
563
|
+
var MAX_JSON_RPC_LINE_BYTES = 64 * 1024 * 1024;
|
|
564
|
+
function readBoundedLines(args) {
|
|
565
|
+
const maxLineBytes = args.maxLineBytes ?? MAX_JSON_RPC_LINE_BYTES;
|
|
566
|
+
const decoder = new StringDecoder("utf8");
|
|
567
|
+
let pending = "";
|
|
568
|
+
let discarding = false;
|
|
569
|
+
let discardedBytes = 0;
|
|
570
|
+
args.input.on("data", (chunk) => {
|
|
571
|
+
const text = typeof chunk === "string" ? chunk : decoder.write(chunk);
|
|
572
|
+
let start = 0;
|
|
573
|
+
for (; ; ) {
|
|
574
|
+
const newlineIndex = text.indexOf("\n", start);
|
|
575
|
+
if (newlineIndex === -1) {
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
if (discarding) {
|
|
579
|
+
discarding = false;
|
|
580
|
+
args.onOverflow(discardedBytes);
|
|
581
|
+
discardedBytes = 0;
|
|
582
|
+
} else {
|
|
583
|
+
emit(pending + text.slice(start, newlineIndex));
|
|
584
|
+
}
|
|
585
|
+
pending = "";
|
|
586
|
+
start = newlineIndex + 1;
|
|
587
|
+
}
|
|
588
|
+
const tail = text.slice(start);
|
|
589
|
+
if (discarding) {
|
|
590
|
+
discardedBytes += Buffer.byteLength(tail);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
pending += tail;
|
|
594
|
+
if (Buffer.byteLength(pending) > maxLineBytes) {
|
|
595
|
+
discarding = true;
|
|
596
|
+
discardedBytes = Buffer.byteLength(pending);
|
|
597
|
+
pending = "";
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
args.input.on("end", () => {
|
|
601
|
+
if (!discarding && pending.length > 0) {
|
|
602
|
+
emit(pending);
|
|
603
|
+
}
|
|
604
|
+
pending = "";
|
|
605
|
+
args.onClose?.();
|
|
606
|
+
});
|
|
607
|
+
function emit(line) {
|
|
608
|
+
args.onLine(line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// ../provider-bridge-protocol/src/bridge-kit/bridge-recorder.ts
|
|
613
|
+
import {
|
|
614
|
+
closeSync,
|
|
615
|
+
mkdirSync,
|
|
616
|
+
openSync,
|
|
617
|
+
writeSync
|
|
618
|
+
} from "node:fs";
|
|
619
|
+
import { join as join2, resolve } from "node:path";
|
|
620
|
+
import { StringDecoder as StringDecoder2 } from "node:string_decoder";
|
|
621
|
+
var PROVIDER_BRIDGE_RECORD_DIR_ENV = "BB_PROVIDER_BRIDGE_RECORD_DIR";
|
|
622
|
+
var BRIDGE_RECORDING_PROCESS_SCOPE = "_process";
|
|
623
|
+
function bridgeRecordingFileName(direction) {
|
|
624
|
+
return `${direction}.ndjson`;
|
|
625
|
+
}
|
|
626
|
+
function createRecordingLineSplitter(onLine, maxLineBytes = MAX_JSON_RPC_LINE_BYTES) {
|
|
627
|
+
const decoder = new StringDecoder2("utf8");
|
|
628
|
+
let pending = "";
|
|
629
|
+
let discarding = false;
|
|
630
|
+
return {
|
|
631
|
+
push(chunk) {
|
|
632
|
+
const text = typeof chunk === "string" ? chunk : decoder.write(Buffer.from(chunk));
|
|
633
|
+
let start = 0;
|
|
634
|
+
for (; ; ) {
|
|
635
|
+
const newlineIndex = text.indexOf("\n", start);
|
|
636
|
+
if (newlineIndex === -1) {
|
|
637
|
+
break;
|
|
638
|
+
}
|
|
639
|
+
if (!discarding) {
|
|
640
|
+
const line = pending + text.slice(start, newlineIndex);
|
|
641
|
+
onLine(line.endsWith("\r") ? line.slice(0, -1) : line);
|
|
642
|
+
}
|
|
643
|
+
discarding = false;
|
|
644
|
+
pending = "";
|
|
645
|
+
start = newlineIndex + 1;
|
|
646
|
+
}
|
|
647
|
+
if (discarding) {
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
pending += text.slice(start);
|
|
651
|
+
if (Buffer.byteLength(pending) > maxLineBytes) {
|
|
652
|
+
discarding = true;
|
|
653
|
+
pending = "";
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
function safeScopeSegment(threadId) {
|
|
659
|
+
if (threadId === null || threadId === "") {
|
|
660
|
+
return BRIDGE_RECORDING_PROCESS_SCOPE;
|
|
661
|
+
}
|
|
662
|
+
const sanitized = threadId.replace(/[^A-Za-z0-9_.-]+/g, "-");
|
|
663
|
+
return sanitized === "" || sanitized.startsWith("_") ? `t-${sanitized}` : sanitized;
|
|
664
|
+
}
|
|
665
|
+
function parseRuntimeLine(line) {
|
|
666
|
+
let parsed;
|
|
667
|
+
try {
|
|
668
|
+
parsed = JSON.parse(line);
|
|
669
|
+
} catch {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
const record = parsed;
|
|
676
|
+
const id = typeof record.id === "string" || typeof record.id === "number" ? record.id : void 0;
|
|
677
|
+
const method = typeof record.method === "string" ? record.method : void 0;
|
|
678
|
+
const params = record.params;
|
|
679
|
+
const threadId = typeof params === "object" && params !== null && typeof params.threadId === "string" ? params.threadId : void 0;
|
|
680
|
+
return { id, method, threadId };
|
|
681
|
+
}
|
|
682
|
+
function pendingKey(id) {
|
|
683
|
+
return `${typeof id}:${String(id)}`;
|
|
684
|
+
}
|
|
685
|
+
function createBridgeRecorder(args) {
|
|
686
|
+
const dir = resolve(args.dir);
|
|
687
|
+
const fds = /* @__PURE__ */ new Map();
|
|
688
|
+
const runtimeRequestThreads = /* @__PURE__ */ new Map();
|
|
689
|
+
const bridgeRequestThreads = /* @__PURE__ */ new Map();
|
|
690
|
+
const run = Date.now();
|
|
691
|
+
let seq = 0;
|
|
692
|
+
let closed = false;
|
|
693
|
+
function fdFor(scope, direction) {
|
|
694
|
+
const key = `${scope}\0${direction}`;
|
|
695
|
+
const existing = fds.get(key);
|
|
696
|
+
if (existing !== void 0) {
|
|
697
|
+
return existing;
|
|
698
|
+
}
|
|
699
|
+
const scopeDir = join2(dir, scope);
|
|
700
|
+
mkdirSync(scopeDir, { recursive: true });
|
|
701
|
+
const fd = openSync(join2(scopeDir, bridgeRecordingFileName(direction)), "a");
|
|
702
|
+
fds.set(key, fd);
|
|
703
|
+
return fd;
|
|
704
|
+
}
|
|
705
|
+
function record(recordArgs) {
|
|
706
|
+
if (closed) {
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
seq += 1;
|
|
710
|
+
const entry2 = {
|
|
711
|
+
ts: Date.now(),
|
|
712
|
+
run,
|
|
713
|
+
seq,
|
|
714
|
+
dir: recordArgs.direction,
|
|
715
|
+
line: recordArgs.line
|
|
716
|
+
};
|
|
717
|
+
try {
|
|
718
|
+
writeSync(
|
|
719
|
+
fdFor(safeScopeSegment(recordArgs.threadId), recordArgs.direction),
|
|
720
|
+
`${JSON.stringify(entry2)}
|
|
721
|
+
`
|
|
722
|
+
);
|
|
723
|
+
} catch (error) {
|
|
724
|
+
process.stderr.write(
|
|
725
|
+
`provider bridge recorder: failed to append to ${dir}: ${error instanceof Error ? error.message : String(error)}
|
|
726
|
+
`
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function recordRuntimeLine(direction, line) {
|
|
731
|
+
const parsed = parseRuntimeLine(line);
|
|
732
|
+
let threadId = parsed?.threadId ?? null;
|
|
733
|
+
if (parsed !== null && parsed.id !== void 0) {
|
|
734
|
+
const key = pendingKey(parsed.id);
|
|
735
|
+
if (parsed.method !== void 0) {
|
|
736
|
+
(direction === "runtime\u2192bridge" ? runtimeRequestThreads : bridgeRequestThreads).set(key, threadId);
|
|
737
|
+
} else {
|
|
738
|
+
const pending = direction === "runtime\u2192bridge" ? bridgeRequestThreads : runtimeRequestThreads;
|
|
739
|
+
const owner = pending.get(key);
|
|
740
|
+
if (owner !== void 0) {
|
|
741
|
+
pending.delete(key);
|
|
742
|
+
threadId = owner;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
record({ direction, line, threadId });
|
|
747
|
+
}
|
|
748
|
+
function recordChildIo(child, scope) {
|
|
749
|
+
const { stdin, stdout } = child;
|
|
750
|
+
if (stdout) {
|
|
751
|
+
const splitter = createRecordingLineSplitter(
|
|
752
|
+
(line) => record({ direction: "provider\u2192bridge", line, threadId: scope.threadId })
|
|
753
|
+
);
|
|
754
|
+
stdout.on("data", (chunk) => splitter.push(chunk));
|
|
755
|
+
}
|
|
756
|
+
if (stdin) {
|
|
757
|
+
const splitter = createRecordingLineSplitter(
|
|
758
|
+
(line) => record({ direction: "bridge\u2192provider", line, threadId: scope.threadId })
|
|
759
|
+
);
|
|
760
|
+
const originalWrite = stdin.write.bind(stdin);
|
|
761
|
+
stdin.write = ((chunk, ...rest) => {
|
|
762
|
+
splitter.push(chunk);
|
|
763
|
+
return originalWrite(
|
|
764
|
+
chunk,
|
|
765
|
+
...rest
|
|
766
|
+
);
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
dir,
|
|
772
|
+
record,
|
|
773
|
+
recordRuntimeLine,
|
|
774
|
+
recordChildIo,
|
|
775
|
+
close() {
|
|
776
|
+
closed = true;
|
|
777
|
+
for (const fd of fds.values()) {
|
|
778
|
+
try {
|
|
779
|
+
closeSync(fd);
|
|
780
|
+
} catch {
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
fds.clear();
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
var RECORDER_GLOBAL_KEY = /* @__PURE__ */ Symbol.for("bb.providerBridgeRecorder");
|
|
788
|
+
function globalSlot() {
|
|
789
|
+
const holder = globalThis;
|
|
790
|
+
const existing = holder[RECORDER_GLOBAL_KEY];
|
|
791
|
+
if (existing !== void 0) {
|
|
792
|
+
return existing;
|
|
793
|
+
}
|
|
794
|
+
const slot = { recorder: null, resolved: false };
|
|
795
|
+
holder[RECORDER_GLOBAL_KEY] = slot;
|
|
796
|
+
return slot;
|
|
797
|
+
}
|
|
798
|
+
function getBridgeRecorder() {
|
|
799
|
+
const slot = globalSlot();
|
|
800
|
+
if (!slot.resolved) {
|
|
801
|
+
slot.resolved = true;
|
|
802
|
+
const dir = process.env[PROVIDER_BRIDGE_RECORD_DIR_ENV];
|
|
803
|
+
if (dir !== void 0 && dir.trim() !== "") {
|
|
804
|
+
slot.recorder = createBridgeRecorder({ dir: dir.trim() });
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return slot.recorder;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// ../provider-bridge-protocol/src/bridge-kit/provider-bridge-entry.ts
|
|
811
|
+
var PROVIDER_BRIDGE_EXPORT_NAME = "experimental_providerBridge";
|
|
812
|
+
function parseProviderBridgeEntry(value) {
|
|
813
|
+
if (typeof value !== "object" || value === null) {
|
|
814
|
+
return {
|
|
815
|
+
entry: null,
|
|
816
|
+
problem: `exports no "${PROVIDER_BRIDGE_EXPORT_NAME}"`
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
const candidate = value;
|
|
820
|
+
if (candidate.experimental_apiVersion !== 1) {
|
|
821
|
+
return {
|
|
822
|
+
entry: null,
|
|
823
|
+
problem: `exports "${PROVIDER_BRIDGE_EXPORT_NAME}" with unsupported apiVersion ${String(candidate.experimental_apiVersion)} (expected 1) \u2014 build it with experimental_defineProviderBridge()`
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
if (typeof candidate.handleLine !== "function") {
|
|
827
|
+
return {
|
|
828
|
+
entry: null,
|
|
829
|
+
problem: `exports "${PROVIDER_BRIDGE_EXPORT_NAME}" without a handleLine function`
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
return { entry: candidate, problem: null };
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// ../provider-bridge-protocol/src/bridge-worker-entry.ts
|
|
836
|
+
var [bridgeModulePath, pluginId, dataDir] = process.argv.slice(2);
|
|
837
|
+
function fail(message) {
|
|
838
|
+
process.stderr.write(`${message}
|
|
839
|
+
`);
|
|
840
|
+
process.exit(1);
|
|
841
|
+
}
|
|
842
|
+
if (bridgeModulePath === void 0 || !isAbsolute(bridgeModulePath) || pluginId === void 0 || pluginId === "" || dataDir === void 0 || !isAbsolute(dataDir)) {
|
|
843
|
+
fail(
|
|
844
|
+
"provider bridge bootstrap usage: <bridgeModulePath> <pluginId> <pluginDataDir> (absolute paths)"
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
var tempDir = await createPluginProcessTempDir({
|
|
848
|
+
pluginId,
|
|
849
|
+
prefix: "bb-provider-bridge"
|
|
850
|
+
});
|
|
851
|
+
var removedTempDir = false;
|
|
852
|
+
function removeTempDir() {
|
|
853
|
+
if (removedTempDir) return;
|
|
854
|
+
removedTempDir = true;
|
|
855
|
+
try {
|
|
856
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
857
|
+
} catch {
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
process.once("exit", removeTempDir);
|
|
861
|
+
var recorder = getBridgeRecorder();
|
|
862
|
+
if (recorder !== null) {
|
|
863
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
864
|
+
const outbound = createRecordingLineSplitter(
|
|
865
|
+
(line) => recorder.recordRuntimeLine("bridge\u2192runtime", line)
|
|
866
|
+
);
|
|
867
|
+
process.stdout.write = ((chunk, ...rest) => {
|
|
868
|
+
outbound.push(chunk);
|
|
869
|
+
return originalStdoutWrite(
|
|
870
|
+
chunk,
|
|
871
|
+
...rest
|
|
872
|
+
);
|
|
873
|
+
});
|
|
874
|
+
process.once("exit", () => recorder.close());
|
|
875
|
+
}
|
|
876
|
+
var entry;
|
|
877
|
+
try {
|
|
878
|
+
const imported = await import(pathToFileURL(bridgeModulePath).href);
|
|
879
|
+
const parsed = parseProviderBridgeEntry(
|
|
880
|
+
typeof imported === "object" && imported !== null ? Reflect.get(imported, PROVIDER_BRIDGE_EXPORT_NAME) : void 0
|
|
881
|
+
);
|
|
882
|
+
if (parsed.entry === null) {
|
|
883
|
+
fail(
|
|
884
|
+
`plugin "${pluginId}" cannot run as a provider bridge: its host artifact ${parsed.problem} (${bridgeModulePath})`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
entry = parsed.entry;
|
|
888
|
+
} catch (error) {
|
|
889
|
+
removeTempDir();
|
|
890
|
+
fail(
|
|
891
|
+
`plugin "${pluginId}" failed to load its provider bridge: ${error instanceof Error ? error.message : String(error)}`
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
entry.start?.({ pluginId, dataDir, tempDir });
|
|
895
|
+
if (entry.onSigterm) {
|
|
896
|
+
process.once("SIGTERM", entry.onSigterm);
|
|
897
|
+
}
|
|
898
|
+
if (entry.onSigint) {
|
|
899
|
+
process.once("SIGINT", entry.onSigint);
|
|
900
|
+
}
|
|
901
|
+
readBoundedLines({
|
|
902
|
+
input: process.stdin,
|
|
903
|
+
onLine: recorder === null ? entry.handleLine : (line) => {
|
|
904
|
+
recorder.recordRuntimeLine("runtime\u2192bridge", line);
|
|
905
|
+
entry.handleLine(line);
|
|
906
|
+
},
|
|
907
|
+
onOverflow: (bytes) => {
|
|
908
|
+
process.stderr.write(
|
|
909
|
+
`Discarded an oversized JSON-RPC line from the runtime (${bytes} bytes).
|
|
910
|
+
`
|
|
911
|
+
);
|
|
912
|
+
},
|
|
913
|
+
onClose: () => {
|
|
914
|
+
removeTempDir();
|
|
915
|
+
entry.onClose?.();
|
|
916
|
+
}
|
|
917
|
+
});
|