shipdeck
Version:
Ship MVPs in 48 hours. Fix bugs in 30 seconds. The command deck for developers who ship.
350 lines (309 loc) • 10.5 kB
JavaScript
/**
* Ultimate Plan Pricing Logic for $599 All-Inclusive MVPs
* Implements hybrid strategy with intelligent limits and overages
*/
class UltimatePlanManager {
constructor(options = {}) {
this.planType = 'ultimate';
this.basePrice = 599;
// Included resources per MVP
this.included = {
haiku: {
tokens: Infinity, // Unlimited for low-cost operations
description: 'Unlimited drafts, validation, and simple tasks'
},
sonnet: {
tokens: 500000, // ~125 full components
description: 'Code generation and complex features'
},
opus: {
renders: 10, // Critical architecture decisions
description: 'Premium architecture and system design'
},
templates: {
access: 'full',
count: 100,
description: 'Pre-built MVP components library'
},
support: {
level: 'priority',
revisions: 2,
delivery: '48 hours'
}
};
// Overage pricing
this.overages = {
opus: {
perRender: 0.50,
bulkDiscount: 0.40 // After 20 renders
},
sonnet: {
per100kTokens: 10,
bulkDiscount: 8 // After 1M tokens
}
};
// Usage tracking
this.currentUsage = {
haiku: { tokens: 0, cost: 0 },
sonnet: { tokens: 0, cost: 0 },
opus: { renders: 0, cost: 0 },
templates: { used: [] },
totalCost: 0
};
// Quality guarantees
this.guarantees = {
deliveryHours: 48,
codeQuality: 'production-ready',
testCoverage: 80,
documentation: 'comprehensive'
};
}
/**
* Check if request is within included limits
*/
checkAllowance(modelTier, estimatedUsage) {
const result = {
allowed: true,
included: true,
overageCost: 0,
suggestion: null
};
switch(modelTier) {
case 'haiku':
// Always allowed - unlimited
result.suggestion = 'Free tier - optimize by using Haiku when possible';
break;
case 'sonnet':
const sonnetRemaining = this.included.sonnet.tokens - this.currentUsage.sonnet.tokens;
if (estimatedUsage > sonnetRemaining) {
result.included = false;
const overageTokens = estimatedUsage - sonnetRemaining;
result.overageCost = (overageTokens / 100000) * this.overages.sonnet.per100kTokens;
result.suggestion = `Would exceed Sonnet allowance. Overage: $${result.overageCost.toFixed(2)}`;
}
break;
case 'opus':
const opusRemaining = this.included.opus.renders - this.currentUsage.opus.renders;
if (opusRemaining <= 0) {
result.included = false;
result.overageCost = this.overages.opus.perRender;
result.suggestion = `Opus renders exhausted. Additional render: $${result.overageCost}`;
} else if (opusRemaining <= 2) {
result.suggestion = `Only ${opusRemaining} Opus renders remaining - use wisely`;
}
break;
}
return result;
}
/**
* Record usage after API call
*/
recordUsage(modelTier, actualUsage) {
switch(modelTier) {
case 'haiku':
this.currentUsage.haiku.tokens += actualUsage.tokens || 0;
// No cost - unlimited
break;
case 'sonnet':
this.currentUsage.sonnet.tokens += actualUsage.tokens || 0;
// Calculate overage if exceeded
const sonnetOverage = Math.max(0,
this.currentUsage.sonnet.tokens - this.included.sonnet.tokens);
if (sonnetOverage > 0) {
this.currentUsage.sonnet.cost =
(sonnetOverage / 100000) * this.overages.sonnet.per100kTokens;
}
break;
case 'opus':
this.currentUsage.opus.renders += 1;
// Calculate overage if exceeded
const opusOverage = Math.max(0,
this.currentUsage.opus.renders - this.included.opus.renders);
if (opusOverage > 0) {
this.currentUsage.opus.cost = opusOverage * this.overages.opus.perRender;
}
break;
}
// Update total cost
this.currentUsage.totalCost =
this.currentUsage.sonnet.cost + this.currentUsage.opus.cost;
}
/**
* Get intelligent routing recommendation
*/
getRoutingRecommendation(task, context = {}) {
// Template-first approach
const templateMatch = this.findTemplate(task);
if (templateMatch) {
return {
approach: 'template',
template: templateMatch,
model: 'haiku', // Templates only need Haiku for customization
estimatedSavings: '90%'
};
}
// Check cache potential
if (context.similar_requests > 0) {
return {
approach: 'cached',
model: 'cache',
estimatedSavings: '100%'
};
}
// Intelligent routing based on task criticality
const routing = {
draft: 'haiku',
implementation: 'sonnet',
architecture: 'opus'
};
// Determine task phase
const phase = this.detectTaskPhase(task);
const recommendedModel = routing[phase] || 'sonnet';
// Check allowances
const allowance = this.checkAllowance(recommendedModel, context.estimatedTokens || 1000);
// Downgrade if over allowance and not critical
if (!allowance.included && phase !== 'architecture') {
return {
approach: 'downgraded',
model: phase === 'implementation' ? 'haiku' : 'sonnet',
reason: 'Optimizing for included allowance',
originalChoice: recommendedModel
};
}
return {
approach: 'standard',
model: recommendedModel,
withinAllowance: allowance.included
};
}
/**
* Detect task phase from description
*/
detectTaskPhase(task) {
const taskLower = task.toLowerCase();
if (taskLower.includes('draft') || taskLower.includes('outline') ||
taskLower.includes('validate') || taskLower.includes('check')) {
return 'draft';
}
if (taskLower.includes('architect') || taskLower.includes('design system') ||
taskLower.includes('database') || taskLower.includes('security')) {
return 'architecture';
}
return 'implementation';
}
/**
* Find matching template
*/
findTemplate(task) {
// In production, this would search actual template library
const templates = [
{ name: 'auth-system', keywords: ['login', 'auth', 'user', 'signup'] },
{ name: 'crud-api', keywords: ['api', 'crud', 'rest', 'endpoint'] },
{ name: 'dashboard', keywords: ['dashboard', 'admin', 'analytics'] },
{ name: 'payment', keywords: ['payment', 'stripe', 'billing'] },
{ name: 'landing-page', keywords: ['landing', 'hero', 'marketing'] }
];
const taskLower = task.toLowerCase();
for (const template of templates) {
if (template.keywords.some(keyword => taskLower.includes(keyword))) {
return template;
}
}
return null;
}
/**
* Get current usage summary
*/
getUsageSummary() {
return {
plan: 'Ultimate ($599)',
included: this.included,
currentUsage: {
haiku: {
used: this.currentUsage.haiku.tokens,
limit: 'Unlimited',
percentage: 0
},
sonnet: {
used: this.currentUsage.sonnet.tokens,
limit: this.included.sonnet.tokens,
percentage: (this.currentUsage.sonnet.tokens / this.included.sonnet.tokens * 100).toFixed(1),
remaining: Math.max(0, this.included.sonnet.tokens - this.currentUsage.sonnet.tokens)
},
opus: {
used: this.currentUsage.opus.renders,
limit: this.included.opus.renders,
percentage: (this.currentUsage.opus.renders / this.included.opus.renders * 100).toFixed(1),
remaining: Math.max(0, this.included.opus.renders - this.currentUsage.opus.renders)
}
},
overageCosts: {
current: this.currentUsage.totalCost,
projected: this.projectOverageCost()
},
recommendations: this.getOptimizationTips()
};
}
/**
* Project total overage cost
*/
projectOverageCost() {
// Estimate based on current usage patterns
const usageRatio = this.currentUsage.sonnet.tokens / 100000; // Per 100k tokens
const projectedSonnetOverage = Math.max(0, usageRatio * 2 - 5) * this.overages.sonnet.per100kTokens;
const projectedOpusOverage = Math.max(0, this.currentUsage.opus.renders * 1.5 - 10) * this.overages.opus.perRender;
return projectedSonnetOverage + projectedOpusOverage;
}
/**
* Get optimization recommendations
*/
getOptimizationTips() {
const tips = [];
// Check Sonnet usage
const sonnetPercent = (this.currentUsage.sonnet.tokens / this.included.sonnet.tokens) * 100;
if (sonnetPercent > 70) {
tips.push('Consider using more templates to reduce Sonnet usage');
tips.push('Break complex features into smaller, Haiku-manageable tasks');
}
// Check Opus usage
const opusPercent = (this.currentUsage.opus.renders / this.included.opus.renders) * 100;
if (opusPercent > 80) {
tips.push('Reserve Opus for critical architecture decisions only');
tips.push('Use Sonnet for implementation details instead of Opus');
}
// General tips
if (this.currentUsage.templates.used.length < 5) {
tips.push('Leverage more templates - they\'re included and save 90% on API costs');
}
return tips;
}
/**
* Check if MVP is within guaranteed delivery time
*/
checkDeliveryGuarantee(startTime) {
const hoursElapsed = (Date.now() - startTime) / (1000 * 60 * 60);
const hoursRemaining = this.guarantees.deliveryHours - hoursElapsed;
return {
onTrack: hoursRemaining > 0,
hoursRemaining: Math.max(0, hoursRemaining),
message: hoursRemaining > 24 ?
`On track - ${hoursRemaining.toFixed(1)} hours remaining` :
hoursRemaining > 0 ?
`⚠️ Approaching deadline - ${hoursRemaining.toFixed(1)} hours remaining` :
'🔥 Deadline passed - expedite completion'
};
}
/**
* Reset usage for new MVP
*/
resetForNewMVP() {
this.currentUsage = {
haiku: { tokens: 0, cost: 0 },
sonnet: { tokens: 0, cost: 0 },
opus: { renders: 0, cost: 0 },
templates: { used: [] },
totalCost: 0
};
}
}
module.exports = { UltimatePlanManager };