POLPOUI

ChatProvider

Context provider that wires up chat state, streaming, and file uploads.

ChatProvider wraps useChat from @polpo-ai/react and useFiles to provide a unified context consumed by all chat components. It exposes the full UseChatReturn interface plus file upload capabilities.

Import

import { ChatProvider, useChatContext } from "@polpo-ai/chat";

Props

PropTypeDefaultDescription
sessionIdstringResume an existing session by ID
agentstringTarget a specific agent for conversation
onSessionCreated(id: string) => voidCalled when a new session is created (first message)
onUpdate() => voidCalled after each stream update
childrenReactNoderequiredChild components that consume the context

Context value

The useChatContext() hook returns ChatContextValue which extends UseChatReturn with:

FieldTypeDescription
uploadFile(destPath, file, filename) => Promise<...>Upload a file attachment
isUploadingbooleanWhether a file upload is in progress

Usage

<ChatProvider agent="my-agent" onSessionCreated={(id) => console.log(id)}>
  <ChatMessages />
  <ChatInput />
</ChatProvider>

Accessing context directly

function CustomControls() {
  const { messages, isStreaming, abort } = useChatContext();
  return <p>{messages.length} messages</p>;
}

On this page