@probelabs/probe 0.6.0-rc159 → 0.6.0-rc162
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 +169 -1
- package/build/agent/FallbackManager.d.ts +176 -0
- package/build/agent/FallbackManager.js +545 -0
- package/build/agent/ProbeAgent.d.ts +7 -1
- package/build/agent/ProbeAgent.js +545 -89
- package/build/agent/RetryManager.d.ts +157 -0
- package/build/agent/RetryManager.js +334 -0
- package/build/agent/acp/tools.js +6 -2
- package/build/agent/contextCompactor.js +271 -0
- package/build/agent/index.js +2165 -250
- package/build/agent/probeTool.js +20 -2
- package/build/agent/schemaUtils.js +7 -0
- package/build/agent/tools.js +16 -0
- package/build/agent/xmlParsingUtils.js +24 -4
- package/build/index.js +13 -0
- package/build/tools/common.js +21 -4
- package/build/tools/edit.js +409 -0
- package/build/tools/index.js +11 -0
- package/cjs/agent/ProbeAgent.cjs +2620 -606
- package/cjs/index.cjs +2582 -563
- package/package.json +2 -2
- package/src/agent/FallbackManager.d.ts +176 -0
- package/src/agent/FallbackManager.js +545 -0
- package/src/agent/ProbeAgent.d.ts +7 -1
- package/src/agent/ProbeAgent.js +545 -89
- package/src/agent/RetryManager.d.ts +157 -0
- package/src/agent/RetryManager.js +334 -0
- package/src/agent/acp/tools.js +6 -2
- package/src/agent/contextCompactor.js +271 -0
- package/src/agent/index.js +30 -1
- package/src/agent/probeTool.js +20 -2
- package/src/agent/schemaUtils.js +7 -0
- package/src/agent/tools.js +16 -0
- package/src/agent/xmlParsingUtils.js +24 -4
- package/src/index.js +13 -0
- package/src/tools/common.js +21 -4
- package/src/tools/edit.js +409 -0
- package/src/tools/index.js +11 -0
- package/bin/binaries/probe-v0.6.0-rc159-aarch64-apple-darwin.tar.gz +0 -0
- package/bin/binaries/probe-v0.6.0-rc159-aarch64-unknown-linux-musl.tar.gz +0 -0
- package/bin/binaries/probe-v0.6.0-rc159-x86_64-apple-darwin.tar.gz +0 -0
- package/bin/binaries/probe-v0.6.0-rc159-x86_64-pc-windows-msvc.zip +0 -0
- package/bin/binaries/probe-v0.6.0-rc159-x86_64-unknown-linux-musl.tar.gz +0 -0
package/cjs/index.cjs
CHANGED
|
@@ -104,7 +104,7 @@ var require_package = __commonJS({
|
|
|
104
104
|
// node_modules/dotenv/lib/main.js
|
|
105
105
|
var require_main = __commonJS({
|
|
106
106
|
"node_modules/dotenv/lib/main.js"(exports2, module2) {
|
|
107
|
-
var
|
|
107
|
+
var fs7 = require("fs");
|
|
108
108
|
var path7 = require("path");
|
|
109
109
|
var os3 = require("os");
|
|
110
110
|
var crypto2 = require("crypto");
|
|
@@ -213,7 +213,7 @@ var require_main = __commonJS({
|
|
|
213
213
|
if (options && options.path && options.path.length > 0) {
|
|
214
214
|
if (Array.isArray(options.path)) {
|
|
215
215
|
for (const filepath of options.path) {
|
|
216
|
-
if (
|
|
216
|
+
if (fs7.existsSync(filepath)) {
|
|
217
217
|
possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
@@ -223,7 +223,7 @@ var require_main = __commonJS({
|
|
|
223
223
|
} else {
|
|
224
224
|
possibleVaultPath = path7.resolve(process.cwd(), ".env.vault");
|
|
225
225
|
}
|
|
226
|
-
if (
|
|
226
|
+
if (fs7.existsSync(possibleVaultPath)) {
|
|
227
227
|
return possibleVaultPath;
|
|
228
228
|
}
|
|
229
229
|
return null;
|
|
@@ -272,7 +272,7 @@ var require_main = __commonJS({
|
|
|
272
272
|
const parsedAll = {};
|
|
273
273
|
for (const path8 of optionPaths) {
|
|
274
274
|
try {
|
|
275
|
-
const parsed = DotenvModule.parse(
|
|
275
|
+
const parsed = DotenvModule.parse(fs7.readFileSync(path8, { encoding }));
|
|
276
276
|
DotenvModule.populate(parsedAll, parsed, options);
|
|
277
277
|
} catch (e3) {
|
|
278
278
|
if (debug) {
|
|
@@ -678,7 +678,7 @@ async function waitForFileLock(lockPath, binaryPath) {
|
|
|
678
678
|
}
|
|
679
679
|
} catch {
|
|
680
680
|
}
|
|
681
|
-
await new Promise((
|
|
681
|
+
await new Promise((resolve5) => setTimeout(resolve5, LOCK_POLL_INTERVAL_MS));
|
|
682
682
|
}
|
|
683
683
|
if (process.env.DEBUG === "1" || process.env.VERBOSE === "1") {
|
|
684
684
|
console.log(`Timeout waiting for file lock`);
|
|
@@ -1662,7 +1662,7 @@ Command: ${command}`;
|
|
|
1662
1662
|
}
|
|
1663
1663
|
}
|
|
1664
1664
|
function extractWithStdin(binaryPath, cliArgs, content, options) {
|
|
1665
|
-
return new Promise((
|
|
1665
|
+
return new Promise((resolve5, reject2) => {
|
|
1666
1666
|
const childProcess = (0, import_child_process4.spawn)(binaryPath, ["extract", ...cliArgs], {
|
|
1667
1667
|
stdio: ["pipe", "pipe", "pipe"]
|
|
1668
1668
|
});
|
|
@@ -1684,7 +1684,7 @@ function extractWithStdin(binaryPath, cliArgs, content, options) {
|
|
|
1684
1684
|
}
|
|
1685
1685
|
try {
|
|
1686
1686
|
const result = processExtractOutput(stdout, options);
|
|
1687
|
-
|
|
1687
|
+
resolve5(result);
|
|
1688
1688
|
} catch (error2) {
|
|
1689
1689
|
reject2(error2);
|
|
1690
1690
|
}
|
|
@@ -2570,48 +2570,37 @@ var require_dist_cjs5 = __commonJS({
|
|
|
2570
2570
|
}
|
|
2571
2571
|
});
|
|
2572
2572
|
|
|
2573
|
-
// node_modules/@aws/lambda-invoke-store/dist/invoke-store.js
|
|
2574
|
-
var
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2573
|
+
// node_modules/@aws/lambda-invoke-store/dist-es/invoke-store.js
|
|
2574
|
+
var invoke_store_exports = {};
|
|
2575
|
+
__export(invoke_store_exports, {
|
|
2576
|
+
InvokeStore: () => InvokeStore
|
|
2577
|
+
});
|
|
2578
|
+
var import_async_hooks, noGlobalAwsLambda, PROTECTED_KEYS, InvokeStoreImpl, instance, InvokeStore;
|
|
2579
|
+
var init_invoke_store = __esm({
|
|
2580
|
+
"node_modules/@aws/lambda-invoke-store/dist-es/invoke-store.js"() {
|
|
2581
|
+
import_async_hooks = require("async_hooks");
|
|
2582
|
+
noGlobalAwsLambda = process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "1" || process.env["AWS_LAMBDA_NODEJS_NO_GLOBAL_AWSLAMBDA"] === "true";
|
|
2581
2583
|
if (!noGlobalAwsLambda) {
|
|
2582
2584
|
globalThis.awslambda = globalThis.awslambda || {};
|
|
2583
2585
|
}
|
|
2584
|
-
|
|
2586
|
+
PROTECTED_KEYS = {
|
|
2585
2587
|
REQUEST_ID: Symbol("_AWS_LAMBDA_REQUEST_ID"),
|
|
2586
|
-
X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID")
|
|
2588
|
+
X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID"),
|
|
2589
|
+
TENANT_ID: Symbol("_AWS_LAMBDA_TENANT_ID")
|
|
2587
2590
|
};
|
|
2588
|
-
|
|
2589
|
-
static storage = new
|
|
2590
|
-
// Protected keys for Lambda context fields
|
|
2591
|
+
InvokeStoreImpl = class {
|
|
2592
|
+
static storage = new import_async_hooks.AsyncLocalStorage();
|
|
2591
2593
|
static PROTECTED_KEYS = PROTECTED_KEYS;
|
|
2592
|
-
/**
|
|
2593
|
-
* Initialize and run code within an invoke context
|
|
2594
|
-
*/
|
|
2595
2594
|
static run(context, fn) {
|
|
2596
2595
|
return this.storage.run({ ...context }, fn);
|
|
2597
2596
|
}
|
|
2598
|
-
/**
|
|
2599
|
-
* Get the complete current context
|
|
2600
|
-
*/
|
|
2601
2597
|
static getContext() {
|
|
2602
2598
|
return this.storage.getStore();
|
|
2603
2599
|
}
|
|
2604
|
-
/**
|
|
2605
|
-
* Get a specific value from the context by key
|
|
2606
|
-
*/
|
|
2607
2600
|
static get(key) {
|
|
2608
2601
|
const context = this.storage.getStore();
|
|
2609
2602
|
return context?.[key];
|
|
2610
2603
|
}
|
|
2611
|
-
/**
|
|
2612
|
-
* Set a custom value in the current context
|
|
2613
|
-
* Protected Lambda context fields cannot be overwritten
|
|
2614
|
-
*/
|
|
2615
2604
|
static set(key, value) {
|
|
2616
2605
|
if (this.isProtectedKey(key)) {
|
|
2617
2606
|
throw new Error(`Cannot modify protected Lambda context field`);
|
|
@@ -2621,32 +2610,22 @@ var require_invoke_store = __commonJS({
|
|
|
2621
2610
|
context[key] = value;
|
|
2622
2611
|
}
|
|
2623
2612
|
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Get the current request ID
|
|
2626
|
-
*/
|
|
2627
2613
|
static getRequestId() {
|
|
2628
2614
|
return this.get(this.PROTECTED_KEYS.REQUEST_ID) ?? "-";
|
|
2629
2615
|
}
|
|
2630
|
-
/**
|
|
2631
|
-
* Get the current X-ray trace ID
|
|
2632
|
-
*/
|
|
2633
2616
|
static getXRayTraceId() {
|
|
2634
2617
|
return this.get(this.PROTECTED_KEYS.X_RAY_TRACE_ID);
|
|
2635
2618
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2619
|
+
static getTenantId() {
|
|
2620
|
+
return this.get(this.PROTECTED_KEYS.TENANT_ID);
|
|
2621
|
+
}
|
|
2639
2622
|
static hasContext() {
|
|
2640
2623
|
return this.storage.getStore() !== void 0;
|
|
2641
2624
|
}
|
|
2642
|
-
/**
|
|
2643
|
-
* Check if a key is protected (readonly Lambda context field)
|
|
2644
|
-
*/
|
|
2645
2625
|
static isProtectedKey(key) {
|
|
2646
2626
|
return key === this.PROTECTED_KEYS.REQUEST_ID || key === this.PROTECTED_KEYS.X_RAY_TRACE_ID;
|
|
2647
2627
|
}
|
|
2648
2628
|
};
|
|
2649
|
-
var instance;
|
|
2650
2629
|
if (!noGlobalAwsLambda && globalThis.awslambda?.InvokeStore) {
|
|
2651
2630
|
instance = globalThis.awslambda.InvokeStore;
|
|
2652
2631
|
} else {
|
|
@@ -2655,7 +2634,7 @@ var require_invoke_store = __commonJS({
|
|
|
2655
2634
|
globalThis.awslambda.InvokeStore = instance;
|
|
2656
2635
|
}
|
|
2657
2636
|
}
|
|
2658
|
-
|
|
2637
|
+
InvokeStore = instance;
|
|
2659
2638
|
}
|
|
2660
2639
|
});
|
|
2661
2640
|
|
|
@@ -2665,7 +2644,7 @@ var require_recursionDetectionMiddleware = __commonJS({
|
|
|
2665
2644
|
"use strict";
|
|
2666
2645
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
2667
2646
|
exports2.recursionDetectionMiddleware = void 0;
|
|
2668
|
-
var lambda_invoke_store_1 =
|
|
2647
|
+
var lambda_invoke_store_1 = (init_invoke_store(), __toCommonJS(invoke_store_exports));
|
|
2669
2648
|
var protocol_http_1 = require_dist_cjs2();
|
|
2670
2649
|
var TRACE_ID_HEADER_NAME = "X-Amzn-Trace-Id";
|
|
2671
2650
|
var ENV_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME";
|
|
@@ -3688,7 +3667,7 @@ var require_headStream = __commonJS({
|
|
|
3688
3667
|
if ((0, stream_type_check_1.isReadableStream)(stream2)) {
|
|
3689
3668
|
return (0, headStream_browser_1.headStream)(stream2, bytes);
|
|
3690
3669
|
}
|
|
3691
|
-
return new Promise((
|
|
3670
|
+
return new Promise((resolve5, reject2) => {
|
|
3692
3671
|
const collector = new Collector();
|
|
3693
3672
|
collector.limit = bytes;
|
|
3694
3673
|
stream2.pipe(collector);
|
|
@@ -3699,7 +3678,7 @@ var require_headStream = __commonJS({
|
|
|
3699
3678
|
collector.on("error", reject2);
|
|
3700
3679
|
collector.on("finish", function() {
|
|
3701
3680
|
const bytes2 = new Uint8Array(Buffer.concat(this.buffers));
|
|
3702
|
-
|
|
3681
|
+
resolve5(bytes2);
|
|
3703
3682
|
});
|
|
3704
3683
|
});
|
|
3705
3684
|
};
|
|
@@ -3880,28 +3859,28 @@ var require_dist_cjs15 = __commonJS({
|
|
|
3880
3859
|
return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
|
|
3881
3860
|
};
|
|
3882
3861
|
var MIN_WAIT_TIME = 6e3;
|
|
3883
|
-
async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME) {
|
|
3862
|
+
async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) {
|
|
3884
3863
|
const headers = request.headers ?? {};
|
|
3885
3864
|
const expect = headers.Expect || headers.expect;
|
|
3886
3865
|
let timeoutId = -1;
|
|
3887
3866
|
let sendBody = true;
|
|
3888
|
-
if (expect === "100-continue") {
|
|
3867
|
+
if (!externalAgent && expect === "100-continue") {
|
|
3889
3868
|
sendBody = await Promise.race([
|
|
3890
|
-
new Promise((
|
|
3891
|
-
timeoutId = Number(timing.setTimeout(() =>
|
|
3869
|
+
new Promise((resolve5) => {
|
|
3870
|
+
timeoutId = Number(timing.setTimeout(() => resolve5(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
|
|
3892
3871
|
}),
|
|
3893
|
-
new Promise((
|
|
3872
|
+
new Promise((resolve5) => {
|
|
3894
3873
|
httpRequest.on("continue", () => {
|
|
3895
3874
|
timing.clearTimeout(timeoutId);
|
|
3896
|
-
|
|
3875
|
+
resolve5(true);
|
|
3897
3876
|
});
|
|
3898
3877
|
httpRequest.on("response", () => {
|
|
3899
3878
|
timing.clearTimeout(timeoutId);
|
|
3900
|
-
|
|
3879
|
+
resolve5(false);
|
|
3901
3880
|
});
|
|
3902
3881
|
httpRequest.on("error", () => {
|
|
3903
3882
|
timing.clearTimeout(timeoutId);
|
|
3904
|
-
|
|
3883
|
+
resolve5(false);
|
|
3905
3884
|
});
|
|
3906
3885
|
})
|
|
3907
3886
|
]);
|
|
@@ -3935,6 +3914,7 @@ var require_dist_cjs15 = __commonJS({
|
|
|
3935
3914
|
config;
|
|
3936
3915
|
configProvider;
|
|
3937
3916
|
socketWarningTimestamp = 0;
|
|
3917
|
+
externalAgent = false;
|
|
3938
3918
|
metadata = { handlerProtocol: "http/1.1" };
|
|
3939
3919
|
static create(instanceOrOptions) {
|
|
3940
3920
|
if (typeof instanceOrOptions?.handle === "function") {
|
|
@@ -3966,13 +3946,13 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
3966
3946
|
return socketWarningTimestamp;
|
|
3967
3947
|
}
|
|
3968
3948
|
constructor(options) {
|
|
3969
|
-
this.configProvider = new Promise((
|
|
3949
|
+
this.configProvider = new Promise((resolve5, reject2) => {
|
|
3970
3950
|
if (typeof options === "function") {
|
|
3971
3951
|
options().then((_options) => {
|
|
3972
|
-
|
|
3952
|
+
resolve5(this.resolveDefaultConfig(_options));
|
|
3973
3953
|
}).catch(reject2);
|
|
3974
3954
|
} else {
|
|
3975
|
-
|
|
3955
|
+
resolve5(this.resolveDefaultConfig(options));
|
|
3976
3956
|
}
|
|
3977
3957
|
});
|
|
3978
3958
|
}
|
|
@@ -3988,12 +3968,14 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
3988
3968
|
throwOnRequestTimeout,
|
|
3989
3969
|
httpAgent: (() => {
|
|
3990
3970
|
if (httpAgent instanceof http.Agent || typeof httpAgent?.destroy === "function") {
|
|
3971
|
+
this.externalAgent = true;
|
|
3991
3972
|
return httpAgent;
|
|
3992
3973
|
}
|
|
3993
3974
|
return new http.Agent({ keepAlive, maxSockets, ...httpAgent });
|
|
3994
3975
|
})(),
|
|
3995
3976
|
httpsAgent: (() => {
|
|
3996
3977
|
if (httpsAgent instanceof https.Agent || typeof httpsAgent?.destroy === "function") {
|
|
3978
|
+
this.externalAgent = true;
|
|
3997
3979
|
return httpsAgent;
|
|
3998
3980
|
}
|
|
3999
3981
|
return new https.Agent({ keepAlive, maxSockets, ...httpsAgent });
|
|
@@ -4013,7 +3995,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4013
3995
|
const config = this.config;
|
|
4014
3996
|
let writeRequestBodyPromise = void 0;
|
|
4015
3997
|
const timeouts = [];
|
|
4016
|
-
const
|
|
3998
|
+
const resolve5 = async (arg) => {
|
|
4017
3999
|
await writeRequestBodyPromise;
|
|
4018
4000
|
timeouts.forEach(timing.clearTimeout);
|
|
4019
4001
|
_resolve(arg);
|
|
@@ -4033,7 +4015,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4033
4015
|
const headers = request.headers ?? {};
|
|
4034
4016
|
const expectContinue = (headers.Expect ?? headers.expect) === "100-continue";
|
|
4035
4017
|
let agent = isSSL ? config.httpsAgent : config.httpAgent;
|
|
4036
|
-
if (expectContinue) {
|
|
4018
|
+
if (expectContinue && !this.externalAgent) {
|
|
4037
4019
|
agent = new (isSSL ? https.Agent : http.Agent)({
|
|
4038
4020
|
keepAlive: false,
|
|
4039
4021
|
maxSockets: Infinity
|
|
@@ -4079,7 +4061,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4079
4061
|
headers: getTransformedHeaders(res.headers),
|
|
4080
4062
|
body: res
|
|
4081
4063
|
});
|
|
4082
|
-
|
|
4064
|
+
resolve5({ response: httpResponse });
|
|
4083
4065
|
});
|
|
4084
4066
|
req.on("error", (err) => {
|
|
4085
4067
|
if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) {
|
|
@@ -4114,7 +4096,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4114
4096
|
keepAliveMsecs: httpAgent.keepAliveMsecs
|
|
4115
4097
|
}));
|
|
4116
4098
|
}
|
|
4117
|
-
writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout).catch((e3) => {
|
|
4099
|
+
writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e3) => {
|
|
4118
4100
|
timeouts.forEach(timing.clearTimeout);
|
|
4119
4101
|
return _reject(e3);
|
|
4120
4102
|
});
|
|
@@ -4259,13 +4241,13 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4259
4241
|
return new _NodeHttp2Handler(instanceOrOptions);
|
|
4260
4242
|
}
|
|
4261
4243
|
constructor(options) {
|
|
4262
|
-
this.configProvider = new Promise((
|
|
4244
|
+
this.configProvider = new Promise((resolve5, reject2) => {
|
|
4263
4245
|
if (typeof options === "function") {
|
|
4264
4246
|
options().then((opts) => {
|
|
4265
|
-
|
|
4247
|
+
resolve5(opts || {});
|
|
4266
4248
|
}).catch(reject2);
|
|
4267
4249
|
} else {
|
|
4268
|
-
|
|
4250
|
+
resolve5(options || {});
|
|
4269
4251
|
}
|
|
4270
4252
|
});
|
|
4271
4253
|
}
|
|
@@ -4285,7 +4267,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4285
4267
|
return new Promise((_resolve, _reject) => {
|
|
4286
4268
|
let fulfilled = false;
|
|
4287
4269
|
let writeRequestBodyPromise = void 0;
|
|
4288
|
-
const
|
|
4270
|
+
const resolve5 = async (arg) => {
|
|
4289
4271
|
await writeRequestBodyPromise;
|
|
4290
4272
|
_resolve(arg);
|
|
4291
4273
|
};
|
|
@@ -4341,7 +4323,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4341
4323
|
body: req
|
|
4342
4324
|
});
|
|
4343
4325
|
fulfilled = true;
|
|
4344
|
-
|
|
4326
|
+
resolve5({ response: httpResponse });
|
|
4345
4327
|
if (disableConcurrentStreams) {
|
|
4346
4328
|
session.close();
|
|
4347
4329
|
this.connectionManager.deleteSession(authority, session);
|
|
@@ -4418,7 +4400,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4418
4400
|
if (isReadableStreamInstance(stream3)) {
|
|
4419
4401
|
return collectReadableStream(stream3);
|
|
4420
4402
|
}
|
|
4421
|
-
return new Promise((
|
|
4403
|
+
return new Promise((resolve5, reject2) => {
|
|
4422
4404
|
const collector = new Collector();
|
|
4423
4405
|
stream3.pipe(collector);
|
|
4424
4406
|
stream3.on("error", (err) => {
|
|
@@ -4428,7 +4410,7 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
|
|
|
4428
4410
|
collector.on("error", reject2);
|
|
4429
4411
|
collector.on("finish", function() {
|
|
4430
4412
|
const bytes = new Uint8Array(Buffer.concat(this.bufferedBytes));
|
|
4431
|
-
|
|
4413
|
+
resolve5(bytes);
|
|
4432
4414
|
});
|
|
4433
4415
|
});
|
|
4434
4416
|
};
|
|
@@ -4472,7 +4454,7 @@ var require_dist_cjs16 = __commonJS({
|
|
|
4472
4454
|
return new Request(url, requestOptions);
|
|
4473
4455
|
}
|
|
4474
4456
|
function requestTimeout(timeoutInMs = 0) {
|
|
4475
|
-
return new Promise((
|
|
4457
|
+
return new Promise((resolve5, reject2) => {
|
|
4476
4458
|
if (timeoutInMs) {
|
|
4477
4459
|
setTimeout(() => {
|
|
4478
4460
|
const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
|
|
@@ -4590,7 +4572,7 @@ var require_dist_cjs16 = __commonJS({
|
|
|
4590
4572
|
requestTimeout(requestTimeoutInMs)
|
|
4591
4573
|
];
|
|
4592
4574
|
if (abortSignal) {
|
|
4593
|
-
raceOfPromises.push(new Promise((
|
|
4575
|
+
raceOfPromises.push(new Promise((resolve5, reject2) => {
|
|
4594
4576
|
const onAbort = () => {
|
|
4595
4577
|
const abortError = new Error("Request aborted");
|
|
4596
4578
|
abortError.name = "AbortError";
|
|
@@ -4654,7 +4636,7 @@ var require_dist_cjs16 = __commonJS({
|
|
|
4654
4636
|
return collected;
|
|
4655
4637
|
}
|
|
4656
4638
|
function readToBase64(blob) {
|
|
4657
|
-
return new Promise((
|
|
4639
|
+
return new Promise((resolve5, reject2) => {
|
|
4658
4640
|
const reader = new FileReader();
|
|
4659
4641
|
reader.onloadend = () => {
|
|
4660
4642
|
if (reader.readyState !== 2) {
|
|
@@ -4663,7 +4645,7 @@ var require_dist_cjs16 = __commonJS({
|
|
|
4663
4645
|
const result = reader.result ?? "";
|
|
4664
4646
|
const commaIndex = result.indexOf(",");
|
|
4665
4647
|
const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
|
|
4666
|
-
|
|
4648
|
+
resolve5(result.substring(dataOffset));
|
|
4667
4649
|
};
|
|
4668
4650
|
reader.onabort = () => reject2(new Error("Read aborted"));
|
|
4669
4651
|
reader.onerror = () => reject2(reader.error);
|
|
@@ -5165,8 +5147,8 @@ var init_Schema = __esm({
|
|
|
5165
5147
|
name;
|
|
5166
5148
|
namespace;
|
|
5167
5149
|
traits;
|
|
5168
|
-
static assign(
|
|
5169
|
-
const schema = Object.assign(
|
|
5150
|
+
static assign(instance2, values2) {
|
|
5151
|
+
const schema = Object.assign(instance2, values2);
|
|
5170
5152
|
return schema;
|
|
5171
5153
|
}
|
|
5172
5154
|
static [Symbol.hasInstance](lhs) {
|
|
@@ -6283,11 +6265,11 @@ function __metadata(metadataKey, metadataValue) {
|
|
|
6283
6265
|
}
|
|
6284
6266
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
6285
6267
|
function adopt(value) {
|
|
6286
|
-
return value instanceof P ? value : new P(function(
|
|
6287
|
-
|
|
6268
|
+
return value instanceof P ? value : new P(function(resolve5) {
|
|
6269
|
+
resolve5(value);
|
|
6288
6270
|
});
|
|
6289
6271
|
}
|
|
6290
|
-
return new (P || (P = Promise))(function(
|
|
6272
|
+
return new (P || (P = Promise))(function(resolve5, reject2) {
|
|
6291
6273
|
function fulfilled(value) {
|
|
6292
6274
|
try {
|
|
6293
6275
|
step(generator.next(value));
|
|
@@ -6303,7 +6285,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
6303
6285
|
}
|
|
6304
6286
|
}
|
|
6305
6287
|
function step(result) {
|
|
6306
|
-
result.done ?
|
|
6288
|
+
result.done ? resolve5(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
6307
6289
|
}
|
|
6308
6290
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
6309
6291
|
});
|
|
@@ -6494,14 +6476,14 @@ function __asyncValues(o3) {
|
|
|
6494
6476
|
}, i3);
|
|
6495
6477
|
function verb(n3) {
|
|
6496
6478
|
i3[n3] = o3[n3] && function(v3) {
|
|
6497
|
-
return new Promise(function(
|
|
6498
|
-
v3 = o3[n3](v3), settle(
|
|
6479
|
+
return new Promise(function(resolve5, reject2) {
|
|
6480
|
+
v3 = o3[n3](v3), settle(resolve5, reject2, v3.done, v3.value);
|
|
6499
6481
|
});
|
|
6500
6482
|
};
|
|
6501
6483
|
}
|
|
6502
|
-
function settle(
|
|
6484
|
+
function settle(resolve5, reject2, d3, v3) {
|
|
6503
6485
|
Promise.resolve(v3).then(function(v4) {
|
|
6504
|
-
|
|
6486
|
+
resolve5({ value: v4, done: d3 });
|
|
6505
6487
|
}, reject2);
|
|
6506
6488
|
}
|
|
6507
6489
|
}
|
|
@@ -6828,12 +6810,8 @@ var init_schema_date_utils = __esm({
|
|
|
6828
6810
|
range(hours, 0, 23);
|
|
6829
6811
|
range(minutes, 0, 59);
|
|
6830
6812
|
range(seconds, 0, 60);
|
|
6831
|
-
const date2 =
|
|
6832
|
-
date2.setUTCFullYear(Number(yearStr)
|
|
6833
|
-
date2.setUTCHours(Number(hours));
|
|
6834
|
-
date2.setUTCMinutes(Number(minutes));
|
|
6835
|
-
date2.setUTCSeconds(Number(seconds));
|
|
6836
|
-
date2.setUTCMilliseconds(Number(ms) ? Math.round(parseFloat(`0.${ms}`) * 1e3) : 0);
|
|
6813
|
+
const date2 = new Date(Date.UTC(Number(yearStr), Number(monthStr) - 1, Number(dayStr), Number(hours), Number(minutes), Number(seconds), Number(ms) ? Math.round(parseFloat(`0.${ms}`) * 1e3) : 0));
|
|
6814
|
+
date2.setUTCFullYear(Number(yearStr));
|
|
6837
6815
|
if (offsetStr.toUpperCase() != "Z") {
|
|
6838
6816
|
const [, sign, offsetH, offsetM] = /([+-])(\d\d):(\d\d)/.exec(offsetStr) || [void 0, "+", 0, 0];
|
|
6839
6817
|
const scalar = sign === "-" ? 1 : -1;
|
|
@@ -6865,18 +6843,13 @@ var init_schema_date_utils = __esm({
|
|
|
6865
6843
|
[, month, day, hour, minute, second, fraction, year2] = matches;
|
|
6866
6844
|
}
|
|
6867
6845
|
if (year2 && second) {
|
|
6868
|
-
const
|
|
6869
|
-
date2.setUTCFullYear(Number(year2));
|
|
6870
|
-
date2.setUTCMonth(months.indexOf(month));
|
|
6846
|
+
const timestamp = Date.UTC(Number(year2), months.indexOf(month), Number(day), Number(hour), Number(minute), Number(second), fraction ? Math.round(parseFloat(`0.${fraction}`) * 1e3) : 0);
|
|
6871
6847
|
range(day, 1, 31);
|
|
6872
|
-
date2.setUTCDate(Number(day));
|
|
6873
6848
|
range(hour, 0, 23);
|
|
6874
|
-
date2.setUTCHours(Number(hour));
|
|
6875
6849
|
range(minute, 0, 59);
|
|
6876
|
-
date2.setUTCMinutes(Number(minute));
|
|
6877
6850
|
range(second, 0, 60);
|
|
6878
|
-
date2
|
|
6879
|
-
date2.
|
|
6851
|
+
const date2 = new Date(timestamp);
|
|
6852
|
+
date2.setUTCFullYear(Number(year2));
|
|
6880
6853
|
return date2;
|
|
6881
6854
|
}
|
|
6882
6855
|
throw new TypeError(`Invalid RFC7231 date-time value ${value}.`);
|
|
@@ -9110,6 +9083,9 @@ var require_dist_cjs23 = __commonJS({
|
|
|
9110
9083
|
},
|
|
9111
9084
|
"us-isob-east-1": {
|
|
9112
9085
|
description: "US ISOB East (Ohio)"
|
|
9086
|
+
},
|
|
9087
|
+
"us-isob-west-1": {
|
|
9088
|
+
description: "US ISOB West"
|
|
9113
9089
|
}
|
|
9114
9090
|
}
|
|
9115
9091
|
},
|
|
@@ -11247,7 +11223,10 @@ var init_CborCodec = __esm({
|
|
|
11247
11223
|
}
|
|
11248
11224
|
} else if (ns.isStructSchema()) {
|
|
11249
11225
|
for (const [key, memberSchema] of ns.structIterator()) {
|
|
11250
|
-
|
|
11226
|
+
const v3 = this.readValue(memberSchema, value[key]);
|
|
11227
|
+
if (v3 != null) {
|
|
11228
|
+
newObject[key] = v3;
|
|
11229
|
+
}
|
|
11251
11230
|
}
|
|
11252
11231
|
}
|
|
11253
11232
|
return newObject;
|
|
@@ -12114,18 +12093,18 @@ var require_dist_cjs27 = __commonJS({
|
|
|
12114
12093
|
const candidate = value;
|
|
12115
12094
|
return _ServiceException.prototype.isPrototypeOf(candidate) || Boolean(candidate.$fault) && Boolean(candidate.$metadata) && (candidate.$fault === "client" || candidate.$fault === "server");
|
|
12116
12095
|
}
|
|
12117
|
-
static [Symbol.hasInstance](
|
|
12118
|
-
if (!
|
|
12096
|
+
static [Symbol.hasInstance](instance2) {
|
|
12097
|
+
if (!instance2)
|
|
12119
12098
|
return false;
|
|
12120
|
-
const candidate =
|
|
12099
|
+
const candidate = instance2;
|
|
12121
12100
|
if (this === _ServiceException) {
|
|
12122
|
-
return _ServiceException.isInstance(
|
|
12101
|
+
return _ServiceException.isInstance(instance2);
|
|
12123
12102
|
}
|
|
12124
|
-
if (_ServiceException.isInstance(
|
|
12103
|
+
if (_ServiceException.isInstance(instance2)) {
|
|
12125
12104
|
if (candidate.name && this.name) {
|
|
12126
|
-
return this.prototype.isPrototypeOf(
|
|
12105
|
+
return this.prototype.isPrototypeOf(instance2) || candidate.name === this.name;
|
|
12127
12106
|
}
|
|
12128
|
-
return this.prototype.isPrototypeOf(
|
|
12107
|
+
return this.prototype.isPrototypeOf(instance2);
|
|
12129
12108
|
}
|
|
12130
12109
|
return false;
|
|
12131
12110
|
}
|
|
@@ -12768,10 +12747,7 @@ var init_JsonShapeSerializer = __esm({
|
|
|
12768
12747
|
if (ns === this.rootSchema) {
|
|
12769
12748
|
return value;
|
|
12770
12749
|
}
|
|
12771
|
-
|
|
12772
|
-
return (0, import_util_base645.toBase64)(value);
|
|
12773
|
-
}
|
|
12774
|
-
return this.serdeContext?.base64Encoder(value);
|
|
12750
|
+
return (this.serdeContext?.base64Encoder ?? import_util_base645.toBase64)(value);
|
|
12775
12751
|
}
|
|
12776
12752
|
if ((ns.isTimestampSchema() || ns.isDocumentSchema()) && value instanceof Date) {
|
|
12777
12753
|
const format2 = determineTimestampFormat(ns, this.settings);
|
|
@@ -14406,7 +14382,13 @@ var init_AwsQueryProtocol = __esm({
|
|
|
14406
14382
|
Code: errorData.Code,
|
|
14407
14383
|
Message: message
|
|
14408
14384
|
};
|
|
14409
|
-
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) =>
|
|
14385
|
+
const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) => {
|
|
14386
|
+
try {
|
|
14387
|
+
return registry.getSchema(errorName);
|
|
14388
|
+
} catch (e3) {
|
|
14389
|
+
return registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
|
|
14390
|
+
}
|
|
14391
|
+
});
|
|
14410
14392
|
const ns = NormalizedSchema.of(errorSchema);
|
|
14411
14393
|
const ErrorCtor = TypeRegistry.for(errorSchema[1]).getErrorCtor(errorSchema) ?? Error;
|
|
14412
14394
|
const exception = new ErrorCtor(message);
|
|
@@ -15051,8 +15033,8 @@ var require_dist_cjs29 = __commonJS({
|
|
|
15051
15033
|
var X_AMZ_USER_AGENT = "x-amz-user-agent";
|
|
15052
15034
|
var SPACE = " ";
|
|
15053
15035
|
var UA_NAME_SEPARATOR = "/";
|
|
15054
|
-
var UA_NAME_ESCAPE_REGEX = /[
|
|
15055
|
-
var UA_VALUE_ESCAPE_REGEX = /[
|
|
15036
|
+
var UA_NAME_ESCAPE_REGEX = /[^!$%&'*+\-.^_`|~\w]/g;
|
|
15037
|
+
var UA_VALUE_ESCAPE_REGEX = /[^!$%&'*+\-.^_`|~\w#]/g;
|
|
15056
15038
|
var UA_ESCAPE_CHAR = "-";
|
|
15057
15039
|
var BYTE_LIMIT = 1024;
|
|
15058
15040
|
function encodeFeatures(features) {
|
|
@@ -15085,7 +15067,7 @@ var require_dist_cjs29 = __commonJS({
|
|
|
15085
15067
|
const customUserAgent = options?.customUserAgent?.map(escapeUserAgent) || [];
|
|
15086
15068
|
const appId = await options.userAgentAppId();
|
|
15087
15069
|
if (appId) {
|
|
15088
|
-
defaultUserAgent.push(escapeUserAgent([`app
|
|
15070
|
+
defaultUserAgent.push(escapeUserAgent([`app`, `${appId}`]));
|
|
15089
15071
|
}
|
|
15090
15072
|
const prefix = utilEndpoints.getUserAgentPrefix();
|
|
15091
15073
|
const sdkUserAgentValue = (prefix ? [prefix] : []).concat([...defaultUserAgent, ...userAgent, ...customUserAgent]).join(SPACE);
|
|
@@ -16575,7 +16557,7 @@ var require_dist_cjs37 = __commonJS({
|
|
|
16575
16557
|
this.sockets[url] = (this.sockets[url] ?? []).filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
|
16576
16558
|
}
|
|
16577
16559
|
waitForReady(socket, connectionTimeout) {
|
|
16578
|
-
return new Promise((
|
|
16560
|
+
return new Promise((resolve5, reject2) => {
|
|
16579
16561
|
const timeout = setTimeout(() => {
|
|
16580
16562
|
this.removeNotUsableSockets(socket.url);
|
|
16581
16563
|
reject2({
|
|
@@ -16586,7 +16568,7 @@ var require_dist_cjs37 = __commonJS({
|
|
|
16586
16568
|
}, connectionTimeout);
|
|
16587
16569
|
socket.onopen = () => {
|
|
16588
16570
|
clearTimeout(timeout);
|
|
16589
|
-
|
|
16571
|
+
resolve5();
|
|
16590
16572
|
};
|
|
16591
16573
|
});
|
|
16592
16574
|
}
|
|
@@ -16595,10 +16577,10 @@ var require_dist_cjs37 = __commonJS({
|
|
|
16595
16577
|
let socketErrorOccurred = false;
|
|
16596
16578
|
let reject2 = () => {
|
|
16597
16579
|
};
|
|
16598
|
-
let
|
|
16580
|
+
let resolve5 = () => {
|
|
16599
16581
|
};
|
|
16600
16582
|
socket.onmessage = (event) => {
|
|
16601
|
-
|
|
16583
|
+
resolve5({
|
|
16602
16584
|
done: false,
|
|
16603
16585
|
value: new Uint8Array(event.data)
|
|
16604
16586
|
});
|
|
@@ -16615,7 +16597,7 @@ var require_dist_cjs37 = __commonJS({
|
|
|
16615
16597
|
if (streamError) {
|
|
16616
16598
|
reject2(streamError);
|
|
16617
16599
|
} else {
|
|
16618
|
-
|
|
16600
|
+
resolve5({
|
|
16619
16601
|
done: true,
|
|
16620
16602
|
value: void 0
|
|
16621
16603
|
});
|
|
@@ -16625,7 +16607,7 @@ var require_dist_cjs37 = __commonJS({
|
|
|
16625
16607
|
[Symbol.asyncIterator]: () => ({
|
|
16626
16608
|
next: () => {
|
|
16627
16609
|
return new Promise((_resolve, _reject) => {
|
|
16628
|
-
|
|
16610
|
+
resolve5 = _resolve;
|
|
16629
16611
|
reject2 = _reject;
|
|
16630
16612
|
});
|
|
16631
16613
|
}
|
|
@@ -16772,7 +16754,11 @@ var require_dist_cjs39 = __commonJS({
|
|
|
16772
16754
|
var validRegions = /* @__PURE__ */ new Set();
|
|
16773
16755
|
var checkRegion = (region, check = utilEndpoints.isValidHostLabel) => {
|
|
16774
16756
|
if (!validRegions.has(region) && !check(region)) {
|
|
16775
|
-
|
|
16757
|
+
if (region === "*") {
|
|
16758
|
+
console.warn(`@smithy/config-resolver WARN - Please use the caller region instead of "*". See "sigv4a" in https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md.`);
|
|
16759
|
+
} else {
|
|
16760
|
+
throw new Error(`Region not accepted: region="${region}" is not a valid hostname component.`);
|
|
16761
|
+
}
|
|
16776
16762
|
} else {
|
|
16777
16763
|
validRegions.add(region);
|
|
16778
16764
|
}
|
|
@@ -16970,42 +16956,40 @@ var require_getSSOTokenFromFile = __commonJS({
|
|
|
16970
16956
|
"use strict";
|
|
16971
16957
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16972
16958
|
exports2.getSSOTokenFromFile = exports2.tokenIntercept = void 0;
|
|
16973
|
-
var
|
|
16959
|
+
var promises_1 = require("fs/promises");
|
|
16974
16960
|
var getSSOTokenFilepath_1 = require_getSSOTokenFilepath();
|
|
16975
|
-
var { readFile: readFile2 } = fs_1.promises;
|
|
16976
16961
|
exports2.tokenIntercept = {};
|
|
16977
16962
|
var getSSOTokenFromFile = async (id) => {
|
|
16978
16963
|
if (exports2.tokenIntercept[id]) {
|
|
16979
16964
|
return exports2.tokenIntercept[id];
|
|
16980
16965
|
}
|
|
16981
16966
|
const ssoTokenFilepath = (0, getSSOTokenFilepath_1.getSSOTokenFilepath)(id);
|
|
16982
|
-
const ssoTokenText = await
|
|
16967
|
+
const ssoTokenText = await (0, promises_1.readFile)(ssoTokenFilepath, "utf8");
|
|
16983
16968
|
return JSON.parse(ssoTokenText);
|
|
16984
16969
|
};
|
|
16985
16970
|
exports2.getSSOTokenFromFile = getSSOTokenFromFile;
|
|
16986
16971
|
}
|
|
16987
16972
|
});
|
|
16988
16973
|
|
|
16989
|
-
// node_modules/@smithy/shared-ini-file-loader/dist-cjs/
|
|
16990
|
-
var
|
|
16991
|
-
"node_modules/@smithy/shared-ini-file-loader/dist-cjs/
|
|
16974
|
+
// node_modules/@smithy/shared-ini-file-loader/dist-cjs/readFile.js
|
|
16975
|
+
var require_readFile = __commonJS({
|
|
16976
|
+
"node_modules/@smithy/shared-ini-file-loader/dist-cjs/readFile.js"(exports2) {
|
|
16992
16977
|
"use strict";
|
|
16993
16978
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
16994
|
-
exports2.
|
|
16995
|
-
var
|
|
16996
|
-
|
|
16997
|
-
exports2.filePromisesHash = {};
|
|
16979
|
+
exports2.readFile = exports2.fileIntercept = exports2.filePromises = void 0;
|
|
16980
|
+
var promises_1 = require("node:fs/promises");
|
|
16981
|
+
exports2.filePromises = {};
|
|
16998
16982
|
exports2.fileIntercept = {};
|
|
16999
|
-
var
|
|
16983
|
+
var readFile2 = (path7, options) => {
|
|
17000
16984
|
if (exports2.fileIntercept[path7] !== void 0) {
|
|
17001
16985
|
return exports2.fileIntercept[path7];
|
|
17002
16986
|
}
|
|
17003
|
-
if (!exports2.
|
|
17004
|
-
exports2.
|
|
16987
|
+
if (!exports2.filePromises[path7] || options?.ignoreCache) {
|
|
16988
|
+
exports2.filePromises[path7] = (0, promises_1.readFile)(path7, "utf8");
|
|
17005
16989
|
}
|
|
17006
|
-
return exports2.
|
|
16990
|
+
return exports2.filePromises[path7];
|
|
17007
16991
|
};
|
|
17008
|
-
exports2.
|
|
16992
|
+
exports2.readFile = readFile2;
|
|
17009
16993
|
}
|
|
17010
16994
|
});
|
|
17011
16995
|
|
|
@@ -17018,7 +17002,7 @@ var require_dist_cjs42 = __commonJS({
|
|
|
17018
17002
|
var getSSOTokenFromFile = require_getSSOTokenFromFile();
|
|
17019
17003
|
var path7 = require("path");
|
|
17020
17004
|
var types2 = require_dist_cjs();
|
|
17021
|
-
var
|
|
17005
|
+
var readFile2 = require_readFile();
|
|
17022
17006
|
var ENV_PROFILE = "AWS_PROFILE";
|
|
17023
17007
|
var DEFAULT_PROFILE = "default";
|
|
17024
17008
|
var getProfileName = (init) => init.profile || process.env[ENV_PROFILE] || DEFAULT_PROFILE;
|
|
@@ -17102,10 +17086,10 @@ var require_dist_cjs42 = __commonJS({
|
|
|
17102
17086
|
resolvedConfigFilepath = path7.join(homeDir, configFilepath.slice(2));
|
|
17103
17087
|
}
|
|
17104
17088
|
const parsedFiles = await Promise.all([
|
|
17105
|
-
|
|
17089
|
+
readFile2.readFile(resolvedConfigFilepath, {
|
|
17106
17090
|
ignoreCache: init.ignoreCache
|
|
17107
17091
|
}).then(parseIni).then(getConfigData).catch(swallowError$1),
|
|
17108
|
-
|
|
17092
|
+
readFile2.readFile(resolvedFilepath, {
|
|
17109
17093
|
ignoreCache: init.ignoreCache
|
|
17110
17094
|
}).then(parseIni).catch(swallowError$1)
|
|
17111
17095
|
]);
|
|
@@ -17116,7 +17100,7 @@ var require_dist_cjs42 = __commonJS({
|
|
|
17116
17100
|
};
|
|
17117
17101
|
var getSsoSessionData = (data2) => Object.entries(data2).filter(([key]) => key.startsWith(types2.IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR)).reduce((acc, [key, value]) => ({ ...acc, [key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1)]: value }), {});
|
|
17118
17102
|
var swallowError = () => ({});
|
|
17119
|
-
var loadSsoSessionData = async (init = {}) =>
|
|
17103
|
+
var loadSsoSessionData = async (init = {}) => readFile2.readFile(init.configFilepath ?? getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError);
|
|
17120
17104
|
var mergeConfigFiles = (...files) => {
|
|
17121
17105
|
const merged = {};
|
|
17122
17106
|
for (const file of files) {
|
|
@@ -17136,10 +17120,10 @@ var require_dist_cjs42 = __commonJS({
|
|
|
17136
17120
|
};
|
|
17137
17121
|
var externalDataInterceptor = {
|
|
17138
17122
|
getFileRecord() {
|
|
17139
|
-
return
|
|
17123
|
+
return readFile2.fileIntercept;
|
|
17140
17124
|
},
|
|
17141
17125
|
interceptFile(path8, contents) {
|
|
17142
|
-
|
|
17126
|
+
readFile2.fileIntercept[path8] = Promise.resolve(contents);
|
|
17143
17127
|
},
|
|
17144
17128
|
getTokenRecord() {
|
|
17145
17129
|
return getSSOTokenFromFile.tokenIntercept;
|
|
@@ -17154,6 +17138,12 @@ var require_dist_cjs42 = __commonJS({
|
|
|
17154
17138
|
return getSSOTokenFromFile.getSSOTokenFromFile;
|
|
17155
17139
|
}
|
|
17156
17140
|
});
|
|
17141
|
+
Object.defineProperty(exports2, "readFile", {
|
|
17142
|
+
enumerable: true,
|
|
17143
|
+
get: function() {
|
|
17144
|
+
return readFile2.readFile;
|
|
17145
|
+
}
|
|
17146
|
+
});
|
|
17157
17147
|
exports2.CONFIG_PREFIX_SEPARATOR = CONFIG_PREFIX_SEPARATOR;
|
|
17158
17148
|
exports2.DEFAULT_PROFILE = DEFAULT_PROFILE;
|
|
17159
17149
|
exports2.ENV_PROFILE = ENV_PROFILE;
|
|
@@ -17648,7 +17638,7 @@ var require_dist_cjs46 = __commonJS({
|
|
|
17648
17638
|
this.refillTokenBucket();
|
|
17649
17639
|
if (amount > this.currentCapacity) {
|
|
17650
17640
|
const delay = (amount - this.currentCapacity) / this.fillRate * 1e3;
|
|
17651
|
-
await new Promise((
|
|
17641
|
+
await new Promise((resolve5) => _DefaultRateLimiter.setTimeoutFn(resolve5, delay));
|
|
17652
17642
|
}
|
|
17653
17643
|
this.currentCapacity = this.currentCapacity - amount;
|
|
17654
17644
|
}
|
|
@@ -17983,7 +17973,7 @@ var require_dist_cjs47 = __commonJS({
|
|
|
17983
17973
|
const delayFromResponse = getDelayFromRetryAfterHeader(err.$response);
|
|
17984
17974
|
const delay = Math.max(delayFromResponse || 0, delayFromDecider);
|
|
17985
17975
|
totalDelay += delay;
|
|
17986
|
-
await new Promise((
|
|
17976
|
+
await new Promise((resolve5) => setTimeout(resolve5, delay));
|
|
17987
17977
|
continue;
|
|
17988
17978
|
}
|
|
17989
17979
|
if (!err.$metadata) {
|
|
@@ -18141,7 +18131,7 @@ var require_dist_cjs47 = __commonJS({
|
|
|
18141
18131
|
attempts = retryToken.getRetryCount();
|
|
18142
18132
|
const delay = retryToken.getRetryDelay();
|
|
18143
18133
|
totalRetryDelay += delay;
|
|
18144
|
-
await new Promise((
|
|
18134
|
+
await new Promise((resolve5) => setTimeout(resolve5, delay));
|
|
18145
18135
|
}
|
|
18146
18136
|
}
|
|
18147
18137
|
} else {
|
|
@@ -18293,7 +18283,7 @@ var require_package2 = __commonJS({
|
|
|
18293
18283
|
module2.exports = {
|
|
18294
18284
|
name: "@aws-sdk/client-bedrock-runtime",
|
|
18295
18285
|
description: "AWS SDK for JavaScript Bedrock Runtime Client for Node.js, Browser and React Native",
|
|
18296
|
-
version: "3.
|
|
18286
|
+
version: "3.928.0",
|
|
18297
18287
|
scripts: {
|
|
18298
18288
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
18299
18289
|
"build:cjs": "node ../../scripts/compilation/inline client-bedrock-runtime",
|
|
@@ -18312,49 +18302,49 @@ var require_package2 = __commonJS({
|
|
|
18312
18302
|
dependencies: {
|
|
18313
18303
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
18314
18304
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
18315
|
-
"@aws-sdk/core": "3.
|
|
18316
|
-
"@aws-sdk/credential-provider-node": "3.
|
|
18317
|
-
"@aws-sdk/eventstream-handler-node": "3.
|
|
18318
|
-
"@aws-sdk/middleware-eventstream": "3.
|
|
18319
|
-
"@aws-sdk/middleware-host-header": "3.
|
|
18320
|
-
"@aws-sdk/middleware-logger": "3.
|
|
18321
|
-
"@aws-sdk/middleware-recursion-detection": "3.
|
|
18322
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
18323
|
-
"@aws-sdk/middleware-websocket": "3.
|
|
18324
|
-
"@aws-sdk/region-config-resolver": "3.
|
|
18325
|
-
"@aws-sdk/token-providers": "3.
|
|
18326
|
-
"@aws-sdk/types": "3.
|
|
18327
|
-
"@aws-sdk/util-endpoints": "3.
|
|
18328
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
18329
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
18330
|
-
"@smithy/config-resolver": "^4.4.
|
|
18331
|
-
"@smithy/core": "^3.17.
|
|
18332
|
-
"@smithy/eventstream-serde-browser": "^4.2.
|
|
18333
|
-
"@smithy/eventstream-serde-config-resolver": "^4.3.
|
|
18334
|
-
"@smithy/eventstream-serde-node": "^4.2.
|
|
18335
|
-
"@smithy/fetch-http-handler": "^5.3.
|
|
18336
|
-
"@smithy/hash-node": "^4.2.
|
|
18337
|
-
"@smithy/invalid-dependency": "^4.2.
|
|
18338
|
-
"@smithy/middleware-content-length": "^4.2.
|
|
18339
|
-
"@smithy/middleware-endpoint": "^4.3.
|
|
18340
|
-
"@smithy/middleware-retry": "^4.4.
|
|
18341
|
-
"@smithy/middleware-serde": "^4.2.
|
|
18342
|
-
"@smithy/middleware-stack": "^4.2.
|
|
18343
|
-
"@smithy/node-config-provider": "^4.3.
|
|
18344
|
-
"@smithy/node-http-handler": "^4.4.
|
|
18345
|
-
"@smithy/protocol-http": "^5.3.
|
|
18346
|
-
"@smithy/smithy-client": "^4.9.
|
|
18347
|
-
"@smithy/types": "^4.8.
|
|
18348
|
-
"@smithy/url-parser": "^4.2.
|
|
18305
|
+
"@aws-sdk/core": "3.928.0",
|
|
18306
|
+
"@aws-sdk/credential-provider-node": "3.928.0",
|
|
18307
|
+
"@aws-sdk/eventstream-handler-node": "3.922.0",
|
|
18308
|
+
"@aws-sdk/middleware-eventstream": "3.922.0",
|
|
18309
|
+
"@aws-sdk/middleware-host-header": "3.922.0",
|
|
18310
|
+
"@aws-sdk/middleware-logger": "3.922.0",
|
|
18311
|
+
"@aws-sdk/middleware-recursion-detection": "3.922.0",
|
|
18312
|
+
"@aws-sdk/middleware-user-agent": "3.928.0",
|
|
18313
|
+
"@aws-sdk/middleware-websocket": "3.922.0",
|
|
18314
|
+
"@aws-sdk/region-config-resolver": "3.925.0",
|
|
18315
|
+
"@aws-sdk/token-providers": "3.928.0",
|
|
18316
|
+
"@aws-sdk/types": "3.922.0",
|
|
18317
|
+
"@aws-sdk/util-endpoints": "3.922.0",
|
|
18318
|
+
"@aws-sdk/util-user-agent-browser": "3.922.0",
|
|
18319
|
+
"@aws-sdk/util-user-agent-node": "3.928.0",
|
|
18320
|
+
"@smithy/config-resolver": "^4.4.2",
|
|
18321
|
+
"@smithy/core": "^3.17.2",
|
|
18322
|
+
"@smithy/eventstream-serde-browser": "^4.2.4",
|
|
18323
|
+
"@smithy/eventstream-serde-config-resolver": "^4.3.4",
|
|
18324
|
+
"@smithy/eventstream-serde-node": "^4.2.4",
|
|
18325
|
+
"@smithy/fetch-http-handler": "^5.3.5",
|
|
18326
|
+
"@smithy/hash-node": "^4.2.4",
|
|
18327
|
+
"@smithy/invalid-dependency": "^4.2.4",
|
|
18328
|
+
"@smithy/middleware-content-length": "^4.2.4",
|
|
18329
|
+
"@smithy/middleware-endpoint": "^4.3.6",
|
|
18330
|
+
"@smithy/middleware-retry": "^4.4.6",
|
|
18331
|
+
"@smithy/middleware-serde": "^4.2.4",
|
|
18332
|
+
"@smithy/middleware-stack": "^4.2.4",
|
|
18333
|
+
"@smithy/node-config-provider": "^4.3.4",
|
|
18334
|
+
"@smithy/node-http-handler": "^4.4.4",
|
|
18335
|
+
"@smithy/protocol-http": "^5.3.4",
|
|
18336
|
+
"@smithy/smithy-client": "^4.9.2",
|
|
18337
|
+
"@smithy/types": "^4.8.1",
|
|
18338
|
+
"@smithy/url-parser": "^4.2.4",
|
|
18349
18339
|
"@smithy/util-base64": "^4.3.0",
|
|
18350
18340
|
"@smithy/util-body-length-browser": "^4.2.0",
|
|
18351
18341
|
"@smithy/util-body-length-node": "^4.2.1",
|
|
18352
|
-
"@smithy/util-defaults-mode-browser": "^4.3.
|
|
18353
|
-
"@smithy/util-defaults-mode-node": "^4.2.
|
|
18354
|
-
"@smithy/util-endpoints": "^3.2.
|
|
18355
|
-
"@smithy/util-middleware": "^4.2.
|
|
18356
|
-
"@smithy/util-retry": "^4.2.
|
|
18357
|
-
"@smithy/util-stream": "^4.5.
|
|
18342
|
+
"@smithy/util-defaults-mode-browser": "^4.3.5",
|
|
18343
|
+
"@smithy/util-defaults-mode-node": "^4.2.8",
|
|
18344
|
+
"@smithy/util-endpoints": "^3.2.4",
|
|
18345
|
+
"@smithy/util-middleware": "^4.2.4",
|
|
18346
|
+
"@smithy/util-retry": "^4.2.4",
|
|
18347
|
+
"@smithy/util-stream": "^4.5.5",
|
|
18358
18348
|
"@smithy/util-utf8": "^4.2.0",
|
|
18359
18349
|
"@smithy/uuid": "^1.1.0",
|
|
18360
18350
|
tslib: "^2.6.2"
|
|
@@ -18456,7 +18446,7 @@ var require_dist_cjs49 = __commonJS({
|
|
|
18456
18446
|
var nodeConfigProvider = require_dist_cjs43();
|
|
18457
18447
|
var urlParser = require_dist_cjs22();
|
|
18458
18448
|
function httpRequest(options) {
|
|
18459
|
-
return new Promise((
|
|
18449
|
+
return new Promise((resolve5, reject2) => {
|
|
18460
18450
|
const req = http.request({
|
|
18461
18451
|
method: "GET",
|
|
18462
18452
|
...options,
|
|
@@ -18481,7 +18471,7 @@ var require_dist_cjs49 = __commonJS({
|
|
|
18481
18471
|
chunks.push(chunk);
|
|
18482
18472
|
});
|
|
18483
18473
|
res.on("end", () => {
|
|
18484
|
-
|
|
18474
|
+
resolve5(buffer.Buffer.concat(chunks));
|
|
18485
18475
|
req.destroy();
|
|
18486
18476
|
});
|
|
18487
18477
|
});
|
|
@@ -18901,7 +18891,7 @@ var require_retry_wrapper = __commonJS({
|
|
|
18901
18891
|
try {
|
|
18902
18892
|
return await toRetry();
|
|
18903
18893
|
} catch (e3) {
|
|
18904
|
-
await new Promise((
|
|
18894
|
+
await new Promise((resolve5) => setTimeout(resolve5, delayMs));
|
|
18905
18895
|
}
|
|
18906
18896
|
}
|
|
18907
18897
|
return await toRetry();
|
|
@@ -19074,7 +19064,7 @@ var init_package = __esm({
|
|
|
19074
19064
|
"node_modules/@aws-sdk/nested-clients/package.json"() {
|
|
19075
19065
|
package_default = {
|
|
19076
19066
|
name: "@aws-sdk/nested-clients",
|
|
19077
|
-
version: "3.
|
|
19067
|
+
version: "3.928.0",
|
|
19078
19068
|
description: "Nested clients for AWS SDK packages.",
|
|
19079
19069
|
main: "./dist-cjs/index.js",
|
|
19080
19070
|
module: "./dist-es/index.js",
|
|
@@ -19103,40 +19093,40 @@ var init_package = __esm({
|
|
|
19103
19093
|
dependencies: {
|
|
19104
19094
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
19105
19095
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
19106
|
-
"@aws-sdk/core": "3.
|
|
19107
|
-
"@aws-sdk/middleware-host-header": "3.
|
|
19108
|
-
"@aws-sdk/middleware-logger": "3.
|
|
19109
|
-
"@aws-sdk/middleware-recursion-detection": "3.
|
|
19110
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
19111
|
-
"@aws-sdk/region-config-resolver": "3.
|
|
19112
|
-
"@aws-sdk/types": "3.
|
|
19113
|
-
"@aws-sdk/util-endpoints": "3.
|
|
19114
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
19115
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
19116
|
-
"@smithy/config-resolver": "^4.4.
|
|
19117
|
-
"@smithy/core": "^3.17.
|
|
19118
|
-
"@smithy/fetch-http-handler": "^5.3.
|
|
19119
|
-
"@smithy/hash-node": "^4.2.
|
|
19120
|
-
"@smithy/invalid-dependency": "^4.2.
|
|
19121
|
-
"@smithy/middleware-content-length": "^4.2.
|
|
19122
|
-
"@smithy/middleware-endpoint": "^4.3.
|
|
19123
|
-
"@smithy/middleware-retry": "^4.4.
|
|
19124
|
-
"@smithy/middleware-serde": "^4.2.
|
|
19125
|
-
"@smithy/middleware-stack": "^4.2.
|
|
19126
|
-
"@smithy/node-config-provider": "^4.3.
|
|
19127
|
-
"@smithy/node-http-handler": "^4.4.
|
|
19128
|
-
"@smithy/protocol-http": "^5.3.
|
|
19129
|
-
"@smithy/smithy-client": "^4.9.
|
|
19130
|
-
"@smithy/types": "^4.8.
|
|
19131
|
-
"@smithy/url-parser": "^4.2.
|
|
19096
|
+
"@aws-sdk/core": "3.928.0",
|
|
19097
|
+
"@aws-sdk/middleware-host-header": "3.922.0",
|
|
19098
|
+
"@aws-sdk/middleware-logger": "3.922.0",
|
|
19099
|
+
"@aws-sdk/middleware-recursion-detection": "3.922.0",
|
|
19100
|
+
"@aws-sdk/middleware-user-agent": "3.928.0",
|
|
19101
|
+
"@aws-sdk/region-config-resolver": "3.925.0",
|
|
19102
|
+
"@aws-sdk/types": "3.922.0",
|
|
19103
|
+
"@aws-sdk/util-endpoints": "3.922.0",
|
|
19104
|
+
"@aws-sdk/util-user-agent-browser": "3.922.0",
|
|
19105
|
+
"@aws-sdk/util-user-agent-node": "3.928.0",
|
|
19106
|
+
"@smithy/config-resolver": "^4.4.2",
|
|
19107
|
+
"@smithy/core": "^3.17.2",
|
|
19108
|
+
"@smithy/fetch-http-handler": "^5.3.5",
|
|
19109
|
+
"@smithy/hash-node": "^4.2.4",
|
|
19110
|
+
"@smithy/invalid-dependency": "^4.2.4",
|
|
19111
|
+
"@smithy/middleware-content-length": "^4.2.4",
|
|
19112
|
+
"@smithy/middleware-endpoint": "^4.3.6",
|
|
19113
|
+
"@smithy/middleware-retry": "^4.4.6",
|
|
19114
|
+
"@smithy/middleware-serde": "^4.2.4",
|
|
19115
|
+
"@smithy/middleware-stack": "^4.2.4",
|
|
19116
|
+
"@smithy/node-config-provider": "^4.3.4",
|
|
19117
|
+
"@smithy/node-http-handler": "^4.4.4",
|
|
19118
|
+
"@smithy/protocol-http": "^5.3.4",
|
|
19119
|
+
"@smithy/smithy-client": "^4.9.2",
|
|
19120
|
+
"@smithy/types": "^4.8.1",
|
|
19121
|
+
"@smithy/url-parser": "^4.2.4",
|
|
19132
19122
|
"@smithy/util-base64": "^4.3.0",
|
|
19133
19123
|
"@smithy/util-body-length-browser": "^4.2.0",
|
|
19134
19124
|
"@smithy/util-body-length-node": "^4.2.1",
|
|
19135
|
-
"@smithy/util-defaults-mode-browser": "^4.3.
|
|
19136
|
-
"@smithy/util-defaults-mode-node": "^4.2.
|
|
19137
|
-
"@smithy/util-endpoints": "^3.2.
|
|
19138
|
-
"@smithy/util-middleware": "^4.2.
|
|
19139
|
-
"@smithy/util-retry": "^4.2.
|
|
19125
|
+
"@smithy/util-defaults-mode-browser": "^4.3.5",
|
|
19126
|
+
"@smithy/util-defaults-mode-node": "^4.2.8",
|
|
19127
|
+
"@smithy/util-endpoints": "^3.2.4",
|
|
19128
|
+
"@smithy/util-middleware": "^4.2.4",
|
|
19129
|
+
"@smithy/util-retry": "^4.2.4",
|
|
19140
19130
|
"@smithy/util-utf8": "^4.2.0",
|
|
19141
19131
|
tslib: "^2.6.2"
|
|
19142
19132
|
},
|
|
@@ -19338,8 +19328,8 @@ var init_ruleset = __esm({
|
|
|
19338
19328
|
f = "tree";
|
|
19339
19329
|
g = "PartitionResult";
|
|
19340
19330
|
h = "getAttr";
|
|
19341
|
-
i = { [u]: false, "type": "
|
|
19342
|
-
j = { [u]: true, "default": false, "type": "
|
|
19331
|
+
i = { [u]: false, "type": "string" };
|
|
19332
|
+
j = { [u]: true, "default": false, "type": "boolean" };
|
|
19343
19333
|
k = { [x]: "Endpoint" };
|
|
19344
19334
|
l = { [v]: c, [w]: [{ [x]: "UseFIPS" }, true] };
|
|
19345
19335
|
m = { [v]: c, [w]: [{ [x]: "UseDualStack" }, true] };
|
|
@@ -19545,11 +19535,38 @@ var init_runtimeConfig = __esm({
|
|
|
19545
19535
|
}
|
|
19546
19536
|
});
|
|
19547
19537
|
|
|
19538
|
+
// node_modules/@aws-sdk/region-config-resolver/dist-cjs/regionConfig/stsRegionDefaultResolver.js
|
|
19539
|
+
var require_stsRegionDefaultResolver = __commonJS({
|
|
19540
|
+
"node_modules/@aws-sdk/region-config-resolver/dist-cjs/regionConfig/stsRegionDefaultResolver.js"(exports2) {
|
|
19541
|
+
"use strict";
|
|
19542
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
19543
|
+
exports2.warning = void 0;
|
|
19544
|
+
exports2.stsRegionDefaultResolver = stsRegionDefaultResolver2;
|
|
19545
|
+
var config_resolver_1 = require_dist_cjs39();
|
|
19546
|
+
var node_config_provider_1 = require_dist_cjs43();
|
|
19547
|
+
function stsRegionDefaultResolver2(loaderConfig = {}) {
|
|
19548
|
+
return (0, node_config_provider_1.loadConfig)({
|
|
19549
|
+
...config_resolver_1.NODE_REGION_CONFIG_OPTIONS,
|
|
19550
|
+
async default() {
|
|
19551
|
+
if (!exports2.warning.silence) {
|
|
19552
|
+
console.warn("@aws-sdk - WARN - default STS region of us-east-1 used. See @aws-sdk/credential-providers README and set a region explicitly.");
|
|
19553
|
+
}
|
|
19554
|
+
return "us-east-1";
|
|
19555
|
+
}
|
|
19556
|
+
}, { ...config_resolver_1.NODE_REGION_CONFIG_FILE_OPTIONS, ...loaderConfig });
|
|
19557
|
+
}
|
|
19558
|
+
exports2.warning = {
|
|
19559
|
+
silence: false
|
|
19560
|
+
};
|
|
19561
|
+
}
|
|
19562
|
+
});
|
|
19563
|
+
|
|
19548
19564
|
// node_modules/@aws-sdk/region-config-resolver/dist-cjs/index.js
|
|
19549
19565
|
var require_dist_cjs55 = __commonJS({
|
|
19550
19566
|
"node_modules/@aws-sdk/region-config-resolver/dist-cjs/index.js"(exports2) {
|
|
19551
19567
|
"use strict";
|
|
19552
19568
|
var configResolver = require_dist_cjs39();
|
|
19569
|
+
var stsRegionDefaultResolver2 = require_stsRegionDefaultResolver();
|
|
19553
19570
|
var getAwsRegionExtensionConfiguration3 = (runtimeConfig) => {
|
|
19554
19571
|
return {
|
|
19555
19572
|
setRegion(region) {
|
|
@@ -19597,6 +19614,14 @@ var require_dist_cjs55 = __commonJS({
|
|
|
19597
19614
|
});
|
|
19598
19615
|
exports2.getAwsRegionExtensionConfiguration = getAwsRegionExtensionConfiguration3;
|
|
19599
19616
|
exports2.resolveAwsRegionExtensionConfiguration = resolveAwsRegionExtensionConfiguration3;
|
|
19617
|
+
Object.keys(stsRegionDefaultResolver2).forEach(function(k3) {
|
|
19618
|
+
if (k3 !== "default" && !Object.prototype.hasOwnProperty.call(exports2, k3)) Object.defineProperty(exports2, k3, {
|
|
19619
|
+
enumerable: true,
|
|
19620
|
+
get: function() {
|
|
19621
|
+
return stsRegionDefaultResolver2[k3];
|
|
19622
|
+
}
|
|
19623
|
+
});
|
|
19624
|
+
});
|
|
19600
19625
|
}
|
|
19601
19626
|
});
|
|
19602
19627
|
|
|
@@ -20294,7 +20319,7 @@ var require_dist_cjs56 = __commonJS({
|
|
|
20294
20319
|
var httpAuthSchemes = (init_httpAuthSchemes2(), __toCommonJS(httpAuthSchemes_exports));
|
|
20295
20320
|
var propertyProvider = require_dist_cjs24();
|
|
20296
20321
|
var sharedIniFileLoader = require_dist_cjs42();
|
|
20297
|
-
var
|
|
20322
|
+
var fs7 = require("fs");
|
|
20298
20323
|
var fromEnvSigningName = ({ logger: logger2, signingName } = {}) => async () => {
|
|
20299
20324
|
logger2?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
|
|
20300
20325
|
if (!signingName) {
|
|
@@ -20312,9 +20337,11 @@ var require_dist_cjs56 = __commonJS({
|
|
|
20312
20337
|
var REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
|
|
20313
20338
|
var getSsoOidcClient = async (ssoRegion, init = {}) => {
|
|
20314
20339
|
const { SSOOIDCClient: SSOOIDCClient2 } = await Promise.resolve().then(() => (init_sso_oidc(), sso_oidc_exports));
|
|
20340
|
+
const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop];
|
|
20315
20341
|
const ssoOidcClient = new SSOOIDCClient2(Object.assign({}, init.clientConfig ?? {}, {
|
|
20316
20342
|
region: ssoRegion ?? init.clientConfig?.region,
|
|
20317
|
-
logger:
|
|
20343
|
+
logger: coalesce("logger"),
|
|
20344
|
+
userAgentAppId: coalesce("userAgentAppId")
|
|
20318
20345
|
}));
|
|
20319
20346
|
return ssoOidcClient;
|
|
20320
20347
|
};
|
|
@@ -20338,7 +20365,7 @@ var require_dist_cjs56 = __commonJS({
|
|
|
20338
20365
|
throw new propertyProvider.TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
|
|
20339
20366
|
}
|
|
20340
20367
|
};
|
|
20341
|
-
var { writeFile } =
|
|
20368
|
+
var { writeFile } = fs7.promises;
|
|
20342
20369
|
var writeSSOTokenToFile = (id, ssoToken) => {
|
|
20343
20370
|
const tokenFilepath = sharedIniFileLoader.getSSOTokenFilepath(id);
|
|
20344
20371
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
|
@@ -20517,7 +20544,7 @@ var require_package3 = __commonJS({
|
|
|
20517
20544
|
module2.exports = {
|
|
20518
20545
|
name: "@aws-sdk/client-sso",
|
|
20519
20546
|
description: "AWS SDK for JavaScript Sso Client for Node.js, Browser and React Native",
|
|
20520
|
-
version: "3.
|
|
20547
|
+
version: "3.928.0",
|
|
20521
20548
|
scripts: {
|
|
20522
20549
|
build: "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
20523
20550
|
"build:cjs": "node ../../scripts/compilation/inline client-sso",
|
|
@@ -20536,40 +20563,40 @@ var require_package3 = __commonJS({
|
|
|
20536
20563
|
dependencies: {
|
|
20537
20564
|
"@aws-crypto/sha256-browser": "5.2.0",
|
|
20538
20565
|
"@aws-crypto/sha256-js": "5.2.0",
|
|
20539
|
-
"@aws-sdk/core": "3.
|
|
20540
|
-
"@aws-sdk/middleware-host-header": "3.
|
|
20541
|
-
"@aws-sdk/middleware-logger": "3.
|
|
20542
|
-
"@aws-sdk/middleware-recursion-detection": "3.
|
|
20543
|
-
"@aws-sdk/middleware-user-agent": "3.
|
|
20544
|
-
"@aws-sdk/region-config-resolver": "3.
|
|
20545
|
-
"@aws-sdk/types": "3.
|
|
20546
|
-
"@aws-sdk/util-endpoints": "3.
|
|
20547
|
-
"@aws-sdk/util-user-agent-browser": "3.
|
|
20548
|
-
"@aws-sdk/util-user-agent-node": "3.
|
|
20549
|
-
"@smithy/config-resolver": "^4.4.
|
|
20550
|
-
"@smithy/core": "^3.17.
|
|
20551
|
-
"@smithy/fetch-http-handler": "^5.3.
|
|
20552
|
-
"@smithy/hash-node": "^4.2.
|
|
20553
|
-
"@smithy/invalid-dependency": "^4.2.
|
|
20554
|
-
"@smithy/middleware-content-length": "^4.2.
|
|
20555
|
-
"@smithy/middleware-endpoint": "^4.3.
|
|
20556
|
-
"@smithy/middleware-retry": "^4.4.
|
|
20557
|
-
"@smithy/middleware-serde": "^4.2.
|
|
20558
|
-
"@smithy/middleware-stack": "^4.2.
|
|
20559
|
-
"@smithy/node-config-provider": "^4.3.
|
|
20560
|
-
"@smithy/node-http-handler": "^4.4.
|
|
20561
|
-
"@smithy/protocol-http": "^5.3.
|
|
20562
|
-
"@smithy/smithy-client": "^4.9.
|
|
20563
|
-
"@smithy/types": "^4.8.
|
|
20564
|
-
"@smithy/url-parser": "^4.2.
|
|
20566
|
+
"@aws-sdk/core": "3.928.0",
|
|
20567
|
+
"@aws-sdk/middleware-host-header": "3.922.0",
|
|
20568
|
+
"@aws-sdk/middleware-logger": "3.922.0",
|
|
20569
|
+
"@aws-sdk/middleware-recursion-detection": "3.922.0",
|
|
20570
|
+
"@aws-sdk/middleware-user-agent": "3.928.0",
|
|
20571
|
+
"@aws-sdk/region-config-resolver": "3.925.0",
|
|
20572
|
+
"@aws-sdk/types": "3.922.0",
|
|
20573
|
+
"@aws-sdk/util-endpoints": "3.922.0",
|
|
20574
|
+
"@aws-sdk/util-user-agent-browser": "3.922.0",
|
|
20575
|
+
"@aws-sdk/util-user-agent-node": "3.928.0",
|
|
20576
|
+
"@smithy/config-resolver": "^4.4.2",
|
|
20577
|
+
"@smithy/core": "^3.17.2",
|
|
20578
|
+
"@smithy/fetch-http-handler": "^5.3.5",
|
|
20579
|
+
"@smithy/hash-node": "^4.2.4",
|
|
20580
|
+
"@smithy/invalid-dependency": "^4.2.4",
|
|
20581
|
+
"@smithy/middleware-content-length": "^4.2.4",
|
|
20582
|
+
"@smithy/middleware-endpoint": "^4.3.6",
|
|
20583
|
+
"@smithy/middleware-retry": "^4.4.6",
|
|
20584
|
+
"@smithy/middleware-serde": "^4.2.4",
|
|
20585
|
+
"@smithy/middleware-stack": "^4.2.4",
|
|
20586
|
+
"@smithy/node-config-provider": "^4.3.4",
|
|
20587
|
+
"@smithy/node-http-handler": "^4.4.4",
|
|
20588
|
+
"@smithy/protocol-http": "^5.3.4",
|
|
20589
|
+
"@smithy/smithy-client": "^4.9.2",
|
|
20590
|
+
"@smithy/types": "^4.8.1",
|
|
20591
|
+
"@smithy/url-parser": "^4.2.4",
|
|
20565
20592
|
"@smithy/util-base64": "^4.3.0",
|
|
20566
20593
|
"@smithy/util-body-length-browser": "^4.2.0",
|
|
20567
20594
|
"@smithy/util-body-length-node": "^4.2.1",
|
|
20568
|
-
"@smithy/util-defaults-mode-browser": "^4.3.
|
|
20569
|
-
"@smithy/util-defaults-mode-node": "^4.2.
|
|
20570
|
-
"@smithy/util-endpoints": "^3.2.
|
|
20571
|
-
"@smithy/util-middleware": "^4.2.
|
|
20572
|
-
"@smithy/util-retry": "^4.2.
|
|
20595
|
+
"@smithy/util-defaults-mode-browser": "^4.3.5",
|
|
20596
|
+
"@smithy/util-defaults-mode-node": "^4.2.8",
|
|
20597
|
+
"@smithy/util-endpoints": "^3.2.4",
|
|
20598
|
+
"@smithy/util-middleware": "^4.2.4",
|
|
20599
|
+
"@smithy/util-retry": "^4.2.4",
|
|
20573
20600
|
"@smithy/util-utf8": "^4.2.0",
|
|
20574
20601
|
tslib: "^2.6.2"
|
|
20575
20602
|
},
|
|
@@ -20633,8 +20660,8 @@ var require_ruleset = __commonJS({
|
|
|
20633
20660
|
var f3 = "tree";
|
|
20634
20661
|
var g3 = "PartitionResult";
|
|
20635
20662
|
var h3 = "getAttr";
|
|
20636
|
-
var i3 = { [u3]: false, "type": "
|
|
20637
|
-
var j3 = { [u3]: true, "default": false, "type": "
|
|
20663
|
+
var i3 = { [u3]: false, "type": "string" };
|
|
20664
|
+
var j3 = { [u3]: true, "default": false, "type": "boolean" };
|
|
20638
20665
|
var k3 = { [x3]: "Endpoint" };
|
|
20639
20666
|
var l3 = { [v3]: c3, [w3]: [{ [x3]: "UseFIPS" }, true] };
|
|
20640
20667
|
var m3 = { [v3]: c3, [w3]: [{ [x3]: "UseDualStack" }, true] };
|
|
@@ -21314,7 +21341,8 @@ var require_dist_cjs58 = __commonJS({
|
|
|
21314
21341
|
});
|
|
21315
21342
|
const sso = ssoClient || new SSOClient(Object.assign({}, clientConfig ?? {}, {
|
|
21316
21343
|
logger: clientConfig?.logger ?? parentClientConfig?.logger,
|
|
21317
|
-
region: clientConfig?.region ?? ssoRegion
|
|
21344
|
+
region: clientConfig?.region ?? ssoRegion,
|
|
21345
|
+
userAgentAppId: clientConfig?.userAgentAppId ?? parentClientConfig?.userAgentAppId
|
|
21318
21346
|
}));
|
|
21319
21347
|
let ssoResp;
|
|
21320
21348
|
try {
|
|
@@ -21542,8 +21570,8 @@ var init_ruleset2 = __esm({
|
|
|
21542
21570
|
j2 = "tree";
|
|
21543
21571
|
k2 = "error";
|
|
21544
21572
|
l2 = "getAttr";
|
|
21545
|
-
m2 = { [F]: false, [G]: "
|
|
21546
|
-
n2 = { [F]: true, "default": false, [G]: "
|
|
21573
|
+
m2 = { [F]: false, [G]: "string" };
|
|
21574
|
+
n2 = { [F]: true, "default": false, [G]: "boolean" };
|
|
21547
21575
|
o2 = { [J]: "Endpoint" };
|
|
21548
21576
|
p2 = { [H]: "isSet", [I]: [{ [J]: "Region" }] };
|
|
21549
21577
|
q2 = { [J]: "Region" };
|
|
@@ -22539,13 +22567,13 @@ var init_models2 = __esm({
|
|
|
22539
22567
|
});
|
|
22540
22568
|
|
|
22541
22569
|
// node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/defaultStsRoleAssumers.js
|
|
22542
|
-
var
|
|
22570
|
+
var import_region_config_resolver3, getAccountIdFromAssumedRoleUser, resolveRegion, getDefaultRoleAssumer, getDefaultRoleAssumerWithWebIdentity, isH2;
|
|
22543
22571
|
var init_defaultStsRoleAssumers = __esm({
|
|
22544
22572
|
"node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/defaultStsRoleAssumers.js"() {
|
|
22545
22573
|
init_client();
|
|
22574
|
+
import_region_config_resolver3 = __toESM(require_dist_cjs55());
|
|
22546
22575
|
init_AssumeRoleCommand();
|
|
22547
22576
|
init_AssumeRoleWithWebIdentityCommand();
|
|
22548
|
-
ASSUME_ROLE_DEFAULT_REGION = "us-east-1";
|
|
22549
22577
|
getAccountIdFromAssumedRoleUser = (assumedRoleUser) => {
|
|
22550
22578
|
if (typeof assumedRoleUser?.Arn === "string") {
|
|
22551
22579
|
const arnComponents = assumedRoleUser.Arn.split(":");
|
|
@@ -22555,11 +22583,12 @@ var init_defaultStsRoleAssumers = __esm({
|
|
|
22555
22583
|
}
|
|
22556
22584
|
return void 0;
|
|
22557
22585
|
};
|
|
22558
|
-
resolveRegion = async (_region, _parentRegion, credentialProviderLogger) => {
|
|
22586
|
+
resolveRegion = async (_region, _parentRegion, credentialProviderLogger, loaderConfig = {}) => {
|
|
22559
22587
|
const region = typeof _region === "function" ? await _region() : _region;
|
|
22560
22588
|
const parentRegion = typeof _parentRegion === "function" ? await _parentRegion() : _parentRegion;
|
|
22561
|
-
|
|
22562
|
-
|
|
22589
|
+
const stsDefaultRegion = await (0, import_region_config_resolver3.stsRegionDefaultResolver)(loaderConfig)();
|
|
22590
|
+
credentialProviderLogger?.debug?.("@aws-sdk/client-sts::resolveRegion", "accepting first of:", `${region} (credential provider clientConfig)`, `${parentRegion} (contextual client)`, `${stsDefaultRegion} (STS default: AWS_REGION, profile region, or us-east-1)`);
|
|
22591
|
+
return region ?? parentRegion ?? stsDefaultRegion;
|
|
22563
22592
|
};
|
|
22564
22593
|
getDefaultRoleAssumer = (stsOptions, STSClient2) => {
|
|
22565
22594
|
let stsClient;
|
|
@@ -22567,11 +22596,15 @@ var init_defaultStsRoleAssumers = __esm({
|
|
|
22567
22596
|
return async (sourceCreds, params) => {
|
|
22568
22597
|
closureSourceCreds = sourceCreds;
|
|
22569
22598
|
if (!stsClient) {
|
|
22570
|
-
const { logger: logger2 = stsOptions?.parentClientConfig?.logger, profile = stsOptions?.parentClientConfig?.profile, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger } = stsOptions;
|
|
22571
|
-
const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger
|
|
22599
|
+
const { logger: logger2 = stsOptions?.parentClientConfig?.logger, profile = stsOptions?.parentClientConfig?.profile, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger, userAgentAppId = stsOptions?.parentClientConfig?.userAgentAppId } = stsOptions;
|
|
22600
|
+
const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger, {
|
|
22601
|
+
logger: logger2,
|
|
22602
|
+
profile
|
|
22603
|
+
});
|
|
22572
22604
|
const isCompatibleRequestHandler = !isH2(requestHandler);
|
|
22573
22605
|
stsClient = new STSClient2({
|
|
22574
22606
|
...stsOptions,
|
|
22607
|
+
userAgentAppId,
|
|
22575
22608
|
profile,
|
|
22576
22609
|
credentialDefaultProvider: () => async () => closureSourceCreds,
|
|
22577
22610
|
region: resolvedRegion,
|
|
@@ -22600,11 +22633,15 @@ var init_defaultStsRoleAssumers = __esm({
|
|
|
22600
22633
|
let stsClient;
|
|
22601
22634
|
return async (params) => {
|
|
22602
22635
|
if (!stsClient) {
|
|
22603
|
-
const { logger: logger2 = stsOptions?.parentClientConfig?.logger, profile = stsOptions?.parentClientConfig?.profile, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger } = stsOptions;
|
|
22604
|
-
const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger
|
|
22636
|
+
const { logger: logger2 = stsOptions?.parentClientConfig?.logger, profile = stsOptions?.parentClientConfig?.profile, region, requestHandler = stsOptions?.parentClientConfig?.requestHandler, credentialProviderLogger, userAgentAppId = stsOptions?.parentClientConfig?.userAgentAppId } = stsOptions;
|
|
22637
|
+
const resolvedRegion = await resolveRegion(region, stsOptions?.parentClientConfig?.region, credentialProviderLogger, {
|
|
22638
|
+
logger: logger2,
|
|
22639
|
+
profile
|
|
22640
|
+
});
|
|
22605
22641
|
const isCompatibleRequestHandler = !isH2(requestHandler);
|
|
22606
22642
|
stsClient = new STSClient2({
|
|
22607
22643
|
...stsOptions,
|
|
22644
|
+
userAgentAppId,
|
|
22608
22645
|
profile,
|
|
22609
22646
|
region: resolvedRegion,
|
|
22610
22647
|
requestHandler: isCompatibleRequestHandler ? requestHandler : void 0,
|
|
@@ -22863,7 +22900,7 @@ var require_fromTokenFile = __commonJS({
|
|
|
22863
22900
|
var ENV_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE";
|
|
22864
22901
|
var ENV_ROLE_ARN = "AWS_ROLE_ARN";
|
|
22865
22902
|
var ENV_ROLE_SESSION_NAME = "AWS_ROLE_SESSION_NAME";
|
|
22866
|
-
var fromTokenFile = (init = {}) => async () => {
|
|
22903
|
+
var fromTokenFile = (init = {}) => async (awsIdentityProperties) => {
|
|
22867
22904
|
init.logger?.debug("@aws-sdk/credential-provider-web-identity - fromTokenFile");
|
|
22868
22905
|
const webIdentityTokenFile = init?.webIdentityTokenFile ?? process.env[ENV_TOKEN_FILE];
|
|
22869
22906
|
const roleArn = init?.roleArn ?? process.env[ENV_ROLE_ARN];
|
|
@@ -22878,7 +22915,7 @@ var require_fromTokenFile = __commonJS({
|
|
|
22878
22915
|
webIdentityToken: shared_ini_file_loader_1.externalDataInterceptor?.getTokenRecord?.()[webIdentityTokenFile] ?? (0, fs_1.readFileSync)(webIdentityTokenFile, { encoding: "ascii" }),
|
|
22879
22916
|
roleArn,
|
|
22880
22917
|
roleSessionName
|
|
22881
|
-
})();
|
|
22918
|
+
})(awsIdentityProperties);
|
|
22882
22919
|
if (webIdentityTokenFile === process.env[ENV_TOKEN_FILE]) {
|
|
22883
22920
|
(0, client_1.setCredentialFeature)(credentials, "CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN", "h");
|
|
22884
22921
|
}
|
|
@@ -23115,15 +23152,67 @@ var require_dist_cjs62 = __commonJS({
|
|
|
23115
23152
|
init.logger?.debug("@aws-sdk/credential-provider-node - remoteProvider::fromInstanceMetadata");
|
|
23116
23153
|
return fromInstanceMetadata(init);
|
|
23117
23154
|
};
|
|
23155
|
+
function memoizeChain(providers, treatAsExpired) {
|
|
23156
|
+
const chain = internalCreateChain(providers);
|
|
23157
|
+
let activeLock;
|
|
23158
|
+
let passiveLock;
|
|
23159
|
+
let credentials;
|
|
23160
|
+
const provider = async (options) => {
|
|
23161
|
+
if (options?.forceRefresh) {
|
|
23162
|
+
return await chain(options);
|
|
23163
|
+
}
|
|
23164
|
+
if (credentials?.expiration) {
|
|
23165
|
+
if (credentials?.expiration?.getTime() < Date.now()) {
|
|
23166
|
+
credentials = void 0;
|
|
23167
|
+
}
|
|
23168
|
+
}
|
|
23169
|
+
if (activeLock) {
|
|
23170
|
+
await activeLock;
|
|
23171
|
+
} else if (!credentials || treatAsExpired?.(credentials)) {
|
|
23172
|
+
if (credentials) {
|
|
23173
|
+
if (!passiveLock) {
|
|
23174
|
+
passiveLock = chain(options).then((c3) => {
|
|
23175
|
+
credentials = c3;
|
|
23176
|
+
passiveLock = void 0;
|
|
23177
|
+
});
|
|
23178
|
+
}
|
|
23179
|
+
} else {
|
|
23180
|
+
activeLock = chain(options).then((c3) => {
|
|
23181
|
+
credentials = c3;
|
|
23182
|
+
activeLock = void 0;
|
|
23183
|
+
});
|
|
23184
|
+
return provider(options);
|
|
23185
|
+
}
|
|
23186
|
+
}
|
|
23187
|
+
return credentials;
|
|
23188
|
+
};
|
|
23189
|
+
return provider;
|
|
23190
|
+
}
|
|
23191
|
+
var internalCreateChain = (providers) => async (awsIdentityProperties) => {
|
|
23192
|
+
let lastProviderError;
|
|
23193
|
+
for (const provider of providers) {
|
|
23194
|
+
try {
|
|
23195
|
+
return await provider(awsIdentityProperties);
|
|
23196
|
+
} catch (err) {
|
|
23197
|
+
lastProviderError = err;
|
|
23198
|
+
if (err?.tryNextLink) {
|
|
23199
|
+
continue;
|
|
23200
|
+
}
|
|
23201
|
+
throw err;
|
|
23202
|
+
}
|
|
23203
|
+
}
|
|
23204
|
+
throw lastProviderError;
|
|
23205
|
+
};
|
|
23118
23206
|
var multipleCredentialSourceWarningEmitted = false;
|
|
23119
|
-
var defaultProvider = (init = {}) =>
|
|
23120
|
-
|
|
23121
|
-
|
|
23122
|
-
|
|
23123
|
-
|
|
23124
|
-
if (
|
|
23125
|
-
|
|
23126
|
-
|
|
23207
|
+
var defaultProvider = (init = {}) => memoizeChain([
|
|
23208
|
+
async () => {
|
|
23209
|
+
const profile = init.profile ?? process.env[sharedIniFileLoader.ENV_PROFILE];
|
|
23210
|
+
if (profile) {
|
|
23211
|
+
const envStaticCredentialsAreSet = process.env[credentialProviderEnv.ENV_KEY] && process.env[credentialProviderEnv.ENV_SECRET];
|
|
23212
|
+
if (envStaticCredentialsAreSet) {
|
|
23213
|
+
if (!multipleCredentialSourceWarningEmitted) {
|
|
23214
|
+
const warnFn = init.logger?.warn && init.logger?.constructor?.name !== "NoOpLogger" ? init.logger.warn.bind(init.logger) : console.warn;
|
|
23215
|
+
warnFn(`@aws-sdk/credential-provider-node - defaultProvider::fromEnv WARNING:
|
|
23127
23216
|
Multiple credential sources detected:
|
|
23128
23217
|
Both AWS_PROFILE and the pair AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY static credentials are set.
|
|
23129
23218
|
This SDK will proceed with the AWS_PROFILE value.
|
|
@@ -23132,45 +23221,52 @@ var require_dist_cjs62 = __commonJS({
|
|
|
23132
23221
|
Please ensure that your environment only sets either the AWS_PROFILE or the
|
|
23133
23222
|
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY pair.
|
|
23134
23223
|
`);
|
|
23135
|
-
|
|
23224
|
+
multipleCredentialSourceWarningEmitted = true;
|
|
23225
|
+
}
|
|
23136
23226
|
}
|
|
23227
|
+
throw new propertyProvider.CredentialsProviderError("AWS_PROFILE is set, skipping fromEnv provider.", {
|
|
23228
|
+
logger: init.logger,
|
|
23229
|
+
tryNextLink: true
|
|
23230
|
+
});
|
|
23137
23231
|
}
|
|
23138
|
-
|
|
23139
|
-
|
|
23140
|
-
|
|
23232
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromEnv");
|
|
23233
|
+
return credentialProviderEnv.fromEnv(init)();
|
|
23234
|
+
},
|
|
23235
|
+
async (awsIdentityProperties) => {
|
|
23236
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromSSO");
|
|
23237
|
+
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init;
|
|
23238
|
+
if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
|
|
23239
|
+
throw new propertyProvider.CredentialsProviderError("Skipping SSO provider in default chain (inputs do not include SSO fields).", { logger: init.logger });
|
|
23240
|
+
}
|
|
23241
|
+
const { fromSSO } = await Promise.resolve().then(() => __toESM(require_dist_cjs58()));
|
|
23242
|
+
return fromSSO(init)(awsIdentityProperties);
|
|
23243
|
+
},
|
|
23244
|
+
async (awsIdentityProperties) => {
|
|
23245
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromIni");
|
|
23246
|
+
const { fromIni } = await Promise.resolve().then(() => __toESM(require_dist_cjs61()));
|
|
23247
|
+
return fromIni(init)(awsIdentityProperties);
|
|
23248
|
+
},
|
|
23249
|
+
async (awsIdentityProperties) => {
|
|
23250
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromProcess");
|
|
23251
|
+
const { fromProcess } = await Promise.resolve().then(() => __toESM(require_dist_cjs59()));
|
|
23252
|
+
return fromProcess(init)(awsIdentityProperties);
|
|
23253
|
+
},
|
|
23254
|
+
async (awsIdentityProperties) => {
|
|
23255
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromTokenFile");
|
|
23256
|
+
const { fromTokenFile } = await Promise.resolve().then(() => __toESM(require_dist_cjs60()));
|
|
23257
|
+
return fromTokenFile(init)(awsIdentityProperties);
|
|
23258
|
+
},
|
|
23259
|
+
async () => {
|
|
23260
|
+
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::remoteProvider");
|
|
23261
|
+
return (await remoteProvider(init))();
|
|
23262
|
+
},
|
|
23263
|
+
async () => {
|
|
23264
|
+
throw new propertyProvider.CredentialsProviderError("Could not load credentials from any providers", {
|
|
23265
|
+
tryNextLink: false,
|
|
23266
|
+
logger: init.logger
|
|
23141
23267
|
});
|
|
23142
23268
|
}
|
|
23143
|
-
|
|
23144
|
-
return credentialProviderEnv.fromEnv(init)();
|
|
23145
|
-
}, async () => {
|
|
23146
|
-
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromSSO");
|
|
23147
|
-
const { ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession } = init;
|
|
23148
|
-
if (!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession) {
|
|
23149
|
-
throw new propertyProvider.CredentialsProviderError("Skipping SSO provider in default chain (inputs do not include SSO fields).", { logger: init.logger });
|
|
23150
|
-
}
|
|
23151
|
-
const { fromSSO } = await Promise.resolve().then(() => __toESM(require_dist_cjs58()));
|
|
23152
|
-
return fromSSO(init)();
|
|
23153
|
-
}, async () => {
|
|
23154
|
-
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromIni");
|
|
23155
|
-
const { fromIni } = await Promise.resolve().then(() => __toESM(require_dist_cjs61()));
|
|
23156
|
-
return fromIni(init)();
|
|
23157
|
-
}, async () => {
|
|
23158
|
-
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromProcess");
|
|
23159
|
-
const { fromProcess } = await Promise.resolve().then(() => __toESM(require_dist_cjs59()));
|
|
23160
|
-
return fromProcess(init)();
|
|
23161
|
-
}, async () => {
|
|
23162
|
-
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::fromTokenFile");
|
|
23163
|
-
const { fromTokenFile } = await Promise.resolve().then(() => __toESM(require_dist_cjs60()));
|
|
23164
|
-
return fromTokenFile(init)();
|
|
23165
|
-
}, async () => {
|
|
23166
|
-
init.logger?.debug("@aws-sdk/credential-provider-node - defaultProvider::remoteProvider");
|
|
23167
|
-
return (await remoteProvider(init))();
|
|
23168
|
-
}, async () => {
|
|
23169
|
-
throw new propertyProvider.CredentialsProviderError("Could not load credentials from any providers", {
|
|
23170
|
-
tryNextLink: false,
|
|
23171
|
-
logger: init.logger
|
|
23172
|
-
});
|
|
23173
|
-
}), credentialsTreatedAsExpired, credentialsWillNeedRefresh);
|
|
23269
|
+
], credentialsTreatedAsExpired);
|
|
23174
23270
|
var credentialsWillNeedRefresh = (credentials) => credentials?.expiration !== void 0;
|
|
23175
23271
|
var credentialsTreatedAsExpired = (credentials) => credentials?.expiration !== void 0 && credentials.expiration.getTime() - Date.now() < 3e5;
|
|
23176
23272
|
exports2.credentialsTreatedAsExpired = credentialsTreatedAsExpired;
|
|
@@ -23311,7 +23407,7 @@ var require_dist_cjs64 = __commonJS({
|
|
|
23311
23407
|
streamEnded = true;
|
|
23312
23408
|
});
|
|
23313
23409
|
while (!generationEnded) {
|
|
23314
|
-
const value = await new Promise((
|
|
23410
|
+
const value = await new Promise((resolve5) => setTimeout(() => resolve5(records.shift()), 0));
|
|
23315
23411
|
if (value) {
|
|
23316
23412
|
yield value;
|
|
23317
23413
|
}
|
|
@@ -23357,8 +23453,8 @@ var require_ruleset2 = __commonJS({
|
|
|
23357
23453
|
var e3 = "endpoint";
|
|
23358
23454
|
var f3 = "tree";
|
|
23359
23455
|
var g3 = "PartitionResult";
|
|
23360
|
-
var h3 = { [s3]: false, "type": "
|
|
23361
|
-
var i3 = { [s3]: true, "default": false, "type": "
|
|
23456
|
+
var h3 = { [s3]: false, "type": "string" };
|
|
23457
|
+
var i3 = { [s3]: true, "default": false, "type": "boolean" };
|
|
23362
23458
|
var j3 = { [v3]: "Endpoint" };
|
|
23363
23459
|
var k3 = { [t3]: c3, [u3]: [{ [v3]: "UseFIPS" }, true] };
|
|
23364
23460
|
var l3 = { [t3]: c3, [u3]: [{ [v3]: "UseDualStack" }, true] };
|
|
@@ -23931,6 +24027,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
23931
24027
|
exports2.CitationLocation = void 0;
|
|
23932
24028
|
(function(CitationLocation) {
|
|
23933
24029
|
CitationLocation.visit = (value, visitor) => {
|
|
24030
|
+
if (value.web !== void 0)
|
|
24031
|
+
return visitor.web(value.web);
|
|
23934
24032
|
if (value.documentChar !== void 0)
|
|
23935
24033
|
return visitor.documentChar(value.documentChar);
|
|
23936
24034
|
if (value.documentPage !== void 0)
|
|
@@ -24083,6 +24181,9 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24083
24181
|
ERROR: "error",
|
|
24084
24182
|
SUCCESS: "success"
|
|
24085
24183
|
};
|
|
24184
|
+
var ToolUseType = {
|
|
24185
|
+
SERVER_TOOL_USE: "server_tool_use"
|
|
24186
|
+
};
|
|
24086
24187
|
exports2.ContentBlock = void 0;
|
|
24087
24188
|
(function(ContentBlock) {
|
|
24088
24189
|
ContentBlock.visit = (value, visitor) => {
|
|
@@ -24162,6 +24263,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24162
24263
|
Tool.visit = (value, visitor) => {
|
|
24163
24264
|
if (value.toolSpec !== void 0)
|
|
24164
24265
|
return visitor.toolSpec(value.toolSpec);
|
|
24266
|
+
if (value.systemTool !== void 0)
|
|
24267
|
+
return visitor.systemTool(value.systemTool);
|
|
24165
24268
|
if (value.cachePoint !== void 0)
|
|
24166
24269
|
return visitor.cachePoint(value.cachePoint);
|
|
24167
24270
|
return visitor._(value.$unknown[0], value.$unknown[1]);
|
|
@@ -24241,6 +24344,14 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24241
24344
|
return visitor._(value.$unknown[0], value.$unknown[1]);
|
|
24242
24345
|
};
|
|
24243
24346
|
})(exports2.ReasoningContentBlockDelta || (exports2.ReasoningContentBlockDelta = {}));
|
|
24347
|
+
exports2.ToolResultBlockDelta = void 0;
|
|
24348
|
+
(function(ToolResultBlockDelta) {
|
|
24349
|
+
ToolResultBlockDelta.visit = (value, visitor) => {
|
|
24350
|
+
if (value.text !== void 0)
|
|
24351
|
+
return visitor.text(value.text);
|
|
24352
|
+
return visitor._(value.$unknown[0], value.$unknown[1]);
|
|
24353
|
+
};
|
|
24354
|
+
})(exports2.ToolResultBlockDelta || (exports2.ToolResultBlockDelta = {}));
|
|
24244
24355
|
exports2.ContentBlockDelta = void 0;
|
|
24245
24356
|
(function(ContentBlockDelta) {
|
|
24246
24357
|
ContentBlockDelta.visit = (value, visitor) => {
|
|
@@ -24248,6 +24359,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24248
24359
|
return visitor.text(value.text);
|
|
24249
24360
|
if (value.toolUse !== void 0)
|
|
24250
24361
|
return visitor.toolUse(value.toolUse);
|
|
24362
|
+
if (value.toolResult !== void 0)
|
|
24363
|
+
return visitor.toolResult(value.toolResult);
|
|
24251
24364
|
if (value.reasoningContent !== void 0)
|
|
24252
24365
|
return visitor.reasoningContent(value.reasoningContent);
|
|
24253
24366
|
if (value.citation !== void 0)
|
|
@@ -24260,6 +24373,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24260
24373
|
ContentBlockStart.visit = (value, visitor) => {
|
|
24261
24374
|
if (value.toolUse !== void 0)
|
|
24262
24375
|
return visitor.toolUse(value.toolUse);
|
|
24376
|
+
if (value.toolResult !== void 0)
|
|
24377
|
+
return visitor.toolResult(value.toolResult);
|
|
24263
24378
|
return visitor._(value.$unknown[0], value.$unknown[1]);
|
|
24264
24379
|
};
|
|
24265
24380
|
})(exports2.ContentBlockStart || (exports2.ContentBlockStart = {}));
|
|
@@ -24649,6 +24764,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
24649
24764
|
return { text: obj.text };
|
|
24650
24765
|
if (obj.toolUse !== void 0)
|
|
24651
24766
|
return { toolUse: obj.toolUse };
|
|
24767
|
+
if (obj.toolResult !== void 0)
|
|
24768
|
+
return { toolResult: obj.toolResult.map((item) => item) };
|
|
24652
24769
|
if (obj.reasoningContent !== void 0)
|
|
24653
24770
|
return { reasoningContent: smithyClient.SENSITIVE_STRING };
|
|
24654
24771
|
if (obj.citation !== void 0)
|
|
@@ -25744,6 +25861,7 @@ var require_dist_cjs65 = __commonJS({
|
|
|
25744
25861
|
var se_Tool = (input, context) => {
|
|
25745
25862
|
return exports2.Tool.visit(input, {
|
|
25746
25863
|
cachePoint: (value) => ({ cachePoint: smithyClient._json(value) }),
|
|
25864
|
+
systemTool: (value) => ({ systemTool: smithyClient._json(value) }),
|
|
25747
25865
|
toolSpec: (value) => ({ toolSpec: se_ToolSpecification(value) }),
|
|
25748
25866
|
_: (name14, value) => ({ [name14]: value })
|
|
25749
25867
|
});
|
|
@@ -25764,7 +25882,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
25764
25882
|
return smithyClient.take(input, {
|
|
25765
25883
|
content: (_2) => se_ToolResultContentBlocks(_2, context),
|
|
25766
25884
|
status: [],
|
|
25767
|
-
toolUseId: []
|
|
25885
|
+
toolUseId: [],
|
|
25886
|
+
type: []
|
|
25768
25887
|
});
|
|
25769
25888
|
};
|
|
25770
25889
|
var se_ToolResultContentBlock = (input, context) => {
|
|
@@ -25798,7 +25917,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
25798
25917
|
return smithyClient.take(input, {
|
|
25799
25918
|
input: (_2) => se_Document(_2),
|
|
25800
25919
|
name: [],
|
|
25801
|
-
toolUseId: []
|
|
25920
|
+
toolUseId: [],
|
|
25921
|
+
type: []
|
|
25802
25922
|
});
|
|
25803
25923
|
};
|
|
25804
25924
|
var se_VideoBlock = (input, context) => {
|
|
@@ -25906,6 +26026,11 @@ var require_dist_cjs65 = __commonJS({
|
|
|
25906
26026
|
if (smithyClient.expectString(output.text) !== void 0) {
|
|
25907
26027
|
return { text: smithyClient.expectString(output.text) };
|
|
25908
26028
|
}
|
|
26029
|
+
if (output.toolResult != null) {
|
|
26030
|
+
return {
|
|
26031
|
+
toolResult: smithyClient._json(output.toolResult)
|
|
26032
|
+
};
|
|
26033
|
+
}
|
|
25909
26034
|
if (output.toolUse != null) {
|
|
25910
26035
|
return {
|
|
25911
26036
|
toolUse: smithyClient._json(output.toolUse)
|
|
@@ -26251,7 +26376,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
26251
26376
|
return smithyClient.take(output, {
|
|
26252
26377
|
content: (_2) => de_ToolResultContentBlocks(_2, context),
|
|
26253
26378
|
status: smithyClient.expectString,
|
|
26254
|
-
toolUseId: smithyClient.expectString
|
|
26379
|
+
toolUseId: smithyClient.expectString,
|
|
26380
|
+
type: smithyClient.expectString
|
|
26255
26381
|
});
|
|
26256
26382
|
};
|
|
26257
26383
|
var de_ToolResultContentBlock = (output, context) => {
|
|
@@ -26290,7 +26416,8 @@ var require_dist_cjs65 = __commonJS({
|
|
|
26290
26416
|
return smithyClient.take(output, {
|
|
26291
26417
|
input: (_2) => de_Document(_2),
|
|
26292
26418
|
name: smithyClient.expectString,
|
|
26293
|
-
toolUseId: smithyClient.expectString
|
|
26419
|
+
toolUseId: smithyClient.expectString,
|
|
26420
|
+
type: smithyClient.expectString
|
|
26294
26421
|
});
|
|
26295
26422
|
};
|
|
26296
26423
|
var de_VideoBlock = (output, context) => {
|
|
@@ -26572,6 +26699,7 @@ var require_dist_cjs65 = __commonJS({
|
|
|
26572
26699
|
exports2.SystemContentBlockFilterSensitiveLog = SystemContentBlockFilterSensitiveLog;
|
|
26573
26700
|
exports2.ThrottlingException = ThrottlingException;
|
|
26574
26701
|
exports2.ToolResultStatus = ToolResultStatus;
|
|
26702
|
+
exports2.ToolUseType = ToolUseType;
|
|
26575
26703
|
exports2.Trace = Trace;
|
|
26576
26704
|
exports2.ValidationException = ValidationException;
|
|
26577
26705
|
exports2.VideoFormat = VideoFormat;
|
|
@@ -26591,16 +26719,16 @@ function prepareTools(mode) {
|
|
|
26591
26719
|
}
|
|
26592
26720
|
const toolWarnings = [];
|
|
26593
26721
|
const bedrockTools = [];
|
|
26594
|
-
for (const
|
|
26595
|
-
if (
|
|
26596
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
26722
|
+
for (const tool4 of tools2) {
|
|
26723
|
+
if (tool4.type === "provider-defined") {
|
|
26724
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool4 });
|
|
26597
26725
|
} else {
|
|
26598
26726
|
bedrockTools.push({
|
|
26599
26727
|
toolSpec: {
|
|
26600
|
-
name:
|
|
26601
|
-
description:
|
|
26728
|
+
name: tool4.name,
|
|
26729
|
+
description: tool4.description,
|
|
26602
26730
|
inputSchema: {
|
|
26603
|
-
json:
|
|
26731
|
+
json: tool4.parameters
|
|
26604
26732
|
}
|
|
26605
26733
|
}
|
|
26606
26734
|
});
|
|
@@ -27759,6 +27887,162 @@ var init_BytePairEncodingCore = __esm({
|
|
|
27759
27887
|
}
|
|
27760
27888
|
});
|
|
27761
27889
|
|
|
27890
|
+
// node_modules/gpt-tokenizer/esm/functionCalling.js
|
|
27891
|
+
function countMessageTokens(message, countStringTokens) {
|
|
27892
|
+
let tokens = 0;
|
|
27893
|
+
if (message.role) {
|
|
27894
|
+
tokens += countStringTokens(message.role);
|
|
27895
|
+
}
|
|
27896
|
+
if (message.content) {
|
|
27897
|
+
tokens += countStringTokens(message.content);
|
|
27898
|
+
}
|
|
27899
|
+
if (message.name) {
|
|
27900
|
+
tokens += countStringTokens(message.name) + MESSAGE_NAME_TOKEN_OVERHEAD;
|
|
27901
|
+
}
|
|
27902
|
+
if (message.function_call) {
|
|
27903
|
+
const { name: name14, arguments: args } = message.function_call;
|
|
27904
|
+
if (name14) {
|
|
27905
|
+
tokens += countStringTokens(name14);
|
|
27906
|
+
}
|
|
27907
|
+
if (args) {
|
|
27908
|
+
tokens += countStringTokens(args);
|
|
27909
|
+
}
|
|
27910
|
+
tokens += FUNCTION_CALL_METADATA_TOKEN_OVERHEAD;
|
|
27911
|
+
}
|
|
27912
|
+
tokens += MESSAGE_TOKEN_OVERHEAD;
|
|
27913
|
+
if (message.role === "function") {
|
|
27914
|
+
tokens -= FUNCTION_ROLE_TOKEN_DISCOUNT;
|
|
27915
|
+
}
|
|
27916
|
+
return tokens;
|
|
27917
|
+
}
|
|
27918
|
+
function formatObjectProperties(obj, indent, formatType) {
|
|
27919
|
+
if (!obj.properties) {
|
|
27920
|
+
return "";
|
|
27921
|
+
}
|
|
27922
|
+
const lines = [];
|
|
27923
|
+
const requiredParams = new Set(obj.required ?? []);
|
|
27924
|
+
const indentString = " ".repeat(indent);
|
|
27925
|
+
for (const [name14, param] of Object.entries(obj.properties)) {
|
|
27926
|
+
if (param.description && indent < 2) {
|
|
27927
|
+
lines.push(`${indentString}// ${param.description}`);
|
|
27928
|
+
}
|
|
27929
|
+
const isRequired = requiredParams.has(name14);
|
|
27930
|
+
const formattedType = formatType(param, indent);
|
|
27931
|
+
lines.push(`${indentString}${name14}${isRequired ? "" : "?"}: ${formattedType},`);
|
|
27932
|
+
}
|
|
27933
|
+
return lines.join("\n");
|
|
27934
|
+
}
|
|
27935
|
+
function formatFunctionType(param, indent) {
|
|
27936
|
+
switch (param.type) {
|
|
27937
|
+
case "string":
|
|
27938
|
+
return param.enum?.map((value) => JSON.stringify(value)).join(" | ") ?? "string";
|
|
27939
|
+
case "integer":
|
|
27940
|
+
case "number":
|
|
27941
|
+
return param.enum?.map((value) => `${value}`).join(" | ") ?? "number";
|
|
27942
|
+
case "boolean":
|
|
27943
|
+
return "boolean";
|
|
27944
|
+
case "null":
|
|
27945
|
+
return "null";
|
|
27946
|
+
case "array":
|
|
27947
|
+
return param.items ? `${formatFunctionType(param.items, indent)}[]` : "any[]";
|
|
27948
|
+
case "object": {
|
|
27949
|
+
const inner = formatObjectProperties(param, indent + 2, formatFunctionType);
|
|
27950
|
+
const closingIndent = " ".repeat(indent);
|
|
27951
|
+
return `{
|
|
27952
|
+
${inner}
|
|
27953
|
+
${closingIndent}}`;
|
|
27954
|
+
}
|
|
27955
|
+
default:
|
|
27956
|
+
return "any";
|
|
27957
|
+
}
|
|
27958
|
+
}
|
|
27959
|
+
function formatFunctionDefinitions(functions) {
|
|
27960
|
+
const lines = ["namespace functions {", ""];
|
|
27961
|
+
for (const fn of functions) {
|
|
27962
|
+
if (fn.description) {
|
|
27963
|
+
lines.push(`// ${fn.description}`);
|
|
27964
|
+
}
|
|
27965
|
+
const { parameters } = fn;
|
|
27966
|
+
const properties = parameters?.properties;
|
|
27967
|
+
if (!parameters || !properties || Object.keys(properties).length === 0) {
|
|
27968
|
+
lines.push(`type ${fn.name} = () => any;`);
|
|
27969
|
+
} else {
|
|
27970
|
+
lines.push(`type ${fn.name} = (_: {`);
|
|
27971
|
+
const formattedProperties = formatObjectProperties(parameters, 0, formatFunctionType);
|
|
27972
|
+
if (formattedProperties.length > 0) {
|
|
27973
|
+
lines.push(formattedProperties);
|
|
27974
|
+
}
|
|
27975
|
+
lines.push("}) => any;");
|
|
27976
|
+
}
|
|
27977
|
+
lines.push("");
|
|
27978
|
+
}
|
|
27979
|
+
lines.push("} // namespace functions");
|
|
27980
|
+
return lines.join("\n");
|
|
27981
|
+
}
|
|
27982
|
+
function estimateTokensInFunctions(functions, countStringTokens) {
|
|
27983
|
+
const formatted = formatFunctionDefinitions(functions);
|
|
27984
|
+
let tokens = countStringTokens(formatted);
|
|
27985
|
+
tokens += FUNCTION_DEFINITION_TOKEN_OVERHEAD;
|
|
27986
|
+
return tokens;
|
|
27987
|
+
}
|
|
27988
|
+
function padSystemMessage(message, hasFunctions, isSystemPadded) {
|
|
27989
|
+
if (!hasFunctions || isSystemPadded || message.role !== "system") {
|
|
27990
|
+
return message;
|
|
27991
|
+
}
|
|
27992
|
+
if (!message.content || message.content.endsWith(NEWLINE)) {
|
|
27993
|
+
return message;
|
|
27994
|
+
}
|
|
27995
|
+
return {
|
|
27996
|
+
...message,
|
|
27997
|
+
content: `${message.content}${NEWLINE}`
|
|
27998
|
+
};
|
|
27999
|
+
}
|
|
28000
|
+
function computeChatCompletionTokenCount(request, countStringTokens) {
|
|
28001
|
+
const { messages, functions, function_call: functionCall } = request;
|
|
28002
|
+
const hasFunctions = Boolean(functions && functions.length > 0);
|
|
28003
|
+
let paddedSystem = false;
|
|
28004
|
+
let total = 0;
|
|
28005
|
+
for (const message of messages) {
|
|
28006
|
+
const messageToCount = padSystemMessage(message, hasFunctions, paddedSystem);
|
|
28007
|
+
if (messageToCount !== message && message.role === "system") {
|
|
28008
|
+
paddedSystem = true;
|
|
28009
|
+
} else if (message.role === "system" && hasFunctions && !paddedSystem) {
|
|
28010
|
+
paddedSystem = true;
|
|
28011
|
+
}
|
|
28012
|
+
total += countMessageTokens(messageToCount, countStringTokens);
|
|
28013
|
+
}
|
|
28014
|
+
total += COMPLETION_REQUEST_TOKEN_OVERHEAD;
|
|
28015
|
+
if (hasFunctions && functions) {
|
|
28016
|
+
total += estimateTokensInFunctions(functions, countStringTokens);
|
|
28017
|
+
if (messages.some((message) => message.role === "system")) {
|
|
28018
|
+
total -= SYSTEM_FUNCTION_TOKEN_DEDUCTION;
|
|
28019
|
+
}
|
|
28020
|
+
}
|
|
28021
|
+
if (functionCall && functionCall !== "auto") {
|
|
28022
|
+
if (functionCall === "none") {
|
|
28023
|
+
total += FUNCTION_CALL_NONE_TOKEN_OVERHEAD;
|
|
28024
|
+
} else if (typeof functionCall === "object" && functionCall.name) {
|
|
28025
|
+
total += countStringTokens(functionCall.name) + FUNCTION_CALL_NAME_TOKEN_OVERHEAD;
|
|
28026
|
+
}
|
|
28027
|
+
}
|
|
28028
|
+
return total;
|
|
28029
|
+
}
|
|
28030
|
+
var MESSAGE_TOKEN_OVERHEAD, MESSAGE_NAME_TOKEN_OVERHEAD, FUNCTION_ROLE_TOKEN_DISCOUNT, FUNCTION_CALL_METADATA_TOKEN_OVERHEAD, FUNCTION_DEFINITION_TOKEN_OVERHEAD, COMPLETION_REQUEST_TOKEN_OVERHEAD, FUNCTION_CALL_NAME_TOKEN_OVERHEAD, FUNCTION_CALL_NONE_TOKEN_OVERHEAD, SYSTEM_FUNCTION_TOKEN_DEDUCTION, NEWLINE;
|
|
28031
|
+
var init_functionCalling = __esm({
|
|
28032
|
+
"node_modules/gpt-tokenizer/esm/functionCalling.js"() {
|
|
28033
|
+
MESSAGE_TOKEN_OVERHEAD = 3;
|
|
28034
|
+
MESSAGE_NAME_TOKEN_OVERHEAD = 1;
|
|
28035
|
+
FUNCTION_ROLE_TOKEN_DISCOUNT = 2;
|
|
28036
|
+
FUNCTION_CALL_METADATA_TOKEN_OVERHEAD = 3;
|
|
28037
|
+
FUNCTION_DEFINITION_TOKEN_OVERHEAD = 9;
|
|
28038
|
+
COMPLETION_REQUEST_TOKEN_OVERHEAD = 3;
|
|
28039
|
+
FUNCTION_CALL_NAME_TOKEN_OVERHEAD = 4;
|
|
28040
|
+
FUNCTION_CALL_NONE_TOKEN_OVERHEAD = 1;
|
|
28041
|
+
SYSTEM_FUNCTION_TOKEN_DEDUCTION = 4;
|
|
28042
|
+
NEWLINE = "\n";
|
|
28043
|
+
}
|
|
28044
|
+
});
|
|
28045
|
+
|
|
27762
28046
|
// node_modules/gpt-tokenizer/esm/modelsChatEnabled.gen.js
|
|
27763
28047
|
var chatEnabledModels;
|
|
27764
28048
|
var init_modelsChatEnabled_gen = __esm({
|
|
@@ -27772,11 +28056,12 @@ var modelsMap_exports = {};
|
|
|
27772
28056
|
__export(modelsMap_exports, {
|
|
27773
28057
|
cl100k_base: () => cl100k_base,
|
|
27774
28058
|
o200k_base: () => o200k_base,
|
|
28059
|
+
o200k_harmony: () => o200k_harmony,
|
|
27775
28060
|
p50k_base: () => p50k_base,
|
|
27776
28061
|
p50k_edit: () => p50k_edit,
|
|
27777
28062
|
r50k_base: () => r50k_base
|
|
27778
28063
|
});
|
|
27779
|
-
var p50k_base, r50k_base, p50k_edit, cl100k_base, o200k_base;
|
|
28064
|
+
var p50k_base, r50k_base, p50k_edit, cl100k_base, o200k_base, o200k_harmony;
|
|
27780
28065
|
var init_modelsMap = __esm({
|
|
27781
28066
|
"node_modules/gpt-tokenizer/esm/modelsMap.js"() {
|
|
27782
28067
|
p50k_base = [
|
|
@@ -27851,11 +28136,15 @@ var init_modelsMap = __esm({
|
|
|
27851
28136
|
"davinci-002"
|
|
27852
28137
|
];
|
|
27853
28138
|
o200k_base = [];
|
|
28139
|
+
o200k_harmony = [
|
|
28140
|
+
"gpt-oss-20b",
|
|
28141
|
+
"gpt-oss-120b"
|
|
28142
|
+
];
|
|
27854
28143
|
}
|
|
27855
28144
|
});
|
|
27856
28145
|
|
|
27857
28146
|
// node_modules/gpt-tokenizer/esm/specialTokens.js
|
|
27858
|
-
var EndOfText, FimPrefix, FimMiddle, FimSuffix, ImStart, ImEnd, ImSep, EndOfPrompt;
|
|
28147
|
+
var EndOfText, FimPrefix, FimMiddle, FimSuffix, ImStart, ImEnd, ImSep, EndOfPrompt, HarmonyStartOfText, HarmonyStart, HarmonyEnd, HarmonyMessage, HarmonyChannel, HarmonyReturn, HarmonyConstrain, HarmonyCall;
|
|
27859
28148
|
var init_specialTokens = __esm({
|
|
27860
28149
|
"node_modules/gpt-tokenizer/esm/specialTokens.js"() {
|
|
27861
28150
|
EndOfText = "<|endoftext|>";
|
|
@@ -27866,6 +28155,14 @@ var init_specialTokens = __esm({
|
|
|
27866
28155
|
ImEnd = "<|im_end|>";
|
|
27867
28156
|
ImSep = "<|im_sep|>";
|
|
27868
28157
|
EndOfPrompt = "<|endofprompt|>";
|
|
28158
|
+
HarmonyStartOfText = "<|startoftext|>";
|
|
28159
|
+
HarmonyStart = "<|start|>";
|
|
28160
|
+
HarmonyEnd = "<|end|>";
|
|
28161
|
+
HarmonyMessage = "<|message|>";
|
|
28162
|
+
HarmonyChannel = "<|channel|>";
|
|
28163
|
+
HarmonyReturn = "<|return|>";
|
|
28164
|
+
HarmonyConstrain = "<|constrain|>";
|
|
28165
|
+
HarmonyCall = "<|call|>";
|
|
27869
28166
|
}
|
|
27870
28167
|
});
|
|
27871
28168
|
|
|
@@ -27892,11 +28189,16 @@ var init_mapping = __esm({
|
|
|
27892
28189
|
});
|
|
27893
28190
|
|
|
27894
28191
|
// node_modules/gpt-tokenizer/esm/encodingParams/constants.js
|
|
27895
|
-
var R50K_TOKEN_SPLIT_REGEX,
|
|
28192
|
+
var R50K_TOKEN_SPLIT_REGEX, CONTRACTION_SUFFIX_PATTERN, OPTIONAL_CONTRACTION_SUFFIX, CL100K_TOKEN_SPLIT_PATTERN, CL100K_TOKEN_SPLIT_REGEX, O200K_TOKEN_SPLIT_PATTERN, O200K_TOKEN_SPLIT_REGEX;
|
|
27896
28193
|
var init_constants2 = __esm({
|
|
27897
28194
|
"node_modules/gpt-tokenizer/esm/encodingParams/constants.js"() {
|
|
27898
28195
|
R50K_TOKEN_SPLIT_REGEX = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu;
|
|
27899
|
-
|
|
28196
|
+
CONTRACTION_SUFFIX_PATTERN = String.raw`'(?:[sS]|[dD]|[mM]|[tT]|[lL][lL]|[vV][eE]|[rR][eE])`;
|
|
28197
|
+
OPTIONAL_CONTRACTION_SUFFIX = String.raw`(?:${CONTRACTION_SUFFIX_PATTERN})?`;
|
|
28198
|
+
CL100K_TOKEN_SPLIT_PATTERN = String.raw`${CONTRACTION_SUFFIX_PATTERN}|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s+$|\s*[\r\n]|\s+(?!\S)|\s`;
|
|
28199
|
+
CL100K_TOKEN_SPLIT_REGEX = new RegExp(CL100K_TOKEN_SPLIT_PATTERN, "gu");
|
|
28200
|
+
O200K_TOKEN_SPLIT_PATTERN = String.raw`[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]*[\p{Ll}\p{Lm}\p{Lo}\p{M}]+${OPTIONAL_CONTRACTION_SUFFIX}|[^\r\n\p{L}\p{N}]?[\p{Lu}\p{Lt}\p{Lm}\p{Lo}\p{M}]+[\p{Ll}\p{Lm}\p{Lo}\p{M}]*${OPTIONAL_CONTRACTION_SUFFIX}|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n/]*|\s*[\r\n]+|\s+(?!\S)|\s+`;
|
|
28201
|
+
O200K_TOKEN_SPLIT_REGEX = new RegExp(O200K_TOKEN_SPLIT_PATTERN, "gu");
|
|
27900
28202
|
}
|
|
27901
28203
|
});
|
|
27902
28204
|
|
|
@@ -27913,7 +28215,7 @@ function Cl100KBase(bytePairRankDecoder) {
|
|
|
27913
28215
|
[EndOfPrompt, 100276]
|
|
27914
28216
|
]);
|
|
27915
28217
|
return {
|
|
27916
|
-
tokenSplitRegex:
|
|
28218
|
+
tokenSplitRegex: CL100K_TOKEN_SPLIT_REGEX,
|
|
27917
28219
|
bytePairRankDecoder,
|
|
27918
28220
|
specialTokensEncoder: specialTokenMapping
|
|
27919
28221
|
};
|
|
@@ -27927,26 +28229,69 @@ var init_cl100k_base = __esm({
|
|
|
27927
28229
|
|
|
27928
28230
|
// node_modules/gpt-tokenizer/esm/encodingParams/o200k_base.js
|
|
27929
28231
|
function O200KBase(bytePairRankDecoder) {
|
|
27930
|
-
const specialTokenMapping = /* @__PURE__ */ new Map([
|
|
27931
|
-
[EndOfText, 199999],
|
|
27932
|
-
[FimPrefix, 2e5],
|
|
27933
|
-
[FimMiddle, 200001],
|
|
27934
|
-
[FimSuffix, 200002],
|
|
27935
|
-
[ImStart, 200003],
|
|
27936
|
-
[ImEnd, 200004],
|
|
27937
|
-
[ImSep, 200005],
|
|
27938
|
-
[EndOfPrompt, 200006]
|
|
27939
|
-
]);
|
|
27940
28232
|
return {
|
|
27941
|
-
tokenSplitRegex:
|
|
28233
|
+
tokenSplitRegex: O200K_TOKEN_SPLIT_REGEX,
|
|
27942
28234
|
bytePairRankDecoder,
|
|
27943
|
-
specialTokensEncoder:
|
|
28235
|
+
specialTokensEncoder: createO200KSpecialTokenMap()
|
|
27944
28236
|
};
|
|
27945
28237
|
}
|
|
28238
|
+
var O200K_BASE_SPECIAL_TOKEN_ENTRIES, createO200KSpecialTokenMap;
|
|
27946
28239
|
var init_o200k_base2 = __esm({
|
|
27947
28240
|
"node_modules/gpt-tokenizer/esm/encodingParams/o200k_base.js"() {
|
|
27948
28241
|
init_specialTokens();
|
|
27949
28242
|
init_constants2();
|
|
28243
|
+
O200K_BASE_SPECIAL_TOKEN_ENTRIES = [
|
|
28244
|
+
[EndOfText, 199999],
|
|
28245
|
+
[FimPrefix, 2e5],
|
|
28246
|
+
[FimMiddle, 200001],
|
|
28247
|
+
[FimSuffix, 200002],
|
|
28248
|
+
[ImStart, 200003],
|
|
28249
|
+
[ImEnd, 200004],
|
|
28250
|
+
[ImSep, 200005],
|
|
28251
|
+
[EndOfPrompt, 200006]
|
|
28252
|
+
];
|
|
28253
|
+
createO200KSpecialTokenMap = () => new Map(O200K_BASE_SPECIAL_TOKEN_ENTRIES);
|
|
28254
|
+
}
|
|
28255
|
+
});
|
|
28256
|
+
|
|
28257
|
+
// node_modules/gpt-tokenizer/esm/encodingParams/o200k_harmony.js
|
|
28258
|
+
function O200KHarmony(bytePairRankDecoder) {
|
|
28259
|
+
const specialTokensEncoder = new Map(STATIC_SPECIAL_TOKEN_ENTRIES);
|
|
28260
|
+
for (let tokenId = RESERVED_TOKEN_RANGE_START; tokenId < RESERVED_TOKEN_RANGE_END; tokenId += 1) {
|
|
28261
|
+
specialTokensEncoder.set(`<|reserved_${tokenId}|>`, tokenId);
|
|
28262
|
+
}
|
|
28263
|
+
specialTokensEncoder.set(EndOfPrompt, 200018);
|
|
28264
|
+
return {
|
|
28265
|
+
tokenSplitRegex: O200K_TOKEN_SPLIT_REGEX,
|
|
28266
|
+
bytePairRankDecoder,
|
|
28267
|
+
specialTokensEncoder,
|
|
28268
|
+
chatFormatter: "harmony"
|
|
28269
|
+
};
|
|
28270
|
+
}
|
|
28271
|
+
var RESERVED_TOKEN_RANGE_START, RESERVED_TOKEN_RANGE_END, STATIC_SPECIAL_TOKEN_ENTRIES;
|
|
28272
|
+
var init_o200k_harmony = __esm({
|
|
28273
|
+
"node_modules/gpt-tokenizer/esm/encodingParams/o200k_harmony.js"() {
|
|
28274
|
+
init_specialTokens();
|
|
28275
|
+
init_constants2();
|
|
28276
|
+
RESERVED_TOKEN_RANGE_START = 200013;
|
|
28277
|
+
RESERVED_TOKEN_RANGE_END = 201088;
|
|
28278
|
+
STATIC_SPECIAL_TOKEN_ENTRIES = [
|
|
28279
|
+
[HarmonyStartOfText, 199998],
|
|
28280
|
+
[EndOfText, 199999],
|
|
28281
|
+
["<|reserved_200000|>", 2e5],
|
|
28282
|
+
["<|reserved_200001|>", 200001],
|
|
28283
|
+
[HarmonyReturn, 200002],
|
|
28284
|
+
[HarmonyConstrain, 200003],
|
|
28285
|
+
["<|reserved_200004|>", 200004],
|
|
28286
|
+
[HarmonyChannel, 200005],
|
|
28287
|
+
[HarmonyStart, 200006],
|
|
28288
|
+
[HarmonyEnd, 200007],
|
|
28289
|
+
[HarmonyMessage, 200008],
|
|
28290
|
+
["<|reserved_200009|>", 200009],
|
|
28291
|
+
["<|reserved_200010|>", 200010],
|
|
28292
|
+
["<|reserved_200011|>", 200011],
|
|
28293
|
+
[HarmonyCall, 200012]
|
|
28294
|
+
];
|
|
27950
28295
|
}
|
|
27951
28296
|
});
|
|
27952
28297
|
|
|
@@ -28020,6 +28365,8 @@ function getEncodingParams(encodingName, getMergeableRanks) {
|
|
|
28020
28365
|
return Cl100KBase(mergeableBytePairRanks);
|
|
28021
28366
|
case "o200k_base":
|
|
28022
28367
|
return O200KBase(mergeableBytePairRanks);
|
|
28368
|
+
case "o200k_harmony":
|
|
28369
|
+
return O200KHarmony(mergeableBytePairRanks);
|
|
28023
28370
|
default:
|
|
28024
28371
|
throw new Error(`Unknown encoding name: ${encodingName}`);
|
|
28025
28372
|
}
|
|
@@ -28028,6 +28375,7 @@ var init_modelParams = __esm({
|
|
|
28028
28375
|
"node_modules/gpt-tokenizer/esm/modelParams.js"() {
|
|
28029
28376
|
init_cl100k_base();
|
|
28030
28377
|
init_o200k_base2();
|
|
28378
|
+
init_o200k_harmony();
|
|
28031
28379
|
init_p50k_base();
|
|
28032
28380
|
init_p50k_edit();
|
|
28033
28381
|
init_r50k_base();
|
|
@@ -28040,6 +28388,7 @@ var init_GptEncoding = __esm({
|
|
|
28040
28388
|
"node_modules/gpt-tokenizer/esm/GptEncoding.js"() {
|
|
28041
28389
|
init_BytePairEncodingCore();
|
|
28042
28390
|
init_constants();
|
|
28391
|
+
init_functionCalling();
|
|
28043
28392
|
init_mapping();
|
|
28044
28393
|
init_modelParams();
|
|
28045
28394
|
init_specialTokens();
|
|
@@ -28058,8 +28407,10 @@ var init_GptEncoding = __esm({
|
|
|
28058
28407
|
specialTokensSet;
|
|
28059
28408
|
allSpecialTokenRegex;
|
|
28060
28409
|
defaultSpecialTokenConfig;
|
|
28410
|
+
chatFormatter;
|
|
28411
|
+
countChatCompletionTokens;
|
|
28061
28412
|
vocabularySize;
|
|
28062
|
-
constructor({ bytePairRankDecoder: mergeableBytePairRanks, specialTokensEncoder, expectedVocabularySize, modelName, modelSpec, ...rest }) {
|
|
28413
|
+
constructor({ bytePairRankDecoder: mergeableBytePairRanks, specialTokensEncoder, expectedVocabularySize, modelName, modelSpec, chatFormatter, ...rest }) {
|
|
28063
28414
|
this.specialTokensEncoder = specialTokensEncoder;
|
|
28064
28415
|
this.specialTokensSet = new Set(this.specialTokensEncoder.keys());
|
|
28065
28416
|
this.allSpecialTokenRegex = getSpecialTokenRegex(this.specialTokensSet);
|
|
@@ -28092,8 +28443,69 @@ var init_GptEncoding = __esm({
|
|
|
28092
28443
|
this.setMergeCacheSize = this.setMergeCacheSize.bind(this);
|
|
28093
28444
|
this.clearMergeCache = this.clearMergeCache.bind(this);
|
|
28094
28445
|
this.estimateCost = this.estimateCost.bind(this);
|
|
28446
|
+
if (modelSpec?.supported_features?.includes("function_calling")) {
|
|
28447
|
+
this.countChatCompletionTokens = this.countChatCompletionTokensInternal.bind(this);
|
|
28448
|
+
}
|
|
28095
28449
|
this.modelName = modelName;
|
|
28096
28450
|
this.modelSpec = modelSpec;
|
|
28451
|
+
this.chatFormatter = chatFormatter ?? "chatml";
|
|
28452
|
+
}
|
|
28453
|
+
*encodeHarmonyChatGenerator(chat, encodeOptions) {
|
|
28454
|
+
const harmonyStart = this.specialTokensEncoder.get(HarmonyStart);
|
|
28455
|
+
const harmonyMessage = this.specialTokensEncoder.get(HarmonyMessage);
|
|
28456
|
+
const harmonyEnd = this.specialTokensEncoder.get(HarmonyEnd);
|
|
28457
|
+
const harmonyReturn = this.specialTokensEncoder.get(HarmonyReturn);
|
|
28458
|
+
const harmonyCall = this.specialTokensEncoder.get(HarmonyCall);
|
|
28459
|
+
const harmonyChannel = this.specialTokensEncoder.get(HarmonyChannel);
|
|
28460
|
+
const harmonyConstrain = this.specialTokensEncoder.get(HarmonyConstrain);
|
|
28461
|
+
if (harmonyStart === void 0 || harmonyMessage === void 0 || harmonyEnd === void 0 || harmonyReturn === void 0 || harmonyCall === void 0 || harmonyChannel === void 0 || harmonyConstrain === void 0) {
|
|
28462
|
+
throw new Error("Harmony chat format requires dedicated special tokens.");
|
|
28463
|
+
}
|
|
28464
|
+
const encodeHeaderText = (text) => text.length > 0 ? this.encode(text) : [];
|
|
28465
|
+
const resolveTerminatorToken = (terminator) => {
|
|
28466
|
+
switch (terminator) {
|
|
28467
|
+
case "<|return|>":
|
|
28468
|
+
return harmonyReturn;
|
|
28469
|
+
case "<|call|>":
|
|
28470
|
+
return harmonyCall;
|
|
28471
|
+
// eslint-disable-next-line unicorn/no-useless-switch-case
|
|
28472
|
+
case "<|end|>":
|
|
28473
|
+
default:
|
|
28474
|
+
return harmonyEnd;
|
|
28475
|
+
}
|
|
28476
|
+
};
|
|
28477
|
+
for (const message of chat) {
|
|
28478
|
+
if (message.content === void 0) {
|
|
28479
|
+
throw new Error("Content must be defined for all messages.");
|
|
28480
|
+
}
|
|
28481
|
+
const roleOrName = message.name ?? message.role ?? "user";
|
|
28482
|
+
yield [harmonyStart];
|
|
28483
|
+
yield encodeHeaderText(roleOrName);
|
|
28484
|
+
const recipientInRole = message.recipient && (message.recipientPlacement === "role" || !message.channel);
|
|
28485
|
+
const recipientInChannel = message.recipient && !recipientInRole;
|
|
28486
|
+
if (recipientInRole) {
|
|
28487
|
+
yield encodeHeaderText(` to=${message.recipient}`);
|
|
28488
|
+
}
|
|
28489
|
+
if (message.channel) {
|
|
28490
|
+
yield [harmonyChannel];
|
|
28491
|
+
yield encodeHeaderText(message.channel);
|
|
28492
|
+
if (recipientInChannel) {
|
|
28493
|
+
yield encodeHeaderText(` to=${message.recipient}`);
|
|
28494
|
+
}
|
|
28495
|
+
}
|
|
28496
|
+
if (message.constraint) {
|
|
28497
|
+
yield [harmonyConstrain];
|
|
28498
|
+
yield encodeHeaderText(message.constraint);
|
|
28499
|
+
}
|
|
28500
|
+
yield [harmonyMessage];
|
|
28501
|
+
yield* this.encodeGenerator(message.content, encodeOptions);
|
|
28502
|
+
yield [resolveTerminatorToken(message.terminator)];
|
|
28503
|
+
}
|
|
28504
|
+
const assistantPrime = encodeOptions?.primeWithAssistantResponse ?? "assistant";
|
|
28505
|
+
if (assistantPrime.length > 0) {
|
|
28506
|
+
yield [harmonyStart];
|
|
28507
|
+
yield encodeHeaderText(assistantPrime);
|
|
28508
|
+
}
|
|
28097
28509
|
}
|
|
28098
28510
|
static getEncodingApi(encodingName, getMergeableRanks) {
|
|
28099
28511
|
const modelParams = getEncodingParams(encodingName, getMergeableRanks);
|
|
@@ -28166,9 +28578,16 @@ var init_GptEncoding = __esm({
|
|
|
28166
28578
|
throw new Error("Model name must be provided either during initialization or passed in to the method.");
|
|
28167
28579
|
}
|
|
28168
28580
|
const params = chatModelParams[model];
|
|
28581
|
+
if (!params) {
|
|
28582
|
+
throw new Error(`Model '${model}' does not support chat.`);
|
|
28583
|
+
}
|
|
28584
|
+
if (this.chatFormatter === "harmony") {
|
|
28585
|
+
yield* this.encodeHarmonyChatGenerator(chat, encodeOptions);
|
|
28586
|
+
return;
|
|
28587
|
+
}
|
|
28169
28588
|
const chatStartToken = this.specialTokensEncoder.get(ImStart);
|
|
28170
28589
|
const chatEndToken = this.specialTokensEncoder.get(ImEnd);
|
|
28171
|
-
if (
|
|
28590
|
+
if (chatStartToken === void 0 || chatEndToken === void 0) {
|
|
28172
28591
|
throw new Error(`Model '${model}' does not support chat.`);
|
|
28173
28592
|
}
|
|
28174
28593
|
const allowedSpecial = /* @__PURE__ */ new Set([ImSep]);
|
|
@@ -28191,8 +28610,11 @@ var init_GptEncoding = __esm({
|
|
|
28191
28610
|
yield [chatEndToken];
|
|
28192
28611
|
yield encodedMessageSeparator;
|
|
28193
28612
|
}
|
|
28194
|
-
|
|
28195
|
-
|
|
28613
|
+
const assistantPrime = encodeOptions?.primeWithAssistantResponse ?? "assistant";
|
|
28614
|
+
if (assistantPrime.length > 0) {
|
|
28615
|
+
yield [chatStartToken];
|
|
28616
|
+
yield* this.encodeGenerator(assistantPrime, encodeOptions);
|
|
28617
|
+
}
|
|
28196
28618
|
if (encodedRoleSeparator.length > 0) {
|
|
28197
28619
|
yield encodedRoleSeparator;
|
|
28198
28620
|
}
|
|
@@ -28250,6 +28672,15 @@ var init_GptEncoding = __esm({
|
|
|
28250
28672
|
}
|
|
28251
28673
|
return count;
|
|
28252
28674
|
}
|
|
28675
|
+
countStringTokens(text) {
|
|
28676
|
+
if (!text) {
|
|
28677
|
+
return 0;
|
|
28678
|
+
}
|
|
28679
|
+
return this.bytePairEncodingCoreProcessor.countNative(text);
|
|
28680
|
+
}
|
|
28681
|
+
countChatCompletionTokensInternal(request) {
|
|
28682
|
+
return computeChatCompletionTokenCount(request, (text) => this.countStringTokens(text));
|
|
28683
|
+
}
|
|
28253
28684
|
setMergeCacheSize(size) {
|
|
28254
28685
|
this.bytePairEncodingCoreProcessor.setMergeCacheSize(size);
|
|
28255
28686
|
}
|
|
@@ -28941,10 +29372,22 @@ function extractThinkingContent(xmlString) {
|
|
|
28941
29372
|
return thinkingMatch ? thinkingMatch[1].trim() : null;
|
|
28942
29373
|
}
|
|
28943
29374
|
function checkAttemptCompleteRecovery(cleanedXmlString, validTools = []) {
|
|
28944
|
-
const
|
|
28945
|
-
if (
|
|
28946
|
-
const
|
|
28947
|
-
const
|
|
29375
|
+
const openTagIndex = cleanedXmlString.indexOf("<attempt_completion>");
|
|
29376
|
+
if (openTagIndex !== -1) {
|
|
29377
|
+
const afterOpenTag = cleanedXmlString.substring(openTagIndex + "<attempt_completion>".length);
|
|
29378
|
+
const closeTagIndex = cleanedXmlString.lastIndexOf("</attempt_completion>");
|
|
29379
|
+
let content;
|
|
29380
|
+
let hasClosingTag = false;
|
|
29381
|
+
if (closeTagIndex !== -1 && closeTagIndex >= openTagIndex + "<attempt_completion>".length) {
|
|
29382
|
+
content = cleanedXmlString.substring(
|
|
29383
|
+
openTagIndex + "<attempt_completion>".length,
|
|
29384
|
+
closeTagIndex
|
|
29385
|
+
).trim();
|
|
29386
|
+
hasClosingTag = true;
|
|
29387
|
+
} else {
|
|
29388
|
+
content = afterOpenTag.trim();
|
|
29389
|
+
hasClosingTag = false;
|
|
29390
|
+
}
|
|
28948
29391
|
if (content) {
|
|
28949
29392
|
return {
|
|
28950
29393
|
toolName: "attempt_completion",
|
|
@@ -28990,8 +29433,8 @@ function checkAttemptCompleteRecovery(cleanedXmlString, validTools = []) {
|
|
|
28990
29433
|
function hasOtherToolTags(xmlString, validTools = []) {
|
|
28991
29434
|
const defaultTools = ["search", "query", "extract", "listFiles", "searchFiles", "implement", "attempt_completion"];
|
|
28992
29435
|
const toolsToCheck = validTools.length > 0 ? validTools : defaultTools;
|
|
28993
|
-
for (const
|
|
28994
|
-
if (
|
|
29436
|
+
for (const tool4 of toolsToCheck) {
|
|
29437
|
+
if (tool4 !== "attempt_completion" && xmlString.includes(`<${tool4}`)) {
|
|
28995
29438
|
return true;
|
|
28996
29439
|
}
|
|
28997
29440
|
}
|
|
@@ -29028,6 +29471,10 @@ function createTools(configOptions) {
|
|
|
29028
29471
|
if (configOptions.enableBash) {
|
|
29029
29472
|
tools2.bashTool = bashTool(configOptions);
|
|
29030
29473
|
}
|
|
29474
|
+
if (configOptions.allowEdit) {
|
|
29475
|
+
tools2.editTool = editTool(configOptions);
|
|
29476
|
+
tools2.createTool = createTool(configOptions);
|
|
29477
|
+
}
|
|
29031
29478
|
return tools2;
|
|
29032
29479
|
}
|
|
29033
29480
|
function parseXmlToolCallWithThinking(xmlString, validTools) {
|
|
@@ -33257,7 +33704,15 @@ function parseXmlToolCall(xmlString, validTools = DEFAULT_VALID_TOOLS) {
|
|
|
33257
33704
|
if (openIndex === -1) {
|
|
33258
33705
|
continue;
|
|
33259
33706
|
}
|
|
33260
|
-
let closeIndex
|
|
33707
|
+
let closeIndex;
|
|
33708
|
+
if (toolName === "attempt_completion") {
|
|
33709
|
+
closeIndex = xmlString.lastIndexOf(closeTag);
|
|
33710
|
+
if (closeIndex !== -1 && closeIndex <= openIndex + openTag.length) {
|
|
33711
|
+
closeIndex = -1;
|
|
33712
|
+
}
|
|
33713
|
+
} else {
|
|
33714
|
+
closeIndex = xmlString.indexOf(closeTag, openIndex + openTag.length);
|
|
33715
|
+
}
|
|
33261
33716
|
let hasClosingTag = closeIndex !== -1;
|
|
33262
33717
|
if (closeIndex === -1) {
|
|
33263
33718
|
closeIndex = xmlString.length;
|
|
@@ -33347,11 +33802,12 @@ var init_common2 = __esm({
|
|
|
33347
33802
|
pattern: external_exports.string().describe("AST pattern to search for. Use $NAME for variable names, $$$PARAMS for parameter lists, etc."),
|
|
33348
33803
|
path: external_exports.string().optional().default(".").describe("Path to search in"),
|
|
33349
33804
|
language: external_exports.string().optional().default("rust").describe("Programming language to use for parsing"),
|
|
33350
|
-
allow_tests: external_exports.boolean().optional().default(
|
|
33805
|
+
allow_tests: external_exports.boolean().optional().default(true).describe("Allow test files in search results")
|
|
33351
33806
|
});
|
|
33352
33807
|
extractSchema = external_exports.object({
|
|
33353
33808
|
targets: external_exports.string().optional().describe('File paths or symbols to extract from. Formats: "file.js" (whole file), "file.js:42" (line 42), "file.js:10-20" (lines 10-20), "file.js#funcName" (symbol). Multiple targets separated by spaces.'),
|
|
33354
|
-
input_content: external_exports.string().optional().describe("Text content to extract file paths from (alternative to targets)")
|
|
33809
|
+
input_content: external_exports.string().optional().describe("Text content to extract file paths from (alternative to targets)"),
|
|
33810
|
+
allow_tests: external_exports.boolean().optional().default(true).describe("Include test files in extraction results")
|
|
33355
33811
|
});
|
|
33356
33812
|
delegateSchema = external_exports.object({
|
|
33357
33813
|
task: external_exports.string().describe("The task to delegate to a subagent. Be specific about what needs to be accomplished.")
|
|
@@ -33478,7 +33934,7 @@ Parameters:
|
|
|
33478
33934
|
- pattern: (required) AST pattern to search for. Use $NAME for variable names, $$$PARAMS for parameter lists, etc.
|
|
33479
33935
|
- path: (optional, default: '.') Path to search in.
|
|
33480
33936
|
- language: (optional, default: 'rust') Programming language to use for parsing.
|
|
33481
|
-
- allow_tests: (optional, default:
|
|
33937
|
+
- allow_tests: (optional, default: true) Allow test files in search results (true/false).
|
|
33482
33938
|
Usage Example:
|
|
33483
33939
|
|
|
33484
33940
|
<examples>
|
|
@@ -33503,6 +33959,7 @@ Full file extraction should be the LAST RESORT! Always prefer search.
|
|
|
33503
33959
|
Parameters:
|
|
33504
33960
|
- targets: (required) File paths or symbols to extract from. Formats: "file.js" (whole file), "file.js:42" (code block at line 42), "file.js:10-20" (lines 10-20), "file.js#funcName" (specific symbol). Multiple targets separated by spaces.
|
|
33505
33961
|
- input_content: (optional) Text content to extract file paths from (alternative to targets for processing diffs/logs).
|
|
33962
|
+
- allow_tests: (optional, default: true) Include test files in extraction results.
|
|
33506
33963
|
|
|
33507
33964
|
Usage Example:
|
|
33508
33965
|
|
|
@@ -37324,10 +37781,10 @@ var init_esm3 = __esm({
|
|
|
37324
37781
|
* Return a void Promise that resolves once the stream ends.
|
|
37325
37782
|
*/
|
|
37326
37783
|
async promise() {
|
|
37327
|
-
return new Promise((
|
|
37784
|
+
return new Promise((resolve5, reject2) => {
|
|
37328
37785
|
this.on(DESTROYED, () => reject2(new Error("stream destroyed")));
|
|
37329
37786
|
this.on("error", (er) => reject2(er));
|
|
37330
|
-
this.on("end", () =>
|
|
37787
|
+
this.on("end", () => resolve5());
|
|
37331
37788
|
});
|
|
37332
37789
|
}
|
|
37333
37790
|
/**
|
|
@@ -37351,7 +37808,7 @@ var init_esm3 = __esm({
|
|
|
37351
37808
|
return Promise.resolve({ done: false, value: res });
|
|
37352
37809
|
if (this[EOF])
|
|
37353
37810
|
return stop();
|
|
37354
|
-
let
|
|
37811
|
+
let resolve5;
|
|
37355
37812
|
let reject2;
|
|
37356
37813
|
const onerr = (er) => {
|
|
37357
37814
|
this.off("data", ondata);
|
|
@@ -37365,19 +37822,19 @@ var init_esm3 = __esm({
|
|
|
37365
37822
|
this.off("end", onend);
|
|
37366
37823
|
this.off(DESTROYED, ondestroy);
|
|
37367
37824
|
this.pause();
|
|
37368
|
-
|
|
37825
|
+
resolve5({ value, done: !!this[EOF] });
|
|
37369
37826
|
};
|
|
37370
37827
|
const onend = () => {
|
|
37371
37828
|
this.off("error", onerr);
|
|
37372
37829
|
this.off("data", ondata);
|
|
37373
37830
|
this.off(DESTROYED, ondestroy);
|
|
37374
37831
|
stop();
|
|
37375
|
-
|
|
37832
|
+
resolve5({ done: true, value: void 0 });
|
|
37376
37833
|
};
|
|
37377
37834
|
const ondestroy = () => onerr(new Error("stream destroyed"));
|
|
37378
37835
|
return new Promise((res2, rej) => {
|
|
37379
37836
|
reject2 = rej;
|
|
37380
|
-
|
|
37837
|
+
resolve5 = res2;
|
|
37381
37838
|
this.once(DESTROYED, ondestroy);
|
|
37382
37839
|
this.once("error", onerr);
|
|
37383
37840
|
this.once("end", onend);
|
|
@@ -38357,9 +38814,9 @@ var init_esm4 = __esm({
|
|
|
38357
38814
|
if (this.#asyncReaddirInFlight) {
|
|
38358
38815
|
await this.#asyncReaddirInFlight;
|
|
38359
38816
|
} else {
|
|
38360
|
-
let
|
|
38817
|
+
let resolve5 = () => {
|
|
38361
38818
|
};
|
|
38362
|
-
this.#asyncReaddirInFlight = new Promise((res) =>
|
|
38819
|
+
this.#asyncReaddirInFlight = new Promise((res) => resolve5 = res);
|
|
38363
38820
|
try {
|
|
38364
38821
|
for (const e3 of await this.#fs.promises.readdir(fullpath, {
|
|
38365
38822
|
withFileTypes: true
|
|
@@ -38372,7 +38829,7 @@ var init_esm4 = __esm({
|
|
|
38372
38829
|
children.provisional = 0;
|
|
38373
38830
|
}
|
|
38374
38831
|
this.#asyncReaddirInFlight = void 0;
|
|
38375
|
-
|
|
38832
|
+
resolve5();
|
|
38376
38833
|
}
|
|
38377
38834
|
return children.slice(0, children.provisional);
|
|
38378
38835
|
}
|
|
@@ -38602,8 +39059,8 @@ var init_esm4 = __esm({
|
|
|
38602
39059
|
*
|
|
38603
39060
|
* @internal
|
|
38604
39061
|
*/
|
|
38605
|
-
constructor(cwd = process.cwd(), pathImpl,
|
|
38606
|
-
this.#fs = fsFromOption(
|
|
39062
|
+
constructor(cwd = process.cwd(), pathImpl, sep3, { nocase, childrenCacheSize = 16 * 1024, fs: fs7 = defaultFS } = {}) {
|
|
39063
|
+
this.#fs = fsFromOption(fs7);
|
|
38607
39064
|
if (cwd instanceof URL || cwd.startsWith("file://")) {
|
|
38608
39065
|
cwd = (0, import_node_url.fileURLToPath)(cwd);
|
|
38609
39066
|
}
|
|
@@ -38613,7 +39070,7 @@ var init_esm4 = __esm({
|
|
|
38613
39070
|
this.#resolveCache = new ResolveCache();
|
|
38614
39071
|
this.#resolvePosixCache = new ResolveCache();
|
|
38615
39072
|
this.#children = new ChildrenCache(childrenCacheSize);
|
|
38616
|
-
const split = cwdPath.substring(this.rootPath.length).split(
|
|
39073
|
+
const split = cwdPath.substring(this.rootPath.length).split(sep3);
|
|
38617
39074
|
if (split.length === 1 && !split[0]) {
|
|
38618
39075
|
split.pop();
|
|
38619
39076
|
}
|
|
@@ -39161,8 +39618,8 @@ var init_esm4 = __esm({
|
|
|
39161
39618
|
/**
|
|
39162
39619
|
* @internal
|
|
39163
39620
|
*/
|
|
39164
|
-
newRoot(
|
|
39165
|
-
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
39621
|
+
newRoot(fs7) {
|
|
39622
|
+
return new PathWin32(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs7 });
|
|
39166
39623
|
}
|
|
39167
39624
|
/**
|
|
39168
39625
|
* Return true if the provided path string is an absolute path
|
|
@@ -39190,8 +39647,8 @@ var init_esm4 = __esm({
|
|
|
39190
39647
|
/**
|
|
39191
39648
|
* @internal
|
|
39192
39649
|
*/
|
|
39193
|
-
newRoot(
|
|
39194
|
-
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs:
|
|
39650
|
+
newRoot(fs7) {
|
|
39651
|
+
return new PathPosix(this.rootPath, IFDIR, void 0, this.roots, this.nocase, this.childrenCache(), { fs: fs7 });
|
|
39195
39652
|
}
|
|
39196
39653
|
/**
|
|
39197
39654
|
* Return true if the provided path string is an absolute path
|
|
@@ -40384,6 +40841,20 @@ function createWrappedTools(baseTools) {
|
|
|
40384
40841
|
baseTools.bashTool.execute
|
|
40385
40842
|
);
|
|
40386
40843
|
}
|
|
40844
|
+
if (baseTools.editTool) {
|
|
40845
|
+
wrappedTools.editToolInstance = wrapToolWithEmitter(
|
|
40846
|
+
baseTools.editTool,
|
|
40847
|
+
"edit",
|
|
40848
|
+
baseTools.editTool.execute
|
|
40849
|
+
);
|
|
40850
|
+
}
|
|
40851
|
+
if (baseTools.createTool) {
|
|
40852
|
+
wrappedTools.createToolInstance = wrapToolWithEmitter(
|
|
40853
|
+
baseTools.createTool,
|
|
40854
|
+
"create",
|
|
40855
|
+
baseTools.createTool.execute
|
|
40856
|
+
);
|
|
40857
|
+
}
|
|
40387
40858
|
return wrappedTools;
|
|
40388
40859
|
}
|
|
40389
40860
|
var import_child_process6, import_util11, import_crypto3, import_events, import_fs2, import_fs3, import_path4, toolCallEmitter, activeToolExecutions, wrapToolWithEmitter, listFilesTool, searchFilesTool, listFilesToolInstance, searchFilesToolInstance;
|
|
@@ -40401,9 +40872,9 @@ var init_probeTool = __esm({
|
|
|
40401
40872
|
init_esm5();
|
|
40402
40873
|
toolCallEmitter = new import_events.EventEmitter();
|
|
40403
40874
|
activeToolExecutions = /* @__PURE__ */ new Map();
|
|
40404
|
-
wrapToolWithEmitter = (
|
|
40875
|
+
wrapToolWithEmitter = (tool4, toolName, baseExecute) => {
|
|
40405
40876
|
return {
|
|
40406
|
-
...
|
|
40877
|
+
...tool4,
|
|
40407
40878
|
// Spread schema, description etc.
|
|
40408
40879
|
execute: async (params) => {
|
|
40409
40880
|
const debug = process.env.DEBUG === "1";
|
|
@@ -40614,7 +41085,7 @@ function createMockProvider() {
|
|
|
40614
41085
|
provider: "mock",
|
|
40615
41086
|
// Mock the doGenerate method used by Vercel AI SDK
|
|
40616
41087
|
doGenerate: async ({ messages, tools: tools2 }) => {
|
|
40617
|
-
await new Promise((
|
|
41088
|
+
await new Promise((resolve5) => setTimeout(resolve5, 10));
|
|
40618
41089
|
return {
|
|
40619
41090
|
text: "This is a mock response for testing",
|
|
40620
41091
|
toolCalls: [],
|
|
@@ -52601,16 +53072,6 @@ var init_parser2 = __esm({
|
|
|
52601
53072
|
this.subgraph = this.RULE("subgraph", () => {
|
|
52602
53073
|
this.CONSUME(SubgraphKeyword);
|
|
52603
53074
|
this.OR([
|
|
52604
|
-
{
|
|
52605
|
-
ALT: () => {
|
|
52606
|
-
this.CONSUME(Identifier, { LABEL: "subgraphId" });
|
|
52607
|
-
this.OPTION(() => {
|
|
52608
|
-
this.CONSUME1(SquareOpen);
|
|
52609
|
-
this.SUBRULE(this.nodeContent);
|
|
52610
|
-
this.CONSUME1(SquareClose);
|
|
52611
|
-
});
|
|
52612
|
-
}
|
|
52613
|
-
},
|
|
52614
53075
|
{
|
|
52615
53076
|
ALT: () => {
|
|
52616
53077
|
this.CONSUME(QuotedString, { LABEL: "subgraphTitleQ" });
|
|
@@ -52622,6 +53083,33 @@ var init_parser2 = __esm({
|
|
|
52622
53083
|
this.SUBRULE2(this.nodeContent);
|
|
52623
53084
|
this.CONSUME2(SquareClose);
|
|
52624
53085
|
}
|
|
53086
|
+
},
|
|
53087
|
+
{
|
|
53088
|
+
ALT: () => {
|
|
53089
|
+
this.CONSUME1(Identifier, { LABEL: "subgraphIdOrFirstWord" });
|
|
53090
|
+
this.OPTION(() => {
|
|
53091
|
+
this.OR1([
|
|
53092
|
+
{
|
|
53093
|
+
ALT: () => {
|
|
53094
|
+
this.CONSUME1(SquareOpen);
|
|
53095
|
+
this.SUBRULE(this.nodeContent);
|
|
53096
|
+
this.CONSUME1(SquareClose);
|
|
53097
|
+
}
|
|
53098
|
+
},
|
|
53099
|
+
{
|
|
53100
|
+
ALT: () => {
|
|
53101
|
+
this.AT_LEAST_ONE(() => {
|
|
53102
|
+
this.OR2([
|
|
53103
|
+
{ ALT: () => this.CONSUME2(Identifier) },
|
|
53104
|
+
{ ALT: () => this.CONSUME(Text) },
|
|
53105
|
+
{ ALT: () => this.CONSUME(NumberLiteral) }
|
|
53106
|
+
]);
|
|
53107
|
+
});
|
|
53108
|
+
}
|
|
53109
|
+
}
|
|
53110
|
+
]);
|
|
53111
|
+
});
|
|
53112
|
+
}
|
|
52625
53113
|
}
|
|
52626
53114
|
]);
|
|
52627
53115
|
this.CONSUME(Newline);
|
|
@@ -53225,7 +53713,6 @@ var init_semantics = __esm({
|
|
|
53225
53713
|
const last2 = allChildren[allChildren.length - 1];
|
|
53226
53714
|
const isSlash = (t3) => t3.image === "/" || t3.image === "\\";
|
|
53227
53715
|
if (isSlash(first2) && isSlash(last2)) {
|
|
53228
|
-
continue;
|
|
53229
53716
|
}
|
|
53230
53717
|
}
|
|
53231
53718
|
const opens = ch.RoundOpen || [];
|
|
@@ -54019,16 +54506,19 @@ function mapFlowchartParserError(err, text) {
|
|
|
54019
54506
|
const subgraphIdx = lineStr.indexOf("subgraph");
|
|
54020
54507
|
if (subgraphIdx !== -1) {
|
|
54021
54508
|
const afterSubgraph = lineStr.slice(subgraphIdx + 8).trim();
|
|
54022
|
-
if (afterSubgraph && !afterSubgraph.startsWith('"') && !afterSubgraph.startsWith("'")
|
|
54023
|
-
|
|
54024
|
-
|
|
54025
|
-
|
|
54026
|
-
|
|
54027
|
-
|
|
54028
|
-
|
|
54029
|
-
|
|
54030
|
-
|
|
54031
|
-
|
|
54509
|
+
if (afterSubgraph && !afterSubgraph.startsWith('"') && !afterSubgraph.startsWith("'")) {
|
|
54510
|
+
const hasHazard = /[\[\](){}/:|"'\\]/.test(afterSubgraph);
|
|
54511
|
+
if (hasHazard) {
|
|
54512
|
+
return {
|
|
54513
|
+
line,
|
|
54514
|
+
column,
|
|
54515
|
+
severity: "error",
|
|
54516
|
+
code: "FL-SUBGRAPH-UNQUOTED-TITLE",
|
|
54517
|
+
message: "Subgraph title contains special characters; wrap it in quotes.",
|
|
54518
|
+
hint: 'Example: subgraph "Streams (inside Gateway)"',
|
|
54519
|
+
length: afterSubgraph.length
|
|
54520
|
+
};
|
|
54521
|
+
}
|
|
54032
54522
|
}
|
|
54033
54523
|
}
|
|
54034
54524
|
}
|
|
@@ -54726,11 +55216,11 @@ function validateFlowchart(text, options = {}) {
|
|
|
54726
55216
|
const byLine = /* @__PURE__ */ new Map();
|
|
54727
55217
|
const collect = (arr) => {
|
|
54728
55218
|
for (const e3 of arr || []) {
|
|
54729
|
-
if (e3 && e3.code === "FL-LABEL-PARENS-UNQUOTED") {
|
|
55219
|
+
if (e3 && (e3.code === "FL-LABEL-PARENS-UNQUOTED" || e3.code === "FL-LABEL-AT-IN-UNQUOTED")) {
|
|
54730
55220
|
const ln = e3.line ?? 0;
|
|
54731
55221
|
const col = e3.column ?? 1;
|
|
54732
55222
|
const list2 = byLine.get(ln) || [];
|
|
54733
|
-
list2.push(col);
|
|
55223
|
+
list2.push({ start: col, end: col });
|
|
54734
55224
|
byLine.set(ln, list2);
|
|
54735
55225
|
}
|
|
54736
55226
|
}
|
|
@@ -54739,33 +55229,91 @@ function validateFlowchart(text, options = {}) {
|
|
|
54739
55229
|
collect(errs);
|
|
54740
55230
|
const lines2 = text2.split(/\r?\n/);
|
|
54741
55231
|
for (let ii = 0; ii < lines2.length; ii++) {
|
|
54742
|
-
const
|
|
54743
|
-
if (!
|
|
55232
|
+
const raw = lines2[ii] || "";
|
|
55233
|
+
if (!raw.includes("[") || !raw.includes("]"))
|
|
54744
55234
|
continue;
|
|
54745
|
-
let
|
|
54746
|
-
|
|
54747
|
-
|
|
54748
|
-
|
|
54749
|
-
|
|
54750
|
-
const
|
|
54751
|
-
if (
|
|
54752
|
-
|
|
54753
|
-
|
|
54754
|
-
|
|
54755
|
-
|
|
54756
|
-
|
|
54757
|
-
|
|
54758
|
-
|
|
54759
|
-
|
|
54760
|
-
|
|
54761
|
-
|
|
54762
|
-
|
|
54763
|
-
|
|
54764
|
-
|
|
54765
|
-
|
|
54766
|
-
byLine.set(ln2, existing.concat([segStartCol]));
|
|
55235
|
+
let i3 = 0;
|
|
55236
|
+
const n3 = raw.length;
|
|
55237
|
+
let inQuote = false;
|
|
55238
|
+
let esc = false;
|
|
55239
|
+
while (i3 < n3) {
|
|
55240
|
+
const ch = raw[i3];
|
|
55241
|
+
if (inQuote) {
|
|
55242
|
+
if (esc) {
|
|
55243
|
+
esc = false;
|
|
55244
|
+
} else if (ch === "\\") {
|
|
55245
|
+
esc = true;
|
|
55246
|
+
} else if (ch === '"') {
|
|
55247
|
+
inQuote = false;
|
|
55248
|
+
}
|
|
55249
|
+
i3++;
|
|
55250
|
+
continue;
|
|
55251
|
+
}
|
|
55252
|
+
if (ch === '"') {
|
|
55253
|
+
inQuote = true;
|
|
55254
|
+
i3++;
|
|
55255
|
+
continue;
|
|
54767
55256
|
}
|
|
54768
|
-
|
|
55257
|
+
if (ch === "[") {
|
|
55258
|
+
let j3 = i3 + 1;
|
|
55259
|
+
let inQ = false;
|
|
55260
|
+
let esc2 = false;
|
|
55261
|
+
let depth = 1;
|
|
55262
|
+
while (j3 < n3 && depth > 0) {
|
|
55263
|
+
const cj = raw[j3];
|
|
55264
|
+
if (inQ) {
|
|
55265
|
+
if (esc2) {
|
|
55266
|
+
esc2 = false;
|
|
55267
|
+
} else if (cj === "\\") {
|
|
55268
|
+
esc2 = true;
|
|
55269
|
+
} else if (cj === '"') {
|
|
55270
|
+
inQ = false;
|
|
55271
|
+
}
|
|
55272
|
+
j3++;
|
|
55273
|
+
continue;
|
|
55274
|
+
}
|
|
55275
|
+
if (cj === '"') {
|
|
55276
|
+
inQ = true;
|
|
55277
|
+
j3++;
|
|
55278
|
+
continue;
|
|
55279
|
+
}
|
|
55280
|
+
if (cj === "[")
|
|
55281
|
+
depth++;
|
|
55282
|
+
else if (cj === "]")
|
|
55283
|
+
depth--;
|
|
55284
|
+
j3++;
|
|
55285
|
+
}
|
|
55286
|
+
if (depth === 0) {
|
|
55287
|
+
const startCol = i3 + 2;
|
|
55288
|
+
const endCol = j3;
|
|
55289
|
+
const seg = raw.slice(i3 + 1, j3 - 1);
|
|
55290
|
+
const trimmed = seg.trim();
|
|
55291
|
+
const ln = ii + 1;
|
|
55292
|
+
const lsp = trimmed.slice(0, 1), rsp = trimmed.slice(-1);
|
|
55293
|
+
const isSlashPair = (lsp === "/" || lsp === "\\") && (rsp === "/" || rsp === "\\");
|
|
55294
|
+
const isParenWrapped = lsp === "(" && rsp === ")";
|
|
55295
|
+
const isQuoted = /^"[\s\S]*"$/.test(trimmed);
|
|
55296
|
+
const existing = byLine.get(ln) || [];
|
|
55297
|
+
const covered = existing.some((r3) => !(endCol < r3.start || startCol > r3.end));
|
|
55298
|
+
const hasParens = seg.includes("(") || seg.includes(")");
|
|
55299
|
+
const hasAt = seg.includes("@");
|
|
55300
|
+
if (!covered && !isQuoted && !isParenWrapped && hasParens) {
|
|
55301
|
+
errs.push({ line: ln, column: startCol, severity: "error", code: "FL-LABEL-PARENS-UNQUOTED", message: "Parentheses inside an unquoted label are not supported by Mermaid.", hint: 'Wrap the label in quotes, e.g., A["Mark (X)"] \u2014 or replace ( and ) with HTML entities: ( and ).' });
|
|
55302
|
+
existing.push({ start: startCol, end: endCol });
|
|
55303
|
+
byLine.set(ln, existing);
|
|
55304
|
+
}
|
|
55305
|
+
if (!covered && !isQuoted && !isSlashPair && hasAt) {
|
|
55306
|
+
errs.push({ line: ln, column: startCol, severity: "error", code: "FL-LABEL-AT-IN-UNQUOTED", message: "'@' inside an unquoted label can be misparsed by Mermaid.", hint: 'Wrap the label in quotes, e.g., B["@probelabs/probe v0.6.0-rc149"]' });
|
|
55307
|
+
existing.push({ start: startCol, end: endCol });
|
|
55308
|
+
byLine.set(ln, existing);
|
|
55309
|
+
}
|
|
55310
|
+
i3 = j3;
|
|
55311
|
+
continue;
|
|
55312
|
+
} else {
|
|
55313
|
+
break;
|
|
55314
|
+
}
|
|
55315
|
+
}
|
|
55316
|
+
i3++;
|
|
54769
55317
|
}
|
|
54770
55318
|
}
|
|
54771
55319
|
}
|
|
@@ -66251,7 +66799,7 @@ var require_bk = __commonJS({
|
|
|
66251
66799
|
return xs;
|
|
66252
66800
|
}
|
|
66253
66801
|
function buildBlockGraph(g3, layering, root2, reverseSep) {
|
|
66254
|
-
var blockGraph = new Graph(), graphLabel = g3.graph(), sepFn =
|
|
66802
|
+
var blockGraph = new Graph(), graphLabel = g3.graph(), sepFn = sep3(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
|
|
66255
66803
|
_2.forEach(layering, function(layer) {
|
|
66256
66804
|
var u3;
|
|
66257
66805
|
_2.forEach(layer, function(v3) {
|
|
@@ -66341,7 +66889,7 @@ var require_bk = __commonJS({
|
|
|
66341
66889
|
alignCoordinates(xss, smallestWidth);
|
|
66342
66890
|
return balance(xss, g3.graph().align);
|
|
66343
66891
|
}
|
|
66344
|
-
function
|
|
66892
|
+
function sep3(nodeSep, edgeSep, reverseSep) {
|
|
66345
66893
|
return function(g3, v3, w3) {
|
|
66346
66894
|
var vLabel = g3.node(v3);
|
|
66347
66895
|
var wLabel = g3.node(w3);
|
|
@@ -73635,7 +74183,7 @@ var require_compile = __commonJS({
|
|
|
73635
74183
|
const schOrFunc = root2.refs[ref];
|
|
73636
74184
|
if (schOrFunc)
|
|
73637
74185
|
return schOrFunc;
|
|
73638
|
-
let _sch =
|
|
74186
|
+
let _sch = resolve5.call(this, root2, ref);
|
|
73639
74187
|
if (_sch === void 0) {
|
|
73640
74188
|
const schema = (_a16 = root2.localRefs) === null || _a16 === void 0 ? void 0 : _a16[ref];
|
|
73641
74189
|
const { schemaId } = this.opts;
|
|
@@ -73662,7 +74210,7 @@ var require_compile = __commonJS({
|
|
|
73662
74210
|
function sameSchemaEnv(s1, s22) {
|
|
73663
74211
|
return s1.schema === s22.schema && s1.root === s22.root && s1.baseId === s22.baseId;
|
|
73664
74212
|
}
|
|
73665
|
-
function
|
|
74213
|
+
function resolve5(root2, ref) {
|
|
73666
74214
|
let sch;
|
|
73667
74215
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
73668
74216
|
ref = sch;
|
|
@@ -74237,7 +74785,7 @@ var require_fast_uri = __commonJS({
|
|
|
74237
74785
|
}
|
|
74238
74786
|
return uri;
|
|
74239
74787
|
}
|
|
74240
|
-
function
|
|
74788
|
+
function resolve5(baseURI, relativeURI, options) {
|
|
74241
74789
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
74242
74790
|
const resolved = resolveComponent(parse6(baseURI, schemelessOptions), parse6(relativeURI, schemelessOptions), schemelessOptions, true);
|
|
74243
74791
|
schemelessOptions.skipEscape = true;
|
|
@@ -74464,7 +75012,7 @@ var require_fast_uri = __commonJS({
|
|
|
74464
75012
|
var fastUri = {
|
|
74465
75013
|
SCHEMES,
|
|
74466
75014
|
normalize: normalize2,
|
|
74467
|
-
resolve:
|
|
75015
|
+
resolve: resolve5,
|
|
74468
75016
|
resolveComponent,
|
|
74469
75017
|
equal,
|
|
74470
75018
|
serialize,
|
|
@@ -78811,12 +79359,12 @@ var init_client2 = __esm({
|
|
|
78811
79359
|
const toolsResponse = await client.listTools();
|
|
78812
79360
|
const toolCount = toolsResponse?.tools?.length || 0;
|
|
78813
79361
|
if (toolsResponse && toolsResponse.tools) {
|
|
78814
|
-
for (const
|
|
78815
|
-
const qualifiedName = `${name14}_${
|
|
79362
|
+
for (const tool4 of toolsResponse.tools) {
|
|
79363
|
+
const qualifiedName = `${name14}_${tool4.name}`;
|
|
78816
79364
|
this.tools.set(qualifiedName, {
|
|
78817
|
-
...
|
|
79365
|
+
...tool4,
|
|
78818
79366
|
serverName: name14,
|
|
78819
|
-
originalName:
|
|
79367
|
+
originalName: tool4.name
|
|
78820
79368
|
});
|
|
78821
79369
|
if (this.debug) {
|
|
78822
79370
|
console.error(`[MCP DEBUG] Registered tool: ${qualifiedName}`);
|
|
@@ -78839,13 +79387,13 @@ var init_client2 = __esm({
|
|
|
78839
79387
|
* @param {Object} args - Tool arguments
|
|
78840
79388
|
*/
|
|
78841
79389
|
async callTool(toolName, args) {
|
|
78842
|
-
const
|
|
78843
|
-
if (!
|
|
79390
|
+
const tool4 = this.tools.get(toolName);
|
|
79391
|
+
if (!tool4) {
|
|
78844
79392
|
throw new Error(`Unknown tool: ${toolName}`);
|
|
78845
79393
|
}
|
|
78846
|
-
const clientInfo = this.clients.get(
|
|
79394
|
+
const clientInfo = this.clients.get(tool4.serverName);
|
|
78847
79395
|
if (!clientInfo) {
|
|
78848
|
-
throw new Error(`Server ${
|
|
79396
|
+
throw new Error(`Server ${tool4.serverName} not connected`);
|
|
78849
79397
|
}
|
|
78850
79398
|
try {
|
|
78851
79399
|
if (this.debug) {
|
|
@@ -78859,7 +79407,7 @@ var init_client2 = __esm({
|
|
|
78859
79407
|
});
|
|
78860
79408
|
const result = await Promise.race([
|
|
78861
79409
|
clientInfo.client.callTool({
|
|
78862
|
-
name:
|
|
79410
|
+
name: tool4.originalName,
|
|
78863
79411
|
arguments: args
|
|
78864
79412
|
}),
|
|
78865
79413
|
timeoutPromise
|
|
@@ -78882,11 +79430,11 @@ var init_client2 = __esm({
|
|
|
78882
79430
|
*/
|
|
78883
79431
|
getTools() {
|
|
78884
79432
|
const tools2 = {};
|
|
78885
|
-
for (const [name14,
|
|
79433
|
+
for (const [name14, tool4] of this.tools.entries()) {
|
|
78886
79434
|
tools2[name14] = {
|
|
78887
|
-
description:
|
|
78888
|
-
inputSchema:
|
|
78889
|
-
serverName:
|
|
79435
|
+
description: tool4.description,
|
|
79436
|
+
inputSchema: tool4.inputSchema,
|
|
79437
|
+
serverName: tool4.serverName
|
|
78890
79438
|
};
|
|
78891
79439
|
}
|
|
78892
79440
|
return tools2;
|
|
@@ -78897,10 +79445,10 @@ var init_client2 = __esm({
|
|
|
78897
79445
|
*/
|
|
78898
79446
|
getVercelTools() {
|
|
78899
79447
|
const tools2 = {};
|
|
78900
|
-
for (const [name14,
|
|
79448
|
+
for (const [name14, tool4] of this.tools.entries()) {
|
|
78901
79449
|
tools2[name14] = {
|
|
78902
|
-
description:
|
|
78903
|
-
inputSchema:
|
|
79450
|
+
description: tool4.description,
|
|
79451
|
+
inputSchema: tool4.inputSchema,
|
|
78904
79452
|
execute: async (args) => {
|
|
78905
79453
|
const result = await this.callTool(name14, args);
|
|
78906
79454
|
if (result.content && result.content[0]) {
|
|
@@ -78949,9 +79497,9 @@ var init_client2 = __esm({
|
|
|
78949
79497
|
});
|
|
78950
79498
|
|
|
78951
79499
|
// src/agent/mcp/xmlBridge.js
|
|
78952
|
-
function mcpToolToXmlDefinition(name14,
|
|
78953
|
-
const description =
|
|
78954
|
-
const inputSchema =
|
|
79500
|
+
function mcpToolToXmlDefinition(name14, tool4) {
|
|
79501
|
+
const description = tool4.description || "MCP tool";
|
|
79502
|
+
const inputSchema = tool4.inputSchema || tool4.parameters || {};
|
|
78955
79503
|
let paramDocs = "";
|
|
78956
79504
|
if (inputSchema.properties) {
|
|
78957
79505
|
paramDocs = "\n\nParameters (provide as JSON object):";
|
|
@@ -79130,8 +79678,8 @@ var init_xmlBridge = __esm({
|
|
|
79130
79678
|
const vercelTools = this.mcpManager.getVercelTools();
|
|
79131
79679
|
this.mcpTools = vercelTools;
|
|
79132
79680
|
const toolCount = Object.keys(vercelTools).length;
|
|
79133
|
-
for (const [name14,
|
|
79134
|
-
this.xmlDefinitions[name14] = mcpToolToXmlDefinition(name14,
|
|
79681
|
+
for (const [name14, tool4] of Object.entries(vercelTools)) {
|
|
79682
|
+
this.xmlDefinitions[name14] = mcpToolToXmlDefinition(name14, tool4);
|
|
79135
79683
|
}
|
|
79136
79684
|
if (toolCount === 0) {
|
|
79137
79685
|
console.error("[MCP INFO] MCP initialization complete: 0 tools loaded");
|
|
@@ -79178,14 +79726,14 @@ var init_xmlBridge = __esm({
|
|
|
79178
79726
|
console.error(`[MCP DEBUG] Executing MCP tool: ${toolName}`);
|
|
79179
79727
|
console.error(`[MCP DEBUG] Parameters:`, JSON.stringify(params, null, 2));
|
|
79180
79728
|
}
|
|
79181
|
-
const
|
|
79182
|
-
if (!
|
|
79729
|
+
const tool4 = this.mcpTools[toolName];
|
|
79730
|
+
if (!tool4) {
|
|
79183
79731
|
console.error(`[MCP ERROR] Unknown MCP tool: ${toolName}`);
|
|
79184
79732
|
console.error(`[MCP ERROR] Available tools: ${this.getToolNames().join(", ")}`);
|
|
79185
79733
|
throw new Error(`Unknown MCP tool: ${toolName}`);
|
|
79186
79734
|
}
|
|
79187
79735
|
try {
|
|
79188
|
-
const result = await
|
|
79736
|
+
const result = await tool4.execute(params);
|
|
79189
79737
|
if (this.debug) {
|
|
79190
79738
|
console.error(`[MCP DEBUG] Tool ${toolName} executed successfully`);
|
|
79191
79739
|
}
|
|
@@ -79239,19 +79787,797 @@ var init_mcp = __esm({
|
|
|
79239
79787
|
}
|
|
79240
79788
|
});
|
|
79241
79789
|
|
|
79790
|
+
// src/agent/RetryManager.js
|
|
79791
|
+
function isRetryableError(error2, retryableErrors = DEFAULT_RETRYABLE_ERRORS) {
|
|
79792
|
+
if (!error2) return false;
|
|
79793
|
+
const errorString = error2.toString().toLowerCase();
|
|
79794
|
+
const errorMessage = (error2.message || "").toLowerCase();
|
|
79795
|
+
const errorCode = (error2.code || "").toLowerCase();
|
|
79796
|
+
const errorType = (error2.type || "").toLowerCase();
|
|
79797
|
+
const statusCode = error2.statusCode || error2.status;
|
|
79798
|
+
for (const pattern of retryableErrors) {
|
|
79799
|
+
const lowerPattern = pattern.toLowerCase();
|
|
79800
|
+
if (errorString.includes(lowerPattern) || errorMessage.includes(lowerPattern) || errorCode.includes(lowerPattern) || errorType.includes(lowerPattern) || statusCode?.toString() === pattern) {
|
|
79801
|
+
return true;
|
|
79802
|
+
}
|
|
79803
|
+
}
|
|
79804
|
+
return false;
|
|
79805
|
+
}
|
|
79806
|
+
function extractErrorInfo(error2) {
|
|
79807
|
+
return {
|
|
79808
|
+
message: error2.message || error2.toString(),
|
|
79809
|
+
type: error2.type || error2.constructor.name,
|
|
79810
|
+
code: error2.code,
|
|
79811
|
+
statusCode: error2.statusCode || error2.status,
|
|
79812
|
+
provider: error2.provider,
|
|
79813
|
+
isRetryable: isRetryableError(error2)
|
|
79814
|
+
};
|
|
79815
|
+
}
|
|
79816
|
+
function sleep(ms) {
|
|
79817
|
+
return new Promise((resolve5) => setTimeout(resolve5, ms));
|
|
79818
|
+
}
|
|
79819
|
+
var DEFAULT_RETRYABLE_ERRORS, RetryManager;
|
|
79820
|
+
var init_RetryManager = __esm({
|
|
79821
|
+
"src/agent/RetryManager.js"() {
|
|
79822
|
+
"use strict";
|
|
79823
|
+
DEFAULT_RETRYABLE_ERRORS = [
|
|
79824
|
+
"Overloaded",
|
|
79825
|
+
"overloaded",
|
|
79826
|
+
"rate_limit",
|
|
79827
|
+
"rate limit",
|
|
79828
|
+
"429",
|
|
79829
|
+
"500",
|
|
79830
|
+
"502",
|
|
79831
|
+
"503",
|
|
79832
|
+
"504",
|
|
79833
|
+
"timeout",
|
|
79834
|
+
"ECONNRESET",
|
|
79835
|
+
"ETIMEDOUT",
|
|
79836
|
+
"ENOTFOUND",
|
|
79837
|
+
"api_error"
|
|
79838
|
+
];
|
|
79839
|
+
RetryManager = class {
|
|
79840
|
+
/**
|
|
79841
|
+
* Create a new RetryManager
|
|
79842
|
+
* @param {Object} options - Configuration options
|
|
79843
|
+
* @param {number} [options.maxRetries=3] - Maximum retry attempts
|
|
79844
|
+
* @param {number} [options.initialDelay=1000] - Initial delay in ms (1 second)
|
|
79845
|
+
* @param {number} [options.maxDelay=30000] - Maximum delay in ms (30 seconds)
|
|
79846
|
+
* @param {number} [options.backoffFactor=2] - Exponential backoff multiplier
|
|
79847
|
+
* @param {Array<string>} [options.retryableErrors] - List of retryable error patterns
|
|
79848
|
+
* @param {boolean} [options.debug=false] - Enable debug logging
|
|
79849
|
+
*/
|
|
79850
|
+
constructor(options = {}) {
|
|
79851
|
+
this.maxRetries = this._validateNumber(options.maxRetries, 3, "maxRetries", 0, 100);
|
|
79852
|
+
this.initialDelay = this._validateNumber(options.initialDelay, 1e3, "initialDelay", 0, 6e4);
|
|
79853
|
+
this.maxDelay = this._validateNumber(options.maxDelay, 3e4, "maxDelay", 0, 3e5);
|
|
79854
|
+
this.backoffFactor = this._validateNumber(options.backoffFactor, 2, "backoffFactor", 1, 10);
|
|
79855
|
+
this.retryableErrors = options.retryableErrors || DEFAULT_RETRYABLE_ERRORS;
|
|
79856
|
+
this.debug = options.debug ?? false;
|
|
79857
|
+
this.jitter = options.jitter ?? true;
|
|
79858
|
+
if (this.maxDelay < this.initialDelay) {
|
|
79859
|
+
throw new Error("maxDelay must be greater than or equal to initialDelay");
|
|
79860
|
+
}
|
|
79861
|
+
this.stats = {
|
|
79862
|
+
totalAttempts: 0,
|
|
79863
|
+
totalRetries: 0,
|
|
79864
|
+
successfulRetries: 0,
|
|
79865
|
+
failedRetries: 0
|
|
79866
|
+
};
|
|
79867
|
+
}
|
|
79868
|
+
/**
|
|
79869
|
+
* Validate a numeric parameter
|
|
79870
|
+
* @param {*} value - Value to validate
|
|
79871
|
+
* @param {number} defaultValue - Default if undefined
|
|
79872
|
+
* @param {string} name - Parameter name for error messages
|
|
79873
|
+
* @param {number} min - Minimum allowed value
|
|
79874
|
+
* @param {number} max - Maximum allowed value
|
|
79875
|
+
* @returns {number} - Validated number
|
|
79876
|
+
* @private
|
|
79877
|
+
*/
|
|
79878
|
+
_validateNumber(value, defaultValue, name14, min, max) {
|
|
79879
|
+
if (value === void 0 || value === null) {
|
|
79880
|
+
return defaultValue;
|
|
79881
|
+
}
|
|
79882
|
+
const num = Number(value);
|
|
79883
|
+
if (isNaN(num)) {
|
|
79884
|
+
throw new Error(`${name14} must be a number, got: ${value}`);
|
|
79885
|
+
}
|
|
79886
|
+
if (num < min || num > max) {
|
|
79887
|
+
throw new Error(`${name14} must be between ${min} and ${max}, got: ${num}`);
|
|
79888
|
+
}
|
|
79889
|
+
return num;
|
|
79890
|
+
}
|
|
79891
|
+
/**
|
|
79892
|
+
* Execute a function with retry logic
|
|
79893
|
+
* @param {Function} fn - Async function to execute
|
|
79894
|
+
* @param {Object} [context={}] - Context information for logging
|
|
79895
|
+
* @param {AbortSignal} [context.signal] - Optional abort signal for cancellation
|
|
79896
|
+
* @returns {Promise<*>} - Result from the function
|
|
79897
|
+
* @throws {Error} - If all retries are exhausted or operation is aborted
|
|
79898
|
+
*/
|
|
79899
|
+
async executeWithRetry(fn, context = {}) {
|
|
79900
|
+
let lastError = null;
|
|
79901
|
+
let currentDelay = this.initialDelay;
|
|
79902
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
79903
|
+
if (context.signal?.aborted) {
|
|
79904
|
+
const abortError = new Error("Operation aborted");
|
|
79905
|
+
abortError.name = "AbortError";
|
|
79906
|
+
throw abortError;
|
|
79907
|
+
}
|
|
79908
|
+
this.stats.totalAttempts++;
|
|
79909
|
+
try {
|
|
79910
|
+
if (this.debug && attempt > 0) {
|
|
79911
|
+
console.log(`[RetryManager] Retry attempt ${attempt}/${this.maxRetries}`, context);
|
|
79912
|
+
}
|
|
79913
|
+
const result = await fn();
|
|
79914
|
+
if (attempt > 0) {
|
|
79915
|
+
this.stats.successfulRetries++;
|
|
79916
|
+
if (this.debug) {
|
|
79917
|
+
console.log(`[RetryManager] \u2705 Retry successful on attempt ${attempt + 1}`, context);
|
|
79918
|
+
}
|
|
79919
|
+
}
|
|
79920
|
+
return result;
|
|
79921
|
+
} catch (error2) {
|
|
79922
|
+
lastError = error2;
|
|
79923
|
+
const errorInfo = extractErrorInfo(error2);
|
|
79924
|
+
const shouldRetry = isRetryableError(error2, this.retryableErrors);
|
|
79925
|
+
const hasRetriesLeft = attempt < this.maxRetries;
|
|
79926
|
+
if (this.debug) {
|
|
79927
|
+
console.log(`[RetryManager] \u274C Attempt ${attempt + 1}/${this.maxRetries + 1} failed:`, {
|
|
79928
|
+
...context,
|
|
79929
|
+
error: errorInfo,
|
|
79930
|
+
shouldRetry,
|
|
79931
|
+
hasRetriesLeft
|
|
79932
|
+
});
|
|
79933
|
+
}
|
|
79934
|
+
if (!shouldRetry) {
|
|
79935
|
+
if (this.debug) {
|
|
79936
|
+
console.log(`[RetryManager] Error is not retryable, failing immediately`, errorInfo);
|
|
79937
|
+
}
|
|
79938
|
+
throw error2;
|
|
79939
|
+
}
|
|
79940
|
+
if (!hasRetriesLeft) {
|
|
79941
|
+
this.stats.failedRetries++;
|
|
79942
|
+
if (this.debug) {
|
|
79943
|
+
console.log(`[RetryManager] Max retries (${this.maxRetries}) exhausted`, context);
|
|
79944
|
+
}
|
|
79945
|
+
throw error2;
|
|
79946
|
+
}
|
|
79947
|
+
this.stats.totalRetries++;
|
|
79948
|
+
let delayWithJitter = currentDelay;
|
|
79949
|
+
if (this.jitter) {
|
|
79950
|
+
const jitterAmount = currentDelay * 0.25;
|
|
79951
|
+
delayWithJitter = currentDelay + (Math.random() * jitterAmount * 2 - jitterAmount);
|
|
79952
|
+
}
|
|
79953
|
+
if (this.debug) {
|
|
79954
|
+
console.log(`[RetryManager] Waiting ${Math.round(delayWithJitter)}ms before retry...`);
|
|
79955
|
+
}
|
|
79956
|
+
await sleep(delayWithJitter);
|
|
79957
|
+
currentDelay = Math.min(currentDelay * this.backoffFactor, this.maxDelay);
|
|
79958
|
+
}
|
|
79959
|
+
}
|
|
79960
|
+
throw lastError;
|
|
79961
|
+
}
|
|
79962
|
+
/**
|
|
79963
|
+
* Check if an error is retryable
|
|
79964
|
+
* @param {Error} error - The error to check
|
|
79965
|
+
* @returns {boolean} - True if error should be retried
|
|
79966
|
+
*/
|
|
79967
|
+
isRetryable(error2) {
|
|
79968
|
+
return isRetryableError(error2, this.retryableErrors);
|
|
79969
|
+
}
|
|
79970
|
+
/**
|
|
79971
|
+
* Get retry statistics
|
|
79972
|
+
* @returns {Object} - Statistics object
|
|
79973
|
+
*/
|
|
79974
|
+
getStats() {
|
|
79975
|
+
return { ...this.stats };
|
|
79976
|
+
}
|
|
79977
|
+
/**
|
|
79978
|
+
* Reset statistics
|
|
79979
|
+
*/
|
|
79980
|
+
resetStats() {
|
|
79981
|
+
this.stats = {
|
|
79982
|
+
totalAttempts: 0,
|
|
79983
|
+
totalRetries: 0,
|
|
79984
|
+
successfulRetries: 0,
|
|
79985
|
+
failedRetries: 0
|
|
79986
|
+
};
|
|
79987
|
+
}
|
|
79988
|
+
};
|
|
79989
|
+
}
|
|
79990
|
+
});
|
|
79991
|
+
|
|
79992
|
+
// src/agent/FallbackManager.js
|
|
79993
|
+
function createFallbackManagerFromEnv(debug = false) {
|
|
79994
|
+
const fallbackProvidersEnv = process.env.FALLBACK_PROVIDERS;
|
|
79995
|
+
const fallbackModelsEnv = process.env.FALLBACK_MODELS;
|
|
79996
|
+
if (!fallbackProvidersEnv && !fallbackModelsEnv) {
|
|
79997
|
+
return null;
|
|
79998
|
+
}
|
|
79999
|
+
let providers = [];
|
|
80000
|
+
let models = [];
|
|
80001
|
+
let strategy = FALLBACK_STRATEGIES.ANY;
|
|
80002
|
+
if (fallbackProvidersEnv) {
|
|
80003
|
+
try {
|
|
80004
|
+
if (typeof fallbackProvidersEnv !== "string" || fallbackProvidersEnv.length > 1e4) {
|
|
80005
|
+
console.error("[FallbackManager] FALLBACK_PROVIDERS must be a valid JSON string under 10KB");
|
|
80006
|
+
return null;
|
|
80007
|
+
}
|
|
80008
|
+
const parsed = JSON.parse(fallbackProvidersEnv);
|
|
80009
|
+
if (!Array.isArray(parsed)) {
|
|
80010
|
+
console.error("[FallbackManager] FALLBACK_PROVIDERS must be a JSON array");
|
|
80011
|
+
return null;
|
|
80012
|
+
}
|
|
80013
|
+
providers = parsed;
|
|
80014
|
+
strategy = FALLBACK_STRATEGIES.CUSTOM;
|
|
80015
|
+
} catch (error2) {
|
|
80016
|
+
console.error("[FallbackManager] Failed to parse FALLBACK_PROVIDERS:", error2.message);
|
|
80017
|
+
return null;
|
|
80018
|
+
}
|
|
80019
|
+
}
|
|
80020
|
+
if (fallbackModelsEnv) {
|
|
80021
|
+
try {
|
|
80022
|
+
if (typeof fallbackModelsEnv !== "string" || fallbackModelsEnv.length > 1e4) {
|
|
80023
|
+
console.error("[FallbackManager] FALLBACK_MODELS must be a valid JSON string under 10KB");
|
|
80024
|
+
return null;
|
|
80025
|
+
}
|
|
80026
|
+
const parsed = JSON.parse(fallbackModelsEnv);
|
|
80027
|
+
if (!Array.isArray(parsed)) {
|
|
80028
|
+
console.error("[FallbackManager] FALLBACK_MODELS must be a JSON array");
|
|
80029
|
+
return null;
|
|
80030
|
+
}
|
|
80031
|
+
models = parsed;
|
|
80032
|
+
strategy = FALLBACK_STRATEGIES.SAME_PROVIDER;
|
|
80033
|
+
} catch (error2) {
|
|
80034
|
+
console.error("[FallbackManager] Failed to parse FALLBACK_MODELS:", error2.message);
|
|
80035
|
+
return null;
|
|
80036
|
+
}
|
|
80037
|
+
}
|
|
80038
|
+
const maxTotalAttempts = process.env.FALLBACK_MAX_TOTAL_ATTEMPTS ? (() => {
|
|
80039
|
+
const val = parseInt(process.env.FALLBACK_MAX_TOTAL_ATTEMPTS, 10);
|
|
80040
|
+
if (isNaN(val) || val < 1 || val > 100) {
|
|
80041
|
+
console.warn("[FallbackManager] FALLBACK_MAX_TOTAL_ATTEMPTS must be between 1 and 100, using default: 10");
|
|
80042
|
+
return 10;
|
|
80043
|
+
}
|
|
80044
|
+
return val;
|
|
80045
|
+
})() : 10;
|
|
80046
|
+
return new FallbackManager({
|
|
80047
|
+
strategy,
|
|
80048
|
+
providers,
|
|
80049
|
+
models,
|
|
80050
|
+
maxTotalAttempts,
|
|
80051
|
+
debug
|
|
80052
|
+
});
|
|
80053
|
+
}
|
|
80054
|
+
function buildFallbackProvidersFromEnv(options = {}) {
|
|
80055
|
+
const providers = [];
|
|
80056
|
+
const anthropicApiKey = process.env.ANTHROPIC_API_KEY || process.env.ANTHROPIC_AUTH_TOKEN;
|
|
80057
|
+
const openaiApiKey = process.env.OPENAI_API_KEY;
|
|
80058
|
+
const googleApiKey = process.env.GOOGLE_GENERATIVE_AI_API_KEY || process.env.GOOGLE_API_KEY;
|
|
80059
|
+
const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
|
80060
|
+
const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
80061
|
+
const awsRegion = process.env.AWS_REGION;
|
|
80062
|
+
const awsApiKey = process.env.AWS_BEDROCK_API_KEY;
|
|
80063
|
+
const llmBaseUrl = process.env.LLM_BASE_URL;
|
|
80064
|
+
const anthropicApiUrl = process.env.ANTHROPIC_API_URL || process.env.ANTHROPIC_BASE_URL || llmBaseUrl;
|
|
80065
|
+
const openaiApiUrl = process.env.OPENAI_API_URL || llmBaseUrl;
|
|
80066
|
+
const googleApiUrl = process.env.GOOGLE_API_URL || llmBaseUrl;
|
|
80067
|
+
const awsBedrockBaseUrl = process.env.AWS_BEDROCK_BASE_URL || llmBaseUrl;
|
|
80068
|
+
const primaryProvider = options.primaryProvider?.toLowerCase();
|
|
80069
|
+
const primaryModel = options.primaryModel;
|
|
80070
|
+
if (primaryProvider === "anthropic" && anthropicApiKey) {
|
|
80071
|
+
providers.push({
|
|
80072
|
+
provider: "anthropic",
|
|
80073
|
+
apiKey: anthropicApiKey,
|
|
80074
|
+
...anthropicApiUrl && { baseURL: anthropicApiUrl },
|
|
80075
|
+
...primaryModel && { model: primaryModel }
|
|
80076
|
+
});
|
|
80077
|
+
} else if (primaryProvider === "openai" && openaiApiKey) {
|
|
80078
|
+
providers.push({
|
|
80079
|
+
provider: "openai",
|
|
80080
|
+
apiKey: openaiApiKey,
|
|
80081
|
+
...openaiApiUrl && { baseURL: openaiApiUrl },
|
|
80082
|
+
...primaryModel && { model: primaryModel }
|
|
80083
|
+
});
|
|
80084
|
+
} else if (primaryProvider === "google" && googleApiKey) {
|
|
80085
|
+
providers.push({
|
|
80086
|
+
provider: "google",
|
|
80087
|
+
apiKey: googleApiKey,
|
|
80088
|
+
...googleApiUrl && { baseURL: googleApiUrl },
|
|
80089
|
+
...primaryModel && { model: primaryModel }
|
|
80090
|
+
});
|
|
80091
|
+
} else if (primaryProvider === "bedrock" && (awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey)) {
|
|
80092
|
+
const config = { provider: "bedrock" };
|
|
80093
|
+
if (awsApiKey) {
|
|
80094
|
+
config.apiKey = awsApiKey;
|
|
80095
|
+
} else {
|
|
80096
|
+
config.accessKeyId = awsAccessKeyId;
|
|
80097
|
+
config.secretAccessKey = awsSecretAccessKey;
|
|
80098
|
+
config.region = awsRegion;
|
|
80099
|
+
if (process.env.AWS_SESSION_TOKEN) {
|
|
80100
|
+
config.sessionToken = process.env.AWS_SESSION_TOKEN;
|
|
80101
|
+
}
|
|
80102
|
+
}
|
|
80103
|
+
if (awsBedrockBaseUrl) config.baseURL = awsBedrockBaseUrl;
|
|
80104
|
+
if (primaryModel) config.model = primaryModel;
|
|
80105
|
+
providers.push(config);
|
|
80106
|
+
}
|
|
80107
|
+
if (anthropicApiKey && primaryProvider !== "anthropic") {
|
|
80108
|
+
providers.push({
|
|
80109
|
+
provider: "anthropic",
|
|
80110
|
+
apiKey: anthropicApiKey,
|
|
80111
|
+
...anthropicApiUrl && { baseURL: anthropicApiUrl }
|
|
80112
|
+
});
|
|
80113
|
+
}
|
|
80114
|
+
if (openaiApiKey && primaryProvider !== "openai") {
|
|
80115
|
+
providers.push({
|
|
80116
|
+
provider: "openai",
|
|
80117
|
+
apiKey: openaiApiKey,
|
|
80118
|
+
...openaiApiUrl && { baseURL: openaiApiUrl }
|
|
80119
|
+
});
|
|
80120
|
+
}
|
|
80121
|
+
if (googleApiKey && primaryProvider !== "google") {
|
|
80122
|
+
providers.push({
|
|
80123
|
+
provider: "google",
|
|
80124
|
+
apiKey: googleApiKey,
|
|
80125
|
+
...googleApiUrl && { baseURL: googleApiUrl }
|
|
80126
|
+
});
|
|
80127
|
+
}
|
|
80128
|
+
if ((awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey) && primaryProvider !== "bedrock") {
|
|
80129
|
+
const config = { provider: "bedrock" };
|
|
80130
|
+
if (awsApiKey) {
|
|
80131
|
+
config.apiKey = awsApiKey;
|
|
80132
|
+
} else {
|
|
80133
|
+
config.accessKeyId = awsAccessKeyId;
|
|
80134
|
+
config.secretAccessKey = awsSecretAccessKey;
|
|
80135
|
+
config.region = awsRegion;
|
|
80136
|
+
if (process.env.AWS_SESSION_TOKEN) {
|
|
80137
|
+
config.sessionToken = process.env.AWS_SESSION_TOKEN;
|
|
80138
|
+
}
|
|
80139
|
+
}
|
|
80140
|
+
if (awsBedrockBaseUrl) config.baseURL = awsBedrockBaseUrl;
|
|
80141
|
+
providers.push(config);
|
|
80142
|
+
}
|
|
80143
|
+
return providers;
|
|
80144
|
+
}
|
|
80145
|
+
var import_anthropic, import_openai, import_google, FALLBACK_STRATEGIES, DEFAULT_MODELS, FallbackManager;
|
|
80146
|
+
var init_FallbackManager = __esm({
|
|
80147
|
+
"src/agent/FallbackManager.js"() {
|
|
80148
|
+
"use strict";
|
|
80149
|
+
import_anthropic = require("@ai-sdk/anthropic");
|
|
80150
|
+
import_openai = require("@ai-sdk/openai");
|
|
80151
|
+
import_google = require("@ai-sdk/google");
|
|
80152
|
+
init_dist3();
|
|
80153
|
+
FALLBACK_STRATEGIES = {
|
|
80154
|
+
SAME_MODEL: "same-model",
|
|
80155
|
+
// Try same model on different providers
|
|
80156
|
+
SAME_PROVIDER: "same-provider",
|
|
80157
|
+
// Try different models on same provider
|
|
80158
|
+
ANY: "any",
|
|
80159
|
+
// Try any available provider/model
|
|
80160
|
+
CUSTOM: "custom"
|
|
80161
|
+
// Use custom provider list
|
|
80162
|
+
};
|
|
80163
|
+
DEFAULT_MODELS = {
|
|
80164
|
+
anthropic: "claude-sonnet-4-5-20250929",
|
|
80165
|
+
openai: "gpt-4o",
|
|
80166
|
+
google: "gemini-2.0-flash-exp",
|
|
80167
|
+
bedrock: "anthropic.claude-sonnet-4-20250514-v1:0"
|
|
80168
|
+
};
|
|
80169
|
+
FallbackManager = class {
|
|
80170
|
+
/**
|
|
80171
|
+
* Create a new FallbackManager
|
|
80172
|
+
* @param {Object} options - Configuration options
|
|
80173
|
+
* @param {string} [options.strategy='any'] - Fallback strategy
|
|
80174
|
+
* @param {Array<string>} [options.models] - List of models for same-provider fallback
|
|
80175
|
+
* @param {Array<ProviderConfig>} [options.providers] - List of provider configurations
|
|
80176
|
+
* @param {boolean} [options.stopOnSuccess=true] - Stop on first success
|
|
80177
|
+
* @param {boolean} [options.continueOnNonRetryableError=false] - Continue to fallback on non-retryable errors
|
|
80178
|
+
* @param {number} [options.maxTotalAttempts=10] - Maximum total attempts across all providers
|
|
80179
|
+
* @param {boolean} [options.debug=false] - Enable debug logging
|
|
80180
|
+
*/
|
|
80181
|
+
constructor(options = {}) {
|
|
80182
|
+
this.strategy = options.strategy || FALLBACK_STRATEGIES.ANY;
|
|
80183
|
+
this.models = Array.isArray(options.models) ? options.models : [];
|
|
80184
|
+
this.providers = Array.isArray(options.providers) ? options.providers : [];
|
|
80185
|
+
this.stopOnSuccess = options.stopOnSuccess ?? true;
|
|
80186
|
+
this.continueOnNonRetryableError = options.continueOnNonRetryableError ?? false;
|
|
80187
|
+
this.debug = options.debug ?? false;
|
|
80188
|
+
const maxAttempts = options.maxTotalAttempts ?? 10;
|
|
80189
|
+
if (typeof maxAttempts !== "number" || isNaN(maxAttempts) || maxAttempts < 1 || maxAttempts > 100) {
|
|
80190
|
+
throw new Error(`FallbackManager: maxTotalAttempts must be a number between 1 and 100, got: ${maxAttempts}`);
|
|
80191
|
+
}
|
|
80192
|
+
this.maxTotalAttempts = maxAttempts;
|
|
80193
|
+
this.stats = {
|
|
80194
|
+
totalAttempts: 0,
|
|
80195
|
+
providerAttempts: {},
|
|
80196
|
+
successfulProvider: null,
|
|
80197
|
+
failedProviders: []
|
|
80198
|
+
};
|
|
80199
|
+
this._validateConfiguration();
|
|
80200
|
+
}
|
|
80201
|
+
/**
|
|
80202
|
+
* Validate the fallback configuration
|
|
80203
|
+
* @private
|
|
80204
|
+
*/
|
|
80205
|
+
_validateConfiguration() {
|
|
80206
|
+
if (this.strategy === FALLBACK_STRATEGIES.SAME_PROVIDER && this.models.length === 0) {
|
|
80207
|
+
throw new Error('FallbackManager: strategy "same-provider" requires models list');
|
|
80208
|
+
}
|
|
80209
|
+
if (this.strategy === FALLBACK_STRATEGIES.CUSTOM && this.providers.length === 0) {
|
|
80210
|
+
throw new Error('FallbackManager: strategy "custom" requires providers list');
|
|
80211
|
+
}
|
|
80212
|
+
for (const config of this.providers) {
|
|
80213
|
+
if (!config.provider) {
|
|
80214
|
+
throw new Error('FallbackManager: Each provider config must have a "provider" field');
|
|
80215
|
+
}
|
|
80216
|
+
if (!["anthropic", "openai", "google", "bedrock"].includes(config.provider)) {
|
|
80217
|
+
throw new Error(`FallbackManager: Invalid provider "${config.provider}". Must be: anthropic, openai, google, or bedrock`);
|
|
80218
|
+
}
|
|
80219
|
+
if (config.provider === "bedrock") {
|
|
80220
|
+
const hasCredentials = config.accessKeyId && config.secretAccessKey && config.region;
|
|
80221
|
+
const hasApiKey = config.apiKey;
|
|
80222
|
+
if (!hasCredentials && !hasApiKey) {
|
|
80223
|
+
throw new Error("FallbackManager: Bedrock provider requires either (accessKeyId, secretAccessKey, region) or apiKey");
|
|
80224
|
+
}
|
|
80225
|
+
} else {
|
|
80226
|
+
if (!config.apiKey) {
|
|
80227
|
+
throw new Error(`FallbackManager: Provider "${config.provider}" requires apiKey`);
|
|
80228
|
+
}
|
|
80229
|
+
}
|
|
80230
|
+
}
|
|
80231
|
+
}
|
|
80232
|
+
/**
|
|
80233
|
+
* Create a provider instance from configuration
|
|
80234
|
+
* @param {ProviderConfig} config - Provider configuration
|
|
80235
|
+
* @returns {Object} - Provider instance
|
|
80236
|
+
* @throws {Error} - If provider creation fails
|
|
80237
|
+
* @private
|
|
80238
|
+
*/
|
|
80239
|
+
_createProviderInstance(config) {
|
|
80240
|
+
try {
|
|
80241
|
+
switch (config.provider) {
|
|
80242
|
+
case "anthropic":
|
|
80243
|
+
return (0, import_anthropic.createAnthropic)({
|
|
80244
|
+
apiKey: config.apiKey,
|
|
80245
|
+
...config.baseURL && { baseURL: config.baseURL }
|
|
80246
|
+
});
|
|
80247
|
+
case "openai":
|
|
80248
|
+
return (0, import_openai.createOpenAI)({
|
|
80249
|
+
compatibility: "strict",
|
|
80250
|
+
apiKey: config.apiKey,
|
|
80251
|
+
...config.baseURL && { baseURL: config.baseURL }
|
|
80252
|
+
});
|
|
80253
|
+
case "google":
|
|
80254
|
+
return (0, import_google.createGoogleGenerativeAI)({
|
|
80255
|
+
apiKey: config.apiKey,
|
|
80256
|
+
...config.baseURL && { baseURL: config.baseURL }
|
|
80257
|
+
});
|
|
80258
|
+
case "bedrock": {
|
|
80259
|
+
const bedrockConfig = {};
|
|
80260
|
+
if (config.apiKey) {
|
|
80261
|
+
bedrockConfig.apiKey = config.apiKey;
|
|
80262
|
+
} else if (config.accessKeyId && config.secretAccessKey) {
|
|
80263
|
+
bedrockConfig.accessKeyId = config.accessKeyId;
|
|
80264
|
+
bedrockConfig.secretAccessKey = config.secretAccessKey;
|
|
80265
|
+
if (config.sessionToken) {
|
|
80266
|
+
bedrockConfig.sessionToken = config.sessionToken;
|
|
80267
|
+
}
|
|
80268
|
+
}
|
|
80269
|
+
if (config.region) {
|
|
80270
|
+
bedrockConfig.region = config.region;
|
|
80271
|
+
}
|
|
80272
|
+
if (config.baseURL) {
|
|
80273
|
+
bedrockConfig.baseURL = config.baseURL;
|
|
80274
|
+
}
|
|
80275
|
+
return createAmazonBedrock(bedrockConfig);
|
|
80276
|
+
}
|
|
80277
|
+
default:
|
|
80278
|
+
throw new Error(`FallbackManager: Unknown provider "${config.provider}"`);
|
|
80279
|
+
}
|
|
80280
|
+
} catch (error2) {
|
|
80281
|
+
const providerName = this._getProviderDisplayName(config);
|
|
80282
|
+
throw new Error(`Failed to create provider instance for ${providerName}: ${error2.message}`);
|
|
80283
|
+
}
|
|
80284
|
+
}
|
|
80285
|
+
/**
|
|
80286
|
+
* Get the model name for a provider configuration
|
|
80287
|
+
* @param {ProviderConfig} config - Provider configuration
|
|
80288
|
+
* @returns {string} - Model name
|
|
80289
|
+
* @private
|
|
80290
|
+
*/
|
|
80291
|
+
_getModelName(config) {
|
|
80292
|
+
return config.model || DEFAULT_MODELS[config.provider];
|
|
80293
|
+
}
|
|
80294
|
+
/**
|
|
80295
|
+
* Get provider display name for logging
|
|
80296
|
+
* @param {ProviderConfig} config - Provider configuration
|
|
80297
|
+
* @returns {string} - Display name
|
|
80298
|
+
* @private
|
|
80299
|
+
*/
|
|
80300
|
+
_getProviderDisplayName(config) {
|
|
80301
|
+
const model = this._getModelName(config);
|
|
80302
|
+
const provider = config.provider;
|
|
80303
|
+
const url = config.baseURL ? ` (${config.baseURL})` : "";
|
|
80304
|
+
return `${provider}/${model}${url}`;
|
|
80305
|
+
}
|
|
80306
|
+
/**
|
|
80307
|
+
* Execute a function with fallback support
|
|
80308
|
+
* @param {Function} fn - Function that takes (provider, model, config) and returns a Promise
|
|
80309
|
+
* @returns {Promise<*>} - Result from the function
|
|
80310
|
+
* @throws {Error} - If all fallbacks are exhausted
|
|
80311
|
+
*/
|
|
80312
|
+
async executeWithFallback(fn) {
|
|
80313
|
+
if (this.providers.length === 0) {
|
|
80314
|
+
throw new Error("FallbackManager: No providers configured for fallback");
|
|
80315
|
+
}
|
|
80316
|
+
let lastError = null;
|
|
80317
|
+
let totalAttempts = 0;
|
|
80318
|
+
for (const config of this.providers) {
|
|
80319
|
+
if (totalAttempts >= this.maxTotalAttempts) {
|
|
80320
|
+
if (this.debug) {
|
|
80321
|
+
console.log(`[FallbackManager] \u26A0\uFE0F Max total attempts (${this.maxTotalAttempts}) reached`);
|
|
80322
|
+
}
|
|
80323
|
+
break;
|
|
80324
|
+
}
|
|
80325
|
+
totalAttempts++;
|
|
80326
|
+
this.stats.totalAttempts++;
|
|
80327
|
+
const providerName = this._getProviderDisplayName(config);
|
|
80328
|
+
this.stats.providerAttempts[providerName] = (this.stats.providerAttempts[providerName] || 0) + 1;
|
|
80329
|
+
try {
|
|
80330
|
+
if (this.debug) {
|
|
80331
|
+
console.log(`[FallbackManager] Attempting provider: ${providerName} (attempt ${totalAttempts}/${this.maxTotalAttempts})`);
|
|
80332
|
+
}
|
|
80333
|
+
const provider = this._createProviderInstance(config);
|
|
80334
|
+
const model = this._getModelName(config);
|
|
80335
|
+
const result = await fn(provider, model, config);
|
|
80336
|
+
this.stats.successfulProvider = providerName;
|
|
80337
|
+
if (this.debug) {
|
|
80338
|
+
console.log(`[FallbackManager] \u2705 Success with provider: ${providerName}`);
|
|
80339
|
+
}
|
|
80340
|
+
return result;
|
|
80341
|
+
} catch (error2) {
|
|
80342
|
+
lastError = error2;
|
|
80343
|
+
const errorInfo = {
|
|
80344
|
+
message: error2.message || error2.toString(),
|
|
80345
|
+
type: error2.type || error2.constructor.name,
|
|
80346
|
+
statusCode: error2.statusCode || error2.status
|
|
80347
|
+
};
|
|
80348
|
+
this.stats.failedProviders.push({
|
|
80349
|
+
provider: providerName,
|
|
80350
|
+
error: errorInfo
|
|
80351
|
+
});
|
|
80352
|
+
if (this.debug) {
|
|
80353
|
+
console.log(`[FallbackManager] \u274C Failed with provider: ${providerName}`, errorInfo);
|
|
80354
|
+
}
|
|
80355
|
+
if (!this.continueOnNonRetryableError && error2.nonRetryable) {
|
|
80356
|
+
if (this.debug) {
|
|
80357
|
+
console.log(`[FallbackManager] Non-retryable error, stopping fallback chain`);
|
|
80358
|
+
}
|
|
80359
|
+
throw error2;
|
|
80360
|
+
}
|
|
80361
|
+
if (this.debug) {
|
|
80362
|
+
const remaining = this.providers.length - (this.providers.indexOf(config) + 1);
|
|
80363
|
+
console.log(`[FallbackManager] Trying next provider (${remaining} remaining)...`);
|
|
80364
|
+
}
|
|
80365
|
+
}
|
|
80366
|
+
}
|
|
80367
|
+
if (this.debug) {
|
|
80368
|
+
console.log(`[FallbackManager] \u274C All providers exhausted. Total attempts: ${totalAttempts}`);
|
|
80369
|
+
}
|
|
80370
|
+
const fallbackError = new Error(
|
|
80371
|
+
`All provider fallbacks exhausted after ${totalAttempts} attempts. Last error: ${lastError?.message || "Unknown error"}`
|
|
80372
|
+
);
|
|
80373
|
+
fallbackError.cause = lastError;
|
|
80374
|
+
fallbackError.stats = this.getStats();
|
|
80375
|
+
fallbackError.allProvidersFailed = true;
|
|
80376
|
+
throw fallbackError;
|
|
80377
|
+
}
|
|
80378
|
+
/**
|
|
80379
|
+
* Get fallback statistics
|
|
80380
|
+
* @returns {Object} - Statistics object
|
|
80381
|
+
*/
|
|
80382
|
+
getStats() {
|
|
80383
|
+
return {
|
|
80384
|
+
...this.stats,
|
|
80385
|
+
providerAttempts: { ...this.stats.providerAttempts },
|
|
80386
|
+
failedProviders: [...this.stats.failedProviders]
|
|
80387
|
+
};
|
|
80388
|
+
}
|
|
80389
|
+
/**
|
|
80390
|
+
* Reset statistics
|
|
80391
|
+
*/
|
|
80392
|
+
resetStats() {
|
|
80393
|
+
this.stats = {
|
|
80394
|
+
totalAttempts: 0,
|
|
80395
|
+
providerAttempts: {},
|
|
80396
|
+
successfulProvider: null,
|
|
80397
|
+
failedProviders: []
|
|
80398
|
+
};
|
|
80399
|
+
}
|
|
80400
|
+
};
|
|
80401
|
+
}
|
|
80402
|
+
});
|
|
80403
|
+
|
|
80404
|
+
// src/agent/contextCompactor.js
|
|
80405
|
+
var contextCompactor_exports = {};
|
|
80406
|
+
__export(contextCompactor_exports, {
|
|
80407
|
+
calculateCompactionStats: () => calculateCompactionStats,
|
|
80408
|
+
compactMessages: () => compactMessages,
|
|
80409
|
+
handleContextLimitError: () => handleContextLimitError,
|
|
80410
|
+
identifyMessageSegments: () => identifyMessageSegments,
|
|
80411
|
+
isContextLimitError: () => isContextLimitError
|
|
80412
|
+
});
|
|
80413
|
+
function isContextLimitError(error2) {
|
|
80414
|
+
if (!error2) return false;
|
|
80415
|
+
const errorMessage = (typeof error2 === "string" ? error2 : error2?.message || "").toLowerCase();
|
|
80416
|
+
const errorString = error2.toString().toLowerCase();
|
|
80417
|
+
for (const pattern of CONTEXT_LIMIT_ERROR_PATTERNS) {
|
|
80418
|
+
const lowerPattern = pattern.toLowerCase();
|
|
80419
|
+
if (errorMessage.includes(lowerPattern) || errorString.includes(lowerPattern)) {
|
|
80420
|
+
return true;
|
|
80421
|
+
}
|
|
80422
|
+
}
|
|
80423
|
+
return false;
|
|
80424
|
+
}
|
|
80425
|
+
function identifyMessageSegments(messages) {
|
|
80426
|
+
const segments = [];
|
|
80427
|
+
let currentSegment = null;
|
|
80428
|
+
for (let i3 = 0; i3 < messages.length; i3++) {
|
|
80429
|
+
const msg = messages[i3];
|
|
80430
|
+
if (msg.role === "system") {
|
|
80431
|
+
continue;
|
|
80432
|
+
}
|
|
80433
|
+
if (msg.role === "user") {
|
|
80434
|
+
const content = typeof msg.content === "string" ? msg.content : "";
|
|
80435
|
+
const isToolResult = content.includes("<tool_result>");
|
|
80436
|
+
if (isToolResult && currentSegment) {
|
|
80437
|
+
currentSegment.finalIndex = i3;
|
|
80438
|
+
segments.push(currentSegment);
|
|
80439
|
+
currentSegment = null;
|
|
80440
|
+
} else {
|
|
80441
|
+
if (currentSegment) {
|
|
80442
|
+
segments.push(currentSegment);
|
|
80443
|
+
}
|
|
80444
|
+
currentSegment = {
|
|
80445
|
+
userIndex: i3,
|
|
80446
|
+
monologueIndices: [],
|
|
80447
|
+
finalIndex: null
|
|
80448
|
+
};
|
|
80449
|
+
}
|
|
80450
|
+
}
|
|
80451
|
+
if (msg.role === "assistant" && currentSegment) {
|
|
80452
|
+
const content = typeof msg.content === "string" ? msg.content : "";
|
|
80453
|
+
if (content.includes("<attempt_completion>") || content.includes("attempt_completion")) {
|
|
80454
|
+
currentSegment.monologueIndices.push(i3);
|
|
80455
|
+
currentSegment.finalIndex = i3;
|
|
80456
|
+
segments.push(currentSegment);
|
|
80457
|
+
currentSegment = null;
|
|
80458
|
+
} else {
|
|
80459
|
+
currentSegment.monologueIndices.push(i3);
|
|
80460
|
+
}
|
|
80461
|
+
}
|
|
80462
|
+
}
|
|
80463
|
+
if (currentSegment) {
|
|
80464
|
+
segments.push(currentSegment);
|
|
80465
|
+
}
|
|
80466
|
+
return segments;
|
|
80467
|
+
}
|
|
80468
|
+
function compactMessages(messages, options = {}) {
|
|
80469
|
+
const {
|
|
80470
|
+
keepLastSegment = true,
|
|
80471
|
+
minSegmentsToKeep = 1
|
|
80472
|
+
} = options;
|
|
80473
|
+
if (!messages || messages.length === 0) {
|
|
80474
|
+
return messages;
|
|
80475
|
+
}
|
|
80476
|
+
const segments = identifyMessageSegments(messages);
|
|
80477
|
+
if (segments.length === 0) {
|
|
80478
|
+
return messages;
|
|
80479
|
+
}
|
|
80480
|
+
const segmentsToPreserve = keepLastSegment ? Math.max(minSegmentsToKeep, 1) : minSegmentsToKeep;
|
|
80481
|
+
const compactableSegments = segments.slice(0, -segmentsToPreserve);
|
|
80482
|
+
const preservedSegments = segments.slice(-segmentsToPreserve);
|
|
80483
|
+
const indicesToKeep = /* @__PURE__ */ new Set();
|
|
80484
|
+
messages.forEach((msg, idx) => {
|
|
80485
|
+
if (msg.role === "system") {
|
|
80486
|
+
indicesToKeep.add(idx);
|
|
80487
|
+
}
|
|
80488
|
+
});
|
|
80489
|
+
compactableSegments.forEach((segment) => {
|
|
80490
|
+
indicesToKeep.add(segment.userIndex);
|
|
80491
|
+
if (segment.finalIndex !== null) {
|
|
80492
|
+
indicesToKeep.add(segment.finalIndex);
|
|
80493
|
+
}
|
|
80494
|
+
});
|
|
80495
|
+
preservedSegments.forEach((segment) => {
|
|
80496
|
+
indicesToKeep.add(segment.userIndex);
|
|
80497
|
+
segment.monologueIndices.forEach((idx) => indicesToKeep.add(idx));
|
|
80498
|
+
if (segment.finalIndex !== null) {
|
|
80499
|
+
indicesToKeep.add(segment.finalIndex);
|
|
80500
|
+
}
|
|
80501
|
+
});
|
|
80502
|
+
const compactedMessages = messages.filter((_2, idx) => indicesToKeep.has(idx));
|
|
80503
|
+
return compactedMessages;
|
|
80504
|
+
}
|
|
80505
|
+
function calculateCompactionStats(originalMessages, compactedMessages) {
|
|
80506
|
+
const originalCount = originalMessages.length;
|
|
80507
|
+
const compactedCount = compactedMessages.length;
|
|
80508
|
+
const removed = originalCount - compactedCount;
|
|
80509
|
+
const reductionPercent = originalCount > 0 ? (removed / originalCount * 100).toFixed(1) : 0;
|
|
80510
|
+
const estimateTokens = (msgs) => {
|
|
80511
|
+
return msgs.reduce((sum, msg) => {
|
|
80512
|
+
const content = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
80513
|
+
return sum + Math.ceil(content.length / 4);
|
|
80514
|
+
}, 0);
|
|
80515
|
+
};
|
|
80516
|
+
const originalTokens = estimateTokens(originalMessages);
|
|
80517
|
+
const compactedTokens = estimateTokens(compactedMessages);
|
|
80518
|
+
const tokensSaved = originalTokens - compactedTokens;
|
|
80519
|
+
return {
|
|
80520
|
+
originalCount,
|
|
80521
|
+
compactedCount,
|
|
80522
|
+
removed,
|
|
80523
|
+
reductionPercent: parseFloat(reductionPercent),
|
|
80524
|
+
originalTokens,
|
|
80525
|
+
compactedTokens,
|
|
80526
|
+
tokensSaved
|
|
80527
|
+
};
|
|
80528
|
+
}
|
|
80529
|
+
function handleContextLimitError(error2, messages, options = {}) {
|
|
80530
|
+
if (!isContextLimitError(error2)) {
|
|
80531
|
+
return null;
|
|
80532
|
+
}
|
|
80533
|
+
const compactedMessages = compactMessages(messages, options);
|
|
80534
|
+
const stats = calculateCompactionStats(messages, compactedMessages);
|
|
80535
|
+
return {
|
|
80536
|
+
compacted: true,
|
|
80537
|
+
messages: compactedMessages,
|
|
80538
|
+
stats
|
|
80539
|
+
};
|
|
80540
|
+
}
|
|
80541
|
+
var CONTEXT_LIMIT_ERROR_PATTERNS;
|
|
80542
|
+
var init_contextCompactor = __esm({
|
|
80543
|
+
"src/agent/contextCompactor.js"() {
|
|
80544
|
+
"use strict";
|
|
80545
|
+
CONTEXT_LIMIT_ERROR_PATTERNS = [
|
|
80546
|
+
// Anthropic
|
|
80547
|
+
"context_length_exceeded",
|
|
80548
|
+
"prompt is too long",
|
|
80549
|
+
// OpenAI
|
|
80550
|
+
"maximum context length",
|
|
80551
|
+
"context length is",
|
|
80552
|
+
// Google/Gemini
|
|
80553
|
+
"input token count exceeds",
|
|
80554
|
+
"token limit exceeded",
|
|
80555
|
+
// Generic patterns
|
|
80556
|
+
"context window",
|
|
80557
|
+
"too many tokens",
|
|
80558
|
+
"token limit",
|
|
80559
|
+
"context limit",
|
|
80560
|
+
"exceed",
|
|
80561
|
+
// Catches "exceeds", "exceed maximum", etc.
|
|
80562
|
+
"over the limit",
|
|
80563
|
+
"maximum tokens"
|
|
80564
|
+
];
|
|
80565
|
+
}
|
|
80566
|
+
});
|
|
80567
|
+
|
|
79242
80568
|
// src/agent/ProbeAgent.js
|
|
79243
80569
|
var ProbeAgent_exports = {};
|
|
79244
80570
|
__export(ProbeAgent_exports, {
|
|
79245
80571
|
ProbeAgent: () => ProbeAgent
|
|
79246
80572
|
});
|
|
79247
|
-
var import_dotenv,
|
|
80573
|
+
var import_dotenv, import_anthropic2, import_openai2, import_google2, import_ai, import_crypto4, import_events2, import_fs5, import_promises2, import_path6, MAX_TOOL_ITERATIONS, MAX_HISTORY_MESSAGES, MAX_IMAGE_FILE_SIZE, ProbeAgent;
|
|
79248
80574
|
var init_ProbeAgent = __esm({
|
|
79249
80575
|
"src/agent/ProbeAgent.js"() {
|
|
79250
80576
|
"use strict";
|
|
79251
80577
|
import_dotenv = __toESM(require_main(), 1);
|
|
79252
|
-
|
|
79253
|
-
|
|
79254
|
-
|
|
80578
|
+
import_anthropic2 = require("@ai-sdk/anthropic");
|
|
80579
|
+
import_openai2 = require("@ai-sdk/openai");
|
|
80580
|
+
import_google2 = require("@ai-sdk/google");
|
|
79255
80581
|
init_dist3();
|
|
79256
80582
|
import_ai = require("ai");
|
|
79257
80583
|
import_crypto4 = require("crypto");
|
|
@@ -79271,8 +80597,18 @@ var init_ProbeAgent = __esm({
|
|
|
79271
80597
|
init_schemaUtils();
|
|
79272
80598
|
init_xmlParsingUtils();
|
|
79273
80599
|
init_mcp();
|
|
80600
|
+
init_RetryManager();
|
|
80601
|
+
init_FallbackManager();
|
|
80602
|
+
init_contextCompactor();
|
|
79274
80603
|
import_dotenv.default.config();
|
|
79275
|
-
MAX_TOOL_ITERATIONS =
|
|
80604
|
+
MAX_TOOL_ITERATIONS = (() => {
|
|
80605
|
+
const val = parseInt(process.env.MAX_TOOL_ITERATIONS || "30", 10);
|
|
80606
|
+
if (isNaN(val) || val < 1 || val > 200) {
|
|
80607
|
+
console.warn("[ProbeAgent] MAX_TOOL_ITERATIONS must be between 1 and 200, using default: 30");
|
|
80608
|
+
return 30;
|
|
80609
|
+
}
|
|
80610
|
+
return val;
|
|
80611
|
+
})();
|
|
79276
80612
|
MAX_HISTORY_MESSAGES = 100;
|
|
79277
80613
|
MAX_IMAGE_FILE_SIZE = 20 * 1024 * 1024;
|
|
79278
80614
|
ProbeAgent = class _ProbeAgent {
|
|
@@ -79299,6 +80635,20 @@ var init_ProbeAgent = __esm({
|
|
|
79299
80635
|
* @param {Array} [options.mcpServers] - Deprecated, use mcpConfig instead
|
|
79300
80636
|
* @param {Object} [options.storageAdapter] - Custom storage adapter for history management
|
|
79301
80637
|
* @param {Object} [options.hooks] - Hook callbacks for events (e.g., {'tool:start': callback})
|
|
80638
|
+
* @param {Array<string>|null} [options.allowedTools] - List of allowed tool names. Use ['*'] for all tools (default), [] or null for no tools (raw AI mode), or specific tool names like ['search', 'query', 'extract']. Supports exclusion with '!' prefix (e.g., ['*', '!bash'])
|
|
80639
|
+
* @param {boolean} [options.disableTools=false] - Convenience flag to disable all tools (equivalent to allowedTools: []). Takes precedence over allowedTools if set.
|
|
80640
|
+
* @param {Object} [options.retry] - Retry configuration
|
|
80641
|
+
* @param {number} [options.retry.maxRetries=3] - Maximum retry attempts per provider
|
|
80642
|
+
* @param {number} [options.retry.initialDelay=1000] - Initial delay in ms
|
|
80643
|
+
* @param {number} [options.retry.maxDelay=30000] - Maximum delay in ms
|
|
80644
|
+
* @param {number} [options.retry.backoffFactor=2] - Exponential backoff multiplier
|
|
80645
|
+
* @param {Array<string>} [options.retry.retryableErrors] - List of retryable error patterns
|
|
80646
|
+
* @param {Object} [options.fallback] - Fallback configuration
|
|
80647
|
+
* @param {string} [options.fallback.strategy] - Fallback strategy: 'same-model', 'same-provider', 'any', 'custom'
|
|
80648
|
+
* @param {Array<string>} [options.fallback.models] - List of models for same-provider fallback
|
|
80649
|
+
* @param {Array<Object>} [options.fallback.providers] - List of provider configurations for custom fallback
|
|
80650
|
+
* @param {boolean} [options.fallback.stopOnSuccess=true] - Stop on first success
|
|
80651
|
+
* @param {number} [options.fallback.maxTotalAttempts=10] - Maximum total attempts across all providers
|
|
79302
80652
|
*/
|
|
79303
80653
|
constructor(options = {}) {
|
|
79304
80654
|
this.sessionId = options.sessionId || (0, import_crypto4.randomUUID)();
|
|
@@ -79310,10 +80660,18 @@ var init_ProbeAgent = __esm({
|
|
|
79310
80660
|
this.cancelled = false;
|
|
79311
80661
|
this.tracer = options.tracer || null;
|
|
79312
80662
|
this.outline = !!options.outline;
|
|
79313
|
-
this.maxResponseTokens = options.maxResponseTokens ||
|
|
80663
|
+
this.maxResponseTokens = options.maxResponseTokens || (() => {
|
|
80664
|
+
const val = parseInt(process.env.MAX_RESPONSE_TOKENS || "0", 10);
|
|
80665
|
+
if (isNaN(val) || val < 0 || val > 2e5) {
|
|
80666
|
+
return null;
|
|
80667
|
+
}
|
|
80668
|
+
return val || null;
|
|
80669
|
+
})();
|
|
79314
80670
|
this.maxIterations = options.maxIterations || null;
|
|
79315
80671
|
this.disableMermaidValidation = !!options.disableMermaidValidation;
|
|
79316
80672
|
this.disableJsonValidation = !!options.disableJsonValidation;
|
|
80673
|
+
const effectiveAllowedTools = options.disableTools ? [] : options.allowedTools;
|
|
80674
|
+
this.allowedTools = this._parseAllowedTools(effectiveAllowedTools);
|
|
79317
80675
|
this.storageAdapter = options.storageAdapter || new InMemoryStorageAdapter();
|
|
79318
80676
|
this.hooks = new HookManager();
|
|
79319
80677
|
if (options.hooks) {
|
|
@@ -79351,8 +80709,67 @@ var init_ProbeAgent = __esm({
|
|
|
79351
80709
|
this.mcpServers = options.mcpServers || null;
|
|
79352
80710
|
this.mcpBridge = null;
|
|
79353
80711
|
this._mcpInitialized = false;
|
|
80712
|
+
this.retryConfig = options.retry || {};
|
|
80713
|
+
this.retryManager = null;
|
|
80714
|
+
this.fallbackConfig = options.fallback || null;
|
|
80715
|
+
this.fallbackManager = null;
|
|
79354
80716
|
this.initializeModel();
|
|
79355
80717
|
}
|
|
80718
|
+
/**
|
|
80719
|
+
* Parse allowedTools configuration
|
|
80720
|
+
* @param {Array<string>|null|undefined} allowedTools - Tool filtering configuration
|
|
80721
|
+
* @returns {Object} Parsed configuration with isEnabled method
|
|
80722
|
+
* @private
|
|
80723
|
+
*/
|
|
80724
|
+
_parseAllowedTools(allowedTools) {
|
|
80725
|
+
const matchesPattern2 = (toolName, pattern) => {
|
|
80726
|
+
if (!pattern.includes("*")) {
|
|
80727
|
+
return toolName === pattern;
|
|
80728
|
+
}
|
|
80729
|
+
const regexPattern = pattern.replace(/\*/g, ".*");
|
|
80730
|
+
return new RegExp(`^${regexPattern}$`).test(toolName);
|
|
80731
|
+
};
|
|
80732
|
+
if (!allowedTools || Array.isArray(allowedTools) && allowedTools.includes("*")) {
|
|
80733
|
+
const exclusions = Array.isArray(allowedTools) ? allowedTools.filter((t3) => t3.startsWith("!")).map((t3) => t3.slice(1)) : [];
|
|
80734
|
+
return {
|
|
80735
|
+
mode: "all",
|
|
80736
|
+
exclusions,
|
|
80737
|
+
isEnabled: (toolName) => !exclusions.some((pattern) => matchesPattern2(toolName, pattern))
|
|
80738
|
+
};
|
|
80739
|
+
}
|
|
80740
|
+
if (Array.isArray(allowedTools) && allowedTools.length === 0) {
|
|
80741
|
+
return {
|
|
80742
|
+
mode: "none",
|
|
80743
|
+
isEnabled: () => false
|
|
80744
|
+
};
|
|
80745
|
+
}
|
|
80746
|
+
const allowedPatterns = allowedTools.filter((t3) => !t3.startsWith("!"));
|
|
80747
|
+
return {
|
|
80748
|
+
mode: "whitelist",
|
|
80749
|
+
allowed: allowedPatterns,
|
|
80750
|
+
isEnabled: (toolName) => allowedPatterns.some((pattern) => matchesPattern2(toolName, pattern))
|
|
80751
|
+
};
|
|
80752
|
+
}
|
|
80753
|
+
/**
|
|
80754
|
+
* Check if an MCP tool is allowed based on allowedTools configuration
|
|
80755
|
+
* Uses mcp__ prefix convention (like Claude Code)
|
|
80756
|
+
* @param {string} toolName - The MCP tool name (without mcp__ prefix)
|
|
80757
|
+
* @returns {boolean} - Whether the tool is allowed
|
|
80758
|
+
* @private
|
|
80759
|
+
*/
|
|
80760
|
+
_isMcpToolAllowed(toolName) {
|
|
80761
|
+
const mcpToolName = `mcp__${toolName}`;
|
|
80762
|
+
return this.allowedTools.isEnabled(mcpToolName) || this.allowedTools.isEnabled(toolName);
|
|
80763
|
+
}
|
|
80764
|
+
/**
|
|
80765
|
+
* Filter MCP tools based on allowedTools configuration
|
|
80766
|
+
* @param {string[]} mcpToolNames - Array of MCP tool names
|
|
80767
|
+
* @returns {string[]} - Filtered array of allowed MCP tool names
|
|
80768
|
+
* @private
|
|
80769
|
+
*/
|
|
80770
|
+
_filterMcpTools(mcpToolNames) {
|
|
80771
|
+
return mcpToolNames.filter((toolName) => this._isMcpToolAllowed(toolName));
|
|
80772
|
+
}
|
|
79356
80773
|
/**
|
|
79357
80774
|
* Initialize the agent asynchronously (must be called after constructor)
|
|
79358
80775
|
* This method initializes MCP and merges MCP tools into the tool list, and loads history from storage
|
|
@@ -79379,7 +80796,11 @@ var init_ProbeAgent = __esm({
|
|
|
79379
80796
|
if (this.mcpBridge) {
|
|
79380
80797
|
const mcpTools = this.mcpBridge.mcpTools || {};
|
|
79381
80798
|
for (const [toolName, toolImpl] of Object.entries(mcpTools)) {
|
|
79382
|
-
this.
|
|
80799
|
+
if (this._isMcpToolAllowed(toolName)) {
|
|
80800
|
+
this.toolImplementations[toolName] = toolImpl;
|
|
80801
|
+
} else if (this.debug) {
|
|
80802
|
+
console.error(`[DEBUG] MCP tool '${toolName}' filtered out by allowedTools`);
|
|
80803
|
+
}
|
|
79383
80804
|
}
|
|
79384
80805
|
}
|
|
79385
80806
|
if (this.debug) {
|
|
@@ -79435,6 +80856,14 @@ var init_ProbeAgent = __esm({
|
|
|
79435
80856
|
if (this.enableBash && wrappedTools.bashToolInstance) {
|
|
79436
80857
|
this.toolImplementations.bash = wrappedTools.bashToolInstance;
|
|
79437
80858
|
}
|
|
80859
|
+
if (this.allowEdit) {
|
|
80860
|
+
if (wrappedTools.editToolInstance) {
|
|
80861
|
+
this.toolImplementations.edit = wrappedTools.editToolInstance;
|
|
80862
|
+
}
|
|
80863
|
+
if (wrappedTools.createToolInstance) {
|
|
80864
|
+
this.toolImplementations.create = wrappedTools.createToolInstance;
|
|
80865
|
+
}
|
|
80866
|
+
}
|
|
79438
80867
|
this.wrappedTools = wrappedTools;
|
|
79439
80868
|
if (this.debug) {
|
|
79440
80869
|
console.error("\n[DEBUG] ========================================");
|
|
@@ -79485,36 +80914,147 @@ var init_ProbeAgent = __esm({
|
|
|
79485
80914
|
if (forceProvider) {
|
|
79486
80915
|
if (forceProvider === "anthropic" && anthropicApiKey) {
|
|
79487
80916
|
this.initializeAnthropicModel(anthropicApiKey, anthropicApiUrl, modelName);
|
|
80917
|
+
this.initializeFallbackManager(forceProvider, modelName);
|
|
79488
80918
|
return;
|
|
79489
80919
|
} else if (forceProvider === "openai" && openaiApiKey) {
|
|
79490
80920
|
this.initializeOpenAIModel(openaiApiKey, openaiApiUrl, modelName);
|
|
80921
|
+
this.initializeFallbackManager(forceProvider, modelName);
|
|
79491
80922
|
return;
|
|
79492
80923
|
} else if (forceProvider === "google" && googleApiKey) {
|
|
79493
80924
|
this.initializeGoogleModel(googleApiKey, googleApiUrl, modelName);
|
|
80925
|
+
this.initializeFallbackManager(forceProvider, modelName);
|
|
79494
80926
|
return;
|
|
79495
80927
|
} else if (forceProvider === "bedrock" && (awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey)) {
|
|
79496
80928
|
this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
|
|
80929
|
+
this.initializeFallbackManager(forceProvider, modelName);
|
|
79497
80930
|
return;
|
|
79498
80931
|
}
|
|
79499
80932
|
console.warn(`WARNING: Forced provider "${forceProvider}" selected but required API key is missing or invalid! Falling back to auto-detection.`);
|
|
79500
80933
|
}
|
|
79501
80934
|
if (anthropicApiKey) {
|
|
79502
80935
|
this.initializeAnthropicModel(anthropicApiKey, anthropicApiUrl, modelName);
|
|
80936
|
+
this.initializeFallbackManager("anthropic", modelName);
|
|
79503
80937
|
} else if (openaiApiKey) {
|
|
79504
80938
|
this.initializeOpenAIModel(openaiApiKey, openaiApiUrl, modelName);
|
|
80939
|
+
this.initializeFallbackManager("openai", modelName);
|
|
79505
80940
|
} else if (googleApiKey) {
|
|
79506
80941
|
this.initializeGoogleModel(googleApiKey, googleApiUrl, modelName);
|
|
80942
|
+
this.initializeFallbackManager("google", modelName);
|
|
79507
80943
|
} else if (awsAccessKeyId && awsSecretAccessKey && awsRegion || awsApiKey) {
|
|
79508
80944
|
this.initializeBedrockModel(awsAccessKeyId, awsSecretAccessKey, awsRegion, awsSessionToken, awsApiKey, awsBedrockBaseUrl, modelName);
|
|
80945
|
+
this.initializeFallbackManager("bedrock", modelName);
|
|
79509
80946
|
} else {
|
|
79510
80947
|
throw new Error("No API key provided. Please set ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN), OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY (or GOOGLE_API_KEY), AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION), or AWS_BEDROCK_API_KEY environment variables.");
|
|
79511
80948
|
}
|
|
79512
80949
|
}
|
|
80950
|
+
/**
|
|
80951
|
+
* Initialize fallback manager based on configuration
|
|
80952
|
+
* @param {string} primaryProvider - The primary provider being used
|
|
80953
|
+
* @param {string} primaryModel - The primary model being used
|
|
80954
|
+
* @private
|
|
80955
|
+
*/
|
|
80956
|
+
initializeFallbackManager(primaryProvider, primaryModel) {
|
|
80957
|
+
if (this.fallbackConfig === false || process.env.DISABLE_FALLBACK === "1") {
|
|
80958
|
+
return;
|
|
80959
|
+
}
|
|
80960
|
+
if (this.fallbackConfig && this.fallbackConfig.providers) {
|
|
80961
|
+
try {
|
|
80962
|
+
this.fallbackManager = new FallbackManager({
|
|
80963
|
+
...this.fallbackConfig,
|
|
80964
|
+
debug: this.debug
|
|
80965
|
+
});
|
|
80966
|
+
if (this.debug) {
|
|
80967
|
+
console.log(`[DEBUG] Fallback manager initialized with ${this.fallbackManager.providers.length} providers`);
|
|
80968
|
+
}
|
|
80969
|
+
} catch (error2) {
|
|
80970
|
+
console.error("[WARNING] Failed to initialize fallback manager:", error2.message);
|
|
80971
|
+
}
|
|
80972
|
+
return;
|
|
80973
|
+
}
|
|
80974
|
+
const envFallbackManager = createFallbackManagerFromEnv(this.debug);
|
|
80975
|
+
if (envFallbackManager) {
|
|
80976
|
+
this.fallbackManager = envFallbackManager;
|
|
80977
|
+
if (this.debug) {
|
|
80978
|
+
console.log(`[DEBUG] Fallback manager initialized from environment variables`);
|
|
80979
|
+
}
|
|
80980
|
+
return;
|
|
80981
|
+
}
|
|
80982
|
+
if (process.env.AUTO_FALLBACK === "1" || this.fallbackConfig?.auto) {
|
|
80983
|
+
const providers = buildFallbackProvidersFromEnv({
|
|
80984
|
+
primaryProvider,
|
|
80985
|
+
primaryModel
|
|
80986
|
+
});
|
|
80987
|
+
if (providers.length > 1) {
|
|
80988
|
+
try {
|
|
80989
|
+
this.fallbackManager = new FallbackManager({
|
|
80990
|
+
strategy: "custom",
|
|
80991
|
+
providers,
|
|
80992
|
+
debug: this.debug
|
|
80993
|
+
});
|
|
80994
|
+
if (this.debug) {
|
|
80995
|
+
console.log(`[DEBUG] Auto-fallback enabled with ${providers.length} providers`);
|
|
80996
|
+
}
|
|
80997
|
+
} catch (error2) {
|
|
80998
|
+
console.error("[WARNING] Failed to initialize auto-fallback:", error2.message);
|
|
80999
|
+
}
|
|
81000
|
+
}
|
|
81001
|
+
}
|
|
81002
|
+
}
|
|
81003
|
+
/**
|
|
81004
|
+
* Execute streamText with retry and fallback support
|
|
81005
|
+
* @param {Object} options - streamText options
|
|
81006
|
+
* @returns {Promise<Object>} - streamText result
|
|
81007
|
+
* @private
|
|
81008
|
+
*/
|
|
81009
|
+
async streamTextWithRetryAndFallback(options) {
|
|
81010
|
+
if (!this.retryManager) {
|
|
81011
|
+
this.retryManager = new RetryManager({
|
|
81012
|
+
maxRetries: this.retryConfig.maxRetries ?? 3,
|
|
81013
|
+
initialDelay: this.retryConfig.initialDelay ?? 1e3,
|
|
81014
|
+
maxDelay: this.retryConfig.maxDelay ?? 3e4,
|
|
81015
|
+
backoffFactor: this.retryConfig.backoffFactor ?? 2,
|
|
81016
|
+
retryableErrors: this.retryConfig.retryableErrors,
|
|
81017
|
+
debug: this.debug
|
|
81018
|
+
});
|
|
81019
|
+
}
|
|
81020
|
+
if (!this.fallbackManager) {
|
|
81021
|
+
return await this.retryManager.executeWithRetry(
|
|
81022
|
+
() => (0, import_ai.streamText)(options),
|
|
81023
|
+
{
|
|
81024
|
+
provider: this.apiType,
|
|
81025
|
+
model: this.model
|
|
81026
|
+
}
|
|
81027
|
+
);
|
|
81028
|
+
}
|
|
81029
|
+
return await this.fallbackManager.executeWithFallback(
|
|
81030
|
+
async (provider, model, config) => {
|
|
81031
|
+
const fallbackOptions = {
|
|
81032
|
+
...options,
|
|
81033
|
+
model: provider(model)
|
|
81034
|
+
};
|
|
81035
|
+
const providerRetryManager = new RetryManager({
|
|
81036
|
+
maxRetries: config.maxRetries ?? this.retryConfig.maxRetries ?? 3,
|
|
81037
|
+
initialDelay: this.retryConfig.initialDelay ?? 1e3,
|
|
81038
|
+
maxDelay: this.retryConfig.maxDelay ?? 3e4,
|
|
81039
|
+
backoffFactor: this.retryConfig.backoffFactor ?? 2,
|
|
81040
|
+
retryableErrors: this.retryConfig.retryableErrors,
|
|
81041
|
+
debug: this.debug
|
|
81042
|
+
});
|
|
81043
|
+
return await providerRetryManager.executeWithRetry(
|
|
81044
|
+
() => (0, import_ai.streamText)(fallbackOptions),
|
|
81045
|
+
{
|
|
81046
|
+
provider: config.provider,
|
|
81047
|
+
model
|
|
81048
|
+
}
|
|
81049
|
+
);
|
|
81050
|
+
}
|
|
81051
|
+
);
|
|
81052
|
+
}
|
|
79513
81053
|
/**
|
|
79514
81054
|
* Initialize Anthropic model
|
|
79515
81055
|
*/
|
|
79516
81056
|
initializeAnthropicModel(apiKey, apiUrl, modelName) {
|
|
79517
|
-
this.provider = (0,
|
|
81057
|
+
this.provider = (0, import_anthropic2.createAnthropic)({
|
|
79518
81058
|
apiKey,
|
|
79519
81059
|
...apiUrl && { baseURL: apiUrl }
|
|
79520
81060
|
});
|
|
@@ -79528,7 +81068,7 @@ var init_ProbeAgent = __esm({
|
|
|
79528
81068
|
* Initialize OpenAI model
|
|
79529
81069
|
*/
|
|
79530
81070
|
initializeOpenAIModel(apiKey, apiUrl, modelName) {
|
|
79531
|
-
this.provider = (0,
|
|
81071
|
+
this.provider = (0, import_openai2.createOpenAI)({
|
|
79532
81072
|
compatibility: "strict",
|
|
79533
81073
|
apiKey,
|
|
79534
81074
|
...apiUrl && { baseURL: apiUrl }
|
|
@@ -79543,7 +81083,7 @@ var init_ProbeAgent = __esm({
|
|
|
79543
81083
|
* Initialize Google model
|
|
79544
81084
|
*/
|
|
79545
81085
|
initializeGoogleModel(apiKey, apiUrl, modelName) {
|
|
79546
|
-
this.provider = (0,
|
|
81086
|
+
this.provider = (0, import_google2.createGoogleGenerativeAI)({
|
|
79547
81087
|
apiKey,
|
|
79548
81088
|
...apiUrl && { baseURL: apiUrl }
|
|
79549
81089
|
});
|
|
@@ -79687,21 +81227,21 @@ var init_ProbeAgent = __esm({
|
|
|
79687
81227
|
}
|
|
79688
81228
|
const allowedDirs = this.allowedFolders && this.allowedFolders.length > 0 ? this.allowedFolders : [process.cwd()];
|
|
79689
81229
|
let absolutePath;
|
|
79690
|
-
let
|
|
81230
|
+
let isPathAllowed2 = false;
|
|
79691
81231
|
if ((0, import_path6.isAbsolute)(imagePath)) {
|
|
79692
81232
|
absolutePath = imagePath;
|
|
79693
|
-
|
|
81233
|
+
isPathAllowed2 = allowedDirs.some((dir) => absolutePath.startsWith((0, import_path6.resolve)(dir)));
|
|
79694
81234
|
} else {
|
|
79695
81235
|
for (const dir of allowedDirs) {
|
|
79696
81236
|
const resolvedPath2 = (0, import_path6.resolve)(dir, imagePath);
|
|
79697
81237
|
if (resolvedPath2.startsWith((0, import_path6.resolve)(dir))) {
|
|
79698
81238
|
absolutePath = resolvedPath2;
|
|
79699
|
-
|
|
81239
|
+
isPathAllowed2 = true;
|
|
79700
81240
|
break;
|
|
79701
81241
|
}
|
|
79702
81242
|
}
|
|
79703
81243
|
}
|
|
79704
|
-
if (!
|
|
81244
|
+
if (!isPathAllowed2) {
|
|
79705
81245
|
if (this.debug) {
|
|
79706
81246
|
console.log(`[DEBUG] Image path outside allowed directories: ${imagePath}`);
|
|
79707
81247
|
}
|
|
@@ -79880,7 +81420,11 @@ var init_ProbeAgent = __esm({
|
|
|
79880
81420
|
if (this.mcpBridge) {
|
|
79881
81421
|
const mcpTools = this.mcpBridge.mcpTools || {};
|
|
79882
81422
|
for (const [toolName, toolImpl] of Object.entries(mcpTools)) {
|
|
79883
|
-
this.
|
|
81423
|
+
if (this._isMcpToolAllowed(toolName)) {
|
|
81424
|
+
this.toolImplementations[toolName] = toolImpl;
|
|
81425
|
+
} else if (this.debug) {
|
|
81426
|
+
console.error(`[DEBUG] MCP tool '${toolName}' filtered out by allowedTools`);
|
|
81427
|
+
}
|
|
79884
81428
|
}
|
|
79885
81429
|
}
|
|
79886
81430
|
} catch (error2) {
|
|
@@ -79890,19 +81434,49 @@ var init_ProbeAgent = __esm({
|
|
|
79890
81434
|
}
|
|
79891
81435
|
}
|
|
79892
81436
|
}
|
|
79893
|
-
let toolDefinitions =
|
|
79894
|
-
|
|
79895
|
-
|
|
79896
|
-
|
|
79897
|
-
${listFilesToolDefinition}
|
|
79898
|
-
${searchFilesToolDefinition}
|
|
79899
|
-
${attemptCompletionToolDefinition}
|
|
81437
|
+
let toolDefinitions = "";
|
|
81438
|
+
const isToolAllowed = (toolName) => this.allowedTools.isEnabled(toolName);
|
|
81439
|
+
if (isToolAllowed("search")) {
|
|
81440
|
+
toolDefinitions += `${searchToolDefinition}
|
|
79900
81441
|
`;
|
|
79901
|
-
|
|
81442
|
+
}
|
|
81443
|
+
if (isToolAllowed("query")) {
|
|
81444
|
+
toolDefinitions += `${queryToolDefinition}
|
|
81445
|
+
`;
|
|
81446
|
+
}
|
|
81447
|
+
if (isToolAllowed("extract")) {
|
|
81448
|
+
toolDefinitions += `${extractToolDefinition}
|
|
81449
|
+
`;
|
|
81450
|
+
}
|
|
81451
|
+
if (isToolAllowed("listFiles")) {
|
|
81452
|
+
toolDefinitions += `${listFilesToolDefinition}
|
|
81453
|
+
`;
|
|
81454
|
+
}
|
|
81455
|
+
if (isToolAllowed("searchFiles")) {
|
|
81456
|
+
toolDefinitions += `${searchFilesToolDefinition}
|
|
81457
|
+
`;
|
|
81458
|
+
}
|
|
81459
|
+
if (this.allowEdit && isToolAllowed("implement")) {
|
|
79902
81460
|
toolDefinitions += `${implementToolDefinition}
|
|
79903
81461
|
`;
|
|
79904
81462
|
}
|
|
79905
|
-
if (this.
|
|
81463
|
+
if (this.allowEdit && isToolAllowed("edit")) {
|
|
81464
|
+
toolDefinitions += `${editToolDefinition}
|
|
81465
|
+
`;
|
|
81466
|
+
}
|
|
81467
|
+
if (this.allowEdit && isToolAllowed("create")) {
|
|
81468
|
+
toolDefinitions += `${createToolDefinition}
|
|
81469
|
+
`;
|
|
81470
|
+
}
|
|
81471
|
+
if (this.enableBash && isToolAllowed("bash")) {
|
|
81472
|
+
toolDefinitions += `${bashToolDefinition}
|
|
81473
|
+
`;
|
|
81474
|
+
}
|
|
81475
|
+
if (isToolAllowed("attempt_completion")) {
|
|
81476
|
+
toolDefinitions += `${attemptCompletionToolDefinition}
|
|
81477
|
+
`;
|
|
81478
|
+
}
|
|
81479
|
+
if (this.enableDelegate && isToolAllowed("delegate")) {
|
|
79906
81480
|
toolDefinitions += `${delegateToolDefinition}
|
|
79907
81481
|
`;
|
|
79908
81482
|
}
|
|
@@ -79967,7 +81541,7 @@ Available Tools:
|
|
|
79967
81541
|
- extract: Extract specific code blocks or lines from files.
|
|
79968
81542
|
- listFiles: List files and directories in a specified location.
|
|
79969
81543
|
- searchFiles: Find files matching a glob pattern with recursive search capability.
|
|
79970
|
-
${this.allowEdit ? "- implement: Implement a feature or fix a bug using aider.\n" : ""}${this.enableDelegate ? "- delegate: Delegate big distinct tasks to specialized probe subagents.\n" : ""}
|
|
81544
|
+
${this.allowEdit ? "- implement: Implement a feature or fix a bug using aider.\n- edit: Edit files using exact string replacement.\n- create: Create new files with specified content.\n" : ""}${this.enableDelegate ? "- delegate: Delegate big distinct tasks to specialized probe subagents.\n" : ""}${this.enableBash ? "- bash: Execute bash commands for system operations.\n" : ""}
|
|
79971
81545
|
- attempt_completion: Finalize the task and provide the result to the user.
|
|
79972
81546
|
- attempt_complete: Quick completion using previous response (shorthand).
|
|
79973
81547
|
`;
|
|
@@ -79981,7 +81555,10 @@ Follow these instructions carefully:
|
|
|
79981
81555
|
6. You MUST respond with exactly ONE tool call per message, using the specified XML format, until the task is complete.
|
|
79982
81556
|
7. Wait for the tool execution result (provided in the next user message in a <tool_result> block) before proceeding to the next step.
|
|
79983
81557
|
8. Once the task is fully completed, use the '<attempt_completion>' tool to provide the final result. This is the ONLY way to signal completion.
|
|
79984
|
-
9. Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.
|
|
81558
|
+
9. Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.${this.allowEdit ? `
|
|
81559
|
+
10. When modifying files, choose the appropriate tool:
|
|
81560
|
+
- Use 'edit' for precise changes to existing files (requires exact string match)
|
|
81561
|
+
- Use 'create' for new files or complete file rewrites` : ""}
|
|
79985
81562
|
</instructions>
|
|
79986
81563
|
`;
|
|
79987
81564
|
const predefinedPrompts = {
|
|
@@ -80061,11 +81638,14 @@ ${xmlToolGuidelines}
|
|
|
80061
81638
|
${toolDefinitions}
|
|
80062
81639
|
`;
|
|
80063
81640
|
if (this.mcpBridge && this.mcpBridge.getToolNames().length > 0) {
|
|
80064
|
-
|
|
81641
|
+
const allMcpTools = this.mcpBridge.getToolNames();
|
|
81642
|
+
const allowedMcpTools = this._filterMcpTools(allMcpTools);
|
|
81643
|
+
if (allowedMcpTools.length > 0) {
|
|
81644
|
+
systemMessage += `
|
|
80065
81645
|
## MCP Tools (JSON parameters in <params> tag)
|
|
80066
81646
|
`;
|
|
80067
|
-
|
|
80068
|
-
|
|
81647
|
+
systemMessage += this.mcpBridge.getXmlToolDefinitions(allowedMcpTools);
|
|
81648
|
+
systemMessage += `
|
|
80069
81649
|
|
|
80070
81650
|
For MCP tools, use JSON format within the params tag, e.g.:
|
|
80071
81651
|
<mcp_tool>
|
|
@@ -80074,6 +81654,7 @@ For MCP tools, use JSON format within the params tag, e.g.:
|
|
|
80074
81654
|
</params>
|
|
80075
81655
|
</mcp_tool>
|
|
80076
81656
|
`;
|
|
81657
|
+
}
|
|
80077
81658
|
}
|
|
80078
81659
|
const searchDirectory = this.allowedFolders.length > 0 ? this.allowedFolders[0] : process.cwd();
|
|
80079
81660
|
if (this.debug) {
|
|
@@ -80230,44 +81811,83 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
80230
81811
|
}
|
|
80231
81812
|
}
|
|
80232
81813
|
let assistantResponseContent = "";
|
|
80233
|
-
|
|
80234
|
-
|
|
80235
|
-
|
|
80236
|
-
const
|
|
80237
|
-
|
|
80238
|
-
|
|
80239
|
-
|
|
80240
|
-
|
|
80241
|
-
|
|
80242
|
-
|
|
80243
|
-
|
|
80244
|
-
|
|
80245
|
-
|
|
80246
|
-
|
|
81814
|
+
let compactionAttempted = false;
|
|
81815
|
+
while (true) {
|
|
81816
|
+
try {
|
|
81817
|
+
const executeAIRequest = async () => {
|
|
81818
|
+
const messagesForAI = this.prepareMessagesWithImages(currentMessages);
|
|
81819
|
+
const result = await this.streamTextWithRetryAndFallback({
|
|
81820
|
+
model: this.provider(this.model),
|
|
81821
|
+
messages: messagesForAI,
|
|
81822
|
+
maxTokens: maxResponseTokens,
|
|
81823
|
+
temperature: 0.3
|
|
81824
|
+
});
|
|
81825
|
+
const usagePromise = result.usage;
|
|
81826
|
+
for await (const delta of result.textStream) {
|
|
81827
|
+
assistantResponseContent += delta;
|
|
81828
|
+
if (options.onStream) {
|
|
81829
|
+
options.onStream(delta);
|
|
81830
|
+
}
|
|
81831
|
+
}
|
|
81832
|
+
const usage = await usagePromise;
|
|
81833
|
+
if (usage) {
|
|
81834
|
+
this.tokenCounter.recordUsage(usage, result.experimental_providerMetadata);
|
|
80247
81835
|
}
|
|
81836
|
+
return result;
|
|
81837
|
+
};
|
|
81838
|
+
if (this.tracer) {
|
|
81839
|
+
await this.tracer.withSpan("ai.request", executeAIRequest, {
|
|
81840
|
+
"ai.model": this.model,
|
|
81841
|
+
"ai.provider": this.clientApiProvider || "auto",
|
|
81842
|
+
"iteration": currentIteration,
|
|
81843
|
+
"max_tokens": maxResponseTokens,
|
|
81844
|
+
"temperature": 0.3,
|
|
81845
|
+
"message_count": currentMessages.length
|
|
81846
|
+
});
|
|
81847
|
+
} else {
|
|
81848
|
+
await executeAIRequest();
|
|
80248
81849
|
}
|
|
80249
|
-
|
|
80250
|
-
|
|
80251
|
-
|
|
81850
|
+
break;
|
|
81851
|
+
} catch (error2) {
|
|
81852
|
+
if (!compactionAttempted && handleContextLimitError) {
|
|
81853
|
+
const compactionResult = handleContextLimitError(error2, currentMessages, {
|
|
81854
|
+
keepLastSegment: true,
|
|
81855
|
+
minSegmentsToKeep: 1
|
|
81856
|
+
});
|
|
81857
|
+
if (compactionResult) {
|
|
81858
|
+
const { messages: compactedMessages, stats } = compactionResult;
|
|
81859
|
+
if (stats.removed === 0) {
|
|
81860
|
+
console.error(`[ERROR] Context window exceeded but no messages can be compacted.`);
|
|
81861
|
+
console.error(`[ERROR] The conversation history is already minimal (${stats.originalCount} messages).`);
|
|
81862
|
+
finalResult = `Error: Context window limit exceeded and conversation cannot be compacted further. Consider starting a new session or reducing system message size.`;
|
|
81863
|
+
throw new Error(finalResult);
|
|
81864
|
+
}
|
|
81865
|
+
compactionAttempted = true;
|
|
81866
|
+
console.log(`[INFO] Context window limit exceeded. Compacting conversation...`);
|
|
81867
|
+
console.log(`[INFO] Removed ${stats.removed} messages (${stats.reductionPercent}% reduction)`);
|
|
81868
|
+
console.log(`[INFO] Estimated token savings: ${stats.tokensSaved} tokens`);
|
|
81869
|
+
if (this.debug) {
|
|
81870
|
+
console.log(`[DEBUG] Compaction stats:`, stats);
|
|
81871
|
+
console.log(`[DEBUG] Original message count: ${stats.originalCount}`);
|
|
81872
|
+
console.log(`[DEBUG] Compacted message count: ${stats.compactedCount}`);
|
|
81873
|
+
}
|
|
81874
|
+
currentMessages = [...compactedMessages];
|
|
81875
|
+
if (this.tracer) {
|
|
81876
|
+
this.tracer.addEvent("context.compacted", {
|
|
81877
|
+
"iteration": currentIteration,
|
|
81878
|
+
"original_count": stats.originalCount,
|
|
81879
|
+
"compacted_count": stats.compactedCount,
|
|
81880
|
+
"reduction_percent": stats.reductionPercent,
|
|
81881
|
+
"tokens_saved": stats.tokensSaved
|
|
81882
|
+
});
|
|
81883
|
+
}
|
|
81884
|
+
continue;
|
|
81885
|
+
}
|
|
80252
81886
|
}
|
|
80253
|
-
|
|
80254
|
-
|
|
80255
|
-
|
|
80256
|
-
await this.tracer.withSpan("ai.request", executeAIRequest, {
|
|
80257
|
-
"ai.model": this.model,
|
|
80258
|
-
"ai.provider": this.clientApiProvider || "auto",
|
|
80259
|
-
"iteration": currentIteration,
|
|
80260
|
-
"max_tokens": maxResponseTokens,
|
|
80261
|
-
"temperature": 0.3,
|
|
80262
|
-
"message_count": currentMessages.length
|
|
80263
|
-
});
|
|
80264
|
-
} else {
|
|
80265
|
-
await executeAIRequest();
|
|
81887
|
+
console.error(`Error during streamText (Iter ${currentIteration}):`, error2);
|
|
81888
|
+
finalResult = `Error: Failed to get response from AI model during iteration ${currentIteration}. ${error2.message}`;
|
|
81889
|
+
throw new Error(finalResult);
|
|
80266
81890
|
}
|
|
80267
|
-
} catch (error2) {
|
|
80268
|
-
console.error(`Error during streamText (Iter ${currentIteration}):`, error2);
|
|
80269
|
-
finalResult = `Error: Failed to get response from AI model during iteration ${currentIteration}. ${error2.message}`;
|
|
80270
|
-
throw new Error(finalResult);
|
|
80271
81891
|
}
|
|
80272
81892
|
if (this.debug && assistantResponseContent) {
|
|
80273
81893
|
const assistantPreview = createMessagePreview(assistantResponseContent);
|
|
@@ -80285,7 +81905,10 @@ You are working with a repository located at: ${searchDirectory}
|
|
|
80285
81905
|
"attempt_completion"
|
|
80286
81906
|
];
|
|
80287
81907
|
if (this.allowEdit) {
|
|
80288
|
-
validTools.push("implement");
|
|
81908
|
+
validTools.push("implement", "edit", "create");
|
|
81909
|
+
}
|
|
81910
|
+
if (this.enableBash) {
|
|
81911
|
+
validTools.push("bash");
|
|
80289
81912
|
}
|
|
80290
81913
|
if (this.enableDelegate) {
|
|
80291
81914
|
validTools.push("delegate");
|
|
@@ -80629,7 +82252,6 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
80629
82252
|
...options,
|
|
80630
82253
|
_schemaFormatted: true
|
|
80631
82254
|
});
|
|
80632
|
-
finalResult = cleanSchemaResponse(finalResult);
|
|
80633
82255
|
if (!this.disableMermaidValidation) {
|
|
80634
82256
|
try {
|
|
80635
82257
|
if (this.debug) {
|
|
@@ -80685,14 +82307,11 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
80685
82307
|
} else if (this.debug) {
|
|
80686
82308
|
console.log(`[DEBUG] Mermaid validation: Skipped due to disableMermaidValidation option`);
|
|
80687
82309
|
}
|
|
82310
|
+
finalResult = cleanSchemaResponse(finalResult);
|
|
80688
82311
|
if (isJsonSchema(options.schema)) {
|
|
80689
82312
|
if (this.debug) {
|
|
80690
82313
|
console.log(`[DEBUG] JSON validation: Starting validation process for schema response`);
|
|
80691
|
-
console.log(`[DEBUG] JSON validation:
|
|
80692
|
-
}
|
|
80693
|
-
finalResult = cleanSchemaResponse(finalResult);
|
|
80694
|
-
if (this.debug) {
|
|
80695
|
-
console.log(`[DEBUG] JSON validation: After cleaning, length: ${finalResult.length} chars`);
|
|
82314
|
+
console.log(`[DEBUG] JSON validation: Cleaned response length: ${finalResult.length} chars`);
|
|
80696
82315
|
}
|
|
80697
82316
|
if (this.tracer) {
|
|
80698
82317
|
this.tracer.recordJsonValidationEvent("started", {
|
|
@@ -80782,10 +82401,9 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
80782
82401
|
console.log("[DEBUG] Skipping schema formatting due to max iterations reached without completion");
|
|
80783
82402
|
} else if (completionAttempted && options.schema && !options._schemaFormatted && !options._skipValidation) {
|
|
80784
82403
|
try {
|
|
80785
|
-
finalResult = cleanSchemaResponse(finalResult);
|
|
80786
82404
|
if (!this.disableMermaidValidation) {
|
|
80787
82405
|
if (this.debug) {
|
|
80788
|
-
console.log(`[DEBUG] Mermaid validation: Validating attempt_completion result...`);
|
|
82406
|
+
console.log(`[DEBUG] Mermaid validation: Validating attempt_completion result BEFORE schema cleaning...`);
|
|
80789
82407
|
}
|
|
80790
82408
|
const mermaidValidation = await validateAndFixMermaidResponse(finalResult, {
|
|
80791
82409
|
debug: this.debug,
|
|
@@ -80808,6 +82426,7 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
80808
82426
|
} else if (this.debug) {
|
|
80809
82427
|
console.log(`[DEBUG] Mermaid validation: Skipped for attempt_completion result due to disableMermaidValidation option`);
|
|
80810
82428
|
}
|
|
82429
|
+
finalResult = cleanSchemaResponse(finalResult);
|
|
80811
82430
|
if (isJsonSchema(options.schema)) {
|
|
80812
82431
|
if (this.debug) {
|
|
80813
82432
|
console.log(`[DEBUG] JSON validation: Starting validation process for attempt_completion result`);
|
|
@@ -80981,6 +82600,56 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
80981
82600
|
console.log(`[DEBUG] Cleared conversation history and reset counters for session ${this.sessionId}`);
|
|
80982
82601
|
}
|
|
80983
82602
|
}
|
|
82603
|
+
/**
|
|
82604
|
+
* Manually compact conversation history
|
|
82605
|
+
* Removes intermediate monologues from older segments while preserving
|
|
82606
|
+
* user messages, final answers, and the most recent segment
|
|
82607
|
+
*
|
|
82608
|
+
* @param {Object} options - Compaction options
|
|
82609
|
+
* @param {boolean} [options.keepLastSegment=true] - Keep the most recent segment intact
|
|
82610
|
+
* @param {number} [options.minSegmentsToKeep=1] - Number of recent segments to preserve fully
|
|
82611
|
+
* @returns {Object} Compaction statistics
|
|
82612
|
+
*/
|
|
82613
|
+
async compactHistory(options = {}) {
|
|
82614
|
+
const { compactMessages: compactMessages2, calculateCompactionStats: calculateCompactionStats2 } = await Promise.resolve().then(() => (init_contextCompactor(), contextCompactor_exports));
|
|
82615
|
+
if (this.history.length === 0) {
|
|
82616
|
+
if (this.debug) {
|
|
82617
|
+
console.log(`[DEBUG] No history to compact for session ${this.sessionId}`);
|
|
82618
|
+
}
|
|
82619
|
+
return {
|
|
82620
|
+
originalCount: 0,
|
|
82621
|
+
compactedCount: 0,
|
|
82622
|
+
removed: 0,
|
|
82623
|
+
reductionPercent: 0,
|
|
82624
|
+
originalTokens: 0,
|
|
82625
|
+
compactedTokens: 0,
|
|
82626
|
+
tokensSaved: 0
|
|
82627
|
+
};
|
|
82628
|
+
}
|
|
82629
|
+
const compactedMessages = compactMessages2(this.history, options);
|
|
82630
|
+
const stats = calculateCompactionStats2(this.history, compactedMessages);
|
|
82631
|
+
this.history = compactedMessages;
|
|
82632
|
+
try {
|
|
82633
|
+
await this.storageAdapter.clearHistory(this.sessionId);
|
|
82634
|
+
for (const message of compactedMessages) {
|
|
82635
|
+
await this.storageAdapter.saveMessage(this.sessionId, message);
|
|
82636
|
+
}
|
|
82637
|
+
} catch (error2) {
|
|
82638
|
+
console.error(`[ERROR] Failed to save compacted messages to storage:`, error2);
|
|
82639
|
+
}
|
|
82640
|
+
console.log(`[INFO] Manually compacted conversation history`);
|
|
82641
|
+
console.log(`[INFO] Removed ${stats.removed} messages (${stats.reductionPercent}% reduction)`);
|
|
82642
|
+
console.log(`[INFO] Estimated token savings: ${stats.tokensSaved} tokens`);
|
|
82643
|
+
if (this.debug) {
|
|
82644
|
+
console.log(`[DEBUG] Compaction stats:`, stats);
|
|
82645
|
+
}
|
|
82646
|
+
await this.hooks.emit(HOOK_TYPES.STORAGE_SAVE, {
|
|
82647
|
+
sessionId: this.sessionId,
|
|
82648
|
+
compacted: true,
|
|
82649
|
+
stats
|
|
82650
|
+
});
|
|
82651
|
+
return stats;
|
|
82652
|
+
}
|
|
80984
82653
|
/**
|
|
80985
82654
|
* Clone this agent's session to create a new agent with shared conversation history
|
|
80986
82655
|
* @param {Object} options - Clone options
|
|
@@ -81003,6 +82672,14 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
81003
82672
|
if (stripInternalMessages) {
|
|
81004
82673
|
clonedHistory = this._stripInternalMessages(clonedHistory, keepSystemMessage);
|
|
81005
82674
|
}
|
|
82675
|
+
let allowedToolsArray = null;
|
|
82676
|
+
if (this.allowedTools.mode === "whitelist") {
|
|
82677
|
+
allowedToolsArray = [...this.allowedTools.allowed];
|
|
82678
|
+
} else if (this.allowedTools.mode === "none") {
|
|
82679
|
+
allowedToolsArray = [];
|
|
82680
|
+
} else if (this.allowedTools.mode === "all" && this.allowedTools.exclusions.length > 0) {
|
|
82681
|
+
allowedToolsArray = ["*", ...this.allowedTools.exclusions.map((t3) => "!" + t3)];
|
|
82682
|
+
}
|
|
81006
82683
|
const clonedAgent = new _ProbeAgent({
|
|
81007
82684
|
// Copy current agent's config
|
|
81008
82685
|
customPrompt: this.customPrompt,
|
|
@@ -81020,6 +82697,7 @@ Convert your previous response content into actual JSON data that follows this s
|
|
|
81020
82697
|
maxIterations: this.maxIterations,
|
|
81021
82698
|
disableMermaidValidation: this.disableMermaidValidation,
|
|
81022
82699
|
disableJsonValidation: this.disableJsonValidation,
|
|
82700
|
+
allowedTools: allowedToolsArray,
|
|
81023
82701
|
enableMcp: !!this.mcpBridge,
|
|
81024
82702
|
mcpConfig: this.mcpConfig,
|
|
81025
82703
|
enableBash: this.enableBash,
|
|
@@ -82519,14 +84197,14 @@ async function executeBashCommand(command, options = {}) {
|
|
|
82519
84197
|
console.log(`[BashExecutor] Working directory: "${cwd}"`);
|
|
82520
84198
|
console.log(`[BashExecutor] Timeout: ${timeout}ms`);
|
|
82521
84199
|
}
|
|
82522
|
-
return new Promise((
|
|
84200
|
+
return new Promise((resolve5, reject2) => {
|
|
82523
84201
|
const processEnv = {
|
|
82524
84202
|
...process.env,
|
|
82525
84203
|
...env
|
|
82526
84204
|
};
|
|
82527
84205
|
const args = parseCommandForExecution(command);
|
|
82528
84206
|
if (!args || args.length === 0) {
|
|
82529
|
-
|
|
84207
|
+
resolve5({
|
|
82530
84208
|
success: false,
|
|
82531
84209
|
error: "Failed to parse command",
|
|
82532
84210
|
stdout: "",
|
|
@@ -82609,7 +84287,7 @@ async function executeBashCommand(command, options = {}) {
|
|
|
82609
84287
|
success = false;
|
|
82610
84288
|
error2 = `Command exited with code ${code}`;
|
|
82611
84289
|
}
|
|
82612
|
-
|
|
84290
|
+
resolve5({
|
|
82613
84291
|
success,
|
|
82614
84292
|
error: error2,
|
|
82615
84293
|
stdout: stdout.trim(),
|
|
@@ -82629,7 +84307,7 @@ async function executeBashCommand(command, options = {}) {
|
|
|
82629
84307
|
if (debug) {
|
|
82630
84308
|
console.log(`[BashExecutor] Spawn error:`, error2);
|
|
82631
84309
|
}
|
|
82632
|
-
|
|
84310
|
+
resolve5({
|
|
82633
84311
|
success: false,
|
|
82634
84312
|
error: `Failed to execute command: ${error2.message}`,
|
|
82635
84313
|
stdout: "",
|
|
@@ -82905,6 +84583,323 @@ Command failed with exit code ${result.exitCode}`;
|
|
|
82905
84583
|
}
|
|
82906
84584
|
});
|
|
82907
84585
|
|
|
84586
|
+
// src/tools/edit.js
|
|
84587
|
+
function isPathAllowed(filePath, allowedFolders) {
|
|
84588
|
+
if (!allowedFolders || allowedFolders.length === 0) {
|
|
84589
|
+
const resolvedPath3 = (0, import_path9.resolve)(filePath);
|
|
84590
|
+
const cwd = (0, import_path9.resolve)(process.cwd());
|
|
84591
|
+
return resolvedPath3 === cwd || resolvedPath3.startsWith(cwd + import_path9.sep);
|
|
84592
|
+
}
|
|
84593
|
+
const resolvedPath2 = (0, import_path9.resolve)(filePath);
|
|
84594
|
+
return allowedFolders.some((folder) => {
|
|
84595
|
+
const allowedPath = (0, import_path9.resolve)(folder);
|
|
84596
|
+
return resolvedPath2 === allowedPath || resolvedPath2.startsWith(allowedPath + import_path9.sep);
|
|
84597
|
+
});
|
|
84598
|
+
}
|
|
84599
|
+
function parseFileToolOptions(options = {}) {
|
|
84600
|
+
return {
|
|
84601
|
+
debug: options.debug || false,
|
|
84602
|
+
allowedFolders: options.allowedFolders || [],
|
|
84603
|
+
defaultPath: options.defaultPath
|
|
84604
|
+
};
|
|
84605
|
+
}
|
|
84606
|
+
var import_ai4, import_fs7, import_path9, import_fs8, editTool, createTool, editSchema, createSchema, editDescription, createDescription, editToolDefinition, createToolDefinition;
|
|
84607
|
+
var init_edit = __esm({
|
|
84608
|
+
"src/tools/edit.js"() {
|
|
84609
|
+
"use strict";
|
|
84610
|
+
import_ai4 = require("ai");
|
|
84611
|
+
import_fs7 = require("fs");
|
|
84612
|
+
import_path9 = require("path");
|
|
84613
|
+
import_fs8 = require("fs");
|
|
84614
|
+
editTool = (options = {}) => {
|
|
84615
|
+
const { debug, allowedFolders, defaultPath } = parseFileToolOptions(options);
|
|
84616
|
+
return (0, import_ai4.tool)({
|
|
84617
|
+
name: "edit",
|
|
84618
|
+
description: `Edit files using exact string replacement (Claude Code style).
|
|
84619
|
+
|
|
84620
|
+
This tool performs exact string replacements in files. It requires the old_string to match exactly what's in the file, including all whitespace and indentation.
|
|
84621
|
+
|
|
84622
|
+
Parameters:
|
|
84623
|
+
- file_path: Path to the file to edit (absolute or relative)
|
|
84624
|
+
- old_string: Exact text to find and replace (must be unique in the file unless replace_all is true)
|
|
84625
|
+
- new_string: Text to replace with
|
|
84626
|
+
- replace_all: (optional) Replace all occurrences instead of requiring uniqueness
|
|
84627
|
+
|
|
84628
|
+
Important:
|
|
84629
|
+
- The old_string must match EXACTLY including whitespace
|
|
84630
|
+
- If old_string appears multiple times and replace_all is false, the edit will fail
|
|
84631
|
+
- Use larger context around the string to ensure uniqueness when needed`,
|
|
84632
|
+
inputSchema: {
|
|
84633
|
+
type: "object",
|
|
84634
|
+
properties: {
|
|
84635
|
+
file_path: {
|
|
84636
|
+
type: "string",
|
|
84637
|
+
description: "Path to the file to edit"
|
|
84638
|
+
},
|
|
84639
|
+
old_string: {
|
|
84640
|
+
type: "string",
|
|
84641
|
+
description: "Exact text to find and replace"
|
|
84642
|
+
},
|
|
84643
|
+
new_string: {
|
|
84644
|
+
type: "string",
|
|
84645
|
+
description: "Text to replace with"
|
|
84646
|
+
},
|
|
84647
|
+
replace_all: {
|
|
84648
|
+
type: "boolean",
|
|
84649
|
+
description: "Replace all occurrences (default: false)",
|
|
84650
|
+
default: false
|
|
84651
|
+
}
|
|
84652
|
+
},
|
|
84653
|
+
required: ["file_path", "old_string", "new_string"]
|
|
84654
|
+
},
|
|
84655
|
+
execute: async ({ file_path, old_string, new_string, replace_all = false }) => {
|
|
84656
|
+
try {
|
|
84657
|
+
if (!file_path || typeof file_path !== "string" || file_path.trim() === "") {
|
|
84658
|
+
return `Error editing file: Invalid file_path - must be a non-empty string`;
|
|
84659
|
+
}
|
|
84660
|
+
if (old_string === void 0 || old_string === null || typeof old_string !== "string") {
|
|
84661
|
+
return `Error editing file: Invalid old_string - must be a string`;
|
|
84662
|
+
}
|
|
84663
|
+
if (new_string === void 0 || new_string === null || typeof new_string !== "string") {
|
|
84664
|
+
return `Error editing file: Invalid new_string - must be a string`;
|
|
84665
|
+
}
|
|
84666
|
+
const resolvedPath2 = (0, import_path9.isAbsolute)(file_path) ? file_path : (0, import_path9.resolve)(defaultPath || process.cwd(), file_path);
|
|
84667
|
+
if (debug) {
|
|
84668
|
+
console.error(`[Edit] Attempting to edit file: ${resolvedPath2}`);
|
|
84669
|
+
}
|
|
84670
|
+
if (!isPathAllowed(resolvedPath2, allowedFolders)) {
|
|
84671
|
+
return `Error editing file: Permission denied - ${file_path} is outside allowed directories`;
|
|
84672
|
+
}
|
|
84673
|
+
if (!(0, import_fs8.existsSync)(resolvedPath2)) {
|
|
84674
|
+
return `Error editing file: File not found - ${file_path}`;
|
|
84675
|
+
}
|
|
84676
|
+
const content = await import_fs7.promises.readFile(resolvedPath2, "utf-8");
|
|
84677
|
+
if (!content.includes(old_string)) {
|
|
84678
|
+
return `Error editing file: String not found - the specified old_string was not found in ${file_path}`;
|
|
84679
|
+
}
|
|
84680
|
+
const occurrences = content.split(old_string).length - 1;
|
|
84681
|
+
if (!replace_all && occurrences > 1) {
|
|
84682
|
+
return `Error editing file: Multiple occurrences found - the old_string appears ${occurrences} times. Use replace_all: true to replace all occurrences, or provide more context to make the string unique.`;
|
|
84683
|
+
}
|
|
84684
|
+
let newContent;
|
|
84685
|
+
if (replace_all) {
|
|
84686
|
+
newContent = content.replaceAll(old_string, new_string);
|
|
84687
|
+
} else {
|
|
84688
|
+
newContent = content.replace(old_string, new_string);
|
|
84689
|
+
}
|
|
84690
|
+
if (newContent === content) {
|
|
84691
|
+
return `Error editing file: No changes made - old_string and new_string might be the same`;
|
|
84692
|
+
}
|
|
84693
|
+
await import_fs7.promises.writeFile(resolvedPath2, newContent, "utf-8");
|
|
84694
|
+
const replacedCount = replace_all ? occurrences : 1;
|
|
84695
|
+
if (debug) {
|
|
84696
|
+
console.error(`[Edit] Successfully edited ${resolvedPath2}, replaced ${replacedCount} occurrence(s)`);
|
|
84697
|
+
}
|
|
84698
|
+
return `Successfully edited ${file_path} (${replacedCount} replacement${replacedCount !== 1 ? "s" : ""})`;
|
|
84699
|
+
} catch (error2) {
|
|
84700
|
+
console.error("[Edit] Error:", error2);
|
|
84701
|
+
return `Error editing file: ${error2.message}`;
|
|
84702
|
+
}
|
|
84703
|
+
}
|
|
84704
|
+
});
|
|
84705
|
+
};
|
|
84706
|
+
createTool = (options = {}) => {
|
|
84707
|
+
const { debug, allowedFolders, defaultPath } = parseFileToolOptions(options);
|
|
84708
|
+
return (0, import_ai4.tool)({
|
|
84709
|
+
name: "create",
|
|
84710
|
+
description: `Create new files with specified content.
|
|
84711
|
+
|
|
84712
|
+
This tool creates new files in the filesystem. It will create parent directories if they don't exist.
|
|
84713
|
+
|
|
84714
|
+
Parameters:
|
|
84715
|
+
- file_path: Path where the file should be created (absolute or relative)
|
|
84716
|
+
- content: Content to write to the file
|
|
84717
|
+
- overwrite: (optional) Whether to overwrite if file exists (default: false)
|
|
84718
|
+
|
|
84719
|
+
Important:
|
|
84720
|
+
- By default, will fail if the file already exists
|
|
84721
|
+
- Set overwrite: true to replace existing files
|
|
84722
|
+
- Parent directories will be created automatically if needed`,
|
|
84723
|
+
inputSchema: {
|
|
84724
|
+
type: "object",
|
|
84725
|
+
properties: {
|
|
84726
|
+
file_path: {
|
|
84727
|
+
type: "string",
|
|
84728
|
+
description: "Path where the file should be created"
|
|
84729
|
+
},
|
|
84730
|
+
content: {
|
|
84731
|
+
type: "string",
|
|
84732
|
+
description: "Content to write to the file"
|
|
84733
|
+
},
|
|
84734
|
+
overwrite: {
|
|
84735
|
+
type: "boolean",
|
|
84736
|
+
description: "Overwrite if file exists (default: false)",
|
|
84737
|
+
default: false
|
|
84738
|
+
}
|
|
84739
|
+
},
|
|
84740
|
+
required: ["file_path", "content"]
|
|
84741
|
+
},
|
|
84742
|
+
execute: async ({ file_path, content, overwrite = false }) => {
|
|
84743
|
+
try {
|
|
84744
|
+
if (!file_path || typeof file_path !== "string" || file_path.trim() === "") {
|
|
84745
|
+
return `Error creating file: Invalid file_path - must be a non-empty string`;
|
|
84746
|
+
}
|
|
84747
|
+
if (content === void 0 || content === null || typeof content !== "string") {
|
|
84748
|
+
return `Error creating file: Invalid content - must be a string`;
|
|
84749
|
+
}
|
|
84750
|
+
const resolvedPath2 = (0, import_path9.isAbsolute)(file_path) ? file_path : (0, import_path9.resolve)(defaultPath || process.cwd(), file_path);
|
|
84751
|
+
if (debug) {
|
|
84752
|
+
console.error(`[Create] Attempting to create file: ${resolvedPath2}`);
|
|
84753
|
+
}
|
|
84754
|
+
if (!isPathAllowed(resolvedPath2, allowedFolders)) {
|
|
84755
|
+
return `Error creating file: Permission denied - ${file_path} is outside allowed directories`;
|
|
84756
|
+
}
|
|
84757
|
+
if ((0, import_fs8.existsSync)(resolvedPath2) && !overwrite) {
|
|
84758
|
+
return `Error creating file: File already exists - ${file_path}. Use overwrite: true to replace it.`;
|
|
84759
|
+
}
|
|
84760
|
+
const dir = (0, import_path9.dirname)(resolvedPath2);
|
|
84761
|
+
await import_fs7.promises.mkdir(dir, { recursive: true });
|
|
84762
|
+
await import_fs7.promises.writeFile(resolvedPath2, content, "utf-8");
|
|
84763
|
+
const action = (0, import_fs8.existsSync)(resolvedPath2) && overwrite ? "overwrote" : "created";
|
|
84764
|
+
const bytes = Buffer.byteLength(content, "utf-8");
|
|
84765
|
+
if (debug) {
|
|
84766
|
+
console.error(`[Create] Successfully ${action} ${resolvedPath2}`);
|
|
84767
|
+
}
|
|
84768
|
+
return `Successfully ${action} ${file_path} (${bytes} bytes)`;
|
|
84769
|
+
} catch (error2) {
|
|
84770
|
+
console.error("[Create] Error:", error2);
|
|
84771
|
+
return `Error creating file: ${error2.message}`;
|
|
84772
|
+
}
|
|
84773
|
+
}
|
|
84774
|
+
});
|
|
84775
|
+
};
|
|
84776
|
+
editSchema = {
|
|
84777
|
+
type: "object",
|
|
84778
|
+
properties: {
|
|
84779
|
+
file_path: {
|
|
84780
|
+
type: "string",
|
|
84781
|
+
description: "Path to the file to edit"
|
|
84782
|
+
},
|
|
84783
|
+
old_string: {
|
|
84784
|
+
type: "string",
|
|
84785
|
+
description: "Exact text to find and replace"
|
|
84786
|
+
},
|
|
84787
|
+
new_string: {
|
|
84788
|
+
type: "string",
|
|
84789
|
+
description: "Text to replace with"
|
|
84790
|
+
},
|
|
84791
|
+
replace_all: {
|
|
84792
|
+
type: "boolean",
|
|
84793
|
+
description: "Replace all occurrences (default: false)"
|
|
84794
|
+
}
|
|
84795
|
+
},
|
|
84796
|
+
required: ["file_path", "old_string", "new_string"]
|
|
84797
|
+
};
|
|
84798
|
+
createSchema = {
|
|
84799
|
+
type: "object",
|
|
84800
|
+
properties: {
|
|
84801
|
+
file_path: {
|
|
84802
|
+
type: "string",
|
|
84803
|
+
description: "Path where the file should be created"
|
|
84804
|
+
},
|
|
84805
|
+
content: {
|
|
84806
|
+
type: "string",
|
|
84807
|
+
description: "Content to write to the file"
|
|
84808
|
+
},
|
|
84809
|
+
overwrite: {
|
|
84810
|
+
type: "boolean",
|
|
84811
|
+
description: "Overwrite if file exists (default: false)"
|
|
84812
|
+
}
|
|
84813
|
+
},
|
|
84814
|
+
required: ["file_path", "content"]
|
|
84815
|
+
};
|
|
84816
|
+
editDescription = "Edit files using exact string replacement. Requires exact match including whitespace.";
|
|
84817
|
+
createDescription = "Create new files with specified content. Will create parent directories if needed.";
|
|
84818
|
+
editToolDefinition = `
|
|
84819
|
+
## edit
|
|
84820
|
+
Description: ${editDescription}
|
|
84821
|
+
|
|
84822
|
+
When to use:
|
|
84823
|
+
- For precise, surgical edits to existing files
|
|
84824
|
+
- When you need to change specific lines or blocks of code
|
|
84825
|
+
- For renaming functions, variables, or updating configuration values
|
|
84826
|
+
- When the exact text to replace is known and unique (or use replace_all for multiple occurrences)
|
|
84827
|
+
|
|
84828
|
+
When NOT to use:
|
|
84829
|
+
- For creating new files (use 'create' tool instead)
|
|
84830
|
+
- When you cannot determine the exact text to replace
|
|
84831
|
+
- When changes span multiple locations that would be better handled together
|
|
84832
|
+
|
|
84833
|
+
Parameters:
|
|
84834
|
+
- file_path: (required) Path to the file to edit
|
|
84835
|
+
- old_string: (required) Exact text to find and replace (must match including whitespace, newlines, and indentation)
|
|
84836
|
+
- new_string: (required) Text to replace with
|
|
84837
|
+
- replace_all: (optional, default: false) Replace all occurrences if the string appears multiple times
|
|
84838
|
+
|
|
84839
|
+
Important notes:
|
|
84840
|
+
- The old_string MUST match EXACTLY, including all whitespace, indentation, and line breaks
|
|
84841
|
+
- If old_string appears multiple times and replace_all is false, the tool will fail
|
|
84842
|
+
- Always verify the exact formatting of the text you want to replace
|
|
84843
|
+
|
|
84844
|
+
Examples:
|
|
84845
|
+
<edit>
|
|
84846
|
+
<file_path>src/main.js</file_path>
|
|
84847
|
+
<old_string>function oldName() {
|
|
84848
|
+
return 42;
|
|
84849
|
+
}</old_string>
|
|
84850
|
+
<new_string>function newName() {
|
|
84851
|
+
return 42;
|
|
84852
|
+
}</new_string>
|
|
84853
|
+
</edit>
|
|
84854
|
+
|
|
84855
|
+
<edit>
|
|
84856
|
+
<file_path>config.json</file_path>
|
|
84857
|
+
<old_string>"debug": false</old_string>
|
|
84858
|
+
<new_string>"debug": true</new_string>
|
|
84859
|
+
<replace_all>true</replace_all>
|
|
84860
|
+
</edit>`;
|
|
84861
|
+
createToolDefinition = `
|
|
84862
|
+
## create
|
|
84863
|
+
Description: ${createDescription}
|
|
84864
|
+
|
|
84865
|
+
When to use:
|
|
84866
|
+
- For creating brand new files from scratch
|
|
84867
|
+
- When you need to add configuration files, documentation, or new modules
|
|
84868
|
+
- For generating boilerplate code or templates
|
|
84869
|
+
- When you have the complete content ready to write
|
|
84870
|
+
|
|
84871
|
+
When NOT to use:
|
|
84872
|
+
- For editing existing files (use 'edit' tool instead)
|
|
84873
|
+
- When a file already exists unless you explicitly want to overwrite it
|
|
84874
|
+
|
|
84875
|
+
Parameters:
|
|
84876
|
+
- file_path: (required) Path where the file should be created
|
|
84877
|
+
- content: (required) Complete content to write to the file
|
|
84878
|
+
- overwrite: (optional, default: false) Whether to overwrite if file already exists
|
|
84879
|
+
|
|
84880
|
+
Important notes:
|
|
84881
|
+
- Parent directories will be created automatically if they don't exist
|
|
84882
|
+
- The tool will fail if the file already exists and overwrite is false
|
|
84883
|
+
- Be careful with the overwrite option as it completely replaces existing files
|
|
84884
|
+
|
|
84885
|
+
Examples:
|
|
84886
|
+
<create>
|
|
84887
|
+
<file_path>src/newFile.js</file_path>
|
|
84888
|
+
<content>export function hello() {
|
|
84889
|
+
return "Hello, world!";
|
|
84890
|
+
}</content>
|
|
84891
|
+
</create>
|
|
84892
|
+
|
|
84893
|
+
<create>
|
|
84894
|
+
<file_path>README.md</file_path>
|
|
84895
|
+
<content># My Project
|
|
84896
|
+
|
|
84897
|
+
This is a new project.</content>
|
|
84898
|
+
<overwrite>true</overwrite>
|
|
84899
|
+
</create>`;
|
|
84900
|
+
}
|
|
84901
|
+
});
|
|
84902
|
+
|
|
82908
84903
|
// src/tools/langchain.js
|
|
82909
84904
|
function createSearchTool() {
|
|
82910
84905
|
return {
|
|
@@ -83126,13 +85121,21 @@ __export(tools_exports, {
|
|
|
83126
85121
|
bashSchema: () => bashSchema,
|
|
83127
85122
|
bashTool: () => bashTool,
|
|
83128
85123
|
bashToolDefinition: () => bashToolDefinition,
|
|
85124
|
+
createDescription: () => createDescription,
|
|
83129
85125
|
createExtractTool: () => createExtractTool,
|
|
83130
85126
|
createQueryTool: () => createQueryTool,
|
|
85127
|
+
createSchema: () => createSchema,
|
|
83131
85128
|
createSearchTool: () => createSearchTool,
|
|
85129
|
+
createTool: () => createTool,
|
|
85130
|
+
createToolDefinition: () => createToolDefinition,
|
|
83132
85131
|
delegateDescription: () => delegateDescription,
|
|
83133
85132
|
delegateSchema: () => delegateSchema,
|
|
83134
85133
|
delegateTool: () => delegateTool,
|
|
83135
85134
|
delegateToolDefinition: () => delegateToolDefinition,
|
|
85135
|
+
editDescription: () => editDescription,
|
|
85136
|
+
editSchema: () => editSchema,
|
|
85137
|
+
editTool: () => editTool,
|
|
85138
|
+
editToolDefinition: () => editToolDefinition,
|
|
83136
85139
|
extractSchema: () => extractSchema,
|
|
83137
85140
|
extractTool: () => extractTool,
|
|
83138
85141
|
querySchema: () => querySchema,
|
|
@@ -83147,8 +85150,10 @@ var init_tools2 = __esm({
|
|
|
83147
85150
|
"use strict";
|
|
83148
85151
|
init_vercel();
|
|
83149
85152
|
init_bash();
|
|
85153
|
+
init_edit();
|
|
83150
85154
|
init_langchain();
|
|
83151
85155
|
init_common2();
|
|
85156
|
+
init_edit();
|
|
83152
85157
|
init_system_message();
|
|
83153
85158
|
init_vercel();
|
|
83154
85159
|
init_bash();
|
|
@@ -83171,10 +85176,10 @@ async function listFilesByLevel(options) {
|
|
|
83171
85176
|
maxFiles = 100,
|
|
83172
85177
|
respectGitignore = true
|
|
83173
85178
|
} = options;
|
|
83174
|
-
if (!
|
|
85179
|
+
if (!import_fs9.default.existsSync(directory)) {
|
|
83175
85180
|
throw new Error(`Directory does not exist: ${directory}`);
|
|
83176
85181
|
}
|
|
83177
|
-
const gitDirExists =
|
|
85182
|
+
const gitDirExists = import_fs9.default.existsSync(import_path10.default.join(directory, ".git"));
|
|
83178
85183
|
if (gitDirExists && respectGitignore) {
|
|
83179
85184
|
try {
|
|
83180
85185
|
return await listFilesUsingGit(directory, maxFiles);
|
|
@@ -83189,8 +85194,8 @@ async function listFilesUsingGit(directory, maxFiles) {
|
|
|
83189
85194
|
const { stdout } = await execAsync3("git ls-files", { cwd: directory });
|
|
83190
85195
|
const files = stdout.split("\n").filter(Boolean);
|
|
83191
85196
|
const sortedFiles = files.sort((a3, b3) => {
|
|
83192
|
-
const depthA = a3.split(
|
|
83193
|
-
const depthB = b3.split(
|
|
85197
|
+
const depthA = a3.split(import_path10.default.sep).length;
|
|
85198
|
+
const depthB = b3.split(import_path10.default.sep).length;
|
|
83194
85199
|
return depthA - depthB;
|
|
83195
85200
|
});
|
|
83196
85201
|
return sortedFiles.slice(0, maxFiles);
|
|
@@ -83205,19 +85210,19 @@ async function listFilesByLevelManually(directory, maxFiles, respectGitignore) {
|
|
|
83205
85210
|
while (queue.length > 0 && result.length < maxFiles) {
|
|
83206
85211
|
const { dir, level } = queue.shift();
|
|
83207
85212
|
try {
|
|
83208
|
-
const entries =
|
|
85213
|
+
const entries = import_fs9.default.readdirSync(dir, { withFileTypes: true });
|
|
83209
85214
|
const files = entries.filter((entry) => entry.isFile());
|
|
83210
85215
|
for (const file of files) {
|
|
83211
85216
|
if (result.length >= maxFiles) break;
|
|
83212
|
-
const filePath =
|
|
83213
|
-
const relativePath =
|
|
85217
|
+
const filePath = import_path10.default.join(dir, file.name);
|
|
85218
|
+
const relativePath = import_path10.default.relative(directory, filePath);
|
|
83214
85219
|
if (shouldIgnore(relativePath, ignorePatterns)) continue;
|
|
83215
85220
|
result.push(relativePath);
|
|
83216
85221
|
}
|
|
83217
85222
|
const dirs = entries.filter((entry) => entry.isDirectory());
|
|
83218
85223
|
for (const subdir of dirs) {
|
|
83219
|
-
const subdirPath =
|
|
83220
|
-
const relativeSubdirPath =
|
|
85224
|
+
const subdirPath = import_path10.default.join(dir, subdir.name);
|
|
85225
|
+
const relativeSubdirPath = import_path10.default.relative(directory, subdirPath);
|
|
83221
85226
|
if (shouldIgnore(relativeSubdirPath, ignorePatterns)) continue;
|
|
83222
85227
|
if (subdir.name === "node_modules" || subdir.name === ".git") continue;
|
|
83223
85228
|
queue.push({ dir: subdirPath, level: level + 1 });
|
|
@@ -83229,12 +85234,12 @@ async function listFilesByLevelManually(directory, maxFiles, respectGitignore) {
|
|
|
83229
85234
|
return result;
|
|
83230
85235
|
}
|
|
83231
85236
|
function loadGitignorePatterns(directory) {
|
|
83232
|
-
const gitignorePath =
|
|
83233
|
-
if (!
|
|
85237
|
+
const gitignorePath = import_path10.default.join(directory, ".gitignore");
|
|
85238
|
+
if (!import_fs9.default.existsSync(gitignorePath)) {
|
|
83234
85239
|
return [];
|
|
83235
85240
|
}
|
|
83236
85241
|
try {
|
|
83237
|
-
const content =
|
|
85242
|
+
const content = import_fs9.default.readFileSync(gitignorePath, "utf8");
|
|
83238
85243
|
return content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
83239
85244
|
} catch (error2) {
|
|
83240
85245
|
console.error(`Warning: Could not read .gitignore: ${error2.message}`);
|
|
@@ -83252,12 +85257,12 @@ function shouldIgnore(filePath, ignorePatterns) {
|
|
|
83252
85257
|
}
|
|
83253
85258
|
return false;
|
|
83254
85259
|
}
|
|
83255
|
-
var
|
|
85260
|
+
var import_fs9, import_path10, import_util12, import_child_process8, execAsync3;
|
|
83256
85261
|
var init_file_lister = __esm({
|
|
83257
85262
|
"src/utils/file-lister.js"() {
|
|
83258
85263
|
"use strict";
|
|
83259
|
-
|
|
83260
|
-
|
|
85264
|
+
import_fs9 = __toESM(require("fs"), 1);
|
|
85265
|
+
import_path10 = __toESM(require("path"), 1);
|
|
83261
85266
|
import_util12 = require("util");
|
|
83262
85267
|
import_child_process8 = require("child_process");
|
|
83263
85268
|
execAsync3 = (0, import_util12.promisify)(import_child_process8.exec);
|
|
@@ -83274,12 +85279,12 @@ function initializeSimpleTelemetryFromOptions(options) {
|
|
|
83274
85279
|
});
|
|
83275
85280
|
return telemetry;
|
|
83276
85281
|
}
|
|
83277
|
-
var
|
|
85282
|
+
var import_fs10, import_path11, SimpleTelemetry, SimpleAppTracer;
|
|
83278
85283
|
var init_simpleTelemetry = __esm({
|
|
83279
85284
|
"src/agent/simpleTelemetry.js"() {
|
|
83280
85285
|
"use strict";
|
|
83281
|
-
|
|
83282
|
-
|
|
85286
|
+
import_fs10 = require("fs");
|
|
85287
|
+
import_path11 = require("path");
|
|
83283
85288
|
SimpleTelemetry = class {
|
|
83284
85289
|
constructor(options = {}) {
|
|
83285
85290
|
this.serviceName = options.serviceName || "probe-agent";
|
|
@@ -83293,11 +85298,11 @@ var init_simpleTelemetry = __esm({
|
|
|
83293
85298
|
}
|
|
83294
85299
|
initializeFileExporter() {
|
|
83295
85300
|
try {
|
|
83296
|
-
const dir = (0,
|
|
83297
|
-
if (!(0,
|
|
83298
|
-
(0,
|
|
85301
|
+
const dir = (0, import_path11.dirname)(this.filePath);
|
|
85302
|
+
if (!(0, import_fs10.existsSync)(dir)) {
|
|
85303
|
+
(0, import_fs10.mkdirSync)(dir, { recursive: true });
|
|
83299
85304
|
}
|
|
83300
|
-
this.stream = (0,
|
|
85305
|
+
this.stream = (0, import_fs10.createWriteStream)(this.filePath, { flags: "a" });
|
|
83301
85306
|
this.stream.on("error", (error2) => {
|
|
83302
85307
|
console.error(`[SimpleTelemetry] Stream error: ${error2.message}`);
|
|
83303
85308
|
});
|
|
@@ -83358,20 +85363,20 @@ var init_simpleTelemetry = __esm({
|
|
|
83358
85363
|
}
|
|
83359
85364
|
async flush() {
|
|
83360
85365
|
if (this.stream) {
|
|
83361
|
-
return new Promise((
|
|
83362
|
-
this.stream.once("drain",
|
|
85366
|
+
return new Promise((resolve5) => {
|
|
85367
|
+
this.stream.once("drain", resolve5);
|
|
83363
85368
|
if (!this.stream.writableNeedDrain) {
|
|
83364
|
-
|
|
85369
|
+
resolve5();
|
|
83365
85370
|
}
|
|
83366
85371
|
});
|
|
83367
85372
|
}
|
|
83368
85373
|
}
|
|
83369
85374
|
async shutdown() {
|
|
83370
85375
|
if (this.stream) {
|
|
83371
|
-
return new Promise((
|
|
85376
|
+
return new Promise((resolve5) => {
|
|
83372
85377
|
this.stream.end(() => {
|
|
83373
85378
|
console.log(`[SimpleTelemetry] File stream closed: ${this.filePath}`);
|
|
83374
|
-
|
|
85379
|
+
resolve5();
|
|
83375
85380
|
});
|
|
83376
85381
|
});
|
|
83377
85382
|
}
|
|
@@ -83522,10 +85527,16 @@ __export(index_exports, {
|
|
|
83522
85527
|
bashSchema: () => bashSchema,
|
|
83523
85528
|
bashTool: () => bashTool,
|
|
83524
85529
|
bashToolDefinition: () => bashToolDefinition,
|
|
85530
|
+
createSchema: () => createSchema,
|
|
85531
|
+
createTool: () => createTool,
|
|
85532
|
+
createToolDefinition: () => createToolDefinition,
|
|
83525
85533
|
delegate: () => delegate,
|
|
83526
85534
|
delegateSchema: () => delegateSchema,
|
|
83527
85535
|
delegateTool: () => delegateTool,
|
|
83528
85536
|
delegateToolDefinition: () => delegateToolDefinition,
|
|
85537
|
+
editSchema: () => editSchema,
|
|
85538
|
+
editTool: () => editTool,
|
|
85539
|
+
editToolDefinition: () => editToolDefinition,
|
|
83529
85540
|
extract: () => extract,
|
|
83530
85541
|
extractSchema: () => extractSchema,
|
|
83531
85542
|
extractTool: () => extractTool,
|
|
@@ -83563,8 +85574,10 @@ var init_index = __esm({
|
|
|
83563
85574
|
init_file_lister();
|
|
83564
85575
|
init_system_message();
|
|
83565
85576
|
init_common2();
|
|
85577
|
+
init_edit();
|
|
83566
85578
|
init_vercel();
|
|
83567
85579
|
init_bash();
|
|
85580
|
+
init_edit();
|
|
83568
85581
|
init_ProbeAgent();
|
|
83569
85582
|
init_simpleTelemetry();
|
|
83570
85583
|
init_probeTool();
|
|
@@ -83589,10 +85602,16 @@ init_index();
|
|
|
83589
85602
|
bashSchema,
|
|
83590
85603
|
bashTool,
|
|
83591
85604
|
bashToolDefinition,
|
|
85605
|
+
createSchema,
|
|
85606
|
+
createTool,
|
|
85607
|
+
createToolDefinition,
|
|
83592
85608
|
delegate,
|
|
83593
85609
|
delegateSchema,
|
|
83594
85610
|
delegateTool,
|
|
83595
85611
|
delegateToolDefinition,
|
|
85612
|
+
editSchema,
|
|
85613
|
+
editTool,
|
|
85614
|
+
editToolDefinition,
|
|
83596
85615
|
extract,
|
|
83597
85616
|
extractSchema,
|
|
83598
85617
|
extractTool,
|