@heroui/agent 0.2.0-beta.13 → 0.2.0-beta.15
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 +21 -0
- package/README.md +2 -2
- package/dist/chunk-HIZ5SSLG.js +2 -0
- package/dist/chunk-YXZJD5XQ.js +2 -0
- package/dist/contracts.d.ts +3 -1
- package/dist/contracts.js +2 -2
- package/dist/css/index.css +1 -1
- package/dist/{embed-runtime-7MSWJUQM.js → embed-runtime-YTHRILKV.js} +2 -2
- package/dist/index.d.ts +19 -0
- package/dist/index.js +1 -1
- package/dist/next.js +1 -1
- package/dist/server.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-S3NBK5KL.js +0 -2
- package/dist/chunk-WVP7S2A4.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -311,6 +311,12 @@ type AgentSharedContext = {
|
|
|
311
311
|
page?: () => AgentContext | Promise<AgentContext>;
|
|
312
312
|
} & Record<string, unknown>;
|
|
313
313
|
type AgentViewMode = "floating" | "sidebar";
|
|
314
|
+
/**
|
|
315
|
+
* Controls whether an outside interaction closes the floating panel. Matches React
|
|
316
|
+
* Aria Popover: `true` or omitted always closes; `false` never closes; a
|
|
317
|
+
* predicate receives the outside element and returns whether to close.
|
|
318
|
+
*/
|
|
319
|
+
type AgentShouldCloseOnInteractOutside = boolean | ((element: Element) => boolean);
|
|
314
320
|
type AgentMarkdownAnimation = boolean | AnimateOptions;
|
|
315
321
|
type AgentMarkdownCaret = "block" | "circle";
|
|
316
322
|
type AgentMarkdownRenderer = CustomRenderer;
|
|
@@ -446,6 +452,13 @@ type AgentAppearance = {
|
|
|
446
452
|
launcher?: AgentLauncherOptions;
|
|
447
453
|
/** Size and expansion of the floating panel. */
|
|
448
454
|
panel?: AgentPanelOptions;
|
|
455
|
+
/**
|
|
456
|
+
* When the visitor interacts outside the floating panel, whether to close it.
|
|
457
|
+
* Only applies in `viewMode: "floating"`. `true` or omitted always closes;
|
|
458
|
+
* `false` never closes on outside interact; a predicate receives the outside
|
|
459
|
+
* element. Escape and the header close button are unchanged.
|
|
460
|
+
*/
|
|
461
|
+
shouldCloseOnInteractOutside?: AgentShouldCloseOnInteractOutside;
|
|
449
462
|
theme?: AgentThemeOptions;
|
|
450
463
|
/**
|
|
451
464
|
* How the chat opens: `"floating"` (default) is a floating rounded panel in
|
|
@@ -598,6 +611,12 @@ type HeroUIAgentProps = {
|
|
|
598
611
|
* @default true
|
|
599
612
|
*/
|
|
600
613
|
showLauncher?: boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Show a compact Beta chip in the open panel header, next to the assistant
|
|
616
|
+
* title. Useful while the agent is still stabilizing for end users.
|
|
617
|
+
* @default false
|
|
618
|
+
*/
|
|
619
|
+
showBetaBadge?: boolean;
|
|
601
620
|
startScreen?: AgentStartScreenOptions;
|
|
602
621
|
/**
|
|
603
622
|
* Client tools the agent can call in the user's browser. Define with
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as m,b as a}from"./chunk-
|
|
1
|
+
import{a as m,b as a}from"./chunk-HIZ5SSLG.js";import"./chunk-YXZJD5XQ.js";import"./chunk-6ZJJN322.js";import{a as e}from"./chunk-64RI74L5.js";import{a as t,b as n,c as o,d as r,e as A,f as g,g as i}from"./chunk-UHHKMESI.js";import{a as s}from"./chunk-7KCGPNEN.js";import{a as p}from"./chunk-4JEZZR5J.js";export{p as AGENT_DESIGN_THEMES,t as AGENT_MODEL_IDS,A as AGENT_MODEL_OPTIONS,r as DEFAULT_AGENT_PICKER_MODEL_ID,s as HEROUI_AGENT_RUNTIME_TIMING_EVENT,a as HeroUIAgent,n as LEGACY_AGENT_MODEL_IDS,e as createToolHelper,i as getAgentModelTier,g as isAgentModelId,o as resolveAgentModelId,m as useAgent};
|
package/dist/next.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,b as p}from"./chunk-
|
|
1
|
+
import{a as i,b as p}from"./chunk-HIZ5SSLG.js";import"./chunk-YXZJD5XQ.js";import"./chunk-6ZJJN322.js";import{a as e}from"./chunk-64RI74L5.js";import{a as t,d as n,e as o,f as r,g as A}from"./chunk-UHHKMESI.js";import{a as g}from"./chunk-7KCGPNEN.js";import"./chunk-4JEZZR5J.js";export{t as AGENT_MODEL_IDS,o as AGENT_MODEL_OPTIONS,n as DEFAULT_AGENT_PICKER_MODEL_ID,g as HEROUI_AGENT_RUNTIME_TIMING_EVENT,p as HeroUIAgent,e as createToolHelper,A as getAgentModelTier,r as isAgentModelId,i as useAgent};
|
package/dist/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as e}from"zod";var m="0.2.0-beta.
|
|
1
|
+
import{z as e}from"zod";var m="0.2.0-beta.15",u="https://api.heroui.pro";var d=e.enum(["light","dark","system"]),y=e.enum(["outline","plain","surface","surface-secondary"]),f=new Set(["[object object]","0","anonymous","distinct_id","distinctid","email","false","guest","id","nan","none","not_authenticated","null","true","undefined"]),c=e.string().trim().min(1).max(200).refine(t=>!f.has(t.toLowerCase()),{message:"Identity id is reserved"}),I=e.discriminatedUnion("type",[e.object({id:c,type:e.literal("anonymous")}),e.object({id:c,type:e.literal("user")})]),S=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()}),g=e.object({anonymousId:c.optional(),identity:I,profile:S.optional()}),h=e.object({expiresAt:e.number().int().positive(),token:e.string().trim().min(1)}),O=e.object({agentId:e.string().trim().min(1).max(100),apiKeyId:e.string().trim().min(1).max(100),aud:e.literal("heroui-agent"),exp:e.number().int().positive(),iat:e.number().int().positive(),iss:e.literal("https://api.heroui.com"),jti:e.uuid(),protocolVersion:e.literal(6),sub:e.string().trim().min(1).max(200)});var _=e.object({agentId:e.string(),minimumProtocolVersion:e.literal(6),name:e.string().trim().min(1).max(120),protocolVersion:e.literal(6),sdkVersion:e.string().default(m),suggestedPrompts:e.array(e.string().trim().min(1).max(160)).max(5),surfaceVariant:y.default("plain"),theme:d});var n=class extends Error{status;constructor(o,i,a){super(o,a),this.name="HeroUIAgentAuthError",this.status=i}};async function C(t){let o=t.apiKey.trim(),i=t.agentId.trim(),a=g.safeParse({anonymousId:t.anonymousId,identity:t.identity,profile:t.profile});if(!o||!i||!a.success)throw new n("Invalid HeroUI Agent auth token request",400);let l=(t.apiBaseUrl?.trim()||u).replace(/\/$/,""),r;try{r=await fetch(`${l}/v1/agents/${encodeURIComponent(i)}/auth-tokens`,{body:JSON.stringify(a.data),cache:"no-store",headers:{Accept:"application/json","Content-Type":"application/json","X-HeroUI-Agent-Key":o},method:"POST"})}catch(A){throw new n("HeroUI Agent authentication is unavailable",503,{cause:A})}if(!r.ok)throw new n("HeroUI Agent authentication failed",r.status);let p=h.safeParse(await r.json().catch(()=>null));if(!p.success)throw new n("HeroUI Agent authentication returned invalid data",502);return p.data}export{n as HeroUIAgentAuthError,C as createAuthToken};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heroui/agent",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.15",
|
|
4
4
|
"description": "Embed a hosted HeroUI Agent that turns application data into interactive UI.",
|
|
5
|
-
"homepage": "https://
|
|
5
|
+
"homepage": "https://heroui.pro/agents",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/heroui-inc/heroui-pro/issues"
|
|
8
8
|
},
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"react-aria-components": "1.19.0",
|
|
81
81
|
"recharts": "3.8.0",
|
|
82
82
|
"shiki": "4.0.2",
|
|
83
|
+
"mermaid": "11.16.1",
|
|
83
84
|
"streamdown": "2.5.0",
|
|
84
85
|
"zod": "4.3.6"
|
|
85
86
|
},
|
|
@@ -101,8 +102,7 @@
|
|
|
101
102
|
"@types/react-dom": "19.2.3",
|
|
102
103
|
"fake-indexeddb": "6.2.5",
|
|
103
104
|
"jsdom": "26.1.0",
|
|
104
|
-
"
|
|
105
|
-
"postcss": "8.5.9",
|
|
105
|
+
"postcss": "8.5.23",
|
|
106
106
|
"publint": "0.3.21",
|
|
107
107
|
"react": "19.2.6",
|
|
108
108
|
"react-dom": "19.2.6",
|
|
@@ -111,9 +111,9 @@
|
|
|
111
111
|
"typescript": "5.9.3",
|
|
112
112
|
"vitest": "4.1.0",
|
|
113
113
|
"@heroui-pro/config": "0.0.0",
|
|
114
|
-
"@heroui-
|
|
114
|
+
"@heroui/agent-client": "0.0.0",
|
|
115
115
|
"@heroui/agent-ui": "0.0.0",
|
|
116
|
-
"@heroui/
|
|
116
|
+
"@heroui-pro/react": "1.0.0-beta.8"
|
|
117
117
|
},
|
|
118
118
|
"scripts": {
|
|
119
119
|
"build": "rm -rf dist && tsup && pnpm build:styles",
|
package/dist/chunk-S3NBK5KL.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{E as on,a as qe,c as je,d as ze,f as de,g as Be,j as Ke,k as Qe,l as Ze,o as fe,q as en,r as nn,w as tn}from"./chunk-WVP7S2A4.js";import{a as Je}from"./chunk-6ZJJN322.js";import{d as Xe,e as Ye}from"./chunk-UHHKMESI.js";import{useCallback as C,useEffect as w,useEffectEvent as ht,useLayoutEffect as Sn,useMemo as Ce,useRef as v,useState as p,useSyncExternalStore as Tn}from"react";import{createRoot as yt}from"react-dom/client";import{SparklesFill as Kn}from"@gravity-ui/icons";import{jsx as Jn}from"react/jsx-runtime";function rn(e){return Jn(Kn,{...e})}import{jsx as me}from"react/jsx-runtime";function Xn(e){return/\.svg(?:[?#]|$)/i.test(e)||/^data:image\/svg\+xml[;,]/i.test(e)}function sn(e){return`url("${e.replace(/["\\\n\r]/g,encodeURIComponent)}")`}function an({icon:e}){return e?Xn(e)?me("span",{"aria-hidden":"true",className:"ha-launcher__icon ha-launcher__icon--tinted",style:{WebkitMaskImage:sn(e),maskImage:sn(e)}}):me("img",{alt:"",className:"ha-launcher__icon",src:e}):me(rn,{})}function cn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ln(e,n){if(n===void 0)return e;if(!cn(e)||!cn(n))return n;let t={...e};for(let[r,a]of Object.entries(n))a!==void 0&&(t[r]=r in e?ln(e[r],a):a);return t}function un(e,n){if(!e)return n;let t={appearance:e.appearance,capabilities:e.capabilities,composer:e.composer,markdown:e.markdown,permissions:e.permissions,responseActions:e.responseActions,startScreen:e.startScreen},r=ln(t,{appearance:n.appearance,capabilities:n.capabilities,composer:n.composer,markdown:n.markdown?{...n.markdown,plugins:void 0}:void 0,permissions:n.permissions,responseActions:n.responseActions,startScreen:n.startScreen});return{...n,...r}}function dn(e){return!!e.appearance?.theme?.typography?.fontFamily?.trim()}var fn=1,c=Symbol("invalid");function G(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function S(e){if(e!==void 0)return typeof e=="string"?e:c}function I(e){if(e!==void 0)return typeof e=="boolean"?e:c}function pe(e){if(e!==void 0)return typeof e=="number"&&Number.isFinite(e)?e:c}function M(e){return n=>{if(n!==void 0)return typeof n=="string"&&e.includes(n)?n:c}}function mn(e){if(e===void 0)return;if(typeof e=="string")return e;if(!G(e))return c;let n=S(e.dark),t=S(e.light);return n===c||t===c?c:{...n===void 0?{}:{dark:n},...t===void 0?{}:{light:t}}}function Yn(e){if(e===void 0)return;if(!G(e))return c;let n={};for(let[t,r]of Object.entries(e)){if(typeof r!="string")return c;n[t]=r}return n}function Qn(e){if(e!==void 0)return!Array.isArray(e)||e.some(n=>typeof n!="string")?c:e}function b(e,n){if(e===void 0||!G(e))return c;let t={};for(let[r,a]of Object.entries(n)){let l=a(e[r]);if(l===c)return c;l!==void 0&&(t[r]=l)}return t}function T(e){return e===c?void 0:e}var Zn=["accent","background","foreground","overlay","surface","surfaceSecondary","tooltip"];function et(e){return b(e,{launcher:n=>n===void 0?void 0:b(n,{background:mn,icon:S,position:M(["bottom-left","bottom-right"]),style:Yn}),panel:n=>n===void 0?void 0:b(n,{expandable:I,expanded:I,initialHeight:t=>t===void 0||typeof t=="string"?t:pe(t),initialWidth:t=>t===void 0||typeof t=="string"?t:pe(t)}),theme:n=>n===void 0?void 0:b(n,{colorScheme:M(["dark","light","system"]),colors:t=>t===void 0?void 0:b(t,Object.fromEntries(Zn.map(r=>[r,mn]))),designTheme:M(["base","brutalism","glass","mouve"]),radius:M(["pill","round","sharp","soft"]),typography:t=>t===void 0?void 0:b(t,{baseSize:pe,fontFamily:S})}),viewMode:M(["floating","sidebar"])})}function nt(e){return b(e,{attachments:n=>{if(n===void 0||n===!1)return n;if(!Array.isArray(n))return c;let t=n.filter(r=>typeof r=="string"&&Ke(r));return t.length===n.length?t:c},defaultModel:S,dictation:I,disclaimer:n=>n===!1?!1:S(n),modelPicker:I,placeholder:S})}function tt(e){return b(e,{animated:n=>{if(n===void 0||n===!1)return n;if(!G(n))return c;let t=M(["blurIn","fadeIn","slideUp"])(n.animation);return t===c||t===void 0?c:{...n,animation:t}},caret:n=>n===!1?!1:M(["block","circle"])(n)})}function ot(e){if(e===void 0||e===!1)return e;if(!Array.isArray(e))return c;let n=["copy","feedback","retry"],t=e.filter(r=>typeof r=="string"&&n.includes(r));return t.length===e.length?t:c}function Z(e){if(!G(e)||e.version!==fn)return null;let n=e.revision;if(typeof n!="string"||!n)return null;let t=T(et(e.appearance)),r=T(b(e.capabilities,{imageSearch:I,newsSearch:I,webSearch:I})),a=T(nt(e.composer)),l=T(tt(e.markdown)),f=T(b(e.permissions,{defaultMode:M(["ask","auto","full"]),showPicker:I})),u=T(ot(e.responseActions)),m=T(b(e.startScreen,{greeting:S,promptShortcuts:I,prompts:Qn})),k=T(b(e.webfont,{familyName:g=>typeof g=="string"&&g?g:c,fontFaceUrl:S,stylesheetUrl:S}));return{...t?{appearance:t}:{},...r?{capabilities:r}:{},...a?{composer:a}:{},...l?{markdown:l}:{},...f?{permissions:f}:{},...u===void 0?{}:{responseActions:u},...m?{startScreen:m}:{},...k?{webfont:k}:{},revision:n,version:fn}}function ge(e){return`heroui-agent:config:${e}`}var pn=1;function gn(e){try{let n=window.localStorage.getItem(ge(e));if(!n)return null;let t=JSON.parse(n);if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let a=t;if(a.cacheVersion===pn&&typeof a.cachedAt=="number"&&Number.isFinite(a.cachedAt)){let l=Z(a.config);return l?{cachedAt:a.cachedAt,config:l,legacy:!1}:null}}let r=Z(t);return r?{cachedAt:0,config:r,legacy:!0}:null}catch{return null}}function he(e,n,t=Date.now()){try{let r={cacheVersion:pn,cachedAt:t,config:n};window.localStorage.setItem(ge(e),JSON.stringify(r))}catch{}}function hn(e){try{window.localStorage.removeItem(ge(e))}catch{}}async function yn(e,n,t={}){try{let r=await fetch(`${e}/v1/agents/${encodeURIComponent(n)}/appearance`,{headers:t.revision?{"If-None-Match":`"${t.revision}"`}:{},...t.signal?{signal:t.signal}:{}});if(r.status===304)return{status:"not-modified"};if(r.status===404||r.status===410)return{status:"missing"};if(!r.ok)return{status:"unavailable"};let a=Z(await r.json());return a?{config:a,status:"ok"}:{status:"unavailable"}}catch{return{status:"unavailable"}}}import{ChevronDown as rt,Microphone as it,Plus as st,ShieldCheck as at}from"@gravity-ui/icons";import{useEffect as ct,useRef as lt}from"react";import{Fragment as wn,jsx as h,jsxs as ye}from"react/jsx-runtime";var ut={ask:"Ask for approval",auto:"Approve for me",full:"Full access"};function Cn({onFileDialogActiveChange:e,onIntent:n,options:t}){return{end:h(ft,{options:t}),footer:t.composerDisclaimer?h("p",{className:"ha-footnote",children:Je(t.composerDisclaimer)}):null,start:t.composerAttachmentContentTypes.length>0?h(dt,{accept:t.composerAttachmentAccept,agentId:t.agentId,onFileDialogActiveChange:e,onIntent:n}):null}}function dt({accept:e,agentId:n,onFileDialogActiveChange:t,onIntent:r}){let a=lt(null);return ct(()=>{let l=a.current,f,u=()=>t(!1),m=()=>{f=window.setTimeout(u,0)};return l?.addEventListener("cancel",u),window.addEventListener("focus",m),()=>{l?.removeEventListener("cancel",u),window.removeEventListener("focus",m),window.clearTimeout(f)}},[t]),ye(wn,{children:[h("input",{ref:a,multiple:!0,accept:e,"aria-label":"Choose files to attach",className:"ha-file-input",type:"file",onChange:l=>{nn(n,Array.from(l.currentTarget.files??[])),l.currentTarget.value="",t(!1),r()}}),h("button",{"aria-label":"Attach files",className:"ha-attach",type:"button",onClick:()=>{t(!0),a.current?.click()},children:h(st,{"aria-hidden":"true"})})]})}function ft({options:e}){let n=e.composerDefaultModel??Xe,t=Ye.find(r=>r.id===n)?.label??n;return ye(wn,{children:[e.permissionShowPicker&&e.tools.length>0?h(bn,{icon:h(at,{"aria-hidden":"true",className:"aui-permission-picker__trigger-icon"}),kind:"permission",label:ut[e.permissionDefaultMode],tone:e.permissionDefaultMode==="full"?"warning":void 0}):null,e.composerModelPicker?h(bn,{kind:"model",label:t}):null,e.composerDictation?h("button",{disabled:!0,"aria-label":"Dictate message",className:"ha-dictation",type:"button",children:h(it,{"aria-hidden":"true"})}):null]})}function bn({icon:e,kind:n,label:t,tone:r}){let a=`aui-${n}-picker`;return h("div",{className:`${a} ha-${n}-picker`,"data-tone":r,children:ye("button",{disabled:!0,"aria-label":n==="model"?"AI model":"Tool permissions",className:`${a}__trigger ha-shell-picker-trigger`,type:"button",children:[e,h("span",{className:`${a}__value`,children:t}),h(rt,{"aria-hidden":"true",className:`${a}__indicator`})]})})}var mt=[".woff2",".woff",".ttf",".otf",".eot"];function pt(e){return`heroui-agent-font-${e.familyName.toLowerCase().replace(/[^a-z0-9]+/g,"-")}`}function gt(e){let n=e.includes(":vf@")||e.includes("-wght-")||e.includes("-opsz-");return e.endsWith(".woff")?"woff":e.endsWith(".ttf")?"truetype":e.endsWith(".otf")?"opentype":n?"woff2-variations":"woff2"}function Rn(e,n){try{let t=new URL(e);if(t.protocol!=="https:")return!1;if(!n)return!0;let r=t.pathname.toLowerCase();return mt.some(a=>r.endsWith(a))}catch{return!1}}function An(e){if(!e||typeof document>"u")return()=>{};let n=pt(e);if(document.getElementById(n))return()=>{};if(e.stylesheetUrl&&Rn(e.stylesheetUrl,!1)){let t=document.createElement("link");return t.id=n,t.rel="stylesheet",t.href=e.stylesheetUrl,document.head.append(t),()=>t.remove()}if(e.fontFaceUrl&&Rn(e.fontFaceUrl,!0)){let t=document.createElement("style"),r=e.fontFaceUrl.includes(":vf@")||e.fontFaceUrl.includes("-wght-")||e.fontFaceUrl.includes("-opsz-");return t.id=n,t.textContent=["@font-face {",` font-family: '${e.familyName.replaceAll("'","")}';`," font-style: normal;"," font-display: swap;",` font-weight: ${r?"100 900":"400"};`,` src: url(${e.fontFaceUrl}) format('${gt(e.fontFaceUrl)}');`,"}"].join(`
|
|
2
|
-
`),document.head.append(t),()=>t.remove()}return()=>{}}import{Fragment as Nn,jsx as O,jsxs as En}from"react/jsx-runtime";var bt=600,Ct=5*6e4,wt="heroui-agent:open:";function we(e){return`${wt}${e}`}function Rt(e){if(typeof window>"u")return!1;try{return window.sessionStorage.getItem(we(e))==="true"}catch{return!1}}function be(e,n){try{n?window.sessionStorage.setItem(we(e),"true"):window.sessionStorage.removeItem(we(e))}catch{}}var kn;function In(){return kn??=import(/* webpackPrefetch: true */"./embed-runtime-7MSWJUQM.js").then(e=>e.default),kn}var D=new Map,Re=new Set;function Mn(e){return e?D.get(e):[...D.values()][D.size-1]}function vn(){for(let e of Re)e()}function At(e){return Re.add(e),()=>Re.delete(e)}function St(e){let n=window.matchMedia?.("(prefers-color-scheme: dark)");return n?.addEventListener?.("change",e),()=>n?.removeEventListener?.("change",e)}function kt(){return window.matchMedia?.("(prefers-color-scheme: dark)").matches===!0}function L(e,n,...t){let r=Mn(e);if(!r){console.warn("HeroUI Agent is not mounted yet. Add <HeroUIAgent /> to your layout.");return}let a=r[n];a(...t)}function It(e,n,t){let[r]=p(()=>!t||typeof window>"u"?null:gn(e)),[a,l]=p(()=>{if(!t)return{config:null,presentationReady:!0};let f=r?Date.now()-r.cachedAt:Number.POSITIVE_INFINITY,u=r!==null&&!r.legacy&&f>=0&&f<=Ct;return{config:u?r.config:null,presentationReady:u}});return w(()=>{if(!t)return;let f=new AbortController,u=!0,m=g=>{l(q=>q.presentationReady?q:{config:g,presentationReady:!0})},k=window.setTimeout(()=>{u&&(f.abort(),m(r?.config??null))},bt);return yn(n,e,{...r?.config.revision?{revision:r.config.revision}:{},signal:f.signal}).then(g=>{if(!(!u||f.signal.aborted)){if(g.status==="ok"){he(e,g.config),m(g.config);return}if(g.status==="not-modified"){r&&he(e,r.config),m(r?.config??null);return}if(g.status==="missing"){hn(e),m(null);return}m(r?.config??null)}}).finally(()=>{!u||f.signal.aborted||window.clearTimeout(k)}),()=>{u=!1,f.abort(),window.clearTimeout(k)}},[n,r,t,e]),t?a:{config:null,presentationReady:!0}}function ao(e){let n=C(()=>Mn(e)?.ready??!1,[e]),t=Tn(At,n,()=>!1);return Ce(()=>({hide:()=>L(e,"hide"),newConversation:r=>L(e,"newConversation",r),preload:()=>L(e,"preload"),ready:t,refreshAuth:()=>L(e,"refreshAuth"),show:()=>L(e,"show"),shutdown:()=>L(e,"shutdown"),toggle:()=>L(e,"toggle")}),[e,t])}function co(e){let n=`${e.agentId}\0${e._api?.baseUrl??""}\0${e.remoteConfig!==!1}`;return O(vt,{...e},n)}function vt(e){let{_api:n,agentId:t,appearance:r,capabilities:a,componentExports:l,composer:f,context:u,getAuthToken:m,markdown:k,onFeedback:g,onReady:q,permissions:On,preload:Pn,remoteConfig:_n=!0,reopenOnRefresh:Ae,responseActions:Un,showLauncher:Ln,startNewConversationOnOpen:xn,startScreen:Fn,tools:Se}=e,j=k?.plugins,$n=(n?.baseUrl??je).replace(/\/$/,""),{config:ke,presentationReady:x}=It(t,$n,_n),Ie=JSON.stringify({_api:n,appearance:r,capabilities:a,componentExports:l,composer:f,markdown:k?{...k,plugins:void 0}:void 0,permissions:On,preload:Pn,remote:ke,reopenOnRefresh:Ae,responseActions:Un,showLauncher:Ln,startNewConversationOnOpen:xn,startScreen:Fn}),o=Ce(()=>{let{remote:i,...s}=JSON.parse(Ie),d=un(i,{...s,agentId:t,getAuthToken:m});return on({...d,context:u,markdown:d.markdown?{...d.markdown,plugins:j}:j?{plugins:j}:void 0,onFeedback:g,tools:Se})},[u,m,j,g,t,Ie,Se]),z=Ce(()=>new qe(t,m),[t,m]),ve=dn(e),Ee=ke?.webfont;w(()=>{if(!ve)return An(Ee)},[ve,Ee]);let[B]=p(()=>Ae===!0&&Rt(t)),[ee,V]=p(B),[P,Hn]=p(1),[Ne,Te]=p(1),[Me,Oe]=p(!1),[K,Dn]=p(B||o.startNewConversationOnOpen?null:void 0),[E,Vn]=p(null),[J,Wn]=p(null),[Pe,Gn]=p(!1),[ne,te]=p(!1),[qn,_e]=p(null),oe=v(1),Ue=v(null),re=v(!1),ie=v(null),Le=v(null),F=v(B),se=v(null),X=v(null),ae=v([]),jn=Tn(St,kt,()=>!1),ce=o.designTheme==="base"?null:`${o.designTheme}-${o.colorScheme==="system"?jn?"dark":"light":o.colorScheme}`,_=x&&qn===P&&J!==null,y=x&&ee,[Y,zn]=p(B||o.preload),R=C(()=>zn(!0),[]),[W,$]=p(!1),[xe,Fe]=p(!1),le=C(()=>$(!0),[]);w(()=>{if(!W||!E)return;let i=()=>{queueMicrotask(()=>{let s=E.querySelector(".ha-composer:not([hidden] *)");s&&en(s,document.activeElement)||$(!1)})};return E.addEventListener("focusout",i),()=>E.removeEventListener("focusout",i)},[W,E]),w(()=>{Y&&z.get().catch(()=>{})},[Y,z]),w(()=>{o.reopenOnRefresh?be(o.agentId,ee):be(o.agentId,!1)},[ee,o.agentId,o.reopenOnRefresh]),w(()=>{if(!Y)return;if(!x){In().catch(()=>{});return}let i=!0;return In().then(s=>{i&&Wn(()=>s)}).catch(()=>{}),()=>{i=!1}},[x,Y]),w(()=>{if(!y||o.viewMode!=="sidebar"||window.innerWidth<640)return;let i=document.documentElement,s=i.style.marginRight,d=i.style.transition,A=window.matchMedia("(prefers-reduced-motion: reduce)").matches,ue=Math.min(de(o.agentId,window.innerWidth),window.innerWidth);return A||(i.style.transition=[d,"margin-right .28s cubic-bezier(.2,.8,.2,1)"].filter(Boolean).join(", ")),i.style.marginRight=`${ue}px`,()=>{i.style.marginRight=s,window.setTimeout(()=>{i.style.transition=d},300)}},[y,o.agentId,o.viewMode]),w(()=>{let i=document.createElement("div"),s=document.createElement("div");i.dataset.herouiAgent=o.agentId,s.className="ha-root",se.current=i,ie.current=s,X.current=yt(s),i.append(s),document.body.append(i);let d=!0;return queueMicrotask(()=>{d&&Vn(s)}),()=>{d=!1,fe(o.agentId,!1);let A=X.current;ie.current=null,se.current=null,X.current=null,ae.current=[],queueMicrotask(()=>{A?.unmount(),i.remove()})}},[o.agentId]),Sn(()=>{let i=ie.current,s=se.current;if(!i||!s)return;i.className=ce?`ha-root ${ce}`:"ha-root",i.dataset.theme=o.colorScheme,i.dataset.viewMode=o.viewMode,i.dataset.position=o.launcherPosition,s.dataset.open=y?"true":"false",s.dataset.viewMode=o.viewMode,s.dataset.position=o.launcherPosition,o.launcherOffset?(s.style.setProperty("--ha-launcher-x",`${o.launcherOffset.x}px`),s.style.setProperty("--ha-launcher-y",`${o.launcherOffset.y}px`)):(s.style.removeProperty("--ha-launcher-x"),s.style.removeProperty("--ha-launcher-y")),o.viewMode==="sidebar"&&s.style.setProperty("--ha-sidebar-width",`${de(o.agentId,window.innerWidth)}px`);let d={...o.themeStyle,...o.panelStyle};for(let A of ae.current)A in d||i.style.removeProperty(A);for(let[A,ue]of Object.entries(d))i.style.setProperty(A,ue);ae.current=Object.keys(d)},[ce,y,o.colorScheme,o.agentId,o.launcherOffset,o.launcherPosition,o.panelStyle,o.themeStyle,o.viewMode,E]);let N=C(i=>{fe(o.agentId,!1),Fe(!1),_e(null),Dn(i);let s=oe.current+1;oe.current=s,Hn(s)},[o.agentId]),$e=C(i=>{oe.current===i&&(Gn(!0),_e(i))},[]),Bn=ht(()=>q?.());w(()=>{!_||Le.current===P||(Le.current=P,Bn())},[P,_]);let U=C(()=>{F.current=!1,re.current=!0,V(!1),$(!1),N(o.startNewConversationOnOpen?null:void 0)},[o.startNewConversationOnOpen,N]);w(()=>{y||!_||!re.current||(re.current=!1,requestAnimationFrame(()=>Ue.current?.focus()))},[y,_]);let H=C(()=>{F.current=!0,V(!0),R()},[R]),He=R,Q=C(i=>{let s=i?Qe(i):null;s&&Ze(o.agentId,s),F.current=!0,V(!0),$(!1),R(),N(null)},[o.agentId,N,R]),De=C(i=>{F.current=!0,V(!0),$(!1),R(),N(i)},[N,R]),Ve=C(()=>{y||F.current?U():H()},[U,y,H]),We=C(()=>{te(!1),Oe(!1),Te(i=>i+1)},[]),Ge=C(()=>{let i=[`heroui-agent:anonymous:${o.agentId}`,`heroui-agent:conversation:${o.agentId}:`,`heroui-agent:history:${o.agentId}:`];for(let s=localStorage.length-1;s>=0;s-=1){let d=localStorage.key(s);d&&i.some(A=>d.startsWith(A))&&localStorage.removeItem(d)}F.current=!1,te(!1),V(!1),$(!1),be(o.agentId,!1),Oe(!0),Te(s=>s+1),N(),window.setTimeout(()=>{import("./composer-draft-NSKK65F3.js").then(({clearAgentComposerDraftsForProject:s})=>s(o.agentId)).catch(()=>{})},0)},[o.agentId,N]);return w(()=>{let i={hide:U,newConversation:Q,preload:He,ready:_,refreshAuth:We,show:H,shutdown:Ge,toggle:Ve};return D.set(o.agentId,i),vn(),()=>{D.get(o.agentId)===i&&(D.delete(o.agentId),vn())}},[U,Q,o.agentId,He,_,We,H,Ge,Ve]),Sn(()=>{let i=X.current;if(!E||!i)return;let s=Cn({onFileDialogActiveChange:Fe,onIntent:R,options:o});i.render(En(Nn,{children:[x&&o.showLauncher&&!y?En("button",{ref:Ue,"aria-expanded":!1,"aria-haspopup":"dialog",className:"ha-launcher",style:o.launcherStyle,type:"button","aria-label":ne?"Open data assistant, unread messages":"Open data assistant",onClick:H,children:[O(an,{icon:o.launcherIcon}),ne?O("span",{"aria-hidden":"true",className:"ha-launcher__unread"}):null]}):null,J&&!xe?O(J,{composerControlsRevealed:W,conversationEpoch:P,identityEpoch:Ne,identityReset:Me,open:y,options:o,requestedConversationId:K,shellComposerEndSlot:s.end,shellComposerFooterSlot:s.footer,showReadyLoader:!Pe&&K!==null,tokenManager:z,onClose:U,onComposerControlsReveal:le,onNewConversation:Q,onReady:$e,onSelectConversation:De,onUnreadChange:te}):O(Be,{agentId:o.agentId,defaultExpanded:o.panelExpanded,expandable:o.panelExpandable,historySlot:O(Nn,{}),name:"Data assistant",open:y,viewMode:o.viewMode,onClose:U,children:K===null?O(tn,{composerConnecting:!0,agentId:o.agentId,composerControlsAvailable:o.composerControlsAvailable,composerControlsRevealed:W,composerEndSlot:s.end,composerFooterSlot:s.footer,composerStartSlot:s.start,greeting:o.greeting,placeholder:o.composerPlaceholder,suggestedPrompts:o.suggestedPrompts??[],onComposerControlsReveal:le,onIntent:R},`shell-${P}`):O(ze,{})})]}))},[J,W,xe,P,$e,ne,Pe,U,Ne,Me,y,Q,o,E,_,x,K,R,le,De,H,z]),null}export{ao as a,co as b};
|
package/dist/chunk-WVP7S2A4.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{b as le,e as ce,f as de}from"./chunk-4JEZZR5J.js";var ht="0.2.0-beta.13",ue="https://api.heroui.pro";import{jsx as Fe,jsxs as Ue}from"react/jsx-runtime";function At({indicator:e,label:t="Loading agent\u2026"}){return Ue("div",{"aria-live":"polite",className:"ha-agent-loading",role:"status",children:[e,Fe("span",{children:t})]})}import{jsx as me,jsxs as Be}from"react/jsx-runtime";function z({children:e,shortcut:t}){return Be("span",{"aria-hidden":"true",className:"ha-control-tooltip",children:[me("span",{children:e}),t?me("kbd",{className:"ha-control-tooltip__shortcut",children:t}):null]})}import{ChevronsCollapseUpRight as ze,ChevronsExpandUpRight as Ke}from"@gravity-ui/icons";import{useCallback as he,useEffect as K,useEffectEvent as $e,useLayoutEffect as Xe,useRef as oe,useState as $}from"react";function pe(e){return`heroui-agent:sidebar-width:${e}`}function te(e,t){let n=Math.min(720,Math.floor(t*.9)),o=Math.max(n,320);return Math.min(Math.max(Math.round(e),320),o)}function ge(e,t){let n=Number.NaN;try{n=Number(localStorage.getItem(pe(e))??Number.NaN)}catch{}return te(Number.isFinite(n)?n:420,t)}function ne(e,t){try{localStorage.setItem(pe(e),String(Math.round(t)))}catch{}}import{jsx as d,jsxs as O}from"react/jsx-runtime";function kt({actionsSlot:e,agentId:t,children:n,defaultExpanded:o=!1,expandable:s=!0,expandedSidebarSlot:b,expandedTitle:T,historySlot:i,keepMounted:c=!1,name:p,onClose:M,onNewConversation:R,open:f,viewMode:w}){let y=oe(null),u=oe(0),[L,Q]=$(()=>typeof window>"u"||typeof window.matchMedia!="function"?!1:null),H=$e(M),[h,P]=$(o),F=L!==null,k=L??!1,_=w==="floating",x=!_&&!k,r=k||x&&h,[g,C]=$(!1),_e=!k&&s,U=x&&h&&b;return Xe(()=>{let a=window.matchMedia?.("(max-width: 639px)");if(!a)return;let A=()=>Q(a.matches);return A(),a.addEventListener?.("change",A),()=>a.removeEventListener?.("change",A)},[]),K(()=>{if(!g)return;let a=y.current;if(!a)return;let A=()=>C(!1),E=B=>{let{propertyName:m,target:v}=B;v===a&&(m!=="width"&&m!=="height"||A())},ee=window.setTimeout(A,600);return a.addEventListener("transitionend",E),()=>{window.clearTimeout(ee),a.removeEventListener("transitionend",E)}},[g]),K(()=>{if(!f||!F)return;let a=y.current;if(!a)return;let A=document.activeElement instanceof HTMLElement?document.activeElement:null;a.open||(r&&typeof a.showModal=="function"?a.showModal():!r&&typeof a.show=="function"?a.show():a.open=!0);let E;if(r){let m=document.documentElement,v=window.scrollX,I=window.scrollY,W=m.style.overflow,G=document.body.style.overflow,V=document.body.style.position,Ie=document.body.style.top,Oe=document.body.style.left,De=document.body.style.right,Le=document.body.style.width;m.style.overflow="hidden",document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.top=`${-I}px`,document.body.style.left=`${-v}px`,document.body.style.right="0",document.body.style.width="100%",E=()=>{m.style.overflow=W,document.body.style.overflow=G,document.body.style.position=V,document.body.style.top=Ie,document.body.style.left=Oe,document.body.style.right=De,document.body.style.width=Le,window.scrollTo(v,I)}}let ee=a.querySelector("button,textarea,input,[tabindex]:not([tabindex='-1'])");a.contains(document.activeElement)||ee?.focus();let B=m=>{if(!r&&m.key==="Escape"){if(fe(a)){u.current=Date.now(),m.preventDefault(),m.stopPropagation();return}m.preventDefault(),H();return}if(!r||m.key!=="Tab")return;let v=Array.from(a.querySelectorAll("button:not(:disabled),textarea:not(:disabled),input:not(:disabled),[tabindex]:not([tabindex='-1'])"));if(v.length===0)return;let I=v[0],W=v[v.length-1],G=a.getRootNode(),V=G instanceof ShadowRoot?G.activeElement:document.activeElement;m.shiftKey&&V===I?(m.preventDefault(),W.focus()):!m.shiftKey&&V===W&&(m.preventDefault(),I.focus())};return a.addEventListener("keydown",B),()=>{a.removeEventListener("keydown",B),typeof a.close=="function"?a.close():a.open=!1,E?.(),document.activeElement===document.body&&A?.focus()}},[r,f,F]),K(()=>{if(!f||!_||r)return;let a=y.current;if(!a)return;let A=E=>{E.composedPath().includes(a)||H()};return document.addEventListener("click",A,!0),()=>document.removeEventListener("click",A,!0)},[r,_,f]),!f&&!c?null:O("dialog",{ref:y,"aria-label":p,"aria-modal":r,className:"ha-panel","data-agent-overlay-root":"","data-expanded":!k&&h?"true":void 0,"data-expanded-sidebar":U?"true":void 0,"data-resizing":g?"true":void 0,hidden:!f,onCancel:a=>{if(a.preventDefault(),Date.now()-u.current<350||fe(y.current)){u.current=Date.now();return}M()},children:[x&&!h?d(je,{agentId:t,panelRef:y}):null,U?d("aside",{"aria-label":"Chat history",className:"ha-expanded-sidebar",children:b}):null,O("div",{className:"ha-panel-main",children:[O("header",{className:"ha-header",children:[U?d("span",{className:"ha-session-title ha-expanded-chat-title",children:T??p}):i??d("strong",{children:p}),O("div",{className:"ha-header-actions",children:[U?null:e??(R?d("button",{"aria-label":"New chat",className:"ha-icon-button ha-new-chat-button",type:"button",onClick:R,children:d(Ye,{})}):null),_e?d("button",{"aria-expanded":h,"aria-label":h?"Collapse assistant":"Expand assistant",className:"ha-expand-button ha-icon-button",type:"button",onClick:()=>{C(!0),P(a=>!a)},children:h?d(ze,{"aria-hidden":"true"}):d(Ke,{"aria-hidden":"true"})}):null,O("button",{"aria-keyshortcuts":"Escape","aria-label":"Close assistant",className:"ha-close-button ha-icon-button","data-shortcut":"ESC","data-tooltip":"Close assistant",type:"button",onClick:M,children:[d(qe,{}),d(z,{shortcut:"ESC",children:"Close assistant"})]})]})]}),n,d("div",{className:"ha-overlay-portal","data-agent-overlay-portal":""})]})]})}function fe(e){let t=e?.querySelector(['[data-slot$="-popover"]','[data-slot="agent-ui-image-modal"]','[data-slot="modal-dialog"]',".ha-feedback-popover"].join(","));return t?(t.querySelector('button[aria-label="Dismiss"]')?.click(),!0):!1}function je({agentId:e,panelRef:t}){let[n,o]=$(420),s=oe(null),b=he(i=>{let c=t.current,p=c?.getRootNode();(p instanceof ShadowRoot?p.host:c?.closest("[data-heroui-agent]"))?.style.setProperty("--ha-sidebar-width",`${i}px`),window.innerWidth>=640&&(document.documentElement.style.marginRight=`${Math.min(i,window.innerWidth)}px`),o(i)},[t]);K(()=>{o(ge(e,window.innerWidth))},[e]);let T=he((i,c)=>{let p=te(i,window.innerWidth);return b(p),c&&ne(e,p),p},[b,e]);return d("div",{"aria-label":"Resize assistant panel","aria-orientation":"vertical","aria-valuemax":720,"aria-valuemin":320,"aria-valuenow":n,className:"ha-resize-handle",role:"separator",tabIndex:0,onKeyDown:i=>{let c=i.key==="ArrowLeft"?24:i.key==="ArrowRight"?-24:0;c!==0&&(i.preventDefault(),T(n+c,!0))},onPointerCancel:i=>{let c=s.current;c&&(s.current=null,delete i.currentTarget.dataset.resizing,t.current&&delete t.current.dataset.dragResizing,document.documentElement.style.transition=c.pageTransition,T(c.startWidth,!1))},onPointerDown:i=>{i.button!==0&&i.pointerType==="mouse"||(i.preventDefault(),i.currentTarget.setPointerCapture(i.pointerId),i.currentTarget.dataset.resizing="true",s.current={currentWidth:n,pageTransition:document.documentElement.style.transition,startWidth:n,startX:i.clientX},document.documentElement.style.transition="none",t.current&&(t.current.dataset.dragResizing="true"))},onPointerMove:i=>{let c=s.current;c&&(c.currentWidth=T(c.startWidth+(c.startX-i.clientX),!1))},onPointerUp:i=>{let c=s.current;c&&(s.current=null,delete i.currentTarget.dataset.resizing,t.current&&delete t.current.dataset.dragResizing,i.currentTarget.releasePointerCapture(i.pointerId),document.documentElement.style.transition=c.pageTransition,ne(e,c.currentWidth))}})}function qe(){return d("svg",{"aria-hidden":"true",fill:"none",height:"18",viewBox:"0 0 18 18",width:"18",children:d("path",{d:"m4.25 4.25 9.5 9.5m0-9.5-9.5 9.5",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.6"})})}function Ye(){return d("svg",{"aria-hidden":"true",fill:"none",height:"18",viewBox:"0 0 18 18",width:"18",children:d("path",{d:"M9 4v10M4 9h10",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.6"})})}function Ae(e,{generateConversationTitle:t=!0}={}){let n=performance.now(),o=Date.now(),s=e.trim();return s?{...t?{}:{generateConversationTitle:!1},messageId:crypto.randomUUID(),prompt:s,startedAt:n,startedAtWallClock:o,submitted:!0}:null}var N=new Map,X=new Map,Ze=10080*60*1e3,j=new Map;function be(e){return`heroui-agent:shell-draft:${e}:composer-draft:v1`}function re(e,t){try{let n=be(e);t.trim()?localStorage.setItem(n,JSON.stringify({prompt:t,savedAt:Date.now()})):localStorage.removeItem(n)}catch{}}function Je(e){let t=be(e);try{let n=JSON.parse(localStorage.getItem(t)??"null");if(n&&typeof n.prompt=="string"&&n.prompt.trim()&&typeof n.savedAt=="number"&&Date.now()-n.savedAt<=Ze)return n.prompt;localStorage.removeItem(t)}catch{}return""}function q(e,t){if(!t.prompt.trim()&&!t.submitted){N.delete(e),re(e,"");return}N.set(e,t),t.submitted||re(e,t.prompt)}function ae(e){let t=N.get(e);if(t)return t;let n=Je(e);return n?{prompt:n,submitted:!1}:void 0}function ye(e,t,n){let o=N.get(e);!o?.submitted||o.messageId!==t||o.firstFeedbackPaintedAt!==void 0||N.set(e,{...o,firstFeedbackPaintedAt:n})}function Rt(e){let t=ae(e);return N.delete(e),re(e,""),t}function D(e,t,n){t?j.set(e,[n?.selectionStart??0,n?.selectionEnd??0,n?.selectionDirection??"none"]):j.delete(e)}function ve(e,t){let n=j.get(e);if(!n||!t)return;t.focus({preventScroll:!0});let o=Math.min(n[0],t.value.length),s=Math.min(n[1],t.value.length);t.setSelectionRange(o,s,n[2]),j.set(e,[o,s,n[2]])}function Te(e,t){return t instanceof Node?e.contains(t)||e.closest(".ha-composer-wrap")?.querySelector(".ha-footnote")?.contains(t)===!0||e.closest(".ha-root")?.querySelector(".ha-overlay-portal")?.contains(t)===!0:!1}function Ht(e,t){t.length===0?X.delete(e):X.set(e,t)}function Qe(e){return X.get(e)??[]}function Pt(e){let t=Qe(e);return X.delete(e),t}function we(e){let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function et(e){let t=getComputedStyle(e),n=Number.parseFloat(t.lineHeight);if(Number.isFinite(n)&&n>0)return n;let o=Number.parseFloat(t.fontSize);return Number.isFinite(o)&&o>0?o*1.2:20}function tt(e){let t=getComputedStyle(e);return we(t.paddingTop)+we(t.paddingBottom)}function nt(e){let t=e.style.height,n=e.style.minHeight,o=e.style.maxHeight;e.style.height="0px",e.style.minHeight="0px",e.style.maxHeight="none";let s=e.scrollHeight;return e.style.height=t,e.style.minHeight=n,e.style.maxHeight=o,s}function ot(e){if(e.value.includes(`
|
|
2
|
-
`))return!0;if(e.clientWidth===0)return!1;let t=nt(e),n=tt(e),o=et(e);return Math.max(0,t-n)>o*1.5}function ie(e,{hasAttachments:t=!1,maxHeight:n=120}={}){if(!e)return!1;let o=e.value.length>0;return t||o&&ot(e)?(e.style.height="auto",e.style.height=`${Math.min(e.scrollHeight,n)}px`,!0):(e.style.height="auto",!1)}import{jsx as se,jsxs as xe}from"react/jsx-runtime";var rt="https://heroui.pro/?utm_source=heroui-agent&utm_medium=referral&utm_campaign=powered-by-hero";function Ee(){return xe("a",{"aria-label":"Powered by HeroUI Pro (opens in a new tab)",className:"ha-powered-by",href:rt,rel:"noopener noreferrer",target:"_blank",children:[se("span",{children:"Powered by"}),xe("svg",{"aria-hidden":"true",className:"ha-powered-by-logo",fill:"none",viewBox:"0 0 140 44",children:[se("path",{d:"M.678 11.385V24.04c0 .599.307 1.155.813 1.471l8.628 5.396c1.15.719 2.639-.11 2.639-1.47V18.798c0-.612.322-1.18.847-1.491l5.263-3.13v27.267c0 1.355 1.48 2.186 2.63 1.476l8.905-5.497a1.72 1.72 0 0 0 .822-1.476V9.765c0-1.349-1.467-2.18-2.618-1.484l-9.74 5.897V2.556c0-1.345-1.46-2.177-2.61-1.488L1.52 9.897a1.72 1.72 0 0 0-.842 1.488Z",fill:"currentColor"}),se("path",{d:"M63.876 24.071c0-3.59-1.468-5.246-4.405-5.246-3.363 0-5.732 2.255-5.732 7.316v11.595h-6.063V5.528h6.063v11.779c1.468-2.393 3.884-3.59 7.2-3.59 5.637 0 8.953 3.451 8.953 9.25v14.769h-6.016V24.071ZM84.9 38.473c-7.533 0-12.317-4.877-12.317-12.378 0-7.408 4.737-12.378 12.317-12.378 8.195 0 12.648 5.798 11.416 13.942H78.647c.331 3.865 2.605 6.075 6.253 6.075 2.984 0 4.784-1.52 5.258-3.037h6.016c-.947 4.509-5.115 7.776-11.274 7.776ZM78.789 23.657h11.653c-.047-3.175-2.132-5.338-5.685-5.338-3.174 0-5.4 1.84-5.968 5.338ZM99.623 20.344c0-3.82 2.131-5.89 6.205-5.89h7.77v4.97h-7.912v18.312h-6.063V20.344ZM126.863 38.473c-7.674 0-12.553-4.924-12.553-12.378 0-7.454 4.879-12.378 12.553-12.378 7.58 0 12.459 4.924 12.459 12.378 0 7.454-4.88 12.378-12.46 12.378Zm0-5.016c3.79 0 6.3-2.898 6.3-7.362 0-4.463-2.51-7.408-6.3-7.408-3.838 0-6.348 2.945-6.348 7.408 0 4.464 2.51 7.362 6.348 7.362Z",fill:"currentColor"})]})]})}var Se=new Set(["ask","auto","full"]);function Y(e){return Se.has(e)?e:"auto"}function Lt(e,t){return`${e}:permission-mode:${t}:v1`}function Ft(e,t){return`${e}:active-permission-mode:${t}:v1`}function Ut(e){try{let t=localStorage.getItem(e);return t!==null&&Se.has(t)?Y(t):void 0}catch{return}}function Bt(e,t){try{localStorage.setItem(e,t)}catch{}}function Wt(e){try{localStorage.removeItem(e)}catch{}}function Gt(e,t){let n=Y(t);if(n==="auto")return e;let o=n==="ask";return e.map(s=>!!s.needsApproval===o?s:{...s,needsApproval:o})}function Me(e){return`heroui-agent:anonymous:${e}`}var ke=class{constructor(t,n){this.agentId=t;this.getAuthToken=n}cached=null;generation=0;pending=null;clear(){this.generation+=1,this.cached=null,this.pending=null}reset(){this.clear();try{localStorage.removeItem(Me(this.agentId))}catch{}}async get(){if(this.cached&&this.expiresAt(this.cached)>Date.now()+6e4)return this.cached.token;let t=this.generation,n=this.pending??this.refresh();this.pending||(this.pending=n);try{let o=await n;return t!==this.generation?this.get():(this.cached=o,o.token)}finally{this.pending===n&&(this.pending=null)}}async subjectHash(){let t=await this.get(),n=at(t),o=typeof n.sub=="string"?n.sub:"anonymous",s=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(`${this.agentId}:${o}`));return Array.from(new Uint8Array(s),b=>b.toString(16).padStart(2,"0")).join("").slice(0,24)}anonymousId(){let t=Me(this.agentId);try{let n=localStorage.getItem(t);if(n)return n;let o=crypto.randomUUID();return localStorage.setItem(t,o),o}catch{return crypto.randomUUID()}}expiresAt(t){return t.expiresAt}async refresh(){let t=await this.getAuthToken({agentId:this.agentId,anonymousId:this.anonymousId()});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 at(e){try{let t=e.split(".")[1];if(!t)return{};let n=t.replace(/-/g,"+").replace(/_/g,"/"),o=n.padEnd(Math.ceil(n.length/4)*4,"=");return JSON.parse(atob(o))}catch{return{}}}var it={"application/json":"json","application/pdf":"pdf","image/gif":"gif","image/jpeg":"jpg","image/png":"png","image/webp":"webp","text/csv":"csv","text/markdown":"md","text/plain":"txt","text/tab-separated-values":"tsv"},Z=Object.freeze(Object.keys(it)),Kt=Z.join(","),st=new Set(Z);function Ce(e){return st.has(e.trim().toLowerCase())}import{useEffect as lt,useLayoutEffect as Ne,useRef as ct,useState as J}from"react";import{Fragment as Re,jsx as l,jsxs as S}from"react/jsx-runtime";function Jt({agentId:e,composerConnecting:t=!1,composerControlsAvailable:n,composerControlsRevealed:o,composerEndSlot:s,composerFooterSlot:b,composerStartSlot:T,greeting:i,onComposerControlsReveal:c,onIntent:p,placeholder:M,suggestedPrompts:R}){let[f]=J(()=>ae(e)),[w,y]=J(()=>f?.submitted?"":f?.prompt??""),[u,L]=J(()=>f?.submitted?f:null),[Q,H]=J(!1),h=ct(null),P=n??!!(T||s),F=o??(P&&Q),k=r=>{D(e,!0,r.currentTarget),H(P),P&&c?.(),p()},_=r=>{let g=r.currentTarget.querySelector(".ha-composer");g&&Te(g,r.relatedTarget)||(H(!1),D(e,!1))};Ne(()=>{ve(e,h.current),ie(h.current)},[e]),lt(()=>{u||q(e,{prompt:w,submitted:!1})},[w,e,u]),Ne(()=>{if(!u)return;let r=requestAnimationFrame(g=>{ye(e,u.messageId,g)});return()=>cancelAnimationFrame(r)},[e,u]);let x=(r,g=!0)=>{if(u)return;let C=Ae(r,{generateConversationTitle:g});C&&(L(C),y(""),h.current.style.height="auto",q(e,C),p())};return S(Re,{children:[l("div",{className:"ha-conversation",children:l("div",{"aria-live":"polite",className:"ha-messages",role:"log",children:u?S(Re,{children:[l("div",{className:"ha-message","data-role":"user",children:l("div",{className:"ha-bubble",children:l("div",{className:"ha-message-content",children:l("p",{className:"ha-message-text",children:u.prompt})})})}),l("div",{className:"ha-message","data-role":"assistant","data-stream-anchor":"true","data-turn-feedback-id":u.messageId,children:l("div",{className:"ha-message-body",children:l("div",{"aria-label":"Working on your request\u2026",className:"ha-progress ha-activity-status ha-progress-shimmer",role:"status",children:l("span",{"aria-hidden":"true",className:"ha-shimmer",children:"Thinking\u2026"})})})})]}):S("div",{className:"ha-empty",children:[l("h2",{children:i}),l("p",{children:"Live answers with charts, metrics, and tables."})]})})}),S("form",{className:"ha-composer-wrap",onBlur:_,onSubmit:r=>{r.preventDefault(),x(w)},children:[!u&&R.length>0?l("div",{"aria-label":"Suggested prompts",className:"ha-suggestions",role:"group",children:R.map(r=>S("button",{className:"ha-suggestion",type:"button",onClick:()=>x(r,!1),children:[l("span",{children:r}),l(ut,{})]},r))}):null,S("div",{className:"@container ha-composer","data-connecting":t||void 0,"data-controls-revealed":F||void 0,children:[T,l("textarea",{ref:h,"aria-label":"Message the assistant",placeholder:M,readOnly:!!u,rows:1,value:w,onFocus:k,onSelect:r=>D(e,!0,r.currentTarget),onChange:r=>{let g=r.currentTarget.value;q(e,{prompt:g,submitted:!1}),D(e,!0,r.currentTarget),y(g),ie(r.currentTarget),p()},onKeyDown:r=>{r.key!=="Enter"||r.shiftKey||(r.preventDefault(),x(w))}}),s,S("button",{"aria-label":"Send message",className:"ha-send",disabled:!w.trim()||!!u,type:"submit",children:[l(dt,{}),l(z,{shortcut:"\u21B5",children:"Send message"})]})]}),l("div",{className:"ha-composer-footer","data-revealed":!!b||void 0,children:l("div",{className:"ha-composer-footer-content",children:b})}),l(Ee,{})]})]})}function dt(){return l("svg",{"aria-hidden":"true",fill:"none",height:"18",viewBox:"0 0 18 18",width:"18",children:l("path",{d:"M9 14.5V3.5m0 0L4.5 8M9 3.5 13.5 8",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"})})}function ut(){return l("svg",{"aria-hidden":"true",fill:"none",height:"16",viewBox:"0 0 16 16",width:"16",children:l("path",{d:"M5 11 11 5m0 0H6m5 0v5",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.5"})})}var mt={animation:"fadeIn",duration:160,easing:"ease-out",sep:"word",stagger:18};function He(e){return typeof e=="number"?Number.isFinite(e)?`${Math.round(e)}px`:void 0:e?.trim()||void 0}function pt(e){let t=He(e?.initialWidth),n=He(e?.initialHeight);return{...t?{"--ha-panel-width":t}:{},...n?{"--ha-panel-height":n}:{}}}function Pe(e){return e===void 0||!Number.isFinite(e)?24:Math.min(Math.max(Math.round(e),0),200)}function gt(e){if(e===void 0)return[...Z];if(e===!1||!Array.isArray(e))return[];let t=new Set;for(let n of e){if(typeof n!="string")continue;let o=n.trim().toLowerCase();Ce(o)&&t.add(o)}return[...t]}function an(e){if(typeof e.agentId!="string"||!e.agentId.trim())throw new Error("HeroUI Agent agentId is required");if(typeof e.getAuthToken!="function")throw new Error("HeroUI Agent getAuthToken is required");let t=gt(e.composer?.attachments),n=typeof e.composer?.disclaimer=="string"&&e.composer.disclaimer.trim().slice(0,240)||void 0;return{apiBaseUrl:(e._api?.baseUrl??ue).replace(/\/$/,""),colorScheme:e.appearance?.theme?.colorScheme??"system",componentExportFormats:e.componentExports===!1?[]:e.componentExports??["csv","svg","png"],composerAttachmentAccept:t.join(","),composerAttachmentContentTypes:t,composerControlsAvailable:t.length>0||e.permissions?.showPicker===!0&&!!e.tools?.length||e.composer?.modelPicker===!0||(e.composer?.dictation??!0),composerDefaultModel:e.composer?.defaultModel,composerDictation:e.composer?.dictation??!0,designTheme:le(e.appearance?.theme?.designTheme),...n?{composerDisclaimer:n}:{},agentId:e.agentId,composerModelPicker:e.composer?.modelPicker??!1,composerPlaceholder:e.composer?.placeholder?.trim().slice(0,120)||"Ask anything\u2026",context:e.context,getAuthToken:e.getAuthToken,greeting:e.startScreen?.greeting?.trim().slice(0,120)||"Ask about your data",launcherPosition:e.appearance?.launcher?.position??"bottom-right",markdownAnimation:e.markdown?.animated??mt,markdownCaret:e.markdown?.caret??"block",markdownPlugins:e.markdown?.plugins,messageActions:e.responseActions===!1?[]:e.responseActions??["copy","feedback","retry"],onFeedback:e.onFeedback,panelExpandable:e.appearance?.panel?.expandable??!0,panelExpanded:e.appearance?.panel?.expanded??!1,panelStyle:pt(e.appearance?.panel),permissionDefaultMode:Y(e.permissions?.defaultMode),permissionShowPicker:e.permissions?.showPicker===!0,preload:e.preload??!0,reopenOnRefresh:e.reopenOnRefresh??!1,showLauncher:e.showLauncher??!0,startNewConversationOnOpen:e.startNewConversationOnOpen??!1,suggestedPromptShortcuts:e.startScreen?.promptShortcuts??!1,...e.appearance?.launcher?.icon?.trim()?{launcherIcon:e.appearance.launcher.icon.trim()}:{},...e.appearance?.launcher?.style?{launcherStyle:e.appearance.launcher.style}:{},...e.appearance?.launcher?.offset?{launcherOffset:{x:Pe(e.appearance.launcher.offset.x),y:Pe(e.appearance.launcher.offset.y)}}:{},imageSearch:(e.capabilities?.webSearch??!1)&&(e.capabilities?.imageSearch??!0),newsSearch:(e.capabilities?.webSearch??!1)&&(e.capabilities?.newsSearch??!1),suggestedPrompts:e.startScreen?.prompts?.map(o=>o.trim()).filter(Boolean).slice(0,5),themeStyle:{...de(e.appearance?.theme),...ce(e.appearance?.launcher?.background)},tools:e.tools??[],viewMode:e.appearance?.viewMode??"floating",webSearch:e.capabilities?.webSearch??!1}}export{ke as a,ht as b,ue as c,At as d,z as e,ge as f,kt as g,it as h,Z as i,Ce as j,Ae as k,q as l,ae as m,Rt as n,D as o,ve as p,Te as q,Ht as r,Qe as s,Pt as t,ie as u,Ee as v,Jt as w,Lt as x,Ft as y,Ut as z,Bt as A,Wt as B,Gt as C,mt as D,an as E};
|