@@ -4,35 +4,7 @@ const input = document.getElementById("user-input");
44
55let threadId = null ;
66
7- // ✅ Bronvermeldingen omzetten naar klikbare links
8- function formatSources ( text , sources ) {
9- // Vervang 【...†source】 notatie
10- text = text . replace ( / 【 (?: \d + : ) ? ( \d + ) † s o u r c e 】 / g, ( match , number ) => {
11- const source = sources ?. [ number ] ;
12- return source ?. url
13- ? `<a href="${ source . url } " target="_blank" class="bronlink">[bron ${ number } ]</a>`
14- : `[bron ${ number } ]` ;
15- } ) ;
16-
17- // Vervang [4:0*bron] notatie
18- text = text . replace ( / \[ (?: \d + : ) ? ( \d + ) \* b r o n \] / g, ( match , number ) => {
19- const source = sources ?. [ number ] ;
20- return source ?. url
21- ? `<a href="${ source . url } " target="_blank" class="bronlink">[bron ${ number } ]</a>`
22- : `[bron ${ number } ]` ;
23- } ) ;
24-
25- return text ;
26- }
27-
28- // ✅ Decode HTML entities
29- function decodeHTML ( html ) {
30- const txt = document . createElement ( "textarea" ) ;
31- txt . innerHTML = html ;
32- return txt . value ;
33- }
34-
35- // Welkomstbericht bij het laden
7+ // Openingsbericht bij het laden van de pagina
368window . onload = ( ) => {
379 const welkomstHTML = `
3810 Welkom bij <strong>Indicatiehulp.ai</strong>!<br>
@@ -53,7 +25,6 @@ window.onload = () => {
5325 appendFormattedMessage ( "agent-message" , welkomstHTML ) ;
5426} ;
5527
56- // Form submission → GPT-call
5728form . addEventListener ( "submit" , async ( e ) => {
5829 e . preventDefault ( ) ;
5930 const message = input . value . trim ( ) ;
@@ -77,14 +48,13 @@ form.addEventListener("submit", async (e) => {
7748
7849 const data = await response . json ( ) ;
7950 threadId = data . thread_id ;
80- renderMessage ( "agent-message" , data ) ;
51+ renderMessage ( "agent-message" , data . reply ) ;
8152 } catch ( err ) {
82- renderMessage ( "agent-message" , { reply : "Er ging iets mis." , sources : { } } ) ;
53+ renderMessage ( "agent-message" , "Er ging iets mis." ) ;
8354 console . error ( "Fout in fetch:" , err ) ;
8455 }
8556} ) ;
8657
87- // User messages
8858function appendMessage ( cssClass , text ) {
8959 const msg = document . createElement ( "div" ) ;
9060 msg . classList . add ( "message" , cssClass ) ;
@@ -93,7 +63,6 @@ function appendMessage(cssClass, text) {
9363 chat . scrollTop = chat . scrollHeight ;
9464}
9565
96- // Welkomstbericht of andere HTML-content
9766function appendFormattedMessage ( cssClass , htmlContent ) {
9867 const msg = document . createElement ( "div" ) ;
9968 msg . classList . add ( "message" , cssClass ) ;
@@ -102,19 +71,18 @@ function appendFormattedMessage(cssClass, htmlContent) {
10271 chat . scrollTop = chat . scrollHeight ;
10372}
10473
105- // Agent response message incl. bronverwerking
106- function renderMessage ( cssClass , data ) {
74+ function renderMessage ( cssClass , text ) {
10775 const msg = document . createElement ( "div" ) ;
10876 msg . classList . add ( "message" , cssClass ) ;
10977 chat . appendChild ( msg ) ;
11078
111- let htmlText = data . reply
112- . replace ( / \* \* ( .* ?) \* \* / g, "<strong>$1</strong>" )
113- . replace ( / (?< ! \* ) \* (? ! \* ) ( .* ?) \* (? ! \* ) / g, "<em>$1</em>" ) ;
114- htmlText = formatSources ( htmlText , data . sources ) ;
115- htmlText = decodeHTML ( htmlText ) ;
79+ // Zet **vetgedrukte** en *cursieve* accenten om
80+ let htmlText = text
81+ . replace ( / \* \* ( .* ?) \* \* / g, "<strong>$1</strong>" ) // vet
82+ . replace ( / (?< ! \* ) \* (? ! \* ) ( .* ?) \* (? ! \* ) / g, "<em>$1</em>" ) ; // cursief
11683
11784 const lines = htmlText . split ( "\n" ) . filter ( line => line . trim ( ) !== "" ) ;
85+
11886 const isNumberedList = lines . length > 1 && lines . every ( line => / ^ \d + \. \s + / . test ( line ) ) ;
11987 const isBulletedList = lines . length > 1 && lines . every ( line => / ^ [ - * • ] \s + / . test ( line ) ) ;
12088
0 commit comments