@saadnvd1/agent-os 0.3.770 → 0.3.777
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/app/api/live-shares/[id]/route.ts +72 -0
- package/app/api/live-shares/route.test.ts +45 -0
- package/app/api/live-shares/route.ts +40 -0
- package/app/api/sessions/[id]/artifacts/[artifactId]/compare/route.ts +41 -0
- package/app/api/shares/preview/route.ts +6 -1
- package/app/api/shares/route.test.ts +51 -0
- package/app/page.tsx +6 -0
- package/components/Artifacts/ArtifactActions.tsx +27 -3
- package/components/Artifacts/ArtifactPreview.tsx +27 -12
- package/components/Artifacts/Compare/DiffView.tsx +116 -0
- package/components/Artifacts/Compare/SideBySide.tsx +60 -0
- package/components/Artifacts/Compare/VersionPicker.tsx +47 -0
- package/components/Artifacts/Compare/index.tsx +191 -0
- package/components/Chat/ChatPanel.tsx +6 -0
- package/components/Chat/EventRow.tsx +6 -0
- package/components/Chat/Messages.tsx +6 -0
- package/components/Chat/ShareFromHere.tsx +39 -0
- package/components/CommandPalette/CommandPalette.tsx +5 -4
- package/components/CommandPalette/CommandsBody.tsx +97 -131
- package/components/CommandPalette/PaletteRows.tsx +79 -0
- package/components/CommandPalette/PaletteTabs.tsx +51 -0
- package/components/CommandPalette/conversations/ConversationSearch.tsx +13 -11
- package/components/CommandPalette/useAppCommands.ts +14 -0
- package/components/CommandPalette/useConversationRows.ts +55 -0
- package/components/Live/GuestPromptCard.tsx +64 -0
- package/components/Live/InviteDialog.tsx +225 -0
- package/components/Live/LiveChip.tsx +109 -0
- package/components/Live/LivePanel.tsx +81 -0
- package/components/Live/LobbyCard.tsx +64 -0
- package/components/Pane/MobileTabBar.tsx +8 -0
- package/components/Pane/PaneMenu.tsx +10 -0
- package/components/SessionList/SessionRowMenu.tsx +6 -0
- package/components/SessionList/useSessionSwitching.ts +2 -2
- package/components/Share/MessageList.tsx +87 -0
- package/components/Share/RangePicker.tsx +59 -0
- package/components/Share/ShareDialog.tsx +113 -52
- package/components/Shares/SharedLinksPanel.tsx +51 -0
- package/data/live/index.ts +2 -0
- package/data/live/keys.ts +4 -0
- package/data/live/queries.ts +81 -0
- package/data/session-artifacts/keys.ts +2 -0
- package/data/session-artifacts/queries.ts +25 -0
- package/data/shares/queries.ts +11 -0
- package/hooks/usePaletteCommands.ts +4 -1
- package/lib/artifacts/actions.ts +11 -1
- package/lib/artifacts/compare/compareVersions.ts +66 -0
- package/lib/artifacts/compare/diff.ts +178 -0
- package/lib/artifacts/compare/extractText.ts +64 -0
- package/lib/artifacts/compare/index.ts +11 -0
- package/lib/artifacts/compare/types.ts +44 -0
- package/lib/artifacts/match.ts +64 -0
- package/lib/artifacts/store.ts +39 -10
- package/lib/artifacts/tools.ts +9 -4
- package/lib/artifacts/versions.ts +2 -1
- package/lib/chat/events.ts +4 -1
- package/lib/chat/registry.ts +10 -0
- package/lib/connect/control-api.ts +44 -0
- package/lib/db/migrations/20261029T1400_live_shares.ts +42 -0
- package/lib/live/clean.ts +54 -0
- package/lib/live/frames.ts +132 -0
- package/lib/live/inbox.ts +225 -0
- package/lib/live/publisher.ts +84 -0
- package/lib/live/ring.ts +61 -0
- package/lib/live/runtime.ts +51 -0
- package/lib/live/service.ts +318 -0
- package/lib/live/socket.ts +293 -0
- package/lib/live/store.ts +149 -0
- package/lib/live/types.ts +39 -0
- package/lib/palette/registry.ts +71 -17
- package/lib/palette/sections.ts +143 -0
- package/lib/palette/tabs.ts +21 -0
- package/lib/palette/usage.ts +81 -0
- package/lib/security/demo.ts +3 -0
- package/lib/share/connect.ts +24 -0
- package/lib/share/markdown.ts +3 -0
- package/lib/share/range.ts +189 -0
- package/lib/share/redact.ts +23 -1
- package/lib/share/render.tsx +3 -0
- package/lib/share/secret-patterns.ts +77 -0
- package/lib/share/service.ts +64 -19
- package/lib/share/snapshot.ts +39 -2
- package/lib/share/styles.ts +2 -0
- package/lib/share/view.ts +11 -0
- package/lib/sidebar/row-menu.ts +2 -0
- package/package.json +1 -1
- package/server.ts +2 -0
- package/stores/liveUi.ts +17 -0
- package/stores/palette.ts +13 -11
- package/stores/shareUi.ts +6 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { toast } from "sonner";
|
|
4
|
+
import { useEndLive, useLiveAction, useLiveShare } from "@/data/live";
|
|
5
|
+
import { liveUiActions } from "@/stores/liveUi";
|
|
6
|
+
import { GuestPromptCard } from "./GuestPromptCard";
|
|
7
|
+
import { LiveChip } from "./LiveChip";
|
|
8
|
+
import { LobbyCard } from "./LobbyCard";
|
|
9
|
+
|
|
10
|
+
// Above the composer while a session has a live link: the Live chip, who is
|
|
11
|
+
// waiting to come in, and the suggestions to send, edit or dismiss.
|
|
12
|
+
export function LivePanel({
|
|
13
|
+
sessionId,
|
|
14
|
+
title,
|
|
15
|
+
onEdit,
|
|
16
|
+
}: {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
title: string;
|
|
19
|
+
onEdit: (text: string) => void;
|
|
20
|
+
}) {
|
|
21
|
+
const query = useLiveShare(sessionId);
|
|
22
|
+
const share = query.data?.share;
|
|
23
|
+
const act = useLiveAction(share?.id ?? "");
|
|
24
|
+
const end = useEndLive(share?.id ?? "");
|
|
25
|
+
if (!share) return null;
|
|
26
|
+
const busy = act.isPending || end.isPending;
|
|
27
|
+
const fail = (e: Error) => toast.error(e.message);
|
|
28
|
+
const lobby = share.guests.filter((g) => g.status === "pending");
|
|
29
|
+
return (
|
|
30
|
+
<div className="mx-auto flex w-full max-w-3xl flex-col gap-2 px-3 pb-2">
|
|
31
|
+
<LiveChip
|
|
32
|
+
share={share}
|
|
33
|
+
busy={busy}
|
|
34
|
+
onKick={(guestId) =>
|
|
35
|
+
act.mutate({ action: "kick", guestId }, { onError: fail })
|
|
36
|
+
}
|
|
37
|
+
onEnd={() => end.mutate(undefined, { onError: fail })}
|
|
38
|
+
onInvite={() => liveUiActions.open(sessionId, title)}
|
|
39
|
+
/>
|
|
40
|
+
{lobby.map((g) => (
|
|
41
|
+
<LobbyCard
|
|
42
|
+
key={g.id}
|
|
43
|
+
guest={g}
|
|
44
|
+
busy={busy}
|
|
45
|
+
onAdmit={() =>
|
|
46
|
+
act.mutate({ action: "admit", guestId: g.id }, { onError: fail })
|
|
47
|
+
}
|
|
48
|
+
onDeny={() =>
|
|
49
|
+
act.mutate({ action: "deny", guestId: g.id }, { onError: fail })
|
|
50
|
+
}
|
|
51
|
+
/>
|
|
52
|
+
))}
|
|
53
|
+
{share.suggestions.map((s) => (
|
|
54
|
+
<GuestPromptCard
|
|
55
|
+
key={s.id}
|
|
56
|
+
suggestion={s}
|
|
57
|
+
busy={busy}
|
|
58
|
+
onSend={() =>
|
|
59
|
+
act.mutate(
|
|
60
|
+
{ action: "send", suggestionId: s.id },
|
|
61
|
+
{ onError: fail }
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
onEdit={() => {
|
|
65
|
+
onEdit(s.text);
|
|
66
|
+
act.mutate(
|
|
67
|
+
{ action: "dismiss", suggestionId: s.id },
|
|
68
|
+
{ onError: fail }
|
|
69
|
+
);
|
|
70
|
+
}}
|
|
71
|
+
onDismiss={() =>
|
|
72
|
+
act.mutate(
|
|
73
|
+
{ action: "dismiss", suggestionId: s.id },
|
|
74
|
+
{ onError: fail }
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
/>
|
|
78
|
+
))}
|
|
79
|
+
</div>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Check, UserRound, X } from "lucide-react";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
import type { LiveView } from "@/data/live";
|
|
6
|
+
|
|
7
|
+
type Guest = LiveView["guests"][number];
|
|
8
|
+
|
|
9
|
+
// Someone opened the link and is waiting. The name is whatever they typed.
|
|
10
|
+
export function LobbyCard({
|
|
11
|
+
guest,
|
|
12
|
+
busy,
|
|
13
|
+
onAdmit,
|
|
14
|
+
onDeny,
|
|
15
|
+
}: {
|
|
16
|
+
guest: Guest;
|
|
17
|
+
busy: boolean;
|
|
18
|
+
onAdmit: () => void;
|
|
19
|
+
onDeny: () => void;
|
|
20
|
+
}) {
|
|
21
|
+
return (
|
|
22
|
+
<div
|
|
23
|
+
role="group"
|
|
24
|
+
aria-label={`${guest.name} wants to join`}
|
|
25
|
+
className="bg-muted/60 flex flex-col gap-2 rounded-xl p-3 shadow-sm sm:flex-row sm:items-center"
|
|
26
|
+
>
|
|
27
|
+
<div className="flex min-w-0 flex-1 items-start gap-2">
|
|
28
|
+
<UserRound
|
|
29
|
+
className="text-muted-foreground mt-0.5 h-4 w-4 shrink-0"
|
|
30
|
+
aria-hidden
|
|
31
|
+
/>
|
|
32
|
+
<div className="min-w-0 text-sm">
|
|
33
|
+
<p className="[overflow-wrap:anywhere]">
|
|
34
|
+
<span className="font-medium">{guest.name}</span> wants to join
|
|
35
|
+
</p>
|
|
36
|
+
<p className="text-muted-foreground text-xs">
|
|
37
|
+
{guest.duplicateName
|
|
38
|
+
? "Another guest here has the same name. Names aren't verified."
|
|
39
|
+
: "Names aren't verified."}
|
|
40
|
+
</p>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<div className="flex gap-2">
|
|
44
|
+
<Button
|
|
45
|
+
className="min-h-11 flex-1 sm:flex-none"
|
|
46
|
+
disabled={busy}
|
|
47
|
+
onClick={onAdmit}
|
|
48
|
+
>
|
|
49
|
+
<Check className="h-4 w-4" />
|
|
50
|
+
Admit
|
|
51
|
+
</Button>
|
|
52
|
+
<Button
|
|
53
|
+
variant="outline"
|
|
54
|
+
className="min-h-11 flex-1 sm:flex-none"
|
|
55
|
+
disabled={busy}
|
|
56
|
+
onClick={onDeny}
|
|
57
|
+
>
|
|
58
|
+
<X className="h-4 w-4" />
|
|
59
|
+
Deny
|
|
60
|
+
</Button>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
Search,
|
|
25
25
|
Star,
|
|
26
26
|
Share2,
|
|
27
|
+
Users,
|
|
27
28
|
Download,
|
|
28
29
|
TextSearch,
|
|
29
30
|
Eye,
|
|
@@ -36,6 +37,7 @@ import { HostBadge } from "@/components/Hosts/HostBadge";
|
|
|
36
37
|
import { RolePill } from "@/components/Sessions/RolePill";
|
|
37
38
|
import { bookmarksUiActions } from "@/stores/bookmarksUi";
|
|
38
39
|
import { shareUiActions } from "@/stores/shareUi";
|
|
40
|
+
import { liveUiActions } from "@/stores/liveUi";
|
|
39
41
|
import { exportUiActions } from "@/stores/exportUi";
|
|
40
42
|
import { analystUiActions } from "@/stores/analystUi";
|
|
41
43
|
import { useCanAddAnalyst } from "@/components/Analyst/pair";
|
|
@@ -228,6 +230,12 @@ export function MobileTabBar({
|
|
|
228
230
|
<Share2 className="h-4 w-4" />
|
|
229
231
|
Share…
|
|
230
232
|
</DropdownMenuItem>
|
|
233
|
+
<DropdownMenuItem
|
|
234
|
+
onSelect={() => liveUiActions.open(session.id, session.name)}
|
|
235
|
+
>
|
|
236
|
+
<Users className="h-4 w-4" />
|
|
237
|
+
Invite to watch live…
|
|
238
|
+
</DropdownMenuItem>
|
|
231
239
|
<DropdownMenuItem
|
|
232
240
|
onSelect={() =>
|
|
233
241
|
exportUiActions.open(session.id, session.name)
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Link,
|
|
9
9
|
MoreHorizontal,
|
|
10
10
|
Share2,
|
|
11
|
+
Users,
|
|
11
12
|
Download,
|
|
12
13
|
SplitSquareHorizontal,
|
|
13
14
|
SplitSquareVertical,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
import { copySessionLink, writeClipboard } from "@/hooks/useCopyToClipboard";
|
|
30
31
|
import type { Session } from "@/lib/db";
|
|
31
32
|
import { shareUiActions } from "@/stores/shareUi";
|
|
33
|
+
import { liveUiActions } from "@/stores/liveUi";
|
|
32
34
|
import { exportUiActions } from "@/stores/exportUi";
|
|
33
35
|
import { analystUiActions } from "@/stores/analystUi";
|
|
34
36
|
import { useCanAddAnalyst } from "@/components/Analyst/pair";
|
|
@@ -125,6 +127,14 @@ export function PaneMenu({
|
|
|
125
127
|
Share…
|
|
126
128
|
</DropdownMenuItem>
|
|
127
129
|
)}
|
|
130
|
+
{session.view === "chat" && (
|
|
131
|
+
<DropdownMenuItem
|
|
132
|
+
onSelect={() => liveUiActions.open(session.id, session.name)}
|
|
133
|
+
>
|
|
134
|
+
<Users className="h-4 w-4" />
|
|
135
|
+
Invite to watch live…
|
|
136
|
+
</DropdownMenuItem>
|
|
137
|
+
)}
|
|
128
138
|
{session.view === "chat" && (
|
|
129
139
|
<DropdownMenuItem
|
|
130
140
|
onSelect={() => exportUiActions.open(session.id, session.name)}
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
KanbanSquare,
|
|
16
16
|
Link,
|
|
17
17
|
Share2,
|
|
18
|
+
Users,
|
|
18
19
|
Download,
|
|
19
20
|
Loader2,
|
|
20
21
|
Pencil,
|
|
@@ -57,6 +58,7 @@ import { copySessionLink } from "@/hooks/useCopyToClipboard";
|
|
|
57
58
|
import { useLinkedHostNames } from "@/data/hosts";
|
|
58
59
|
import { remoteBlocks, remoteNote } from "@/lib/hosts/remote-menu";
|
|
59
60
|
import { movableSession } from "@/lib/tasks/move-targets";
|
|
61
|
+
import { liveUiActions } from "@/stores/liveUi";
|
|
60
62
|
import { useMoveTargets } from "@/data/tasks/move";
|
|
61
63
|
import {
|
|
62
64
|
rowMenu,
|
|
@@ -200,6 +202,10 @@ export function SessionRowMenu({
|
|
|
200
202
|
title: session.name,
|
|
201
203
|
})
|
|
202
204
|
);
|
|
205
|
+
case "invite-live":
|
|
206
|
+
return item("Invite to watch live…", Users, () =>
|
|
207
|
+
liveUiActions.open(session.id, session.name)
|
|
208
|
+
);
|
|
203
209
|
case "export":
|
|
204
210
|
return item("Export for AI…", Download, () =>
|
|
205
211
|
exportUiActions.open(session.id, session.name)
|
|
@@ -36,7 +36,7 @@ export function useSessionSwitching(
|
|
|
36
36
|
{
|
|
37
37
|
id: "session.previous",
|
|
38
38
|
title: "Previous session",
|
|
39
|
-
group: "
|
|
39
|
+
group: "Actions",
|
|
40
40
|
hint: chordHint(PREVIOUS),
|
|
41
41
|
keywords: ["switch", "up"],
|
|
42
42
|
icon: MessageSquare,
|
|
@@ -45,7 +45,7 @@ export function useSessionSwitching(
|
|
|
45
45
|
{
|
|
46
46
|
id: "session.next",
|
|
47
47
|
title: "Next session",
|
|
48
|
-
group: "
|
|
48
|
+
group: "Actions",
|
|
49
49
|
hint: chordHint(NEXT),
|
|
50
50
|
keywords: ["switch", "down"],
|
|
51
51
|
icon: MessageSquare,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { TYPE_LABEL } from "@/lib/share/view";
|
|
6
|
+
import type { PreviewItem } from "@/data/shares";
|
|
7
|
+
|
|
8
|
+
// The chat's messages. The text picks the range (click for a start,
|
|
9
|
+
// shift-click for an end); the checkbox leaves one message out of it.
|
|
10
|
+
export function MessageList({
|
|
11
|
+
rows,
|
|
12
|
+
inside,
|
|
13
|
+
dropped,
|
|
14
|
+
touch,
|
|
15
|
+
onPick,
|
|
16
|
+
onToggle,
|
|
17
|
+
}: {
|
|
18
|
+
rows: PreviewItem[];
|
|
19
|
+
inside: Set<string>;
|
|
20
|
+
dropped: string[];
|
|
21
|
+
touch: boolean;
|
|
22
|
+
onPick: (id: string, extend: boolean) => void;
|
|
23
|
+
onToggle: (id: string) => void;
|
|
24
|
+
}) {
|
|
25
|
+
const first = rows.find((r) => inside.has(r.id))?.id;
|
|
26
|
+
const listRef = useRef<HTMLUListElement>(null);
|
|
27
|
+
const firstRef = useRef<HTMLLIElement>(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (listRef.current && firstRef.current)
|
|
30
|
+
listRef.current.scrollTop = firstRef.current.offsetTop;
|
|
31
|
+
}, [first]);
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="shrink-0">
|
|
35
|
+
<div className="text-muted-foreground mb-1 text-xs font-medium">
|
|
36
|
+
Messages
|
|
37
|
+
</div>
|
|
38
|
+
<p className="text-muted-foreground mb-1.5 text-xs">
|
|
39
|
+
{touch
|
|
40
|
+
? "Tap a message to start the range, then another to end it."
|
|
41
|
+
: "Click a message to start the range, shift-click to end it."}
|
|
42
|
+
</p>
|
|
43
|
+
<ul
|
|
44
|
+
ref={listRef}
|
|
45
|
+
className="relative max-h-64 divide-y overflow-y-auto rounded-lg border md:max-h-[40vh]"
|
|
46
|
+
>
|
|
47
|
+
{rows.map((item) => {
|
|
48
|
+
const on = inside.has(item.id);
|
|
49
|
+
return (
|
|
50
|
+
<li
|
|
51
|
+
key={item.id}
|
|
52
|
+
ref={item.id === first ? firstRef : undefined}
|
|
53
|
+
className={cn("flex items-center", on && "bg-primary/5")}
|
|
54
|
+
>
|
|
55
|
+
<label className="flex min-h-11 w-11 shrink-0 cursor-pointer items-center justify-center">
|
|
56
|
+
<input
|
|
57
|
+
type="checkbox"
|
|
58
|
+
className="h-4 w-4"
|
|
59
|
+
aria-label="Include this message"
|
|
60
|
+
disabled={!on}
|
|
61
|
+
checked={on && !dropped.includes(item.id)}
|
|
62
|
+
onChange={() => onToggle(item.id)}
|
|
63
|
+
/>
|
|
64
|
+
</label>
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
aria-pressed={on}
|
|
68
|
+
onClick={(e) => onPick(item.id, e.shiftKey)}
|
|
69
|
+
className={cn(
|
|
70
|
+
"flex min-h-11 min-w-0 flex-1 items-center gap-3 py-1.5 pr-3 text-left text-sm",
|
|
71
|
+
!on && "text-muted-foreground opacity-60"
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
<span className="text-muted-foreground w-12 shrink-0 text-xs">
|
|
75
|
+
{TYPE_LABEL[item.type] ?? item.type}
|
|
76
|
+
</span>
|
|
77
|
+
<span className="min-w-0 flex-1 truncate">
|
|
78
|
+
{item.excerpt || "(empty)"}
|
|
79
|
+
</span>
|
|
80
|
+
</button>
|
|
81
|
+
</li>
|
|
82
|
+
);
|
|
83
|
+
})}
|
|
84
|
+
</ul>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/ui/button";
|
|
4
|
+
import {
|
|
5
|
+
PRESETS,
|
|
6
|
+
presetRange,
|
|
7
|
+
type RangePreset,
|
|
8
|
+
type RangeRow,
|
|
9
|
+
} from "@/lib/share/range";
|
|
10
|
+
|
|
11
|
+
// The part of the chat to share: a preset, with what it comes to underneath.
|
|
12
|
+
export function RangePicker({
|
|
13
|
+
rows,
|
|
14
|
+
active,
|
|
15
|
+
summary,
|
|
16
|
+
onPick,
|
|
17
|
+
}: {
|
|
18
|
+
rows: RangeRow[];
|
|
19
|
+
active: RangePreset | null;
|
|
20
|
+
summary: string;
|
|
21
|
+
onPick: (preset: RangePreset) => void;
|
|
22
|
+
}) {
|
|
23
|
+
const now = new Date();
|
|
24
|
+
return (
|
|
25
|
+
<div className="space-y-1.5">
|
|
26
|
+
<div
|
|
27
|
+
className="grid grid-cols-2 gap-2 sm:flex sm:flex-wrap"
|
|
28
|
+
role="group"
|
|
29
|
+
aria-label="Part of the chat to share"
|
|
30
|
+
>
|
|
31
|
+
{PRESETS.map((p) => {
|
|
32
|
+
const empty = !presetRange(rows, p.id, now);
|
|
33
|
+
return (
|
|
34
|
+
<Button
|
|
35
|
+
key={p.id}
|
|
36
|
+
size="sm"
|
|
37
|
+
variant={active === p.id ? "default" : "outline"}
|
|
38
|
+
className="min-h-11"
|
|
39
|
+
aria-pressed={active === p.id}
|
|
40
|
+
disabled={empty}
|
|
41
|
+
title={empty ? "No messages today" : undefined}
|
|
42
|
+
onClick={() => onPick(p.id)}
|
|
43
|
+
>
|
|
44
|
+
{p.label}
|
|
45
|
+
</Button>
|
|
46
|
+
);
|
|
47
|
+
})}
|
|
48
|
+
</div>
|
|
49
|
+
<p
|
|
50
|
+
className="text-muted-foreground text-xs"
|
|
51
|
+
aria-live="polite"
|
|
52
|
+
data-testid="share-range-summary"
|
|
53
|
+
>
|
|
54
|
+
{summary}
|
|
55
|
+
{!active && " · Custom range"}
|
|
56
|
+
</p>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { useSnapshot } from "valtio";
|
|
5
5
|
import { toast } from "sonner";
|
|
6
6
|
import { Check, Copy, ExternalLink, Link2 } from "lucide-react";
|
|
@@ -19,12 +19,18 @@ import {
|
|
|
19
19
|
SelectValue,
|
|
20
20
|
} from "@/components/ui/select";
|
|
21
21
|
import { DownloadMenu } from "./DownloadMenu";
|
|
22
|
+
import { MessageList } from "./MessageList";
|
|
23
|
+
import { RangePicker } from "./RangePicker";
|
|
24
|
+
import { useCoarsePointer } from "@/components/Chat/composer/useCoarsePointer";
|
|
22
25
|
import { cn } from "@/lib/utils";
|
|
23
26
|
import { Switch } from "@/components/ui/switch";
|
|
24
27
|
import { writeClipboard } from "@/hooks/useCopyToClipboard";
|
|
25
28
|
import {
|
|
26
29
|
useCreateShare,
|
|
30
|
+
useShareMessages,
|
|
27
31
|
useSharePreview,
|
|
32
|
+
type PreviewItem,
|
|
33
|
+
type PreviewRequest,
|
|
28
34
|
type ShareExpiry,
|
|
29
35
|
type SharePreview,
|
|
30
36
|
} from "@/data/shares";
|
|
@@ -34,12 +40,21 @@ import {
|
|
|
34
40
|
DEFAULT_EXPIRY,
|
|
35
41
|
EXPIRIES,
|
|
36
42
|
EXPIRY_LABEL,
|
|
37
|
-
TYPE_LABEL,
|
|
38
43
|
formatBytes,
|
|
39
|
-
nothingLeft,
|
|
40
44
|
redactionSummary,
|
|
41
45
|
toggleDrop,
|
|
42
46
|
} from "@/lib/share/view";
|
|
47
|
+
import {
|
|
48
|
+
DEFAULT_PRESET,
|
|
49
|
+
activePreset,
|
|
50
|
+
clickRange,
|
|
51
|
+
inRange,
|
|
52
|
+
presetRange,
|
|
53
|
+
rangeFromHere,
|
|
54
|
+
rangeSummary,
|
|
55
|
+
type RangePreset,
|
|
56
|
+
type ShareRange,
|
|
57
|
+
} from "@/lib/share/range";
|
|
43
58
|
|
|
44
59
|
// Opened from a menu or an artifact: the redacted page exactly as it would be
|
|
45
60
|
// uploaded, with what to leave out, then Create link or Download.
|
|
@@ -52,7 +67,7 @@ export function ShareDialog() {
|
|
|
52
67
|
>
|
|
53
68
|
{target && (
|
|
54
69
|
<ShareBody
|
|
55
|
-
key={target.sessionId ?? target.artifactId}
|
|
70
|
+
key={`${target.sessionId ?? target.artifactId}:${target.fromId ?? ""}`}
|
|
56
71
|
target={{ ...target }}
|
|
57
72
|
/>
|
|
58
73
|
)}
|
|
@@ -69,6 +84,7 @@ function ShareBody({
|
|
|
69
84
|
artifactId?: string;
|
|
70
85
|
title: string;
|
|
71
86
|
version?: number;
|
|
87
|
+
fromId?: string;
|
|
72
88
|
};
|
|
73
89
|
}) {
|
|
74
90
|
const [tools, setTools] = useState(false);
|
|
@@ -80,22 +96,60 @@ function ShareBody({
|
|
|
80
96
|
const [follow, setFollow] = useState(false);
|
|
81
97
|
const [copied, setCopied] = useState(false);
|
|
82
98
|
const [tab, setTab] = useState<"page" | "markdown">("page");
|
|
99
|
+
const [rows, setRows] = useState<PreviewItem[] | null>(null);
|
|
100
|
+
const [range, setRange] = useState<ShareRange | null>(null);
|
|
101
|
+
const [anchor, setAnchor] = useState<string | null>(null);
|
|
102
|
+
const [armed, setArmed] = useState(false);
|
|
83
103
|
const previewReq = useSharePreview();
|
|
104
|
+
const listReq = useShareMessages();
|
|
84
105
|
const create = useCreateShare();
|
|
106
|
+
const coarse = useCoarsePointer();
|
|
85
107
|
const seq = useRef(0);
|
|
86
108
|
|
|
87
109
|
const { kind, sessionId, artifactId } = target;
|
|
110
|
+
const chat = kind === "chat";
|
|
111
|
+
|
|
112
|
+
// A chat opens on its last exchange, or on the message it was shared from.
|
|
88
113
|
useEffect(() => {
|
|
114
|
+
if (!chat) return;
|
|
115
|
+
let live = true;
|
|
116
|
+
listReq
|
|
117
|
+
.mutateAsync({ kind, sessionId, includeTools: true })
|
|
118
|
+
.then(({ items }) => {
|
|
119
|
+
if (!live) return;
|
|
120
|
+
const from = target.fromId ? rangeFromHere(items, target.fromId) : null;
|
|
121
|
+
setRows(items);
|
|
122
|
+
setRange(from ?? presetRange(items, DEFAULT_PRESET, new Date()));
|
|
123
|
+
setAnchor(from?.fromId ?? null);
|
|
124
|
+
})
|
|
125
|
+
.catch((err: Error) => live && setError(err.message));
|
|
126
|
+
return () => {
|
|
127
|
+
live = false;
|
|
128
|
+
};
|
|
129
|
+
// listReq is stable enough; re-running on it would loop.
|
|
130
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
131
|
+
}, [chat, kind, sessionId, target.fromId]);
|
|
132
|
+
|
|
133
|
+
const ready =
|
|
134
|
+
!chat || (rows !== null && range !== null) || rows?.length === 0;
|
|
135
|
+
const request: PreviewRequest = useMemo(
|
|
136
|
+
() => ({
|
|
137
|
+
kind,
|
|
138
|
+
sessionId,
|
|
139
|
+
artifactId,
|
|
140
|
+
includeTools: tools,
|
|
141
|
+
dropIds: dropped,
|
|
142
|
+
...(range ?? {}),
|
|
143
|
+
}),
|
|
144
|
+
[kind, sessionId, artifactId, tools, dropped, range]
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!ready) return;
|
|
89
149
|
const mine = ++seq.current;
|
|
90
150
|
const timer = setTimeout(async () => {
|
|
91
151
|
try {
|
|
92
|
-
const p = await previewReq.mutateAsync(
|
|
93
|
-
kind,
|
|
94
|
-
sessionId,
|
|
95
|
-
artifactId,
|
|
96
|
-
includeTools: tools,
|
|
97
|
-
dropIds: dropped,
|
|
98
|
-
});
|
|
152
|
+
const p = await previewReq.mutateAsync(request);
|
|
99
153
|
if (mine === seq.current) {
|
|
100
154
|
setPreview(p);
|
|
101
155
|
setError(null);
|
|
@@ -107,7 +161,7 @@ function ShareBody({
|
|
|
107
161
|
return () => clearTimeout(timer);
|
|
108
162
|
// previewReq is stable enough; re-running on it would loop.
|
|
109
163
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
-
}, [
|
|
164
|
+
}, [ready, request]);
|
|
111
165
|
|
|
112
166
|
const toggle = (id: string) => setDropped((d) => toggleDrop(d, id));
|
|
113
167
|
|
|
@@ -115,11 +169,7 @@ function ShareBody({
|
|
|
115
169
|
if (!preview) return;
|
|
116
170
|
try {
|
|
117
171
|
const res = await create.mutateAsync({
|
|
118
|
-
|
|
119
|
-
sessionId,
|
|
120
|
-
artifactId,
|
|
121
|
-
includeTools: tools,
|
|
122
|
-
dropIds: dropped,
|
|
172
|
+
...request,
|
|
123
173
|
sharedAt: preview.sharedAt,
|
|
124
174
|
hash: preview.hash,
|
|
125
175
|
expiresIn,
|
|
@@ -149,8 +199,33 @@ function ShareBody({
|
|
|
149
199
|
};
|
|
150
200
|
|
|
151
201
|
const linked = preview?.connectLinked ?? false;
|
|
152
|
-
const
|
|
153
|
-
|
|
202
|
+
const visibleRows = useMemo(
|
|
203
|
+
() => (rows ?? []).filter((r) => tools || !r.tools),
|
|
204
|
+
[rows, tools]
|
|
205
|
+
);
|
|
206
|
+
const covered = useMemo(() => inRange(rows ?? [], range), [rows, range]);
|
|
207
|
+
const inside = useMemo(() => new Set(covered.map((r) => r.id)), [covered]);
|
|
208
|
+
const shared = visibleRows.filter(
|
|
209
|
+
(r) => inside.has(r.id) && !dropped.includes(r.id)
|
|
210
|
+
);
|
|
211
|
+
const empty = chat && !!rows && shared.length === 0;
|
|
212
|
+
const active = activePreset(rows ?? [], range, new Date());
|
|
213
|
+
|
|
214
|
+
const pickPreset = (preset: RangePreset) => {
|
|
215
|
+
const r = presetRange(rows ?? [], preset, new Date());
|
|
216
|
+
if (!r) return;
|
|
217
|
+
setRange(r);
|
|
218
|
+
setAnchor(r.fromId);
|
|
219
|
+
setArmed(false);
|
|
220
|
+
};
|
|
221
|
+
const pickRow = (id: string, shift: boolean) => {
|
|
222
|
+
const extend = shift || (coarse && armed);
|
|
223
|
+
setRange(
|
|
224
|
+
clickRange(rows ?? [], anchor ?? range?.fromId ?? null, id, extend)
|
|
225
|
+
);
|
|
226
|
+
if (!extend) setAnchor(id);
|
|
227
|
+
setArmed(coarse && !extend);
|
|
228
|
+
};
|
|
154
229
|
const summary = preview ? redactionSummary(preview.hits) : "";
|
|
155
230
|
|
|
156
231
|
return (
|
|
@@ -166,6 +241,15 @@ function ShareBody({
|
|
|
166
241
|
</DialogDescription>
|
|
167
242
|
</div>
|
|
168
243
|
|
|
244
|
+
{chat && rows && rows.length > 0 && (
|
|
245
|
+
<RangePicker
|
|
246
|
+
rows={rows}
|
|
247
|
+
active={active}
|
|
248
|
+
summary={rangeSummary(visibleRows.length, shared)}
|
|
249
|
+
onPick={pickPreset}
|
|
250
|
+
/>
|
|
251
|
+
)}
|
|
252
|
+
|
|
169
253
|
<div className="flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto md:flex-row md:overflow-hidden">
|
|
170
254
|
<div className="flex min-h-[45vh] flex-1 flex-col gap-2 md:min-h-0">
|
|
171
255
|
<div className="flex gap-2" role="group" aria-label="Preview format">
|
|
@@ -210,31 +294,14 @@ function ShareBody({
|
|
|
210
294
|
<span>Include tool calls and thinking</span>
|
|
211
295
|
<Switch checked={tools} onCheckedChange={setTools} />
|
|
212
296
|
</label>
|
|
213
|
-
<
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
<input
|
|
222
|
-
type="checkbox"
|
|
223
|
-
className="h-4 w-4 shrink-0"
|
|
224
|
-
checked={!dropped.includes(item.id)}
|
|
225
|
-
onChange={() => toggle(item.id)}
|
|
226
|
-
/>
|
|
227
|
-
<span className="text-muted-foreground w-12 shrink-0 text-xs">
|
|
228
|
-
{TYPE_LABEL[item.type] ?? item.type}
|
|
229
|
-
</span>
|
|
230
|
-
<span className="min-w-0 flex-1 truncate">
|
|
231
|
-
{item.excerpt || "(empty)"}
|
|
232
|
-
</span>
|
|
233
|
-
</label>
|
|
234
|
-
</li>
|
|
235
|
-
))}
|
|
236
|
-
</ul>
|
|
237
|
-
</div>
|
|
297
|
+
<MessageList
|
|
298
|
+
rows={visibleRows}
|
|
299
|
+
inside={inside}
|
|
300
|
+
dropped={dropped}
|
|
301
|
+
touch={coarse}
|
|
302
|
+
onPick={pickRow}
|
|
303
|
+
onToggle={toggle}
|
|
304
|
+
/>
|
|
238
305
|
</>
|
|
239
306
|
)}
|
|
240
307
|
|
|
@@ -372,15 +439,9 @@ function ShareBody({
|
|
|
372
439
|
<div className="flex gap-2">
|
|
373
440
|
<DownloadMenu
|
|
374
441
|
preview={preview}
|
|
375
|
-
title={target.title}
|
|
442
|
+
title={target.title || preview?.title || ""}
|
|
376
443
|
disabled={!preview || preview.tooBig || empty}
|
|
377
|
-
request={
|
|
378
|
-
kind,
|
|
379
|
-
sessionId,
|
|
380
|
-
artifactId,
|
|
381
|
-
includeTools: tools,
|
|
382
|
-
dropIds: dropped,
|
|
383
|
-
}}
|
|
444
|
+
request={request}
|
|
384
445
|
/>
|
|
385
446
|
{linked && (
|
|
386
447
|
<Button
|