@mcp-use/inspector 0.13.2 → 0.14.0-canary.1

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.
Files changed (46) hide show
  1. package/dist/cli.js +7 -53
  2. package/dist/client/assets/base-Aouj1Yhj.js +2 -0
  3. package/dist/client/assets/{index-CR9w_74S.js → base-ZEkF4ver.js} +33 -36
  4. package/dist/client/assets/browser-BWolhM7l.js +12 -0
  5. package/dist/client/assets/embeddings-BTUgP3x_.js +1 -0
  6. package/dist/client/assets/{index-BYR-I2bf.js → index-BOIA9kd1.js} +2 -2
  7. package/dist/client/assets/{index-sQyTG4jp.js → index-BSuQO5pd.js} +3 -3
  8. package/dist/client/assets/index-Bfe1ynAS.js +4 -0
  9. package/dist/client/assets/{index-ClpBZU-N.js → index-C88Q8iJs.js} +1 -1
  10. package/dist/client/assets/index-CNfmoBX-.js +1701 -0
  11. package/dist/client/assets/index-CSZqqrHs.js +34 -0
  12. package/dist/client/assets/index-CtWrgdCi.js +7 -0
  13. package/dist/client/assets/index-DIlJ2WcE.js +70 -0
  14. package/dist/client/assets/index-cMXsdFDY.css +1 -0
  15. package/dist/client/index.html +3 -3
  16. package/dist/server/{chunk-XGILHZOF.js → chunk-F7YWZTWJ.js} +4 -48
  17. package/dist/server/{chunk-JEKCWLHD.js → chunk-Y4GX3FDV.js} +1 -1
  18. package/dist/server/{chunk-MCMZDGO6.js → chunk-Z5QIR3IS.js} +2 -2
  19. package/dist/server/cli.js +2 -2
  20. package/dist/server/index.js +3 -3
  21. package/dist/server/middleware.js +3 -3
  22. package/dist/server/server.d.ts.map +1 -1
  23. package/dist/server/server.js +28 -5
  24. package/dist/server/shared-routes.d.ts.map +1 -1
  25. package/dist/server/shared-routes.js +2 -2
  26. package/dist/server/shared-utils-browser.d.ts.map +1 -1
  27. package/dist/server/shared-utils-browser.js +1 -1
  28. package/package.json +2 -2
  29. package/dist/client/assets/browser-DZ15LLaB.js +0 -501
  30. package/dist/client/assets/display-A5IEINAP-HkQbiJ2E.js +0 -17
  31. package/dist/client/assets/embeddings-C0rUXJ5F.js +0 -1
  32. package/dist/client/assets/fs-u42MReIY.js +0 -1
  33. package/dist/client/assets/index-B5kLR_Rv.js +0 -33
  34. package/dist/client/assets/index-CkHH_UI9.js +0 -1676
  35. package/dist/client/assets/index-DQ7i0BFM.css +0 -1
  36. package/dist/client/assets/index-DRz5BQNA.js +0 -1
  37. package/dist/client/assets/index-DiwCBW8I.js +0 -7
  38. package/dist/client/assets/index-Dj6Mccu_.js +0 -20
  39. package/dist/client/assets/index-JiKw9JSs.js +0 -5
  40. package/dist/client/assets/index-Zctd0Z8B.js +0 -71
  41. package/dist/client/assets/llms-BDMth6TQ.js +0 -2
  42. package/dist/client/assets/path-BOQPmbms.js +0 -1
  43. package/dist/client/assets/path-MNZaYwxc.js +0 -1
  44. package/dist/client/assets/posthog-node-CuYhrq1Q.js +0 -1
  45. package/dist/client/assets/util-t-trnxQI.js +0 -1
  46. package/dist/client/assets/winston-CEUa9Wj-.js +0 -37
package/dist/cli.js CHANGED
@@ -7,11 +7,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7
7
  import { serve } from "@hono/node-server";
8
8
  import { Hono } from "hono";
9
9
  import { cors } from "hono/cors";
10
- import { logger as logger2 } from "hono/logger";
11
- import open from "open";
12
-
13
- // src/server/shared-routes.ts
14
10
  import { logger } from "hono/logger";
11
+ import open from "open";
15
12
 
16
13
  // src/server/shared-utils-browser.ts
17
14
  function toBase64(str) {
@@ -30,7 +27,7 @@ async function* handleChatRequestStream(requestBody) {
30
27
  "Missing required fields: mcpServerUrl, llmConfig, messages"
31
28
  );
32
29
  }
33
- const { MCPAgent, MCPClient } = await import("mcp-use/browser");
30
+ const { MCPAgent, MCPClient } = await import("mcp-use");
34
31
  let llm;
35
32
  if (llmConfig.provider === "openai") {
36
33
  const { ChatOpenAI } = await import("@langchain/openai");
@@ -144,7 +141,7 @@ async function handleChatRequest(requestBody) {
144
141
  "Missing required fields: mcpServerUrl, llmConfig, messages"
145
142
  );
146
143
  }
147
- const { MCPAgent, MCPClient } = await import("mcp-use/browser");
144
+ const { MCPAgent, MCPClient } = await import("mcp-use");
148
145
  let llm;
149
146
  if (llmConfig.provider === "openai") {
150
147
  const { ChatOpenAI } = await import("@langchain/openai");
@@ -865,56 +862,13 @@ var RpcLogBus = class {
865
862
  var rpcLogBus = new RpcLogBus();
866
863
 
867
864
  // src/server/shared-routes.ts
865
+ import { mountMcpProxy } from "mcp-use/server";
868
866
  function registerInspectorRoutes(app2, config) {
869
867
  app2.get("/inspector/health", (c) => {
870
868
  return c.json({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() });
871
869
  });
872
- app2.use("/inspector/api/proxy/*", logger());
873
- app2.all("/inspector/api/proxy/*", async (c) => {
874
- try {
875
- const targetUrl = c.req.header("X-Target-URL");
876
- if (!targetUrl) {
877
- return c.json({ error: "X-Target-URL header is required" }, 400);
878
- }
879
- const method = c.req.method;
880
- const headers = {};
881
- const requestHeaders = c.req.header();
882
- for (const [key, value] of Object.entries(requestHeaders)) {
883
- const lowerKey = key.toLowerCase();
884
- if (!lowerKey.startsWith("x-proxy-") && !lowerKey.startsWith("x-target-") && lowerKey !== "host" && lowerKey !== "accept-encoding") {
885
- headers[key] = value;
886
- }
887
- }
888
- headers["Accept-Encoding"] = "identity";
889
- try {
890
- const targetUrlObj = new URL(targetUrl);
891
- headers.Host = targetUrlObj.host;
892
- } catch {
893
- return c.json({ error: "Invalid target URL" }, 400);
894
- }
895
- const body = method !== "GET" && method !== "HEAD" ? await c.req.arrayBuffer() : void 0;
896
- const response = await fetch(targetUrl, {
897
- method,
898
- headers,
899
- body: body ? new Uint8Array(body) : void 0
900
- });
901
- const responseHeaders = {};
902
- response.headers.forEach((value, key) => {
903
- const lowerKey = key.toLowerCase();
904
- if (lowerKey !== "content-encoding" && lowerKey !== "transfer-encoding" && lowerKey !== "content-length") {
905
- responseHeaders[key] = value;
906
- }
907
- });
908
- return new Response(response.body, {
909
- status: response.status,
910
- statusText: response.statusText,
911
- headers: responseHeaders
912
- });
913
- } catch (error) {
914
- const message = error instanceof Error ? error.message : "Unknown error";
915
- console.error("Proxy request failed:", message, error);
916
- return c.json({ error: "Proxy request failed", details: message }, 500);
917
- }
870
+ mountMcpProxy(app2, {
871
+ path: "/inspector/api/proxy"
918
872
  });
919
873
  app2.post("/inspector/api/chat/stream", async (c) => {
920
874
  try {
@@ -1508,7 +1462,7 @@ Examples:
1508
1462
  }
1509
1463
  var app = new Hono();
1510
1464
  app.use("*", cors());
1511
- app.use("/inspector/api/proxy/*", logger2());
1465
+ app.use("/inspector/api/proxy/*", logger());
1512
1466
  registerInspectorRoutes(app, { autoConnectUrl: mcpUrl });
1513
1467
  registerStaticRoutes(app);
1514
1468
  async function startServer() {
@@ -0,0 +1,2 @@
1
+ import{i as G,av as P,G as U,ad as X,aw as Y,_ as C,O as Z,q as L,ai as Q}from"./base-ZEkF4ver.js";import{g as ee}from"./index-CNfmoBX-.js";function te(e){return e!==void 0&&Array.isArray(e.lc_namespace)}function se(e){return e!==void 0&&P.isRunnable(e)&&"lc_name"in e.constructor&&typeof e.constructor.lc_name=="function"&&e.constructor.lc_name()==="RunnableToolLike"}function ae(e){return!!e&&typeof e=="object"&&"name"in e&&"schema"in e&&(G(e.schema)||e.schema!=null&&typeof e.schema=="object"&&"type"in e.schema&&typeof e.schema.type=="string"&&["null","boolean","object","array","number","string"].includes(e.schema.type))}function Re(e){return ae(e)||se(e)||te(e)}var re={};C(re,{BasePromptValue:()=>M,ChatPromptValue:()=>V,ImagePromptValue:()=>ie,StringPromptValue:()=>O});var M=class extends Y{},O=class extends M{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 U(this.value)]}},V=class extends M{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 X(this.messages)}toChatMessages(){return this.messages}},ie=class extends M{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 U({content:[{type:"image_url",image_url:{detail:this.imageUrl.detail,url:this.imageUrl.url}}]})]}},o="0123456789abcdef".split(""),ne=[-2147483648,8388608,32768,128],_=[24,16,8,0],E=[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],m=[];function A(e,t){t?(m[0]=m[16]=m[1]=m[2]=m[3]=m[4]=m[5]=m[6]=m[7]=m[8]=m[9]=m[10]=m[11]=m[12]=m[13]=m[14]=m[15]=0,this.blocks=m):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}A.prototype.update=function(e){if(!this.finalized){var t,r=typeof e;if(r!=="string"){if(r==="object"){if(e===null)throw new Error(ERROR);if(ARRAY_BUFFER&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!Array.isArray(e)&&(!ARRAY_BUFFER||!ArrayBuffer.isView(e)))throw new Error(ERROR)}else throw new Error(ERROR);t=!0}for(var s,i=0,a,h=e.length,n=this.blocks;i<h;){if(this.hashed&&(this.hashed=!1,n[0]=this.block,this.block=n[16]=n[1]=n[2]=n[3]=n[4]=n[5]=n[6]=n[7]=n[8]=n[9]=n[10]=n[11]=n[12]=n[13]=n[14]=n[15]=0),t)for(a=this.start;i<h&&a<64;++i)n[a>>>2]|=e[i]<<_[a++&3];else for(a=this.start;i<h&&a<64;++i)s=e.charCodeAt(i),s<128?n[a>>>2]|=s<<_[a++&3]:s<2048?(n[a>>>2]|=(192|s>>>6)<<_[a++&3],n[a>>>2]|=(128|s&63)<<_[a++&3]):s<55296||s>=57344?(n[a>>>2]|=(224|s>>>12)<<_[a++&3],n[a>>>2]|=(128|s>>>6&63)<<_[a++&3],n[a>>>2]|=(128|s&63)<<_[a++&3]):(s=65536+((s&1023)<<10|e.charCodeAt(++i)&1023),n[a>>>2]|=(240|s>>>18)<<_[a++&3],n[a>>>2]|=(128|s>>>12&63)<<_[a++&3],n[a>>>2]|=(128|s>>>6&63)<<_[a++&3],n[a>>>2]|=(128|s&63)<<_[a++&3]);this.lastByteIndex=a,this.bytes+=a-this.start,a>=64?(this.block=n[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=this.bytes%4294967296),this}};A.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var e=this.blocks,t=this.lastByteIndex;e[16]=this.block,e[t>>>2]|=ne[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()}};A.prototype.hash=function(){var e=this.h0,t=this.h1,r=this.h2,s=this.h3,i=this.h4,a=this.h5,h=this.h6,n=this.h7,g=this.blocks,u,b,x,k,c,l,p,d,y,f,v;for(u=16;u<64;++u)c=g[u-15],b=(c>>>7|c<<25)^(c>>>18|c<<14)^c>>>3,c=g[u-2],x=(c>>>17|c<<15)^(c>>>19|c<<13)^c>>>10,g[u]=g[u-16]+b+g[u-7]+x<<0;for(v=t&r,u=0;u<64;u+=4)this.first?(this.is224?(d=300032,c=g[0]-1413257819,n=c-150054599<<0,s=c+24177077<<0):(d=704751109,c=g[0]-210244248,n=c-1521486534<<0,s=c+143694565<<0),this.first=!1):(b=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),x=(i>>>6|i<<26)^(i>>>11|i<<21)^(i>>>25|i<<7),d=e&t,k=d^e&r^v,p=i&a^~i&h,c=n+x+p+E[u]+g[u],l=b+k,n=s+c<<0,s=c+l<<0),b=(s>>>2|s<<30)^(s>>>13|s<<19)^(s>>>22|s<<10),x=(n>>>6|n<<26)^(n>>>11|n<<21)^(n>>>25|n<<7),y=s&e,k=y^s&t^d,p=h&n^~h&i,c=a+x+p+E[u+1]+g[u+1],l=b+k,h=r+c<<0,r=c+l<<0,b=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),x=(h>>>6|h<<26)^(h>>>11|h<<21)^(h>>>25|h<<7),f=r&s,k=f^r&e^y,p=a&h^~a&n,c=i+x+p+E[u+2]+g[u+2],l=b+k,a=t+c<<0,t=c+l<<0,b=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),x=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),v=t&r,k=v^t&s^f,p=a&h^~a&n,c=i+x+p+E[u+3]+g[u+3],l=b+k,i=e+c<<0,e=c+l<<0,this.chromeBugWorkAround=!0;this.h0=this.h0+e<<0,this.h1=this.h1+t<<0,this.h2=this.h2+r<<0,this.h3=this.h3+s<<0,this.h4=this.h4+i<<0,this.h5=this.h5+a<<0,this.h6=this.h6+h<<0,this.h7=this.h7+n<<0};A.prototype.hex=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,s=this.h3,i=this.h4,a=this.h5,h=this.h6,n=this.h7,g=o[e>>>28&15]+o[e>>>24&15]+o[e>>>20&15]+o[e>>>16&15]+o[e>>>12&15]+o[e>>>8&15]+o[e>>>4&15]+o[e&15]+o[t>>>28&15]+o[t>>>24&15]+o[t>>>20&15]+o[t>>>16&15]+o[t>>>12&15]+o[t>>>8&15]+o[t>>>4&15]+o[t&15]+o[r>>>28&15]+o[r>>>24&15]+o[r>>>20&15]+o[r>>>16&15]+o[r>>>12&15]+o[r>>>8&15]+o[r>>>4&15]+o[r&15]+o[s>>>28&15]+o[s>>>24&15]+o[s>>>20&15]+o[s>>>16&15]+o[s>>>12&15]+o[s>>>8&15]+o[s>>>4&15]+o[s&15]+o[i>>>28&15]+o[i>>>24&15]+o[i>>>20&15]+o[i>>>16&15]+o[i>>>12&15]+o[i>>>8&15]+o[i>>>4&15]+o[i&15]+o[a>>>28&15]+o[a>>>24&15]+o[a>>>20&15]+o[a>>>16&15]+o[a>>>12&15]+o[a>>>8&15]+o[a>>>4&15]+o[a&15]+o[h>>>28&15]+o[h>>>24&15]+o[h>>>20&15]+o[h>>>16&15]+o[h>>>12&15]+o[h>>>8&15]+o[h>>>4&15]+o[h&15];return this.is224||(g+=o[n>>>28&15]+o[n>>>24&15]+o[n>>>20&15]+o[n>>>16&15]+o[n>>>12&15]+o[n>>>8&15]+o[n>>>4&15]+o[n&15]),g};A.prototype.toString=A.prototype.hex;A.prototype.digest=function(){this.finalize();var e=this.h0,t=this.h1,r=this.h2,s=this.h3,i=this.h4,a=this.h5,h=this.h6,n=this.h7,g=[e>>>24&255,e>>>16&255,e>>>8&255,e&255,t>>>24&255,t>>>16&255,t>>>8&255,t&255,r>>>24&255,r>>>16&255,r>>>8&255,r&255,s>>>24&255,s>>>16&255,s>>>8&255,s&255,i>>>24&255,i>>>16&255,i>>>8&255,i&255,a>>>24&255,a>>>16&255,a>>>8&255,a&255,h>>>24&255,h>>>16&255,h>>>8&255,h&255];return this.is224||g.push(n>>>24&255,n>>>16&255,n>>>8&255,n&255),g};A.prototype.array=A.prototype.digest;A.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};const I=(...e)=>new A(!1,!0).update(e.join("")).hex();var ce={};C(ce,{sha256:()=>I});var oe={};C(oe,{BaseCache:()=>$,InMemoryCache:()=>D,defaultHashKeyEncoder:()=>H,deserializeStoredGeneration:()=>he,serializeGeneration:()=>le});const H=(...e)=>I(e.join("_"));function he(e){return e.message!==void 0?{text:e.text,message:Z(e.message)}:{text:e.text}}function le(e){const t={text:e.text};return e.message!==void 0&&(t.message=e.message.toDict()),t}var $=class{keyEncoder=H;makeDefaultKeyEncoder(e){this.keyEncoder=e}};const ue=new Map;var D=class W extends ${cache;constructor(t){super(),this.cache=t??new Map}lookup(t,r){return Promise.resolve(this.cache.get(this.keyEncoder(t,r))??null)}async update(t,r,s){this.cache.set(this.keyEncoder(t,r),s)}static global(){return new W(ue)}},F={},z;function pe(){if(z)return F;z=1,F.byteLength=n,F.toByteArray=u,F.fromByteArray=k;for(var e=[],t=[],r=typeof Uint8Array<"u"?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,a=s.length;i<a;++i)e[i]=s[i],t[s.charCodeAt(i)]=i;t[45]=62,t[95]=63;function h(c){var l=c.length;if(l%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var p=c.indexOf("=");p===-1&&(p=l);var d=p===l?0:4-p%4;return[p,d]}function n(c){var l=h(c),p=l[0],d=l[1];return(p+d)*3/4-d}function g(c,l,p){return(l+p)*3/4-p}function u(c){var l,p=h(c),d=p[0],y=p[1],f=new r(g(c,d,y)),v=0,T=y>0?d-4:d,w;for(w=0;w<T;w+=4)l=t[c.charCodeAt(w)]<<18|t[c.charCodeAt(w+1)]<<12|t[c.charCodeAt(w+2)]<<6|t[c.charCodeAt(w+3)],f[v++]=l>>16&255,f[v++]=l>>8&255,f[v++]=l&255;return y===2&&(l=t[c.charCodeAt(w)]<<2|t[c.charCodeAt(w+1)]>>4,f[v++]=l&255),y===1&&(l=t[c.charCodeAt(w)]<<10|t[c.charCodeAt(w+1)]<<4|t[c.charCodeAt(w+2)]>>2,f[v++]=l>>8&255,f[v++]=l&255),f}function b(c){return e[c>>18&63]+e[c>>12&63]+e[c>>6&63]+e[c&63]}function x(c,l,p){for(var d,y=[],f=l;f<p;f+=3)d=(c[f]<<16&16711680)+(c[f+1]<<8&65280)+(c[f+2]&255),y.push(b(d));return y.join("")}function k(c){for(var l,p=c.length,d=p%3,y=[],f=16383,v=0,T=p-d;v<T;v+=f)y.push(x(c,v,v+f>T?T:v+f));return d===1?(l=c[p-1],y.push(e[l>>2]+e[l<<4&63]+"==")):d===2&&(l=(c[p-2]<<8)+c[p-1],y.push(e[l>>10]+e[l>>4&63]+e[l<<2&63]+"=")),y.join("")}return F}var ge=pe();const de=ee(ge);var fe=Object.defineProperty,be=(e,t,r)=>t in e?fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,me=(e,t,r)=>(be(e,t+"",r),r);function ve(e,t){let r=Array.from({length:e.length},(s,i)=>({start:i,end:i+1}));for(;r.length>1;){let s=null;for(let i=0;i<r.length-1;i++){const a=e.slice(r[i].start,r[i+1].end),h=t.get(a.join(","));h!=null&&(s==null||h<s[0])&&(s=[h,i])}if(s!=null){const i=s[1];r[i]={start:r[i].start,end:r[i+1].end},r.splice(i+1,1)}else break}return r}function ye(e,t){return e.length===1?[t.get(e.join(","))]:ve(e,t).map(r=>t.get(e.slice(r.start,r.end).join(","))).filter(r=>r!=null)}function xe(e){return e.replace(/[\\^$*+?.()|[\]{}]/g,"\\$&")}var R=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;const r=e.bpe_ranks.split(`
2
+ `).filter(Boolean).reduce((s,i)=>{const[a,h,...n]=i.split(" "),g=Number.parseInt(h,10);return n.forEach((u,b)=>s[u]=g+b),s},{});for(const[s,i]of Object.entries(r)){const a=de.toByteArray(s);this.rankMap.set(a.join(","),i),this.textMap.set(i,a)}this.specialTokens={...e.special_tokens,...t},this.inverseSpecialTokens=Object.entries(this.specialTokens).reduce((s,[i,a])=>(s[a]=this.textEncoder.encode(i),s),{})}encode(e,t=[],r="all"){const s=new RegExp(this.patStr,"ug"),i=R.specialTokenRegex(Object.keys(this.specialTokens)),a=[],h=new Set(t==="all"?Object.keys(this.specialTokens):t),n=new Set(r==="all"?Object.keys(this.specialTokens).filter(u=>!h.has(u)):r);if(n.size>0){const u=R.specialTokenRegex([...n]),b=e.match(u);if(b!=null)throw new Error(`The text contains a special token that is not allowed: ${b[0]}`)}let g=0;for(;;){let u=null,b=g;for(;i.lastIndex=b,u=i.exec(e),!(u==null||h.has(u[0]));)b=u.index+1;const x=u?.index??e.length;for(const c of e.substring(g,x).matchAll(s)){const l=this.textEncoder.encode(c[0]),p=this.rankMap.get(l.join(","));if(p!=null){a.push(p);continue}a.push(...ye(l,this.rankMap))}if(u==null)break;let k=this.specialTokens[u[0]];a.push(k),g=u.index+u[0].length}return a}decode(e){const t=[];let r=0;for(let a=0;a<e.length;++a){const h=e[a],n=this.textMap.get(h)??this.inverseSpecialTokens[h];n!=null&&(t.push(n),r+=n.length)}const s=new Uint8Array(r);let i=0;for(const a of t)s.set(a,i),i+=a.length;return this.textDecoder.decode(s)}},J=R;me(J,"specialTokenRegex",e=>new RegExp(e.map(t=>xe(t)).join("|"),"g"));function ke(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 new Error("Unknown model")}}var we={};C(we,{encodingForModel:()=>j,getEncoding:()=>K});const S={},_e=new L({});async function K(e){return e in S||(S[e]=_e.fetch(`https://tiktoken.pages.dev/js/${e}.json`).then(t=>t.json()).then(t=>new J(t)).catch(t=>{throw delete S[e],t})),await S[e]}async function j(e){return K(ke(e))}var Ae={};C(Ae,{BaseLangChain:()=>q,BaseLanguageModel:()=>Se,calculateMaxTokens:()=>Ce,getEmbeddingContextSize:()=>Te,getModelContextSize:()=>N,getModelNameForTiktoken:()=>B,isOpenAITool:()=>Fe});const B=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,Te=e=>{switch(e){case"text-embedding-ada-002":return 8191;default:return 2046}},N=e=>{switch(B(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 Fe(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)}const Ce=async({prompt:e,modelName:t})=>{let r;try{r=(await j(B(t))).encode(e).length}catch{console.warn("Failed to calculate number of tokens, falling back to approximate count"),r=Math.ceil(e.length/4)}return N(t)-r},Ee=()=>!1;var q=class extends P{verbose;callbacks;tags;metadata;get lc_attributes(){return{callbacks:void 0,verbose:void 0}}constructor(e){super(e),this.verbose=e.verbose??Ee(),this.callbacks=e.callbacks,this.tags=e.tags??[],this.metadata=e.metadata??{}}},Se=class extends q{get callKeys(){return["stop","timeout","signal","tags","metadata","callbacks"]}caller;cache;constructor({callbacks:e,callbackManager:t,...r}){const{cache:s,...i}=r;super({callbacks:e??t,...i}),typeof s=="object"?this.cache=s:s?this.cache=D.global():this.cache=void 0,this.caller=new L(r??{})}_encoding;async getNumTokens(e){let t;typeof e=="string"?t=e:t=e.map(s=>typeof s=="string"?s:s.type==="text"&&"text"in s?s.text:"").join("");let r=Math.ceil(t.length/4);if(!this._encoding)try{this._encoding=await j("modelName"in this?B(this.modelName):"gpt2")}catch(s){console.warn("Failed to calculate number of tokens, falling back to approximate count",s)}if(this._encoding)try{r=this._encoding.encode(t).length}catch(s){console.warn("Failed to calculate number of tokens, falling back to approximate count",s)}return r}static _convertInputToPromptValue(e){return typeof e=="string"?new O(e):Array.isArray(e)?new V(e.map(Q)):e}_identifyingParams(){return{}}_getSerializedCacheKeyParametersForCall({config:e,...t}){const r={...this._identifyingParams(),...t,_type:this._llmType(),_model:this._modelType()};return Object.entries(r).filter(([a,h])=>h!==void 0).map(([a,h])=>`${a}:${JSON.stringify(h)}`).sort().join(",")}serialize(){return{...this._identifyingParams(),_type:this._llmType(),_model:this._modelType()}}static async deserialize(e){throw new Error("Use .toJSON() instead")}get profile(){return{}}};export{q as B,te as a,se as b,Re as c,Fe as d,Se as e,ae as i};