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

@cmdop/react

v2026.3.301

Published

CMDOP SDK for React - Hooks and components for browser-based agent interaction

Readme

@cmdop/react

CMDOP Architecture

React hooks and components for browser-based CMDOP agent interaction.

Installation

npm install @cmdop/react react react-dom
# or
pnpm add @cmdop/react react react-dom
# or
yarn add @cmdop/react react react-dom

Peer Dependencies: React >= 18.0.0

Quick Start

import { CMDOPProvider, WebSocketProvider, useTerminal } from '@cmdop/react';

function App() {
  return (
    <CMDOPProvider token="your-jwt-token">
      <WebSocketProvider
        url="wss://ws.cmdop.com/connection/websocket"
        getToken={() => Promise.resolve('your-jwt-token')}
      >
        <Terminal sessionId="session-123" />
      </WebSocketProvider>
    </CMDOPProvider>
  );
}

function Terminal({ sessionId }: { sessionId: string }) {
  const { isConnected, output, sendInput } = useTerminal({ sessionId });

  return (
    <div>
      <pre>{output}</pre>
      <input
        onKeyDown={(e) => {
          if (e.key === 'Enter') {
            sendInput(e.currentTarget.value + '\n');
            e.currentTarget.value = '';
          }
        }}
        placeholder={isConnected ? 'Type command...' : 'Connecting...'}
      />
    </div>
  );
}

Features

HTTP API Hooks (SWR)

Data fetching with caching and revalidation:

import { CMDOPProvider, useMachines, useMachine, useWorkspaces } from '@cmdop/react';

function MachineList() {
  const { machines, isLoading, error, refetch } = useMachines();

  if (isLoading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;

  return (
    <ul>
      {machines?.map((machine) => (
        <li key={machine.id}>{machine.name}</li>
      ))}
    </ul>
  );
}

function MachineDetail({ id }: { id: string }) {
  const { machine, isLoading } = useMachine(id);
  return <div>{machine?.name}</div>;
}

function WorkspaceList() {
  const { workspaces, isLoading } = useWorkspaces();
  return (
    <ul>
      {workspaces?.map((ws) => (
        <li key={ws.id}>{ws.name}</li>
      ))}
    </ul>
  );
}

WebSocket Terminal Hook

Real-time terminal interaction:

import { useTerminal } from '@cmdop/react';

function Terminal({ sessionId }: { sessionId: string }) {
  const {
    isConnected,
    isConnecting,
    output,
    status,
    error,
    sendInput,
    resize,
    signal,
    clear,
  } = useTerminal({
    sessionId,
    onOutput: (data) => console.log('Output:', data),
    onStatus: (status) => console.log('Status:', status),
    onError: (err) => console.error('Error:', err),
  });

  // Send input
  const handleSubmit = (command: string) => {
    sendInput(command + '\n');
  };

  // Resize terminal
  const handleResize = () => {
    resize(120, 40);
  };

  // Send Ctrl+C
  const handleInterrupt = () => {
    signal('SIGINT');
  };

  return (
    <div>
      <pre>{output}</pre>
      <button onClick={() => signal('SIGINT')}>Ctrl+C</button>
      <button onClick={clear}>Clear</button>
    </div>
  );
}

AI Agent Hook

Streaming AI agent with tool calls:

import { useAgent } from '@cmdop/react';

function AgentChat({ sessionId }: { sessionId: string }) {
  const {
    run,
    isRunning,
    streamingText,
    result,
    toolCalls,
    error,
    reset,
    cancel,
  } = useAgent({
    sessionId,
    onToken: (text) => console.log('Token:', text),
    onToolCall: (tool) => console.log('Tool:', tool.name),
    onDone: (result) => console.log('Done:', result),
    onError: (err) => console.error('Error:', err),
  });

  const handleSubmit = async (prompt: string) => {
    const response = await run(prompt, {
      mode: 'chat',
      timeoutSeconds: 60,
    });
    console.log('Final response:', response);
  };

  return (
    <div>
      {/* Streaming output */}
      <pre>{streamingText || result}</pre>

      {/* Active tool calls */}
      {toolCalls.map((tool) => (
        <div key={tool.id}>Running: {tool.name}</div>
      ))}

      {/* Controls */}
      <button onClick={() => handleSubmit('List files')}>
        {isRunning ? 'Running...' : 'Send'}
      </button>
      {isRunning && <button onClick={cancel}>Cancel</button>}
      <button onClick={reset}>Reset</button>
    </div>
  );
}

WebSocket Infrastructure

Low-level WebSocket hooks for custom implementations:

import { useSubscription, useRPC, useWebSocket } from '@cmdop/react';

// Access WebSocket client
function CustomComponent() {
  const { client, isConnected } = useWebSocket();
  // ...
}

// Subscribe to channel
function Subscriber() {
  const { data, isSubscribed, error } = useSubscription<MyData>({
    channel: 'my-channel',
    onData: (data) => console.log('Received:', data),
  });
  // ...
}

// Make RPC calls
function RPCCaller() {
  const { call, isLoading, error } = useRPC();

  const handleCall = async () => {
    const result = await call<Request, Response>('method.name', { param: 'value' });
  };
  // ...
}

Providers

CMDOPProvider

Provides JWT token for HTTP API calls:

<CMDOPProvider token="jwt-token" baseUrl="https://api.cmdop.com">
  <App />
</CMDOPProvider>

WebSocketProvider

Manages WebSocket connection:

<WebSocketProvider
  url="wss://ws.cmdop.com/connection/websocket"
  getToken={() => fetchToken()}
  autoConnect={true}
  debug={false}
>
  <App />
</WebSocketProvider>

Related Packages

Links

License

MIT