@lemonriver/core 0.8.0 → 1.0.1
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 +3 -1
- package/dist/{build-Bdagm0FU.js → build-CiT4CNey.js} +1 -1
- package/dist/cli/bin.js +11 -4
- package/dist/client-DpO_eR9X.js +57 -0
- package/dist/{config-Begts3gq.js → config-BI3VRI2n.js} +4557 -4596
- package/dist/{dev-DjjzmT28.js → dev-DpzBn_sf.js} +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/mcp-CjYDzcJa.js +262 -0
- package/dist/{preview-C9y9MTY1.js → preview-Dro8hl5_.js} +2 -2
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DcrDeKxr.js → zh-tw-BhYyMx0-.js} +40 -40
- package/package.json +1 -1
- package/skills/slide-authoring/SKILL.md +2 -0
- package/src/app/lemonriver/agent-providers/section.tsx +13 -4
- package/src/app/lemonriver/board/use-self-check.ts +1 -1
- package/src/app/lemonriver/brand/mascot.tsx +4 -1
- package/src/app/lemonriver/chrome/app-chrome.tsx +6 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +9 -1
- package/src/app/lemonriver/feedback/lemon-empty.tsx +3 -1
- package/src/app/lemonriver/guide/guide-prompt.tsx +89 -0
- package/src/app/lemonriver/guide/state.ts +29 -0
- package/src/app/lemonriver/guide/use-guide.ts +17 -0
- package/src/app/lemonriver/help/help-page.tsx +5 -0
- package/src/app/lemonriver/help/model.test.ts +72 -0
- package/src/app/lemonriver/help/model.ts +10 -1
- package/src/app/lemonriver/home/home-page.tsx +25 -7
- package/src/app/lemonriver/mcp/respond.ts +47 -0
- package/src/app/lemonriver/mcp/screenshot.tsx +155 -0
- package/src/app/lemonriver/mcp/self-check.tsx +65 -0
- package/src/app/lemonriver/outline/describe-page.tsx +3 -1
- package/src/app/lemonriver/routes.test.tsx +4 -1
- package/src/app/lemonriver/routes.tsx +12 -11
- package/src/app/lemonriver/settings/settings-page.tsx +3 -3
- package/src/app/lemonriver/share/freeze.ts +13 -5
- package/src/app/lemonriver/text/en.ts +227 -7
- package/src/app/lemonriver/text/es.ts +23 -6
- package/src/app/lemonriver/text/ja.ts +23 -6
- package/src/app/lemonriver/text/types.ts +14 -1
- package/src/app/lemonriver/text/zh-cn.ts +218 -6
- package/src/app/lemonriver/text/zh-tw.ts +218 -6
- package/src/app/lemonriver/update/beta-badge.tsx +3 -0
- package/src/app/lemonriver/update/lazy-page.tsx +29 -0
- package/src/app/lemonriver/update/notice-mascot.tsx +18 -0
- package/src/app/lemonriver/update/restart-notice.tsx +47 -0
- package/src/app/lemonriver/update/state.ts +33 -0
- package/src/app/lemonriver/update/update-prompt.tsx +30 -1
- package/src/app/lemonriver/update/version.test.ts +14 -0
- package/src/app/lemonriver/update/version.ts +5 -0
- package/src/locale/en.ts +8 -8
- package/src/locale/es.ts +10 -8
- package/src/locale/ja.ts +9 -8
- package/src/locale/zh-cn.ts +9 -8
- package/src/locale/zh-tw.ts +9 -8
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { Button } from '@/components/ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogDescription,
|
|
8
|
+
DialogFooter,
|
|
9
|
+
DialogHeader,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
} from '@/components/ui/dialog';
|
|
12
|
+
import { Mascot } from '../brand/mascot';
|
|
13
|
+
import { useLrText } from '../text';
|
|
14
|
+
import { guideSeen, markGuideSeen } from './state';
|
|
15
|
+
import { useGuideFlags } from './use-guide';
|
|
16
|
+
|
|
17
|
+
const CARD =
|
|
18
|
+
'flex min-h-[170px] flex-col items-start gap-2 rounded-[14px] border border-border bg-card p-4 text-left outline-none transition-colors hover:border-[var(--lr-focus)] focus-visible:ring-2 focus-visible:ring-ring/40';
|
|
19
|
+
|
|
20
|
+
/** The first-open chooser: two ways to work, shown once. */
|
|
21
|
+
export function GuidePrompt() {
|
|
22
|
+
const lr = useLrText();
|
|
23
|
+
const g = lr.guide;
|
|
24
|
+
const navigate = useNavigate();
|
|
25
|
+
const flags = useGuideFlags();
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (flags?.prompt === true && !guideSeen()) setOpen(true);
|
|
30
|
+
}, [flags]);
|
|
31
|
+
|
|
32
|
+
const skip = () => {
|
|
33
|
+
markGuideSeen();
|
|
34
|
+
setOpen(false);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const pick = (anchor: 'guide-agent' | 'guide-ui') => {
|
|
38
|
+
markGuideSeen();
|
|
39
|
+
setOpen(false);
|
|
40
|
+
navigate(`/help#${anchor}`);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Dialog
|
|
45
|
+
open={open}
|
|
46
|
+
onOpenChange={(next) => {
|
|
47
|
+
if (!next) skip();
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
<DialogContent data-lr-guide-prompt className="sm:max-w-[560px]">
|
|
51
|
+
<DialogHeader>
|
|
52
|
+
<DialogTitle>{g.promptTitle}</DialogTitle>
|
|
53
|
+
<DialogDescription>{g.promptIntro}</DialogDescription>
|
|
54
|
+
</DialogHeader>
|
|
55
|
+
<div className="mt-1 grid gap-3 sm:grid-cols-2">
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
data-lr-guide-card="agent"
|
|
59
|
+
onClick={() => pick('guide-agent')}
|
|
60
|
+
className={CARD}
|
|
61
|
+
>
|
|
62
|
+
<Mascot state="idle" size={44} />
|
|
63
|
+
<span className="text-[15px] font-semibold">{g.cardAgentTitle}</span>
|
|
64
|
+
<span className="text-[13px] leading-relaxed text-muted-foreground">
|
|
65
|
+
{g.cardAgentBody}
|
|
66
|
+
</span>
|
|
67
|
+
</button>
|
|
68
|
+
<button
|
|
69
|
+
type="button"
|
|
70
|
+
data-lr-guide-card="ui"
|
|
71
|
+
onClick={() => pick('guide-ui')}
|
|
72
|
+
className={CARD}
|
|
73
|
+
>
|
|
74
|
+
<Mascot state="done" size={44} />
|
|
75
|
+
<span className="text-[15px] font-semibold">{g.cardUiTitle}</span>
|
|
76
|
+
<span className="text-[13px] leading-relaxed text-muted-foreground">
|
|
77
|
+
{g.cardUiBody}
|
|
78
|
+
</span>
|
|
79
|
+
</button>
|
|
80
|
+
</div>
|
|
81
|
+
<DialogFooter>
|
|
82
|
+
<Button type="button" variant="ghost" size="sm" data-lr-guide-skip onClick={skip}>
|
|
83
|
+
{g.skip}
|
|
84
|
+
</Button>
|
|
85
|
+
</DialogFooter>
|
|
86
|
+
</DialogContent>
|
|
87
|
+
</Dialog>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type GuideFlags = { prompt: boolean; guided: boolean };
|
|
2
|
+
|
|
3
|
+
export const GUIDE_SEEN_KEY = 'lemonriver:guide-seen';
|
|
4
|
+
|
|
5
|
+
export function guideSeen(): boolean {
|
|
6
|
+
try {
|
|
7
|
+
return localStorage.getItem(GUIDE_SEEN_KEY) === '1';
|
|
8
|
+
} catch {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function markGuideSeen(): void {
|
|
14
|
+
try {
|
|
15
|
+
localStorage.setItem(GUIDE_SEEN_KEY, '1');
|
|
16
|
+
} catch {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The server decides both: the chooser on first open, and the in-app agent entry points. */
|
|
20
|
+
export async function guideFlags(): Promise<GuideFlags> {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch('/__lr/guide');
|
|
23
|
+
if (!res.ok) throw new Error(String(res.status));
|
|
24
|
+
const data = (await res.json()) as { prompt?: unknown; guided?: unknown };
|
|
25
|
+
return { prompt: data.prompt !== false, guided: data.guided === true };
|
|
26
|
+
} catch {
|
|
27
|
+
return { prompt: true, guided: false };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { type GuideFlags, guideFlags } from './state';
|
|
3
|
+
|
|
4
|
+
/** Null until the server answers; callers treat that as "not shown". */
|
|
5
|
+
export function useGuideFlags(): GuideFlags | null {
|
|
6
|
+
const [flags, setFlags] = useState<GuideFlags | null>(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
let alive = true;
|
|
9
|
+
void guideFlags().then((value) => {
|
|
10
|
+
if (alive) setFlags(value);
|
|
11
|
+
});
|
|
12
|
+
return () => {
|
|
13
|
+
alive = false;
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
return flags;
|
|
17
|
+
}
|
|
@@ -3,6 +3,7 @@ import { useEffect, useMemo, useState } from 'react';
|
|
|
3
3
|
import { Link, useLocation } from 'react-router-dom';
|
|
4
4
|
import { format } from '@/lib/use-locale';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
|
+
import { markGuideSeen } from '../guide/state';
|
|
6
7
|
import { useLrText } from '../text';
|
|
7
8
|
import { useReduceMotionSetting } from '../theme/motion';
|
|
8
9
|
import {
|
|
@@ -204,6 +205,10 @@ export function HelpPage() {
|
|
|
204
205
|
|
|
205
206
|
const anchor = location.hash.replace(/^#/, '');
|
|
206
207
|
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
if (anchor.startsWith('guide')) markGuideSeen();
|
|
210
|
+
}, [anchor]);
|
|
211
|
+
|
|
207
212
|
useEffect(() => {
|
|
208
213
|
if (anchor === '') return;
|
|
209
214
|
const target = document.getElementById(`help-${anchor}`);
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { en } from '../../../locale/en.ts';
|
|
2
3
|
import type { Locale } from '../../../locale/types.ts';
|
|
4
|
+
import { zhCN } from '../../../locale/zh-cn.ts';
|
|
5
|
+
import { zhTW } from '../../../locale/zh-tw.ts';
|
|
3
6
|
import { lrTextFor } from '../text/all';
|
|
4
7
|
import { filterHelpSections, helpAnchorForPlace, helpStrings, placeholdersIn } from './model.ts';
|
|
5
8
|
|
|
6
9
|
const ANCHORS = [
|
|
10
|
+
'guide',
|
|
11
|
+
'guide-prepare',
|
|
12
|
+
'guide-agent',
|
|
13
|
+
'guide-ui',
|
|
14
|
+
'guide-finish',
|
|
15
|
+
'guide-faq',
|
|
7
16
|
'share',
|
|
8
17
|
'import',
|
|
9
18
|
'backup',
|
|
@@ -32,6 +41,14 @@ const PLACES = [
|
|
|
32
41
|
|
|
33
42
|
const LOCALES: Locale['id'][] = ['en', 'es', 'ja', 'zh-CN', 'zh-TW'];
|
|
34
43
|
|
|
44
|
+
/** The two example lines under "Prepare", in the order the guide shows them. */
|
|
45
|
+
function agentLists(id: Locale['id']): string[] {
|
|
46
|
+
const section = lrTextFor(id).help.sections.find((item) => item.id === 'guide-prepare');
|
|
47
|
+
const block = section?.blocks[0];
|
|
48
|
+
if (block?.kind !== 'steps') throw new Error(`${id}: guide-prepare does not open with steps`);
|
|
49
|
+
return block.items[0]?.children ?? [];
|
|
50
|
+
}
|
|
51
|
+
|
|
35
52
|
describe('the help page', () => {
|
|
36
53
|
const zh = lrTextFor('zh-CN');
|
|
37
54
|
|
|
@@ -48,8 +65,10 @@ describe('the help page', () => {
|
|
|
48
65
|
|
|
49
66
|
it('names every app button the way the interface does', () => {
|
|
50
67
|
// Japanese and Spanish show the English help, so they keep the English names.
|
|
68
|
+
const locale = { en, 'zh-CN': zhCN, 'zh-TW': zhTW } as const;
|
|
51
69
|
for (const id of ['en', 'zh-CN', 'zh-TW'] as const) {
|
|
52
70
|
const text = lrTextFor(id);
|
|
71
|
+
const ui = locale[id];
|
|
53
72
|
const buttons = text.help.buttons;
|
|
54
73
|
const expected = {
|
|
55
74
|
settings: text.settings.title,
|
|
@@ -66,6 +85,15 @@ describe('the help page', () => {
|
|
|
66
85
|
change: text.backup.change,
|
|
67
86
|
chooseOther: text.backup.chooseOther,
|
|
68
87
|
reveal: text.backup.reveal,
|
|
88
|
+
format: ui.inspector.format,
|
|
89
|
+
replaceImage: ui.inspector.replaceImageDialogTitle,
|
|
90
|
+
assets: ui.home.assets,
|
|
91
|
+
board: text.board.title,
|
|
92
|
+
notes: ui.presenter.speakerNotes,
|
|
93
|
+
comments: ui.inspector.commentMode,
|
|
94
|
+
selfCheck: text.board.selfCheck,
|
|
95
|
+
present: ui.slide.present,
|
|
96
|
+
duplicate: ui.home.duplicate,
|
|
69
97
|
};
|
|
70
98
|
for (const [key, value] of Object.entries(expected)) {
|
|
71
99
|
expect(buttons[key as keyof typeof buttons], `${id}: ${key}`).toBe(value);
|
|
@@ -73,6 +101,50 @@ describe('the help page', () => {
|
|
|
73
101
|
}
|
|
74
102
|
});
|
|
75
103
|
|
|
104
|
+
it('puts the agent line each language leads with first', () => {
|
|
105
|
+
const domestic = 'WorkBuddy';
|
|
106
|
+
const overseas = 'Claude Code';
|
|
107
|
+
for (const id of ['zh-CN', 'zh-TW'] as const) {
|
|
108
|
+
const lists = agentLists(id);
|
|
109
|
+
expect(lists[0], id).toContain(domestic);
|
|
110
|
+
expect(lists[1], id).toContain(overseas);
|
|
111
|
+
}
|
|
112
|
+
for (const id of ['en', 'ja', 'es'] as const) {
|
|
113
|
+
const lists = agentLists(id);
|
|
114
|
+
expect(lists[0], id).toContain(overseas);
|
|
115
|
+
expect(lists[1], id).toContain(domestic);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('lists the agents word for word as the guide text file does', () => {
|
|
120
|
+
expect(agentLists('zh-CN')).toEqual([
|
|
121
|
+
'国内常用:WorkBuddy、DuMate、DeepSeek Harness、Trae、千问办公、豆包、Kimi CLI 等',
|
|
122
|
+
'海外常用:Claude Code、Codex、Gemini CLI、Grok、Cursor、GitHub Copilot、OpenCode 等',
|
|
123
|
+
]);
|
|
124
|
+
expect(agentLists('en')).toEqual([
|
|
125
|
+
'Common elsewhere: Claude Code, Codex, Gemini CLI, Grok, Cursor, GitHub Copilot, OpenCode and others',
|
|
126
|
+
'Common in China: WorkBuddy, DuMate, DeepSeek Harness, Trae, 千问办公, 豆包, Kimi CLI and others',
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('leads with the usage guide', () => {
|
|
131
|
+
for (const id of ['en', 'zh-CN', 'zh-TW'] as const) {
|
|
132
|
+
const help = lrTextFor(id).help;
|
|
133
|
+
expect(help.sections[0]?.id, id).toBe('guide');
|
|
134
|
+
const children = help.sections
|
|
135
|
+
.filter((section) => section.parent === 'guide')
|
|
136
|
+
.map((s) => s.id);
|
|
137
|
+
expect(children, id).toEqual([
|
|
138
|
+
'guide-prepare',
|
|
139
|
+
'guide-agent',
|
|
140
|
+
'guide-ui',
|
|
141
|
+
'guide-finish',
|
|
142
|
+
'guide-faq',
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
expect(lrTextFor('zh-CN').help.title).toBe('使用指南和帮助');
|
|
146
|
+
});
|
|
147
|
+
|
|
76
148
|
it('fills every placeholder from the button list', () => {
|
|
77
149
|
for (const id of LOCALES) {
|
|
78
150
|
const help = lrTextFor(id).help;
|
|
@@ -32,7 +32,16 @@ export type HelpButtonKey =
|
|
|
32
32
|
| 'chooseOtherFile'
|
|
33
33
|
| 'change'
|
|
34
34
|
| 'chooseOther'
|
|
35
|
-
| 'reveal'
|
|
35
|
+
| 'reveal'
|
|
36
|
+
| 'format'
|
|
37
|
+
| 'replaceImage'
|
|
38
|
+
| 'assets'
|
|
39
|
+
| 'board'
|
|
40
|
+
| 'notes'
|
|
41
|
+
| 'comments'
|
|
42
|
+
| 'selfCheck'
|
|
43
|
+
| 'present'
|
|
44
|
+
| 'duplicate';
|
|
36
45
|
|
|
37
46
|
export type HelpContent = {
|
|
38
47
|
title: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChevronDown, Plus } from 'lucide-react';
|
|
2
2
|
import { type ReactNode, useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import { useNavigate, useOutletContext } from 'react-router-dom';
|
|
3
|
+
import { Link, useNavigate, useOutletContext } from 'react-router-dom';
|
|
4
4
|
import { toast } from 'sonner';
|
|
5
5
|
import { Button } from '@/components/ui/button';
|
|
6
6
|
import {
|
|
@@ -19,6 +19,8 @@ import type { HomeOutletContext } from '../../routes/home-shell';
|
|
|
19
19
|
import { FilterPill } from '../chrome/filter-pill';
|
|
20
20
|
import { isFeatureEnabled } from '../features';
|
|
21
21
|
import { LemonEmpty } from '../feedback/lemon-empty';
|
|
22
|
+
import { GuidePrompt } from '../guide/guide-prompt';
|
|
23
|
+
import { useGuideFlags } from '../guide/use-guide';
|
|
22
24
|
import { type InspectOk, inspectPackage } from '../share/client';
|
|
23
25
|
import { shareErrorText } from '../share/codes';
|
|
24
26
|
import { ImportDialog } from '../share/import-dialog';
|
|
@@ -67,6 +69,7 @@ export function LemonRiverHome() {
|
|
|
67
69
|
const times = useDeckTimes();
|
|
68
70
|
const library = useTemplateLibrary();
|
|
69
71
|
const editing = useEditingDecks();
|
|
72
|
+
const guide = useGuideFlags();
|
|
70
73
|
const [query, setQuery] = useState('');
|
|
71
74
|
const [occasion, setOccasion] = useState<string | null>(null);
|
|
72
75
|
const [sortKey, setSortKey] = useSortPref();
|
|
@@ -155,17 +158,20 @@ export function LemonRiverHome() {
|
|
|
155
158
|
return (
|
|
156
159
|
<div data-lr-home {...(shareOn ? dropHandlers : {})}>
|
|
157
160
|
{shareOn && dropHint}
|
|
161
|
+
{isFeatureEnabled('help') && <GuidePrompt />}
|
|
158
162
|
{import.meta.env.DEV && isAll && (
|
|
159
163
|
<>
|
|
160
164
|
<header className="mb-6">
|
|
161
165
|
<h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
|
|
162
166
|
{greeting}
|
|
163
167
|
</h1>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
{guide?.guided === true && (
|
|
169
|
+
<p className="lr-on-lime mt-0.5 text-[14px] text-muted-foreground">
|
|
170
|
+
{lr.home.subtitle}
|
|
171
|
+
</p>
|
|
172
|
+
)}
|
|
167
173
|
</header>
|
|
168
|
-
<BriefCard />
|
|
174
|
+
{guide?.guided === true && <BriefCard />}
|
|
169
175
|
</>
|
|
170
176
|
)}
|
|
171
177
|
|
|
@@ -328,7 +334,8 @@ function NewDeckCard() {
|
|
|
328
334
|
const lr = useLrText();
|
|
329
335
|
const navigate = useNavigate();
|
|
330
336
|
const createDeck = useCreateDeck();
|
|
331
|
-
const
|
|
337
|
+
const guide = useGuideFlags();
|
|
338
|
+
const guided = guide?.guided === true && isFeatureEnabled('outline');
|
|
332
339
|
return (
|
|
333
340
|
<li>
|
|
334
341
|
<button
|
|
@@ -363,8 +370,10 @@ function GridSkeleton() {
|
|
|
363
370
|
|
|
364
371
|
function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: string }) {
|
|
365
372
|
const t = useLocale();
|
|
373
|
+
const lr = useLrText();
|
|
366
374
|
const { enabled, provider } = useAgentStatus();
|
|
367
375
|
const createDeck = useCreateDeck();
|
|
376
|
+
const guide = useGuideFlags();
|
|
368
377
|
if (!isDraft) {
|
|
369
378
|
return (
|
|
370
379
|
<LemonEmpty title={t.home.folderEmptyTitle.replace('{name}', folderName ?? '')}>
|
|
@@ -372,11 +381,13 @@ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: str
|
|
|
372
381
|
</LemonEmpty>
|
|
373
382
|
);
|
|
374
383
|
}
|
|
384
|
+
const guided = guide?.guided === true;
|
|
375
385
|
return (
|
|
376
386
|
<LemonEmpty
|
|
377
387
|
title={t.home.noSlidesYet}
|
|
378
388
|
actions={
|
|
379
389
|
import.meta.env.DEV &&
|
|
390
|
+
guided &&
|
|
380
391
|
enabled && (
|
|
381
392
|
<Button onClick={() => void createDeck()}>
|
|
382
393
|
{provider
|
|
@@ -386,13 +397,20 @@ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: str
|
|
|
386
397
|
)
|
|
387
398
|
}
|
|
388
399
|
>
|
|
389
|
-
{!enabled && (
|
|
400
|
+
{(!enabled || !guided) && (
|
|
390
401
|
<>
|
|
391
402
|
{t.home.createSlideHintPrefix}
|
|
392
403
|
<code className="rounded-[4px] bg-muted px-1.5 py-0.5 font-mono text-[12.5px] text-foreground">
|
|
393
404
|
/create-slide
|
|
394
405
|
</code>
|
|
395
406
|
{t.home.createSlideHintSuffix}
|
|
407
|
+
<Link
|
|
408
|
+
to="/help#guide-agent"
|
|
409
|
+
data-lr-guide-start
|
|
410
|
+
className="mt-2 inline-block text-[13px] text-foreground underline underline-offset-2 outline-none hover:no-underline focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
411
|
+
>
|
|
412
|
+
{lr.guide.startHint}
|
|
413
|
+
</Link>
|
|
396
414
|
</>
|
|
397
415
|
)}
|
|
398
416
|
</LemonEmpty>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { screenshotPage } from './screenshot';
|
|
2
|
+
import { runSelfCheck } from './self-check';
|
|
3
|
+
|
|
4
|
+
export const MCP_REQUEST_EVENT = 'lemonriver:mcp-request';
|
|
5
|
+
|
|
6
|
+
type Request = { id: string; tool: string; args: Record<string, unknown> };
|
|
7
|
+
|
|
8
|
+
async function answer(request: Request): Promise<unknown> {
|
|
9
|
+
// A background tab stops painting, so the work below would never finish.
|
|
10
|
+
if (document.hidden) return { ok: false, hidden: true };
|
|
11
|
+
const args = request.args ?? {};
|
|
12
|
+
const slideId = typeof args.slideId === 'string' ? args.slideId : '';
|
|
13
|
+
try {
|
|
14
|
+
if (request.tool === 'screenshot') {
|
|
15
|
+
const page = typeof args.page === 'number' ? args.page : 0;
|
|
16
|
+
const step = typeof args.step === 'number' ? args.step : undefined;
|
|
17
|
+
return { ok: true, result: await screenshotPage(slideId, page, step) };
|
|
18
|
+
}
|
|
19
|
+
if (request.tool === 'self-check') {
|
|
20
|
+
return { ok: true, result: await runSelfCheck(slideId) };
|
|
21
|
+
}
|
|
22
|
+
return { ok: false, error: `unknown request: ${request.tool}` };
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return { ok: false, error: (err as Error).message ?? String(err) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Answers the dev server's screenshot and self-check requests from whichever
|
|
30
|
+
* LemonRiver page is open. Every open page listens; the server keeps the first
|
|
31
|
+
* reply and drops the rest.
|
|
32
|
+
*/
|
|
33
|
+
export function installMcpResponder(): () => void {
|
|
34
|
+
const hot = import.meta.hot;
|
|
35
|
+
if (!hot) return () => {};
|
|
36
|
+
const onRequest = (data: Request) => {
|
|
37
|
+
void answer(data).then((reply) => {
|
|
38
|
+
void fetch(`/__lr/mcp/reply/${encodeURIComponent(data.id)}`, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: { 'content-type': 'application/json' },
|
|
41
|
+
body: JSON.stringify(reply),
|
|
42
|
+
}).catch(() => {});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
hot.on(MCP_REQUEST_EVENT, onRequest);
|
|
46
|
+
return () => hot.off(MCP_REQUEST_EVENT, onRequest);
|
|
47
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { PreviewStepHost } from '../../components/preview-step-host';
|
|
5
|
+
import { designToCssVars } from '../../lib/design';
|
|
6
|
+
import { nextPaint, sleep } from '../../lib/dom';
|
|
7
|
+
import { SlidePageProvider } from '../../lib/page-context';
|
|
8
|
+
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from '../../lib/print-ready';
|
|
9
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../../lib/sdk';
|
|
10
|
+
import { loadSlide } from '../../lib/slides';
|
|
11
|
+
import { toBase64 } from '../share/capture';
|
|
12
|
+
import { canvasJpeg, canvasScaled, freezeForCapture } from '../share/freeze';
|
|
13
|
+
|
|
14
|
+
const CAPTURE_CLASS = 'lr-mcp-capture';
|
|
15
|
+
const WIDTH = 1280;
|
|
16
|
+
const HEIGHT = 720;
|
|
17
|
+
const QUALITY = 0.85;
|
|
18
|
+
// Past this the encoded page is bigger than a reply should carry; a second,
|
|
19
|
+
// lower-quality pass keeps the screenshot instead of failing it.
|
|
20
|
+
const FALLBACK_QUALITY = 0.7;
|
|
21
|
+
const MAX_BASE64 = 2 * 1024 * 1024;
|
|
22
|
+
const ANIMATION_TIMEOUT_MS = 15_000;
|
|
23
|
+
const POLL_INTERVAL_MS = 100;
|
|
24
|
+
|
|
25
|
+
export type Screenshot = { image: string; mimeType: 'image/jpeg'; width: number; height: number };
|
|
26
|
+
|
|
27
|
+
// Same fast-forward trick the share capture uses: the rasterised clone must not
|
|
28
|
+
// replay an animation from its invisible first frame.
|
|
29
|
+
function captureStyleText(): string {
|
|
30
|
+
return `.${CAPTURE_CLASS} *, .${CAPTURE_CLASS} *::before, .${CAPTURE_CLASS} *::after {
|
|
31
|
+
animation-delay: -1s !important;
|
|
32
|
+
animation-duration: 1ms !important;
|
|
33
|
+
animation-iteration-count: 1 !important;
|
|
34
|
+
animation-fill-mode: forwards !important;
|
|
35
|
+
transition: none !important;
|
|
36
|
+
}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function settle(frame: HTMLElement): Promise<void> {
|
|
40
|
+
await nextPaint();
|
|
41
|
+
await waitForFonts();
|
|
42
|
+
const deadline = performance.now() + ANIMATION_TIMEOUT_MS;
|
|
43
|
+
while (performance.now() < deadline) {
|
|
44
|
+
if (isFrameAnimationSettled(frame)) break;
|
|
45
|
+
await sleep(POLL_INTERVAL_MS);
|
|
46
|
+
}
|
|
47
|
+
await waitForDataWaitfor(frame);
|
|
48
|
+
await waitForFonts();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** One page, off screen, at 1920x1080, then down to the 1280x720 the tool returns. */
|
|
52
|
+
async function mountPage(
|
|
53
|
+
slide: SlideModule,
|
|
54
|
+
index: number,
|
|
55
|
+
step: number | undefined,
|
|
56
|
+
): Promise<{ frame: HTMLElement; dispose: () => void }> {
|
|
57
|
+
const pages = slide.default ?? [];
|
|
58
|
+
const Page = pages[index];
|
|
59
|
+
if (!Page) throw new Error(`this deck has no page ${index + 1}`);
|
|
60
|
+
|
|
61
|
+
const container = document.createElement('div');
|
|
62
|
+
container.className = CAPTURE_CLASS;
|
|
63
|
+
container.setAttribute('aria-hidden', 'true');
|
|
64
|
+
Object.assign(container.style, {
|
|
65
|
+
position: 'fixed',
|
|
66
|
+
left: '-99999px',
|
|
67
|
+
top: '0',
|
|
68
|
+
pointerEvents: 'none',
|
|
69
|
+
});
|
|
70
|
+
document.body.appendChild(container);
|
|
71
|
+
|
|
72
|
+
const style = document.createElement('style');
|
|
73
|
+
style.textContent = captureStyleText();
|
|
74
|
+
document.head.appendChild(style);
|
|
75
|
+
|
|
76
|
+
const frame = document.createElement('div');
|
|
77
|
+
frame.setAttribute('data-osd-canvas', '');
|
|
78
|
+
frame.style.width = `${CANVAS_WIDTH}px`;
|
|
79
|
+
frame.style.height = `${CANVAS_HEIGHT}px`;
|
|
80
|
+
frame.style.overflow = 'hidden';
|
|
81
|
+
const designVars = slide.design ? designToCssVars(slide.design) : null;
|
|
82
|
+
frame.style.background = designVars?.['--osd-bg'] ?? '#fff';
|
|
83
|
+
if (designVars) {
|
|
84
|
+
for (const [key, value] of Object.entries(designVars)) frame.style.setProperty(key, value);
|
|
85
|
+
}
|
|
86
|
+
container.appendChild(frame);
|
|
87
|
+
|
|
88
|
+
const root: Root = createRoot(frame);
|
|
89
|
+
const dispose = () => {
|
|
90
|
+
root.unmount();
|
|
91
|
+
container.remove();
|
|
92
|
+
style.remove();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const page = createElement(
|
|
96
|
+
SlidePageProvider,
|
|
97
|
+
{ index, total: pages.length },
|
|
98
|
+
createElement(Page),
|
|
99
|
+
);
|
|
100
|
+
try {
|
|
101
|
+
flushSync(() => {
|
|
102
|
+
root.render(
|
|
103
|
+
step === undefined ? page : <PreviewStepHost revealed={step}>{page}</PreviewStepHost>,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
await settle(frame);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
dispose();
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
return { frame, dispose };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function screenshotPage(
|
|
115
|
+
slideId: string,
|
|
116
|
+
page: number,
|
|
117
|
+
step: number | undefined,
|
|
118
|
+
): Promise<Screenshot> {
|
|
119
|
+
const slide = await loadSlide(slideId);
|
|
120
|
+
const total = slide.default?.length ?? 0;
|
|
121
|
+
if (total === 0) throw new Error('this deck has no pages');
|
|
122
|
+
if (page > total) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`this deck has ${total} page${total === 1 ? '' : 's'}, so page ${page} does not exist`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const mounted = await mountPage(slide, page - 1, step);
|
|
129
|
+
try {
|
|
130
|
+
freezeForCapture(mounted.frame);
|
|
131
|
+
const { toCanvas } = await import('html-to-image');
|
|
132
|
+
// html-to-image crops the page to width/height rather than scaling it, so
|
|
133
|
+
// the full canvas is captured and scaled down afterwards.
|
|
134
|
+
const full = await toCanvas(mounted.frame, {
|
|
135
|
+
width: CANVAS_WIDTH,
|
|
136
|
+
height: CANVAS_HEIGHT,
|
|
137
|
+
pixelRatio: 1,
|
|
138
|
+
backgroundColor: '#ffffff',
|
|
139
|
+
cacheBust: true,
|
|
140
|
+
});
|
|
141
|
+
const canvas = canvasScaled(full, WIDTH, HEIGHT);
|
|
142
|
+
let image = toBase64(await canvasJpeg(canvas, QUALITY));
|
|
143
|
+
if (image.length > MAX_BASE64) {
|
|
144
|
+
image = toBase64(await canvasJpeg(canvas, FALLBACK_QUALITY));
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
image,
|
|
148
|
+
mimeType: 'image/jpeg',
|
|
149
|
+
width: WIDTH,
|
|
150
|
+
height: HEIGHT,
|
|
151
|
+
};
|
|
152
|
+
} finally {
|
|
153
|
+
mounted.dispose();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { loadSlide } from '../../lib/slides';
|
|
5
|
+
import type { CheckResult } from '../board/model/self-check';
|
|
6
|
+
import { SelfCheckRunner } from '../board/self-check-runner';
|
|
7
|
+
import { templateFloor } from '../board/use-self-check';
|
|
8
|
+
|
|
9
|
+
export type SelfCheckSummary = {
|
|
10
|
+
findings: { page: number; kind: string; detail: string }[];
|
|
11
|
+
unread: number[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The board's own check, run on a hidden copy of the deck. The record is written
|
|
16
|
+
* back the same way the Self-check button writes it, so the board shows this run
|
|
17
|
+
* next time it is opened.
|
|
18
|
+
*/
|
|
19
|
+
export async function runSelfCheck(slideId: string): Promise<SelfCheckSummary> {
|
|
20
|
+
const deck = await loadSlide(slideId);
|
|
21
|
+
if (!deck.default || deck.default.length === 0) throw new Error('this deck has no pages');
|
|
22
|
+
const minType = await templateFloor(slideId);
|
|
23
|
+
|
|
24
|
+
const host = document.createElement('div');
|
|
25
|
+
host.setAttribute('aria-hidden', 'true');
|
|
26
|
+
document.body.appendChild(host);
|
|
27
|
+
const root = createRoot(host);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await new Promise<CheckResult>((resolve) => {
|
|
31
|
+
flushSync(() => {
|
|
32
|
+
root.render(
|
|
33
|
+
createElement(SelfCheckRunner, {
|
|
34
|
+
input: {
|
|
35
|
+
pages: deck.default,
|
|
36
|
+
design: deck.design,
|
|
37
|
+
notes: deck.notes,
|
|
38
|
+
minType,
|
|
39
|
+
},
|
|
40
|
+
onDone: resolve,
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const selfCheck = { at: Date.now(), findings: result.findings, unread: result.unread };
|
|
47
|
+
await fetch('/__board/self-check', {
|
|
48
|
+
method: 'PUT',
|
|
49
|
+
headers: { 'content-type': 'application/json' },
|
|
50
|
+
body: JSON.stringify({ slideId, selfCheck }),
|
|
51
|
+
}).catch(() => {});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
findings: result.findings.map((finding) => ({
|
|
55
|
+
page: finding.page,
|
|
56
|
+
kind: finding.kind,
|
|
57
|
+
detail: finding.detail,
|
|
58
|
+
})),
|
|
59
|
+
unread: result.unread,
|
|
60
|
+
};
|
|
61
|
+
} finally {
|
|
62
|
+
root.unmount();
|
|
63
|
+
host.remove();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -16,6 +16,7 @@ import { cn } from '@/lib/utils';
|
|
|
16
16
|
import { readPrefs } from '../agent-prefs/prefs';
|
|
17
17
|
import { useAgentPrefs } from '../agent-prefs/use-prefs';
|
|
18
18
|
import { Mascot } from '../brand/mascot';
|
|
19
|
+
import { useGuideFlags } from '../guide/use-guide';
|
|
19
20
|
import { Onboarding } from '../onboarding/onboarding';
|
|
20
21
|
import { OCCASIONS, type OccasionId } from '../templates/model';
|
|
21
22
|
import { useTemplateLibrary } from '../templates/use-library';
|
|
@@ -38,6 +39,7 @@ function fileKey(file: File): string {
|
|
|
38
39
|
export function DescribePage() {
|
|
39
40
|
const lr = useLrText();
|
|
40
41
|
const locale = useLocale();
|
|
42
|
+
const guide = useGuideFlags();
|
|
41
43
|
const location = useLocation();
|
|
42
44
|
const prefs = useAgentPrefs();
|
|
43
45
|
const { connected, loading, provider } = useAgentStatus();
|
|
@@ -410,7 +412,7 @@ export function DescribePage() {
|
|
|
410
412
|
</p>
|
|
411
413
|
)}
|
|
412
414
|
|
|
413
|
-
<Onboarding />
|
|
415
|
+
{guide?.guided === true && <Onboarding />}
|
|
414
416
|
</div>
|
|
415
417
|
);
|
|
416
418
|
}
|