New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@hackdance/hooks

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hackdance/hooks

> [!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 -

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

[!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
NameTypeDescription
onBeforeStartfunctionOptional callback function that will be invoked before the stream starts.
onStopfunctionOptional 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
NameTypeDescription
onReceivefunctionOptional callback function that will be invoked when a message is received.
onEndfunctionOptional callback function that will be invoked when the chat stream ends.
startingMessagesarrayOptional array of starting messages.
ctxobjectOptional static context object, appended to every post body on each startStream invocation .
defaultMethodstringOptional method for the request, one of GET
defaultHeadersobjectOptional 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:

NameTypeDescription
urlstringThe URL of the stream.
promptstringA string prompt included in the post body on the request to your url.
ctxobjectOptional context object, sent in the post body on the request to your url.
methodstringOptional method for the request, one of GET
headersobjectOptional 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
NameTypeDescription
onReceivefunctionOptional callback function that will be invoked when a JSON object is received.
onEndfunctionOptional callback function that will be invoked when the JSON stream ends.
schemaz.ZodObjectThe zod schema for the JSON data, the top level must be an object.
ctxobjectOptional static context object, appended to every post body on each
startStream invocation .
defaultMethodstringOptional method for the request, one of GET
defaultHeadersobjectOptional 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:

NameTypeDescription
urlstringThe URL of the stream.
ctxobjectOptional context object, sent in the post body to your url.
methodstringOptional method for the request, one of GET
headersobjectOptional 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

FAQs

Package last updated on 21 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc