1
2import { Actor } from 'apify';
3await Actor.init();
4const input = (await Actor.getInput()) ?? {};
5const { check = 'table', tables = [], arxiv_ids = [], items = [], max_items = 100 } = input;
6const UA = 'apify-verify-numbers/0.1 (Tansaku)';
7const H = { 'user-agent': UA, accept: 'application/json', 'content-type': 'application/json' };
8async function post(path, body) { const r = await fetch('https://www.pops4.com' + path, { method: 'POST', headers: H, body: JSON.stringify(body) }); const text = await r.text(); let j; try { j = JSON.parse(text); } catch { j = { raw: text.slice(0, 500) }; } return { status: r.status, body: j }; }
9async function get(path) { const r = await fetch('https://www.pops4.com' + path, { headers: H }); const text = await r.text(); let j; try { j = JSON.parse(text); } catch { j = { raw: text.slice(0, 500) }; } return { status: r.status, body: j }; }
10let pushed = 0;
11async function out(row) { if (pushed >= max_items) return false; await Actor.pushData({ ...row, checked_at: new Date().toISOString(), served_by: 'Tansaku, pops4.com (deterministic; no language model)' }); pushed += 1; await Actor.charge({ eventName: 'check' }).catch(() => {}); return true; }
12if (check === 'table') {
13 for (const t of tables) {
14 const name = t?.name ?? null; const columns = Array.isArray(t) ? t : t?.columns;
15 if (!Array.isArray(columns)) { await out({ check, input_name: name, status: 'bad_input', result: { error: 'tables must be [{name, columns:[[...],[...]]}]' }, model_calls: 0, caution: null }); continue; }
16 const { status, body } = await post('/tansaku/examine', { columns });
17 if (!(await out({ check, input_name: name, status: status === 200 ? body.status ?? 'ok' : `http_${status}`, result: body, model_calls: body.model_calls ?? 0, caution: body.caution ?? null }))) break;
18 }
19} else if (check === 'paper') {
20 for (const id of arxiv_ids) {
21 const { status, body } = await get(`/tansaku/claims?arxiv=${encodeURIComponent(String(id).trim())}`);
22 const summary = status === 200 ? `${body.supported ?? 0} supported of ${body.judged ?? 0} judged` : `http_${status}`;
23 if (!(await out({ check, input_name: String(id), status: summary, result: body, model_calls: body.ai_used ? 1 : 0, caution: body.how ?? null }))) break;
24 }
25} else if (check === 'dependence') {
26 const { status, body } = await post('/tansaku/really', { items });
27 await out({ check, input_name: `${items.length} items`, status: status === 200 ? `really ${body.really}` : `http_${status}`, result: body, model_calls: body.model_calls ?? 0, caution: body.means ?? null });
28}
29console.log(`Done: ${pushed} checks.`);
30await Actor.exit();