@_daniel_jiang/ai-host 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ai-host.js CHANGED
@@ -1,4 +1,4 @@
1
- var St=Object.defineProperty,$t=Object.defineProperties;var zt=Object.getOwnPropertyDescriptors;var tt=Object.getOwnPropertySymbols;var Wt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable;var _=(p,l,d)=>l in p?St(p,l,{enumerable:!0,configurable:!0,writable:!0,value:d}):p[l]=d,S=(p,l)=>{for(var d in l||(l={}))Wt.call(l,d)&&_(p,d,l[d]);if(tt)for(var d of tt(l))Bt.call(l,d)&&_(p,d,l[d]);return p},et=(p,l)=>$t(p,zt(l));var c=(p,l,d)=>_(p,typeof l!="symbol"?l+"":l,d);var b=(p,l,d)=>new Promise((k,v)=>{var y=h=>{try{C(d.next(h))}catch(H){v(H)}},L=h=>{try{C(d.throw(h))}catch(H){v(H)}},C=h=>h.done?k(h.value):Promise.resolve(h.value).then(y,L);C((d=d.apply(p,l)).next())});(function(p){"use strict";const l="agent-host";function d(e){return typeof e=="object"&&e!==null&&e.channel===l&&typeof e.type=="string"}function k(e){return e==null?e:JSON.parse(JSON.stringify(e))}function v(e){return typeof e=="function"?e():e}const y={},L={};let C={},h=null,H=!1,x=null,$=null,q=!1;function N(e){$=e}function I(){try{$==null||$()}catch(e){}}function W(e){var o;if(!e)return null;const t=typeof e=="function"?e():e;if(!t)return null;let n=null;if(t instanceof Element?n=t:typeof t=="object"&&t.$el instanceof Element&&(n=t.$el),!n)return null;const i=(o=n.querySelector)==null?void 0:o.call(n,'textarea, input, [contenteditable="true"]');return i instanceof HTMLElement?i:n}function B(e){return!e||typeof e.closest!="function"?!1:!!e.closest("#agent-host-launcher-hint")}function D(e){return!!e.anchor&&e.hintPlacement==="anchor"}function nt(e,t){if(!h){x&&(x=null,I());return}if(B(e)||B(t))return;const n=y[h]||[];let i=null;if(e instanceof Node)for(const o of n){if(!D(o))continue;const s=W(o.anchor);if(s&&s.contains(e)){i=o.id;break}}i!==x&&(x=i,I())}function it(e){nt(e.target)}function ot(e){if(B(e.relatedTarget))return;const t=e.target;if(!(t instanceof Node)||!h)return;const i=(y[h]||[]).find(s=>s.id===x);if(!i)return;const o=W(i.anchor);o&&o.contains(t)&&!o.contains(e.relatedTarget)&&(x=null,I())}function st(){q||typeof document=="undefined"||(document.addEventListener("focusin",it,!0),document.addEventListener("focusout",ot,!0),q=!0)}function rt(e,t){const n=(t||"").trim();if(n)return n;for(const i of e){if(!i.hostContext)continue;const o=v(i.hostContext),s=o&&typeof o=="object"?String(o.refresh||"").trim():"";if(s)return s}}function G(e){return((e==null?void 0:e.kind)||"widget")==="direct"}function at(e,t,n={}){st();const i=e!==h;i&&(H=!1,x=null),y[e]=t,h=e,!i&&t.some(s=>!s.enabled||s.enabled())&&(H=!1);const o=rt(t,n.refreshKey);o&&typeof n.onRefresh=="function"?L[e]={refreshKey:o,onRefresh:n.onRefresh}:delete L[e],I()}function lt(e){delete y[e],delete L[e],h===e&&(h=null,x=null),I()}function ht(e){const t=k(e||{});for(const n of Object.keys(t)){const i=t[n];(i==null||typeof i=="string"&&!i.trim())&&delete t[n]}return t}function ct(e){return C=ht(e||{}),S({},C)}function F(){return S({},C)}function ut(e,t){const n=String(e||"").trim();if(n){for(const i of Object.values(L))if(i.refreshKey===n)try{i.onRefresh(t)}catch(o){}}}function dt(){for(const e of Object.keys(y))delete y[e];for(const e of Object.keys(L))delete L[e];C={},h=null,H=!1,x=null,I()}function ft(e){e!==h&&(H=!1,x=null),h=e,I()}function pt(){H=!0}function K(e){return e.map(t=>({id:t.id,workflow:t.workflow||t.skill||"",label:t.label,host:t.host,hint:t.hint?v(t.hint):void 0,hostContext:t.hostContext?k(v(t.hostContext)):void 0,prefilled:t.prefilled?k(v(t.prefilled)):void 0,enabled:t.enabled?t.enabled():!0,kind:t.kind,skill:t.skill,noTools:t.noTools===!0?!0:void 0}))}function V(e,t){const n=(y[e]||[]).find(o=>o.id===t);if(!n||n.enabled&&!n.enabled())return null;const i=n.prefilled?k(v(n.prefilled)):void 0;return{action:n,prefilled:i,hostContext:n.hostContext?k(v(n.hostContext)):void 0}}function gt(e,t){const n=V(e,t);return!n||G(n.action)?null:{workflow:n.action.workflow||n.action.skill||"",title:n.action.label,host:n.action.host,prefilled:n.prefilled,hostContext:n.hostContext}}function bt(){return h}function wt(){return Object.entries(y).map(([e,t])=>({pageId:e,actions:t}))}function Y(e,t){const n=(y[e]||[]).find(i=>i.id===t);return n?W(n.anchor):null}function yt(e,t){const n=Y(e,t);if(!n)return null;const i=n.getBoundingClientRect();return!i.width&&!i.height?null:i}function xt(){if(H||!h)return null;const e=y[h]||[];for(const t of e){if(t.enabled&&!t.enabled()||D(t)&&x!==t.id)continue;const n=t.hint?v(t.hint):`可使用「${t.label}」`,i=D(t)?"anchor":"launcher";return{pageId:h,actionId:t.id,hint:n,placement:i}}return null}const f="agent-host-launcher",m="agent-host-hub-panel-overlay",mt="agent-host-hub-iframe",J="agent-host-widget-overlay",vt="agent-host-widget-iframe",X="agent-host-ai-host-styles";function Ht(e){return e.replace(/\/$/,"")}function z(e){try{return new URL(e).origin}catch(t){return e.replace(/\/$/,"")}}function kt(e,t){const n=z(e),i=z(t);if(n===i)return!0;try{const o=new URL(n),s=new URL(i),u=new Set(["localhost","127.0.0.1","[::1]"]);return o.protocol===s.protocol&&o.port===s.port&&u.has(o.hostname)&&u.has(s.hostname)}catch(o){return!1}}function Lt(){if(typeof document=="undefined"||document.getElementById(X))return;const e=document.createElement("style");e.id=X,e.textContent=`
1
+ var Mt=Object.defineProperty,$t=Object.defineProperties;var zt=Object.getOwnPropertyDescriptors;var tt=Object.getOwnPropertySymbols;var Wt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable;var q=(p,l,d)=>l in p?Mt(p,l,{enumerable:!0,configurable:!0,writable:!0,value:d}):p[l]=d,M=(p,l)=>{for(var d in l||(l={}))Wt.call(l,d)&&q(p,d,l[d]);if(tt)for(var d of tt(l))Bt.call(l,d)&&q(p,d,l[d]);return p},et=(p,l)=>$t(p,zt(l));var c=(p,l,d)=>q(p,typeof l!="symbol"?l+"":l,d);var b=(p,l,d)=>new Promise((k,v)=>{var y=h=>{try{C(d.next(h))}catch(H){v(H)}},L=h=>{try{C(d.throw(h))}catch(H){v(H)}},C=h=>h.done?k(h.value):Promise.resolve(h.value).then(y,L);C((d=d.apply(p,l)).next())});(function(p){"use strict";const l="agent-host";function d(e){return typeof e=="object"&&e!==null&&e.channel===l&&typeof e.type=="string"}function k(e){return e==null?e:JSON.parse(JSON.stringify(e))}function v(e){return typeof e=="function"?e():e}const y={},L={};let C={},h=null,H=!1,x=null,$=null,V=!1;function N(e){$=e}function A(){try{$==null||$()}catch(e){}}function W(e){var o;if(!e)return null;const t=typeof e=="function"?e():e;if(!t)return null;let n=null;if(t instanceof Element?n=t:typeof t=="object"&&t.$el instanceof Element&&(n=t.$el),!n)return null;const i=(o=n.querySelector)==null?void 0:o.call(n,'textarea, input, [contenteditable="true"]');return i instanceof HTMLElement?i:n}function B(e){return!e||typeof e.closest!="function"?!1:!!e.closest("#agent-host-launcher-hint")}function D(e){return!!e.anchor&&e.hintPlacement==="anchor"}function nt(e,t){if(!h){x&&(x=null,A());return}if(B(e)||B(t))return;const n=y[h]||[];let i=null;if(e instanceof Node)for(const o of n){if(!D(o))continue;const s=W(o.anchor);if(s&&s.contains(e)){i=o.id;break}}i!==x&&(x=i,A())}function it(e){nt(e.target)}function ot(e){if(B(e.relatedTarget))return;const t=e.target;if(!(t instanceof Node)||!h)return;const i=(y[h]||[]).find(s=>s.id===x);if(!i)return;const o=W(i.anchor);o&&o.contains(t)&&!o.contains(e.relatedTarget)&&(x=null,A())}function st(){V||typeof document=="undefined"||(document.addEventListener("focusin",it,!0),document.addEventListener("focusout",ot,!0),V=!0)}function rt(e,t){const n=(t||"").trim();if(n)return n;for(const i of e){if(!i.hostContext)continue;const o=v(i.hostContext),s=o&&typeof o=="object"?String(o.refresh||"").trim():"";if(s)return s}}function G(e){return((e==null?void 0:e.kind)||"widget")==="direct"}function at(e,t,n={}){st();const i=e!==h;i&&(H=!1,x=null),y[e]=t,h=e,!i&&t.some(s=>!s.enabled||s.enabled())&&(H=!1);const o=rt(t,n.refreshKey);o&&typeof n.onRefresh=="function"?L[e]={refreshKey:o,onRefresh:n.onRefresh}:delete L[e],A()}function lt(e){delete y[e],delete L[e],h===e&&(h=null,x=null),A()}function ht(e){const t=k(e||{});for(const n of Object.keys(t)){const i=t[n];(i==null||typeof i=="string"&&!i.trim())&&delete t[n]}return t}function ct(e){return C=ht(e||{}),M({},C)}function F(){return M({},C)}function ut(e,t){const n=String(e||"").trim();if(n){for(const i of Object.values(L))if(i.refreshKey===n)try{i.onRefresh(t)}catch(o){}}}function dt(){for(const e of Object.keys(y))delete y[e];for(const e of Object.keys(L))delete L[e];C={},h=null,H=!1,x=null,A()}function ft(e){e!==h&&(H=!1,x=null),h=e,A()}function pt(){H=!0}function K(e){return e.map(t=>({id:t.id,workflow:t.workflow||t.skill||"",label:t.label,host:t.host,hint:t.hint?v(t.hint):void 0,hostContext:t.hostContext?k(v(t.hostContext)):void 0,prefilled:t.prefilled?k(v(t.prefilled)):void 0,enabled:t.enabled?t.enabled():!0,kind:t.kind,skill:t.skill,noTools:t.noTools===!0?!0:void 0}))}function j(e,t){const n=(y[e]||[]).find(o=>o.id===t);if(!n||n.enabled&&!n.enabled())return null;const i=n.prefilled?k(v(n.prefilled)):void 0;return{action:n,prefilled:i,hostContext:n.hostContext?k(v(n.hostContext)):void 0}}function gt(e,t){const n=j(e,t);return!n||G(n.action)?null:{workflow:n.action.workflow||n.action.skill||"",title:n.action.label,host:n.action.host,prefilled:n.prefilled,hostContext:n.hostContext}}function bt(){return h}function wt(){return Object.entries(y).map(([e,t])=>({pageId:e,actions:t}))}function Y(e,t){const n=(y[e]||[]).find(i=>i.id===t);return n?W(n.anchor):null}function yt(e,t){const n=Y(e,t);if(!n)return null;const i=n.getBoundingClientRect();return!i.width&&!i.height?null:i}function xt(){if(H||!h)return null;const e=y[h]||[];for(const t of e){if(t.enabled&&!t.enabled()||D(t)&&x!==t.id)continue;const n=t.hint?v(t.hint):`可使用「${t.label}」`,i=D(t)?"anchor":"launcher";return{pageId:h,actionId:t.id,hint:n,placement:i}}return null}const f="agent-host-launcher",m="agent-host-hub-panel-overlay",mt="agent-host-hub-iframe",J="agent-host-widget-overlay",vt="agent-host-widget-iframe",X="agent-host-ai-host-styles";function Ht(e){return e.replace(/\/$/,"")}function z(e){try{return new URL(e).origin}catch(t){return e.replace(/\/$/,"")}}function kt(e,t){const n=z(e),i=z(t);if(n===i)return!0;try{const o=new URL(n),s=new URL(i),u=new Set(["localhost","127.0.0.1","[::1]"]);return o.protocol===s.protocol&&o.port===s.port&&u.has(o.hostname)&&u.has(s.hostname)}catch(o){return!1}}function Lt(){if(typeof document=="undefined"||document.getElementById(X))return;const e=document.createElement("style");e.id=X,e.textContent=`
2
2
  #${f} {
3
3
  position: fixed;
4
4
  right: 24px;
@@ -295,4 +295,4 @@ var St=Object.defineProperty,$t=Object.defineProperties;var zt=Object.getOwnProp
295
295
  <button type="button" class="agent-host-hint-use">立即开始</button>
296
296
  <button type="button" class="agent-host-hint-dismiss">稍后</button>
297
297
  </div>
298
- </div>`;const i=n.querySelector(".agent-host-hint-text");i&&(i.textContent=t.hint);const o=n.querySelector(".agent-host-hint-use"),s=n.querySelector(".agent-host-hint-dismiss"),u=g=>g.preventDefault();o==null||o.addEventListener("mousedown",u),s==null||s.addEventListener("mousedown",u),o==null||o.addEventListener("click",g=>{var w;g.stopPropagation(),(w=this.onHintUse)==null||w.call(this,t.pageId,t.actionId)}),s==null||s.addEventListener("click",g=>{var w;g.stopPropagation(),(w=this.onHintDismiss)==null||w.call(this)}),n.classList.add("is-visible"),this.layoutHint(n,t),this.bindHintReposition()}layoutHint(t,n){if(n.placement!=="anchor"){t.classList.remove("is-anchored"),t.style.top="",t.style.left="";return}const i=yt(n.pageId,n.actionId);if(!i){t.classList.remove("is-anchored"),t.style.top="",t.style.left="";return}t.classList.add("is-anchored");const o=8,s=t.offsetWidth||320,u=t.offsetHeight||48;let g=i.top,w=i.right+o;w+s>window.innerWidth-16&&(w=Math.max(16,i.left),g=i.bottom+o),g+u>window.innerHeight-16&&(g=Math.max(16,i.top-u-o)),g<16&&(g=16),w<16&&(w=16),t.style.top=`${Math.round(g)}px`,t.style.left=`${Math.round(w)}px`}collectScrollParents(t){var o;const n=[];let i=(o=t==null?void 0:t.parentElement)!=null?o:null;for(;i;){const s=window.getComputedStyle(i),u=s.overflowY,g=s.overflowX;/(auto|scroll|overlay)/.test(`${g} ${u}`)&&n.push(i),i=i.parentElement}return n}bindHintReposition(){var i,o;if(typeof window=="undefined")return;this.hintRepositionBound||(window.addEventListener("scroll",this.onHintReposition,!0),window.addEventListener("resize",this.onHintReposition),(i=window.visualViewport)==null||i.addEventListener("resize",this.onHintReposition),(o=window.visualViewport)==null||o.addEventListener("scroll",this.onHintReposition),this.hintRepositionBound=!0);const t=this.launcherHintAction;for(const s of this.hintScrollParents)s.removeEventListener("scroll",this.onHintReposition);if(this.hintScrollParents=[],!t||t.placement!=="anchor")return;const n=Y(t.pageId,t.actionId);this.hintScrollParents=this.collectScrollParents(n);for(const s of this.hintScrollParents)s.addEventListener("scroll",this.onHintReposition,{passive:!0})}unbindHintReposition(){var t,n;if(typeof window!="undefined"){this.hintRepositionBound&&(window.removeEventListener("scroll",this.onHintReposition,!0),window.removeEventListener("resize",this.onHintReposition),(t=window.visualViewport)==null||t.removeEventListener("resize",this.onHintReposition),(n=window.visualViewport)==null||n.removeEventListener("scroll",this.onHintReposition),this.hintRepositionBound=!1);for(const i of this.hintScrollParents)i.removeEventListener("scroll",this.onHintReposition);this.hintScrollParents=[]}}mountLauncher(){if(this.hubLauncher||document.getElementById(f))return;const t=document.createElement("button");if(t.id=f,t.type="button",t.title="景行 AI",t.setAttribute("aria-label","景行 AI"),t.innerHTML='<span class="agent-host-launcher-logo" aria-hidden="true"><svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" d="M603.904 244.992c134.4 0 243.3536 108.9536 243.3536 243.3536v202.8032c0 134.4-108.9536 243.3536-243.3536 243.3536H320c-134.4 0-243.3536-108.9536-243.3536-243.3536V488.3456c0-134.4 108.9536-243.3536 243.3536-243.3536h283.904z m0 81.1008H320c-89.6 0-162.2528 72.6528-162.2528 162.2528v202.8032c0 89.6 72.6528 162.2528 162.2528 162.2528h283.904c89.6 0 162.2528-72.6528 162.2528-162.2528V488.3456c0-89.6-72.6528-162.2528-162.2528-162.2528z"/><path fill="#fff" d="M340.224 508.6208c27.0336 0 40.5504 13.5168 40.5504 40.5504v81.1008c0 27.0336-13.5168 40.5504-40.5504 40.5504-27.0336 0-40.5504-13.5168-40.5504-40.5504v-81.1008c0-27.0336 13.5168-40.5504 40.5504-40.5504zM583.2192 501.3504c15.2576-11.4176 36.864-8.3456 48.2816 6.912a34.4832 34.4832 0 0 1-6.912 48.2816l-44.3904 33.28 44.3904 33.28a34.53952 34.53952 0 0 1 9.472 44.3392l-2.56 3.9424c-11.4176 15.2576-33.024 18.3296-48.2816 6.912l-59.4944-44.5952c-13.7728-10.3424-21.9136-26.5728-21.9136-43.8272s8.0896-33.4848 21.9136-43.8272l59.4944-44.5952zM883.5072 261.12l-19.7632 47.3088c-2.7648 6.656-9.2672 10.9568-16.4864 10.9568s-13.6704-4.3008-16.4864-10.9568L811.008 261.12a44.416 44.416 0 0 0-19.7632-21.9648l-34.8672-19.0976c-5.7344-3.1232-9.2672-9.1136-9.2672-15.6672s3.5328-12.544 9.2672-15.6672l34.8672-19.0464a44.89728 44.89728 0 0 0 19.7632-21.9648l19.7632-47.3088c2.7648-6.656 9.2672-10.9568 16.4864-10.9568s13.6704 4.3008 16.4864 10.9568l19.7632 47.3088a44.416 44.416 0 0 0 19.7632 21.9648l34.8672 19.0976c5.7344 3.1232 9.2672 9.1136 9.2672 15.6672s-3.584 12.544-9.2672 15.6672l-34.8672 19.0464c-8.9088 4.864-15.872 12.6464-19.7632 21.9648z"/></svg></span><span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span><span class="agent-host-launcher-bell" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 3a5 5 0 0 0-5 5v1.5c0 1.3-.4 2.6-1.2 3.7L4.5 15.5c-.4.5-.1 1.3.5 1.3h14c.6 0 .9-.8.5-1.3l-1.3-2.3A6.6 6.6 0 0 1 17 9.5V8a5 5 0 0 0-5-5Z" fill="#fff"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg></span><span class="agent-host-launcher-badge"></span>',t.addEventListener("click",()=>this.openHubPanel()),document.body.appendChild(t),this.hubLauncher=t,this.hubLauncherBadge=t.querySelector(".agent-host-launcher-badge"),document.getElementById("agent-host-launcher-hint"))this.hubLauncherHint=document.getElementById("agent-host-launcher-hint");else{const n=document.createElement("div");n.id="agent-host-launcher-hint",document.body.appendChild(n),this.hubLauncherHint=n}}mountHubPanel(){const t=document.createElement("div");t.id=m;const n=document.createElement("div");n.className="agent-host-hub-backdrop",n.addEventListener("click",()=>this.closeHubPanel());const i=document.createElement("div");i.className="agent-host-hub-panel-shell";const o=document.createElement("iframe");o.id=mt,o.title="景行 AI",o.src=`${this.agentOrigin}/host/hub?embed=1&panel=1&layout=studio`,o.allow="clipboard-read; clipboard-write",i.appendChild(o),t.appendChild(n),t.appendChild(i),document.body.appendChild(t),this.hubPanelOverlay=t,this.hubIframe=o}updateLauncherStats(t,n){this.lastRunning=t,this.lastWaiting=n,this.applyLauncherVisual()}applyLauncherVisual(){const t=this.hubLauncher,n=this.hubLauncherBadge;if(!t||!n)return;const i=t.querySelector(".agent-host-launcher-bell"),o=this.lastRunning,s=this.lastWaiting,u=s>0&&!this.hubPanelOpen;t.classList.toggle("is-pulse",o>0&&!u),t.classList.toggle("is-orbiting",o>0&&!u),t.classList.toggle("is-hitl",u),u?(t.title="有待确认事项,点击打开助手",t.setAttribute("aria-label","有待确认事项,点击打开助手")):(t.title="景行 AI",t.setAttribute("aria-label","景行 AI")),i&&i.classList.toggle("is-visible",u),o>0?(n.textContent=String(o),n.classList.add("is-visible"),n.classList.remove("is-waiting")):s>0?(n.textContent="!",n.classList.add("is-visible","is-waiting")):(n.textContent="",n.classList.remove("is-visible","is-waiting"))}removeHub(){var t,n,i;(t=document.getElementById(f))==null||t.remove(),(n=document.getElementById("agent-host-launcher-hint"))==null||n.remove(),(i=document.getElementById(m))==null||i.remove(),this.hubLauncher=null,this.hubLauncherBadge=null,this.hubLauncherHint=null,this.hubPanelOverlay=null,this.hubIframe=null,this.hubReady=!1,this.hubPanelOpen=!1,this.pendingHubMessages=[]}openWidget(t,n,i){this.closeWidget();const o=document.createElement("div");o.id=J,o.style.cssText="position:fixed;inset:0;z-index:2147483646;background:rgba(15,23,42,0.45);display:flex;align-items:center;justify-content:center;padding:16px;",o.addEventListener("click",Tt=>{Tt.target===o&&this.closeWidget()});const s=document.createElement("iframe");s.id=vt,s.title=t.title||t.workflow;const u=new URLSearchParams({embed:"1",workflow:t.workflow,host:t.host||"",title:t.title||""});s.src=`${this.agentOrigin}/host/widget?${u.toString()}`,s.style.cssText="width:min(560px,100%);height:80vh;border:none;border-radius:12px;background:#fff;box-shadow:0 20px 60px rgba(0,0,0,0.25);display:block;",o.appendChild(s),document.body.appendChild(o),this.widgetIframe=s,this.widgetReady=!1;const g={channel:l,type:"init",token:n,refreshToken:i},w={workflow:t.workflow,title:t.title,host:t.host,prefilled:t.prefilled?k(t.prefilled):void 0,hostContext:t.hostContext?k(t.hostContext):void 0,sessionId:t.sessionId,preferSandboxFiles:t.preferSandboxFiles},Mt={channel:l,type:"open-widget",payload:w};this.pendingWidgetMessages=[g,Mt]}closeWidget(){var t;(t=document.getElementById(J))==null||t.remove(),this.widgetIframe=null,this.widgetReady=!1,this.pendingWidgetMessages=[]}sendToHub(t){this.post("hub",t)}post(t,n){var u;const i=t==="hub"?this.hubReady:this.widgetReady,o=t==="hub"?this.pendingHubMessages:this.pendingWidgetMessages;if(!i){o.push(n);return}const s=t==="hub"?this.hubIframe:this.widgetIframe;(u=s==null?void 0:s.contentWindow)==null||u.postMessage(n,z(this.agentOrigin))}flush(t){const n=t==="hub"?this.pendingHubMessages:this.pendingWidgetMessages,i=t==="hub"?this.hubIframe:this.widgetIframe;if(!(i!=null&&i.contentWindow))return;const o=z(this.agentOrigin);for(;n.length;){const s=n.shift();s&&i.contentWindow.postMessage(s,o)}}}let a={},r=null,E="",A="",P=null;function Et(){const e=(a.agentOrigin||"").replace(/\/$/,"");if(!e)throw new Error("Agent 前端地址未配置:请在 init({ agentOrigin }) 传入,或由宿主 BFF bootstrap 返回 agent_web_origin");return e}function Z(e){var t;e.agent_web_origin&&(a.agentOrigin=e.agent_web_origin.replace(/\/$/,"")),e.agent_token&&(E=e.agent_token),e.refresh_token&&(A=e.refresh_token),(t=a.onBootstrap)==null||t.call(a,e)}function T(){return b(this,null,function*(){if(a.getToken)return E=yield a.getToken(),E;if(E)return E;if(a.bootstrap){const e=yield a.bootstrap();if(Z(e),E)return E}throw new Error("未连接 Agent:请配置 bootstrap 或 getToken")})}function O(){if(a.agentOrigin)try{R().updateLauncherHint(xt())}catch(e){}}function R(){const e=Et();return r||(N(O),r=new Ct(e,Rt,{onHintUse:(t,n)=>{j(t,n)},onHintDismiss:()=>{pt(),O()}}),a.showHub!==!1&&r.mountHub()),r}function Pt(){if(!(!r||!a.agentOrigin)){for(const{pageId:e,actions:t}of wt())r.sendToHub({channel:"agent-host",type:"register-page",pageId:e,actions:K(t)});r.sendToHub({channel:"agent-host",type:"set-page",pageId:bt()}),O()}}function Rt(e){var t;if(e.type==="ready"&&e.surface==="hub"&&T().then(n=>{r==null||r.sendToHub({channel:"agent-host",type:"init",token:n,refreshToken:A||void 0}),Pt()}).catch(()=>{}),e.type==="started"&&(r==null||r.closeWidget(),r==null||r.openHubPanel(),r==null||r.sendToHub({channel:"agent-host",type:"task-started",taskId:e.taskId,sessionId:e.sessionId,workflow:e.workflow,label:e.label||e.workflow,formValues:e.formValues,prefilled:e.prefilled,hostContext:e.hostContext,hubContinue:e.hubContinue})),e.type==="complete"){if(e.status==="success"||e.status==="failed"||e.status==="cancelled"){const n=e.hostContext&&e.hostContext.refresh;ut(n,{taskId:e.taskId,result:e.result,hostContext:e.hostContext,apply:e.apply})}(t=a.onTaskComplete)==null||t.call(a,{taskId:e.taskId,status:e.status,hostContext:e.hostContext,result:e.result,apply:e.apply}),r==null||r.closeWidget()}e.type==="close"&&(r==null||r.closeWidget()),e.type==="open-widget"&&U(e.payload),e.type==="open-action"&&j(e.pageId,e.actionId),e.type==="hub-stats"&&(e.running,r==null||r.updateLauncherStats(e.running,e.waiting),O()),e.type==="request-host-context"&&It()}function It(){return b(this,null,function*(){if(!r||!a.agentOrigin)return;let e={};try{a.getHostContext?e=(yield a.getHostContext())||{}:e=F()}catch(n){e=F()}const t=ct(e);r.sendToHub({channel:"agent-host",type:"set-host-context",context:t})})}function j(e,t){return b(this,null,function*(){const n=V(e,t);if(!n)return;if(G(n.action)){yield Ot(n);return}const i=gt(e,t);i&&(yield U(i))})}function Ot(e){return b(this,null,function*(){yield M(),e.action.workflow&&!e.action.skill&&a.prepareOpenWidget&&(yield a.prepareOpenWidget());const t=yield T(),n=R();n.openHubPanel(),n.sendToHub({channel:"agent-host",type:"init",token:t,refreshToken:A||void 0}),n.sendToHub({channel:"agent-host",type:"run-direct",workflow:e.action.workflow||e.action.skill||"",title:e.action.label,host:e.action.host||a.host,skill:e.action.skill,noTools:e.action.noTools===!0,prefilled:e.prefilled,hostContext:e.hostContext})})}function U(e){return b(this,null,function*(){yield M(),a.prepareOpenWidget&&(yield a.prepareOpenWidget());const t=R(),n=yield T();t.openWidget({workflow:e.workflow,title:e.title||e.label,host:e.host||a.host,prefilled:e.prefilled,hostContext:e.hostContext,sessionId:e.sessionId,preferSandboxFiles:e.preferSandboxFiles},n,A||void 0)})}function M(){return b(this,null,function*(){P&&(yield P)})}function At(e){return b(this,null,function*(){if(a=S({showHub:!0},e),a.bootstrap){const t=yield a.bootstrap();Z(t)}if(a.agentOrigin&&a.showHub!==!1&&typeof document!="undefined")try{R();const t=yield T();r==null||r.sendToHub({channel:"agent-host",type:"init",token:t,refreshToken:A||void 0})}catch(t){}})}const Q={init(e){return b(this,null,function*(){P&&(yield P),P=At(e).finally(()=>{P=null}),yield P})},getToken(){return b(this,null,function*(){return yield M(),T()})},registerPage(i,o){return b(this,arguments,function*(e,t,n={}){yield M(),at(e,t,n),a.agentOrigin&&R().sendToHub({channel:"agent-host",type:"register-page",pageId:e,actions:K(t)}),O()})},getHostContext(){return F()},unregisterPage(e){return b(this,null,function*(){yield M(),lt(e),a.agentOrigin&&(R().sendToHub({channel:"agent-host",type:"unregister-page",pageId:e}),R().sendToHub({channel:"agent-host",type:"set-page",pageId:null})),O()})},setCurrentPage(e){return b(this,null,function*(){yield M(),ft(e),a.agentOrigin&&R().sendToHub({channel:"agent-host",type:"set-page",pageId:e}),O()})},openAction(e,t){return b(this,null,function*(){if(!V(e,t))throw new Error("当前操作不可用");yield j(e,t)})},openWorkflow(n){return b(this,arguments,function*(e,t={}){yield U(et(S({workflow:e},t),{host:t.host||a.host,title:t.title||t.label||e}))})},canOpen(e,t){return!0},destroy(){r==null||r.destroy(),r=null,E="",A="",a={},P=null,N(null),dt()}};typeof window!="undefined"&&(window.AgentHost=Q),p.AGENT_HOST_MSG=l,p.AgentHost=Q,p.isAgentHostMessage=d,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})})(this.AgentHost=this.AgentHost||{});
298
+ </div>`;const i=n.querySelector(".agent-host-hint-text");i&&(i.textContent=t.hint);const o=n.querySelector(".agent-host-hint-use"),s=n.querySelector(".agent-host-hint-dismiss"),u=g=>g.preventDefault();o==null||o.addEventListener("mousedown",u),s==null||s.addEventListener("mousedown",u),o==null||o.addEventListener("click",g=>{var w;g.stopPropagation(),(w=this.onHintUse)==null||w.call(this,t.pageId,t.actionId)}),s==null||s.addEventListener("click",g=>{var w;g.stopPropagation(),(w=this.onHintDismiss)==null||w.call(this)}),n.classList.add("is-visible"),this.layoutHint(n,t),this.bindHintReposition()}layoutHint(t,n){if(n.placement!=="anchor"){t.classList.remove("is-anchored"),t.style.top="",t.style.left="";return}const i=yt(n.pageId,n.actionId);if(!i){t.classList.remove("is-anchored"),t.style.top="",t.style.left="";return}t.classList.add("is-anchored");const o=8,s=t.offsetWidth||320,u=t.offsetHeight||48;let g=i.top,w=i.right+o;w+s>window.innerWidth-16&&(w=Math.max(16,i.left),g=i.bottom+o),g+u>window.innerHeight-16&&(g=Math.max(16,i.top-u-o)),g<16&&(g=16),w<16&&(w=16),t.style.top=`${Math.round(g)}px`,t.style.left=`${Math.round(w)}px`}collectScrollParents(t){var o;const n=[];let i=(o=t==null?void 0:t.parentElement)!=null?o:null;for(;i;){const s=window.getComputedStyle(i),u=s.overflowY,g=s.overflowX;/(auto|scroll|overlay)/.test(`${g} ${u}`)&&n.push(i),i=i.parentElement}return n}bindHintReposition(){var i,o;if(typeof window=="undefined")return;this.hintRepositionBound||(window.addEventListener("scroll",this.onHintReposition,!0),window.addEventListener("resize",this.onHintReposition),(i=window.visualViewport)==null||i.addEventListener("resize",this.onHintReposition),(o=window.visualViewport)==null||o.addEventListener("scroll",this.onHintReposition),this.hintRepositionBound=!0);const t=this.launcherHintAction;for(const s of this.hintScrollParents)s.removeEventListener("scroll",this.onHintReposition);if(this.hintScrollParents=[],!t||t.placement!=="anchor")return;const n=Y(t.pageId,t.actionId);this.hintScrollParents=this.collectScrollParents(n);for(const s of this.hintScrollParents)s.addEventListener("scroll",this.onHintReposition,{passive:!0})}unbindHintReposition(){var t,n;if(typeof window!="undefined"){this.hintRepositionBound&&(window.removeEventListener("scroll",this.onHintReposition,!0),window.removeEventListener("resize",this.onHintReposition),(t=window.visualViewport)==null||t.removeEventListener("resize",this.onHintReposition),(n=window.visualViewport)==null||n.removeEventListener("scroll",this.onHintReposition),this.hintRepositionBound=!1);for(const i of this.hintScrollParents)i.removeEventListener("scroll",this.onHintReposition);this.hintScrollParents=[]}}mountLauncher(){if(this.hubLauncher||document.getElementById(f))return;const t=document.createElement("button");if(t.id=f,t.type="button",t.title="景行 AI",t.setAttribute("aria-label","景行 AI"),t.innerHTML='<span class="agent-host-launcher-logo" aria-hidden="true"><svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" d="M576 192v64H352A160 160 0 0 0 192 416v192A160 160 0 0 0 352 768h320A160 160 0 0 0 832 608v-192h64v192a224 224 0 0 1-224 224h-320A224 224 0 0 1 128 608v-192A224 224 0 0 1 352 192H576z m73.344 217.344l45.312 45.312-3.52 3.456-39.168 39.168-12.608 12.608L637.248 512l57.408 57.344-45.312 45.312-80-80a32 32 0 0 1 0-45.312l17.28-17.28 20.096-20.032 21.12-21.184 3.84-3.712 14.208-14.272 3.456-3.52zM432 416v192H352v-192h80z m351.488-292.032c8.128 31.168 21.824 56.192 41.088 75.52 19.2 19.2 44.288 32.896 75.52 41.024 15.872 4.16 15.872 26.816 0 30.976-31.232 8.128-56.32 21.824-75.52 41.088-19.2 19.2-32.96 44.288-41.088 75.52-4.16 15.872-26.816 15.872-30.976 0-8.128-31.232-21.824-56.32-41.088-75.52-19.2-19.2-44.288-32.96-75.52-41.088-15.872-4.16-15.872-26.816 0-30.976 31.232-8.128 56.32-21.824 75.52-41.088 19.2-19.2 32.96-44.288 41.088-75.52 4.16-15.872 26.816-15.872 30.976 0z"/></svg></span><span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span><span class="agent-host-launcher-bell" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 3a5 5 0 0 0-5 5v1.5c0 1.3-.4 2.6-1.2 3.7L4.5 15.5c-.4.5-.1 1.3.5 1.3h14c.6 0 .9-.8.5-1.3l-1.3-2.3A6.6 6.6 0 0 1 17 9.5V8a5 5 0 0 0-5-5Z" fill="#fff"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg></span><span class="agent-host-launcher-badge"></span>',t.addEventListener("click",()=>this.openHubPanel()),document.body.appendChild(t),this.hubLauncher=t,this.hubLauncherBadge=t.querySelector(".agent-host-launcher-badge"),document.getElementById("agent-host-launcher-hint"))this.hubLauncherHint=document.getElementById("agent-host-launcher-hint");else{const n=document.createElement("div");n.id="agent-host-launcher-hint",document.body.appendChild(n),this.hubLauncherHint=n}}mountHubPanel(){const t=document.createElement("div");t.id=m;const n=document.createElement("div");n.className="agent-host-hub-backdrop",n.addEventListener("click",()=>this.closeHubPanel());const i=document.createElement("div");i.className="agent-host-hub-panel-shell";const o=document.createElement("iframe");o.id=mt,o.title="景行 AI",o.src=`${this.agentOrigin}/host/hub?embed=1&panel=1&layout=studio`,o.allow="clipboard-read; clipboard-write",i.appendChild(o),t.appendChild(n),t.appendChild(i),document.body.appendChild(t),this.hubPanelOverlay=t,this.hubIframe=o}updateLauncherStats(t,n){this.lastRunning=t,this.lastWaiting=n,this.applyLauncherVisual()}applyLauncherVisual(){const t=this.hubLauncher,n=this.hubLauncherBadge;if(!t||!n)return;const i=t.querySelector(".agent-host-launcher-bell"),o=this.lastRunning,s=this.lastWaiting,u=s>0&&!this.hubPanelOpen;t.classList.toggle("is-pulse",o>0&&!u),t.classList.toggle("is-orbiting",o>0&&!u),t.classList.toggle("is-hitl",u),u?(t.title="有待确认事项,点击打开助手",t.setAttribute("aria-label","有待确认事项,点击打开助手")):(t.title="景行 AI",t.setAttribute("aria-label","景行 AI")),i&&i.classList.toggle("is-visible",u),o>0?(n.textContent=String(o),n.classList.add("is-visible"),n.classList.remove("is-waiting")):s>0?(n.textContent="!",n.classList.add("is-visible","is-waiting")):(n.textContent="",n.classList.remove("is-visible","is-waiting"))}removeHub(){var t,n,i;(t=document.getElementById(f))==null||t.remove(),(n=document.getElementById("agent-host-launcher-hint"))==null||n.remove(),(i=document.getElementById(m))==null||i.remove(),this.hubLauncher=null,this.hubLauncherBadge=null,this.hubLauncherHint=null,this.hubPanelOverlay=null,this.hubIframe=null,this.hubReady=!1,this.hubPanelOpen=!1,this.pendingHubMessages=[]}openWidget(t,n,i){this.closeWidget();const o=document.createElement("div");o.id=J,o.style.cssText="position:fixed;inset:0;z-index:2147483646;background:rgba(15,23,42,0.45);display:flex;align-items:center;justify-content:center;padding:16px;",o.addEventListener("click",St=>{St.target===o&&this.closeWidget()});const s=document.createElement("iframe");s.id=vt,s.title=t.title||t.workflow;const u=new URLSearchParams({embed:"1",workflow:t.workflow,host:t.host||"",title:t.title||""});s.src=`${this.agentOrigin}/host/widget?${u.toString()}`,s.style.cssText="width:min(560px,100%);height:80vh;border:none;border-radius:12px;background:#fff;box-shadow:0 20px 60px rgba(0,0,0,0.25);display:block;",o.appendChild(s),document.body.appendChild(o),this.widgetIframe=s,this.widgetReady=!1;const g={channel:l,type:"init",token:n,refreshToken:i},w={workflow:t.workflow,title:t.title,host:t.host,prefilled:t.prefilled?k(t.prefilled):void 0,hostContext:t.hostContext?k(t.hostContext):void 0,sessionId:t.sessionId,preferSandboxFiles:t.preferSandboxFiles},Tt={channel:l,type:"open-widget",payload:w};this.pendingWidgetMessages=[g,Tt]}closeWidget(){var t;(t=document.getElementById(J))==null||t.remove(),this.widgetIframe=null,this.widgetReady=!1,this.pendingWidgetMessages=[]}sendToHub(t){this.post("hub",t)}post(t,n){var u;const i=t==="hub"?this.hubReady:this.widgetReady,o=t==="hub"?this.pendingHubMessages:this.pendingWidgetMessages;if(!i){o.push(n);return}const s=t==="hub"?this.hubIframe:this.widgetIframe;(u=s==null?void 0:s.contentWindow)==null||u.postMessage(n,z(this.agentOrigin))}flush(t){const n=t==="hub"?this.pendingHubMessages:this.pendingWidgetMessages,i=t==="hub"?this.hubIframe:this.widgetIframe;if(!(i!=null&&i.contentWindow))return;const o=z(this.agentOrigin);for(;n.length;){const s=n.shift();s&&i.contentWindow.postMessage(s,o)}}}let a={},r=null,E="",O="",P=null;function Et(){const e=(a.agentOrigin||"").replace(/\/$/,"");if(!e)throw new Error("Agent 前端地址未配置:请在 init({ agentOrigin }) 传入,或由宿主 BFF bootstrap 返回 agent_web_origin");return e}function Z(e){var t;e.agent_web_origin&&(a.agentOrigin=e.agent_web_origin.replace(/\/$/,"")),e.agent_token&&(E=e.agent_token),e.refresh_token&&(O=e.refresh_token),(t=a.onBootstrap)==null||t.call(a,e)}function S(){return b(this,null,function*(){if(a.getToken)return E=yield a.getToken(),E;if(E)return E;if(a.bootstrap){const e=yield a.bootstrap();if(Z(e),E)return E}throw new Error("未连接 Agent:请配置 bootstrap 或 getToken")})}function I(){if(a.agentOrigin)try{R().updateLauncherHint(xt())}catch(e){}}function R(){const e=Et();return r||(N(I),r=new Ct(e,Rt,{onHintUse:(t,n)=>{U(t,n)},onHintDismiss:()=>{pt(),I()}}),a.showHub!==!1&&r.mountHub()),r}function Pt(){if(!(!r||!a.agentOrigin)){for(const{pageId:e,actions:t}of wt())r.sendToHub({channel:"agent-host",type:"register-page",pageId:e,actions:K(t)});r.sendToHub({channel:"agent-host",type:"set-page",pageId:bt()}),I()}}function Rt(e){var t;if(e.type==="ready"&&e.surface==="hub"&&S().then(n=>{r==null||r.sendToHub({channel:"agent-host",type:"init",token:n,refreshToken:O||void 0}),Pt()}).catch(()=>{}),e.type==="started"&&(r==null||r.closeWidget(),r==null||r.openHubPanel(),r==null||r.sendToHub({channel:"agent-host",type:"task-started",taskId:e.taskId,sessionId:e.sessionId,workflow:e.workflow,label:e.label||e.workflow,formValues:e.formValues,prefilled:e.prefilled,hostContext:e.hostContext,hubContinue:e.hubContinue})),e.type==="complete"){if(e.status==="success"||e.status==="failed"||e.status==="cancelled"){const n=e.hostContext&&e.hostContext.refresh;ut(n,{taskId:e.taskId,result:e.result,hostContext:e.hostContext,apply:e.apply})}(t=a.onTaskComplete)==null||t.call(a,{taskId:e.taskId,status:e.status,hostContext:e.hostContext,result:e.result,apply:e.apply}),r==null||r.closeWidget()}e.type==="close"&&(r==null||r.closeWidget()),e.type==="open-widget"&&_(e.payload),e.type==="open-action"&&U(e.pageId,e.actionId),e.type==="hub-stats"&&(e.running,r==null||r.updateLauncherStats(e.running,e.waiting),I()),e.type==="request-host-context"&&At()}function At(){return b(this,null,function*(){if(!r||!a.agentOrigin)return;let e={};try{a.getHostContext?e=(yield a.getHostContext())||{}:e=F()}catch(n){e=F()}const t=ct(e);r.sendToHub({channel:"agent-host",type:"set-host-context",context:t})})}function U(e,t){return b(this,null,function*(){const n=j(e,t);if(!n)return;if(G(n.action)){yield It(n);return}const i=gt(e,t);i&&(yield _(i))})}function It(e){return b(this,null,function*(){yield T(),e.action.workflow&&!e.action.skill&&a.prepareOpenWidget&&(yield a.prepareOpenWidget());const t=yield S(),n=R();n.openHubPanel(),n.sendToHub({channel:"agent-host",type:"init",token:t,refreshToken:O||void 0}),n.sendToHub({channel:"agent-host",type:"run-direct",workflow:e.action.workflow||e.action.skill||"",title:e.action.label,host:e.action.host||a.host,skill:e.action.skill,noTools:e.action.noTools===!0,prefilled:e.prefilled,hostContext:e.hostContext})})}function _(e){return b(this,null,function*(){yield T(),a.prepareOpenWidget&&(yield a.prepareOpenWidget());const t=R(),n=yield S();t.openWidget({workflow:e.workflow,title:e.title||e.label,host:e.host||a.host,prefilled:e.prefilled,hostContext:e.hostContext,sessionId:e.sessionId,preferSandboxFiles:e.preferSandboxFiles},n,O||void 0)})}function T(){return b(this,null,function*(){P&&(yield P)})}function Ot(e){return b(this,null,function*(){if(a=M({showHub:!0},e),a.bootstrap){const t=yield a.bootstrap();Z(t)}if(a.agentOrigin&&a.showHub!==!1&&typeof document!="undefined")try{R();const t=yield S();r==null||r.sendToHub({channel:"agent-host",type:"init",token:t,refreshToken:O||void 0})}catch(t){}})}const Q={init(e){return b(this,null,function*(){P&&(yield P),P=Ot(e).finally(()=>{P=null}),yield P})},getToken(){return b(this,null,function*(){return yield T(),S()})},registerPage(i,o){return b(this,arguments,function*(e,t,n={}){yield T(),at(e,t,n),a.agentOrigin&&R().sendToHub({channel:"agent-host",type:"register-page",pageId:e,actions:K(t)}),I()})},getHostContext(){return F()},unregisterPage(e){return b(this,null,function*(){yield T(),lt(e),a.agentOrigin&&(R().sendToHub({channel:"agent-host",type:"unregister-page",pageId:e}),R().sendToHub({channel:"agent-host",type:"set-page",pageId:null})),I()})},setCurrentPage(e){return b(this,null,function*(){yield T(),ft(e),a.agentOrigin&&R().sendToHub({channel:"agent-host",type:"set-page",pageId:e}),I()})},openAction(e,t){return b(this,null,function*(){if(!j(e,t))throw new Error("当前操作不可用");yield U(e,t)})},openWorkflow(n){return b(this,arguments,function*(e,t={}){yield _(et(M({workflow:e},t),{host:t.host||a.host,title:t.title||t.label||e}))})},canOpen(e,t){return!0},destroy(){r==null||r.destroy(),r=null,E="",O="",a={},P=null,N(null),dt()}};typeof window!="undefined"&&(window.AgentHost=Q),p.AGENT_HOST_MSG=l,p.AgentHost=Q,p.isAgentHostMessage=d,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})})(this.AgentHost=this.AgentHost||{});
package/dist/ai-host.mjs CHANGED
@@ -1,12 +1,12 @@
1
1
  var et = Object.defineProperty, nt = Object.defineProperties;
2
2
  var it = Object.getOwnPropertyDescriptors;
3
- var q = Object.getOwnPropertySymbols;
3
+ var V = Object.getOwnPropertySymbols;
4
4
  var ot = Object.prototype.hasOwnProperty, st = Object.prototype.propertyIsEnumerable;
5
5
  var z = (e, t, n) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, O = (e, t) => {
6
6
  for (var n in t || (t = {}))
7
7
  ot.call(t, n) && z(e, n, t[n]);
8
- if (q)
9
- for (var n of q(t))
8
+ if (V)
9
+ for (var n of V(t))
10
10
  st.call(t, n) && z(e, n, t[n]);
11
11
  return e;
12
12
  }, _ = (e, t) => nt(e, it(t));
@@ -38,13 +38,13 @@ function v(e) {
38
38
  return typeof e == "function" ? e() : e;
39
39
  }
40
40
  const w = {}, E = {};
41
- let S = {}, p = null, P = !1, b = null, T = null, N = !1;
41
+ let S = {}, p = null, P = !1, b = null, M = null, N = !1;
42
42
  function Y(e) {
43
- T = e;
43
+ M = e;
44
44
  }
45
45
  function L() {
46
46
  try {
47
- T == null || T();
47
+ M == null || M();
48
48
  } catch (e) {
49
49
  }
50
50
  }
@@ -171,7 +171,7 @@ function X(e) {
171
171
  noTools: t.noTools === !0 ? !0 : void 0
172
172
  }));
173
173
  }
174
- function V(e, t) {
174
+ function U(e, t) {
175
175
  const n = (w[e] || []).find((o) => o.id === t);
176
176
  if (!n || n.enabled && !n.enabled()) return null;
177
177
  const i = n.prefilled ? k(v(n.prefilled)) : void 0;
@@ -182,7 +182,7 @@ function V(e, t) {
182
182
  };
183
183
  }
184
184
  function mt(e, t) {
185
- const n = V(e, t);
185
+ const n = U(e, t);
186
186
  return !n || J(n.action) ? null : {
187
187
  workflow: n.action.workflow || n.action.skill || "",
188
188
  title: n.action.label,
@@ -682,7 +682,7 @@ class Ot {
682
682
  mountLauncher() {
683
683
  if (this.hubLauncher || document.getElementById(d)) return;
684
684
  const t = document.createElement("button");
685
- if (t.id = d, t.type = "button", t.title = "景行 AI", t.setAttribute("aria-label", "景行 AI"), t.innerHTML = '<span class="agent-host-launcher-logo" aria-hidden="true"><svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" d="M603.904 244.992c134.4 0 243.3536 108.9536 243.3536 243.3536v202.8032c0 134.4-108.9536 243.3536-243.3536 243.3536H320c-134.4 0-243.3536-108.9536-243.3536-243.3536V488.3456c0-134.4 108.9536-243.3536 243.3536-243.3536h283.904z m0 81.1008H320c-89.6 0-162.2528 72.6528-162.2528 162.2528v202.8032c0 89.6 72.6528 162.2528 162.2528 162.2528h283.904c89.6 0 162.2528-72.6528 162.2528-162.2528V488.3456c0-89.6-72.6528-162.2528-162.2528-162.2528z"/><path fill="#fff" d="M340.224 508.6208c27.0336 0 40.5504 13.5168 40.5504 40.5504v81.1008c0 27.0336-13.5168 40.5504-40.5504 40.5504-27.0336 0-40.5504-13.5168-40.5504-40.5504v-81.1008c0-27.0336 13.5168-40.5504 40.5504-40.5504zM583.2192 501.3504c15.2576-11.4176 36.864-8.3456 48.2816 6.912a34.4832 34.4832 0 0 1-6.912 48.2816l-44.3904 33.28 44.3904 33.28a34.53952 34.53952 0 0 1 9.472 44.3392l-2.56 3.9424c-11.4176 15.2576-33.024 18.3296-48.2816 6.912l-59.4944-44.5952c-13.7728-10.3424-21.9136-26.5728-21.9136-43.8272s8.0896-33.4848 21.9136-43.8272l59.4944-44.5952zM883.5072 261.12l-19.7632 47.3088c-2.7648 6.656-9.2672 10.9568-16.4864 10.9568s-13.6704-4.3008-16.4864-10.9568L811.008 261.12a44.416 44.416 0 0 0-19.7632-21.9648l-34.8672-19.0976c-5.7344-3.1232-9.2672-9.1136-9.2672-15.6672s3.5328-12.544 9.2672-15.6672l34.8672-19.0464a44.89728 44.89728 0 0 0 19.7632-21.9648l19.7632-47.3088c2.7648-6.656 9.2672-10.9568 16.4864-10.9568s13.6704 4.3008 16.4864 10.9568l19.7632 47.3088a44.416 44.416 0 0 0 19.7632 21.9648l34.8672 19.0976c5.7344 3.1232 9.2672 9.1136 9.2672 15.6672s-3.584 12.544-9.2672 15.6672l-34.8672 19.0464c-8.9088 4.864-15.872 12.6464-19.7632 21.9648z"/></svg></span><span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span><span class="agent-host-launcher-bell" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 3a5 5 0 0 0-5 5v1.5c0 1.3-.4 2.6-1.2 3.7L4.5 15.5c-.4.5-.1 1.3.5 1.3h14c.6 0 .9-.8.5-1.3l-1.3-2.3A6.6 6.6 0 0 1 17 9.5V8a5 5 0 0 0-5-5Z" fill="#fff"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg></span><span class="agent-host-launcher-badge"></span>', t.addEventListener("click", () => this.openHubPanel()), document.body.appendChild(t), this.hubLauncher = t, this.hubLauncherBadge = t.querySelector(".agent-host-launcher-badge"), document.getElementById("agent-host-launcher-hint"))
685
+ if (t.id = d, t.type = "button", t.title = "景行 AI", t.setAttribute("aria-label", "景行 AI"), t.innerHTML = '<span class="agent-host-launcher-logo" aria-hidden="true"><svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" d="M576 192v64H352A160 160 0 0 0 192 416v192A160 160 0 0 0 352 768h320A160 160 0 0 0 832 608v-192h64v192a224 224 0 0 1-224 224h-320A224 224 0 0 1 128 608v-192A224 224 0 0 1 352 192H576z m73.344 217.344l45.312 45.312-3.52 3.456-39.168 39.168-12.608 12.608L637.248 512l57.408 57.344-45.312 45.312-80-80a32 32 0 0 1 0-45.312l17.28-17.28 20.096-20.032 21.12-21.184 3.84-3.712 14.208-14.272 3.456-3.52zM432 416v192H352v-192h80z m351.488-292.032c8.128 31.168 21.824 56.192 41.088 75.52 19.2 19.2 44.288 32.896 75.52 41.024 15.872 4.16 15.872 26.816 0 30.976-31.232 8.128-56.32 21.824-75.52 41.088-19.2 19.2-32.96 44.288-41.088 75.52-4.16 15.872-26.816 15.872-30.976 0-8.128-31.232-21.824-56.32-41.088-75.52-19.2-19.2-44.288-32.96-75.52-41.088-15.872-4.16-15.872-26.816 0-30.976 31.232-8.128 56.32-21.824 75.52-41.088 19.2-19.2 32.96-44.288 41.088-75.52 4.16-15.872 26.816-15.872 30.976 0z"/></svg></span><span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span><span class="agent-host-launcher-bell" aria-hidden="true"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12 3a5 5 0 0 0-5 5v1.5c0 1.3-.4 2.6-1.2 3.7L4.5 15.5c-.4.5-.1 1.3.5 1.3h14c.6 0 .9-.8.5-1.3l-1.3-2.3A6.6 6.6 0 0 1 17 9.5V8a5 5 0 0 0-5-5Z" fill="#fff"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/></svg></span><span class="agent-host-launcher-badge"></span>', t.addEventListener("click", () => this.openHubPanel()), document.body.appendChild(t), this.hubLauncher = t, this.hubLauncherBadge = t.querySelector(".agent-host-launcher-badge"), document.getElementById("agent-host-launcher-hint"))
686
686
  this.hubLauncherHint = document.getElementById("agent-host-launcher-hint");
687
687
  else {
688
688
  const n = document.createElement("div");
@@ -787,7 +787,7 @@ function Q(e) {
787
787
  var t;
788
788
  e.agent_web_origin && (a.agentOrigin = e.agent_web_origin.replace(/\/$/, "")), e.agent_token && (x = e.agent_token), e.refresh_token && (R = e.refresh_token), (t = a.onBootstrap) == null || t.call(a, e);
789
789
  }
790
- function M() {
790
+ function T() {
791
791
  return f(this, null, function* () {
792
792
  if (a.getToken)
793
793
  return x = yield a.getToken(), x;
@@ -808,16 +808,16 @@ function H() {
808
808
  }
809
809
  function m() {
810
810
  const e = At();
811
- return r || (Y(H), r = new Ot(e, Tt, {
811
+ return r || (Y(H), r = new Ot(e, Mt, {
812
812
  onHintUse: (t, n) => {
813
- U(t, n);
813
+ j(t, n);
814
814
  },
815
815
  onHintDismiss: () => {
816
816
  yt(), H();
817
817
  }
818
818
  }), a.showHub !== !1 && r.mountHub()), r;
819
819
  }
820
- function Mt() {
820
+ function Tt() {
821
821
  if (!(!r || !a.agentOrigin)) {
822
822
  for (const { pageId: e, actions: t } of Ht())
823
823
  r.sendToHub({
@@ -833,15 +833,15 @@ function Mt() {
833
833
  }), H();
834
834
  }
835
835
  }
836
- function Tt(e) {
836
+ function Mt(e) {
837
837
  var t;
838
- if (e.type === "ready" && e.surface === "hub" && M().then((n) => {
838
+ if (e.type === "ready" && e.surface === "hub" && T().then((n) => {
839
839
  r == null || r.sendToHub({
840
840
  channel: "agent-host",
841
841
  type: "init",
842
842
  token: n,
843
843
  refreshToken: R || void 0
844
- }), Mt();
844
+ }), Tt();
845
845
  }).catch(() => {
846
846
  }), e.type === "started" && (r == null || r.closeWidget(), r == null || r.openHubPanel(), r == null || r.sendToHub({
847
847
  channel: "agent-host",
@@ -872,7 +872,7 @@ function Tt(e) {
872
872
  apply: e.apply
873
873
  }), r == null || r.closeWidget();
874
874
  }
875
- e.type === "close" && (r == null || r.closeWidget()), e.type === "open-widget" && j(e.payload), e.type === "open-action" && U(e.pageId, e.actionId), e.type === "hub-stats" && (e.running, r == null || r.updateLauncherStats(e.running, e.waiting), H()), e.type === "request-host-context" && St();
875
+ e.type === "close" && (r == null || r.closeWidget()), e.type === "open-widget" && q(e.payload), e.type === "open-action" && j(e.pageId, e.actionId), e.type === "hub-stats" && (e.running, r == null || r.updateLauncherStats(e.running, e.waiting), H()), e.type === "request-host-context" && St();
876
876
  }
877
877
  function St() {
878
878
  return f(this, null, function* () {
@@ -891,22 +891,22 @@ function St() {
891
891
  });
892
892
  });
893
893
  }
894
- function U(e, t) {
894
+ function j(e, t) {
895
895
  return f(this, null, function* () {
896
- const n = V(e, t);
896
+ const n = U(e, t);
897
897
  if (!n) return;
898
898
  if (J(n.action)) {
899
899
  yield $t(n);
900
900
  return;
901
901
  }
902
902
  const i = mt(e, t);
903
- i && (yield j(i));
903
+ i && (yield q(i));
904
904
  });
905
905
  }
906
906
  function $t(e) {
907
907
  return f(this, null, function* () {
908
908
  yield C(), e.action.workflow && !e.action.skill && a.prepareOpenWidget && (yield a.prepareOpenWidget());
909
- const t = yield M(), n = m();
909
+ const t = yield T(), n = m();
910
910
  n.openHubPanel(), n.sendToHub({
911
911
  channel: "agent-host",
912
912
  type: "init",
@@ -925,10 +925,10 @@ function $t(e) {
925
925
  });
926
926
  });
927
927
  }
928
- function j(e) {
928
+ function q(e) {
929
929
  return f(this, null, function* () {
930
930
  yield C(), a.prepareOpenWidget && (yield a.prepareOpenWidget());
931
- const t = m(), n = yield M();
931
+ const t = m(), n = yield T();
932
932
  t.openWidget(
933
933
  {
934
934
  workflow: e.workflow,
@@ -958,7 +958,7 @@ function zt(e) {
958
958
  if (a.agentOrigin && a.showHub !== !1 && typeof document != "undefined")
959
959
  try {
960
960
  m();
961
- const t = yield M();
961
+ const t = yield T();
962
962
  r == null || r.sendToHub({
963
963
  channel: "agent-host",
964
964
  type: "init",
@@ -979,7 +979,7 @@ const Wt = {
979
979
  },
980
980
  getToken() {
981
981
  return f(this, null, function* () {
982
- return yield C(), M();
982
+ return yield C(), T();
983
983
  });
984
984
  },
985
985
  registerPage(i, o) {
@@ -1008,13 +1008,13 @@ const Wt = {
1008
1008
  },
1009
1009
  openAction(e, t) {
1010
1010
  return f(this, null, function* () {
1011
- if (!V(e, t)) throw new Error("当前操作不可用");
1012
- yield U(e, t);
1011
+ if (!U(e, t)) throw new Error("当前操作不可用");
1012
+ yield j(e, t);
1013
1013
  });
1014
1014
  },
1015
1015
  openWorkflow(n) {
1016
1016
  return f(this, arguments, function* (e, t = {}) {
1017
- yield j(_(O({
1017
+ yield q(_(O({
1018
1018
  workflow: e
1019
1019
  }, t), {
1020
1020
  host: t.host || a.host,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_daniel_jiang/ai-host",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "景行 AI 宿主嵌入 SDK(FAB → 居中工作室模态;iframe Hub/Widget)",
5
5
  "type": "module",
6
6
  "main": "./dist/ai-host.js",
package/src/iframe.ts CHANGED
@@ -566,8 +566,7 @@ export class IframeBridge {
566
566
  btn.innerHTML =
567
567
  '<span class="agent-host-launcher-logo" aria-hidden="true">' +
568
568
  '<svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">' +
569
- '<path fill="#fff" d="M603.904 244.992c134.4 0 243.3536 108.9536 243.3536 243.3536v202.8032c0 134.4-108.9536 243.3536-243.3536 243.3536H320c-134.4 0-243.3536-108.9536-243.3536-243.3536V488.3456c0-134.4 108.9536-243.3536 243.3536-243.3536h283.904z m0 81.1008H320c-89.6 0-162.2528 72.6528-162.2528 162.2528v202.8032c0 89.6 72.6528 162.2528 162.2528 162.2528h283.904c89.6 0 162.2528-72.6528 162.2528-162.2528V488.3456c0-89.6-72.6528-162.2528-162.2528-162.2528z"/>' +
570
- '<path fill="#fff" d="M340.224 508.6208c27.0336 0 40.5504 13.5168 40.5504 40.5504v81.1008c0 27.0336-13.5168 40.5504-40.5504 40.5504-27.0336 0-40.5504-13.5168-40.5504-40.5504v-81.1008c0-27.0336 13.5168-40.5504 40.5504-40.5504zM583.2192 501.3504c15.2576-11.4176 36.864-8.3456 48.2816 6.912a34.4832 34.4832 0 0 1-6.912 48.2816l-44.3904 33.28 44.3904 33.28a34.53952 34.53952 0 0 1 9.472 44.3392l-2.56 3.9424c-11.4176 15.2576-33.024 18.3296-48.2816 6.912l-59.4944-44.5952c-13.7728-10.3424-21.9136-26.5728-21.9136-43.8272s8.0896-33.4848 21.9136-43.8272l59.4944-44.5952zM883.5072 261.12l-19.7632 47.3088c-2.7648 6.656-9.2672 10.9568-16.4864 10.9568s-13.6704-4.3008-16.4864-10.9568L811.008 261.12a44.416 44.416 0 0 0-19.7632-21.9648l-34.8672-19.0976c-5.7344-3.1232-9.2672-9.1136-9.2672-15.6672s3.5328-12.544 9.2672-15.6672l34.8672-19.0464a44.89728 44.89728 0 0 0 19.7632-21.9648l19.7632-47.3088c2.7648-6.656 9.2672-10.9568 16.4864-10.9568s13.6704 4.3008 16.4864 10.9568l19.7632 47.3088a44.416 44.416 0 0 0 19.7632 21.9648l34.8672 19.0976c5.7344 3.1232 9.2672 9.1136 9.2672 15.6672s-3.584 12.544-9.2672 15.6672l-34.8672 19.0464c-8.9088 4.864-15.872 12.6464-19.7632 21.9648z"/>' +
569
+ '<path fill="#fff" d="M576 192v64H352A160 160 0 0 0 192 416v192A160 160 0 0 0 352 768h320A160 160 0 0 0 832 608v-192h64v192a224 224 0 0 1-224 224h-320A224 224 0 0 1 128 608v-192A224 224 0 0 1 352 192H576z m73.344 217.344l45.312 45.312-3.52 3.456-39.168 39.168-12.608 12.608L637.248 512l57.408 57.344-45.312 45.312-80-80a32 32 0 0 1 0-45.312l17.28-17.28 20.096-20.032 21.12-21.184 3.84-3.712 14.208-14.272 3.456-3.52zM432 416v192H352v-192h80z m351.488-292.032c8.128 31.168 21.824 56.192 41.088 75.52 19.2 19.2 44.288 32.896 75.52 41.024 15.872 4.16 15.872 26.816 0 30.976-31.232 8.128-56.32 21.824-75.52 41.088-19.2 19.2-32.96 44.288-41.088 75.52-4.16 15.872-26.816 15.872-30.976 0-8.128-31.232-21.824-56.32-41.088-75.52-19.2-19.2-44.288-32.96-75.52-41.088-15.872-4.16-15.872-26.816 0-30.976 31.232-8.128 56.32-21.824 75.52-41.088 19.2-19.2 32.96-44.288 41.088-75.52 4.16-15.872 26.816-15.872 30.976 0z"/>' +
571
570
  '</svg></span>' +
572
571
  '<span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span>' +
573
572
  '<span class="agent-host-launcher-bell" aria-hidden="true">' +