@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.
Files changed (54) hide show
  1. package/LICENSE +245 -0
  2. package/{lib → dist}/anthropic/index.cjs +7 -12
  3. package/{lib → dist}/anthropic/index.cjs.map +1 -1
  4. package/{lib → dist}/anthropic/index.mjs +4 -5
  5. package/{lib → dist}/anthropic/index.mjs.map +1 -1
  6. package/{lib → dist}/gemini/index.cjs +1 -1
  7. package/{lib → dist}/gemini/index.cjs.map +1 -1
  8. package/{lib → dist}/gemini/index.mjs.map +1 -1
  9. package/{lib → dist}/index.cjs +547 -479
  10. package/dist/index.cjs.map +1 -0
  11. package/{lib → dist}/index.mjs +530 -456
  12. package/dist/index.mjs.map +1 -0
  13. package/{lib → dist}/langchain/index.cjs +150 -110
  14. package/dist/langchain/index.cjs.map +1 -0
  15. package/{lib → dist}/langchain/index.mjs +147 -104
  16. package/dist/langchain/index.mjs.map +1 -0
  17. package/{lib → dist}/openai/index.cjs +7 -1
  18. package/dist/openai/index.cjs.map +1 -0
  19. package/{lib → dist}/openai/index.mjs +6 -0
  20. package/dist/openai/index.mjs.map +1 -0
  21. package/{lib → dist}/vercel/index.cjs +0 -2
  22. package/{lib → dist}/vercel/index.cjs.map +1 -1
  23. package/{lib → dist}/vercel/index.mjs.map +1 -1
  24. package/package.json +42 -33
  25. package/CHANGELOG.md +0 -89
  26. package/index.ts +0 -1
  27. package/lib/index.cjs.map +0 -1
  28. package/lib/index.mjs.map +0 -1
  29. package/lib/langchain/index.cjs.map +0 -1
  30. package/lib/langchain/index.mjs.map +0 -1
  31. package/lib/openai/index.cjs.map +0 -1
  32. package/lib/openai/index.mjs.map +0 -1
  33. package/src/anthropic/index.ts +0 -211
  34. package/src/gemini/index.ts +0 -254
  35. package/src/index.ts +0 -13
  36. package/src/langchain/callbacks.ts +0 -640
  37. package/src/langchain/index.ts +0 -1
  38. package/src/openai/azure.ts +0 -481
  39. package/src/openai/index.ts +0 -498
  40. package/src/utils.ts +0 -287
  41. package/src/vercel/index.ts +0 -1
  42. package/src/vercel/middleware.ts +0 -393
  43. package/tests/callbacks.test.ts +0 -48
  44. package/tests/gemini.test.ts +0 -344
  45. package/tests/openai.test.ts +0 -403
  46. package/tsconfig.json +0 -10
  47. /package/{lib → dist}/anthropic/index.d.ts +0 -0
  48. /package/{lib → dist}/gemini/index.d.ts +0 -0
  49. /package/{lib → dist}/gemini/index.mjs +0 -0
  50. /package/{lib → dist}/index.d.ts +0 -0
  51. /package/{lib → dist}/langchain/index.d.ts +0 -0
  52. /package/{lib → dist}/openai/index.d.ts +0 -0
  53. /package/{lib → dist}/vercel/index.d.ts +0 -0
  54. /package/{lib → dist}/vercel/index.mjs +0 -0
@@ -48,7 +48,7 @@ const formatResponseOpenAI = response => {
48
48
  return output;
49
49
  };
50
50
  const mergeSystemPrompt = (params, provider) => {
51
- if (provider == 'anthropic') {
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
- class WrappedChat$1 extends Chat {
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
- class WrappedCompletions$1 extends Completions {
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
- class WrappedResponses$1 extends Responses {
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, 'anthropic'),
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, 'anthropic'),
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, 'anthropic'),
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
- var decamelize = function (str, sep) {
1679
- if (typeof str !== 'string') {
1680
- throw new TypeError('Expected a string');
1681
- }
1682
- sep = typeof sep === 'undefined' ? '_' : sep;
1683
- return str
1684
- .replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
1685
- .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
1686
- .toLowerCase();
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
- const UPPERCASE = /[\p{Lu}]/u;
1692
- const LOWERCASE = /[\p{Ll}]/u;
1693
- const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
1694
- const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
1695
- const SEPARATORS = /[_.\- ]+/;
1696
- const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
1697
- const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
1698
- const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
1699
- const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
1700
- let isLastCharLower = false;
1701
- let isLastCharUpper = false;
1702
- let isLastLastCharUpper = false;
1703
- for (let i = 0; i < string.length; i++) {
1704
- const character = string[i];
1705
- if (isLastCharLower && UPPERCASE.test(character)) {
1706
- string = string.slice(0, i) + '-' + string.slice(i);
1707
- isLastCharLower = false;
1708
- isLastLastCharUpper = isLastCharUpper;
1709
- isLastCharUpper = true;
1710
- i++;
1711
- }
1712
- else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
1713
- string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
1714
- isLastLastCharUpper = isLastCharUpper;
1715
- isLastCharUpper = false;
1716
- isLastCharLower = true;
1717
- }
1718
- else {
1719
- isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
1720
- isLastLastCharUpper = isLastCharUpper;
1721
- isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
1722
- }
1723
- }
1724
- return string;
1725
- };
1726
- const preserveConsecutiveUppercase = (input, toLowerCase) => {
1727
- LEADING_CAPITAL.lastIndex = 0;
1728
- return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
1729
- };
1730
- const postProcess = (input, toUpperCase) => {
1731
- SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
1732
- NUMBERS_AND_IDENTIFIER.lastIndex = 0;
1733
- return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
1734
- .replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
1735
- };
1736
- const camelCase = (input, options) => {
1737
- if (!(typeof input === 'string' || Array.isArray(input))) {
1738
- throw new TypeError('Expected the input to be `string | string[]`');
1739
- }
1740
- options = {
1741
- pascalCase: false,
1742
- preserveConsecutiveUppercase: false,
1743
- ...options
1744
- };
1745
- if (Array.isArray(input)) {
1746
- input = input.map(x => x.trim())
1747
- .filter(x => x.length)
1748
- .join('-');
1749
- }
1750
- else {
1751
- input = input.trim();
1752
- }
1753
- if (input.length === 0) {
1754
- return '';
1755
- }
1756
- const toLowerCase = options.locale === false ?
1757
- string => string.toLowerCase() :
1758
- string => string.toLocaleLowerCase(options.locale);
1759
- const toUpperCase = options.locale === false ?
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
- function keyToJson(key, map) {
1786
- return map?.[key] || decamelize(key);
1787
- }
1788
- function mapKeys(fields, mapper, map) {
1789
- const mapped = {};
1790
- for (const key in fields) {
1791
- if (Object.hasOwn(fields, key)) {
1792
- mapped[mapper(key, map)] = fields[key];
1793
- }
1794
- }
1795
- return mapped;
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
- function shallowCopy(obj) {
1799
- return Array.isArray(obj) ? [...obj] : { ...obj };
1800
- }
1801
- function replaceSecrets(root, secretsMap) {
1802
- const result = shallowCopy(root);
1803
- for (const [path, secretId] of Object.entries(secretsMap)) {
1804
- const [last, ...partsReverse] = path.split(".").reverse();
1805
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1806
- let current = result;
1807
- for (const part of partsReverse.reverse()) {
1808
- if (current[part] === undefined) {
1809
- break;
1810
- }
1811
- current[part] = shallowCopy(current[part]);
1812
- current = current[part];
1813
- }
1814
- if (current[last] !== undefined) {
1815
- current[last] = {
1816
- lc: 1,
1817
- type: "secret",
1818
- id: [secretId],
1819
- };
1820
- }
1821
- }
1822
- return result;
1823
- }
1824
- /**
1825
- * Get a unique name for the module, rather than parent class implementations.
1826
- * Should not be subclassed, subclass lc_name above instead.
1827
- */
1828
- function get_lc_unique_name(
1829
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
1830
- serializableClass) {
1831
- // "super" here would refer to the parent class of Serializable,
1832
- // when we want the parent class of the module actually calling this method.
1833
- const parentClass = Object.getPrototypeOf(serializableClass);
1834
- const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
1835
- (typeof parentClass.lc_name !== "function" ||
1836
- serializableClass.lc_name() !== parentClass.lc_name());
1837
- if (lcNameIsSubclassed) {
1838
- return serializableClass.lc_name();
1839
- }
1840
- else {
1841
- return serializableClass.name;
1842
- }
1843
- }
1844
- class Serializable {
1845
- /**
1846
- * The name of the serializable. Override to provide an alias or
1847
- * to preserve the serialized module name in minified environments.
1848
- *
1849
- * Implemented as a static method to support loading logic.
1850
- */
1851
- static lc_name() {
1852
- return this.name;
1853
- }
1854
- /**
1855
- * The final serialized identifier for the module.
1856
- */
1857
- get lc_id() {
1858
- return [
1859
- ...this.lc_namespace,
1860
- get_lc_unique_name(this.constructor),
1861
- ];
1862
- }
1863
- /**
1864
- * A map of secrets, which will be omitted from serialization.
1865
- * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
1866
- * Values are the secret ids, which will be used when deserializing.
1867
- */
1868
- get lc_secrets() {
1869
- return undefined;
1870
- }
1871
- /**
1872
- * A map of additional attributes to merge with constructor args.
1873
- * Keys are the attribute names, e.g. "foo".
1874
- * Values are the attribute values, which will be serialized.
1875
- * These attributes need to be accepted by the constructor as arguments.
1876
- */
1877
- get lc_attributes() {
1878
- return undefined;
1879
- }
1880
- /**
1881
- * A map of aliases for constructor args.
1882
- * Keys are the attribute names, e.g. "foo".
1883
- * Values are the alias that will replace the key in serialization.
1884
- * This is used to eg. make argument names match Python.
1885
- */
1886
- get lc_aliases() {
1887
- return undefined;
1888
- }
1889
- constructor(kwargs, ..._args) {
1890
- Object.defineProperty(this, "lc_serializable", {
1891
- enumerable: true,
1892
- configurable: true,
1893
- writable: true,
1894
- value: false
1895
- });
1896
- Object.defineProperty(this, "lc_kwargs", {
1897
- enumerable: true,
1898
- configurable: true,
1899
- writable: true,
1900
- value: void 0
1901
- });
1902
- this.lc_kwargs = kwargs || {};
1903
- }
1904
- toJSON() {
1905
- if (!this.lc_serializable) {
1906
- return this.toJSONNotImplemented();
1907
- }
1908
- if (
1909
- // eslint-disable-next-line no-instanceof/no-instanceof
1910
- this.lc_kwargs instanceof Serializable ||
1911
- typeof this.lc_kwargs !== "object" ||
1912
- Array.isArray(this.lc_kwargs)) {
1913
- // We do not support serialization of classes with arg not a POJO
1914
- // I'm aware the check above isn't as strict as it could be
1915
- return this.toJSONNotImplemented();
1916
- }
1917
- const aliases = {};
1918
- const secrets = {};
1919
- const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
1920
- acc[key] = key in this ? this[key] : this.lc_kwargs[key];
1921
- return acc;
1922
- }, {});
1923
- // get secrets, attributes and aliases from all superclasses
1924
- for (
1925
- // eslint-disable-next-line @typescript-eslint/no-this-alias
1926
- let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
1927
- Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
1928
- Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
1929
- Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
1930
- }
1931
- // include all secrets used, even if not in kwargs,
1932
- // will be replaced with sentinel value in replaceSecrets
1933
- Object.keys(secrets).forEach((keyPath) => {
1934
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
1935
- let read = this;
1936
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1937
- let write = kwargs;
1938
- const [last, ...partsReverse] = keyPath.split(".").reverse();
1939
- for (const key of partsReverse.reverse()) {
1940
- if (!(key in read) || read[key] === undefined)
1941
- return;
1942
- if (!(key in write) || write[key] === undefined) {
1943
- if (typeof read[key] === "object" && read[key] != null) {
1944
- write[key] = {};
1945
- }
1946
- else if (Array.isArray(read[key])) {
1947
- write[key] = [];
1948
- }
1949
- }
1950
- read = read[key];
1951
- write = write[key];
1952
- }
1953
- if (last in read && read[last] !== undefined) {
1954
- write[last] = write[last] || read[last];
1955
- }
1956
- });
1957
- return {
1958
- lc: 1,
1959
- type: "constructor",
1960
- id: this.lc_id,
1961
- kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
1962
- };
1963
- }
1964
- toJSONNotImplemented() {
1965
- return {
1966
- lc: 1,
1967
- type: "not_implemented",
1968
- id: this.lc_id,
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
- * The name of the serializable. Override to provide an alias or
2024
- * to preserve the serialized module name in minified environments.
2025
- *
2026
- * Implemented as a static method to support loading logic.
2027
- */
2028
- static lc_name() {
2029
- return this.name;
2030
- }
2031
- /**
2032
- * The final serialized identifier for the module.
2033
- */
2034
- get lc_id() {
2035
- return [
2036
- ...this.lc_namespace,
2037
- get_lc_unique_name(this.constructor),
2038
- ];
2039
- }
2040
- constructor(input) {
2041
- super();
2042
- Object.defineProperty(this, "lc_serializable", {
2043
- enumerable: true,
2044
- configurable: true,
2045
- writable: true,
2046
- value: false
2047
- });
2048
- Object.defineProperty(this, "lc_kwargs", {
2049
- enumerable: true,
2050
- configurable: true,
2051
- writable: true,
2052
- value: void 0
2053
- });
2054
- Object.defineProperty(this, "ignoreLLM", {
2055
- enumerable: true,
2056
- configurable: true,
2057
- writable: true,
2058
- value: false
2059
- });
2060
- Object.defineProperty(this, "ignoreChain", {
2061
- enumerable: true,
2062
- configurable: true,
2063
- writable: true,
2064
- value: false
2065
- });
2066
- Object.defineProperty(this, "ignoreAgent", {
2067
- enumerable: true,
2068
- configurable: true,
2069
- writable: true,
2070
- value: false
2071
- });
2072
- Object.defineProperty(this, "ignoreRetriever", {
2073
- enumerable: true,
2074
- configurable: true,
2075
- writable: true,
2076
- value: false
2077
- });
2078
- Object.defineProperty(this, "ignoreCustomEvent", {
2079
- enumerable: true,
2080
- configurable: true,
2081
- writable: true,
2082
- value: false
2083
- });
2084
- Object.defineProperty(this, "raiseError", {
2085
- enumerable: true,
2086
- configurable: true,
2087
- writable: true,
2088
- value: false
2089
- });
2090
- Object.defineProperty(this, "awaitHandlers", {
2091
- enumerable: true,
2092
- configurable: true,
2093
- writable: true,
2094
- value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
2095
- });
2096
- this.lc_kwargs = input || {};
2097
- if (input) {
2098
- this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
2099
- this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
2100
- this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
2101
- this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
2102
- this.ignoreCustomEvent =
2103
- input.ignoreCustomEvent ?? this.ignoreCustomEvent;
2104
- this.raiseError = input.raiseError ?? this.raiseError;
2105
- this.awaitHandlers =
2106
- this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
2107
- }
2108
- }
2109
- copy() {
2110
- return new this.constructor(this);
2111
- }
2112
- toJSON() {
2113
- return Serializable.prototype.toJSON.call(this);
2114
- }
2115
- toJSONNotImplemented() {
2116
- return Serializable.prototype.toJSONNotImplemented.call(this);
2117
- }
2118
- static fromMethods(methods) {
2119
- class Handler extends BaseCallbackHandler {
2120
- constructor() {
2121
- super();
2122
- Object.defineProperty(this, "name", {
2123
- enumerable: true,
2124
- configurable: true,
2125
- writable: true,
2126
- value: uuid.v4()
2127
- });
2128
- Object.assign(this, methods);
2129
- }
2130
- }
2131
- return new Handler();
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) {