dac4d94bfe
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FbMbJPadPzVwvt9rU9GBNo
73 lines
3.3 KiB
TypeScript
73 lines
3.3 KiB
TypeScript
import { one, query } from './db';
|
|
import { listReviews } from './reviews';
|
|
import { Area, Role } from './worktypes';
|
|
|
|
/** Your tree of content. Add nodes here; each node pulls its numbers from the areas / taxonomy nodes it lists. */
|
|
export interface ContentNode {
|
|
id: string;
|
|
title: string;
|
|
blurb: string;
|
|
areas: string[]; // work-type areas (areas.id)
|
|
taxonomy: string[]; // taxonomy node ids
|
|
children: ContentNode[];
|
|
}
|
|
|
|
export const CONTENT_TREE: ContentNode = {
|
|
id: 'root',
|
|
title: 'Contents',
|
|
blurb: 'The structure of the survey write-up.',
|
|
areas: [],
|
|
taxonomy: [],
|
|
children: [
|
|
{
|
|
id: 'tools-of-agents',
|
|
title: 'Tools of agents',
|
|
blurb: 'How agents call tools: function calling, MCP, API use and tool-integrated reasoning.',
|
|
areas: ['tool-use'],
|
|
taxonomy: ['agents/tools'],
|
|
children: [],
|
|
},
|
|
],
|
|
};
|
|
|
|
export function findNode(id: string, n: ContentNode = CONTENT_TREE): ContentNode | null {
|
|
if (n.id === id) return n;
|
|
for (const c of n.children) { const f = findNode(id, c); if (f) return f; }
|
|
return null;
|
|
}
|
|
|
|
export async function getContent(node: ContentNode) {
|
|
const areas = await query<Area>('SELECT a.*, 0 AS n FROM areas a WHERE a.id = ANY(?) ORDER BY sort', [node.areas]);
|
|
const [roles, byRole, benchmarks, taxonomy, papers, total, reviews] = await Promise.all([
|
|
query<Role>('SELECT r.*, 0 AS n FROM roles r ORDER BY sort'),
|
|
query<{ type_id: string; n: number; n_llm: number }>(
|
|
`SELECT type_id, COUNT(*) AS n, SUM((source='llm')::int) AS n_llm FROM paper_work_types WHERE split_part(type_id,'|',1) = ANY(?) GROUP BY type_id`, [node.areas]),
|
|
query<{ id: number; name: string; n: number; n_new: number }>(
|
|
`SELECT b.id, b.name, COUNT(DISTINCT pb.paper_id) AS n, SUM(pb.is_new) AS n_new
|
|
FROM paper_benchmarks pb JOIN benchmarks b ON b.id = pb.bench_id JOIN paper_work_types w ON w.paper_id = pb.paper_id
|
|
WHERE split_part(w.type_id,'|',1) = ANY(?) GROUP BY b.id ORDER BY n DESC, b.id LIMIT 12`, [node.areas]),
|
|
query<{ id: string; label: string; n: number }>(
|
|
`SELECT pt.node_id AS id, t.label, COUNT(DISTINCT pt.paper_id) AS n FROM paper_taxonomy pt JOIN taxonomy t ON t.id = pt.node_id
|
|
WHERE pt.node_id = ANY(?) GROUP BY pt.node_id, t.label`, [node.taxonomy]),
|
|
query<{ id: number; title: string; conf_short: string; date: string; summary: string | null }>(
|
|
`SELECT p.id, p.title, c.short AS conf_short, COALESCE(c.start_date,'2026-06-01') AS date, pm.summary
|
|
FROM papers p JOIN conferences c ON c.slug = p.conf LEFT JOIN paper_meta pm ON pm.paper_id = p.id
|
|
WHERE p.id IN (SELECT paper_id FROM paper_work_types WHERE split_part(type_id,'|',1) = ANY(?) AND source = 'llm')
|
|
ORDER BY date DESC, p.id LIMIT 20`, [node.areas]),
|
|
one<{ n: number }>(`SELECT COUNT(DISTINCT paper_id) AS n FROM paper_work_types WHERE split_part(type_id,'|',1) = ANY(?)`, [node.areas]),
|
|
listReviews(),
|
|
]);
|
|
const cells = new Map(byRole.map((r) => [r.type_id, r]));
|
|
return {
|
|
areas,
|
|
total: total?.n ?? 0,
|
|
roles: roles
|
|
.map((r) => ({ ...r, cells: node.areas.map((a) => ({ id: `${a}|${r.id}`, ...(cells.get(`${a}|${r.id}`) ?? { n: 0, n_llm: 0 }) })) }))
|
|
.filter((r) => r.cells.some((c) => c.n > 0)),
|
|
benchmarks,
|
|
taxonomy,
|
|
papers,
|
|
reviews: reviews.filter((r) => node.areas.includes(r.area)),
|
|
};
|
|
}
|