{#if message.role === 'assistant' && !hasBubbleContent && !showStreamingSpinner} {:else}
{#if showStreamingSpinner} {/if} {#if messageAttachment}
{messageAttachment.name}
{/if} {#each inlineParts as part, partIndex (partIndex)} {#if part.type === 'text'}
{@html renderMentions(renderMarkdown(part.text as string), courseId)}
{/if} {/each} {#each deferredPlanParts as part, partIndex (partIndex)} {@const toolName = getAgentToolName(part)} {@const toolResult = getAgentToolResult(part)} {@const toolStatus = getAgentToolStatus(part)} {@const errorText = getPartErrorText(part)} {#if toolName === 'generate_course_plan' && toolStatus === 'completed'}
{:else if toolName === 'ask_template_questions' && (toolStatus === 'completed' || toolStatus === 'in_progress')} {@const merged = (toolResult ?? getAgentToolInput(part)) as | { templateId?: CourseTemplateId; fields?: TemplateFormField[] } | undefined} {#if merged?.templateId} {@const canonicalFields = mergeTemplateFieldsWithRegistry(merged.templateId, merged.fields)} {#if canonicalFields.length > 0}
{/if} {/if} {:else}
{#if toolStatus === 'completed' && toolName} {:else if toolStatus === 'failed' && toolName} {#if errorText} {truncateErrorText(errorText)} {:else} {$t('ai_assistant.run_failed_after', { action: localizePendingTool(toolName) })} {/if} {#if errorText} {/if} {:else if toolStatus === 'in_progress' && toolName} {:else} {#if toolName} {:else} {$t('ai_assistant.generic_working')} {/if} {/if}
{/if} {/each} {#if message.role === 'assistant' && tokenUsage}
{tokenUsage.totalTokens.toLocaleString()} {$t('ai_assistant.tokens_label')}
{/if}
{/if}