@posthog/ai 5.2.2 → 5.2.3
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/LICENSE +245 -0
- package/{lib → dist}/anthropic/index.cjs +7 -12
- package/{lib → dist}/anthropic/index.cjs.map +1 -1
- package/{lib → dist}/anthropic/index.mjs +4 -5
- package/{lib → dist}/anthropic/index.mjs.map +1 -1
- package/{lib → dist}/gemini/index.cjs +1 -1
- package/{lib → dist}/gemini/index.cjs.map +1 -1
- package/{lib → dist}/gemini/index.mjs.map +1 -1
- package/{lib → dist}/index.cjs +547 -479
- package/dist/index.cjs.map +1 -0
- package/{lib → dist}/index.mjs +530 -456
- package/dist/index.mjs.map +1 -0
- package/{lib → dist}/langchain/index.cjs +150 -110
- package/dist/langchain/index.cjs.map +1 -0
- package/{lib → dist}/langchain/index.mjs +147 -104
- package/dist/langchain/index.mjs.map +1 -0
- package/{lib → dist}/openai/index.cjs +7 -1
- package/dist/openai/index.cjs.map +1 -0
- package/{lib → dist}/openai/index.mjs +6 -0
- package/dist/openai/index.mjs.map +1 -0
- package/{lib → dist}/vercel/index.cjs +0 -2
- package/{lib → dist}/vercel/index.cjs.map +1 -1
- package/{lib → dist}/vercel/index.mjs.map +1 -1
- package/package.json +42 -33
- package/CHANGELOG.md +0 -89
- package/index.ts +0 -1
- package/lib/index.cjs.map +0 -1
- package/lib/index.mjs.map +0 -1
- package/lib/langchain/index.cjs.map +0 -1
- package/lib/langchain/index.mjs.map +0 -1
- package/lib/openai/index.cjs.map +0 -1
- package/lib/openai/index.mjs.map +0 -1
- package/src/anthropic/index.ts +0 -211
- package/src/gemini/index.ts +0 -254
- package/src/index.ts +0 -13
- package/src/langchain/callbacks.ts +0 -640
- package/src/langchain/index.ts +0 -1
- package/src/openai/azure.ts +0 -481
- package/src/openai/index.ts +0 -498
- package/src/utils.ts +0 -287
- package/src/vercel/index.ts +0 -1
- package/src/vercel/middleware.ts +0 -393
- package/tests/callbacks.test.ts +0 -48
- package/tests/gemini.test.ts +0 -344
- package/tests/openai.test.ts +0 -403
- package/tsconfig.json +0 -10
- /package/{lib → dist}/anthropic/index.d.ts +0 -0
- /package/{lib → dist}/gemini/index.d.ts +0 -0
- /package/{lib → dist}/gemini/index.mjs +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/langchain/index.d.ts +0 -0
- /package/{lib → dist}/openai/index.d.ts +0 -0
- /package/{lib → dist}/vercel/index.d.ts +0 -0
- /package/{lib → dist}/vercel/index.mjs +0 -0
package/{lib → dist}/index.mjs
RENAMED
|
@@ -48,7 +48,7 @@ const formatResponseOpenAI = response => {
|
|
|
48
48
|
return output;
|
|
49
49
|
};
|
|
50
50
|
const mergeSystemPrompt = (params, provider) => {
|
|
51
|
-
|
|
51
|
+
{
|
|
52
52
|
const messages = params.messages || [];
|
|
53
53
|
if (!params.system) {
|
|
54
54
|
return messages;
|
|
@@ -59,7 +59,6 @@ const mergeSystemPrompt = (params, provider) => {
|
|
|
59
59
|
content: systemMessage
|
|
60
60
|
}, ...messages];
|
|
61
61
|
}
|
|
62
|
-
return params.messages;
|
|
63
62
|
};
|
|
64
63
|
const withPrivacyMode = (client, privacyMode, input) => {
|
|
65
64
|
return client.privacy_mode || privacyMode ? null : input;
|
|
@@ -196,13 +195,13 @@ class PostHogOpenAI extends OpenAI {
|
|
|
196
195
|
this.responses = new WrappedResponses$1(this, this.phClient);
|
|
197
196
|
}
|
|
198
197
|
}
|
|
199
|
-
|
|
198
|
+
let WrappedChat$1 = class WrappedChat extends Chat {
|
|
200
199
|
constructor(parentClient, phClient) {
|
|
201
200
|
super(parentClient);
|
|
202
201
|
this.completions = new WrappedCompletions$1(parentClient, phClient);
|
|
203
202
|
}
|
|
204
|
-
}
|
|
205
|
-
|
|
203
|
+
};
|
|
204
|
+
let WrappedCompletions$1 = class WrappedCompletions extends Completions {
|
|
206
205
|
constructor(client, phClient) {
|
|
207
206
|
super(client);
|
|
208
207
|
this.phClient = phClient;
|
|
@@ -344,8 +343,8 @@ class WrappedCompletions$1 extends Completions {
|
|
|
344
343
|
return wrappedPromise;
|
|
345
344
|
}
|
|
346
345
|
}
|
|
347
|
-
}
|
|
348
|
-
|
|
346
|
+
};
|
|
347
|
+
let WrappedResponses$1 = class WrappedResponses extends Responses {
|
|
349
348
|
constructor(client, phClient) {
|
|
350
349
|
super(client);
|
|
351
350
|
this.phClient = phClient;
|
|
@@ -394,6 +393,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
394
393
|
client: this.phClient,
|
|
395
394
|
distinctId: posthogDistinctId,
|
|
396
395
|
traceId,
|
|
396
|
+
//@ts-expect-error
|
|
397
397
|
model: openAIParams.model,
|
|
398
398
|
provider: 'openai',
|
|
399
399
|
input: openAIParams.input,
|
|
@@ -410,6 +410,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
410
410
|
client: this.phClient,
|
|
411
411
|
distinctId: posthogDistinctId,
|
|
412
412
|
traceId,
|
|
413
|
+
//@ts-expect-error
|
|
413
414
|
model: openAIParams.model,
|
|
414
415
|
provider: 'openai',
|
|
415
416
|
input: openAIParams.input,
|
|
@@ -440,6 +441,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
440
441
|
client: this.phClient,
|
|
441
442
|
distinctId: posthogDistinctId,
|
|
442
443
|
traceId,
|
|
444
|
+
//@ts-expect-error
|
|
443
445
|
model: openAIParams.model,
|
|
444
446
|
provider: 'openai',
|
|
445
447
|
input: openAIParams.input,
|
|
@@ -463,6 +465,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
463
465
|
client: this.phClient,
|
|
464
466
|
distinctId: posthogDistinctId,
|
|
465
467
|
traceId,
|
|
468
|
+
//@ts-expect-error
|
|
466
469
|
model: openAIParams.model,
|
|
467
470
|
provider: 'openai',
|
|
468
471
|
input: openAIParams.input,
|
|
@@ -510,6 +513,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
510
513
|
client: this.phClient,
|
|
511
514
|
distinctId: posthogDistinctId,
|
|
512
515
|
traceId,
|
|
516
|
+
//@ts-expect-error
|
|
513
517
|
model: openAIParams.model,
|
|
514
518
|
provider: 'openai',
|
|
515
519
|
input: openAIParams.input,
|
|
@@ -532,6 +536,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
532
536
|
client: this.phClient,
|
|
533
537
|
distinctId: posthogDistinctId,
|
|
534
538
|
traceId,
|
|
539
|
+
//@ts-expect-error
|
|
535
540
|
model: openAIParams.model,
|
|
536
541
|
provider: 'openai',
|
|
537
542
|
input: openAIParams.input,
|
|
@@ -556,7 +561,7 @@ class WrappedResponses$1 extends Responses {
|
|
|
556
561
|
originalSelf.create = tempCreate;
|
|
557
562
|
}
|
|
558
563
|
}
|
|
559
|
-
}
|
|
564
|
+
};
|
|
560
565
|
|
|
561
566
|
class PostHogAzureOpenAI extends AzureOpenAI {
|
|
562
567
|
constructor(config) {
|
|
@@ -767,6 +772,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
767
772
|
client: this.phClient,
|
|
768
773
|
distinctId: posthogDistinctId,
|
|
769
774
|
traceId,
|
|
775
|
+
//@ts-expect-error
|
|
770
776
|
model: openAIParams.model,
|
|
771
777
|
provider: 'azure',
|
|
772
778
|
input: openAIParams.input,
|
|
@@ -783,6 +789,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
783
789
|
client: this.phClient,
|
|
784
790
|
distinctId: posthogDistinctId,
|
|
785
791
|
traceId,
|
|
792
|
+
//@ts-expect-error
|
|
786
793
|
model: openAIParams.model,
|
|
787
794
|
provider: 'azure',
|
|
788
795
|
input: openAIParams.input,
|
|
@@ -813,6 +820,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
813
820
|
client: this.phClient,
|
|
814
821
|
distinctId: posthogDistinctId,
|
|
815
822
|
traceId,
|
|
823
|
+
//@ts-expect-error
|
|
816
824
|
model: openAIParams.model,
|
|
817
825
|
provider: 'azure',
|
|
818
826
|
input: openAIParams.input,
|
|
@@ -836,6 +844,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
836
844
|
client: this.phClient,
|
|
837
845
|
distinctId: posthogDistinctId,
|
|
838
846
|
traceId,
|
|
847
|
+
//@ts-expect-error
|
|
839
848
|
model: openAIParams.model,
|
|
840
849
|
provider: 'azure',
|
|
841
850
|
input: openAIParams.input,
|
|
@@ -877,6 +886,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
877
886
|
client: this.phClient,
|
|
878
887
|
distinctId: posthogDistinctId,
|
|
879
888
|
traceId,
|
|
889
|
+
//@ts-expect-error
|
|
880
890
|
model: openAIParams.model,
|
|
881
891
|
provider: 'azure',
|
|
882
892
|
input: openAIParams.input,
|
|
@@ -899,6 +909,7 @@ class WrappedResponses extends AzureOpenAI.Responses {
|
|
|
899
909
|
client: this.phClient,
|
|
900
910
|
distinctId: posthogDistinctId,
|
|
901
911
|
traceId,
|
|
912
|
+
//@ts-expect-error
|
|
902
913
|
model: openAIParams.model,
|
|
903
914
|
provider: 'azure',
|
|
904
915
|
input: openAIParams.input,
|
|
@@ -1372,7 +1383,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1372
1383
|
traceId,
|
|
1373
1384
|
model: anthropicParams.model,
|
|
1374
1385
|
provider: 'anthropic',
|
|
1375
|
-
input: mergeSystemPrompt(anthropicParams
|
|
1386
|
+
input: mergeSystemPrompt(anthropicParams),
|
|
1376
1387
|
output: [],
|
|
1377
1388
|
latency: 0,
|
|
1378
1389
|
baseURL: this.baseURL ?? '',
|
|
@@ -1403,7 +1414,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1403
1414
|
traceId,
|
|
1404
1415
|
model: anthropicParams.model,
|
|
1405
1416
|
provider: 'anthropic',
|
|
1406
|
-
input: mergeSystemPrompt(anthropicParams
|
|
1417
|
+
input: mergeSystemPrompt(anthropicParams),
|
|
1407
1418
|
output: formatResponseAnthropic(result),
|
|
1408
1419
|
latency,
|
|
1409
1420
|
baseURL: this.baseURL ?? '',
|
|
@@ -1426,7 +1437,7 @@ class WrappedMessages extends AnthropicOriginal.Messages {
|
|
|
1426
1437
|
traceId,
|
|
1427
1438
|
model: anthropicParams.model,
|
|
1428
1439
|
provider: 'anthropic',
|
|
1429
|
-
input: mergeSystemPrompt(anthropicParams
|
|
1440
|
+
input: mergeSystemPrompt(anthropicParams),
|
|
1430
1441
|
output: [],
|
|
1431
1442
|
latency: 0,
|
|
1432
1443
|
baseURL: this.baseURL ?? '',
|
|
@@ -1675,461 +1686,521 @@ class WrappedModels {
|
|
|
1675
1686
|
}
|
|
1676
1687
|
}
|
|
1677
1688
|
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1689
|
+
function getDefaultExportFromCjs (x) {
|
|
1690
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
var decamelize;
|
|
1694
|
+
var hasRequiredDecamelize;
|
|
1695
|
+
|
|
1696
|
+
function requireDecamelize () {
|
|
1697
|
+
if (hasRequiredDecamelize) return decamelize;
|
|
1698
|
+
hasRequiredDecamelize = 1;
|
|
1699
|
+
decamelize = function (str, sep) {
|
|
1700
|
+
if (typeof str !== 'string') {
|
|
1701
|
+
throw new TypeError('Expected a string');
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
sep = typeof sep === 'undefined' ? '_' : sep;
|
|
1705
|
+
|
|
1706
|
+
return str
|
|
1707
|
+
.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
|
|
1708
|
+
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
|
|
1709
|
+
.toLowerCase();
|
|
1710
|
+
};
|
|
1711
|
+
return decamelize;
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
var decamelizeExports = requireDecamelize();
|
|
1715
|
+
var snakeCase = /*@__PURE__*/getDefaultExportFromCjs(decamelizeExports);
|
|
1688
1716
|
|
|
1689
1717
|
var camelcase = {exports: {}};
|
|
1690
1718
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
const
|
|
1698
|
-
const
|
|
1699
|
-
const
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
string => string.toUpperCase() :
|
|
1761
|
-
string => string.toLocaleUpperCase(options.locale);
|
|
1762
|
-
if (input.length === 1) {
|
|
1763
|
-
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
1764
|
-
}
|
|
1765
|
-
const hasUpperCase = input !== toLowerCase(input);
|
|
1766
|
-
if (hasUpperCase) {
|
|
1767
|
-
input = preserveCamelCase(input, toLowerCase, toUpperCase);
|
|
1768
|
-
}
|
|
1769
|
-
input = input.replace(LEADING_SEPARATORS, '');
|
|
1770
|
-
if (options.preserveConsecutiveUppercase) {
|
|
1771
|
-
input = preserveConsecutiveUppercase(input, toLowerCase);
|
|
1772
|
-
}
|
|
1773
|
-
else {
|
|
1774
|
-
input = toLowerCase(input);
|
|
1775
|
-
}
|
|
1776
|
-
if (options.pascalCase) {
|
|
1777
|
-
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
1778
|
-
}
|
|
1779
|
-
return postProcess(input, toUpperCase);
|
|
1780
|
-
};
|
|
1781
|
-
camelcase.exports = camelCase;
|
|
1782
|
-
// TODO: Remove this for the next major release
|
|
1783
|
-
camelcase.exports.default = camelCase;
|
|
1719
|
+
var hasRequiredCamelcase;
|
|
1720
|
+
|
|
1721
|
+
function requireCamelcase () {
|
|
1722
|
+
if (hasRequiredCamelcase) return camelcase.exports;
|
|
1723
|
+
hasRequiredCamelcase = 1;
|
|
1724
|
+
|
|
1725
|
+
const UPPERCASE = /[\p{Lu}]/u;
|
|
1726
|
+
const LOWERCASE = /[\p{Ll}]/u;
|
|
1727
|
+
const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
|
|
1728
|
+
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
1729
|
+
const SEPARATORS = /[_.\- ]+/;
|
|
1730
|
+
|
|
1731
|
+
const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
|
|
1732
|
+
const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
|
|
1733
|
+
const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
|
|
1734
|
+
|
|
1735
|
+
const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
|
|
1736
|
+
let isLastCharLower = false;
|
|
1737
|
+
let isLastCharUpper = false;
|
|
1738
|
+
let isLastLastCharUpper = false;
|
|
1739
|
+
|
|
1740
|
+
for (let i = 0; i < string.length; i++) {
|
|
1741
|
+
const character = string[i];
|
|
1742
|
+
|
|
1743
|
+
if (isLastCharLower && UPPERCASE.test(character)) {
|
|
1744
|
+
string = string.slice(0, i) + '-' + string.slice(i);
|
|
1745
|
+
isLastCharLower = false;
|
|
1746
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
1747
|
+
isLastCharUpper = true;
|
|
1748
|
+
i++;
|
|
1749
|
+
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
|
|
1750
|
+
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
1751
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
1752
|
+
isLastCharUpper = false;
|
|
1753
|
+
isLastCharLower = true;
|
|
1754
|
+
} else {
|
|
1755
|
+
isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
|
|
1756
|
+
isLastLastCharUpper = isLastCharUpper;
|
|
1757
|
+
isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
return string;
|
|
1762
|
+
};
|
|
1763
|
+
|
|
1764
|
+
const preserveConsecutiveUppercase = (input, toLowerCase) => {
|
|
1765
|
+
LEADING_CAPITAL.lastIndex = 0;
|
|
1766
|
+
|
|
1767
|
+
return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
|
|
1768
|
+
};
|
|
1769
|
+
|
|
1770
|
+
const postProcess = (input, toUpperCase) => {
|
|
1771
|
+
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
|
1772
|
+
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
|
1773
|
+
|
|
1774
|
+
return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
|
|
1775
|
+
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
const camelCase = (input, options) => {
|
|
1779
|
+
if (!(typeof input === 'string' || Array.isArray(input))) {
|
|
1780
|
+
throw new TypeError('Expected the input to be `string | string[]`');
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
options = {
|
|
1784
|
+
pascalCase: false,
|
|
1785
|
+
preserveConsecutiveUppercase: false,
|
|
1786
|
+
...options
|
|
1787
|
+
};
|
|
1784
1788
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1789
|
+
if (Array.isArray(input)) {
|
|
1790
|
+
input = input.map(x => x.trim())
|
|
1791
|
+
.filter(x => x.length)
|
|
1792
|
+
.join('-');
|
|
1793
|
+
} else {
|
|
1794
|
+
input = input.trim();
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
if (input.length === 0) {
|
|
1798
|
+
return '';
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
const toLowerCase = options.locale === false ?
|
|
1802
|
+
string => string.toLowerCase() :
|
|
1803
|
+
string => string.toLocaleLowerCase(options.locale);
|
|
1804
|
+
const toUpperCase = options.locale === false ?
|
|
1805
|
+
string => string.toUpperCase() :
|
|
1806
|
+
string => string.toLocaleUpperCase(options.locale);
|
|
1807
|
+
|
|
1808
|
+
if (input.length === 1) {
|
|
1809
|
+
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
const hasUpperCase = input !== toLowerCase(input);
|
|
1813
|
+
|
|
1814
|
+
if (hasUpperCase) {
|
|
1815
|
+
input = preserveCamelCase(input, toLowerCase, toUpperCase);
|
|
1816
|
+
}
|
|
1817
|
+
|
|
1818
|
+
input = input.replace(LEADING_SEPARATORS, '');
|
|
1819
|
+
|
|
1820
|
+
if (options.preserveConsecutiveUppercase) {
|
|
1821
|
+
input = preserveConsecutiveUppercase(input, toLowerCase);
|
|
1822
|
+
} else {
|
|
1823
|
+
input = toLowerCase(input);
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
if (options.pascalCase) {
|
|
1827
|
+
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
return postProcess(input, toUpperCase);
|
|
1831
|
+
};
|
|
1832
|
+
|
|
1833
|
+
camelcase.exports = camelCase;
|
|
1834
|
+
// TODO: Remove this for the next major release
|
|
1835
|
+
camelcase.exports.default = camelCase;
|
|
1836
|
+
return camelcase.exports;
|
|
1796
1837
|
}
|
|
1797
1838
|
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
*
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
*
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1839
|
+
requireCamelcase();
|
|
1840
|
+
|
|
1841
|
+
function keyToJson(key, map) {
|
|
1842
|
+
return map?.[key] || snakeCase(key);
|
|
1843
|
+
}
|
|
1844
|
+
function mapKeys(fields, mapper, map) {
|
|
1845
|
+
const mapped = {};
|
|
1846
|
+
for (const key in fields) {
|
|
1847
|
+
if (Object.hasOwn(fields, key)) {
|
|
1848
|
+
mapped[mapper(key, map)] = fields[key];
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return mapped;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
function shallowCopy(obj) {
|
|
1855
|
+
return Array.isArray(obj) ? [...obj] : { ...obj };
|
|
1856
|
+
}
|
|
1857
|
+
function replaceSecrets(root, secretsMap) {
|
|
1858
|
+
const result = shallowCopy(root);
|
|
1859
|
+
for (const [path, secretId] of Object.entries(secretsMap)) {
|
|
1860
|
+
const [last, ...partsReverse] = path.split(".").reverse();
|
|
1861
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1862
|
+
let current = result;
|
|
1863
|
+
for (const part of partsReverse.reverse()) {
|
|
1864
|
+
if (current[part] === undefined) {
|
|
1865
|
+
break;
|
|
1866
|
+
}
|
|
1867
|
+
current[part] = shallowCopy(current[part]);
|
|
1868
|
+
current = current[part];
|
|
1869
|
+
}
|
|
1870
|
+
if (current[last] !== undefined) {
|
|
1871
|
+
current[last] = {
|
|
1872
|
+
lc: 1,
|
|
1873
|
+
type: "secret",
|
|
1874
|
+
id: [secretId],
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return result;
|
|
1879
|
+
}
|
|
1880
|
+
/**
|
|
1881
|
+
* Get a unique name for the module, rather than parent class implementations.
|
|
1882
|
+
* Should not be subclassed, subclass lc_name above instead.
|
|
1883
|
+
*/
|
|
1884
|
+
function get_lc_unique_name(
|
|
1885
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1886
|
+
serializableClass) {
|
|
1887
|
+
// "super" here would refer to the parent class of Serializable,
|
|
1888
|
+
// when we want the parent class of the module actually calling this method.
|
|
1889
|
+
const parentClass = Object.getPrototypeOf(serializableClass);
|
|
1890
|
+
const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
|
|
1891
|
+
(typeof parentClass.lc_name !== "function" ||
|
|
1892
|
+
serializableClass.lc_name() !== parentClass.lc_name());
|
|
1893
|
+
if (lcNameIsSubclassed) {
|
|
1894
|
+
return serializableClass.lc_name();
|
|
1895
|
+
}
|
|
1896
|
+
else {
|
|
1897
|
+
return serializableClass.name;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
class Serializable {
|
|
1901
|
+
/**
|
|
1902
|
+
* The name of the serializable. Override to provide an alias or
|
|
1903
|
+
* to preserve the serialized module name in minified environments.
|
|
1904
|
+
*
|
|
1905
|
+
* Implemented as a static method to support loading logic.
|
|
1906
|
+
*/
|
|
1907
|
+
static lc_name() {
|
|
1908
|
+
return this.name;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* The final serialized identifier for the module.
|
|
1912
|
+
*/
|
|
1913
|
+
get lc_id() {
|
|
1914
|
+
return [
|
|
1915
|
+
...this.lc_namespace,
|
|
1916
|
+
get_lc_unique_name(this.constructor),
|
|
1917
|
+
];
|
|
1918
|
+
}
|
|
1919
|
+
/**
|
|
1920
|
+
* A map of secrets, which will be omitted from serialization.
|
|
1921
|
+
* Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
|
|
1922
|
+
* Values are the secret ids, which will be used when deserializing.
|
|
1923
|
+
*/
|
|
1924
|
+
get lc_secrets() {
|
|
1925
|
+
return undefined;
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* A map of additional attributes to merge with constructor args.
|
|
1929
|
+
* Keys are the attribute names, e.g. "foo".
|
|
1930
|
+
* Values are the attribute values, which will be serialized.
|
|
1931
|
+
* These attributes need to be accepted by the constructor as arguments.
|
|
1932
|
+
*/
|
|
1933
|
+
get lc_attributes() {
|
|
1934
|
+
return undefined;
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* A map of aliases for constructor args.
|
|
1938
|
+
* Keys are the attribute names, e.g. "foo".
|
|
1939
|
+
* Values are the alias that will replace the key in serialization.
|
|
1940
|
+
* This is used to eg. make argument names match Python.
|
|
1941
|
+
*/
|
|
1942
|
+
get lc_aliases() {
|
|
1943
|
+
return undefined;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* A manual list of keys that should be serialized.
|
|
1947
|
+
* If not overridden, all fields passed into the constructor will be serialized.
|
|
1948
|
+
*/
|
|
1949
|
+
get lc_serializable_keys() {
|
|
1950
|
+
return undefined;
|
|
1951
|
+
}
|
|
1952
|
+
constructor(kwargs, ..._args) {
|
|
1953
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
1954
|
+
enumerable: true,
|
|
1955
|
+
configurable: true,
|
|
1956
|
+
writable: true,
|
|
1957
|
+
value: false
|
|
1958
|
+
});
|
|
1959
|
+
Object.defineProperty(this, "lc_kwargs", {
|
|
1960
|
+
enumerable: true,
|
|
1961
|
+
configurable: true,
|
|
1962
|
+
writable: true,
|
|
1963
|
+
value: void 0
|
|
1964
|
+
});
|
|
1965
|
+
if (this.lc_serializable_keys !== undefined) {
|
|
1966
|
+
this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
|
|
1967
|
+
}
|
|
1968
|
+
else {
|
|
1969
|
+
this.lc_kwargs = kwargs ?? {};
|
|
1970
|
+
}
|
|
1971
|
+
}
|
|
1972
|
+
toJSON() {
|
|
1973
|
+
if (!this.lc_serializable) {
|
|
1974
|
+
return this.toJSONNotImplemented();
|
|
1975
|
+
}
|
|
1976
|
+
if (
|
|
1977
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
1978
|
+
this.lc_kwargs instanceof Serializable ||
|
|
1979
|
+
typeof this.lc_kwargs !== "object" ||
|
|
1980
|
+
Array.isArray(this.lc_kwargs)) {
|
|
1981
|
+
// We do not support serialization of classes with arg not a POJO
|
|
1982
|
+
// I'm aware the check above isn't as strict as it could be
|
|
1983
|
+
return this.toJSONNotImplemented();
|
|
1984
|
+
}
|
|
1985
|
+
const aliases = {};
|
|
1986
|
+
const secrets = {};
|
|
1987
|
+
const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
|
|
1988
|
+
acc[key] = key in this ? this[key] : this.lc_kwargs[key];
|
|
1989
|
+
return acc;
|
|
1990
|
+
}, {});
|
|
1991
|
+
// get secrets, attributes and aliases from all superclasses
|
|
1992
|
+
for (
|
|
1993
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1994
|
+
let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
|
|
1995
|
+
Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
|
|
1996
|
+
Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
|
|
1997
|
+
Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
|
|
1998
|
+
}
|
|
1999
|
+
// include all secrets used, even if not in kwargs,
|
|
2000
|
+
// will be replaced with sentinel value in replaceSecrets
|
|
2001
|
+
Object.keys(secrets).forEach((keyPath) => {
|
|
2002
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
|
|
2003
|
+
let read = this;
|
|
2004
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2005
|
+
let write = kwargs;
|
|
2006
|
+
const [last, ...partsReverse] = keyPath.split(".").reverse();
|
|
2007
|
+
for (const key of partsReverse.reverse()) {
|
|
2008
|
+
if (!(key in read) || read[key] === undefined)
|
|
2009
|
+
return;
|
|
2010
|
+
if (!(key in write) || write[key] === undefined) {
|
|
2011
|
+
if (typeof read[key] === "object" && read[key] != null) {
|
|
2012
|
+
write[key] = {};
|
|
2013
|
+
}
|
|
2014
|
+
else if (Array.isArray(read[key])) {
|
|
2015
|
+
write[key] = [];
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
read = read[key];
|
|
2019
|
+
write = write[key];
|
|
2020
|
+
}
|
|
2021
|
+
if (last in read && read[last] !== undefined) {
|
|
2022
|
+
write[last] = write[last] || read[last];
|
|
2023
|
+
}
|
|
2024
|
+
});
|
|
2025
|
+
return {
|
|
2026
|
+
lc: 1,
|
|
2027
|
+
type: "constructor",
|
|
2028
|
+
id: this.lc_id,
|
|
2029
|
+
kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
toJSONNotImplemented() {
|
|
2033
|
+
return {
|
|
2034
|
+
lc: 1,
|
|
2035
|
+
type: "not_implemented",
|
|
2036
|
+
id: this.lc_id,
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
1971
2039
|
}
|
|
1972
2040
|
|
|
1973
|
-
// Supabase Edge Function provides a `Deno` global object
|
|
1974
|
-
// without `version` property
|
|
1975
|
-
const isDeno = () => typeof Deno !== "undefined";
|
|
1976
|
-
function getEnvironmentVariable(name) {
|
|
1977
|
-
// Certain Deno setups will throw an error if you try to access environment variables
|
|
1978
|
-
// https://github.com/langchain-ai/langchainjs/issues/1412
|
|
1979
|
-
try {
|
|
1980
|
-
if (typeof process !== "undefined") {
|
|
1981
|
-
// eslint-disable-next-line no-process-env
|
|
1982
|
-
return process.env?.[name];
|
|
1983
|
-
}
|
|
1984
|
-
else if (isDeno()) {
|
|
1985
|
-
return Deno?.env.get(name);
|
|
1986
|
-
}
|
|
1987
|
-
else {
|
|
1988
|
-
return undefined;
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
catch (e) {
|
|
1992
|
-
return undefined;
|
|
1993
|
-
}
|
|
2041
|
+
// Supabase Edge Function provides a `Deno` global object
|
|
2042
|
+
// without `version` property
|
|
2043
|
+
const isDeno = () => typeof Deno !== "undefined";
|
|
2044
|
+
function getEnvironmentVariable(name) {
|
|
2045
|
+
// Certain Deno setups will throw an error if you try to access environment variables
|
|
2046
|
+
// https://github.com/langchain-ai/langchainjs/issues/1412
|
|
2047
|
+
try {
|
|
2048
|
+
if (typeof process !== "undefined") {
|
|
2049
|
+
// eslint-disable-next-line no-process-env
|
|
2050
|
+
return process.env?.[name];
|
|
2051
|
+
}
|
|
2052
|
+
else if (isDeno()) {
|
|
2053
|
+
return Deno?.env.get(name);
|
|
2054
|
+
}
|
|
2055
|
+
else {
|
|
2056
|
+
return undefined;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
catch (e) {
|
|
2060
|
+
return undefined;
|
|
2061
|
+
}
|
|
1994
2062
|
}
|
|
1995
2063
|
|
|
1996
|
-
/**
|
|
1997
|
-
* Abstract class that provides a set of optional methods that can be
|
|
1998
|
-
* overridden in derived classes to handle various events during the
|
|
1999
|
-
* execution of a LangChain application.
|
|
2000
|
-
*/
|
|
2001
|
-
class BaseCallbackHandlerMethodsClass {
|
|
2002
|
-
}
|
|
2003
|
-
/**
|
|
2004
|
-
* Abstract base class for creating callback handlers in the LangChain
|
|
2005
|
-
* framework. It provides a set of optional methods that can be overridden
|
|
2006
|
-
* in derived classes to handle various events during the execution of a
|
|
2007
|
-
* LangChain application.
|
|
2008
|
-
*/
|
|
2009
|
-
class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
|
|
2010
|
-
get lc_namespace() {
|
|
2011
|
-
return ["langchain_core", "callbacks", this.name];
|
|
2012
|
-
}
|
|
2013
|
-
get lc_secrets() {
|
|
2014
|
-
return undefined;
|
|
2015
|
-
}
|
|
2016
|
-
get lc_attributes() {
|
|
2017
|
-
return undefined;
|
|
2018
|
-
}
|
|
2019
|
-
get lc_aliases() {
|
|
2020
|
-
return undefined;
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
*
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
this.
|
|
2102
|
-
this.
|
|
2103
|
-
|
|
2104
|
-
this.
|
|
2105
|
-
this.
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
}
|
|
2112
|
-
|
|
2113
|
-
return
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
return Serializable.prototype.
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2064
|
+
/**
|
|
2065
|
+
* Abstract class that provides a set of optional methods that can be
|
|
2066
|
+
* overridden in derived classes to handle various events during the
|
|
2067
|
+
* execution of a LangChain application.
|
|
2068
|
+
*/
|
|
2069
|
+
class BaseCallbackHandlerMethodsClass {
|
|
2070
|
+
}
|
|
2071
|
+
/**
|
|
2072
|
+
* Abstract base class for creating callback handlers in the LangChain
|
|
2073
|
+
* framework. It provides a set of optional methods that can be overridden
|
|
2074
|
+
* in derived classes to handle various events during the execution of a
|
|
2075
|
+
* LangChain application.
|
|
2076
|
+
*/
|
|
2077
|
+
class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
|
|
2078
|
+
get lc_namespace() {
|
|
2079
|
+
return ["langchain_core", "callbacks", this.name];
|
|
2080
|
+
}
|
|
2081
|
+
get lc_secrets() {
|
|
2082
|
+
return undefined;
|
|
2083
|
+
}
|
|
2084
|
+
get lc_attributes() {
|
|
2085
|
+
return undefined;
|
|
2086
|
+
}
|
|
2087
|
+
get lc_aliases() {
|
|
2088
|
+
return undefined;
|
|
2089
|
+
}
|
|
2090
|
+
get lc_serializable_keys() {
|
|
2091
|
+
return undefined;
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* The name of the serializable. Override to provide an alias or
|
|
2095
|
+
* to preserve the serialized module name in minified environments.
|
|
2096
|
+
*
|
|
2097
|
+
* Implemented as a static method to support loading logic.
|
|
2098
|
+
*/
|
|
2099
|
+
static lc_name() {
|
|
2100
|
+
return this.name;
|
|
2101
|
+
}
|
|
2102
|
+
/**
|
|
2103
|
+
* The final serialized identifier for the module.
|
|
2104
|
+
*/
|
|
2105
|
+
get lc_id() {
|
|
2106
|
+
return [
|
|
2107
|
+
...this.lc_namespace,
|
|
2108
|
+
get_lc_unique_name(this.constructor),
|
|
2109
|
+
];
|
|
2110
|
+
}
|
|
2111
|
+
constructor(input) {
|
|
2112
|
+
super();
|
|
2113
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
2114
|
+
enumerable: true,
|
|
2115
|
+
configurable: true,
|
|
2116
|
+
writable: true,
|
|
2117
|
+
value: false
|
|
2118
|
+
});
|
|
2119
|
+
Object.defineProperty(this, "lc_kwargs", {
|
|
2120
|
+
enumerable: true,
|
|
2121
|
+
configurable: true,
|
|
2122
|
+
writable: true,
|
|
2123
|
+
value: void 0
|
|
2124
|
+
});
|
|
2125
|
+
Object.defineProperty(this, "ignoreLLM", {
|
|
2126
|
+
enumerable: true,
|
|
2127
|
+
configurable: true,
|
|
2128
|
+
writable: true,
|
|
2129
|
+
value: false
|
|
2130
|
+
});
|
|
2131
|
+
Object.defineProperty(this, "ignoreChain", {
|
|
2132
|
+
enumerable: true,
|
|
2133
|
+
configurable: true,
|
|
2134
|
+
writable: true,
|
|
2135
|
+
value: false
|
|
2136
|
+
});
|
|
2137
|
+
Object.defineProperty(this, "ignoreAgent", {
|
|
2138
|
+
enumerable: true,
|
|
2139
|
+
configurable: true,
|
|
2140
|
+
writable: true,
|
|
2141
|
+
value: false
|
|
2142
|
+
});
|
|
2143
|
+
Object.defineProperty(this, "ignoreRetriever", {
|
|
2144
|
+
enumerable: true,
|
|
2145
|
+
configurable: true,
|
|
2146
|
+
writable: true,
|
|
2147
|
+
value: false
|
|
2148
|
+
});
|
|
2149
|
+
Object.defineProperty(this, "ignoreCustomEvent", {
|
|
2150
|
+
enumerable: true,
|
|
2151
|
+
configurable: true,
|
|
2152
|
+
writable: true,
|
|
2153
|
+
value: false
|
|
2154
|
+
});
|
|
2155
|
+
Object.defineProperty(this, "raiseError", {
|
|
2156
|
+
enumerable: true,
|
|
2157
|
+
configurable: true,
|
|
2158
|
+
writable: true,
|
|
2159
|
+
value: false
|
|
2160
|
+
});
|
|
2161
|
+
Object.defineProperty(this, "awaitHandlers", {
|
|
2162
|
+
enumerable: true,
|
|
2163
|
+
configurable: true,
|
|
2164
|
+
writable: true,
|
|
2165
|
+
value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
|
|
2166
|
+
});
|
|
2167
|
+
this.lc_kwargs = input || {};
|
|
2168
|
+
if (input) {
|
|
2169
|
+
this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
|
|
2170
|
+
this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
|
|
2171
|
+
this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
|
|
2172
|
+
this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
|
|
2173
|
+
this.ignoreCustomEvent =
|
|
2174
|
+
input.ignoreCustomEvent ?? this.ignoreCustomEvent;
|
|
2175
|
+
this.raiseError = input.raiseError ?? this.raiseError;
|
|
2176
|
+
this.awaitHandlers =
|
|
2177
|
+
this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
|
|
2178
|
+
}
|
|
2179
|
+
}
|
|
2180
|
+
copy() {
|
|
2181
|
+
return new this.constructor(this);
|
|
2182
|
+
}
|
|
2183
|
+
toJSON() {
|
|
2184
|
+
return Serializable.prototype.toJSON.call(this);
|
|
2185
|
+
}
|
|
2186
|
+
toJSONNotImplemented() {
|
|
2187
|
+
return Serializable.prototype.toJSONNotImplemented.call(this);
|
|
2188
|
+
}
|
|
2189
|
+
static fromMethods(methods) {
|
|
2190
|
+
class Handler extends BaseCallbackHandler {
|
|
2191
|
+
constructor() {
|
|
2192
|
+
super();
|
|
2193
|
+
Object.defineProperty(this, "name", {
|
|
2194
|
+
enumerable: true,
|
|
2195
|
+
configurable: true,
|
|
2196
|
+
writable: true,
|
|
2197
|
+
value: uuid.v4()
|
|
2198
|
+
});
|
|
2199
|
+
Object.assign(this, methods);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return new Handler();
|
|
2203
|
+
}
|
|
2133
2204
|
}
|
|
2134
2205
|
|
|
2135
2206
|
class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
@@ -2309,6 +2380,9 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
|
2309
2380
|
};
|
|
2310
2381
|
if (extraParams) {
|
|
2311
2382
|
generation.modelParams = getModelParams(extraParams.invocation_params);
|
|
2383
|
+
if (extraParams.invocation_params.tools) {
|
|
2384
|
+
generation.tools = extraParams.invocation_params.tools;
|
|
2385
|
+
}
|
|
2312
2386
|
}
|
|
2313
2387
|
if (metadata) {
|
|
2314
2388
|
if (metadata.ls_model_name) {
|