@xynogen/pix-runtime 0.1.2 → 0.2.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/package.json +1 -1
- package/src/collapse.ts +31 -0
package/package.json
CHANGED
package/src/collapse.ts
CHANGED
|
@@ -18,3 +18,34 @@ export function shouldCollapse(toolName: string): boolean {
|
|
|
18
18
|
export function collapseDelayMs(): number {
|
|
19
19
|
return pixRuntime().get(collapseSection).delaySec * 1000;
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
/** Per-card render state bag for the collapse timer. */
|
|
23
|
+
export interface CollapseState {
|
|
24
|
+
collapsed?: boolean;
|
|
25
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Run the collapse timer for a tool card. Call this inside `renderResult`.
|
|
30
|
+
*
|
|
31
|
+
* @param toolName — the tool name (e.g. "bash", "read") for per-tool config
|
|
32
|
+
* @param state — the render context's `state` bag (mutable, per-card)
|
|
33
|
+
* @param invalidate — `context.invalidate()` to trigger re-render
|
|
34
|
+
* @param expanded — whether the host currently requests the detailed view
|
|
35
|
+
* @returns `true` if the card is currently collapsed and not expanded
|
|
36
|
+
*/
|
|
37
|
+
export function tickCollapse(
|
|
38
|
+
toolName: string,
|
|
39
|
+
state: CollapseState,
|
|
40
|
+
invalidate: () => void,
|
|
41
|
+
expanded = false,
|
|
42
|
+
): boolean {
|
|
43
|
+
if (!shouldCollapse(toolName)) return false;
|
|
44
|
+
if (!state.timer && !state.collapsed) {
|
|
45
|
+
state.timer = setTimeout(() => {
|
|
46
|
+
state.collapsed = true;
|
|
47
|
+
invalidate();
|
|
48
|
+
}, collapseDelayMs());
|
|
49
|
+
}
|
|
50
|
+
return state.collapsed === true && !expanded;
|
|
51
|
+
}
|