@intelliweave/embedded 2.2.81 → 2.2.82
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/component/component.js +62 -24
- package/dist/intelliweave-wordpress.zip +0 -0
- package/dist/node/node.js +1 -1
- package/dist/react/react.js +59 -21
- package/dist/script-tag/script-tag.js +62 -24
- package/dist/webpack/index.js +59 -21
- package/package.json +1 -1
- package/AGENTS.md +0 -12
|
Binary file
|
package/dist/node/node.js
CHANGED
|
@@ -18,7 +18,7 @@ New information found:
|
|
|
18
18
|
${o}
|
|
19
19
|
|
|
20
20
|
New tools available:
|
|
21
|
-
${r}`}},{id:"ui.openURL",type:"action",name:"Open a URL in a new tab.",tags:"open, url, website, navigate, visit, go to, new tab, browser",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowOpenNewTab,content:"Opens the specified URL in a new tab. Use this when the user asks to open a website, visit a URL, go to a page, or navigate to a specific website. Only available when allowOpenNewTab flag is enabled.",parameters:[{name:"url",type:"string",description:"The URL to open in a new tab"}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowOpenNewTab)throw new Error("Open New Tab action is not enabled for this persona.");if(!e.url||typeof e.url!="string")throw new Error("URL parameter is required and must be a string.");if(!window.open(e.url,"_blank"))throw new Error("Window blocked by popup blocker. Please allow popups for this site.");return`Opened URL: ${e.url}`}},{id:"ui.changeRoute",type:"action",name:"Change the current page route.",tags:"navigate, route, path, page, go to, change page, routing, navigation",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowChangeRoute,content:"Changes the current page route to the specified path. Use this when the user asks to navigate to a different page, go to a specific section, or change the current page route. Only available when allowChangeRoute flag is enabled.",parameters:[{name:"path",type:"string",description:'The path to navigate to (e.g., "/home", "/dashboard")'}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowChangeRoute)throw new Error("Change Route action is not enabled for this persona.");if(!e.path||typeof e.path!="string")throw new Error("Path parameter is required and must be a string.");let n=new URL(e.path,window.location.origin).pathname;return window.location.href=n,`Changed route to: ${n}`}},{id:"ui.sendEmail",type:"action",name:"Send an email",tags:"email, send, mail, compose, message, contact, mailto",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowSendEmail,content:"Sends an email using the user's default mail client by opening a mailto: link. Use this when the user asks to send an email, compose a message, or contact someone via email. Only available when allowSendEmail flag is enabled.",parameters:[{name:"email_address",type:"string",description:"The recipient email address"},{name:"subject",type:"string",description:"The email subject line"},{name:"body",type:"string",description:"The email body content"}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowSendEmail)throw new Error("Send Email action is not enabled for this persona.");if(!e.email_address||typeof e.email_address!="string")throw new Error("Email address parameter is required and must be a string.");if(!e.subject||typeof e.subject!="string")throw new Error("Subject parameter is required and must be a string.");if(!e.body||typeof e.body!="string")throw new Error("Body parameter is required and must be a string.");let n=encodeURIComponent(e.email_address),s=encodeURIComponent(e.subject),o=encodeURIComponent(e.body),r=`mailto:${n}?subject=${s}&body=${o}`;try{window.location.href=r}catch(c){throw new Error(`Failed to open email client: ${c instanceof Error?c.message:String(c)}`)}return`Email opened in default mail client. Recipient: ${e.email_address}, Subject: ${e.subject}`}}];import{Client as de}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as pe}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var v={name:"@intelliweave/embedded",version:"2.2.81",description:"Integrate IntelliWeave into your app or website.",main:"./dist/webpack/index.js",types:"./dist/webpack/index.d.ts",type:"module",exports:{".":"./dist/webpack/index.js","./component":"./dist/component/component.js","./node":"./dist/node/node.js","./react":"./dist/react/react.js","./webpack":"./dist/webpack/index.js"},scripts:{build:"npm run build:lib && npm run build:docs","build:lib":"tsx build.ts","build:dev":"cross-env DEVELOPMENT=1 npm run build","build:docs":"typedoc src/index.mts --out dist/docs/",deploy:'npm run build && gsutil cp ./dist/web-weaver.min.js gs://metapress-cdn/web-weaver.min.js && gcloud compute url-maps invalidate-cdn-cache mp-cdn-loadbalancer --project="mp-backend-api" --path "/web-weaver.min.js" --async',"start:server":"cd server && npm run start","deploy:server":"cd server && npm run deploy","llm:build":"cd llm-server && docker build -t web-weaver-llm .","llm:start":"npm run llm:build && docker run -it --rm -p 8000:80 --gpus=all web-weaver-llm","llm:deploy.docker":"npm run llm:build && gcloud auth configure-docker us-central1-docker.pkg.dev && docker tag web-weaver-llm us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm && docker push us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm","llm:deploy":'npm run llm:deploy.docker && gcloud run deploy web-weaver-llm --project=ydangle-web-companion --image=us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm --allow-unauthenticated --region=us-central1 --description="Web Weaver LLM" --concurrency=2 --min-instances=0 --timeout=5m --memory=16Gi --cpu=8',prepack:"npm run build",test:"npm run build && vitest run","test:local":"IW_API_URL=http://localhost:3000/api npm run test"},keywords:["web","weaver","ai","assistant","chat"],author:"jjv360",license:"UNLICENSED",devDependencies:{"@types/audioworklet":"^0.0.97","@types/lodash":"^4.17.24","@types/react":"^19.2.14",bestzip:"^2.2.2","cross-env":"^10.1.0","find-cache-dir":"^6.0.0",lodash:"^4.17.23","onnxruntime-web":"^1.24.3",react:"^19.2.4","replace-in-file":"^8.4.0",tsup:"^8.5.1",tsx:"^4.21.0",typedoc:"^0.28.18",vitest:"^4.1.0"},peerDependencies:{"onnxruntime-web":"^1.20.0",react:"^18 || ^19"},dependencies:{"@anthropic-ai/sdk":"^0.80.0","@modelcontextprotocol/sdk":"^1.27.1","@types/json-schema":"^7.0.15",minisearch:"^7.2.0",openai:"^6.32.0","rehype-document":"^7.0.3","rehype-external-links":"^3.0.0","rehype-format":"^5.0.1","rehype-stringify":"^10.0.1","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",unified:"^11.0.5","utility-types":"^3.11.0",uuid:"^13.0.0"}};import{LoggingMessageNotificationSchema as he,ToolListChangedNotificationSchema as ge}from"@modelcontextprotocol/sdk/types.js";var m=new g("MCPKnowledgeClient"),me="https://intelliweave-mcp-proxy-828827766277.us-central1.run.app",W=class{constructor(e){this.tools=[];this.iwActions=[];this.stats={toolsCalled:0};this.lastSearchQuery="";this.lastSearchResults=[];this.config=e}async connect(){return this.client?this.client:this.connectionPromise?await this.connectionPromise:(this.connectionPromise=this.connectInternal(),this.connectionPromise.finally(()=>{this.connectionPromise=void 0}),await this.connectionPromise)}async connectInternal(){m.debug("Connecting to MCP client");let e=this.config.connect?await this.config.connect():await Promise.resolve().then(async()=>{let t=new URL(this.config.baseURL),n={};this.config.headers&&(n={...n,...this.config.headers}),this.config.proxy?.enabled&&(n["Mcp-Target-Url"]=t.toString(),n["IntelliWeave-Api-Key"]=this.config.proxy.apiKey||"",t=new URL(this.config.proxy.url||me));let s=new de({name:v.name,version:v.version}),o=new pe(t,{requestInit:{headers:n}});return await s.connect(o),m.debug("Connected with HTTP streaming mode"),s});return await this.disconnect(),this.client=e,e.onerror=t=>{m.error(`MCP client error: ${t.message}`)},e.onclose=()=>{m.debug("MCP client connection closed"),this.client=void 0},e.setNotificationHandler(he,t=>{t.params.level=="critical"?m.error(`[Server] ${t.params.data}`):t.params.level=="emergency"?m.error(`[Server] ${t.params.data}`):t.params.level=="error"?m.error(`[Server] ${t.params.data}`):t.params.level=="warning"?m.warn(`[Server] ${t.params.data}`):t.params.level=="info"?m.info(`[Server] ${t.params.data}`):t.params.level=="debug"?m.debug(`[Server] ${t.params.data}`):m.log(`[Server] ${t.params.data}`)}),e.setNotificationHandler(ge,t=>{m.debug("Tool list changed",t),this.fetchTools()}),m.debug("Fetching tools from MCP server..."),await this.fetchTools(),e}async disconnect(){await this.client?.close(),this.client=void 0,this.tools=[],this.iwActions=[]}async fetchTools(){let e=[],t;for(;;){let o=await this.client.listTools({cursor:t});t=o.nextCursor;for(let r of o.tools||[])e.push(r);if(!o?.tools?.length||!t)break}let n=[],s=this.config.id||"mcp";for(let o of e){let r=!!(this.config.searchToolName&&o.name==this.config.searchToolName&&!this.config.searchToolVisible),c=`${s}_${o.name}`;n.push({id:c,name:o.name,content:o.description||"",type:"action",isContext:!0,parameters:o.inputSchema,action:l=>this.performToolCall(o.name,l),disabled:r})}m.debug(`Fetched ${e.length} tools from MCP server.`),this.tools=e,this.iwActions=n}async search(e){if(e==this.lastSearchQuery)return this.lastSearchResults;await this.connect();let t=this.iwActions.slice(),n=await this.performSearchCall(e);return t=t.concat(n),this.lastSearchQuery=e,this.lastSearchResults=t,m.debug(`Search completed, found ${t.length} items.`),t}async performSearchCall(e){let t=[];if(!this.config.searchToolName)return t;let n=this.tools.find(o=>o.name==this.config.searchToolName);if(!n)return m.warn(`Search function ${this.config.searchToolName} not found on the MCP server.`),t;let s;if(n.inputSchema.required?.length==1){let o=n.inputSchema.required[0];s=await this.performToolCall(this.config.searchToolName,{[o]:e})}else if(n.inputSchema.properties&&Object.keys(n.inputSchema.properties).length==1){let o=Object.keys(n.inputSchema.properties)[0];s=await this.performToolCall(this.config.searchToolName,{[o]:e})}else s=await this.performToolCall(this.config.searchToolName,{});if(Array.isArray(s))for(let o=0;o<s.length;o++){let r=s[o];t.push({id:this.config.id+":"+this.config.searchToolName+":"+o,name:`Search result ${o+1} in ${this.config.searchToolName}`,type:"info",content:typeof r=="string"?r:JSON.stringify(r)})}else t.push({id:this.config.id+":"+this.config.searchToolName+":result",name:`Search result in ${this.config.searchToolName}`,type:"info",content:typeof s=="string"?s:JSON.stringify(s)});return t}async performToolCall(e,t){await this.connect(),m.debug(`Performing tool call for ${e} with params:`,t),this.stats.toolsCalled+=1;let n=await this.client.callTool({name:e,arguments:t});if(n.isError){let s=n.content?.[0]?.text||"Unknown error";throw m.error(`Error calling tool ${e}: ${s}`),new Error(`Error calling tool ${e}: ${s}`)}if(Array.isArray(n.content)&&n.content.length==1&&n.content[0].type=="text")try{return JSON.parse(n.content[0].text)}catch{}return n.content||[]}};import{v4 as fe}from"uuid";var we=new g("Statistics"),E=[];async function I(u,e){let t={...e,event_id:fe(),event_date:new Date().toISOString(),sdk_version:v.version,conversation_id:u?.conversationID||"",api_key:u?.apiKey||"",user_id:u?.userID||""};if(E.push(t),!u||(await new Promise(s=>setTimeout(s,5e3)),E.length===0))return;let n=E.slice();E.length=0;try{let s=await fetch(u.hubAPI+"/analytics/stats",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:n})});if(!s.ok)throw new Error(`Analytics submission failed: ${s.status} ${s.statusText}`)}catch(s){we.warn("Failed to submit analytics event:",s),E.push(...n);return}}var k=new g("KnowledgeBase"),be=8*1024,L=1,O=class u{constructor(e){this._sources=[];this._windowSources=[];this.lastResults=[];this.manualEntries=[];this.allowWindowSources=!0;this.allowGlobalConfigSources=!0;this.allowRagSearch=!0;this.ai=e,this.ensureInternalKnowledge()}ensureInternalKnowledge(){this._sources=this._sources.filter(e=>e.id!=="core.internal"),this._sources.push({id:"core.internal",query:async()=>Q(this.ai)})}reset(){this._windowSources=[],this.manualEntries=[],this.lastResults=[],this._sources=[],this.ensureInternalKnowledge()}registerSource(e,t){let n=e;return typeof e=="function"&&(t=e,n=`source.${L++}`),this._sources.push({id:n,query:t}),n}removeSource(e){this._sources=this.sources.filter(t=>t.id!==e&&t.query!==e)}addEntry(e){this.manualEntries.push(e)}removeEntry(e){this.manualEntries=this.manualEntries.filter(t=>t.id!==e)}get sources(){let e=this._sources;return this.allowGlobalConfigSources&&y().knowledgeBaseSources&&(e=e.concat(y().knowledgeBaseSources)),this.allowWindowSources&&typeof document<"u"&&(e=e.concat(this._windowSources)),e=e.filter(t=>!t.disabled),e}async search(e){k.debug(`Searching knowledge base for: ${e}`);let t=Date.now(),n=new Event("webweaver_kb_search",{bubbles:!0,cancelable:!0});n.query=e,n.entries=[],n.sources=[],this.allowWindowSources&&typeof document<"u"?(document.dispatchEvent(n),this._windowSources=n.sources):this._windowSources=[];let o=(await Promise.all(this.sources.map(async i=>{try{let p=Date.now(),h=await i.query(e);return k.debug(`Source '${i.id}' took ${Date.now()-p}ms`),h||[]}catch(p){return k.warn(`Knowledge source '${i.id}' failed:`,p),[]}}))).flat();o=o.concat(n.entries),o=o.concat(this.manualEntries),this.allowGlobalConfigSources&&y().knowledgeBase&&(o=o.concat(y().knowledgeBase)),o=o.filter(i=>i&&!i.disabled);let r=new Map;for(let i of o)i.id&&r.set(i.id,(r.get(i.id)||0)+1);for(let[i,p]of r)if(p>1){k.warn(`Duplicate knowledge base item ID detected: '${i}' appears ${p} times. Adding suffixes to make them unique.`);let h=1,f=!0;for(let S of o)if(S.id===i){if(f){f=!1;continue}S.id=`${i}(${h})`,h++}}for(let i=0;i<o.length;i++){let p=o[i];p.id=p.id||`temp.${i}`,p._functionID=p.id.replaceAll(/[^a-zA-Z0-9_]/g,"_")}let c=new ye({fields:["id","type","name","content","tags"],storeFields:[],searchOptions:{boost:{name:3,tags:2},fuzzy:.2}});c.addAll(o);let d=c.search(e).map(i=>o.find(p=>p.id==i.id)).filter(Boolean),a=0;d=d.filter(i=>{if(i.isContext)return!0;let p=(i.content||"").length;return a+p>be?!1:(a+=p,!0)});for(let i of o)i.isContext&&(d.find(p=>p.id===i.id)||d.push(i));return this.lastResults=d,I(this.ai,{event_type:"kb_search",value:d.length,value_str:"",event_properties:{search_time_ms:Date.now()-t,sources_searched:this.sources.length}}),k.debug("Found results:",d),d}getCachedEntry(e){return this.lastResults.find(t=>t.id==e||t._functionID==e)}registerSourceFromURL(e,t){t||(t=`external.${L++}`),k.debug(`Registering remote knowledge base source: ${e}`);let n=[],s=[],o=!0,r=async(l,d)=>{k.debug(`Calling remote knowledge base action: ${l.id}`);let a={type:"action",userID:this.ai.userID,actionID:l.id,parameters:d},i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(`HTTP Error ${i.status} ${i.statusText}`);let p=await i.json();return c(p.updateItems||[]),p.response},c=l=>{for(let d of l){if(!d.id){k.warn("KB item skipped since it has no ID.",d);continue}let a=n.find(i=>i.id==d.id);if(a){a.name=d.name||a.name||"",a.content=d.content||a.content||"",a.disabled=d.disabled??a.disabled,a.isContext=d.isContext??a.isContext,a.parameters=d.parameters||a.parameters||[],a.tags=d.tags||a.tags,a.type=d.type||a.type;continue}n.push({...d,action:i=>r(d,i)})}};this.registerSource(t,async l=>{if(o&&s.includes(l))return n;let d={type:"search",userID:this.ai?.userID||"",query:l},a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!a.ok)throw new Error(`HTTP Error ${a.status} ${a.statusText}`);let i=await a.json();return o=!i.noCache,s.includes(l)||s.push(l),c(i.items),n})}clone(e){let t=new u(e);return t._sources=this._sources.slice(),t._windowSources=this._windowSources.slice(),t.manualEntries=this.manualEntries.slice(),t.allowGlobalConfigSources=this.allowGlobalConfigSources,t.allowWindowSources=this.allowWindowSources,t.allowRagSearch=this.allowRagSearch,t.ensureInternalKnowledge(),t}registerMCPSource(e){e.id||(e.id=`external.${L++}`);let t=new W(e);return this.registerSource(e.id,n=>t.search(n)),t}};function ve(u){let e="",t=[],n=0;for(;n<u.length;){let s=u.indexOf("<[[",n);if(s===-1){e+=u.slice(n);break}e+=u.slice(n,s);let o=u.indexOf("]]>",s+3);if(o===-1)break;let r=u.slice(s,o+3),c=u.slice(s+3,o).trim(),l={raw:r,content:c};try{let d=JSON.parse(c);d&&typeof d=="object"&&!Array.isArray(d)&&(l.action=d)}catch{}t.push(l),n=o+3}return{visibleText:e,actions:t.flatMap(s=>s.action?[s.action]:[]),blocks:t}}function Z(u){return ve(u).visibleText}var R=class{constructor(e){this.messages=e}text(){return this.messages?.flatMap(e=>e.sections)?.filter(e=>e?.type=="text")?.map(e=>Z(e?.text||""))?.filter(e=>!!e)?.join(`
|
|
21
|
+
${r}`}},{id:"ui.openURL",type:"action",name:"Open a URL in a new tab.",tags:"open, url, website, navigate, visit, go to, new tab, browser",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowOpenNewTab,content:"Opens the specified URL in a new tab. Use this when the user asks to open a website, visit a URL, go to a page, or navigate to a specific website. Only available when allowOpenNewTab flag is enabled.",parameters:[{name:"url",type:"string",description:"The URL to open in a new tab"}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowOpenNewTab)throw new Error("Open New Tab action is not enabled for this persona.");if(!e.url||typeof e.url!="string")throw new Error("URL parameter is required and must be a string.");if(!window.open(e.url,"_blank"))throw new Error("Window blocked by popup blocker. Please allow popups for this site.");return`Opened URL: ${e.url}`}},{id:"ui.changeRoute",type:"action",name:"Change the current page route.",tags:"navigate, route, path, page, go to, change page, routing, navigation",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowChangeRoute,content:"Changes the current page route to the specified path. Use this when the user asks to navigate to a different page, go to a specific section, or change the current page route. Only available when allowChangeRoute flag is enabled.",parameters:[{name:"path",type:"string",description:'The path to navigate to (e.g., "/home", "/dashboard")'}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowChangeRoute)throw new Error("Change Route action is not enabled for this persona.");if(!e.path||typeof e.path!="string")throw new Error("Path parameter is required and must be a string.");let n=new URL(e.path,window.location.origin).pathname;return window.location.href=n,`Changed route to: ${n}`}},{id:"ui.sendEmail",type:"action",name:"Send an email",tags:"email, send, mail, compose, message, contact, mailto",isContext:!0,disabled:typeof window>"u"||!u?.flags?.allowSendEmail,content:"Sends an email using the user's default mail client by opening a mailto: link. Use this when the user asks to send an email, compose a message, or contact someone via email. Only available when allowSendEmail flag is enabled.",parameters:[{name:"email_address",type:"string",description:"The recipient email address"},{name:"subject",type:"string",description:"The email subject line"},{name:"body",type:"string",description:"The email body content"}],action:(e,t)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!t.flags.allowSendEmail)throw new Error("Send Email action is not enabled for this persona.");if(!e.email_address||typeof e.email_address!="string")throw new Error("Email address parameter is required and must be a string.");if(!e.subject||typeof e.subject!="string")throw new Error("Subject parameter is required and must be a string.");if(!e.body||typeof e.body!="string")throw new Error("Body parameter is required and must be a string.");let n=encodeURIComponent(e.email_address),s=encodeURIComponent(e.subject),o=encodeURIComponent(e.body),r=`mailto:${n}?subject=${s}&body=${o}`;try{window.location.href=r}catch(c){throw new Error(`Failed to open email client: ${c instanceof Error?c.message:String(c)}`)}return`Email opened in default mail client. Recipient: ${e.email_address}, Subject: ${e.subject}`}}];import{Client as de}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as pe}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var v={name:"@intelliweave/embedded",version:"2.2.82",description:"Integrate IntelliWeave into your app or website.",main:"./dist/webpack/index.js",types:"./dist/webpack/index.d.ts",type:"module",exports:{".":"./dist/webpack/index.js","./component":"./dist/component/component.js","./node":"./dist/node/node.js","./react":"./dist/react/react.js","./webpack":"./dist/webpack/index.js"},scripts:{build:"npm run build:lib && npm run build:docs","build:lib":"tsx build.ts","build:dev":"cross-env DEVELOPMENT=1 npm run build","build:docs":"typedoc src/index.mts --out dist/docs/",deploy:'npm run build && gsutil cp ./dist/web-weaver.min.js gs://metapress-cdn/web-weaver.min.js && gcloud compute url-maps invalidate-cdn-cache mp-cdn-loadbalancer --project="mp-backend-api" --path "/web-weaver.min.js" --async',"start:server":"cd server && npm run start","deploy:server":"cd server && npm run deploy","llm:build":"cd llm-server && docker build -t web-weaver-llm .","llm:start":"npm run llm:build && docker run -it --rm -p 8000:80 --gpus=all web-weaver-llm","llm:deploy.docker":"npm run llm:build && gcloud auth configure-docker us-central1-docker.pkg.dev && docker tag web-weaver-llm us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm && docker push us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm","llm:deploy":'npm run llm:deploy.docker && gcloud run deploy web-weaver-llm --project=ydangle-web-companion --image=us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm --allow-unauthenticated --region=us-central1 --description="Web Weaver LLM" --concurrency=2 --min-instances=0 --timeout=5m --memory=16Gi --cpu=8',prepack:"npm run build",test:"npm run build && vitest run","test:local":"IW_API_URL=http://localhost:3000/api npm run test"},keywords:["web","weaver","ai","assistant","chat"],author:"jjv360",license:"UNLICENSED",devDependencies:{"@types/audioworklet":"^0.0.97","@types/lodash":"^4.17.24","@types/react":"^19.2.14",bestzip:"^2.2.2","cross-env":"^10.1.0","find-cache-dir":"^6.0.0",lodash:"^4.17.23","onnxruntime-web":"^1.24.3",react:"^19.2.4","replace-in-file":"^8.4.0",tsup:"^8.5.1",tsx:"^4.21.0",typedoc:"^0.28.18",vitest:"^4.1.0"},peerDependencies:{"onnxruntime-web":"^1.20.0",react:"^18 || ^19"},dependencies:{"@anthropic-ai/sdk":"^0.80.0","@modelcontextprotocol/sdk":"^1.27.1","@types/json-schema":"^7.0.15",minisearch:"^7.2.0",openai:"^6.32.0","rehype-document":"^7.0.3","rehype-external-links":"^3.0.0","rehype-format":"^5.0.1","rehype-stringify":"^10.0.1","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",unified:"^11.0.5","utility-types":"^3.11.0",uuid:"^13.0.0"}};import{LoggingMessageNotificationSchema as he,ToolListChangedNotificationSchema as ge}from"@modelcontextprotocol/sdk/types.js";var m=new g("MCPKnowledgeClient"),me="https://intelliweave-mcp-proxy-828827766277.us-central1.run.app",W=class{constructor(e){this.tools=[];this.iwActions=[];this.stats={toolsCalled:0};this.lastSearchQuery="";this.lastSearchResults=[];this.config=e}async connect(){return this.client?this.client:this.connectionPromise?await this.connectionPromise:(this.connectionPromise=this.connectInternal(),this.connectionPromise.finally(()=>{this.connectionPromise=void 0}),await this.connectionPromise)}async connectInternal(){m.debug("Connecting to MCP client");let e=this.config.connect?await this.config.connect():await Promise.resolve().then(async()=>{let t=new URL(this.config.baseURL),n={};this.config.headers&&(n={...n,...this.config.headers}),this.config.proxy?.enabled&&(n["Mcp-Target-Url"]=t.toString(),n["IntelliWeave-Api-Key"]=this.config.proxy.apiKey||"",t=new URL(this.config.proxy.url||me));let s=new de({name:v.name,version:v.version}),o=new pe(t,{requestInit:{headers:n}});return await s.connect(o),m.debug("Connected with HTTP streaming mode"),s});return await this.disconnect(),this.client=e,e.onerror=t=>{m.error(`MCP client error: ${t.message}`)},e.onclose=()=>{m.debug("MCP client connection closed"),this.client=void 0},e.setNotificationHandler(he,t=>{t.params.level=="critical"?m.error(`[Server] ${t.params.data}`):t.params.level=="emergency"?m.error(`[Server] ${t.params.data}`):t.params.level=="error"?m.error(`[Server] ${t.params.data}`):t.params.level=="warning"?m.warn(`[Server] ${t.params.data}`):t.params.level=="info"?m.info(`[Server] ${t.params.data}`):t.params.level=="debug"?m.debug(`[Server] ${t.params.data}`):m.log(`[Server] ${t.params.data}`)}),e.setNotificationHandler(ge,t=>{m.debug("Tool list changed",t),this.fetchTools()}),m.debug("Fetching tools from MCP server..."),await this.fetchTools(),e}async disconnect(){await this.client?.close(),this.client=void 0,this.tools=[],this.iwActions=[]}async fetchTools(){let e=[],t;for(;;){let o=await this.client.listTools({cursor:t});t=o.nextCursor;for(let r of o.tools||[])e.push(r);if(!o?.tools?.length||!t)break}let n=[],s=this.config.id||"mcp";for(let o of e){let r=!!(this.config.searchToolName&&o.name==this.config.searchToolName&&!this.config.searchToolVisible),c=`${s}_${o.name}`;n.push({id:c,name:o.name,content:o.description||"",type:"action",isContext:!0,parameters:o.inputSchema,action:l=>this.performToolCall(o.name,l),disabled:r})}m.debug(`Fetched ${e.length} tools from MCP server.`),this.tools=e,this.iwActions=n}async search(e){if(e==this.lastSearchQuery)return this.lastSearchResults;await this.connect();let t=this.iwActions.slice(),n=await this.performSearchCall(e);return t=t.concat(n),this.lastSearchQuery=e,this.lastSearchResults=t,m.debug(`Search completed, found ${t.length} items.`),t}async performSearchCall(e){let t=[];if(!this.config.searchToolName)return t;let n=this.tools.find(o=>o.name==this.config.searchToolName);if(!n)return m.warn(`Search function ${this.config.searchToolName} not found on the MCP server.`),t;let s;if(n.inputSchema.required?.length==1){let o=n.inputSchema.required[0];s=await this.performToolCall(this.config.searchToolName,{[o]:e})}else if(n.inputSchema.properties&&Object.keys(n.inputSchema.properties).length==1){let o=Object.keys(n.inputSchema.properties)[0];s=await this.performToolCall(this.config.searchToolName,{[o]:e})}else s=await this.performToolCall(this.config.searchToolName,{});if(Array.isArray(s))for(let o=0;o<s.length;o++){let r=s[o];t.push({id:this.config.id+":"+this.config.searchToolName+":"+o,name:`Search result ${o+1} in ${this.config.searchToolName}`,type:"info",content:typeof r=="string"?r:JSON.stringify(r)})}else t.push({id:this.config.id+":"+this.config.searchToolName+":result",name:`Search result in ${this.config.searchToolName}`,type:"info",content:typeof s=="string"?s:JSON.stringify(s)});return t}async performToolCall(e,t){await this.connect(),m.debug(`Performing tool call for ${e} with params:`,t),this.stats.toolsCalled+=1;let n=await this.client.callTool({name:e,arguments:t});if(n.isError){let s=n.content?.[0]?.text||"Unknown error";throw m.error(`Error calling tool ${e}: ${s}`),new Error(`Error calling tool ${e}: ${s}`)}if(Array.isArray(n.content)&&n.content.length==1&&n.content[0].type=="text")try{return JSON.parse(n.content[0].text)}catch{}return n.content||[]}};import{v4 as fe}from"uuid";var we=new g("Statistics"),E=[];async function I(u,e){let t={...e,event_id:fe(),event_date:new Date().toISOString(),sdk_version:v.version,conversation_id:u?.conversationID||"",api_key:u?.apiKey||"",user_id:u?.userID||""};if(E.push(t),!u||(await new Promise(s=>setTimeout(s,5e3)),E.length===0))return;let n=E.slice();E.length=0;try{let s=await fetch(u.hubAPI+"/analytics/stats",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:n})});if(!s.ok)throw new Error(`Analytics submission failed: ${s.status} ${s.statusText}`)}catch(s){we.warn("Failed to submit analytics event:",s),E.push(...n);return}}var k=new g("KnowledgeBase"),be=8*1024,L=1,O=class u{constructor(e){this._sources=[];this._windowSources=[];this.lastResults=[];this.manualEntries=[];this.allowWindowSources=!0;this.allowGlobalConfigSources=!0;this.allowRagSearch=!0;this.ai=e,this.ensureInternalKnowledge()}ensureInternalKnowledge(){this._sources=this._sources.filter(e=>e.id!=="core.internal"),this._sources.push({id:"core.internal",query:async()=>Q(this.ai)})}reset(){this._windowSources=[],this.manualEntries=[],this.lastResults=[],this._sources=[],this.ensureInternalKnowledge()}registerSource(e,t){let n=e;return typeof e=="function"&&(t=e,n=`source.${L++}`),this._sources.push({id:n,query:t}),n}removeSource(e){this._sources=this.sources.filter(t=>t.id!==e&&t.query!==e)}addEntry(e){this.manualEntries.push(e)}removeEntry(e){this.manualEntries=this.manualEntries.filter(t=>t.id!==e)}get sources(){let e=this._sources;return this.allowGlobalConfigSources&&y().knowledgeBaseSources&&(e=e.concat(y().knowledgeBaseSources)),this.allowWindowSources&&typeof document<"u"&&(e=e.concat(this._windowSources)),e=e.filter(t=>!t.disabled),e}async search(e){k.debug(`Searching knowledge base for: ${e}`);let t=Date.now(),n=new Event("webweaver_kb_search",{bubbles:!0,cancelable:!0});n.query=e,n.entries=[],n.sources=[],this.allowWindowSources&&typeof document<"u"?(document.dispatchEvent(n),this._windowSources=n.sources):this._windowSources=[];let o=(await Promise.all(this.sources.map(async i=>{try{let p=Date.now(),h=await i.query(e);return k.debug(`Source '${i.id}' took ${Date.now()-p}ms`),h||[]}catch(p){return k.warn(`Knowledge source '${i.id}' failed:`,p),[]}}))).flat();o=o.concat(n.entries),o=o.concat(this.manualEntries),this.allowGlobalConfigSources&&y().knowledgeBase&&(o=o.concat(y().knowledgeBase)),o=o.filter(i=>i&&!i.disabled);let r=new Map;for(let i of o)i.id&&r.set(i.id,(r.get(i.id)||0)+1);for(let[i,p]of r)if(p>1){k.warn(`Duplicate knowledge base item ID detected: '${i}' appears ${p} times. Adding suffixes to make them unique.`);let h=1,f=!0;for(let S of o)if(S.id===i){if(f){f=!1;continue}S.id=`${i}(${h})`,h++}}for(let i=0;i<o.length;i++){let p=o[i];p.id=p.id||`temp.${i}`,p._functionID=p.id.replaceAll(/[^a-zA-Z0-9_]/g,"_")}let c=new ye({fields:["id","type","name","content","tags"],storeFields:[],searchOptions:{boost:{name:3,tags:2},fuzzy:.2}});c.addAll(o);let d=c.search(e).map(i=>o.find(p=>p.id==i.id)).filter(Boolean),a=0;d=d.filter(i=>{if(i.isContext)return!0;let p=(i.content||"").length;return a+p>be?!1:(a+=p,!0)});for(let i of o)i.isContext&&(d.find(p=>p.id===i.id)||d.push(i));return this.lastResults=d,I(this.ai,{event_type:"kb_search",value:d.length,value_str:"",event_properties:{search_time_ms:Date.now()-t,sources_searched:this.sources.length}}),k.debug("Found results:",d),d}getCachedEntry(e){return this.lastResults.find(t=>t.id==e||t._functionID==e)}registerSourceFromURL(e,t){t||(t=`external.${L++}`),k.debug(`Registering remote knowledge base source: ${e}`);let n=[],s=[],o=!0,r=async(l,d)=>{k.debug(`Calling remote knowledge base action: ${l.id}`);let a={type:"action",userID:this.ai.userID,actionID:l.id,parameters:d},i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(`HTTP Error ${i.status} ${i.statusText}`);let p=await i.json();return c(p.updateItems||[]),p.response},c=l=>{for(let d of l){if(!d.id){k.warn("KB item skipped since it has no ID.",d);continue}let a=n.find(i=>i.id==d.id);if(a){a.name=d.name||a.name||"",a.content=d.content||a.content||"",a.disabled=d.disabled??a.disabled,a.isContext=d.isContext??a.isContext,a.parameters=d.parameters||a.parameters||[],a.tags=d.tags||a.tags,a.type=d.type||a.type;continue}n.push({...d,action:i=>r(d,i)})}};this.registerSource(t,async l=>{if(o&&s.includes(l))return n;let d={type:"search",userID:this.ai?.userID||"",query:l},a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!a.ok)throw new Error(`HTTP Error ${a.status} ${a.statusText}`);let i=await a.json();return o=!i.noCache,s.includes(l)||s.push(l),c(i.items),n})}clone(e){let t=new u(e);return t._sources=this._sources.slice(),t._windowSources=this._windowSources.slice(),t.manualEntries=this.manualEntries.slice(),t.allowGlobalConfigSources=this.allowGlobalConfigSources,t.allowWindowSources=this.allowWindowSources,t.allowRagSearch=this.allowRagSearch,t.ensureInternalKnowledge(),t}registerMCPSource(e){e.id||(e.id=`external.${L++}`);let t=new W(e);return this.registerSource(e.id,n=>t.search(n)),t}};function ve(u){let e="",t=[],n=0;for(;n<u.length;){let s=u.indexOf("<[[",n);if(s===-1){e+=u.slice(n);break}e+=u.slice(n,s);let o=u.indexOf("]]>",s+3);if(o===-1)break;let r=u.slice(s,o+3),c=u.slice(s+3,o).trim(),l={raw:r,content:c};try{let d=JSON.parse(c);d&&typeof d=="object"&&!Array.isArray(d)&&(l.action=d)}catch{}t.push(l),n=o+3}return{visibleText:e,actions:t.flatMap(s=>s.action?[s.action]:[]),blocks:t}}function Z(u){return ve(u).visibleText}var R=class{constructor(e){this.messages=e}text(){return this.messages?.flatMap(e=>e.sections)?.filter(e=>e?.type=="text")?.map(e=>Z(e?.text||""))?.filter(e=>!!e)?.join(`
|
|
22
22
|
|
|
23
23
|
`)?.trim()||""}tokenUsage(){return{cachedInputTokens:this.messages?.reduce((e,t)=>e+(t.usage?.cachedInputTokens||0),0)||0,inputTokens:this.messages?.reduce((e,t)=>e+(t.usage?.inputTokens||0),0)||0,outputTokens:this.messages?.reduce((e,t)=>e+(t.usage?.outputTokens||0),0)||0,totalTokens:this.messages?.reduce((e,t)=>e+(t.usage?.totalTokens||0),0)||0}}sections(){return this.messages?.flatMap(e=>e.sections||[])||[]}toolCalls(){return this.messages?.flatMap(e=>e.sections?.filter(t=>t.type=="tool_call")||[])||[]}toolResult(e){return this.messages?.map(t=>t.sections?.find(n=>n.type=="tool_result"&&n.toolCallInstanceID==e)).filter(t=>!!t)[0]||null}};import{v4 as ee}from"uuid";var K=class{constructor(e){this.ai=e}async boolean(e){let t=await this.instruct({...e,instruction:`${e.instruction}
|
|
24
24
|
|
package/dist/react/react.js
CHANGED
|
@@ -12,7 +12,7 @@ New information found:
|
|
|
12
12
|
${o}
|
|
13
13
|
|
|
14
14
|
New tools available:
|
|
15
|
-
${s}`}},{id:"ui.openURL",type:"action",name:"Open a URL in a new tab.",tags:"open, url, website, navigate, visit, go to, new tab, browser",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowOpenNewTab,content:"Opens the specified URL in a new tab. Use this when the user asks to open a website, visit a URL, go to a page, or navigate to a specific website. Only available when allowOpenNewTab flag is enabled.",parameters:[{name:"url",type:"string",description:"The URL to open in a new tab"}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowOpenNewTab)throw new Error("Open New Tab action is not enabled for this persona.");if(!n.url||typeof n.url!="string")throw new Error("URL parameter is required and must be a string.");if(!window.open(n.url,"_blank"))throw new Error("Window blocked by popup blocker. Please allow popups for this site.");return`Opened URL: ${n.url}`}},{id:"ui.changeRoute",type:"action",name:"Change the current page route.",tags:"navigate, route, path, page, go to, change page, routing, navigation",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowChangeRoute,content:"Changes the current page route to the specified path. Use this when the user asks to navigate to a different page, go to a specific section, or change the current page route. Only available when allowChangeRoute flag is enabled.",parameters:[{name:"path",type:"string",description:'The path to navigate to (e.g., "/home", "/dashboard")'}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowChangeRoute)throw new Error("Change Route action is not enabled for this persona.");if(!n.path||typeof n.path!="string")throw new Error("Path parameter is required and must be a string.");let t=new URL(n.path,window.location.origin).pathname;return window.location.href=t,`Changed route to: ${t}`}},{id:"ui.sendEmail",type:"action",name:"Send an email",tags:"email, send, mail, compose, message, contact, mailto",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowSendEmail,content:"Sends an email using the user's default mail client by opening a mailto: link. Use this when the user asks to send an email, compose a message, or contact someone via email. Only available when allowSendEmail flag is enabled.",parameters:[{name:"email_address",type:"string",description:"The recipient email address"},{name:"subject",type:"string",description:"The email subject line"},{name:"body",type:"string",description:"The email body content"}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowSendEmail)throw new Error("Send Email action is not enabled for this persona.");if(!n.email_address||typeof n.email_address!="string")throw new Error("Email address parameter is required and must be a string.");if(!n.subject||typeof n.subject!="string")throw new Error("Subject parameter is required and must be a string.");if(!n.body||typeof n.body!="string")throw new Error("Body parameter is required and must be a string.");let t=encodeURIComponent(n.email_address),i=encodeURIComponent(n.subject),o=encodeURIComponent(n.body),s=`mailto:${t}?subject=${i}&body=${o}`;try{window.location.href=s}catch(r){throw new Error(`Failed to open email client: ${r instanceof Error?r.message:String(r)}`)}return`Email opened in default mail client. Recipient: ${n.email_address}, Subject: ${n.subject}`}}];import{Client as Jt}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as $t}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var O={name:"@intelliweave/embedded",version:"2.2.81",description:"Integrate IntelliWeave into your app or website.",main:"./dist/webpack/index.js",types:"./dist/webpack/index.d.ts",type:"module",exports:{".":"./dist/webpack/index.js","./component":"./dist/component/component.js","./node":"./dist/node/node.js","./react":"./dist/react/react.js","./webpack":"./dist/webpack/index.js"},scripts:{build:"npm run build:lib && npm run build:docs","build:lib":"tsx build.ts","build:dev":"cross-env DEVELOPMENT=1 npm run build","build:docs":"typedoc src/index.mts --out dist/docs/",deploy:'npm run build && gsutil cp ./dist/web-weaver.min.js gs://metapress-cdn/web-weaver.min.js && gcloud compute url-maps invalidate-cdn-cache mp-cdn-loadbalancer --project="mp-backend-api" --path "/web-weaver.min.js" --async',"start:server":"cd server && npm run start","deploy:server":"cd server && npm run deploy","llm:build":"cd llm-server && docker build -t web-weaver-llm .","llm:start":"npm run llm:build && docker run -it --rm -p 8000:80 --gpus=all web-weaver-llm","llm:deploy.docker":"npm run llm:build && gcloud auth configure-docker us-central1-docker.pkg.dev && docker tag web-weaver-llm us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm && docker push us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm","llm:deploy":'npm run llm:deploy.docker && gcloud run deploy web-weaver-llm --project=ydangle-web-companion --image=us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm --allow-unauthenticated --region=us-central1 --description="Web Weaver LLM" --concurrency=2 --min-instances=0 --timeout=5m --memory=16Gi --cpu=8',prepack:"npm run build",test:"npm run build && vitest run","test:local":"IW_API_URL=http://localhost:3000/api npm run test"},keywords:["web","weaver","ai","assistant","chat"],author:"jjv360",license:"UNLICENSED",devDependencies:{"@types/audioworklet":"^0.0.97","@types/lodash":"^4.17.24","@types/react":"^19.2.14",bestzip:"^2.2.2","cross-env":"^10.1.0","find-cache-dir":"^6.0.0",lodash:"^4.17.23","onnxruntime-web":"^1.24.3",react:"^19.2.4","replace-in-file":"^8.4.0",tsup:"^8.5.1",tsx:"^4.21.0",typedoc:"^0.28.18",vitest:"^4.1.0"},peerDependencies:{"onnxruntime-web":"^1.20.0",react:"^18 || ^19"},dependencies:{"@anthropic-ai/sdk":"^0.80.0","@modelcontextprotocol/sdk":"^1.27.1","@types/json-schema":"^7.0.15",minisearch:"^7.2.0",openai:"^6.32.0","rehype-document":"^7.0.3","rehype-external-links":"^3.0.0","rehype-format":"^5.0.1","rehype-stringify":"^10.0.1","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",unified:"^11.0.5","utility-types":"^3.11.0",uuid:"^13.0.0"}};import{LoggingMessageNotificationSchema as Qt,ToolListChangedNotificationSchema as qt}from"@modelcontextprotocol/sdk/types.js";var I=new f("MCPKnowledgeClient"),ei="https://intelliweave-mcp-proxy-828827766277.us-central1.run.app",Ee=class{constructor(n){this.tools=[];this.iwActions=[];this.stats={toolsCalled:0};this.lastSearchQuery="";this.lastSearchResults=[];this.config=n}async connect(){return this.client?this.client:this.connectionPromise?await this.connectionPromise:(this.connectionPromise=this.connectInternal(),this.connectionPromise.finally(()=>{this.connectionPromise=void 0}),await this.connectionPromise)}async connectInternal(){I.debug("Connecting to MCP client");let n=this.config.connect?await this.config.connect():await Promise.resolve().then(async()=>{let e=new URL(this.config.baseURL),t={};this.config.headers&&(t={...t,...this.config.headers}),this.config.proxy?.enabled&&(t["Mcp-Target-Url"]=e.toString(),t["IntelliWeave-Api-Key"]=this.config.proxy.apiKey||"",e=new URL(this.config.proxy.url||ei));let i=new Jt({name:O.name,version:O.version}),o=new $t(e,{requestInit:{headers:t}});return await i.connect(o),I.debug("Connected with HTTP streaming mode"),i});return await this.disconnect(),this.client=n,n.onerror=e=>{I.error(`MCP client error: ${e.message}`)},n.onclose=()=>{I.debug("MCP client connection closed"),this.client=void 0},n.setNotificationHandler(Qt,e=>{e.params.level=="critical"?I.error(`[Server] ${e.params.data}`):e.params.level=="emergency"?I.error(`[Server] ${e.params.data}`):e.params.level=="error"?I.error(`[Server] ${e.params.data}`):e.params.level=="warning"?I.warn(`[Server] ${e.params.data}`):e.params.level=="info"?I.info(`[Server] ${e.params.data}`):e.params.level=="debug"?I.debug(`[Server] ${e.params.data}`):I.log(`[Server] ${e.params.data}`)}),n.setNotificationHandler(qt,e=>{I.debug("Tool list changed",e),this.fetchTools()}),I.debug("Fetching tools from MCP server..."),await this.fetchTools(),n}async disconnect(){await this.client?.close(),this.client=void 0,this.tools=[],this.iwActions=[]}async fetchTools(){let n=[],e;for(;;){let o=await this.client.listTools({cursor:e});e=o.nextCursor;for(let s of o.tools||[])n.push(s);if(!o?.tools?.length||!e)break}let t=[],i=this.config.id||"mcp";for(let o of n){let s=!!(this.config.searchToolName&&o.name==this.config.searchToolName&&!this.config.searchToolVisible),r=`${i}_${o.name}`;t.push({id:r,name:o.name,content:o.description||"",type:"action",isContext:!0,parameters:o.inputSchema,action:l=>this.performToolCall(o.name,l),disabled:s})}I.debug(`Fetched ${n.length} tools from MCP server.`),this.tools=n,this.iwActions=t}async search(n){if(n==this.lastSearchQuery)return this.lastSearchResults;await this.connect();let e=this.iwActions.slice(),t=await this.performSearchCall(n);return e=e.concat(t),this.lastSearchQuery=n,this.lastSearchResults=e,I.debug(`Search completed, found ${e.length} items.`),e}async performSearchCall(n){let e=[];if(!this.config.searchToolName)return e;let t=this.tools.find(o=>o.name==this.config.searchToolName);if(!t)return I.warn(`Search function ${this.config.searchToolName} not found on the MCP server.`),e;let i;if(t.inputSchema.required?.length==1){let o=t.inputSchema.required[0];i=await this.performToolCall(this.config.searchToolName,{[o]:n})}else if(t.inputSchema.properties&&Object.keys(t.inputSchema.properties).length==1){let o=Object.keys(t.inputSchema.properties)[0];i=await this.performToolCall(this.config.searchToolName,{[o]:n})}else i=await this.performToolCall(this.config.searchToolName,{});if(Array.isArray(i))for(let o=0;o<i.length;o++){let s=i[o];e.push({id:this.config.id+":"+this.config.searchToolName+":"+o,name:`Search result ${o+1} in ${this.config.searchToolName}`,type:"info",content:typeof s=="string"?s:JSON.stringify(s)})}else e.push({id:this.config.id+":"+this.config.searchToolName+":result",name:`Search result in ${this.config.searchToolName}`,type:"info",content:typeof i=="string"?i:JSON.stringify(i)});return e}async performToolCall(n,e){await this.connect(),I.debug(`Performing tool call for ${n} with params:`,e),this.stats.toolsCalled+=1;let t=await this.client.callTool({name:n,arguments:e});if(t.isError){let i=t.content?.[0]?.text||"Unknown error";throw I.error(`Error calling tool ${n}: ${i}`),new Error(`Error calling tool ${n}: ${i}`)}if(Array.isArray(t.content)&&t.content.length==1&&t.content[0].type=="text")try{return JSON.parse(t.content[0].text)}catch{}return t.content||[]}};import{v4 as ti}from"uuid";var ii=new f("Statistics"),ge=[];async function C(a,n){let e={...n,event_id:ti(),event_date:new Date().toISOString(),sdk_version:O.version,conversation_id:a?.conversationID||"",api_key:a?.apiKey||"",user_id:a?.userID||""};if(ge.push(e),!a||(await new Promise(i=>setTimeout(i,5e3)),ge.length===0))return;let t=ge.slice();ge.length=0;try{let i=await fetch(a.hubAPI+"/analytics/stats",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t})});if(!i.ok)throw new Error(`Analytics submission failed: ${i.status} ${i.statusText}`)}catch(i){ii.warn("Failed to submit analytics event:",i),ge.push(...t);return}}var V=new f("KnowledgeBase"),oi=8*1024,qe=1,Ae=class a{constructor(n){this._sources=[];this._windowSources=[];this.lastResults=[];this.manualEntries=[];this.allowWindowSources=!0;this.allowGlobalConfigSources=!0;this.allowRagSearch=!0;this.ai=n,this.ensureInternalKnowledge()}ensureInternalKnowledge(){this._sources=this._sources.filter(n=>n.id!=="core.internal"),this._sources.push({id:"core.internal",query:async()=>ft(this.ai)})}reset(){this._windowSources=[],this.manualEntries=[],this.lastResults=[],this._sources=[],this.ensureInternalKnowledge()}registerSource(n,e){let t=n;return typeof n=="function"&&(e=n,t=`source.${qe++}`),this._sources.push({id:t,query:e}),t}removeSource(n){this._sources=this.sources.filter(e=>e.id!==n&&e.query!==n)}addEntry(n){this.manualEntries.push(n)}removeEntry(n){this.manualEntries=this.manualEntries.filter(e=>e.id!==n)}get sources(){let n=this._sources;return this.allowGlobalConfigSources&&b().knowledgeBaseSources&&(n=n.concat(b().knowledgeBaseSources)),this.allowWindowSources&&typeof document<"u"&&(n=n.concat(this._windowSources)),n=n.filter(e=>!e.disabled),n}async search(n){V.debug(`Searching knowledge base for: ${n}`);let e=Date.now(),t=new Event("webweaver_kb_search",{bubbles:!0,cancelable:!0});t.query=n,t.entries=[],t.sources=[],this.allowWindowSources&&typeof document<"u"?(document.dispatchEvent(t),this._windowSources=t.sources):this._windowSources=[];let o=(await Promise.all(this.sources.map(async c=>{try{let h=Date.now(),p=await c.query(n);return V.debug(`Source '${c.id}' took ${Date.now()-h}ms`),p||[]}catch(h){return V.warn(`Knowledge source '${c.id}' failed:`,h),[]}}))).flat();o=o.concat(t.entries),o=o.concat(this.manualEntries),this.allowGlobalConfigSources&&b().knowledgeBase&&(o=o.concat(b().knowledgeBase)),o=o.filter(c=>c&&!c.disabled);let s=new Map;for(let c of o)c.id&&s.set(c.id,(s.get(c.id)||0)+1);for(let[c,h]of s)if(h>1){V.warn(`Duplicate knowledge base item ID detected: '${c}' appears ${h} times. Adding suffixes to make them unique.`);let p=1,m=!0;for(let g of o)if(g.id===c){if(m){m=!1;continue}g.id=`${c}(${p})`,p++}}for(let c=0;c<o.length;c++){let h=o[c];h.id=h.id||`temp.${c}`,h._functionID=h.id.replaceAll(/[^a-zA-Z0-9_]/g,"_")}let r=new ni({fields:["id","type","name","content","tags"],storeFields:[],searchOptions:{boost:{name:3,tags:2},fuzzy:.2}});r.addAll(o);let u=r.search(n).map(c=>o.find(h=>h.id==c.id)).filter(Boolean),d=0;u=u.filter(c=>{if(c.isContext)return!0;let h=(c.content||"").length;return d+h>oi?!1:(d+=h,!0)});for(let c of o)c.isContext&&(u.find(h=>h.id===c.id)||u.push(c));return this.lastResults=u,C(this.ai,{event_type:"kb_search",value:u.length,value_str:"",event_properties:{search_time_ms:Date.now()-e,sources_searched:this.sources.length}}),V.debug("Found results:",u),u}getCachedEntry(n){return this.lastResults.find(e=>e.id==n||e._functionID==n)}registerSourceFromURL(n,e){e||(e=`external.${qe++}`),V.debug(`Registering remote knowledge base source: ${n}`);let t=[],i=[],o=!0,s=async(l,u)=>{V.debug(`Calling remote knowledge base action: ${l.id}`);let d={type:"action",userID:this.ai.userID,actionID:l.id,parameters:u},c=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!c.ok)throw new Error(`HTTP Error ${c.status} ${c.statusText}`);let h=await c.json();return r(h.updateItems||[]),h.response},r=l=>{for(let u of l){if(!u.id){V.warn("KB item skipped since it has no ID.",u);continue}let d=t.find(c=>c.id==u.id);if(d){d.name=u.name||d.name||"",d.content=u.content||d.content||"",d.disabled=u.disabled??d.disabled,d.isContext=u.isContext??d.isContext,d.parameters=u.parameters||d.parameters||[],d.tags=u.tags||d.tags,d.type=u.type||d.type;continue}t.push({...u,action:c=>s(u,c)})}};this.registerSource(e,async l=>{if(o&&i.includes(l))return t;let u={type:"search",userID:this.ai?.userID||"",query:l},d=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!d.ok)throw new Error(`HTTP Error ${d.status} ${d.statusText}`);let c=await d.json();return o=!c.noCache,i.includes(l)||i.push(l),r(c.items),t})}clone(n){let e=new a(n);return e._sources=this._sources.slice(),e._windowSources=this._windowSources.slice(),e.manualEntries=this.manualEntries.slice(),e.allowGlobalConfigSources=this.allowGlobalConfigSources,e.allowWindowSources=this.allowWindowSources,e.allowRagSearch=this.allowRagSearch,e.ensureInternalKnowledge(),e}registerMCPSource(n){n.id||(n.id=`external.${qe++}`);let e=new Ee(n);return this.registerSource(n.id,t=>e.search(t)),e}};var Le=class{constructor(n){this.ai=n}async boolean(n){let e=await this.instruct({...n,instruction:`${n.instruction}
|
|
15
|
+
${s}`}},{id:"ui.openURL",type:"action",name:"Open a URL in a new tab.",tags:"open, url, website, navigate, visit, go to, new tab, browser",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowOpenNewTab,content:"Opens the specified URL in a new tab. Use this when the user asks to open a website, visit a URL, go to a page, or navigate to a specific website. Only available when allowOpenNewTab flag is enabled.",parameters:[{name:"url",type:"string",description:"The URL to open in a new tab"}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowOpenNewTab)throw new Error("Open New Tab action is not enabled for this persona.");if(!n.url||typeof n.url!="string")throw new Error("URL parameter is required and must be a string.");if(!window.open(n.url,"_blank"))throw new Error("Window blocked by popup blocker. Please allow popups for this site.");return`Opened URL: ${n.url}`}},{id:"ui.changeRoute",type:"action",name:"Change the current page route.",tags:"navigate, route, path, page, go to, change page, routing, navigation",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowChangeRoute,content:"Changes the current page route to the specified path. Use this when the user asks to navigate to a different page, go to a specific section, or change the current page route. Only available when allowChangeRoute flag is enabled.",parameters:[{name:"path",type:"string",description:'The path to navigate to (e.g., "/home", "/dashboard")'}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowChangeRoute)throw new Error("Change Route action is not enabled for this persona.");if(!n.path||typeof n.path!="string")throw new Error("Path parameter is required and must be a string.");let t=new URL(n.path,window.location.origin).pathname;return window.location.href=t,`Changed route to: ${t}`}},{id:"ui.sendEmail",type:"action",name:"Send an email",tags:"email, send, mail, compose, message, contact, mailto",isContext:!0,disabled:typeof window>"u"||!a?.flags?.allowSendEmail,content:"Sends an email using the user's default mail client by opening a mailto: link. Use this when the user asks to send an email, compose a message, or contact someone via email. Only available when allowSendEmail flag is enabled.",parameters:[{name:"email_address",type:"string",description:"The recipient email address"},{name:"subject",type:"string",description:"The email subject line"},{name:"body",type:"string",description:"The email body content"}],action:(n,e)=>{if(typeof window>"u")throw new Error("This action is only available in browser environments.");if(!e.flags.allowSendEmail)throw new Error("Send Email action is not enabled for this persona.");if(!n.email_address||typeof n.email_address!="string")throw new Error("Email address parameter is required and must be a string.");if(!n.subject||typeof n.subject!="string")throw new Error("Subject parameter is required and must be a string.");if(!n.body||typeof n.body!="string")throw new Error("Body parameter is required and must be a string.");let t=encodeURIComponent(n.email_address),i=encodeURIComponent(n.subject),o=encodeURIComponent(n.body),s=`mailto:${t}?subject=${i}&body=${o}`;try{window.location.href=s}catch(r){throw new Error(`Failed to open email client: ${r instanceof Error?r.message:String(r)}`)}return`Email opened in default mail client. Recipient: ${n.email_address}, Subject: ${n.subject}`}}];import{Client as Jt}from"@modelcontextprotocol/sdk/client/index.js";import{StreamableHTTPClientTransport as $t}from"@modelcontextprotocol/sdk/client/streamableHttp.js";var O={name:"@intelliweave/embedded",version:"2.2.82",description:"Integrate IntelliWeave into your app or website.",main:"./dist/webpack/index.js",types:"./dist/webpack/index.d.ts",type:"module",exports:{".":"./dist/webpack/index.js","./component":"./dist/component/component.js","./node":"./dist/node/node.js","./react":"./dist/react/react.js","./webpack":"./dist/webpack/index.js"},scripts:{build:"npm run build:lib && npm run build:docs","build:lib":"tsx build.ts","build:dev":"cross-env DEVELOPMENT=1 npm run build","build:docs":"typedoc src/index.mts --out dist/docs/",deploy:'npm run build && gsutil cp ./dist/web-weaver.min.js gs://metapress-cdn/web-weaver.min.js && gcloud compute url-maps invalidate-cdn-cache mp-cdn-loadbalancer --project="mp-backend-api" --path "/web-weaver.min.js" --async',"start:server":"cd server && npm run start","deploy:server":"cd server && npm run deploy","llm:build":"cd llm-server && docker build -t web-weaver-llm .","llm:start":"npm run llm:build && docker run -it --rm -p 8000:80 --gpus=all web-weaver-llm","llm:deploy.docker":"npm run llm:build && gcloud auth configure-docker us-central1-docker.pkg.dev && docker tag web-weaver-llm us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm && docker push us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm","llm:deploy":'npm run llm:deploy.docker && gcloud run deploy web-weaver-llm --project=ydangle-web-companion --image=us-central1-docker.pkg.dev/ydangle-web-companion/docker-artifacts/web-weaver-llm --allow-unauthenticated --region=us-central1 --description="Web Weaver LLM" --concurrency=2 --min-instances=0 --timeout=5m --memory=16Gi --cpu=8',prepack:"npm run build",test:"npm run build && vitest run","test:local":"IW_API_URL=http://localhost:3000/api npm run test"},keywords:["web","weaver","ai","assistant","chat"],author:"jjv360",license:"UNLICENSED",devDependencies:{"@types/audioworklet":"^0.0.97","@types/lodash":"^4.17.24","@types/react":"^19.2.14",bestzip:"^2.2.2","cross-env":"^10.1.0","find-cache-dir":"^6.0.0",lodash:"^4.17.23","onnxruntime-web":"^1.24.3",react:"^19.2.4","replace-in-file":"^8.4.0",tsup:"^8.5.1",tsx:"^4.21.0",typedoc:"^0.28.18",vitest:"^4.1.0"},peerDependencies:{"onnxruntime-web":"^1.20.0",react:"^18 || ^19"},dependencies:{"@anthropic-ai/sdk":"^0.80.0","@modelcontextprotocol/sdk":"^1.27.1","@types/json-schema":"^7.0.15",minisearch:"^7.2.0",openai:"^6.32.0","rehype-document":"^7.0.3","rehype-external-links":"^3.0.0","rehype-format":"^5.0.1","rehype-stringify":"^10.0.1","remark-gfm":"^4.0.1","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",unified:"^11.0.5","utility-types":"^3.11.0",uuid:"^13.0.0"}};import{LoggingMessageNotificationSchema as Qt,ToolListChangedNotificationSchema as qt}from"@modelcontextprotocol/sdk/types.js";var I=new f("MCPKnowledgeClient"),ei="https://intelliweave-mcp-proxy-828827766277.us-central1.run.app",Ee=class{constructor(n){this.tools=[];this.iwActions=[];this.stats={toolsCalled:0};this.lastSearchQuery="";this.lastSearchResults=[];this.config=n}async connect(){return this.client?this.client:this.connectionPromise?await this.connectionPromise:(this.connectionPromise=this.connectInternal(),this.connectionPromise.finally(()=>{this.connectionPromise=void 0}),await this.connectionPromise)}async connectInternal(){I.debug("Connecting to MCP client");let n=this.config.connect?await this.config.connect():await Promise.resolve().then(async()=>{let e=new URL(this.config.baseURL),t={};this.config.headers&&(t={...t,...this.config.headers}),this.config.proxy?.enabled&&(t["Mcp-Target-Url"]=e.toString(),t["IntelliWeave-Api-Key"]=this.config.proxy.apiKey||"",e=new URL(this.config.proxy.url||ei));let i=new Jt({name:O.name,version:O.version}),o=new $t(e,{requestInit:{headers:t}});return await i.connect(o),I.debug("Connected with HTTP streaming mode"),i});return await this.disconnect(),this.client=n,n.onerror=e=>{I.error(`MCP client error: ${e.message}`)},n.onclose=()=>{I.debug("MCP client connection closed"),this.client=void 0},n.setNotificationHandler(Qt,e=>{e.params.level=="critical"?I.error(`[Server] ${e.params.data}`):e.params.level=="emergency"?I.error(`[Server] ${e.params.data}`):e.params.level=="error"?I.error(`[Server] ${e.params.data}`):e.params.level=="warning"?I.warn(`[Server] ${e.params.data}`):e.params.level=="info"?I.info(`[Server] ${e.params.data}`):e.params.level=="debug"?I.debug(`[Server] ${e.params.data}`):I.log(`[Server] ${e.params.data}`)}),n.setNotificationHandler(qt,e=>{I.debug("Tool list changed",e),this.fetchTools()}),I.debug("Fetching tools from MCP server..."),await this.fetchTools(),n}async disconnect(){await this.client?.close(),this.client=void 0,this.tools=[],this.iwActions=[]}async fetchTools(){let n=[],e;for(;;){let o=await this.client.listTools({cursor:e});e=o.nextCursor;for(let s of o.tools||[])n.push(s);if(!o?.tools?.length||!e)break}let t=[],i=this.config.id||"mcp";for(let o of n){let s=!!(this.config.searchToolName&&o.name==this.config.searchToolName&&!this.config.searchToolVisible),r=`${i}_${o.name}`;t.push({id:r,name:o.name,content:o.description||"",type:"action",isContext:!0,parameters:o.inputSchema,action:l=>this.performToolCall(o.name,l),disabled:s})}I.debug(`Fetched ${n.length} tools from MCP server.`),this.tools=n,this.iwActions=t}async search(n){if(n==this.lastSearchQuery)return this.lastSearchResults;await this.connect();let e=this.iwActions.slice(),t=await this.performSearchCall(n);return e=e.concat(t),this.lastSearchQuery=n,this.lastSearchResults=e,I.debug(`Search completed, found ${e.length} items.`),e}async performSearchCall(n){let e=[];if(!this.config.searchToolName)return e;let t=this.tools.find(o=>o.name==this.config.searchToolName);if(!t)return I.warn(`Search function ${this.config.searchToolName} not found on the MCP server.`),e;let i;if(t.inputSchema.required?.length==1){let o=t.inputSchema.required[0];i=await this.performToolCall(this.config.searchToolName,{[o]:n})}else if(t.inputSchema.properties&&Object.keys(t.inputSchema.properties).length==1){let o=Object.keys(t.inputSchema.properties)[0];i=await this.performToolCall(this.config.searchToolName,{[o]:n})}else i=await this.performToolCall(this.config.searchToolName,{});if(Array.isArray(i))for(let o=0;o<i.length;o++){let s=i[o];e.push({id:this.config.id+":"+this.config.searchToolName+":"+o,name:`Search result ${o+1} in ${this.config.searchToolName}`,type:"info",content:typeof s=="string"?s:JSON.stringify(s)})}else e.push({id:this.config.id+":"+this.config.searchToolName+":result",name:`Search result in ${this.config.searchToolName}`,type:"info",content:typeof i=="string"?i:JSON.stringify(i)});return e}async performToolCall(n,e){await this.connect(),I.debug(`Performing tool call for ${n} with params:`,e),this.stats.toolsCalled+=1;let t=await this.client.callTool({name:n,arguments:e});if(t.isError){let i=t.content?.[0]?.text||"Unknown error";throw I.error(`Error calling tool ${n}: ${i}`),new Error(`Error calling tool ${n}: ${i}`)}if(Array.isArray(t.content)&&t.content.length==1&&t.content[0].type=="text")try{return JSON.parse(t.content[0].text)}catch{}return t.content||[]}};import{v4 as ti}from"uuid";var ii=new f("Statistics"),ge=[];async function C(a,n){let e={...n,event_id:ti(),event_date:new Date().toISOString(),sdk_version:O.version,conversation_id:a?.conversationID||"",api_key:a?.apiKey||"",user_id:a?.userID||""};if(ge.push(e),!a||(await new Promise(i=>setTimeout(i,5e3)),ge.length===0))return;let t=ge.slice();ge.length=0;try{let i=await fetch(a.hubAPI+"/analytics/stats",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({events:t})});if(!i.ok)throw new Error(`Analytics submission failed: ${i.status} ${i.statusText}`)}catch(i){ii.warn("Failed to submit analytics event:",i),ge.push(...t);return}}var V=new f("KnowledgeBase"),oi=8*1024,qe=1,Ae=class a{constructor(n){this._sources=[];this._windowSources=[];this.lastResults=[];this.manualEntries=[];this.allowWindowSources=!0;this.allowGlobalConfigSources=!0;this.allowRagSearch=!0;this.ai=n,this.ensureInternalKnowledge()}ensureInternalKnowledge(){this._sources=this._sources.filter(n=>n.id!=="core.internal"),this._sources.push({id:"core.internal",query:async()=>ft(this.ai)})}reset(){this._windowSources=[],this.manualEntries=[],this.lastResults=[],this._sources=[],this.ensureInternalKnowledge()}registerSource(n,e){let t=n;return typeof n=="function"&&(e=n,t=`source.${qe++}`),this._sources.push({id:t,query:e}),t}removeSource(n){this._sources=this.sources.filter(e=>e.id!==n&&e.query!==n)}addEntry(n){this.manualEntries.push(n)}removeEntry(n){this.manualEntries=this.manualEntries.filter(e=>e.id!==n)}get sources(){let n=this._sources;return this.allowGlobalConfigSources&&b().knowledgeBaseSources&&(n=n.concat(b().knowledgeBaseSources)),this.allowWindowSources&&typeof document<"u"&&(n=n.concat(this._windowSources)),n=n.filter(e=>!e.disabled),n}async search(n){V.debug(`Searching knowledge base for: ${n}`);let e=Date.now(),t=new Event("webweaver_kb_search",{bubbles:!0,cancelable:!0});t.query=n,t.entries=[],t.sources=[],this.allowWindowSources&&typeof document<"u"?(document.dispatchEvent(t),this._windowSources=t.sources):this._windowSources=[];let o=(await Promise.all(this.sources.map(async c=>{try{let h=Date.now(),p=await c.query(n);return V.debug(`Source '${c.id}' took ${Date.now()-h}ms`),p||[]}catch(h){return V.warn(`Knowledge source '${c.id}' failed:`,h),[]}}))).flat();o=o.concat(t.entries),o=o.concat(this.manualEntries),this.allowGlobalConfigSources&&b().knowledgeBase&&(o=o.concat(b().knowledgeBase)),o=o.filter(c=>c&&!c.disabled);let s=new Map;for(let c of o)c.id&&s.set(c.id,(s.get(c.id)||0)+1);for(let[c,h]of s)if(h>1){V.warn(`Duplicate knowledge base item ID detected: '${c}' appears ${h} times. Adding suffixes to make them unique.`);let p=1,m=!0;for(let g of o)if(g.id===c){if(m){m=!1;continue}g.id=`${c}(${p})`,p++}}for(let c=0;c<o.length;c++){let h=o[c];h.id=h.id||`temp.${c}`,h._functionID=h.id.replaceAll(/[^a-zA-Z0-9_]/g,"_")}let r=new ni({fields:["id","type","name","content","tags"],storeFields:[],searchOptions:{boost:{name:3,tags:2},fuzzy:.2}});r.addAll(o);let u=r.search(n).map(c=>o.find(h=>h.id==c.id)).filter(Boolean),d=0;u=u.filter(c=>{if(c.isContext)return!0;let h=(c.content||"").length;return d+h>oi?!1:(d+=h,!0)});for(let c of o)c.isContext&&(u.find(h=>h.id===c.id)||u.push(c));return this.lastResults=u,C(this.ai,{event_type:"kb_search",value:u.length,value_str:"",event_properties:{search_time_ms:Date.now()-e,sources_searched:this.sources.length}}),V.debug("Found results:",u),u}getCachedEntry(n){return this.lastResults.find(e=>e.id==n||e._functionID==n)}registerSourceFromURL(n,e){e||(e=`external.${qe++}`),V.debug(`Registering remote knowledge base source: ${n}`);let t=[],i=[],o=!0,s=async(l,u)=>{V.debug(`Calling remote knowledge base action: ${l.id}`);let d={type:"action",userID:this.ai.userID,actionID:l.id,parameters:u},c=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)});if(!c.ok)throw new Error(`HTTP Error ${c.status} ${c.statusText}`);let h=await c.json();return r(h.updateItems||[]),h.response},r=l=>{for(let u of l){if(!u.id){V.warn("KB item skipped since it has no ID.",u);continue}let d=t.find(c=>c.id==u.id);if(d){d.name=u.name||d.name||"",d.content=u.content||d.content||"",d.disabled=u.disabled??d.disabled,d.isContext=u.isContext??d.isContext,d.parameters=u.parameters||d.parameters||[],d.tags=u.tags||d.tags,d.type=u.type||d.type;continue}t.push({...u,action:c=>s(u,c)})}};this.registerSource(e,async l=>{if(o&&i.includes(l))return t;let u={type:"search",userID:this.ai?.userID||"",query:l},d=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!d.ok)throw new Error(`HTTP Error ${d.status} ${d.statusText}`);let c=await d.json();return o=!c.noCache,i.includes(l)||i.push(l),r(c.items),t})}clone(n){let e=new a(n);return e._sources=this._sources.slice(),e._windowSources=this._windowSources.slice(),e.manualEntries=this.manualEntries.slice(),e.allowGlobalConfigSources=this.allowGlobalConfigSources,e.allowWindowSources=this.allowWindowSources,e.allowRagSearch=this.allowRagSearch,e.ensureInternalKnowledge(),e}registerMCPSource(n){n.id||(n.id=`external.${qe++}`);let e=new Ee(n);return this.registerSource(n.id,t=>e.search(t)),e}};var Le=class{constructor(n){this.ai=n}async boolean(n){let e=await this.instruct({...n,instruction:`${n.instruction}
|
|
16
16
|
|
|
17
17
|
Return only the text "true" or "false" to indicate the answer to the question. Do not include any additional text or explanations.`});if(e.toLowerCase().includes("true"))return!0;if(e.toLowerCase().includes("false"))return!1;throw new Error("The AI did not give a boolean answer: "+e)}async choose(n){let e=await this.instruct({...n,instruction:`${n.instruction}
|
|
18
18
|
|
|
@@ -250,7 +250,7 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
250
250
|
color: #061017;
|
|
251
251
|
opacity: 1;
|
|
252
252
|
}
|
|
253
|
-
:host([layout="widget"]) #send-button
|
|
253
|
+
:host([layout="widget"]) #send-button
|
|
254
254
|
background: var(--iw-send-btn-gradient, linear-gradient(135deg, #0b7aa1, 55%, #a34b0d));
|
|
255
255
|
opacity: 1;
|
|
256
256
|
}
|
|
@@ -603,14 +603,14 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
603
603
|
|
|
604
604
|
#root #poweredby {
|
|
605
605
|
width: 100%;
|
|
606
|
-
height:
|
|
606
|
+
height: 18px;
|
|
607
607
|
background-color: rgba(0, 0, 0, 0.3);
|
|
608
608
|
border-top: 1px solid rgba(255, 255, 255, 0.1);
|
|
609
609
|
display: flex;
|
|
610
610
|
align-items: center;
|
|
611
611
|
justify-content: center;
|
|
612
612
|
overflow: hidden;
|
|
613
|
-
font-size:
|
|
613
|
+
font-size: 10px;
|
|
614
614
|
color: var(--intelliweave-text-color, white);
|
|
615
615
|
opacity: 0.7;
|
|
616
616
|
border-bottom-right-radius: 16px;
|
|
@@ -905,26 +905,32 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
905
905
|
}
|
|
906
906
|
|
|
907
907
|
:host a, :host a:visited {
|
|
908
|
-
color: rgba(128, 192, 255, 1);
|
|
909
|
-
text-decoration:
|
|
908
|
+
color: var(--intelliweave-text-color, rgba(128, 192, 255, 1));
|
|
909
|
+
text-decoration: underline;
|
|
910
|
+
font-weight: bold;
|
|
910
911
|
}
|
|
911
912
|
#root.layout-fullscreen #interaction-bar {
|
|
913
|
+
/* Make the fullscreen input treatment read as a full-width bottom banner. */
|
|
912
914
|
width: 100%;
|
|
913
|
-
max-width:
|
|
914
|
-
margin:
|
|
915
|
-
border-radius:
|
|
915
|
+
max-width: none;
|
|
916
|
+
margin: 0;
|
|
917
|
+
border-radius: 0;
|
|
916
918
|
overflow: hidden;
|
|
919
|
+
flex: 0 0 auto;
|
|
917
920
|
}
|
|
918
921
|
#root.layout-fullscreen #interaction-bar {
|
|
919
922
|
background: var(--intelliweave-fullscreen-input-section-bg, var(--intelliweave-interaction-bg, rgba(32, 38, 44, 0.9)));
|
|
920
923
|
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
|
921
924
|
backdrop-filter: blur(16px);
|
|
922
925
|
-webkit-backdrop-filter: blur(16px);
|
|
926
|
+
padding: 8px 15% 6px;
|
|
923
927
|
}
|
|
924
928
|
@media (max-width: 768px) {
|
|
925
929
|
#root.layout-fullscreen #interaction-bar {
|
|
926
|
-
|
|
927
|
-
|
|
930
|
+
/* Keep the fullscreen input banner edge-to-edge on mobile too. */
|
|
931
|
+
width: 100%;
|
|
932
|
+
margin-bottom: 0;
|
|
933
|
+
padding: 8px 12px 8px;
|
|
928
934
|
}
|
|
929
935
|
}
|
|
930
936
|
|
|
@@ -1158,6 +1164,13 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1158
1164
|
}
|
|
1159
1165
|
#root.layout-fullscreen #fullscreen-header {
|
|
1160
1166
|
border-bottom: none;
|
|
1167
|
+
align-items: center;
|
|
1168
|
+
/* Align the persona logo with the fullscreen conversation column. */
|
|
1169
|
+
padding: 24px 15% 16px;
|
|
1170
|
+
}
|
|
1171
|
+
#root.layout-fullscreen.container-mode #fullscreen-header {
|
|
1172
|
+
/* Container embeds should keep their compact local padding. */
|
|
1173
|
+
padding: 14px 14px 12px;
|
|
1161
1174
|
}
|
|
1162
1175
|
#root.open #fullscreen-header {
|
|
1163
1176
|
display: flex;
|
|
@@ -1319,6 +1332,8 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1319
1332
|
border-radius: 16px;
|
|
1320
1333
|
background: var(--intelliweave-assistant-bubble-bg, linear-gradient(135deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035)));
|
|
1321
1334
|
color: var(--intelliweave-assistant-bubble-text, inherit);
|
|
1335
|
+
font-size: 15px;
|
|
1336
|
+
line-height: 1.6;
|
|
1322
1337
|
text-align: left;
|
|
1323
1338
|
}
|
|
1324
1339
|
#root.layout-fullscreen:not(.container-mode) #web-weaver-embed-inner > .input {
|
|
@@ -1333,8 +1348,8 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1333
1348
|
border-color: var(--intelliweave-user-bubble-border, rgba(34, 211, 238, 0.25));
|
|
1334
1349
|
background: var(--intelliweave-user-bubble-bg, linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(34, 211, 238, 0.07)));
|
|
1335
1350
|
color: var(--intelliweave-user-bubble-text, inherit);
|
|
1336
|
-
font-size:
|
|
1337
|
-
line-height: 1.
|
|
1351
|
+
font-size: 15px;
|
|
1352
|
+
line-height: 1.6;
|
|
1338
1353
|
opacity: 1;
|
|
1339
1354
|
}
|
|
1340
1355
|
#root.layout-fullscreen:not(.container-mode) #web-weaver-embed-inner > .output,
|
|
@@ -1356,8 +1371,8 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1356
1371
|
border-color: var(--intelliweave-assistant-bubble-border, rgba(255, 255, 255, 0.12));
|
|
1357
1372
|
background: var(--intelliweave-assistant-bubble-bg, linear-gradient(135deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035)));
|
|
1358
1373
|
color: var(--intelliweave-assistant-bubble-text, inherit);
|
|
1359
|
-
font-size:
|
|
1360
|
-
line-height: 1.
|
|
1374
|
+
font-size: 15px;
|
|
1375
|
+
line-height: 1.6;
|
|
1361
1376
|
opacity: 1;
|
|
1362
1377
|
}
|
|
1363
1378
|
#root.layout-fullscreen:not(.container-mode) #web-weaver-embed-inner > .output-container {
|
|
@@ -1378,8 +1393,8 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1378
1393
|
border-color: var(--intelliweave-assistant-bubble-border, rgba(255, 255, 255, 0.12));
|
|
1379
1394
|
background: var(--intelliweave-assistant-bubble-bg, linear-gradient(135deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.035)));
|
|
1380
1395
|
color: var(--intelliweave-assistant-bubble-text, inherit);
|
|
1381
|
-
font-size:
|
|
1382
|
-
line-height: 1.
|
|
1396
|
+
font-size: 15px;
|
|
1397
|
+
line-height: 1.6;
|
|
1383
1398
|
opacity: 1;
|
|
1384
1399
|
}
|
|
1385
1400
|
#web-weaver-embed-inner .output-container {
|
|
@@ -1402,15 +1417,31 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1402
1417
|
}
|
|
1403
1418
|
#web-weaver-embed-inner .output strong,
|
|
1404
1419
|
#web-weaver-embed-inner .info-block-text strong {
|
|
1405
|
-
color
|
|
1420
|
+
/* Bold markdown should keep the configured message text color in light themes. */
|
|
1421
|
+
color: inherit;
|
|
1406
1422
|
font-weight: 950;
|
|
1407
1423
|
}
|
|
1424
|
+
#web-weaver-embed-inner .output h1,
|
|
1425
|
+
#web-weaver-embed-inner .output h2,
|
|
1426
|
+
#web-weaver-embed-inner .output h3,
|
|
1427
|
+
#web-weaver-embed-inner .output h4,
|
|
1428
|
+
#web-weaver-embed-inner .output h5,
|
|
1429
|
+
#web-weaver-embed-inner .output h6,
|
|
1430
|
+
#web-weaver-embed-inner .info-block-text h1,
|
|
1431
|
+
#web-weaver-embed-inner .info-block-text h2,
|
|
1432
|
+
#web-weaver-embed-inner .info-block-text h3,
|
|
1433
|
+
#web-weaver-embed-inner .info-block-text h4,
|
|
1434
|
+
#web-weaver-embed-inner .info-block-text h5,
|
|
1435
|
+
#web-weaver-embed-inner .info-block-text h6 {
|
|
1436
|
+
/* Headings should not switch to the old forced light color. */
|
|
1437
|
+
color: inherit;
|
|
1438
|
+
}
|
|
1408
1439
|
#web-weaver-embed-inner .output code,
|
|
1409
1440
|
#web-weaver-embed-inner .info-block-text code {
|
|
1410
1441
|
padding: 0.08rem 0.28rem;
|
|
1411
1442
|
border-radius: 6px;
|
|
1412
1443
|
background: rgba(255, 255, 255, 0.08);
|
|
1413
|
-
color: #67E8F9;
|
|
1444
|
+
color: var(--intelliweave-text-color, #67E8F9);
|
|
1414
1445
|
font-size: 0.78em;
|
|
1415
1446
|
}
|
|
1416
1447
|
#web-weaver-embed-inner .suggestion-button {
|
|
@@ -1444,6 +1475,8 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1444
1475
|
border-color: var(--intelliweave-suggestion-button-border, rgba(236, 72, 153, 0.22));
|
|
1445
1476
|
background: var(--intelliweave-suggestion-button-bg, linear-gradient(135deg, rgba(236, 72, 153, 0.11), rgba(34, 211, 238, 0.07)));
|
|
1446
1477
|
color: var(--intelliweave-suggestion-button-text, inherit);
|
|
1478
|
+
/* Match the slightly larger fullscreen chat text scale. */
|
|
1479
|
+
font-size: 14px;
|
|
1447
1480
|
}
|
|
1448
1481
|
#root.layout-fullscreen #web-weaver-embed-inner .suggestion-button:hover {
|
|
1449
1482
|
border-color: var(--intelliweave-suggestion-button-hover-border, rgba(236, 72, 153, 0.42));
|
|
@@ -1469,13 +1502,14 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1469
1502
|
#poweredby {
|
|
1470
1503
|
display: none;
|
|
1471
1504
|
width: 100%;
|
|
1472
|
-
height
|
|
1505
|
+
/* Give the powered-by footer enough height to read clearly below the fullscreen input banner. */
|
|
1506
|
+
height: 28px;
|
|
1473
1507
|
align-items: center;
|
|
1474
1508
|
justify-content: center;
|
|
1475
1509
|
border-top: 1px solid rgba(255, 255, 255, 0.08);
|
|
1476
1510
|
background: rgba(7, 11, 13, 0.38);
|
|
1477
1511
|
color: rgba(230, 241, 245, 0.62);
|
|
1478
|
-
font-size:
|
|
1512
|
+
font-size: 10px;
|
|
1479
1513
|
}
|
|
1480
1514
|
#root.open #poweredby {
|
|
1481
1515
|
display: flex;
|
|
@@ -1506,6 +1540,10 @@ ${o}`,cannotRemove:i.isContext,sortOrder:101,disabled:typeof i.disabled=="functi
|
|
|
1506
1540
|
left: max(0px, env(safe-area-inset-left)) !important;
|
|
1507
1541
|
border-radius: 0;
|
|
1508
1542
|
}
|
|
1543
|
+
#root.layout-fullscreen #fullscreen-header {
|
|
1544
|
+
/* Avoid over-indenting the header on small screens. */
|
|
1545
|
+
padding: 14px 12px 12px;
|
|
1546
|
+
}
|
|
1509
1547
|
#dock-main .dock-title {
|
|
1510
1548
|
max-width: 112px;
|
|
1511
1549
|
overflow: hidden;
|