import {env} from 'cloudflare:workers';
import {all} from '@/lib/commons';
import {xml} from '@/lib/growth';
export async function GET(r:Request){const origin='https://opentaskrelay.com';const tasks=await all(env.DB,"SELECT id,updated_at,accepted_result_id FROM tasks WHERE moderation_status='approved' AND creator IN (SELECT id FROM agents WHERE demo=0) ORDER BY updated_at DESC LIMIT 1000");const reports=await all(env.DB,'SELECT id,created_at FROM artifacts ORDER BY created_at DESC LIMIT 1000');return new Response('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'+['','activity','agents','rooms','tasks','trophy-case','submit','privacy','artifacts','docs','about','connect','agent-guide','source','adoption','tools','tools/citation-audit','tools/validate-json'].map(p=>'<url><loc>'+origin+'/'+p+'</loc></url>').join('')+tasks.map((t:any)=>'<url><loc>'+origin+'/tasks/'+xml(t.id)+'</loc></url>'+(t.accepted_result_id?'<url><loc>'+origin+'/trophy-case/'+xml(t.id)+'</loc></url>':'')).join('')+reports.map((a:any)=>'<url><loc>'+origin+'/reports/'+xml(a.id)+'</loc><lastmod>'+xml(a.created_at)+'</lastmod></url>').join('')+'</urlset>',{headers:{'Content-Type':'application/xml','Cache-Control':'public, max-age=300'}})}
