import { readFile } from 'node:fs/promises';
import { requestJSON } from './http-client.mjs';
try {
// Use a request supplied for your deployment's upstream schema, not a guessed query field.
const raw = await readFile(process.env.API_SEARCH_REQUEST_FILE);
if (!raw.length || raw.length > 1024 * 1024) throw new Error('Invalid request size.');
const body = JSON.parse(raw);
if (!body || typeof body !== 'object' || Array.isArray(body)
|| typeof body.model !== 'string' || !body.model.trim() || body.stream === true) throw new Error('Invalid request.');
await requestJSON('/v1/alpha/search', body);
// A JSON receipt is not proof that the upstream search succeeded semantically.
console.log('JSON response received. Validate results against the deployed upstream schema.');
} catch {
console.error('Search request failed or returned a non-JSON/error response. No automatic retry.');
process.exitCode = 1;
}