@anthusai/papyrus 5.43.0-next.37 → 5.43.0-next.39
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/components/conversation-context.tsx +52 -0
- package/components/conversation-provider.tsx +20 -0
- package/components/conversation-thread.tsx +173 -0
- package/components/decision-control.tsx +306 -0
- package/components/needs-me-bodies.tsx +4 -3
- package/components/needs-me-feed.tsx +8 -14
- package/components/needs-me-reference-detail.tsx +2 -0
- package/components/news-desk-taxonomy-client.ts +241 -25
- package/components/newsroom-organizer.css +24 -0
- package/components/newsroom-references-view.tsx +9 -0
- package/components/notification-cards.tsx +5 -4
- package/components/reference-conversation.tsx +43 -0
- package/components/reference-feed.tsx +22 -17
- package/components/reference-review-card.tsx +8 -134
- package/components/topic-steering-workspace.tsx +3 -2
- package/components/use-conversation.ts +84 -0
- package/components/use-reference-ratings.ts +1 -1
- package/lib/conversation.ts +154 -0
- package/package.json +8 -2
- package/routes.manifest.json +1 -1
- package/components/review-rating-grid.tsx +0 -190
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, type ReactNode } from "react";
|
|
4
|
+
import type { ConversationAnchor, ConversationMessage } from "../lib/conversation";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where conversations are read and written. The newsroom provides the network one; a demo or a test provides the in-memory one. A
|
|
8
|
+
* component that finds no store shows no conversation at all.
|
|
9
|
+
*/
|
|
10
|
+
export type ConversationStore = {
|
|
11
|
+
/** Who the optimistic Message says wrote it, until the saved one replaces it. */
|
|
12
|
+
authorLabel: string;
|
|
13
|
+
load: (anchor: ConversationAnchor) => Promise<ConversationMessage[]>;
|
|
14
|
+
append: (input: { anchor: ConversationAnchor; body: string; parentMessageId: string | null }) => Promise<ConversationMessage>;
|
|
15
|
+
/** Message counts by Reference lineage, for the feed cards. */
|
|
16
|
+
counts: () => Promise<Map<string, number>>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ConversationStoreContext = createContext<ConversationStore | null>(null);
|
|
20
|
+
|
|
21
|
+
export function ConversationStoreProvider({ store, children }: { store: ConversationStore; children: ReactNode }) {
|
|
22
|
+
return <ConversationStoreContext.Provider value={store}>{children}</ConversationStoreContext.Provider>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function useConversationStore(): ConversationStore | null {
|
|
26
|
+
return useContext(ConversationStoreContext);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A store that keeps everything in memory: the demo newsroom, and the tests. */
|
|
30
|
+
export function createMemoryConversationStore(authorLabel: string, seed: Record<string, ConversationMessage[]> = {}): ConversationStore {
|
|
31
|
+
const byAnchor = new Map<string, ConversationMessage[]>(Object.entries(seed));
|
|
32
|
+
const keyOf = (anchor: ConversationAnchor) => `${anchor.kind}#${anchor.lineageId ?? ""}`;
|
|
33
|
+
return {
|
|
34
|
+
authorLabel,
|
|
35
|
+
load: async (anchor) => [...(byAnchor.get(keyOf(anchor)) ?? [])],
|
|
36
|
+
append: async ({ anchor, body, parentMessageId }) => {
|
|
37
|
+
const list = byAnchor.get(keyOf(anchor)) ?? [];
|
|
38
|
+
const sequenceNumber = Math.max(0, ...list.map((message) => message.sequenceNumber)) + 1;
|
|
39
|
+
const message: ConversationMessage = {
|
|
40
|
+
id: `message-memory-${sequenceNumber}-${list.length}`,
|
|
41
|
+
parentMessageId,
|
|
42
|
+
authorLabel,
|
|
43
|
+
content: body.trim(),
|
|
44
|
+
createdAt: new Date().toISOString(),
|
|
45
|
+
sequenceNumber,
|
|
46
|
+
};
|
|
47
|
+
byAnchor.set(keyOf(anchor), [...list, message]);
|
|
48
|
+
return message;
|
|
49
|
+
},
|
|
50
|
+
counts: async () => new Map([...byAnchor].filter(([key]) => key.startsWith("reference#")).map(([key, list]) => [key.slice("reference#".length), list.length])),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, type ReactNode } from "react";
|
|
4
|
+
import { ConversationStoreProvider, createMemoryConversationStore, type ConversationStore } from "./conversation-context";
|
|
5
|
+
import { appendConversationMessage, loadConversationMessages, loadReferenceConversationCounts } from "./news-desk-taxonomy-client";
|
|
6
|
+
|
|
7
|
+
function networkConversationStore(authorLabel: string): ConversationStore {
|
|
8
|
+
return {
|
|
9
|
+
authorLabel,
|
|
10
|
+
load: loadConversationMessages,
|
|
11
|
+
append: async ({ anchor, body, parentMessageId }) => (await appendConversationMessage({ anchor, body, parentMessageId })).message,
|
|
12
|
+
counts: loadReferenceConversationCounts,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Gives the newsroom its conversations: saved to the backend, or kept in memory in the demo. */
|
|
17
|
+
export function ConversationProvider({ authorLabel, demo, children }: { authorLabel: string; demo: boolean; children: ReactNode }) {
|
|
18
|
+
const store = useMemo(() => (demo ? createMemoryConversationStore(authorLabel) : networkConversationStore(authorLabel)), [authorLabel, demo]);
|
|
19
|
+
return <ConversationStoreProvider store={store}>{children}</ConversationStoreProvider>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Loader2Icon, MessageSquarePlusIcon, ReplyIcon, TriangleAlertIcon, CornerDownRightIcon } from "lucide-react";
|
|
4
|
+
import { useMemo, useState } from "react";
|
|
5
|
+
import { buildConversationTree, conversationAge, conversationAuthorName, type ConversationMessage } from "../lib/conversation";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { AutoGrowTextarea } from "./ui/auto-grow-textarea";
|
|
8
|
+
import type { ConversationState } from "./use-conversation";
|
|
9
|
+
|
|
10
|
+
/** Flat pill buttons, like the feed's: a tone, never an outline. */
|
|
11
|
+
const PILL = "inline-flex min-h-9 items-center justify-center gap-1.5 rounded-full px-3.5 text-sm font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50";
|
|
12
|
+
const PILL_PRIMARY = cn(PILL, "bg-[var(--primary)] text-[var(--primary-foreground)]");
|
|
13
|
+
const PILL_QUIET = cn(PILL, "text-muted-foreground hover:text-foreground");
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A box for writing a Message. The text clears the moment you post, so the Message shows at once; if the save fails the text comes
|
|
17
|
+
* back (unless you have typed something new) with the reason, and nothing you wrote is lost.
|
|
18
|
+
*/
|
|
19
|
+
function Composer({ autoFocus = false, buttonLabel, disabledReason, icon, label, onCancel, onSubmit, placeholder }: {
|
|
20
|
+
autoFocus?: boolean;
|
|
21
|
+
buttonLabel: string;
|
|
22
|
+
disabledReason?: string | null;
|
|
23
|
+
icon: "post" | "reply";
|
|
24
|
+
label: string;
|
|
25
|
+
onCancel?: () => void;
|
|
26
|
+
onSubmit: (body: string) => Promise<void>;
|
|
27
|
+
placeholder: string;
|
|
28
|
+
}) {
|
|
29
|
+
const [draft, setDraft] = useState("");
|
|
30
|
+
const [error, setError] = useState<string | null>(null);
|
|
31
|
+
const Icon = icon === "post" ? MessageSquarePlusIcon : ReplyIcon;
|
|
32
|
+
const canPost = !disabledReason && draft.trim().length > 0;
|
|
33
|
+
|
|
34
|
+
async function submit() {
|
|
35
|
+
const text = draft.trim();
|
|
36
|
+
if (!text || disabledReason) return;
|
|
37
|
+
setDraft("");
|
|
38
|
+
setError(null);
|
|
39
|
+
try {
|
|
40
|
+
await onSubmit(text);
|
|
41
|
+
onCancel?.();
|
|
42
|
+
} catch (failure) {
|
|
43
|
+
setDraft((current) => current || text);
|
|
44
|
+
setError(failure instanceof Error ? failure.message : "Your message could not be saved.");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className="space-y-2" data-conversation-composer={icon}>
|
|
50
|
+
<AutoGrowTextarea
|
|
51
|
+
aria-label={label}
|
|
52
|
+
autoFocus={autoFocus}
|
|
53
|
+
className="block min-h-16 w-full rounded-[var(--feed-radius-lg,10px)] bg-[var(--feed-control)] p-3 text-base font-normal outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"
|
|
54
|
+
disabled={Boolean(disabledReason)}
|
|
55
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
56
|
+
onKeyDown={(event) => { if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) { event.preventDefault(); void submit(); } }}
|
|
57
|
+
placeholder={placeholder}
|
|
58
|
+
value={draft}
|
|
59
|
+
/>
|
|
60
|
+
{error ? (
|
|
61
|
+
<p className="flex items-start gap-1.5 text-sm text-destructive" data-conversation-error role="alert">
|
|
62
|
+
<TriangleAlertIcon aria-hidden="true" className="mt-0.5 size-4 shrink-0" />
|
|
63
|
+
<span>Not posted: {error} Your text is kept here.</span>
|
|
64
|
+
</p>
|
|
65
|
+
) : null}
|
|
66
|
+
{disabledReason ? <p className="text-sm text-muted-foreground">{disabledReason}</p> : null}
|
|
67
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
68
|
+
<button className={PILL_PRIMARY} data-conversation-post={icon} disabled={!canPost} onClick={() => void submit()} type="button">
|
|
69
|
+
<Icon aria-hidden="true" className="size-4" />
|
|
70
|
+
{buttonLabel}
|
|
71
|
+
</button>
|
|
72
|
+
{onCancel ? <button className={PILL_QUIET} onClick={onCancel} type="button">Cancel</button> : null}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function MessageBody({ answers, message, now, onReply, replying, tone }: {
|
|
79
|
+
answers?: string | null;
|
|
80
|
+
message: ConversationMessage;
|
|
81
|
+
now: number;
|
|
82
|
+
onReply: () => void;
|
|
83
|
+
replying: boolean;
|
|
84
|
+
tone: "root" | "reply";
|
|
85
|
+
}) {
|
|
86
|
+
return (
|
|
87
|
+
<div className={cn("space-y-1.5 rounded-[var(--feed-radius-lg,10px)] p-3", tone === "root" ? "bg-[var(--feed-control)]" : "bg-[var(--feed-footer)]")} data-conversation-message={message.id} data-conversation-pending={message.pending || undefined}>
|
|
88
|
+
<p className="flex flex-wrap items-center gap-x-2 text-sm">
|
|
89
|
+
<span className="font-semibold" data-conversation-author>{conversationAuthorName(message.authorLabel)}</span>
|
|
90
|
+
<span className="text-xs text-muted-foreground" data-conversation-age>
|
|
91
|
+
{message.pending ? (
|
|
92
|
+
<span className="inline-flex items-center gap-1"><Loader2Icon aria-hidden="true" className="size-3 animate-spin" />Sending</span>
|
|
93
|
+
) : conversationAge(message.createdAt, now)}
|
|
94
|
+
</span>
|
|
95
|
+
</p>
|
|
96
|
+
{answers ? (
|
|
97
|
+
<p className="flex items-center gap-1 text-xs text-muted-foreground" data-conversation-answers>
|
|
98
|
+
<CornerDownRightIcon aria-hidden="true" className="size-3" />
|
|
99
|
+
In reply to {answers}
|
|
100
|
+
</p>
|
|
101
|
+
) : null}
|
|
102
|
+
<p className="whitespace-pre-wrap break-words text-base" data-conversation-content>{message.content}</p>
|
|
103
|
+
{!message.pending ? (
|
|
104
|
+
<button aria-expanded={replying} className={cn(PILL_QUIET, "-ml-3")} data-conversation-reply={message.id} onClick={onReply} type="button">
|
|
105
|
+
<ReplyIcon aria-hidden="true" className="size-4" />
|
|
106
|
+
Reply
|
|
107
|
+
</button>
|
|
108
|
+
) : null}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The Messages of one conversation, replies nested one level under their top-level Message, and a box to add another. It knows
|
|
115
|
+
* nothing about where the Messages come from: the caller loads them and saves a post.
|
|
116
|
+
*/
|
|
117
|
+
export function ConversationThread({ disabledReason = null, error = null, heading = "Messages", messages, now, onPost, onRetry, state = "ready" }: {
|
|
118
|
+
disabledReason?: string | null;
|
|
119
|
+
error?: string | null;
|
|
120
|
+
heading?: string;
|
|
121
|
+
messages: ReadonlyArray<ConversationMessage>;
|
|
122
|
+
now: number;
|
|
123
|
+
onPost: (body: string, parentMessageId: string | null) => Promise<void>;
|
|
124
|
+
onRetry?: () => void;
|
|
125
|
+
state?: ConversationState;
|
|
126
|
+
}) {
|
|
127
|
+
const tree = useMemo(() => buildConversationTree(messages), [messages]);
|
|
128
|
+
const [replyingTo, setReplyingTo] = useState<string | null>(null);
|
|
129
|
+
const authorOf = (id: string) => conversationAuthorName(messages.find((message) => message.id === id)?.authorLabel);
|
|
130
|
+
const toggleReply = (id: string) => setReplyingTo((current) => (current === id ? null : id));
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<section aria-label={heading} className="space-y-3" data-conversation-thread>
|
|
134
|
+
<h3 className="text-sm font-medium">{heading}</h3>
|
|
135
|
+
{state === "loading" ? <p className="flex items-center gap-1.5 text-sm text-muted-foreground" data-conversation-loading><Loader2Icon aria-hidden="true" className="size-4 animate-spin" />Loading messages</p> : null}
|
|
136
|
+
{state === "error" ? (
|
|
137
|
+
<p className="flex flex-wrap items-center gap-2 text-sm text-destructive" role="alert">
|
|
138
|
+
<TriangleAlertIcon aria-hidden="true" className="size-4" />
|
|
139
|
+
Messages could not be loaded. {error}
|
|
140
|
+
{onRetry ? <button className={PILL_QUIET} onClick={onRetry} type="button">Try again</button> : null}
|
|
141
|
+
</p>
|
|
142
|
+
) : null}
|
|
143
|
+
{state === "ready" && !tree.length ? <p className="text-sm text-muted-foreground" data-conversation-empty>No messages yet. Write down what this made you think.</p> : null}
|
|
144
|
+
<ul className="space-y-3">
|
|
145
|
+
{tree.map((root) => (
|
|
146
|
+
<li className="space-y-2" key={root.message.id}>
|
|
147
|
+
<MessageBody message={root.message} now={now} onReply={() => toggleReply(root.message.id)} replying={replyingTo === root.message.id} tone="root" />
|
|
148
|
+
{root.replies.length || replyingTo === root.message.id ? (
|
|
149
|
+
<ul className="ml-4 space-y-2" data-conversation-replies>
|
|
150
|
+
{root.replies.map((reply) => (
|
|
151
|
+
<li key={reply.message.id}>
|
|
152
|
+
<MessageBody answers={reply.answers} message={reply.message} now={now} onReply={() => toggleReply(reply.message.id)} replying={replyingTo === reply.message.id} tone="reply" />
|
|
153
|
+
{replyingTo === reply.message.id ? (
|
|
154
|
+
<div className="mt-2">
|
|
155
|
+
<Composer autoFocus buttonLabel="Reply" disabledReason={disabledReason} icon="reply" label={`Reply to ${authorOf(reply.message.id)}`} onCancel={() => setReplyingTo(null)} onSubmit={(body) => onPost(body, reply.message.id)} placeholder={`Reply to ${authorOf(reply.message.id)}…`} />
|
|
156
|
+
</div>
|
|
157
|
+
) : null}
|
|
158
|
+
</li>
|
|
159
|
+
))}
|
|
160
|
+
{replyingTo === root.message.id ? (
|
|
161
|
+
<li>
|
|
162
|
+
<Composer autoFocus buttonLabel="Reply" disabledReason={disabledReason} icon="reply" label={`Reply to ${authorOf(root.message.id)}`} onCancel={() => setReplyingTo(null)} onSubmit={(body) => onPost(body, root.message.id)} placeholder={`Reply to ${authorOf(root.message.id)}…`} />
|
|
163
|
+
</li>
|
|
164
|
+
) : null}
|
|
165
|
+
</ul>
|
|
166
|
+
) : null}
|
|
167
|
+
</li>
|
|
168
|
+
))}
|
|
169
|
+
</ul>
|
|
170
|
+
<Composer buttonLabel="Post" disabledReason={disabledReason} icon="post" label="Add a message" onSubmit={(body) => onPost(body, null)} placeholder="Add a message…" />
|
|
171
|
+
</section>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useId, useState } from "react";
|
|
4
|
+
import { CheckIcon, Loader2Icon, XIcon } from "lucide-react";
|
|
5
|
+
import { UNRECORDED_CONFIDENCE } from "../lib/reference-feed-ranking";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import type { CardPrediction, ReviewChoice } from "./reference-review-card";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One classification, in two stages: a model predicts it, a person decides it.
|
|
11
|
+
*
|
|
12
|
+
* PREDICTED ACCEPT
|
|
13
|
+
* [=========== 96% ==========| ] the prediction's own confidence, in its own bar
|
|
14
|
+
* [ ✓ Accept PREDICTED ] [ ✕ Reject ] one pair of segments; the predicted one is pre-filled, in its own tone
|
|
15
|
+
* REASON · OPTIONAL
|
|
16
|
+
* [ Why? In your own words… ] written, always in view, full width
|
|
17
|
+
* ✓ Recorded · confirms the prediction one status line for the whole block
|
|
18
|
+
*
|
|
19
|
+
* The prediction and the answer share one row of segments rather than a row each: they are not two
|
|
20
|
+
* voters, they are one decision before and after a person touched it. Once decided, a small marker
|
|
21
|
+
* stays on the segment the model picked — on the losing one if it was overturned — so the comparison
|
|
22
|
+
* survives the answer without a second row. The bar belongs to the model, so it never moves when the
|
|
23
|
+
* person answers; only its tone changes.
|
|
24
|
+
*
|
|
25
|
+
* The verdict never tints the person's own choice: a decided segment is always `--primary`, and
|
|
26
|
+
* `--feed-verdict-*` colours the marker and the bar. An overturned Reject painted red reads as "your
|
|
27
|
+
* answer is wrong" rather than "the model's was".
|
|
28
|
+
*
|
|
29
|
+
* No engine or product name appears in the copy: the component knows about predictions, not about
|
|
30
|
+
* what made them (AGENTS.md: a deployment publishes about any subject with any classifier behind it).
|
|
31
|
+
*
|
|
32
|
+
* Every tone, corner and opacity is a feed token from newsroom-organizer.css; the values after the
|
|
33
|
+
* comma are the last resort for a surface that declares none.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export type RatingFeedback = { phase: "idle" | "saving" | "saved" | "error"; message?: string };
|
|
37
|
+
|
|
38
|
+
/** P(accept) from a prediction: its confidence is in the side it chose; an unrecorded confidence is a mild lean. */
|
|
39
|
+
export function predictionAcceptProbability(prediction: Extract<CardPrediction, { state: "ready" }>): number {
|
|
40
|
+
const confidence = prediction.confidence ?? UNRECORDED_CONFIDENCE;
|
|
41
|
+
return prediction.choice === "accept" ? confidence : 1 - confidence;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** How far, in percent of the whole bar, the fill reaches from the centre: |P(accept) - 0.5| * 2, over the two halves. */
|
|
45
|
+
export function confidenceFillPercent(probability: number): number {
|
|
46
|
+
return Math.min(100, Math.abs(probability - 0.5) * 100 * 2);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const WORD: Record<ReviewChoice, string> = { accept: "Accept", reject: "Reject" };
|
|
50
|
+
const LABEL = "font-[family-name:var(--font-sans)] text-[10px] font-extrabold tracking-[0.07em] uppercase";
|
|
51
|
+
/** A fill shorter than this cannot hold its own percentage, so the number sits beside it. */
|
|
52
|
+
const NARROW_FILL = 14;
|
|
53
|
+
|
|
54
|
+
export function DecisionControl({
|
|
55
|
+
answer,
|
|
56
|
+
decided = null,
|
|
57
|
+
disabled = false,
|
|
58
|
+
disabledReason = null,
|
|
59
|
+
feedback = { phase: "idle" },
|
|
60
|
+
needsReason = false,
|
|
61
|
+
note = null,
|
|
62
|
+
onChoose,
|
|
63
|
+
onReasonChange,
|
|
64
|
+
onReasonCommit,
|
|
65
|
+
prediction,
|
|
66
|
+
reason = "",
|
|
67
|
+
reasonRequiredFor = null,
|
|
68
|
+
showPrediction = true,
|
|
69
|
+
showReason = true,
|
|
70
|
+
size = "compact",
|
|
71
|
+
statusOverlay = false,
|
|
72
|
+
surface = "footer",
|
|
73
|
+
}: {
|
|
74
|
+
/** The side shown as chosen. It may be an answer that is still saving. */
|
|
75
|
+
answer: ReviewChoice | null;
|
|
76
|
+
/** The saved answer, which the Confirmed / Overturned verdict compares against. */
|
|
77
|
+
decided?: ReviewChoice | null;
|
|
78
|
+
disabled?: boolean;
|
|
79
|
+
disabledReason?: string | null;
|
|
80
|
+
feedback?: RatingFeedback;
|
|
81
|
+
/** The answer is staged and waiting for a written reason before it can be recorded. */
|
|
82
|
+
needsReason?: boolean;
|
|
83
|
+
/** A short line shown in the status row beside the saved tick. It never adds a row. */
|
|
84
|
+
note?: string | null;
|
|
85
|
+
onChoose: (choice: ReviewChoice) => void;
|
|
86
|
+
onReasonChange?: (text: string) => void;
|
|
87
|
+
/** Save the reason on its own (on blur, or from the status row). */
|
|
88
|
+
onReasonCommit?: () => void;
|
|
89
|
+
prediction: CardPrediction;
|
|
90
|
+
/** The written reason, owned by the caller. */
|
|
91
|
+
reason?: string;
|
|
92
|
+
/** The side that cannot be recorded without a written reason. */
|
|
93
|
+
reasonRequiredFor?: ReviewChoice | null;
|
|
94
|
+
/** False for an item with nothing to predict: the bar and the caption are left out. */
|
|
95
|
+
showPrediction?: boolean;
|
|
96
|
+
/** False where the surrounding card owns the reason field. */
|
|
97
|
+
showReason?: boolean;
|
|
98
|
+
size?: "compact" | "large";
|
|
99
|
+
/** Lay the status line over the bottom padding of the nearest positioned ancestor, so it adds no height. */
|
|
100
|
+
statusOverlay?: boolean;
|
|
101
|
+
/** The tone the control sits on, so the bar's centre notch matches it. */
|
|
102
|
+
surface?: "footer" | "card";
|
|
103
|
+
}) {
|
|
104
|
+
const fieldId = useId();
|
|
105
|
+
const ready = prediction.state === "ready" ? prediction : null;
|
|
106
|
+
const verdict = ready && decided ? (ready.choice === decided ? "match" : "miss") : null;
|
|
107
|
+
const saving = feedback.phase === "saving";
|
|
108
|
+
const [reasonDirty, setReasonDirty] = useState(false);
|
|
109
|
+
useEffect(() => { if (feedback.phase === "saved") setReasonDirty(false); }, [feedback.phase]);
|
|
110
|
+
|
|
111
|
+
const probability = ready ? predictionAcceptProbability(ready) : 0.5;
|
|
112
|
+
const half = confidenceFillPercent(probability) / 2; // percent of the full bar, one side of the centre
|
|
113
|
+
const leansAccept = probability >= 0.5;
|
|
114
|
+
const confidenceText = ready ? (ready.confidence !== null ? `${Math.round(ready.confidence * 100)}%` : "unrecorded") : null;
|
|
115
|
+
const narrow = half < NARROW_FILL;
|
|
116
|
+
const cell = size === "large" ? "min-h-14 text-base" : "min-h-12 text-sm";
|
|
117
|
+
const field = size === "large" ? "min-h-16" : "min-h-9";
|
|
118
|
+
|
|
119
|
+
const caption = ready
|
|
120
|
+
? `Predicted ${WORD[ready.choice]}`
|
|
121
|
+
: prediction.state === "loading" ? "Reading the prediction…"
|
|
122
|
+
: prediction.state === "error" ? "Prediction unavailable" : "No prediction";
|
|
123
|
+
|
|
124
|
+
/* What the chosen segment says about itself while the answer is in flight or held back. A segment
|
|
125
|
+
never claims to be unrecorded while it is being recorded. */
|
|
126
|
+
const stagedWord = saving ? (decided ? "Updating…" : "Sending…") : needsReason ? "Needs a reason" : null;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div className="@container/decision grid gap-y-2" data-decision-control data-rating-grid>
|
|
130
|
+
{showPrediction ? (
|
|
131
|
+
<div className="grid gap-y-0.5" data-prediction>
|
|
132
|
+
<span className={cn(LABEL, "text-muted-foreground")} data-prediction-caption>{caption}</span>
|
|
133
|
+
<div
|
|
134
|
+
aria-label={ready ? `Prediction: ${WORD[ready.choice]}, ${confidenceText} confident` : caption}
|
|
135
|
+
className="relative h-4 w-full overflow-hidden rounded-full bg-[var(--feed-control)]"
|
|
136
|
+
data-confidence-bar
|
|
137
|
+
data-confidence-direction={ready ? (leansAccept ? "accept" : "reject") : "none"}
|
|
138
|
+
data-prediction-state={ready ? undefined : prediction.state}
|
|
139
|
+
role="img"
|
|
140
|
+
>
|
|
141
|
+
{ready ? (
|
|
142
|
+
<span
|
|
143
|
+
className={cn(
|
|
144
|
+
"absolute inset-y-0 flex items-center rounded-full",
|
|
145
|
+
leansAccept ? "justify-end" : "justify-start",
|
|
146
|
+
verdict === "match" ? "bg-[var(--feed-verdict-match-fill,#059669)]"
|
|
147
|
+
: verdict === "miss" ? "bg-[var(--feed-verdict-miss-fill,#dc2626)]"
|
|
148
|
+
: "bg-[var(--foreground-muted)]",
|
|
149
|
+
)}
|
|
150
|
+
data-confidence-fill
|
|
151
|
+
data-fill-percent={Math.round(half * 2)}
|
|
152
|
+
style={{ left: leansAccept ? `${50 - half}%` : "50%", width: `${half}%` }}
|
|
153
|
+
>
|
|
154
|
+
{/* The confidence is printed in the bar and nowhere else, so no button has to carry a number. */}
|
|
155
|
+
{narrow ? null : <small className={cn(LABEL, "px-1.5 text-[var(--feed-card)] whitespace-nowrap")} data-confidence-value>{confidenceText}</small>}
|
|
156
|
+
</span>
|
|
157
|
+
) : null}
|
|
158
|
+
{ready && narrow ? (
|
|
159
|
+
<small
|
|
160
|
+
className={cn(LABEL, "absolute top-0.5 text-muted-foreground whitespace-nowrap")}
|
|
161
|
+
data-confidence-value
|
|
162
|
+
style={leansAccept ? { left: `${50 - half}%`, transform: "translateX(-100%)" } : { left: `${50 + half}%` }}
|
|
163
|
+
>
|
|
164
|
+
{confidenceText}
|
|
165
|
+
</small>
|
|
166
|
+
) : null}
|
|
167
|
+
<span aria-hidden="true" className={cn("absolute inset-y-0 left-1/2 w-1 -translate-x-1/2", surface === "footer" ? "bg-[var(--feed-footer)]" : "bg-[var(--feed-card)]")} />
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
) : null}
|
|
171
|
+
|
|
172
|
+
<div aria-label="Classification" className="grid grid-cols-2 gap-x-1.5" data-review-row="you" role="group">
|
|
173
|
+
{(["accept", "reject"] as const).map((choice) => {
|
|
174
|
+
const on = answer === choice;
|
|
175
|
+
const predicted = ready?.choice === choice;
|
|
176
|
+
const proposed = predicted && !answer;
|
|
177
|
+
const Icon = choice === "accept" ? CheckIcon : XIcon;
|
|
178
|
+
const sub = proposed ? "Predicted"
|
|
179
|
+
: on ? (stagedWord ?? (verdict === "miss" ? "Overturned" : verdict === "match" ? "Confirmed" : decided === choice ? "Recorded" : null))
|
|
180
|
+
: null;
|
|
181
|
+
return (
|
|
182
|
+
<button
|
|
183
|
+
aria-disabled={disabled ? true : undefined}
|
|
184
|
+
aria-pressed={on}
|
|
185
|
+
className={cn(
|
|
186
|
+
"relative inline-flex min-w-0 flex-col items-center justify-center gap-px rounded-[var(--feed-radius-md,16px)] px-2 font-medium outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring @max-[17rem]/decision:px-1",
|
|
187
|
+
cell,
|
|
188
|
+
// Three degrees of finish, in tone alone: the feed register has no borders to spend
|
|
189
|
+
// (newsroom-organizer.css strips them), so a chosen answer is the solid fill, the
|
|
190
|
+
// predicted side is the control tone, and an untouched side is quieter still.
|
|
191
|
+
on ? "bg-[var(--primary)] font-semibold text-[var(--primary-foreground)]"
|
|
192
|
+
: proposed ? "bg-[var(--feed-control)] text-foreground hover:bg-[var(--feed-control)]/70"
|
|
193
|
+
: "bg-[var(--feed-control)]/45 text-muted-foreground hover:bg-[var(--feed-control)]/70",
|
|
194
|
+
disabled && !on && "opacity-[var(--feed-quiet,0.6)]",
|
|
195
|
+
)}
|
|
196
|
+
data-predicted={predicted || undefined}
|
|
197
|
+
data-review-choice={choice}
|
|
198
|
+
data-state={on ? (saving || needsReason ? "staged" : "decided") : proposed ? "predicted" : "idle"}
|
|
199
|
+
key={choice}
|
|
200
|
+
onClick={() => { if (!disabled) onChoose(choice); }}
|
|
201
|
+
type="button"
|
|
202
|
+
>
|
|
203
|
+
{/* The model's opinion survives the answer, on the segment it picked. */}
|
|
204
|
+
{predicted && answer ? (
|
|
205
|
+
<span
|
|
206
|
+
className={cn(
|
|
207
|
+
"absolute top-1.5 right-2 opacity-55",
|
|
208
|
+
verdict === "match" && "text-[var(--feed-verdict-match-fill,#059669)] opacity-100",
|
|
209
|
+
verdict === "miss" && "text-[var(--feed-verdict-miss-fill,#dc2626)] opacity-100",
|
|
210
|
+
)}
|
|
211
|
+
data-prediction-mark
|
|
212
|
+
data-verdict={verdict ?? undefined}
|
|
213
|
+
title="this is what was predicted"
|
|
214
|
+
>
|
|
215
|
+
<svg aria-hidden="true" className="size-3" fill="none" stroke="currentColor" strokeWidth="2" viewBox="0 0 24 24">
|
|
216
|
+
<circle cx="12" cy="12" r="8" />
|
|
217
|
+
<circle cx="12" cy="12" fill="currentColor" r="2.6" stroke="none" />
|
|
218
|
+
</svg>
|
|
219
|
+
</span>
|
|
220
|
+
) : null}
|
|
221
|
+
<span className="flex items-center gap-1.5">
|
|
222
|
+
<Icon aria-hidden="true" className={cn("size-4", !on && "opacity-[var(--feed-quiet,0.6)]")} />
|
|
223
|
+
{WORD[choice]}
|
|
224
|
+
</span>
|
|
225
|
+
{sub ? <span className={cn(LABEL, "opacity-75")} data-choice-state>{sub}</span> : null}
|
|
226
|
+
{verdict && predicted ? <span className="sr-only">{verdict === "match" ? ", this is what was predicted" : ", the prediction was the other way"}</span> : null}
|
|
227
|
+
</button>
|
|
228
|
+
);
|
|
229
|
+
})}
|
|
230
|
+
</div>
|
|
231
|
+
|
|
232
|
+
{showReason ? (
|
|
233
|
+
<div className="grid gap-y-1.5" data-review-reason>
|
|
234
|
+
<label className={cn(LABEL, "text-muted-foreground")} htmlFor={fieldId}>
|
|
235
|
+
Reason{reasonRequiredFor ? ` · required to ${WORD[reasonRequiredFor].toLowerCase()}` : " · optional"}
|
|
236
|
+
</label>
|
|
237
|
+
{/* Written reasons only. A row of canned answers collects a label the model mostly has already;
|
|
238
|
+
what trains the next prediction is a sentence. */}
|
|
239
|
+
<textarea
|
|
240
|
+
className={cn(
|
|
241
|
+
"w-full rounded-[var(--feed-radius-md,16px)] border-0 bg-[var(--feed-control)] px-3 py-2 text-sm leading-5 text-foreground outline-none transition-[min-height] placeholder:text-muted-foreground focus-visible:ring-[3px] focus-visible:ring-ring",
|
|
242
|
+
field,
|
|
243
|
+
)}
|
|
244
|
+
disabled={disabled}
|
|
245
|
+
id={fieldId}
|
|
246
|
+
onBlur={() => { if (!disabled) onReasonCommit?.(); }}
|
|
247
|
+
onChange={(event) => { setReasonDirty(true); onReasonChange?.(event.target.value); }}
|
|
248
|
+
placeholder="Why? In your own words — this is what the next prediction learns from."
|
|
249
|
+
value={reason}
|
|
250
|
+
/>
|
|
251
|
+
</div>
|
|
252
|
+
) : null}
|
|
253
|
+
|
|
254
|
+
<div
|
|
255
|
+
className={cn(
|
|
256
|
+
"flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground",
|
|
257
|
+
// The overlay strip is 16px tall: a question with a button, or an error, needs a row of its own.
|
|
258
|
+
statusOverlay && !needsReason && feedback.phase !== "error" ? "absolute inset-x-4 bottom-0 h-4 overflow-hidden leading-4" : "min-h-5",
|
|
259
|
+
)}
|
|
260
|
+
data-feed-saved
|
|
261
|
+
role="status"
|
|
262
|
+
>
|
|
263
|
+
{note ? <span data-feed-reason>{note}</span> : null}
|
|
264
|
+
{needsReason ? (
|
|
265
|
+
<>
|
|
266
|
+
<span className="font-semibold text-foreground">A reason is needed to record {WORD[answer ?? "reject"]}</span>
|
|
267
|
+
<button
|
|
268
|
+
className="rounded-[var(--feed-radius-md,16px)] bg-[var(--primary)] px-2.5 py-0.5 font-semibold text-[var(--primary-foreground)] outline-none focus-visible:ring-[3px] focus-visible:ring-ring disabled:opacity-[var(--feed-quiet,0.6)]"
|
|
269
|
+
disabled={!reason.trim()}
|
|
270
|
+
data-review-record
|
|
271
|
+
onClick={() => { if (answer) onChoose(answer); }}
|
|
272
|
+
type="button"
|
|
273
|
+
>
|
|
274
|
+
Record
|
|
275
|
+
</button>
|
|
276
|
+
</>
|
|
277
|
+
) : null}
|
|
278
|
+
{saving ? <span className="inline-flex items-center gap-1"><Loader2Icon aria-hidden="true" className="size-3.5 animate-spin" />Recording…</span> : null}
|
|
279
|
+
{feedback.phase === "saved" && !needsReason ? (
|
|
280
|
+
<span className="inline-flex items-center gap-1 text-foreground" data-review-saved>
|
|
281
|
+
<CheckIcon aria-hidden="true" className="size-3.5" />
|
|
282
|
+
Recorded
|
|
283
|
+
{verdict ? <span className="text-muted-foreground">· {verdict === "match" ? "confirms" : "overturns"} the prediction</span> : null}
|
|
284
|
+
{showReason ? (
|
|
285
|
+
reasonDirty ? <span className="text-muted-foreground">· reason not saved yet</span>
|
|
286
|
+
: reason.trim() ? <span className="text-muted-foreground">· reason saved</span>
|
|
287
|
+
: <span className="text-muted-foreground">· no reason given</span>
|
|
288
|
+
) : null}
|
|
289
|
+
</span>
|
|
290
|
+
) : null}
|
|
291
|
+
{feedback.phase === "saved" && reasonDirty && showReason ? (
|
|
292
|
+
<button
|
|
293
|
+
className="rounded-[var(--feed-radius-md,16px)] bg-[var(--primary)] px-2.5 py-0.5 font-semibold text-[var(--primary-foreground)] outline-none focus-visible:ring-[3px] focus-visible:ring-ring"
|
|
294
|
+
data-review-save-reason
|
|
295
|
+
onClick={() => onReasonCommit?.()}
|
|
296
|
+
type="button"
|
|
297
|
+
>
|
|
298
|
+
Save reason
|
|
299
|
+
</button>
|
|
300
|
+
) : null}
|
|
301
|
+
</div>
|
|
302
|
+
{disabledReason ? <p className="text-xs text-muted-foreground" data-review-disabled-reason>{disabledReason}</p> : null}
|
|
303
|
+
{feedback.phase === "error" ? <p className="text-xs text-destructive" role="alert">{feedback.message}</p> : null}
|
|
304
|
+
</div>
|
|
305
|
+
);
|
|
306
|
+
}
|
|
@@ -13,7 +13,7 @@ import type { NeedsMeEntry } from "../lib/needs-me-items";
|
|
|
13
13
|
import { answerWords, formatWhen, nextText, steeringText, subjectHref, subjectLabel } from "../lib/review-requests";
|
|
14
14
|
import { DecidedLine } from "./notification-cards";
|
|
15
15
|
import { SourceMark } from "./reference-feed";
|
|
16
|
-
import {
|
|
16
|
+
import { DecisionControl } from "./decision-control";
|
|
17
17
|
import type { RatingController } from "./use-reference-ratings";
|
|
18
18
|
import { FlagFooter, decidedChoiceOf, recordedAnswer } from "./needs-me-shared";
|
|
19
19
|
|
|
@@ -111,7 +111,7 @@ export function DecisionPanel({ item, ratings, extras, onExtras, disabledReason,
|
|
|
111
111
|
{item.decisionState === "acknowledged"
|
|
112
112
|
? <p className="flex items-center gap-1.5 text-sm font-medium" data-flag-acknowledged><CircleCheckIcon aria-hidden="true" className="size-4" />Acknowledged</p>
|
|
113
113
|
: <DecidedLine choice={decided ?? "accept"} notThisKind={recorded.notThisKind} />}
|
|
114
|
-
{flag ? null : <
|
|
114
|
+
{flag ? null : <DecisionControl answer={decided} disabled feedback={{ phase: "idle" }} onChoose={() => undefined} prediction={{ state: "none" }} showPrediction={false} showReason={false} size="large" surface="footer" />}
|
|
115
115
|
{lockedNote ? <p className="text-xs text-muted-foreground" data-review-disabled-reason>{lockedNote}</p> : null}
|
|
116
116
|
</>
|
|
117
117
|
) : (
|
|
@@ -134,7 +134,7 @@ export function DecisionPanel({ item, ratings, extras, onExtras, disabledReason,
|
|
|
134
134
|
{flag ? (
|
|
135
135
|
<FlagFooter busy={busy} disabledReason={disabledReason} done={false} error={rating.feedback.phase === "error" ? rating.feedback.message ?? null : null} onAcknowledge={() => ratings.choose(item.id, "accept")} />
|
|
136
136
|
) : (
|
|
137
|
-
<
|
|
137
|
+
<DecisionControl
|
|
138
138
|
answer={rating.pending}
|
|
139
139
|
disabled={Boolean(disabledReason)}
|
|
140
140
|
disabledReason={disabledReason}
|
|
@@ -142,6 +142,7 @@ export function DecisionPanel({ item, ratings, extras, onExtras, disabledReason,
|
|
|
142
142
|
onChoose={(choice) => { if (!disabledReason) ratings.choose(item.id, choice); }}
|
|
143
143
|
prediction={{ state: "none" }}
|
|
144
144
|
showPrediction={false}
|
|
145
|
+
showReason={false}
|
|
145
146
|
size="large"
|
|
146
147
|
surface="footer"
|
|
147
148
|
/>
|
|
@@ -32,7 +32,7 @@ import { NotificationSkeleton, RecentDecisions } from "./notification-cards";
|
|
|
32
32
|
import { FEED_GRID, FEED_SURFACE_PROPS, FeedImage, PILL, REASON_LABELS, SELECTED_RING, SourceMark } from "./reference-feed";
|
|
33
33
|
import { predictionFromDecision, ReviewQueueBar, useQueueGestures, type CardPrediction, type ReviewChoice } from "./reference-review-card";
|
|
34
34
|
import type { CorrectCaptureAction } from "./reference-capture-client";
|
|
35
|
-
import {
|
|
35
|
+
import { DecisionControl } from "./decision-control";
|
|
36
36
|
import { useMediaQuery } from "./use-media-query";
|
|
37
37
|
import { useRatingStore, type RatingController } from "./use-reference-ratings";
|
|
38
38
|
import { useResolvedPapyrusTheme } from "./use-resolved-papyrus-theme";
|
|
@@ -169,30 +169,24 @@ export function NeedsMeCard({ item, now, onOpen, predictionLoading, ratings, sel
|
|
|
169
169
|
{flag ? (
|
|
170
170
|
<FlagFooter busy={rating.feedback.phase === "saving"} disabledReason={disabledReason} done={item.decisionState === "acknowledged"} error={rating.feedback.phase === "error" ? rating.feedback.message ?? null : null} onAcknowledge={() => ratings.choose(item.id, "accept")} />
|
|
171
171
|
) : (
|
|
172
|
-
<
|
|
172
|
+
<DecisionControl
|
|
173
173
|
answer={chosen}
|
|
174
174
|
decided={decided}
|
|
175
175
|
disabled={Boolean(disabledReason) || locked}
|
|
176
176
|
disabledReason={disabledReason}
|
|
177
177
|
feedback={feedback}
|
|
178
|
+
needsReason={refLike && rating.askReason}
|
|
178
179
|
note={reasonLabel ? `Reason: ${reasonLabel}` : locked ? whyLine ?? "Decided here." : null}
|
|
179
180
|
onChoose={(choice) => { if (!disabledReason && !locked) ratings.choose(item.id, choice); }}
|
|
181
|
+
onReasonChange={(text) => ratings.setNote(item.id, text)}
|
|
182
|
+
onReasonCommit={() => { if (!disabledReason && !locked) ratings.commitNote(item.id); }}
|
|
180
183
|
prediction={cardPrediction(item, predictionLoading)}
|
|
184
|
+
reason={rating.note ?? ""}
|
|
185
|
+
reasonRequiredFor={refLike ? "reject" : null}
|
|
181
186
|
showPrediction={refLike}
|
|
187
|
+
showReason={refLike}
|
|
182
188
|
/>
|
|
183
189
|
)}
|
|
184
|
-
{refLike && rating.askReason ? (
|
|
185
|
-
// Covers the footer rather than adding to it, so asking for a reason never pushes the cards below it down.
|
|
186
|
-
<div className="absolute inset-0 z-10 flex flex-col justify-center space-y-2 bg-[var(--feed-footer)] p-3" data-review-reasons>
|
|
187
|
-
<p className="text-xs font-medium">Reason for rejecting. Choose one to save your Reject.</p>
|
|
188
|
-
<div className="flex flex-wrap gap-1.5">
|
|
189
|
-
{REFERENCE_REJECTION_REASON_CODES.map((code) => (
|
|
190
|
-
<button className={cn(PILL, "min-h-8 bg-[var(--feed-control)] px-3 text-xs")} data-review-reason={code} key={code} onClick={() => ratings.setReason(item.id, code)} type="button">{REASON_LABELS[code]}</button>
|
|
191
|
-
))}
|
|
192
|
-
<button className={cn(PILL, "min-h-8 px-3 text-xs text-muted-foreground")} onClick={() => ratings.cancelReason(item.id)} type="button">Cancel</button>
|
|
193
|
-
</div>
|
|
194
|
-
</div>
|
|
195
|
-
) : null}
|
|
196
190
|
</div>
|
|
197
191
|
</article>
|
|
198
192
|
);
|
|
@@ -11,6 +11,7 @@ import type { NeedsMeEntry } from "../lib/needs-me-items";
|
|
|
11
11
|
import { DefaultOutcome, Heading, type DetailProps } from "./needs-me-bodies";
|
|
12
12
|
import { decidedChoiceOf } from "./needs-me-shared";
|
|
13
13
|
import { predictionFromDecision, ReviewCard, type CardPrediction } from "./reference-review-card";
|
|
14
|
+
import { ReferenceConversation } from "./reference-conversation";
|
|
14
15
|
import { ReferenceCapturePanel } from "./reference-capture-panel";
|
|
15
16
|
import { useReferenceCapture } from "./reference-capture-client";
|
|
16
17
|
import { ReferenceSourcePreview } from "./reference-source-preview";
|
|
@@ -57,6 +58,7 @@ export function ReferenceBody(props: DetailProps & { payload: Extract<NeedsMeEnt
|
|
|
57
58
|
titleHref={url}
|
|
58
59
|
>
|
|
59
60
|
{payload.decision ? <div data-reference-relevance-decision={lineageId}><ReferenceSuggestionProvenance decision={payload.decision} /></div> : null}
|
|
61
|
+
<ReferenceConversation disabledReason={disabledReason ? "Editor access is required to write messages." : null} lineageId={lineageId} referenceId={reference.id} title={referenceDisplayTitle(reference)} />
|
|
60
62
|
</ReviewCard>
|
|
61
63
|
<DefaultOutcome item={item} />
|
|
62
64
|
{incomplete ? <p className="text-sm text-muted-foreground" data-needs-me-capture-note>The captured text looks cut off or missing. Read it below. If it is incomplete, choose Paste or correct the text and say whether the capture was complete, or rate the Reference as it is.</p> : null}
|