@heroui/agent 1.0.0-beta.7 → 1.0.0-beta.8
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/CHANGELOG.md +5 -0
- package/README.md +20 -2
- package/dist/chunk-2W6CUSN3.js +1 -0
- package/dist/chunk-KMVOOEIK.js +1 -0
- package/dist/chunk-KQ3FZPFS.js +1 -0
- package/dist/{chunk-MVHWCBZK.js → chunk-MUJYIDA4.js} +1 -1
- package/dist/{client-tools-manifest-3LJBKDBZ.js → client-tools-manifest-BD7O7M3V.js} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/internal/host.d.ts +2 -2
- package/dist/internal/host.js +1 -1
- package/dist/internal/shared.d.ts +4 -4
- package/dist/internal/shared.js +1 -1
- package/dist/next.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/{types-ZXWEIhzk.d.ts → types-Cuqd4_1K.d.ts} +10 -0
- package/dist/{version-0m_IH9PW.d.ts → version-DDaVFBVG.d.ts} +1 -1
- package/package.json +2 -2
- package/dist/chunk-7NL3SCZA.js +0 -1
- package/dist/chunk-BDMHEOR3.js +0 -1
- package/dist/chunk-MPJ6AAXH.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- Add `locale` to React and vanilla integrations, including `auto` for browser language detection, regional formatting, and optional `translations` for custom copy by language.
|
|
6
|
+
- Select localized agent copy using the SDK override or saved agent default. AI responses follow the user's language.
|
|
7
|
+
|
|
8
|
+
## Unreleased
|
|
9
|
+
|
|
5
10
|
- Move the model catalog, attachment limits and MIME allowlist, and design theme
|
|
6
11
|
list out of the published package and into the hosted runtime. Adding a model,
|
|
7
12
|
attachment type, or theme variant no longer requires a customer npm release.
|
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ package and is deployed through `agent.heroui.pro`.
|
|
|
14
14
|
## React installation
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
|
-
npm install @heroui/agent@
|
|
17
|
+
npm install @heroui/agent@latest
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## React (Vite) usage
|
|
@@ -156,7 +156,7 @@ The typed React bridge for embedding the hosted Agent iframe.
|
|
|
156
156
|
#### Installation
|
|
157
157
|
|
|
158
158
|
```bash
|
|
159
|
-
npm install @heroui/agent@
|
|
159
|
+
npm install @heroui/agent@latest
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
### @heroui/agent/next
|
|
@@ -284,3 +284,21 @@ Generated forms submit their validated values as a queued user message without c
|
|
|
284
284
|
draft. “Submitted to agent” confirms queue acceptance; action completion is reported separately.
|
|
285
285
|
The selected conversation stays connected while visible. Settled inactive conversations disconnect
|
|
286
286
|
after a grace period; closing the panel leaves active work running.
|
|
287
|
+
|
|
288
|
+
## Language
|
|
289
|
+
|
|
290
|
+
Set the default language in the HeroUI Agents editor. Pass `locale` to override it for a user:
|
|
291
|
+
|
|
292
|
+
```tsx
|
|
293
|
+
<HeroUIAgent agentId={agentId} getAuthToken={getAuthToken} locale="es" />
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The vanilla integration accepts the same `locale` option. English (`en`) and neutral Latin American Spanish (`es`) are supported. Regional tags such as `es-AR` share Spanish text and use regional number and date formatting. Unsupported locales fall back to English.
|
|
297
|
+
|
|
298
|
+
Set `locale="auto"` (or choose **Auto** in the editor) to use the first supported language in the visitor’s browser preferences, with English as the fallback. Regional formatting is preserved. Auto updates when browser language preferences change.
|
|
299
|
+
|
|
300
|
+
The SDK locale takes precedence over the saved agent locale, then English. With `remoteConfig={false}`, only the SDK locale and English fallback apply. Update the prop when your application's language changes; existing messages stay intact and subsequent submissions capture the new locale.
|
|
301
|
+
|
|
302
|
+
Interface language and response language are separate: the AI follows the user's message, keeps the previous conversational language for ambiguous follow-ups, and otherwise uses the configured locale. Explicit translation requests are honored.
|
|
303
|
+
|
|
304
|
+
Edit English and Spanish greetings, subtitles, placeholders, disclaimers, and suggested prompts in the editor's **Edit and preview** tabs. Explicit SDK copy overrides the selected translation. With `remoteConfig={false}`, pass a `translations` object keyed by base language (`{en: {greeting: "Hello"}, es: {greeting: "Hola"}}`) to provide custom copy for Auto. Missing Spanish copy uses built-in Spanish defaults; untranslated suggested prompts are hidden. Empty values and disabled disclaimers are preserved. Legacy custom copy remains English.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t="1.0.0-beta.8",o="https://api.heroui.pro";export{t as a,o as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as J}from"./chunk-2W6CUSN3.js";import{c as G,e as V,f as X,i as Y,j as Q,k as Z}from"./chunk-YPHOJDYK.js";function ge(e,t){return e.throwIfAborted(),new Promise((n,r)=>{let l=()=>r(e.reason);e.addEventListener("abort",l,{once:!0});try{t().then(n,r).finally(()=>e.removeEventListener("abort",l))}catch(c){e.removeEventListener("abort",l),r(c)}})}async function U(e,t,n){let r=new AbortController,l=setTimeout(()=>r.abort(new DOMException("Request timed out","TimeoutError")),e),c=n?AbortSignal.any([n,r.signal]):r.signal;try{return await ge(c,()=>t(c))}finally{clearTimeout(l)}}var fe={approval:"This approval has expired. Ask the agent to request it again.",authentication:"Could not authenticate. Sign in if needed, then retry.",chunk:"Could not load the conversation. Retry, or reload the panel.",configuration:"Could not load the agent configuration. Try again.",connection:"Connection interrupted. Completed page changes remain applied. Reconnect to continue this chat.",credits:"This agent has reached its usage limit.",deleted:"This conversation was deleted. Start a new conversation.",rate_limit:"Too many requests. Wait a moment before retrying.",unknown:"The request could not be completed. Try again."},me="Too many conversations are active. Wait a few minutes, then retry this chat.";function ee(e,t="connecting"){let n=e&&typeof e=="object"?e:{},r=[e instanceof Error?e.message:"",n.code,n.status].filter(c=>typeof c=="string"||typeof c=="number").join(" ").toLowerCase(),l=t==="authenticating"||/auth|401|sign.in/.test(r)?"authentication":/429|rate.limit|concurrency_limit|too many conversations are active/.test(r)?"rate_limit":/credit|usage.limit|usage_limit|402/.test(r)?"credits":/deleted|conversation_not_found/.test(r)?"deleted":/approval.*expir/.test(r)?"approval":/dynamic.*import|chunk|module.*fetch/.test(r)?"chunk":/config/.test(r)?"configuration":/network|fetch|connect|timeout|timed out/.test(r)?"connection":"unknown";return{category:l,diagnosticId:crypto.randomUUID(),message:/concurrency_limit|too many conversations are active/.test(r)?me:fe[l],phase:t,retryable:!["credits","deleted","approval"].includes(l)}}var he=5e3;function te(e){return`heroui-agent:anonymous:${e}`}function ye(e){return e instanceof Error?e:new Error("Auth token request failed")}var P=class{constructor(t,n){this.agentId=t;this.getAuthToken=n}cached=null;failure=null;generation=0;pending=null;controller=new AbortController;clear(){this.controller.abort(),this.controller=new AbortController,this.generation+=1,this.cached=null,this.failure=null,this.pending=null}reset(){this.clear();try{localStorage.removeItem(te(this.agentId))}catch{}}async get(){if(this.cached&&this.expiresAt(this.cached)>Date.now()+6e4)return this.cached.token;if(!this.pending&&this.failure&&Date.now()<this.failure.retryAt)throw this.failure.error;let t=this.generation,n=this.pending??this.refresh();this.pending||(this.pending=n);try{let r=await n;return t!==this.generation?this.get():(this.cached=r,this.failure=null,r.token)}catch(r){throw t===this.generation&&(this.failure={error:ye(r),retryAt:Date.now()+he}),r}finally{this.pending===n&&(this.pending=null)}}async subjectHash(){let t=await this.get(),n=we(t),r=typeof n.sub=="string"?n.sub:"anonymous",l=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(`${this.agentId}:${r}`));return Array.from(new Uint8Array(l),c=>c.toString(16).padStart(2,"0")).join("").slice(0,24)}anonymousId(){let t=te(this.agentId);try{let n=localStorage.getItem(t);if(n)return n;let r=crypto.randomUUID();return localStorage.setItem(t,r),r}catch{return crypto.randomUUID()}}expiresAt(t){return t.expiresAt}async refresh(){let t=await U(15e3,n=>this.getAuthToken({agentId:this.agentId,anonymousId:this.anonymousId(),signal:n}),this.controller.signal);if(!t||typeof t.token!="string"||!t.token.trim()||typeof t.expiresAt!="number"||!Number.isFinite(t.expiresAt)||t.expiresAt<=0)throw new Error("Auth token callback returned invalid data");return{expiresAt:t.expiresAt,token:t.token}}};function we(e){try{let t=e.split(".")[1];if(!t)return{};let n=t.replace(/-/g,"+").replace(/_/g,"/"),r=n.padEnd(Math.ceil(n.length/4)*4,"=");return JSON.parse(atob(r))}catch{return{}}}function ne(e){return{bounds:null,closing:!1,dragging:!1,expanded:e.appearance?.panel?.expanded??!1,mounted:!1,open:!1,overlayOpen:!1,ready:!1,resizing:!1,sidebarWidth:null,viewMode:e.appearance?.viewMode??"floating"}}function w(e,t,n){return{background:"transparent",border:"0",clipPath:be(e,t,n),colorScheme:"normal",height:"100dvh",inset:"0",position:"fixed",width:"100vw",zIndex:t.appearance?.zIndex??40}}function oe(e){if(!e||typeof e!="object")return null;let t=e;return typeof t.open!="boolean"||typeof t.ready!="boolean"||typeof t.expanded!="boolean"||t.viewMode!=="floating"&&t.viewMode!=="sidebar"?null:{bounds:ve(t.bounds),closing:t.closing===!0,dragging:t.dragging===!0,expanded:t.expanded,mounted:t.mounted!==!1,open:t.open,overlayOpen:t.overlayOpen===!0,ready:t.ready,resizing:t.resizing===!0,sidebarWidth:L(t.sidebarWidth)?t.sidebarWidth:null,viewMode:t.viewMode}}function re(){let e=document.documentElement,t=document.body;return{active:!1,body:t,original:{bodyLeft:t.style.left,bodyOverflow:t.style.overflow,bodyPosition:t.style.position,bodyRight:t.style.right,bodyTop:t.style.top,bodyWidth:t.style.width,rootMarginRight:e.style.marginRight,rootOverflow:e.style.overflow,rootTransition:e.style.transition},root:e,scrollLock:null}}function x(e,t,n,r){let l=t.open||t.closing;if(!l&&!e.active)return;l&&(e.active=!0);let c=l&&(r||t.viewMode==="sidebar"&&t.expanded);se(e,c);let a=l&&t.viewMode==="sidebar"&&!t.expanded&&!r?Ae(t,n):e.original.rootMarginRight;e.root.style.transition=e.original.rootTransition,e.root.style.marginRight=a,l||(e.active=!1)}function ie(e){se(e,!1),e.root.style.marginRight=e.original.rootMarginRight,e.root.style.transition=e.original.rootTransition,e.active=!1}function be(e,t,n){let r=e.open||e.closing;if(r&&(n||e.overlayOpen))return"inset(0px)";if(e.bounds)return`inset(${e.bounds.top}px calc(100% - ${e.bounds.right}px) calc(100% - ${e.bounds.bottom}px) ${e.bounds.left}px)`;let l=t.appearance?.launcher,c=l?.position==="bottom-left",g=(l?.offset?.x??24)+60,a=(l?.offset?.y??24)+60;if(!r)return c?`inset(calc(100% - ${a}px) calc(100% - ${g}px) 0px 0px)`:`inset(calc(100% - ${a}px) 0px 0px calc(100% - ${g}px))`;if(e.viewMode==="sidebar")return`inset(0px 0px 0px calc(100% - (${F(t.appearance?.panel?.initialWidth??420)} + 16px)))`;let f=F(t.appearance?.panel?.initialWidth??440),v=`calc(100% - min(calc(${F(t.appearance?.panel?.initialHeight??"max(420px, 56dvh)")} + 32px), 100dvh))`;return c?`inset(${v} calc(100% - min(calc(${f} + 32px), 100vw)) 0px 0px)`:`inset(${v} 0px 0px calc(100% - min(calc(${f} + 32px), 100vw)))`}function ve(e){if(!e||typeof e!="object")return null;let t=e;return!L(t.top)||!L(t.right)||!L(t.bottom)||!L(t.left)||t.right<t.left||t.bottom<t.top?null:{bottom:t.bottom,left:t.left,right:t.right,top:t.top}}function L(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1e5}function Ae(e,t){return e.sidebarWidth===null?F(t.appearance?.panel?.initialWidth??420):`${Math.round(e.sidebarWidth)}px`}function F(e){return typeof e=="number"?`${Math.round(e)}px`:e}function se(e,t){if(t&&!e.scrollLock){e.scrollLock={x:window.scrollX,y:window.scrollY},e.root.style.overflow="hidden",e.body.style.overflow="hidden",e.body.style.position="fixed",e.body.style.top=`${-e.scrollLock.y}px`,e.body.style.left=`${-e.scrollLock.x}px`,e.body.style.right="0",e.body.style.width="100%";return}if(!t&&e.scrollLock){let{x:n,y:r}=e.scrollLock;e.root.style.overflow=e.original.rootOverflow,e.body.style.overflow=e.original.bodyOverflow,e.body.style.position=e.original.bodyPosition,e.body.style.top=e.original.bodyTop,e.body.style.left=e.original.bodyLeft,e.body.style.right=e.original.bodyRight,e.body.style.width=e.original.bodyWidth,e.scrollLock=null;try{window.scrollTo(n,r)}catch{}}}var Te=16*1024,Ie=64*1024;function qe(e,t){let n=e;if(!n?.agentId||typeof n.getAuthToken!="function")throw new Error("HeroUIAgent.mount requires agentId and getAuthToken");let r=crypto.randomUUID(),l=crypto.randomUUID(),c=(n._api?.baseUrl??J).replace(/\/$/,""),g=Le(c,n._api?.embedOrigin),a=document.createElement("iframe"),f=new Map,y=[],v=new Set,A=new Map,k=new Set,T=re(),C=new P(n.agentId,n.getAuthToken),s=ne(n),O=null,h=!1,b=!1,I=null,W=!1,$=!1,N=new URL("/embed",g);N.searchParams.set("agentId",n.agentId),N.hash=new URLSearchParams({nonce:l,parentOrigin:window.location.origin,sessionId:r}).toString(),a.allow="microphone; clipboard-write",a.referrerPolicy="origin",a.setAttribute("sandbox","allow-downloads allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"),a.src=N.toString(),a.title="HeroUI Agent",Object.assign(a.style,w(s,n,window.innerWidth<640)),document.body.append(a);let m=(o,i,d)=>{$||a.contentWindow?.postMessage(Y(r,l,o,i,d),g)},de=(o,i)=>{let d=crypto.randomUUID();return new Promise((p,u)=>{let H=window.setTimeout(()=>{f.delete(d),u(new Error(`HeroUI Agent iframe request timed out: ${o}`))},3e4);f.set(d,{reject:u,resolve:p,timer:H}),m(o,i,d)})},S=new Map,q=0,z="",B=async(o,i=!1)=>{let d=++q,p=await ke(n,t);if($||d!==q)return;let u=JSON.stringify({props:p.props,tools:p.tools});!i&&u===z||(z=u,m(o,{...p,restoreSession:o==="host.init"&&b}))},E=(o,i)=>{if(!s.mounted){y.push({name:o,payload:i}),y.length>32&&y.shift();return}m("host.command",{name:o,payload:i})},M=o=>{o&&!h&&document.activeElement!==a&&(O=document.activeElement),h=o,o||(b=!1),E(o?"show":"hide")},ce=()=>{if(s.mounted)for(let o of y.splice(0))m("host.command",o)},ue=()=>{b=s.mounted&&h&&!s.closing,s={...s,bounds:null,closing:!1,mounted:!1,open:b,ready:!1},W=!1;for(let o of k)o();Object.assign(a.style,w(s,n,window.innerWidth<640)),x(T,s,n,window.innerWidth<640)},j=o=>{if(o.origin!==g||o.source!==a.contentWindow)return;let i=Q(o.data);if(!(!i||i.sessionId!==r||i.nonce!==l)){if(i.type==="iframe.rpc-result"||i.type==="iframe.rpc-error"){Se(i,f);return}Pe(v,i.requestId)&&pe(i)}},pe=async o=>{try{if(o.type==="iframe.ready"){(s.mounted||s.ready)&&ue(),await B("host.init",!0);return}if(o.type==="iframe.reload"){let i=a.cloneNode(!1),d=new URL(a.src);d.pathname=`/reload/${crypto.randomUUID()}/embed`,i.src=d.href,a.replaceWith(i),a=i;return}if(o.type==="iframe.state"){let i=oe(o.payload);if(i){let d=s.mounted,p=s.open||s.closing,u=i;b?i.mounted?(b=!1,i.open||(m("host.command",{name:"show"}),u={...i,bounds:null,closing:!1,open:!0,sidebarWidth:i.sidebarWidth??s.sidebarWidth})):u={...i,bounds:null,closing:!1,open:!0,sidebarWidth:i.sidebarWidth??s.sidebarWidth}:i.open?h=!0:(i.closing||s.open||s.closing)&&(h=!1);let H=u.open||u.closing;if(H&&!p&&document.activeElement!==a&&(O=document.activeElement),!H&&p&&O?.isConnected){let D=O;window.requestAnimationFrame(()=>window.requestAnimationFrame(()=>D.focus({preventScroll:!0})))}s=u,s.mounted&&!d&&B("host.update"),H&&s.expanded?a.dataset.expanded="true":a.removeAttribute("data-expanded");for(let D of k)D();Object.assign(a.style,w(s,n,window.innerWidth<640)),x(T,s,n,window.innerWidth<640),ce(),s.ready&&!W&&(W=!0,n.onReady?.())}return}if(o.type==="iframe.error"){n.onError?.(o.payload);return}if(o.type==="iframe.status"){n.onStatusChange?.(o.payload);return}if(o.type==="iframe.tool-cancel"){let i=o.payload;i.idempotencyKey&&S.get(i.idempotencyKey)?.abort();return}if(o.type==="iframe.auth-request"){let i=await C.get(),d=await U(15e3,p=>fetch(`${c}/v1/agents/${encodeURIComponent(n.agentId)}/embed-sessions`,{body:JSON.stringify({iframeOrigin:g,sessionId:r}),cache:"no-store",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},method:"POST",signal:p}));if(!d.ok)throw new Error("Could not authenticate HeroUI Agent");m("host.rpc-result",{value:await d.json()},o.requestId);return}if(o.type==="iframe.context-request"){let i=le(await n.context?.page?.()??{},Te,"Agent page context");m("host.rpc-result",{value:i},o.requestId);return}if(o.type==="iframe.tool-execute"){let i=Ee(o.payload),d=n.tools?.find(u=>u.name===i.name);if(!d)throw new Error(`Unknown client tool: ${i.name}`);let p=A.get(i.idempotencyKey);if(!p){let u=new AbortController;S.set(i.idempotencyKey,u),p=xe(d,i,n,de,u.signal).finally(()=>S.delete(i.idempotencyKey)),A.set(i.idempotencyKey,p),A.size>2048&&A.delete(A.keys().next().value)}m("host.rpc-result",{value:await p},o.requestId);return}if(o.type==="iframe.feedback"){await n.onFeedback?.(o.payload);return}if(o.type==="iframe.storage"){He(o.payload);return}if(o.type==="iframe.persistence"){let i=await import("./persistence-YI6JSYCT.js").then(({executeAgentHostPersistence:d})=>d(n.agentId,o.payload));m("host.rpc-result",{value:i},o.requestId)}}catch(i){let d=ee(i,o.type==="iframe.auth-request"?"authenticating":"failed");n.onError?.(d),m("host.rpc-error",{error:d.message},o.requestId)}},K=o=>{o.composedPath().includes(a)||s.open&&s.viewMode==="floating"&&(n.appearance?.shouldCloseOnInteractOutside??!0)&&M(!1)},R=()=>{s={...s,bounds:null},Object.assign(a.style,w(s,n,window.innerWidth<640)),x(T,s,n,window.innerWidth<640)},_=()=>{document.visibilityState==="visible"&&(s={...s,bounds:null},Object.assign(a.style,w(s,n,window.innerWidth<640)),x(T,s,n,window.innerWidth<640),h&&s.mounted&&m("host.command",{name:"show"}),I!==null&&window.cancelAnimationFrame(I),I=window.requestAnimationFrame(()=>{I=null,Object.assign(a.style,w(s,n,window.innerWidth<640))}))};return window.addEventListener("message",j),window.addEventListener("pointerdown",K,!0),window.addEventListener("resize",R),window.addEventListener("pageshow",_),window.visualViewport?.addEventListener("resize",R),document.addEventListener("visibilitychange",_),{destroy:()=>{$=!0;for(let o of S.values())o.abort();S.clear(),window.removeEventListener("message",j),window.removeEventListener("pointerdown",K,!0),window.removeEventListener("resize",R),window.removeEventListener("pageshow",_),window.visualViewport?.removeEventListener("resize",R),document.removeEventListener("visibilitychange",_),I!==null&&window.cancelAnimationFrame(I);for(let o of f.values())window.clearTimeout(o.timer),o.reject(new Error("HeroUI Agent iframe was removed"));f.clear(),y.length=0,k.clear(),ie(T),a.remove()},hide:()=>M(!1),newConversation:o=>{h=!0,E("newConversation",{prompt:o})},preload:()=>E("preload"),get ready(){return s.ready},refreshAuth:()=>{C.clear(),E("refreshAuth")},show:()=>M(!0),shutdown:()=>{h=!1,b=!1,C.reset(),E("shutdown")},subscribe:o=>(k.add(o),()=>k.delete(o)),toggle:()=>M(!h),update:o=>{if(o.agentId!==n.agentId)throw new Error("HeroUI Agent agentId cannot change without remounting");o.getAuthToken!==n.getAuthToken&&(C=new P(o.agentId,o.getAuthToken)),n=o,Object.assign(a.style,w(s,n,window.innerWidth<640)),x(T,s,n,window.innerWidth<640),s.mounted&&B("host.update")}}}async function xe(e,t,n,r,l){let c={conversationId:t.conversationId,idempotencyKey:t.idempotencyKey,signal:l,toolCallId:t.toolCallId,uploadDataSource:async f=>await r("host.upload-data-source",{toolCallId:t.toolCallId,upload:f})},g;try{g=G(e,t.args)}catch{return{code:"CLIENT_TOOL_INVALID_INPUT",error:`The arguments for ${e.name} do not match its declared schema. Correct the input and try again. No action was performed.`,success:!1}}let a=await e.execute(g,n.context??{},c)??null;return le(a,Ie,`Client tool ${e.name} result`)}async function ke(e,t){let{context:n,getAuthToken:r,onError:l,onFeedback:c,onReady:g,onStatusChange:a,tools:f,...y}=e,v=await t(f??[]);return{localStorage:ae(window.localStorage),props:JSON.parse(JSON.stringify(y)),sessionStorage:ae(window.sessionStorage),tools:v}}function Se(e,t){let n=t.get(e.requestId);if(n)if(t.delete(e.requestId),window.clearTimeout(n.timer),e.type==="iframe.rpc-error"){let r=e.payload;n.reject(new Error(typeof r?.error=="string"?r.error:"Iframe request failed"))}else{let r=e.payload;n.resolve(r?.value)}}function Ee(e){if(!e||typeof e!="object")throw new Error("Invalid client tool request");let t=e;if(typeof t.conversationId!="string"||typeof t.idempotencyKey!="string"||typeof t.name!="string"||typeof t.toolCallId!="string")throw new Error("Invalid client tool request");return t}function le(e,t,n){if(!Z(e))throw new Error(`${n} must be JSON-serializable`);let r=JSON.stringify(e);if(new TextEncoder().encode(r).byteLength>t)throw new Error(`${n} exceeds ${Math.round(t/1024)} KiB`);return JSON.parse(r)}function ae(e){let t={};try{for(let n=0;n<e.length;n+=1){let r=e.key(n);r?.startsWith("heroui-agent:")&&(t[r]=e.getItem(r)??"")}}catch{}return t}function He(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.key=="string"&&!t.key.startsWith("heroui-agent:"))return;let n=t.storage==="session"?sessionStorage:localStorage;try{if(t.operation==="set"&&typeof t.key=="string"&&typeof t.value=="string")n.setItem(t.key,t.value);else if(t.operation==="remove"&&typeof t.key=="string")n.removeItem(t.key);else if(t.operation==="clear")for(let r=n.length-1;r>=0;r-=1){let l=n.key(r);l?.startsWith("heroui-agent:")&&n.removeItem(l)}}catch{}}function Pe(e,t){return e.has(t)?!1:(e.add(t),e.size>2048&&e.delete(e.values().next().value),!0)}function Le(e,t){if(t){let n=new URL(t);if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error("HeroUI Agent embed origin must use HTTP or HTTPS");return n.origin}return/^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/i.test(e)?"http://localhost:8793":e.includes("staging")?X:V}export{ge as a,U as b,ee as c,P as d,qe as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as i,k as a}from"./chunk-YPHOJDYK.js";import{z as t}from"zod";var c=["readConversationHistory","callMcpTool","composeUI","executeSandbox","generateFile","getUIComponents","readSkill","renderComponent","renderDocument","searchKnowledge","searchMcpTools","searchWeb"],m="mcp_",p=20,l=16*1024,d=t.object({description:t.string().trim().min(1).max(1e3),inputSchema:t.record(t.string(),t.unknown()),name:t.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/).refine(e=>!c.includes(e)&&!e.toLowerCase().startsWith(m),"Client tool name is reserved by the HeroUI Agent runtime"),needsApproval:t.boolean().optional()}),f=t.array(d).max(p).superRefine((e,n)=>{let o=new Set;for(let r of e)o.has(r.name)&&n.addIssue({code:"custom",message:`Duplicate client tool name: ${r.name}`}),o.add(r.name);new TextEncoder().encode(JSON.stringify(e)).byteLength>l&&n.addIssue({code:"custom",message:"Client tool manifest exceeds 16KB"})});function u(e){let n=i(e.parameters)?t.toJSONSchema(e.parameters):e.parameters;if(!a(n))throw new Error(`Client tool ${e.name} parameters must be a JSON-serializable schema`);return s(n)}function s(e){return Array.isArray(e)?e.map(s):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,o])=>[n,s(o)])):e}function E(e){return f.parse(e.map(n=>({description:n.description,inputSchema:u(n),name:n.name,...n.needsApproval?{needsApproval:!0}:{}})))}export{c as a,m as b,p as c,l as d,d as e,f,E as g};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as S}from"./chunk-
|
|
1
|
+
import{e as S}from"./chunk-KMVOOEIK.js";import{b as d}from"./chunk-YPHOJDYK.js";import{useEffect as k,useLayoutEffect as p,useMemo as x,useRef as m,useState as O,useSyncExternalStore as w}from"react";var i=new Map,h=new Set;function f(){for(let e of h)e()}function H(e){return h.add(e),()=>h.delete(e)}function a(e,n,r){let o=e?i.get(e):[...i.values()][i.size-1];if(!o){console.warn("HeroUI Agent is not mounted yet. Add <HeroUIAgent /> to your layout.");return}n==="newConversation"?o.newConversation(r):o[n]()}function R(e){let n=w(H,()=>(e?i.get(e):[...i.values()].at(-1))?.ready??!1,()=>!1);return x(()=>({hide:()=>a(e,"hide"),newConversation:r=>a(e,"newConversation",r),preload:()=>a(e,"preload"),ready:n,refreshAuth:()=>a(e,"refreshAuth"),show:()=>a(e,"show"),shutdown:()=>a(e,"shutdown"),toggle:()=>a(e,"toggle")}),[e,n])}async function E(e){let{serializeClientTools:n}=await import("./client-tools-manifest-BD7O7M3V.js");return n(e).map(o=>{let s=e.find(l=>l.name===o.name);return{...o,...s?.displayName?{displayName:s.displayName}:{},...s?.icon?{icon:s.icon}:{},...s?.iconColor?{iconColor:s.iconColor}:{}}})}function P(e){let n=m(e),r=m(null),o=m(null);p(()=>{n.current=e}),o.current||(o.current={getAuthToken:t=>n.current.getAuthToken(t),onError:t=>n.current.onError?.(t),onFeedback:t=>n.current.onFeedback?.(t),onReady:()=>n.current.onReady?.(),onStatusChange:t=>n.current.onStatusChange?.(t)},Object.defineProperties(o.current,{context:{enumerable:!0,get(){return n.current.context}},tools:{enumerable:!0,get(){return n.current.tools}}}));let s=T(e),l=o.current;for(let t of Object.keys(l))t!=="context"&&t!=="getAuthToken"&&t!=="onError"&&t!=="onStatusChange"&&t!=="onFeedback"&&t!=="onReady"&&t!=="tools"&&!(t in s)&&delete l[t];Object.assign(l,s,{agentId:e.agentId});let g=o.current;p(()=>{let t=S(g,E),u=t.subscribe(f);return r.current=t,i.set(e.agentId,t),f(),()=>{u(),t.destroy(),i.get(e.agentId)===t&&i.delete(e.agentId),r.current===t&&(r.current=null),f()}},[e.agentId]);let[C,c]=O("");k(()=>{let t=e.tools??[];if(!t.some(A=>d(A.parameters))){c("");return}let u=!1;return import("./client-tools-manifest-BD7O7M3V.js").then(({serializeClientTools:A})=>{u||c(JSON.stringify(A(t).map(y=>({inputSchema:y.inputSchema,name:y.name}))))}),()=>{u=!0}},[e.tools]);let b=JSON.stringify({props:T(e),tools:(e.tools??[]).map(t=>({description:t.description,displayName:t.displayName,icon:t.icon,iconColor:t.iconColor,name:t.name,needsApproval:t.needsApproval===!0,parameters:d(t.parameters)?null:t.parameters})),zodToolsSchemasKey:C});return p(()=>{r.current?.update(g)},[b]),null}function T(e){let{context:n,getAuthToken:r,onError:o,onFeedback:s,onReady:l,onStatusChange:g,tools:C,...c}=e;return JSON.parse(JSON.stringify(c))}export{R as a,P as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g}from"./chunk-KQ3FZPFS.js";import"./chunk-YPHOJDYK.js";export{c as MAX_CLIENT_TOOLS,d as MAX_CLIENT_TOOLS_BYTES,a as RESERVED_AGENT_TOOL_NAMES,b as RESERVED_AGENT_TOOL_PREFIX,e as clientToolManifestEntrySchema,f as clientToolsSchema,g as serializeClientTools};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { T as HeroUIAgentProps, i as AgentController } from './types-
|
|
2
|
-
export { A as AgentApiOverrides, a as AgentAppearance, b as AgentAttachmentContentType, c as AgentAuthToken, d as AgentCapabilities, e as AgentColorScheme, f as AgentComponentExportFormat, g as AgentComposerOptions, h as AgentContext, j as AgentDataSource, k as AgentDataSourceFormat, l as AgentDesignTheme, m as AgentError, n as AgentFeedbackReason, o as AgentLauncherOptions, p as AgentLauncherPosition, q as AgentMarkdownAnimation, r as AgentMarkdownAnimationOptions, s as AgentMarkdownCaret, t as AgentMarkdownOptions, u as AgentMessageAction, v as AgentModelId, w as AgentPanelOptions, x as AgentPermissionMode, y as AgentPermissionOptions, z as AgentRadius, B as AgentResponseFeedback, C as AgentSharedContext, D as AgentShouldCloseOnInteractOutside, E as AgentStartScreenOptions, F as AgentStatus, G as AgentSurfaceVariant, H as AgentThemeColor, I as AgentThemeColors, J as AgentThemeOptions, K as AgentTypography, L as AgentViewMode, M as ClientTool, N as ClientToolExecutionContext, O as ClientToolIcon, P as ClientToolStatus, Q as DEFAULT_MARKDOWN_ANIMATION, R as GetAuthToken, S as GetAuthTokenContext, U as UploadAgentDataSourceInput, V as createToolHelper } from './types-
|
|
3
|
-
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from './version-
|
|
1
|
+
import { T as HeroUIAgentProps, i as AgentController } from './types-Cuqd4_1K.js';
|
|
2
|
+
export { A as AgentApiOverrides, a as AgentAppearance, b as AgentAttachmentContentType, c as AgentAuthToken, d as AgentCapabilities, e as AgentColorScheme, f as AgentComponentExportFormat, g as AgentComposerOptions, h as AgentContext, j as AgentDataSource, k as AgentDataSourceFormat, l as AgentDesignTheme, m as AgentError, n as AgentFeedbackReason, o as AgentLauncherOptions, p as AgentLauncherPosition, q as AgentMarkdownAnimation, r as AgentMarkdownAnimationOptions, s as AgentMarkdownCaret, t as AgentMarkdownOptions, u as AgentMessageAction, v as AgentModelId, w as AgentPanelOptions, x as AgentPermissionMode, y as AgentPermissionOptions, z as AgentRadius, B as AgentResponseFeedback, C as AgentSharedContext, D as AgentShouldCloseOnInteractOutside, E as AgentStartScreenOptions, F as AgentStatus, G as AgentSurfaceVariant, H as AgentThemeColor, I as AgentThemeColors, J as AgentThemeOptions, K as AgentTypography, L as AgentViewMode, M as ClientTool, N as ClientToolExecutionContext, O as ClientToolIcon, P as ClientToolStatus, Q as DEFAULT_MARKDOWN_ANIMATION, R as GetAuthToken, S as GetAuthTokenContext, U as UploadAgentDataSourceInput, V as createToolHelper } from './types-Cuqd4_1K.js';
|
|
3
|
+
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from './version-DDaVFBVG.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
6
6
|
/** Imperative controls for the hosted iframe Agent. */
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as d,b as e}from"./chunk-
|
|
1
|
+
import{a as d,b as e}from"./chunk-MUJYIDA4.js";import"./chunk-KMVOOEIK.js";import{a as f}from"./chunk-AR424OVX.js";import{a as b,b as c}from"./chunk-2W6CUSN3.js";import{a}from"./chunk-YPHOJDYK.js";export{f as DEFAULT_MARKDOWN_ANIMATION,c as HEROUI_AGENT_API_BASE_URL,b as HEROUI_AGENT_SDK_VERSION,e as HeroUIAgent,a as createToolHelper,d as useAgent};
|
package/dist/internal/host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as ClientToolIcon, U as UploadAgentDataSourceInput, B as AgentResponseFeedback, m as AgentError, F as AgentStatus, i as AgentController, T as HeroUIAgentProps, M as ClientTool, R as GetAuthToken } from '../types-
|
|
2
|
-
export { W as parseClientToolArgs, X as resolveDirectToolAction } from '../types-
|
|
1
|
+
import { O as ClientToolIcon, U as UploadAgentDataSourceInput, B as AgentResponseFeedback, m as AgentError, F as AgentStatus, i as AgentController, T as HeroUIAgentProps, M as ClientTool, R as GetAuthToken } from '../types-Cuqd4_1K.js';
|
|
2
|
+
export { W as parseClientToolArgs, X as resolveDirectToolAction } from '../types-Cuqd4_1K.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
5
|
type HostedFrameBounds = {
|
package/dist/internal/host.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as r,b as t,c as a,d as l,e as n}from"../chunk-
|
|
1
|
+
import{a as r,b as t,c as a,d as l,e as n}from"../chunk-KMVOOEIK.js";import"../chunk-2W6CUSN3.js";import{c as o,d as e,e as m,f as p,g as s,h as i,i as f,j as x,k as g,l as A}from"../chunk-YPHOJDYK.js";export{l as EmbedSessionManager,s as HEROUI_AGENT_BRIDGE_MAX_MESSAGE_BYTES,i as HEROUI_AGENT_BRIDGE_MAX_PERSISTENCE_BYTES,m as HEROUI_AGENT_HOSTED_ORIGIN,p as HEROUI_AGENT_HOSTED_STAGING_ORIGIN,r as abortable,f as createAgentBridgeEnvelope,a as createAgentError,A as estimateAgentBridgeMessageBytes,g as isAgentBridgeJsonValue,n as mountAgent,x as parseAgentBridgeEnvelope,o as parseClientToolArgs,e as resolveDirectToolAction,t as withDeadline};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from '../version-
|
|
1
|
+
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from '../version-DDaVFBVG.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { M as ClientTool } from '../types-
|
|
4
|
-
export { Q as DEFAULT_MARKDOWN_ANIMATION } from '../types-
|
|
3
|
+
import { M as ClientTool } from '../types-Cuqd4_1K.js';
|
|
4
|
+
export { Q as DEFAULT_MARKDOWN_ANIMATION } from '../types-Cuqd4_1K.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare const agentIdentityIdSchema: z.ZodString;
|
|
@@ -41,7 +41,7 @@ type AgentAuthProfile = z.infer<typeof agentAuthProfileSchema>;
|
|
|
41
41
|
type AgentAuthToken = z.infer<typeof agentAuthTokenSchema>;
|
|
42
42
|
type CreateAgentAuthTokenRequest = z.infer<typeof createAgentAuthTokenRequestSchema>;
|
|
43
43
|
|
|
44
|
-
declare const RESERVED_AGENT_TOOL_NAMES: readonly ["readConversationHistory", "callMcpTool", "composeUI", "executeSandbox", "generateFile", "
|
|
44
|
+
declare const RESERVED_AGENT_TOOL_NAMES: readonly ["readConversationHistory", "callMcpTool", "composeUI", "executeSandbox", "generateFile", "getUIComponents", "readSkill", "renderComponent", "renderDocument", "searchKnowledge", "searchMcpTools", "searchWeb"];
|
|
45
45
|
declare const RESERVED_AGENT_TOOL_PREFIX = "mcp_";
|
|
46
46
|
declare const MAX_CLIENT_TOOLS = 20;
|
|
47
47
|
declare const MAX_CLIENT_TOOLS_BYTES: number;
|
package/dist/internal/shared.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as l}from"../chunk-AR424OVX.js";import{a,b as r}from"../chunk-
|
|
1
|
+
import{a as l}from"../chunk-AR424OVX.js";import{a,b as r}from"../chunk-2W6CUSN3.js";import{a as m,b as A,c as p,d as s,e as c,f as h,g as u}from"../chunk-KQ3FZPFS.js";import"../chunk-YPHOJDYK.js";import{z as e}from"zod";var g=new Set(["[object object]","0","anonymous","distinct_id","distinctid","email","false","guest","id","nan","none","not_authenticated","null","true","undefined"]),t=e.string().trim().min(1).max(200).refine(i=>!g.has(i.toLowerCase()),{message:"Identity id is reserved"}),n=e.discriminatedUnion("type",[e.object({id:t,type:e.literal("anonymous")}),e.object({id:t,type:e.literal("user")})]),o=e.object({avatarUrl:e.string().trim().pipe(e.url()).optional(),email:e.string().trim().max(320).pipe(e.email()).optional(),name:e.string().trim().max(120).optional()}),T=e.object({anonymousId:t.optional(),identity:n,profile:o.optional()}),S=e.object({expiresAt:e.number().int().positive(),token:e.string().trim().min(1)});export{l as DEFAULT_MARKDOWN_ANIMATION,r as HEROUI_AGENT_API_BASE_URL,a as HEROUI_AGENT_SDK_VERSION,p as MAX_CLIENT_TOOLS,s as MAX_CLIENT_TOOLS_BYTES,m as RESERVED_AGENT_TOOL_NAMES,A as RESERVED_AGENT_TOOL_PREFIX,n as agentAuthIdentitySchema,o as agentAuthProfileSchema,S as agentAuthTokenSchema,t as agentIdentityIdSchema,c as clientToolManifestEntrySchema,h as clientToolsSchema,T as createAgentAuthTokenRequestSchema,u as serializeClientTools};
|
package/dist/next.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AgentApiOverrides, a as AgentAppearance, b as AgentAttachmentContentType, c as AgentAuthToken, d as AgentCapabilities, e as AgentColorScheme, f as AgentComponentExportFormat, g as AgentComposerOptions, h as AgentContext, i as AgentController, j as AgentDataSource, k as AgentDataSourceFormat, l as AgentDesignTheme, m as AgentError, n as AgentFeedbackReason, o as AgentLauncherOptions, p as AgentLauncherPosition, q as AgentMarkdownAnimation, r as AgentMarkdownAnimationOptions, s as AgentMarkdownCaret, t as AgentMarkdownOptions, u as AgentMessageAction, v as AgentModelId, w as AgentPanelOptions, x as AgentPermissionMode, y as AgentPermissionOptions, z as AgentRadius, B as AgentResponseFeedback, C as AgentSharedContext, D as AgentShouldCloseOnInteractOutside, E as AgentStartScreenOptions, F as AgentStatus, G as AgentSurfaceVariant, H as AgentThemeColor, I as AgentThemeColors, J as AgentThemeOptions, K as AgentTypography, L as AgentViewMode, M as ClientTool, N as ClientToolExecutionContext, O as ClientToolIcon, P as ClientToolStatus, Q as DEFAULT_MARKDOWN_ANIMATION, R as GetAuthToken, S as GetAuthTokenContext, T as HeroUIAgentProps, U as UploadAgentDataSourceInput, V as createToolHelper } from './types-
|
|
1
|
+
export { A as AgentApiOverrides, a as AgentAppearance, b as AgentAttachmentContentType, c as AgentAuthToken, d as AgentCapabilities, e as AgentColorScheme, f as AgentComponentExportFormat, g as AgentComposerOptions, h as AgentContext, i as AgentController, j as AgentDataSource, k as AgentDataSourceFormat, l as AgentDesignTheme, m as AgentError, n as AgentFeedbackReason, o as AgentLauncherOptions, p as AgentLauncherPosition, q as AgentMarkdownAnimation, r as AgentMarkdownAnimationOptions, s as AgentMarkdownCaret, t as AgentMarkdownOptions, u as AgentMessageAction, v as AgentModelId, w as AgentPanelOptions, x as AgentPermissionMode, y as AgentPermissionOptions, z as AgentRadius, B as AgentResponseFeedback, C as AgentSharedContext, D as AgentShouldCloseOnInteractOutside, E as AgentStartScreenOptions, F as AgentStatus, G as AgentSurfaceVariant, H as AgentThemeColor, I as AgentThemeColors, J as AgentThemeOptions, K as AgentTypography, L as AgentViewMode, M as ClientTool, N as ClientToolExecutionContext, O as ClientToolIcon, P as ClientToolStatus, Q as DEFAULT_MARKDOWN_ANIMATION, R as GetAuthToken, S as GetAuthTokenContext, T as HeroUIAgentProps, U as UploadAgentDataSourceInput, V as createToolHelper } from './types-Cuqd4_1K.js';
|
|
2
2
|
export { HeroUIAgent, useAgent } from './index.js';
|
|
3
|
-
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from './version-
|
|
3
|
+
export { H as HEROUI_AGENT_API_BASE_URL, a as HEROUI_AGENT_SDK_VERSION } from './version-DDaVFBVG.js';
|
|
4
4
|
import 'react';
|
package/dist/next.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as f,b as m}from"./chunk-
|
|
1
|
+
import{a as f,b as m}from"./chunk-MUJYIDA4.js";import"./chunk-KMVOOEIK.js";import{a as p}from"./chunk-AR424OVX.js";import{a as r,b as e}from"./chunk-2W6CUSN3.js";import{a as o}from"./chunk-YPHOJDYK.js";export{p as DEFAULT_MARKDOWN_ANIMATION,e as HEROUI_AGENT_API_BASE_URL,r as HEROUI_AGENT_SDK_VERSION,m as HeroUIAgent,o as createToolHelper,f as useAgent};
|
|
@@ -440,6 +440,16 @@ type AgentError = {
|
|
|
440
440
|
retryable: boolean;
|
|
441
441
|
};
|
|
442
442
|
type HeroUIAgentProps = {
|
|
443
|
+
/** Interface locale, or "auto" to match browser preferences. SDK override > agent default > English. */
|
|
444
|
+
locale?: string;
|
|
445
|
+
/** Copy by language tag, beneath explicit composer/startScreen text. Useful with locale="auto". */
|
|
446
|
+
translations?: Record<string, {
|
|
447
|
+
greeting?: string;
|
|
448
|
+
subtitle?: string;
|
|
449
|
+
placeholder?: string;
|
|
450
|
+
disclaimer?: string | false;
|
|
451
|
+
prompts?: string[];
|
|
452
|
+
}>;
|
|
443
453
|
onError?: (error: AgentError) => void;
|
|
444
454
|
onStatusChange?: (status: AgentStatus) => void;
|
|
445
455
|
/** Internal — for HeroUI platform development only. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const HEROUI_AGENT_SDK_VERSION: "1.0.0-beta.
|
|
1
|
+
declare const HEROUI_AGENT_SDK_VERSION: "1.0.0-beta.8";
|
|
2
2
|
/** Production Agent API origin used when hosts omit `_api.baseUrl` / `apiBaseUrl`. */
|
|
3
3
|
declare const HEROUI_AGENT_API_BASE_URL: "https://api.heroui.pro";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroui/agent",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.8",
|
|
4
4
|
"description": "Embed a hosted HeroUI Agent that turns application data into interactive UI.",
|
|
5
5
|
"homepage": "https://heroui.pro/agents",
|
|
6
6
|
"bugs": {
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react-dom": "19.2.6",
|
|
98
98
|
"tsup": "8.5.0",
|
|
99
99
|
"typescript": "5.9.3",
|
|
100
|
-
"vitest": "
|
|
100
|
+
"vitest": "5.0.0",
|
|
101
101
|
"@heroui-pro/config": "0.0.0"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
package/dist/chunk-7NL3SCZA.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as G}from"./chunk-MPJ6AAXH.js";import{c as K,e as J,f as V,i as X,j as Y,k as Q}from"./chunk-YPHOJDYK.js";function pe(e,t){return e.throwIfAborted(),new Promise((n,r)=>{let l=()=>r(e.reason);e.addEventListener("abort",l,{once:!0});try{t().then(n,r).finally(()=>e.removeEventListener("abort",l))}catch(c){e.removeEventListener("abort",l),r(c)}})}async function _(e,t,n){let r=new AbortController,l=setTimeout(()=>r.abort(new DOMException("Request timed out","TimeoutError")),e),c=n?AbortSignal.any([n,r.signal]):r.signal;try{return await pe(c,()=>t(c))}finally{clearTimeout(l)}}var ge={approval:"This approval has expired. Ask the agent to request it again.",authentication:"Could not authenticate. Sign in if needed, then retry.",chunk:"Could not load the conversation. Retry, or reload the panel.",configuration:"Could not load the agent configuration. Try again.",connection:"Connection interrupted. Check your connection and retry.",credits:"This agent has reached its usage limit.",deleted:"This conversation was deleted. Start a new conversation.",rate_limit:"Too many requests. Wait a moment before retrying.",unknown:"The request could not be completed. Try again."};function Z(e,t="connecting"){let n=e&&typeof e=="object"?e:{},r=[e instanceof Error?e.message:"",n.code,n.status].filter(c=>typeof c=="string"||typeof c=="number").join(" ").toLowerCase(),l=t==="authenticating"||/auth|401|sign.in/.test(r)?"authentication":/429|rate.limit/.test(r)?"rate_limit":/credit|usage.limit|usage_limit|402/.test(r)?"credits":/deleted|conversation_not_found/.test(r)?"deleted":/approval.*expir/.test(r)?"approval":/dynamic.*import|chunk|module.*fetch/.test(r)?"chunk":/config/.test(r)?"configuration":/network|fetch|connect|timeout|timed out/.test(r)?"connection":"unknown";return{category:l,diagnosticId:crypto.randomUUID(),message:ge[l],phase:t,retryable:!["credits","deleted","approval"].includes(l)}}var fe=5e3;function ee(e){return`heroui-agent:anonymous:${e}`}function he(e){return e instanceof Error?e:new Error("Auth token request failed")}var P=class{constructor(t,n){this.agentId=t;this.getAuthToken=n}cached=null;failure=null;generation=0;pending=null;controller=new AbortController;clear(){this.controller.abort(),this.controller=new AbortController,this.generation+=1,this.cached=null,this.failure=null,this.pending=null}reset(){this.clear();try{localStorage.removeItem(ee(this.agentId))}catch{}}async get(){if(this.cached&&this.expiresAt(this.cached)>Date.now()+6e4)return this.cached.token;if(!this.pending&&this.failure&&Date.now()<this.failure.retryAt)throw this.failure.error;let t=this.generation,n=this.pending??this.refresh();this.pending||(this.pending=n);try{let r=await n;return t!==this.generation?this.get():(this.cached=r,this.failure=null,r.token)}catch(r){throw t===this.generation&&(this.failure={error:he(r),retryAt:Date.now()+fe}),r}finally{this.pending===n&&(this.pending=null)}}async subjectHash(){let t=await this.get(),n=me(t),r=typeof n.sub=="string"?n.sub:"anonymous",l=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(`${this.agentId}:${r}`));return Array.from(new Uint8Array(l),c=>c.toString(16).padStart(2,"0")).join("").slice(0,24)}anonymousId(){let t=ee(this.agentId);try{let n=localStorage.getItem(t);if(n)return n;let r=crypto.randomUUID();return localStorage.setItem(t,r),r}catch{return crypto.randomUUID()}}expiresAt(t){return t.expiresAt}async refresh(){let t=await _(15e3,n=>this.getAuthToken({agentId:this.agentId,anonymousId:this.anonymousId(),signal:n}),this.controller.signal);if(!t||typeof t.token!="string"||!t.token.trim()||typeof t.expiresAt!="number"||!Number.isFinite(t.expiresAt)||t.expiresAt<=0)throw new Error("Auth token callback returned invalid data");return{expiresAt:t.expiresAt,token:t.token}}};function me(e){try{let t=e.split(".")[1];if(!t)return{};let n=t.replace(/-/g,"+").replace(/_/g,"/"),r=n.padEnd(Math.ceil(n.length/4)*4,"=");return JSON.parse(atob(r))}catch{return{}}}function te(e){return{bounds:null,closing:!1,dragging:!1,expanded:e.appearance?.panel?.expanded??!1,mounted:!1,open:!1,overlayOpen:!1,ready:!1,resizing:!1,sidebarWidth:null,viewMode:e.appearance?.viewMode??"floating"}}function w(e,t,n){return{background:"transparent",border:"0",clipPath:ye(e,t,n),colorScheme:"normal",height:"100dvh",inset:"0",position:"fixed",width:"100vw",zIndex:t.appearance?.zIndex??40}}function ne(e){if(!e||typeof e!="object")return null;let t=e;return typeof t.open!="boolean"||typeof t.ready!="boolean"||typeof t.expanded!="boolean"||t.viewMode!=="floating"&&t.viewMode!=="sidebar"?null:{bounds:we(t.bounds),closing:t.closing===!0,dragging:t.dragging===!0,expanded:t.expanded,mounted:t.mounted!==!1,open:t.open,overlayOpen:t.overlayOpen===!0,ready:t.ready,resizing:t.resizing===!0,sidebarWidth:L(t.sidebarWidth)?t.sidebarWidth:null,viewMode:t.viewMode}}function oe(){let e=document.documentElement,t=document.body;return{active:!1,body:t,original:{bodyLeft:t.style.left,bodyOverflow:t.style.overflow,bodyPosition:t.style.position,bodyRight:t.style.right,bodyTop:t.style.top,bodyWidth:t.style.width,rootMarginRight:e.style.marginRight,rootOverflow:e.style.overflow,rootTransition:e.style.transition},root:e,scrollLock:null}}function I(e,t,n,r){let l=t.open||t.closing;if(!l&&!e.active)return;l&&(e.active=!0);let c=l&&(r||t.viewMode==="sidebar"&&t.expanded);ie(e,c);let a=l&&t.viewMode==="sidebar"&&!t.expanded&&!r?be(t,n):e.original.rootMarginRight;e.root.style.transition=e.original.rootTransition,e.root.style.marginRight=a,l||(e.active=!1)}function re(e){ie(e,!1),e.root.style.marginRight=e.original.rootMarginRight,e.root.style.transition=e.original.rootTransition,e.active=!1}function ye(e,t,n){let r=e.open||e.closing;if(r&&(n||e.overlayOpen))return"inset(0px)";if(e.bounds)return`inset(${e.bounds.top}px calc(100% - ${e.bounds.right}px) calc(100% - ${e.bounds.bottom}px) ${e.bounds.left}px)`;let l=t.appearance?.launcher,c=l?.position==="bottom-left",g=(l?.offset?.x??24)+60,a=(l?.offset?.y??24)+60;if(!r)return c?`inset(calc(100% - ${a}px) calc(100% - ${g}px) 0px 0px)`:`inset(calc(100% - ${a}px) 0px 0px calc(100% - ${g}px))`;if(e.viewMode==="sidebar")return`inset(0px 0px 0px calc(100% - (${F(t.appearance?.panel?.initialWidth??420)} + 16px)))`;let h=F(t.appearance?.panel?.initialWidth??440),v=`calc(100% - min(calc(${F(t.appearance?.panel?.initialHeight??"max(420px, 56dvh)")} + 32px), 100dvh))`;return c?`inset(${v} calc(100% - min(calc(${h} + 32px), 100vw)) 0px 0px)`:`inset(${v} 0px 0px calc(100% - min(calc(${h} + 32px), 100vw)))`}function we(e){if(!e||typeof e!="object")return null;let t=e;return!L(t.top)||!L(t.right)||!L(t.bottom)||!L(t.left)||t.right<t.left||t.bottom<t.top?null:{bottom:t.bottom,left:t.left,right:t.right,top:t.top}}function L(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=1e5}function be(e,t){return e.sidebarWidth===null?F(t.appearance?.panel?.initialWidth??420):`${Math.round(e.sidebarWidth)}px`}function F(e){return typeof e=="number"?`${Math.round(e)}px`:e}function ie(e,t){if(t&&!e.scrollLock){e.scrollLock={x:window.scrollX,y:window.scrollY},e.root.style.overflow="hidden",e.body.style.overflow="hidden",e.body.style.position="fixed",e.body.style.top=`${-e.scrollLock.y}px`,e.body.style.left=`${-e.scrollLock.x}px`,e.body.style.right="0",e.body.style.width="100%";return}if(!t&&e.scrollLock){let{x:n,y:r}=e.scrollLock;e.root.style.overflow=e.original.rootOverflow,e.body.style.overflow=e.original.bodyOverflow,e.body.style.position=e.original.bodyPosition,e.body.style.top=e.original.bodyTop,e.body.style.left=e.original.bodyLeft,e.body.style.right=e.original.bodyRight,e.body.style.width=e.original.bodyWidth,e.scrollLock=null;try{window.scrollTo(n,r)}catch{}}}var ve=16*1024,Ae=64*1024;function De(e,t){let n=e;if(!n?.agentId||typeof n.getAuthToken!="function")throw new Error("HeroUIAgent.mount requires agentId and getAuthToken");let r=crypto.randomUUID(),l=crypto.randomUUID(),c=(n._api?.baseUrl??G).replace(/\/$/,""),g=He(c,n._api?.embedOrigin),a=document.createElement("iframe"),h=new Map,y=[],v=new Set,A=new Map,k=new Set,T=oe(),C=new P(n.agentId,n.getAuthToken),s=te(n),O=null,m=!1,b=!1,x=null,W=!1,$=!1,B=new URL("/embed",g);B.searchParams.set("agentId",n.agentId),B.hash=new URLSearchParams({nonce:l,parentOrigin:window.location.origin,sessionId:r}).toString(),a.allow="microphone; clipboard-write",a.referrerPolicy="origin",a.setAttribute("sandbox","allow-downloads allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"),a.src=B.toString(),a.title="HeroUI Agent",Object.assign(a.style,w(s,n,window.innerWidth<640)),document.body.append(a);let f=(o,i,d)=>{$||a.contentWindow?.postMessage(X(r,l,o,i,d),g)},le=(o,i)=>{let d=crypto.randomUUID();return new Promise((u,p)=>{let H=window.setTimeout(()=>{h.delete(d),p(new Error(`HeroUI Agent iframe request timed out: ${o}`))},3e4);h.set(d,{reject:p,resolve:u,timer:H}),f(o,i,d)})},S=new Map,D=0,q="",N=async(o,i=!1)=>{let d=++D,u=await xe(n,t);if($||d!==D)return;let p=JSON.stringify({props:u.props,tools:u.tools});!i&&p===q||(q=p,f(o,{...u,restoreSession:o==="host.init"&&b}))},E=(o,i)=>{if(!s.mounted){y.push({name:o,payload:i}),y.length>32&&y.shift();return}f("host.command",{name:o,payload:i})},M=o=>{o&&!m&&document.activeElement!==a&&(O=document.activeElement),m=o,o||(b=!1),E(o?"show":"hide")},de=()=>{if(s.mounted)for(let o of y.splice(0))f("host.command",o)},ce=()=>{b=s.mounted&&m&&!s.closing,s={...s,bounds:null,closing:!1,mounted:!1,open:b,ready:!1},W=!1;for(let o of k)o();Object.assign(a.style,w(s,n,window.innerWidth<640)),I(T,s,n,window.innerWidth<640)},z=o=>{if(o.origin!==g||o.source!==a.contentWindow)return;let i=Y(o.data);if(!(!i||i.sessionId!==r||i.nonce!==l)){if(i.type==="iframe.rpc-result"||i.type==="iframe.rpc-error"){Ie(i,h);return}Ee(v,i.requestId)&&ue(i)}},ue=async o=>{try{if(o.type==="iframe.ready"){(s.mounted||s.ready)&&ce(),await N("host.init",!0);return}if(o.type==="iframe.reload"){let i=a.cloneNode(!1),d=new URL(a.src);d.pathname=`/reload/${crypto.randomUUID()}/embed`,i.src=d.href,a.replaceWith(i),a=i;return}if(o.type==="iframe.state"){let i=ne(o.payload);if(i){let d=s.open||s.closing,u=i;b?i.mounted?(b=!1,i.open||(f("host.command",{name:"show"}),u={...i,bounds:null,closing:!1,open:!0,sidebarWidth:i.sidebarWidth??s.sidebarWidth})):u={...i,bounds:null,closing:!1,open:!0,sidebarWidth:i.sidebarWidth??s.sidebarWidth}:i.open?m=!0:(i.closing||s.open||s.closing)&&(m=!1);let p=u.open||u.closing;if(p&&!d&&document.activeElement!==a&&(O=document.activeElement),!p&&d&&O?.isConnected){let H=O;window.requestAnimationFrame(()=>window.requestAnimationFrame(()=>H.focus({preventScroll:!0})))}s=u,p&&s.expanded?a.dataset.expanded="true":a.removeAttribute("data-expanded");for(let H of k)H();Object.assign(a.style,w(s,n,window.innerWidth<640)),I(T,s,n,window.innerWidth<640),de(),s.ready&&!W&&(W=!0,n.onReady?.())}return}if(o.type==="iframe.error"){n.onError?.(o.payload);return}if(o.type==="iframe.status"){n.onStatusChange?.(o.payload);return}if(o.type==="iframe.tool-cancel"){let i=o.payload;i.idempotencyKey&&S.get(i.idempotencyKey)?.abort();return}if(o.type==="iframe.auth-request"){let i=await C.get(),d=await _(15e3,u=>fetch(`${c}/v1/agents/${encodeURIComponent(n.agentId)}/embed-sessions`,{body:JSON.stringify({iframeOrigin:g,sessionId:r}),cache:"no-store",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},method:"POST",signal:u}));if(!d.ok)throw new Error("Could not authenticate HeroUI Agent");f("host.rpc-result",{value:await d.json()},o.requestId);return}if(o.type==="iframe.context-request"){let i=ae(await n.context?.page?.()??{},ve,"Agent page context");f("host.rpc-result",{value:i},o.requestId);return}if(o.type==="iframe.tool-execute"){let i=ke(o.payload),d=n.tools?.find(p=>p.name===i.name);if(!d)throw new Error(`Unknown client tool: ${i.name}`);let u=A.get(i.idempotencyKey);if(!u){let p=new AbortController;S.set(i.idempotencyKey,p),u=Te(d,i,n,le,p.signal).finally(()=>S.delete(i.idempotencyKey)),A.set(i.idempotencyKey,u),A.size>2048&&A.delete(A.keys().next().value)}f("host.rpc-result",{value:await u},o.requestId);return}if(o.type==="iframe.feedback"){await n.onFeedback?.(o.payload);return}if(o.type==="iframe.storage"){Se(o.payload);return}if(o.type==="iframe.persistence"){let i=await import("./persistence-YI6JSYCT.js").then(({executeAgentHostPersistence:d})=>d(n.agentId,o.payload));f("host.rpc-result",{value:i},o.requestId)}}catch(i){let d=Z(i,o.type==="iframe.auth-request"?"authenticating":"failed");n.onError?.(d),f("host.rpc-error",{error:d.message},o.requestId)}},j=o=>{o.composedPath().includes(a)||s.open&&s.viewMode==="floating"&&(n.appearance?.shouldCloseOnInteractOutside??!0)&&M(!1)},R=()=>{s={...s,bounds:null},Object.assign(a.style,w(s,n,window.innerWidth<640)),I(T,s,n,window.innerWidth<640)},U=()=>{document.visibilityState==="visible"&&(s={...s,bounds:null},Object.assign(a.style,w(s,n,window.innerWidth<640)),I(T,s,n,window.innerWidth<640),m&&s.mounted&&f("host.command",{name:"show"}),x!==null&&window.cancelAnimationFrame(x),x=window.requestAnimationFrame(()=>{x=null,Object.assign(a.style,w(s,n,window.innerWidth<640))}))};return window.addEventListener("message",z),window.addEventListener("pointerdown",j,!0),window.addEventListener("resize",R),window.addEventListener("pageshow",U),window.visualViewport?.addEventListener("resize",R),document.addEventListener("visibilitychange",U),{destroy:()=>{$=!0;for(let o of S.values())o.abort();S.clear(),window.removeEventListener("message",z),window.removeEventListener("pointerdown",j,!0),window.removeEventListener("resize",R),window.removeEventListener("pageshow",U),window.visualViewport?.removeEventListener("resize",R),document.removeEventListener("visibilitychange",U),x!==null&&window.cancelAnimationFrame(x);for(let o of h.values())window.clearTimeout(o.timer),o.reject(new Error("HeroUI Agent iframe was removed"));h.clear(),y.length=0,k.clear(),re(T),a.remove()},hide:()=>M(!1),newConversation:o=>{m=!0,E("newConversation",{prompt:o})},preload:()=>E("preload"),get ready(){return s.ready},refreshAuth:()=>{C.clear(),E("refreshAuth")},show:()=>M(!0),shutdown:()=>{m=!1,b=!1,C.reset(),E("shutdown")},subscribe:o=>(k.add(o),()=>k.delete(o)),toggle:()=>M(!m),update:o=>{if(o.agentId!==n.agentId)throw new Error("HeroUI Agent agentId cannot change without remounting");o.getAuthToken!==n.getAuthToken&&(C=new P(o.agentId,o.getAuthToken)),n=o,Object.assign(a.style,w(s,n,window.innerWidth<640)),I(T,s,n,window.innerWidth<640),s.ready&&N("host.update")}}}async function Te(e,t,n,r,l){let c={conversationId:t.conversationId,idempotencyKey:t.idempotencyKey,signal:l,toolCallId:t.toolCallId,uploadDataSource:async a=>await r("host.upload-data-source",{toolCallId:t.toolCallId,upload:a})},g=await e.execute(K(e,t.args),n.context??{},c)??null;return ae(g,Ae,`Client tool ${e.name} result`)}async function xe(e,t){let{context:n,getAuthToken:r,onError:l,onFeedback:c,onReady:g,onStatusChange:a,tools:h,...y}=e,v=await t(h??[]);return{localStorage:se(window.localStorage),props:JSON.parse(JSON.stringify(y)),sessionStorage:se(window.sessionStorage),tools:v}}function Ie(e,t){let n=t.get(e.requestId);if(n)if(t.delete(e.requestId),window.clearTimeout(n.timer),e.type==="iframe.rpc-error"){let r=e.payload;n.reject(new Error(typeof r?.error=="string"?r.error:"Iframe request failed"))}else{let r=e.payload;n.resolve(r?.value)}}function ke(e){if(!e||typeof e!="object")throw new Error("Invalid client tool request");let t=e;if(typeof t.conversationId!="string"||typeof t.idempotencyKey!="string"||typeof t.name!="string"||typeof t.toolCallId!="string")throw new Error("Invalid client tool request");return t}function ae(e,t,n){if(!Q(e))throw new Error(`${n} must be JSON-serializable`);let r=JSON.stringify(e);if(new TextEncoder().encode(r).byteLength>t)throw new Error(`${n} exceeds ${Math.round(t/1024)} KiB`);return JSON.parse(r)}function se(e){let t={};try{for(let n=0;n<e.length;n+=1){let r=e.key(n);r?.startsWith("heroui-agent:")&&(t[r]=e.getItem(r)??"")}}catch{}return t}function Se(e){if(!e||typeof e!="object")return;let t=e;if(typeof t.key=="string"&&!t.key.startsWith("heroui-agent:"))return;let n=t.storage==="session"?sessionStorage:localStorage;try{if(t.operation==="set"&&typeof t.key=="string"&&typeof t.value=="string")n.setItem(t.key,t.value);else if(t.operation==="remove"&&typeof t.key=="string")n.removeItem(t.key);else if(t.operation==="clear")for(let r=n.length-1;r>=0;r-=1){let l=n.key(r);l?.startsWith("heroui-agent:")&&n.removeItem(l)}}catch{}}function Ee(e,t){return e.has(t)?!1:(e.add(t),e.size>2048&&e.delete(e.values().next().value),!0)}function He(e,t){if(t){let n=new URL(t);if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error("HeroUI Agent embed origin must use HTTP or HTTPS");return n.origin}return/^https?:\/\/(?:localhost|127\.0\.0\.1)(?::\d+)?$/i.test(e)?"http://localhost:8793":e.includes("staging")?V:J}export{pe as a,_ as b,Z as c,P as d,De as e};
|
package/dist/chunk-BDMHEOR3.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{b as i,k as a}from"./chunk-YPHOJDYK.js";import{z as t}from"zod";var c=["readConversationHistory","callMcpTool","composeUI","executeSandbox","generateFile","getComponentSchema","renderComponent","searchKnowledge","searchMcpTools","searchWeb"],m="mcp_",p=20,l=16*1024,d=t.object({description:t.string().trim().min(1).max(1e3),inputSchema:t.record(t.string(),t.unknown()),name:t.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/).refine(e=>!c.includes(e)&&!e.toLowerCase().startsWith(m),"Client tool name is reserved by the HeroUI Agent runtime"),needsApproval:t.boolean().optional()}),f=t.array(d).max(p).superRefine((e,n)=>{let o=new Set;for(let r of e)o.has(r.name)&&n.addIssue({code:"custom",message:`Duplicate client tool name: ${r.name}`}),o.add(r.name);new TextEncoder().encode(JSON.stringify(e)).byteLength>l&&n.addIssue({code:"custom",message:"Client tool manifest exceeds 16KB"})});function u(e){let n=i(e.parameters)?t.toJSONSchema(e.parameters):e.parameters;if(!a(n))throw new Error(`Client tool ${e.name} parameters must be a JSON-serializable schema`);return s(n)}function s(e){return Array.isArray(e)?e.map(s):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,o])=>[n,s(o)])):e}function y(e){return f.parse(e.map(n=>({description:n.description,inputSchema:u(n),name:n.name,...n.needsApproval?{needsApproval:!0}:{}})))}export{c as a,m as b,p as c,l as d,d as e,f,y as g};
|
package/dist/chunk-MPJ6AAXH.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t="1.0.0-beta.7",o="https://api.heroui.pro";export{t as a,o as b};
|