@_daniel_jiang/ai-host 0.1.0

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.
@@ -0,0 +1,1004 @@
1
+ var et = Object.defineProperty, nt = Object.defineProperties;
2
+ var it = Object.getOwnPropertyDescriptors;
3
+ var j = Object.getOwnPropertySymbols;
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) => {
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]);
11
+ return e;
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) => {
16
+ try {
17
+ l(n.next(u));
18
+ } catch (I) {
19
+ o(I);
20
+ }
21
+ }, c = (u) => {
22
+ try {
23
+ l(n.throw(u));
24
+ } catch (I) {
25
+ o(I);
26
+ }
27
+ }, l = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(s, c);
28
+ l((n = n.apply(e, t)).next());
29
+ });
30
+ const A = "agent-host";
31
+ function rt(e) {
32
+ return typeof e == "object" && e !== null && e.channel === A && typeof e.type == "string";
33
+ }
34
+ function k(e) {
35
+ return e == null ? e : JSON.parse(JSON.stringify(e));
36
+ }
37
+ function v(e) {
38
+ return typeof e == "function" ? e() : e;
39
+ }
40
+ const w = {}, E = {};
41
+ let M = {}, p = null, P = !1, b = null, S = null, N = !1;
42
+ function Y(e) {
43
+ S = e;
44
+ }
45
+ function L() {
46
+ try {
47
+ S == null || S();
48
+ } catch (e) {
49
+ }
50
+ }
51
+ function F(e) {
52
+ var o;
53
+ if (!e) return null;
54
+ const t = typeof e == "function" ? e() : e;
55
+ if (!t) return null;
56
+ let n = null;
57
+ if (t instanceof Element ? n = t : typeof t == "object" && t.$el instanceof Element && (n = t.$el), !n) return null;
58
+ const i = (o = n.querySelector) == null ? void 0 : o.call(n, 'textarea, input, [contenteditable="true"]');
59
+ return i instanceof HTMLElement ? i : n;
60
+ }
61
+ function B(e) {
62
+ return !e || typeof e.closest != "function" ? !1 : !!e.closest("#agent-host-launcher-hint");
63
+ }
64
+ function z(e) {
65
+ return !!e.anchor && e.hintPlacement === "anchor";
66
+ }
67
+ function at(e, t) {
68
+ if (!p) {
69
+ b && (b = null, L());
70
+ return;
71
+ }
72
+ if (B(e) || B(t)) return;
73
+ const n = w[p] || [];
74
+ let i = null;
75
+ if (e instanceof Node)
76
+ for (const o of n) {
77
+ if (!z(o)) continue;
78
+ const s = F(o.anchor);
79
+ if (s && s.contains(e)) {
80
+ i = o.id;
81
+ break;
82
+ }
83
+ }
84
+ i !== b && (b = i, L());
85
+ }
86
+ function lt(e) {
87
+ at(e.target);
88
+ }
89
+ function ht(e) {
90
+ if (B(e.relatedTarget)) return;
91
+ const t = e.target;
92
+ if (!(t instanceof Node) || !p) return;
93
+ const i = (w[p] || []).find((s) => s.id === b);
94
+ if (!i) return;
95
+ const o = F(i.anchor);
96
+ o && o.contains(t) && !o.contains(e.relatedTarget) && (b = null, L());
97
+ }
98
+ function ct() {
99
+ N || typeof document == "undefined" || (document.addEventListener("focusin", lt, !0), document.addEventListener("focusout", ht, !0), N = !0);
100
+ }
101
+ function ut(e, t) {
102
+ const n = (t || "").trim();
103
+ if (n) return n;
104
+ for (const i of e) {
105
+ if (!i.hostContext) continue;
106
+ const o = v(i.hostContext), s = o && typeof o == "object" ? String(o.refresh || "").trim() : "";
107
+ if (s) return s;
108
+ }
109
+ }
110
+ function J(e) {
111
+ return ((e == null ? void 0 : e.kind) || "widget") === "direct";
112
+ }
113
+ function dt(e, t, n = {}) {
114
+ ct();
115
+ const i = e !== p;
116
+ i && (P = !1, b = null), w[e] = t, p = e, !i && t.some((s) => !s.enabled || s.enabled()) && (P = !1);
117
+ const o = ut(t, n.refreshKey);
118
+ o && typeof n.onRefresh == "function" ? E[e] = { refreshKey: o, onRefresh: n.onRefresh } : delete E[e], L();
119
+ }
120
+ function ft(e) {
121
+ delete w[e], delete E[e], p === e && (p = null, b = null), L();
122
+ }
123
+ function pt(e) {
124
+ const t = k(e || {});
125
+ for (const n of Object.keys(t)) {
126
+ const i = t[n];
127
+ (i == null || typeof i == "string" && !i.trim()) && delete t[n];
128
+ }
129
+ return t;
130
+ }
131
+ function gt(e) {
132
+ return M = pt(e || {}), O({}, M);
133
+ }
134
+ function D() {
135
+ return O({}, M);
136
+ }
137
+ function bt(e, t) {
138
+ const n = String(e || "").trim();
139
+ if (n) {
140
+ for (const i of Object.values(E))
141
+ if (i.refreshKey === n)
142
+ try {
143
+ i.onRefresh(t);
144
+ } catch (o) {
145
+ }
146
+ }
147
+ }
148
+ function wt() {
149
+ for (const e of Object.keys(w)) delete w[e];
150
+ for (const e of Object.keys(E)) delete E[e];
151
+ M = {}, p = null, P = !1, b = null, L();
152
+ }
153
+ function yt(e) {
154
+ e !== p && (P = !1, b = null), p = e, L();
155
+ }
156
+ function xt() {
157
+ P = !0;
158
+ }
159
+ function X(e) {
160
+ return e.map((t) => ({
161
+ id: t.id,
162
+ workflow: t.workflow || t.skill || "",
163
+ label: t.label,
164
+ host: t.host,
165
+ hint: t.hint ? v(t.hint) : void 0,
166
+ hostContext: t.hostContext ? k(v(t.hostContext)) : void 0,
167
+ prefilled: t.prefilled ? k(v(t.prefilled)) : void 0,
168
+ enabled: t.enabled ? t.enabled() : !0,
169
+ kind: t.kind,
170
+ skill: t.skill,
171
+ noTools: t.noTools === !0 ? !0 : void 0
172
+ }));
173
+ }
174
+ function q(e, t) {
175
+ const n = (w[e] || []).find((o) => o.id === t);
176
+ if (!n || n.enabled && !n.enabled()) return null;
177
+ const i = n.prefilled ? k(v(n.prefilled)) : void 0;
178
+ return {
179
+ action: n,
180
+ prefilled: i,
181
+ hostContext: n.hostContext ? k(v(n.hostContext)) : void 0
182
+ };
183
+ }
184
+ function mt(e, t) {
185
+ const n = q(e, t);
186
+ return !n || J(n.action) ? null : {
187
+ workflow: n.action.workflow || n.action.skill || "",
188
+ title: n.action.label,
189
+ host: n.action.host,
190
+ prefilled: n.prefilled,
191
+ hostContext: n.hostContext
192
+ };
193
+ }
194
+ function vt() {
195
+ return p;
196
+ }
197
+ function Ht() {
198
+ return Object.entries(w).map(([e, t]) => ({ pageId: e, actions: t }));
199
+ }
200
+ function Z(e, t) {
201
+ const n = (w[e] || []).find((i) => i.id === t);
202
+ return n ? F(n.anchor) : null;
203
+ }
204
+ function kt(e, t) {
205
+ const n = Z(e, t);
206
+ if (!n) return null;
207
+ const i = n.getBoundingClientRect();
208
+ return !i.width && !i.height ? null : i;
209
+ }
210
+ function Lt() {
211
+ if (P || !p) return null;
212
+ const e = w[p] || [];
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";
216
+ return { pageId: p, actionId: t.id, hint: n, placement: i };
217
+ }
218
+ return null;
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";
221
+ function Pt(e) {
222
+ return e.replace(/\/$/, "");
223
+ }
224
+ function $(e) {
225
+ try {
226
+ return new URL(e).origin;
227
+ } catch (t) {
228
+ return e.replace(/\/$/, "");
229
+ }
230
+ }
231
+ function Rt(e, t) {
232
+ const n = $(e), i = $(t);
233
+ if (n === i) return !0;
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);
237
+ } catch (o) {
238
+ return !1;
239
+ }
240
+ }
241
+ function It() {
242
+ if (typeof document == "undefined" || document.getElementById(G)) return;
243
+ const e = document.createElement("style");
244
+ e.id = G, e.textContent = `
245
+ #${f} {
246
+ position: fixed;
247
+ right: 24px;
248
+ bottom: 24px;
249
+ z-index: 2147482999;
250
+ width: 56px;
251
+ height: 56px;
252
+ border: none;
253
+ border-radius: 50%;
254
+ cursor: pointer;
255
+ display: flex;
256
+ align-items: center;
257
+ justify-content: center;
258
+ color: #fff;
259
+ font-size: 22px;
260
+ line-height: 1;
261
+ background: linear-gradient(145deg, #12a892 0%, #0d8f7b 55%, #0a7a6a 100%);
262
+ box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42);
263
+ transition: transform 0.15s ease, opacity 0.2s ease, visibility 0.2s ease;
264
+ }
265
+ #${f}:hover { transform: scale(1.05); }
266
+ #${f}.is-hidden {
267
+ opacity: 0;
268
+ visibility: hidden;
269
+ pointer-events: none;
270
+ transform: scale(0.85);
271
+ }
272
+ #${f}.is-pulse {
273
+ animation: agent-host-fab-pulse 2s ease-in-out infinite;
274
+ }
275
+ #${f} .agent-host-launcher-icon {
276
+ display: inline-block;
277
+ line-height: 1;
278
+ transform-origin: center center;
279
+ }
280
+ #${f}.is-breathe .agent-host-launcher-icon {
281
+ animation: agent-host-clover-breathe 1.8s ease-in-out infinite;
282
+ }
283
+ #${f} .agent-host-launcher-bell {
284
+ display: none;
285
+ width: 22px;
286
+ height: 22px;
287
+ line-height: 0;
288
+ transform-origin: top center;
289
+ }
290
+ #${f} .agent-host-launcher-bell.is-visible {
291
+ display: inline-block;
292
+ animation: agent-host-bell-shake 0.85s ease-in-out infinite;
293
+ }
294
+ #${f} .agent-host-launcher-bell svg {
295
+ width: 100%;
296
+ height: 100%;
297
+ display: block;
298
+ }
299
+ #${f} .agent-host-launcher-badge {
300
+ position: absolute;
301
+ top: -4px;
302
+ right: -4px;
303
+ box-sizing: border-box;
304
+ min-width: 20px;
305
+ height: 20px;
306
+ padding: 0 5px;
307
+ border-radius: 999px;
308
+ font-size: 11px;
309
+ font-weight: 600;
310
+ line-height: 1;
311
+ display: none;
312
+ align-items: center;
313
+ justify-content: center;
314
+ border: 2px solid #fff;
315
+ background: #f59e0b;
316
+ color: #fff;
317
+ }
318
+ #${f} .agent-host-launcher-badge.is-visible { display: flex; }
319
+ #${f} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
320
+ #agent-host-launcher-hint {
321
+ position: fixed;
322
+ right: 24px;
323
+ bottom: 88px;
324
+ z-index: 2147482998;
325
+ max-width: min(800px, calc(100vw - 48px));
326
+ padding: 10px 14px;
327
+ border-radius: 10px;
328
+ font-size: 13px;
329
+ line-height: 1.45;
330
+ color: #333;
331
+ background: #fff;
332
+ border: 1px solid rgba(13, 143, 123, 0.22);
333
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
334
+ display: none;
335
+ pointer-events: auto;
336
+ }
337
+ #agent-host-launcher-hint.is-visible { display: block; }
338
+ #agent-host-launcher-hint.is-anchored {
339
+ right: auto;
340
+ bottom: auto;
341
+ }
342
+ #agent-host-launcher-hint .agent-host-hint-inner {
343
+ display: flex;
344
+ align-items: center;
345
+ gap: 10px;
346
+ flex-wrap: wrap;
347
+ }
348
+ #agent-host-launcher-hint .agent-host-hint-icon {
349
+ flex-shrink: 0;
350
+ display: inline-flex;
351
+ align-items: center;
352
+ justify-content: center;
353
+ width: 20px;
354
+ height: 20px;
355
+ font-size: 16px;
356
+ line-height: 1;
357
+ color: #0d8f7b;
358
+ transform-origin: center center;
359
+ animation: agent-host-hint-clover 4.5s ease-in-out infinite;
360
+ }
361
+ #agent-host-launcher-hint .agent-host-hint-text {
362
+ flex: 1;
363
+ min-width: 140px;
364
+ color: #333;
365
+ }
366
+ #agent-host-launcher-hint .agent-host-hint-actions {
367
+ display: flex;
368
+ align-items: center;
369
+ gap: 4px;
370
+ flex-shrink: 0;
371
+ }
372
+ #agent-host-launcher-hint .agent-host-hint-use {
373
+ border: 1px solid #0d8f7b;
374
+ border-radius: 6px;
375
+ padding: 0 12px;
376
+ height: 28px;
377
+ font-size: 12px;
378
+ font-weight: 500;
379
+ color: #0d8f7b;
380
+ background: transparent;
381
+ cursor: pointer;
382
+ }
383
+ #agent-host-launcher-hint .agent-host-hint-use:hover {
384
+ color: #fff;
385
+ background: #0d8f7b;
386
+ }
387
+ #agent-host-launcher-hint .agent-host-hint-dismiss {
388
+ border: none;
389
+ border-radius: 6px;
390
+ padding: 0 8px;
391
+ height: 28px;
392
+ font-size: 12px;
393
+ color: #999;
394
+ background: transparent;
395
+ cursor: pointer;
396
+ }
397
+ #agent-host-launcher-hint .agent-host-hint-dismiss:hover { color: #666; }
398
+ #${g} {
399
+ position: fixed;
400
+ inset: 0;
401
+ z-index: 2147483000;
402
+ pointer-events: none;
403
+ }
404
+ #${g}.is-open {
405
+ pointer-events: auto;
406
+ }
407
+ #${g} .agent-host-hub-backdrop {
408
+ position: absolute;
409
+ inset: 0;
410
+ background: rgba(15, 23, 42, 0.42);
411
+ opacity: 0;
412
+ transition: opacity 0.35s ease;
413
+ }
414
+ #${g}.is-open .agent-host-hub-backdrop {
415
+ opacity: 1;
416
+ }
417
+ /* FAB 位圆形 → 居中工作室模态 */
418
+ #${g} .agent-host-hub-panel-shell {
419
+ position: absolute;
420
+ right: 24px;
421
+ bottom: 24px;
422
+ width: 56px;
423
+ height: 56px;
424
+ border-radius: 50%;
425
+ background: #fff;
426
+ box-shadow: 0 4px 18px rgba(13, 143, 123, 0.35);
427
+ overflow: hidden;
428
+ opacity: 0;
429
+ transform: scale(0.92);
430
+ transition:
431
+ width 0.42s cubic-bezier(0.22, 1, 0.36, 1),
432
+ height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
433
+ right 0.42s cubic-bezier(0.22, 1, 0.36, 1),
434
+ bottom 0.42s cubic-bezier(0.22, 1, 0.36, 1),
435
+ border-radius 0.42s cubic-bezier(0.22, 1, 0.36, 1),
436
+ box-shadow 0.42s ease,
437
+ opacity 0.2s ease,
438
+ transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
439
+ }
440
+ #${g}.is-open .agent-host-hub-panel-shell {
441
+ right: max(24px, calc((100vw - min(1120px, calc(100vw - 48px))) / 2));
442
+ bottom: max(24px, calc((100vh - min(780px, calc(100vh - 48px))) / 2));
443
+ width: min(1120px, calc(100vw - 48px));
444
+ height: min(780px, calc(100vh - 48px));
445
+ border-radius: 16px;
446
+ box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
447
+ opacity: 1;
448
+ transform: scale(1);
449
+ }
450
+ @media (max-width: 720px) {
451
+ #${g}.is-open .agent-host-hub-panel-shell {
452
+ right: 12px;
453
+ bottom: 12px;
454
+ width: calc(100vw - 24px);
455
+ height: calc(100vh - 24px);
456
+ border-radius: 12px;
457
+ }
458
+ }
459
+ #${g} iframe {
460
+ width: 100%;
461
+ height: 100%;
462
+ border: none;
463
+ background: #fff;
464
+ display: block;
465
+ opacity: 0;
466
+ transition: opacity 0.2s ease 0.18s;
467
+ }
468
+ #${g}.is-open iframe {
469
+ opacity: 1;
470
+ }
471
+ @keyframes agent-host-fab-pulse {
472
+ 0%, 100% { box-shadow: 0 4px 18px rgba(13, 143, 123, 0.42); }
473
+ 50% { box-shadow: 0 4px 26px rgba(13, 143, 123, 0.62); }
474
+ }
475
+ @keyframes agent-host-clover-breathe {
476
+ 0%, 100% { transform: scale(1); }
477
+ 50% { transform: scale(1.28); }
478
+ }
479
+ @keyframes agent-host-hint-clover {
480
+ 0% { transform: scale(0.88) rotate(0deg); }
481
+ 16.67% { transform: scale(1.12) rotate(0deg); }
482
+ 33.33% { transform: scale(0.88) rotate(0deg); }
483
+ 50% { transform: scale(1.12) rotate(0deg); }
484
+ 66.67% { transform: scale(1) rotate(0deg); }
485
+ 100% { transform: scale(1) rotate(360deg); }
486
+ }
487
+ @keyframes agent-host-bell-shake {
488
+ 0%, 100% { transform: rotate(0deg); }
489
+ 12% { transform: rotate(14deg); }
490
+ 24% { transform: rotate(-12deg); }
491
+ 36% { transform: rotate(10deg); }
492
+ 48% { transform: rotate(-8deg); }
493
+ 60% { transform: rotate(5deg); }
494
+ 72% { transform: rotate(-3deg); }
495
+ 84% { transform: rotate(1deg); }
496
+ }
497
+ `, document.head.appendChild(e);
498
+ }
499
+ class Ot {
500
+ constructor(t, n, i) {
501
+ h(this, "agentOrigin", "");
502
+ h(this, "hubLauncher", null);
503
+ h(this, "hubLauncherBadge", null);
504
+ h(this, "hubLauncherHint", null);
505
+ h(this, "hubPanelOverlay", null);
506
+ h(this, "hubIframe", null);
507
+ h(this, "widgetIframe", null);
508
+ h(this, "hubReady", !1);
509
+ h(this, "widgetReady", !1);
510
+ h(this, "hubPanelOpen", !1);
511
+ h(this, "lastRunning", 0);
512
+ h(this, "lastWaiting", 0);
513
+ h(this, "launcherHintAction", null);
514
+ h(this, "hintRepositionBound", !1);
515
+ h(this, "hintScrollParents", []);
516
+ h(this, "pendingHubMessages", []);
517
+ h(this, "pendingWidgetMessages", []);
518
+ h(this, "onChildMessage");
519
+ h(this, "onHintUse");
520
+ h(this, "onHintDismiss");
521
+ h(this, "onHintReposition", () => {
522
+ const t = this.launcherHintAction, n = this.hubLauncherHint;
523
+ !t || !n || !n.classList.contains("is-visible") || this.layoutHint(n, t);
524
+ });
525
+ h(this, "handleMessage", (t) => {
526
+ var i, o, s;
527
+ if (!Rt(this.agentOrigin, t.origin) || !rt(t.data)) return;
528
+ const n = t.data;
529
+ if (n.type === "ready") {
530
+ n.surface === "hub" ? (this.hubReady = !0, this.flush("hub")) : (this.widgetReady = !0, this.flush("widget")), (i = this.onChildMessage) == null || i.call(this, n);
531
+ return;
532
+ }
533
+ if (n.type === "hub-panel-close") {
534
+ this.closeHubPanel();
535
+ return;
536
+ }
537
+ if (n.type === "hub-panel-width") {
538
+ this.setHubPanelExpanded(!!n.expanded);
539
+ return;
540
+ }
541
+ if (n.type === "hub-stats") {
542
+ this.updateLauncherStats(n.running, n.waiting), (o = this.onChildMessage) == null || o.call(this, n);
543
+ return;
544
+ }
545
+ (s = this.onChildMessage) == null || s.call(this, n);
546
+ });
547
+ this.agentOrigin = Pt(t), this.onChildMessage = n, this.onHintUse = i == null ? void 0 : i.onHintUse, this.onHintDismiss = i == null ? void 0 : i.onHintDismiss, window.addEventListener("message", this.handleMessage);
548
+ }
549
+ destroy() {
550
+ window.removeEventListener("message", this.handleMessage), this.unbindHintReposition(), this.removeHub(), this.closeWidget();
551
+ }
552
+ /** Launcher(宿主 DOM)+ 居中工作室模态(显隐用 CSS,不改 iframe 尺寸) */
553
+ mountHub() {
554
+ this.hubPanelOverlay || typeof document == "undefined" || (It(), this.mountLauncher(), this.mountHubPanel());
555
+ }
556
+ openHubPanel() {
557
+ var t, n;
558
+ this.hubPanelOverlay && (this.hubPanelOpen = !0, this.hubPanelOverlay.classList.add("is-open"), (t = this.hubLauncher) == null || t.classList.add("is-hidden"), (n = this.hubLauncherHint) == null || n.classList.remove("is-visible"), this.post("hub", { channel: A, type: "open-hub-panel" }), this.applyLauncherVisual());
559
+ }
560
+ closeHubPanel() {
561
+ var t;
562
+ this.hubPanelOverlay && (this.hubPanelOpen = !1, this.hubPanelOverlay.classList.remove("is-open"), (t = this.hubLauncher) == null || t.classList.remove("is-hidden"), this.post("hub", { channel: A, type: "close-hub-panel" }), this.updateLauncherHint(this.launcherHintAction), this.applyLauncherVisual());
563
+ }
564
+ /** @deprecated 工作室模态固定宽度,忽略半屏展开 */
565
+ setHubPanelExpanded(t) {
566
+ }
567
+ updateLauncherHint(t) {
568
+ this.launcherHintAction = t;
569
+ const n = this.hubLauncherHint;
570
+ if (!n) return;
571
+ if (this.hubPanelOpen) {
572
+ n.classList.remove("is-visible", "is-anchored"), this.unbindHintReposition();
573
+ return;
574
+ }
575
+ if (!t || !t.hint.trim()) {
576
+ n.innerHTML = "", n.classList.remove("is-visible", "is-anchored"), this.unbindHintReposition();
577
+ return;
578
+ }
579
+ n.innerHTML = `
580
+ <div class="agent-host-hint-inner">
581
+ <span class="agent-host-hint-icon" aria-hidden="true">✦</span>
582
+ <span class="agent-host-hint-text"></span>
583
+ <div class="agent-host-hint-actions">
584
+ <button type="button" class="agent-host-hint-use">立即开始</button>
585
+ <button type="button" class="agent-host-hint-dismiss">稍后</button>
586
+ </div>
587
+ </div>`;
588
+ const i = n.querySelector(".agent-host-hint-text");
589
+ 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);
597
+ }), n.classList.add("is-visible"), this.layoutHint(n, t), this.bindHintReposition();
598
+ }
599
+ layoutHint(t, n) {
600
+ if (n.placement !== "anchor") {
601
+ t.classList.remove("is-anchored"), t.style.top = "", t.style.left = "";
602
+ return;
603
+ }
604
+ const i = kt(n.pageId, n.actionId);
605
+ if (!i) {
606
+ t.classList.remove("is-anchored"), t.style.top = "", t.style.left = "";
607
+ return;
608
+ }
609
+ 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`;
613
+ }
614
+ collectScrollParents(t) {
615
+ var o;
616
+ const n = [];
617
+ let i = (o = t == null ? void 0 : t.parentElement) != null ? o : null;
618
+ 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;
621
+ }
622
+ return n;
623
+ }
624
+ bindHintReposition() {
625
+ var i, o;
626
+ if (typeof window == "undefined") return;
627
+ 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);
628
+ const t = this.launcherHintAction;
629
+ for (const s of this.hintScrollParents)
630
+ s.removeEventListener("scroll", this.onHintReposition);
631
+ if (this.hintScrollParents = [], !t || t.placement !== "anchor") return;
632
+ const n = Z(t.pageId, t.actionId);
633
+ this.hintScrollParents = this.collectScrollParents(n);
634
+ for (const s of this.hintScrollParents)
635
+ s.addEventListener("scroll", this.onHintReposition, { passive: !0 });
636
+ }
637
+ unbindHintReposition() {
638
+ var t, n;
639
+ if (typeof window != "undefined") {
640
+ 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);
641
+ for (const i of this.hintScrollParents)
642
+ i.removeEventListener("scroll", this.onHintReposition);
643
+ this.hintScrollParents = [];
644
+ }
645
+ }
646
+ mountLauncher() {
647
+ if (this.hubLauncher || document.getElementById(f)) return;
648
+ 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"))
650
+ this.hubLauncherHint = document.getElementById("agent-host-launcher-hint");
651
+ else {
652
+ const n = document.createElement("div");
653
+ n.id = "agent-host-launcher-hint", document.body.appendChild(n), this.hubLauncherHint = n;
654
+ }
655
+ }
656
+ mountHubPanel() {
657
+ const t = document.createElement("div");
658
+ t.id = g;
659
+ const n = document.createElement("div");
660
+ n.className = "agent-host-hub-backdrop", n.addEventListener("click", () => this.closeHubPanel());
661
+ const i = document.createElement("div");
662
+ i.className = "agent-host-hub-panel-shell";
663
+ const o = document.createElement("iframe");
664
+ o.id = Ct, 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;
665
+ }
666
+ updateLauncherStats(t, n) {
667
+ this.lastRunning = t, this.lastWaiting = n, this.applyLauncherVisual();
668
+ }
669
+ applyLauncherVisual() {
670
+ const t = this.hubLauncher, n = this.hubLauncherBadge;
671
+ 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"));
674
+ }
675
+ removeHub() {
676
+ 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 = [];
678
+ }
679
+ openWidget(t, n, i) {
680
+ this.closeWidget();
681
+ const o = document.createElement("div");
682
+ o.id = K, 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) => {
683
+ tt.target === o && this.closeWidget();
684
+ });
685
+ const s = document.createElement("iframe");
686
+ s.id = Et, s.title = t.title || t.workflow;
687
+ const c = new URLSearchParams({
688
+ embed: "1",
689
+ workflow: t.workflow,
690
+ host: t.host || "",
691
+ title: t.title || ""
692
+ });
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 = {
695
+ channel: A,
696
+ type: "init",
697
+ token: n,
698
+ refreshToken: i
699
+ }, u = {
700
+ workflow: t.workflow,
701
+ title: t.title,
702
+ host: t.host,
703
+ prefilled: t.prefilled ? k(t.prefilled) : void 0,
704
+ hostContext: t.hostContext ? k(t.hostContext) : void 0,
705
+ sessionId: t.sessionId,
706
+ preferSandboxFiles: t.preferSandboxFiles
707
+ }, I = {
708
+ channel: A,
709
+ type: "open-widget",
710
+ payload: u
711
+ };
712
+ this.pendingWidgetMessages = [l, I];
713
+ }
714
+ closeWidget() {
715
+ var t;
716
+ (t = document.getElementById(K)) == null || t.remove(), this.widgetIframe = null, this.widgetReady = !1, this.pendingWidgetMessages = [];
717
+ }
718
+ sendToHub(t) {
719
+ this.post("hub", t);
720
+ }
721
+ post(t, n) {
722
+ var c;
723
+ const i = t === "hub" ? this.hubReady : this.widgetReady, o = t === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages;
724
+ if (!i) {
725
+ o.push(n);
726
+ return;
727
+ }
728
+ const s = t === "hub" ? this.hubIframe : this.widgetIframe;
729
+ (c = s == null ? void 0 : s.contentWindow) == null || c.postMessage(n, $(this.agentOrigin));
730
+ }
731
+ flush(t) {
732
+ const n = t === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages, i = t === "hub" ? this.hubIframe : this.widgetIframe;
733
+ if (!(i != null && i.contentWindow)) return;
734
+ const o = $(this.agentOrigin);
735
+ for (; n.length; ) {
736
+ const s = n.shift();
737
+ s && i.contentWindow.postMessage(s, o);
738
+ }
739
+ }
740
+ }
741
+ let a = {}, r = null, y = "", R = "", x = null;
742
+ function At() {
743
+ const e = (a.agentOrigin || "").replace(/\/$/, "");
744
+ if (!e)
745
+ throw new Error(
746
+ "Agent 前端地址未配置:请在 init({ agentOrigin }) 传入,或由宿主 BFF bootstrap 返回 agent_web_origin"
747
+ );
748
+ return e;
749
+ }
750
+ function Q(e) {
751
+ 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);
753
+ }
754
+ function T() {
755
+ return d(this, null, function* () {
756
+ if (a.getToken)
757
+ return y = yield a.getToken(), y;
758
+ if (y) return y;
759
+ if (a.bootstrap) {
760
+ const e = yield a.bootstrap();
761
+ if (Q(e), y) return y;
762
+ }
763
+ throw new Error("未连接 Agent:请配置 bootstrap 或 getToken");
764
+ });
765
+ }
766
+ function H() {
767
+ if (a.agentOrigin)
768
+ try {
769
+ m().updateLauncherHint(Lt());
770
+ } catch (e) {
771
+ }
772
+ }
773
+ function m() {
774
+ const e = At();
775
+ return r || (Y(H), r = new Ot(e, St, {
776
+ onHintUse: (t, n) => {
777
+ U(t, n);
778
+ },
779
+ onHintDismiss: () => {
780
+ xt(), H();
781
+ }
782
+ }), a.showHub !== !1 && r.mountHub()), r;
783
+ }
784
+ function Tt() {
785
+ if (!(!r || !a.agentOrigin)) {
786
+ for (const { pageId: e, actions: t } of Ht())
787
+ r.sendToHub({
788
+ channel: "agent-host",
789
+ type: "register-page",
790
+ pageId: e,
791
+ actions: X(t)
792
+ });
793
+ r.sendToHub({
794
+ channel: "agent-host",
795
+ type: "set-page",
796
+ pageId: vt()
797
+ }), H();
798
+ }
799
+ }
800
+ function St(e) {
801
+ var t;
802
+ if (e.type === "ready" && e.surface === "hub" && T().then((n) => {
803
+ r == null || r.sendToHub({
804
+ channel: "agent-host",
805
+ type: "init",
806
+ token: n,
807
+ refreshToken: R || void 0
808
+ }), Tt();
809
+ }).catch(() => {
810
+ }), e.type === "started" && (r == null || r.closeWidget(), r == null || r.openHubPanel(), r == null || r.sendToHub({
811
+ channel: "agent-host",
812
+ type: "task-started",
813
+ taskId: e.taskId,
814
+ sessionId: e.sessionId,
815
+ workflow: e.workflow,
816
+ label: e.label || e.workflow,
817
+ formValues: e.formValues,
818
+ prefilled: e.prefilled,
819
+ hostContext: e.hostContext,
820
+ hubContinue: e.hubContinue
821
+ })), e.type === "complete") {
822
+ if (e.status === "success" || e.status === "failed" || e.status === "cancelled") {
823
+ const n = e.hostContext && e.hostContext.refresh;
824
+ bt(n, {
825
+ taskId: e.taskId,
826
+ result: e.result,
827
+ hostContext: e.hostContext,
828
+ apply: e.apply
829
+ });
830
+ }
831
+ (t = a.onTaskComplete) == null || t.call(a, {
832
+ taskId: e.taskId,
833
+ status: e.status,
834
+ hostContext: e.hostContext,
835
+ result: e.result,
836
+ apply: e.apply
837
+ }), r == null || r.closeWidget();
838
+ }
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();
840
+ }
841
+ function Mt() {
842
+ return d(this, null, function* () {
843
+ if (!r || !a.agentOrigin) return;
844
+ let e = {};
845
+ try {
846
+ a.getHostContext ? e = (yield a.getHostContext()) || {} : e = D();
847
+ } catch (n) {
848
+ e = D();
849
+ }
850
+ const t = gt(e);
851
+ r.sendToHub({
852
+ channel: "agent-host",
853
+ type: "set-host-context",
854
+ context: t
855
+ });
856
+ });
857
+ }
858
+ function U(e, t) {
859
+ return d(this, null, function* () {
860
+ const n = q(e, t);
861
+ if (!n) return;
862
+ if (J(n.action)) {
863
+ yield $t(n);
864
+ return;
865
+ }
866
+ const i = mt(e, t);
867
+ i && (yield V(i));
868
+ });
869
+ }
870
+ function $t(e) {
871
+ return d(this, null, function* () {
872
+ yield C(), e.action.workflow && !e.action.skill && a.prepareOpenWidget && (yield a.prepareOpenWidget());
873
+ const t = yield T(), n = m();
874
+ n.openHubPanel(), n.sendToHub({
875
+ channel: "agent-host",
876
+ type: "init",
877
+ token: t,
878
+ refreshToken: R || void 0
879
+ }), n.sendToHub({
880
+ channel: "agent-host",
881
+ type: "run-direct",
882
+ workflow: e.action.workflow || e.action.skill || "",
883
+ title: e.action.label,
884
+ host: e.action.host || a.host,
885
+ skill: e.action.skill,
886
+ noTools: e.action.noTools === !0,
887
+ prefilled: e.prefilled,
888
+ hostContext: e.hostContext
889
+ });
890
+ });
891
+ }
892
+ function V(e) {
893
+ return d(this, null, function* () {
894
+ yield C(), a.prepareOpenWidget && (yield a.prepareOpenWidget());
895
+ const t = m(), n = yield T();
896
+ t.openWidget(
897
+ {
898
+ workflow: e.workflow,
899
+ title: e.title || e.label,
900
+ host: e.host || a.host,
901
+ prefilled: e.prefilled,
902
+ hostContext: e.hostContext,
903
+ sessionId: e.sessionId,
904
+ preferSandboxFiles: e.preferSandboxFiles
905
+ },
906
+ n,
907
+ R || void 0
908
+ );
909
+ });
910
+ }
911
+ function C() {
912
+ return d(this, null, function* () {
913
+ x && (yield x);
914
+ });
915
+ }
916
+ function Wt(e) {
917
+ return d(this, null, function* () {
918
+ if (a = O({ showHub: !0 }, e), a.bootstrap) {
919
+ const t = yield a.bootstrap();
920
+ Q(t);
921
+ }
922
+ if (a.agentOrigin && a.showHub !== !1 && typeof document != "undefined")
923
+ try {
924
+ m();
925
+ const t = yield T();
926
+ r == null || r.sendToHub({
927
+ channel: "agent-host",
928
+ type: "init",
929
+ token: t,
930
+ refreshToken: R || void 0
931
+ });
932
+ } catch (t) {
933
+ }
934
+ });
935
+ }
936
+ const Bt = {
937
+ init(e) {
938
+ return d(this, null, function* () {
939
+ x && (yield x), x = Wt(e).finally(() => {
940
+ x = null;
941
+ }), yield x;
942
+ });
943
+ },
944
+ getToken() {
945
+ return d(this, null, function* () {
946
+ return yield C(), T();
947
+ });
948
+ },
949
+ registerPage(i, o) {
950
+ return d(this, arguments, function* (e, t, n = {}) {
951
+ yield C(), dt(e, t, n), a.agentOrigin && m().sendToHub({
952
+ channel: "agent-host",
953
+ type: "register-page",
954
+ pageId: e,
955
+ actions: X(t)
956
+ }), H();
957
+ });
958
+ },
959
+ /** 最近一次按需回写的宿主上下文(系统 / 名称 / 描述 / 菜单) */
960
+ getHostContext() {
961
+ return D();
962
+ },
963
+ unregisterPage(e) {
964
+ return d(this, null, function* () {
965
+ 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
+ });
967
+ },
968
+ 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();
971
+ });
972
+ },
973
+ openAction(e, t) {
974
+ return d(this, null, function* () {
975
+ if (!q(e, t)) throw new Error("当前操作不可用");
976
+ yield U(e, t);
977
+ });
978
+ },
979
+ openWorkflow(n) {
980
+ return d(this, arguments, function* (e, t = {}) {
981
+ yield V(_(O({
982
+ workflow: e
983
+ }, t), {
984
+ host: t.host || a.host,
985
+ title: t.title || t.label || e
986
+ }));
987
+ });
988
+ },
989
+ /**
990
+ * 兼容保留。场景能否启动由宿主 `action.enabled` 判断,SDK 不识别具体 workflow/skill slug。
991
+ */
992
+ canOpen(e, t) {
993
+ return !0;
994
+ },
995
+ destroy() {
996
+ r == null || r.destroy(), r = null, y = "", R = "", a = {}, x = null, Y(null), wt();
997
+ }
998
+ };
999
+ typeof window != "undefined" && (window.AgentHost = Bt);
1000
+ export {
1001
+ A as AGENT_HOST_MSG,
1002
+ Bt as AgentHost,
1003
+ rt as isAgentHostMessage
1004
+ };