@_daniel_jiang/ai-host 0.1.0 → 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,5 +1,5 @@
1
- var Mt=Object.defineProperty,$t=Object.defineProperties;var Wt=Object.getOwnPropertyDescriptors;var tt=Object.getOwnPropertySymbols;var Bt=Object.prototype.hasOwnProperty,zt=Object.prototype.propertyIsEnumerable;var j=(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={}))Bt.call(l,d)&&j(p,d,l[d]);if(tt)for(var d of tt(l))zt.call(l,d)&&j(p,d,l[d]);return p},et=(p,l)=>$t(p,Wt(l));var c=(p,l,d)=>j(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 I(){try{$==null||$()}catch(e){}}function B(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 z(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(z(e)||z(t))return;const n=y[h]||[];let i=null;if(e instanceof Node)for(const o of n){if(!D(o))continue;const s=B(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(z(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=B(i.anchor);o&&o.contains(t)&&!o.contains(e.relatedTarget)&&(x=null,I())}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],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||{}),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,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 q(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=q(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?B(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 g="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 W(e){try{return new URL(e).origin}catch(t){return e.replace(/\/$/,"")}}function kt(e,t){const n=W(e),i=W(t);if(n===i)return!0;try{const o=new URL(n),s=new URL(i),f=new Set(["localhost","127.0.0.1","[::1]"]);return o.protocol===s.protocol&&o.port===s.port&&f.has(o.hostname)&&f.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
- #${g} {
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
+ #${f} {
3
3
  position: fixed;
4
4
  right: 24px;
5
5
  bottom: 24px;
@@ -19,41 +19,77 @@ var Mt=Object.defineProperty,$t=Object.defineProperties;var Wt=Object.getOwnProp
19
19
  box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42);
20
20
  transition: transform 0.15s ease, opacity 0.2s ease, visibility 0.2s ease;
21
21
  }
22
- #${g}:hover { transform: scale(1.05); }
23
- #${g}.is-hidden {
22
+ #${f}:hover { transform: scale(1.05); }
23
+ #${f}.is-hidden {
24
24
  opacity: 0;
25
25
  visibility: hidden;
26
26
  pointer-events: none;
27
27
  transform: scale(0.85);
28
28
  }
29
- #${g}.is-pulse {
29
+ #${f}.is-pulse {
30
30
  animation: agent-host-fab-pulse 2s ease-in-out infinite;
31
31
  }
32
- #${g} .agent-host-launcher-icon {
33
- display: inline-block;
34
- line-height: 1;
35
- transform-origin: center center;
32
+ #${f} .agent-host-launcher-logo {
33
+ position: relative;
34
+ z-index: 1;
35
+ width: 28px;
36
+ height: 28px;
37
+ display: inline-flex;
38
+ align-items: center;
39
+ justify-content: center;
40
+ line-height: 0;
36
41
  }
37
- #${g}.is-breathe .agent-host-launcher-icon {
38
- animation: agent-host-clover-breathe 1.8s ease-in-out infinite;
42
+ #${f} .agent-host-launcher-logo svg {
43
+ width: 100%;
44
+ height: 100%;
45
+ display: block;
39
46
  }
40
- #${g} .agent-host-launcher-bell {
47
+ #${f} .agent-host-launcher-orbit {
48
+ display: none;
49
+ position: absolute;
50
+ inset: 6px;
51
+ pointer-events: none;
52
+ z-index: 2;
53
+ }
54
+ #${f}.is-orbiting .agent-host-launcher-orbit {
55
+ display: block;
56
+ animation: agent-host-fab-orbit 2.4s linear infinite;
57
+ }
58
+ #${f} .agent-host-launcher-orbit-dot {
59
+ position: absolute;
60
+ top: 0;
61
+ left: 50%;
62
+ width: 10px;
63
+ height: 10px;
64
+ margin-left: -5px;
65
+ font-size: 10px;
66
+ line-height: 10px;
67
+ color: #fff;
68
+ text-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
69
+ }
70
+ #${f} .agent-host-launcher-bell {
41
71
  display: none;
42
72
  width: 22px;
43
73
  height: 22px;
44
74
  line-height: 0;
45
75
  transform-origin: top center;
76
+ position: relative;
77
+ z-index: 1;
46
78
  }
47
- #${g} .agent-host-launcher-bell.is-visible {
79
+ #${f} .agent-host-launcher-bell.is-visible {
48
80
  display: inline-block;
49
81
  animation: agent-host-bell-shake 0.85s ease-in-out infinite;
50
82
  }
51
- #${g} .agent-host-launcher-bell svg {
83
+ #${f} .agent-host-launcher-bell svg {
52
84
  width: 100%;
53
85
  height: 100%;
54
86
  display: block;
55
87
  }
56
- #${g} .agent-host-launcher-badge {
88
+ #${f}.is-hitl .agent-host-launcher-logo,
89
+ #${f}.is-hitl .agent-host-launcher-orbit {
90
+ display: none !important;
91
+ }
92
+ #${f} .agent-host-launcher-badge {
57
93
  position: absolute;
58
94
  top: -4px;
59
95
  right: -4px;
@@ -72,8 +108,8 @@ var Mt=Object.defineProperty,$t=Object.defineProperties;var Wt=Object.getOwnProp
72
108
  background: #f59e0b;
73
109
  color: #fff;
74
110
  }
75
- #${g} .agent-host-launcher-badge.is-visible { display: flex; }
76
- #${g} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
111
+ #${f} .agent-host-launcher-badge.is-visible { display: flex; }
112
+ #${f} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
77
113
  #agent-host-launcher-hint {
78
114
  position: fixed;
79
115
  right: 24px;
@@ -229,9 +265,9 @@ var Mt=Object.defineProperty,$t=Object.defineProperties;var Wt=Object.getOwnProp
229
265
  0%, 100% { box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42); }
230
266
  50% { box-shadow: 0 4px 26px rgba(13, 143, 123, 0.62); }
231
267
  }
232
- @keyframes agent-host-clover-breathe {
233
- 0%, 100% { transform: scale(1); }
234
- 50% { transform: scale(1.28); }
268
+ @keyframes agent-host-fab-orbit {
269
+ from { transform: rotate(0deg); }
270
+ to { transform: rotate(360deg); }
235
271
  }
236
272
  @keyframes agent-host-hint-clover {
237
273
  0% { transform: scale(0.88) rotate(0deg); }
@@ -259,4 +295,4 @@ var Mt=Object.defineProperty,$t=Object.defineProperties;var Wt=Object.getOwnProp
259
295
  <button type="button" class="agent-host-hint-use">立即开始</button>
260
296
  <button type="button" class="agent-host-hint-dismiss">稍后</button>
261
297
  </div>
262
- </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"),f=u=>u.preventDefault();o==null||o.addEventListener("mousedown",f),s==null||s.addEventListener("mousedown",f),o==null||o.addEventListener("click",u=>{var w;u.stopPropagation(),(w=this.onHintUse)==null||w.call(this,t.pageId,t.actionId)}),s==null||s.addEventListener("click",u=>{var w;u.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,f=t.offsetHeight||48;let u=i.top,w=i.right+o;w+s>window.innerWidth-16&&(w=Math.max(16,i.left),u=i.bottom+o),u+f>window.innerHeight-16&&(u=Math.max(16,i.top-f-o)),u<16&&(u=16),w<16&&(w=16),t.style.top=`${Math.round(u)}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),f=s.overflowY,u=s.overflowX;/(auto|scroll|overlay)/.test(`${u} ${f}`)&&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(g))return;const t=document.createElement("button");if(t.id=g,t.type="button",t.title="景行 AI",t.setAttribute("aria-label","景行 AI"),t.innerHTML='<span class="agent-host-launcher-icon" aria-hidden="true">✦</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="#f59e0b"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#f59e0b" 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-icon"),o=t.querySelector(".agent-host-launcher-bell"),s=this.lastRunning,f=this.lastWaiting,u=f>0&&!this.hubPanelOpen;t.classList.toggle("is-pulse",s>0),t.classList.toggle("is-breathe",(s>0||f>0)&&!u),u?(t.title="有待确认事项,点击打开助手",t.setAttribute("aria-label","有待确认事项,点击打开助手")):(t.title="景行 AI",t.setAttribute("aria-label","景行 AI")),i&&(i.style.display=u?"none":""),o&&o.classList.toggle("is-visible",u),s>0?(n.textContent=String(s),n.classList.add("is-visible"),n.classList.remove("is-waiting")):f>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(g))==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 f=new URLSearchParams({embed:"1",workflow:t.workflow,host:t.host||"",title:t.title||""});s.src=`${this.agentOrigin}/host/widget?${f.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 u={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},St={channel:l,type:"open-widget",payload:w};this.pendingWidgetMessages=[u,St]}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 f;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;(f=s==null?void 0:s.contentWindow)==null||f.postMessage(n,W(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=W(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)=>{U(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"&&_(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),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 U(e,t){return b(this,null,function*(){const n=q(e,t);if(!n)return;if(G(n.action)){yield Ot(n);return}const i=gt(e,t);i&&(yield _(i))})}function Ot(e){return b(this,null,function*(){yield S(),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 _(e){return b(this,null,function*(){yield S(),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 S(){return b(this,null,function*(){P&&(yield P)})}function At(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 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 S(),T()})},registerPage(i,o){return b(this,arguments,function*(e,t,n={}){yield S(),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 S(),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 S(),ft(e),a.agentOrigin&&R().sendToHub({channel:"agent-host",type:"set-page",pageId:e}),O()})},openAction(e,t){return b(this,null,function*(){if(!q(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="",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,31 +1,31 @@
1
1
  var et = Object.defineProperty, nt = Object.defineProperties;
2
2
  var it = Object.getOwnPropertyDescriptors;
3
- var j = Object.getOwnPropertySymbols;
3
+ var V = Object.getOwnPropertySymbols;
4
4
  var ot = Object.prototype.hasOwnProperty, st = Object.prototype.propertyIsEnumerable;
5
- var W = (e, t, n) => t in e ? et(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n, O = (e, t) => {
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
- ot.call(t, n) && W(e, n, t[n]);
8
- if (j)
9
- for (var n of j(t))
10
- st.call(t, n) && W(e, n, t[n]);
7
+ ot.call(t, n) && z(e, n, t[n]);
8
+ if (V)
9
+ for (var n of V(t))
10
+ st.call(t, n) && z(e, n, t[n]);
11
11
  return e;
12
12
  }, _ = (e, t) => nt(e, it(t));
13
- var h = (e, t, n) => W(e, typeof t != "symbol" ? t + "" : t, n);
14
- var d = (e, t, n) => new Promise((i, o) => {
15
- var s = (u) => {
13
+ var h = (e, t, n) => z(e, typeof t != "symbol" ? t + "" : t, n);
14
+ var f = (e, t, n) => new Promise((i, o) => {
15
+ var s = (c) => {
16
16
  try {
17
- l(n.next(u));
17
+ u(n.next(c));
18
18
  } catch (I) {
19
19
  o(I);
20
20
  }
21
- }, c = (u) => {
21
+ }, l = (c) => {
22
22
  try {
23
- l(n.throw(u));
23
+ u(n.throw(c));
24
24
  } catch (I) {
25
25
  o(I);
26
26
  }
27
- }, l = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(s, c);
28
- l((n = n.apply(e, t)).next());
27
+ }, u = (c) => c.done ? i(c.value) : Promise.resolve(c.value).then(s, l);
28
+ u((n = n.apply(e, t)).next());
29
29
  });
30
30
  const A = "agent-host";
31
31
  function rt(e) {
@@ -38,13 +38,13 @@ function v(e) {
38
38
  return typeof e == "function" ? e() : e;
39
39
  }
40
40
  const w = {}, E = {};
41
- let M = {}, p = null, P = !1, b = null, S = null, N = !1;
41
+ let S = {}, p = null, P = !1, b = null, M = null, N = !1;
42
42
  function Y(e) {
43
- S = e;
43
+ M = e;
44
44
  }
45
45
  function L() {
46
46
  try {
47
- S == null || S();
47
+ M == null || M();
48
48
  } catch (e) {
49
49
  }
50
50
  }
@@ -58,10 +58,10 @@ function F(e) {
58
58
  const i = (o = n.querySelector) == null ? void 0 : o.call(n, 'textarea, input, [contenteditable="true"]');
59
59
  return i instanceof HTMLElement ? i : n;
60
60
  }
61
- function B(e) {
61
+ function W(e) {
62
62
  return !e || typeof e.closest != "function" ? !1 : !!e.closest("#agent-host-launcher-hint");
63
63
  }
64
- function z(e) {
64
+ function B(e) {
65
65
  return !!e.anchor && e.hintPlacement === "anchor";
66
66
  }
67
67
  function at(e, t) {
@@ -69,12 +69,12 @@ function at(e, t) {
69
69
  b && (b = null, L());
70
70
  return;
71
71
  }
72
- if (B(e) || B(t)) return;
72
+ if (W(e) || W(t)) return;
73
73
  const n = w[p] || [];
74
74
  let i = null;
75
75
  if (e instanceof Node)
76
76
  for (const o of n) {
77
- if (!z(o)) continue;
77
+ if (!B(o)) continue;
78
78
  const s = F(o.anchor);
79
79
  if (s && s.contains(e)) {
80
80
  i = o.id;
@@ -87,7 +87,7 @@ function lt(e) {
87
87
  at(e.target);
88
88
  }
89
89
  function ht(e) {
90
- if (B(e.relatedTarget)) return;
90
+ if (W(e.relatedTarget)) return;
91
91
  const t = e.target;
92
92
  if (!(t instanceof Node) || !p) return;
93
93
  const i = (w[p] || []).find((s) => s.id === b);
@@ -129,10 +129,10 @@ function pt(e) {
129
129
  return t;
130
130
  }
131
131
  function gt(e) {
132
- return M = pt(e || {}), O({}, M);
132
+ return S = pt(e || {}), O({}, S);
133
133
  }
134
134
  function D() {
135
- return O({}, M);
135
+ return O({}, S);
136
136
  }
137
137
  function bt(e, t) {
138
138
  const n = String(e || "").trim();
@@ -148,12 +148,12 @@ function bt(e, t) {
148
148
  function wt() {
149
149
  for (const e of Object.keys(w)) delete w[e];
150
150
  for (const e of Object.keys(E)) delete E[e];
151
- M = {}, p = null, P = !1, b = null, L();
151
+ S = {}, p = null, P = !1, b = null, L();
152
152
  }
153
- function yt(e) {
153
+ function xt(e) {
154
154
  e !== p && (P = !1, b = null), p = e, L();
155
155
  }
156
- function xt() {
156
+ function yt() {
157
157
  P = !0;
158
158
  }
159
159
  function X(e) {
@@ -171,7 +171,7 @@ function X(e) {
171
171
  noTools: t.noTools === !0 ? !0 : void 0
172
172
  }));
173
173
  }
174
- function q(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 q(e, t) {
182
182
  };
183
183
  }
184
184
  function mt(e, t) {
185
- const n = q(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,
@@ -211,13 +211,13 @@ function Lt() {
211
211
  if (P || !p) return null;
212
212
  const e = w[p] || [];
213
213
  for (const t of e) {
214
- if (t.enabled && !t.enabled() || z(t) && b !== t.id) continue;
215
- const n = t.hint ? v(t.hint) : `可使用「${t.label}」`, i = z(t) ? "anchor" : "launcher";
214
+ if (t.enabled && !t.enabled() || B(t) && b !== t.id) continue;
215
+ const n = t.hint ? v(t.hint) : `可使用「${t.label}」`, i = B(t) ? "anchor" : "launcher";
216
216
  return { pageId: p, actionId: t.id, hint: n, placement: i };
217
217
  }
218
218
  return null;
219
219
  }
220
- const f = "agent-host-launcher", g = "agent-host-hub-panel-overlay", Ct = "agent-host-hub-iframe", K = "agent-host-widget-overlay", Et = "agent-host-widget-iframe", G = "agent-host-ai-host-styles";
220
+ const d = "agent-host-launcher", g = "agent-host-hub-panel-overlay", Ct = "agent-host-hub-iframe", K = "agent-host-widget-overlay", Et = "agent-host-widget-iframe", G = "agent-host-ai-host-styles";
221
221
  function Pt(e) {
222
222
  return e.replace(/\/$/, "");
223
223
  }
@@ -232,8 +232,8 @@ function Rt(e, t) {
232
232
  const n = $(e), i = $(t);
233
233
  if (n === i) return !0;
234
234
  try {
235
- const o = new URL(n), s = new URL(i), c = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
236
- return o.protocol === s.protocol && o.port === s.port && c.has(o.hostname) && c.has(s.hostname);
235
+ const o = new URL(n), s = new URL(i), l = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
236
+ return o.protocol === s.protocol && o.port === s.port && l.has(o.hostname) && l.has(s.hostname);
237
237
  } catch (o) {
238
238
  return !1;
239
239
  }
@@ -242,7 +242,7 @@ function It() {
242
242
  if (typeof document == "undefined" || document.getElementById(G)) return;
243
243
  const e = document.createElement("style");
244
244
  e.id = G, e.textContent = `
245
- #${f} {
245
+ #${d} {
246
246
  position: fixed;
247
247
  right: 24px;
248
248
  bottom: 24px;
@@ -262,41 +262,77 @@ function It() {
262
262
  box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42);
263
263
  transition: transform 0.15s ease, opacity 0.2s ease, visibility 0.2s ease;
264
264
  }
265
- #${f}:hover { transform: scale(1.05); }
266
- #${f}.is-hidden {
265
+ #${d}:hover { transform: scale(1.05); }
266
+ #${d}.is-hidden {
267
267
  opacity: 0;
268
268
  visibility: hidden;
269
269
  pointer-events: none;
270
270
  transform: scale(0.85);
271
271
  }
272
- #${f}.is-pulse {
272
+ #${d}.is-pulse {
273
273
  animation: agent-host-fab-pulse 2s ease-in-out infinite;
274
274
  }
275
- #${f} .agent-host-launcher-icon {
276
- display: inline-block;
277
- line-height: 1;
278
- transform-origin: center center;
275
+ #${d} .agent-host-launcher-logo {
276
+ position: relative;
277
+ z-index: 1;
278
+ width: 28px;
279
+ height: 28px;
280
+ display: inline-flex;
281
+ align-items: center;
282
+ justify-content: center;
283
+ line-height: 0;
279
284
  }
280
- #${f}.is-breathe .agent-host-launcher-icon {
281
- animation: agent-host-clover-breathe 1.8s ease-in-out infinite;
285
+ #${d} .agent-host-launcher-logo svg {
286
+ width: 100%;
287
+ height: 100%;
288
+ display: block;
289
+ }
290
+ #${d} .agent-host-launcher-orbit {
291
+ display: none;
292
+ position: absolute;
293
+ inset: 6px;
294
+ pointer-events: none;
295
+ z-index: 2;
296
+ }
297
+ #${d}.is-orbiting .agent-host-launcher-orbit {
298
+ display: block;
299
+ animation: agent-host-fab-orbit 2.4s linear infinite;
300
+ }
301
+ #${d} .agent-host-launcher-orbit-dot {
302
+ position: absolute;
303
+ top: 0;
304
+ left: 50%;
305
+ width: 10px;
306
+ height: 10px;
307
+ margin-left: -5px;
308
+ font-size: 10px;
309
+ line-height: 10px;
310
+ color: #fff;
311
+ text-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
282
312
  }
283
- #${f} .agent-host-launcher-bell {
313
+ #${d} .agent-host-launcher-bell {
284
314
  display: none;
285
315
  width: 22px;
286
316
  height: 22px;
287
317
  line-height: 0;
288
318
  transform-origin: top center;
319
+ position: relative;
320
+ z-index: 1;
289
321
  }
290
- #${f} .agent-host-launcher-bell.is-visible {
322
+ #${d} .agent-host-launcher-bell.is-visible {
291
323
  display: inline-block;
292
324
  animation: agent-host-bell-shake 0.85s ease-in-out infinite;
293
325
  }
294
- #${f} .agent-host-launcher-bell svg {
326
+ #${d} .agent-host-launcher-bell svg {
295
327
  width: 100%;
296
328
  height: 100%;
297
329
  display: block;
298
330
  }
299
- #${f} .agent-host-launcher-badge {
331
+ #${d}.is-hitl .agent-host-launcher-logo,
332
+ #${d}.is-hitl .agent-host-launcher-orbit {
333
+ display: none !important;
334
+ }
335
+ #${d} .agent-host-launcher-badge {
300
336
  position: absolute;
301
337
  top: -4px;
302
338
  right: -4px;
@@ -315,8 +351,8 @@ function It() {
315
351
  background: #f59e0b;
316
352
  color: #fff;
317
353
  }
318
- #${f} .agent-host-launcher-badge.is-visible { display: flex; }
319
- #${f} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
354
+ #${d} .agent-host-launcher-badge.is-visible { display: flex; }
355
+ #${d} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
320
356
  #agent-host-launcher-hint {
321
357
  position: fixed;
322
358
  right: 24px;
@@ -472,9 +508,9 @@ function It() {
472
508
  0%, 100% { box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42); }
473
509
  50% { box-shadow: 0 4px 26px rgba(13, 143, 123, 0.62); }
474
510
  }
475
- @keyframes agent-host-clover-breathe {
476
- 0%, 100% { transform: scale(1); }
477
- 50% { transform: scale(1.28); }
511
+ @keyframes agent-host-fab-orbit {
512
+ from { transform: rotate(0deg); }
513
+ to { transform: rotate(360deg); }
478
514
  }
479
515
  @keyframes agent-host-hint-clover {
480
516
  0% { transform: scale(0.88) rotate(0deg); }
@@ -587,13 +623,13 @@ class Ot {
587
623
  </div>`;
588
624
  const i = n.querySelector(".agent-host-hint-text");
589
625
  i && (i.textContent = t.hint);
590
- const o = n.querySelector(".agent-host-hint-use"), s = n.querySelector(".agent-host-hint-dismiss"), c = (l) => l.preventDefault();
591
- o == null || o.addEventListener("mousedown", c), s == null || s.addEventListener("mousedown", c), o == null || o.addEventListener("click", (l) => {
592
- var u;
593
- l.stopPropagation(), (u = this.onHintUse) == null || u.call(this, t.pageId, t.actionId);
594
- }), s == null || s.addEventListener("click", (l) => {
595
- var u;
596
- l.stopPropagation(), (u = this.onHintDismiss) == null || u.call(this);
626
+ const o = n.querySelector(".agent-host-hint-use"), s = n.querySelector(".agent-host-hint-dismiss"), l = (u) => u.preventDefault();
627
+ o == null || o.addEventListener("mousedown", l), s == null || s.addEventListener("mousedown", l), o == null || o.addEventListener("click", (u) => {
628
+ var c;
629
+ u.stopPropagation(), (c = this.onHintUse) == null || c.call(this, t.pageId, t.actionId);
630
+ }), s == null || s.addEventListener("click", (u) => {
631
+ var c;
632
+ u.stopPropagation(), (c = this.onHintDismiss) == null || c.call(this);
597
633
  }), n.classList.add("is-visible"), this.layoutHint(n, t), this.bindHintReposition();
598
634
  }
599
635
  layoutHint(t, n) {
@@ -607,17 +643,17 @@ class Ot {
607
643
  return;
608
644
  }
609
645
  t.classList.add("is-anchored");
610
- const o = 8, s = t.offsetWidth || 320, c = t.offsetHeight || 48;
611
- let l = i.top, u = i.right + o;
612
- u + s > window.innerWidth - 16 && (u = Math.max(16, i.left), l = i.bottom + o), l + c > window.innerHeight - 16 && (l = Math.max(16, i.top - c - o)), l < 16 && (l = 16), u < 16 && (u = 16), t.style.top = `${Math.round(l)}px`, t.style.left = `${Math.round(u)}px`;
646
+ const o = 8, s = t.offsetWidth || 320, l = t.offsetHeight || 48;
647
+ let u = i.top, c = i.right + o;
648
+ c + s > window.innerWidth - 16 && (c = Math.max(16, i.left), u = i.bottom + o), u + l > window.innerHeight - 16 && (u = Math.max(16, i.top - l - o)), u < 16 && (u = 16), c < 16 && (c = 16), t.style.top = `${Math.round(u)}px`, t.style.left = `${Math.round(c)}px`;
613
649
  }
614
650
  collectScrollParents(t) {
615
651
  var o;
616
652
  const n = [];
617
653
  let i = (o = t == null ? void 0 : t.parentElement) != null ? o : null;
618
654
  for (; i; ) {
619
- const s = window.getComputedStyle(i), c = s.overflowY, l = s.overflowX;
620
- /(auto|scroll|overlay)/.test(`${l} ${c}`) && n.push(i), i = i.parentElement;
655
+ const s = window.getComputedStyle(i), l = s.overflowY, u = s.overflowX;
656
+ /(auto|scroll|overlay)/.test(`${u} ${l}`) && n.push(i), i = i.parentElement;
621
657
  }
622
658
  return n;
623
659
  }
@@ -644,9 +680,9 @@ class Ot {
644
680
  }
645
681
  }
646
682
  mountLauncher() {
647
- if (this.hubLauncher || document.getElementById(f)) return;
683
+ if (this.hubLauncher || document.getElementById(d)) return;
648
684
  const t = document.createElement("button");
649
- if (t.id = f, t.type = "button", t.title = "景行 AI", t.setAttribute("aria-label", "景行 AI"), t.innerHTML = '<span class="agent-host-launcher-icon" aria-hidden="true">✦</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="#f59e0b"/><path d="M10 18.5a2 2 0 0 0 4 0" stroke="#f59e0b" 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"))
650
686
  this.hubLauncherHint = document.getElementById("agent-host-launcher-hint");
651
687
  else {
652
688
  const n = document.createElement("div");
@@ -669,12 +705,12 @@ class Ot {
669
705
  applyLauncherVisual() {
670
706
  const t = this.hubLauncher, n = this.hubLauncherBadge;
671
707
  if (!t || !n) return;
672
- const i = t.querySelector(".agent-host-launcher-icon"), o = t.querySelector(".agent-host-launcher-bell"), s = this.lastRunning, c = this.lastWaiting, l = c > 0 && !this.hubPanelOpen;
673
- t.classList.toggle("is-pulse", s > 0), t.classList.toggle("is-breathe", (s > 0 || c > 0) && !l), l ? (t.title = "有待确认事项,点击打开助手", t.setAttribute("aria-label", "有待确认事项,点击打开助手")) : (t.title = "景行 AI", t.setAttribute("aria-label", "景行 AI")), i && (i.style.display = l ? "none" : ""), o && o.classList.toggle("is-visible", l), s > 0 ? (n.textContent = String(s), n.classList.add("is-visible"), n.classList.remove("is-waiting")) : c > 0 ? (n.textContent = "!", n.classList.add("is-visible", "is-waiting")) : (n.textContent = "", n.classList.remove("is-visible", "is-waiting"));
708
+ const i = t.querySelector(".agent-host-launcher-bell"), o = this.lastRunning, s = this.lastWaiting, l = s > 0 && !this.hubPanelOpen;
709
+ t.classList.toggle("is-pulse", o > 0 && !l), t.classList.toggle("is-orbiting", o > 0 && !l), t.classList.toggle("is-hitl", l), l ? (t.title = "有待确认事项,点击打开助手", t.setAttribute("aria-label", "有待确认事项,点击打开助手")) : (t.title = "景行 AI", t.setAttribute("aria-label", "景行 AI")), i && i.classList.toggle("is-visible", l), 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"));
674
710
  }
675
711
  removeHub() {
676
712
  var t, n, i;
677
- (t = document.getElementById(f)) == null || t.remove(), (n = document.getElementById("agent-host-launcher-hint")) == null || n.remove(), (i = document.getElementById(g)) == 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 = [];
713
+ (t = document.getElementById(d)) == null || t.remove(), (n = document.getElementById("agent-host-launcher-hint")) == null || n.remove(), (i = document.getElementById(g)) == 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 = [];
678
714
  }
679
715
  openWidget(t, n, i) {
680
716
  this.closeWidget();
@@ -684,19 +720,19 @@ class Ot {
684
720
  });
685
721
  const s = document.createElement("iframe");
686
722
  s.id = Et, s.title = t.title || t.workflow;
687
- const c = new URLSearchParams({
723
+ const l = new URLSearchParams({
688
724
  embed: "1",
689
725
  workflow: t.workflow,
690
726
  host: t.host || "",
691
727
  title: t.title || ""
692
728
  });
693
- s.src = `${this.agentOrigin}/host/widget?${c.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;
694
- const l = {
729
+ s.src = `${this.agentOrigin}/host/widget?${l.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;
730
+ const u = {
695
731
  channel: A,
696
732
  type: "init",
697
733
  token: n,
698
734
  refreshToken: i
699
- }, u = {
735
+ }, c = {
700
736
  workflow: t.workflow,
701
737
  title: t.title,
702
738
  host: t.host,
@@ -707,9 +743,9 @@ class Ot {
707
743
  }, I = {
708
744
  channel: A,
709
745
  type: "open-widget",
710
- payload: u
746
+ payload: c
711
747
  };
712
- this.pendingWidgetMessages = [l, I];
748
+ this.pendingWidgetMessages = [u, I];
713
749
  }
714
750
  closeWidget() {
715
751
  var t;
@@ -719,14 +755,14 @@ class Ot {
719
755
  this.post("hub", t);
720
756
  }
721
757
  post(t, n) {
722
- var c;
758
+ var l;
723
759
  const i = t === "hub" ? this.hubReady : this.widgetReady, o = t === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages;
724
760
  if (!i) {
725
761
  o.push(n);
726
762
  return;
727
763
  }
728
764
  const s = t === "hub" ? this.hubIframe : this.widgetIframe;
729
- (c = s == null ? void 0 : s.contentWindow) == null || c.postMessage(n, $(this.agentOrigin));
765
+ (l = s == null ? void 0 : s.contentWindow) == null || l.postMessage(n, $(this.agentOrigin));
730
766
  }
731
767
  flush(t) {
732
768
  const n = t === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages, i = t === "hub" ? this.hubIframe : this.widgetIframe;
@@ -738,7 +774,7 @@ class Ot {
738
774
  }
739
775
  }
740
776
  }
741
- let a = {}, r = null, y = "", R = "", x = null;
777
+ let a = {}, r = null, x = "", R = "", y = null;
742
778
  function At() {
743
779
  const e = (a.agentOrigin || "").replace(/\/$/, "");
744
780
  if (!e)
@@ -749,16 +785,16 @@ function At() {
749
785
  }
750
786
  function Q(e) {
751
787
  var t;
752
- e.agent_web_origin && (a.agentOrigin = e.agent_web_origin.replace(/\/$/, "")), e.agent_token && (y = e.agent_token), e.refresh_token && (R = e.refresh_token), (t = a.onBootstrap) == null || t.call(a, e);
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);
753
789
  }
754
790
  function T() {
755
- return d(this, null, function* () {
791
+ return f(this, null, function* () {
756
792
  if (a.getToken)
757
- return y = yield a.getToken(), y;
758
- if (y) return y;
793
+ return x = yield a.getToken(), x;
794
+ if (x) return x;
759
795
  if (a.bootstrap) {
760
796
  const e = yield a.bootstrap();
761
- if (Q(e), y) return y;
797
+ if (Q(e), x) return x;
762
798
  }
763
799
  throw new Error("未连接 Agent:请配置 bootstrap 或 getToken");
764
800
  });
@@ -772,12 +808,12 @@ function H() {
772
808
  }
773
809
  function m() {
774
810
  const e = At();
775
- return r || (Y(H), r = new Ot(e, St, {
811
+ return r || (Y(H), r = new Ot(e, Mt, {
776
812
  onHintUse: (t, n) => {
777
- U(t, n);
813
+ j(t, n);
778
814
  },
779
815
  onHintDismiss: () => {
780
- xt(), H();
816
+ yt(), H();
781
817
  }
782
818
  }), a.showHub !== !1 && r.mountHub()), r;
783
819
  }
@@ -797,7 +833,7 @@ function Tt() {
797
833
  }), H();
798
834
  }
799
835
  }
800
- function St(e) {
836
+ function Mt(e) {
801
837
  var t;
802
838
  if (e.type === "ready" && e.surface === "hub" && T().then((n) => {
803
839
  r == null || r.sendToHub({
@@ -836,10 +872,10 @@ function St(e) {
836
872
  apply: e.apply
837
873
  }), r == null || r.closeWidget();
838
874
  }
839
- e.type === "close" && (r == null || r.closeWidget()), e.type === "open-widget" && V(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" && Mt();
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();
840
876
  }
841
- function Mt() {
842
- return d(this, null, function* () {
877
+ function St() {
878
+ return f(this, null, function* () {
843
879
  if (!r || !a.agentOrigin) return;
844
880
  let e = {};
845
881
  try {
@@ -855,20 +891,20 @@ function Mt() {
855
891
  });
856
892
  });
857
893
  }
858
- function U(e, t) {
859
- return d(this, null, function* () {
860
- const n = q(e, t);
894
+ function j(e, t) {
895
+ return f(this, null, function* () {
896
+ const n = U(e, t);
861
897
  if (!n) return;
862
898
  if (J(n.action)) {
863
899
  yield $t(n);
864
900
  return;
865
901
  }
866
902
  const i = mt(e, t);
867
- i && (yield V(i));
903
+ i && (yield q(i));
868
904
  });
869
905
  }
870
906
  function $t(e) {
871
- return d(this, null, function* () {
907
+ return f(this, null, function* () {
872
908
  yield C(), e.action.workflow && !e.action.skill && a.prepareOpenWidget && (yield a.prepareOpenWidget());
873
909
  const t = yield T(), n = m();
874
910
  n.openHubPanel(), n.sendToHub({
@@ -889,8 +925,8 @@ function $t(e) {
889
925
  });
890
926
  });
891
927
  }
892
- function V(e) {
893
- return d(this, null, function* () {
928
+ function q(e) {
929
+ return f(this, null, function* () {
894
930
  yield C(), a.prepareOpenWidget && (yield a.prepareOpenWidget());
895
931
  const t = m(), n = yield T();
896
932
  t.openWidget(
@@ -909,12 +945,12 @@ function V(e) {
909
945
  });
910
946
  }
911
947
  function C() {
912
- return d(this, null, function* () {
913
- x && (yield x);
948
+ return f(this, null, function* () {
949
+ y && (yield y);
914
950
  });
915
951
  }
916
- function Wt(e) {
917
- return d(this, null, function* () {
952
+ function zt(e) {
953
+ return f(this, null, function* () {
918
954
  if (a = O({ showHub: !0 }, e), a.bootstrap) {
919
955
  const t = yield a.bootstrap();
920
956
  Q(t);
@@ -933,21 +969,21 @@ function Wt(e) {
933
969
  }
934
970
  });
935
971
  }
936
- const Bt = {
972
+ const Wt = {
937
973
  init(e) {
938
- return d(this, null, function* () {
939
- x && (yield x), x = Wt(e).finally(() => {
940
- x = null;
941
- }), yield x;
974
+ return f(this, null, function* () {
975
+ y && (yield y), y = zt(e).finally(() => {
976
+ y = null;
977
+ }), yield y;
942
978
  });
943
979
  },
944
980
  getToken() {
945
- return d(this, null, function* () {
981
+ return f(this, null, function* () {
946
982
  return yield C(), T();
947
983
  });
948
984
  },
949
985
  registerPage(i, o) {
950
- return d(this, arguments, function* (e, t, n = {}) {
986
+ return f(this, arguments, function* (e, t, n = {}) {
951
987
  yield C(), dt(e, t, n), a.agentOrigin && m().sendToHub({
952
988
  channel: "agent-host",
953
989
  type: "register-page",
@@ -961,24 +997,24 @@ const Bt = {
961
997
  return D();
962
998
  },
963
999
  unregisterPage(e) {
964
- return d(this, null, function* () {
1000
+ return f(this, null, function* () {
965
1001
  yield C(), ft(e), a.agentOrigin && (m().sendToHub({ channel: "agent-host", type: "unregister-page", pageId: e }), m().sendToHub({ channel: "agent-host", type: "set-page", pageId: null })), H();
966
1002
  });
967
1003
  },
968
1004
  setCurrentPage(e) {
969
- return d(this, null, function* () {
970
- yield C(), yt(e), a.agentOrigin && m().sendToHub({ channel: "agent-host", type: "set-page", pageId: e }), H();
1005
+ return f(this, null, function* () {
1006
+ yield C(), xt(e), a.agentOrigin && m().sendToHub({ channel: "agent-host", type: "set-page", pageId: e }), H();
971
1007
  });
972
1008
  },
973
1009
  openAction(e, t) {
974
- return d(this, null, function* () {
975
- if (!q(e, t)) throw new Error("当前操作不可用");
976
- yield U(e, t);
1010
+ return f(this, null, function* () {
1011
+ if (!U(e, t)) throw new Error("当前操作不可用");
1012
+ yield j(e, t);
977
1013
  });
978
1014
  },
979
1015
  openWorkflow(n) {
980
- return d(this, arguments, function* (e, t = {}) {
981
- yield V(_(O({
1016
+ return f(this, arguments, function* (e, t = {}) {
1017
+ yield q(_(O({
982
1018
  workflow: e
983
1019
  }, t), {
984
1020
  host: t.host || a.host,
@@ -993,12 +1029,12 @@ const Bt = {
993
1029
  return !0;
994
1030
  },
995
1031
  destroy() {
996
- r == null || r.destroy(), r = null, y = "", R = "", a = {}, x = null, Y(null), wt();
1032
+ r == null || r.destroy(), r = null, x = "", R = "", a = {}, y = null, Y(null), wt();
997
1033
  }
998
1034
  };
999
- typeof window != "undefined" && (window.AgentHost = Bt);
1035
+ typeof window != "undefined" && (window.AgentHost = Wt);
1000
1036
  export {
1001
1037
  A as AGENT_HOST_MSG,
1002
- Bt as AgentHost,
1038
+ Wt as AgentHost,
1003
1039
  rt as isAgentHostMessage
1004
1040
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@_daniel_jiang/ai-host",
3
- "version": "0.1.0",
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
@@ -83,13 +83,43 @@ function ensureHostSdkStyles() {
83
83
  #${HUB_LAUNCHER_ID}.is-pulse {
84
84
  animation: agent-host-fab-pulse 2s ease-in-out infinite;
85
85
  }
86
- #${HUB_LAUNCHER_ID} .agent-host-launcher-icon {
87
- display: inline-block;
88
- line-height: 1;
89
- transform-origin: center center;
86
+ #${HUB_LAUNCHER_ID} .agent-host-launcher-logo {
87
+ position: relative;
88
+ z-index: 1;
89
+ width: 28px;
90
+ height: 28px;
91
+ display: inline-flex;
92
+ align-items: center;
93
+ justify-content: center;
94
+ line-height: 0;
95
+ }
96
+ #${HUB_LAUNCHER_ID} .agent-host-launcher-logo svg {
97
+ width: 100%;
98
+ height: 100%;
99
+ display: block;
100
+ }
101
+ #${HUB_LAUNCHER_ID} .agent-host-launcher-orbit {
102
+ display: none;
103
+ position: absolute;
104
+ inset: 6px;
105
+ pointer-events: none;
106
+ z-index: 2;
90
107
  }
91
- #${HUB_LAUNCHER_ID}.is-breathe .agent-host-launcher-icon {
92
- animation: agent-host-clover-breathe 1.8s ease-in-out infinite;
108
+ #${HUB_LAUNCHER_ID}.is-orbiting .agent-host-launcher-orbit {
109
+ display: block;
110
+ animation: agent-host-fab-orbit 2.4s linear infinite;
111
+ }
112
+ #${HUB_LAUNCHER_ID} .agent-host-launcher-orbit-dot {
113
+ position: absolute;
114
+ top: 0;
115
+ left: 50%;
116
+ width: 10px;
117
+ height: 10px;
118
+ margin-left: -5px;
119
+ font-size: 10px;
120
+ line-height: 10px;
121
+ color: #fff;
122
+ text-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
93
123
  }
94
124
  #${HUB_LAUNCHER_ID} .agent-host-launcher-bell {
95
125
  display: none;
@@ -97,6 +127,8 @@ function ensureHostSdkStyles() {
97
127
  height: 22px;
98
128
  line-height: 0;
99
129
  transform-origin: top center;
130
+ position: relative;
131
+ z-index: 1;
100
132
  }
101
133
  #${HUB_LAUNCHER_ID} .agent-host-launcher-bell.is-visible {
102
134
  display: inline-block;
@@ -107,6 +139,10 @@ function ensureHostSdkStyles() {
107
139
  height: 100%;
108
140
  display: block;
109
141
  }
142
+ #${HUB_LAUNCHER_ID}.is-hitl .agent-host-launcher-logo,
143
+ #${HUB_LAUNCHER_ID}.is-hitl .agent-host-launcher-orbit {
144
+ display: none !important;
145
+ }
110
146
  #${HUB_LAUNCHER_ID} .agent-host-launcher-badge {
111
147
  position: absolute;
112
148
  top: -4px;
@@ -283,9 +319,9 @@ function ensureHostSdkStyles() {
283
319
  0%, 100% { box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42); }
284
320
  50% { box-shadow: 0 4px 26px rgba(13, 143, 123, 0.62); }
285
321
  }
286
- @keyframes agent-host-clover-breathe {
287
- 0%, 100% { transform: scale(1); }
288
- 50% { transform: scale(1.28); }
322
+ @keyframes agent-host-fab-orbit {
323
+ from { transform: rotate(0deg); }
324
+ to { transform: rotate(360deg); }
289
325
  }
290
326
  @keyframes agent-host-hint-clover {
291
327
  0% { transform: scale(0.88) rotate(0deg); }
@@ -528,11 +564,15 @@ export class IframeBridge {
528
564
  btn.title = '景行 AI'
529
565
  btn.setAttribute('aria-label', '景行 AI')
530
566
  btn.innerHTML =
531
- '<span class="agent-host-launcher-icon" aria-hidden="true">✦</span>' +
567
+ '<span class="agent-host-launcher-logo" aria-hidden="true">' +
568
+ '<svg viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">' +
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"/>' +
570
+ '</svg></span>' +
571
+ '<span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span>' +
532
572
  '<span class="agent-host-launcher-bell" aria-hidden="true">' +
533
573
  '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">' +
534
- '<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="#f59e0b"/>' +
535
- '<path d="M10 18.5a2 2 0 0 0 4 0" stroke="#f59e0b" stroke-width="1.8" stroke-linecap="round"/>' +
574
+ '<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"/>' +
575
+ '<path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/>' +
536
576
  '</svg></span>' +
537
577
  '<span class="agent-host-launcher-badge"></span>'
538
578
  btn.addEventListener('click', () => this.openHubPanel())
@@ -586,16 +626,15 @@ export class IframeBridge {
586
626
  const btn = this.hubLauncher
587
627
  const badge = this.hubLauncherBadge
588
628
  if (!btn || !badge) return
589
- const icon = btn.querySelector('.agent-host-launcher-icon') as HTMLElement | null
590
629
  const bell = btn.querySelector('.agent-host-launcher-bell') as HTMLElement | null
591
630
  const running = this.lastRunning
592
631
  const waiting = this.lastWaiting
593
- // 抽屉关闭且有待确认:中间换成橙色抖动铃铛(底色不变)
632
+ // 抽屉关闭且有待确认:中间换成白色抖动铃铛(底色不变)
594
633
  const hitlAlert = waiting > 0 && !this.hubPanelOpen
595
634
 
596
- btn.classList.toggle('is-pulse', running > 0)
597
- // 有进行中/待确认任务且显示四叶草时:图标变大呼吸
598
- btn.classList.toggle('is-breathe', (running > 0 || waiting > 0) && !hitlAlert)
635
+ btn.classList.toggle('is-pulse', running > 0 && !hitlAlert)
636
+ btn.classList.toggle('is-orbiting', running > 0 && !hitlAlert)
637
+ btn.classList.toggle('is-hitl', hitlAlert)
599
638
  if (hitlAlert) {
600
639
  btn.title = '有待确认事项,点击打开助手'
601
640
  btn.setAttribute('aria-label', '有待确认事项,点击打开助手')
@@ -603,7 +642,6 @@ export class IframeBridge {
603
642
  btn.title = '景行 AI'
604
643
  btn.setAttribute('aria-label', '景行 AI')
605
644
  }
606
- if (icon) icon.style.display = hitlAlert ? 'none' : ''
607
645
  if (bell) bell.classList.toggle('is-visible', hitlAlert)
608
646
 
609
647
  if (running > 0) {