AI Resource Pro / website / scripts / fix-tutorial-content.js
| 1 | import dotenv from 'dotenv'; |
| 2 | import { createClient } from '@supabase/supabase-js'; |
| 3 | |
| 4 | dotenv.config({ path: '.env' }); |
| 5 | |
| 6 | const BATCH_SIZE = 10; |
| 7 | const SKIP_IDS = new Set([690]); |
| 8 | |
| 9 | const TOOL_FACTS = { |
| 10 | 672: { category: 'llm_model', action: 'deploy open-source LLMs for reasoning, coding, and chat use cases' }, |
| 11 | 673: { category: 'assistant_chat', action: 'draft, analyze, and automate everyday knowledge work with a general AI assistant' }, |
| 12 | 674: { category: 'assistant_chat', action: 'run high-quality reasoning, writing, and coding tasks with a safety-focused AI assistant' }, |
| 13 | 675: { category: 'llm_platform', action: 'prototype and test Gemini model prompts before building production features' }, |
| 14 | 676: { category: 'agent_framework', action: 'orchestrate multiple AI agents with roles, memory, and shared goals' }, |
| 15 | 677: { category: 'llm_platform', action: 'explore Google AI products, research, and model capabilities in one ecosystem' }, |
| 16 | 678: { category: 'automation', action: 'automate multi-step workflows across apps with flexible no-code and self-hosted control' }, |
| 17 | 680: { category: 'automation', action: 'build visual app integrations and business automations without writing code' }, |
| 18 | 681: { category: 'agent_framework', action: 'experiment with autonomous goal-driven AI agents for complex task execution' }, |
| 19 | 682: { category: 'automation', action: 'design AI-powered workflows for prompt operations, evaluation, and process automation' }, |
| 20 | 683: { category: 'automation', action: 'connect cloud apps and automate repetitive operations with simple trigger-action flows' }, |
| 21 | 684: { category: 'automation', action: 'set up simple personal and smart-home automations using if-this-then-that rules' }, |
| 22 | 685: { category: 'automation', action: 'run private local smart-home automations with broad device integration' }, |
| 23 | 686: { category: 'automation', action: 'automate business processes and approvals with a low-code workflow platform' }, |
| 24 | 687: { category: 'agent_framework', action: 'build LLM chains and agent workflows with a drag-and-drop interface' }, |
| 25 | 688: { category: 'agent_framework', action: 'build and deploy LLM applications with prompt, model, and workflow controls' }, |
| 26 | 689: { category: 'agent_framework', action: 'create AI workforces and semantic workflows for business operations' }, |
| 27 | 690: { category: 'assistant_chat', action: 'use Google Gemini for multimodal chat, reasoning, and productivity tasks' }, |
| 28 | 691: { category: 'agent_framework', action: 'develop production LLM applications with chains, tools, and retrieval patterns' }, |
| 29 | 692: { category: 'agent_framework', action: 'define structured task flows for multi-agent CrewAI systems' }, |
| 30 | 693: { category: 'agent_framework', action: 'integrate AI orchestration into enterprise apps using Microsoft Semantic Kernel' }, |
| 31 | 694: { category: 'agent_framework', action: 'add streaming chat and AI interactions to web apps with a frontend-first SDK' }, |
| 32 | 695: { category: 'llm_model', action: 'run a strong open Meta model for local reasoning and coding workloads' }, |
| 33 | 696: { category: 'research', action: 'research questions with cited answers from web sources in one interface' }, |
| 34 | 697: { category: 'productivity', action: 'write, summarize, and organize workspace content directly inside Notion' }, |
| 35 | 698: { category: 'video', action: 'generate cinematic AI video clips from text or image prompts' }, |
| 36 | 699: { category: 'video', action: 'edit audio and video by editing transcript text with AI cleanup tools' }, |
| 37 | 700: { category: 'image', action: 'generate high-quality AI artwork from text prompts with strong style control' }, |
| 38 | 701: { category: 'coding', action: 'write and refactor code faster with inline AI suggestions in your IDE' }, |
| 39 | 702: { category: 'coding', action: 'get AI code completion with privacy-focused deployment options for teams' }, |
| 40 | 703: { category: 'coding', action: 'speed up coding tasks with AI-assisted generation and refactoring workflows' }, |
| 41 | 771: { category: 'coding', action: 'build and refactor full codebases inside an AI-native editor' }, |
| 42 | 772: { category: 'coding', action: 'prompt your way to full-stack web apps and deploy directly from the browser' }, |
| 43 | 773: { category: 'coding', action: 'use an AI-first IDE to plan and execute multi-step coding tasks' }, |
| 44 | 774: { category: 'coding', action: 'generate production-ready React and Next.js UI components from prompts' }, |
| 45 | 775: { category: 'audio', action: 'create full songs with vocals and instrumentation from text prompts' }, |
| 46 | 776: { category: 'audio', action: 'clone voices and generate natural speech for content and products' }, |
| 47 | 777: { category: 'coding', action: 'generate full-stack app scaffolds from plain-language product ideas' }, |
| 48 | 778: { category: 'coding', action: 'delegate coding tasks to an autonomous cloud development agent' }, |
| 49 | 779: { category: 'video', action: 'create and edit AI video scenes from text and image inputs' }, |
| 50 | 780: { category: 'image', action: 'generate AI images with reliable text rendering for creative assets' }, |
| 51 | 781: { category: 'writing', action: 'produce on-brand marketing copy and campaign assets at scale' }, |
| 52 | 782: { category: 'writing', action: 'automate go-to-market writing and outbound content workflows' }, |
| 53 | 783: { category: 'meeting', action: 'transcribe meetings and generate searchable notes and summaries automatically' }, |
| 54 | 784: { category: 'presentation', action: 'turn ideas and notes into polished presentations and docs quickly' }, |
| 55 | 785: { category: 'video', action: 'create AI avatar videos for training, marketing, and internal communication' }, |
| 56 | 786: { category: 'assistant_chat', action: 'build and chat with persona-based AI characters for entertainment and roleplay' }, |
| 57 | 787: { category: 'ml_data', action: 'discover, share, and deploy open machine learning models and datasets' }, |
| 58 | 788: { category: 'llm_platform', action: 'build enterprise NLP and RAG applications with production APIs' }, |
| 59 | 789: { category: 'llm_model', action: 'use efficient open and commercial language models for production AI systems' }, |
| 60 | 790: { category: 'writing', action: 'improve writing quality, tone, and clarity across emails and documents' }, |
| 61 | 791: { category: 'coding', action: 'run an agentic coding assistant in the terminal for end-to-end code changes' }, |
| 62 | 792: { category: 'agent_framework', action: 'run a persistent personal AI agent connected to messaging and tools' }, |
| 63 | 793: { category: 'image', action: 'design social graphics, documents, and assets using built-in AI tools' }, |
| 64 | 794: { category: 'presentation', action: 'build business presentations with automatic layout and design logic' }, |
| 65 | 795: { category: 'meeting', action: 'capture meeting transcripts, summaries, and action items automatically' }, |
| 66 | 796: { category: 'sales_support', action: 'analyze sales conversations to improve pipeline quality and coaching' }, |
| 67 | 797: { category: 'sales_support', action: 'automate customer support conversations with an AI service agent' }, |
| 68 | 798: { category: 'audio', action: 'compose royalty-friendly music tracks for videos, games, and media projects' }, |
| 69 | 799: { category: 'writing', action: 'optimize articles for search rankings using data-driven SEO guidance' }, |
| 70 | 800: { category: 'writing', action: 'plan content strategy and topic clusters for long-term organic growth' }, |
| 71 | 801: { category: 'health', action: 'assess symptoms and triage potential care paths with an AI health assistant' }, |
| 72 | 802: { category: 'video', action: 'record async video messages with automatic transcripts and summaries' }, |
| 73 | 803: { category: 'meeting', action: 'capture voice notes and convert them into transcribed, summarized notes' }, |
| 74 | 806: { category: 'writing', action: 'generate and schedule social content from trending topics in your niche' }, |
| 75 | 807: { category: 'llm_model', action: 'use a large open model with multi-agent reasoning for advanced tasks' }, |
| 76 | 808: { category: 'coding', action: 'delegate coding, refactoring, and code review tasks to an AI coding agent' }, |
| 77 | 809: { category: 'assistant_chat', action: 'chat with a real-time assistant integrated with the X ecosystem' }, |
| 78 | 810: { category: 'llm_model', action: 'run bilingual English-Chinese language models for production AI apps' }, |
| 79 | 811: { category: 'llm_model', action: 'build long-context applications with a hybrid-architecture language model' }, |
| 80 | 812: { category: 'llm_model', action: 'build with Alibaba open-weight multilingual models for reasoning and coding' }, |
| 81 | 813: { category: 'llm_platform', action: 'deploy foundation models through AWS Bedrock with enterprise controls' }, |
| 82 | 814: { category: 'llm_model', action: 'run an enterprise-ready open MoE model for data-heavy AI workloads' }, |
| 83 | 815: { category: 'assistant_chat', action: 'use an empathetic personal AI assistant for everyday conversations' }, |
| 84 | 816: { category: 'llm_model', action: 'deploy compact language models for efficient on-device AI applications' }, |
| 85 | 817: { category: 'llm_model', action: 'build multimodal applications across text, image, audio, and video inputs' }, |
| 86 | 818: { category: 'llm_model', action: 'work with open-source language models for lightweight text generation tasks' }, |
| 87 | 819: { category: 'writing', action: 'generate compliant enterprise content with business-tuned language models' }, |
| 88 | 820: { category: 'llm_model', action: 'build bilingual applications on China-focused GLM model families' }, |
| 89 | 821: { category: 'coding', action: 'assign software engineering tasks to an autonomous AI developer' }, |
| 90 | 822: { category: 'coding', action: 'pair program from the terminal with AI-assisted git-aware code edits' }, |
| 91 | 823: { category: 'coding', action: 'embed an open-source AI coding assistant directly in your IDE' }, |
| 92 | 824: { category: 'coding', action: 'use fast AI autocomplete and code chat across many IDEs for free' }, |
| 93 | 825: { category: 'coding', action: 'accelerate AWS development with AI coding help and cloud-specific guidance' }, |
| 94 | 826: { category: 'coding', action: 'ask codebase-aware questions and edits with repository graph context' }, |
| 95 | 827: { category: 'image', action: 'generate production-quality images, assets, and textures for creative work' }, |
| 96 | 828: { category: 'image', action: 'create and remix AI images on a mixed-image editing canvas' }, |
| 97 | 829: { category: 'image', action: 'edit images with AI tools for cleanup, relighting, and background removal' }, |
| 98 | 830: { category: 'image', action: 'iterate on AI images in real time from prompts and sketches' }, |
| 99 | 831: { category: 'image', action: 'generate photorealistic images with a modern open model family' }, |
| 100 | 832: { category: 'image', action: 'create prompt-faithful images with OpenAI’s latest image generation model' }, |
| 101 | 833: { category: 'video', action: 'produce talking-avatar videos with translation and voice cloning' }, |
| 102 | 834: { category: 'video', action: 'turn still photos into talking-head videos from scripts or audio' }, |
| 103 | 835: { category: 'video', action: 'repurpose long videos into short-form social clips automatically' }, |
| 104 | 836: { category: 'video', action: 'generate AI videos and 3D captures for immersive visual storytelling' }, |
| 105 | 837: { category: 'video', action: 'generate longer-form AI videos with strong motion consistency' }, |
| 106 | 838: { category: 'video', action: 'generate complete social videos from a single text brief' }, |
| 107 | 839: { category: 'productivity', action: 'capture notes and retrieve context with AI-powered knowledge organization' }, |
| 108 | 840: { category: 'writing', action: 'write SEO articles, ads, and marketing content with AI workflows' }, |
| 109 | 841: { category: 'writing', action: 'generate low-cost marketing and business copy across common use cases' }, |
| 110 | 842: { category: 'presentation', action: 'build narrative decks and story-driven presentations from prompts' }, |
| 111 | 843: { category: 'productivity', action: 'manage projects with AI agents, docs, and task automation in one workspace' }, |
| 112 | 844: { category: 'ml_data', action: 'automate enterprise machine learning from model building to monitoring' }, |
| 113 | 845: { category: 'ml_data', action: 'train and deploy predictive and generative models on an open ML platform' }, |
| 114 | 846: { category: 'ml_data', action: 'analyze business data with AI-assisted dashboards and natural language queries' }, |
| 115 | 847: { category: 'ml_data', action: 'build no-code predictive models directly from spreadsheet-style data' }, |
| 116 | 848: { category: 'audio', action: 'create realistic voiceovers with studio-style AI narration controls' }, |
| 117 | 849: { category: 'audio', action: 'clone custom voices and generate real-time synthetic speech' }, |
| 118 | 850: { category: 'audio', action: 'convert text, docs, and web pages into natural-sounding spoken audio' }, |
| 119 | 851: { category: 'audio', action: 'remove background noise and generate cleaner meeting audio automatically' }, |
| 120 | 852: { category: 'research', action: 'speed up literature review by finding and summarizing research papers' }, |
| 121 | 853: { category: 'research', action: 'search academic papers with AI-assisted relevance and citation discovery' }, |
| 122 | 854: { category: 'research', action: 'answer questions from peer-reviewed studies with evidence-linked summaries' }, |
| 123 | 855: { category: 'research', action: 'map related papers visually to discover key research clusters quickly' }, |
| 124 | 856: { category: 'presentation', action: 'turn AI research output into structured, shareable pages and articles' }, |
| 125 | 857: { category: 'presentation', action: 'convert text ideas into diagrams and visuals for communication' }, |
| 126 | 858: { category: 'coding', action: 'autocomplete multi-line code edits using Cursor’s context-aware Tab model' }, |
| 127 | 859: { category: 'research', action: 'chat with uploaded sources and generate grounded research summaries' }, |
| 128 | 860: { category: 'video', action: 'generate short high-quality videos from text prompts' }, |
| 129 | 861: { category: 'video', action: 'create dance and motion-rich AI videos with multimodal control inputs' }, |
| 130 | 862: { category: 'llm_model', action: 'run a cost-efficient multimodal reasoning model for advanced workloads' }, |
| 131 | 863: { category: 'productivity', action: 'build no-code AI automations across Gmail, Docs, Drive, and Sheets' }, |
| 132 | 864: { category: 'sales_support', action: 'deploy AI agents for CRM workflows in sales and service teams' }, |
| 133 | 865: { category: 'video', action: 'generate navigable 3D worlds from text, images, and layout references' }, |
| 134 | 866: { category: 'coding', action: 'navigate and modify large codebases with deep AI code understanding' }, |
| 135 | 867: { category: 'coding', action: 'get very fast AI code completion with long-context repository support' }, |
| 136 | 868: { category: 'coding', action: 'run an open-source terminal coding agent with bring-your-own-model control' }, |
| 137 | 870: { category: 'methodology', action: 'run AI-assisted software delivery using a structured multi-agent development method' }, |
| 138 | }; |
| 139 | |
| 140 | const CATEGORY_PROFILES = { |
| 141 | assistant_chat: { |
| 142 | minutes: 10, |
| 143 | subhead: 'Start with one concrete outcome, provide context and constraints, then iterate prompts until the response is ready to use.', |
| 144 | not_for: 'Work that requires guaranteed factual accuracy or formal compliance without human review.', |
| 145 | setup_time: '5-10 minutes', |
| 146 | alternatives: ['Claude', 'Google Gemini', 'Perplexity AI'], |
| 147 | }, |
| 148 | llm_model: { |
| 149 | minutes: 20, |
| 150 | subhead: 'Pick a deployment path first (API, hosted endpoint, or self-hosted), then test prompts on real tasks before scaling usage.', |
| 151 | not_for: 'Teams that need turnkey no-code workflows without model operations or prompt tuning.', |
| 152 | setup_time: '15-30 minutes', |
| 153 | alternatives: ['Llama 3.3', 'Mistral AI', 'Alibaba Qwen'], |
| 154 | }, |
| 155 | llm_platform: { |
| 156 | minutes: 15, |
| 157 | subhead: 'Prototype prompts against a target model, evaluate output quality and latency, then wire successful prompts into your application flow.', |
| 158 | not_for: 'Single-purpose tools where you do not need model testing, orchestration, or API-level control.', |
| 159 | setup_time: '10-20 minutes', |
| 160 | alternatives: ['Google AI Studio', 'OpenAI', 'Cohere'], |
| 161 | }, |
| 162 | automation: { |
| 163 | minutes: 20, |
| 164 | subhead: 'Connect your apps, define trigger-action steps, and validate edge cases with test data before enabling the workflow in production.', |
| 165 | not_for: 'Heavy custom backend logic that requires full software development and custom infrastructure.', |
| 166 | setup_time: '10-25 minutes', |
| 167 | alternatives: ['Zapier', 'Make', 'n8n'], |
| 168 | }, |
| 169 | agent_framework: { |
| 170 | minutes: 25, |
| 171 | subhead: 'Define agent roles and tools, build a minimal task loop, and test on constrained scenarios before expanding scope.', |
| 172 | not_for: 'Simple one-shot prompts where a single-model chat interface is sufficient.', |
| 173 | setup_time: '15-30 minutes', |
| 174 | alternatives: ['LangChain', 'CrewAI', 'Microsoft Semantic Kernel'], |
| 175 | }, |
| 176 | coding: { |
| 177 | minutes: 15, |
| 178 | subhead: 'Start with a small file or task, review generated changes carefully, then expand to multi-file refactors with tests in the loop.', |
| 179 | not_for: 'Hands-off autonomous development without review, testing, and repository safeguards.', |
| 180 | setup_time: '5-15 minutes', |
| 181 | alternatives: ['Cursor', 'GitHub Copilot', 'Codeium'], |
| 182 | }, |
| 183 | image: { |
| 184 | minutes: 10, |
| 185 | subhead: 'Write a focused visual prompt, iterate style and composition in short cycles, then upscale or edit for final delivery.', |
| 186 | not_for: 'Pixel-perfect brand systems that still require expert manual design and art direction.', |
| 187 | setup_time: '5-10 minutes', |
| 188 | alternatives: ['Midjourney', 'Ideogram', 'DALL-E 3'], |
| 189 | }, |
| 190 | video: { |
| 191 | minutes: 20, |
| 192 | subhead: 'Create a concise storyboard prompt, generate a first pass, then refine shots, timing, and voiceover for publish-ready output.', |
| 193 | not_for: 'Long-form productions that require frame-level creative control and complex post-production pipelines.', |
| 194 | setup_time: '10-20 minutes', |
| 195 | alternatives: ['RunwayML', 'Pika', 'HeyGen'], |
| 196 | }, |
| 197 | audio: { |
| 198 | minutes: 10, |
| 199 | subhead: 'Choose a voice or music style first, generate a draft, then adjust pacing, tone, and output format for the target channel.', |
| 200 | not_for: 'Projects requiring full legal rights clearance or studio-grade direction without manual review.', |
| 201 | setup_time: '5-10 minutes', |
| 202 | alternatives: ['ElevenLabs', 'Murf AI', 'Resemble AI'], |
| 203 | }, |
| 204 | writing: { |
| 205 | minutes: 10, |
| 206 | subhead: 'Define audience and channel, generate a structured draft, then revise tone and factual claims before publishing.', |
| 207 | not_for: 'Unedited publishing of high-stakes legal, medical, or financial content.', |
| 208 | setup_time: '5-10 minutes', |
| 209 | alternatives: ['Jasper AI', 'Copy.ai', 'Writesonic'], |
| 210 | }, |
| 211 | meeting: { |
| 212 | minutes: 10, |
| 213 | subhead: 'Connect your meeting source, auto-capture transcript and summary, then review highlights and action items for accuracy.', |
| 214 | not_for: 'Environments where recording consent, privacy controls, or compliance requirements are not satisfied.', |
| 215 | setup_time: '5-10 minutes', |
| 216 | alternatives: ['Otter.ai', 'Fireflies.ai', 'Krisp'], |
| 217 | }, |
| 218 | presentation: { |
| 219 | minutes: 10, |
| 220 | subhead: 'Start from a clear outline, let AI generate a first deck, then tighten narrative flow, visuals, and speaker notes.', |
| 221 | not_for: 'Complex brand-heavy decks that require full manual design control from the start.', |
| 222 | setup_time: '5-10 minutes', |
| 223 | alternatives: ['Gamma', 'Tome', 'Beautiful.ai'], |
| 224 | }, |
| 225 | research: { |
| 226 | minutes: 15, |
| 227 | subhead: 'Frame a specific question, review citations and source quality, then synthesize findings into actionable conclusions.', |
| 228 | not_for: 'Decisions that require exhaustive domain validation without checking primary sources.', |
| 229 | setup_time: '5-15 minutes', |
| 230 | alternatives: ['Perplexity AI', 'Elicit', 'Consensus'], |
| 231 | }, |
| 232 | ml_data: { |
| 233 | minutes: 25, |
| 234 | subhead: 'Prepare data first, run a baseline model or analysis, then iterate features and evaluation metrics before deployment.', |
| 235 | not_for: 'Teams without reliable data governance, validation processes, or model monitoring practices.', |
| 236 | setup_time: '20-30 minutes', |
| 237 | alternatives: ['DataRobot', 'H2O.ai', 'Tableau AI'], |
| 238 | }, |
| 239 | sales_support: { |
| 240 | minutes: 20, |
| 241 | subhead: 'Connect CRM and conversation data, define success metrics, then deploy automations that are reviewed by your team.', |
| 242 | not_for: 'Support or sales motions that require zero human oversight for sensitive customer decisions.', |
| 243 | setup_time: '15-30 minutes', |
| 244 | alternatives: ['Gong', 'Intercom Fin AI', 'Salesforce Agentforce'], |
| 245 | }, |
| 246 | health: { |
| 247 | minutes: 10, |
| 248 | subhead: 'Enter symptoms and context clearly, review suggested next steps, and confirm care decisions with licensed professionals.', |
| 249 | not_for: 'Emergency diagnosis, treatment decisions, or replacing qualified medical care.', |
| 250 | setup_time: '5-10 minutes', |
| 251 | alternatives: ['WebMD Symptom Checker', 'Buoy Health', 'K Health'], |
| 252 | }, |
| 253 | productivity: { |
| 254 | minutes: 10, |
| 255 | subhead: 'Capture your working context first, then use AI to summarize, prioritize, and generate next actions you can execute immediately.', |
| 256 | not_for: 'Teams expecting flawless automation without validating generated summaries and action plans.', |
| 257 | setup_time: '5-10 minutes', |
| 258 | alternatives: ['Notion AI', 'Mem.ai', 'Taskade AI'], |
| 259 | }, |
| 260 | methodology: { |
| 261 | minutes: 30, |
| 262 | subhead: 'Set project scope and constraints, assign agent roles by function, then run structured delivery loops with review checkpoints.', |
| 263 | not_for: 'Very small one-off tasks where a lightweight prompt workflow is enough.', |
| 264 | setup_time: '20-30 minutes', |
| 265 | alternatives: ['CrewAI', 'LangChain', 'AutoGPT'], |
| 266 | }, |
| 267 | }; |
| 268 | |
| 269 | function titleCaseMinutes(minutes) { |
| 270 | return Math.max(5, Math.min(30, Math.round(minutes / 5) * 5)); |
| 271 | } |
| 272 | |
| 273 | function deriveCostToStart(pricingRaw) { |
| 274 | const pricing = (pricingRaw || '').trim(); |
| 275 | const lower = pricing.toLowerCase(); |
| 276 | const priceMatch = pricing.match(/\$\s?\d+(?:\.\d+)?(?:\s*\/?\s*(?:mo|month|yr|year))?/i); |
| 277 | |
| 278 | if (!pricing) return 'Check vendor pricing'; |
| 279 | |
| 280 | if (/(open[- ]source|open source)/i.test(pricing)) { |
| 281 | if (/free/i.test(lower) && priceMatch) return `Free (open-source) with paid hosted options from ${priceMatch[0].replace(/\s+/g, ' ')}`; |
| 282 | if (/free/i.test(lower)) return 'Free (open-source) with optional paid hosted plans'; |
| 283 | return 'Free (open-source) or paid managed hosting'; |
| 284 | } |
| 285 | |
| 286 | if (/free/i.test(lower) && priceMatch) { |
| 287 | return `Free tier available; paid plans from ${priceMatch[0].replace(/\s+/g, ' ')}`; |
| 288 | } |
| 289 | |
| 290 | if (/free/i.test(lower)) { |
| 291 | if (/trial/i.test(lower)) return 'Free trial available'; |
| 292 | return 'Free or free tier available'; |
| 293 | } |
| 294 | |
| 295 | if (priceMatch) { |
| 296 | return `Starts at ${priceMatch[0].replace(/\s+/g, ' ')}`; |
| 297 | } |
| 298 | |
| 299 | if (/(contact sales|custom|enterprise)/i.test(lower)) return 'Paid plans (contact sales)'; |
| 300 | if (/pay[- ]?as[- ]?you[- ]?go|usage/i.test(lower)) return 'Usage-based pricing'; |
| 301 | |
| 302 | return pricing.split('.')[0].trim(); |
| 303 | } |
| 304 | |
| 305 | function uniqueAlternatives(alts, toolName) { |
| 306 | const norm = (toolName || '').toLowerCase(); |
| 307 | return (alts || []).filter((alt) => !norm.includes(String(alt).toLowerCase())).slice(0, 3); |
| 308 | } |
| 309 | |
| 310 | async function main() { |
| 311 | const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL; |
| 312 | const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY; |
| 313 | |
| 314 | if (!supabaseUrl || !serviceKey) { |
| 315 | throw new Error('Missing NEXT_PUBLIC_SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY in .env'); |
| 316 | } |
| 317 | |
| 318 | const supabase = createClient(supabaseUrl, serviceKey, { |
| 319 | auth: { autoRefreshToken: false, persistSession: false }, |
| 320 | }); |
| 321 | |
| 322 | const { data: tools, error: toolsError } = await supabase |
| 323 | .from('tools') |
| 324 | .select('id,name,description,pricing,url') |
| 325 | .order('id', { ascending: true }); |
| 326 | |
| 327 | if (toolsError) throw new Error(`Failed fetching tools: ${toolsError.message}`); |
| 328 | |
| 329 | const { data: overviewRows, error: overviewError } = await supabase |
| 330 | .from('tool_tutorial_overviews') |
| 331 | .select('tool_id') |
| 332 | .order('tool_id', { ascending: true }); |
| 333 | |
| 334 | if (overviewError) throw new Error(`Failed fetching overviews: ${overviewError.message}`); |
| 335 | |
| 336 | const overviewIds = new Set((overviewRows || []).map((r) => r.tool_id)); |
| 337 | const missingOverview = tools.filter((t) => !overviewIds.has(t.id)); |
| 338 | if (missingOverview.length > 0) { |
| 339 | throw new Error(`Expected existing overview rows for all tools. Missing: ${missingOverview.map((t) => t.id).join(', ')}`); |
| 340 | } |
| 341 | |
| 342 | const missingFacts = tools |
| 343 | .filter((t) => !SKIP_IDS.has(t.id)) |
| 344 | .filter((t) => !TOOL_FACTS[t.id]); |
| 345 | |
| 346 | if (missingFacts.length > 0) { |
| 347 | throw new Error(`Missing TOOL_FACTS entries for tool IDs: ${missingFacts.map((t) => t.id).join(', ')}`); |
| 348 | } |
| 349 | |
| 350 | const targets = tools.filter((t) => !SKIP_IDS.has(t.id)); |
| 351 | const totalBatches = Math.ceil(targets.length / BATCH_SIZE); |
| 352 | |
| 353 | console.log(`Loaded ${tools.length} tools and ${overviewRows.length} overview rows.`); |
| 354 | console.log(`Skipping tool IDs: ${Array.from(SKIP_IDS).join(', ')}`); |
| 355 | console.log(`Updating ${targets.length} tools in ${totalBatches} batches of ${BATCH_SIZE}.`); |
| 356 | |
| 357 | let updatedCount = 0; |
| 358 | let failedCount = 0; |
| 359 | |
| 360 | for (let i = 0; i < targets.length; i += BATCH_SIZE) { |
| 361 | const batch = targets.slice(i, i + BATCH_SIZE); |
| 362 | const batchNumber = Math.floor(i / BATCH_SIZE) + 1; |
| 363 | |
| 364 | console.log(`\\n[Batch ${batchNumber}/${totalBatches}] Processing ${batch.length} tools...`); |
| 365 | |
| 366 | for (const tool of batch) { |
| 367 | const fact = TOOL_FACTS[tool.id]; |
| 368 | const profile = CATEGORY_PROFILES[fact.category] || CATEGORY_PROFILES.assistant_chat; |
| 369 | const minutes = titleCaseMinutes(profile.minutes); |
| 370 | |
| 371 | const hero_headline = `Use ${tool.name} to ${fact.action} in ${minutes} minutes`; |
| 372 | const hero_subhead = profile.subhead; |
| 373 | const hero_time_estimate_minutes = minutes; |
| 374 | |
| 375 | const quick_verdict = { |
| 376 | best_for: `Teams that need to ${fact.action}.`, |
| 377 | not_for: profile.not_for, |
| 378 | setup_time: profile.setup_time, |
| 379 | cost_to_start: deriveCostToStart(tool.pricing), |
| 380 | alternatives: uniqueAlternatives(profile.alternatives, tool.name), |
| 381 | }; |
| 382 | |
| 383 | const { error: updateError } = await supabase |
| 384 | .from('tool_tutorial_overviews') |
| 385 | .update({ |
| 386 | hero_headline, |
| 387 | hero_subhead, |
| 388 | hero_time_estimate_minutes, |
| 389 | quick_verdict, |
| 390 | }) |
| 391 | .eq('tool_id', tool.id); |
| 392 | |
| 393 | if (updateError) { |
| 394 | failedCount += 1; |
| 395 | console.error(` FAIL tool_id=${tool.id} ${tool.name}: ${updateError.message}`); |
| 396 | } else { |
| 397 | updatedCount += 1; |
| 398 | console.log(` OK tool_id=${tool.id} ${tool.name}`); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | console.log(`[Batch ${batchNumber}/${totalBatches}] Completed. Running totals -> updated: ${updatedCount}, failed: ${failedCount}`); |
| 403 | } |
| 404 | |
| 405 | console.log('\\nDone.'); |
| 406 | console.log(`Updated rows: ${updatedCount}`); |
| 407 | console.log(`Failed rows: ${failedCount}`); |
| 408 | console.log(`Skipped rows: ${SKIP_IDS.size}`); |
| 409 | |
| 410 | if (failedCount > 0) { |
| 411 | process.exitCode = 1; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | main().catch((error) => { |
| 416 | console.error(`Fatal error: ${error.message}`); |
| 417 | process.exit(1); |
| 418 | }); |