Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
feat(schemas): add shared playground and searchTools Zod schemas
diegosouzapw52c2d1cb7579
diff --git a/src/shared/schemas/playground.ts b/src/shared/schemas/playground.tsnew file mode 100644index 0000000000..af7cdac650--- /dev/null+++ b/src/shared/schemas/playground.ts@@ -0,0 +1,68 @@+// src/shared/schemas/playground.ts+import { z } from "zod";++/** Row da tabela playground_presets. */+export const PlaygroundPresetRowSchema = z.object({+ id: z.string().uuid(),+ name: z.string().min(1).max(100),+ endpoint: z.string().min(1),+ model: z.string().min(1),+ system: z.string().max(50_000).nullable(),+ params_json: z.string(), // JSON serializado (parsed na rota)+ created_at: z.string().datetime(),+});+export type PlaygroundPresetRow = z.infer<typeof PlaygroundPresetRowSchema>;++/** Body de POST /api/playground/presets. */+export const PlaygroundPresetCreateSchema = z.object({+ name: z.string().min(1).max(100),+ endpoint: z.string().min(1),+ model: z.string().min(1),+ system: z.string().max(50_000).nullable().optional(),+ params: z.record(z.string(), z.any()).default({}),+});++/** Body de PUT /api/playground/presets/[id]. */+export const PlaygroundPresetUpdateSchema = PlaygroundPresetCreateSchema.partial();++export const PlaygroundPresetListItemSchema = z.object({+ id: z.string().uuid(),+ name: z.string(),+ endpoint: z.string(),+ model: z.string(),+ system: z.string().nullable(),+ params: z.record(z.string(), z.any()),+ created_at: z.string().datetime(),+});+export type PlaygroundPresetListItem = z.infer<typeof PlaygroundPresetListItemSchema>;++/** Tool definition aceito pelo Build tab. Validação client-side. */+export const ToolDefinitionSchema = z.object({+ type: z.literal("function"),+ function: z.object({+ name: z.string().min(1).max(64),+ description: z.string().max(1024).optional(),+ parameters: z.record(z.string(), z.any()),+ }),+});++/** JSON schema do response_format (Structured Output). Validação client-side. */+export const StructuredOutputSchema = z.object({+ type: z.literal("json_schema"),+ json_schema: z.object({+ name: z.string().min(1).max(64),+ schema: z.record(z.string(), z.any()),+ strict: z.boolean().optional(),+ }),+});++/** Stream metrics — uma medição por coluna/mensagem. */+export const StreamMetricsSchema = z.object({+ ttftMs: z.number().nonnegative().nullable(), // null = não chegou primeiro chunk ainda+ totalMs: z.number().nonnegative().nullable(),+ tokensOut: z.number().int().nonnegative(),+ tokensIn: z.number().int().nonnegative(),+ tps: z.number().nonnegative().nullable(), // tokens/segundo (out/totalSec)+ costUsd: z.number().nonnegative().nullable(),+});+export type StreamMetrics = z.infer<typeof StreamMetricsSchema>;diff --git a/src/shared/schemas/searchTools.ts b/src/shared/schemas/searchTools.tsnew file mode 100644index 0000000000..2463a11a0f--- /dev/null+++ b/src/shared/schemas/searchTools.ts@@ -0,0 +1,38 @@+// src/shared/schemas/searchTools.ts+import { z } from "zod";++/** Item exposto pelo /api/search/providers (estendido em F4). */+export const SearchProviderCatalogItemSchema = z.object({+ id: z.string(),+ name: z.string(),+ /** "search" para os 12 search providers; "fetch" para firecrawl/jina/tavily-fetch. */+ kind: z.enum(["search", "fetch"]),+ costPerQuery: z.number().nonnegative(),+ freeMonthlyQuota: z.number().int().nonnegative(),+ searchTypes: z.array(z.string()).optional(), // só search+ fetchFormats: z.array(z.string()).optional(), // só fetch+ /** "configured" = creds presentes; "missing" = sem creds; "rate_limited" = todas as keys em cooldown. */+ status: z.enum(["configured", "missing", "rate_limited"]),+ /** Link para configurar provider. */+ configureHref: z.string().default("/dashboard/providers"),+});+export type SearchProviderCatalogItem = z.infer<typeof SearchProviderCatalogItemSchema>;++export const SearchProviderCatalogResponseSchema = z.object({+ providers: z.array(SearchProviderCatalogItemSchema),+});++/** ScrapeResult mostrado na aba Scrape (já é a resposta de /v1/web/fetch, mas tipado). */+export const ScrapeResultSchema = z.object({+ provider: z.string(),+ url: z.string(),+ content: z.string(),+ links: z.array(z.string()),+ metadata: z+ .object({+ title: z.string().nullable(),+ description: z.string().nullable(),+ })+ .nullable(),+ screenshot_url: z.string().nullable(),+});