@bernierllc/content-workflow-ai-rewrite-step
v0.3.0
Published
AI-powered content rewriting workflow step for transforming technical to readable content
Readme
@bernierllc/content-workflow-ai-rewrite-step
AI-powered content rewriting workflow step for transforming technical to readable content.
Features
- Transform technical commit messages into readable blog content
- Rewrite text for different tones and audiences
- Improve clarity and engagement
- Track changes made during rewriting
- Support for long-form content with automatic chunking
- Optional NeverHub integration for event tracking
- Intelligent AI provider routing with cost optimization
Installation
npm install @bernierllc/content-workflow-ai-rewrite-stepUsage
Basic Usage
import { AIRewriteStep } from '@bernierllc/content-workflow-ai-rewrite-step';
// Create the step
const rewriteStep = new AIRewriteStep();
// Initialize (optional, enables NeverHub if available)
await rewriteStep.initialize();
// Execute the rewrite
const result = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: 'Rewrite this for a general audience'
}
},
{
content: {
id: 'content-123',
body: 'Complex technical content here...'
},
workflowId: 'workflow-456'
}
);
if (result.success && result.data) {
console.log('Original:', result.data.originalText);
console.log('Rewritten:', result.data.rewrittenText);
console.log('Changes:', result.data.changes);
console.log('Cost:', result.data.costUsd);
}Custom AI Configuration
const result = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: 'Make this sound professional and authoritative',
provider: 'anthropic',
model: 'claude-3-sonnet',
maxTokens: 2000,
temperature: 0.7,
maxChunkSize: 5000
}
},
context
);With Custom Router and Logger
import { AIRewriteStep } from '@bernierllc/content-workflow-ai-rewrite-step';
import { AIProviderRouter } from '@bernierllc/ai-provider-router';
import { createLogger } from '@bernierllc/logger';
const router = new AIProviderRouter({
providers: [
{
name: 'openai',
priority: 1,
enabled: true,
costPer1kTokens: 0.002
},
{
name: 'anthropic',
priority: 2,
enabled: true,
costPer1kTokens: 0.003
}
],
strategy: 'least-cost'
});
const logger = createLogger({ level: 2 });
const rewriteStep = new AIRewriteStep({ router, logger });API Reference
AIRewriteStep
Main class implementing the AI rewrite workflow step.
Constructor Options
interface AIRewriteStepOptions {
router?: AIProviderRouter;
logger?: Logger;
neverhub?: NeverHubAdapter;
}Methods
initialize(): Promise<void>
Initialize the step and auto-detect NeverHub if available.
execute(config, context): Promise<WorkflowStepExecutionResult>
Execute the rewrite operation.
Parameters:
config: WorkflowStepConfig- Step configurationcontext: WorkflowContext- Workflow execution context
Returns: WorkflowStepExecutionResult with rewrite data
ChangeTracker
Utility class for tracking and analyzing changes.
import { ChangeTracker } from '@bernierllc/content-workflow-ai-rewrite-step';
const tracker = new ChangeTracker();
tracker.addChange('tone', 'Changed to conversational');
tracker.addChange('clarity', 'Simplified technical terms');
console.log(tracker.getChanges());
console.log(tracker.getChangeCountByType('tone'));
console.log(tracker.hasChanges());Static Methods
analyzeChanges(explanation: string): RewriteChange[]
Extract changes from AI's explanation text.
compareTexts(original: string, rewritten: string): TextDifference
Compare two texts and identify basic differences.
Types
AIRewriteResult
interface AIRewriteResult {
originalText: string;
rewrittenText: string;
changes: RewriteChange[];
provider: string;
model: string;
tokensUsed: number;
costUsd: number;
}RewriteChange
interface RewriteChange {
type: 'tone' | 'clarity' | 'audience' | 'technical';
description: string;
}AIRewriteConfig
interface AIRewriteConfig {
prompt?: string;
provider?: string;
model?: string;
maxTokens?: number;
temperature?: number;
maxChunkSize?: number;
}Examples
Transform Technical Commit to Blog Post
const result = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: `Transform this git commit message into an engaging blog post.
Make it readable for non-technical audiences while preserving key information.`
}
},
{
content: {
id: 'commit-123',
body: `feat(auth): implement JWT-based authentication with refresh tokens
- Added JWT token generation with RS256 signing
- Implemented refresh token rotation strategy
- Added token revocation via Redis blacklist`
},
workflowId: 'blog-workflow'
}
);Adjust Tone for Different Audiences
// For technical audience
const technicalResult = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: 'Rewrite this for a technical audience. Use precise terminology.'
}
},
context
);
// For general audience
const generalResult = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: 'Rewrite this for a general audience. Avoid jargon and simplify concepts.'
}
},
context
);Handle Long-Form Content
// Content longer than maxChunkSize will be automatically split
const longContentResult = await rewriteStep.execute(
{
id: 'ai-rewrite-step',
aiConfig: {
prompt: 'Improve clarity and engagement',
maxChunkSize: 4000 // Characters per chunk
}
},
{
content: {
id: 'article-123',
body: veryLongArticleText // 20,000+ characters
},
workflowId: 'editorial-workflow'
}
);NeverHub Integration
When NeverHub is available, the step automatically:
- Registers as a workflow step service
- Emits
ai.rewrite.completedevents on success - Emits
ai.rewrite.failedevents on error
Events include metadata like provider, cost, tokens used, and change count.
Error Handling
const result = await rewriteStep.execute(config, context);
if (!result.success) {
console.error('Rewrite failed:', result.error);
console.log('Metadata:', result.metadata);
}Performance Considerations
- Chunking: Long content is automatically split to respect AI provider token limits
- Cost Tracking: All operations track tokens used and estimated cost
- Provider Selection: Use
provider: 'auto'for automatic cost-optimized routing - Caching: Consider caching results for identical inputs (implement externally)
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.
