Getting Started

Set it up in your app in a few minutes

Quick Start

Install

npm install @intentctrl/react

Make sure react, react-dom, and zod are already in your project.

Add the provider

Wrap your application (or the part that needs AI) in IntentCtrlProvider. You need the URL of an AI backend and an API key. Use the cloud platform directly, or self-host the backend for free.

app/layout.tsx
import { IntentCtrlProvider } from "@intentctrl/react";

export default function RootLayout({ children }) {
  return (
    <IntentCtrlProvider apiUrl="http://app.intentctrl.com/api/chat" apiKey={process.env.NEXT_PUBLIC_API_KEY!}>
      {children}
    </IntentCtrlProvider>
  );
}

Start a chat

Inside any child component, use useIntentCtrl() to send messages and display responses.

components/chat-panel.tsx
import { useIntentCtrl } from "@intentctrl/react";

export function ChatPanel() {
  const { messages, sendMessage, status } = useIntentCtrl();

  return (
    <div>
      {messages.map((msg) => (
        <div key={msg.id}>
          <strong>{msg.role}:</strong> {msg.content}
        </div>
      ))}
      <input
        placeholder="Ask something..."
        onKeyDown={(e) => {
          if (e.key === "Enter" && e.currentTarget.value) {
            sendMessage(e.currentTarget.value);
            e.currentTarget.value = "";
          }
        }}
      />
      {status === "streaming" && <span>Thinking...</span>}
    </div>
  );
}

That's it. The AI sees the current page, knows about any tools you've registered, and can respond with text or take actions.

What's next

Last updated on

On this page