@mcp-use/inspector 20.0.0-beta.3 → 20.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/{ChatTab-BS5Tlm2y.js → ChatTab-UQAPDRQG.js} +6 -6
- package/dist/cdn/{ConnectionSettingsForm-BFsZpwK4.js → ConnectionSettingsForm-DrY1p-NO.js} +1 -1
- package/dist/cdn/{ConnectionSettingsTab-DDk06dhT.js → ConnectionSettingsTab-B1cRD7hz.js} +1 -1
- package/dist/cdn/{MarkdownRenderer-_aYcof42.js → MarkdownRenderer-BoDJE8tP.js} +1 -1
- package/dist/cdn/{OAuthCallback-C4n2hqKU.js → OAuthCallback-C9AvCkOn.js} +1 -1
- package/dist/cdn/{PromptsTab-BajHFLa3.js → PromptsTab-CkAWyWVb.js} +1 -1
- package/dist/cdn/{ResourcesTab-BgeMlTdR.js → ResourcesTab-BtBKxd4c.js} +5 -5
- package/dist/cdn/{SamplingTab-CnJB229N.js → SamplingTab-Czp7Rmhz.js} +3 -3
- package/dist/cdn/{ToolsTab-ACLxPxR6.js → ToolsTab-Dm4vCB8D.js} +4 -4
- package/dist/cdn/{ViewPreview-DsPwZAwO.js → ViewPreview-CZvl_7x-.js} +4 -3
- package/dist/cdn/{WidgetWrapper-CwlpDv17.js → WidgetWrapper-DeiogRXV.js} +2 -2
- package/dist/cdn/{dist-B0eL32Gb.js → dist-3QLh0dt8.js} +3 -3
- package/dist/cdn/{index-browser-QDjRGsPo.js → index-browser-CIoYSwCt.js} +1 -1
- package/dist/cdn/inspector.js +5 -5
- package/dist/cdn/{react-Dn8PWXwP.js → react-0oJnFpBS.js} +593 -585
- package/dist/cdn/{telemetry-gHF-tMli.js → telemetry-BbhH1Z_E.js} +2 -2
- package/dist/cdn/{useConfig-BWcNCqwi.js → useConfig-BNpU7Atw.js} +2 -2
- package/dist/cdn/{useViewHostProps-DIIlz3tJ.js → useViewHostProps-ru80AnlT.js} +3 -2
- package/dist/cli.js +1 -1
- package/dist/client/hooks/useViewHostProps.d.ts +1 -1
- package/dist/client/hooks/useViewHostProps.d.ts.map +1 -1
- package/dist/client/index.js +2 -1
- package/dist/server/cdn-shell.js +2 -2
- package/dist/server/{chunk-W3PVQLOP.js → chunk-5L3HMC5B.js} +1 -1
- package/dist/server/{chunk-HGPQON3P.js → chunk-BEJGHVKM.js} +1 -1
- package/dist/server/{chunk-H7UBATRR.js → chunk-PGN3B3MQ.js} +1 -1
- package/dist/server/cli.js +2 -2
- package/dist/server/index.js +3 -3
- package/dist/server/middleware.js +3 -3
- package/dist/server/version.js +1 -1
- package/dist/web/assets/{ChatTab-C2FtENBM.js → ChatTab-B_5S87J1.js} +1 -1
- package/dist/web/assets/{ConnectionSettingsTab-B2sUjytG.js → ConnectionSettingsTab-XwjwKfsO.js} +1 -1
- package/dist/web/assets/{ElicitationTab-DwH08kDC.js → ElicitationTab-BD1tfmYR.js} +1 -1
- package/dist/web/assets/{ManufactOAuthCallback-Btu4B6u6.js → ManufactOAuthCallback-DD3qfIC3.js} +1 -1
- package/dist/web/assets/{MarkdownRenderer-DpIEt9wb.js → MarkdownRenderer-DH-7vpw0.js} +1 -1
- package/dist/web/assets/{NotificationsTab-CHB8mtSz.js → NotificationsTab-Cg48O6IH.js} +1 -1
- package/dist/web/assets/{OAuthCallback-DV4MgX4Z.js → OAuthCallback-4i2i3YpE.js} +1 -1
- package/dist/web/assets/{PromptsTab-0GIapoSs.js → PromptsTab-pAR6izrQ.js} +1 -1
- package/dist/web/assets/{ResourcesTab-N9xjsI_b.js → ResourcesTab-CgvfWrsU.js} +1 -1
- package/dist/web/assets/{SamplingTab-Dw0vpi4t.js → SamplingTab-DfIWMQFY.js} +1 -1
- package/dist/web/assets/{ServerMetadataTab-D-eQpLBF.js → ServerMetadataTab-Dsz8Qhyr.js} +1 -1
- package/dist/web/assets/{ToolsTab-BMrMJ5JV.js → ToolsTab-ln9w58BW.js} +1 -1
- package/dist/web/assets/{ViewPreview-N_cpEO0W.js → ViewPreview-CQ3G3VP0.js} +1 -1
- package/dist/web/assets/{WidgetWrapper-pDgNVq9y.js → WidgetWrapper-A-zaxY5s.js} +1 -1
- package/dist/web/assets/{checkbox-CrnXSMh2.js → checkbox-DZWS_U_i.js} +1 -1
- package/dist/web/assets/{dist-CeWSydFI.js → dist-DxRFPg-B.js} +4 -4
- package/dist/web/assets/{index-Cfuv_gb3.js → index-CoRK2C3M.js} +30 -13
- package/dist/web/assets/{shared-B1GD9FMm.js → shared-Dbc2GbRx.js} +1 -1
- package/dist/web/assets/{tabs-subtle-CG5cjC_N.js → tabs-subtle-CxMZqhP6.js} +1 -1
- package/dist/web/assets/{useConfig-BTp15Lle.js → useConfig-Cg-BtSHA.js} +1 -1
- package/dist/web/assets/{useViewHostProps-BQlaFC2Q.js → useViewHostProps-CMgPpdfy.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as e,t}from"./react-CU_d2d5K.js";import{t as n}from"./jsx-runtime-Cjj9sGSy.js";import{Et as r,_t as i,ct as a,st as o,xt as s}from"./index-
|
|
1
|
+
import{s as e,t}from"./react-CU_d2d5K.js";import{t as n}from"./jsx-runtime-Cjj9sGSy.js";import{Et as r,_t as i,ct as a,st as o,xt as s}from"./index-CoRK2C3M.js";import{t as c}from"./useViewHostProps-CMgPpdfy.js";var l=e(t(),1),u=n(),d=`preview-default`;function f(e){if(!e)return{};try{let t=atob(e),n=JSON.parse(t);if(n&&typeof n==`object`)return n}catch{}return{}}function p(e,t){let n=`ui://widget/${t}`,r=e.find(e=>e.uri.startsWith(`${n}.`)&&e.uri.endsWith(`.html`));return r?r.uri:e.find(e=>e.name===t)?.uri}function m(){let e=globalThis.__mcpUsePreviewBundle;if(!e||typeof e!=`object`)return;let t=e;if(typeof t.resourceUri==`string`)return t}function h(){(0,l.useEffect)(()=>{let e=document.documentElement,t=document.body,n=e.style.margin,r=t.style.margin,i=t.style.overflow;return e.style.margin=`0`,t.style.margin=`0`,t.style.overflow=`hidden`,()=>{e.style.margin=n,t.style.margin=r,t.style.overflow=i}},[])}function g(e,t){(0,l.useEffect)(()=>{let n=()=>{document.body.dataset.viewError=`runtime_error`};return e&&!t&&(document.body.dataset.viewError=`invalid_payload`),window.addEventListener(`error`,n),window.addEventListener(`unhandledrejection`,n),()=>{window.removeEventListener(`error`,n),window.removeEventListener(`unhandledrejection`,n),delete document.body.dataset.viewError}},[e,t])}function _(e){(0,l.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{await document.fonts.ready}catch{}t||(await new Promise(e=>requestAnimationFrame(()=>e(void 0))),await new Promise(e=>requestAnimationFrame(()=>e(void 0))),!t&&document.body.setAttribute(`data-view-ready`,`true`))})(),()=>{t=!0,document.body.removeAttribute(`data-view-ready`)}},[e])}function v(e,t){(0,l.useEffect)(()=>{if(!e)return;let n=!1,r,i,a=e=>{n||(e&&(document.body.dataset.viewX=String(Math.round(e.left)),document.body.dataset.viewY=String(Math.round(e.top)),document.body.dataset.viewWidth=String(Math.round(e.width)),document.body.dataset.viewHeight=String(Math.round(e.height))),document.body.setAttribute(`data-view-ready`,`true`))};return(async()=>{try{await document.fonts.ready}catch{}if(n||(await new Promise(e=>requestAnimationFrame(()=>e(void 0))),await new Promise(e=>requestAnimationFrame(()=>e(void 0))),n))return;let e=t.current?.querySelector(`iframe`);if(!e){a(null);return}let o=()=>{r&&clearTimeout(r),r=setTimeout(()=>{n||(i?.disconnect(),a(e.getBoundingClientRect()))},250)};i=new ResizeObserver(o),i.observe(e),o()})(),()=>{n=!0,r&&clearTimeout(r),i?.disconnect(),document.body.removeAttribute(`data-view-ready`),delete document.body.dataset.viewX,delete document.body.dataset.viewY,delete document.body.dataset.viewWidth,delete document.body.dataset.viewHeight}},[e,t])}function y({view:e,bundle:t,widthOverride:n}){let[r,i]=(0,l.useState)(!1),a=(0,l.useRef)(null);h(),v(r,a);let o=(0,l.useMemo)(()=>async e=>{if(e===t.resourceUri)return t.resourceContents;throw Error(`Resource ${e} not in screenshot bundle`)},[t]);return(0,u.jsx)(`div`,{ref:a,style:{width:`100vw`,height:`100vh`},children:(0,u.jsx)(s,{viewId:(0,l.useMemo)(()=>`preview-bundle-${e}-${Date.now().toString(36)}`,[e]),toolName:e,toolInput:t.toolInput,toolOutput:t.toolOutput,displayMode:`inline`,inlineMaxWidth:n,chromeless:!0,onReady:()=>i(!0),source:{kind:`live`,connection:{callTool:async()=>{throw Error(`Preview bundle mode has no server connection`)},readResource:o},resourceUri:t.resourceUri},cspMode:`permissive`,hostInfo:{name:`mcp-use-inspector`,version:`11.0.0`},mockOpenAiFileApis:!0})})}function b({view:e}){let[t]=a(),n=(0,l.useMemo)(()=>f(t.get(`props`)),[t]),o=(0,l.useMemo)(()=>t.get(`server`)||`${window.location.origin}${i()||`/`}`,[t]),m=(0,l.useMemo)(()=>{let e=t.get(`headers`);if(e)try{let t=JSON.parse(atob(e));if(t&&typeof t==`object`)return t}catch{}},[t]),{servers:g,addServer:v,storageLoaded:y}=r(),b=g.find(e=>e.id===d);(0,l.useEffect)(()=>{y&&v(d,{url:o,displayName:`Preview`,protocolNegotiation:`auto`,...m?{headers:m}:{}})},[y,o,m,v]);let x=b?.state===`ready`,S=b?.state===`failed`,C=(0,l.useMemo)(()=>{if(x)return p(b.resources,e)},[x,b?.resources,e]),w=(0,l.useMemo)(()=>`preview-${e}-${Date.now().toString(36)}`,[e]),T=(0,l.useMemo)(()=>async e=>{if(!b?.readResource)throw Error(`Server not ready`);return b.readResource(e)},[b]),[E,D]=(0,l.useState)(!1);_(E),h();let O=c({serverId:d,viewId:w,resourceUri:C??``,toolName:e,toolInput:n.toolInput,toolOutput:n.toolOutput,readResource:T,displayMode:`fullscreen`,chromeless:!0,onReady:()=>D(!0)});return S?(0,u.jsxs)(`div`,{style:{padding:16,fontFamily:`monospace`,color:`#b00`},children:[`Failed to connect to MCP server at `,o,`.`]}):!x||!C?x&&!C?(0,u.jsxs)(`div`,{style:{padding:16,fontFamily:`monospace`,color:`#b00`},children:[`View "`,e,`" not found on `,o,`.`]}):(0,u.jsx)(`div`,{style:{width:`100vw`,height:`100vh`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontFamily:`monospace`,color:`var(--muted-foreground, #888)`},children:`Loading…`}):(0,u.jsx)(`div`,{style:{width:`100vw`,height:`100vh`},children:O&&C?(0,u.jsx)(s,{viewId:w,toolName:e,toolInput:n.toolInput,toolOutput:n.toolOutput,displayMode:`fullscreen`,chromeless:!0,...O}):null})}function x(){let e=o(),[t]=a(),n=e.view??``,r=(0,l.useMemo)(()=>m(),[]),i=t.get(`protocol`)===`1`;g(i,r!==void 0);let s=(0,l.useMemo)(()=>{let e=t.get(`width`);if(!e)return;let n=parseInt(e,10);return Number.isFinite(n)&&n>0?n:void 0},[t]);return r?(0,u.jsx)(y,{view:n,bundle:r,widthOverride:s}):i?null:(0,u.jsx)(b,{view:n})}export{x as ViewPreview};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{s as e,t}from"./react-CU_d2d5K.js";import{G as n,K as r,Lr as i,a,n as o,r as s,sr as c,t as l}from"./input-CLYhA7PK.js";import{t as u}from"./jsx-runtime-Cjj9sGSy.js";import{t as d}from"./label-Cdim77Jw.js";import{a as f,i as p,n as m,r as h,t as g}from"./select-CJ57-Bor.js";import{t as _}from"./createLucideIcon-B3b8EU0b.js";import{t as v}from"./maximize-2-BTT9QQU9.js";import{t as y}from"./sparkles-2OAsc1aP.js";import{B as b,D as x,E as S,G as C,Gt as w,H as T,Ht as E,Jt as D,K as O,Kt as k,O as A,Qt as j,R as ee,U as te,V as M,Vt as ne,W as re,Wt as ie,Yt as ae,Zt as oe,_n as se,b as ce,c as N,d as P,f as F,gn as le,hn as ue,in as de,k as fe,l as pe,n as me,nn as he,ot as I,p as ge,tn as _e,w as ve,yt as L,z as ye}from"./index-Cfuv_gb3.js";import{a as R}from"./dist-CeWSydFI.js";import{t as z}from"./textarea-DLAmNVf_.js";import{a as be,i as xe,n as Se,o as Ce,r as we}from"./useViewHostProps-BQlaFC2Q.js";var Te=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Ee=_(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),De=_(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),Oe=_(`picture-in-picture`,[[`path`,{d:`M2 10h6V4`,key:`zwrco`}],[`path`,{d:`m2 4 6 6`,key:`ug085t`}],[`path`,{d:`M21 10V7a2 2 0 0 0-2-2h-7`,key:`git5jr`}],[`path`,{d:`M3 14v2a2 2 0 0 0 2 2h3`,key:`1f7fh3`}],[`rect`,{x:`12`,y:`14`,width:`10`,height:`7`,rx:`1`,key:`1wjs3o`}]]),ke=_(`pointer`,[[`path`,{d:`M22 14a8 8 0 0 1-8 8`,key:`56vcr3`}],[`path`,{d:`M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1agjmk`}],[`path`,{d:`M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1`,key:`wdbh2u`}],[`path`,{d:`M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10`,key:`1ibuk9`}],[`path`,{d:`M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`g6ys72`}]]),Ae=_(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),je=_(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Me=_(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),Ne=_(`square-dashed-mouse-pointer`,[[`path`,{d:`M12.034 12.681a.498.498 0 0 1 .647-.647l9 3.5a.5.5 0 0 1-.033.943l-3.444 1.068a1 1 0 0 0-.66.66l-1.067 3.443a.5.5 0 0 1-.943.033z`,key:`xwnzip`}],[`path`,{d:`M5 3a2 2 0 0 0-2 2`,key:`y57alp`}],[`path`,{d:`M19 3a2 2 0 0 1 2 2`,key:`18rm91`}],[`path`,{d:`M5 21a2 2 0 0 1-2-2`,key:`sbafld`}],[`path`,{d:`M9 3h1`,key:`1yesri`}],[`path`,{d:`M9 21h2`,key:`1qve2z`}],[`path`,{d:`M14 3h1`,key:`1ec4yj`}],[`path`,{d:`M3 9v1`,key:`1r0deq`}],[`path`,{d:`M21 9v2`,key:`p14lih`}],[`path`,{d:`M3 14v1`,key:`vnatye`}]]),Pe=_(`tablet`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]),B=_(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),Fe=_(`trash`,[[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),V=e(t(),1),Ie=[{value:`en-US`,label:`English (US)`},{value:`en-GB`,label:`English (UK)`},{value:`en-CA`,label:`English (Canada)`},{value:`en-AU`,label:`English (Australia)`},{value:`en-IN`,label:`English (India)`},{value:`es-ES`,label:`Spanish (Spain)`},{value:`es-MX`,label:`Spanish (Mexico)`},{value:`es-AR`,label:`Spanish (Argentina)`},{value:`es-CO`,label:`Spanish (Colombia)`},{value:`fr-FR`,label:`French (France)`},{value:`fr-CA`,label:`French (Canada)`},{value:`fr-BE`,label:`French (Belgium)`},{value:`fr-CH`,label:`French (Switzerland)`},{value:`de-DE`,label:`German (Germany)`},{value:`de-AT`,label:`German (Austria)`},{value:`de-CH`,label:`German (Switzerland)`},{value:`pt-BR`,label:`Portuguese (Brazil)`},{value:`pt-PT`,label:`Portuguese (Portugal)`},{value:`zh-CN`,label:`Chinese (Simplified, China)`},{value:`zh-TW`,label:`Chinese (Traditional, Taiwan)`},{value:`zh-HK`,label:`Chinese (Traditional, Hong Kong)`},{value:`ja-JP`,label:`Japanese (Japan)`},{value:`ko-KR`,label:`Korean (Korea)`},{value:`ar-SA`,label:`Arabic (Saudi Arabia)`},{value:`ar-EG`,label:`Arabic (Egypt)`},{value:`hi-IN`,label:`Hindi (India)`},{value:`ru-RU`,label:`Russian (Russia)`},{value:`it-IT`,label:`Italian (Italy)`},{value:`nl-NL`,label:`Dutch (Netherlands)`},{value:`nl-BE`,label:`Dutch (Belgium)`},{value:`pl-PL`,label:`Polish (Poland)`},{value:`sv-SE`,label:`Swedish (Sweden)`},{value:`no-NO`,label:`Norwegian (Norway)`},{value:`da-DK`,label:`Danish (Denmark)`},{value:`fi-FI`,label:`Finnish (Finland)`},{value:`tr-TR`,label:`Turkish (Turkey)`},{value:`el-GR`,label:`Greek (Greece)`},{value:`cs-CZ`,label:`Czech (Czech Republic)`},{value:`hu-HU`,label:`Hungarian (Hungary)`},{value:`ro-RO`,label:`Romanian (Romania)`},{value:`th-TH`,label:`Thai (Thailand)`},{value:`vi-VN`,label:`Vietnamese (Vietnam)`},{value:`id-ID`,label:`Indonesian (Indonesia)`},{value:`ms-MY`,label:`Malay (Malaysia)`},{value:`tl-PH`,label:`Tagalog (Philippines)`},{value:`he-IL`,label:`Hebrew (Israel)`},{value:`uk-UA`,label:`Ukrainian (Ukraine)`},{value:`bg-BG`,label:`Bulgarian (Bulgaria)`},{value:`hr-HR`,label:`Croatian (Croatia)`},{value:`sk-SK`,label:`Slovak (Slovakia)`},{value:`sl-SI`,label:`Slovenian (Slovenia)`},{value:`sr-RS`,label:`Serbian (Serbia)`},{value:`bn-BD`,label:`Bengali (Bangladesh)`},{value:`ta-IN`,label:`Tamil (India)`},{value:`te-IN`,label:`Telugu (India)`},{value:`mr-IN`,label:`Marathi (India)`},{value:`ur-PK`,label:`Urdu (Pakistan)`},{value:`fa-IR`,label:`Persian (Iran)`},{value:`sw-KE`,label:`Swahili (Kenya)`}];function Le(){return Intl.supportedValuesOf(`timeZone`).map(e=>({value:e,label:e.replace(/_/g,` `)}))}var Re=Le(),H=e=>`mcp-inspector-resource-props-${e}`;function ze(e){let[t,n]=(0,V.useState)([]),[r,i]=(0,V.useState)(null);return(0,V.useEffect)(()=>{(()=>{try{let t=H(e),r=localStorage.getItem(t);if(r){let e=JSON.parse(r);n(e.presets||[]),i(e.activePresetId||null)}else n([]),i(null)}catch(e){console.error(`[useResourceProps] Failed to load presets:`,e),n([]),i(null)}})()},[e]),(0,V.useEffect)(()=>{let n=H(e),i={presets:t,activePresetId:r};localStorage.setItem(n,JSON.stringify(i))},[e,t,r]),{presets:t,activePresetId:r,savePreset:(0,V.useCallback)(e=>{n(t=>{let n=t.findIndex(t=>t.id===e.id),r;return n>=0?(r=[...t],r[n]=e):r=[...t,e],r})},[]),deletePreset:(0,V.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e)),i(t=>t===e?null:t)},[]),setActivePreset:(0,V.useCallback)(e=>{i(e)},[]),getActiveProps:(0,V.useCallback)(()=>r&&t.find(e=>e.id===r)?.props||null,[r,t])}}function U(e={}){let{enabled:t=!0,maxLogs:n=1e3,proxyToPageConsole:r=!1}=e,[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(0),l=(0,V.useCallback)(e=>{if(!t)return;let i={...e,id:`log-${++c.current}-${Date.now()}`};if(a(e=>[...e,i].slice(-n)),r){let t=`[WIDGET CONSOLE]`,n=e.args.map(e=>{if(typeof e==`object`&&e)try{return JSON.stringify(e,null,2)}catch{return String(e)}return e});switch(e.level){case`error`:console.error(t,...n);break;case`warn`:console.warn(t,...n);break;case`info`:console.info(t,...n);break;case`debug`:console.debug(t,...n);break;case`trace`:console.trace(t,...n);break;default:console.log(t,...n)}}},[t,n,r]),u=(0,V.useCallback)(()=>{a([]),c.current=0},[]);return(0,V.useEffect)(()=>{if(!t)return;let e=e=>{e.data&&e.data.type===`iframe-console-log`&&e.data.level&&Array.isArray(e.data.args)&&l({level:e.data.level,args:e.data.args,timestamp:e.data.timestamp||new Date().toISOString(),url:e.data.url})};return window.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e)}},[t,l]),(0,V.useEffect)(()=>{if(t)return Ce.subscribe(l)},[t,l]),{logs:i,addLog:l,clearLogs:u,isOpen:o,setIsOpen:s}}var W=u(),Be=200,Ve=.9;function G(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`object`)try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function K(e){if(e.length===0)return[];let t=e[0];if(typeof t!=`string`||!/%[oOdisfc]/.test(t))return e.map(G);let n=e.slice(1),r=0,i=``;for(let e=0;e<t.length;e++){let a=t[e];if(a===`%`&&e+1<t.length){let o=t[e+1],s=n[r++];switch(o){case`o`:case`O`:i+=G(s),e++;break;case`s`:i+=s===void 0?`undefined`:String(s),e++;break;case`d`:case`i`:i+=String(Number.parseInt(String(s??``),10)||0),e++;break;case`f`:i+=String(Number.parseFloat(String(s??``))||0),e++;break;case`c`:e++;break;default:i+=a}continue}i+=a}let a=[i.trim()];for(;r<n.length;)a.push(G(n[r++]));return a.filter(e=>e.length>0)}function He({level:e}){return(0,W.jsx)(`span`,{className:i(`px-1.5 py-0.5 text-[11px] font-mono font-semibold rounded-full text-white shrink-0`,{log:`bg-zinc-500`,info:`bg-blue-500`,warn:`bg-yellow-500`,error:`bg-red-500`,debug:`bg-purple-500`,trace:`bg-gray-500`}[e]),children:e.toUpperCase()})}function Ue({log:e}){let[t,n]=(0,V.useState)(!1),a=(0,V.useMemo)(()=>{try{return new Date(e.timestamp).toLocaleTimeString()}catch{return``}},[e.timestamp]),o=(0,V.useMemo)(()=>K(e.args),[e.args]),s=(0,V.useMemo)(()=>{if(o.length===0)return``;let e=o[0].replace(/\s*\n\s*/g,` `).trim();return(e.length>120?e.slice(0,120)+`…`:e)+(o.length>1?` +${o.length-1}`:``)},[o]),c=async e=>{e.stopPropagation();try{await L(o.join(`
|
|
1
|
+
import{s as e,t}from"./react-CU_d2d5K.js";import{G as n,K as r,Lr as i,a,n as o,r as s,sr as c,t as l}from"./input-CLYhA7PK.js";import{t as u}from"./jsx-runtime-Cjj9sGSy.js";import{t as d}from"./label-Cdim77Jw.js";import{a as f,i as p,n as m,r as h,t as g}from"./select-CJ57-Bor.js";import{t as _}from"./createLucideIcon-B3b8EU0b.js";import{t as v}from"./maximize-2-BTT9QQU9.js";import{t as y}from"./sparkles-2OAsc1aP.js";import{B as b,D as x,E as S,G as C,Gt as w,H as T,Ht as E,Jt as D,K as O,Kt as k,O as A,Qt as j,R as ee,U as te,V as M,Vt as ne,W as re,Wt as ie,Yt as ae,Zt as oe,_n as se,b as ce,c as N,d as P,f as F,gn as le,hn as ue,in as de,k as fe,l as pe,n as me,nn as he,ot as I,p as ge,tn as _e,w as ve,yt as L,z as ye}from"./index-CoRK2C3M.js";import{a as R}from"./dist-DxRFPg-B.js";import{t as z}from"./textarea-DLAmNVf_.js";import{a as be,i as xe,n as Se,o as Ce,r as we}from"./useViewHostProps-CMgPpdfy.js";var Te=_(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),Ee=_(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),De=_(`mouse-pointer-2`,[[`path`,{d:`M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z`,key:`edeuup`}]]),Oe=_(`picture-in-picture`,[[`path`,{d:`M2 10h6V4`,key:`zwrco`}],[`path`,{d:`m2 4 6 6`,key:`ug085t`}],[`path`,{d:`M21 10V7a2 2 0 0 0-2-2h-7`,key:`git5jr`}],[`path`,{d:`M3 14v2a2 2 0 0 0 2 2h3`,key:`1f7fh3`}],[`rect`,{x:`12`,y:`14`,width:`10`,height:`7`,rx:`1`,key:`1wjs3o`}]]),ke=_(`pointer`,[[`path`,{d:`M22 14a8 8 0 0 1-8 8`,key:`56vcr3`}],[`path`,{d:`M18 11v-1a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1agjmk`}],[`path`,{d:`M14 10V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1`,key:`wdbh2u`}],[`path`,{d:`M10 9.5V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v10`,key:`1ibuk9`}],[`path`,{d:`M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`g6ys72`}]]),Ae=_(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),je=_(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Me=_(`smartphone`,[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]),Ne=_(`square-dashed-mouse-pointer`,[[`path`,{d:`M12.034 12.681a.498.498 0 0 1 .647-.647l9 3.5a.5.5 0 0 1-.033.943l-3.444 1.068a1 1 0 0 0-.66.66l-1.067 3.443a.5.5 0 0 1-.943.033z`,key:`xwnzip`}],[`path`,{d:`M5 3a2 2 0 0 0-2 2`,key:`y57alp`}],[`path`,{d:`M19 3a2 2 0 0 1 2 2`,key:`18rm91`}],[`path`,{d:`M5 21a2 2 0 0 1-2-2`,key:`sbafld`}],[`path`,{d:`M9 3h1`,key:`1yesri`}],[`path`,{d:`M9 21h2`,key:`1qve2z`}],[`path`,{d:`M14 3h1`,key:`1ec4yj`}],[`path`,{d:`M3 9v1`,key:`1r0deq`}],[`path`,{d:`M21 9v2`,key:`p14lih`}],[`path`,{d:`M3 14v1`,key:`vnatye`}]]),Pe=_(`tablet`,[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]),B=_(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),Fe=_(`trash`,[[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),V=e(t(),1),Ie=[{value:`en-US`,label:`English (US)`},{value:`en-GB`,label:`English (UK)`},{value:`en-CA`,label:`English (Canada)`},{value:`en-AU`,label:`English (Australia)`},{value:`en-IN`,label:`English (India)`},{value:`es-ES`,label:`Spanish (Spain)`},{value:`es-MX`,label:`Spanish (Mexico)`},{value:`es-AR`,label:`Spanish (Argentina)`},{value:`es-CO`,label:`Spanish (Colombia)`},{value:`fr-FR`,label:`French (France)`},{value:`fr-CA`,label:`French (Canada)`},{value:`fr-BE`,label:`French (Belgium)`},{value:`fr-CH`,label:`French (Switzerland)`},{value:`de-DE`,label:`German (Germany)`},{value:`de-AT`,label:`German (Austria)`},{value:`de-CH`,label:`German (Switzerland)`},{value:`pt-BR`,label:`Portuguese (Brazil)`},{value:`pt-PT`,label:`Portuguese (Portugal)`},{value:`zh-CN`,label:`Chinese (Simplified, China)`},{value:`zh-TW`,label:`Chinese (Traditional, Taiwan)`},{value:`zh-HK`,label:`Chinese (Traditional, Hong Kong)`},{value:`ja-JP`,label:`Japanese (Japan)`},{value:`ko-KR`,label:`Korean (Korea)`},{value:`ar-SA`,label:`Arabic (Saudi Arabia)`},{value:`ar-EG`,label:`Arabic (Egypt)`},{value:`hi-IN`,label:`Hindi (India)`},{value:`ru-RU`,label:`Russian (Russia)`},{value:`it-IT`,label:`Italian (Italy)`},{value:`nl-NL`,label:`Dutch (Netherlands)`},{value:`nl-BE`,label:`Dutch (Belgium)`},{value:`pl-PL`,label:`Polish (Poland)`},{value:`sv-SE`,label:`Swedish (Sweden)`},{value:`no-NO`,label:`Norwegian (Norway)`},{value:`da-DK`,label:`Danish (Denmark)`},{value:`fi-FI`,label:`Finnish (Finland)`},{value:`tr-TR`,label:`Turkish (Turkey)`},{value:`el-GR`,label:`Greek (Greece)`},{value:`cs-CZ`,label:`Czech (Czech Republic)`},{value:`hu-HU`,label:`Hungarian (Hungary)`},{value:`ro-RO`,label:`Romanian (Romania)`},{value:`th-TH`,label:`Thai (Thailand)`},{value:`vi-VN`,label:`Vietnamese (Vietnam)`},{value:`id-ID`,label:`Indonesian (Indonesia)`},{value:`ms-MY`,label:`Malay (Malaysia)`},{value:`tl-PH`,label:`Tagalog (Philippines)`},{value:`he-IL`,label:`Hebrew (Israel)`},{value:`uk-UA`,label:`Ukrainian (Ukraine)`},{value:`bg-BG`,label:`Bulgarian (Bulgaria)`},{value:`hr-HR`,label:`Croatian (Croatia)`},{value:`sk-SK`,label:`Slovak (Slovakia)`},{value:`sl-SI`,label:`Slovenian (Slovenia)`},{value:`sr-RS`,label:`Serbian (Serbia)`},{value:`bn-BD`,label:`Bengali (Bangladesh)`},{value:`ta-IN`,label:`Tamil (India)`},{value:`te-IN`,label:`Telugu (India)`},{value:`mr-IN`,label:`Marathi (India)`},{value:`ur-PK`,label:`Urdu (Pakistan)`},{value:`fa-IR`,label:`Persian (Iran)`},{value:`sw-KE`,label:`Swahili (Kenya)`}];function Le(){return Intl.supportedValuesOf(`timeZone`).map(e=>({value:e,label:e.replace(/_/g,` `)}))}var Re=Le(),H=e=>`mcp-inspector-resource-props-${e}`;function ze(e){let[t,n]=(0,V.useState)([]),[r,i]=(0,V.useState)(null);return(0,V.useEffect)(()=>{(()=>{try{let t=H(e),r=localStorage.getItem(t);if(r){let e=JSON.parse(r);n(e.presets||[]),i(e.activePresetId||null)}else n([]),i(null)}catch(e){console.error(`[useResourceProps] Failed to load presets:`,e),n([]),i(null)}})()},[e]),(0,V.useEffect)(()=>{let n=H(e),i={presets:t,activePresetId:r};localStorage.setItem(n,JSON.stringify(i))},[e,t,r]),{presets:t,activePresetId:r,savePreset:(0,V.useCallback)(e=>{n(t=>{let n=t.findIndex(t=>t.id===e.id),r;return n>=0?(r=[...t],r[n]=e):r=[...t,e],r})},[]),deletePreset:(0,V.useCallback)(e=>{n(t=>t.filter(t=>t.id!==e)),i(t=>t===e?null:t)},[]),setActivePreset:(0,V.useCallback)(e=>{i(e)},[]),getActiveProps:(0,V.useCallback)(()=>r&&t.find(e=>e.id===r)?.props||null,[r,t])}}function U(e={}){let{enabled:t=!0,maxLogs:n=1e3,proxyToPageConsole:r=!1}=e,[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),c=(0,V.useRef)(0),l=(0,V.useCallback)(e=>{if(!t)return;let i={...e,id:`log-${++c.current}-${Date.now()}`};if(a(e=>[...e,i].slice(-n)),r){let t=`[WIDGET CONSOLE]`,n=e.args.map(e=>{if(typeof e==`object`&&e)try{return JSON.stringify(e,null,2)}catch{return String(e)}return e});switch(e.level){case`error`:console.error(t,...n);break;case`warn`:console.warn(t,...n);break;case`info`:console.info(t,...n);break;case`debug`:console.debug(t,...n);break;case`trace`:console.trace(t,...n);break;default:console.log(t,...n)}}},[t,n,r]),u=(0,V.useCallback)(()=>{a([]),c.current=0},[]);return(0,V.useEffect)(()=>{if(!t)return;let e=e=>{e.data&&e.data.type===`iframe-console-log`&&e.data.level&&Array.isArray(e.data.args)&&l({level:e.data.level,args:e.data.args,timestamp:e.data.timestamp||new Date().toISOString(),url:e.data.url})};return window.addEventListener(`message`,e),()=>{window.removeEventListener(`message`,e)}},[t,l]),(0,V.useEffect)(()=>{if(t)return Ce.subscribe(l)},[t,l]),{logs:i,addLog:l,clearLogs:u,isOpen:o,setIsOpen:s}}var W=u(),Be=200,Ve=.9;function G(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(typeof e==`string`)return e;if(typeof e==`object`)try{return JSON.stringify(e,null,2)}catch{return String(e)}return String(e)}function K(e){if(e.length===0)return[];let t=e[0];if(typeof t!=`string`||!/%[oOdisfc]/.test(t))return e.map(G);let n=e.slice(1),r=0,i=``;for(let e=0;e<t.length;e++){let a=t[e];if(a===`%`&&e+1<t.length){let o=t[e+1],s=n[r++];switch(o){case`o`:case`O`:i+=G(s),e++;break;case`s`:i+=s===void 0?`undefined`:String(s),e++;break;case`d`:case`i`:i+=String(Number.parseInt(String(s??``),10)||0),e++;break;case`f`:i+=String(Number.parseFloat(String(s??``))||0),e++;break;case`c`:e++;break;default:i+=a}continue}i+=a}let a=[i.trim()];for(;r<n.length;)a.push(G(n[r++]));return a.filter(e=>e.length>0)}function He({level:e}){return(0,W.jsx)(`span`,{className:i(`px-1.5 py-0.5 text-[11px] font-mono font-semibold rounded-full text-white shrink-0`,{log:`bg-zinc-500`,info:`bg-blue-500`,warn:`bg-yellow-500`,error:`bg-red-500`,debug:`bg-purple-500`,trace:`bg-gray-500`}[e]),children:e.toUpperCase()})}function Ue({log:e}){let[t,n]=(0,V.useState)(!1),a=(0,V.useMemo)(()=>{try{return new Date(e.timestamp).toLocaleTimeString()}catch{return``}},[e.timestamp]),o=(0,V.useMemo)(()=>K(e.args),[e.args]),s=(0,V.useMemo)(()=>{if(o.length===0)return``;let e=o[0].replace(/\s*\n\s*/g,` `).trim();return(e.length>120?e.slice(0,120)+`…`:e)+(o.length>1?` +${o.length-1}`:``)},[o]),c=async e=>{e.stopPropagation();try{await L(o.join(`
|
|
2
2
|
`)),I.success(`Copied to clipboard`)}catch{I.error(`Failed to copy`)}},l=i(`font-mono text-xs border-b border-zinc-200 dark:border-zinc-800`,e.level===`error`&&`bg-red-50/30 dark:bg-red-950/10`,e.level===`warn`&&`bg-yellow-50/30 dark:bg-yellow-950/10`),u=i(`cursor-pointer select-none`,e.level===`error`&&`hover:bg-red-50/50 dark:hover:bg-red-950/20`,e.level===`warn`&&`hover:bg-yellow-50/50 dark:hover:bg-yellow-950/20`,e.level!==`error`&&e.level!==`warn`&&`hover:bg-zinc-100/70 dark:hover:bg-zinc-800/40`);return(0,W.jsxs)(`div`,{className:i(l,`group`),children:[(0,W.jsxs)(`div`,{className:i(`flex items-center gap-2 px-2 py-1.5`,u),onClick:()=>n(e=>!e),children:[(0,W.jsx)(`span`,{className:`text-zinc-400 dark:text-zinc-500 shrink-0`,children:t?(0,W.jsx)(se,{className:`size-3`}):(0,W.jsx)(r,{className:`size-3`})}),(0,W.jsx)(He,{level:e.level}),(0,W.jsx)(`span`,{className:`text-zinc-500 dark:text-zinc-400 text-[10px] shrink-0`,children:a}),!t&&(0,W.jsx)(`span`,{className:i(`truncate text-[11px]`,e.level===`error`&&`text-red-700 dark:text-red-400`,e.level===`warn`&&`text-yellow-700 dark:text-yellow-400`,e.level!==`error`&&e.level!==`warn`&&`text-zinc-700 dark:text-zinc-300`),children:s}),t&&e.url&&(0,W.jsx)(`span`,{className:`text-zinc-400 dark:text-zinc-500 text-[10px] truncate flex-1`,children:(()=>{try{return new URL(e.url).pathname}catch{return e.url}})()}),t&&(0,W.jsx)(`button`,{onClick:c,"aria-label":`Copy log`,className:`ml-auto shrink-0 opacity-0 group-hover:opacity-100 transition-opacity p-0.5 rounded text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200`,children:(0,W.jsx)(ue,{className:`size-3`})})]}),t&&(0,W.jsx)(`div`,{className:`pl-8 pr-2 pb-2 select-text`,children:o.map((t,n)=>(0,W.jsx)(`pre`,{className:i(`whitespace-pre-wrap wrap-break-word text-[11px]`,e.level===`error`&&`text-red-700 dark:text-red-400`,e.level===`warn`&&`text-yellow-700 dark:text-yellow-400`,e.level!==`error`&&e.level!==`warn`&&`text-zinc-700 dark:text-zinc-300`),children:t},n))})]})}var q=`mcp-inspector-console-proxy-enabled`,We=`mcp-inspector-console-height`,Ge=[`log`,`info`,`warn`,`error`,`debug`,`trace`],Ke={log:`text-zinc-500`,info:`text-blue-500`,warn:`text-yellow-500`,error:`text-red-500`,debug:`text-purple-500`,trace:`text-gray-500`};function qe({iframeId:e,enabled:t=!0}){let[r,l]=(0,V.useState)(()=>{if(typeof window>`u`)return!0;try{return localStorage.getItem(q)===`true`}catch{return!0}}),[u,f]=(0,V.useState)(()=>{if(typeof window>`u`)return 400;try{let e=localStorage.getItem(We);return e?Math.max(Be,parseInt(e,10)):400}catch{return 400}}),p=(0,V.useRef)(!1),m=(0,V.useCallback)(e=>{e.preventDefault(),p.current=!0;let t=e=>{if(!p.current)return;let t=Math.floor(window.innerHeight*Ve);f(Math.min(t,Math.max(Be,window.innerHeight-e.clientY)))},n=()=>{p.current=!1,window.removeEventListener(`mousemove`,t),window.removeEventListener(`mouseup`,n)};window.addEventListener(`mousemove`,t),window.addEventListener(`mouseup`,n)},[]);(0,V.useEffect)(()=>{try{localStorage.setItem(We,String(u))}catch{}},[u]);let[h,g]=(0,V.useState)(`all`),[_,v]=(0,V.useState)(``),{logs:y,clearLogs:b,isOpen:x,setIsOpen:S}=U({enabled:t,proxyToPageConsole:r}),C=(0,V.useRef)(null);(0,V.useEffect)(()=>{try{localStorage.setItem(q,String(r))}catch{}},[r]);let w=(0,V.useMemo)(()=>{let e={log:0,info:0,warn:0,error:0,debug:0,trace:0};for(let t of y)e[t.level]++;return e},[y]),T=w.error,E=w.warn,D=w.log+w.info+w.debug+w.trace,O=y.length,A=(0,V.useMemo)(()=>T>0?`bg-red-500`:E>0?`bg-yellow-500`:`bg-zinc-500`,[T,E,D]),j=(0,V.useMemo)(()=>{let e=h===`all`?y:y.filter(e=>e.level===h),t=_.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=K(e.args).join(` `).toLowerCase(),r=(e.url??``).toLowerCase();return n.includes(t)||r.includes(t)})),e},[y,h,_]);return(0,V.useEffect)(()=>{x&&!_&&C.current&&(C.current.scrollTop=C.current.scrollHeight)},[j,x,_]),(0,W.jsxs)(N,{open:x,onOpenChange:S,children:[(0,W.jsx)(ge,{render:(0,W.jsxs)(o,{children:[(0,W.jsx)(a,{render:(0,W.jsxs)(c,{variant:`outline`,size:`sm`,className:`relative bg-white/90 dark:bg-zinc-900/90 backdrop-blur-sm shadow-sm hover:bg-white dark:hover:bg-zinc-900`,onClick:()=>S(!0),children:[(0,W.jsx)(B,{className:`size-4`}),O>0&&(0,W.jsx)(`span`,{className:i(`ml-2 px-1.5 py-0.5 text-xs rounded-full text-white font-semibold`,A),children:O})]}),nativeButton:!0}),(0,W.jsx)(s,{children:(0,W.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,W.jsxs)(`p`,{className:`font-semibold`,children:[O,` console `,O===1?`log`:`logs`]}),T>0&&(0,W.jsxs)(`p`,{className:`text-red-400`,children:[T,` error`,T===1?``:`s`]}),E>0&&(0,W.jsxs)(`p`,{className:`text-yellow-400`,children:[E,` warning`,E===1?``:`s`]}),D>0&&(0,W.jsxs)(`p`,{className:`text-zinc-400`,children:[D,` info`]})]})})]}),nativeButton:!1}),(0,W.jsxs)(pe,{side:`bottom`,className:`flex flex-col p-0 transition-none m-0 gap-0`,style:{height:u},children:[(0,W.jsx)(`div`,{className:`h-1.5 w-full shrink-0 cursor-ns-resize bg-zinc-200 dark:bg-zinc-700 hover:bg-zinc-300 dark:hover:bg-zinc-600 transition-colors`,onMouseDown:m}),(0,W.jsxs)(P,{className:`px-4 py-4 m-0 border-b border-zinc-200 dark:border-zinc-800 shrink-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(F,{className:`flex items-center gap-2`,children:[(0,W.jsx)(B,{className:`size-4`}),`Widget Console Logs`,y.length>0&&(0,W.jsxs)(`span`,{className:`text-sm font-normal text-zinc-500 dark:text-zinc-400`,children:[`(`,y.length,` `,y.length===1?`log`:`logs`,`)`]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4 pr-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(ve,{id:`proxy-console-toggle`,checked:r,onCheckedChange:l}),(0,W.jsx)(d,{htmlFor:`proxy-console-toggle`,className:`text-sm font-normal cursor-pointer`,children:`Proxy logs to page console`})]}),y.length>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(c,{variant:`ghost`,size:`sm`,onClick:async()=>{try{await L(j.map(e=>{let t=new Date(e.timestamp).toLocaleTimeString();return`[${e.level.toUpperCase()}] ${t}${e.url?` ${e.url}`:``}\n${K(e.args).join(`
|
|
3
3
|
`)}`}).join(`
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Lr as e}from"./input-CLYhA7PK.js";import{t}from"./jsx-runtime-Cjj9sGSy.js";import{g as n,h as r,vn as i}from"./index-
|
|
1
|
+
import{Lr as e}from"./input-CLYhA7PK.js";import{t}from"./jsx-runtime-Cjj9sGSy.js";import{g as n,h as r,vn as i}from"./index-CoRK2C3M.js";var a=t();function o({className:t,...o}){return(0,a.jsx)(n,{"data-slot":`checkbox`,className:e(`peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input shadow-xs transition-shadow outline-none group-has-disabled/field:opacity-50 after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary`,t),...o,children:(0,a.jsx)(r,{"data-slot":`checkbox-indicator`,className:`grid place-content-center text-current transition-none [&>svg]:size-3.5`,children:(0,a.jsx)(i,{})})})}export{o as t};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-
|
|
2
|
-
import{At as e,Mt as t,kt as n}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-CoRK2C3M.js","assets/react-CU_d2d5K.js","assets/input-CLYhA7PK.js","assets/createLucideIcon-B3b8EU0b.js","assets/jsx-runtime-Cjj9sGSy.js","assets/FormContext-DH2caWKO.js","assets/select-CJ57-Bor.js","assets/AnimatePresence-C5p0yiY1.js","assets/label-Cdim77Jw.js","assets/index-fBX3akc8.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{At as e,Mt as t,kt as n}from"./index-CoRK2C3M.js";var r=class{disallowedTools;connectorToolMap=new Map;constructor(e){this.disallowedTools=e??[]}static async createTools(e,t){let r=new this(t);(!e.activeSessions||Object.keys(e.activeSessions).length===0)&&(n.debug(`No active sessions found, creating new ones...`),await e.createAllSessions());let i=e.getAllActiveSessions(),a=Object.values(i).map(e=>e.connector);return r.createToolsFromConnectors(a)}async loadToolsForConnector(e){if(this.connectorToolMap.has(e)){let t=this.connectorToolMap.get(e);return n.debug(`Returning ${t.length} existing tools for connector`),t}let t=[];if(!await this.ensureConnectorInitialized(e))return[];for(let n of e.tools){let r=this.convertTool(n,e);r&&t.push(r)}return this.connectorToolMap.set(e,t),n.debug(`Loaded ${t.length} new tools for connector: ${t.map(e=>e?.name??String(e)).join(`, `)}`),t}async createToolsFromConnectors(e){let t=[];for(let n of e){let e=await this.loadToolsForConnector(n);t.push(...e)}return n.debug(`Available tools: ${t.length}`),t}async loadResourcesForConnector(e){let t=[];if(!await this.ensureConnectorInitialized(e))return[];try{let r=(await e.listAllResources())?.resources||[];if(this.convertResource)for(let n of r){let r=this.convertResource(n,e);r&&t.push(r)}n.debug(`Loaded ${t.length} new resources for connector: ${t.map(e=>e?.name??String(e)).join(`, `)}`)}catch(e){n.warn(`Error loading resources for connector: ${e}`)}return t}async loadPromptsForConnector(e){let t=[];if(!await this.ensureConnectorInitialized(e))return[];try{let r=(await e.listPrompts())?.prompts||[];if(this.convertPrompt)for(let n of r){let r=this.convertPrompt(n,e);r&&t.push(r)}n.debug(`Loaded ${t.length} new prompts for connector: ${t.map(e=>e?.name??String(e)).join(`, `)}`)}catch(e){n.warn(`Error loading prompts for connector: ${e}`)}return t}async createResourcesFromConnectors(e){let t=[];for(let n of e){let e=await this.loadResourcesForConnector(n);t.push(...e)}return n.debug(`Available resources: ${t.length}`),t}async createPromptsFromConnectors(e){let t=[];for(let n of e){let e=await this.loadPromptsForConnector(n);t.push(...e)}return n.debug(`Available prompts: ${t.length}`),t}checkConnectorInitialized(e){return!!(e.tools&&e.tools.length)}async ensureConnectorInitialized(e){if(!this.checkConnectorInitialized(e)){n.debug(`Connector doesn't have tools, initializing it`);try{return await e.initialize(),!0}catch(e){return n.error(`Error initializing connector: ${e}`),!1}}return!0}};function i(e){return e.replace(/[^A-Za-z0-9_]+/g,`_`).toLowerCase().replace(/^_+|_+$/g,``)}var a=class extends r{usedToolNames=new Set;handlers=new Map;constructor(e=[]){super(e)}async createToolsFromConnectors(e){return this.usedToolNames.clear(),this.handlers.clear(),super.createToolsFromConnectors(e)}createCallTool(){let e=this.handlers;return async(t,r)=>{let i=e.get(t);if(!i)throw Error(`Unknown tool: ${t}`);try{if(i.kind===`tool`)return await i.connector.callTool(i.mcpName,r);if(i.kind===`resource`){let e=i.resourceUri??i.mcpName;return await i.connector.readResource(e)}return await i.connector.getPrompt(i.mcpName,r)}catch(e){throw n.error(`Error executing native MCP tool ${t}: ${e}`),e}}}toProviderTools(e){return e.map(({name:e,description:t,inputSchema:n})=>({name:e,description:t,inputSchema:n}))}reserveName(e,t){if(!this.usedToolNames.has(e))return this.usedToolNames.add(e),e;if(t){let n=`${t}_${e}`;if(!this.usedToolNames.has(n))return this.usedToolNames.add(n),n;let r=2;for(;this.usedToolNames.has(`${n}_${r}`);)r++;let i=`${n}_${r}`;return this.usedToolNames.add(i),i}let n=2;for(;this.usedToolNames.has(`${e}_${n}`);)n++;let r=`${e}_${n}`;return this.usedToolNames.add(r),r}register(e,t){return this.handlers.set(e.name,t),e}convertTool(e,t){if(this.disallowedTools.includes(e.name))return null;let n=this.reserveName(e.name??`tool`),r={name:n,dispatchKey:n,description:e.description??``,inputSchema:e.inputSchema??{type:`object`,properties:{}}};return this.register(r,{connector:t,kind:`tool`,mcpName:e.name})}convertResource(e,t){let n=i(e.name||e.uri)||`resource`,r=this.reserveName(n,`resource`),a={name:r,dispatchKey:r,description:e.description||`Return the content of the resource located at URI ${e.uri}.`,inputSchema:{type:`object`,properties:{}}};return this.register(a,{connector:t,kind:`resource`,mcpName:e.uri,resourceUri:e.uri})}convertPrompt(e,t){let n={},r=[];if(e.arguments?.length)for(let t of e.arguments)n[t.name]={type:`string`,description:t.description},t.required!==!1&&r.push(t.name);let a=i(e.name||`prompt`)||`prompt`,o=this.reserveName(a,`prompt`),s={name:o,dispatchKey:o,description:e.description||``,inputSchema:{type:`object`,properties:n,...r.length>0?{required:r}:{}}};return this.register(s,{connector:t,kind:`prompt`,mcpName:e.name})}};function o(e){return{type:`text`,text:e}}function s(e,t){return{type:`image`,url:`data:${t};base64,${e}`,mimeType:t,data:e}}function c(e){if(!e||typeof e!=`object`)return!1;let t=e;return Array.isArray(t.content)?!0:`structuredContent`in t}function l(e){return typeof e==`object`&&!!e&&e.isError===!0}function u(e){if(!e||typeof e!=`object`)return null;switch(e.type){case`text`:{let t=e.text;return typeof t==`string`&&t.length>0?o(t):null}case`image`:{let t=e;if(typeof t.data!=`string`||!t.data)return null;let n=typeof t.mimeType==`string`&&t.mimeType?t.mimeType:`image/png`;return s(t.data,n)}case`audio`:{let t=e;return o(`[audio: ${typeof t.mimeType==`string`&&t.mimeType?t.mimeType:`audio/*`}, base64 omitted (${typeof t.data==`string`?t.data.length:0} chars)]`)}case`resource`:{let t=e.resource??{};return typeof t.text==`string`&&t.text.length>0?o(t.text):typeof t.blob==`string`&&typeof t.mimeType==`string`&&t.mimeType.startsWith(`image/`)?s(t.blob,t.mimeType):o(`[resource: ${typeof t.uri==`string`?t.uri:`<unknown>`} (${typeof t.mimeType==`string`?t.mimeType:`unknown`})]`)}case`resource_link`:{let t=e,n=typeof t.uri==`string`?t.uri:`<unknown>`;return o(`[resource_link${typeof t.name==`string`?` "${t.name}"`:``}: ${n}]`)}default:return o(`[unsupported tool content block: ${String(e.type)}]`)}}function ee(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let{_meta:t,...n}=e;return n}return e}function te(e){let t=ee(e);if(typeof t==`string`)return t.length>0?[o(t)]:[];if(c(t)){let e=t,n=[];if(Array.isArray(e.content))for(let t of e.content){let e=u(t);e&&n.push(e)}if(e.structuredContent!==void 0)try{n.push(o(`structuredContent: ${JSON.stringify(e.structuredContent)}`))}catch{}return e.isError&&n.unshift(o(`[tool reported isError=true]`)),n}try{return[o(JSON.stringify(t))]}catch{return[o(String(t))]}}function ne(e){return e.length===0?``:e.every(e=>e.type===`text`)?e.map(e=>e.text).join(`
|
|
3
3
|
`):null}function d(e){let t=te(e),n=ne(t);return n===null?t:n}function f(e){if(typeof e==`string`)return{text:e,imageParts:[],isString:!0};let t=[],n=[];for(let r of e)r.type===`text`?r.text&&t.push(r.text):r.type===`image`&&n.push(r);return{text:t.join(`
|
|
4
4
|
`),imageParts:n,isString:!1}}function p(e,t){return`(Tool "${e??`<tool>`}" returned the following image${t===1?``:`s`}:)`}function m(e){let t=typeof e.content==`string`?e.content:Array.isArray(e.content)?e.content.map(e=>e?.text??``).join(`
|
|
5
5
|
`):JSON.stringify(e.content??``);return t.trim()?t.trim():e.parts?.length?e.parts.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(``).trim():``}function re(e){let t=[];return e.forEach((e,n)=>{if(e.role===`user`){let n=m(e)||`[no content]`;if(e.attachments?.length){let r=[{type:`text`,text:n}];for(let t of e.attachments)t.type===`image`&&r.push({type:`image`,url:`data:${t.mimeType};base64,${t.data}`,mimeType:t.mimeType,data:t.data});t.push({role:`user`,content:r})}else t.push({role:`user`,content:n});return}let r=(e.parts??[]).filter(e=>e.type===`tool-invocation`&&e.toolInvocation&&e.toolInvocation.result!==void 0);if(r.length===0){let n=m(e)||`[no content]`;t.push({role:`assistant`,content:n});return}let i=m(e),a=r.map((e,t)=>({id:`call_${n}_${t}_${e.toolInvocation.toolName}`,name:e.toolInvocation.toolName,args:e.toolInvocation.args}));t.push({role:`assistant`,content:i,toolCalls:a}),r.forEach((e,r)=>{let i=e.toolInvocation.result;t.push({role:`tool`,content:d(i),toolCallId:`call_${n}_${r}_${e.toolInvocation.toolName}`,toolName:e.toolInvocation.toolName,toolResult:i,toolIsError:l(i)})})}),t}function ie(e){let t=[],n=[];for(let r of e)if(r.role===`system`){if(typeof r.content==`string`)t.push(r.content);else if(Array.isArray(r.content))for(let e of r.content)e.type===`text`&&t.push(e.text)}else n.push(r);return{system:t.length>0?t.join(`
|
|
@@ -13,9 +13,9 @@ import{At as e,Mt as t,kt as n}from"./index-Cfuv_gb3.js";var r=class{disallowedT
|
|
|
13
13
|
`);i=o.pop()??``;for(let e of o){let t=e.trim();if(t)try{yield JSON.parse(t)}catch{}}}let e=i.trim();if(e)try{yield JSON.parse(e)}catch{}}finally{n.releaseLock()}}var Ce=`http://localhost:11434`;function E(e){let t=(e||`http://localhost:11434`).trim(),n=t.length;for(;n>0&&t.charCodeAt(n-1)===47;)n--;let r=t.slice(0,n);return r.endsWith(`/api`)?r.slice(0,-4):r}function D(e,t){return`${E(e)}${t}`}var we=class extends Error{constructor(e){super("Could not reach Ollama. If it's running, allow this origin by starting Ollama with `OLLAMA_ORIGINS=*` (or your inspector origin) and try again."),this.name=`OllamaCorsError`,this.cause=e}};function Te(e){let t=[];for(let n of e){if(n.type!==`image`)continue;if(n.data){t.push(n.data);continue}let e=h(n.url);e?.data&&t.push(e.data)}return t}function O(e){if(typeof e==`string`)return{content:e};let t=e.filter(e=>e.type===`text`).map(e=>e.text).join(``),n=Te(e);return{content:t,...n.length>0?{images:n}:{}}}function Ee(e){return e.map(e=>e.role===`tool`?{role:`tool`,tool_name:e.toolName,content:typeof e.content==`string`?e.content:JSON.stringify(e.toolResult??e.content)}:e.role===`assistant`?{role:`assistant`,...typeof e.content==`string`?{content:e.content}:O(e.content),...e.toolCalls?.length?{tool_calls:e.toolCalls.map((e,t)=>({type:`function`,function:{index:t,name:e.name,arguments:e.args}}))}:{}}:{role:e.role,...O(e.content)})}function k(e,t){let{config:n,messages:r,tools:i}=e,a={model:n.model,messages:Ee(r),stream:t},o={};return n.temperature!==void 0&&(o.temperature=n.temperature),n.maxTokens!==void 0&&(o.num_predict=n.maxTokens),Object.keys(o).length>0&&(a.options=o),i&&i.length>0&&(a.tools=i.map(e=>({type:`function`,function:{name:e.name,description:e.description,parameters:e.inputSchema}}))),a}function A(e){return{"Content-Type":`application/json`,...e.apiKey.trim()?{Authorization:`Bearer ${e.apiKey.trim()}`}:{}}}function j(e){return Array.isArray(e)?e.map(e=>{let t=e&&typeof e==`object`?e.function:void 0,n=typeof t?.name==`string`?t.name:``,r=t?.arguments;return{name:n,args:r&&typeof r==`object`?r:{}}}).filter(e=>e.name):[]}async function*De(e){let{config:t,signal:n}=e,r=await fetch(D(t.baseUrl,`/api/chat`),{method:`POST`,headers:A(t),body:JSON.stringify(k(e,!0)),signal:n});if(!r.ok||!r.body){let e=await r.text().catch(()=>``);throw Error(`Ollama request failed (${r.status} ${r.statusText}): ${e}`)}let i=!1,a;for await(let e of Se(r.body,n)){let t=e&&typeof e==`object`?e.message:void 0;if(typeof t?.content==`string`&&t.content.length>0&&(yield{type:`text-delta`,delta:t.content}),!i){let e=j(t?.tool_calls);if(e.length>0){for(let[t,n]of e.entries()){let e=`call_${t}_${n.name||`tool`}`;yield{type:`tool-call-start`,index:t,toolCallId:e,toolName:n.name};let r=JSON.stringify(n.args);r&&r!==`{}`&&(yield{type:`tool-call-args-delta`,index:t,toolCallId:e,toolName:n.name,argsDelta:r}),yield{type:`tool-call-ready`,index:t,toolCallId:e,toolName:n.name,args:n.args}}i=!0}}e&&typeof e==`object`&&e.error&&(yield{type:`error`,message:String(e.error)}),a=y(e)??a}a&&(yield{type:`usage`,usage:a}),yield{type:`done`}}async function Oe(e){let{config:t,signal:n}=e,r=await fetch(D(t.baseUrl,`/api/chat`),{method:`POST`,headers:A(t),body:JSON.stringify(k(e,!1)),signal:n});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`Ollama request failed (${r.status} ${r.statusText}): ${e}`)}let i=(await r.json())?.message??{};return{text:typeof i.content==`string`?i.content:``,toolCalls:j(i.tool_calls).map((e,t)=>({id:`call_${t}_${e.name||`tool`}`,name:e.name,args:e.args}))}}var M=class extends Error{status;body;constructor(e,t,n){super(t),this.name=`LlmRequestError`,this.status=e,this.body=n}};async function N(e){let t=await e.text().catch(()=>``),n=t;if(t)try{n=JSON.parse(t)}catch{}throw new M(e.status,`OpenAI request failed (${e.status} ${e.statusText}): ${t}`,n)}var ke=`https://api.openai.com/v1`;function P(e,t){return`${e.baseUrl??ke}${t}`}function F(e){let t={"Content-Type":`application/json`,...e.extraHeaders};return e.apiKey&&(t.Authorization=`Bearer ${e.apiKey}`),t}function Ae(e){return typeof e==`string`?e:e.map(e=>e.type===`text`?{type:`text`,text:e.text}:{type:`image_url`,image_url:{url:e.url}})}function I(e){let t=[];for(let n of e){if(n.role===`tool`){let{text:e,imageParts:r}=f(n.content),i=r.length>0?`[image content; see next message]`:`[no content]`;if(t.push({role:`tool`,tool_call_id:n.toolCallId,content:e||i}),r.length>0){let e=[{type:`text`,text:p(n.toolName,r.length)},...r.map(e=>({type:`image_url`,image_url:{url:e.url}}))];t.push({role:`user`,content:e})}continue}if(n.role===`assistant`){let e={role:`assistant`,content:typeof n.content==`string`&&n.content.length>0?n.content:null};n.toolCalls?.length&&(e.tool_calls=n.toolCalls.map(e=>({id:e.id,type:`function`,function:{name:e.name,arguments:JSON.stringify(e.args)}}))),t.push(e);continue}t.push({role:n.role,content:Ae(n.content)})}return t}async function*L(e){let{config:t,messages:n,tools:r,signal:i}=e,a={model:t.model,messages:I(n),stream:!0};t.provider===`openrouter`&&(a.stream_options={include_usage:!0}),t.temperature!==void 0&&(a.temperature=t.temperature),t.maxTokens!==void 0&&(a.max_tokens=t.maxTokens),r&&r.length>0&&(a.tools=r.map(e=>({type:`function`,function:{name:e.name,description:e.description,parameters:e.inputSchema}})));let o=P(t,`/chat/completions`),s=await fetch(o,{method:`POST`,headers:F(t),body:JSON.stringify(a),signal:i,...t.credentials?{credentials:t.credentials}:{}}),c=s.body;s.ok||await N(s),c||await N(s);let l=c,u=new Map;for await(let e of g(l,i)){if(!e.data||e.data===`[DONE]`)continue;let t;try{t=JSON.parse(e.data)}catch{continue}let n=y(t?.usage);n&&(yield{type:`usage`,usage:n});let r=t?.choices?.[0];if(!r)continue;let i=r.delta??{};if(typeof i.content==`string`&&i.content.length>0&&(yield{type:`text-delta`,delta:i.content}),Array.isArray(i.tool_calls))for(let e of i.tool_calls){let t=typeof e.index==`number`?e.index:0,n=u.get(t);n||(n={id:e.id??`call_${t}`,name:e.function?.name??``,argsJson:``,started:!1},u.set(t,n)),(e.id&&!n.id.startsWith(`call_`)||e.id)&&(n.id=e.id),e.function?.name&&(n.name=e.function.name),!n.started&&n.name&&(n.started=!0,yield{type:`tool-call-start`,index:t,toolCallId:n.id,toolName:n.name});let r=e.function?.arguments;typeof r==`string`&&r.length>0&&(n.argsJson+=r,n.started&&(yield{type:`tool-call-args-delta`,index:t,toolCallId:n.id,toolName:n.name,argsDelta:r}))}if(r.finish_reason){for(let[e,t]of u){let n={};if(t.argsJson)try{n=JSON.parse(t.argsJson)}catch{n={}}yield{type:`tool-call-ready`,index:e,toolCallId:t.id,toolName:t.name,args:n}}u.clear()}}yield{type:`done`}}async function R(e){let{config:t,messages:n,tools:r,signal:i}=e,a={model:t.model,messages:I(n)};t.temperature!==void 0&&(a.temperature=t.temperature),t.maxTokens!==void 0&&(a.max_tokens=t.maxTokens),r&&r.length>0&&(a.tools=r.map(e=>({type:`function`,function:{name:e.name,description:e.description,parameters:e.inputSchema}})));let o=P(t,`/chat/completions`),s=await fetch(o,{method:`POST`,headers:F(t),body:JSON.stringify(a),signal:i,...t.credentials?{credentials:t.credentials}:{}});s.ok||await N(s);let c=(await s.json())?.choices?.[0]?.message;return{text:typeof c?.content==`string`?c.content:``,toolCalls:Array.isArray(c?.tool_calls)?c.tool_calls.map(e=>{let t={};try{t=JSON.parse(e?.function?.arguments??`{}`)}catch{t={}}return{id:e.id,name:e.function?.name??``,args:t}}):[]}}function z(e){return{...e,config:{...e.config,baseUrl:`https://openrouter.ai/api/v1`,extraHeaders:{"HTTP-Referer":`https://inspector.mcp-use.com`,"X-Title":`mcp-use Inspector`}}}}function je(e){switch(e.config.provider){case`openai`:throw Error(`provider 'openai' uses the Responses API via OpenAIResponsesDriver, not streamChat`);case`openai-compatible`:return L(e);case`anthropic`:return ue(e);case`google`:return be(e);case`openrouter`:return L(z(e));case`ollama`:return De(e);default:throw Error(`Unsupported LLM provider: ${e.config.provider}`)}}function Me(e){switch(e.config.provider){case`openai`:throw Error(`provider 'openai' uses the Responses API via OpenAIResponsesDriver, not chat`);case`openai-compatible`:return R(e);case`anthropic`:return de(e);case`google`:return xe(e);case`openrouter`:return R(z(e));case`ollama`:return Oe(e);default:throw Error(`Unsupported LLM provider: ${e.config.provider}`)}}var Ne=`https://api.openai.com/v1`;function B(e,t){return`${(e.baseUrl??Ne).replace(/\/$/,``)}${t}`}function V(e){let t={"Content-Type":`application/json`,...e.extraHeaders};return e.apiKey&&(t.Authorization=`Bearer ${e.apiKey}`),t}async function H(e){let t=await e.text().catch(()=>``);return`OpenAI request failed (${e.status} ${e.statusText}): ${t}`}function Pe(e){return typeof e==`string`?e:e.map(e=>e.type===`text`?{type:`input_text`,text:e.text}:{type:`input_image`,image_url:e.url})}function U(e){let t=[],n=[];for(let r of e){if(r.role===`system`){let e=typeof r.content==`string`?r.content:r.content.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
14
14
|
`);e&&t.push(e);continue}if(r.role===`user`){n.push({role:`user`,content:Pe(r.content)});continue}if(r.role===`assistant`){typeof r.content==`string`&&r.content.length>0&&n.push({type:`message`,role:`assistant`,content:[{type:`output_text`,text:r.content}]});for(let e of r.toolCalls??[])n.push({type:`function_call`,call_id:e.id,name:e.name,arguments:JSON.stringify(e.args)});continue}if(r.role===`tool`){let{text:e,imageParts:t}=f(r.content),i=t.length>0?`[image content; see next message]`:`[no content]`;n.push({type:`function_call_output`,call_id:r.toolCallId,output:e||i}),t.length>0&&n.push({role:`user`,content:[{type:`input_text`,text:p(r.toolName,t.length)},...t.map(e=>({type:`input_image`,image_url:e.url}))]})}}return{instructions:t.length>0?t.join(`
|
|
15
15
|
|
|
16
|
-
`):void 0,input:n}}function Fe(e){return e.map(e=>({type:`function`,name:e.name,description:e.description,parameters:e.inputSchema,strict:!1}))}function W(e,t,n,r){let i=d(r);if(typeof i==`string`){e.push({type:`function_call_output`,call_id:t,output:i});return}let{text:a,imageParts:o}=f(i);e.push({type:`function_call_output`,call_id:t,output:a||`[image content; see next message]`}),o.length>0&&e.push({role:`user`,content:[{type:`input_text`,text:p(n,o.length)},...o.map(e=>({type:`input_image`,image_url:e.url}))]})}function G(e,t){let n={model:e.config.model,input:e.input,store:!1,include:[`reasoning.encrypted_content`],reasoning:{effort:e.config.reasoningEffort??`low`},stream:t};return e.instructions&&(n.instructions=e.instructions),e.tools&&e.tools.length>0&&(n.tools=Fe(e.tools)),e.config.maxTokens!==void 0&&(n.max_output_tokens=e.config.maxTokens),n}function K(e){let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;e.type===`function_call`&&(typeof e.call_id!=`string`||typeof e.name!=`string`||t.push({call_id:e.call_id,name:e.name,arguments:typeof e.arguments==`string`?e.arguments:`{}`}))}return t}function Ie(e){let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(e.type!==`message`||e.role!==`assistant`)continue;let r=e.content;if(Array.isArray(r))for(let e of r){if(!e||typeof e!=`object`)continue;let n=e;n.type===`output_text`&&typeof n.text==`string`&&t.push(n.text)}}return t.join(``)}function q(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}async function*J(e){let t=await fetch(B(e.config,`/responses`),{method:`POST`,headers:V(e.config),body:JSON.stringify(G(e,!0)),signal:e.signal});if(!t.ok||!t.body)throw Error(await H(t));let n=new Map,r=0,i=[];for await(let a of g(t.body,e.signal)){if(!a.data||a.data===`[DONE]`)continue;let e;try{e=JSON.parse(a.data)}catch{continue}let t=typeof e.type==`string`?e.type:a.event;if(t===`response.output_text.delta`){let t=e.delta;typeof t==`string`&&t.length>0&&(yield{type:`text-delta`,delta:t});continue}if(t===`response.output_item.added`){let t=e.item;if(t?.type===`function_call`){let e=typeof t.call_id==`string`?t.call_id:`call_${r}`,i=typeof t.name==`string`?t.name:``,a=r++;n.set(e,{index:a,name:i,argsJson:``,started:!0}),yield{type:`tool-call-start`,index:a,toolCallId:e,toolName:i}}continue}if(t===`response.function_call_arguments.delta`){let t=typeof e.call_id==`string`?e.call_id:``,r=typeof e.delta==`string`?e.delta:``,i=n.get(t);i&&r.length>0&&(i.argsJson+=r,yield{type:`tool-call-args-delta`,index:i.index,toolCallId:t,toolName:i.name,argsDelta:r});continue}if(t===`response.function_call_arguments.done`){let t=typeof e.call_id==`string`?e.call_id:``,r=typeof e.arguments==`string`?e.arguments:``,i=n.get(t);i&&(r&&(i.argsJson=r),yield{type:`tool-call-ready`,index:i.index,toolCallId:t,toolName:i.name,args:q(i.argsJson||r)});continue}if(t===`response.completed`){let t=e.response;t&&Array.isArray(t.output)&&(i=t.output);let n=y(t?.usage);n&&(yield{type:`usage`,usage:n});continue}if(t===`error`)return yield{type:`error`,message:typeof e.message==`string`?e.message:`OpenAI Responses stream error`},[]}return yield{type:`done`},i}async function Y(e){let t=await fetch(B(e.config,`/responses`),{method:`POST`,headers:V(e.config),body:JSON.stringify(G(e,!1)),signal:e.signal});if(!t.ok)throw Error(await H(t));let n=await t.json(),r=n.status;if(r!==`completed`&&r!==void 0)throw Error(`OpenAI response ended with status ${String(r)}`);let i=Array.isArray(n.output)?n.output:[],a=K(i);return{text:typeof n.output_text==`string`?n.output_text:Ie(i),output:i,toolCalls:a.map(e=>({id:e.call_id,name:e.name,args:q(e.arguments)}))}}var Le=class{constructor(e){this.config=e}managesToolLoop=!0;stream(e){return this.streamSingleTurn(e)}async complete(e){let{instructions:t,input:n}=U(e.messages),r=await Y({config:this.config,instructions:t,input:n,tools:e.tools,signal:e.signal});return{text:r.text,toolCalls:r.toolCalls}}async*streamToolLoop(e){let{instructions:t,input:n}=U(e.messages),r=[...n],i=e.maxSteps??10;for(let n=0;n<i;n++){if(e.signal?.aborted)return;let n=J({config:this.config,instructions:t,input:r,tools:e.tools,signal:e.signal}),i=[];for(;;){let e=await n.next();if(e.done){i=e.value??[];break}if(yield e.value,e.value.type===`error`)return}r.push(...i);let a=K(i);if(a.length===0)return;for(let t of a){if(e.signal?.aborted)return;let n={};try{n=JSON.parse(t.arguments)}catch{n={}}let i,a=!1;try{i=await e.callTool(t.name,n),a=l(i)}catch(e){a=!0,i={isError:!0,error:e instanceof Error?e.message:String(e)}}W(r,t.call_id,t.name,i),yield{type:`tool-result`,toolCallId:t.call_id,toolName:t.name,result:i,isError:a}}}}async runToolLoopNonStreaming(e){let{instructions:t,input:n}=U(e.messages),r=[...n],i=e.maxSteps??10,a=[],o=``;for(let n=0;n<i&&!e.signal?.aborted;n++){let n=await Y({config:this.config,instructions:t,input:r,tools:e.tools,signal:e.signal});if(r.push(...n.output),n.toolCalls.length===0){o=n.text;break}for(let t of n.toolCalls){let n;try{n=await e.callTool(t.name,t.args),l(n)}catch(e){n={isError:!0,error:e instanceof Error?e.message:String(e)}}a.push({toolName:t.name,args:t.args,result:n}),W(r,t.id,t.name,n)}}return{content:o,toolCalls:a}}async*streamSingleTurn(e){let{instructions:t,input:n}=U(e.messages),r=J({config:this.config,instructions:t,input:n,tools:e.tools,signal:e.signal});for(;;){let e=await r.next();if(e.done||(yield e.value,e.value.type===`error`))return}}};function X(e){return e.provider===`openai`?new Le(e):new Re(e)}var Re=class{constructor(e){this.config=e}stream(e){return je({config:this.config,messages:e.messages,tools:e.tools,signal:e.signal})}async complete(e){let t=await Me({config:this.config,messages:e.messages,tools:e.tools,signal:e.signal});return{text:t.text,toolCalls:t.toolCalls}}};async function*ze(e){if(e.driver.managesToolLoop&&e.driver.streamToolLoop){yield*e.driver.streamToolLoop(e);return}let{driver:t,tools:n,callTool:r,signal:i}=e,a=e.maxSteps??10,o=[...e.messages];for(let e=0;e<a;e++){if(i?.aborted)return;let e=[],a=``;try{for await(let r of t.stream({messages:o,tools:n,signal:i}))r.type===`text-delta`?a+=r.delta:r.type===`tool-call-ready`&&e.push({id:r.toolCallId,name:r.toolName,args:r.args}),yield r}catch(e){if(e instanceof M)throw e;yield{type:`error`,message:e instanceof Error?e.message:String(e)};return}if(e.length===0)return;o.push({role:`assistant`,content:a,toolCalls:e});for(let t of e){if(i?.aborted)return;let e,n=!1;try{e=await r(t.name,t.args),n=l(e)}catch(t){n=!0,e={isError:!0,error:t instanceof Error?t.message:String(t)}}o.push({role:`tool`,content:d(e),toolCallId:t.id,toolName:t.name,toolResult:e,toolIsError:n}),yield{type:`tool-result`,toolCallId:t.id,toolName:t.name,result:e,isError:n}}}}async function Be(e){if(e.driver.managesToolLoop&&e.driver.runToolLoopNonStreaming)return e.driver.runToolLoopNonStreaming(e);let{driver:t,tools:n,callTool:r,signal:i}=e,a=e.maxSteps??10,o=[...e.messages],s=[],c=``;for(let e=0;e<a&&!i?.aborted;e++){let{text:e,toolCalls:a}=await t.complete({messages:o,tools:n,signal:i});if(a.length===0){c=e;break}o.push({role:`assistant`,content:e,toolCalls:a});for(let e of a){let t,n=!1;try{t=await r(e.name,e.args),n=l(t)}catch(e){n=!0,t={isError:!0,error:e instanceof Error?e.message:String(e)}}s.push({toolName:e.name,args:e.args,result:t}),o.push({role:`tool`,content:d(t),toolCallId:e.id,toolName:e.name,toolResult:t,toolIsError:n})}}return{content:c,toolCalls:s}}async function*Z(e,t){yield*ze({driver:e,messages:t.messages,tools:t.tools,callTool:t.callTool,maxSteps:t.maxSteps,signal:t.signal})}async function*Ve(e,t){let n=``,r=null;for await(let i of Z(e,t))if(i.type===`text-delta`)n+=i.delta;else if(i.type===`tool-call-ready`)r={action:{tool:i.toolName,toolInput:i.args,log:`Calling tool ${i.toolName}`},observation:``},yield r;else if(i.type===`tool-result`&&r){let e=typeof i.result==`string`?i.result:JSON.stringify(i.result??``);yield{action:r.action,observation:e},r=null}else if(i.type===`error`)throw Error(i.message);return n}async function He(e,t){return(await Be({driver:e,messages:t.messages,tools:t.tools,callTool:t.callTool,maxSteps:t.maxSteps,signal:t.signal})).content}var Ue={openai:[`OPENAI_API_KEY`],anthropic:[`ANTHROPIC_API_KEY`],google:[`GOOGLE_API_KEY`,`GOOGLE_GENERATIVE_AI_API_KEY`],openrouter:[`OPENROUTER_API_KEY`],ollama:[],"openai-compatible":[`OPENAI_API_KEY`]};function We(e,t){if(t?.apiKey)return t.apiKey;let r=Ue[e]??[];if(typeof process<`u`)for(let t of r){let r={}[t];if(r)return n.debug(`Using API key from ${t} for ${e}`),r}if(e===`ollama`)return``;let i=r.length>0?r.join(` or `):`apiKey in llmConfig`;throw Error(`API key not found for provider '${e}'. Set ${i}.`)}function Q(e,t){let n=e.split(`/`);if(n.length<2)throw Error(`Invalid LLM string '${e}'. Expected 'provider/model'.`);let r=n[0].toLowerCase(),i=n.slice(1).join(`/`),a=[`openai`,`anthropic`,`google`,`openrouter`,`ollama`,`openai-compatible`];if(!a.includes(r))throw Error(`Unsupported provider '${r}'. Supported: ${a.join(`, `)}`);return{provider:r,model:i,apiKey:We(r,t),temperature:t?.temperature,maxTokens:t?.maxTokens,baseUrl:t?.baseUrl,extraHeaders:t?.extraHeaders,credentials:t?.credentials}}function Ge(e,t,n){return{provider:e,model:t,apiKey:We(e,n),temperature:n?.temperature,maxTokens:n?.maxTokens,baseUrl:n?.baseUrl,extraHeaders:n?.extraHeaders,credentials:n?.credentials}}var Ke=`2.0.0-beta.1`;function qe(){return Ke}function $(e,t,n,r,i,a){return typeof e==`object`&&e?{prompt:e.prompt,maxSteps:e.maxSteps,manageConnector:e.manageConnector,messages:e.messages,schema:e.schema,signal:e.signal}:{prompt:e,maxSteps:t,manageConnector:n,schema:i,signal:a}}var Je=`/api/v1/chats`,Ye=`/api/v1/chats/{chat_id}/execute`;function Xe(e,t,n,r,i){if(typeof e==`object`&&e){let t=e;return{query:t.prompt??``,maxSteps:t.maxSteps,manageConnector:t.manageConnector,externalHistory:t.externalHistory,outputSchema:t.schema}}return{query:e,maxSteps:t,manageConnector:n,externalHistory:r,outputSchema:i}}var Ze=class{agentId;apiKey;baseUrl;chatId=null;constructor(e){this.agentId=e.agentId,this.baseUrl=e.baseUrl??`https://cloud.manufact.com`;let t=e.apiKey??(typeof process<`u`&&{}.MCP_USE_API_KEY);if(!t)throw Error(`API key is required for remote execution. Please provide it as a parameter or set the MCP_USE_API_KEY environment variable. You can get an API key from https://cloud.manufact.com`);this.apiKey=t}pydanticToJsonSchema(e){return t(e)}parseStructuredResponse(e,t){let r;if(typeof e==`object`&&e)if(`result`in e){let t=e.result;r=typeof t==`object`&&t&&`result`in t?t.result:t}else r=e;else if(typeof e==`string`)try{r=JSON.parse(e)}catch{r={content:e}}else r=e;try{return t.parse(r)}catch(e){n.warn(`Failed to parse structured output: ${e}`);let i=t._def?.shape();if(i&&`content`in i)return t.parse({content:String(r)});throw e}}async createChatSession(){let e={title:`Remote Agent Session - ${this.agentId}`,agent_id:this.agentId,type:`agent_execution`},t={"Content-Type":`application/json`,"x-api-key":this.apiKey},r=`${this.baseUrl}${Je}`;n.debug(`\u{1F4DD} Creating chat session for agent ${this.agentId}`);try{let i=await fetch(r,{method:`POST`,headers:t,body:JSON.stringify(e)});if(!i.ok){let e=await i.text(),t=i.status;throw Error(t===404?`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`:`Failed to create chat session: ${t} - ${e}`)}let a=(await i.json()).id;return n.debug(`\u2705 Chat session created: ${a}`),a}catch(e){throw e instanceof Error?TypeError(`Failed to create chat session: ${e.message}`):Error(`Failed to create chat session: ${String(e)}`)}}async run(e,t,r,i,a){let{query:o,maxSteps:s,externalHistory:c,outputSchema:l}=Xe(e,t,r,i,a);c!==void 0&&n.warn(`External history is not yet supported for remote execution`);try{n.debug(`\u{1F310} Executing query on remote agent ${this.agentId}`),this.chatId===null&&(this.chatId=await this.createChatSession());let e=this.chatId,t={query:o,max_steps:s??10};l&&(t.output_schema=this.pydanticToJsonSchema(l),n.debug(`🔧 Using structured output with schema`));let r={"Content-Type":`application/json`,"x-api-key":this.apiKey},i=`${this.baseUrl}${Ye.replace(`{chat_id}`,e)}`;n.debug(`\u{1F680} Executing agent in chat ${e}`);let a=await fetch(i,{method:`POST`,headers:r,body:JSON.stringify(t),signal:AbortSignal.timeout(3e5)});if(!a.ok){let e=await a.text(),t=a.status;throw t===401?(n.error(`\u274C Authentication failed: ${e}`),Error(`Authentication failed: Invalid or missing API key. Please check your API key and ensure the MCP_USE_API_KEY environment variable is set correctly.`)):t===403?(n.error(`\u274C Access forbidden: ${e}`),Error(`Access denied: You don't have permission to execute agent '${this.agentId}'. Check if the agent exists and you have the necessary permissions.`)):t===404?(n.error(`\u274C Agent not found: ${e}`),Error(`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`)):t===422?(n.error(`\u274C Validation error: ${e}`),Error(`Request validation failed: ${e}. Please check your query parameters and output schema format.`)):t===500?(n.error(`\u274C Server error: ${e}`),Error(`Internal server error occurred during agent execution. Please try again later or contact support if the issue persists.`)):(n.error(`\u274C Remote execution failed with status ${t}: ${e}`),Error(`Remote agent execution failed: ${t} - ${e}`))}let c=await a.json();if(n.debug(`\u{1F527} Response: ${JSON.stringify(c)}`),n.debug(`✅ Remote execution completed successfully`),typeof c==`object`&&c){if(c.status===`error`||c.error!==null){let e=c.error??String(c);throw n.error(`\u274C Remote agent execution failed: ${e}`),Error(`Remote agent execution failed: ${e}`)}if(String(c).includes(`failed to initialize`))throw n.error(`\u274C Agent initialization failed: ${c}`),Error(`Agent initialization failed on remote server. This usually indicates:
|
|
16
|
+
`):void 0,input:n}}function Fe(e){return e.map(e=>({type:`function`,name:e.name,description:e.description,parameters:e.inputSchema,strict:!1}))}function W(e,t,n,r){let i=d(r);if(typeof i==`string`){e.push({type:`function_call_output`,call_id:t,output:i});return}let{text:a,imageParts:o}=f(i);e.push({type:`function_call_output`,call_id:t,output:a||`[image content; see next message]`}),o.length>0&&e.push({role:`user`,content:[{type:`input_text`,text:p(n,o.length)},...o.map(e=>({type:`input_image`,image_url:e.url}))]})}function G(e,t){let n={model:e.config.model,input:e.input,store:!1,include:[`reasoning.encrypted_content`],reasoning:{effort:e.config.reasoningEffort??`low`},stream:t};return e.instructions&&(n.instructions=e.instructions),e.tools&&e.tools.length>0&&(n.tools=Fe(e.tools)),e.config.maxTokens!==void 0&&(n.max_output_tokens=e.config.maxTokens),n}function K(e){let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;e.type===`function_call`&&(typeof e.call_id!=`string`||typeof e.name!=`string`||t.push({call_id:e.call_id,name:e.name,arguments:typeof e.arguments==`string`?e.arguments:`{}`}))}return t}function Ie(e){let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(e.type!==`message`||e.role!==`assistant`)continue;let r=e.content;if(Array.isArray(r))for(let e of r){if(!e||typeof e!=`object`)continue;let n=e;n.type===`output_text`&&typeof n.text==`string`&&t.push(n.text)}}return t.join(``)}function q(e){if(!e)return{};try{return JSON.parse(e)}catch{return{}}}async function*J(e){let t=await fetch(B(e.config,`/responses`),{method:`POST`,headers:V(e.config),body:JSON.stringify(G(e,!0)),signal:e.signal});if(!t.ok||!t.body)throw Error(await H(t));let n=new Map,r=0,i=[];for await(let a of g(t.body,e.signal)){if(!a.data||a.data===`[DONE]`)continue;let e;try{e=JSON.parse(a.data)}catch{continue}let t=typeof e.type==`string`?e.type:a.event;if(t===`response.output_text.delta`){let t=e.delta;typeof t==`string`&&t.length>0&&(yield{type:`text-delta`,delta:t});continue}if(t===`response.output_item.added`){let t=e.item;if(t?.type===`function_call`){let e=typeof t.call_id==`string`?t.call_id:`call_${r}`,i=typeof t.name==`string`?t.name:``,a=r++;n.set(e,{index:a,name:i,argsJson:``,started:!0}),yield{type:`tool-call-start`,index:a,toolCallId:e,toolName:i}}continue}if(t===`response.function_call_arguments.delta`){let t=typeof e.call_id==`string`?e.call_id:``,r=typeof e.delta==`string`?e.delta:``,i=n.get(t);i&&r.length>0&&(i.argsJson+=r,yield{type:`tool-call-args-delta`,index:i.index,toolCallId:t,toolName:i.name,argsDelta:r});continue}if(t===`response.function_call_arguments.done`){let t=typeof e.call_id==`string`?e.call_id:``,r=typeof e.arguments==`string`?e.arguments:``,i=n.get(t);i&&(r&&(i.argsJson=r),yield{type:`tool-call-ready`,index:i.index,toolCallId:t,toolName:i.name,args:q(i.argsJson||r)});continue}if(t===`response.completed`){let t=e.response;t&&Array.isArray(t.output)&&(i=t.output);let n=y(t?.usage);n&&(yield{type:`usage`,usage:n});continue}if(t===`error`)return yield{type:`error`,message:typeof e.message==`string`?e.message:`OpenAI Responses stream error`},[]}return yield{type:`done`},i}async function Y(e){let t=await fetch(B(e.config,`/responses`),{method:`POST`,headers:V(e.config),body:JSON.stringify(G(e,!1)),signal:e.signal});if(!t.ok)throw Error(await H(t));let n=await t.json(),r=n.status;if(r!==`completed`&&r!==void 0)throw Error(`OpenAI response ended with status ${String(r)}`);let i=Array.isArray(n.output)?n.output:[],a=K(i);return{text:typeof n.output_text==`string`?n.output_text:Ie(i),output:i,toolCalls:a.map(e=>({id:e.call_id,name:e.name,args:q(e.arguments)}))}}var Le=class{constructor(e){this.config=e}managesToolLoop=!0;stream(e){return this.streamSingleTurn(e)}async complete(e){let{instructions:t,input:n}=U(e.messages),r=await Y({config:this.config,instructions:t,input:n,tools:e.tools,signal:e.signal});return{text:r.text,toolCalls:r.toolCalls}}async*streamToolLoop(e){let{instructions:t,input:n}=U(e.messages),r=[...n],i=e.maxSteps??10;for(let n=0;n<i;n++){if(e.signal?.aborted)return;let n=J({config:this.config,instructions:t,input:r,tools:e.tools,signal:e.signal}),i=[];for(;;){let e=await n.next();if(e.done){i=e.value??[];break}if(yield e.value,e.value.type===`error`)return}r.push(...i);let a=K(i);if(a.length===0)return;for(let t of a){if(e.signal?.aborted)return;let n={};try{n=JSON.parse(t.arguments)}catch{n={}}let i,a=!1;try{i=await e.callTool(t.name,n),a=l(i)}catch(e){a=!0,i={isError:!0,error:e instanceof Error?e.message:String(e)}}W(r,t.call_id,t.name,i),yield{type:`tool-result`,toolCallId:t.call_id,toolName:t.name,result:i,isError:a}}}}async runToolLoopNonStreaming(e){let{instructions:t,input:n}=U(e.messages),r=[...n],i=e.maxSteps??10,a=[],o=``;for(let n=0;n<i&&!e.signal?.aborted;n++){let n=await Y({config:this.config,instructions:t,input:r,tools:e.tools,signal:e.signal});if(r.push(...n.output),n.toolCalls.length===0){o=n.text;break}for(let t of n.toolCalls){let n;try{n=await e.callTool(t.name,t.args),l(n)}catch(e){n={isError:!0,error:e instanceof Error?e.message:String(e)}}a.push({toolName:t.name,args:t.args,result:n}),W(r,t.id,t.name,n)}}return{content:o,toolCalls:a}}async*streamSingleTurn(e){let{instructions:t,input:n}=U(e.messages),r=J({config:this.config,instructions:t,input:n,tools:e.tools,signal:e.signal});for(;;){let e=await r.next();if(e.done||(yield e.value,e.value.type===`error`))return}}};function X(e){return e.provider===`openai`?new Le(e):new Re(e)}var Re=class{constructor(e){this.config=e}stream(e){return je({config:this.config,messages:e.messages,tools:e.tools,signal:e.signal})}async complete(e){let t=await Me({config:this.config,messages:e.messages,tools:e.tools,signal:e.signal});return{text:t.text,toolCalls:t.toolCalls}}};async function*ze(e){if(e.driver.managesToolLoop&&e.driver.streamToolLoop){yield*e.driver.streamToolLoop(e);return}let{driver:t,tools:n,callTool:r,signal:i}=e,a=e.maxSteps??10,o=[...e.messages];for(let e=0;e<a;e++){if(i?.aborted)return;let e=[],a=``;try{for await(let r of t.stream({messages:o,tools:n,signal:i}))r.type===`text-delta`?a+=r.delta:r.type===`tool-call-ready`&&e.push({id:r.toolCallId,name:r.toolName,args:r.args}),yield r}catch(e){if(e instanceof M)throw e;yield{type:`error`,message:e instanceof Error?e.message:String(e)};return}if(e.length===0)return;o.push({role:`assistant`,content:a,toolCalls:e});for(let t of e){if(i?.aborted)return;let e,n=!1;try{e=await r(t.name,t.args),n=l(e)}catch(t){n=!0,e={isError:!0,error:t instanceof Error?t.message:String(t)}}o.push({role:`tool`,content:d(e),toolCallId:t.id,toolName:t.name,toolResult:e,toolIsError:n}),yield{type:`tool-result`,toolCallId:t.id,toolName:t.name,result:e,isError:n}}}}async function Be(e){if(e.driver.managesToolLoop&&e.driver.runToolLoopNonStreaming)return e.driver.runToolLoopNonStreaming(e);let{driver:t,tools:n,callTool:r,signal:i}=e,a=e.maxSteps??10,o=[...e.messages],s=[],c=``;for(let e=0;e<a&&!i?.aborted;e++){let{text:e,toolCalls:a}=await t.complete({messages:o,tools:n,signal:i});if(a.length===0){c=e;break}o.push({role:`assistant`,content:e,toolCalls:a});for(let e of a){let t,n=!1;try{t=await r(e.name,e.args),n=l(t)}catch(e){n=!0,t={isError:!0,error:e instanceof Error?e.message:String(e)}}s.push({toolName:e.name,args:e.args,result:t}),o.push({role:`tool`,content:d(t),toolCallId:e.id,toolName:e.name,toolResult:t,toolIsError:n})}}return{content:c,toolCalls:s}}async function*Z(e,t){yield*ze({driver:e,messages:t.messages,tools:t.tools,callTool:t.callTool,maxSteps:t.maxSteps,signal:t.signal})}async function*Ve(e,t){let n=``,r=null;for await(let i of Z(e,t))if(i.type===`text-delta`)n+=i.delta;else if(i.type===`tool-call-ready`)r={action:{tool:i.toolName,toolInput:i.args,log:`Calling tool ${i.toolName}`},observation:``},yield r;else if(i.type===`tool-result`&&r){let e=typeof i.result==`string`?i.result:JSON.stringify(i.result??``);yield{action:r.action,observation:e},r=null}else if(i.type===`error`)throw Error(i.message);return n}async function He(e,t){return(await Be({driver:e,messages:t.messages,tools:t.tools,callTool:t.callTool,maxSteps:t.maxSteps,signal:t.signal})).content}var Ue={openai:[`OPENAI_API_KEY`],anthropic:[`ANTHROPIC_API_KEY`],google:[`GOOGLE_API_KEY`,`GOOGLE_GENERATIVE_AI_API_KEY`],openrouter:[`OPENROUTER_API_KEY`],ollama:[],"openai-compatible":[`OPENAI_API_KEY`]};function We(e,t){if(t?.apiKey)return t.apiKey;let r=Ue[e]??[];if(typeof process<`u`)for(let t of r){let r={}[t];if(r)return n.debug(`Using API key from ${t} for ${e}`),r}if(e===`ollama`)return``;let i=r.length>0?r.join(` or `):`apiKey in llmConfig`;throw Error(`API key not found for provider '${e}'. Set ${i}.`)}function Q(e,t){let n=e.split(`/`);if(n.length<2)throw Error(`Invalid LLM string '${e}'. Expected 'provider/model'.`);let r=n[0].toLowerCase(),i=n.slice(1).join(`/`),a=[`openai`,`anthropic`,`google`,`openrouter`,`ollama`,`openai-compatible`];if(!a.includes(r))throw Error(`Unsupported provider '${r}'. Supported: ${a.join(`, `)}`);return{provider:r,model:i,apiKey:We(r,t),temperature:t?.temperature,maxTokens:t?.maxTokens,baseUrl:t?.baseUrl,extraHeaders:t?.extraHeaders,credentials:t?.credentials}}function Ge(e,t,n){return{provider:e,model:t,apiKey:We(e,n),temperature:n?.temperature,maxTokens:n?.maxTokens,baseUrl:n?.baseUrl,extraHeaders:n?.extraHeaders,credentials:n?.credentials}}var Ke=`2.0.0-beta.2`;function qe(){return Ke}function $(e,t,n,r,i,a){return typeof e==`object`&&e?{prompt:e.prompt,maxSteps:e.maxSteps,manageConnector:e.manageConnector,messages:e.messages,schema:e.schema,signal:e.signal}:{prompt:e,maxSteps:t,manageConnector:n,schema:i,signal:a}}var Je=`/api/v1/chats`,Ye=`/api/v1/chats/{chat_id}/execute`;function Xe(e,t,n,r,i){if(typeof e==`object`&&e){let t=e;return{query:t.prompt??``,maxSteps:t.maxSteps,manageConnector:t.manageConnector,externalHistory:t.externalHistory,outputSchema:t.schema}}return{query:e,maxSteps:t,manageConnector:n,externalHistory:r,outputSchema:i}}var Ze=class{agentId;apiKey;baseUrl;chatId=null;constructor(e){this.agentId=e.agentId,this.baseUrl=e.baseUrl??`https://cloud.manufact.com`;let t=e.apiKey??(typeof process<`u`&&{}.MCP_USE_API_KEY);if(!t)throw Error(`API key is required for remote execution. Please provide it as a parameter or set the MCP_USE_API_KEY environment variable. You can get an API key from https://cloud.manufact.com`);this.apiKey=t}pydanticToJsonSchema(e){return t(e)}parseStructuredResponse(e,t){let r;if(typeof e==`object`&&e)if(`result`in e){let t=e.result;r=typeof t==`object`&&t&&`result`in t?t.result:t}else r=e;else if(typeof e==`string`)try{r=JSON.parse(e)}catch{r={content:e}}else r=e;try{return t.parse(r)}catch(e){n.warn(`Failed to parse structured output: ${e}`);let i=t._def?.shape();if(i&&`content`in i)return t.parse({content:String(r)});throw e}}async createChatSession(){let e={title:`Remote Agent Session - ${this.agentId}`,agent_id:this.agentId,type:`agent_execution`},t={"Content-Type":`application/json`,"x-api-key":this.apiKey},r=`${this.baseUrl}${Je}`;n.debug(`\u{1F4DD} Creating chat session for agent ${this.agentId}`);try{let i=await fetch(r,{method:`POST`,headers:t,body:JSON.stringify(e)});if(!i.ok){let e=await i.text(),t=i.status;throw Error(t===404?`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`:`Failed to create chat session: ${t} - ${e}`)}let a=(await i.json()).id;return n.debug(`\u2705 Chat session created: ${a}`),a}catch(e){throw e instanceof Error?TypeError(`Failed to create chat session: ${e.message}`):Error(`Failed to create chat session: ${String(e)}`)}}async run(e,t,r,i,a){let{query:o,maxSteps:s,externalHistory:c,outputSchema:l}=Xe(e,t,r,i,a);c!==void 0&&n.warn(`External history is not yet supported for remote execution`);try{n.debug(`\u{1F310} Executing query on remote agent ${this.agentId}`),this.chatId===null&&(this.chatId=await this.createChatSession());let e=this.chatId,t={query:o,max_steps:s??10};l&&(t.output_schema=this.pydanticToJsonSchema(l),n.debug(`🔧 Using structured output with schema`));let r={"Content-Type":`application/json`,"x-api-key":this.apiKey},i=`${this.baseUrl}${Ye.replace(`{chat_id}`,e)}`;n.debug(`\u{1F680} Executing agent in chat ${e}`);let a=await fetch(i,{method:`POST`,headers:r,body:JSON.stringify(t),signal:AbortSignal.timeout(3e5)});if(!a.ok){let e=await a.text(),t=a.status;throw t===401?(n.error(`\u274C Authentication failed: ${e}`),Error(`Authentication failed: Invalid or missing API key. Please check your API key and ensure the MCP_USE_API_KEY environment variable is set correctly.`)):t===403?(n.error(`\u274C Access forbidden: ${e}`),Error(`Access denied: You don't have permission to execute agent '${this.agentId}'. Check if the agent exists and you have the necessary permissions.`)):t===404?(n.error(`\u274C Agent not found: ${e}`),Error(`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`)):t===422?(n.error(`\u274C Validation error: ${e}`),Error(`Request validation failed: ${e}. Please check your query parameters and output schema format.`)):t===500?(n.error(`\u274C Server error: ${e}`),Error(`Internal server error occurred during agent execution. Please try again later or contact support if the issue persists.`)):(n.error(`\u274C Remote execution failed with status ${t}: ${e}`),Error(`Remote agent execution failed: ${t} - ${e}`))}let c=await a.json();if(n.debug(`\u{1F527} Response: ${JSON.stringify(c)}`),n.debug(`✅ Remote execution completed successfully`),typeof c==`object`&&c){if(c.status===`error`||c.error!==null){let e=c.error??String(c);throw n.error(`\u274C Remote agent execution failed: ${e}`),Error(`Remote agent execution failed: ${e}`)}if(String(c).includes(`failed to initialize`))throw n.error(`\u274C Agent initialization failed: ${c}`),Error(`Agent initialization failed on remote server. This usually indicates:
|
|
17
17
|
\u2022 Invalid agent configuration (LLM model, system prompt)
|
|
18
18
|
\u2022 Missing or invalid MCP server configurations
|
|
19
19
|
\u2022 Network connectivity issues with MCP servers
|
|
20
20
|
\u2022 Missing environment variables or credentials
|
|
21
|
-
Raw error: ${c}`)}return l?this.parseStructuredResponse(c,l):typeof c==`object`&&c&&`result`in c?c.result:typeof c==`string`?c:String(c)}catch(e){throw e instanceof Error?e.name===`AbortError`?(n.error(`\u274C Remote execution timed out: ${e}`),Error(`Remote agent execution timed out. The server may be overloaded or the query is taking too long to process. Try again or use a simpler query.`)):(n.error(`\u274C Remote execution error: ${e}`),Error(`Remote agent execution failed: ${e.message}`)):(n.error(`\u274C Remote execution error: ${e}`),Error(`Remote agent execution failed: ${String(e)}`))}}async*stream(e,t,n,r,i){return await this.run(e,t,n,r,i)}async close(){n.debug(`🔌 Remote agent client closed`)}},Qe=class{static getPackageVersion(){return qe()}driver;client;connectors=[];clientOwnedByAgent=!1;nativeAdapter;providerTools=[];callTool;maxSteps;autoInitialize;systemPrompt;disallowedTools;exposeResourcesAsTools;exposePromptsAsTools;initialized=!1;isRemote=!1;remoteAgent=null;isSimplifiedMode=!1;llmString;llmConfig;mcpServersConfig;explicitProviderConfig;conversationMessages=[];memoryEnabled;boundConnections;constructor(e){if(e.agentId){this.isRemote=!0,this.remoteAgent=new Ze({agentId:e.agentId,apiKey:e.apiKey,baseUrl:e.baseUrl}),this.maxSteps=e.maxSteps??10,this.autoInitialize=e.autoInitialize??!1,this.nativeAdapter=new a,this.systemPrompt=e.systemPrompt??`You are a helpful assistant with access to MCP tools.`,this.disallowedTools=[],this.exposeResourcesAsTools=!0,this.exposePromptsAsTools=!0,this.memoryEnabled=e.memoryEnabled??!0;return}if(this.maxSteps=e.maxSteps??10,this.autoInitialize=e.autoInitialize??!1,this.systemPrompt=e.systemPrompt??`You are a helpful assistant with access to MCP tools.`,this.disallowedTools=e.disallowedTools??[],this.exposeResourcesAsTools=e.exposeResourcesAsTools??!0,this.exposePromptsAsTools=e.exposePromptsAsTools??!0,this.memoryEnabled=e.memoryEnabled??!0,this.nativeAdapter=new a(this.disallowedTools),this.llmConfig=e.llmConfig,this.resolveMcpServers(e.mcpServers),typeof e.llm==`string`){if(this.isSimplifiedMode=!0,this.llmString=e.llm,!this.hasLiveConnections()&&(!this.mcpServersConfig||Object.keys(this.mcpServersConfig).length===0)&&!e.client&&!e.connectors?.length)throw Error(`Simplified mode requires mcpServers, or an existing client/connectors.`)}else if(this.explicitProviderConfig=e.llm,this.client=e.client,this.connectors=e.connectors??[],!this.hasLiveConnections()&&!this.client&&this.connectors.length===0&&(!this.mcpServersConfig||Object.keys(this.mcpServersConfig).length===0))throw Error(`Explicit mode requires mcpServers, client, or connectors.`);e.client&&(this.client=e.client),e.connectors?.length&&(this.connectors=e.connectors),this.hasLiveConnections()&&this.explicitProviderConfig?this.bindConnections(this.boundConnections,this.explicitProviderConfig):this.hasLiveConnections()&&this.llmString&&(this.driver=X(Q(this.llmString,this.llmConfig)),this.bindConnections(this.boundConnections,Q(this.llmString,this.llmConfig)))}resolveMcpServers(e){if(e){if(Array.isArray(e)){this.boundConnections=e;return}this.mcpServersConfig=e}}hasLiveConnections(){return(this.boundConnections?.length??0)>0}async initialize(){if(this.isRemote){this.initialized=!0;return}if(!this.initialized){if(this.isSimplifiedMode){if(!this.client&&this.mcpServersConfig){let{MCPClient:t}=await e(async()=>{let{MCPClient:e}=await import(`./index-
|
|
21
|
+
Raw error: ${c}`)}return l?this.parseStructuredResponse(c,l):typeof c==`object`&&c&&`result`in c?c.result:typeof c==`string`?c:String(c)}catch(e){throw e instanceof Error?e.name===`AbortError`?(n.error(`\u274C Remote execution timed out: ${e}`),Error(`Remote agent execution timed out. The server may be overloaded or the query is taking too long to process. Try again or use a simpler query.`)):(n.error(`\u274C Remote execution error: ${e}`),Error(`Remote agent execution failed: ${e.message}`)):(n.error(`\u274C Remote execution error: ${e}`),Error(`Remote agent execution failed: ${String(e)}`))}}async*stream(e,t,n,r,i){return await this.run(e,t,n,r,i)}async close(){n.debug(`🔌 Remote agent client closed`)}},Qe=class{static getPackageVersion(){return qe()}driver;client;connectors=[];clientOwnedByAgent=!1;nativeAdapter;providerTools=[];callTool;maxSteps;autoInitialize;systemPrompt;disallowedTools;exposeResourcesAsTools;exposePromptsAsTools;initialized=!1;isRemote=!1;remoteAgent=null;isSimplifiedMode=!1;llmString;llmConfig;mcpServersConfig;explicitProviderConfig;conversationMessages=[];memoryEnabled;boundConnections;constructor(e){if(e.agentId){this.isRemote=!0,this.remoteAgent=new Ze({agentId:e.agentId,apiKey:e.apiKey,baseUrl:e.baseUrl}),this.maxSteps=e.maxSteps??10,this.autoInitialize=e.autoInitialize??!1,this.nativeAdapter=new a,this.systemPrompt=e.systemPrompt??`You are a helpful assistant with access to MCP tools.`,this.disallowedTools=[],this.exposeResourcesAsTools=!0,this.exposePromptsAsTools=!0,this.memoryEnabled=e.memoryEnabled??!0;return}if(this.maxSteps=e.maxSteps??10,this.autoInitialize=e.autoInitialize??!1,this.systemPrompt=e.systemPrompt??`You are a helpful assistant with access to MCP tools.`,this.disallowedTools=e.disallowedTools??[],this.exposeResourcesAsTools=e.exposeResourcesAsTools??!0,this.exposePromptsAsTools=e.exposePromptsAsTools??!0,this.memoryEnabled=e.memoryEnabled??!0,this.nativeAdapter=new a(this.disallowedTools),this.llmConfig=e.llmConfig,this.resolveMcpServers(e.mcpServers),typeof e.llm==`string`){if(this.isSimplifiedMode=!0,this.llmString=e.llm,!this.hasLiveConnections()&&(!this.mcpServersConfig||Object.keys(this.mcpServersConfig).length===0)&&!e.client&&!e.connectors?.length)throw Error(`Simplified mode requires mcpServers, or an existing client/connectors.`)}else if(this.explicitProviderConfig=e.llm,this.client=e.client,this.connectors=e.connectors??[],!this.hasLiveConnections()&&!this.client&&this.connectors.length===0&&(!this.mcpServersConfig||Object.keys(this.mcpServersConfig).length===0))throw Error(`Explicit mode requires mcpServers, client, or connectors.`);e.client&&(this.client=e.client),e.connectors?.length&&(this.connectors=e.connectors),this.hasLiveConnections()&&this.explicitProviderConfig?this.bindConnections(this.boundConnections,this.explicitProviderConfig):this.hasLiveConnections()&&this.llmString&&(this.driver=X(Q(this.llmString,this.llmConfig)),this.bindConnections(this.boundConnections,Q(this.llmString,this.llmConfig)))}resolveMcpServers(e){if(e){if(Array.isArray(e)){this.boundConnections=e;return}this.mcpServersConfig=e}}hasLiveConnections(){return(this.boundConnections?.length??0)>0}async initialize(){if(this.isRemote){this.initialized=!0;return}if(!this.initialized){if(this.isSimplifiedMode){if(!this.client&&this.mcpServersConfig){let{MCPClient:t}=await e(async()=>{let{MCPClient:e}=await import(`./index-CoRK2C3M.js`).then(e=>e.Ot);return{MCPClient:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));this.client=new t({mcpServers:this.mcpServersConfig}),this.clientOwnedByAgent=!0}this.llmString&&(this.driver=X(Q(this.llmString,this.llmConfig)))}else this.explicitProviderConfig&&(this.driver=X(this.explicitProviderConfig));if(!this.driver)throw Error(`LLM driver not configured.`);this.hasLiveConnections()||await this.loadTools(),this.initialized=!0,n.debug(`MCPAgent initialized`)}}async loadTools(){let e=[];if(this.client){(!this.client.activeSessions||Object.keys(this.client.activeSessions).length===0)&&await this.client.createAllSessions();let t=this.client.getAllActiveSessions(),n=Object.values(t).map(e=>e.connector);e.push(...await this.nativeAdapter.createToolsFromConnectors(n)),this.exposeResourcesAsTools&&e.push(...await this.nativeAdapter.createResourcesFromConnectors(n)),this.exposePromptsAsTools&&e.push(...await this.nativeAdapter.createPromptsFromConnectors(n))}else{for(let e of this.connectors)e.isClientConnected||await e.connect();e.push(...await this.nativeAdapter.createToolsFromConnectors(this.connectors)),this.exposeResourcesAsTools&&e.push(...await this.nativeAdapter.createResourcesFromConnectors(this.connectors)),this.exposePromptsAsTools&&e.push(...await this.nativeAdapter.createPromptsFromConnectors(this.connectors))}this.providerTools=this.nativeAdapter.toProviderTools(e),this.callTool=this.nativeAdapter.createCallTool()}bindConnections(e,t){let n=new Set(this.disallowedTools),r=new Set,i=new Map,a=e=>{if(!r.has(e))return r.add(e),e;let t=2;for(;r.has(`${e}_${t}`);)t++;let n=`${e}_${t}`;return r.add(n),n},o=[];for(let t of e)for(let e of t.tools??[]){if(n.has(e.name))continue;let r=a(e.name);i.set(r,{connection:t,mcpName:e.name}),o.push({name:r,description:e.description,inputSchema:e.inputSchema??{type:`object`,properties:{}}})}this.providerTools=o,this.callTool=async(e,t)=>{let n=i.get(e);if(!n)throw Error(`Unknown tool: ${e}`);return n.connection.callTool(n.mcpName,t)},this.driver=X(t),this.initialized=!0}buildMessages(e){let t=[{role:`system`,content:this.systemPrompt}];return this.memoryEnabled&&this.conversationMessages.length>0&&t.push(...this.conversationMessages),e.messages?.length&&t.push(...e.messages),e.prompt&&t.push({role:`user`,content:e.prompt}),t}getConversationHistory(){return[...this.conversationMessages]}clearConversationHistory(){this.conversationMessages=[]}setSystemMessage(e){this.systemPrompt=e}async ensureReady(e=!0){if(e&&!this.initialized)if(this.autoInitialize)await this.initialize();else throw Error(`MCPAgent not initialized. Call initialize() first.`);if(!this.driver||!this.callTool)throw Error(`MCPAgent driver or tools not ready.`)}nativeRunParams(e){return{messages:this.buildMessages(e),tools:this.providerTools,callTool:this.callTool,maxSteps:e.maxSteps??this.maxSteps,signal:e.signal}}async run(e,t,n,r,i,a){let o=$(e,t,n,r,i,a);if(o.schema)throw Error(`Structured output requires @mcp-use/agent/langchain or pass a JSON schema via prompt.`);if(this.isRemote&&this.remoteAgent)return this.remoteAgent.run(o.prompt??``,o.maxSteps,o.manageConnector);await this.ensureReady(o.manageConnector??!0);let s=await He(this.driver,this.nativeRunParams(o));return this.memoryEnabled&&o.prompt&&(this.conversationMessages.push({role:`user`,content:o.prompt}),this.conversationMessages.push({role:`assistant`,content:s})),s}async*stream(e,t,n,r,i,a){let o=$(e,t,n,r,i,a);if(this.isRemote&&this.remoteAgent)return await this.remoteAgent.run(o.prompt??``,o.maxSteps,o.manageConnector);await this.ensureReady(o.manageConnector??!0);let s=yield*Ve(this.driver,this.nativeRunParams(o));return this.memoryEnabled&&o.prompt&&(this.conversationMessages.push({role:`user`,content:o.prompt}),this.conversationMessages.push({role:`assistant`,content:s})),s}async*streamEvents(e,t,n,r,i,a){let o=$(e,t,n,r,i,a);if(this.isRemote&&this.remoteAgent)throw Error(`streamEvents is not supported for remote agents.`);await this.ensureReady(o.manageConnector??!0),yield*Z(this.driver,this.nativeRunParams(o))}async chat(e){return await this.ensureReady(),(await this.driver.complete({messages:e.messages,tools:[],signal:e.signal})).text}async close(){this.clientOwnedByAgent&&this.client&&await this.client.closeAllSessions?.(),this.initialized=!1}};async function $e(e){return(await X(e.config).complete({messages:e.messages,tools:[],signal:e.signal})).text}export{$e as a,Ge as c,D as i,Qe as n,re as o,we as r,E as s,Ce as t};
|