@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
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var openai = require('openai');
6
4
  var uuid = require('uuid');
7
5
  var buffer = require('buffer');
@@ -9,28 +7,24 @@ var ai = require('ai');
9
7
  var AnthropicOriginal = require('@anthropic-ai/sdk');
10
8
  var genai = require('@google/genai');
11
9
 
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- function _interopNamespace(e) {
15
- if (e && e.__esModule) return e;
16
- var n = Object.create(null);
17
- if (e) {
18
- Object.keys(e).forEach(function (k) {
19
- if (k !== 'default') {
20
- var d = Object.getOwnPropertyDescriptor(e, k);
21
- Object.defineProperty(n, k, d.get ? d : {
22
- enumerable: true,
23
- get: function () { return e[k]; }
10
+ function _interopNamespaceDefault(e) {
11
+ var n = Object.create(null);
12
+ if (e) {
13
+ Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default') {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
24
21
  });
25
- }
26
- });
27
- }
28
- n["default"] = e;
29
- return Object.freeze(n);
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
30
25
  }
31
26
 
32
- var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
33
- var AnthropicOriginal__default = /*#__PURE__*/_interopDefaultLegacy(AnthropicOriginal);
27
+ var uuid__namespace = /*#__PURE__*/_interopNamespaceDefault(uuid);
34
28
 
35
29
  // limit large outputs by truncating to 200kb (approx 200k bytes)
36
30
  const MAX_OUTPUT_SIZE = 200000;
@@ -74,7 +68,7 @@ const formatResponseOpenAI = response => {
74
68
  return output;
75
69
  };
76
70
  const mergeSystemPrompt = (params, provider) => {
77
- if (provider == 'anthropic') {
71
+ {
78
72
  const messages = params.messages || [];
79
73
  if (!params.system) {
80
74
  return messages;
@@ -85,7 +79,6 @@ const mergeSystemPrompt = (params, provider) => {
85
79
  content: systemMessage
86
80
  }, ...messages];
87
81
  }
88
- return params.messages;
89
82
  };
90
83
  const withPrivacyMode = (client, privacyMode, input) => {
91
84
  return client.privacy_mode || privacyMode ? null : input;
@@ -222,13 +215,13 @@ class PostHogOpenAI extends openai.OpenAI {
222
215
  this.responses = new WrappedResponses$1(this, this.phClient);
223
216
  }
224
217
  }
225
- class WrappedChat$1 extends Chat {
218
+ let WrappedChat$1 = class WrappedChat extends Chat {
226
219
  constructor(parentClient, phClient) {
227
220
  super(parentClient);
228
221
  this.completions = new WrappedCompletions$1(parentClient, phClient);
229
222
  }
230
- }
231
- class WrappedCompletions$1 extends Completions {
223
+ };
224
+ let WrappedCompletions$1 = class WrappedCompletions extends Completions {
232
225
  constructor(client, phClient) {
233
226
  super(client);
234
227
  this.phClient = phClient;
@@ -370,8 +363,8 @@ class WrappedCompletions$1 extends Completions {
370
363
  return wrappedPromise;
371
364
  }
372
365
  }
373
- }
374
- class WrappedResponses$1 extends Responses {
366
+ };
367
+ let WrappedResponses$1 = class WrappedResponses extends Responses {
375
368
  constructor(client, phClient) {
376
369
  super(client);
377
370
  this.phClient = phClient;
@@ -420,6 +413,7 @@ class WrappedResponses$1 extends Responses {
420
413
  client: this.phClient,
421
414
  distinctId: posthogDistinctId,
422
415
  traceId,
416
+ //@ts-expect-error
423
417
  model: openAIParams.model,
424
418
  provider: 'openai',
425
419
  input: openAIParams.input,
@@ -436,6 +430,7 @@ class WrappedResponses$1 extends Responses {
436
430
  client: this.phClient,
437
431
  distinctId: posthogDistinctId,
438
432
  traceId,
433
+ //@ts-expect-error
439
434
  model: openAIParams.model,
440
435
  provider: 'openai',
441
436
  input: openAIParams.input,
@@ -466,6 +461,7 @@ class WrappedResponses$1 extends Responses {
466
461
  client: this.phClient,
467
462
  distinctId: posthogDistinctId,
468
463
  traceId,
464
+ //@ts-expect-error
469
465
  model: openAIParams.model,
470
466
  provider: 'openai',
471
467
  input: openAIParams.input,
@@ -489,6 +485,7 @@ class WrappedResponses$1 extends Responses {
489
485
  client: this.phClient,
490
486
  distinctId: posthogDistinctId,
491
487
  traceId,
488
+ //@ts-expect-error
492
489
  model: openAIParams.model,
493
490
  provider: 'openai',
494
491
  input: openAIParams.input,
@@ -536,6 +533,7 @@ class WrappedResponses$1 extends Responses {
536
533
  client: this.phClient,
537
534
  distinctId: posthogDistinctId,
538
535
  traceId,
536
+ //@ts-expect-error
539
537
  model: openAIParams.model,
540
538
  provider: 'openai',
541
539
  input: openAIParams.input,
@@ -558,6 +556,7 @@ class WrappedResponses$1 extends Responses {
558
556
  client: this.phClient,
559
557
  distinctId: posthogDistinctId,
560
558
  traceId,
559
+ //@ts-expect-error
561
560
  model: openAIParams.model,
562
561
  provider: 'openai',
563
562
  input: openAIParams.input,
@@ -582,7 +581,7 @@ class WrappedResponses$1 extends Responses {
582
581
  originalSelf.create = tempCreate;
583
582
  }
584
583
  }
585
- }
584
+ };
586
585
 
587
586
  class PostHogAzureOpenAI extends openai.AzureOpenAI {
588
587
  constructor(config) {
@@ -793,6 +792,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
793
792
  client: this.phClient,
794
793
  distinctId: posthogDistinctId,
795
794
  traceId,
795
+ //@ts-expect-error
796
796
  model: openAIParams.model,
797
797
  provider: 'azure',
798
798
  input: openAIParams.input,
@@ -809,6 +809,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
809
809
  client: this.phClient,
810
810
  distinctId: posthogDistinctId,
811
811
  traceId,
812
+ //@ts-expect-error
812
813
  model: openAIParams.model,
813
814
  provider: 'azure',
814
815
  input: openAIParams.input,
@@ -839,6 +840,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
839
840
  client: this.phClient,
840
841
  distinctId: posthogDistinctId,
841
842
  traceId,
843
+ //@ts-expect-error
842
844
  model: openAIParams.model,
843
845
  provider: 'azure',
844
846
  input: openAIParams.input,
@@ -862,6 +864,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
862
864
  client: this.phClient,
863
865
  distinctId: posthogDistinctId,
864
866
  traceId,
867
+ //@ts-expect-error
865
868
  model: openAIParams.model,
866
869
  provider: 'azure',
867
870
  input: openAIParams.input,
@@ -903,6 +906,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
903
906
  client: this.phClient,
904
907
  distinctId: posthogDistinctId,
905
908
  traceId,
909
+ //@ts-expect-error
906
910
  model: openAIParams.model,
907
911
  provider: 'azure',
908
912
  input: openAIParams.input,
@@ -925,6 +929,7 @@ class WrappedResponses extends openai.AzureOpenAI.Responses {
925
929
  client: this.phClient,
926
930
  distinctId: posthogDistinctId,
927
931
  traceId,
932
+ //@ts-expect-error
928
933
  model: openAIParams.model,
929
934
  provider: 'azure',
930
935
  input: openAIParams.input,
@@ -1312,7 +1317,7 @@ const wrapVercelLanguageModel = (model, phClient, options) => {
1312
1317
  return wrappedModel;
1313
1318
  };
1314
1319
 
1315
- class PostHogAnthropic extends AnthropicOriginal__default["default"] {
1320
+ class PostHogAnthropic extends AnthropicOriginal {
1316
1321
  constructor(config) {
1317
1322
  const {
1318
1323
  posthog,
@@ -1323,7 +1328,7 @@ class PostHogAnthropic extends AnthropicOriginal__default["default"] {
1323
1328
  this.messages = new WrappedMessages(this, this.phClient);
1324
1329
  }
1325
1330
  }
1326
- class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
1331
+ class WrappedMessages extends AnthropicOriginal.Messages {
1327
1332
  constructor(parentClient, phClient) {
1328
1333
  super(parentClient);
1329
1334
  this.phClient = phClient;
@@ -1398,7 +1403,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
1398
1403
  traceId,
1399
1404
  model: anthropicParams.model,
1400
1405
  provider: 'anthropic',
1401
- input: mergeSystemPrompt(anthropicParams, 'anthropic'),
1406
+ input: mergeSystemPrompt(anthropicParams),
1402
1407
  output: [],
1403
1408
  latency: 0,
1404
1409
  baseURL: this.baseURL ?? '',
@@ -1429,7 +1434,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
1429
1434
  traceId,
1430
1435
  model: anthropicParams.model,
1431
1436
  provider: 'anthropic',
1432
- input: mergeSystemPrompt(anthropicParams, 'anthropic'),
1437
+ input: mergeSystemPrompt(anthropicParams),
1433
1438
  output: formatResponseAnthropic(result),
1434
1439
  latency,
1435
1440
  baseURL: this.baseURL ?? '',
@@ -1452,7 +1457,7 @@ class WrappedMessages extends AnthropicOriginal__default["default"].Messages {
1452
1457
  traceId,
1453
1458
  model: anthropicParams.model,
1454
1459
  provider: 'anthropic',
1455
- input: mergeSystemPrompt(anthropicParams, 'anthropic'),
1460
+ input: mergeSystemPrompt(anthropicParams),
1456
1461
  output: [],
1457
1462
  latency: 0,
1458
1463
  baseURL: this.baseURL ?? '',
@@ -1701,461 +1706,521 @@ class WrappedModels {
1701
1706
  }
1702
1707
  }
1703
1708
 
1704
- var decamelize = function (str, sep) {
1705
- if (typeof str !== 'string') {
1706
- throw new TypeError('Expected a string');
1707
- }
1708
- sep = typeof sep === 'undefined' ? '_' : sep;
1709
- return str
1710
- .replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
1711
- .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
1712
- .toLowerCase();
1713
- };
1709
+ function getDefaultExportFromCjs (x) {
1710
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1711
+ }
1712
+
1713
+ var decamelize;
1714
+ var hasRequiredDecamelize;
1715
+
1716
+ function requireDecamelize () {
1717
+ if (hasRequiredDecamelize) return decamelize;
1718
+ hasRequiredDecamelize = 1;
1719
+ decamelize = function (str, sep) {
1720
+ if (typeof str !== 'string') {
1721
+ throw new TypeError('Expected a string');
1722
+ }
1723
+
1724
+ sep = typeof sep === 'undefined' ? '_' : sep;
1725
+
1726
+ return str
1727
+ .replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
1728
+ .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
1729
+ .toLowerCase();
1730
+ };
1731
+ return decamelize;
1732
+ }
1733
+
1734
+ var decamelizeExports = requireDecamelize();
1735
+ var snakeCase = /*@__PURE__*/getDefaultExportFromCjs(decamelizeExports);
1714
1736
 
1715
1737
  var camelcase = {exports: {}};
1716
1738
 
1717
- const UPPERCASE = /[\p{Lu}]/u;
1718
- const LOWERCASE = /[\p{Ll}]/u;
1719
- const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
1720
- const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
1721
- const SEPARATORS = /[_.\- ]+/;
1722
- const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
1723
- const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
1724
- const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
1725
- const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
1726
- let isLastCharLower = false;
1727
- let isLastCharUpper = false;
1728
- let isLastLastCharUpper = false;
1729
- for (let i = 0; i < string.length; i++) {
1730
- const character = string[i];
1731
- if (isLastCharLower && UPPERCASE.test(character)) {
1732
- string = string.slice(0, i) + '-' + string.slice(i);
1733
- isLastCharLower = false;
1734
- isLastLastCharUpper = isLastCharUpper;
1735
- isLastCharUpper = true;
1736
- i++;
1737
- }
1738
- else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
1739
- string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
1740
- isLastLastCharUpper = isLastCharUpper;
1741
- isLastCharUpper = false;
1742
- isLastCharLower = true;
1743
- }
1744
- else {
1745
- isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
1746
- isLastLastCharUpper = isLastCharUpper;
1747
- isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
1748
- }
1749
- }
1750
- return string;
1751
- };
1752
- const preserveConsecutiveUppercase = (input, toLowerCase) => {
1753
- LEADING_CAPITAL.lastIndex = 0;
1754
- return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
1755
- };
1756
- const postProcess = (input, toUpperCase) => {
1757
- SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
1758
- NUMBERS_AND_IDENTIFIER.lastIndex = 0;
1759
- return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
1760
- .replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
1761
- };
1762
- const camelCase = (input, options) => {
1763
- if (!(typeof input === 'string' || Array.isArray(input))) {
1764
- throw new TypeError('Expected the input to be `string | string[]`');
1765
- }
1766
- options = {
1767
- pascalCase: false,
1768
- preserveConsecutiveUppercase: false,
1769
- ...options
1770
- };
1771
- if (Array.isArray(input)) {
1772
- input = input.map(x => x.trim())
1773
- .filter(x => x.length)
1774
- .join('-');
1775
- }
1776
- else {
1777
- input = input.trim();
1778
- }
1779
- if (input.length === 0) {
1780
- return '';
1781
- }
1782
- const toLowerCase = options.locale === false ?
1783
- string => string.toLowerCase() :
1784
- string => string.toLocaleLowerCase(options.locale);
1785
- const toUpperCase = options.locale === false ?
1786
- string => string.toUpperCase() :
1787
- string => string.toLocaleUpperCase(options.locale);
1788
- if (input.length === 1) {
1789
- return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
1790
- }
1791
- const hasUpperCase = input !== toLowerCase(input);
1792
- if (hasUpperCase) {
1793
- input = preserveCamelCase(input, toLowerCase, toUpperCase);
1794
- }
1795
- input = input.replace(LEADING_SEPARATORS, '');
1796
- if (options.preserveConsecutiveUppercase) {
1797
- input = preserveConsecutiveUppercase(input, toLowerCase);
1798
- }
1799
- else {
1800
- input = toLowerCase(input);
1801
- }
1802
- if (options.pascalCase) {
1803
- input = toUpperCase(input.charAt(0)) + input.slice(1);
1804
- }
1805
- return postProcess(input, toUpperCase);
1806
- };
1807
- camelcase.exports = camelCase;
1808
- // TODO: Remove this for the next major release
1809
- camelcase.exports.default = camelCase;
1739
+ var hasRequiredCamelcase;
1740
+
1741
+ function requireCamelcase () {
1742
+ if (hasRequiredCamelcase) return camelcase.exports;
1743
+ hasRequiredCamelcase = 1;
1744
+
1745
+ const UPPERCASE = /[\p{Lu}]/u;
1746
+ const LOWERCASE = /[\p{Ll}]/u;
1747
+ const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
1748
+ const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
1749
+ const SEPARATORS = /[_.\- ]+/;
1750
+
1751
+ const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
1752
+ const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
1753
+ const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
1754
+
1755
+ const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
1756
+ let isLastCharLower = false;
1757
+ let isLastCharUpper = false;
1758
+ let isLastLastCharUpper = false;
1759
+
1760
+ for (let i = 0; i < string.length; i++) {
1761
+ const character = string[i];
1762
+
1763
+ if (isLastCharLower && UPPERCASE.test(character)) {
1764
+ string = string.slice(0, i) + '-' + string.slice(i);
1765
+ isLastCharLower = false;
1766
+ isLastLastCharUpper = isLastCharUpper;
1767
+ isLastCharUpper = true;
1768
+ i++;
1769
+ } else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
1770
+ string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
1771
+ isLastLastCharUpper = isLastCharUpper;
1772
+ isLastCharUpper = false;
1773
+ isLastCharLower = true;
1774
+ } else {
1775
+ isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
1776
+ isLastLastCharUpper = isLastCharUpper;
1777
+ isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
1778
+ }
1779
+ }
1780
+
1781
+ return string;
1782
+ };
1783
+
1784
+ const preserveConsecutiveUppercase = (input, toLowerCase) => {
1785
+ LEADING_CAPITAL.lastIndex = 0;
1810
1786
 
1811
- function keyToJson(key, map) {
1812
- return map?.[key] || decamelize(key);
1813
- }
1814
- function mapKeys(fields, mapper, map) {
1815
- const mapped = {};
1816
- for (const key in fields) {
1817
- if (Object.hasOwn(fields, key)) {
1818
- mapped[mapper(key, map)] = fields[key];
1819
- }
1820
- }
1821
- return mapped;
1787
+ return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
1788
+ };
1789
+
1790
+ const postProcess = (input, toUpperCase) => {
1791
+ SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
1792
+ NUMBERS_AND_IDENTIFIER.lastIndex = 0;
1793
+
1794
+ return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
1795
+ .replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
1796
+ };
1797
+
1798
+ const camelCase = (input, options) => {
1799
+ if (!(typeof input === 'string' || Array.isArray(input))) {
1800
+ throw new TypeError('Expected the input to be `string | string[]`');
1801
+ }
1802
+
1803
+ options = {
1804
+ pascalCase: false,
1805
+ preserveConsecutiveUppercase: false,
1806
+ ...options
1807
+ };
1808
+
1809
+ if (Array.isArray(input)) {
1810
+ input = input.map(x => x.trim())
1811
+ .filter(x => x.length)
1812
+ .join('-');
1813
+ } else {
1814
+ input = input.trim();
1815
+ }
1816
+
1817
+ if (input.length === 0) {
1818
+ return '';
1819
+ }
1820
+
1821
+ const toLowerCase = options.locale === false ?
1822
+ string => string.toLowerCase() :
1823
+ string => string.toLocaleLowerCase(options.locale);
1824
+ const toUpperCase = options.locale === false ?
1825
+ string => string.toUpperCase() :
1826
+ string => string.toLocaleUpperCase(options.locale);
1827
+
1828
+ if (input.length === 1) {
1829
+ return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
1830
+ }
1831
+
1832
+ const hasUpperCase = input !== toLowerCase(input);
1833
+
1834
+ if (hasUpperCase) {
1835
+ input = preserveCamelCase(input, toLowerCase, toUpperCase);
1836
+ }
1837
+
1838
+ input = input.replace(LEADING_SEPARATORS, '');
1839
+
1840
+ if (options.preserveConsecutiveUppercase) {
1841
+ input = preserveConsecutiveUppercase(input, toLowerCase);
1842
+ } else {
1843
+ input = toLowerCase(input);
1844
+ }
1845
+
1846
+ if (options.pascalCase) {
1847
+ input = toUpperCase(input.charAt(0)) + input.slice(1);
1848
+ }
1849
+
1850
+ return postProcess(input, toUpperCase);
1851
+ };
1852
+
1853
+ camelcase.exports = camelCase;
1854
+ // TODO: Remove this for the next major release
1855
+ camelcase.exports.default = camelCase;
1856
+ return camelcase.exports;
1822
1857
  }
1823
1858
 
1824
- function shallowCopy(obj) {
1825
- return Array.isArray(obj) ? [...obj] : { ...obj };
1826
- }
1827
- function replaceSecrets(root, secretsMap) {
1828
- const result = shallowCopy(root);
1829
- for (const [path, secretId] of Object.entries(secretsMap)) {
1830
- const [last, ...partsReverse] = path.split(".").reverse();
1831
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1832
- let current = result;
1833
- for (const part of partsReverse.reverse()) {
1834
- if (current[part] === undefined) {
1835
- break;
1836
- }
1837
- current[part] = shallowCopy(current[part]);
1838
- current = current[part];
1839
- }
1840
- if (current[last] !== undefined) {
1841
- current[last] = {
1842
- lc: 1,
1843
- type: "secret",
1844
- id: [secretId],
1845
- };
1846
- }
1847
- }
1848
- return result;
1849
- }
1850
- /**
1851
- * Get a unique name for the module, rather than parent class implementations.
1852
- * Should not be subclassed, subclass lc_name above instead.
1853
- */
1854
- function get_lc_unique_name(
1855
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
1856
- serializableClass) {
1857
- // "super" here would refer to the parent class of Serializable,
1858
- // when we want the parent class of the module actually calling this method.
1859
- const parentClass = Object.getPrototypeOf(serializableClass);
1860
- const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
1861
- (typeof parentClass.lc_name !== "function" ||
1862
- serializableClass.lc_name() !== parentClass.lc_name());
1863
- if (lcNameIsSubclassed) {
1864
- return serializableClass.lc_name();
1865
- }
1866
- else {
1867
- return serializableClass.name;
1868
- }
1869
- }
1870
- class Serializable {
1871
- /**
1872
- * The name of the serializable. Override to provide an alias or
1873
- * to preserve the serialized module name in minified environments.
1874
- *
1875
- * Implemented as a static method to support loading logic.
1876
- */
1877
- static lc_name() {
1878
- return this.name;
1879
- }
1880
- /**
1881
- * The final serialized identifier for the module.
1882
- */
1883
- get lc_id() {
1884
- return [
1885
- ...this.lc_namespace,
1886
- get_lc_unique_name(this.constructor),
1887
- ];
1888
- }
1889
- /**
1890
- * A map of secrets, which will be omitted from serialization.
1891
- * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
1892
- * Values are the secret ids, which will be used when deserializing.
1893
- */
1894
- get lc_secrets() {
1895
- return undefined;
1896
- }
1897
- /**
1898
- * A map of additional attributes to merge with constructor args.
1899
- * Keys are the attribute names, e.g. "foo".
1900
- * Values are the attribute values, which will be serialized.
1901
- * These attributes need to be accepted by the constructor as arguments.
1902
- */
1903
- get lc_attributes() {
1904
- return undefined;
1905
- }
1906
- /**
1907
- * A map of aliases for constructor args.
1908
- * Keys are the attribute names, e.g. "foo".
1909
- * Values are the alias that will replace the key in serialization.
1910
- * This is used to eg. make argument names match Python.
1911
- */
1912
- get lc_aliases() {
1913
- return undefined;
1914
- }
1915
- constructor(kwargs, ..._args) {
1916
- Object.defineProperty(this, "lc_serializable", {
1917
- enumerable: true,
1918
- configurable: true,
1919
- writable: true,
1920
- value: false
1921
- });
1922
- Object.defineProperty(this, "lc_kwargs", {
1923
- enumerable: true,
1924
- configurable: true,
1925
- writable: true,
1926
- value: void 0
1927
- });
1928
- this.lc_kwargs = kwargs || {};
1929
- }
1930
- toJSON() {
1931
- if (!this.lc_serializable) {
1932
- return this.toJSONNotImplemented();
1933
- }
1934
- if (
1935
- // eslint-disable-next-line no-instanceof/no-instanceof
1936
- this.lc_kwargs instanceof Serializable ||
1937
- typeof this.lc_kwargs !== "object" ||
1938
- Array.isArray(this.lc_kwargs)) {
1939
- // We do not support serialization of classes with arg not a POJO
1940
- // I'm aware the check above isn't as strict as it could be
1941
- return this.toJSONNotImplemented();
1942
- }
1943
- const aliases = {};
1944
- const secrets = {};
1945
- const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
1946
- acc[key] = key in this ? this[key] : this.lc_kwargs[key];
1947
- return acc;
1948
- }, {});
1949
- // get secrets, attributes and aliases from all superclasses
1950
- for (
1951
- // eslint-disable-next-line @typescript-eslint/no-this-alias
1952
- let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
1953
- Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
1954
- Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
1955
- Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
1956
- }
1957
- // include all secrets used, even if not in kwargs,
1958
- // will be replaced with sentinel value in replaceSecrets
1959
- Object.keys(secrets).forEach((keyPath) => {
1960
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
1961
- let read = this;
1962
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1963
- let write = kwargs;
1964
- const [last, ...partsReverse] = keyPath.split(".").reverse();
1965
- for (const key of partsReverse.reverse()) {
1966
- if (!(key in read) || read[key] === undefined)
1967
- return;
1968
- if (!(key in write) || write[key] === undefined) {
1969
- if (typeof read[key] === "object" && read[key] != null) {
1970
- write[key] = {};
1971
- }
1972
- else if (Array.isArray(read[key])) {
1973
- write[key] = [];
1974
- }
1975
- }
1976
- read = read[key];
1977
- write = write[key];
1978
- }
1979
- if (last in read && read[last] !== undefined) {
1980
- write[last] = write[last] || read[last];
1981
- }
1982
- });
1983
- return {
1984
- lc: 1,
1985
- type: "constructor",
1986
- id: this.lc_id,
1987
- kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
1988
- };
1989
- }
1990
- toJSONNotImplemented() {
1991
- return {
1992
- lc: 1,
1993
- type: "not_implemented",
1994
- id: this.lc_id,
1995
- };
1996
- }
1859
+ requireCamelcase();
1860
+
1861
+ function keyToJson(key, map) {
1862
+ return map?.[key] || snakeCase(key);
1863
+ }
1864
+ function mapKeys(fields, mapper, map) {
1865
+ const mapped = {};
1866
+ for (const key in fields) {
1867
+ if (Object.hasOwn(fields, key)) {
1868
+ mapped[mapper(key, map)] = fields[key];
1869
+ }
1870
+ }
1871
+ return mapped;
1997
1872
  }
1998
1873
 
1999
- // Supabase Edge Function provides a `Deno` global object
2000
- // without `version` property
2001
- const isDeno = () => typeof Deno !== "undefined";
2002
- function getEnvironmentVariable(name) {
2003
- // Certain Deno setups will throw an error if you try to access environment variables
2004
- // https://github.com/langchain-ai/langchainjs/issues/1412
2005
- try {
2006
- if (typeof process !== "undefined") {
2007
- // eslint-disable-next-line no-process-env
2008
- return process.env?.[name];
2009
- }
2010
- else if (isDeno()) {
2011
- return Deno?.env.get(name);
2012
- }
2013
- else {
2014
- return undefined;
2015
- }
2016
- }
2017
- catch (e) {
2018
- return undefined;
2019
- }
1874
+ function shallowCopy(obj) {
1875
+ return Array.isArray(obj) ? [...obj] : { ...obj };
1876
+ }
1877
+ function replaceSecrets(root, secretsMap) {
1878
+ const result = shallowCopy(root);
1879
+ for (const [path, secretId] of Object.entries(secretsMap)) {
1880
+ const [last, ...partsReverse] = path.split(".").reverse();
1881
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1882
+ let current = result;
1883
+ for (const part of partsReverse.reverse()) {
1884
+ if (current[part] === undefined) {
1885
+ break;
1886
+ }
1887
+ current[part] = shallowCopy(current[part]);
1888
+ current = current[part];
1889
+ }
1890
+ if (current[last] !== undefined) {
1891
+ current[last] = {
1892
+ lc: 1,
1893
+ type: "secret",
1894
+ id: [secretId],
1895
+ };
1896
+ }
1897
+ }
1898
+ return result;
1899
+ }
1900
+ /**
1901
+ * Get a unique name for the module, rather than parent class implementations.
1902
+ * Should not be subclassed, subclass lc_name above instead.
1903
+ */
1904
+ function get_lc_unique_name(
1905
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
1906
+ serializableClass) {
1907
+ // "super" here would refer to the parent class of Serializable,
1908
+ // when we want the parent class of the module actually calling this method.
1909
+ const parentClass = Object.getPrototypeOf(serializableClass);
1910
+ const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
1911
+ (typeof parentClass.lc_name !== "function" ||
1912
+ serializableClass.lc_name() !== parentClass.lc_name());
1913
+ if (lcNameIsSubclassed) {
1914
+ return serializableClass.lc_name();
1915
+ }
1916
+ else {
1917
+ return serializableClass.name;
1918
+ }
1919
+ }
1920
+ class Serializable {
1921
+ /**
1922
+ * The name of the serializable. Override to provide an alias or
1923
+ * to preserve the serialized module name in minified environments.
1924
+ *
1925
+ * Implemented as a static method to support loading logic.
1926
+ */
1927
+ static lc_name() {
1928
+ return this.name;
1929
+ }
1930
+ /**
1931
+ * The final serialized identifier for the module.
1932
+ */
1933
+ get lc_id() {
1934
+ return [
1935
+ ...this.lc_namespace,
1936
+ get_lc_unique_name(this.constructor),
1937
+ ];
1938
+ }
1939
+ /**
1940
+ * A map of secrets, which will be omitted from serialization.
1941
+ * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
1942
+ * Values are the secret ids, which will be used when deserializing.
1943
+ */
1944
+ get lc_secrets() {
1945
+ return undefined;
1946
+ }
1947
+ /**
1948
+ * A map of additional attributes to merge with constructor args.
1949
+ * Keys are the attribute names, e.g. "foo".
1950
+ * Values are the attribute values, which will be serialized.
1951
+ * These attributes need to be accepted by the constructor as arguments.
1952
+ */
1953
+ get lc_attributes() {
1954
+ return undefined;
1955
+ }
1956
+ /**
1957
+ * A map of aliases for constructor args.
1958
+ * Keys are the attribute names, e.g. "foo".
1959
+ * Values are the alias that will replace the key in serialization.
1960
+ * This is used to eg. make argument names match Python.
1961
+ */
1962
+ get lc_aliases() {
1963
+ return undefined;
1964
+ }
1965
+ /**
1966
+ * A manual list of keys that should be serialized.
1967
+ * If not overridden, all fields passed into the constructor will be serialized.
1968
+ */
1969
+ get lc_serializable_keys() {
1970
+ return undefined;
1971
+ }
1972
+ constructor(kwargs, ..._args) {
1973
+ Object.defineProperty(this, "lc_serializable", {
1974
+ enumerable: true,
1975
+ configurable: true,
1976
+ writable: true,
1977
+ value: false
1978
+ });
1979
+ Object.defineProperty(this, "lc_kwargs", {
1980
+ enumerable: true,
1981
+ configurable: true,
1982
+ writable: true,
1983
+ value: void 0
1984
+ });
1985
+ if (this.lc_serializable_keys !== undefined) {
1986
+ this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
1987
+ }
1988
+ else {
1989
+ this.lc_kwargs = kwargs ?? {};
1990
+ }
1991
+ }
1992
+ toJSON() {
1993
+ if (!this.lc_serializable) {
1994
+ return this.toJSONNotImplemented();
1995
+ }
1996
+ if (
1997
+ // eslint-disable-next-line no-instanceof/no-instanceof
1998
+ this.lc_kwargs instanceof Serializable ||
1999
+ typeof this.lc_kwargs !== "object" ||
2000
+ Array.isArray(this.lc_kwargs)) {
2001
+ // We do not support serialization of classes with arg not a POJO
2002
+ // I'm aware the check above isn't as strict as it could be
2003
+ return this.toJSONNotImplemented();
2004
+ }
2005
+ const aliases = {};
2006
+ const secrets = {};
2007
+ const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
2008
+ acc[key] = key in this ? this[key] : this.lc_kwargs[key];
2009
+ return acc;
2010
+ }, {});
2011
+ // get secrets, attributes and aliases from all superclasses
2012
+ for (
2013
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
2014
+ let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
2015
+ Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
2016
+ Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
2017
+ Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
2018
+ }
2019
+ // include all secrets used, even if not in kwargs,
2020
+ // will be replaced with sentinel value in replaceSecrets
2021
+ Object.keys(secrets).forEach((keyPath) => {
2022
+ // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
2023
+ let read = this;
2024
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2025
+ let write = kwargs;
2026
+ const [last, ...partsReverse] = keyPath.split(".").reverse();
2027
+ for (const key of partsReverse.reverse()) {
2028
+ if (!(key in read) || read[key] === undefined)
2029
+ return;
2030
+ if (!(key in write) || write[key] === undefined) {
2031
+ if (typeof read[key] === "object" && read[key] != null) {
2032
+ write[key] = {};
2033
+ }
2034
+ else if (Array.isArray(read[key])) {
2035
+ write[key] = [];
2036
+ }
2037
+ }
2038
+ read = read[key];
2039
+ write = write[key];
2040
+ }
2041
+ if (last in read && read[last] !== undefined) {
2042
+ write[last] = write[last] || read[last];
2043
+ }
2044
+ });
2045
+ return {
2046
+ lc: 1,
2047
+ type: "constructor",
2048
+ id: this.lc_id,
2049
+ kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
2050
+ };
2051
+ }
2052
+ toJSONNotImplemented() {
2053
+ return {
2054
+ lc: 1,
2055
+ type: "not_implemented",
2056
+ id: this.lc_id,
2057
+ };
2058
+ }
2059
+ }
2060
+
2061
+ // Supabase Edge Function provides a `Deno` global object
2062
+ // without `version` property
2063
+ const isDeno = () => typeof Deno !== "undefined";
2064
+ function getEnvironmentVariable(name) {
2065
+ // Certain Deno setups will throw an error if you try to access environment variables
2066
+ // https://github.com/langchain-ai/langchainjs/issues/1412
2067
+ try {
2068
+ if (typeof process !== "undefined") {
2069
+ // eslint-disable-next-line no-process-env
2070
+ return process.env?.[name];
2071
+ }
2072
+ else if (isDeno()) {
2073
+ return Deno?.env.get(name);
2074
+ }
2075
+ else {
2076
+ return undefined;
2077
+ }
2078
+ }
2079
+ catch (e) {
2080
+ return undefined;
2081
+ }
2020
2082
  }
2021
2083
 
2022
- /**
2023
- * Abstract class that provides a set of optional methods that can be
2024
- * overridden in derived classes to handle various events during the
2025
- * execution of a LangChain application.
2026
- */
2027
- class BaseCallbackHandlerMethodsClass {
2028
- }
2029
- /**
2030
- * Abstract base class for creating callback handlers in the LangChain
2031
- * framework. It provides a set of optional methods that can be overridden
2032
- * in derived classes to handle various events during the execution of a
2033
- * LangChain application.
2034
- */
2035
- class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
2036
- get lc_namespace() {
2037
- return ["langchain_core", "callbacks", this.name];
2038
- }
2039
- get lc_secrets() {
2040
- return undefined;
2041
- }
2042
- get lc_attributes() {
2043
- return undefined;
2044
- }
2045
- get lc_aliases() {
2046
- return undefined;
2047
- }
2048
- /**
2049
- * The name of the serializable. Override to provide an alias or
2050
- * to preserve the serialized module name in minified environments.
2051
- *
2052
- * Implemented as a static method to support loading logic.
2053
- */
2054
- static lc_name() {
2055
- return this.name;
2056
- }
2057
- /**
2058
- * The final serialized identifier for the module.
2059
- */
2060
- get lc_id() {
2061
- return [
2062
- ...this.lc_namespace,
2063
- get_lc_unique_name(this.constructor),
2064
- ];
2065
- }
2066
- constructor(input) {
2067
- super();
2068
- Object.defineProperty(this, "lc_serializable", {
2069
- enumerable: true,
2070
- configurable: true,
2071
- writable: true,
2072
- value: false
2073
- });
2074
- Object.defineProperty(this, "lc_kwargs", {
2075
- enumerable: true,
2076
- configurable: true,
2077
- writable: true,
2078
- value: void 0
2079
- });
2080
- Object.defineProperty(this, "ignoreLLM", {
2081
- enumerable: true,
2082
- configurable: true,
2083
- writable: true,
2084
- value: false
2085
- });
2086
- Object.defineProperty(this, "ignoreChain", {
2087
- enumerable: true,
2088
- configurable: true,
2089
- writable: true,
2090
- value: false
2091
- });
2092
- Object.defineProperty(this, "ignoreAgent", {
2093
- enumerable: true,
2094
- configurable: true,
2095
- writable: true,
2096
- value: false
2097
- });
2098
- Object.defineProperty(this, "ignoreRetriever", {
2099
- enumerable: true,
2100
- configurable: true,
2101
- writable: true,
2102
- value: false
2103
- });
2104
- Object.defineProperty(this, "ignoreCustomEvent", {
2105
- enumerable: true,
2106
- configurable: true,
2107
- writable: true,
2108
- value: false
2109
- });
2110
- Object.defineProperty(this, "raiseError", {
2111
- enumerable: true,
2112
- configurable: true,
2113
- writable: true,
2114
- value: false
2115
- });
2116
- Object.defineProperty(this, "awaitHandlers", {
2117
- enumerable: true,
2118
- configurable: true,
2119
- writable: true,
2120
- value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
2121
- });
2122
- this.lc_kwargs = input || {};
2123
- if (input) {
2124
- this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
2125
- this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
2126
- this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
2127
- this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
2128
- this.ignoreCustomEvent =
2129
- input.ignoreCustomEvent ?? this.ignoreCustomEvent;
2130
- this.raiseError = input.raiseError ?? this.raiseError;
2131
- this.awaitHandlers =
2132
- this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
2133
- }
2134
- }
2135
- copy() {
2136
- return new this.constructor(this);
2137
- }
2138
- toJSON() {
2139
- return Serializable.prototype.toJSON.call(this);
2140
- }
2141
- toJSONNotImplemented() {
2142
- return Serializable.prototype.toJSONNotImplemented.call(this);
2143
- }
2144
- static fromMethods(methods) {
2145
- class Handler extends BaseCallbackHandler {
2146
- constructor() {
2147
- super();
2148
- Object.defineProperty(this, "name", {
2149
- enumerable: true,
2150
- configurable: true,
2151
- writable: true,
2152
- value: uuid__namespace.v4()
2153
- });
2154
- Object.assign(this, methods);
2155
- }
2156
- }
2157
- return new Handler();
2158
- }
2084
+ /**
2085
+ * Abstract class that provides a set of optional methods that can be
2086
+ * overridden in derived classes to handle various events during the
2087
+ * execution of a LangChain application.
2088
+ */
2089
+ class BaseCallbackHandlerMethodsClass {
2090
+ }
2091
+ /**
2092
+ * Abstract base class for creating callback handlers in the LangChain
2093
+ * framework. It provides a set of optional methods that can be overridden
2094
+ * in derived classes to handle various events during the execution of a
2095
+ * LangChain application.
2096
+ */
2097
+ class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
2098
+ get lc_namespace() {
2099
+ return ["langchain_core", "callbacks", this.name];
2100
+ }
2101
+ get lc_secrets() {
2102
+ return undefined;
2103
+ }
2104
+ get lc_attributes() {
2105
+ return undefined;
2106
+ }
2107
+ get lc_aliases() {
2108
+ return undefined;
2109
+ }
2110
+ get lc_serializable_keys() {
2111
+ return undefined;
2112
+ }
2113
+ /**
2114
+ * The name of the serializable. Override to provide an alias or
2115
+ * to preserve the serialized module name in minified environments.
2116
+ *
2117
+ * Implemented as a static method to support loading logic.
2118
+ */
2119
+ static lc_name() {
2120
+ return this.name;
2121
+ }
2122
+ /**
2123
+ * The final serialized identifier for the module.
2124
+ */
2125
+ get lc_id() {
2126
+ return [
2127
+ ...this.lc_namespace,
2128
+ get_lc_unique_name(this.constructor),
2129
+ ];
2130
+ }
2131
+ constructor(input) {
2132
+ super();
2133
+ Object.defineProperty(this, "lc_serializable", {
2134
+ enumerable: true,
2135
+ configurable: true,
2136
+ writable: true,
2137
+ value: false
2138
+ });
2139
+ Object.defineProperty(this, "lc_kwargs", {
2140
+ enumerable: true,
2141
+ configurable: true,
2142
+ writable: true,
2143
+ value: void 0
2144
+ });
2145
+ Object.defineProperty(this, "ignoreLLM", {
2146
+ enumerable: true,
2147
+ configurable: true,
2148
+ writable: true,
2149
+ value: false
2150
+ });
2151
+ Object.defineProperty(this, "ignoreChain", {
2152
+ enumerable: true,
2153
+ configurable: true,
2154
+ writable: true,
2155
+ value: false
2156
+ });
2157
+ Object.defineProperty(this, "ignoreAgent", {
2158
+ enumerable: true,
2159
+ configurable: true,
2160
+ writable: true,
2161
+ value: false
2162
+ });
2163
+ Object.defineProperty(this, "ignoreRetriever", {
2164
+ enumerable: true,
2165
+ configurable: true,
2166
+ writable: true,
2167
+ value: false
2168
+ });
2169
+ Object.defineProperty(this, "ignoreCustomEvent", {
2170
+ enumerable: true,
2171
+ configurable: true,
2172
+ writable: true,
2173
+ value: false
2174
+ });
2175
+ Object.defineProperty(this, "raiseError", {
2176
+ enumerable: true,
2177
+ configurable: true,
2178
+ writable: true,
2179
+ value: false
2180
+ });
2181
+ Object.defineProperty(this, "awaitHandlers", {
2182
+ enumerable: true,
2183
+ configurable: true,
2184
+ writable: true,
2185
+ value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
2186
+ });
2187
+ this.lc_kwargs = input || {};
2188
+ if (input) {
2189
+ this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
2190
+ this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
2191
+ this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
2192
+ this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
2193
+ this.ignoreCustomEvent =
2194
+ input.ignoreCustomEvent ?? this.ignoreCustomEvent;
2195
+ this.raiseError = input.raiseError ?? this.raiseError;
2196
+ this.awaitHandlers =
2197
+ this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
2198
+ }
2199
+ }
2200
+ copy() {
2201
+ return new this.constructor(this);
2202
+ }
2203
+ toJSON() {
2204
+ return Serializable.prototype.toJSON.call(this);
2205
+ }
2206
+ toJSONNotImplemented() {
2207
+ return Serializable.prototype.toJSONNotImplemented.call(this);
2208
+ }
2209
+ static fromMethods(methods) {
2210
+ class Handler extends BaseCallbackHandler {
2211
+ constructor() {
2212
+ super();
2213
+ Object.defineProperty(this, "name", {
2214
+ enumerable: true,
2215
+ configurable: true,
2216
+ writable: true,
2217
+ value: uuid__namespace.v4()
2218
+ });
2219
+ Object.assign(this, methods);
2220
+ }
2221
+ }
2222
+ return new Handler();
2223
+ }
2159
2224
  }
2160
2225
 
2161
2226
  class LangChainCallbackHandler extends BaseCallbackHandler {
@@ -2335,6 +2400,9 @@ class LangChainCallbackHandler extends BaseCallbackHandler {
2335
2400
  };
2336
2401
  if (extraParams) {
2337
2402
  generation.modelParams = getModelParams(extraParams.invocation_params);
2403
+ if (extraParams.invocation_params.tools) {
2404
+ generation.tools = extraParams.invocation_params.tools;
2405
+ }
2338
2406
  }
2339
2407
  if (metadata) {
2340
2408
  if (metadata.ls_model_name) {