• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
kamenxrider

kamenxrider

readwise-mastra

Public
Like
readwise-mastra
Home
Code
9
app
1
jobs
1
lib
6
web
3
IMPLEMENTATION_RECAP.md
grounding.md
keyupdates.md
plan.md
tracker.md
Environment variables
6
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
tracker.md
Code
/
tracker.md
Search
…
tracker.md

Implementation Tracker

Current Status: ✅ All Phases Complete

Last Updated: 2026-02-02


Pollinations Integration Updates

Phase 1: Fix Core Endpoint & Configuration

Status: ✅ Complete

File: lib/env.ts

  • Update default POLLINATIONS_BASE_URL → https://gen.pollinations.ai
  • Add POLLINATIONS_CHAT_PATH (default: /v1/chat/completions)
  • Remove POLLINATIONS_MODEL env var (now dynamic)
  • Add optional POLLINATIONS_PRIMARY_MODEL for override

Phase 2: SQLite Model Cache Schema

Status: ✅ Complete

File: lib/db.ts

  • Add model_cache table for discovered models
  • Add model_config table for selected primary/fallback models
  • Add upsertModelCache(model) function
  • Add getModelCache(type) function
  • Add getModelConfig(key) / setModelConfig(key, value) functions
  • Add getModelByName(name) function
  • Add clearModelCache(type?) function
  • Add getAllModelConfig() function

Phase 3: Model Discovery Service

Status: ✅ Complete

File: lib/llm_pollinations.ts

  • Add discoverTextModels() - GET /v1/models + /text/models
  • Add discoverImageModels() - GET /image/models
  • Add refreshModelCache() - run discovery and cache to SQLite
  • Add selectBestModel(options) - pick model based on needs
  • Add getModelWithFallbacks() - return primary + fallback list
  • Add isDiscoveryNeeded() - check if cache is stale (>24h)
  • Add ensureModelCache() - run discovery if needed

Phase 4: Smart Request Wrapper with Auto-Fallback

Status: ✅ Complete

File: lib/llm_pollinations.ts

  • Update generateChat() with model hints (useTools, complexTask)
  • Add auto-retry with fallback models on error
  • Add modelUsed and fallbacksAttempted to response
  • Update generateJSON() to use new wrapper
  • Update generateText() to use new wrapper
  • Handle content_blocks in Gemini responses

Phase 5: Image Generation

Status: ✅ Complete

File: lib/llm_pollinations.ts

  • Add generateImage(prompt, options) function
  • Download image and store in Val Town blob storage
  • Add getImageModels() function

File: app/http.ts

  • Add POST /api/image/generate endpoint
  • Add GET /api/image/models endpoint

Phase 6: Update Interval Job for Model Discovery

Status: ✅ Complete

File: jobs/sync/interval.ts

  • Add model cache refresh (daily)
  • Check last_discovery timestamp before refreshing
  • Log model discovery results

Phase 7: Update Agent for Smart Model Selection

Status: ✅ Complete

File: lib/agent.ts

  • Use complexTask: true for plan generation
  • Log which model was used
  • Use cheaper model for simple agent interactions

Phase 8: Add Model Management API Routes

Status: ✅ Complete

File: app/http.ts

  • Add GET /api/ai/models - list cached models + config
  • Add POST /api/ai/discover - trigger model rediscovery

Summary of Changes

New Endpoints

  • GET /api/ai/models - List cached text/image models and current config
  • POST /api/ai/discover - Manually trigger model rediscovery
  • POST /api/image/generate - Generate image from prompt (stored in blob)
  • GET /api/image/models - List available image models

New Database Tables

  • model_cache - Stores discovered models with metadata
  • model_config - Stores selected primary/fallback models

Model Selection Strategy

  1. Primary: gemini (cheap, tools=true)
  2. Fallback 1: openai (baseline compatibility)
  3. Fallback 2: gemini-large (complex tasks)

Key Behaviors

  • Model discovery runs automatically once per day via interval job
  • Models are auto-selected based on task complexity
  • Automatic fallback on model errors
  • Images stored in Val Town blob storage

Environment Variables (Final)

# Required READWISE_TOKEN=your_readwise_token APP_ADMIN_SECRET=your_secret_for_api_auth POLLINATIONS_TOKEN=your_pollinations_sk_token # Optional (with defaults) POLLINATIONS_BASE_URL=https://gen.pollinations.ai POLLINATIONS_CHAT_PATH=/v1/chat/completions POLLINATIONS_PRIMARY_MODEL= # leave empty for auto-discovery # Optional (webhooks) READWISE_WEBHOOK_SECRET=
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.