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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-mainframe

v0.0.0

Published

HTTP/SSE server wrapping pi coding agent with a web UI, sandbox support, and TTS

Readme

pi-mainframe

HTTP/SSE server wrapping pi coding agent as a library, with a web UI, pi-daytona sandbox integration, and xAI TTS support.

Features

  • Web UI — chat interface with thread management, task scheduling, and sandbox monitoring
  • REST API — create sessions, send prompts, manage models
  • SSE streaming — real-time event stream for agent output
  • pi-daytona support — run tools inside isolated Daytona cloud sandboxes
  • xAI TTS — text-to-speech playback of assistant responses
  • Task scheduling — cron-based automated prompt execution
  • Zero Express — uses Node.js built-in http module (no framework dependencies)

Quick Start

# Run directly via npx
npx pi-mainframe

# Or install globally
npm install -g pi-mainframe
pi-mainframe

The server starts on http://127.0.0.1:8888 by default. Open that URL in your browser to use the web UI.

Development

git clone https://github.com/richardanaya/pi-mainframe.git
cd pi-mainframe
npm install
npm run dev

Configuration

Environment variables:

| Variable | Default | Description | |----------|---------|-------------| | PORT | 8888 | HTTP port | | HOST | 127.0.0.1 | Bind address | | PI_DEFAULT_PROVIDER | anthropic | Default model provider | | PI_DEFAULT_MODEL | claude-sonnet-4-20250514 | Default model ID |

TTS

Create ~/.pi/xai-tts.json with your xAI API key:

{
  "xaiApiKey": "your-key-here",
  "voice": "eve"
}

Voice options: leo, eve, ara, rex, sal

API Endpoints

Health

GET /api/health

Models

GET /api/models

Sessions

POST   /api/sessions              Create session
GET    /api/sessions              List active sessions
GET    /api/sessions/:id           Get session state
DELETE /api/sessions/:id           Dispose session

Prompting

POST /api/sessions/:id/prompt     Send prompt → SSE stream
POST /api/sessions/:id/steer      Queue steering message
POST /api/sessions/:id/follow-up  Queue follow-up message
POST /api/sessions/:id/abort      Abort current operation

Control

POST /api/sessions/:id/compact    Compact context
PUT  /api/sessions/:id/model      Set model
PUT  /api/sessions/:id/thinking   Set thinking level
POST /api/sessions/:id/cycle-model Cycle model
GET  /api/sessions/:id/messages   Get all messages

Auth

POST /api/auth                    Set runtime API key

TTS

POST /api/tts                     Generate speech audio (xAI TTS)

Using Sandboxes (pi-daytona)

First install pi-daytona:

pi install npm:pi-daytona

Then create a session with sandbox mode:

curl -X POST http://localhost:8888/api/sessions \
  -H "Content-Type: application/json" \
  -d '{
    "sandbox": true,
    "sandboxName": "my-project",
    "tools": "coding"
  }'

Or via headers:

curl -X POST http://localhost:8888/api/sessions \
  -H "X-Sandbox: true" \
  -H "X-Sandbox-Name: my-project"

To disable sandbox for a session if pi-daytona is loaded:

curl -X POST http://localhost:8888/api/sessions \
  -H "Content-Type: application/json" \
  -d '{"sandbox": true, "noSandbox": true}'

Prompt with SSE Streaming

curl -N -X POST http://localhost:8888/api/sessions/<session-id>/prompt \
  -H "Content-Type: application/json" \
  -d '{"message": "Write a hello world program in TypeScript"}'

Events are delivered as SSE:

event: message-update
data: {"seq":1,"ts":...,"type":"message_update","assistantMessageEvent":{"type":"text_delta","delta":"Hello"}}

event: tool-start
data: {"seq":2,"ts":...,"type":"tool_execution_start","toolCallId":"...","toolName":"write","toolInput":{...}}

event: tool-end
data: {"seq":3,"ts":...,"type":"tool_execution_end","toolCallId":"...","isError":false}

event: agent-end
data: {"seq":4,"ts":...,"type":"agent_end","messages":[...]}

event: done
data: {}

Example: Full Flow

# 1. Set API key
curl -X POST http://localhost:8888/api/auth \
  -H "Content-Type: application/json" \
  -d '{"provider": "anthropic", "apiKey": "sk-ant-..."}'

# 2. Create a session
SESSION=$(curl -s -X POST http://localhost:8888/api/sessions \
  -H "Content-Type: application/json" \
  -d '{"tools": "coding", "thinkingLevel": "off"}' | jq -r '.id')

# 3. Send a prompt (SSE)
curl -N -X POST "http://localhost:8888/api/sessions/$SESSION/prompt" \
  -H "Content-Type: application/json" \
  -d '{"message": "List the files in the current directory"}'

# 4. Get messages
curl "http://localhost:8888/api/sessions/$SESSION/messages"

# 5. Clean up
curl -X DELETE "http://localhost:8888/api/sessions/$SESSION"

Programmatic Usage

import { createPiServer } from "./server.js";

const { pi, server, shutdown } = await createPiServer({
  port: 8888,
  host: "127.0.0.1",
  daytonaExtensionPath: "/home/user/.pi/extensions/pi-daytona/index.ts",
});

// pi is a PiManager instance — use it directly
const handle = await pi.createSession({
  tools: "coding",
  extensionFlags: new Map([["sandbox", "my-sandbox"]]),
  extraExtensionPaths: ["/path/to/daytona/index.ts"],
});

await pi.prompt(handle.id, { message: "Hello" }, (event) => {
  console.log(event);
});

License

MIT