Pastecn AI SDK Tools
pastecn/ai-sdkFreeUtility
AI SDK tools for creating and reading pastecn snippets
Live preview
live · rendered by the registry
Rendered by pastecn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://pastecn.com/r/ai-sdk.jsonSource
1import { tool } from "ai";2import { z } from "zod";34export const createSnippet = (options?: { baseUrl?: string }) =>5 tool({6 description: "Create a code snippet on pastecn and get a shareable URL",7 inputSchema: z.object({8 name: z.string().describe("Name of the snippet"),9 type: z10 .enum(["file", "component", "hook", "lib", "block"])11 .describe("Type of snippet"),12 files: z13 .array(14 z.object({15 path: z16 .string()17 .describe('File path (e.g., "components/button.tsx")'),18 content: z.string().describe("File content"),19 target: z20 .string()21 .optional()22 .describe("Target path for installation"),23 })24 )25 .describe("Files to include in the snippet"),26 password: z.string().optional().describe("Optional password protection"),27 }),28 execute: async ({ name, type, files, password }) => {29 const baseUrl = options?.baseUrl ?? "https://pastecn.com";30 const response = await fetch(`${baseUrl}/api/v1/snippets`, {31 method: "POST",32 headers: { "Content-Type": "application/json" },33 body: JSON.stringify({ name, type, files, password }),34 });3536 if (!response.ok) {37 const error = await response.text();38 throw new Error(error || "Failed to create snippet");39 }4041 return response.json();42 },43 });4445export const getSnippet = (options?: { baseUrl?: string }) =>46 tool({47 description: "Retrieve a code snippet from pastecn by ID",48 inputSchema: z.object({49 id: z.string().describe("Snippet ID"),50 password: z51 .string()52 .optional()53 .describe("Password if snippet is protected"),54 }),55 execute: async ({ id, password }) => {56 const baseUrl = options?.baseUrl ?? "https://pastecn.com";57 const headers: Record<string, string> = {58 "Content-Type": "application/json",59 };6061 if (password) {62 headers["Authorization"] = `Bearer ${password}`;63 }6465 const response = await fetch(`${baseUrl}/api/v1/snippets/${id}`, {66 headers,67 });6869 if (!response.ok) {70 const error = await response.text();71 throw new Error(error || "Failed to get snippet");72 }7374 return response.json();75 },76 });
What it pulls in
npm packages
