@kortyx/react
v0.3.1
Published
React hooks for Kortyx client streaming experiences.
Maintainers
Readme
@kortyx/react
React hooks and transport helpers for Kortyx client streaming experiences.
Install
pnpm add @kortyx/reactnpm install @kortyx/reactExports
useChatcreateRouteChatTransportcreateChatTransportcreateBrowserChatStorageuseStructuredStreamscreateLiveChatPiecestoHumanInputPiece
useChat keeps finalized chat history in messages and the active assistant
response in streamContentPieces while a stream is running.
It also exposes stream controls for UI integrations:
abort()/canAborterror/clearError()clearMessages()resetSession()resetChat()respondToInterrupt(...)
clearMessages() keeps the current session. resetChat() clears messages,
active stream state, errors, and the session id. Route transports forward
abort() through an AbortSignal; custom transports should forward
context.signal to their own request layer.
useChat({ context }) forwards request context to the transport. Route
transports send { sessionId, workflowId, messages, context } by default, and
createRouteChatTransport({ createBody }) can customize that body.
prepareContextMessages lets apps replace the default history with summaries
or server-owned history while useChat still appends the outgoing message.
Example
"use client";
import { createRouteChatTransport, useChat } from "@kortyx/react";
export function Chat() {
const chat = useChat({
transport: createRouteChatTransport({ endpoint: "/api/chat" }),
});
return (
<button onClick={() => chat.send("Summarize this account")}>
Send
</button>
);
}Documentation
License
Apache-2.0. See LICENSE.
