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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dedalus-react

v0.1.2

Published

React hooks and utilities for building chat interfaces with Dedalus

Readme

dedalus-react

React hooks for building chat interfaces with Dedalus.

Dedalus React

Installation

pnpm add dedalus-react dedalus-labs

Quick Start

Client (React)

import { useChat } from "dedalus-react";

function Chat() {
  const { messages, sendMessage, status, stop } = useChat({
    transport: { api: "/api/chat" },
  });

  return (
    <div>
      {messages.map((msg, i) => (
        <div key={i}>
          <strong>{msg.role}:</strong> {msg.content}
        </div>
      ))}

      <button onClick={() => sendMessage("Hello!")}>Send</button>

      {status === "streaming" && <button onClick={stop}>Stop</button>}
    </div>
  );
}

Server (Express)

Use streamToNodeResponse for Node.js HTTP frameworks like Express, Fastify, or the built-in http module.

import express from "express";
import Dedalus, { DedalusRunner } from "dedalus-labs";
import { streamToNodeResponse } from "dedalus-react/server";

const app = express();
const client = new Dedalus();
const runner = new DedalusRunner(client);

app.post("/api/chat", async (req, res) => {
  const { messages } = req.body;

  const stream = await runner.run({
    messages,
    model: "openai/gpt-4o-mini",
    stream: true,
  });

  await streamToNodeResponse(stream, res);
});

Server (Next.js App Router)

Use streamToWebResponse for environments using the Web Fetch API, including Next.js App Router, Cloudflare Workers, Deno, and Bun.

import Dedalus, { DedalusRunner } from "dedalus-labs";
import { streamToWebResponse } from "dedalus-react/server";

const client = new Dedalus();
const runner = new DedalusRunner(client);

export async function POST(req: Request) {
  const { messages } = await req.json();

  const stream = await runner.run({
    messages,
    model: "openai/gpt-4o-mini",
    stream: true,
  });

  return streamToWebResponse(stream);
}

API

useChat(options) Params

| Option | Type | Description | | --- | --- | --- | | transport | TransportConfig | Required. Transport configuration (see below) | | id | string | Chat session ID | | messages | Message[] | Initial messages | | generateId | () => string | Custom ID generator (defaults to crypto.randomUUID) | | onError | (error: Error) => void | Error callback | | onFinish | (opts: OnFinishOptions) => void | Completion callback | | onToolCall | (opts: OnToolCallOptions) => void \| Promise<void> | Tool call callback | | sendAutomaticallyWhen | (opts) => boolean \| Promise<boolean> | Auto-send condition for agentic flows |

Returns

| Property | Type | Description | | --- | --- | --- | | id | string | Chat session ID | | messages | Message[] | Current messages | | status | string | ready, submitted, streaming, or error | | error | Error \| undefined | Current error (if any) | | sendMessage | (message: Message \| string, options?: ChatRequestOptions) => Promise<void> | Send a message | | setMessages | (messages: Message[] \| (prev: Message[]) => Message[]) => void | Update messages | | stop | () => void | Stop streaming | | addToolResult | (opts: AddToolResultOptions) => void | Add a tool result to the conversation |

TransportConfig

| Property | Type | Description | | --- | --- | --- | | api | string \| () => string | Required. API endpoint | | headers | object \| Headers \| () => object | Additional request headers | | credentials | RequestCredentials \| () => RequestCredentials | Fetch credentials mode | | body | object \| () => object | Additional body properties merged into requests | | fetch | typeof fetch | Custom fetch function | | prepareRequestBody | (opts) => object | Transform the request body before sending |

OnFinishOptions

| Property | Type | Description | | --- | --- | --- | | message | Message | The final assistant message | | messages | Message[] | All messages in the conversation including the final assistant message | | isAbort | boolean | True if the request was aborted by the user | | isDisconnect | boolean | True if a network error caused disconnection | | isError | boolean | True if an error occurred during streaming |

OnToolCallOptions

| Property | Type | Description | | --- | --- | --- | | toolCall | ToolCall | The tool call received from the assistant |

ToolCall

| Property | Type | Description | | --- | --- | --- | | id | string | Unique identifier for this tool call | | type | "function" | The type of tool call | | function | { name: string; arguments: string } | The function name and JSON-encoded arguments |

SendAutomaticallyWhenOptions

| Property | Type | Description | | --- | --- | --- | | messages | Message[] | Current messages in the conversation |

Examples

The example/ directory contains working examples for different setups:

| Example | Description | | ------- | ----------- | | next-simple | Minimal Next.js App Router example | | next-model-select | Next.js with dynamic model selection | | react-express-simple | Minimal React + Express example | | react-express-model-select | React + Express with model selection |

Running an Example

cd example/next-simple  # or any other example
pnpm install
cp .env.example .env.local  # use .env for Express examples
# Add your DEDALUS_API_KEY to the env file
pnpm dev  # or pnpm start for Express examples

License

MIT