@elizaos/core 1.6.5-alpha.18 → 1.6.5-alpha.19
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/dist/browser/index.browser.js +110 -109
- package/dist/browser/index.browser.js.map +24 -14
- package/dist/node/index.node.js +592 -334
- package/dist/node/index.node.js.map +16 -14
- package/package.json +3 -3
package/dist/node/index.node.js
CHANGED
|
@@ -1438,295 +1438,6 @@ var require_dist2 = __commonJS((exports) => {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
});
|
|
1440
1440
|
|
|
1441
|
-
// ../../node_modules/retry/lib/retry_operation.js
|
|
1442
|
-
var require_retry_operation = __commonJS((exports, module) => {
|
|
1443
|
-
function RetryOperation(timeouts, options) {
|
|
1444
|
-
if (typeof options === "boolean") {
|
|
1445
|
-
options = { forever: options };
|
|
1446
|
-
}
|
|
1447
|
-
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
1448
|
-
this._timeouts = timeouts;
|
|
1449
|
-
this._options = options || {};
|
|
1450
|
-
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
1451
|
-
this._fn = null;
|
|
1452
|
-
this._errors = [];
|
|
1453
|
-
this._attempts = 1;
|
|
1454
|
-
this._operationTimeout = null;
|
|
1455
|
-
this._operationTimeoutCb = null;
|
|
1456
|
-
this._timeout = null;
|
|
1457
|
-
this._operationStart = null;
|
|
1458
|
-
this._timer = null;
|
|
1459
|
-
if (this._options.forever) {
|
|
1460
|
-
this._cachedTimeouts = this._timeouts.slice(0);
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
module.exports = RetryOperation;
|
|
1464
|
-
RetryOperation.prototype.reset = function() {
|
|
1465
|
-
this._attempts = 1;
|
|
1466
|
-
this._timeouts = this._originalTimeouts.slice(0);
|
|
1467
|
-
};
|
|
1468
|
-
RetryOperation.prototype.stop = function() {
|
|
1469
|
-
if (this._timeout) {
|
|
1470
|
-
clearTimeout(this._timeout);
|
|
1471
|
-
}
|
|
1472
|
-
if (this._timer) {
|
|
1473
|
-
clearTimeout(this._timer);
|
|
1474
|
-
}
|
|
1475
|
-
this._timeouts = [];
|
|
1476
|
-
this._cachedTimeouts = null;
|
|
1477
|
-
};
|
|
1478
|
-
RetryOperation.prototype.retry = function(err) {
|
|
1479
|
-
if (this._timeout) {
|
|
1480
|
-
clearTimeout(this._timeout);
|
|
1481
|
-
}
|
|
1482
|
-
if (!err) {
|
|
1483
|
-
return false;
|
|
1484
|
-
}
|
|
1485
|
-
var currentTime = new Date().getTime();
|
|
1486
|
-
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
1487
|
-
this._errors.push(err);
|
|
1488
|
-
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
1489
|
-
return false;
|
|
1490
|
-
}
|
|
1491
|
-
this._errors.push(err);
|
|
1492
|
-
var timeout = this._timeouts.shift();
|
|
1493
|
-
if (timeout === undefined) {
|
|
1494
|
-
if (this._cachedTimeouts) {
|
|
1495
|
-
this._errors.splice(0, this._errors.length - 1);
|
|
1496
|
-
timeout = this._cachedTimeouts.slice(-1);
|
|
1497
|
-
} else {
|
|
1498
|
-
return false;
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
var self2 = this;
|
|
1502
|
-
this._timer = setTimeout(function() {
|
|
1503
|
-
self2._attempts++;
|
|
1504
|
-
if (self2._operationTimeoutCb) {
|
|
1505
|
-
self2._timeout = setTimeout(function() {
|
|
1506
|
-
self2._operationTimeoutCb(self2._attempts);
|
|
1507
|
-
}, self2._operationTimeout);
|
|
1508
|
-
if (self2._options.unref) {
|
|
1509
|
-
self2._timeout.unref();
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
self2._fn(self2._attempts);
|
|
1513
|
-
}, timeout);
|
|
1514
|
-
if (this._options.unref) {
|
|
1515
|
-
this._timer.unref();
|
|
1516
|
-
}
|
|
1517
|
-
return true;
|
|
1518
|
-
};
|
|
1519
|
-
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
1520
|
-
this._fn = fn;
|
|
1521
|
-
if (timeoutOps) {
|
|
1522
|
-
if (timeoutOps.timeout) {
|
|
1523
|
-
this._operationTimeout = timeoutOps.timeout;
|
|
1524
|
-
}
|
|
1525
|
-
if (timeoutOps.cb) {
|
|
1526
|
-
this._operationTimeoutCb = timeoutOps.cb;
|
|
1527
|
-
}
|
|
1528
|
-
}
|
|
1529
|
-
var self2 = this;
|
|
1530
|
-
if (this._operationTimeoutCb) {
|
|
1531
|
-
this._timeout = setTimeout(function() {
|
|
1532
|
-
self2._operationTimeoutCb();
|
|
1533
|
-
}, self2._operationTimeout);
|
|
1534
|
-
}
|
|
1535
|
-
this._operationStart = new Date().getTime();
|
|
1536
|
-
this._fn(this._attempts);
|
|
1537
|
-
};
|
|
1538
|
-
RetryOperation.prototype.try = function(fn) {
|
|
1539
|
-
console.log("Using RetryOperation.try() is deprecated");
|
|
1540
|
-
this.attempt(fn);
|
|
1541
|
-
};
|
|
1542
|
-
RetryOperation.prototype.start = function(fn) {
|
|
1543
|
-
console.log("Using RetryOperation.start() is deprecated");
|
|
1544
|
-
this.attempt(fn);
|
|
1545
|
-
};
|
|
1546
|
-
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
1547
|
-
RetryOperation.prototype.errors = function() {
|
|
1548
|
-
return this._errors;
|
|
1549
|
-
};
|
|
1550
|
-
RetryOperation.prototype.attempts = function() {
|
|
1551
|
-
return this._attempts;
|
|
1552
|
-
};
|
|
1553
|
-
RetryOperation.prototype.mainError = function() {
|
|
1554
|
-
if (this._errors.length === 0) {
|
|
1555
|
-
return null;
|
|
1556
|
-
}
|
|
1557
|
-
var counts = {};
|
|
1558
|
-
var mainError = null;
|
|
1559
|
-
var mainErrorCount = 0;
|
|
1560
|
-
for (var i = 0;i < this._errors.length; i++) {
|
|
1561
|
-
var error = this._errors[i];
|
|
1562
|
-
var message = error.message;
|
|
1563
|
-
var count = (counts[message] || 0) + 1;
|
|
1564
|
-
counts[message] = count;
|
|
1565
|
-
if (count >= mainErrorCount) {
|
|
1566
|
-
mainError = error;
|
|
1567
|
-
mainErrorCount = count;
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
return mainError;
|
|
1571
|
-
};
|
|
1572
|
-
});
|
|
1573
|
-
|
|
1574
|
-
// ../../node_modules/retry/lib/retry.js
|
|
1575
|
-
var require_retry = __commonJS((exports) => {
|
|
1576
|
-
var RetryOperation = require_retry_operation();
|
|
1577
|
-
exports.operation = function(options) {
|
|
1578
|
-
var timeouts = exports.timeouts(options);
|
|
1579
|
-
return new RetryOperation(timeouts, {
|
|
1580
|
-
forever: options && (options.forever || options.retries === Infinity),
|
|
1581
|
-
unref: options && options.unref,
|
|
1582
|
-
maxRetryTime: options && options.maxRetryTime
|
|
1583
|
-
});
|
|
1584
|
-
};
|
|
1585
|
-
exports.timeouts = function(options) {
|
|
1586
|
-
if (options instanceof Array) {
|
|
1587
|
-
return [].concat(options);
|
|
1588
|
-
}
|
|
1589
|
-
var opts = {
|
|
1590
|
-
retries: 10,
|
|
1591
|
-
factor: 2,
|
|
1592
|
-
minTimeout: 1 * 1000,
|
|
1593
|
-
maxTimeout: Infinity,
|
|
1594
|
-
randomize: false
|
|
1595
|
-
};
|
|
1596
|
-
for (var key in options) {
|
|
1597
|
-
opts[key] = options[key];
|
|
1598
|
-
}
|
|
1599
|
-
if (opts.minTimeout > opts.maxTimeout) {
|
|
1600
|
-
throw new Error("minTimeout is greater than maxTimeout");
|
|
1601
|
-
}
|
|
1602
|
-
var timeouts = [];
|
|
1603
|
-
for (var i = 0;i < opts.retries; i++) {
|
|
1604
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
1605
|
-
}
|
|
1606
|
-
if (options && options.forever && !timeouts.length) {
|
|
1607
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
1608
|
-
}
|
|
1609
|
-
timeouts.sort(function(a, b) {
|
|
1610
|
-
return a - b;
|
|
1611
|
-
});
|
|
1612
|
-
return timeouts;
|
|
1613
|
-
};
|
|
1614
|
-
exports.createTimeout = function(attempt, opts) {
|
|
1615
|
-
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
1616
|
-
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
1617
|
-
timeout = Math.min(timeout, opts.maxTimeout);
|
|
1618
|
-
return timeout;
|
|
1619
|
-
};
|
|
1620
|
-
exports.wrap = function(obj, options, methods) {
|
|
1621
|
-
if (options instanceof Array) {
|
|
1622
|
-
methods = options;
|
|
1623
|
-
options = null;
|
|
1624
|
-
}
|
|
1625
|
-
if (!methods) {
|
|
1626
|
-
methods = [];
|
|
1627
|
-
for (var key in obj) {
|
|
1628
|
-
if (typeof obj[key] === "function") {
|
|
1629
|
-
methods.push(key);
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
for (var i = 0;i < methods.length; i++) {
|
|
1634
|
-
var method = methods[i];
|
|
1635
|
-
var original = obj[method];
|
|
1636
|
-
obj[method] = function retryWrapper(original2) {
|
|
1637
|
-
var op = exports.operation(options);
|
|
1638
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
|
1639
|
-
var callback = args.pop();
|
|
1640
|
-
args.push(function(err) {
|
|
1641
|
-
if (op.retry(err)) {
|
|
1642
|
-
return;
|
|
1643
|
-
}
|
|
1644
|
-
if (err) {
|
|
1645
|
-
arguments[0] = op.mainError();
|
|
1646
|
-
}
|
|
1647
|
-
callback.apply(this, arguments);
|
|
1648
|
-
});
|
|
1649
|
-
op.attempt(function() {
|
|
1650
|
-
original2.apply(obj, args);
|
|
1651
|
-
});
|
|
1652
|
-
}.bind(obj, original);
|
|
1653
|
-
obj[method].options = options;
|
|
1654
|
-
}
|
|
1655
|
-
};
|
|
1656
|
-
});
|
|
1657
|
-
|
|
1658
|
-
// ../../node_modules/p-retry/index.js
|
|
1659
|
-
var require_p_retry = __commonJS((exports, module) => {
|
|
1660
|
-
var retry = require_retry();
|
|
1661
|
-
var networkErrorMsgs = [
|
|
1662
|
-
"Failed to fetch",
|
|
1663
|
-
"NetworkError when attempting to fetch resource.",
|
|
1664
|
-
"The Internet connection appears to be offline.",
|
|
1665
|
-
"Network request failed"
|
|
1666
|
-
];
|
|
1667
|
-
|
|
1668
|
-
class AbortError extends Error {
|
|
1669
|
-
constructor(message) {
|
|
1670
|
-
super();
|
|
1671
|
-
if (message instanceof Error) {
|
|
1672
|
-
this.originalError = message;
|
|
1673
|
-
({ message } = message);
|
|
1674
|
-
} else {
|
|
1675
|
-
this.originalError = new Error(message);
|
|
1676
|
-
this.originalError.stack = this.stack;
|
|
1677
|
-
}
|
|
1678
|
-
this.name = "AbortError";
|
|
1679
|
-
this.message = message;
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
1683
|
-
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
1684
|
-
error.attemptNumber = attemptNumber;
|
|
1685
|
-
error.retriesLeft = retriesLeft;
|
|
1686
|
-
return error;
|
|
1687
|
-
};
|
|
1688
|
-
var isNetworkError = (errorMessage) => networkErrorMsgs.includes(errorMessage);
|
|
1689
|
-
var pRetry = (input, options) => new Promise((resolve, reject) => {
|
|
1690
|
-
options = {
|
|
1691
|
-
onFailedAttempt: () => {},
|
|
1692
|
-
retries: 10,
|
|
1693
|
-
...options
|
|
1694
|
-
};
|
|
1695
|
-
const operation = retry.operation(options);
|
|
1696
|
-
operation.attempt(async (attemptNumber) => {
|
|
1697
|
-
try {
|
|
1698
|
-
resolve(await input(attemptNumber));
|
|
1699
|
-
} catch (error) {
|
|
1700
|
-
if (!(error instanceof Error)) {
|
|
1701
|
-
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
1702
|
-
return;
|
|
1703
|
-
}
|
|
1704
|
-
if (error instanceof AbortError) {
|
|
1705
|
-
operation.stop();
|
|
1706
|
-
reject(error.originalError);
|
|
1707
|
-
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
1708
|
-
operation.stop();
|
|
1709
|
-
reject(error);
|
|
1710
|
-
} else {
|
|
1711
|
-
decorateErrorWithCounts(error, attemptNumber, options);
|
|
1712
|
-
try {
|
|
1713
|
-
await options.onFailedAttempt(error);
|
|
1714
|
-
} catch (error2) {
|
|
1715
|
-
reject(error2);
|
|
1716
|
-
return;
|
|
1717
|
-
}
|
|
1718
|
-
if (!operation.retry(error)) {
|
|
1719
|
-
reject(operation.mainError());
|
|
1720
|
-
}
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
});
|
|
1724
|
-
});
|
|
1725
|
-
module.exports = pRetry;
|
|
1726
|
-
module.exports.default = pRetry;
|
|
1727
|
-
module.exports.AbortError = AbortError;
|
|
1728
|
-
});
|
|
1729
|
-
|
|
1730
1441
|
// ../../node_modules/eventemitter3/index.js
|
|
1731
1442
|
var require_eventemitter3 = __commonJS((exports, module) => {
|
|
1732
1443
|
var has = Object.prototype.hasOwnProperty;
|
|
@@ -26612,6 +26323,8 @@ function mergeContent(firstContent, secondContent) {
|
|
|
26612
26323
|
return secondContent;
|
|
26613
26324
|
if (typeof secondContent === "string")
|
|
26614
26325
|
return firstContent + secondContent;
|
|
26326
|
+
else if (Array.isArray(secondContent) && secondContent.length === 0)
|
|
26327
|
+
return firstContent;
|
|
26615
26328
|
else if (Array.isArray(secondContent) && secondContent.some((c) => isDataContentBlock(c)))
|
|
26616
26329
|
return [{
|
|
26617
26330
|
type: "text",
|
|
@@ -26851,9 +26564,17 @@ Right ${typeof right}`);
|
|
|
26851
26564
|
Left ${left}
|
|
26852
26565
|
Right ${right}`);
|
|
26853
26566
|
}
|
|
26854
|
-
var BaseMessageChunk = class extends BaseMessage {
|
|
26567
|
+
var BaseMessageChunk = class BaseMessageChunk2 extends BaseMessage {
|
|
26855
26568
|
static isInstance(obj) {
|
|
26856
|
-
|
|
26569
|
+
if (!super.isInstance(obj))
|
|
26570
|
+
return false;
|
|
26571
|
+
let proto = Object.getPrototypeOf(obj);
|
|
26572
|
+
while (proto !== null) {
|
|
26573
|
+
if (proto === BaseMessageChunk2.prototype)
|
|
26574
|
+
return true;
|
|
26575
|
+
proto = Object.getPrototypeOf(proto);
|
|
26576
|
+
}
|
|
26577
|
+
return false;
|
|
26857
26578
|
}
|
|
26858
26579
|
};
|
|
26859
26580
|
|
|
@@ -27887,7 +27608,6 @@ function warnOnce(message) {
|
|
|
27887
27608
|
|
|
27888
27609
|
// ../../node_modules/langsmith/dist/utils/_uuid.js
|
|
27889
27610
|
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
27890
|
-
var UUID7_WARNING_EMITTED = false;
|
|
27891
27611
|
function assertUuid(str, which) {
|
|
27892
27612
|
if (!UUID_REGEX.test(str)) {
|
|
27893
27613
|
const msg = which !== undefined ? `Invalid UUID for ${which}: ${str}` : `Invalid UUID: ${str}`;
|
|
@@ -27899,22 +27619,8 @@ function uuid7FromTime(timestamp) {
|
|
|
27899
27619
|
const msecs = typeof timestamp === "string" ? Date.parse(timestamp) : timestamp;
|
|
27900
27620
|
return v72({ msecs, seq: 0 });
|
|
27901
27621
|
}
|
|
27902
|
-
function getUuidVersion(uuidStr) {
|
|
27903
|
-
if (!UUID_REGEX.test(uuidStr)) {
|
|
27904
|
-
return null;
|
|
27905
|
-
}
|
|
27906
|
-
const versionChar = uuidStr[14];
|
|
27907
|
-
return parseInt(versionChar, 16);
|
|
27908
|
-
}
|
|
27909
|
-
function warnIfNotUuidV7(uuidStr, _idType) {
|
|
27910
|
-
const version3 = getUuidVersion(uuidStr);
|
|
27911
|
-
if (version3 !== null && version3 !== 7 && !UUID7_WARNING_EMITTED) {
|
|
27912
|
-
UUID7_WARNING_EMITTED = true;
|
|
27913
|
-
warnOnce(`LangSmith now uses UUID v7 for run and trace identifiers. ` + `This warning appears when passing custom IDs. ` + `Please use: import { uuidv7 } from 'langsmith'; const id = uuidv7(); ` + `Future versions will require UUID v7.`);
|
|
27914
|
-
}
|
|
27915
|
-
}
|
|
27916
27622
|
// ../../node_modules/langsmith/dist/index.js
|
|
27917
|
-
var __version__ = "0.3.
|
|
27623
|
+
var __version__ = "0.3.82";
|
|
27918
27624
|
|
|
27919
27625
|
// ../../node_modules/langsmith/dist/utils/env.js
|
|
27920
27626
|
var globalEnv;
|
|
@@ -28501,10 +28207,213 @@ class LangSmithToOTELTranslator {
|
|
|
28501
28207
|
}
|
|
28502
28208
|
}
|
|
28503
28209
|
|
|
28210
|
+
// ../../node_modules/langsmith/dist/utils/is-network-error/index.js
|
|
28211
|
+
var objectToString = Object.prototype.toString;
|
|
28212
|
+
var isError = (value) => objectToString.call(value) === "[object Error]";
|
|
28213
|
+
var errorMessages = new Set([
|
|
28214
|
+
"network error",
|
|
28215
|
+
"Failed to fetch",
|
|
28216
|
+
"NetworkError when attempting to fetch resource.",
|
|
28217
|
+
"The Internet connection appears to be offline.",
|
|
28218
|
+
"Network request failed",
|
|
28219
|
+
"fetch failed",
|
|
28220
|
+
"terminated",
|
|
28221
|
+
" A network error occurred.",
|
|
28222
|
+
"Network connection lost"
|
|
28223
|
+
]);
|
|
28224
|
+
function isNetworkError(error) {
|
|
28225
|
+
const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
|
|
28226
|
+
if (!isValid) {
|
|
28227
|
+
return false;
|
|
28228
|
+
}
|
|
28229
|
+
const { message, stack } = error;
|
|
28230
|
+
if (message === "Load failed") {
|
|
28231
|
+
return stack === undefined || "__sentry_captured__" in error;
|
|
28232
|
+
}
|
|
28233
|
+
if (message.startsWith("error sending request for url")) {
|
|
28234
|
+
return true;
|
|
28235
|
+
}
|
|
28236
|
+
return errorMessages.has(message);
|
|
28237
|
+
}
|
|
28238
|
+
|
|
28239
|
+
// ../../node_modules/langsmith/dist/utils/p-retry/index.js
|
|
28240
|
+
function validateRetries(retries) {
|
|
28241
|
+
if (typeof retries === "number") {
|
|
28242
|
+
if (retries < 0) {
|
|
28243
|
+
throw new TypeError("Expected `retries` to be a non-negative number.");
|
|
28244
|
+
}
|
|
28245
|
+
if (Number.isNaN(retries)) {
|
|
28246
|
+
throw new TypeError("Expected `retries` to be a valid number or Infinity, got NaN.");
|
|
28247
|
+
}
|
|
28248
|
+
} else if (retries !== undefined) {
|
|
28249
|
+
throw new TypeError("Expected `retries` to be a number or Infinity.");
|
|
28250
|
+
}
|
|
28251
|
+
}
|
|
28252
|
+
function validateNumberOption(name, value, { min = 0, allowInfinity = false } = {}) {
|
|
28253
|
+
if (value === undefined) {
|
|
28254
|
+
return;
|
|
28255
|
+
}
|
|
28256
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
28257
|
+
throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? " or Infinity" : ""}.`);
|
|
28258
|
+
}
|
|
28259
|
+
if (!allowInfinity && !Number.isFinite(value)) {
|
|
28260
|
+
throw new TypeError(`Expected \`${name}\` to be a finite number.`);
|
|
28261
|
+
}
|
|
28262
|
+
if (value < min) {
|
|
28263
|
+
throw new TypeError(`Expected \`${name}\` to be ≥ ${min}.`);
|
|
28264
|
+
}
|
|
28265
|
+
}
|
|
28266
|
+
|
|
28267
|
+
class AbortError extends Error {
|
|
28268
|
+
constructor(message) {
|
|
28269
|
+
super();
|
|
28270
|
+
if (message instanceof Error) {
|
|
28271
|
+
this.originalError = message;
|
|
28272
|
+
({ message } = message);
|
|
28273
|
+
} else {
|
|
28274
|
+
this.originalError = new Error(message);
|
|
28275
|
+
this.originalError.stack = this.stack;
|
|
28276
|
+
}
|
|
28277
|
+
this.name = "AbortError";
|
|
28278
|
+
this.message = message;
|
|
28279
|
+
}
|
|
28280
|
+
}
|
|
28281
|
+
function calculateDelay(retriesConsumed, options) {
|
|
28282
|
+
const attempt = Math.max(1, retriesConsumed + 1);
|
|
28283
|
+
const random = options.randomize ? Math.random() + 1 : 1;
|
|
28284
|
+
let timeout = Math.round(random * options.minTimeout * options.factor ** (attempt - 1));
|
|
28285
|
+
timeout = Math.min(timeout, options.maxTimeout);
|
|
28286
|
+
return timeout;
|
|
28287
|
+
}
|
|
28288
|
+
function calculateRemainingTime(start, max) {
|
|
28289
|
+
if (!Number.isFinite(max)) {
|
|
28290
|
+
return max;
|
|
28291
|
+
}
|
|
28292
|
+
return max - (performance.now() - start);
|
|
28293
|
+
}
|
|
28294
|
+
async function onAttemptFailure({ error, attemptNumber, retriesConsumed, startTime, options }) {
|
|
28295
|
+
const normalizedError = error instanceof Error ? error : new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
|
|
28296
|
+
if (normalizedError instanceof AbortError) {
|
|
28297
|
+
throw normalizedError.originalError;
|
|
28298
|
+
}
|
|
28299
|
+
const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
|
|
28300
|
+
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
28301
|
+
const context = Object.freeze({
|
|
28302
|
+
error: normalizedError,
|
|
28303
|
+
attemptNumber,
|
|
28304
|
+
retriesLeft,
|
|
28305
|
+
retriesConsumed
|
|
28306
|
+
});
|
|
28307
|
+
await options.onFailedAttempt(context);
|
|
28308
|
+
if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
|
|
28309
|
+
throw normalizedError;
|
|
28310
|
+
}
|
|
28311
|
+
const consumeRetry = await options.shouldConsumeRetry(context);
|
|
28312
|
+
const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
|
|
28313
|
+
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
28314
|
+
throw normalizedError;
|
|
28315
|
+
}
|
|
28316
|
+
if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
|
|
28317
|
+
if (consumeRetry) {
|
|
28318
|
+
throw normalizedError;
|
|
28319
|
+
}
|
|
28320
|
+
options.signal?.throwIfAborted();
|
|
28321
|
+
return false;
|
|
28322
|
+
}
|
|
28323
|
+
if (!await options.shouldRetry(context)) {
|
|
28324
|
+
throw normalizedError;
|
|
28325
|
+
}
|
|
28326
|
+
if (!consumeRetry) {
|
|
28327
|
+
options.signal?.throwIfAborted();
|
|
28328
|
+
return false;
|
|
28329
|
+
}
|
|
28330
|
+
const delayTime = calculateDelay(retriesConsumed, options);
|
|
28331
|
+
const finalDelay = Math.min(delayTime, remainingTime);
|
|
28332
|
+
if (finalDelay > 0) {
|
|
28333
|
+
await new Promise((resolve, reject) => {
|
|
28334
|
+
const onAbort = () => {
|
|
28335
|
+
clearTimeout(timeoutToken);
|
|
28336
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
28337
|
+
reject(options.signal.reason);
|
|
28338
|
+
};
|
|
28339
|
+
const timeoutToken = setTimeout(() => {
|
|
28340
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
28341
|
+
resolve();
|
|
28342
|
+
}, finalDelay);
|
|
28343
|
+
if (options.unref) {
|
|
28344
|
+
timeoutToken.unref?.();
|
|
28345
|
+
}
|
|
28346
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
28347
|
+
});
|
|
28348
|
+
}
|
|
28349
|
+
options.signal?.throwIfAborted();
|
|
28350
|
+
return true;
|
|
28351
|
+
}
|
|
28352
|
+
async function pRetry(input, options = {}) {
|
|
28353
|
+
options = { ...options };
|
|
28354
|
+
validateRetries(options.retries);
|
|
28355
|
+
if (Object.hasOwn(options, "forever")) {
|
|
28356
|
+
throw new Error("The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.");
|
|
28357
|
+
}
|
|
28358
|
+
options.retries ??= 10;
|
|
28359
|
+
options.factor ??= 2;
|
|
28360
|
+
options.minTimeout ??= 1000;
|
|
28361
|
+
options.maxTimeout ??= Number.POSITIVE_INFINITY;
|
|
28362
|
+
options.maxRetryTime ??= Number.POSITIVE_INFINITY;
|
|
28363
|
+
options.randomize ??= false;
|
|
28364
|
+
options.onFailedAttempt ??= () => {};
|
|
28365
|
+
options.shouldRetry ??= () => true;
|
|
28366
|
+
options.shouldConsumeRetry ??= () => true;
|
|
28367
|
+
validateNumberOption("factor", options.factor, {
|
|
28368
|
+
min: 0,
|
|
28369
|
+
allowInfinity: false
|
|
28370
|
+
});
|
|
28371
|
+
validateNumberOption("minTimeout", options.minTimeout, {
|
|
28372
|
+
min: 0,
|
|
28373
|
+
allowInfinity: false
|
|
28374
|
+
});
|
|
28375
|
+
validateNumberOption("maxTimeout", options.maxTimeout, {
|
|
28376
|
+
min: 0,
|
|
28377
|
+
allowInfinity: true
|
|
28378
|
+
});
|
|
28379
|
+
validateNumberOption("maxRetryTime", options.maxRetryTime, {
|
|
28380
|
+
min: 0,
|
|
28381
|
+
allowInfinity: true
|
|
28382
|
+
});
|
|
28383
|
+
if (!(options.factor > 0)) {
|
|
28384
|
+
options.factor = 1;
|
|
28385
|
+
}
|
|
28386
|
+
options.signal?.throwIfAborted();
|
|
28387
|
+
let attemptNumber = 0;
|
|
28388
|
+
let retriesConsumed = 0;
|
|
28389
|
+
const startTime = performance.now();
|
|
28390
|
+
while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
|
|
28391
|
+
attemptNumber++;
|
|
28392
|
+
try {
|
|
28393
|
+
options.signal?.throwIfAborted();
|
|
28394
|
+
const result = await input(attemptNumber);
|
|
28395
|
+
options.signal?.throwIfAborted();
|
|
28396
|
+
return result;
|
|
28397
|
+
} catch (error) {
|
|
28398
|
+
if (await onAttemptFailure({
|
|
28399
|
+
error,
|
|
28400
|
+
attemptNumber,
|
|
28401
|
+
retriesConsumed,
|
|
28402
|
+
startTime,
|
|
28403
|
+
options
|
|
28404
|
+
})) {
|
|
28405
|
+
retriesConsumed++;
|
|
28406
|
+
}
|
|
28407
|
+
}
|
|
28408
|
+
}
|
|
28409
|
+
throw new Error("Retry attempts exhausted without throwing an error.");
|
|
28410
|
+
}
|
|
28411
|
+
|
|
28504
28412
|
// ../../node_modules/langsmith/dist/utils/async_caller.js
|
|
28505
|
-
var import_p_retry = __toESM(require_p_retry(), 1);
|
|
28506
28413
|
var import_p_queue = __toESM(require_dist3(), 1);
|
|
28507
28414
|
var STATUS_RETRYABLE = [
|
|
28415
|
+
408,
|
|
28416
|
+
425,
|
|
28508
28417
|
429,
|
|
28509
28418
|
500,
|
|
28510
28419
|
502,
|
|
@@ -28574,14 +28483,14 @@ class AsyncCaller {
|
|
|
28574
28483
|
this.queueSizeBytes += sizeBytes;
|
|
28575
28484
|
}
|
|
28576
28485
|
const onFailedResponseHook = this.onFailedResponseHook;
|
|
28577
|
-
let promise = this.queue.add(() =>
|
|
28486
|
+
let promise = this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
|
|
28578
28487
|
if (error instanceof Error) {
|
|
28579
28488
|
throw error;
|
|
28580
28489
|
} else {
|
|
28581
28490
|
throw new Error(error);
|
|
28582
28491
|
}
|
|
28583
28492
|
}), {
|
|
28584
|
-
async onFailedAttempt(error) {
|
|
28493
|
+
async onFailedAttempt({ error }) {
|
|
28585
28494
|
if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.name === "TimeoutError" || error.message.startsWith("AbortError")) {
|
|
28586
28495
|
throw error;
|
|
28587
28496
|
}
|
|
@@ -32209,8 +32118,30 @@ var isTracingEnabled = (tracingEnabled) => {
|
|
|
32209
32118
|
|
|
32210
32119
|
// ../../node_modules/langsmith/dist/singletons/constants.js
|
|
32211
32120
|
var _LC_CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
|
|
32121
|
+
var _REPLICA_TRACE_ROOTS_KEY = Symbol.for("langsmith:replica_trace_roots");
|
|
32122
|
+
|
|
32123
|
+
// ../../node_modules/langsmith/dist/utils/context_vars.js
|
|
32124
|
+
function getContextVar(runTree, key) {
|
|
32125
|
+
if (_LC_CONTEXT_VARIABLES_KEY in runTree) {
|
|
32126
|
+
const contextVars = runTree[_LC_CONTEXT_VARIABLES_KEY];
|
|
32127
|
+
return contextVars[key];
|
|
32128
|
+
}
|
|
32129
|
+
return;
|
|
32130
|
+
}
|
|
32131
|
+
function setContextVar(runTree, key, value) {
|
|
32132
|
+
const contextVars = _LC_CONTEXT_VARIABLES_KEY in runTree ? runTree[_LC_CONTEXT_VARIABLES_KEY] : {};
|
|
32133
|
+
contextVars[key] = value;
|
|
32134
|
+
runTree[_LC_CONTEXT_VARIABLES_KEY] = contextVars;
|
|
32135
|
+
}
|
|
32212
32136
|
|
|
32213
32137
|
// ../../node_modules/langsmith/dist/run_trees.js
|
|
32138
|
+
var TIMESTAMP_LENGTH = 36;
|
|
32139
|
+
var UUID_NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
32140
|
+
function getReplicaKey(replica) {
|
|
32141
|
+
const sortedKeys = Object.keys(replica).sort();
|
|
32142
|
+
const keyData = sortedKeys.map((key) => `${key}:${replica[key] ?? ""}`).join("|");
|
|
32143
|
+
return v52(keyData, UUID_NAMESPACE_DNS);
|
|
32144
|
+
}
|
|
32214
32145
|
function stripNonAlphanumeric(input) {
|
|
32215
32146
|
return input.replace(/[-:.]/g, "");
|
|
32216
32147
|
}
|
|
@@ -32445,6 +32376,12 @@ class RunTree {
|
|
|
32445
32376
|
writable: true,
|
|
32446
32377
|
value: undefined
|
|
32447
32378
|
});
|
|
32379
|
+
Object.defineProperty(this, "distributedParentId", {
|
|
32380
|
+
enumerable: true,
|
|
32381
|
+
configurable: true,
|
|
32382
|
+
writable: true,
|
|
32383
|
+
value: undefined
|
|
32384
|
+
});
|
|
32448
32385
|
Object.defineProperty(this, "_serialized_start_time", {
|
|
32449
32386
|
enumerable: true,
|
|
32450
32387
|
configurable: true,
|
|
@@ -32475,20 +32412,12 @@ class RunTree {
|
|
|
32475
32412
|
if (!this.id) {
|
|
32476
32413
|
this.id = uuid7FromTime(this._serialized_start_time ?? this.start_time);
|
|
32477
32414
|
}
|
|
32478
|
-
if (config.id) {
|
|
32479
|
-
warnIfNotUuidV7(config.id, "run_id");
|
|
32480
|
-
}
|
|
32481
32415
|
if (!this.trace_id) {
|
|
32482
32416
|
if (this.parent_run) {
|
|
32483
32417
|
this.trace_id = this.parent_run.trace_id ?? this.id;
|
|
32484
32418
|
} else {
|
|
32485
32419
|
this.trace_id = this.id;
|
|
32486
32420
|
}
|
|
32487
|
-
} else if (config.trace_id) {
|
|
32488
|
-
warnIfNotUuidV7(config.trace_id, "trace_id");
|
|
32489
|
-
}
|
|
32490
|
-
if (config.parent_run_id) {
|
|
32491
|
-
warnIfNotUuidV7(config.parent_run_id, "parent_run_id");
|
|
32492
32421
|
}
|
|
32493
32422
|
this.replicas = _ensureWriteReplicas(this.replicas);
|
|
32494
32423
|
if (!this.dotted_order) {
|
|
@@ -32535,11 +32464,16 @@ class RunTree {
|
|
|
32535
32464
|
}
|
|
32536
32465
|
createChild(config) {
|
|
32537
32466
|
const child_execution_order = this.child_execution_order + 1;
|
|
32467
|
+
const inheritedReplicas = this.replicas?.map((replica) => {
|
|
32468
|
+
const { reroot, ...rest } = replica;
|
|
32469
|
+
return rest;
|
|
32470
|
+
});
|
|
32471
|
+
const childReplicas = config.replicas ?? inheritedReplicas;
|
|
32538
32472
|
const child = new RunTree({
|
|
32539
32473
|
...config,
|
|
32540
32474
|
parent_run: this,
|
|
32541
32475
|
project_name: this.project_name,
|
|
32542
|
-
replicas:
|
|
32476
|
+
replicas: childReplicas,
|
|
32543
32477
|
client: this.client,
|
|
32544
32478
|
tracingEnabled: this.tracingEnabled,
|
|
32545
32479
|
execution_order: child_execution_order,
|
|
@@ -32623,10 +32557,126 @@ class RunTree {
|
|
|
32623
32557
|
events: run.events
|
|
32624
32558
|
};
|
|
32625
32559
|
}
|
|
32626
|
-
|
|
32560
|
+
_sliceParentId(parentId, run) {
|
|
32561
|
+
if (run.dotted_order) {
|
|
32562
|
+
const segs = run.dotted_order.split(".");
|
|
32563
|
+
let startIdx = null;
|
|
32564
|
+
for (let idx = 0;idx < segs.length; idx++) {
|
|
32565
|
+
const segId = segs[idx].slice(-TIMESTAMP_LENGTH);
|
|
32566
|
+
if (segId === parentId) {
|
|
32567
|
+
startIdx = idx;
|
|
32568
|
+
break;
|
|
32569
|
+
}
|
|
32570
|
+
}
|
|
32571
|
+
if (startIdx !== null) {
|
|
32572
|
+
const trimmedSegs = segs.slice(startIdx + 1);
|
|
32573
|
+
run.dotted_order = trimmedSegs.join(".");
|
|
32574
|
+
if (trimmedSegs.length > 0) {
|
|
32575
|
+
run.trace_id = trimmedSegs[0].slice(-TIMESTAMP_LENGTH);
|
|
32576
|
+
} else {
|
|
32577
|
+
run.trace_id = run.id;
|
|
32578
|
+
}
|
|
32579
|
+
}
|
|
32580
|
+
}
|
|
32581
|
+
if (run.parent_run_id === parentId) {
|
|
32582
|
+
run.parent_run_id = undefined;
|
|
32583
|
+
}
|
|
32584
|
+
}
|
|
32585
|
+
_setReplicaTraceRoot(replicaKey, traceRootId) {
|
|
32586
|
+
const replicaTraceRoots = getContextVar(this, _REPLICA_TRACE_ROOTS_KEY) ?? {};
|
|
32587
|
+
replicaTraceRoots[replicaKey] = traceRootId;
|
|
32588
|
+
setContextVar(this, _REPLICA_TRACE_ROOTS_KEY, replicaTraceRoots);
|
|
32589
|
+
for (const child of this.child_runs) {
|
|
32590
|
+
child._setReplicaTraceRoot(replicaKey, traceRootId);
|
|
32591
|
+
}
|
|
32592
|
+
}
|
|
32593
|
+
_remapForProject(params) {
|
|
32594
|
+
const { projectName, runtimeEnv, excludeChildRuns = true, reroot = false, distributedParentId, apiUrl, apiKey, workspaceId } = params;
|
|
32627
32595
|
const baseRun = this._convertToCreate(this, runtimeEnv, excludeChildRuns);
|
|
32596
|
+
if (projectName === this.project_name) {
|
|
32597
|
+
return {
|
|
32598
|
+
...baseRun,
|
|
32599
|
+
session_name: projectName
|
|
32600
|
+
};
|
|
32601
|
+
}
|
|
32602
|
+
if (reroot) {
|
|
32603
|
+
if (distributedParentId) {
|
|
32604
|
+
this._sliceParentId(distributedParentId, baseRun);
|
|
32605
|
+
} else {
|
|
32606
|
+
baseRun.parent_run_id = undefined;
|
|
32607
|
+
if (baseRun.dotted_order) {
|
|
32608
|
+
const segs = baseRun.dotted_order.split(".");
|
|
32609
|
+
if (segs.length > 0) {
|
|
32610
|
+
baseRun.dotted_order = segs[segs.length - 1];
|
|
32611
|
+
baseRun.trace_id = baseRun.id;
|
|
32612
|
+
}
|
|
32613
|
+
}
|
|
32614
|
+
}
|
|
32615
|
+
const replicaKey = getReplicaKey({
|
|
32616
|
+
projectName,
|
|
32617
|
+
apiUrl,
|
|
32618
|
+
apiKey,
|
|
32619
|
+
workspaceId
|
|
32620
|
+
});
|
|
32621
|
+
this._setReplicaTraceRoot(replicaKey, baseRun.id);
|
|
32622
|
+
}
|
|
32623
|
+
let ancestorRerootedTraceId;
|
|
32624
|
+
if (!reroot) {
|
|
32625
|
+
const replicaTraceRoots = getContextVar(this, _REPLICA_TRACE_ROOTS_KEY) ?? {};
|
|
32626
|
+
const replicaKey = getReplicaKey({
|
|
32627
|
+
projectName,
|
|
32628
|
+
apiUrl,
|
|
32629
|
+
apiKey,
|
|
32630
|
+
workspaceId
|
|
32631
|
+
});
|
|
32632
|
+
ancestorRerootedTraceId = replicaTraceRoots[replicaKey];
|
|
32633
|
+
if (ancestorRerootedTraceId) {
|
|
32634
|
+
baseRun.trace_id = ancestorRerootedTraceId;
|
|
32635
|
+
if (baseRun.dotted_order) {
|
|
32636
|
+
const segs = baseRun.dotted_order.split(".");
|
|
32637
|
+
let rootIdx = null;
|
|
32638
|
+
for (let idx = 0;idx < segs.length; idx++) {
|
|
32639
|
+
const segId = segs[idx].slice(-TIMESTAMP_LENGTH);
|
|
32640
|
+
if (segId === ancestorRerootedTraceId) {
|
|
32641
|
+
rootIdx = idx;
|
|
32642
|
+
break;
|
|
32643
|
+
}
|
|
32644
|
+
}
|
|
32645
|
+
if (rootIdx !== null) {
|
|
32646
|
+
const trimmedSegs = segs.slice(rootIdx);
|
|
32647
|
+
baseRun.dotted_order = trimmedSegs.join(".");
|
|
32648
|
+
}
|
|
32649
|
+
}
|
|
32650
|
+
}
|
|
32651
|
+
}
|
|
32652
|
+
const oldId = baseRun.id;
|
|
32653
|
+
const newId = v52(`${oldId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
32654
|
+
let newTraceId;
|
|
32655
|
+
if (baseRun.trace_id) {
|
|
32656
|
+
newTraceId = v52(`${baseRun.trace_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
32657
|
+
} else {
|
|
32658
|
+
newTraceId = newId;
|
|
32659
|
+
}
|
|
32660
|
+
let newParentId;
|
|
32661
|
+
if (baseRun.parent_run_id) {
|
|
32662
|
+
newParentId = v52(`${baseRun.parent_run_id}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
32663
|
+
}
|
|
32664
|
+
let newDottedOrder;
|
|
32665
|
+
if (baseRun.dotted_order) {
|
|
32666
|
+
const segs = baseRun.dotted_order.split(".");
|
|
32667
|
+
const remappedSegs = segs.map((seg) => {
|
|
32668
|
+
const segId = seg.slice(-TIMESTAMP_LENGTH);
|
|
32669
|
+
const remappedId = v52(`${segId}:${projectName}`, UUID_NAMESPACE_DNS);
|
|
32670
|
+
return seg.slice(0, -TIMESTAMP_LENGTH) + remappedId;
|
|
32671
|
+
});
|
|
32672
|
+
newDottedOrder = remappedSegs.join(".");
|
|
32673
|
+
}
|
|
32628
32674
|
return {
|
|
32629
32675
|
...baseRun,
|
|
32676
|
+
id: newId,
|
|
32677
|
+
trace_id: newTraceId,
|
|
32678
|
+
parent_run_id: newParentId,
|
|
32679
|
+
dotted_order: newDottedOrder,
|
|
32630
32680
|
session_name: projectName
|
|
32631
32681
|
};
|
|
32632
32682
|
}
|
|
@@ -32634,8 +32684,17 @@ class RunTree {
|
|
|
32634
32684
|
try {
|
|
32635
32685
|
const runtimeEnv = getRuntimeEnvironment2();
|
|
32636
32686
|
if (this.replicas && this.replicas.length > 0) {
|
|
32637
|
-
for (const { projectName, apiKey, apiUrl, workspaceId } of this.replicas) {
|
|
32638
|
-
const runCreate = this._remapForProject(
|
|
32687
|
+
for (const { projectName, apiKey, apiUrl, workspaceId, reroot } of this.replicas) {
|
|
32688
|
+
const runCreate = this._remapForProject({
|
|
32689
|
+
projectName: projectName ?? this.project_name,
|
|
32690
|
+
runtimeEnv,
|
|
32691
|
+
excludeChildRuns: true,
|
|
32692
|
+
reroot,
|
|
32693
|
+
distributedParentId: this.distributedParentId,
|
|
32694
|
+
apiUrl,
|
|
32695
|
+
apiKey,
|
|
32696
|
+
workspaceId
|
|
32697
|
+
});
|
|
32639
32698
|
await this.client.createRun(runCreate, {
|
|
32640
32699
|
apiKey,
|
|
32641
32700
|
apiUrl,
|
|
@@ -32658,8 +32717,17 @@ class RunTree {
|
|
|
32658
32717
|
}
|
|
32659
32718
|
async patchRun(options) {
|
|
32660
32719
|
if (this.replicas && this.replicas.length > 0) {
|
|
32661
|
-
for (const { projectName, apiKey, apiUrl, workspaceId, updates } of this.replicas) {
|
|
32662
|
-
const runData = this._remapForProject(
|
|
32720
|
+
for (const { projectName, apiKey, apiUrl, workspaceId, updates, reroot } of this.replicas) {
|
|
32721
|
+
const runData = this._remapForProject({
|
|
32722
|
+
projectName: projectName ?? this.project_name,
|
|
32723
|
+
runtimeEnv: undefined,
|
|
32724
|
+
excludeChildRuns: true,
|
|
32725
|
+
reroot,
|
|
32726
|
+
distributedParentId: this.distributedParentId,
|
|
32727
|
+
apiUrl,
|
|
32728
|
+
apiKey,
|
|
32729
|
+
workspaceId
|
|
32730
|
+
});
|
|
32663
32731
|
const updatePayload = {
|
|
32664
32732
|
id: runData.id,
|
|
32665
32733
|
name: runData.name,
|
|
@@ -32811,7 +32879,9 @@ class RunTree {
|
|
|
32811
32879
|
config.project_name = baggage.project_name;
|
|
32812
32880
|
config.replicas = baggage.replicas;
|
|
32813
32881
|
}
|
|
32814
|
-
|
|
32882
|
+
const runTree = new RunTree(config);
|
|
32883
|
+
runTree.distributedParentId = runTree.id;
|
|
32884
|
+
return runTree;
|
|
32815
32885
|
}
|
|
32816
32886
|
toHeaders(headers) {
|
|
32817
32887
|
const result = {
|
|
@@ -35755,8 +35825,197 @@ var EventStreamCallbackHandler = class extends BaseTracer {
|
|
|
35755
35825
|
}
|
|
35756
35826
|
};
|
|
35757
35827
|
|
|
35828
|
+
// ../../node_modules/is-network-error/index.js
|
|
35829
|
+
var objectToString2 = Object.prototype.toString;
|
|
35830
|
+
var isError2 = (value) => objectToString2.call(value) === "[object Error]";
|
|
35831
|
+
var errorMessages2 = new Set([
|
|
35832
|
+
"network error",
|
|
35833
|
+
"Failed to fetch",
|
|
35834
|
+
"NetworkError when attempting to fetch resource.",
|
|
35835
|
+
"The Internet connection appears to be offline.",
|
|
35836
|
+
"Network request failed",
|
|
35837
|
+
"fetch failed",
|
|
35838
|
+
"terminated",
|
|
35839
|
+
" A network error occurred.",
|
|
35840
|
+
"Network connection lost"
|
|
35841
|
+
]);
|
|
35842
|
+
function isNetworkError2(error) {
|
|
35843
|
+
const isValid = error && isError2(error) && error.name === "TypeError" && typeof error.message === "string";
|
|
35844
|
+
if (!isValid) {
|
|
35845
|
+
return false;
|
|
35846
|
+
}
|
|
35847
|
+
const { message, stack } = error;
|
|
35848
|
+
if (message === "Load failed") {
|
|
35849
|
+
return stack === undefined || "__sentry_captured__" in error;
|
|
35850
|
+
}
|
|
35851
|
+
if (message.startsWith("error sending request for url")) {
|
|
35852
|
+
return true;
|
|
35853
|
+
}
|
|
35854
|
+
return errorMessages2.has(message);
|
|
35855
|
+
}
|
|
35856
|
+
|
|
35857
|
+
// ../../node_modules/p-retry/index.js
|
|
35858
|
+
function validateRetries2(retries) {
|
|
35859
|
+
if (typeof retries === "number") {
|
|
35860
|
+
if (retries < 0) {
|
|
35861
|
+
throw new TypeError("Expected `retries` to be a non-negative number.");
|
|
35862
|
+
}
|
|
35863
|
+
if (Number.isNaN(retries)) {
|
|
35864
|
+
throw new TypeError("Expected `retries` to be a valid number or Infinity, got NaN.");
|
|
35865
|
+
}
|
|
35866
|
+
} else if (retries !== undefined) {
|
|
35867
|
+
throw new TypeError("Expected `retries` to be a number or Infinity.");
|
|
35868
|
+
}
|
|
35869
|
+
}
|
|
35870
|
+
function validateNumberOption2(name, value, { min = 0, allowInfinity = false } = {}) {
|
|
35871
|
+
if (value === undefined) {
|
|
35872
|
+
return;
|
|
35873
|
+
}
|
|
35874
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
35875
|
+
throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? " or Infinity" : ""}.`);
|
|
35876
|
+
}
|
|
35877
|
+
if (!allowInfinity && !Number.isFinite(value)) {
|
|
35878
|
+
throw new TypeError(`Expected \`${name}\` to be a finite number.`);
|
|
35879
|
+
}
|
|
35880
|
+
if (value < min) {
|
|
35881
|
+
throw new TypeError(`Expected \`${name}\` to be ≥ ${min}.`);
|
|
35882
|
+
}
|
|
35883
|
+
}
|
|
35884
|
+
|
|
35885
|
+
class AbortError2 extends Error {
|
|
35886
|
+
constructor(message) {
|
|
35887
|
+
super();
|
|
35888
|
+
if (message instanceof Error) {
|
|
35889
|
+
this.originalError = message;
|
|
35890
|
+
({ message } = message);
|
|
35891
|
+
} else {
|
|
35892
|
+
this.originalError = new Error(message);
|
|
35893
|
+
this.originalError.stack = this.stack;
|
|
35894
|
+
}
|
|
35895
|
+
this.name = "AbortError";
|
|
35896
|
+
this.message = message;
|
|
35897
|
+
}
|
|
35898
|
+
}
|
|
35899
|
+
function calculateDelay2(retriesConsumed, options) {
|
|
35900
|
+
const attempt = Math.max(1, retriesConsumed + 1);
|
|
35901
|
+
const random = options.randomize ? Math.random() + 1 : 1;
|
|
35902
|
+
let timeout = Math.round(random * options.minTimeout * options.factor ** (attempt - 1));
|
|
35903
|
+
timeout = Math.min(timeout, options.maxTimeout);
|
|
35904
|
+
return timeout;
|
|
35905
|
+
}
|
|
35906
|
+
function calculateRemainingTime2(start, max) {
|
|
35907
|
+
if (!Number.isFinite(max)) {
|
|
35908
|
+
return max;
|
|
35909
|
+
}
|
|
35910
|
+
return max - (performance.now() - start);
|
|
35911
|
+
}
|
|
35912
|
+
async function onAttemptFailure2({ error, attemptNumber, retriesConsumed, startTime, options }) {
|
|
35913
|
+
const normalizedError = error instanceof Error ? error : new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
|
|
35914
|
+
if (normalizedError instanceof AbortError2) {
|
|
35915
|
+
throw normalizedError.originalError;
|
|
35916
|
+
}
|
|
35917
|
+
const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
|
|
35918
|
+
const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
|
|
35919
|
+
const context = Object.freeze({
|
|
35920
|
+
error: normalizedError,
|
|
35921
|
+
attemptNumber,
|
|
35922
|
+
retriesLeft,
|
|
35923
|
+
retriesConsumed
|
|
35924
|
+
});
|
|
35925
|
+
await options.onFailedAttempt(context);
|
|
35926
|
+
if (calculateRemainingTime2(startTime, maxRetryTime) <= 0) {
|
|
35927
|
+
throw normalizedError;
|
|
35928
|
+
}
|
|
35929
|
+
const consumeRetry = await options.shouldConsumeRetry(context);
|
|
35930
|
+
const remainingTime = calculateRemainingTime2(startTime, maxRetryTime);
|
|
35931
|
+
if (remainingTime <= 0 || retriesLeft <= 0) {
|
|
35932
|
+
throw normalizedError;
|
|
35933
|
+
}
|
|
35934
|
+
if (normalizedError instanceof TypeError && !isNetworkError2(normalizedError)) {
|
|
35935
|
+
if (consumeRetry) {
|
|
35936
|
+
throw normalizedError;
|
|
35937
|
+
}
|
|
35938
|
+
options.signal?.throwIfAborted();
|
|
35939
|
+
return false;
|
|
35940
|
+
}
|
|
35941
|
+
if (!await options.shouldRetry(context)) {
|
|
35942
|
+
throw normalizedError;
|
|
35943
|
+
}
|
|
35944
|
+
if (!consumeRetry) {
|
|
35945
|
+
options.signal?.throwIfAborted();
|
|
35946
|
+
return false;
|
|
35947
|
+
}
|
|
35948
|
+
const delayTime = calculateDelay2(retriesConsumed, options);
|
|
35949
|
+
const finalDelay = Math.min(delayTime, remainingTime);
|
|
35950
|
+
if (finalDelay > 0) {
|
|
35951
|
+
await new Promise((resolve, reject) => {
|
|
35952
|
+
const onAbort = () => {
|
|
35953
|
+
clearTimeout(timeoutToken);
|
|
35954
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
35955
|
+
reject(options.signal.reason);
|
|
35956
|
+
};
|
|
35957
|
+
const timeoutToken = setTimeout(() => {
|
|
35958
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
35959
|
+
resolve();
|
|
35960
|
+
}, finalDelay);
|
|
35961
|
+
if (options.unref) {
|
|
35962
|
+
timeoutToken.unref?.();
|
|
35963
|
+
}
|
|
35964
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
35965
|
+
});
|
|
35966
|
+
}
|
|
35967
|
+
options.signal?.throwIfAborted();
|
|
35968
|
+
return true;
|
|
35969
|
+
}
|
|
35970
|
+
async function pRetry2(input, options = {}) {
|
|
35971
|
+
options = { ...options };
|
|
35972
|
+
validateRetries2(options.retries);
|
|
35973
|
+
if (Object.hasOwn(options, "forever")) {
|
|
35974
|
+
throw new Error("The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.");
|
|
35975
|
+
}
|
|
35976
|
+
options.retries ??= 10;
|
|
35977
|
+
options.factor ??= 2;
|
|
35978
|
+
options.minTimeout ??= 1000;
|
|
35979
|
+
options.maxTimeout ??= Number.POSITIVE_INFINITY;
|
|
35980
|
+
options.maxRetryTime ??= Number.POSITIVE_INFINITY;
|
|
35981
|
+
options.randomize ??= false;
|
|
35982
|
+
options.onFailedAttempt ??= () => {};
|
|
35983
|
+
options.shouldRetry ??= () => true;
|
|
35984
|
+
options.shouldConsumeRetry ??= () => true;
|
|
35985
|
+
validateNumberOption2("factor", options.factor, { min: 0, allowInfinity: false });
|
|
35986
|
+
validateNumberOption2("minTimeout", options.minTimeout, { min: 0, allowInfinity: false });
|
|
35987
|
+
validateNumberOption2("maxTimeout", options.maxTimeout, { min: 0, allowInfinity: true });
|
|
35988
|
+
validateNumberOption2("maxRetryTime", options.maxRetryTime, { min: 0, allowInfinity: true });
|
|
35989
|
+
if (!(options.factor > 0)) {
|
|
35990
|
+
options.factor = 1;
|
|
35991
|
+
}
|
|
35992
|
+
options.signal?.throwIfAborted();
|
|
35993
|
+
let attemptNumber = 0;
|
|
35994
|
+
let retriesConsumed = 0;
|
|
35995
|
+
const startTime = performance.now();
|
|
35996
|
+
while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
|
|
35997
|
+
attemptNumber++;
|
|
35998
|
+
try {
|
|
35999
|
+
options.signal?.throwIfAborted();
|
|
36000
|
+
const result = await input(attemptNumber);
|
|
36001
|
+
options.signal?.throwIfAborted();
|
|
36002
|
+
return result;
|
|
36003
|
+
} catch (error) {
|
|
36004
|
+
if (await onAttemptFailure2({
|
|
36005
|
+
error,
|
|
36006
|
+
attemptNumber,
|
|
36007
|
+
retriesConsumed,
|
|
36008
|
+
startTime,
|
|
36009
|
+
options
|
|
36010
|
+
})) {
|
|
36011
|
+
retriesConsumed++;
|
|
36012
|
+
}
|
|
36013
|
+
}
|
|
36014
|
+
}
|
|
36015
|
+
throw new Error("Retry attempts exhausted without throwing an error.");
|
|
36016
|
+
}
|
|
36017
|
+
|
|
35758
36018
|
// ../../node_modules/@langchain/core/dist/utils/async_caller.js
|
|
35759
|
-
var import_p_retry2 = __toESM(require_p_retry(), 1);
|
|
35760
36019
|
var import_p_queue3 = __toESM(require_dist3(), 1);
|
|
35761
36020
|
var async_caller_exports = {};
|
|
35762
36021
|
__export(async_caller_exports, { AsyncCaller: () => AsyncCaller2 });
|
|
@@ -35798,13 +36057,13 @@ var AsyncCaller2 = class {
|
|
|
35798
36057
|
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
35799
36058
|
}
|
|
35800
36059
|
call(callable, ...args) {
|
|
35801
|
-
return this.queue.add(() =>
|
|
36060
|
+
return this.queue.add(() => pRetry2(() => callable(...args).catch((error) => {
|
|
35802
36061
|
if (error instanceof Error)
|
|
35803
36062
|
throw error;
|
|
35804
36063
|
else
|
|
35805
36064
|
throw new Error(error);
|
|
35806
36065
|
}), {
|
|
35807
|
-
onFailedAttempt: this.onFailedAttempt,
|
|
36066
|
+
onFailedAttempt: ({ error }) => this.onFailedAttempt?.(error),
|
|
35808
36067
|
retries: this.maxRetries,
|
|
35809
36068
|
randomize: true
|
|
35810
36069
|
}), { throwOnTimeout: true });
|
|
@@ -38762,7 +39021,6 @@ async function* consumeAsyncIterableInContext(context, iter) {
|
|
|
38762
39021
|
}
|
|
38763
39022
|
|
|
38764
39023
|
// ../../node_modules/@langchain/core/dist/runnables/base.js
|
|
38765
|
-
var import_p_retry3 = __toESM(require_p_retry(), 1);
|
|
38766
39024
|
import { z } from "zod/v3";
|
|
38767
39025
|
function _coerceToDict2(value, defaultKey) {
|
|
38768
39026
|
return value && !Array.isArray(value) && !(value instanceof Date) && typeof value === "object" ? value : { [defaultKey]: value };
|
|
@@ -39359,8 +39617,8 @@ var RunnableRetry = class extends RunnableBinding {
|
|
|
39359
39617
|
return patchConfig(config, { callbacks: runManager?.getChild(tag) });
|
|
39360
39618
|
}
|
|
39361
39619
|
async _invoke(input, config, runManager) {
|
|
39362
|
-
return
|
|
39363
|
-
onFailedAttempt: (error) => this.onFailedAttempt(error, input),
|
|
39620
|
+
return pRetry2((attemptNumber) => super.invoke(input, this._patchConfigForRetry(attemptNumber, config, runManager)), {
|
|
39621
|
+
onFailedAttempt: ({ error }) => this.onFailedAttempt(error, input),
|
|
39364
39622
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
39365
39623
|
randomize: true
|
|
39366
39624
|
});
|
|
@@ -39371,7 +39629,7 @@ var RunnableRetry = class extends RunnableBinding {
|
|
|
39371
39629
|
async _batch(inputs, configs, runManagers, batchOptions) {
|
|
39372
39630
|
const resultsMap = {};
|
|
39373
39631
|
try {
|
|
39374
|
-
await
|
|
39632
|
+
await pRetry2(async (attemptNumber) => {
|
|
39375
39633
|
const remainingIndexes = inputs.map((_, i) => i).filter((i) => resultsMap[i.toString()] === undefined || resultsMap[i.toString()] instanceof Error);
|
|
39376
39634
|
const remainingInputs = remainingIndexes.map((i) => inputs[i]);
|
|
39377
39635
|
const patchedConfigs = remainingIndexes.map((i) => this._patchConfigForRetry(attemptNumber, configs?.[i], runManagers?.[i]));
|
|
@@ -39395,7 +39653,7 @@ var RunnableRetry = class extends RunnableBinding {
|
|
|
39395
39653
|
throw firstException;
|
|
39396
39654
|
return results;
|
|
39397
39655
|
}, {
|
|
39398
|
-
onFailedAttempt: (error) => this.onFailedAttempt(error, error.input),
|
|
39656
|
+
onFailedAttempt: ({ error }) => this.onFailedAttempt(error, error.input),
|
|
39399
39657
|
retries: Math.max(this.maxAttemptNumber - 1, 0),
|
|
39400
39658
|
randomize: true
|
|
39401
39659
|
});
|
|
@@ -50067,5 +50325,5 @@ export {
|
|
|
50067
50325
|
AgentRuntime
|
|
50068
50326
|
};
|
|
50069
50327
|
|
|
50070
|
-
//# debugId=
|
|
50328
|
+
//# debugId=1AE99B04D756580C64756E2164756E21
|
|
50071
50329
|
//# sourceMappingURL=index.node.js.map
|