@anthusai/papyrus 1.0.0-next.4 → 1.0.0-next.6
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/amplify/data/resource.js +6 -0
- package/amplify/data/resource.ts +7 -0
- package/amplify/data/schema.js +6 -0
- package/amplify/data/schema.ts +7 -0
- package/amplify/functions/content-actions/handler.py +44 -2
- package/amplify/rebuild-trigger-settings.js +22 -0
- package/amplify/rebuild-trigger-settings.ts +42 -0
- package/amplify/site-backend-config.ts +6 -0
- package/amplify/site-backend.js +18 -0
- package/amplify/site-backend.ts +20 -0
- package/amplify/storage/resource.js +3 -0
- package/amplify/storage/resource.ts +3 -0
- package/app/%5F_preview/[[...path]]/route.ts +8 -0
- package/app/globals.css +19 -0
- package/app/newsroom/articles/[id]/page.tsx +15 -0
- package/app/newsroom/articles/page.tsx +13 -0
- package/bin/papyrus-app.mjs +12 -2
- package/bin/papyrus-infra.mjs +26 -0
- package/components/article-video.tsx +112 -3
- package/components/markus-ir-preview.tsx +279 -0
- package/components/newsroom-access-gate.tsx +66 -0
- package/components/newsroom-article-editor.tsx +637 -0
- package/components/newsroom-articles-view.tsx +129 -0
- package/components/newsroom-ops-shell.tsx +3 -1
- package/components/topic-steering-workspace.tsx +1 -59
- package/infra/amplify-app-shell.js +56 -1
- package/infra/amplify-app-shell.ts +79 -1
- package/infra/github-oidc-provider.js +24 -0
- package/infra/github-oidc-provider.ts +30 -0
- package/infra/index.js +1 -0
- package/infra/site-config.js +31 -1
- package/infra/site-config.ts +38 -1
- package/lib/content-actions-demo.ts +172 -0
- package/lib/newsroom-articles.ts +325 -0
- package/lib/newsroom-demo-articles.ts +90 -0
- package/lib/newsroom-nav.ts +2 -0
- package/lib/site-brand.ts +13 -0
- package/lib/staging-preview-object.ts +98 -0
- package/lib/video-mode.ts +42 -0
- package/lib/video-script.ts +63 -0
- package/middleware.ts +14 -1
- package/package.json +16 -1
- package/routes.manifest.json +27 -1
- package/scripts/videoml/build-browser-bundle.mjs +22 -0
- package/scripts/videoml/build-preview-bundle.mjs +50 -0
- package/scripts/videoml/bundle-common.mjs +129 -0
- package/scripts/videoml/preview/preview-entry.tsx +381 -0
- package/scripts/videoml/preview/preview-stage-fit.ts +28 -0
- package/scripts/videoml/preview/preview-timing.ts +42 -0
- package/scripts/videoml/preview.html +77 -0
- package/scripts/videoml/standard-entry.tsx +46 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import {
|
|
3
|
+
parseMarkusDocument,
|
|
4
|
+
type MarkusBlock,
|
|
5
|
+
type MarkusDirective,
|
|
6
|
+
type MarkusInline,
|
|
7
|
+
type MarkusNode,
|
|
8
|
+
} from "../lib/markus-ir";
|
|
9
|
+
|
|
10
|
+
const TOKEN_PATTERN = /PAPYRUSMARKUP\d{5}END/g;
|
|
11
|
+
const WHOLE_TOKEN_PATTERN = /^PAPYRUSMARKUP\d{5}END$/;
|
|
12
|
+
|
|
13
|
+
type PreviewSidecar = {
|
|
14
|
+
images: Record<string, Record<string, unknown>>;
|
|
15
|
+
citations: Record<string, string[]>;
|
|
16
|
+
citationLists: Record<string, unknown>;
|
|
17
|
+
bibliography: string[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type PreviewContext = {
|
|
21
|
+
sidecar: PreviewSidecar;
|
|
22
|
+
citationNumbers: Map<string, number>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
26
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readSidecar(envelope: Record<string, unknown>): PreviewSidecar {
|
|
30
|
+
const sidecar = envelope.papyrus;
|
|
31
|
+
if (!isRecord(sidecar)) throw new Error("bodyIr.papyrus is missing");
|
|
32
|
+
const { images, citations, citationLists, bibliography } = sidecar;
|
|
33
|
+
if (!isRecord(images) || !isRecord(citations) || !isRecord(citationLists) || !Array.isArray(bibliography)) {
|
|
34
|
+
throw new Error("bodyIr.papyrus must contain images, citations, citationLists and bibliography");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
images: images as PreviewSidecar["images"],
|
|
38
|
+
citations: citations as PreviewSidecar["citations"],
|
|
39
|
+
citationLists,
|
|
40
|
+
bibliography: bibliography.map(String),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function numberCitationsByFirstAppearance(document: unknown, sidecar: PreviewSidecar): Map<string, number> {
|
|
45
|
+
const numbers = new Map<string, number>();
|
|
46
|
+
for (const token of JSON.stringify(document).match(TOKEN_PATTERN) ?? []) {
|
|
47
|
+
for (const key of sidecar.citations[token] ?? []) {
|
|
48
|
+
if (!numbers.has(key)) numbers.set(key, numbers.size + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return numbers;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function imagePlaceholder(token: string, context: PreviewContext): ReactNode {
|
|
55
|
+
const entry = context.sidecar.images[token];
|
|
56
|
+
const src = typeof entry?.src === "string" ? entry.src : "";
|
|
57
|
+
const alt = typeof entry?.alt === "string" ? entry.alt : "";
|
|
58
|
+
return (
|
|
59
|
+
<div
|
|
60
|
+
className="my-3 rounded-lg border border-dashed border-border bg-muted/30 px-3 py-6 text-center text-xs text-muted-foreground"
|
|
61
|
+
data-markus-preview-image
|
|
62
|
+
>
|
|
63
|
+
{`Image: ${src} (${alt})`}
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function renderText(text: string, context: PreviewContext): ReactNode {
|
|
69
|
+
const parts: ReactNode[] = [];
|
|
70
|
+
let cursor = 0;
|
|
71
|
+
for (const match of text.matchAll(TOKEN_PATTERN)) {
|
|
72
|
+
const token = match[0];
|
|
73
|
+
const index = match.index ?? 0;
|
|
74
|
+
const keys = context.sidecar.citations[token];
|
|
75
|
+
if (!keys) continue;
|
|
76
|
+
if (index > cursor) parts.push(text.slice(cursor, index));
|
|
77
|
+
parts.push(
|
|
78
|
+
<sup className="text-primary" key={`${index}-${token}`}>
|
|
79
|
+
{keys.map((key) => `[${context.citationNumbers.get(key)}]`).join("")}
|
|
80
|
+
</sup>,
|
|
81
|
+
);
|
|
82
|
+
cursor = index + token.length;
|
|
83
|
+
}
|
|
84
|
+
if (cursor < text.length) parts.push(text.slice(cursor));
|
|
85
|
+
return parts;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function renderInlines(inlines: MarkusInline[], context: PreviewContext): ReactNode[] {
|
|
89
|
+
return inlines.map((node, index) => {
|
|
90
|
+
switch (node.type) {
|
|
91
|
+
case "text":
|
|
92
|
+
return <span key={index}>{renderText(node.text, context)}</span>;
|
|
93
|
+
case "emphasis":
|
|
94
|
+
return <em key={index}>{renderInlines(node.children, context)}</em>;
|
|
95
|
+
case "strong":
|
|
96
|
+
return <strong key={index}>{renderInlines(node.children, context)}</strong>;
|
|
97
|
+
case "strikethrough":
|
|
98
|
+
return <s key={index}>{renderInlines(node.children, context)}</s>;
|
|
99
|
+
case "code_span":
|
|
100
|
+
return <code className="rounded bg-muted px-1 py-0.5 font-mono text-[0.85em]" key={index}>{node.code}</code>;
|
|
101
|
+
case "link":
|
|
102
|
+
return node.href ? (
|
|
103
|
+
<a className="text-primary underline" href={node.href} key={index} rel="noopener noreferrer" target="_blank">
|
|
104
|
+
{renderInlines(node.children, context)}
|
|
105
|
+
</a>
|
|
106
|
+
) : (
|
|
107
|
+
<span key={index}>{renderInlines(node.children, context)}</span>
|
|
108
|
+
);
|
|
109
|
+
case "image":
|
|
110
|
+
return (
|
|
111
|
+
<span className="rounded border border-dashed border-border px-1 text-xs text-muted-foreground" key={index}>
|
|
112
|
+
{`Image: ${node.src ?? ""} (${node.alt})`}
|
|
113
|
+
</span>
|
|
114
|
+
);
|
|
115
|
+
case "soft_break":
|
|
116
|
+
return <span key={index}>{" "}</span>;
|
|
117
|
+
case "hard_break":
|
|
118
|
+
return <br key={index} />;
|
|
119
|
+
case "html_inline":
|
|
120
|
+
return <code className="font-mono text-xs" key={index}>{node.value}</code>;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function soleToken(inlines: MarkusInline[]): string | null {
|
|
126
|
+
if (inlines.length !== 1 || inlines[0].type !== "text") return null;
|
|
127
|
+
const text = inlines[0].text.trim();
|
|
128
|
+
return WHOLE_TOKEN_PATTERN.test(text) ? text : null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const HEADING_CLASSES = [
|
|
132
|
+
"mt-5 mb-2 text-2xl font-semibold tracking-tight",
|
|
133
|
+
"mt-5 mb-2 text-xl font-semibold tracking-tight",
|
|
134
|
+
"mt-4 mb-2 text-lg font-semibold",
|
|
135
|
+
"mt-4 mb-1 text-base font-semibold",
|
|
136
|
+
"mt-3 mb-1 text-sm font-semibold",
|
|
137
|
+
"mt-3 mb-1 text-sm font-medium",
|
|
138
|
+
];
|
|
139
|
+
|
|
140
|
+
function renderBlock(block: MarkusBlock, index: number, context: PreviewContext): ReactNode {
|
|
141
|
+
switch (block.type) {
|
|
142
|
+
case "paragraph": {
|
|
143
|
+
const token = soleToken(block.inline);
|
|
144
|
+
if (token && token in context.sidecar.images) return <div key={index}>{imagePlaceholder(token, context)}</div>;
|
|
145
|
+
if (token && token in context.sidecar.citationLists) {
|
|
146
|
+
return (
|
|
147
|
+
<ol className="my-3 list-decimal space-y-1 pl-6 text-sm" data-markus-preview-bibliography key={index}>
|
|
148
|
+
{context.sidecar.bibliography.map((entry, entryIndex) => (
|
|
149
|
+
<li key={entryIndex}>{entry}</li>
|
|
150
|
+
))}
|
|
151
|
+
</ol>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return <p className="my-3 leading-relaxed" key={index}>{renderInlines(block.inline, context)}</p>;
|
|
155
|
+
}
|
|
156
|
+
case "heading": {
|
|
157
|
+
const level = Math.min(Math.max(block.level, 1), 6);
|
|
158
|
+
const Tag = `h${level}` as "h1";
|
|
159
|
+
return <Tag className={HEADING_CLASSES[level - 1]} key={index}>{renderInlines(block.inline, context)}</Tag>;
|
|
160
|
+
}
|
|
161
|
+
case "list": {
|
|
162
|
+
const items = block.items.map((item, itemIndex) => (
|
|
163
|
+
<li key={itemIndex}>{renderBlocks(item.children, context)}</li>
|
|
164
|
+
));
|
|
165
|
+
return block.ordered ? (
|
|
166
|
+
<ol className="my-3 list-decimal space-y-1 pl-6" key={index} start={block.start ?? undefined}>{items}</ol>
|
|
167
|
+
) : (
|
|
168
|
+
<ul className="my-3 list-disc space-y-1 pl-6" key={index}>{items}</ul>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
case "blockquote":
|
|
172
|
+
return (
|
|
173
|
+
<blockquote className="my-3 border-l-4 border-border pl-4 italic text-muted-foreground" key={index}>
|
|
174
|
+
{renderBlocks(block.children, context)}
|
|
175
|
+
</blockquote>
|
|
176
|
+
);
|
|
177
|
+
case "code":
|
|
178
|
+
return (
|
|
179
|
+
<pre className="my-3 overflow-x-auto rounded-lg bg-muted p-3 font-mono text-xs" key={index}>
|
|
180
|
+
<code>{block.value}</code>
|
|
181
|
+
</pre>
|
|
182
|
+
);
|
|
183
|
+
case "thematic_break":
|
|
184
|
+
return <hr className="my-4 border-border" key={index} />;
|
|
185
|
+
case "table":
|
|
186
|
+
return (
|
|
187
|
+
<div className="my-3 overflow-x-auto" key={index}>
|
|
188
|
+
<table className="w-full border-collapse text-sm">
|
|
189
|
+
<thead>
|
|
190
|
+
<tr>
|
|
191
|
+
{block.header.map((cell, cellIndex) => (
|
|
192
|
+
<th className="border border-border bg-muted/40 px-2 py-1 text-left" key={cellIndex}>
|
|
193
|
+
{renderInlines(cell, context)}
|
|
194
|
+
</th>
|
|
195
|
+
))}
|
|
196
|
+
</tr>
|
|
197
|
+
</thead>
|
|
198
|
+
<tbody>
|
|
199
|
+
{block.rows.map((row, rowIndex) => (
|
|
200
|
+
<tr key={rowIndex}>
|
|
201
|
+
{row.map((cell, cellIndex) => (
|
|
202
|
+
<td className="border border-border px-2 py-1" key={cellIndex}>{renderInlines(cell, context)}</td>
|
|
203
|
+
))}
|
|
204
|
+
</tr>
|
|
205
|
+
))}
|
|
206
|
+
</tbody>
|
|
207
|
+
</table>
|
|
208
|
+
</div>
|
|
209
|
+
);
|
|
210
|
+
case "html":
|
|
211
|
+
return (
|
|
212
|
+
<pre className="my-3 overflow-x-auto rounded-lg bg-muted p-3 font-mono text-xs" key={index}>{block.value}</pre>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderDirective(directive: MarkusDirective, index: number, context: PreviewContext): ReactNode {
|
|
218
|
+
if (directive.name === "pull-quote") {
|
|
219
|
+
const attribution = directive.attributes.attribution;
|
|
220
|
+
return (
|
|
221
|
+
<blockquote
|
|
222
|
+
className="my-4 border-y border-border px-4 py-3 text-lg font-medium italic"
|
|
223
|
+
data-markus-preview-directive="pull-quote"
|
|
224
|
+
key={index}
|
|
225
|
+
>
|
|
226
|
+
{renderBlocks(directive.children, context)}
|
|
227
|
+
{typeof attribution === "string" && attribution ? (
|
|
228
|
+
<footer className="mt-1 text-sm not-italic text-muted-foreground">{`— ${attribution}`}</footer>
|
|
229
|
+
) : null}
|
|
230
|
+
</blockquote>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const attributeEntries = Object.entries(directive.attributes).filter(([, value]) => value !== null && value !== "");
|
|
234
|
+
return (
|
|
235
|
+
<section
|
|
236
|
+
className="my-3 rounded-lg border border-border"
|
|
237
|
+
data-markus-preview-directive={directive.name}
|
|
238
|
+
key={index}
|
|
239
|
+
>
|
|
240
|
+
<header className="border-b border-border bg-muted/40 px-3 py-1 text-xs font-semibold uppercase tracking-wide text-muted-foreground">
|
|
241
|
+
{directive.name}
|
|
242
|
+
</header>
|
|
243
|
+
<div className="px-3 py-1">
|
|
244
|
+
{directive.leaf && attributeEntries.length > 0 ? (
|
|
245
|
+
<p className="my-2 font-mono text-xs text-muted-foreground">
|
|
246
|
+
{attributeEntries.map(([key, value]) => `${key}=${String(value)}`).join(" ")}
|
|
247
|
+
</p>
|
|
248
|
+
) : null}
|
|
249
|
+
{renderBlocks(directive.children, context)}
|
|
250
|
+
</div>
|
|
251
|
+
</section>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function renderBlocks(nodes: MarkusNode[], context: PreviewContext): ReactNode[] {
|
|
256
|
+
return nodes.map((node, index) =>
|
|
257
|
+
node.type === "directive" ? renderDirective(node, index, context) : renderBlock(node, index, context),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function MarkusIrPreview({ bodyIr }: { bodyIr: unknown }) {
|
|
262
|
+
try {
|
|
263
|
+
const envelope = typeof bodyIr === "string" ? JSON.parse(bodyIr) : bodyIr;
|
|
264
|
+
if (!isRecord(envelope)) throw new Error("bodyIr must be a JSON object");
|
|
265
|
+
const document = parseMarkusDocument(envelope.document);
|
|
266
|
+
const sidecar = readSidecar(envelope);
|
|
267
|
+
const context: PreviewContext = {
|
|
268
|
+
sidecar,
|
|
269
|
+
citationNumbers: numberCitationsByFirstAppearance(envelope.document, sidecar),
|
|
270
|
+
};
|
|
271
|
+
return <div data-markus-preview>{renderBlocks(document.children, context)}</div>;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
return (
|
|
274
|
+
<p className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive" data-markus-preview-error role="alert">
|
|
275
|
+
{`The preview could not be rendered: ${error instanceof Error ? error.message : "unknown error"}`}
|
|
276
|
+
</p>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import { SITE_BRAND } from "../lib/site-brand";
|
|
5
|
+
import type { NewsDeskShellState } from "../lib/news-desk-session";
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { NewsroomOpsShell } from "./newsroom-ops-shell";
|
|
8
|
+
import { ReaderAuthControl } from "./reader-auth-control";
|
|
9
|
+
import { buttonVariants } from "./ui/button";
|
|
10
|
+
|
|
11
|
+
export function NewsDeskAccessGate({ shell, showSectionTabs = false }: { shell: NewsDeskShellState | null; showSectionTabs?: boolean }) {
|
|
12
|
+
const accessPhase = shell?.phase ?? "checkingAccess";
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<NewsroomOpsShell
|
|
16
|
+
activeTab="overview"
|
|
17
|
+
appTitle={SITE_BRAND.appTitle}
|
|
18
|
+
backHref="/"
|
|
19
|
+
backLabel={SITE_BRAND.backToHomeLabel}
|
|
20
|
+
headerActions={(
|
|
21
|
+
<Link className={cn(buttonVariants({ variant: "ghost", size: "sm" }))} href="/settings">Settings</Link>
|
|
22
|
+
)}
|
|
23
|
+
pageTitle="Newsroom"
|
|
24
|
+
showNavigation={showSectionTabs}
|
|
25
|
+
>
|
|
26
|
+
<section aria-live="polite" data-news-desk-access={accessPhase} data-news-desk-access-phase={accessPhase}>
|
|
27
|
+
<div className="space-y-3 rounded-xl border border-border bg-card p-6">
|
|
28
|
+
<p className="m-0 text-[0.7rem] font-semibold uppercase tracking-[0.08em] text-muted-foreground">Access</p>
|
|
29
|
+
<h2 className="m-0 font-sans text-xl font-semibold tracking-tight">{formatAccessTitle(shell)}</h2>
|
|
30
|
+
<p className="m-0 text-sm text-muted-foreground">{formatAccessDetail(shell)}</p>
|
|
31
|
+
{shell?.error ? <p className="text-sm text-destructive">{shell.error}</p> : null}
|
|
32
|
+
<p className="m-0 text-sm text-foreground">{formatAccessActionDetail(shell)}</p>
|
|
33
|
+
{shell?.phase === "signedOut" || shell?.phase === "error" ? (
|
|
34
|
+
<div className="news-desk-access-panel__auth">
|
|
35
|
+
<ReaderAuthControl postAuthPath="/newsroom" showIdentity />
|
|
36
|
+
</div>
|
|
37
|
+
) : null}
|
|
38
|
+
</div>
|
|
39
|
+
</section>
|
|
40
|
+
</NewsroomOpsShell>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatAccessTitle(state: NewsDeskShellState | null): string {
|
|
45
|
+
if (!state || state.phase === "checkingAccess") return "Checking Desk Credentials";
|
|
46
|
+
if (state.phase === "loadingDesk") return "Loading Newsroom Records";
|
|
47
|
+
if (state.phase === "forbidden") return "Editor Role Required";
|
|
48
|
+
if (state.phase === "error") return "Newsroom Unavailable";
|
|
49
|
+
return "Editor Sign-In Required";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatAccessDetail(state: NewsDeskShellState | null): string {
|
|
53
|
+
if (!state || state.phase === "checkingAccess") return `${SITE_BRAND.appTitle} is checking the current browser session before loading steering state.`;
|
|
54
|
+
if (state.phase === "loadingDesk") return `${SITE_BRAND.appTitle} verified the browser session and is loading private Newsroom records.`;
|
|
55
|
+
if (state.phase === "forbidden") return "This account is signed in, but the Cognito session does not include the editor or admin group.";
|
|
56
|
+
if (state.phase === "error") return `${SITE_BRAND.appTitle} could not verify this editor session or load the private Newsroom data.`;
|
|
57
|
+
return "Sign in with an editor or admin account to inspect category, category tree, ontology, and graph steering.";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function formatAccessActionDetail(state: NewsDeskShellState | null): string {
|
|
61
|
+
if (!state || state.phase === "checkingAccess") return "This should only take a moment. If it hangs, reload the page.";
|
|
62
|
+
if (state.phase === "loadingDesk") return "Private records are loading from GraphQL. Large reference queues may take several seconds.";
|
|
63
|
+
if (state.phase === "forbidden") return "Ask an admin to add this account to the editor or admin group, then sign out and back in.";
|
|
64
|
+
if (state.phase === "error") return "Reload the page or check the local development console for the GraphQL error.";
|
|
65
|
+
return "Use the login button above to authenticate with an editor or admin account.";
|
|
66
|
+
}
|