universal-plugin-hub 1.0.45 → 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/client/client.js +869 -456
- package/package.json +3 -2
- package/src/icons.js +132 -14
- package/src/index.js +2 -2
- package/src/install.js +426 -145
- package/src/oauth-bridge.js +8 -3
- package/src/oauth-store.js +60 -10
- package/src/oauth.js +28 -2
- package/src/parser.js +57 -26
- package/src/routes.js +21 -6
- package/src/store.js +23 -4
package/client/client.js
CHANGED
|
@@ -243,7 +243,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
243
243
|
const useSafeLayoutEffect = typeof useLayoutEffect === "function" ? useLayoutEffect : useEffect;
|
|
244
244
|
|
|
245
245
|
// ────────────────────────────── Styles ──────────────────────────────
|
|
246
|
-
const
|
|
246
|
+
const ICON_SHAPE_CSS = `
|
|
247
|
+
:root {
|
|
248
|
+
--cpm-icon-corner-shape: squircle;
|
|
249
|
+
--cpm-connector-icon-radius: calc(100% / 3);
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
|
|
253
|
+
const CSS = `${ICON_SHAPE_CSS}
|
|
247
254
|
/* ────────────────────────────── Light Theme (Default) ────────────────────────────── */
|
|
248
255
|
.cpm-root {
|
|
249
256
|
/* A damped spring (damping 0.62, ~8.4% overshoot) sampled into linear().
|
|
@@ -593,11 +600,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
593
600
|
pointer-events: none !important;
|
|
594
601
|
}
|
|
595
602
|
.cpm-tab.is-shifting {
|
|
596
|
-
transition: transform
|
|
603
|
+
transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), background .15s ease, color .15s ease !important;
|
|
597
604
|
will-change: transform;
|
|
598
605
|
}
|
|
599
606
|
.cpm-tab-drag-overlay {
|
|
600
607
|
position: fixed !important;
|
|
608
|
+
left: 0;
|
|
609
|
+
top: 0;
|
|
601
610
|
z-index: 9999999 !important;
|
|
602
611
|
pointer-events: none !important;
|
|
603
612
|
box-sizing: border-box !important;
|
|
@@ -618,7 +627,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
618
627
|
box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.32), 0 8px 16px -2px rgba(37, 99, 235, 0.25), 0 0 0 1px rgba(37, 99, 235, 0.4) !important;
|
|
619
628
|
backdrop-filter: blur(8px);
|
|
620
629
|
-webkit-backdrop-filter: blur(8px);
|
|
621
|
-
will-change:
|
|
630
|
+
will-change: transform;
|
|
622
631
|
}
|
|
623
632
|
.cpm-dark .cpm-tab-drag-overlay,
|
|
624
633
|
.cpm-tab-drag-overlay.cpm-dark {
|
|
@@ -1051,7 +1060,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1051
1060
|
.cpm-detail {
|
|
1052
1061
|
flex: 1;
|
|
1053
1062
|
overflow-y: auto;
|
|
1054
|
-
padding:
|
|
1063
|
+
padding: 11px 24px 28px 24px;
|
|
1055
1064
|
width: 100%;
|
|
1056
1065
|
display: flex;
|
|
1057
1066
|
flex-direction: column;
|
|
@@ -1088,6 +1097,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1088
1097
|
gap: 4px;
|
|
1089
1098
|
}
|
|
1090
1099
|
.cpm-back:hover { color: var(--cpm-text); }
|
|
1100
|
+
/* The top bar leaves 10px below its rule: 10 + 11 above Back matches
|
|
1101
|
+
the 21px below it, keeping Back centered without moving the title row. */
|
|
1102
|
+
.cpm-detail:not(.cpm-skill-detail) > .cpm-back { padding-bottom: 21px; }
|
|
1091
1103
|
.cpm-title-row {
|
|
1092
1104
|
display: flex;
|
|
1093
1105
|
align-items: center;
|
|
@@ -1303,7 +1315,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1303
1315
|
.cpm-manage {
|
|
1304
1316
|
flex: 1;
|
|
1305
1317
|
overflow-y: auto;
|
|
1306
|
-
padding:
|
|
1318
|
+
padding: 11px 24px 28px 24px;
|
|
1307
1319
|
width: 100%;
|
|
1308
1320
|
background: var(--cpm-bg);
|
|
1309
1321
|
display: flex;
|
|
@@ -1332,7 +1344,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1332
1344
|
display: flex;
|
|
1333
1345
|
align-items: center;
|
|
1334
1346
|
justify-content: space-between;
|
|
1335
|
-
margin-bottom:
|
|
1347
|
+
margin-bottom: 21px;
|
|
1336
1348
|
}
|
|
1337
1349
|
.cpm-meta {
|
|
1338
1350
|
display: flex;
|
|
@@ -1625,6 +1637,99 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
1625
1637
|
margin-top: 12px;
|
|
1626
1638
|
margin-bottom: 6px;
|
|
1627
1639
|
}
|
|
1640
|
+
.cpm-agent-list {
|
|
1641
|
+
display: grid;
|
|
1642
|
+
gap: .625rem;
|
|
1643
|
+
list-style: none;
|
|
1644
|
+
margin: .25rem 0 0;
|
|
1645
|
+
padding: 0;
|
|
1646
|
+
}
|
|
1647
|
+
.cpm-agent-item {
|
|
1648
|
+
min-inline-size: 0;
|
|
1649
|
+
padding: .875rem 1rem;
|
|
1650
|
+
border: 1px solid var(--cpm-border);
|
|
1651
|
+
border-radius: .875rem;
|
|
1652
|
+
background: var(--cpm-card-bg);
|
|
1653
|
+
}
|
|
1654
|
+
.cpm-agent-header, .cpm-agent-meta {
|
|
1655
|
+
display: flex;
|
|
1656
|
+
align-items: center;
|
|
1657
|
+
flex-wrap: wrap;
|
|
1658
|
+
gap: .375rem .625rem;
|
|
1659
|
+
}
|
|
1660
|
+
.cpm-agent-name {
|
|
1661
|
+
min-inline-size: 0;
|
|
1662
|
+
margin: 0;
|
|
1663
|
+
font-size: .9375rem;
|
|
1664
|
+
font-weight: 600;
|
|
1665
|
+
line-height: 1.4;
|
|
1666
|
+
letter-spacing: -.015em;
|
|
1667
|
+
color: var(--cpm-text);
|
|
1668
|
+
overflow-wrap: anywhere;
|
|
1669
|
+
}
|
|
1670
|
+
.cpm-agent-meta {
|
|
1671
|
+
min-inline-size: 0;
|
|
1672
|
+
max-inline-size: 100%;
|
|
1673
|
+
margin-inline-start: auto;
|
|
1674
|
+
color: var(--cpm-muted);
|
|
1675
|
+
font-size: .6875rem;
|
|
1676
|
+
line-height: 1.5;
|
|
1677
|
+
font-variant-numeric: tabular-nums;
|
|
1678
|
+
}
|
|
1679
|
+
.cpm-agent-model {
|
|
1680
|
+
box-sizing: border-box;
|
|
1681
|
+
max-inline-size: 100%;
|
|
1682
|
+
padding: .125rem .4375rem;
|
|
1683
|
+
border-radius: .375rem;
|
|
1684
|
+
background: var(--cpm-pill-bg);
|
|
1685
|
+
color: var(--cpm-text-sub);
|
|
1686
|
+
overflow-wrap: anywhere;
|
|
1687
|
+
}
|
|
1688
|
+
.cpm-agent-description {
|
|
1689
|
+
margin-block: .4375rem 0;
|
|
1690
|
+
font-size: .8125rem;
|
|
1691
|
+
line-height: 1.55;
|
|
1692
|
+
color: var(--cpm-text-sub);
|
|
1693
|
+
overflow-wrap: anywhere;
|
|
1694
|
+
}
|
|
1695
|
+
.cpm-agent-description .cpm-smart-md { font-size: inherit; line-height: inherit; color: inherit; }
|
|
1696
|
+
.cpm-agent-tools { display: grid; gap: .375rem; margin-block-start: .625rem; }
|
|
1697
|
+
.cpm-agent-tool-group {
|
|
1698
|
+
display: flex;
|
|
1699
|
+
align-items: baseline;
|
|
1700
|
+
flex-wrap: wrap;
|
|
1701
|
+
gap: .375rem .75rem;
|
|
1702
|
+
}
|
|
1703
|
+
.cpm-agent-tool-source {
|
|
1704
|
+
flex: 0 1 13rem;
|
|
1705
|
+
min-inline-size: 0;
|
|
1706
|
+
font-size: .6875rem;
|
|
1707
|
+
line-height: 1.6;
|
|
1708
|
+
color: var(--cpm-muted);
|
|
1709
|
+
overflow-wrap: anywhere;
|
|
1710
|
+
}
|
|
1711
|
+
.cpm-agent-tool-list {
|
|
1712
|
+
display: flex;
|
|
1713
|
+
flex: 1 1 24rem;
|
|
1714
|
+
flex-wrap: wrap;
|
|
1715
|
+
flex-wrap: balance;
|
|
1716
|
+
gap: .25rem .375rem;
|
|
1717
|
+
min-inline-size: 0;
|
|
1718
|
+
list-style: none;
|
|
1719
|
+
margin: 0;
|
|
1720
|
+
padding: 0;
|
|
1721
|
+
}
|
|
1722
|
+
.cpm-agent-tool-list > li { min-inline-size: 0; max-inline-size: 100%; }
|
|
1723
|
+
.cpm-agent-tool {
|
|
1724
|
+
display: block;
|
|
1725
|
+
padding: .125rem .375rem;
|
|
1726
|
+
border-radius: .3125rem;
|
|
1727
|
+
background: var(--cpm-pill-bg);
|
|
1728
|
+
font: .6875rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
1729
|
+
color: var(--cpm-text-sub);
|
|
1730
|
+
white-space: normal;
|
|
1731
|
+
overflow-wrap: anywhere;
|
|
1732
|
+
}
|
|
1628
1733
|
.cpm-skill-list { margin-top: 4px; }
|
|
1629
1734
|
.cpm-skill-item {
|
|
1630
1735
|
padding: 12px 2px;
|
|
@@ -2416,6 +2521,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2416
2521
|
}
|
|
2417
2522
|
@media (prefers-reduced-motion: reduce) {
|
|
2418
2523
|
.cpm-oauth-pending { animation: none; }
|
|
2524
|
+
.cpm-tab.is-shifting, .cpm-tab-drag-overlay { transition: none !important; }
|
|
2419
2525
|
/* The spring is decoration; the state change is the message. A user who
|
|
2420
2526
|
asked for less motion gets the knob in place immediately. */
|
|
2421
2527
|
.cpm-toggle, .cpm-toggle::after {
|
|
@@ -2552,7 +2658,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2552
2658
|
height: var(--del-size);
|
|
2553
2659
|
padding: 0;
|
|
2554
2660
|
border-radius: var(--del-radius);
|
|
2555
|
-
corner-shape:
|
|
2661
|
+
corner-shape: var(--cpm-icon-corner-shape);
|
|
2556
2662
|
/* The resting state already carries the squircle surface, so the control
|
|
2557
2663
|
reads as a button before the pointer arrives; hover only deepens it. */
|
|
2558
2664
|
border: 1px solid rgba(0, 0, 0, 0.07);
|
|
@@ -2813,14 +2919,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
2813
2919
|
width: 24px;
|
|
2814
2920
|
height: 24px;
|
|
2815
2921
|
flex: 0 0 24px;
|
|
2816
|
-
border-radius:
|
|
2922
|
+
border-radius: var(--cpm-connector-icon-radius);
|
|
2817
2923
|
overflow: hidden;
|
|
2818
2924
|
}
|
|
2819
2925
|
.cpm-connector-owner-icon > .cpm-card-icon {
|
|
2820
2926
|
width: 24px;
|
|
2821
2927
|
height: 24px;
|
|
2822
2928
|
flex: 0 0 24px;
|
|
2823
|
-
border-radius:
|
|
2929
|
+
border-radius: var(--cpm-connector-icon-radius);
|
|
2824
2930
|
box-shadow: none;
|
|
2825
2931
|
}
|
|
2826
2932
|
/* The fallback badge carries a hard-coded 34px <img>, which overflows a 24px
|
|
@@ -3377,23 +3483,62 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3377
3483
|
font-family: var(--cpm-mono, monospace);
|
|
3378
3484
|
}
|
|
3379
3485
|
|
|
3486
|
+
.cpm-mcp-discovery {
|
|
3487
|
+
display: inline-flex;
|
|
3488
|
+
align-items: center;
|
|
3489
|
+
flex-wrap: wrap;
|
|
3490
|
+
gap: 6px 8px;
|
|
3491
|
+
min-width: 0;
|
|
3492
|
+
max-width: 100%;
|
|
3493
|
+
color: var(--cpm-muted);
|
|
3494
|
+
font-size: 11.5px;
|
|
3495
|
+
line-height: 1.6;
|
|
3496
|
+
}
|
|
3497
|
+
.cpm-mcp-discovery.is-error { color: var(--cpm-text-secondary, var(--cpm-muted)); }
|
|
3498
|
+
.cpm-mcp-discovery-message { overflow-wrap: anywhere; }
|
|
3499
|
+
.cpm-mcp-retry {
|
|
3500
|
+
min-height: 24px;
|
|
3501
|
+
border: 1px solid var(--cpm-border);
|
|
3502
|
+
border-radius: 7px;
|
|
3503
|
+
background: var(--cpm-pill-bg);
|
|
3504
|
+
color: var(--cpm-text);
|
|
3505
|
+
padding: 2px 8px;
|
|
3506
|
+
font: inherit;
|
|
3507
|
+
font-weight: 500;
|
|
3508
|
+
cursor: pointer;
|
|
3509
|
+
transition: background 120ms ease, transform 100ms ease;
|
|
3510
|
+
}
|
|
3511
|
+
.cpm-mcp-retry:hover { background: var(--cpm-hover); }
|
|
3512
|
+
.cpm-mcp-retry:active { transform: scale(0.97); }
|
|
3513
|
+
.cpm-mcp-retry:focus-visible, .cpm-mcp-expand:focus-visible { outline: 2px solid #3b82f6; outline-offset: 3px; }
|
|
3514
|
+
@media (prefers-reduced-motion: reduce) {
|
|
3515
|
+
.cpm-toast { animation: none !important; }
|
|
3516
|
+
.cpm-mcp-discovery .cpm-spin-ring { animation: none; }
|
|
3517
|
+
.cpm-mcp-retry { transition: none; }
|
|
3518
|
+
.cpm-mcp-retry:active { transform: none; }
|
|
3519
|
+
}
|
|
3520
|
+
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
|
|
3521
|
+
.cpm-root .cpm-toast { background: var(--cpm-bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
|
|
3522
|
+
}
|
|
3523
|
+
|
|
3380
3524
|
.cpm-toast {
|
|
3381
|
-
position:
|
|
3525
|
+
position: absolute;
|
|
3382
3526
|
bottom: 28px;
|
|
3383
3527
|
left: 50%;
|
|
3384
3528
|
transform: translateX(-50%);
|
|
3385
|
-
background: rgba(255, 255, 255, 0.
|
|
3529
|
+
background: rgba(255, 255, 255, 0.72);
|
|
3386
3530
|
color: #09090b;
|
|
3387
3531
|
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
3388
3532
|
border-radius: 12px;
|
|
3389
3533
|
padding: 11px 16px;
|
|
3390
3534
|
font-size: 13px;
|
|
3391
3535
|
z-index: 100001;
|
|
3392
|
-
max-width: min(
|
|
3536
|
+
max-width: min(calc(100% - 32px), 500px);
|
|
3537
|
+
box-sizing: border-box;
|
|
3393
3538
|
width: max-content;
|
|
3394
|
-
box-shadow: 0
|
|
3395
|
-
-webkit-backdrop-filter: blur(20px) saturate(
|
|
3396
|
-
backdrop-filter: blur(20px) saturate(
|
|
3539
|
+
box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
|
|
3540
|
+
-webkit-backdrop-filter: blur(20px) saturate(180%);
|
|
3541
|
+
backdrop-filter: blur(20px) saturate(180%);
|
|
3397
3542
|
display: flex;
|
|
3398
3543
|
align-items: center;
|
|
3399
3544
|
gap: 20px;
|
|
@@ -3402,10 +3547,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3402
3547
|
user-select: none;
|
|
3403
3548
|
}
|
|
3404
3549
|
.cpm-dark .cpm-toast {
|
|
3405
|
-
background: rgba(
|
|
3550
|
+
background: rgba(55, 55, 57, 0.75);
|
|
3406
3551
|
color: #f4f4f5;
|
|
3407
|
-
|
|
3408
|
-
|
|
3552
|
+
backdrop-filter: blur(22px) saturate(180%);
|
|
3553
|
+
-webkit-backdrop-filter: blur(22px) saturate(180%);
|
|
3554
|
+
border: 1px solid var(--cpm-modal-border);
|
|
3555
|
+
box-shadow: var(--cpm-shadow);
|
|
3409
3556
|
}
|
|
3410
3557
|
@keyframes cpm-toast-in {
|
|
3411
3558
|
from { opacity: 0; transform: translate(-50%, 14px) scale(0.97); }
|
|
@@ -3425,6 +3572,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3425
3572
|
to { transform: rotate(360deg); }
|
|
3426
3573
|
}
|
|
3427
3574
|
.cpm-toast-content {
|
|
3575
|
+
text-align: center;
|
|
3428
3576
|
flex: 1;
|
|
3429
3577
|
min-width: 0;
|
|
3430
3578
|
display: flex;
|
|
@@ -3432,6 +3580,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3432
3580
|
justify-content: center;
|
|
3433
3581
|
}
|
|
3434
3582
|
.cpm-toast-title {
|
|
3583
|
+
justify-content: center;
|
|
3435
3584
|
color: #09090b;
|
|
3436
3585
|
font-size: 13px;
|
|
3437
3586
|
font-weight: 600;
|
|
@@ -3448,9 +3597,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3448
3597
|
font-size: 12px;
|
|
3449
3598
|
line-height: 1.4;
|
|
3450
3599
|
margin-top: 2px;
|
|
3451
|
-
white-space:
|
|
3452
|
-
overflow:
|
|
3453
|
-
text-overflow: ellipsis;
|
|
3600
|
+
white-space: normal;
|
|
3601
|
+
overflow-wrap: anywhere;
|
|
3454
3602
|
}
|
|
3455
3603
|
.cpm-dark .cpm-toast-body {
|
|
3456
3604
|
color: #a1a1aa;
|
|
@@ -3584,9 +3732,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3584
3732
|
if (!el) {
|
|
3585
3733
|
el = document.createElement("style");
|
|
3586
3734
|
el.id = "cpm-style";
|
|
3735
|
+
el.textContent = CSS;
|
|
3587
3736
|
document.head.appendChild(el);
|
|
3737
|
+
} else if (el.textContent !== CSS) {
|
|
3738
|
+
el.textContent = CSS;
|
|
3588
3739
|
}
|
|
3589
|
-
el.textContent = CSS;
|
|
3590
3740
|
}
|
|
3591
3741
|
|
|
3592
3742
|
function isDarkMode(ctx, rootEl) {
|
|
@@ -3659,6 +3809,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
3659
3809
|
let body = null;
|
|
3660
3810
|
try { body = await res.json(); } catch { /* no body */ }
|
|
3661
3811
|
if (!res.ok) throw new Error((body && body.error) || `HTTP ${res.status}`);
|
|
3812
|
+
if (body?.ok !== false && !body?.error && /^(POST|PUT|PATCH|DELETE)$/.test(options?.method || "") &&
|
|
3813
|
+
/^\/(plugins|mcps)(\/|$)/.test(path) && !/\/(verify|oauth-status|inspect|tools\/toggle)$/.test(path)) {
|
|
3814
|
+
document.dispatchEvent(new Event("uph-mcp-branding-changed"));
|
|
3815
|
+
}
|
|
3662
3816
|
return body;
|
|
3663
3817
|
}
|
|
3664
3818
|
|
|
@@ -4093,9 +4247,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4093
4247
|
// visible only on the rows that actually hit the network, which read as
|
|
4094
4248
|
// "these few icons reload every time".
|
|
4095
4249
|
const LOADED_AVATARS = new Set();
|
|
4096
|
-
// Only a successful load in this session may skip the placeholder. Restored
|
|
4097
|
-
// history helps fetch and decode quickly, but must not expose an empty box.
|
|
4098
|
-
const PAINTED_AVATARS = new Set();
|
|
4099
4250
|
const FAILED_ICON_URLS = new Map();
|
|
4100
4251
|
const LOADED_AVATARS_KEY = "cpm_loaded_icons_v1";
|
|
4101
4252
|
// Deferred: touching localStorage while this module is still being evaluated
|
|
@@ -4123,7 +4274,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4123
4274
|
}
|
|
4124
4275
|
function trackLoadedAvatar(url) {
|
|
4125
4276
|
if (!url || url.startsWith("data:")) return;
|
|
4126
|
-
PAINTED_AVATARS.add(url);
|
|
4127
4277
|
restoreLoadedAvatars();
|
|
4128
4278
|
// Only a real change is worth a write: a restart re-reports every icon it
|
|
4129
4279
|
// already knows, and rewriting an identical 2048-entry set on each boot is
|
|
@@ -4138,7 +4288,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4138
4288
|
}
|
|
4139
4289
|
function forgetLoadedAvatar(url) {
|
|
4140
4290
|
restoreLoadedAvatars();
|
|
4141
|
-
PAINTED_AVATARS.delete(url);
|
|
4142
4291
|
if (!LOADED_AVATARS.delete(url)) return;
|
|
4143
4292
|
loadedAvatarsDirty = true;
|
|
4144
4293
|
defer(persistLoadedAvatars);
|
|
@@ -4146,8 +4295,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4146
4295
|
|
|
4147
4296
|
function PluginIcon({ plugin, isDark, eager = false }) {
|
|
4148
4297
|
const candidates = useMemo(() => getPluginIconCandidates(plugin, isDark), [plugin, isDark]);
|
|
4149
|
-
const embedded = candidates.find((url) => url.startsWith("data:image/"));
|
|
4150
|
-
const fallback = embedded ? h("img", { src: embedded, alt: "", width: 38, height: 38, style: { width: "100%", height: "100%", objectFit: "contain" } }) : h(PluginIconFallback, { plugin, isDark });
|
|
4298
|
+
const embedded = plugin?.icons?.previews?.[candidates[0]] || candidates.find((url) => url.startsWith("data:image/"));
|
|
4299
|
+
const fallback = embedded ? h("img", { src: embedded, alt: "", width: 38, height: 38, decoding: "sync", style: { width: "100%", height: "100%", objectFit: "contain" } }) : h(PluginIconFallback, { plugin, isDark });
|
|
4151
4300
|
return candidates.length ? h(PluginIconImage, { key: candidates.join("|"), candidates, plugin, fallback, eager }) : fallback;
|
|
4152
4301
|
}
|
|
4153
4302
|
|
|
@@ -4155,21 +4304,24 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4155
4304
|
const [index, setIndex] = useState(0);
|
|
4156
4305
|
const [loaded, setLoaded] = useState("");
|
|
4157
4306
|
const avatarUrl = candidates.slice(index).find((url) => !(FAILED_ICON_URLS.get(url) > Date.now()));
|
|
4158
|
-
//
|
|
4159
|
-
//
|
|
4160
|
-
// `loaded` to "" and paint the placeholder until the same bytes were
|
|
4161
|
-
// decoded again, which flashed on every click. A restored entry that
|
|
4162
|
-
// has not yet loaded in this session still holds the placeholder, so
|
|
4163
|
-
// a cold start never paints an empty container either.
|
|
4307
|
+
// History controls scheduling, not visibility: a new <img> can still be
|
|
4308
|
+
// fetching or decoding even if this URL loaded on an earlier mount.
|
|
4164
4309
|
const known = !!avatarUrl && isKnownAvatar(avatarUrl);
|
|
4165
|
-
const
|
|
4166
|
-
const imgLoaded = avatarUrl && (avatarUrl.startsWith("data:") || painted || loaded === avatarUrl);
|
|
4310
|
+
const imgLoaded = avatarUrl && (avatarUrl.startsWith("data:") || loaded === avatarUrl);
|
|
4167
4311
|
return h("div", { className: "cpm-card-icon", style: { position: "relative", overflow: "hidden" } },
|
|
4168
4312
|
h("div", { className: "cpm-icon-underlay", "aria-hidden": true, style: { position: "absolute", inset: 0, opacity: imgLoaded ? 0 : 1 } }, fallback),
|
|
4169
4313
|
// A plugin-local icon is a same-origin disk read, so deferring it to
|
|
4170
4314
|
// the viewport buys nothing and costs a visible placeholder on scroll.
|
|
4171
4315
|
// Only remote avatars are worth deferring — and never above the fold.
|
|
4172
4316
|
avatarUrl && h("img", { key: avatarUrl, src: avatarUrl, alt: plugin?.displayName || plugin?.name || "", width: 38, height: 38, decoding: known ? "sync" : "async", loading: (eager || known || avatarUrl.indexOf("/api/plugin-icon") >= 0) ? "eager" : "lazy",
|
|
4317
|
+
ref: (image) => {
|
|
4318
|
+
// A memory-cached image can be ready at commit, before onLoad.
|
|
4319
|
+
// Confirm this element before paint to avoid a fallback flash.
|
|
4320
|
+
if (image?.complete && image.naturalWidth > 0 && loaded !== avatarUrl) {
|
|
4321
|
+
trackLoadedAvatar(avatarUrl);
|
|
4322
|
+
setLoaded(avatarUrl);
|
|
4323
|
+
}
|
|
4324
|
+
},
|
|
4173
4325
|
style: { position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "contain", borderRadius: "inherit", opacity: imgLoaded ? 1 : 0 },
|
|
4174
4326
|
onLoad: () => { trackLoadedAvatar(avatarUrl); setLoaded(avatarUrl); },
|
|
4175
4327
|
onError: () => {
|
|
@@ -4256,7 +4408,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4256
4408
|
h("div", { className: "cpm-card-name" },
|
|
4257
4409
|
h("span", { className: "cpm-card-name-text" }, plugin.displayName || plugin.name),
|
|
4258
4410
|
),
|
|
4259
|
-
h("div", { className: "cpm-card-desc" }, plugin.description || (plugin.author ? `by ${plugin.author}` : "")),
|
|
4411
|
+
h("div", { className: "cpm-card-desc" }, plugin.shortDescription || plugin.description || (plugin.author ? `by ${plugin.author}` : "")),
|
|
4260
4412
|
),
|
|
4261
4413
|
action || (installed
|
|
4262
4414
|
? h("button", {
|
|
@@ -4278,7 +4430,41 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4278
4430
|
onClick: e => e.stopPropagation(), onChange: e => { setInteractive(true); onToggle(skill, e.currentTarget.checked); } });
|
|
4279
4431
|
}
|
|
4280
4432
|
|
|
4281
|
-
function
|
|
4433
|
+
function useRememberedDetailScroll(identity, containerRef, page, updateMask, content) {
|
|
4434
|
+
useLayoutEffect(() => {
|
|
4435
|
+
const el = containerRef.current;
|
|
4436
|
+
if (!el) return;
|
|
4437
|
+
const positions = page ? (page.scrollPositions ||= {}) : {};
|
|
4438
|
+
let pending = positions[identity] || 0;
|
|
4439
|
+
const restore = () => {
|
|
4440
|
+
if (pending !== null) {
|
|
4441
|
+
el.scrollTop = pending;
|
|
4442
|
+
if (el.scrollTop === pending) pending = null;
|
|
4443
|
+
}
|
|
4444
|
+
updateMask();
|
|
4445
|
+
};
|
|
4446
|
+
const save = () => { if (pending === null) positions[identity] = el.scrollTop; };
|
|
4447
|
+
const interact = () => { pending = null; save(); };
|
|
4448
|
+
restore();
|
|
4449
|
+
el.addEventListener?.("scroll", save);
|
|
4450
|
+
el.addEventListener?.("wheel", interact, { passive: true });
|
|
4451
|
+
el.addEventListener?.("pointerdown", interact);
|
|
4452
|
+
el.addEventListener?.("keydown", interact);
|
|
4453
|
+
const observer = typeof ResizeObserver === "function" ? new ResizeObserver(restore) : null;
|
|
4454
|
+
observer?.observe(el);
|
|
4455
|
+
Array.from(el.children || []).forEach(child => observer?.observe(child));
|
|
4456
|
+
return () => {
|
|
4457
|
+
save();
|
|
4458
|
+
observer?.disconnect();
|
|
4459
|
+
el.removeEventListener?.("scroll", save);
|
|
4460
|
+
el.removeEventListener?.("wheel", interact);
|
|
4461
|
+
el.removeEventListener?.("pointerdown", interact);
|
|
4462
|
+
el.removeEventListener?.("keydown", interact);
|
|
4463
|
+
};
|
|
4464
|
+
}, [identity, containerRef, page, updateMask, content]);
|
|
4465
|
+
}
|
|
4466
|
+
|
|
4467
|
+
function useDetailScrollMask(identity, containerRef, content, scrollState) {
|
|
4282
4468
|
const localRef = useRef(null);
|
|
4283
4469
|
const detailRef = containerRef || localRef;
|
|
4284
4470
|
const [maskClass, setMaskClass] = useState(" mask-bottom");
|
|
@@ -4287,10 +4473,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4287
4473
|
if (!el) return;
|
|
4288
4474
|
setMaskClass(el.scrollHeight - el.clientHeight > 4 && el.scrollTop < el.scrollHeight - el.clientHeight - 4 ? " mask-bottom" : "");
|
|
4289
4475
|
}, [detailRef]);
|
|
4290
|
-
|
|
4291
|
-
if (detailRef.current) detailRef.current.scrollTop = 0;
|
|
4292
|
-
updateMask();
|
|
4293
|
-
}, [identity, detailRef, updateMask]);
|
|
4476
|
+
useRememberedDetailScroll(identity, detailRef, scrollState, updateMask, content);
|
|
4294
4477
|
useLayoutEffect(() => {
|
|
4295
4478
|
updateMask();
|
|
4296
4479
|
const el = detailRef.current;
|
|
@@ -4302,11 +4485,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4302
4485
|
return { detailRef, maskClass, updateMask };
|
|
4303
4486
|
}
|
|
4304
4487
|
|
|
4305
|
-
function SkillDetail({ skill, onBack, onToggle, onRemove, busy, isDark, containerRef }) {
|
|
4488
|
+
function SkillDetail({ skill, onBack, onToggle, onRemove, busy, isDark, containerRef, scrollState }) {
|
|
4306
4489
|
const [detail, setDetail] = useState(null);
|
|
4307
4490
|
const [error, setError] = useState("");
|
|
4308
4491
|
const [removing, setRemoving] = useState(false);
|
|
4309
|
-
const { detailRef, maskClass, updateMask } = useDetailScrollMask(skill.id, containerRef, detail || error);
|
|
4492
|
+
const { detailRef, maskClass, updateMask } = useDetailScrollMask(skill.id, containerRef, detail || error, scrollState);
|
|
4310
4493
|
useEffect(() => {
|
|
4311
4494
|
let live = true;
|
|
4312
4495
|
setDetail(null); setError("");
|
|
@@ -4522,23 +4705,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4522
4705
|
h("polyline", { points: "15 18 9 12 15 6" }),
|
|
4523
4706
|
);
|
|
4524
4707
|
|
|
4525
|
-
const IconMore = ({ size = 14, color = "currentColor" }) =>
|
|
4526
|
-
h("svg", {
|
|
4527
|
-
width: size,
|
|
4528
|
-
height: size,
|
|
4529
|
-
viewBox: "0 0 24 24",
|
|
4530
|
-
fill: "none",
|
|
4531
|
-
stroke: color,
|
|
4532
|
-
strokeWidth: 2,
|
|
4533
|
-
strokeLinecap: "round",
|
|
4534
|
-
strokeLinejoin: "round",
|
|
4535
|
-
style: { flexShrink: 0 },
|
|
4536
|
-
},
|
|
4537
|
-
h("circle", { cx: 12, cy: 12, r: 1.3, fill: "currentColor" }),
|
|
4538
|
-
h("circle", { cx: 12, cy: 5, r: 1.3, fill: "currentColor" }),
|
|
4539
|
-
h("circle", { cx: 12, cy: 19, r: 1.3, fill: "currentColor" }),
|
|
4540
|
-
);
|
|
4541
|
-
|
|
4542
4708
|
const IconEye = ({ size = 14, color = "currentColor" }) =>
|
|
4543
4709
|
h("svg", {
|
|
4544
4710
|
width: size,
|
|
@@ -4829,8 +4995,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4829
4995
|
const SESSION_STORE = {
|
|
4830
4996
|
view: { type: "browse" },
|
|
4831
4997
|
sourceViews: {},
|
|
4832
|
-
|
|
4833
|
-
prevView: null,
|
|
4998
|
+
browseSortSnapshots: Object.create(null),
|
|
4834
4999
|
query: "",
|
|
4835
5000
|
filter: "all",
|
|
4836
5001
|
sortBy: "default",
|
|
@@ -4857,10 +5022,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4857
5022
|
|
|
4858
5023
|
const [isDark, setIsDark] = useState(getEffectiveTheme);
|
|
4859
5024
|
const [view, setViewRaw] = useState(() => SESSION_STORE.view);
|
|
4860
|
-
const [manageFor, setManageForRaw] = useState(() => SESSION_STORE.manageFor);
|
|
4861
|
-
const [manageTab, setManageTab] = useState(null);
|
|
4862
|
-
const [manageConnector, setManageConnector] = useState(null);
|
|
4863
|
-
const [prevView, setPrevViewRaw] = useState(() => SESSION_STORE.prevView);
|
|
4864
5025
|
|
|
4865
5026
|
// Persistent browse state across views and sidebar tab switching
|
|
4866
5027
|
const [query, setQueryRaw] = useState(() => SESSION_STORE.query);
|
|
@@ -4900,16 +5061,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4900
5061
|
setViewRaw(targetView);
|
|
4901
5062
|
}, []);
|
|
4902
5063
|
|
|
4903
|
-
const setManageFor = useCallback((m) => {
|
|
4904
|
-
SESSION_STORE.manageFor = m;
|
|
4905
|
-
setManageForRaw(m);
|
|
4906
|
-
}, []);
|
|
4907
|
-
|
|
4908
|
-
const setPrevView = useCallback((pv) => {
|
|
4909
|
-
SESSION_STORE.prevView = pv;
|
|
4910
|
-
setPrevViewRaw(pv);
|
|
4911
|
-
}, []);
|
|
4912
|
-
|
|
4913
5064
|
const setQuery = useCallback((q) => {
|
|
4914
5065
|
SESSION_STORE.query = q;
|
|
4915
5066
|
setQueryRaw(q);
|
|
@@ -4957,7 +5108,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
4957
5108
|
}, []);
|
|
4958
5109
|
|
|
4959
5110
|
useEffect(() => {
|
|
4960
|
-
ensureCss();
|
|
4961
5111
|
const update = () => setIsDark(getEffectiveTheme());
|
|
4962
5112
|
update();
|
|
4963
5113
|
const raf = requestAnimationFrame(update);
|
|
@@ -5083,8 +5233,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5083
5233
|
// The plugin panel itself is being closed (MarketApp unmounts). Reset
|
|
5084
5234
|
// the scroll memory so a fresh open of the panel starts at the top —
|
|
5085
5235
|
// the user explicitly wants panel close/reopen to reset scroll. This
|
|
5086
|
-
// does NOT run
|
|
5087
|
-
// swaps BrowseView/ManagePage inside the same MarketApp), so returning
|
|
5236
|
+
// does NOT run when opening management inside BrowseView, so returning
|
|
5088
5237
|
// from manage still restores the saved position.
|
|
5089
5238
|
useEffect(() => {
|
|
5090
5239
|
return () => {
|
|
@@ -5095,21 +5244,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5095
5244
|
};
|
|
5096
5245
|
}, []);
|
|
5097
5246
|
|
|
5098
|
-
const openManage = useCallback((record, fromView, tab, connector) => {
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
}, [
|
|
5104
|
-
|
|
5105
|
-
const closeManage = useCallback(() => {
|
|
5106
|
-
setManageFor(null);
|
|
5107
|
-
if (prevView && prevView.type === "detail") {
|
|
5108
|
-
setView(prevView);
|
|
5109
|
-
} else {
|
|
5110
|
-
setView({ type: "browse", sourceId: activeSourceId });
|
|
5111
|
-
}
|
|
5112
|
-
}, [prevView, setManageFor, setView, activeSourceId]);
|
|
5247
|
+
const openManage = useCallback((record, fromView, tab, connector, returnToMcp = false) => {
|
|
5248
|
+
if (!record) return;
|
|
5249
|
+
setView({ type: "manage", sourceId: activeSourceId, pluginName: record.name,
|
|
5250
|
+
initialTab: tab || null, initialConnector: connector || null,
|
|
5251
|
+
returnView: returnToMcp || fromView?.type === "detail" ? fromView : undefined, returnToMcp });
|
|
5252
|
+
}, [activeSourceId, setView]);
|
|
5113
5253
|
|
|
5114
5254
|
return h("div", {
|
|
5115
5255
|
ref: rootRef,
|
|
@@ -5117,7 +5257,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5117
5257
|
onMouseOver: handleRootMouseOver,
|
|
5118
5258
|
onMouseOut: handleRootMouseOut,
|
|
5119
5259
|
},
|
|
5120
|
-
|
|
5260
|
+
h(BrowseView, {
|
|
5121
5261
|
view,
|
|
5122
5262
|
setView,
|
|
5123
5263
|
state,
|
|
@@ -5139,20 +5279,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5139
5279
|
setRows,
|
|
5140
5280
|
scrollTopRef,
|
|
5141
5281
|
}),
|
|
5142
|
-
manageFor && h(ManagePage, {
|
|
5143
|
-
record: state.plugins.find((p) => p.name === manageFor) || null,
|
|
5144
|
-
state,
|
|
5145
|
-
rows,
|
|
5146
|
-
isDark,
|
|
5147
|
-
refreshState,
|
|
5148
|
-
showToast,
|
|
5149
|
-
initialTab: manageTab,
|
|
5150
|
-
initialConnector: manageConnector,
|
|
5151
|
-
onBack: closeManage,
|
|
5152
|
-
onClose: closeManage,
|
|
5153
|
-
}),
|
|
5154
5282
|
toast && h("div", {
|
|
5155
|
-
className: "cpm-toast",
|
|
5283
|
+
className: "cpm-toast", role: "status", "aria-live": "polite", "aria-atomic": "true",
|
|
5156
5284
|
},
|
|
5157
5285
|
h("div", { className: "cpm-toast-content" },
|
|
5158
5286
|
h("div", { className: "cpm-toast-title" },
|
|
@@ -5779,7 +5907,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5779
5907
|
setState,
|
|
5780
5908
|
refreshState,
|
|
5781
5909
|
showToast,
|
|
5782
|
-
openManage,
|
|
5910
|
+
openManage: openManageView,
|
|
5783
5911
|
onInstalled,
|
|
5784
5912
|
isDark,
|
|
5785
5913
|
query,
|
|
@@ -5817,6 +5945,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5817
5945
|
SESSION_STORE.mcpsOpen = v;
|
|
5818
5946
|
setMcpsOpenRaw(v);
|
|
5819
5947
|
}, []);
|
|
5948
|
+
const openManage = (record, fromView, tab, connector) => {
|
|
5949
|
+
setMcpsOpen(false);
|
|
5950
|
+
openManageView(record, mcpsOpen ? view : fromView, tab, connector, mcpsOpen);
|
|
5951
|
+
};
|
|
5820
5952
|
const [editMcp, setEditMcp] = useState(null);
|
|
5821
5953
|
// Plugin name when the editor was opened from a plugin-provided server;
|
|
5822
5954
|
// null means the editor targets a user-added MCP.
|
|
@@ -5868,47 +6000,42 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5868
6000
|
), [state.plugins]);
|
|
5869
6001
|
const hasMcps = mcps.some((m) => m?.name) || pluginMcpRows.length > 0;
|
|
5870
6002
|
|
|
5871
|
-
|
|
6003
|
+
const loadGlobalTools = useCallback(async (owner, connectorName, forceFresh = false) => {
|
|
5872
6004
|
const key = `${owner}::${connectorName}`;
|
|
5873
6005
|
const cached = GLOBAL_MCP_TOOLS_CACHE[key];
|
|
5874
|
-
const hasCachedTools = Array.isArray(cached?.tools) && cached.tools.length > 0;
|
|
5875
|
-
if (!hasCachedTools) {
|
|
5876
6006
|
setGlobalToolData((prev) => ({ ...prev, [key]: { ...(prev[key] || {}), loading: true, error: null } }));
|
|
5877
|
-
}
|
|
5878
6007
|
try {
|
|
5879
6008
|
const url = owner === "user-mcp"
|
|
5880
6009
|
? `/mcps/${encodeURIComponent(connectorName)}/tools`
|
|
5881
6010
|
: `/plugins/${encodeURIComponent(owner)}/connectors/${encodeURIComponent(connectorName)}/tools`;
|
|
5882
|
-
|
|
6011
|
+
const res = await api(url + (forceFresh ? "?fresh=1" : ""));
|
|
5883
6012
|
const tools = Array.isArray(res.tools) ? res.tools : [];
|
|
5884
6013
|
const disabledTools = Array.isArray(res.disabledTools) ? res.disabledTools : [];
|
|
5885
|
-
|
|
6014
|
+
if (res.ok) saveMcpToolsCache(key, { tools, disabledTools });
|
|
5886
6015
|
setGlobalToolData((prev) => ({
|
|
5887
6016
|
...prev,
|
|
5888
6017
|
[key]: {
|
|
5889
6018
|
loading: false,
|
|
5890
6019
|
error: res.ok ? null : (res.message || "获取能力列表失败"),
|
|
5891
|
-
|
|
6020
|
+
tools: res.ok ? tools : (prev[key]?.tools || tools),
|
|
5892
6021
|
disabledTools,
|
|
5893
6022
|
},
|
|
5894
6023
|
}));
|
|
5895
6024
|
} catch (e) {
|
|
5896
|
-
|
|
5897
|
-
setGlobalToolData((prev) => ({ ...prev, [key]: { loading: false, error: e.message, tools: [], disabledTools: [] } }));
|
|
5898
|
-
}
|
|
6025
|
+
setGlobalToolData((prev) => ({ ...prev, [key]: { ...(prev[key] || cached), loading: false, error: e.message } }));
|
|
5899
6026
|
}
|
|
5900
6027
|
}, []);
|
|
5901
6028
|
|
|
5902
|
-
|
|
6029
|
+
useAutoMcpTools([
|
|
6030
|
+
...pluginMcpRows.map(row => ({ owner: row.owner, name: row.name, connected: row.connected, revision: JSON.stringify([row.record.installedAt, row.conn]) })),
|
|
6031
|
+
...mcps.map(row => ({ owner: "user-mcp", name: row.name, connected: row.enabled === true, revision: JSON.stringify(row) })),
|
|
6032
|
+
], loadGlobalTools);
|
|
6033
|
+
|
|
6034
|
+
const toggleGlobalExpand = useCallback((owner, connectorName) => {
|
|
5903
6035
|
const key = `${owner}::${connectorName}`;
|
|
5904
6036
|
const willExpand = !globalExpanded[key];
|
|
5905
6037
|
setGlobalExpanded((prev) => ({ ...prev, [key]: willExpand }));
|
|
5906
|
-
|
|
5907
|
-
// spawns a local MCP server.
|
|
5908
|
-
if (willExpand && (!globalToolData[key] || !globalToolData[key].tools || globalToolData[key].tools.length === 0)) {
|
|
5909
|
-
loadGlobalTools(owner, connectorName);
|
|
5910
|
-
}
|
|
5911
|
-
}, [globalExpanded, globalToolData, loadGlobalTools]);
|
|
6038
|
+
}, [globalExpanded]);
|
|
5912
6039
|
|
|
5913
6040
|
const toggleGlobalTool = useCallback(async (owner, connectorName, toolName) => {
|
|
5914
6041
|
const key = `${owner}::${connectorName}`;
|
|
@@ -5948,7 +6075,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5948
6075
|
const info = globalToolData[key];
|
|
5949
6076
|
const toolsList = info?.tools || [];
|
|
5950
6077
|
const disabledTools = info?.disabledTools || [];
|
|
5951
|
-
const activeCount = toolsList.filter((t) => !disabledTools.includes(typeof t === "string" ? t : t.name)).length;
|
|
5952
6078
|
|
|
5953
6079
|
const onToggleServer = async () => {
|
|
5954
6080
|
try {
|
|
@@ -6018,18 +6144,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6018
6144
|
// inline-flex so the pill's text baseline is the one that aligns,
|
|
6019
6145
|
// instead of the padded box being pushed around as a block.
|
|
6020
6146
|
h("span", { style: { display: "inline-flex", alignItems: "center", fontSize: 11, lineHeight: "16px", padding: "2px 8px", borderRadius: 6, background: "var(--cpm-pill-bg)", color: "var(--cpm-text)", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", flexShrink: 0 } }, transport === "stdio" ? "stdio" : "http"),
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
connected && h("button", {
|
|
6024
|
-
type: "button",
|
|
6025
|
-
className: "cpm-mcp-expand",
|
|
6026
|
-
onClick: () => toggleGlobalExpand(owner, name),
|
|
6027
|
-
},
|
|
6028
|
-
h("span", null, toolsList.length > 0
|
|
6029
|
-
? `${activeCount} tools enabled${disabledTools.length > 0 ? ` (${disabledTools.length} disabled)` : ""}`
|
|
6030
|
-
: "Tools"),
|
|
6031
|
-
h("span", { className: "cpm-connector-collapse-btn" + (isExpanded ? " is-expanded" : "") }, h(IconArrow, { size: 10 })),
|
|
6032
|
-
),
|
|
6147
|
+
connected && h(McpDiscoveryStatus, { info, expanded: isExpanded,
|
|
6148
|
+
onExpand: () => toggleGlobalExpand(owner, name), onRetry: () => loadGlobalTools(owner, name, true) }),
|
|
6033
6149
|
),
|
|
6034
6150
|
h("button", {
|
|
6035
6151
|
type: "button",
|
|
@@ -6045,12 +6161,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6045
6161
|
onClick: onToggleServer,
|
|
6046
6162
|
}),
|
|
6047
6163
|
),
|
|
6048
|
-
|
|
6164
|
+
isExpanded && connected && info && !info.loading && !info.error && h(McpToolsPanel, {
|
|
6049
6165
|
loading: info?.loading,
|
|
6050
6166
|
error: info?.error,
|
|
6051
6167
|
tools: toolsList,
|
|
6052
6168
|
disabledTools,
|
|
6053
|
-
|
|
6169
|
+
onRetry: () => loadGlobalTools(owner, name, true),
|
|
6054
6170
|
onHoverTool: (tool, rect, anchor, pointer, keyboard) => globalHover.enter({ owner, connectorName: name, tool, rect }, anchor, pointer, keyboard),
|
|
6055
6171
|
onHoverEnd: (anchor) => globalHover.leave(anchor),
|
|
6056
6172
|
onToggleTool: (toolName) => toggleGlobalTool(owner, name, toolName),
|
|
@@ -6375,6 +6491,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6375
6491
|
const autoScrollRafRef = useRef(null);
|
|
6376
6492
|
const isLongPressTriggeredRef = useRef(false);
|
|
6377
6493
|
const snapTimerRef = useRef(null);
|
|
6494
|
+
const snapFinishRef = useRef(null);
|
|
6495
|
+
const dragOverlayRef = useRef(null);
|
|
6378
6496
|
|
|
6379
6497
|
const stopAutoScroll = useCallback(() => {
|
|
6380
6498
|
if (autoScrollRafRef.current) {
|
|
@@ -6397,45 +6515,27 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6397
6515
|
|
|
6398
6516
|
// Visual center of dragged tab in container scroll content coordinate
|
|
6399
6517
|
const contentCenter = (overlayX + (draggedWidth / 2)) - cRect.left + curScroll;
|
|
6400
|
-
const numSlots = baseSlots.length;
|
|
6401
|
-
|
|
6402
6518
|
let newIdx = fromIndex;
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
const lastCenter = Math.min(
|
|
6416
|
-
baseSlots[lastMoveable].offsetLeft + (baseSlots[lastMoveable].width / 2),
|
|
6417
|
-
curScroll + cRect.width
|
|
6418
|
-
);
|
|
6419
|
-
|
|
6420
|
-
if (contentCenter <= firstCenter) {
|
|
6421
|
-
newIdx = firstMoveable;
|
|
6422
|
-
} else if (contentCenter >= lastCenter) {
|
|
6423
|
-
newIdx = lastMoveable;
|
|
6424
|
-
} else {
|
|
6425
|
-
newIdx = firstMoveable;
|
|
6426
|
-
for (let i = firstMoveable; i < lastMoveable; i++) {
|
|
6427
|
-
const currentSlot = baseSlots[i];
|
|
6428
|
-
const nextSlot = baseSlots[i + 1];
|
|
6429
|
-
const midBoundary = (currentSlot.offsetLeft + (currentSlot.width / 2) + nextSlot.offsetLeft + (nextSlot.width / 2)) / 2;
|
|
6430
|
-
if (contentCenter > midBoundary) {
|
|
6431
|
-
newIdx = i + 1;
|
|
6432
|
-
}
|
|
6433
|
-
}
|
|
6519
|
+
let nearestDistance = Infinity;
|
|
6520
|
+
// Each candidate is where THIS tab's center would land after reordering,
|
|
6521
|
+
// not the original occupant's center. This keeps every insertion slot
|
|
6522
|
+
// reachable even when a short tab sits between two much wider tabs.
|
|
6523
|
+
// Frozen geometry also prevents animated neighbors feeding back on hit tests.
|
|
6524
|
+
for (const slot of baseSlots) {
|
|
6525
|
+
if (!slot || !slot.movable) continue;
|
|
6526
|
+
const left = slot.offsetLeft + (slot.index > fromIndex ? slot.width - draggedWidth : 0);
|
|
6527
|
+
const distance = Math.abs(contentCenter - (left + draggedWidth / 2));
|
|
6528
|
+
if (distance < nearestDistance) {
|
|
6529
|
+
nearestDistance = distance;
|
|
6530
|
+
newIdx = slot.index;
|
|
6434
6531
|
}
|
|
6435
6532
|
}
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6533
|
+
if (dragOverlayRef.current) {
|
|
6534
|
+
dragOverlayRef.current.style.transform = `translate3d(${overlayX}px, ${startOverlayY - 4}px, 0) scale(1.04)`;
|
|
6535
|
+
}
|
|
6536
|
+
// Pointer tracking stays off React's render path. Only crossing an
|
|
6537
|
+
// insertion boundary needs to render a new surrounding-tab preview.
|
|
6538
|
+
if (newIdx === dragLiveRef.current.toIndex) return;
|
|
6439
6539
|
dragLiveRef.current.toIndex = newIdx;
|
|
6440
6540
|
setDragState((prev) => prev ? {
|
|
6441
6541
|
...prev,
|
|
@@ -6470,13 +6570,22 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6470
6570
|
longPressTimerRef.current = null;
|
|
6471
6571
|
}
|
|
6472
6572
|
stopAutoScroll();
|
|
6573
|
+
if (dragLiveRef.current.isSnapping && snapFinishRef.current) {
|
|
6574
|
+
snapFinishRef.current();
|
|
6575
|
+
return;
|
|
6576
|
+
}
|
|
6473
6577
|
if (snapTimerRef.current) {
|
|
6474
6578
|
clearTimeout(snapTimerRef.current);
|
|
6475
6579
|
snapTimerRef.current = null;
|
|
6476
6580
|
}
|
|
6581
|
+
snapFinishRef.current = null;
|
|
6477
6582
|
|
|
6478
|
-
|
|
6479
|
-
|
|
6583
|
+
const { pointerId } = dragLiveRef.current;
|
|
6584
|
+
const wasActive = dragLiveRef.current.active;
|
|
6585
|
+
dragLiveRef.current.active = false;
|
|
6586
|
+
dragLiveRef.current.isSnapping = false;
|
|
6587
|
+
dragLiveRef.current.pointerId = null;
|
|
6588
|
+
if (wasActive || pointerId !== null) {
|
|
6480
6589
|
if (pointerId !== null) {
|
|
6481
6590
|
try {
|
|
6482
6591
|
const el = tabRefs.current[dragLiveRef.current.sourceId];
|
|
@@ -6486,36 +6595,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6486
6595
|
} catch {}
|
|
6487
6596
|
}
|
|
6488
6597
|
|
|
6489
|
-
if (toIndex !== fromIndex && fromIndex >= 1 && toIndex >= 1) {
|
|
6490
|
-
const scrollEl = tabsRef.current;
|
|
6491
|
-
if (scrollEl) savedTabScrolls.set(activeSourceId, scrollEl.scrollLeft);
|
|
6492
|
-
const newSources = [...state.sources];
|
|
6493
|
-
const [moved] = newSources.splice(fromIndex, 1);
|
|
6494
|
-
newSources.splice(toIndex, 0, moved);
|
|
6495
|
-
setState((prev) => ({ ...prev, sources: newSources }));
|
|
6496
|
-
SESSION_STORE.state = { ...(SESSION_STORE.state || {}), sources: newSources };
|
|
6497
|
-
try {
|
|
6498
|
-
localStorage.setItem(STORAGE_KEY_STATE, JSON.stringify(SESSION_STORE.state));
|
|
6499
|
-
} catch {}
|
|
6500
|
-
api("/sources/reorder", {
|
|
6501
|
-
method: "POST",
|
|
6502
|
-
body: JSON.stringify({ sourceIds: newSources.map((item) => item.id) }),
|
|
6503
|
-
}).catch(() => {});
|
|
6504
|
-
}
|
|
6505
|
-
|
|
6506
|
-
dragLiveRef.current.active = false;
|
|
6507
|
-
dragLiveRef.current.isSnapping = false;
|
|
6508
|
-
dragLiveRef.current.pointerId = null;
|
|
6509
6598
|
dragLiveRef.current.startX = 0;
|
|
6510
6599
|
dragLiveRef.current.startY = 0;
|
|
6511
6600
|
isLongPressTriggeredRef.current = false;
|
|
6512
6601
|
setDragState(null);
|
|
6513
6602
|
updateTabsMask();
|
|
6514
6603
|
}
|
|
6515
|
-
}, [
|
|
6604
|
+
}, [stopAutoScroll, updateTabsMask]);
|
|
6516
6605
|
|
|
6517
6606
|
const handleTabPointerDown = useCallback((e, s, idx) => {
|
|
6518
|
-
if (e.button !== 0) return;
|
|
6607
|
+
if (e.button !== 0 || e.isPrimary === false) return;
|
|
6519
6608
|
if (e.target && e.target.closest && e.target.closest(".cpm-tab-del-zone")) return;
|
|
6520
6609
|
if (dragLiveRef.current.active || dragState) {
|
|
6521
6610
|
cancelOrResetDrag();
|
|
@@ -6539,33 +6628,40 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6539
6628
|
dragLiveRef.current.startY = clientY;
|
|
6540
6629
|
dragLiveRef.current.lastClientX = clientX;
|
|
6541
6630
|
dragLiveRef.current.pointerId = pointerId;
|
|
6631
|
+
dragLiveRef.current.sourceId = s.id;
|
|
6542
6632
|
dragLiveRef.current.active = false;
|
|
6543
6633
|
dragLiveRef.current.isSnapping = false;
|
|
6544
|
-
|
|
6545
|
-
const container = tabsRef.current;
|
|
6546
|
-
const curScroll = container ? container.scrollLeft : 0;
|
|
6634
|
+
try { targetEl.setPointerCapture(pointerId); } catch {}
|
|
6547
6635
|
|
|
6548
6636
|
if (longPressTimerRef.current) clearTimeout(longPressTimerRef.current);
|
|
6549
6637
|
longPressTimerRef.current = setTimeout(() => {
|
|
6638
|
+
longPressTimerRef.current = null;
|
|
6639
|
+
const cont = tabsRef.current;
|
|
6640
|
+
if (!cont || !targetEl.isConnected) return;
|
|
6641
|
+
if (currentTabAnim) cancelAnimationFrame(currentTabAnim);
|
|
6642
|
+
currentTabAnim = null;
|
|
6643
|
+
currentTabTarget = null;
|
|
6550
6644
|
isLongPressTriggeredRef.current = true;
|
|
6551
6645
|
if (targetEl && typeof targetEl.setPointerCapture === "function") {
|
|
6552
6646
|
try { targetEl.setPointerCapture(pointerId); } catch {}
|
|
6553
6647
|
}
|
|
6554
|
-
const cont = tabsRef.current;
|
|
6555
|
-
if (!cont) return;
|
|
6556
6648
|
const cRect = cont.getBoundingClientRect();
|
|
6557
6649
|
const tRect = targetEl.getBoundingClientRect();
|
|
6650
|
+
const curScroll = cont.scrollLeft;
|
|
6558
6651
|
|
|
6559
|
-
//
|
|
6652
|
+
// Use one scroll-content coordinate system; offsetLeft may refer to
|
|
6653
|
+
// an ancestor outside this scroller. Hidden sources have no slot.
|
|
6560
6654
|
const baseSlots = state.sources.map((item, mIdx) => {
|
|
6561
6655
|
const el = tabRefs.current[item.id];
|
|
6562
|
-
if (!el
|
|
6656
|
+
if (!el || !el.isConnected || !el.getClientRects().length) return null;
|
|
6657
|
+
const rect = el.getBoundingClientRect();
|
|
6563
6658
|
return {
|
|
6564
6659
|
id: item.id,
|
|
6565
6660
|
index: mIdx,
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6661
|
+
movable: mIdx !== 0 && !item.builtin && item.id?.toLowerCase() !== "anthropic",
|
|
6662
|
+
offsetLeft: rect.left - cRect.left + curScroll,
|
|
6663
|
+
width: rect.width,
|
|
6664
|
+
height: rect.height || 30,
|
|
6569
6665
|
};
|
|
6570
6666
|
});
|
|
6571
6667
|
|
|
@@ -6577,7 +6673,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6577
6673
|
const pointerOffsetX = clientX - startOverlayX;
|
|
6578
6674
|
const draggedWidth = draggedSlot.width;
|
|
6579
6675
|
const draggedHeight = draggedSlot.height;
|
|
6580
|
-
const slotSize = draggedWidth +
|
|
6676
|
+
const slotSize = draggedWidth + (parseFloat(getComputedStyle(cont).columnGap) || 0);
|
|
6581
6677
|
|
|
6582
6678
|
dragLiveRef.current = {
|
|
6583
6679
|
active: true,
|
|
@@ -6622,6 +6718,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6622
6718
|
}, [state.sources, cancelOrResetDrag, dragState]);
|
|
6623
6719
|
|
|
6624
6720
|
const handleTabPointerMove = useCallback((e) => {
|
|
6721
|
+
if (e.pointerId !== dragLiveRef.current.pointerId) return;
|
|
6625
6722
|
if (longPressTimerRef.current && !dragLiveRef.current.active) {
|
|
6626
6723
|
if (Math.hypot(e.clientX - dragLiveRef.current.startX, e.clientY - dragLiveRef.current.startY) > 8) {
|
|
6627
6724
|
clearTimeout(longPressTimerRef.current);
|
|
@@ -6652,6 +6749,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6652
6749
|
}, [startAutoScroll, stopAutoScroll, updateDragPosition]);
|
|
6653
6750
|
|
|
6654
6751
|
const handleTabPointerUp = useCallback((e, s, idx) => {
|
|
6752
|
+
if (dragLiveRef.current.isSnapping) return;
|
|
6753
|
+
if (dragLiveRef.current.pointerId !== null && e?.pointerId !== dragLiveRef.current.pointerId) return;
|
|
6655
6754
|
if (longPressTimerRef.current) {
|
|
6656
6755
|
clearTimeout(longPressTimerRef.current);
|
|
6657
6756
|
longPressTimerRef.current = null;
|
|
@@ -6659,14 +6758,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6659
6758
|
stopAutoScroll();
|
|
6660
6759
|
|
|
6661
6760
|
const wasActive = dragLiveRef.current.active;
|
|
6761
|
+
if (wasActive && Number.isFinite(e?.clientX)) updateDragPosition(e.clientX);
|
|
6662
6762
|
const { fromIndex, toIndex, pointerId, baseSlots, draggedWidth } = dragLiveRef.current;
|
|
6763
|
+
// Mark the handoff before releasing capture: lostpointercapture is a
|
|
6764
|
+
// cancellation only while tracking, never during the settle animation.
|
|
6765
|
+
if (wasActive) dragLiveRef.current.isSnapping = true;
|
|
6663
6766
|
|
|
6664
6767
|
if (e && e.currentTarget && typeof e.currentTarget.releasePointerCapture === "function" && pointerId !== null) {
|
|
6665
6768
|
try { e.currentTarget.releasePointerCapture(pointerId); } catch {}
|
|
6666
6769
|
}
|
|
6667
6770
|
|
|
6668
|
-
if (wasActive
|
|
6669
|
-
dragLiveRef.current.isSnapping = true;
|
|
6771
|
+
if (wasActive) {
|
|
6670
6772
|
const container = tabsRef.current;
|
|
6671
6773
|
const cRect = container ? container.getBoundingClientRect() : { left: 0, top: 0 };
|
|
6672
6774
|
const curScroll = container ? container.scrollLeft : 0;
|
|
@@ -6690,7 +6792,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6690
6792
|
snapTargetY: snapY,
|
|
6691
6793
|
} : null);
|
|
6692
6794
|
|
|
6693
|
-
|
|
6795
|
+
snapFinishRef.current = () => {
|
|
6796
|
+
if (!dragLiveRef.current.isSnapping) return;
|
|
6797
|
+
clearTimeout(snapTimerRef.current);
|
|
6798
|
+
snapFinishRef.current = null;
|
|
6694
6799
|
if (toIndex !== fromIndex && fromIndex >= 1 && toIndex >= 1) {
|
|
6695
6800
|
// Keep the tab bar where the user left it: the state.sources
|
|
6696
6801
|
// change re-runs the tab-scroll restore layout effect, which
|
|
@@ -6722,7 +6827,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6722
6827
|
setDragState(null);
|
|
6723
6828
|
snapTimerRef.current = null;
|
|
6724
6829
|
updateTabsMask();
|
|
6725
|
-
}
|
|
6830
|
+
};
|
|
6831
|
+
// transitionend is the normal completion path; the timer handles
|
|
6832
|
+
// interrupted transitions and reduced-motion (which has no event).
|
|
6833
|
+
const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
6834
|
+
snapTimerRef.current = setTimeout(() => snapFinishRef.current?.(), reducedMotion ? 0 : 320);
|
|
6726
6835
|
return;
|
|
6727
6836
|
}
|
|
6728
6837
|
|
|
@@ -6731,7 +6840,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6731
6840
|
const isBrowseView = !view || view.type === "browse";
|
|
6732
6841
|
const sInstalledCount = (state.plugins || []).filter((p) => (p.sourceId || "").toLowerCase() === s.id.toLowerCase() || (p.id && p.id.startsWith(s.id + "/"))).length;
|
|
6733
6842
|
if (s.id !== activeSourceId) {
|
|
6734
|
-
if (gridRef.current && isBrowseView) {
|
|
6843
|
+
if (gridRef.current && isBrowseView && !mcpsOpen) {
|
|
6735
6844
|
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
6736
6845
|
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
6737
6846
|
}
|
|
@@ -6747,7 +6856,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6747
6856
|
targetFilter = SESSION_STORE.sourceFilters[s.id] || SESSION_STORE.preferredFilter || (filter === "installed" ? "installed" : "all");
|
|
6748
6857
|
}
|
|
6749
6858
|
setActiveSourceId(s.id, targetFilter);
|
|
6750
|
-
} else {
|
|
6859
|
+
} else if (!mcpsOpen) {
|
|
6751
6860
|
// Clicking the current source's tab scrolls its list back to the top.
|
|
6752
6861
|
scrollActiveTabIntoView(s.id, true);
|
|
6753
6862
|
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
@@ -6755,17 +6864,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6755
6864
|
scrollContentToTop();
|
|
6756
6865
|
}
|
|
6757
6866
|
}
|
|
6758
|
-
}, [state.sources, state.plugins, activeSourceId, view, filter, setActiveSourceId, scrollActiveTabIntoView, scrollContentToTop, setState, showToast, stopAutoScroll, updateTabsMask]);
|
|
6867
|
+
}, [state.sources, state.plugins, activeSourceId, view, filter, mcpsOpen, setActiveSourceId, scrollActiveTabIntoView, scrollContentToTop, setState, showToast, stopAutoScroll, updateTabsMask, updateDragPosition]);
|
|
6759
6868
|
|
|
6760
6869
|
useEffect(() => {
|
|
6761
6870
|
const handleWindowBlurOrCancel = () => {
|
|
6762
|
-
|
|
6763
|
-
cancelOrResetDrag();
|
|
6764
|
-
}
|
|
6871
|
+
cancelOrResetDrag();
|
|
6765
6872
|
};
|
|
6766
6873
|
|
|
6767
6874
|
const handleGlobalPointerUp = (e) => {
|
|
6768
|
-
if (dragLiveRef.current.active && !dragLiveRef.current.isSnapping) {
|
|
6875
|
+
if ((dragLiveRef.current.active || longPressTimerRef.current) && !dragLiveRef.current.isSnapping) {
|
|
6769
6876
|
handleTabPointerUp(e, null, dragLiveRef.current.fromIndex);
|
|
6770
6877
|
}
|
|
6771
6878
|
};
|
|
@@ -6784,6 +6891,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6784
6891
|
if (autoScrollRafRef.current) cancelAnimationFrame(autoScrollRafRef.current);
|
|
6785
6892
|
};
|
|
6786
6893
|
}, [cancelOrResetDrag, handleTabPointerUp]);
|
|
6894
|
+
useEffect(() => () => {
|
|
6895
|
+
clearTimeout(snapTimerRef.current);
|
|
6896
|
+
snapFinishRef.current = null;
|
|
6897
|
+
}, []);
|
|
6787
6898
|
|
|
6788
6899
|
const cleanError = (err) => {
|
|
6789
6900
|
if (!err) return "操作失败";
|
|
@@ -6792,7 +6903,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6792
6903
|
return msg;
|
|
6793
6904
|
};
|
|
6794
6905
|
|
|
6795
|
-
|
|
6906
|
+
// MCP is a separate surface; keep the source's list/detail view intact
|
|
6907
|
+
// underneath it so returning to that source resumes the same page.
|
|
6908
|
+
const isBrowse = mcpsOpen || !view || view.type === "browse";
|
|
6909
|
+
const isSourceBrowse = isBrowse && !mcpsOpen;
|
|
6796
6910
|
|
|
6797
6911
|
// Per-source Scroll restoration and wheel scroll suppression
|
|
6798
6912
|
const onGridWheel = useCallback(() => {
|
|
@@ -6849,15 +6963,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6849
6963
|
// must NOT re-detect "filter changed". Only genuine user-driven
|
|
6850
6964
|
// changes set a new pending intent.
|
|
6851
6965
|
//
|
|
6852
|
-
// Ref-based, so the apply-step
|
|
6853
|
-
//
|
|
6966
|
+
// Ref-based, so the apply-step only tracks the visible source surface
|
|
6967
|
+
// and source identity. The restore therefore never
|
|
6854
6968
|
// fires spuriously on unrelated re-renders and never gets clobbered by
|
|
6855
6969
|
// onGridScroll overwriting the store with a stale value.
|
|
6856
6970
|
const pendingScrollTopRef = useRef(null);
|
|
6857
6971
|
const lastActiveSourceRef = useRef(activeSourceId);
|
|
6858
6972
|
const lastFilterRef = useRef(filter);
|
|
6859
6973
|
const lastSortByRef = useRef(sortBy);
|
|
6860
|
-
const prevIsBrowseRef = useRef(
|
|
6974
|
+
const prevIsBrowseRef = useRef(isSourceBrowse);
|
|
6861
6975
|
const firstBrowseRenderRef = useRef(true);
|
|
6862
6976
|
|
|
6863
6977
|
if (lastActiveSourceRef.current !== activeSourceId) {
|
|
@@ -6881,18 +6995,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6881
6995
|
pendingScrollTopRef.current = { type: "reset", filter, sortBy };
|
|
6882
6996
|
}
|
|
6883
6997
|
}
|
|
6884
|
-
//
|
|
6885
|
-
//
|
|
6886
|
-
|
|
6887
|
-
// that was saved right before the detail was opened.
|
|
6888
|
-
if (isBrowse && prevIsBrowseRef.current === false && pendingScrollTopRef.current?.type !== "restore") {
|
|
6998
|
+
// Details and MCP both unmount the source grid. Returning to either the
|
|
6999
|
+
// same source or another source must restore that source's saved position.
|
|
7000
|
+
if (isSourceBrowse && prevIsBrowseRef.current === false && pendingScrollTopRef.current?.type !== "restore") {
|
|
6889
7001
|
pendingScrollTopRef.current = { type: "restore" };
|
|
6890
7002
|
}
|
|
6891
|
-
prevIsBrowseRef.current =
|
|
6892
|
-
//
|
|
6893
|
-
//
|
|
6894
|
-
|
|
6895
|
-
if (firstBrowseRenderRef.current && isBrowse && pendingScrollTopRef.current === null) {
|
|
7003
|
+
prevIsBrowseRef.current = isSourceBrowse;
|
|
7004
|
+
// A fresh panel mount can reuse a remembered source position. Management
|
|
7005
|
+
// round trips are handled by the source-surface transition above.
|
|
7006
|
+
if (firstBrowseRenderRef.current && isSourceBrowse && pendingScrollTopRef.current === null) {
|
|
6896
7007
|
const saved = SESSION_STORE.scrollTops && SESSION_STORE.scrollTops[activeSourceId];
|
|
6897
7008
|
if (typeof saved === "number") {
|
|
6898
7009
|
pendingScrollTopRef.current = { type: "restore" };
|
|
@@ -6908,7 +7019,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6908
7019
|
// yet, and the browser clamps scrollTop when it exceeds the current
|
|
6909
7020
|
// scrollHeight. Re-applying on the next frame makes the restore stick.
|
|
6910
7021
|
//
|
|
6911
|
-
// NOTE: the apply layout effect deliberately depends on `
|
|
7022
|
+
// NOTE: the apply layout effect deliberately depends on `isSourceBrowse`
|
|
6912
7023
|
// and `activeSourceId` — a tab switch changes activeSourceId, and
|
|
6913
7024
|
// that MUST trigger the restore. The change-detection (last-* refs)
|
|
6914
7025
|
// above runs during render and only sets pending for genuine changes,
|
|
@@ -6916,7 +7027,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6916
7027
|
// fire this.
|
|
6917
7028
|
const appliedScrollTopRef = useRef(null);
|
|
6918
7029
|
useSafeLayoutEffect(() => {
|
|
6919
|
-
if (!
|
|
7030
|
+
if (!isSourceBrowse || !gridRef.current) return;
|
|
6920
7031
|
const pending = pendingScrollTopRef.current;
|
|
6921
7032
|
if (!pending) return;
|
|
6922
7033
|
if (pending.type === "reset" && (pending.filter !== filter || pending.sortBy !== sortBy)) return;
|
|
@@ -6937,10 +7048,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6937
7048
|
gridRef.current.scrollTop = target;
|
|
6938
7049
|
pendingScrollTopRef.current = null;
|
|
6939
7050
|
updateGridMask();
|
|
6940
|
-
}, [
|
|
7051
|
+
}, [isSourceBrowse, activeSourceId, updateGridMask]);
|
|
6941
7052
|
|
|
6942
7053
|
useEffect(() => {
|
|
6943
|
-
if (!
|
|
7054
|
+
if (!isSourceBrowse) return;
|
|
6944
7055
|
const applied = appliedScrollTopRef.current;
|
|
6945
7056
|
if (applied === null) return;
|
|
6946
7057
|
const { sourceId, target } = applied;
|
|
@@ -6960,7 +7071,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
6960
7071
|
}
|
|
6961
7072
|
});
|
|
6962
7073
|
return () => cancelAnimationFrame(raf);
|
|
6963
|
-
}, [
|
|
7074
|
+
}, [isSourceBrowse, activeSourceId, updateGridMask]);
|
|
6964
7075
|
|
|
6965
7076
|
useEffect(() => {
|
|
6966
7077
|
const onDocClick = (e) => {
|
|
@@ -7006,6 +7117,32 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7006
7117
|
}, [activeSourceId, setRows, showToast]);
|
|
7007
7118
|
|
|
7008
7119
|
const currentSourceInstalledNames = useMemo(() => new Set((state.plugins || []).filter((p) => p.sourceId === activeSourceId).map((p) => p.name)), [state.plugins, activeSourceId]);
|
|
7120
|
+
// Each source retains its browsing order for this Hub session, including
|
|
7121
|
+
// tab navigation and panel remounts. Filtering or sorting takes a new
|
|
7122
|
+
// snapshot — derived here, committed below, so a render that React
|
|
7123
|
+
// discards leaves the session store untouched.
|
|
7124
|
+
const sortInstalledSnapshots = SESSION_STORE.browseSortSnapshots;
|
|
7125
|
+
const sortInstalledNames = useMemo(() => {
|
|
7126
|
+
const saved = sortInstalledSnapshots && sortInstalledSnapshots[activeSourceId];
|
|
7127
|
+
if (!saved || saved.filter !== filter || saved.query !== query || saved.sortBy !== sortBy) {
|
|
7128
|
+
return currentSourceInstalledNames;
|
|
7129
|
+
}
|
|
7130
|
+
// The captured order only ever loses names, never gains them: an
|
|
7131
|
+
// uninstall has to release the plugin's pinned slot at once (it drops
|
|
7132
|
+
// back into the current order like any other row), while an install
|
|
7133
|
+
// must still leave the list alone until the order is re-snapshotted.
|
|
7134
|
+
if (![...saved.names].some((n) => !currentSourceInstalledNames.has(n))) return saved.names;
|
|
7135
|
+
return new Set([...saved.names].filter((n) => currentSourceInstalledNames.has(n)));
|
|
7136
|
+
}, [sortInstalledSnapshots, activeSourceId, filter, query, sortBy, currentSourceInstalledNames]);
|
|
7137
|
+
// Only a new browsing order (or a tab switch) re-captures what is
|
|
7138
|
+
// installed. A plain install must leave the remembered order alone, so
|
|
7139
|
+
// the pruned set is never written back.
|
|
7140
|
+
useEffect(() => {
|
|
7141
|
+
if (!SESSION_STORE.browseSortSnapshots) SESSION_STORE.browseSortSnapshots = Object.create(null);
|
|
7142
|
+
const saved = SESSION_STORE.browseSortSnapshots[activeSourceId];
|
|
7143
|
+
if (saved && saved.filter === filter && saved.query === query && saved.sortBy === sortBy) return;
|
|
7144
|
+
SESSION_STORE.browseSortSnapshots[activeSourceId] = { filter, query, sortBy, names: currentSourceInstalledNames };
|
|
7145
|
+
}, [activeSourceId, filter, query, sortBy, currentSourceInstalledNames]);
|
|
7009
7146
|
const installedNames = useMemo(() => new Set(state.plugins.map((p) => p.name)), [state.plugins]);
|
|
7010
7147
|
const totalInstalledCount = state.plugins.length;
|
|
7011
7148
|
const currentSourcePlugins = useMemo(() => (rows && rows[activeSourceId]) || [], [rows, activeSourceId]);
|
|
@@ -7158,17 +7295,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7158
7295
|
} else if (sortBy === "name-desc") {
|
|
7159
7296
|
list = [...list].sort((a, b) => (b.displayName || b.name).localeCompare(a.displayName || a.name));
|
|
7160
7297
|
} else if (!query.trim()) {
|
|
7161
|
-
// Use the
|
|
7298
|
+
// Use the installed set captured when this browsing order was chosen.
|
|
7162
7299
|
list = [...list].sort((a, b) => {
|
|
7163
|
-
const instA =
|
|
7164
|
-
const instB =
|
|
7300
|
+
const instA = sortInstalledNames.has(a.name) ? 1 : 0;
|
|
7301
|
+
const instB = sortInstalledNames.has(b.name) ? 1 : 0;
|
|
7165
7302
|
if (instB !== instA) return instB - instA;
|
|
7166
7303
|
return (a.displayName || a.name).localeCompare(b.displayName || b.name);
|
|
7167
7304
|
});
|
|
7168
7305
|
}
|
|
7169
7306
|
|
|
7170
7307
|
return list;
|
|
7171
|
-
}, [currentSourcePlugins, query, sortBy,
|
|
7308
|
+
}, [currentSourcePlugins, query, sortBy, sortInstalledNames]);
|
|
7172
7309
|
|
|
7173
7310
|
const refresh = async () => {
|
|
7174
7311
|
setIsRefreshing(true);
|
|
@@ -7242,6 +7379,23 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7242
7379
|
};
|
|
7243
7380
|
|
|
7244
7381
|
const currentDetailPlugin = detail || (view && view.type === "detail" ? view.plugin : null);
|
|
7382
|
+
const manageRecord = view.type === "manage" ? state.plugins.find(r => r.name === view.pluginName) : null;
|
|
7383
|
+
const closeManage = () => {
|
|
7384
|
+
// A removal can finish after the user has switched to another tab.
|
|
7385
|
+
if (SESSION_STORE.view !== view) return;
|
|
7386
|
+
setView(view.returnView || { type: "browse", sourceId: activeSourceId });
|
|
7387
|
+
if (view.returnToMcp) setMcpsOpen(true);
|
|
7388
|
+
};
|
|
7389
|
+
const openPlugin = (plugin) => {
|
|
7390
|
+
closePluginHover();
|
|
7391
|
+
if (gridRef.current) {
|
|
7392
|
+
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7393
|
+
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7394
|
+
}
|
|
7395
|
+
const record = state.plugins.find(r => r.name === plugin.name);
|
|
7396
|
+
if (record) openManage(record);
|
|
7397
|
+
else setView({ type: "detail", sourceId: activeSourceId, plugin });
|
|
7398
|
+
};
|
|
7245
7399
|
|
|
7246
7400
|
return h("div", { className: "cpm-main" },
|
|
7247
7401
|
// Top bar matching Claude official: Row 1 (Full width search) & Row 2 (Tabs on Left + Filter & Sort on Right)
|
|
@@ -7269,7 +7423,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7269
7423
|
hasMcps && h("button", {
|
|
7270
7424
|
key: "__mcps",
|
|
7271
7425
|
className: "cpm-tab" + (mcpsOpen ? " active" : ""),
|
|
7272
|
-
onClick: () => {
|
|
7426
|
+
onClick: () => {
|
|
7427
|
+
if (isSourceBrowse && gridRef.current) {
|
|
7428
|
+
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7429
|
+
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7430
|
+
}
|
|
7431
|
+
stopScrollTopAnim();
|
|
7432
|
+
setMcpsOpen(true); refreshMcps();
|
|
7433
|
+
},
|
|
7273
7434
|
}, h("span", null, "MCP")),
|
|
7274
7435
|
state.sources.map((s, idx) => {
|
|
7275
7436
|
if (s.id === "local" && !hasLocalPlugins) return null;
|
|
@@ -7307,13 +7468,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7307
7468
|
|
|
7308
7469
|
return h("button", {
|
|
7309
7470
|
key: s.id,
|
|
7310
|
-
ref: (el) => {
|
|
7471
|
+
ref: (el) => { tabRefs.current[s.id] = el; },
|
|
7311
7472
|
className: "cpm-tab" + (s.id === activeSourceId && !mcpsOpen ? " active" : "") + tabClassExtra,
|
|
7312
7473
|
style: tabTransform ? { transform: tabTransform } : undefined,
|
|
7313
7474
|
onPointerDown: (e) => handleTabPointerDown(e, s, idx),
|
|
7314
7475
|
onPointerMove: handleTabPointerMove,
|
|
7315
7476
|
onPointerUp: (e) => handleTabPointerUp(e, s, idx),
|
|
7316
|
-
onPointerCancel:
|
|
7477
|
+
onPointerCancel: cancelOrResetDrag,
|
|
7478
|
+
onLostPointerCapture: (e) => {
|
|
7479
|
+
if (e.pointerId === dragLiveRef.current.pointerId && !dragLiveRef.current.isSnapping) cancelOrResetDrag();
|
|
7480
|
+
},
|
|
7317
7481
|
onContextMenu: (e) => e.preventDefault(),
|
|
7318
7482
|
onMouseDown: (e) => e.preventDefault(),
|
|
7319
7483
|
onClick: () => setMcpsOpen(false),
|
|
@@ -7418,19 +7582,20 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7418
7582
|
),
|
|
7419
7583
|
),
|
|
7420
7584
|
|
|
7421
|
-
view.type === "skill-detail" && (() => {
|
|
7585
|
+
!mcpsOpen && view.type === "skill-detail" && (() => {
|
|
7422
7586
|
const selected = ((rows && rows["skills-local"]) || []).find(s => s.id === view.skill.id) || view.skill;
|
|
7423
|
-
return h(SkillDetail, { skill: selected, isDark, containerRef: detailContainerRef, busy: skillBusy === selected.id, onToggle: toggleSkill, onRemove: removeUploadedSkill, onBack: () => setView({ type: "browse", sourceId: "skills-local" }) });
|
|
7587
|
+
return h(SkillDetail, { skill: selected, isDark, containerRef: detailContainerRef, scrollState: view, busy: skillBusy === selected.id, onToggle: toggleSkill, onRemove: removeUploadedSkill, onBack: () => setView({ type: "browse", sourceId: "skills-local" }) });
|
|
7424
7588
|
})(),
|
|
7425
7589
|
|
|
7426
7590
|
// Detail view — 0ms instant transition without intermediate loading screen
|
|
7427
|
-
view.type === "detail" && currentDetailPlugin && h(DetailView, {
|
|
7591
|
+
!mcpsOpen && view.type === "detail" && currentDetailPlugin && h(DetailView, {
|
|
7428
7592
|
plugin: {
|
|
7429
7593
|
...currentDetailPlugin,
|
|
7430
7594
|
installed: installedNames.has(currentDetailPlugin.name),
|
|
7431
7595
|
enabled: state.plugins.find((r) => r.name === currentDetailPlugin.name)?.enabled !== false,
|
|
7432
7596
|
},
|
|
7433
7597
|
pluginRecord: state.plugins.find((r) => r.name === currentDetailPlugin.name),
|
|
7598
|
+
scrollState: view,
|
|
7434
7599
|
isDark,
|
|
7435
7600
|
containerRef: detailContainerRef,
|
|
7436
7601
|
onBack: () => setView({ type: "browse", sourceId: activeSourceId }),
|
|
@@ -7446,6 +7611,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7446
7611
|
},
|
|
7447
7612
|
showToast,
|
|
7448
7613
|
}),
|
|
7614
|
+
!mcpsOpen && view.type === "manage" && h(ManagePage, {
|
|
7615
|
+
key: view.pluginName || manageRecord?.name,
|
|
7616
|
+
record: manageRecord || null, state, rows, isDark, refreshState, showToast,
|
|
7617
|
+
containerRef: detailContainerRef,
|
|
7618
|
+
initialTab: view.initialTab, initialConnector: view.initialConnector,
|
|
7619
|
+
scrollState: view,
|
|
7620
|
+
onBack: closeManage, onClose: closeManage,
|
|
7621
|
+
}),
|
|
7449
7622
|
|
|
7450
7623
|
// Browse View — Mode A: Grouped Installed across all sources (Selected active tab source displayed first)
|
|
7451
7624
|
isBrowse && activeSourceId !== "skills-local" && filter === "installed" && !mcpsOpen && h("div", {
|
|
@@ -7473,22 +7646,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7473
7646
|
isDark,
|
|
7474
7647
|
onMouseEnter: (e) => handleCardMouseEnter(p, e.currentTarget, { x: e.clientX, y: e.clientY, buttons: e.buttons }),
|
|
7475
7648
|
onMouseLeave: () => handleCardMouseLeave(p),
|
|
7476
|
-
onClick: () =>
|
|
7477
|
-
closePluginHover();
|
|
7478
|
-
if (gridRef.current) {
|
|
7479
|
-
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7480
|
-
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7481
|
-
}
|
|
7482
|
-
setView({ type: "detail", sourceId: p.sourceId || grp.source.id, plugin: p });
|
|
7483
|
-
},
|
|
7649
|
+
onClick: () => openPlugin(p),
|
|
7484
7650
|
onManage: (e) => {
|
|
7485
7651
|
e.stopPropagation();
|
|
7486
|
-
|
|
7487
|
-
if (gridRef.current) {
|
|
7488
|
-
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7489
|
-
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7490
|
-
}
|
|
7491
|
-
openManage(state.plugins.find((r) => r.name === p.name), { type: "browse" });
|
|
7652
|
+
openPlugin(p);
|
|
7492
7653
|
},
|
|
7493
7654
|
onInstall: (e) => {
|
|
7494
7655
|
e.stopPropagation();
|
|
@@ -7544,22 +7705,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7544
7705
|
isDark,
|
|
7545
7706
|
onMouseEnter: (e) => handleCardMouseEnter(p, e.currentTarget, { x: e.clientX, y: e.clientY, buttons: e.buttons }),
|
|
7546
7707
|
onMouseLeave: () => handleCardMouseLeave(p),
|
|
7547
|
-
onClick: () =>
|
|
7548
|
-
closePluginHover();
|
|
7549
|
-
if (gridRef.current) {
|
|
7550
|
-
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7551
|
-
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7552
|
-
}
|
|
7553
|
-
setView({ type: "detail", sourceId: activeSourceId, plugin: p });
|
|
7554
|
-
},
|
|
7708
|
+
onClick: () => openPlugin(p),
|
|
7555
7709
|
onManage: (e) => {
|
|
7556
7710
|
e.stopPropagation();
|
|
7557
|
-
|
|
7558
|
-
if (gridRef.current) {
|
|
7559
|
-
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
7560
|
-
SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
|
|
7561
|
-
}
|
|
7562
|
-
openManage(state.plugins.find((r) => r.name === p.name && (r.sourceId === activeSourceId || r.sourceId === p.sourceId)) || state.plugins.find((r) => r.name === p.name), { type: "browse" });
|
|
7711
|
+
openPlugin(p);
|
|
7563
7712
|
},
|
|
7564
7713
|
onInstall: (e) => {
|
|
7565
7714
|
e.stopPropagation();
|
|
@@ -7653,7 +7802,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7653
7802
|
showToast,
|
|
7654
7803
|
}),
|
|
7655
7804
|
|
|
7656
|
-
confirmRemoveSource && h("div", { className: "cpm-dialog",
|
|
7805
|
+
confirmRemoveSource && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemoveSource(null)) },
|
|
7657
7806
|
h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
|
|
7658
7807
|
h("div", { className: "cpm-dialog-title" }, `删除插件源「${confirmRemoveSource.name}」`),
|
|
7659
7808
|
h("div", { className: "cpm-field", style: { fontSize: 13, lineHeight: 1.6, color: "var(--cpm-muted)" } },
|
|
@@ -7700,14 +7849,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7700
7849
|
|
|
7701
7850
|
// ────────────────────────────── Modern Floating Drag Overlay (Zero Container Clipping) ──────────────────────────────
|
|
7702
7851
|
dragState?.active && h("div", {
|
|
7852
|
+
ref: dragOverlayRef,
|
|
7703
7853
|
className: "cpm-tab-drag-overlay" + (isDark ? " cpm-dark" : ""),
|
|
7854
|
+
onTransitionEnd: (e) => {
|
|
7855
|
+
if (e.target === e.currentTarget && e.propertyName === "transform") snapFinishRef.current?.();
|
|
7856
|
+
},
|
|
7704
7857
|
style: {
|
|
7705
|
-
left: dragState.isSnapping ? dragState.snapTargetX : dragState.overlayX,
|
|
7706
|
-
top: dragState.isSnapping ? dragState.snapTargetY : dragState.overlayY,
|
|
7707
7858
|
width: dragState.width || "auto",
|
|
7708
7859
|
height: dragState.height || 30,
|
|
7709
|
-
transform: dragState.isSnapping
|
|
7710
|
-
|
|
7860
|
+
transform: dragState.isSnapping
|
|
7861
|
+
? `translate3d(${dragState.snapTargetX}px, ${dragState.snapTargetY}px, 0) scale(1)`
|
|
7862
|
+
: `translate3d(${dragLiveRef.current.currentOverlayX}px, ${dragLiveRef.current.startOverlayY - 4}px, 0) scale(1.04)`,
|
|
7863
|
+
transition: dragState.isSnapping ? "transform 260ms cubic-bezier(0.16, 1, 0.3, 1)" : "none",
|
|
7711
7864
|
},
|
|
7712
7865
|
},
|
|
7713
7866
|
h("span", null, dragState.sourceName)
|
|
@@ -7715,10 +7868,23 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7715
7868
|
);
|
|
7716
7869
|
}
|
|
7717
7870
|
|
|
7871
|
+
function backdropDismissProps(onDismiss) {
|
|
7872
|
+
let pressedBackdrop = false;
|
|
7873
|
+
return {
|
|
7874
|
+
onPointerDown: (event) => { pressedBackdrop = event.button === 0 && event.target === event.currentTarget; },
|
|
7875
|
+
onPointerCancel: () => { pressedBackdrop = false; },
|
|
7876
|
+
onClick: (event) => {
|
|
7877
|
+
const dismiss = pressedBackdrop && event.target === event.currentTarget;
|
|
7878
|
+
pressedBackdrop = false;
|
|
7879
|
+
if (dismiss) onDismiss();
|
|
7880
|
+
},
|
|
7881
|
+
};
|
|
7882
|
+
}
|
|
7883
|
+
|
|
7718
7884
|
// ────────────────────────────── Modern Install Dialog ──────────────────────────────
|
|
7719
7885
|
function InstallDialog({ plugin, isDark, onCancel, onConfirm }) {
|
|
7720
7886
|
const [busy, setBusy] = useState(false);
|
|
7721
|
-
return h("div", { className: "cpm-dialog",
|
|
7887
|
+
return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
|
|
7722
7888
|
h("div", { className: "cpm-dialog-box cpm-install-dialog", onClick: (e) => e.stopPropagation() },
|
|
7723
7889
|
h("div", { className: "cpm-install-dialog-header" },
|
|
7724
7890
|
h(PluginIcon, { plugin, isDark }),
|
|
@@ -7935,7 +8101,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7935
8101
|
const ownerLower = (owner || "").toLowerCase();
|
|
7936
8102
|
const repoLower = (repo || "").toLowerCase();
|
|
7937
8103
|
|
|
7938
|
-
if (repoLower === "claude-plugins-official"
|
|
8104
|
+
if (repoLower === "claude-plugins-official") return "Anthropic";
|
|
7939
8105
|
if (repoLower === "claude-plugins-community") return "Community";
|
|
7940
8106
|
|
|
7941
8107
|
const genericWords = new Set([
|
|
@@ -7992,7 +8158,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
7992
8158
|
const finalSuggested = computeSmartSuggestedName(raw, body.suggestedName);
|
|
7993
8159
|
setRepoLabel(finalRepoLabel);
|
|
7994
8160
|
setSuggested(finalSuggested);
|
|
7995
|
-
setCustomName(
|
|
8161
|
+
setCustomName("");
|
|
8162
|
+
setMode("suggest");
|
|
7996
8163
|
setNormalizedUrl(body.normalizedUrl || raw);
|
|
7997
8164
|
setPluginCount(body.pluginCount || 0);
|
|
7998
8165
|
setPhase("name");
|
|
@@ -8025,7 +8192,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8025
8192
|
}
|
|
8026
8193
|
};
|
|
8027
8194
|
|
|
8028
|
-
return h("div", { className: "cpm-dialog",
|
|
8195
|
+
return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
|
|
8029
8196
|
h("div", {
|
|
8030
8197
|
role: "dialog",
|
|
8031
8198
|
"aria-modal": "true",
|
|
@@ -8315,12 +8482,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8315
8482
|
ref: customInputRef,
|
|
8316
8483
|
className: "cpm-input cpm-source-custom-input",
|
|
8317
8484
|
value: customName,
|
|
8485
|
+
autoComplete: "off",
|
|
8318
8486
|
placeholder: "输入自定义标签名",
|
|
8319
8487
|
onChange: (e) => { setCustomName(e.target.value); setMode("custom"); },
|
|
8320
8488
|
onFocus: () => setMode("custom"),
|
|
8321
8489
|
onClick: (e) => e.stopPropagation(),
|
|
8322
8490
|
onKeyDown: (e) => {
|
|
8323
|
-
if (e.key === "Enter" && !busy && customName.trim()) confirm();
|
|
8491
|
+
if (e.key === "Enter" && !e.nativeEvent.isComposing && !busy && customName.trim()) confirm();
|
|
8324
8492
|
}
|
|
8325
8493
|
}),
|
|
8326
8494
|
h(ClearBtn, { value: customName, onClear: () => setCustomName("") }),
|
|
@@ -8517,7 +8685,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8517
8685
|
}
|
|
8518
8686
|
};
|
|
8519
8687
|
|
|
8520
|
-
return h("div", { className: "cpm-dialog",
|
|
8688
|
+
return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
|
|
8521
8689
|
h("div", { className: "cpm-mcp-modal", onClick: (e) => e.stopPropagation() },
|
|
8522
8690
|
h("button", { className: "cpm-mcp-close-top", onClick: onCancel }, h(IconClose, { size: 14 })),
|
|
8523
8691
|
h("div", { className: "cpm-mcp-body" },
|
|
@@ -8755,7 +8923,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8755
8923
|
}, saving ? "保存中…" : "保存并启用"),
|
|
8756
8924
|
),
|
|
8757
8925
|
),
|
|
8758
|
-
confirmDelete && h("div", { className: "cpm-dialog",
|
|
8926
|
+
confirmDelete && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmDelete(false)) },
|
|
8759
8927
|
h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
|
|
8760
8928
|
h("div", { className: "cpm-dialog-title" }, `删除 MCP「${initial.name}」`),
|
|
8761
8929
|
h("div", { className: "cpm-field", style: { fontSize: 13, lineHeight: 1.6, color: "var(--cpm-muted)" } },
|
|
@@ -8896,11 +9064,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8896
9064
|
}
|
|
8897
9065
|
|
|
8898
9066
|
// ────────────────────────────── Detail View ──────────────────────────────
|
|
8899
|
-
function DetailView({ plugin, pluginRecord, isDark, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef }) {
|
|
9067
|
+
function DetailView({ plugin, pluginRecord, isDark, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef, scrollState }) {
|
|
8900
9068
|
const [busy, setBusy] = useState(false);
|
|
8901
9069
|
const [confirmRemove, setConfirmRemove] = useState(false);
|
|
8902
9070
|
const [toggling, setToggling] = useState(false);
|
|
8903
|
-
const { detailRef, maskClass: detailMaskClass, updateMask: updateDetailMask } = useDetailScrollMask(plugin?.name, containerRef, plugin);
|
|
9071
|
+
const { detailRef, maskClass: detailMaskClass, updateMask: updateDetailMask } = useDetailScrollMask(plugin?.name, containerRef, plugin, scrollState);
|
|
8904
9072
|
|
|
8905
9073
|
if (!plugin) return null;
|
|
8906
9074
|
const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
|
|
@@ -9105,7 +9273,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9105
9273
|
}),
|
|
9106
9274
|
),
|
|
9107
9275
|
|
|
9108
|
-
confirmRemove && h("div", { className: "cpm-dialog",
|
|
9276
|
+
confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemove(false)) },
|
|
9109
9277
|
h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
|
|
9110
9278
|
h("div", { className: "cpm-dialog-title" }, `卸载 ${plugin.displayName || plugin.name}?`),
|
|
9111
9279
|
h("div", { className: "cpm-field", style: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" } }, "将删除插件副本、技能与子代理注册及 MCP 配置。"),
|
|
@@ -9145,7 +9313,38 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9145
9313
|
} catch {}
|
|
9146
9314
|
}
|
|
9147
9315
|
|
|
9148
|
-
|
|
9316
|
+
function useAutoMcpTools(servers, loadTools) {
|
|
9317
|
+
const attempted = useRef(new Map());
|
|
9318
|
+
useEffect(() => {
|
|
9319
|
+
const active = new Set();
|
|
9320
|
+
for (const server of servers) {
|
|
9321
|
+
if (!server.connected || !server.name) continue;
|
|
9322
|
+
const key = `${server.owner}::${server.name}`;
|
|
9323
|
+
active.add(key);
|
|
9324
|
+
if (attempted.current.has(key) && attempted.current.get(key) === server.revision) continue;
|
|
9325
|
+
attempted.current.set(key, server.revision);
|
|
9326
|
+
void loadTools(server.owner, server.name);
|
|
9327
|
+
}
|
|
9328
|
+
for (const key of attempted.current.keys()) if (!active.has(key)) attempted.current.delete(key);
|
|
9329
|
+
}, [servers, loadTools]);
|
|
9330
|
+
}
|
|
9331
|
+
|
|
9332
|
+
function McpDiscoveryStatus({ info, expanded, onExpand, onRetry }) {
|
|
9333
|
+
if (!info || info.loading) return h("span", { className: "cpm-mcp-discovery", role: "status", "aria-live": "polite" },
|
|
9334
|
+
h("span", { className: "cpm-spin-ring", "aria-hidden": "true" }),
|
|
9335
|
+
h("span", null, "正在解析工具…"));
|
|
9336
|
+
if (info.error) return h("span", { className: "cpm-mcp-discovery is-error", role: "status", "aria-live": "polite" },
|
|
9337
|
+
h("span", { className: "cpm-mcp-discovery-message" }, `解析失败:${info.error}`),
|
|
9338
|
+
h("button", { type: "button", className: "cpm-mcp-retry", onClick: event => { event.stopPropagation(); onRetry(); } }, "重新解析"));
|
|
9339
|
+
const tools = info.tools || [], disabled = info.disabledTools || [];
|
|
9340
|
+
const active = tools.filter(tool => !disabled.includes(typeof tool === "string" ? tool : tool.name)).length;
|
|
9341
|
+
return h("button", { type: "button", className: "cpm-mcp-expand", "aria-expanded": !!expanded,
|
|
9342
|
+
onClick: event => { event.stopPropagation(); onExpand(); } },
|
|
9343
|
+
h("span", { className: "cpm-connector-collapse-btn" + (expanded ? " is-expanded" : ""), "aria-hidden": "true" }, h(IconArrow, { size: 10 })),
|
|
9344
|
+
h("span", null, `${active} tools enabled${disabled.length ? ` (${disabled.length} disabled)` : ""}`));
|
|
9345
|
+
}
|
|
9346
|
+
|
|
9347
|
+
// Shared tool grid for the MCP page and the plugin manage page: the
|
|
9149
9348
|
// loading/error/empty branches and the hoverable pill grid are identical
|
|
9150
9349
|
// there, and keeping one copy is what stops the two views drifting apart.
|
|
9151
9350
|
function McpToolsPanel({ loading, error, tools, disabledTools, loadingText, onRetry, onHoverTool, onHoverEnd, onToggleTool }) {
|
|
@@ -9283,13 +9482,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9283
9482
|
}
|
|
9284
9483
|
|
|
9285
9484
|
// ────────────────────────────── Manage Page ──────────────────────────────
|
|
9286
|
-
function ManagePage(
|
|
9485
|
+
function ManagePage(props) {
|
|
9486
|
+
useEffect(() => { if (!props.record) props.onClose(); }, [props.record, props.onClose]);
|
|
9487
|
+
return props.record ? h(ManagePageContent, props) : null;
|
|
9488
|
+
}
|
|
9489
|
+
|
|
9490
|
+
function ManagePageContent({ record, state, rows, isDark, refreshState, showToast, onBack, onClose, initialTab, initialConnector, containerRef, scrollState }) {
|
|
9287
9491
|
const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
|
|
9288
|
-
const [tab,
|
|
9492
|
+
const [tab, setTabRaw] = useState(scrollState?.manageTab || initialTab || "skills");
|
|
9493
|
+
const setTab = (next) => { if (scrollState) scrollState.manageTab = next; setTabRaw(next); };
|
|
9289
9494
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
9290
9495
|
const [tabQuery, setTabQuery] = useState("");
|
|
9291
9496
|
const searchInputRef = useRef(null);
|
|
9292
|
-
const [menuOpen, setMenuOpen] = useState(false);
|
|
9293
9497
|
const [busy, setBusy] = useState(false);
|
|
9294
9498
|
const [updating, setUpdating] = useState(false);
|
|
9295
9499
|
const [toggling, setToggling] = useState(false);
|
|
@@ -9323,22 +9527,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9323
9527
|
const loadConnectorTools = useCallback(async (connectorName, forceFresh = false) => {
|
|
9324
9528
|
const key = `${record.name}::${connectorName}`;
|
|
9325
9529
|
const cached = GLOBAL_MCP_TOOLS_CACHE[key];
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
setConnectorToolsData((prev) => ({
|
|
9331
|
-
...prev,
|
|
9332
|
-
[connectorName]: { ...(prev[connectorName] || {}), loading: true, error: null },
|
|
9333
|
-
}));
|
|
9334
|
-
}
|
|
9530
|
+
setConnectorToolsData((prev) => ({
|
|
9531
|
+
...prev,
|
|
9532
|
+
[connectorName]: { ...(prev[connectorName] || {}), loading: true, error: null },
|
|
9533
|
+
}));
|
|
9335
9534
|
|
|
9336
9535
|
try {
|
|
9337
9536
|
const res = await api(`/plugins/${encodeURIComponent(record.name)}/connectors/${encodeURIComponent(connectorName)}/tools${forceFresh ? "?fresh=1" : ""}`);
|
|
9338
9537
|
const tools = Array.isArray(res.tools) ? res.tools : [];
|
|
9339
9538
|
const disabledTools = Array.isArray(res.disabledTools) ? res.disabledTools : [];
|
|
9340
9539
|
|
|
9341
|
-
if (
|
|
9540
|
+
if (res.ok) {
|
|
9342
9541
|
saveMcpToolsCache(key, { tools, disabledTools });
|
|
9343
9542
|
}
|
|
9344
9543
|
|
|
@@ -9347,22 +9546,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9347
9546
|
[connectorName]: {
|
|
9348
9547
|
loading: false,
|
|
9349
9548
|
error: res.ok ? null : (res.message || "获取能力列表失败"),
|
|
9350
|
-
tools:
|
|
9549
|
+
tools: res.ok ? tools : (prev[connectorName]?.tools || tools),
|
|
9351
9550
|
disabledTools,
|
|
9352
9551
|
},
|
|
9353
9552
|
}));
|
|
9354
9553
|
} catch (e) {
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
[connectorName]: {
|
|
9359
|
-
loading: false,
|
|
9360
|
-
error: e.message,
|
|
9361
|
-
tools: [],
|
|
9362
|
-
disabledTools: [],
|
|
9363
|
-
},
|
|
9364
|
-
}));
|
|
9365
|
-
}
|
|
9554
|
+
setConnectorToolsData((prev) => ({
|
|
9555
|
+
...prev, [connectorName]: { ...(prev[connectorName] || cached), loading: false, error: e.message },
|
|
9556
|
+
}));
|
|
9366
9557
|
}
|
|
9367
9558
|
}, [record?.name]);
|
|
9368
9559
|
|
|
@@ -9463,28 +9654,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9463
9654
|
await oauthFlow.start(payload);
|
|
9464
9655
|
};
|
|
9465
9656
|
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
if (isConnected) {
|
|
9472
|
-
loadConnectorTools(cName);
|
|
9473
|
-
}
|
|
9474
|
-
});
|
|
9475
|
-
}
|
|
9476
|
-
}, [record?.name, record?.connectors, loadConnectorTools]);
|
|
9657
|
+
const autoLoadConnectorTools = useCallback((_owner, name) => loadConnectorTools(name), [loadConnectorTools]);
|
|
9658
|
+
useAutoMcpTools((record.connectors || []).map(connector => ({
|
|
9659
|
+
owner: record.name, name: connector.name, connected: connector.connected === true,
|
|
9660
|
+
revision: JSON.stringify([record.installedAt, connector]),
|
|
9661
|
+
})), autoLoadConnectorTools);
|
|
9477
9662
|
|
|
9478
9663
|
const toggleExpandConnector = useCallback((connectorName) => {
|
|
9479
9664
|
setExpandedConnectors((prev) => {
|
|
9480
9665
|
const nextState = !prev[connectorName];
|
|
9481
|
-
const curr = connectorToolsData[connectorName];
|
|
9482
|
-
if (nextState && (!curr || !curr.tools || curr.tools.length === 0)) {
|
|
9483
|
-
loadConnectorTools(connectorName);
|
|
9484
|
-
}
|
|
9485
9666
|
return { ...prev, [connectorName]: nextState };
|
|
9486
9667
|
});
|
|
9487
|
-
}, [
|
|
9668
|
+
}, []);
|
|
9488
9669
|
|
|
9489
9670
|
const toggleTool = useCallback(async (connectorName, toolName, forcedEnabled) => {
|
|
9490
9671
|
const key = `${record.name}::${connectorName}`;
|
|
@@ -9573,7 +9754,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9573
9754
|
const latestVersion = (marketPlugin && (marketPlugin.version || (marketPlugin.detail && marketPlugin.detail.version))) || null;
|
|
9574
9755
|
const hasUpdate = !!(latestVersion && compareSemver(latestVersion, installedVersion) > 0);
|
|
9575
9756
|
|
|
9576
|
-
const
|
|
9757
|
+
const localManageRef = useRef(null);
|
|
9758
|
+
const manageRef = containerRef || localManageRef;
|
|
9577
9759
|
const [manageMaskClass, setManageMaskClass] = useState("");
|
|
9578
9760
|
|
|
9579
9761
|
const updateManageMask = useCallback(() => {
|
|
@@ -9606,16 +9788,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9606
9788
|
|
|
9607
9789
|
useLayoutEffect(() => {
|
|
9608
9790
|
if (record) {
|
|
9609
|
-
setTab("skills");
|
|
9791
|
+
setTab(scrollState?.manageTab || initialTab || "skills");
|
|
9610
9792
|
setTabQuery("");
|
|
9611
9793
|
setSearchOpen(false);
|
|
9612
|
-
setMenuOpen(false);
|
|
9613
|
-
if (manageRef.current) {
|
|
9614
|
-
manageRef.current.scrollTop = 0;
|
|
9615
|
-
}
|
|
9616
9794
|
updateManageMask();
|
|
9617
9795
|
}
|
|
9618
|
-
}, [record?.name, updateManageMask]);
|
|
9796
|
+
}, [record?.name, initialTab, updateManageMask]);
|
|
9797
|
+
useRememberedDetailScroll(`${record?.name}:${tab}`, manageRef, scrollState, updateManageMask, record);
|
|
9619
9798
|
|
|
9620
9799
|
useLayoutEffect(() => { updateManageMask(); });
|
|
9621
9800
|
useEffect(() => {
|
|
@@ -9631,28 +9810,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9631
9810
|
}
|
|
9632
9811
|
}, [searchOpen]);
|
|
9633
9812
|
|
|
9634
|
-
useEffect(() => {
|
|
9635
|
-
if (!record) onClose();
|
|
9636
|
-
}, [record, onClose]);
|
|
9637
|
-
|
|
9638
9813
|
useEffect(() => {
|
|
9639
9814
|
refreshState();
|
|
9640
9815
|
}, []);
|
|
9641
9816
|
|
|
9642
|
-
useEffect(() => {
|
|
9643
|
-
const onDocClick = (e) => {
|
|
9644
|
-
if (!e.target.closest(".cpm-menu")) {
|
|
9645
|
-
setMenuOpen(false);
|
|
9646
|
-
}
|
|
9647
|
-
};
|
|
9648
|
-
if (menuOpen) {
|
|
9649
|
-
document.addEventListener("mousedown", onDocClick);
|
|
9650
|
-
return () => document.removeEventListener("mousedown", onDocClick);
|
|
9651
|
-
}
|
|
9652
|
-
}, [menuOpen]);
|
|
9653
|
-
|
|
9654
|
-
if (!record) return null;
|
|
9655
|
-
|
|
9656
9817
|
const source = state.sources.find((s) => s.id === record.sourceId);
|
|
9657
9818
|
const skills = (Array.isArray(record.skills) && record.skills.length > 0)
|
|
9658
9819
|
? record.skills
|
|
@@ -9899,7 +10060,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9899
10060
|
h("button", { className: "cpm-back", style: { padding: 0 }, onClick: onBack }, h(IconChevronLeft), "Back"),
|
|
9900
10061
|
),
|
|
9901
10062
|
|
|
9902
|
-
h("div", { className: "cpm-title-row"
|
|
10063
|
+
h("div", { className: "cpm-title-row" },
|
|
9903
10064
|
h("div", { className: "cpm-title-group" },
|
|
9904
10065
|
h(PluginIcon, {
|
|
9905
10066
|
plugin: marketPlugin ? {
|
|
@@ -9923,20 +10084,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9923
10084
|
"data-cpm-tip": updating ? "正在更新…" : (hasUpdate ? `可更新至 v${latestVersion}` : `当前已是最新版本 (v${installedVersion})`),
|
|
9924
10085
|
onClick: hasUpdate && !updating ? update : undefined,
|
|
9925
10086
|
}, updating ? "Updating…" : "Update"),
|
|
10087
|
+
h("button", {
|
|
10088
|
+
type: "button", className: "cpm-btn cpm-btn-danger",
|
|
10089
|
+
disabled: busy || updating || toggling,
|
|
10090
|
+
onClick: () => setConfirmRemove(true),
|
|
10091
|
+
}, "Remove"),
|
|
9926
10092
|
h("button", {
|
|
9927
10093
|
className: "cpm-toggle" + (record.enabled ? " on" : ""),
|
|
9928
10094
|
onClick: toggling ? undefined : toggle,
|
|
9929
10095
|
disabled: toggling || updating || busy,
|
|
9930
10096
|
}),
|
|
9931
|
-
h("div", { className: "cpm-menu" },
|
|
9932
|
-
h("button", { className: "cpm-icon-btn", style: { width: 32, height: 32, padding: 0 }, onClick: () => setMenuOpen(!menuOpen) }, h(IconMore)),
|
|
9933
|
-
menuOpen && h("div", { className: "cpm-menu-pop" },
|
|
9934
|
-
h("div", {
|
|
9935
|
-
className: "cpm-menu-item danger",
|
|
9936
|
-
onClick: () => { setMenuOpen(false); setConfirmRemove(true); },
|
|
9937
|
-
}, "卸载插件"),
|
|
9938
|
-
),
|
|
9939
|
-
),
|
|
9940
10097
|
),
|
|
9941
10098
|
|
|
9942
10099
|
h("div", { className: "cpm-meta" },
|
|
@@ -10076,56 +10233,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10076
10233
|
}),
|
|
10077
10234
|
),
|
|
10078
10235
|
|
|
10079
|
-
activeTab === "agents" && h("div",
|
|
10236
|
+
activeTab === "agents" && h("div", null,
|
|
10080
10237
|
visibleAgents.length === 0 && h("div", { className: "cpm-empty" }, tabQuery ? "未找到匹配的 agents" : "没有可用 agents"),
|
|
10081
|
-
visibleAgents.
|
|
10082
|
-
|
|
10083
|
-
const aDisplayName = typeof a === "object" && a.displayName ? a.displayName : (typeof a === "object" && a.name ? a.name : aFile.replace(/\.[^.]+$/, ""));
|
|
10084
|
-
let aDesc = typeof a === "object" && a.description ? a.description : "Autonomous sub-agent workflow";
|
|
10085
|
-
if (aDesc === ">" || aDesc === "|" || aDesc === ">-" || aDesc === "|-") aDesc = "Autonomous sub-agent workflow";
|
|
10086
|
-
const tools = typeof a === "object" && a.tools ? a.tools : null;
|
|
10087
|
-
const model = typeof a === "object" && a.model ? a.model : null;
|
|
10088
|
-
|
|
10089
|
-
return h("div", { key: aFile, className: "cpm-skill-item" },
|
|
10090
|
-
h("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } },
|
|
10091
|
-
h("div", { className: "cpm-skill-name" }, aDisplayName),
|
|
10092
|
-
h("span", {
|
|
10093
|
-
style: {
|
|
10094
|
-
fontSize: 10.5,
|
|
10095
|
-
fontWeight: 600,
|
|
10096
|
-
padding: "2px 6px",
|
|
10097
|
-
borderRadius: 4,
|
|
10098
|
-
background: "rgba(168, 85, 247, 0.12)",
|
|
10099
|
-
color: "#a855f7",
|
|
10100
|
-
letterSpacing: "0.5px",
|
|
10101
|
-
},
|
|
10102
|
-
}, "SUBAGENT"),
|
|
10103
|
-
model && h("span", {
|
|
10104
|
-
style: {
|
|
10105
|
-
fontSize: 10.5,
|
|
10106
|
-
padding: "1px 5px",
|
|
10107
|
-
borderRadius: 3,
|
|
10108
|
-
background: "rgba(161, 161, 170, 0.12)",
|
|
10109
|
-
color: "var(--cpm-muted)",
|
|
10110
|
-
},
|
|
10111
|
-
}, model),
|
|
10112
|
-
),
|
|
10113
|
-
aDesc ? h("div", { className: "cpm-skill-desc", style: { marginTop: 4 } }, h(SmartMarkdown, { text: aDesc })) : null,
|
|
10114
|
-
tools && h("div", {
|
|
10115
|
-
style: {
|
|
10116
|
-
fontSize: 11.5,
|
|
10117
|
-
color: "var(--cpm-muted)",
|
|
10118
|
-
marginTop: 4,
|
|
10119
|
-
display: "flex",
|
|
10120
|
-
alignItems: "center",
|
|
10121
|
-
gap: 4,
|
|
10122
|
-
},
|
|
10123
|
-
},
|
|
10124
|
-
h("span", { style: { opacity: 0.7 } }, "Tools:"),
|
|
10125
|
-
h("code", { style: { fontSize: 11, background: "rgba(128,128,128,0.1)", padding: "1px 4px", borderRadius: 3 } }, tools),
|
|
10126
|
-
),
|
|
10127
|
-
);
|
|
10128
|
-
}),
|
|
10238
|
+
visibleAgents.length > 0 && h("ul", { className: "cpm-agent-list", "aria-label": "Agents" },
|
|
10239
|
+
visibleAgents.map((agent, index) => h(AgentCard, { key: (typeof agent === "string" ? agent : agent?.file || agent?.name) || index, agent }))),
|
|
10129
10240
|
),
|
|
10130
10241
|
|
|
10131
10242
|
activeTab === "hooks" && h("div", { className: "cpm-skill-list" },
|
|
@@ -10224,7 +10335,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10224
10335
|
const toolsInfo = connectorToolsData[cName];
|
|
10225
10336
|
const toolsList = toolsInfo?.tools || [];
|
|
10226
10337
|
const disabledTools = toolsInfo?.disabledTools || [];
|
|
10227
|
-
const activeToolsCount = toolsList.filter((t) => !disabledTools.includes(typeof t === "string" ? t : t.name)).length;
|
|
10228
10338
|
|
|
10229
10339
|
return h("div", {
|
|
10230
10340
|
key: cName,
|
|
@@ -10256,33 +10366,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10256
10366
|
onClick: isPendingVerify ? () => openAuthDialog(cName, c) : undefined,
|
|
10257
10367
|
}, isConnected ? "● 已连接" : (isPendingVerify ? "○ 待验证" : "○ 未连接")),
|
|
10258
10368
|
|
|
10259
|
-
|
|
10260
|
-
|
|
10261
|
-
|
|
10262
|
-
|
|
10263
|
-
alignItems: "center",
|
|
10264
|
-
gap: 4,
|
|
10265
|
-
cursor: "pointer",
|
|
10266
|
-
marginLeft: 2,
|
|
10267
|
-
},
|
|
10268
|
-
onClick: (e) => {
|
|
10269
|
-
e.stopPropagation();
|
|
10270
|
-
toggleExpandConnector(cName);
|
|
10271
|
-
},
|
|
10272
|
-
},
|
|
10273
|
-
h("button", {
|
|
10274
|
-
type: "button",
|
|
10275
|
-
className: "cpm-connector-collapse-btn" + (isExpanded ? " is-expanded" : ""),
|
|
10276
|
-
}, h(IconArrow, { size: 10 })),
|
|
10277
|
-
toolsList.length > 0 && h("span", {
|
|
10278
|
-
style: {
|
|
10279
|
-
fontSize: 11.5,
|
|
10280
|
-
fontWeight: 500,
|
|
10281
|
-
color: "var(--cpm-muted)",
|
|
10282
|
-
userSelect: "none",
|
|
10283
|
-
},
|
|
10284
|
-
}, `${activeToolsCount} tools enabled${disabledTools.length > 0 ? ` (${disabledTools.length} disabled)` : ""}`),
|
|
10285
|
-
),
|
|
10369
|
+
isConnected && isAuthenticated && h(McpDiscoveryStatus, {
|
|
10370
|
+
info: toolsInfo, expanded: isExpanded,
|
|
10371
|
+
onExpand: () => toggleExpandConnector(cName), onRetry: () => loadConnectorTools(cName, true),
|
|
10372
|
+
}),
|
|
10286
10373
|
),
|
|
10287
10374
|
h("div", { className: "cpm-skill-desc", style: { marginTop: 4 } },
|
|
10288
10375
|
endpoint ? `${transport.toUpperCase()} · ${endpoint}` : "Model Context Protocol (MCP) 服务连接器",
|
|
@@ -10310,13 +10397,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10310
10397
|
),
|
|
10311
10398
|
|
|
10312
10399
|
// Figure 1 & Figure 3: Expandable Capabilities Panel
|
|
10313
|
-
isConnected && isAuthenticated && isExpanded && h(McpToolsPanel, {
|
|
10400
|
+
isConnected && isAuthenticated && isExpanded && toolsInfo && !toolsInfo.loading && !toolsInfo.error && h(McpToolsPanel, {
|
|
10314
10401
|
loading: toolsInfo?.loading,
|
|
10315
10402
|
error: toolsInfo?.error,
|
|
10316
10403
|
tools: toolsList,
|
|
10317
10404
|
disabledTools,
|
|
10318
10405
|
loadingText: "正在启动本地 MCP 服务并解析工具列表(首次启动可能需要下载组件)…",
|
|
10319
|
-
onRetry: () => loadConnectorTools(cName),
|
|
10406
|
+
onRetry: () => loadConnectorTools(cName, true),
|
|
10320
10407
|
onHoverTool: (tool, rect, anchor, pointer, keyboard) => toolHover.enter({ connectorName: cName, tool, rect }, anchor, pointer, keyboard),
|
|
10321
10408
|
onHoverEnd: (anchor) => toolHover.leave(anchor),
|
|
10322
10409
|
onToggleTool: (toolName) => toggleTool(cName, toolName),
|
|
@@ -10326,7 +10413,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10326
10413
|
),
|
|
10327
10414
|
),
|
|
10328
10415
|
|
|
10329
|
-
authDialog && h("div", { className: "cpm-dialog",
|
|
10416
|
+
authDialog && h("div", { className: "cpm-dialog", ...backdropDismissProps(closeAuthDialog) },
|
|
10330
10417
|
h("div", { className: "cpm-mcp-modal", onClick: (e) => e.stopPropagation() },
|
|
10331
10418
|
h("button", {
|
|
10332
10419
|
className: "cpm-mcp-close-top",
|
|
@@ -10668,7 +10755,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10668
10755
|
),
|
|
10669
10756
|
),
|
|
10670
10757
|
|
|
10671
|
-
confirmRemove && h("div", { className: "cpm-dialog",
|
|
10758
|
+
confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemove(false)) },
|
|
10672
10759
|
h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
|
|
10673
10760
|
h("div", { className: "cpm-dialog-title" }, `卸载 ${record.displayName || record.name}?`),
|
|
10674
10761
|
h("div", { className: "cpm-field", style: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" } }, "将删除插件副本、技能与子代理注册及 MCP 配置。"),
|
|
@@ -10692,6 +10779,45 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10692
10779
|
);
|
|
10693
10780
|
}
|
|
10694
10781
|
|
|
10782
|
+
function groupAgentTools(tools) {
|
|
10783
|
+
const names = (Array.isArray(tools) ? tools : [tools])
|
|
10784
|
+
.flatMap(value => typeof value === "string" ? value.split(/,(?![^()]*\))/) : [])
|
|
10785
|
+
.map(name => name.trim()).filter(Boolean);
|
|
10786
|
+
const groups = new Map();
|
|
10787
|
+
for (const fullName of names) {
|
|
10788
|
+
const separator = fullName.startsWith("mcp__") ? fullName.indexOf("__", 5) : -1;
|
|
10789
|
+
const qualified = separator > 5 && separator + 2 < fullName.length;
|
|
10790
|
+
const namespace = qualified ? fullName.slice(0, separator) : "";
|
|
10791
|
+
if (!groups.has(namespace)) groups.set(namespace, { namespace, tools: [] });
|
|
10792
|
+
groups.get(namespace).tools.push({ fullName, name: qualified ? fullName.slice(separator + 2) : fullName });
|
|
10793
|
+
}
|
|
10794
|
+
return [...groups.values()];
|
|
10795
|
+
}
|
|
10796
|
+
|
|
10797
|
+
function AgentCard({ agent }) {
|
|
10798
|
+
const info = agent && typeof agent === "object" ? agent : {};
|
|
10799
|
+
const file = typeof agent === "string" ? agent : info.file || info.name || "Agent";
|
|
10800
|
+
const name = info.displayName || info.name || file.replace(/\.[^.]+$/, "");
|
|
10801
|
+
const rawDescription = info.description || "Autonomous sub-agent workflow";
|
|
10802
|
+
const description = [">", "|", ">-", "|-"].includes(rawDescription) ? "Autonomous sub-agent workflow" : rawDescription;
|
|
10803
|
+
const groups = groupAgentTools(info.tools);
|
|
10804
|
+
const count = groups.reduce((total, group) => total + group.tools.length, 0);
|
|
10805
|
+
return h("li", { className: "cpm-agent-item" },
|
|
10806
|
+
h("div", { className: "cpm-agent-header" },
|
|
10807
|
+
h("h3", { className: "cpm-agent-name" }, name),
|
|
10808
|
+
h("div", { className: "cpm-agent-meta" },
|
|
10809
|
+
h("span", null, "Subagent"),
|
|
10810
|
+
info.model && h("span", { className: "cpm-agent-model" }, info.model),
|
|
10811
|
+
count > 0 && h("span", null, `${count} ${count === 1 ? "tool" : "tools"}`))),
|
|
10812
|
+
h("div", { className: "cpm-agent-description" }, h(SmartMarkdown, { text: description })),
|
|
10813
|
+
count > 0 && h("div", { className: "cpm-agent-tools" },
|
|
10814
|
+
groups.map(group => h("div", { key: group.namespace, className: "cpm-agent-tool-group" },
|
|
10815
|
+
h("span", { className: "cpm-agent-tool-source" }, group.namespace || "Tools"),
|
|
10816
|
+
h("ul", { className: "cpm-agent-tool-list", "aria-label": group.namespace || "Tools" },
|
|
10817
|
+
group.tools.map((tool, index) => h("li", { key: index },
|
|
10818
|
+
h("code", { className: "cpm-agent-tool", "aria-label": tool.fullName, "data-tool-name": tool.fullName }, tool.name))))))));
|
|
10819
|
+
}
|
|
10820
|
+
|
|
10695
10821
|
class ErrorBoundary extends React.Component {
|
|
10696
10822
|
constructor(props) {
|
|
10697
10823
|
super(props);
|
|
@@ -10722,7 +10848,294 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10722
10848
|
}
|
|
10723
10849
|
|
|
10724
10850
|
// ────────────────────────────── Main sidebar & panel entry ──────────────────────────────
|
|
10851
|
+
// DSH's keyed slot adds a display:contents anchor around the fallback row.
|
|
10852
|
+
const TOOL_CALL_ROW = ':is([data-chat-call-id], [data-chat-call-id] > [data-slot="tool.call.toolview"]) > [data-variant="others"]';
|
|
10853
|
+
|
|
10854
|
+
function toolCallIconCss(names, url) {
|
|
10855
|
+
const selectors = [];
|
|
10856
|
+
for (const name of names) {
|
|
10857
|
+
if (!/^mcp__[A-Za-z0-9_-]{1,59}$/.test(name)) continue;
|
|
10858
|
+
// DSH ToolCallTree → generic ToolRow → collapsed DisclosureRow.
|
|
10859
|
+
// The idle span fades on hover, so the native chevron still wins.
|
|
10860
|
+
const row = `${TOOL_CALL_ROW}[data-tool="${name}"]:not([data-state="error"], [data-state="stopped"]) > div:not([data-open]) > [data-disclosure-header] > [data-disclosure-row]`;
|
|
10861
|
+
const leading = `${row} > span:first-child`;
|
|
10862
|
+
selectors.push(`${leading} > svg:only-child`, `${leading} > span:first-child > svg:only-child`);
|
|
10863
|
+
}
|
|
10864
|
+
if (!selectors.length) return "";
|
|
10865
|
+
return `@media (forced-colors: none) {
|
|
10866
|
+
${selectors.join(",\n")} {
|
|
10867
|
+
background: url(${JSON.stringify(url)}) center / contain no-repeat;
|
|
10868
|
+
border-radius: var(--cpm-connector-icon-radius);
|
|
10869
|
+
@supports (corner-shape: squircle) {
|
|
10870
|
+
border-radius: 50%;
|
|
10871
|
+
corner-shape: var(--cpm-icon-corner-shape);
|
|
10872
|
+
}
|
|
10873
|
+
}
|
|
10874
|
+
${selectors.map(selector => `${selector} > *`).join(",\n")} { opacity: 0; }
|
|
10875
|
+
}`;
|
|
10876
|
+
}
|
|
10877
|
+
|
|
10878
|
+
function formatToolCallLabel(name, summary, pluginName, rawName) {
|
|
10879
|
+
if (summary !== name && !summary.startsWith(name + " · ")) return summary;
|
|
10880
|
+
const label = `${pluginName} MCP ${rawName.replace(/_+/g, " ").trim()}`;
|
|
10881
|
+
return label + summary.slice(name.length);
|
|
10882
|
+
}
|
|
10883
|
+
|
|
10884
|
+
function createToolCallLabels(onRow) {
|
|
10885
|
+
const rowSelector = `${TOOL_CALL_ROW}[data-tool]`;
|
|
10886
|
+
const headerSelector = ':scope > div > [data-disclosure-header] > [data-disclosure-row]';
|
|
10887
|
+
const shimmerAttribute = "data-shimmer-text";
|
|
10888
|
+
const summaryAttribute = "data-uph-tool-summary";
|
|
10889
|
+
const brandKey = "uph-mcp-brand";
|
|
10890
|
+
const registry = globalThis.CSS?.highlights;
|
|
10891
|
+
const brandHighlight = registry && typeof Highlight === "function" ? new Highlight() : null;
|
|
10892
|
+
if (brandHighlight) registry.set(brandKey, brandHighlight);
|
|
10893
|
+
const changes = new Map();
|
|
10894
|
+
let labelsByName = new Map();
|
|
10895
|
+
let observedTextRows = new WeakSet();
|
|
10896
|
+
const read = (node, attribute) => attribute ? node.getAttribute(attribute) : node.data;
|
|
10897
|
+
const write = (node, attribute, value) => {
|
|
10898
|
+
if (!attribute) node.data = value;
|
|
10899
|
+
else if (value === null) node.removeAttribute(attribute);
|
|
10900
|
+
else node.setAttribute(attribute, value);
|
|
10901
|
+
};
|
|
10902
|
+
|
|
10903
|
+
function restoreChange(node) {
|
|
10904
|
+
const change = changes.get(node);
|
|
10905
|
+
if (!change) return;
|
|
10906
|
+
const { attribute, original, label, brandRange } = change;
|
|
10907
|
+
if (brandRange) brandHighlight.delete(brandRange);
|
|
10908
|
+
if (node.isConnected && read(node, attribute) === label) write(node, attribute, original);
|
|
10909
|
+
changes.delete(node);
|
|
10910
|
+
}
|
|
10911
|
+
|
|
10912
|
+
function restore() {
|
|
10913
|
+
observer?.disconnect();
|
|
10914
|
+
observedTextRows = new WeakSet();
|
|
10915
|
+
for (const node of changes.keys()) restoreChange(node);
|
|
10916
|
+
}
|
|
10917
|
+
|
|
10918
|
+
function updateRow(row) {
|
|
10919
|
+
const name = row.getAttribute("data-tool");
|
|
10920
|
+
if (name?.startsWith("mcp__")) onRow?.(name);
|
|
10921
|
+
const identity = labelsByName.get(name);
|
|
10922
|
+
if (!identity && !row.querySelector(`[${summaryAttribute}]`)) return;
|
|
10923
|
+
if (identity && observer && !observedTextRows.has(row)) {
|
|
10924
|
+
observer.observe(row, { subtree: true, characterData: true });
|
|
10925
|
+
observedTextRows.add(row);
|
|
10926
|
+
}
|
|
10927
|
+
const header = row.querySelector(headerSelector);
|
|
10928
|
+
if (!header) return;
|
|
10929
|
+
for (const summary of header.querySelectorAll("[data-shimmer-decoration] + *")) {
|
|
10930
|
+
const shimmer = summary.querySelector(`[${shimmerAttribute}]`);
|
|
10931
|
+
const node = shimmer || document.createTreeWalker(summary, 4).nextNode();
|
|
10932
|
+
if (!node || !identity) {
|
|
10933
|
+
if (node) restoreChange(node);
|
|
10934
|
+
restoreChange(summary);
|
|
10935
|
+
continue;
|
|
10936
|
+
}
|
|
10937
|
+
const attribute = shimmer ? shimmerAttribute : null;
|
|
10938
|
+
const original = read(node, attribute);
|
|
10939
|
+
const label = formatToolCallLabel(name, original, identity.pluginName, identity.rawName);
|
|
10940
|
+
if (label === original) {
|
|
10941
|
+
if (changes.get(node)?.label !== original) {
|
|
10942
|
+
restoreChange(node);
|
|
10943
|
+
restoreChange(summary);
|
|
10944
|
+
}
|
|
10945
|
+
continue;
|
|
10946
|
+
}
|
|
10947
|
+
restoreChange(node);
|
|
10948
|
+
write(node, attribute, label);
|
|
10949
|
+
let brandRange;
|
|
10950
|
+
if (brandHighlight && !attribute) {
|
|
10951
|
+
brandRange = document.createRange();
|
|
10952
|
+
brandRange.setStart(node, 0);
|
|
10953
|
+
brandRange.setEnd(node, identity.pluginName.length + " MCP".length);
|
|
10954
|
+
brandHighlight.add(brandRange);
|
|
10955
|
+
}
|
|
10956
|
+
changes.set(node, { attribute, original, label, brandRange });
|
|
10957
|
+
if (!changes.has(summary)) {
|
|
10958
|
+
changes.set(summary, { attribute: summaryAttribute, original: read(summary, summaryAttribute), label: "" });
|
|
10959
|
+
write(summary, summaryAttribute, "");
|
|
10960
|
+
}
|
|
10961
|
+
}
|
|
10962
|
+
}
|
|
10963
|
+
|
|
10964
|
+
const observer = typeof MutationObserver === "undefined" ? null : new MutationObserver(records => {
|
|
10965
|
+
const rows = new Set();
|
|
10966
|
+
for (const { target, addedNodes } of records) {
|
|
10967
|
+
const element = target.nodeType === 1 ? target : target.parentElement;
|
|
10968
|
+
const row = element?.closest(rowSelector);
|
|
10969
|
+
if (row) rows.add(row);
|
|
10970
|
+
for (const node of addedNodes) {
|
|
10971
|
+
if (node.nodeType !== 1) continue;
|
|
10972
|
+
if (node.matches(rowSelector)) rows.add(node);
|
|
10973
|
+
for (const child of node.querySelectorAll(rowSelector)) rows.add(child);
|
|
10974
|
+
}
|
|
10975
|
+
}
|
|
10976
|
+
for (const row of rows) if (row.isConnected) updateRow(row);
|
|
10977
|
+
if (records.some(record => record.removedNodes.length)) {
|
|
10978
|
+
for (const node of changes.keys()) if (!node.isConnected) restoreChange(node);
|
|
10979
|
+
}
|
|
10980
|
+
});
|
|
10981
|
+
|
|
10982
|
+
return {
|
|
10983
|
+
update(groups) {
|
|
10984
|
+
restore();
|
|
10985
|
+
labelsByName = new Map(groups.flatMap(({ plugin, tools }) =>
|
|
10986
|
+
tools.map(({ name, rawName }) => [name, { pluginName: plugin.displayName || plugin.name, rawName }])
|
|
10987
|
+
));
|
|
10988
|
+
if ((!labelsByName.size && !onRow) || !observer || !document.body) return;
|
|
10989
|
+
for (const row of document.querySelectorAll(rowSelector)) updateRow(row);
|
|
10990
|
+
observer.observe(document.body, {
|
|
10991
|
+
childList: true, subtree: true,
|
|
10992
|
+
attributes: true, attributeFilter: [shimmerAttribute, "data-tool"],
|
|
10993
|
+
});
|
|
10994
|
+
},
|
|
10995
|
+
dispose() {
|
|
10996
|
+
restore();
|
|
10997
|
+
if (brandHighlight && registry.get(brandKey) === brandHighlight) registry.delete(brandKey);
|
|
10998
|
+
},
|
|
10999
|
+
};
|
|
11000
|
+
}
|
|
11001
|
+
|
|
11002
|
+
function installToolCallIcons(ctx) {
|
|
11003
|
+
const style = document.createElement("style");
|
|
11004
|
+
style.dataset.plugin = "universal-plugin-hub";
|
|
11005
|
+
style.dataset.uphToolCallIcons = "";
|
|
11006
|
+
const chatCss = `${ICON_SHAPE_CSS}
|
|
11007
|
+
[data-disclosure-row] [data-shimmer-decoration]:has(+ [data-uph-tool-summary]),
|
|
11008
|
+
[data-disclosure-row] :has(+ [data-shimmer-decoration] + [data-uph-tool-summary]) {
|
|
11009
|
+
display: none;
|
|
11010
|
+
}
|
|
11011
|
+
@media (forced-colors: none) {
|
|
11012
|
+
::highlight(uph-mcp-brand) { color: #4D6BFE; }
|
|
11013
|
+
}`;
|
|
11014
|
+
style.textContent = chatCss;
|
|
11015
|
+
document.head.append(style);
|
|
11016
|
+
const labels = createToolCallLabels(onRow);
|
|
11017
|
+
const images = new Map();
|
|
11018
|
+
const byName = new Map();
|
|
11019
|
+
const mcpRowSelector = `${TOOL_CALL_ROW}[data-tool^="mcp__"]`;
|
|
11020
|
+
let disposed = false;
|
|
11021
|
+
let request;
|
|
11022
|
+
let checkedAt = -Infinity;
|
|
11023
|
+
let current = "";
|
|
11024
|
+
let generation = 0;
|
|
11025
|
+
const refreshInterval = 10000;
|
|
11026
|
+
|
|
11027
|
+
function decodeIcon(url, warm) {
|
|
11028
|
+
if (!images.has(url)) {
|
|
11029
|
+
const image = new Image();
|
|
11030
|
+
if (warm) image.fetchPriority = "low";
|
|
11031
|
+
image.src = url;
|
|
11032
|
+
const decoded = image.decode().then(() => true, () => {
|
|
11033
|
+
if (images.get(url) === decoded) images.delete(url);
|
|
11034
|
+
return false;
|
|
11035
|
+
});
|
|
11036
|
+
if (images.size >= 128) images.delete(images.keys().next().value);
|
|
11037
|
+
images.set(url, decoded);
|
|
11038
|
+
}
|
|
11039
|
+
return images.get(url);
|
|
11040
|
+
}
|
|
11041
|
+
|
|
11042
|
+
async function publishIcon(group, warm = false) {
|
|
11043
|
+
const revision = generation;
|
|
11044
|
+
const candidates = warm ? group.urls.slice(0, 1) : group.urls;
|
|
11045
|
+
for (const url of candidates) {
|
|
11046
|
+
if (disposed || revision !== generation || group.published) return;
|
|
11047
|
+
if (!await decodeIcon(url, warm)) continue;
|
|
11048
|
+
if (disposed || revision !== generation || group.published) return;
|
|
11049
|
+
const rule = toolCallIconCss(group.names, url);
|
|
11050
|
+
if (rule && style.sheet) style.sheet.insertRule(rule, style.sheet.cssRules.length);
|
|
11051
|
+
group.published = true;
|
|
11052
|
+
return;
|
|
11053
|
+
}
|
|
11054
|
+
}
|
|
11055
|
+
|
|
11056
|
+
function onRow(name) {
|
|
11057
|
+
const group = byName.get(name);
|
|
11058
|
+
const now = Date.now();
|
|
11059
|
+
if (group && !group.loading && !group.published && now >= (group.retryAt ?? 0)) {
|
|
11060
|
+
group.loading = true;
|
|
11061
|
+
void publishIcon(group).catch(() => {}).finally(() => {
|
|
11062
|
+
group.loading = false;
|
|
11063
|
+
if (!group.published) group.retryAt = Date.now() + refreshInterval;
|
|
11064
|
+
});
|
|
11065
|
+
}
|
|
11066
|
+
if (now - checkedAt >= refreshInterval) void refresh(true);
|
|
11067
|
+
}
|
|
11068
|
+
|
|
11069
|
+
function setGroups(groups, dark) {
|
|
11070
|
+
const signature = JSON.stringify([dark, groups]);
|
|
11071
|
+
if (signature === current) return;
|
|
11072
|
+
generation++;
|
|
11073
|
+
current = signature;
|
|
11074
|
+
byName.clear();
|
|
11075
|
+
style.textContent = chatCss;
|
|
11076
|
+
// Only decode small, already available artwork on the startup path.
|
|
11077
|
+
let warmCount = 0;
|
|
11078
|
+
let warmBytes = 0;
|
|
11079
|
+
for (const { plugin, tools } of groups) {
|
|
11080
|
+
const names = tools.map(tool => tool.name);
|
|
11081
|
+
const urls = getPluginIconCandidates(plugin, dark)
|
|
11082
|
+
.flatMap(url => [plugin.icons?.previews?.[url], url]).filter(Boolean);
|
|
11083
|
+
const group = { names, urls };
|
|
11084
|
+
for (const name of names) byName.set(name, group);
|
|
11085
|
+
const inline = urls[0];
|
|
11086
|
+
if (warmCount < 12 && inline?.startsWith("data:image/") && warmBytes + inline.length <= 256 * 1024) {
|
|
11087
|
+
warmCount++;
|
|
11088
|
+
warmBytes += inline.length;
|
|
11089
|
+
void publishIcon(group, true).catch(() => {});
|
|
11090
|
+
}
|
|
11091
|
+
}
|
|
11092
|
+
labels.update(groups);
|
|
11093
|
+
}
|
|
11094
|
+
|
|
11095
|
+
async function refresh(force = false) {
|
|
11096
|
+
if (disposed || request || document.hidden) return;
|
|
11097
|
+
if (!force && !document.querySelector(mcpRowSelector)) return;
|
|
11098
|
+
const controller = new AbortController();
|
|
11099
|
+
request = controller;
|
|
11100
|
+
checkedAt = Date.now();
|
|
11101
|
+
try {
|
|
11102
|
+
const { groups } = await api("/tool-call-icons", { cache: "no-store", signal: controller.signal });
|
|
11103
|
+
if (request === controller) setGroups(groups, isDarkMode(ctx, document.documentElement));
|
|
11104
|
+
} catch {
|
|
11105
|
+
if (request === controller) setGroups([], false);
|
|
11106
|
+
} finally {
|
|
11107
|
+
if (request === controller) request = undefined;
|
|
11108
|
+
}
|
|
11109
|
+
}
|
|
11110
|
+
|
|
11111
|
+
function invalidate() {
|
|
11112
|
+
request?.abort();
|
|
11113
|
+
request = undefined;
|
|
11114
|
+
checkedAt = -Infinity;
|
|
11115
|
+
void refresh(true);
|
|
11116
|
+
setGroups([], false);
|
|
11117
|
+
}
|
|
11118
|
+
|
|
11119
|
+
const onVisibility = () => void refresh(!current || Date.now() - checkedAt >= refreshInterval);
|
|
11120
|
+
const timer = setInterval(refresh, refreshInterval);
|
|
11121
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
11122
|
+
document.addEventListener("uph-mcp-branding-changed", invalidate);
|
|
11123
|
+
void refresh(true);
|
|
11124
|
+
return () => {
|
|
11125
|
+
disposed = true;
|
|
11126
|
+
request?.abort();
|
|
11127
|
+
request = undefined;
|
|
11128
|
+
clearInterval(timer);
|
|
11129
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
11130
|
+
document.removeEventListener("uph-mcp-branding-changed", invalidate);
|
|
11131
|
+
labels.dispose();
|
|
11132
|
+
style.remove();
|
|
11133
|
+
};
|
|
11134
|
+
}
|
|
11135
|
+
|
|
10725
11136
|
function Section({ ctx }) {
|
|
11137
|
+
const useStyleEffect = React.useInsertionEffect || useSafeLayoutEffect;
|
|
11138
|
+
useStyleEffect(ensureCss, []);
|
|
10726
11139
|
return h(ErrorBoundary, null, h(MarketApp, { ctx }));
|
|
10727
11140
|
}
|
|
10728
11141
|
|
|
@@ -10750,7 +11163,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10750
11163
|
const inject = ["slots", "theme"];
|
|
10751
11164
|
|
|
10752
11165
|
function apply(ctx) {
|
|
10753
|
-
|
|
11166
|
+
ctx.effect?.(() => installToolCallIcons(ctx), "universal-plugin-hub: tool call icons");
|
|
10754
11167
|
ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
|
|
10755
11168
|
name: "sidebar.panellist",
|
|
10756
11169
|
id: "universal-plugin-hub",
|