@posthog/ai 6.6.0 → 7.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/dist/index.cjs CHANGED
@@ -26,7 +26,7 @@ function _interopNamespaceDefault(e) {
26
26
 
27
27
  var uuid__namespace = /*#__PURE__*/_interopNamespaceDefault(uuid);
28
28
 
29
- var version = "6.6.0";
29
+ var version = "7.0.0";
30
30
 
31
31
  // Type guards for safer type checking
32
32
  const isString = value => {
@@ -339,13 +339,14 @@ function calculateWebSearchCount(result) {
339
339
  return 1;
340
340
  }
341
341
  }
342
- // Check for annotations with url_citation in choices[].message (OpenAI/Perplexity)
342
+ // Check for annotations with url_citation in choices[].message or choices[].delta (OpenAI/Perplexity)
343
343
  if ('choices' in result && Array.isArray(result.choices)) {
344
344
  for (const choice of result.choices) {
345
- if (typeof choice === 'object' && choice !== null && 'message' in choice) {
346
- const message = choice.message;
347
- if (typeof message === 'object' && message !== null && 'annotations' in message) {
348
- const annotations = message.annotations;
345
+ if (typeof choice === 'object' && choice !== null) {
346
+ // Check both message (non-streaming) and delta (streaming) for annotations
347
+ const content = ('message' in choice ? choice.message : null) || ('delta' in choice ? choice.delta : null);
348
+ if (typeof content === 'object' && content !== null && 'annotations' in content) {
349
+ const annotations = content.annotations;
349
350
  if (Array.isArray(annotations)) {
350
351
  const hasUrlCitation = annotations.some(ann => {
351
352
  return typeof ann === 'object' && ann !== null && 'type' in ann && ann.type === 'url_citation';
@@ -2842,6 +2843,15 @@ function calculateGoogleWebSearchCount(response) {
2842
2843
  return hasGrounding ? 1 : 0;
2843
2844
  }
2844
2845
 
2846
+ //#region rolldown:runtime
2847
+ var __defProp = Object.defineProperty;
2848
+ var __export = (target, all) => {
2849
+ for (var name in all) __defProp(target, name, {
2850
+ get: all[name],
2851
+ enumerable: true
2852
+ });
2853
+ };
2854
+
2845
2855
  function getDefaultExportFromCjs (x) {
2846
2856
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
2847
2857
  }
@@ -2994,370 +3004,304 @@ function requireCamelcase () {
2994
3004
 
2995
3005
  requireCamelcase();
2996
3006
 
3007
+ //#region src/load/map_keys.ts
2997
3008
  function keyToJson(key, map) {
2998
- return map?.[key] || snakeCase(key);
3009
+ return map?.[key] || snakeCase(key);
2999
3010
  }
3000
3011
  function mapKeys(fields, mapper, map) {
3001
- const mapped = {};
3002
- for (const key in fields) {
3003
- if (Object.hasOwn(fields, key)) {
3004
- mapped[mapper(key, map)] = fields[key];
3005
- }
3006
- }
3007
- return mapped;
3012
+ const mapped = {};
3013
+ for (const key in fields) if (Object.hasOwn(fields, key)) mapped[mapper(key, map)] = fields[key];
3014
+ return mapped;
3008
3015
  }
3009
3016
 
3017
+ //#region src/load/serializable.ts
3018
+ var serializable_exports = {};
3019
+ __export(serializable_exports, {
3020
+ Serializable: () => Serializable,
3021
+ get_lc_unique_name: () => get_lc_unique_name
3022
+ });
3010
3023
  function shallowCopy(obj) {
3011
- return Array.isArray(obj) ? [...obj] : { ...obj };
3024
+ return Array.isArray(obj) ? [...obj] : { ...obj };
3012
3025
  }
3013
3026
  function replaceSecrets(root, secretsMap) {
3014
- const result = shallowCopy(root);
3015
- for (const [path, secretId] of Object.entries(secretsMap)) {
3016
- const [last, ...partsReverse] = path.split(".").reverse();
3017
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3018
- let current = result;
3019
- for (const part of partsReverse.reverse()) {
3020
- if (current[part] === undefined) {
3021
- break;
3022
- }
3023
- current[part] = shallowCopy(current[part]);
3024
- current = current[part];
3025
- }
3026
- if (current[last] !== undefined) {
3027
- current[last] = {
3028
- lc: 1,
3029
- type: "secret",
3030
- id: [secretId],
3031
- };
3032
- }
3033
- }
3034
- return result;
3027
+ const result = shallowCopy(root);
3028
+ for (const [path, secretId] of Object.entries(secretsMap)) {
3029
+ const [last, ...partsReverse] = path.split(".").reverse();
3030
+ let current = result;
3031
+ for (const part of partsReverse.reverse()) {
3032
+ if (current[part] === void 0) break;
3033
+ current[part] = shallowCopy(current[part]);
3034
+ current = current[part];
3035
+ }
3036
+ if (current[last] !== void 0) current[last] = {
3037
+ lc: 1,
3038
+ type: "secret",
3039
+ id: [secretId]
3040
+ };
3041
+ }
3042
+ return result;
3035
3043
  }
3036
3044
  /**
3037
- * Get a unique name for the module, rather than parent class implementations.
3038
- * Should not be subclassed, subclass lc_name above instead.
3039
- */
3040
- function get_lc_unique_name(
3041
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
3042
- serializableClass) {
3043
- // "super" here would refer to the parent class of Serializable,
3044
- // when we want the parent class of the module actually calling this method.
3045
- const parentClass = Object.getPrototypeOf(serializableClass);
3046
- const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" &&
3047
- (typeof parentClass.lc_name !== "function" ||
3048
- serializableClass.lc_name() !== parentClass.lc_name());
3049
- if (lcNameIsSubclassed) {
3050
- return serializableClass.lc_name();
3051
- }
3052
- else {
3053
- return serializableClass.name;
3054
- }
3055
- }
3056
- class Serializable {
3057
- /**
3058
- * The name of the serializable. Override to provide an alias or
3059
- * to preserve the serialized module name in minified environments.
3060
- *
3061
- * Implemented as a static method to support loading logic.
3062
- */
3063
- static lc_name() {
3064
- return this.name;
3065
- }
3066
- /**
3067
- * The final serialized identifier for the module.
3068
- */
3069
- get lc_id() {
3070
- return [
3071
- ...this.lc_namespace,
3072
- get_lc_unique_name(this.constructor),
3073
- ];
3074
- }
3075
- /**
3076
- * A map of secrets, which will be omitted from serialization.
3077
- * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
3078
- * Values are the secret ids, which will be used when deserializing.
3079
- */
3080
- get lc_secrets() {
3081
- return undefined;
3082
- }
3083
- /**
3084
- * A map of additional attributes to merge with constructor args.
3085
- * Keys are the attribute names, e.g. "foo".
3086
- * Values are the attribute values, which will be serialized.
3087
- * These attributes need to be accepted by the constructor as arguments.
3088
- */
3089
- get lc_attributes() {
3090
- return undefined;
3091
- }
3092
- /**
3093
- * A map of aliases for constructor args.
3094
- * Keys are the attribute names, e.g. "foo".
3095
- * Values are the alias that will replace the key in serialization.
3096
- * This is used to eg. make argument names match Python.
3097
- */
3098
- get lc_aliases() {
3099
- return undefined;
3100
- }
3101
- /**
3102
- * A manual list of keys that should be serialized.
3103
- * If not overridden, all fields passed into the constructor will be serialized.
3104
- */
3105
- get lc_serializable_keys() {
3106
- return undefined;
3107
- }
3108
- constructor(kwargs, ..._args) {
3109
- Object.defineProperty(this, "lc_serializable", {
3110
- enumerable: true,
3111
- configurable: true,
3112
- writable: true,
3113
- value: false
3114
- });
3115
- Object.defineProperty(this, "lc_kwargs", {
3116
- enumerable: true,
3117
- configurable: true,
3118
- writable: true,
3119
- value: void 0
3120
- });
3121
- if (this.lc_serializable_keys !== undefined) {
3122
- this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
3123
- }
3124
- else {
3125
- this.lc_kwargs = kwargs ?? {};
3126
- }
3127
- }
3128
- toJSON() {
3129
- if (!this.lc_serializable) {
3130
- return this.toJSONNotImplemented();
3131
- }
3132
- if (
3133
- // eslint-disable-next-line no-instanceof/no-instanceof
3134
- this.lc_kwargs instanceof Serializable ||
3135
- typeof this.lc_kwargs !== "object" ||
3136
- Array.isArray(this.lc_kwargs)) {
3137
- // We do not support serialization of classes with arg not a POJO
3138
- // I'm aware the check above isn't as strict as it could be
3139
- return this.toJSONNotImplemented();
3140
- }
3141
- const aliases = {};
3142
- const secrets = {};
3143
- const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
3144
- acc[key] = key in this ? this[key] : this.lc_kwargs[key];
3145
- return acc;
3146
- }, {});
3147
- // get secrets, attributes and aliases from all superclasses
3148
- for (
3149
- // eslint-disable-next-line @typescript-eslint/no-this-alias
3150
- let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
3151
- Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
3152
- Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
3153
- Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
3154
- }
3155
- // include all secrets used, even if not in kwargs,
3156
- // will be replaced with sentinel value in replaceSecrets
3157
- Object.keys(secrets).forEach((keyPath) => {
3158
- // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
3159
- let read = this;
3160
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3161
- let write = kwargs;
3162
- const [last, ...partsReverse] = keyPath.split(".").reverse();
3163
- for (const key of partsReverse.reverse()) {
3164
- if (!(key in read) || read[key] === undefined)
3165
- return;
3166
- if (!(key in write) || write[key] === undefined) {
3167
- if (typeof read[key] === "object" && read[key] != null) {
3168
- write[key] = {};
3169
- }
3170
- else if (Array.isArray(read[key])) {
3171
- write[key] = [];
3172
- }
3173
- }
3174
- read = read[key];
3175
- write = write[key];
3176
- }
3177
- if (last in read && read[last] !== undefined) {
3178
- write[last] = write[last] || read[last];
3179
- }
3180
- });
3181
- return {
3182
- lc: 1,
3183
- type: "constructor",
3184
- id: this.lc_id,
3185
- kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),
3186
- };
3187
- }
3188
- toJSONNotImplemented() {
3189
- return {
3190
- lc: 1,
3191
- type: "not_implemented",
3192
- id: this.lc_id,
3193
- };
3194
- }
3045
+ * Get a unique name for the module, rather than parent class implementations.
3046
+ * Should not be subclassed, subclass lc_name above instead.
3047
+ */
3048
+ function get_lc_unique_name(serializableClass) {
3049
+ const parentClass = Object.getPrototypeOf(serializableClass);
3050
+ const lcNameIsSubclassed = typeof serializableClass.lc_name === "function" && (typeof parentClass.lc_name !== "function" || serializableClass.lc_name() !== parentClass.lc_name());
3051
+ if (lcNameIsSubclassed) return serializableClass.lc_name();
3052
+ else return serializableClass.name;
3195
3053
  }
3054
+ var Serializable = class Serializable {
3055
+ lc_serializable = false;
3056
+ lc_kwargs;
3057
+ /**
3058
+ * The name of the serializable. Override to provide an alias or
3059
+ * to preserve the serialized module name in minified environments.
3060
+ *
3061
+ * Implemented as a static method to support loading logic.
3062
+ */
3063
+ static lc_name() {
3064
+ return this.name;
3065
+ }
3066
+ /**
3067
+ * The final serialized identifier for the module.
3068
+ */
3069
+ get lc_id() {
3070
+ return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
3071
+ }
3072
+ /**
3073
+ * A map of secrets, which will be omitted from serialization.
3074
+ * Keys are paths to the secret in constructor args, e.g. "foo.bar.baz".
3075
+ * Values are the secret ids, which will be used when deserializing.
3076
+ */
3077
+ get lc_secrets() {
3078
+ return void 0;
3079
+ }
3080
+ /**
3081
+ * A map of additional attributes to merge with constructor args.
3082
+ * Keys are the attribute names, e.g. "foo".
3083
+ * Values are the attribute values, which will be serialized.
3084
+ * These attributes need to be accepted by the constructor as arguments.
3085
+ */
3086
+ get lc_attributes() {
3087
+ return void 0;
3088
+ }
3089
+ /**
3090
+ * A map of aliases for constructor args.
3091
+ * Keys are the attribute names, e.g. "foo".
3092
+ * Values are the alias that will replace the key in serialization.
3093
+ * This is used to eg. make argument names match Python.
3094
+ */
3095
+ get lc_aliases() {
3096
+ return void 0;
3097
+ }
3098
+ /**
3099
+ * A manual list of keys that should be serialized.
3100
+ * If not overridden, all fields passed into the constructor will be serialized.
3101
+ */
3102
+ get lc_serializable_keys() {
3103
+ return void 0;
3104
+ }
3105
+ constructor(kwargs, ..._args) {
3106
+ if (this.lc_serializable_keys !== void 0) this.lc_kwargs = Object.fromEntries(Object.entries(kwargs || {}).filter(([key]) => this.lc_serializable_keys?.includes(key)));
3107
+ else this.lc_kwargs = kwargs ?? {};
3108
+ }
3109
+ toJSON() {
3110
+ if (!this.lc_serializable) return this.toJSONNotImplemented();
3111
+ if (this.lc_kwargs instanceof Serializable || typeof this.lc_kwargs !== "object" || Array.isArray(this.lc_kwargs)) return this.toJSONNotImplemented();
3112
+ const aliases = {};
3113
+ const secrets = {};
3114
+ const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {
3115
+ acc[key] = key in this ? this[key] : this.lc_kwargs[key];
3116
+ return acc;
3117
+ }, {});
3118
+ for (let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {
3119
+ Object.assign(aliases, Reflect.get(current, "lc_aliases", this));
3120
+ Object.assign(secrets, Reflect.get(current, "lc_secrets", this));
3121
+ Object.assign(kwargs, Reflect.get(current, "lc_attributes", this));
3122
+ }
3123
+ Object.keys(secrets).forEach((keyPath) => {
3124
+ let read = this;
3125
+ let write = kwargs;
3126
+ const [last, ...partsReverse] = keyPath.split(".").reverse();
3127
+ for (const key of partsReverse.reverse()) {
3128
+ if (!(key in read) || read[key] === void 0) return;
3129
+ if (!(key in write) || write[key] === void 0) {
3130
+ if (typeof read[key] === "object" && read[key] != null) write[key] = {};
3131
+ else if (Array.isArray(read[key])) write[key] = [];
3132
+ }
3133
+ read = read[key];
3134
+ write = write[key];
3135
+ }
3136
+ if (last in read && read[last] !== void 0) write[last] = write[last] || read[last];
3137
+ });
3138
+ return {
3139
+ lc: 1,
3140
+ type: "constructor",
3141
+ id: this.lc_id,
3142
+ kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases)
3143
+ };
3144
+ }
3145
+ toJSONNotImplemented() {
3146
+ return {
3147
+ lc: 1,
3148
+ type: "not_implemented",
3149
+ id: this.lc_id
3150
+ };
3151
+ }
3152
+ };
3196
3153
 
3197
- // Supabase Edge Function provides a `Deno` global object
3198
- // without `version` property
3154
+ //#region src/utils/env.ts
3155
+ var env_exports = {};
3156
+ __export(env_exports, {
3157
+ getEnv: () => getEnv,
3158
+ getEnvironmentVariable: () => getEnvironmentVariable,
3159
+ getRuntimeEnvironment: () => getRuntimeEnvironment,
3160
+ isBrowser: () => isBrowser,
3161
+ isDeno: () => isDeno,
3162
+ isJsDom: () => isJsDom,
3163
+ isNode: () => isNode,
3164
+ isWebWorker: () => isWebWorker
3165
+ });
3166
+ const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
3167
+ const isWebWorker = () => typeof globalThis === "object" && globalThis.constructor && globalThis.constructor.name === "DedicatedWorkerGlobalScope";
3168
+ const isJsDom = () => typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && navigator.userAgent.includes("jsdom");
3199
3169
  const isDeno = () => typeof Deno !== "undefined";
3170
+ const isNode = () => typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined" && !isDeno();
3171
+ const getEnv = () => {
3172
+ let env;
3173
+ if (isBrowser()) env = "browser";
3174
+ else if (isNode()) env = "node";
3175
+ else if (isWebWorker()) env = "webworker";
3176
+ else if (isJsDom()) env = "jsdom";
3177
+ else if (isDeno()) env = "deno";
3178
+ else env = "other";
3179
+ return env;
3180
+ };
3181
+ let runtimeEnvironment;
3182
+ function getRuntimeEnvironment() {
3183
+ if (runtimeEnvironment === void 0) {
3184
+ const env = getEnv();
3185
+ runtimeEnvironment = {
3186
+ library: "langchain-js",
3187
+ runtime: env
3188
+ };
3189
+ }
3190
+ return runtimeEnvironment;
3191
+ }
3200
3192
  function getEnvironmentVariable(name) {
3201
- // Certain Deno setups will throw an error if you try to access environment variables
3202
- // https://github.com/langchain-ai/langchainjs/issues/1412
3203
- try {
3204
- if (typeof process !== "undefined") {
3205
- // eslint-disable-next-line no-process-env
3206
- return process.env?.[name];
3207
- }
3208
- else if (isDeno()) {
3209
- return Deno?.env.get(name);
3210
- }
3211
- else {
3212
- return undefined;
3213
- }
3214
- }
3215
- catch (e) {
3216
- return undefined;
3217
- }
3193
+ try {
3194
+ if (typeof process !== "undefined") return process.env?.[name];
3195
+ else if (isDeno()) return Deno?.env.get(name);
3196
+ else return void 0;
3197
+ } catch {
3198
+ return void 0;
3199
+ }
3218
3200
  }
3219
3201
 
3202
+ //#region src/callbacks/base.ts
3203
+ var base_exports = {};
3204
+ __export(base_exports, {
3205
+ BaseCallbackHandler: () => BaseCallbackHandler,
3206
+ callbackHandlerPrefersStreaming: () => callbackHandlerPrefersStreaming,
3207
+ isBaseCallbackHandler: () => isBaseCallbackHandler
3208
+ });
3220
3209
  /**
3221
- * Abstract class that provides a set of optional methods that can be
3222
- * overridden in derived classes to handle various events during the
3223
- * execution of a LangChain application.
3224
- */
3225
- class BaseCallbackHandlerMethodsClass {
3210
+ * Abstract class that provides a set of optional methods that can be
3211
+ * overridden in derived classes to handle various events during the
3212
+ * execution of a LangChain application.
3213
+ */
3214
+ var BaseCallbackHandlerMethodsClass = class {};
3215
+ function callbackHandlerPrefersStreaming(x) {
3216
+ return "lc_prefer_streaming" in x && x.lc_prefer_streaming;
3226
3217
  }
3227
3218
  /**
3228
- * Abstract base class for creating callback handlers in the LangChain
3229
- * framework. It provides a set of optional methods that can be overridden
3230
- * in derived classes to handle various events during the execution of a
3231
- * LangChain application.
3232
- */
3233
- class BaseCallbackHandler extends BaseCallbackHandlerMethodsClass {
3234
- get lc_namespace() {
3235
- return ["langchain_core", "callbacks", this.name];
3236
- }
3237
- get lc_secrets() {
3238
- return undefined;
3239
- }
3240
- get lc_attributes() {
3241
- return undefined;
3242
- }
3243
- get lc_aliases() {
3244
- return undefined;
3245
- }
3246
- get lc_serializable_keys() {
3247
- return undefined;
3248
- }
3249
- /**
3250
- * The name of the serializable. Override to provide an alias or
3251
- * to preserve the serialized module name in minified environments.
3252
- *
3253
- * Implemented as a static method to support loading logic.
3254
- */
3255
- static lc_name() {
3256
- return this.name;
3257
- }
3258
- /**
3259
- * The final serialized identifier for the module.
3260
- */
3261
- get lc_id() {
3262
- return [
3263
- ...this.lc_namespace,
3264
- get_lc_unique_name(this.constructor),
3265
- ];
3266
- }
3267
- constructor(input) {
3268
- super();
3269
- Object.defineProperty(this, "lc_serializable", {
3270
- enumerable: true,
3271
- configurable: true,
3272
- writable: true,
3273
- value: false
3274
- });
3275
- Object.defineProperty(this, "lc_kwargs", {
3276
- enumerable: true,
3277
- configurable: true,
3278
- writable: true,
3279
- value: void 0
3280
- });
3281
- Object.defineProperty(this, "ignoreLLM", {
3282
- enumerable: true,
3283
- configurable: true,
3284
- writable: true,
3285
- value: false
3286
- });
3287
- Object.defineProperty(this, "ignoreChain", {
3288
- enumerable: true,
3289
- configurable: true,
3290
- writable: true,
3291
- value: false
3292
- });
3293
- Object.defineProperty(this, "ignoreAgent", {
3294
- enumerable: true,
3295
- configurable: true,
3296
- writable: true,
3297
- value: false
3298
- });
3299
- Object.defineProperty(this, "ignoreRetriever", {
3300
- enumerable: true,
3301
- configurable: true,
3302
- writable: true,
3303
- value: false
3304
- });
3305
- Object.defineProperty(this, "ignoreCustomEvent", {
3306
- enumerable: true,
3307
- configurable: true,
3308
- writable: true,
3309
- value: false
3310
- });
3311
- Object.defineProperty(this, "raiseError", {
3312
- enumerable: true,
3313
- configurable: true,
3314
- writable: true,
3315
- value: false
3316
- });
3317
- Object.defineProperty(this, "awaitHandlers", {
3318
- enumerable: true,
3319
- configurable: true,
3320
- writable: true,
3321
- value: getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
3322
- });
3323
- this.lc_kwargs = input || {};
3324
- if (input) {
3325
- this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
3326
- this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
3327
- this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
3328
- this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
3329
- this.ignoreCustomEvent =
3330
- input.ignoreCustomEvent ?? this.ignoreCustomEvent;
3331
- this.raiseError = input.raiseError ?? this.raiseError;
3332
- this.awaitHandlers =
3333
- this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
3334
- }
3335
- }
3336
- copy() {
3337
- return new this.constructor(this);
3338
- }
3339
- toJSON() {
3340
- return Serializable.prototype.toJSON.call(this);
3341
- }
3342
- toJSONNotImplemented() {
3343
- return Serializable.prototype.toJSONNotImplemented.call(this);
3344
- }
3345
- static fromMethods(methods) {
3346
- class Handler extends BaseCallbackHandler {
3347
- constructor() {
3348
- super();
3349
- Object.defineProperty(this, "name", {
3350
- enumerable: true,
3351
- configurable: true,
3352
- writable: true,
3353
- value: uuid__namespace.v4()
3354
- });
3355
- Object.assign(this, methods);
3356
- }
3357
- }
3358
- return new Handler();
3359
- }
3360
- }
3219
+ * Abstract base class for creating callback handlers in the LangChain
3220
+ * framework. It provides a set of optional methods that can be overridden
3221
+ * in derived classes to handle various events during the execution of a
3222
+ * LangChain application.
3223
+ */
3224
+ var BaseCallbackHandler = class extends BaseCallbackHandlerMethodsClass {
3225
+ lc_serializable = false;
3226
+ get lc_namespace() {
3227
+ return [
3228
+ "langchain_core",
3229
+ "callbacks",
3230
+ this.name
3231
+ ];
3232
+ }
3233
+ get lc_secrets() {
3234
+ return void 0;
3235
+ }
3236
+ get lc_attributes() {
3237
+ return void 0;
3238
+ }
3239
+ get lc_aliases() {
3240
+ return void 0;
3241
+ }
3242
+ get lc_serializable_keys() {
3243
+ return void 0;
3244
+ }
3245
+ /**
3246
+ * The name of the serializable. Override to provide an alias or
3247
+ * to preserve the serialized module name in minified environments.
3248
+ *
3249
+ * Implemented as a static method to support loading logic.
3250
+ */
3251
+ static lc_name() {
3252
+ return this.name;
3253
+ }
3254
+ /**
3255
+ * The final serialized identifier for the module.
3256
+ */
3257
+ get lc_id() {
3258
+ return [...this.lc_namespace, get_lc_unique_name(this.constructor)];
3259
+ }
3260
+ lc_kwargs;
3261
+ ignoreLLM = false;
3262
+ ignoreChain = false;
3263
+ ignoreAgent = false;
3264
+ ignoreRetriever = false;
3265
+ ignoreCustomEvent = false;
3266
+ raiseError = false;
3267
+ awaitHandlers = getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false";
3268
+ constructor(input) {
3269
+ super();
3270
+ this.lc_kwargs = input || {};
3271
+ if (input) {
3272
+ this.ignoreLLM = input.ignoreLLM ?? this.ignoreLLM;
3273
+ this.ignoreChain = input.ignoreChain ?? this.ignoreChain;
3274
+ this.ignoreAgent = input.ignoreAgent ?? this.ignoreAgent;
3275
+ this.ignoreRetriever = input.ignoreRetriever ?? this.ignoreRetriever;
3276
+ this.ignoreCustomEvent = input.ignoreCustomEvent ?? this.ignoreCustomEvent;
3277
+ this.raiseError = input.raiseError ?? this.raiseError;
3278
+ this.awaitHandlers = this.raiseError || (input._awaitHandler ?? this.awaitHandlers);
3279
+ }
3280
+ }
3281
+ copy() {
3282
+ return new this.constructor(this);
3283
+ }
3284
+ toJSON() {
3285
+ return Serializable.prototype.toJSON.call(this);
3286
+ }
3287
+ toJSONNotImplemented() {
3288
+ return Serializable.prototype.toJSONNotImplemented.call(this);
3289
+ }
3290
+ static fromMethods(methods) {
3291
+ class Handler extends BaseCallbackHandler {
3292
+ name = uuid__namespace.v4();
3293
+ constructor() {
3294
+ super();
3295
+ Object.assign(this, methods);
3296
+ }
3297
+ }
3298
+ return new Handler();
3299
+ }
3300
+ };
3301
+ const isBaseCallbackHandler = (x) => {
3302
+ const callbackHandler = x;
3303
+ return callbackHandler !== void 0 && typeof callbackHandler.copy === "function" && typeof callbackHandler.name === "string" && typeof callbackHandler.awaitHandlers === "boolean";
3304
+ };
3361
3305
 
3362
3306
  class LangChainCallbackHandler extends BaseCallbackHandler {
3363
3307
  constructor(options) {