AI-generated sales talk track generation via Claude Haiku — prompt logic, caching, and angle formula selection
This skill triggers when editing these files:
lib/talk-track.tsapp/api/store/[domain]/talk-track/route.tsKeywords: talk-track, generateTalkTrack, buildPrompt, TALK_TRACK_VERSION, angleFormula, aiQueue
You are working on the AI talk track generation feature — a Claude-powered sales pitch generator that produces a verbatim cold-call opener and a why_pitch breakdown for each store.
lib/talk-track.ts — buildPrompt(), generateTalkTrack(), TalkTrackResult type, TALK_TRACK_SCHEMA, TALK_TRACK_VERSIONapp/api/store/[domain]/talk-track/route.ts — GET handler: cache check → generate → persist → loglib/pipeline-log-types.ts — AiLog type with angleFormula unionTALK_TRACK_VERSION: Integer version stamp. Route returns cached talk_track JSON if talk_track_version >= TALK_TRACK_VERSION. Bump this constant to invalidate all cached talk tracks on next request.buildPrompt): NON_SHOPIFY (non-Shopify platform, checked first) → EXISTING_CUSTOMER → COMPETITIVE_REPLACE → FIRST_SMS_PITCH. The route independently re-derives the angle to log it via upsertAiLog.client.beta.messages.create with betas: ['interleaved-thinking-2025-05-14'] and output_config.format.json_schema. Response is always content[type==='text'] → JSON.parse. Do not use generateObject or streamObject.generateTalkTrack wraps the Anthropic API call in aiQueue.add() (imported from lib/batch-processor.ts, concurrency 2). This prevents overwhelming the Anthropic API when multiple talk tracks are generated concurrently (e.g., during batch processing or parallel call card opens).process.env.STACKRECON_ANTHROPIC_API_KEY (not ANTHROPIC_API_KEY).upsertAiLog failure is caught and warned — never blocks the response.TALK_TRACK_SCHEMA without bumping TALK_TRACK_VERSION — cached JSON in the DB won't match the new shape.buildPrompt — it overrides all other angles and injects nonShopifyPreamble into the prompt.claude-haiku-4-5-20251001 — logged in AiLog. If you change the model, update both generateTalkTrack and the route's upsertAiLog call.talk_track column stores raw JSON string — always JSON.stringify on write, JSON.parse on read.aiQueue concurrency must stay low — the queue throttles Anthropic API calls to avoid rate limits. Do not increase concurrency without checking API rate limits.lib/pipeline-log-types.ts — AiLog.angleFormula union must stay in sync with route logicLast Updated: 2026-04-02