More refinements

This commit is contained in:
Jorge Manrubia
2025-05-10 18:46:26 +02:00
parent 2d65af8e0e
commit 1f2f47c7e3
@@ -43,14 +43,7 @@ export default class extends Controller {
if (event.detail.success) {
const response = event.detail.fetchResponse
if (response && response.response.headers.get("Content-Type")?.includes("application/json")) {
response.response.json().then((commands) => {
if (commands.reply) {
this.element.querySelector("#chat-insight").innerHTML = marked.parse(commands.reply)
} else {
this.element.querySelector("#chat-responses").textContent = JSON.stringify(commands, null, 2)
}
this.#executeCommands(commands)
})
this.#handleJsonCommandResponse(response)
} else {
this.#reset()
}
@@ -95,6 +88,17 @@ export default class extends Controller {
}
}
#handleJsonCommandResponse(response) {
response.response.json().then((commands) => {
if (commands.reply) {
this.element.querySelector("#chat-insight").innerHTML = marked.parse(commands.reply)
} else {
this.element.querySelector("#chat-responses").textContent = JSON.stringify(commands, null, 2)
}
this.#executeCommands(commands)
})
}
#reset(inputValue = "") {
this.formTarget.reset()
this.inputTarget.value = inputValue