gitnexus 1.6.9-rc.16 → 1.6.9-rc.18
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/package.json +1 -1
- package/web/assets/{agent-D3Xd7zZE.js → agent-C1yQhYA6.js} +2 -2
- package/web/assets/{architectureDiagram-UL44E2DR-ChH9xW-N.js → architectureDiagram-UL44E2DR-BEE5Tkn1.js} +1 -1
- package/web/assets/{chunk-LCXTWHL2-zoomRtWX.js → chunk-LCXTWHL2-CJFWRlb3.js} +1 -1
- package/web/assets/{chunk-RG4AUYOV-DD0B2N2B.js → chunk-RG4AUYOV-BnLGWH9h.js} +1 -1
- package/web/assets/{classDiagram-KGZ6W3CR-DJm9BgF-.js → classDiagram-KGZ6W3CR-CLQYoVUJ.js} +1 -1
- package/web/assets/{classDiagram-v2-72OJOZXJ-DJm9BgF-.js → classDiagram-v2-72OJOZXJ-CLQYoVUJ.js} +1 -1
- package/web/assets/{dagre-ND4H6XIP-BIkxmhcu.js → dagre-ND4H6XIP-Dr5QY4wD.js} +1 -1
- package/web/assets/{diagram-3NCE3AQN-BTa6iH0T.js → diagram-3NCE3AQN-BvWBILtA.js} +1 -1
- package/web/assets/{diagram-GF46GFSD-DZDV0vBj.js → diagram-GF46GFSD-Br3zOR7t.js} +1 -1
- package/web/assets/{diagram-QXG6HAR7-BzM--Jj0.js → diagram-QXG6HAR7-Cs3KWLM2.js} +1 -1
- package/web/assets/{diagram-WEQXMOUZ-DFFwz0k4.js → diagram-WEQXMOUZ-Cxjpe-cV.js} +1 -1
- package/web/assets/{erDiagram-L5TCEMPS-CfHMJJqo.js → erDiagram-L5TCEMPS-CJwkg3B3.js} +1 -1
- package/web/assets/{flowDiagram-H6V6AXG4-Be805QiJ.js → flowDiagram-H6V6AXG4-BgHq4Oef.js} +1 -1
- package/web/assets/{index-BvYev1UJ.js → index-BNHlZ4--.js} +5 -5
- package/web/assets/{infoDiagram-3YFTVSEB-Y7BKSoke.js → infoDiagram-3YFTVSEB-DDs1fvtj.js} +1 -1
- package/web/assets/{ishikawaDiagram-BNXS4ZKH-CT4SHFuI.js → ishikawaDiagram-BNXS4ZKH-zhdjhNj8.js} +1 -1
- package/web/assets/{kanban-definition-75IXJCU3-C6yDxr7N.js → kanban-definition-75IXJCU3-DzBwKL9_.js} +1 -1
- package/web/assets/{mindmap-definition-2TDM6QVE-BOc2WEne.js → mindmap-definition-2TDM6QVE-B6J7xmd_.js} +1 -1
- package/web/assets/{pieDiagram-CU6KROY3-Cvc0f_Pd.js → pieDiagram-CU6KROY3-CkAf4LWQ.js} +1 -1
- package/web/assets/{requirementDiagram-JXO7QTGE-BRcZvHs4.js → requirementDiagram-JXO7QTGE-DTxn3BGP.js} +1 -1
- package/web/assets/{sequenceDiagram-VS2MUI6T-PcSCuvrB.js → sequenceDiagram-VS2MUI6T-TkQjGTFD.js} +1 -1
- package/web/assets/{stateDiagram-7D4R322I-D6qYSV1E.js → stateDiagram-7D4R322I-BZ6GiE7S.js} +1 -1
- package/web/assets/{stateDiagram-v2-36443NZ5-Bg-ImOSX.js → stateDiagram-v2-36443NZ5-zudj8EhG.js} +1 -1
- package/web/assets/{timeline-definition-O6YCAMPW-QWkh01xw.js → timeline-definition-O6YCAMPW-wfNw45-O.js} +1 -1
- package/web/assets/{vennDiagram-MWXL3ELB-ak4DfwuM.js → vennDiagram-MWXL3ELB-9Jef__Cf.js} +1 -1
- package/web/assets/{wardleyDiagram-CUQ6CDDI-CTzR4Loq.js → wardleyDiagram-CUQ6CDDI-BJOzwKo8.js} +1 -1
- package/web/assets/{xychartDiagram-N2JHSOCM-DA1BEaQz.js → xychartDiagram-N2JHSOCM-BMP7fFl2.js} +1 -1
- package/web/index.html +1 -1
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e,f as t,g as n,h as r}from"./index-
|
|
1
|
+
import{d as e,f as t,g as n,h as r}from"./index-BNHlZ4--.js";import{CHAT_ONLY_PROMPT_NOTE as i,buildDynamicSystemPrompt as a}from"./context-builder-BHiFUA8O.js";var o=Object.defineProperty,s=(e,t)=>{let n={};for(var r in e)o(n,r,{get:e[r],enumerable:!0});return t||o(n,Symbol.toStringTag,{value:`Module`}),n};function c(e){let t=Symbol.for(e);return{brand(n,r){let i=r?Symbol.for(`${e}.${r}`):t;class a extends n{[i]=!0;constructor(...e){super(...e)}static isInstance(e){return typeof e==`object`&&!!e&&i in e&&e[i]===!0}}return Object.defineProperty(a,"name",{value:n.name}),a},sub(t){return c(`${e}.${t}`)},isInstance(e){return typeof e==`object`&&!!e&&t in e&&e[t]===!0}}}var l=c(`langchain`),u=s({ContextOverflowError:()=>h,LangChainError:()=>p,ModelAbortError:()=>m,addLangChainErrorFields:()=>d,ns:()=>f});function d(e,t){return e.lc_error_code=t,e.message=`${e.message}\n\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langchain/errors/${t}/\n`,e}var f=l.sub(`error`),p=class extends f.brand(Error){name=`LangChainError`;constructor(e){super(e),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}},m=class extends f.brand(p,`model-abort`){name=`ModelAbortError`;partialOutput;constructor(e,t){super(e),this.partialOutput=t}},h=class e extends f.brand(p,`context-overflow`){name=`ContextOverflowError`;cause;constructor(e){super(e??`Input exceeded the model's context window.`)}static fromError(t){let n=new e(t.message);return n.cause=t,n}};function g(e){return!!(e&&typeof e==`object`&&`type`in e&&e.type===`tool_call`)}function _(e){return!!(e&&typeof e==`object`&&`toolCall`in e&&e.toolCall!=null&&typeof e.toolCall==`object`&&`id`in e.toolCall&&typeof e.toolCall.id==`string`)}var v=class extends Error{output;constructor(e,t){super(e),this.output=t}};function y(e,t=x){e=e.trim();let n=e.indexOf("```");if(n===-1)return t(e);let r=e.substring(n+3);r.startsWith(`json
|
|
2
2
|
`)?r=r.substring(5):r.startsWith(`json`)?r=r.substring(4):r.startsWith(`
|
|
3
3
|
`)&&(r=r.substring(1));let i=r.indexOf("```"),a=r;return i!==-1&&(a=r.substring(0,i)),t(a.trim())}function b(e){try{return JSON.parse(e)}catch{}let t=e.trim();if(t.length===0)throw Error(`Unexpected end of JSON input`);let n=0;function r(){for(;n<t.length&&/\s/.test(t[n]);)n+=1}function i(){if(t[n]!==`"`)throw Error(`Expected '"' at position ${n}, got '${t[n]}'`);n+=1;let e=``,r=!1;for(;n<t.length;){let i=t[n];if(r){if(i===`n`)e+=`
|
|
4
4
|
`;else if(i===`t`)e+=` `;else if(i===`r`)e+=`\r`;else if(i===`\\`)e+=`\\`;else if(i===`"`)e+=`"`;else if(i===`b`)e+=`\b`;else if(i===`f`)e+=`\f`;else if(i===`/`)e+=`/`;else if(i===`u`){let r=t.substring(n+1,n+5);if(/^[0-9A-Fa-f]{0,4}$/.test(r))r.length===4?e+=String.fromCharCode(Number.parseInt(r,16)):e+=`u${r}`,n+=r.length;else throw Error(`Invalid unicode escape sequence '\\u${r}' at position ${n}`)}else throw Error(`Invalid escape sequence '\\${i}' at position ${n}`);r=!1}else if(i===`\\`)r=!0;else if(i===`"`)return n+=1,e;else e+=i;n+=1}return r&&(e+=`\\`),e}function a(){let e=n,r=``;if(t[n]===`-`&&(r+=`-`,n+=1),n<t.length&&t[n]===`0`&&(r+=`0`,n+=1,t[n]>=`0`&&t[n]<=`9`))throw Error(`Invalid number at position ${e}`);if(n<t.length&&t[n]>=`1`&&t[n]<=`9`)for(;n<t.length&&t[n]>=`0`&&t[n]<=`9`;)r+=t[n],n+=1;if(n<t.length&&t[n]===`.`)for(r+=`.`,n+=1;n<t.length&&t[n]>=`0`&&t[n]<=`9`;)r+=t[n],n+=1;if(n<t.length&&(t[n]===`e`||t[n]===`E`))for(r+=t[n],n+=1,n<t.length&&(t[n]===`+`||t[n]===`-`)&&(r+=t[n],n+=1);n<t.length&&t[n]>=`0`&&t[n]<=`9`;)r+=t[n],n+=1;if(r===`-`)return-0;let i=Number.parseFloat(r);if(Number.isNaN(i))throw n=e,Error(`Invalid number '${r}' at position ${e}`);return i}function o(){if(r(),n>=t.length)throw Error(`Unexpected end of input at position ${n}`);let e=t[n];if(e===`{`)return c();if(e===`[`)return s();if(e===`"`)return i();if(`null`.startsWith(t.substring(n,n+4)))return n+=Math.min(4,t.length-n),null;if(`true`.startsWith(t.substring(n,n+4)))return n+=Math.min(4,t.length-n),!0;if(`false`.startsWith(t.substring(n,n+5)))return n+=Math.min(5,t.length-n),!1;if(e===`-`||e>=`0`&&e<=`9`)return a();throw Error(`Unexpected character '${e}' at position ${n}`)}function s(){if(t[n]!==`[`)throw Error(`Expected '[' at position ${n}, got '${t[n]}'`);let e=[];if(n+=1,r(),n>=t.length)return e;if(t[n]===`]`)return n+=1,e;for(;n<t.length;){if(r(),n>=t.length||(e.push(o()),r(),n>=t.length))return e;if(t[n]===`]`)return n+=1,e;if(t[n]===`,`){n+=1;continue}throw Error(`Expected ',' or ']' at position ${n}, got '${t[n]}'`)}return e}function c(){if(t[n]!==`{`)throw Error(`Expected '{' at position ${n}, got '${t[n]}'`);let e={};if(n+=1,r(),n>=t.length)return e;if(t[n]===`}`)return n+=1,e;for(;n<t.length;){if(r(),n>=t.length)return e;let a=i();if(r(),n>=t.length)return e;if(t[n]!==`:`)throw Error(`Expected ':' at position ${n}, got '${t[n]}'`);if(n+=1,r(),n>=t.length||(e[a]=o(),r(),n>=t.length))return e;if(t[n]===`}`)return n+=1,e;if(t[n]===`,`){n+=1;continue}throw Error(`Expected ',' or '}' at position ${n}, got '${t[n]}'`)}return e}let l=o();if(r(),n<t.length)throw Error(`Unexpected character '${t[n]}' at position ${n}`);return l}function x(e){try{return e===void 0?null:b(e)}catch{return null}}var ee=/([A-Z]+)([A-Z][a-z0-9]+)/g,te=/([a-z0-9])([A-Z])/g,S=/[-_\s]+/g;function ne(e){return e.replace(ee,`$1_$2`).replace(te,`$1_$2`).replace(S,`_`).toLowerCase()}function re(e){let t=e.trim();return/[-_\s]/.test(t)?t.replace(S,`_`).toLowerCase().replace(/_+([a-z0-9])/g,(e,t)=>t.toUpperCase()):t}function ie(e,t){return t?.[e]||ne(e)}function ae(e,t){return t?.[e]||re(e)}function oe(e,t,n){let r={};for(let i in e)Object.hasOwn(e,i)&&(r[t(i,n)]=e[i]);return r}var se=`__lc_escaped__`;function ce(e){return`lc`in e||Object.keys(e).length===1&&`__lc_escaped__`in e}function C(e){return{[se]:e}}function le(e){return Object.keys(e).length===1&&`__lc_escaped__`in e}function ue(e){return typeof e==`object`&&!!e&&`lc_serializable`in e&&typeof e.toJSON==`function`}function de(e){let t;return t=typeof e==`object`&&e?`lc_id`in e&&Array.isArray(e.lc_id)?e.lc_id:[e.constructor?.name??`Object`]:[typeof e],{lc:1,type:`not_implemented`,id:t}}function fe(e,t=new WeakSet){if(typeof e==`object`&&e&&!Array.isArray(e)){if(t.has(e))return de(e);if(ue(e))return e;t.add(e);let n=e;if(ce(n))return t.delete(e),C(n);let r={};for(let[e,i]of Object.entries(n))r[e]=fe(i,t);return t.delete(e),r}return Array.isArray(e)?e.map(e=>fe(e,t)):e}function pe(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t=e;if(le(t))return t[se];let n={};for(let[e,r]of Object.entries(t))n[e]=pe(r);return n}return Array.isArray(e)?e.map(e=>pe(e)):e}var me=s({Serializable:()=>ve,get_lc_unique_name:()=>_e});function he(e){return Array.isArray(e)?[...e]:{...e}}function ge(e,t){let n=he(e);for(let[e,r]of Object.entries(t)){let[t,...i]=e.split(`.`).reverse(),a=n;for(let e of i.reverse()){if(a[e]===void 0)break;a[e]=he(a[e]),a=a[e]}a[t]!==void 0&&(a[t]={lc:1,type:`secret`,id:[r]})}return n}function _e(e){let t=Object.getPrototypeOf(e);return typeof e.lc_name==`function`&&(typeof t.lc_name!=`function`||e.lc_name()!==t.lc_name())?e.lc_name():e.name}var ve=class e{lc_serializable=!1;lc_kwargs;static lc_name(){return this.name}get lc_id(){return[...this.lc_namespace,_e(this.constructor)]}get lc_secrets(){}get lc_attributes(){}get lc_aliases(){}get lc_serializable_keys(){}constructor(e,...t){this.lc_serializable_keys===void 0?this.lc_kwargs=e??{}:this.lc_kwargs=Object.fromEntries(Object.entries(e||{}).filter(([e])=>this.lc_serializable_keys?.includes(e)))}toJSON(){if(!this.lc_serializable||this.lc_kwargs instanceof e||typeof this.lc_kwargs!=`object`||Array.isArray(this.lc_kwargs))return this.toJSONNotImplemented();let t={},n={},r=Object.keys(this.lc_kwargs).reduce((e,t)=>(e[t]=t in this?this[t]:this.lc_kwargs[t],e),{});for(let e=Object.getPrototypeOf(this);e;e=Object.getPrototypeOf(e))Object.assign(t,Reflect.get(e,`lc_aliases`,this)),Object.assign(n,Reflect.get(e,`lc_secrets`,this)),Object.assign(r,Reflect.get(e,`lc_attributes`,this));Object.keys(n).forEach(e=>{let t=this,n=r,[i,...a]=e.split(`.`).reverse();for(let e of a.reverse()){if(!(e in t)||t[e]===void 0)return;(!(e in n)||n[e]===void 0)&&(typeof t[e]==`object`&&t[e]!=null?n[e]={}:Array.isArray(t[e])&&(n[e]=[])),t=t[e],n=n[e]}i in t&&t[i]!==void 0&&(n[i]=n[i]||t[i])});let i={},a=new WeakSet;a.add(this);for(let[e,t]of Object.entries(r))i[e]=fe(t,a);let o=oe(Object.keys(n).length?ge(i,n):i,ie,t);return{lc:1,type:`constructor`,id:this.lc_id,kwargs:o}}toJSONNotImplemented(){return{lc:1,type:`not_implemented`,id:this.lc_id}}};function ye(e){return typeof e==`object`&&!!e&&`type`in e&&typeof e.type==`string`&&`source_type`in e&&(e.source_type===`url`||e.source_type===`base64`||e.source_type===`text`||e.source_type===`id`)}function be(e){return ye(e)&&e.source_type===`url`&&`url`in e&&typeof e.url==`string`}function xe(e){return ye(e)&&e.source_type===`base64`&&`data`in e&&typeof e.data==`string`}function Se(e){return ye(e)&&e.source_type===`text`&&`text`in e&&typeof e.text==`string`}function Ce(e){return ye(e)&&e.source_type===`id`&&`id`in e&&typeof e.id==`string`}function we(e){if(ye(e)){if(e.source_type===`url`)return{type:`image_url`,image_url:{url:e.url}};if(e.source_type===`base64`){if(!e.mime_type)throw Error(`mime_type key is required for base64 data.`);return{type:`image_url`,image_url:{url:`data:${e.mime_type};base64,${e.data}`}}}}throw Error(`Unsupported source type. Only 'url' and 'base64' are supported.`)}function Te(e){let t=e.split(`;`)[0].split(`/`);if(t.length!==2)throw Error(`Invalid mime type: "${e}" - does not match type/subtype format.`);let n=t[0].trim(),r=t[1].trim();if(n===``||r===``)throw Error(`Invalid mime type: "${e}" - type or subtype is empty.`);let i={};for(let t of e.split(`;`).slice(1)){let n=t.split(`=`);if(n.length!==2)throw Error(`Invalid parameter syntax in mime type: "${e}".`);let r=n[0].trim(),a=n[1].trim();if(r===``)throw Error(`Invalid parameter syntax in mime type: "${e}".`);i[r]=a}return{type:n,subtype:r,parameters:i}}function Ee({dataUrl:e,asTypedArray:t=!1}){let n=e.match(/^data:(\w+\/\w+);base64,([A-Za-z0-9+/]+=*)$/),r;if(n){r=n[1].toLowerCase();let e=t?Uint8Array.from(atob(n[2]),e=>e.charCodeAt(0)):n[2];return{mime_type:r,data:e}}}function De(e,t){if(e.type===`text`){if(!t.fromStandardTextBlock)throw Error(`Converter for ${t.providerName} does not implement \`fromStandardTextBlock\` method.`);return t.fromStandardTextBlock(e)}if(e.type===`image`){if(!t.fromStandardImageBlock)throw Error(`Converter for ${t.providerName} does not implement \`fromStandardImageBlock\` method.`);return t.fromStandardImageBlock(e)}if(e.type===`audio`){if(!t.fromStandardAudioBlock)throw Error(`Converter for ${t.providerName} does not implement \`fromStandardAudioBlock\` method.`);return t.fromStandardAudioBlock(e)}if(e.type===`file`){if(!t.fromStandardFileBlock)throw Error(`Converter for ${t.providerName} does not implement \`fromStandardFileBlock\` method.`);return t.fromStandardFileBlock(e)}throw Error(`Unable to convert content block type '${e.type}' to provider-specific format: not recognized.`)}function w(e,t){return T(e)&&e.type===t}function T(e){return typeof e==`object`&&!!e}function Oe(e){return Array.isArray(e)}function E(e){return typeof e==`string`}function D(e){return typeof e==`number`}function ke(e){return e instanceof Uint8Array}function Ae(e){try{return JSON.parse(e)}catch{return}}var je=e=>e();function Me(e){if(e.type===`char_location`&&E(e.document_title)&&D(e.start_char_index)&&D(e.end_char_index)&&E(e.cited_text)){let{document_title:t,start_char_index:n,end_char_index:r,cited_text:i,...a}=e;return{...a,type:`citation`,source:`char`,title:t??void 0,startIndex:n,endIndex:r,citedText:i}}if(e.type===`page_location`&&E(e.document_title)&&D(e.start_page_number)&&D(e.end_page_number)&&E(e.cited_text)){let{document_title:t,start_page_number:n,end_page_number:r,cited_text:i,...a}=e;return{...a,type:`citation`,source:`page`,title:t??void 0,startIndex:n,endIndex:r,citedText:i}}if(e.type===`content_block_location`&&E(e.document_title)&&D(e.start_block_index)&&D(e.end_block_index)&&E(e.cited_text)){let{document_title:t,start_block_index:n,end_block_index:r,cited_text:i,...a}=e;return{...a,type:`citation`,source:`block`,title:t??void 0,startIndex:n,endIndex:r,citedText:i}}if(e.type===`web_search_result_location`&&E(e.url)&&E(e.title)&&E(e.encrypted_index)&&E(e.cited_text)){let{url:t,title:n,encrypted_index:r,cited_text:i,...a}=e;return{...a,type:`citation`,source:`url`,url:t,title:n,startIndex:Number(r),endIndex:Number(r),citedText:i}}if(e.type===`search_result_location`&&E(e.source)&&E(e.title)&&D(e.start_block_index)&&D(e.end_block_index)&&E(e.cited_text)){let{source:t,title:n,start_block_index:r,end_block_index:i,cited_text:a,...o}=e;return{...o,type:`citation`,source:`search`,url:t,title:n??void 0,startIndex:r,endIndex:i,citedText:a}}}function Ne(e){if(w(e,`document`)&&T(e.source)&&`type`in e.source){if(e.source.type===`base64`&&E(e.source.media_type)&&E(e.source.data))return{type:`file`,mimeType:e.source.media_type,data:e.source.data};if(e.source.type===`url`&&E(e.source.url))return{type:`file`,url:e.source.url};if(e.source.type===`file`&&E(e.source.file_id))return{type:`file`,fileId:e.source.file_id};if(e.source.type===`text`&&E(e.source.data))return{type:`file`,mimeType:String(e.source.media_type??`text/plain`),data:e.source.data}}else if(w(e,`image`)&&T(e.source)&&`type`in e.source){if(e.source.type===`base64`&&E(e.source.media_type)&&E(e.source.data))return{type:`image`,mimeType:e.source.media_type,data:e.source.data};if(e.source.type===`url`&&E(e.source.url))return{type:`image`,url:e.source.url};if(e.source.type===`file`&&E(e.source.file_id))return{type:`image`,fileId:e.source.file_id}}}function Pe(e){function*t(){for(let t of e){let e=Ne(t);e?yield e:yield t}}return Array.from(t())}function Fe(e){function*t(){let t=typeof e.content==`string`?[{type:`text`,text:e.content}]:e.content;for(let n of t){if(w(n,`text`)&&E(n.text)){let{text:e,citations:t,...r}=n;if(Oe(t)&&t.length){let n=t.reduce((e,t)=>{let n=Me(t);return n?[...e,n]:e},[]);yield{...r,type:`text`,text:e,annotations:n};continue}else{yield{...r,type:`text`,text:e};continue}}else if(w(n,`thinking`)&&E(n.thinking)){let{thinking:e,signature:t,...r}=n;yield{...r,type:`reasoning`,reasoning:e,signature:t};continue}else if(w(n,`redacted_thinking`)){yield{type:`non_standard`,value:n};continue}else if(w(n,`tool_use`)&&E(n.name)&&E(n.id)){yield{type:`tool_call`,id:n.id,name:n.name,args:n.input};continue}else if(w(n,`input_json_delta`)){if(Le(e)&&e.tool_call_chunks?.length){let t=e.tool_call_chunks[0];yield{type:`tool_call_chunk`,id:t.id,name:t.name,args:t.args,index:t.index};continue}}else if(w(n,`server_tool_use`)&&E(n.name)&&E(n.id)){let{name:e,id:t}=n;if(e===`web_search`){yield{id:t,type:`server_tool_call`,name:`web_search`,args:{query:je(()=>{if(typeof n.input==`string`)return n.input;if(T(n.input)&&E(n.input.query))return n.input.query;if(E(n.partial_json)){let e=Ae(n.partial_json);if(e?.query)return e.query}return``})}};continue}else if(n.name===`code_execution`){yield{id:t,type:`server_tool_call`,name:`code_execution`,args:{code:je(()=>{if(typeof n.input==`string`)return n.input;if(T(n.input)&&E(n.input.code))return n.input.code;if(E(n.partial_json)){let e=Ae(n.partial_json);if(e?.code)return e.code}return``})}};continue}}else if(w(n,`web_search_tool_result`)&&E(n.tool_use_id)&&Oe(n.content)){let{content:e,tool_use_id:t}=n;yield{type:`server_tool_call_result`,name:`web_search`,toolCallId:t,status:`success`,output:{urls:e.reduce((e,t)=>w(t,`web_search_result`)?[...e,t.url]:e,[])}};continue}else if(w(n,`code_execution_tool_result`)&&E(n.tool_use_id)&&T(n.content)){yield{type:`server_tool_call_result`,name:`code_execution`,toolCallId:n.tool_use_id,status:`success`,output:n.content};continue}else if(w(n,`mcp_tool_use`)){yield{id:n.id,type:`server_tool_call`,name:`mcp_tool_use`,args:n.input};continue}else if(w(n,`mcp_tool_result`)&&E(n.tool_use_id)&&T(n.content)){yield{type:`server_tool_call_result`,name:`mcp_tool_use`,toolCallId:n.tool_use_id,status:`success`,output:n.content};continue}else if(w(n,`container_upload`)){yield{type:`server_tool_call`,name:`container_upload`,args:n.input};continue}else if(w(n,`search_result`)){yield{id:n.id,type:`non_standard`,value:n};continue}else if(w(n,`tool_result`)){yield{id:n.id,type:`non_standard`,value:n};continue}else{let e=Ne(n);if(e){yield e;continue}}yield{type:`non_standard`,value:n}}}return Array.from(t())}var Ie={translateContent:Fe,translateContentChunk:Fe};function Le(e){return typeof e?._getType==`function`&&typeof e.concat==`function`&&e._getType()===`ai`}function Re(e){return be(e)?{type:e.type,mimeType:e.mime_type,url:e.url,metadata:e.metadata}:xe(e)?{type:e.type,mimeType:e.mime_type??`application/octet-stream`,data:e.data,metadata:e.metadata}:Ce(e)?{type:e.type,mimeType:e.mime_type,fileId:e.id,metadata:e.metadata}:e}function ze(e){return e.map(Re)}function Be(e){return!!(w(e,`image_url`)&&T(e.image_url)||w(e,`input_audio`)&&T(e.input_audio)||w(e,`file`)&&T(e.file))}function Ve(e){if(w(e,`image_url`)&&T(e.image_url)&&E(e.image_url.url)){let t=Ee({dataUrl:e.image_url.url});return t?{type:`image`,mimeType:t.mime_type,data:t.data}:{type:`image`,url:e.image_url.url}}else if(w(e,`input_audio`)&&T(e.input_audio)&&E(e.input_audio.data)&&E(e.input_audio.format))return{type:`audio`,data:e.input_audio.data,mimeType:`audio/${e.input_audio.format}`};else if(w(e,`file`)&&T(e.file)&&E(e.file.data)){let t=Ee({dataUrl:e.file.data});if(t)return{type:`file`,data:t.data,mimeType:t.mime_type};if(E(e.file.file_id))return{type:`file`,fileId:e.file.file_id}}return e}function He(e){let t=[];typeof e.content==`string`?e.content.length>0&&t.push({type:`text`,text:e.content}):t.push(...We(e.content));for(let n of e.tool_calls??[])t.push({type:`tool_call`,id:n.id,name:n.name,args:n.args});return t}function Ue(e){let t=[];typeof e.content==`string`?e.content.length>0&&t.push({type:`text`,text:e.content}):t.push(...We(e.content));for(let n of e.tool_calls??[])t.push({type:`tool_call`,id:n.id,name:n.name,args:n.args});return t}function We(e){let t=[];for(let n of e)Be(n)?t.push(Ve(n)):t.push(n);return t}function Ge(e){if(e.type===`url_citation`){let{url:t,title:n,start_index:r,end_index:i}=e;return{type:`citation`,url:t,title:n,startIndex:r,endIndex:i}}if(e.type===`file_citation`){let{file_id:t,filename:n,index:r}=e;return{type:`citation`,title:n,startIndex:r,endIndex:r,fileId:t}}return e}function Ke(e){function*t(){T(e.additional_kwargs?.reasoning)&&Oe(e.additional_kwargs.reasoning.summary)&&(yield{type:`reasoning`,reasoning:e.additional_kwargs.reasoning.summary.reduce((e,t)=>T(t)&&E(t.text)?`${e}${t.text}`:e,``)});let t=typeof e.content==`string`?[{type:`text`,text:e.content}]:e.content;for(let e of t)if(w(e,`text`)){let{text:t,annotations:n,phase:r,extras:i,...a}=e,o=T(i)?{...i}:{};E(r)&&(o.phase=r);let s=Object.keys(o).length>0?{extras:o}:{};Array.isArray(n)?yield{...a,...s,type:`text`,text:String(t),annotations:n.map(Ge)}:yield{...a,...s,type:`text`,text:String(t)}}for(let t of e.tool_calls??[])yield{type:`tool_call`,id:t.id,name:t.name,args:t.args};if(T(e.additional_kwargs)&&Oe(e.additional_kwargs.tool_outputs))for(let t of e.additional_kwargs.tool_outputs){if(w(t,`web_search_call`)){let e={};if(T(t.action)&&E(t.action.query)&&(e.query=t.action.query),yield{id:t.id,type:`server_tool_call`,name:`web_search`,args:e},t.status===`completed`||t.status===`failed`){let e={};T(t.action)&&(e.action=t.action),yield{type:`server_tool_call_result`,toolCallId:E(t.id)?t.id:``,status:t.status===`completed`?`success`:`error`,output:e}}continue}else if(w(t,`file_search_call`)){yield{id:t.id,type:`server_tool_call`,name:`file_search`,args:{queries:Oe(t.queries)?t.queries:[]}},(t.status===`completed`||t.status===`failed`)&&(yield{type:`server_tool_call_result`,toolCallId:E(t.id)?t.id:``,status:t.status===`completed`?`success`:`error`,output:Oe(t.results)?{results:t.results}:{}});continue}else if(w(t,`computer_call`)){yield{type:`non_standard`,value:t};continue}else if(w(t,`code_interpreter_call`)){if(E(t.code)&&(yield{id:t.id,type:`server_tool_call`,name:`code_interpreter`,args:{code:t.code}}),Oe(t.outputs)){let e=je(()=>{if(t.status!==`in_progress`){if(t.status===`completed`)return 0;if(t.status===`incomplete`)return 127;if(t.status!==`interpreting`&&t.status===`failed`)return 1}});for(let n of t.outputs)if(w(n,`logs`)){yield{type:`server_tool_call_result`,toolCallId:t.id??``,status:`success`,output:{type:`code_interpreter_output`,returnCode:e??0,stderr:[0,void 0].includes(e)?void 0:String(n.logs),stdout:[0,void 0].includes(e)?String(n.logs):void 0}};continue}}continue}else if(w(t,`mcp_call`)){yield{id:t.id,type:`server_tool_call`,name:`mcp_call`,args:t.input};continue}else if(w(t,`mcp_list_tools`)){yield{id:t.id,type:`server_tool_call`,name:`mcp_list_tools`,args:t.input};continue}else if(w(t,`mcp_approval_request`)){yield{type:`non_standard`,value:t};continue}else if(w(t,`tool_search_call`)){let e={};T(t.arguments)&&Object.assign(e,t.arguments);let n={};E(t.execution)&&(n.execution=t.execution),E(t.status)&&(n.status=t.status),E(t.call_id)&&(n.call_id=t.call_id),yield{id:E(t.id)?t.id:``,type:`server_tool_call`,name:`tool_search`,args:e,...Object.keys(n).length>0?{extras:n}:{}};continue}else if(w(t,`tool_search_output`)){let e={name:`tool_search`};E(t.execution)&&(e.execution=t.execution),yield{type:`server_tool_call_result`,toolCallId:E(t.id)?t.id:``,status:t.status===`completed`?`success`:t.status===`failed`?`error`:`success`,output:{tools:Oe(t.tools)?t.tools:[]},extras:e};continue}else if(w(t,`image_generation_call`)){E(t.result)&&(yield{type:`image`,mimeType:`image/png`,data:t.result,id:E(t.id)?t.id:void 0,metadata:{status:E(t.status)?t.status:void 0}}),yield{type:`non_standard`,value:t};continue}T(t)&&(yield{type:`non_standard`,value:t})}}return Array.from(t())}function qe(e){function*t(){yield*Ke(e);for(let t of e.tool_call_chunks??[])yield{type:`tool_call_chunk`,id:t.id,name:t.name,args:t.args}}return Array.from(t())}var Je={translateContent:e=>typeof e.content==`string`?He(e):Ke(e),translateContentChunk:e=>typeof e.content==`string`?Ue(e):qe(e)};function Ye(e){return typeof e==`object`&&!!e&&`type`in e&&`content`in e&&(typeof e.content==`string`||Array.isArray(e.content))}function Xe(e,t=`pretty`){return t===`pretty`?Ze(e):JSON.stringify(e)}function Ze(e){let t=[],n=` ${e.type.charAt(0).toUpperCase()+e.type.slice(1)} Message `,r=Math.floor((80-n.length)/2),i=`=`.repeat(r),a=n.length%2==0?i:`${i}=`;if(t.push(`${i}${n}${a}`),e.type===`ai`){let n=e;if(n.tool_calls&&n.tool_calls.length>0){t.push(`Tool Calls:`);for(let e of n.tool_calls){t.push(` ${e.name} (${e.id})`),t.push(` Call ID: ${e.id}`),t.push(` Args:`);for(let[n,r]of Object.entries(e.args))t.push(` ${n}: ${typeof r==`object`?JSON.stringify(r):r}`)}}}if(e.type===`tool`){let n=e;n.name&&t.push(`Name: ${n.name}`)}return typeof e.content==`string`&&e.content.trim()&&(t.length>1&&t.push(``),t.push(e.content)),t.join(`
|
|
@@ -98,7 +98,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
98
98
|
`)),n.close()}});return ru.fromReadableStream(n)}function tx(e){return typeof e==`object`&&!!e&&typeof e[Symbol.iterator]==`function`&&typeof e.next==`function`}var nx=e=>typeof e==`object`&&!!e&&`next`in e&&typeof e.next==`function`;function rx(e){return typeof e==`object`&&!!e&&typeof e[Symbol.asyncIterator]==`function`}function ix(e){return typeof e==`object`&&!!e&&typeof e.next==`function`}async function ax(e,t){try{let n=await e.next();for(;!n.done;)await t?.(n.value),n=await e.next();return n.value}finally{await e.return?.(void 0)}}function*ox(e,t){for(;;){let{value:n,done:r}=Wl.runWithConfig($l(e),t.next.bind(t),!0);if(r)break;yield n}}async function*sx(e,t){let n=t[Symbol.asyncIterator]();for(;;){let{value:r,done:i}=await Wl.runWithConfig($l(e),n.next.bind(t),!0);if(i)break;yield r}}function cx(e,t){return e&&!Array.isArray(e)&&!(e instanceof Date)&&typeof e==`object`?e:{[t]:e}}var lx=class extends ve{lc_runnable=!0;name;getName(e){let t=this.name??this.constructor.lc_name()??this.constructor.name;return e?`${t}${e}`:t}withRetry(e){return new fx({bound:this,kwargs:{},config:{},maxAttemptNumber:e?.stopAfterAttempt,...e})}withConfig(e){return new ux({bound:this,config:e,kwargs:{}})}withFallbacks(e){let t=Array.isArray(e)?e:e.fallbacks;return new yx({runnable:this,fallbacks:t})}_getOptionsList(e,t=0){if(Array.isArray(e)&&e.length!==t)throw Error(`Passed "options" must be an array with the same length as the inputs, but got ${e.length} options for ${t} inputs`);if(Array.isArray(e))return e.map(Zl);if(t>1&&!Array.isArray(e)&&e.runId){console.warn(`Provided runId will be used only for the first element of the batch.`);let n=Object.fromEntries(Object.entries(e).filter(([e])=>e!==`runId`));return Array.from({length:t},(t,r)=>Zl(r===0?e:n))}return Array.from({length:t},()=>Zl(e))}async batch(e,t,n){let r=this._getOptionsList(t??{},e.length),i=new sd({maxConcurrency:r[0]?.maxConcurrency??n?.maxConcurrency,onFailedAttempt:e=>{throw e}}),a=e.map((e,t)=>i.call(async()=>{try{return await this.invoke(e,r[t])}catch(e){if(n?.returnExceptions)return e;throw e}}));return Promise.all(a)}async*_streamIterator(e,t){yield this.invoke(e,t)}async stream(e,t){let n=Zl(t),r=new ou({generator:this._streamIterator(e,n),config:n});return await r.setup,ru.fromAsyncGenerator(r)}_separateRunnableConfigFromCallOptions(e){let t;t=Zl(e===void 0?e:{callbacks:e.callbacks,tags:e.tags,metadata:e.metadata,runName:e.runName,configurable:e.configurable,recursionLimit:e.recursionLimit,maxConcurrency:e.maxConcurrency,runId:e.runId,timeout:e.timeout,signal:e.signal});let n={...e};return delete n.callbacks,delete n.tags,delete n.metadata,delete n.runName,delete n.configurable,delete n.recursionLimit,delete n.maxConcurrency,delete n.runId,delete n.timeout,delete n.signal,[t,n]}async _callWithConfig(e,t,n){let r=Zl(n),i=await(await Yl(r))?.handleChainStart(this.toJSON(),cx(t,`input`),r.runId,r?.runType,void 0,void 0,r?.runName??this.getName());delete r.runId;let a;try{a=await eu(e.call(this,t,r,i),r.signal)}catch(e){throw await i?.handleChainError(e),e}return await i?.handleChainEnd(cx(a,`output`)),a}async _batchWithConfig(e,t,n,r){let i=this._getOptionsList(n??{},t.length),a=await Promise.all(i.map(Yl)),o=await Promise.all(a.map(async(e,n)=>{let r=await e?.handleChainStart(this.toJSON(),cx(t[n],`input`),i[n].runId,i[n].runType,void 0,void 0,i[n].runName??this.getName());return delete i[n].runId,r})),s;try{s=await eu(e.call(this,t,i,o,r),i?.[0]?.signal)}catch(e){throw await Promise.all(o.map(t=>t?.handleChainError(e))),e}return await Promise.all(o.map(e=>e?.handleChainEnd(cx(s,`output`)))),s}_concatOutputChunks(e,t){return au(e,t)}async*_transformStreamWithConfig(e,t,n){let r,i=!0,a,o=!0,s=Zl(n),c=await Yl(s),l=this;async function*u(){for await(let t of e){if(i)if(r===void 0)r=t;else try{r=l._concatOutputChunks(r,t)}catch{r=void 0,i=!1}yield t}}let d;try{let e=await su(t.bind(this),u(),async()=>c?.handleChainStart(this.toJSON(),{input:``},s.runId,s.runType,void 0,void 0,s.runName??this.getName(),void 0,{lc_defers_inputs:!0}),s.signal,s);delete s.runId,d=e.setup;let n=d?.handlers.find(Gu),r=e.output;n!==void 0&&d!==void 0&&(r=n.tapOutputIterable(d.runId,r));let i=d?.handlers.find(Fu);i!==void 0&&d!==void 0&&(r=i.tapOutputIterable(d.runId,r));for await(let e of r)if(yield e,o)if(a===void 0)a=e;else try{a=this._concatOutputChunks(a,e)}catch{a=void 0,o=!1}}catch(e){throw await d?.handleChainError(e,void 0,void 0,void 0,{inputs:cx(r,`input`)}),e}await d?.handleChainEnd(a??{},void 0,void 0,void 0,{inputs:cx(r,`input`)})}getGraph(e){let t=new Zb,n=t.addNode({name:`${this.getName()}Input`,schema:oy()}),r=t.addNode(this),i=t.addNode({name:`${this.getName()}Output`,schema:oy()});return t.addEdge(n,r),t.addEdge(r,i),t}pipe(e){return new px({first:this,last:bx(e)})}pick(e){return this.pipe(new Sx(e))}assign(e){return this.pipe(new xx(new mx({steps:e})))}async*transform(e,t){let n;for await(let t of e)n=n===void 0?t:this._concatOutputChunks(n,t);yield*this._streamIterator(n,Zl(t))}async*streamLog(e,t,n){let r=new zu({...n,autoClose:!1,_schemaFormat:`original`}),i=Zl(t);yield*this._streamLog(e,r,i)}async*_streamLog(e,t,n){let{callbacks:r}=n;if(r===void 0)n.callbacks=[t];else if(Array.isArray(r))n.callbacks=r.concat([t]);else{let e=r.copy();e.addHandler(t,!0),n.callbacks=e}let i=this.stream(e,n);async function a(){try{let e=await i;for await(let n of e){let e=new Nu({ops:[{op:`add`,path:`/streamed_output/-`,value:n}]});await t.writer.write(e)}}finally{await t.writer.close()}}let o=a();try{for await(let e of t)yield e}finally{await o}}streamEvents(e,t,n){let r;if(t.version===`v1`)r=this._streamEventsV1(e,t,n);else if(t.version===`v2`)r=this._streamEventsV2(e,t,n);else throw Error(`Only versions "v1" and "v2" of the schema are currently supported.`);return t.encoding===`text/event-stream`?ex(r):ru.fromAsyncGenerator(r)}async*_streamEventsV2(e,t,n){let r=new Ku({...n,autoClose:!1}),i=Zl(t),a=i.runId??Sr();i.runId=a;let o=i.callbacks;if(o===void 0)i.callbacks=[r];else if(Array.isArray(o))i.callbacks=o.concat(r);else{let e=o.copy();e.addHandler(r,!0),i.callbacks=e}let s=new AbortController,c=this;async function l(){let t;try{if(i.signal)if(`any`in AbortSignal)t=AbortSignal.any([s.signal,i.signal]);else{let e=new AbortController;i.signal.addEventListener(`abort`,()=>e.abort(),{once:!0}),s.signal.addEventListener(`abort`,()=>e.abort(),{once:!0}),t=e.signal}else t=s.signal;let n=await c.stream(e,{...i,signal:t}),o=r.tapOutputIterable(a,n);for await(let e of o)if(s.signal.aborted)break}finally{await r.finish()}}let u=l(),d=!1,f;try{for await(let t of r){if(!d){t.data.input=e,d=!0,f=t.run_id,yield t;continue}t.run_id===f&&t.event.endsWith(`_end`)&&t.data?.input&&delete t.data.input,yield t}}finally{s.abort(),await u}}async*_streamEventsV1(e,t,n){let r,i=!1,a=Zl(t),o=a.tags??[],s=a.metadata??{},c=a.runName??this.getName(),l=new zu({...n,autoClose:!1,_schemaFormat:`streaming_events`}),u=new ud({...n}),d=this._streamLog(e,l,a);for await(let t of d){if(r=r?r.concat(t):Pu.fromRunLogPatch(t),r.state===void 0)throw Error(`Internal error: "streamEvents" state is missing. Please open a bug report.`);if(!i){i=!0;let t={...r.state},n={run_id:t.id,event:`on_${t.type}_start`,name:c,tags:o,metadata:s,data:{input:e}};u.includeEvent(n,t.type)&&(yield n)}let n=t.ops.filter(e=>e.path.startsWith(`/logs/`)).map(e=>e.path.split(`/`)[2]),a=[...new Set(n)];for(let e of a){let t,n={},i=r.state.logs[e];if(t=i.end_time===void 0?i.streamed_output.length>0?`stream`:`start`:`end`,t===`start`)i.inputs!==void 0&&(n.input=i.inputs);else if(t===`end`)i.inputs!==void 0&&(n.input=i.inputs),n.output=i.final_output;else if(t===`stream`){let e=i.streamed_output.length;if(e!==1)throw Error(`Expected exactly one chunk of streamed output, got ${e} instead. Encountered in: "${i.name}"`);n={chunk:i.streamed_output[0]},i.streamed_output=[]}yield{event:`on_${i.type}_${t}`,name:i.name,run_id:i.id,tags:i.tags,metadata:i.metadata,data:n}}let{state:l}=r;if(l.streamed_output.length>0){let e=l.streamed_output.length;if(e!==1)throw Error(`Expected exactly one chunk of streamed output, got ${e} instead. Encountered in: "${l.name}"`);let t={chunk:l.streamed_output[0]};l.streamed_output=[];let n={event:`on_${l.type}_stream`,run_id:l.id,tags:o,metadata:s,name:c,data:t};u.includeEvent(n,l.type)&&(yield n)}}let f=r?.state;if(f!==void 0){let e={event:`on_${f.type}_end`,name:c,run_id:f.id,tags:o,metadata:s,data:{output:f.final_output}};u.includeEvent(e,f.type)&&(yield e)}}static isRunnable(e){return ld(e)}withListeners({onStart:e,onEnd:t,onError:n}){return new ux({bound:this,config:{},configFactories:[r=>({callbacks:[new cd({config:r,onStart:e,onEnd:t,onError:n})]})]})}asTool(e){return wx(this,e)}},ux=class e extends lx{static lc_name(){return`RunnableBinding`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;bound;config;kwargs;configFactories;constructor(e){super(e),this.bound=e.bound,this.kwargs=e.kwargs,this.config=e.config,this.configFactories=e.configFactories}getName(e){return this.bound.getName(e)}async _mergeConfig(...e){let t=Xl(this.config,...e);return Xl(t,...this.configFactories?await Promise.all(this.configFactories.map(async e=>await e(t))):[])}withConfig(e){return new this.constructor({bound:this.bound,kwargs:this.kwargs,config:{...this.config,...e}})}withRetry(e){return new fx({bound:this.bound,kwargs:this.kwargs,config:this.config,maxAttemptNumber:e?.stopAfterAttempt,...e})}async invoke(e,t){return this.bound.invoke(e,await this._mergeConfig(t,this.kwargs))}async batch(e,t,n){let r=Array.isArray(t)?await Promise.all(t.map(async e=>this._mergeConfig(Zl(e),this.kwargs))):await this._mergeConfig(Zl(t),this.kwargs);return this.bound.batch(e,r,n)}_concatOutputChunks(e,t){return this.bound._concatOutputChunks(e,t)}async*_streamIterator(e,t){yield*this.bound._streamIterator(e,await this._mergeConfig(Zl(t),this.kwargs))}async stream(e,t){return this.bound.stream(e,await this._mergeConfig(Zl(t),this.kwargs))}async*transform(e,t){yield*this.bound.transform(e,await this._mergeConfig(Zl(t),this.kwargs))}streamEvents(e,t,n){let r=this;return ru.fromAsyncGenerator(async function*(){yield*r.bound.streamEvents(e,{...await r._mergeConfig(Zl(t),r.kwargs),version:t.version},n)}())}static isRunnableBinding(e){return e.bound&&lx.isRunnable(e.bound)}withListeners({onStart:t,onEnd:n,onError:r}){return new e({bound:this.bound,kwargs:this.kwargs,config:this.config,configFactories:[e=>({callbacks:[new cd({config:e,onStart:t,onEnd:n,onError:r})]})]})}},dx=class e extends lx{static lc_name(){return`RunnableEach`}lc_serializable=!0;lc_namespace=[`langchain_core`,`runnables`];bound;constructor(e){super(e),this.bound=e.bound}async invoke(e,t){return this._callWithConfig(this._invoke.bind(this),e,t)}async _invoke(e,t,n){return this.bound.batch(e,Ql(t,{callbacks:n?.getChild()}))}withListeners({onStart:t,onEnd:n,onError:r}){return new e({bound:this.bound.withListeners({onStart:t,onEnd:n,onError:r})})}},fx=class extends ux{static lc_name(){return`RunnableRetry`}lc_namespace=[`langchain_core`,`runnables`];maxAttemptNumber=3;onFailedAttempt=()=>{};constructor(e){super(e),this.maxAttemptNumber=e.maxAttemptNumber??this.maxAttemptNumber,this.onFailedAttempt=e.onFailedAttempt??this.onFailedAttempt}_patchConfigForRetry(e,t,n){let r=e>1?`retry:attempt:${e}`:void 0;return Ql(t,{callbacks:n?.getChild(r)})}async _invoke(e,t,n){return rd(r=>super.invoke(e,this._patchConfigForRetry(r,t,n)),{onFailedAttempt:({error:t})=>this.onFailedAttempt(t,e),retries:Math.max(this.maxAttemptNumber-1,0),randomize:!0})}async invoke(e,t){return this._callWithConfig(this._invoke.bind(this),e,t)}async _batch(e,t,n,r){let i={};try{await rd(async a=>{let o=e.map((e,t)=>t).filter(e=>i[e.toString()]===void 0||i[e.toString()]instanceof Error),s=o.map(t=>e[t]),c=o.map(e=>this._patchConfigForRetry(a,t?.[e],n?.[e])),l=await super.batch(s,c,{...r,returnExceptions:!0}),u;for(let e=0;e<l.length;e+=1){let t=l[e],n=o[e];t instanceof Error&&u===void 0&&(u=t,u.input=s[e]),i[n.toString()]=t}if(u)throw u;return l},{onFailedAttempt:({error:e})=>this.onFailedAttempt(e,e.input),retries:Math.max(this.maxAttemptNumber-1,0),randomize:!0})}catch(e){if(r?.returnExceptions!==!0)throw e}return Object.keys(i).sort((e,t)=>parseInt(e,10)-parseInt(t,10)).map(e=>i[parseInt(e,10)])}async batch(e,t,n){return this._batchWithConfig(this._batch.bind(this),e,t,n)}},px=class e extends lx{static lc_name(){return`RunnableSequence`}first;middle=[];last;omitSequenceTags=!1;lc_serializable=!0;lc_namespace=[`langchain_core`,`runnables`];constructor(e){super(e),this.first=e.first,this.middle=e.middle??this.middle,this.last=e.last,this.name=e.name,this.omitSequenceTags=e.omitSequenceTags??this.omitSequenceTags}get steps(){return[this.first,...this.middle,this.last]}async invoke(e,t){let n=Zl(t),r=await(await Yl(n))?.handleChainStart(this.toJSON(),cx(e,`input`),n.runId,void 0,void 0,void 0,n?.runName);delete n.runId;let i=e,a;try{let e=[this.first,...this.middle];for(let t=0;t<e.length;t+=1)i=await eu(e[t].invoke(i,Ql(n,{callbacks:r?.getChild(this.omitSequenceTags?void 0:`seq:step:${t+1}`)})),n.signal);if(n.signal?.aborted)throw tu(n.signal);a=await this.last.invoke(i,Ql(n,{callbacks:r?.getChild(this.omitSequenceTags?void 0:`seq:step:${this.steps.length}`)}))}catch(e){throw await r?.handleChainError(e),e}return await r?.handleChainEnd(cx(a,`output`)),a}async batch(e,t,n){let r=this._getOptionsList(t??{},e.length),i=await Promise.all(r.map(Yl)),a=await Promise.all(i.map(async(t,n)=>{let i=await t?.handleChainStart(this.toJSON(),cx(e[n],`input`),r[n].runId,void 0,void 0,void 0,r[n].runName);return delete r[n].runId,i})),o=e;try{for(let e=0;e<this.steps.length;e+=1)o=await eu(this.steps[e].batch(o,a.map((t,n)=>{let i=t?.getChild(this.omitSequenceTags?void 0:`seq:step:${e+1}`);return Ql(r[n],{callbacks:i})}),n),r[0]?.signal)}catch(e){throw await Promise.all(a.map(t=>t?.handleChainError(e))),e}return await Promise.all(a.map(e=>e?.handleChainEnd(cx(o,`output`)))),o}_concatOutputChunks(e,t){return this.last._concatOutputChunks(e,t)}async*_streamIterator(e,t){let n=await Yl(t),{runId:r,...i}=t??{},a=await n?.handleChainStart(this.toJSON(),cx(e,`input`),r,void 0,void 0,void 0,i?.runName),o=[this.first,...this.middle,this.last],s=!0,c;async function*l(){yield e}try{let e=o[0].transform(l(),Ql(i,{callbacks:a?.getChild(this.omitSequenceTags?void 0:`seq:step:1`)}));for(let t=1;t<o.length;t+=1)e=await o[t].transform(e,Ql(i,{callbacks:a?.getChild(this.omitSequenceTags?void 0:`seq:step:${t+1}`)}));for await(let n of e)if(t?.signal?.throwIfAborted(),yield n,s)if(c===void 0)c=n;else try{c=this._concatOutputChunks(c,n)}catch{c=void 0,s=!1}}catch(e){throw await a?.handleChainError(e),e}await a?.handleChainEnd(cx(c,`output`))}getGraph(e){let t=new Zb,n=null;return this.steps.forEach((r,i)=>{let a=r.getGraph(e);i!==0&&a.trimFirstNode(),i!==this.steps.length-1&&a.trimLastNode(),t.extend(a);let o=a.firstNode();if(!o)throw Error(`Runnable ${r} has no first node`);n&&t.addEdge(n,o),n=a.lastNode()}),t}pipe(t){return e.isRunnableSequence(t)?new e({first:this.first,middle:this.middle.concat([this.last,t.first,...t.middle]),last:t.last,name:this.name??t.name}):new e({first:this.first,middle:[...this.middle,this.last],last:bx(t),name:this.name})}static isRunnableSequence(e){return Array.isArray(e.middle)&&lx.isRunnable(e)}static from([t,...n],r){let i={};return typeof r==`string`?i.name=r:r!==void 0&&(i=r),new e({...i,first:bx(t),middle:n.slice(0,-1).map(bx),last:bx(n[n.length-1])})}},mx=class e extends lx{static lc_name(){return`RunnableMap`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;steps;getStepsKeys(){return Object.keys(this.steps)}constructor(e){super(e),this.steps={};for(let[t,n]of Object.entries(e.steps))this.steps[t]=bx(n)}static from(t){return new e({steps:t})}async invoke(e,t){let n=Zl(t),r=await(await Yl(n))?.handleChainStart(this.toJSON(),{input:e},n.runId,void 0,void 0,void 0,n?.runName);delete n.runId;let i={};try{let t=Object.entries(this.steps).map(async([t,a])=>{i[t]=await a.invoke(e,Ql(n,{callbacks:r?.getChild(`map:key:${t}`)}))});await eu(Promise.all(t),n.signal)}catch(e){throw await r?.handleChainError(e),e}return await r?.handleChainEnd(i),i}async*_transform(e,t,n){let r={...this.steps},i=iu(e,Object.keys(r).length),a=new Map(Object.entries(r).map(([e,r],a)=>{let o=r.transform(i[a],Ql(n,{callbacks:t?.getChild(`map:key:${e}`)}));return[e,o.next().then(t=>({key:e,gen:o,result:t}))]}));for(;a.size;){let{key:e,result:t,gen:r}=await eu(Promise.race(a.values()),n?.signal);a.delete(e),t.done||(yield{[e]:t.value},a.set(e,r.next().then(t=>({key:e,gen:r,result:t}))))}}transform(e,t){return this._transformStreamWithConfig(e,this._transform.bind(this),t)}async stream(e,t){async function*n(){yield e}let r=Zl(t),i=new ou({generator:this.transform(n(),r),config:r});return await i.setup,ru.fromAsyncGenerator(i)}},hx=class e extends lx{lc_serializable=!1;lc_namespace=[`langchain_core`,`runnables`];func;constructor(e){if(super(e),!dl(e.func))throw Error(`RunnableTraceable requires a function that is wrapped in traceable higher-order function`);this.func=e.func}async invoke(e,t){let[n]=this._getOptionsList(t??{},1),r=await Yl(n);return eu(this.func(Ql(n,{callbacks:r}),e),n?.signal)}async*_streamIterator(e,t){let[n]=this._getOptionsList(t??{},1),r=await this.invoke(e,t);if(rx(r)){for await(let e of r)n?.signal?.throwIfAborted(),yield e;return}if(nx(r)){for(;;){n?.signal?.throwIfAborted();let e=r.next();if(e.done)break;yield e.value}return}yield r}static from(t){return new e({func:t})}};function gx(e){if(dl(e))throw Error(`RunnableLambda requires a function that is not wrapped in traceable higher-order function. This shouldn't happen.`)}var _x=class e extends lx{static lc_name(){return`RunnableLambda`}lc_namespace=[`langchain_core`,`runnables`];func;constructor(e){if(dl(e.func))return hx.from(e.func);super(e),gx(e.func),this.func=e.func}static from(t){return new e({func:t})}async _invoke(e,t,n){return new Promise((r,i)=>{let a=Ql(t,{callbacks:n?.getChild(),recursionLimit:(t?.recursionLimit??25)-1});Wl.runWithConfig($l(a),async()=>{try{let n=await this.func(e,{...a});if(n&&lx.isRunnable(n)){if(t?.recursionLimit===0)throw Error(`Recursion limit reached.`);n=await n.invoke(e,{...a,recursionLimit:(a.recursionLimit??25)-1})}else if(rx(n)){let e;for await(let r of sx(a,n))if(t?.signal?.throwIfAborted(),e===void 0)e=r;else try{e=this._concatOutputChunks(e,r)}catch{e=r}n=e}else if(tx(n)){let e;for(let r of ox(a,n))if(t?.signal?.throwIfAborted(),e===void 0)e=r;else try{e=this._concatOutputChunks(e,r)}catch{e=r}n=e}r(n)}catch(e){i(e)}})})}async invoke(e,t){return this._callWithConfig(this._invoke.bind(this),e,t)}async*_transform(e,t,n){let r;for await(let t of e)if(r===void 0)r=t;else try{r=this._concatOutputChunks(r,t)}catch{r=t}let i=Ql(n,{callbacks:t?.getChild(),recursionLimit:(n?.recursionLimit??25)-1}),a=await new Promise((e,t)=>{Wl.runWithConfig($l(i),async()=>{try{e(await this.func(r,{...i,config:i}))}catch(e){t(e)}})});if(a&&lx.isRunnable(a)){if(n?.recursionLimit===0)throw Error(`Recursion limit reached.`);let e=await a.stream(r,i);for await(let t of e)yield t}else if(rx(a))for await(let e of sx(i,a))n?.signal?.throwIfAborted(),yield e;else if(tx(a))for(let e of ox(i,a))n?.signal?.throwIfAborted(),yield e;else yield a}transform(e,t){return this._transformStreamWithConfig(e,this._transform.bind(this),t)}async stream(e,t){async function*n(){yield e}let r=Zl(t),i=new ou({generator:this.transform(n(),r),config:r});return await i.setup,ru.fromAsyncGenerator(i)}},vx=class extends mx{},yx=class extends lx{static lc_name(){return`RunnableWithFallbacks`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;runnable;fallbacks;constructor(e){super(e),this.runnable=e.runnable,this.fallbacks=e.fallbacks}*runnables(){yield this.runnable;for(let e of this.fallbacks)yield e}async invoke(e,t){let n=Zl(t),r=await Yl(n),{runId:i,...a}=n,o=await r?.handleChainStart(this.toJSON(),cx(e,`input`),i,void 0,void 0,void 0,a?.runName),s=Ql(a,{callbacks:o?.getChild()});return await Wl.runWithConfig(s,async()=>{let t;for(let r of this.runnables()){n?.signal?.throwIfAborted();try{let t=await r.invoke(e,s);return await o?.handleChainEnd(cx(t,`output`)),t}catch(e){t===void 0&&(t=e)}}throw t===void 0?Error(`No error stored at end of fallback.`):(await o?.handleChainError(t),t)})}async*_streamIterator(e,t){let n=Zl(t),r=await Yl(n),{runId:i,...a}=n,o=await r?.handleChainStart(this.toJSON(),cx(e,`input`),i,void 0,void 0,void 0,a?.runName),s,c;for(let t of this.runnables()){n?.signal?.throwIfAborted();let r=Ql(a,{callbacks:o?.getChild()});try{c=sx(r,await t.stream(e,r));break}catch(e){s===void 0&&(s=e)}}if(c===void 0){let e=s??Error(`No error stored at end of fallback.`);throw await o?.handleChainError(e),e}let l;try{for await(let e of c){yield e;try{l=l===void 0?l:this._concatOutputChunks(l,e)}catch{l=void 0}}}catch(e){throw await o?.handleChainError(e),e}await o?.handleChainEnd(cx(l,`output`))}async batch(e,t,n){if(n?.returnExceptions)throw Error(`Not implemented.`);let r=this._getOptionsList(t??{},e.length),i=await Promise.all(r.map(e=>Yl(e))),a=await Promise.all(i.map(async(t,n)=>{let i=await t?.handleChainStart(this.toJSON(),cx(e[n],`input`),r[n].runId,void 0,void 0,void 0,r[n].runName);return delete r[n].runId,i})),o;for(let t of this.runnables()){r[0].signal?.throwIfAborted();try{let i=await t.batch(e,a.map((e,t)=>Ql(r[t],{callbacks:e?.getChild()})),n);return await Promise.all(a.map((e,t)=>e?.handleChainEnd(cx(i[t],`output`)))),i}catch(e){o===void 0&&(o=e)}}throw o?(await Promise.all(a.map(e=>e?.handleChainError(o))),o):Error(`No error stored at end of fallbacks.`)}};function bx(e){if(typeof e==`function`)return new _x({func:e});if(lx.isRunnable(e))return e;if(!Array.isArray(e)&&typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=bx(r);return new mx({steps:t})}else throw Error(`Expected a Runnable, function or object.
|
|
99
99
|
Instead got an unsupported type.`)}var xx=class extends lx{static lc_name(){return`RunnableAssign`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;mapper;constructor(e){e instanceof mx&&(e={mapper:e}),super(e),this.mapper=e.mapper}async invoke(e,t){let n=await this.mapper.invoke(e,t);return{...e,...n}}async*_transform(e,t,n){let r=this.mapper.getStepsKeys(),[i,a]=iu(e),o=this.mapper.transform(a,Ql(n,{callbacks:t?.getChild()})),s=o.next();for await(let e of i){if(typeof e!=`object`||Array.isArray(e))throw Error(`RunnableAssign can only be used with objects as input, got ${typeof e}`);let t=Object.fromEntries(Object.entries(e).filter(([e])=>!r.includes(e)));Object.keys(t).length>0&&(yield t)}yield(await s).value;for await(let e of o)yield e}transform(e,t){return this._transformStreamWithConfig(e,this._transform.bind(this),t)}async stream(e,t){async function*n(){yield e}let r=Zl(t),i=new ou({generator:this.transform(n(),r),config:r});return await i.setup,ru.fromAsyncGenerator(i)}},Sx=class extends lx{static lc_name(){return`RunnablePick`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;keys;constructor(e){(typeof e==`string`||Array.isArray(e))&&(e={keys:e}),super(e),this.keys=e.keys}async _pick(e){if(typeof this.keys==`string`)return e[this.keys];{let t=this.keys.map(t=>[t,e[t]]).filter(e=>e[1]!==void 0);return t.length===0?void 0:Object.fromEntries(t)}}async invoke(e,t){return this._callWithConfig(this._pick.bind(this),e,t)}async*_transform(e){for await(let t of e){let e=await this._pick(t);e!==void 0&&(yield e)}}transform(e,t){return this._transformStreamWithConfig(e,this._transform.bind(this),t)}async stream(e,t){async function*n(){yield e}let r=Zl(t),i=new ou({generator:this.transform(n(),r),config:r});return await i.setup,ru.fromAsyncGenerator(i)}},Cx=class extends ux{name;description;schema;constructor(e){let t=px.from([_x.from(async e=>{let t;if(g(e))try{t=await qg(this.schema,e.args)}catch{throw new v(`Received tool input did not match expected schema`,JSON.stringify(e.args))}else t=e;return t}).withConfig({runName:`${e.name}:parse_input`}),e.bound]).withConfig({runName:e.name});super({bound:t,config:e.config??{}}),this.name=e.name,this.description=e.description,this.schema=e.schema}static lc_name(){return`RunnableToolLike`}};function wx(e,t){let n=t.name??e.getName(),r=t.description??Xg(t.schema);return Qg(t.schema)?new Cx({name:n,description:r,schema:sy({input:ay()}).transform(e=>e.input),bound:e}):new Cx({name:n,description:r,schema:t.schema,bound:e})}var Tx=class extends lx{static lc_name(){return`RunnablePassthrough`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;func;constructor(e){super(e),e&&(this.func=e.func)}async invoke(e,t){let n=Zl(t);return this.func&&await this.func(e,n),this._callWithConfig(e=>Promise.resolve(e),e,n)}async*transform(e,t){let n=Zl(t),r,i=!0;for await(let t of this._transformStreamWithConfig(e,e=>e,n))if(yield t,i)if(r===void 0)r=t;else try{r=au(r,t)}catch{r=void 0,i=!1}this.func&&r!==void 0&&await this.func(r,n)}static assign(e){return new xx(new mx({steps:e}))}},Ex=class extends lx{static lc_name(){return`RouterRunnable`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;runnables;constructor(e){super(e),this.runnables=e.runnables}async invoke(e,t){let{key:n,input:r}=e,i=this.runnables[n];if(i===void 0)throw Error(`No runnable associated with key "${n}".`);return i.invoke(r,Zl(t))}async batch(e,t,n){let r=e.map(e=>e.key),i=e.map(e=>e.input);if(r.find(e=>this.runnables[e]===void 0)!==void 0)throw Error(`One or more keys do not have a corresponding runnable.`);let a=r.map(e=>this.runnables[e]),o=this._getOptionsList(t??{},e.length),s=o[0]?.maxConcurrency??n?.maxConcurrency,c=s&&s>0?s:e.length,l=[];for(let e=0;e<i.length;e+=c){let t=i.slice(e,e+c).map((e,t)=>a[t].invoke(e,o[t])),n=await Promise.all(t);l.push(n)}return l.flat()}async stream(e,t){let{key:n,input:r}=e,i=this.runnables[n];if(i===void 0)throw Error(`No runnable associated with key "${n}".`);return i.stream(r,t)}},Dx=class extends lx{static lc_name(){return`RunnableBranch`}lc_namespace=[`langchain_core`,`runnables`];lc_serializable=!0;default;branches;constructor(e){super(e),this.branches=e.branches,this.default=e.default}static from(e){if(e.length<1)throw Error(`RunnableBranch requires at least one branch`);let t=e.slice(0,-1).map(([e,t])=>[bx(e),bx(t)]),n=bx(e[e.length-1]);return new this({branches:t,default:n})}async _invoke(e,t,n){let r;for(let i=0;i<this.branches.length;i+=1){let[a,o]=this.branches[i];if(await a.invoke(e,Ql(t,{callbacks:n?.getChild(`condition:${i+1}`)}))){r=await o.invoke(e,Ql(t,{callbacks:n?.getChild(`branch:${i+1}`)}));break}}return r||=await this.default.invoke(e,Ql(t,{callbacks:n?.getChild(`branch:default`)})),r}async invoke(e,t={}){return this._callWithConfig(this._invoke,e,t)}async*_streamIterator(e,t){let n=await(await Yl(t))?.handleChainStart(this.toJSON(),cx(e,`input`),t?.runId,void 0,void 0,void 0,t?.runName),r,i=!0,a;try{for(let o=0;o<this.branches.length;o+=1){let[s,c]=this.branches[o];if(await s.invoke(e,Ql(t,{callbacks:n?.getChild(`condition:${o+1}`)}))){a=await c.stream(e,Ql(t,{callbacks:n?.getChild(`branch:${o+1}`)}));for await(let e of a)if(yield e,i)if(r===void 0)r=e;else try{r=au(r,e)}catch{r=void 0,i=!1}break}}if(a===void 0){a=await this.default.stream(e,Ql(t,{callbacks:n?.getChild(`branch:default`)}));for await(let e of a)if(yield e,i)if(r===void 0)r=e;else try{r=au(r,e)}catch{r=void 0,i=!1}}}catch(e){throw await n?.handleChainError(e),e}await n?.handleChainEnd(r??{})}},Ox=(e,t)=>{let n=[...new Set(t?.map(e=>{if(typeof e==`string`)return e;let t=new e({});if(!(`getType`in t)||typeof t.getType!=`function`)throw Error(`Invalid type provided.`);return t.getType()}))],r=e.getType();return n.some(e=>e===r)};function kx(e,t){return Array.isArray(e)?Ax(e,t):_x.from(t=>Ax(t,e))}function Ax(e,t={}){let{includeNames:n,excludeNames:r,includeTypes:i,excludeTypes:a,includeIds:o,excludeIds:s}=t,c=[];for(let t of e)r&&t.name&&r.includes(t.name)||a&&Ox(t,a)||s&&t.id&&s.includes(t.id)||(i||o||n?(n&&t.name&&n.some(e=>e===t.name)||i&&Ox(t,i)||o&&t.id&&o.some(e=>e===t.id))&&c.push(t):c.push(t));return c}function jx(e){return Array.isArray(e)?Mx(e):_x.from(Mx)}function Mx(e){if(!e.length)return[];let t=[];for(let n of e){let e=n,r=t.pop();if(!r)t.push(e);else if(e.getType()===`tool`||e.getType()!==r.getType())t.push(r,e);else{let n=Nn(r),i=Nn(e),a=n.concat(i);typeof n.content==`string`&&typeof i.content==`string`&&(a.content=`${n.content}\n${i.content}`),t.push(zx(a))}}return t}function Nx(e,t){if(Array.isArray(e)){let n=e;if(!t)throw Error(`Options parameter is required when providing messages.`);return Px(n,t)}else{let t=e;return _x.from(e=>Px(e,t)).withConfig({runName:`trim_messages`})}}async function Px(e,t){let{maxTokens:n,tokenCounter:r,strategy:i=`last`,allowPartial:a=!1,endOn:o,startOn:s,includeSystem:c=!1,textSplitter:l}=t;if(s&&i===`first`)throw Error("`startOn` should only be specified if `strategy` is 'last'.");if(c&&i===`first`)throw Error("`includeSystem` should only be specified if `strategy` is 'last'.");let u;u=`getNumTokens`in r?async e=>(await Promise.all(e.map(e=>r.getNumTokens(e.content)))).reduce((e,t)=>e+t,0):async e=>r(e);let d=Bx;if(l&&(d=`splitText`in l?l.splitText:async e=>l(e)),i===`first`)return Fx(e,{maxTokens:n,tokenCounter:u,textSplitter:d,partialStrategy:a?`first`:void 0,endOn:o});if(i===`last`)return Ix(e,{maxTokens:n,tokenCounter:u,textSplitter:d,allowPartial:a,includeSystem:c,startOn:s,endOn:o});throw Error(`Unrecognized strategy: '${i}'. Must be one of 'first' or 'last'.`)}async function Fx(e,t){let{maxTokens:n,tokenCounter:r,textSplitter:i,partialStrategy:a,endOn:o}=t,s=[...e],c=0;for(let e=0;e<s.length;e+=1)if(await r(e>0?s.slice(0,-e):s)<=n){c=s.length-e;break}if(c<s.length&&a){let e=!1;if(Array.isArray(s[c].content)){let t=s[c];if(typeof t.content==`string`)throw Error(`Expected content to be an array.`);let i=t.content.length,o=a===`last`?[...t.content].reverse():t.content;for(let l=1;l<=i;l+=1){let i=a===`first`?o.slice(0,l):o.slice(-l),u=Object.fromEntries(Object.entries(t).filter(([e])=>e!==`type`&&!e.startsWith(`lc_`))),d=Rx(t.getType(),{...u,content:i}),f=[...s.slice(0,c),d];if(await r(f)<=n)s=f,c+=1,e=!0;else break}e&&a===`last`&&(t.content=[...o].reverse())}if(!e){let e=s[c],t;if(Array.isArray(e.content)&&e.content.some(e=>typeof e==`string`||e.type===`text`)?t=e.content.find(e=>e.type===`text`&&e.text)?.text:typeof e.content==`string`&&(t=e.content),t){let o=await i(t),l=o.length;a===`last`&&o.reverse();for(let t=0;t<l-1;t+=1)if(o.pop(),e.content=o.join(``),await r([...s.slice(0,c),e])<=n){a===`last`&&(e.content=[...o].reverse().join(``)),s=[...s.slice(0,c),e],c+=1;break}}}}if(o){let e=Array.isArray(o)?o:[o];for(;c>0&&!Ox(s[c-1],e);)--c}return s.slice(0,c)}async function Ix(e,t){let{allowPartial:n=!1,includeSystem:r=!1,endOn:i,startOn:a,...o}=t,s=e.map(e=>{let t=Object.fromEntries(Object.entries(e).filter(([e])=>e!==`type`&&!e.startsWith(`lc_`)));return Rx(e.getType(),t,vt(e))});if(i){let e=Array.isArray(i)?i:[i];for(;s.length>0&&!Ox(s[s.length-1],e);)s=s.slice(0,-1)}let c=r&&s[0]?.getType()===`system`,l=c?s.slice(0,1).concat(s.slice(1).reverse()):s.reverse();return l=await Fx(l,{...o,partialStrategy:n?`last`:void 0,endOn:a}),c?[l[0],...l.slice(1).reverse()]:l.reverse()}var Lx={human:{message:fn,messageChunk:pn},ai:{message:$t,messageChunk:nn},system:{message:_n,messageChunk:vn},developer:{message:_n,messageChunk:vn},tool:{message:xt,messageChunk:St},function:{message:cn,messageChunk:ln},generic:{message:rn,messageChunk:an},remove:{message:gn,messageChunk:gn}};function Rx(e,t,n){let r,i;switch(e){case`human`:n?r=new pn(t):i=new fn(t);break;case`ai`:if(n){let e={...t};`tool_calls`in e&&(e={...e,tool_call_chunks:e.tool_calls?.map(e=>({...e,type:`tool_call_chunk`,index:void 0,args:JSON.stringify(e.args)}))}),r=new nn(e)}else i=new $t(t);break;case`system`:n?r=new vn(t):i=new _n(t);break;case`developer`:n?r=new vn({...t,additional_kwargs:{...t.additional_kwargs,__openai_role__:`developer`}}):i=new _n({...t,additional_kwargs:{...t.additional_kwargs,__openai_role__:`developer`}});break;case`tool`:if(`tool_call_id`in t)n?r=new St(t):i=new xt(t);else throw Error(`Can not convert ToolMessage to ToolMessageChunk if 'tool_call_id' field is not defined.`);break;case`function`:if(n)r=new ln(t);else{if(!t.name)throw Error(`FunctionMessage must have a 'name' field`);i=new cn(t)}break;case`generic`:if(`role`in t)n?r=new an(t):i=new rn(t);else throw Error(`Can not convert ChatMessage to ChatMessageChunk if 'role' field is not defined.`);break;default:throw Error(`Unrecognized message type ${e}`)}if(n&&r)return r;if(i)return i;throw Error(`Unrecognized message type ${e}`)}function zx(e){let t=e.getType(),n,r=Object.fromEntries(Object.entries(e).filter(([e])=>![`type`,`tool_call_chunks`].includes(e)&&!e.startsWith(`lc_`)));if(t in Lx&&(n=Rx(t,r)),!n)throw Error(`Unrecognized message chunk class ${t}. Supported classes are ${Object.keys(Lx)}`);return n}function Bx(e){let t=e.split(`
|
|
100
100
|
`);return Promise.resolve([...t.slice(0,-1).map(e=>`${e}\n`),t[t.length-1]])}var Vx=[`tool_call`,`tool_call_chunk`,`invalid_tool_call`,`server_tool_call`,`server_tool_call_chunk`,`server_tool_call_result`],Hx=[`image`,`video`,`audio`,`text-plain`,`file`],Ux=[`text`,`reasoning`,...Vx,...Hx],Wx=s({AIMessage:()=>$t,AIMessageChunk:()=>nn,BaseMessage:()=>rt,BaseMessageChunk:()=>ht,ChatMessage:()=>rn,ChatMessageChunk:()=>an,DEFAULT_MERGE_IGNORE_KEYS:()=>at,FunctionMessage:()=>cn,FunctionMessageChunk:()=>ln,HumanMessage:()=>fn,HumanMessageChunk:()=>pn,KNOWN_BLOCK_TYPES:()=>Ux,RemoveMessage:()=>gn,SystemMessage:()=>_n,SystemMessageChunk:()=>vn,ToolMessage:()=>xt,ToolMessageChunk:()=>St,_isMessageFieldWithRole:()=>gt,_mergeDicts:()=>ot,_mergeLists:()=>pt,_mergeObj:()=>mt,_mergeStatus:()=>tt,coerceMessageLikeToMessage:()=>En,collapseToolCallChunks:()=>Pn,convertToChunk:()=>Nn,convertToOpenAIImageBlock:()=>we,convertToProviderContentBlock:()=>De,defaultTextSplitter:()=>Bx,defaultToolCallParser:()=>Ct,filterMessages:()=>kx,getBufferString:()=>On,iife:()=>Sn,isAIMessage:()=>en,isAIMessageChunk:()=>tn,isBase64ContentBlock:()=>xe,isBaseMessage:()=>_t,isBaseMessageChunk:()=>vt,isChatMessage:()=>on,isChatMessageChunk:()=>sn,isDataContentBlock:()=>ye,isDirectToolOutput:()=>bt,isFunctionMessage:()=>un,isFunctionMessageChunk:()=>dn,isHumanMessage:()=>mn,isHumanMessageChunk:()=>hn,isIDContentBlock:()=>Ce,isMessage:()=>Ye,isOpenAIToolCallArray:()=>it,isPlainTextContentBlock:()=>Se,isSystemMessage:()=>yn,isSystemMessageChunk:()=>bn,isToolMessage:()=>wt,isToolMessageChunk:()=>Tt,isURLContentBlock:()=>be,mapChatMessagesToStoredMessages:()=>Mn,mapStoredMessageToChatMessage:()=>An,mapStoredMessagesToChatMessages:()=>jn,mergeContent:()=>et,mergeMessageRuns:()=>jx,mergeResponseMetadata:()=>Jt,mergeUsageMetadata:()=>Qt,parseBase64DataUrl:()=>Ee,parseMimeType:()=>Te,trimMessages:()=>Nx}),Gx=class extends ux{runnable;inputMessagesKey;outputMessagesKey;historyMessagesKey;getMessageHistory;constructor(e){let t=_x.from((e,t)=>this._enterHistory(e,t??{})).withConfig({runName:`loadHistory`}),n=e.historyMessagesKey??e.inputMessagesKey;n&&(t=Tx.assign({[n]:t}).withConfig({runName:`insertHistory`}));let r=t.pipe(e.runnable.withListeners({onEnd:(e,t)=>this._exitHistory(e,t??{})})).withConfig({runName:`RunnableWithMessageHistory`}),i=e.config??{};super({...e,config:i,bound:r}),this.runnable=e.runnable,this.getMessageHistory=e.getMessageHistory,this.inputMessagesKey=e.inputMessagesKey,this.outputMessagesKey=e.outputMessagesKey,this.historyMessagesKey=e.historyMessagesKey}_getInputMessages(e){let t;if(typeof e==`object`&&!Array.isArray(e)&&!_t(e)){let n;n=this.inputMessagesKey?this.inputMessagesKey:Object.keys(e).length===1?Object.keys(e)[0]:`input`,t=Array.isArray(e[n])&&Array.isArray(e[n][0])?e[n][0]:e[n]}else t=e;if(typeof t==`string`)return[new fn(t)];if(Array.isArray(t))return t;if(_t(t))return[t];throw Error(`Expected a string, BaseMessage, or array of BaseMessages.\nGot ${JSON.stringify(t,null,2)}`)}_getOutputMessages(e){let t;if(!Array.isArray(e)&&!_t(e)&&typeof e!=`string`){let n;n=this.outputMessagesKey===void 0?Object.keys(e).length===1?Object.keys(e)[0]:`output`:this.outputMessagesKey,t=e.generations===void 0?e[n]:e.generations[0][0].message}else t=e;if(typeof t==`string`)return[new $t(t)];if(Array.isArray(t))return t;if(_t(t))return[t];throw Error(`Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(t,null,2)}`)}async _enterHistory(e,t){let n=await(t?.configurable?.messageHistory).getMessages();return this.historyMessagesKey===void 0?n.concat(this._getInputMessages(e)):n}async _exitHistory(e,t){let n=t.configurable?.messageHistory,r;r=Array.isArray(e.inputs)&&Array.isArray(e.inputs[0])?e.inputs[0]:e.inputs;let i=this._getInputMessages(r);if(this.historyMessagesKey===void 0){let e=await n.getMessages();i=i.slice(e.length)}let a=e.outputs;if(!a)throw Error(`Output values from 'Run' undefined. Run: ${JSON.stringify(e,null,2)}`);let o=this._getOutputMessages(a);await n.addMessages([...i,...o])}async _mergeConfig(...e){let t=await super._mergeConfig(...e);if(!t.configurable||!t.configurable.sessionId){let e={[this.inputMessagesKey??`input`]:`foo`};throw Error(`sessionId is required. Pass it in as part of the config argument to .invoke() or .stream()\neg. chain.invoke(${JSON.stringify(e)}, ${JSON.stringify({configurable:{sessionId:`123`}})})`)}let{sessionId:n}=t.configurable;return t.configurable.messageHistory=await this.getMessageHistory(n),t}},Kx=s({RouterRunnable:()=>Ex,Runnable:()=>lx,RunnableAssign:()=>xx,RunnableBinding:()=>ux,RunnableBranch:()=>Dx,RunnableEach:()=>dx,RunnableLambda:()=>_x,RunnableMap:()=>mx,RunnableParallel:()=>vx,RunnablePassthrough:()=>Tx,RunnablePick:()=>Sx,RunnableRetry:()=>fx,RunnableSequence:()=>px,RunnableToolLike:()=>Cx,RunnableWithFallbacks:()=>yx,RunnableWithMessageHistory:()=>Gx,_coerceToRunnable:()=>bx,ensureConfig:()=>Zl,getCallbackManagerForConfig:()=>Yl,mergeConfigs:()=>Xl,patchConfig:()=>Ql,pickRunnableConfigKeys:()=>$l,raceWithSignal:()=>eu});function qx(e,t){if(e!=null){if(typeof e!=`number`||Number.isNaN(e)||e<=0)throw Error(`${t} must be greater than 0`);return e}}function Jx(e){if(e==null)return;let t=typeof e==`number`?{runTimeout:e}:e,n=t.refreshOn??`auto`;if(n!==`auto`&&n!==`heartbeat`)throw Error(`refreshOn must be "auto" or "heartbeat"`);let r=qx(t.runTimeout,`runTimeout`),i=qx(t.idleTimeout,`idleTimeout`);if(!(r===void 0&&i===void 0))return{runTimeout:r,idleTimeout:i,refreshOn:n}}var Yx=`__start__`,Xx=`__end__`,Zx=`__input__`,Qx=`__error__`,$x=`__error_source_node__`,eS=`__pregel_ns_writes`;function tS(){let e=typeof process<`u`?{}.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT:void 0;if(e!==void 0&&e!==``){let t=Number.parseInt(e,10);if(Number.isFinite(t)&&t>0)return t}return 5e3}var nS=`__pregel_send`,rS=`__pregel_call`,iS=`__pregel_read`,aS=`__pregel_checkpointer`,oS=`__pregel_resuming`,sS=`__pregel_task_id`,cS=`__pregel_stream`,lS=`__pregel_resume_value`,uS=`__pregel_resume_map`,dS=`__pregel_scratchpad`,fS=`__pregel_previous`,pS=`__pregel_durability`,mS=`checkpoint_id`,hS=`checkpoint_ns`,gS=`__pregel_node_finished`,_S=`__pregel_node_error`,vS=`checkpoint_map`,yS=`__pregel_replay_state`,bS=`__pregel_abort_signals`,xS=`__interrupt__`,SS=`__resume__`,CS=`__no_writes__`,wS=`__return__`,TS=`__previous__`,ES=`langsmith:hidden`,DS=`__self__`,OS=`__pregel_tasks`,kS=`__pregel_push`,AS=`__pregel_pull`,jS=`00000000-0000-0000-0000-000000000000`,MS=[ES,Zx,xS,SS,Qx,$x,CS,nS,iS,aS,pS,cS,oS,sS,rS,lS,dS,fS,vS,hS,mS,yS],NS=Symbol.for(`langgraph.command`),PS=class{[NS];constructor(e){this[NS]=e}};function FS(e){let t=e;return t!=null&&typeof t.node==`string`&&t.args!==void 0}var IS=class{lg_name=`Send`;node;args;timeout;constructor(e,t,n){this.node=e,this.args=GS(t),this.timeout=Jx(n?.timeout)}toJSON(){return{lg_name:this.lg_name,node:this.node,args:this.args,timeout:this.timeout}}};function LS(e){return e instanceof IS}var RS=`__overwrite__`;function zS(e){return typeof e==`object`&&e&&`__overwrite__`in e?[!0,e[RS]]:[!1,void 0]}function BS(e){return zS(e)[0]}function VS(e){return!e||typeof e!=`object`||!(`__interrupt__`in e)?!1:Array.isArray(e[xS])}var HS=class extends PS{lg_name=`Command`;lc_direct_tool_output=!0;graph;update;resume;goto=[];static PARENT=`__parent__`;constructor(e){super(e),this.resume=e.resume,this.graph=e.graph,this.update=e.update,e.goto&&(this.goto=Array.isArray(e.goto)?GS(e.goto):[GS(e.goto)])}_updateAsTuples(){return this.update&&typeof this.update==`object`&&!Array.isArray(this.update)?Object.entries(this.update):Array.isArray(this.update)&&this.update.every(e=>Array.isArray(e)&&e.length===2&&typeof e[0]==`string`)?this.update:[[`__root__`,this.update]]}toJSON(){let e;return e=typeof this.goto==`string`?this.goto:LS(this.goto)?this.goto.toJSON():this.goto?.map(e=>typeof e==`string`?e:e.toJSON()),{lg_name:this.lg_name,update:this.update,resume:this.resume,goto:e}}};function US(e){return typeof e!=`object`||!e?!1:`lg_name`in e&&e.lg_name===`Command`}function WS(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function GS(e,t=new Map){if(typeof e==`object`&&e){if(t.has(e))return t.get(e);let n;if(Array.isArray(e))n=[],t.set(e,n),e.forEach((e,r)=>{n[r]=GS(e,t)});else if(e instanceof HS||e instanceof IS||!WS(e))n=e,t.set(e,n);else if(US(e))n=new HS(e),t.set(e,n);else if(FS(e))n=new IS(e.node,e.args,e.timeout===void 0?void 0:{timeout:e.timeout}),t.set(e,n);else if(`lc_serializable`in e&&e.lc_serializable)n=e,t.set(e,n);else{n={},t.set(e,n);for(let[r,i]of Object.entries(e))n[r]=GS(i,t)}return n}return e}var KS=class extends Error{lc_error_code;constructor(e,t){let n=e??``;t?.lc_error_code&&(n=`${n}\n\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${t.lc_error_code}/\n`),super(n),this.lc_error_code=t?.lc_error_code}},qS=class extends KS{get is_bubble_up(){return!0}},JS=class extends KS{constructor(e,t){super(e,t),this.name=`GraphRecursionError`}static get unminifiable_name(){return`GraphRecursionError`}},YS=class extends KS{constructor(e,t){super(e,t),this.name=`GraphValueError`}static get unminifiable_name(){return`GraphValueError`}},XS=class extends qS{reason;constructor(e=`shutdown`,t){super(`Graph drained: ${e}`,t),this.name=`GraphDrained`,this.reason=e}static get unminifiable_name(){return`GraphDrained`}};function ZS(e){return e!==void 0&&e.name===XS.unminifiable_name}var QS=class extends qS{interrupts;constructor(e,t){super(JSON.stringify(e,null,2),t),this.name=`GraphInterrupt`,this.interrupts=e??[]}static get unminifiable_name(){return`GraphInterrupt`}},$S=class extends QS{constructor(e,t){super([{value:e}],t),this.name=`NodeInterrupt`}static get unminifiable_name(){return`NodeInterrupt`}},eC=class{node;error;constructor(e,t){this.node=e,this.error=t}static get unminifiable_name(){return`NodeError`}},tC=class extends qS{command;constructor(e){super(),this.name=`ParentCommand`,this.command=e}static get unminifiable_name(){return`ParentCommand`}};function nC(e){return e!==void 0&&e.name===tC.unminifiable_name}function rC(e){return e!==void 0&&e.is_bubble_up===!0}function iC(e){return e!==void 0&&[QS.unminifiable_name,$S.unminifiable_name].includes(e.name)}var aC=class extends KS{node;kind;timeout;elapsed;runTimeout;idleTimeout;constructor(e,t){let{node:n,elapsed:r,kind:i,runTimeout:a,idleTimeout:o}=e,s,c;if(i===`idle`){if(o===void 0)throw Error(`idleTimeout is required when kind='idle'`);c=o,s=`Node "${n}" exceeded its idle timeout of ${o}ms without making progress (elapsed: ${r}ms).`}else{if(a===void 0)throw Error(`runTimeout is required when kind='run'`);c=a,s=`Node "${n}" exceeded its run timeout of ${a}ms (elapsed: ${r}ms).`}super(s,t),this.name=`NodeTimeoutError`,this.node=n,this.kind=i,this.timeout=c,this.elapsed=r,this.runTimeout=a,this.idleTimeout=o}static get unminifiable_name(){return`NodeTimeoutError`}},oC=class extends KS{constructor(e,t){super(e,t),this.name=`EmptyInputError`}static get unminifiable_name(){return`EmptyInputError`}},sC=class extends KS{constructor(e,t){let n=Error.stackTraceLimit;Error.stackTraceLimit=0,super(e,t),Error.stackTraceLimit=n,this.name=`EmptyChannelError`}static get unminifiable_name(){return`EmptyChannelError`}},cC=class extends KS{constructor(e,t){super(e,t),this.name=`InvalidUpdateError`}static get unminifiable_name(){return`InvalidUpdateError`}},lC=class extends KS{constructor(e,t){super(e,t),this.name=`UnreachableNodeError`}static get unminifiable_name(){return`UnreachableNodeError`}},uC=class extends KS{constructor(e,t){super(e,t),this.name=`StateGraphInputError`,this.message=`Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema.`}static get unminifiable_name(){return`StateGraphInputError`}},dC=0,fC=0;function pC(e){let t=Date.now();return t<=dC?(fC+=1,fC>=1e4&&(fC=0,t=dC+1)):fC=0,dC=t,xr({clockseq:e,msecs:t,nsecs:fC})}function mC(e,t){let n=t.replace(/-/g,``).match(/.{2}/g).map(e=>parseInt(e,16));return br(e,new Uint8Array(n))}var hC=`__error__`,gC=`__scheduled__`,_C=`__interrupt__`,vC=`__resume__`,yC=class{lg_name=`DeltaSnapshot`;value;constructor(e){this.value=e}},bC=`[...]`,xC=`[Circular]`,SC=[],CC=[];function wC(){return{depthLimit:2**53-1,edgesLimit:2**53-1}}function TC(e,t,n,r){r===void 0&&(r=wC()),DC(e,``,0,[],void 0,0,r);var i;try{i=CC.length===0?JSON.stringify(e,t,n):JSON.stringify(e,OC(t),n)}catch{return JSON.stringify(`[unable to serialize, circular reference is too complex to analyze]`)}finally{for(;SC.length!==0;){var a=SC.pop();a.length===4?Object.defineProperty(a[0],a[1],a[3]):a[0][a[1]]=a[2]}}return i}function EC(e,t,n,r){var i=Object.getOwnPropertyDescriptor(r,n);i.get===void 0?(r[n]=e,SC.push([r,n,t])):i.configurable?(Object.defineProperty(r,n,{value:e}),SC.push([r,n,t,i])):CC.push([t,n,e])}function DC(e,t,n,r,i,a,o){a+=1;var s;if(typeof e==`object`&&e){for(s=0;s<r.length;s++)if(r[s]===e){EC(xC,e,t,i);return}if(o.depthLimit!==void 0&&a>o.depthLimit){EC(bC,e,t,i);return}if(o.edgesLimit!==void 0&&n+1>o.edgesLimit){EC(bC,e,t,i);return}if(r.push(e),Array.isArray(e))for(s=0;s<e.length;s++)DC(e[s],s,s,r,e,a,o);else{var c=Object.keys(e);for(s=0;s<c.length;s++){var l=c[s];DC(e[l],l,s,r,e,a,o)}}r.pop()}}function OC(e){return e=e===void 0?function(e,t){return t}:e,function(t,n){if(CC.length>0)for(var r=0;r<CC.length;r++){var i=CC[r];if(i[1]===t&&i[0]===n){n=i[2],CC.splice(r,1);break}}return e.call(this,t,n)}}var kC=[],AC=s({}),jC=s({}),z=`0123456789abcdef`.split(``),MC=[-2147483648,8388608,32768,128],NC=[24,16,8,0],PC=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],FC=[];function IC(e,t){t?(FC[0]=FC[16]=FC[1]=FC[2]=FC[3]=FC[4]=FC[5]=FC[6]=FC[7]=FC[8]=FC[9]=FC[10]=FC[11]=FC[12]=FC[13]=FC[14]=FC[15]=0,this.blocks=FC):this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e?(this.h0=3238371032,this.h1=914150663,this.h2=812702999,this.h3=4144912697,this.h4=4290775857,this.h5=1750603025,this.h6=1694076839,this.h7=3204075428):(this.h0=1779033703,this.h1=3144134277,this.h2=1013904242,this.h3=2773480762,this.h4=1359893119,this.h5=2600822924,this.h6=528734635,this.h7=1541459225),this.block=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0,this.is224=e}IC.prototype.update=function(e){if(!this.finalized){var t,n=typeof e;if(n!==`string`){if(n===`object`){if(e===null)throw Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw Error(ERROR)}else throw Error(ERROR);t=!0}for(var r,i=0,a,o=e.length,s=this.blocks;i<o;){if(this.hashed&&(this.hashed=!1,s[0]=this.block,this.block=s[16]=s[1]=s[2]=s[3]=s[4]=s[5]=s[6]=s[7]=s[8]=s[9]=s[10]=s[11]=s[12]=s[13]=s[14]=s[15]=0),t)for(a=this.start;i<o&&a<64;++i)s[a>>>2]|=e[i]<<NC[a++&3];else for(a=this.start;i<o&&a<64;++i)r=e.charCodeAt(i),r<128?s[a>>>2]|=r<<NC[a++&3]:r<2048?(s[a>>>2]|=(192|r>>>6)<<NC[a++&3],s[a>>>2]|=(128|r&63)<<NC[a++&3]):r<55296||r>=57344?(s[a>>>2]|=(224|r>>>12)<<NC[a++&3],s[a>>>2]|=(128|r>>>6&63)<<NC[a++&3],s[a>>>2]|=(128|r&63)<<NC[a++&3]):(r=65536+((r&1023)<<10|e.charCodeAt(++i)&1023),s[a>>>2]|=(240|r>>>18)<<NC[a++&3],s[a>>>2]|=(128|r>>>12&63)<<NC[a++&3],s[a>>>2]|=(128|r>>>6&63)<<NC[a++&3],s[a>>>2]|=(128|r&63)<<NC[a++&3]);this.lastByteIndex=a,this.bytes+=a-this.start,a>=64?(this.block=s[16],this.start=a-64,this.hash(),this.hashed=!0):this.start=a}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes%=4294967296),this}},IC.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>>2]|=MC[t&3],this.block=e[16],t>=56&&(this.hashed||this.hash(),e[0]=this.block,e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=this.hBytes<<3|this.bytes>>>29,e[15]=this.bytes<<3,this.hash()}},IC.prototype.hash=function(){var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,a=this.h5,o=this.h6,s=this.h7,c=this.blocks,l,u,d,f,p,m,h,g,_,v,y;for(l=16;l<64;++l)p=c[l-15],u=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,p=c[l-2],d=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,c[l]=c[l-16]+u+c[l-7]+d<<0;for(y=t&n,l=0;l<64;l+=4)this.first?(this.is224?(g=300032,p=c[0]-1413257819,s=p-150054599<<0,r=p+24177077<<0):(g=704751109,p=c[0]-210244248,s=p-1521486534<<0,r=p+143694565<<0),this.first=!1):(u=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),d=(i>>>6|i<<26)^(i>>>11|i<<21)^(i>>>25|i<<7),g=e&t,f=g^e&n^y,h=i&a^~i&o,p=s+d+h+PC[l]+c[l],m=u+f,s=r+p<<0,r=p+m<<0),u=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),d=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7),_=r&e,f=_^r&t^g,h=o&s^~o&i,p=a+d+h+PC[l+1]+c[l+1],m=u+f,o=n+p<<0,n=p+m<<0,u=(n>>>2|n<<30)^(n>>>13|n<<19)^(n>>>22|n<<10),d=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),v=n&r,f=v^n&e^_,h=a&o^~a&s,p=i+d+h+PC[l+2]+c[l+2],m=u+f,a=t+p<<0,t=p+m<<0,u=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),d=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),y=t&n,f=y^t&r^v,h=a&o^~a&s,p=i+d+h+PC[l+3]+c[l+3],m=u+f,i=e+p<<0,e=p+m<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+e<<0,this.h1=this.h1+t<<0,this.h2=this.h2+n<<0,this.h3=this.h3+r<<0,this.h4=this.h4+i<<0,this.h5=this.h5+a<<0,this.h6=this.h6+o<<0,this.h7=this.h7+s<<0},IC.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,a=this.h5,o=this.h6,s=this.h7,c=z[e>>>28&15]+z[e>>>24&15]+z[e>>>20&15]+z[e>>>16&15]+z[e>>>12&15]+z[e>>>8&15]+z[e>>>4&15]+z[e&15]+z[t>>>28&15]+z[t>>>24&15]+z[t>>>20&15]+z[t>>>16&15]+z[t>>>12&15]+z[t>>>8&15]+z[t>>>4&15]+z[t&15]+z[n>>>28&15]+z[n>>>24&15]+z[n>>>20&15]+z[n>>>16&15]+z[n>>>12&15]+z[n>>>8&15]+z[n>>>4&15]+z[n&15]+z[r>>>28&15]+z[r>>>24&15]+z[r>>>20&15]+z[r>>>16&15]+z[r>>>12&15]+z[r>>>8&15]+z[r>>>4&15]+z[r&15]+z[i>>>28&15]+z[i>>>24&15]+z[i>>>20&15]+z[i>>>16&15]+z[i>>>12&15]+z[i>>>8&15]+z[i>>>4&15]+z[i&15]+z[a>>>28&15]+z[a>>>24&15]+z[a>>>20&15]+z[a>>>16&15]+z[a>>>12&15]+z[a>>>8&15]+z[a>>>4&15]+z[a&15]+z[o>>>28&15]+z[o>>>24&15]+z[o>>>20&15]+z[o>>>16&15]+z[o>>>12&15]+z[o>>>8&15]+z[o>>>4&15]+z[o&15];return this.is224||(c+=z[s>>>28&15]+z[s>>>24&15]+z[s>>>20&15]+z[s>>>16&15]+z[s>>>12&15]+z[s>>>8&15]+z[s>>>4&15]+z[s&15]),c},IC.prototype.toString=IC.prototype.hex,IC.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,n=this.h2,r=this.h3,i=this.h4,a=this.h5,o=this.h6,s=this.h7,c=[e>>>24&255,e>>>16&255,e>>>8&255,e&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255,n>>>24&255,n>>>16&255,n>>>8&255,n&255,r>>>24&255,r>>>16&255,r>>>8&255,r&255,i>>>24&255,i>>>16&255,i>>>8&255,i&255,a>>>24&255,a>>>16&255,a>>>8&255,a&255,o>>>24&255,o>>>16&255,o>>>8&255,o&255];return this.is224||c.push(s>>>24&255,s>>>16&255,s>>>8&255,s&255),c},IC.prototype.array=IC.prototype.digest,IC.prototype.arrayBuffer=function(){this.finalize();var e=new ArrayBuffer(this.is224?28:32),t=new DataView(e);return t.setUint32(0,this.h0),t.setUint32(4,this.h1),t.setUint32(8,this.h2),t.setUint32(12,this.h3),t.setUint32(16,this.h4),t.setUint32(20,this.h5),t.setUint32(24,this.h6),this.is224||t.setUint32(28,this.h7),e};var LC=(...e)=>new IC(!1,!0).update(e.join(``)).hex(),RC=s({sha256:()=>LC}),zC=s({BaseCache:()=>UC,InMemoryCache:()=>GC,defaultHashKeyEncoder:()=>BC,deserializeStoredGeneration:()=>VC,serializeGeneration:()=>HC}),BC=(...e)=>LC(e.join(`_`));function VC(e){return e.message===void 0?{text:e.text}:{text:e.text,message:An(e.message)}}function HC(e){let t={text:e.text};return e.message!==void 0&&(t.message=e.message.toDict()),t}var UC=class{keyEncoder=BC;makeDefaultKeyEncoder(e){this.keyEncoder=e}},WC=new Map,GC=class e extends UC{cache;constructor(e){super(),this.cache=e??new Map}lookup(e,t){return Promise.resolve(this.cache.get(this.keyEncoder(e,t))??null)}async update(e,t,n){this.cache.set(this.keyEncoder(e,t),n)}static global(){return new e(WC)}},KC=s({BaseChatMessageHistory:()=>qC,BaseListChatMessageHistory:()=>JC,InMemoryChatMessageHistory:()=>YC}),qC=class extends ve{async addMessages(e){for(let t of e)await this.addMessage(t)}},JC=class extends ve{addUserMessage(e){return this.addMessage(new fn(e))}addAIMessage(e){return this.addMessage(new $t(e))}async addMessages(e){for(let t of e)await this.addMessage(t)}clear(){throw Error(`Not implemented.`)}},YC=class extends JC{lc_namespace=[`langchain`,`stores`,`message`,`in_memory`];messages=[];constructor(e){super(...arguments),this.messages=e??[]}async getMessages(){return this.messages}async addMessage(e){this.messages.push(e)}async clear(){this.messages=[]}},XC=class{pageContent;metadata;id;constructor(e){this.pageContent=e.pageContent===void 0?``:e.pageContent.toString(),this.metadata=e.metadata??{},this.id=e.id}},ZC=class extends lx{lc_namespace=[`langchain_core`,`documents`,`transformers`];invoke(e,t){return this.transformDocuments(e)}},QC=class extends ZC{async transformDocuments(e){let t=[];for(let n of e){let e=await this._transformDocument(n);t.push(e)}return t}},$C=s({BaseDocumentTransformer:()=>ZC,Document:()=>XC,MappingDocumentTransformer:()=>QC}),ew=s({BaseDocumentLoader:()=>tw}),tw=class{},nw=s({LangSmithLoader:()=>rw}),rw=class extends tw{datasetId;datasetName;exampleIds;asOf;splits;inlineS3Urls;offset;limit;metadata;filter;contentKey;formatContent;client;constructor(e){if(super(),e.client&&e.clientConfig)throw Error(`client and clientConfig cannot both be provided.`);this.client=e.client??new bc(e?.clientConfig),this.contentKey=e.contentKey?e.contentKey.split(`.`):[],this.formatContent=e.formatContent??iw,this.datasetId=e.datasetId,this.datasetName=e.datasetName,this.exampleIds=e.exampleIds,this.asOf=e.asOf,this.splits=e.splits,this.inlineS3Urls=e.inlineS3Urls,this.offset=e.offset,this.limit=e.limit,this.metadata=e.metadata,this.filter=e.filter}async load(){let e=[];for await(let t of this.client.listExamples({datasetId:this.datasetId,datasetName:this.datasetName,exampleIds:this.exampleIds,asOf:this.asOf,splits:this.splits,inlineS3Urls:this.inlineS3Urls,offset:this.offset,limit:this.limit,metadata:this.metadata,filter:this.filter})){let n=t.inputs;for(let e of this.contentKey)n=n[e];let r=this.formatContent(n),i=t;[`created_at`,`modified_at`].forEach(e=>{e in i&&typeof i[e]==`object`&&(i[e]=i[e].toString())}),e.push({pageContent:r,metadata:i})}return e}};function iw(e){if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}var aw=s({Embeddings:()=>ow}),ow=class{caller;constructor(e){this.caller=new sd(e??{})}},sw=class extends ve{lc_namespace=[`langchain_core`,`example_selectors`,`base`]},cw=class{async getPromptAsync(e,t){return this.getPrompt(e).partial(t?.partialVariables??{})}},lw=class extends cw{defaultPrompt;conditionals;constructor(e,t=[]){super(),this.defaultPrompt=e,this.conditionals=t}getPrompt(e){for(let[t,n]of this.conditionals)if(t(e))return n;return this.defaultPrompt}};function uw(e){return e._modelType()===`base_llm`}function dw(e){return e._modelType()===`base_chat_model`}function fw(e){return e.split(/\n| /).length}var pw=class e extends sw{examples=[];examplePrompt;getTextLength=fw;maxLength=2048;exampleTextLengths=[];constructor(e){super(e),this.examplePrompt=e.examplePrompt,this.maxLength=e.maxLength??2048,this.getTextLength=e.getTextLength??fw}async addExample(e){this.examples.push(e);let t=await this.examplePrompt.format(e);this.exampleTextLengths.push(this.getTextLength(t))}async calculateExampleTextLengths(e,t){if(e.length>0)return e;let{examples:n,examplePrompt:r}=t;return(await Promise.all(n.map(e=>r.format(e)))).map(e=>this.getTextLength(e))}async selectExamples(e){let t=Object.values(e).join(` `),n=this.maxLength-this.getTextLength(t),r=0,i=[];for(;n>0&&r<this.examples.length;){let e=n-this.exampleTextLengths[r];if(e<0)break;i.push(this.examples[r]),n=e,r+=1}return i}static async fromExamples(t,n){let r=new e(n);return await Promise.all(t.map(e=>r.addExample(e))),r}};function mw(e){return Object.keys(e).sort().map(t=>e[t])}var hw=class e extends sw{vectorStoreRetriever;exampleKeys;inputKeys;constructor(e){if(super(e),this.exampleKeys=e.exampleKeys,this.inputKeys=e.inputKeys,e.vectorStore!==void 0)this.vectorStoreRetriever=e.vectorStore.asRetriever({k:e.k??4,filter:e.filter});else if(e.vectorStoreRetriever)this.vectorStoreRetriever=e.vectorStoreRetriever;else throw Error(`You must specify one of "vectorStore" and "vectorStoreRetriever".`)}async addExample(e){let t=mw((this.inputKeys??Object.keys(e)).reduce((t,n)=>({...t,[n]:e[n]}),{})).join(` `);await this.vectorStoreRetriever.addDocuments([new XC({pageContent:t,metadata:e})])}async selectExamples(e){let t=mw((this.inputKeys??Object.keys(e)).reduce((t,n)=>({...t,[n]:e[n]}),{})).join(` `),n=(await this.vectorStoreRetriever.invoke(t)).map(e=>e.metadata);return this.exampleKeys?n.map(e=>this.exampleKeys.reduce((t,n)=>({...t,[n]:e[n]}),{})):n}static async fromExamples(t,n,r,i={}){let a=i.inputKeys??null,o=t.map(e=>mw(a?a.reduce((t,n)=>({...t,[n]:e[n]}),{}):e).join(` `));return new e({vectorStore:await r.fromTexts(o,t,n,i),k:i.k??4,exampleKeys:i.exampleKeys,inputKeys:i.inputKeys})}},gw=s({BaseExampleSelector:()=>sw,BasePromptSelector:()=>cw,ConditionalPromptSelector:()=>lw,LengthBasedExampleSelector:()=>pw,SemanticSimilarityExampleSelector:()=>hw,isChatModel:()=>dw,isLLM:()=>uw}),_w=`10f90ea3-90a4-4962-bf75-83a0f3c1c62a`,vw=class extends ve{lc_namespace=[`langchain`,`recordmanagers`]},yw=class{uid;hash_;contentHash;metadataHash;pageContent;metadata;keyEncoder=LC;constructor(e){this.uid=e.uid,this.pageContent=e.pageContent,this.metadata=e.metadata}makeDefaultKeyEncoder(e){this.keyEncoder=e}calculateHashes(){let e=[`hash_`,`content_hash`,`metadata_hash`];for(let t of e)if(t in this.metadata)throw Error(`Metadata cannot contain key ${t} as it is reserved for internal use. Restricted keys: [${e.join(`, `)}]`);let t=this._hashStringToUUID(this.pageContent);try{let e=this._hashNestedDictToUUID(this.metadata);this.contentHash=t,this.metadataHash=e}catch(e){throw Error(`Failed to hash metadata: ${e}. Please use a dict that can be serialized using json.`)}this.hash_=this._hashStringToUUID(this.contentHash+this.metadataHash),this.uid||=this.hash_}toDocument(){return new XC({pageContent:this.pageContent,metadata:this.metadata})}static fromDocument(e,t){let n=new this({pageContent:e.pageContent,metadata:e.metadata,uid:t||e.uid});return n.calculateHashes(),n}_hashStringToUUID(e){return br(this.keyEncoder(e),_w)}_hashNestedDictToUUID(e){let t=JSON.stringify(e,Object.keys(e).sort());return br(this.keyEncoder(t),_w)}};function bw(e,t){let n=[],r=[];return t.forEach(t=>{r.push(t),r.length>=e&&(n.push(r),r=[])}),r.length>0&&n.push(r),n}function xw(e){let t=new Set,n=[];for(let r of e){if(!r.hash_)throw Error(`Hashed document does not have a hash`);t.has(r.hash_)||(t.add(r.hash_),n.push(r))}return n}function Sw(e){if(e===null)return e=>null;if(typeof e==`string`)return t=>t.metadata[e];if(typeof e==`function`)return e;throw Error(`sourceIdKey should be null, a string or a function, got ${typeof e}`)}var Cw=e=>`load`in e&&typeof e.load==`function`&&`loadAndSplit`in e&&typeof e.loadAndSplit==`function`;async function ww(e){let{docsSource:t,recordManager:n,vectorStore:r,options:i}=e,{batchSize:a=100,cleanup:o,sourceIdKey:s,cleanupBatchSize:c=1e3,forceUpdate:l=!1}=i??{};if(o===`incremental`&&!s)throw Error(`sourceIdKey is required when cleanup mode is incremental. Please provide through 'options.sourceIdKey'.`);let u=Cw(t)?await t.load():t,d=Sw(s??null),f=await n.getTime(),p=0,m=0,h=0,g=0,_=bw(a??100,u);for(let e of _){let t=xw(e.map(e=>yw.fromDocument(e))),i=t.map(e=>d(e));o===`incremental`&&t.forEach((e,t)=>{if(i[t]===null)throw Error(`sourceIdKey must be provided when cleanup is incremental`)});let a=await n.exists(t.map(e=>e.uid)),s=[],c=[],u=[],_=new Set;if(t.forEach((e,t)=>{if(a[t])if(l)_.add(e.uid);else{u.push(e.uid);return}s.push(e.uid),c.push(e.toDocument())}),u.length>0&&(await n.update(u,{timeAtLeast:f}),g+=u.length),c.length>0&&(await r.addDocuments(c,{ids:s}),p+=c.length-_.size,h+=_.size),await n.update(t.map(e=>e.uid),{timeAtLeast:f,groupIds:i}),o===`incremental`){i.forEach(e=>{if(!e)throw Error(`Source id cannot be null`)});let e=await n.listKeys({before:f,groupIds:i});e.length>0&&(await r.delete({ids:e}),await n.deleteKeys(e),m+=e.length)}}if(o===`full`){let e=await n.listKeys({before:f,limit:c});for(;e.length>0;)await r.delete({ids:e}),await n.deleteKeys(e),m+=e.length,e=await n.listKeys({before:f,limit:c})}return{numAdded:p,numDeleted:m,numUpdated:h,numSkipped:g}}var Tw=s({RecordManager:()=>vw,UUIDV5_NAMESPACE:()=>_w,_HashedDocument:()=>yw,_batch:()=>bw,_deduplicateInOrder:()=>xw,_getSourceIdAssigner:()=>Sw,_isBaseDocumentLoader:()=>Cw,index:()=>ww}),Ew=s({BasePromptValue:()=>Dw,ChatPromptValue:()=>kw,ImagePromptValue:()=>Aw,StringPromptValue:()=>Ow}),Dw=class extends ve{},Ow=class extends Dw{static lc_name(){return`StringPromptValue`}lc_namespace=[`langchain_core`,`prompt_values`];lc_serializable=!0;value;constructor(e){super({value:e}),this.value=e}toString(){return this.value}toChatMessages(){return[new fn(this.value)]}},kw=class extends Dw{lc_namespace=[`langchain_core`,`prompt_values`];lc_serializable=!0;static lc_name(){return`ChatPromptValue`}messages;constructor(e){Array.isArray(e)&&(e={messages:e}),super(e),this.messages=e.messages}toString(){return On(this.messages)}toChatMessages(){return this.messages}},Aw=class extends Dw{lc_namespace=[`langchain_core`,`prompt_values`];lc_serializable=!0;static lc_name(){return`ImagePromptValue`}imageUrl;value;constructor(e){`imageUrl`in e||(e={imageUrl:e}),super(e),this.imageUrl=e.imageUrl}toString(){return this.imageUrl.url}toChatMessages(){return[new fn({content:[{type:`image_url`,image_url:{detail:this.imageUrl.detail,url:this.imageUrl.url}}]})]}},jw=n(r((e=>{e.toByteArray=l;for(var t=[],n=[],r=typeof Uint8Array<`u`?Uint8Array:Array,i=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,a=0,o=i.length;a<o;++a)t[a]=i[a],n[i.charCodeAt(a)]=a;n[45]=62,n[95]=63;function s(e){var t=e.length;if(t%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function c(e,t,n){return(t+n)*3/4-n}function l(e){var t,i=s(e),a=i[0],o=i[1],l=new r(c(e,a,o)),u=0,d=o>0?a-4:a,f;for(f=0;f<d;f+=4)t=n[e.charCodeAt(f)]<<18|n[e.charCodeAt(f+1)]<<12|n[e.charCodeAt(f+2)]<<6|n[e.charCodeAt(f+3)],l[u++]=t>>16&255,l[u++]=t>>8&255,l[u++]=t&255;return o===2&&(t=n[e.charCodeAt(f)]<<2|n[e.charCodeAt(f+1)]>>4,l[u++]=t&255),o===1&&(t=n[e.charCodeAt(f)]<<10|n[e.charCodeAt(f+1)]<<4|n[e.charCodeAt(f+2)]>>2,l[u++]=t>>8&255,l[u++]=t&255),l}}))(),1),Mw=Object.defineProperty,Nw=(e,t,n)=>t in e?Mw(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pw=(e,t,n)=>(Nw(e,typeof t==`symbol`?t:t+``,n),n);function Fw(e,t){let n=Array.from({length:e.length},(e,t)=>({start:t,end:t+1}));for(;n.length>1;){let r=null;for(let i=0;i<n.length-1;i++){let a=e.slice(n[i].start,n[i+1].end),o=t.get(a.join(`,`));o!=null&&(r==null||o<r[0])&&(r=[o,i])}if(r!=null){let e=r[1];n[e]={start:n[e].start,end:n[e+1].end},n.splice(e+1,1)}else break}return n}function Iw(e,t){return e.length===1?[t.get(e.join(`,`))]:Fw(e,t).map(n=>t.get(e.slice(n.start,n.end).join(`,`))).filter(e=>e!=null)}function Lw(e){return e.replace(/[\\^$*+?.()|[\]{}]/g,`\\$&`)}var Rw=class{specialTokens;inverseSpecialTokens;patStr;textEncoder=new TextEncoder;textDecoder=new TextDecoder(`utf-8`);rankMap=new Map;textMap=new Map;constructor(e,t){this.patStr=e.pat_str;let n=e.bpe_ranks.split(`
|
|
101
|
-
`).filter(Boolean).reduce((e,t)=>{let[n,r,...i]=t.split(` `),a=Number.parseInt(r,10);return i.forEach((t,n)=>e[t]=a+n),e},{});for(let[e,t]of Object.entries(n)){let n=jw.toByteArray(e);this.rankMap.set(n.join(`,`),t),this.textMap.set(t,n)}this.specialTokens={...e.special_tokens,...t},this.inverseSpecialTokens=Object.entries(this.specialTokens).reduce((e,[t,n])=>(e[n]=this.textEncoder.encode(t),e),{})}encode(e,t=[],n=`all`){let r=new RegExp(this.patStr,`ug`),i=Rw.specialTokenRegex(Object.keys(this.specialTokens)),a=[],o=new Set(t===`all`?Object.keys(this.specialTokens):t),s=new Set(n===`all`?Object.keys(this.specialTokens).filter(e=>!o.has(e)):n);if(s.size>0){let t=Rw.specialTokenRegex([...s]),n=e.match(t);if(n!=null)throw Error(`The text contains a special token that is not allowed: ${n[0]}`)}let c=0;for(;;){let t=null,n=c;for(;i.lastIndex=n,t=i.exec(e),!(t==null||o.has(t[0]));)n=t.index+1;let s=t?.index??e.length;for(let t of e.substring(c,s).matchAll(r)){let e=this.textEncoder.encode(t[0]),n=this.rankMap.get(e.join(`,`));if(n!=null){a.push(n);continue}a.push(...Iw(e,this.rankMap))}if(t==null)break;let l=this.specialTokens[t[0]];a.push(l),c=t.index+t[0].length}return a}decode(e){let t=[],n=0;for(let r=0;r<e.length;++r){let i=e[r],a=this.textMap.get(i)??this.inverseSpecialTokens[i];a!=null&&(t.push(a),n+=a.length)}let r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return this.textDecoder.decode(r)}},zw=Rw;Pw(zw,`specialTokenRegex`,e=>new RegExp(e.map(e=>Lw(e)).join(`|`),`g`));function Bw(e){switch(e){case`gpt2`:return`gpt2`;case`code-cushman-001`:case`code-cushman-002`:case`code-davinci-001`:case`code-davinci-002`:case`cushman-codex`:case`davinci-codex`:case`davinci-002`:case`text-davinci-002`:case`text-davinci-003`:return`p50k_base`;case`code-davinci-edit-001`:case`text-davinci-edit-001`:return`p50k_edit`;case`ada`:case`babbage`:case`babbage-002`:case`code-search-ada-code-001`:case`code-search-babbage-code-001`:case`curie`:case`davinci`:case`text-ada-001`:case`text-babbage-001`:case`text-curie-001`:case`text-davinci-001`:case`text-search-ada-doc-001`:case`text-search-babbage-doc-001`:case`text-search-curie-doc-001`:case`text-search-davinci-doc-001`:case`text-similarity-ada-001`:case`text-similarity-babbage-001`:case`text-similarity-curie-001`:case`text-similarity-davinci-001`:return`r50k_base`;case`gpt-3.5-turbo-instruct-0914`:case`gpt-3.5-turbo-instruct`:case`gpt-3.5-turbo-16k-0613`:case`gpt-3.5-turbo-16k`:case`gpt-3.5-turbo-0613`:case`gpt-3.5-turbo-0301`:case`gpt-3.5-turbo`:case`gpt-4-32k-0613`:case`gpt-4-32k-0314`:case`gpt-4-32k`:case`gpt-4-0613`:case`gpt-4-0314`:case`gpt-4`:case`gpt-3.5-turbo-1106`:case`gpt-35-turbo`:case`gpt-4-1106-preview`:case`gpt-4-vision-preview`:case`gpt-3.5-turbo-0125`:case`gpt-4-turbo`:case`gpt-4-turbo-2024-04-09`:case`gpt-4-turbo-preview`:case`gpt-4-0125-preview`:case`text-embedding-ada-002`:case`text-embedding-3-small`:case`text-embedding-3-large`:return`cl100k_base`;case`gpt-4o`:case`gpt-4o-2024-05-13`:case`gpt-4o-2024-08-06`:case`gpt-4o-2024-11-20`:case`gpt-4o-mini-2024-07-18`:case`gpt-4o-mini`:case`gpt-4o-search-preview`:case`gpt-4o-search-preview-2025-03-11`:case`gpt-4o-mini-search-preview`:case`gpt-4o-mini-search-preview-2025-03-11`:case`gpt-4o-audio-preview`:case`gpt-4o-audio-preview-2024-12-17`:case`gpt-4o-audio-preview-2024-10-01`:case`gpt-4o-mini-audio-preview`:case`gpt-4o-mini-audio-preview-2024-12-17`:case`o1`:case`o1-2024-12-17`:case`o1-mini`:case`o1-mini-2024-09-12`:case`o1-preview`:case`o1-preview-2024-09-12`:case`o1-pro`:case`o1-pro-2025-03-19`:case`o3`:case`o3-2025-04-16`:case`o3-mini`:case`o3-mini-2025-01-31`:case`o4-mini`:case`o4-mini-2025-04-16`:case`chatgpt-4o-latest`:case`gpt-4o-realtime`:case`gpt-4o-realtime-preview-2024-10-01`:case`gpt-4o-realtime-preview-2024-12-17`:case`gpt-4o-mini-realtime-preview`:case`gpt-4o-mini-realtime-preview-2024-12-17`:case`gpt-4.1`:case`gpt-4.1-2025-04-14`:case`gpt-4.1-mini`:case`gpt-4.1-mini-2025-04-14`:case`gpt-4.1-nano`:case`gpt-4.1-nano-2025-04-14`:case`gpt-4.5-preview`:case`gpt-4.5-preview-2025-02-27`:case`gpt-5`:case`gpt-5-2025-08-07`:case`gpt-5-nano`:case`gpt-5-nano-2025-08-07`:case`gpt-5-mini`:case`gpt-5-mini-2025-08-07`:case`gpt-5-chat-latest`:return`o200k_base`;default:throw Error(`Unknown model`)}}var Vw=s({encodingForModel:()=>Gw,getEncoding:()=>Ww}),Hw={},Uw=new sd({});async function Ww(e){return e in Hw||(Hw[e]=Uw.fetch(`https://tiktoken.pages.dev/js/${e}.json`).then(e=>e.json()).then(e=>new zw(e)).catch(t=>{throw delete Hw[e],t})),await Hw[e]}async function Gw(e){return Ww(Bw(e))}var Kw=s({BaseLangChain:()=>$w,BaseLanguageModel:()=>eT,calculateMaxTokens:()=>Zw,getEmbeddingContextSize:()=>Jw,getModelContextSize:()=>Yw,getModelNameForTiktoken:()=>qw,isOpenAITool:()=>Xw}),qw=e=>e.startsWith(`gpt-5`)?`gpt-5`:e.startsWith(`gpt-3.5-turbo-16k`)?`gpt-3.5-turbo-16k`:e.startsWith(`gpt-3.5-turbo-`)?`gpt-3.5-turbo`:e.startsWith(`gpt-4-32k`)?`gpt-4-32k`:e.startsWith(`gpt-4-`)?`gpt-4`:e.startsWith(`gpt-4o`)?`gpt-4o`:e,Jw=e=>{switch(e){case`text-embedding-ada-002`:return 8191;default:return 2046}},Yw=e=>{switch(qw(e)){case`gpt-5`:case`gpt-5-turbo`:case`gpt-5-turbo-preview`:return 4e5;case`gpt-4o`:case`gpt-4o-mini`:case`gpt-4o-2024-05-13`:case`gpt-4o-2024-08-06`:return 128e3;case`gpt-4-turbo`:case`gpt-4-turbo-preview`:case`gpt-4-turbo-2024-04-09`:case`gpt-4-0125-preview`:case`gpt-4-1106-preview`:return 128e3;case`gpt-4-32k`:case`gpt-4-32k-0314`:case`gpt-4-32k-0613`:return 32768;case`gpt-4`:case`gpt-4-0314`:case`gpt-4-0613`:return 8192;case`gpt-3.5-turbo-16k`:case`gpt-3.5-turbo-16k-0613`:return 16384;case`gpt-3.5-turbo`:case`gpt-3.5-turbo-0301`:case`gpt-3.5-turbo-0613`:case`gpt-3.5-turbo-1106`:case`gpt-3.5-turbo-0125`:return 4096;case`text-davinci-003`:case`text-davinci-002`:return 4097;case`text-davinci-001`:return 2049;case`text-curie-001`:case`text-babbage-001`:case`text-ada-001`:return 2048;case`code-davinci-002`:case`code-davinci-001`:return 8e3;case`code-cushman-001`:return 2048;case`claude-3-5-sonnet-20241022`:case`claude-3-5-sonnet-20240620`:case`claude-3-opus-20240229`:case`claude-3-sonnet-20240229`:case`claude-3-haiku-20240307`:case`claude-2.1`:return 2e5;case`claude-2.0`:case`claude-instant-1.2`:return 1e5;case`gemini-1.5-pro`:case`gemini-1.5-pro-latest`:case`gemini-1.5-flash`:case`gemini-1.5-flash-latest`:return 1e6;case`gemini-pro`:case`gemini-pro-vision`:return 32768;default:return 4097}};function Xw(e){return typeof e!=`object`||!e?!1:!!(`type`in e&&e.type===`function`&&`function`in e&&typeof e.function==`object`&&e.function&&`name`in e.function&&`parameters`in e.function)}var Zw=async({prompt:e,modelName:t})=>{let n;try{n=(await Gw(qw(t))).encode(e).length}catch{console.warn(`Failed to calculate number of tokens, falling back to approximate count`),n=Math.ceil(e.length/4)}return Yw(t)-n},Qw=()=>!1,$w=class extends lx{verbose;callbacks;tags;metadata;get lc_attributes(){return{callbacks:void 0,verbose:void 0}}constructor(e){super(e),this.verbose=e.verbose??Qw(),this.callbacks=e.callbacks,this.tags=e.tags??[],this.metadata=e.metadata??{},this._addVersion(`@langchain/core`,`1.1.48`)}_addVersion(e,t){let n=this.metadata?.versions;this.metadata={...this.metadata,versions:{...typeof n==`object`&&n?n:{},[e]:t}}}},eT=class extends $w{get callKeys(){return[`stop`,`timeout`,`signal`,`tags`,`metadata`,`callbacks`]}caller;cache;constructor({callbacks:e,callbackManager:t,...n}){let{cache:r,...i}=n;super({callbacks:e??t,...i}),typeof r==`object`?this.cache=r:r?this.cache=GC.global():this.cache=void 0,this.caller=new sd(n??{})}_encoding;async getNumTokens(e){let t;t=typeof e==`string`?e:e.map(e=>typeof e==`string`?e:e.type===`text`&&`text`in e?e.text:``).join(``);let n=Math.ceil(t.length/4);if(!this._encoding)try{this._encoding=await Gw(`modelName`in this?qw(this.modelName):`gpt2`)}catch(e){console.warn(`Failed to calculate number of tokens, falling back to approximate count`,e)}if(this._encoding)try{n=this._encoding.encode(t).length}catch(e){console.warn(`Failed to calculate number of tokens, falling back to approximate count`,e)}return n}static _convertInputToPromptValue(e){return typeof e==`string`?new Ow(e):Array.isArray(e)?new kw(e.map(En)):e}_identifyingParams(){return{}}_getSerializedCacheKeyParametersForCall({config:e,...t}){let n={...this._identifyingParams(),...t,_type:this._llmType(),_model:this._modelType()};return Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>`${e}:${JSON.stringify(t)}`).sort().join(`,`)}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}static async deserialize(e){throw Error(`Use .toJSON() instead`)}get profile(){return{}}_filterInvocationParamsForTracing(e){let{tools:t,functions:n,messages:r,response_format:i,...a}=e;return a}},tT=s({applyPatch:()=>Tu,compare:()=>ju}),nT=class extends lx{parseResultWithPrompt(e,t,n){return this.parseResult(e,n)}_baseMessageToString(e){return typeof e.content==`string`?e.content:this._baseMessageContentToString(e.content)}_baseMessageContentToString(e){return JSON.stringify(e)}async invoke(e,t){return typeof e==`string`?this._callWithConfig(async(e,t)=>this.parseResult([{text:e}],t?.callbacks),e,{...t,runType:`parser`}):this._callWithConfig(async(e,t)=>this.parseResult([{message:e,text:this._baseMessageToString(e)}],t?.callbacks),e,{...t,runType:`parser`})}},rT=class extends nT{parseResult(e,t){return this.parse(e[0].text,t)}async parseWithPrompt(e,t,n){return this.parse(e,n)}_type(){throw Error(`_type not implemented`)}},iT=class extends Error{llmOutput;observation;sendToLLM;constructor(e,t,n,r=!1){if(super(e),this.llmOutput=t,this.observation=n,this.sendToLLM=r,r&&(n===void 0||t===void 0))throw Error(`Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true`);d(this,`OUTPUT_PARSING_FAILURE`)}},aT=class extends rT{async*_transform(e){for await(let t of e)typeof t==`string`?yield this.parseResult([{text:t}]):yield this.parseResult([{message:t,text:this._baseMessageToString(t)}])}async*transform(e,t){yield*this._transformStreamWithConfig(e,this._transform.bind(this),{...t,runType:`parser`})}},oT=class extends aT{diff=!1;constructor(e){super(e),this.diff=e?.diff??this.diff}async*_transform(e){let t,n;for await(let r of e){if(typeof r!=`string`&&typeof r.content!=`string`)throw Error(`Cannot handle non-string output.`);let e;if(vt(r)){if(typeof r.content!=`string`)throw Error(`Cannot handle non-string message output.`);e=new Uu({message:r,text:r.content})}else if(_t(r)){if(typeof r.content!=`string`)throw Error(`Cannot handle non-string message output.`);e=new Uu({message:Nn(r),text:r.content})}else e=new Hu({text:r});n=n===void 0?e:n.concat(e);let i=await this.parsePartialResult([n]);i!=null&&!ob(i,t)&&(this.diff?yield this._diff(t,i):yield i,t=i)}}getFormatInstructions(){return``}},sT=class extends aT{static lc_name(){return`BytesOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`bytes`];lc_serializable=!0;textEncoder=new TextEncoder;parse(e){return Promise.resolve(this.textEncoder.encode(e))}getFormatInstructions(){return``}},cT=class extends aT{re;async*_transform(e){let t=``;for await(let n of e)if(typeof n==`string`?t+=n:t+=n.content,this.re){let e=[...t.matchAll(this.re)];if(e.length>1){let n=0;for(let t of e.slice(0,-1))yield[t[1]],n+=(t.index??0)+t[0].length;t=t.slice(n)}}else{let e=await this.parse(t);if(e.length>1){for(let t of e.slice(0,-1))yield[t];t=e[e.length-1]}}for(let e of await this.parse(t))yield[e]}},lT=class extends cT{static lc_name(){return`CommaSeparatedListOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`list`];lc_serializable=!0;async parse(e){try{return e.trim().split(`,`).map(e=>e.trim())}catch{throw new iT(`Could not parse output: ${e}`,e)}}getFormatInstructions(){return"Your response should be a list of comma separated values, eg: `foo, bar, baz`"}},uT=class extends cT{lc_namespace=[`langchain_core`,`output_parsers`,`list`];length;separator;constructor({length:e,separator:t}){super(...arguments),this.length=e,this.separator=t||`,`}async parse(e){try{let t=e.trim().split(this.separator).map(e=>e.trim());if(this.length!==void 0&&t.length!==this.length)throw new iT(`Incorrect number of items. Expected ${this.length}, got ${t.length}.`);return t}catch(t){throw Object.getPrototypeOf(t)===iT.prototype?t:new iT(`Could not parse output: ${e}`)}}getFormatInstructions(){return`Your response should be a list of ${this.length===void 0?``:`${this.length} `}items separated by "${this.separator}" (eg: \`foo${this.separator} bar${this.separator} baz\`)`}},dT=class extends cT{static lc_name(){return`NumberedListOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`list`];lc_serializable=!0;getFormatInstructions(){return`Your response should be a numbered list with each item on a new line. For example:
|
|
101
|
+
`).filter(Boolean).reduce((e,t)=>{let[n,r,...i]=t.split(` `),a=Number.parseInt(r,10);return i.forEach((t,n)=>e[t]=a+n),e},{});for(let[e,t]of Object.entries(n)){let n=jw.toByteArray(e);this.rankMap.set(n.join(`,`),t),this.textMap.set(t,n)}this.specialTokens={...e.special_tokens,...t},this.inverseSpecialTokens=Object.entries(this.specialTokens).reduce((e,[t,n])=>(e[n]=this.textEncoder.encode(t),e),{})}encode(e,t=[],n=`all`){let r=new RegExp(this.patStr,`ug`),i=Rw.specialTokenRegex(Object.keys(this.specialTokens)),a=[],o=new Set(t===`all`?Object.keys(this.specialTokens):t),s=new Set(n===`all`?Object.keys(this.specialTokens).filter(e=>!o.has(e)):n);if(s.size>0){let t=Rw.specialTokenRegex([...s]),n=e.match(t);if(n!=null)throw Error(`The text contains a special token that is not allowed: ${n[0]}`)}let c=0;for(;;){let t=null,n=c;for(;i.lastIndex=n,t=i.exec(e),!(t==null||o.has(t[0]));)n=t.index+1;let s=t?.index??e.length;for(let t of e.substring(c,s).matchAll(r)){let e=this.textEncoder.encode(t[0]),n=this.rankMap.get(e.join(`,`));if(n!=null){a.push(n);continue}a.push(...Iw(e,this.rankMap))}if(t==null)break;let l=this.specialTokens[t[0]];a.push(l),c=t.index+t[0].length}return a}decode(e){let t=[],n=0;for(let r=0;r<e.length;++r){let i=e[r],a=this.textMap.get(i)??this.inverseSpecialTokens[i];a!=null&&(t.push(a),n+=a.length)}let r=new Uint8Array(n),i=0;for(let e of t)r.set(e,i),i+=e.length;return this.textDecoder.decode(r)}},zw=Rw;Pw(zw,`specialTokenRegex`,e=>new RegExp(e.map(e=>Lw(e)).join(`|`),`g`));function Bw(e){switch(e){case`gpt2`:return`gpt2`;case`code-cushman-001`:case`code-cushman-002`:case`code-davinci-001`:case`code-davinci-002`:case`cushman-codex`:case`davinci-codex`:case`davinci-002`:case`text-davinci-002`:case`text-davinci-003`:return`p50k_base`;case`code-davinci-edit-001`:case`text-davinci-edit-001`:return`p50k_edit`;case`ada`:case`babbage`:case`babbage-002`:case`code-search-ada-code-001`:case`code-search-babbage-code-001`:case`curie`:case`davinci`:case`text-ada-001`:case`text-babbage-001`:case`text-curie-001`:case`text-davinci-001`:case`text-search-ada-doc-001`:case`text-search-babbage-doc-001`:case`text-search-curie-doc-001`:case`text-search-davinci-doc-001`:case`text-similarity-ada-001`:case`text-similarity-babbage-001`:case`text-similarity-curie-001`:case`text-similarity-davinci-001`:return`r50k_base`;case`gpt-3.5-turbo-instruct-0914`:case`gpt-3.5-turbo-instruct`:case`gpt-3.5-turbo-16k-0613`:case`gpt-3.5-turbo-16k`:case`gpt-3.5-turbo-0613`:case`gpt-3.5-turbo-0301`:case`gpt-3.5-turbo`:case`gpt-4-32k-0613`:case`gpt-4-32k-0314`:case`gpt-4-32k`:case`gpt-4-0613`:case`gpt-4-0314`:case`gpt-4`:case`gpt-3.5-turbo-1106`:case`gpt-35-turbo`:case`gpt-4-1106-preview`:case`gpt-4-vision-preview`:case`gpt-3.5-turbo-0125`:case`gpt-4-turbo`:case`gpt-4-turbo-2024-04-09`:case`gpt-4-turbo-preview`:case`gpt-4-0125-preview`:case`text-embedding-ada-002`:case`text-embedding-3-small`:case`text-embedding-3-large`:return`cl100k_base`;case`gpt-4o`:case`gpt-4o-2024-05-13`:case`gpt-4o-2024-08-06`:case`gpt-4o-2024-11-20`:case`gpt-4o-mini-2024-07-18`:case`gpt-4o-mini`:case`gpt-4o-search-preview`:case`gpt-4o-search-preview-2025-03-11`:case`gpt-4o-mini-search-preview`:case`gpt-4o-mini-search-preview-2025-03-11`:case`gpt-4o-audio-preview`:case`gpt-4o-audio-preview-2024-12-17`:case`gpt-4o-audio-preview-2024-10-01`:case`gpt-4o-mini-audio-preview`:case`gpt-4o-mini-audio-preview-2024-12-17`:case`o1`:case`o1-2024-12-17`:case`o1-mini`:case`o1-mini-2024-09-12`:case`o1-preview`:case`o1-preview-2024-09-12`:case`o1-pro`:case`o1-pro-2025-03-19`:case`o3`:case`o3-2025-04-16`:case`o3-mini`:case`o3-mini-2025-01-31`:case`o4-mini`:case`o4-mini-2025-04-16`:case`chatgpt-4o-latest`:case`gpt-4o-realtime`:case`gpt-4o-realtime-preview-2024-10-01`:case`gpt-4o-realtime-preview-2024-12-17`:case`gpt-4o-mini-realtime-preview`:case`gpt-4o-mini-realtime-preview-2024-12-17`:case`gpt-4.1`:case`gpt-4.1-2025-04-14`:case`gpt-4.1-mini`:case`gpt-4.1-mini-2025-04-14`:case`gpt-4.1-nano`:case`gpt-4.1-nano-2025-04-14`:case`gpt-4.5-preview`:case`gpt-4.5-preview-2025-02-27`:case`gpt-5`:case`gpt-5-2025-08-07`:case`gpt-5-nano`:case`gpt-5-nano-2025-08-07`:case`gpt-5-mini`:case`gpt-5-mini-2025-08-07`:case`gpt-5-chat-latest`:return`o200k_base`;default:throw Error(`Unknown model`)}}var Vw=s({encodingForModel:()=>Gw,getEncoding:()=>Ww}),Hw={},Uw=new sd({});async function Ww(e){return e in Hw||(Hw[e]=Uw.fetch(`https://tiktoken.pages.dev/js/${e}.json`).then(e=>e.json()).then(e=>new zw(e)).catch(t=>{throw delete Hw[e],t})),await Hw[e]}async function Gw(e){return Ww(Bw(e))}var Kw=s({BaseLangChain:()=>$w,BaseLanguageModel:()=>eT,calculateMaxTokens:()=>Zw,getEmbeddingContextSize:()=>Jw,getModelContextSize:()=>Yw,getModelNameForTiktoken:()=>qw,isOpenAITool:()=>Xw}),qw=e=>e.startsWith(`gpt-5`)?`gpt-5`:e.startsWith(`gpt-3.5-turbo-16k`)?`gpt-3.5-turbo-16k`:e.startsWith(`gpt-3.5-turbo-`)?`gpt-3.5-turbo`:e.startsWith(`gpt-4-32k`)?`gpt-4-32k`:e.startsWith(`gpt-4-`)?`gpt-4`:e.startsWith(`gpt-4o`)?`gpt-4o`:e,Jw=e=>{switch(e){case`text-embedding-ada-002`:return 8191;default:return 2046}},Yw=e=>{switch(qw(e)){case`gpt-5`:case`gpt-5-turbo`:case`gpt-5-turbo-preview`:return 4e5;case`gpt-4o`:case`gpt-4o-mini`:case`gpt-4o-2024-05-13`:case`gpt-4o-2024-08-06`:return 128e3;case`gpt-4-turbo`:case`gpt-4-turbo-preview`:case`gpt-4-turbo-2024-04-09`:case`gpt-4-0125-preview`:case`gpt-4-1106-preview`:return 128e3;case`gpt-4-32k`:case`gpt-4-32k-0314`:case`gpt-4-32k-0613`:return 32768;case`gpt-4`:case`gpt-4-0314`:case`gpt-4-0613`:return 8192;case`gpt-3.5-turbo-16k`:case`gpt-3.5-turbo-16k-0613`:return 16384;case`gpt-3.5-turbo`:case`gpt-3.5-turbo-0301`:case`gpt-3.5-turbo-0613`:case`gpt-3.5-turbo-1106`:case`gpt-3.5-turbo-0125`:return 4096;case`text-davinci-003`:case`text-davinci-002`:return 4097;case`text-davinci-001`:return 2049;case`text-curie-001`:case`text-babbage-001`:case`text-ada-001`:return 2048;case`code-davinci-002`:case`code-davinci-001`:return 8e3;case`code-cushman-001`:return 2048;case`claude-3-5-sonnet-20241022`:case`claude-3-5-sonnet-20240620`:case`claude-3-opus-20240229`:case`claude-3-sonnet-20240229`:case`claude-3-haiku-20240307`:case`claude-2.1`:return 2e5;case`claude-2.0`:case`claude-instant-1.2`:return 1e5;case`gemini-1.5-pro`:case`gemini-1.5-pro-latest`:case`gemini-1.5-flash`:case`gemini-1.5-flash-latest`:return 1e6;case`gemini-pro`:case`gemini-pro-vision`:return 32768;default:return 4097}};function Xw(e){return typeof e!=`object`||!e?!1:!!(`type`in e&&e.type===`function`&&`function`in e&&typeof e.function==`object`&&e.function&&`name`in e.function&&`parameters`in e.function)}var Zw=async({prompt:e,modelName:t})=>{let n;try{n=(await Gw(qw(t))).encode(e).length}catch{console.warn(`Failed to calculate number of tokens, falling back to approximate count`),n=Math.ceil(e.length/4)}return Yw(t)-n},Qw=()=>!1,$w=class extends lx{verbose;callbacks;tags;metadata;get lc_attributes(){return{callbacks:void 0,verbose:void 0}}constructor(e){super(e),this.verbose=e.verbose??Qw(),this.callbacks=e.callbacks,this.tags=e.tags??[],this.metadata=e.metadata??{},this._addVersion(`@langchain/core`,`1.1.49`)}_addVersion(e,t){let n=this.metadata?.versions;this.metadata={...this.metadata,versions:{...typeof n==`object`&&n?n:{},[e]:t}}}},eT=class extends $w{get callKeys(){return[`stop`,`timeout`,`signal`,`tags`,`metadata`,`callbacks`]}caller;cache;constructor({callbacks:e,callbackManager:t,...n}){let{cache:r,...i}=n;super({callbacks:e??t,...i}),typeof r==`object`?this.cache=r:r?this.cache=GC.global():this.cache=void 0,this.caller=new sd(n??{})}_encoding;async getNumTokens(e){let t;t=typeof e==`string`?e:e.map(e=>typeof e==`string`?e:e.type===`text`&&`text`in e?e.text:``).join(``);let n=Math.ceil(t.length/4);if(!this._encoding)try{this._encoding=await Gw(`modelName`in this?qw(this.modelName):`gpt2`)}catch(e){console.warn(`Failed to calculate number of tokens, falling back to approximate count`,e)}if(this._encoding)try{n=this._encoding.encode(t).length}catch(e){console.warn(`Failed to calculate number of tokens, falling back to approximate count`,e)}return n}static _convertInputToPromptValue(e){return typeof e==`string`?new Ow(e):Array.isArray(e)?new kw(e.map(En)):e}_identifyingParams(){return{}}_getSerializedCacheKeyParametersForCall({config:e,...t}){let n={...this._identifyingParams(),...t,_type:this._llmType(),_model:this._modelType()};return Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>`${e}:${JSON.stringify(t)}`).sort().join(`,`)}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}static async deserialize(e){throw Error(`Use .toJSON() instead`)}get profile(){return{}}_filterInvocationParamsForTracing(e){let{tools:t,functions:n,messages:r,response_format:i,...a}=e;return a}},tT=s({applyPatch:()=>Tu,compare:()=>ju}),nT=class extends lx{parseResultWithPrompt(e,t,n){return this.parseResult(e,n)}_baseMessageToString(e){return typeof e.content==`string`?e.content:this._baseMessageContentToString(e.content)}_baseMessageContentToString(e){return JSON.stringify(e)}async invoke(e,t){return typeof e==`string`?this._callWithConfig(async(e,t)=>this.parseResult([{text:e}],t?.callbacks),e,{...t,runType:`parser`}):this._callWithConfig(async(e,t)=>this.parseResult([{message:e,text:this._baseMessageToString(e)}],t?.callbacks),e,{...t,runType:`parser`})}},rT=class extends nT{parseResult(e,t){return this.parse(e[0].text,t)}async parseWithPrompt(e,t,n){return this.parse(e,n)}_type(){throw Error(`_type not implemented`)}},iT=class extends Error{llmOutput;observation;sendToLLM;constructor(e,t,n,r=!1){if(super(e),this.llmOutput=t,this.observation=n,this.sendToLLM=r,r&&(n===void 0||t===void 0))throw Error(`Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true`);d(this,`OUTPUT_PARSING_FAILURE`)}},aT=class extends rT{async*_transform(e){for await(let t of e)typeof t==`string`?yield this.parseResult([{text:t}]):yield this.parseResult([{message:t,text:this._baseMessageToString(t)}])}async*transform(e,t){yield*this._transformStreamWithConfig(e,this._transform.bind(this),{...t,runType:`parser`})}},oT=class extends aT{diff=!1;constructor(e){super(e),this.diff=e?.diff??this.diff}async*_transform(e){let t,n;for await(let r of e){if(typeof r!=`string`&&typeof r.content!=`string`)throw Error(`Cannot handle non-string output.`);let e;if(vt(r)){if(typeof r.content!=`string`)throw Error(`Cannot handle non-string message output.`);e=new Uu({message:r,text:r.content})}else if(_t(r)){if(typeof r.content!=`string`)throw Error(`Cannot handle non-string message output.`);e=new Uu({message:Nn(r),text:r.content})}else e=new Hu({text:r});n=n===void 0?e:n.concat(e);let i=await this.parsePartialResult([n]);i!=null&&!ob(i,t)&&(this.diff?yield this._diff(t,i):yield i,t=i)}}getFormatInstructions(){return``}},sT=class extends aT{static lc_name(){return`BytesOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`bytes`];lc_serializable=!0;textEncoder=new TextEncoder;parse(e){return Promise.resolve(this.textEncoder.encode(e))}getFormatInstructions(){return``}},cT=class extends aT{re;async*_transform(e){let t=``;for await(let n of e)if(typeof n==`string`?t+=n:t+=n.content,this.re){let e=[...t.matchAll(this.re)];if(e.length>1){let n=0;for(let t of e.slice(0,-1))yield[t[1]],n+=(t.index??0)+t[0].length;t=t.slice(n)}}else{let e=await this.parse(t);if(e.length>1){for(let t of e.slice(0,-1))yield[t];t=e[e.length-1]}}for(let e of await this.parse(t))yield[e]}},lT=class extends cT{static lc_name(){return`CommaSeparatedListOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`list`];lc_serializable=!0;async parse(e){try{return e.trim().split(`,`).map(e=>e.trim())}catch{throw new iT(`Could not parse output: ${e}`,e)}}getFormatInstructions(){return"Your response should be a list of comma separated values, eg: `foo, bar, baz`"}},uT=class extends cT{lc_namespace=[`langchain_core`,`output_parsers`,`list`];length;separator;constructor({length:e,separator:t}){super(...arguments),this.length=e,this.separator=t||`,`}async parse(e){try{let t=e.trim().split(this.separator).map(e=>e.trim());if(this.length!==void 0&&t.length!==this.length)throw new iT(`Incorrect number of items. Expected ${this.length}, got ${t.length}.`);return t}catch(t){throw Object.getPrototypeOf(t)===iT.prototype?t:new iT(`Could not parse output: ${e}`)}}getFormatInstructions(){return`Your response should be a list of ${this.length===void 0?``:`${this.length} `}items separated by "${this.separator}" (eg: \`foo${this.separator} bar${this.separator} baz\`)`}},dT=class extends cT{static lc_name(){return`NumberedListOutputParser`}lc_namespace=[`langchain_core`,`output_parsers`,`list`];lc_serializable=!0;getFormatInstructions(){return`Your response should be a numbered list with each item on a new line. For example:
|
|
102
102
|
|
|
103
103
|
1. foo
|
|
104
104
|
|