Vercel Voice Agents PR#324
Conversation
Codex reviewThe PR adds a Vercel voice-agent cookbook, but the new runtime route and CI/package metadata introduce regressions that can break the demo or future merges/releases. Findings not on changed lines:
The PR adds an AI SDK 7 cookbook ( |
| // Storing the promise means search requests block until ready, or fail fast if it rejects. | ||
| const indexReady = client.loadIndex(process.env.MOSS_INDEX_NAME!) | ||
| .then(() => console.log('[MOSS] index loaded locally')) | ||
| .catch((err: unknown) => { console.error('[MOSS] loadIndex failed:', err); throw err; }); |
There was a problem hiding this comment.
BLOCKING ```ts
.catch((err: unknown) => { console.error('[MOSS] loadIndex failed:', err); throw err; });
`indexReady` is created at module load, so if `loadIndex()` rejects before any search request awaits it, this rethrow leaves the stored promise rejected without a handler and can terminate the Node/Next process instead of returning the intended 503. Keep the startup promise fulfilled with status, then branch in the handler:
```ts
const indexReady = client.loadIndex(indexName)
.then(() => true)
.catch((err) => { console.error('[MOSS] loadIndex failed:', err); return false; });
if (!(await indexReady)) return new Response('Search index unavailable', { status: 503 });
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify({ query, topK: topK ?? 5 }), | ||
| }); | ||
| const text = await res.text(); |
There was a problem hiding this comment.
CONSIDER ```ts
const text = await res.text();
`/api/token` deliberately returns non-2xx responses for auth and index-load failures, but this handler treats every response body as a successful tool result and returns it to the model. Check `res.ok` before counting hits or returning text so the UI surfaces failures instead of letting the assistant answer from `Unauthorized`, `Search index unavailable`, or an HTML error page:
```ts
if (!res.ok) {
const message = await res.text();
setError(message || `Search failed (${res.status})`);
throw new Error(message || `Search failed (${res.status})`);
}
const text = await res.text();
Voice agents with vercel ai sdk package.