Files
wehub-resource-sync e30e75b5d4
Code Quality / Oxlint + Oxfmt (push) Waiting to run
Code Quality / Template Sync (push) Waiting to run
Code Quality / Build Changed Packages (push) Waiting to run
Code Quality / Test Changed Packages (push) Waiting to run
Deploy Expo Example / Deploy Production (push) Waiting to run
Deploy Ink Example / Deploy Production (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-stream, 3.12) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Waiting to run
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Waiting to run
Deploy Shadcn Registry / Deploy Production (push) Waiting to run
Template Metrics / LOC + Bundle Size (push) Waiting to run
Changesets / Create Version PR (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:40:13 +08:00

84 lines
2.2 KiB
TypeScript

"use client";
import { useMemo } from "react";
import {
AssistantRuntimeProvider,
WebSpeechSynthesisAdapter,
WebSpeechDictationAdapter,
CloudFileAttachmentAdapter,
AssistantCloud,
useAui,
Tools,
Suggestions,
unstable_Interactables,
type FeedbackAdapter,
} from "@assistant-ui/react";
import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
import { DevToolsModal } from "@assistant-ui/react-devtools";
import { lastAssistantMessageIsCompleteWithToolCalls } from "ai";
import docsToolkit from "@/lib/docs-toolkit";
// Stateless adapter - safe to share across instances
const feedbackAdapter: FeedbackAdapter = {
submit: () => {
// Feedback is tracked via analytics in AssistantActionBar
// The runtime automatically updates message.metadata.submittedFeedback
},
};
export function DocsRuntimeProvider({
children,
}: {
children: React.ReactNode;
}) {
const assistantCloud = useMemo(
() =>
new AssistantCloud({
baseUrl: process.env.NEXT_PUBLIC_ASSISTANT_BASE_URL!,
anonymous: true,
}),
[],
);
// Speech/dictation adapters keep internal state; create per component instance.
const adapters = useMemo(
() => ({
speech: new WebSpeechSynthesisAdapter(),
dictation: new WebSpeechDictationAdapter(),
feedback: feedbackAdapter,
attachments: new CloudFileAttachmentAdapter(assistantCloud),
}),
[assistantCloud],
);
const runtime = useChatRuntime({
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
adapters,
cloud: assistantCloud,
});
const aui = useAui({
tools: Tools({ toolkit: docsToolkit }),
unstable_interactables: unstable_Interactables(),
suggestions: Suggestions([
{
title: "What's the weather",
label: "in San Francisco?",
prompt: "What's the weather in San Francisco?",
},
{
title: "Explain React hooks",
label: "like useState and useEffect",
prompt: "Explain React hooks like useState and useEffect",
},
]),
});
return (
<AssistantRuntimeProvider aui={aui} runtime={runtime}>
{children}
<DevToolsModal />
</AssistantRuntimeProvider>
);
}