diff --git a/cptr/frontend/src/lib/components/chat/AskUserCard.svelte b/cptr/frontend/src/lib/components/chat/AskUserCard.svelte index ee2cb0e..4bca156 100644 --- a/cptr/frontend/src/lib/components/chat/AskUserCard.svelte +++ b/cptr/frontend/src/lib/components/chat/AskUserCard.svelte @@ -21,13 +21,16 @@ const questions = $derived(Array.isArray(request.questions) ? request.questions : []); const question = $derived(questions[questionIndex]); const pending = $derived(item.status === 'pending'); - const canSubmit = $derived( - questions.length > 0 && + function hasAnswers(answers: Record) { + return ( + questions.length > 0 && questions.every((question: any) => { - const choice = selections[question.id]; + const choice = answers[question.id]; return choice && (choice !== '__other__' || otherAnswers[question.id]?.trim()); }) - ); + ); + } + const canSubmit = $derived(hasAnswers(selections)); const resolved = $derived.by(() => { try { return JSON.parse(pairedOutput?.output || '{}'); @@ -36,11 +39,11 @@ } }); - function submit(timedOut = false) { - if (!chatId || (!canSubmit && !timedOut)) return; + function submit(timedOut = false, selected = selections) { + if (!chatId || (!hasAnswers(selected) && !timedOut)) return; const answers: Record = {}; for (const question of questions) { - const choice = selections[question.id]; + const choice = selected[question.id]; answers[question.id] = timedOut ? question.options[0].label : choice === '__other__' @@ -50,68 +53,117 @@ submitting = true; onanswer(messageId, item.call_id, answers, timedOut); } + + function selectAnswer(questionId: string, answer: string) { + const selected = { ...selections, [questionId]: answer }; + selections = selected; + if (answer === '__other__') return; + if (questionIndex < questions.length - 1) { + questionIndex += 1; + } else if (hasAnswers(selected)) { + submit(false, selected); + } + } -
-
-
Planning question
+
+
+
+ Planning question +
{#if pending}
- {questionIndex + 1} / {questions.length} · paused while this chat is visible + {questionIndex + 1} of {questions.length} · paused while visible
{:else if item.timed_out || resolved.timed_out} -
Used recommendations
+
Recommendations used
{/if}
-
+
{#if question} -
+
-
{question.header}
-
{question.question}
+
+ {question.header} +
+
+ {question.question} +
{#if pending} -
+
{#each question.options || [] as option, optionIndex} {/each} {#if selections[question.id] === '__other__'} @@ -120,17 +172,17 @@ {/if}
{:else} -
+
{resolved.answers?.[question.id]?.answers?.join(', ') || 'No answer recorded'}
{/if}
{/if} -
+