Skip to content

secondsky/claude-skills / plugins/thesys-generative-ui/skills/thesys-generative-ui

thesys-generative-ui

Verified

> Generate, modify, and style React components from natural language using the Thesys SDK. Guides schema-driven UI generation, theme customisation, tool calling integration, and deployment to Vite, Next.js, or Cloudflare Workers. Use when the user says "generate UI", "create a component", "build an interface", "Thesys", "generative UI", or asks to turn a description into a React component.

templates/cloudflare-workers/worker-backend.ts

View on GitHub
/**
 * Cloudflare Worker Backend with Hono + TheSys C1
 *
 * File: backend/src/index.ts
 *
 * Features:
 * - Hono routing
 * - TheSys C1 API proxy
 * - Streaming support
 * - Static assets serving
 * - CORS handling
 */

import { Hono } from "hono";
import { cors } from "hono/cors";
import { serveStatic } from "hono/cloudflare-workers";

type Bindings = {
  THESYS_API_KEY: string;
  ASSETS: Fetcher;
};

const app = new Hono<{ Bindings: Bindings }>();

// CORS middleware
app.use("/*", cors({
  origin: "*",
  allowMethods: ["GET", "POST", "OPTIONS"],
  allowHeaders: ["Content-Type", "Authorization"],
}));

// ============================================================================
// Chat API Endpoint
// ============================================================================

app.post("/api/chat", async (c) => {
  try {
    const { prompt, previousC1Response } = await c.req.json();

    if (!prompt || typeof prompt !== "string") {
      return c.json({ error: "Invalid prompt" }, 400);
    }

    // Check API key binding
    if (!c.env.THESYS_API_KEY) {
      console.error("THESYS_API_KEY binding not found");
      return c.json({ error: "Server configuration error" }, 500);
    }

    // Build messages
    const messages = [
      {
        role: "system",
        content: "You are a helpful AI assistant that generates interactive UI.",
      },
      {
        role: "user",
        content: prompt,
      },
    ];

    if (previousC1Response) {
      messages.splice(1, 0, {
        role: "assistant",
        content: previousC1Response,
      });
    }

    // Call TheSys C1 API
    const response = await fetch(
      "https://api.thesys.dev/v1/embed/chat/completions",
      {
        method: "POST",
        headers: {
          "Authorization": `Bearer ${c.env.THESYS_API_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          model: "c1/openai/gpt-5/v-20250930",
          messages,
          stream: false, // Or handle streaming
          temperature: 0.7,
          max_tokens: 2000,
        }),
      }
    );

    if (!response.ok) {
      const error = await response.text();
      console.error("TheSys API Error:", error);
      return c.json(
        { error: "Failed to get AI response" },
        response.status
      );
    }

    const data = await response.json();

    return c.json({
      response: data.choices[0]?.message?.content || "",
      usage: data.usage,
    });
  } catch (error) {
    console.error("Chat endpoint error:", error);
    return c.json(
      { error: error instanceof Error ? error.message : "Internal error" },
      500
    );
  }
});

// ============================================================================
// Streaming Chat Endpoint
// ============================================================================

app.post("/api/chat/stream", async (c) => {
  try {
    const { prompt } = await c.req.json();

    const response = await fetch(
      "https://api.thesys.dev/v1/embed/chat/completions",
      {
        method: "POST",
        headers: {
          "Authorization": `Bearer ${c.env.THESYS_API_KEY}`,
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          model: "c1/openai/gpt-5/v-20250930",
          messages: [
            { role: "system", content: "You are a helpful assistant." },
            { role: "user", content: prompt },
          ],
          stream: true,
        }),
      }
    );

    if (!response.ok) {
      return c.json({ error: "Stream failed" }, response.status);
    }

    // Return the stream directly
    return new Response(response.body, {
      headers: {
        "Content-Type": "text/event-stream",
        "Cache-Control": "no-cache",
        "Connection": "keep-alive",
      },
    });
  } catch (error) {
    console.error("Stream error:", error);
    return c.json({ error: "Stream failed" }, 500);
  }
});

// ============================================================================
// Health Check
// ============================================================================

app.get("/api/health", (c) => {
  return c.json({
    status: "ok",
    timestamp: new Date().toISOString(),
  });
});

// ============================================================================
// Serve Static Assets (Vite build output)
// ============================================================================

app.get("/*", serveStatic({ root: "./", mimes: {} }));

export default app;

/**
 * Alternative: Using Workers AI directly (cheaper for some models)
 *
 * type Bindings = {
 *   AI: any; // Cloudflare AI binding
 * };
 *
 * app.post("/api/chat", async (c) => {
 *   const { prompt } = await c.req.json();
 *
 *   const aiResponse = await c.env.AI.run('@cf/meta/llama-3-8b-instruct', {
 *     messages: [
 *       { role: "system", content: "You are a helpful assistant." },
 *       { role: "user", content: prompt },
 *     ],
 *   });
 *
 *   // Then optionally send to TheSys C1 for UI generation
 *   const c1Response = await fetch("https://api.thesys.dev/v1/embed/chat/completions", {
 *     method: "POST",
 *     headers: {
 *       "Authorization": `Bearer ${c.env.THESYS_API_KEY}`,
 *       "Content-Type": "application/json",
 *     },
 *     body: JSON.stringify({
 *       model: "c1/openai/gpt-5/v-20250930",
 *       messages: [
 *         {
 *           role: "system",
 *           content: "Generate a UI for this content: " + aiResponse.response,
 *         },
 *       ],
 *     }),
 *   });
 *
 *   // ... return c1Response
 * });
 */

/**
 * Alternative: With D1 Database for message persistence
 *
 * type Bindings = {
 *   THESYS_API_KEY: string;
 *   DB: D1Database; // D1 binding
 * };
 *
 * app.post("/api/chat", async (c) => {
 *   const { userId, threadId, prompt } = await c.req.json();
 *
 *   // Save user message
 *   await c.env.DB.prepare(
 *     "INSERT INTO messages (thread_id, user_id, role, content) VALUES (?, ?, ?, ?)"
 *   )
 *     .bind(threadId, userId, "user", prompt)
 *     .run();
 *
 *   // Get conversation history
 *   const { results } = await c.env.DB.prepare(
 *     "SELECT role, content FROM messages WHERE thread_id = ? ORDER BY created_at"
 *   )
 *     .bind(threadId)
 *     .all();
 *
 *   const messages = [
 *     { role: "system", content: "You are a helpful assistant." },
 *     ...results,
 *   ];
 *
 *   // Call TheSys API with full history...
 * });
 */
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall