@huaqiu/dsh-tool-uncollapse 0.3.6
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/LICENSE +21 -0
- package/lib/index.d.mts +32 -0
- package/lib/index.mjs +34 -0
- package/package.json +30 -0
- package/src/index.ts +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 深圳华秋智联股份有限公司
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `@huaqiu/dsh-tool-uncollapse` — keep a plugin's tool-call preview card
|
|
4
|
+
* visible in DSH's compact transcript, without patching DSH.
|
|
5
|
+
*
|
|
6
|
+
* DSH collapses `tool-call` nodes behind a "N tool calls" disclosure by setting
|
|
7
|
+
* `hidden="until-found"` on the chat-node wrapper once the turn closes (see
|
|
8
|
+
* `ui-chat`'s `ChatNodeSeat` + `useSearchableHidden`). That hides the entire
|
|
9
|
+
* card (preview included). A plugin cannot prevent it from inside the card and
|
|
10
|
+
* must not patch DSH, so we undo it from the plugin's client half: for every
|
|
11
|
+
* collapsed seat that wraps the plugin's card, remove the `hidden` attribute.
|
|
12
|
+
* A rAF-coalesced MutationObserver reasserts this whenever DSH's virtualized
|
|
13
|
+
* renderer re-adds it.
|
|
14
|
+
*
|
|
15
|
+
* Scoped to the plugin's cards only — other tools keep collapsing. Returns a
|
|
16
|
+
* disposer (or a no-op when there is no DOM, e.g. SSR/tests).
|
|
17
|
+
*
|
|
18
|
+
* @param cardRootSelector - CSS selector matching the plugin card's root
|
|
19
|
+
* element, e.g. `.hq-genhit` (symbol/footprint) or `.hq-sch` (schematic).
|
|
20
|
+
* @param options.skipWhenContains - when a collapsed seat ALSO contains this
|
|
21
|
+
* selector, leave it collapsed and follow DSH's default behaviour. Use this
|
|
22
|
+
* for transient sub-states that should not be pinned open — e.g. the inline
|
|
23
|
+
* login card (`.hq-genhit__login` / `.hq-sch__login`), so the login HIT
|
|
24
|
+
* collapses automatically while the finished preview stays visible.
|
|
25
|
+
* @returns cleanup function; safe to call repeatedly.
|
|
26
|
+
*/
|
|
27
|
+
interface KeepToolCardVisibleOptions {
|
|
28
|
+
skipWhenContains?: string;
|
|
29
|
+
}
|
|
30
|
+
declare function keepToolCardVisible(cardRootSelector: string, options?: KeepToolCardVisibleOptions): () => void;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { KeepToolCardVisibleOptions, keepToolCardVisible };
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
function keepToolCardVisible(cardRootSelector, options) {
|
|
3
|
+
if (typeof document === "undefined" || typeof MutationObserver === "undefined") return () => {};
|
|
4
|
+
const skipSelector = options?.skipWhenContains;
|
|
5
|
+
const root = document.documentElement;
|
|
6
|
+
const revealSeat = (seat) => {
|
|
7
|
+
if (!seat.querySelector(cardRootSelector)) return;
|
|
8
|
+
if (skipSelector && seat.querySelector(skipSelector)) return;
|
|
9
|
+
seat.removeAttribute("hidden");
|
|
10
|
+
};
|
|
11
|
+
let scheduled = false;
|
|
12
|
+
const sweep = () => {
|
|
13
|
+
scheduled = false;
|
|
14
|
+
for (const seat of root.querySelectorAll("[data-turn-process-hidden]")) revealSeat(seat);
|
|
15
|
+
};
|
|
16
|
+
const observer = new MutationObserver(() => {
|
|
17
|
+
if (scheduled) return;
|
|
18
|
+
scheduled = true;
|
|
19
|
+
requestAnimationFrame(sweep);
|
|
20
|
+
});
|
|
21
|
+
observer.observe(root, {
|
|
22
|
+
subtree: true,
|
|
23
|
+
childList: true,
|
|
24
|
+
attributes: true,
|
|
25
|
+
attributeFilter: ["hidden", "data-turn-process-hidden"]
|
|
26
|
+
});
|
|
27
|
+
sweep();
|
|
28
|
+
return () => {
|
|
29
|
+
observer.disconnect();
|
|
30
|
+
scheduled = false;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { keepToolCardVisible };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@huaqiu/dsh-tool-uncollapse",
|
|
3
|
+
"version": "0.3.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./lib/index.mjs",
|
|
6
|
+
"types": "./lib/index.d.mts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./lib/index.d.mts",
|
|
10
|
+
"default": "./lib/index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"lib",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsdown": "^0.22.14",
|
|
23
|
+
"typescript": "^5.9.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"test": "vitest run"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@huaqiu/dsh-tool-uncollapse` — keep a plugin's tool-call preview card
|
|
3
|
+
* visible in DSH's compact transcript, without patching DSH.
|
|
4
|
+
*
|
|
5
|
+
* DSH collapses `tool-call` nodes behind a "N tool calls" disclosure by setting
|
|
6
|
+
* `hidden="until-found"` on the chat-node wrapper once the turn closes (see
|
|
7
|
+
* `ui-chat`'s `ChatNodeSeat` + `useSearchableHidden`). That hides the entire
|
|
8
|
+
* card (preview included). A plugin cannot prevent it from inside the card and
|
|
9
|
+
* must not patch DSH, so we undo it from the plugin's client half: for every
|
|
10
|
+
* collapsed seat that wraps the plugin's card, remove the `hidden` attribute.
|
|
11
|
+
* A rAF-coalesced MutationObserver reasserts this whenever DSH's virtualized
|
|
12
|
+
* renderer re-adds it.
|
|
13
|
+
*
|
|
14
|
+
* Scoped to the plugin's cards only — other tools keep collapsing. Returns a
|
|
15
|
+
* disposer (or a no-op when there is no DOM, e.g. SSR/tests).
|
|
16
|
+
*
|
|
17
|
+
* @param cardRootSelector - CSS selector matching the plugin card's root
|
|
18
|
+
* element, e.g. `.hq-genhit` (symbol/footprint) or `.hq-sch` (schematic).
|
|
19
|
+
* @param options.skipWhenContains - when a collapsed seat ALSO contains this
|
|
20
|
+
* selector, leave it collapsed and follow DSH's default behaviour. Use this
|
|
21
|
+
* for transient sub-states that should not be pinned open — e.g. the inline
|
|
22
|
+
* login card (`.hq-genhit__login` / `.hq-sch__login`), so the login HIT
|
|
23
|
+
* collapses automatically while the finished preview stays visible.
|
|
24
|
+
* @returns cleanup function; safe to call repeatedly.
|
|
25
|
+
*/
|
|
26
|
+
export interface KeepToolCardVisibleOptions {
|
|
27
|
+
skipWhenContains?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function keepToolCardVisible(
|
|
31
|
+
cardRootSelector: string,
|
|
32
|
+
options?: KeepToolCardVisibleOptions,
|
|
33
|
+
): () => void {
|
|
34
|
+
if (typeof document === 'undefined' || typeof MutationObserver === 'undefined') {
|
|
35
|
+
return () => {}
|
|
36
|
+
}
|
|
37
|
+
const skipSelector = options?.skipWhenContains
|
|
38
|
+
const root = document.documentElement
|
|
39
|
+
const revealSeat = (seat: HTMLElement): void => {
|
|
40
|
+
if (!seat.querySelector(cardRootSelector)) return
|
|
41
|
+
// Leave transient sub-states (e.g. the login HIT) collapsed by default.
|
|
42
|
+
if (skipSelector && seat.querySelector(skipSelector)) return
|
|
43
|
+
seat.removeAttribute('hidden')
|
|
44
|
+
}
|
|
45
|
+
let scheduled = false
|
|
46
|
+
const sweep = (): void => {
|
|
47
|
+
scheduled = false
|
|
48
|
+
for (const seat of root.querySelectorAll<HTMLElement>('[data-turn-process-hidden]')) {
|
|
49
|
+
revealSeat(seat)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const observer = new MutationObserver(() => {
|
|
53
|
+
if (scheduled) return
|
|
54
|
+
scheduled = true
|
|
55
|
+
requestAnimationFrame(sweep)
|
|
56
|
+
})
|
|
57
|
+
observer.observe(root, {
|
|
58
|
+
subtree: true,
|
|
59
|
+
childList: true,
|
|
60
|
+
attributes: true,
|
|
61
|
+
attributeFilter: ['hidden', 'data-turn-process-hidden'],
|
|
62
|
+
})
|
|
63
|
+
sweep()
|
|
64
|
+
return () => {
|
|
65
|
+
observer.disconnect()
|
|
66
|
+
scheduled = false
|
|
67
|
+
}
|
|
68
|
+
}
|