tpmjs/packages/tools/createBlogPost
Ajax Davis 78c72b85f3 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
..
src feat(tools): create @tpmjs/createblogpost test tool package 2025-11-28 03:10:31 +10:00
CHANGELOG.md chore: version @tpmjs/createblogpost to 0.2.0 2025-11-28 03:17:50 +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(tools): create @tpmjs/createblogpost test tool package 2025-11-28 03:10:31 +10:00
tsconfig.json feat(tools): create @tpmjs/createblogpost test tool package 2025-11-28 03:10:31 +10:00
tsup.config.ts feat(tools): create @tpmjs/createblogpost test tool package 2025-11-28 03:10:31 +10:00

@tpmjs/createblogpost

A tool for creating structured blog posts with frontmatter and metadata. Part of the TPMJS registry.

Installation

npm install @tpmjs/createblogpost
# or
pnpm add @tpmjs/createblogpost
# or
yarn add @tpmjs/createblogpost

Usage

import { createBlogPost } from '@tpmjs/createblogpost';

const post = await createBlogPost({
  title: 'Getting Started with TypeScript',
  author: 'John Doe',
  content: 'TypeScript is a typed superset of JavaScript that compiles to plain JavaScript...',
  tags: ['typescript', 'javascript', 'programming'],
  excerpt: 'Learn the basics of TypeScript in this comprehensive guide',
  format: 'markdown',
});

console.log(post.formattedOutput);

API

createBlogPost(options: BlogPostOptions): Promise<BlogPost>

Creates a structured blog post with frontmatter and metadata.

Options

Parameter Type Required Default Description
title string Yes - The title of the blog post
author string Yes - The author of the blog post
content string Yes - The main content of the blog post
tags string[] No [] Array of tags for categorization
format 'markdown' | 'mdx' No 'markdown' Output format for the blog post
excerpt string No - Short excerpt or summary of the post
publishDate Date No new Date() Publication date

Returns

Returns a BlogPost object with the following structure:

{
  frontmatter: {
    title: string;
    author: string;
    date: string;        // ISO date format (YYYY-MM-DD)
    tags: string[];
    slug: string;        // Auto-generated from title
    wordCount: number;   // Calculated from content
    readingTime: number; // Estimated minutes to read
    excerpt?: string;
  };
  content: string;
  formattedOutput: string; // Complete post with frontmatter
}

Example Output

---
title: "Getting Started with TypeScript"
author: John Doe
date: 2025-11-28
slug: getting-started-with-typescript
tags: ["typescript", "javascript", "programming"]
excerpt: "Learn the basics of TypeScript in this comprehensive guide"
wordCount: 250
readingTime: 2
---

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript...

Features

  • Automatic slug generation from title
  • Word count calculation
  • Reading time estimation (200 words/min)
  • Support for both Markdown and MDX formats
  • Customizable frontmatter
  • SEO-friendly metadata

Use Cases

  • Static site generators (Next.js, Gatsby, Astro)
  • Content management systems
  • Blog platforms
  • Documentation sites
  • Automated content generation

License

MIT