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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hackdance/hooks

v4.0.1

Published

> [!WARNING] > The agents and hooks packages are no longer maintained and schema-stream has moved here: [island-ai](https://github.com/hack-dance/island-ai) > Agents has been mostly replaced by zod-stream and the hooks package has moved to stream-hooks -

Downloads

10

Readme

[!WARNING] The agents and hooks packages are no longer maintained and schema-stream has moved here: island-ai Agents has been mostly replaced by zod-stream and the hooks package has moved to stream-hooks - now both part of the island-ai project.

@hackdance/hooks

This package provides three custom React hooks for managing streams, chat streams, and JSON streams.

Installation

To install the package, run the following command:

  pnpm add @hackdance/hooks

Hooks

useStream

useStream is a custom React hook that manages a stream. It provides functionalities to start and stop the stream.

Props

| Name | Type | Description | | ------------- | -------- | ----------- | | onBeforeStart | function | Optional callback function that will be invoked before the stream starts. | | onStop | function | Optional callback function that will be invoked when the stream stops. |

Usage

  import { useStream } from '@hackdance/hooks';

  const { startStream, stopStream } = useStream({ onBeforeStart: ..., onStop: ... });

useChatStream

useChatStream is a custom React hook that extends the useStream hook to manage a chat stream. It provides functionalities to start and stop the chat stream, manage the chat messages, and manage the loading state.

Props

| Name | Type | Description | | ---------------- | -------- | ----------- | | onReceive | function | Optional callback function that will be invoked when a message is received. | | onEnd | function | Optional callback function that will be invoked when the chat stream ends. | | startingMessages | array | Optional array of starting messages. | | ctx | object | Optional static context object, appended to every post body on each startStream invocation . | | defaultMethod | string | Optional method for the request, one of GET | POST defaults to POST. | | defaultHeaders | object | Optional request headers |

Usage

  import { useChatStream } from '@hackdance/hooks'

  const { loading, startStream, stopStream, messages, setMessages } = useChatStream({ onBeforeStart: ..., onReceive: ..., onEnd: ..., startingMessages: [] })

startStream

startStream is a function that starts a stream with the provided arguments and parses the incoming stream into JSON. It takes an object as an argument with the following properties:

| Name | Type | Description | | ---- | ------ | ----------- | | url | string | The URL of the stream. | | prompt | string | A string prompt included in the post body on the request to your url. | | ctx | object | Optional context object, sent in the post body on the request to your url. | | method | string | Optional method for the request, one of GET | POST defaults to POST. | | headers | object | Optional request headers |

Example:

  startStream({ url: 'http://example.com', prompt: "hey there", ctx: { key: 'value' } });

stopStream

stopStream is a function that stops the stream. It doesn't take any arguments.

Example:

  stopStream();

useJsonStream

useJsonStream is a custom React hook that extends the useStream hook to add JSON parsing functionality. It uses the SchemaStream to parse the incoming stream into JSON.

Props

| Name | Type | Description | | --------- | -------- | ----------- | | onReceive | function | Optional callback function that will be invoked when a JSON object is received. | | onEnd | function | Optional callback function that will be invoked when the JSON stream ends. | | schema | z.ZodObject | The zod schema for the JSON data, the top level must be an object. | | ctx | object | Optional static context object, appended to every post body on each startStream invocation . | | defaultMethod | string | Optional method for the request, one of GET | POST defaults to POST. | | defaultHeaders | object | Optional request headers |

Usage

  import { useJsonStream } from '@hackdance/hooks';

  const { loading, startStream, stopStream, json } = useJsonStream({ onBeforeStart: ..., onReceive: ..., onStop: ..., onEnd: ..., schema: ..., ctx: {} });

startStream

startStream is a function that starts a stream with the provided arguments and parses the incoming stream into JSON. It takes an object as an argument with the following properties:

| Name | Type | Description | | ---- | ------ | ----------- | | url | string | The URL of the stream. | | ctx | object | Optional context object, sent in the post body to your url. | | method | string | Optional method for the request, one of GET | POST defaults to POST. | | headers | object | Optional request headers |

Example:

  startStream({ url: 'http://example.com', ctx: { key: 'value' } });

stopStream

stopStream is a function that stops the stream. It doesn't take any arguments.

Example:

  stopStream();

License

MIT