
Research
SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.
ai.matey.react.hooks
Advanced tools
Additional React hooks for AI Matey - useAssistant, useStream, useTokenCount
Additional specialized React hooks for AI applications.
Part of the ai.matey monorepo.
npm install ai.matey.react.hooks
import { useAssistant } from 'ai.matey.react.hooks';
function AssistantChat() {
const { messages, input, handleInputChange, handleSubmit, status } = useAssistant({
api: '/api/assistant',
assistantId: 'asst_xxx',
});
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={status === 'in_progress'}>
Send
</button>
</form>
<p>Status: {status}</p>
</div>
);
}
useAssistant - OpenAI Assistants API integration with thread managementuseTokenCount - Token counting and context window trackinguseStream - Low-level stream consumption hookAssistantMessage, Annotation, AssistantStatus - Assistant typesUseAssistantOptions, UseAssistantReturn - useAssistant typesUseTokenCountOptions, UseTokenCountReturn - useTokenCount typesUseStreamOptions, UseStreamReturn - useStream typesReact hook for OpenAI Assistants API with thread and run management.
const {
messages, // AssistantMessage[] - Chat history with annotations
input, // string - Current input
setInput, // (value: string) => void
handleInputChange, // (e: ChangeEvent) => void
handleSubmit, // (e?: FormEvent) => void
append, // (message: string | Message) => Promise<void>
threadId, // string | undefined - Current thread ID
status, // AssistantStatus - Run status
stop, // () => void - Cancel current run
setMessages, // (messages: AssistantMessage[]) => void
error, // Error | undefined
} = useAssistant({
api: '/api/assistant', // API endpoint
assistantId: 'asst_xxx', // OpenAI Assistant ID
threadId: 'thread_xxx', // Existing thread to continue
headers: {}, // Request headers
body: {}, // Extra request body
onStatus: (status) => {}, // Called on status change
onError: (error) => {}, // Called on error
});
AssistantStatus values:
awaiting_message - Ready for inputin_progress - Processing requestrequires_action - Tool call pendingcompleted - Run finishedfailed - Run failedcancelled - Run cancelledexpired - Run expiredTrack token usage and context window limits.
const {
tokenCount, // number - Current token count
maxTokens, // number - Model's max context
remainingTokens, // number - Tokens remaining
isNearLimit, // boolean - Within 10% of limit
isOverLimit, // boolean - Exceeded limit
updateText, // (text: string) => void - Update counted text
} = useTokenCount({
model: 'gpt-4', // Model name for limits
text: '', // Initial text to count
warningThreshold: 0.9, // Threshold for isNearLimit
});
Supported models:
gpt-4, gpt-4-turbo: 128,000 tokensgpt-3.5-turbo: 16,385 tokensclaude-3-opus, claude-3-sonnet: 200,000 tokensLow-level hook for consuming async iterables/streams.
const {
data, // T[] - Accumulated data
isStreaming, // boolean
error, // Error | undefined
start, // (stream: AsyncIterable<T>) => void
stop, // () => void
reset, // () => void
} = useStream<ChunkType>({
onChunk: (chunk) => {}, // Called for each chunk
onComplete: (data) => {}, // Called when done
onError: (error) => {}, // Called on error
});
MIT - see LICENSE for details.
FAQs
Additional React hooks for AI Matey - useAssistant, useStream, useTokenCount
We found that ai.matey.react.hooks 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.

Research
An emerging npm supply chain attack that infects repos, steals CI secrets, and targets developer AI toolchains for further compromise.

Company News
Socket is proud to join the OpenJS Foundation as a Silver Member, deepening our commitment to the long-term health and security of the JavaScript ecosystem.

Security News
npm now links to Socket's security analysis on every package page. Here's what you'll find when you click through.