@anthusai/papyrus 0.0.0 → 1.0.0-next.1
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/LICENSE +21 -0
- package/amplify/auth/resource.js +61 -0
- package/amplify/auth/resource.ts +65 -0
- package/amplify/data/resource.js +2037 -0
- package/amplify/data/resource.ts +2148 -0
- package/amplify/data/schema.js +1850 -0
- package/amplify/data/schema.ts +1953 -0
- package/amplify/functions/assignment-action/handler.ts +1416 -0
- package/amplify/functions/assignment-action/resource.js +8 -0
- package/amplify/functions/assignment-action/resource.ts +9 -0
- package/amplify/functions/category-action/handler.ts +2259 -0
- package/amplify/functions/category-action/resource.js +8 -0
- package/amplify/functions/category-action/resource.ts +9 -0
- package/amplify/functions/console-chat-responder/Cargo.lock +3456 -0
- package/amplify/functions/console-chat-responder/Cargo.toml +26 -0
- package/amplify/functions/console-chat-responder/Dockerfile +19 -0
- package/amplify/functions/console-chat-responder/py/execute_tactus_runner.py +116 -0
- package/amplify/functions/console-chat-responder/resource.js +153 -0
- package/amplify/functions/console-chat-responder/resource.ts +179 -0
- package/amplify/functions/console-chat-responder/src/main.rs +3242 -0
- package/amplify/functions/email-submission-processor/handler.py +46 -0
- package/amplify/functions/email-submission-processor/requirements.txt +2 -0
- package/amplify/functions/email-submission-processor/resource.js +56 -0
- package/amplify/functions/email-submission-processor/resource.ts +69 -0
- package/amplify/functions/graphql-jwt-authorizer/handler.ts +193 -0
- package/amplify/functions/graphql-jwt-authorizer/resource.js +14 -0
- package/amplify/functions/graphql-jwt-authorizer/resource.ts +15 -0
- package/amplify/functions/knowledge-query/handler.py +1 -0
- package/amplify/functions/knowledge-query/requirements.txt +3 -0
- package/amplify/functions/knowledge-query/resource.js +50 -0
- package/amplify/functions/knowledge-query/resource.ts +61 -0
- package/amplify/functions/manage-user-role/handler.ts +799 -0
- package/amplify/functions/manage-user-role/resource.js +8 -0
- package/amplify/functions/manage-user-role/resource.ts +9 -0
- package/amplify/functions/model-attachment-upload/handler.ts +387 -0
- package/amplify/functions/model-attachment-upload/resource.js +8 -0
- package/amplify/functions/model-attachment-upload/resource.ts +9 -0
- package/amplify/functions/newsroom-summary/handler.ts +321 -0
- package/amplify/functions/newsroom-summary/resource.js +8 -0
- package/amplify/functions/newsroom-summary/resource.ts +9 -0
- package/amplify/functions/procedure-action/handler.ts +621 -0
- package/amplify/functions/procedure-action/resource.js +8 -0
- package/amplify/functions/procedure-action/resource.ts +9 -0
- package/amplify/functions/reader-settings/handler.ts +322 -0
- package/amplify/functions/reader-settings/resource.js +8 -0
- package/amplify/functions/reader-settings/resource.ts +9 -0
- package/amplify/functions/ses-inbound-receive/handler.ts +493 -0
- package/amplify/functions/ses-inbound-receive/resource.js +8 -0
- package/amplify/functions/ses-inbound-receive/resource.ts +9 -0
- package/amplify/functions/shared/amplify-secrets.ts +65 -0
- package/amplify/functions/shared/console-chat-enqueue.ts +117 -0
- package/amplify/functions/shared/email-mime-intake.ts +196 -0
- package/amplify/functions/shared/email-submission.ts +415 -0
- package/amplify/functions/shared/inbound-email-intake.ts +37 -0
- package/amplify/functions/shared/lambda-data-client.ts +21 -0
- package/amplify/functions/shared/model-payloads.ts +186 -0
- package/amplify/functions/shared/python-bundle.js +115 -0
- package/amplify/functions/shared/python-bundle.ts +141 -0
- package/amplify/functions/shared/slack-events.ts +111 -0
- package/amplify/functions/slack-delivery/handler.py +112 -0
- package/amplify/functions/slack-delivery/requirements.txt +2 -0
- package/amplify/functions/slack-delivery/resource.js +38 -0
- package/amplify/functions/slack-delivery/resource.ts +51 -0
- package/amplify/functions/slack-events/handler.ts +155 -0
- package/amplify/functions/slack-events/resource.js +11 -0
- package/amplify/functions/slack-events/resource.ts +12 -0
- package/amplify/inbound-email/stack.js +46 -0
- package/amplify/inbound-email/stack.ts +61 -0
- package/amplify/package.json +3 -0
- package/amplify/site-backend-config.js +1 -0
- package/amplify/site-backend-config.ts +30 -0
- package/amplify/site-backend.js +587 -0
- package/amplify/site-backend.ts +704 -0
- package/amplify/storage/resource.js +18 -0
- package/amplify/storage/resource.ts +19 -0
- package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +62 -0
- package/app/[year]/[month]/[day]/edition-route-page.tsx +53 -0
- package/app/[year]/[month]/[day]/page/[pageNumber]/page.tsx +32 -0
- package/app/[year]/[month]/[day]/page.tsx +22 -0
- package/app/[year]/[month]/[day]/section/[sectionKey]/page.tsx +32 -0
- package/app/api/archive/editions/route.ts +18 -0
- package/app/api/media/[...path]/route.ts +35 -0
- package/app/api/revalidate/route.ts +94 -0
- package/app/archive/page.tsx +24 -0
- package/app/articles/[slug]/page.tsx +35 -0
- package/app/globals.css +10329 -0
- package/app/layout.tsx +146 -0
- package/app/newsroom/[section]/[...selection]/page.tsx +50 -0
- package/app/newsroom/[section]/page.tsx +47 -0
- package/app/newsroom/forum/[threadId]/page.tsx +35 -0
- package/app/newsroom/insights/[threadId]/page.tsx +22 -0
- package/app/newsroom/insights/page.tsx +14 -0
- package/app/newsroom/layout.tsx +12 -0
- package/app/newsroom/page.tsx +31 -0
- package/app/newsroom/sections/[sectionId]/page.tsx +17 -0
- package/app/page.tsx +272 -0
- package/app/settings/page.tsx +14 -0
- package/app/tailwind.css +65 -0
- package/bin/papyrus-app.mjs +10 -0
- package/bin/papyrus-infra.mjs +39 -0
- package/components/ai-elements/conversation.tsx +168 -0
- package/components/ai-elements/message.tsx +360 -0
- package/components/ai-elements/model-selector.tsx +30 -0
- package/components/ai-elements/prompt-input.tsx +1461 -0
- package/components/ai-elements/shimmer.tsx +76 -0
- package/components/ai-elements/suggestion.tsx +54 -0
- package/components/ai-elements/tool.tsx +173 -0
- package/components/amplify-client-provider.tsx +140 -0
- package/components/archive-grid.tsx +89 -0
- package/components/archive-shell.tsx +41 -0
- package/components/article-video.tsx +47 -0
- package/components/blog-page-background.tsx +20 -0
- package/components/dev-sandbox-editor-sign-in.tsx +60 -0
- package/components/news-desk-client-provider.tsx +211 -0
- package/components/news-desk-page.tsx +119 -0
- package/components/news-desk-taxonomy-client.ts +3684 -0
- package/components/newspaper.tsx +1929 -0
- package/components/newsroom-assignments-view.tsx +664 -0
- package/components/newsroom-ops-overview.tsx +226 -0
- package/components/newsroom-ops-shell.tsx +319 -0
- package/components/newsroom-references-view.tsx +598 -0
- package/components/newsroom-topics-view.tsx +425 -0
- package/components/papyrus-console-shell.tsx +1912 -0
- package/components/pictogram-figure.tsx +65 -0
- package/components/presentation-footer.tsx +146 -0
- package/components/reader-auth-control.tsx +162 -0
- package/components/reader-auth-state.ts +122 -0
- package/components/reader-settings.ts +332 -0
- package/components/reader-theme-control.tsx +85 -0
- package/components/reference-source-preview.tsx +163 -0
- package/components/settings-page.tsx +239 -0
- package/components/topic-steering-workspace.tsx +18063 -0
- package/components/ui/badge.tsx +30 -0
- package/components/ui/button-group.tsx +87 -0
- package/components/ui/button.tsx +58 -0
- package/components/ui/card.tsx +32 -0
- package/components/ui/command.tsx +194 -0
- package/components/ui/dialog.tsx +158 -0
- package/components/ui/dropdown-menu.tsx +266 -0
- package/components/ui/hover-card.tsx +51 -0
- package/components/ui/input-group.tsx +158 -0
- package/components/ui/input.tsx +20 -0
- package/components/ui/scroll-area.tsx +16 -0
- package/components/ui/select.tsx +199 -0
- package/components/ui/separator.tsx +23 -0
- package/components/ui/sheet.tsx +92 -0
- package/components/ui/spinner.tsx +10 -0
- package/components/ui/tabs.tsx +113 -0
- package/components/ui/textarea.tsx +18 -0
- package/components/ui/tooltip.tsx +66 -0
- package/components/use-resolved-papyrus-theme.ts +47 -0
- package/infra/amplify-app-shell.js +109 -0
- package/infra/amplify-app-shell.ts +155 -0
- package/infra/index.js +12 -0
- package/lib/amplify-outputs-guard.ts +24 -0
- package/lib/amplify-outputs-path.ts +16 -0
- package/lib/amplify-server-runtime.ts +63 -0
- package/lib/archive-data.ts +30 -0
- package/lib/archive-types.ts +15 -0
- package/lib/articles.ts +320 -0
- package/lib/cached-content-repository.ts +89 -0
- package/lib/category-dashboard.ts +37 -0
- package/lib/category-repository.ts +1907 -0
- package/lib/console-chat-client.ts +1316 -0
- package/lib/console-web-context.ts +118 -0
- package/lib/content-load-timing.ts +23 -0
- package/lib/content-repository.ts +40 -0
- package/lib/content-types.ts +104 -0
- package/lib/define-site.js +3 -0
- package/lib/define-site.ts +21 -0
- package/lib/demo-amplify-outputs.ts +15 -0
- package/lib/dev-sandbox-editor-auth.ts +18 -0
- package/lib/doctrine.ts +128 -0
- package/lib/edition-routes.ts +155 -0
- package/lib/edition-sections.ts +111 -0
- package/lib/empty-edition-layout-plan.ts +109 -0
- package/lib/excerpts.ts +8 -0
- package/lib/graphql-content-repository.ts +986 -0
- package/lib/image-url.ts +10 -0
- package/lib/layout-plan.ts +981 -0
- package/lib/layout-scenarios.ts +564 -0
- package/lib/markus-body.ts +168 -0
- package/lib/markus-ir.ts +235 -0
- package/lib/markus-projection.ts +243 -0
- package/lib/markus-to-article.ts +93 -0
- package/lib/news-desk-session.ts +160 -0
- package/lib/newspaper-layout.ts +3459 -0
- package/lib/newsroom-assignments.ts +173 -0
- package/lib/newsroom-base-path.ts +48 -0
- package/lib/newsroom-card-layout.ts +102 -0
- package/lib/newsroom-category-drilldown.ts +133 -0
- package/lib/newsroom-demo-dashboard.ts +267 -0
- package/lib/newsroom-demo-profile.ts +46 -0
- package/lib/newsroom-forum-routes.ts +153 -0
- package/lib/newsroom-index-filters.ts +202 -0
- package/lib/newsroom-knowledge-query-request.ts +51 -0
- package/lib/newsroom-list-selection.ts +42 -0
- package/lib/newsroom-nav.ts +42 -0
- package/lib/newsroom-references.ts +116 -0
- package/lib/newsroom-sections.ts +52 -0
- package/lib/newsroom-topics.ts +118 -0
- package/lib/papyrus-object-kinds.ts +24 -0
- package/lib/papyrus-web-locations.ts +480 -0
- package/lib/pilobol-sample.ts +167 -0
- package/lib/presentation-footer.ts +92 -0
- package/lib/pretext-layout.ts +179 -0
- package/lib/public-placeholder-config.ts +102 -0
- package/lib/publication-items.ts +181 -0
- package/lib/reader-route-config.ts +1 -0
- package/lib/reader-static-params.ts +56 -0
- package/lib/reader-storage-url.ts +63 -0
- package/lib/reference-display.ts +74 -0
- package/lib/reference-policy.ts +97 -0
- package/lib/reference-source-preview.ts +175 -0
- package/lib/renderer-config.ts +50 -0
- package/lib/renderer.ts +87 -0
- package/lib/reporting-story-budget.ts +638 -0
- package/lib/semantic-graph.ts +554 -0
- package/lib/site-brand-tenant.ts +41 -0
- package/lib/site-brand.ts +179 -0
- package/lib/site-renderer.ts +17 -0
- package/lib/site-stack.ts +195 -0
- package/lib/themed-image.ts +30 -0
- package/lib/utils.ts +6 -0
- package/middleware.ts +78 -0
- package/package.json +296 -1
- package/publications/anth_us/brand.ts +68 -0
- package/publications/anth_us/theme.css +66 -0
- package/publications/papyrus/theme.css +11 -0
- package/publications/pilobol_us/brand.ts +37 -0
- package/publications/pilobol_us/theme.css +140 -0
- package/publications/threat_intelligence/blog-defense/graph.ts +636 -0
- package/publications/threat_intelligence/blog-defense/layout.ts +934 -0
- package/publications/threat_intelligence/blog-defense/page-background.tsx +590 -0
- package/publications/threat_intelligence/brand.ts +40 -0
- package/publications/threat_intelligence/pictograms/art.tsx +608 -0
- package/publications/threat_intelligence/pictograms/figure.tsx +82 -0
- package/publications/threat_intelligence/pictograms/registry.ts +30 -0
- package/publications/threat_intelligence/pictograms/system.tsx +305 -0
- package/publications/threat_intelligence/seed/seed-edition-content.json +629 -0
- package/publications/threat_intelligence/theme.css +1440 -0
- package/renderers/markus/index.ts +25 -0
- package/renderers/markus/stubs.tsx +33 -0
- package/renderers/pretext/article-page.tsx +174 -0
- package/renderers/pretext/index.ts +30 -0
- package/renderers/pretext/layouts.ts +16 -0
- package/renderers/pretext/presentation-shell.tsx +477 -0
- package/routes.manifest.json +182 -0
- package/scripts/fixtures/pilobol-sample.ast.json +234 -0
- package/src/backend.js +1 -0
- package/src/backend.ts +3 -0
- package/src/sync.mjs +87 -0
- package/src/with-papyrus.d.mts +2 -0
- package/src/with-papyrus.mjs +47 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { fetchAuthSession, signIn, signOut } from "aws-amplify/auth";
|
|
4
|
+
import { configureAmplifyClient } from "./amplify-client-provider";
|
|
5
|
+
import type { DevSandboxEditorAuth } from "../lib/dev-sandbox-editor-auth";
|
|
6
|
+
|
|
7
|
+
const EDITOR_GROUPS = new Set(["editor", "admin"]);
|
|
8
|
+
|
|
9
|
+
function readSessionGroups(session: Awaited<ReturnType<typeof fetchAuthSession>>): string[] {
|
|
10
|
+
const accessPayload = session.tokens?.accessToken?.payload ?? {};
|
|
11
|
+
const idPayload = session.tokens?.idToken?.payload ?? {};
|
|
12
|
+
const rawGroups = [
|
|
13
|
+
accessPayload["cognito:groups"],
|
|
14
|
+
accessPayload.groups,
|
|
15
|
+
idPayload["cognito:groups"],
|
|
16
|
+
idPayload.groups,
|
|
17
|
+
];
|
|
18
|
+
const groups: string[] = [];
|
|
19
|
+
for (const value of rawGroups) {
|
|
20
|
+
if (typeof value === "string" && value.trim()) groups.push(value.trim());
|
|
21
|
+
else if (Array.isArray(value)) {
|
|
22
|
+
for (const entry of value) {
|
|
23
|
+
if (typeof entry === "string" && entry.trim()) groups.push(entry.trim());
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return [...new Set(groups)];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function sessionHasEditorAccess(session: Awaited<ReturnType<typeof fetchAuthSession>>): boolean {
|
|
31
|
+
if (!session.tokens?.accessToken) return false;
|
|
32
|
+
return readSessionGroups(session).some((group) => EDITOR_GROUPS.has(group));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function ensureDevSandboxEditorSession(
|
|
36
|
+
credentials: DevSandboxEditorAuth | null | undefined,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
if (!credentials) return;
|
|
39
|
+
|
|
40
|
+
configureAmplifyClient();
|
|
41
|
+
|
|
42
|
+
const existing = await fetchAuthSession();
|
|
43
|
+
if (sessionHasEditorAccess(existing)) return;
|
|
44
|
+
|
|
45
|
+
if (existing.tokens?.accessToken) {
|
|
46
|
+
try {
|
|
47
|
+
await signOut();
|
|
48
|
+
} catch {
|
|
49
|
+
// Continue into seed sign-in even if sign-out fails.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const result = await signIn({
|
|
54
|
+
username: credentials.username,
|
|
55
|
+
password: credentials.password,
|
|
56
|
+
});
|
|
57
|
+
if (!result.isSignedIn) return;
|
|
58
|
+
|
|
59
|
+
await fetchAuthSession({ forceRefresh: true });
|
|
60
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Hub } from "aws-amplify/utils";
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import type { DevSandboxEditorAuth } from "../lib/dev-sandbox-editor-auth";
|
|
6
|
+
import { ensureDevSandboxEditorSession } from "./dev-sandbox-editor-sign-in";
|
|
7
|
+
import {
|
|
8
|
+
loadEditorAssignmentsData,
|
|
9
|
+
loadEditorDoctrineRecordsData,
|
|
10
|
+
loadEditorNewsDeskDashboard,
|
|
11
|
+
loadEditorResolvedAccessState,
|
|
12
|
+
loadEditorUserDirectoryData,
|
|
13
|
+
} from "./news-desk-taxonomy-client";
|
|
14
|
+
import {
|
|
15
|
+
beginAccessCheck,
|
|
16
|
+
beginAuthenticatedDeskHydration,
|
|
17
|
+
createInitialNewsDeskShellState,
|
|
18
|
+
patchDashboard,
|
|
19
|
+
resolveDashboardFailure,
|
|
20
|
+
resolveDashboardReady,
|
|
21
|
+
resolveForbidden,
|
|
22
|
+
resolveSignedOut,
|
|
23
|
+
type NewsDeskShellState,
|
|
24
|
+
} from "../lib/news-desk-session";
|
|
25
|
+
|
|
26
|
+
export type NewsDeskSearchTransition = {
|
|
27
|
+
href: string;
|
|
28
|
+
kind: "modal-to-serp";
|
|
29
|
+
requestKey: string;
|
|
30
|
+
submittedAt: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type NewsDeskClientContextValue = {
|
|
34
|
+
beginSearchTransition: (transition: NewsDeskSearchTransition) => void;
|
|
35
|
+
clearSearchTransition: () => void;
|
|
36
|
+
shell: NewsDeskShellState;
|
|
37
|
+
searchTransition: NewsDeskSearchTransition | null;
|
|
38
|
+
refreshDashboard: () => Promise<void>;
|
|
39
|
+
refreshAssignments: () => Promise<void>;
|
|
40
|
+
refreshDoctrineRecords: () => Promise<void>;
|
|
41
|
+
refreshUserDirectory: () => Promise<void>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const NewsDeskClientContext = createContext<NewsDeskClientContextValue | null>(null);
|
|
45
|
+
|
|
46
|
+
export function NewsDeskClientProvider({
|
|
47
|
+
children,
|
|
48
|
+
devSandboxEditorAuth = null,
|
|
49
|
+
}: Readonly<{ children: React.ReactNode; devSandboxEditorAuth?: DevSandboxEditorAuth | null }>) {
|
|
50
|
+
const [shell, setShell] = useState<NewsDeskShellState>(() => createInitialNewsDeskShellState());
|
|
51
|
+
const [searchTransition, setSearchTransition] = useState<NewsDeskSearchTransition | null>(null);
|
|
52
|
+
const shellRef = useRef(shell);
|
|
53
|
+
const bootstrapSequenceRef = useRef(0);
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
shellRef.current = shell;
|
|
57
|
+
}, [shell]);
|
|
58
|
+
|
|
59
|
+
const refreshDashboard = useCallback(async () => {
|
|
60
|
+
const sequence = ++bootstrapSequenceRef.current;
|
|
61
|
+
setShell((current) => beginAccessCheck(current));
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await ensureDevSandboxEditorSession(devSandboxEditorAuth);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("[PapyrusDevAuth] Sandbox editor auto sign-in failed:", error);
|
|
67
|
+
}
|
|
68
|
+
if (bootstrapSequenceRef.current !== sequence) return;
|
|
69
|
+
|
|
70
|
+
const access = await loadEditorResolvedAccessState();
|
|
71
|
+
if (bootstrapSequenceRef.current !== sequence) return;
|
|
72
|
+
|
|
73
|
+
if (access.status === "signedOut") {
|
|
74
|
+
setShell((current) => resolveSignedOut(current, access.auth));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (access.status === "forbidden") {
|
|
78
|
+
setShell((current) => resolveForbidden(current, access.auth));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (access.status === "error") {
|
|
82
|
+
setShell((current) => resolveDashboardFailure(current, access.auth, access.error));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setShell((current) => beginAuthenticatedDeskHydration(current, access.auth, { canManageUsers: access.isAdmin }));
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const dashboard = await loadEditorNewsDeskDashboard({ isAdmin: access.isAdmin });
|
|
90
|
+
if (bootstrapSequenceRef.current !== sequence) return;
|
|
91
|
+
setShell((current) => resolveDashboardReady(current, dashboard, access.auth, new Date().toISOString()));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (bootstrapSequenceRef.current !== sequence) return;
|
|
94
|
+
if (isAuthorizationError(error)) {
|
|
95
|
+
setShell((current) => resolveForbidden(current, access.auth));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setShell((current) => resolveDashboardFailure(
|
|
99
|
+
current,
|
|
100
|
+
access.auth,
|
|
101
|
+
error instanceof Error ? error.message : "Could not load Newsroom data.",
|
|
102
|
+
));
|
|
103
|
+
}
|
|
104
|
+
}, [devSandboxEditorAuth]);
|
|
105
|
+
|
|
106
|
+
const refreshAssignments = useCallback(async () => {
|
|
107
|
+
try {
|
|
108
|
+
const assignmentState = await loadEditorAssignmentsData();
|
|
109
|
+
setShell((current) => patchDashboard(
|
|
110
|
+
current,
|
|
111
|
+
(dashboard) => ({
|
|
112
|
+
...dashboard,
|
|
113
|
+
assignments: assignmentState.assignments,
|
|
114
|
+
assignmentEvents: assignmentState.assignmentEvents,
|
|
115
|
+
}),
|
|
116
|
+
new Date().toISOString(),
|
|
117
|
+
));
|
|
118
|
+
} catch (error) {
|
|
119
|
+
const auth = shellRef.current.auth;
|
|
120
|
+
setShell((current) => resolveDashboardFailure(
|
|
121
|
+
current,
|
|
122
|
+
auth,
|
|
123
|
+
error instanceof Error ? error.message : "Could not refresh assignments.",
|
|
124
|
+
));
|
|
125
|
+
}
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
const refreshDoctrineRecords = useCallback(async () => {
|
|
129
|
+
try {
|
|
130
|
+
const doctrineRecords = await loadEditorDoctrineRecordsData({ dashboard: shellRef.current.dashboard });
|
|
131
|
+
setShell((current) => patchDashboard(
|
|
132
|
+
current,
|
|
133
|
+
(dashboard) => ({
|
|
134
|
+
...dashboard,
|
|
135
|
+
doctrineRecords,
|
|
136
|
+
}),
|
|
137
|
+
new Date().toISOString(),
|
|
138
|
+
));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
const auth = shellRef.current.auth;
|
|
141
|
+
setShell((current) => resolveDashboardFailure(
|
|
142
|
+
current,
|
|
143
|
+
auth,
|
|
144
|
+
error instanceof Error ? error.message : "Could not refresh doctrine records.",
|
|
145
|
+
));
|
|
146
|
+
}
|
|
147
|
+
}, []);
|
|
148
|
+
|
|
149
|
+
const refreshUserDirectory = useCallback(async () => {
|
|
150
|
+
if (!shellRef.current.dashboard?.canManageUsers) return;
|
|
151
|
+
try {
|
|
152
|
+
const userDirectory = await loadEditorUserDirectoryData();
|
|
153
|
+
setShell((current) => patchDashboard(
|
|
154
|
+
current,
|
|
155
|
+
(dashboard) => ({
|
|
156
|
+
...dashboard,
|
|
157
|
+
userDirectory,
|
|
158
|
+
}),
|
|
159
|
+
new Date().toISOString(),
|
|
160
|
+
));
|
|
161
|
+
} catch (error) {
|
|
162
|
+
const auth = shellRef.current.auth;
|
|
163
|
+
setShell((current) => resolveDashboardFailure(
|
|
164
|
+
current,
|
|
165
|
+
auth,
|
|
166
|
+
error instanceof Error ? error.message : "Could not refresh the user directory.",
|
|
167
|
+
));
|
|
168
|
+
}
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
void refreshDashboard();
|
|
173
|
+
const unsubscribe = Hub.listen("auth", ({ payload }) => {
|
|
174
|
+
if (payload.event === "signedOut") {
|
|
175
|
+
bootstrapSequenceRef.current += 1;
|
|
176
|
+
setShell((current) => resolveSignedOut(current, { status: "signedOut", label: "Signed out" }));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (
|
|
180
|
+
payload.event === "signedIn" ||
|
|
181
|
+
payload.event === "signInWithRedirect" ||
|
|
182
|
+
payload.event === "signInWithRedirect_failure"
|
|
183
|
+
) {
|
|
184
|
+
void refreshDashboard();
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return () => unsubscribe();
|
|
188
|
+
}, [refreshDashboard]);
|
|
189
|
+
|
|
190
|
+
const value = useMemo<NewsDeskClientContextValue>(() => ({
|
|
191
|
+
beginSearchTransition: (transition) => setSearchTransition(transition),
|
|
192
|
+
clearSearchTransition: () => setSearchTransition(null),
|
|
193
|
+
shell,
|
|
194
|
+
searchTransition,
|
|
195
|
+
refreshDashboard,
|
|
196
|
+
refreshAssignments,
|
|
197
|
+
refreshDoctrineRecords,
|
|
198
|
+
refreshUserDirectory,
|
|
199
|
+
}), [refreshAssignments, refreshDashboard, refreshDoctrineRecords, refreshUserDirectory, searchTransition, shell]);
|
|
200
|
+
|
|
201
|
+
return <NewsDeskClientContext.Provider value={value}>{children}</NewsDeskClientContext.Provider>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isAuthorizationError(error: unknown): boolean {
|
|
205
|
+
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
206
|
+
return /not authorized|unauthorized|access denied|forbidden/i.test(message);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function useOptionalNewsDeskClient() {
|
|
210
|
+
return useContext(NewsDeskClientContext);
|
|
211
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { cookies } from "next/headers";
|
|
2
|
+
import { NewsDeskWorkspace, type NewsDeskTab } from "./topic-steering-workspace";
|
|
3
|
+
import {
|
|
4
|
+
createDemoCategorySteeringDashboard,
|
|
5
|
+
loadAnalysisProfileSummaries,
|
|
6
|
+
loadCategorySteeringDashboard,
|
|
7
|
+
loadConfiguredCorpusSummaries,
|
|
8
|
+
} from "../lib/category-repository";
|
|
9
|
+
import {
|
|
10
|
+
BRAND_OVERRIDE_COOKIE,
|
|
11
|
+
getBrandAnalysisProfilesPath,
|
|
12
|
+
getBrandNewsroomSectionsConfigPath,
|
|
13
|
+
getBrandSteeringConfigPath,
|
|
14
|
+
resolveActiveSiteBrand,
|
|
15
|
+
} from "../lib/site-brand-tenant";
|
|
16
|
+
|
|
17
|
+
export type NewsDeskPageProps = {
|
|
18
|
+
sectionPageId?: string | null;
|
|
19
|
+
section?: string | string[] | null;
|
|
20
|
+
selectionPath?: string[] | null;
|
|
21
|
+
searchParams?: Promise<{
|
|
22
|
+
demo?: string | string[];
|
|
23
|
+
section?: string | string[];
|
|
24
|
+
tab?: string | string[];
|
|
25
|
+
panel?: string | string[];
|
|
26
|
+
reference?: string | string[];
|
|
27
|
+
category?: string | string[];
|
|
28
|
+
node?: string | string[];
|
|
29
|
+
message?: string | string[];
|
|
30
|
+
assignment?: string | string[];
|
|
31
|
+
user?: string | string[];
|
|
32
|
+
item?: string | string[];
|
|
33
|
+
q?: string | string[];
|
|
34
|
+
anchorKind?: string | string[];
|
|
35
|
+
anchorId?: string | string[];
|
|
36
|
+
anchorLineageId?: string | string[];
|
|
37
|
+
maxTokens?: string | string[];
|
|
38
|
+
from?: string | string[];
|
|
39
|
+
view?: string | string[];
|
|
40
|
+
proposal?: string | string[];
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export async function NewsDeskPage({ section: routeSection, sectionPageId, selectionPath, searchParams }: NewsDeskPageProps) {
|
|
45
|
+
const resolvedSearchParams = await searchParams;
|
|
46
|
+
const initialTab = parseNewsDeskTab(routeSection ?? getSearchParam(resolvedSearchParams, "section"), getSearchParam(resolvedSearchParams, "tab"));
|
|
47
|
+
const routeSelection = parseRouteSelection(initialTab, selectionPath);
|
|
48
|
+
const initialSelection = {
|
|
49
|
+
assignment: routeSelection.assignment ?? getFirstSearchParam(resolvedSearchParams, "assignment"),
|
|
50
|
+
reference: routeSelection.reference ?? getFirstSearchParam(resolvedSearchParams, "reference"),
|
|
51
|
+
category: routeSelection.category ?? getFirstSearchParam(resolvedSearchParams, "category"),
|
|
52
|
+
node: getFirstSearchParam(resolvedSearchParams, "node"),
|
|
53
|
+
message: routeSelection.message ?? getFirstSearchParam(resolvedSearchParams, "message"),
|
|
54
|
+
user: getFirstSearchParam(resolvedSearchParams, "user"),
|
|
55
|
+
item: getFirstSearchParam(resolvedSearchParams, "item"),
|
|
56
|
+
panel: routeSelection.panel ?? getFirstSearchParam(resolvedSearchParams, "panel"),
|
|
57
|
+
searchQuery: getFirstSearchParam(resolvedSearchParams, "q"),
|
|
58
|
+
searchAnchorKind: getFirstSearchParam(resolvedSearchParams, "anchorKind"),
|
|
59
|
+
searchAnchorId: getFirstSearchParam(resolvedSearchParams, "anchorId"),
|
|
60
|
+
searchAnchorLineageId: getFirstSearchParam(resolvedSearchParams, "anchorLineageId"),
|
|
61
|
+
searchMaxTokens: getFirstSearchParam(resolvedSearchParams, "maxTokens"),
|
|
62
|
+
searchFrom: getFirstSearchParam(resolvedSearchParams, "from"),
|
|
63
|
+
assignmentView: getFirstSearchParam(resolvedSearchParams, "view"),
|
|
64
|
+
forumThread: routeSelection.forumThread,
|
|
65
|
+
proposal: getFirstSearchParam(resolvedSearchParams, "proposal"),
|
|
66
|
+
};
|
|
67
|
+
const useDemoDashboard = getFirstSearchParam(resolvedSearchParams, "demo") === "1";
|
|
68
|
+
const brandOverride = (await cookies()).get(BRAND_OVERRIDE_COOKIE)?.value ?? null;
|
|
69
|
+
const brand = resolveActiveSiteBrand(brandOverride);
|
|
70
|
+
const analysisProfiles = await loadAnalysisProfileSummaries(getBrandAnalysisProfilesPath(brand));
|
|
71
|
+
const configuredCorpora = await loadConfiguredCorpusSummaries(getBrandSteeringConfigPath(brand));
|
|
72
|
+
const dashboard = useDemoDashboard
|
|
73
|
+
? createDemoCategorySteeringDashboard(brand.id, getBrandNewsroomSectionsConfigPath(brand))
|
|
74
|
+
: await loadCategorySteeringDashboard();
|
|
75
|
+
return <NewsDeskWorkspace analysisProfiles={analysisProfiles} configuredCorpora={configuredCorpora} dashboard={dashboard} initialSelection={initialSelection} initialTab={initialTab} sectionPageId={sectionPageId ?? null} />;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function parseRouteSelection(tab: NewsDeskTab, selectionPath: string[] | null | undefined): { assignment?: string | null; category?: string | null; message?: string | null; panel?: string | null; reference?: string | null; forumThread?: string | null } {
|
|
79
|
+
const segments = (selectionPath ?? []).map((segment) => decodeURIComponent(segment)).filter(Boolean);
|
|
80
|
+
if (!segments.length) return {};
|
|
81
|
+
if (segments[0] === "forum" && segments[1]) return { forumThread: segments[1] };
|
|
82
|
+
if (tab === "administration") return { panel: segments[0] ?? null };
|
|
83
|
+
if (tab === "topics") return { category: segments[1] ?? segments[0] ?? null };
|
|
84
|
+
if (tab === "references") return { reference: segments[0] ?? null };
|
|
85
|
+
if (tab === "concepts") return { category: segments[0] ?? null };
|
|
86
|
+
if (tab === "messages") {
|
|
87
|
+
if (segments[0] === "forum" && segments[1]) return { forumThread: segments[1] };
|
|
88
|
+
return { message: segments[0] ?? null };
|
|
89
|
+
}
|
|
90
|
+
if (tab === "insights") return { forumThread: segments[0] ?? null };
|
|
91
|
+
if (tab === "assignments") return { assignment: segments[0] ?? null };
|
|
92
|
+
if (tab === "overview" && segments[0] === "forum" && segments[1]) return { forumThread: segments[1] };
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getSearchParam(searchParams: unknown, key: string): string | string[] | null | undefined {
|
|
97
|
+
if (searchParams instanceof URLSearchParams) return searchParams.get(key);
|
|
98
|
+
if (!searchParams || typeof searchParams !== "object") return undefined;
|
|
99
|
+
return (searchParams as Record<string, string | string[] | undefined>)[key];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getFirstSearchParam(searchParams: unknown, key: string): string | null {
|
|
103
|
+
const value = getSearchParam(searchParams, key);
|
|
104
|
+
const first = Array.isArray(value) ? value[0] : value;
|
|
105
|
+
return typeof first === "string" && first.trim() ? first.trim() : null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parseNewsDeskTab(sectionValue: string | string[] | null | undefined, legacyTabValue: string | string[] | null | undefined): NewsDeskTab {
|
|
109
|
+
const section = Array.isArray(sectionValue) ? sectionValue[0] : sectionValue;
|
|
110
|
+
const legacyTab = Array.isArray(legacyTabValue) ? legacyTabValue[0] : legacyTabValue;
|
|
111
|
+
const rawValue = section ?? (legacyTab === "categories" ? "topics" : legacyTab);
|
|
112
|
+
const value = rawValue === "users" || rawValue === "doctrine"
|
|
113
|
+
? "administration"
|
|
114
|
+
: rawValue === "desks"
|
|
115
|
+
? "topics"
|
|
116
|
+
: rawValue;
|
|
117
|
+
if (value === "administration" || value === "topics" || value === "concepts" || value === "references" || value === "insights" || value === "messages" || value === "assignments" || value === "search") return value;
|
|
118
|
+
return "overview";
|
|
119
|
+
}
|