1- const chat = document . getElementById ( "chat" ) ;
1+ const chat = document . getElementById ( "chat" ) ;
22const form = document . getElementById ( "input-form" ) ;
33const input = document . getElementById ( "user-input" ) ;
44
55let threadId = null ;
66
7- // ✅ Toegevoegd: bronnummer → URL mapping
8- const sourceMap = {
9- 4 : "https://voorbeeld.nl/bron4.pdf" ,
10- 6 : "https://voorbeeld.nl/bron6.pdf" ,
11- 11 : "https://voorbeeld.nl/bron11.pdf" ,
12- 14 : "https://voorbeeld.nl/bron14.pdf" ,
13- 16 : "https://voorbeeld.nl/bron16.pdf" ,
14- 17 : "https://voorbeeld.nl/bron17.pdf"
15- } ;
16-
17- // ✅ Toegevoegd: functie om 【X†source】 te vervangen door klikbare links
18- function formatSources ( text ) {
7+ // ✅ Verwerkt alleen klikbare links voor bronnen met een openbare URL
8+ function formatSources ( text , sources ) {
199 return text . replace ( / 【 ( \d + ) † s o u r c e 】 / g, ( match , number ) => {
20- const url = sourceMap [ number ] ;
21- return url
22- ? `<a href="${ url } " target="_blank" class="bronlink">[bron ${ number } ]</a>`
23- : `[bron ${ number } ]` ;
10+ const source = sources ?. [ number ] ;
11+ if ( source ?. url ) {
12+ return `<a href="${ source . url } " target="_blank" class="bronlink">[bron ${ number } ]</a>` ;
13+ } else {
14+ return `[bron ${ number } ]` ;
15+ }
2416 } ) ;
2517}
2618
@@ -68,9 +60,9 @@ form.addEventListener("submit", async (e) => {
6860
6961 const data = await response . json ( ) ;
7062 threadId = data . thread_id ;
71- renderMessage ( "agent-message" , data . reply ) ;
63+ renderMessage ( "agent-message" , data ) ;
7264 } catch ( err ) {
73- renderMessage ( "agent-message" , "Er ging iets mis." ) ;
65+ renderMessage ( "agent-message" , { reply : "Er ging iets mis." , sources : { } } ) ;
7466 console . error ( "Fout in fetch:" , err ) ;
7567 }
7668} ) ;
@@ -91,19 +83,17 @@ function appendFormattedMessage(cssClass, htmlContent) {
9183 chat . scrollTop = chat . scrollHeight ;
9284}
9385
94- function renderMessage ( cssClass , text ) {
86+ function renderMessage ( cssClass , data ) {
9587 const msg = document . createElement ( "div" ) ;
9688 msg . classList . add ( "message" , cssClass ) ;
9789 chat . appendChild ( msg ) ;
9890
99- // ✅ Verwerk vet, cursief én bronverwijzingen
100- let htmlText = text
91+ let htmlText = data . reply
10192 . replace ( / \* \* ( .* ?) \* \* / g, "<strong>$1</strong>" )
10293 . replace ( / (?< ! \* ) \* (? ! \* ) ( .* ?) \* (? ! \* ) / g, "<em>$1</em>" ) ;
103- htmlText = formatSources ( htmlText ) ;
94+ htmlText = formatSources ( htmlText , data . sources ) ;
10495
10596 const lines = htmlText . split ( "\n" ) . filter ( line => line . trim ( ) !== "" ) ;
106-
10797 const isNumberedList = lines . length > 1 && lines . every ( line => / ^ \d + \. \s + / . test ( line ) ) ;
10898 const isBulletedList = lines . length > 1 && lines . every ( line => / ^ [ - * • ] \s + / . test ( line ) ) ;
10999
0 commit comments