@d0nj/dsh-narration 0.2.0 → 0.3.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/LICENSE +24 -0
- package/package.json +10 -10
- package/dist/client/rail.d.ts +0 -20
- package/dist/client/rail.js +0 -182
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 d0nj
|
|
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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
20
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
21
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
22
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
23
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
24
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0nj/dsh-narration",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Always-on live narration for the DeepSeek Harness Web UI: streaming reasoning, preparing tool calls and a frame-paced activity rail instead of collapsed blocks and blank spinners.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,14 +39,6 @@
|
|
|
39
39
|
"icon.svg",
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsc -p tsconfig.build.json && node scripts/stamp-client.mjs",
|
|
44
|
-
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|
|
45
|
-
"pretest": "tsc -p tsconfig.test.json",
|
|
46
|
-
"test": "node --test \"dist-test/**/*.test.js\"",
|
|
47
|
-
"check": "node --check dist/index.js && node --check dist/client/client.js && node --check dist/pacing.js && node --check dist/live.js && node --check dist/diff.js && node --check dist/ansi.js && node --check dist/envelope.js && node --check dist/narration.js",
|
|
48
|
-
"clean": "node -e \"const fs=require('node:fs');for(const d of ['dist','dist-test'])fs.rmSync(d,{recursive:true,force:true})\""
|
|
49
|
-
},
|
|
50
42
|
"dsh": {
|
|
51
43
|
"bundle": {
|
|
52
44
|
"patch": "./cordis.patch.yml"
|
|
@@ -68,5 +60,13 @@
|
|
|
68
60
|
"@deepseek-ai/schemastery": "~3.19.0",
|
|
69
61
|
"@types/node": "^24.0.0",
|
|
70
62
|
"typescript": "^5.9.0"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsc -p tsconfig.build.json && node scripts/stamp-client.mjs",
|
|
66
|
+
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|
|
67
|
+
"pretest": "tsc -p tsconfig.test.json",
|
|
68
|
+
"test": "node --test \"dist-test/**/*.test.js\"",
|
|
69
|
+
"check": "node --check dist/index.js && node --check dist/client/client.js && node --check dist/pacing.js && node --check dist/live.js && node --check dist/diff.js && node --check dist/ansi.js && node --check dist/envelope.js && node --check dist/narration.js",
|
|
70
|
+
"clean": "node -e \"const fs=require('node:fs');for(const d of ['dist','dist-test'])fs.rmSync(d,{recursive:true,force:true})\""
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
}
|
package/dist/client/rail.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { LiveCall } from '../live.js';
|
|
2
|
-
export interface ReactApi {
|
|
3
|
-
createElement(type: unknown, props?: Record<string, unknown> | null, ...children: unknown[]): unknown;
|
|
4
|
-
useState<T>(initial: T | (() => T)): [T, (next: T | ((prev: T) => T)) => void];
|
|
5
|
-
useEffect(effect: () => void | (() => void), deps?: readonly unknown[]): void;
|
|
6
|
-
useRef<T>(initial: T): {
|
|
7
|
-
current: T;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
type Selector = (snapshot: unknown) => unknown;
|
|
11
|
-
export interface RailProps {
|
|
12
|
-
readonly sessionId?: string | undefined;
|
|
13
|
-
readonly useSession?: ((select: Selector) => unknown) | undefined;
|
|
14
|
-
readonly useSessionStatus?: ((select: Selector) => unknown) | undefined;
|
|
15
|
-
readonly useChat?: ((select: Selector) => unknown) | undefined;
|
|
16
|
-
}
|
|
17
|
-
export declare function toLiveCalls(raw: unknown): LiveCall[];
|
|
18
|
-
export declare function createNarrationRail(React: ReactApi): (props: RailProps) => unknown;
|
|
19
|
-
export {};
|
|
20
|
-
//# sourceMappingURL=rail.d.ts.map
|
package/dist/client/rail.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { PacedText, RateMeter } from '../pacing.js';
|
|
2
|
-
import { formatElapsed, formatRate, narrateCall, phaseLabel, summarize, } from '../live.js';
|
|
3
|
-
import { PHASE_COLOUR } from './style.js';
|
|
4
|
-
const NO_SELECT = () => undefined;
|
|
5
|
-
const MISSING_ARGS = { text: () => undefined };
|
|
6
|
-
function legacyOf(snapshot) {
|
|
7
|
-
if (snapshot === null || typeof snapshot !== 'object')
|
|
8
|
-
return undefined;
|
|
9
|
-
const legacy = snapshot.legacy;
|
|
10
|
-
return legacy !== null && typeof legacy === 'object' ? legacy : undefined;
|
|
11
|
-
}
|
|
12
|
-
function sessionRunning(snapshot) {
|
|
13
|
-
return snapshot !== null && typeof snapshot === 'object' && snapshot.running === true;
|
|
14
|
-
}
|
|
15
|
-
function statusRunning(statuses, sessionId) {
|
|
16
|
-
if (sessionId.length === 0 || statuses === null || typeof statuses !== 'object')
|
|
17
|
-
return false;
|
|
18
|
-
const read = statuses.get;
|
|
19
|
-
if (typeof read !== 'function')
|
|
20
|
-
return false;
|
|
21
|
-
const status = read.call(statuses, sessionId);
|
|
22
|
-
return status !== null && typeof status === 'object' && status.running === true;
|
|
23
|
-
}
|
|
24
|
-
export function toLiveCalls(raw) {
|
|
25
|
-
if (!Array.isArray(raw))
|
|
26
|
-
return [];
|
|
27
|
-
const calls = [];
|
|
28
|
-
for (const entry of raw) {
|
|
29
|
-
if (entry === null || typeof entry !== 'object')
|
|
30
|
-
continue;
|
|
31
|
-
const record = entry;
|
|
32
|
-
if (typeof record.callId !== 'string' || typeof record.name !== 'string')
|
|
33
|
-
continue;
|
|
34
|
-
const source = record.args;
|
|
35
|
-
const usable = source !== null && typeof source === 'object' && typeof source.text === 'function';
|
|
36
|
-
calls.push({
|
|
37
|
-
callId: record.callId,
|
|
38
|
-
name: record.name,
|
|
39
|
-
phase: record.phase === 'start' ? 'start' : 'preparing',
|
|
40
|
-
time: typeof record.time === 'number' ? record.time : 0,
|
|
41
|
-
args: usable ? source : MISSING_ARGS,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return calls;
|
|
45
|
-
}
|
|
46
|
-
function joinedBlocks(partial, kind) {
|
|
47
|
-
if (partial === null || typeof partial !== 'object')
|
|
48
|
-
return '';
|
|
49
|
-
const blocks = partial.blocks;
|
|
50
|
-
if (!Array.isArray(blocks))
|
|
51
|
-
return '';
|
|
52
|
-
let text = '';
|
|
53
|
-
for (const block of blocks) {
|
|
54
|
-
if (block === null || typeof block !== 'object')
|
|
55
|
-
continue;
|
|
56
|
-
const entry = block;
|
|
57
|
-
if (entry.kind !== kind || typeof entry.text !== 'string')
|
|
58
|
-
continue;
|
|
59
|
-
text += entry.text;
|
|
60
|
-
}
|
|
61
|
-
return text;
|
|
62
|
-
}
|
|
63
|
-
function usePacedText(React, target, animating) {
|
|
64
|
-
const [shown, setShown] = React.useState(target);
|
|
65
|
-
const stream = React.useRef({ seen: target, queue: new PacedText() });
|
|
66
|
-
React.useEffect(() => {
|
|
67
|
-
const state = stream.current;
|
|
68
|
-
const previouslySeen = state.seen;
|
|
69
|
-
state.seen = target;
|
|
70
|
-
if (!target.startsWith(previouslySeen)) {
|
|
71
|
-
state.queue.reset();
|
|
72
|
-
setShown(target);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const delta = target.slice(previouslySeen.length);
|
|
76
|
-
if (delta.length === 0)
|
|
77
|
-
return;
|
|
78
|
-
if (!animating) {
|
|
79
|
-
state.queue.reset();
|
|
80
|
-
setShown(target);
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
state.queue.push(delta);
|
|
84
|
-
let frame = 0;
|
|
85
|
-
const step = () => {
|
|
86
|
-
const chunk = state.queue.take();
|
|
87
|
-
if (chunk.length > 0)
|
|
88
|
-
setShown((previous) => previous + chunk);
|
|
89
|
-
frame = state.queue.pending > 0 ? requestAnimationFrame(step) : 0;
|
|
90
|
-
};
|
|
91
|
-
frame = requestAnimationFrame(step);
|
|
92
|
-
return () => {
|
|
93
|
-
if (frame !== 0)
|
|
94
|
-
cancelAnimationFrame(frame);
|
|
95
|
-
};
|
|
96
|
-
}, [target, animating]);
|
|
97
|
-
return shown;
|
|
98
|
-
}
|
|
99
|
-
function useClock(React, running, meter, charsOf) {
|
|
100
|
-
const [now, setNow] = React.useState(() => Date.now());
|
|
101
|
-
const [rate, setRate] = React.useState(0);
|
|
102
|
-
React.useEffect(() => {
|
|
103
|
-
if (!running) {
|
|
104
|
-
meter.current.reset();
|
|
105
|
-
setRate(0);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
const tick = setInterval(() => {
|
|
109
|
-
const at = Date.now();
|
|
110
|
-
setNow(at);
|
|
111
|
-
setRate(meter.current.sample(at, charsOf()));
|
|
112
|
-
}, 100);
|
|
113
|
-
return () => clearInterval(tick);
|
|
114
|
-
}, [running]);
|
|
115
|
-
return { now, rate };
|
|
116
|
-
}
|
|
117
|
-
function callRow(React, call, now) {
|
|
118
|
-
const narration = narrateCall(call, 220);
|
|
119
|
-
const spent = call.time > 0 ? formatElapsed(Math.max(0, now - call.time)) : '';
|
|
120
|
-
return React.createElement('div', { key: call.callId, className: 'd0nj-nar-call', 'data-preparing': String(narration.preparing) }, React.createElement('span', { className: 'd0nj-nar-verb' }, narration.verb), React.createElement('span', { className: 'd0nj-nar-arg' }, narration.argument, React.createElement('span', { className: 'd0nj-nar-caret' })), spent.length > 0 ? React.createElement('span', { className: 'd0nj-nar-spent' }, spent) : null);
|
|
121
|
-
}
|
|
122
|
-
export function createNarrationRail(React) {
|
|
123
|
-
const h = React.createElement;
|
|
124
|
-
return function NarrationRail(props) {
|
|
125
|
-
const useChat = props.useChat ?? NO_SELECT;
|
|
126
|
-
const useSession = props.useSession ?? NO_SELECT;
|
|
127
|
-
const useSessionStatus = props.useSessionStatus ?? NO_SELECT;
|
|
128
|
-
const sessionId = props.sessionId ?? '';
|
|
129
|
-
const rawCalls = useChat((snapshot) => legacyOf(snapshot)?.runningCalls);
|
|
130
|
-
const rawPartial = useChat((snapshot) => legacyOf(snapshot)?.partial);
|
|
131
|
-
const runningFromSession = useSession(sessionRunning) === true;
|
|
132
|
-
const runningFromStatus = useSessionStatus((statuses) => statusRunning(statuses, sessionId)) === true;
|
|
133
|
-
const running = runningFromSession || runningFromStatus;
|
|
134
|
-
const calls = toLiveCalls(rawCalls);
|
|
135
|
-
const reasoningTarget = joinedBlocks(rawPartial, 'reasoning');
|
|
136
|
-
const answer = joinedBlocks(rawPartial, 'text');
|
|
137
|
-
const reasoning = usePacedText(React, reasoningTarget, running);
|
|
138
|
-
const start = React.useRef(0);
|
|
139
|
-
React.useEffect(() => {
|
|
140
|
-
start.current = running ? Date.now() : 0;
|
|
141
|
-
}, [running]);
|
|
142
|
-
const meter = React.useRef(new RateMeter());
|
|
143
|
-
const charsRef = React.useRef(0);
|
|
144
|
-
charsRef.current = reasoningTarget.length + answer.length;
|
|
145
|
-
const { now, rate } = useClock(React, running, meter, () => charsRef.current);
|
|
146
|
-
const [open, setOpen] = React.useState(false);
|
|
147
|
-
const pinned = React.useRef(true);
|
|
148
|
-
const summary = summarize({ calls, reasoning, answer, running, limit: 140 });
|
|
149
|
-
const phase = summary.phase;
|
|
150
|
-
const working = running || calls.length > 0;
|
|
151
|
-
if (!working && reasoning.length === 0 && answer.length === 0)
|
|
152
|
-
return null;
|
|
153
|
-
const elapsed = start.current === 0 ? 0 : Math.max(0, now - start.current);
|
|
154
|
-
const reasoningBlock = open && reasoning.length > 0
|
|
155
|
-
? h('pre', {
|
|
156
|
-
className: 'd0nj-nar-reason',
|
|
157
|
-
onScroll: (event) => {
|
|
158
|
-
const node = event.currentTarget;
|
|
159
|
-
pinned.current = node.scrollHeight - node.scrollTop - node.clientHeight < 12;
|
|
160
|
-
},
|
|
161
|
-
ref: (node) => {
|
|
162
|
-
if (node !== null && pinned.current)
|
|
163
|
-
node.scrollTop = node.scrollHeight;
|
|
164
|
-
},
|
|
165
|
-
}, reasoning)
|
|
166
|
-
: null;
|
|
167
|
-
const rows = calls.length > 0
|
|
168
|
-
? h('div', { className: 'd0nj-nar-calls' }, calls.map((call) => callRow(React, call, now)))
|
|
169
|
-
: null;
|
|
170
|
-
const body = reasoningBlock === null && rows === null
|
|
171
|
-
? null
|
|
172
|
-
: h('div', { className: 'd0nj-nar-body' }, reasoningBlock, rows);
|
|
173
|
-
return h('div', { className: working ? 'd0nj-nar d0nj-nar-working' : 'd0nj-nar' }, h('button', {
|
|
174
|
-
type: 'button',
|
|
175
|
-
className: 'd0nj-nar-head',
|
|
176
|
-
'aria-expanded': open,
|
|
177
|
-
onClick: () => setOpen((previous) => !previous),
|
|
178
|
-
style: { '--d0nj-nar-phase': PHASE_COLOUR[phase] ?? PHASE_COLOUR.idle },
|
|
179
|
-
}, h('span', { className: 'd0nj-nar-dot' }), h('span', { className: 'd0nj-nar-phase' }, phaseLabel(phase)), h('span', { className: 'd0nj-nar-lead' }, summary.lead), h('span', { className: 'd0nj-nar-metrics' }, h('span', null, formatElapsed(elapsed)), working ? h('span', null, formatRate(rate)) : null)), body);
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
//# sourceMappingURL=rail.js.map
|