npm.io
0.1.0 • Published yesterday

@eyoben/ai-react

Licence
MIT
Version
0.1.0
Deps
0
Size
12 kB
Vulns
0
Weekly
0

@eyoben/ai-react

Provider-neutral React primitives for secure AI experiences.

Install

npm install @eyoben/ai-react

This package supplies the client-side chat state and accessible primitives. Your application must provide a server-backed transport; API keys and provider SDK calls stay on the server.

Design

The package does not contain provider API keys or call an AI provider directly from the browser. Applications provide a server-backed ChatTransport through AIProvider.

import { AIProvider, MessageList, PromptInput, useChat } from "@eyoben/ai-react";

function Chat() {
  const chat = useChat();

  return (
    <>
      <MessageList messages={chat.messages} />
      <PromptInput onSubmit={chat.sendMessage} disabled={chat.status === "streaming"} />
    </>
  );
}

<AIProvider transport={transport}>
  <Chat />
</AIProvider>;

The server-backed transport receives the conversation and an AbortSignal, then returns an async stream of text-delta, message, error, or finish parts.