@anthusai/papyrus 5.43.0-next.6 → 5.43.0-next.8

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.
Files changed (39) hide show
  1. package/amplify/functions/category-action/handler.ts +2 -1
  2. package/amplify/functions/procedure-action/handler.ts +2 -10
  3. package/amplify/functions/proposal-actions/proposals.py +20 -3
  4. package/amplify/plugins/reader-steering/function/handler.py +1 -3
  5. package/amplify/plugins/reader-steering/function/moderation.py +19 -0
  6. package/bin/papyrus-infra.mjs +21 -1
  7. package/components/dev-sandbox-editor-sign-in.tsx +2 -2
  8. package/components/monitoring-overview-view.tsx +4 -2
  9. package/components/news-desk-client-provider.tsx +8 -2
  10. package/components/news-desk-taxonomy-client.ts +2 -1
  11. package/components/newsroom-ops-overview.tsx +6 -1
  12. package/components/newsroom-references-view.tsx +2 -4
  13. package/components/notification-center.tsx +345 -63
  14. package/components/papyrus-console-shell.tsx +2 -1
  15. package/components/proposals-panel.tsx +21 -24
  16. package/components/proposals-view.tsx +4 -2
  17. package/components/reference-review-card.tsx +80 -63
  18. package/infra/amplify-app-shell.js +18 -2
  19. package/infra/amplify-app-shell.ts +18 -2
  20. package/infra/chat-stack.js +222 -0
  21. package/infra/chat-stack.ts +250 -0
  22. package/infra/chat.test.js +142 -0
  23. package/infra/chat.test.ts +151 -0
  24. package/infra/index.js +1 -0
  25. package/infra/site-config.js +58 -1
  26. package/infra/site-config.ts +78 -1
  27. package/lib/monitoring-overview.ts +2 -0
  28. package/lib/newsroom-chat-identity.ts +2 -1
  29. package/lib/newsroom-organizer-nav.ts +1 -0
  30. package/lib/proposals-client.ts +29 -0
  31. package/lib/reader-subject.ts +3 -2
  32. package/lib/review-client.ts +38 -1
  33. package/lib/review-drafts.ts +231 -0
  34. package/lib/review-fixture.ts +36 -2
  35. package/lib/review-requests.ts +64 -24
  36. package/lib/staff-groups.ts +23 -0
  37. package/lib/staging-gate.ts +2 -2
  38. package/package.json +4 -1
  39. package/routes.manifest.json +1 -1
@@ -24,6 +24,7 @@ import {
24
24
  requestDelegation,
25
25
  type DelegationStore,
26
26
  } from "../shared/curation-delegation-flow";
27
+ import { claimGroups } from "../../../lib/staff-groups";
27
28
 
28
29
  type ReviewHandler = Schema["reviewSteeringProposal"]["functionHandler"];
29
30
  type ReferenceCurationHandler = Schema["reviewReferenceCuration"]["functionHandler"];
@@ -360,7 +361,7 @@ function requireSignedInPerson(event: { identity?: unknown }): { sub: string; la
360
361
  }
361
362
  const identity = event.identity as { sub?: unknown; claims?: Record<string, unknown> };
362
363
  const claims = identity.claims ?? {};
363
- const groups = Array.isArray(claims["cognito:groups"]) ? (claims["cognito:groups"] as unknown[]) : [];
364
+ const groups = claimGroups(claims["cognito:groups"]);
364
365
  return {
365
366
  sub: normalizeRequiredString(claims.sub ?? identity.sub, "identity.sub"),
366
367
  label: normalizeOptionalString(claims.email) ?? normalizeOptionalString(claims.name) ?? "Newsroom editor",
@@ -3,6 +3,7 @@ import { getAmplifyDataClientConfig } from "@aws-amplify/backend/function/runtim
3
3
  import { Amplify } from "aws-amplify";
4
4
  import { generateClient } from "aws-amplify/data";
5
5
  import type { Schema } from "../../data/resource";
6
+ import { claimGroups } from "../../../lib/staff-groups";
6
7
 
7
8
  type DataClient = ReturnType<typeof generateClient<Schema>>;
8
9
  type DataClientErrors = Array<{ message?: string | null } | string | null> | null | undefined;
@@ -474,20 +475,11 @@ function validateJsonSchemaInput(schema: Record<string, unknown>, input: Record<
474
475
 
475
476
  function requireAdmin(event: ProcedureEvent): void {
476
477
  const claims = objectValue(event.identity?.claims);
477
- const groups = [
478
- ...normalizeClaimGroups(claims["cognito:groups"]),
479
- ...normalizeClaimGroups(claims.groups),
480
- ];
478
+ const groups = [...claimGroups(claims["cognito:groups"]), ...claimGroups(claims.groups)];
481
479
  if (groups.includes("admin")) return;
482
480
  throw new Error("Admin role required.");
483
481
  }
484
482
 
485
- function normalizeClaimGroups(value: unknown): string[] {
486
- if (Array.isArray(value)) return value.map((entry) => String(entry).trim()).filter(Boolean);
487
- if (typeof value === "string") return value.split(",").map((entry) => entry.trim()).filter(Boolean);
488
- return [];
489
- }
490
-
491
483
  async function getDataClient(): Promise<DataClient> {
492
484
  if (!clientPromise) {
493
485
  clientPromise = (async () => {
@@ -92,6 +92,25 @@ def is_appsync_event(event: dict[str, Any]) -> bool:
92
92
  return "arguments" in event and ("info" in event or event_field_name(event) is not None)
93
93
  PROPOSER_AI = "ai"
94
94
  STAFF_GROUPS = frozenset({"editor", "admin"})
95
+
96
+ _GROUP_SEPARATORS = re.compile(r"[\s,]+")
97
+
98
+
99
+ def claim_groups(value: Any) -> list[str]:
100
+ """Copy of ``papyrus_content.staff_groups.claim_groups`` (this function ships without that package; a test keeps them equal)."""
101
+ if isinstance(value, (list, tuple, set, frozenset)):
102
+ raw = [item for item in value if isinstance(item, str)]
103
+ elif isinstance(value, str):
104
+ raw = _GROUP_SEPARATORS.split(value)
105
+ else:
106
+ return []
107
+ cleaned = (item.strip().strip("\"'[](){}").strip() for item in raw)
108
+ return [item for item in cleaned if item]
109
+
110
+
111
+ def has_editor_rights(groups: Any) -> bool:
112
+ """``admin`` has every editor right: an admin who is not in the ``editor`` group is staff."""
113
+ return any(group.lower() in STAFF_GROUPS for group in claim_groups(groups))
95
114
  #: The only moves an operator's IAM role may make, as (from, to). Everything after the draft is an editor's decision.
96
115
  OPERATOR_TRANSITIONS = frozenset({(DRAFT, IN_STEERING), (DRAFT, DECLINED)})
97
116
  BY_STAFF, BY_OPERATOR = "staff", "operator"
@@ -140,10 +159,8 @@ def staff_subject(identity: dict[str, Any]) -> str | None:
140
159
  """The Cognito subject of an editor or admin, or ``None`` for anyone else."""
141
160
  claims = identity.get("claims") or {}
142
161
  groups = claims.get("cognito:groups") or identity.get("groups") or []
143
- if isinstance(groups, str):
144
- groups = [group.strip() for group in groups.strip("[]").replace(",", " ").split()]
145
162
  subject = identity.get("sub")
146
- if not isinstance(subject, str) or not subject or not STAFF_GROUPS.intersection(groups):
163
+ if not isinstance(subject, str) or not subject or not has_editor_rights(groups):
147
164
  return None
148
165
  return subject
149
166
 
@@ -1468,10 +1468,8 @@ def handle_staff_event(event: dict[str, Any], *, store: Any, settings: ReaderSet
1468
1468
  identity = event.get("identity") or {}
1469
1469
  claims = identity.get("claims") or {}
1470
1470
  groups = claims.get("cognito:groups") or identity.get("groups") or []
1471
- if isinstance(groups, str):
1472
- groups = [group.strip() for group in groups.strip("[]").replace(",", " ").split()]
1473
1471
  subject = identity.get("sub")
1474
- if not isinstance(subject, str) or not subject or not moderation_rules.STAFF_GROUPS.intersection(groups):
1472
+ if not isinstance(subject, str) or not subject or not moderation_rules.has_editor_rights(groups):
1475
1473
  return moderation_rules.refused("not_staff", "Only editors and admins can moderate.").to_dict()
1476
1474
  arguments = event.get("arguments") or {}
1477
1475
  outcome = moderation_rules.apply_action(
@@ -37,6 +37,25 @@ READER_ID = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f
37
37
  ACTION_ID = re.compile(r"mod-[0-9a-f]{32}")
38
38
  MAXIMUM_REASON = 500
39
39
  STAFF_GROUPS = frozenset({"editor", "admin"})
40
+
41
+ _GROUP_SEPARATORS = re.compile(r"[\s,]+")
42
+
43
+
44
+ def claim_groups(value: Any) -> list[str]:
45
+ """Copy of ``papyrus_content.staff_groups.claim_groups`` (this function ships without that package; a test keeps them equal)."""
46
+ if isinstance(value, (list, tuple, set, frozenset)):
47
+ raw = [item for item in value if isinstance(item, str)]
48
+ elif isinstance(value, str):
49
+ raw = _GROUP_SEPARATORS.split(value)
50
+ else:
51
+ return []
52
+ cleaned = (item.strip().strip("\"'[](){}").strip() for item in raw)
53
+ return [item for item in cleaned if item]
54
+
55
+
56
+ def has_editor_rights(groups: Any) -> bool:
57
+ """``admin`` has every editor right: an admin who is not in the ``editor`` group is staff."""
58
+ return any(group.lower() in STAFF_GROUPS for group in claim_groups(groups))
40
59
  ITEM_ID_PREFIX = "item-"
41
60
 
42
61
 
@@ -3,6 +3,7 @@
3
3
  * papyrus-infra synth --site infra/site.json [--out cdk.out] [--account A] [--region R]
4
4
  * papyrus-infra synth --account-stack github-oidc [--out cdk.out] [--account A] [--region R]
5
5
  * papyrus-infra print-buildspec --site infra/site.json --app cms-production|cms-staging|reader
6
+ * papyrus-infra synth --site infra/site.json --part chat [--chat-lambdas DIR] [--out cdk.out] (the private chat data stack)
6
7
  * papyrus-infra deploy --site infra/site.json [--only-branch main] [--only-app-id ID] [--out cdk.out] [--account A] [--region R]
7
8
  * Synthesizes the app-shell stack for a publication from its own site.json,
8
9
  * prints one of the generated Amplify build specs, or deploys the stack from
@@ -16,6 +17,7 @@ import { resolveCdkEnvironment } from "../src/cdk-environment.mjs";
16
17
 
17
18
  const USAGE = [
18
19
  "Usage: papyrus-infra synth --site infra/site.json [--out cdk.out] [--account A] [--region R]",
20
+ " papyrus-infra synth --site infra/site.json --part chat [--chat-lambdas DIR] [--out cdk.out] [--account A] [--region R]",
19
21
  " papyrus-infra synth --account-stack github-oidc [--out cdk.out] [--account A] [--region R]",
20
22
  " papyrus-infra print-buildspec --site infra/site.json --app cms-production|cms-staging|reader",
21
23
  " papyrus-infra deploy-edge --stack NAME --template FILE [--adoption-template FILE --adopt-resources FILE] [--parameter KEY=VALUE]... [--delete-function NAME] [--only-branch main] [--only-app-id ID] [--region R]",
@@ -186,8 +188,9 @@ if (command === "deploy") {
186
188
  }
187
189
 
188
190
  let AmplifyAppShellStack;
191
+ let PapyrusChatStack;
189
192
  try {
190
- ({ AmplifyAppShellStack } = await import("../infra/index.js"));
193
+ ({ AmplifyAppShellStack, PapyrusChatStack } = await import("../infra/index.js"));
191
194
  } catch (error) {
192
195
  console.error(`papyrus-infra: ${error instanceof Error ? error.message : error}`);
193
196
  process.exit(1);
@@ -195,6 +198,23 @@ try {
195
198
 
196
199
  const { App } = createRequire(path.join(process.cwd(), "noop.js"))("aws-cdk-lib");
197
200
  const app = new App({ outdir: path.resolve(opt("out", "cdk.out")) });
201
+ if (opt("part", "shell") === "chat") {
202
+ // The site's private newsroom chat data stack (docs/private-newsroom-chat-per-site.md); deployed before the app shell enables chat.
203
+ if (!config.chat?.enabled) {
204
+ console.error(`papyrus-infra: site ${config.siteId} has no enabled chat block`);
205
+ process.exit(1);
206
+ }
207
+ const lambdaAssetDirectory = opt("chat-lambdas");
208
+ const chatStack = new PapyrusChatStack(app, {
209
+ config,
210
+ env: resolveEnvironmentOrExit(),
211
+ lambdaAssetDirectory: lambdaAssetDirectory ? path.resolve(lambdaAssetDirectory) : undefined,
212
+ description: `Private Papyrus newsroom chat data plane for ${config.siteId}.`,
213
+ });
214
+ app.synth();
215
+ console.log(`synthesized ${chatStack.stackName} -> ${path.resolve(opt("out", "cdk.out"))}`);
216
+ process.exit(0);
217
+ }
198
218
  new AmplifyAppShellStack(app, `AmplifyAppShell-${config.siteId}`, config, {
199
219
  env: resolveEnvironmentOrExit(),
200
220
  stackName: resolveStackName(config),
@@ -2,9 +2,9 @@
2
2
 
3
3
  import { fetchAuthSession, signIn, signOut } from "aws-amplify/auth";
4
4
  import { configureAmplifyClient } from "./amplify-client-provider";
5
+ import { hasEditorRights } from "../lib/staff-groups";
5
6
  import type { DevSandboxEditorAuth } from "../lib/dev-sandbox-editor-auth";
6
7
 
7
- const EDITOR_GROUPS = new Set(["editor", "admin"]);
8
8
 
9
9
  function readSessionGroups(session: Awaited<ReturnType<typeof fetchAuthSession>>): string[] {
10
10
  const accessPayload = session.tokens?.accessToken?.payload ?? {};
@@ -29,7 +29,7 @@ function readSessionGroups(session: Awaited<ReturnType<typeof fetchAuthSession>>
29
29
 
30
30
  function sessionHasEditorAccess(session: Awaited<ReturnType<typeof fetchAuthSession>>): boolean {
31
31
  if (!session.tokens?.accessToken) return false;
32
- return readSessionGroups(session).some((group) => EDITOR_GROUPS.has(group));
32
+ return hasEditorRights(readSessionGroups(session));
33
33
  }
34
34
 
35
35
  export async function ensureDevSandboxEditorSession(
@@ -139,7 +139,7 @@ export function EmailSubmissions({ items, detail, onOpen, onResolveArticleLink,
139
139
  if (!isCurrentEmailSubmissionAction(activeReceiptId.current, requestReceiptId)) return;
140
140
  if (!("url" in result)) {
141
141
  const reason = "reason" in result && typeof result.reason === "string"
142
- && /^(?:redirect_[a-z_]+|resolution_record_invalid|resolution_not_recorded)$/.test(result.reason)
142
+ && /^(?:redirect_[a-z_]+|resolution_record_invalid|resolution_not_recorded|invalid_url|not_public|dns|timeout|connection|tls|loop|http_4xx|http_5xx|blocked|too_large|unreadable|unsafe_destination|no_query|search_unavailable|search_error|no_match)$/.test(result.reason)
143
143
  ? ` (${result.reason})` : "";
144
144
  setNoticeByReceipt((current) => ({ ...current, [requestReceiptId]: `The article destination could not be resolved safely${reason}. The original link remains private and unchanged.` }));
145
145
  return;
@@ -147,7 +147,9 @@ export function EmailSubmissions({ items, detail, onOpen, onResolveArticleLink,
147
147
  const candidate = detail && "submission" in detail ? detail.candidateLinks[index] : null;
148
148
  setResolvedByReceipt((current) => ({ ...current, [requestReceiptId]: { ...current[requestReceiptId], [index]: { url: result.url, title: result.title || candidate?.title || "Article" } } }));
149
149
  setSelectedByReceipt((current) => ({ ...current, [requestReceiptId]: { ...current[requestReceiptId], [index]: true } }));
150
- setNoticeByReceipt((current) => ({ ...current, [requestReceiptId]: "Resolved. This request may be recorded as a click by the newsletter sender." }));
150
+ setNoticeByReceipt((current) => ({ ...current, [requestReceiptId]: result.foundVia === "search"
151
+ ? `The newsletter link could not be followed, so this article was found by searching the headline (match ${Math.round((result.search?.matchScore ?? 0) * 100)}%). Check that it is the right article before importing it.`
152
+ : "Resolved. This request may be recorded as a click by the newsletter sender." }));
151
153
  } catch {
152
154
  if (isCurrentEmailSubmissionAction(activeReceiptId.current, requestReceiptId)) {
153
155
  setNoticeByReceipt((current) => ({ ...current, [requestReceiptId]: "The article destination could not be resolved. Try again later." }));
@@ -113,7 +113,8 @@ export function NewsDeskClientProvider({
113
113
  return;
114
114
  }
115
115
  if (isAuthorizationError(error)) {
116
- setShell((current) => resolveForbidden(current, access.auth));
116
+ // The session already has editor rights, so the backend refusing a read is not a missing role. Say what was refused.
117
+ setShell((current) => resolveDashboardFailure(current, access.auth, refusedReadMessage(error)));
117
118
  return;
118
119
  }
119
120
  setShell((current) => resolveDashboardFailure(
@@ -215,9 +216,14 @@ function isAuthorizationError(error: unknown): boolean {
215
216
  return /not authorized|unauthorized|access denied|forbidden/i.test(message);
216
217
  }
217
218
 
219
+ function refusedReadMessage(error: unknown): string {
220
+ const detail = error instanceof Error ? error.message : String(error ?? "");
221
+ return `The Newsroom backend refused a read for this signed-in account (${detail}). The account has editor or admin rights, so this is a backend authorization rule, not a missing role.`;
222
+ }
223
+
218
224
  function resolvePrivateReadFailure(state: NewsDeskShellState, auth: NewsDeskShellState["auth"], error: unknown, fallback: string): NewsDeskShellState {
219
225
  if (isUnauthenticatedError(error)) return resolveSignedOut(state, { status: "signedOut", label: "Signed out" });
220
- if (isAuthorizationError(error)) return resolveForbidden(state, auth);
226
+ if (isAuthorizationError(error)) return resolveDashboardFailure(state, auth, refusedReadMessage(error));
221
227
  return resolveDashboardFailure(state, auth, error instanceof Error ? error.message : fallback);
222
228
  }
223
229
 
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import { loadReferenceReviewDetails } from "../lib/reference-review-details";
4
+ import { hasEditorRights } from "../lib/staff-groups";
4
5
 
5
6
  import { isEditorialWorkAssignment } from "../lib/newsroom-assignments";
6
7
  import { isLocalPreviewEnabled } from "../lib/local-preview";
@@ -838,7 +839,7 @@ export async function loadEditorResolvedAccessState(): Promise<EditorAccessState
838
839
  if (!refreshed.hasSession || refreshed.auth.status === "signedOut") {
839
840
  return { status: "signedOut", isEditor: false, isAdmin: false, auth: refreshed.auth, error: null };
840
841
  }
841
- const isEditor = refreshed.groups.some((group) => group === "editor" || group === "admin");
842
+ const isEditor = hasEditorRights(refreshed.groups);
842
843
  if (!isEditor) {
843
844
  return {
844
845
  status: "forbidden",
@@ -24,6 +24,7 @@ import {
24
24
  import { newsroomInboxRowClassName } from "../lib/newsroom-list-selection";
25
25
  import type { RelevanceDecisionView } from "../lib/relevance-decisions";
26
26
  import { NotificationCenter } from "./notification-center";
27
+ import { CyclotronRow, predictionFromDecision } from "./reference-review-card";
27
28
 
28
29
  type NewsroomOpsOverviewProps = {
29
30
  assignments: AssignmentRecord[];
@@ -105,9 +106,13 @@ export function NewsroomOpsOverview({
105
106
  href={href}
106
107
  key={lineageId}
107
108
  >
108
- <div className="min-w-0 flex-1">
109
+ <div className="min-w-0 flex-1 space-y-1">
109
110
  <p className="truncate text-sm font-medium text-foreground">{referenceDisplayTitle(reference)}</p>
110
111
  <p className="text-xs text-muted-foreground">Review source intake · {formatReferenceListDate(reference)}</p>
112
+ <div data-needs-attention-suggestion={lineageId}>
113
+ <CyclotronRow prediction={decisions.get(lineageId) ? predictionFromDecision(decisions.get(lineageId)!) : { state: "none" }} />
114
+ </div>
115
+ <p className="text-xs font-medium text-foreground">Open it to Accept or Reject in the review queue</p>
111
116
  </div>
112
117
  <Badge className="mt-0.5 shrink-0" variant="outline">Pending</Badge>
113
118
  </Link>
@@ -44,6 +44,7 @@ import { newsroomListRowClassName } from "../lib/newsroom-list-selection";
44
44
  import { ReferenceSourcePreview } from "./reference-source-preview";
45
45
  import {
46
46
  ReviewCard,
47
+ predictionFromDecision,
47
48
  ReviewQueueBar,
48
49
  useQueueGestures,
49
50
  type CardPrediction,
@@ -269,10 +270,7 @@ function summaryOf(reference: ReferenceRecord): string | null {
269
270
  }
270
271
 
271
272
  function cardPrediction(decision: RelevanceDecisionView | undefined, predictionState: PredictionState): CardPrediction {
272
- if (decision) {
273
- const positive = decision.positiveLabel ?? "include";
274
- return { state: "ready", choice: decision.label === positive ? "accept" : "reject", confidence: decision.confidence };
275
- }
273
+ if (decision) return predictionFromDecision(decision);
276
274
  if (predictionState === "loading") return { state: "loading" };
277
275
  if (predictionState === "error") return { state: "error" };
278
276
  return { state: "none" };