@posthog/ai 7.21.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -4
- package/dist/anthropic/index.cjs +1 -1
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.mjs +1 -1
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/gemini/index.cjs +2 -1
- package/dist/gemini/index.cjs.map +1 -1
- package/dist/gemini/index.d.ts +1 -1
- package/dist/gemini/index.mjs +2 -2
- package/dist/gemini/index.mjs.map +1 -1
- package/dist/index.cjs +72 -3500
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -276
- package/dist/index.mjs +72 -3473
- package/dist/index.mjs.map +1 -1
- package/dist/langchain/index.cjs +4 -486
- package/dist/langchain/index.cjs.map +1 -1
- package/dist/langchain/index.mjs +3 -465
- package/dist/langchain/index.mjs.map +1 -1
- package/dist/openai/index.cjs +529 -1
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.ts +40 -2
- package/dist/openai/index.mjs +530 -3
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openai-agents/index.cjs +1 -1
- package/dist/openai-agents/index.cjs.map +1 -1
- package/dist/openai-agents/index.mjs +1 -1
- package/dist/openai-agents/index.mjs.map +1 -1
- package/dist/otel/index.cjs +14 -14
- package/dist/otel/index.cjs.map +1 -1
- package/dist/otel/index.d.ts +11 -16
- package/dist/otel/index.mjs +14 -14
- package/dist/otel/index.mjs.map +1 -1
- package/dist/vercel/index.cjs +1 -1
- package/dist/vercel/index.cjs.map +1 -1
- package/dist/vercel/index.mjs +1 -1
- package/dist/vercel/index.mjs.map +1 -1
- package/package.json +24 -9
package/dist/langchain/index.cjs
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function _interopNamespace(e) {
|
|
6
|
-
if (e && e.__esModule) return e;
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n.default = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
|
|
3
|
+
require('uuid');
|
|
4
|
+
var base = require('@langchain/core/callbacks/base');
|
|
24
5
|
|
|
25
6
|
const DATA_URL_PREFIX_RE = /^data:([^;,\s]+)(?:;[^;,\s]+)*;base64,/i;
|
|
26
7
|
const BASE64_ALPHABET_RE = /^[A-Za-z0-9+/_=-]+$/;
|
|
@@ -236,470 +217,7 @@ function sanitizeValues(obj) {
|
|
|
236
217
|
return jsonSafe;
|
|
237
218
|
}
|
|
238
219
|
|
|
239
|
-
|
|
240
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
var decamelize;
|
|
244
|
-
var hasRequiredDecamelize;
|
|
245
|
-
|
|
246
|
-
function requireDecamelize () {
|
|
247
|
-
if (hasRequiredDecamelize) return decamelize;
|
|
248
|
-
hasRequiredDecamelize = 1;
|
|
249
|
-
decamelize = function (str, sep) {
|
|
250
|
-
if (typeof str !== 'string') {
|
|
251
|
-
throw new TypeError('Expected a string');
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
sep = typeof sep === 'undefined' ? '_' : sep;
|
|
255
|
-
|
|
256
|
-
return str
|
|
257
|
-
.replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
|
|
258
|
-
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
|
|
259
|
-
.toLowerCase();
|
|
260
|
-
};
|
|
261
|
-
return decamelize;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
var decamelizeExports = requireDecamelize();
|
|
265
|
-
var snakeCase = /*@__PURE__*/getDefaultExportFromCjs(decamelizeExports);
|
|
266
|
-
|
|
267
|
-
var camelcase = {exports: {}};
|
|
268
|
-
|
|
269
|
-
var hasRequiredCamelcase;
|
|
270
|
-
|
|
271
|
-
function requireCamelcase () {
|
|
272
|
-
if (hasRequiredCamelcase) return camelcase.exports;
|
|
273
|
-
hasRequiredCamelcase = 1;
|
|
274
|
-
|
|
275
|
-
const UPPERCASE = /[\p{Lu}]/u;
|
|
276
|
-
const LOWERCASE = /[\p{Ll}]/u;
|
|
277
|
-
const LEADING_CAPITAL = /^[\p{Lu}](?![\p{Lu}])/gu;
|
|
278
|
-
const IDENTIFIER = /([\p{Alpha}\p{N}_]|$)/u;
|
|
279
|
-
const SEPARATORS = /[_.\- ]+/;
|
|
280
|
-
|
|
281
|
-
const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
|
|
282
|
-
const SEPARATORS_AND_IDENTIFIER = new RegExp(SEPARATORS.source + IDENTIFIER.source, 'gu');
|
|
283
|
-
const NUMBERS_AND_IDENTIFIER = new RegExp('\\d+' + IDENTIFIER.source, 'gu');
|
|
284
|
-
|
|
285
|
-
const preserveCamelCase = (string, toLowerCase, toUpperCase) => {
|
|
286
|
-
let isLastCharLower = false;
|
|
287
|
-
let isLastCharUpper = false;
|
|
288
|
-
let isLastLastCharUpper = false;
|
|
289
|
-
|
|
290
|
-
for (let i = 0; i < string.length; i++) {
|
|
291
|
-
const character = string[i];
|
|
292
|
-
|
|
293
|
-
if (isLastCharLower && UPPERCASE.test(character)) {
|
|
294
|
-
string = string.slice(0, i) + '-' + string.slice(i);
|
|
295
|
-
isLastCharLower = false;
|
|
296
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
297
|
-
isLastCharUpper = true;
|
|
298
|
-
i++;
|
|
299
|
-
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) {
|
|
300
|
-
string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
|
301
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
302
|
-
isLastCharUpper = false;
|
|
303
|
-
isLastCharLower = true;
|
|
304
|
-
} else {
|
|
305
|
-
isLastCharLower = toLowerCase(character) === character && toUpperCase(character) !== character;
|
|
306
|
-
isLastLastCharUpper = isLastCharUpper;
|
|
307
|
-
isLastCharUpper = toUpperCase(character) === character && toLowerCase(character) !== character;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return string;
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
const preserveConsecutiveUppercase = (input, toLowerCase) => {
|
|
315
|
-
LEADING_CAPITAL.lastIndex = 0;
|
|
316
|
-
|
|
317
|
-
return input.replace(LEADING_CAPITAL, m1 => toLowerCase(m1));
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
const postProcess = (input, toUpperCase) => {
|
|
321
|
-
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
|
|
322
|
-
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
|
|
323
|
-
|
|
324
|
-
return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
|
|
325
|
-
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
const camelCase = (input, options) => {
|
|
329
|
-
if (!(typeof input === 'string' || Array.isArray(input))) {
|
|
330
|
-
throw new TypeError('Expected the input to be `string | string[]`');
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
options = {
|
|
334
|
-
pascalCase: false,
|
|
335
|
-
preserveConsecutiveUppercase: false,
|
|
336
|
-
...options
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
if (Array.isArray(input)) {
|
|
340
|
-
input = input.map(x => x.trim())
|
|
341
|
-
.filter(x => x.length)
|
|
342
|
-
.join('-');
|
|
343
|
-
} else {
|
|
344
|
-
input = input.trim();
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (input.length === 0) {
|
|
348
|
-
return '';
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const toLowerCase = options.locale === false ?
|
|
352
|
-
string => string.toLowerCase() :
|
|
353
|
-
string => string.toLocaleLowerCase(options.locale);
|
|
354
|
-
const toUpperCase = options.locale === false ?
|
|
355
|
-
string => string.toUpperCase() :
|
|
356
|
-
string => string.toLocaleUpperCase(options.locale);
|
|
357
|
-
|
|
358
|
-
if (input.length === 1) {
|
|
359
|
-
return options.pascalCase ? toUpperCase(input) : toLowerCase(input);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const hasUpperCase = input !== toLowerCase(input);
|
|
363
|
-
|
|
364
|
-
if (hasUpperCase) {
|
|
365
|
-
input = preserveCamelCase(input, toLowerCase, toUpperCase);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
input = input.replace(LEADING_SEPARATORS, '');
|
|
369
|
-
|
|
370
|
-
if (options.preserveConsecutiveUppercase) {
|
|
371
|
-
input = preserveConsecutiveUppercase(input, toLowerCase);
|
|
372
|
-
} else {
|
|
373
|
-
input = toLowerCase(input);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (options.pascalCase) {
|
|
377
|
-
input = toUpperCase(input.charAt(0)) + input.slice(1);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return postProcess(input, toUpperCase);
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
camelcase.exports = camelCase;
|
|
384
|
-
// TODO: Remove this for the next major release
|
|
385
|
-
camelcase.exports.default = camelCase;
|
|
386
|
-
return camelcase.exports;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
requireCamelcase();
|
|
390
|
-
|
|
391
|
-
//#region src/load/map_keys.ts
|
|
392
|
-
function keyToJson(key, map) {
|
|
393
|
-
return map?.[key] || snakeCase(key);
|
|
394
|
-
}
|
|
395
|
-
function mapKeys(fields, mapper, map) {
|
|
396
|
-
const mapped = {};
|
|
397
|
-
for (const key in fields) if (Object.hasOwn(fields, key)) mapped[mapper(key, map)] = fields[key];
|
|
398
|
-
return mapped;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
//#region src/load/validation.ts
|
|
402
|
-
/**
|
|
403
|
-
* Sentinel key used to mark escaped user objects during serialization.
|
|
404
|
-
*
|
|
405
|
-
* When a plain object contains 'lc' key (which could be confused with LC objects),
|
|
406
|
-
* we wrap it as `{"__lc_escaped__": {...original...}}`.
|
|
407
|
-
*/
|
|
408
|
-
const LC_ESCAPED_KEY = "__lc_escaped__";
|
|
409
|
-
/**
|
|
410
|
-
* Check if an object needs escaping to prevent confusion with LC objects.
|
|
411
|
-
*
|
|
412
|
-
* An object needs escaping if:
|
|
413
|
-
* 1. It has an `'lc'` key (could be confused with LC serialization format)
|
|
414
|
-
* 2. It has only the escape key (would be mistaken for an escaped object)
|
|
415
|
-
*/
|
|
416
|
-
function needsEscaping(obj) {
|
|
417
|
-
return "lc" in obj || Object.keys(obj).length === 1 && LC_ESCAPED_KEY in obj;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Wrap an object in the escape marker.
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* {"key": "value"} // becomes {"__lc_escaped__": {"key": "value"}}
|
|
425
|
-
* ```
|
|
426
|
-
*/
|
|
427
|
-
function escapeObject(obj) {
|
|
428
|
-
return { [LC_ESCAPED_KEY]: obj };
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* Check if an object looks like a Serializable instance (duck typing).
|
|
432
|
-
*/
|
|
433
|
-
function isSerializableLike(obj) {
|
|
434
|
-
return obj !== null && typeof obj === "object" && "lc_serializable" in obj && typeof obj.toJSON === "function";
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Create a "not_implemented" serialization result for objects that cannot be serialized.
|
|
438
|
-
*/
|
|
439
|
-
function createNotImplemented(obj) {
|
|
440
|
-
let id;
|
|
441
|
-
if (obj !== null && typeof obj === "object") if ("lc_id" in obj && Array.isArray(obj.lc_id)) id = obj.lc_id;
|
|
442
|
-
else id = [obj.constructor?.name ?? "Object"];
|
|
443
|
-
else id = [typeof obj];
|
|
444
|
-
return {
|
|
445
|
-
lc: 1,
|
|
446
|
-
type: "not_implemented",
|
|
447
|
-
id
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Escape a value if it needs escaping (contains `lc` key).
|
|
452
|
-
*
|
|
453
|
-
* This is a simpler version of `serializeValue` that doesn't handle Serializable
|
|
454
|
-
* objects - it's meant to be called on kwargs values that have already been
|
|
455
|
-
* processed by `toJSON()`.
|
|
456
|
-
*
|
|
457
|
-
* @param value - The value to potentially escape.
|
|
458
|
-
* @param pathSet - WeakSet to track ancestor objects in the current path to detect circular references.
|
|
459
|
-
* Objects are removed after processing to allow shared references (same object in
|
|
460
|
-
* multiple places) while still detecting true circular references (ancestor in descendant).
|
|
461
|
-
* @returns The value with any `lc`-containing objects wrapped in escape markers.
|
|
462
|
-
*/
|
|
463
|
-
function escapeIfNeeded(value, pathSet = /* @__PURE__ */ new WeakSet()) {
|
|
464
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
465
|
-
if (pathSet.has(value)) return createNotImplemented(value);
|
|
466
|
-
if (isSerializableLike(value)) return value;
|
|
467
|
-
pathSet.add(value);
|
|
468
|
-
const record = value;
|
|
469
|
-
if (needsEscaping(record)) {
|
|
470
|
-
pathSet.delete(value);
|
|
471
|
-
return escapeObject(record);
|
|
472
|
-
}
|
|
473
|
-
const result = {};
|
|
474
|
-
for (const [key, val] of Object.entries(record)) result[key] = escapeIfNeeded(val, pathSet);
|
|
475
|
-
pathSet.delete(value);
|
|
476
|
-
return result;
|
|
477
|
-
}
|
|
478
|
-
if (Array.isArray(value)) return value.map((item) => escapeIfNeeded(item, pathSet));
|
|
479
|
-
return value;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
function shallowCopy(obj) {
|
|
483
|
-
return Array.isArray(obj) ? [...obj] : { ...obj };
|
|
484
|
-
}
|
|
485
|
-
function replaceSecrets(root, secretsMap) {
|
|
486
|
-
const result = shallowCopy(root);
|
|
487
|
-
for (const [path, secretId] of Object.entries(secretsMap)) {
|
|
488
|
-
const [last, ...partsReverse] = path.split(".").reverse();
|
|
489
|
-
let current = result;
|
|
490
|
-
for (const part of partsReverse.reverse()) {
|
|
491
|
-
if (current[part] === void 0) break;
|
|
492
|
-
current[part] = shallowCopy(current[part]);
|
|
493
|
-
current = current[part];
|
|
494
|
-
}
|
|
495
|
-
if (current[last] !== void 0) current[last] = {
|
|
496
|
-
lc: 1,
|
|
497
|
-
type: "secret",
|
|
498
|
-
id: [secretId]
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
return result;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* Get a unique name for the module, rather than parent class implementations.
|
|
505
|
-
* Should not be subclassed, subclass lc_name above instead.
|
|
506
|
-
*/
|
|
507
|
-
function get_lc_unique_name(serializableClass) {
|
|
508
|
-
const parentClass = Object.getPrototypeOf(serializableClass);
|
|
509
|
-
if (typeof serializableClass.lc_name === "function" && (typeof parentClass.lc_name !== "function" || serializableClass.lc_name() !== parentClass.lc_name())) return serializableClass.lc_name();
|
|
510
|
-
else return serializableClass.name;
|
|
511
|
-
}
|
|
512
|
-
var Serializable = class Serializable {
|
|
513
|
-
lc_serializable = false;
|
|
514
|
-
lc_kwargs;
|
|
515
|
-
/**
|
|
516
|
-
* The name of the serializable. Override to provide an alias or
|
|
517
|
-
* to preserve the serialized module name in minified environments.
|
|
518
|
-
*
|
|
519
|
-
* Implemented as a static method to support loading logic.
|
|
520
|
-
*/
|
|
521
|
-
static lc_name() {
|
|
522
|
-
return this.name;
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* The final serialized identifier for the module.
|
|
526
|
-
*/
|
|
527
|
-
get lc_id() {
|
|
528
|
-
return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* A map of secrets, which will be omitted from serialization.
|
|
532
|
-
* Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
|
|
533
|
-
* Values are the secret ids, which will be used when deserializing.
|
|
534
|
-
*/
|
|
535
|
-
get lc_secrets() {}
|
|
536
|
-
/**
|
|
537
|
-
* A map of additional attributes to merge with constructor args.
|
|
538
|
-
* Keys are the attribute names, e.g. "foo".
|
|
539
|
-
* Values are the attribute values, which will be serialized.
|
|
540
|
-
* These attributes need to be accepted by the constructor as arguments.
|
|
541
|
-
*/
|
|
542
|
-
get lc_attributes() {}
|
|
543
|
-
/**
|
|
544
|
-
* A map of aliases for constructor args.
|
|
545
|
-
* Keys are the attribute names, e.g. "foo".
|
|
546
|
-
* Values are the alias that will replace the key in serialization.
|
|
547
|
-
* This is used to eg. make argument names match Python.
|
|
548
|
-
*/
|
|
549
|
-
get lc_aliases() {}
|
|
550
|
-
/**
|
|
551
|
-
* A manual list of keys that should be serialized.
|
|
552
|
-
* If not overridden, all fields passed into the constructor will be serialized.
|
|
553
|
-
*/
|
|
554
|
-
get lc_serializable_keys() {}
|
|
555
|
-
constructor(kwargs, ..._args) {
|
|
556
|
-
if (this.lc_serializable_keys !== void 0) this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
|
|
557
|
-
else this.lc_kwargs = kwargs ?? {};
|
|
558
|
-
}
|
|
559
|
-
toJSON() {
|
|
560
|
-
if (!this.lc_serializable) return this.toJSONNotImplemented();
|
|
561
|
-
if (this.lc_kwargs instanceof Serializable || typeof this.lc_kwargs !== "object" || Array.isArray(this.lc_kwargs)) return this.toJSONNotImplemented();
|
|
562
|
-
const aliases = {};
|
|
563
|
-
const secrets = {};
|
|
564
|
-
const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
|
|
565
|
-
acc[key] = key in this ? this[key] : this.lc_kwargs[key];
|
|
566
|
-
return acc;
|
|
567
|
-
}, {});
|
|
568
|
-
for (let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
|
|
569
|
-
Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
|
|
570
|
-
Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
|
|
571
|
-
Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
|
|
572
|
-
}
|
|
573
|
-
Object.keys(secrets).forEach((keyPath) => {
|
|
574
|
-
let read = this;
|
|
575
|
-
let write = kwargs;
|
|
576
|
-
const [last, ...partsReverse] = keyPath.split(".").reverse();
|
|
577
|
-
for (const key of partsReverse.reverse()) {
|
|
578
|
-
if (!(key in read) || read[key] === void 0) return;
|
|
579
|
-
if (!(key in write) || write[key] === void 0) {
|
|
580
|
-
if (typeof read[key] === "object" && read[key] != null) write[key] = {};
|
|
581
|
-
else if (Array.isArray(read[key])) write[key] = [];
|
|
582
|
-
}
|
|
583
|
-
read = read[key];
|
|
584
|
-
write = write[key];
|
|
585
|
-
}
|
|
586
|
-
if (last in read && read[last] !== void 0) write[last] = write[last] || read[last];
|
|
587
|
-
});
|
|
588
|
-
const escapedKwargs = {};
|
|
589
|
-
const pathSet = /* @__PURE__ */ new WeakSet();
|
|
590
|
-
pathSet.add(this);
|
|
591
|
-
for (const [key, value] of Object.entries(kwargs)) escapedKwargs[key] = escapeIfNeeded(value, pathSet);
|
|
592
|
-
const processedKwargs = mapKeys(Object.keys(secrets).length ? replaceSecrets(escapedKwargs, secrets) : escapedKwargs, keyToJson, aliases);
|
|
593
|
-
return {
|
|
594
|
-
lc: 1,
|
|
595
|
-
type: "constructor",
|
|
596
|
-
id: this.lc_id,
|
|
597
|
-
kwargs: processedKwargs
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
toJSONNotImplemented() {
|
|
601
|
-
return {
|
|
602
|
-
lc: 1,
|
|
603
|
-
type: "not_implemented",
|
|
604
|
-
id: this.lc_id
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
|
|
609
|
-
const isDeno = () => typeof Deno !== "undefined";
|
|
610
|
-
function getEnvironmentVariable(name) {
|
|
611
|
-
try {
|
|
612
|
-
if (typeof process !== "undefined") return process.env?.[name];
|
|
613
|
-
else if (isDeno()) return Deno?.env.get(name);
|
|
614
|
-
else return;
|
|
615
|
-
} catch {
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
* Abstract class that provides a set of optional methods that can be
|
|
622
|
-
* overridden in derived classes to handle various events during the
|
|
623
|
-
* execution of a LangChain application.
|
|
624
|
-
*/
|
|
625
|
-
var BaseCallbackHandlerMethodsClass = class {};
|
|
626
|
-
/**
|
|
627
|
-
* Abstract base class for creating callback handlers in the LangChain
|
|
628
|
-
* framework. It provides a set of optional methods that can be overridden
|
|
629
|
-
* in derived classes to handle various events during the execution of a
|
|
630
|
-
* LangChain application.
|
|
631
|
-
*/
|
|
632
|
-
var BaseCallbackHandler = class extends BaseCallbackHandlerMethodsClass {
|
|
633
|
-
lc_serializable = false;
|
|
634
|
-
get lc_namespace() {
|
|
635
|
-
return [
|
|
636
|
-
"langchain_core",
|
|
637
|
-
"callbacks",
|
|
638
|
-
this.name
|
|
639
|
-
];
|
|
640
|
-
}
|
|
641
|
-
get lc_secrets() {}
|
|
642
|
-
get lc_attributes() {}
|
|
643
|
-
get lc_aliases() {}
|
|
644
|
-
get lc_serializable_keys() {}
|
|
645
|
-
/**
|
|
646
|
-
* The name of the serializable. Override to provide an alias or
|
|
647
|
-
* to preserve the serialized module name in minified environments.
|
|
648
|
-
*
|
|
649
|
-
* Implemented as a static method to support loading logic.
|
|
650
|
-
*/
|
|
651
|
-
static lc_name() {
|
|
652
|
-
return this.name;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* The final serialized identifier for the module.
|
|
656
|
-
*/
|
|
657
|
-
get lc_id() {
|
|
658
|
-
return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
|
|
659
|
-
}
|
|
660
|
-
lc_kwargs;
|
|
661
|
-
ignoreLLM = false;
|
|
662
|
-
ignoreChain = false;
|
|
663
|
-
ignoreAgent = false;
|
|
664
|
-
ignoreRetriever = false;
|
|
665
|
-
ignoreCustomEvent = false;
|
|
666
|
-
raiseError = false;
|
|
667
|
-
awaitHandlers = getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false";
|
|
668
|
-
constructor(input) {
|
|
669
|
-
super();
|
|
670
|
-
this.lc_kwargs = input || {};
|
|
671
|
-
if (input) {
|
|
672
|
-
this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
|
|
673
|
-
this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
|
|
674
|
-
this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
|
|
675
|
-
this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
|
|
676
|
-
this.ignoreCustomEvent = input.ignoreCustomEvent ?? this.ignoreCustomEvent;
|
|
677
|
-
this.raiseError = input.raiseError ?? this.raiseError;
|
|
678
|
-
this.awaitHandlers = this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
copy() {
|
|
682
|
-
return new this.constructor(this);
|
|
683
|
-
}
|
|
684
|
-
toJSON() {
|
|
685
|
-
return Serializable.prototype.toJSON.call(this);
|
|
686
|
-
}
|
|
687
|
-
toJSONNotImplemented() {
|
|
688
|
-
return Serializable.prototype.toJSONNotImplemented.call(this);
|
|
689
|
-
}
|
|
690
|
-
static fromMethods(methods) {
|
|
691
|
-
class Handler extends BaseCallbackHandler {
|
|
692
|
-
name = uuid__namespace.v7();
|
|
693
|
-
constructor() {
|
|
694
|
-
super();
|
|
695
|
-
Object.assign(this, methods);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
return new Handler();
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
|
|
702
|
-
var version = "7.21.0";
|
|
220
|
+
var version = "8.0.0";
|
|
703
221
|
|
|
704
222
|
const DEFAULT_MAX_DEPTH = 3;
|
|
705
223
|
const MAX_STACK_LINES = 20;
|
|
@@ -756,7 +274,7 @@ function truncateStack(stack) {
|
|
|
756
274
|
|
|
757
275
|
/** Storage for run metadata */
|
|
758
276
|
|
|
759
|
-
class LangChainCallbackHandler extends BaseCallbackHandler {
|
|
277
|
+
class LangChainCallbackHandler extends base.BaseCallbackHandler {
|
|
760
278
|
name = 'PosthogCallbackHandler';
|
|
761
279
|
runs = {};
|
|
762
280
|
parentTree = {};
|