
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
ai.matey.react.core
Advanced tools
Core React hooks for AI chat interactions.
Part of the ai.matey monorepo.
npm install ai.matey.react.core
import { useChat } from 'ai.matey.react.core';
function ChatComponent() {
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
api: '/api/chat',
});
return (
<div>
{messages.map((m) => (
<div key={m.id}>
<strong>{m.role}:</strong> {m.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button type="submit" disabled={isLoading}>Send</button>
</form>
</div>
);
}
Use any backend adapter directly without HTTP - great for Electron apps, browser extensions, or when you want to skip the server:
import { useChat } from 'ai.matey.react.core';
import { OpenAIBackend } from 'ai.matey.backend/openai';
// Create backend (could also be Anthropic, Gemini, Ollama, etc.)
const backend = new OpenAIBackend({
apiKey: process.env.REACT_APP_OPENAI_API_KEY,
});
function ChatComponent() {
const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
direct: {
backend,
systemPrompt: 'You are a helpful assistant.',
},
});
return (
<div>
{messages.map((m) => (
<div key={m.id}>
<strong>{m.role}:</strong> {m.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input value={input} onChange={handleInputChange} />
<button type="submit" disabled={isLoading}>Send</button>
</form>
</div>
);
}
useChat - Chat interface with streaming supportuseCompletion - Text completion interfaceuseObject - Structured object generationMessage - Chat message typeToolCall, ToolInvocation, Tool - Tool calling typesUseChatOptions, UseChatReturn - useChat typesUseCompletionOptions, UseCompletionReturn - useCompletion typesUseObjectOptions, UseObjectReturn - useObject typesDirectBackend, DirectModeOptions, DirectToolCallHandler - Direct mode typesReact hook for building chat interfaces with streaming support.
Supports two modes:
api endpoint with fetchdirect.backend for direct backend accessconst {
messages, // Message[] - Chat history
input, // string - Current input value
setInput, // (value: string) => void - Set input
handleInputChange, // (e: ChangeEvent) => void - Input change handler
handleSubmit, // (e?: FormEvent) => void - Form submit handler
append, // (message: Message | string) => Promise<string | null>
reload, // () => Promise<string | null> - Reload last response
stop, // () => void - Stop streaming
setMessages, // (messages: Message[]) => void
isLoading, // boolean - Request in progress
error, // Error | undefined
data, // unknown[] | undefined - Additional data
} = useChat(options);
useChat({
api: '/api/chat', // API endpoint (default: '/api/chat')
initialMessages: [], // Initial messages
initialInput: '', // Initial input value
id: 'chat-1', // Chat instance ID
headers: {}, // Request headers
body: {}, // Extra request body fields
onFinish: (message) => {}, // Called when response completes
onError: (error) => {}, // Called on error
onResponse: (response) => {}, // Called with fetch response
streamProtocol: 'data', // 'data' (SSE) or 'text'
});
useChat({
direct: {
// Required: Backend adapter (any ai.matey backend or Bridge)
backend: myBackendAdapter,
// Optional: System prompt
systemPrompt: 'You are a helpful assistant.',
// Optional: Default IR parameters
defaultParameters: {
temperature: 0.7,
maxTokens: 1000,
},
// Optional: Available tools
tools: [
{
name: 'get_weather',
description: 'Get weather for a location',
parameters: { /* JSON Schema */ },
},
],
// Optional: Tool call handler
onToolCall: async (name, input, id) => {
return 'Tool result';
},
// Optional: Auto-execute tools (default: false)
autoExecuteTools: true,
// Optional: Max tool rounds (default: 10)
maxToolRounds: 5,
},
// Common options still work
initialMessages: [],
onFinish: (message) => {},
onError: (error) => {},
});
React hook for text completion interfaces.
const {
completion, // string - Current completion
input, // string - Current input
setInput, // (value: string) => void
handleInputChange,
handleSubmit,
complete, // (prompt: string) => Promise<string | null>
stop,
isLoading,
error,
} = useCompletion({
api: '/api/completion',
// ... similar options to useChat
});
React hook for generating structured objects.
const {
object, // T | undefined - Generated object
submit, // (input: string) => void
isLoading,
error,
} = useObject<MyType>({
api: '/api/object',
schema: myZodSchema, // Zod schema for validation
});
| Feature | HTTP Mode | Direct Mode |
|---|---|---|
| Setup | Requires API endpoint | Just a backend adapter |
| Server needed | Yes | No |
| Use case | Full-stack apps | Electron, browser extensions, testing |
| Streaming | Via SSE | Native async iterators |
| Tool calling | Via API | Built-in with wrapper-ir |
MIT - see LICENSE for details.
FAQs
Core React hooks for AI Matey - useChat, useCompletion, useObject
We found that ai.matey.react.core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.