@_daniel_jiang/host-sdk 1.0.0 → 1.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.
- package/README.md +18 -19
- package/dist/agent-host.js +26 -22
- package/dist/agent-host.mjs +490 -319
- package/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/agent-host.mjs
CHANGED
|
@@ -1,65 +1,237 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
1
|
+
var Q = Object.defineProperty, ee = Object.defineProperties;
|
|
2
|
+
var te = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var F = Object.getOwnPropertySymbols;
|
|
4
|
+
var ne = Object.prototype.hasOwnProperty, ie = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var M = (t, e, n) => e in t ? Q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, _ = (t, e) => {
|
|
6
6
|
for (var n in e || (e = {}))
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var n of
|
|
10
|
-
|
|
7
|
+
ne.call(e, n) && M(t, n, e[n]);
|
|
8
|
+
if (F)
|
|
9
|
+
for (var n of F(e))
|
|
10
|
+
ie.call(e, n) && M(t, n, e[n]);
|
|
11
11
|
return t;
|
|
12
|
-
},
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
12
|
+
}, U = (t, e) => ee(t, te(e));
|
|
13
|
+
var h = (t, e, n) => M(t, typeof e != "symbol" ? e + "" : e, n);
|
|
14
|
+
var f = (t, e, n) => new Promise((i, o) => {
|
|
15
|
+
var s = (u) => {
|
|
16
16
|
try {
|
|
17
|
-
|
|
18
|
-
} catch (
|
|
19
|
-
|
|
17
|
+
l(n.next(u));
|
|
18
|
+
} catch (C) {
|
|
19
|
+
o(C);
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, c = (u) => {
|
|
22
22
|
try {
|
|
23
|
-
|
|
24
|
-
} catch (
|
|
25
|
-
|
|
23
|
+
l(n.throw(u));
|
|
24
|
+
} catch (C) {
|
|
25
|
+
o(C);
|
|
26
26
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
27
|
+
}, l = (u) => u.done ? i(u.value) : Promise.resolve(u.value).then(s, c);
|
|
28
|
+
l((n = n.apply(t, e)).next());
|
|
29
29
|
});
|
|
30
|
-
const
|
|
31
|
-
function
|
|
32
|
-
return typeof t == "object" && t !== null && t.channel ===
|
|
30
|
+
const O = "agent-host";
|
|
31
|
+
function oe(t) {
|
|
32
|
+
return typeof t == "object" && t !== null && t.channel === O && typeof t.type == "string";
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function P(t) {
|
|
35
35
|
return t == null ? t : JSON.parse(JSON.stringify(t));
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
function
|
|
37
|
+
function v(t) {
|
|
38
|
+
return typeof t == "function" ? t() : t;
|
|
39
|
+
}
|
|
40
|
+
const b = {}, E = {};
|
|
41
|
+
let d = null, I = !1, g = null, S = null, q = !1;
|
|
42
|
+
function K(t) {
|
|
43
|
+
S = t;
|
|
44
|
+
}
|
|
45
|
+
function k() {
|
|
46
|
+
try {
|
|
47
|
+
S == null || S();
|
|
48
|
+
} catch (t) {
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function W(t) {
|
|
52
|
+
var o;
|
|
53
|
+
if (!t) return null;
|
|
54
|
+
const e = typeof t == "function" ? t() : t;
|
|
55
|
+
if (!e) return null;
|
|
56
|
+
let n = null;
|
|
57
|
+
if (e instanceof Element ? n = e : typeof e == "object" && e.$el instanceof Element && (n = e.$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 $(t) {
|
|
62
|
+
return !t || typeof t.closest != "function" ? !1 : !!t.closest("#agent-host-launcher-hint");
|
|
63
|
+
}
|
|
64
|
+
function B(t) {
|
|
65
|
+
return !!t.anchor && t.hintPlacement === "anchor";
|
|
66
|
+
}
|
|
67
|
+
function se(t, e) {
|
|
68
|
+
if (!d) {
|
|
69
|
+
g && (g = null, k());
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if ($(t) || $(e)) return;
|
|
73
|
+
const n = b[d] || [];
|
|
74
|
+
let i = null;
|
|
75
|
+
if (t instanceof Node)
|
|
76
|
+
for (const o of n) {
|
|
77
|
+
if (!B(o)) continue;
|
|
78
|
+
const s = W(o.anchor);
|
|
79
|
+
if (s && s.contains(t)) {
|
|
80
|
+
i = o.id;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
i !== g && (g = i, k());
|
|
85
|
+
}
|
|
86
|
+
function re(t) {
|
|
87
|
+
se(t.target);
|
|
88
|
+
}
|
|
89
|
+
function ae(t) {
|
|
90
|
+
if ($(t.relatedTarget)) return;
|
|
91
|
+
const e = t.target;
|
|
92
|
+
if (!(e instanceof Node) || !d) return;
|
|
93
|
+
const i = (b[d] || []).find((s) => s.id === g);
|
|
94
|
+
if (!i) return;
|
|
95
|
+
const o = W(i.anchor);
|
|
96
|
+
o && o.contains(e) && !o.contains(t.relatedTarget) && (g = null, k());
|
|
97
|
+
}
|
|
98
|
+
function le() {
|
|
99
|
+
q || typeof document == "undefined" || (document.addEventListener("focusin", re, !0), document.addEventListener("focusout", ae, !0), q = !0);
|
|
100
|
+
}
|
|
101
|
+
function he(t, e) {
|
|
102
|
+
const n = (e || "").trim();
|
|
103
|
+
if (n) return n;
|
|
104
|
+
for (const i of t) {
|
|
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 G(t) {
|
|
111
|
+
return ((t == null ? void 0 : t.kind) || "widget") === "direct";
|
|
112
|
+
}
|
|
113
|
+
function ce(t, e, n = {}) {
|
|
114
|
+
le();
|
|
115
|
+
const i = t !== d;
|
|
116
|
+
i && (I = !1, g = null), b[t] = e, d = t, !i && e.some((s) => !s.enabled || s.enabled()) && (I = !1);
|
|
117
|
+
const o = he(e, n.refreshKey);
|
|
118
|
+
o && typeof n.onRefresh == "function" ? E[t] = { refreshKey: o, onRefresh: n.onRefresh } : delete E[t], k();
|
|
119
|
+
}
|
|
120
|
+
function ue(t) {
|
|
121
|
+
delete b[t], delete E[t], d === t && (d = null, g = null), k();
|
|
122
|
+
}
|
|
123
|
+
function de(t, e) {
|
|
124
|
+
const n = String(t || "").trim();
|
|
125
|
+
if (n) {
|
|
126
|
+
for (const i of Object.values(E))
|
|
127
|
+
if (i.refreshKey === n)
|
|
128
|
+
try {
|
|
129
|
+
i.onRefresh(e);
|
|
130
|
+
} catch (o) {
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function fe() {
|
|
135
|
+
for (const t of Object.keys(b)) delete b[t];
|
|
136
|
+
for (const t of Object.keys(E)) delete E[t];
|
|
137
|
+
d = null, I = !1, g = null, k();
|
|
138
|
+
}
|
|
139
|
+
function pe(t) {
|
|
140
|
+
t !== d && (I = !1, g = null), d = t, k();
|
|
141
|
+
}
|
|
142
|
+
function ge() {
|
|
143
|
+
I = !0;
|
|
144
|
+
}
|
|
145
|
+
function Y(t) {
|
|
146
|
+
return t.map((e) => ({
|
|
147
|
+
id: e.id,
|
|
148
|
+
workflow: e.workflow,
|
|
149
|
+
label: e.label,
|
|
150
|
+
host: e.host,
|
|
151
|
+
hint: e.hint ? v(e.hint) : void 0,
|
|
152
|
+
hostContext: e.hostContext ? P(v(e.hostContext)) : void 0,
|
|
153
|
+
prefilled: e.prefilled ? P(v(e.prefilled)) : void 0,
|
|
154
|
+
enabled: e.enabled ? e.enabled() : !0,
|
|
155
|
+
kind: e.kind,
|
|
156
|
+
skill: e.skill
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
function be(t, e) {
|
|
160
|
+
const n = (t.workflow || t.skill || "").trim();
|
|
161
|
+
return e ? !(n === "edc_form_fill" && !e.sub_project_id && !e.subProjectId || n === "edc_crf_design" && !e.sub_project_id && !e.subProjectId || n === "sds_crf_schema_from_doc" && !e.index_id && !e.indexId || n === "sds-project-remark" && !String(e.project_name || e.name || "").trim()) : !0;
|
|
162
|
+
}
|
|
163
|
+
function j(t, e) {
|
|
164
|
+
const n = (b[t] || []).find((o) => o.id === e);
|
|
165
|
+
if (!n || n.enabled && !n.enabled()) return null;
|
|
166
|
+
const i = n.prefilled ? P(v(n.prefilled)) : void 0;
|
|
167
|
+
return i && typeof i == "object" && !be(n, i) ? null : {
|
|
168
|
+
action: n,
|
|
169
|
+
prefilled: i,
|
|
170
|
+
hostContext: n.hostContext ? P(v(n.hostContext)) : void 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function we(t, e) {
|
|
174
|
+
const n = j(t, e);
|
|
175
|
+
return !n || G(n.action) ? null : {
|
|
176
|
+
workflow: n.action.workflow,
|
|
177
|
+
title: n.action.label,
|
|
178
|
+
host: n.action.host,
|
|
179
|
+
prefilled: n.prefilled,
|
|
180
|
+
hostContext: n.hostContext
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function me() {
|
|
184
|
+
return d;
|
|
185
|
+
}
|
|
186
|
+
function ye() {
|
|
187
|
+
return Object.entries(b).map(([t, e]) => ({ pageId: t, actions: e }));
|
|
188
|
+
}
|
|
189
|
+
function X(t, e) {
|
|
190
|
+
const n = (b[t] || []).find((i) => i.id === e);
|
|
191
|
+
return n ? W(n.anchor) : null;
|
|
192
|
+
}
|
|
193
|
+
function xe(t, e) {
|
|
194
|
+
const n = X(t, e);
|
|
195
|
+
if (!n) return null;
|
|
196
|
+
const i = n.getBoundingClientRect();
|
|
197
|
+
return !i.width && !i.height ? null : i;
|
|
198
|
+
}
|
|
199
|
+
function ve() {
|
|
200
|
+
if (I || !d) return null;
|
|
201
|
+
const t = b[d] || [];
|
|
202
|
+
for (const e of t) {
|
|
203
|
+
if (e.enabled && !e.enabled() || B(e) && g !== e.id) continue;
|
|
204
|
+
const n = e.hint ? v(e.hint) : `可使用「${e.label}」`, i = B(e) ? "anchor" : "launcher";
|
|
205
|
+
return { pageId: d, actionId: e.id, hint: n, placement: i };
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const p = "agent-host-launcher", w = "agent-host-hub-panel-overlay", He = "agent-host-hub-iframe", V = "agent-host-widget-overlay", ke = "agent-host-widget-iframe", Le = 400, N = "agent-host-sdk-styles";
|
|
210
|
+
function Pe(t) {
|
|
39
211
|
return t.replace(/\/$/, "");
|
|
40
212
|
}
|
|
41
|
-
function
|
|
213
|
+
function T(t) {
|
|
42
214
|
try {
|
|
43
215
|
return new URL(t).origin;
|
|
44
216
|
} catch (e) {
|
|
45
217
|
return t.replace(/\/$/, "");
|
|
46
218
|
}
|
|
47
219
|
}
|
|
48
|
-
function
|
|
49
|
-
const n =
|
|
220
|
+
function Ee(t, e) {
|
|
221
|
+
const n = T(t), i = T(e);
|
|
50
222
|
if (n === i) return !0;
|
|
51
223
|
try {
|
|
52
|
-
const
|
|
53
|
-
return
|
|
54
|
-
} catch (
|
|
224
|
+
const o = new URL(n), s = new URL(i), c = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
225
|
+
return o.protocol === s.protocol && o.port === s.port && c.has(o.hostname) && c.has(s.hostname);
|
|
226
|
+
} catch (o) {
|
|
55
227
|
return !1;
|
|
56
228
|
}
|
|
57
229
|
}
|
|
58
|
-
function
|
|
59
|
-
if (typeof document == "undefined" || document.getElementById(
|
|
230
|
+
function Ie() {
|
|
231
|
+
if (typeof document == "undefined" || document.getElementById(N)) return;
|
|
60
232
|
const t = document.createElement("style");
|
|
61
|
-
t.id =
|
|
62
|
-
#${
|
|
233
|
+
t.id = N, t.textContent = `
|
|
234
|
+
#${p} {
|
|
63
235
|
position: fixed;
|
|
64
236
|
right: 24px;
|
|
65
237
|
bottom: 24px;
|
|
@@ -79,35 +251,35 @@ function Q() {
|
|
|
79
251
|
box-shadow: 0 4px 16px rgba(79, 70, 229, 0.45);
|
|
80
252
|
transition: transform 0.15s ease;
|
|
81
253
|
}
|
|
82
|
-
#${
|
|
83
|
-
#${
|
|
254
|
+
#${p}:hover { transform: scale(1.05); }
|
|
255
|
+
#${p}.is-pulse {
|
|
84
256
|
animation: agent-host-fab-pulse 2s ease-in-out infinite;
|
|
85
257
|
}
|
|
86
|
-
#${
|
|
258
|
+
#${p} .agent-host-launcher-icon {
|
|
87
259
|
display: inline-block;
|
|
88
260
|
line-height: 1;
|
|
89
261
|
transform-origin: center center;
|
|
90
262
|
}
|
|
91
|
-
#${
|
|
263
|
+
#${p}.is-breathe .agent-host-launcher-icon {
|
|
92
264
|
animation: agent-host-clover-breathe 1.8s ease-in-out infinite;
|
|
93
265
|
}
|
|
94
|
-
#${
|
|
266
|
+
#${p} .agent-host-launcher-bell {
|
|
95
267
|
display: none;
|
|
96
268
|
width: 22px;
|
|
97
269
|
height: 22px;
|
|
98
270
|
line-height: 0;
|
|
99
271
|
transform-origin: top center;
|
|
100
272
|
}
|
|
101
|
-
#${
|
|
273
|
+
#${p} .agent-host-launcher-bell.is-visible {
|
|
102
274
|
display: inline-block;
|
|
103
275
|
animation: agent-host-bell-shake 0.85s ease-in-out infinite;
|
|
104
276
|
}
|
|
105
|
-
#${
|
|
277
|
+
#${p} .agent-host-launcher-bell svg {
|
|
106
278
|
width: 100%;
|
|
107
279
|
height: 100%;
|
|
108
280
|
display: block;
|
|
109
281
|
}
|
|
110
|
-
#${
|
|
282
|
+
#${p} .agent-host-launcher-badge {
|
|
111
283
|
position: absolute;
|
|
112
284
|
top: -4px;
|
|
113
285
|
right: -4px;
|
|
@@ -126,8 +298,8 @@ function Q() {
|
|
|
126
298
|
background: #f59e0b;
|
|
127
299
|
color: #fff;
|
|
128
300
|
}
|
|
129
|
-
#${
|
|
130
|
-
#${
|
|
301
|
+
#${p} .agent-host-launcher-badge.is-visible { display: flex; }
|
|
302
|
+
#${p} .agent-host-launcher-badge.is-waiting { background: #ef4444; }
|
|
131
303
|
#agent-host-launcher-hint {
|
|
132
304
|
position: fixed;
|
|
133
305
|
right: 24px;
|
|
@@ -146,6 +318,10 @@ function Q() {
|
|
|
146
318
|
pointer-events: auto;
|
|
147
319
|
}
|
|
148
320
|
#agent-host-launcher-hint.is-visible { display: block; }
|
|
321
|
+
#agent-host-launcher-hint.is-anchored {
|
|
322
|
+
right: auto;
|
|
323
|
+
bottom: auto;
|
|
324
|
+
}
|
|
149
325
|
#agent-host-launcher-hint .agent-host-hint-inner {
|
|
150
326
|
display: flex;
|
|
151
327
|
align-items: center;
|
|
@@ -202,7 +378,7 @@ function Q() {
|
|
|
202
378
|
cursor: pointer;
|
|
203
379
|
}
|
|
204
380
|
#agent-host-launcher-hint .agent-host-hint-dismiss:hover { color: #666; }
|
|
205
|
-
#${
|
|
381
|
+
#${w} {
|
|
206
382
|
position: fixed;
|
|
207
383
|
inset: 0;
|
|
208
384
|
z-index: 2147483000;
|
|
@@ -210,34 +386,34 @@ function Q() {
|
|
|
210
386
|
opacity: 0;
|
|
211
387
|
transition: opacity 0.2s ease;
|
|
212
388
|
}
|
|
213
|
-
#${
|
|
389
|
+
#${w}.is-open {
|
|
214
390
|
pointer-events: auto;
|
|
215
391
|
opacity: 1;
|
|
216
392
|
}
|
|
217
|
-
#${
|
|
393
|
+
#${w} .agent-host-hub-backdrop {
|
|
218
394
|
position: absolute;
|
|
219
395
|
inset: 0;
|
|
220
396
|
background: rgba(15, 23, 42, 0.45);
|
|
221
397
|
}
|
|
222
|
-
#${
|
|
398
|
+
#${w} .agent-host-hub-panel-shell {
|
|
223
399
|
position: absolute;
|
|
224
400
|
top: 0;
|
|
225
401
|
right: 0;
|
|
226
402
|
bottom: 0;
|
|
227
|
-
width: min(${
|
|
403
|
+
width: min(${Le}px, 100vw);
|
|
228
404
|
transform: translateX(100%);
|
|
229
405
|
transition: transform 0.28s cubic-bezier(0.2, 0, 0, 1), width 0.28s cubic-bezier(0.2, 0, 0, 1);
|
|
230
406
|
background: #fff;
|
|
231
407
|
box-shadow: -8px 0 24px rgba(15, 23, 42, 0.14);
|
|
232
408
|
overflow: hidden;
|
|
233
409
|
}
|
|
234
|
-
#${
|
|
410
|
+
#${w} .agent-host-hub-panel-shell.is-expanded {
|
|
235
411
|
width: min(50vw, 100vw);
|
|
236
412
|
}
|
|
237
|
-
#${
|
|
413
|
+
#${w}.is-open .agent-host-hub-panel-shell {
|
|
238
414
|
transform: translateX(0);
|
|
239
415
|
}
|
|
240
|
-
#${
|
|
416
|
+
#${w} iframe {
|
|
241
417
|
width: 100%;
|
|
242
418
|
height: 100%;
|
|
243
419
|
border: none;
|
|
@@ -273,30 +449,36 @@ function Q() {
|
|
|
273
449
|
}
|
|
274
450
|
`, document.head.appendChild(t);
|
|
275
451
|
}
|
|
276
|
-
class
|
|
452
|
+
class Re {
|
|
277
453
|
constructor(e, n, i) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
454
|
+
h(this, "agentOrigin", "");
|
|
455
|
+
h(this, "hubLauncher", null);
|
|
456
|
+
h(this, "hubLauncherBadge", null);
|
|
457
|
+
h(this, "hubLauncherHint", null);
|
|
458
|
+
h(this, "hubPanelOverlay", null);
|
|
459
|
+
h(this, "hubIframe", null);
|
|
460
|
+
h(this, "widgetIframe", null);
|
|
461
|
+
h(this, "hubReady", !1);
|
|
462
|
+
h(this, "widgetReady", !1);
|
|
463
|
+
h(this, "hubPanelOpen", !1);
|
|
464
|
+
h(this, "hubPanelExpanded", !1);
|
|
465
|
+
h(this, "lastRunning", 0);
|
|
466
|
+
h(this, "lastWaiting", 0);
|
|
467
|
+
h(this, "launcherHintAction", null);
|
|
468
|
+
h(this, "hintRepositionBound", !1);
|
|
469
|
+
h(this, "hintScrollParents", []);
|
|
470
|
+
h(this, "pendingHubMessages", []);
|
|
471
|
+
h(this, "pendingWidgetMessages", []);
|
|
472
|
+
h(this, "onChildMessage");
|
|
473
|
+
h(this, "onHintUse");
|
|
474
|
+
h(this, "onHintDismiss");
|
|
475
|
+
h(this, "onHintReposition", () => {
|
|
476
|
+
const e = this.launcherHintAction, n = this.hubLauncherHint;
|
|
477
|
+
!e || !n || !n.classList.contains("is-visible") || this.layoutHint(n, e);
|
|
478
|
+
});
|
|
479
|
+
h(this, "handleMessage", (e) => {
|
|
480
|
+
var i, o;
|
|
481
|
+
if (!Ee(this.agentOrigin, e.origin) || !oe(e.data)) return;
|
|
300
482
|
const n = e.data;
|
|
301
483
|
if (n.type === "ready") {
|
|
302
484
|
n.surface === "hub" ? (this.hubReady = !0, this.flush("hub")) : (this.widgetReady = !0, this.flush("widget"));
|
|
@@ -314,23 +496,23 @@ class ee {
|
|
|
314
496
|
this.updateLauncherStats(n.running, n.waiting), (i = this.onChildMessage) == null || i.call(this, n);
|
|
315
497
|
return;
|
|
316
498
|
}
|
|
317
|
-
(
|
|
499
|
+
(o = this.onChildMessage) == null || o.call(this, n);
|
|
318
500
|
});
|
|
319
|
-
this.agentOrigin =
|
|
501
|
+
this.agentOrigin = Pe(e), this.onChildMessage = n, this.onHintUse = i == null ? void 0 : i.onHintUse, this.onHintDismiss = i == null ? void 0 : i.onHintDismiss, window.addEventListener("message", this.handleMessage);
|
|
320
502
|
}
|
|
321
503
|
destroy() {
|
|
322
|
-
window.removeEventListener("message", this.handleMessage), this.removeHub(), this.closeWidget();
|
|
504
|
+
window.removeEventListener("message", this.handleMessage), this.unbindHintReposition(), this.removeHub(), this.closeWidget();
|
|
323
505
|
}
|
|
324
506
|
/** Launcher(宿主 DOM)+ 固定尺寸 Hub Panel(显隐用 CSS,不改 iframe 尺寸) */
|
|
325
507
|
mountHub() {
|
|
326
|
-
this.hubPanelOverlay || typeof document == "undefined" || (
|
|
508
|
+
this.hubPanelOverlay || typeof document == "undefined" || (Ie(), this.mountLauncher(), this.mountHubPanel());
|
|
327
509
|
}
|
|
328
510
|
openHubPanel() {
|
|
329
511
|
var e;
|
|
330
|
-
this.hubPanelOverlay && (this.hubPanelOpen = !0, this.hubPanelOverlay.classList.add("is-open"), (e = this.hubLauncherHint) == null || e.classList.remove("is-visible"), this.post("hub", { channel:
|
|
512
|
+
this.hubPanelOverlay && (this.hubPanelOpen = !0, this.hubPanelOverlay.classList.add("is-open"), (e = this.hubLauncherHint) == null || e.classList.remove("is-visible"), this.post("hub", { channel: O, type: "open-hub-panel" }), this.applyLauncherVisual());
|
|
331
513
|
}
|
|
332
514
|
closeHubPanel() {
|
|
333
|
-
this.hubPanelOverlay && (this.hubPanelOpen = !1, this.hubPanelOverlay.classList.remove("is-open"), this.setHubPanelExpanded(!1), this.post("hub", { channel:
|
|
515
|
+
this.hubPanelOverlay && (this.hubPanelOpen = !1, this.hubPanelOverlay.classList.remove("is-open"), this.setHubPanelExpanded(!1), this.post("hub", { channel: O, type: "close-hub-panel" }), this.updateLauncherHint(this.launcherHintAction), this.applyLauncherVisual());
|
|
334
516
|
}
|
|
335
517
|
setHubPanelExpanded(e) {
|
|
336
518
|
var i;
|
|
@@ -339,16 +521,15 @@ class ee {
|
|
|
339
521
|
n == null || n.classList.toggle("is-expanded", e);
|
|
340
522
|
}
|
|
341
523
|
updateLauncherHint(e) {
|
|
342
|
-
var s, o;
|
|
343
524
|
this.launcherHintAction = e;
|
|
344
525
|
const n = this.hubLauncherHint;
|
|
345
526
|
if (!n) return;
|
|
346
527
|
if (this.hubPanelOpen) {
|
|
347
|
-
n.classList.remove("is-visible");
|
|
528
|
+
n.classList.remove("is-visible", "is-anchored"), this.unbindHintReposition();
|
|
348
529
|
return;
|
|
349
530
|
}
|
|
350
531
|
if (!e || !e.hint.trim()) {
|
|
351
|
-
n.innerHTML = "", n.classList.remove("is-visible");
|
|
532
|
+
n.innerHTML = "", n.classList.remove("is-visible", "is-anchored"), this.unbindHintReposition();
|
|
352
533
|
return;
|
|
353
534
|
}
|
|
354
535
|
n.innerHTML = `
|
|
@@ -361,18 +542,67 @@ class ee {
|
|
|
361
542
|
</div>
|
|
362
543
|
</div>`;
|
|
363
544
|
const i = n.querySelector(".agent-host-hint-text");
|
|
364
|
-
i && (i.textContent = e.hint)
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
545
|
+
i && (i.textContent = e.hint);
|
|
546
|
+
const o = n.querySelector(".agent-host-hint-use"), s = n.querySelector(".agent-host-hint-dismiss"), c = (l) => l.preventDefault();
|
|
547
|
+
o == null || o.addEventListener("mousedown", c), s == null || s.addEventListener("mousedown", c), o == null || o.addEventListener("click", (l) => {
|
|
548
|
+
var u;
|
|
549
|
+
l.stopPropagation(), (u = this.onHintUse) == null || u.call(this, e.pageId, e.actionId);
|
|
550
|
+
}), s == null || s.addEventListener("click", (l) => {
|
|
551
|
+
var u;
|
|
552
|
+
l.stopPropagation(), (u = this.onHintDismiss) == null || u.call(this);
|
|
553
|
+
}), n.classList.add("is-visible"), this.layoutHint(n, e), this.bindHintReposition();
|
|
554
|
+
}
|
|
555
|
+
layoutHint(e, n) {
|
|
556
|
+
if (n.placement !== "anchor") {
|
|
557
|
+
e.classList.remove("is-anchored"), e.style.top = "", e.style.left = "";
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const i = xe(n.pageId, n.actionId);
|
|
561
|
+
if (!i) {
|
|
562
|
+
e.classList.remove("is-anchored"), e.style.top = "", e.style.left = "";
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
e.classList.add("is-anchored");
|
|
566
|
+
const o = 8, s = e.offsetWidth || 320, c = e.offsetHeight || 48;
|
|
567
|
+
let l = i.top, u = i.right + o;
|
|
568
|
+
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), e.style.top = `${Math.round(l)}px`, e.style.left = `${Math.round(u)}px`;
|
|
569
|
+
}
|
|
570
|
+
collectScrollParents(e) {
|
|
571
|
+
var o;
|
|
572
|
+
const n = [];
|
|
573
|
+
let i = (o = e == null ? void 0 : e.parentElement) != null ? o : null;
|
|
574
|
+
for (; i; ) {
|
|
575
|
+
const s = window.getComputedStyle(i), c = s.overflowY, l = s.overflowX;
|
|
576
|
+
/(auto|scroll|overlay)/.test(`${l} ${c}`) && n.push(i), i = i.parentElement;
|
|
577
|
+
}
|
|
578
|
+
return n;
|
|
579
|
+
}
|
|
580
|
+
bindHintReposition() {
|
|
581
|
+
var i, o;
|
|
582
|
+
if (typeof window == "undefined") return;
|
|
583
|
+
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);
|
|
584
|
+
const e = this.launcherHintAction;
|
|
585
|
+
for (const s of this.hintScrollParents)
|
|
586
|
+
s.removeEventListener("scroll", this.onHintReposition);
|
|
587
|
+
if (this.hintScrollParents = [], !e || e.placement !== "anchor") return;
|
|
588
|
+
const n = X(e.pageId, e.actionId);
|
|
589
|
+
this.hintScrollParents = this.collectScrollParents(n);
|
|
590
|
+
for (const s of this.hintScrollParents)
|
|
591
|
+
s.addEventListener("scroll", this.onHintReposition, { passive: !0 });
|
|
592
|
+
}
|
|
593
|
+
unbindHintReposition() {
|
|
594
|
+
var e, n;
|
|
595
|
+
if (typeof window != "undefined") {
|
|
596
|
+
this.hintRepositionBound && (window.removeEventListener("scroll", this.onHintReposition, !0), window.removeEventListener("resize", this.onHintReposition), (e = window.visualViewport) == null || e.removeEventListener("resize", this.onHintReposition), (n = window.visualViewport) == null || n.removeEventListener("scroll", this.onHintReposition), this.hintRepositionBound = !1);
|
|
597
|
+
for (const i of this.hintScrollParents)
|
|
598
|
+
i.removeEventListener("scroll", this.onHintReposition);
|
|
599
|
+
this.hintScrollParents = [];
|
|
600
|
+
}
|
|
371
601
|
}
|
|
372
602
|
mountLauncher() {
|
|
373
|
-
if (this.hubLauncher || document.getElementById(
|
|
603
|
+
if (this.hubLauncher || document.getElementById(p)) return;
|
|
374
604
|
const e = document.createElement("button");
|
|
375
|
-
if (e.id =
|
|
605
|
+
if (e.id = p, e.type = "button", e.title = "科研AI助手", e.setAttribute("aria-label", "科研AI助手"), e.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>', e.addEventListener("click", () => this.openHubPanel()), document.body.appendChild(e), this.hubLauncher = e, this.hubLauncherBadge = e.querySelector(".agent-host-launcher-badge"), document.getElementById("agent-host-launcher-hint"))
|
|
376
606
|
this.hubLauncherHint = document.getElementById("agent-host-launcher-hint");
|
|
377
607
|
else {
|
|
378
608
|
const n = document.createElement("div");
|
|
@@ -381,13 +611,13 @@ class ee {
|
|
|
381
611
|
}
|
|
382
612
|
mountHubPanel() {
|
|
383
613
|
const e = document.createElement("div");
|
|
384
|
-
e.id =
|
|
614
|
+
e.id = w;
|
|
385
615
|
const n = document.createElement("div");
|
|
386
616
|
n.className = "agent-host-hub-backdrop", n.addEventListener("click", () => this.closeHubPanel());
|
|
387
617
|
const i = document.createElement("div");
|
|
388
618
|
i.className = "agent-host-hub-panel-shell";
|
|
389
|
-
const
|
|
390
|
-
|
|
619
|
+
const o = document.createElement("iframe");
|
|
620
|
+
o.id = He, o.title = "科研AI助手", o.src = `${this.agentOrigin}/host/hub?embed=1&panel=1`, o.allow = "clipboard-read; clipboard-write", i.appendChild(o), e.appendChild(n), e.appendChild(i), document.body.appendChild(e), this.hubPanelOverlay = e, this.hubIframe = o;
|
|
391
621
|
}
|
|
392
622
|
updateLauncherStats(e, n) {
|
|
393
623
|
this.lastRunning = e, this.lastWaiting = n, this.applyLauncherVisual();
|
|
@@ -395,239 +625,145 @@ class ee {
|
|
|
395
625
|
applyLauncherVisual() {
|
|
396
626
|
const e = this.hubLauncher, n = this.hubLauncherBadge;
|
|
397
627
|
if (!e || !n) return;
|
|
398
|
-
const i = e.querySelector(".agent-host-launcher-icon"),
|
|
399
|
-
e.classList.toggle("is-pulse",
|
|
628
|
+
const i = e.querySelector(".agent-host-launcher-icon"), o = e.querySelector(".agent-host-launcher-bell"), s = this.lastRunning, c = this.lastWaiting, l = c > 0 && !this.hubPanelOpen;
|
|
629
|
+
e.classList.toggle("is-pulse", s > 0), e.classList.toggle("is-breathe", (s > 0 || c > 0) && !l), l ? (e.title = "有待确认事项,点击打开助手", e.setAttribute("aria-label", "有待确认事项,点击打开助手")) : (e.title = "科研AI助手", e.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"));
|
|
400
630
|
}
|
|
401
631
|
removeHub() {
|
|
402
632
|
var e, n, i;
|
|
403
|
-
(e = document.getElementById(
|
|
633
|
+
(e = document.getElementById(p)) == null || e.remove(), (n = document.getElementById("agent-host-launcher-hint")) == null || n.remove(), (i = document.getElementById(w)) == 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.hubPanelExpanded = !1, this.pendingHubMessages = [];
|
|
404
634
|
}
|
|
405
635
|
openWidget(e, n, i) {
|
|
406
636
|
this.closeWidget();
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
|
|
637
|
+
const o = document.createElement("div");
|
|
638
|
+
o.id = V, 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", (Z) => {
|
|
639
|
+
Z.target === o && this.closeWidget();
|
|
410
640
|
});
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
const
|
|
641
|
+
const s = document.createElement("iframe");
|
|
642
|
+
s.id = ke, s.title = e.title || e.workflow;
|
|
643
|
+
const c = new URLSearchParams({
|
|
414
644
|
embed: "1",
|
|
415
645
|
workflow: e.workflow,
|
|
416
646
|
host: e.host || "",
|
|
417
647
|
title: e.title || ""
|
|
418
648
|
});
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
channel:
|
|
649
|
+
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;
|
|
650
|
+
const l = {
|
|
651
|
+
channel: O,
|
|
422
652
|
type: "init",
|
|
423
653
|
token: n,
|
|
424
654
|
refreshToken: i
|
|
425
|
-
},
|
|
655
|
+
}, u = {
|
|
426
656
|
workflow: e.workflow,
|
|
427
657
|
title: e.title,
|
|
428
658
|
host: e.host,
|
|
429
|
-
prefilled: e.prefilled ?
|
|
430
|
-
hostContext: e.hostContext ?
|
|
659
|
+
prefilled: e.prefilled ? P(e.prefilled) : void 0,
|
|
660
|
+
hostContext: e.hostContext ? P(e.hostContext) : void 0,
|
|
431
661
|
sessionId: e.sessionId,
|
|
432
662
|
preferSandboxFiles: e.preferSandboxFiles
|
|
433
|
-
},
|
|
434
|
-
channel:
|
|
663
|
+
}, C = {
|
|
664
|
+
channel: O,
|
|
435
665
|
type: "open-widget",
|
|
436
|
-
payload:
|
|
666
|
+
payload: u
|
|
437
667
|
};
|
|
438
|
-
this.pendingWidgetMessages = [
|
|
668
|
+
this.pendingWidgetMessages = [l, C];
|
|
439
669
|
}
|
|
440
670
|
closeWidget() {
|
|
441
671
|
var e;
|
|
442
|
-
(e = document.getElementById(
|
|
672
|
+
(e = document.getElementById(V)) == null || e.remove(), this.widgetIframe = null, this.widgetReady = !1, this.pendingWidgetMessages = [];
|
|
443
673
|
}
|
|
444
674
|
sendToHub(e) {
|
|
445
675
|
this.post("hub", e);
|
|
446
676
|
}
|
|
447
677
|
post(e, n) {
|
|
448
|
-
var
|
|
449
|
-
const i = e === "hub" ? this.hubReady : this.widgetReady,
|
|
678
|
+
var c;
|
|
679
|
+
const i = e === "hub" ? this.hubReady : this.widgetReady, o = e === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages;
|
|
450
680
|
if (!i) {
|
|
451
|
-
|
|
681
|
+
o.push(n);
|
|
452
682
|
return;
|
|
453
683
|
}
|
|
454
|
-
const
|
|
455
|
-
(
|
|
684
|
+
const s = e === "hub" ? this.hubIframe : this.widgetIframe;
|
|
685
|
+
(c = s == null ? void 0 : s.contentWindow) == null || c.postMessage(n, T(this.agentOrigin));
|
|
456
686
|
}
|
|
457
687
|
flush(e) {
|
|
458
688
|
const n = e === "hub" ? this.pendingHubMessages : this.pendingWidgetMessages, i = e === "hub" ? this.hubIframe : this.widgetIframe;
|
|
459
689
|
if (!(i != null && i.contentWindow)) return;
|
|
460
|
-
const
|
|
690
|
+
const o = T(this.agentOrigin);
|
|
461
691
|
for (; n.length; ) {
|
|
462
|
-
const
|
|
463
|
-
|
|
692
|
+
const s = n.shift();
|
|
693
|
+
s && i.contentWindow.postMessage(s, o);
|
|
464
694
|
}
|
|
465
695
|
}
|
|
466
696
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const x = {}, H = {};
|
|
471
|
-
let f = null, L = !1;
|
|
472
|
-
function te(t, e) {
|
|
473
|
-
const n = (e || "").trim();
|
|
474
|
-
if (n) return n;
|
|
475
|
-
for (const i of t) {
|
|
476
|
-
if (!i.hostContext) continue;
|
|
477
|
-
const s = w(i.hostContext), o = s && typeof s == "object" ? String(s.refresh || "").trim() : "";
|
|
478
|
-
if (o) return o;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
function ne(t, e, n = {}) {
|
|
482
|
-
const i = t !== f;
|
|
483
|
-
i && (L = !1), x[t] = e, f = t, !i && e.some((o) => !o.enabled || o.enabled()) && (L = !1);
|
|
484
|
-
const s = te(e, n.refreshKey);
|
|
485
|
-
s && typeof n.onRefresh == "function" ? H[t] = { refreshKey: s, onRefresh: n.onRefresh } : delete H[t];
|
|
486
|
-
}
|
|
487
|
-
function ie(t) {
|
|
488
|
-
delete x[t], delete H[t], f === t && (f = null);
|
|
489
|
-
}
|
|
490
|
-
function se(t) {
|
|
491
|
-
const e = String(t || "").trim();
|
|
492
|
-
if (e) {
|
|
493
|
-
for (const n of Object.values(H))
|
|
494
|
-
if (n.refreshKey === e)
|
|
495
|
-
try {
|
|
496
|
-
n.onRefresh();
|
|
497
|
-
} catch (i) {
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function oe() {
|
|
502
|
-
for (const t of Object.keys(x)) delete x[t];
|
|
503
|
-
for (const t of Object.keys(H)) delete H[t];
|
|
504
|
-
f = null, L = !1;
|
|
505
|
-
}
|
|
506
|
-
function ae(t) {
|
|
507
|
-
t !== f && (L = !1), f = t;
|
|
508
|
-
}
|
|
509
|
-
function re() {
|
|
510
|
-
L = !0;
|
|
511
|
-
}
|
|
512
|
-
function j(t) {
|
|
513
|
-
return t.map((e) => ({
|
|
514
|
-
id: e.id,
|
|
515
|
-
workflow: e.workflow,
|
|
516
|
-
label: e.label,
|
|
517
|
-
host: e.host,
|
|
518
|
-
hint: e.hint ? w(e.hint) : void 0,
|
|
519
|
-
hostContext: e.hostContext ? k(w(e.hostContext)) : void 0,
|
|
520
|
-
prefilled: e.prefilled ? k(w(e.prefilled)) : void 0,
|
|
521
|
-
enabled: e.enabled ? e.enabled() : !0
|
|
522
|
-
}));
|
|
523
|
-
}
|
|
524
|
-
function T(t, e) {
|
|
525
|
-
const n = (x[t] || []).find((o) => o.id === e);
|
|
526
|
-
if (!n || n.enabled && !n.enabled()) return null;
|
|
527
|
-
const i = n.prefilled ? k(w(n.prefilled)) : void 0, s = (n.workflow || "").trim();
|
|
528
|
-
if (s === "edc_form_fill" && i && typeof i == "object") {
|
|
529
|
-
const o = i;
|
|
530
|
-
if (!o.sub_project_id && !o.subProjectId) return null;
|
|
531
|
-
}
|
|
532
|
-
if (s === "edc_crf_design" && i && typeof i == "object") {
|
|
533
|
-
const o = i;
|
|
534
|
-
if (!o.sub_project_id && !o.subProjectId) return null;
|
|
535
|
-
}
|
|
536
|
-
return {
|
|
537
|
-
workflow: n.workflow,
|
|
538
|
-
title: n.label,
|
|
539
|
-
host: n.host,
|
|
540
|
-
prefilled: i,
|
|
541
|
-
hostContext: n.hostContext ? k(w(n.hostContext)) : void 0
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
function le() {
|
|
545
|
-
return f;
|
|
546
|
-
}
|
|
547
|
-
function he() {
|
|
548
|
-
return Object.entries(x).map(([t, e]) => ({ pageId: t, actions: e }));
|
|
549
|
-
}
|
|
550
|
-
function ce() {
|
|
551
|
-
if (L || !f) return null;
|
|
552
|
-
const t = x[f] || [];
|
|
553
|
-
for (const e of t) {
|
|
554
|
-
if (e.enabled && !e.enabled()) continue;
|
|
555
|
-
const n = e.hint ? w(e.hint) : `可使用「${e.label}」`;
|
|
556
|
-
return { pageId: f, actionId: e.id, hint: n };
|
|
557
|
-
}
|
|
558
|
-
return null;
|
|
559
|
-
}
|
|
560
|
-
let r = {}, a = null, b = "", E = "", m = null;
|
|
561
|
-
function ue() {
|
|
562
|
-
const t = (r.agentOrigin || "").replace(/\/$/, "");
|
|
697
|
+
let a = {}, r = null, m = "", R = "", y = null;
|
|
698
|
+
function Ce() {
|
|
699
|
+
const t = (a.agentOrigin || "").replace(/\/$/, "");
|
|
563
700
|
if (!t)
|
|
564
701
|
throw new Error(
|
|
565
702
|
"Agent 前端地址未配置:请在 init({ agentOrigin }) 传入,或由宿主 BFF bootstrap 返回 agent_web_origin"
|
|
566
703
|
);
|
|
567
704
|
return t;
|
|
568
705
|
}
|
|
569
|
-
function
|
|
706
|
+
function J(t) {
|
|
570
707
|
var e;
|
|
571
|
-
t.agent_web_origin && (
|
|
572
|
-
}
|
|
573
|
-
function
|
|
574
|
-
return
|
|
575
|
-
if (
|
|
576
|
-
return
|
|
577
|
-
if (
|
|
578
|
-
if (
|
|
579
|
-
const t = yield
|
|
580
|
-
if (
|
|
708
|
+
t.agent_web_origin && (a.agentOrigin = t.agent_web_origin.replace(/\/$/, "")), t.agent_token && (m = t.agent_token), t.refresh_token && (R = t.refresh_token), (e = a.onBootstrap) == null || e.call(a, t);
|
|
709
|
+
}
|
|
710
|
+
function A() {
|
|
711
|
+
return f(this, null, function* () {
|
|
712
|
+
if (a.getToken)
|
|
713
|
+
return m = yield a.getToken(), m;
|
|
714
|
+
if (m) return m;
|
|
715
|
+
if (a.bootstrap) {
|
|
716
|
+
const t = yield a.bootstrap();
|
|
717
|
+
if (J(t), m) return m;
|
|
581
718
|
}
|
|
582
719
|
throw new Error("未连接 Agent:请配置 bootstrap 或 getToken");
|
|
583
720
|
});
|
|
584
721
|
}
|
|
585
|
-
function
|
|
586
|
-
if (
|
|
722
|
+
function H() {
|
|
723
|
+
if (a.agentOrigin)
|
|
587
724
|
try {
|
|
588
|
-
|
|
725
|
+
x().updateLauncherHint(ve());
|
|
589
726
|
} catch (t) {
|
|
590
727
|
}
|
|
591
728
|
}
|
|
592
|
-
function
|
|
593
|
-
const t =
|
|
594
|
-
return
|
|
729
|
+
function x() {
|
|
730
|
+
const t = Ce();
|
|
731
|
+
return r || (K(H), r = new Re(t, Ae, {
|
|
595
732
|
onHintUse: (e, n) => {
|
|
596
|
-
|
|
597
|
-
i && O(i);
|
|
733
|
+
D(e, n);
|
|
598
734
|
},
|
|
599
735
|
onHintDismiss: () => {
|
|
600
|
-
|
|
736
|
+
ge(), H();
|
|
601
737
|
}
|
|
602
|
-
}),
|
|
738
|
+
}), a.showHub !== !1 && r.mountHub()), r;
|
|
603
739
|
}
|
|
604
|
-
function
|
|
605
|
-
if (!(!
|
|
606
|
-
for (const { pageId: t, actions: e } of
|
|
607
|
-
|
|
740
|
+
function Oe() {
|
|
741
|
+
if (!(!r || !a.agentOrigin)) {
|
|
742
|
+
for (const { pageId: t, actions: e } of ye())
|
|
743
|
+
r.sendToHub({
|
|
608
744
|
channel: "agent-host",
|
|
609
745
|
type: "register-page",
|
|
610
746
|
pageId: t,
|
|
611
|
-
actions:
|
|
747
|
+
actions: Y(e)
|
|
612
748
|
});
|
|
613
|
-
|
|
749
|
+
r.sendToHub({
|
|
614
750
|
channel: "agent-host",
|
|
615
751
|
type: "set-page",
|
|
616
|
-
pageId:
|
|
617
|
-
}),
|
|
752
|
+
pageId: me()
|
|
753
|
+
}), H();
|
|
618
754
|
}
|
|
619
755
|
}
|
|
620
|
-
function
|
|
756
|
+
function Ae(t) {
|
|
621
757
|
var e;
|
|
622
|
-
if (t.type === "ready" && t.surface === "hub" &&
|
|
623
|
-
|
|
758
|
+
if (t.type === "ready" && t.surface === "hub" && A().then((n) => {
|
|
759
|
+
r == null || r.sendToHub({
|
|
624
760
|
channel: "agent-host",
|
|
625
761
|
type: "init",
|
|
626
762
|
token: n,
|
|
627
|
-
refreshToken:
|
|
628
|
-
}),
|
|
763
|
+
refreshToken: R || void 0
|
|
764
|
+
}), Oe();
|
|
629
765
|
}).catch(() => {
|
|
630
|
-
}), t.type === "started" && (
|
|
766
|
+
}), t.type === "started" && (r == null || r.closeWidget(), r == null || r.openHubPanel(), r == null || r.sendToHub({
|
|
631
767
|
channel: "agent-host",
|
|
632
768
|
type: "task-started",
|
|
633
769
|
taskId: t.taskId,
|
|
@@ -641,110 +777,145 @@ function fe(t) {
|
|
|
641
777
|
})), t.type === "complete") {
|
|
642
778
|
if (t.status === "success") {
|
|
643
779
|
const n = t.hostContext && t.hostContext.refresh;
|
|
644
|
-
|
|
780
|
+
de(n, {
|
|
781
|
+
taskId: t.taskId,
|
|
782
|
+
result: t.result,
|
|
783
|
+
hostContext: t.hostContext,
|
|
784
|
+
apply: t.apply
|
|
785
|
+
});
|
|
645
786
|
}
|
|
646
|
-
(e =
|
|
787
|
+
(e = a.onTaskComplete) == null || e.call(a, {
|
|
647
788
|
taskId: t.taskId,
|
|
648
789
|
status: t.status,
|
|
649
|
-
hostContext: t.hostContext
|
|
650
|
-
|
|
790
|
+
hostContext: t.hostContext,
|
|
791
|
+
result: t.result,
|
|
792
|
+
apply: t.apply
|
|
793
|
+
}), r == null || r.closeWidget();
|
|
651
794
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
795
|
+
t.type === "close" && (r == null || r.closeWidget()), t.type === "open-widget" && z(t.payload), t.type === "open-action" && D(t.pageId, t.actionId), t.type === "hub-stats" && (t.running, r == null || r.updateLauncherStats(t.running, t.waiting), H());
|
|
796
|
+
}
|
|
797
|
+
function D(t, e) {
|
|
798
|
+
return f(this, null, function* () {
|
|
799
|
+
const n = j(t, e);
|
|
800
|
+
if (!n) return;
|
|
801
|
+
if (G(n.action)) {
|
|
802
|
+
yield Se(n);
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
const i = we(t, e);
|
|
806
|
+
i && (yield z(i));
|
|
807
|
+
});
|
|
657
808
|
}
|
|
658
|
-
function
|
|
659
|
-
return
|
|
660
|
-
yield
|
|
661
|
-
const e =
|
|
809
|
+
function Se(t) {
|
|
810
|
+
return f(this, null, function* () {
|
|
811
|
+
yield L();
|
|
812
|
+
const e = yield A(), n = x();
|
|
813
|
+
n.openHubPanel(), n.sendToHub({
|
|
814
|
+
channel: "agent-host",
|
|
815
|
+
type: "init",
|
|
816
|
+
token: e,
|
|
817
|
+
refreshToken: R || void 0
|
|
818
|
+
}), n.sendToHub({
|
|
819
|
+
channel: "agent-host",
|
|
820
|
+
type: "run-direct",
|
|
821
|
+
workflow: t.action.workflow || t.action.skill || "",
|
|
822
|
+
title: t.action.label,
|
|
823
|
+
host: t.action.host || a.host,
|
|
824
|
+
skill: t.action.skill,
|
|
825
|
+
prefilled: t.prefilled,
|
|
826
|
+
hostContext: t.hostContext
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
function z(t) {
|
|
831
|
+
return f(this, null, function* () {
|
|
832
|
+
yield L(), a.prepareOpenWidget && (yield a.prepareOpenWidget());
|
|
833
|
+
const e = x(), n = yield A();
|
|
662
834
|
e.openWidget(
|
|
663
835
|
{
|
|
664
836
|
workflow: t.workflow,
|
|
665
837
|
title: t.title || t.label,
|
|
666
|
-
host: t.host ||
|
|
838
|
+
host: t.host || a.host,
|
|
667
839
|
prefilled: t.prefilled,
|
|
668
840
|
hostContext: t.hostContext,
|
|
669
841
|
sessionId: t.sessionId,
|
|
670
842
|
preferSandboxFiles: t.preferSandboxFiles
|
|
671
843
|
},
|
|
672
844
|
n,
|
|
673
|
-
|
|
845
|
+
R || void 0
|
|
674
846
|
);
|
|
675
847
|
});
|
|
676
848
|
}
|
|
677
|
-
function
|
|
678
|
-
return
|
|
679
|
-
|
|
849
|
+
function L() {
|
|
850
|
+
return f(this, null, function* () {
|
|
851
|
+
y && (yield y);
|
|
680
852
|
});
|
|
681
853
|
}
|
|
682
|
-
function
|
|
683
|
-
return
|
|
684
|
-
if (
|
|
685
|
-
const e = yield
|
|
686
|
-
|
|
854
|
+
function Te(t) {
|
|
855
|
+
return f(this, null, function* () {
|
|
856
|
+
if (a = _({ showHub: !0 }, t), a.bootstrap) {
|
|
857
|
+
const e = yield a.bootstrap();
|
|
858
|
+
J(e);
|
|
687
859
|
}
|
|
688
|
-
if (
|
|
860
|
+
if (a.agentOrigin && a.showHub !== !1 && typeof document != "undefined")
|
|
689
861
|
try {
|
|
690
|
-
|
|
691
|
-
const e = yield
|
|
692
|
-
|
|
862
|
+
x();
|
|
863
|
+
const e = yield A();
|
|
864
|
+
r == null || r.sendToHub({
|
|
693
865
|
channel: "agent-host",
|
|
694
866
|
type: "init",
|
|
695
867
|
token: e,
|
|
696
|
-
refreshToken:
|
|
868
|
+
refreshToken: R || void 0
|
|
697
869
|
});
|
|
698
870
|
} catch (e) {
|
|
699
871
|
}
|
|
700
872
|
});
|
|
701
873
|
}
|
|
702
|
-
const
|
|
874
|
+
const Me = {
|
|
703
875
|
init(t) {
|
|
704
|
-
return
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}), yield
|
|
876
|
+
return f(this, null, function* () {
|
|
877
|
+
y && (yield y), y = Te(t).finally(() => {
|
|
878
|
+
y = null;
|
|
879
|
+
}), yield y;
|
|
708
880
|
});
|
|
709
881
|
},
|
|
710
882
|
getToken() {
|
|
711
|
-
return
|
|
712
|
-
return yield
|
|
883
|
+
return f(this, null, function* () {
|
|
884
|
+
return yield L(), A();
|
|
713
885
|
});
|
|
714
886
|
},
|
|
715
|
-
registerPage(i,
|
|
716
|
-
return
|
|
717
|
-
yield
|
|
887
|
+
registerPage(i, o) {
|
|
888
|
+
return f(this, arguments, function* (t, e, n = {}) {
|
|
889
|
+
yield L(), ce(t, e, n), a.agentOrigin && x().sendToHub({
|
|
718
890
|
channel: "agent-host",
|
|
719
891
|
type: "register-page",
|
|
720
892
|
pageId: t,
|
|
721
|
-
actions:
|
|
722
|
-
}),
|
|
893
|
+
actions: Y(e)
|
|
894
|
+
}), H();
|
|
723
895
|
});
|
|
724
896
|
},
|
|
725
897
|
unregisterPage(t) {
|
|
726
|
-
return
|
|
727
|
-
yield
|
|
898
|
+
return f(this, null, function* () {
|
|
899
|
+
yield L(), ue(t), a.agentOrigin && (x().sendToHub({ channel: "agent-host", type: "unregister-page", pageId: t }), x().sendToHub({ channel: "agent-host", type: "set-page", pageId: null })), H();
|
|
728
900
|
});
|
|
729
901
|
},
|
|
730
902
|
setCurrentPage(t) {
|
|
731
|
-
return
|
|
732
|
-
yield
|
|
903
|
+
return f(this, null, function* () {
|
|
904
|
+
yield L(), pe(t), a.agentOrigin && x().sendToHub({ channel: "agent-host", type: "set-page", pageId: t }), H();
|
|
733
905
|
});
|
|
734
906
|
},
|
|
735
907
|
openAction(t, e) {
|
|
736
|
-
return
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
yield O(n);
|
|
908
|
+
return f(this, null, function* () {
|
|
909
|
+
if (!j(t, e)) throw new Error("当前操作不可用");
|
|
910
|
+
yield D(t, e);
|
|
740
911
|
});
|
|
741
912
|
},
|
|
742
913
|
openWorkflow(n) {
|
|
743
|
-
return
|
|
744
|
-
yield
|
|
914
|
+
return f(this, arguments, function* (t, e = {}) {
|
|
915
|
+
yield z(U(_({
|
|
745
916
|
workflow: t
|
|
746
917
|
}, e), {
|
|
747
|
-
host: e.host ||
|
|
918
|
+
host: e.host || a.host,
|
|
748
919
|
title: e.title || e.label || t
|
|
749
920
|
}));
|
|
750
921
|
});
|
|
@@ -753,20 +924,20 @@ const pe = {
|
|
|
753
924
|
* EDC AI 填表是否可打开:须 prefilled.sub_project_id + forms 列表(表单在 Widget 内选择)。
|
|
754
925
|
*/
|
|
755
926
|
canOpen(t, e = {}) {
|
|
756
|
-
const n = (t || "").trim(), i = e.prefilled || {},
|
|
927
|
+
const n = (t || "").trim(), i = e.prefilled || {}, o = String(i.sub_project_id || i.subProjectId || "").trim();
|
|
757
928
|
if (n === "edc_form_fill") {
|
|
758
|
-
const
|
|
759
|
-
return !!(
|
|
929
|
+
const s = i.forms;
|
|
930
|
+
return !!(o && Array.isArray(s) && s.length > 0);
|
|
760
931
|
}
|
|
761
|
-
return n === "edc_crf_design" ? !!
|
|
932
|
+
return n === "edc_crf_design" ? !!o : n === "sds_crf_schema_from_doc" ? !!String(i.index_id || i.indexId || "").trim() : n === "sds-project-remark" ? !!String(i.project_name || i.name || "").trim() : !0;
|
|
762
933
|
},
|
|
763
934
|
destroy() {
|
|
764
|
-
|
|
935
|
+
r == null || r.destroy(), r = null, m = "", R = "", a = {}, y = null, K(null), fe();
|
|
765
936
|
}
|
|
766
937
|
};
|
|
767
|
-
typeof window != "undefined" && (window.AgentHost =
|
|
938
|
+
typeof window != "undefined" && (window.AgentHost = Me);
|
|
768
939
|
export {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
940
|
+
O as AGENT_HOST_MSG,
|
|
941
|
+
Me as AgentHost,
|
|
942
|
+
oe as isAgentHostMessage
|
|
772
943
|
};
|