Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

4.0 KB
Raw Blame
import type { StoryData } from './story-data';

// Deep link generator for story sharing
export function generateStoryDeepLink(
  countryCode: string,
  type: 'ciianalysis' | 'convergence' | 'brief' = 'ciianalysis',
  score?: number,
  level?: string
): string {
  const params = new URLSearchParams({
    c: countryCode,
    t: type,
    ts: Date.now().toString()
  });
  if (score !== undefined) params.set('s', String(score));
  if (level) params.set('l', level);
  return `https://three.ws/api/story?${params.toString()}`;
}

// Parse deep link parameters
export function parseStoryParams(url: URL): { countryCode: string; type: string } | null {
  const countryCode = url.searchParams.get('c');
  if (!countryCode) return null;
  return {
    countryCode,
    type: url.searchParams.get('t') || 'ciianalysis'
  };
}

// Convert 2-letter country code to flag emoji
function countryFlag(code: string): string {
  const upper = code.toUpperCase();
  if (upper.length !== 2) return '';
  return String.fromCodePoint(
    0x1F1E6 + upper.charCodeAt(0) - 65,
    0x1F1E6 + upper.charCodeAt(1) - 65
  );
}

// Share text templates for different platforms
export const shareTexts = {
  twitter: (data: StoryData) =>
    `${countryFlag(data.countryCode)} ${data.countryName} DeFi Brief\n\n` +
    `Instability: ${data.cii?.score || 'N/A'}/100 (${data.cii?.level || 'N/A'})\n` +
    `${data.threats.critical > 0 ? `⚠️ ${data.threats.critical} critical threats\n` : ''}` +
    `\nGenerated by @trythreews`,

  whatsapp: (data: StoryData) =>
    `${countryFlag(data.countryCode)} *${data.countryName} DeFi Brief*\n\n` +
    `*Instability:* ${data.cii?.score || 'N/A'}/100 (${data.cii?.level || 'N/A'})\n` +
    `*Trend:* ${data.cii?.trend || 'stable'}\n` +
    `${data.threats.critical > 0 ? `*⚠️ Critical:* ${data.threats.critical}\n` : ''}` +
    `${data.threats.high > 0 ? `*🔴 High:* ${data.threats.high}\n` : ''}` +
    `\n📊 View full analysis: ${generateStoryDeepLink(data.countryCode, 'ciianalysis', data.cii?.score, data.cii?.level)}`,

  linkedin: (data: StoryData) =>
    `DeFi Update: ${data.countryName}\n\n` +
    `Real-time instability assessment:\n` +
    `• Score: ${data.cii?.score || 'N/A'}/100 (${data.cii?.level || 'N/A'})\n` +
    `• 24h change: ${data.cii?.change24h ? (data.cii.change24h > 0 ? '+' : '') + data.cii.change24h : 'N/A'}%\n` +
    `${data.threats.critical > 0 ? `• Critical threats: ${data.threats.critical}\n` : ''}` +
    `\nData via three.ws HQ - Open source market intelligence`,

  telegram: (data: StoryData) =>
    `${countryFlag(data.countryCode)} *${data.countryName} DeFi Analysis*\n\n` +
    `📊 Instability: *${data.cii?.score || 'N/A'}/100* (${data.cii?.level || 'N/A'})\n` +
    `📈 Trend: *${data.cii?.trend || 'stable'}*\n` +
    `${data.cii?.change24h ? `📉 24h: *${data.cii.change24h > 0 ? '+' : ''}${data.cii.change24h}*\n` : ''}` +
    `${data.threats.critical > 0 ? `🚨 Critical: *${data.threats.critical}*\n` : ''}` +
    `${data.threats.high > 0 ? `🔴 High: *${data.threats.high}*\n` : ''}` +
    `\n🔗 ${generateStoryDeepLink(data.countryCode, 'ciianalysis', data.cii?.score, data.cii?.level)}`
};

// Pre-generated share URLs
export function getShareUrls(data: StoryData): Record<string, string> {
  const url = generateStoryDeepLink(data.countryCode, 'ciianalysis', data.cii?.score, data.cii?.level);
  const text = encodeURIComponent(shareTexts.twitter(data));
  
  return {
    twitter: `https://twitter.com/intent/tweet?text=${text}&url=${encodeURIComponent(url)}`,
    linkedin: `https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(url)}`,
    reddit: `https://reddit.com/submit?url=${encodeURIComponent(url)}&title=${encodeURIComponent(`${data.countryName} DeFi Brief - HQ`)}`,
    facebook: `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url)}`,
    whatsapp: `https://wa.me/?text=${encodeURIComponent(shareTexts.whatsapp(data).replace('\n', '%0A'))}`,
    telegram: `https://t.me/share/url?url=${encodeURIComponent(url)}&text=${encodeURIComponent(shareTexts.telegram(data).replace('\n', '%0A'))}`,
  };
}