export async function handle(input, ctx) {
const csv = buildCsv(input.data);
const file = await ctx.tools.surface_file({
filename: 'results.csv',
content: csv,
description: `${input.data.length} rows`,
});
// Show a summary card with the download URL embedded
return await ctx.tools.render_ui({
interactive: false,
spec: {
root: 'card',
elements: {
card: { type: 'card', props: { title: 'Export ready', subtitle: null }, children: ['kv'] },
kv: {
type: 'key_value',
props: {
items: [
{ key: 'Rows', value: String(input.data.length) },
{ key: 'Format', value: 'CSV' },
{ key: 'Expires', value: '24 hours' },
{ key: 'Download', value: file.downloadUrl },
],
},
children: [],
},
},
state: {},
},
});
}