llm_wiki/
default_schemas.rs1use std::collections::HashMap;
2
3const BASE: &str = include_str!("../schemas/base.json");
4const CONCEPT: &str = include_str!("../schemas/concept.json");
5const PAPER: &str = include_str!("../schemas/paper.json");
6const SKILL: &str = include_str!("../schemas/skill.json");
7const DOC: &str = include_str!("../schemas/doc.json");
8const SECTION: &str = include_str!("../schemas/section.json");
9
10const TMPL_CONCEPT: &str = include_str!("../schemas/concept.md");
11const TMPL_PAPER: &str = include_str!("../schemas/paper.md");
12const TMPL_DOC: &str = include_str!("../schemas/doc.md");
13const TMPL_SECTION: &str = include_str!("../schemas/section.md");
14const TMPL_QUERY_RESULT: &str = include_str!("../schemas/query-result.md");
15
16pub fn default_schemas() -> HashMap<&'static str, &'static str> {
18 HashMap::from([
19 ("base.json", BASE),
20 ("concept.json", CONCEPT),
21 ("paper.json", PAPER),
22 ("skill.json", SKILL),
23 ("doc.json", DOC),
24 ("section.json", SECTION),
25 ])
26}
27
28pub fn default_templates() -> HashMap<&'static str, &'static str> {
30 HashMap::from([
31 ("concept.md", TMPL_CONCEPT),
32 ("paper.md", TMPL_PAPER),
33 ("doc.md", TMPL_DOC),
34 ("section.md", TMPL_SECTION),
35 ("query-result.md", TMPL_QUERY_RESULT),
36 ])
37}
38
39pub fn embedded_body_template(type_name: &str) -> Option<&'static str> {
41 let filename = format!("{type_name}.md");
42 default_templates().get(filename.as_str()).copied()
43}
44
45pub struct DefaultTypeEntry {
47 pub type_name: String,
49 pub schema_file: String,
51 pub description: String,
53}
54
55pub fn default_type_entries() -> Vec<DefaultTypeEntry> {
60 let mut entries = Vec::new();
61 for (filename, content) in default_schemas() {
62 let schema: serde_json::Value = serde_json::from_str(content)
63 .unwrap_or_else(|e| panic!("{filename} is not valid JSON: {e}"));
64 if let Some(types) = schema.get("x-wiki-types").and_then(|v| v.as_object()) {
65 for (type_name, desc) in types {
66 entries.push(DefaultTypeEntry {
67 type_name: type_name.clone(),
68 schema_file: format!("schemas/{filename}"),
69 description: desc.as_str().unwrap_or("").to_string(),
70 });
71 }
72 }
73 }
74 entries.sort_by(|a, b| a.type_name.cmp(&b.type_name));
75 entries
76}