npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@optima-chat/agentic-sdk

v0.15.0

Published

Chat core logic for Optima gateway - Provider, hooks, store, WebSocket client

Readme

@optima-chat/agentic-sdk

React SDK for the Optima agentic chat gateway. Provides a <ChatProvider>, a set of hooks for reading/writing chat state, a Zustand store, a WebSocket client, and a workspace-file integration. Pluggable auth (works with @optima-chat/agentic-auth or any custom tokenProvider).

Install

pnpm add @optima-chat/agentic-sdk

Peer dependencies: react@^19, zustand@^5.

Usage

1. Wrap your app in ChatProvider

import { ChatProvider, createDefaultWorkspaceProvider } from '@optima-chat/agentic-sdk';

<ChatProvider
  gatewayUrl="wss://gateway.optima.chat/ws"
  tokenProvider={async () => currentAccessToken}
  authenticatedFetch={fetchWithAuth}                    // optional
  workspaceProvider={createDefaultWorkspaceProvider(    // optional
    'https://gateway.optima.chat',
    fetchWithAuth,
  )}
  onFinish={({ conversationId, finish }) => { /* … */ }}
  onToolCall={({ toolName, args }) => { /* … */ }}
  onError={(error) => { /* … */ }}
  onNotification={(event) => { /* … */ }}
  onRawEvent={(event) => { /* intercept gateway events before store mutation */ }}
>
  {children}
</ChatProvider>

2. Consume via hooks

All hooks must be called inside a <ChatProvider> descendant.

| Hook | Returns | |---|---| | useConnectionState() | { connectionState, error, reconnectAttempt, reconnect } | | useSession() | { sessionId, userId, provider, model } | | useConversations() | { conversations, currentConversationId, createConversation, deleteConversation, renameConversation, switchConversation, isLoading, error } | | useCurrentChat() | { messages, isStreaming, isThinking, error, sendMessage, abort, resetConversation, loadHistory, hasMoreHistory, isLoadingHistory } | | useQuestion() | { pendingQuestion, answerQuestion, dismissQuestion } | | useApproval() | { pendingApprovals, approve, reject, modify } | | useSwitchConfig() | { switchConfig } | | useProcessingConversations() | string[] — conversation ids with active streams (for sidebar spinners) |

Example: send a message, stream response

import { useConversations, useCurrentChat } from '@optima-chat/agentic-sdk';

function ChatInput() {
  const { currentConversationId, createConversation, switchConversation } = useConversations();
  const { sendMessage, isStreaming } = useCurrentChat();

  async function send(text: string) {
    if (!currentConversationId) {
      const conv = await createConversation();
      switchConversation(conv.id);
    }
    await sendMessage(text);
  }

  return /* … */;
}

ChatProvider props — callback summary

  • onFinish — assistant turn completed. Receives { conversationId, finish: FinishInfo }.
  • onToolCall — tool invocation started. Receives { toolName, args, toolCallId }. Useful for opening side panels when specific tools run.
  • onError — mapped chat error with { code, message, details }. For billing-category errors, error.code is the BillingError.reason and error.details is the full BillingError.
  • onNotification — in-band notifications ({ type: 'error' | 'warning' | 'info', message }), typically rendered as toasts.
  • onRawEvent — raw gateway event before store mutation. Use this to extract out-of-band data (progress events, custom info events, tool-result payloads) into your own store.

Impersonation / reconnect

<ChatProvider> reads tokenProvider on every WebSocket connect. To switch users (e.g., admin impersonation) or force a reconnect with different credentials, remount the provider with a key:

<ChatProvider key={impersonationId ?? 'normal'} tokenProvider={…} … />

Workspace integration

workspaceProvider is optional. If you need file attachments on messages or skill-backed file access, wire up createDefaultWorkspaceProvider(gatewayHttpBase, authenticatedFetch) or implement the WorkspaceProvider interface yourself.

Type exports

import type {
  ChatProviderProps,
  ConnectionState, MessageStatus, ToolCallStatus,
  ChatError, Conversation, Message, MessageAttachment, ToolCall,
  QuestionRequest, ApprovalRequestWithId,
  SendMessageOptions, UploadResult,
  WorkspaceProvider,
  // re-exports from @optima-chat/gateway-protocol
  ServerEvent, ClientEvent, FinishInfo, Question, ApprovalRequest,
  ApprovalResponse, TokenProgress, BillingError,
} from '@optima-chat/agentic-sdk';

Relation to agentic-auth

agentic-sdk does not depend on agentic-auth. You can pair them for the standard OAuth 2.0 / email-OTP flow, or provide any other tokenProvider: () => Promise<string> implementation.

Development

pnpm --filter @optima-chat/agentic-sdk test
pnpm --filter @optima-chat/agentic-sdk typecheck
pnpm --filter @optima-chat/agentic-sdk build

Tests run under vitest with jsdom.