9e79ba37572feb2ae7b32247b58501150dd5c8a1ae838fcbddd6e74f068ade2b.json 18 KB

1
  1. {"ast":null,"code":"import { keyToJson, mapKeys } from \"./map_keys.js\";\nfunction shallowCopy(obj) {\n return Array.isArray(obj) ? [...obj] : {\n ...obj\n };\n}\nfunction replaceSecrets(root, secretsMap) {\n const result = shallowCopy(root);\n for (const [path, secretId] of Object.entries(secretsMap)) {\n const [last, ...partsReverse] = path.split(\".\").reverse();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let current = result;\n for (const part of partsReverse.reverse()) {\n if (current[part] === undefined) {\n break;\n }\n current[part] = shallowCopy(current[part]);\n current = current[part];\n }\n if (current[last] !== undefined) {\n current[last] = {\n lc: 1,\n type: \"secret\",\n id: [secretId]\n };\n }\n }\n return result;\n}\n/**\n * Get a unique name for the module, rather than parent class implementations.\n * Should not be subclassed, subclass lc_name above instead.\n */\nexport function get_lc_unique_name(\n// eslint-disable-next-line @typescript-eslint/no-use-before-define\nserializableClass) {\n // \"super\" here would refer to the parent class of Serializable,\n // when we want the parent class of the module actually calling this method.\n const parentClass = Object.getPrototypeOf(serializableClass);\n const lcNameIsSubclassed = typeof serializableClass.lc_name === \"function\" && (typeof parentClass.lc_name !== \"function\" || serializableClass.lc_name() !== parentClass.lc_name());\n if (lcNameIsSubclassed) {\n return serializableClass.lc_name();\n } else {\n return serializableClass.name;\n }\n}\nexport class Serializable {\n /**\n * The name of the serializable. Override to provide an alias or\n * to preserve the serialized module name in minified environments.\n *\n * Implemented as a static method to support loading logic.\n */\n static lc_name() {\n return this.name;\n }\n /**\n * The final serialized identifier for the module.\n */\n get lc_id() {\n return [...this.lc_namespace, get_lc_unique_name(this.constructor)];\n }\n /**\n * A map of secrets, which will be omitted from serialization.\n * Keys are paths to the secret in constructor args, e.g. \"foo.bar.baz\".\n * Values are the secret ids, which will be used when deserializing.\n */\n get lc_secrets() {\n return undefined;\n }\n /**\n * A map of additional attributes to merge with constructor args.\n * Keys are the attribute names, e.g. \"foo\".\n * Values are the attribute values, which will be serialized.\n * These attributes need to be accepted by the constructor as arguments.\n */\n get lc_attributes() {\n return undefined;\n }\n /**\n * A map of aliases for constructor args.\n * Keys are the attribute names, e.g. \"foo\".\n * Values are the alias that will replace the key in serialization.\n * This is used to eg. make argument names match Python.\n */\n get lc_aliases() {\n return undefined;\n }\n constructor(kwargs, ..._args) {\n Object.defineProperty(this, \"lc_serializable\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: false\n });\n Object.defineProperty(this, \"lc_kwargs\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.lc_kwargs = kwargs || {};\n }\n toJSON() {\n if (!this.lc_serializable) {\n return this.toJSONNotImplemented();\n }\n if (\n // eslint-disable-next-line no-instanceof/no-instanceof\n this.lc_kwargs instanceof Serializable || typeof this.lc_kwargs !== \"object\" || Array.isArray(this.lc_kwargs)) {\n // We do not support serialization of classes with arg not a POJO\n // I'm aware the check above isn't as strict as it could be\n return this.toJSONNotImplemented();\n }\n const aliases = {};\n const secrets = {};\n const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {\n acc[key] = key in this ? this[key] : this.lc_kwargs[key];\n return acc;\n }, {});\n // get secrets, attributes and aliases from all superclasses\n for (\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {\n Object.assign(aliases, Reflect.get(current, \"lc_aliases\", this));\n Object.assign(secrets, Reflect.get(current, \"lc_secrets\", this));\n Object.assign(kwargs, Reflect.get(current, \"lc_attributes\", this));\n }\n // include all secrets used, even if not in kwargs,\n // will be replaced with sentinel value in replaceSecrets\n Object.keys(secrets).forEach(keyPath => {\n // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any\n let read = this;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let write = kwargs;\n const [last, ...partsReverse] = keyPath.split(\".\").reverse();\n for (const key of partsReverse.reverse()) {\n if (!(key in read) || read[key] === undefined) return;\n if (!(key in write) || write[key] === undefined) {\n if (typeof read[key] === \"object\" && read[key] != null) {\n write[key] = {};\n } else if (Array.isArray(read[key])) {\n write[key] = [];\n }\n }\n read = read[key];\n write = write[key];\n }\n if (last in read && read[last] !== undefined) {\n write[last] = write[last] || read[last];\n }\n });\n return {\n lc: 1,\n type: \"constructor\",\n id: this.lc_id,\n kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases)\n };\n }\n toJSONNotImplemented() {\n return {\n lc: 1,\n type: \"not_implemented\",\n id: this.lc_id\n };\n }\n}","map":{"version":3,"names":["keyToJson","mapKeys","shallowCopy","obj","Array","isArray","replaceSecrets","root","secretsMap","result","path","secretId","Object","entries","last","partsReverse","split","reverse","current","part","undefined","lc","type","id","get_lc_unique_name","serializableClass","parentClass","getPrototypeOf","lcNameIsSubclassed","lc_name","name","Serializable","lc_id","lc_namespace","constructor","lc_secrets","lc_attributes","lc_aliases","kwargs","_args","defineProperty","enumerable","configurable","writable","value","lc_kwargs","toJSON","lc_serializable","toJSONNotImplemented","aliases","secrets","keys","reduce","acc","key","assign","Reflect","get","forEach","keyPath","read","write","length"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@langchain/core/dist/load/serializable.js"],"sourcesContent":["import { keyToJson, mapKeys } from \"./map_keys.js\";\nfunction shallowCopy(obj) {\n return Array.isArray(obj) ? [...obj] : { ...obj };\n}\nfunction replaceSecrets(root, secretsMap) {\n const result = shallowCopy(root);\n for (const [path, secretId] of Object.entries(secretsMap)) {\n const [last, ...partsReverse] = path.split(\".\").reverse();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let current = result;\n for (const part of partsReverse.reverse()) {\n if (current[part] === undefined) {\n break;\n }\n current[part] = shallowCopy(current[part]);\n current = current[part];\n }\n if (current[last] !== undefined) {\n current[last] = {\n lc: 1,\n type: \"secret\",\n id: [secretId],\n };\n }\n }\n return result;\n}\n/**\n * Get a unique name for the module, rather than parent class implementations.\n * Should not be subclassed, subclass lc_name above instead.\n */\nexport function get_lc_unique_name(\n// eslint-disable-next-line @typescript-eslint/no-use-before-define\nserializableClass) {\n // \"super\" here would refer to the parent class of Serializable,\n // when we want the parent class of the module actually calling this method.\n const parentClass = Object.getPrototypeOf(serializableClass);\n const lcNameIsSubclassed = typeof serializableClass.lc_name === \"function\" &&\n (typeof parentClass.lc_name !== \"function\" ||\n serializableClass.lc_name() !== parentClass.lc_name());\n if (lcNameIsSubclassed) {\n return serializableClass.lc_name();\n }\n else {\n return serializableClass.name;\n }\n}\nexport class Serializable {\n /**\n * The name of the serializable. Override to provide an alias or\n * to preserve the serialized module name in minified environments.\n *\n * Implemented as a static method to support loading logic.\n */\n static lc_name() {\n return this.name;\n }\n /**\n * The final serialized identifier for the module.\n */\n get lc_id() {\n return [\n ...this.lc_namespace,\n get_lc_unique_name(this.constructor),\n ];\n }\n /**\n * A map of secrets, which will be omitted from serialization.\n * Keys are paths to the secret in constructor args, e.g. \"foo.bar.baz\".\n * Values are the secret ids, which will be used when deserializing.\n */\n get lc_secrets() {\n return undefined;\n }\n /**\n * A map of additional attributes to merge with constructor args.\n * Keys are the attribute names, e.g. \"foo\".\n * Values are the attribute values, which will be serialized.\n * These attributes need to be accepted by the constructor as arguments.\n */\n get lc_attributes() {\n return undefined;\n }\n /**\n * A map of aliases for constructor args.\n * Keys are the attribute names, e.g. \"foo\".\n * Values are the alias that will replace the key in serialization.\n * This is used to eg. make argument names match Python.\n */\n get lc_aliases() {\n return undefined;\n }\n constructor(kwargs, ..._args) {\n Object.defineProperty(this, \"lc_serializable\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: false\n });\n Object.defineProperty(this, \"lc_kwargs\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.lc_kwargs = kwargs || {};\n }\n toJSON() {\n if (!this.lc_serializable) {\n return this.toJSONNotImplemented();\n }\n if (\n // eslint-disable-next-line no-instanceof/no-instanceof\n this.lc_kwargs instanceof Serializable ||\n typeof this.lc_kwargs !== \"object\" ||\n Array.isArray(this.lc_kwargs)) {\n // We do not support serialization of classes with arg not a POJO\n // I'm aware the check above isn't as strict as it could be\n return this.toJSONNotImplemented();\n }\n const aliases = {};\n const secrets = {};\n const kwargs = Object.keys(this.lc_kwargs).reduce((acc, key) => {\n acc[key] = key in this ? this[key] : this.lc_kwargs[key];\n return acc;\n }, {});\n // get secrets, attributes and aliases from all superclasses\n for (\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n let current = Object.getPrototypeOf(this); current; current = Object.getPrototypeOf(current)) {\n Object.assign(aliases, Reflect.get(current, \"lc_aliases\", this));\n Object.assign(secrets, Reflect.get(current, \"lc_secrets\", this));\n Object.assign(kwargs, Reflect.get(current, \"lc_attributes\", this));\n }\n // include all secrets used, even if not in kwargs,\n // will be replaced with sentinel value in replaceSecrets\n Object.keys(secrets).forEach((keyPath) => {\n // eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any\n let read = this;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let write = kwargs;\n const [last, ...partsReverse] = keyPath.split(\".\").reverse();\n for (const key of partsReverse.reverse()) {\n if (!(key in read) || read[key] === undefined)\n return;\n if (!(key in write) || write[key] === undefined) {\n if (typeof read[key] === \"object\" && read[key] != null) {\n write[key] = {};\n }\n else if (Array.isArray(read[key])) {\n write[key] = [];\n }\n }\n read = read[key];\n write = write[key];\n }\n if (last in read && read[last] !== undefined) {\n write[last] = write[last] || read[last];\n }\n });\n return {\n lc: 1,\n type: \"constructor\",\n id: this.lc_id,\n kwargs: mapKeys(Object.keys(secrets).length ? replaceSecrets(kwargs, secrets) : kwargs, keyToJson, aliases),\n };\n }\n toJSONNotImplemented() {\n return {\n lc: 1,\n type: \"not_implemented\",\n id: this.lc_id,\n };\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,OAAO,QAAQ,eAAe;AAClD,SAASC,WAAWA,CAACC,GAAG,EAAE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