@lemonriver/core 0.4.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.
- package/README.md +14 -4
- package/dist/{build-Nl7EeJ6x.js → build-CS1goZxt.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-CpC0nM3r.js → config-BpbcCbUv.js} +3673 -2065
- package/dist/{dev-BB3THd5I.js → dev-BpYnfgLL.js} +2 -2
- package/dist/{preview-BGjgTg7H.js → preview-HSzPPkSs.js} +1 -1
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +17 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
- package/src/app/lemonriver/board/blocks/classify.ts +125 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1687 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- package/src/app/lemonriver/board/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +236 -55
- package/src/app/lemonriver/board/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- package/src/app/lemonriver/outline/model.test.ts +39 -0
- package/src/app/lemonriver/outline/model.ts +12 -0
- package/src/app/lemonriver/outline/outline-page.tsx +34 -1
- package/src/app/lemonriver/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/slide-extensions.tsx +14 -2
- package/src/app/lemonriver/text/en.ts +171 -0
- package/src/app/lemonriver/text/es.ts +163 -0
- package/src/app/lemonriver/text/ja.ts +163 -0
- package/src/app/lemonriver/text/types.ts +170 -0
- package/src/app/lemonriver/text/zh-cn.ts +161 -0
- package/src/app/lemonriver/text/zh-tw.ts +161 -0
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/slide.tsx +1 -1
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closestCenter,
|
|
3
|
+
DndContext,
|
|
4
|
+
type DragEndEvent,
|
|
5
|
+
KeyboardSensor,
|
|
6
|
+
PointerSensor,
|
|
7
|
+
useSensor,
|
|
8
|
+
useSensors,
|
|
9
|
+
} from '@dnd-kit/core';
|
|
10
|
+
import {
|
|
11
|
+
horizontalListSortingStrategy,
|
|
12
|
+
SortableContext,
|
|
13
|
+
sortableKeyboardCoordinates,
|
|
14
|
+
useSortable,
|
|
15
|
+
} from '@dnd-kit/sortable';
|
|
16
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
17
|
+
import { useEffect, useState } from 'react';
|
|
18
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
19
|
+
import { cn, pad2 } from '@/lib/utils';
|
|
20
|
+
import type { Page } from '../../../lib/sdk';
|
|
21
|
+
import { useLrText } from '../../text';
|
|
22
|
+
import type { Block } from '../blocks/classify';
|
|
23
|
+
import { pageName } from '../layout';
|
|
24
|
+
import type { BoardCard } from '../model/cards';
|
|
25
|
+
import { type BoardColumn, chapterProgress, columnStarts } from '../model/structure';
|
|
26
|
+
import {
|
|
27
|
+
estimateSeconds,
|
|
28
|
+
formatDuration,
|
|
29
|
+
type Timing,
|
|
30
|
+
timelineSegments,
|
|
31
|
+
xForSeconds,
|
|
32
|
+
} from '../model/timing';
|
|
33
|
+
import { useStatusLabels } from '../page-node';
|
|
34
|
+
import { STATUS_STYLE } from '../status-style';
|
|
35
|
+
import { Progress } from './progress';
|
|
36
|
+
|
|
37
|
+
type Props = {
|
|
38
|
+
pages: Page[];
|
|
39
|
+
keys: string[];
|
|
40
|
+
cards: (BoardCard | undefined)[];
|
|
41
|
+
columns: BoardColumn[];
|
|
42
|
+
notes?: (string | undefined)[];
|
|
43
|
+
dimmed: boolean[];
|
|
44
|
+
selected: number[];
|
|
45
|
+
target: number | null;
|
|
46
|
+
targetFor: (minutes: number | null) => void;
|
|
47
|
+
onSelect: (indices: number[]) => void;
|
|
48
|
+
onOpenPage: (index: number) => void;
|
|
49
|
+
onMovePages: (moving: number[], to: number) => void;
|
|
50
|
+
blocksOfPage: (key: string) => Block[] | null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const pageIndexOf = (id: string) => Number(id.replace('page-', ''));
|
|
54
|
+
|
|
55
|
+
const BASIS: Record<Timing['basis'], 'basisNotes' | 'basisPage' | 'basisNone'> = {
|
|
56
|
+
notes: 'basisNotes',
|
|
57
|
+
page: 'basisPage',
|
|
58
|
+
none: 'basisNone',
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The deck laid out as the talk it will be: every page a stretch of the track as
|
|
63
|
+
* wide as it takes to say, chapter after chapter, with the target marked on it.
|
|
64
|
+
*/
|
|
65
|
+
export function TimelineView({
|
|
66
|
+
pages,
|
|
67
|
+
keys,
|
|
68
|
+
cards,
|
|
69
|
+
columns,
|
|
70
|
+
notes,
|
|
71
|
+
dimmed,
|
|
72
|
+
selected,
|
|
73
|
+
target,
|
|
74
|
+
targetFor,
|
|
75
|
+
onSelect,
|
|
76
|
+
onOpenPage,
|
|
77
|
+
onMovePages,
|
|
78
|
+
blocksOfPage,
|
|
79
|
+
}: Props) {
|
|
80
|
+
const lr = useLrText();
|
|
81
|
+
const locale = useLocale();
|
|
82
|
+
const [draft, setDraft] = useState(target === null ? '' : String(target));
|
|
83
|
+
|
|
84
|
+
useEffect(() => setDraft(target === null ? '' : String(target)), [target]);
|
|
85
|
+
|
|
86
|
+
const sensors = useSensors(
|
|
87
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
|
88
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const timings = pages.map((_, index) => {
|
|
92
|
+
const key = keys[index];
|
|
93
|
+
return estimateSeconds({ notes: notes?.[index], blocks: key ? blocksOfPage(key) : null });
|
|
94
|
+
});
|
|
95
|
+
const seconds = timings.map((timing) => timing.seconds);
|
|
96
|
+
const segments = timelineSegments(seconds);
|
|
97
|
+
const total = seconds.reduce((sum, value) => sum + value, 0);
|
|
98
|
+
const trackWidth = segments.reduce((sum, segment) => sum + segment.width, 0);
|
|
99
|
+
|
|
100
|
+
const targetSeconds = target === null ? null : target * 60;
|
|
101
|
+
const over = targetSeconds !== null && total > targetSeconds;
|
|
102
|
+
const targetX = targetSeconds === null ? null : xForSeconds(seconds, targetSeconds);
|
|
103
|
+
|
|
104
|
+
const starts = columnStarts(columns);
|
|
105
|
+
const chapterOf = (index: number) => {
|
|
106
|
+
for (let i = starts.length - 1; i >= 0; i--) if (index >= starts[i]) return i;
|
|
107
|
+
return 0;
|
|
108
|
+
};
|
|
109
|
+
const byKey = cards.reduce<Record<string, BoardCard>>((all, card, index) => {
|
|
110
|
+
const key = keys[index];
|
|
111
|
+
if (card && key) all[key] = card;
|
|
112
|
+
return all;
|
|
113
|
+
}, {});
|
|
114
|
+
|
|
115
|
+
const onDragEnd = (event: DragEndEvent) => {
|
|
116
|
+
const { active, over: on } = event;
|
|
117
|
+
if (!on || active.id === on.id) return;
|
|
118
|
+
const from = pageIndexOf(String(active.id));
|
|
119
|
+
const to = pageIndexOf(String(on.id));
|
|
120
|
+
if (!Number.isInteger(from) || !Number.isInteger(to)) return;
|
|
121
|
+
onMovePages([from], to);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const commitTarget = (value: string) => {
|
|
125
|
+
setDraft(value);
|
|
126
|
+
if (!value.trim()) {
|
|
127
|
+
targetFor(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const minutes = Math.trunc(Number(value));
|
|
131
|
+
if (Number.isInteger(minutes) && minutes >= 1 && minutes <= 180) targetFor(minutes);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<div className="flex h-full min-h-0 min-w-0 flex-col" data-lr-timeline-view>
|
|
136
|
+
<div className="flex shrink-0 items-center gap-3 border-b border-hairline px-6 py-2.5">
|
|
137
|
+
<span
|
|
138
|
+
className={cn('text-[13px] tabular-nums', over ? 'text-destructive' : 'text-foreground')}
|
|
139
|
+
data-lr-total
|
|
140
|
+
data-over={over ? 'true' : 'false'}
|
|
141
|
+
>
|
|
142
|
+
{format(lr.board.totalDuration, { d: formatDuration(total, locale.id) })}
|
|
143
|
+
</span>
|
|
144
|
+
{target !== null && targetSeconds !== null && (
|
|
145
|
+
<span
|
|
146
|
+
className={cn(
|
|
147
|
+
'text-[12px] tabular-nums',
|
|
148
|
+
over ? 'text-destructive' : 'text-muted-foreground',
|
|
149
|
+
)}
|
|
150
|
+
data-lr-target-diff
|
|
151
|
+
>
|
|
152
|
+
{over
|
|
153
|
+
? format(lr.board.overTarget, {
|
|
154
|
+
d: formatDuration(total - targetSeconds, locale.id),
|
|
155
|
+
})
|
|
156
|
+
: format(lr.board.underTarget, {
|
|
157
|
+
d: formatDuration(targetSeconds - total, locale.id),
|
|
158
|
+
})}
|
|
159
|
+
</span>
|
|
160
|
+
)}
|
|
161
|
+
<label className="ml-auto flex items-center gap-1.5 text-[12px] text-muted-foreground">
|
|
162
|
+
{lr.board.target}
|
|
163
|
+
<input
|
|
164
|
+
type="number"
|
|
165
|
+
min={1}
|
|
166
|
+
max={180}
|
|
167
|
+
value={draft}
|
|
168
|
+
aria-label={lr.board.target}
|
|
169
|
+
data-lr-target
|
|
170
|
+
onChange={(event) => commitTarget(event.currentTarget.value)}
|
|
171
|
+
className="w-16 rounded-[4px] border border-hairline bg-background px-2 py-1 text-[12.5px] tabular-nums text-foreground outline-none focus:ring-1 focus:ring-brand/50"
|
|
172
|
+
/>
|
|
173
|
+
</label>
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<div className="min-h-0 w-full flex-1 overflow-auto px-6 py-5">
|
|
177
|
+
{pages.length === 0 ? null : (
|
|
178
|
+
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={onDragEnd}>
|
|
179
|
+
<div className="relative" style={{ width: trackWidth }}>
|
|
180
|
+
<div className="mb-2 flex">
|
|
181
|
+
{columns.map((column, columnIndex) => {
|
|
182
|
+
const from = starts[columnIndex] ?? 0;
|
|
183
|
+
const width = segments
|
|
184
|
+
.slice(from, from + column.size)
|
|
185
|
+
.reduce((sum, segment) => sum + segment.width, 0);
|
|
186
|
+
const chapterSeconds = seconds
|
|
187
|
+
.slice(from, from + column.size)
|
|
188
|
+
.reduce((sum, value) => sum + value, 0);
|
|
189
|
+
const progress = chapterProgress(byKey, keys.slice(from, from + column.size));
|
|
190
|
+
return (
|
|
191
|
+
<div
|
|
192
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a chapter is its position in the deck
|
|
193
|
+
key={`chapter-${columnIndex}`}
|
|
194
|
+
data-lr-timeline-chapter
|
|
195
|
+
className={cn(
|
|
196
|
+
'flex min-w-0 items-baseline gap-1.5 overflow-hidden pr-2',
|
|
197
|
+
columnIndex > 0 && 'border-l border-hairline pl-2',
|
|
198
|
+
)}
|
|
199
|
+
style={{ width }}
|
|
200
|
+
>
|
|
201
|
+
<span className="eyebrow truncate text-foreground">
|
|
202
|
+
{column.title || format(lr.board.columnFallback, { n: columnIndex + 1 })}
|
|
203
|
+
</span>
|
|
204
|
+
{/* A short chapter cannot show its numbers; the name is what it
|
|
205
|
+
has to keep. */}
|
|
206
|
+
{width >= 120 && (
|
|
207
|
+
<span className="shrink-0 text-[11px] text-muted-foreground tabular-nums">
|
|
208
|
+
{formatDuration(chapterSeconds, locale.id)}
|
|
209
|
+
</span>
|
|
210
|
+
)}
|
|
211
|
+
{width >= 140 && <Progress progress={progress} compact={width < 260} />}
|
|
212
|
+
</div>
|
|
213
|
+
);
|
|
214
|
+
})}
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<div className="relative flex h-20" data-lr-timeline-track>
|
|
218
|
+
<SortableContext
|
|
219
|
+
items={segments.map((_, index) => `page-${index}`)}
|
|
220
|
+
strategy={horizontalListSortingStrategy}
|
|
221
|
+
>
|
|
222
|
+
{segments.map((segment, index) => {
|
|
223
|
+
const chapter = chapterOf(index);
|
|
224
|
+
const chapterHead = index === starts[chapter];
|
|
225
|
+
return (
|
|
226
|
+
<Segment
|
|
227
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: a page is its position in the deck
|
|
228
|
+
key={`page-${index}`}
|
|
229
|
+
id={`page-${index}`}
|
|
230
|
+
index={index}
|
|
231
|
+
width={segment.width}
|
|
232
|
+
chapterHead={chapterHead}
|
|
233
|
+
pages={pages}
|
|
234
|
+
card={cards[index]}
|
|
235
|
+
timing={timings[index]}
|
|
236
|
+
dimmed={dimmed[index] === true}
|
|
237
|
+
beyond={
|
|
238
|
+
targetX !== null && segment.start >= targetX && targetSeconds !== null
|
|
239
|
+
}
|
|
240
|
+
selected={selected.includes(index)}
|
|
241
|
+
onSelect={() => onSelect([index])}
|
|
242
|
+
onOpen={() => onOpenPage(index)}
|
|
243
|
+
/>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
</SortableContext>
|
|
247
|
+
|
|
248
|
+
{targetX !== null && (
|
|
249
|
+
<span
|
|
250
|
+
aria-hidden
|
|
251
|
+
data-lr-target-line
|
|
252
|
+
className="pointer-events-none absolute top-0 bottom-0 w-px bg-destructive/70"
|
|
253
|
+
style={{ left: Math.min(targetX, trackWidth) }}
|
|
254
|
+
/>
|
|
255
|
+
)}
|
|
256
|
+
</div>
|
|
257
|
+
</div>
|
|
258
|
+
</DndContext>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function Segment({
|
|
266
|
+
id,
|
|
267
|
+
index,
|
|
268
|
+
width,
|
|
269
|
+
chapterHead,
|
|
270
|
+
pages,
|
|
271
|
+
card,
|
|
272
|
+
timing,
|
|
273
|
+
dimmed,
|
|
274
|
+
beyond,
|
|
275
|
+
selected,
|
|
276
|
+
onSelect,
|
|
277
|
+
onOpen,
|
|
278
|
+
}: {
|
|
279
|
+
id: string;
|
|
280
|
+
index: number;
|
|
281
|
+
width: number;
|
|
282
|
+
chapterHead: boolean;
|
|
283
|
+
pages: Page[];
|
|
284
|
+
card?: BoardCard;
|
|
285
|
+
timing: Timing;
|
|
286
|
+
dimmed: boolean;
|
|
287
|
+
beyond: boolean;
|
|
288
|
+
selected: boolean;
|
|
289
|
+
onSelect: () => void;
|
|
290
|
+
onOpen: () => void;
|
|
291
|
+
}) {
|
|
292
|
+
const lr = useLrText();
|
|
293
|
+
const locale = useLocale();
|
|
294
|
+
const labels = useStatusLabels();
|
|
295
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
296
|
+
id,
|
|
297
|
+
});
|
|
298
|
+
const status = card?.status;
|
|
299
|
+
const title = card?.title || pageName(pages[index]) || '';
|
|
300
|
+
const duration = formatDuration(timing.seconds, locale.id);
|
|
301
|
+
const hint = [
|
|
302
|
+
`${pad2(index + 1)}${title ? ` ${title}` : ''}`,
|
|
303
|
+
duration,
|
|
304
|
+
lr.board[BASIS[timing.basis]],
|
|
305
|
+
status ? labels[status] : null,
|
|
306
|
+
]
|
|
307
|
+
.filter(Boolean)
|
|
308
|
+
.join(' · ');
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<button
|
|
312
|
+
ref={setNodeRef}
|
|
313
|
+
type="button"
|
|
314
|
+
title={hint}
|
|
315
|
+
data-lr-timeline-segment
|
|
316
|
+
data-page={index + 1}
|
|
317
|
+
data-selected={selected ? 'true' : 'false'}
|
|
318
|
+
onClick={onSelect}
|
|
319
|
+
onDoubleClick={onOpen}
|
|
320
|
+
style={{ width, transform: CSS.Transform.toString(transform), transition }}
|
|
321
|
+
className={cn(
|
|
322
|
+
'relative flex h-full flex-col items-start justify-start overflow-hidden rounded-[4px] border-r border-background px-1.5 py-1 text-left',
|
|
323
|
+
status ? STATUS_STYLE[status].bar : 'bg-muted',
|
|
324
|
+
'hover:brightness-[0.97]',
|
|
325
|
+
chapterHead && 'border-l-2 border-l-foreground/25',
|
|
326
|
+
selected && 'ring-2 ring-brand ring-inset',
|
|
327
|
+
dimmed && 'opacity-35',
|
|
328
|
+
beyond && 'opacity-40',
|
|
329
|
+
isDragging && 'z-10 opacity-70 shadow-[var(--lr-shadow-1)]',
|
|
330
|
+
)}
|
|
331
|
+
{...attributes}
|
|
332
|
+
{...listeners}
|
|
333
|
+
>
|
|
334
|
+
<span className="text-[11px] tabular-nums text-muted-foreground">{pad2(index + 1)}</span>
|
|
335
|
+
{width >= 120 && title && (
|
|
336
|
+
<span className="line-clamp-2 text-[11.5px] text-foreground/80">{title}</span>
|
|
337
|
+
)}
|
|
338
|
+
<span className="mt-auto text-[10.5px] tabular-nums text-muted-foreground">{duration}</span>
|
|
339
|
+
</button>
|
|
340
|
+
);
|
|
341
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { AgentItem } from '../../../agent/types';
|
|
2
3
|
import { DEFAULT_PREFS } from '../agent-prefs/prefs';
|
|
3
4
|
import {
|
|
4
5
|
afterTurn,
|
|
5
6
|
collectDecisions,
|
|
6
7
|
driverAction,
|
|
7
8
|
insertPage,
|
|
9
|
+
lastErrorText,
|
|
8
10
|
MAX_BRIEF,
|
|
9
11
|
MAX_DECISIONS,
|
|
10
12
|
MAX_ITEMS,
|
|
@@ -631,3 +633,40 @@ describe('collectDecisions', () => {
|
|
|
631
633
|
expect(collectDecisions([], many)).toHaveLength(MAX_DECISIONS);
|
|
632
634
|
});
|
|
633
635
|
});
|
|
636
|
+
|
|
637
|
+
describe('lastErrorText', () => {
|
|
638
|
+
const user = (id: string): AgentItem => ({ kind: 'user', id, ts: '', text: 'go' });
|
|
639
|
+
const error = (id: string, text: string): AgentItem => ({ kind: 'error', id, ts: '', text });
|
|
640
|
+
const assistant = (id: string): AgentItem => ({
|
|
641
|
+
kind: 'assistant',
|
|
642
|
+
id,
|
|
643
|
+
ts: '',
|
|
644
|
+
text: 'ok',
|
|
645
|
+
streaming: false,
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
it('returns the last error after the message the user sent', () => {
|
|
649
|
+
const items = [user('u1'), error('e1', 'old'), assistant('a1'), error('e2', 'new')];
|
|
650
|
+
expect(lastErrorText(items, 'u1')).toBe('new');
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it('ignores errors that came before the user message', () => {
|
|
654
|
+
const items = [error('e0', 'before'), user('u1'), assistant('a1'), user('u2')];
|
|
655
|
+
expect(lastErrorText(items, 'u2')).toBeNull();
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
it('returns null when the turn carried no error', () => {
|
|
659
|
+
expect(lastErrorText([user('u1'), assistant('a1')], 'u1')).toBeNull();
|
|
660
|
+
expect(lastErrorText([], null)).toBeNull();
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it('reads every item when the user message is unknown', () => {
|
|
664
|
+
expect(lastErrorText([error('e1', 'one'), assistant('a1')], null)).toBe('one');
|
|
665
|
+
expect(lastErrorText([user('u1'), error('e1', 'one')], 'missing')).toBe('one');
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it('clips the text to 200 characters', () => {
|
|
669
|
+
const long = 'x'.repeat(500);
|
|
670
|
+
expect(lastErrorText([user('u1'), error('e1', long)], 'u1')).toHaveLength(200);
|
|
671
|
+
});
|
|
672
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AgentItem } from '../../../agent/types';
|
|
1
2
|
import { type AgentPrefs, prefsLines, sanitizePrefs } from '../agent-prefs/prefs';
|
|
2
3
|
|
|
3
4
|
export const PAGE_KINDS = ['cover', 'kpi', 'chart', 'list', 'page', 'end'] as const;
|
|
@@ -413,6 +414,17 @@ export type TeamState = {
|
|
|
413
414
|
review: TeamHelperState;
|
|
414
415
|
};
|
|
415
416
|
|
|
417
|
+
// The failure the user needs to see is the last one after the message they sent.
|
|
418
|
+
export function lastErrorText(items: AgentItem[], userItemId: string | null): string | null {
|
|
419
|
+
const start = userItemId ? items.findIndex((item) => item.id === userItemId) : -1;
|
|
420
|
+
const after = start === -1 ? items : items.slice(start + 1);
|
|
421
|
+
for (let i = after.length - 1; i >= 0; i--) {
|
|
422
|
+
const item = after[i];
|
|
423
|
+
if (item.kind === 'error') return item.text.slice(0, 200);
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
416
428
|
export function teamState(
|
|
417
429
|
outline: Outline,
|
|
418
430
|
seen: { running: boolean; waitingForAnswer: boolean; action: DriverAction },
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
sendMessage,
|
|
34
34
|
setActiveSession,
|
|
35
35
|
setDockOpen,
|
|
36
|
+
useAgentSession,
|
|
36
37
|
useAgentSessions,
|
|
37
38
|
useAgentStatus,
|
|
38
39
|
} from '@/lib/agent/use-agent';
|
|
@@ -44,6 +45,7 @@ import { useLrText } from '../text';
|
|
|
44
45
|
import type { LrText } from '../text/types';
|
|
45
46
|
import {
|
|
46
47
|
insertPage,
|
|
48
|
+
lastErrorText,
|
|
47
49
|
movePage,
|
|
48
50
|
type Outline,
|
|
49
51
|
type OutlinePage,
|
|
@@ -84,6 +86,16 @@ export function OutlineView() {
|
|
|
84
86
|
const navigate = useNavigate();
|
|
85
87
|
const { sessions } = useAgentSessions();
|
|
86
88
|
const { provider } = useAgentStatus();
|
|
89
|
+
const latestSession = sessions
|
|
90
|
+
.filter((session) => session.slideId === slideId)
|
|
91
|
+
.sort((a, b) => a.updatedAt.localeCompare(b.updatedAt))
|
|
92
|
+
.at(-1);
|
|
93
|
+
const session = useAgentSession(latestSession?.id ?? null);
|
|
94
|
+
const sessionItems = session?.items ?? [];
|
|
95
|
+
const failureReason = lastErrorText(
|
|
96
|
+
sessionItems,
|
|
97
|
+
[...sessionItems].reverse().find((item) => item.kind === 'user')?.id ?? null,
|
|
98
|
+
);
|
|
87
99
|
const [outline, setOutline] = useState<Outline | null | undefined>(undefined);
|
|
88
100
|
const [items, setItems] = useState<OutlinePage[]>([]);
|
|
89
101
|
const [building, setBuilding] = useState(false);
|
|
@@ -270,7 +282,15 @@ export function OutlineView() {
|
|
|
270
282
|
<div className="min-w-0 flex-1">
|
|
271
283
|
<p className="text-[15px] font-semibold">{lr.failedTitle}</p>
|
|
272
284
|
<p className="mt-1 text-[13px] text-muted-foreground">{lr.failedHint}</p>
|
|
273
|
-
|
|
285
|
+
{failureReason && (
|
|
286
|
+
<p
|
|
287
|
+
data-lr-outline-error
|
|
288
|
+
className="mt-1.5 select-text text-[12px] leading-relaxed text-muted-foreground"
|
|
289
|
+
>
|
|
290
|
+
{format(lr.failedReason, { reason: failureReason })}
|
|
291
|
+
</p>
|
|
292
|
+
)}
|
|
293
|
+
<div className="mt-3 flex flex-wrap items-center gap-2">
|
|
274
294
|
<Button
|
|
275
295
|
type="button"
|
|
276
296
|
variant="outline"
|
|
@@ -283,6 +303,19 @@ export function OutlineView() {
|
|
|
283
303
|
<Button type="button" variant="ghost" size="sm" onClick={editBrief}>
|
|
284
304
|
{lr.editBrief}
|
|
285
305
|
</Button>
|
|
306
|
+
{failureReason && (
|
|
307
|
+
<Button
|
|
308
|
+
type="button"
|
|
309
|
+
variant="ghost"
|
|
310
|
+
size="sm"
|
|
311
|
+
onClick={() => {
|
|
312
|
+
setDockOpen(true);
|
|
313
|
+
window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}`);
|
|
314
|
+
}}
|
|
315
|
+
>
|
|
316
|
+
{lr.openAgent}
|
|
317
|
+
</Button>
|
|
318
|
+
)}
|
|
286
319
|
</div>
|
|
287
320
|
</div>
|
|
288
321
|
</div>
|
|
@@ -5,6 +5,7 @@ import { useLocale } from '@/lib/use-locale';
|
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
6
|
import type { AgentPrefs } from '../agent-prefs/prefs';
|
|
7
7
|
import { updateAgentPrefs, useAgentPrefs } from '../agent-prefs/use-prefs';
|
|
8
|
+
import { AgentProvidersSection } from '../agent-providers/section';
|
|
8
9
|
import { HelperMascot, type HelperRole } from '../brand/mascot';
|
|
9
10
|
import { ONBOARDED_KEY } from '../onboarding/onboarding';
|
|
10
11
|
import { useLrText } from '../text';
|
|
@@ -164,6 +165,8 @@ export function SettingsPage() {
|
|
|
164
165
|
</div>
|
|
165
166
|
</section>
|
|
166
167
|
|
|
168
|
+
{import.meta.env.DEV && <AgentProvidersSection />}
|
|
169
|
+
|
|
167
170
|
{import.meta.env.DEV && (
|
|
168
171
|
<section
|
|
169
172
|
data-lr-agent-prefs
|
|
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
|
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
6
|
-
import { hasModifier,
|
|
6
|
+
import { hasModifier, isTypingTarget } from '@/lib/keys';
|
|
7
7
|
import { cn } from '@/lib/utils';
|
|
8
8
|
import { useSlot } from './chrome/use-slot';
|
|
9
9
|
import { isFeatureEnabled } from './features';
|
|
@@ -16,6 +16,18 @@ type Props = {
|
|
|
16
16
|
overviewOpen: boolean;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* A key pressed with focus inside a menu or dialog belongs to that overlay. A
|
|
21
|
+
* focused button does not: the shortcut has to reach the page from any view,
|
|
22
|
+
* including the asset grid, whose own controls sit under the pointer.
|
|
23
|
+
*/
|
|
24
|
+
function isInsideOverlay(target: EventTarget | null): boolean {
|
|
25
|
+
return (
|
|
26
|
+
target instanceof Element &&
|
|
27
|
+
!!target.closest('[role="dialog"], [role="menu"], [role="listbox"]')
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
export function SlideExtensions({ slideId, overviewOpen }: Props) {
|
|
20
32
|
const enabled = isFeatureEnabled('board');
|
|
21
33
|
const navigate = useNavigate();
|
|
@@ -28,7 +40,7 @@ export function SlideExtensions({ slideId, overviewOpen }: Props) {
|
|
|
28
40
|
const onKey = (e: KeyboardEvent) => {
|
|
29
41
|
if (
|
|
30
42
|
isTypingTarget(e.target) ||
|
|
31
|
-
|
|
43
|
+
isInsideOverlay(e.target) ||
|
|
32
44
|
e.isComposing ||
|
|
33
45
|
e.keyCode === 229 ||
|
|
34
46
|
e.defaultPrevented
|