REFERENCE
Developer Reference
Authentication, APIs, SDKs, Flow Agent processors and parameter resolution, in full.
React SDK (@asgard-js/react)
@asgard-js/react React SDK reference
@asgard-js/react builds on @asgard-js/core to provide a ready-made React chat UI and hooks, so a React application can integrate Asgard chat quickly.
Choosing an integration pattern, advanced configuration and common problems are covered in the frontend SDK guide, and every capability has a runnable example at SDK Demo.
Installation
@asgard-js/reacttakes@asgard-js/coreas a peer dependency, so install both:npm install @asgard-js/react @asgard-js/coreImporting the stylesheet
import "@asgard-js/react/style";This line is needed once. Without it the chatbot renders unstyled.
The
<Chatbot>componentimport { Chatbot } from "@asgard-js/react";
import "@asgard-js/react/style";
export default function App() {
return (
<div style={{ height: "100vh" }}>
<Chatbot
title="My AI assistant"
customChannelId="user-123"
config={{
botProviderEndpoint:
"https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}",
}}
/>
</div>
);
}Required props
Prop Type Description config.botProviderEndpointstringThe Bot Provider's endpoint URL customChannelIdstringThe conversation channel's id, usually a user id or session id The full prop list is in the Props Reference.
SSR frameworks (Next.js)
@asgard-js/reactdepends on browser APIs (window,SpeechRecognition,ResizeObserver), so it cannot run on the server.Next.js App Router
"use client";
import dynamic from "next/dynamic";
import "@asgard-js/react/style";
const Chatbot = dynamic(
() => import("@asgard-js/react").then((m) => m.Chatbot),
{ ssr: false },
);
export default function ChatPage() {
return (
<div style={{ height: "100vh" }}>
<Chatbot
title="My AI assistant"
customChannelId="user-123"
config={{
botProviderEndpoint:
"https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}",
}}
/>
</div>
);
}Next.js Pages Router
import dynamic from "next/dynamic";
const Chatbot = dynamic(
() => import("@asgard-js/react").then((m) => m.Chatbot),
{ ssr: false },
);Docusaurus / Gatsby
import BrowserOnly from "@docusaurus/BrowserOnly";
export default function MyPage() {
return (
<BrowserOnly>
{() => {
const { Chatbot } = require("@asgard-js/react");
require("@asgard-js/react/style");
return (
<Chatbot
title="..."
customChannelId="..."
config={{ botProviderEndpoint: "..." }}
/>
);
}}
</BrowserOnly>
);
}Custom UI (useAsgardContext)
Inside custom render props such as
renderHeaderandrenderFooter,useAsgardContextgives you the conversation state:import { useAsgardContext } from "@asgard-js/react";
function CustomHeader() {
const { resetChannel, isConnecting } = useAsgardContext();
return (
<div>
<span>My Bot</span>
<button onClick={resetChannel} disabled={isConnecting}>
Reset conversation
</button>
</div>
);
}Contexts and providers
@asgard-js/reactexports four contexts, each with a provider and a hook.<Chatbot>wires them up internally; you only reach for them when assembling your own UI.Context Provider Hook What it provides AsgardServiceContextAsgardServiceContextProvideruseAsgardContextConversation state and actions ( resetChannel,isConnecting)AsgardThemeContextAsgardThemeContextProvideruseAsgardThemeContextTheme settings, defaulting to defaultAsgardThemeContextValueAsgardTemplateContextAsgardTemplateContextProvideruseAsgardTemplateContextHow message templates render AsgardAppInitializationContextAsgardAppInitializationContextProvideruseAsgardAppInitializationContextApplication initialization state FileDropContextProvideranduseFileDropContexthandle drag-and-drop files.ThemeScopeapplies a theme to one subtree, andDEFAULT_CONTENT_MAX_WIDTHis the content area's default maximum width.Headless integration
To build your own interface instead of using
<Chatbot>, start from these two hooks:import { useAsgardServiceClient, useChannel } from '@asgard-js/react';
const client = useAsgardServiceClient({
config: { botProviderEndpoint, apiKey },
keepConnectionOnUnmount: false,
});
const channel = useChannel({ client, customChannelId, initMessages });useAsgardServiceClientcreates and manages theAsgardServiceClientlifecycle, returningAsgardServiceClient | null.keepConnectionOnUnmountdecides whether the connection survives the component unmounting.useChanneltakesUseChannelProps(client,customChannelId,initMessages,autoResetChannel,onSseMessage,onAuthErrorand more) and returnsUseChannelReturn.File explorer and sandbox
Components and hooks for showing a sandbox filesystem:
Export Purpose FileExplorer/FileExplorerPanelThe explorer itself and its panel container FileExplorerProvider/useFileExplorerThe explorer's context and the hook that reads it useFileExplorerControllerBuilds the explorer's controller, taking UseFileExplorerControllerOptionsFileViewViewer for a single file createSandboxFsProvidersWraps AsgardServiceClient'ssandboxFs*methods into the provider set the explorer expectsuseSandboxLaunch/useLaunchedSandboxesLaunch a sandbox, and read the list of launched ones sandboxAsSource/sandboxesAsSourcesTurn a sandbox into an explorer source SourceSetFileExplorerThe SourceSet explorer, paired with AsgardSourceSetClientfrom@asgard-js/coreEMPTY_SOURCE_VIEWis the empty state used when there is no source.Other components
ChatHeaderis the conversation title bar, andChatHeaderActionadds action buttons to it.TaskListandSubagentListrender tasks and subagents from@asgard-js/core's derived state.General React utilities
These hooks carry no Asgard-specific meaning. They are general-purpose helpers the package uses internally and exports along the way: you can use them, but they are not part of the integration surface.
useDebounce,useDeepCompareMemo,useResizeObserver,useVisualViewport,useIsAtBottom,useSyncedSpin,usePromptSuggestion.tis the i18n translation function andLocaleis the locale type.Sandbox browser panel
SandboxBrowserPanelrenders a Sandbox's browser inside your layout and handles the connection, input forwarding and cursor itself.useSandboxBrowserController({ open?, activeSandboxName? })owns its open state and which Sandbox it points at. It returnsopen,activeSandboxNameandrequestedBrowser, plusopenBrowser(),closeBrowser(),toggle(),selectSandbox(name)andrequestBrowser(name, { reveal }).requestBrowseropens the panel as well by default; passreveal: falseto switch target without revealing it.The returned object is memoised so its identity moves only with the state — the panel's connection effect depends on it, and a fresh object each render would reconnect every time.
toRemoteCoords(video, clientX, clientY)converts a pointer position on the panel into the remote screen's coordinates, andfromRemoteCoords(video, x, y)goes the other way. Both account for the video's letterboxing and returnnullrather than inventing a coordinate they cannot compute. You only call them directly when building your own pointer overlay or annotations.Further reading
- Frontend SDK guide — pattern selection, props and common problems
- JavaScript SDK reference — the underlying
@asgard-js/coreAPI