@lemonriver/core 0.5.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/dist/{build-CS1goZxt.js → build-RlcGG-Ve.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-BpbcCbUv.js → config-BJT87wE9.js} +1155 -19
- package/dist/{dev-BpYnfgLL.js → dev-DR-j_xda.js} +1 -1
- package/dist/{preview-HSzPPkSs.js → preview-BTAhTb5B.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/lemonriver/board/blocks/classify.test.ts +5 -0
- package/src/app/lemonriver/board/blocks/classify.ts +29 -2
- package/src/app/lemonriver/board/blocks/snapshot.ts +34 -4
- package/src/app/lemonriver/board/board-page.tsx +15 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +33 -1
- 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/page-node.tsx +23 -1
- 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/use-self-check.ts +117 -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 +79 -0
- package/src/app/lemonriver/outline/model.ts +80 -7
- package/src/app/lemonriver/outline/outline-page.tsx +56 -6
- 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/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 +57 -0
- package/src/app/lemonriver/text/es.ts +57 -0
- package/src/app/lemonriver/text/ja.ts +57 -0
- package/src/app/lemonriver/text/types.ts +73 -0
- package/src/app/lemonriver/text/zh-cn.ts +57 -0
- package/src/app/lemonriver/text/zh-tw.ts +57 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +6 -1
- package/src/app/lemonriver/update/prompt.ts +1 -1
|
@@ -16,8 +16,11 @@ import { FolderIconChip, SystemViewIcon } from '../../components/sidebar/folder-
|
|
|
16
16
|
import { ALL_SLIDES_ID, DRAFT_ID } from '../../components/sidebar/sidebar';
|
|
17
17
|
import { slideCreatedAt, slideIds } from '../../lib/slides';
|
|
18
18
|
import type { HomeOutletContext } from '../../routes/home-shell';
|
|
19
|
+
import { FilterPill } from '../chrome/filter-pill';
|
|
19
20
|
import { isFeatureEnabled } from '../features';
|
|
20
21
|
import { LemonEmpty } from '../feedback/lemon-empty';
|
|
22
|
+
import { OCCASIONS } from '../templates/model';
|
|
23
|
+
import { useTemplateLibrary } from '../templates/use-library';
|
|
21
24
|
import { useLrText } from '../text';
|
|
22
25
|
import { moveToTrash } from '../trash/api';
|
|
23
26
|
import { BriefCard } from './brief-card';
|
|
@@ -57,8 +60,10 @@ export function LemonRiverHome() {
|
|
|
57
60
|
const lr = useLrText();
|
|
58
61
|
const now = useNow();
|
|
59
62
|
const times = useDeckTimes();
|
|
63
|
+
const library = useTemplateLibrary();
|
|
60
64
|
const editing = useEditingDecks();
|
|
61
65
|
const [query, setQuery] = useState('');
|
|
66
|
+
const [occasion, setOccasion] = useState<string | null>(null);
|
|
62
67
|
const [sortKey, setSortKey] = useSortPref();
|
|
63
68
|
const [dialog, setDialog] = useState<Dialog>(null);
|
|
64
69
|
|
|
@@ -68,13 +73,27 @@ export function LemonRiverHome() {
|
|
|
68
73
|
isAll || isDraft ? null : (manifest.folders.find((f) => f.id === selectedId) ?? null);
|
|
69
74
|
const visible = isAll ? slideIds : isDraft ? draftSlides : (slidesByFolder[selectedId] ?? []);
|
|
70
75
|
const filtered = useMemo(() => filterDecks(visible, query, titleMap), [visible, query, titleMap]);
|
|
76
|
+
const presentOccasions = useMemo(
|
|
77
|
+
() => OCCASIONS.filter((entry) => visible.some((id) => times[id]?.occasion === entry.id)),
|
|
78
|
+
[visible, times],
|
|
79
|
+
);
|
|
80
|
+
const shown = useMemo(
|
|
81
|
+
() => (occasion ? filtered.filter((id) => times[id]?.occasion === occasion) : filtered),
|
|
82
|
+
[filtered, occasion, times],
|
|
83
|
+
);
|
|
71
84
|
const sorted = useMemo(
|
|
72
|
-
() => sortDecks(
|
|
73
|
-
[
|
|
85
|
+
() => sortDecks(shown, sortKey, (id) => titleMap[id] ?? id, slideCreatedAt),
|
|
86
|
+
[shown, sortKey, titleMap],
|
|
74
87
|
);
|
|
75
88
|
const searching = query.trim().length > 0;
|
|
89
|
+
const narrowing = searching || occasion !== null;
|
|
76
90
|
const showLoading = useDelayed(loading);
|
|
77
91
|
const titleOf = (id: string) => titleMap[id] ?? id;
|
|
92
|
+
const templateNameOf = (id: string): string | null => {
|
|
93
|
+
const templateId = times[id]?.template;
|
|
94
|
+
if (!templateId) return null;
|
|
95
|
+
return library?.templates.find((entry) => entry.id === templateId)?.name ?? null;
|
|
96
|
+
};
|
|
78
97
|
|
|
79
98
|
const greeting = {
|
|
80
99
|
morning: lr.home.greetingMorning,
|
|
@@ -130,8 +149,8 @@ export function LemonRiverHome() {
|
|
|
130
149
|
<FolderSwitcher ctx={ctx} />
|
|
131
150
|
{!loading && (
|
|
132
151
|
<span className="folio ml-0.5">
|
|
133
|
-
{pad2(
|
|
134
|
-
{
|
|
152
|
+
{pad2(narrowing ? shown.length : visible.length)}
|
|
153
|
+
{narrowing && <span className="opacity-40">/{pad2(visible.length)}</span>}
|
|
135
154
|
</span>
|
|
136
155
|
)}
|
|
137
156
|
<div className="ml-auto flex w-full items-center gap-2 md:w-auto">
|
|
@@ -140,18 +159,47 @@ export function LemonRiverHome() {
|
|
|
140
159
|
</div>
|
|
141
160
|
</div>
|
|
142
161
|
|
|
162
|
+
{!loading && library?.available === true && presentOccasions.length > 0 && (
|
|
163
|
+
<div
|
|
164
|
+
role="radiogroup"
|
|
165
|
+
aria-label={lr.templates.occasions}
|
|
166
|
+
data-lr-occasion-filter
|
|
167
|
+
className="mb-4 flex flex-wrap items-center gap-2"
|
|
168
|
+
>
|
|
169
|
+
<FilterPill
|
|
170
|
+
label={lr.templates.all}
|
|
171
|
+
active={occasion === null}
|
|
172
|
+
onSelect={() => setOccasion(null)}
|
|
173
|
+
/>
|
|
174
|
+
{presentOccasions.map((entry) => (
|
|
175
|
+
<FilterPill
|
|
176
|
+
key={entry.id}
|
|
177
|
+
label={entry.name}
|
|
178
|
+
active={occasion === entry.id}
|
|
179
|
+
onSelect={() => setOccasion(entry.id)}
|
|
180
|
+
/>
|
|
181
|
+
))}
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
|
|
143
185
|
{loading ? (
|
|
144
186
|
showLoading ? (
|
|
145
187
|
<GridSkeleton />
|
|
146
188
|
) : null
|
|
147
189
|
) : visible.length === 0 ? (
|
|
148
190
|
<EmptyHome isDraft={isAll || isDraft} folderName={folder?.name} />
|
|
149
|
-
) :
|
|
191
|
+
) : shown.length === 0 ? (
|
|
150
192
|
<LemonEmpty
|
|
151
193
|
state="thinking"
|
|
152
194
|
title={t.home.noMatches}
|
|
153
195
|
actions={
|
|
154
|
-
<Button
|
|
196
|
+
<Button
|
|
197
|
+
variant="outline"
|
|
198
|
+
onClick={() => {
|
|
199
|
+
setQuery('');
|
|
200
|
+
setOccasion(null);
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
155
203
|
{t.home.clearSearch}
|
|
156
204
|
</Button>
|
|
157
205
|
}
|
|
@@ -174,6 +222,7 @@ export function LemonRiverHome() {
|
|
|
174
222
|
now={now}
|
|
175
223
|
modifiedAt={times[id]?.modifiedAt}
|
|
176
224
|
editing={editing.has(id)}
|
|
225
|
+
templateName={templateNameOf(id)}
|
|
177
226
|
onTitleResolved={ctx.reportTitle}
|
|
178
227
|
actions={{
|
|
179
228
|
onRename: () => setDialog({ kind: 'rename', id }),
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
export type DeckTimes = Record<
|
|
3
|
+
export type DeckTimes = Record<
|
|
4
|
+
string,
|
|
5
|
+
{ modifiedAt: number; occasion: string | null; template?: string | null }
|
|
6
|
+
>;
|
|
4
7
|
|
|
5
8
|
/** When each deck was last saved. Only the dev server knows; a built site gets nothing. */
|
|
6
9
|
export function useDeckTimes(): DeckTimes {
|
|
@@ -3,6 +3,11 @@ import { toast } from 'sonner';
|
|
|
3
3
|
import { Button } from '@/components/ui/button';
|
|
4
4
|
import { format, plural } from '@/lib/use-locale';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
|
+
import { problemsOf } from '../board/model/self-check';
|
|
7
|
+
import { SelfCheckFindings, SelfCheckHighlight, useJumpToFinding } from '../board/self-check-panel';
|
|
8
|
+
import { SelfCheckRunner } from '../board/self-check-runner';
|
|
9
|
+
import { useBoardApply } from '../board/use-board-apply';
|
|
10
|
+
import { useSelfCheck } from '../board/use-self-check';
|
|
6
11
|
import {
|
|
7
12
|
HelperMascot,
|
|
8
13
|
type HelperRole,
|
|
@@ -42,12 +47,30 @@ export function BuildTeam({ slideId }: { slideId: string }) {
|
|
|
42
47
|
const prefsLr = useLrText().prefs;
|
|
43
48
|
const { outline, action, running, waitingForAnswer, connected, pause, resume, undo } =
|
|
44
49
|
useBuildDriver(slideId);
|
|
50
|
+
const boardLr = useLrText().board;
|
|
51
|
+
const selfCheck = useSelfCheck(slideId);
|
|
52
|
+
const jumpToFinding = useJumpToFinding(slideId);
|
|
53
|
+
const apply = useBoardApply(slideId, (last, was) => {
|
|
54
|
+
if (was?.task.kind === 'self-check' && last?.ok) {
|
|
55
|
+
toast.success(boardLr.selfCheckDone);
|
|
56
|
+
void selfCheck.run();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
45
59
|
const [events, setEvents] = useState<Event[]>([]);
|
|
46
60
|
const [hidden, setHidden] = useState(false);
|
|
47
61
|
const previous = useRef<typeof outline>(undefined);
|
|
48
62
|
const eventSeq = useRef(0);
|
|
49
63
|
const toasted = useRef(false);
|
|
50
64
|
|
|
65
|
+
const needsCheck =
|
|
66
|
+
outline?.state === 'built' &&
|
|
67
|
+
selfCheck.record !== undefined &&
|
|
68
|
+
(selfCheck.record === null || selfCheck.record.at < outline.updatedAt);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (needsCheck && !selfCheck.running) void selfCheck.run();
|
|
72
|
+
}, [needsCheck, selfCheck.running, selfCheck.run]);
|
|
73
|
+
|
|
51
74
|
const built = outline?.built ?? 0;
|
|
52
75
|
const total = outline?.items.length ?? 0;
|
|
53
76
|
const state = outline?.state;
|
|
@@ -273,6 +296,25 @@ export function BuildTeam({ slideId }: { slideId: string }) {
|
|
|
273
296
|
))}
|
|
274
297
|
</ul>
|
|
275
298
|
)}
|
|
299
|
+
|
|
300
|
+
{state === 'built' && (
|
|
301
|
+
<SelfCheckFindings
|
|
302
|
+
record={selfCheck.record}
|
|
303
|
+
running={selfCheck.running}
|
|
304
|
+
fixing={apply.starting || apply.applying !== null}
|
|
305
|
+
onFix={() => {
|
|
306
|
+
const findings = problemsOf(selfCheck.record?.findings ?? []);
|
|
307
|
+
if (findings.length === 0) return;
|
|
308
|
+
toast.message(boardLr.selfCheckRunning);
|
|
309
|
+
void apply.start({ kind: 'self-check', findings });
|
|
310
|
+
}}
|
|
311
|
+
onJump={jumpToFinding}
|
|
312
|
+
onRun={() => void selfCheck.run()}
|
|
313
|
+
/>
|
|
314
|
+
)}
|
|
315
|
+
|
|
316
|
+
{selfCheck.runner && <SelfCheckRunner {...selfCheck.runner} />}
|
|
317
|
+
<SelfCheckHighlight />
|
|
276
318
|
</div>
|
|
277
319
|
);
|
|
278
320
|
}
|
|
@@ -17,38 +17,20 @@ import { readPrefs } from '../agent-prefs/prefs';
|
|
|
17
17
|
import { useAgentPrefs } from '../agent-prefs/use-prefs';
|
|
18
18
|
import { Mascot } from '../brand/mascot';
|
|
19
19
|
import { Onboarding } from '../onboarding/onboarding';
|
|
20
|
+
import { OCCASIONS, type OccasionId } from '../templates/model';
|
|
21
|
+
import { useTemplateLibrary } from '../templates/use-library';
|
|
20
22
|
import { useLrText } from '../text';
|
|
23
|
+
import { readDraft, writeDraft } from './draft';
|
|
21
24
|
import { checkFileObject, type FileVerdict, formatSize } from './files';
|
|
22
|
-
import { MAX_BRIEF, OUTLINE_PAGE_SIZES, type Outline, outlinePrompt } from './model';
|
|
25
|
+
import { MAX_AUDIENCE, MAX_BRIEF, OUTLINE_PAGE_SIZES, type Outline, outlinePrompt } from './model';
|
|
23
26
|
import { Steps } from './steps';
|
|
24
27
|
|
|
25
|
-
const DRAFT_KEY = 'lemonriver:new-deck-draft';
|
|
26
|
-
|
|
27
28
|
type DraftFile = { key: string; file: File; verdict: FileVerdict };
|
|
28
29
|
|
|
29
|
-
type StoredDraft = { brief?: unknown; pages?: unknown };
|
|
30
|
-
|
|
31
30
|
function basePath(): string {
|
|
32
31
|
return import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
function readDraft(): StoredDraft {
|
|
36
|
-
try {
|
|
37
|
-
const raw = sessionStorage.getItem(DRAFT_KEY);
|
|
38
|
-
if (!raw) return {};
|
|
39
|
-
const parsed: unknown = JSON.parse(raw);
|
|
40
|
-
return parsed && typeof parsed === 'object' ? (parsed as StoredDraft) : {};
|
|
41
|
-
} catch {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function writeDraft(brief: string, pages: number): void {
|
|
47
|
-
try {
|
|
48
|
-
sessionStorage.setItem(DRAFT_KEY, JSON.stringify({ brief, pages }));
|
|
49
|
-
} catch {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
34
|
function fileKey(file: File): string {
|
|
53
35
|
return `${file.name}:${file.size}:${file.lastModified}:${Math.random().toString(36).slice(2, 7)}`;
|
|
54
36
|
}
|
|
@@ -59,27 +41,50 @@ export function DescribePage() {
|
|
|
59
41
|
const location = useLocation();
|
|
60
42
|
const prefs = useAgentPrefs();
|
|
61
43
|
const { connected, loading, provider } = useAgentStatus();
|
|
44
|
+
const library = useTemplateLibrary();
|
|
62
45
|
const deckId = new URLSearchParams(location.search).get('deck') ?? '';
|
|
46
|
+
const templateParam = new URLSearchParams(location.search).get('template') ?? '';
|
|
63
47
|
const initialState = (location.state ?? {}) as { brief?: unknown };
|
|
48
|
+
const [draft] = useState(readDraft);
|
|
64
49
|
|
|
65
50
|
const [brief, setBrief] = useState(() => {
|
|
66
51
|
if (typeof initialState.brief === 'string') return initialState.brief.slice(0, MAX_BRIEF);
|
|
67
|
-
const draft = readDraft();
|
|
68
52
|
return typeof draft.brief === 'string' ? draft.brief.slice(0, MAX_BRIEF) : '';
|
|
69
53
|
});
|
|
70
54
|
const [pages, setPages] = useState<number>(() => {
|
|
71
|
-
const draft = readDraft();
|
|
72
55
|
return OUTLINE_PAGE_SIZES.find((size) => size === draft.pages) ?? 8;
|
|
73
56
|
});
|
|
57
|
+
const [occasion, setOccasion] = useState<OccasionId | null>(() =>
|
|
58
|
+
OCCASIONS.find((entry) => entry.id === draft.occasion) ? (draft.occasion as OccasionId) : null,
|
|
59
|
+
);
|
|
60
|
+
const [audience, setAudience] = useState(() =>
|
|
61
|
+
typeof draft.audience === 'string' ? draft.audience.slice(0, MAX_AUDIENCE) : '',
|
|
62
|
+
);
|
|
63
|
+
const [templateId, setTemplateId] = useState<string | null>(() => {
|
|
64
|
+
if (templateParam) return templateParam;
|
|
65
|
+
return typeof draft.template === 'string' ? draft.template : null;
|
|
66
|
+
});
|
|
74
67
|
const [files, setFiles] = useState<DraftFile[]>([]);
|
|
75
68
|
const [uploaded, setUploaded] = useState<string[]>([]);
|
|
76
69
|
const [busy, setBusy] = useState(false);
|
|
77
70
|
const input = useRef<HTMLInputElement>(null);
|
|
78
71
|
const replacing = useRef<string | null>(null);
|
|
72
|
+
const appliedTemplate = useRef<string | null>(null);
|
|
73
|
+
|
|
74
|
+
const template = library?.templates.find((entry) => entry.id === templateId) ?? null;
|
|
75
|
+
const occasions = library?.occasions ?? OCCASIONS;
|
|
76
|
+
const occasionPickersShown = library?.available === true;
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
writeDraft({ brief, pages, occasion, audience, template: templateId });
|
|
80
|
+
}, [brief, pages, occasion, audience, templateId]);
|
|
79
81
|
|
|
80
82
|
useEffect(() => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
if (!templateParam || !template || appliedTemplate.current === templateParam) return;
|
|
84
|
+
appliedTemplate.current = templateParam;
|
|
85
|
+
setTemplateId(template.id);
|
|
86
|
+
setOccasion(template.occasions[0] ?? null);
|
|
87
|
+
}, [templateParam, template]);
|
|
83
88
|
|
|
84
89
|
useEffect(() => {
|
|
85
90
|
if (!deckId) return;
|
|
@@ -151,6 +156,11 @@ export function DescribePage() {
|
|
|
151
156
|
lastTurn: null,
|
|
152
157
|
prefs: readPrefs(localStorage),
|
|
153
158
|
decisions: [],
|
|
159
|
+
occasion,
|
|
160
|
+
audience: audience.trim(),
|
|
161
|
+
templatePrompt: '',
|
|
162
|
+
templateSkeletons: [],
|
|
163
|
+
templateId,
|
|
154
164
|
};
|
|
155
165
|
const started = await fetch('/__lr/outline/start', {
|
|
156
166
|
method: 'POST',
|
|
@@ -161,13 +171,25 @@ export function DescribePage() {
|
|
|
161
171
|
pages,
|
|
162
172
|
files: names,
|
|
163
173
|
prefs: outline.prefs,
|
|
174
|
+
occasion: outline.occasion,
|
|
175
|
+
audience: outline.audience,
|
|
176
|
+
template: templateId,
|
|
164
177
|
}),
|
|
165
178
|
});
|
|
166
179
|
if (!started.ok) throw new Error('start failed');
|
|
180
|
+
// The server reads the occasion's audience and page order from the library.
|
|
181
|
+
const extra = ((await started.json().catch(() => null)) as { prompt?: unknown } | null)
|
|
182
|
+
?.prompt;
|
|
167
183
|
|
|
168
184
|
const session = await createSession(provider.id, slideId);
|
|
169
185
|
setActiveSession(session.id);
|
|
170
|
-
|
|
186
|
+
const prompt = [
|
|
187
|
+
outlinePrompt(outline, slideId, locale.id),
|
|
188
|
+
typeof extra === 'string' ? extra : '',
|
|
189
|
+
]
|
|
190
|
+
.filter((line) => line.trim() !== '')
|
|
191
|
+
.join('\n');
|
|
192
|
+
await sendMessage(session.id, prompt, { slideId });
|
|
171
193
|
window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}/outline`);
|
|
172
194
|
} catch {
|
|
173
195
|
toast.error(lr.outline.startFailed);
|
|
@@ -179,6 +201,22 @@ export function DescribePage() {
|
|
|
179
201
|
<div data-lr-new className="max-w-[760px]">
|
|
180
202
|
<Steps current={1} />
|
|
181
203
|
|
|
204
|
+
{template && (
|
|
205
|
+
<div data-lr-selected-template={template.id} className="mt-5 flex items-center gap-2">
|
|
206
|
+
<span className="inline-flex items-center gap-1 rounded-full border border-border bg-[var(--lr-accent-soft)] py-0.5 pr-1 pl-3 text-[13px] font-medium">
|
|
207
|
+
{format(lr.outline.selectedTemplate, { name: template.name })}
|
|
208
|
+
<button
|
|
209
|
+
type="button"
|
|
210
|
+
aria-label={lr.outline.removeTemplate}
|
|
211
|
+
onClick={() => setTemplateId(null)}
|
|
212
|
+
className="rounded-full px-1 text-[15px] leading-none text-muted-foreground hover:text-foreground"
|
|
213
|
+
>
|
|
214
|
+
×
|
|
215
|
+
</button>
|
|
216
|
+
</span>
|
|
217
|
+
</div>
|
|
218
|
+
)}
|
|
219
|
+
|
|
182
220
|
<header className="mt-6 mb-5">
|
|
183
221
|
<h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
|
|
184
222
|
{lr.outline.describeTitle}
|
|
@@ -195,6 +233,69 @@ export function DescribePage() {
|
|
|
195
233
|
className="min-h-[88px] resize-none text-[15px]"
|
|
196
234
|
/>
|
|
197
235
|
|
|
236
|
+
{occasionPickersShown && (
|
|
237
|
+
<div className="mt-5">
|
|
238
|
+
<p className="text-[13px] font-semibold">{lr.outline.occasionLabel}</p>
|
|
239
|
+
<div
|
|
240
|
+
role="radiogroup"
|
|
241
|
+
aria-label={lr.outline.occasionLabel}
|
|
242
|
+
data-lr-occasions
|
|
243
|
+
className="mt-2 flex flex-wrap gap-2"
|
|
244
|
+
>
|
|
245
|
+
{occasions.map((entry) => (
|
|
246
|
+
// biome-ignore lint/a11y/useSemanticElements: a row of pills, as with the page count
|
|
247
|
+
<button
|
|
248
|
+
key={entry.id}
|
|
249
|
+
type="button"
|
|
250
|
+
role="radio"
|
|
251
|
+
aria-checked={occasion === entry.id}
|
|
252
|
+
onClick={() => setOccasion(entry.id)}
|
|
253
|
+
className={cn(
|
|
254
|
+
'h-8 rounded-full border px-3.5 text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
255
|
+
occasion === entry.id
|
|
256
|
+
? 'border-[var(--lr-focus)] bg-[var(--lr-accent-soft)] text-foreground'
|
|
257
|
+
: 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
|
|
258
|
+
)}
|
|
259
|
+
>
|
|
260
|
+
{entry.name}
|
|
261
|
+
</button>
|
|
262
|
+
))}
|
|
263
|
+
{/* biome-ignore lint/a11y/useSemanticElements: a row of pills, as with the page count */}
|
|
264
|
+
<button
|
|
265
|
+
type="button"
|
|
266
|
+
role="radio"
|
|
267
|
+
aria-checked={occasion === null}
|
|
268
|
+
onClick={() => setOccasion(null)}
|
|
269
|
+
className={cn(
|
|
270
|
+
'h-8 rounded-full border px-3.5 text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
271
|
+
occasion === null
|
|
272
|
+
? 'border-[var(--lr-focus)] bg-[var(--lr-accent-soft)] text-foreground'
|
|
273
|
+
: 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
|
|
274
|
+
)}
|
|
275
|
+
>
|
|
276
|
+
{lr.outline.unsure}
|
|
277
|
+
</button>
|
|
278
|
+
</div>
|
|
279
|
+
</div>
|
|
280
|
+
)}
|
|
281
|
+
|
|
282
|
+
{occasionPickersShown && (
|
|
283
|
+
<div className="mt-5">
|
|
284
|
+
<label className="text-[13px] font-semibold" htmlFor="lr-audience">
|
|
285
|
+
{lr.outline.audienceLabel}
|
|
286
|
+
</label>
|
|
287
|
+
<input
|
|
288
|
+
id="lr-audience"
|
|
289
|
+
type="text"
|
|
290
|
+
value={audience}
|
|
291
|
+
maxLength={MAX_AUDIENCE}
|
|
292
|
+
onChange={(event) => setAudience(event.target.value.slice(0, MAX_AUDIENCE))}
|
|
293
|
+
placeholder={lr.outline.audiencePlaceholder}
|
|
294
|
+
className="mt-2 h-9 w-full rounded-[6px] border border-border bg-card px-3 text-[14px] outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
295
|
+
/>
|
|
296
|
+
</div>
|
|
297
|
+
)}
|
|
298
|
+
|
|
198
299
|
<div className="mt-5">
|
|
199
300
|
<p className="text-[13px] font-semibold">{lr.outline.pagesLabel}</p>
|
|
200
301
|
<div role="radiogroup" aria-label={lr.outline.pagesLabel} className="mt-2 flex gap-2">
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const DRAFT_KEY = 'lemonriver:new-deck-draft';
|
|
2
|
+
|
|
3
|
+
export type StoredDraft = {
|
|
4
|
+
brief?: unknown;
|
|
5
|
+
pages?: unknown;
|
|
6
|
+
occasion?: unknown;
|
|
7
|
+
audience?: unknown;
|
|
8
|
+
template?: unknown;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function readDraft(): StoredDraft {
|
|
12
|
+
try {
|
|
13
|
+
const raw = sessionStorage.getItem(DRAFT_KEY);
|
|
14
|
+
if (!raw) return {};
|
|
15
|
+
const parsed: unknown = JSON.parse(raw);
|
|
16
|
+
return parsed && typeof parsed === 'object' ? (parsed as StoredDraft) : {};
|
|
17
|
+
} catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function writeDraft(draft: {
|
|
23
|
+
brief: string;
|
|
24
|
+
pages: number;
|
|
25
|
+
occasion: string | null;
|
|
26
|
+
audience: string;
|
|
27
|
+
template: string | null;
|
|
28
|
+
}): void {
|
|
29
|
+
try {
|
|
30
|
+
sessionStorage.setItem(DRAFT_KEY, JSON.stringify(draft));
|
|
31
|
+
} catch {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The template the user came in with from the library, if they picked one. */
|
|
35
|
+
export function draftTemplateId(): string | null {
|
|
36
|
+
const { template } = readDraft();
|
|
37
|
+
return typeof template === 'string' && template !== '' ? template : null;
|
|
38
|
+
}
|
|
@@ -51,6 +51,11 @@ const outline: Outline = {
|
|
|
51
51
|
lastTurn: null,
|
|
52
52
|
prefs: DEFAULT_PREFS,
|
|
53
53
|
decisions: [],
|
|
54
|
+
occasion: 'report',
|
|
55
|
+
audience: '董事会成员',
|
|
56
|
+
templatePrompt: '',
|
|
57
|
+
templateSkeletons: [],
|
|
58
|
+
templateId: null,
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
describe('sanitizeOutline', () => {
|
|
@@ -58,6 +63,23 @@ describe('sanitizeOutline', () => {
|
|
|
58
63
|
expect(sanitizeOutline(outline)).toEqual(outline);
|
|
59
64
|
});
|
|
60
65
|
|
|
66
|
+
it('keeps the occasion and audience, and drops ones it cannot use', () => {
|
|
67
|
+
expect(sanitizeOutline(outline)).toMatchObject({ occasion: 'report', audience: '董事会成员' });
|
|
68
|
+
expect(sanitizeOutline({ ...outline, occasion: 'nope', audience: 7 })).toMatchObject({
|
|
69
|
+
occasion: null,
|
|
70
|
+
audience: '',
|
|
71
|
+
});
|
|
72
|
+
expect(sanitizeOutline({ ...outline, audience: ` ${'字'.repeat(80)} ` })?.audience).toBe(
|
|
73
|
+
'字'.repeat(40),
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('reads a record written before the occasion fields existed', () => {
|
|
78
|
+
expect(sanitizeOutline({ ...outline, occasion: undefined, audience: undefined })).toMatchObject(
|
|
79
|
+
{ occasion: null, audience: '' },
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
61
83
|
it('fills the build fields on a record written before they existed', () => {
|
|
62
84
|
const old = {
|
|
63
85
|
state: 'building',
|
|
@@ -313,6 +335,63 @@ describe('prompts', () => {
|
|
|
313
335
|
});
|
|
314
336
|
});
|
|
315
337
|
|
|
338
|
+
describe('template prompts', () => {
|
|
339
|
+
const applied: Outline = {
|
|
340
|
+
...outline,
|
|
341
|
+
templatePrompt: 'This deck uses the "Board" template.',
|
|
342
|
+
templateSkeletons: ['cover', 'overview', 'figure', 'cards', 'compare', 'ask', 'end'],
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
it('puts the template instructions first on page one', () => {
|
|
346
|
+
const text = pagePrompt(applied, 'deck-1', 1);
|
|
347
|
+
expect(text.startsWith('This deck uses the "Board" template.')).toBe(true);
|
|
348
|
+
expect(text).toContain('Build slides/deck-1/index.tsx');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('suggests a skeleton per page from the ones the template has', () => {
|
|
352
|
+
const text = pagePrompt(applied, 'deck-1', 1);
|
|
353
|
+
expect(text).toContain('1. [cover] Cover → cover');
|
|
354
|
+
expect(text).toContain('2. [list] Why now → cards');
|
|
355
|
+
expect(text).toContain('3. [kpi] Numbers → overview');
|
|
356
|
+
expect(text).toContain('4. [end] End → end');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('leaves a page kind alone when the template has no skeleton for it', () => {
|
|
360
|
+
const partial: Outline = { ...outline, templateSkeletons: ['cover', 'end'] };
|
|
361
|
+
const text = pagePrompt(partial, 'deck-1', 1);
|
|
362
|
+
expect(text).toContain('2. [list] Why now\n');
|
|
363
|
+
expect(text).toContain('3. [kpi] Numbers\n');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('tells later pages to keep the template and its guide', () => {
|
|
367
|
+
const text = pagePrompt(applied, 'deck-1', 3);
|
|
368
|
+
expect(text.split('\n')[0]).toBe(
|
|
369
|
+
'Page 3 of 4: [kpi] Numbers → overview. Write only this page; leave the others as they are.',
|
|
370
|
+
);
|
|
371
|
+
expect(text).toContain('Keep using the template in ./kit/');
|
|
372
|
+
expect(text).toContain('kit/docs/GUIDE.md');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('adds the quality checklist to the review pass', () => {
|
|
376
|
+
const withTemplate = reviewPrompt(applied, 'deck-1');
|
|
377
|
+
expect(withTemplate).toContain('kit/docs/质量清单.md');
|
|
378
|
+
expect(withTemplate).toContain('take a screenshot of every page');
|
|
379
|
+
const plain = reviewPrompt(outline, 'deck-1');
|
|
380
|
+
expect(plain).not.toContain('质量清单');
|
|
381
|
+
expect(plain).toContain('pre-delivery checklist at the end of the slide-authoring skill');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('reads only the skeletons the model knows', () => {
|
|
385
|
+
const read = sanitizeOutline({
|
|
386
|
+
...outline,
|
|
387
|
+
templatePrompt: 'x',
|
|
388
|
+
templateSkeletons: ['cover', 'nope', 3, 'cover', 'end'],
|
|
389
|
+
});
|
|
390
|
+
expect(read?.templateSkeletons).toEqual(['cover', 'end']);
|
|
391
|
+
expect(read?.templatePrompt).toBe('x');
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
316
395
|
const building = (patch: Partial<Outline> = {}): Outline => ({
|
|
317
396
|
...outline,
|
|
318
397
|
state: 'building',
|