dsh-agy-link 0.6.23 → 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 CHANGED
@@ -1,5 +1,27 @@
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 `![...](file:///...)` 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 先于 `![...](file:///...)` 链接出现(流式分块),就会永久跳过。现为每个容器保存短文本指纹,指纹变化时清除标记并重试;快速路径仍只是一次属性查询。新增两段式流式回归测试。
14
+
15
+ ## 0.6.24 (2026-11-14)
16
+
17
+ ### English
18
+
19
+ - **Fix(client): toggling `poolWideCatalog` now refreshes the model picker immediately (fixes #108, #109).** `/config` only emitted `llm/adapters-updated` for `hiddenModels`, so switching the just-shipped pool-wide catalog flag changed the setting and `/status` but left DSH's cached model selector showing the old account's models until a restart. Both keys that change the visible model set now announce a picker update; the HTTP-contract test pins the event count. Note for multi-account Windows users: `agy models` discovery still reads the machine-wide credential slot, so if a secondary account's probe returns only the primary account's basic models, the union cannot invent Argon/Hydrogen — that is an upstream credential-isolation limitation, not a filter in this plugin.
20
+
21
+ ### 中文
22
+
23
+ - **修复(客户端):切换「号池全量模型并集」后立即刷新模型选择器(修复 #108、#109)。** `/config` 此前只对 `hiddenModels` 广播 `llm/adapters-updated`,导致刚上线的 `poolWideCatalog` 开关虽然写入了配置、状态也变了,DSH 缓存的模型列表却仍是旧账号的,必须重启才生效——表现为「开关没作用」。现两个会改变可见模型集合的配置键都会触发选择器刷新,HTTP 契约测试锁定事件次数。另说明:Windows 多账号下 `agy models` 探测仍读取机器级凭据槽,若备用账号的探测被系统凭据劫持、只返回主账号的基础模型,并集也不会凭空补出 Argon/Hydrogen;这属于上游凭据隔离限制,不是本插件的过滤逻辑。
24
+
3
25
  ## 0.6.23 (2026-11-14)
4
26
 
5
27
  ### 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 && img.src.includes("127.0.0.1")) {
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
- function enhanceAltSpans() {
2635
- const markdownContainers = document.querySelectorAll("div[class*=\"_markdown_\"], [data-markdown-variant]");
2636
- for (let i = 0; i < markdownContainers.length; i++) {
2637
- const container = markdownContainers[i];
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 altSpans = container.querySelectorAll("span[class*=\"imageAlt\"], span[class*=\"_imageAlt_\"]");
2640
- if (altSpans.length === 0) continue;
2641
- const props = getReactProps(container);
2642
- const mdText = typeof props?.text === "string" ? props.text : "";
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) continue;
2652
- for (let j = 0; j < altSpans.length; j++) {
2653
- const span = altSpans[j];
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 enhanceImageLinks(links) {
2692
- for (let i = 0; i < links.length; i++) {
2693
- const link = links[i];
2694
- if (!link || link.dataset.agyLinkEnhanced === "true") continue;
2695
- const rawHref = link.getAttribute("href") ?? "";
2696
- const resolvedHref = link.href ?? "";
2697
- if (!isImageFile(rawHref) && !isImageFile(resolvedHref)) continue;
2698
- link.dataset.agyLinkEnhanced = "true";
2699
- const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
2700
- const mediaUrl = buildMediaUrl(pathToUse);
2701
- const linkText = (link.textContent ?? "Image").replace(/预览$/, "").trim();
2702
- link.addEventListener("click", (e) => {
2703
- if (e.target?.closest?.(".agy-image-link-chip")) return;
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
- if (!link.querySelector(".agy-image-link-icon")) {
2709
- const badge = document.createElement("span");
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
- badge.onkeydown = (e) => {
2721
- if (e.key === "Enter" || e.key === " ") {
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 enhanceVideoLinks(links) {
2732
- for (let i = 0; i < links.length; i++) {
2733
- const link = links[i];
2734
- if (!link || link.dataset.agyVideoEnhanced === "true") continue;
2735
- const rawHref = link.getAttribute("href") ?? "";
2736
- const resolvedHref = link.href ?? "";
2737
- if (!isVideoFile(rawHref) && !isVideoFile(resolvedHref)) continue;
2738
- link.dataset.agyVideoEnhanced = "true";
2739
- const pathToUse = rawHref.startsWith("file://") ? rawHref : resolvedHref.startsWith("file://") ? resolvedHref : rawHref || resolvedHref;
2740
- const mediaUrl = buildMediaUrl(pathToUse);
2741
- const linkText = (link.textContent ?? "Video").replace(/播放$/, "").trim();
2742
- link.addEventListener("click", (e) => {
2743
- if (e.target?.closest?.(".agy-image-link-chip")) return;
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
- if (!link.querySelector(".agy-video-link-icon")) {
2749
- const badge = document.createElement("span");
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
- badge.onkeydown = (e) => {
2761
- if (e.key === "Enter" || e.key === " ") {
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 enhanceFileLinks(links) {
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 || link.dataset.agyFileEnhanced === "true" || link.dataset.agyLinkEnhanced === "true" || link.dataset.agyVideoEnhanced === "true") continue;
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) || isVideoFile(rawHref) || isVideoFile(resolvedHref)) continue;
2778
- if (!rawHref.startsWith("file://") && !resolvedHref.startsWith("file://") && !isLocalFilePath(rawHref)) continue;
2779
- link.dataset.agyFileEnhanced = "true";
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
- const links = document.querySelectorAll("a[href]");
2805
- enhanceImageLinks(links);
2806
- enhanceVideoLinks(links);
2807
- enhanceFileLinks(links);
2845
+ enhanceLinks();
2808
2846
  }
2809
2847
  let imageEnhancerDispose = null;
2810
2848
  let imageScanTimer = null;
package/dist/index.js CHANGED
@@ -40697,7 +40697,7 @@ function handleConfig(services, req, res) {
40697
40697
  }
40698
40698
  setOverride(key, body.value);
40699
40699
  onConfigWritten(key, body.value);
40700
- if (key === "hiddenModels") notifyPicker();
40700
+ if (key === "hiddenModels" || key === "poolWideCatalog") notifyPicker();
40701
40701
  sendJson(res, 200, {
40702
40702
  ok: true,
40703
40703
  key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agy-link",
3
- "version": "0.6.23",
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",