readwise-mastra
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.
Viewing readonly version of main branch: v47View latest version
Last Updated: 2026-02-02
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_MODELenv var (now dynamic) - Add optional
POLLINATIONS_PRIMARY_MODELfor override
Status: ✅ Complete
File: lib/db.ts
- Add
model_cachetable for discovered models - Add
model_configtable 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
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
Status: ✅ Complete
File: lib/llm_pollinations.ts
- Update
generateChat()with model hints (useTools, complexTask) - Add auto-retry with fallback models on error
- Add
modelUsedandfallbacksAttemptedto response - Update
generateJSON()to use new wrapper - Update
generateText()to use new wrapper - Handle
content_blocksin Gemini responses
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/generateendpoint - Add
GET /api/image/modelsendpoint
Status: ✅ Complete
File: jobs/sync/interval.ts
- Add model cache refresh (daily)
- Check
last_discoverytimestamp before refreshing - Log model discovery results
Status: ✅ Complete
File: lib/agent.ts
- Use
complexTask: truefor plan generation - Log which model was used
- Use cheaper model for simple agent interactions
Status: ✅ Complete
File: app/http.ts
- Add
GET /api/ai/models- list cached models + config - Add
POST /api/ai/discover- trigger model rediscovery
GET /api/ai/models- List cached text/image models and current configPOST /api/ai/discover- Manually trigger model rediscoveryPOST /api/image/generate- Generate image from prompt (stored in blob)GET /api/image/models- List available image models
model_cache- Stores discovered models with metadatamodel_config- Stores selected primary/fallback models
- Primary:
gemini(cheap, tools=true) - Fallback 1:
openai(baseline compatibility) - Fallback 2:
gemini-large(complex tasks)
- 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
# 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=