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