tpmjs/packages/db
Ajax Davis a92c2c250c feat: upgrade to AI SDK v6 beta and Zod v4 to fix tool schema errors
OpenAI was rejecting tool definitions with error "schema must be a JSON Schema of 'type: "object"'". This was caused by AI SDK v5 not properly converting Zod schemas to JSON Schema format.

**Changes:**
- Upgrade AI SDK from v5.0.104 to v6.0.0-beta.124
- Upgrade @ai-sdk/openai from v2.0.74 to v3.0.0-beta.22
- Upgrade Zod from v3.25.76 to v4.1.13 across all packages

**AI SDK v6 breaking changes:**
- Tool definition API: `parameters` renamed to `inputSchema`
- Removed `aiTool()` wrapper - use plain object with description, inputSchema, execute
- Streaming API: Use `textStream` async iterator instead of onChunk callback
- Zod schemas now properly converted to JSON Schema for OpenAI

**Zod v4 breaking changes:**
- `z.record()` now requires two arguments: `z.record(keySchema, valueSchema)`
- `z.enum()` params changed: `errorMap` removed, use `message` instead
- Type system improvements require explicit type parameters
- Fixed type errors in @tpmjs/env, @tpmjs/npm-client, @tpmjs/types

**Files changed:**
- apps/web/src/lib/ai-agent/tool-executor-agent.ts
  - Updated tool definition to use `inputSchema` instead of `parameters`
  - Removed `aiTool()` wrapper
  - Fixed streaming to use `textStream` iterator
- packages/env/src/index.ts
  - Updated type constraint from `z.ZodRawShape` to `Record<string, z.ZodTypeAny>`
- packages/npm-client/src/package.ts
  - Fixed `z.record()` calls to include both key and value schemas
  - Added type assertions for record indexing
- packages/types/src/tpmjs.ts
  - Changed `errorMap` to `message` in z.enum() calls

**Testing:**
-  Type-check passes
-  Production build succeeds
-  All routes compile correctly

This fixes the tool execution error where OpenAI rejected tool schemas with invalid format.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 19:14:01 +10:00
..
prisma feat: add interactive tool playground with AI-powered execution 2025-11-30 00:36:05 +10:00
src feat(db): create database package with Prisma schema for NPM registry 2025-11-28 02:07:39 +10:00
.env.example feat(db): create database package with Prisma schema for NPM registry 2025-11-28 02:07:39 +10:00
check-tool.js fix: update API route to use catch-all pattern for clean URLs 2025-11-29 22:57:54 +10:00
check-tool.mjs fix: update dependency cruiser config to allow TypeScript path aliases and workspace packages 2025-11-30 01:55:51 +10:00
package.json feat: upgrade to AI SDK v6 beta and Zod v4 to fix tool schema errors 2025-11-30 19:14:01 +10:00
README.md feat(db): create database package with Prisma schema for NPM registry 2025-11-28 02:07:39 +10:00
sync-single-tool.mjs fix: update dependency cruiser config to allow TypeScript path aliases and workspace packages 2025-11-30 01:55:51 +10:00
test-query.mjs fix(ci): skip lefthook install when .git directory missing 2025-11-29 13:51:05 +10:00
tsconfig.json feat(db): create database package with Prisma schema for NPM registry 2025-11-28 02:07:39 +10:00

@tpmjs/db

Database package for TPMJS NPM Registry. Provides Prisma ORM setup and database client for storing tool metadata.

Setup

1. Create Neon Database

  1. Go to https://neon.tech/
  2. Create a new project
  3. Copy the connection string

2. Configure Environment

cp .env.example .env
# Edit .env and add your DATABASE_URL

3. Run Migrations

pnpm db:migrate
pnpm db:seed

Usage

import { prisma } from '@tpmjs/db';

// Query tools
const tools = await prisma.tool.findMany({
  where: {
    category: 'web-scraping',
    isOfficial: true,
  },
  orderBy: {
    qualityScore: 'desc',
  },
  take: 10,
});

// Update sync checkpoint
await prisma.syncCheckpoint.update({
  where: { source: 'changes-feed' },
  data: {
    checkpoint: {
      sequence: '12345',
      lastProcessed: new Date().toISOString(),
    },
  },
});

Scripts

  • pnpm db:generate - Generate Prisma client
  • pnpm db:push - Push schema to database (for development)
  • pnpm db:migrate - Create and run migrations (for production)
  • pnpm db:studio - Open Prisma Studio GUI
  • pnpm db:seed - Seed initial data

Schema

Tool

Stores NPM packages with TPMJS metadata from their package.json.

SyncCheckpoint

Tracks progress of sync workers (changes feed, keyword search, metrics).

SyncLog

Audit trail of all sync operations.