dsh-agy-link 0.6.24 → 0.6.25
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 +12 -0
- package/dist/client.js +138 -100
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.6.25 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
### English
|
|
6
|
+
|
|
7
|
+
- **Perf(client): scope DOM scanning so streaming no longer sweeps the whole document (merges PR #110).** `scanAndEnhanceImages()` runs on a 100ms debounce for every DOM mutation; it previously re-queried every `a[href]` for three separate enhancers and walked every markdown container on each pass, even when nothing new existed. Links are now visited once (`data-agy-link-scanned`), image/video/file dispatch is a single pass, alt-span work exits early when no unenhanced spans remain, and origin rewrites skip already-processed images. Thanks to @Ronnoc for the profiling and patch.
|
|
8
|
+
- **Fix(client): a streaming markdown change re-evaluates previously skipped alt spans.** The perf pass stamps non-matching alt spans as scanned; without a guard, a span present before its `` link streamed in would be skipped forever. Containers now carry a short text fingerprint, and a changed fingerprint clears the stamps so the span is retried — the fast path stays a single attribute query. Regression test reproduces the two-chunk stream.
|
|
9
|
+
|
|
10
|
+
### 中文
|
|
11
|
+
|
|
12
|
+
- **性能(客户端):收敛 DOM 扫描范围,避免流式输出时全文档轮询(合并 PR #110)。** `scanAndEnhanceImages()` 在每次 DOM 变更的 100ms debounce 上执行,旧实现对全部 `a[href]` 跑三遍增强器、并遍历页面上每个 markdown 容器,即使没有新节点也重复解析。现在链接只访问一次(`data-agy-link-scanned`)、图片/视频/文件判断合并为单趟、无未处理 alt span 时快速返回、已改写的图片不再重复处理。感谢 @Ronnoc 的定位与补丁。
|
|
13
|
+
- **修复(客户端):markdown 文本变化后重新评估此前跳过的 alt span。** 性能优化会把「当前没有本地图片匹配」的 span 标记为已扫描;若 span 先于 `` 链接出现(流式分块),就会永久跳过。现为每个容器保存短文本指纹,指纹变化时清除标记并重试;快速路径仍只是一次属性查询。新增两段式流式回归测试。
|
|
14
|
+
|
|
3
15
|
## 0.6.24 (2026-11-14)
|
|
4
16
|
|
|
5
17
|
### English
|
package/dist/client.js
CHANGED
|
@@ -2622,24 +2622,67 @@ window.__ModuleLoader__.load({
|
|
|
2622
2622
|
}
|
|
2623
2623
|
function rewriteMediaOrigins(origin) {
|
|
2624
2624
|
if (!origin || origin.includes("127.0.0.1") || origin.includes("localhost")) return;
|
|
2625
|
-
const images = document.querySelectorAll("img[src*=\"/plugins/agy-link/media\"]");
|
|
2625
|
+
const images = document.querySelectorAll("img[src*=\"/plugins/agy-link/media\"]:not([data-agy-origin-rewritten])");
|
|
2626
2626
|
for (let i = 0; i < images.length; i++) {
|
|
2627
2627
|
const img = images[i];
|
|
2628
|
-
if (img
|
|
2628
|
+
if (!img) continue;
|
|
2629
|
+
if (img.src.includes("127.0.0.1")) {
|
|
2629
2630
|
const u = new URL(img.src);
|
|
2630
2631
|
img.src = `${origin}${u.pathname}${u.search}`;
|
|
2631
2632
|
}
|
|
2633
|
+
img.dataset.agyOriginRewritten = "true";
|
|
2632
2634
|
}
|
|
2633
2635
|
}
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2636
|
+
/**
|
|
2637
|
+
* PR #110 stamps non-matching alt spans as "scanned" so later passes can exit
|
|
2638
|
+
* early. Streaming markdown grows while tokens arrive, so a span skipped once
|
|
2639
|
+
* must be re-evaluated when its container's markdown text changes. Track a
|
|
2640
|
+
* short fingerprint on the container (never the whole text) and clear the
|
|
2641
|
+
* stamps only for containers whose text actually changed — the fast path stays
|
|
2642
|
+
* a single cheap attribute query.
|
|
2643
|
+
*/
|
|
2644
|
+
const ALT_MD_ATTR = "data-agy-alt-md";
|
|
2645
|
+
function markdownTextOf(container) {
|
|
2646
|
+
const props = getReactProps(container);
|
|
2647
|
+
return typeof props?.text === "string" ? props.text : "";
|
|
2648
|
+
}
|
|
2649
|
+
function altFingerprint(text) {
|
|
2650
|
+
let h = 5381;
|
|
2651
|
+
for (let i = 0; i < text.length; i++) h = (h << 5) + h + text.charCodeAt(i) | 0;
|
|
2652
|
+
return `${text.length}:${h}`;
|
|
2653
|
+
}
|
|
2654
|
+
function refreshChangedAltContainers() {
|
|
2655
|
+
const tracked = document.querySelectorAll(`[${ALT_MD_ATTR}]`);
|
|
2656
|
+
for (let i = 0; i < tracked.length; i++) {
|
|
2657
|
+
const container = tracked[i];
|
|
2638
2658
|
if (!container) continue;
|
|
2639
|
-
const
|
|
2640
|
-
if (
|
|
2641
|
-
|
|
2642
|
-
const
|
|
2659
|
+
const next = altFingerprint(markdownTextOf(container));
|
|
2660
|
+
if (container.getAttribute(ALT_MD_ATTR) === next) continue;
|
|
2661
|
+
container.setAttribute(ALT_MD_ATTR, next);
|
|
2662
|
+
const spans = container.querySelectorAll("span[class*=\"imageAlt\"], span[class*=\"_imageAlt_\"]");
|
|
2663
|
+
for (let j = 0; j < spans.length; j++) {
|
|
2664
|
+
const span = spans[j];
|
|
2665
|
+
if (span && span.dataset.agyEnhanced !== "true") delete span.dataset.agyAltScanned;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
function enhanceAltSpans() {
|
|
2670
|
+
refreshChangedAltContainers();
|
|
2671
|
+
const unenhancedSpans = document.querySelectorAll("span[class*=\"imageAlt\"]:not([data-agy-alt-scanned]):not([data-agy-enhanced]), span[class*=\"_imageAlt_\"]:not([data-agy-alt-scanned]):not([data-agy-enhanced])");
|
|
2672
|
+
if (unenhancedSpans.length === 0) return;
|
|
2673
|
+
const seenContainers = /* @__PURE__ */ new Set();
|
|
2674
|
+
for (let i = 0; i < unenhancedSpans.length; i++) {
|
|
2675
|
+
const span = unenhancedSpans[i];
|
|
2676
|
+
if (!span) continue;
|
|
2677
|
+
const container = span.closest("div[class*=\"_markdown_\"], [data-markdown-variant]");
|
|
2678
|
+
if (container) seenContainers.add(container);
|
|
2679
|
+
else span.dataset.agyAltScanned = "true";
|
|
2680
|
+
}
|
|
2681
|
+
for (const container of seenContainers) {
|
|
2682
|
+
const allSpans = container.querySelectorAll("span[class*=\"imageAlt\"], span[class*=\"_imageAlt_\"]");
|
|
2683
|
+
if (allSpans.length === 0) continue;
|
|
2684
|
+
const mdText = markdownTextOf(container);
|
|
2685
|
+
container.setAttribute(ALT_MD_ATTR, altFingerprint(mdText));
|
|
2643
2686
|
if (!mdText) continue;
|
|
2644
2687
|
const imgMatches = [];
|
|
2645
2688
|
const re = /!\[(.*?)\]\((file:\/\/\/[^\s)]+|file:\/\/[^\s)]+|[A-Za-z]:[\\/][^\s)]+|\/home\/[^\s)]+|\/mnt\/[a-zA-Z]\/[^\s)]+|\\\\wsl\.localhost\\[^\s)]+)\)/g;
|
|
@@ -2648,10 +2691,17 @@ window.__ModuleLoader__.load({
|
|
|
2648
2691
|
alt: m[1] ?? "",
|
|
2649
2692
|
target: m[2] ?? ""
|
|
2650
2693
|
});
|
|
2651
|
-
if (imgMatches.length === 0)
|
|
2652
|
-
|
|
2653
|
-
|
|
2694
|
+
if (imgMatches.length === 0) {
|
|
2695
|
+
for (let j = 0; j < allSpans.length; j++) {
|
|
2696
|
+
const span = allSpans[j];
|
|
2697
|
+
if (span) span.dataset.agyAltScanned = "true";
|
|
2698
|
+
}
|
|
2699
|
+
continue;
|
|
2700
|
+
}
|
|
2701
|
+
for (let j = 0; j < allSpans.length; j++) {
|
|
2702
|
+
const span = allSpans[j];
|
|
2654
2703
|
if (!span || span.dataset.agyEnhanced === "true") continue;
|
|
2704
|
+
span.dataset.agyAltScanned = "true";
|
|
2655
2705
|
const altText = (span.textContent ?? "").trim();
|
|
2656
2706
|
const match = imgMatches.find((im) => im.alt.trim() === altText) ?? imgMatches[j];
|
|
2657
2707
|
if (!match) continue;
|
|
@@ -2688,109 +2738,100 @@ window.__ModuleLoader__.load({
|
|
|
2688
2738
|
}
|
|
2689
2739
|
}
|
|
2690
2740
|
}
|
|
2691
|
-
function
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
if (
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2741
|
+
function enhanceImageLink(link, rawHref, resolvedHref) {
|
|
2742
|
+
link.dataset.agyLinkEnhanced = "true";
|
|
2743
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2744
|
+
const mediaUrl = buildMediaUrl(pathToUse);
|
|
2745
|
+
const linkText = (link.textContent ?? "Image").replace(/预览$/, "").trim();
|
|
2746
|
+
link.addEventListener("click", (e) => {
|
|
2747
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2748
|
+
e.preventDefault();
|
|
2749
|
+
e.stopPropagation();
|
|
2750
|
+
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2751
|
+
});
|
|
2752
|
+
if (!link.querySelector(".agy-image-link-icon")) {
|
|
2753
|
+
const badge = document.createElement("span");
|
|
2754
|
+
badge.className = "agy-image-link-chip agy-image-link-icon";
|
|
2755
|
+
badge.setAttribute("role", "button");
|
|
2756
|
+
badge.setAttribute("tabindex", "0");
|
|
2757
|
+
badge.title = `预览图片 / Preview (${linkText})`;
|
|
2758
|
+
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"vertical-align:-1px;display:inline-block;\"><path d=\"M1 8s3-5.5 7-5.5S15 8 15 8s-3 5.5-7 5.5S1 8 1 8z\"/><circle cx=\"8\" cy=\"8\" r=\"2.5\"/></svg></span><span class=\"agy-image-chip-text\">预览</span>";
|
|
2759
|
+
badge.onclick = (e) => {
|
|
2704
2760
|
e.preventDefault();
|
|
2705
2761
|
e.stopPropagation();
|
|
2706
2762
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2707
|
-
}
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
badge.className = "agy-image-link-chip agy-image-link-icon";
|
|
2711
|
-
badge.setAttribute("role", "button");
|
|
2712
|
-
badge.setAttribute("tabindex", "0");
|
|
2713
|
-
badge.title = `预览图片 / Preview (${linkText})`;
|
|
2714
|
-
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" style=\"vertical-align:-1px;display:inline-block;\"><path d=\"M1 8s3-5.5 7-5.5S15 8 15 8s-3 5.5-7 5.5S1 8 1 8z\"/><circle cx=\"8\" cy=\"8\" r=\"2.5\"/></svg></span><span class=\"agy-image-chip-text\">预览</span>";
|
|
2715
|
-
badge.onclick = (e) => {
|
|
2763
|
+
};
|
|
2764
|
+
badge.onkeydown = (e) => {
|
|
2765
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2716
2766
|
e.preventDefault();
|
|
2717
2767
|
e.stopPropagation();
|
|
2718
2768
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2719
|
-
}
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
e.preventDefault();
|
|
2723
|
-
e.stopPropagation();
|
|
2724
|
-
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2725
|
-
}
|
|
2726
|
-
};
|
|
2727
|
-
link.appendChild(badge);
|
|
2728
|
-
}
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
link.appendChild(badge);
|
|
2729
2772
|
}
|
|
2730
2773
|
}
|
|
2731
|
-
function
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
if (
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2774
|
+
function enhanceVideoLink(link, rawHref, resolvedHref) {
|
|
2775
|
+
link.dataset.agyVideoEnhanced = "true";
|
|
2776
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2777
|
+
const mediaUrl = buildMediaUrl(pathToUse);
|
|
2778
|
+
const linkText = (link.textContent ?? "Video").replace(/播放$/, "").trim();
|
|
2779
|
+
link.addEventListener("click", (e) => {
|
|
2780
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2781
|
+
e.preventDefault();
|
|
2782
|
+
e.stopPropagation();
|
|
2783
|
+
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2784
|
+
});
|
|
2785
|
+
if (!link.querySelector(".agy-video-link-icon")) {
|
|
2786
|
+
const badge = document.createElement("span");
|
|
2787
|
+
badge.className = "agy-image-link-chip agy-chip-video agy-video-link-icon";
|
|
2788
|
+
badge.setAttribute("role", "button");
|
|
2789
|
+
badge.setAttribute("tabindex", "0");
|
|
2790
|
+
badge.title = `播放视频 / Play Video (${linkText})`;
|
|
2791
|
+
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"10\" height=\"10\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><polygon points=\"5 3 19 12 5 21 5 3\"></polygon></svg></span><span class=\"agy-image-chip-text\">播放</span>";
|
|
2792
|
+
badge.onclick = (e) => {
|
|
2744
2793
|
e.preventDefault();
|
|
2745
2794
|
e.stopPropagation();
|
|
2746
2795
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
badge.className = "agy-image-link-chip agy-chip-video agy-video-link-icon";
|
|
2751
|
-
badge.setAttribute("role", "button");
|
|
2752
|
-
badge.setAttribute("tabindex", "0");
|
|
2753
|
-
badge.title = `播放视频 / Play Video (${linkText})`;
|
|
2754
|
-
badge.innerHTML = "<span class=\"agy-image-chip-icon\"><svg width=\"10\" height=\"10\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><polygon points=\"5 3 19 12 5 21 5 3\"></polygon></svg></span><span class=\"agy-image-chip-text\">播放</span>";
|
|
2755
|
-
badge.onclick = (e) => {
|
|
2796
|
+
};
|
|
2797
|
+
badge.onkeydown = (e) => {
|
|
2798
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
2756
2799
|
e.preventDefault();
|
|
2757
2800
|
e.stopPropagation();
|
|
2758
2801
|
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
e.preventDefault();
|
|
2763
|
-
e.stopPropagation();
|
|
2764
|
-
openLightbox(mediaUrl, linkText, pathToUse);
|
|
2765
|
-
}
|
|
2766
|
-
};
|
|
2767
|
-
link.appendChild(badge);
|
|
2768
|
-
}
|
|
2802
|
+
}
|
|
2803
|
+
};
|
|
2804
|
+
link.appendChild(badge);
|
|
2769
2805
|
}
|
|
2770
2806
|
}
|
|
2771
|
-
function
|
|
2807
|
+
function enhanceFileLink(link, rawHref, resolvedHref) {
|
|
2808
|
+
link.dataset.agyFileEnhanced = "true";
|
|
2809
|
+
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2810
|
+
link.addEventListener("click", (e) => {
|
|
2811
|
+
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2812
|
+
e.preventDefault();
|
|
2813
|
+
e.stopPropagation();
|
|
2814
|
+
const fileName = pathToUse.split(/[/\\]/).pop() || pathToUse;
|
|
2815
|
+
if (openInRightSidebar(pathToUse)) {
|
|
2816
|
+
showToast(`已在原生边栏打开: ${fileName}`);
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2819
|
+
openInSystem(pathToUse, false).then((res) => {
|
|
2820
|
+
showToast(res.ok ? `已在系统程序中打开: ${fileName}` : `打开失败: ${res.error || "未找到文件"}`);
|
|
2821
|
+
});
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
function enhanceLinks() {
|
|
2825
|
+
const links = document.querySelectorAll("a[href]:not([data-agy-link-scanned]):not([data-agy-link-enhanced]):not([data-agy-video-enhanced]):not([data-agy-file-enhanced])");
|
|
2772
2826
|
for (let i = 0; i < links.length; i++) {
|
|
2773
2827
|
const link = links[i];
|
|
2774
|
-
if (!link
|
|
2828
|
+
if (!link) continue;
|
|
2829
|
+
link.dataset.agyLinkScanned = "true";
|
|
2775
2830
|
const rawHref = link.getAttribute("href") ?? "";
|
|
2776
2831
|
const resolvedHref = link.href ?? "";
|
|
2777
|
-
if (isImageFile(rawHref) || isImageFile(resolvedHref)
|
|
2778
|
-
if (
|
|
2779
|
-
|
|
2780
|
-
const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
|
|
2781
|
-
link.addEventListener("click", (e) => {
|
|
2782
|
-
if (e.target?.closest?.(".agy-image-link-chip")) return;
|
|
2783
|
-
e.preventDefault();
|
|
2784
|
-
e.stopPropagation();
|
|
2785
|
-
const fileName = pathToUse.split(/[/\\]/).pop() || pathToUse;
|
|
2786
|
-
if (openInRightSidebar(pathToUse)) {
|
|
2787
|
-
showToast(`已在原生边栏打开: ${fileName}`);
|
|
2788
|
-
return;
|
|
2789
|
-
}
|
|
2790
|
-
openInSystem(pathToUse, false).then((res) => {
|
|
2791
|
-
showToast(res.ok ? `已在系统程序中打开: ${fileName}` : `打开失败: ${res.error || "未找到文件"}`);
|
|
2792
|
-
});
|
|
2793
|
-
});
|
|
2832
|
+
if (isImageFile(rawHref) || isImageFile(resolvedHref)) enhanceImageLink(link, rawHref, resolvedHref);
|
|
2833
|
+
else if (isVideoFile(rawHref) || isVideoFile(resolvedHref)) enhanceVideoLink(link, rawHref, resolvedHref);
|
|
2834
|
+
else if (rawHref.startsWith("file://") || resolvedHref.startsWith("file://") || isLocalFilePath(rawHref)) enhanceFileLink(link, rawHref, resolvedHref);
|
|
2794
2835
|
}
|
|
2795
2836
|
}
|
|
2796
2837
|
/**
|
|
@@ -2801,10 +2842,7 @@ window.__ModuleLoader__.load({
|
|
|
2801
2842
|
if (isInteractionLocked()) return;
|
|
2802
2843
|
rewriteMediaOrigins(getOrigin());
|
|
2803
2844
|
enhanceAltSpans();
|
|
2804
|
-
|
|
2805
|
-
enhanceImageLinks(links);
|
|
2806
|
-
enhanceVideoLinks(links);
|
|
2807
|
-
enhanceFileLinks(links);
|
|
2845
|
+
enhanceLinks();
|
|
2808
2846
|
}
|
|
2809
2847
|
let imageEnhancerDispose = null;
|
|
2810
2848
|
let imageScanTimer = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agy-link",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.25",
|
|
4
4
|
"description": "Google Antigravity (agy CLI) models for DeepSeek Harness — stream Gemini/Claude/GPT-OSS subscriptions into DSH with thinking, tool activity, token usage and in-GUI Google OAuth login.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|