@elizaos/core 1.7.1-alpha.9 → 1.7.1-beta.0
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 +89 -89
- package/dist/browser/index.browser.js.map +15 -13
- package/dist/node/index.node.js +570 -266
- package/dist/node/index.node.js.map +15 -13
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/services/default-message-service.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/node/index.node.js
CHANGED
|
@@ -5053,11 +5053,11 @@ var require_ast = __commonJS((exports, module) => {
|
|
|
5053
5053
|
helperExpression: function helperExpression(node) {
|
|
5054
5054
|
return node.type === "SubExpression" || (node.type === "MustacheStatement" || node.type === "BlockStatement") && !!(node.params && node.params.length || node.hash);
|
|
5055
5055
|
},
|
|
5056
|
-
scopedId: function scopedId(
|
|
5057
|
-
return /^\.|this\b/.test(
|
|
5056
|
+
scopedId: function scopedId(path2) {
|
|
5057
|
+
return /^\.|this\b/.test(path2.original);
|
|
5058
5058
|
},
|
|
5059
|
-
simpleId: function simpleId(
|
|
5060
|
-
return
|
|
5059
|
+
simpleId: function simpleId(path2) {
|
|
5060
|
+
return path2.parts.length === 1 && !AST.helpers.scopedId(path2) && !path2.depth;
|
|
5061
5061
|
}
|
|
5062
5062
|
}
|
|
5063
5063
|
};
|
|
@@ -6117,12 +6117,12 @@ var require_helpers2 = __commonJS((exports) => {
|
|
|
6117
6117
|
loc
|
|
6118
6118
|
};
|
|
6119
6119
|
}
|
|
6120
|
-
function prepareMustache(
|
|
6120
|
+
function prepareMustache(path2, params, hash, open, strip, locInfo) {
|
|
6121
6121
|
var escapeFlag = open.charAt(3) || open.charAt(2), escaped = escapeFlag !== "{" && escapeFlag !== "&";
|
|
6122
6122
|
var decorator = /\*/.test(open);
|
|
6123
6123
|
return {
|
|
6124
6124
|
type: decorator ? "Decorator" : "MustacheStatement",
|
|
6125
|
-
path,
|
|
6125
|
+
path: path2,
|
|
6126
6126
|
params,
|
|
6127
6127
|
hash,
|
|
6128
6128
|
escaped,
|
|
@@ -6386,9 +6386,9 @@ var require_compiler = __commonJS((exports) => {
|
|
|
6386
6386
|
},
|
|
6387
6387
|
DecoratorBlock: function DecoratorBlock(decorator) {
|
|
6388
6388
|
var program = decorator.program && this.compileProgram(decorator.program);
|
|
6389
|
-
var params = this.setupFullMustacheParams(decorator, program, undefined),
|
|
6389
|
+
var params = this.setupFullMustacheParams(decorator, program, undefined), path2 = decorator.path;
|
|
6390
6390
|
this.useDecorators = true;
|
|
6391
|
-
this.opcode("registerDecorator", params.length,
|
|
6391
|
+
this.opcode("registerDecorator", params.length, path2.original);
|
|
6392
6392
|
},
|
|
6393
6393
|
PartialStatement: function PartialStatement(partial) {
|
|
6394
6394
|
this.usePartial = true;
|
|
@@ -6451,46 +6451,46 @@ var require_compiler = __commonJS((exports) => {
|
|
|
6451
6451
|
}
|
|
6452
6452
|
},
|
|
6453
6453
|
ambiguousSexpr: function ambiguousSexpr(sexpr, program, inverse) {
|
|
6454
|
-
var
|
|
6455
|
-
this.opcode("getContext",
|
|
6454
|
+
var path2 = sexpr.path, name = path2.parts[0], isBlock = program != null || inverse != null;
|
|
6455
|
+
this.opcode("getContext", path2.depth);
|
|
6456
6456
|
this.opcode("pushProgram", program);
|
|
6457
6457
|
this.opcode("pushProgram", inverse);
|
|
6458
|
-
|
|
6459
|
-
this.accept(
|
|
6458
|
+
path2.strict = true;
|
|
6459
|
+
this.accept(path2);
|
|
6460
6460
|
this.opcode("invokeAmbiguous", name, isBlock);
|
|
6461
6461
|
},
|
|
6462
6462
|
simpleSexpr: function simpleSexpr(sexpr) {
|
|
6463
|
-
var
|
|
6464
|
-
|
|
6465
|
-
this.accept(
|
|
6463
|
+
var path2 = sexpr.path;
|
|
6464
|
+
path2.strict = true;
|
|
6465
|
+
this.accept(path2);
|
|
6466
6466
|
this.opcode("resolvePossibleLambda");
|
|
6467
6467
|
},
|
|
6468
6468
|
helperSexpr: function helperSexpr(sexpr, program, inverse) {
|
|
6469
|
-
var params = this.setupFullMustacheParams(sexpr, program, inverse),
|
|
6469
|
+
var params = this.setupFullMustacheParams(sexpr, program, inverse), path2 = sexpr.path, name = path2.parts[0];
|
|
6470
6470
|
if (this.options.knownHelpers[name]) {
|
|
6471
6471
|
this.opcode("invokeKnownHelper", params.length, name);
|
|
6472
6472
|
} else if (this.options.knownHelpersOnly) {
|
|
6473
6473
|
throw new _exception2["default"]("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr);
|
|
6474
6474
|
} else {
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
this.accept(
|
|
6478
|
-
this.opcode("invokeHelper", params.length,
|
|
6475
|
+
path2.strict = true;
|
|
6476
|
+
path2.falsy = true;
|
|
6477
|
+
this.accept(path2);
|
|
6478
|
+
this.opcode("invokeHelper", params.length, path2.original, _ast2["default"].helpers.simpleId(path2));
|
|
6479
6479
|
}
|
|
6480
6480
|
},
|
|
6481
|
-
PathExpression: function PathExpression(
|
|
6482
|
-
this.addDepth(
|
|
6483
|
-
this.opcode("getContext",
|
|
6484
|
-
var name =
|
|
6481
|
+
PathExpression: function PathExpression(path2) {
|
|
6482
|
+
this.addDepth(path2.depth);
|
|
6483
|
+
this.opcode("getContext", path2.depth);
|
|
6484
|
+
var name = path2.parts[0], scoped = _ast2["default"].helpers.scopedId(path2), blockParamId = !path2.depth && !scoped && this.blockParamIndex(name);
|
|
6485
6485
|
if (blockParamId) {
|
|
6486
|
-
this.opcode("lookupBlockParam", blockParamId,
|
|
6486
|
+
this.opcode("lookupBlockParam", blockParamId, path2.parts);
|
|
6487
6487
|
} else if (!name) {
|
|
6488
6488
|
this.opcode("pushContext");
|
|
6489
|
-
} else if (
|
|
6489
|
+
} else if (path2.data) {
|
|
6490
6490
|
this.options.data = true;
|
|
6491
|
-
this.opcode("lookupData",
|
|
6491
|
+
this.opcode("lookupData", path2.depth, path2.parts, path2.strict);
|
|
6492
6492
|
} else {
|
|
6493
|
-
this.opcode("lookupOnContext",
|
|
6493
|
+
this.opcode("lookupOnContext", path2.parts, path2.falsy, path2.strict, scoped);
|
|
6494
6494
|
}
|
|
6495
6495
|
},
|
|
6496
6496
|
StringLiteral: function StringLiteral(string) {
|
|
@@ -6834,16 +6834,16 @@ var require_util = __commonJS((exports) => {
|
|
|
6834
6834
|
}
|
|
6835
6835
|
exports.urlGenerate = urlGenerate;
|
|
6836
6836
|
function normalize(aPath) {
|
|
6837
|
-
var
|
|
6837
|
+
var path2 = aPath;
|
|
6838
6838
|
var url = urlParse(aPath);
|
|
6839
6839
|
if (url) {
|
|
6840
6840
|
if (!url.path) {
|
|
6841
6841
|
return aPath;
|
|
6842
6842
|
}
|
|
6843
|
-
|
|
6843
|
+
path2 = url.path;
|
|
6844
6844
|
}
|
|
6845
|
-
var isAbsolute = exports.isAbsolute(
|
|
6846
|
-
var parts =
|
|
6845
|
+
var isAbsolute = exports.isAbsolute(path2);
|
|
6846
|
+
var parts = path2.split(/\/+/);
|
|
6847
6847
|
for (var part, up = 0, i = parts.length - 1;i >= 0; i--) {
|
|
6848
6848
|
part = parts[i];
|
|
6849
6849
|
if (part === ".") {
|
|
@@ -6860,15 +6860,15 @@ var require_util = __commonJS((exports) => {
|
|
|
6860
6860
|
}
|
|
6861
6861
|
}
|
|
6862
6862
|
}
|
|
6863
|
-
|
|
6864
|
-
if (
|
|
6865
|
-
|
|
6863
|
+
path2 = parts.join("/");
|
|
6864
|
+
if (path2 === "") {
|
|
6865
|
+
path2 = isAbsolute ? "/" : ".";
|
|
6866
6866
|
}
|
|
6867
6867
|
if (url) {
|
|
6868
|
-
url.path =
|
|
6868
|
+
url.path = path2;
|
|
6869
6869
|
return urlGenerate(url);
|
|
6870
6870
|
}
|
|
6871
|
-
return
|
|
6871
|
+
return path2;
|
|
6872
6872
|
}
|
|
6873
6873
|
exports.normalize = normalize;
|
|
6874
6874
|
function join(aRoot, aPath) {
|
|
@@ -9425,8 +9425,8 @@ var require_printer = __commonJS((exports) => {
|
|
|
9425
9425
|
return this.accept(sexpr.path) + " " + params + hash;
|
|
9426
9426
|
};
|
|
9427
9427
|
PrintVisitor.prototype.PathExpression = function(id) {
|
|
9428
|
-
var
|
|
9429
|
-
return (id.data ? "@" : "") + "PATH:" +
|
|
9428
|
+
var path2 = id.parts.join("/");
|
|
9429
|
+
return (id.data ? "@" : "") + "PATH:" + path2;
|
|
9430
9430
|
};
|
|
9431
9431
|
PrintVisitor.prototype.StringLiteral = function(string) {
|
|
9432
9432
|
return '"' + string.value + '"';
|
|
@@ -9463,8 +9463,8 @@ var require_lib = __commonJS((exports, module) => {
|
|
|
9463
9463
|
handlebars.print = printer.print;
|
|
9464
9464
|
module.exports = handlebars;
|
|
9465
9465
|
function extension(module2, filename) {
|
|
9466
|
-
var
|
|
9467
|
-
var templateString =
|
|
9466
|
+
var fs2 = __require("fs");
|
|
9467
|
+
var templateString = fs2.readFileSync(filename, "utf8");
|
|
9468
9468
|
module2.exports = handlebars.compile(templateString);
|
|
9469
9469
|
}
|
|
9470
9470
|
if (__require.extensions) {
|
|
@@ -9653,19 +9653,19 @@ var require_parse4 = __commonJS((exports, module) => {
|
|
|
9653
9653
|
const wildcards = [];
|
|
9654
9654
|
var wcLen = 0;
|
|
9655
9655
|
const secret = paths.reduce(function(o, strPath, ix) {
|
|
9656
|
-
var
|
|
9656
|
+
var path2 = strPath.match(rx).map((p) => p.replace(/'|"|`/g, ""));
|
|
9657
9657
|
const leadingBracket = strPath[0] === "[";
|
|
9658
|
-
|
|
9658
|
+
path2 = path2.map((p) => {
|
|
9659
9659
|
if (p[0] === "[")
|
|
9660
9660
|
return p.substr(1, p.length - 2);
|
|
9661
9661
|
else
|
|
9662
9662
|
return p;
|
|
9663
9663
|
});
|
|
9664
|
-
const star =
|
|
9664
|
+
const star = path2.indexOf("*");
|
|
9665
9665
|
if (star > -1) {
|
|
9666
|
-
const before =
|
|
9666
|
+
const before = path2.slice(0, star);
|
|
9667
9667
|
const beforeStr = before.join(".");
|
|
9668
|
-
const after =
|
|
9668
|
+
const after = path2.slice(star + 1, path2.length);
|
|
9669
9669
|
const nested = after.length > 0;
|
|
9670
9670
|
wcLen++;
|
|
9671
9671
|
wildcards.push({
|
|
@@ -9676,7 +9676,7 @@ var require_parse4 = __commonJS((exports, module) => {
|
|
|
9676
9676
|
});
|
|
9677
9677
|
} else {
|
|
9678
9678
|
o[strPath] = {
|
|
9679
|
-
path,
|
|
9679
|
+
path: path2,
|
|
9680
9680
|
val: undefined,
|
|
9681
9681
|
precensored: false,
|
|
9682
9682
|
circle: "",
|
|
@@ -9719,13 +9719,13 @@ var require_redactor = __commonJS((exports, module) => {
|
|
|
9719
9719
|
return redact;
|
|
9720
9720
|
}
|
|
9721
9721
|
function redactTmpl(secret, isCensorFct, censorFctTakesPath) {
|
|
9722
|
-
return Object.keys(secret).map((
|
|
9723
|
-
const { escPath, leadingBracket, path: arrPath } = secret[
|
|
9722
|
+
return Object.keys(secret).map((path2) => {
|
|
9723
|
+
const { escPath, leadingBracket, path: arrPath } = secret[path2];
|
|
9724
9724
|
const skip = leadingBracket ? 1 : 0;
|
|
9725
9725
|
const delim = leadingBracket ? "" : ".";
|
|
9726
9726
|
const hops = [];
|
|
9727
9727
|
var match;
|
|
9728
|
-
while ((match = rx.exec(
|
|
9728
|
+
while ((match = rx.exec(path2)) !== null) {
|
|
9729
9729
|
const [, ix] = match;
|
|
9730
9730
|
const { index, input } = match;
|
|
9731
9731
|
if (index > skip)
|
|
@@ -9733,9 +9733,9 @@ var require_redactor = __commonJS((exports, module) => {
|
|
|
9733
9733
|
}
|
|
9734
9734
|
var existence = hops.map((p) => `o${delim}${p}`).join(" && ");
|
|
9735
9735
|
if (existence.length === 0)
|
|
9736
|
-
existence += `o${delim}${
|
|
9736
|
+
existence += `o${delim}${path2} != null`;
|
|
9737
9737
|
else
|
|
9738
|
-
existence += ` && o${delim}${
|
|
9738
|
+
existence += ` && o${delim}${path2} != null`;
|
|
9739
9739
|
const circularDetection = `
|
|
9740
9740
|
switch (true) {
|
|
9741
9741
|
${hops.reverse().map((p) => `
|
|
@@ -9749,12 +9749,12 @@ var require_redactor = __commonJS((exports, module) => {
|
|
|
9749
9749
|
const censorArgs = censorFctTakesPath ? `val, ${JSON.stringify(arrPath)}` : `val`;
|
|
9750
9750
|
return `
|
|
9751
9751
|
if (${existence}) {
|
|
9752
|
-
const val = o${delim}${
|
|
9752
|
+
const val = o${delim}${path2}
|
|
9753
9753
|
if (val === censor) {
|
|
9754
9754
|
secret[${escPath}].precensored = true
|
|
9755
9755
|
} else {
|
|
9756
9756
|
secret[${escPath}].val = val
|
|
9757
|
-
o${delim}${
|
|
9757
|
+
o${delim}${path2} = ${isCensorFct ? `censor(${censorArgs})` : "censor"}
|
|
9758
9758
|
${circularDetection}
|
|
9759
9759
|
}
|
|
9760
9760
|
}
|
|
@@ -9805,14 +9805,14 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9805
9805
|
target[k] = values[i];
|
|
9806
9806
|
}
|
|
9807
9807
|
}
|
|
9808
|
-
function groupRedact(o,
|
|
9809
|
-
const target = get(o,
|
|
9808
|
+
function groupRedact(o, path2, censor, isCensorFct, censorFctTakesPath) {
|
|
9809
|
+
const target = get(o, path2);
|
|
9810
9810
|
if (target == null || typeof target === "string")
|
|
9811
9811
|
return { keys: null, values: null, target, flat: true };
|
|
9812
9812
|
const keys2 = Object.keys(target);
|
|
9813
9813
|
const keysLength = keys2.length;
|
|
9814
|
-
const pathLength =
|
|
9815
|
-
const pathWithKey = censorFctTakesPath ? [...
|
|
9814
|
+
const pathLength = path2.length;
|
|
9815
|
+
const pathWithKey = censorFctTakesPath ? [...path2] : undefined;
|
|
9816
9816
|
const values = new Array(keysLength);
|
|
9817
9817
|
for (var i = 0;i < keysLength; i++) {
|
|
9818
9818
|
const key = keys2[i];
|
|
@@ -9830,30 +9830,30 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9830
9830
|
}
|
|
9831
9831
|
function nestedRestore(instructions) {
|
|
9832
9832
|
for (let i = 0;i < instructions.length; i++) {
|
|
9833
|
-
const { target, path, value } = instructions[i];
|
|
9833
|
+
const { target, path: path2, value } = instructions[i];
|
|
9834
9834
|
let current = target;
|
|
9835
|
-
for (let i2 =
|
|
9836
|
-
current = current[
|
|
9835
|
+
for (let i2 = path2.length - 1;i2 > 0; i2--) {
|
|
9836
|
+
current = current[path2[i2]];
|
|
9837
9837
|
}
|
|
9838
|
-
current[
|
|
9838
|
+
current[path2[0]] = value;
|
|
9839
9839
|
}
|
|
9840
9840
|
}
|
|
9841
|
-
function nestedRedact(store, o,
|
|
9842
|
-
const target = get(o,
|
|
9841
|
+
function nestedRedact(store, o, path2, ns, censor, isCensorFct, censorFctTakesPath) {
|
|
9842
|
+
const target = get(o, path2);
|
|
9843
9843
|
if (target == null)
|
|
9844
9844
|
return;
|
|
9845
9845
|
const keys2 = Object.keys(target);
|
|
9846
9846
|
const keysLength = keys2.length;
|
|
9847
9847
|
for (var i = 0;i < keysLength; i++) {
|
|
9848
9848
|
const key = keys2[i];
|
|
9849
|
-
specialSet(store, target, key,
|
|
9849
|
+
specialSet(store, target, key, path2, ns, censor, isCensorFct, censorFctTakesPath);
|
|
9850
9850
|
}
|
|
9851
9851
|
return store;
|
|
9852
9852
|
}
|
|
9853
9853
|
function has(obj, prop) {
|
|
9854
9854
|
return obj !== undefined && obj !== null ? "hasOwn" in Object ? Object.hasOwn(obj, prop) : Object.prototype.hasOwnProperty.call(obj, prop) : false;
|
|
9855
9855
|
}
|
|
9856
|
-
function specialSet(store, o, k,
|
|
9856
|
+
function specialSet(store, o, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath) {
|
|
9857
9857
|
const afterPathLen = afterPath.length;
|
|
9858
9858
|
const lastPathIndex = afterPathLen - 1;
|
|
9859
9859
|
const originalKey = k;
|
|
@@ -9897,7 +9897,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9897
9897
|
if (consecutive) {
|
|
9898
9898
|
redactPathCurrent = node(redactPathCurrent, wck, depth);
|
|
9899
9899
|
level = i;
|
|
9900
|
-
ov = iterateNthLevel(wcov, level - 1, k,
|
|
9900
|
+
ov = iterateNthLevel(wcov, level - 1, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, o[originalKey], depth + 1);
|
|
9901
9901
|
} else {
|
|
9902
9902
|
if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
|
|
9903
9903
|
if (kIsWc) {
|
|
@@ -9905,7 +9905,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9905
9905
|
} else {
|
|
9906
9906
|
ov = wcov[k];
|
|
9907
9907
|
}
|
|
9908
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
9908
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
9909
9909
|
if (kIsWc) {
|
|
9910
9910
|
const rv = restoreInstr(node(redactPathCurrent, wck, depth), ov, o[originalKey]);
|
|
9911
9911
|
store.push(rv);
|
|
@@ -9927,7 +9927,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9927
9927
|
} else {
|
|
9928
9928
|
ov = n[k];
|
|
9929
9929
|
redactPathCurrent = node(redactPathCurrent, k, depth);
|
|
9930
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
9930
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
9931
9931
|
if (has(n, k) && nv === ov || nv === undefined && censor !== undefined) {} else {
|
|
9932
9932
|
const rv = restoreInstr(redactPathCurrent, ov, o[originalKey]);
|
|
9933
9933
|
store.push(rv);
|
|
@@ -9949,7 +9949,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9949
9949
|
}
|
|
9950
9950
|
return n;
|
|
9951
9951
|
}
|
|
9952
|
-
function iterateNthLevel(wcov, level, k,
|
|
9952
|
+
function iterateNthLevel(wcov, level, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth) {
|
|
9953
9953
|
if (level === 0) {
|
|
9954
9954
|
if (kIsWc || typeof wcov === "object" && wcov !== null && k in wcov) {
|
|
9955
9955
|
if (kIsWc) {
|
|
@@ -9957,7 +9957,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9957
9957
|
} else {
|
|
9958
9958
|
ov = wcov[k];
|
|
9959
9959
|
}
|
|
9960
|
-
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...
|
|
9960
|
+
nv = i !== lastPathIndex ? ov : isCensorFct ? censorFctTakesPath ? censor(ov, [...path2, originalKey, ...afterPath]) : censor(ov) : censor;
|
|
9961
9961
|
if (kIsWc) {
|
|
9962
9962
|
const rv = restoreInstr(redactPathCurrent, ov, parent);
|
|
9963
9963
|
store.push(rv);
|
|
@@ -9974,7 +9974,7 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9974
9974
|
for (const key in wcov) {
|
|
9975
9975
|
if (typeof wcov[key] === "object") {
|
|
9976
9976
|
redactPathCurrent = node(redactPathCurrent, key, depth);
|
|
9977
|
-
iterateNthLevel(wcov[key], level - 1, k,
|
|
9977
|
+
iterateNthLevel(wcov[key], level - 1, k, path2, afterPath, censor, isCensorFct, censorFctTakesPath, originalKey, n, nv, ov, kIsWc, wck, i, lastPathIndex, redactPathCurrent, store, parent, depth + 1);
|
|
9978
9978
|
}
|
|
9979
9979
|
}
|
|
9980
9980
|
}
|
|
@@ -9996,12 +9996,12 @@ var require_modifiers = __commonJS((exports, module) => {
|
|
|
9996
9996
|
}
|
|
9997
9997
|
function restoreInstr(node2, value, target) {
|
|
9998
9998
|
let current = node2;
|
|
9999
|
-
const
|
|
9999
|
+
const path2 = [];
|
|
10000
10000
|
do {
|
|
10001
|
-
|
|
10001
|
+
path2.push(current.key);
|
|
10002
10002
|
current = current.parent;
|
|
10003
10003
|
} while (current.parent != null);
|
|
10004
|
-
return { path, value, target };
|
|
10004
|
+
return { path: path2, value, target };
|
|
10005
10005
|
}
|
|
10006
10006
|
});
|
|
10007
10007
|
|
|
@@ -10025,10 +10025,10 @@ var require_restorer = __commonJS((exports, module) => {
|
|
|
10025
10025
|
};
|
|
10026
10026
|
}
|
|
10027
10027
|
function resetTmpl(secret, paths) {
|
|
10028
|
-
return paths.map((
|
|
10029
|
-
const { circle, escPath, leadingBracket } = secret[
|
|
10028
|
+
return paths.map((path2) => {
|
|
10029
|
+
const { circle, escPath, leadingBracket } = secret[path2];
|
|
10030
10030
|
const delim = leadingBracket ? "" : ".";
|
|
10031
|
-
const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${
|
|
10031
|
+
const reset = circle ? `o.${circle} = secret[${escPath}].val` : `o${delim}${path2} = secret[${escPath}].val`;
|
|
10032
10032
|
const clear = `secret[${escPath}].val = undefined`;
|
|
10033
10033
|
return `
|
|
10034
10034
|
if (secret[${escPath}].val !== undefined) {
|
|
@@ -19932,8 +19932,8 @@ var require_reporter = __commonJS((exports) => {
|
|
|
19932
19932
|
errors: state.errors
|
|
19933
19933
|
};
|
|
19934
19934
|
};
|
|
19935
|
-
function ReporterError(
|
|
19936
|
-
this.path =
|
|
19935
|
+
function ReporterError(path2, msg) {
|
|
19936
|
+
this.path = path2;
|
|
19937
19937
|
this.rethrow(msg);
|
|
19938
19938
|
}
|
|
19939
19939
|
inherits(ReporterError, Error);
|
|
@@ -25516,20 +25516,41 @@ function escapeObject(obj) {
|
|
|
25516
25516
|
function isSerializableLike(obj) {
|
|
25517
25517
|
return obj !== null && typeof obj === "object" && "lc_serializable" in obj && typeof obj.toJSON === "function";
|
|
25518
25518
|
}
|
|
25519
|
-
function
|
|
25519
|
+
function createNotImplemented(obj) {
|
|
25520
|
+
let id;
|
|
25521
|
+
if (obj !== null && typeof obj === "object")
|
|
25522
|
+
if ("lc_id" in obj && Array.isArray(obj.lc_id))
|
|
25523
|
+
id = obj.lc_id;
|
|
25524
|
+
else
|
|
25525
|
+
id = [obj.constructor?.name ?? "Object"];
|
|
25526
|
+
else
|
|
25527
|
+
id = [typeof obj];
|
|
25528
|
+
return {
|
|
25529
|
+
lc: 1,
|
|
25530
|
+
type: "not_implemented",
|
|
25531
|
+
id
|
|
25532
|
+
};
|
|
25533
|
+
}
|
|
25534
|
+
function escapeIfNeeded(value, pathSet = /* @__PURE__ */ new WeakSet) {
|
|
25520
25535
|
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
25536
|
+
if (pathSet.has(value))
|
|
25537
|
+
return createNotImplemented(value);
|
|
25521
25538
|
if (isSerializableLike(value))
|
|
25522
25539
|
return value;
|
|
25540
|
+
pathSet.add(value);
|
|
25523
25541
|
const record = value;
|
|
25524
|
-
if (needsEscaping(record))
|
|
25542
|
+
if (needsEscaping(record)) {
|
|
25543
|
+
pathSet.delete(value);
|
|
25525
25544
|
return escapeObject(record);
|
|
25545
|
+
}
|
|
25526
25546
|
const result = {};
|
|
25527
25547
|
for (const [key, val] of Object.entries(record))
|
|
25528
|
-
result[key] = escapeIfNeeded(val);
|
|
25548
|
+
result[key] = escapeIfNeeded(val, pathSet);
|
|
25549
|
+
pathSet.delete(value);
|
|
25529
25550
|
return result;
|
|
25530
25551
|
}
|
|
25531
25552
|
if (Array.isArray(value))
|
|
25532
|
-
return value.map((item) => escapeIfNeeded(item));
|
|
25553
|
+
return value.map((item) => escapeIfNeeded(item, pathSet));
|
|
25533
25554
|
return value;
|
|
25534
25555
|
}
|
|
25535
25556
|
|
|
@@ -25633,8 +25654,10 @@ var Serializable = class Serializable2 {
|
|
|
25633
25654
|
write[last] = write[last] || read[last];
|
|
25634
25655
|
});
|
|
25635
25656
|
const escapedKwargs = {};
|
|
25657
|
+
const pathSet = /* @__PURE__ */ new WeakSet;
|
|
25658
|
+
pathSet.add(this);
|
|
25636
25659
|
for (const [key, value] of Object.entries(kwargs))
|
|
25637
|
-
escapedKwargs[key] = escapeIfNeeded(value);
|
|
25660
|
+
escapedKwargs[key] = escapeIfNeeded(value, pathSet);
|
|
25638
25661
|
const kwargsWithSecrets = Object.keys(secrets).length ? replaceSecrets(escapedKwargs, secrets) : escapedKwargs;
|
|
25639
25662
|
const processedKwargs = mapKeys(kwargsWithSecrets, keyToJson, aliases);
|
|
25640
25663
|
return {
|
|
@@ -26571,7 +26594,11 @@ var BaseMessage = class extends Serializable {
|
|
|
26571
26594
|
return convertToFormattedString(this, format);
|
|
26572
26595
|
}
|
|
26573
26596
|
};
|
|
26574
|
-
function _mergeDicts(left
|
|
26597
|
+
function _mergeDicts(left, right) {
|
|
26598
|
+
if (left === undefined && right === undefined)
|
|
26599
|
+
return;
|
|
26600
|
+
if (left === undefined || right === undefined)
|
|
26601
|
+
return left ?? right;
|
|
26575
26602
|
const merged = { ...left };
|
|
26576
26603
|
for (const [key, value] of Object.entries(right))
|
|
26577
26604
|
if (merged[key] == null)
|
|
@@ -26593,6 +26620,8 @@ function _mergeDicts(left = {}, right = {}) {
|
|
|
26593
26620
|
merged[key] = value;
|
|
26594
26621
|
} else
|
|
26595
26622
|
merged[key] += value;
|
|
26623
|
+
else if (typeof merged[key] === "number")
|
|
26624
|
+
merged[key] = merged[key] + value;
|
|
26596
26625
|
else if (typeof merged[key] === "object" && !Array.isArray(merged[key]))
|
|
26597
26626
|
merged[key] = _mergeDicts(merged[key], value);
|
|
26598
26627
|
else if (Array.isArray(merged[key]))
|
|
@@ -27411,7 +27440,7 @@ function getTranslator(modelProvider) {
|
|
|
27411
27440
|
|
|
27412
27441
|
// ../../node_modules/@langchain/core/dist/messages/metadata.js
|
|
27413
27442
|
function mergeResponseMetadata(a, b) {
|
|
27414
|
-
const output = _mergeDicts(a
|
|
27443
|
+
const output = _mergeDicts(a, b) ?? {};
|
|
27415
27444
|
return output;
|
|
27416
27445
|
}
|
|
27417
27446
|
function mergeModalitiesTokenDetails(a, b) {
|
|
@@ -27489,8 +27518,8 @@ Please upgrade your packages to versions that set`,
|
|
|
27489
27518
|
].join(" "));
|
|
27490
27519
|
try {
|
|
27491
27520
|
if (!(rawToolCalls == null) && toolCalls === undefined) {
|
|
27492
|
-
const [
|
|
27493
|
-
initParams.tool_calls =
|
|
27521
|
+
const [parsedToolCalls, invalidToolCalls] = defaultToolCallParser(rawToolCalls);
|
|
27522
|
+
initParams.tool_calls = parsedToolCalls ?? [];
|
|
27494
27523
|
initParams.invalid_tool_calls = invalidToolCalls ?? [];
|
|
27495
27524
|
} else {
|
|
27496
27525
|
initParams.tool_calls = initParams.tool_calls ?? [];
|
|
@@ -27505,12 +27534,13 @@ Please upgrade your packages to versions that set`,
|
|
|
27505
27534
|
initParams.content = undefined;
|
|
27506
27535
|
}
|
|
27507
27536
|
if (initParams.contentBlocks !== undefined) {
|
|
27508
|
-
|
|
27509
|
-
|
|
27510
|
-
|
|
27511
|
-
|
|
27512
|
-
|
|
27513
|
-
|
|
27537
|
+
if (initParams.tool_calls)
|
|
27538
|
+
initParams.contentBlocks.push(...initParams.tool_calls.map((toolCall) => ({
|
|
27539
|
+
type: "tool_call",
|
|
27540
|
+
id: toolCall.id,
|
|
27541
|
+
name: toolCall.name,
|
|
27542
|
+
args: toolCall.args
|
|
27543
|
+
})));
|
|
27514
27544
|
const missingToolCalls = initParams.contentBlocks.filter((block) => block.type === "tool_call").filter((block) => !initParams.tool_calls?.some((toolCall) => toolCall.id === block.id && toolCall.name === block.name));
|
|
27515
27545
|
if (missingToolCalls.length > 0)
|
|
27516
27546
|
initParams.tool_calls = missingToolCalls.map((block) => ({
|
|
@@ -27543,7 +27573,6 @@ Please upgrade your packages to versions that set`,
|
|
|
27543
27573
|
if (this.tool_calls) {
|
|
27544
27574
|
const missingToolCalls = this.tool_calls.filter((block) => !blocks.some((b) => b.id === block.id && b.name === block.name));
|
|
27545
27575
|
blocks.push(...missingToolCalls.map((block) => ({
|
|
27546
|
-
...block,
|
|
27547
27576
|
type: "tool_call",
|
|
27548
27577
|
id: block.id,
|
|
27549
27578
|
name: block.name,
|
|
@@ -27587,12 +27616,16 @@ var AIMessageChunk = class extends BaseMessageChunk {
|
|
|
27587
27616
|
tool_call_chunks: [],
|
|
27588
27617
|
usage_metadata: fields.usage_metadata !== undefined ? fields.usage_metadata : undefined
|
|
27589
27618
|
};
|
|
27590
|
-
else
|
|
27619
|
+
else {
|
|
27620
|
+
const collapsed = collapseToolCallChunks(fields.tool_call_chunks ?? []);
|
|
27591
27621
|
initParams = {
|
|
27592
27622
|
...fields,
|
|
27593
|
-
|
|
27623
|
+
tool_call_chunks: collapsed.tool_call_chunks,
|
|
27624
|
+
tool_calls: collapsed.tool_calls,
|
|
27625
|
+
invalid_tool_calls: collapsed.invalid_tool_calls,
|
|
27594
27626
|
usage_metadata: fields.usage_metadata !== undefined ? fields.usage_metadata : undefined
|
|
27595
27627
|
};
|
|
27628
|
+
}
|
|
27596
27629
|
super(initParams);
|
|
27597
27630
|
this.tool_call_chunks = initParams.tool_call_chunks ?? this.tool_call_chunks;
|
|
27598
27631
|
this.tool_calls = initParams.tool_calls ?? this.tool_calls;
|
|
@@ -27672,21 +27705,29 @@ function getBufferString(messages, humanPrefix = "Human", aiPrefix = "AI") {
|
|
|
27672
27705
|
const string_messages = [];
|
|
27673
27706
|
for (const m of messages) {
|
|
27674
27707
|
let role;
|
|
27675
|
-
if (m.
|
|
27708
|
+
if (m.type === "human")
|
|
27676
27709
|
role = humanPrefix;
|
|
27677
|
-
else if (m.
|
|
27710
|
+
else if (m.type === "ai")
|
|
27678
27711
|
role = aiPrefix;
|
|
27679
|
-
else if (m.
|
|
27712
|
+
else if (m.type === "system")
|
|
27680
27713
|
role = "System";
|
|
27681
|
-
else if (m.
|
|
27714
|
+
else if (m.type === "tool")
|
|
27682
27715
|
role = "Tool";
|
|
27683
|
-
else if (m.
|
|
27716
|
+
else if (m.type === "generic")
|
|
27684
27717
|
role = m.role;
|
|
27685
27718
|
else
|
|
27686
|
-
throw new Error(`Got unsupported message type: ${m.
|
|
27719
|
+
throw new Error(`Got unsupported message type: ${m.type}`);
|
|
27687
27720
|
const nameStr = m.name ? `${m.name}, ` : "";
|
|
27688
|
-
const readableContent =
|
|
27689
|
-
|
|
27721
|
+
const readableContent = m.text;
|
|
27722
|
+
let message = `${role}: ${nameStr}${readableContent}`;
|
|
27723
|
+
if (m.type === "ai") {
|
|
27724
|
+
const aiMessage = m;
|
|
27725
|
+
if (aiMessage.tool_calls && aiMessage.tool_calls.length > 0)
|
|
27726
|
+
message += JSON.stringify(aiMessage.tool_calls);
|
|
27727
|
+
else if (aiMessage.additional_kwargs && "function_call" in aiMessage.additional_kwargs)
|
|
27728
|
+
message += JSON.stringify(aiMessage.additional_kwargs.function_call);
|
|
27729
|
+
}
|
|
27730
|
+
string_messages.push(message);
|
|
27690
27731
|
}
|
|
27691
27732
|
return string_messages.join(`
|
|
27692
27733
|
`);
|
|
@@ -28002,8 +28043,232 @@ function uuid7FromTime(timestamp) {
|
|
|
28002
28043
|
const msecs = typeof timestamp === "string" ? Date.parse(timestamp) : timestamp;
|
|
28003
28044
|
return v72({ msecs, seq: 0 });
|
|
28004
28045
|
}
|
|
28046
|
+
// ../../node_modules/langsmith/dist/utils/prompts_cache_fs.js
|
|
28047
|
+
import * as fs from "node:fs";
|
|
28048
|
+
import * as path from "node:path";
|
|
28049
|
+
function dumpCache(filePath, entries) {
|
|
28050
|
+
const dir = path.dirname(filePath);
|
|
28051
|
+
if (!fs.existsSync(dir)) {
|
|
28052
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
28053
|
+
}
|
|
28054
|
+
const data = { entries };
|
|
28055
|
+
const tempPath = `${filePath}.tmp`;
|
|
28056
|
+
try {
|
|
28057
|
+
fs.writeFileSync(tempPath, JSON.stringify(data, null, 2));
|
|
28058
|
+
fs.renameSync(tempPath, filePath);
|
|
28059
|
+
} catch (e) {
|
|
28060
|
+
if (fs.existsSync(tempPath)) {
|
|
28061
|
+
fs.unlinkSync(tempPath);
|
|
28062
|
+
}
|
|
28063
|
+
throw e;
|
|
28064
|
+
}
|
|
28065
|
+
}
|
|
28066
|
+
function loadCache(filePath) {
|
|
28067
|
+
if (!fs.existsSync(filePath)) {
|
|
28068
|
+
return null;
|
|
28069
|
+
}
|
|
28070
|
+
try {
|
|
28071
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
28072
|
+
const data = JSON.parse(content);
|
|
28073
|
+
return data.entries ?? null;
|
|
28074
|
+
} catch {
|
|
28075
|
+
return null;
|
|
28076
|
+
}
|
|
28077
|
+
}
|
|
28078
|
+
|
|
28079
|
+
// ../../node_modules/langsmith/dist/utils/prompts_cache.js
|
|
28080
|
+
function isStale(entry, ttlSeconds) {
|
|
28081
|
+
if (ttlSeconds === null) {
|
|
28082
|
+
return false;
|
|
28083
|
+
}
|
|
28084
|
+
const ageMs = Date.now() - entry.createdAt;
|
|
28085
|
+
return ageMs > ttlSeconds * 1000;
|
|
28086
|
+
}
|
|
28087
|
+
|
|
28088
|
+
class Cache {
|
|
28089
|
+
constructor(config = {}) {
|
|
28090
|
+
Object.defineProperty(this, "cache", {
|
|
28091
|
+
enumerable: true,
|
|
28092
|
+
configurable: true,
|
|
28093
|
+
writable: true,
|
|
28094
|
+
value: new Map
|
|
28095
|
+
});
|
|
28096
|
+
Object.defineProperty(this, "maxSize", {
|
|
28097
|
+
enumerable: true,
|
|
28098
|
+
configurable: true,
|
|
28099
|
+
writable: true,
|
|
28100
|
+
value: undefined
|
|
28101
|
+
});
|
|
28102
|
+
Object.defineProperty(this, "ttlSeconds", {
|
|
28103
|
+
enumerable: true,
|
|
28104
|
+
configurable: true,
|
|
28105
|
+
writable: true,
|
|
28106
|
+
value: undefined
|
|
28107
|
+
});
|
|
28108
|
+
Object.defineProperty(this, "refreshIntervalSeconds", {
|
|
28109
|
+
enumerable: true,
|
|
28110
|
+
configurable: true,
|
|
28111
|
+
writable: true,
|
|
28112
|
+
value: undefined
|
|
28113
|
+
});
|
|
28114
|
+
Object.defineProperty(this, "fetchFunc", {
|
|
28115
|
+
enumerable: true,
|
|
28116
|
+
configurable: true,
|
|
28117
|
+
writable: true,
|
|
28118
|
+
value: undefined
|
|
28119
|
+
});
|
|
28120
|
+
Object.defineProperty(this, "refreshTimer", {
|
|
28121
|
+
enumerable: true,
|
|
28122
|
+
configurable: true,
|
|
28123
|
+
writable: true,
|
|
28124
|
+
value: undefined
|
|
28125
|
+
});
|
|
28126
|
+
Object.defineProperty(this, "_metrics", {
|
|
28127
|
+
enumerable: true,
|
|
28128
|
+
configurable: true,
|
|
28129
|
+
writable: true,
|
|
28130
|
+
value: {
|
|
28131
|
+
hits: 0,
|
|
28132
|
+
misses: 0,
|
|
28133
|
+
refreshes: 0,
|
|
28134
|
+
refreshErrors: 0
|
|
28135
|
+
}
|
|
28136
|
+
});
|
|
28137
|
+
this.maxSize = config.maxSize ?? 100;
|
|
28138
|
+
this.ttlSeconds = config.ttlSeconds ?? 3600;
|
|
28139
|
+
this.refreshIntervalSeconds = config.refreshIntervalSeconds ?? 60;
|
|
28140
|
+
this.fetchFunc = config.fetchFunc;
|
|
28141
|
+
if (this.fetchFunc && this.ttlSeconds !== null) {
|
|
28142
|
+
this.startRefreshLoop();
|
|
28143
|
+
}
|
|
28144
|
+
}
|
|
28145
|
+
get metrics() {
|
|
28146
|
+
return { ...this._metrics };
|
|
28147
|
+
}
|
|
28148
|
+
get totalRequests() {
|
|
28149
|
+
return this._metrics.hits + this._metrics.misses;
|
|
28150
|
+
}
|
|
28151
|
+
get hitRate() {
|
|
28152
|
+
const total = this.totalRequests;
|
|
28153
|
+
return total > 0 ? this._metrics.hits / total : 0;
|
|
28154
|
+
}
|
|
28155
|
+
resetMetrics() {
|
|
28156
|
+
this._metrics = {
|
|
28157
|
+
hits: 0,
|
|
28158
|
+
misses: 0,
|
|
28159
|
+
refreshes: 0,
|
|
28160
|
+
refreshErrors: 0
|
|
28161
|
+
};
|
|
28162
|
+
}
|
|
28163
|
+
get(key) {
|
|
28164
|
+
const entry = this.cache.get(key);
|
|
28165
|
+
if (!entry) {
|
|
28166
|
+
this._metrics.misses += 1;
|
|
28167
|
+
return;
|
|
28168
|
+
}
|
|
28169
|
+
this.cache.delete(key);
|
|
28170
|
+
this.cache.set(key, entry);
|
|
28171
|
+
this._metrics.hits += 1;
|
|
28172
|
+
return entry.value;
|
|
28173
|
+
}
|
|
28174
|
+
set(key, value) {
|
|
28175
|
+
if (!this.cache.has(key) && this.cache.size >= this.maxSize) {
|
|
28176
|
+
const oldestKey = this.cache.keys().next().value;
|
|
28177
|
+
if (oldestKey !== undefined) {
|
|
28178
|
+
this.cache.delete(oldestKey);
|
|
28179
|
+
}
|
|
28180
|
+
}
|
|
28181
|
+
const entry = {
|
|
28182
|
+
value,
|
|
28183
|
+
createdAt: Date.now()
|
|
28184
|
+
};
|
|
28185
|
+
this.cache.delete(key);
|
|
28186
|
+
this.cache.set(key, entry);
|
|
28187
|
+
}
|
|
28188
|
+
invalidate(key) {
|
|
28189
|
+
this.cache.delete(key);
|
|
28190
|
+
}
|
|
28191
|
+
clear() {
|
|
28192
|
+
this.cache.clear();
|
|
28193
|
+
}
|
|
28194
|
+
get size() {
|
|
28195
|
+
return this.cache.size;
|
|
28196
|
+
}
|
|
28197
|
+
stop() {
|
|
28198
|
+
if (this.refreshTimer) {
|
|
28199
|
+
clearInterval(this.refreshTimer);
|
|
28200
|
+
this.refreshTimer = undefined;
|
|
28201
|
+
}
|
|
28202
|
+
}
|
|
28203
|
+
dump(filePath) {
|
|
28204
|
+
const entries = {};
|
|
28205
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
28206
|
+
entries[key] = entry.value;
|
|
28207
|
+
}
|
|
28208
|
+
dumpCache(filePath, entries);
|
|
28209
|
+
}
|
|
28210
|
+
load(filePath) {
|
|
28211
|
+
const entries = loadCache(filePath);
|
|
28212
|
+
if (!entries) {
|
|
28213
|
+
return 0;
|
|
28214
|
+
}
|
|
28215
|
+
let loaded = 0;
|
|
28216
|
+
const now = Date.now();
|
|
28217
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
28218
|
+
if (this.cache.size >= this.maxSize) {
|
|
28219
|
+
break;
|
|
28220
|
+
}
|
|
28221
|
+
const entry = {
|
|
28222
|
+
value,
|
|
28223
|
+
createdAt: now
|
|
28224
|
+
};
|
|
28225
|
+
this.cache.set(key, entry);
|
|
28226
|
+
loaded += 1;
|
|
28227
|
+
}
|
|
28228
|
+
return loaded;
|
|
28229
|
+
}
|
|
28230
|
+
startRefreshLoop() {
|
|
28231
|
+
this.refreshTimer = setInterval(() => {
|
|
28232
|
+
this.refreshStaleEntries().catch((e) => {
|
|
28233
|
+
console.warn("Unexpected error in cache refresh loop:", e);
|
|
28234
|
+
});
|
|
28235
|
+
}, this.refreshIntervalSeconds * 1000);
|
|
28236
|
+
if (this.refreshTimer.unref) {
|
|
28237
|
+
this.refreshTimer.unref();
|
|
28238
|
+
}
|
|
28239
|
+
}
|
|
28240
|
+
getStaleKeys() {
|
|
28241
|
+
const staleKeys = [];
|
|
28242
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
28243
|
+
if (isStale(entry, this.ttlSeconds)) {
|
|
28244
|
+
staleKeys.push(key);
|
|
28245
|
+
}
|
|
28246
|
+
}
|
|
28247
|
+
return staleKeys;
|
|
28248
|
+
}
|
|
28249
|
+
async refreshStaleEntries() {
|
|
28250
|
+
if (!this.fetchFunc) {
|
|
28251
|
+
return;
|
|
28252
|
+
}
|
|
28253
|
+
const staleKeys = this.getStaleKeys();
|
|
28254
|
+
if (staleKeys.length === 0) {
|
|
28255
|
+
return;
|
|
28256
|
+
}
|
|
28257
|
+
for (const key of staleKeys) {
|
|
28258
|
+
try {
|
|
28259
|
+
const newValue = await this.fetchFunc(key);
|
|
28260
|
+
this.set(key, newValue);
|
|
28261
|
+
this._metrics.refreshes += 1;
|
|
28262
|
+
} catch (e) {
|
|
28263
|
+
this._metrics.refreshErrors += 1;
|
|
28264
|
+
console.warn(`Failed to refresh cache entry ${key}:`, e);
|
|
28265
|
+
}
|
|
28266
|
+
}
|
|
28267
|
+
}
|
|
28268
|
+
}
|
|
28269
|
+
|
|
28005
28270
|
// ../../node_modules/langsmith/dist/index.js
|
|
28006
|
-
var __version__ = "0.4.
|
|
28271
|
+
var __version__ = "0.4.5";
|
|
28007
28272
|
|
|
28008
28273
|
// ../../node_modules/langsmith/dist/utils/env.js
|
|
28009
28274
|
var globalEnv;
|
|
@@ -29531,6 +29796,12 @@ class Client {
|
|
|
29531
29796
|
writable: true,
|
|
29532
29797
|
value: undefined
|
|
29533
29798
|
});
|
|
29799
|
+
Object.defineProperty(this, "_cache", {
|
|
29800
|
+
enumerable: true,
|
|
29801
|
+
configurable: true,
|
|
29802
|
+
writable: true,
|
|
29803
|
+
value: undefined
|
|
29804
|
+
});
|
|
29534
29805
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
29535
29806
|
enumerable: true,
|
|
29536
29807
|
configurable: true,
|
|
@@ -29596,6 +29867,13 @@ class Client {
|
|
|
29596
29867
|
this.langSmithToOTELTranslator = new LangSmithToOTELTranslator;
|
|
29597
29868
|
}
|
|
29598
29869
|
this.cachedLSEnvVarsForMetadata = getLangSmithEnvVarsMetadata();
|
|
29870
|
+
if (config.cache === true) {
|
|
29871
|
+
this._cache = new Cache;
|
|
29872
|
+
} else if (config.cache && typeof config.cache === "object") {
|
|
29873
|
+
this._cache = config.cache;
|
|
29874
|
+
} else {
|
|
29875
|
+
this._cache = undefined;
|
|
29876
|
+
}
|
|
29599
29877
|
}
|
|
29600
29878
|
static getDefaultClientConfig() {
|
|
29601
29879
|
const apiKey = getLangSmithEnvironmentVariable("API_KEY");
|
|
@@ -29648,9 +29926,9 @@ class Client {
|
|
|
29648
29926
|
}
|
|
29649
29927
|
return headers;
|
|
29650
29928
|
}
|
|
29651
|
-
_getPlatformEndpointPath(
|
|
29929
|
+
_getPlatformEndpointPath(path2) {
|
|
29652
29930
|
const needsV1Prefix = this.apiUrl.slice(-3) !== "/v1" && this.apiUrl.slice(-4) !== "/v1/";
|
|
29653
|
-
return needsV1Prefix ? `/v1/platform/${
|
|
29931
|
+
return needsV1Prefix ? `/v1/platform/${path2}` : `/platform/${path2}`;
|
|
29654
29932
|
}
|
|
29655
29933
|
async processInputs(inputs) {
|
|
29656
29934
|
if (this.hideInputs === false) {
|
|
@@ -29686,9 +29964,9 @@ class Client {
|
|
|
29686
29964
|
}
|
|
29687
29965
|
return runParams;
|
|
29688
29966
|
}
|
|
29689
|
-
async _getResponse(
|
|
29967
|
+
async _getResponse(path2, queryParams) {
|
|
29690
29968
|
const paramsString = queryParams?.toString() ?? "";
|
|
29691
|
-
const url = `${this.apiUrl}${
|
|
29969
|
+
const url = `${this.apiUrl}${path2}?${paramsString}`;
|
|
29692
29970
|
const response = await this.caller.call(async () => {
|
|
29693
29971
|
const res = await this._fetch(url, {
|
|
29694
29972
|
method: "GET",
|
|
@@ -29696,22 +29974,22 @@ class Client {
|
|
|
29696
29974
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
29697
29975
|
...this.fetchOptions
|
|
29698
29976
|
});
|
|
29699
|
-
await raiseForStatus(res, `fetch ${
|
|
29977
|
+
await raiseForStatus(res, `fetch ${path2}`);
|
|
29700
29978
|
return res;
|
|
29701
29979
|
});
|
|
29702
29980
|
return response;
|
|
29703
29981
|
}
|
|
29704
|
-
async _get(
|
|
29705
|
-
const response = await this._getResponse(
|
|
29982
|
+
async _get(path2, queryParams) {
|
|
29983
|
+
const response = await this._getResponse(path2, queryParams);
|
|
29706
29984
|
return response.json();
|
|
29707
29985
|
}
|
|
29708
|
-
async* _getPaginated(
|
|
29986
|
+
async* _getPaginated(path2, queryParams = new URLSearchParams, transform) {
|
|
29709
29987
|
let offset = Number(queryParams.get("offset")) || 0;
|
|
29710
29988
|
const limit = Number(queryParams.get("limit")) || 100;
|
|
29711
29989
|
while (true) {
|
|
29712
29990
|
queryParams.set("offset", String(offset));
|
|
29713
29991
|
queryParams.set("limit", String(limit));
|
|
29714
|
-
const url = `${this.apiUrl}${
|
|
29992
|
+
const url = `${this.apiUrl}${path2}?${queryParams}`;
|
|
29715
29993
|
const response = await this.caller.call(async () => {
|
|
29716
29994
|
const res = await this._fetch(url, {
|
|
29717
29995
|
method: "GET",
|
|
@@ -29719,7 +29997,7 @@ class Client {
|
|
|
29719
29997
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
29720
29998
|
...this.fetchOptions
|
|
29721
29999
|
});
|
|
29722
|
-
await raiseForStatus(res, `fetch ${
|
|
30000
|
+
await raiseForStatus(res, `fetch ${path2}`);
|
|
29723
30001
|
return res;
|
|
29724
30002
|
});
|
|
29725
30003
|
const items = transform ? transform(await response.json()) : await response.json();
|
|
@@ -29733,19 +30011,19 @@ class Client {
|
|
|
29733
30011
|
offset += items.length;
|
|
29734
30012
|
}
|
|
29735
30013
|
}
|
|
29736
|
-
async* _getCursorPaginatedList(
|
|
30014
|
+
async* _getCursorPaginatedList(path2, body = null, requestMethod = "POST", dataKey = "runs") {
|
|
29737
30015
|
const bodyParams = body ? { ...body } : {};
|
|
29738
30016
|
while (true) {
|
|
29739
30017
|
const body2 = JSON.stringify(bodyParams);
|
|
29740
30018
|
const response = await this.caller.call(async () => {
|
|
29741
|
-
const res = await this._fetch(`${this.apiUrl}${
|
|
30019
|
+
const res = await this._fetch(`${this.apiUrl}${path2}`, {
|
|
29742
30020
|
method: requestMethod,
|
|
29743
30021
|
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
29744
30022
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
29745
30023
|
...this.fetchOptions,
|
|
29746
30024
|
body: body2
|
|
29747
30025
|
});
|
|
29748
|
-
await raiseForStatus(res, `fetch ${
|
|
30026
|
+
await raiseForStatus(res, `fetch ${path2}`);
|
|
29749
30027
|
return res;
|
|
29750
30028
|
});
|
|
29751
30029
|
const responseBody = await response.json();
|
|
@@ -30581,8 +30859,8 @@ Context: ${context}`);
|
|
|
30581
30859
|
limit: Number(limit) || 100
|
|
30582
30860
|
};
|
|
30583
30861
|
let currentOffset = Number(offset) || 0;
|
|
30584
|
-
const
|
|
30585
|
-
const url = `${this.apiUrl}${
|
|
30862
|
+
const path2 = "/runs/group";
|
|
30863
|
+
const url = `${this.apiUrl}${path2}`;
|
|
30586
30864
|
while (true) {
|
|
30587
30865
|
const currentBody = {
|
|
30588
30866
|
...baseBody,
|
|
@@ -30598,7 +30876,7 @@ Context: ${context}`);
|
|
|
30598
30876
|
...this.fetchOptions,
|
|
30599
30877
|
body
|
|
30600
30878
|
});
|
|
30601
|
-
await raiseForStatus(res, `Failed to fetch ${
|
|
30879
|
+
await raiseForStatus(res, `Failed to fetch ${path2}`);
|
|
30602
30880
|
return res;
|
|
30603
30881
|
});
|
|
30604
30882
|
const items = await response.json();
|
|
@@ -30908,20 +31186,20 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
30908
31186
|
return result;
|
|
30909
31187
|
}
|
|
30910
31188
|
async hasProject({ projectId, projectName }) {
|
|
30911
|
-
let
|
|
31189
|
+
let path2 = "/sessions";
|
|
30912
31190
|
const params = new URLSearchParams;
|
|
30913
31191
|
if (projectId !== undefined && projectName !== undefined) {
|
|
30914
31192
|
throw new Error("Must provide either projectName or projectId, not both");
|
|
30915
31193
|
} else if (projectId !== undefined) {
|
|
30916
31194
|
assertUuid(projectId);
|
|
30917
|
-
|
|
31195
|
+
path2 += `/${projectId}`;
|
|
30918
31196
|
} else if (projectName !== undefined) {
|
|
30919
31197
|
params.append("name", projectName);
|
|
30920
31198
|
} else {
|
|
30921
31199
|
throw new Error("Must provide projectName or projectId");
|
|
30922
31200
|
}
|
|
30923
31201
|
const response = await this.caller.call(async () => {
|
|
30924
|
-
const res = await this._fetch(`${this.apiUrl}${
|
|
31202
|
+
const res = await this._fetch(`${this.apiUrl}${path2}?${params}`, {
|
|
30925
31203
|
method: "GET",
|
|
30926
31204
|
headers: this.headers,
|
|
30927
31205
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
@@ -30944,13 +31222,13 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
30944
31222
|
}
|
|
30945
31223
|
}
|
|
30946
31224
|
async readProject({ projectId, projectName, includeStats }) {
|
|
30947
|
-
let
|
|
31225
|
+
let path2 = "/sessions";
|
|
30948
31226
|
const params = new URLSearchParams;
|
|
30949
31227
|
if (projectId !== undefined && projectName !== undefined) {
|
|
30950
31228
|
throw new Error("Must provide either projectName or projectId, not both");
|
|
30951
31229
|
} else if (projectId !== undefined) {
|
|
30952
31230
|
assertUuid(projectId);
|
|
30953
|
-
|
|
31231
|
+
path2 += `/${projectId}`;
|
|
30954
31232
|
} else if (projectName !== undefined) {
|
|
30955
31233
|
params.append("name", projectName);
|
|
30956
31234
|
} else {
|
|
@@ -30959,7 +31237,7 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
30959
31237
|
if (includeStats !== undefined) {
|
|
30960
31238
|
params.append("include_stats", includeStats.toString());
|
|
30961
31239
|
}
|
|
30962
|
-
const response = await this._get(
|
|
31240
|
+
const response = await this._get(path2, params);
|
|
30963
31241
|
let result;
|
|
30964
31242
|
if (Array.isArray(response)) {
|
|
30965
31243
|
if (response.length === 0) {
|
|
@@ -31122,19 +31400,19 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31122
31400
|
return result;
|
|
31123
31401
|
}
|
|
31124
31402
|
async readDataset({ datasetId, datasetName }) {
|
|
31125
|
-
let
|
|
31403
|
+
let path2 = "/datasets";
|
|
31126
31404
|
const params = new URLSearchParams({ limit: "1" });
|
|
31127
31405
|
if (datasetId && datasetName) {
|
|
31128
31406
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
31129
31407
|
} else if (datasetId) {
|
|
31130
31408
|
assertUuid(datasetId);
|
|
31131
|
-
|
|
31409
|
+
path2 += `/${datasetId}`;
|
|
31132
31410
|
} else if (datasetName) {
|
|
31133
31411
|
params.append("name", datasetName);
|
|
31134
31412
|
} else {
|
|
31135
31413
|
throw new Error("Must provide datasetName or datasetId");
|
|
31136
31414
|
}
|
|
31137
|
-
const response = await this._get(
|
|
31415
|
+
const response = await this._get(path2, params);
|
|
31138
31416
|
let result;
|
|
31139
31417
|
if (Array.isArray(response)) {
|
|
31140
31418
|
if (response.length === 0) {
|
|
@@ -31175,20 +31453,20 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31175
31453
|
return response;
|
|
31176
31454
|
}
|
|
31177
31455
|
async readDatasetOpenaiFinetuning({ datasetId, datasetName }) {
|
|
31178
|
-
const
|
|
31456
|
+
const path2 = "/datasets";
|
|
31179
31457
|
if (datasetId !== undefined) {} else if (datasetName !== undefined) {
|
|
31180
31458
|
datasetId = (await this.readDataset({ datasetName })).id;
|
|
31181
31459
|
} else {
|
|
31182
31460
|
throw new Error("Must provide either datasetName or datasetId");
|
|
31183
31461
|
}
|
|
31184
|
-
const response = await this._getResponse(`${
|
|
31462
|
+
const response = await this._getResponse(`${path2}/${datasetId}/openai_ft`);
|
|
31185
31463
|
const datasetText = await response.text();
|
|
31186
31464
|
const dataset = datasetText.trim().split(`
|
|
31187
31465
|
`).map((line) => JSON.parse(line));
|
|
31188
31466
|
return dataset;
|
|
31189
31467
|
}
|
|
31190
31468
|
async* listDatasets({ limit = 100, offset = 0, datasetIds, datasetName, datasetNameContains, metadata } = {}) {
|
|
31191
|
-
const
|
|
31469
|
+
const path2 = "/datasets";
|
|
31192
31470
|
const params = new URLSearchParams({
|
|
31193
31471
|
limit: limit.toString(),
|
|
31194
31472
|
offset: offset.toString()
|
|
@@ -31207,7 +31485,7 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31207
31485
|
if (metadata !== undefined) {
|
|
31208
31486
|
params.append("metadata", JSON.stringify(metadata));
|
|
31209
31487
|
}
|
|
31210
|
-
for await (const datasets of this._getPaginated(
|
|
31488
|
+
for await (const datasets of this._getPaginated(path2, params)) {
|
|
31211
31489
|
yield* datasets;
|
|
31212
31490
|
}
|
|
31213
31491
|
}
|
|
@@ -31256,7 +31534,7 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31256
31534
|
});
|
|
31257
31535
|
}
|
|
31258
31536
|
async deleteDataset({ datasetId, datasetName }) {
|
|
31259
|
-
let
|
|
31537
|
+
let path2 = "/datasets";
|
|
31260
31538
|
let datasetId_ = datasetId;
|
|
31261
31539
|
if (datasetId !== undefined && datasetName !== undefined) {
|
|
31262
31540
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
@@ -31266,18 +31544,18 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31266
31544
|
}
|
|
31267
31545
|
if (datasetId_ !== undefined) {
|
|
31268
31546
|
assertUuid(datasetId_);
|
|
31269
|
-
|
|
31547
|
+
path2 += `/${datasetId_}`;
|
|
31270
31548
|
} else {
|
|
31271
31549
|
throw new Error("Must provide datasetName or datasetId");
|
|
31272
31550
|
}
|
|
31273
31551
|
await this.caller.call(async () => {
|
|
31274
|
-
const res = await this._fetch(this.apiUrl +
|
|
31552
|
+
const res = await this._fetch(this.apiUrl + path2, {
|
|
31275
31553
|
method: "DELETE",
|
|
31276
31554
|
headers: this.headers,
|
|
31277
31555
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
31278
31556
|
...this.fetchOptions
|
|
31279
31557
|
});
|
|
31280
|
-
await raiseForStatus(res, `delete ${
|
|
31558
|
+
await raiseForStatus(res, `delete ${path2}`, true);
|
|
31281
31559
|
return res;
|
|
31282
31560
|
});
|
|
31283
31561
|
}
|
|
@@ -31438,8 +31716,8 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31438
31716
|
}
|
|
31439
31717
|
async readExample(exampleId) {
|
|
31440
31718
|
assertUuid(exampleId);
|
|
31441
|
-
const
|
|
31442
|
-
const rawExample = await this._get(
|
|
31719
|
+
const path2 = `/examples/${exampleId}`;
|
|
31720
|
+
const rawExample = await this._get(path2);
|
|
31443
31721
|
const { attachment_urls, ...rest } = rawExample;
|
|
31444
31722
|
const example = rest;
|
|
31445
31723
|
if (attachment_urls) {
|
|
@@ -31522,24 +31800,24 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31522
31800
|
}
|
|
31523
31801
|
async deleteExample(exampleId) {
|
|
31524
31802
|
assertUuid(exampleId);
|
|
31525
|
-
const
|
|
31803
|
+
const path2 = `/examples/${exampleId}`;
|
|
31526
31804
|
await this.caller.call(async () => {
|
|
31527
|
-
const res = await this._fetch(this.apiUrl +
|
|
31805
|
+
const res = await this._fetch(this.apiUrl + path2, {
|
|
31528
31806
|
method: "DELETE",
|
|
31529
31807
|
headers: this.headers,
|
|
31530
31808
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
31531
31809
|
...this.fetchOptions
|
|
31532
31810
|
});
|
|
31533
|
-
await raiseForStatus(res, `delete ${
|
|
31811
|
+
await raiseForStatus(res, `delete ${path2}`, true);
|
|
31534
31812
|
return res;
|
|
31535
31813
|
});
|
|
31536
31814
|
}
|
|
31537
31815
|
async deleteExamples(exampleIds, options) {
|
|
31538
31816
|
exampleIds.forEach((id) => assertUuid(id));
|
|
31539
31817
|
if (options?.hardDelete) {
|
|
31540
|
-
const
|
|
31818
|
+
const path2 = this._getPlatformEndpointPath("datasets/examples/delete");
|
|
31541
31819
|
await this.caller.call(async () => {
|
|
31542
|
-
const res = await this._fetch(`${this.apiUrl}${
|
|
31820
|
+
const res = await this._fetch(`${this.apiUrl}${path2}`, {
|
|
31543
31821
|
method: "POST",
|
|
31544
31822
|
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
31545
31823
|
body: JSON.stringify({
|
|
@@ -31761,21 +32039,21 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
31761
32039
|
}
|
|
31762
32040
|
async readFeedback(feedbackId) {
|
|
31763
32041
|
assertUuid(feedbackId);
|
|
31764
|
-
const
|
|
31765
|
-
const response = await this._get(
|
|
32042
|
+
const path2 = `/feedback/${feedbackId}`;
|
|
32043
|
+
const response = await this._get(path2);
|
|
31766
32044
|
return response;
|
|
31767
32045
|
}
|
|
31768
32046
|
async deleteFeedback(feedbackId) {
|
|
31769
32047
|
assertUuid(feedbackId);
|
|
31770
|
-
const
|
|
32048
|
+
const path2 = `/feedback/${feedbackId}`;
|
|
31771
32049
|
await this.caller.call(async () => {
|
|
31772
|
-
const res = await this._fetch(this.apiUrl +
|
|
32050
|
+
const res = await this._fetch(this.apiUrl + path2, {
|
|
31773
32051
|
method: "DELETE",
|
|
31774
32052
|
headers: this.headers,
|
|
31775
32053
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
31776
32054
|
...this.fetchOptions
|
|
31777
32055
|
});
|
|
31778
|
-
await raiseForStatus(res, `delete ${
|
|
32056
|
+
await raiseForStatus(res, `delete ${path2}`, true);
|
|
31779
32057
|
return res;
|
|
31780
32058
|
});
|
|
31781
32059
|
}
|
|
@@ -32435,7 +32713,11 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
32435
32713
|
});
|
|
32436
32714
|
return response.json();
|
|
32437
32715
|
}
|
|
32438
|
-
|
|
32716
|
+
_getPromptCacheKey(promptIdentifier, includeModel) {
|
|
32717
|
+
const suffix = includeModel ? ":with_model" : "";
|
|
32718
|
+
return `${promptIdentifier}${suffix}`;
|
|
32719
|
+
}
|
|
32720
|
+
async _fetchPromptFromApi(promptIdentifier, options) {
|
|
32439
32721
|
const [owner, promptName, commitHash] = parsePromptIdentifier(promptIdentifier);
|
|
32440
32722
|
const response = await this.caller.call(async () => {
|
|
32441
32723
|
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
|
|
@@ -32456,9 +32738,23 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
32456
32738
|
examples: result.examples
|
|
32457
32739
|
};
|
|
32458
32740
|
}
|
|
32741
|
+
async pullPromptCommit(promptIdentifier, options) {
|
|
32742
|
+
if (!options?.skipCache && this._cache) {
|
|
32743
|
+
const cacheKey = this._getPromptCacheKey(promptIdentifier, options?.includeModel);
|
|
32744
|
+
const cached = this._cache.get(cacheKey);
|
|
32745
|
+
if (cached) {
|
|
32746
|
+
return cached;
|
|
32747
|
+
}
|
|
32748
|
+
const result = await this._fetchPromptFromApi(promptIdentifier, options);
|
|
32749
|
+
this._cache.set(cacheKey, result);
|
|
32750
|
+
return result;
|
|
32751
|
+
}
|
|
32752
|
+
return this._fetchPromptFromApi(promptIdentifier, options);
|
|
32753
|
+
}
|
|
32459
32754
|
async _pullPrompt(promptIdentifier, options) {
|
|
32460
32755
|
const promptObject = await this.pullPromptCommit(promptIdentifier, {
|
|
32461
|
-
includeModel: options?.includeModel
|
|
32756
|
+
includeModel: options?.includeModel,
|
|
32757
|
+
skipCache: options?.skipCache
|
|
32462
32758
|
});
|
|
32463
32759
|
const prompt = JSON.stringify(promptObject.manifest);
|
|
32464
32760
|
return prompt;
|
|
@@ -32540,6 +32836,14 @@ Message: ${Array.isArray(result.detail) ? result.detail.join(`
|
|
|
32540
32836
|
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
32541
32837
|
}
|
|
32542
32838
|
}
|
|
32839
|
+
get cache() {
|
|
32840
|
+
return this._cache;
|
|
32841
|
+
}
|
|
32842
|
+
cleanup() {
|
|
32843
|
+
if (this._cache) {
|
|
32844
|
+
this._cache.stop();
|
|
32845
|
+
}
|
|
32846
|
+
}
|
|
32543
32847
|
async awaitPendingTraceBatches() {
|
|
32544
32848
|
if (this.manualFlushMode) {
|
|
32545
32849
|
console.warn("[WARNING]: When tracing in manual flush mode, you must call `await client.flush()` manually to submit trace batches.");
|
|
@@ -35261,13 +35565,13 @@ function isInteger(str) {
|
|
|
35261
35565
|
}
|
|
35262
35566
|
return true;
|
|
35263
35567
|
}
|
|
35264
|
-
function escapePathComponent(
|
|
35265
|
-
if (
|
|
35266
|
-
return
|
|
35267
|
-
return
|
|
35568
|
+
function escapePathComponent(path2) {
|
|
35569
|
+
if (path2.indexOf("/") === -1 && path2.indexOf("~") === -1)
|
|
35570
|
+
return path2;
|
|
35571
|
+
return path2.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
35268
35572
|
}
|
|
35269
|
-
function unescapePathComponent(
|
|
35270
|
-
return
|
|
35573
|
+
function unescapePathComponent(path2) {
|
|
35574
|
+
return path2.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
35271
35575
|
}
|
|
35272
35576
|
function hasUndefined(obj) {
|
|
35273
35577
|
if (obj === undefined)
|
|
@@ -35483,8 +35787,8 @@ function applyOperation(document2, operation, validateOperation = false, mutateD
|
|
|
35483
35787
|
} else {
|
|
35484
35788
|
if (!mutateDocument)
|
|
35485
35789
|
document2 = _deepClone(document2);
|
|
35486
|
-
const
|
|
35487
|
-
const keys =
|
|
35790
|
+
const path2 = operation.path || "";
|
|
35791
|
+
const keys = path2.split("/");
|
|
35488
35792
|
let obj = document2;
|
|
35489
35793
|
let t = 1;
|
|
35490
35794
|
let len = keys.length;
|
|
@@ -39963,10 +40267,10 @@ var Runnable = class extends Serializable {
|
|
|
39963
40267
|
}
|
|
39964
40268
|
const paths = log.ops.filter((op) => op.path.startsWith("/logs/")).map((op) => op.path.split("/")[2]);
|
|
39965
40269
|
const dedupedPaths = [...new Set(paths)];
|
|
39966
|
-
for (const
|
|
40270
|
+
for (const path2 of dedupedPaths) {
|
|
39967
40271
|
let eventType;
|
|
39968
40272
|
let data = {};
|
|
39969
|
-
const logEntry = runLog.state.logs[
|
|
40273
|
+
const logEntry = runLog.state.logs[path2];
|
|
39970
40274
|
if (logEntry.end_time === undefined)
|
|
39971
40275
|
if (logEntry.streamed_output.length > 0)
|
|
39972
40276
|
eventType = "stream";
|
|
@@ -42064,17 +42368,17 @@ function findEnvFile(startDir, filenames = [".env", ".env.local"]) {
|
|
|
42064
42368
|
if (typeof process === "undefined" || !process.cwd) {
|
|
42065
42369
|
return null;
|
|
42066
42370
|
}
|
|
42067
|
-
const
|
|
42068
|
-
const
|
|
42371
|
+
const fs2 = __require("node:fs");
|
|
42372
|
+
const path2 = __require("node:path");
|
|
42069
42373
|
let currentDir = startDir || process.cwd();
|
|
42070
42374
|
while (true) {
|
|
42071
42375
|
for (const filename of filenames) {
|
|
42072
|
-
const candidate =
|
|
42073
|
-
if (
|
|
42376
|
+
const candidate = path2.join(currentDir, filename);
|
|
42377
|
+
if (fs2.existsSync(candidate)) {
|
|
42074
42378
|
return candidate;
|
|
42075
42379
|
}
|
|
42076
42380
|
}
|
|
42077
|
-
const parentDir =
|
|
42381
|
+
const parentDir = path2.dirname(currentDir);
|
|
42078
42382
|
if (parentDir === currentDir) {
|
|
42079
42383
|
break;
|
|
42080
42384
|
}
|
|
@@ -44954,9 +45258,9 @@ var getContentTypeFromMimeType = (mimeType) => {
|
|
|
44954
45258
|
}
|
|
44955
45259
|
return;
|
|
44956
45260
|
};
|
|
44957
|
-
function getLocalServerUrl(
|
|
45261
|
+
function getLocalServerUrl(path2) {
|
|
44958
45262
|
const port = getEnv3("SERVER_PORT", "3000");
|
|
44959
|
-
return `http://localhost:${port}${
|
|
45263
|
+
return `http://localhost:${port}${path2}`;
|
|
44960
45264
|
}
|
|
44961
45265
|
// src/schemas/character.ts
|
|
44962
45266
|
import { z as z3 } from "zod";
|
|
@@ -45473,8 +45777,8 @@ class ActionStreamFilter {
|
|
|
45473
45777
|
// src/utils/paths.ts
|
|
45474
45778
|
var pathJoin = (...parts) => {
|
|
45475
45779
|
if (typeof process !== "undefined" && process.platform) {
|
|
45476
|
-
const
|
|
45477
|
-
return
|
|
45780
|
+
const path2 = __require("node:path");
|
|
45781
|
+
return path2.join(...parts);
|
|
45478
45782
|
}
|
|
45479
45783
|
return parts.filter((part) => part).join("/").replace(/\/+/g, "/").replace(/\/$/, "");
|
|
45480
45784
|
};
|
|
@@ -48076,66 +48380,41 @@ class AgentRuntime {
|
|
|
48076
48380
|
}
|
|
48077
48381
|
this.messageService = new DefaultMessageService;
|
|
48078
48382
|
const skipMigrations = options?.skipMigrations ?? false;
|
|
48079
|
-
if (skipMigrations) {
|
|
48080
|
-
this.logger.debug({ src: "agent", agentId: this.agentId }, "Skipping plugin migrations");
|
|
48081
|
-
} else {
|
|
48082
|
-
this.logger.debug({ src: "agent", agentId: this.agentId }, "Running plugin migrations");
|
|
48083
|
-
await this.runPluginMigrations();
|
|
48084
|
-
this.logger.debug({ src: "agent", agentId: this.agentId }, "Plugin migrations completed");
|
|
48085
|
-
}
|
|
48086
48383
|
const existingAgent = await this.ensureAgentExists({
|
|
48087
48384
|
...this.character,
|
|
48088
48385
|
id: this.agentId
|
|
48089
48386
|
});
|
|
48090
48387
|
if (!existingAgent) {
|
|
48091
|
-
|
|
48092
|
-
throw new Error(errorMsg);
|
|
48388
|
+
throw new Error(`Agent ${this.agentId} does not exist in database after ensureAgentExists`);
|
|
48093
48389
|
}
|
|
48094
|
-
|
|
48095
|
-
|
|
48096
|
-
|
|
48097
|
-
|
|
48098
|
-
|
|
48099
|
-
|
|
48100
|
-
|
|
48101
|
-
|
|
48102
|
-
|
|
48103
|
-
|
|
48104
|
-
|
|
48105
|
-
|
|
48106
|
-
}
|
|
48107
|
-
|
|
48108
|
-
|
|
48109
|
-
|
|
48110
|
-
if (value !== null && value !== undefined) {
|
|
48111
|
-
filteredSecrets[key] = value;
|
|
48112
|
-
}
|
|
48113
|
-
}
|
|
48114
|
-
if (Object.keys(filteredSecrets).length > 0) {
|
|
48115
|
-
this.character.secrets = filteredSecrets;
|
|
48116
|
-
this.character.settings.secrets = filteredSecrets;
|
|
48117
|
-
}
|
|
48118
|
-
}
|
|
48119
|
-
}
|
|
48120
|
-
let agentEntity = await this.getEntityById(this.agentId);
|
|
48121
|
-
if (!agentEntity) {
|
|
48122
|
-
const created = await this.createEntity({
|
|
48390
|
+
this.mergeAgentSettings(existingAgent);
|
|
48391
|
+
await Promise.all([
|
|
48392
|
+
this.ensureWorldExists({
|
|
48393
|
+
id: this.agentId,
|
|
48394
|
+
name: `${this.character.name}'s World`,
|
|
48395
|
+
agentId: this.agentId,
|
|
48396
|
+
messageServerId: this.agentId
|
|
48397
|
+
}),
|
|
48398
|
+
skipMigrations ? Promise.resolve() : (async () => {
|
|
48399
|
+
this.logger.debug({ src: "agent", agentId: this.agentId }, "Running plugin migrations");
|
|
48400
|
+
await this.runPluginMigrations();
|
|
48401
|
+
this.logger.debug({ src: "agent", agentId: this.agentId }, "Plugin migrations completed");
|
|
48402
|
+
})()
|
|
48403
|
+
]);
|
|
48404
|
+
const [agentEntity, existingRoom, participants] = await Promise.all([
|
|
48405
|
+
this.ensureEntity({
|
|
48123
48406
|
id: this.agentId,
|
|
48124
48407
|
names: [this.character.name],
|
|
48125
48408
|
metadata: {},
|
|
48126
48409
|
agentId: existingAgent.id
|
|
48127
|
-
})
|
|
48128
|
-
|
|
48129
|
-
|
|
48130
|
-
|
|
48131
|
-
|
|
48132
|
-
|
|
48133
|
-
if (!agentEntity)
|
|
48134
|
-
throw new Error(`Agent entity not found for ${this.agentId}`);
|
|
48135
|
-
this.logger.debug({ src: "agent", agentId: this.agentId }, "Agent entity created");
|
|
48410
|
+
}),
|
|
48411
|
+
this.getRoom(this.agentId),
|
|
48412
|
+
this.adapter.getParticipantsForRoom(this.agentId)
|
|
48413
|
+
]);
|
|
48414
|
+
if (!agentEntity) {
|
|
48415
|
+
throw new Error(`Failed to ensure entity for agent ${this.agentId}`);
|
|
48136
48416
|
}
|
|
48137
|
-
|
|
48138
|
-
if (!room) {
|
|
48417
|
+
if (!existingRoom) {
|
|
48139
48418
|
await this.createRoom({
|
|
48140
48419
|
id: this.agentId,
|
|
48141
48420
|
name: this.character.name,
|
|
@@ -48145,8 +48424,8 @@ class AgentRuntime {
|
|
|
48145
48424
|
messageServerId: this.agentId,
|
|
48146
48425
|
worldId: this.agentId
|
|
48147
48426
|
});
|
|
48427
|
+
this.logger.debug({ src: "agent", agentId: this.agentId }, "Agent room created");
|
|
48148
48428
|
}
|
|
48149
|
-
const participants = await this.adapter.getParticipantsForRoom(this.agentId);
|
|
48150
48429
|
if (!participants.includes(this.agentId)) {
|
|
48151
48430
|
const added = await this.addParticipant(this.agentId, this.agentId);
|
|
48152
48431
|
if (!added) {
|
|
@@ -48165,6 +48444,34 @@ class AgentRuntime {
|
|
|
48165
48444
|
this.initResolver = undefined;
|
|
48166
48445
|
}
|
|
48167
48446
|
}
|
|
48447
|
+
mergeAgentSettings(existingAgent) {
|
|
48448
|
+
if (!existingAgent.settings)
|
|
48449
|
+
return;
|
|
48450
|
+
this.character.settings = {
|
|
48451
|
+
...existingAgent.settings,
|
|
48452
|
+
...this.character.settings
|
|
48453
|
+
};
|
|
48454
|
+
const dbSecrets = existingAgent.settings.secrets && typeof existingAgent.settings.secrets === "object" ? existingAgent.settings.secrets : {};
|
|
48455
|
+
const settingsSecrets = this.character.settings.secrets && typeof this.character.settings.secrets === "object" ? this.character.settings.secrets : {};
|
|
48456
|
+
const characterSecrets = this.character.secrets && typeof this.character.secrets === "object" ? this.character.secrets : {};
|
|
48457
|
+
const mergedSecrets = {
|
|
48458
|
+
...dbSecrets,
|
|
48459
|
+
...characterSecrets,
|
|
48460
|
+
...settingsSecrets
|
|
48461
|
+
};
|
|
48462
|
+
if (Object.keys(mergedSecrets).length > 0) {
|
|
48463
|
+
const filteredSecrets = {};
|
|
48464
|
+
for (const [key, value] of Object.entries(mergedSecrets)) {
|
|
48465
|
+
if (value !== null && value !== undefined) {
|
|
48466
|
+
filteredSecrets[key] = value;
|
|
48467
|
+
}
|
|
48468
|
+
}
|
|
48469
|
+
if (Object.keys(filteredSecrets).length > 0) {
|
|
48470
|
+
this.character.secrets = filteredSecrets;
|
|
48471
|
+
this.character.settings.secrets = filteredSecrets;
|
|
48472
|
+
}
|
|
48473
|
+
}
|
|
48474
|
+
}
|
|
48168
48475
|
async runPluginMigrations() {
|
|
48169
48476
|
if (!this.adapter) {
|
|
48170
48477
|
this.logger.warn({ src: "agent", agentId: this.agentId }, "Database adapter not found, skipping plugin migrations");
|
|
@@ -48676,9 +48983,9 @@ class AgentRuntime {
|
|
|
48676
48983
|
chunks[chunks.length - 1].push(item);
|
|
48677
48984
|
return chunks;
|
|
48678
48985
|
}, []);
|
|
48679
|
-
const roomIds = rooms.map((
|
|
48986
|
+
const roomIds = rooms.map((r) => r.id);
|
|
48680
48987
|
const roomExistsCheck = await this.getRoomsByIds(roomIds);
|
|
48681
|
-
const roomsIdExists = roomExistsCheck?.map((
|
|
48988
|
+
const roomsIdExists = roomExistsCheck?.map((r) => r.id);
|
|
48682
48989
|
const roomsToCreate = roomIds.filter((id) => !roomsIdExists?.includes(id));
|
|
48683
48990
|
const rf = {
|
|
48684
48991
|
worldId: world.id,
|
|
@@ -48688,36 +48995,27 @@ class AgentRuntime {
|
|
|
48688
48995
|
};
|
|
48689
48996
|
if (roomsToCreate.length) {
|
|
48690
48997
|
this.logger.debug({ src: "agent", agentId: this.agentId, count: roomsToCreate.length }, "Creating rooms");
|
|
48691
|
-
const roomObjsToCreate = rooms.filter((
|
|
48998
|
+
const roomObjsToCreate = rooms.filter((r) => roomsToCreate.includes(r.id)).map((r) => ({ ...r, ...rf, type: r.type || "GROUP" /* GROUP */ }));
|
|
48692
48999
|
await this.createRooms(roomObjsToCreate);
|
|
48693
49000
|
}
|
|
48694
49001
|
const entityIds = entities.map((e) => e.id).filter((id) => id !== undefined);
|
|
48695
|
-
|
|
48696
|
-
|
|
48697
|
-
|
|
48698
|
-
|
|
48699
|
-
|
|
48700
|
-
|
|
48701
|
-
|
|
48702
|
-
|
|
48703
|
-
const wf = {
|
|
48704
|
-
worldId: world.id,
|
|
48705
|
-
messageServerId: world.messageServerId
|
|
48706
|
-
};
|
|
48707
|
-
if (entitiesToCreate.length) {
|
|
48708
|
-
this.logger.debug({ src: "agent", agentId: this.agentId, count: entitiesToCreate.length }, "Creating entities");
|
|
48709
|
-
const ef = {
|
|
48710
|
-
...r,
|
|
48711
|
-
...wf,
|
|
49002
|
+
if (entities.length) {
|
|
49003
|
+
this.logger.debug({ src: "agent", agentId: this.agentId, count: entities.length }, "Creating entities");
|
|
49004
|
+
const entityFields = {
|
|
49005
|
+
roomId: firstRoom.id,
|
|
49006
|
+
channelId: firstRoom.channelId,
|
|
49007
|
+
type: firstRoom.type,
|
|
49008
|
+
worldId: world.id,
|
|
49009
|
+
messageServerId: world.messageServerId,
|
|
48712
49010
|
source,
|
|
48713
49011
|
agentId: this.agentId
|
|
48714
49012
|
};
|
|
48715
|
-
const
|
|
49013
|
+
const entitiesWithFields = entities.filter((e) => e.id !== undefined).map((e) => ({
|
|
48716
49014
|
...e,
|
|
48717
|
-
...
|
|
49015
|
+
...entityFields,
|
|
48718
49016
|
metadata: e.metadata || {}
|
|
48719
49017
|
}));
|
|
48720
|
-
const batches = chunkArray(
|
|
49018
|
+
const batches = chunkArray(entitiesWithFields, 5000);
|
|
48721
49019
|
for (const batch of batches) {
|
|
48722
49020
|
await this.createEntities(batch);
|
|
48723
49021
|
}
|
|
@@ -48855,18 +49153,14 @@ class AgentRuntime {
|
|
|
48855
49153
|
return await this.adapter.addParticipantsRoom(entityIds, roomId);
|
|
48856
49154
|
}
|
|
48857
49155
|
async ensureWorldExists({ id, name, messageServerId, metadata }) {
|
|
48858
|
-
|
|
48859
|
-
|
|
48860
|
-
|
|
48861
|
-
|
|
48862
|
-
|
|
48863
|
-
|
|
48864
|
-
|
|
48865
|
-
|
|
48866
|
-
metadata
|
|
48867
|
-
});
|
|
48868
|
-
this.logger.debug({ src: "agent", agentId: this.agentId, worldId: id, messageServerId }, "World created");
|
|
48869
|
-
}
|
|
49156
|
+
this.logger.debug({ src: "agent", agentId: this.agentId, worldId: id, name, messageServerId }, "Ensuring world exists");
|
|
49157
|
+
await this.adapter.createWorld({
|
|
49158
|
+
id,
|
|
49159
|
+
name,
|
|
49160
|
+
agentId: this.agentId,
|
|
49161
|
+
messageServerId,
|
|
49162
|
+
metadata
|
|
49163
|
+
});
|
|
48870
49164
|
}
|
|
48871
49165
|
async ensureRoomExists({
|
|
48872
49166
|
id,
|
|
@@ -49404,16 +49698,18 @@ ${input}`;
|
|
|
49404
49698
|
if (!this.adapter) {
|
|
49405
49699
|
throw new Error("Database adapter not initialized before ensureEmbeddingDimension");
|
|
49406
49700
|
}
|
|
49407
|
-
|
|
49408
|
-
if (!model) {
|
|
49701
|
+
if (!this.getModel(ModelType.TEXT_EMBEDDING)) {
|
|
49409
49702
|
throw new Error("No TEXT_EMBEDDING model registered");
|
|
49410
49703
|
}
|
|
49411
|
-
const
|
|
49412
|
-
|
|
49413
|
-
|
|
49704
|
+
const providedDimension = this.getSetting("EMBEDDING_DIMENSION");
|
|
49705
|
+
const parsedDimension = Number(providedDimension);
|
|
49706
|
+
const useProvidedDimension = parsedDimension > 0;
|
|
49707
|
+
const dimension = useProvidedDimension ? parsedDimension : (await this.useModel(ModelType.TEXT_EMBEDDING, { text: "" }))?.length;
|
|
49708
|
+
if (!dimension) {
|
|
49709
|
+
throw new Error("Invalid embedding dimension");
|
|
49414
49710
|
}
|
|
49415
|
-
await this.adapter.ensureEmbeddingDimension(
|
|
49416
|
-
this.logger.debug({ src: "agent", agentId: this.agentId, dimension
|
|
49711
|
+
await this.adapter.ensureEmbeddingDimension(dimension);
|
|
49712
|
+
this.logger.debug({ src: "agent", agentId: this.agentId, dimension }, useProvidedDimension ? "Embedding dimension set from config" : "Embedding dimension set via API call");
|
|
49417
49713
|
}
|
|
49418
49714
|
registerTaskWorker(taskHandler) {
|
|
49419
49715
|
if (this.taskWorkers.has(taskHandler.name)) {
|
|
@@ -49511,6 +49807,14 @@ ${input}`;
|
|
|
49511
49807
|
}
|
|
49512
49808
|
return await this.createEntities([entity]);
|
|
49513
49809
|
}
|
|
49810
|
+
async ensureEntity(entity) {
|
|
49811
|
+
if (!entity.id)
|
|
49812
|
+
return null;
|
|
49813
|
+
const created = await this.createEntity(entity);
|
|
49814
|
+
if (!created)
|
|
49815
|
+
return null;
|
|
49816
|
+
return entity;
|
|
49817
|
+
}
|
|
49514
49818
|
async createEntities(entities) {
|
|
49515
49819
|
entities.forEach((e) => {
|
|
49516
49820
|
e.agentId = this.agentId;
|
|
@@ -51265,5 +51569,5 @@ export {
|
|
|
51265
51569
|
ActionStreamFilter
|
|
51266
51570
|
};
|
|
51267
51571
|
|
|
51268
|
-
//# debugId=
|
|
51572
|
+
//# debugId=9E4B3437FAC39D4E64756E2164756E21
|
|
51269
51573
|
//# sourceMappingURL=index.node.js.map
|