BREAKING CHANGE: Complete refactoring from single-tool to multi-tool package support Database Schema: - Split Tool model into Package (1) and Tool (many) with one-to-many relationship - Package stores npm metadata and package-level tpmjs fields (category, env, frameworks, tier) - Tool stores individual tool exports with tool-level metadata (exportName, description, parameters, returns, aiAgent) - Unique constraint on (packageId, exportName) to prevent duplicate tools - Cascade deletes when packages are removed Type System: - Updated tpmjs field schema to support tools array - Each tool has exportName, description, parameters, returns, aiAgent - Package-level fields: category, env, frameworks shared across all tools - Backward compatible with legacy single-tool format (auto-migrates to exportName: "default") API Updates: - Updated all /api/tools routes to query Tool model with Package relations - Updated /api/tools/[slug] to accept package/export path segments - Updated tool-executor-agent to use actual exportName instead of hardcoded "default" - Updated metrics sync to calculate quality scores per Tool Frontend Updates: - Updated tool search page to display exportName as primary heading - Updated tool detail pages to show package name as secondary info - Removed tag-based filtering (tags moved to package level) Manual Tool Registry: - Added manual-tools.ts with 23 curated tools from major providers - Created sync-manual-tools.ts script to sync manual tools to database - Added MANUAL_TOOLS.md documentation for manual tool system - Added GitHub workflow for automated daily sync - Includes tools from: Vercel, Exa, Firecrawl, AWS Bedrock, Perplexity, Tavily, Superagent, Valyu Playground Updates: - Updated tool loader to load multiple tools per package - Added sanitizeToolName for OpenAI API compatibility Sync System Updates: - Updated changes feed sync to handle multi-tool packages - Updated keyword sync to upsert multiple tools per package - Added orphaned tool deletion when tools removed from package.json Migration Strategy: - Database uses same Neon instance for dev and prod - Schema updated via prisma db push (no migration files yet) - All data repopulates from npm via sync system 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
188 lines
6 KiB
Text
188 lines
6 KiB
Text
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
|
|
/// Package table - stores NPM package metadata (package-level)
|
|
model Package {
|
|
id String @id @default(cuid())
|
|
|
|
// NPM Metadata
|
|
npmPackageName String @unique @map("npm_package_name") @db.VarChar(214)
|
|
npmVersion String @map("npm_version") @db.VarChar(50)
|
|
npmPublishedAt DateTime @map("npm_published_at")
|
|
npmDescription String? @map("npm_description") @db.Text
|
|
npmRepository Json? @map("npm_repository") @db.JsonB
|
|
npmHomepage String? @map("npm_homepage") @db.Text
|
|
npmLicense String? @map("npm_license") @db.VarChar(50)
|
|
npmKeywords String[] @default([]) @map("npm_keywords") @db.Text
|
|
npmReadme String? @map("npm_readme") @db.Text
|
|
npmAuthor Json? @map("npm_author") @db.JsonB
|
|
npmMaintainers Json? @map("npm_maintainers") @db.JsonB
|
|
|
|
// TPMJS Package-Level Metadata
|
|
category String @db.VarChar(50)
|
|
env Json? @db.JsonB // Environment variables (shared across tools)
|
|
frameworks String[] @default([]) @db.Text
|
|
tier String @db.VarChar(20) // 'minimal' | 'rich'
|
|
discoveryMethod String @map("discovery_method") @db.VarChar(20) // 'keyword' | 'changes-feed'
|
|
isOfficial Boolean @default(false) @map("is_official")
|
|
|
|
// Package Metrics
|
|
npmDownloadsLastMonth Int? @default(0) @map("npm_downloads_last_month")
|
|
githubStars Int? @default(0) @map("github_stars")
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
// Relations
|
|
tools Tool[]
|
|
|
|
@@index([category])
|
|
@@index([isOfficial])
|
|
@@index([npmDownloadsLastMonth])
|
|
@@index([createdAt])
|
|
@@map("packages")
|
|
}
|
|
|
|
/// Tool table - stores individual tools within packages
|
|
model Tool {
|
|
id String @id @default(cuid())
|
|
|
|
// Package Relation
|
|
packageId String @map("package_id")
|
|
package Package @relation(fields: [packageId], references: [id], onDelete: Cascade)
|
|
|
|
// Tool Identity
|
|
exportName String @map("export_name") @db.VarChar(100) // e.g., "helloWorldTool", "default"
|
|
|
|
// Tool Metadata
|
|
description String @db.Text
|
|
parameters Json? @db.JsonB
|
|
returns Json? @db.JsonB
|
|
aiAgent Json? @map("ai_agent") @db.JsonB
|
|
|
|
// Tool Metrics
|
|
qualityScore Decimal? @map("quality_score") @db.Decimal(3, 2) // 0.00 to 1.00
|
|
|
|
// Timestamps
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
// Relations
|
|
simulations Simulation[]
|
|
|
|
@@unique([packageId, exportName])
|
|
@@index([qualityScore])
|
|
@@map("tools")
|
|
}
|
|
|
|
/// Sync checkpoints - tracks progress of sync workers
|
|
model SyncCheckpoint {
|
|
id String @id @default(cuid())
|
|
|
|
source String @unique @db.VarChar(50) // 'changes-feed' | 'keyword-search' | 'metrics'
|
|
checkpoint Json @db.JsonB // Stores last sequence, timestamp, etc.
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("sync_checkpoints")
|
|
}
|
|
|
|
/// Sync logs - audit trail of sync operations
|
|
model SyncLog {
|
|
id String @id @default(cuid())
|
|
|
|
source String @db.VarChar(50) // 'changes-feed' | 'keyword-search' | 'metrics'
|
|
status String @db.VarChar(20) // 'success' | 'error' | 'partial'
|
|
processed Int @default(0) // Number of packages processed
|
|
skipped Int @default(0) // Number of packages skipped
|
|
errors Int @default(0) // Number of errors encountered
|
|
message String? @db.Text // Error message or summary
|
|
metadata Json? @db.JsonB // Additional context
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
@@index([source])
|
|
@@index([status])
|
|
@@index([createdAt])
|
|
@@map("sync_logs")
|
|
}
|
|
|
|
/// Simulations - tracks tool playground executions
|
|
model Simulation {
|
|
id String @id @default(cuid())
|
|
|
|
// Relations
|
|
toolId String @map("tool_id")
|
|
tool Tool @relation(fields: [toolId], references: [id], onDelete: Cascade)
|
|
|
|
// Request data
|
|
userPrompt String @map("user_prompt") @db.Text
|
|
parameters Json? @db.JsonB
|
|
ipAddress String? @map("ip_address") @db.VarChar(45)
|
|
userAgent String? @map("user_agent") @db.Text
|
|
|
|
// Results
|
|
status String @db.VarChar(20) // pending|running|success|error|timeout
|
|
executionTimeMs Int? @map("execution_time_ms")
|
|
output Json? @db.JsonB
|
|
error String? @db.Text
|
|
|
|
// AI metadata
|
|
agentSteps Int @default(0) @map("agent_steps")
|
|
model String? @db.VarChar(50)
|
|
|
|
// Relations
|
|
tokenUsage TokenUsage?
|
|
logs ExecutionLog[]
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
completedAt DateTime? @map("completed_at")
|
|
|
|
@@index([toolId])
|
|
@@index([status])
|
|
@@index([ipAddress, createdAt]) // For rate limiting
|
|
@@map("simulations")
|
|
}
|
|
|
|
/// Token usage - tracks token consumption per simulation
|
|
model TokenUsage {
|
|
id String @id @default(cuid())
|
|
|
|
simulationId String @unique @map("simulation_id")
|
|
simulation Simulation @relation(fields: [simulationId], references: [id], onDelete: Cascade)
|
|
|
|
inputTokens Int @default(0) @map("input_tokens")
|
|
toolDescTokens Int @default(0) @map("tool_desc_tokens")
|
|
schemaTokens Int @default(0) @map("schema_tokens")
|
|
outputTokens Int @default(0) @map("output_tokens")
|
|
totalTokens Int @default(0) @map("total_tokens")
|
|
estimatedCost Decimal? @map("estimated_cost") @db.Decimal(10, 6)
|
|
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
@@map("token_usage")
|
|
}
|
|
|
|
/// Execution logs - detailed logs for each simulation
|
|
model ExecutionLog {
|
|
id String @id @default(cuid())
|
|
|
|
simulationId String @map("simulation_id")
|
|
simulation Simulation @relation(fields: [simulationId], references: [id], onDelete: Cascade)
|
|
|
|
timestamp DateTime @default(now())
|
|
level String @db.VarChar(20) // info|warning|error|debug
|
|
event String @db.VarChar(50)
|
|
message String @db.Text
|
|
metadata Json? @db.JsonB
|
|
|
|
@@index([simulationId])
|
|
@@map("execution_logs")
|
|
}
|