@intelliweave/embedded 2.2.81 → 2.2.83

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.
Binary file
@@ -1401,6 +1401,10 @@ interface WebWeaverGPTConfig {
1401
1401
  offsetY?: number;
1402
1402
  /** Custom brand name displayed in the panel header kicker (replaces "IntelliWeave"). */
1403
1403
  brandName?: string;
1404
+ /** Custom brand name color displayed in the panel header kicker. */
1405
+ brandNameColor?: string;
1406
+ /** If true, the built-in UI hides the powered-by footer after server-side subscription checks. */
1407
+ hidePoweredBy?: boolean;
1404
1408
  /** Identifier of an external app or service which manages this persona, if any. (eg. "chatterly") */
1405
1409
  managedBy?: string;
1406
1410
  /** Voice information */
@@ -1826,6 +1830,7 @@ declare class WebWeaverEmbed extends BaseComponent {
1826
1830
  private _lastOffsetX?;
1827
1831
  private _lastOffsetY?;
1828
1832
  private _lastBrandName?;
1833
+ private _lastBrandNameColor?;
1829
1834
  /** Apply persona-based color variants as CSS variables */
1830
1835
  private applyPersonaColorVariants;
1831
1836
  /** Parse a color string to RGB (supports hex and rgb/rgba) */
@@ -1839,6 +1844,10 @@ declare class WebWeaverEmbed extends BaseComponent {
1839
1844
  private applyConfigStylesAndAttributes;
1840
1845
  /** Called on update */
1841
1846
  onUpdate(): void;
1847
+ /** True when a config value explicitly enables a feature flag. */
1848
+ private isTruthyFeatureFlag;
1849
+ /** True when the current hub config or explicit attribute should remove the powered-by footer. */
1850
+ private shouldHidePoweredBy;
1842
1851
  /** Called when the component is created */
1843
1852
  onDestroy(): void;
1844
1853
  /** Called when the container is clicked */
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.83",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
 
@@ -1015,6 +1015,10 @@ interface WebWeaverGPTConfig {
1015
1015
  offsetY?: number;
1016
1016
  /** Custom brand name displayed in the panel header kicker (replaces "IntelliWeave"). */
1017
1017
  brandName?: string;
1018
+ /** Custom brand name color displayed in the panel header kicker. */
1019
+ brandNameColor?: string;
1020
+ /** If true, the built-in UI hides the powered-by footer after server-side subscription checks. */
1021
+ hidePoweredBy?: boolean;
1018
1022
  /** Identifier of an external app or service which manages this persona, if any. (eg. "chatterly") */
1019
1023
  managedBy?: string;
1020
1024
  /** Voice information */
@@ -1348,6 +1352,12 @@ declare const WebWeaverUI: (props: {
1348
1352
  positionX?: "left" | "right";
1349
1353
  /** Vertical position: 'top' or 'bottom' (default: 'bottom') - only used when positioningMode is 'fixed' */
1350
1354
  positionY?: "top" | "bottom";
1355
+ /** Custom brand name displayed in the panel header kicker. */
1356
+ brandName?: string;
1357
+ /** Custom brand name color displayed in the panel header kicker. */
1358
+ brandNameColor?: string;
1359
+ /** If true, hides the powered-by footer in the built-in UI. */
1360
+ hidePoweredBy?: boolean;
1351
1361
  }) => React.JSX.Element | null;
1352
1362
  /** Web Component ... React supports any registered Web Component with dashes in the name, but they don't get TypeScript definitions */
1353
1363
  declare global {