@lemonriver/core 0.4.0 → 0.6.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/README.md +14 -4
- package/dist/{build-Nl7EeJ6x.js → build-RlcGG-Ve.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-CpC0nM3r.js → config-BJT87wE9.js} +4756 -2012
- package/dist/{dev-BB3THd5I.js → dev-DR-j_xda.js} +2 -2
- package/dist/{preview-BGjgTg7H.js → preview-BTAhTb5B.js} +1 -1
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +17 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +209 -0
- package/src/app/lemonriver/board/blocks/classify.ts +152 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +116 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1702 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +223 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
- package/src/app/lemonriver/board/model/self-check.ts +489 -0
- package/src/app/lemonriver/board/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +258 -55
- package/src/app/lemonriver/board/self-check-jump.ts +23 -0
- package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
- package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
- package/src/app/lemonriver/board/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-self-check.ts +117 -0
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
- package/src/app/lemonriver/features.test.ts +5 -0
- package/src/app/lemonriver/features.ts +2 -1
- package/src/app/lemonriver/home/deck-card.tsx +10 -0
- package/src/app/lemonriver/home/home-page.tsx +55 -6
- package/src/app/lemonriver/home/use-deck-times.ts +4 -1
- package/src/app/lemonriver/outline/build-team.tsx +42 -0
- package/src/app/lemonriver/outline/describe-page.tsx +128 -27
- package/src/app/lemonriver/outline/draft.ts +38 -0
- package/src/app/lemonriver/outline/model.test.ts +118 -0
- package/src/app/lemonriver/outline/model.ts +92 -7
- package/src/app/lemonriver/outline/outline-page.tsx +90 -7
- package/src/app/lemonriver/outline/pick-style.tsx +282 -0
- package/src/app/lemonriver/routes.test.tsx +17 -5
- package/src/app/lemonriver/routes.tsx +28 -0
- package/src/app/lemonriver/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/slide-extensions.tsx +14 -2
- package/src/app/lemonriver/templates/client.ts +60 -0
- package/src/app/lemonriver/templates/demo-page.tsx +79 -0
- package/src/app/lemonriver/templates/knobs.test.ts +62 -0
- package/src/app/lemonriver/templates/knobs.ts +62 -0
- package/src/app/lemonriver/templates/library-page.tsx +292 -0
- package/src/app/lemonriver/templates/model.test.ts +175 -0
- package/src/app/lemonriver/templates/model.ts +339 -0
- package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
- package/src/app/lemonriver/templates/preview-content.ts +149 -0
- package/src/app/lemonriver/templates/recommend.test.ts +71 -0
- package/src/app/lemonriver/templates/recommend.ts +72 -0
- package/src/app/lemonriver/templates/use-library.ts +58 -0
- package/src/app/lemonriver/templates/virtual.d.ts +28 -0
- package/src/app/lemonriver/text/en.ts +228 -0
- package/src/app/lemonriver/text/es.ts +220 -0
- package/src/app/lemonriver/text/ja.ts +220 -0
- package/src/app/lemonriver/text/types.ts +243 -0
- package/src/app/lemonriver/text/zh-cn.ts +218 -0
- package/src/app/lemonriver/text/zh-tw.ts +218 -0
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +6 -1
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lemonriver/update/prompt.ts +1 -1
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/slide.tsx +1 -1
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ScanSearch } from 'lucide-react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import { format } from '@/lib/use-locale';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
import { useLrText } from '../text';
|
|
8
|
+
import type { LrText } from '../text/types';
|
|
9
|
+
import { CANVAS, type Finding, hintsOf, problemsOf, type SelfCheck } from './model/self-check';
|
|
10
|
+
import { dropHighlight, requestHighlight, takeHighlight } from './self-check-jump';
|
|
11
|
+
|
|
12
|
+
/** The card badge reads what the board last published, without prop drilling. */
|
|
13
|
+
let published: { slideId: string; findings: Finding[]; unread: number[] } = {
|
|
14
|
+
slideId: '',
|
|
15
|
+
findings: [],
|
|
16
|
+
unread: [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function publishFindings(slideId: string, findings: Finding[], unread: number[]): void {
|
|
20
|
+
published = { slideId, findings, unread };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function findingsForPage(index: number): Finding[] {
|
|
24
|
+
return problemsOf(published.findings).filter((finding) => finding.page === index + 1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isPageUnread(index: number): boolean {
|
|
28
|
+
return published.unread.includes(index + 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The one sentence both the panel and the button show when pages were unread. */
|
|
32
|
+
export function unreadLabel(board: LrText['board'], unread: readonly number[]): string {
|
|
33
|
+
return unread.length > 5
|
|
34
|
+
? format(board.selfCheckUnreadMany, { n: unread.length })
|
|
35
|
+
: format(board.selfCheckUnread, { pages: unread.join(', ') });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function findingText(board: LrText['board'], finding: Finding): string {
|
|
39
|
+
switch (finding.kind) {
|
|
40
|
+
case 'tiny':
|
|
41
|
+
return format(board.findingTiny, { size: finding.size ?? 0 });
|
|
42
|
+
case 'small-body':
|
|
43
|
+
return board.findingSmallBody;
|
|
44
|
+
case 'overflow':
|
|
45
|
+
return board.findingOverflow;
|
|
46
|
+
case 'overlap':
|
|
47
|
+
return board.findingOverlap;
|
|
48
|
+
case 'no-notes':
|
|
49
|
+
return board.findingNoNotes;
|
|
50
|
+
case 'long-title':
|
|
51
|
+
return format(board.findingLongTitle, { n: finding.measure ?? 0 });
|
|
52
|
+
default:
|
|
53
|
+
return format(board.findingAccent, { n: finding.measure ?? 0 });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The board's own button: runs the check again and shows how many it found. */
|
|
58
|
+
export function SelfCheckButton({
|
|
59
|
+
record,
|
|
60
|
+
running,
|
|
61
|
+
onRun,
|
|
62
|
+
}: {
|
|
63
|
+
record: SelfCheck | null | undefined;
|
|
64
|
+
running: boolean;
|
|
65
|
+
onRun: () => void;
|
|
66
|
+
}) {
|
|
67
|
+
const lr = useLrText();
|
|
68
|
+
const count = problemsOf(record?.findings ?? []).length;
|
|
69
|
+
const unread = record?.unread ?? [];
|
|
70
|
+
return (
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
data-lr-self-check-button
|
|
74
|
+
disabled={running}
|
|
75
|
+
onClick={onRun}
|
|
76
|
+
className={cn(
|
|
77
|
+
'inline-flex h-8 items-center gap-1.5 rounded-[8px] border border-border bg-card px-2.5 text-[12.5px] font-medium text-muted-foreground outline-none',
|
|
78
|
+
'hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 disabled:opacity-50',
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<ScanSearch className="size-[15px]" aria-hidden />
|
|
82
|
+
{lr.board.selfCheck}
|
|
83
|
+
{record &&
|
|
84
|
+
(unread.length > 0 ? (
|
|
85
|
+
<span
|
|
86
|
+
data-lr-self-check-unread={unread.length}
|
|
87
|
+
title={unreadLabel(lr.board, unread)}
|
|
88
|
+
className="font-semibold text-foreground tabular-nums"
|
|
89
|
+
>
|
|
90
|
+
{format(lr.board.selfCheckUnreadBadge, { n: unread.length })}
|
|
91
|
+
</span>
|
|
92
|
+
) : (
|
|
93
|
+
<span
|
|
94
|
+
data-lr-self-check-count
|
|
95
|
+
className={cn('tabular-nums', count > 0 && 'font-semibold text-foreground')}
|
|
96
|
+
>
|
|
97
|
+
{count}
|
|
98
|
+
</span>
|
|
99
|
+
))}
|
|
100
|
+
</button>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function SelfCheckFindings({
|
|
105
|
+
record,
|
|
106
|
+
running,
|
|
107
|
+
onFix,
|
|
108
|
+
fixing,
|
|
109
|
+
onJump,
|
|
110
|
+
onRun,
|
|
111
|
+
}: {
|
|
112
|
+
record: SelfCheck | null | undefined;
|
|
113
|
+
running: boolean;
|
|
114
|
+
onFix: () => void;
|
|
115
|
+
fixing: boolean;
|
|
116
|
+
onJump: (finding: Finding) => void;
|
|
117
|
+
onRun: () => void;
|
|
118
|
+
}) {
|
|
119
|
+
const lr = useLrText().board;
|
|
120
|
+
if (record === undefined) return null;
|
|
121
|
+
const findings = record?.findings ?? [];
|
|
122
|
+
const problems = problemsOf(findings);
|
|
123
|
+
const hints = hintsOf(findings);
|
|
124
|
+
const unread = record?.unread ?? [];
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<section data-lr-self-check className="mt-3 rounded-[12px] border border-border bg-card p-3">
|
|
128
|
+
<div className="flex items-center justify-between gap-2">
|
|
129
|
+
<p data-lr-self-check-summary className="text-[12.5px] font-semibold">
|
|
130
|
+
{running
|
|
131
|
+
? lr.selfCheck
|
|
132
|
+
: unread.length > 0
|
|
133
|
+
? unreadLabel(lr, unread)
|
|
134
|
+
: problems.length === 0
|
|
135
|
+
? lr.selfCheckPassed
|
|
136
|
+
: format(lr.selfCheckFindings, { n: problems.length })}
|
|
137
|
+
</p>
|
|
138
|
+
<span className="flex shrink-0 items-center gap-1.5">
|
|
139
|
+
{unread.length > 0 && (
|
|
140
|
+
<Button type="button" size="xs" variant="outline" disabled={running} onClick={onRun}>
|
|
141
|
+
{lr.selfCheckAgain}
|
|
142
|
+
</Button>
|
|
143
|
+
)}
|
|
144
|
+
{problems.length > 0 && (
|
|
145
|
+
<Button
|
|
146
|
+
type="button"
|
|
147
|
+
size="xs"
|
|
148
|
+
variant="outline"
|
|
149
|
+
disabled={fixing || running}
|
|
150
|
+
onClick={onFix}
|
|
151
|
+
>
|
|
152
|
+
{lr.selfCheckFix}
|
|
153
|
+
</Button>
|
|
154
|
+
)}
|
|
155
|
+
</span>
|
|
156
|
+
</div>
|
|
157
|
+
{problems.length > 0 && (
|
|
158
|
+
<ul data-lr-self-check-problems className="mt-2 space-y-1">
|
|
159
|
+
{problems.map((finding) => (
|
|
160
|
+
<FindingRow key={`${finding.page}-${finding.kind}`} finding={finding} onJump={onJump} />
|
|
161
|
+
))}
|
|
162
|
+
</ul>
|
|
163
|
+
)}
|
|
164
|
+
{hints.length > 0 && (
|
|
165
|
+
<details data-lr-self-check-hints className="mt-2">
|
|
166
|
+
<summary className="cursor-pointer text-[12px] font-medium text-muted-foreground">
|
|
167
|
+
{lr.selfCheckHints}
|
|
168
|
+
</summary>
|
|
169
|
+
<ul className="mt-1 space-y-1">
|
|
170
|
+
{hints.map((finding) => (
|
|
171
|
+
<FindingRow
|
|
172
|
+
key={`${finding.page}-${finding.kind}`}
|
|
173
|
+
finding={finding}
|
|
174
|
+
onJump={onJump}
|
|
175
|
+
/>
|
|
176
|
+
))}
|
|
177
|
+
</ul>
|
|
178
|
+
</details>
|
|
179
|
+
)}
|
|
180
|
+
</section>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function FindingRow({ finding, onJump }: { finding: Finding; onJump: (finding: Finding) => void }) {
|
|
185
|
+
const lr = useLrText().board;
|
|
186
|
+
return (
|
|
187
|
+
<li>
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
data-lr-self-check-row={finding.page}
|
|
191
|
+
onClick={() => onJump(finding)}
|
|
192
|
+
className="w-full rounded-[6px] px-1.5 py-1 text-left text-[12px] leading-snug text-muted-foreground outline-none hover:bg-muted/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
193
|
+
>
|
|
194
|
+
<span className="font-medium">{format(lr.selfCheckPage, { n: finding.page })}</span>
|
|
195
|
+
{' · '}
|
|
196
|
+
{finding.count > 1 && `${format(lr.selfCheckTimes, { n: finding.count })} · `}
|
|
197
|
+
{findingText(lr, finding)}
|
|
198
|
+
</button>
|
|
199
|
+
</li>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Draws the box of the finding the list jumped to, then fades out. */
|
|
204
|
+
export function SelfCheckHighlight() {
|
|
205
|
+
const [params] = useSearchParams();
|
|
206
|
+
const page = Number(params.get('p') ?? 1);
|
|
207
|
+
const [boxes, setBoxes] = useState<
|
|
208
|
+
{
|
|
209
|
+
left: number;
|
|
210
|
+
top: number;
|
|
211
|
+
width: number;
|
|
212
|
+
height: number;
|
|
213
|
+
}[]
|
|
214
|
+
>([]);
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
const request = takeHighlight(page);
|
|
218
|
+
if (!request?.boxes || request.boxes.length === 0) return;
|
|
219
|
+
const targets = request.boxes;
|
|
220
|
+
let retry = 0;
|
|
221
|
+
const draw = (): boolean => {
|
|
222
|
+
const host = document.querySelector('main[data-inspector-root]');
|
|
223
|
+
const canvas = host?.querySelector<HTMLElement>('[data-osd-canvas]');
|
|
224
|
+
if (!canvas) return false;
|
|
225
|
+
const rect = canvas.getBoundingClientRect();
|
|
226
|
+
if (rect.width === 0) return false;
|
|
227
|
+
const scale = rect.width / CANVAS.width;
|
|
228
|
+
setBoxes(
|
|
229
|
+
targets.map((target) => ({
|
|
230
|
+
left: rect.left + target.x * scale,
|
|
231
|
+
top: rect.top + target.y * scale,
|
|
232
|
+
width: target.w * scale,
|
|
233
|
+
height: target.h * scale,
|
|
234
|
+
})),
|
|
235
|
+
);
|
|
236
|
+
return true;
|
|
237
|
+
};
|
|
238
|
+
if (!draw()) retry = window.setTimeout(() => void draw(), 240);
|
|
239
|
+
const clear = window.setTimeout(() => {
|
|
240
|
+
setBoxes([]);
|
|
241
|
+
dropHighlight();
|
|
242
|
+
}, 2000);
|
|
243
|
+
return () => {
|
|
244
|
+
window.clearTimeout(retry);
|
|
245
|
+
window.clearTimeout(clear);
|
|
246
|
+
};
|
|
247
|
+
}, [page]);
|
|
248
|
+
|
|
249
|
+
if (boxes.length === 0) return null;
|
|
250
|
+
return (
|
|
251
|
+
<>
|
|
252
|
+
{boxes.map((box) => (
|
|
253
|
+
<div
|
|
254
|
+
key={`${box.left}-${box.top}-${box.width}-${box.height}`}
|
|
255
|
+
data-lr-self-check-highlight
|
|
256
|
+
aria-hidden
|
|
257
|
+
className="pointer-events-none fixed z-50 rounded-[4px] bg-[var(--lr-focus)]/10 ring-2 ring-[var(--lr-focus)]"
|
|
258
|
+
style={box}
|
|
259
|
+
/>
|
|
260
|
+
))}
|
|
261
|
+
</>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The list's rows send the editor to that page; the box follows in the editor. */
|
|
266
|
+
export function useJumpToFinding(slideId: string) {
|
|
267
|
+
const navigate = useNavigate();
|
|
268
|
+
return (finding: Finding) => {
|
|
269
|
+
requestHighlight({ page: finding.page, boxes: finding.boxes });
|
|
270
|
+
navigate(`/s/${encodeURIComponent(slideId)}?p=${finding.page}`);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Component, type ReactNode, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { SlideCanvas } from '../../components/slide-canvas';
|
|
3
|
+
import type { DesignSystem } from '../../lib/design';
|
|
4
|
+
import { SlidePageProvider } from '../../lib/page-context';
|
|
5
|
+
import type { Page } from '../../lib/sdk';
|
|
6
|
+
import type { SnapNode } from './blocks/classify';
|
|
7
|
+
import { snapshotPage } from './blocks/snapshot';
|
|
8
|
+
import { CARD_H, CARD_W } from './layout';
|
|
9
|
+
import { type CheckedPage, type CheckResult, checkDeck } from './model/self-check';
|
|
10
|
+
|
|
11
|
+
/** Pages drawn off screen at a time; the next batch follows the one before it. */
|
|
12
|
+
const PER_PASS = 6;
|
|
13
|
+
const SCALE = 0.25;
|
|
14
|
+
/** A page that has not painted by then is reported as unread, never as clean. */
|
|
15
|
+
export const READY_TIMEOUT_MS = 5000;
|
|
16
|
+
|
|
17
|
+
export type SelfCheckInput = {
|
|
18
|
+
pages: Page[];
|
|
19
|
+
design?: DesignSystem;
|
|
20
|
+
notes?: (string | undefined)[];
|
|
21
|
+
titles?: string[];
|
|
22
|
+
minType?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const wait = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms));
|
|
26
|
+
|
|
27
|
+
const frames = (count: number) =>
|
|
28
|
+
new Promise<void>((resolve) => {
|
|
29
|
+
const step = (left: number) => {
|
|
30
|
+
if (left <= 0) resolve();
|
|
31
|
+
else window.requestAnimationFrame(() => step(left - 1));
|
|
32
|
+
};
|
|
33
|
+
step(count);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** A page that throws while drawn is a page this check could not read. */
|
|
37
|
+
class PageBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
|
|
38
|
+
state = { failed: false };
|
|
39
|
+
|
|
40
|
+
static getDerivedStateFromError(): { failed: boolean } {
|
|
41
|
+
return { failed: true };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
render() {
|
|
45
|
+
return this.state.failed ? null : this.props.children;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Draws every page off screen, waits for each to paint, copies its DOM and runs
|
|
51
|
+
* the rules. Nothing here is shown: the deck is already on screen elsewhere,
|
|
52
|
+
* and the check needs the pages laid out, not visible.
|
|
53
|
+
*/
|
|
54
|
+
export function SelfCheckRunner({
|
|
55
|
+
input,
|
|
56
|
+
onDone,
|
|
57
|
+
}: {
|
|
58
|
+
input: SelfCheckInput;
|
|
59
|
+
onDone: (result: CheckResult) => void;
|
|
60
|
+
}) {
|
|
61
|
+
const host = useRef<HTMLDivElement | null>(null);
|
|
62
|
+
const [pass, setPass] = useState(0);
|
|
63
|
+
const collected = useRef<CheckedPage[]>([]);
|
|
64
|
+
const done = useRef(onDone);
|
|
65
|
+
done.current = onDone;
|
|
66
|
+
|
|
67
|
+
const start = pass * PER_PASS;
|
|
68
|
+
const total = input.pages.length;
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (start >= total) {
|
|
72
|
+
done.current(
|
|
73
|
+
checkDeck(collected.current, {
|
|
74
|
+
accent: input.design?.palette.accent,
|
|
75
|
+
minType: input.minType,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let cancelled = false;
|
|
81
|
+
|
|
82
|
+
const readTree = (index: number): SnapNode | null => {
|
|
83
|
+
const box = host.current?.querySelector<HTMLElement>(`[data-lr-self-check-page="${index}"]`);
|
|
84
|
+
const canvas = box?.querySelector<HTMLElement>('[data-osd-canvas]');
|
|
85
|
+
if (!canvas) return null;
|
|
86
|
+
try {
|
|
87
|
+
return snapshotPage(canvas, SCALE);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const run = async () => {
|
|
94
|
+
await Promise.race([document.fonts.ready, wait(READY_TIMEOUT_MS)]);
|
|
95
|
+
await frames(2);
|
|
96
|
+
if (cancelled) return;
|
|
97
|
+
const trees = new Map<number, SnapNode | null>();
|
|
98
|
+
for (let index = start; index < Math.min(start + PER_PASS, total); index += 1) {
|
|
99
|
+
trees.set(index, readTree(index));
|
|
100
|
+
}
|
|
101
|
+
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
102
|
+
while ([...trees.values()].some((tree) => tree === null) && Date.now() < deadline) {
|
|
103
|
+
await frames(1);
|
|
104
|
+
if (cancelled) return;
|
|
105
|
+
for (const [index, tree] of trees) {
|
|
106
|
+
if (!tree) trees.set(index, readTree(index));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (let index = start; index < Math.min(start + PER_PASS, total); index += 1) {
|
|
110
|
+
collected.current.push({
|
|
111
|
+
n: index + 1,
|
|
112
|
+
tree: trees.get(index) ?? null,
|
|
113
|
+
notes: input.notes?.[index] ?? '',
|
|
114
|
+
title: input.titles?.[index] ?? '',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
setPass((value) => value + 1);
|
|
118
|
+
};
|
|
119
|
+
void run();
|
|
120
|
+
|
|
121
|
+
return () => {
|
|
122
|
+
cancelled = true;
|
|
123
|
+
};
|
|
124
|
+
}, [start, total, input.design?.palette.accent, input.notes, input.titles, input.minType]);
|
|
125
|
+
|
|
126
|
+
if (start >= total) return null;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div ref={host} aria-hidden className="pointer-events-none fixed top-0 left-[-20000px]">
|
|
130
|
+
{input.pages.slice(start, start + PER_PASS).map((PageComp, offset) => {
|
|
131
|
+
const index = start + offset;
|
|
132
|
+
return (
|
|
133
|
+
<div
|
|
134
|
+
key={index}
|
|
135
|
+
data-lr-self-check-page={index}
|
|
136
|
+
style={{ width: CARD_W, height: CARD_H }}
|
|
137
|
+
>
|
|
138
|
+
<PageBoundary>
|
|
139
|
+
<SlideCanvas scale={SCALE} center={false} flat freezeMotion design={input.design}>
|
|
140
|
+
<SlidePageProvider index={index} total={total}>
|
|
141
|
+
<PageComp />
|
|
142
|
+
</SlidePageProvider>
|
|
143
|
+
</SlideCanvas>
|
|
144
|
+
</PageBoundary>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
})}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CardStatus } from './model/cards';
|
|
2
|
+
|
|
3
|
+
/** One colour per status, shared by the cards, the list and the timeline. */
|
|
4
|
+
export const STATUS_STYLE: Record<CardStatus, { dot: string; ring: string; bar: string }> = {
|
|
5
|
+
todo: {
|
|
6
|
+
dot: 'bg-muted-foreground/50',
|
|
7
|
+
ring: 'ring-muted-foreground/35',
|
|
8
|
+
bar: 'bg-muted-foreground/20',
|
|
9
|
+
},
|
|
10
|
+
doing: {
|
|
11
|
+
dot: 'bg-[var(--lr-accent)]',
|
|
12
|
+
ring: 'ring-[var(--lr-accent)]',
|
|
13
|
+
bar: 'bg-[var(--lr-accent)]/25',
|
|
14
|
+
},
|
|
15
|
+
review: {
|
|
16
|
+
dot: 'bg-[var(--lr-warning)]',
|
|
17
|
+
ring: 'ring-[var(--lr-warning)]/75',
|
|
18
|
+
bar: 'bg-[var(--lr-warning)]/30',
|
|
19
|
+
},
|
|
20
|
+
done: {
|
|
21
|
+
dot: 'bg-[var(--lr-success)]',
|
|
22
|
+
ring: 'ring-[var(--lr-success)]/70',
|
|
23
|
+
bar: 'bg-[var(--lr-success)]/30',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { toast } from 'sonner';
|
|
3
|
+
import {
|
|
4
|
+
createSession,
|
|
5
|
+
sendMessage,
|
|
6
|
+
setActiveSession,
|
|
7
|
+
setDockOpen,
|
|
8
|
+
useAgentSessions,
|
|
9
|
+
useAgentStatus,
|
|
10
|
+
} from '@/lib/agent/use-agent';
|
|
11
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
12
|
+
import { useLrText } from '../text';
|
|
13
|
+
import type { BoardTask } from './model/agent-tasks';
|
|
14
|
+
import {
|
|
15
|
+
type BoardApplying,
|
|
16
|
+
type BoardLastApply,
|
|
17
|
+
type ChapterPlan,
|
|
18
|
+
sanitizeApplying,
|
|
19
|
+
sanitizeChapterPlan,
|
|
20
|
+
sanitizeLastApply,
|
|
21
|
+
} from './model/apply';
|
|
22
|
+
import { type BoardColumn, sanitizeStructure } from './model/structure';
|
|
23
|
+
|
|
24
|
+
const POLL_MS = 1500;
|
|
25
|
+
const STALL_MS = 10 * 60_000;
|
|
26
|
+
/** Long enough for the turn to start; a session that is idle after this never got it. */
|
|
27
|
+
const IDLE_STALL_MS = 60_000;
|
|
28
|
+
|
|
29
|
+
type BoardApplyState = {
|
|
30
|
+
applying: BoardApplying | null;
|
|
31
|
+
lastApply: BoardLastApply | null;
|
|
32
|
+
chapterPlan: ChapterPlan | null;
|
|
33
|
+
/** The chapters as the server has them now, read with every poll. */
|
|
34
|
+
columns: BoardColumn[] | null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async function readBoardState(slideId: string): Promise<BoardApplyState | null> {
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(`/__board?slideId=${encodeURIComponent(slideId)}`);
|
|
40
|
+
if (!res.ok) return null;
|
|
41
|
+
const body = (await res.json()) as {
|
|
42
|
+
applying?: unknown;
|
|
43
|
+
lastApply?: unknown;
|
|
44
|
+
chapterPlan?: unknown;
|
|
45
|
+
columns?: unknown;
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
applying: sanitizeApplying(body.applying),
|
|
49
|
+
lastApply: sanitizeLastApply(body.lastApply),
|
|
50
|
+
chapterPlan: sanitizeChapterPlan(body.chapterPlan),
|
|
51
|
+
columns: sanitizeStructure({ columns: body.columns })?.columns ?? null,
|
|
52
|
+
};
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function post(path: string, slideId: string, body: Record<string, unknown> = {}) {
|
|
59
|
+
try {
|
|
60
|
+
return await fetch(path, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: { 'content-type': 'application/json' },
|
|
63
|
+
body: JSON.stringify({ slideId, ...body }),
|
|
64
|
+
});
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Hands one task to the agent in a single message and follows the board record
|
|
72
|
+
* until the turn ends: running, settled, or given up on.
|
|
73
|
+
*/
|
|
74
|
+
export function useBoardApply(
|
|
75
|
+
slideId: string,
|
|
76
|
+
onSettled: (last: BoardLastApply | null, was: BoardApplying | null) => void,
|
|
77
|
+
) {
|
|
78
|
+
const lr = useLrText();
|
|
79
|
+
const locale = useLocale();
|
|
80
|
+
const { sessions } = useAgentSessions();
|
|
81
|
+
const { connected, provider } = useAgentStatus();
|
|
82
|
+
const [state, setState] = useState<BoardApplyState>({
|
|
83
|
+
applying: null,
|
|
84
|
+
lastApply: null,
|
|
85
|
+
chapterPlan: null,
|
|
86
|
+
columns: null,
|
|
87
|
+
});
|
|
88
|
+
const [starting, setStarting] = useState(false);
|
|
89
|
+
const [now, setNow] = useState(() => Date.now());
|
|
90
|
+
const previous = useRef<BoardApplying | null>(null);
|
|
91
|
+
const settled = useRef(onSettled);
|
|
92
|
+
settled.current = onSettled;
|
|
93
|
+
|
|
94
|
+
const refresh = useCallback(async () => {
|
|
95
|
+
const next = await readBoardState(slideId);
|
|
96
|
+
if (!next) return;
|
|
97
|
+
const was = previous.current;
|
|
98
|
+
const wasRunning = was !== null;
|
|
99
|
+
previous.current = next.applying;
|
|
100
|
+
setState(next);
|
|
101
|
+
setNow(Date.now());
|
|
102
|
+
if (wasRunning && !next.applying) settled.current(next.lastApply, was);
|
|
103
|
+
}, [slideId]);
|
|
104
|
+
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
previous.current = null;
|
|
107
|
+
setState({ applying: null, lastApply: null, chapterPlan: null, columns: null });
|
|
108
|
+
void refresh();
|
|
109
|
+
}, [refresh]);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!state.applying) return;
|
|
113
|
+
const timer = window.setInterval(() => void refresh(), POLL_MS);
|
|
114
|
+
return () => window.clearInterval(timer);
|
|
115
|
+
}, [state.applying, refresh]);
|
|
116
|
+
|
|
117
|
+
const start = useCallback(
|
|
118
|
+
async (task: BoardTask) => {
|
|
119
|
+
if (starting) return;
|
|
120
|
+
setStarting(true);
|
|
121
|
+
try {
|
|
122
|
+
const res = await post('/__board/apply', slideId, { task, lang: locale.id });
|
|
123
|
+
if (!res?.ok) {
|
|
124
|
+
const body = res ? ((await res.json().catch(() => null)) as { error?: string }) : null;
|
|
125
|
+
throw new Error(body?.error ?? `HTTP ${res?.status ?? 0}`);
|
|
126
|
+
}
|
|
127
|
+
const { prompt } = (await res.json()) as { prompt: string };
|
|
128
|
+
|
|
129
|
+
const existing = sessions.find((session) => session.slideId === slideId);
|
|
130
|
+
let sessionId = existing?.id ?? null;
|
|
131
|
+
if (!sessionId) {
|
|
132
|
+
if (!provider) throw new Error('no agent');
|
|
133
|
+
sessionId = (await createSession(provider.id, slideId)).id;
|
|
134
|
+
}
|
|
135
|
+
setActiveSession(sessionId);
|
|
136
|
+
await sendMessage(sessionId, prompt, { slideId });
|
|
137
|
+
// The message id is the server's to make; the session is enough to keep
|
|
138
|
+
// another conversation on this deck from settling the task.
|
|
139
|
+
await fetch('/__board/apply', {
|
|
140
|
+
method: 'PATCH',
|
|
141
|
+
headers: { 'content-type': 'application/json' },
|
|
142
|
+
body: JSON.stringify({ slideId, sessionId }),
|
|
143
|
+
});
|
|
144
|
+
setDockOpen(true);
|
|
145
|
+
await refresh();
|
|
146
|
+
} catch (err) {
|
|
147
|
+
toast.error(
|
|
148
|
+
format(lr.board.applyFailed, { reason: String((err as Error).message ?? err) }),
|
|
149
|
+
);
|
|
150
|
+
await refresh();
|
|
151
|
+
} finally {
|
|
152
|
+
setStarting(false);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
[lr.board.applyFailed, locale.id, provider, refresh, sessions, slideId, starting],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const savePlan = useCallback(
|
|
159
|
+
async (plan: ChapterPlan | null) => {
|
|
160
|
+
try {
|
|
161
|
+
await fetch('/__board/plan', {
|
|
162
|
+
method: 'PUT',
|
|
163
|
+
headers: { 'content-type': 'application/json' },
|
|
164
|
+
body: JSON.stringify({ slideId, chapterPlan: plan }),
|
|
165
|
+
});
|
|
166
|
+
} catch {}
|
|
167
|
+
await refresh();
|
|
168
|
+
},
|
|
169
|
+
[refresh, slideId],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const cancel = useCallback(async () => {
|
|
173
|
+
await post('/__board/apply/cancel', slideId);
|
|
174
|
+
await refresh();
|
|
175
|
+
}, [refresh, slideId]);
|
|
176
|
+
|
|
177
|
+
const undoLast = useCallback(async () => {
|
|
178
|
+
const res = await post('/__board/apply/undo', slideId);
|
|
179
|
+
if (!res?.ok) return false;
|
|
180
|
+
await refresh();
|
|
181
|
+
return true;
|
|
182
|
+
}, [refresh, slideId]);
|
|
183
|
+
|
|
184
|
+
const running = sessions.some(
|
|
185
|
+
(session) => session.slideId === slideId && session.status === 'running',
|
|
186
|
+
);
|
|
187
|
+
const { applying, lastApply, chapterPlan, columns } = state;
|
|
188
|
+
const elapsed = applying ? now - applying.startedAt : 0;
|
|
189
|
+
const stalled =
|
|
190
|
+
applying !== null && (elapsed > STALL_MS || (!running && elapsed > IDLE_STALL_MS));
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
applying,
|
|
194
|
+
lastApply,
|
|
195
|
+
chapterPlan,
|
|
196
|
+
columns,
|
|
197
|
+
stalled,
|
|
198
|
+
starting,
|
|
199
|
+
connected,
|
|
200
|
+
start,
|
|
201
|
+
savePlan,
|
|
202
|
+
cancel,
|
|
203
|
+
undoLast,
|
|
204
|
+
refresh,
|
|
205
|
+
};
|
|
206
|
+
}
|