feat(ai-assistant): odt support, document-to-lesson attach, upload UX fixes
- Add .odt (application/vnd.oasis.opendocument.text) as a supported upload format; extract text via JSZip + content.xml parsing - Add attach_document_to_lesson agent tool so the AI can attach an uploaded document to a lesson as a downloadable material - Instruct the agent to create a "Course Materials" lesson (first lesson of the first section) and attach the uploaded document to it on implementation - Suppress hallucinated references: uploaded documents do not count as fetched URLs — omit the References section when no fetch_documentation_url calls were made - Surface specific upload error snackbars (file_too_large, unsupported_file_type) instead of silently logging; fix generic fallback message - Allow typing in the chat textarea while a document is uploading; only block Enter/send, not the whole input - Fix retry endpoint to return the current run instead of erroring when the run is already active (queued/running/waiting_for_input/paused) - Connect @cio/core Redis singleton in the jobs bootstrap so course-generation workers no longer fail with "The client is closed" - Expose documentAssets (assetId + fileName) alongside documentText in AgentContext and pass it through both the chat route and course runner
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { BaseApiWithErrors, classroomio, apiClient, getRequestBaseUrl } from '$lib/utils/services/api';
|
||||
import { snackbar } from '$features/ui/snackbar/store';
|
||||
import { t } from '$lib/utils/functions/translations';
|
||||
import type {
|
||||
AgentConversation,
|
||||
AgentConversationCreateData,
|
||||
@@ -158,7 +160,25 @@ class AiAssistantApi extends BaseApiWithErrors {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error uploading document:', error);
|
||||
this.error = 'Failed to upload document';
|
||||
|
||||
let errorCode: string | null = null;
|
||||
|
||||
if (error instanceof Error) {
|
||||
try {
|
||||
const body = JSON.parse(error.message) as { error?: string };
|
||||
errorCode = body.error ?? null;
|
||||
} catch {
|
||||
// message was not JSON
|
||||
}
|
||||
}
|
||||
|
||||
if (errorCode === 'file_too_large') {
|
||||
snackbar.error(t.get('ai_assistant.upload_error_file_too_large'));
|
||||
} else if (errorCode === 'unsupported_file_type') {
|
||||
snackbar.error(t.get('ai_assistant.upload_error_unsupported_type'));
|
||||
} else {
|
||||
snackbar.error(t.get('ai_assistant.upload_error_generic'));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
<input
|
||||
bind:this={fileInputEl}
|
||||
type="file"
|
||||
accept=".pdf,.docx,.pptx,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||
accept=".pdf,.docx,.pptx,.odt,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.oasis.opendocument.text"
|
||||
class="hidden"
|
||||
onchange={handleFileChange}
|
||||
/>
|
||||
@@ -255,9 +255,9 @@
|
||||
bind:ref={chatTextareaRef}
|
||||
bind:value={inputValue}
|
||||
{mentionItems}
|
||||
onSubmit={onSend}
|
||||
onSubmit={isUploading ? undefined : onSend}
|
||||
placeholder={$t('ai_assistant.input_placeholder')}
|
||||
disabled={isStreaming || isUploading}
|
||||
disabled={isStreaming}
|
||||
typeLabel={getTypeLabel}
|
||||
emptyMessage={t.get('ai_assistant.mention_no_results')}
|
||||
rows={2}
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
? 'bg-white/15 text-white/90'
|
||||
: 'ui:bg-background/70 ui:text-muted-foreground'}"
|
||||
>
|
||||
<FileTextIcon size={12} class="shrink-0" />
|
||||
<FileTextIcon size={12} class="custom shrink-0" />
|
||||
<span class="min-w-0 truncate">{messageAttachment.name}</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import FileQuestionIcon from '@lucide/svelte/icons/file-question';
|
||||
import PencilIcon from '@lucide/svelte/icons/pencil';
|
||||
import ArrowUpIcon from '@lucide/svelte/icons/arrow-up';
|
||||
import LoaderIcon from '@lucide/svelte/icons/loader';
|
||||
import { Button } from '@cio/ui/base/button';
|
||||
import { Textarea } from '@cio/ui/base/textarea';
|
||||
import { SvelteSet } from 'svelte/reactivity';
|
||||
@@ -53,6 +54,12 @@
|
||||
isExpanded = !defaultCollapsed;
|
||||
});
|
||||
|
||||
let isImplementing = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (isBusy) isImplementing = false;
|
||||
});
|
||||
|
||||
let changeRequest = $state('');
|
||||
const canSendChange = $derived(!isBusy && changeRequest.trim().length > 0);
|
||||
|
||||
@@ -301,7 +308,18 @@
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Button size="sm" onclick={() => onImplement(editablePlan)} class="w-full">
|
||||
<Button
|
||||
size="sm"
|
||||
disabled={isImplementing || isBusy}
|
||||
onclick={() => {
|
||||
isImplementing = true;
|
||||
onImplement(editablePlan);
|
||||
}}
|
||||
class="w-full"
|
||||
>
|
||||
{#if isImplementing || isBusy}
|
||||
<LoaderIcon size={14} class="animate-spin" />
|
||||
{/if}
|
||||
{$t('ai_assistant.plan_implement')}
|
||||
</Button>
|
||||
<div class="flex items-end gap-2">
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Spørg AI",
|
||||
"content_input_placeholder": "Spørg om dette indhold...",
|
||||
"ask_ai_expand_aria": "Åbn Spørg AI-input",
|
||||
"ask_ai_input_aria": "Spørg AI om dette indhold"
|
||||
"ask_ai_input_aria": "Spørg AI om dette indhold",
|
||||
"upload_error_file_too_large": "Filen er for stor. Maksimal størrelse er 5 MB.",
|
||||
"upload_error_unsupported_type": "Filtype understøttes ikke. Upload venligst en PDF-, DOCX-, PPTX- eller ODT-fil.",
|
||||
"upload_error_generic": "Kunne ikke uploade dokument. Prøv venligst igen."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widgets",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Fragen Sie die KI",
|
||||
"content_input_placeholder": "Fragen Sie nach diesem Inhalt…",
|
||||
"ask_ai_expand_aria": "Öffnen Sie „Ask AI Input“.",
|
||||
"ask_ai_input_aria": "Fragen Sie AI nach diesem Inhalt"
|
||||
"ask_ai_input_aria": "Fragen Sie AI nach diesem Inhalt",
|
||||
"upload_error_file_too_large": "Die Datei ist zu groß. Die maximale Größe beträgt 5 MB.",
|
||||
"upload_error_unsupported_type": "Dateityp wird nicht unterstützt. Bitte laden Sie eine PDF-, DOCX-, PPTX- oder ODT-Datei hoch.",
|
||||
"upload_error_generic": "Das Hochladen des Dokuments ist fehlgeschlagen. Bitte versuchen Sie es erneut."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widgets",
|
||||
|
||||
@@ -4613,7 +4613,10 @@
|
||||
"ask_ai_expand_aria": "Open Ask AI input",
|
||||
"ask_ai_input_aria": "Ask AI about this content",
|
||||
"quote_lesson_note": "Quote in assistant",
|
||||
"attach_document": "Attach a document (PDF, DOCX, PPTX)",
|
||||
"attach_document": "Attach a document (PDF, DOCX, PPTX, ODT)",
|
||||
"upload_error_file_too_large": "File is too large. Maximum size is 5 MB.",
|
||||
"upload_error_unsupported_type": "File type not supported. Please upload a PDF, DOCX, PPTX, or ODT file.",
|
||||
"upload_error_generic": "Failed to upload document. Please try again.",
|
||||
"upgrade_to_upload": "Upgrade to upload documents",
|
||||
"tokens_exhausted": "Monthly AI token limit reached.",
|
||||
"tokens_exhausted_buy_more": "Buy more",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Pregúntale a la IA",
|
||||
"content_input_placeholder": "Pregunta por este contenido...",
|
||||
"ask_ai_expand_aria": "Abrir Preguntar entrada a AI",
|
||||
"ask_ai_input_aria": "Pregúntale a AI sobre este contenido"
|
||||
"ask_ai_input_aria": "Pregúntale a AI sobre este contenido",
|
||||
"upload_error_file_too_large": "El archivo es demasiado grande. El tamaño máximo es 5 MB.",
|
||||
"upload_error_unsupported_type": "Tipo de archivo no compatible. Cargue un archivo PDF, DOCX, PPTX u ODT.",
|
||||
"upload_error_generic": "No se pudo cargar el documento. Por favor inténtalo de nuevo."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "widgets",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Demandez à l'IA",
|
||||
"content_input_placeholder": "Renseignez-vous sur ce contenu…",
|
||||
"ask_ai_expand_aria": "Ouvrir la saisie de Ask AI",
|
||||
"ask_ai_input_aria": "Interrogez AI à propos de ce contenu"
|
||||
"ask_ai_input_aria": "Interrogez AI à propos de ce contenu",
|
||||
"upload_error_file_too_large": "Le fichier est trop volumineux. La taille maximale est de 5 Mo.",
|
||||
"upload_error_unsupported_type": "Type de fichier non pris en charge. Veuillez télécharger un fichier PDF, DOCX, PPTX ou ODT.",
|
||||
"upload_error_generic": "Échec du téléchargement du document. Veuillez réessayer."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widgets",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "एआई से पूछें",
|
||||
"content_input_placeholder": "इस सामग्री के बारे में पूछें...",
|
||||
"ask_ai_expand_aria": "एआई इनपुट पूछें खोलें",
|
||||
"ask_ai_input_aria": "इस सामग्री के बारे में AI से पूछें"
|
||||
"ask_ai_input_aria": "इस सामग्री के बारे में AI से पूछें",
|
||||
"upload_error_file_too_large": "फ़ाइल बहुत बड़ी है। अधिकतम आकार 5 एमबी है.",
|
||||
"upload_error_unsupported_type": "फ़ाइल प्रकार समर्थित नहीं है. कृपया एक PDF, DOCX, PPTX, या ODT फ़ाइल अपलोड करें।",
|
||||
"upload_error_generic": "दस्तावेज़ अपलोड करने में विफल. कृपया पुन: प्रयास करें।"
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "विजेट्स",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Zapytaj AI",
|
||||
"content_input_placeholder": "Zapytaj o tę treść…",
|
||||
"ask_ai_expand_aria": "Otwórz wejście Zapytaj AI",
|
||||
"ask_ai_input_aria": "Zapytaj AI o tę treść"
|
||||
"ask_ai_input_aria": "Zapytaj AI o tę treść",
|
||||
"upload_error_file_too_large": "Plik jest za duży. Maksymalny rozmiar to 5 MB.",
|
||||
"upload_error_unsupported_type": "Typ pliku nie jest obsługiwany. Prześlij plik PDF, DOCX, PPTX lub ODT.",
|
||||
"upload_error_generic": "Nie udało się przesłać dokumentu. Spróbuj ponownie."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widżety",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Pergunte à IA",
|
||||
"content_input_placeholder": "Pergunte sobre este conteúdo…",
|
||||
"ask_ai_expand_aria": "Abra a entrada Ask AI",
|
||||
"ask_ai_input_aria": "Pergunte à IA sobre este conteúdo"
|
||||
"ask_ai_input_aria": "Pergunte à IA sobre este conteúdo",
|
||||
"upload_error_file_too_large": "O arquivo é muito grande. O tamanho máximo é 5 MB.",
|
||||
"upload_error_unsupported_type": "Tipo de arquivo não suportado. Faça upload de um arquivo PDF, DOCX, PPTX ou ODT.",
|
||||
"upload_error_generic": "Falha ao carregar o documento. Por favor, tente novamente."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widgets",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Спросите ИИ",
|
||||
"content_input_placeholder": "Спросите об этом контенте…",
|
||||
"ask_ai_expand_aria": "Открыть вход Ask AI",
|
||||
"ask_ai_input_aria": "Спросите ИИ об этом контенте"
|
||||
"ask_ai_input_aria": "Спросите ИИ об этом контенте",
|
||||
"upload_error_file_too_large": "Файл слишком большой. Максимальный размер — 5 МБ.",
|
||||
"upload_error_unsupported_type": "Тип файла не поддерживается. Загрузите файл PDF, DOCX, PPTX или ODT.",
|
||||
"upload_error_generic": "Не удалось загрузить документ. Пожалуйста, попробуйте еще раз."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Виджеты",
|
||||
|
||||
@@ -4316,7 +4316,10 @@
|
||||
"ask_ai": "Hỏi AI",
|
||||
"content_input_placeholder": "Hỏi về nội dung này…",
|
||||
"ask_ai_expand_aria": "Mở đầu vào Hỏi AI",
|
||||
"ask_ai_input_aria": "Hỏi AI về nội dung này"
|
||||
"ask_ai_input_aria": "Hỏi AI về nội dung này",
|
||||
"upload_error_file_too_large": "Tệp quá lớn. Kích thước tối đa là 5 MB.",
|
||||
"upload_error_unsupported_type": "Loại tệp không được hỗ trợ. Vui lòng tải lên tệp PDF, DOCX, PPTX hoặc ODT.",
|
||||
"upload_error_generic": "Không thể tải tài liệu lên. Vui lòng thử lại."
|
||||
},
|
||||
"widgets": {
|
||||
"heading": "Widget",
|
||||
|
||||
Reference in New Issue
Block a user