dsh-agy-link 0.4.41 → 0.4.43
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/CHANGELOG.md +43 -2
- package/assets/mermaid.min.js +3636 -0
- package/dist/client.js +253 -18
- package/dist/index.js +482 -131
- package/dist/mermaid.min.js +3636 -0
- package/package.json +4 -2
package/dist/client.js
CHANGED
|
@@ -1345,7 +1345,7 @@ window.__ModuleLoader__.load({
|
|
|
1345
1345
|
|
|
1346
1346
|
/* Diff stat badge (+10 -2) */
|
|
1347
1347
|
.agy-tv-diff-stat {
|
|
1348
|
-
font-family: var(--
|
|
1348
|
+
font-family: var(--ds-font-family-code, ui-monospace, monospace);
|
|
1349
1349
|
font-size: calc(var(--dsh-content-font-size-secondary, 13px) - 2px);
|
|
1350
1350
|
color: var(--dsw-alias-label-caption, #94a3b8);
|
|
1351
1351
|
margin-left: 10px;
|
|
@@ -1354,7 +1354,7 @@ window.__ModuleLoader__.load({
|
|
|
1354
1354
|
|
|
1355
1355
|
/* Preview text */
|
|
1356
1356
|
.agy-tv-preview {
|
|
1357
|
-
font-family: var(--
|
|
1357
|
+
font-family: var(--ds-font-family-code, ui-monospace, monospace);
|
|
1358
1358
|
font-size: 11px;
|
|
1359
1359
|
color: var(--dsw-alias-label-caption, #94a3b8);
|
|
1360
1360
|
margin-left: 8px;
|
|
@@ -1375,7 +1375,7 @@ window.__ModuleLoader__.load({
|
|
|
1375
1375
|
.agy-tv-card {
|
|
1376
1376
|
border: 0.5px solid var(--dsw-alias-border-l1, #e2e8f0);
|
|
1377
1377
|
background: var(--dsw-alias-markdown-code-block, #f8fafc);
|
|
1378
|
-
font-family: var(--
|
|
1378
|
+
font-family: var(--ds-font-family-code, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
|
|
1379
1379
|
font-size: 12px;
|
|
1380
1380
|
line-height: 1.55;
|
|
1381
1381
|
border-radius: 12px;
|
|
@@ -1564,6 +1564,228 @@ window.__ModuleLoader__.load({
|
|
|
1564
1564
|
}
|
|
1565
1565
|
}
|
|
1566
1566
|
//#endregion
|
|
1567
|
+
//#region src/client/mermaid.ts
|
|
1568
|
+
const MERMAID_CSS = `
|
|
1569
|
+
div.md-code-block[data-agy-mermaid="done"] [data-code-block-content] {
|
|
1570
|
+
display: none !important;
|
|
1571
|
+
}
|
|
1572
|
+
div.md-code-block[data-agy-mermaid="render"] {
|
|
1573
|
+
border-color: var(--dsw-alias-border-l2, #e2e8f0);
|
|
1574
|
+
}
|
|
1575
|
+
div[data-agy-mermaid-svg] {
|
|
1576
|
+
padding: 12px 8px;
|
|
1577
|
+
overflow-x: auto;
|
|
1578
|
+
text-align: center;
|
|
1579
|
+
background: var(--dsw-alias-bg-base, #ffffff);
|
|
1580
|
+
}
|
|
1581
|
+
div[data-agy-mermaid-svg] svg {
|
|
1582
|
+
max-width: 100%;
|
|
1583
|
+
height: auto;
|
|
1584
|
+
}
|
|
1585
|
+
div[data-agy-mermaid-svg][data-agy-mermaid-error] {
|
|
1586
|
+
text-align: left;
|
|
1587
|
+
color: var(--dsw-alias-label-tertiary, #64748b);
|
|
1588
|
+
font-size: 12px;
|
|
1589
|
+
white-space: pre-wrap;
|
|
1590
|
+
padding: 10px 12px;
|
|
1591
|
+
}
|
|
1592
|
+
`;
|
|
1593
|
+
const CDN_URLS = [
|
|
1594
|
+
"/plugins/agy-link/mermaid.min.js",
|
|
1595
|
+
"https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js",
|
|
1596
|
+
"https://unpkg.com/mermaid@11/dist/mermaid.min.js"
|
|
1597
|
+
];
|
|
1598
|
+
let loadPromise = null;
|
|
1599
|
+
let loadFailedAt = 0;
|
|
1600
|
+
const LOAD_RETRY_MS = 6e4;
|
|
1601
|
+
let renderSeq = 0;
|
|
1602
|
+
function injectStyles$1() {
|
|
1603
|
+
if (typeof document === "undefined") return;
|
|
1604
|
+
if (document.getElementById("agy-mermaid-css")) return;
|
|
1605
|
+
const st = document.createElement("style");
|
|
1606
|
+
st.id = "agy-mermaid-css";
|
|
1607
|
+
st.textContent = MERMAID_CSS;
|
|
1608
|
+
document.head.appendChild(st);
|
|
1609
|
+
}
|
|
1610
|
+
function loadScript(src) {
|
|
1611
|
+
return new Promise((resolve) => {
|
|
1612
|
+
const s = document.createElement("script");
|
|
1613
|
+
s.src = src;
|
|
1614
|
+
s.async = true;
|
|
1615
|
+
const done = (ok) => {
|
|
1616
|
+
s.removeEventListener("load", onLoad);
|
|
1617
|
+
s.removeEventListener("error", onError);
|
|
1618
|
+
resolve(ok);
|
|
1619
|
+
};
|
|
1620
|
+
const onLoad = () => done(true);
|
|
1621
|
+
const onError = () => done(false);
|
|
1622
|
+
s.addEventListener("load", onLoad);
|
|
1623
|
+
s.addEventListener("error", onError);
|
|
1624
|
+
document.head.appendChild(s);
|
|
1625
|
+
setTimeout(() => done(false), 15e3);
|
|
1626
|
+
});
|
|
1627
|
+
}
|
|
1628
|
+
async function loadMermaid() {
|
|
1629
|
+
if (typeof window === "undefined") return null;
|
|
1630
|
+
if (window.mermaid !== void 0) return window.mermaid;
|
|
1631
|
+
if (loadPromise !== null) return loadPromise;
|
|
1632
|
+
if (Date.now() - loadFailedAt < LOAD_RETRY_MS) return null;
|
|
1633
|
+
loadPromise = (async () => {
|
|
1634
|
+
for (const url of CDN_URLS) if (await loadScript(url) && window.mermaid !== void 0) {
|
|
1635
|
+
try {
|
|
1636
|
+
window.mermaid.initialize({
|
|
1637
|
+
startOnLoad: false,
|
|
1638
|
+
securityLevel: "strict",
|
|
1639
|
+
theme: "neutral",
|
|
1640
|
+
fontFamily: "inherit"
|
|
1641
|
+
});
|
|
1642
|
+
} catch {}
|
|
1643
|
+
return window.mermaid;
|
|
1644
|
+
}
|
|
1645
|
+
loadFailedAt = Date.now();
|
|
1646
|
+
loadPromise = null;
|
|
1647
|
+
return null;
|
|
1648
|
+
})();
|
|
1649
|
+
return loadPromise;
|
|
1650
|
+
}
|
|
1651
|
+
/** Banner infostring text ("mermaid") identifies the fence language. */
|
|
1652
|
+
function fenceLang(block) {
|
|
1653
|
+
const text = ((block.querySelector("[data-code-block-banner] [class*=\"infostring\"]") ?? block.querySelector("[data-code-block-banner] [class*=\"language\"]") ?? block.querySelector("[data-code-block-banner]"))?.textContent ?? "").trim().toLowerCase();
|
|
1654
|
+
if (text !== "") return text.split(/\s+/)[0] ?? "";
|
|
1655
|
+
const code = block.querySelector("[data-code-block-content] code");
|
|
1656
|
+
const m = (code?.getAttribute("class") ?? "").match(/language-([\w-]+)/);
|
|
1657
|
+
if (m?.[1]) return m[1].toLowerCase();
|
|
1658
|
+
return (code?.getAttribute("data-language") ?? block.getAttribute("data-language") ?? "").toLowerCase();
|
|
1659
|
+
}
|
|
1660
|
+
const MERMAID_FIRST_LINE = /^(?:flowchart(?:\s+\w+)?|graph\s+(?:TB|TD|LR|RL|BT)|sequenceDiagram|classDiagram(?:-v2)?|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|sankey-beta|xychart-beta|block-beta|quadrantChart|requirementDiagram|radar-beta|C4(?:Context|Container|Component|Dynamic))\b/;
|
|
1661
|
+
/** Content sniff: unknown-language fences are the whole reason this module exists. */
|
|
1662
|
+
function looksLikeMermaidSource(source) {
|
|
1663
|
+
const line = source.split(/\r?\n/).find((l) => l.trim() !== "");
|
|
1664
|
+
return line !== void 0 && MERMAID_FIRST_LINE.test(line.trim());
|
|
1665
|
+
}
|
|
1666
|
+
function isMermaidLang(lang) {
|
|
1667
|
+
return lang === "mermaid" || lang === "mermaidjs" || lang.startsWith("mermaid");
|
|
1668
|
+
}
|
|
1669
|
+
const KNOWN_NON_MERMAID = /* @__PURE__ */ new Set([
|
|
1670
|
+
"typescript",
|
|
1671
|
+
"ts",
|
|
1672
|
+
"javascript",
|
|
1673
|
+
"js",
|
|
1674
|
+
"jsx",
|
|
1675
|
+
"tsx",
|
|
1676
|
+
"python",
|
|
1677
|
+
"py",
|
|
1678
|
+
"java",
|
|
1679
|
+
"c",
|
|
1680
|
+
"cpp",
|
|
1681
|
+
"c++",
|
|
1682
|
+
"csharp",
|
|
1683
|
+
"cs",
|
|
1684
|
+
"go",
|
|
1685
|
+
"golang",
|
|
1686
|
+
"rust",
|
|
1687
|
+
"rs",
|
|
1688
|
+
"php",
|
|
1689
|
+
"ruby",
|
|
1690
|
+
"rb",
|
|
1691
|
+
"swift",
|
|
1692
|
+
"kotlin",
|
|
1693
|
+
"kt",
|
|
1694
|
+
"scala",
|
|
1695
|
+
"shell",
|
|
1696
|
+
"bash",
|
|
1697
|
+
"sh",
|
|
1698
|
+
"zsh",
|
|
1699
|
+
"sql",
|
|
1700
|
+
"html",
|
|
1701
|
+
"css",
|
|
1702
|
+
"scss",
|
|
1703
|
+
"less",
|
|
1704
|
+
"json",
|
|
1705
|
+
"yaml",
|
|
1706
|
+
"yml",
|
|
1707
|
+
"xml",
|
|
1708
|
+
"graphql",
|
|
1709
|
+
"toml",
|
|
1710
|
+
"ini",
|
|
1711
|
+
"dockerfile",
|
|
1712
|
+
"makefile"
|
|
1713
|
+
]);
|
|
1714
|
+
function isMermaidBlock(lang, source) {
|
|
1715
|
+
if (isMermaidLang(lang)) return true;
|
|
1716
|
+
if (KNOWN_NON_MERMAID.has(lang)) return false;
|
|
1717
|
+
return looksLikeMermaidSource(source);
|
|
1718
|
+
}
|
|
1719
|
+
function readSource(block) {
|
|
1720
|
+
return ((block.querySelector("[data-code-block-content] code") ?? block.querySelector("[data-code-block-content] pre") ?? block.querySelector("[data-code-block-content]"))?.textContent ?? "").trim();
|
|
1721
|
+
}
|
|
1722
|
+
async function renderInto(block, source) {
|
|
1723
|
+
block.querySelector("[data-agy-mermaid-svg]")?.remove();
|
|
1724
|
+
const mount = document.createElement("div");
|
|
1725
|
+
mount.setAttribute("data-agy-mermaid-svg", "1");
|
|
1726
|
+
block.appendChild(mount);
|
|
1727
|
+
const api = await loadMermaid();
|
|
1728
|
+
if (api === null) {
|
|
1729
|
+
block.setAttribute("data-agy-mermaid", "error");
|
|
1730
|
+
mount.setAttribute("data-agy-mermaid-error", "1");
|
|
1731
|
+
mount.textContent = "Mermaid renderer unavailable (offline). Diagram source stays below.";
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
try {
|
|
1735
|
+
renderSeq += 1;
|
|
1736
|
+
const id = "agy-mmd-" + renderSeq;
|
|
1737
|
+
const { svg } = await api.render(id, source);
|
|
1738
|
+
mount.innerHTML = svg;
|
|
1739
|
+
block.setAttribute("data-agy-mermaid", "done");
|
|
1740
|
+
} catch (e) {
|
|
1741
|
+
block.setAttribute("data-agy-mermaid", "error");
|
|
1742
|
+
mount.setAttribute("data-agy-mermaid-error", "1");
|
|
1743
|
+
mount.textContent = "Mermaid render failed: " + (e instanceof Error ? e.message : String(e));
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
let scanTimer = null;
|
|
1747
|
+
function scheduleScan() {
|
|
1748
|
+
if (scanTimer !== null) return;
|
|
1749
|
+
scanTimer = setTimeout(() => {
|
|
1750
|
+
scanTimer = null;
|
|
1751
|
+
scan();
|
|
1752
|
+
}, 150);
|
|
1753
|
+
}
|
|
1754
|
+
function scan() {
|
|
1755
|
+
if (typeof document === "undefined") return;
|
|
1756
|
+
const blocks = document.querySelectorAll(".md-code-block");
|
|
1757
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
1758
|
+
const block = blocks[i];
|
|
1759
|
+
if (!block) continue;
|
|
1760
|
+
const state = block.getAttribute("data-agy-mermaid");
|
|
1761
|
+
if (state === "done" || state === "busy" || state === "error") continue;
|
|
1762
|
+
const lang = fenceLang(block);
|
|
1763
|
+
const source = readSource(block);
|
|
1764
|
+
if (source === "") continue;
|
|
1765
|
+
if (!isMermaidBlock(lang, source)) continue;
|
|
1766
|
+
block.setAttribute("data-agy-mermaid", "busy");
|
|
1767
|
+
renderInto(block, source);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
function installMermaidRendering() {
|
|
1771
|
+
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
1772
|
+
injectStyles$1();
|
|
1773
|
+
const observer = new MutationObserver(() => {
|
|
1774
|
+
scheduleScan();
|
|
1775
|
+
});
|
|
1776
|
+
const setup = () => {
|
|
1777
|
+
if (document.body) {
|
|
1778
|
+
observer.observe(document.body, {
|
|
1779
|
+
childList: true,
|
|
1780
|
+
subtree: true
|
|
1781
|
+
});
|
|
1782
|
+
scan();
|
|
1783
|
+
}
|
|
1784
|
+
};
|
|
1785
|
+
if (document.readyState === "loading") window.addEventListener("DOMContentLoaded", setup, { once: true });
|
|
1786
|
+
else setup();
|
|
1787
|
+
}
|
|
1788
|
+
//#endregion
|
|
1567
1789
|
//#region src/client/reasoning.ts
|
|
1568
1790
|
const REASONING_CSS = `
|
|
1569
1791
|
/* Hover affordance on thinking disclosure rows */
|
|
@@ -2729,12 +2951,12 @@ body.dark,
|
|
|
2729
2951
|
color: "var(--agy-text-primary)"
|
|
2730
2952
|
} }, brandIcon(FAMILY_BRAND[familyKey], 14), h("span", null, label)), renderLine(t("quota.fiveHour"), pct5h, c5h, w5h.resetText ? w5h.resetText + cdNote : cdNote.replace(/^ · /, "")), renderLine(t("quota.weekly"), pctWeekly, cWeekly, wWeekly.resetText));
|
|
2731
2953
|
};
|
|
2732
|
-
const
|
|
2954
|
+
const activeAccountId = pool?.activeAccountId ?? pool?.lastActiveAccountId ?? pool?.activeAccountIds?.google ?? pool?.primaryAccountId;
|
|
2733
2955
|
const renderedAccountCards = accounts.map((acc) => {
|
|
2734
2956
|
const isPrimary = acc.id === pool?.primaryAccountId;
|
|
2735
|
-
const isInUse = inUseIds.has(acc.id);
|
|
2736
2957
|
const hasCooldown = Object.entries(acc.cooldowns).some(([, cd]) => cd && cd.cooldownUntil > Date.now());
|
|
2737
2958
|
const isAuthRequired = acc.authRequired;
|
|
2959
|
+
const isInUse = acc.enabled && !isAuthRequired && activeAccountId !== void 0 && activeAccountId === acc.id;
|
|
2738
2960
|
const dotColor = !acc.enabled ? "#64748b" : isAuthRequired ? "#ef4444" : hasCooldown ? "#f59e0b" : "#10b981";
|
|
2739
2961
|
const isEditingProxy = editingProxyId === acc.id;
|
|
2740
2962
|
const isExpanded = expandedModels[acc.id] ?? false;
|
|
@@ -2798,14 +3020,17 @@ body.dark,
|
|
|
2798
3020
|
} }, uiIcon("mail", 11, "var(--agy-badge-email-text)"), acc.email) : null, isPrimary ? h("span", { style: {
|
|
2799
3021
|
...S.badgePrimary,
|
|
2800
3022
|
gap: "4px"
|
|
2801
|
-
} }, uiIcon("star", 10, "var(--agy-badge-primary-text)"), t("status.primary")) : null, isInUse ? h("span", {
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
3023
|
+
} }, uiIcon("star", 10, "var(--agy-badge-primary-text)"), t("status.primary")) : null, isInUse ? h("span", {
|
|
3024
|
+
style: {
|
|
3025
|
+
...S.badgeTag,
|
|
3026
|
+
background: "rgba(16, 185, 129, 0.12)",
|
|
3027
|
+
color: "#10b981",
|
|
3028
|
+
borderColor: "rgba(16, 185, 129, 0.45)",
|
|
3029
|
+
gap: "4px",
|
|
3030
|
+
fontWeight: 700
|
|
3031
|
+
},
|
|
3032
|
+
title: t("status.inUse")
|
|
3033
|
+
}, uiIcon("zap", 11, "#10b981"), t("status.inUse")) : null, acc.proxyUrl ? h("span", { style: {
|
|
2809
3034
|
...S.badgeTag,
|
|
2810
3035
|
background: "var(--agy-badge-proxy-bg)",
|
|
2811
3036
|
color: "var(--agy-badge-proxy-text)",
|
|
@@ -3261,13 +3486,22 @@ body.dark,
|
|
|
3261
3486
|
clearInterval(timer);
|
|
3262
3487
|
};
|
|
3263
3488
|
}, []);
|
|
3264
|
-
const
|
|
3265
|
-
const
|
|
3489
|
+
const pool = status?.pool;
|
|
3490
|
+
const accounts = pool?.accounts ?? [];
|
|
3491
|
+
const rawActiveId = pool?.activeAccountId ?? pool?.lastActiveAccountId ?? pool?.activeAccountIds?.google ?? pool?.primaryAccountId;
|
|
3492
|
+
const activeAcc = accounts.find((a) => a.id === rawActiveId && a.enabled && !a.authRequired) ?? accounts.find((a) => a.enabled && !a.authRequired) ?? accounts[0];
|
|
3493
|
+
const activeHasCooldown = activeAcc ? Object.entries(activeAcc.cooldowns).some(([, cd]) => cd && cd.cooldownUntil > Date.now()) : false;
|
|
3494
|
+
const allInCooldown = accounts.length > 0 && accounts.every((a) => !a.enabled || a.authRequired || Object.entries(a.cooldowns).some(([, cd]) => cd && cd.cooldownUntil > Date.now()));
|
|
3266
3495
|
const isAuthed = status?.auth?.phase === "ok" || accounts.length > 0;
|
|
3267
|
-
const color = status === null ? "#64748b" : status.dormantReason ? "#f59e0b" :
|
|
3496
|
+
const color = status === null ? "#64748b" : status.dormantReason ? "#f59e0b" : allInCooldown ? "#f59e0b" : activeHasCooldown ? "#f59e0b" : isAuthed ? "#10b981" : "#f59e0b";
|
|
3497
|
+
const legacyDefault = activeAcc && activeAcc.defaultAlias === void 0 && activeAcc.systemHome && activeAcc.alias === "主账号 (系统登录)";
|
|
3498
|
+
const displayAlias = activeAcc ? activeAcc.defaultAlias || legacyDefault ? activeAcc.systemHome ? t("account.defaultAlias") : t("account.aliasDefault", { number: accounts.indexOf(activeAcc) + 1 }) : activeAcc.alias : "";
|
|
3499
|
+
const activeDetail = activeAcc ? ` · ${t("status.inUse")}: ${displayAlias}${activeAcc.email ? ` (${activeAcc.email})` : ""}` : "";
|
|
3500
|
+
const badgeTitle = `${t("header.badgeTitle", { count: accounts.length })}${activeDetail}`;
|
|
3501
|
+
const buttonLabel = displayAlias ? `AGY · ${displayAlias}` : `AGY (${accounts.length})`;
|
|
3268
3502
|
const badge = h("button", {
|
|
3269
3503
|
type: "button",
|
|
3270
|
-
title:
|
|
3504
|
+
title: badgeTitle,
|
|
3271
3505
|
className: "agy-btn",
|
|
3272
3506
|
onClick: () => agyModalStore.setOpen(true),
|
|
3273
3507
|
style: {
|
|
@@ -3291,7 +3525,7 @@ body.dark,
|
|
|
3291
3525
|
height: "7px",
|
|
3292
3526
|
borderRadius: "50%",
|
|
3293
3527
|
background: color
|
|
3294
|
-
} }),
|
|
3528
|
+
} }), buttonLabel);
|
|
3295
3529
|
return h("div", { style: { display: "inline-block" } }, badge, portalToBody(h(AgyModalDialog, null)));
|
|
3296
3530
|
};
|
|
3297
3531
|
ctx.slots.inject("conversation.session.header.actions", () => {
|
|
@@ -3314,6 +3548,7 @@ body.dark,
|
|
|
3314
3548
|
});
|
|
3315
3549
|
installAgyToolView(ctx);
|
|
3316
3550
|
installAutoExpandReasoning();
|
|
3551
|
+
installMermaidRendering();
|
|
3317
3552
|
}
|
|
3318
3553
|
//#endregion
|
|
3319
3554
|
exports.apply = apply;
|