@_daniel_jiang/ai-host 0.1.0 → 0.1.1
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 +57 -21
- package/dist/ai-host.mjs +161 -125
- package/package.json +1 -1
- package/src/iframe.ts +57 -18
package/dist/ai-host.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
#${
|
|
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=`
|
|
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
|
-
#${
|
|
23
|
-
#${
|
|
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
|
-
#${
|
|
29
|
+
#${f}.is-pulse {
|
|
30
30
|
animation: agent-host-fab-pulse 2s ease-in-out infinite;
|
|
31
31
|
}
|
|
32
|
-
#${
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
#${
|
|
38
|
-
|
|
42
|
+
#${f} .agent-host-launcher-logo svg {
|
|
43
|
+
width: 100%;
|
|
44
|
+
height: 100%;
|
|
45
|
+
display: block;
|
|
39
46
|
}
|
|
40
|
-
#${
|
|
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
|
-
#${
|
|
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
|
-
#${
|
|
83
|
+
#${f} .agent-host-launcher-bell svg {
|
|
52
84
|
width: 100%;
|
|
53
85
|
height: 100%;
|
|
54
86
|
display: block;
|
|
55
87
|
}
|
|
56
|
-
#${
|
|
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
|
-
#${
|
|
76
|
-
#${
|
|
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-
|
|
233
|
-
|
|
234
|
-
|
|
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="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||{});
|
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
|
|
3
|
+
var q = Object.getOwnPropertySymbols;
|
|
4
4
|
var ot = Object.prototype.hasOwnProperty, st = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var
|
|
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) &&
|
|
8
|
-
if (
|
|
9
|
-
for (var n of
|
|
10
|
-
st.call(t, n) &&
|
|
7
|
+
ot.call(t, n) && z(e, n, t[n]);
|
|
8
|
+
if (q)
|
|
9
|
+
for (var n of q(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) =>
|
|
14
|
-
var
|
|
15
|
-
var s = (
|
|
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
|
-
|
|
17
|
+
u(n.next(c));
|
|
18
18
|
} catch (I) {
|
|
19
19
|
o(I);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, l = (c) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
23
|
+
u(n.throw(c));
|
|
24
24
|
} catch (I) {
|
|
25
25
|
o(I);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
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
|
|
41
|
+
let S = {}, p = null, P = !1, b = null, T = null, N = !1;
|
|
42
42
|
function Y(e) {
|
|
43
|
-
|
|
43
|
+
T = e;
|
|
44
44
|
}
|
|
45
45
|
function L() {
|
|
46
46
|
try {
|
|
47
|
-
|
|
47
|
+
T == null || T();
|
|
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
|
|
61
|
+
function W(e) {
|
|
62
62
|
return !e || typeof e.closest != "function" ? !1 : !!e.closest("#agent-host-launcher-hint");
|
|
63
63
|
}
|
|
64
|
-
function
|
|
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 (
|
|
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 (!
|
|
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 (
|
|
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
|
|
132
|
+
return S = pt(e || {}), O({}, S);
|
|
133
133
|
}
|
|
134
134
|
function D() {
|
|
135
|
-
return O({},
|
|
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
|
-
|
|
151
|
+
S = {}, p = null, P = !1, b = null, L();
|
|
152
152
|
}
|
|
153
|
-
function
|
|
153
|
+
function xt(e) {
|
|
154
154
|
e !== p && (P = !1, b = null), p = e, L();
|
|
155
155
|
}
|
|
156
|
-
function
|
|
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
|
|
174
|
+
function V(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 =
|
|
185
|
+
const n = V(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() ||
|
|
215
|
-
const n = t.hint ? v(t.hint) : `可使用「${t.label}」`, i =
|
|
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
|
|
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),
|
|
236
|
-
return o.protocol === s.protocol && o.port === s.port &&
|
|
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
|
-
#${
|
|
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
|
-
#${
|
|
266
|
-
#${
|
|
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
|
-
#${
|
|
272
|
+
#${d}.is-pulse {
|
|
273
273
|
animation: agent-host-fab-pulse 2s ease-in-out infinite;
|
|
274
274
|
}
|
|
275
|
-
#${
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
#${
|
|
281
|
-
|
|
285
|
+
#${d} .agent-host-launcher-logo svg {
|
|
286
|
+
width: 100%;
|
|
287
|
+
height: 100%;
|
|
288
|
+
display: block;
|
|
282
289
|
}
|
|
283
|
-
#${
|
|
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);
|
|
312
|
+
}
|
|
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
|
-
#${
|
|
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
|
-
#${
|
|
326
|
+
#${d} .agent-host-launcher-bell svg {
|
|
295
327
|
width: 100%;
|
|
296
328
|
height: 100%;
|
|
297
329
|
display: block;
|
|
298
330
|
}
|
|
299
|
-
#${
|
|
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
|
-
#${
|
|
319
|
-
#${
|
|
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-
|
|
476
|
-
|
|
477
|
-
|
|
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"),
|
|
591
|
-
o == null || o.addEventListener("mousedown",
|
|
592
|
-
var
|
|
593
|
-
|
|
594
|
-
}), s == null || s.addEventListener("click", (
|
|
595
|
-
var
|
|
596
|
-
|
|
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,
|
|
611
|
-
let
|
|
612
|
-
|
|
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),
|
|
620
|
-
/(auto|scroll|overlay)/.test(`${
|
|
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(
|
|
683
|
+
if (this.hubLauncher || document.getElementById(d)) return;
|
|
648
684
|
const t = document.createElement("button");
|
|
649
|
-
if (t.id =
|
|
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"))
|
|
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-
|
|
673
|
-
t.classList.toggle("is-pulse",
|
|
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(
|
|
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
|
|
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?${
|
|
694
|
-
const
|
|
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
|
-
},
|
|
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:
|
|
746
|
+
payload: c
|
|
711
747
|
};
|
|
712
|
-
this.pendingWidgetMessages = [
|
|
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
|
|
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
|
-
(
|
|
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,
|
|
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 && (
|
|
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
|
-
function
|
|
755
|
-
return
|
|
790
|
+
function M() {
|
|
791
|
+
return f(this, null, function* () {
|
|
756
792
|
if (a.getToken)
|
|
757
|
-
return
|
|
758
|
-
if (
|
|
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),
|
|
797
|
+
if (Q(e), x) return x;
|
|
762
798
|
}
|
|
763
799
|
throw new Error("未连接 Agent:请配置 bootstrap 或 getToken");
|
|
764
800
|
});
|
|
@@ -772,16 +808,16 @@ function H() {
|
|
|
772
808
|
}
|
|
773
809
|
function m() {
|
|
774
810
|
const e = At();
|
|
775
|
-
return r || (Y(H), r = new Ot(e,
|
|
811
|
+
return r || (Y(H), r = new Ot(e, Tt, {
|
|
776
812
|
onHintUse: (t, n) => {
|
|
777
813
|
U(t, n);
|
|
778
814
|
},
|
|
779
815
|
onHintDismiss: () => {
|
|
780
|
-
|
|
816
|
+
yt(), H();
|
|
781
817
|
}
|
|
782
818
|
}), a.showHub !== !1 && r.mountHub()), r;
|
|
783
819
|
}
|
|
784
|
-
function
|
|
820
|
+
function Mt() {
|
|
785
821
|
if (!(!r || !a.agentOrigin)) {
|
|
786
822
|
for (const { pageId: e, actions: t } of Ht())
|
|
787
823
|
r.sendToHub({
|
|
@@ -797,15 +833,15 @@ function Tt() {
|
|
|
797
833
|
}), H();
|
|
798
834
|
}
|
|
799
835
|
}
|
|
800
|
-
function
|
|
836
|
+
function Tt(e) {
|
|
801
837
|
var t;
|
|
802
|
-
if (e.type === "ready" && e.surface === "hub" &&
|
|
838
|
+
if (e.type === "ready" && e.surface === "hub" && M().then((n) => {
|
|
803
839
|
r == null || r.sendToHub({
|
|
804
840
|
channel: "agent-host",
|
|
805
841
|
type: "init",
|
|
806
842
|
token: n,
|
|
807
843
|
refreshToken: R || void 0
|
|
808
|
-
}),
|
|
844
|
+
}), Mt();
|
|
809
845
|
}).catch(() => {
|
|
810
846
|
}), e.type === "started" && (r == null || r.closeWidget(), r == null || r.openHubPanel(), r == null || r.sendToHub({
|
|
811
847
|
channel: "agent-host",
|
|
@@ -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" &&
|
|
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();
|
|
840
876
|
}
|
|
841
|
-
function
|
|
842
|
-
return
|
|
877
|
+
function St() {
|
|
878
|
+
return f(this, null, function* () {
|
|
843
879
|
if (!r || !a.agentOrigin) return;
|
|
844
880
|
let e = {};
|
|
845
881
|
try {
|
|
@@ -856,21 +892,21 @@ function Mt() {
|
|
|
856
892
|
});
|
|
857
893
|
}
|
|
858
894
|
function U(e, t) {
|
|
859
|
-
return
|
|
860
|
-
const n =
|
|
895
|
+
return f(this, null, function* () {
|
|
896
|
+
const n = V(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
|
|
903
|
+
i && (yield j(i));
|
|
868
904
|
});
|
|
869
905
|
}
|
|
870
906
|
function $t(e) {
|
|
871
|
-
return
|
|
907
|
+
return f(this, null, function* () {
|
|
872
908
|
yield C(), e.action.workflow && !e.action.skill && a.prepareOpenWidget && (yield a.prepareOpenWidget());
|
|
873
|
-
const t = yield
|
|
909
|
+
const t = yield M(), n = m();
|
|
874
910
|
n.openHubPanel(), n.sendToHub({
|
|
875
911
|
channel: "agent-host",
|
|
876
912
|
type: "init",
|
|
@@ -889,10 +925,10 @@ function $t(e) {
|
|
|
889
925
|
});
|
|
890
926
|
});
|
|
891
927
|
}
|
|
892
|
-
function
|
|
893
|
-
return
|
|
928
|
+
function j(e) {
|
|
929
|
+
return f(this, null, function* () {
|
|
894
930
|
yield C(), a.prepareOpenWidget && (yield a.prepareOpenWidget());
|
|
895
|
-
const t = m(), n = yield
|
|
931
|
+
const t = m(), n = yield M();
|
|
896
932
|
t.openWidget(
|
|
897
933
|
{
|
|
898
934
|
workflow: e.workflow,
|
|
@@ -909,12 +945,12 @@ function V(e) {
|
|
|
909
945
|
});
|
|
910
946
|
}
|
|
911
947
|
function C() {
|
|
912
|
-
return
|
|
913
|
-
|
|
948
|
+
return f(this, null, function* () {
|
|
949
|
+
y && (yield y);
|
|
914
950
|
});
|
|
915
951
|
}
|
|
916
|
-
function
|
|
917
|
-
return
|
|
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);
|
|
@@ -922,7 +958,7 @@ function Wt(e) {
|
|
|
922
958
|
if (a.agentOrigin && a.showHub !== !1 && typeof document != "undefined")
|
|
923
959
|
try {
|
|
924
960
|
m();
|
|
925
|
-
const t = yield
|
|
961
|
+
const t = yield M();
|
|
926
962
|
r == null || r.sendToHub({
|
|
927
963
|
channel: "agent-host",
|
|
928
964
|
type: "init",
|
|
@@ -933,21 +969,21 @@ function Wt(e) {
|
|
|
933
969
|
}
|
|
934
970
|
});
|
|
935
971
|
}
|
|
936
|
-
const
|
|
972
|
+
const Wt = {
|
|
937
973
|
init(e) {
|
|
938
|
-
return
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
}), yield
|
|
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
|
|
946
|
-
return yield C(),
|
|
981
|
+
return f(this, null, function* () {
|
|
982
|
+
return yield C(), M();
|
|
947
983
|
});
|
|
948
984
|
},
|
|
949
985
|
registerPage(i, o) {
|
|
950
|
-
return
|
|
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
|
|
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
|
|
970
|
-
yield C(),
|
|
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
|
|
975
|
-
if (!
|
|
1010
|
+
return f(this, null, function* () {
|
|
1011
|
+
if (!V(e, t)) throw new Error("当前操作不可用");
|
|
976
1012
|
yield U(e, t);
|
|
977
1013
|
});
|
|
978
1014
|
},
|
|
979
1015
|
openWorkflow(n) {
|
|
980
|
-
return
|
|
981
|
-
yield
|
|
1016
|
+
return f(this, arguments, function* (e, t = {}) {
|
|
1017
|
+
yield j(_(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,
|
|
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 =
|
|
1035
|
+
typeof window != "undefined" && (window.AgentHost = Wt);
|
|
1000
1036
|
export {
|
|
1001
1037
|
A as AGENT_HOST_MSG,
|
|
1002
|
-
|
|
1038
|
+
Wt as AgentHost,
|
|
1003
1039
|
rt as isAgentHostMessage
|
|
1004
1040
|
};
|
package/package.json
CHANGED
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-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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-
|
|
92
|
-
|
|
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-
|
|
287
|
-
|
|
288
|
-
|
|
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,16 @@ 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-
|
|
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="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"/>' +
|
|
571
|
+
'</svg></span>' +
|
|
572
|
+
'<span class="agent-host-launcher-orbit" aria-hidden="true"><span class="agent-host-launcher-orbit-dot">✦</span></span>' +
|
|
532
573
|
'<span class="agent-host-launcher-bell" aria-hidden="true">' +
|
|
533
574
|
'<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="#
|
|
535
|
-
'<path d="M10 18.5a2 2 0 0 0 4 0" stroke="#
|
|
575
|
+
'<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"/>' +
|
|
576
|
+
'<path d="M10 18.5a2 2 0 0 0 4 0" stroke="#fff" stroke-width="1.8" stroke-linecap="round"/>' +
|
|
536
577
|
'</svg></span>' +
|
|
537
578
|
'<span class="agent-host-launcher-badge"></span>'
|
|
538
579
|
btn.addEventListener('click', () => this.openHubPanel())
|
|
@@ -586,16 +627,15 @@ export class IframeBridge {
|
|
|
586
627
|
const btn = this.hubLauncher
|
|
587
628
|
const badge = this.hubLauncherBadge
|
|
588
629
|
if (!btn || !badge) return
|
|
589
|
-
const icon = btn.querySelector('.agent-host-launcher-icon') as HTMLElement | null
|
|
590
630
|
const bell = btn.querySelector('.agent-host-launcher-bell') as HTMLElement | null
|
|
591
631
|
const running = this.lastRunning
|
|
592
632
|
const waiting = this.lastWaiting
|
|
593
|
-
//
|
|
633
|
+
// 抽屉关闭且有待确认:中间换成白色抖动铃铛(底色不变)
|
|
594
634
|
const hitlAlert = waiting > 0 && !this.hubPanelOpen
|
|
595
635
|
|
|
596
|
-
btn.classList.toggle('is-pulse', running > 0)
|
|
597
|
-
|
|
598
|
-
btn.classList.toggle('is-
|
|
636
|
+
btn.classList.toggle('is-pulse', running > 0 && !hitlAlert)
|
|
637
|
+
btn.classList.toggle('is-orbiting', running > 0 && !hitlAlert)
|
|
638
|
+
btn.classList.toggle('is-hitl', hitlAlert)
|
|
599
639
|
if (hitlAlert) {
|
|
600
640
|
btn.title = '有待确认事项,点击打开助手'
|
|
601
641
|
btn.setAttribute('aria-label', '有待确认事项,点击打开助手')
|
|
@@ -603,7 +643,6 @@ export class IframeBridge {
|
|
|
603
643
|
btn.title = '景行 AI'
|
|
604
644
|
btn.setAttribute('aria-label', '景行 AI')
|
|
605
645
|
}
|
|
606
|
-
if (icon) icon.style.display = hitlAlert ? 'none' : ''
|
|
607
646
|
if (bell) bell.classList.toggle('is-visible', hitlAlert)
|
|
608
647
|
|
|
609
648
|
if (running > 0) {
|