Skip to main content
API reference for the @enclave-vm/react package - React hooks and components for EnclaveJS.

Installation

EnclaveProvider

Provider component for the EnclaveJS context.

Props

config takes exactly the options of EnclaveClient: baseUrl, headers, timeout, autoReconnect, maxReconnectAttempts, reconnectDelay, maxEventLength and fetch. Any other option, such as encryption, auth or serverUrl, throws when the provider renders.
The client does not encrypt. Requests and events travel as plain JSON over HTTP and are protected only by the transport: use an https: base URL, and send credentials with headers.

Configuration Changes

  • When a render brings a config with other values, such as another baseUrl or a renewed token in headers, the provider builds a new client from it. The context then exposes that client together with that configuration.
  • A render with an equal config, such as an object literal written inline, keeps the client. headers are compared entry by entry, every other option by identity, so pass the same fetch function on every render.
  • A session that was started before the change finishes on the client it was started with.

useEnclaveSession

Main hook for code execution.

Options

Tools run on the broker. The hook is told about tool calls; it executes nothing and has no API to handle them.

Return Value

stdout, events, result and error are cleared when the next execution starts. The hook does not cancel a running session when the component unmounts.

Example

useEnclaveClient

Get direct access to the client instance.

Example

useEnclaveContext

Get the context value: the client, and the configuration it was built from.
useEnclaveContext, useEnclaveClient and useEnclaveSession throw when they are used outside an EnclaveProvider.

Complete Example

TypeScript

All hooks and components are fully typed.
EnclaveClient is exported from @enclave-vm/react as a type. To create a client, import the class from @enclave-vm/client.