npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bernierllc/content-workflow-ai-generate-step

v0.1.5

Published

AI-powered content generation workflow step for creating blog posts and social media content

Downloads

495

Readme

@bernierllc/content-workflow-ai-generate-step

AI-powered content generation workflow step for creating blog posts, social media content, and email campaigns.

Features

  • Multi-Format Generation: Generate blog posts, social media content, and email campaigns
  • AI Provider Support: Works with OpenAI, Anthropic, Google, and auto-selection
  • Platform-Specific Social: Generate content for Twitter, LinkedIn, Facebook, Instagram, etc.
  • Custom Prompts: Use default prompts or provide your own
  • Cost Tracking: Track token usage and estimated costs per generation
  • Smart Parsing: Automatically extract titles, excerpts, and structured content
  • Workflow Integration: Implements BaseWorkflowStep interface for seamless integration

Installation

npm install @bernierllc/content-workflow-ai-generate-step

Dependencies

This package requires:

  • @bernierllc/ai-content-generator - Core AI content generation
  • @bernierllc/ai-social-generator - Social media content generation
  • @bernierllc/logger - Structured logging

Usage

Basic Setup

import { AIGenerateStep } from '@bernierllc/content-workflow-ai-generate-step';
import { AIContentGenerator } from '@bernierllc/ai-content-generator';
import { AISocialGenerator } from '@bernierllc/ai-social-generator';

// Create AI generators
const contentGenerator = new AIContentGenerator({
  provider: aiProvider,
  defaultTemperature: 0.7
});

const socialGenerator = new AISocialGenerator({
  contentGenerator: {
    provider: aiProvider
  }
});

// Create workflow step
const generateStep = new AIGenerateStep(
  contentGenerator,
  socialGenerator,
  logger
);

Generate Blog Post

const config = {
  id: 'generate-blog',
  name: 'Generate Blog Post',
  type: 'ai_generate',
  enabled: true,
  order: 0,
  aiConfig: {
    contentType: 'blog',
    provider: 'openai',
    options: {
      tone: 'professional',
      targetLength: 1500,
      includeHashtags: false
    }
  }
};

const context = {
  content: {
    id: 'content-1',
    title: 'Getting Started with AI',
    body: 'AI is transforming software development...'
  },
  user: { id: 'user-1' },
  variables: new Map(),
  stepOutputs: new Map()
};

const result = await generateStep.execute(config, context);

if (result.success) {
  console.log('Generated blog post:', result.data.generatedContent.title);
  console.log('Tokens used:', result.data.tokensUsed);
  console.log('Cost:', `$${result.data.costUsd.toFixed(4)}`);
}

Generate Social Media Content

const config = {
  id: 'generate-social',
  name: 'Generate Social Posts',
  type: 'ai_generate',
  enabled: true,
  order: 0,
  aiConfig: {
    contentType: 'social',
    platforms: ['twitter', 'linkedin', 'facebook'],
    options: {
      tone: 'casual',
      includeHashtags: true,
      includeCTA: true
    }
  }
};

const result = await generateStep.execute(config, context);

if (result.success) {
  console.log('Generated for platforms:', result.data.platforms);
  console.log('Social content:', result.data.generatedContent.body);
}

Generate Email Campaign

const config = {
  id: 'generate-email',
  name: 'Generate Email',
  type: 'ai_generate',
  enabled: true,
  order: 0,
  aiConfig: {
    contentType: 'email',
    options: {
      includeCTA: true,
      tone: 'friendly',
      audience: 'subscribers'
    }
  }
};

const result = await generateStep.execute(config, context);

if (result.success) {
  console.log('Subject:', result.data.generatedContent.title);
  console.log('Preheader:', result.data.generatedContent.excerpt);
  console.log('Body:', result.data.generatedContent.body);
}

Custom Prompts

const config = {
  id: 'generate-custom',
  name: 'Generate with Custom Prompt',
  type: 'ai_generate',
  enabled: true,
  order: 0,
  aiConfig: {
    contentType: 'blog',
    prompt: `Create a detailed technical blog post covering:
      - Architecture decisions
      - Implementation details
      - Performance considerations
      - Best practices`,
    options: {
      tone: 'technical',
      audience: 'senior developers',
      targetLength: 2000
    }
  }
};

API Reference

AIGenerateStep

Main workflow step class for AI content generation.

Properties

  • id: string - Step identifier ('ai-generate-step')
  • type: string - Step type ('ai_generate')

Methods

execute(config, context)

Execute the content generation step.

Parameters:

  • config: WorkflowStepConfig - Step configuration
  • context: WorkflowContext - Workflow execution context

Returns: Promise<WorkflowStepExecutionResult>

validate(config)

Validate step configuration.

Parameters:

  • config: WorkflowStepConfig - Configuration to validate

Returns: ValidationResult

getRequirements()

Get step requirements (permissions and dependencies).

Returns: StepRequirements

canSkip(context)

Check if step can be skipped based on context.

Parameters:

  • context: WorkflowContext - Workflow context

Returns: boolean

Types

AIGenerateResult

Result from AI content generation.

interface AIGenerateResult {
  contentType: 'blog' | 'social' | 'email';
  generatedContent: {
    title?: string;
    body: string;
    excerpt?: string;
    metadata?: Record<string, any>;
  };
  platforms?: string[];
  provider: string;
  model: string;
  tokensUsed: number;
  costUsd: number;
}

AIGenerateConfig

Configuration for AI generation.

interface AIGenerateConfig {
  contentType: 'blog' | 'social' | 'email';
  prompt?: string;
  provider?: 'auto' | 'openai' | 'anthropic' | 'google';
  platforms?: string[];
  options?: {
    tone?: string;
    audience?: string;
    includeHashtags?: boolean;
    includeCTA?: boolean;
    targetLength?: number;
  };
}

Prompt Templates

The package includes default prompts for each content type:

Blog Prompt

Generates comprehensive blog posts with:

  • Engaging title
  • Clear structure with sections
  • Professional yet approachable tone
  • Key takeaways in conclusion

Social Prompt

Generates platform-specific social posts with:

  • Platform-appropriate tone and style
  • Character limit compliance
  • Relevant hashtags
  • Clear calls-to-action

Email Prompt

Generates complete email campaigns with:

  • Attention-grabbing subject line
  • Engaging preheader text
  • Clear and concise body
  • Strong call-to-action

Custom Prompts

You can override default prompts:

import { createGenerationPrompt } from '@bernierllc/content-workflow-ai-generate-step';

const prompt = createGenerationPrompt(
  'blog',
  sourceContent,
  'Your custom prompt here',
  { tone: 'casual', targetLength: 1000 }
);

Cost Estimation

The step automatically estimates costs based on:

  • Token usage
  • AI model used
  • Current pricing rates

Example cost estimates (per 1K tokens):

  • GPT-4: ~$0.045
  • GPT-3.5: ~$0.002
  • Claude 3 Opus: ~$0.0375
  • Claude 3 Sonnet: ~$0.006
  • Claude 3 Haiku: ~$0.0005
  • Gemini Pro: ~$0.00025

Error Handling

The step handles various error scenarios:

const result = await generateStep.execute(config, context);

if (!result.success) {
  console.error('Generation failed:', result.error);
  // Handle error appropriately
}

Common errors:

  • Missing AI configuration
  • Invalid content type
  • Invalid AI provider
  • AI generation failure
  • Unsupported content type

Validation

Validate configuration before execution:

const validation = generateStep.validate(config);

if (!validation.valid) {
  console.error('Invalid configuration:', validation.errors);
}

Validation checks:

  • Required fields (id, name, type, order)
  • AI config presence
  • Valid content type
  • Valid AI provider

Skip Logic

The step can be skipped if content already has AI-generated content:

const context = {
  content: {
    id: 'content-1',
    metadata: { aiGenerated: true }
  },
  // ... other context fields
};

if (generateStep.canSkip(context)) {
  console.log('Skipping - content already AI-generated');
}

License

Copyright (c) 2025 Bernier LLC

This file is licensed to the client under a limited-use license. The client may use and modify this code only within the scope of the project it was delivered for. Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.