
Security News
pnpm 11.5 Adds Support for Recognizing npm Staged Publishes
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.
@enclave-vm/react
Advanced tools
React hooks and components for the EnclaveJS streaming runtime
The @enclave-vm/react package provides React bindings for EnclaveJS, including hooks for code execution, connection management, and pre-built components for common use cases like code editors and output displays.
useEnclave, useExecution, useSession hooksnpm install @enclave-vm/react @enclave-vm/client
# or
yarn add @enclave-vm/react @enclave-vm/client
# or
pnpm add @enclave-vm/react @enclave-vm/client
import { EnclaveProvider, useEnclave } from '@enclave-vm/react';
function App() {
return (
<EnclaveProvider url="wss://runtime.example.com">
<CodeRunner />
</EnclaveProvider>
);
}
function CodeRunner() {
const { execute, isConnected, isExecuting } = useEnclave();
const [result, setResult] = useState(null);
const runCode = async () => {
const res = await execute(`
const user = await callTool('getUser', { id: 1 });
return user.name;
`);
setResult(res.value);
};
return (
<div>
<button onClick={runCode} disabled={!isConnected || isExecuting}>
{isExecuting ? 'Running...' : 'Run Code'}
</button>
{result && <div>Result: {result}</div>}
</div>
);
}
Main hook for interacting with the EnclaveJS runtime:
import { useEnclave } from '@enclave-vm/react';
function MyComponent() {
const {
// Connection
isConnected,
connect,
disconnect,
// Execution
execute,
stream,
isExecuting,
// Session
sessionId,
createSession,
destroySession,
// Events
onToolCall,
onToolResult,
onLog,
onError,
} = useEnclave();
// Subscribe to tool calls
useEffect(() => {
const unsubscribe = onToolCall((call) => {
console.log('Tool called:', call.name);
});
return unsubscribe;
}, [onToolCall]);
return <div>{isConnected ? 'Connected' : 'Disconnected'}</div>;
}
Hook for managing individual code executions:
import { useExecution } from '@enclave-vm/react';
function ExecutionComponent() {
const { execute, result, error, isLoading, toolCalls } = useExecution();
return (
<div>
<button onClick={() => execute('return 1 + 1')} disabled={isLoading}>
Execute
</button>
{isLoading && <div>Executing...</div>}
{error && <div>Error: {error.message}</div>}
{result && <div>Result: {JSON.stringify(result.value)}</div>}
<div>
<h3>Tool Calls:</h3>
{toolCalls.map((call) => (
<div key={call.id}>
{call.name}: {JSON.stringify(call.args)}
</div>
))}
</div>
</div>
);
}
Hook for persistent session management:
import { useSession } from '@enclave-vm/react';
function SessionComponent() {
const { session, create, destroy, execute, isActive } = useSession();
useEffect(() => {
create({ timeout: 60000 });
return () => destroy();
}, []);
if (!isActive) return <div>No active session</div>;
return (
<div>
<div>Session: {session.id}</div>
<button onClick={() => execute('return Date.now()')}>Get Time</button>
</div>
);
}
import { EnclaveProvider } from '@enclave-vm/react';
function App() {
return (
<EnclaveProvider
url="wss://runtime.example.com"
auth={{ token: 'your-token' }}
autoConnect={true}
reconnect={{
enabled: true,
maxAttempts: 5,
}}
onConnected={() => console.log('Connected!')}
onDisconnected={() => console.log('Disconnected')}
onError={(error) => console.error(error)}
>
<App />
</EnclaveProvider>
);
}
Handle streaming execution with real-time updates:
import { useEnclave } from '@enclave-vm/react';
function StreamingComponent() {
const { stream } = useEnclave();
const [items, setItems] = useState([]);
const runStreaming = async () => {
setItems([]);
await stream(
`
for (const i of [1, 2, 3, 4, 5]) {
const data = await callTool('processItem', { id: i });
yield data;
}
`,
{
onYield: (value) => {
setItems((prev) => [...prev, value]);
},
},
);
};
return (
<div>
<button onClick={runStreaming}>Start Streaming</button>
<ul>
{items.map((item, i) => (
<li key={i}>{JSON.stringify(item)}</li>
))}
</ul>
</div>
);
}
Use with React error boundaries:
import { EnclaveErrorBoundary } from '@enclave-vm/react';
function App() {
return (
<EnclaveErrorBoundary
fallback={(error, reset) => (
<div>
<p>Something went wrong: {error.message}</p>
<button onClick={reset}>Try again</button>
</div>
)}
>
<CodeRunner />
</EnclaveErrorBoundary>
);
}
For Next.js App Router, use client components:
// components/code-runner.tsx
'use client';
import { EnclaveProvider, useEnclave } from '@enclave-vm/react';
export function CodeRunner() {
return (
<EnclaveProvider url={process.env.NEXT_PUBLIC_ENCLAVE_URL!}>
<RunnerInner />
</EnclaveProvider>
);
}
| Package | Description |
|---|---|
| @enclave-vm/types | Type definitions and Zod schemas |
| @enclave-vm/client | Browser/Node.js client SDK |
| @enclave-vm/stream | Streaming protocol implementation |
| @enclave-vm/runtime | Standalone runtime worker |
Apache-2.0
FAQs
React hooks and components for the EnclaveJS streaming runtime
We found that @enclave-vm/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.