mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-07-27 04:31:57 +00:00
Finish the fumadocs→Hanzo Docs rebrand: rename the remaining fuma-named
workspace packages and every reference so the framework is uniformly
@hanzo/docs-*. One brand, no Fuma in package names or product surface.
Package renames (name field + all refs: deps, imports, CSS @import,
configs, .changeset, next/vite build config):
fumadocs-core → @hanzo/docs-core
fumadocs-mdx → @hanzo/docs-mdx
fumadocs-ui → @hanzo/docs-ui (packages/radix-ui)
fumadocs-openapi → @hanzo/docs-openapi
fumadocs-preview → @hanzo/docs-preview
@fumadocs/base-ui → @hanzo/docs-base-ui
@fumadocs/basehub → @hanzo/docs-basehub
@fumadocs/language → @hanzo/docs-language
@fumadocs/local-md → @hanzo/docs-local-md
@fumadocs/sanity → @hanzo/docs-sanity
@fumadocs/shadcn → @hanzo/docs-shadcn
@fumadocs/vite → @hanzo/docs-vite
@fumari/stf → @hanzo/docs-stf
create-fumadocs-app → @hanzo/create-docs
create-fumadocs-versions → @hanzo/docs-create-versions
Stale @fumadocs/{cli,story,tailwind,mdx-remote,...} references collapsed to
their existing @hanzo/docs-* canonical packages (no dup created).
De-branded product strings: Fumadocs/Fuma prose → Hanzo Docs/Hanzo; site
branding, CLI output, doc copy, AI-assistant name, metadata. URLs
fumadocs.dev → docs.hanzo.ai, repo fuma-nama/fumadocs → hanzoai/docs.
Filesystem renames: packages/python/fumapy → hanzodocs_py, preview config,
what-is-fumadocs.mdx → what-is-hanzo-docs.mdx, api/fumadocs-ui route.
KEPT (real external npm deps / attribution — NOT renamed):
fuma-cli, fuma-content, @fumari/json-schema-ts (published upstream pkgs),
typesense-/trieve-fumadocs-adapter (3rd-party search adapters),
LICENSE "Copyright (c) 2023 Fuma" (OSS attribution, all 7 LICENSE files
untouched), CHANGELOG.md history (accurate release records, left as-is).
Build: node 24, pnpm install clean; all 4 target apps next build GREEN
(spec, gui-docs, zen-docs, base-docs) + full package closure (18/18 turbo).
Gate: zero @hanzo-package fumadocs-/@fumadocs/ references remain.
474 lines
13 KiB
TypeScript
474 lines
13 KiB
TypeScript
'use client';
|
|
import {
|
|
type ComponentProps,
|
|
createContext,
|
|
type ReactNode,
|
|
type SyntheticEvent,
|
|
use,
|
|
useEffect,
|
|
useEffectEvent,
|
|
useMemo,
|
|
useRef,
|
|
useState,
|
|
} from 'react';
|
|
import { Loader2, MessageCircleIcon, RefreshCw, Send, X } from 'lucide-react';
|
|
import { cn } from '@/lib/cn';
|
|
import { buttonVariants } from '@hanzo/docs-base-ui/components/ui/button';
|
|
import Link from '@hanzo/docs-core/link';
|
|
import { useChat, type UseChatHelpers } from '@ai-sdk/react';
|
|
import type { ProvideLinksToolSchema } from '@/lib/chat/inkeep-qa-schema';
|
|
import type { z } from 'zod';
|
|
import { DefaultChatTransport } from 'ai';
|
|
import { chatEndpoint, publishableKey } from '@/lib/hanzo/client';
|
|
import { Markdown } from './markdown';
|
|
import { Presence } from '@radix-ui/react-presence';
|
|
import type { InkeepUIMessage } from '@/lib/inkeep/server';
|
|
|
|
const Context = createContext<{
|
|
open: boolean;
|
|
setOpen: (open: boolean) => void;
|
|
chat: UseChatHelpers<InkeepUIMessage>;
|
|
} | null>(null);
|
|
|
|
export function AISearchPanelHeader({ className, ...props }: ComponentProps<'div'>) {
|
|
const { setOpen } = useAISearchContext();
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
'sticky top-0 flex items-start gap-2 border rounded-xl bg-fd-secondary text-fd-secondary-foreground shadow-sm',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
<div className="px-3 py-2 flex-1">
|
|
<p className="text-sm font-medium mb-2">AI Chat</p>
|
|
<p className="text-xs text-fd-muted-foreground">
|
|
Powered by{' '}
|
|
<a href="https://hanzo.ai" target="_blank" rel="noreferrer noopener">
|
|
Hanzo AI
|
|
</a>
|
|
</p>
|
|
</div>
|
|
|
|
<button
|
|
aria-label="Close"
|
|
tabIndex={-1}
|
|
className={cn(
|
|
buttonVariants({
|
|
size: 'icon-sm',
|
|
color: 'ghost',
|
|
className: 'text-fd-muted-foreground rounded-full',
|
|
}),
|
|
)}
|
|
onClick={() => setOpen(false)}
|
|
>
|
|
<X />
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function AISearchInputActions() {
|
|
const { messages, status, setMessages, regenerate } = useChatContext();
|
|
const isLoading = status === 'streaming';
|
|
|
|
if (messages.length === 0) return null;
|
|
|
|
return (
|
|
<>
|
|
{!isLoading && messages.at(-1)?.role === 'assistant' && (
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
buttonVariants({
|
|
color: 'secondary',
|
|
size: 'sm',
|
|
className: 'rounded-full gap-1.5',
|
|
}),
|
|
)}
|
|
onClick={() => regenerate()}
|
|
>
|
|
<RefreshCw className="size-4" />
|
|
Retry
|
|
</button>
|
|
)}
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
buttonVariants({
|
|
color: 'secondary',
|
|
size: 'sm',
|
|
className: 'rounded-full',
|
|
}),
|
|
)}
|
|
onClick={() => setMessages([])}
|
|
>
|
|
Clear Chat
|
|
</button>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const StorageKeyInput = '__ai_search_input';
|
|
export function AISearchInput(props: ComponentProps<'form'>) {
|
|
const { status, sendMessage, stop } = useChatContext();
|
|
const [input, setInput] = useState(() => localStorage.getItem(StorageKeyInput) ?? '');
|
|
const isLoading = status === 'streaming' || status === 'submitted';
|
|
const onStart = (e?: SyntheticEvent) => {
|
|
e?.preventDefault();
|
|
const message = input.trim();
|
|
if (message.length === 0) return;
|
|
|
|
void sendMessage({
|
|
role: 'user',
|
|
parts: [
|
|
{
|
|
type: 'data-client',
|
|
data: {
|
|
location: location.href,
|
|
},
|
|
},
|
|
{
|
|
type: 'text',
|
|
text: message,
|
|
},
|
|
],
|
|
});
|
|
setInput('');
|
|
localStorage.removeItem(StorageKeyInput);
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (isLoading) document.getElementById('nd-ai-input')?.focus();
|
|
}, [isLoading]);
|
|
|
|
return (
|
|
<form {...props} className={cn('flex items-start pe-2', props.className)} onSubmit={onStart}>
|
|
<Input
|
|
value={input}
|
|
placeholder={isLoading ? 'AI is answering...' : 'Ask a question'}
|
|
autoFocus
|
|
className="p-3"
|
|
disabled={status === 'streaming' || status === 'submitted'}
|
|
onChange={(e) => {
|
|
setInput(e.target.value);
|
|
localStorage.setItem(StorageKeyInput, e.target.value);
|
|
}}
|
|
onKeyDown={(event) => {
|
|
if (!event.shiftKey && event.key === 'Enter') {
|
|
onStart(event);
|
|
}
|
|
}}
|
|
/>
|
|
{isLoading ? (
|
|
<button
|
|
key="bn"
|
|
type="button"
|
|
className={cn(
|
|
buttonVariants({
|
|
color: 'secondary',
|
|
className: 'transition-all rounded-full mt-2 gap-2',
|
|
}),
|
|
)}
|
|
onClick={stop}
|
|
>
|
|
<Loader2 className="size-4 animate-spin text-fd-muted-foreground" />
|
|
Abort Answer
|
|
</button>
|
|
) : (
|
|
<button
|
|
key="bn"
|
|
type="submit"
|
|
className={cn(
|
|
buttonVariants({
|
|
color: 'primary',
|
|
className: 'transition-all rounded-full mt-2',
|
|
}),
|
|
)}
|
|
disabled={input.length === 0}
|
|
>
|
|
<Send className="size-4" />
|
|
</button>
|
|
)}
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function List(props: Omit<ComponentProps<'div'>, 'dir'>) {
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
useEffect(() => {
|
|
if (!containerRef.current) return;
|
|
function callback() {
|
|
const container = containerRef.current;
|
|
if (!container) return;
|
|
|
|
container.scrollTo({
|
|
top: container.scrollHeight,
|
|
behavior: 'instant',
|
|
});
|
|
}
|
|
|
|
const observer = new ResizeObserver(callback);
|
|
callback();
|
|
|
|
const element = containerRef.current?.firstElementChild;
|
|
|
|
if (element) {
|
|
observer.observe(element);
|
|
}
|
|
|
|
return () => {
|
|
observer.disconnect();
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<div
|
|
ref={containerRef}
|
|
{...props}
|
|
className={cn('fd-scroll-container overflow-y-auto min-w-0 flex flex-col', props.className)}
|
|
>
|
|
{props.children}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Input(props: ComponentProps<'textarea'>) {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
const shared = cn('col-start-1 row-start-1', props.className);
|
|
|
|
return (
|
|
<div className="grid flex-1">
|
|
<textarea
|
|
id="nd-ai-input"
|
|
{...props}
|
|
className={cn(
|
|
'resize-none bg-transparent placeholder:text-fd-muted-foreground focus-visible:outline-none',
|
|
shared,
|
|
)}
|
|
/>
|
|
<div ref={ref} className={cn(shared, 'break-all invisible')}>
|
|
{`${props.value?.toString() ?? ''}\n`}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const roleName: Record<string, string> = {
|
|
user: 'you',
|
|
assistant: 'hanzo-bot',
|
|
};
|
|
|
|
function Message({ message, ...props }: { message: InkeepUIMessage } & ComponentProps<'div'>) {
|
|
let markdown = '';
|
|
let links: z.infer<typeof ProvideLinksToolSchema>['links'] = [];
|
|
|
|
for (const part of message.parts ?? []) {
|
|
if (part.type === 'text') {
|
|
markdown += part.text;
|
|
continue;
|
|
}
|
|
|
|
if (part.type === 'tool-provideLinks' && part.input) {
|
|
links = (part.input as z.infer<typeof ProvideLinksToolSchema>).links;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div onClick={(e) => e.stopPropagation()} {...props}>
|
|
<p
|
|
className={cn(
|
|
'mb-1 text-sm font-medium text-fd-muted-foreground',
|
|
message.role === 'assistant' && 'text-fd-primary',
|
|
)}
|
|
>
|
|
{roleName[message.role] ?? 'unknown'}
|
|
</p>
|
|
<div className="prose text-sm">
|
|
<Markdown text={markdown} />
|
|
</div>
|
|
{links && links.length > 0 && (
|
|
<div className="mt-2 flex flex-row flex-wrap items-center gap-1">
|
|
{links.map((item, i) => (
|
|
<Link
|
|
key={i}
|
|
href={item.url}
|
|
className="block text-xs rounded-lg border p-3 hover:bg-fd-accent hover:text-fd-accent-foreground"
|
|
>
|
|
<p className="font-medium">{item.title}</p>
|
|
<p className="text-fd-muted-foreground">Reference {item.label}</p>
|
|
</Link>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const systemPrompt =
|
|
'You are the documentation assistant for Hanzo Bot, a personal AI assistant by Hanzo AI (a Techstars-backed applied AI lab). ' +
|
|
'Hanzo Bot runs on your own devices and integrates with messaging platforms you already use. ' +
|
|
'It can run skills, automate tasks, browse the web, write code, and manage files — all locally. ' +
|
|
'Answer confidently and directly. Be concise. Use markdown. Include doc links when relevant.';
|
|
|
|
export function AISearch({ children }: { children: ReactNode }) {
|
|
const [open, setOpen] = useState(false);
|
|
const chat = useChat<InkeepUIMessage>({
|
|
id: 'search',
|
|
initialMessages: [{ id: 'system', role: 'system' as const, content: systemPrompt, parts: [] }],
|
|
transport: new DefaultChatTransport({
|
|
api: chatEndpoint,
|
|
headers: { Authorization: `Bearer ${publishableKey}` },
|
|
}),
|
|
});
|
|
|
|
return (
|
|
<Context value={useMemo(() => ({ chat, open, setOpen }), [chat, open])}>{children}</Context>
|
|
);
|
|
}
|
|
|
|
export function AISearchTrigger({
|
|
position = 'default',
|
|
className,
|
|
...props
|
|
}: ComponentProps<'button'> & { position?: 'default' | 'float' }) {
|
|
const { open, setOpen } = useAISearchContext();
|
|
|
|
return (
|
|
<button
|
|
data-state={open ? 'open' : 'closed'}
|
|
className={cn(
|
|
position === 'float' && [
|
|
'fixed bottom-4 gap-3 w-24 inset-e-[calc(--spacing(4)+var(--removed-body-scroll-bar-size,0px))] shadow-lg z-20 transition-[translate,opacity]',
|
|
open && 'translate-y-10 opacity-0',
|
|
],
|
|
className,
|
|
)}
|
|
onClick={() => setOpen(!open)}
|
|
{...props}
|
|
>
|
|
{props.children}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
export function AISearchPanel() {
|
|
const { open, setOpen } = useAISearchContext();
|
|
useHotKey();
|
|
|
|
return (
|
|
<>
|
|
<style>
|
|
{`
|
|
@keyframes ask-ai-open {
|
|
from {
|
|
translate: 100% 0;
|
|
}
|
|
to {
|
|
translate: 0 0;
|
|
}
|
|
}
|
|
@keyframes ask-ai-close {
|
|
from {
|
|
width: var(--ai-chat-width);
|
|
}
|
|
to {
|
|
width: 0px;
|
|
}
|
|
}`}
|
|
</style>
|
|
<Presence present={open}>
|
|
<div
|
|
data-state={open ? 'open' : 'closed'}
|
|
className="fixed inset-0 z-30 backdrop-blur-xs bg-fd-overlay data-[state=open]:animate-fd-fade-in data-[state=closed]:animate-fd-fade-out lg:hidden"
|
|
onClick={() => setOpen(false)}
|
|
/>
|
|
</Presence>
|
|
<Presence present={open}>
|
|
<div
|
|
className={cn(
|
|
'overflow-hidden z-30 bg-fd-card text-fd-card-foreground [--ai-chat-width:400px] 2xl:[--ai-chat-width:460px]',
|
|
'max-lg:fixed max-lg:inset-x-2 max-lg:inset-y-4 max-lg:border max-lg:rounded-2xl max-lg:shadow-xl',
|
|
'lg:sticky lg:top-0 lg:h-dvh lg:border-s lg:ms-auto lg:in-[#nd-docs-layout]:[grid-area:toc] lg:in-[#nd-notebook-layout]:row-span-full lg:in-[#nd-notebook-layout]:col-start-5',
|
|
open
|
|
? 'animate-fd-dialog-in lg:animate-[ask-ai-open_200ms]'
|
|
: 'animate-fd-dialog-out lg:animate-[ask-ai-close_200ms]',
|
|
)}
|
|
>
|
|
<div className="flex flex-col size-full p-2 lg:p-3 lg:w-(--ai-chat-width)">
|
|
<AISearchPanelHeader />
|
|
<AISearchPanelList className="flex-1" />
|
|
<div className="rounded-xl border bg-fd-secondary text-fd-secondary-foreground shadow-sm has-focus-visible:shadow-md">
|
|
<AISearchInput />
|
|
<div className="flex items-center gap-1.5 p-1 empty:hidden">
|
|
<AISearchInputActions />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Presence>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export function AISearchPanelList({ className, style, ...props }: ComponentProps<'div'>) {
|
|
const chat = useChatContext();
|
|
const messages = chat.messages.filter((msg) => msg.role !== 'system');
|
|
|
|
return (
|
|
<List
|
|
className={cn('py-4 overscroll-contain', className)}
|
|
style={{
|
|
maskImage:
|
|
'linear-gradient(to bottom, transparent, white 1rem, white calc(100% - 1rem), transparent 100%)',
|
|
...style,
|
|
}}
|
|
{...props}
|
|
>
|
|
{messages.length === 0 ? (
|
|
<div className="text-sm text-fd-muted-foreground/80 size-full flex flex-col items-center justify-center text-center gap-2">
|
|
<MessageCircleIcon fill="currentColor" stroke="none" />
|
|
<p onClick={(e) => e.stopPropagation()}>Start a new chat below.</p>
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col px-3 gap-4">
|
|
{messages.map((item) => (
|
|
<Message key={item.id} message={item} />
|
|
))}
|
|
</div>
|
|
)}
|
|
</List>
|
|
);
|
|
}
|
|
|
|
export function useHotKey() {
|
|
const { open, setOpen } = useAISearchContext();
|
|
|
|
const onKeyPress = useEffectEvent((e: KeyboardEvent) => {
|
|
if (e.key === 'Escape' && open) {
|
|
setOpen(false);
|
|
e.preventDefault();
|
|
}
|
|
|
|
if (e.key === '/' && (e.metaKey || e.ctrlKey) && !open) {
|
|
setOpen(true);
|
|
e.preventDefault();
|
|
}
|
|
});
|
|
|
|
useEffect(() => {
|
|
window.addEventListener('keydown', onKeyPress);
|
|
return () => window.removeEventListener('keydown', onKeyPress);
|
|
}, []);
|
|
}
|
|
|
|
export function useAISearchContext() {
|
|
return use(Context)!;
|
|
}
|
|
|
|
function useChatContext() {
|
|
return use(Context)!.chat;
|
|
}
|