feat: Workflow Engine Part 3 - Inline Prompts (v0.9q)
Deploy Development / deploy (push) Successful in 56s
Build Test / pytest-backend (push) Failing after 4s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 17s

Ermöglicht Analysis Nodes zwischen zwei Prompt-Modi zu wählen:
- Reference Mode: Basis-Prompt aus DB referenzieren (bestehend)
- Inline Mode: Template direkt im Node editieren (NEU)

Frontend:
- InlineTemplateEditor Component (~80 Zeilen)
- Radio Buttons in WorkflowEditorPage für Mode-Auswahl
- Placeholder Picker für beide Modi (End Node + Inline Template)
- Cursor-Position Tracking mit textareaRef
- Conditional Rendering basierend auf promptSource
- Validation: Entweder prompt_slug ODER inline_template

Backend:
- load_prompt_template() akzeptiert ganzen WorkflowNode (statt nur slug)
- Unterstützt inline_template (Mode 1) und prompt_slug (Mode 2)
- WorkflowNode.inline_template Feld hinzugefügt
- Validation: HTTPException wenn weder slug noch template

Serialization:
- inline_template in graph_data speichern/laden
- Backward-compatible mit bestehenden Workflows

Version: 0.9q
Module: workflow 0.7.0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-04-11 08:45:00 +02:00
1 parent b453ce63c6
commit a1723db387
7 files changed
+295 -79

No files matched your search

+148 -55
View File
@@ -18,6 +18,7 @@ import { EndNodeConfig } from '../components/workflow/panels/EndNodeConfig'
import { PlaceholderPicker } from '../components/workflow/panels/PlaceholderPicker'
import { WorkflowExecutePanel } from '../components/workflow/panels/WorkflowExecutePanel'
import { WorkflowResultViewer } from '../components/workflow/panels/WorkflowResultViewer'
import { InlineTemplateEditor } from '../components/workflow/panels/InlineTemplateEditor'
import '../styles/workflowEditor.css'
// Node-Type Mapping
@@ -50,7 +51,9 @@ export default function WorkflowEditorPage() {
const [availablePrompts, setAvailablePrompts] = useState([])
const [executionResult, setExecutionResult] = useState(null)
const [showPlaceholderPicker, setShowPlaceholderPicker] = useState(false)
const [placeholderPickerTarget, setPlaceholderPickerTarget] = useState('end') // 'end' | 'inline'
const endNodeTextareaRef = useRef(null)
const inlineTemplateTextareaRef = useRef(null)
// Load available basis prompts for Analysis nodes
useEffect(() => {
@@ -262,30 +265,60 @@ export default function WorkflowEditorPage() {
}
const handlePlaceholderSelect = (placeholderString) => {
if (!selectedNode || selectedNode.type !== 'end') return
if (!selectedNode) return
const textarea = endNodeTextareaRef.current
const currentTemplate = selectedNode.data.template || ''
// Target bestimmen: End Node oder Inline Template
if (placeholderPickerTarget === 'end' && selectedNode.type === 'end') {
const textarea = endNodeTextareaRef.current
const currentTemplate = selectedNode.data.template || ''
// Wenn Textarea Ref verfügbar, an Cursor-Position einfügen
if (textarea) {
const cursorPos = textarea.selectionStart || currentTemplate.length
const before = currentTemplate.substring(0, cursorPos)
const after = currentTemplate.substring(cursorPos)
const newTemplate = before + placeholderString + after
// Wenn Textarea Ref verfügbar, an Cursor-Position einfügen
if (textarea) {
const cursorPos = textarea.selectionStart || currentTemplate.length
const before = currentTemplate.substring(0, cursorPos)
const after = currentTemplate.substring(cursorPos)
const newTemplate = before + placeholderString + after
handleNodeUpdate(selectedNode.id, { template: newTemplate })
handleNodeUpdate(selectedNode.id, { template: newTemplate })
// Cursor nach eingefügtem Platzhalter positionieren
setTimeout(() => {
const newPos = cursorPos + placeholderString.length
textarea.setSelectionRange(newPos, newPos)
textarea.focus()
}, 0)
} else {
// Fallback: Am Ende einfügen
const newTemplate = currentTemplate + placeholderString
handleNodeUpdate(selectedNode.id, { template: newTemplate })
// Cursor nach eingefügtem Platzhalter positionieren
setTimeout(() => {
const newPos = cursorPos + placeholderString.length
textarea.setSelectionRange(newPos, newPos)
textarea.focus()
}, 0)
} else {
// Fallback: Am Ende einfügen
const newTemplate = currentTemplate + placeholderString
handleNodeUpdate(selectedNode.id, { template: newTemplate })
}
}
// Inline Template (Analysis Node)
else if (placeholderPickerTarget === 'inline' && selectedNode.type === 'analysis') {
const textarea = inlineTemplateTextareaRef.current
const currentTemplate = selectedNode.data.inline_template || ''
// Wenn Textarea Ref verfügbar, an Cursor-Position einfügen
if (textarea) {
const cursorPos = textarea.selectionStart || currentTemplate.length
const before = currentTemplate.substring(0, cursorPos)
const after = currentTemplate.substring(cursorPos)
const newTemplate = before + placeholderString + after
handleNodeUpdate(selectedNode.id, { inline_template: newTemplate })
// Cursor nach eingefügtem Platzhalter positionieren
setTimeout(() => {
const newPos = cursorPos + placeholderString.length
textarea.setSelectionRange(newPos, newPos)
textarea.focus()
}, 0)
} else {
// Fallback: Am Ende einfügen
const newTemplate = currentTemplate + placeholderString
handleNodeUpdate(selectedNode.id, { inline_template: newTemplate })
}
}
}
@@ -455,43 +488,100 @@ export default function WorkflowEditorPage() {
{/* Type-spezifische Konfiguration */}
{selectedNode.type === 'analysis' && (
<>
{/* Prompt Source Selector */}
<div className="config-section">
<label>KI-Prompt auswählen</label>
<select
value={selectedNode.data.prompt_slug ? String(selectedNode.data.prompt_slug) : ''}
onChange={(e) => {
const promptSlug = e.target.value
console.log('🎯 Prompt selected:', promptSlug, 'Type:', typeof promptSlug)
const selectedPrompt = availablePrompts.find(p => p.slug === promptSlug)
console.log('📋 Selected prompt object:', selectedPrompt)
handleNodeUpdate(selectedNode.id, {
prompt_slug: promptSlug || null,
prompt_name: selectedPrompt?.name || null
})
}}
style={{
width: '100%',
padding: '8px',
borderRadius: '4px',
border: '1px solid var(--border)',
background: 'var(--surface)',
color: 'var(--text1)'
}}
>
<option value="">-- Basis-Prompt wählen --</option>
{availablePrompts.map(prompt => (
<option key={prompt.id} value={prompt.slug}>
{prompt.name}
</option>
))}
</select>
{selectedNode.data.prompt_slug && (
<div style={{ marginTop: 8, fontSize: 12, color: 'var(--text3)' }}>
Prompt: {selectedNode.data.prompt_slug} ({selectedNode.data.prompt_name || 'unbekannt'})
</div>
)}
<label className="form-label">Prompt-Quelle</label>
<div style={{ display: 'flex', flexDirection: 'column', gap: '8px' }}>
<label style={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }}>
<input
type="radio"
name={`promptSource-${selectedNode.id}`}
checked={!!selectedNode.data.prompt_slug}
onChange={() => {
handleNodeUpdate(selectedNode.id, {
prompt_slug: '',
inline_template: null
})
}}
style={{ marginRight: '8px' }}
/>
<span style={{ fontSize: '14px' }}>📚 Basis-Prompt referenzieren</span>
</label>
<label style={{ display: 'flex', alignItems: 'center', cursor: 'pointer' }}>
<input
type="radio"
name={`promptSource-${selectedNode.id}`}
checked={!!selectedNode.data.inline_template || (!selectedNode.data.prompt_slug && !selectedNode.data.inline_template)}
onChange={() => {
handleNodeUpdate(selectedNode.id, {
prompt_slug: null,
inline_template: ''
})
}}
style={{ marginRight: '8px' }}
/>
<span style={{ fontSize: '14px' }}>✏️ Inline-Template erstellen</span>
</label>
</div>
</div>
{/* Conditional Rendering: Reference oder Inline */}
{selectedNode.data.prompt_slug !== null && !selectedNode.data.inline_template && (
<div className="config-section">
<label>Basis-Prompt auswählen</label>
<select
value={selectedNode.data.prompt_slug ? String(selectedNode.data.prompt_slug) : ''}
onChange={(e) => {
const promptSlug = e.target.value
console.log('🎯 Prompt selected:', promptSlug, 'Type:', typeof promptSlug)
const selectedPrompt = availablePrompts.find(p => p.slug === promptSlug)
console.log('📋 Selected prompt object:', selectedPrompt)
handleNodeUpdate(selectedNode.id, {
prompt_slug: promptSlug || null,
prompt_name: selectedPrompt?.name || null,
inline_template: null
})
}}
style={{
width: '100%',
padding: '8px',
borderRadius: '4px',
border: '1px solid var(--border)',
background: 'var(--surface)',
color: 'var(--text1)'
}}
>
<option value="">-- Basis-Prompt wählen --</option>
{availablePrompts.map(prompt => (
<option key={prompt.id} value={prompt.slug}>
{prompt.name}
</option>
))}
</select>
{selectedNode.data.prompt_slug && (
<div style={{ marginTop: 8, fontSize: 12, color: 'var(--text3)' }}>
Prompt: {selectedNode.data.prompt_slug} ({selectedNode.data.prompt_name || 'unbekannt'})
</div>
)}
</div>
)}
{/* Inline Template Editor */}
{(selectedNode.data.inline_template !== null || !selectedNode.data.prompt_slug) && (
<InlineTemplateEditor
value={selectedNode.data.inline_template || ''}
onChange={(template) => handleNodeUpdate(selectedNode.id, {
inline_template: template,
prompt_slug: null
})}
onPlaceholderPick={() => {
setPlaceholderPickerTarget('inline')
setShowPlaceholderPicker(true)
}}
textareaRef={inlineTemplateTextareaRef}
/>
)}
<QuestionAugmentationPanel node={selectedNode} onChange={handleNodeUpdate} />
<FallbackConfig node={selectedNode} edges={edges} nodes={nodes} onChange={handleNodeUpdate} />
</>
@@ -517,7 +607,10 @@ export default function WorkflowEditorPage() {
<EndNodeConfig
node={selectedNode}
onChange={handleNodeUpdate}
onOpenPlaceholderPicker={() => setShowPlaceholderPicker(true)}
onOpenPlaceholderPicker={() => {
setPlaceholderPickerTarget('end')
setShowPlaceholderPicker(true)
}}
textareaRef={endNodeTextareaRef}
/>
)}