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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bernierllc/ai-social-generator

v1.2.0

Published

AI-powered social media post generation service with platform-specific optimization and validation

Readme

@bernierllc/ai-social-generator

AI-powered social media post generation service with platform-specific optimization and validation.

Overview

The @bernierllc/ai-social-generator package provides a specialized service for generating social media posts from source content (blog posts, articles, etc.) with platform-specific optimization, character limits, hashtag generation, and content validation using social media content type validators.

Features

  • Multi-Platform Generation: Generate posts for Twitter, LinkedIn, Facebook, Instagram, Mastodon, and BlueSky
  • Platform-Specific Optimization: Character limits, tone, and formatting optimized for each platform
  • Content Validation: Validates generated content against platform constraints
  • Hashtag & Mention Extraction: Automatically extracts hashtags and mentions from generated content
  • Thread Generation: Automatically splits long Twitter content into threads
  • Multi-Platform Batch: Generate posts for multiple platforms in parallel
  • Uses AI Content Generator: Leverages @bernierllc/ai-content-generator for actual generation

Installation

npm install @bernierllc/ai-social-generator

Usage

import { AISocialGenerator, createAISocialGenerator } from '@bernierllc/ai-social-generator';
import { OpenAIProvider } from '@bernierllc/ai-provider-openai';

// Create AI provider
const provider = new OpenAIProvider({
  providerName: 'openai',
  apiKey: process.env.OPENAI_API_KEY!
});

// Create social generator
const generator = createAISocialGenerator({
  contentGenerator: {
    provider
  },
  enableValidation: true
});

// Generate a single post
const result = await generator.generatePost(
  'Excited to announce our new TypeScript features that improve developer productivity by 50%!',
  'twitter',
  {
    tone: 'professional',
    includeHashtags: true,
    maxHashtags: 3,
    includeEmojis: true,
    includeCTA: true,
    generateThread: false
  }
);

if (result.success) {
  console.log('Generated:', result.content);
  console.log('Hashtags:', result.hashtags);
  console.log('Mentions:', result.mentions);
  if (result.thread) {
    console.log('Thread:', result.thread);
  }
}

// Generate for multiple platforms
const multiResult = await generator.generateMultiPlatform(
  'Source content for social posts',
  ['twitter', 'linkedin', 'facebook'],
  {
    tone: 'professional',
    includeHashtags: true
  }
);

console.log(`Generated ${multiResult.successCount} of ${multiResult.totalGenerated} posts`);
for (const [platform, post] of multiResult.results) {
  if (post.success) {
    console.log(`${platform}: ${post.content}`);
  }
}

API

AISocialGenerator

Constructor

new AISocialGenerator(config: AISocialGeneratorConfig)

Config Options:

  • contentGenerator (required) - AI Content Generator configuration
    • provider (required) - AI provider instance
    • fallbackProvider (optional) - Fallback provider for failover
  • enableValidation (optional) - Enable content validation (default: true)
  • enableNeverHub (optional) - Enable NeverHub integration (default: false)

Methods

  • generatePost(sourceContent: string, platform: SocialPlatform, options?: SocialGenerationOptions): Promise<GeneratedSocialPost> - Generate a single social post
  • generateMultiPlatform(sourceContent: string, platforms: SocialPlatform[], options?: SocialGenerationOptions): Promise<MultiPlatformResult> - Generate posts for multiple platforms
  • shutdown(): void - Shutdown the generator gracefully

Social Generation Options

interface SocialGenerationOptions {
  tone?: 'professional' | 'casual' | 'humorous' | 'informative' | 'promotional';
  includeHashtags?: boolean;
  maxHashtags?: number;
  includeCTA?: boolean;
  generateThread?: boolean; // For Twitter
  includeEmojis?: boolean;
  audience?: string;
  customPrompt?: string;
}

Generated Social Post

interface GeneratedSocialPost {
  success: boolean;
  content: string;
  platform: SocialPlatform;
  characterCount: number;
  hashtags?: string[];
  mentions?: string[];
  thread?: string[]; // For Twitter threads
  metadata: {
    generatedAt: Date;
    model: string;
    tokensUsed: number;
    costUsd: number;
    durationMs: number;
  };
  error?: string;
}

Platform Specifications

| Platform | Max Length | Default Tone | |----------|-----------|--------------| | Twitter | 280 | Concise and engaging | | LinkedIn | 3000 | Professional | | Facebook | 5000 | Conversational | | Instagram | 2200 | Visual and engaging | | Mastodon | 500 | Community-focused | | BlueSky | 300 | Authentic |

Thread Generation

For Twitter, when content exceeds 280 characters and generateThread: true is set, the generator automatically splits the content into a thread:

const result = await generator.generatePost(
  'Very long content that exceeds 280 characters...',
  'twitter',
  { generateThread: true }
);

if (result.thread) {
  // result.thread is an array of tweets
  console.log(`Thread has ${result.thread.length} tweets`);
}

Content Validation

When enableValidation is true, generated content is validated against platform constraints:

  • Character Limits: Content is checked against platform-specific limits
  • Twitter Validation: Uses @bernierllc/social-media-content-type-twitter validator
  • Auto-Truncation: Content exceeding limits is automatically truncated (unless thread generation is enabled)

Integration Status

  • Logger: ✅ Integrated - Uses @bernierllc/logger for all logging operations
  • Docs-Suite: ✅ Ready - Full TypeDoc API documentation available
  • NeverHub: ⚠️ Optional - Can emit social generation events to NeverHub event bus for distributed observability

Dependencies

  • @bernierllc/ai-content-generator - Content generation service
  • @bernierllc/content-type-registry - Content type management
  • @bernierllc/social-media-content-type-* - Platform validators (6 packages)
  • @bernierllc/logger - Logging
  • @bernierllc/retry-policy - Retry logic
  • @bernierllc/neverhub-adapter - Service discovery (optional)

Testing

Run tests with:

npm test
npm run test:coverage

Target coverage: 85%+ (service package standard)

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.