@anthusai/papyrus 0.0.0 → 1.0.0-next.10
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 +2069 -0
- package/amplify/data/resource.ts +2185 -0
- package/amplify/data/schema.js +1882 -0
- package/amplify/data/schema.ts +1990 -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/content-actions/handler.py +149 -0
- package/amplify/functions/content-actions/requirements.txt +4 -0
- package/amplify/functions/content-actions/resource.js +40 -0
- package/amplify/functions/content-actions/resource.ts +54 -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 +130 -0
- package/amplify/functions/shared/python-bundle.ts +162 -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/rebuild-trigger-settings.js +22 -0
- package/amplify/rebuild-trigger-settings.ts +42 -0
- package/amplify/site-backend-config.js +1 -0
- package/amplify/site-backend-config.ts +36 -0
- package/amplify/site-backend.js +615 -0
- package/amplify/site-backend.ts +739 -0
- package/amplify/storage/resource.js +21 -0
- package/amplify/storage/resource.ts +22 -0
- package/app/%5F_preview/[[...path]]/route.ts +8 -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 +10345 -0
- package/app/layout.tsx +142 -0
- package/app/newsroom/[section]/[...selection]/page.tsx +50 -0
- package/app/newsroom/[section]/page.tsx +47 -0
- package/app/newsroom/articles/[id]/page.tsx +15 -0
- package/app/newsroom/articles/page.tsx +13 -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/papyrus-theme.css +11 -0
- package/app/robots.ts +11 -0
- package/app/settings/page.tsx +14 -0
- package/app/tailwind.css +65 -0
- package/bin/papyrus-app.mjs +20 -0
- package/bin/papyrus-infra.mjs +95 -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 +156 -0
- package/components/blog-page-background.tsx +20 -0
- package/components/dev-sandbox-editor-sign-in.tsx +60 -0
- package/components/markus-ir-preview.tsx +300 -0
- package/components/news-desk-client-provider.tsx +211 -0
- package/components/news-desk-page.tsx +116 -0
- package/components/news-desk-taxonomy-client.ts +3684 -0
- package/components/newspaper.tsx +1929 -0
- package/components/newsroom-access-gate.tsx +66 -0
- package/components/newsroom-article-editor.tsx +741 -0
- package/components/newsroom-articles-view.tsx +129 -0
- package/components/newsroom-assignments-view.tsx +664 -0
- package/components/newsroom-ops-overview.tsx +226 -0
- package/components/newsroom-ops-shell.tsx +321 -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/staging-banner.tsx +11 -0
- package/components/topic-steering-workspace.tsx +18005 -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 +234 -0
- package/infra/amplify-app-shell.ts +284 -0
- package/infra/build-specs.js +85 -0
- package/infra/build-specs.ts +131 -0
- package/infra/github-oidc-provider.js +24 -0
- package/infra/github-oidc-provider.ts +30 -0
- package/infra/index.js +15 -0
- package/infra/site-config.js +186 -0
- package/infra/site-config.ts +235 -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 +90 -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-actions-client.ts +98 -0
- package/lib/content-actions-demo.ts +190 -0
- package/lib/content-load-timing.ts +23 -0
- package/lib/content-repository.ts +43 -0
- package/lib/content-source-context.ts +26 -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/empty-theme.css +1 -0
- package/lib/excerpts.ts +8 -0
- package/lib/graphql-content-repository.ts +1140 -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-articles.ts +325 -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-articles.ts +90 -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-media-backend.ts +142 -0
- package/lib/newsroom-media.ts +182 -0
- package/lib/newsroom-nav.ts +44 -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 +22 -0
- package/lib/site-brand.ts +194 -0
- package/lib/site-env.ts +52 -0
- package/lib/site-renderer.ts +17 -0
- package/lib/site-stack.ts +195 -0
- package/lib/staging-gate.ts +37 -0
- package/lib/staging-preview-object.ts +98 -0
- package/lib/themed-image.ts +30 -0
- package/lib/utils.ts +6 -0
- package/lib/video-mode.ts +42 -0
- package/lib/video-script.ts +63 -0
- package/middleware.ts +103 -0
- package/package.json +318 -1
- package/renderers/markus/index.ts +25 -0
- package/renderers/markus/stubs.tsx +33 -0
- package/renderers/pretext/article-page.tsx +169 -0
- package/renderers/pretext/index.ts +30 -0
- package/renderers/pretext/layouts.ts +16 -0
- package/renderers/pretext/presentation-shell.tsx +470 -0
- package/routes.manifest.json +208 -0
- package/scripts/fixtures/pilobol-sample.ast.json +234 -0
- 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
- 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 +60 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "../ui/button";
|
|
4
|
+
import {
|
|
5
|
+
ButtonGroup,
|
|
6
|
+
ButtonGroupText,
|
|
7
|
+
} from "../ui/button-group";
|
|
8
|
+
import {
|
|
9
|
+
Tooltip,
|
|
10
|
+
TooltipContent,
|
|
11
|
+
TooltipProvider,
|
|
12
|
+
TooltipTrigger,
|
|
13
|
+
} from "../ui/tooltip";
|
|
14
|
+
import { cn } from "../../lib/utils";
|
|
15
|
+
import { cjk } from "@streamdown/cjk";
|
|
16
|
+
import { code } from "@streamdown/code";
|
|
17
|
+
import { math } from "@streamdown/math";
|
|
18
|
+
import { mermaid } from "@streamdown/mermaid";
|
|
19
|
+
import type { UIMessage } from "ai";
|
|
20
|
+
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
21
|
+
import type { ComponentProps, HTMLAttributes, ReactElement } from "react";
|
|
22
|
+
import {
|
|
23
|
+
createContext,
|
|
24
|
+
memo,
|
|
25
|
+
useCallback,
|
|
26
|
+
useContext,
|
|
27
|
+
useEffect,
|
|
28
|
+
useMemo,
|
|
29
|
+
useState,
|
|
30
|
+
} from "react";
|
|
31
|
+
import { Streamdown } from "streamdown";
|
|
32
|
+
|
|
33
|
+
export type MessageProps = HTMLAttributes<HTMLDivElement> & {
|
|
34
|
+
from: UIMessage["role"];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Message = ({ className, from, ...props }: MessageProps) => (
|
|
38
|
+
<div
|
|
39
|
+
className={cn(
|
|
40
|
+
"group flex w-full max-w-[95%] flex-col gap-2",
|
|
41
|
+
from === "user" ? "is-user ml-auto justify-end" : "is-assistant",
|
|
42
|
+
className
|
|
43
|
+
)}
|
|
44
|
+
{...props}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export type MessageContentProps = HTMLAttributes<HTMLDivElement>;
|
|
49
|
+
|
|
50
|
+
export const MessageContent = ({
|
|
51
|
+
children,
|
|
52
|
+
className,
|
|
53
|
+
...props
|
|
54
|
+
}: MessageContentProps) => (
|
|
55
|
+
<div
|
|
56
|
+
className={cn(
|
|
57
|
+
"is-user:dark flex w-fit min-w-0 max-w-full flex-col gap-2 overflow-hidden text-sm",
|
|
58
|
+
"group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground",
|
|
59
|
+
"group-[.is-assistant]:text-foreground",
|
|
60
|
+
className
|
|
61
|
+
)}
|
|
62
|
+
{...props}
|
|
63
|
+
>
|
|
64
|
+
{children}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export type MessageActionsProps = ComponentProps<"div">;
|
|
69
|
+
|
|
70
|
+
export const MessageActions = ({
|
|
71
|
+
className,
|
|
72
|
+
children,
|
|
73
|
+
...props
|
|
74
|
+
}: MessageActionsProps) => (
|
|
75
|
+
<div className={cn("flex items-center gap-1", className)} {...props}>
|
|
76
|
+
{children}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
export type MessageActionProps = ComponentProps<typeof Button> & {
|
|
81
|
+
tooltip?: string;
|
|
82
|
+
label?: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const MessageAction = ({
|
|
86
|
+
tooltip,
|
|
87
|
+
children,
|
|
88
|
+
label,
|
|
89
|
+
variant = "ghost",
|
|
90
|
+
size = "icon-sm",
|
|
91
|
+
...props
|
|
92
|
+
}: MessageActionProps) => {
|
|
93
|
+
const button = (
|
|
94
|
+
<Button size={size} type="button" variant={variant} {...props}>
|
|
95
|
+
{children}
|
|
96
|
+
<span className="sr-only">{label || tooltip}</span>
|
|
97
|
+
</Button>
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (tooltip) {
|
|
101
|
+
return (
|
|
102
|
+
<TooltipProvider>
|
|
103
|
+
<Tooltip>
|
|
104
|
+
<TooltipTrigger>{button}</TooltipTrigger>
|
|
105
|
+
<TooltipContent>
|
|
106
|
+
<p>{tooltip}</p>
|
|
107
|
+
</TooltipContent>
|
|
108
|
+
</Tooltip>
|
|
109
|
+
</TooltipProvider>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return button;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
interface MessageBranchContextType {
|
|
117
|
+
currentBranch: number;
|
|
118
|
+
totalBranches: number;
|
|
119
|
+
goToPrevious: () => void;
|
|
120
|
+
goToNext: () => void;
|
|
121
|
+
branches: ReactElement[];
|
|
122
|
+
setBranches: (branches: ReactElement[]) => void;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const MessageBranchContext = createContext<MessageBranchContextType | null>(
|
|
126
|
+
null
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const useMessageBranch = () => {
|
|
130
|
+
const context = useContext(MessageBranchContext);
|
|
131
|
+
|
|
132
|
+
if (!context) {
|
|
133
|
+
throw new Error(
|
|
134
|
+
"MessageBranch components must be used within MessageBranch"
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return context;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type MessageBranchProps = HTMLAttributes<HTMLDivElement> & {
|
|
142
|
+
defaultBranch?: number;
|
|
143
|
+
onBranchChange?: (branchIndex: number) => void;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const MessageBranch = ({
|
|
147
|
+
defaultBranch = 0,
|
|
148
|
+
onBranchChange,
|
|
149
|
+
className,
|
|
150
|
+
...props
|
|
151
|
+
}: MessageBranchProps) => {
|
|
152
|
+
const [currentBranch, setCurrentBranch] = useState(defaultBranch);
|
|
153
|
+
const [branches, setBranches] = useState<ReactElement[]>([]);
|
|
154
|
+
|
|
155
|
+
const handleBranchChange = useCallback(
|
|
156
|
+
(newBranch: number) => {
|
|
157
|
+
setCurrentBranch(newBranch);
|
|
158
|
+
onBranchChange?.(newBranch);
|
|
159
|
+
},
|
|
160
|
+
[onBranchChange]
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const goToPrevious = useCallback(() => {
|
|
164
|
+
const newBranch =
|
|
165
|
+
currentBranch > 0 ? currentBranch - 1 : branches.length - 1;
|
|
166
|
+
handleBranchChange(newBranch);
|
|
167
|
+
}, [currentBranch, branches.length, handleBranchChange]);
|
|
168
|
+
|
|
169
|
+
const goToNext = useCallback(() => {
|
|
170
|
+
const newBranch =
|
|
171
|
+
currentBranch < branches.length - 1 ? currentBranch + 1 : 0;
|
|
172
|
+
handleBranchChange(newBranch);
|
|
173
|
+
}, [currentBranch, branches.length, handleBranchChange]);
|
|
174
|
+
|
|
175
|
+
const contextValue = useMemo<MessageBranchContextType>(
|
|
176
|
+
() => ({
|
|
177
|
+
branches,
|
|
178
|
+
currentBranch,
|
|
179
|
+
goToNext,
|
|
180
|
+
goToPrevious,
|
|
181
|
+
setBranches,
|
|
182
|
+
totalBranches: branches.length,
|
|
183
|
+
}),
|
|
184
|
+
[branches, currentBranch, goToNext, goToPrevious]
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<MessageBranchContext.Provider value={contextValue}>
|
|
189
|
+
<div
|
|
190
|
+
className={cn("grid w-full gap-2 [&>div]:pb-0", className)}
|
|
191
|
+
{...props}
|
|
192
|
+
/>
|
|
193
|
+
</MessageBranchContext.Provider>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export type MessageBranchContentProps = HTMLAttributes<HTMLDivElement>;
|
|
198
|
+
|
|
199
|
+
export const MessageBranchContent = ({
|
|
200
|
+
children,
|
|
201
|
+
...props
|
|
202
|
+
}: MessageBranchContentProps) => {
|
|
203
|
+
const { currentBranch, setBranches, branches } = useMessageBranch();
|
|
204
|
+
const childrenArray = useMemo(
|
|
205
|
+
() => (Array.isArray(children) ? children : [children]),
|
|
206
|
+
[children]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
// Use useEffect to update branches when they change
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
if (branches.length !== childrenArray.length) {
|
|
212
|
+
setBranches(childrenArray);
|
|
213
|
+
}
|
|
214
|
+
}, [childrenArray, branches, setBranches]);
|
|
215
|
+
|
|
216
|
+
return childrenArray.map((branch, index) => (
|
|
217
|
+
<div
|
|
218
|
+
className={cn(
|
|
219
|
+
"grid gap-2 overflow-hidden [&>div]:pb-0",
|
|
220
|
+
index === currentBranch ? "block" : "hidden"
|
|
221
|
+
)}
|
|
222
|
+
key={branch.key}
|
|
223
|
+
{...props}
|
|
224
|
+
>
|
|
225
|
+
{branch}
|
|
226
|
+
</div>
|
|
227
|
+
));
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export type MessageBranchSelectorProps = ComponentProps<typeof ButtonGroup>;
|
|
231
|
+
|
|
232
|
+
export const MessageBranchSelector = ({
|
|
233
|
+
className,
|
|
234
|
+
...props
|
|
235
|
+
}: MessageBranchSelectorProps) => {
|
|
236
|
+
const { totalBranches } = useMessageBranch();
|
|
237
|
+
|
|
238
|
+
// Don't render if there's only one branch
|
|
239
|
+
if (totalBranches <= 1) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return (
|
|
244
|
+
<ButtonGroup
|
|
245
|
+
className={cn(
|
|
246
|
+
"[&>*:not(:first-child)]:rounded-l-md [&>*:not(:last-child)]:rounded-r-md",
|
|
247
|
+
className
|
|
248
|
+
)}
|
|
249
|
+
orientation="horizontal"
|
|
250
|
+
{...props}
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
export type MessageBranchPreviousProps = ComponentProps<typeof Button>;
|
|
256
|
+
|
|
257
|
+
export const MessageBranchPrevious = ({
|
|
258
|
+
children,
|
|
259
|
+
...props
|
|
260
|
+
}: MessageBranchPreviousProps) => {
|
|
261
|
+
const { goToPrevious, totalBranches } = useMessageBranch();
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<Button
|
|
265
|
+
aria-label="Previous branch"
|
|
266
|
+
disabled={totalBranches <= 1}
|
|
267
|
+
onClick={goToPrevious}
|
|
268
|
+
size="icon-sm"
|
|
269
|
+
type="button"
|
|
270
|
+
variant="ghost"
|
|
271
|
+
{...props}
|
|
272
|
+
>
|
|
273
|
+
{children ?? <ChevronLeftIcon size={14} />}
|
|
274
|
+
</Button>
|
|
275
|
+
);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export type MessageBranchNextProps = ComponentProps<typeof Button>;
|
|
279
|
+
|
|
280
|
+
export const MessageBranchNext = ({
|
|
281
|
+
children,
|
|
282
|
+
...props
|
|
283
|
+
}: MessageBranchNextProps) => {
|
|
284
|
+
const { goToNext, totalBranches } = useMessageBranch();
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<Button
|
|
288
|
+
aria-label="Next branch"
|
|
289
|
+
disabled={totalBranches <= 1}
|
|
290
|
+
onClick={goToNext}
|
|
291
|
+
size="icon-sm"
|
|
292
|
+
type="button"
|
|
293
|
+
variant="ghost"
|
|
294
|
+
{...props}
|
|
295
|
+
>
|
|
296
|
+
{children ?? <ChevronRightIcon size={14} />}
|
|
297
|
+
</Button>
|
|
298
|
+
);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export type MessageBranchPageProps = HTMLAttributes<HTMLSpanElement>;
|
|
302
|
+
|
|
303
|
+
export const MessageBranchPage = ({
|
|
304
|
+
className,
|
|
305
|
+
...props
|
|
306
|
+
}: MessageBranchPageProps) => {
|
|
307
|
+
const { currentBranch, totalBranches } = useMessageBranch();
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<ButtonGroupText
|
|
311
|
+
className={cn(
|
|
312
|
+
"border-none bg-transparent text-muted-foreground shadow-none",
|
|
313
|
+
className
|
|
314
|
+
)}
|
|
315
|
+
{...props}
|
|
316
|
+
>
|
|
317
|
+
{currentBranch + 1} of {totalBranches}
|
|
318
|
+
</ButtonGroupText>
|
|
319
|
+
);
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export type MessageResponseProps = ComponentProps<typeof Streamdown>;
|
|
323
|
+
|
|
324
|
+
const streamdownPlugins = { cjk, code, math, mermaid };
|
|
325
|
+
|
|
326
|
+
export const MessageResponse = memo(
|
|
327
|
+
({ className, ...props }: MessageResponseProps) => (
|
|
328
|
+
<Streamdown
|
|
329
|
+
className={cn(
|
|
330
|
+
"size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",
|
|
331
|
+
className
|
|
332
|
+
)}
|
|
333
|
+
plugins={streamdownPlugins}
|
|
334
|
+
{...props}
|
|
335
|
+
/>
|
|
336
|
+
),
|
|
337
|
+
(prevProps, nextProps) =>
|
|
338
|
+
prevProps.children === nextProps.children &&
|
|
339
|
+
nextProps.isAnimating === prevProps.isAnimating
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
MessageResponse.displayName = "MessageResponse";
|
|
343
|
+
|
|
344
|
+
export type MessageToolbarProps = ComponentProps<"div">;
|
|
345
|
+
|
|
346
|
+
export const MessageToolbar = ({
|
|
347
|
+
className,
|
|
348
|
+
children,
|
|
349
|
+
...props
|
|
350
|
+
}: MessageToolbarProps) => (
|
|
351
|
+
<div
|
|
352
|
+
className={cn(
|
|
353
|
+
"mt-4 flex w-full items-center justify-between gap-4",
|
|
354
|
+
className
|
|
355
|
+
)}
|
|
356
|
+
{...props}
|
|
357
|
+
>
|
|
358
|
+
{children}
|
|
359
|
+
</div>
|
|
360
|
+
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils";
|
|
4
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
5
|
+
|
|
6
|
+
export type ModelSelectorOption = {
|
|
7
|
+
value: string;
|
|
8
|
+
label: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ModelSelectorProps = Omit<ComponentPropsWithoutRef<"select">, "onChange"> & {
|
|
12
|
+
options: readonly ModelSelectorOption[];
|
|
13
|
+
onValueChange?: (value: string) => void;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function ModelSelector({ className, options, onValueChange, ...props }: ModelSelectorProps) {
|
|
17
|
+
return (
|
|
18
|
+
<select
|
|
19
|
+
className={cn("papyrus-console-model-selector", className)}
|
|
20
|
+
onChange={(event) => onValueChange?.(event.currentTarget.value)}
|
|
21
|
+
{...props}
|
|
22
|
+
>
|
|
23
|
+
{options.map((option) => (
|
|
24
|
+
<option key={option.value} value={option.value}>
|
|
25
|
+
{option.label}
|
|
26
|
+
</option>
|
|
27
|
+
))}
|
|
28
|
+
</select>
|
|
29
|
+
);
|
|
30
|
+
}
|