@lemonriver/core 0.3.0 → 0.5.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 (146) hide show
  1. package/README.md +14 -4
  2. package/dist/{build-Bqo69DWP.js → build-CS1goZxt.js} +1 -1
  3. package/dist/cli/bin.js +4 -4
  4. package/dist/{config-DJ5rkMMg.js → config-BpbcCbUv.js} +3835 -1532
  5. package/dist/{config-teo3kWz7.d.ts → config-CYNOR93W.d.ts} +1 -1
  6. package/dist/{dev-B2FJD5bJ.js → dev-BpYnfgLL.js} +2 -2
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +1 -1
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-C93BOZL1.js → preview-HSzPPkSs.js} +1 -1
  12. package/dist/{types-DFK02XVv.d.ts → types-tdaXSyah.d.ts} +1 -0
  13. package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
  14. package/dist/vite/index.d.ts +1 -1
  15. package/dist/vite/index.js +1 -1
  16. package/dist/{zh-tw-DwTAZKa6.js → zh-tw-DcrDeKxr.js} +5 -0
  17. package/package.json +2 -2
  18. package/src/agent/prompt.ts +2 -0
  19. package/src/agent/types.ts +14 -2
  20. package/src/app/components/agent/agent-panel.tsx +19 -5
  21. package/src/app/components/agent/connect-view.tsx +1 -1
  22. package/src/app/components/agent/provider-logo.tsx +10 -1
  23. package/src/app/components/player.tsx +105 -23
  24. package/src/app/components/present/curtain.tsx +52 -0
  25. package/src/app/components/present/last-slide-hint.tsx +36 -0
  26. package/src/app/components/sidebar/sidebar-footer.tsx +6 -1
  27. package/src/app/components/thumbnail-rail.tsx +1 -0
  28. package/src/app/lemonriver/agent/lemon.tsx +16 -1
  29. package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
  30. package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
  31. package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
  32. package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
  33. package/src/app/lemonriver/agent-providers/section.tsx +75 -0
  34. package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
  35. package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
  36. package/src/app/lemonriver/board/blocks/cache.ts +28 -0
  37. package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
  38. package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
  39. package/src/app/lemonriver/board/blocks/classify.ts +125 -0
  40. package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
  41. package/src/app/lemonriver/board/board-canvas.tsx +627 -104
  42. package/src/app/lemonriver/board/board-page.tsx +1687 -91
  43. package/src/app/lemonriver/board/board.css +58 -7
  44. package/src/app/lemonriver/board/layout.test.ts +84 -0
  45. package/src/app/lemonriver/board/layout.ts +112 -11
  46. package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
  47. package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
  48. package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
  49. package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
  50. package/src/app/lemonriver/board/model/apply.ts +71 -0
  51. package/src/app/lemonriver/board/model/cards.test.ts +95 -2
  52. package/src/app/lemonriver/board/model/cards.ts +88 -20
  53. package/src/app/lemonriver/board/model/changes.test.ts +244 -0
  54. package/src/app/lemonriver/board/model/changes.ts +268 -0
  55. package/src/app/lemonriver/board/model/filter.test.ts +50 -0
  56. package/src/app/lemonriver/board/model/filter.ts +42 -0
  57. package/src/app/lemonriver/board/model/history.test.ts +71 -0
  58. package/src/app/lemonriver/board/model/history.ts +51 -0
  59. package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
  60. package/src/app/lemonriver/board/model/restructure.ts +169 -0
  61. package/src/app/lemonriver/board/model/structure.test.ts +249 -0
  62. package/src/app/lemonriver/board/model/structure.ts +209 -0
  63. package/src/app/lemonriver/board/model/timing.test.ts +113 -0
  64. package/src/app/lemonriver/board/model/timing.ts +117 -0
  65. package/src/app/lemonriver/board/page-node.tsx +236 -55
  66. package/src/app/lemonriver/board/status-style.ts +25 -0
  67. package/src/app/lemonriver/board/use-board-apply.ts +206 -0
  68. package/src/app/lemonriver/board/use-board-cards.ts +108 -5
  69. package/src/app/lemonriver/board/use-board-changes.ts +108 -0
  70. package/src/app/lemonriver/board/use-board-columns.ts +37 -56
  71. package/src/app/lemonriver/board/use-board-comments.ts +36 -0
  72. package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
  73. package/src/app/lemonriver/board/use-history.ts +86 -0
  74. package/src/app/lemonriver/board/use-page-order.ts +65 -38
  75. package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
  76. package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
  77. package/src/app/lemonriver/board/views/list-view.tsx +356 -0
  78. package/src/app/lemonriver/board/views/progress.tsx +32 -0
  79. package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
  80. package/src/app/lemonriver/brand/mascot.tsx +86 -0
  81. package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
  82. package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
  83. package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
  84. package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
  85. package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
  86. package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
  87. package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
  88. package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
  89. package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
  90. package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
  91. package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
  92. package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
  93. package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
  94. package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
  95. package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
  96. package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
  97. package/src/app/lemonriver/chrome/app-chrome.tsx +2 -0
  98. package/src/app/lemonriver/features.test.ts +5 -0
  99. package/src/app/lemonriver/features.ts +2 -1
  100. package/src/app/lemonriver/home/brief-card.tsx +8 -1
  101. package/src/app/lemonriver/home/home-page.tsx +11 -7
  102. package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
  103. package/src/app/lemonriver/outline/build-team.tsx +278 -0
  104. package/src/app/lemonriver/outline/describe-page.tsx +380 -0
  105. package/src/app/lemonriver/outline/files.test.ts +90 -0
  106. package/src/app/lemonriver/outline/files.ts +69 -0
  107. package/src/app/lemonriver/outline/model.test.ts +672 -0
  108. package/src/app/lemonriver/outline/model.ts +455 -0
  109. package/src/app/lemonriver/outline/outline-page.tsx +537 -0
  110. package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
  111. package/src/app/lemonriver/outline/rule.ts +3 -0
  112. package/src/app/lemonriver/outline/steps.tsx +43 -0
  113. package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
  114. package/src/app/lemonriver/routes.test.tsx +6 -6
  115. package/src/app/lemonriver/routes.tsx +28 -0
  116. package/src/app/lemonriver/settings/settings-page.tsx +214 -0
  117. package/src/app/lemonriver/slide-extensions.tsx +45 -26
  118. package/src/app/lemonriver/text/en.ts +320 -0
  119. package/src/app/lemonriver/text/es.ts +311 -0
  120. package/src/app/lemonriver/text/ja.ts +313 -0
  121. package/src/app/lemonriver/text/text.test.ts +33 -0
  122. package/src/app/lemonriver/text/types.ts +339 -0
  123. package/src/app/lemonriver/text/zh-cn.ts +307 -0
  124. package/src/app/lemonriver/text/zh-tw.ts +307 -0
  125. package/src/app/lemonriver/theme/app.css +12 -1
  126. package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
  127. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  128. package/src/app/lemonriver/theme/pages.ts +11 -2
  129. package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
  130. package/src/app/lemonriver/theme/use-theme.tsx +2 -2
  131. package/src/app/lemonriver/update/beta-badge.tsx +26 -0
  132. package/src/app/lemonriver/update/prompt.test.ts +84 -0
  133. package/src/app/lemonriver/update/prompt.ts +48 -0
  134. package/src/app/lemonriver/update/update-prompt.tsx +113 -0
  135. package/src/app/lib/agent/use-agent.ts +4 -3
  136. package/src/app/routes/home.tsx +13 -5
  137. package/src/app/routes/slide.tsx +71 -14
  138. package/src/locale/en.ts +1 -0
  139. package/src/locale/es.ts +1 -0
  140. package/src/locale/ja.ts +1 -0
  141. package/src/locale/types.ts +1 -0
  142. package/src/locale/zh-cn.ts +1 -0
  143. package/src/locale/zh-tw.ts +1 -0
  144. package/src/app/assets/open-slide.svg +0 -39
  145. package/src/app/favicon.ico +0 -0
  146. package/src/app/favicon.svg +0 -39
@@ -8,6 +8,7 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
8
8
  import { format, useLocale } from '@/lib/use-locale';
9
9
  import { useRestartServer } from '@/lib/use-restart-server';
10
10
  import { ThemeToggle } from '../../lemonriver/theme/theme-menu';
11
+ import { BetaBadge } from '../../lemonriver/update/beta-badge';
11
12
 
12
13
  type UpdateCheck = { current: string; latest: string | null; outdated: boolean };
13
14
  type UpdateStatus = 'idle' | 'running' | 'done' | 'error';
@@ -64,9 +65,13 @@ export function SidebarFooter() {
64
65
  >
65
66
  <span className="size-1.5 rounded-full bg-brand" aria-hidden />
66
67
  {label}
68
+ <BetaBadge />
67
69
  </button>
68
70
  ) : (
69
- <span className="inline-flex cursor-default items-center gap-1.5">{label}</span>
71
+ <span className="inline-flex cursor-default items-center gap-1.5">
72
+ {label}
73
+ <BetaBadge />
74
+ </span>
70
75
  );
71
76
 
72
77
  return (
@@ -369,6 +369,7 @@ export function ThumbnailRail({
369
369
  onCurrentPositionChange={setCurrentPosition}
370
370
  renderThumb={renderThumb}
371
371
  />
372
+ <div data-lr-rail-pending="" />
372
373
  </aside>
373
374
  );
374
375
 
@@ -1,8 +1,11 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import type { AgentActivity } from '@/lib/agent/use-agent';
3
- import { Mascot, type MascotState } from '../brand/mascot';
3
+ import { HelperMascot, type HelperRole, Mascot, type MascotState } from '../brand/mascot';
4
+ import { useBuildOutline } from '../outline/use-build-driver';
4
5
  import { useLrText } from '../text';
5
6
 
7
+ const REVIEW_ROLE: HelperRole = 'review';
8
+
6
9
  const PHASE_STATE: Record<AgentActivity['phase'], MascotState> = {
7
10
  thinking: 'thinking',
8
11
  tool: 'working',
@@ -40,6 +43,18 @@ export function ResultLemon({ aborted }: { aborted: boolean }) {
40
43
  /** The header of a question the agent asks: the design package's confirmation card. */
41
44
  export function ConfirmWho() {
42
45
  const lr = useLrText();
46
+ const outline = useBuildOutline();
47
+ if (outline?.state === 'building' && outline.stage === 'review') {
48
+ return (
49
+ <div
50
+ data-lr-confirm-who="review"
51
+ className="mb-2 flex items-center gap-2 px-1.5 text-[12.5px] font-semibold"
52
+ >
53
+ <HelperMascot role={REVIEW_ROLE} state="needs-you" size={36} />
54
+ {lr.feedback.confirmReview}
55
+ </div>
56
+ );
57
+ }
43
58
  return (
44
59
  <div className="mb-2 flex items-center gap-2 px-1.5 text-[12.5px] font-semibold">
45
60
  <Mascot state="needs-you" size={36} />
@@ -0,0 +1,53 @@
1
+ import { useState } from 'react';
2
+ import type { AgentProviderId } from '../../../agent/types';
3
+ import { cn } from '../../lib/utils';
4
+
5
+ // These products pick their own app icon on the machine they are installed on,
6
+ // so the panel shows the real one and falls back to our initial in a circle
7
+ // when the app is missing. The image is never bundled with us; the dev server
8
+ // reads it off the installed app and caches it under node_modules.
9
+ const MARKS: Partial<Record<AgentProviderId, { letter: string; fill: string }>> = {
10
+ workbuddy: { letter: 'W', fill: '#1F8A5B' },
11
+ dumate: { letter: 'D', fill: '#3357CE' },
12
+ };
13
+
14
+ export function ExtraProviderLogo({
15
+ provider,
16
+ className,
17
+ }: {
18
+ provider: AgentProviderId;
19
+ className?: string;
20
+ }) {
21
+ const [unavailable, setUnavailable] = useState(false);
22
+ const mark = MARKS[provider];
23
+
24
+ if (mark && !unavailable) {
25
+ return (
26
+ <img
27
+ src={`/__lr/agent-providers/${provider}/icon`}
28
+ alt=""
29
+ aria-hidden="true"
30
+ className={cn('rounded-[3px] object-contain', className)}
31
+ onError={() => setUnavailable(true)}
32
+ />
33
+ );
34
+ }
35
+
36
+ const fallback = mark ?? { letter: '?', fill: '#6B7280' };
37
+ return (
38
+ <svg viewBox="0 0 24 24" aria-hidden="true" className={className}>
39
+ <circle cx="12" cy="12" r="12" fill={fallback.fill} />
40
+ <text
41
+ x="12"
42
+ y="16.4"
43
+ textAnchor="middle"
44
+ fontSize="13.5"
45
+ fontWeight="700"
46
+ fill="#ffffff"
47
+ fontFamily="-apple-system, BlinkMacSystemFont, Inter, sans-serif"
48
+ >
49
+ {fallback.letter}
50
+ </text>
51
+ </svg>
52
+ );
53
+ }
@@ -0,0 +1,173 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ type AgentPrefs,
4
+ DEFAULT_PREFS,
5
+ PREFS_KEY,
6
+ prefsLines,
7
+ readPrefs,
8
+ sanitizePrefs,
9
+ savePrefs,
10
+ toneForUses,
11
+ } from './prefs';
12
+
13
+ function memoryStorage(initial: Record<string, string> = {}): Storage {
14
+ const data = new Map(Object.entries(initial));
15
+ return {
16
+ get length() {
17
+ return data.size;
18
+ },
19
+ clear: () => data.clear(),
20
+ getItem: (key: string) => data.get(key) ?? null,
21
+ key: (index: number) => [...data.keys()][index] ?? null,
22
+ removeItem: (key: string) => {
23
+ data.delete(key);
24
+ },
25
+ setItem: (key: string, value: string) => {
26
+ data.set(key, value);
27
+ },
28
+ };
29
+ }
30
+
31
+ describe('sanitizePrefs', () => {
32
+ it('returns the defaults for anything that is not an object', () => {
33
+ expect(sanitizePrefs(null)).toEqual(DEFAULT_PREFS);
34
+ expect(sanitizePrefs('dense')).toEqual(DEFAULT_PREFS);
35
+ expect(sanitizePrefs(['dense'])).toEqual(DEFAULT_PREFS);
36
+ });
37
+
38
+ it('keeps the values it knows', () => {
39
+ const prefs: AgentPrefs = {
40
+ confirmEachPage: true,
41
+ askOnMismatch: false,
42
+ autoImages: false,
43
+ tone: 'concise',
44
+ research: 'web',
45
+ outline: 'direct',
46
+ design: 'dense',
47
+ review: 'numbers',
48
+ };
49
+ expect(sanitizePrefs(prefs)).toEqual(prefs);
50
+ });
51
+
52
+ it('replaces the values it does not know with the defaults', () => {
53
+ expect(
54
+ sanitizePrefs({
55
+ confirmEachPage: 'yes',
56
+ askOnMismatch: 0,
57
+ autoImages: null,
58
+ tone: 'shouty',
59
+ research: 'library',
60
+ outline: 'auto',
61
+ design: 'sparse',
62
+ review: 'loose',
63
+ }),
64
+ ).toEqual(DEFAULT_PREFS);
65
+ });
66
+
67
+ it('fills a partial record', () => {
68
+ expect(sanitizePrefs({ design: 'visual' })).toEqual({ ...DEFAULT_PREFS, design: 'visual' });
69
+ });
70
+ });
71
+
72
+ describe('readPrefs and savePrefs', () => {
73
+ it('round-trips through storage', () => {
74
+ const storage = memoryStorage();
75
+ const prefs: AgentPrefs = { ...DEFAULT_PREFS, tone: 'friendly', confirmEachPage: true };
76
+ savePrefs(storage, prefs);
77
+ expect(storage.getItem(PREFS_KEY)).toBe(JSON.stringify(prefs));
78
+ expect(readPrefs(storage)).toEqual(prefs);
79
+ });
80
+
81
+ it('falls back to the defaults on junk or a missing key', () => {
82
+ expect(readPrefs(memoryStorage())).toEqual(DEFAULT_PREFS);
83
+ expect(readPrefs(memoryStorage({ [PREFS_KEY]: 'not json' }))).toEqual(DEFAULT_PREFS);
84
+ expect(readPrefs(memoryStorage({ [PREFS_KEY]: '{"tone":"loud"}' }))).toEqual(DEFAULT_PREFS);
85
+ });
86
+
87
+ it('swallows a storage that throws', () => {
88
+ const broken = {
89
+ getItem: () => {
90
+ throw new Error('blocked');
91
+ },
92
+ setItem: () => {
93
+ throw new Error('blocked');
94
+ },
95
+ } as unknown as Storage;
96
+ expect(readPrefs(broken)).toEqual(DEFAULT_PREFS);
97
+ expect(() => savePrefs(broken, DEFAULT_PREFS)).not.toThrow();
98
+ });
99
+ });
100
+
101
+ describe('prefsLines', () => {
102
+ const prefs = (patch: Partial<AgentPrefs> = {}): AgentPrefs => ({ ...DEFAULT_PREFS, ...patch });
103
+
104
+ it('gives every step the tone', () => {
105
+ for (const step of ['outline', 'page', 'review'] as const) {
106
+ expect(prefsLines(prefs(), step)[0]).toBe('Write in a steady, professional tone.');
107
+ }
108
+ expect(prefsLines(prefs({ tone: 'friendly' }), 'page')[0]).toBe(
109
+ 'Write in a light, friendly tone.',
110
+ );
111
+ expect(prefsLines(prefs({ tone: 'concise' }), 'review')[0]).toBe(
112
+ 'Keep the wording short and punchy.',
113
+ );
114
+ });
115
+
116
+ it('tells the outline step where facts may come from', () => {
117
+ expect(prefsLines(prefs(), 'outline')).toEqual([
118
+ 'Write in a steady, professional tone.',
119
+ "Use only the user's reference files; do not look anything up on the web.",
120
+ ]);
121
+ expect(prefsLines(prefs({ research: 'web' }), 'outline')).toContain(
122
+ 'You may look up facts the files do not cover; say where each one came from.',
123
+ );
124
+ });
125
+
126
+ it('tells the page step how dense to lay out and whether to use images', () => {
127
+ expect(prefsLines(prefs(), 'page')).toEqual([
128
+ 'Write in a steady, professional tone.',
129
+ 'Balance text and visuals.',
130
+ 'Use icons and image placeholders where a picture helps; never invent photos the user did not provide.',
131
+ ]);
132
+ expect(prefsLines(prefs({ design: 'dense' }), 'page')).toContain(
133
+ 'A page may carry more text and data when the content needs it.',
134
+ );
135
+ expect(prefsLines(prefs({ autoImages: false }), 'page')).toContain(
136
+ 'Do not add any image the user did not provide.',
137
+ );
138
+ });
139
+
140
+ it('tells the review step how far to check and what to do with a mismatch', () => {
141
+ expect(prefsLines(prefs(), 'review')).toEqual([
142
+ 'Write in a steady, professional tone.',
143
+ 'Check wording, typos and every number.',
144
+ ]);
145
+ expect(prefsLines(prefs({ review: 'numbers' }), 'review')).toContain(
146
+ 'Check only the numbers against the reference files.',
147
+ );
148
+ const lenient = prefsLines(prefs({ askOnMismatch: false }), 'review');
149
+ expect(lenient).toContain(
150
+ 'When two files disagree on a number, use the one from the spreadsheet (.xlsx, .xls or .csv) and say which you used.',
151
+ );
152
+ });
153
+ });
154
+
155
+ describe('toneForUses', () => {
156
+ it('picks a tone from what the deck is for', () => {
157
+ expect(toneForUses(['report'])).toBe('steady');
158
+ expect(toneForUses(['pitch'])).toBe('steady');
159
+ expect(toneForUses(['lecture'])).toBe('friendly');
160
+ expect(toneForUses(['training'])).toBe('friendly');
161
+ expect(toneForUses(['launch'])).toBe('concise');
162
+ });
163
+
164
+ it('lets a launch win over anything else picked with it', () => {
165
+ expect(toneForUses(['lecture', 'launch'])).toBe('concise');
166
+ expect(toneForUses(['report', 'training'])).toBe('friendly');
167
+ });
168
+
169
+ it('changes nothing for other or an empty pick', () => {
170
+ expect(toneForUses([])).toBeNull();
171
+ expect(toneForUses(['other'])).toBeNull();
172
+ });
173
+ });
@@ -0,0 +1,137 @@
1
+ export type Tone = 'steady' | 'friendly' | 'concise';
2
+ export type ResearchSource = 'uploads' | 'web';
3
+ export type OutlineMode = 'review' | 'direct';
4
+ export type DesignDensity = 'visual' | 'balanced' | 'dense';
5
+ export type ReviewMode = 'strict' | 'numbers';
6
+
7
+ export type AgentPrefs = {
8
+ confirmEachPage: boolean;
9
+ askOnMismatch: boolean;
10
+ autoImages: boolean;
11
+ tone: Tone;
12
+ research: ResearchSource;
13
+ outline: OutlineMode;
14
+ design: DesignDensity;
15
+ review: ReviewMode;
16
+ };
17
+
18
+ export const DEFAULT_PREFS: AgentPrefs = {
19
+ confirmEachPage: false,
20
+ askOnMismatch: true,
21
+ autoImages: true,
22
+ tone: 'steady',
23
+ research: 'uploads',
24
+ outline: 'review',
25
+ design: 'balanced',
26
+ review: 'strict',
27
+ };
28
+
29
+ export const PREFS_KEY = 'lemonriver:agent-prefs';
30
+
31
+ const TONES: readonly Tone[] = ['steady', 'friendly', 'concise'];
32
+ const RESEARCH: readonly ResearchSource[] = ['uploads', 'web'];
33
+ const OUTLINES: readonly OutlineMode[] = ['review', 'direct'];
34
+ const DESIGNS: readonly DesignDensity[] = ['visual', 'balanced', 'dense'];
35
+ const REVIEWS: readonly ReviewMode[] = ['strict', 'numbers'];
36
+
37
+ function pick<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {
38
+ return typeof value === 'string' && (allowed as readonly string[]).includes(value)
39
+ ? (value as T)
40
+ : fallback;
41
+ }
42
+
43
+ function flag(value: unknown, fallback: boolean): boolean {
44
+ return typeof value === 'boolean' ? value : fallback;
45
+ }
46
+
47
+ export function sanitizePrefs(raw: unknown): AgentPrefs {
48
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return { ...DEFAULT_PREFS };
49
+ const r = raw as Record<string, unknown>;
50
+ return {
51
+ confirmEachPage: flag(r.confirmEachPage, DEFAULT_PREFS.confirmEachPage),
52
+ askOnMismatch: flag(r.askOnMismatch, DEFAULT_PREFS.askOnMismatch),
53
+ autoImages: flag(r.autoImages, DEFAULT_PREFS.autoImages),
54
+ tone: pick(r.tone, TONES, DEFAULT_PREFS.tone),
55
+ research: pick(r.research, RESEARCH, DEFAULT_PREFS.research),
56
+ outline: pick(r.outline, OUTLINES, DEFAULT_PREFS.outline),
57
+ design: pick(r.design, DESIGNS, DEFAULT_PREFS.design),
58
+ review: pick(r.review, REVIEWS, DEFAULT_PREFS.review),
59
+ };
60
+ }
61
+
62
+ export function readPrefs(storage: Storage): AgentPrefs {
63
+ let raw: string | null = null;
64
+ try {
65
+ raw = storage.getItem(PREFS_KEY);
66
+ } catch {
67
+ return { ...DEFAULT_PREFS };
68
+ }
69
+ if (!raw) return { ...DEFAULT_PREFS };
70
+ try {
71
+ return sanitizePrefs(JSON.parse(raw));
72
+ } catch {
73
+ return { ...DEFAULT_PREFS };
74
+ }
75
+ }
76
+
77
+ export function savePrefs(storage: Storage, prefs: AgentPrefs): void {
78
+ try {
79
+ storage.setItem(PREFS_KEY, JSON.stringify(sanitizePrefs(prefs)));
80
+ } catch {}
81
+ }
82
+
83
+ const TONE_LINE: Record<Tone, string> = {
84
+ steady: 'Write in a steady, professional tone.',
85
+ friendly: 'Write in a light, friendly tone.',
86
+ concise: 'Keep the wording short and punchy.',
87
+ };
88
+
89
+ const RESEARCH_LINE: Record<ResearchSource, string> = {
90
+ uploads: "Use only the user's reference files; do not look anything up on the web.",
91
+ web: 'You may look up facts the files do not cover; say where each one came from.',
92
+ };
93
+
94
+ const DESIGN_LINE: Record<DesignDensity, string> = {
95
+ visual: 'Keep text short and give each page one large visual, chart or icon.',
96
+ balanced: 'Balance text and visuals.',
97
+ dense: 'A page may carry more text and data when the content needs it.',
98
+ };
99
+
100
+ const IMAGES_LINE = {
101
+ yes: 'Use icons and image placeholders where a picture helps; never invent photos the user did not provide.',
102
+ no: 'Do not add any image the user did not provide.',
103
+ };
104
+
105
+ const REVIEW_LINE: Record<ReviewMode, string> = {
106
+ strict: 'Check wording, typos and every number.',
107
+ numbers: 'Check only the numbers against the reference files.',
108
+ };
109
+
110
+ const MISMATCH_LINE =
111
+ 'When two files disagree on a number, use the one from the spreadsheet (.xlsx, .xls or .csv) and say which you used.';
112
+
113
+ export type PrefStep = 'outline' | 'page' | 'review';
114
+
115
+ export function prefsLines(prefs: AgentPrefs, step: PrefStep): string[] {
116
+ const lines = [TONE_LINE[prefs.tone]];
117
+ if (step === 'outline') lines.push(RESEARCH_LINE[prefs.research]);
118
+ if (step === 'page') {
119
+ lines.push(DESIGN_LINE[prefs.design]);
120
+ lines.push(prefs.autoImages ? IMAGES_LINE.yes : IMAGES_LINE.no);
121
+ }
122
+ if (step === 'review') {
123
+ lines.push(REVIEW_LINE[prefs.review]);
124
+ if (!prefs.askOnMismatch) lines.push(MISMATCH_LINE);
125
+ }
126
+ return lines;
127
+ }
128
+
129
+ export const USE_IDS = ['report', 'pitch', 'lecture', 'launch', 'training', 'other'] as const;
130
+ export type UseId = (typeof USE_IDS)[number];
131
+
132
+ export function toneForUses(uses: readonly string[]): Tone | null {
133
+ if (uses.includes('launch')) return 'concise';
134
+ if (uses.includes('lecture') || uses.includes('training')) return 'friendly';
135
+ if (uses.includes('report') || uses.includes('pitch')) return 'steady';
136
+ return null;
137
+ }
@@ -0,0 +1,36 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { type AgentPrefs, DEFAULT_PREFS, readPrefs, sanitizePrefs, savePrefs } from './prefs';
3
+
4
+ let current: AgentPrefs =
5
+ typeof window === 'undefined' ? DEFAULT_PREFS : readPrefs(window.localStorage);
6
+
7
+ const listeners = new Set<() => void>();
8
+
9
+ function subscribe(listener: () => void): () => void {
10
+ listeners.add(listener);
11
+ return () => {
12
+ listeners.delete(listener);
13
+ };
14
+ }
15
+
16
+ function snapshot(): AgentPrefs {
17
+ return current;
18
+ }
19
+
20
+ function serverSnapshot(): AgentPrefs {
21
+ return DEFAULT_PREFS;
22
+ }
23
+
24
+ export function useAgentPrefs(): AgentPrefs {
25
+ return useSyncExternalStore(subscribe, snapshot, serverSnapshot);
26
+ }
27
+
28
+ export function setAgentPrefs(next: AgentPrefs): void {
29
+ current = sanitizePrefs(next);
30
+ savePrefs(window.localStorage, current);
31
+ for (const listener of listeners) listener();
32
+ }
33
+
34
+ export function updateAgentPrefs(patch: Partial<AgentPrefs>): void {
35
+ setAgentPrefs({ ...current, ...patch });
36
+ }
@@ -0,0 +1,75 @@
1
+ import { toast } from 'sonner';
2
+ import { format } from '@/lib/use-locale';
3
+ import { cn } from '@/lib/utils';
4
+ import { ProviderLogo } from '../../components/agent/provider-logo';
5
+ import { useLrText } from '../text';
6
+ import { type AgentProviderRow, useAgentProviders } from './use-providers';
7
+
8
+ export function AgentProvidersSection() {
9
+ const lr = useLrText();
10
+ const { catalog, saving, setEnabled } = useAgentProviders();
11
+ if (!catalog) return null;
12
+
13
+ const on = new Set(catalog.enabled);
14
+
15
+ async function toggle(row: AgentProviderRow) {
16
+ const ok = await setEnabled(row.id, !on.has(row.id));
17
+ if (!ok) toast.error(lr.agents.saveFailed);
18
+ }
19
+
20
+ function hint(row: AgentProviderRow): string {
21
+ if (!row.detected) return lr.agents.missingHint;
22
+ if (row.connectable) return lr.agents.detected;
23
+ if (row.reason === 'desktop-only') return lr.agents.dumateReason;
24
+ return lr.agents.missingHint;
25
+ }
26
+
27
+ return (
28
+ <section
29
+ data-lr-agent-providers
30
+ className="mt-5 rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]"
31
+ >
32
+ <h2 className="text-[16px] font-semibold">{lr.agents.title}</h2>
33
+ <p className="mt-1 mb-2 text-[14px] text-muted-foreground">{lr.agents.hint}</p>
34
+
35
+ <ul className="divide-y divide-border border-t border-border">
36
+ {catalog.providers.map((row) => {
37
+ const checked = row.builtin || on.has(row.id);
38
+ const locked = row.builtin || !row.detected || !row.connectable;
39
+ return (
40
+ <li key={row.id} data-lr-agent-row={row.id} className="flex items-center gap-3 py-3">
41
+ <ProviderLogo provider={row.id} className="size-6 shrink-0" />
42
+ <div className="min-w-0 flex-1">
43
+ <p className="text-[14px] font-semibold">
44
+ {row.name}
45
+ {row.builtin && (
46
+ <span className="ml-2 text-[12px] font-normal text-muted-foreground">
47
+ {lr.agents.alwaysOn}
48
+ </span>
49
+ )}
50
+ </p>
51
+ <p data-lr-agent-state={row.id} className="text-[12px] text-muted-foreground">
52
+ {hint(row)}
53
+ </p>
54
+ </div>
55
+ <button
56
+ type="button"
57
+ role="switch"
58
+ data-lr-agent-switch={row.id}
59
+ aria-checked={checked}
60
+ aria-label={format(lr.agents.unlock, { name: row.name })}
61
+ aria-disabled={locked}
62
+ disabled={locked || saving === row.id}
63
+ onClick={() => void toggle(row)}
64
+ className={cn(
65
+ 'lr-switch shrink-0 outline-none focus-visible:ring-2 focus-visible:ring-ring/40',
66
+ locked && 'cursor-not-allowed opacity-45',
67
+ )}
68
+ />
69
+ </li>
70
+ );
71
+ })}
72
+ </ul>
73
+ </section>
74
+ );
75
+ }
@@ -0,0 +1,61 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { refreshStatus } from '@/lib/agent/use-agent';
3
+ import type { AgentProviderId } from '../../../agent/types';
4
+
5
+ export type AgentProviderRow = {
6
+ id: AgentProviderId;
7
+ name: string;
8
+ builtin: boolean;
9
+ detected: boolean;
10
+ connectable: boolean;
11
+ reason: string | null;
12
+ };
13
+
14
+ type Catalog = { enabled: string[]; providers: AgentProviderRow[] };
15
+
16
+ export function useAgentProviders() {
17
+ const [catalog, setCatalog] = useState<Catalog | null>(null);
18
+ const [saving, setSaving] = useState<string | null>(null);
19
+
20
+ const load = useCallback(async () => {
21
+ try {
22
+ const res = await fetch('/__lr/agent-providers');
23
+ if (!res.ok) return;
24
+ setCatalog((await res.json()) as Catalog);
25
+ } catch {}
26
+ }, []);
27
+
28
+ useEffect(() => {
29
+ if (!import.meta.env.DEV) return;
30
+ void load();
31
+ }, [load]);
32
+
33
+ const setEnabled = useCallback(
34
+ async (id: string, on: boolean): Promise<boolean> => {
35
+ if (!catalog) return false;
36
+ const next = on
37
+ ? [...catalog.enabled.filter((x) => x !== id), id]
38
+ : catalog.enabled.filter((x) => x !== id);
39
+ setSaving(id);
40
+ try {
41
+ const res = await fetch('/__lr/agent-providers', {
42
+ method: 'PUT',
43
+ headers: { 'content-type': 'application/json' },
44
+ body: JSON.stringify({ enabled: next }),
45
+ });
46
+ if (!res.ok) return false;
47
+ const body = (await res.json()) as { enabled: string[] };
48
+ setCatalog({ ...catalog, enabled: body.enabled });
49
+ void refreshStatus();
50
+ return true;
51
+ } catch {
52
+ return false;
53
+ } finally {
54
+ setSaving(null);
55
+ }
56
+ },
57
+ [catalog],
58
+ );
59
+
60
+ return { catalog, saving, setEnabled, reload: load };
61
+ }