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/nextjs/api-chat-route.ts
View on GitHub/**
* Next.js App Router - API Route for Chat
*
* File: app/api/chat/route.ts
*
* Handles streaming chat completions with TheSys C1 API.
*
* Features:
* - Streaming responses
* - OpenAI SDK integration
* - Error handling
* - CORS headers
*/
import { NextRequest, NextResponse } from "next/server";
import OpenAI from "openai";
import { transformStream } from "@crayonai/stream";
const client = new OpenAI({
baseURL: "https://api.thesys.dev/v1/embed",
apiKey: process.env.THESYS_API_KEY,
});
// System prompt for the AI
const SYSTEM_PROMPT = `You are a helpful AI assistant that generates interactive user interfaces.
When responding:
- Use clear, concise language
- Generate appropriate UI components (charts, tables, forms) when beneficial
- Ask clarifying questions when needed
- Be friendly and professional`;
export async function POST(req: NextRequest) {
try {
const { prompt, previousC1Response } = await req.json();
if (!prompt || typeof prompt !== "string") {
return NextResponse.json(
{ error: "Invalid prompt" },
{ status: 400 }
);
}
// Check API key
if (!process.env.THESYS_API_KEY) {
console.error("THESYS_API_KEY is not set");
return NextResponse.json(
{ error: "Server configuration error" },
{ status: 500 }
);
}
// Build messages array
const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [
{ role: "system", content: SYSTEM_PROMPT },
{ role: "user", content: prompt },
];
// If there's previous context, include it
if (previousC1Response) {
messages.splice(1, 0, {
role: "assistant",
content: previousC1Response,
});
}
// Create streaming completion
const stream = await client.chat.completions.create({
model: "c1/openai/gpt-5/v-20250930", // or claude-sonnet-4/v-20250930
messages,
stream: true,
temperature: 0.7,
max_tokens: 2000,
});
// Transform OpenAI stream to C1 format
const responseStream = transformStream(stream, (chunk) => {
return chunk.choices[0]?.delta?.content || "";
}) as ReadableStream<string>;
return new NextResponse(responseStream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache, no-transform",
"Connection": "keep-alive",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
});
} catch (error) {
console.error("Chat API Error:", error);
// Handle specific OpenAI errors
if (error instanceof OpenAI.APIError) {
return NextResponse.json(
{
error: error.message,
type: error.type,
code: error.code,
},
{ status: error.status || 500 }
);
}
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
);
}
}
// Handle preflight requests
export async function OPTIONS() {
return new NextResponse(null, {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
},
});
}
/**
* Alternative: Using Anthropic (Claude) models
*
* const stream = await client.chat.completions.create({
* model: "c1/anthropic/claude-sonnet-4/v-20250617",
* messages,
* stream: true,
* temperature: 0.8,
* max_tokens: 4096,
* });
*/
/**
* Alternative: With message persistence
*
* import { db } from "@/lib/db";
*
* export async function POST(req: NextRequest) {
* const { userId } = auth(); // Clerk, NextAuth, etc.
* const { prompt, threadId } = await req.json();
*
* // Save user message
* await db.insert(messages).values({
* threadId,
* userId,
* role: "user",
* content: prompt,
* });
*
* // Get conversation history
* const history = await db
* .select()
* .from(messages)
* .where(eq(messages.threadId, threadId))
* .orderBy(messages.createdAt);
*
* const llmMessages = history.map((m) => ({
* role: m.role,
* content: m.content,
* }));
*
* const stream = await client.chat.completions.create({
* model: "c1/openai/gpt-5/v-20250930",
* messages: [{ role: "system", content: SYSTEM_PROMPT }, ...llmMessages],
* stream: true,
* });
*
* // ... transform and return stream
*
* // Save assistant response after streaming completes
* // (You'd need to handle this in the client or use a callback)
* }
*/
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 119k | Updated | Claude CodeCodex | Verified | Install |
| 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: 118k | Updated | Claude CodeCodex | Verified | Install |