This commit is contained in:
seb
2026-10-16 14:17:22 +02:00
parent 764d6f850a
commit a592cc30f6
8 changed files with 477 additions and 64 deletions

View File

@@ -331,20 +331,18 @@ const actions = {
/**
* Stage an extracted text snippet (e.g. from an invoice or delivery document) as a pill.
* @param {{ text: string, size?: number, label?: string }} snippet
* @param {{ text: string, label?: string }} snippet
*/
insertExtractionSnippet({ text = '', size, label } = {}) {
insertExtractionSnippet({ text = '', label = 'parsed invoice' } = {}) {
const trimmed = String(text || '').trim();
if (!trimmed) return;
const finalSize = Number(size) || new Blob([trimmed]).size;
chatOpenedThisSession = true;
chatAutomat.setState({
isOpen: true,
sseEstablished: true,
pendingExtraction: {
text: trimmed,
size: finalSize,
label,
label: label || 'parsed invoice',
},
});
ensureCompanyEventsConnected();
@@ -356,26 +354,17 @@ const actions = {
/**
* Open the chat drawer and append text / prompt to the chat composer.
* If the prompt is an extracted text snippet (e.g. `Text aus „...“:`),
* automatically converts it into a staged extraction pill.
* @param {string} prompt
*/
insertPrompt(prompt = '') {
chatOpenedThisSession = true;
const trimmedPrompt = String(prompt || '').trim();
const extractionMatch = trimmedPrompt.match(/^(?:Text for Data Extraction|Text aus „[^“]+“):\s*```(?:\w+)?\n([\s\S]*?)```$/);
if (extractionMatch) {
const content = (extractionMatch[1] || '').trim();
if (content) {
chatAutomat.actions.insertExtractionSnippet({ text: content });
return;
}
}
const text = String(prompt || '').trim();
if (!text) return;
chatOpenedThisSession = true;
chatAutomat.setState((prev) => ({
isOpen: true,
sseEstablished: true,
pendingInput: prev.pendingInput ? `${prev.pendingInput}\n\n${prompt}` : prompt,
pendingInput: prev.pendingInput ? `${prev.pendingInput}\n\n${text}` : text,
}));
ensureCompanyEventsConnected();
if (!chatAutomat.state.selectedConversationId && !chatAutomat.state.draftConversation) {