import { IMPOSSIBLE, VersionInfo } from '@start9labs/start-sdk'

/**
 * v1.1.0:3 — AI: workout-history context, test connection,
 *            cost estimator, streaming preview render.
 *
 * History context (the killer feature)
 *   - lib/ai/historyContext.ts builds a compact 90-day rollup of
 *     the user's training: per-exercise frequency, recent weights,
 *     estimated 1RMs (Epley), avg RPE, days-since-last, plus a
 *     STAGNANT flag when the heaviest weight in the new half of
 *     the window doesn't beat the old half.
 *   - Generate page has an "Include my workout history as context"
 *     checkbox (default on if you have ≥10 logged workouts). When
 *     checked, the summary is appended to the system prompt so the
 *     model can recommend things like "you've stalled bench at 245
 *     for 6 weeks — try paused reps."
 *   - The summary is text, ~1-3 KB even for heavy users. We
 *     deliberately don't ship raw set logs (privacy + token cost).
 *
 * Test connection
 *   - POST /api/ai/test sends a tiny "say hi in 3 words" prompt
 *     against the user's configured provider and reports
 *     latency + first sample of the response, or the error inline.
 *   - "Test connection" button next to "Save AI config" in
 *     Settings → AI integration. Lets you verify the provider/
 *     model/key/baseUrl combo without going through full program
 *     generation.
 *
 * Cost estimator
 *   - lib/ai/pricing.ts ships a price table for the major models
 *     (Claude Sonnet/Opus/Haiku 4-5, GPT-5/4o/o3, Gemini 2.5/2.0).
 *     Ollama always returns 0 (self-hosted, no per-token cost).
 *     openai-compatible returns null (we don't know the gateway's
 *     pricing).
 *   - Generation history shows per-row cost + a 30-day rolling
 *     total at the top of the page.
 *
 * Streaming preview render
 *   - lib/ai/lenientJson.ts: a stack-aware partial-JSON parser
 *     that auto-closes open strings/brackets/braces in
 *     reverse-of-opening order, drops dangling key:value pairs
 *     and partial keywords. Returns a best-effort snapshot of
 *     the program-so-far on each chunk.
 *   - Generate UI now renders a live "Building program..." panel
 *     that updates as weeks/days/exercises arrive, instead of
 *     just showing raw text and waiting for stream end.
 *
 * No schema changes. /data is untouched.
 */
export const v_1_1_0_3 = VersionInfo.of({
  version: '1.1.0:3',
  releaseNotes: {
    en_US:
      'AI program generation gets four upgrades: (1) include your last 90 days of workout history as context — the model designs around your actual frequency, current weights, and stagnations; (2) "Test connection" button in Settings to verify provider/model/key without a full generation; (3) per-generation USD cost + 30-day rolling total in the history page (Ollama is free, openai-compatible gateways are unknown); (4) streaming preview renders the program tree as the model writes it instead of waiting for the full response. No data migration.',
  },
  migrations: {
    up: async () => {},
    down: IMPOSSIBLE,
  },
})
