There are some js/svelte libraries to simplify the code like this by removing repetitions and noise. In the scope of this task some research should be performed and the appropriate library introduced.
The dirty code example:
function articleClass(m) {
const base =
m.role === "function_call" || m.role === "function_result"
? "chat-function-note"
: "chat-message";
return [base, m.roleClass, m.isAnchor ? "is-anchor" : "", m.isAfterAnchor ? "is-after-anchor" : ""]
.filter(Boolean)
.join(" ");
}
function functionDetailText(m) {
if (m.role === "function_call") {
return (m.toolCalls || []).map((tc) => tc.name + "()").join(", ");
}
return (m.functionName ? m.functionName + ": " : "") + m.text;
}
</script>
<article
class={articleClass(msg)}
...
There are some js/svelte libraries to simplify the code like this by removing repetitions and noise. In the scope of this task some research should be performed and the appropriate library introduced.
The dirty code example: