@lemonriver/core 0.2.0 → 0.4.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.
Files changed (160) hide show
  1. package/dist/{build-Df_xwIpg.js → build-Nl7EeJ6x.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-rMGCkz6i.d.ts → config-CYNOR93W.d.ts} +1 -1
  4. package/dist/{config-BjWCLoMQ.js → config-CpC0nM3r.js} +3152 -1837
  5. package/dist/{dev-Ctsx9IeO.js → dev-BB3THd5I.js} +2 -2
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +1 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-CJgcqsPk.js → preview-BGjgTg7H.js} +1 -1
  11. package/dist/{types-8VUyA2bu.d.ts → types-tdaXSyah.d.ts} +1 -35
  12. package/dist/{update-BKOA3Z6o.js → update-DsxZBtwv.js} +2 -70
  13. package/dist/vite/index.d.ts +1 -1
  14. package/dist/vite/index.js +1 -1
  15. package/dist/{zh-tw-CeLrYwRE.js → zh-tw-DcrDeKxr.js} +11 -172
  16. package/package.json +1 -1
  17. package/src/agent/prompt.ts +2 -0
  18. package/src/app/app.tsx +5 -18
  19. package/src/app/components/agent/agent-panel.tsx +5 -0
  20. package/src/app/components/agent/agent-presence.tsx +2 -2
  21. package/src/app/components/agent/history-view.tsx +3 -2
  22. package/src/app/components/agent/transcript.tsx +15 -4
  23. package/src/app/components/asset-view.tsx +6 -6
  24. package/src/app/components/command/command-menu.tsx +2 -1
  25. package/src/app/components/inspector/asset-picker-dialog.tsx +7 -5
  26. package/src/app/components/inspector/comment-layer.tsx +2 -1
  27. package/src/app/components/inspector/inspector-panel.tsx +2 -2
  28. package/src/app/components/player.tsx +105 -23
  29. package/src/app/components/present/curtain.tsx +52 -0
  30. package/src/app/components/present/last-slide-hint.tsx +36 -0
  31. package/src/app/components/sidebar/sidebar-footer.tsx +7 -2
  32. package/src/app/components/sidebar/sidebar.tsx +3 -2
  33. package/src/app/components/themes/theme-detail.tsx +4 -2
  34. package/src/app/components/thumbnail-rail.tsx +2 -28
  35. package/src/app/index.html +2 -2
  36. package/src/app/lemonriver/agent/lemon.tsx +79 -0
  37. package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
  38. package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
  39. package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
  40. package/src/app/{components → lemonriver}/board/board-canvas.tsx +17 -17
  41. package/src/app/{routes/board.tsx → lemonriver/board/board-page.tsx} +16 -15
  42. package/src/app/{components → lemonriver}/board/layout.ts +1 -1
  43. package/src/app/lemonriver/board/model/cards.test.ts +239 -0
  44. package/src/app/lemonriver/board/model/cards.ts +234 -0
  45. package/src/app/lemonriver/board/model/structure.test.ts +101 -0
  46. package/src/app/lemonriver/board/model/structure.ts +82 -0
  47. package/src/app/{components → lemonriver}/board/page-node.tsx +34 -31
  48. package/src/app/{components → lemonriver}/board/use-board-cards.ts +6 -6
  49. package/src/app/{components → lemonriver}/board/use-board-columns.ts +7 -7
  50. package/src/app/{components → lemonriver}/board/use-page-order.ts +10 -6
  51. package/src/app/lemonriver/brand/app-icon.svg +44 -0
  52. package/src/app/lemonriver/brand/apple-touch-icon.png +0 -0
  53. package/src/app/lemonriver/brand/favicon-32.png +0 -0
  54. package/src/app/lemonriver/brand/mascot.tsx +145 -0
  55. package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
  56. package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
  57. package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
  58. package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
  59. package/src/app/lemonriver/brand/mascots/lemon-done.png +0 -0
  60. package/src/app/lemonriver/brand/mascots/lemon-idle.png +0 -0
  61. package/src/app/lemonriver/brand/mascots/lemon-needs-you.png +0 -0
  62. package/src/app/lemonriver/brand/mascots/lemon-thinking.png +0 -0
  63. package/src/app/lemonriver/brand/mascots/lemon-working.png +0 -0
  64. package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
  65. package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
  66. package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
  67. package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
  68. package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
  69. package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
  70. package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
  71. package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
  72. package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
  73. package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
  74. package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
  75. package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
  76. package/src/app/lemonriver/chrome/app-chrome.tsx +101 -0
  77. package/src/app/lemonriver/chrome/nav-row.tsx +34 -0
  78. package/src/app/lemonriver/chrome/not-found.tsx +34 -0
  79. package/src/app/lemonriver/chrome/sidebar-extras.tsx +57 -0
  80. package/src/app/lemonriver/chrome/use-slot.ts +23 -0
  81. package/src/app/lemonriver/features.test.ts +34 -0
  82. package/src/app/lemonriver/features.ts +27 -0
  83. package/src/app/lemonriver/feedback/export.ts +7 -0
  84. package/src/app/lemonriver/feedback/lemon-empty.tsx +54 -0
  85. package/src/app/lemonriver/feedback/offline-banner.tsx +41 -0
  86. package/src/app/lemonriver/feedback/pending-toast.test.ts +44 -0
  87. package/src/app/lemonriver/feedback/pending-toast.ts +39 -0
  88. package/src/app/lemonriver/feedback/toaster.tsx +34 -0
  89. package/src/app/lemonriver/feedback/upload.test.ts +26 -0
  90. package/src/app/lemonriver/feedback/upload.ts +19 -0
  91. package/src/app/lemonriver/home/brief-card.tsx +70 -0
  92. package/src/app/lemonriver/home/brief.test.ts +38 -0
  93. package/src/app/lemonriver/home/brief.ts +34 -0
  94. package/src/app/lemonriver/home/controls.tsx +93 -0
  95. package/src/app/lemonriver/home/deck-card.tsx +183 -0
  96. package/src/app/lemonriver/home/dialogs.tsx +292 -0
  97. package/src/app/lemonriver/home/home-page.tsx +339 -0
  98. package/src/app/lemonriver/home/sorting.test.ts +24 -0
  99. package/src/app/lemonriver/home/sorting.ts +59 -0
  100. package/src/app/lemonriver/home/time.test.ts +33 -0
  101. package/src/app/lemonriver/home/time.ts +33 -0
  102. package/src/app/lemonriver/home/use-deck-times.ts +27 -0
  103. package/src/app/lemonriver/home/use-delayed.ts +15 -0
  104. package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
  105. package/src/app/lemonriver/outline/build-team.tsx +278 -0
  106. package/src/app/lemonriver/outline/describe-page.tsx +380 -0
  107. package/src/app/lemonriver/outline/files.test.ts +90 -0
  108. package/src/app/lemonriver/outline/files.ts +69 -0
  109. package/src/app/lemonriver/outline/model.test.ts +633 -0
  110. package/src/app/lemonriver/outline/model.ts +443 -0
  111. package/src/app/lemonriver/outline/outline-page.tsx +504 -0
  112. package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
  113. package/src/app/lemonriver/outline/rule.ts +3 -0
  114. package/src/app/lemonriver/outline/steps.tsx +43 -0
  115. package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
  116. package/src/app/lemonriver/routes.test.tsx +37 -0
  117. package/src/app/lemonriver/routes.tsx +66 -0
  118. package/src/app/lemonriver/settings/settings-page.tsx +314 -0
  119. package/src/app/lemonriver/slide-extensions.tsx +80 -0
  120. package/src/app/lemonriver/text/all.ts +19 -0
  121. package/src/app/lemonriver/text/en.ts +255 -0
  122. package/src/app/lemonriver/text/es.ts +256 -0
  123. package/src/app/lemonriver/text/index.ts +9 -0
  124. package/src/app/lemonriver/text/ja.ts +256 -0
  125. package/src/app/lemonriver/text/text.test.ts +90 -0
  126. package/src/app/lemonriver/text/types.ts +280 -0
  127. package/src/app/lemonriver/text/zh-cn.ts +247 -0
  128. package/src/app/lemonriver/text/zh-tw.ts +247 -0
  129. package/src/app/lemonriver/theme/app.css +299 -0
  130. package/src/app/lemonriver/theme/controls.css +463 -0
  131. package/src/app/lemonriver/theme/index.css +3 -0
  132. package/src/app/lemonriver/theme/motion.ts +52 -0
  133. package/src/app/lemonriver/theme/pages.test.ts +70 -0
  134. package/src/app/lemonriver/theme/pages.ts +65 -0
  135. package/src/app/lemonriver/theme/theme-menu.tsx +64 -0
  136. package/src/app/lemonriver/theme/themes.test.ts +18 -0
  137. package/src/app/lemonriver/theme/themes.ts +16 -0
  138. package/src/app/lemonriver/theme/tokens.css +226 -0
  139. package/src/app/lemonriver/theme/use-theme.tsx +49 -0
  140. package/src/app/lemonriver/trash/api.test.ts +19 -0
  141. package/src/app/lemonriver/trash/api.ts +77 -0
  142. package/src/app/lemonriver/trash/trash-page.tsx +131 -0
  143. package/src/app/lemonriver/update/beta-badge.tsx +26 -0
  144. package/src/app/lemonriver/update/prompt.test.ts +84 -0
  145. package/src/app/lemonriver/update/prompt.ts +48 -0
  146. package/src/app/lemonriver/update/update-prompt.tsx +113 -0
  147. package/src/app/lib/pptx/raster.ts +1 -1
  148. package/src/app/main.tsx +8 -1
  149. package/src/app/routes/home-shell.tsx +4 -2
  150. package/src/app/routes/home.tsx +13 -5
  151. package/src/app/routes/slide.tsx +81 -28
  152. package/src/app/styles.css +1 -0
  153. package/src/locale/en.ts +1 -35
  154. package/src/locale/es.ts +1 -34
  155. package/src/locale/ja.ts +1 -34
  156. package/src/locale/types.ts +1 -36
  157. package/src/locale/zh-cn.ts +4 -37
  158. package/src/locale/zh-tw.ts +4 -37
  159. /package/src/app/{components → lemonriver}/board/board.css +0 -0
  160. /package/src/app/{components → lemonriver}/board/layout.test.ts +0 -0
@@ -0,0 +1,258 @@
1
+ import { useCallback, useEffect, useSyncExternalStore } from 'react';
2
+ import {
3
+ createSession,
4
+ sendMessage,
5
+ setActiveSession,
6
+ useAgentSession,
7
+ useAgentSessions,
8
+ useAgentStatus,
9
+ } from '@/lib/agent/use-agent';
10
+ import type { AgentProviderId, AgentSession, AgentSessionSummary } from '../../../agent/types';
11
+ import { type DriverAction, driverAction, type Outline } from './model';
12
+
13
+ const POLL_BUILD_MS = 2000;
14
+ const POLL_IDLE_MS = 10_000;
15
+
16
+ type Snapshot = {
17
+ slideId: string | null;
18
+ outline: Outline | null | undefined;
19
+ running: boolean;
20
+ waitingForAnswer: boolean;
21
+ action: DriverAction;
22
+ };
23
+
24
+ type AgentView = {
25
+ sessions: AgentSessionSummary[];
26
+ active: AgentSession | null;
27
+ providerId: AgentProviderId | null;
28
+ connected: boolean;
29
+ };
30
+
31
+ let view: Snapshot = {
32
+ slideId: null,
33
+ outline: undefined,
34
+ running: false,
35
+ waitingForAnswer: false,
36
+ action: 'idle',
37
+ };
38
+ let agent: AgentView = { sessions: [], active: null, providerId: null, connected: false };
39
+ let timer: number | null = null;
40
+ let subscribers = 0;
41
+ let sending = false;
42
+
43
+ const listeners = new Set<() => void>();
44
+
45
+ function notify() {
46
+ for (const listener of listeners) listener();
47
+ }
48
+
49
+ function subscribe(listener: () => void): () => void {
50
+ listeners.add(listener);
51
+ return () => {
52
+ listeners.delete(listener);
53
+ };
54
+ }
55
+
56
+ function getSnapshot(): Snapshot {
57
+ return view;
58
+ }
59
+
60
+ /** The outline the team panel is following; the confirmation card reads it too. */
61
+ export function useBuildOutline(): Outline | null | undefined {
62
+ return useSyncExternalStore(
63
+ subscribe,
64
+ () => view.outline,
65
+ () => undefined,
66
+ );
67
+ }
68
+
69
+ function currentAction(now: number): DriverAction {
70
+ if (!view.outline) return 'idle';
71
+ const action = driverAction(view.outline, { running: view.running, now });
72
+ return action === 'send' && !agent.connected ? 'interrupted' : action;
73
+ }
74
+
75
+ function recompute() {
76
+ const action = currentAction(Date.now());
77
+ if (action === view.action) return;
78
+ view = { ...view, action };
79
+ notify();
80
+ }
81
+
82
+ async function sendPrompt(slideId: string, text: string): Promise<void> {
83
+ const existing = agent.sessions.find((session) => session.slideId === slideId);
84
+ if (existing) {
85
+ setActiveSession(existing.id);
86
+ await sendMessage(existing.id, text, { slideId });
87
+ return;
88
+ }
89
+ if (!agent.providerId) throw new Error('no agent');
90
+ const created = await createSession(agent.providerId, slideId);
91
+ await sendMessage(created.id, text, { slideId });
92
+ }
93
+
94
+ async function dispatch(slideId: string, resume: boolean): Promise<void> {
95
+ if (sending || !agent.connected) return;
96
+ sending = true;
97
+ try {
98
+ const res = await fetch('/__lr/outline/next', {
99
+ method: 'POST',
100
+ headers: { 'content-type': 'application/json' },
101
+ body: JSON.stringify({ slideId, resume }),
102
+ });
103
+ if (!res.ok) return;
104
+ const { prompt } = (await res.json()) as { prompt: string };
105
+ await sendPrompt(slideId, prompt);
106
+ await refresh(slideId);
107
+ } catch {
108
+ } finally {
109
+ sending = false;
110
+ }
111
+ }
112
+
113
+ function schedule() {
114
+ if (timer !== null || view.slideId === null) return;
115
+ const delay = view.outline?.state === 'building' ? POLL_BUILD_MS : POLL_IDLE_MS;
116
+ timer = window.setTimeout(() => {
117
+ timer = null;
118
+ const slideId = view.slideId;
119
+ if (slideId) void tick(slideId);
120
+ }, delay);
121
+ }
122
+
123
+ async function tick(slideId: string): Promise<void> {
124
+ await refresh(slideId);
125
+ schedule();
126
+ }
127
+
128
+ async function refresh(slideId: string): Promise<void> {
129
+ try {
130
+ const res = await fetch(`/__lr/outline?slideId=${encodeURIComponent(slideId)}`);
131
+ if (!res.ok) return;
132
+ const body = (await res.json()) as { outline: Outline | null };
133
+ if (view.slideId !== slideId) return;
134
+ view = { ...view, outline: body.outline };
135
+ const action = currentAction(Date.now());
136
+ const changed = action !== view.action;
137
+ view = { ...view, action };
138
+ if (changed) notify();
139
+ if (action === 'send') void dispatch(slideId, false);
140
+ } catch {}
141
+ }
142
+
143
+ function attach(slideId: string) {
144
+ subscribers += 1;
145
+ if (view.slideId !== slideId) {
146
+ if (timer !== null) {
147
+ window.clearTimeout(timer);
148
+ timer = null;
149
+ }
150
+ view = {
151
+ slideId,
152
+ outline: undefined,
153
+ running: false,
154
+ waitingForAnswer: false,
155
+ action: 'idle',
156
+ };
157
+ notify();
158
+ void refresh(slideId);
159
+ }
160
+ schedule();
161
+ }
162
+
163
+ function detach() {
164
+ subscribers = Math.max(subscribers - 1, 0);
165
+ if (subscribers > 0) return;
166
+ if (timer !== null) {
167
+ window.clearTimeout(timer);
168
+ timer = null;
169
+ }
170
+ view = { ...view, slideId: null };
171
+ }
172
+
173
+ function syncAgent(input: AgentView & { running: boolean; waitingForAnswer: boolean }) {
174
+ agent = {
175
+ sessions: input.sessions,
176
+ active: input.active,
177
+ providerId: input.providerId,
178
+ connected: input.connected,
179
+ };
180
+ if (view.running !== input.running || view.waitingForAnswer !== input.waitingForAnswer) {
181
+ view = { ...view, running: input.running, waitingForAnswer: input.waitingForAnswer };
182
+ notify();
183
+ }
184
+ recompute();
185
+ if (view.action === 'send' && view.slideId) void dispatch(view.slideId, false);
186
+ }
187
+
188
+ async function post(path: string, slideId: string, body: Record<string, unknown> = {}) {
189
+ try {
190
+ return await fetch(path, {
191
+ method: 'POST',
192
+ headers: { 'content-type': 'application/json' },
193
+ body: JSON.stringify({ slideId, ...body }),
194
+ });
195
+ } catch {
196
+ return null;
197
+ }
198
+ }
199
+
200
+ function lastIsPendingQuestion(session: AgentSession | null): boolean {
201
+ const last = session?.items.at(-1);
202
+ return last?.kind === 'question' && last.status === 'pending';
203
+ }
204
+
205
+ export function useBuildDriver(slideId: string) {
206
+ const { sessions, activeId } = useAgentSessions();
207
+ const active = useAgentSession(activeId);
208
+ const { connected, provider } = useAgentStatus();
209
+
210
+ const running = sessions.some(
211
+ (session) => session.slideId === slideId && session.status === 'running',
212
+ );
213
+ const waitingForAnswer = active?.slideId === slideId && lastIsPendingQuestion(active);
214
+
215
+ const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
216
+
217
+ useEffect(() => {
218
+ attach(slideId);
219
+ return detach;
220
+ }, [slideId]);
221
+
222
+ useEffect(() => {
223
+ syncAgent({
224
+ sessions,
225
+ active,
226
+ providerId: provider?.id ?? null,
227
+ connected,
228
+ running,
229
+ waitingForAnswer,
230
+ });
231
+ }, [sessions, active, provider, connected, running, waitingForAnswer]);
232
+
233
+ const pause = useCallback(async () => {
234
+ const res = await post('/__lr/outline/pause', slideId, { paused: true });
235
+ if (res?.ok) await refresh(slideId);
236
+ }, [slideId]);
237
+
238
+ const resume = useCallback(async () => {
239
+ await post('/__lr/outline/pause', slideId, { paused: false });
240
+ await dispatch(slideId, true);
241
+ }, [slideId]);
242
+
243
+ const undo = useCallback(async () => {
244
+ const res = await post('/__lr/outline/undo', slideId);
245
+ return res?.ok ?? false;
246
+ }, [slideId]);
247
+
248
+ return {
249
+ outline: snapshot.slideId === slideId ? snapshot.outline : undefined,
250
+ action: snapshot.slideId === slideId ? snapshot.action : ('idle' as DriverAction),
251
+ running: snapshot.running,
252
+ waitingForAnswer: snapshot.waitingForAnswer,
253
+ connected,
254
+ pause,
255
+ resume,
256
+ undo,
257
+ };
258
+ }
@@ -0,0 +1,37 @@
1
+ import type { ReactElement } from 'react';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+
4
+ vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
5
+ vi.mock('./chrome/not-found', () => ({ NotFound: () => null }));
6
+ vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
7
+ vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
8
+ vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
9
+
10
+ import { isFeatureEnabled } from './features';
11
+ import { lemonRiverRoutes, lemonRiverShellRoutes } from './routes';
12
+
13
+ const paths = (routes: unknown[]) =>
14
+ routes.filter(Boolean).map((r) => (r as ReactElement<{ path: string }>).props.path);
15
+
16
+ describe('lemonRiverRoutes', () => {
17
+ it('adds the board, the outline and the not-found page', () => {
18
+ expect(paths(lemonRiverRoutes())).toEqual(['/s/:slideId/board', '/s/:slideId/outline', '*']);
19
+ });
20
+
21
+ it('drops the pages whose feature is off', () => {
22
+ vi.mocked(isFeatureEnabled).mockReturnValue(false);
23
+ expect(paths(lemonRiverRoutes())).toEqual(['*']);
24
+ vi.mocked(isFeatureEnabled).mockReturnValue(true);
25
+ });
26
+ });
27
+
28
+ describe('lemonRiverShellRoutes', () => {
29
+ it('puts our home and the guided flow first, then settings and trash', () => {
30
+ expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings', '/trash']);
31
+ });
32
+
33
+ it('leaves out the pages whose feature is off', () => {
34
+ vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash');
35
+ expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
36
+ });
37
+ });
@@ -0,0 +1,66 @@
1
+ import { lazy, Suspense } from 'react';
2
+ import { Route } from 'react-router-dom';
3
+ import { NotFound } from './chrome/not-found';
4
+ import { isFeatureEnabled } from './features';
5
+ import { LemonRiverHome } from './home/home-page';
6
+ import { SettingsPage } from './settings/settings-page';
7
+ import { TrashPage } from './trash/trash-page';
8
+
9
+ const BoardPage = lazy(() => import('./board/board-page').then((m) => ({ default: m.Board })));
10
+ const DescribePage = lazy(() =>
11
+ import('./outline/describe-page').then((m) => ({ default: m.DescribePage })),
12
+ );
13
+ const OutlinePage = lazy(() =>
14
+ import('./outline/outline-page').then((m) => ({ default: m.OutlineView })),
15
+ );
16
+
17
+ /** Routes of our own, outside the home shell. Placed before the official catch-all. */
18
+ export function lemonRiverRoutes() {
19
+ return [
20
+ isFeatureEnabled('board') && (
21
+ <Route
22
+ key="board"
23
+ path="/s/:slideId/board"
24
+ element={
25
+ <Suspense fallback={null}>
26
+ <BoardPage />
27
+ </Suspense>
28
+ }
29
+ />
30
+ ),
31
+ isFeatureEnabled('outline') && (
32
+ <Route
33
+ key="outline"
34
+ path="/s/:slideId/outline"
35
+ element={
36
+ <Suspense fallback={null}>
37
+ <OutlinePage />
38
+ </Suspense>
39
+ }
40
+ />
41
+ ),
42
+ <Route key="not-found" path="*" element={<NotFound />} />,
43
+ ];
44
+ }
45
+
46
+ /** Pages inside the home shell. Placed before the official home route, which they replace. */
47
+ export function lemonRiverShellRoutes() {
48
+ return [
49
+ <Route key="home" path="/" element={<LemonRiverHome />} />,
50
+ isFeatureEnabled('outline') && (
51
+ <Route
52
+ key="new"
53
+ path="/new"
54
+ element={
55
+ <Suspense fallback={null}>
56
+ <DescribePage />
57
+ </Suspense>
58
+ }
59
+ />
60
+ ),
61
+ isFeatureEnabled('settings') && (
62
+ <Route key="settings" path="/settings" element={<SettingsPage />} />
63
+ ),
64
+ isFeatureEnabled('trash') && <Route key="trash" path="/trash" element={<TrashPage />} />,
65
+ ];
66
+ }
@@ -0,0 +1,314 @@
1
+ import type { ReactNode } from 'react';
2
+ import { useEffect, useState } from 'react';
3
+ import { useNavigate } from 'react-router-dom';
4
+ import { useLocale } from '@/lib/use-locale';
5
+ import { cn } from '@/lib/utils';
6
+ import type { AgentPrefs } from '../agent-prefs/prefs';
7
+ import { updateAgentPrefs, useAgentPrefs } from '../agent-prefs/use-prefs';
8
+ import { HelperMascot, type HelperRole } from '../brand/mascot';
9
+ import { ONBOARDED_KEY } from '../onboarding/onboarding';
10
+ import { useLrText } from '../text';
11
+ import { setReduceMotionSetting, useReduceMotionSetting } from '../theme/motion';
12
+ import { LR_THEME_CHOICES, type LrThemeChoice } from '../theme/themes';
13
+ import { useTheme } from '../theme/use-theme';
14
+
15
+ const SWATCH: Record<LrThemeChoice, { bg: string; fg: string }> = {
16
+ system: { bg: 'linear-gradient(90deg,#fafbf5 50%,#111412 50%)', fg: '#13240f' },
17
+ light: { bg: '#fafbf5', fg: '#13240f' },
18
+ dark: { bg: '#111412', fg: '#eef3ea' },
19
+ lime: { bg: 'linear-gradient(160deg,#eef56a,#9bc929)', fg: '#12300f' },
20
+ };
21
+
22
+ export function SettingsPage() {
23
+ const t = useLocale();
24
+ const lr = useLrText();
25
+ const navigate = useNavigate();
26
+ const prefs = useAgentPrefs();
27
+ const { theme, setTheme } = useTheme();
28
+ const reduceMotion = useReduceMotionSetting();
29
+ const [mounted, setMounted] = useState(false);
30
+
31
+ useEffect(() => {
32
+ setMounted(true);
33
+ }, []);
34
+
35
+ const names: Record<LrThemeChoice, string> = {
36
+ system: t.themeToggle.system,
37
+ light: t.themeToggle.light,
38
+ dark: t.themeToggle.dark,
39
+ lime: lr.theme.lime,
40
+ };
41
+
42
+ function replayOnboarding() {
43
+ try {
44
+ localStorage.removeItem(ONBOARDED_KEY);
45
+ } catch {}
46
+ navigate('/new');
47
+ }
48
+
49
+ const helpers: {
50
+ role: HelperRole;
51
+ label: string;
52
+ value: string;
53
+ apply: (value: string) => void;
54
+ options: { value: string; label: string }[];
55
+ }[] = [
56
+ {
57
+ role: 'research',
58
+ label: lr.build.research,
59
+ value: prefs.research,
60
+ apply: (value) => updateAgentPrefs({ research: value as AgentPrefs['research'] }),
61
+ options: [
62
+ { value: 'uploads', label: lr.prefs.researchUploads },
63
+ { value: 'web', label: lr.prefs.researchWeb },
64
+ ],
65
+ },
66
+ {
67
+ role: 'outline',
68
+ label: lr.build.outline,
69
+ value: prefs.outline,
70
+ apply: (value) => updateAgentPrefs({ outline: value as AgentPrefs['outline'] }),
71
+ options: [
72
+ { value: 'review', label: lr.prefs.outlineReview },
73
+ { value: 'direct', label: lr.prefs.outlineDirect },
74
+ ],
75
+ },
76
+ {
77
+ role: 'design',
78
+ label: lr.build.design,
79
+ value: prefs.design,
80
+ apply: (value) => updateAgentPrefs({ design: value as AgentPrefs['design'] }),
81
+ options: [
82
+ { value: 'visual', label: lr.prefs.designVisual },
83
+ { value: 'balanced', label: lr.prefs.designBalanced },
84
+ { value: 'dense', label: lr.prefs.designDense },
85
+ ],
86
+ },
87
+ {
88
+ role: 'review',
89
+ label: lr.build.review,
90
+ value: prefs.review,
91
+ apply: (value) => updateAgentPrefs({ review: value as AgentPrefs['review'] }),
92
+ options: [
93
+ { value: 'strict', label: lr.prefs.reviewStrict },
94
+ { value: 'numbers', label: lr.prefs.reviewNumbers },
95
+ ],
96
+ },
97
+ ];
98
+
99
+ return (
100
+ <div data-lr-settings className="max-w-[760px]">
101
+ <header className="mb-6">
102
+ <h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
103
+ {lr.settings.title}
104
+ </h1>
105
+ <p className="lr-on-lime mt-0.5 text-[14px] text-muted-foreground">
106
+ {lr.settings.subtitle}
107
+ </p>
108
+ </header>
109
+
110
+ <section className="rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]">
111
+ <h2 className="text-[16px] font-semibold">{lr.settings.appearance}</h2>
112
+ <p className="mt-1 mb-4 text-[14px] text-muted-foreground">{lr.settings.appearanceHint}</p>
113
+ <div
114
+ role="radiogroup"
115
+ aria-label={t.themeToggle.title}
116
+ className="grid grid-cols-2 gap-3 sm:grid-cols-4"
117
+ >
118
+ {LR_THEME_CHOICES.map((choice) => {
119
+ const picked = mounted && theme === choice;
120
+ return (
121
+ // biome-ignore lint/a11y/useSemanticElements: a card-shaped radio, as in the design package
122
+ <button
123
+ key={choice}
124
+ type="button"
125
+ role="radio"
126
+ aria-checked={picked}
127
+ data-lr-theme-card={choice}
128
+ onClick={() => setTheme(choice)}
129
+ className={cn(
130
+ 'rounded-[12px] border-[1.5px] bg-card px-1.5 pt-1.5 pb-2.5 text-[14px] font-medium outline-none',
131
+ 'transition-[border-color,box-shadow] duration-150 focus-visible:ring-2 focus-visible:ring-ring/40',
132
+ picked
133
+ ? 'border-[var(--lr-focus)] shadow-[0_0_0_3px_var(--lr-accent-soft)]'
134
+ : 'border-border hover:border-[var(--lr-text-3)]',
135
+ )}
136
+ >
137
+ <span
138
+ aria-hidden
139
+ className="relative mb-2 block h-16 overflow-hidden rounded-[8px] ring-1 ring-black/5"
140
+ style={{ background: SWATCH[choice].bg, color: SWATCH[choice].fg }}
141
+ >
142
+ <span className="absolute top-[18%] left-[10%] h-[12%] w-[45%] rounded-[4px] bg-current opacity-85" />
143
+ <span className="absolute bottom-[16%] left-[10%] h-[22%] w-[32%] rounded-[6px] bg-[#fcd810]" />
144
+ </span>
145
+ {names[choice]}
146
+ </button>
147
+ );
148
+ })}
149
+ </div>
150
+
151
+ <div className="mt-3 flex items-center gap-4 border-t border-border pt-3">
152
+ <div className="min-w-0 flex-1">
153
+ <p className="text-[14px] font-semibold">{lr.settings.reduceMotion}</p>
154
+ <p className="text-[12px] text-muted-foreground">{lr.settings.reduceMotionHint}</p>
155
+ </div>
156
+ <button
157
+ type="button"
158
+ role="switch"
159
+ aria-checked={reduceMotion}
160
+ aria-label={lr.settings.reduceMotion}
161
+ onClick={() => setReduceMotionSetting(!reduceMotion)}
162
+ className="lr-switch outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
163
+ />
164
+ </div>
165
+ </section>
166
+
167
+ {import.meta.env.DEV && (
168
+ <section
169
+ data-lr-agent-prefs
170
+ className="mt-5 rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]"
171
+ >
172
+ <h2 className="text-[16px] font-semibold">{lr.prefs.title}</h2>
173
+ <p className="mt-1 mb-2 text-[14px] text-muted-foreground">{lr.prefs.hint}</p>
174
+
175
+ <PrefsSwitch
176
+ label={lr.prefs.confirmEachPage}
177
+ hint={lr.prefs.confirmEachPageHint}
178
+ checked={prefs.confirmEachPage}
179
+ onChange={(value) => updateAgentPrefs({ confirmEachPage: value })}
180
+ />
181
+ <PrefsSwitch
182
+ label={lr.prefs.askOnMismatch}
183
+ hint={lr.prefs.askOnMismatchHint}
184
+ checked={prefs.askOnMismatch}
185
+ onChange={(value) => updateAgentPrefs({ askOnMismatch: value })}
186
+ />
187
+ <PrefsSwitch
188
+ label={lr.prefs.autoImages}
189
+ hint={lr.prefs.autoImagesHint}
190
+ checked={prefs.autoImages}
191
+ onChange={(value) => updateAgentPrefs({ autoImages: value })}
192
+ />
193
+
194
+ <div className="mt-4 border-t border-border pt-4">
195
+ <p className="text-[14px] font-semibold">{lr.prefs.tone}</p>
196
+ <div className="mt-2 flex flex-wrap gap-1.5">
197
+ <PrefPill
198
+ pressed={prefs.tone === 'steady'}
199
+ onClick={() => updateAgentPrefs({ tone: 'steady' })}
200
+ >
201
+ {lr.prefs.toneSteady}
202
+ </PrefPill>
203
+ <PrefPill
204
+ pressed={prefs.tone === 'friendly'}
205
+ onClick={() => updateAgentPrefs({ tone: 'friendly' })}
206
+ >
207
+ {lr.prefs.toneFriendly}
208
+ </PrefPill>
209
+ <PrefPill
210
+ pressed={prefs.tone === 'concise'}
211
+ onClick={() => updateAgentPrefs({ tone: 'concise' })}
212
+ >
213
+ {lr.prefs.toneConcise}
214
+ </PrefPill>
215
+ </div>
216
+ </div>
217
+
218
+ <div className="mt-4 grid grid-cols-2 gap-2.5 border-t border-border pt-4 sm:grid-cols-4">
219
+ {helpers.map((helper) => (
220
+ <div
221
+ key={helper.role}
222
+ data-lr-pref-helper={helper.role}
223
+ className="flex flex-col items-center gap-1.5 rounded-[12px] border border-border bg-muted/30 px-2 py-3 text-center"
224
+ >
225
+ <HelperMascot role={helper.role} state="idle" size={32} />
226
+ <span className="text-[12px] font-semibold">{helper.label}</span>
227
+ <div className="flex flex-wrap justify-center gap-1">
228
+ {helper.options.map((option) => (
229
+ <PrefPill
230
+ key={option.value}
231
+ compact
232
+ pressed={helper.value === option.value}
233
+ onClick={() => helper.apply(option.value)}
234
+ >
235
+ {option.label}
236
+ </PrefPill>
237
+ ))}
238
+ </div>
239
+ </div>
240
+ ))}
241
+ </div>
242
+
243
+ <div className="mt-4 border-t border-border pt-3">
244
+ <button
245
+ type="button"
246
+ onClick={replayOnboarding}
247
+ className="rounded text-[13px] text-muted-foreground underline-offset-2 outline-none hover:text-foreground hover:underline focus-visible:ring-2 focus-visible:ring-ring/40"
248
+ >
249
+ {lr.prefs.replayOnboarding}
250
+ </button>
251
+ </div>
252
+ </section>
253
+ )}
254
+ </div>
255
+ );
256
+ }
257
+
258
+ function PrefsSwitch({
259
+ label,
260
+ hint,
261
+ checked,
262
+ onChange,
263
+ }: {
264
+ label: string;
265
+ hint: string;
266
+ checked: boolean;
267
+ onChange: (value: boolean) => void;
268
+ }) {
269
+ return (
270
+ <div className="mt-3 flex items-center gap-4 border-t border-border pt-3">
271
+ <div className="min-w-0 flex-1">
272
+ <p className="text-[14px] font-semibold">{label}</p>
273
+ <p className="text-[12px] text-muted-foreground">{hint}</p>
274
+ </div>
275
+ <button
276
+ type="button"
277
+ role="switch"
278
+ aria-checked={checked}
279
+ aria-label={label}
280
+ onClick={() => onChange(!checked)}
281
+ className="lr-switch outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
282
+ />
283
+ </div>
284
+ );
285
+ }
286
+
287
+ function PrefPill({
288
+ pressed,
289
+ compact = false,
290
+ onClick,
291
+ children,
292
+ }: {
293
+ pressed: boolean;
294
+ compact?: boolean;
295
+ onClick: () => void;
296
+ children: ReactNode;
297
+ }) {
298
+ return (
299
+ <button
300
+ type="button"
301
+ aria-pressed={pressed}
302
+ onClick={onClick}
303
+ className={cn(
304
+ 'min-h-8 rounded-full border px-3 py-1 text-center text-[12.5px] leading-snug font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
305
+ compact ? 'px-2.5 text-[11.5px]' : '',
306
+ pressed
307
+ ? 'border-[var(--lr-accent)] bg-[var(--lr-accent-soft)] text-foreground'
308
+ : 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
309
+ )}
310
+ >
311
+ {children}
312
+ </button>
313
+ );
314
+ }