---
phase: 02-model-discovery
plan: 01-FIX
type: fix
---
Fix 1 UAT issue from plan 02-01.
Source: 02-01-ISSUES.md
Priority: 0 critical, 1 major, 0 minor
@~/.claude/get-shit-done/workflows/execute-phase.md
@~/.claude/get-shit-done/templates/summary.md
@.planning/STATE.md
@.planning/ROADMAP.md
**Issues being fixed:**
@.planning/phases/02-model-discovery/02-01-ISSUES.md
**Original plan for reference:**
@.planning/phases/02-model-discovery/02-01-PLAN.md
Task 1: Fix UAT-001 - Search endpoint "undefined.map" error
src/app/api/providers/replicate/models/route.ts
Fix the Replicate search endpoint handling.
**Root cause:** The code assumes search returns `{ results: [{ model: {...} }] }` but the actual Replicate search API response structure is different, causing `data.results` to be undefined.
**Fix approach:**
1. First, investigate the actual search response by adding debug logging:
- Log the raw response from Replicate search API
- Identify the actual response structure
2. Update the code to handle the correct structure:
- The Replicate search API may return models differently (e.g., at root level, different field names)
- Add defensive null checks: `if (!data.results) { ... }`
- Return appropriate error or empty array if no results
3. Keep the existing `ReplicateSearchResponse` interface or update it based on findings
**Safety:** Add null check before .map() call:
```typescript
if (!data.results) {
console.log(`[Replicate:${requestId}] Search returned no results`);
return NextResponse.json({
success: true,
models: [],
});
}
```
4. Update the provider file (src/lib/providers/replicate.ts) with same fix if searchModels() has similar issue.
curl "http://localhost:3000/api/providers/replicate/models?search=flux&api_key=YOUR_KEY" returns success:true with models array (may be empty if no matches)
- Search endpoint returns 200 with models array (not error)
- If no results, returns empty array (not crash)
- List endpoint still works unchanged
Before declaring plan complete:
- [ ] Search query returns success:true (not error)
- [ ] List endpoint still works: `curl "http://localhost:3000/api/providers/replicate/models"` with API key
- [ ] TypeScript compiles: `npx tsc --noEmit`
- [ ] Build succeeds: `npm run build`
- UAT-001 resolved - search endpoint no longer crashes
- Defensive null checks in place
- No regression in list functionality