Sunpeak AI App Framework and Testing

0.20.7 · active · verified Sun Apr 19

Sunpeak (current version 0.20.7) is an AI application framework, testing framework, and inspector specifically designed for building and debugging Multi-Platform (MCP) Apps, such as those for ChatGPT and Claude. It provides a convention-over-configuration approach to simplify wiring MCP servers, handling protocol messages, managing resource HTML bundles, and setting up dev environments with hot module replacement (HMR). Its key differentiators include a robust testing framework that simulates host runtimes and provides simulation fixtures for reproducible testing across various hosts, themes, and data states without relying on external accounts or API credits. It also offers a visual inspector for debugging. Sunpeak releases are frequent, primarily focusing on bug fixes, performance improvements, and feature enhancements within the 0.x.x minor version range, indicating active development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Sunpeak project and write an end-to-end test for an MCP App using the `sunpeak/test` framework, including mocking AI model interactions.

import { test, expect } from 'sunpeak/test';
import { createOpenAI } from '@ai-sdk/openai';

// To initialize a new Sunpeak project:
// npx sunpeak new

// Then, add a test file (e.g., tests/e2e/my-app.test.ts)

// Mock your AI model for consistent testing
const mockOpenAI = createOpenAI({ apiKey: process.env.OPENAI_API_KEY ?? 'mock-key' });

test('My MCP App loads and renders a tool', async ({ page, inspector, mcp }) => {
  // Render a specific tool within the Sunpeak inspector
  await inspector.renderTool({ name: 'my-awesome-tool', params: { query: 'test' } });

  // Wait for the tool's UI to appear and interact with it
  await expect(page.locator('text=Welcome to My Awesome Tool')).toBeVisible();

  // You can also mock tool calls to the MCP server
  mcp.useTool(async ({ name, params }) => {
    if (name === 'my-awesome-tool') {
      const result = await mockOpenAI.chat({
        model: 'gpt-4o',
        messages: [{ role: 'user', content: params.query as string }],
      });
      return { result: result.text };
    }
    return { result: 'Unknown tool' };
  });

  // Simulate an interaction or assert on UI changes
  await page.locator('button', { hasText: 'Execute' }).click();
  await expect(page.locator('text=Execution complete')).toBeVisible();
});

// To run the tests:
// npx sunpeak test --e2e

view raw JSON →